aboutsummaryrefslogtreecommitdiff
path: root/src
AgeCommit message (Collapse)Author
2023-10-22Coupled some routines together, implemented OP_PLUS_*, -vm_peekAryadev Chavali
Routines that use the stack for their operands i.e. aren't supplied operands directly all have the same signature. We may as well stick them all together in one array and one conditional, just reduces the number of branches. Also looks nicer. Implemented OP_PLUS_*. Pretty simple to implement. Deleted vm_peek as it was only necessary to update the `ret` register.
2023-10-22Added OP_PLUS_*Aryadev Chavali
Takes two operands from the stack then pushes their sum.
2023-10-22Fix bug where negative opcodes lead to invalid bytecode parsingAryadev Chavali
2023-10-22Added runtime errors to virtual machineAryadev Chavali
Every vm routine now returns an err_t, which is an enumeration of possible error states. ERR_OK represents the good state and is 0 so error checking seems very natural in terms of language `if (err) ...`. Errors bubble up the runtime, with any callers forced to check if an error occurred. This does mean that routines that call other routines cannot provide an accurate trace of the subcaller (based on the fact that an error is generated for the current instruction), but this should be a non issue as no instruction should be complex enough to need proper traces.
2023-10-22Added and implemented OP_JUMP_(STACK|REGISTER)Aryadev Chavali
Uses the stack and register, respectively, to jump to an absolute address. The stack based jump pops a word off the stack to perform a jump, while the register based one uses the operand to figure out which register to use.
2023-10-22Removed `ret` registerAryadev Chavali
Wasn't useful or necessary.
2023-10-22Added and implemented OP_JUMP_ABSAryadev Chavali
Jumps to the operand given, interpreted as a word, an absolute address.
2023-10-22Fixed bug in vm_execute_all, if no OP_HALT then program kept goingAryadev Chavali
This adds a bound on vm_execute_all to stop program->ptr from going past program->max.
2023-10-22Implemented vm_* routines for OP_DUP and vm_execute codeAryadev Chavali
2023-10-22Use conversion functions for (h)word to and from bytes instead of bit shiftingAryadev Chavali
Wasn't very secure for endianness, and using these helpers abstracts the details away a bit in case I want to enforce a certain system.
2023-10-22Added NUMBER_OF_OPCODES which aids in compilation errorsAryadev Chavali
If I add a new operand I want the build system to be more helpful in finding the places I need to change to make it work.
2023-10-22Added opcode OP_DUP_*Aryadev Chavali
Duplicates the nth datum off the stack, pushing it to the top. Useful for operations such as MOV which eat the stack.
2023-10-22Cleaned up inst.cAryadev Chavali
Use (H)WORD_SIZE more, added some notes, etc
2023-10-22Functions which convert (h)words to and from bytesAryadev Chavali
Uses memcpy internally, so we don't need to care about endianness.
2023-10-22Simple program which assembles instructions then executes themAryadev Chavali
2023-10-22Fix bug where accessing byte/hword registers > 8 wouldn't workAryadev Chavali
This is because we were checking them as if they were word registers.
2023-10-22When VEROBSE flag is set greater than 0, print traces in vm_execute_allAryadev Chavali
For each cycle, print the cycle and any changes. We track changes on the stack by remembering the previous stack pointer. For registers, I remember the previous array of registers and do a byte level compare of the current registers and the remembered ones. Produces pretty log messages and an easy way to track execution.
2023-10-22Changed formats for vm_print_(stack|program)Aryadev Chavali
Easier to read now
2023-10-22Fix bug where FILE is closed when passing to darr_(write|read)Aryadev Chavali
2023-10-22Added flag in base.h, VERBOSEAryadev Chavali
Will be used to provide traces during program execution or assembly.
2023-10-22Added macros for NOOP and HALTAryadev Chavali
2023-10-22Changed format of inst_printAryadev Chavali
Prints the opcode then any operands in the following brackets
2023-10-22Store the result of OP_POP in the last register as a wordAryadev Chavali
Instead of making routines to handle data in the `ret` register, just store the result of POP into the last word register. This means we are no longer using vm_pop_* or POP_ROUTINES for the vm_execute script on OP_POP: instead we'll just use vm_mov_* which automatically pops the datum for us, while moving the datum to the last register.
2023-10-21Implemented vm routines for OP_EQ_*Aryadev Chavali
2023-10-21Implemented vm routines for OP_XOR_*Aryadev Chavali
2023-10-21Implemented vm routines for OP_AND_*Aryadev Chavali
2023-10-21Implemented vm routines for OP_OR_*Aryadev Chavali
2023-10-21Implemented vm routines for OP_NOT_*Aryadev Chavali
2023-10-21Implemented opcode_as_cstr for NOT,OR,AND,XOR,EQAryadev Chavali
2023-10-21Introduced opcodes for NOT, OR, AND, XOR and EQAryadev Chavali
Does a bit level version of each of these.
2023-10-21Cleaned up and used macro magic to shorten the INST_* macrosAryadev Chavali
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-21Added vm_execute_all which executes an entire programAryadev Chavali
Handles OP_HALT
2023-10-21Wrote generalised procedures for interpret and assemblyAryadev Chavali
2023-10-21Helper functions for read/write instructions from darr or FILE*Aryadev Chavali
2023-10-21Helper darr functions to read/write bytes from FILE *Aryadev Chavali
2023-10-21Switched from floats to halfwordAryadev Chavali
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-16Implemented vm_print_* routinesAryadev Chavali
Prints each aspect of the vm, and vm_print_all does it all.
2023-10-16Added opcode_as_cstr, opcode_type_as_cstr and inst_printAryadev Chavali
Pretty self explanatory, helps with logging.
2023-10-16Added helper functions to read and write bytes from filesAryadev Chavali
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-16Made a sample program, loaded into VM and executedAryadev Chavali
Seems pretty nice to use, and it works according to GDB.
2023-10-16Fixed bug with get_opcode_data_typeAryadev Chavali
Pushed the bits one step too far.
2023-10-16Set opcode after reading parameters in inst_read_byteAryadev Chavali
2023-10-16Fixed error with OP_PUSH where bits weren't in the pattern of data_type_tAryadev Chavali
2023-10-16MOV and PUSH_*_REGISTER should only need bytes for their operandAryadev Chavali
We won't have more than 255 registers, so a byte is all that's necessary.
2023-10-16Added functionality to read and write instruction bytecodeAryadev Chavali
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-16Made OP_HALT the only instruction to have the top byte filledAryadev Chavali
2023-10-16MOV now uses the stack, removed register member in inst_tAryadev Chavali
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-15Better checking of opcode typesAryadev Chavali
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-15Remove parameter for INST_*POPAryadev Chavali
POP instructions do not require an operand: they're a unary operator.
2023-10-15Set register parameter for inst_t to be a byteAryadev Chavali
We at most have 255 registers, so no need to have a word for it.