Add more notes, some other TODOs, STATUS register

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2020-01-26 11:15:09 -05:00
parent 6c96adddff
commit c8690e79bc

41
vm.md
View File

@@ -23,7 +23,8 @@ CPU registers are addressed by a value between 0-63 (6 bits). All registers are
* SP - Stack pointer * SP - Stack pointer
* FP - Frame pointer * FP - Frame pointer
* FLAGS - CPU flags * FLAGS - CPU flags
* (10 unused registers) * (9 unused registers)
* STATUS - Generic status code
* R0-R49 * R0-R49
## CPU Flags ## CPU Flags
@@ -82,10 +83,12 @@ wrapping around to 0.
* Shr * Shr
* **Params**: REG1, REG2 * **Params**: REG1, REG2
* `REG1 = REG1 >> REG2` * `REG1 = REG1 >> REG2`
* Does not sign extend
### TODO ### TODO
* Add signed instructions (iadd, imul, etc) * Add signed instructions (iadd, imul, etc)
* Sign-extending SHR
* Overflow flag? * Overflow flag?
## Control flow ## Control flow
@@ -99,6 +102,7 @@ wrapping around to 0.
FLAGS[1] = 0; FLAGS[1] = 0;
} }
``` ```
* Sets the COMPARE flag to 1 if REG1 == REG2
* CmpLt * CmpLt
* **Params**: REG1, REG2 * **Params**: REG1, REG2
* ``` * ```
@@ -108,20 +112,27 @@ wrapping around to 0.
FLAGS[1] = 0; FLAGS[1] = 0;
} }
``` ```
* Sets the COMPARE flag to 1 if REG1 < REG2
* Jz * Jz
* **Params**: REG1 * **Params**: REG1
* ``` * ```
if FLAGS[0] == 0 { if FLAGS[1] == 0 {
IP = REG1; IP = REG1;
} }
``` ```
* Jumps to the address in REG1 if COMPARE flag is 0.
* Jnz * Jnz
* **Params**: REG1 * **Params**: REG1
* ``` * ```
if FLAGS[0] != 0 { if FLAGS[1] != 0 {
IP = REG1; IP = REG1;
} }
``` ```
* Jumps to the address in REG1 if COMPARE flag is 1.
* Halt
* **Params**: (none)
* `FLAGS[0] = 1`
* Halts the machine
## Data movement ## Data movement
@@ -130,17 +141,41 @@ wrapping around to 0.
* ``` * ```
REG1 = MEM[REG2]; REG1 = MEM[REG2];
``` ```
* Sets REG1 to the value at the memory address in REG2.
* Store * Store
* **Params**: REG1, REG2 * **Params**: REG1, REG2
* ``` * ```
MEM[REG2] = REG1; MEM[REG2] = REG1;
``` ```
* Sets the value at the memory address in REG2 to the value in REG1.
* StoreImm32 * StoreImm32
* **Params**: REG1, IMM_32 * **Params**: REG1, IMM_32
* `REG1 = IMM_32` * `REG1 = IMM_32`
* Sets REG1 to the specified 32-bit number.
* MemCopy * MemCopy
* **Params**: REG1, REG2 * **Params**: REG1, REG2
* `MEM[REG1] = MEM[REG2]` * `MEM[REG1] = MEM[REG2]`
* Copies the value at the memory address in REG2 to the memory address in REG1.
* RegCopy * RegCopy
* **Params**: REG1, REG2 * **Params**: REG1, REG2
* `REG1 = REG2` * `REG1 = REG2`
* Copies the value in REG2 into REG1.
## Other instructions TODO
* Call
* Takes address and number of bytes on the stack that are for args(?)
* Updates SP, FP, IP, storing previous values starting at the new FP
* Ret
* Uses FP to determine previous SP, FP, and IP and restores them
* Push
* Pop
* More immediate stores?
# General TODO
* Interrupts
* MMIO regions
* Execution pipeline
* Helps to define when certain side effects happen (e.g. when the IP increments)
* Paging?