flat assembler
Message board for the users of flat assembler.

Index > OS Construction > PHBoot Program ???

Author
Thread Post new topic Reply to topic
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat
Heya all! My question currently is refferring to the PHBOOT example on the flat assembler site. Well, more or less two questions.

1. Is floppy drive memory @ 0x9000 (like the HD is based at 0xC8000)?
2. If I'm wrong with the first question, can someone please explain what it all is doing? So far with every FAT tutorial that I've read I've gotten lost. I know that hard disks/floppy drives are split up into 512 byte sectors and everything else is a bit blurry (read/write heads are used to put stuff on and read stuff from the HD/Floppy and that HDs are split up into cylinders which contain 512 byte sectors).

Sorry if I sound stupid with these questions, it's just been puzzling to me ever since I picked it up... I want to write my own filesystem and I would like to learn FAT so I can understand better how they work.

Thank you all again!

-Rhyno
Post 04 Dec 2006, 03:41
View user's profile Send private message Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat
Sorry if I came off a bit strong in the questions, but here's what I'm really wondering: How's it reading/writing to the diskette? I see not int 13h being used Razz
Post 05 Dec 2006, 00:02
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Quote:

I see not int 13h being used

Code:
read_linear_again:
        push    ax                      ;save ax; count can be destroyed? RIGHT
        mov     ah,02h                  ;read sectors
        int     13h                     ;BIOS disk interrupt
        jnc     short read_linear_ok    ;cool, no error (really?!! Cool )
    
Confused
Post 05 Dec 2006, 00:30
View user's profile Send private message Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat
... Of all the embarrassing things I could beat myself up about... Embarassed

Lo siento y gracias Loco!

One question though... How do I perform access to the hard disk in PMode?
Post 05 Dec 2006, 01:25
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Quote:

One question though... How do I perform access to the hard disk in PMode?

AFAIK, two options, backing to real mode to call int13 and then switching again to PMode or writing your own driver.

If you want to see some driver source code you can look at http://octaos.joox.net/ which has IDE support (written in OctaASM) and http://www.osdever.net/ for hardware reference.

Quote:

Lo siento y gracias Loco!

