BOCHS debugging technology
Freos Hobby OS: Frank WAN /
China core network
For any friends who want to try to write their own operating systems, I have to recommend Bochs to you. The biggest benefit of this simulator is that you can debug it in a single step. I didn't know between it, I was writing Freos almost blind, progress is very slow, especially before you didn't complete the monitor driver, you can imagine, see any error messages, I can't see the register status, this time you must I feel that Bochs is your Fuxing. ^ _ ^
Here is mainly to tell the Bochs debug command, how to configure Bochs, please refer to Bochsrc-Sample.txt, write a Bochsrc.txt. Bochsrc-sample.txt's instructions are very detailed, I believe there should be no problem. Here is an example configured by authors to Freos for reference only. Then run the bochsdbg.exe (debug mode). Note: Bochs.exe is the execution mode and cannot be debugged. The debug mode will appear the following command line:
BOCHS: 1>
The following is initially explained: Usage of each instruction ::
The execution control command C continues to execute, encounter breakpoints to stop stepi [count] to execute the count article instruction, default is 1 Si [count] Stepi abbreviation Step [count] Execute the COUNT instruction, default is 1 S [count] STEP's abbreviation Ctrl-c stops execution, return to the command line Ctrl-D After all commands are executed, exit Quit Exit Debugger Q Quit Abbreviation
Set breakpoint vbreak seg: OFF sets breakpoints in the specified virtual address (segment offset), can also use VB Seg: OFF in protection mode
LBreak addr Sets breakpoints LB AddR in a linear address
PBREAK [*] addr sets breakpoints PB [*] addr break [*] addrb [*] addr in a physical address
Info Break shows all breakpoint status, for example: ------------------------------------ Num Type DISP ENB Address1 PBREAKPOINT Keep Y 0x00007C00 Indicates a breakpoint in the physical address 0x00007c00, which is currently valid ----------------------------- ---------- Delete n Delete a breakpoint DEL ND N
With regard to physical address, linear address, and virtual address, I can only talk about my understanding, it may not be accurate. When the physical address exists, it is difficult to determine the physical address and the linear address form in real mode, so it is recommended to use physical address and linear address form in real mode. At this time, physical address and linear address are actually It is consistent. The most commonly used, for example, the computer started after the computer is 0xfff0: 0000, load the BIOS, then transfer to 0x07c0: 0000, so you can always set a physical breakpoint 0x7c00, start debugging your bootloader. View Memory X / NUF Addr View a linear address of memory XP / NUF Addr View a physical address of memory n Show how many units of memory U memory unit size, can be b-byte h word (2 bytes) W Double word (4 bytes) G 4 words (8 bytes) Note: They are not very inclined with Intel byte naming format, but comply with GDB conventions. f printing format, can be x 16 credit format print D 10 credit format print u No Symbol 10 Encult Format Print O 8 Encryption Format Print T 2 Encult Format Print
n, f, and u are optional parameters. U and F defaults to the parameters you are using, if it is used for the first time, u defaults to W, F default is X, n defaults to 1. If you do not specify NUF, then / or not. SetPMEM Addr DataSize Val Sets the physical address addr, the value of the size DataSize memory unit is Val.Crc Addr1 addr2 for the physical address range addr1 to addr2 CRC check? (Nothing) INFO DIRTY shows the page written? (Not used)
InfoInfo Program View Programs Info Registers Enumeral CPU Integer Register Remains Info Break Display Current Breakpoint Information Where Print Current Call Stack
Register Operates SET $ REG = VAL to change the contents of the register. Changeable registers are: EAX, ECX, EDX, EBX, ESP, EBP, ESI, EDI. Inverted registers include: EFLAGS, CS, SS, DS, ES, FS, GS.
For example, SET $ EAX = 0x01234567set $ EDX = 25
Info Registers Display Register Content Dump_CPU View All Register Status and CPU Status Set_CPU Set All Register Status Dump_CPU and SET_CPU Formats related to the CPU are as follows: "EAX: 0x% x / n" "EBX: 0x% x / n" ECX: 0x% x / n "" EDX: 0x% x / n "" EBP: 0x% x / n "" ESI: 0x% x / n "" EDI: 0x% x / n "" ESP: 0x% X / N " "EFLAGS: 0x% x / n" "EIP: 0x% x / n" "CS: S = 0x% x, DL = 0x% x, DH = 0x% x, valid =% u / n" "SS: S = 0x% x, DL = 0x% x, DH = 0x% x, valid =% u / n "" DS: S = 0x% x, DL = 0x% x, DH = 0x% x, valid =% u / N "" ES: S = 0x% x, DL = 0x% x, DH = 0x% x, valid =% u / n "" fs: s = 0x% x, DL = 0x% x, DH = 0x% X, Valid =% u / n "" GS: S = 0x% x, DL = 0x% x, DH = 0x% x, valid =% u / n "" "LDTR: S = 0x% x, DL = 0x% X, DH = 0x% x, valid =% u / n "" TR: S = 0x% x, DL = 0x% x, DH = 0x% x, valid =% u / n "" GDTR: base = 0x% X, LIMIT = 0x% x / n "" idtr: base = 0x% x, limited = 0x% x / n "" DR0: 0x% x / n "" DR1: 0x% x / n "" DR2: 0x% X / N "" DR3: 0x% x / n "" DR4: 0x% x / n "" DR5: 0x% x / n "" DR6: 0x% x / n "" DR7: 0x% x / n "" Tr3: 0x% x / n "" TR4: 0x% x / n "" TR5: 0x% x / n "" TR6: 0x% x / n "" TR7: 0x% x / n "" CR0: 0x% x / N "" CR1: 0x% x / n "" CR2: 0x% x / n "" CR3: 0x% x / n "" CR4: 0x% x / n "" INHIBIT_INT:% U / N "" DONE / N "Anti-assembly Disassemble Start End Announced address range set $ disassemble_size = n Tell the debugger, the properties of the reverse segment (16-bit or 32 bits, the default 32). Some of the above commands are commonly used by Bochs. I translate based on Bochs comes with the English documentation of Bochs, and I also combine some of my actual use experience, wrong, unfair, affirm a lot, welcome everyone to talk or supplement.