riscv64: initial risc-v port

This commit is contained in:
2026-09-28 00:09:01 +02:00
committed by rdmsr
parent d03251d3e0
commit 2c20f0b456
21 changed files with 839 additions and 9 deletions
+3 -1
View File
@@ -15,6 +15,7 @@ pub const Platform = struct {
const ArchEnum = enum {
amd64,
aarch64,
riscv64,
};
const BootloaderEnum = enum {
@@ -36,11 +37,12 @@ pub fn getPlatform(config: Config) !Platform {
.arch = switch (config.arch) {
.amd64 => .x86_64,
.aarch64 => .aarch64,
.riscv64 => .riscv64,
},
.os = .freestanding,
};
if (ret.os == .freestanding and (ret.arch == .x86_64 or ret.arch == .aarch64)) {
if (ret.os == .freestanding and (ret.arch == .x86_64 or ret.arch == .aarch64 or ret.arch == .riscv64)) {
ret.bootloader = switch (config.bootloader) {
.limine => .Limine,
};
+89
View File
@@ -0,0 +1,89 @@
OUTPUT_FORMAT(elf64-littleriscv)
ENTRY(kmain)
PHDRS
{
limine_requests PT_LOAD;
text PT_LOAD;
rodata PT_LOAD;
data PT_LOAD;
}
SECTIONS
{
. = 0xffffffff80000000;
.limine_requests : {
KEEP(*(.limine_requests_start))
KEEP(*(.limine_requests))
KEEP(*(.limine_requests_end))
} :limine_requests
. = ALIGN(CONSTANT(MAXPAGESIZE));
text_start_addr = .;
.text : {
*(.text .text.*)
} :text
. = ALIGN(CONSTANT(MAXPAGESIZE));
text_end_addr = .;
rodata_start_addr = .;
.rodata : {
*(.rodata .rodata.*)
} :rodata
.note.gnu.build-id : {
*(.note.gnu.build-id)
} :rodata
. = ALIGN(CONSTANT(MAXPAGESIZE));
rodata_end_addr = .;
data_start_addr = .;
.data.percpu : {
__percpu_start = .;
KEEP(*(.data.percpu .data.percpu.*))
__percpu_end = .;
} :data
.data.tunable : {
__tunables_start = .;
KEEP(*(.data.tunable .data.tunable.*))
__tunables_end = .;
} :data
.data : {
*(.data .data.*)
} :data
.bss : {
*(.bss .bss.*)
*(COMMON)
} :data
. = ALIGN(CONSTANT(MAXPAGESIZE));
data_end_addr = .;
/DISCARD/ : {
*(.eh_frame*)
*(.note .note.*)
}
}
+68
View File
@@ -0,0 +1,68 @@
OUTPUT_FORMAT(elf64-littleriscv)
ENTRY(loader_entry)
PHDRS
{
limine_requests PT_LOAD;
text PT_LOAD;
rodata PT_LOAD;
data PT_LOAD;
}
SECTIONS
{
. = 0xffffffffe0000000;
.limine_requests : {
KEEP(*(.limine_requests_start))
KEEP(*(.limine_requests))
KEEP(*(.limine_requests_end))
} :limine_requests
. = ALIGN(CONSTANT(MAXPAGESIZE));
text_start_addr = .;
.text : {
*(.text .text.*)
} :text
. = ALIGN(CONSTANT(MAXPAGESIZE));
text_end_addr = .;
rodata_start_addr = .;
.rodata : {
*(.rodata .rodata.*)
} :rodata
.note.gnu.build-id : {
*(.note.gnu.build-id)
} :rodata
. = ALIGN(CONSTANT(MAXPAGESIZE));
rodata_end_addr = .;
data_start_addr = .;
.data : {
*(.data .data.*)
} :data
.bss : {
*(.bss .bss.*)
*(COMMON)
} :data
. = ALIGN(CONSTANT(MAXPAGESIZE));
data_end_addr = .;
/DISCARD/ : {
*(.eh_frame*)
*(.note .note.*)
}
}
+2 -2
View File
@@ -62,8 +62,8 @@ pub fn addRun(b: *std.Build, kernel: *std.Build.Step.Compile, loader: *std.Build
if (!debug and builtin.target.os.tag == .linux and builtin.cpu.arch == .x86_64) qemu.addArgs(&.{ "-enable-kvm", "-cpu", "host,+invtsc" });
},
.aarch64 => qemu.addArgs(&.{ "-machine", "virt", "-cpu", "cortex-a57" }),
.riscv64 => qemu.addArgs(&.{ "-machine", "virt" }),
.aarch64 => qemu.addArgs(&.{ "-machine", "virt", "-cpu", "cortex-a57", "-device", "ramfb" }),
.riscv64 => qemu.addArgs(&.{ "-machine", "virt", "-m", "1G", "-device", "ramfb" }),
else => {},
}