Browse Source

Some CPU boilerplate

master
Taylor Bockman 7 years ago
parent
commit
367b63feda
  1. 6
      README.md
  2. 36
      include/cpu.h
  3. 1
      include/opcodes.h
  4. 10
      src/cpu.cc

6
README.md

@ -15,11 +15,12 @@ uVM is simply an experiment in developing a working virtual machine with it's ow
## Usage ## Usage
`uvm [-v] [-h] -f <your_file_of_bytecode>.uc` `uvm [-v] [-h] [-d <stack_depth>] -f <your_file_of_bytecode>.uc`
* `-v`: Enable verbose logging mode * `-v`: Enable verbose logging mode
* `-h`: Show usage * `-h`: Show usage
* `-f <file_name>.uc`: Load the uvm bytecode file for processing * `-f <file_name>.uc`: Load the uvm bytecode file for processing
* `-d <stack_depth>`: The maximum stack depth in words
## Testing ## Testing
@ -53,6 +54,7 @@ uVM possesses the standard issue instruction set you might expect in a simple VM
| isub | 5 | Subtracts the top two _integer_ arguments of the stack from each other | | isub | 5 | Subtracts the top two _integer_ arguments of the stack from each other |
| jmp _LABEL_ | 6 | Unconditional jump to _label_ | | jmp _LABEL_ | 6 | Unconditional jump to _label_ |
| jc _LABEL_ | 7 | Jump if the top of the stack is a 1 | | jc _LABEL_ | 7 | Jump if the top of the stack is a 1 |
| halt | 8 | Halts the VM |
As I learn more about VM development this instruction set will likely become much more robust. As I learn more about VM development this instruction set will likely become much more robust.
@ -61,6 +63,8 @@ As I learn more about VM development this instruction set will likely become muc
- [] Tests for good paths for all instructions - [] Tests for good paths for all instructions
- [] Tests for uncompilable code - [] Tests for uncompilable code
- [] Tests for maximum stack size reached
- [] Tests to make sure the maximum stack depth is always greater than 0
- [] Logging out current stack position, etc when verbose mode is enabled - [] Logging out current stack position, etc when verbose mode is enabled
- [] If verbose mode isn't enabled it shows the ascii loading while processing - [] If verbose mode isn't enabled it shows the ascii loading while processing
- [] Come up with a way to allow the user to echo to the screen - [] Come up with a way to allow the user to echo to the screen

36
include/cpu.h

@ -0,0 +1,36 @@
// This file is part of UVM.
//
// UVM is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// UVM is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with UVM. If not, see <http://www.gnu.org/licenses/>.
//
#ifndef CPU_H_
#define CPU_H_
class CPU {
private:
int sp; // Stack pointer
int ip; // Instruction pointer
int fp; // Frame pointer
// Stack goes here
public:
CPU(); // The CPU should be initialized with the code and stuff
fetch();
decode();
execute();
run(); // Runs the loaded code...this should have something in args
};
#endif // CPU_H_

1
include/opcodes.h

@ -13,7 +13,6 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with UVM. If not, see <http://www.gnu.org/licenses/>. // along with UVM. If not, see <http://www.gnu.org/licenses/>.
// //
//
#ifndef OPCODES_H_ #ifndef OPCODES_H_

10
include/decoder.h → src/cpu.cc

@ -13,13 +13,3 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with UVM. If not, see <http://www.gnu.org/licenses/>. // along with UVM. If not, see <http://www.gnu.org/licenses/>.
// //
//
#ifndef DECODER_H_
#define DECODER_H_
#endif // DECODER_H_
Loading…
Cancel
Save