diff --git a/blog/intro.org b/blog/intro.org index 16edb72..bd0dfde 100644 --- a/blog/intro.org +++ b/blog/intro.org @@ -259,3 +259,90 @@ We will create a =run.sh= script to automate hide away the details of launching -vga std #+end_src + +Lets go through the script step by step: +The first like after the shebang that tells the loader to use =bash= as the interpreter is =set -e=, which means the script will exit immediately if any command returns a failure exit code. +This means that, if we for example don't have limine installed, the script won't try to create the image or run qemu with an incomplete setup. + +Our script currently takes a single argument, the path to the kernel binary. +Cargo allows us to set a "runner" command in the =.cargo/config.toml= file, which it will call with the path to the binary as the first argument instead of the calling the binary itself. We will make use of this feature to automatically start our kernel in qemu with the help of cargo. + +We take the first argument and extract the proper parent directory and the filename and use both to construct the path to the image file we create in the next step: +#+begin_src bash +bin="$1" + +canonicalised=$(realpath -- "$bin") +parent=$(dirname -- "$canonicalised") +bin_name=$(basename -- "$exe") + +image="$parent/$bin_name.img" +#+end_src + +Next, we check if a file exists at the path we constructed for the image file, and whether it is older than the kernel binary: +#+begin_src bash +if [[ "$canonicalised" -nt "$image" ]]; then +#+end_src + +If so, we will want to (re)create the image, starting with the =limine.conf= file the limine bootloader will read to know where to find our kernel binary: + +#+begin_src bash +cat > /tmp/limine.conf < /tmp/limine.conf < /tmp/limine.conf <