Mercurial > hg > Members > kono > os9 > sbc09
comparison os9/os9mod.c @ 94:f20bf9874697
fix os9 dir
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 25 Dec 2018 15:57:05 +0900 |
parents | src/os9/os9mod.c@2088fd998865 |
children |
comparison
equal
deleted
inserted
replaced
93:03a26438ab8d | 94:f20bf9874697 |
---|---|
1 #include <stdio.h> | |
2 #include <stdlib.h> | |
3 #include <string.h> | |
4 #include <errno.h> | |
5 #include "os9.h" | |
6 | |
7 | |
8 u_char *os9_string(u_char *string); | |
9 void ident(OS9_MODULE_t *mod); | |
10 void usage(void); | |
11 long pos; | |
12 | |
13 static char *types[16] = { | |
14 "???", "Prog", "Subr", "Multi", "Data", "USR 5", "USR 6", "USR 7", | |
15 "USR 8", "USR 9", "USR A", "USR B", "System", "File Manager", | |
16 "Device Driver", "Device Descriptor" | |
17 }; | |
18 | |
19 static char *langs[16] = { | |
20 "Data", "6809 Obj", "Basic09 I-Code", "Pascal P-Code", "C I-Code", | |
21 "Cobol I-Code", "Fortran I-Code", "6309 Obj", "???", "???", "???", | |
22 "???", "???", "???", "???", "???" | |
23 }; | |
24 | |
25 int offset = 0; | |
26 | |
27 int main(int argc, char **argv) | |
28 { | |
29 char *filename = NULL; | |
30 FILE *fp; | |
31 u_char buffer[65536]; /* OS9 Module can't be larger than this */ | |
32 OS9_MODULE_t *mod = (OS9_MODULE_t *) buffer; | |
33 int i=0, j; | |
34 int flag = 0; | |
35 | |
36 argv++; /* skip my name */ | |
37 | |
38 if (argc == 1) | |
39 usage(); | |
40 | |
41 while ((argc >= 2) && (*argv[0] == '-')) { | |
42 if (*(argv[0] + 1) == 's') { | |
43 argc--; | |
44 flag = 1; | |
45 } else if (*(argv[0] + 1) == 'o') { | |
46 argc--; argc--; | |
47 argv++; | |
48 offset = strtol(argv[0],(char**)0,0); | |
49 } else | |
50 usage(); | |
51 argv++; | |
52 } | |
53 | |
54 | |
55 while (argc-- > 1) { | |
56 if (*argv==0) return 0; | |
57 filename = *(argv++); | |
58 | |
59 if ((fp = fopen(filename,"rb")) == NULL) { | |
60 fprintf(stderr, "Error opening file %s: %s\n", | |
61 filename, strerror(errno)); | |
62 return 1; | |
63 } | |
64 | |
65 while (!feof(fp)) { | |
66 | |
67 if (flag) { | |
68 int c; | |
69 while( !feof(fp) && (c = fgetc(fp)) != 0x87 ); | |
70 ungetc(c, fp); | |
71 } | |
72 | |
73 pos = ftell(fp); | |
74 if (fread(buffer, OS9_HEADER_SIZE, 1, fp) != 1) { | |
75 if (feof(fp)) | |
76 break; | |
77 else { | |
78 fprintf(stderr, "Error reading file %s: %s\n", | |
79 filename, strerror(errno)); | |
80 return 1; | |
81 } | |
82 } | |
83 | |
84 if ((mod->id[0] != OS9_ID0) && (mod->id[1] != OS9_ID1)) { | |
85 fprintf(stderr,"Not OS9 module, skipping.\n"); | |
86 return 1; | |
87 } | |
88 | |
89 if ((i = os9_header(mod))!=0xff) { | |
90 fprintf(stderr, "Bad header parity. Expected 0xFF, got 0x%02X\n", i); | |
91 return 1; | |
92 } | |
93 | |
94 i = INT(mod->size) - OS9_HEADER_SIZE; | |
95 if ((j = fread(buffer + OS9_HEADER_SIZE, 1, i, fp)) != i) { | |
96 fprintf(stderr,"Module short. Expected 0x%04X, got 0x%04X\n", | |
97 i + OS9_HEADER_SIZE, j + OS9_HEADER_SIZE); | |
98 return 1; | |
99 } | |
100 ident(mod); | |
101 } | |
102 fclose(fp); | |
103 } | |
104 return 0; | |
105 | |
106 } | |
107 | |
108 void ident(OS9_MODULE_t *mod) | |
109 { | |
110 int i, j; | |
111 u_char *name, *ptr, tmp, *buffer = (u_char *) mod; | |
112 | |
113 i = INT(mod->name); | |
114 j = INT(mod->size); | |
115 name = os9_string(&buffer[i]); | |
116 printf("Offset : 0x%04lx\n", pos + offset); | |
117 printf("Header for : %s\n", name); | |
118 printf("Module size: $%X #%d\n", j, j); | |
119 ptr = &buffer[j - 3]; | |
120 printf("Module CRC : $%02X%02X%02X (%s)\n", ptr[0], ptr[1], ptr[2], | |
121 os9_crc(mod) ? "Good" : "Bad" ); | |
122 printf("Hdr parity : $%02X\n", mod->parity); | |
123 | |
124 switch ((mod->tyla & TYPE_MASK) >> 4) | |
125 { | |
126 | |
127 case Drivr: | |
128 case Prgrm: | |
129 i = INT(mod->data.program.exec); | |
130 printf("Exec. off : $%04X #%d\n", i, i); | |
131 i = INT(mod->data.program.mem); | |
132 printf("Data size : $%04X #%d\n", i, i); | |
133 break; | |
134 | |
135 case Devic: | |
136 printf("File Mgr : %s\n", | |
137 os9_string(&buffer[INT(mod->data.descriptor.fmgr)])); | |
138 printf("Driver : %s\n", | |
139 os9_string(&buffer[INT(mod->data.descriptor.driver)])); | |
140 break; | |
141 | |
142 case NULL_TYPE: | |
143 case TYPE_6: | |
144 case TYPE_7: | |
145 case TYPE_8: | |
146 case TYPE_9: | |
147 case TYPE_A: | |
148 case TYPE_B: | |
149 case Systm: | |
150 break; | |
151 } | |
152 | |
153 | |
154 | |
155 | |
156 tmp = buffer[i + strlen((const char *)name)]; | |
157 printf("Edition : $%02X #%d\n", tmp, tmp); | |
158 printf("Ty/La At/Rv: $%02X $%02x\n", mod->tyla, mod->atrv); | |
159 printf("%s mod, ", types[(mod->tyla & TYPE_MASK) >> 4]); | |
160 printf("%s, ", langs[mod->tyla & LANG_MASK]); | |
161 printf("%s, %s\n", (mod->atrv & ReEnt) ? "re-ent" : "non-share", | |
162 (mod->atrv & Modprot) ? "R/W" : "R/O" ); | |
163 printf("\n"); | |
164 } | |
165 | |
166 u_char *os9_string(u_char *string) | |
167 { | |
168 static u_char cleaned[80]; /* strings shouldn't be longer than this */ | |
169 u_char *ptr = cleaned; | |
170 int i = 0; | |
171 | |
172 while (((*(ptr++) = *(string++)) < 0x7f) && | |
173 (i++ < sizeof(cleaned) - 1)) | |
174 ; | |
175 | |
176 *(ptr - 1) &= 0x7f; | |
177 *ptr = '\0'; | |
178 return cleaned; | |
179 } | |
180 void usage(void) | |
181 { | |
182 printf("Usage: os9mod [-s] [-o offset] file [ file ... ]\n"); | |
183 printf("Performs an OS-9: 6809 'ident' on the specified files.\n"); | |
184 printf(" -s : skip to valid module\n"); | |
185 printf(" -o : offset \n\n"); | |
186 exit(0); | |
187 } |