flat assembler
Message board for the users of flat assembler.

Index > OS Construction > Disk Drive/Usb Read Protected Mode?

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
blind_dragon



Joined: 20 Jun 2012
Posts: 12
blind_dragon 20 Jun 2012, 04:43
Hello,

Is there a example of 32 bit protected mode hdd io?
read lba sector and get disk information?

any sugestions from people experienced with this?


I found this but it is for 64 bit...
http://wiki.osdev.org/ATA_read/write_sectors
Post 20 Jun 2012, 04:43
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u 20 Jun 2012, 13:11
blind_dragon wrote:
Hello,

Is there a example of 32 bit protected mode hdd io?
read lba sector and get disk information?

any sugestions from people experienced with this?


I found this but it is for 64 bit...
http://wiki.osdev.org/ATA_read/write_sectors


You can download DexOS, in the Drivers folder, you will find a HddFunctions.inc in it you will find examples.

http://www.dex-os.com/
Post 20 Jun 2012, 13:11
View user's profile Send private message Reply with quote
blind_dragon



Joined: 20 Jun 2012
Posts: 12
blind_dragon 20 Jun 2012, 13:26
Ok I will check it out.

thank you.
Post 20 Jun 2012, 13:26
View user's profile Send private message Reply with quote
blind_dragon



Joined: 20 Jun 2012
Posts: 12
blind_dragon 20 Jun 2012, 22:50
@Dex4u:
I did find this code and tried to read and in testing it gets stuck in the loop
hddwaitFS: ? Any ideas?

Does anything need to be done in order to enable it?


Code:
HddBaseFS                      dd 0x1f0                            ; First device =0x1f0 for primary, second =0x170 for secondary device.
MasterSlave                       db 0x00                             ; Master = 0x00 Slave = 0x10.


HddReadFS:
 pushad
      push  eax
newhdreadFS:
       mov edx,[HddBaseFS]
 inc   edx
   mov   al,0
  out   dx,al

     inc   edx
   mov   al,1
  out   dx,al

     inc   edx
   pop   ax
    out   dx,al

     inc   edx
   shr   ax,8
  out   dx,al

     inc   edx
   pop   ax
    out   dx,al

     inc   edx
   shr   ax,8
  and   al,1+2+4+8
    add   al,[MasterSlave]
      add   al,128+64+32
  out   dx,al

     inc   edx
   mov   al,20h
        out   dx,al
hddwaitFS:
       in    al,dx
 test  al,128
        jnz   hddwaitFS

 mov   edi,dword[HddScratchBuffer]
   mov   ecx,256
       mov edx,[HddBaseFS]
 cld
 rep   insw

      popad
       ret
    
Post 20 Jun 2012, 22:50
View user's profile Send private message Reply with quote
BAiC



Joined: 22 Mar 2011
Posts: 272
Location: California
BAiC 21 Jun 2012, 10:05
USB access to hard drives are severely complicated. the only way it'll be "easy" to access a USB hard drive is if you have "wrapper"-like service hiding the USB part. in my experience, "wrapper"s of this complexity are roughly 10k-100k in code size.

as for "classic" Hard Drive IO: the old code where you access IO Space at 0x1F0 either breaks on modern hardware, or it does nothing. I have 2 systems and neither one supports placing one of its' hard drive controllers in that mode.

blind_dragon: what emulator/VM are you using to test on? you need to make sure that the "device" is also at that address.
Post 21 Jun 2012, 10:05
View user's profile Send private message Visit poster's website Reply with quote
blind_dragon



Joined: 20 Jun 2012
Posts: 12
blind_dragon 21 Jun 2012, 17:55
no emulator - real pc..

when I boot the usb I get the boot drive and returns as 80h
but even though I should be able to access my disc drive or the usb..
its not reading any of them..

I should be able to read one of the 2.. and dump it to screen to see if its the usb or the hdd its reading.. based on the MBR - well I would think
Post 21 Jun 2012, 17:55
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u 21 Jun 2012, 18:51
blind_dragon wrote:
no emulator - real pc..