No hay problema Smile
Post 05 Dec 2006, 01:57
View user's profile Send private message Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat
Thanks again! Smile
Post 05 Dec 2006, 02:10
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u
To read/write to hdd is very easy, but it's the fat that will take more time, to get right.
Code:
;       Reading the harddisk using ports!;       +-------------------------------+   by qark;;;  This took me months to get working but I finally managed it.;;  This code only works for the 286+ so you must detect for 8088's somewhere;  in your code.;;  Technical Information on the ports:;      Port    Read/Write   Misc;     ------  ------------ -------------------------------------------------;       1f0       r/w       data register, the bytes are written/read here;       1f1       r         error register  (look these values up yourself);       1f2       r/w       sector count, how many sectors to read/write;       1f3       r/w       sector number, the actual sector wanted;       1f4       r/w       cylinder low, cylinders is 0-1024;       1f5       r/w       cylinder high, this makes up the rest of the 1024;       1f6       r/w       drive/head;                              bit 7 = 1;                              bit 6 = 0;                              bit 5 = 1;                              bit 4 = 0  drive 0 select;                                    = 1  drive 1 select;                              bit 3-0    head select bits;       1f7       r         status register;                              bit 7 = 1  controller is executing a command;                              bit 6 = 1  drive is ready;                              bit 5 = 1  write fault;                              bit 4 = 1  seek complete;                              bit 3 = 1  sector buffer requires servicing;                              bit 2 = 1  disk data read corrected;                              bit 1 = 1  index - set to 1 each revolution;                              bit 0 = 1  previous command ended in an error;       1f7       w         command register;                            commands:;                              50h format track;                              20h read sectors with retry;                              21h read sectors without retry;                              22h read long with retry;                              23h read long without retry;                              30h write sectors with retry;                              31h write sectors without retry;                              32h write long with retry;                              33h write long without retry;;  Most of these should work on even non-IDE hard disks.;  This code is for reading, the code for writing is the next article.        mov     dx,1f6h         ;Drive and head port        mov     al,0a0h         ;Drive 0, head 0        out     dx,al        mov     dx,1f2h         ;Sector count port        mov     al,1            ;Read one sector        out     dx,al        mov     dx,1f3h         ;Sector number port        mov     al,1            ;Read sector one        out     dx,al        mov     dx,1f4h         ;Cylinder low port        mov     al,0            ;Cylinder 0        out     dx,al        mov     dx,1f5h         ;Cylinder high port        mov     al,0            ;The rest of the cylinder 0        out     dx,al        mov     dx,1f7h         ;Command port        mov     al,20h          ;Read with retry.        out     dx,alstill_going:        in      al,dx        test    al,8            ;This means the sector buffer requires                                ;servicing.        jz      still_going     ;Don't continue until the sector buffer                                ;is ready.        mov     cx,512/2        ;One sector /2        mov     di,offset buffer        mov     dx,1f0h         ;Data port - data comes in and out of here.        rep     insw;   ------        mov     ax,201h         ;Read using int13h then compare buffers.        mov     dx,80h        mov     cx,1        mov     bx,offset buffer2        int     13h        mov     cx,512        mov     si,offset buffer        mov     di,offset buffer2        repe    cmpsb        jne     failure        mov     ah,9        mov     dx,offset readmsg        int     21h        jmp     good_exitfailure:        mov     ah,9        mov     dx,offset failmsg        int     21hgood_exit:        mov     ax,4c00h        ;Exit the program        int     21h        readmsg db      'The buffers match.  Hard disk read using ports.$'        failmsg db      'The buffers do not match.$'buffer  db      512 dup ('V')buffer2 db      512 dup ('L');;       Writing to the hard disk using the ports!     by qark;       +---------------------------------------+;;  The only differences between reading and writing using the ports is;  that 30h is sent to the command register, and instead of INSW you;  OUTSW.  ;        mov     dx,1f6h         ;Drive and head port        mov     al,0a0h         ;Drive 0, head 0        out     dx,al        mov     dx,1f2h         ;Sector count port        mov     al,1            ;Write one sector        out     dx,al        mov     dx,1f3h         ;Sector number port        mov     al,1           ;Wrote to sector one        out     dx,al        mov     dx,1f4h         ;Cylinder low port        mov     al,0            ;Cylinder 0        out     dx,al        mov     dx,1f5h         ;Cylinder high port        mov     al,0            ;The rest of the cylinder 0        out     dx,al        mov     dx,1f7h         ;Command port        mov     al,30h          ;Write with retry.        out     dx,aloogle:        in      al,dx        test    al,8            ;Wait for sector buffer ready.        jz      oogle        mov     cx,512/2        ;One sector /2        mov     si,offset buffer        mov     dx,1f0h         ;Data port - data comes in and out of here.        rep     outsw           ;Send it.;    ------------        mov     ax,201h                 ;We'll read in sector 1 using        mov     bx,offset buffer2       ;int13h and see if we are successful.        mov     cx,1        mov     dx,80h        int     13h        mov     cx,512        mov     si,offset buffer        mov     di,offset buffer2        repe    cmpsb                   ;Compare the buffers.        jne     failure        mov     ah,9        mov     dx,offset write_msg        int     21h        jmp     w_exitfailure:        mov     ah,9        mov     dx,offset fail        int     21hw_exit:        mov     ax,4c00h        ;Exit the program        int     21h        write_msg       db      'Sector one written to using the ports, OH NO! there goes XP.$'        fail            db      'Writing using ports failed.$'buffer  db      512 dup ('A')buffer2 db      512 dup ('D')    

NOTE: THE ABOVE CODE WILL OVER WRITE YOUR MBR, so do not run with above settings. So do not use the write part untill you have better understanding.

Here my pmode floppy driver writen in fasm, commented to go with intels pdf for floppy controler : http://www.dex4u.com/DexFloppy/FloppyDriver.zip
Post 05 Dec 2006, 02:59
View user's profile Send private message Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat
Thanks Dex!

Edit: It said inside of that that it was apparently one article out of two or more, do you by any chance have the site where I can get those from directly?
Post 05 Dec 2006, 06:25
View user's profile Send private message Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat
Wow.... Nevermind... I found it in my OSDev docs folder on my HD... that was the file I was looking for!!!!! I thought it was pdf though. I knew I had seen that file before, just not sure where. Thanks though! I have the whole thing there on my HD, so I'm looking at it Smile
Post 05 Dec 2006, 06:55
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-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.