flat assembler
Message board for the users of flat assembler.

Index > OS Construction > IDT problem

Author
Thread Post new topic Reply to topic
dilipcs1992



Joined: 06 Apr 2012
Posts: 8
dilipcs1992 06 Apr 2012, 18:35
Hi Everyone
I'm Developing os in fasm using Grub as my bootloader
i've printed the string on the screen, and set my own GDT and IDT and defined ISR
every thing works fine, whe i call interup, interupt is triggered and i get message on screen
but problem is if i don't call any interupt also my os is throwing Double Fault Exception, please help!
Here is my code
Code:

InstallGDT:
        cli                                                                                                                                     
        pusha                                                                                                                           
        lgdt    [GDT]                                                                                                           
        sti                                                                                                                                     
        popa                                                                                                                            ; restore registers
        ret                                                                                                                                     ; All done!
        
;*******************************************
; Global Descriptor Table (GDT)
;*******************************************

GdtData: 
        dd              0                                                                                                                       ; null descriptor
        dd              0

        dw              0FFFFh                                                                                                          ; limit low
        dw              0                                                                                                                       ; base low
        db              0                                                                                                                       ; base middle
        db              10011010b                                                                                                       ; access
        db              11001111b                                                                                                       ; granularity
        db              0

        dw              0FFFFh                                                                                                          ; limit low
        dw              0                                                                                                                       ; base low
        db              0                                                                                                                       ; base middle
        db              10010010b                                                                                                       ; access
        db              11001111b                                                                                                       ; granularity
        db              0
EndOfGdt:
GDT: 
        dw              EndOfGdt - GdtData - 1                                                                          ; limit (Size of GDT)
        dd              GdtData                                                                                                         ; base of GDT
        
        
; Interupt Descriptor Table (IDT)

InstallIDT:
        cli
        pusha
        lidt    [IDT]
        sti
        popa
        ret
        
IdtData:

        dw              (isr0 and 0FFFFh)
        dw              00001000b
        db              0
        db              10001110b
        dw              (isr0 shr 16)

        dw              (isr1 and 0FFFFh)
        dw              00001000b
        db              0
        db              10001110b
        dw              (isr1 shr 16)

        dw              (isr2 and 0FFFFh)
        dw              00001000b
        db              0
        db              10001110b
        dw              (isr2 shr 16)

        dw              (isr3 and 0FFFFh)
        dw              00001000b
        db              0
        db              10001110b
        dw              (isr3 shr 16)

        dw              (isr4 and 0FFFFh)
        dw              00001000b
        db              0
        db              10001110b
        dw              (isr4 shr 16)

        dw              (isr5 and 0FFFFh)
        dw              00001000b
        db              0
        db              10001110b
        dw              (isr5 shr 16)

        dw              (isr6 and 0FFFFh)
        dw              00001000b
        db              0
        db              10001110b
        dw              (isr6 shr 16)

        dw              (isr7 and 0FFFFh)
        dw              00001000b
        db              0
        db              10001110b
        dw              (isr7 shr 16)

        dw              (isr8 and 0FFFFh)
        dw              00001000b
        db              0
        db              10001110b
        dw              (isr8 shr 16)



EndOfIdt:

IDT:
        dw              EndOfIdt - IdtData - 1
        dd              IdtData



isr0:
   pusha
   push ds
   push es
   push fs
   push gs
   mov ax, 0x10
   mov ds, ax
   mov es, ax
   mov fs, ax
   mov gs, ax
   cld
   cli
   mov ebx,err0
   call Puts
   mov ebx,er
   call Puts
   pop ebx
   pop gs
   pop fs
   pop es
   pop ds
   popa
   sti
   iret
isr1:
   pusha
   push ds
   push es
   push fs
   push gs
   mov ax, 0x10
   mov ds, ax
   mov es, ax
   mov fs, ax
   mov gs, ax
   cld
   cli
   mov ebx,err1
   call Puts
   mov ebx,er
   call Puts
   pop ebx
   pop gs
   pop fs
   pop es
   pop ds
   popa
   sti
   iret
isr2:
  pusha
   push ds
   push es
   push fs
   push gs
   mov ax, 0x10
   mov ds, ax
   mov es, ax
   mov fs, ax
   mov gs, ax
   cld
   cli
   mov ebx,err2
   call Puts
   mov ebx,er
   call Puts
   pop ebx
   pop gs
   pop fs
   pop es
   pop ds
   popa
   sti
   iret
isr3:
   pusha
   push ds
   push es
   push fs
   push gs
   mov ax, 0x10
   mov ds, ax
   mov es, ax
   mov fs, ax
   mov gs, ax
   cld
   cli
   mov ebx,err3
   call Puts
   mov ebx,er
   call Puts
   pop ebx
   pop gs
   pop fs
   pop es
   pop ds
   popa
   sti
   iret