when I boot the usb I get the boot drive and returns as 80h
but even though I should be able to access my disc drive or the usb..
its not reading any of them..

I should be able to read one of the 2.. and dump it to screen to see if its the usb or the hdd its reading.. based on the MBR - well I would think


First let me get somethings clear, you are booting using hdd emulation from a USB fob ?.

But you want to
1. read your real hdd ?
2. read your usb fob ?

Which is it 1 or 2.
Post 21 Jun 2012, 18:51
View user's profile Send private message Reply with quote
BAiC



Joined: 22 Mar 2011
Posts: 272
Location: California
BAiC 21 Jun 2012, 21:51
the USB Drive definitely won't show up using the Hard Drive IO Port access. you need a USB driver if you want anything "low-level" to access that thing.
Post 21 Jun 2012, 21:51
View user's profile Send private message Visit poster's website Reply with quote
BAiC



Joined: 22 Mar 2011
Posts: 272
Location: California
BAiC 21 Jun 2012, 22:05
as for your actual hard drive: it's most likely on a non-compatible controller.
Post 21 Jun 2012, 22:05
View user's profile Send private message Visit poster's website Reply with quote
blind_dragon



Joined: 20 Jun 2012
Posts: 12
blind_dragon 21 Jun 2012, 22:32
Quote:
First let me get somethings clear, you are booting using hdd emulation from a USB fob ?.

But you want to
1. read your real hdd ?
2. read your usb fob ?


I would like to read the USB
so I can read and load files from the kernel from a fat sys.

but in trying to use the read functions.. I can not figure out why I can not read the hard drives either.

just for now - read lba 0 of the usb would be a good start.

if you or baic could point me in the right direction

over all goal..
boot - detect the boot drive.. set a perm drive for os as usb.. and use it / excluding
all other drives to protect the computers it runs on.
Post 21 Jun 2012, 22:32
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u 22 Jun 2012, 12:00
There are only 3 way to do that
1. write a USB stack
2. stay in real mode and use int 13h (drive 80h or 0 depend if hdd or fdd emulation)
3. Go to pmode and back for every read/write

I use 1 and 3, (1 not released yet), so if you try my OS you can see how going back and forth works.
With no usb driver int 13h is the only way to read/write USB, once you leave real mode int 13h is no longer available, until you go back to real mode.

See my post here:
http://board.flatassembler.net/topic.php?p=143625#143625
For a going to and from realmode demo, this is for switching vesa modes, but you can replace that with int 13h to read from USB fob.

You can also see the work done by Mike Gonta.
Post 22 Jun 2012, 12:00
View user's profile Send private message Reply with quote
shutdownall



Joined: 02 Apr 2010
Posts: 517
Location: Munich
shutdownall 22 Jun 2012, 12:03
Is it really that easy, that you can access any USB stick in real mode through BIOS int 13h ?
Didn't try before but thought that you need a special driver.

Maybe BIOS dependend ?
I think you need some newer BIOS with option to boot from USB ???
Post 22 Jun 2012, 12:03
View user's profile Send private message Send e-mail Reply with quote
blind_dragon



Joined: 20 Jun 2012
Posts: 12
blind_dragon 22 Jun 2012, 12:39
write a USB stack .

Since you have experince in this.. can you point me to were I can learn more on it?
any documents or sites.

The int 13h real mode does work thats how I boot the kernel. Never tried to switch back and forth once in protected mode.

I will look at that option - thanks
Post 22 Jun 2012, 12:39
View user's profile Send private message Reply with quote
smiddy



Joined: 31 Oct 2004
Posts: 557
smiddy 22 Jun 2012, 14:02
shutdownall wrote:
Is it really that easy, that you can access any USB stick in real mode through BIOS int 13h ?
Didn't try before but thought that you need a special driver.

Maybe BIOS dependend ?
I think you need some newer BIOS with option to boot from USB ???

