* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#include <asm.inc>
+.intel_syntax noprefix
+#define HEX(y) 0x##y
+
+#define ASM
#include <arch.h>
#include <multiboot.h>
-EXTERN _BootMain:PROC
-EXTERN __bss_start__:DWORD
-EXTERN __bss_end__:DWORD
-EXTERN i386idtptr:FWORD
-
-.code16
+ .code16
-PUBLIC RealEntryPoint
-RealEntryPoint:
+EXTERN(RealEntryPoint)
cli
sti
/* Init pmode */
- call switch_to_prot
+ call switch_to_prot
-.endcode16
-.code32
+ .code32
/* Zero BootDrive and BootPartition */
xor eax, eax
call _BootMain
call switch_to_real
-.code16
+ .code16
int HEX(19)
* Switches the processor to protected mode
* it destroys eax
*/
-PUBLIC switch_to_prot
-switch_to_prot:
+EXTERN(switch_to_prot)
+
+.code16
cli /* None of these */
mov word ptr ds:[stack16], sp
/* Load the GDT */
- lgdt gdtptr
+ lgdt gdtptr
/* Load the IDT */
- lidt i386idtptr
+ lidt i386idtptr
/* Enable Protected Mode */
mov eax, cr0
mov cr0, eax
/* Clear prefetch queue & correct CS */
- ljmp16 PMODE_CS, inpmode
+ //ljmp PMODE_CS, inpmode
+ jmp far ptr PMODE_CS:inpmode
-inpmode:
-.endcode16
.code32
+inpmode:
/* Setup segment selectors */
mov ax, PMODE_DS
mov ds, ax
* Switches the processor back to real mode
* it destroys eax
*/
-PUBLIC switch_to_real
-switch_to_real:
+EXTERN(switch_to_real)
+
+.code32
/* We don't know what values are currently */
/* in the segment registers. So we are */
mov cr0, eax
/* Clear prefetch queue & correct CS */
- //ljmp16 0, offset inrmode
+ //ljmp $0, $inrmode
jmp far ptr 0:inrmode
inrmode:
push word ptr ds:[code16ret]
/* Load IDTR with real mode value */
- lidt rmode_idtptr
+ lidt rmode_idtptr
sti /* These are ok now */
/*
* Needed for enabling the a20 address line
*/
+.code16
empty_8042:
- .word HEX(00eb), HEX(00eb) // jmp $+2, jmp $+2
+ .word 0x00eb,0x00eb // jmp $+2, jmp $+2
in al, HEX(64)
cmp al, HEX(ff) // legacy-free machine without keyboard
jz empty_8042_ret // controllers on Intel Macs read back 0xFF
empty_8042_ret:
ret
-.endcode16
-.code32
-
/*
* Enable the A20 address line (to allow access to over 1mb)
*/
-PUBLIC _EnableA20
-_EnableA20:
+EXTERN(_EnableA20)
+.code32
pusha
out HEX(60), al
call empty_8042
call switch_to_prot
-
-.endcode16
-.code32
+ .code32
popa
/*
* Disable the A20 address line
*/
-PUBLIC _DisableA20
-_DisableA20:
+EXTERN(_DisableA20)
+.code32
pusha
call switch_to_real
+ .code16
-.code16
-
- call empty_8042
+ call empty_8042
mov al, HEX(D1) // command write
out HEX(64), al
call empty_8042
mov al, HEX(DD) // A20 off
out HEX(60), al
- call empty_8042
- call switch_to_prot
-
-.endcode16
-.code32
+ call empty_8042
+ call switch_to_prot
+ .code32
popa
#define INITIAL_BASE HEX(200000)
/* Align 32 bits boundary */
- .align 4
+.align 4
/* Multiboot header */
MultibootHeader:
/* Although the multiboot spec says we should be called with the
* segment registers set to 4GB flat mode, let's be sure and set up
* our own */
- lgdt gdtptrhigh + INITIAL_BASE - FREELDR_BASE
+ lgdt gdtptrhigh + INITIAL_BASE - FREELDR_BASE
/* Reload segment selectors */
- ljmp PMODE_CS, (mb1 + INITIAL_BASE - FREELDR_BASE)
- //jmp far ptr PMODE_CS: (offset mb1 + INITIAL_BASE - FREELDR_BASE)
+ //ljmp $PMODE_CS, $(mb1 + INITIAL_BASE - FREELDR_BASE)
+ jmp far ptr PMODE_CS: (mb1 + INITIAL_BASE - FREELDR_BASE)
mb1:
mov dx, PMODE_DS
mov ds, dx
rep movsd
/* Load the GDT and IDT */
- lgdt gdtptr
- lidt i386idtptr
+ lgdt gdtptr
+ lidt i386idtptr
/* Clear prefetch queue & correct CS,
* jump to low mem */
- ljmp PMODE_CS, mb4
- //jmp far ptr PMODE_CS:mb4
+ //ljmp $PMODE_CS, $mb4
+ jmp far ptr PMODE_CS:mb4
mb4:
/* Reload segment selectors */
mov dx, PMODE_DS
/* GO! */
push eax
- call _BootMain
+ call _BootMain
mbfail:
call switch_to_real
-.code16
- int HEX(19)
-mbstop:
- jmp mbstop /* We should never get here */
+ .code16
+ int 0x19
+mbstop: jmp mbstop /* We should never get here */
-.endcode16
-.code32
+ .code32
/* 16-bit stack pointer */
stack16:
cmdline:
.fill CMDLINE_SIZE, 1, 0
-PUBLIC _BootDrive
-_BootDrive:
+EXTERN(_BootDrive)
.long 0
-
-PUBLIC _BootPartition
-_BootPartition:
+
+EXTERN(_BootPartition)
.long 0
-
-END
-