From 367b63fedaa6d47ce3514d2be8512f3f0b05f5eb Mon Sep 17 00:00:00 2001 From: Taylor Bockman Date: Thu, 6 Jul 2017 00:27:58 -0700 Subject: [PATCH] Some CPU boilerplate --- README.md | 6 +++++- include/cpu.h | 36 ++++++++++++++++++++++++++++++++++++ include/decoder.h | 25 ------------------------- include/opcodes.h | 1 - src/cpu.cc | 15 +++++++++++++++ 5 files changed, 56 insertions(+), 27 deletions(-) create mode 100644 include/cpu.h delete mode 100644 include/decoder.h create mode 100644 src/cpu.cc diff --git a/README.md b/README.md index 7232252..1d1171e 100644 --- a/README.md +++ b/README.md @@ -15,11 +15,12 @@ uVM is simply an experiment in developing a working virtual machine with it's ow ## Usage -`uvm [-v] [-h] -f .uc` +`uvm [-v] [-h] [-d ] -f .uc` * `-v`: Enable verbose logging mode * `-h`: Show usage * `-f .uc`: Load the uvm bytecode file for processing +* `-d `: The maximum stack depth in words ## 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 | | jmp _LABEL_ | 6 | Unconditional jump to _label_ | | 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. @@ -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 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 - [] 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 diff --git a/include/cpu.h b/include/cpu.h new file mode 100644 index 0000000..e601ccb --- /dev/null +++ b/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 . +// + +#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_ diff --git a/include/decoder.h b/include/decoder.h deleted file mode 100644 index bcc6a0a..0000000 --- a/include/decoder.h +++ /dev/null @@ -1,25 +0,0 @@ -// 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 . -// -// - - -#ifndef DECODER_H_ -#define DECODER_H_ - - - - -#endif // DECODER_H_ diff --git a/include/opcodes.h b/include/opcodes.h index 788d6e5..16be48f 100644 --- a/include/opcodes.h +++ b/include/opcodes.h @@ -13,7 +13,6 @@ // You should have received a copy of the GNU General Public License // along with UVM. If not, see . // -// #ifndef OPCODES_H_ diff --git a/src/cpu.cc b/src/cpu.cc new file mode 100644 index 0000000..7ff3f4b --- /dev/null +++ b/src/cpu.cc @@ -0,0 +1,15 @@ +// 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 . +//