SkillAgentSearch skills...

X86osdev

x86 OS development using Bochs emulator. MIT xv6, JamesM's kernel development tutorials (with some changes) & more

Install / Use

/learn @therealdreg/X86osdev
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

x86 OS development using Bochs emulator (x86osdev)

Prerequisites: You need to know x86 assembly, C, GCC inline ASM, basic Linux and Windows cmd usage.

Index

Install Bochs

For Windows all are included, just download this repo:

  • https://github.com/therealdreg/x86osdev/archive/refs/heads/main.zip

For Linux you must install Bochs with debugger gui support + smp (--enable-smp, --enable-debugger and --enable-debugger-gui):

  • https://bochs.sourceforge.io/doc/docbook/user/compiling.html

Usage and Debug

WARNING: wait and be patient, Bochs is slow

  1. Copy bochs/x86osdev/Project/floppy.img to bochs/
  2. Go to bochs/
  3. run bochsdbg.bat (For Linux ./bochsdbg.sh)
  4. Click Start
  5. Click Continue (First Breakpoint):

bochs_usage

  1. When "Magic Breakpoint" text appears click Continue again (Second Magic Breakpoint):

magicbp

IMPORTANT: When you read "Run" or "Run Bochs" it means Run bochs from bochsdbg.bat (For Linux ./bochsdbg.sh) script.

With first breakpoint its possible debug bootloader code from start.

With second magic breakpoint its possible debug kernel code from start.

Debug commands: https://bochs.sourceforge.io/doc/docbook/user/internal-debugger.html

Bochs Software Magic Breakpoint

From our OS Code:

GCC:

asm volatile ("xchgw %bx, %bx");

NASM:

xchg bx, bx

Bochs Input and Output debugger macros - BochsConsolePrintChar and BochsBreak

From our OS Code:

//outputs a character to the debug console
#define BochsConsolePrintChar(c) outportb(0xe9, c)
//stops simulation and breaks into the debug console
#define BochsBreak() outportw(0x8A00,0x8A00); outportw(0x8A00,0x08AE0);

Advanced Bochs debugging

Commands supported by port 0x8A00

  • 0x8A00: Used to enable the device. Any I/O to the debug module before this command is sent is sent will simply be ignored.
  • 0x8A01: Selects register 0: Memory monitoring range start address (inclusive)
  • 0x8A02: Selects register 1: Memory monitoring range end address (exclusive)
  • 0x8A80: Enable address range memory monitoring as indicated by register 0 and 1 and clears both registers
  • 0x8AE0: Return to Debugger Prompt. If the debugger is enabled (via --enable-debugger), sending 0x8AE0 to port 0x8A00 after the device has been enabled will return the Bochs to the debugger prompt. Basically the same as doing CTRL+C.
  • 0x8AE2: Instruction Trace Disable. If the debugger is enabled (via --enable-debugger), sending 0x8AE2 to port 0x8A00 after the device has been enabled will disable instruction tracing
  • 0x8AE3: Instruction Trace Enable. If the debugger is enabled (via --enable-debugger), sending 0x8AE3 to port 0x8A00 after the device has been enabled will enable instruction tracing
  • 0x8AE4: Register Trace Disable. If the debugger is enabled (via --enable-debugger), sending 0x8AE4 to port 0x8A00 after the device has been enabled will disable register tracing.
  • 0x8AE5: Register Trace Enable. If the debugger is enabled (via --enable-debugger), sending 0x8AE5 to port 0x8A00 after the device has been enabled will enable register tracing. This currently output the value of all the registers for each instruction traced. Note: instruction tracing must

Related Skills

View on GitHub
GitHub Stars85
CategoryDevelopment
Updated2mo ago
Forks12

Languages

C++

Security Score

85/100

Audited on Jan 2, 2026

No findings