📄 uc.cc
字号:
int i; for (i= 0; i < mems->count; i++) { } }}*/voidcl_uc::address_space_added(class cl_address_space *as){ if (hws) hws->address_space_added(as); else printf("JAJ uc\n");//FIXME}/* * Error handling */voidcl_uc::error(class cl_error *error){ errors->add(error); if ((error->inst= inst_exec)) error->PC= instPC;}voidcl_uc::check_errors(void){ int i; class cl_commander *c= sim->app->get_commander(); bool must_stop= DD_FALSE; if (c) { for (i= 0; i < errors->count; i++) { class cl_error *error= (class cl_error *)(errors->at(i)); if (!error->is_on()) continue; error->print(c); must_stop= must_stop || (error->get_type() & err_stop); if (error->inst) { class cl_console *con; con= c->actual_console; if (!con) con= c->frozen_console; if (con) { con->dd_printf("Erronouse instruction: "); print_disass(error->PC, con); } } } errors->free_all(); } else fprintf(stderr, "no actual console, %d errors\n", errors->count); if (must_stop) sim->stop(resERROR);}/* * Converting bit address into real memory */class cl_address_space *cl_uc::bit2mem(t_addr bitaddr, t_addr *memaddr, t_mem *bitmask){ if (memaddr) *memaddr= bitaddr; if (bitmask) *bitmask= 1 << (bitaddr & 0x7); return(0); // abstract...}/* * Execution */intcl_uc::tick_hw(int cycles){ class cl_hw *hw; int i;//, cpc= clock_per_cycle(); // tick hws for (i= 0; i < hws->count; i++) { hw= (class cl_hw *)(hws->at(i)); if (hw->flags & HWF_INSIDE) hw->tick(cycles); } do_extra_hw(cycles); return(0);}voidcl_uc::do_extra_hw(int cycles){}intcl_uc::tick(int cycles){ //class cl_hw *hw; int i, cpc= clock_per_cycle(); // increase time ticks->tick(cycles * cpc); class it_level *il= (class it_level *)(it_levels->top()); if (il->level >= 0) isr_ticks->tick(cycles * cpc); if (state == stIDLE) idle_ticks->tick(cycles * cpc); for (i= 0; i < counters->count; i++) { class cl_ticker *t= (class cl_ticker *)(counters->at(i)); if (t) { if ((t->options&TICK_INISR) || il->level < 0) t->tick(cycles * cpc); } } // tick for hardwares inst_ticks+= cycles; return(0);}class cl_ticker *cl_uc::get_counter(int nr){ if (nr >= counters->count) return(0); return((class cl_ticker *)(counters->at(nr)));}class cl_ticker *cl_uc::get_counter(char *nam){ int i; if (!nam) return(0); for (i= 0; i < counters->count; i++) { class cl_ticker *t= (class cl_ticker *)(counters->at(i)); if (t && t->get_name() && strcmp(t->get_name(), nam) == 0) return(t); } return(0);}voidcl_uc::add_counter(class cl_ticker *ticker, int nr){ while (counters->count <= nr) counters->add(0); counters->put_at(nr, ticker);}voidcl_uc::add_counter(class cl_ticker *ticker, char */*nam*/){ int i; if (counters->count < 1) counters->add(0); for (i= 1; i < counters->count; i++) { class cl_ticker *t= (class cl_ticker *)(counters->at(i)); if (!t) { counters->put_at(i, ticker); return; } } counters->add(ticker);}voidcl_uc::del_counter(int nr){ class cl_ticker *t; if (nr >= counters->count) return; if ((t= (class cl_ticker *)(counters->at(0))) != 0) delete t; counters->put_at(nr, 0);}voidcl_uc::del_counter(char *nam){ int i; if (!nam) return; for (i= 0; i < counters->count; i++) { class cl_ticker *t= (class cl_ticker *)(counters->at(i)); if (t && t->get_name() && strcmp(t->get_name(), nam) == 0) { delete t; counters->put_at(i, 0); return; } }}/* * Fetch without checking for breakpoint hit */t_memcl_uc::fetch(void){ ulong code; if (!rom) return(0); code= rom->read(PC); PC= rom->inc_address(PC); return(code);}/* * Fetch but checking for breakpoint hit first, returns TRUE if * a breakpoint is hit */boolcl_uc::fetch(t_mem *code){ class cl_brk *brk; int idx; if (!code) return(0); if ((sim->state & SIM_GO) && rom) { if (rom->get_cell_flag(PC, CELL_FETCH_BRK) && (brk= fbrk->get_bp(PC, &idx)) && (brk->do_hit())) { if (brk->perm == brkDYNAMIC) fbrk->del_bp(PC); return(1); } } *code= fetch(); return(0);}intcl_uc::do_inst(int step){ int res= resGO; if (step < 0) step= 1; while (step-- && res == resGO) { pre_inst(); res= exec_inst(); post_inst(); } if (res != resGO) sim->stop(res); return(res);}voidcl_uc::pre_inst(void){ inst_exec= DD_TRUE; inst_ticks= 0; events->disconn_all();}intcl_uc::exec_inst(void){ instPC= PC; return(resGO);}voidcl_uc::post_inst(void){ tick_hw(inst_ticks); if (errors->count) check_errors(); if (events->count) check_events(); inst_exec= DD_FALSE;}/* * Time related functions */doublecl_uc::get_rtime(void){ /* double d; d= (double)ticks/xtal; return(d);*/ return(ticks->get_rtime(xtal));}intcl_uc::clock_per_cycle(void){ return(1);}/* * Stack tracking system */voidcl_uc::stack_write(class cl_stack_op *op){ if (op->get_op() & stack_read_operation) { class cl_error_stack_tracker_wrong_handle *e= new cl_error_stack_tracker_wrong_handle(DD_FALSE); //fprintf(stderr, "%06"_A_"x cl_uc::stack_read() should be called for " //"%s\n", op->get_pc(), op->get_op_name()); e->init(); error(e); return; } stack_ops->push(op);}voidcl_uc::stack_read(class cl_stack_op *op){ class cl_stack_op *top= (class cl_stack_op *)(stack_ops->top()); if (op->get_op() & stack_write_operation) { class cl_error_stack_tracker_wrong_handle *e= new cl_error_stack_tracker_wrong_handle(DD_TRUE); e->init(); error(e); //fprintf(stderr, "%06"_A_"x cl_uc::stack_write() should be called for " //"%s\n", op->get_pc(), op->get_op_name()); return; } if (!top) { class cl_error *e= new cl_error_stack_tracker_empty(op); /*printf("0x%06"_A_"x %s operation on stack but no operation was before\n ", op->get_pc(), op->get_op_name());*/ e->init(); error(e); return; } if (top) { if (!top->match(op)) { class cl_error *e= new cl_error_stack_tracker_unmatch(top, op); e->init(); error(e); /*printf("0x%06"_A_"x %s operation on stack but last was %s\n", op->get_pc(), op->get_op_name(), top->get_op_name());*/ } int top_size= top->data_size(), op_size= op->data_size(); if (top_size != op_size) { application->debug("0x%06"_A_"x %d bytes to read out of stack " "but %d was pushed in last operation\n", op->get_pc(), op_size, top_size); } } int removed= 0; while (top && top->can_removed(op)) { top= (class cl_stack_op *)stack_ops->pop(); delete top; top= (class cl_stack_op *)stack_ops->top(); removed++; } if (removed != 1) { application->debug("0x%06"_A_"x %d ops removed from stack-tracker " "when %s happened, top pc=0x%06"_A_"x " "top before=0x%06"_A_"x op after=0x%06"_A_"x\n", op->get_pc(), removed, op->get_op_name(), top?(top->get_pc()):0, top?(top->get_before()):0, op->get_after()); } if (top) { int ta= top->get_after(), oa= op->get_after(); if (ta != oa) { application->debug("0x%06"_A_"x stack still inconsistent after %s, " "%d byte(s) should be read out; top after" "=0x%06"_A_"x op after=0x%06"_A_"x\n", op->get_pc(), op->get_op_name(), abs(ta-oa), ta, oa); class cl_error *e= new cl_error_stack_tracker_inconsistent(op, abs(ta-oa)); e->init(); error(e); } } delete op;}/* * Breakpoint handling */class cl_fetch_brk *cl_uc::fbrk_at(t_addr addr){ int idx; return((class cl_fetch_brk *)(fbrk->get_bp(addr, &idx)));}class cl_ev_brk *cl_uc::ebrk_at(t_addr addr, char *id){ int i; class cl_ev_brk *eb; for (i= 0; i < ebrk->count; i++) { eb= (class cl_ev_brk *)(ebrk->at(i)); if (eb->addr == addr && !strcmp(eb->id, id)) return(eb); } return(0);}/*voidcl_uc::rm_fbrk(long addr){ fbrk->del_bp(addr);}*//* Get a breakpoint specified by its number */class cl_brk *cl_uc::brk_by_nr(int nr){ class cl_brk *bp; if ((bp= fbrk->get_bp(nr))) return(bp); if ((bp= ebrk->get_bp(nr))) return(bp); return(0);}/* Get a breakpoint from the specified collection by its number */class cl_brk *cl_uc::brk_by_nr(class brk_coll *bpcoll, int nr){ class cl_brk *bp; if ((bp= bpcoll->get_bp(nr))) return(bp); return(0);}/* Remove an event breakpoint specified by its address and id */voidcl_uc::rm_ebrk(t_addr addr, char *id){ int i; class cl_ev_brk *eb; for (i= 0; i < ebrk->count; i++) { eb= (class cl_ev_brk *)(ebrk->at(i)); if (eb->addr == addr && !strcmp(eb->id, id)) ebrk->del_bp(i, 0); }}/* Remove a breakpoint specified by its number */boolcl_uc::rm_brk(int nr){ class cl_brk *bp; if ((bp= brk_by_nr(fbrk, nr))) { fbrk->del_bp(bp->addr); return(DD_TRUE); } else if ((bp= brk_by_nr(ebrk, nr))) { ebrk->del_bp(ebrk->index_of(bp), 0); return(DD_TRUE); } return(DD_FALSE);}voidcl_uc::put_breaks(void){}/* Remove all fetch and event breakpoints */voidcl_uc::remove_all_breaks(void){ while (fbrk->count) { class cl_brk *brk= (class cl_brk *)(fbrk->at(0)); fbrk->del_bp(brk->addr); } while (ebrk->count) ebrk->del_bp(ebrk->count-1, 0);}intcl_uc::make_new_brknr(void){ if (brk_counter == 0) return(brk_counter= 1); if (fbrk->count == 0 && ebrk->count == 0) return(brk_counter= 1); return(++brk_counter);}class cl_ev_brk *cl_uc::mk_ebrk(enum brk_perm perm, class cl_address_space *mem, char op, t_addr addr, int hit){ class cl_ev_brk *b; op= toupper(op); b= new cl_ev_brk(mem, make_new_brknr(), addr, perm, hit, op); b->init(); return(b);}voidcl_uc::check_events(void){ int i; for (i= 0; i < events->count; i++) { class cl_ev_brk *brk= dynamic_cast<class cl_ev_brk *>(events->object_at(i)); sim->stop(brk); } sim->stop(resBREAKPOINT);}/* * Errors *---------------------------------------------------------------------------- */cl_error_unknown_code::cl_error_unknown_code(class cl_uc *the_uc){ uc= the_uc; classification= uc_error_registry.find("unknown_code");}voidcl_error_unknown_code::print(class cl_commander *c){ FILE *f= c->get_out(); cmd_fprintf(f, "%s: unknown instruction code at ", get_type_name()); if (uc->rom) { cmd_fprintf(f, uc->rom->addr_format, PC); cmd_fprintf(f, " ("); cmd_fprintf(f, uc->rom->data_format, uc->rom->get(PC)); cmd_fprintf(f, ")"); } else cmd_fprintf(f, "0x%06x", PC); cmd_fprintf(f, "\n");}cl_uc_error_registry::cl_uc_error_registry(void){ class cl_error_class *prev = uc_error_registry.find("non-classified"); prev = register_error(new cl_error_class(err_error, "unknown_code", prev, ERROR_OFF));}/* End of uc.cc */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -