flat assembler
Message board for the users of flat assembler.

Index > OS Construction > LBA Write Sector Problem

Author
Thread Post new topic Reply to topic
Navic



Joined: 05 Mar 2007
Posts: 16
Location: USA
Navic 18 May 2007, 21:12
My write function writes one sector at a time without a problem, but when I create a loop to write multiple sectors a GPF will occur during random writes in the loop.... eg. one time it will write 5 sectors then GPF, next time 40 sectors then GPF, third time only 2 sectors then GPF, etc.

The difficult thing is that my read function is identical with the exception of command 20h, using EDI and INSW. When performing the same loop with read sector, it completes every time without error.

I've checked out some OS code that uses LBA writing in their file system, and it's pretty much the same as my code below, no signs of anything special that writing needs in which reading doesn't.

Does anyone know what I'm doing wrong? Is there perhaps some kind of controller reset I need to perform after each individual write? Thanks in advance!


Code:
;Write sectors 10,000 thru 10,100

 mov ebp,10000
rep_format:
    mov eax,ebp
 lea edi,[lba]
       stosd
       lea esi,[buffer]
    call hd_write_sector
        inc ebp
     cmp ebp,10100
       je looper
   jmp rep_format
looper:
       jmp looper




;Write Sector Function
hd_write_sector:
        cli
 push esi
    xor eax,eax
 mov dx,1F1h
 out dx,al
   mov dx,1F2h
 mov al,1
    out dx,al
   lea esi,[lba]
       lodsw
       inc dx
      out dx,al
           inc dx
      xchg al,ah
          out dx,al
           lodsw
       inc dx
      out dx,al
   xchg al,ah
          mov ah,0E0h
         add al,ah
           inc dx
      out dx,al
   inc dx
      mov al,30h
  out dx,al
waitwrite:
 in al,dx
    shl al,1
    jc waitwrite
        pop esi
     mov dx,1F0h
 mov ecx,100h
        cld
 rep outsw
   sti
 call hd_wait
        ret


;Hard Disk Wait Function
hd_wait:
     cli
 mov dx,1F7h
waitloop: 
       in al,dx
    cmp al,50h
  je waitok
   cmp al,0
    je waitok
        jmp waitloop
waitok:
    sti
 ret


;Variables and Buffers
lba dd 0
buffer times 512 db 24h
    
Post 18 May 2007, 21:12
View user's profile Send private message Reply with quote
Navic



Joined: 05 Mar 2007
Posts: 16
Location: USA
Navic 23 May 2007, 01:44
No thoughts.... I guess everyone just uses CHS disk I/O?
Post 23 May 2007, 01:44
View user's profile Send private message Reply with quote
Octavio



Joined: 21 Jun 2003
Posts: 366
Location: Spain
Octavio 23 May 2007, 08:06
Navic wrote:
No thoughts.... I guess everyone just uses CHS disk I/O?

I don“t see any bug ,perhaps it is in another part of the code.
use a debugger or try with bochs .
Post 23 May 2007, 08:06
View user's profile Send private message Visit poster's website Reply with quote
Navic



Joined: 05 Mar 2007
Posts: 16
Location: USA
Navic 24 May 2007, 07:01
i will, although emulators aren't the same as a real machine test. I was just wondering if anyone has written any LBA code that actually works. It seems every OS I find that deals with the hard drive uses CHS, which is old and very limited.
Post 24 May 2007, 07:01
View user's profile Send private message Reply with quote
Goplat



Joined: 15 Sep 2006
Posts: 181
Goplat 25 May 2007, 00:51
Intel's documentation says in/out don't give GPFs unless you're using a port you don't have access to, and in that case you would be getting it as soon as you started, not later. Is it possible that an interrupt handler isn't restoring DS or ESI properly?
Post 25 May 2007, 00:51
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
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 vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.