flat assembler
Message board for the users of flat assembler.

Index > OS Construction > HD disk system

Goto page Previous  1, 2
Author
Thread Post new topic Reply to topic
edfed



Joined: 20 Feb 2006
Posts: 4354
Location: Now
edfed 25 Feb 2009, 17:37
Code:
explore dd f.gnode,0,0,320,200,@f-$-4
        dd .view
        dd .box
        @@:
.box    dd f.box,0,0,320,200,Red
.view   dd f.asm,@f,.path,.disp
        @@:
        push eax ebx ecx edx
        pop edx ecx ebx eax
        ret
.disp   dd f.null,0,0,0,0,0,0,0,0  ;will be used to display icons and text.
.path   rb 100h
        db 0    
    

the function do explore the folders from a single path will be explore.view.
the coding of this one is in progress, and remark:
i use the f.asm function to elaborate new functions.
after, it will be renamed f.fsview.
the goal is to be able to display the content of a file or folder.
if it is a file, it will be displayed in hexadecimal
if it is a folder, it will be displayed as a list of files.
a simple command line is still there just to input paths.
Post 25 Feb 2009, 17:37
View user's profile Send private message Visit poster's website Reply with quote
dosin



Joined: 24 Aug 2007
Posts: 337
dosin 25 Feb 2009, 19:50
edfed - are you using int 13h?

wont that limit it to 8 gigabytes on drives??

I think I am going to start with IDE drives .. detect number of drives and format my new disk with 4 portions.. and detect them.. for a start...

The 1st program is going to be kind of like grub booted from a floppy or CD
/DVD and try and boot XP and Vista from it..

if anyone knows of any good reading material or anything.. I have found some good info ,, but the more the better.. any pointers or any advice.. please share- even if you think there is a better way to start,, I am allways open for input - good or bad.. lol


Thanks to anyone wanting to contribute or help with this project!
Post 25 Feb 2009, 19:50
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4354
Location: Now
edfed 26 Feb 2009, 09:51
dosin wrote:
edfed - are you using int 13h?

wont that limit it to 8 gigabytes on drives??


i use f.disk that use int13h for the moment.
and yes, it limits the drive to 8GB, the size of my bigger USB pen. Smile

but it is not a problem because f.disk is limited to 2TB and as the revolution's contest say: use of BIOS/DOS ints is forbidden.

about the f.disk function and my bootloader, it will load a .com binary from the floppy, somewhere in RM ram, execute it, and when it will finish this program, it will load the boot sector from the first drive (C: ) and then, it is like a reboot with another OS, tested with 98 and XP, OK!
but 98, DOS and XP don't do that Sad
it would be easy to imagine a multidrive boot selector based on this principle.
Post 26 Feb 2009, 09:51
View user's profile Send private message Visit poster's website Reply with quote
tom tobias



Joined: 09 Sep 2003
Posts: 1320
Location: usa
tom tobias 26 Feb 2009, 12:49
dosin wrote:
...if anyone knows of any good reading material or anything...
http://suif.stanford.edu/~csapuntz/ide.html
has a link to a full specification for programming PCI IDE controllers.

