OSDev.org
https://forum.osdev.org/

Common Ports
https://forum.osdev.org/viewtopic.php?f=1&t=36932
Page 1 of 1

Author:  Schmidtzilla [ Sat Jun 27, 2020 7:40 am ]
Post subject:  Common Ports

I've been reading nonstop now for the past several months and the same one question keeps coming to mind, which I have seen been asked numerous times by others as well over and over again. What are these IO Ports and/or where is a list for them. On this sites wiki page https://wiki.osdev.org/I/O_Ports it states that I should not be looking for a list, which it also posts a link to bochs beautiful list of ports as well. However, I'm also left with the same question even while possessing such a list, "WHERE ON EARTH ARE THESE PORT NUMBERS COMING FROM???" When I view the PCI it gives me BARs to look over. Say, as a basis for clarification of my question, I am trying to program an ATA/ATAPI driver for my hard drive. I look through my PCI's BARs and find it says 0x0 or 0x1 in BAR 1, as it says to do here, https://wiki.osdev.org/PCI_IDE_Controller. Now it tells me that 0 or 1 means that the address is 0x1F0 and 0x3F6 however where did these numbers come from if I read the thing and it tells me the address is 0? Why doesn't it tell me the address 0x1F0 or 0x3F6 within the BAR and where are these other port numbers coming from? Not to mention where on Earth did the initial PCI port number of 0xCF8 and 0xCFC even come from?

I am assuming there is a configuration table somewhere in memory, as with all things in programming (working with descriptor tables on everything) there is something in maybe the extended bios data area or somewhere in the BIOS chip with a more accurate listing of all these available port numbers actually available on my specific PC? I keep reading things seeing people saying "You gotta read the standard for the device" and things like that however I have already read the standard on several of these chips such as the 8259A whose ports are 20h-21h and A0h-A1h as well as different keyboard controllers the DMA controller and several others not a single one of these standards have told me anything about "port numbers." and every time I'm readying one the same thing pops into mind. Where is this port number coming from? I have just started reading PnP bios but haven't finished yet, but am I on the right track? Is it BIOs? ISA? EISA? or do I have to finish reading PCI maybe? Do the devices themselves have the port number to listen to saved to them? And if so why does the 8259A's have multiple ports and the specs not say a single thing about them? Maybe PCI has a configuration saved inside of it so when it hits a 0101h in its class config space it gives the device the port 1F0h? Or is it literally the 0-31 address pins on the processor pins 60h in the address lines point at the keyboard controller? I'm so confused and it's that one question that will never stop haunting me every day now for SEVERAL months!

Sorry for the repeated question as I know it has been asked several times EVERYWHERE else but its gotta have an actual answer to it.

Author:  Octocontrabass [ Tue Jun 30, 2020 12:43 pm ]
Post subject:  Re: Common Ports

Schmidtzilla wrote:
"WHERE ON EARTH ARE THESE PORT NUMBERS COMING FROM???"

Depends on which port you're asking about.

Schmidtzilla wrote:
Say, as a basis for clarification of my question, I am trying to program an ATA/ATAPI driver for my hard drive. I look through my PCI's BARs and find it says 0x0 or 0x1 in BAR 1, as it says to do here, https://wiki.osdev.org/PCI_IDE_Controller. Now it tells me that 0 or 1 means that the address is 0x1F0 and 0x3F6 however where did these numbers come from if I read the thing and it tells me the address is 0? Why doesn't it tell me the address 0x1F0 or 0x3F6 within the BAR and where are these other port numbers coming from?

That article is incorrect. According to the PCI IDE Controller Specification, you're supposed to read all three bytes of the class code to determine whether the PCI IDE controller is using the BARs or legacy addresses. The BARs don't tell you the correct addresses when the controller is using legacy addresses because you're not supposed to read the BARs in that case.

The numbers 0x1F0 and 0x3F6 come from the IBM PC AT Fixed Disk and Diskette Drive Adapter, since IDE is designed to be backwards-compatible with it.

Schmidtzilla wrote:
Not to mention where on Earth did the initial PCI port number of 0xCF8 and 0xCFC even come from?

