OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 4:16 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: How to read the disk in 64 bit mode?
PostPosted: Sat Sep 10, 2022 3:11 am 
Offline
Member
Member

Joined: Tue Jun 07, 2022 11:23 am
Posts: 78
Location: France
I have only read the disk from real mode using bios before, and now I want to read the hard disk from 64 bit mode.

I looked on some wiki pages and got very confused on how the disk reading stuff works

Does anyone got some recommendations on where I should start? Thanks in advance!


Top
 Profile  
 
 Post subject: Re: How to read the disk in 64 bit mode?
PostPosted: Sat Sep 10, 2022 4:37 am 
Offline

Joined: Mon Aug 15, 2022 12:30 pm
Posts: 18
You can try to create a simple SATA device driver.

The process is kind of complex and it is way harder to explain than to
show, so i'll attach some code for you.

First, find the devices. You will need to obtain the RSDP. (i get it from limine services)

Having the RSDP, you will have to find the MCFG header, required for iterating PCI bus.

Related code for this is:

https://github.com/TretornESP/bloodmoon ... dev/acpi.c function
Code:
init_acpi
.
(get_rsdp_address() is a function that talks to limine, replace it with whatever
you like).

Then enumerate PCI devices
https://github.com/TretornESP/bloodmoon ... /dev/pci.c
Code:
function enumerate_pci(
)
and search for class: 1, subclass: 6 and program interface: 1 wich are AHCI devices.

https://github.com/TretornESP/bloodmoon ... /devices.c function
Code:
register_devices()


For each one, initialice the ahci device.

https://github.com/TretornESP/bloodmoon ... dev/ahci.c function
Code:
init_ahci()


And store some reference to each available port categorizing it as SATA or ATAPI.

Now when you call your read function, you need to select the desired target device and use the function:

https://github.com/TretornESP/bloodmoon ... dev/ahci.c function
Code:
read_port()


I'm sorry but it is a really lenghty process and i don't really know how to explain it better. Hope this helps!

Have a nice day.


Top
 Profile  
 
 Post subject: Re: How to read the disk in 64 bit mode?
PostPosted: Sat Sep 10, 2022 6:47 am 
Offline
Member
Member

Joined: Tue Jun 07, 2022 11:23 am
Posts: 78
Location: France
Oh that's a lot harder then I expected, gonna still use the BIOS atm, but thanks a lot for the explanation!

_________________
https://github.com/cheyao/Achieve-Core


Top
 Profile  
 
 Post subject: Re: How to read the disk in 64 bit mode?
PostPosted: Sat Sep 10, 2022 2:39 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5100
What kind of hard disk do you want to access? If you're trying to read a disk in a virtual machine, you can make things easier by changing how the VM is configured. You don't need to support PCIe or AHCI if your VM isn't configured to emulate those.


Top
 Profile  
 
 Post subject: Re: How to read the disk in 64 bit mode?
PostPosted: Sun Sep 11, 2022 2:33 am 
Offline
Member
Member

Joined: Tue Jun 07, 2022 11:23 am
Posts: 78
Location: France
Im just trying to access the boot disk (using -drive file=boot.iso,format=raw,media=disk on qemu) for reading and writing some data

_________________
https://github.com/cheyao/Achieve-Core


Top
 Profile  
 
 Post subject: Re: How to read the disk in 64 bit mode?
PostPosted: Sun Sep 11, 2022 4:25 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4591
Location: Chichester, UK
A simple ATA PIO mode driver will do the job: https://wiki.osdev.org/ATA_PIO_Mode


Top
 Profile  
 
 Post subject: Re: How to read the disk in 64 bit mode?
PostPosted: Sun Sep 11, 2022 8:47 am 
Offline
Member
Member

Joined: Tue Jun 07, 2022 11:23 am
Posts: 78
Location: France
Ok thanks!

_________________
https://github.com/cheyao/Achieve-Core


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 75 guests


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 post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group