Skip to content

Commit

Permalink
Added syscall handler function implementations.
Browse files Browse the repository at this point in the history
  • Loading branch information
nthnn committed Feb 16, 2024
1 parent 2483453 commit bda09f3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
19 changes: 19 additions & 0 deletions src/rishka_syscalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,25 @@ char rishka_syscall_io_readch() {
return (char) Serial.read();
}

char* rishka_syscal_io_readline() {
return Serial.readLine().c_str();
}

void rishka_syscall_sys_delay(unsigned long ms) {
delay(ms);
}

unsigned long rishka_syscall_sys_micros() {
return micros();
}

unsigned long rishka_syscall_sys_millis() {
return millis();
}

void rishka_syscall_sys_delay(unsigned long ms);
unsigned long rishka_syscall_sys_micros();
unsigned long rishka_syscall_sys_millis();
void rishka_syscall_sys_exit(rishka_virtual_machine* vm, int code) {
vm->running = false;
vm->exitcode = code;
Expand Down
14 changes: 4 additions & 10 deletions src/rishka_vm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
#include <rishka_vm.h>
#include <rishka_vm_helper.h>

void rishka_vm_run(int argc, char** argv) {
rishka_virtual_machine* vm = &riscvm_machine;
void rishka_vm_run(rishka_virtual_machine* vm, int argc, char** argv) {
vm->running = true;
vm->argc = argc;
vm->argv = argv;
Expand All @@ -33,9 +32,7 @@ void rishka_vm_run(int argc, char** argv) {
rishka_vm_execute(rishka_vm_fetch(vm));
}

void rishka_vm_execute(uint32_t inst) {
rishka_virtual_machine* vm = &riscvm_machine;

void rishka_vm_execute(rishka_virtual_machine* vm, uint32_t inst) {
uint32_t opcode = ((inst >> 0) & 127);
uint32_t rd = ((inst >> 7) & 31),
rs1 = ((inst >> 15) & 31),
Expand Down Expand Up @@ -547,14 +544,13 @@ void rishka_vm_execute(uint32_t inst) {
vm->pc = (vm->pc + 4);
}

bool rishka_vm_loadfile(const char* file_name) {
bool rishka_vm_loadfile(rishka_virtual_machine* vm, const char* file_name) {
File file = SD.open(file_name);
if(!file) {
file.close();
return false;
}

rishka_virtual_machine* vm = &riscvm_machine;
file.read(&(((rishka_u8_arrptr*) & vm->memory)->a).v[4096], file.size());
file.close();

Expand Down Expand Up @@ -612,9 +608,7 @@ uint64_t rishka_vm_handle_syscall(rishka_virtual_machine* vm, uint64_t code) {
return 0;
}

void rishka_vm_reset() {
rishka_virtual_machine* vm = &riscvm_machine;

void rishka_vm_reset(rishka_virtual_machine* vm) {
vm->running = false;
vm->argv = NULL;
vm->argc = 0;
Expand Down

0 comments on commit bda09f3

Please sign in to comment.