How to setup IDT in Pmode, using asm

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
chen17981

How to setup IDT in Pmode, using asm

Post 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

User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re:How to setup IDT in Pmode, using asm

Post 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
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:How to setup IDT in Pmode, using asm

Post 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...
Every good solution is obvious once you've found it.
chen17981

Re:How to setup IDT in Pmode, using asm

Post 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.
Post Reply