Beispiel #1
0
void doStuff(InstInfo* FI, InstInfo* DI, InstInfo* XI, InstInfo* MI, InstInfo* WI) {
  //fetch(FI);
  //printf("%s\n", FI->string);
  decode(DI);
  execute(XI);
  memory(MI);
  writeback(WI); 
  setPCWithInfo(MI);
}
Beispiel #2
0
/*
 * trap and syscall both need the following work done before returning
 * to user mode.
 */
static inline void
userret(struct lwp *l, struct frame *fp, u_quad_t oticks, u_int faultaddr,
    int fromtrap)
{
	struct proc *p = l->l_proc;
#ifdef M68040
	int sig;
	int beenhere = 0;

again:
#endif
	/* Invoke MI userret code */
	mi_userret(l);

	/*
	 * If profiling, charge system time to the trapped pc.
	 */
	if (p->p_stflag & PST_PROFIL) {
		extern int psratio;

		addupc_task(l, fp->f_pc,
			    (int)(p->p_sticks - oticks) * psratio);
	}
#ifdef M68040
	/*
	 * Deal with user mode writebacks (from trap, or from sigreturn).
	 * If any writeback fails, go back and attempt signal delivery.
	 * unless we have already been here and attempted the writeback
	 * (e.g. bad address with user ignoring SIGSEGV).  In that case
	 * we just return to the user without successfully completing
	 * the writebacks.  Maybe we should just drop the sucker?
	 */
	if (cputype == CPU_68040 && fp->f_format == FMT7) {
		if (beenhere) {
#ifdef DEBUG
			if (mmudebug & MDB_WBFAILED)
				printf(fromtrap ?
		"pid %d(%s): writeback aborted, pc=%x, fa=%x\n" :
		"pid %d(%s): writeback aborted in sigreturn, pc=%x\n",
				    p->p_pid, p->p_comm, fp->f_pc, faultaddr);
#endif
		} else if ((sig = writeback(fp, fromtrap))) {
			ksiginfo_t ksi;
			beenhere = 1;
			oticks = p->p_sticks;
			(void)memset(&ksi, 0, sizeof(ksi));
			ksi.ksi_signo = sig;
			ksi.ksi_addr = (void *)faultaddr;
			ksi.ksi_code = BUS_OBJERR;
			trapsignal(l, &ksi);
			goto again;
		}
	}
#endif
}
Beispiel #3
0
std::set<std::string> filelist::enumerate()
{
	auto contents = readfile();
	check_stale(contents);
	writeback(contents);
	std::set<std::string> ret;
	for(auto i : contents)
		if(i.second != 0)
			ret.insert(i.first);
	return ret;
}
Beispiel #4
0
/* start simulation, program loaded, processor precise state initialized */
void sim_main(void)
{
    cpen411_init();

    do {
        writeback();
        memory();
        execute();
        decode();
        fetch();

        sim_cycle++;
    } while (!max_insts || sim_num_insn < max_insts);
}
Beispiel #5
0
void doStage(int isFirst, int *stall, int * cycles, int * counter)
{
	if(pipelineInsts[4]->inst!=0){
		if(debug)printf("DEBUG: writing back\n");
		writeback(pipelineInsts[4]);
	}

	if(pipelineInsts[3]->inst!=0){
		if(debug)printf("DEBUG: memorying\n");
		memory(pipelineInsts[3]);
	}
	// if stall is being set, no need to call any of fowllowing functions
	if(!*stall){
		if(debug)printf("DEBUG: no stall...........\n");
		if(pipelineInsts[2]->inst!=0){
			if(debug)printf("DEBUG: executing\n");
			forwardData(pipelineInsts);	// forward data before execute

			if(debug)printf("DEBUG: instruction is about to get executed: %s\n", pipelineInsts[2]->string);
			execute(pipelineInsts[2]);
		}
		if(pipelineInsts[1]->inst!=0){
			if(debug)printf("DEBUG: decoding\n");

			
			decode(pipelineInsts[1]);
			
			setDependency(pipelineInsts, stall);	// set dependencies after decode

			// if cur inst is bge
			if(pipelineInsts[1]->signals.btype != 0){
				if(debug)printf("DEBUG: calling doBranching\n");
				doBranching(pipelineInsts, stall, cycles, counter);
			}
		}
	}
	if(pipelineInsts[0]->inst!=0 || isFirst){
		if(debug)printf("DEBUG: fetching\n");

		fetch(pipelineInsts[0]);
		if(*stall){		// when stall is being set, needs to defetch one instruction
			/*if(pipelineInsts[1]->signals.btype == 2){
				if(pipelineInsts[2]->aluout >= 0)
					pc = pc + pipelineInsts[1]->imm + 1;
			}*/
			defetch(pipelineInsts[0]);
		}
	}
}
Beispiel #6
0
int
main(int argc, char *argv[]) {
  state_t *state;
  int data_count;
  int commit_ret, dispatch_ret;
  int num_insn, i;
  int commit_status, areBuffersFull = 0;

  parse_args(argc, argv);
  state = state_create(&data_count, bin_file, fu_file, wbpi, wbpf);

  if (state == NULL) {
    fclose(bin_file);
    fclose(fu_file);
    return -1;
  }

  fclose(bin_file);
  fclose(fu_file);

  /* main sim loop */
  for (i = 0, num_insn = 0; TRUE; i++) {

    printf("\n\n*** CYCLE %d\n", i);
    print_state(state, data_count);
    
    commit_status = commit(state);
    if(commit_status != 0) num_insn++;
    if(commit_status == -1) break;
    writeback(state);
    execute(state);
    memory_disambiguation(state);
    issue(state);
    if (!(state->fetch_lock)) {
      areBuffersFull = dispatch(state);
      if(areBuffersFull != -1) fetch(state);
    }
  }

  printf("SIMULATION COMPLETE!\n");
  printf("COMMITTED %d INSTRUCTIONS IN %d CYCLES\n", num_insn, i);
  printf("CPI:  %.2f\n", (float)i / (float)num_insn);

  return 0;
}
void GPR_Machine::processInstruction() {
	multicycle = true;
	//determine type of instruction
	instr = m_current_instruction;

	//backups
	latch_fetch_decode_old = latch_fetch_decode_new;
	latch_fetch_decode_new.current_instruction = instr; //set instruction

	latch_decode_execute_old = latch_decode_execute_new;
	latch_decode_execute_new = decode(); //decode

	latch_execute_memory_old = latch_execute_memory_new;
	latch_execute_memory_new = executeInstruction(); //execute

	latch_memory_writeback_old = latch_memory_writeback_new;
	latch_memory_writeback_new = pipelineMemory(); //memory

	//writeback
	int result = writeback(); 
}
int main(int argc, char** argv) {
  DataStoreNodeTemplate tlb_stat("tlb_stat"); {
    tlb_stat.summable = 1;
    tlb_stat.addint("hits");
    tlb_stat.addint("misses");
  }
  DataStoreNodeTemplate PerContextOutOfOrderCoreStats("PerContextOutOfOrderCoreStats"); {
    DataStoreNodeTemplate& fetch = PerContextOutOfOrderCoreStats("fetch"); {
      DataStoreNodeTemplate& stop = fetch("stop"); {
        stop.summable = 1;
        stop.addint("stalled");
        stop.addint("icache_miss");
        stop.addint("fetchq_full");
        stop.addint("issueq_quota_full");
        stop.addint("bogus_rip");
        stop.addint("microcode_assist");
        stop.addint("branch_taken");
        stop.addint("full_width");
        stop.addint("icache_stalled");
        stop.addint("invalid_blocks");
      }
      fetch.histogram("opclass", 29, opclass_names);
      fetch.histogram("width", OutOfOrderModel::FETCH_WIDTH+1, 0, OutOfOrderModel::FETCH_WIDTH, 1);
      fetch.addint("blocks");
      fetch.addint("uops");
      fetch.addint("user_insns");
    }
    DataStoreNodeTemplate& frontend = PerContextOutOfOrderCoreStats("frontend"); {
      DataStoreNodeTemplate& status = frontend("status"); {
        status.summable = 1;
        status.addint("complete");
        status.addint("fetchq_empty");
        status.addint("rob_full");
        status.addint("physregs_full");
        status.addint("ldq_full");
        status.addint("stq_full");
      }
      frontend.histogram("width", OutOfOrderModel::FRONTEND_WIDTH+1, 0, OutOfOrderModel::FRONTEND_WIDTH, 1);
      DataStoreNodeTemplate& renamed = frontend("renamed"); {
        renamed.addint("none");
        renamed.addint("reg");
        renamed.addint("flags");
        renamed.addint("reg_and_flags");
      }
      DataStoreNodeTemplate& alloc = frontend("alloc"); {
        alloc.addint("reg");
        alloc.addint("ldreg");
        alloc.addint("sfr");
        alloc.addint("br");
      }
      frontend.histogram("consumer_count", 256, 0, 255, 1);
    }
    DataStoreNodeTemplate& dispatch = PerContextOutOfOrderCoreStats("dispatch"); {
      dispatch.histogram("cluster", OutOfOrderModel::MAX_CLUSTERS, OutOfOrderModel::cluster_names);
      DataStoreNodeTemplate& redispatch = dispatch("redispatch"); {
        redispatch.addint("trigger_uops");
        redispatch.addint("deadlock_flushes");
        redispatch.addint("deadlock_uops_flushed");
        redispatch.histogram("dependent_uops", OutOfOrderModel::ROB_SIZE+1, 0, OutOfOrderModel::ROB_SIZE, 1);
      }
    }
    DataStoreNodeTemplate& issue = PerContextOutOfOrderCoreStats("issue"); {
      issue.addint("uops");
      issue.addfloat("uipc");
      DataStoreNodeTemplate& result = issue("result"); {
        result.summable = 1;
        result.addint("no_fu");
        result.addint("replay");
        result.addint("misspeculated");
        result.addint("refetch");
        result.addint("branch_mispredict");
        result.addint("exception");
        result.addint("complete");
      }
      issue.histogram("opclass", 29, opclass_names);
    }
    DataStoreNodeTemplate& writeback = PerContextOutOfOrderCoreStats("writeback"); {
      writeback.histogram("writebacks", OutOfOrderModel::PHYS_REG_FILE_COUNT, OutOfOrderModel::phys_reg_file_names);
    }
    DataStoreNodeTemplate& commit = PerContextOutOfOrderCoreStats("commit"); {
      commit.addint("uops");
      commit.addint("insns");
      commit.addfloat("uipc");
      commit.addfloat("ipc");
      DataStoreNodeTemplate& result = commit("result"); {
        result.summable = 1;
        result.addint("none");
        result.addint("ok");
        result.addint("exception");
        result.addint("skipblock");
        result.addint("barrier");
        result.addint("smc");
        result.addint("memlocked");
        result.addint("stop");
        result.addint("dcache_stall");
      }
      DataStoreNodeTemplate& fail = commit("fail"); {
        fail.summable = 1;
        fail.addint("free_list");
        fail.addint("frontend_list");
        fail.addint("ready_to_dispatch_list");
        fail.addint("dispatched_list");
        fail.addint("ready_to_issue_list");
        fail.addint("ready_to_store_list");
        fail.addint("ready_to_load_list");
        fail.addint("issued_list");
        fail.addint("completed_list");
        fail.addint("ready_to_writeback_list");
        fail.addint("cache_miss_list");
        fail.addint("tlb_miss_list");
        fail.addint("memory_fence_list");
        fail.addint("ready_to_commit_queue");
      }
      DataStoreNodeTemplate& setflags = commit("setflags"); {
        setflags.summable = 1;
        setflags.addint("yes");
        setflags.addint("no");
      }
      commit.histogram("opclass", 29, opclass_names);
    }
    DataStoreNodeTemplate& branchpred = PerContextOutOfOrderCoreStats("branchpred"); {
      branchpred.addint("predictions");
      branchpred.addint("updates");
      branchpred.histogram("cond", 2, branchpred_outcome_names);
      branchpred.histogram("indir", 2, branchpred_outcome_names);
      branchpred.histogram("ret", 2, branchpred_outcome_names);
      branchpred.histogram("summary", 2, branchpred_outcome_names);
      DataStoreNodeTemplate& ras = branchpred("ras"); {
        ras.summable = 1;
        ras.addint("pushes");
        ras.addint("overflows");
        ras.addint("pops");
        ras.addint("underflows");
        ras.addint("annuls");
      }
    }
    DataStoreNodeTemplate& dcache = PerContextOutOfOrderCoreStats("dcache"); {
      DataStoreNodeTemplate& load = dcache("load"); {
        DataStoreNodeTemplate& issue = load("issue"); {
          issue.summable = 1;
          issue.addint("complete");
          issue.addint("miss");
          issue.addint("exception");
          issue.addint("ordering");
          issue.addint("unaligned");
          DataStoreNodeTemplate& replay = issue("replay"); {
            replay.summable = 1;
            replay.addint("sfr_addr_and_data_not_ready");
            replay.addint("sfr_addr_not_ready");
            replay.addint("sfr_data_not_ready");
            replay.addint("missbuf_full");
            replay.addint("interlocked");
            replay.addint("interlock_overflow");
            replay.addint("fence");
            replay.addint("bank_conflict");
            replay.addint("dcache_stall");
          }
        }
        DataStoreNodeTemplate& forward = load("forward"); {
          forward.summable = 1;
          forward.addint("cache");
          forward.addint("sfr");
          forward.addint("sfr_and_cache");
        }
        DataStoreNodeTemplate& dependency = load("dependency"); {
          dependency.summable = 1;
          dependency.addint("independent");
          dependency.addint("predicted_alias_unresolved");
          dependency.addint("stq_address_match");
          dependency.addint("stq_address_not_ready");
          dependency.addint("fence");
          dependency.addint("mmio");
        }
        DataStoreNodeTemplate& type = load("type"); {
          type.summable = 1;
          type.addint("aligned");
          type.addint("unaligned");
          type.addint("internal");
        }
        load.histogram("size", 4, sizeshift_names);
        load.histogram("datatype", DATATYPE_COUNT, datatype_names);
      }
      DataStoreNodeTemplate& store = dcache("store"); {
        DataStoreNodeTemplate& issue = store("issue"); {
          issue.summable = 1;
          issue.addint("complete");
          issue.addint("exception");
          issue.addint("ordering");
          issue.addint("unaligned");
          DataStoreNodeTemplate& replay = issue("replay"); {
            replay.summable = 1;
            replay.addint("sfr_addr_and_data_not_ready");
            replay.addint("sfr_addr_not_ready");
            replay.addint("sfr_data_not_ready");
            replay.addint("sfr_addr_and_data_and_data_to_store_not_ready");
            replay.addint("sfr_addr_and_data_to_store_not_ready");
            replay.addint("sfr_data_and_data_to_store_not_ready");
            replay.addint("interlocked");
            replay.addint("fence");
            replay.addint("parallel_aliasing");
            replay.addint("bank_conflict");
          }
        }
        DataStoreNodeTemplate& forward = store("forward"); {
          forward.summable = 1;
          forward.addint("zero");
          forward.addint("sfr");
        }
        DataStoreNodeTemplate& type = store("type"); {
          type.summable = 1;
          type.addint("aligned");
          type.addint("unaligned");
          type.addint("internal");
        }
        store.histogram("size", 4, sizeshift_names);
        store.histogram("datatype", DATATYPE_COUNT, datatype_names);
      }
      DataStoreNodeTemplate& fence = dcache("fence"); {
        fence.summable = 1;
        fence.addint("lfence");
        fence.addint("sfence");
        fence.addint("mfence");
      }
      dcache.add("dtlb", tlb_stat);
      dcache.add("itlb", tlb_stat);
      dcache.histogram("dtlb_latency", 1001, 0, 200, 1);
      dcache.histogram("itlb_latency", 1001, 0, 200, 1);
    }
    PerContextOutOfOrderCoreStats.addint("interrupt_requests");
    PerContextOutOfOrderCoreStats.addint("cpu_exit_requests");
    PerContextOutOfOrderCoreStats.addint("cycles_in_pause");
  }
  DataStoreNodeTemplate OutOfOrderCoreStats("OutOfOrderCoreStats"); {
    OutOfOrderCoreStats.addint("cycles");
    DataStoreNodeTemplate& dispatch = OutOfOrderCoreStats("dispatch"); {
      DataStoreNodeTemplate& source = dispatch("source"); {
        source.summable = 1;
        source.histogram("integer", OutOfOrderModel::MAX_PHYSREG_STATE, OutOfOrderModel::physreg_state_names);
        source.histogram("fp", OutOfOrderModel::MAX_PHYSREG_STATE, OutOfOrderModel::physreg_state_names);
        source.histogram("st", OutOfOrderModel::MAX_PHYSREG_STATE, OutOfOrderModel::physreg_state_names);
        source.histogram("br", OutOfOrderModel::MAX_PHYSREG_STATE, OutOfOrderModel::physreg_state_names);
      }
      dispatch.histogram("width", OutOfOrderModel::DISPATCH_WIDTH+1, 0, OutOfOrderModel::DISPATCH_WIDTH, 1);
    }
    DataStoreNodeTemplate& issue = OutOfOrderCoreStats("issue"); {
      DataStoreNodeTemplate& source = issue("source"); {
        source.summable = 1;
        source.histogram("integer", OutOfOrderModel::MAX_PHYSREG_STATE, OutOfOrderModel::physreg_state_names);
        source.histogram("fp", OutOfOrderModel::MAX_PHYSREG_STATE, OutOfOrderModel::physreg_state_names);
        source.histogram("st", OutOfOrderModel::MAX_PHYSREG_STATE, OutOfOrderModel::physreg_state_names);
        source.histogram("br", OutOfOrderModel::MAX_PHYSREG_STATE, OutOfOrderModel::physreg_state_names);
      }
      DataStoreNodeTemplate& width = issue("width"); {
        width.histogram("all", OutOfOrderModel::MAX_ISSUE_WIDTH+1, 0, OutOfOrderModel::MAX_ISSUE_WIDTH, 1);
      }
    }
    DataStoreNodeTemplate& writeback = OutOfOrderCoreStats("writeback"); {
      DataStoreNodeTemplate& width = writeback("width"); {
        width.histogram("all", OutOfOrderModel::MAX_ISSUE_WIDTH+1, 0, OutOfOrderModel::MAX_ISSUE_WIDTH, 1);
      }
    }
    DataStoreNodeTemplate& commit = OutOfOrderCoreStats("commit"); {
      DataStoreNodeTemplate& freereg = commit("freereg"); {
        freereg.summable = 1;
        freereg.addint("pending");
        freereg.addint("free");
      }
      commit.addint("free_regs_recycled");
      commit.histogram("width", OutOfOrderModel::COMMIT_WIDTH+1, 0, OutOfOrderModel::COMMIT_WIDTH, 1);
    }
    DataStoreNodeTemplate& branchpred = OutOfOrderCoreStats("branchpred"); {
      branchpred.addint("predictions");
      branchpred.addint("updates");
      branchpred.histogram("cond", 2, branchpred_outcome_names);
      branchpred.histogram("indir", 2, branchpred_outcome_names);
      branchpred.histogram("ret", 2, branchpred_outcome_names);
      branchpred.histogram("summary", 2, branchpred_outcome_names);
      DataStoreNodeTemplate& ras = branchpred("ras"); {
        ras.summable = 1;
        ras.addint("pushes");
        ras.addint("overflows");
        ras.addint("pops");
        ras.addint("underflows");
        ras.addint("annuls");
      }
    }
    OutOfOrderCoreStats.add("total", PerContextOutOfOrderCoreStats);
    OutOfOrderCoreStats.add("vcpu0", PerContextOutOfOrderCoreStats);
    OutOfOrderCoreStats.add("vcpu1", PerContextOutOfOrderCoreStats);
    OutOfOrderCoreStats.add("vcpu2", PerContextOutOfOrderCoreStats);
    OutOfOrderCoreStats.add("vcpu3", PerContextOutOfOrderCoreStats);
    DataStoreNodeTemplate& simulator = OutOfOrderCoreStats("simulator"); {
      simulator.addfloat("total_time");
      DataStoreNodeTemplate& cputime = simulator("cputime"); {
        cputime.summable = 1;
        cputime.addfloat("fetch");
        cputime.addfloat("decode");
        cputime.addfloat("rename");
        cputime.addfloat("frontend");
        cputime.addfloat("dispatch");
        cputime.addfloat("issue");
        cputime.addfloat("issueload");
        cputime.addfloat("issuestore");
        cputime.addfloat("complete");
        cputime.addfloat("transfer");
        cputime.addfloat("writeback");
        cputime.addfloat("commit");
      }
    }
  }
  DataStoreNodeTemplate PerContextDataCacheStats("PerContextDataCacheStats"); {
    DataStoreNodeTemplate& load = PerContextDataCacheStats("load"); {
      DataStoreNodeTemplate& hit = load("hit"); {
        hit.summable = 1;
        hit.addint("L1");
        hit.addint("L2");
        hit.addint("L3");
        hit.addint("mem");
      }
      DataStoreNodeTemplate& dtlb = load("dtlb"); {
        dtlb.summable = 1;
        dtlb.addint("hits");
        dtlb.addint("misses");
      }
      DataStoreNodeTemplate& tlbwalk = load("tlbwalk"); {
        tlbwalk.summable = 1;
        tlbwalk.addint("L1_dcache_hit");
        tlbwalk.addint("L1_dcache_miss");
        tlbwalk.addint("no_lfrq_mb");
      }
    }
    DataStoreNodeTemplate& fetch = PerContextDataCacheStats("fetch"); {
      DataStoreNodeTemplate& hit = fetch("hit"); {
        hit.summable = 1;
        hit.addint("L1");
        hit.addint("L2");
        hit.addint("L3");
        hit.addint("mem");
      }
      DataStoreNodeTemplate& itlb = fetch("itlb"); {
        itlb.summable = 1;
        itlb.addint("hits");
        itlb.addint("misses");
      }
      DataStoreNodeTemplate& tlbwalk = fetch("tlbwalk"); {
        tlbwalk.summable = 1;
        tlbwalk.addint("L1_dcache_hit");
        tlbwalk.addint("L1_dcache_miss");
        tlbwalk.addint("no_lfrq_mb");
      }
    }
    DataStoreNodeTemplate& store = PerContextDataCacheStats("store"); {
      store.addint("prefetches");
    }
  }
  DataStoreNodeTemplate DataCacheStats("DataCacheStats"); {
    DataStoreNodeTemplate& load = DataCacheStats("load"); {
      DataStoreNodeTemplate& transfer = load("transfer"); {
        transfer.summable = 1;
        transfer.addint("L2_to_L1_full");
        transfer.addint("L2_to_L1_partial");
        transfer.addint("L2_L1I_full");
      }
    }
    DataStoreNodeTemplate& missbuf = DataCacheStats("missbuf"); {
      missbuf.addint("inserts");
      DataStoreNodeTemplate& deliver = missbuf("deliver"); {
        deliver.summable = 1;
        deliver.addint("mem_to_L3");
        deliver.addint("L3_to_L2");
        deliver.addint("L2_to_L1D");
        deliver.addint("L2_to_L1I");
      }
    }
    DataStoreNodeTemplate& prefetch = DataCacheStats("prefetch"); {
      prefetch.summable = 1;
      prefetch.addint("in_L1");
      prefetch.addint("in_L2");
      prefetch.addint("required");
    }
    DataStoreNodeTemplate& lfrq = DataCacheStats("lfrq"); {
      lfrq.addint("inserts");
      lfrq.addint("wakeups");
      lfrq.addint("annuls");
      lfrq.addint("resets");
      lfrq.addint("total_latency");
      lfrq.addfloat("average_latency");
      lfrq.histogram("width", CacheSubsystem::MAX_WAKEUPS_PER_CYCLE+1, 0, CacheSubsystem::MAX_WAKEUPS_PER_CYCLE+1, 1);
    }
    DataCacheStats.add("total", PerContextDataCacheStats);
    DataCacheStats.add("vcpu0", PerContextDataCacheStats);
    DataCacheStats.add("vcpu1", PerContextDataCacheStats);
    DataCacheStats.add("vcpu2", PerContextDataCacheStats);
    DataCacheStats.add("vcpu3", PerContextDataCacheStats);
  }
  DataStoreNodeTemplate stall_sub("stall_sub"); {
    stall_sub.summable = 1;
    stall_sub.addint("dependency");
    stall_sub.addint("cache_port");
    stall_sub.addint("buffer_full");
  }
  DataStoreNodeTemplate CacheStats("CacheStats"); {
    DataStoreNodeTemplate& cpurequest = CacheStats("cpurequest"); {
      DataStoreNodeTemplate& count = cpurequest("count"); {
        count.summable = 1;
        DataStoreNodeTemplate& hit = count("hit"); {
          DataStoreNodeTemplate& read = hit("read"); {
            read.summable = 1;
            DataStoreNodeTemplate& hit = read("hit"); {
              hit.summable = 1;
              hit.addint("hit");
              hit.addint("forward");
            }
          }
          DataStoreNodeTemplate& write = hit("write"); {
            write.summable = 1;
            DataStoreNodeTemplate& hit = write("hit"); {
              hit.summable = 1;
              hit.addint("hit");
              hit.addint("forward");
            }
          }
        }
        DataStoreNodeTemplate& miss = count("miss"); {
          miss.summable = 1;
          miss.addint("read");
          miss.addint("write");
        }
      }
      DataStoreNodeTemplate& stall = cpurequest("stall"); {
        stall.summable = 1;
        stall.add("read", stall_sub);
        stall.add("write", stall_sub);
      }
      cpurequest.addint("redirects");
    }
    DataStoreNodeTemplate& snooprequest = CacheStats("snooprequest"); {
      snooprequest.summable = 1;
      snooprequest.addint("hit");
      snooprequest.addint("miss");
    }
    CacheStats.addint("annul");
    CacheStats.addint("queueFull");
    DataStoreNodeTemplate& latency = CacheStats("latency"); {
      latency.summable = 1;
      latency.addint("IF");
      latency.addint("load");
      latency.addint("store");
    }
    DataStoreNodeTemplate& lat_count = CacheStats("lat_count"); {
      lat_count.summable = 1;
      lat_count.addint("IF");
      lat_count.addint("load");
      lat_count.addint("store");
    }
    DataStoreNodeTemplate& mesi_stats = CacheStats("mesi_stats"); {
      DataStoreNodeTemplate& hit_state = mesi_stats("hit_state"); {
        hit_state.summable = 1;
        hit_state.histogram("snoop", 5, 0, 4, 1);
        hit_state.histogram("cpu", 5, 0, 4, 1);
      }
      mesi_stats.histogram("state_transition", 17, 0, 16, 1);
    }
  }
  DataStoreNodeTemplate PerCoreCacheStats("PerCoreCacheStats"); {
    PerCoreCacheStats.add("CPUController", CacheStats);
    PerCoreCacheStats.add("L1I", CacheStats);
    PerCoreCacheStats.add("L1D", CacheStats);
    PerCoreCacheStats.add("L2", CacheStats);
    PerCoreCacheStats.add("L3", CacheStats);
  }
  DataStoreNodeTemplate BusStats("BusStats"); {
    DataStoreNodeTemplate& broadcasts = BusStats("broadcasts"); {
      broadcasts.summable = 1;
      broadcasts.addint("read");
      broadcasts.addint("write");
      broadcasts.addint("update");
    }
    DataStoreNodeTemplate& broadcast_cycles = BusStats("broadcast_cycles"); {
      broadcast_cycles.summable = 1;
      broadcast_cycles.addint("read");
      broadcast_cycles.addint("write");
      broadcast_cycles.addint("update");
    }
    BusStats.addint("addr_bus_cycles");
    BusStats.addint("data_bus_cycles");
  }
  DataStoreNodeTemplate EventsInMode("EventsInMode"); {
    EventsInMode.summable = 1;
    EventsInMode.addint("user64");
    EventsInMode.addint("user32");
    EventsInMode.addint("kernel64");
    EventsInMode.addint("kernel32");
    EventsInMode.addint("legacy16");
    EventsInMode.addint("userlib");
    EventsInMode.addint("microcode");
    EventsInMode.addint("idle");
  }
  DataStoreNodeTemplate PerCoreEvents("PerCoreEvents"); {
    PerCoreEvents.add("cycles_in_mode", EventsInMode);
    PerCoreEvents.add("insns_in_mode", EventsInMode);
    PerCoreEvents.add("uops_in_mode", EventsInMode);
  }
  DataStoreNodeTemplate PTLsimStats("PTLsimStats"); {
    PTLsimStats.addint("snapshot_uuid");
    PTLsimStats.addstring("snapshot_name", 64);
    DataStoreNodeTemplate& summary = PTLsimStats("summary"); {
      summary.addint("cycles");
      summary.addint("insns");
      summary.addint("uops");
      summary.addint("basicblocks");
    }
    DataStoreNodeTemplate& simulator = PTLsimStats("simulator"); {
      DataStoreNodeTemplate& version = simulator("version"); {
        version.addstring("build_timestamp", 32);
        version.addint("svn_revision");
        version.addstring("svn_timestamp", 32);
        version.addstring("build_hostname", 64);
        version.addstring("build_compiler", 16);
      }
      DataStoreNodeTemplate& run = simulator("run"); {
        run.addint("timestamp");
        run.addstring("hostname", 64);
        run.addstring("kernel_version", 32);
        run.addstring("hypervisor_version", 32);
        run.addint("native_cpuid");
        run.addint("native_hz");
      }
      DataStoreNodeTemplate& config = simulator("config"); {
        config.addstring("config", 256);
      }
      DataStoreNodeTemplate& performance = simulator("performance"); {
        DataStoreNodeTemplate& rate = performance("rate"); {
          rate.addfloat("cycles_per_sec");
          rate.addfloat("issues_per_sec");
          rate.addfloat("user_commits_per_sec");
        }
      }
    }
    DataStoreNodeTemplate& decoder = PTLsimStats("decoder"); {
      DataStoreNodeTemplate& throughput = decoder("throughput"); {
        throughput.addint("basic_blocks");
        throughput.addint("x86_insns");
        throughput.addint("uops");
        throughput.addint("bytes");
      }
      decoder.histogram("x86_decode_type", DECODE_TYPE_COUNT, decode_type_names);
      DataStoreNodeTemplate& bb_decode_type = decoder("bb_decode_type"); {
        bb_decode_type.summable = 1;
        bb_decode_type.addint("all_insns_fast");
        bb_decode_type.addint("some_complex_insns");
      }
      DataStoreNodeTemplate& page_crossings = decoder("page_crossings"); {
        page_crossings.summable = 1;
        page_crossings.addint("within_page");
        page_crossings.addint("crosses_page");
      }
      DataStoreNodeTemplate& bbcache = decoder("bbcache"); {
        bbcache.addint("count");
        bbcache.addint("inserts");
        bbcache.histogram("invalidates", INVALIDATE_REASON_COUNT, invalidate_reason_names);
      }
      DataStoreNodeTemplate& pagecache = decoder("pagecache"); {
        pagecache.addint("count");
        pagecache.addint("inserts");
        pagecache.histogram("invalidates", INVALIDATE_REASON_COUNT, invalidate_reason_names);
      }
      decoder.addint("reclaim_rounds");
    }
    PTLsimStats.add("ooocore_total", OutOfOrderCoreStats);
    PTLsimStats.add("ooocore_context_total", PerContextOutOfOrderCoreStats);
    PTLsimStats.addint("elapse_seconds");
    DataStoreNodeTemplate& ooocore = PTLsimStats("ooocore"); {
      ooocore.add("total", OutOfOrderCoreStats);
      ooocore.add("c0", OutOfOrderCoreStats);
      ooocore.add("c1", OutOfOrderCoreStats);
      ooocore.add("c2", OutOfOrderCoreStats);
      ooocore.add("c3", OutOfOrderCoreStats);
      ooocore.add("c4", OutOfOrderCoreStats);
      ooocore.add("c5", OutOfOrderCoreStats);
      ooocore.add("c6", OutOfOrderCoreStats);
      ooocore.add("c7", OutOfOrderCoreStats);
    }
    DataStoreNodeTemplate& dcache = PTLsimStats("dcache"); {
      dcache.add("total", DataCacheStats);
      dcache.add("c0", DataCacheStats);
      dcache.add("c1", DataCacheStats);
      dcache.add("c2", DataCacheStats);
      dcache.add("c3", DataCacheStats);
      dcache.add("c4", DataCacheStats);
      dcache.add("c5", DataCacheStats);
      dcache.add("c6", DataCacheStats);
      dcache.add("c7", DataCacheStats);
    }
    DataStoreNodeTemplate& external = PTLsimStats("external"); {
      external.histogram("assists", ASSIST_COUNT, assist_names);
      external.histogram("l_assists", L_ASSIST_COUNT, light_assist_names);
      external.histogram("traps", 256, x86_exception_names);
      external.add("total", PerCoreEvents);
      external.add("c0", PerCoreEvents);
      external.add("c1", PerCoreEvents);
      external.add("c2", PerCoreEvents);
      external.add("c3", PerCoreEvents);
      external.add("c4", PerCoreEvents);
      external.add("c5", PerCoreEvents);
      external.add("c6", PerCoreEvents);
      external.add("c7", PerCoreEvents);
    }
    DataStoreNodeTemplate& memory = PTLsimStats("memory"); {
      memory.add("total", PerCoreCacheStats);
      memory.add("c0", PerCoreCacheStats);
      memory.add("c1", PerCoreCacheStats);
      memory.add("c2", PerCoreCacheStats);
      memory.add("c3", PerCoreCacheStats);
      memory.add("c4", PerCoreCacheStats);
      memory.add("c5", PerCoreCacheStats);
      memory.add("c6", PerCoreCacheStats);
      memory.add("c7", PerCoreCacheStats);
      memory.add("bus", BusStats);
      memory.histogram("dcache_latency", 200, 0, 199, 1);
      memory.histogram("icache_latency", 200, 0, 199, 1);
    }
  }
  ofstream os(argv[1], std::ios::binary |std::ios::out);
  PTLsimStats.write(os);
  os.close();
}
Beispiel #9
0
/*
 * Save all of the undetermined messages at the top of "mbox"
 * Save all untouched messages back in the system mailbox.
 * Remove the system mailbox, if none saved there.
 */
