Annotation of kernel/machdep/ppc/miniMonMachdep.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
        !             3:  *
        !             4:  * @APPLE_LICENSE_HEADER_START@
        !             5:  * 
        !             6:  * Portions Copyright (c) 1999 Apple Computer, Inc.  All Rights
        !             7:  * Reserved.  This file contains Original Code and/or Modifications of
        !             8:  * Original Code as defined in and that are subject to the Apple Public
        !             9:  * Source License Version 1.1 (the "License").  You may not use this file
        !            10:  * except in compliance with the License.  Please obtain a copy of the
        !            11:  * License at http://www.apple.com/publicsource and read it before using
        !            12:  * this file.
        !            13:  * 
        !            14:  * The Original Code and all software distributed under the License are
        !            15:  * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
        !            16:  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
        !            17:  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
        !            18:  * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
        !            19:  * License for the specific language governing rights and limitations
        !            20:  * under the License.
        !            21:  * 
        !            22:  * @APPLE_LICENSE_HEADER_END@
        !            23:  */
        !            24: 
        !            25: /*
        !            26:  * Copyright (c) 1997 Apple Computer, Inc.  All rights reserved.
        !            27:  * Copyright (c) 1994 NeXT Computer, Inc.  All rights reserved.
        !            28:  *
        !            29:  * machdep/ppc/miniMonMachdep.c
        !            30:  *
        !            31:  * Machine-dependent code for Remote Debugging Protocol
        !            32:  *
        !            33:  * March, 1997 Created.        Umesh Vaishampayan [[email protected]]
        !            34:  *
        !            35:  */
        !            36: 
        !            37: #include <sys/reboot.h>
        !            38: #include <kern/miniMonPrivate.h>
        !            39: 
        !            40: 
        !            41: static boolean_t ishex(char c)
        !            42: {
        !            43:     if ((c >= '0' && c <= '9') ||
        !            44:         (c >= 'a' && c <= 'f') ||
        !            45:        (c >= 'A' && c <= 'F'))
        !            46:            return TRUE;
        !            47:     return FALSE;
        !            48: }
        !            49: 
        !            50: static int xx(char c)
        !            51: {
        !            52:     if (c >= '0' && c <= '9')
        !            53:         return c - '0';
        !            54:     if (c >= 'a' && c <= 'f')
        !            55:         return c - 'a' + 10;
        !            56:     if (c >= 'A' && c <= 'F')
        !            57:         return c - 'A' + 10;
        !            58:     return 0;
        !            59: }
        !            60: 
        !            61: static unsigned int
        !            62: xtoi(char *str)
        !            63: {
        !            64:     unsigned int num = 0;
        !            65: 
        !            66:     while (*str && ishex(*str)) {
        !            67:         num = (16 * num) + xx(*str);
        !            68:         str++;
        !            69:     }
        !            70:     return num;
        !            71: }
        !            72: 
        !            73: static boolean_t
        !            74: miniMonDump(char *line)
        !            75: {
        !            76:     int addr, count;
        !            77:     static unsigned int *ptr = 0x10000;
        !            78:     static unsigned int old_count = 8;
        !            79:     int text;
        !            80: 
        !            81:     text = ((*line) == 't');
        !            82: 
        !            83:     /* Skip command name */
        !            84:     while (*line && (*line != ' ' && *line != '\t'))
        !            85:        line++;
        !            86:     /* Skip whitespace */
        !            87:     while (*line && (*line == ' ' || *line == '\t'))
        !            88:        line++;
        !            89:     addr = xtoi(line);
        !            90:     if (addr != 0)
        !            91:        ptr = (unsigned int *)addr;
        !            92:     /* Skip address */
        !            93:     while (*line && (*line != ' ' && *line != '\t'))
        !            94:        line++;
        !            95:     /* Skip whitespace */
        !            96:     while (*line && (*line == ' ' || *line == '\t'))
        !            97:        line++;
        !            98:     if (*line == 's') {
        !            99:        safe_prf(ptr);
        !           100:        return TRUE;
        !           101:     }
        !           102:     count = xtoi(line);
        !           103:     if (count == 0)
        !           104:        count = old_count;
        !           105:     else
        !           106:        old_count = count;
        !           107:     if (count > 1024) count = 1024;
        !           108:     safe_prf("%08x : ", ptr);
        !           109:     while (count > 0)
        !           110:        if( text) {
        !           111:           miniMonPutchar(*((char *)ptr)++);
        !           112:           count--;
        !           113:        } else {
        !           114:           safe_prf("%08x ",*ptr++);
        !           115:           count -= 4;
        !           116:        }
        !           117:     safe_prf("\n");
        !           118:     return TRUE;
        !           119: }
        !           120: 
        !           121: miniMonCommand_t miniMonMDCommands[] =
        !           122: {
        !           123:     {"dump", miniMonDump, "Dump memory"},
        !           124:     {"text", miniMonDump, "Dump text"},
        !           125:     {0,0,0}
        !           126: };
        !           127: 
        !           128: 
        !           129: /*
        !           130:  * Reboot without sync.
        !           131:  */
        !           132: boolean_t
        !           133: miniMonReboot(char *line)
        !           134: {
        !           135:   boot(RB_BOOT, RB_AUTOBOOT|RB_NOSYNC, "");
        !           136:   return FALSE;
        !           137: }
        !           138: 
        !           139: /*
        !           140:  * Halt with sync.
        !           141:  */
        !           142: boolean_t
        !           143: miniMonHalt(char *line)
        !           144: {
        !           145:   reboot_mach(RB_HALT);
        !           146:   return FALSE;
        !           147: }
        !           148: 
        !           149: boolean_t
        !           150: miniMonGdb(char *line)
        !           151: {
        !           152:     call_kdp();
        !           153:   return FALSE;
        !           154: }
        !           155: 
        !           156: int
        !           157: miniMonTryGetchar(void)
        !           158: {
        !           159:   return kmtrygetc();
        !           160: }
        !           161: 
        !           162: int
        !           163: miniMonGetchar(void)
        !           164: {
        !           165:   register int c;
        !           166:   do {
        !           167:     c = kmtrygetc();
        !           168:   } while (c == NO_CHAR);
        !           169:   switch (c) {
        !           170:   case '\177':
        !           171:     c = '\b';
        !           172:     break;
        !           173:   case '\r':
        !           174:     kmputc(0,'\r');
        !           175:     c = '\n';
        !           176:     break;
        !           177:   case 'u'&037:
        !           178:     c = '\025';
        !           179:     break;
        !           180:   default:
        !           181:     break;
        !           182:   }
        !           183:   kmputc(0,c);
        !           184:   return c;
        !           185: }
        !           186: 
        !           187: void
        !           188: miniMonPutchar(int ch)
        !           189: {
        !           190:     kmputc(0,ch);
        !           191: };
        !           192: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.