Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Low level I/O access using outb and inb

i'm having hard time trying to understand how interrupts work.

the code below initialize the Programmable Interrupt Controller

  #define PIC0_CTRL 0x20    /* Master PIC control register address. */
  #define PIC0_DATA 0x21    /* Master PIC data register address. */

  /* Mask all interrupts*/
  outb (PIC0_DATA, 0xff);

  /* Initialize master. */
  outb (PIC0_CTRL, 0x11); /* ICW1: single mode, edge triggered, expect ICW4. */
  outb (PIC0_DATA, 0x20); /* ICW2: line IR0...7 -> irq 0x20...0x27. */
  outb (PIC0_DATA, 0x04); /* ICW3: slave PIC on line IR2. */
  outb (PIC0_DATA, 0x01); /* ICW4: 8086 mode, normal EOI, non-buffered. */

  /* Unmask all interrupts. */
  outb (PIC0_DATA, 0x00);

can someone explain to me how it works:

-the role of outb (i didn't understand the linux man)

-the addresses and their meaning

another unrelated question,i read that outb and inb are for port-mapped I/O, can we use memory-mapped I/o for doing Input/output communication?

thanks.

like image 891
Amine Hajyoussef Avatar asked Jan 22 '12 11:01

Amine Hajyoussef


1 Answers

outb() writes the byte specified by its second argument to the I/O port specified by its first argument. In this context, a "port" is a means for the CPU to communication with another chip.

The specific C code that you present relates to the 8259A Programmable Interrupt Controller (PIC).

You can read about the PIC here and here.

If that doesn't provide enough details to understand the commands and the bit masks, you could always refer to the chip's datasheet.

like image 76
NPE Avatar answered Sep 29 '22 06:09

NPE