x86_os_stu/src/include/onix/global.h

46 lines
1.4 KiB
C

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#ifndef ONIX_GLOBAL_H
#define ONIX_GLOBAL_H
#include <onix/types.h>
// 我们只使用128个, 当然全局描述符最大可以有 2**13 8192个
#define GDT_SIZE 128
#define CODE_SELECT 1 << 3 // 选择子
#define DATA_SELECT 2 << 3 // 选择子
// 全局描述符
typedef struct descriptor_t /* 共 8 个字节 */
{
unsigned short limit_low; // 段界限 0 ~ 15 位
unsigned int base_low : 24; // 基地址 0 ~ 23 位 16M
unsigned char type : 4; // 段类型
unsigned char segment : 1; // 1 表示代码段或数据段0 表示系统段
unsigned char DPL : 2; // Descriptor Privilege Level 描述符特权等级 0 ~ 3
unsigned char present : 1; // 存在位1 在内存中0 在磁盘上
unsigned char limit_high : 4; // 段界限 16 ~ 19;
unsigned char available : 1; // 该安排的都安排了,送给操作系统吧
unsigned char long_mode : 1; // 64 位扩展标志
unsigned char big : 1; // 32 位 还是 16 位;
unsigned char granularity : 1; // 粒度 4KB 或 1B
unsigned char base_high; // 基地址 24 ~ 31 位
} _packed descriptor_t;
// 段选择子
typedef struct selector_t
{
u8 RPL : 2; // Request Privilege Level
u8 TI : 1; // Table Indicator
u16 index : 13;
} selector_t;
// 全局描述符表指针
typedef struct pointer_t
{
u16 limit;
u32 base;
} _packed pointer_t;
void gdt_init();
#endif