More information for SuperVM and the Instruction header file.

This commit is contained in:
Felix Queißner 2016-05-19 12:42:39 +02:00
parent cfbe20ea70
commit 29bea1a335
4 changed files with 106 additions and 3 deletions

View file

@ -45,11 +45,11 @@ An SuperVM instruction is composed of multiple components:
| Component | Range | Size | Function | | Component | Range | Size | Function |
|-----------|-------------------|------|-------------------------------------------| |-----------|-------------------|------|-------------------------------------------|
| execution | See below. | 6 | When is the instruction executed. | | execution | See below. | 4 | When is the instruction executed. |
| input0 | Zero/Pop/Peek/Arg | 2 | Where does input0 come from? | | input0 | Zero/Pop/Peek/Arg | 2 | Where does input0 come from? |
| input1 | Zero/Pop | 1 | Where does input1 come from? | | input1 | Zero/Pop | 1 | Where does input1 come from? |
| command | [8bit] | 8 | Which command is executed? | | command | [6bit] | 6 | Which command is executed? |
| cmdinfo | [12bit] | 12 | Parameter value for the command. | | cmdinfo | [16bit] | 16 | Parameter value for the command. |
| flagmod | yes/no | 1 | Does this command modifies flags? | | flagmod | yes/no | 1 | Does this command modifies flags? |
| output | Discard/Push/Jump | 2 | What is done with the output? | | output | Discard/Push/Jump | 2 | What is done with the output? |
| argument | [32bit] | 32 | Some commands can take extra information | | argument | [32bit] | 32 | Some commands can take extra information |

12
prototypes/supervm/main.c Normal file
View file

@ -0,0 +1,12 @@
#include "vm.h"
#include <stdlib.h>
#include <stdio.h>
int main(int argc, const char **argv)
{
return 0;
}

1
prototypes/supervm/vm.c Normal file
View file

@ -0,0 +1 @@
#include "vm.h"

90
prototypes/supervm/vm.h Normal file
View file

@ -0,0 +1,90 @@
#pragma once
#include <stddef.h>
#include <inttypes.h>
#if defined(__cplusplus)
extern "C" {
#endif
#if !defined(VM_STACKSIZE)
#define VM_STACKSIZE 64
#endif
// Binary Encoding : (enabled, value)
#define VM_EXEC_X 0
#define VM_EXEC_0 2
#define VM_EXEC_1 3
#define VM_INPUT_ZERO 0
#define VM_INPUT_POP 1
#define VM_INPUT_PEEK 2
#define VM_INPUT_ARG 3
#define VM_CMD_COPY 0
#define VM_CMD_STORE 1
#define VM_CMD_LOAD 2
#define VM_CMD_GET 3
#define VM_CMD_SET 4
#define VM_CMD_BPGET 5
#define VM_CMD_BPSET 6
#define VM_CMD_RSTSTACK 7
#define VM_CMD_MATH 8
#define VM_CMD_SPGET 9
#define VM_CMD_SPSET 10
#define VM_MATH_ADD 0
#define VM_MATH_SUB 1
#define VM_MATH_MUL 2
#define VM_MATH_DIV 3
#define VM_MATH_MOD 4
#define VM_MATH_AND 5
#define VM_MATH_OR 6
#define VM_MATH_XOR 7
#define VM_MATH_NOT 8
#define VM_MATH_ROL 9
#define VM_MATH_ROR 10
#define VM_MATH_ASL 11
#define VM_MATH_ASR 12
#define VM_MATH_SHL 13
#define VM_MATH_SHR 14
#define VM_FLAG_NO 0
#define VM_FLAG_YES 0
#define VM_OUTPUT_DISCARD 0
#define VM_OUTPUT_PUSH 1
#define VM_OUTPUT_JUMP 2
typedef struct
{
unsigned int execZ : 2;
unsigned int execN : 2;
unsigned int input0 : 2;
unsigned int input1 : 1;
unsigned int command : 6;
unsigned int cmdinfo : 16;
unsigned int flags : 1;
unsigned int output : 2;
uint32_t argument;
} __attribute__ ((packed)) Instruction;
_Static_assert(sizeof(Instruction) == 8, "Instruction must be 8 bytes large.");
_Static_assert(offsetof(Instruction, argument) == 4, "Argument must be must be 8 bytes large.");
typedef struct
{
uint32_t codePointer;
uint32_t stackPointer;
uint32_t basePointer;
uint32_t flags;
uint32_t stack[VM_STACKSIZE];
} Process;
#if defined(__cplusplus)
}
#endif