ports programming
ports programming
hi guys i want to write a mouse driver using ports and im ganna compile that with TC 3.0 but i don't know any thing about ports programming can you give me any good tutorial
or any thing good
thanks
or any thing good
thanks
-
- Member
- Posts: 1600
- Joined: Wed Oct 18, 2006 11:59 am
- Location: Vienna/Austria
- Contact:
Re:ports programming
the osfaq (look at my sig or click the mega-tokyo banner) should give elucidating info on them.
ports programming as you call it is f. ex. in the i386 architecture accessing of IO address space, either reading or writing, with the iorq line set to 1.
in asm you use the commands "in [port],[register]", and "out [port],[register]" for these operations. Don't know by heart the exact syntax. You build c functions around these asm commands to ease byte, word and doubleword access to ports.
Well ... for cpu's which have the possibility to access PORTS au contraire to memory-mapped device io, there exist one or more dedicated N:1-Decoders (we call them io decoder) which takes the port number and enables the desired device (there's a bit of logic involved of course), so that only the responsible device reads from the data bus/writes to the data bus. You know, bus architecture: only one device at a time may write to the bus, the others have to stay silent. Anyway ... von Neumann is cool.
In short: you write to a port with out, you read from a port with in.
the osfaq (look at my sig or click the mega-tokyo banner) should give elucidating info on them.
ports programming as you call it is f. ex. in the i386 architecture accessing of IO address space, either reading or writing, with the iorq line set to 1.
in asm you use the commands "in [port],[register]", and "out [port],[register]" for these operations. Don't know by heart the exact syntax. You build c functions around these asm commands to ease byte, word and doubleword access to ports.
Well ... for cpu's which have the possibility to access PORTS au contraire to memory-mapped device io, there exist one or more dedicated N:1-Decoders (we call them io decoder) which takes the port number and enables the desired device (there's a bit of logic involved of course), so that only the responsible device reads from the data bus/writes to the data bus. You know, bus architecture: only one device at a time may write to the bus, the others have to stay silent. Anyway ... von Neumann is cool.
In short: you write to a port with out, you read from a port with in.
the osfaq (look at my sig or click the mega-tokyo banner) should give elucidating info on them.
... the osdever formerly known as beyond infinity ...
BlueillusionOS iso image
BlueillusionOS iso image
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:ports programming
you can think of Intel's x86 architecture as having two address spaces: memory space (which you access through mov <reg>,[mem]; add [mem],<reg>, etc.) and IO space. IO space is limitted to 64K addresses and each of this addresses can be caught by a peripheral device (count your chipset as many peripheral devices integrated on a single die). An odd thing, really. Only intel has something alike
Basically, the BIOS and the motherboard arrange things so that all you have to do is know the proper IO address, issue "in al, dx" or "out dx,al" (and friends) to access the proper device. How a specific port behaves is usually highly depending on its device: unlike memory, its "content" may change without warnings, sometimes reading a word at port 0x1234 is the same as reading one byte at 0x1234 and then another byte at 0x1235, sometimes it's the same as reading twice a byte from 0x1234. Sometimes by writing a "1" to a bit, you request the bit to turn back to "0" ...
Read it as "the device has the complete control over what it does with read/write requests you make to its IO port". All this should be specified in the device's datasheet (8042 controller for PS/2 mouse -- grab info at OSRC).
Basically, the BIOS and the motherboard arrange things so that all you have to do is know the proper IO address, issue "in al, dx" or "out dx,al" (and friends) to access the proper device. How a specific port behaves is usually highly depending on its device: unlike memory, its "content" may change without warnings, sometimes reading a word at port 0x1234 is the same as reading one byte at 0x1234 and then another byte at 0x1235, sometimes it's the same as reading twice a byte from 0x1234. Sometimes by writing a "1" to a bit, you request the bit to turn back to "0" ...
Read it as "the device has the complete control over what it does with read/write requests you make to its IO port". All this should be specified in the device's datasheet (8042 controller for PS/2 mouse -- grab info at OSRC).
Re:ports programming
Well, what would you consider helpful?
Every good solution is obvious once you've found it.
Re:ports programming
as i said before i don't know any thing about ports
so simply i need some good tutorial about it.
so simply i need some good tutorial about it.
Re:ports programming
Do you mean tutorial as in hand-holding? I don't know where theres any of these for I/O programming (I assume thats what you mean by ports but please try to phrase the question better, a little bit of research before posting goes a long way).
My suggesting is to look at the FAQ on this site, head over to http://www.osdever.net and look at the tutorials there, and look for a few sourceforge projects for basic kernels.
May I tell you to read http://www.catb.org/~esr/faqs/smart-questions.html without intending it as an offence?
My suggesting is to look at the FAQ on this site, head over to http://www.osdever.net and look at the tutorials there, and look for a few sourceforge projects for basic kernels.
May I tell you to read http://www.catb.org/~esr/faqs/smart-questions.html without intending it as an offence?
-
- Member
- Posts: 1600
- Joined: Wed Oct 18, 2006 11:59 am
- Location: Vienna/Austria
- Contact:
Re:ports programming
@pype: yeah, the sparcs f. ex. have it easy: memory mapped io (no need for an iorq line) and the sparc cpu only knows: here is an address I wanna write to (lays it on the address bus) and here is the data to be written (lays it on the data bus).
The N:1 Address Decoders do the rest. Maybe (I don't know it really) the sparc mainboard has a cascaded n:1 address decoder for IO address space behind the index (pin actually) responsible for IO address decoding.
YOu don't need to distinguish between in and mov in those architectures anymore as we have to when dealing with i386, where both, memory mapped io and io mapped io are mixed together. One good example is writing to video memory. that's plain memory mapped io on intel hardware. *gg*
well, enough the rambling in /dev/brain
@abuashraf: Not helpful is the way you are posting your question. We do not know what you need explained. We don't like to shoot into the blue at random. Help us to give you good answers by posting a good and well thought question. Thanks.
The N:1 Address Decoders do the rest. Maybe (I don't know it really) the sparc mainboard has a cascaded n:1 address decoder for IO address space behind the index (pin actually) responsible for IO address decoding.
YOu don't need to distinguish between in and mov in those architectures anymore as we have to when dealing with i386, where both, memory mapped io and io mapped io are mixed together. One good example is writing to video memory. that's plain memory mapped io on intel hardware. *gg*
well, enough the rambling in /dev/brain
@abuashraf: Not helpful is the way you are posting your question. We do not know what you need explained. We don't like to shoot into the blue at random. Help us to give you good answers by posting a good and well thought question. Thanks.
... the osdever formerly known as beyond infinity ...
BlueillusionOS iso image
BlueillusionOS iso image
Re:ports programming
Theres really not much to say about the two opcodes in and out. But to understand them and why it is nessessary for the x86 architecture. More importantly its nessessary to understand that multiple devices can be connected on a single bus, which is where I/O ports come in.
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:ports programming
you have simple example code using ports for Turbo C (man, you're using _old_ compiling tools, you know !?) on http://gd.tuwien.ac.at/languages/c/prog ... .htm#sound
e.g.
Now, please be more explicit at what you don't get with that.
[*] "what does "outportb(0x61, settings|3) means ?" it means you write back on port 0x61 the previous value you've read there, forcing bits 0 and 1 to be "1" regardless of whatever they were previously.
[*] "where does that inportb() / outportb() comes from ?" --> check out TC3.x documentation. It's part of "dos.h" library and are wrappers around assembly instructions such as IN and OUT.
[*] "where does 0x61 and 0x42, etc. come from" ? --> these are port addresses, indicating the individual device/function you want to access. Get yourself "helppc" or google for Ralf Brown Interrupt List which should (iirc) feature a map of standard I/O ports, what specific bits they have and how things works in general.
[*] "why settings | 3 turns speaker on ?" or "why initialize timer with 0xb6 ?" then head yourself to datasheets of 8253 and 8042 or find a copy of "the indispensable PC hardware" book...
If you have some other question that pops in your mind, then _please_ take the time to make them clear on paper and ask them. There's no such thing like a tutorial that can read in your mind and see why you're confuse and unconfuse you by making something appear in front of your eyes, you know.
And sorry if i cannot come with "just a good tutorial": the word "tutorial" was still unknown to me when i first used IN and OUT, so ...
e.g.
Code: Select all
#include <dos.h>
void beep() {
int delay;
unsigned char settings;
outportb(0x43,0xb6); /* write to timer mode register */
/* 0x553 is the frequency divisor for 1000Hz */
outportb(0x42,0x553&0xff); /* write LSB */
outportb(0x42,0x553>>8); /* write MSB */
settings = inportb(0x61); /* get current port setting */
outportb(0x61,settings | 3); /* turn speaker on */
for(delay = 0; delay < 20000; delay++)
;
outportb(0x61,settings); /* restore original settings */
}
[*] "what does "outportb(0x61, settings|3) means ?" it means you write back on port 0x61 the previous value you've read there, forcing bits 0 and 1 to be "1" regardless of whatever they were previously.
[*] "where does that inportb() / outportb() comes from ?" --> check out TC3.x documentation. It's part of "dos.h" library and are wrappers around assembly instructions such as IN and OUT.
[*] "where does 0x61 and 0x42, etc. come from" ? --> these are port addresses, indicating the individual device/function you want to access. Get yourself "helppc" or google for Ralf Brown Interrupt List which should (iirc) feature a map of standard I/O ports, what specific bits they have and how things works in general.
[*] "why settings | 3 turns speaker on ?" or "why initialize timer with 0xb6 ?" then head yourself to datasheets of 8253 and 8042 or find a copy of "the indispensable PC hardware" book...
If you have some other question that pops in your mind, then _please_ take the time to make them clear on paper and ask them. There's no such thing like a tutorial that can read in your mind and see why you're confuse and unconfuse you by making something appear in front of your eyes, you know.
And sorry if i cannot come with "just a good tutorial": the word "tutorial" was still unknown to me when i first used IN and OUT, so ...
Re:ports programming
okay...
thankx guys next time i'm ganna try to be more clear and explicit...
I saw a lot of free operating systems where using turbo C 3.0
so Pype.CliCker what do you advice me to use?
and i have another question,i have just got a simple mouse driver
written in assembly 16bit(source code and an exe file) ,
how can i use it with my os?
thankx guys next time i'm ganna try to be more clear and explicit...
I saw a lot of free operating systems where using turbo C 3.0
so Pype.CliCker what do you advice me to use?
and i have another question,i have just got a simple mouse driver
written in assembly 16bit(source code and an exe file) ,
how can i use it with my os?
Re:ports programming
If your OS is in 32bit protected mode, then you can use it with great difficulty (TM).
If you're writing in 16bit code it shouldnt be to hard. I assume it uses the BIOS to do most of the hard work. I guess from your previous posts that this is what you mean.
Do you understand assembly language well? If you understand it you should be able to adapt the code to your needs, but if you don't it might be very difficult.
Have you looked at Ralf Brown's Interrupt List? Its probably the best place to start if you want to learn about using the BIOS to access a floppy disk.
If you're working in protected mode, my advice is to avoid the floppy disk at first because it can be a real pain. Thats my personal opinion though, and someone else may give you different advice. If you're interested in filesystems, make a ramdisk driver to develop the fs on. If you want to learn about disk I/O, try ATA hard disk drives (floppys are slowly being phased out anyway). And lastly, if it has to be a floppy disk driver then Wikipedia has a surprisingly technical page at http://en.wikipedia.org/wiki/Floppy_disk_controller.
This should give you a few ideas to clarify what it is you actually want. Take a look around, google a bit and let us know which direction you're going.
PS. While googling for "simple floppy disk driver" (without the quotes) I came across this: http://www.generation5.org/content/2001/floppy.asp. Not at all OS related, but how could I avoid an article titled "Converting a Floppy Disk Drive into a Simple Robot".
If you're writing in 16bit code it shouldnt be to hard. I assume it uses the BIOS to do most of the hard work. I guess from your previous posts that this is what you mean.
Do you understand assembly language well? If you understand it you should be able to adapt the code to your needs, but if you don't it might be very difficult.
Have you looked at Ralf Brown's Interrupt List? Its probably the best place to start if you want to learn about using the BIOS to access a floppy disk.
If you're working in protected mode, my advice is to avoid the floppy disk at first because it can be a real pain. Thats my personal opinion though, and someone else may give you different advice. If you're interested in filesystems, make a ramdisk driver to develop the fs on. If you want to learn about disk I/O, try ATA hard disk drives (floppys are slowly being phased out anyway). And lastly, if it has to be a floppy disk driver then Wikipedia has a surprisingly technical page at http://en.wikipedia.org/wiki/Floppy_disk_controller.
This should give you a few ideas to clarify what it is you actually want. Take a look around, google a bit and let us know which direction you're going.
PS. While googling for "simple floppy disk driver" (without the quotes) I came across this: http://www.generation5.org/content/2001/floppy.asp. Not at all OS related, but how could I avoid an article titled "Converting a Floppy Disk Drive into a Simple Robot".