protect.c - Minix

This is a discussion on protect.c - Minix ; At line 08461: gdt[TSS_INDEX].access = PRESENT | (INTR_PRIVILEGE what is the meaning of left-shifting 0 by 5? thank you Christos...

+ Reply to Thread
Results 1 to 3 of 3

Thread: protect.c

  1. protect.c

    At line 08461:

    gdt[TSS_INDEX].access = PRESENT | (INTR_PRIVILEGE << DPL_SHIFT) | TSS_TYPE;

    what is the meaning of left-shifting 0 by 5?

    thank you

    Christos



  2. Re: protect.c

    All,

    > At line 08461:
    >
    > gdt[TSS_INDEX].access = PRESENT | (INTR_PRIVILEGE << DPL_SHIFT) | TSS_TYPE;
    >
    > what is the meaning of left-shifting 0 by 5?


    Readability. The privilege level as interrupts happens to be 0. The
    position of the access level in the segment descriptor is DPL_SHIFT.
    Spelling this out makes it understandable what's going on - leaving
    (INTR_PRIVILEGE << DPL_SHIFT) out alltogether may be confusing. Leaving
    it in shows the reader this is where that information is encoded.

    =Ben



  3. Re: protect.c

    Readability is certainly a good reason to spend some bytes more. However
    this might cause a little confusion since the access field of the current
    segdesc_s struct (the gdt[TSS_INDEX]) is an eight-bits value and line 08461
    sets the seventh bit (PRESENT) and also bits 3 and 0 of the first five bits
    (grouped together with the shifting by DPL_SHIFT). The shifting probably
    indicates that bits 0-4 that are not set are zero, something that is true
    anyway, but for readability reasons it is underlined. However, we don't
    manipulate the DPL bits (bits 5, 6) and I wonder if these bits should also
    be grouped (shifted) with the other five bits to indicate that we leave them
    untouched. In other words if the shifting should be by 7 instead of 5

    Christos

    Christos




+ Reply to Thread