问题
%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