/* Segment constants */ #define BOOT_SEG 0x7C0 /* Segment we reside on startup */ #define BOOT_RELOC_SEG 0x7A0 /* Relocation segment */ .code16 _start: /* Normalize CS + other selectors */ ljmp $BOOT_SEG,$1f 1: xor %ax, %ax mov %ax, %ss mov %ax, %gs mov %ax, %fs /* * The second stage bootloader expects to be loaded to 0x7C00 but since we are * already executing at this address we'll need to relocate ourselves first before * we clobber it. */ mov $BOOT_SEG, %ax mov %ax, %ds mov $BOOT_RELOC_SEG, %ax mov %ax, %es xor %si, %si xor %di, %di mov $0x200, %cx cld rep movsb /* Jump to our relocated self */ ljmp $BOOT_RELOC_SEG,$reloc reloc: /* Save the drive number */ mov %dl, drive_num /* Set our stack */ mov $0x7C00, %sp /* Write out our boot string */ mov $boot_msg, %si call putstr cli hlt jmp reloc /* * Write a string to the console * * %si: String to write * * XXX: Clobbers %AL */ putstr: lodsb or %al, %al jz 1f call putchr jmp putstr 1: ret /* * Write a single character to the console * * %al: Character to write */ putchr: push %dx mov $0x3F8, %dx out %al, %dx pop %dx ret drive_num: .byte 0x00 boot_msg: .ascii "booting\0" .org 510 .byte 0x55 .byte 0xAA