Enumerate PCI Buses
-
- Posts: 5
- Joined: Fri Jul 31, 2015 5:49 am
Enumerate PCI Buses
Hi All,
In the context of a school project on computers architecture, I have to make a PCI Bus Enumerator.
The code will be divided into two layers :
- An enumeration layer that handle enumeration of the differents buses and devices in each bus. It then must use a data structure to store all these informations (Tree maybe?) and other informations about the device (vendor id, device id, functions). It should generate a tree representing all the devices and buses.
This layer will then be ported to the kernel land (fictive of course).
- A display layer that take the data structure and display it (using dashes, colors, spaces etc... It must be fashion).
To make this program, I can use assembly languages or C language. I can't use any API. I must talk directly to the hardware and/or use BIOS routines.
I have to deliver a binary that runs on Linux or Win32.
Having only assembly concepts (Hello world :/), I don't see at all how can I start this project. I read some articles on OsDev and I more or less understood the operation (use two loops to browse the buses and devices and check for every device/bus if it exists and if it have functions). But I don't know how to code this.
It's why I ask for your help. Naturally, I don't want any pre-made code, I'm very motivated to learn.
Thanks.
(Sorry for my english, I'm french).
In the context of a school project on computers architecture, I have to make a PCI Bus Enumerator.
The code will be divided into two layers :
- An enumeration layer that handle enumeration of the differents buses and devices in each bus. It then must use a data structure to store all these informations (Tree maybe?) and other informations about the device (vendor id, device id, functions). It should generate a tree representing all the devices and buses.
This layer will then be ported to the kernel land (fictive of course).
- A display layer that take the data structure and display it (using dashes, colors, spaces etc... It must be fashion).
To make this program, I can use assembly languages or C language. I can't use any API. I must talk directly to the hardware and/or use BIOS routines.
I have to deliver a binary that runs on Linux or Win32.
Having only assembly concepts (Hello world :/), I don't see at all how can I start this project. I read some articles on OsDev and I more or less understood the operation (use two loops to browse the buses and devices and check for every device/bus if it exists and if it have functions). But I don't know how to code this.
It's why I ask for your help. Naturally, I don't want any pre-made code, I'm very motivated to learn.
Thanks.
(Sorry for my english, I'm french).
-
- Member
- Posts: 5513
- Joined: Mon Mar 25, 2013 7:01 pm
Re: Enumerate PCI Buses
It sounds like you have to fight the operating system for access to the hardware...Multit4sker wrote:I can't use any API. I must talk directly to the hardware and/or use BIOS routines.
I have to deliver a binary that runs on Linux or Win32.
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: Enumerate PCI Buses
Re: Enumerate PCI Buses
It sounds like his professor doesn't understand how computers work.Octocontrabass wrote:It sounds like you have to fight the operating system for access to the hardware...Multit4sker wrote:I can't use any API. I must talk directly to the hardware and/or use BIOS routines.
I have to deliver a binary that runs on Linux or Win32.
I'd double check the requirements and make sure you aren't missing something.
Project: OZone
Source: GitHub
Current Task: LIB/OBJ file support
"The more they overthink the plumbing, the easier it is to stop up the drain." - Montgomery Scott
Source: GitHub
Current Task: LIB/OBJ file support
"The more they overthink the plumbing, the easier it is to stop up the drain." - Montgomery Scott
- BrightLight
- Member
- Posts: 901
- Joined: Sat Dec 27, 2014 9:11 am
- Location: Maadi, Cairo, Egypt
- Contact:
Re: Enumerate PCI Buses
It's not going to be easy, that is if you figure out a way to do it. Linux and Win32 prevent hardware access to programs. And I'm pretty sure they don't let you call the BIOS, either.Multit4sker wrote:I can't use any API. I must talk directly to the hardware and/or use BIOS routines.
I have to deliver a binary that runs on Linux or Win32.
You know your OS is advanced when you stop using the Intel programming guide as a reference.
-
- Member
- Posts: 116
- Joined: Thu May 06, 2010 4:34 am
- Libera.chat IRC: peterbjornx
- Location: Leiden, The Netherlands
- Contact:
Re: Enumerate PCI Buses
Is it required that the computer keeps operating normally afterwards?, you could use kexec() to load a stub kernel containing your pci code and a simple kprintf or on windows, load a driver that clears the interrupt flag and proceeds to load that same kernel
Re: Enumerate PCI Buses
Combuster already mentioned ioperm(). This will generally only work as root, but that's it.omarrx024 wrote:Linux and Win32 prevent hardware access to programs.
It might be helpful to turn off hardware interrupts while you're accessing the PCI registers in order to avoid any conflicts with the kernel accessing them. After iopl(), this should be possible.
-
- Posts: 5
- Joined: Fri Jul 31, 2015 5:49 am
Re: Enumerate PCI Buses
Hi guys, I'm really sorry, I didn't see I had so much answers.
Obviously, I can't use API only on the PCI related part.
According to my professor, this program will be executed on a virtual machine.
Here is the homework if you can understand it better than me (Maybe I haven't explained it well) : https://www.dropbox.com/s/4e7ufkpshcsoc ... r.pdf?dl=0
Again, I don't tell you to make this for me, I want to do it myself (If I success, I will go out stronger :p ).
Thanks !
Obviously, I can't use API only on the PCI related part.
According to my professor, this program will be executed on a virtual machine.
Here is the homework if you can understand it better than me (Maybe I haven't explained it well) : https://www.dropbox.com/s/4e7ufkpshcsoc ... r.pdf?dl=0
Again, I don't tell you to make this for me, I want to do it myself (If I success, I will go out stronger :p ).
Thanks !
Re: Enumerate PCI Buses
Nope, you explained it perfectly.
The PDF actually says that you must a) write a PCI enumerator in ASM or C for a kernel that does not exist yet, and b) you must deliver an EXE that will run in Linux or Windows.
I'm not sure how both of these statements can be in the same document. They appear to be mutually exclusive. I would talk to the instructor and verify that this wording is correct, because it makes no sense to me...
Personally, I think that I would ignore the line about delivering an EXE that will run on Windows or Linux. I think that line is a mistake. It has nothing to do with OS development at all.
I did notice that they included a link to the osdev wiki as a reference for you to do research. Pretty cool!
The PDF actually says that you must a) write a PCI enumerator in ASM or C for a kernel that does not exist yet, and b) you must deliver an EXE that will run in Linux or Windows.
I'm not sure how both of these statements can be in the same document. They appear to be mutually exclusive. I would talk to the instructor and verify that this wording is correct, because it makes no sense to me...
Personally, I think that I would ignore the line about delivering an EXE that will run on Windows or Linux. I think that line is a mistake. It has nothing to do with OS development at all.
I did notice that they included a link to the osdev wiki as a reference for you to do research. Pretty cool!
Project: OZone
Source: GitHub
Current Task: LIB/OBJ file support
"The more they overthink the plumbing, the easier it is to stop up the drain." - Montgomery Scott
Source: GitHub
Current Task: LIB/OBJ file support
"The more they overthink the plumbing, the easier it is to stop up the drain." - Montgomery Scott
Re: Enumerate PCI Buses
Actually, the PDF saysSpyderTL wrote:The PDF actually says that you must a) write a PCI enumerator in ASM or C for a kernel that does not exist yet, and b) you must deliver an EXE that will run in Linux or Windows.
and deliverYou’ll create a userland mock-‐up that will later be ported to the kernel space.
That sounds perfectly doable to me, with no mutual exclusion involved. The only aspect I am not 100% sure of is whether userland programs can access the PCI memory space. But "lspci" does this very thing, so I presume it is possible.A binary that runs on Linux or Win32.
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: Enumerate PCI Buses
lspci runs unprivileged, so it will be using device files and system calls rather than direct port access (and the required mutual exclusion probably happens in the kernel).
Re: Enumerate PCI Buses
Yes. A little research turned up this paper from AMD that shows that lspci uses kernel APIs: http://developer.amd.com/wordpress/medi ... access.pdf . But it also points out that a userland program can access the memory directly (via /dev/mem). It says that it is inadvisable to do so as it might affect system stability. I can't see that reading the configuration space could cause such problems, though writing could be a mistake.
Bottom line - it can be done, and this is presumably what the question intends. Really, the Wiki article on PCI tells you just about all you need to know. (And a bit of research will no doubt tell you how to do it in Windows.)
Bottom line - it can be done, and this is presumably what the question intends. Really, the Wiki article on PCI tells you just about all you need to know. (And a bit of research will no doubt tell you how to do it in Windows.)
-
- Member
- Posts: 1146
- Joined: Sat Mar 01, 2014 2:59 pm
Re: Enumerate PCI Buses
I assume (read: hope) that they mean a *binary* that will run on Linux or Windows, not an *EXE*. Linux does not use .exe files, and if they're going to the trouble of mentioning Linux I certainly hope that they are not mentioning it just for the few Wine users out there...SpyderTL wrote:The PDF actually says that you must a) write a PCI enumerator in ASM or C for a kernel that does not exist yet, and b) you must deliver an EXE that will run in Linux or Windows.
When you start writing an OS you do the minimum possible to get the x86 processor in a usable state, then you try to get as far away from it as possible.
Syntax checkup:
Wrong: OS's, IRQ's, zero'ing
Right: OSes, IRQs, zeroing
Syntax checkup:
Wrong: OS's, IRQ's, zero'ing
Right: OSes, IRQs, zeroing
Re: Enumerate PCI Buses
That's probably why the PDF specifies "binary" rather than "EXE".onlyonemac wrote:I assume (read: hope) that they mean a *binary* that will run on Linux or Windows, not an *EXE*. Linux does not use .exe files, and if they're going to the trouble of mentioning Linux I certainly hope that they are not mentioning it just for the few Wine users out there...SpyderTL wrote:The PDF actually says that you must a) write a PCI enumerator in ASM or C for a kernel that does not exist yet, and b) you must deliver an EXE that will run in Linux or Windows.
-
- Member
- Posts: 1146
- Joined: Sat Mar 01, 2014 2:59 pm
Re: Enumerate PCI Buses
I was assuming that when SpyderTL wrote "The PDF actually says..." that he was quoting it exactly as it was written in the PDF.iansjack wrote:That's probably why the PDF specifies "binary" rather than "EXE".onlyonemac wrote:I assume (read: hope) that they mean a *binary* that will run on Linux or Windows, not an *EXE*. Linux does not use .exe files, and if they're going to the trouble of mentioning Linux I certainly hope that they are not mentioning it just for the few Wine users out there...SpyderTL wrote:The PDF actually says that you must a) write a PCI enumerator in ASM or C for a kernel that does not exist yet, and b) you must deliver an EXE that will run in Linux or Windows.
When you start writing an OS you do the minimum possible to get the x86 processor in a usable state, then you try to get as far away from it as possible.
Syntax checkup:
Wrong: OS's, IRQ's, zero'ing
Right: OSes, IRQs, zeroing
Syntax checkup:
Wrong: OS's, IRQ's, zero'ing
Right: OSes, IRQs, zeroing