【发布时间】:2018-06-22 14:31:06
【问题描述】:
# Load the GDT.
mov $gdt_descriptor, %ecx
lgdt (%ecx)
mov $0x10, %cx
mov %cx, %ds
mov %cx, %es
mov %cx, %fs
mov %cx, %gs
mov %cx, %ss
ljmp $0x8, $1f
1: mov $kernel_stack, %esp
我无法理解这段代码的作用。 为什么在加载 GDT 后将 mov $0x10 移动到 cx 然后再移动到其他寄存器?而ljmp指令是做什么的?
【问题讨论】:
-
它加载全局描述符表,然后使用数据选择器加载段寄存器(可能是 32 位数据 r/w flat 4gb 段)。 LJMP 用于设置代码段(CS)。 CS不能直接用
mov指令加载。1f是标签:的地址。因此 JMP 有效地跳转到下一条指令,但同时设置 CS。
标签: assembly x86 operating-system att gdt