Call gate problem... 
Author Message
 Call gate problem...

Hello. I am trying to write a small operating system, and I can't get my call
gate entries in GDT to work. When I do a "jmp 18:0" (the call gate is the
fourth descriptor), a general protection fault is generated.
The call gate entry looks like this:

extern void idle();

struct CallGate
{
 short Offset0_15;
 short Selector;
 short Flags;
 short Offset16_31;

Quote:
};

callgate[0].Offset0_15          =       (((int)idle)<<16)>>16;
callgate[0].Selector            =       0x8;
callgate[0].Flags               =       0x4600;
callgate[0].Offset16_31         =       (int)idle>>16;

The idle() funktion is just an assembly function that starts looping. The
Selector (0x8) is the normal code descriptor. If you can't see what's wrong
with this from the fragments of code I have included, but would be so kind as
to look through the rest of the code (it's not THAT big), I would be very happy
to send it to you.
Any help would be greatly appreciated.




Wed, 26 Sep 2001 03:00:00 GMT  
 Call gate problem...

says...

[ ... ]

Quote:
> struct CallGate
> {
>  short Offset0_15;
>  short Selector;
>  short Flags;
>  short Offset16_31;
> };

> callgate[0].Offset0_15     =       (((int)idle)<<16)>>16;
> callgate[0].Selector       =       0x8;
> callgate[0].Flags          =       0x4600;

First of all, you're setting the 'type' field to indicate that this is
a 286 interrupt gate rather than a call gate.  Second, you're setting
the DPL to 2, which is _probably_ not what you're starting execution
at.  Third, you've got the present bit clear, so any call through the
gate should cause an exception.  If you're running this at ring 3,
then you'd _probably_ want Flags set to 0xEC00.  (present, ring 3,
DT=0, Type = C, 0 dwords of data transferred to callee's stack (only
relevant if you're switching protection levels).

If you're going to do things like this in C, I'd suggest starting with
a more complete breakdown instead of your "flags" member, something
like this:

typedef unsigned char uchar;
typedef unsigned short ushort;

typedef struct {
        ushort offset0_15;      
        ushort selector;
        uchar param_size:5;
        char ignore:0;
        uchar type:4;
        uchar dtype:1;
        uchar dpl:2;
        uchar present:1;

Quote:
} gate_descriptor;

Note that you have to be _very_ careful when you're aliasing bit-
fields to structures that need to have a specific memory layout;
depending on the compiler you're using, you might have to rearrange
these.

Alternatively, you might write some macros to allow you to set up the
flags and such a bit more easily in assembly language.  



Thu, 27 Sep 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Call Gate Problems

2. call gates and int gates

3. Bill Gates at the Pearly Gates

4. How to use synthesis tool to get gate level netlist only containing verilog basic gates

5. Gates-gate?

6. call gate?

7. Call gate??

8. dumb me (i386 call gates)

9. i386 call gates in 32-bit segments ...

10. i386 call gate return

11. i386 call gate ...

12. interrupt and far call via task gate,alike?

 

 
Powered by phpBB® Forum Software