Kernel: OpenSBI memes
Just making sure things work
This commit is contained in:
parent
4a9d3a24d5
commit
4367e38f39
1 changed files with 94 additions and 15 deletions
|
@ -3,6 +3,13 @@
|
||||||
|
|
||||||
#include <opensbi/opensbi.h>
|
#include <opensbi/opensbi.h>
|
||||||
#include <opensbi/extensions/legacy.h>
|
#include <opensbi/extensions/legacy.h>
|
||||||
|
#include <opensbi/extensions/base.h>
|
||||||
|
#include <opensbi/extensions/timer.h>
|
||||||
|
#include <opensbi/extensions/ipi.h>
|
||||||
|
#include <opensbi/extensions/rfence.h>
|
||||||
|
#include <opensbi/extensions/hsm.h>
|
||||||
|
#include <opensbi/extensions/srst.h>
|
||||||
|
#include <opensbi/extensions/pmu.h>
|
||||||
|
|
||||||
#define read_csr(csr) \
|
#define read_csr(csr) \
|
||||||
({ \
|
({ \
|
||||||
|
@ -32,13 +39,13 @@
|
||||||
typedef unsigned long sbi_word;
|
typedef unsigned long sbi_word;
|
||||||
|
|
||||||
void fmt(const char *f, ...) {
|
void fmt(const char *f, ...) {
|
||||||
using drivers::opensbi::legacy::console_putchar;
|
namespace legacy = drivers::opensbi::legacy;
|
||||||
|
|
||||||
va_list va;
|
va_list va;
|
||||||
va_start(va, f);
|
va_start(va, f);
|
||||||
while(*f) {
|
while(*f) {
|
||||||
if(*f != '{') {
|
if(*f != '{') {
|
||||||
console_putchar(*(f++));
|
legacy::console_putchar(*(f++));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
f++;
|
f++;
|
||||||
|
@ -54,7 +61,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;
|
||||||
console_putchar(digits[d]);
|
legacy::console_putchar(digits[d]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
va_end(va);
|
va_end(va);
|
||||||
|
@ -192,7 +199,8 @@ void switch_task(void *ctx, continuation_t c) {
|
||||||
extern "C" void isr();
|
extern "C" void isr();
|
||||||
|
|
||||||
extern "C" void handle_isr(isr_frame_t *frame) {
|
extern "C" void handle_isr(isr_frame_t *frame) {
|
||||||
using drivers::opensbi::legacy::console_putchar;
|
namespace legacy = drivers::opensbi::legacy;
|
||||||
|
namespace timer = drivers::opensbi::timer;
|
||||||
|
|
||||||
unsigned long cause = read_csr("scause");
|
unsigned long cause = read_csr("scause");
|
||||||
unsigned long code = cause & ~(1UL << 63);
|
unsigned long code = cause & ~(1UL << 63);
|
||||||
|
@ -203,20 +211,22 @@ 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::ecall(0x54494D45, 0, time + 100000);
|
//drivers::opensbi::ecall(0x54494D45, 0, time + 100000);
|
||||||
save_stack(switch_task, current_task);
|
timer::set_timer(time + 10000000);
|
||||||
|
//set_timer(time + 100000);
|
||||||
|
//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.
|
||||||
console_putchar(frame->a[0]);
|
legacy::console_putchar(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)
|
||||||
console_putchar(*(s++));
|
legacy::console_putchar(*(s++));
|
||||||
while(1)
|
while(1)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
@ -266,10 +276,56 @@ extern "C" void kmain(unsigned long hart, void *dtb) {
|
||||||
(void)hart;
|
(void)hart;
|
||||||
(void)dtb;
|
(void)dtb;
|
||||||
|
|
||||||
using drivers::opensbi::legacy::console_putchar;
|
namespace legacy = drivers::opensbi::legacy;
|
||||||
|
namespace base = drivers::opensbi::base;
|
||||||
|
namespace timer = drivers::opensbi::timer;
|
||||||
|
namespace ipi = drivers::opensbi::ipi;
|
||||||
|
|
||||||
fmt("test\n");
|
fmt("test\n");
|
||||||
|
|
||||||
|
auto ret = base::get_spec_version();
|
||||||
|
if(ret.error) {
|
||||||
|
fmt("get_spec_version failed\n");
|
||||||
|
} else {
|
||||||
|
fmt("spec version: {}\n", ret.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = base::get_impl_id();
|
||||||
|
if(ret.error) {
|
||||||
|
fmt("get_impl_id failed\n");
|
||||||
|
} else {
|
||||||
|
fmt("impl id: {}\n", ret.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = base::get_impl_version();
|
||||||
|
if(ret.error) {
|
||||||
|
fmt("get_impl_version failed\n");
|
||||||
|
} else {
|
||||||
|
fmt("impl version: {}\n", ret.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = base::get_mvendor_id();
|
||||||
|
if(ret.error) {
|
||||||
|
fmt("get_mvendor_id failed\n");
|
||||||
|
} else {
|
||||||
|
fmt("vendor id: {}\n", ret.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = base::get_march_id();
|
||||||
|
if(ret.error) {
|
||||||
|
fmt("get_march_id failed\n");
|
||||||
|
} else {
|
||||||
|
fmt("arch id: {}\n", ret.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = base::get_mimp_id();
|
||||||
|
if(ret.error) {
|
||||||
|
fmt("get_mimp_id failed\n");
|
||||||
|
} else {
|
||||||
|
fmt("imp id: {}\n", ret.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
fmt("uintmax: {} bits\n", sizeof(uintmax_t) * 8);
|
fmt("uintmax: {} bits\n", sizeof(uintmax_t) * 8);
|
||||||
fmt("HART: {}, DTB: {}\n", hart, dtb);
|
fmt("HART: {}, DTB: {}\n", hart, dtb);
|
||||||
|
|
||||||
|
@ -279,7 +335,7 @@ extern "C" void kmain(unsigned long hart, void *dtb) {
|
||||||
*cfg = 0x10;
|
*cfg = 0x10;
|
||||||
*dat = 0xFF;
|
*dat = 0xFF;
|
||||||
|
|
||||||
while(1);
|
//while(1);
|
||||||
|
|
||||||
cli();
|
cli();
|
||||||
|
|
||||||
|
@ -292,9 +348,28 @@ 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::ecall(0x735049, 0, 1 << hart, 0);
|
ipi::send_ipi({ 1UL << hart, 0 });
|
||||||
|
|
||||||
sti();
|
sti();
|
||||||
|
unsigned long timea = read_csr("time");
|
||||||
|
ret = timer::set_timer(timea + 100000);
|
||||||
|
|
||||||
|
drivers::opensbi::rfence::remote_fence_i({0, 0});
|
||||||
|
//ret = drivers::opensbi::hsm::hart_stop();
|
||||||
|
using drivers::opensbi::srst::ResetType;
|
||||||
|
using drivers::opensbi::srst::ResetReason;
|
||||||
|
// ret = drivers::opensbi::srst::system_reset(ResetType::WARM_REBOOT, ResetReason::SYSTEM_FAILURE);
|
||||||
|
|
||||||
|
namespace pmu = drivers::opensbi::pmu;
|
||||||
|
ret = pmu::num_counters();
|
||||||
|
|
||||||
|
fmt("Number of counters: {}\n", ret.value);
|
||||||
|
for(int i = 0; i < ret.value; i++) {
|
||||||
|
ret = pmu::counter_get_info(i);
|
||||||
|
fmt("{} err: {}\n", i, ret.error);
|
||||||
|
fmt("{} val: {}\n", i, ret.value);
|
||||||
|
}
|
||||||
|
while(1);
|
||||||
cli();
|
cli();
|
||||||
|
|
||||||
unsigned long time;
|
unsigned long time;
|
||||||
|
@ -325,17 +400,21 @@ 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)
|
||||||
console_putchar(*(s++));
|
legacy::console_putchar(*(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::ecall(0x54494D45, 0, time + 100000);
|
//set_timer(time + 100000);
|
||||||
|
//drivers::opensbi::ecall(0x54494D45, 0, time + 100000);
|
||||||
|
//timer::set_timer(time + 100000);
|
||||||
|
|
||||||
save_stack(switch_task, 0);
|
//save_stack(switch_task, 0);
|
||||||
|
|
||||||
drivers::opensbi::ecall(8, 0, 0);
|
namespace hsm = drivers::opensbi::hsm;
|
||||||
|
hsm::hart_stop();
|
||||||
|
// drivers::opensbi::ecall(8, 0, 0);
|
||||||
|
|
||||||
while(1);
|
while(1);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue