4 #include <arch/pc/x86common.h>
12 /* Setup segment selectors */
20 //mov word ptr [HEX(b8000)], HEX(0e00) + '1'
22 /* Setup long mode stack */
23 mov rsp, qword ptr [stack64]
25 /* Continue execution */
26 jmp qword ptr [ContinueAddress]
29 .double offset FrldrStartup
33 /* Store BootDrive and BootPartition */
34 mov al, byte ptr [BSS_BootDrive]
35 mov byte ptr [FrldrBootDrive], al
37 mov al, byte ptr [BSS_BootPartition]
38 mov dword ptr [FrldrBootPartition], eax
40 /* Patch long jump with real mode entry point */
41 mov eax, dword ptr [BSS_RealModeEntry]
42 mov dword ptr [AddressOfRealModeEntryPoint], eax
48 /* We should never get here */
55 /* Internal function for realmode calls
56 * bx must be set to the ID of the realmode function to call. */
59 /* Save current stack pointer */
60 mov qword ptr [stack64], rsp
62 /* Set continue address and switch to real mode */
63 lea rax, [CallRealMode_return]
64 mov qword ptr [ContinueAddress], rax
67 /* Set sane segments */
75 //mov word ptr [HEX(0b8008)], HEX(0e00) + '4'
77 /* Save 64-bit stack pointer */
78 mov qword ptr [stack64], rsp
80 /* Step 1 - jump to compatibility segment */
81 jmp fword ptr [jumpvector]
84 .long offset SwitchToRealCompSegment
87 SwitchToRealCompSegment:
88 /* Note: In fact the CPU is in 32 bit mode here. But it will interprete
89 the generated instructions accordingly. rax will become eax */
91 /* Step 2 - deactivate long mode, by disabling paging */
93 and eax, HEX(7fffffff) //~0x80000000, upper bits cleared
96 // mov word ptr [HEX(0b800a)], HEX(0e00) + '5'
98 /* Step 3 - jump to 16-bit segment to set the limit correctly */
99 .byte HEX(0EA) // 32bit long jmp
100 AddressOfRealModeEntryPoint:
101 .long 0 // receives address of RealModeEntryPoint
102 .word HEX(20)//RMODE_CS
106 /* restore stack pointer */
107 mov rsp, qword ptr [stack64]
110 /////////////////////////////////////////
113 /* 64-bit stack pointer */
117 PUBLIC FrldrBootDrive
121 PUBLIC FrldrBootPartition
130 //void __lgdt(void *Source);
136 //void __ltr(unsigned short Source);