diff --git a/.gdbinit b/.gdbinit new file mode 100644 index 0000000..24efe1e --- /dev/null +++ b/.gdbinit @@ -0,0 +1 @@ +target remote localhost:1234 diff --git a/.gitignore b/.gitignore index 566c245..d929617 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,5 @@ toolchain/ +sysroot/ +*.iso +*.img +*.log diff --git a/Makefile b/Makefile index 7febc5b..1088b87 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,12 @@ ifeq ($(MITTOS64),) $(error Build environment is not activated. Please source activate) endif -.PHONY: all +.PHONY: all clean +SHELL := bash all: +clean: + @(. util/helpers.sh; print_info "Cleaning up") + rm -f mittos64.iso + rm -f qemu-error.log diff --git a/README.md b/README.md index 054ecea..89cc118 100644 --- a/README.md +++ b/README.md @@ -19,3 +19,27 @@ automatically if you install homebrew. The rest of the packages can be installed with homebrew. You'll also want homebrews ctags. homebrew install gmp mpfr libmpc ctags + +In order to build the boot disk and run the emulator you'll need xorriso and +qemu - also installable by homebrew. + + homebrew install xorriso qemu + + +A note on qemu and compatibility +-------------------------------- +I have had great trouble with qemu, gdb and the x86_64 structure in cobination. +For now, everything seem to work in the setup I'm using if the installed +version of qemu is commit: a470b33259bf82ef2336bfcd5d07640562d3f63b built with +--enable-curses. +You may need to remove the check for wide character support in the qemu +./configure file if building under OSX with homebrew (e.g. by deleting lines: +2953, 2954, 2956, 2957, 2958) + +This is tested for GDB 7.12. + +Among the problems that may arise if wrong versions are used are: + +- g-packet something something too large in gdb +- gdb thinking sizeof(void *) == 4 even in 64 bit mode, meaning no variables can be viewed, because their addresses are truncated to 32 bits +- qemu crashing when a keyboard irq is received diff --git a/activate b/activate index 989ee69..2266248 100755 --- a/activate +++ b/activate @@ -7,6 +7,7 @@ export MITTOS64=mittos64 . util/helpers.sh export BUILDROOT=`pwd` +export SYSROOT=${BUILDROOT}/sysroot export TOOLCHAIN=${BUILDROOT}/toolchain export PATH=${TOOLCHAIN}/bin:${PATH} export TARGET=x86_64-elf diff --git a/emul b/emul new file mode 100755 index 0000000..4c8f179 --- /dev/null +++ b/emul @@ -0,0 +1,93 @@ +#!/usr/bin/env bash + +if [[ -z ${TOOLCHAIN+x} ]]; then + echo TOOLCHAIN is not set. Please source activate + exit 1 +fi + +function print_help() { + cat << EOF +emul [-gvdh] + + Runs emulator + + -g + Run with graphics window + Can also be invoked by setting EMULGFX + -v + Run in vnc mode + Can also be invoked by setting EMULVNC + Open a listening client to port 5909 to connect + -d + DON'T run gdb debugger + Can also be invoked by setting EMULNDEBUG + -h + Display help message +EOF +} + +function main() { + + EMULGFX="${EMULGFX+x}" + EMULVNC="${EMULVNC+x}" + EMULNDEBUG="${EMULNDEBUG+x}" + + local monitorwin="" + + while getopts "gvdh" OPTION; do + case ${OPTION} in + g) + readonly EMULGFX=1 + ;; + v) + readonly EMULVNC=1 + ;; + d) + readonly EMULNDEBUG=1 + ;; + h) + print_help + exit 0 + ;; + esac + done + + [[ $1 = "--" ]] && shift + EMULPARAM=("$@") + + make all || exit 1 + util/build_iso.sh || exit 1 + emulator="qemu-system-x86_64 -cdrom mittos64.iso ${EMULPARAM[@]}" + debugger=$(which x86_64-elf-linux-gdb) + + if [[ (-n ${EMULVNC}) ]]; then + # A bug in qemu means the reverse port does not work as written in the man pages + # :X,reverse will open a reverse connection on DISPLAY X, not PORT X + # i.e. PORT 5900+X + emulator="${emulator} -vnc :9,reverse" + fi + + if [[ (-n ${EMULVNC}) || (-n ${EMULGFX}) ]]; then + emulator="${emulator} -monitor stdio" + fi + + if [[ (-z ${EMULNDEBUG}) ]]; then + emulator="${emulator} -s -S" + fi + + if [[ (-z ${EMULVNC}) && (-z ${EMULGFX}) && (-n "${TMUX+x}") ]]; then + emulator="${emulator} -curses" + fi + + if [[ -n "${TMUX}" ]]; then + emulwindow=`tmux new-window -P -n "osdevemul" "${emulator} 2>qemu-error.log; tmux kill-window -t osdevemul"` + if [[ -z ${EMULDEBUG} ]]; then + debugpane=`tmux split-window -P -h -t ${emulwindow} "sleep 1; ${debugger}"` + fi + else + ${emulator} + fi + +} + +main "${@}" diff --git a/util/build_iso.sh b/util/build_iso.sh new file mode 100755 index 0000000..0e94d04 --- /dev/null +++ b/util/build_iso.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +set -e + +. util/helpers.sh + +function fail() { + print_error "Something went wrong" + die "Building boot iso failed" +} + +SYSROOT=${SYSROOT-${BUILDROOT}/sysroot} + +function collect() { +print_info "Collecting sysroot" + +mkdir -p ${SYSROOT} + +# Grub menu configuration +mkdir -p ${SYSROOT}/boot/grub +cp ${BUILDROOT}/util/grub.cfg ${SYSROOT}/boot/grub/grub.cfg +} + +function mkimage() { +print_info "Making boot disk" +grub-mkrescue -o ${BUILDROOT}/mittos64.iso ${SYSROOT} +} + +collect +mkimage diff --git a/util/grub.cfg b/util/grub.cfg new file mode 100644 index 0000000..07bf364 --- /dev/null +++ b/util/grub.cfg @@ -0,0 +1,6 @@ +set timeout=0 +set default=0 + +menuentry "mittos64" { + +}