isr4:
   pusha
   push ds
   push es
   push fs
   push gs
   mov ax, 0x10
   mov ds, ax
   mov es, ax
   mov fs, ax
   mov gs, ax
   cld
   cli
   mov ebx,err4
   call Puts
   mov ebx,er
   call Puts
   pop ebx
   pop gs
   pop fs
   pop es
   pop ds
   popa
   sti
   iret
isr5:
  pusha
   push ds
   push es
   push fs
   push gs
   mov ax, 0x10
   mov ds, ax
   mov es, ax
   mov fs, ax
   mov gs, ax
   cld
   cli
   mov ebx,err5
   call Puts
   mov ebx,er
   call Puts
   pop ebx
   pop gs
   pop fs
   pop es
   pop ds
   popa
   sti
   iret
isr6:
   pusha
   push ds
   push es
   push fs
   push gs
   mov ax, 0x10
   mov ds, ax
   mov es, ax
   mov fs, ax
   mov gs, ax
   cld
   cli
   mov ebx,err6
   call Puts
   mov ebx,er
   call Puts
   pop ebx
   pop gs
   pop fs
   pop es
   pop ds
   popa
   sti
   iret
isr7:
   pusha
   push ds
   push es
   push fs
   push gs
   mov ax, 0x10
   mov ds, ax
   mov es, ax
   mov fs, ax
   mov gs, ax
   cld
   cli
   mov ebx,err7
   call Puts
   mov ebx,er
   call Puts
   pop ebx
   pop gs
   pop fs
   pop es
   pop ds
   popa
   sti
   iret
isr8:
   pusha
   push ds
   push es
   push fs
   push gs
   mov ax, 0x10
   mov ds, ax
   mov es, ax
   mov fs, ax
   mov gs, ax
   cld
   cli
   mov ebx,err8
   call Puts
   mov ebx,er
   call Puts
   hlt
   pop ebx
   pop gs
   pop fs
   pop es
   pop ds
   popa
   sti
   iret

ErrorMsg:
        er      db              'Exception System Halted!',10,0
        err0    db             'Division By Zero',10,0
        err1    db             'Debug',10,0
        err2    db             'NMI Interrupt',10,0
        err3    db             'Breakpoint Exception',10,0
        err4    db             'Overflow Exception',10,0
        err5    db             'BOUND Range Exceeded Exception ',10,0
        err6    db             'Invalid Opcode Exception',10,0
        err7    db             'Device Not Available Exception',10,0
        err8    db             'Double Fault Exception ',10,0

    
Post 06 Apr 2012, 18:35
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4347
Location: Now
edfed 06 Apr 2012, 23:39
you should implement the 32 first interrupt vectors as they are reserved for the cpu in protected mode. here, you just have defined the 9 first vectors, it's not enough.
Post 06 Apr 2012, 23:39
View user's profile Send private message Visit poster's website Reply with quote
dilipcs1992



Joined: 06 Apr 2012
Posts: 8
dilipcs1992 07 Apr 2012, 04:01
edfed wrote:
you should implement the 32 first interrupt vectors as they are reserved for the cpu in protected mode. here, you just have defined the 9 first vectors, it's not enough.


no i have defined 32 interrupt vectors but i have posted only some part of the code
Post 07 Apr 2012, 04:01
View user's profile Send private message Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 618
cod3b453 07 Apr 2012, 12:38
Only double fault or does it triple fault as well?
Do you know what the first exception was?
Is paging enabled?
Is the pop ebx in the ISRs correct?
Post 07 Apr 2012, 12:38
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4347
Location: Now
edfed 07 Apr 2012, 14:29
cod3b453 wrote:
Is the pop ebx in the ISRs correct?


effectivelly, this instruction seems to unbalance the stack.
Post 07 Apr 2012, 14:29
View user's profile Send private message Visit poster's website Reply with quote
smiddy



Joined: 31 Oct 2004
Posts: 557
smiddy 07 Apr 2012, 15:55
edfed wrote:
cod3b453 wrote:
Is the pop ebx in the ISRs correct?


effectivelly, this instruction seems to unbalance the stack.
This appears to be it, seems there's no "push EBX" to correspond to the pop, unless it is being done elsewhere.
Post 07 Apr 2012, 15:55
View user's profile Send private message Reply with quote
dilipcs1992



Joined: 06 Apr 2012
Posts: 8
dilipcs1992 07 Apr 2012, 16:35
cod3b453 wrote:
Only double fault or does it triple fault as well?
Do you know what the first exception was?
Is paging enabled?
Is the pop ebx in the ISRs correct?


first exception is bound range exceeded
only double fault exception, no triple fault
paging is not enabled
yes i removed pop ebx instruction.still same result
Post 07 Apr 2012, 16:35
View user's profile Send private message Reply with quote
16bitPM



