Commit Graph

73 Commits

Author SHA1 Message Date
2b8663037f First part of libvm transition
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-03-03 19:05:50 -05:00
74139b7c65 Remove defunct TODO from spec
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-03-03 18:34:56 -05:00
ef03ea9137 Update assembler infrastructure to be more modular
Assembler has more discrete passes now, but things are kind of bare on
the error message front. But, everything is working as it did
previously, so we can move on to more interesting things.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-03-03 18:10:08 -05:00
ad7c22c168 Remove include_paths() methods from AsmSession
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-02-28 15:08:17 -05:00
782a2ea4e9 Remove examples/constants.asm, update deadbeef.asm to not use it
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-02-27 17:33:44 -05:00
4b96902831 Scrap preprocessor, add .include directive instead
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-02-27 15:52:17 -05:00
0eb394ddf5 Update build.rs
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-02-26 14:27:30 -05:00
381a59f5fe Clean up main.rs some, add preprocessor
* Preprocessor uses an LRPAR generated lexer and a custom parser to
  filter comments and set defines. Includes and conditional compilation
  will come next.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-02-26 14:24:30 -05:00
79d37a4e7b Add documentation to the Source and Dest value_len() and len() functions
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-02-26 10:26:18 -05:00
44dc34e52d Update spec for push and pop operations
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-02-26 10:25:46 -05:00
cd95011e7b Add function call test
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-02-26 10:19:26 -05:00
a4e1d43a74 Add factorial asm example
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-02-26 10:16:38 -05:00
7a6c2d80ab Add call/ret/push/pop instructions
* Call/ret/push/pop are implemented and appear to be working
* Call/ret/push/pop is specified in the 0x2000 block, replacing the
  mov instruction
* Mov instruction is now specified in the 0x3000 block

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-02-26 10:14:48 -05:00
bd34cdad63 Add compile and compile_out options, and extended input/output options
* compile flag and compile_out argument to the driver allow the program
  to be compiled only
* if '-' is supplied to compile_out, it will output to STDOUT instead
* if '-' is supplied to input, it will read from STDIN instead

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-02-25 18:12:28 -05:00
d11dbbcdf5 Add meta section len() and to_bytes()
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-02-25 17:56:16 -05:00
86d46b2a50 Add data section names and conversion to object file format
* Data section names are encoded in the object file format
* Objects can be converted into their file format layouts
* Add writing/reading test to make sure that an object converted to
  bytes and then back from bytes is equal to hopefully catch major
  object translations

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-02-25 16:39:32 -05:00
700ea6c54f Add section name to data section spec
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-02-25 16:38:43 -05:00
461cf59bb0 Update intermediate object representation
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-02-25 15:08:49 -05:00
ef83cf7ef3 Add max_mem and size parsing for arg parsing
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-02-25 14:55:14 -05:00
b4637e2070 Comments in main.rs
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-02-25 14:21:39 -05:00
07abfc96b5 Add structopt for arg parsing
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-02-25 14:19:12 -05:00
bc4f59ecad Add bitwise tests, squash all arithmetic tests into test_arithmetic
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-02-25 14:10:21 -05:00
362590292a Add some integration tests and runner
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-02-25 13:48:03 -05:00
145739aee2 Add brackets to lexer in preparation for arrays
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-02-25 13:47:28 -05:00
0ff189bc1b Minor code cleanup and surpress warnings for unused inst and register constants
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-02-25 13:46:38 -05:00
b8a769c80f Add sized int value defs
Integer value definitions now respect their sizes (.u8, .u16, etc)

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-02-25 13:45:41 -05:00
1c05b3bb44 Update main to return the given status instead of printing the status out when halted
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-02-25 13:45:04 -05:00
aff2da591b Add rerun_except crate to prevent building when .asm files are changed
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-02-25 13:44:15 -05:00
795a890502 Add IDiv instruction for signed integer division
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-02-25 13:44:03 -05:00
5619c9dc87 Add address deref, syntax, and deref sizes
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-02-25 12:07:24 -05:00
bdd08c6c5b Fix bug when generating single-source instructions
Single-source instructions need their source spec to be in the the top 4
bits of the source/dest spec, and it was incorrectly being set in the
bottom 4 bits. This affected jump instructions, as they would
be reading the instruction at the given address rather than jumping
to it.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-02-19 14:11:57 -05:00
2413f9f362 Remove LALRPOP parser
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-02-18 17:55:11 -05:00
b0ef49bc2a Add assembler and execution logic
Most everything works, but there's one small bug with the execution
involving jumps - still have to figure that one out.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-02-18 17:44:41 -05:00
0598bd1526 Rename vm::common -> vm::addr
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-02-17 16:22:15 -05:00
bf6b0dfba9 Remove vm::obj::assemble mod
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-02-17 16:17:55 -05:00
2c4b56e362 Use lrpar for parsing, big 'ol syntax overhaul
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-02-17 16:15:06 -05:00
cf9ba376aa Add value directives and strings
.string, .zstring, .u64, .u32, .u16, .u8 are used before an ImmValue to
determine how the memory should be laid out for that value.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-02-11 17:49:17 -05:00
95d4eb0a60 Move test.asm -> examples directory
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-02-11 13:57:33 -05:00
6feeeea028 Add binary number parsing
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-02-10 19:10:17 -05:00
0ea3406b71 Add storeimm32 and storeimm64 syntax
These explicitly allow usage of storeimm32 and storeimm64 in the
assembler syntax. It will also warn you if you try to store a value
that's too large using the storeimm32 instruction

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-02-10 18:59:23 -05:00
15423502f3 Remove data section from test.asm example file
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-02-10 18:03:50 -05:00
7504b81b2d Require assembler sections to specify where in virtual memory they begin
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-02-10 18:02:44 -05:00
a4a37b5a27 Add Disassemble, fix bug in position calculation
* Disassemble structure can be used for dumping an object section
* Assembler position calculation was messing up, causing jump addresses
  to be wrong. This is fixed.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-02-10 16:31:08 -05:00
6c352396fa Add instruction visitor, which traverses memory and choosing instructions
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-02-10 13:22:54 -05:00
c982be553f Add execution to VM via file, starting to iron out bugs
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-02-09 15:43:07 -05:00
00027c4542 Add memory and register checking when required in the VM
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-02-09 14:10:02 -05:00
f1ed41f98b Rustfmt
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-02-09 13:13:26 -05:00
1c16be650a Start using 'symbol' in favor of 'name' or 'label'
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-02-09 13:12:56 -05:00
e198da5825 Finish up parser and assembler with more-or-less complete syntax
Major changes inlude:

* Bit the bullet and now instructions have their length hard-coded
* Move from_utf8 object parsing to be done by their objects (instead of
  a Parser god object)
* A list of AST sections are assembled into an Object using the new
  vm::obj::assemble module.
* Changed the object layout some in the spec, and adjusted code to match
  this.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-02-09 13:04:56 -05:00
329e61e087 Fix typos in some of the opcode binary layouts
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-02-03 18:00:24 -05:00