Page 2 of 2
Re: Can't load kernel from floppy
Posted: Tue May 21, 2013 4:32 am
by embryo
Blacklight wrote:Fifty invisible internet dollars on INT 13h, AH=42h
You have won
Blacklight wrote:Which wouldn't work, anyways, because it only works for hard disks, and even then, may not be supported by all BIOSes.
There is mentioning about "non-LBA devices" in the function description. But I haven't tested it with floppies. At least - not too much work for another attempt to catch the bug.
Re: Can't load kernel from floppy
Posted: Tue May 21, 2013 8:15 am
by Prochamber
embryo wrote:Blacklight wrote:Fifty invisible internet dollars on INT 13h, AH=42h
You have won
You should be more specific than "int 42" next time.
embryo wrote:Blacklight wrote:Which wouldn't work, anyways, because it only works for hard disks, and even then, may not be supported by all BIOSes.
There is mentioning about "non-LBA devices" in the function description. But I haven't tested it with floppies. [/quote]
Hmm...
"The addresses of interesting sectors on a disk are almost always calculated as LBAs, but some drives (especially USB flash drives doing floppy emulation) cannot use LBA addressing." --- ATA in Read Mode
"Floppy drives use CHS addressing exclusively." --- Floppy Disk Controller
It's a little unclear. It may work on some systems through a BIOS doing an internal translation and probably in emulators. I wouldn't recommend using LBA BIOS functions for floppy disks.
Re: Can't load kernel from floppy
Posted: Tue May 21, 2013 7:39 pm
by matt8110
So then it goes
Head 0, Track 0,
Head 1, Track 0,
Head 0, Track 1,
Head 1, Track 1?
And is there any way to load from a CD instead, i am happy with a floppy but it is a bit limited space wise.
Re: Can't load kernel from floppy
Posted: Wed May 22, 2013 1:40 am
by Prochamber
matt8110 wrote:So then it goes
Head 0, Track 0,
Head 1, Track 0,
Head 0, Track 1,
Head 1, Track 1?
Yep, and the sector goes from 1-18 for each one. Be warned, the sectors number in a CHS address starts at one
not zero like everything else.
In a standard 1440 KB floppy you have 512 bytes in a sector, 18 sectors per track, 80 tracks per side and of course two sides.
512 * 18 * 80 * 2 = 1,474,560 bytes = 1440 KB
matt8110 wrote:And is there any way to load from a CD instead, i am happy with a floppy but it is a bit limited space wise.
I'd recommend you start off on a floppy disk, they are a fairly simple disk to start off with. Try to implement support for the FAT12 file system in your bootloader.
There's more than enough space on a floppy disk for most hobby operating system kernels, i.e. I've got over 10,000 lines of assembly and it still fits in 64k.
However, when you plan to support things like images of a decent resolution, these usually take up a fair bit of space and floppy disks are quite slow on real hardware.
I wouldn't recommend using a CD as your operating system will not be able to save/modify any files without a special disk burning program. Even then most disks can only be burnt once.
If you need more space I'd suggest using a USB Flash Drive or a Hard Drive partition.
Re: Can't load kernel from floppy
Posted: Wed May 22, 2013 2:21 pm
by matt8110
How would i go about reading the root directory?
Re: Can't load kernel from floppy
Posted: Wed May 22, 2013 4:32 pm
by sortie
It's called a filesystem. Find the specification for the filesystem you will be using and implement a driver that parses it and offers a copy-logical-file-offset-to-memory routine.
Re: Can't load kernel from floppy
Posted: Wed May 22, 2013 5:07 pm
by Prochamber
matt8110 wrote:How would i go about reading the root directory?
First things first, you need to have a file system in your boot sector or there won't be a root directory to load, FAT12 is the most common for floppy disks.
The idea is that you start with a short jump to the start of your kernel, then have bunch of data values, then your bootloader. You can look at this on the OSDev Wiki page on the
FAT filesystem. Your bootloader should include the BIOS Parameter Block, the Extended Boot Record and of course the boot code. You might want to read the page on
creating a bootloader.
Re: Can't load kernel from floppy
Posted: Fri May 24, 2013 6:58 pm
by matt8110
Now i have a new question, and this is probably a stupid one
Can i do this in my kernel
mov al, 'A'
mov ah, 0x0e
int 0x10
Or do i need to specify bits and org? I am asking because i do not see why i would need to, but i am not sure.
Re: Can't load kernel from floppy
Posted: Fri May 24, 2013 10:06 pm
by matt8110
It is not even loading from the floppy, i decided to try and reload my bootloader and jump to it to see if it was loading, it is not working but the carry flag is not getting set, i don't get it.
I am using VirtualBox, i am not sure if it has something to do with that, also i am using VFD for the floppy.
My code just in case
Code: Select all
bits 16
org 0x7c00
jmp main
main:
call ResetFloppy
call LoadKernel
jmp 0:0x7e00
ResetFloppy:
;Reset floppy drive
mov si, ResettingFloppy
call PrintString
mov ah, 0x00
int 0x13
jc ResetFloppy
jnc Return
LoadKernel:
;Load kernel
mov si, LoadingFloppy
call PrintString
mov ah, 0x02 ;Function
mov al, 0x01 ;Sectors to read
mov ch, 0x00 ;Track
mov al, 0x00 ;Sector
mov dh, 0x00 ;Head
mov dl, 0x00 ;Drive
xor bx, bx ;Setting it to zero
mov es, bx ;Setting left
mov bx, 0x7E00 ;Setting right
jc LoadKernel
jnc Return
PrintString:
mov al, [si]
cmp al, 0
je Return
mov ah, 0x0e
int 0x10
inc si
jmp PrintString
Return:
ret
hang:
jmp hang
ResettingFloppy db "Resetting Floppy",0
LoadingFloppy db "Loading Kernel",0
times 510 - ($-$$) db 0
dw 0xAA55
Re: Can't load kernel from floppy
Posted: Fri May 24, 2013 11:57 pm
by Prochamber
matt8110 wrote:Can i do this in my kernel
mov al, 'A'
mov ah, 0x0e
int 0x10
Or do i need to specify bits and org? I am asking because i do not see why i would need to, but i am not sure.
No, there aren't any restrictions on it.
matt8110 wrote:It is not even loading from the floppy, i decided to try and reload my bootloader and jump to it to see if it was loading, it is not working but the carry flag is not getting set, i don't get it.
Code: Select all
mov ch, 0x00 ;Track
mov al, 0x00 ;Sector
mov dh, 0x00 ;Head
Did you forget that the sector number in CHS ranges from 1-18? Or perhaps that it is stored in the CL not AL register?
Fix it and try again.
Re: Can't load kernel from floppy
Posted: Sat May 25, 2013 12:04 am
by matt8110
Or perhaps that it is stored in the CL not AL register?
That's embarrassing, and yes i forgot that it started at 1, but correcting both of those errors did not help, i don't get it.
EDIT: I feel incredibly stupid! I forgot to call the interrupt, god i suck at OS development!
Re: Can't load kernel from floppy
Posted: Sun May 26, 2013 1:00 pm
by Mikemk
matt8110 wrote:EDIT: I feel incredibly stupid! I forgot to call the interrupt, god i suck at OS development!
Happens to the best of us.