BOOTSEG = 0x07c0 /* original address of boot-sector */ SYSSEG = 0x1000 /* historical load address >> 4 */ .code16 .global bootsect_start bootsect_start: # Normalize the start address ljmp $BOOTSEG, $start2 start2: movw %cs, %ax /* make all the register to zero*/ movw %ax, %ds movw %ax, %es movw %ax, %ss xorw %sp, %sp /* zero the sp*/ sti cld msg_loop: movw $bugger_off_msg, %ax movw %ax, %bp movw $16, %cx movw $0x1301, %ax movw $0x00c, %bx int $0x10 jmp msg_loop bugger_off_msg: .ascii "hello os world!!!" .org 510 .word 0xaa55
Makefile
cc = gcc ld = ld as = as ld_flag = -Ttext 0x0 -s --oformat binary c_flag = -E -traditional-cpp all:a.img a.img: boot.bin dd if=boot.bin of=a.img bs=512 conv=notrunc #用 bin file 生成对应的镜像文件 boot.bin:boot.o $(ld) $(ld_flag) $^ -o $@ boot.o:boot.s $(as) $^ -o $@ boot.s:boot.S $(cc) $(c_flag) $^ -o $@ clean: rm a.img boot.s boot.o boo.bin
这样一个简单的在bios POST后,打印hello os world的程序就完成了,相对于intel版的代码,在编译阶段相对来说复杂的多,但是复杂也就意味着更自由,继续学习。