我已经在Assembly中完成了一部分操作系统,但是现在我也想为其构建一个自己的引导程序,而不是使用GRUB。当我在Assembly中开发测试操作系统时,我记得我是这样启动的:
org 0x7c00
bits 16
; OS Kernel Here
times 510 - ($-$$) db 0
dw 0xAA55
这我已经知道了。现在,我想使用它并执行“真实”操作系统,该操作系统将是一个* .bin文件,写入软盘的第二个扇区。那我想知道一点
您用于int 0x13
加载所需数量的扇区并跳转到放置新代码的位置。在第二阶段,您无需执行任何操作,但是您将要确保设置DS
为对加载代码的任何地方都有效。
我的小型OS存档中的示例:
/* BIOS loads the sectors into es:bx */
pushw $STAGE1_WORKSEG
popw %es
movw $STAGE1_OFFSET, %bx
read_stage1:
/* Try to read in a few sectors */
movb $0x2, %cl /* Sector */
movb $0x0, %ch /* Cylinder */
movb $0x0, %dh /* Head */
movb $0x0, %dl /* Drive */
movb $0x2, %ah /* BIOS read function */
/* How many sectors to load */
movb $STAGE1_SIZE, %al
int $0x13
jnc read_stage1_done
/* Reset drive */
xorw %ax, %ax
int $0x13
jmp read_stage1
read_stage1_done:
/* Perform a long jump into stage1 */
ljmp $STAGE1_WORKSEG, $STAGE1_OFFSET
call halt
halt:
/*
* Function: halt
* Synopsis: Sends the processor into a permanent halted status
* Notes:
* The only way out of this is to manually reboot
*/
hlt /* Halt the processor */
jmp halt
该格式为GAS格式,因此您需要颠倒操作数的顺序,因为看起来您正在使用times
指令中的NASM 。变量名称应该是不言自明的。
如果您正在开发业余操作系统,那么这http://forum.osdev.org/
是从其他从事同一工作的人那里获得支持的好地方。它比stackoverflow更加专业,并且许多OS东西都可能很深奥。