Yep, a newer BIOS will hav ethe ability to access USB, sense what is there, and make it accessible to INT 13h. I don't know where that cutoff is however.
Post 22 Jun 2012, 14:02
View user's profile Send private message Reply with quote
smiddy



Joined: 31 Oct 2004
Posts: 557
smiddy 22 Jun 2012, 14:04
blind_dragon wrote:
write a USB stack .

Since you have experince in this.. can you point me to were I can learn more on it?
any documents or sites.

The int 13h real mode does work thats how I boot the kernel. Never tried to switch back and forth once in protected mode.

I will look at that option - thanks

If you intend to switch back and forth between real and protected modes, you need to know how to switch the Interrupt Vector Tables (IVT). This is an area to research if you intend to go down that path.
Post 22 Jun 2012, 14:04
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u 22 Jun 2012, 18:37
shutdownall wrote:
Is it really that easy, that you can access any USB stick in real mode through BIOS int 13h ?
Didn't try before but thought that you need a special driver.

Yes its that easy, if your BIOS supports USB booting (all in the last 8 years do), things to note:
USB can emulate floppy or hdd or both.
If it support floppy emulation, then a bootable floppy image placed at the start of the usb fob, will work.
If it boots as hdd emulation, then you need to use a boot sector that can load sectors using fat16 or fat32 depending on the way you formatted the fob.

Also some old PC will boot usb after a BIOS update.
blind_dragon wrote:
write a USB stack .
Since you have experince in this.. can you point me to were I can learn more on it?
any documents or sites.

Theres some good links here:
http://wiki.osdev.org/Universal_Serial_Bus

Also this book is a big help:
http://www.amazon.co.uk/USB-Universal-Serial-Bus-8/dp/1468151983/
Post 22 Jun 2012, 18:37
View user's profile Send private message Reply with quote
shutdownall



Joined: 02 Apr 2010
Posts: 517
Location: Munich
shutdownall 23 Jun 2012, 13:03
Dex4u wrote:
Theres some good links here:
http://wiki.osdev.org/Universal_Serial_Bus

Also this book is a big help:
http://www.amazon.co.uk/USB-Universal-Serial-Bus-8/dp/1468151983/

Thanks, I have this book but maybe the website with OS Dev is worth to read, at least the USB article.

Because I am working on another project with FTDI USB controller chips. The specification of USB 2.0 is not so helpful because it has more than 1000 pages and you don't know where begin to read. Rolling Eyes
Post 23 Jun 2012, 13:03
View user's profile Send private message Send e-mail Reply with quote
blind_dragon



Joined: 20 Jun 2012
Posts: 12
blind_dragon 23 Jun 2012, 14:00
Is there a in/out port list anywere?
for ports on a PC?
Post 23 Jun 2012, 14:00
View user's profile Send private message Reply with quote
BAiC



Joined: 22 Mar 2011
Posts: 272
Location: California
BAiC 23 Jun 2012, 20:00
port lists aren't dependable. you need to know what hardware exists in the system before accessing ports. I highly recommend a PCI Enumerator as it'll ensure software only runs upon discovery of the device.

USB, by the way, doesn't have any static port addresses. you must discover the USB Host Controller through a PCI Enumerator in order to determine where it is in IO (or MMIO) space.

you can read a DWORD in PCI Configuration Space by:
Code:
mov eax, 1 shl 31;this will read the DeviceID and Vendor ID for Device 0 on Function 0 of Bus 0.
mov edx, 0xCF8
out dx, eax
add edx, 4
in eax, dx    
Post 23 Jun 2012, 20:00
View user's profile Send private message Visit poster's website Reply with quote
blind_dragon



Joined: 20 Jun 2012
Posts: 12
blind_dragon 24 Jun 2012, 14:21
thanks for your input BAiC..

I will probably get the book dex4u listed.

I have checked the net on this book and looks pretty popular.
I think I will buy it.
Post 24 Jun 2012, 14:21
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< 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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.