Page 1 of 2

Call gates

Posted: Sun Aug 08, 2004 6:16 am
by Eric
What?s the differences between regular interrupt/trapgates and Call gates. Is there anything special that has to be done when I?d like to use call gates? (Or do I still use the IDT to set them up)?

Re:Call gates

Posted: Sun Aug 08, 2004 10:16 am
by ManOfSteel
They are set up like segment descriptors in the GDT.
Like this:

Code: Select all

         dw 0                      ;Offset (low word)
         dw 08h                    ;Code segment
         db 0
         db 11101100b              ;present (1), ring3 (11), type (01100)
         dw 0                      ;Offset (high word)
The offset is manually set (I do it like that).

They are used like this: "call gdtentrynumber:offset"
E.g.:

Code: Select all

call 28h:0h
The offset is not important.

Re:Call gates

Posted: Sun Aug 08, 2004 10:24 am
by Eric
you mean that the descriptors look like the GDT or that I actually set them in the GDT?
thank you!

Re:Call gates

Posted: Sun Aug 08, 2004 10:31 am
by Candy
of course, because the offset is not used (not reserved, but not used) you can abuse it for your goals. Try using it as a first parameter, selector for which function it is, or something auxiliary.

Re:Call gates

Posted: Sun Aug 08, 2004 10:38 am
by Eric
alright :)
but I read that I can use call gates for syscalls.. how do I do that? Suppose I have a function written in C in my kernel, how do I make my call gate call it? and how do I "call" a call gate from C? Right now Im using trap gates using the INT command for syscalls, but I?d like to try with call gates

Re:Call gates

Posted: Sun Aug 08, 2004 10:52 am
by Candy
Eric wrote: alright :)
but I read that I can use call gates for syscalls.. how do I do that? Suppose I have a function written in C in my kernel, how do I make my call gate call it? and how do I "call" a call gate from C? Right now Im using trap gates using the INT command for syscalls, but I?d like to try with call gates
To call them, use

Code: Select all

asm ("call $<gate>:$<some number>");
and add to the asm command that all registers plus memory can be clobbered (IE: used). This way you don't have to save too much in the called function. The <some-number> doesn't matter btw, it's totally ignored.

Re:Call gates

Posted: Sun Aug 08, 2004 10:54 am
by Eric
I dont really understand how I set the function I?d like to call? Like in the IDT, I set a pointer to which function that should be executed, but dont really how I get a call gate a call a certain C function

Re:Call gates

Posted: Sun Aug 08, 2004 11:32 am
by Candy
Eric wrote: I dont really understand how I set the function I?d like to call? Like in the IDT, I set a pointer to which function that should be executed, but dont really how I get a call gate a call a certain C function
You set the GDT gate to the function, instead of the IDT gate... Not much difference afaik.

Re:Call gates

Posted: Sun Aug 08, 2004 11:45 am
by Eric
But where in the GDT do I save the adress of the function I?d like to call? In the "base-address" spaces? That makes sense to me. If it?s correct?

But if I use C (GCC) I cant make a "call" like "call Segment:offset"(GCC is using a flat memory model). And can an application(ring 3) really do this?

Re:Call gates

Posted: Sun Aug 08, 2004 2:04 pm
by mpp.eox3
OT
02915721ada53213a49b4f4daba98b952ddb657125960c ->; if you know LZW, decode it. B&;W image, white is 0, 11x11 dimension. Enjoy
yay nice homework :)
I tried to do it with pen&paper.. but could you please tell what's your dictionary size?
or better with how many bits have you encoded each "character"?
I guessed/tried on the calculater (23*8) mod x with x=5,6,7,8,9,10,11,12,13,.. but I always get some remainders..

If I succeed in decoding and get to see your bitmap, I'll make up a pen&paper riddle for you too if you want ;)
(might be DCT, FFT, arithmetic coder or huffman)

Re:Call gates

Posted: Sun Aug 08, 2004 2:14 pm
by Candy
mpp.eox3 wrote: OT
02915721ada53213a49b4f4daba98b952ddb657125960c ->; if you know LZW, decode it. B&;W image, white is 0, 11x11 dimension. Enjoy
yay nice homework :)
I tried to do it with pen&paper.. but could you please tell what's your dictionary size?
or better with how many bits have you encoded each "character"?
I guessed/tried on the calculater (23*8) mod x with x=5,6,7,8,9,10,11,12,13,.. but I always get some remainders..

If I succeed in decoding and get to see your bitmap, I'll make up a pen&paper riddle for you too if you want ;)
(might be DCT, FFT, arithmetic coder or huffman)
If you do make one, please do a jpeg stream... gotta learn decoding them :)

It's 1-bit btw, with 0=white, 1=black, 2=clearcode, 3=EOI. Thus it starts with 3-bit (5x), then 4-bit (8x), then 5-bit... etc :)

Think I've padded a bit there...

Got some hints to default quantization tables for jpeg? And preferably a nice calculation method to do the DCT?

Re:Call gates

Posted: Sun Aug 08, 2004 4:34 pm
by Eric
I did as you told me but when I try it I get

call_protected: invalid CS descriptor

in bochs

Re:Call gates

Posted: Sun Aug 08, 2004 4:48 pm
by Eric
I moved the descriptor to offset 0x26.. bochs doesnt halt but I get general protection fault..

Re:Call gates

Posted: Sun Aug 08, 2004 5:18 pm
by Eric
it works now =)
just one thing I dont understand. The "far call" call 026h:0 sets cs = 026h. But how is the normal value of cs set back? (cause I dont do it) ? My code segment = 08h. Does the call gate set cs=08 automaticlly (spelling?) as soon as it gets called?

Re:Call gates

Posted: Mon Aug 09, 2004 2:15 am
by Candy
Eric wrote: it works now =)
just one thing I dont understand. The "far call" call 026h:0 sets cs = 026h. But how is the normal value of cs set back? (cause I dont do it) ? My code segment = 08h. Does the call gate set cs=08 automaticlly (spelling?) as soon as it gets called?
CS is not set to 26h afaik, the CS loaded is the one specified in the call gate. The previous one is popped off the stack on return.