Problems with IDT

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
Baxos
Posts: 10
Joined: Fri Mar 07, 2008 11:52 am
Location: Denmark

Problems with IDT

Post 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? :/
CodeCat
Member
Member
Posts: 158
Joined: Tue Sep 23, 2008 1:45 pm
Location: Eindhoven, Netherlands

Re: Problems with IDT

Post 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.
Baxos
Posts: 10
Joined: Fri Mar 07, 2008 11:52 am
Location: Denmark

Re: Problems with IDT

Post by Baxos »

And that means? :)
I have just followed JamesMolly's guide http://www.jamesmolloy.co.uk/tutorial_html/index.html
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: Problems with IDT

Post by AJ »

Hi,

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

Cheers,
Adam
Baxos
Posts: 10
Joined: Fri Mar 07, 2008 11:52 am
Location: Denmark

Re: Problems with IDT

Post 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?
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: Problems with IDT

Post 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
System123
Member
Member
Posts: 196
Joined: Mon Jul 07, 2008 1:25 am

Re: Problems with IDT

Post 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;
Gizmic OS
Currently - Busy with FAT12 driver and VFS
Post Reply