Compare commits

..

No commits in common. "94fbea02ca96a60c6aec1cd4c2466a7067b457e3" and "7336f9e6d614afade623f877f0938f23e45c085c" have entirely different histories.

6 changed files with 201 additions and 367 deletions

View file

@ -8,7 +8,6 @@ arch_sources += [
elf = executable( elf = executable(
'kernel.elf', 'kernel.elf',
arch_sources, arch_sources,
include_directories: includes,
link_args: [ link_args: [
'-Wl,-T,' + meson.current_source_dir() + '/platform.ld', '-Wl,-T,' + meson.current_source_dir() + '/platform.ld',
'-static' '-static'

View file

@ -1,62 +0,0 @@
#pragma once
typedef unsigned long uintmax_t;
namespace drivers {
namespace opensbi {
// We use uintmax_t to make sure this works on 32 and 64 bit
// At least thats how I hope this works..
// TODO: Add assert() to make sure this is the case
struct sbiret_t {
uintmax_t error;
uintmax_t value;
};
sbiret_t call(
uintmax_t extension,
uintmax_t function,
uintmax_t a0,
uintmax_t a1,
uintmax_t a2,
uintmax_t a3,
uintmax_t a4,
uintmax_t a5);
sbiret_t call(
uintmax_t extension,
uintmax_t function,
uintmax_t a0,
uintmax_t a1,
uintmax_t a2,
uintmax_t a3,
uintmax_t a4);
sbiret_t call(
uintmax_t extension,
uintmax_t function,
uintmax_t a0,
uintmax_t a1,
uintmax_t a2,
uintmax_t a3);
sbiret_t call(
uintmax_t extension,
uintmax_t function,
uintmax_t a0,
uintmax_t a1,
uintmax_t a2);
sbiret_t call(
uintmax_t extension,
uintmax_t function,
uintmax_t a0,
uintmax_t a1);
sbiret_t call(
uintmax_t extension,
uintmax_t function,
uintmax_t a0);
} // End namespace opensbi
} // End namespace drivers

View file

@ -1,9 +0,0 @@
kernel_sources += [
files(
'opensbi.cpp'
),
]
kernel_includes += include_directories(
'include'
)

View file

@ -1,78 +0,0 @@
#include <cstdint>
#include <opensbi.h>
namespace drivers {
namespace opensbi {
sbiret_t call(
uintmax_t extension,
uintmax_t function,
uintmax_t a0,
uintmax_t a1,
uintmax_t a2,
uintmax_t a3,
uintmax_t a4,
uintmax_t a5) {
register uintmax_t r_a7 asm("a7") = extension;
register uintmax_t r_a6 asm("a6") = function;
register uintmax_t r_a0 asm("a0") = a0;
register uintmax_t r_a1 asm("a1") = a1;
register uintmax_t r_a2 asm("a2") = a2;
register uintmax_t r_a3 asm("a3") = a3;
register uintmax_t r_a4 asm("a4") = a4;
register uintmax_t r_a5 asm("a5") = a5;
asm volatile("ecall" : // Instruction
"=r"(r_a0), "=r"(r_a1) : // Inputs
"r"(r_a7), "r"(r_a6), // Outputs
"r"(r_a0), "r"(r_a1), "r"(r_a2),
"r"(r_a3), "r"(r_a4), "r"(r_a5));
return {.error = a0, .value = a1};
}
sbiret_t call(
uintmax_t extension,
uintmax_t function,
uintmax_t a0,
uintmax_t a1,
uintmax_t a2,
uintmax_t a3,
uintmax_t a4) {
return call(extension, function, a0, a1, a2, a3, a4, 0);
}
sbiret_t call(
uintmax_t extension,
uintmax_t function,
uintmax_t a0,
uintmax_t a1,
uintmax_t a2,
uintmax_t a3) {
return call(extension, function, a0, a1, a2, a3, 0, 0);
}
sbiret_t call(
uintmax_t extension,
uintmax_t function,
uintmax_t a0,
uintmax_t a1,
uintmax_t a2) {
return call(extension, function, a0, a1, a2, 0, 0, 0);
}
sbiret_t call(
uintmax_t extension,
uintmax_t function,
uintmax_t a0,
uintmax_t a1) {
return call(extension, function, a0, a1, 0, 0, 0, 0);
}
sbiret_t call(
uintmax_t extension,
uintmax_t function,
uintmax_t a0) {
return call(extension, function, a0, 0, 0, 0, 0, 0);
}
} // End namespace opensbi
} // End namespace drivers

View file

@ -1,8 +1,6 @@
#include <stdarg.h> #include <stdarg.h>
#include <inttypes.h> #include <inttypes.h>
#include <opensbi.h>
#define read_csr(csr) \ #define read_csr(csr) \
({ \ ({ \
unsigned long __v; \ unsigned long __v; \
@ -30,7 +28,6 @@
typedef unsigned long sbi_word; typedef unsigned long sbi_word;
/*
void sbi_call1(int ext, int func, sbi_word arg0) { void sbi_call1(int ext, int func, sbi_word arg0) {
register sbi_word rExt asm("a7") = ext; register sbi_word rExt asm("a7") = ext;
register sbi_word rFunc asm("a6") = func; register sbi_word rFunc asm("a6") = func;
@ -50,14 +47,13 @@ void sbi_call2(int ext, int func, sbi_word arg0, sbi_word arg1) {
if(rArg0) if(rArg0)
__builtin_trap(); __builtin_trap();
} }
*/
void fmt(const char *f, ...) { void fmt(const char *f, ...) {
va_list va; va_list va;
va_start(va, f); va_start(va, f);
while(*f) { while(*f) {
if(*f != '{') { if(*f != '{') {
drivers::opensbi::call(1, 0, *(f++)); sbi_call1(1, 0, *(f++));
continue; continue;
} }
f++; f++;
@ -73,7 +69,7 @@ void fmt(const char *f, ...) {
for(int i = 0; i < 16; ++i) { for(int i = 0; i < 16; ++i) {
const char *digits = "0123456789abcdef"; const char *digits = "0123456789abcdef";
int d = (v >> (60 - i * 4)) & 0xF; int d = (v >> (60 - i * 4)) & 0xF;
drivers::opensbi::call(1, 0, digits[d]); sbi_call1(1, 0, digits[d]);
} }
} }
va_end(va); va_end(va);
@ -220,20 +216,20 @@ extern "C" void handle_isr(isr_frame_t *frame) {
}else if(code == 5) { // Timer interrupt. }else if(code == 5) { // Timer interrupt.
//clear_csr_bits("sie", sie_s_timer); //clear_csr_bits("sie", sie_s_timer);
unsigned long time = read_csr("time"); unsigned long time = read_csr("time");
drivers::opensbi::call(0x54494D45, 0, time + 100000); sbi_call1(0x54494D45, 0, time + 100000);
save_stack(switch_task, current_task); save_stack(switch_task, current_task);
}else{ }else{
fmt("it's an unhandled interrupt, code: {}\n", code); fmt("it's an unhandled interrupt, code: {}\n", code);
} }
}else{ }else{
if(code == 8) { // Syscall. if(code == 8) { // Syscall.
drivers::opensbi::call(1, 0, frame->a[0]); sbi_call1(1, 0, frame->a[0]);
}else{ }else{
unsigned long sepc = read_csr("sepc"); unsigned long sepc = read_csr("sepc");
fmt("it's an exception at {}\n", sepc); fmt("it's an exception at {}\n", sepc);
const char *s = exception_strings[cause]; const char *s = exception_strings[cause];
while(*s) while(*s)
drivers::opensbi::call(1, 0, *(s++)); sbi_call1(1, 0, *(s++));
while(1) while(1)
; ;
} }
@ -283,18 +279,17 @@ extern "C" void kmain(unsigned long hart, void *dtb) {
(void)hart; (void)hart;
(void)dtb; (void)dtb;
fmt("test\n"); //fmt("test\n");
fmt("uintmax: {} bits\n", sizeof(uintmax_t) * 8);
fmt("HART: {}, DTB: {}\n", hart, dtb);
/*
volatile uint32_t *cfg = (uint32_t *)0x2000060; volatile uint32_t *cfg = (uint32_t *)0x2000060;
volatile uint32_t *dat = (uint32_t *)0x2000070; volatile uint32_t *dat = (uint32_t *)0x2000070;
*cfg = 0x10; *cfg = 0x10;
*dat = 0xFF; *dat = 0xFF;
*/
while(1); fmt("y");
cli(); cli();
@ -307,7 +302,7 @@ extern "C" void kmain(unsigned long hart, void *dtb) {
set_csr_bits("sie", sie_s_software | sie_s_timer); set_csr_bits("sie", sie_s_software | sie_s_timer);
// Self-IPI. // Self-IPI.
drivers::opensbi::call(0x735049, 0, 1 << hart, 0); sbi_call2(0x735049, 0, 1 << hart, 0);
sti(); sti();
cli(); cli();
@ -340,17 +335,17 @@ extern "C" void kmain(unsigned long hart, void *dtb) {
s = "paging works!\n"; s = "paging works!\n";
s += 512UL * 1024 * 1024 * 1024; s += 512UL * 1024 * 1024 * 1024;
while(*s) while(*s)
drivers::opensbi::call(1, 0, *(s++)); sbi_call1(1, 0, *(s++));
create_task(&task1, task1_main); create_task(&task1, task1_main);
create_task(&task2, task2_main); create_task(&task2, task2_main);
time = read_csr("time"); time = read_csr("time");
drivers::opensbi::call(0x54494D45, 0, time + 100000); sbi_call1(0x54494D45, 0, time + 100000);
save_stack(switch_task, 0); save_stack(switch_task, 0);
drivers::opensbi::call(8, 0, 0); sbi_call1(8, 0, 0);
while(1); while(1);
} }

View file

@ -4,16 +4,5 @@ kernel_sources = [
) )
] ]
kernel_includes = [
include_directories('include')
]
subdir('drivers/opensbi')
includes = [
# arch_includes,
kernel_includes
]
subdir('arch/' + arch) subdir('arch/' + arch)