OSDev.org https://forum.osdev.org/ |
|
INT 13,2 - Read Disk Sectors Error https://forum.osdev.org/viewtopic.php?f=1&t=33432 |
Page 1 of 1 |
Author: | NullByte [ Sat Jan 12, 2019 3:34 pm ] |
Post subject: | INT 13,2 - Read Disk Sectors Error |
Hi guys, I try read ascii text from sector but I didn't. I can't see anything on the screen Updated. build.sh Code: #!/bin/bash echo 'Starting.' nasm -f bin boot.asm -o boot.bin nasm -f bin stage2.asm -o stage2.bin dd if=boot.bin of=loader.img bs=512 count=1 dd if=stage2.bin of=loader.img bs=512 count=7 seek=1 dd if=asd.txt of=loader.img bs=512 count=1 seek=7 rm boot.bin rm stage2.bin echo 'OK!' qemu-system-x86_64 -fda loader.img asd.txt Code: Helloooo boot.asm Code: ; initialize the environment mov ax, 0x07c0 mov ds, ax ; the segment of the stage2 mov ax, 0x07e0 mov ch, 0x00 mov cl, 0x02 mov dh, 0x00 mov dl, 0x00 mov es, ax mov bx, 0x0000 read: mov al, 0x07 mov ah, 0x02 int 0x13 jc read mov ax, 0x07e0 mov ds, ax mov es, ax mov fs, ax mov gs, ax mov ss, ax jmp 0x07e0:0x0000 times 510 - ($ - $$) db 0 dw 0xaa55 stage2.asm Code: start:
mov ax, 0x7e00 mov ss, ax mov sp, 0x2000 mov al, 0x03 mov ah, 0x00 int 0x10 call clearScreen push 0x0000 call moveCursor add sp, 0x2 push INTRO call print add sp, 0x2 mov ah, 0x0 int 0x16 call clearScreen push 0x0000 call moveCursor add sp, 0x2 push HEADER call print add sp, 0x2 call checkDisk call readInput ; cli ; hlt checkDisk: pusha mov ah, 0x2 mov al, 0x1 mov cl, 0x8 mov ch, 0x0 mov dh, 0x0 mov dl, 0x0 int 0x13 jc diskError push bx call print popa ret diskError: pusha push DISK_ERROR call print popa ret clearScreen: push bp mov bp, sp pusha mov ah, 0x7 mov al, 0x0 mov bh, 0x4 mov cx, 0x0 mov dh, 0x18 mov dl, 0x4F int 0x10 popa mov sp, bp pop bp ret moveCursor: push bp mov bp, sp pusha mov dx, [bp+4] mov ah, 0x2 mov bh, 0x0 int 0x10 popa mov sp, bp pop bp ret print: push bp mov bp, sp pusha mov si, [bp+4] mov bh, 0x0 mov bl, 0x0 mov ah, 0x0e .char: mov al, [si] add si, 1 or al, 0x0 je .return int 0x10 jmp .char .return: popa mov sp, bp pop bp ret readInput: xor ax,ax readInputLoop: xor ax,ax int 0x16 ; cmp al, 0x8 ; Backspace ; je backSpace cmp al, 0x0D ; Enter je readInputEnd call putChar mov BYTE [es:KEY_OFFSET + bx], al inc bl cmp bl, KEY_SIZE jne readInputLoop readInputEnd: ;backSpace: putChar: push bx mov ah, 0x0e xor bx, bx int 0x10 pop bx ret DISK_ERROR: db 'Disk read error', 0x0 DISK_ERROR1: db 'Disk write error', 0x0 SECTORS_ERROR: db "Incorrect number of sectors read", 0 INTRO: db '', 0xA, 0xD db '', 0xA, 0xD db '', 0xA, 0xD db '', 0xA, 0xD db '', 0xA, 0xD db '', 0xA, 0xD db '', 0xA, 0xD db '', 0xA, 0xD db '', 0xA, 0xD db '', 0xA, 0xD db '', 0xA, 0xD db '', 0xA, 0xD db '', 0xA, 0xD db '', 0xA, 0xD db '', 0xA, 0xD db '', 0xA, 0xD db '', 0xA, 0xD db '', 0xA, 0xD db '', 0xA, 0xD db '', 0xA, 0xD db '', 0xA, 0xD db '', 0xA, 0xD db '', 0xA, 0xD db '', 0xA, 0xD db '', 0xA, 0xD db '', 0xA, 0xD db 'Press any key...', 0x0 HEADER: db 'Simple Bootloader', 0xA, 0xD, 0xA, 0xD, 'jkljkl', 0xA, 0xD, 0xA, 0xD, 'kjljkl', 0xA, 0xD, 0xA, 0xD, 'jkl', 0xA, 0xD, 0xA, 0xD, 'jkljkl', 0xA, 0xD, 0xA, 0xD, 'jkljkl', 0xA, 0xD, 0xA, 0xD, 'jkljkl', 0xA, 0xD, 'asdasd', 0xA, 0xD, 0xA, 0xD, 'asdasd', 0xA, 0xD, 0xA, 0xD, 'asd', 0x0 KEY_OFFSET equ 0x500 KEY_SIZE equ 0x50 times 3584 - ($ - $$) db 0x0 |
Author: | MichaelPetch [ Sat Jan 12, 2019 5:43 pm ] |
Post subject: | Re: INT 13,2 - Read Disk Sectors Error |
There really isn't enough to go on here.It may be because you didn't set the segments properly, that you may be using the wrong origin point (ORG), there might be a problem in your print routine. It's unclear that when you do the disk read that ES:BX are set properly. Show us all the code for your boot sector and your second stage (and anything those files include) and we'd be able to tell you what is wrong. I do highly recommend installing and leaning to use BOCHs and its debugger. You can step through the code an instruction at a time;look at memory; set breakpoints;look at segment and general purpose registers. You'd likely find the problem on your own. I recommend BOCHs for debugging this since it deals with real mode code very well. |
Author: | NullByte [ Sat Jan 12, 2019 6:15 pm ] |
Post subject: | Re: INT 13,2 - Read Disk Sectors Error |
MichaelPetch wrote: There really isn't enough to go on here.It may be because you didn't set the segments properly, that you may be using the wrong origin point (ORG), there might be a problem in your print routine. It's unclear that when you do the disk read that ES:BX are set properly. Show us all the code for your boot sector and your second stage (and anything those files include) and we'd be able to tell you what is wrong. I do highly recommend installing and leaning to use BOCHs and its debugger. You can step through the code an instruction at a time;look at memory; set breakpoints;look at segment and general purpose registers. You'd likely find the problem on your own. I recommend BOCHs for debugging this since it deals with real mode code very well. Thanks for reply. Bootloader is running successfully and successfully passes to second stage. There is no problem here. A problem occurs when I call checkMsg. I did not understand what happened. I try BOCHs for debugging. Thanks |
Author: | MichaelPetch [ Sat Jan 12, 2019 8:59 pm ] |
Post subject: | Re: INT 13,2 - Read Disk Sectors Error |
NullByte wrote: Thanks for reply. Bootloader is running successfully and successfully passes to second stage. There is no problem here. A problem occurs when I call checkMsg. I did not understand what happened. I try BOCHs for debugging. Thanks I've heard that before and seen code that may appear to work but when certain things are done later on it doesn't work as expected. As well your print function isn't something you show,so again we can't say. If you provided all your code it probably wouldn't take long for myself or someone else here to pinpoint the problem. Hopefully you'll discover the problem in BOCHs. If you still have difficulty you can return here and let us see the code. Good luck!
|
Author: | NullByte [ Sun Jan 13, 2019 5:27 am ] |
Post subject: | Re: INT 13,2 - Read Disk Sectors Error |
MichaelPetch wrote: NullByte wrote: Thanks for reply. Bootloader is running successfully and successfully passes to second stage. There is no problem here. A problem occurs when I call checkMsg. I did not understand what happened. I try BOCHs for debugging. Thanks I've heard that before and seen code that may appear to work but when certain things are done later on it doesn't work as expected. As well your print function isn't something you show,so again we can't say. If you provided all your code it probably wouldn't take long for myself or someone else here to pinpoint the problem. Hopefully you'll discover the problem in BOCHs. If you still have difficulty you can return here and let us see the code. Good luck!I add my codes in first post. |
Author: | MichaelPetch [ Sun Jan 13, 2019 6:38 am ] |
Post subject: | Re: INT 13,2 - Read Disk Sectors Error |
The thing that stands out to me is in checkDisk function. You seem to not have set BX to an offset to read into.So it is using the previous value of BX which I believe is 0. Since ES is 0x7e0 at that point you are reading your disk sectors to address 0x7e0:0x0000 which is on top of where you loaded your second stage already. So when the disk read returns all the previous code for stage2 is now gone so it will start executing the bytes that were loaded from sector 8 which are probably mostly zeroes. I suggest you set BX to some value that won't clobber your running code or the stack you set. |
Author: | NullByte [ Sun Jan 13, 2019 11:09 am ] |
Post subject: | Re: INT 13,2 - Read Disk Sectors Error |
Up |
Author: | MichaelPetch [ Sun Jan 13, 2019 1:46 pm ] |
Post subject: | Re: INT 13,2 - Read Disk Sectors Error |
one quick fix would be to set BX to an address after existing code.Since you read 7 sectors in for stage 2 starting at the beginning of the segment 0x07e0 then you could place the text in memory after that at ES:BX = 0x07c0:(7*512).So before you call checkDisk (or in checkDisk before the int 0x13) do a mov bx, 7*512. You may want to read the Starman article on 20-bit segment:offset addressing in real mode to get a better understanding how segments and offsets relate to physical memory. There are some indications in the code that you may be new to this segment:offset addressing (ie: the values you use for the stack pointer are peculiar - although valid, using ES:BX as a memory pointer for disk reads etc). |
Page 1 of 1 | All times are UTC - 6 hours |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |