summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'kernel')
-rwxr-xr-xkernel/run73
1 files changed, 47 insertions, 26 deletions
diff --git a/kernel/run b/kernel/run
index df258d8..d8aa011 100755
--- a/kernel/run
+++ b/kernel/run
@@ -11,28 +11,42 @@ name="uff"
build_mode=debug
action=help
target=x86_64
-target_name="$target-$name"
-target_path="target/"
-rust_target_path="$target_path/$target_name/$build_mode/"
-iso_path="$target_path/iso/"
-obj_path="$iso_path/obj/"
-src_path="src/"
-asm_path="$src_path/"
-link_script="$src_path/linker.ld"
-grub_cfg="$src_path/grub.cfg"
+test_mode=false
+function define_vars() {
+ target_name="$target-$name"
+ target_path="target/"
+ rust_target_path="$target_path/$target_name/$build_mode/"
+ iso_path="$target_path/iso/"
+ obj_path="$iso_path/obj/"
+ src_path="src/"
+ asm_path="$src_path/"
+ link_script="$src_path/linker.ld"
+ grub_cfg="$src_path/grub.cfg"
+}
+define_vars
print_help() {
echo "usage: $0 (options) [action]"
echo "options:"
- echo " -mode=<str> set build mode (standard: debug)"
+ echo " -name=<str> set application name (standard: $name)"
+ echo " -mode=<str> set build mode (standard: $build_mode)"
+ echo " -target=<str> set target (standard: $target)"
+ echo " -test enable test mode (standard: disabled)"
+ echo
+ echo "actions:"
+ echo " build build the iso"
+ echo " run build and lauch the iso in qemu"
+ echo " test build iso in test mode and run it in qemu"
+ echo " help show this help message"
exit
}
get_rust_bin() {
- case "$action" in
- "test") echo "$rust_target_path/$(ls -t1 $rust_target_path | grep -P '^kernel-[a-fA-F0-9]+$' | head -n1)";;
- *) echo "$rust_target_path/libkernel.a";;
- esac
+ if $test_mode; then
+ echo "$rust_target_path/$(ls -t1 $rust_target_path | grep -P '^kernel-[a-fA-F0-9]+$' | head -n1)"
+ else
+ echo "$rust_target_path/libkernel.a"
+ fi
}
prepare_iso() {
@@ -50,33 +64,40 @@ prepare_iso() {
build_iso() {
ld -n -o "$iso_path/isofiles/boot/kernel.bin" -gc-sections -T "$link_script" "$obj_path"/*.o "$(get_rust_bin)"
- grub-mkrescue -d /usr/lib/grub/i386-pc -o "$iso_path/uff.iso" "$iso_path/isofiles"
+ grub-mkrescue -d /usr/lib/grub/i386-pc -o "$iso_path/$name.iso" "$iso_path/isofiles"
}
build() {
if test ! -d "$iso_path/isofiles"; then
prepare_iso
fi
- cargo xbuild
- build_iso
-}
-
-build_test() {
- if test ! -d "$iso_path/isofiles"; then
- prepare_iso
+ if $test_mode; then
+ RUSTFLAGS="-Clink-arg=-r -Clink-dead-code" cargo xtest --no-run
+ else
+ cargo xbuild
fi
- RUSTFLAGS="-Clink-arg=-r -Clink-dead-code" cargo xtest --no-run
build_iso
}
run() {
- qemu-system-x86_64 -cdrom "$iso_path/uff.iso"
+ case "$target" in
+ "x86_64")
+ qemu-system-x86_64 -cdrom "$iso_path/$name.iso";;
+ *)
+ echo "error: no laucher defined for target '$target'";;
+ esac
}
for arg in "$@"; do
case "$arg" in
-mode=*)
- build_mode="$(echo $arg | sed "s/^-mode=//")";;
+ build_mode="$(echo $arg | sed "s/^-mode=//")"; define_vars;;
+ -name=*)
+ name="$(echo $arg | sed "s/^-name=//")"; define_vars;;
+ -target=*)
+ target="$(echo $arg | sed "s/^-target=//")"; define_vars;;
+ -test)
+ test_mode=true; define_vars;;
"run") action=run;;
"build") action=build;;
"test") action=test;;
@@ -89,7 +110,7 @@ done
case "$action" in
"help") print_help;;
"build") build;;
- "test") build_test; run;;
+ "test") test_mode=true; build; run;;
"run") build; run;;
esac