Ticket #7172: selector.h

File selector.h, 1.1 KB (added by stargatefan, 13 years ago)
Line 
1/*
2** Copyright 2002, Michael Noisternig. All rights reserved.
3** Distributed under the terms of the NewOS License.
4*/
5#ifndef _I386_SELECTOR_H_
6#define _I386_SELECTOR_H_
7
8#include <arch/i386/types.h>
9
10typedef uint32 selector_id;
11typedef uint64 selector_type;
12
13// DATA segments are read-only
14// CODE segments are execute-only
15// both can be modified by using the suffixed enum versions
16// legend: w = writable
17// d = expand down
18// r = readable
19// c = conforming
20enum segment_type {
21 DATA = 0x8, DATA_w, DATA_d, DATA_wd, CODE, CODE_r, CODE_c, CODE_rc
22};
23
24#define SELECTOR(base,limit,type,mode32) \
25 (((uint64)(((((uint32)base)>>16)&0xff) | (((uint32)base)&0xff000000) | ((type)<<9) | ((mode32)<<22) | (1<<15))<<32) \
26 | ( (limit) >= (1<<20) ? (((limit)>>12)&0xffff) | ((uint64)(((limit)>>12)&0xf0000)<<32) | ((uint64)1<<(23+32)) : ((limit)&0xffff) | ((uint64)((limit)&0xf0000)<<32) ) \
27 | ((((uint32)base)&0xffff)<<16))
28
29void i386_selector_init( void *gdt );
30selector_id i386_selector_add( selector_type selector );
31void i386_selector_remove( selector_id id );
32selector_type i386_selector_get( selector_id id );
33
34#endif
35