Aryadev Chavali
696589b7b6
Introduced opcodes for NOT, OR, AND, XOR and EQ
...
Does a bit level version of each of these.
2023-10-21 23:42:07 +01:00
Aryadev Chavali
f9b2c8ed77
Cleaned up and used macro magic to shorten the INST_* macros
...
Instead of having 3 differing macros for each typed version of each
opcode, just supply the type as a symbol to the macro, which will
concatenated the type to all the places necessary.
Relies on D(BYTE|HWORD|WORD) and OP_*_(BYTE|HWORD|WORD) being a
consistent naming style.
2023-10-21 23:40:03 +01:00
Aryadev Chavali
d2cdb211b2
Added vm_execute_all which executes an entire program
...
Handles OP_HALT
2023-10-21 23:31:48 +01:00
Aryadev Chavali
1c2de9a926
Wrote a quick tutorial on targeting the virtual machine
2023-10-21 23:27:33 +01:00
Aryadev Chavali
f3a5981fa2
Wrote generalised procedures for interpret and assembly
2023-10-21 23:24:41 +01:00
Aryadev Chavali
44a9a3ca46
Helper functions for read/write instructions from darr or FILE*
2023-10-21 23:23:37 +01:00
Aryadev Chavali
903ae3ab04
Helper darr functions to read/write bytes from FILE *
2023-10-21 23:23:13 +01:00
Aryadev Chavali
dcedb70a5c
Switched from floats to halfword
...
Registers are now just words, with pushing from and moving to
registers with specified subtypes just pushing those types into the
word registers. That means there are 8 word registers which can act
as 16 half word registers, which themselves can act as 64 byte
registers.
2023-10-21 22:57:43 +01:00
Aryadev Chavali
266b4e4572
Implemented vm_print_* routines
...
Prints each aspect of the vm, and vm_print_all does it all.
2023-10-16 12:55:19 +01:00
Aryadev Chavali
44f8c81efe
Added opcode_as_cstr, opcode_type_as_cstr and inst_print
...
Pretty self explanatory, helps with logging.
2023-10-16 12:55:15 +01:00
Aryadev Chavali
d01b39d1bb
Added helper functions to read and write bytes from files
...
Given a filepath, helper function to write a buffer of bytes to a file
and to read a file completely as a buffer.
2023-10-16 12:03:42 +01:00
Aryadev Chavali
e7616cdeb6
Made a sample program, loaded into VM and executed
...
Seems pretty nice to use, and it works according to GDB.
2023-10-16 11:32:20 +01:00
Aryadev Chavali
7380dd375a
Fixed bug with get_opcode_data_type
...
Pushed the bits one step too far.
2023-10-16 11:25:52 +01:00
Aryadev Chavali
845d864bc0
Set opcode after reading parameters in inst_read_byte
2023-10-16 11:04:43 +01:00
Aryadev Chavali
4d9b8a04f2
Fixed error with OP_PUSH where bits weren't in the pattern of data_type_t
2023-10-16 01:20:11 +01:00
Aryadev Chavali
a4c9b85c79
MOV and PUSH_*_REGISTER should only need bytes for their operand
...
We won't have more than 255 registers, so a byte is all that's
necessary.
2023-10-16 01:20:06 +01:00
Aryadev Chavali
6038363d2f
Added functionality to read and write instruction bytecode
...
Uses some bit hacks to quickly check what data type an opcode may have
by shifting down to units then casting it to a data_type_t.
Not very well tested yet, we'll need to see now.
2023-10-16 01:18:05 +01:00
Aryadev Chavali
a24a096e2a
Made OP_HALT the only instruction to have the top byte filled
2023-10-16 01:06:02 +01:00
Aryadev Chavali
0f37a59940
MOV now uses the stack, removed register member in inst_t
...
Instead of taking an operand and a register, mov just uses the stack
for the operand. Therefore, there's no need for a register member in
inst_t.
As a result, PUSH_*_REGISTER now uses the operand for the register.
2023-10-16 01:05:42 +01:00
Aryadev Chavali
cd19f1e1d3
Better checking of opcode types
...
Introduced an enum (opcode_type_t) for the masks and values of each
opcode, which allows defining a single enum which checks an opcode by
a opcode_type_t.
2023-10-15 22:16:31 +01:00
Aryadev Chavali
1cb54dc994
Remove parameter for INST_*POP
...
POP instructions do not require an operand: they're a unary operator.
2023-10-15 22:06:30 +01:00
Aryadev Chavali
15ce778771
Set register parameter for inst_t to be a byte
...
We at most have 255 registers, so no need to have a word for it.
2023-10-15 22:05:59 +01:00
Aryadev Chavali
c24c1d1607
Implemented a dynamically sized byte array
...
Pretty simple, want to ensure amortised constant big O so I use a
REALLOC_MULT, which can be redefined if wished.
2023-10-15 21:50:31 +01:00
Aryadev Chavali
98760ee63b
Added macros for getting the maximum and minimum of two numbers
2023-10-15 21:49:13 +01:00
Aryadev Chavali
639808a092
Moved vm_* code to its own file (runtime.(h|c))
2023-10-15 21:41:16 +01:00
Aryadev Chavali
14e9192996
Implemented OP_PUSH_*_REGISTER in vm_execute
2023-10-15 21:29:26 +01:00
Aryadev Chavali
f73604ba6e
Make error TODOs specific to routine (for vm_mov_*)
2023-10-15 21:27:45 +01:00
Aryadev Chavali
f513e90f00
Implemented vm_push_*_register routines
2023-10-15 21:27:26 +01:00
Aryadev Chavali
744cc7acf7
Renamed opcodes PUSH_*REG to PUSH_*_REGISTER
...
More precise in naming
2023-10-15 21:27:00 +01:00
Aryadev Chavali
4ae762294d
Rearranged opcodes (switched mov with push_reg)
...
This is so push opcodes are closer together
2023-10-15 21:22:42 +01:00
Aryadev Chavali
54760d446c
Added instructions to push register values onto the stack
2023-10-15 21:19:49 +01:00
Aryadev Chavali
f0e48a186d
Added a register ret, a word, which holds the result of any instruction
...
Allows inspection at runtime of any routines result.
2023-10-15 21:14:56 +01:00
Aryadev Chavali
2490966554
Implemented vm_execute for pop routines
2023-10-15 21:13:15 +01:00
Aryadev Chavali
6927557d3f
Made vm_pop_* routines more uniform by returning a data_t
2023-10-15 21:12:53 +01:00
Aryadev Chavali
00517fddd6
Added instructions for popping differing types
...
Bit mask is 100.
2023-10-15 21:09:00 +01:00
Aryadev Chavali
2bc20f07d3
Added vm_execute support for mov routines
...
Similar to push routines support. Easy to extend by adding items to
the MOV_ROUTINES array.
2023-10-15 21:05:56 +01:00
Aryadev Chavali
3f8544485a
Move push routines outside of vm_execute
2023-10-15 21:05:09 +01:00
Aryadev Chavali
56c545e7c9
Added opcodes for MOV and ability for instructions to hold registers
...
Pretty simple implementation
2023-10-15 21:03:27 +01:00
Aryadev Chavali
33aa62634a
Added registers to virtual machine
...
Registers for bytes, words and floats with routines to set them.
2023-10-15 21:01:03 +01:00
Aryadev Chavali
7a820290f9
Make push opcodes a specific bit set and add a NOOP opcode
...
By default, a zero initialised set of instructions are NOOPs, which is
great.
Last two bits of a push opcode is always 01. Rest of the bits are
used to distinguish between differing types of push. This makes it
easier to inspect on the byte level what type of opcode we have.
2023-10-15 20:59:26 +01:00
Aryadev Chavali
40dfa5c255
Split off instruction structure to its own file
2023-10-15 17:38:35 +01:00
Aryadev Chavali
ea14b3beb6
Added an instruction setup
...
op_t provides opcodes, inst_t provides a wrapper with operands. vm_t
carries around a pointer to a set of instructions, and vm_execute
attempts to execute that one. I do some weird stuff here, and it's
definitely not complete.
2023-10-15 05:52:58 +01:00
Aryadev Chavali
3786b7d785
stack.size -> stack.max
2023-10-15 05:44:06 +01:00
Aryadev Chavali
4ddc3cce71
Main now loads a stack allocated byte array for VM stack
2023-10-15 05:41:20 +01:00
Aryadev Chavali
bee6d445bb
Added a routine to load a pointer as stack memory
2023-10-15 05:40:53 +01:00
Aryadev Chavali
2de37b20e2
Changed stack data to be a pointer
...
I wouldn't really want this to be malloc'd per se, you could make a
byte array on the stack then pass it into the VM?
2023-10-15 05:39:19 +01:00
Aryadev Chavali
a8747faa08
Split off general types and structures into separate header
2023-10-15 05:36:01 +01:00
Aryadev Chavali
da1c4aad35
Changed stack.pointer->stack.ptr
2023-10-15 05:33:42 +01:00
Aryadev Chavali
268fdf0ca0
Added floats (64 bit floating point) push and pop routines
...
Not machine independent, uses the underlying memcpy routine.
2023-10-15 05:23:38 +01:00
Aryadev Chavali
724f5e0258
Force big endian when pushing words
...
This ensures that if one wanted to pop a word byte by byte, they'd go
from least to most significance. Machine independent so that's nice.
2023-10-15 05:18:43 +01:00