Commit | Line | Data |
---|---|---|
84b74595 AT |
1 | /* (c) 2021 Aaron Taylor <ataylor at subgeniuskitty dot com> */ |
2 | /* See LICENSE.txt file for copyright and license details. */ | |
3 | ||
4 | // TODO: Prune includes in both this header and the corresponding source file. | |
5 | #include <stdio.h> | |
6 | #include <stdint.h> | |
7 | #include <inttypes.h> | |
8 | #include <stdlib.h> | |
9 | #include <stdbool.h> | |
10 | #include <unistd.h> | |
11 | #include <fcntl.h> | |
12 | #include <string.h> | |
13 | #include <errno.h> | |
14 | #include <time.h> | |
15 | #include <termios.h> | |
16 | #include <signal.h> | |
17 | #include <sys/socket.h> | |
18 | #include <sys/types.h> | |
19 | #include <netinet/in.h> | |
20 | #include <arpa/inet.h> | |
21 | #include <netdb.h> | |
22 | ||
23 | #include "./a.out.h" | |
24 | ||
25 | // TODO: Can get rid of this since I don't do a show_usage() anymore? | |
26 | #define VERSION 5 | |
27 | ||
28 | /* Bytes per word. */ | |
29 | #define BPW 4 | |
30 | ||
31 | /* Number of stack words. */ | |
32 | #define STACK_LENGTH 1048576 | |
33 | ||
34 | /* Number of bytes of RAM. */ | |
35 | #define RAM_LENGTH 1073741824 | |
36 | ||
37 | /* Number of hardware threads. */ | |
38 | #define THREAD_COUNT 8 | |
39 | ||
40 | /* Number of syllables per word. */ | |
41 | #define SPW 5 | |
42 | ||
43 | struct NEDpsw { | |
44 | bool zero; | |
45 | bool negative; | |
46 | }; | |
47 | ||
48 | struct NEDthread { | |
49 | uint32_t stack[STACK_LENGTH]; | |
50 | uint32_t sp; | |
51 | uint32_t pc; | |
52 | uint8_t sc; | |
53 | struct NEDpsw * psw; | |
54 | }; | |
55 | ||
56 | struct NEDhack { | |
57 | uint32_t iw; | |
58 | bool resume_word; | |
59 | }; | |
60 | ||
61 | // TODO: Make this a single thread before committing. Multi-thread is broken with my current main loop. | |
62 | struct NEDstate { | |
63 | bool halted; | |
64 | uint8_t ram[RAM_LENGTH]; | |
65 | struct NEDthread * thread[THREAD_COUNT]; | |
66 | struct NEDthread * active_thread; | |
67 | struct NEDhack * hack; | |
68 | }; | |
69 | ||
70 | enum syllables { | |
71 | MVSTCK = 0b00001111, | |
72 | JMP = 0b00001110, | |
73 | SWAP = 0b00001101, | |
74 | ADD = 0b00001100, | |
75 | XOR = 0b00001011, | |
76 | NOT = 0b00001010, | |
77 | OR = 0b00001001, | |
78 | AND = 0b00001000, | |
79 | BRZ = 0b00000111, | |
80 | TEST = 0b00000110, | |
81 | CMPSWP = 0b00000101, | |
82 | SHIFT = 0b00000100, | |
83 | STORE = 0b00000011, | |
84 | LOAD = 0b00000010, | |
85 | NOP = 0b00000001, | |
86 | HALT = 0b00000000 | |
87 | }; | |
88 | ||
89 | struct NEDstate * init_simulator(void); | |
90 | struct NEDstate * run_simulator(struct NEDstate * state); | |
91 | uint32_t ram_r_word(struct NEDstate * state, uint32_t address); | |
92 |