summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'main.c')
-rw-r--r--main.c50
1 files changed, 49 insertions, 1 deletions
diff --git a/main.c b/main.c
index 2a38dde..a136a40 100644
--- a/main.c
+++ b/main.c
@@ -14,10 +14,58 @@
* Description: Entrypoint
*/
+#include <malloc.h>
+#include <stdint.h>
#include <stdio.h>
+#include <string.h>
+
+typedef uint8_t u8;
+typedef uint16_t u16;
+typedef uint32_t u32;
+typedef uint64_t u64;
+
+typedef int8_t i8;
+typedef int16_t i16;
+typedef int32_t i32;
+typedef int64_t i64;
+
+typedef struct
+{
+ u8 *buffer;
+ u64 size_memory, size_stack, size_registers;
+} vm_t;
+
+#define VM_DEFAULT_MEM_SIZE (1024)
+#define VM_DEFAULT_STACK_SIZE (128 * sizeof(u64))
+#define VM_DEFAULT_REGISTERS_SIZE (8 * sizeof(u64))
+
+#define VM_STACK(VM) ((VM)->buffer + (VM)->size_memory + (VM)->size_registers)
+#define VM_REGISTERS(VM) ((u64 *)((VM)->buffer + (VM)->size_memory))
+#define VM_IP(VM) (VM_REGISTERS(VM)[0])
+#define VM_SP(VM) (VM_REGISTERS(VM)[1])
+
+void vm_init_malloc(vm_t *vm)
+{
+ if (vm->size_stack == 0)
+ vm->size_stack = VM_DEFAULT_STACK_SIZE;
+ if (vm->size_registers == 0)
+ vm->size_registers = VM_DEFAULT_REGISTERS_SIZE;
+ if (vm->size_memory == 0)
+ vm->size_memory = VM_DEFAULT_MEM_SIZE;
+
+ vm->buffer = calloc(1, vm->size_memory + vm->size_stack + vm->size_registers);
+}
+
+void vm_stop(vm_t *vm)
+{
+ free(vm->buffer);
+ memset(vm, 0, sizeof(*vm));
+}
int main(void)
{
- puts("Hello, world!");
+ vm_t vm = {0};
+ vm_init_malloc(&vm);
+ vm_stop(&vm);
return 0;
}