#include <stage1.h>
#define ABS(x) (x-_start+0x7c00) //計算實體位址,不依賴編譯器
#define MSG(x) movw $ABS(x), %si; call message
#define MOV_MEM_TO_AL(x) .byte 0xa0; .word x //這個不用管它,隻是為了實作相容性用了機器碼
.file "stage1.S" .text .code16 .globl _start; _start:
jmp after_BPB
nop . = _start + 4 //跳過上面兩條指令
mode:
.byte 0
disk_address_packet:
sectors:
.long 0
heads:
.long 0
cylinders:
.word 0
sector_start:
.byte 0
head_start:
.byte 0
cylinder_start:
.word 0
. = _start + STAGE1_BPBEND stage1_version:
.byte COMPAT_VERSION_MAJOR, COMPAT_VERSION_MINOR
boot_drive:
.byte GRUB_INVALID_DRIVE
force_lba:
.byte 0
stage2_address:
.word 0x8000
stage2_sector:
.long 1
stage2_segment:
.word 0x800 after_BPB:
cli boot_drive_check:
jmp 1f
testb $0x80, %dl
jnz 1f
movb $0x80, %dl
1:
ljmp $0, $ABS(real_start) real_start:
xorw %ax, %ax
movw %ax, %ds
movw %ax, %ss
movw $STAGE1_STACKSEG, %sp sti
MOV_MEM_TO_AL(ABS(boot_drive))
cmpb $GRUB_INVALID_DRIVE, %al
je 1f
movb %al, %dl
1:
pushw %dx
MSG(notification_string)
testb $STAGE1_BIOS_HD_FLAG, %dl
jz chs_mode
movb $0x41, %ah
movw $0x55aa, %bx
int $0x13
popw %dx
pushw %dx
jc chs_mode
cmpw $0xaa55, %bx
jne chs_mode
MOV_MEM_TO_AL(ABS(force_lba))
testb %al, %al
jnz lba_mode
andw $1, %cx
jz chs_mode
lba_mode:
movl 0x10(%si), %ecx