IDT+GDT Pointer

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
distantvoices
Member
Member
Posts: 1600
Joined: Wed Oct 18, 2006 11:59 am
Location: Vienna/Austria
Contact:

IDT+GDT Pointer

Post by distantvoices »

Salut messieurs et dames!

I am now in the point in development of operating system, where I have sucessfully loaded Gdt & IDT and also installed some pretty neat irq & exception handlers, and now, i want to move that whole thing to memory location above 1 mb.

I understand, that I have to build according values for the gdt register as well as the idt register, where in both cas3es is as example the idtr in pseudocode:

idtr: unsigned int limit; unsigned long base;

in limit I have to put a value representing the length of the idt: (8 * nr.of entries p.ex. 8*60) In nasm this is idt-end - idt - 1.

In base, i have to put the PHYSICAL address of the which shall be a pointer containing the value of DS-Base & the offset from DS-base to the Location of the idt, sinc in most examples I have studied, there is some Left shift of bits after one hase moved DS-Base to some register, and after that comes a move ?from an other register containing the relative adress of the idt to the register containing DS-Base(already shifted).

So i would code this in nasm:


mov ax,ds

mov bx,[idt]

shl eax,16 -->shift eax by 16 bits to left.

or eax,ebx --> to get the value of ebx to eax, so eax contains the 32 bit physical address.

mov [idtr+6], dword[eax] --> store physical adress in idtr

mov ax,8 (size of idt entries)

mov bx,60 (nr of idt entries)

mul ax,bx

mov [idtr],ax -> store limit in idtr

lidt [idtr]


Is this a correct way to build an appropriate IDT-Register-structure?

would be nice, because I am now to dependent from loading the kernel beneath 1 mb. I am kinda stuck to the butt with an idt fixed in my assembler files. I want to implement multitasking with the aid of the timer interrupt, and I want to add memory management to that thing as soon as possible.

thank you in advance for your help, folks!
... the osdever formerly known as beyond infinity ...
BlueillusionOS iso image
Adrian

Re:IDT+GDT Pointer

Post by Adrian »

To access memory above 1Mb gate A20:

IN AL, 0x92
OR AL, 2
OUT AL, 0x92

Then you simply copy your program into a desired place, like 0x100000 (six zeros), change your GDT entries to point to the new place, and make a jump to SYS_CODE_SEL:(offset do_pm).

Adrian
Slasher

Re:IDT+GDT Pointer

Post by Slasher »

Adrian's code is right, but i'll also suggest trying to set the A20 line through the Keyboard controller, as this was the standard way of doing this before the ps2 implemented the 0x92 port (correct me if i'm wrong anyone!).
If after you try using the keyboard and the A20 line is still not set then use Adrian's code as a fall back option!
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:IDT+GDT Pointer

Post by Pype.Clicker »

http://www.mega-tokyo.com/forum/index.p ... eadid=2492

for more info about A20 enabling ...
distantvoices
Member
Member
Posts: 1600
Joined: Wed Oct 18, 2006 11:59 am
Location: Vienna/Austria
Contact:

Re:IDT+GDT Pointer

Post by distantvoices »

salut!

first of all, thank you for your prompt and reliable reply!

I think I have used the wrong words for my question. sorry for that.

How do I make the idt /gdt relocatible to any place in the computers memory? How do I make the gdt/idt pointers independent from where they get loadet first by the bootloader BEFORE I relocate the kernel after having enabled the a20 line?

The code I have posted in my first question is intended to create idt/gdt pointers in the init sequence of the kernel. I wanted to know, if this code would work.

Thank you in advance for your help!
... the osdever formerly known as beyond infinity ...
BlueillusionOS iso image
Post Reply