x86汇编code语法 [英] Syntax of x86 assembly code
问题描述
我想了解操作系统的基本知识,并发现它OCW课程(名为6.828)。我找到了引导加载程序的code在使用过程中的实验室,我试过,但不明白code的以下部分:结果
#开启A20:#对于最早的个人电脑向后兼容性,物理#地址线20接低电平,使地址高于#1MB绕到零默认。这code解开这一点。seta20.1:
INB $ 0x64,%#人等待不旺
TESTB 0X2 $,%人
JNZ seta20.1MOVB $ 0xd1,%#人0xd1 - >端口0x64
OUTB%人,$ 0x64seta20.2:
INB $ 0x64,%#人等待不旺
TESTB 0X2 $,%人
JNZ seta20.2MOVB $ 0xdf,%#人0xdf - > 0x60端口
OUTB%人,$ 0x60的
我们如何检查,如果该端口0x64占线或没有,为什么这个端口用于使A20位?进一步使芯片运行到GDT的32位模式下配置完成后如下:
从实到保护模式,使用引导GDT#开关#和段翻译,使虚拟地址#等同于它们的物理地址,从而使#有效存储器映射中的切换期间不会改变。LGDT gdtdesc
#引导GDT
.p2align 2#4力字节对齐
GDT:
SEG_NULL#空赛格
SEG(STA_X | STA_R,为0x0,为0xffffffff)#code赛格
SEG(STA_W,为0x0,为0xffffffff)#赛格数据gdtdesc:
.word 0x17已#的sizeof(GDT) - 1
。长GDT#地址GDT
什么是上面code呢?什么是先从台词的意思。?此外,似乎有两种格式大会code .S和.ASM两者有什么区别呢?
我们如何检查,如果该端口0x64忙不?
块引用>这是在那里。如果
位#1
(值2
)被设定的端口忙。
为什么这个端口用于使A20位
块引用>历史原因的。这是很容易连线该功能集成到键盘控制器。就像CPU复位线。
什么是上面code呢?
块引用>设定了GDT三个描述:
空
,code
和数据
。我不会在这里解释一下什么是GDT以及如何保护模式的分割工作。我希望这是本教程中,否则咨询 osdev.org 。
什么是先从台词的意思。?
块引用>这些都为汇编语言指令,它们指示它做的事情。如
.word
指示它发出一个字与给定值。请参考汇编程序的使用手册。
似乎有两种格式大会code .S和.ASM
块引用>有2(或者说3,计数
.S
和.S
作为独立)装配常用扩展文件。在.S
版本一般都是GNU工具链,而.ASM
是给别人。有这样两个以上的格式,每汇编pretty太多之一。这些只是为文件常用扩展,他们并不真正定义的内容。PS:貌似你是组装一个初学者来说,这是很好的,但也许直到你搜集了一些经验,你不应该与低级别的OS的东西马上开始
。I am trying to understand the basics of operating systems and found a course on it in OCW (named 6.828). I found the code of the bootloader in the labs of the course, I tried but did not understand the following part of the code:
# 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
How are we checking if the port 0x64 is busy or not and why this port is used for enabling the A20 bit? Further to make the chip run into 32 bit mode configuration of GDT is done as follows:
# 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
What does the above code do? What is the meaning of lines starting with "."? Further, there appear to be two formats for the assembly code .S and .asm what is the difference between the two?
解决方案How are we checking if the port 0x64 is busy or not?
It's right there. If
bit #1
(value2
) is set the port is busy.why this port is used for enabling the A20 bit
Historical reasons. It was easy to wire this functionality into the keyboard controller. Just like the cpu reset line.
What does the above code do?
Sets up the GDT with three descriptors:
null
,code
anddata
. I won't explain here what the GDT is and how protected mode segmentation works. I hope it is covered in the tutorial, or else consult osdev.org.What is the meaning of lines starting with "."?
Those are directives for the assembler, they instruct it to do things. Such as
.word
instructs it to emit a word with a given value. Consult the assembler's manual for details.there appear to be two formats for the assembly code .S and .asm
There are 2 (or rather 3, counting
.s
and.S
as separate) common extensions for assembly files. The.s
versions are generally for the gnu toolchain, while.asm
is for others. There are way more than two formats, pretty much one per assembler. These are just the commonly used extensions for the files, they don't really define the contents.PS: Looks like you are a beginner with assembly, which is fine, but maybe you should not start with low-level OS stuff right away until you have gathered some experience.
这篇关于x86汇编code语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!