add gdt.h
This commit is contained in:
parent
bffd652c16
commit
556b0f0c4d
33
src/gdt.h
Normal file
33
src/gdt.h
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
#ifndef GDT_H
|
||||||
|
#define GDT_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint16_t size;
|
||||||
|
uint16_t offset_upper;
|
||||||
|
uint16_t offset_lower;
|
||||||
|
uint16_t _reserved;
|
||||||
|
} gdtr_t;
|
||||||
|
#define gdt_build_gdtr(size, offset) \
|
||||||
|
{(size), ((offset >> 16u) & 0xFFFFu), (offset & 0xFFFFu), 0u}
|
||||||
|
|
||||||
|
typedef uint64_t gdt_entry_t;
|
||||||
|
#define gdt_build_entry(base, limit, p, privl, s, ex, dc, rw, ac, gr, sz, l) \
|
||||||
|
(gdt_entry_t)( \
|
||||||
|
(((gdt_entry_t)base << 32) & 0xFF00000000000000ull) | /* Base 0:15 */ \
|
||||||
|
(((gdt_entry_t)gr & 0x1u) << 55) | /* Granularity (0 = bytes, 1 = blocks) */ \
|
||||||
|
(((gdt_entry_t)sz & 0x1u) << 54) | /* Size (0 = 16-bit, 1 = 32-bit) */ \
|
||||||
|
(((gdt_entry_t)l & 0x1u) << 53) | /* L flag (x86_64 code) */ \
|
||||||
|
(((gdt_entry_t)limit << 32) & 0x000F000000000000ull) | /* Limit 16:19 */ \
|
||||||
|
(((gdt_entry_t)pr & 0x1u) << 47) | /* Present flag */ \
|
||||||
|
(((gdt_entry_t)privl & 0x3u) << 45) | /* Privilege (ring level) */ \
|
||||||
|
(((gdt_entry_t)s & 0x1u) << 44) | /* Type (0 = system, 1 = code/data) */ \
|
||||||
|
(((gdt_entry_t)ex & 0x1u) << 43) | /* Executable flag */ \
|
||||||
|
(((gdt_entry_t)dc & 0x1u) << 42) | /* Direction/Conforming */ \
|
||||||
|
(((gdt_entry_t)rw & 0x1u) << 41) | /* Readable/Writable */ \
|
||||||
|
(((gdt_entry_t)ac & 0x1u) << 40) | /* Accessed flag */ \
|
||||||
|
(((gdt_entry_t)base << 16) & 0x000000FFFFFF0000ull) | /* Base 0:23 */ \
|
||||||
|
((gdt_entry_t)limit & 0x000000000000FFFFull)) /* Limit 0:15 */
|
||||||
|
|
||||||
|
#endif
|
Loading…
x
Reference in New Issue
Block a user