"Write the OS family from scratch" using Bochs to debug the operating system

Source: Internet
Author: User

In the previous article, "Environment construction and the first Hello-world", I talked about how to install Bochs and run a HelloWorld operating system, but using the method in the previous article to install the Bochs is not support debugging, I'll show you how to install Bochs using source code compilation, and use Bochs to debug the operating system.

Compiling and installing Bochs
    • Download Bochs Source code

http://sourceforge.net/projects/bochs/files/bochs/2.6.8/

    • After decompression, enter the directory, configure

sudo ./configure --enable-debugger --enable-disasm

    • Compiling the installation

sudo make

sudo make install

At this point, Bochs is finished compiling the installation, and then we continue to use the floppy image used in the previous article.

Debugging the operating system with Bochs

After starting the Bochs with debugging, we will see that Bochs will go into an option interface and we can start debugging by selecting "6.Begin simulation".

Partial Bochs Debug Instructions Viewing register information
behavior directive example
Set breakpoints at a physical address B addr b 0x7c00
Show All current breakpoint information in FO breaks info break
continue execution until breakpoint is encountered C c
Step through s s
Stepping (encountered function skipped) n n
info CPU
R
FP
Sreg
Creg
info CPU
R
FP
Sreg
Cre
View Stack Print-stack Print-stack
viewing Memory Physical Address contents xp/nuf addr xp/40bx 0x9013e
Viewing linear address content x/nuf addr x/40bx 0x13e
disassemble a memory u start end u 0x30400 0x3040d
disassembly of each instruction executed trace-on trace-on
Print CPU information for each instruction trace-reg trace-reg

-We can use Help to view debugging assistance

Example

Use the image from the previous article to debug

<bochs:1>b 0x7c00<bochs:2>C00000003305i[bios] $Revision: 1.257 $ $Date: 2011/01/26 09:52:02 $ ... 00014041008i[bios] booting from 0000:7C00 (0) Breakpoint 1, 0x00007c00 in?? () Next at t=14041069 (0) [0x000000007c00] 0000:7c00 (UNK. Ctxt): MOV ax, CS; 8cc8<bochs:4>X/64XB 0x7c00[Bochs]:0x00007c00 <bogus+ 0>: 0x8c 0xc8 0x8e 0xd8 0x8e 0xc0 0xe8 0x020x00007c08 <bogus+ 8>: 0x00 0xeb 0xfe 0xb8 0x1e 0x7c 0x89 0xc50x00007c10 <bogus+ 16>: 0xb9 0x0d 0x00 0xb8 0x01 0x13 0xbb 0x0c0x00007c18 <bogus+ 24>: 0x00 0xb2 0x00 0xcd 0x10 0xc3 0x48 0x650x00007c20 <bogus+ 32>: 0x6c 0x6c 0x6f 0x2c 0x20 0x77 0x6f 0x720x00007c28 <bogus+ 40>: 0x6c 0x64 0x21 0x00 0x00 0x00 0x00 0x000x00007c30 <bogus+ 48>: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x000x00007c38 <bogus+ 56>: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00<bochs:5> NNext at t=14041070(0) [0X000000007C02] 0000:7c02 (UNK. Ctxt): mov ds, ax; 8ed8<bochs:6> Trace-reg onregister-tracing enabled for CPU0<bochs:7> NNext at t=14041071eax:0x00000000 0ecx:0x00090000 589824edx:0x00000000 0ebx:0x00000000 0Esp:0x0000ffd6 65494ebp:0x00000000 0esi:0x000e472c 935724EDI:0X0000FFAC 65452EIP:0X00007C04eflags 0x00000082:id VIP vif ac VM RF NT iopl=0 of DF if TF SF ZF AF PF CF(0) [0X000000007C04] 0000:7C04 (UNK. Ctxt): mov es, ax; 8ec0<bochs:8> C...

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Article Source: http://blog.luoyuanhang.com

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced. (Article Source: http://blog.luoyuanhang.com)

"Write the OS family from scratch" using Bochs to debug the operating system

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.