Call gates

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.
Eric

Call gates

Post 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)?
ManOfSteel

Re:Call gates

Post 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.
Eric

Re:Call gates

Post by Eric »

you mean that the descriptors look like the GDT or that I actually set them in the GDT?
thank you!
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:Call gates

Post 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.
Eric

Re:Call gates

Post 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
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:Call gates

Post 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.
Eric

Re:Call gates

Post 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
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:Call gates

Post 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.
Eric

Re:Call gates

Post 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?
mpp.eox3

Re:Call gates

Post 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)
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:Call gates

Post 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?
Eric

Re:Call gates

Post by Eric »

I did as you told me but when I try it I get

call_protected: invalid CS descriptor

in bochs
Eric

Re:Call gates

Post by Eric »

I moved the descriptor to offset 0x26.. bochs doesnt halt but I get general protection fault..
Eric

Re:Call gates

Post 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?
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:Call gates

Post 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.
Post Reply