Commit 91ff09d1a4f123de8a57a03e6f98d30580fe760f

Authored by Imanol-Mikel Barba Sabariego
1 parent b5e96df6

Implemented debugger and disassembler

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 23 \ No newline at end of file
... ...
.idea/copyright/profiles_settings.xml 0 → 100644
  1 +<component name="CopyrightManager">
  2 + <settings default="" />
  3 +</component>
0 4 \ No newline at end of file
... ...
.idea/misc.xml
... ... @@ -16,4 +16,5 @@
16 16 <ConfirmationsSetting value="0" id="Add" />
17 17 <ConfirmationsSetting value="0" id="Remove" />
18 18 </component>
  19 + <component name="ProjectRootManager" version="2" assert-keyword="false" jdk-15="false" />
19 20 </project>
20 21 \ No newline at end of file
... ...
.idea/synacorvm.iml
... ... @@ -2,16 +2,21 @@
2 2 <module type="CPP_MODULE" version="4">
3 3 <component name="NewModuleRootManager">
4 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 6 <sourceFolder url="file://$MODULE_DIR$/stack.c" isTestSource="false" />
9   - <sourceFolder url="file://$MODULE_DIR$/mem.h" isTestSource="false" />
10 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 11 <sourceFolder url="file://$MODULE_DIR$/mem.c" isTestSource="false" />
12 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 15 <sourceFolder url="file://$MODULE_DIR$/registers.c" isTestSource="false" />
  16 + <sourceFolder url="file://$MODULE_DIR$/debug.h" isTestSource="false" />
14 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 20 </content>
16 21 <orderEntry type="sourceFolder" forTests="false" />
17 22 <orderEntry type="module-library">
... ...
CMakeLists.txt
... ... @@ -3,5 +3,5 @@ project(synacorvm)
3 3  
4 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 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})
... ...
... ... @@ -5,8 +5,6 @@
5 5 #include <stdlib.h>
6 6 #include "cpu.h"
7 7  
8   -uint64_t cycle_count = 0;
9   -
10 8 void mov(uint16_t dst, uint16_t src)
11 9 {
12 10 if(src > MAX_INT)
... ... @@ -117,7 +115,7 @@ void add(uint16_t dst, uint16_t a, uint16_t b)
117 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 120 if(a > MAX_INT)
123 121 {
... ... @@ -237,13 +235,7 @@ void nop()
237 235  
238 236 uint16_t fetch()
239 237 {
240   - /*if(pc == 0x5bf-1)
241   - {
242   - //break
243   - }*/
244 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 239 return value;
248 240 }
249 241  
... ... @@ -304,11 +296,11 @@ void start_execution()
304 296 arg3 = fetch();
305 297 add(arg1,arg2,arg3);
306 298 break;
307   - case MULT:
  299 + case MUL:
308 300 arg1 = fetch();
309 301 arg2 = fetch();
310 302 arg3 = fetch();
311   - mult(arg1,arg2,arg3);
  303 + mul(arg1,arg2,arg3);
312 304 break;
313 305 case MOD:
314 306 arg1 = fetch();
... ... @@ -372,7 +364,7 @@ void start_execution()
372 364 }
373 365 }
374 366  
375   -void core_dump()
  367 +void print_regs()
376 368 {
377 369 fprintf(stderr,"r0: %2x\n",regs[0]);
378 370 fprintf(stderr,"r1: %2x\n",regs[1]);
... ... @@ -383,7 +375,14 @@ void core_dump()
383 375 fprintf(stderr,"r6: %2x\n",regs[6]);
384 376 fprintf(stderr,"r7: %2x\n",regs[7]);
385 377 fprintf(stderr,"pc: %2x\n",pc);
  378 +}
  379 +
  380 +void core_dump()
  381 +{
  382 + print_regs();
386 383 //dump memory to file
387 384 //dump stack to file
388 385 exit(1);
389 386 }
  387 +
  388 +
... ...
... ... @@ -9,34 +9,34 @@
9 9 #include "mem.h"
10 10 #include "stack.h"
11 11 #include "registers.h"
  12 +#include "instructions.h"
12 13  
13 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 38 void start_execution();
40 39 void core_dump();
  40 +void print_regs();
41 41  
42 42 #endif //SYNACORVM_CPU_H
... ...