@@ -64,28 +64,30 @@ rom32_start:
64
64
jmpl *%eax
65
65
66
66
.code16
67
- rom16_protected:
68
- # We are now in 16-bit protected mode, To enter 32-bit protected mode, we
67
+ rom16:
68
+ # Order of instructions from Intel SDM 9.9.1 "Switching to Protected Mode"
69
+ # Step 1: Disable interrupts
70
+ cli
71
+
72
+ # Step 2: Load the GDT
73
+ # We are currently in 16-bit real mode. To enter 32-bit protected mode, we
69
74
# need to load 32-bit code/data segments into our GDT. The gdt32 in ROM is
70
75
# at too high of an address (4 GiB - offset) for the data segment to reach.
71
76
# So, we load gdt32 via the 16-bit code segement, using a 16-bit address.
72
77
movw $gdt32_ptr_addr16, %bx
73
78
lgdtl %cs :(%bx )
74
79
75
- # Set CS to a 32-bit segment and jump to 32-bit code.
76
- ljmpl $(code32_desc - gdt32_start), $rom32_addr32
77
-
78
- .align 16
79
- reset_vector: # 0xffff_fff0
80
- # This code must be 16 bytes or less, so be careful when adding anyting.
81
- cli
82
-
83
- # Set CRO.PE (Protected Mode Enable)
80
+ # Step 3: Set CRO.PE (Protected Mode Enable)
84
81
movl %cr0 , %eax
85
82
orb $0b00000001 , %al # Set bit 0
86
83
movl %eax , %cr0
87
84
88
- jmp rom16_protected
85
+ # Step 4: Far JMP to change execution flow and serializes the processor.
86
+ # Set CS to a 32-bit segment and jump to 32-bit code.
87
+ ljmpl $(code32_desc - gdt32_start), $rom32_addr32
89
88
90
89
.align 16
90
+ reset_vector: # 0xffff_fff0
91
+ jmp rom16
92
+ .align 16
91
93
rom_end: # 0x1_0000_0000
0 commit comments