ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机

2020-02-03 14:39:55王振洲

可以在这个网页上查看汇编指令,以及对应的机器码:http://x86.renejeschke.de/
注意开头多了一个0x66,解释如下:

http://wiki.osdev.org/X86-64_Instruction_Encoding里面的Prefix group 3

所以我们需要在simple_os.asm文件的开头添加.code16,这样的话就对了,但是objdump显示的又不对了,需要这样使用才行:


    
  • shuyin.wsy@10-101-175-19:~$ objdump -d -Mintel,i8086 simple_os.o      simple_os.o:     file format elf64-x86-64     
  • Disassembly of section .text:      0000000000000000 <.text>:     
  •    0:   ba f8 03                mov    dx,0x3f8         3:   00 d8                   add    al,bl     
  •    5:   04 30                   add    al,0x30         7:   ee                      out    dx,al     
  •    8:   b0 0a                   mov    al,0xa         a:   ee                      out    dx,al     
  •    b:   f4                      hlt      https://sourceware.org/binutils/docs/as/i386_002d16bit.html   
  • http://stackoverflow.com/questions/1737095/how-do-i-disassemble-raw-x86-code  
  • 我们会把这段代码,放到虚拟物理内存,也就是GPA(guest physical address)的第二个页面中(to avoid conflicting with a non-existent real-mode interrupt descriptor table at address 0),防止和实模式的中断向量表冲突。al和bl初始化为2,cs初始化为0,ip指向第二个页面的起始位置0x1000。
    除此之外,我们还有一个虚拟的串口设备,端口是0x3f8,8bit,用于输出字符。