From 76b4979067c670301e70d92a1d1ef103fa19676f Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Sun, 20 Jul 2025 23:17:40 +0200 Subject: [PATCH] Fix linker RWX warning --- Rakefile | 9 +++++---- kernel.ld => arch/riscv/kernel.ld | 27 ++++++++++++++------------ arch/riscv/kernel.s | 4 ++-- source.elna => source/device_tree.elna | 2 +- 4 files changed, 23 insertions(+), 19 deletions(-) rename kernel.ld => arch/riscv/kernel.ld (56%) rename source.elna => source/device_tree.elna (99%) diff --git a/Rakefile b/Rakefile index adde9c3..a8ffeca 100755 --- a/Rakefile +++ b/Rakefile @@ -350,7 +350,7 @@ rule '.elna.o' => ->(match) { architecture, *path_components = relative_from_tmp(match).to_a path_components[-1] = path_components.last.ext('') - [File.join(path_components), TMP + architecture] + [File.join('source', path_components), TMP + architecture] } do |t| options = BuildTarget.new relative_from_tmp(t.name).first compiler = options.rootfs + "bin/#{options.target}-gcc" @@ -366,10 +366,11 @@ rule 'kernel.elf' => ->(match) { 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) + source_objects = FileList['source/*.elna'] + .map { |source| Pathname.new(source).relative_path_from('source').sub_ext('.elna.o') } + objects = (arch_objects + source_objects).map { |source| (TMP + architecture + source).to_s } - arch_objects + FileList['*.elna'].map { |source| (TMP + architecture + source).to_path + '.o' } << 'kernel.ld' + objects << "arch/#{instruction_set}/kernel.ld" } do |t| options = BuildTarget.new relative_from_tmp(t.name).first compiler = options.rootfs + "bin/#{options.target}-gcc" diff --git a/kernel.ld b/arch/riscv/kernel.ld similarity index 56% rename from kernel.ld rename to arch/riscv/kernel.ld index 7f65958..502dd14 100644 --- a/kernel.ld +++ b/arch/riscv/kernel.ld @@ -1,25 +1,28 @@ -OUTPUT_ARCH( "riscv" ) +OUTPUT_ARCH("riscv") OUTPUT_FORMAT("elf32-littleriscv") -ENTRY(boot) +ENTRY(_entry) + +PHDRS { + text PT_LOAD FLAGS(5); + data PT_LOAD FLAGS(6); +} SECTIONS { - . = 0x80200000; - __kernel_base = .; - - .text :{ + .text 0x80200000 : { + __kernel_base = .; KEEP(*(.text.boot)); *(.text .text.*); - } + } :text - .rodata : ALIGN(4) { + .rodata : ALIGN(16) { *(.rodata .rodata.*); } - .data : ALIGN(4) { + .data : ALIGN(16) { *(.data .data.*); - } + } :data - .bss : ALIGN(4) { + .bss : ALIGN(16) { __bss = .; *(.bss .bss.* .sbss .sbss.*); __bss_end = .; @@ -29,6 +32,6 @@ SECTIONS { . += 128 * 1024; /* 128KB */ __stack_top = .; - . = ALIGN(4096); + . = ALIGN(CONSTANT(MAXPAGESIZE)); __free_ram = .; } diff --git a/arch/riscv/kernel.s b/arch/riscv/kernel.s index f1805c5..08fc6ef 100644 --- a/arch/riscv/kernel.s +++ b/arch/riscv/kernel.s @@ -1,4 +1,4 @@ -.global kernel_main, __bss, __bss_end, __stack_top +.global _entry, __bss, __bss_end, __stack_top .section .rodata @@ -215,7 +215,7 @@ panic: ret .section .text.boot -boot: +_entry: la t0, __stack_top mv sp, t0 # Set the stack pointer diff --git a/source.elna b/source/device_tree.elna similarity index 99% rename from source.elna rename to source/device_tree.elna index 2076b05..c11b729 100644 --- a/source.elna +++ b/source/device_tree.elna @@ -118,7 +118,7 @@ proc print_i*(value: Int, sink: proc(Char)) -> Word; begin if value < 0 then sink('-'); - value := -value + value := -value end; return print_w(cast(value: Word), sink) end;