From 51228e257ac68e055886ce54df51b0933bf13218 Mon Sep 17 00:00:00 2001 From: Aaron Taylor Date: Thu, 8 Jul 2021 18:28:22 -0700 Subject: [PATCH] Made most functions in NEDsim simulator static. --- hacks/NEDsim/simulator.c | 53 ++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/hacks/NEDsim/simulator.c b/hacks/NEDsim/simulator.c index 9708486..9c63b67 100644 --- a/hacks/NEDsim/simulator.c +++ b/hacks/NEDsim/simulator.c @@ -5,7 +5,6 @@ /* NED1 Simulator */ /* -------------------------------------------------------------------------- */ -// TODO: Make a bunch of functions private in this file. #include #include #include @@ -27,7 +26,7 @@ #include "a.out.h" #include "simulator.h" -uint32_t +static uint32_t generate_binary_psw(struct NEDstate * state) { uint32_t psw = 0; @@ -36,13 +35,13 @@ generate_binary_psw(struct NEDstate * state) return psw; } -void +static void ram_w_byte(struct NEDstate * state, uint32_t address, uint8_t data) { state->ram[address-RAM_BASE_ADDRESS] = data; } -uint8_t +static uint8_t ram_r_byte(struct NEDstate * state, uint32_t address) { return state->ram[address-RAM_BASE_ADDRESS]; @@ -50,7 +49,7 @@ ram_r_byte(struct NEDstate * state, uint32_t address) /* For now, with only a terminal for IO, we pick off IO requests when accessing RAM. */ -void +static void ram_w_word(struct NEDstate * state, uint32_t address, uint32_t data) { if (address >= RAM_BASE_ADDRESS) { @@ -80,7 +79,7 @@ ram_r_word(struct NEDstate * state, uint32_t address) return 0b0; } -uint32_t +static uint32_t fetch_instruction_word(struct NEDstate * state) { uint32_t word = ram_r_word(state, state->active_thread->pc); @@ -88,31 +87,31 @@ fetch_instruction_word(struct NEDstate * state) return word; } -void +static void stack_w(struct NEDthread * thread, uint32_t value, uint8_t offset) { thread->stack[thread->sp - (offset + 1)] = value; } -uint32_t +static uint32_t stack_r(struct NEDthread * thread, uint8_t offset) { return thread->stack[thread->sp - (offset + 1)]; } -void +static void stack_push(struct NEDthread * thread, uint32_t value) { thread->stack[thread->sp++] = value; } -uint32_t +static uint32_t stack_pop(struct NEDthread * thread) { return thread->stack[--thread->sp]; } -void +static void set_psw_flags(uint32_t word, struct NEDstate * state) { if (word == 0) { @@ -127,7 +126,7 @@ set_psw_flags(uint32_t word, struct NEDstate * state) } } -void +static void ned_instruction_and(struct NEDstate * state) { uint32_t operand1 = stack_pop(state->active_thread); @@ -136,7 +135,7 @@ ned_instruction_and(struct NEDstate * state) set_psw_flags(stack_r(state->active_thread,0), state); } -void +static void ned_instruction_or(struct NEDstate * state) { uint32_t operand1 = stack_pop(state->active_thread); @@ -145,14 +144,14 @@ ned_instruction_or(struct NEDstate * state) set_psw_flags(stack_r(state->active_thread,0), state); } -void +static void ned_instruction_not(struct NEDstate * state) { stack_push(state->active_thread, ~stack_pop(state->active_thread)); set_psw_flags(stack_r(state->active_thread,0), state); } -void +static void ned_instruction_xor(struct NEDstate * state) { uint32_t operand1 = stack_pop(state->active_thread); @@ -161,7 +160,7 @@ ned_instruction_xor(struct NEDstate * state) set_psw_flags(stack_r(state->active_thread,0), state); } -void +static void ned_instruction_add(struct NEDstate * state) { uint32_t operand1 = stack_pop(state->active_thread); @@ -170,7 +169,7 @@ ned_instruction_add(struct NEDstate * state) set_psw_flags(stack_r(state->active_thread,0), state); } -void +static void ned_instruction_shift(struct NEDstate * state) { /* TODO: Bounds check: Either all inputs are valid OR shift_by < 32. */ @@ -186,21 +185,21 @@ ned_instruction_shift(struct NEDstate * state) set_psw_flags(stack_r(state->active_thread,0), state); } -void +static void ned_instruction_test(struct NEDstate * state) { uint32_t word = stack_pop(state->active_thread); set_psw_flags(word, state); } -void +static void ned_instruction_jmp(struct NEDstate * state) { state->active_thread->pc = stack_pop(state->active_thread); // The SC is caught and reset by the main loop since the PC changed. } -void +static void ned_instruction_swap(struct NEDstate * state) { uint32_t temp1 = stack_pop(state->active_thread); @@ -210,7 +209,7 @@ ned_instruction_swap(struct NEDstate * state) set_psw_flags(stack_r(state->active_thread,0), state); } -void +static void ned_instruction_brz(struct NEDstate * state) { uint32_t new_pc = stack_pop(state->active_thread); @@ -221,7 +220,7 @@ ned_instruction_brz(struct NEDstate * state) } } -void +static void ned_instruction_load(struct NEDstate * state) { uint32_t address = stack_pop(state->active_thread); @@ -229,7 +228,7 @@ ned_instruction_load(struct NEDstate * state) set_psw_flags(stack_r(state->active_thread,0), state); } -void +static void ned_instruction_store(struct NEDstate * state) { uint32_t address = stack_pop(state->active_thread); @@ -237,14 +236,14 @@ ned_instruction_store(struct NEDstate * state) ram_w_word(state, address, data); } -void +static void ned_instruction_halt(struct NEDstate * state) { printf("Halting.\n"); state->halted = true; } -void +static void execute_syllable(struct NEDstate * state, enum syllables syllable) { if (syllable & 0b100000) { /* Check the first bit of the syllable. 1 means IM_x. */ @@ -282,14 +281,14 @@ execute_syllable(struct NEDstate * state, enum syllables syllable) } } -uint8_t +static uint8_t extract_syllable_from_word(uint32_t word, uint8_t index) { uint32_t mask = 0b111111 << 6*(4-index); return (word & mask) >> 6*(4-index); } -void +static void parse_aout_file(FILE * input, struct exec * aout_exec, uint8_t * text_segment, struct nlist ** symbol_table, uint32_t * symbol_count) { -- 2.20.1