stdlibc: \!perror()
[meinos.git] / kernel2 / include / gdt.h
blobe73f04d3208d99159c9fe44f1981441185ce7020
1 /*
2 meinOS - A unix-like x86 microkernel operating system
3 Copyright (C) 2008 Janosch Gräf <janosch.graef@gmx.net>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #ifndef _GDT_H_
20 #define _GDT_H_
22 #include <sys/types.h>
23 #include <stdint.h>
25 #define GDT_CODESEG 0x0A
26 #define GDT_DATASEG 0x02
27 #define GDT_TSS 0x09
28 #define GDT_PRESENT 0x80
29 #define GDT_SEGMENT 0x10
31 #define GDT_TSSDESC 8
33 #define GDT_MAXDESC 64
35 #define IDX2SEL(idx,priv) (((idx)<<3)|(priv))
37 typedef enum {
38 PRIV_KERNEL = 0,
39 PRIV_USER = 3
40 } priv_t;
42 /*typedef struct {
43 unsigned limit0_15:16;
44 unsigned base0_15:16;
45 unsigned base16_23:8;
46 unsigned accessed:1;
47 unsigned int rw:1;
48 enum {
49 GDT_UP = 0,
50 GDT_DOWN = 1
51 } dc:1;
52 enum {
53 GDT_DATA = 0,
54 GDT_CODE = 1
55 } type:1;
56 unsigned notsystem:1;
57 priv_t priv:2;
58 unsigned present:1;
59 unsigned zero:2;
60 enum {
61 GDT_16BIT = 0,
62 GDT_32BIT = 1,
63 } size:1;
64 gran_t granular:1;
65 unsigned limit16_19:4;
66 unsigned base24_31:8;
67 } __attribute__ ((packed)) gdtdesc_t;*/
68 typedef struct {
69 uint16_t size0_15;
70 uint16_t base0_15;
71 uint8_t base16_23;
72 uint8_t access;
73 uint8_t flags;
74 uint8_t base24_31;
75 } __attribute__ ((packed)) gdtdesc_t;
77 typedef struct {
78 uint16_t size;
79 uint32_t offset;
80 } __attribute__ ((packed)) gdtsel_t;
82 typedef struct {
83 priv_t priv:2;
84 unsigned ti:1;
85 unsigned index:13;
86 } __attribute__ ((packed)) selector_t;
88 typedef gdtdesc_t* gdt_t;
90 //gdt_t gdt;
91 gdtdesc_t gdt[GDT_MAXDESC];
93 int gdt_init();
94 void gdt_set_descriptor(int segment,size_t size,void *base,int access,priv_t priv);
96 #endif