Adds syscall and hwio instructions and mnemonics.
This commit is contained in:
parent
f7bc2624a0
commit
88d44b4ca1
4 changed files with 94 additions and 46 deletions
|
@ -35,6 +35,24 @@ void vm_assert(int assertion, const char *msg)
|
|||
exit(1);
|
||||
}
|
||||
|
||||
void vm_syscall(Process *p, CommandInfo *info)
|
||||
{
|
||||
printf("Some syscall: (%d, %d, %d, %d)\n",
|
||||
info->input0,
|
||||
info->input1,
|
||||
info->argument,
|
||||
info->additional);
|
||||
}
|
||||
|
||||
void vm_hwio(Process *p, CommandInfo *info)
|
||||
{
|
||||
printf("Some hardware IO: (%d, %d, %d, %d)\n",
|
||||
info->input0,
|
||||
info->input1,
|
||||
info->argument,
|
||||
info->additional);
|
||||
}
|
||||
|
||||
int main(int argc, const char **argv)
|
||||
{
|
||||
if(argc < 2) {
|
||||
|
|
|
@ -84,8 +84,8 @@ An instruction is only executed when all conditions are met.
|
|||
| 8 | MATH | output = input0 OP[info] input1 |
|
||||
| 9 | SPGET | output = SP + input0 |
|
||||
| 10 | SPSET | output = SP + input0 = input1 |
|
||||
| 11 | | |
|
||||
| 12 | | |
|
||||
| 11 | SYSCALL | output = SysCall(input0, input1) |
|
||||
| 12 | HWIO | output = HardwareIO(input0, input1) |
|
||||
| 13 | | |
|
||||
| 14 | | |
|
||||
| 15 | | |
|
||||
|
@ -115,37 +115,40 @@ by the `cmdinfo`.
|
|||
|
||||
## Assembler Mnemonics
|
||||
|
||||
| Mnemonic | Arg? | i0 | i1 | Cmd | CmdInfo | Output |
|
||||
|----------|------|------|------|-------|----------|---------|
|
||||
| nop | no | zero | zero | copy | 0 | discard |
|
||||
| push | yes | arg | zero | copy | 0 | push |
|
||||
| drop | no | pop | zero | copy | 0 | discard |
|
||||
| dup | no | peek | zero | copy | 0 | push |
|
||||
| jmp | yes | arg | zero | copy | 0 | jump |
|
||||
| jmpi | no | pop | zero | copy | 0 | jump |
|
||||
| ret | no | pop | zero | copy | 0 | jump |
|
||||
| load | yes | arg | zero | load | 0 | push |
|
||||
| loadi | no | pop | zero | load | 0 | push |
|
||||
| store | yes | arg | pop | store | 0 | discard |
|
||||
| storei | no | pop | pop | store | 0 | discard |
|
||||
| get | yes | arg | zero | get | 0 | push |
|
||||
| geti | no | pop | zero | get | 0 | push |
|
||||
| set | yes | arg | pop | set | 0 | discard |
|
||||
| seti | no | pop | pop | set | 0 | discard |
|
||||
| bpget | no | zero | zero | bpget | 0 | push |
|
||||
| bpset | no | pop | zero | bpset | 0 | discard |
|
||||
| add | no | pop | pop | math | 0 | push |
|
||||
| sub | no | pop | pop | math | 1 | push |
|
||||
| mul | no | pop | pop | math | 2 | push |
|
||||
| div | no | pop | pop | math | 3 | push |
|
||||
| mod | no | pop | pop | math | 4 | push |
|
||||
| and | no | pop | pop | math | 5 | push |
|
||||
| or | no | pop | pop | math | 6 | push |
|
||||
| xor | no | pop | pop | math | 7 | push |
|
||||
| not | no | pop | zero | math | 8 | push |
|
||||
| rol | no | pop | pop | math | 9 | push |
|
||||
| ror | no | pop | pop | math | 10 | push |
|
||||
| asl | no | pop | pop | math | 11 | push |
|
||||
| asr | no | pop | pop | math | 12 | push |
|
||||
| shl | no | pop | pop | math | 13 | push |
|
||||
| shr | no | pop | pop | math | 14 | push |
|
||||
| Mnemonic | Arg? | i0 | i1 | Cmd | CmdInfo | Output | Flags? |
|
||||
|----------|------|------|------|---------|----------|---------|--------|
|
||||
| nop | no | zero | zero | copy | 0 | discard | no |
|
||||
| push | yes | arg | zero | copy | 0 | push | no |
|
||||
| drop | no | pop | zero | copy | 0 | discard | no |
|
||||
| dup | no | peek | zero | copy | 0 | push | no |
|
||||
| jmp | yes | arg | zero | copy | 0 | jump | no |
|
||||
| jmpi | no | pop | zero | copy | 0 | jump | no |
|
||||
| ret | no | pop | zero | copy | 0 | jump | no |
|
||||
| load | yes | arg | zero | load | 0 | push | no |
|
||||
| loadi | no | pop | zero | load | 0 | push | no |
|
||||
| store | yes | arg | pop | store | 0 | discard | no |
|
||||
| storei | no | pop | pop | store | 0 | discard | no |
|
||||
| get | yes | arg | zero | get | 0 | push | no |
|
||||
| geti | no | pop | zero | get | 0 | push | no |
|
||||
| set | yes | arg | pop | set | 0 | discard | no |
|
||||
| seti | no | pop | pop | set | 0 | discard | no |
|
||||
| bpget | no | zero | zero | bpget | 0 | push | no |
|
||||
| bpset | no | pop | zero | bpset | 0 | discard | no |
|
||||
| add | no | pop | pop | math | 0 | push | no |
|
||||
| sub | no | pop | pop | math | 1 | push | no |
|
||||
| cmp | no | pop | pop | math | 1 | discard | yes |
|
||||
| mul | no | pop | pop | math | 2 | push | no |
|
||||
| div | no | pop | pop | math | 3 | push | no |
|
||||
| mod | no | pop | pop | math | 4 | push | no |
|
||||
| and | no | pop | pop | math | 5 | push | no |
|
||||
| or | no | pop | pop | math | 6 | push | no |
|
||||
| xor | no | pop | pop | math | 7 | push | no |
|
||||
| not | no | pop | zero | math | 8 | push | no |
|
||||
| rol | no | pop | pop | math | 9 | push | no |
|
||||
| ror | no | pop | pop | math | 10 | push | no |
|
||||
| asl | no | pop | pop | math | 11 | push | no |
|
||||
| asr | no | pop | pop | math | 12 | push | no |
|
||||
| shl | no | pop | pop | math | 13 | push | no |
|
||||
| shr | no | pop | pop | math | 14 | push | no |
|
||||
| syscall | yes | zero | zero | syscall | 0 | discard | no |
|
||||
| hwio | yes | zero | zero | hwio | 0 | discard | no |
|
|
@ -2,16 +2,6 @@
|
|||
|
||||
#include <stdio.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t input0;
|
||||
uint32_t input1;
|
||||
uint32_t argument;
|
||||
uint32_t additional;
|
||||
|
||||
uint32_t output;
|
||||
} CommandInfo;
|
||||
|
||||
static void cmd_copy(CommandInfo *info)
|
||||
{
|
||||
info->output = info->input0;
|
||||
|
@ -108,6 +98,8 @@ int vm_step_process(Process *process)
|
|||
{
|
||||
case VM_CMD_COPY: cmd_copy(&info); break;
|
||||
case VM_CMD_MATH: cmd_math(&info); break;
|
||||
case VM_CMD_SYSCALL: vm_syscall(process, &info); break;
|
||||
case VM_CMD_HWIO: vm_hwio(process, &info); break;
|
||||
default: vm_assert(0, "Invalid instruction: command undefined.");
|
||||
}
|
||||
|
||||
|
|
|
@ -32,6 +32,8 @@ extern "C" {
|
|||
#define VM_CMD_MATH 8
|
||||
#define VM_CMD_SPGET 9
|
||||
#define VM_CMD_SPSET 10
|
||||
#define VM_CMD_SYSCALL 11
|
||||
#define VM_CMD_HWIO 12
|
||||
|
||||
#define VM_MATH_ADD 0
|
||||
#define VM_MATH_SUB 1
|
||||
|
@ -84,6 +86,7 @@ typedef struct
|
|||
typedef struct
|
||||
{
|
||||
Module *module;
|
||||
void *tag;
|
||||
|
||||
uint32_t codePointer;
|
||||
uint32_t stackPointer;
|
||||
|
@ -93,6 +96,16 @@ typedef struct
|
|||
uint32_t stack[VM_STACKSIZE];
|
||||
} Process;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t input0;
|
||||
uint32_t input1;
|
||||
uint32_t argument;
|
||||
uint32_t additional;
|
||||
|
||||
uint32_t output;
|
||||
} CommandInfo;
|
||||
|
||||
/**
|
||||
* @brief Steps a given process.
|
||||
*
|
||||
|
@ -118,8 +131,30 @@ uint32_t vm_pop(Process *process);
|
|||
*/
|
||||
uint32_t vm_peek(Process *process);
|
||||
|
||||
|
||||
// The following functions need to be host-implemented.
|
||||
|
||||
/**
|
||||
* An assertion the VM does.
|
||||
* @param assertion If zero, the assertion failed.
|
||||
* @param msg The message that should be shown when the assertion fails.
|
||||
*/
|
||||
void vm_assert(int assertion, const char *msg);
|
||||
|
||||
/**
|
||||
* The hosts syscall implementation.
|
||||
* @param process The process that calls the syscall.
|
||||
* @param info Additional information for the syscall. Contains arguments and results.
|
||||
*/
|
||||
void vm_syscall(Process *process, CommandInfo *info);
|
||||
|
||||
/**
|
||||
* The hosts hardware IO implementation.
|
||||
* @param process The process that wants to do IO.
|
||||
* @param info Additional information for the HWIO. Contains arguments and results.
|
||||
*/
|
||||
void vm_hwio(Process *process, CommandInfo *info);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
Loading…
Reference in a new issue