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!
How to read the disk in 64 bit mode?
-
- Posts: 18
- Joined: Mon Aug 15, 2022 12:30 pm
Re: How to read the disk in 64 bit mode?
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.
(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)
and search for class: 1, subclass: 6 and program interface: 1 wich are AHCI devices.
https://github.com/TretornESP/bloodmoon ... /devices.c function
For each one, initialice the ahci device.
https://github.com/TretornESP/bloodmoon ... dev/ahci.c function
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
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.
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: Select all
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: Select all
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: Select all
register_devices()
https://github.com/TretornESP/bloodmoon ... dev/ahci.c function
Code: Select all
init_ahci()
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: Select all
read_port()
Have a nice day.
-
- Member
- Posts: 78
- Joined: Tue Jun 07, 2022 11:23 am
- Libera.chat IRC: Cyao
- Location: France
- Contact:
Re: How to read the disk in 64 bit mode?
Oh that's a lot harder then I expected, gonna still use the BIOS atm, but thanks a lot for the explanation!
-
- Member
- Posts: 5563
- Joined: Mon Mar 25, 2013 7:01 pm
Re: How to read the disk in 64 bit mode?
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.
-
- Member
- Posts: 78
- Joined: Tue Jun 07, 2022 11:23 am
- Libera.chat IRC: Cyao
- Location: France
- Contact:
Re: How to read the disk in 64 bit mode?
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
Re: How to read the disk in 64 bit mode?
A simple ATA PIO mode driver will do the job: https://wiki.osdev.org/ATA_PIO_Mode