💾 Archived View for 0x80.org › gemlog › 2014-07-05-risc.gmi captured on 2022-04-28 at 17:41:16. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2021-12-03)
-=-=-=-=-=-=-
I have been working on a RISC-like vm emulator and compiler/assembler for sometime for fun and to waste time which currently is capable of emulating a set of the usual opcodes (mov., add., sub., xor., push., pop., ..etc). The machine is a 32-bit machine, have a stack, supports external linux syscalls it's meant to run under linux.
The machine doesn't currently support conditions, flags, but I'll implement those as soon as I'm done with the initial assembler design.
Note this is just a side project the code isn't anything but a joke and a waste of time :P, but who cares right? It's always fun to play with things!.
Code can be forked/found here[1].
1: https://github.com/q6r/risc
The machine has 8 general registers r1-r8, a program counter rpc, a stack pointer rps. They are all 32bit.
It has a stack where you can push bytes, words, dwords, or registers using pushib,pushiw,pushid to push immediate values, and pushb,pushw,pushd to push registers. the {b,w,d,ib,iw,id} is used for most of the opcodes.
movib r1, SYS_write; movib r2, STDOUT; pushid "lleh"; pushid "rowo"; pushid "\x00\ndl"; gstk r3; movib r4, 0x0b; syscall;
r1 will have SYS_write, r2 is first parameter, r3 is second, r4 is third, and return value of r1 syscall will be in r1. This translate to something like r1 = r1(r2,r3,r4); gstk is used to get pointers from stack like pstk is used to derference a stack pointer to the stack (if that makes sense?).
movib r1, SYS_open; pushid FILE...... .... gstk r2; movib r3, O_RDONLY; syscall // r1 = open(FILE, O_RDONY); // read 64 bytes from it mov r2, r1; movib r1, SYS_read; movib r4, 0x40; gstk r3; subid r3, r4; // allocate memory in stack syscall; // r1 = read(fd, buf:0x40, 0x40);
The machine contains a small list of supported system calls the list will be increased to support all linux system calls soon. They will be used as follow. r1 will hold the syscall number, return value always in r1 after the syscall. first parameter to last parameter are r2-r8.