summaryrefslogtreecommitdiff
path: root/sys/arch/arm32/kshell/shell_shell.c
blob: 870e4a1434af6880bbc16e06936d2cea2764c898 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
/* $NetBSD: shell_shell.c,v 1.5 1996/04/19 20:15:36 mark Exp $ */

/*
 * Copyright (c) 1994-1996 Mark Brinicombe.
 * Copyright (c) 1994 Brini.
 * All rights reserved.
 *
 * This code is derived from software written for Brini by Mark Brinicombe
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *	This product includes software developed by Brini.
 * 4. The name of the company nor the name of the author may be used to
 *    endorse or promote products derived from this software without specific
 *    prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY BRINI ``AS IS'' AND ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL BRINI OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * RiscBSD kernel project
 *
 * shell_shell.c
 *
 * Debug / Monitor shell entry and commands
 *
 * Created      : 09/10/94
 */

/* Include standard header files */

#include <sys/param.h>
#include <sys/systm.h>
#include <sys/buf.h>
#include <sys/proc.h>
#include <sys/device.h>
#include <sys/vnode.h>
#include <vm/vm.h>

/* Local header files */

#include <machine/pmap.h>
#include <machine/katelib.h>
#include <machine/vidc.h>
#include <machine/rtc.h>

/* Declare global variables */

/* Local function prototypes */

char	*strchr __P((const char *, int));

void dumpb __P((u_char */*addr*/, int /*count*/));
void dumpw __P((u_char */*addr*/, int /*count*/));

int readstring __P((char *, int, char *, char *));

void debug_show_q_details __P((void));
void shell_disassem	__P((int argc, char *argv[]));
void shell_devices	__P((int argc, char *argv[]));
void shell_vmmap	__P((int argc, char *argv[]));
void shell_flush	__P((int argc, char *argv[]));
void shell_pextract	__P((int argc, char *argv[]));
void shell_vnode	__P((int argc, char *argv[]));
void debug_show_all_procs __P((int argc, char *argv[]));
void debug_show_callout	__P((int argc, char *argv[]));
void debug_show_fs	__P((int argc, char *argv[]));
void debug_show_vm_map	__P((vm_map_t map, char *text));
void debug_show_pmap	__P((pmap_t pmap));
void pmap_dump_pvs	__P((void));
void bootsync		__P((void));

/* Now for the main code */

/* readhex
 *
 * This routine interprets the input string as a sequence of hex characters
 * and returns it as an integer.
 */

int
readhex(buf)
	char *buf;
{
	int value;
	int nibble;

	if (buf == NULL)
		return(0);

/* skip any spaces */

	while (*buf == ' ')
		++buf;

/* return 0 if a zero length string is passed */

	if (*buf == 0)
		return(0);

/* Convert the characters */

	value = 0;

	while (*buf != 0 && strchr("0123456789abcdefABCDEF", *buf) != 0) {
		nibble = (*buf - '0');
		if (nibble > 9) nibble -= 7;
		if (nibble > 15) nibble -= 32;
		value = (value << 4) | nibble;
		++buf;
	}

	return(value);
}


/* poke - writes a byte/word to memory */

void
shell_poke(argc, argv)
	int argc;
	char *argv[];	
{
	u_int addr;
	u_int data;

	if (argc < 3) {
		printf("Syntax: poke[bw] <addr> <data>\n\r");
		return;
	}

/* Decode the two arguments */

	addr = readhex(argv[1]);
	data = readhex(argv[2]);

	if (argv[0][4] == 'b')
		WriteByte(addr, data);
	if (argv[0][4] == 'w')
		WriteWord(addr, data);
}


/* peek - reads a byte/word from memory*/

void
shell_peek(argc, argv)
	int argc;
	char *argv[];	
{
	u_int addr;
	u_int data;

	if (argc < 2) {
		printf("Syntax: peek[bw] <addr>\n\r");
		return;
	}

/* Decode the one argument */

	addr = readhex(argv[1]);

	if (argv[0][4] == 'b')
		data = ReadByte(addr);
	if (argv[0][4] == 'w')
		data = ReadWord(addr);

	printf("%08x : %08x\n\r", addr, data);
}


/* dumpb - dumps memory in bytes*/

