diff options
| author | mrb0nk500 <b0nk@b0nk.xyz> | 2022-02-09 13:45:26 -0400 | 
|---|---|---|
| committer | mrb0nk500 <b0nk@b0nk.xyz> | 2022-02-09 13:45:26 -0400 | 
| commit | 8d9190cb14f287193196f422d49dbca0809980c7 (patch) | |
| tree | fd7224d362d1c80fd6b1fe9d2fab7ad397e1325f | |
| parent | b9fdf56717af2a9e7c9224610082bb026c86a87e (diff) | |
sux.{c,h}, opcode.h, disasm.c: Add code to use the new
instruction handler for reading the interrupt vectors.
| -rw-r--r-- | disasm.c | 25 | ||||
| -rw-r--r-- | opcode.h | 3 | ||||
| -rw-r--r-- | sux.c | 40 | ||||
| -rw-r--r-- | sux.h | 2 | 
4 files changed, 50 insertions, 20 deletions
| @@ -407,15 +407,17 @@ static void disasm_ortho(struct sux *cpu, WINDOW *w, uint8_t opcode, uint8_t pre  } -void disasm(struct sux *cpu, WINDOW *w, uint8_t lines, uint8_t opcode, uint8_t prefix, uint8_t ext_prefix, uint8_t prefix2, uint8_t *op_type, uint8_t *op_id, uint8_t thread) { +void disasm(struct sux *cpu, WINDOW *w, uint8_t lines, int opcode, uint8_t prefix, uint8_t ext_prefix, uint8_t prefix2, uint8_t *op_type, uint8_t *op_id, uint8_t thread) {  	uint64_t value;  	uint64_t address = 0;  	operand ortho_op[2];  	uint64_t ortho_addr[2] = {0, 0}; -	if (ext_prefix != 0x1D) { -		address = get_addr(cpu, opcode, prefix, ext_prefix, 0, 0, thread); -	} else { -		get_ortho_addr(cpu, opcode, prefix, cpu->pc, ortho_op, ortho_addr, op_type, op_id, 0, 0, thread); +	if (opcode < 0x100) { +		if (ext_prefix != 0x1D) { +			address = get_addr(cpu, opcode, prefix, ext_prefix, 0, 0, thread); +		} else { +			get_ortho_addr(cpu, opcode, prefix, cpu->pc, ortho_op, ortho_addr, op_type, op_id, 0, 0, thread); +		}  	}  	uint8_t rs = (prefix >> 4) & 3;  	char *postfix; @@ -449,8 +451,17 @@ void disasm(struct sux *cpu, WINDOW *w, uint8_t lines, uint8_t opcode, uint8_t p  				case 0x0: inst_name = ext_opname[opcode]; inst_type = ext_optype[opcode]; break;  			}  		} else { -			inst_name = opname[opcode]; -			inst_type = optype[opcode]; +			if (opcode < 0x100) { +				inst_name = opname[opcode]; +				inst_type = optype[opcode]; +			} else { +				switch (opcode) { +					case 0x100: inst_name = "NMI"; break; +					case 0x101: inst_name = "RESET"; break; +					case 0x102: inst_name = "IRQ"; break; +				} +				inst_type = IMPL; +			}  		}  		memcpy(op, inst_name, 3); @@ -64,6 +64,9 @@ struct sux {  	uint64_t bp; /* Base pointer. */  	uint64_t r11, r12, r13, r14, r15; /* Registers R11-R15. */;  	uint64_t clk; /* Number of clock cycles.  */ +	int nmi : 1; /* NMI flag. */ +	int reset : 1; /* Reset flag. */ +	int irq : 1; /* IRQ flag. */  };  typedef struct op operand; @@ -131,7 +131,7 @@ void *run(void *args) {  	uint8_t ext_prefix = 0;  	uint8_t prefix2 = 0;  	uint8_t op_id = 0; -	uint8_t opcode = 0; +	int opcode = 0;  	union reg address;  	union reg value;  	cpu->clk = 0; @@ -175,6 +175,7 @@ void *run(void *args) {  	uc.clk = 0;  	struct sux uc_test;*/  	for (;;) { +		uint8_t inst_len = 0;  		#if !bench  		if (end) {  			pthread_mutex_lock(&main_mutex); @@ -185,19 +186,29 @@ void *run(void *args) {  		#endif  		address.u64 = 0;  		value.u64 = 0; -		uint32_t instr = read_value(cpu, 0, cpu->pc, 4, 1, 0); -		uint8_t *tmp_inst = (uint8_t *)&instr; -		uint8_t inst_len = 0; -		prefix = ((instr & 3) == 3) ? tmp_inst[inst_len++] : 0; -		ext_prefix = ((tmp_inst[inst_len] & 0xF) == 0xD) ? tmp_inst[inst_len++] : 0; -		opcode = tmp_inst[inst_len++]; -		op_id = (ext_prefix == 0x1D) ? tmp_inst[inst_len++] : 0; +		if (cpu->reset) { +			opcode = 0x101; +			cpu->reset = 0; +		} else if (cpu->nmi) { +			opcode = 0x100; +			cpu->nmi = 0; +		} else if (cpu->irq) { +			opcode = 0x102; +			cpu->irq = 0; +		} else { +			uint32_t instr = read_value(cpu, 0, cpu->pc, 4, 1, 0); +			uint8_t *tmp_inst = (uint8_t *)&instr; +			prefix = ((instr & 3) == 3) ? tmp_inst[inst_len++] : 0; +			ext_prefix = ((tmp_inst[inst_len] & 0xF) == 0xD) ? tmp_inst[inst_len++] : 0; +			opcode = tmp_inst[inst_len++]; +			op_id = (ext_prefix == 0x1D) ? tmp_inst[inst_len++] : 0; +		}  		uint8_t operand_type[2];  		uint8_t am;  		uint8_t ortho_id[2];  		uint8_t ext_id = 0; -		uint8_t tmp_opcode = opcode; +		int tmp_opcode = opcode;  		uint8_t tmp_ext_prefix = ext_prefix;  		int is_ortho = 0;  		int is_ext = 0; @@ -251,7 +262,7 @@ void *run(void *args) {  					break;  			}  		} else { -			am = optype[opcode]; +			am = (opcode < 0x100) ? optype[opcode] : IMPL;  		}  		uint8_t rs   = (prefix >>  4) & 3;  		uint8_t size = (/***/1 << rs) - 1; @@ -316,7 +327,9 @@ void *run(void *args) {  		}  		/*usleep(1);*/  		#if !IO -		ins++; +		if (opcode < 0x100) { +			ins++; +		}  		#endif  		#if !bench  		if (step) { @@ -500,7 +513,10 @@ int main(int argc, char **argv) {  		thr[i].sx.r11 = 0, thr[i].sx.r12 = 0;  		thr[i].sx.r12 = 0, thr[i].sx.r13 = 0;  		thr[i].sx.r14 = 0, thr[i].sx.r15 = 0; -		thr[i].sx.pc = read_value(&thr[i].sx, 0, vec+offset, 7, 0, 0); +		thr[i].sx.pc = 0; +		thr[i].sx.nmi = 0; +		thr[i].sx.reset = 1; +		thr[i].sx.irq = 0;  		thr[i].th = i;  		#if !IO  		inst[i] = 0; @@ -60,7 +60,7 @@ extern pthread_cond_t main_cond;  #if debug  extern void print_info(struct sux *cpu, WINDOW *w, uint8_t lines, uint8_t thread);  extern void print_regs(struct sux *cpu, WINDOW *w); -extern void disasm(struct sux *cpu, WINDOW *w, uint8_t lines, uint8_t opcode, uint8_t prefix, uint8_t ext_prefix, uint8_t prefix2, uint8_t *op_type, uint8_t *op_id, uint8_t thread); +extern void disasm(struct sux *cpu, WINDOW *w, uint8_t lines, int opcode, uint8_t prefix, uint8_t ext_prefix, uint8_t prefix2, uint8_t *op_type, uint8_t *op_id, uint8_t thread);  #endif  /*#define KEYBUF_SIZE 0x40 | 
