3 #include <arch/pc/x86common.h>
11 /* Setup segment selectors */
19 //mov word ptr [HEX(b8000)], HEX(0e00) + '1'
21 /* Setup long mode stack */
22 mov rsp, qword ptr [stack64]
24 /* Continue execution */
25 jmp qword ptr [ContinueAddress]
28 .quad offset FrldrStartup
32 /* Store BootDrive and BootPartition */
33 mov al, byte ptr [BSS_BootDrive]
34 mov byte ptr [FrldrBootDrive], al
36 mov al, byte ptr [BSS_BootPartition]
37 mov dword ptr [FrldrBootPartition], eax
39 /* Patch long jump with real mode entry point */
40 mov eax, dword ptr [BSS_RealModeEntry]
41 mov dword ptr [AddressOfRealModeEntryPoint], eax
47 /* We should never get here */
56 /* Set the function ID */
59 /* Switch to real mode (We don't return) */
63 /* Internal function for realmode calls
64 * bx must be set to the ID of the realmode function to call. */
67 /* Save current stack pointer */
68 mov qword ptr [stack64], rsp
70 /* Set continue address and switch to real mode */
71 lea rax, [CallRealMode_return]
72 mov qword ptr [ContinueAddress], rax
75 /* Set sane segments */
83 //mov word ptr [HEX(0b8008)], HEX(0e00) + '4'
85 /* Save 64-bit stack pointer */
86 mov qword ptr [stack64], rsp
88 /* Step 1 - jump to compatibility segment */
89 jmp fword ptr [jumpvector]
92 .long offset SwitchToRealCompSegment
95 SwitchToRealCompSegment:
96 /* Note: In fact the CPU is in 32 bit mode here. But it will interprete
97 the generated instructions accordingly. rax will become eax */
99 /* Step 2 - deactivate long mode, by disabling paging */
101 and eax, HEX(7fffffff) //~0x80000000, upper bits cleared
104 // mov word ptr [HEX(0b800a)], HEX(0e00) + '5'
106 /* Step 3 - jump to 16-bit segment to set the limit correctly */
107 .byte HEX(0EA) // 32bit long jmp
108 AddressOfRealModeEntryPoint:
109 .long 0 // receives address of RealModeEntryPoint
110 .word HEX(20)//RMODE_CS
114 /* restore stack pointer */
115 mov rsp, qword ptr [stack64]
118 /////////////////////////////////////////
121 /* 64-bit stack pointer */
125 PUBLIC FrldrBootDrive
129 PUBLIC FrldrBootPartition
138 //void __lgdt(void *Source);
144 //void __ltr(unsigned short Source);