void
shell_dumpb(argc, argv)
	int argc;
	char *argv[];	
{
	u_char *addr;
	int count;

	if (argc < 2) {
		printf("Syntax: dumpb <addr> [<bytes>]\n\r");
		return;
	}

/* Decode the one argument */

	addr = (u_char *)readhex(argv[1]);

	if (argc > 2)
		count = readhex(argv[2]);
	else
		count = 0x80;

	dumpb(addr, count);
}


/* dumpw - dumps memory in bytes*/

void
shell_dumpw(argc, argv)
	int argc;
	char *argv[];	
{
	u_char *addr;
	int count;

	if (argc < 2) {
		printf("Syntax: dumpw <addr> [<bytes>]\n\r");
		return;
	}

/* Decode the one argument */

	addr = (u_char *)readhex(argv[1]);

	if (argc > 2)
		count = readhex(argv[2]);
	else
		count = 0x80;

	dumpw(addr, count); 
}

  
/* vmmap - dumps the vmmap */

void
shell_vmmap(argc, argv)
	int argc;
	char *argv[];	
{
	u_char *addr;

	if (argc < 2) {
		printf("Syntax: vmmap <map addr>\n\r");
		return;
	}

/* Decode the one argument */

	addr = (u_char *)readhex(argv[1]);

	debug_show_vm_map((vm_map_t)addr, argv[1]);
}


/* pmap - dumps the pmap */

void
shell_pmap(argc, argv)
	int argc;
	char *argv[];	
{
	u_char *addr;

	if (argc < 2) {
		printf("Syntax: pmap <pmap addr>\n\r");
		return;
	}

/* Decode the one argument */

	addr = (u_char *)readhex(argv[1]);

	debug_show_pmap((pmap_t)addr);
}


/*
 * void shell_devices(int argc, char *argv[])
 *
 * Display all the devices
 */

extern struct cfdata cfdata[];
 
void
shell_devices(argc, argv)
	int argc;
	char *argv[];	
{
	struct cfdata *cf;
	struct cfdriver *cd;
	struct device *dv;
	int loop;
	char *state;

	printf(" driver  unit state     name\n");
	for (cf = cfdata; cf->cf_driver; ++cf) {
		cd = cf->cf_driver;
		if (cf->cf_fstate & FSTATE_FOUND)
			state = "FOUND    ";
		else
			state = "NOT FOUND";

		printf("%08x  %2d  %s %s\n", (u_int)cd, (u_int)cf->cf_unit,
		    state, cd->cd_name);

		if (cf->cf_fstate & FSTATE_FOUND) {
			for (loop = 0; loop < cd->cd_ndevs; ++loop) {
				dv = (struct device *)cd->cd_devs[loop];
				if (dv != 0)
					printf("                        %s (%08x)\n",
					    dv->dv_xname, (u_int) dv);
			}
		}
		printf("\n");
	} 
}


void
shell_reboot(argc, argv)
	int argc;
	char *argv[];	
{
	printf("Running shutdown hooks ...\n");
	doshutdownhooks();

	IRQdisable;
	boot0();
}

void
forceboot(argc, argv)
	int argc;
	char *argv[];	
{
	cmos_write(0x90, cmos_read(0x90) | 0x02);
	shell_reboot(0, NULL);
}


void
shell_flush(argc, argv)
	int argc;
	char *argv[];	
{
	idcflush();
	tlbflush();
}


void
shell_vmstat(argc, argv)
	int argc;
	char *argv[];	
{
	struct vmmeter sum;
    
	sum = cnt;
	(void)printf("%9u cpu context switches\n", sum.v_swtch);
	(void)printf("%9u device interrupts\n", sum.v_intr);
	(void)printf("%9u software interrupts\n", sum.v_soft);
	(void)printf("%9u traps\n", sum.v_trap);
	(void)printf("%9u system calls\n", sum.v_syscall);
	(void)printf("%9u total faults taken\n", sum.v_faults);
	(void)printf("%9u swap ins\n", sum.v_swpin);
	(void)printf("%9u swap outs\n", sum.v_swpout);
	(void)printf("%9u pages swapped in\n", sum.v_pswpin / CLSIZE);
	(void)printf("%9u pages swapped out\n", sum.v_pswpout / CLSIZE);
	(void)printf("%9u page ins\n", sum.v_pageins);
	(void)printf("%9u page outs\n", sum.v_pageouts);
	(void)printf("%9u pages paged in\n", sum.v_pgpgin);
	(void)printf("%9u pages paged out\n", sum.v_pgpgout);
	(void)printf("%9u pages reactivated\n", sum.v_reactivated);
	(void)printf("%9u intransit blocking page faults\n", sum.v_intrans);
	(void)printf("%9u zero fill pages created\n", sum.v_nzfod / CLSIZE);
	(void)printf("%9u zero fill page faults\n", sum.v_zfod / CLSIZE);
	(void)printf("%9u pages examined by the clock daemon\n", sum.v_scan);
	(void)printf("%9u revolutions of the clock hand\n", sum.v_rev);
	(void)printf("%9u VM object cache lookups\n", sum.v_lookups);
	(void)printf("%9u VM object hits\n", sum.v_hits);
	(void)printf("%9u total VM faults taken\n", sum.v_vm_faults);
	(void)printf("%9u copy-on-write faults\n", sum.v_cow_faults);
	(void)printf("%9u pages freed by daemon\n", sum.v_dfree);
	(void)printf("%9u pages freed by exiting processes\n", sum.v_pfree);
	(void)printf("%9u pages free\n", sum.v_free_count);
	(void)printf("%9u pages wired down\n", sum.v_wire_count);
	(void)printf("%9u pages active\n", sum.v_active_count);
	(void)printf("%9u pages inactive\n", sum.v_inactive_count);
	(void)printf("%9u bytes per page\n", sum.v_page_size);
}


void
shell_pextract(argc, argv)
	int argc;
	char *argv[];	
{
	u_char *addr;
	vm_offset_t pa;
	int pind;

	if (argc < 2) {
		printf("Syntax: pextract <addr>\n\r");
		return;
	}

/* Decode the one argument */

	addr = (u_char *)readhex(argv[1]);

	pa = pmap_extract(kernel_pmap, (vm_offset_t)addr);
	pind = pmap_page_index(pa);

	printf("va=%08x pa=%08x pind=%d\n", (u_int)addr, (u_int)pa, pind);
}


void
shell_vnode(argc, argv)
	int argc;
	char *argv[];	
{
	struct vnode *vp;

	if (argc < 2) {
		printf("Syntax: vnode <vp>\n\r");
		return;
	}

/* Decode the one argument */

	vp = (struct vnode *)readhex(argv[1]);

	printf("vp = %08x\n", (u_int)vp);
	printf("vp->v_type = %d\n", vp->v_type);
	printf("vp->v_flag = %ld\n", vp->v_flag);
	printf("vp->v_usecount = %d\n", vp->v_usecount);
	printf("vp->v_writecount = %d\n", vp->v_writecount);
	printf("vp->v_numoutput = %ld\n", vp->v_numoutput);

	vprint("vnode:", vp);
}

#if 0
void
shell_vndbuf(argc, argv)
	int argc;
	char *argv[];	
{
	struct vnode *vp;

	if (argc < 2) {
		printf("Syntax: vndbuf <vp>\n\r");
		return;
	}

/* Decode the one argument */

	vp = (struct vnode *)readhex(argv[1]);

	dumpvndbuf(vp);
}


void
shell_vncbuf(argc, argv)
	int argc;
	char *argv[];	
{
	struct vnode *vp;

	if (argc < 2) {
		printf("Syntax: vndbuf <vp>\n\r");
		return;
	}

/* Decode the one argument */

	vp = (struct vnode *)readhex(argv[1]);

	dumpvncbuf(vp);
}
#endif

/* shell - a crude shell */

int
shell()
{
	int quit = 0;
	char buffer[200];
	char *ptr;
	char *ptr1;
	int args;
	char *argv[20];

	printf("\nRiscBSD debug/monitor shell\n");
	printf("CTRL-D, exit or reboot to terminate\n\n");

	do {
/* print prompt */

		printf("kshell> ");

/* Read line from keyboard */

		if (readstring(buffer, 200, NULL, NULL) == -1)
			return(0);

		ptr = buffer;

/* Slice leading spaces */

		while (*ptr == ' ')
			++ptr;

/* Loop back if zero length string */

		if (*ptr == 0)
			continue;

/* Count the number of space separated args */

		args = 0;
		ptr1 = ptr;

		while (*ptr1 != 0) {
			if (*ptr1 == ' ') {
				++args;
				while (*ptr1 == ' ')
					++ptr1;
			} else
				++ptr1;
		}

/*
 * Construct the array of pointers to the args and terminate
 * each argument with 0x00
 */

		args = 0;
		ptr1 = ptr;

		while (*ptr1 != 0) {
			argv[args] = ptr1;
			++args;
			while (*ptr1 != ' ' && *ptr1 != 0)
				++ptr1;

			while (*ptr1 == ' ') {
				*ptr1 = 0;
				++ptr1;
			}
		}

		argv[args] = NULL;

/* Interpret commands */

		if (strcmp(argv[0], "exit") == 0)
			quit = 1;
#ifdef DDB
		else if (strcmp(argv[0], "deb") == 0)
			Debugger();
#endif
		else if (strcmp(argv[0], "peekb") == 0)
			shell_peek(args, argv);
		else if (strcmp(argv[0], "pokeb") == 0)
			shell_poke(args, argv);
		else if (strcmp(argv[0], "peekw") == 0)
			shell_peek(args, argv);
		else if (strcmp(argv[0], "pokew") == 0)
			shell_poke(args, argv);
		else if (strcmp(argv[0], "dumpb") == 0)
			shell_dumpb(args, argv);
		else if (strcmp(argv[0], "reboot") == 0)
			shell_reboot(args, argv);
		else if (strcmp(argv[0], "dumpw") == 0)
			shell_dumpw(args, argv);
		else if (strcmp(argv[0], "dump") == 0)
			shell_dumpw(args, argv);
		else if (strcmp(argv[0], "dis") == 0)
			shell_disassem(args, argv);
		else if (strcmp(argv[0], "qs") == 0)
			debug_show_q_details();
		else if (strcmp(argv[0], "ps") == 0)
			debug_show_all_procs(args, argv);
		else if (strcmp(argv[0], "callouts") == 0)
			debug_show_callout(args, argv);
		else if (strcmp(argv[0], "devices") == 0)
			shell_devices(args, argv);
		else if (strcmp(argv[0], "listfs") == 0)
			debug_show_fs(args, argv);
		else if (strcmp(argv[0], "vmmap") == 0)
			shell_vmmap(args, argv);
		else if (strcmp(argv[0], "pmap") == 0)
			shell_pmap(args, argv);
		else if (strcmp(argv[0], "flush") == 0)
			shell_flush(args, argv);
		else if (strcmp(argv[0], "vmstat") == 0)
			shell_vmstat(args, argv);
		else if (strcmp(argv[0], "pdstat") == 0)
			pmap_pagedir_dump();
		else if (strcmp(argv[0], "traceback") == 0)
			traceback();
		else if (strcmp(argv[0], "forceboot") == 0)
			forceboot(args, argv);
		else if (strcmp(argv[0], "dumppvs") == 0)
			pmap_dump_pvs();
		else if (strcmp(argv[0], "pextract") == 0)
			shell_pextract(args, argv);
		else if (strcmp(argv[0], "vnode") == 0)
			shell_vnode(args, argv);
		else if (strcmp(argv[0], "ascdump") == 0)
			asc_dump();
		else if (strcmp(argv[0], "help") == 0
		    || strcmp(argv[0], "?") == 0) {
			printf("peekb <hexaddr>\r\n");
			printf("pokeb <hexaddr> <data>\r\n");
			printf("peekw <hexaddr>\r\n");
			printf("pokew <hexaddr <data>\r\n");
			printf("dis <hexaddr>\r\n");
			printf("dumpb <hexaddr> [length]\r\n");
			printf("dumpw <hexaddr> [length]\r\n");
			printf("dump <hexaddr> [length]\r\n");
			printf("reboot\r\n");
			printf("qs\r\n");
			printf("ps [m]\r\n");
			printf("vmstat\n");
			printf("listfs\n");
			printf("devices\n");
			printf("callouts\n");
			printf("prompt\r\n");
			printf("vmmap <vmmap addr>\r\n");
			printf("pmap <pmap addr>\r\n");
			printf("pdstat\r\n");
			printf("flush\r\n");
			printf("exit\r\n");
			printf("forceboot\r\n");
			printf("dumppvs\r\n");
			printf("pextract <phys addr>\r\n");
			printf("vnode <vp>\r\n");
			printf("ascdump\r\n");
		}
	} while (!quit);

	return(0);
}

/* End of shell_shell.c */