|
|
1.1 root 1: /* Test program for tertiary boot.
2: * These are simple tests I found useful in building and
3: * debugging boot library routines.
4: *
5: * La Monte H. Yarroll <[email protected]>, September 1991
6: */
7:
8:
9: #include <ctype.h>
10: #include <canon.h>
11: #include <sys/types.h>
12: #include <sys/ino.h>
13: #include <sys/inode.h>
14: #include <sys/dir.h>
15: #include "tboot.h"
16:
17: /* CMOS addresses */
18: #define LOMEM 0x15 /* Memory size below 1MB. */
19: #define EXTMEM 0x17 /* Memory size avove 1MB. */
20:
21: main()
22: {
23: int i, k;
24: long j;
25: unsigned int tmp;
26:
27: char letter;
28: char buffer[BLOCK];
29: char outbuff[LINESIZE]; /* Buffer for outputing numbers. */
30: char filename[LINESIZE]; /* Name of a file to look up. */
31: struct inode rootinode;
32: struct inode myinode;
33: struct direct dirent;
34:
35: /* Test the output routines puts() and putchar(). */
36: puts("Hello world!\r\n");
37:
38:
39: /* Open "/" and print out the direct block file entries. */
40: iopen(&rootinode, (ino_t) 2);
41:
42: /* Read each directory entry one at a time. */
43: for (i = 0; i < rootinode.i_size; i += sizeof(struct direct)) {
44:
45: iread(&rootinode, (char *) &dirent, (fsize_t) i,
46: (uint16) sizeof(struct direct));
47:
48: /* Canonicalize it. */
49: canino(dirent.d_ino);
50: /* NUL terminate the name. */
51: strncpy(outbuff,
52: dirent.d_name,
53: DIRSIZ);
54: outbuff[DIRSIZ] = '\0';
55: /* Print the file name. */
56: puts(outbuff);
57: puts(" ");
58: /* Print the inode number in hexadecimal. */
59: itobase((int) (dirent.d_ino), outbuff, 16);
60: puts(outbuff);
61: putchar(':');
62: }
63:
64: /* Get some information from the CMOS. */
65: puts("\r\nLow memory: ");
66: print16(read16_cmos(LOMEM));
67: puts("K\r\n");
68: puts("Extended memory: ");
69: print16(read_cmos(EXTMEM, &tmp, 2));
70: puts("K\r\n");
71:
72: puts("CMOS:\r\n");
73: for (i=0; i < 52; ++i) {
74: print16(i);
75: puts(": ");
76: print16(read_cmos(i));
77: puts(" ");
78: }
79:
80:
81: /* Test namei() by asking for a file name and looking it up. */
82: puts("\r\nPlease enter a file name: ");
83: gets(filename);
84: puts("\r\nThe inode number for that is: ");
85: itobase((int) namei(filename), outbuff, 16);
86: puts(outbuff);
87:
88: if (0 == iopen(&myinode, namei(filename))) {
89: puts("\r\nCan't open ");
90: puts(filename);
91: puts(".\r\n");
92: }
93:
94: /* Fetch selected blocks from the file. */
95: puts("\r\nPlease enter an hex offset (! to finish): ");
96: gets(outbuff);
97:
98: while (outbuff[0] != '!') {
99: puts("\r\n");
100: i = basetoi(outbuff, 16);
101: iread(&myinode, buffer,
102: ((fsize_t) i * (fsize_t) BLOCK) ,
103: (short) BLOCK);
104: buffer[BLOCK] = '\0';
105: puts(buffer);
106: puts("\r\nPlease enter an hex offset: ");
107: gets(outbuff);
108: }
109:
110: puts("\r\nHit '!' to finish echo test.\r\n");
111: /* Echo characters until we get a '!' character.
112: * This tests the input routine getchar().
113: */
114: while ((char) '!' != (letter = (char) getchar())) {
115: putchar(letter);
116: itobase((int) letter, outbuff, 16);
117: puts(outbuff);
118: putchar(':');
119: }
120: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.