我正在为将来的测试应用程序构建一个简单的内核,比如MEMTEST等。
所以,我现在拥有的是引导加载程序。 我需要做的是加载另一个我将编译的文件放在软盘的第二个扇区然后运行。
那么,如何将剩余的软盘加载到RAM然后运行?
你不需要100%准确,我只需要知道并学习必要的中断和“功能”来做我需要的:)
只是为了分享引导程序:
[BITS 16] ;set 16bit mode
[ORG 0x7C00] ; address location where the program will run
jmp main ;start on main
main:
mov si,hstr ; put the pointer into si register
call printstr ;print hstr
;call load_kernel
;here we gonna load kernel into memory and then we will run it.
mov si,mstr ; put the pointer into si register
call printstr ;print mstr
jmp hold ;idle the CPU
hold:
hlt ;idle CPU
printstr:
;This will write in TTY char that will be loaded into al 8bit register.
lodsb ;load into al
cmp al,0 ; set flag if al is 0
jnz print ; if isnt equal to 0 then jump to print
ret ;else return to main
print: ;print the char
mov ah,0x0E ;set the ah before calling the video interrupt
int 10h ;here we go
jmp printstr ;jump back
;
hstr db "Loading ...",13,10,0 ;define the strings. 13 is ASCII, 10 for new line, 0 is the null terminator
mstr db "CPU is now idle!",13,10,0
times 510 - ($-$$) db 0 ;fill the rest of the sector(less 2 last bytes) with 0's. 510-(here-start)=free space with 0's
dw 0xAA55 ;the last 2 bytes of the sector with AA55 signature. means that is the bootloader.
答案 0 :(得分:2)
从软盘加载数据或使用硬盘中断13(十六进制)。
使用软盘中断比使用硬盘更复杂(功能AH = 2 - 也可以用于硬盘 - 使用扇区的C / H / S寻址)(功能AH = 0x42 - 这是不存在于非常老的BIOS中(2000年之前) - 只能与硬盘一起使用而不能与软盘一起使用。
要运行C代码,您需要一个生成16位代码的C编译器(也许Watcom C编译器仍然可以执行此操作),或者您必须切换到32位保护模式。
“osdev.org”的WIKI是一个很好的OS编程资源,你可以在这里找到很多信息。