Skip to content

Instantly share code, notes, and snippets.

@pdvyas
Last active September 15, 2022 01:53
Show Gist options
  • Save pdvyas/caa812ea38cf62324814dc2ff390f887 to your computer and use it in GitHub Desktop.
Save pdvyas/caa812ea38cf62324814dc2ff390f887 to your computer and use it in GitHub Desktop.
bochs-howto

Compile bochs

  • Checkout code
cd ~/temp/bochs-svn/
svn co http://svn.code.sf.net/p/bochs/code/trunk/bochs
cd bochs
  • Patch (reqd as of writing)
Index: cpu/icache.h
===================================================================
--- cpu/icache.h	(revision 13835)
+++ cpu/icache.h	(working copy)
@@ -28,7 +28,7 @@
 
 class bxPageWriteStampTable
 {
-  const Bit32u PHY_MEM_PAGES = 1024*1024;
+  static const Bit32u PHY_MEM_PAGES = 1024*1024;
   Bit32u *fineGranularityMapping;
 
 public:
  • Build
./configure --enable-all-optimizations \
		--enable-avx \
		--enable-large-ramfile \
		--enable-smp \
		--enable-svm \
		--enable-x86-64 \
		--enable-vmx=2 \
		--with-x11 \
		--with-nogui \
		--enable-debugger \
		--disable-debugger-gui \
		--enable-x86-debugger \
		--enable-readline
make -j6

Setup bochs

  • mkdir ~/bochs. This is where you keep your bochs machine.
  • copy bochsrc
    NOTE: this needs a few ptys and takes over the following, you can reduce it but it's not a problem unless you have too many terminals open
    com1: enabled=true, mode=term, dev="/dev/ptypz"
    com2: enabled=true, mode=term, dev="/dev/ptypy"
    com3: enabled=true, mode=term, dev="/dev/ptypx"
  • cd ~/bochs #everything further is assumed to be run from here
  • disk image: a "raw" (not qcow2) disk image from vmd should work fine. Otherwise, if starting afresh,
    • bximage -q -mode=create -hd=2G obsd.img
    • Install openbsd. Use vmm to do this fast
      ftp -o /tmp/install67.iso https://fastly.cdn.openbsd.org/pub/OpenBSD/snapshots/amd64/install67.iso
      doas vmctl start -d obsd.img -r /tmp/install67.iso -c testvm
      # install install intstall (bsd, bsd.rd, base* is enough)
  • Start (from ~/bochs)
BOCHS_DIR=~/temp/bochs-svn/bochs/bochs
echo 'c\n' | $BOCHS_DIR/bochs -q
  • in another terminal, run cu /dev/ttypz to see the serial console

TODO

  • edit /etc/rc to comment out expensive ops: reorder kernel, reorder libs and a lot of start_daemon
  • edit /etc/ttys to enable more serial consoles

Compile bochs

  • Checkout code
cd ~/temp/bochs-svn/
svn co http://svn.code.sf.net/p/bochs/code/trunk/bochs
cd bochs
  • Patch (reqd as of writing)
Index: cpu/icache.h
===================================================================
--- cpu/icache.h	(revision 13835)
+++ cpu/icache.h	(working copy)
@@ -28,7 +28,7 @@
 
 class bxPageWriteStampTable
 {
-  const Bit32u PHY_MEM_PAGES = 1024*1024;
+  static const Bit32u PHY_MEM_PAGES = 1024*1024;
   Bit32u *fineGranularityMapping;
 
 public:
  • Build
./configure --enable-all-optimizations \
		--enable-avx \
		--enable-large-ramfile \
		--enable-smp \
		--enable-svm \
		--enable-x86-64 \
		--enable-vmx=2 \
		--with-x11 \
		--with-nogui \
		--enable-debugger \
		--disable-debugger-gui \
		--enable-x86-debugger \
		--enable-readline
make -j6

Setup bochs

  • mkdir ~/bochs. This is where you keep your bochs machine.
  • copy bochsrc, rc.firsttime and deploy.sh to ~/bochs/
  • cd ~/bochs #everything further is assumed to be run from here
  • make a disk image bximage -q -mode=create -hd=2G obsd.img
  • Install openbsd. Use vmm to do this fast
ftp -o /tmp/install67.iso https://fastly.cdn.openbsd.org/pub/OpenBSD/snapshots/amd64/install67.iso
doas vmctl start -d obsd.img -r /tmp/install67.iso -c testvm
# install install intstall (bsd, bsd.rd, base* is enough)
  • MAKE SURE YOU DON'T USE /mnt (the deploy script uses this as mount point)
  • run sh deploy.sh
  • in another terminal, run cu /dev/ttypz

TODO

  • edit /etc/rc to comment out expensive ops: reorder kernel, reorder libs and a lot of start_daemon
  • edit /etc/ttys to enable more serial consoles
Index: cpu/icache.h
===================================================================
--- cpu/icache.h (revision 13835)
+++ cpu/icache.h (working copy)
@@ -28,7 +28,7 @@
class bxPageWriteStampTable
{
- const Bit32u PHY_MEM_PAGES = 1024*1024;
+ static const Bit32u PHY_MEM_PAGES = 1024*1024;
Bit32u *fineGranularityMapping;
public:
# configuration file generated by Bochs
plugin_ctrl: unmapped=true, biosdev=true, speaker=true, extfpuirq=true, parallel=true, serial=true, iodebug=true
config_interface: textconfig
display_library: nogui
memory: host=512, guest=512
romimage: file="/usr/local/share/bochs/BIOS-bochs-latest", address=0x00000000, options=none
vgaromimage: file="/usr/local/share/bochs/VGABIOS-lgpl-latest"
boot: disk
floppy_bootsig_check: disabled=0
# no floppya
# no floppyb
ata0: enabled=true, ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14
ata0-master: type=disk, path="obsd.img"
ata0-slave: type=none
ata1: enabled=true, ioaddr1=0x170, ioaddr2=0x370, irq=15
ata1-master: type=none
ata1-slave: type=none
ata2: enabled=false
ata3: enabled=false
optromimage1: file=none
optromimage2: file=none
optromimage3: file=none
optromimage4: file=none
optramimage1: file=none
optramimage2: file=none
optramimage3: file=none
optramimage4: file=none
pci: enabled=1, chipset=i440fx
vga: extension=vbe, update_freq=5, realtime=1, ddc=builtin
cpu: count=1, ips=95000000, quantum=16, model=ryzen, reset_on_triple_fault=1, cpuid_limit_winnt=0, ignore_bad_msrs=1, mwait_is_nop=0
print_timestamps: enabled=0
debugger_log: blog.log
magic_break: enabled=1
port_e9_hack: enabled=0
private_colormap: enabled=0
clock: sync=realtime, time0=local, rtc_sync=0
# no cmosimage
log: -
logprefix: %t%e%d
debug: action=ignore
info: action=report
error: action=report
panic: action=ask
keyboard: type=mf, serial_delay=20000, paste_delay=100000, user_shortcut=none
mouse: type=ps2, enabled=false, toggle=ctrl+mbutton
speaker: enabled=true, mode=gui
parport1: enabled=true, file=none
parport2: enabled=false
com1: enabled=true, mode=term, dev="/dev/ptypz"
com2: enabled=true, mode=term, dev="/dev/ptypy"
com3: enabled=true, mode=term, dev="/dev/ptypx"
com4: enabled=false
set -x
SRC=~/project/openbsd-src
KERN_CONFIG=DEBUGVMM
BOCHS_DIR=~/temp/bochs-svn/bochs/bochs
doas umount /mnt || echo
doas vnconfig -u vnd0 || echo
doas vnconfig vnd0 obsd.img
doas fsck -y /dev/vnd0a
doas mount /dev/vnd0a /mnt
doas cp $SRC/sys/arch/amd64/compile/$KERN_CONFIG/obj/bsd.gdb /mnt/bsd
doas cp /bsd.rd /mnt/bsd.rd
doas cp $SRC/usr.sbin/vmd/vmd /mnt/usr/sbin/vmd
doas cp $SRC/usr.sbin/vmctl/vmctl /mnt/usr/sbin/vmctl
doas cp rc.firsttime /mnt/etc/rc.firsttime
doas umount /mnt
doas vnconfig -u vnd0
rm -r obsd.img.lock
echo 'c\n' | $BOCHS_DIR/bochs -q
echo this is the firsttime
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment