|
|
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) 1993 NeXT Computer, Inc. All rights reserved.
27: *
28: * miniMonMachdep.c -- Machine-dependent code for mini-monitor.
29: *
30: * HISTORY
31: * 04-Oct-1993 Curtis Galloway at NeXT
32: * Created.
33: *
34: */
35:
36: #import <sys/reboot.h>
37: #import <kern/miniMonPrivate.h>
38: #import <kern/thread.h>
39:
40: #define N_BACKTRACE 6 // number of backtrace frames to print
41:
42: static boolean_t
43: miniMonBacktrace(char *line)
44: {
45: extern void *miniMonState;
46: extern void _i386_backtrace(void *, int);
47: int sum;
48:
49: /* Skip command name */
50: while (*line && (*line != ' ' && *line != '\t'))
51: line++;
52: /* Skip whitespace */
53: while (*line && (*line == ' ' || *line == '\t'))
54: line++;
55: for (sum = 0; *line && (*line >= '0' && *line <= '9'); line++)
56: sum = sum * 10 + (*line - '0');
57: if (sum == 0)
58: sum = N_BACKTRACE;
59:
60: printf("State pointer = 0x%x\n",miniMonState);
61: if (miniMonState) {
62: _i386_backtrace(miniMonState, sum);
63: }
64: return TRUE;
65: }
66:
67: static boolean_t ishex(char c)
68: {
69: if ((c >= '0' && c <= '9') ||
70: (c >= 'a' && c <= 'f') ||
71: (c >= 'A' && c <= 'F'))
72: return TRUE;
73: return FALSE;
74: }
75:
76: static int xx(char c)
77: {
78: if (c >= '0' && c <= '9')
79: return c - '0';
80: if (c >= 'a' && c <= 'f')
81: return c - 'a' + 10;
82: if (c >= 'A' && c <= 'F')
83: return c - 'A' + 10;
84: return 0;
85: }
86:
87: static unsigned int
88: xtoi(char *str)
89: {
90: unsigned int num = 0;
91:
92: while (*str && ishex(*str)) {
93: num = (16 * num) + xx(*str);
94: str++;
95: }
96: return num;
97: }
98:
99: static boolean_t
100: miniMonDump(char *line)
101: {
102: int addr, count;
103: static unsigned int *ptr;
104: static unsigned int old_count = 1;
105:
106: /* Skip command name */
107: while (*line && (*line != ' ' && *line != '\t'))
108: line++;
109: /* Skip whitespace */
110: while (*line && (*line == ' ' || *line == '\t'))
111: line++;
112: addr = xtoi(line);
113: if (addr != 0)
114: ptr = (unsigned int *)addr;
115: /* Skip address */
116: while (*line && (*line != ' ' && *line != '\t'))
117: line++;
118: /* Skip whitespace */
119: while (*line && (*line == ' ' || *line == '\t'))
120: line++;
121: if (*line == 's') {
122: safe_prf(ptr);
123: return TRUE;
124: }
125: count = xtoi(line);
126: if (count == 0)
127: count = old_count;
128: else
129: old_count = count;
130: if (count > 1024) count = 1024;
131: safe_prf("%08x : ", ptr);
132: while (count--)
133: safe_prf("%08x ",*ptr++);
134: safe_prf("\n");
135: return TRUE;
136: }
137:
138:
139: miniMonCommand_t miniMonMDCommands[] =
140: {
141: {"backtrace", miniMonBacktrace,
142: "Print stack backtrace"},
143: {"dump", miniMonDump,
144: "Dump memory"},
145: {0,0,0}
146: };
147:
148: /*
149: * Reboot without sync.
150: */
151: extern boolean_t
152: miniMonReboot(char *line)
153: {
154: keyboard_reboot();
155: return FALSE;
156: }
157:
158: /*
159: * Halt with sync.
160: */
161: extern boolean_t
162: miniMonHalt(char *line)
163: {
164: reboot_mach(RB_HALT);
165: return FALSE;
166: }
167:
168: extern boolean_t
169: miniMonGdb(char *line)
170: {
171: asm volatile("int3");
172: return FALSE;
173: }
174:
175: extern int
176: miniMonTryGetchar(void)
177: {
178: return kmtrygetc();
179: }
180:
181: extern int
182: miniMonGetchar(void)
183: {
184: register int c;
185: do {
186: c = kmtrygetc();
187: } while (c == NO_CHAR);
188: switch (c) {
189: case '\177':
190: c = '\b';
191: break;
192: case '\r':
193: kmputc(0,'\r');
194: c = '\n';
195: break;
196: case 'u'&037:
197: c = '\025';
198: break;
199: default:
200: break;
201: }
202: kmputc(0,c);
203: return c;
204: }
205:
206: extern void
207: miniMonPutchar(int c)
208: {
209: kmputc(0,c);
210: }
211:
212:
213:
214:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.