aboutsummaryrefslogtreecommitdiff
path: root/arch/i386/gdt.c
blob: 3148096d7a3489e2250ce697b4eb9ad6f9d0ab64 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include "gdt.h"

void
SegmentDescriptor(struct SegmentDescriptor_t *self, unsigned base, unsigned limit, uint8_t access)
{
  self->base_15_0 = base & 0xffff;
  self->base_23_16 = (uint8_t)(base >> 16);
  self->base_31_24 = (uint8_t)(base >> 24);

  self->limit_15_0 = (limit <= 0xffff) ? (limit & 0xffff) : ((limit >> 12) & 0xffff);
  self->limit_19_16 = 0xfu & (uint8_t)((limit <= 0xffff) ? 0 : (limit >> 28));

  self->access = access;

  self->a = 0;
  self->rsv = 0;
  self->db = (limit > 0xffff) ? 1 : 0;
  self->granularity = (limit > 0) ? 1 : 0;
}