From d77b7b8735406bf8888feb444da6f5e6222ed266 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Sun, 13 Jul 2025 17:26:36 +0200 Subject: [PATCH] Don't build the kernel image for cross compiler --- Rakefile | 4 +-- common.s | 81 +---------------------------------------------------- kernel.s | 9 ++++-- source.elna | 53 +++++++++++++++++++++++++++++------ 4 files changed, 54 insertions(+), 93 deletions(-) diff --git a/Rakefile b/Rakefile index e02aa4a..d54391a 100755 --- a/Rakefile +++ b/Rakefile @@ -228,7 +228,7 @@ namespace :cross do 'HOSTCFLAGS' => "-D_UUID_T -D__GETHOSTUUID_H -I#{TMP + 'tools/include'}" } sh env, 'make', 'rv32_defconfig', chdir: cwd.to_path - sh env, 'make', '-j', Etc.nprocessors.to_s, chdir: cwd.to_path + # sh env, 'make', '-j', Etc.nprocessors.to_s, chdir: cwd.to_path sh env, 'make', 'headers', chdir: cwd.to_path user_directory = options.sysroot + 'usr' @@ -298,7 +298,7 @@ namespace :cross do "--build=#{options.build}", "--host=#{options.build}" ] - flags = '-O2 -fPIC' + flags = '-O2 -fPIC -I/opt/homebrew/opt/flex/include' env = { 'CFLAGS' => flags, 'CXXFLAGS' => flags, diff --git a/common.s b/common.s index f91823f..4108d16 100644 --- a/common.s +++ b/common.s @@ -2,7 +2,7 @@ # v. 2.0. If a copy of the MPL was not distributed with this file, You can # obtain one at https://mozilla.org/MPL/2.0/. -.global write_s, write_c, write_i, _print_i +.global write_s, write_c .global memcmp, memchr, memmem, memcpy .section .text @@ -75,85 +75,6 @@ write_s: addi sp, sp, 32 ret -# Writes a number to a string buffer. -# -# t0 - Local buffer. -# t1 - Constant 10. -# t2 - Current character. -# t3 - Whether the number is negative. -# -# Parameters: -# a0 - Whole number. -# a1 - Buffer pointer. -# -# Sets a0 to the length of the written number. -.type _print_i, @function -_print_i: - addi sp, sp, -32 - sw ra, 28(sp) - sw s0, 24(sp) - addi s0, sp, 32 - - li t1, 10 - addi t0, s0, -9 - - li t3, 0 - bgez a0, .Lprint_i_digit10 - li t3, 1 - neg a0, a0 - -.Lprint_i_digit10: - rem t2, a0, t1 - addi t2, t2, '0' - sb t2, 0(t0) - div a0, a0, t1 - addi t0, t0, -1 - bne zero, a0, .Lprint_i_digit10 - - beq zero, t3, .Lprint_i_write_call - addi t2, zero, '-' - sb t2, 0(t0) - addi t0, t0, -1 - -.Lprint_i_write_call: - mv a0, a1 - addi a1, t0, 1 - sub a2, s0, t0 - addi a2, a2, -9 - sw a2, 0(sp) - - call memcpy - - lw a0, 0(sp) - - lw ra, 28(sp) - lw s0, 24(sp) - addi sp, sp, 32 - ret - -# Writes a number to the standard output. -# -# Parameters: -# a0 - Whole number. -.type write_i, @function -write_i: - addi sp, sp, -32 - sw ra, 28(sp) - sw s0, 24(sp) - addi s0, sp, 32 - - addi a1, sp, 0 - call _print_i - - mv a1, a0 - addi a0, sp, 0 - call write_s - - lw ra, 28(sp) - lw s0, 24(sp) - addi sp, sp, 32 - ret - # Prints a character from a0. # # Arguments: diff --git a/kernel.s b/kernel.s index 4d15247..f1805c5 100644 --- a/kernel.s +++ b/kernel.s @@ -170,19 +170,22 @@ handle_trap: call write_c csrr a0, scause - call write_i + la a1, write_c + call print_i call separator call write_c csrr a0, stval - call write_i + la a1, write_c + call print_i call separator call write_c csrr a0, sepc - call write_i + la a1, write_c + call print_i call panic diff --git a/source.elna b/source.elna index 876992d..2076b05 100644 --- a/source.elna +++ b/source.elna @@ -26,7 +26,6 @@ type var next_paddr*: Pointer; -proc write_i(value: Int); extern; proc write_c(value: Char); extern; proc write_s(value: String); extern; @@ -86,6 +85,44 @@ proc write_x*(value: Word, padding: Word) -> Word; return print_x(value, padding, write_c) end; +(* Writes a Word and puts it into the sink. *) +proc print_w*(value: Word, sink: proc(Char)) -> Word; +var + buffer: [10]Char; + i: Word; + result: Word; + character_code: Word; +begin + i := 0u; + + if value = 0u then + i := 1u; + buffer[i] := '0' + end; + while value <> 0u do + i := i + 1u; + character_code := value % 10u + cast('0': Word); + buffer[i] := cast(character_code: Char); + value := value / 10u + end; + result := i; + while i > 0u do + sink(buffer[i]); + i := i - 1u + end; + return result +end; + +(* Writes an Int and puts it into the sink. *) +proc print_i*(value: Int, sink: proc(Char)) -> Word; +begin + if value < 0 then + sink('-'); + value := -value + end; + return print_w(cast(value: Word), sink) +end; + (* Converts 4 bytes of the input in network byte order into an unsigned integer. *) @@ -113,7 +150,7 @@ begin write_c('\n'); write_s("Total size: "); - write_i(cast(header^.totalsize: Int)); + print_w(header^.totalsize, write_c); write_c('\n'); write_s("Struct offset: 0x"); @@ -129,23 +166,23 @@ begin write_c('\n'); write_s("Version: "); - write_i(cast(header^.version: Int)); + print_w(header^.version, write_c); write_c('\n'); write_s("Last compatible version: "); - write_i(cast(header^.last_comp_version: Int)); + print_w(header^.last_comp_version, write_c); write_c('\n'); write_s("CPU id: "); - write_i(cast(header^.boot_cpuid_phys: Int)); + print_w(header^.boot_cpuid_phys, write_c); write_c('\n'); write_s("Strings length: "); - write_i(cast(header^.size_dt_strings: Int)); + print_w(header^.size_dt_strings, write_c); write_c('\n'); write_s("Struct length: "); - write_i(cast(header^.size_dt_struct: Int)); + print_w(header^.size_dt_struct, write_c); write_c('\n') end; @@ -198,7 +235,7 @@ begin else write_c(' '); stream := stream + property.len; - write_i(cast(property.len: Int)) + print_w(property.len, write_c) end; write_c('\n');