void print_disassembly(const word scommand) { script_command s_c = command_list[scommand]; if(s_c.args == 2) { al_trace("%14s: ", s_c.name); if(s_c.arg1_type == 0) al_trace("%10s (val = %9d), ", varToString(sarg1), get_register(sarg1)); else al_trace("%10s (val = %9d), ", "immediate", sarg1); if(s_c.arg2_type == 0) al_trace("%10s (val = %9d)\n", varToString(sarg2), get_register(sarg2)); else al_trace("%10s (val = %9d)\n", "immediate", sarg2); } else if(s_c.args == 1) { al_trace("%14s: ", s_c.name); if(s_c.arg1_type == 0) al_trace("%10s (val = %9d)\n", varToString(sarg1), get_register(sarg1)); else al_trace("%10s (val = %9d)\n", "immediate", sarg1); } else al_trace("%14s\n", s_c.name); }
testGate1(int looper_max) { long instrwords[10]; int i,loop_count,ninstr; i = 0; instrwords[i++] = encode_MASTERSetGates(0,0xfff,0); instrwords[i++] = encode_MASTERSetDuration(0,800); /* for 10 us */ instrwords[i++] = encode_MASTERSetGates(1,0x1,0x1); /* blip gate 0 for 10 usec after the phase count cpmplete */ instrwords[i++] = encode_MASTERSetGates(1,0x1,0x0); /* raise gate 6, sample phase count */ ninstr = i; while (get_register(MASTER,InstructionFIFOCount) < 900) { cntrlFifoPIO(instrwords, ninstr); } DPRINT1(-1,"testGate1: data fifo count: %ld\n",get_field(MASTER,data_fifo_count)); taskDelay(calcSysClkTicks(1000)); /* 1 sec */ cntrlFifoStart(); loop_count = 0; DPRINT1(-1,"testGate1: fifo running: %d\n",cntrlFifoRunning()); while ( cntrlFifoRunning() && (loop_count < looper_max)) { if (get_register(MASTER,InstructionFIFOCount) < 990) { cntrlFifoPIO(instrwords, ninstr); } loop_count++; } if (loop_count >= looper_max) { cntrlFifoPut(encode_MASTERSetDuration(1,0)); } }
int hal_syscall_handler(void) { CYG_ADDRWORD func, arg1, arg2, arg3, arg4; CYG_ADDRWORD err; func = get_register(ER0); arg1 = get_register(ER1); arg2 = get_register(ER2); arg3 = get_register(ER3); arg4 = 0; if (func == SYS_interrupt) { // A console interrupt landed us here. // Invoke the debug agent so as to cause a SIGINT. return SIGINT; } if (__do_syscall(func, arg1, arg2, arg3, arg4, &err)) { put_register(D0, err); return 0; } return SIGTRAP; }
void test_lazy() { #ifdef DEFERRED_CALLS_FIRST_DRAFT Branch branch; Term* a = branch.compile("a = add(1 2)"); set_lazy_call(a, true); Stack context; push_frame(&context, &branch); run_interpreter(&context); test_equals(get_register(&context, a), ":Unevaluated"); Frame* frame = push_frame(&context, &branch); frame->pc = a->index; frame->startPc = frame->pc; frame->endPc = frame->pc + 1; frame->strategy = ByDemand; run_interpreter(&context); test_equals(get_register(&context, a), "3"); reset_stack(&context); Term* b = branch.compile("b = add(a a)"); push_frame(&context, &branch); run_interpreter(&context); test_equals(get_register(&context, a), "3"); test_equals(get_register(&context, b), "6"); #endif }
void LLScriptLSOParse::printRegisters(LLFILE *fp) { // print out registers first S32 i; fprintf(fp, "=============================\n"); fprintf(fp, "Registers\n"); fprintf(fp, "=============================\n"); S32 version = get_register(mRawData, LREG_VN); if (version == LSL2_VERSION1_END_NUMBER) { gMajorVersion = LSL2_MAJOR_VERSION_ONE; } else if (version == LSL2_VERSION_NUMBER) { gMajorVersion = LSL2_MAJOR_VERSION_TWO; } for (i = LREG_IP; i < LREG_EOF; i++) { if (i < LREG_NCE) { fprintf(fp, "%s: 0x%X\n", gLSCRIPTRegisterNames[i], get_register(mRawData, (LSCRIPTRegisters)i)); } else if (gMajorVersion == LSL2_MAJOR_VERSION_TWO) { U64 data = get_register_u64(mRawData, (LSCRIPTRegisters)i); fprintf(fp, "%s: 0x%X%X\n", gLSCRIPTRegisterNames[i], (U32)(data>>32), (U32)(data && 0xFFFFFFFF)); } }
// if we're going to assign a variable, we need to decrement the reference count of what we were pointing at (if anything) void LLScriptHeapRunTime::releaseLocal(S32 address) { S32 hr = get_register(mBuffer, LREG_HR); address = lscript_local_get(mBuffer, address); if ( (address >= hr) &&(address < hr + get_register(mBuffer, LREG_HP))) { decreaseRefCount(address); } }
void LLScriptHeapRunTime::releaseGlobal(S32 address) { // NOTA BENE: Global strings are referenced relative to the HR while local strings aren't S32 hr = get_register(mBuffer, LREG_HR); address = lscript_global_get(mBuffer, address) + hr; if ( (address >= hr) &&(address < hr + get_register(mBuffer, LREG_HP))) { decreaseRefCount(address); } }
int hal_syscall_handler(void) { CYG_ADDRWORD func, arg1, arg2, arg3, arg4; CYG_ADDRWORD err, sig; func = get_register(EAX); arg1 = get_register(EBX); arg2 = get_register(ECX); arg3 = get_register(EDX); arg4 = 0; switch (func) { case 1: func = SYS_exit; break; case 3: func = SYS_read; break; case 4: func = SYS_write; break; case 37: func = SYS_kill; break; case 48: // install signal handler // FIXME! put_register(EAX, 0); return 0; case 184: // get program arguments // FIXME! *(int *)arg1 = 0; put_register(EAX, 0); return 0; default: return SIGTRAP; } if (func == SYS_exit) { // We want to stop in exit so that the user may poke around // to see why his app exited. return SIGTRAP; } if (__do_syscall(func, arg1, arg2, arg3, arg4, &err, &sig)) { put_register(EAX, err); return (int)sig; } return SIGTRAP; }
int hal_syscall_handler(void) { int func, arg1, arg2, arg3, arg4; int err, sig; func = get_register(R4); arg1 = get_register(R5); arg2 = get_register(R6); arg3 = get_register(R7); arg4 = *(unsigned int *)(get_register(SP)); switch (func) { case _shnewlib_SYS_read: func = SYS_read; break; case _shnewlib_SYS_write: func = SYS_write; break; case _shnewlib_SYS_open: func = SYS_open; break; case _shnewlib_SYS_close: func = SYS_close; break; case _shnewlib_SYS_lseek: func = SYS_lseek; break; case _shnewlib_SYS_utime: func = SYS_utime; default: return SIGTRAP; } if (func == SYS_interrupt) { // A console interrupt landed us here. // Invoke the debug agent so as to cause a SIGINT. return SIGINT; } if (__do_syscall(func, arg1, arg2, arg3, arg4, &err, &sig)) { // R0 is normally result register, but newlib's trap // code looks in R1 for the return value put_register(R1, err); return sig; } return SIGTRAP; }
LLScriptLibData *lsa_get_list_ptr(U8 *buffer, S32 &offset, BOOL b_dec_ref) { if (get_register(buffer, LREG_FR)) return (new LLScriptLibData); S32 orig_offset = offset; // this bit of nastiness is to get around that code paths to local variables can result in lack of initialization // and function clean up of ref counts isn't based on scope (a mistake, I know) offset += get_register(buffer, LREG_HR) - 1; if ( (offset < get_register(buffer, LREG_HR)) ||(offset >= get_register(buffer, LREG_HP))) { set_fault(buffer, LSRF_BOUND_CHECK_ERROR); return (new LLScriptLibData); } LLScriptAllocEntry entry; bytestream2alloc_entry(entry, buffer, offset); if (!entry.mType) { set_fault(buffer, LSRF_HEAP_ERROR); return NULL; } LLScriptLibData base, *tip = &base; if (entry.mType != LST_LIST) { return NULL; } else { // get length of list S32 i, length = bytestream2integer(buffer, offset); for (i = 0; i < length; i++) { S32 address = bytestream2integer(buffer, offset); tip->mListp = lsa_get_data(buffer, address, FALSE); tip = tip->mListp; } } if (b_dec_ref) { lsa_decrease_ref_count(buffer, orig_offset); } tip = base.mListp; base.mListp = NULL; return tip; }
// Read a bunch of registers to see what happens, for initial debugging void test_registers() { u_long id; id = idcode(id); id = get_cpsr(); id = 0x87654321; ice_set(watchpoint0_adr, id); id = idcode(); id = ice_get(watchpoint0_adr); set_register(5, 0xaa5533cc); set_register(12, 0x1234fedc); id = get_register(5); id = get_register(12); }
void exMOV(enum addr_mode mode, char src, char dst) { char val; switch( mode ) { case VAL_REG : if(set_register(src, dst)) { printf("Bad register access\n"); exit(-1); } break; case REG_REG: if(get_register(&val, src)) { printf("Bad register access\n"); exit(-1); } if(set_register(val, dst)) { printf("Bad register access\n"); exit(-1); } break; case ADDR_REG : if( get_address( &val,src )) { printf("Bad Address Location -RO\n"); exit(-1); } if( set_register( val, dst )) { printf("Bad Register access \n"); exit(-1); } break; case REG_ADDR : if( get_register( &val,src )) { printf("Bad Register Access \n"); exit(-1); } if( set_address( val,dst)) { printf("Bad Address Location -RO \n"); } break; default : printf("Bad addressing mode\n"); } }
void __single_step (void) { int exr; exr = get_register(EXR); exr |= 0x80; /* set T flag */ put_register(EXR,exr); }
void __clear_single_step (void) { int exr; exr = get_register(EXR); exr &= 0x7f; /* clear T flag */ put_register(EXR,exr); }
void exADD(enum addr_mode mode, char src,char dst) { char val; switch( mode ) { case VAL_REG : if(set_register(src, dst)) { printf("Bad register access\n"); exit(-1); } break; case REG_REG: if(get_register(&val, src)) { printf("Bad register access\n"); exit(-1); } if(set_register(val, dst)) { printf("Bad register access\n"); exit(-1); } break; default : printf("Bad addressing mode\n"); } }
bool token::is_register(registers _register) const { if (is_register()) { return get_register() == _register; } return false; }
static GLuint get_hw_reg(struct pair_state *s, GLuint file, GLuint index) { GLuint hwindex; struct pair_register_translation *t = get_register(s, file, index); if (!t) { _mesa_problem(s->Ctx, "get_hw_reg: %i[%i]\n", file, index); return 0; } if (t->Allocated) return t->HwIndex; for(hwindex = 0; hwindex < s->Handler->MaxHwTemps; ++hwindex) if (!s->HwTemps[hwindex].RefCount) break; if (hwindex >= s->Handler->MaxHwTemps) { error("Ran out of hardware temporaries"); return 0; } alloc_hw_reg(s, file, index, hwindex); return hwindex; }
S32 lsa_postadd_lists(U8 *buffer, S32 offset1, LLScriptLibData *data, S32 heapsize) { if (get_register(buffer, LREG_FR)) return 0; LLScriptLibData *list1 = lsa_get_data(buffer, offset1, TRUE); if (!list1) { set_fault(buffer, LSRF_HEAP_ERROR); delete list1; return 0; } if (list1->mType != LST_LIST) { set_fault(buffer, LSRF_HEAP_ERROR); delete list1; return 0; } LLScriptLibData *runner = list1; while (runner->mListp) { runner = runner->mListp; } runner->mListp = data->mListp; return lsa_heap_add_data(buffer, list1, heapsize, TRUE); }
static unsigned int get_areg (int n) { switch (n) { case 0: return get_register (A0); case 1: return get_register (A1); case 2: return get_register (A2); case 3: return get_register (A3); } return 0; }
uint32_t eval(int p, int q, bool *success) { if(p > q) { printf("Bad expression!\n"); *success = false; return 0; } else if(p == q) { uint32_t val; if(tokens[p].type == DINT) sscanf(tokens[p].str, "%d", &val); else if(tokens[p].type == HINT) sscanf(tokens[p].str, "%x", &val); else if(tokens[p].type == REG) val = get_register(tokens[p].str); else if(tokens[p].type == VAR) { Exp_flag = 1; val = find_var(tokens[p].str); if(val == -1) { printf("No var matched!\n"); *success = false; return 0; } } else { printf("No number matched!\n"); *success = false; return 0; } return val; } else if(check_parentheses(p, q, success) == true) { return eval(p + 1, q - 1, success); } else if(*success == true) { int op = find_dominant_operator(p, q); //printf("%d\n", op); int op_type = tokens[op].type; uint32_t val1, val2; if(op_type == NOT || op_type == DEREF) { val1 = eval(op+1, q, success); val2 = eval(op+1, q, success); } else { val1 = eval(p, op-1, success); val2 = eval(op+1, q, success); } switch(op_type) { case '+': return val1 + val2; case '-': return val1 - val2; case '*': return val1 * val2; case '/': return val1 / val2; case EQ: return val1 == val2; case UEQ: return val1 != val2; case AND: return val1 && val2; case OR: return val1 || val2; case NOT: return !val2; case DEREF: return swaddr_read(val2, 4,R_DS); default: *success = false; printf("Cannot evaluate expression!\n"); return 0; } } else { return 0; } }
u32int process_in_loc(farcpu *cpu, char *mem, u32int loc, u8int *madd) { input_location in = mem_get8(mem, loc); switch(in) { case REGISTER: *madd = *madd + 2; printf("REGISTER, "); return get_register(cpu, mem_get8(mem, loc + 1)); case NUMBER: *madd = *madd + 3; printf("NUMBER(%X), ", mem_get8(mem, loc + 1) << 8 | mem_get8(mem, loc + 2)); return mem_get8(mem, loc + 1) << 8 | mem_get8(mem, loc + 2); case IO: *madd = *madd + 1; printf("IO, "); return cpu->IO; case MEMORY: *madd = *madd + 5; printf("MEMORY, "); return mem_get8(mem, mem_get32(mem, loc + 1)); default: *madd = 1; printf("ERR:DEFAULT\n"); return 0; } }
int hll_merge(hll_t *hll_a, hll_t *hll_b, hll_t *merged_hll) { if (hll_a->precision != hll_b->precision) { return -1; } int reg = NUM_REG(hll_a->precision); int i; for(i = 0; i < reg; i++) { int a = get_register(hll_a, i); int b = get_register(hll_b, i); if (a + b > 0) { int mx = MAX(a, b); set_register(merged_hll, i, mx); } } return 0; }
void sti_op(t_proc *proc, t_op_arg args[3]) { int champ_number; int offset; int a; int b; a = get_value(proc, args, 1, 0); b = get_value(proc, args, 2, 0); if (g_corewar.reg_error) return ; offset = (a + b) % IDX_MOD; champ_number = 0; read_register(get_register(proc->reg, 1), (char *)&champ_number); write_register(get_register(proc->reg, args[0].value), proc->pc + offset, champ_number); }
void __single_step(void) { target_register_t msr = get_register(PS); target_register_t pc = get_register(PC); target_register_t next_pc = __branch_pc(pc); // Disable interrupts. irq_state = msr & MSR_EE; msr &= ~MSR_EE; put_register (PS, msr); // Set a breakpoint at the next instruction __insert_break(0, pc+4); if (next_pc != (pc+4)) { __insert_break(1, next_pc); } }
void __clear_single_step (void) { target_register_t sr = get_register (PS); // Clear single-step flag in the exception context. sr &= ~SR_TRACE; put_register (PS, sr); }
static void alloc_hw_reg(struct pair_state *s, GLuint file, GLuint index, GLuint hwindex) { struct pair_register_translation *t = get_register(s, file, index); ASSERT(!s->HwTemps[hwindex].RefCount); ASSERT(!t->Allocated); s->HwTemps[hwindex].RefCount = t->RefCount; t->Allocated = 1; t->HwIndex = hwindex; }
void __single_step (void) { target_register_t sr = get_register (PS); // Set trace flag in the exception context. sr |= SR_TRACE; put_register (PS, sr); }
// default address for pipe 0 is 0xe7e7e7e7e7 // default address for pipe 1 is 0xc2c2c2c2c2 // default address for pipe 2 is 0xc2c2c2c2c3 (disabled) // default address for pipe 3 is 0xc2c2c2c2c4 (disabled) // default address for pipe 4 is 0xc2c2c2c2c5 (disabled) // default address for pipe 5 is 0xc2c2c2c2c6 (disabled) void Radio_Configure_Rx(RADIO_PIPE pipe, uint8_t* address, uint8_t enable) { uint8_t value; uint8_t use_aa = 1; uint8_t payload_width = 32; if (payload_width < 1 || payload_width > 32 || pipe < RADIO_PIPE_0 || pipe > RADIO_PIPE_5) return; // store the pipe 0 address so that it can be overwritten when transmitting with auto-ack enabled. if (pipe == RADIO_PIPE_0) { rx_pipe0_address[0] = address[0]; rx_pipe0_address[1] = address[1]; rx_pipe0_address[2] = address[2]; rx_pipe0_address[3] = address[3]; rx_pipe0_address[4] = address[4]; } // Set the address. We set this stuff even if the pipe is being disabled, because for example the transmitter // needs pipe 0 to have the same address as the Tx address for auto-ack to work, even if pipe 0 is disabled. set_register(RX_ADDR_P0 + pipe, address, pipe > RADIO_PIPE_1 ? 1 : ADDRESS_LENGTH); // Set auto-ack. get_register(EN_AA, &value, 1); if (use_aa) value |= _BV(pipe); else value &= ~_BV(pipe); set_register(EN_AA, &value, 1); // Set the pipe's payload width. If the pipe is being disabled, then the payload width is set to 0. value = enable ? payload_width : 0; set_register(RX_PW_P0 + pipe, &value, 1); rx_pipe_widths[pipe] = value; // Enable or disable the pipe. get_register(EN_RXADDR, &value, 1); if (enable) value |= _BV(pipe); else value &= ~_BV(pipe); set_register(EN_RXADDR, &value, 1); }
int get_rvalue(int type, int val) { if (type == T_REG) { return (*get_register(val)); } else if (type == T_VAL) { return val; } else { fprintf(stderr, "unknown type: %d\n", type); return FAILURE; } }
S32 lsa_cmp_strings(U8 *buffer, S32 offset1, S32 offset2) { if (get_register(buffer, LREG_FR)) return 0; LLScriptLibData *string1; LLScriptLibData *string2; string1 = lsa_get_data(buffer, offset1, TRUE); string2 = lsa_get_data(buffer, offset2, TRUE); if ( (!string1) ||(!string2)) { set_fault(buffer, LSRF_HEAP_ERROR); delete string1; delete string2; return 0; } char *test1 = NULL, *test2 = NULL; if (string1->mType == LST_STRING) { test1 = string1->mString; } else if (string1->mType == LST_KEY) { test1 = string1->mKey; } if (string2->mType == LST_STRING) { test2 = string2->mString; } else if (string2->mType == LST_KEY) { test2 = string2->mKey; } if ( (!test1) ||(!test2)) { set_fault(buffer, LSRF_HEAP_ERROR); delete string1; delete string2; return 0; } S32 retval = strcmp(test1, test2); delete string1; delete string2; return retval; }