Page 1 of 1

How to setup IDT in Pmode, using asm

Posted: Wed Jul 21, 2004 1:20 am
by chen17981
Hi everyone

Now I am already in Pmode, following code has been move to 0x90000 physical address. When I use bochs to try my code,i find there is a big bug in my code. Attachment is my code and image.

BUG: I cannot use INT 0x0, but there is no problem with my idt setting. In bochs, when i run the INT instruction, the output is " LOCK PUSH EBX "

Pupose of following code : Setup IDT in Pmode, and have a test.

compiler: nasm

Code: Select all

[bits 32]
jmp Begin

; 2 reserved interrupts:
idtr:   dw idt_end - idt - 1   ; IDT limit
   dd idt         ; linear, physical addr

; 32 reserved interrupts:
idt:   dw test      ; entry point 15:0
   dw 0x10      ; selector
   db 0         ; word count
   db 0x8E         ; type (32-bit Ring 0 
   dw 0         ; entry point 31:16 
idt_end:

test:   cli
   mov ax,0x08
   mov gs,ax
   mov byte [gs:0xB8000],'#'
   jmp $

Begin:

xor eax,eax
mov ax,0x08                     ;0x08 is the LINEAR_SEL in GDT
mov ds,ax
mov eax,0x90000              ; I have move this progrom to 
                                     ;  0x90000 physical address
mov ebx, idt
add ebx, eax
mov dword [ds:idtr + 2 + 0x90000 ], ebx


lidt [ds:idtr + 0x90000]


int 0x0                             ; problem happen
   
hlt


Re:How to setup IDT in Pmode, using asm

Posted: Wed Jul 21, 2004 2:26 am
by Brendan
Hi,

Try this replacement:

Code: Select all

[bits 32]
[org 0x90000]
jmp Begin

   section .bss
   alignb 4
   resb 1024
STACKTOP:
   section .text

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;   interrupt descriptor table (IDT)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; 2 reserved interrupts:
idtr:   dw idt_end - idt - 1   ; IDT limit
   dd idt         ; linear, physical address of IDT

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;   interrupt descriptor table (IDT)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; 32 reserved interrupts:
idt:   dw (unhand & 0xFFFF)   ; entry point 15:0
   dw 0x10         ; selector
   db 0         ; word count
   db 0x8E         ; type (32-bit Ring 0 interrupt gate)
   dw (unhand >> 16)   ; entry point 31:16 (XXX - unhand >> 16)
idt_end:

unhand:
;   cli     <-- not needed for interrupt gate
   mov ax,0x08
   mov gs,ax
   mov byte [gs:0xB8000],'#'
   jmp $

Begin:
   mov ax,0x08
   mov ds,ax
   mov es,ax
   mov fs,ax
   mov gs,ax
   mov ss,ax
   mov esp,STACKTOP

   lidt [idtr]
   int 0x0
   hlt


Cheers,

Brendan

Re:How to setup IDT in Pmode, using asm

Posted: Wed Jul 21, 2004 2:44 am
by Solar
@ chen17981:

Would you mind keeping related questions in one thread? Right now you're spreading the general topic "how to get pmode and my interrupt handlers to co-operate" across four forum threads...

Re:How to setup IDT in Pmode, using asm

Posted: Wed Jul 21, 2004 8:32 am
by chen17981
Thank you very much,Brendan

I try your code, all is ok. And I found the bug in my code, I forgot that i am already in Pmode, so i ignore the offset of Interrupt handle.


Hi,Solar
i am sorry, i think your advice is good, in future i will take care of this problem.