操作系统学习笔记(22)--全局描述符表
2010-05-30 18:08
309 查看
在保护模式下访问内存步骤:
1 获取段选择子
2 根据GDTR寄存器获得基地址
3 和偏移地址结合获得线性地址
与内存有关的描述符
align 8, db 0 (内存对齐)
GDT_Pointer:
dw 3; limit
dd 0xAAAAAAAA +GDT ; base address
lgdt [GDT_Pointer] ; 装载GDTR
LGDT Load global descriptor table (GDT) register
On power up or reset of the processor, the base address is set to the default value of 0 and
the limit is set to FFFFH
A segment descriptor provides the base address of a segment and access rights, type, and usage information. Each segment descriptor has a segment selector associated with it. The segment selector provides an index into the GDT
or LDT (to its associated segment descriptor), a global/local flag (that determines whether the segment selector points to the GDT or the LDT), and access rights information.
1<<3 ; kernel code segment is GDT entry 1
2<<3 ; kernel data segment is GDT entry 2
分别对应下列的段选择子(Segment Selector)说明:
0000000000001000
0000000000010000
对应上面的代码的代码段和数据段
段描述符内容格式如下:对应6个字节
可对应上面的代码检查。
实例:比较92和9A的不同
可参考位置为Type
2:Read/Write Data Descriptor Type
A:Execute/Read Code Descriptor Type
G (granularity) flag
Determines the scaling of the segment limit field. When the granularity flag is
clear, the segment limit is interpreted in byte units; when flag is set, the
segment limit is interpreted in 4-KByte units. (This flag does not affect the
granularity of the base address; it is always byte granular.) When the granularity
flag is set, the twelve least significant bits of an offset are not tested when
checking the offset against the segment limit. For example, when the granularity
flag is set, a limit of 0 results in valid offsets from 0 to 4095.
上面设置为1,则后面的segment limit是作为4K为基数的。
/*
* The general format of a segment descriptor.
*/
struct Segment_Descriptor {
ushort_t sizeLow PACKED ;
uint_t baseLow : 24 PACKED ;
uint_t type : 4 PACKED ;
uint_t system : 1 PACKED ;
uint_t dpl : 2 PACKED ;
uint_t present : 1 PACKED ;
uint_t sizeHigh : 4 PACKED ;
uint_t avail : 1 PACKED ;
uint_t reserved : 1 PACKED ; /* set to zero */
uint_t dbBit : 1 PACKED ;
uint_t granularity : 1 PACKED ;
uchar_t baseHigh PACKED ;
};
15 3 2 1 0
TI
Index
Table Indicator
0 = GDT
1 = LDT
Requested Privilege Level (RPL)
RPL
/**
* Construct a segment selector.
* @param rpl requestor privilege level; should be KERNEL_PRIVILEGE
* for kernel segments and USER_PRIVILEGE for user segments
* @param segmentIsInGDT true if the referenced segment descriptor
* is defined in the GDT, false if it is defined in the LDT
* @param index index of the segment descriptor
* @return the segment selector
*/
static __inline__ ushort_t Selector(int rpl, bool segmentIsInGDT, int index)
{
ushort_t selector = 0;
selector = (rpl & 0x3) | ((segmentIsInGDT ? 0 : 1) << 2) | ((index & 0x1FFF) << 3);
return selector;
}
1 获取段选择子
2 根据GDTR寄存器获得基地址
3 和偏移地址结合获得线性地址
与内存有关的描述符
align 8, db 0 (内存对齐)
GDT: ; Descriptor 0 is not used dw 0 dw 0 dw 0 dw 0 ; Descriptor 1: kernel code segment dw 0xFFFF ; bytes 0 and 1 of segment size dw 0x0000 ; bytes 0 and 1 of segment base address db 0x00 ; byte 2 of segment base address db 0x9A ; present, DPL=0, non-system, code, non-conforming, ; readable, not accessed db 0xCF ; granularity=page, 32 bit code, upper nibble of size db 0x00 ; byte 3 of segment base address ; Descriptor 2: kernel data and stack segment ; NOTE: what Intel calls an "expand-up" segment ; actually means that the stack will grow DOWN, ; towards lower memory. So, we can use this descriptor ; for both data and stack references. dw 0xFFFF ; bytes 0 and 1 of segment size dw 0x0000 ; bytes 0 and 1 of segment base address db 0x00 ; byte 2 of segment base address db 0x92 ; present, DPL=0, non-system, data, expand-up, ; writable, not accessed db 0xCF ; granularity=page, big, upper nibble of size db 0x00 ; byte 3 of segment base address
GDT_Pointer:
dw 3; limit
dd 0xAAAAAAAA +GDT ; base address
lgdt [GDT_Pointer] ; 装载GDTR
LGDT Load global descriptor table (GDT) register
On power up or reset of the processor, the base address is set to the default value of 0 and
the limit is set to FFFFH
A segment descriptor provides the base address of a segment and access rights, type, and usage information. Each segment descriptor has a segment selector associated with it. The segment selector provides an index into the GDT
or LDT (to its associated segment descriptor), a global/local flag (that determines whether the segment selector points to the GDT or the LDT), and access rights information.
1<<3 ; kernel code segment is GDT entry 1
2<<3 ; kernel data segment is GDT entry 2
分别对应下列的段选择子(Segment Selector)说明:
0000000000001000
0000000000010000
对应上面的代码的代码段和数据段
段描述符内容格式如下:对应6个字节
可对应上面的代码检查。
实例:比较92和9A的不同
可参考位置为Type
2:Read/Write Data Descriptor Type
A:Execute/Read Code Descriptor Type
G (granularity) flag
Determines the scaling of the segment limit field. When the granularity flag is
clear, the segment limit is interpreted in byte units; when flag is set, the
segment limit is interpreted in 4-KByte units. (This flag does not affect the
granularity of the base address; it is always byte granular.) When the granularity
flag is set, the twelve least significant bits of an offset are not tested when
checking the offset against the segment limit. For example, when the granularity
flag is set, a limit of 0 results in valid offsets from 0 to 4095.
上面设置为1,则后面的segment limit是作为4K为基数的。
/*
* The general format of a segment descriptor.
*/
struct Segment_Descriptor {
ushort_t sizeLow PACKED ;
uint_t baseLow : 24 PACKED ;
uint_t type : 4 PACKED ;
uint_t system : 1 PACKED ;
uint_t dpl : 2 PACKED ;
uint_t present : 1 PACKED ;
uint_t sizeHigh : 4 PACKED ;
uint_t avail : 1 PACKED ;
uint_t reserved : 1 PACKED ; /* set to zero */
uint_t dbBit : 1 PACKED ;
uint_t granularity : 1 PACKED ;
uchar_t baseHigh PACKED ;
};
15 3 2 1 0
TI
Index
Table Indicator
0 = GDT
1 = LDT
Requested Privilege Level (RPL)
RPL
/**
* Construct a segment selector.
* @param rpl requestor privilege level; should be KERNEL_PRIVILEGE
* for kernel segments and USER_PRIVILEGE for user segments
* @param segmentIsInGDT true if the referenced segment descriptor
* is defined in the GDT, false if it is defined in the LDT
* @param index index of the segment descriptor
* @return the segment selector
*/
static __inline__ ushort_t Selector(int rpl, bool segmentIsInGDT, int index)
{
ushort_t selector = 0;
selector = (rpl & 0x3) | ((segmentIsInGDT ? 0 : 1) << 2) | ((index & 0x1FFF) << 3);
return selector;
}
相关文章推荐
- 操作系统原理学习笔记(2)之进程概念(关键词:操作系统原理学习笔记、进程、process)
- Python学习笔记22:扩展Python
- 【学习笔记】自己动手写操作系统——pmtest2
- js学习笔记22----BOM属性和方法
- 【学习笔记】自己动手写操作系统--pmtest3
- 学习笔记:一个操作系统的实现--保护模式之基础知识
- 学习笔记(一)——安装与远程连接Linux操作系统
- 用S60操作系统SDK开发NOKIA手机应用程序-学习笔记(3)
- 极具职场竞争力的操作系统背景知识学习笔记(Windows+Linux)
- 操作系统学习笔记:分布式协调
- 《Orange's 一个操作系统的实现》学习笔记(一) 实验环境搭建
- Java多线程与并发库高级应用 学习笔记 16-22课 +面试题
- python基础教程_学习笔记22:数据库支持
- iOS学习笔记22-推送通知
- 操作系统学习笔记--系统启动流程
- 2015—01—22 Shell学习笔记基础(1)
- 操作系统学习笔记(三)--进程
- 操作系统学习笔记(二):计算机硬件
- 《30天自制操作系统》11_day_学习笔记
- ES学习和使用笔记之ES配置及操作系统配置调优