void
quit(void)
{
    int mcount, p, modify, autohold, anystat, holdbit, nohold;
    FILE *ibuf, *obuf, *fbuf, *rbuf, *readstat, *abuf;
    struct message *mp;
    int c, fd;
    struct stat minfo;
    char *mbox, tempname[PATHSIZE];

    /*
     * If we are read only, we can't do anything,
     * so just return quickly.
     */
    if (readonly)
        return;
    /*
     * If editing (not reading system mail box), then do the work
     * in edstop()
     */
    if (edit) {
        edstop();
        return;
    }

    /*
     * See if there any messages to save in mbox.  If no, we
     * can save copying mbox to /tmp and back.
     *
     * Check also to see if any files need to be preserved.
     * Delete all untouched messages to keep them out of mbox.
     * If all the messages are to be preserved, just exit with
     * a message.
     */

    fbuf = Fopen(mailname, "r");
    if (fbuf == NULL)
        goto newmail;
    flock(fileno(fbuf), LOCK_EX);
    rbuf = NULL;
    if (fstat(fileno(fbuf), &minfo) >= 0 && minfo.st_size > mailsize) {
        printf("New mail has arrived.\n");
        snprintf(tempname, sizeof(tempname), "%s/mail.RqXXXXXXXXXX",
                 tmpdir);
        if ((fd = mkstemp(tempname)) == -1 ||
                (rbuf = Fdopen(fd, "w")) == NULL)
            goto newmail;
#ifdef APPEND
        fseeko(fbuf, mailsize, SEEK_SET);
        while ((c = getc(fbuf)) != EOF)
            putc(c, rbuf);
#else
        p = minfo.st_size - mailsize;
        while (p-- > 0) {
            c = getc(fbuf);
            if (c == EOF)
                goto newmail;
            putc(c, rbuf);
        }
#endif
        Fclose(rbuf);
        if ((rbuf = Fopen(tempname, "r")) == NULL)
            goto newmail;
        rm(tempname);
    }

    /*
     * Adjust the message flags in each message.
     */

    anystat = 0;
    autohold = value("hold") != NULL;
    holdbit = autohold ? MPRESERVE : MBOX;
    nohold = MBOX|MSAVED|MDELETED|MPRESERVE;
    if (value("keepsave") != NULL)
        nohold &= ~MSAVED;
    for (mp = &message[0]; mp < &message[msgCount]; mp++) {
        if (mp->m_flag & MNEW) {
            mp->m_flag &= ~MNEW;
            mp->m_flag |= MSTATUS;
        }
        if (mp->m_flag & MSTATUS)
            anystat++;
        if ((mp->m_flag & MTOUCH) == 0)
            mp->m_flag |= MPRESERVE;
        if ((mp->m_flag & nohold) == 0)
            mp->m_flag |= holdbit;
    }
    modify = 0;
    if (Tflag != NULL) {
        if ((readstat = Fopen(Tflag, "w")) == NULL)
            Tflag = NULL;
    }
    for (c = 0, p = 0, mp = &message[0]; mp < &message[msgCount]; mp++) {
        if (mp->m_flag & MBOX)
            c++;
        if (mp->m_flag & MPRESERVE)
            p++;
        if (mp->m_flag & MODIFY)
            modify++;
        if (Tflag != NULL && (mp->m_flag & (MREAD|MDELETED)) != 0) {
            char *id;

            if ((id = hfield("article-id", mp)) != NULL)
                fprintf(readstat, "%s\n", id);
        }
    }
    if (Tflag != NULL)
        Fclose(readstat);
    if (p == msgCount && !modify && !anystat) {
        printf("Held %d message%s in %s\n",
               p, p == 1 ? "" : "s", mailname);
        Fclose(fbuf);
        return;
    }
    if (c == 0) {
        if (p != 0) {
            writeback(rbuf);
            Fclose(fbuf);
            return;
        }
        goto cream;
    }

    /*
     * Create another temporary file and copy user's mbox file
     * darin.  If there is no mbox, copy nothing.
     * If he has specified "append" don't copy his mailbox,
     * just copy saveable entries at the end.
     */

    mbox = expand("&");
    mcount = c;
    if (value("append") == NULL) {
        snprintf(tempname, sizeof(tempname), "%s/mail.RmXXXXXXXXXX",
                 tmpdir);
        if ((fd = mkstemp(tempname)) == -1 ||
                (obuf = Fdopen(fd, "w")) == NULL) {
            warn("%s", tempname);
            Fclose(fbuf);
            return;
        }
        if ((ibuf = Fopen(tempname, "r")) == NULL) {
            warn("%s", tempname);
            rm(tempname);
            Fclose(obuf);
            Fclose(fbuf);
            return;
        }
        rm(tempname);
        if ((abuf = Fopen(mbox, "r")) != NULL) {
            while ((c = getc(abuf)) != EOF)
                putc(c, obuf);
            Fclose(abuf);
        }
        if (ferror(obuf)) {
            warnx("%s", tempname);
            Fclose(ibuf);
            Fclose(obuf);
            Fclose(fbuf);
            return;
        }
        Fclose(obuf);
        close(open(mbox, O_CREAT | O_TRUNC | O_WRONLY, 0600));
        if ((obuf = Fopen(mbox, "r+")) == NULL) {
            warn("%s", mbox);
            Fclose(ibuf);
            Fclose(fbuf);
            return;
        }
    }
    if (value("append") != NULL) {
        if ((obuf = Fopen(mbox, "a")) == NULL) {
            warn("%s", mbox);
            Fclose(fbuf);
            return;
        }
        fchmod(fileno(obuf), 0600);
    }
    for (mp = &message[0]; mp < &message[msgCount]; mp++)
        if (mp->m_flag & MBOX)
            if (sendmessage(mp, obuf, saveignore, NULL) < 0) {
                warnx("%s", mbox);
                Fclose(ibuf);
                Fclose(obuf);
                Fclose(fbuf);
                return;
            }

    /*
     * Copy the user's old mbox contents back
     * to the end of the stuff we just saved.
     * If we are appending, this is unnecessary.
     */

    if (value("append") == NULL) {
        rewind(ibuf);
        c = getc(ibuf);
        while (c != EOF) {
            putc(c, obuf);
            if (ferror(obuf))
                break;
            c = getc(ibuf);
        }
        Fclose(ibuf);
    }
    fflush(obuf);
    trunc(obuf);
    if (ferror(obuf)) {
        warn("%s", mbox);
        Fclose(obuf);
        Fclose(fbuf);
        return;
    }
    Fclose(obuf);
    if (mcount == 1)
        printf("Saved 1 message in mbox\n");
    else
        printf("Saved %d messages in mbox\n", mcount);

    /*
     * Now we are ready to copy back preserved files to
     * the system mailbox, if any were requested.
     */

    if (p != 0) {
        writeback(rbuf);
        Fclose(fbuf);
        return;
    }

    /*
     * Finally, remove his /var/mail file.
     * If new mail has arrived, copy it back.
     */

cream:
    if (rbuf != NULL) {
        abuf = Fopen(mailname, "r+");
        if (abuf == NULL)
            goto newmail;
        while ((c = getc(rbuf)) != EOF)
            putc(c, abuf);
        Fclose(rbuf);
        trunc(abuf);
        Fclose(abuf);
        alter(mailname);
        Fclose(fbuf);
        return;
    }
    demail();
    Fclose(fbuf);
    return;

newmail:
    printf("Thou hast new mail.\n");
    if (fbuf != NULL)
        Fclose(fbuf);
}
Beispiel #10
0
qryproc()
{
	register QTREE			*root;
	register QTREE			*q;
	register int			i;
	register int			mode;
	register int			result_num;
	register int			retr_uniq;
	extern long			AAccuread;
	extern long			AAccuwrite;
	extern long			AAccusread;
	extern int			derror();
	extern QTREE			*trbuild();
	extern QTREE			*readqry();

#	ifdef xDTM
	if (AAtTf(76, 1))
		timtrace(23, 0);
#	endif
#	ifdef xDTR1
	if (AAtTf(50, 0))
		AAccuread = AAccusread = AAccuwrite = 0;
#	endif

	/* initialize query buffer */
	initbuf(Qbuf, QBUFSIZ, QBUFFULL, derror);

	/* init various variables in decomp for start of this query */
	startdecomp();

	/* Read in query, range table and mode */
	root = readqry();
	mode = Qmode;

	/* Initialize relation descriptors */
	initdesc(mode);

	/* re-build the tree */
	root = trbuild(root);
	if (!root)
		derror(STACKFULL);


	/* locate pointers to QLEND and TREE nodes */
	for (q = root->right; q->sym.type != QLEND; q = q->right)
		continue;
	Qle = q;

	for (q = root->left; q->sym.type != TREE; q = q->left)
		continue;
	Tr = q;


	/* map the complete tree */
	mapvar(root, 0);

	/* set logical locks */
	lockit(root, Resultvar);

	/* If there is no result variable then this must be a retrieve to the terminal */
	Qry_mode = Resultvar < 0 ? (int) mdRETTERM : mode;

	/* if the mode is retrieve_unique, then make a result rel */
	retr_uniq = mode == (int) mdRET_UNI;
	if (retr_uniq)
	{
		mk_unique(root);
		mode = (int) mdRETR;
	}

	/* get id of result relation */
	if (Resultvar < 0)
		result_num = NORESULT;
	else
		result_num = Rangev[Resultvar].relnum;

	/* evaluate aggregates in query */
	aggregate(root);

	/* decompose and process aggregate free query */
	decomp(root, mode, result_num);

	/* If this is a retrieve unique, then retrieve results */
	if (retr_uniq)
		pr_unique(root, Resultvar);

	if (mode != (int) mdRETR)
		i = ACK;
	else
		i = NOACK;
	i = endovqp(i);

	/* call update processor if batch mode */
	if (i == UPDATE)
	{
		initp();
		call_dbu(mdUPDATE, -1);
	}


	/*
	** send eop back to parser to indicate completion
	** if UPDATE then return block comes from dbu else
	** return block comes from decomp
	*/
	writeback(i == UPDATE ? -1 : 1);

#	ifdef xDTM
	if(AAtTf(76, 1))
		timtrace(24, 0);
#	endif
#	ifdef xDTR1
	AAtTfp(50, 1, "DECOMP read %ld pages,%ld catalog pages,wrote %ld pages\n",
		AAccuread, AAccusread, AAccuwrite);
#	endif

	/* clean decomp */
	reinit();

	/* return */
}
void load(FILE* file)
{
    /* Load number of variables */
    int vars = 0;
    fscanf(file, "%i%*c", &vars);
    bool success = change_vars(vars);
    if(!success) {
        return;
    }
    gtk_spin_button_set_value(variables, (gdouble)vars);

    /* Reference new models */
    GtkTreeModel* function = gtk_tree_view_get_model(function_view);
    GtkTreeModel* restrictions = gtk_tree_view_get_model(restrictions_view);

    /* Load if objetive function is to maximize */
    int is_max = 0;
    fscanf(file, "%i%*c", &is_max);
    if(is_max) {
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(function_max), true);
    } else {
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(function_min), true);
    }

    /* Load coefficients of the objetive function */
    int coeff = 0;
    char buff[15];
    for(int i = 0; i < vars; i++) {
        fscanf(file, "%i", &coeff);
        sprintf(buff, "%d", coeff);
        writeback(function, "0", vars, true, (gchar*)&buff, GINT_TO_POINTER(i));
    }
    fscanf(file, "%*c");

    /* Load number of restrictions */
    int num_restrictions = 0;
    fscanf(file, "%i%*c", &num_restrictions);
    for(int i = 0; i < num_restrictions; i++) {
        add_row(NULL, NULL);
    }

    /* Load coefficients of each restriction */
    int size = vars + 2;
    char buff2[15];
    GtkTreeIter iter;
    bool iter_set = gtk_tree_model_get_iter_first(restrictions, &iter);
    for(int i = 0; iter_set && (i < num_restrictions); i++) {
        for(int j = 0; j < size; j++) {
            /* Coefficient or num */
            if(j != (size - 2)) {
                fscanf(file, "%i", &coeff);
                sprintf(buff,  "%d", coeff); /* new_text */
                sprintf(buff2, "%d", i);     /* path */
                writeback(restrictions,
                    (gchar*)&buff2,
                    size, j < (size - 1),
                    (gchar*)&buff,
                    GINT_TO_POINTER(j));
            /* Equation type */
            } else {
                fscanf(file, "%i", &coeff);
                DEBUG("Found type to be %i at (%i, %i).\n", coeff, i, j);
                write_symbol(restrictions, &iter, coeff, size);
            }
        }
        fscanf(file, "%*c");

        iter_set = gtk_tree_model_iter_next(restrictions, &iter);
    }
}
Beispiel #12
0
/* This fine tunes the HT link settings, which were loaded by ROM strap. */
static void host_ctrl_enable_k8t8xx(struct device *dev)
{
	/*
	 * Bit 4 is reserved but set by AW. Set PCI to HT outstanding
	 * requests to 3.
	 */
	pci_write_config8(dev, 0xa0, 0x13);

	/*
	 * NVRAM I/O base at K8T890_NVRAM_IO_BASE
	 * Some bits are set and reserved.
	 */
	pci_write_config8(dev, 0xa2, (K8T890_NVRAM_IO_BASE >> 8));

	/* enable NB NVRAM and enable non-posted PCI writes. */
	pci_write_config8(dev, 0xa1, 0x8f);
	/* Arbitration control, some bits are reserved. */
	pci_write_config8(dev, 0xa5, 0x3c);

	/* Arbitration control 2 */
	pci_write_config8(dev, 0xa6, 0x80);

	/* this will be possibly removed, when I figure out
	 * if the ROM SIP is good, second reason is that the
	 * unknown bits are AGP related, which are dummy on K8T890
	 */

	writeback(dev, 0xa0, 0x13);	/* Bit4 is reserved! */
	writeback(dev, 0xa1, 0x8e);	/* Some bits are reserved. */
	writeback(dev, 0xa2, 0x0e);	/* I/O NVRAM base 0xe00-0xeff disabled. */
	writeback(dev, 0xa3, 0x31);
	writeback(dev, 0xa4, 0x30);

	writeback(dev, 0xa5, 0x3c);	/* Some bits reserved. */
	writeback(dev, 0xa6, 0x80);	/* Some bits reserved. */
	writeback(dev, 0xa7, 0x86);	/* Some bits reserved. */
	writeback(dev, 0xa8, 0x7f);	/* Some bits reserved. */
	writeback(dev, 0xa9, 0xcf);	/* Some bits reserved. */
	writeback(dev, 0xaa, 0x44);
	writeback(dev, 0xab, 0x22);
	writeback(dev, 0xac, 0x35);	/* Maybe bit0 is read-only? */

	writeback(dev, 0xae, 0x22);
	writeback(dev, 0xaf, 0x40);
	/* b0 is missing. */
	writeback(dev, 0xb1, 0x13);
	writeback(dev, 0xb4, 0x02);	/* Some bits are reserved. */
	writeback(dev, 0xc0, 0x20);
	writeback(dev, 0xc1, 0xaa);
	writeback(dev, 0xc2, 0xaa);
	writeback(dev, 0xc3, 0x02);
	writeback(dev, 0xc4, 0x50);
	writeback(dev, 0xc5, 0x50);

	printk(BIOS_DEBUG, " VIA_X_2 device dump:\n");
	dump_south(dev);
}
Beispiel #13
0
void 
quit(
    int noremove	/* don't remove system mailbox, trunc it instead */
)
{
	int mcount, p, modify, autohold, anystat, holdbit, nohold, fd;
	FILE *ibuf, *obuf, *fbuf, *readstat;
	register struct message *mp;
	register int c;
	char *id;
	int appending;
	char *mbox = Getf("MBOX");

	/*
	 * If we are read only, we can't do anything,
	 * so just return quickly.
	 */

	mcount = 0;
	if (readonly)
		return;
	/*
	 * See if there any messages to save in mbox.  If no, we
	 * can save copying mbox to /tmp and back.
	 *
	 * Check also to see if any files need to be preserved.
	 * Delete all untouched messages to keep them out of mbox.
	 * If all the messages are to be preserved, just exit with
	 * a message.
	 *
	 * If the luser has sent mail to himself, refuse to do
	 * anything with the mailbox, unless mail locking works.
	 */

#ifndef CANLOCK
	if (selfsent) {
		printf(gettext("You have new mail.\n"));
		return;
	}
#endif

	/*
	 * Adjust the message flags in each message.
	 */

	anystat = 0;
	autohold = value("hold") != NOSTR;
	appending = value("append") != NOSTR;
	holdbit = autohold ? MPRESERVE : MBOX;
	nohold = MBOXED|MBOX|MSAVED|MDELETED|MPRESERVE;
	if (value("keepsave") != NOSTR)
		nohold &= ~MSAVED;
	for (mp = &message[0]; mp < &message[msgCount]; mp++) {
		if (mp->m_flag & MNEW) {
			receipt(mp);
			mp->m_flag &= ~MNEW;
			mp->m_flag |= MSTATUS;
		}
		if (mp->m_flag & MSTATUS)
			anystat++;
		if ((mp->m_flag & MTOUCH) == 0)
			mp->m_flag |= MPRESERVE;
		if ((mp->m_flag & nohold) == 0)
			mp->m_flag |= holdbit;
	}
	modify = 0;
	if (Tflag != NOSTR) {
		if ((readstat = fopen(Tflag, "w")) == NULL)
			Tflag = NOSTR;
	}
	for (c = 0, p = 0, mp = &message[0]; mp < &message[msgCount]; mp++) {
		if (mp->m_flag & MBOX)
			c++;
		if (mp->m_flag & MPRESERVE)
			p++;
		if (mp->m_flag & MODIFY)
			modify++;
		if (Tflag != NOSTR && (mp->m_flag & (MREAD|MDELETED)) != 0) {
			id = hfield("message-id", mp, addone);
			if (id != NOSTR)
				fprintf(readstat, "%s\n", id);
			else {
				id = hfield("article-id", mp, addone);
				if (id != NOSTR)
					fprintf(readstat, "%s\n", id);
			}
		}
	}
	if (Tflag != NOSTR)
		fclose(readstat);
	if (p == msgCount && !modify && !anystat) {
		if (p == 1)
			printf(gettext("Held 1 message in %s\n"), mailname);
		else
			printf(gettext("Held %d messages in %s\n"), p,
			    mailname);
		return;
	}
	if (c == 0) {
		writeback(noremove);
		return;
	}

	/*
	 * Create another temporary file and copy user's mbox file
	 * therein.  If there is no mbox, copy nothing.
	 * If s/he has specified "append" don't copy the mailbox,
	 * just copy saveable entries at the end.
	 */

	mcount = c;
	if (!appending) {
		if ((fd = open(tempQuit, O_RDWR|O_CREAT|O_EXCL, 0600)) < 0 ||
		(obuf = fdopen(fd, "w")) == NULL) {
			perror(tempQuit);
			return;
		}
		if ((ibuf = fopen(tempQuit, "r")) == NULL) {
			perror(tempQuit);
			removefile(tempQuit);
			fclose(obuf);
			return;
		}
		removefile(tempQuit);
		if ((fbuf = fopen(mbox, "r")) != NULL) {
			while ((c = getc(fbuf)) != EOF)
				putc(c, obuf);
			fclose(fbuf);
		}
		fflush(obuf);
		if (fferror(obuf)) {
			perror(tempQuit);
			fclose(ibuf);
			fclose(obuf);
			return;
		}
		fclose(obuf);
		if ((fd = open(mbox, O_RDWR|O_CREAT|O_TRUNC, MBOXPERM)) < 0 ||
		    (obuf = fdopen(fd, "r+")) == NULL) {
			perror(mbox);
			fclose(ibuf);
			return;
		}
		if (issysmbox)
			touchlock();
	} else {	/* we are appending */
		if ((fd = open(mbox, O_RDWR|O_CREAT, MBOXPERM)) < 0 ||
		    (obuf = fdopen(fd, "a")) == NULL) {
			perror(mbox);
			return;
		}
	}
	for (mp = &message[0]; mp < &message[msgCount]; mp++)
		if (mp->m_flag & MBOX) {
			if (msend(mp, obuf, (int)value("alwaysignore") ?
			    M_IGNORE|M_SAVING : M_SAVING, fputs) < 0) {
				perror(mbox);
				if (!appending)
					fclose(ibuf);
				fclose(obuf);
				return;
			}
			mp->m_flag &= ~MBOX;
			mp->m_flag |= MBOXED;
			if (issysmbox)
				touchlock();
		}

	/*
	 * Copy the user's old mbox contents back
	 * to the end of the stuff we just saved.
	 * If we are appending, this is unnecessary.
	 */

	if (!appending) {
		rewind(ibuf);
		c = getc(ibuf);
		while (c != EOF) {
			putc(c, obuf);
			if (ferror(obuf))
				break;
			c = getc(ibuf);
		}
		fclose(ibuf);
		fflush(obuf);
	}
	trunc(obuf);
	if (fferror(obuf)) {
		perror(mbox);
		fclose(obuf);
		return;
	}
	fclose(obuf);
	if (mcount == 1)
		printf(gettext("Saved 1 message in %s\n"), mbox);
	else
		printf(gettext("Saved %d messages in %s\n"), mcount, mbox);

	/*
	 * Now we are ready to copy back preserved files to
	 * the system mailbox, if any were requested.
	 */
	writeback(noremove);
}
Beispiel #14
0
quit()
{
	int mcount, p, modify, autohold, anystat, holdbit, nohold;
	FILE *ibuf, *obuf, *fbuf, *rbuf, *readstat, *abuf;
	register struct message *mp;
	register int c;
	extern char tempQuit[], tempResid[];
	struct stat minfo;
	char *id;

	/*
	 * If we are read only, we can't do anything,
	 * so just return quickly.
	 */

	if (readonly)
		return;
	/*
	 * See if there any messages to save in mbox.  If no, we
	 * can save copying mbox to /tmp and back.
	 *
	 * Check also to see if any files need to be preserved.
	 * Delete all untouched messages to keep them out of mbox.
	 * If all the messages are to be preserved, just exit with
	 * a message.
	 *
	 * If the luser has sent mail to himself, refuse to do
	 * anything with the mailbox, unless mail locking works.
	 */

	fbuf = fopen(mailname, "r");
	if (fbuf == NULL)
		goto newmail;
	flock(fileno(fbuf), LOCK_EX);
#ifndef CANLOCK
	if (selfsent) {
		printf("You have new mail.\n");
		fclose(fbuf);
		return;
	}
#endif
	rbuf = NULL;
	if (fstat(fileno(fbuf), &minfo) >= 0 && minfo.st_size > mailsize) {
		printf("New mail has arrived.\n");
		rbuf = fopen(tempResid, "w");
		if (rbuf == NULL || fbuf == NULL)
			goto newmail;
#ifdef APPEND
		fseek(fbuf, mailsize, 0);
		while ((c = getc(fbuf)) != EOF)
			putc(c, rbuf);
#else
		p = minfo.st_size - mailsize;
		while (p-- > 0) {
			c = getc(fbuf);
			if (c == EOF)
				goto newmail;
			putc(c, rbuf);
		}
#endif
		fclose(rbuf);
		if ((rbuf = fopen(tempResid, "r")) == NULL)
			goto newmail;
		remove(tempResid);
	}

	/*
	 * Adjust the message flags in each message.
	 */

	anystat = 0;
	autohold = value("hold") != NOSTR;
	holdbit = autohold ? MPRESERVE : MBOX;
	nohold = MBOX|MSAVED|MDELETED|MPRESERVE;
	if (value("keepsave") != NOSTR)
		nohold &= ~MSAVED;
	for (mp = &message[0]; mp < &message[msgCount]; mp++) {
		if (mp->m_flag & MNEW) {
			mp->m_flag &= ~MNEW;
			mp->m_flag |= MSTATUS;
		}
		if (mp->m_flag & MSTATUS)
			anystat++;
		if ((mp->m_flag & MTOUCH) == 0)
			mp->m_flag |= MPRESERVE;
		if ((mp->m_flag & nohold) == 0)
			mp->m_flag |= holdbit;
	}
	modify = 0;
	if (Tflag != NOSTR) {
		if ((readstat = fopen(Tflag, "w")) == NULL)
			Tflag = NOSTR;
	}
	for (c = 0, p = 0, mp = &message[0]; mp < &message[msgCount]; mp++) {
		if (mp->m_flag & MBOX)
			c++;
		if (mp->m_flag & MPRESERVE)
			p++;
		if (mp->m_flag & MODIFY)
			modify++;
		if (Tflag != NOSTR && (mp->m_flag & (MREAD|MDELETED)) != 0) {
			id = hfield("article-id", mp);
			if (id != NOSTR)
				fprintf(readstat, "%s\n", id);
		}
	}
	if (Tflag != NOSTR)
		fclose(readstat);
	if (p == msgCount && !modify && !anystat) {
		if (p == 1)
			printf("Held 1 message in %s\n", mailname);
		else
			printf("Held %2d messages in %s\n", p, mailname);
		fclose(fbuf);
		return;
	}
	if (c == 0) {
		if (p != 0) {
			writeback(rbuf);
			fclose(fbuf);
			return;
		}
		goto cream;
	}

	/*
	 * Create another temporary file and copy user's mbox file
	 * darin.  If there is no mbox, copy nothing.
	 * If he has specified "append" don't copy his mailbox,
	 * just copy saveable entries at the end.
	 */

	mcount = c;
	if (value("append") == NOSTR) {
		if ((obuf = fopen(tempQuit, "w")) == NULL) {
			perror(tempQuit);
			fclose(fbuf);
			return;
		}
		if ((ibuf = fopen(tempQuit, "r")) == NULL) {
			perror(tempQuit);
			remove(tempQuit);
			fclose(obuf);
			fclose(fbuf);
			return;
		}
		remove(tempQuit);
		if ((abuf = fopen(mbox, "r")) != NULL) {
			while ((c = getc(abuf)) != EOF)
				putc(c, obuf);
			fclose(abuf);
		}
		if (ferror(obuf)) {
			perror(tempQuit);
			fclose(ibuf);
			fclose(obuf);
			fclose(fbuf);
			return;
		}
		fclose(obuf);
		close(creat(mbox, 0600));
		if ((obuf = fopen(mbox, "r+")) == NULL) {
			perror(mbox);
			fclose(ibuf);
			fclose(fbuf);
			return;
		}
	}
	if (value("append") != NOSTR) {
		if ((obuf = fopen(mbox, "a")) == NULL) {
			perror(mbox);
			fclose(fbuf);
			return;
		}
		fchmod(fileno(obuf), 0600);
	}
	for (mp = &message[0]; mp < &message[msgCount]; mp++)
		if (mp->m_flag & MBOX)
			if (send(mp, obuf, 0) < 0) {
				perror(mbox);
				fclose(ibuf);
				fclose(obuf);
				fclose(fbuf);
				return;
			}

	/*
	 * Copy the user's old mbox contents back
	 * to the end of the stuff we just saved.
	 * If we are appending, this is unnecessary.
	 */

	if (value("append") == NOSTR) {
		rewind(ibuf);
		c = getc(ibuf);
		while (c != EOF) {
			putc(c, obuf);
			if (ferror(obuf))
				break;
			c = getc(ibuf);
		}
		fclose(ibuf);
		fflush(obuf);
	}
	trunc(obuf);
	if (ferror(obuf)) {
		perror(mbox);
		fclose(obuf);
		fclose(fbuf);
		return;
	}
	fclose(obuf);
	if (mcount == 1)
		printf("Saved 1 message in mbox\n");
	else
		printf("Saved %d messages in mbox\n", mcount);

	/*
	 * Now we are ready to copy back preserved files to
	 * the system mailbox, if any were requested.
	 */

	if (p != 0) {
		writeback(rbuf);
		fclose(fbuf);
		return;
	}

	/*
	 * Finally, remove his /usr/mail file.
	 * If new mail has arrived, copy it back.
	 */

cream:
	if (rbuf != NULL) {
		abuf = fopen(mailname, "r+");
		if (abuf == NULL)
			goto newmail;
		while ((c = getc(rbuf)) != EOF)
			putc(c, abuf);
		fclose(rbuf);
		trunc(abuf);
		fclose(abuf);
		alter(mailname);
		fclose(fbuf);
		return;
	}
	demail();
	fclose(fbuf);
	return;

newmail:
	printf("Thou hast new mail.\n");
	if (fbuf != NULL)
		fclose(fbuf);
}
Beispiel #15
0
int main(int argc, char *argv[])
{
  
  InstInfo curInst;
  //InstInfo* instArray[4];
  //int top = 0;
  //  InstInfo *f = &curInst;
  int instnum = 0;
  int maxpc;
  FILE *program;
  int i;
  for (i =0 ; i < 32; i++) {
   regfile[i]=0;
  }
  
  if (argc != 2)
    {
      printf("Usage: sim filename\n");
      exit(0);
    }
  
  maxpc = load(argv[1]) - 1;
  InstInfo* n; n= malloc(sizeof(*n));
  InstInfo* f; f=malloc(sizeof(*f));
  InstInfo* d; d=malloc(sizeof(*d));
  InstInfo* x; x=malloc(sizeof(*x));
  InstInfo* m; m=malloc(sizeof(*m));
  InstInfo* w; w=malloc(sizeof(*w));
  
  fetch(f);
  decode(f);
  i = 0;
  InstInfo* nop = malloc(sizeof(*nop));
  nop->inst = 31;
  int nopnop=0; 
  int MAXPC4 = maxpc + 4;
  int k = 0;
  int zapzap=0;
  int setPC;
  while (i<=MAXPC4) {
    
    writeback(w);
    memory(m);
    execute(x);
    decode(d);
    setPCWithInfo(w);  
    printP2(f,d,x,m,w,instnum++); 

    printf("-------------------------------------------------\n");
    //printf("PC %d \n", pc);
    int memoryResult = m->memout;//w->memout;
    int executeResult=x->aluout;
    int forwardA=0, forwardB=0;
    int xRegWrite = x->signals.rw;
    int mRegWrite = m->signals.rw;
    int wRegWrite = m->signals.rw;
    int wrd = w->destreg;
    int mrd = m->destreg;
    int xrd = x->destreg;
    int drs = d->sourcereg;
    int drt = d->targetreg;
    int dmr = x->signals.mr;
    int drd = x->destreg;
    int frs = d->sourcereg;
    int frt = d->targetreg;
    int dBType = f->signals.btype;
    int zapped;
    int zapper;
    //if (zapzap == 2) {
      
    //}
    if (zapzap == 1) {
	  //  zapzap++; }
      //  if (zapzap == 2) {
      //      *w = *m;
      //*m = *x;
      //*x =*d;
      //*d = *f;
      printf("IN XAAPZAP\n");
      zapzap=0;
      zapped = 1;
    }
    //    int zapped = 1;
    int guessedNotTaken = pc+1;
    if (dBType == 1 || dBType ==2 || dBType == 3) {
      if (guessedNotTaken != d->aluout) {
	zapzap=1;
	//zapped = 0;
	int setPC = d->aluout;
	//setPCWithInfo(d);
      }
    }
    
    printf("PC %d , setPC: %d \n", pc, setPC);
    printf("ZAPZAP %d btype %d \n",zapzap, dBType);//zapzap);
    
    // int k = 0;

    //printf("memorytest %d\n", memoryResult);
    if (dmr == 1 && ( drd == frs || drd ==frt) ) {
      nopnop = 1;
      //printf("SETTING NOPNOP! %d\n", nopnop);
    }
    else {
      //printf("NOT SETTING NOPNOP %d\n", nopnop);
    }    
    if (wRegWrite == 1 && wrd != 0 && (wrd == drs)) { 
      forwardA=3; 
      
      //printf("3a %d \n", regfile[wrd]);
    }
    else {
      if (mRegWrite == 1 && mrd !=0 && (mrd == drs)) {
    forwardA= 1;
    //printf("1a %d \n", memoryResult);//regfile[mrd]);
      }
      else {
    if (xRegWrite == 1 && xrd !=0 && (xrd==drs)) {
      //printf("2a %d \n", regfile[xrd]);
      forwardA = 2;
    }
      }
    }
    
    if (wRegWrite == 1 && wrd != 0 && (wrd == drt)) { 
      forwardB=3; 
      //printf("3b  %d \n", regfile[wrd]);
    }
    else {
      if (mRegWrite == 1 && mrd !=0 && (mrd == drt)) {
    //printf("1b %d \n", regfile[mrd]);
    forwardB= 1;
      }
      else {
    if (xRegWrite == 1 && xrd !=0 && (xrd==drt)) {
      forwardB = 2;
      //printf("2b  %d \n", regfile[xrd]);
    }
      }
    }
    
    switch (forwardA) {
    case 2: //from execute
      d->input1 = executeResult;
      break;
    case 1: //from mem 
      d->input1 = m->memout;//memoryResult;
      break;
    case 3:
      d->input1 = w->destdata;
      break;
    default:
      break;
    }
    // printf("D %d input1: %d\n", forwardA, d->input1);
    
    switch (forwardB) {
    case 2:
      d->input2 = executeResult;
      break;
    case 1:
      d->input2 = memoryResult;
      break;
    case 3:
      d->input2 = w->destdata;
      break;
    default:
      break;
    }

    i++;

    if (nopnop== 0) {// && zapped != 1)  { 
      printf("NO NOP!\n");
      // if (zapzap==0)
	*w=*m; *m=*x; *x=*d; *d=*f;
	if (zapped ==1) {
	  d=nop;
	  zapper = 1;
	}
    }
    else {
      //printf("NO NOP\n");
      *w = *m;
      *m = *x;
      *x = *nop;
      //*w=*m; *m=*x; *x=*d; *d=*f;
      i--;
      k++;
      pc--;
    }

    if (i <= maxpc){// && dBType ==0) {
      fetch(f);
      decode(f);
    }
    else {
      *f = *n;
    }
    nopnop = 0;
    //if (zapzap == 1 and zapped = 1) {
    zapped=0;
    //}
  }
  printf("Cycles: %d\nInstructions Executed: %d\n", i+k, maxpc+1);
  free(d);  free(x);  free(m);  free(w);  free(n); free(f);
  exit(0);
}
Beispiel #16
0
/*ARGSUSED*/
void
trap(struct frame *fp, int type, unsigned code, unsigned v)
{
	extern char fubail[], subail[];
	struct lwp *l;
	struct proc *p;
	struct pcb *pcb;
	void *onfault;
	ksiginfo_t ksi;
	int s;
	int rv;
	u_quad_t sticks = 0 /* XXX initialiser works around compiler bug */;
	static int panicking __diagused;

	curcpu()->ci_data.cpu_ntrap++;
	l = curlwp;
	p = l->l_proc;
	pcb = lwp_getpcb(l);

	KSI_INIT_TRAP(&ksi);
	ksi.ksi_trap = type & ~T_USER;

	if (USERMODE(fp->f_sr)) {
		type |= T_USER;
		sticks = p->p_sticks;
		l->l_md.md_regs = fp->f_regs;
		LWP_CACHE_CREDS(l, p);
	}
	switch (type) {

	default:
	dopanic:
		/*
		 * Let the kernel debugger see the trap frame that
		 * caused us to panic.  This is a convenience so
		 * one can see registers at the point of failure.
		 */
		s = splhigh();
		panicking = 1;
		printf("trap type %d, code = 0x%x, v = 0x%x\n", type, code, v);
		printf("%s program counter = 0x%x\n",
		    (type & T_USER) ? "user" : "kernel", fp->f_pc);
#ifdef KGDB
		/* If connected, step or cont returns 1 */
		if (kgdb_trap(type, (db_regs_t *)fp))
			goto kgdb_cont;
#endif
#ifdef DDB
		(void)kdb_trap(type, (db_regs_t *)fp);
#endif
#ifdef KGDB
	kgdb_cont:
#endif
		splx(s);
		if (panicstr) {
			printf("trap during panic!\n");
#ifdef DEBUG
			/* XXX should be a machine-dependent hook */
			printf("(press a key)\n"); (void)cngetc();
#endif
		}
		regdump((struct trapframe *)fp, 128);
		type &= ~T_USER;
		if ((u_int)type < trap_types)
			panic(trap_type[type]);
		panic("trap");

	case T_BUSERR:		/* kernel bus error */
		onfault = pcb->pcb_onfault;
		if (onfault == NULL)
			goto dopanic;
		rv = EFAULT;
		/* FALLTHROUGH */

	copyfault:
		/*
		 * If we have arranged to catch this fault in any of the
		 * copy to/from user space routines, set PC to return to
		 * indicated location and set flag informing buserror code
		 * that it may need to clean up stack frame.
		 */
		fp->f_stackadj = exframesize[fp->f_format];
		fp->f_format = fp->f_vector = 0;
		fp->f_pc = (int)onfault;
		fp->f_regs[D0] = rv;
		return;

	case T_BUSERR|T_USER:	/* bus error */
	case T_ADDRERR|T_USER:	/* address error */
		ksi.ksi_addr = (void *)v;
		ksi.ksi_signo = SIGBUS;
		ksi.ksi_code = (type == (T_BUSERR|T_USER)) ?
			BUS_OBJERR : BUS_ADRERR;
		break;

	case T_COPERR:		/* kernel coprocessor violation */
	case T_FMTERR|T_USER:	/* do all RTE errors come in as T_USER? */
	case T_FMTERR:		/* ...just in case... */
	/*
	 * The user has most likely trashed the RTE or FP state info
	 * in the stack frame of a signal handler.
	 */
		printf("pid %d: kernel %s exception\n", p->p_pid,
		       type==T_COPERR ? "coprocessor" : "format");
		type |= T_USER;

		mutex_enter(p->p_lock);
		SIGACTION(p, SIGILL).sa_handler = SIG_DFL;
		sigdelset(&p->p_sigctx.ps_sigignore, SIGILL);
		sigdelset(&p->p_sigctx.ps_sigcatch, SIGILL);
		sigdelset(&l->l_sigmask, SIGILL);
		mutex_exit(p->p_lock);

		ksi.ksi_signo = SIGILL;
		ksi.ksi_addr = (void *)(int)fp->f_format;
				/* XXX was ILL_RESAD_FAULT */
		ksi.ksi_code = (type == T_COPERR) ?
			ILL_COPROC : ILL_ILLOPC;
		break;

	case T_COPERR|T_USER:	/* user coprocessor violation */
	/* What is a proper response here? */
		ksi.ksi_signo = SIGFPE;
		ksi.ksi_code = FPE_FLTINV;
		break;

	case T_FPERR|T_USER:	/* 68881 exceptions */
	/*
	 * We pass along the 68881 status register which locore stashed
	 * in code for us.
	 */
		ksi.ksi_signo = SIGFPE;
		ksi.ksi_code = fpsr2siginfocode(code);
		break;

#ifdef M68040
	case T_FPEMULI|T_USER:	/* unimplemented FP instruction */
	case T_FPEMULD|T_USER:	/* unimplemented FP data type */
		/* XXX need to FSAVE */
		printf("pid %d(%s): unimplemented FP %s at %x (EA %x)\n",
		       p->p_pid, p->p_comm,
		       fp->f_format == 2 ? "instruction" : "data type",
		       fp->f_pc, fp->f_fmt2.f_iaddr);
		/* XXX need to FRESTORE */
		ksi.ksi_signo = SIGFPE;
		ksi.ksi_code = FPE_FLTINV;
		break;
#endif

	case T_ILLINST|T_USER:	/* illegal instruction fault */
	case T_PRIVINST|T_USER:	/* privileged instruction fault */
		ksi.ksi_addr = (void *)(int)fp->f_format;
				/* XXX was ILL_PRIVIN_FAULT */
		ksi.ksi_signo = SIGILL;
		ksi.ksi_code = (type == (T_PRIVINST|T_USER)) ?
			ILL_PRVOPC : ILL_ILLOPC;
		break;

	case T_ZERODIV|T_USER:	/* Divide by zero */
		ksi.ksi_addr = (void *)(int)fp->f_format;
				/* XXX was FPE_INTDIV_TRAP */
		ksi.ksi_signo = SIGFPE;
		ksi.ksi_code = FPE_FLTDIV;
		break;

	case T_CHKINST|T_USER:	/* CHK instruction trap */
		ksi.ksi_addr = (void *)(int)fp->f_format;
				/* XXX was FPE_SUBRNG_TRAP */
		ksi.ksi_signo = SIGFPE;
		break;

	case T_TRAPVINST|T_USER:	/* TRAPV instruction trap */
		ksi.ksi_addr = (void *)(int)fp->f_format;
				/* XXX was FPE_INTOVF_TRAP */
		ksi.ksi_signo = SIGFPE;
		break;

	/*
	 * XXX: Trace traps are a nightmare.
	 *
	 *	HP-UX uses trap #1 for breakpoints,
	 *	NetBSD/m68k uses trap #2,
	 *	SUN 3.x uses trap #15,
	 *	DDB and KGDB uses trap #15 (for kernel breakpoints;
	 *	handled elsewhere).
	 *
	 * NetBSD and HP-UX traps both get mapped by locore.s into T_TRACE.
	 * SUN 3.x traps get passed through as T_TRAP15 and are not really
	 * supported yet.
	 *
	 * XXX: We should never get kernel-mode T_TRAP15
	 * XXX: because locore.s now gives them special treatment.
	 */
	case T_TRAP15:		/* kernel breakpoint */
#ifdef DEBUG
		printf("unexpected kernel trace trap, type = %d\n", type);
		printf("program counter = 0x%x\n", fp->f_pc);
#endif
		fp->f_sr &= ~PSL_T;
		return;

	case T_TRACE|T_USER:	/* user trace trap */
#ifdef COMPAT_SUNOS
		/*
		 * SunOS uses Trap #2 for a "CPU cache flush".
		 * Just flush the on-chip caches and return.
		 */
		if (p->p_emul == &emul_sunos) {
			ICIA();
			DCIU();
			return;
		}
#endif
		/* FALLTHROUGH */
	case T_TRACE:		/* tracing a trap instruction */
	case T_TRAP15|T_USER:	/* SUN user trace trap */
		fp->f_sr &= ~PSL_T;
		ksi.ksi_signo = SIGTRAP;
		break;

	case T_ASTFLT:		/* system async trap, cannot happen */
		goto dopanic;

	case T_ASTFLT|T_USER:	/* user async trap */
		astpending = 0;
		/*
		 * We check for software interrupts first.  This is because
		 * they are at a higher level than ASTs, and on a VAX would
		 * interrupt the AST.  We assume that if we are processing
		 * an AST that we must be at IPL0 so we don't bother to
		 * check.  Note that we ensure that we are at least at SIR
		 * IPL while processing the SIR.
		 */
		spl1();
		/* fall into... */

	case T_SSIR:		/* software interrupt */
	case T_SSIR|T_USER:
		/*
		 * If this was not an AST trap, we are all done.
		 */
		if (type != (T_ASTFLT|T_USER)) {
			curcpu()->ci_data.cpu_ntrap--;
			return;
		}
		spl0();
		if (l->l_pflag & LP_OWEUPC) {
			l->l_pflag &= ~LP_OWEUPC;
			ADDUPROF(l);
		}
		if (curcpu()->ci_want_resched)
			preempt();
		goto out;

	case T_MMUFLT:		/* kernel mode page fault */
		/*
		 * If we were doing profiling ticks or other user mode
		 * stuff from interrupt code, Just Say No.
		 */
		onfault = pcb->pcb_onfault;
		if (onfault == fubail || onfault == subail) {
			rv = EFAULT;
			goto copyfault;
		}
		/* fall into ... */

	case T_MMUFLT|T_USER:	/* page fault */
	    {
		vaddr_t va;
		struct vmspace *vm = p->p_vmspace;
		struct vm_map *map;
		vm_prot_t ftype;
		extern struct vm_map *kernel_map;

		onfault = pcb->pcb_onfault;

#ifdef DEBUG
		if ((mmudebug & MDB_WBFOLLOW) || MDB_ISPID(p->p_pid))
		printf("trap: T_MMUFLT pid=%d, code=%x, v=%x, pc=%x, sr=%x\n",
		       p->p_pid, code, v, fp->f_pc, fp->f_sr);
#endif
		/*
		 * It is only a kernel address space fault iff:
		 * 	1. (type & T_USER) == 0  and
		 * 	2. pcb_onfault not set or
		 *	3. pcb_onfault set but supervisor space data fault
		 * The last can occur during an exec() copyin where the
		 * argument space is lazy-allocated.
		 */
		if ((type & T_USER) == 0 && (onfault == NULL || KDFAULT(code)))
			map = kernel_map;
		else {
			map = vm ? &vm->vm_map : kernel_map;
		}

		if (WRFAULT(code))
			ftype = VM_PROT_WRITE;
		else
			ftype = VM_PROT_READ;

		va = trunc_page((vaddr_t)v);

		if (map == kernel_map && va == 0) {
			printf("trap: bad kernel %s access at 0x%x\n",
			    (ftype & VM_PROT_WRITE) ? "read/write" :
			    "read", v);
			goto dopanic;
		}

#ifdef DIAGNOSTIC
		if (interrupt_depth && !panicking) {
			printf("trap: calling uvm_fault() from interrupt!\n");
			goto dopanic;
		}
#endif
		
		pcb->pcb_onfault = NULL;
		rv = uvm_fault(map, va, ftype);
		pcb->pcb_onfault = onfault;
#ifdef DEBUG
		if (rv && MDB_ISPID(p->p_pid))
			printf("uvm_fault(%p, 0x%lx, 0x%x) -> 0x%x\n",
			    map, va, ftype, rv);
#endif
		/*
		 * If this was a stack access we keep track of the maximum
		 * accessed stack size.  Also, if vm_fault gets a protection
		 * failure it is due to accessing the stack region outside
		 * the current limit and we need to reflect that as an access
		 * error.
		 */
		if (rv == 0) {
			if (map != kernel_map && (void *)va >= vm->vm_maxsaddr)
				uvm_grow(p, va);

			if (type == T_MMUFLT) {
				if (ucas_ras_check(&fp->F_t)) {
					return;
				}
#ifdef M68040
				if (cputype == CPU_68040)
					(void) writeback(fp, 1);
#endif
				return;
			}
			goto out;
		}
		if (rv == EACCES) {
			ksi.ksi_code = SEGV_ACCERR;
			rv = EFAULT;
		} else
			ksi.ksi_code = SEGV_MAPERR;
		if (type == T_MMUFLT) {
			if (onfault)
				goto copyfault;
			printf("uvm_fault(%p, 0x%lx, 0x%x) -> 0x%x\n",
			    map, va, ftype, rv);
			printf("  type %x, code [mmu,,ssw]: %x\n",
			       type, code);
			goto dopanic;
		}
		ksi.ksi_addr = (void *)v;
		switch (rv) {
		case ENOMEM:
			printf("UVM: pid %d (%s), uid %d killed: out of swap\n",
			       p->p_pid, p->p_comm,
			       l->l_cred ?
			       kauth_cred_geteuid(l->l_cred) : -1);
			ksi.ksi_signo = SIGKILL;
			break;
		case EINVAL:
			ksi.ksi_signo = SIGBUS;
			ksi.ksi_code = BUS_ADRERR;
			break;
		case EACCES:
			ksi.ksi_signo = SIGSEGV;
			ksi.ksi_code = SEGV_ACCERR;
			break;
		default:
			ksi.ksi_signo = SIGSEGV;
			ksi.ksi_code = SEGV_MAPERR;
			break;
		}
		break;
	    }
	}
	trapsignal(l, &ksi);
	if ((type & T_USER) == 0)
		return;
out:
	userret(l, fp, sticks, v, 1);
}
Beispiel #17
0
/*ARGSUSED*/
void
trap(struct frame *fp, int type, u_int code, u_int v)
{
	extern char fubail[], subail[];
	struct lwp *l;
	struct proc *p;
	ksiginfo_t ksi;
	int s;
	u_quad_t sticks;

	uvmexp.traps++;
	l = curlwp;

	KSI_INIT_TRAP(&ksi);
	ksi.ksi_trap = type & ~T_USER;

	p = l->l_proc;

	if (USERMODE(fp->f_sr)) {
		type |= T_USER;
		sticks = p->p_sticks;
		l->l_md.md_regs = fp->f_regs;
		LWP_CACHE_CREDS(l, p);
	} else
		sticks = 0;

#ifdef DIAGNOSTIC
	if (l->l_addr == NULL)
		panic("trap: type 0x%x, code 0x%x, v 0x%x -- no pcb",
			type, code, v);
#endif

	switch (type) {
	default:
	dopanic:
		printf("trap type %d, code = 0x%x, v = 0x%x\n", type, code, v);
		printf("%s program counter = 0x%x\n",
		    (type & T_USER) ? "user" : "kernel", fp->f_pc);
		/*
		 * Let the kernel debugger see the trap frame that
		 * caused us to panic.  This is a convenience so
		 * one can see registers at the point of failure.
		 */
		s = splhigh();
#ifdef KGDB
		/* If connected, step or cont returns 1 */
		if (kgdb_trap(type, (db_regs_t *)fp))
			goto kgdb_cont;
#endif
#ifdef DDB
		(void)kdb_trap(type, (db_regs_t *)fp);
#endif
#ifdef KGDB
	kgdb_cont:
#endif
		splx(s);
		if (panicstr) {
			printf("trap during panic!\n");
#ifdef DEBUG
			/* XXX should be a machine-dependent hook */
			printf("(press a key)\n"); (void)cngetc();
#endif
		}
		regdump((struct trapframe *)fp, 128);
		type &= ~T_USER;
		if ((u_int)type < trap_types)
			panic(trap_type[type]);
		panic("trap");

	case T_BUSERR:		/* Kernel bus error */
		if (!l->l_addr->u_pcb.pcb_onfault)
			goto dopanic;
		/*
		 * If we have arranged to catch this fault in any of the
		 * copy to/from user space routines, set PC to return to
		 * indicated location and set flag informing buserror code
		 * that it may need to clean up stack frame.
		 */
copyfault:
		fp->f_stackadj = exframesize[fp->f_format];
		fp->f_format = fp->f_vector = 0;
		fp->f_pc = (int)l->l_addr->u_pcb.pcb_onfault;
		return;

	case T_BUSERR|T_USER:	/* Bus error */
	case T_ADDRERR|T_USER:	/* Address error */
		ksi.ksi_addr = (void *)v;
		ksi.ksi_signo = SIGBUS;
		ksi.ksi_code = (type == (T_BUSERR|T_USER)) ?
			BUS_OBJERR : BUS_ADRERR;
		break;

	case T_ILLINST|T_USER:	/* Illegal instruction fault */
	case T_PRIVINST|T_USER:	/* Privileged instruction fault */
		ksi.ksi_addr = (void *)(int)fp->f_format;
				/* XXX was ILL_PRIVIN_FAULT */
		ksi.ksi_signo = SIGILL;
		ksi.ksi_code = (type == (T_PRIVINST|T_USER)) ?
			ILL_PRVOPC : ILL_ILLOPC;
		break;
	/*
	 * divde by zero, CHK/TRAPV inst 
	 */
	case T_ZERODIV|T_USER:		/* Divide by zero trap */
		ksi.ksi_code = FPE_FLTDIV;
	case T_CHKINST|T_USER:		/* CHK instruction trap */
	case T_TRAPVINST|T_USER:	/* TRAPV instruction trap */
		ksi.ksi_addr = (void *)(int)fp->f_format;
		ksi.ksi_signo = SIGFPE;
		break;

	/* 
	 * User coprocessor violation
	 */
	case T_COPERR|T_USER:
	/* XXX What is a proper response here? */
		ksi.ksi_signo = SIGFPE;
		ksi.ksi_code = FPE_FLTINV;
		break;
	/* 
	 * 6888x exceptions 
	 */
	case T_FPERR|T_USER:
		/*
		 * We pass along the 68881 status register which locore
		 * stashed in code for us.  Note that there is a
		 * possibility that the bit pattern of this register
		 * will conflict with one of the FPE_* codes defined
		 * in signal.h.  Fortunately for us, the only such
		 * codes we use are all in the range 1-7 and the low
		 * 3 bits of the status register are defined as 0 so
		 * there is no clash.
		 */
		ksi.ksi_signo = SIGFPE;
		ksi.ksi_addr = (void *)code;
		break;

	/*
	 * FPU faults in supervisor mode.
	 */
	case T_ILLINST:	/* fnop generates this, apparently. */
	case T_FPEMULI:
	case T_FPEMULD: {
		extern label_t *nofault;

		if (nofault)	/* If we're probing. */
			longjmp(nofault);
		if (type == T_ILLINST)
			printf("Kernel Illegal Instruction trap.\n");
		else
			printf("Kernel FPU trap.\n");
		goto dopanic;
	}

	/*
	 * Unimplemented FPU instructions/datatypes.
	 */
	case T_FPEMULI|T_USER:
	case T_FPEMULD|T_USER:
#ifdef FPU_EMULATE
		if (fpu_emulate(fp, &l->l_addr->u_pcb.pcb_fpregs,
			&ksi) == 0)
			; /* XXX - Deal with tracing? (fp->f_sr & PSL_T) */
#else
		uprintf("pid %d killed: no floating point support.\n",
			p->p_pid);
		ksi.ksi_signo = SIGILL;
		ksi.ksi_code = ILL_ILLOPC;
#endif
		break;

	case T_COPERR:		/* Kernel coprocessor violation */
	case T_FMTERR:		/* Kernel format error */
	case T_FMTERR|T_USER:	/* User format error */
		/*
		 * The user has most likely trashed the RTE or FP state info
		 * in the stack frame of a signal handler.
		 */
		printf("pid %d: kernel %s exception\n", p->p_pid,
		    type==T_COPERR ? "coprocessor" : "format");
		type |= T_USER;
		mutex_enter(p->p_lock);
		SIGACTION(p, SIGILL).sa_handler = SIG_DFL;
		sigdelset(&p->p_sigctx.ps_sigignore, SIGILL);
		sigdelset(&p->p_sigctx.ps_sigcatch, SIGILL);
		sigdelset(&l->l_sigmask, SIGILL);
		mutex_exit(p->p_lock);
		ksi.ksi_signo = SIGILL;
		ksi.ksi_addr = (void *)(int)fp->f_format;
				/* XXX was ILL_RESAD_FAULT */
		ksi.ksi_code = (type == T_COPERR) ?
			ILL_COPROC : ILL_ILLOPC;
		break;

	/*
	 * XXX: Trace traps are a nightmare.
	 *
	 *	HP-UX uses trap #1 for breakpoints,
	 *	NetBSD/m68k uses trap #2,
	 *	SUN 3.x uses trap #15,
	 *	DDB and KGDB uses trap #15 (for kernel breakpoints;
	 *	handled elsewhere).
	 *
	 * NetBSD and HP-UX traps both get mapped by locore.s into T_TRACE.
	 * SUN 3.x traps get passed through as T_TRAP15 and are not really
	 * supported yet.
	 *
	 * XXX: We should never get kernel-mode T_TRAP15 because
	 * XXX: locore.s now gives it special treatment.
	 */
	case T_TRAP15:		/* SUN trace trap */
#ifdef DEBUG
		printf("unexpected kernel trace trap, type = %d\n", type);
		printf("program counter = 0x%x\n", fp->f_pc);
#endif
		fp->f_sr &= ~PSL_T;
		ksi.ksi_signo = SIGTRAP;
		break;

	case T_TRACE|T_USER:	/* user trace trap */
#ifdef COMPAT_SUNOS
		/*
		 * SunOS uses Trap #2 for a "CPU cache flush".
		 * Just flush the on-chip caches and return.
		 */
		if (p->p_emul == &emul_sunos) {
			ICIA();
			DCIU();
			return;
		}
#endif
		/* FALLTHROUGH */
	case T_TRACE:		/* tracing a trap instruction */
	case T_TRAP15|T_USER:	/* SUN user trace trap */
		fp->f_sr &= ~PSL_T;
		ksi.ksi_signo = SIGTRAP;
		break;

	case T_ASTFLT:		/* System async trap, cannot happen */
		goto dopanic;

	case T_ASTFLT|T_USER:	/* User async trap. */
		astpending = 0;
		/*
		 * We check for software interrupts first.  This is because
		 * they are at a higher level than ASTs, and on a VAX would
		 * interrupt the AST.  We assume that if we are processing
		 * an AST that we must be at IPL0 so we don't bother to
		 * check.  Note that we ensure that we are at least at SIR
		 * IPL while processing the SIR.
		 */
		spl1();
		/* fall into... */

	case T_SSIR:		/* Software interrupt */
	case T_SSIR|T_USER:
		/*
		 * If this was not an AST trap, we are all done.
		 */
		if (type != (T_ASTFLT|T_USER)) {
			uvmexp.traps--;
			return;
		}
		spl0();
		if (l->l_pflag & LP_OWEUPC) {
			l->l_pflag &= ~LP_OWEUPC;
			ADDUPROF(l);
		}
		if (curcpu()->ci_want_resched)
			preempt();
		goto out;

	case T_MMUFLT:		/* Kernel mode page fault */
		/*
		 * If we were doing profiling ticks or other user mode
		 * stuff from interrupt code, Just Say No.
		 */
		if (l->l_addr->u_pcb.pcb_onfault == fubail ||
		    l->l_addr->u_pcb.pcb_onfault == subail)
			goto copyfault;
		/* fall into... */

	case T_MMUFLT|T_USER:	/* page fault */
	    {
		vaddr_t va;
		struct vmspace *vm = p->p_vmspace;
		struct vm_map *map;
		int rv;
		vm_prot_t ftype;
		extern struct vm_map *kernel_map;

#ifdef DEBUG
		if ((mmudebug & MDB_WBFOLLOW) || MDB_ISPID(p->p_pid))
		printf("trap: T_MMUFLT pid=%d, code=%x, v=%x, pc=%x, sr=%x\n",
			p->p_pid, code, v, fp->f_pc, fp->f_sr);
#endif
		/*
		 * It is only a kernel address space fault iff:
		 *	1. (type & T_USER) == 0 and
		 *	2. pcb_onfault not set or
		 *	3. pcb_onfault set but supervisor data fault
		 * The last can occur during an exec() copyin where the
		 * argument space is lazy-allocated.
		 */
		if (type == T_MMUFLT &&
		    (!l->l_addr->u_pcb.pcb_onfault || KDFAULT(code)))
			map = kernel_map;
		else {
			map = vm ? &vm->vm_map : kernel_map;
			if ((l->l_flag & LW_SA)
			    && (~l->l_pflag & LP_SA_NOBLOCK)) {
				l->l_savp->savp_faultaddr = (vaddr_t)v;
				l->l_pflag |= LP_SA_PAGEFAULT;
			}
		}
		if (WRFAULT(code))
			ftype = VM_PROT_WRITE;
		else
			ftype = VM_PROT_READ;
		va = trunc_page((vaddr_t)v);
#ifdef DEBUG
		if (map == kernel_map && va == 0) {
			printf("trap: bad kernel access at %x\n", v);
			goto dopanic;
		}
#endif
		rv = uvm_fault(map, va, ftype);
#ifdef DEBUG
		if (rv && MDB_ISPID(p->p_pid))
			printf("uvm_fault(%p, 0x%lx, 0x%x) -> 0x%x\n",
			    map, va, ftype, rv);
#endif
		/*
		 * If this was a stack access, we keep track of the maximum
		 * accessed stack size.  Also, if vm_fault gets a protection
		 * failure, it is due to accessing the stack region outside
		 * the current limit and we need to reflect that as an access
		 * error.
		 */
		if (rv == 0) {
			if (map != kernel_map && (void *)va >= vm->vm_maxsaddr)
				uvm_grow(p, va);

			if (type == T_MMUFLT) {
#if defined(M68040)
				if (mmutype == MMU_68040)
					(void)writeback(fp, 1);
#endif
				return;
			}
			l->l_pflag &= ~LP_SA_PAGEFAULT;
			goto out;
		}
		if (rv == EACCES) {
			ksi.ksi_code = SEGV_ACCERR;
			rv = EFAULT;
		} else
			ksi.ksi_code = SEGV_MAPERR;
		if (type == T_MMUFLT) {
			if (l->l_addr->u_pcb.pcb_onfault)
				goto copyfault;
			printf("uvm_fault(%p, 0x%lx, 0x%x) -> 0x%x\n",
			    map, va, ftype, rv);
			printf("  type %x, code [mmu,,ssw]: %x\n",
				type, code);
			goto dopanic;
		}
		l->l_pflag &= ~LP_SA_PAGEFAULT;
		ksi.ksi_addr = (void *)v;
		if (rv == ENOMEM) {
			printf("UVM: pid %d (%s), uid %d killed: out of swap\n",
			       p->p_pid, p->p_comm,
			       l->l_cred ?
			       kauth_cred_geteuid(l->l_cred) : -1);
			ksi.ksi_signo = SIGKILL;
		} else {
			ksi.ksi_signo = SIGSEGV;
		}
		break;
	    }
	}
	if (ksi.ksi_signo)
		trapsignal(l, &ksi);
	if ((type & T_USER) == 0)
		return;
out:
	userret(l, fp, sticks, v, 1); 
}