diff --git a/README.md b/README.md new file mode 100644 index 0000000..48d1961 --- /dev/null +++ b/README.md @@ -0,0 +1,21 @@ +Experimenting with operating system development. + +- Programming language: [Elna](https://git.caraus.tech/belka/elna). +- Architecture: RISC-V 32-bit. +- Target machine: Qemu. + +This repository contains some rake (ruby's task runner) tasks to build +a cross compiler and the code. Assuming that all dependencies needed to build +GCC are installed in the system the build is tested on Linux an MacOS. + +To build the cross compiler do: + +```sh +rake cross +``` + +To build and run the rest in qemu: + +```sh +rake +``` diff --git a/Rakefile b/Rakefile index d54391a..adde9c3 100755 --- a/Rakefile +++ b/Rakefile @@ -324,14 +324,19 @@ def relative_from_tmp(path) Pathname.new(path).relative_path_from(TMP).each_filename end +def architecture_instruction_set(architecture) + architecture.gsub /[[:digit:]]+$/, '' +end + CLEAN.include(TMP + 'riscv32') directory(TMP + 'riscv32') rule '.s.o' => ->(match) { architecture, *path_components = relative_from_tmp(match).to_a path_components[-1] = path_components.last.ext('') + instruction_set = architecture_instruction_set architecture - [File.join(path_components), TMP + architecture] + [File.join('arch', instruction_set, path_components), TMP + architecture] } do |t| options = BuildTarget.new relative_from_tmp(t.name).first compiler = options.rootfs + "bin/#{options.target}-gcc" @@ -356,9 +361,15 @@ rule '.elna.o' => ->(match) { end rule 'kernel.elf' => ->(match) { - architecture_tmp = TMP + relative_from_tmp(match).first + architecture = relative_from_tmp(match).first + instruction_set = architecture_instruction_set architecture - FileList['*.s', '*.elna'].map { |source| (architecture_tmp + source).to_path + '.o' } << 'kernel.ld' + arch_objects = FileList["arch/#{instruction_set}/*.s"] + .map { |source| Pathname.new(source).relative_path_from("arch/#{instruction_set}").sub_ext('.s.o') } + .map { |source| TMP + architecture + source } + .map(&:to_path) + + arch_objects + FileList['*.elna'].map { |source| (TMP + architecture + source).to_path + '.o' } << 'kernel.ld' } do |t| options = BuildTarget.new relative_from_tmp(t.name).first compiler = options.rootfs + "bin/#{options.target}-gcc" diff --git a/common.s b/arch/riscv/common.s similarity index 100% rename from common.s rename to arch/riscv/common.s diff --git a/kernel.s b/arch/riscv/kernel.s similarity index 100% rename from kernel.s rename to arch/riscv/kernel.s