Author Topic: Quick question about IO ports  (Read 4262 times)

0 Members and 1 Guest are viewing this topic.


  • Entrant
  • Posts: 8
Quick question about IO ports
« on: February 21, 2010, 01:08:01 AM »
Hi all,

I was wondering if it's possible to directly write to IO ports with modification of the source code?

My Assembler language experience is very limited, and the part I'm struggling with is how to address IO ports, as they are different to memory registers aren't they?

All I need to do is this: send 0x12 to IO port 0x6C and send 0x01 to IO port 0x68 whenever Chameleon boots, regardless of the OS choice... If someone could give an example of IOport addressing or know a place with more info, I'm all ears.  :)

What would be the easiest way of doing this, and would boot0 file be the best file to modify in this case?

Thanks. :)


  • VoodooLabs
  • Posts: 102
Re: Quick question about IO ports
« Reply #1 on: February 21, 2010, 06:55:43 PM »
assembly inb and outb.

you need
Code: [Select]
outb 0x12, 0x6C
outb 0x01, 0x68

if it is in a c code you can use
Code: [Select]
asm("insert assembly code here" : : );
Code: [Select]
asm("outb $0x12, $0x6C \n
     outb $0x01, $0x68 \n" : : );

« Last Edit: February 21, 2010, 07:03:50 PM by Superhai »


  • Entrant
  • Posts: 8
Re: Quick question about IO ports
« Reply #2 on: February 22, 2010, 06:08:09 PM »
Thanks for the info, I would not have managed this otherwise...

I did originally try adding my ASM code into the boot0.s and boot1.s files, but I was getting the TIMES error (too many bytes), so it turns out I had to mod the C code.

I have no experience of C, so the ASM command was a godsend.

After some more reading around I found a little subroutine, as hardcoded hex values seemed to give errors when I compiled....
Code: [Select]
static inline void outbbbyte(int port, u_int8_t data) {
asm volatile("outb %0,%w1" :: "a" (data), "d" (port));

I just fed the routine with hex values and it works great, thanks again  :)
« Last Edit: February 22, 2010, 06:11:29 PM by HuntMike »