Reputation: 658
I'm building a simple kernel for future tests applications, like MEMTEST and others.
So, what I have right now is the bootloader. What i need to do is load another file that I'll compile put in the second sector of the floppy disk and then run.
So, how can I load the rest of the floppy into RAM and then run?
You don't need to be 100% accurate, I just need to know and learn the necessary interrupts and "functions" to do that I need :)
just to share the bootloader:
[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.
Upvotes: 4
Views: 1612
Reputation: 18521
To load data from floppy disk or hard disk interrupt 13 (hexadecimal) is used.
Using the interrupt with floppy disk is more complicated (function AH=2 - that can also be used with hard disks - uses C/H/S-Addressing of sectors) than using hard disks (function AH=0x42 - which is not present in very old BIOSes (before the year 2000) - can only be used together with hard disks and not with floppy disks).
To run C code you need a C compiler generating 16-bit code (maybe the Watcom C compiler is still able to do this) or you have to switch to 32-bit protected mode.
The WIKI at "osdev.org" is a good resource for OS programming where you'll find a lot of information.
Upvotes: 2