Been lurking and admiring for a while now, was put off joining by a guy in an IRC who said I wouldn't make much progress learning and getting 'RTFM' on each question. Everyone seems nice enough and I'm in dire need of help so I've had to take the plunge.
I have a quick question regarding Virtual Machine BIOS and disk image structure.
I tried OS dev a while back, years ago I was about 15. I was going to sign up due to a problem I was having. Alas, 7 years later I still got stuck in the same spot and it's really been pulling my teeth out.
I cannot for the life of me load a sector from an image into memory on a VM.
Here is my code to read the second sector on disk, should know it like the back of your hand:
Code: Select all
mov ax, 0x1000 ; we are going to read sector to into address 0x1000:0
mov es, ax;
xor bx, bx;
mov ah, 0x02 ; read floppy sector function
mov al, 1 ; read 1 sector
mov ch, 0 ; we are reading the second sector past us, so its still on track 1
mov cl, 2 ; sector to read (The second sector)
mov dh, 0 ; head number
mov dl, [start_drive] ; drive number. Remember Drive 0 is floppy drive.
int 0x13 ; call BIOS - Read the sector
jc .Reset;
mov si, load_ok;
call Print;
jmp 0x1000:0 ; jump to execute the sector!
It prints out the message right before jumping to the next sector, when it reaches the other side, it's supposed to print again saying we're in the next sector, but rather it seems it passes the Print function, and goes straight to halt. Here is my sector 2:
Code: Select all
; Sector 2 - Loader continued
bits 16;
jmp kernel_main;
Print:
lodsb ; load next byte from string from SI to AL
or al, al ; Test for null terminator
jz .Done;
mov ah, 0eh;
int 10h
jmp Print ; Repeat until done
.Done:
ret;
kernel_main:
mov si, kernel_msg;
call Print;
cli;
hlt;
kernel_msg db "Kernel loaded at 0x1000:0",0;
times 512 - ($-$$) db 0;
VirtualBox allows me to plug the binary file from nasm ( For instance nasm -o boot.bin ) directly into the floppy drive source. It loaded, and the messages printed out. This has lead me to believe that the VM BIOS is able to see the image, and use it's own function(13hF2 ) to load the first sector on the disk ( Which would be the only one at this point ) to 0x7c00. All good and gravy.
So now my image is basically made from 2 sectors, being 512 bytes each, and concatenated in series to produce a 1024 binary file.
Is my image format flawed? I thought it was safe to assume if I had made my second file exactly 512 bytes long I would of essentially made the second sector, for the boot sector to load it with int 13h.
I even wrote my own hex viewer ( As a break away from the assembly, I thought I may have been missing something ) and everything seems okay, I saw the 55 AA at the end of the first sector, then started the code from the second file, padded with zeros to the end. I copied by bytes into a converter and the instructions came out crystal saying it is doing exactly what it should be doing.
int 13hF2 is supposed to set the carry if it fails, doesn't fail. So success, right? I'm not so sure, AL is supposed to hold the amount of sectors actually read, when I test against it, it fails, didn't read the sector.
I've just realised how long I have been writing for. I'm completely stumped believe me I've been trying. I'll have a smoke a leave it with you.
Rob.