Page 1 of 1

Disk access in protected mode...

Posted: Fri Oct 22, 2004 8:33 pm
by Goudaman
Hey everyone,

We are currently trying to write a monotasking 32-bit os and our basic code outline is: (* = not done/working yet)

Real-mode bootloader:
- reads self and an arbitrary length of attatched code that in essence just runs longer than the 512 byte bootsector.
- in the non-bs real-mode code it initalizes an idt, and gdt and switches to protected mode, in which it has a flat non-address translated memory model.
Protected-mode code:
-Implements a subset of the linux int0x80 system calls*
-Loads a statically linked elf file from disk to a base adress based on its header*
-and jumps to its entry point*

Basically we get into protected mode fine, and our user interrupts work without problems, but we cant access disks.
Obviously we are aware that the bios interrupts dont work in protected mode, so we tried implementing ide drive access code by using port io. (similar to http://www.nondot.org/sabre/os/files/Disk/HD_PORTS.asm)

Basically it doesn't work at all, and we've been trying to debug for a long time now. We're stumped.

After searching of the internet, it seems that any resources available regarding 32-bit direct disk access in protected mode are nonexistent... can anyone tell us if it's possible to access the hard disk without switching to real mode and calling the BIOS interrupts? Or, alternatively, another way of accomplishing our goal?

Thanks guys.

-Alex, Lucas.

Re:Disk access in protected mode...

Posted: Fri Oct 22, 2004 9:38 pm
by mystran
Sure reading can be done without BIOS. If you are going to implement Linux system calls, you might just as well take the Linux sources now, and see how it does it.

I'd imagine there's also some resources for this pointed to in the "quicklinkz" thread.

Re:Disk access in protected mode...

Posted: Fri Oct 22, 2004 10:11 pm
by Goudaman
True, but a) if we wanted to just take linux code we would just use linux and be done right now ::) b) the linux source is totally indecipherable!

We're basically looking for some examples of how to do port I/O in protected mode to access a disk. I mean, somebody has to have done it before, otherwise how would any of the 32-bit OS's we see on this web forum be able to access the disk?

The reason we're implementing the Linux system calls is so we can use the Linux C/C++ compiler and libraries (saving us to have to write our own compiler in addition to an OS!)

If anyone has an example of some Intel x86 assembly code that accesses the hard disk through the bus master IDE controller by port I/O, we would appreciate it more than anything at this point. :D

Thanks!

-Alex, Lucas.

Re:Disk access in protected mode...

Posted: Sat Oct 23, 2004 3:38 am
by pkd
Hi I just added IDE read/Write sectors to my tut/example page at http://doyle.id.au/html/ide_read_write.html

Hopefully it helps

Its PIO not DMA and will read or write 8 sectors at a time, no error checking.

bye
pkd.

Re:Disk access in protected mode...

Posted: Sat Oct 23, 2004 4:30 am
by Brendan
Hi,
Goudaman wrote: If anyone has an example of some Intel x86 assembly code that accesses the hard disk through the bus master IDE controller by port I/O, we would appreciate it more than anything at this point. :D
For bus mastering you'll need a driver for each different PCI IDE controller, so which chipset do you intend starting with?

Alternatively (as they all support legacy mode) you could do a generic IDE driver using PIO - there's plenty of information on the internet for that :)...


Cheers,

Brendan

Re:Disk access in protected mode...

Posted: Sat Oct 23, 2004 8:32 am
by ASHLEY4
I think that theres more ide code on the net, then any other.
Here are some examples:
http://www.humboldt1.com/~doors/idework/idework.htm
http://www.rdos.net/

But do what pkd tut does, and set it up for Secondary Slave, until you know what you are doing or give big
WARNINGS!.

\\\\||////
(@@)
ASHLEY4.

Re:Disk access in protected mode...

Posted: Sat Oct 23, 2004 12:09 pm
by Goudaman
Wow, thanks for all the info we'll read it and hopefully code some routines that work! As for DMA/PIO etc, just generic pio code is fine, our os is kind of "special purpose" anyways so as long as we can read from the disk in a compatible way its all good. Also, we are developing in vmware so we dont have to worry about messing anything up, if we werent i wouldn't have a computer to type this on by now.

-Lucas