【发布时间】:2023-10-18 07:49:01
【问题描述】:
我正在尝试了解操作系统的基础知识,并在 OCW(名为 6.828)中找到了有关它的课程。在课程的labs中找到了bootloader的代码,试过了但是没看懂下面这段代码:
# Enable A20:
# For backwards compatibility with the earliest PCs, physical
# address line 20 is tied low, so that addresses higher than
# 1MB wrap around to zero by default. This code undoes this.
seta20.1:
inb $0x64,%al # Wait for not busy
testb $0x2,%al
jnz seta20.1
movb $0xd1,%al # 0xd1 -> port 0x64
outb %al,$0x64
seta20.2:
inb $0x64,%al # Wait for not busy
testb $0x2,%al
jnz seta20.2
movb $0xdf,%al # 0xdf -> port 0x60
outb %al,$0x60
我们如何检查端口 0x64 是否忙,以及为什么要使用此端口来启用 A20 位?进一步使芯片运行到 GDT 的 32 位模式配置如下:
# Switch from real to protected mode, using a bootstrap GDT
# and segment translation that makes virtual addresses
# identical to their physical addresses, so that the
# effective memory map does not change during the switch.
lgdt gdtdesc
# Bootstrap GDT
.p2align 2 # force 4 byte alignment
gdt:
SEG_NULL # null seg
SEG(STA_X|STA_R, 0x0, 0xffffffff) # code seg
SEG(STA_W, 0x0, 0xffffffff) # data seg
gdtdesc:
.word 0x17 # sizeof(gdt) - 1
.long gdt # address gdt
上面的代码是做什么的?以“.”开头的行是什么意思?此外,汇编代码似乎有两种格式 .S 和 .asm 两者有什么区别?
【问题讨论】:
标签: assembly x86 operating-system