MIT操作系统实验1-1

MIT操作系统实验1-1

lightwind

[email protected]

Part1: PC Bootstrap

1.1 Getting Started with x86 assembly

Exercise 1.Read or at least carefully scan the entire PC Assembly Language book, except that you should skip all sections after 1.3.5 in chapter 1, which talk about features of the NASM assembler that do not apply directly to the GNU assembler. You may also skip chapters 5 and 6, and all sections under 7.2, which deal with processor and language features we won't use in 6.828.

Also read the section "The Syntax" inBrennan's Guide to Inline Assemblyto familiarize yourself with the most important features of GNU assembler syntax.

 

嵌入汇编的方法:

 

asm ("pushl %eax\n\t"

     "movl $0, %eax\n\t"

     "popl %eax");


或者是:

asm ("movl %eax, %ebx");

asm ("xorl %ebx, %edx");

asm ("movl $0, _booga");


内联汇编常用限定符:

a        eax

b        ebx

c        ecx

d        edx

S        esi

D        edi

I        constant value (0 to 31)

q,r     dynamically allocated register (see below)

g        eax, ebx, ecx, edx or variable in memory

A        eax and edx combined into a 64-bit integer (use long longs)

=        output register

例如:

#define times3(arg1, arg2) \

__asm__ ( \

  "leal (%0,%0,2),%0" \

  : "=r" (arg2) \

  : "0" (arg1) );


 

Exercise 2.Scan through theUsing Bochs internal debuggersection of the Bochs user manual to get a feel for these commands and their syntax. Play with the commands a little: do some stepping and tracing through the code, examining CPU registers and memory and disassembling instructions at different points, without worrying too much yet about what the code is actually doing. While the kernel monitor is waiting for user input (or at any other time the simulation is running), you can always hit CTRL-C in the shell window from which you ran Bochs in order to halt the simulation and break back into the Bochs debugger. Be sure you understand the distinction between which software you're interacting with when you type commands in the kernel monitor versus in the Bochs debugger. 

 

Bochs的常用调试命令:
l  控制命令
c/continue        继续执行
s/step [count]    单步执行
Ctrl+C            停止执行,返回命令行
Ctrl+D            退出Bochs
q/quit/exit       退出调试和执行
l  查看所有的寄存器
dump_cpu
info cpu
操作CPU寄存器的命令
set reg = expr
如:set eax = 2
l  监视内存命令
watch r/read addr 在物理地址addr处插入一个读内存监视符
watch w/write addr 在物理地址addr处插入一个写内存监视符
watch 显示当前所有内存监视符
watch stop 设定程序执行到所对应的位置时,若读写条件满足则停止(默认设置)
watch continue 设定程序执行到所对应的位置时,若读写条件满足还是继续执行
unwatch addr 去除内存addr处的监视符
unwatch 去除所有内存读写监视符
l  查看内存
x [/nuf] addr 查看当前内存某个地址的内容,addr代表线性地址
xp [/nuf] addr 查看当前内存某个地址的内容,addr代表物理地址
其中: n表示显示内存的单元数
       u分为四种情况:
                  b---字节
                  h---字(2个字节)
                  w---双字(4个字节)
                  g---长字(8个字节)
      f表示在屏上显示的形式:
                  x---以十六进制显示
                  d---以有符号十进制数显示
                  u---以无符号十进制数显示
                  o---以8进进制数显示
                  t---以二进制流显示
如:x /20 0x7c00
l  设置断点
vb seg:off    用虚拟地址设置断点,seg表示段基址,off表示偏移地址
如:vb 0x0:0x7c00
lb addr       用线性地地址来设置断点
如:lb 0x7c00
b  addr       用物理地址来设置断点
如:b 0x7c00
info b/break  显示所有断点
bpe n         激活第n个断点
bpd n         禁用第n个断点
d/del n       删除第n个断点
 
l  指令追踪命令
    trace on
    trace off
 
l  其它的命令
ptime 打印当前的时间(开始模拟后所经历的单位时间数)
sb delta 插一个时间断点,delta为单位时间数
record filename 将控制台所输入的命令记录到一个文件中,文件名为filename
playback filename 将文件中记录的命令读出来输入到控制台中
print-stack [num] 打印当前栈中的信息,以字为单位
 

1.2 The ROM BIOS

Exercise 3. Use the Bochs debugger to trace into the ROM BIOS for a few more instructions, and try to guess what it might be doing. You might want to look at the Bochs I/O address assignments, Phil Storrs I/O Ports Description, as well as other materials on the 6.828 reference materials page ( See syllabus.). No need to figure out all the details - just the general idea of what the BIOS is doing first.  

你可能感兴趣的:(汇编,assembly,Integer,vb,features,reference)