gonzui


Format: Advanced Search

t2ex/t2ex_source/kernel/sysmain/src/ref_command.cbare sourcepermlink (0.03 seconds)

Search this content:

    1: /*
    2:  *----------------------------------------------------------------------
    3:  *    T2EX Software Package
    4:  *
    5:  *    Copyright 2012 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 2012/12/12.
   10:  *    Modified by T-Engine Forum at 2014/07/31.
   11:  *    Modified by TRON Forum(http://www.tron.org/) at 2015/06/04.
   12:  *
   13:  *----------------------------------------------------------------------
   14:  */
   15: /*
   16:  * This software package is available for use, modification, 
   17:  * and redistribution in accordance with the terms of the attached 
   18:  * T-License 2.x.
   19:  * If you want to redistribute the source code, you need to attach 
   20:  * the T-License 2.x document.
   21:  * There's no obligation to publish the content, and no obligation 
   22:  * to disclose it to the TRON Forum if you have modified the 
   23:  * software package.
   24:  * You can also distribute the modified source code. In this case, 
   25:  * please register the modification to T-Kernel traceability service.
   26:  * People can know the history of modifications by the service, 
   27:  * and can be sure that the version you have inherited some 
   28:  * modification of a particular version or not.
   29:  *
   30:  *    http://trace.tron.org/tk/?lang=en
   31:  *    http://trace.tron.org/tk/?lang=ja
   32:  *
   33:  * As per the provisions of the T-License 2.x, TRON Forum ensures that 
   34:  * the portion of the software that is copyrighted by Ken Sakamura or 
   35:  * the TRON Forum does not infringe the copyrights of a third party.
   36:  * However, it does not make any warranty other than this.
   37:  * DISCLAIMER: TRON Forum and Ken Sakamura shall not be held
   38:  * responsible for any consequences or damages caused directly or
   39:  * indirectly by the use of this software package.
   40:  *
   41:  * The source codes in bsd_source.tar.gz in this software package are 
   42:  * derived from NetBSD or OpenBSD and not covered under T-License 2.x.
   43:  * They need to be changed or redistributed according to the 
   44:  * representation of each source header.
   45:  */
   46: 
   47: /*
   48:  *      @(#)ref_command.c
   49:  *
   50:  */
   51: 
   52: #include <tk/dbgspt.h>
   53: #include <sys/misc.h>
   54: 
   55: /*
   56:         display exinf
   57: */
   58: LOCAL   void      dsp_exinf(VP exinf)
   59: {
   60:         INT    i;
   61:         UB     *p = (UB*)&exinf;
   62: 
   63:         if (exinf != NULL) {
   64:                 P("%08x", exinf);
   65:                 for (i = 0; i < 4; i++) {
   66:                         if (p[i] != 0 && (p[i] < 0x20 || p[i] > 0x7E)) break;
   67:                 }
   68:                 if (i >= 4) P(" %.4s", p);
   69:         }
   70:         P("\n");
   71: }
   72: /*
   73:         dump system memory status
   74: */
   75: LOCAL   void      dump_sysmem(void)
   76: {
   77:         T_RSMB ms;
   78:         W      ratio;
   79:         ER     er;
   80: 
   81:         er = tk_ref_smb(&ms);
   82:         if (er < E_OK) {
   83:                 P("ERR [%#x]\n", er);
   84:                 return;
   85:         }
   86:         P("MEMORY: ");
   87:         if (ms.total <= 0 || ms.free < 0) {
   88:                 P("unknown\n");
   89:                 return;
   90:         }
   91:         ratio = 100 - (ms.free * 100 / ms.total);
   92:         P("Blksz=%d Total=%d (%d KB) Free=%d (%d KB) [%d %% used]\n",
   93:                 ms.blksz, ms.total, ms.total * (ms.blksz / 1024),
   94:                 ms.free, ms.free * (ms.blksz / 1024), ratio);
   95: }
   96: /*
   97:         dump task status
   98: */
   99: LOCAL   void      dump_task(ID tskid)
  100: {
  101:         T_RTSK ref;
  102:         T_ITSK inf;
  103:         ID     id, maxid;
  104:         ER     er;
  105:         char   *p;
  106: 
  107:         maxid = 0;
  108:         tk_get_cfn((UB*)"TMaxTskId", &maxid, 1);
  109:         P("TSK STATE (MAX:%d)\n", maxid);
  110: 
  111:         if (tskid > 0) maxid = tskid;
  112:         else           tskid = 1;
  113: 
  114:         P("TID PRI:BPR SLT WUP SUS STS(*:NODISWAI)  ST+UT(x10) RID EXINF\n");
  115: 
  116:         for (id = tskid; id <= maxid; id++) {
  117:                 er = tk_ref_tsk(id, &ref);
  118:                 if (er < E_OK) {
  119:                         if (er != E_NOEXS)
  120:                                 P("ERR id = %3d [%#x]\n", id, er);
  121:                         continue;
  122:                 }
  123: 
  124:                 /*   TID PRI:BPR SLT WUP SUS */
  125:                 P("%3d %3d:%3d %3d %3d %3d ",
  126:                         id, ref.tskpri, ref.tskbpri, ref.slicetime,
  127:                         ref.wupcnt, ref.suscnt);
  128: 
  129:                 /* STS */
  130:                 switch (ref.tskstat & ~TTS_NODISWAI) {
  131:                   case TTS_RUN:       p = "RUN"; break;
  132:                   case TTS_RDY:       p = "RDY"; break;
  133:                   case TTS_WAI:       p = "WAI"; break;
  134:                   case TTS_SUS:       p = "SUS"; break;
  135:                   case TTS_WAS:       p = "WAS"; break;
  136:                   case TTS_DMT:       p = "DMT"; break;
  137:                   default:            p = "???";
  138:                 }
  139:                 P(p);
  140: 
  141:                 if ((ref.tskstat & TTS_WAI) != 0) {
  142:                         UINT tev = 0;
  143: 
  144:                         switch (ref.tskwait) {
  145:                           case TTW_SLP:  p = "SLP";  break;
  146:                           case TTW_DLY:  p = "DLY";  break;
  147:                           case TTW_SEM:  p = "SEM";  break;
  148:                           case TTW_FLG:  p = "FLG";  break;
  149:                           case TTW_MBX:  p = "MBX";  break;
  150:                           case TTW_MTX:  p = "MTX";  break;
  151:                           case TTW_SMBF: p = "SMBF"; break;
  152:                           case TTW_RMBF: p = "RMBF"; break;
  153:                           case TTW_CAL:  p = "CAL";  break;
  154:                           case TTW_ACP:  p = "ACP";  break;
  155:                           case TTW_RDV:  p = "RDV";  break;
  156:                           case TTW_MPF:  p = "MPF";  break;
  157:                           case TTW_MPL:  p = "MPL";  break;
  158:                           default:
  159:                                 tev = (ref.tskwait >> 16) & 0xff;
  160:                                 p = (tev != 0)? "EV": "???";
  161:                         }
  162:                         if (tev == 0) P("-%-5s", p);
  163:                         else         P("-%2s:%02x", p, tev);
  164: 
  165:                         P("%c", ((ref.tskstat & TTS_NODISWAI) != 0)? '*':' ');
  166: 
  167:                         if (ref.wid > 0)     P("[%3d]", ref.wid);
  168:                         else                 P("     ");
  169:                 } else {
  170:                         P("            ");
  171:                 }
  172: 
  173:                 /* ST+UT RID */
  174:                 tk_inf_tsk(id, &inf, FALSE);
  175:                 P(" %5d+%-5d %3d ", inf.stime / 10,
  176:                                         inf.utime / 10, tk_get_rid(id));
  177:                 dsp_exinf(ref.exinf);
  178:         }
  179: }
  180: /*
  181:         dump semaphore status
  182: */
  183: LOCAL   void      dump_semaphore(ID semid)
  184: {
  185:         T_RSEM ref;
  186:         ID     id, maxid;
  187:         ER     er;
  188: 
  189:         maxid = 0;
  190:         tk_get_cfn((UB*)"TMaxSemId", &maxid, 1);
  191:         P("SEM STATE (MAX:%d):\n", maxid);
  192: 
  193:         if (semid > 0) maxid = semid;
  194:         else           semid = 1;
  195: 
  196:         P(" ID WID CNT EXINF\n");
  197: 
  198:         for (id = semid; id <= maxid; id++) {
  199:                 er = tk_ref_sem(id, &ref);
  200:                 if (er < E_OK) {
  201:                         if (er != E_NOEXS)
  202:                                 P("ERR id = %3d [%#x]\n", id, er);
  203:                         continue;
  204:                 }
  205:                 P("%3d %3d %3d ", id, ref.wtsk, ref.semcnt);
  206:                 dsp_exinf(ref.exinf);
  207:         }
  208: }
  209: /*
  210:         dump mutex status
  211: */
  212: LOCAL   void      dump_mutex(ID mtxid)
  213: {
  214:         T_RMTX ref;
  215:         ID     id, maxid;
  216:         ER     er;
  217: 
  218:         maxid = 0;
  219:         tk_get_cfn((UB*)"TMaxMtxId", &maxid, 1);
  220:         P("MTX STATE (MAX:%d):\n", maxid);
  221: 
  222:         if (mtxid > 0) maxid = mtxid;
  223:         else           mtxid = 1;
  224: 
  225:         P(" ID HID WID EXINF\n");
  226: 
  227:         for (id = mtxid; id <= maxid; id++) {
  228:                 er = tk_ref_mtx(id, &ref);
  229:                 if (er < E_OK) {
  230:                         if (er != E_NOEXS)
  231:                                 P("ERR id = %3d [%#x]\n", id, er);
  232:                         continue;
  233:                 }
  234:                 P("%3d %3d %3d ", id, ref.htsk, ref.wtsk);
  235:                 dsp_exinf(ref.exinf);
  236:         }
  237: }
  238: /*
  239:         dump event flag status
  240: */
  241: LOCAL   void      dump_eventflag(ID flgid)
  242: {
  243:         T_RFLG ref;
  244:         ID     id, maxid;
  245:         ER     er;
  246: 
  247:         maxid = 0;
  248:         tk_get_cfn((UB*)"TMaxFlgId", &maxid, 1);
  249:         P("FLG STATE (MAX:%d):\n", maxid);
  250: 
  251:         if (flgid > 0) maxid = flgid;
  252:         else           flgid = 1;
  253: 
  254:         P(" ID WID PTN      EXINF\n");
  255: 
  256:         for (id = flgid; id <= maxid; id++) {
  257:                 er = tk_ref_flg(id, &ref);
  258:                 if (er < E_OK) {
  259:                         if (er != E_NOEXS)
  260:                                 P("ERR id = %3d [%#x]\n", id, er);
  261:                         continue;
  262:                 }
  263:                 P("%3d %3d %08x ", id, ref.wtsk, ref.flgptn);
  264:                 dsp_exinf(ref.exinf);
  265:         }
  266: }
  267: /*
  268:         dump mailbox status
  269: */
  270: LOCAL   void      dump_mailbox(ID mbxid)
  271: {
  272:         T_RMBX ref;
  273:         ID     id, maxid;
  274:         ER     er;
  275: 
  276:         maxid = 0;
  277:         tk_get_cfn((UB*)"TMaxMbxId", &maxid, 1);
  278:         P("MBX STATE (MAX:%d):\n", maxid);
  279: 
  280:         if (mbxid > 0) maxid = mbxid;
  281:         else           mbxid = 1;
  282: 
  283:         P(" ID WID MSG      EXINF\n");
  284: 
  285:         for (id = mbxid; id <= maxid; id++) {
  286:                 er = tk_ref_mbx(id, &ref);
  287:                 if (er < E_OK) {
  288:                         if (er != E_NOEXS)
  289:                                 P("ERR id = %3d [%#x]\n", id, er);
  290:                         continue;
  291:                 }
  292:                 P("%3d %3d %08x ", id, ref.wtsk, ref.pk_msg);
  293:                 dsp_exinf(ref.exinf);
  294:         }
  295: }
  296: /*
  297:         dump message buffer status
  298: */
  299: LOCAL   void      dump_messagebuf(ID mbfid)
  300: {
  301:         T_RMBF ref;
  302:         ID     id, maxid;
  303:         ER     er;
  304: 
  305:         maxid = 0;
  306:         tk_get_cfn((UB*)"TMaxMbfId", &maxid, 1);
  307:         P("MBF STATE (MAX:%d):\n", maxid);
  308: 
  309:         if (mbfid > 0) maxid = mbfid;
  310:         else           mbfid = 1;
  311: 
  312:         P(" ID WID SID  MSGSZ   FREE    MAX EXINF\n");
  313: 
  314:         for (id = mbfid; id <= maxid; id++) {
  315:                 er = tk_ref_mbf(id, &ref);
  316:                 if (er < E_OK) {
  317:                         if (er != E_NOEXS)
  318:                                 P("ERR id = %3d [%#x]\n", id, er);
  319:                         continue;
  320:                 }
  321:                 P("%3d %3d %3d %6d %6d %6d ", id, ref.wtsk, ref.stsk,
  322:                                         ref.msgsz, ref.frbufsz, ref.maxmsz);
  323:                 dsp_exinf(ref.exinf);
  324:         }
  325: }
  326: /*
  327:         dump rendezvous port status
  328: */
  329: LOCAL   void      dump_rdvport(ID porid)
  330: {
  331:         T_RPOR ref;
  332:         ID     id, maxid;
  333:         ER     er;
  334: 
  335:         maxid = 0;
  336:         tk_get_cfn((UB*)"TMaxPorId", &maxid, 1);
  337:         P("POR STATE (MAX:%d):\n", maxid);
  338: 
  339:         if (porid > 0) maxid = porid;
  340:         else           porid = 1;
  341: 
  342:         P(" ID WID AID MAXCSZ MAXRSZ EXINF\n");
  343: 
  344:         for (id = porid; id <= maxid; id++) {
  345:                 er = tk_ref_por(id, &ref);
  346:                 if (er < E_OK) {
  347:                         if (er != E_NOEXS)
  348:                                 P("ERR id = %3d [%#x]\n", id, er);
  349:                         continue;
  350:                 }
  351:                 P("%3d %3d %3d %6d %6d ", id, ref.wtsk, ref.atsk,
  352:                                         ref.maxcmsz, ref.maxrmsz);
  353:                 dsp_exinf(ref.exinf);
  354:         }
  355: }
  356: /*
  357:         dump memory pool status
  358: */
  359: LOCAL   void      dump_memorypool(ID mplid)
  360: {
  361:         T_RMPL ref;
  362:         ID     id, maxid;
  363:         ER     er;
  364: 
  365:         maxid = 0;
  366:         tk_get_cfn((UB*)"TMaxMplId", &maxid, 1);
  367:         P("MPL STATE (MAX:%d):\n", maxid);
  368: 
  369:         if (mplid > 0) maxid = mplid;
  370:         else           mplid = 1;
  371: 
  372:         P(" ID WID   FREE    MAX EXINF\n");
  373: 
  374:         for (id = mplid; id <= maxid; id++) {
  375:                 er = tk_ref_mpl(id, &ref);
  376:                 if (er < E_OK) {
  377:                         if (er != E_NOEXS)
  378:                                 P("ERR id = %3d [%#x]\n", id, er);
  379:                         continue;
  380:                 }
  381:                 P("%3d %3d %6d %6d ", id, ref.wtsk, ref.frsz, ref.maxsz);
  382:                 dsp_exinf(ref.exinf);
  383:         }
  384: }
  385: /*
  386:         dump fixed memory pool status
  387: */
  388: LOCAL   void      dump_fixmempool(ID mpfid)
  389: {
  390:         T_RMPF ref;
  391:         ID     id, maxid;
  392:         ER     er;
  393: 
  394:         maxid = 0;
  395:         tk_get_cfn((UB*)"TMaxMpfId", &maxid, 1);
  396:         P("MPF STATE (MAX:%d):\n", maxid);
  397: 
  398:         if (mpfid > 0) maxid = mpfid;
  399:         else           mpfid = 1;
  400: 
  401:         P(" ID WID FREE EXINF\n");
  402: 
  403:         for (id = mpfid; id <= maxid; id++) {
  404:                 er = tk_ref_mpf(id, &ref);
  405:                 if (er < E_OK) {
  406:                         if (er != E_NOEXS)
  407:                                 P("ERR id = %3d [%#x]\n", id, er);
  408:                         continue;
  409:                 }
  410:                 P("%3d %3d %4d ", id, ref.wtsk, ref.frbcnt);
  411:                 dsp_exinf(ref.exinf);
  412:         }
  413: }
  414: /*
  415:         dump cyclic handler status
  416: */
  417: LOCAL   void      dump_cyclichdr(ID cycid)
  418: {
  419:         T_RCYC ref;
  420:         ID     id, maxid;
  421:         ER     er;
  422: 
  423:         maxid = 0;
  424:         tk_get_cfn((UB*)"TMaxCycId", &maxid, 1);
  425:         P("CYC STATE (MAX:%d):\n", maxid);
  426: 
  427:         if (cycid > 0) maxid = cycid;
  428:         else           cycid = 1;
  429: 
  430:         P(" ID STS   TIME EXINF\n");
  431: 
  432:         for (id = cycid; id <= maxid; id++) {
  433:                 er = tk_ref_cyc(id, &ref);
  434:                 if (er < E_OK) {
  435:                         if (er != E_NOEXS)
  436:                                 P("ERR id = %3d [%#x]\n", id, er);
  437:                         continue;
  438:                 }
  439:                 P("%3d %3s %6d ", id, ((ref.cycstat & TCYC_STA) != 0) ?
  440:                                         "STA" : "", ref.lfttim);
  441:                 dsp_exinf(ref.exinf);
  442:         }
  443: }
  444: /*
  445:         dump alarm handler status
  446: */
  447: LOCAL   void      dump_alarmhdr(ID almid)
  448: {
  449:         T_RALM ref;
  450:         ID     id, maxid;
  451:         ER     er;
  452: 
  453:         maxid = 0;
  454:         tk_get_cfn((UB*)"TMaxAlmId", &maxid, 1);
  455:         P("ALM STATE (MAX:%d):\n", maxid);
  456: 
  457:         if (almid > 0) maxid = almid;
  458:         else           almid = 1;
  459: 
  460:         P(" ID STS   TIME EXINF\n");
  461: 
  462:         for (id = almid; id <= maxid; id++) {
  463:                 er = tk_ref_alm(id, &ref);
  464:                 if (er < E_OK) {
  465:                         if (er != E_NOEXS)
  466:                                 P("ERR id = %3d [%#x]\n", id, er);
  467:                         continue;
  468:                 }
  469:                 P("%3d %3s %6d ", id, ((ref.almstat & TALM_STA) != 0) ?
  470:                                         "STA" : "", ref.lfttim);
  471:                 dsp_exinf(ref.exinf);
  472:         }
  473: }
  474: /*
  475:         dump task registers
  476: */
  477: LOCAL   void      dump_task_register(ID tskid)
  478: {
  479:         T_REGS greg;
  480:         T_EIT  ereg;
  481:         T_CREGS        creg;
  482:         TD_RTSK        rtsk;
  483:         ER     er;
  484: 
  485:         P("TASK REGISTER (TID:%d)\n", tskid);
  486: 
  487:         er = tk_get_reg(tskid, &greg, &ereg, &creg);
  488:         if (er < E_OK) {
  489:                 P("ERR [%#x]\n", er);
  490:                 return;
  491:         }
  492: 
  493:         PrintTaskRegister((void*)&P, &greg, &ereg, &creg);
  494: 
  495:         er = td_ref_tsk(tskid, &rtsk);
  496:         if (er < E_OK) return;
  497: 
  498:         P("SYSTEM STACK AREA: 0x%08x - 0x%08x\n",
  499:                         (UW)rtsk.isstack - rtsk.sstksz, (UW)rtsk.isstack);
  500:         if (rtsk.stksz > 0) {
  501:                 P("  USER STACK AREA: 0x%08x - 0x%08x\n",
  502:                         (UW)rtsk.istack - rtsk.stksz, (UW)rtsk.istack);
  503:         } else {
  504:                 P("  USER STACK AREA: %10s - 0x%08x\n",
  505:                         "?", (UW)rtsk.istack);
  506:         }
  507: }
  508: /*
  509:         ref command
  510: */
  511: LOCAL   void      cmd_ref(INT ac, B *av[])
  512: {
  513:         INT    num;
  514: 
  515:         if (ac < 2) goto usage;
  516:         num = (ac >= 3) ? strtol(av[2], NULL, 0) : 0;
  517: 
  518:         if (strcmp(av[1], "mem") == 0) {
  519:                 dump_sysmem();
  520:         } else if (strcmp(av[1], "tsk") == 0) {
  521:                 dump_task(num);
  522:         } else if (strcmp(av[1], "sem") == 0) {
  523:                 dump_semaphore(num);
  524:         } else if (strcmp(av[1], "flg") == 0) {
  525:                 dump_eventflag(num);
  526:         } else if (strcmp(av[1], "mbx") == 0) {
  527:                 dump_mailbox(num);
  528:         } else if (strcmp(av[1], "mbf") == 0) {
  529:                 dump_messagebuf(num);
  530:         } else if (strcmp(av[1], "por") == 0) {
  531:                 dump_rdvport(num);
  532:         } else if (strcmp(av[1], "mtx") == 0) {
  533:                 dump_mutex(num);
  534:         } else if (strcmp(av[1], "mpl") == 0) {
  535:                 dump_memorypool(num);
  536:         } else if (strcmp(av[1], "mpf") == 0) {
  537:                 dump_fixmempool(num);
  538:         } else if (strcmp(av[1], "cyc") == 0) {
  539:                 dump_cyclichdr(num);
  540:         } else if (strcmp(av[1], "alm") == 0) {
  541:                 dump_alarmhdr(num);
  542:         } else if (strcmp(av[1], "reg") == 0) {
  543:                 if (ac < 3) goto usage;
  544:                 dump_task_register(num);
  545:         } else {
  546: usage:
  547:                 P("ref  item [num]   dump kernel resources\n");
  548:                 P("  item: mem,tsk,sem,flg,mbx,mbf,por,mtx,mpl,mpf,cyc,alm\n");
  549:                 P("ref  reg tskid    dump task registers\n");
  550:         }
  551: }
  552: