Page 1 of 1

Interrupt problems

Posted: Wed Sep 25, 2002 5:09 am
by Whatever5k
I am in PMode and have created an IDT...
They all have the same ISR, which does nothing than a call to putc().
So this is my IDT:

Code: Select all

; **** Interrupt Descriptor Table ****
; have 256 descriptor here, all having
; the same interrupt handler
; will change this at runtime
idt:
%rep 256
   dw 0   ; offset 15:0
   dw CS_SELECTOR   ; selector
   db 0
   db 8Eh   ; present, ring 0, '386 interrupt gate
   dw 0   ; offset 31:16
%endrep
idt_end: 

idt_ptr:
   dw idt_end - idt - 1; IDT limit
   dd idt   ; start of IDT
; **** End of Interrupt Descriptor Table ****
This here implements the ISR:

Code: Select all

; now, let's set up an IDT
   ; up to now, we have 256 descriptors
   ; so first, fill every descriptor with
   ; a common interrupt handler routine
   ; afterwards, we'll change this
   mov ecx,(idt_end - idt) >> 3   ; number of descriptors
   mov edi,idt   ; idt location
   mov esi,common_isr   ; common handler to esi

fill_idt:
   mov eax,esi
   mov [edi],ax   ; low offset
   shr eax,16
   mov [edi+6],ax   ; high offset
   add edi,8   ; descriptor length
   loop fill_idt

   lidt [idt_ptr]   ; ok, load the IDT
And this here is the common_isr:

Code: Select all

common_isr:
   ; this is the common interrupt service routine
   ; this means, we haven't implemented this
   ; interrupt yet
   ; so we just return
   extern putc
   mov eax,"g"
   push eax
   call putc
   iretd
But it doesn't work...
Bochs sais something like:
LDTR.valid=0

Somebody can help? Is my IDT not right, or is the Interrupt Service routine not correct?

Re:Interrupt problems

Posted: Wed Sep 25, 2002 5:33 am
by Whatever5k
Hm, I've changed the common_isr to:

Code: Select all

common_isr:
  call testfunction
   iret
testfunction() is a C function which just does a putc("T");
And, what do see? A "T". So, that works...the IDT is correctly set up...
But how can I move the argument for the putc() function in Assembler?

Re:Interrupt problems

Posted: Wed Sep 25, 2002 6:00 am
by Pype.Clicker

Code: Select all

   pushad ;; <-- avoid unexpected registers modifications
   mov eax,byte 'g'
   push eax
   call _putc
   add esp,4 ;; <-- don't forget to restore your stack ;)
   popad ;; <-- avoid unexpected registers modifications
   iretd

Re:Interrupt problems

Posted: Wed Sep 25, 2002 6:25 am
by Whatever5k
Yeah, I already figured it out right now...
Anyway, thanks!