Page 1 of 1

Problems with IDT

Posted: Thu Jan 08, 2009 10:19 am
by Baxos
Hello out there! =)
Im writing an os in pascal using Fpc as compiler
then i was following JamesMolly's tutorial about IDT & GDT
but i just cant get the idt and gdt working
in the gdt i have an error in the flush
and in the idt it just wont say that an interrupt happend, even if im calling isr0(); from kernel it wont say anything
my isr0 looks like this :

Code: Select all

procedure isr0(); assembler;  [public, alias: 'isr0'];
asm
	cli
	push byte 0
	push byte 0
	jmp isr_common_stub 
end;
the error in the Gdt code is as i said in the flush

Code: Select all

procedure gdt_flush (ptn: LongWord); assembler;
asm
	mov eax, ptn
	lgdt [eax]       
 
	mov ax, $10     
	mov ds, ax        <-- Error here
	mov es, ax         And here and the rest of the moving of the segments
	mov fs, ax
	mov gs, ax
	mov ss, ax
end;
Cry cry what do i do wrong? :/

Re: Problems with IDT

Posted: Thu Jan 08, 2009 12:46 pm
by CodeCat
I don't know much about Pascal but it seems to me your selector is invalid, as it's not a multiple of 8.

Re: Problems with IDT

Posted: Thu Jan 08, 2009 1:08 pm
by Baxos
And that means? :)
I have just followed JamesMolly's guide http://www.jamesmolloy.co.uk/tutorial_html/index.html

Re: Problems with IDT

Posted: Thu Jan 08, 2009 2:56 pm
by AJ
Hi,

It means that in all probability you meant to load the segment selectors with 0x10 (10h), not 10.

Cheers,
Adam

Re: Problems with IDT

Posted: Thu Jan 08, 2009 2:58 pm
by Baxos
AJ wrote:Hi,

It means that in all probability you meant to load the segment selectors with 0x10 (10h), not 10.

Cheers,
Adam
$10 is 10h in pascal, as far i know?

Re: Problems with IDT

Posted: Thu Jan 08, 2009 3:05 pm
by AJ
Hi,

I don't know Pascal, but here are a few of likely candidates:
1) Is each bit in your GDT correct?
2) If $10 is 10h in Pascal, does that apply even for inline assembly, or does $ simply represent an immediate value?
3) Does Pascal add any preamble to its functions (in which case, that ISR will be dodgy).
4) Do you understand what each piece of code is doing, or have you simply translated the code directly? Are you happy that you understand what assembly is being generated from your Pascal code?

Also, what is the error with reloading the GDT? Does the machine triple fault, or is it a compile-time error?

Cheers,
Adam

Re: Problems with IDT

Posted: Fri Jan 09, 2009 12:50 am
by System123
Yes $10 in Pascal is 0x10. Pascal uses $ to address hex values.

Did you pack you GDT and IDT descriptors?
Did you set up atleat 1 code and on data segment for the GDT?
If in the end you can't get it working I will let you see my code, as my OS is in pascal and is based on JamesM's tutorials. But first you going to have to try yourself.

Ok let me help you with this a bit. It should read as so to flush your GDT.
Baxos wrote:Code:
procedure gdt_flush (ptn: LongWord); assembler; nostackframe;
label flush;
asm
lgdt [ptn]

mov ax, $10
mov ds, ax <-- Error here
mov es, ax And here and the rest of the moving of the segments
mov fs, ax
mov gs, ax
flush:
end;
The next part CAN'T be done in pascal it has to be in an external assembler file, ie STUB.s
The reason is that pascal does not follow the cdecl calling convention needed by the ISR_Handler to obtain the correct information.
Baxos wrote:Code:
procedure isr0(); assembler; [public, alias: 'isr0'];
asm
cli
push byte 0
push byte 0
jmp isr_common_stub
end;