gonzui


Format: Advanced Search

tkernel_2/monitor/cmdsvc/src/armv6/disassemble.cbare sourcepermlink (0.02 seconds)

Search this content:

    1: /*
    2:  *----------------------------------------------------------------------
    3:  *    T-Kernel 2.0 Software Package
    4:  *
    5:  *    Copyright 2011 by Ken Sakamura.
    6:  *    This software is distributed under the latest version of T-License 2.x.
    7:  *----------------------------------------------------------------------
    8:  *
    9:  *    Released by T-Engine Forum(http://www.t-engine.org/) at 2011/05/17.
   10:  *    Modified by T-Engine Forum at 2013/03/04.
   11:  *    Modified by TRON Forum(http://www.tron.org/) at 2015/06/01.
   12:  *
   13:  *----------------------------------------------------------------------
   14:  */
   15: 
   16: /*
   17:  *      disasemble.c
   18:  *
   19:  *       disassember
   20:  */
   21: 
   22: #include "../cmdsvc.h"
   23: 
   24: LOCAL   UB        *make_hex(UB *str, UB byte)
   25: {
   26:         LOCAL  const UB hex[] = "0123456789ABCDEF";
   27: 
   28:         *str++ = hex[(byte >> 4) & 0x0f];
   29:         *str++ = hex[(byte >> 0) & 0x0f];
   30: 
   31:         return str;
   32: }
   33: 
   34: /*
   35:         disassembler main body
   36: 
   37:         * disassembly is not fully done. But, during step tracing,
   38:           memory content is shown (this much is implemented).
   39:           the content of *naddr is meaningless
   40:  */
   41: EXPORT  ER       disAssemble(UW *saddr, UW *naddr, UB *str)
   42: {
   43:         W      len;
   44:         UW     inst, addr;
   45: 
   46:         len = (*saddr & 0x1) ? 2 : 4;          // Thumb or Arm instruction
   47:         addr = (*saddr &= ~(len - 1));         // address adjustment
   48: 
   49:         // extract op code
   50:         if (readMem(addr, &inst, len, 2) != len) return E_MACV;
   51: 
   52:         // binary dump
   53:         if (len == 4) {
   54:                 str = make_hex(str, inst >> 24);
   55:                 str = make_hex(str, inst >> 16);
   56:         }
   57:         str = make_hex(str, inst >> 8);
   58:         str = make_hex(str, inst >> 0);
   59: 
   60:         *str = '\0';
   61: 
   62:         return E_OK;
   63: }