102 Commits

Author SHA1 Message Date
bff9220fb1 Extend how interrupts are reported to the main execution loop
Some things that were previously hard VM-level errors are now handled by
interrupts. While this is relatively easy to handle, I was wanting a
little more structure for the error types - so, errors that should
invoke an interrupt are passed along in their own structure in a
VmError::Interrupt variant. If an error is raised during the tick()
phase of execution that would cause an interrupt, that interrupt is
intercepted and the VM continues.

The State::interrupt() function also will catch double faults and triple
faults, with a triple fault being its own variant in the VmError
structure (so it cannot be intercepted as an interrupt by accident).

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-03-12 16:56:20 -04:00
cb75bf59e0 Polish the VM exception definitions, add double faults, update exception order
* Exception definition is a little more comprehensive
* Add error state exceptions including double fault
* Exception numbers are now roughly in the order of their importance

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-03-10 16:02:23 -04:00
28edfb6933 Remove dollar sign ($) from front of number tokens
Number tokens with a dollar sign are kind of cumbersome and don't really
serve a purpose, so I'm removing them.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-03-10 15:59:36 -04:00
7c9d4fe908 Update spec to reflect previous changes
This adds R00-R31 preservation to interrupts and adds meta section
required values.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-03-10 12:21:29 -04:00
85e5f7a2bf Add INTERRUPT_ENABLE flag, fix bug with register preservation
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-03-10 12:20:59 -04:00
3da72874f5 Add syntax for previous commit
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-03-10 12:20:15 -04:00
551bd2c3f4 Add initial register states to meta section; remove entry directive
It makes sense to allow users to set the initial register values. This
allows someone to e.g. enable interrupts once the VM has started, or set
the initial stack pointer value.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-03-10 12:18:31 -04:00
3522b3d0cd Update spec and register offset for interrupts
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-03-09 18:42:31 -04:00
8c4a9991fd Fix dumb mistake in address calculation for interrupts, add more registers to interrupt call stack
Interrupts need to be on 8-byte (or 64-bit) bounds. I had mistakenly
decided to shift right by 5 (which isn't even dividing by 64, it's 32)
-but since this an address pointing at byte ranges, that should be
divided by 8, or >> 3.

Additionally, interrupts add all 32 general purpose registers to the
stack because otherwise they become useless.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-03-09 18:24:54 -04:00
9e82663b2a Rename tests/call.asm -> tests/test_call.asm
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-03-09 18:24:19 -04:00
219da3c3c2 Run rustfmt
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-03-09 16:47:38 -04:00
d0f8d93edf Run rustfmt
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-03-09 16:47:30 -04:00
63c81f07f7 Fix alignment calculation and padding
Aligned values are a little funky, because the size of the line can't be
determined without knowing what address we're at. So the
DataLines iterator now takes a start address, so it is able to correctly
calculate alignment padding.

Also, the length of the data section uses the DataLines iterator now so
there isn't a complex re-implementation of the same logic.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-03-09 16:43:04 -04:00
4ae060c68d Add rerun_except to root crate
Cargo is finding more reasons to do unnecessary rebuilds, so I've added
the rerun_except crate to its build.rs as well to ignore .asm files
before recompiling.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-03-09 16:38:41 -04:00
65972fcbbe 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>
2020-03-09 15:11:32 -04:00
b697b000a4 Add updated Cargo.lock for new table generator package
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-03-07 18:08:57 -05:00
90155b0cb3 Add alignment syntax, datasection pos/line iterator, disassembler
* Interrupts require functions being aligned on 64-bit boundaries.
  Alignment is now allowed via the .align <intsize> directive, aligning
  the current address to a new alignment.
* Datasection iteration doesn't require keeping track of the current
  position.
* Rudimentary disassembler for breaking down the contents of an object

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-03-07 18:01:31 -05:00
1f93732a7c Reorganize instruction assembler logic (fixing a known bug), add interrupts to frontend
* Instruction assembler used to use macros for handling source,
  dest-source, source-source, etc instructions. It did not have a
  source-source implementation, however, so the two source-source
  instructions (cmpeq and cmplt) were treated as dest-source. This has
  been refactored into some local methods that handle this now.
* Syntax for interrupts and interrupt returns are implemented and appear
  to be working

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-03-06 12:53:07 -05:00
fbe2c529af Add decoding of INT and IRET instructions
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-03-06 12:52:46 -05:00
34b1147fe6 Add int and iret instruction definitions to the VM backend
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-03-06 12:30:49 -05:00
1fb2a1df44 Add interrupts enabled flag to spec, add interrupt return actions to spec
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-03-06 12:19:07 -05:00
58262eab40 Move examples to libvm source base and add symlink to root directory
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-03-06 12:18:20 -05:00
b1f2de198e Add interrupt definition syntax and interrupt handling in VM execution state
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-03-06 12:17:05 -05:00
bf83601cdf Add interrupt struct and IVT reader
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-03-04 16:41:37 -05:00
ce352c000c Add IVT register and interrupt module
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-03-04 14:37:00 -05:00
bdd30274ed Add interrupts draft to spec
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-03-04 14:23:57 -05:00
711bfeb7f9 Squash some warnings
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-03-03 19:34:41 -05:00
bac1b413dc Remove structopt where appropriate
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-03-03 19:33:55 -05:00
5ffca7bcf0 Second part of VM lib transition
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
2020-03-03 19:07:35 -05:00
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