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 */
57 /* Set the function ID */
60 /* Switch to real mode (We don't return) */
64 /* Internal function for realmode calls
65 * bx must be set to the ID of the realmode function to call. */
68 /* Save current stack pointer */
69 mov qword ptr [stack64], rsp
71 /* Set continue address and switch to real mode */
72 lea rax, [CallRealMode_return]
73 mov qword ptr [ContinueAddress], rax
76 /* Set sane segments */
84 //mov word ptr [HEX(0b8008)], HEX(0e00) + '4'
86 /* Save 64-bit stack pointer */
87 mov qword ptr [stack64], rsp
89 /* Step 1 - jump to compatibility segment */
90 jmp fword ptr [jumpvector]
93 .long offset SwitchToRealCompSegment
96 SwitchToRealCompSegment:
97 /* Note: In fact the CPU is in 32 bit mode here. But it will interprete
98 the generated instructions accordingly. rax will become eax */
100 /* Step 2 - deactivate long mode, by disabling paging */
102 and eax, HEX(7fffffff) //~0x80000000, upper bits cleared
105 // mov word ptr [HEX(0b800a)], HEX(0e00) + '5'
107 /* Step 3 - jump to 16-bit segment to set the limit correctly */
108 .byte HEX(0EA) // 32bit long jmp
109 AddressOfRealModeEntryPoint:
110 .long 0 // receives address of RealModeEntryPoint
111 .word HEX(20)//RMODE_CS
115 /* restore stack pointer */
116 mov rsp, qword ptr [stack64]
119 /////////////////////////////////////////
122 /* 64-bit stack pointer */
126 PUBLIC FrldrBootDrive
130 PUBLIC FrldrBootPartition
139 //void __lgdt(void *Source);
145 //void __ltr(unsigned short Source);