⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 debug_trans.c

📁 一个用在mips体系结构中的操作系统
💻 C
字号:
/* * Copyright (C) 1996-1998 by the Board of Trustees *    of Leland Stanford Junior University. *  * This file is part of the SimOS distribution.  * See LICENSE file for terms of the license.  * */#include <stdio.h>#include <sys/stat.h>#include <sys/types.h>#include <sys/mman.h>#include <fcntl.h>#include <disassembler.h>#include "mshade.h"#include "cp0.h"#include "tc.h"#include "stats.h"int trans_test_num_decoded;/* Dummy Functions */void callout(void) {}void mem_ref_wrapper(void) {}void phys_mem_ref_wrapper(void) {}void do_periodic_callout(void) {}void get_fc31(void){}void compare_and_swap(unsigned u, unsigned u1, unsigned u2){}void ReenterTC(void){}void continue_run(void) {}void continue_run_without_chaining(void) {}void Clear_Translation_State(){}void icache_coherence_flush( void ) {}int icache_coherence_is_code( PA pAddr ) { return 1;}void icache_coherence_mark_code( K0A start, K0A finish ) {}void icache_coherence_check( PA start, PA finish, VA vAddr ) {}void Embra_CX(void) {}int hw_counter_start( HW_counter* count ) {}int hw_counter_stop( HW_counter* count ) {}double sqrt(double d) {}K0A  mem_ref( VA vAddr, int new_state ) {}void  qc_downgrade( VA vAddr, int new_state ) {}void em_remap(void) {}void UPperiodic_callout(void) {}void CSpillFP(void) {}void FlashliteConfigDefaults(void) {}uint ICheckLevel;typedef struct {   uint addr;   char* name;}rout2name;static rout2name r2n[] = {   { (uint) callout, "callout" },   { (uint) mem_ref_wrapper, "mem_ref_wrapper" },   { (uint) phys_mem_ref_wrapper, "phys_mem_ref_wrapper" },   { (uint) do_periodic_callout, "do_periodic_callout" },   { (uint) compare_and_swap, "compare_and_swap" },   { (uint) continue_run, "continue_run" },   { (uint) continue_run_without_chaining, "continue_run_without_chaining"},};#define R2N_SIZE (sizeof(r2n)/sizeof(r2n[0]))/* Dummy Globals */int numCPUs;stats_t em_stats;/* Initialized globals */TC realtc;TC* tc = &realtc;CPUType emode;EmbraState PE_Space[1];EmbraState* PE = PE_Space;EmbraState* EMP = PE_Space;int is_R4000;int MPinUP;int Simcp0MustRunCPU(void){   return 1;}K0A non_excepting_tv( int cpuNum, VA va ){   return va;}K0A mem_translate( int cpuNum, VA vAddr ){   return vAddr;}ResultEm_TranslateVirtual(int cpuNum, VA vAddr, PA *pAddr, Em_accesstype act){   *pAddr = vAddr;   return NORMAL_CODE;}main(int argc, char** argv){   int fd;   unsigned* instr;   long len;   unsigned g1, g2, g3;   char buf[100];   unsigned i;   unsigned* code_ptr;   uint* trans_ptr;   uint* trans_end_ptr;   int c;   extern int optind;   uint map_addr = 0;   is_R4000 = 1;   emode = EMBRA_PAGE;   EMP[0].outTC = 1;   MPinUP = 0;   while ((c = getopt(argc, argv, "pckum")) != EOF) {      switch (c) {      case 'p':         emode = EMBRA_PAGE;         break;      case 'm':         MPinUP = 1;         break;      case 'c':         emode = EMBRA_CACHE;         break;      case 'k':         map_addr = 0x60000000;         break;      case 'u':         map_addr = 0;         break;      default:         printf("Usage: %s -p (page) -c (cache) -u (user) -k (kernel) -m (MPinUP)\n", argv[0]);      }   }   SimConfigDefaults();   tc = TC_init();   DecoderInit();   Translator_Init();   pc_tc_init();   dis_init( 0, 0, 0, 1);   fd = open( argv[optind], O_RDWR, 0);   if( fd == -1 ) {      printf("Can't open %s\n", argv[optind]);      perror("open");   }   len = lseek(fd,0,SEEK_END);   if( map_addr ) {      instr = (unsigned*)mmap((void*)map_addr, len, (PROT_READ),                              (MAP_PRIVATE|MAP_FIXED), fd, 0);      if( (int) instr != map_addr )         perror("mmap");   } else {      instr = (unsigned*)mmap((void*)0, len, (PROT_READ),                              (MAP_PRIVATE), fd, 0);      if( (int) instr == -1 )         perror("mmap");   }   code_ptr = instr;   while( (unsigned)code_ptr < ((unsigned)instr+len) ) {      int junk;      Translate( 0, code_ptr, &junk );      code_ptr = (unsigned*)          ((unsigned)code_ptr + (trans_test_num_decoded * sizeof(unsigned)));   }   if( map_addr ) {      trans_ptr = tc->kern_buf;      trans_end_ptr = (uint*)tc->kern_next;   } else {      trans_ptr = tc->exec_buf;      trans_end_ptr = (uint*)tc->next;   }   while( trans_ptr < trans_end_ptr ) {      int inst_type;      uint target;      inst_type = disasm( buf, (uint)trans_ptr, *trans_ptr, &g1, &target, &g3 );      trans_ptr++;      printf("%s", buf);      switch( inst_type ) {      case 1: {         int i;         for( i = 0; i < R2N_SIZE; i++ ) {            if( target == r2n[i].addr ) {               printf("  %s", r2n[i].name);               break;            }         }      }         break;      }      printf("\n");   }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -