Page 1 of 1

exception when calling an int

Posted: Mon Jan 12, 2015 10:59 am
by Realtime
I was trying to develop an os in nasm but i got stuck in IDT:

The exception:

Code: Select all

Booting from 0000:7c00
00015496180e[CPU0  ] interrupt(): gate descriptor is not valid sys seg (vector=0x12)
00015496180e[CPU0  ] interrupt(): gate descriptor is not valid sys seg (vector=0x0d)
00015496180e[CPU0  ] interrupt(): gate descriptor is not valid sys seg (vector=0x08)
00015496180i[CPU0  ] CPU is in protected mode (active)
00015496180i[CPU0  ] CS.mode = 32 bit
00015496180i[CPU0  ] SS.mode = 32 bit
00015496180i[CPU0  ] EFER   = 0x00000000
00015496180i[CPU0  ] | EAX=00008e00  EBX=000003fc  ECX=00090000  EDX=00000000
00015496180i[CPU0  ] | ESP=00007bff  EBP=00000000  ESI=000e055d  EDI=0000ffac
00015496180i[CPU0  ] | IOPL=0 id vip vif ac vm RF nt of df if tf sf zf af pf cf
00015496180i[CPU0  ] | SEG sltr(index|ti|rpl)     base    limit G D
00015496180i[CPU0  ] |  CS:0008( 0001| 0|  0) 00000000 000fffff 0 1
00015496180i[CPU0  ] |  DS:0010( 0002| 0|  0) 00000000 000fffff 0 1
00015496180i[CPU0  ] |  SS:0010( 0002| 0|  0) 00000000 000fffff 0 1
00015496180i[CPU0  ] |  ES:0010( 0002| 0|  0) 00000000 000fffff 0 1
00015496180i[CPU0  ] |  FS:0010( 0002| 0|  0) 00000000 000fffff 0 1
00015496180i[CPU0  ] |  GS:0010( 0002| 0|  0) 00000000 000fffff 0 1
00015496180i[CPU0  ] | EIP=00007e2f (00007e2f)
00015496180i[CPU0  ] | CR0=0x60000011 CR2=0x00000000
00015496180i[CPU0  ] | CR3=0x00000000 CR4=0x00000000
00015496180i[CPU0  ] 0x0000000000007e2f>> int 0x12 : CD12
00015496180e[CPU0  ] exception(): 3rd (13) exception with no resolution, shutdown status is 00h, resetting
00015496180i[SYS   ] bx_pc_system_c::Reset(HARDWARE) called
00015496180i[CPU0  ] cpu hardware reset
My Codes:

Code: Select all

bits 32
org 0x7e00
%include "preproc.asm"

mov dword[MMNGR_TableBegin],0x7c00
mov dword[MMNGR_MinVal],0x100000
mov dword[MMNGR_MaxEntries],0x100

mov al,0x0c
call SetColor
call ClrScr

call IDT_Init
int 0x12

cli
hlt
%include "print32.asm"
%include "MMNGR.asm"
%include "IDT.asm"
And:

Code: Select all

%ifndef IDT_asm
%define IDT_asm
%include "preproc.asm"

bits 32

struc IDT_interrupt
	.baseLow resw 1
	.selector resw 1
	.reserved resb 1
	.flags resb 1
	.baseHi resw 1
endstruc

%define IDT_IDTBegin 0x7400

IDT_IDTPTR:
	.limit dw 0x800
	.base  dd IDT_IDTBegin

IDT_InvalidInt:
	call ClrScr
	ldstr ebx,"Invalid Interrupt Call"
	call Puts
	jmp $
	
IDT_SetInt:
	push eax
	push ebx
	push ecx
	lea eax,[ebx*8+IDT_IDTBegin]
	mov word[eax],cx
	inc eax
	inc eax
	mov word[eax],0x8
	inc eax
	mov byte[eax],0
	inc eax
	mov byte[eax],010001110b
	inc eax
	shr ecx,16
	mov word[eax],cx
	pop ecx
	pop ebx
	pop eax
	ret
	
IDT_Init:
	push ebx
	push ecx
	xor ebx,ebx
	mov ecx,IDT_InvalidInt
	_loop:
		call IDT_SetInt
		inc ebx
		cmp ebx,0x100
		jl _loop
	lidt [IDT_IDTPTR]
	pop ecx
	pop ebx
	ret

	
%include "print32.asm"

%endif
Can anyone see the problem? Thanks in advance.

Re: exception when calling an int

Posted: Mon Jan 12, 2015 11:13 am
by iansjack
interrupt(): gate descriptor is not valid sys seg (vector=0x12)
interrupt(): gate descriptor is not valid sys seg (vector=0x0d)
interrupt(): gate descriptor is not valid sys seg (vector=0x08)

Re: exception when calling an int

Posted: Mon Jan 12, 2015 11:15 am
by Realtime
iansjack wrote:
interrupt(): gate descriptor is not valid sys seg (vector=0x12)
interrupt(): gate descriptor is not valid sys seg (vector=0x0d)
interrupt(): gate descriptor is not valid sys seg (vector=0x08)
Well , i thought that had something to do with it but .. I have no idea what it means :(

Re: exception when calling an int

Posted: Mon Jan 12, 2015 11:38 am
by iansjack
Have you read about descriptors and descriptor tables in the Intel Programmer's Manuals? That should tell you all you need to know.

Re: exception when calling an int

Posted: Mon Jan 12, 2015 12:27 pm
by Realtime
Ok i found the problem .. IDT_SetInt function doesn't set the Ints right .. When i defined the idt in the file with everything in place it worked ... Now i have to find what's IDT_SetInt's problem .. Can anyone help me again :D pretty pleaaase ??

Re: exception when calling an int

Posted: Mon Jan 12, 2015 1:57 pm
by eryjus
iansjack wrote:Have you read about descriptors and descriptor tables in the Intel Programmer's Manuals? That should tell you all you need to know.
Go get the Intel manuals. You are not setting up the IDT entry (flags) correctly.

Re: exception when calling an int

Posted: Mon Jan 12, 2015 1:58 pm
by Realtime
Thank you all guys I finally fixed it .. My interrupts work just fine now :)