OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Jan 16, 2018 9:20 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: how to get device io port or PCI numbers
PostPosted: Tue Dec 26, 2017 5:01 pm 
Offline

Joined: Wed May 10, 2017 7:00 pm
Posts: 9
In real mode, I read/write a disk via int 13h, but in protected mode, we can only access it by io, of cource I can enum all the storage devices and check out which is the disk I boot from.

However, I would like to have a easier way to config out the io port or PCI bus&device$fuction number of the disk in real mode, so that after I enter protected mode, I can access it directly by it.


Top
 Profile  
 
 Post subject: Re: how to get device io port or PCI numbers
PostPosted: Tue Dec 26, 2017 6:12 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 1214
If the BIOS supports it, you can find that information using INT 0x13 AH=0x48. Here's a link to the specification.

If the BIOS doesn't support it, you have to enumerate all of the storage devices to find the boot disk.


Top
 Profile  
 
 Post subject: Re: how to get device io port or PCI numbers
PostPosted: Wed Dec 27, 2017 6:14 am 
Offline

Joined: Wed May 10, 2017 7:00 pm
Posts: 9
Octocontrabass wrote:
If the BIOS supports it, you can find that information using INT 0x13 AH=0x48. Here's a link to the specification.

If the BIOS doesn't support it, you have to enumerate all of the storage devices to find the boot disk.


Thanks for your help, I tried with qemu and unfourtuantly it does not support EDD, maybe I need to deal with the enumeration.


Top
 Profile  
 
 Post subject: Re: how to get device io port or PCI numbers
PostPosted: Wed Dec 27, 2017 7:57 pm 
Offline
Member
Member
User avatar

Joined: Sat Jan 15, 2005 12:00 am
Posts: 8197
Location: At his keyboard!
Hi,

zq wrote:
Octocontrabass wrote:
If the BIOS doesn't support it, you have to enumerate all of the storage devices to find the boot disk.


Thanks for your help, I tried with qemu and unfourtuantly it does not support EDD, maybe I need to deal with the enumeration.


In this case there's multiple scenarios where it's impossible for the OS to figure out what it booted from.

For a simple example, assume the user has eight USB flash devices plugged into a USB hub where all of the flash devices are identical clones and have a "write protect" switch set.

For a more bizarre example (that you can expect to fail even if EDD is fully supported), imagine if the user boots a hard disk image from network using Syslinux MEMDISK (which downloads a disk image into RAM, then hooks "int 0x13" to make the RAM look like an actual disk).


Cheers,

Brendan

_________________
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.


Top
 Profile  
 
 Post subject: Re: how to get device io port or PCI numbers
PostPosted: Fri Jan 05, 2018 3:50 am 
Offline
Member
Member
User avatar

Joined: Sat Dec 27, 2014 9:11 am
Posts: 865
Location: Maadi, Cairo, Egypt
Just to give a more complete answer, there are mainly two ways of detecting the boot drive. First, you can have a kernel parameter that instructs it which drive to use. Or next, you can scan for all devices and search for boot files or other "magic" combinations that mark your boot device.

Scanning for all devices is not that hard. One way or another, you will have to detect all drives anyway. So you can scan the PCI bus for IDE/AHCI controllers, and then scan each IDE/AHCI controller for ATA/SATA/ATAPI/SATAPI devices. The same goes for the USB; you'd find USB controllers, scan each controller for USB hubs, and scan each USB hub for mass storage devices.

For Syslinux Memdisk, you're sure that if it exists, it is already the boot device. To detect Syslinux Memdisk (as I do in my code), you use BIOS INT 0x13 function 0x48 to get drive size. Then use the BIOS E820 memory map, and scan for a memory range that is the same size as the boot device, and is marked as "reserved." The start of that memory area represents the start of the memory-mapped disk. This works for Syslinux 4.07 at least, I haven't tried other versions, but probably works too.

_________________
Byte me; OS site, source code.
You know your OS is advanced when you stop using the Intel programming guide as a reference.


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot] and 16 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