Change instruction encodings to avoid null instructions
Lots of null bytes in a row are a common thing, so the instructions available can't start with a null pair of bytes anymore. Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
@@ -21,7 +21,7 @@
|
|||||||
jnz end
|
jnz end
|
||||||
mov %status, $1
|
mov %status, $1
|
||||||
end:
|
end:
|
||||||
div %r0, $0
|
int $0, $0
|
||||||
halt
|
halt
|
||||||
.export main
|
.export main
|
||||||
|
|
||||||
|
|||||||
@@ -23,32 +23,32 @@ macro_rules! instructions {
|
|||||||
pub type InstOp = u16;
|
pub type InstOp = u16;
|
||||||
|
|
||||||
instructions! {
|
instructions! {
|
||||||
ADD = 0x0000,
|
ADD = 0x1000,
|
||||||
SUB = 0x0001,
|
SUB = 0x1001,
|
||||||
MUL = 0x0002,
|
MUL = 0x1002,
|
||||||
DIV = 0x0003,
|
DIV = 0x1003,
|
||||||
IDIV = 0x0004,
|
IDIV = 0x1004,
|
||||||
MOD = 0x0005,
|
MOD = 0x1005,
|
||||||
AND = 0x0006,
|
AND = 0x1006,
|
||||||
OR = 0x0007,
|
OR = 0x1007,
|
||||||
XOR = 0x0008,
|
XOR = 0x1008,
|
||||||
SHL = 0x0009,
|
SHL = 0x1009,
|
||||||
SHR = 0x000a,
|
SHR = 0x100a,
|
||||||
INEG = 0x000b,
|
INEG = 0x100b,
|
||||||
INV = 0x000c,
|
INV = 0x100c,
|
||||||
NOT = 0x000d,
|
NOT = 0x100d,
|
||||||
CMPEQ = 0x1000,
|
CMPEQ = 0x2000,
|
||||||
CMPLT = 0x1001,
|
CMPLT = 0x2001,
|
||||||
JMP = 0x1002,
|
JMP = 0x2002,
|
||||||
JZ = 0x1003,
|
JZ = 0x2003,
|
||||||
JNZ = 0x1004,
|
JNZ = 0x2004,
|
||||||
CALL = 0x2000,
|
CALL = 0x3000,
|
||||||
RET = 0x2001,
|
RET = 0x3001,
|
||||||
PUSH = 0x2002,
|
PUSH = 0x3002,
|
||||||
POP = 0x2003,
|
POP = 0x3003,
|
||||||
INT = 0x2004,
|
INT = 0x3004,
|
||||||
IRET = 0x2005,
|
IRET = 0x3005,
|
||||||
MOV = 0x3000,
|
MOV = 0x4000,
|
||||||
HALT = 0xF000,
|
HALT = 0xF000,
|
||||||
NOP = 0xF001,
|
NOP = 0xF001,
|
||||||
DUMP = 0xF002,
|
DUMP = 0xF002,
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
addr::Addr,
|
|
||||||
obj::{
|
obj::{
|
||||||
assemble::{
|
assemble::{
|
||||||
Asm,
|
Asm,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use crate::{mem::MemCursor, obj::obj::*, inst::Inst};
|
use crate::{mem::MemCursor, obj::obj::*};
|
||||||
use prettytable::{Table, row, cell};
|
use prettytable::{Table, row, cell};
|
||||||
use std::io::{self, Write as Write};
|
use std::io::{self, Write as Write};
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ extern crate libvm as vm;
|
|||||||
|
|
||||||
use structopt::StructOpt;
|
use structopt::StructOpt;
|
||||||
use snafu::Snafu;
|
use snafu::Snafu;
|
||||||
use std::{fs, io::{stdin, stdout, Write, Read}, path::{Path, PathBuf}, process};
|
use std::{fs, io::{stdout, Write}, path::{Path, PathBuf}, process};
|
||||||
|
|
||||||
const DEFAULT_MAX_MEM: usize = 64 * 1024 * 1024;
|
const DEFAULT_MAX_MEM: usize = 64 * 1024 * 1024;
|
||||||
|
|
||||||
|
|||||||
51
vm.md
51
vm.md
@@ -128,43 +128,43 @@ Arithmetic instructions store their result in the first register specified. Over
|
|||||||
wrapping around to 0.
|
wrapping around to 0.
|
||||||
|
|
||||||
* Add
|
* Add
|
||||||
* Opcode: 0x0000
|
* Opcode: 0x1000
|
||||||
* Params: Destination, source
|
* Params: Destination, source
|
||||||
* Sub
|
* Sub
|
||||||
* Opcode: 0x0001
|
* Opcode: 0x1001
|
||||||
* Params: Destination, source
|
* Params: Destination, source
|
||||||
* Mul
|
* Mul
|
||||||
* Opcode: 0x0002
|
* Opcode: 0x1002
|
||||||
* Params: Destination, source
|
* Params: Destination, source
|
||||||
* Div
|
* Div
|
||||||
* Opcode: 0x0003
|
* Opcode: 0x1003
|
||||||
* Params: Destination, source
|
* Params: Destination, source
|
||||||
* Mod
|
* Mod
|
||||||
* Opcode: 0x0004
|
* Opcode: 0x1004
|
||||||
* Params: Destination, source
|
* Params: Destination, source
|
||||||
* And
|
* And
|
||||||
* Opcode: 0x0005
|
* Opcode: 0x1005
|
||||||
* Params: Destination, source
|
* Params: Destination, source
|
||||||
* Or
|
* Or
|
||||||
* Opcode: 0x0006
|
* Opcode: 0x1006
|
||||||
* Params: Destination, source
|
* Params: Destination, source
|
||||||
* Xor
|
* Xor
|
||||||
* Opcode: 0x0007
|
* Opcode: 0x1007
|
||||||
* Params: Destination, source
|
* Params: Destination, source
|
||||||
* Shl
|
* Shl
|
||||||
* Opcode: 0x0008
|
* Opcode: 0x1008
|
||||||
* Params: Destination, source
|
* Params: Destination, source
|
||||||
* Shr
|
* Shr
|
||||||
* Opcode: 0x0009
|
* Opcode: 0x1009
|
||||||
* Params: Destination, source
|
* Params: Destination, source
|
||||||
* INeg
|
* INeg
|
||||||
* Opcode: 0x000a
|
* Opcode: 0x100a
|
||||||
* Params: Destination, source
|
* Params: Destination, source
|
||||||
* Inv
|
* Inv
|
||||||
* Opcode: 0x000b
|
* Opcode: 0x100b
|
||||||
* Params: Destination, source
|
* Params: Destination, source
|
||||||
* Not
|
* Not
|
||||||
* Opcode: 0x000c
|
* Opcode: 0x100c
|
||||||
* Params: Destination, source
|
* Params: Destination, source
|
||||||
|
|
||||||
### TODO
|
### TODO
|
||||||
@@ -176,25 +176,25 @@ wrapping around to 0.
|
|||||||
## Control flow
|
## Control flow
|
||||||
|
|
||||||
* CmpEq
|
* CmpEq
|
||||||
* Opcode: 0x1000
|
* Opcode: 0x2000
|
||||||
* Params: Source, source
|
* Params: Source, source
|
||||||
* CmpLt
|
* CmpLt
|
||||||
* Opcode: 0x1001
|
* Opcode: 0x2001
|
||||||
* Params: Source, source
|
* Params: Source, source
|
||||||
* Jmp
|
* Jmp
|
||||||
* Opcode: 0x1002
|
* Opcode: 0x2002
|
||||||
* Params: Source
|
* Params: Source
|
||||||
* Jz
|
* Jz
|
||||||
* Opcode: 0x1003
|
* Opcode: 0x2003
|
||||||
* Params: Source
|
* Params: Source
|
||||||
* Jnz
|
* Jnz
|
||||||
* Opcode: 0x1004
|
* Opcode: 0x2004
|
||||||
* Params: Source
|
* Params: Source
|
||||||
|
|
||||||
## Functions
|
## Functions
|
||||||
|
|
||||||
* Call
|
* Call
|
||||||
* Opcode: 0x2000
|
* Opcode: 0x3000
|
||||||
* Params: Source
|
* Params: Source
|
||||||
* When this instruction is executed, these actions occur:
|
* When this instruction is executed, these actions occur:
|
||||||
* Push the current stack frame pointer
|
* Push the current stack frame pointer
|
||||||
@@ -202,26 +202,26 @@ wrapping around to 0.
|
|||||||
* Update the IP (i.e., jump) to the value at the given source.
|
* Update the IP (i.e., jump) to the value at the given source.
|
||||||
* Update the frame pointer to the current stack pointer - 16
|
* Update the frame pointer to the current stack pointer - 16
|
||||||
* Ret
|
* Ret
|
||||||
* Opcode: 0x2001
|
* Opcode: 0x3001
|
||||||
* When this instruction is executed, these actions occur:
|
* When this instruction is executed, these actions occur:
|
||||||
* Update the stack pointer to the current frame pointer + 16.
|
* Update the stack pointer to the current frame pointer + 16.
|
||||||
* Pop the IP of the next instruction.
|
* Pop the IP of the next instruction.
|
||||||
* Pop the old stack frame.
|
* Pop the old stack frame.
|
||||||
* Restore the last three values in an undefined order
|
* Restore the last three values in an undefined order
|
||||||
* Push
|
* Push
|
||||||
* Opcode: 0x2002
|
* Opcode: 0x3002
|
||||||
* Params: Source
|
* Params: Source
|
||||||
* When this instruction is executed, these actions occur:
|
* When this instruction is executed, these actions occur:
|
||||||
* Set the value in memory at the current stack pointer to the source value.
|
* Set the value in memory at the current stack pointer to the source value.
|
||||||
* Increment the stack pointer by the size of value at the source.
|
* Increment the stack pointer by the size of value at the source.
|
||||||
* Pop
|
* Pop
|
||||||
* Opcode: 0x2003
|
* Opcode: 0x3003
|
||||||
* Params: Dest
|
* Params: Dest
|
||||||
* When this instruction is executed, these actions occur:
|
* When this instruction is executed, these actions occur:
|
||||||
* Decrement the stack pointer by the size of value at the destination.
|
* Decrement the stack pointer by the size of value at the destination.
|
||||||
* Copy the value at the stack pointer into the destination.
|
* Copy the value at the stack pointer into the destination.
|
||||||
* Int
|
* Int
|
||||||
* Opcode: 0x2004
|
* Opcode: 0x3004
|
||||||
* Params: Source, Source
|
* Params: Source, Source
|
||||||
* When this instruction is executed, these actions occur:
|
* When this instruction is executed, these actions occur:
|
||||||
* Push the current stack frame pointer
|
* Push the current stack frame pointer
|
||||||
@@ -235,7 +235,7 @@ wrapping around to 0.
|
|||||||
* Update the R1 register to the value in the second parameter
|
* Update the R1 register to the value in the second parameter
|
||||||
* Update the frame pointer to the current stack pointer - 48
|
* Update the frame pointer to the current stack pointer - 48
|
||||||
* IRet
|
* IRet
|
||||||
* Opcode: 0x2005
|
* Opcode: 0x3005
|
||||||
* When this instruction is executed, these actions occur:
|
* When this instruction is executed, these actions occur:
|
||||||
* Update the stack pointer to the current frame pointer + 48
|
* Update the stack pointer to the current frame pointer + 48
|
||||||
* Pop the old R1 value
|
* Pop the old R1 value
|
||||||
@@ -249,7 +249,7 @@ wrapping around to 0.
|
|||||||
## Data movement
|
## Data movement
|
||||||
|
|
||||||
* Mov
|
* Mov
|
||||||
* Opcode: 0x3000
|
* Opcode: 0x4000
|
||||||
* Params: Source, Dest
|
* Params: Source, Dest
|
||||||
|
|
||||||
## Miscellaneous
|
## Miscellaneous
|
||||||
@@ -410,7 +410,6 @@ A VM must provide support for the following meta-values:
|
|||||||
|
|
||||||
# General TODO
|
# General TODO
|
||||||
|
|
||||||
* Interrupts
|
|
||||||
* MMIO regions
|
* MMIO regions
|
||||||
* Paging?
|
* Paging?
|
||||||
* Determine how address sizes are determined
|
* Determine how address sizes are determined
|
||||||
|
|||||||
Reference in New Issue
Block a user