Making an OS

At a university course, we made a little toy OS. It consisted of 6 projects:

Vagrantfile - Virtual machine setup

To make the development environment reproducible, I added a Vagrantfile to the repo. After running vagrant up, almost all dev tools for testing the OS is installed.

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
  config.vm.box = "ubuntu/trusty64"

  # for GUI
  config.ssh.forward_agent = true
  config.ssh.forward_x11 = true

  config.vm.synced_folder "..", "/home/vagrant/inf3151"
  config.vm.provision "file", source: ".bochsrc", destination: "/home/vagrant/"
  config.vm.provision "file", source: ".exports", destination: "/home/vagrant/"
  
   config.vm.provision "shell", inline: <<-SHELL
     sudo apt update && sudo apt upgrade -y
     sudo apt install bochs git -y # PC emulator
     sudo apt install libc6-dev-i386 g++ g++-multilib  -y # compiling 32-bit applications
     sudo apt install build-essential libx11-dev libxrandr-dev libgtk2.0-dev -y # bochs / bochs GUI
     sudo apt install byacc flex -y # dependencies needed for installing bochs
     sudo apt install gdb qemu -y
     sudo apt install valgrind -y
     sudo locale-gen UTF-8
   SHELL
end

Installing Bochs with gui

After running vagrant up and going into the machine with vagrant ssh, we can install Bochs. This could have been part of the provisioner.

We are building Bochs from source. Be sure to change the download url for newer versions.

curl --location https://sourceforge.net/projects/bochs/files/bochs/2.6.9/bochs-2.6.9.tar.gz/download > bochs.tar.gz
tar --extract --verbose --file  bochs.tar.gz
cd bochs-2.6.9
# configure bochs
./configure --enable-debugger --enable-disasm --enable-debugger-gui --enable-pci --enable-usb --enable-usb-ohci
make

In ~/.bochsrc the path for romimage and vgaromimage need to be changed

# Configuration file for bochs.
#
# See user documentation on http://bochs.sourceforge.net/ for 
# documentation on these and more configuration directives.

###################### DEBUGGING ###############################
# Uncomment this line to enable debugging with gdb.
# gdbstub: enabled=1, port=1234
#
# Start gdb, then do
#  (gdb) target remote localhost:1234
#
# You can save gdb startup commands like the one above in a
# .gdbinit file in your home directory to avoid having to write
# them each time you initiate a debugging session. 
################################################################

# BIOS and VGABIOS images
# if the user running bochs is not admin, the paths should point to the files located in ~/<path>
# ~ must be expanded to the actual path, type "cd ~;pwd".
romimage:    file=/usr/local/share/bochs/Seabios.bin
vgaromimage: file=/usr/local/share/bochs/VGABIOS-lgpl-latest

# Use UHCI standard to access USB 
plugin_ctrl: usb_uhci=1, serial=1

# The UHCI chip is embedded  in i440fx chip
# Seabios requires pcivga adapter
pci: enabled=1, chipset=i440fx, slot1=pcivga
vga: extension=vbe, update_freq=60, realtime=1

# Enable UHCI chip and attach the image file on port 1
#  and the keypad on port 2 to test usb keyboard support
usb_uhci: enabled=1, port1=disk:./image, port2=keypad

cpu: count=1, ips=1000000, reset_on_triple_fault=1
megs: 256

# Forwards data written to IO port 0x3f8 (COM1) to the serial.out file
# Use the rsprintf() function to write to this IO port (works for P2-P6)
com1: enabled=1, mode=file, dev=serial.out

# Bochs report levels
panic: action=ask
error: action=ignore
info: action=report
debug: action=ignore

log: -
debugger_log: /dev/null

keyboard: type=mf, serial_delay=200, paste_delay=100000
# Remove comment to enable  GUI debugger
display_library: x, options="gui_debug"


# debugging

magic_break: enabled=1

Running Bochs

After running make and producing an image, bochs -q can be run inside the virtual machine, and the bochs GUI will pop up due to X11 forwaring.