Joined: 08 Jul 2011
Posts: 30
16bitPM 07 Apr 2012, 20:04
dilipcs1992 wrote:
cod3b453 wrote:
Only double fault or does it triple fault as well?
Do you know what the first exception was?
Is paging enabled?
Is the pop ebx in the ISRs correct?


first exception is bound range exceeded
only double fault exception, no triple fault
paging is not enabled
yes i removed pop ebx instruction.still same result


Probably a silly question, but since you suggested that you are writing boot code: are you already in protected mode? Wink
Post 07 Apr 2012, 20:04
View user's profile Send private message Reply with quote
flash



Joined: 11 Mar 2006
Posts: 55
Location: Cuba
flash 08 Apr 2012, 01:47
Well, may be the problem is not in your initialization code, but at the "operational" code. What are you doing after setting idtr and gdtr?
Take care about implicit ds or ss usages, it is possible you are using incorrect values at those registers.
I recommend you to write a valid descriptor for int 13(general protection fault). It is highly probable it clarifies the bugs:
codes: bits 0 and 1
INDEX: bits 3 up to end(like selectors)
bit 0. 1:External source 0: internal source
bit 1. 1:INDEX is the index of idt that cause the fault 0: index is the gdt index where the fault occurs.
Post 08 Apr 2012, 01:47
View user's profile Send private message Reply with quote
dilipcs1992



Joined: 06 Apr 2012
Posts: 8
dilipcs1992 08 Apr 2012, 11:39
flash wrote:
Well, may be the problem is not in your initialization code, but at the "operational" code. What are you doing after setting idtr and gdtr?
Take care about implicit ds or ss usages, it is possible you are using incorrect values at those registers.
I recommend you to write a valid descriptor for int 13(general protection fault). It is highly probable it clarifies the bugs:
codes: bits 0 and 1
INDEX: bits 3 up to end(like selectors)
bit 0. 1:External source 0: internal source
bit 1. 1:INDEX is the index of idt that cause the fault 0: index is the gdt index where the fault occurs.


after setting gdt and idt i just print Hello World string.
after setting valid idt descriptor
General protection fault is causing double fault exception
Post 08 Apr 2012, 11:39
View user's profile Send private message Reply with quote
BAiC



Joined: 22 Mar 2011
Posts: 272
Location: California
BAiC 11 Apr 2012, 15:02
FYI: executing a halt (hlt) with the interrupt flag cleared causes a processor freeze that can only be recovered with an advanced NMI/SMI... not sure why you've included it though.
Post 11 Apr 2012, 15:02
View user's profile Send private message Visit poster's website Reply with quote
shutdownall



Joined: 02 Apr 2010
Posts: 517
Location: Munich
shutdownall 11 Apr 2012, 21:08
dilipcs1992 wrote:

after setting valid idt descriptor
General protection fault is causing double fault exception

Maybe this is because you get interrupts ?
Did you try to disable interrupt controller ?
Maybe you get an interrupt not catched.

Did you try to disable PIC with the specified I/O addresses ?
Post 11 Apr 2012, 21:08
View user's profile Send private message Send e-mail Reply with quote
dilipcs1992



Joined: 06 Apr 2012
Posts: 8
dilipcs1992 19 Apr 2012, 18:48
yes when i disable irqs
everything is working fine, but when i enable irqs i get GP#
Post 19 Apr 2012, 18:48
View user's profile Send private message Reply with quote
shutdownall



Joined: 02 Apr 2010
Posts: 517
Location: Munich
shutdownall 20 Apr 2012, 13:03
I think (as is in my mind) you can not disable the exceptions or "traps" (IRQ 0-1F).
So must be a "real" interrupt not catched from a real time clock or something similar.
Try to catch all interrupts 00-FF and check which interrupt occurs and why.


Did you check all hints in the INTEL documentation "IA32 Software Development Guide Vol. 3a" ? Chapter 6 describes detailed interrupt system and how to be handled on about 65 pages. Wink
Post 20 Apr 2012, 13:03
View user's profile Send private message Send e-mail Reply with quote
BAiC



Joined: 22 Mar 2011
Posts: 272
Location: California
BAiC 24 Apr 2012, 04:30
perhaps it's in the code you didn't publish? "puts" isn't provided, for one.
Post 24 Apr 2012, 04:30
View user's profile Send private message Visit poster's website Reply with quote
smiddy



Joined: 31 Oct 2004
Posts: 557
smiddy 24 Apr 2012, 11:11
Here's my IDT, hopefully it will provide you with what you need. Beware, it is circa 2005 and may not be as up to date as it could be, although it still assembles and works:


Description:
Download
Filename: IDT.asm
Filesize: 93.81 KB
Downloaded: 370 Time(s)

Post 24 Apr 2012, 11:11
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.