rev |
line source |
nuclear@7
|
1 #include <string.h>
|
nuclear@7
|
2 #include "segm.h"
|
nuclear@7
|
3
|
nuclear@7
|
4 #define BIT_ACCESSED (1 << 8)
|
nuclear@7
|
5 #define BIT_WR (1 << 9)
|
nuclear@7
|
6 #define BIT_RD (1 << 9)
|
nuclear@7
|
7 #define BIT_EXP_DOWN (1 << 10)
|
nuclear@7
|
8 #define BIT_CONFORMING (1 << 10)
|
nuclear@7
|
9 #define BIT_CODE (1 << 11)
|
nuclear@7
|
10 #define BIT_NOSYS (1 << 12)
|
nuclear@7
|
11 #define BIT_PRESENT (1 << 15)
|
nuclear@7
|
12
|
nuclear@7
|
13 #define BIT_BIG (1 << 6)
|
nuclear@7
|
14 #define BIT_DEFAULT (1 << 6)
|
nuclear@7
|
15 #define BIT_GRAN (1 << 7)
|
nuclear@7
|
16
|
nuclear@7
|
17 enum {TYPE_DATA, TYPE_CODE};
|
nuclear@7
|
18
|
nuclear@7
|
19 static void segm_desc(desc_t *desc, uint32_t base, uint32_t limit, int dpl, int type);
|
nuclear@7
|
20
|
nuclear@7
|
21
|
nuclear@7
|
22 static desc_t gdt[4];
|
nuclear@7
|
23
|
nuclear@7
|
24
|
nuclear@7
|
25 void init_segm(void)
|
nuclear@7
|
26 {
|
nuclear@7
|
27 memset(gdt, 0, sizeof gdt);
|
nuclear@7
|
28 segm_desc(gdt + SEGM_KCODE, 0, 0xffffffff, 0, TYPE_CODE);
|
nuclear@7
|
29 segm_desc(gdt + SEGM_KDATA, 0, 0xffffffff, 0, TYPE_DATA);
|
nuclear@7
|
30
|
nuclear@7
|
31 set_gdt((uint32_t)gdt, sizeof gdt - 1);
|
nuclear@7
|
32
|
nuclear@7
|
33 setup_selectors(selector(SEGM_KCODE, 0), selector(SEGM_KDATA, 0));
|
nuclear@7
|
34 }
|
nuclear@7
|
35
|
nuclear@7
|
36 uint16_t selector(int idx, int rpl)
|
nuclear@7
|
37 {
|
nuclear@7
|
38 return (idx << 3) | (rpl & 3);
|
nuclear@7
|
39 }
|
nuclear@7
|
40
|
nuclear@7
|
41 static void segm_desc(desc_t *desc, uint32_t base, uint32_t limit, int dpl, int type)
|
nuclear@7
|
42 {
|
nuclear@7
|
43 desc->d[0] = limit & 0xffff; /* low order 16bits of limit */
|
nuclear@7
|
44 desc->d[1] = base & 0xffff; /* low order 16bits of base */
|
nuclear@7
|
45
|
nuclear@7
|
46 /* third 16bit part contains the last 8 bits of base, the 2 priviledge
|
nuclear@7
|
47 * level bits starting on bit 13, present flag on bit 15, and type bits
|
nuclear@7
|
48 * starting from bit 8
|
nuclear@7
|
49 */
|
nuclear@7
|
50 desc->d[2] = ((base >> 16) & 0xff) | ((dpl & 3) << 13) | BIT_PRESENT |
|
nuclear@7
|
51 BIT_NOSYS | (type == TYPE_DATA ? BIT_WR : (BIT_RD | BIT_CODE));
|
nuclear@7
|
52
|
nuclear@7
|
53 /* last 16bit part contains the last nibble of limit, the last byte of
|
nuclear@7
|
54 * base, and the granularity and deafult/big flags in bits 23 and 22 resp.
|
nuclear@7
|
55 */
|
nuclear@7
|
56 desc->d[3] = ((limit >> 16) & 0xf) | ((base >> 16) & 0xff00) | BIT_GRAN | BIT_BIG;
|
nuclear@7
|
57 }
|