What does this Descriptor's init do?

a 夏天 提交于 2019-12-24 04:53:10

问题


%macro Descriptor 3
dw  %2 & 0FFFFh             
dw  %1 & 0FFFFh             
db  (%1 >> 16) & 0FFh           
dw  ((%2 >> 8) & 0F00h) | (%3 & 0F0FFh) 
db  (%1 >> 24) & 0FFh           
%endmacro ; 

LABEL_DESC_DATA:   Descriptor    0,   DataLen-1, 92h 

the things above are the definition.

here are the questions about its init:

xor eax, eax                           
mov ax, ds                              
shl eax, 4                              
add eax, LABEL_DATA                     
mov word [LABEL_DESC_DATA + 2], ax      ;what happens in this instruction?
shr eax, 16
mov byte [LABEL_DESC_DATA + 4], al
mov byte [LABEL_DESC_DATA + 7], ah

回答1:


This macro initializes a Global Descriptor Table entry (i.e. a segment descriptor). Due to x86 architecture history these descriptors have some fields split in several parts:


(picture from OS Dev wiki)

The macro takes the base, limit and access values and puts them into corresponding places of the 8-byte entry.

The code fragment initializes the Base fields of the descriptor to their runtime values. Because Base must be a linear address, it calculates that address first by using the linaddr = segment<<4 + offset formula (valid for real mode).

For more info, see the OS Dev wiki: Segmentation, GDT.



来源:https://stackoverflow.com/questions/17169003/what-does-this-descriptors-init-do

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!