2022-01-03 19:11:49 -05:00
|
|
|
#include <stdarg.h>
|
2022-07-31 21:32:11 -04:00
|
|
|
#include <stdint.h>
|
2022-01-03 19:11:49 -05:00
|
|
|
|
2022-07-31 23:01:57 -04:00
|
|
|
// #include <dtb/dtb.h>
|
2022-06-07 01:06:02 -04:00
|
|
|
|
2022-01-23 20:15:53 -05:00
|
|
|
#include <opensbi/opensbi.h>
|
|
|
|
#include <opensbi/extensions/legacy.h>
|
2022-06-07 01:04:21 -04:00
|
|
|
#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>
|
2022-01-05 02:47:30 -05:00
|
|
|
|
2022-01-03 19:11:49 -05:00
|
|
|
|
|
|
|
void fmt(const char *f, ...) {
|
2022-06-07 01:04:21 -04:00
|
|
|
namespace legacy = drivers::opensbi::legacy;
|
2022-01-23 20:15:53 -05:00
|
|
|
|
2022-01-05 02:50:14 -05:00
|
|
|
va_list va;
|
|
|
|
va_start(va, f);
|
|
|
|
while(*f) {
|
|
|
|
if(*f != '{') {
|
2022-06-07 01:04:21 -04:00
|
|
|
legacy::console_putchar(*(f++));
|
2022-01-05 02:50:14 -05:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
f++;
|
|
|
|
|
|
|
|
while(*f != '}') {
|
|
|
|
if(!(*f))
|
|
|
|
return;
|
|
|
|
f++;
|
|
|
|
}
|
|
|
|
f++;
|
|
|
|
|
|
|
|
unsigned long v = va_arg(va, unsigned long);
|
|
|
|
for(int i = 0; i < 16; ++i) {
|
|
|
|
const char *digits = "0123456789abcdef";
|
|
|
|
int d = (v >> (60 - i * 4)) & 0xF;
|
2022-06-07 01:04:21 -04:00
|
|
|
legacy::console_putchar(digits[d]);
|
2022-01-05 02:50:14 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
va_end(va);
|
2022-01-03 19:11:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" void kmain(unsigned long hart, void *dtb) {
|
2022-01-05 02:50:14 -05:00
|
|
|
(void)hart;
|
|
|
|
(void)dtb;
|
2022-06-07 01:06:02 -04:00
|
|
|
// D1 doesnt give me dtb ptr?
|
2022-07-31 23:01:57 -04:00
|
|
|
/*
|
|
|
|
dtb = (void *)0x5fb38580;
|
2022-06-07 01:06:02 -04:00
|
|
|
|
|
|
|
dtb::DeviceTree dt;
|
|
|
|
int res = dtb::validate_and_parse_header(dt, dtb);
|
|
|
|
if(!res) {
|
|
|
|
fmt("validate_and_parse_header: {}\n", res);
|
|
|
|
fmt("magic: {}\n", dt.meta.base);
|
|
|
|
dtb::print_reserved_regions(dt);
|
|
|
|
dtb::print_structure_block(dt);
|
|
|
|
}
|
2022-07-31 23:01:57 -04:00
|
|
|
*/
|
2022-01-03 19:11:49 -05:00
|
|
|
|
2022-06-07 01:04:21 -04:00
|
|
|
namespace base = drivers::opensbi::base;
|
2022-01-23 20:15:53 -05:00
|
|
|
|
2022-01-05 02:47:30 -05:00
|
|
|
fmt("test\n");
|
|
|
|
|
2022-06-07 01:04:21 -04:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-05 02:47:30 -05:00
|
|
|
fmt("uintmax: {} bits\n", sizeof(uintmax_t) * 8);
|
|
|
|
fmt("HART: {}, DTB: {}\n", hart, dtb);
|
2022-01-03 19:11:49 -05:00
|
|
|
|
2022-07-31 21:20:48 -04:00
|
|
|
fmt("HALT\n");
|
2022-06-07 01:04:21 -04:00
|
|
|
while(1);
|
2022-01-03 19:11:49 -05:00
|
|
|
|
2022-06-07 01:04:21 -04:00
|
|
|
namespace hsm = drivers::opensbi::hsm;
|
|
|
|
hsm::hart_stop();
|
2022-01-03 19:11:49 -05:00
|
|
|
|
2022-01-05 02:50:14 -05:00
|
|
|
while(1);
|
2022-01-03 19:11:49 -05:00
|
|
|
}
|