src/gdt.c
/* Now we have to create the 64-bit representation of the entry.
 * Let's explain how this works:
 * The main point to understand is that by bitwise-&-ing the values
 * of the variables, we force them to a certain size. Rember two
 * hexadecimal digits are equivalent to one byte */
Now we have to create the 64-bit representation of the entry.
Let's explain how this works:
The main point to understand is that by bitwise-&-ing the values
of the variables, we force them to a certain size. Rember two
hexadecimal digits are equivalent to one byte
Now we have to create the 64 - bit representation of the entry . Let ' s explain how this works : The main point to understand is that by bitwise - & - ing the values of the variables we force them to a certain size . Rember two hexadecimal digits are equivalent to one byte
struct packed_entry repr_from_gdt_entry(struct gdt_entry entry)
{
    u16 first_word      = entry.limit & 0xffff;
    u16 second_word     = entry.base & 0xffff;
    uchar third_char    = (entry.base >> 16) & 0xff;
    uchar fourth_char   = 0xff &
                          (0x90
                            | ((entry.read_write)     << 1)
                            | ((entry.dir_or_control) << 2)
                            | ((entry.exec)           << 3)
                            | ((entry.privilege)      << 5)
                        );
    uchar fifth_char    = 0xff &
                          ((GDT_ROOT << 4)
                            | (entry.granularity << 7)
                            | ((entry.limit >> 16))
                        );
    uchar sixth_char    = (entry.base >> 24) & 0xff;
    struct packed_entry ret_val = {
            (first_word & 0xffffffff)           |
            ((second_word & 0xffffffff) << 16),
            ((third_char  & 0xffffffff))        |
            ((fourth_char & 0xffffffff) << 8)   |
            ((fifth_char  & 0xffffffff) << 16)  |
            ((sixth_char  & 0xffffffff) << 24)};
    return ret_val;
}
struct packed_entry repr_from_gdt_entry ( struct gdt_entry entry ) { u16 first_word = entry . limit & 0xffff ; u16 second_word = entry . base & 0xffff ; uchar third_char = ( entry . base >> 16 ) & 0xff ; uchar fourth_char = 0xff & ( 0x90 | ( ( entry . read_write ) << 1 ) | ( ( entry . dir_or_control ) << 2 ) | ( ( entry . exec ) << 3 ) | ( ( entry . privilege ) << 5 ) ) ; uchar fifth_char = 0xff & ( ( GDT_ROOT << 4 ) | ( entry . granularity << 7 ) | ( ( entry . limit >> 16 ) ) ) ; uchar sixth_char = ( entry . base >> 24 ) & 0xff ; struct packed_entry ret_val = { ( first_word & 0xffffffff ) | ( ( second_word & 0xffffffff ) << 16 ) , ( ( third_char & 0xffffffff ) ) | ( ( fourth_char & 0xffffffff ) << 8 ) | ( ( fifth_char & 0xffffffff ) << 16 ) | ( ( sixth_char & 0xffffffff ) << 24 ) } ; return ret_val ; }
Now we have to create the 64-bit representation of the entry.
Now we have to create the 64 - bit representation of the entry .
// This may or may not be terribly bugged. // We need bits 16-23 of base for this one. Pay attention. // Now things have gotten truly horrible. //###### WE MOVED IT ONCE!!!! // Back to normal.