3 #include <arch/pc/x86common.h>
6 // EXTERN cmdline:DWORD
9 EXTERN __bss_start__:FWORD
10 EXTERN __bss_end__:FWORD
17 /* Setup segment selectors */
25 //mov word ptr [HEX(b8000)], HEX(0e00) + '1'
27 /* Setup long mode stack */
28 mov rsp, qword ptr [stack64]
30 /* Continue execution */
31 jmp qword ptr [ContinueAddress]
34 .quad offset FrldrStartup
38 /* Store BootDrive and BootPartition */
39 mov al, byte ptr [BSS_BootDrive]
40 mov byte ptr [FrldrBootDrive], al
42 mov al, byte ptr [BSS_BootPartition]
43 mov dword ptr [FrldrBootPartition], eax
45 /* Patch long jump with real mode entry point */
46 mov eax, dword ptr [BSS_RealModeEntry]
47 mov dword ptr [AddressOfRealModeEntryPoint], eax
51 mov rdi, offset __bss_start__
52 mov rcx, offset __bss_end__ + 7
57 /* Pass the command line to BootMain */
58 // mov rcx, offset cmdline
64 /* We should never get here */
73 /* Set the function ID */
76 /* Switch to real mode (We don't return) */
80 /* Internal function for realmode calls
81 * bx must be set to the ID of the realmode function to call. */
84 /* Save current stack pointer */
85 mov qword ptr [stack64], rsp
87 /* Set continue address and switch to real mode */
88 lea rax, [CallRealMode_return]
89 mov qword ptr [ContinueAddress], rax
92 /* Set sane segments */
100 //mov word ptr [HEX(0b8008)], HEX(0e00) + '4'
102 /* Save 64-bit stack pointer */
103 mov qword ptr [stack64], rsp
105 /* Step 1 - jump to compatibility segment */
106 jmp fword ptr [jumpvector]
109 .long offset SwitchToRealCompSegment
112 SwitchToRealCompSegment:
113 /* Note: In fact the CPU is in 32 bit mode here. But it will interprete
114 the generated instructions accordingly. rax will become eax */
116 /* Step 2 - deactivate long mode, by disabling paging */
118 and eax, HEX(7fffffff) //~0x80000000, upper bits cleared
121 // mov word ptr [HEX(0b800a)], HEX(0e00) + '5'
123 /* Step 3 - jump to 16-bit segment to set the limit correctly */
124 .byte HEX(0EA) // 32bit long jmp
125 AddressOfRealModeEntryPoint:
126 .long 0 // receives address of RealModeEntryPoint
127 .word HEX(20)//RMODE_CS
131 /* restore stack pointer */
132 mov rsp, qword ptr [stack64]
135 /////////////////////////////////////////
138 /* 64-bit stack pointer */
142 PUBLIC FrldrBootDrive
146 PUBLIC FrldrBootPartition
155 //void __lgdt(void *Source);
161 //void __ltr(unsigned short Source);