Page 1 of 1

[Booting] HDD emulated CD

Posted: Sun Apr 15, 2012 6:16 am
by Dennis
Hello everyone,

Story:
I'm a beginning OS developer.
I just made it such far my own bootloader (on sector 1 of floppy) can load the kernel (on sector 2 of floppy).
Now I want to get rid of the floppy usage and step over to hard disk.
But to write the 2 sectors to a harddisk every time is much work, so I should like to emulate a HDD on a CD with El Torito.
I use Nero Burning ROM 10 to write my bootloader and kernel to the CD.
Emulated as 2.88 MB Floppy it works, it can load it from drive 0x0, which is the emulated floppy.

Problem:
Now the problem is when I make an emulated HDD from it and read the kernel from drive 0x80 (which is the emulated HDD) it won't work.
I think I don't know how to read from a HDD. (the emulated CD)
I hope someone could give me more explanation about this.

Thanks in advance,

Dennis

This is all code:

bootloader.asm:

Code: Select all

[BITS 16]
[ORG 0x7C00]

MOV DL, 0x80 ;0x80 = HDD 1 (emulated CD)
MOV DH, 0x0 ;head (0=base)
MOV CH, 0x0 ;track/cylinder
MOV CL, 0x02 ;sector (1=bootloader, apparently sectors starts counting at 1 instead of 0)
MOV BX, 0x1000 ;place in RAM for kernel - I suppose randomly chosen on examples
MOV ES, BX ;place BX in pointer ES
MOV BX, 0x0 ;back to zero - also has something to do with RAM position

ReadFloppy:
MOV AH, 0x02
MOV AL, 0x01
INT 0x13
JC ReadFloppy ;if it went wrong, try again

;pointers to RAM position (0x1000)
MOV AX, 0x1000
MOV DS, AX
MOV ES, AX
MOV FS, AX
MOV GS, AX
MOV SS, AX

JMP 0x1000:0x0

;assuming we get never back here again, so no further coding needed (kernel handles everything now)

TIMES 510 - ($ - $$) db 0 ;fill resting bytes with zero
DW 0xAA55 ;end of bootloader (2 bytes)
kernel.asm:

Code: Select all

;set print-registers
MOV AH, 0x0E ;function nr
MOV BH, 0x00 ;page
MOV BL, 0x07 ;color

MOV SI, msg ;move msg to SI-pointer
CALL PrintString ;call function to print SI (msg)

JMP $ ;hang

PrintString:
.next_char:
MOV AL, [SI] ;current character
OR AL, AL
JZ .exit_char ;if current char is zero, go to end
INT 0x10 ;print character
INC SI ;increase pointer to msg (next character)
JMP .next_char
.exit_char:
RET

msg db 'Hello world from the kernel!', 13, 10, 0

TIMES 512 - ($ - $$) db 0 ;fill the rest
How to assemble and combine (under Windows):

Code: Select all

nasm bootloader.asm -o boot.bin
nasm kernel.asm -o kernel.bin
copy boot.bin x.img
type kernel.bin >> x.img
This creates "x.img" which I burn to the CD (emulated as HDD) with Nero Buring ROM.

Re: [Booting] HDD emulated CD

Posted: Sun Apr 15, 2012 8:15 am
by bubach
Why do you manually set DL to drive number? It should be set by the BIOS at boot. Also how can you know that the emulated hdd is 0x80, do you not have any real hdds in the machine? It could be 0x81 if you already have a hdd.

Re: [Booting] HDD emulated CD

Posted: Sun Apr 15, 2012 9:10 am
by Dennis
I thought I had to set DL manually. I also did this with booting from real floppies and emulated floppies. (Then at 0x0)

I assumed that the emulated HDD is at 0x80 because at: http://en.wikipedia.org/wiki/El_Torito_ ... _standard)
The drive number assigned is either 80 (hard disk emulation), 00 (floppy disk emulation) or an arbitrary number if the BIOS should not provide emulation.
But I've also tested it with 0x81.

I didn't know the BIOS should set DL himself.
Now I will test it without setting DL.

Re: [Booting] HDD emulated CD

Posted: Sun Apr 15, 2012 10:07 am
by Dennis
Yay! It worked! :D
Many thanks for your help.

I'll experiment further with this.