The PCI Local Bus Specification.

Schmidtzilla wrote:
I am assuming there is a configuration table somewhere in memory, as with all things in programming (working with descriptor tables on everything) there is something in maybe the extended bios data area or somewhere in the BIOS chip with a more accurate listing of all these available port numbers actually available on my specific PC?

There isn't.

Schmidtzilla wrote:
I keep reading things seeing people saying "You gotta read the standard for the device" and things like that however I have already read the standard on several of these chips such as the 8259A whose ports are 20h-21h and A0h-A1h as well as different keyboard controllers the DMA controller and several others not a single one of these standards have told me anything about "port numbers."

Those chips don't do their own address decoding, so they don't know which addresses they've been assigned.

Schmidtzilla wrote:
and every time I'm readying one the same thing pops into mind. Where is this port number coming from?

The port numbers for the interrupt controllers, keyboard controller, and DMA controllers were assigned by IBM when they designed the PC and PC AT. Everyone copied those numbers to maintain backwards compatibility.

Schmidtzilla wrote:
I have just started reading PnP bios but haven't finished yet, but am I on the right track? Is it BIOs? ISA? EISA?

No, no, no, and no.

Schmidtzilla wrote:
or do I have to finish reading PCI maybe?

That might help you when it comes to PCI devices.

Schmidtzilla wrote:
Do the devices themselves have the port number to listen to saved to them?

Depends on the device.

Schmidtzilla wrote:
And if so why does the 8259A's have multiple ports and the specs not say a single thing about them?

Those chips don't do their own address decoding, so they don't know which addresses they've been assigned.

Schmidtzilla wrote:
Maybe PCI has a configuration saved inside of it so when it hits a 0101h in its class config space it gives the device the port 1F0h?

No.

Schmidtzilla wrote:
Or is it literally the 0-31 address pins on the processor pins 60h in the address lines point at the keyboard controller?

Almost! There's also a line to select between memory and I/O addresses.

Author:  Schmidtzilla [ Sun Jul 26, 2020 9:33 am ]
Post subject:  Re: Common Ports

Octocontrabass wrote:
Almost! There's also a line to select between memory and I/O addresses.


Thank you for all the answers. I think I figured it out, but this one especially. Haha. I feel as if I want to build my own motherboard from scratch, no matter how shitty, just to be the first "programmer" of my computer. I feel like a custom-made computer could potentially be way faster without having to adhere to certain manufacturer standards, as well as, potentially be nearly impossible to get a virus or "hacked" in a sense. But honestly I wouldn't nearly have any knowledge of where to start besides connect the 3.3v line to the 3.3v pins and the 5v lines to the 5v pins then the ireq lines to the pic and then those pins to the irq and iack pins and just keep connecting pins to where they needa go, but honestly I'd probably just blow the whole damn thing up so I probably shouldn't just "assume" anymore should I? Lmao... Thanks!

Author:  bzt [ Sun Jul 26, 2020 9:53 am ]
Post subject:  Re: Common Ports

Schmidtzilla wrote:
I feel as if I want to build my own motherboard from scratch, no matter how shitty, just to be the first "programmer" of my computer. I feel like a custom-made computer could potentially be way faster without having to adhere to certain manufacturer standards,
There are people on this forum who have done that (but I haven't seen them for a while). One guy has actually built a computer, but most of them use FPGA.
Schmidtzilla wrote:
as well as, potentially be nearly impossible to get a virus or "hacked" in a sense.
Never underestimate hackers :-) Security by obscurity only works for a short time, but always fails on the long run.
Schmidtzilla wrote:
But honestly I wouldn't nearly have any knowledge of where to start besides connect the 3.3v line to the 3.3v pins and the 5v lines to the 5v pins then the ireq lines to the pic and then those pins to the irq and iack pins and just keep connecting pins to where they needa go, but honestly I'd probably just blow the whole damn thing up so I probably shouldn't just "assume" anymore should I? Lmao... Thanks!
Yep, writing code for already existing computer may be hard, but lot easier than to design an entire computer from the ground up.

Cheers,
bzt

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/