PIC changing offset fails

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
oculusfervoris
Posts: 1
Joined: Sat Jun 04, 2011 8:25 am

PIC changing offset fails

Post by oculusfervoris »

Hi everyone. I have been playing around with a toy kernel for a while. Now, I have started adding interrupts. IDT is set up, ISR works, prints a line on the screen (although crashes after several hundred timer ticks, since it messes up the stack, I'll fix that later, I promise :D)

However, the timer interrupt only fires if I bind it to INT 0x8. I have added the PIC init code to the initialization sequence to remap the master PIC to INT 0x20, but the ISR runs only if I also bind it to INT 8.

I thought maybe I use C asm blocks incorrectly, so I moved the PIC init code to the ASM loader part of the kernel. Still, nothing changes, INT 8 fires, INT 0x20 doesn't. I use QEMU to run the kernel, I even thought about recompiling QEMU to add debug statements to the PIC emulation code, but it seems an unreasonable amount of work.

Could someone please proofread my PIC init asm code? I use NASM.

Code: Select all

    mov al,0x11
    out 0x20,al
    out 0xa0,al
    mov al,0x20
    out 0x21,al
    mov al,0x28
    out 0xa1,al
    mov al,0x04
    out 0x21,al
    mov al,0x02
    out 0xa1,al
    mov al,01
    out 0x21,al
    out 0xa1,al

    mov al,0xfe
    out 0x21,al
User avatar
lkurusa
Member
Member
Posts: 42
Joined: Wed Aug 08, 2012 6:39 am
Libera.chat IRC: Levex
Location: New York, NY
Contact:

Re: PIC changing offset fails

Post by lkurusa »

I admit it's been a while since I programmed the PIC, but looking at my code I find it odd that you are trying to remap both PICs in parallel. IMO, separate out programming the master and the slave. Also, you are not masking the interrupts before programming the PIC which could be a bad thing.

For reference, the code I use:

Code: Select all

  outportb(PIC0_DATA, 0xff);
  outportb(PIC1_DATA, 0xff);

  outportb(PIC0_CTRL, 0x11);
  outportb(PIC0_DATA, 0x20);
  outportb(PIC0_DATA, 0x04);
  outportb(PIC0_DATA, 0x01);

  outportb(PIC1_CTRL, 0x11);
  outportb(PIC1_DATA, 0x28);
  outportb(PIC1_DATA, 0x02);
  outportb(PIC1_DATA, 0x01);

  outportb(PIC0_DATA, 0x00);
  outportb(PIC1_DATA, 0x00);
Cheers,

Lev
Post Reply