http://www.geocities.com/siliconvalley/2072/atapi.htm
(accessing the two IDE controllers found on typical motherboards, since the mid 1990's, elaborates the different locations within each register on the IDE controllers corresponding to control of the read/write functions for the individual controllers on the hard drive itself.)

chapter 9 of Master Class Assembly Language Programming offers some information of utility, despite a focus on FAT.
http://openlibrary.org/b/OL8655157M

Here is the web location of all the documents from the Technical Committee for the ATA interface.
http://www.t13.org/
Post 26 Feb 2009, 12:49
View user's profile Send private message Reply with quote
dosin



Joined: 24 Aug 2007
Posts: 337
dosin 26 Feb 2009, 15:58
Excellent! I love information...

http://en.wikipedia.org/wiki/Master_boot_record

On here I found a program thats named HxD its a hex editor that will read the entire Disk drive selected in Vista,XP ect.. and reads all the sectores.. and what is in each sector of the disks on my computers..

and a lot of other info on MBR and Drives ...

edfed... even though your using that now.. you have a bases for it.. switching it from 13h should not be that hard... you have a good idea.
and a good start on the code..! Very Happy

cant wait until I get that far!

I have the shell of the program ready..
now for the important stuff.. Very Happy
Post 26 Feb 2009, 15:58
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u 27 Feb 2009, 18:07
Read/writing raw sectors is very easy from pmode without using bios
NOTE: DO NOT USE THIS CODE AS IS, TO WRITE SECTORS OR YOU WILL LOSE YOU MBR.
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,al
still_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_exit
failure:
   mov     ah,9
   mov     dx,offset failmsg
   int     21h
good_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,al
oogle:
   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_exit
failure:
   mov     ah,9
   mov     dx,offset fail
   int     21h

w_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')
    

Its the fat16/32 driver thats harder to code.
Hope this helps.
Post 27 Feb 2009, 18:07
View user's profile Send private message Reply with quote
dosin



Joined: 24 Aug 2007
Posts: 337
dosin 27 Feb 2009, 19:18
Thanks Dex..
have you ever tried these?

Quote:
Its the fat16/32 driver thats harder to code

This will not be a problem.. Since it will be based on a new filesystem..
Post 27 Feb 2009, 19:18
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u 28 Feb 2009, 02:39
Yes in my OS i have two methods to read/write hdd, one go back to realmode for using bios int 13h and the other using the above code.

PS: You can use this simple demo to test it
Code:
;************************************
; By Dex
; Assemble with fasm
; c:\fasm Hdd.asm Hdd.bin
;
;************************************
org 0x7C00
use16
;****************************
; Realmode startup code.
;****************************
start:
        xor   ax,ax
        mov   ds,ax
        mov   es,ax
        mov   ss,ax
        mov   sp,0x7C00
;*****************************
; Setting up, to enter pmode.
;*****************************
        cli
        lgdt  [gdtr]
        mov   eax, cr0
        or    al,0x1
        mov   cr0,eax
        jmp   0x10: protected
;*****************************
; Pmode. Wink
;*****************************
use32
protected:
        mov   ax,0x8
        mov   ds,ax
        mov   es,ax
        mov   ss,ax
        mov   esp,0x7C00
;*****************************
; Turn floppy off (if space).
;*****************************
        mov   dx,3F2h
        mov   al,0
        out   dx,al
;*********************************
; Print T in the right hand corner
;*********************************
        mov   byte [es:0xB809E], "1"

        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,al
        mov   byte [es:0xB809E], "2"
still_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   byte [es:0xB809E], "3"

        mov   ecx,512/2        ;One sector /2
        mov   edi,buffer
        mov   dx,1f0h         ;Data port - data comes in and out of here.
        rep   insw

        mov   byte [es:0xB809E], "4"

        mov   esi,buffer      ; dump it to screen
        mov   edi,0xB8000
        mov   ecx,512
        mov   ah,' '
ScreenDump:
        lodsb
        stosw
        loop  ScreenDump

        mov   byte [es:0xB809E], "5"
        jmp   $                ; Just loop for now
;*************************************
; GDT.
;*************************************
gdt:        dw    0x0000, 0x0000, 0x0000, 0x0000
sys_data:   dw    0xFFFF, 0x0000, 0x9200, 0x00CF
sys_code:   dw    0xFFFF, 0x0000, 0x9800, 0x00CF
gdt_end:

gdtr:       dw gdt_end - gdt - 1
            dd gdt
;*************************************
; Make program 510 byte's + 0xaa55
;*************************************
times 510- ($-start)  db 0
dw 0xaa55
buffer rb  512
    

NOTE: Untested
Post 28 Feb 2009, 02:39
View user's profile Send private message Reply with quote
dosin



Joined: 24 Aug 2007
Posts: 337
dosin 28 Feb 2009, 03:54
Thanks Dex - I will give a try...
Post 28 Feb 2009, 03:54
View user's profile Send private message Reply with quote
dosin



Joined: 24 Aug 2007
Posts: 337
dosin 03 Mar 2009, 19:28
I am currently working on a program that can detect HD drives and return manufacturer info.. using ports.. will be posting a sample boot loader..
for testing soon! Very Happy

I was able to get all the info off my disks using ports..
and just need time to put it together.. lol

once this is done will begin work on detecting usb.. if tests on other PCs go well!!

I think this should be the 1st step.. before writing/reading from disk..
Post 03 Mar 2009, 19:28
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4354
Location: Now
edfed 04 Mar 2009, 17:50
i had made my first try with PIO using the example from DEX.
but it don't works.
it displays only FFFFFFFF....

i didn't see what is lacking to obtain a real PIO sector read.


Last edited by edfed on 08 Mar 2009, 08:40; edited 1 time in total
Post 04 Mar 2009, 17:50
View user's profile Send private message Visit poster's website Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u 04 Mar 2009, 18:50
The above code as now been tested by a member of my forum as working, so it must be something in your code, eg: your are reading byte at a time after
";Data port-data comes in and out of here"
Try reading WORD
To see if that helps
Post 04 Mar 2009, 18:50
View user's profile Send private message Reply with quote
dosin



Joined: 24 Aug 2007
Posts: 337
dosin 04 Mar 2009, 19:14
post removed..


Last edited by dosin on 05 Mar 2009, 22:24; edited 2 times in total
Post 04 Mar 2009, 19:14
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4354
Location: Now
edfed 04 Mar 2009, 19:18
no problems.
finally the bug is from win98.
i tested the original version in real boot and i saw it was OK. thanks Dex4u
after, i tested mine in real boot, and it is ok.
i can build a little boot sector reader now.

Code:
testide dd f.gnode,0,0,320,200,@f-$-4
        dd .txt
        dd .hexa
        dd .ide
        @@:
.txt    dd f.txt,30,30,200,150,100h,.txtbuf,font85
.hexa   dd f.hexa,.buf,.buf+512,.txtbuf,.txtbuf+2000,32
.ide    dd f.asm,@f
        @@:
        push eax ebx ecx edx esi edi


        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,al 
@@:
        in    al,dx 
        test  al,8            ;This means the sector buffer requires 
            ;servicing. 
        jz @b     ;Don't continue until the sector buffer
            ;is ready. 
        mov   ecx,512/2        ;One sector /2 
        mov   edi,.buf
        mov   dx,1f0h         ;Data port - data comes in and out of here. 
        push es cs
        pop es
        rep   insw
        pop es
        pop edi esi edx ecx ebx eax
        ret
.buf    rb 512
.bufend db 0
.txtbuf rb 2000
.txtbufend db 0   
    


Last edited by edfed on 08 Mar 2009, 08:32; edited 3 times in total
Post 04 Mar 2009, 19:18
View user's profile Send private message Visit poster's website Reply with quote
dosin



Joined: 24 Aug 2007
Posts: 337
dosin 04 Mar 2009, 19:22
nice! Glad to hear you have it working!
Post 04 Mar 2009, 19:22
View user's profile Send private message Reply with quote
dosin



Joined: 24 Aug 2007
Posts: 337
dosin 19 May 2009, 03:25
I am making a HD Multi boot loader.. and utils installer ect...

Is there any features that anyone here would say is a must have:

right now:

it has a boot screen that displays any avil portions..
the portions are named at install..
example:
1. Win XP
but the string can be up to 15 letters..

and sets a default portion that is done also at install..
and has a timer that will boot it after 15 seconds enless
keypress..

if keypress - select a portion to boot 1-4..
ect..

So far testing has been on an XP sys.. all good!
will test vista also.. I am looking into linux...

but anything that someone would want added .. let me know..
I will give it a try... or any options that would prove helpful
please let me know!

Thanks in advance...
Post 19 May 2009, 03:25
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4354
Location: Now
edfed 19 May 2009, 21:28
a hidden multiboot page.
if a win key (or else) is pressed before or during bios boot, the menu appears, else, it boots directly the default os.


improve the speed of boot.
Post 19 May 2009, 21:28
View user's profile Send private message Visit poster's website Reply with quote
dosin



Joined: 24 Aug 2007
Posts: 337
dosin 19 May 2009, 22:26
Good to see your still around! I saw a post that you were going away for a while!

Quote:
a hidden multiboot page.
if a win key (or else) is pressed before or during bios boot, the menu appears, else, it boots directly the default os.


Thats a good idea.. it would cut down on the code also..
I will modify once its finished - tested!

so a 2-3 sec delay waiting for win key or something.. instead of 15 secs..

I think it would be best to leave as any key press that way no one would have to remember what key to hit and could hit anything.. I will test to find the right amount of time for delay.. if to fast could become a pain..
Post 19 May 2009, 22:26
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2

< 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.