summaryrefslogtreecommitdiff
path: root/src/boot/stage2_switch_mode.asm
blob: 9259e08dd357b9106a8d662200502cf1f016f8ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
[bits 16]

%include "boot/boot_gdt.asm"

switch_to_protected_mode:
	; switch off interrupts for now, we don't
	; have a valid IDT installed yet
	cli
	
	; load GDT (global descriptor table)
	lgdt [gdt_descriptor]
	
	; do the actual switch
	mov eax, cr0
	or eax, 0x1
	mov cr0, eax
	
	; unconditional far jump into code segment,
	; wipes the instruction prefetch pipeline
	jmp CODE_SEGMENT:init_pm
	
[bits 32]

; initialize registers and stack for protected mode
init_pm:
	mov ax, DATA_SEGMENT
	mov ds, ax
	mov ss, ax
	mov es, ax
	mov fs, ax
	mov gs, ax
	
	; a new stack
	mov ebp, 0x90000
	mov esp, ebp
	
	call BEGIN_PROTECTED_MODE
	
[bits 16]