OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 6:48 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: INT 13,2 - Read Disk Sectors Error
PostPosted: Sat Jan 12, 2019 3:34 pm 
Offline

Joined: Fri Jan 11, 2019 5:55 am
Posts: 6
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


Last edited by NullByte on Sun Jan 13, 2019 5:27 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: INT 13,2 - Read Disk Sectors Error
PostPosted: Sat Jan 12, 2019 5:43 pm 
Offline
Member
Member

Joined: Fri Aug 26, 2016 1:41 pm
Posts: 671
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.


Top
 Profile  
 
 Post subject: Re: INT 13,2 - Read Disk Sectors Error
PostPosted: Sat Jan 12, 2019 6:15 pm 
Offline

Joined: Fri Jan 11, 2019 5:55 am
Posts: 6
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


Top
 Profile  
 
 Post subject: Re: INT 13,2 - Read Disk Sectors Error
PostPosted: Sat Jan 12, 2019 8:59 pm 
Offline
Member
Member

Joined: Fri Aug 26, 2016 1:41 pm
Posts: 671
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!


Top
 Profile  
 
 Post subject: Re: INT 13,2 - Read Disk Sectors Error
PostPosted: Sun Jan 13, 2019 5:27 am 
Offline

Joined: Fri Jan 11, 2019 5:55 am
Posts: 6
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.


Top
 Profile  
 
 Post subject: Re: INT 13,2 - Read Disk Sectors Error
PostPosted: Sun Jan 13, 2019 6:38 am 
Offline
Member
Member

Joined: Fri Aug 26, 2016 1:41 pm
Posts: 671
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.


Top
 Profile  
 
 Post subject: Re: INT 13,2 - Read Disk Sectors Error
PostPosted: Sun Jan 13, 2019 11:09 am 
Offline

Joined: Fri Jan 11, 2019 5:55 am
Posts: 6
Up


Top
 Profile  
 
 Post subject: Re: INT 13,2 - Read Disk Sectors Error
PostPosted: Sun Jan 13, 2019 1:46 pm 
Offline
Member
Member

Joined: Fri Aug 26, 2016 1:41 pm
Posts: 671
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).


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 62 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group