0

I am working on this 'how to build an os':

https://www.cs.bham.ac.uk/~exr/lectures/opsys/10_11/lectures/os-dev.pdf

I am testing my code using qemu. I am at a part of the code where I am using bios system calls to read from memory. This is the section of the code that makes the call.

disk_load :
    push dx ; Store DX on stack so later we can recall

    ; how many sectors were request to be read ,
    ; even if it is altered in the meantime
    mov ah, 0x02 ; BIOS read sector function
    mov al, dh ; Read DH sectors
    mov dh, 0x00 ; Select head 0


    mov ch, 0x00
    mov cl, 0x02 ; Start reading from second sector 

    int 0x13 ; BIOS interrupt

    jc disk_error ; Jump if error ( i.e. carry flag set )

    pop dx ; Restore DX from the stack
    cmp dh , al ; if AL ( sectors read ) != DH ( sectors expected )
    jne disk_error ; display error message
    ret

disk_error :
    mov bx, DISK_ERROR_MSG
    call print_string
    jmp $

DISK_ERROR_MSG:
    db "Disk read error", 0

I copied exactly what was posted in the tutorial and I doubled checked everything to make sure it makes sense. It should work, but when I run the code, the carry flag is set and the disk_error function gets called. I checked the value of register ah for the return value, which was 0xc. I looked up that value and if I understand correctly, it means the floppy disk was not found.

The thing is, when I comment out the error check, the memory read is actually successful. I completed the tutorial and I was able to successfully boot my kernel from memory.

What is happening? Why am I getting an error flag and return value saying the disk could not be found if the read is actually successful?

Handcre
  • 15
  • 1
  • 6
  • *the memory read is actually successful* You mean the disk read *into* memory, right? – Peter Cordes Oct 26 '16 at 13:24
  • What commands did you use to build the disk image and what command did you use to launch QEMU? Earlier in the year an [SO question](http://stackoverflow.com/questions/36562268/triple-fault-when-jumping-into-protected-mode) appeared about that tutorial. I went through the tutorial and produced this set of code (archive of source files): http://www.capp-sysware.com/misc/stackoverflow/36562268/adotout1.tgz . I'm curious if you have the same problems with those files? – Michael Petch Oct 26 '16 at 15:34
  • 1
    I'm actually not a fan of this tutorial because it makes some false assumptions about the nature of the segment registers when it starts, and it does an improper job of setting up the stack pointer. – Michael Petch Oct 26 '16 at 15:39
  • Unless you posted all your code it may be difficult to determine why your code specifically is failing. – Michael Petch Oct 26 '16 at 15:42
  • Hi guys, thank you for responding. I will try to run your code and see if I still get the disk read error. If so I assume that the problem is just the way that qemu is set up by default. Will get back to you. – Handcre Oct 27 '16 at 14:59

0 Answers0