Commit 91ff09d1a4f123de8a57a03e6f98d30580fe760f
1 parent
b5e96df6
Implemented debugger and disassembler
Showing
18 changed files
with
27341 additions
and
26903 deletions
Too many changes to show.
To preserve performance only 7 of 18 files are displayed.
.idea/compiler.xml
0 → 100644
1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
2 | +<project version="4"> | ||
3 | + <component name="CompilerConfiguration"> | ||
4 | + <resourceExtensions /> | ||
5 | + <wildcardResourcePatterns> | ||
6 | + <entry name="!?*.java" /> | ||
7 | + <entry name="!?*.form" /> | ||
8 | + <entry name="!?*.class" /> | ||
9 | + <entry name="!?*.groovy" /> | ||
10 | + <entry name="!?*.scala" /> | ||
11 | + <entry name="!?*.flex" /> | ||
12 | + <entry name="!?*.kt" /> | ||
13 | + <entry name="!?*.clj" /> | ||
14 | + <entry name="!?*.aj" /> | ||
15 | + </wildcardResourcePatterns> | ||
16 | + <annotationProcessing> | ||
17 | + <profile default="true" name="Default" enabled="false"> | ||
18 | + <processorPath useClasspath="true" /> | ||
19 | + </profile> | ||
20 | + </annotationProcessing> | ||
21 | + </component> | ||
22 | +</project> | ||
0 | \ No newline at end of file | 23 | \ No newline at end of file |
.idea/copyright/profiles_settings.xml
0 → 100644
.idea/misc.xml
@@ -16,4 +16,5 @@ | @@ -16,4 +16,5 @@ | ||
16 | <ConfirmationsSetting value="0" id="Add" /> | 16 | <ConfirmationsSetting value="0" id="Add" /> |
17 | <ConfirmationsSetting value="0" id="Remove" /> | 17 | <ConfirmationsSetting value="0" id="Remove" /> |
18 | </component> | 18 | </component> |
19 | + <component name="ProjectRootManager" version="2" assert-keyword="false" jdk-15="false" /> | ||
19 | </project> | 20 | </project> |
20 | \ No newline at end of file | 21 | \ No newline at end of file |
.idea/synacorvm.iml
@@ -2,16 +2,21 @@ | @@ -2,16 +2,21 @@ | ||
2 | <module type="CPP_MODULE" version="4"> | 2 | <module type="CPP_MODULE" version="4"> |
3 | <component name="NewModuleRootManager"> | 3 | <component name="NewModuleRootManager"> |
4 | <content url="file://$MODULE_DIR$"> | 4 | <content url="file://$MODULE_DIR$"> |
5 | - <sourceFolder url="file://$MODULE_DIR$/cpu.h" isTestSource="false" /> | ||
6 | - <sourceFolder url="file://$MODULE_DIR$/CMakeLists.txt" isTestSource="false" /> | ||
7 | - <sourceFolder url="file://$MODULE_DIR$/main.c" isTestSource="false" /> | 5 | + <sourceFolder url="file://$MODULE_DIR$/disasm.h" isTestSource="false" /> |
8 | <sourceFolder url="file://$MODULE_DIR$/stack.c" isTestSource="false" /> | 6 | <sourceFolder url="file://$MODULE_DIR$/stack.c" isTestSource="false" /> |
9 | - <sourceFolder url="file://$MODULE_DIR$/mem.h" isTestSource="false" /> | ||
10 | <sourceFolder url="file://$MODULE_DIR$/cpu.c" isTestSource="false" /> | 7 | <sourceFolder url="file://$MODULE_DIR$/cpu.c" isTestSource="false" /> |
8 | + <sourceFolder url="file://$MODULE_DIR$/disasm.c" isTestSource="false" /> | ||
9 | + <sourceFolder url="file://$MODULE_DIR$/mem.h" isTestSource="false" /> | ||
10 | + <sourceFolder url="file://$MODULE_DIR$/main.c" isTestSource="false" /> | ||
11 | <sourceFolder url="file://$MODULE_DIR$/mem.c" isTestSource="false" /> | 11 | <sourceFolder url="file://$MODULE_DIR$/mem.c" isTestSource="false" /> |
12 | <sourceFolder url="file://$MODULE_DIR$/registers.h" isTestSource="false" /> | 12 | <sourceFolder url="file://$MODULE_DIR$/registers.h" isTestSource="false" /> |
13 | + <sourceFolder url="file://$MODULE_DIR$/instructions.h" isTestSource="false" /> | ||
14 | + <sourceFolder url="file://$MODULE_DIR$/CMakeLists.txt" isTestSource="false" /> | ||
13 | <sourceFolder url="file://$MODULE_DIR$/registers.c" isTestSource="false" /> | 15 | <sourceFolder url="file://$MODULE_DIR$/registers.c" isTestSource="false" /> |
16 | + <sourceFolder url="file://$MODULE_DIR$/debug.h" isTestSource="false" /> | ||
14 | <sourceFolder url="file://$MODULE_DIR$/stack.h" isTestSource="false" /> | 17 | <sourceFolder url="file://$MODULE_DIR$/stack.h" isTestSource="false" /> |
18 | + <sourceFolder url="file://$MODULE_DIR$/cpu.h" isTestSource="false" /> | ||
19 | + <sourceFolder url="file://$MODULE_DIR$/debug.c" isTestSource="false" /> | ||
15 | </content> | 20 | </content> |
16 | <orderEntry type="sourceFolder" forTests="false" /> | 21 | <orderEntry type="sourceFolder" forTests="false" /> |
17 | <orderEntry type="module-library"> | 22 | <orderEntry type="module-library"> |
CMakeLists.txt
@@ -3,5 +3,5 @@ project(synacorvm) | @@ -3,5 +3,5 @@ project(synacorvm) | ||
3 | 3 | ||
4 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") | 4 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") |
5 | 5 | ||
6 | -set(SOURCE_FILES main.c cpu.c cpu.h registers.h mem.h stack.c stack.h registers.c mem.c) | ||
7 | -add_executable(synacorvm ${SOURCE_FILES}) | ||
8 | \ No newline at end of file | 6 | \ No newline at end of file |
7 | +set(SOURCE_FILES main.c cpu.c cpu.h registers.h mem.h disasm.h disasm.c stack.c stack.h registers.c mem.c instructions.h debug.c debug.h) | ||
8 | +add_executable(synacorvm ${SOURCE_FILES}) |
cpu.c
@@ -5,8 +5,6 @@ | @@ -5,8 +5,6 @@ | ||
5 | #include <stdlib.h> | 5 | #include <stdlib.h> |
6 | #include "cpu.h" | 6 | #include "cpu.h" |
7 | 7 | ||
8 | -uint64_t cycle_count = 0; | ||
9 | - | ||
10 | void mov(uint16_t dst, uint16_t src) | 8 | void mov(uint16_t dst, uint16_t src) |
11 | { | 9 | { |
12 | if(src > MAX_INT) | 10 | if(src > MAX_INT) |
@@ -117,7 +115,7 @@ void add(uint16_t dst, uint16_t a, uint16_t b) | @@ -117,7 +115,7 @@ void add(uint16_t dst, uint16_t a, uint16_t b) | ||
117 | regs[dst % (MAX_INT+1)] = (a + b) % (MAX_INT+1); | 115 | regs[dst % (MAX_INT+1)] = (a + b) % (MAX_INT+1); |
118 | } | 116 | } |
119 | 117 | ||
120 | -void mult(uint16_t dst, uint16_t a, uint16_t b) | 118 | +void mul(uint16_t dst, uint16_t a, uint16_t b) |
121 | { | 119 | { |
122 | if(a > MAX_INT) | 120 | if(a > MAX_INT) |
123 | { | 121 | { |
@@ -237,13 +235,7 @@ void nop() | @@ -237,13 +235,7 @@ void nop() | ||
237 | 235 | ||
238 | uint16_t fetch() | 236 | uint16_t fetch() |
239 | { | 237 | { |
240 | - /*if(pc == 0x5bf-1) | ||
241 | - { | ||
242 | - //break | ||
243 | - }*/ | ||
244 | uint16_t value = mem[pc++]; | 238 | uint16_t value = mem[pc++]; |
245 | - //printf("0x%2x (0x%2x)",pc,pc*sizeof(uint16_t)); | ||
246 | - //printf(" cycle: %d\n",cycle_count++); | ||
247 | return value; | 239 | return value; |
248 | } | 240 | } |
249 | 241 | ||
@@ -304,11 +296,11 @@ void start_execution() | @@ -304,11 +296,11 @@ void start_execution() | ||
304 | arg3 = fetch(); | 296 | arg3 = fetch(); |
305 | add(arg1,arg2,arg3); | 297 | add(arg1,arg2,arg3); |
306 | break; | 298 | break; |
307 | - case MULT: | 299 | + case MUL: |
308 | arg1 = fetch(); | 300 | arg1 = fetch(); |
309 | arg2 = fetch(); | 301 | arg2 = fetch(); |
310 | arg3 = fetch(); | 302 | arg3 = fetch(); |
311 | - mult(arg1,arg2,arg3); | 303 | + mul(arg1,arg2,arg3); |
312 | break; | 304 | break; |
313 | case MOD: | 305 | case MOD: |
314 | arg1 = fetch(); | 306 | arg1 = fetch(); |
@@ -372,7 +364,7 @@ void start_execution() | @@ -372,7 +364,7 @@ void start_execution() | ||
372 | } | 364 | } |
373 | } | 365 | } |
374 | 366 | ||
375 | -void core_dump() | 367 | +void print_regs() |
376 | { | 368 | { |
377 | fprintf(stderr,"r0: %2x\n",regs[0]); | 369 | fprintf(stderr,"r0: %2x\n",regs[0]); |
378 | fprintf(stderr,"r1: %2x\n",regs[1]); | 370 | fprintf(stderr,"r1: %2x\n",regs[1]); |
@@ -383,7 +375,14 @@ void core_dump() | @@ -383,7 +375,14 @@ void core_dump() | ||
383 | fprintf(stderr,"r6: %2x\n",regs[6]); | 375 | fprintf(stderr,"r6: %2x\n",regs[6]); |
384 | fprintf(stderr,"r7: %2x\n",regs[7]); | 376 | fprintf(stderr,"r7: %2x\n",regs[7]); |
385 | fprintf(stderr,"pc: %2x\n",pc); | 377 | fprintf(stderr,"pc: %2x\n",pc); |
378 | +} | ||
379 | + | ||
380 | +void core_dump() | ||
381 | +{ | ||
382 | + print_regs(); | ||
386 | //dump memory to file | 383 | //dump memory to file |
387 | //dump stack to file | 384 | //dump stack to file |
388 | exit(1); | 385 | exit(1); |
389 | } | 386 | } |
387 | + | ||
388 | + |
cpu.h
@@ -9,34 +9,34 @@ | @@ -9,34 +9,34 @@ | ||
9 | #include "mem.h" | 9 | #include "mem.h" |
10 | #include "stack.h" | 10 | #include "stack.h" |
11 | #include "registers.h" | 11 | #include "registers.h" |
12 | +#include "instructions.h" | ||
12 | 13 | ||
13 | #define MAX_INT 32767 | 14 | #define MAX_INT 32767 |
14 | 15 | ||
15 | -#define HALT 0x0000 | ||
16 | -#define MOV 0x0001 | ||
17 | -#define PUSH 0x0002 | ||
18 | -#define POP 0x0003 | ||
19 | -#define TEQ 0x0004 | ||
20 | -#define TGT 0x0005 | ||
21 | -#define JMP 0x0006 | ||
22 | -#define JNZ 0x0007 | ||
23 | -#define JZ 0x0008 | ||
24 | -#define ADD 0x0009 | ||
25 | -#define MULT 0x000A | ||
26 | -#define MOD 0x000B | ||
27 | -#define AND 0x000C | ||
28 | -#define OR 0x000D | ||
29 | -#define NOT 0x000E | ||
30 | -#define LOAD 0x000F | ||
31 | -#define STOR 0x0010 | ||
32 | -#define CALL 0x0011 | ||
33 | -#define RET 0x0012 | ||
34 | -#define OUT 0x0013 | ||
35 | -#define IN 0x0014 | ||
36 | -#define NOP 0x0015 | ||
37 | - | 16 | +void mov(uint16_t dst, uint16_t src); |
17 | +void push(uint16_t src); | ||
18 | +void pop(uint16_t dst); | ||
19 | +void teq(uint16_t dst, uint16_t a, uint16_t b); | ||
20 | +void tgt(uint16_t dst, uint16_t a, uint16_t b); | ||
21 | +void jmp(uint16_t dst); | ||
22 | +void jnz(uint16_t cond, uint16_t dst); | ||
23 | +void jz(uint16_t cond, uint16_t dst); | ||
24 | +void add(uint16_t dst, uint16_t a, uint16_t b); | ||
25 | +void mul(uint16_t dst, uint16_t a, uint16_t b); | ||
26 | +void mod(uint16_t dst, uint16_t a, uint16_t b); | ||
27 | +void and(uint16_t dst, uint16_t a, uint16_t b); | ||
28 | +void or(uint16_t dst, uint16_t a, uint16_t b); | ||
29 | +void not(uint16_t dst, uint16_t src); | ||
30 | +void load(uint16_t dst, uint16_t src); | ||
31 | +void stor(uint16_t dst, uint16_t src); | ||
32 | +void call(uint16_t dst); | ||
33 | +uint8_t ret(); | ||
34 | +void out(uint16_t src); | ||
35 | +void in(uint16_t dst); | ||
36 | +void nop(); | ||
38 | 37 | ||
39 | void start_execution(); | 38 | void start_execution(); |
40 | void core_dump(); | 39 | void core_dump(); |
40 | +void print_regs(); | ||
41 | 41 | ||
42 | #endif //SYNACORVM_CPU_H | 42 | #endif //SYNACORVM_CPU_H |