7 #define YYSTYPE unsigned long
15 i86biosRegs regs = { 00 };
17 enum mem_type { BYTE, WORD, LONG, STRING };
30 struct device Device = {FALSE,NONE,{0}};
32 extern void yyerror(char *s);
33 extern int yylex( void );
35 static void boot(void);
36 static void dump_mem(CARD32 addr, int len);
37 static void exec_int(int num);
38 static void *add_to_list(enum mem_type type, union mem_val *rec, void *next);
39 static void do_list(struct mem *list, memType addr);
40 static char * normalize_string(char *ptr);
55 %token TOK_COMMAND_BOOT
56 %token TOK_COMMAND_EXEC
59 %token TOK_MODIFIER_BYTE
60 %token TOK_MODIFIER_WORD
61 %token TOK_MODIFIER_LONG
62 %token TOK_MODIFIER_MEMSET
63 %token TOK_COMMAND_MEMSET
64 %token TOK_COMMAND_MEMDUMP
65 %token TOK_COMMAND_QUIT
93 line: end | com_reg | com_var | com_select
94 | com_boot | com_memset | com_memdump | com_quit
95 | com_exec | hlp | config | verbose | logging | print | clstat
96 | com_hlt | ioperm | list_pci | boot_bios
97 | error end { printf("unknown command\n"); }
101 com_reg: reg_off val end { *(CARD16*)$1 = $2 & 0xffff; }
102 | reg_seg TOK_SEP reg_off val end {
103 *(CARD16*)$1 = ($4 & 0xf0000) >> 4;
104 *(CARD16*)$3 = ($4 & 0x0ffff);
106 | reg_off '?' end { printf("0x%x\n",*(CARD16*)$1);}
107 | reg_seg TOK_SEP reg_off '?' end
108 { printf("0x%x:0x%x\n",*(CARD16*)$1,
111 register_read: reg_seg TOK_SEP reg_off { $$ = (((*(CARD16*)$1) << 4)
112 | ((*(CARD16*)$3) & 0xffff));
114 | reg_off { $$ = ((*(CARD16*)$1) & 0xffff); }
116 reg_off: TOK_REG_AX { $$ = (unsigned long)&(regs.ax); }
117 | TOK_REG_BX { $$ = (unsigned long)&(regs.bx); }
118 | TOK_REG_CX { $$ = (unsigned long)&(regs.cx); }
119 | TOK_REG_DX { $$ = (unsigned long)&(regs.dx); }
120 | TOK_REG_DI { $$ = (unsigned long)&(regs.di); }
121 | TOK_REG_SI { $$ = (unsigned long)&(regs.si); }
123 reg_seg: TOK_SEG_DS { $$ = (unsigned long)&(regs.ds); }
124 | TOK_SEG_ES { $$ = (unsigned long)&(regs.es); }
126 com_var: TOK_VAR_MEM '?' end { printf("var mem: 0x%x\n",var_mem); }
127 | TOK_VAR '?' end { if ($1 < MAX_VAR)
128 printf("var[%i]: 0x%x\n",(int)$1,var[$1]);
130 printf("var index %i out of range\n",(int)$1); }
131 | TOK_VAR_MEM val end { var_mem = $2; }
132 | TOK_VAR val end { if ($1 <= MAX_VAR)
135 printf("var index %i out of range\n",(int)$1); }
136 | TOK_VAR error end { printf("$i val\n"); }
137 | TOK_VAR_MEM error end { printf("$i val\n"); }
139 com_boot: TOK_COMMAND_BOOT end { boot(); }
140 TOK_COMMAND_BOOT error end { boot(); }
142 com_select: TOK_SELECT TOK_ISA end { Device.booted = FALSE;
145 | TOK_SELECT TOK_PCI val TOK_SEP val TOK_SEP val end
146 { Device.booted = FALSE;
148 Device.loc.pci.bus = $3;
149 Device.loc.pci.dev = $5;
150 Device.loc.pci.func = $7; }
152 { switch (Device.type) {
157 printf("pci: %x:%x:%x\n",Device.loc.pci.bus,
159 Device.loc.pci.func);
162 printf("no device selected\n");
166 | TOK_SELECT error end { printf("select ? | isa "
167 "| pci:bus:dev:func\n"); }
169 com_quit: TOK_COMMAND_QUIT end { return 0; }
170 | TOK_COMMAND_QUIT error end { logoff(); return 0; }
172 com_exec: TOK_COMMAND_EXEC end { exec_int(0x10); }
173 | TOK_COMMAND_EXEC val end { exec_int($2); }
174 | TOK_COMMAND_EXEC error end { exec_int(0x10); }
176 com_memdump: TOK_COMMAND_MEMDUMP val val end { dump_mem($2,$3); }
177 | TOK_COMMAND_MEMDUMP error end { printf("memdump start len\n"); }
181 com_memset: TOK_COMMAND_MEMSET val list end { do_list((struct mem*)$3,$2);}
182 | TOK_COMMAND_MEMSET error end { printf("setmem addr [byte val] "
183 "[word val] [long val] "
187 | TOK_BYTE val list { rec.integer = $2;
188 $$ = (unsigned long)add_to_list(BYTE,&rec,(void*)$3); }
189 | TOK_WORD val list { rec.integer = $2;
190 $$ = (unsigned long) add_to_list(WORD,&rec,(void*)$3); }
191 | TOK_LONG val list { rec.integer = $2;
192 $$ = (unsigned long) add_to_list(LONG,&rec,(void*)$3); }
193 | TOK_STRING list { rec.ptr = (void*)$1;
194 $$ = (unsigned long) add_to_list(STRING,&rec,(void*)$2); }
196 val: TOK_VAR { if ($1 > MAX_VAR) {
197 printf("variable index out of range\n");
201 | TOK_NUM { $$ = $1; }
204 bool: TOK_ON { $$ = 1; }
205 | TOK_OFF { $$ = 0; }
207 config: TOK_PRINT_PORT bool end { Config.PrintPort = $2; }
208 | TOK_PRINT_PORT '?' end { printf("print port %s\n",
209 Config.PrintPort?"on":"off"); }
210 | TOK_PRINT_PORT error end { printf("pport on | off | ?\n") }
211 | TOK_PRINT_IRQ bool end { Config.PrintIrq = $2; }
212 | TOK_PRINT_IRQ '?' end { printf("print irq %s\n",
213 Config.PrintIrq?"on":"off"); }
214 | TOK_PRINT_IRQ error end { printf("pirq on | off | ?\n") }
215 | TOK_PPCI bool end { Config.PrintPci = $2; }
216 | TOK_PPCI '?' end { printf("print PCI %s\n",
217 Config.PrintPci?"on":"off"); }
218 | TOK_PPCI error end { printf("ppci on | off | ?\n") }
219 | TOK_PIP bool end { Config.PrintIp = $2; }
220 | TOK_PIP '?' end { printf("printip %s\n",
221 Config.PrintIp?"on":"off"); }
222 | TOK_PIP error end { printf("pip on | off | ?\n") }
223 | TOK_IOSTAT bool end { Config.IoStatistics = $2; }
224 | TOK_IOSTAT '?' end { printf("io statistics %s\n",
225 Config.IoStatistics?"on":"off"); }
226 | TOK_IOSTAT error end { printf("iostat on | off | ?\n") }
227 | TOK_TRACE bool end { Config.Trace = $2; }
228 | TOK_TRACE '?' end { printf("trace %s\n",
229 Config.Trace ?"on":"off"); }
230 | TOK_TRACE error end { printf("trace on | off | ?\n") }
232 verbose: TOK_VERBOSE val end { Config.Verbose = $2; }
233 | TOK_VERBOSE '?' end { printf("verbose: %i\n",
235 | TOK_VERBOSE error end { printf("verbose val | ?\n"); }
237 logging: TOK_LOG TOK_STRING end { logon(normalize_string((char*)$2)); }
238 | TOK_LOG '?' end { if (logging) printf("logfile: %s\n",
240 else printf("no logging\n?"); }
241 | TOK_LOG TOK_OFF end { logoff(); }
242 | TOK_LOG error end { printf("log \"<filename>\" | ? |"
245 clstat: TOK_CLSTAT end { clear_stat(); }
246 | TOK_CLSTAT error end { printf("clstat\n"); }
248 print: TOK_STDOUT bool end { nostdout = !$2; }
249 | TOK_STDOUT '?' end { printf("print %s\n",nostdout ?
251 | TOK_STDOUT error end { printf("print on | off\n"); }
253 com_hlt: TOK_HLT val end { add_hlt($2); }
254 | TOK_HLT TOK_DEL val end { del_hlt($3); }
255 | TOK_HLT TOK_DEL end { del_hlt(21); }
256 | TOK_HLT '?' end { list_hlt(); }
257 | TOK_HLT error end { printf(
258 "hlt val | del [val] | ?\n"); }
260 ioperm: TOK_IOPERM val val val end { int i,max;
263 if (max > IOPERM_BITS)
265 for (i = $2;i <= max; i++)
270 | TOK_IOPERM '?' end { int i,start;
271 for (i=0; i <= IOPERM_BITS; i++) {
272 if (ioperm_list[i]) {
274 for (; i <= IOPERM_BITS; i++)
275 if (!ioperm_list[i]) {
276 printf("ioperm on in "
277 "0x%x+0x%x\n", start,i-start);
283 | TOK_IOPERM error end { printf("ioperm start len val\n"); }
285 list_pci: TOK_DUMP_PCI end { list_pci(); }
286 | TOK_DUMP_PCI error end { list_pci(); }
288 boot_bios: TOK_BOOT_BIOS '?' end { if (!BootBios) printf("No Boot BIOS\n");
289 else printf("BootBIOS from: %i:%i:%i\n",
290 BootBios->bus, BootBios->dev,
292 | TOK_BOOT_BIOS error end { printf ("bootbios bus:dev:num\n"); }
294 hlp: '?' { printf("Command list:\n");
295 printf(" select isa | pci bus:dev:func\n");
297 printf(" seg:reg val | reg val \n");
298 printf(" $x val | $mem val\n");
299 printf(" setmem addr list; addr := val\n");
300 printf(" dumpmem addr len; addr,len := val\n");
301 printf(" do [val]\n");
304 printf(" seg := ds | es;"
305 " reg := ax | bx | cx | dx | si \n");
306 printf(" val := var | <hex-number> | seg:reg | seg\n");
307 printf(" var := $x | $mem; x := 0..20\n");
308 printf(" list := byte val | word val | long val "
310 printf(" pport on | off | ?\n");
311 printf(" ppci on | off | ?\n");
312 printf(" pirq on | off | ?\n");
313 printf(" pip on | off | ?\n");
314 printf(" trace on | off | ?\n");
315 printf(" iostat on | off | ?\n");
316 printf(" verbose val\n");
317 printf(" log \"<filename>\" | off | ?\n");
318 printf(" print on | off\n");
319 printf(" hlt val | del [val] | ?\n");
322 printf ("bootbios ?\n");
329 dump_mem(CARD32 addr, int len)
337 if (num == 0x10) { /* video interrupt */
338 if (Device.type == NONE) {
339 CurrentPci = PciList;
341 if (CurrentPci->active)
343 CurrentPci = CurrentPci->next;
349 Device.loc.pci.dev = CurrentPci->dev;
350 Device.loc.pci.bus = CurrentPci->bus;
351 Device.loc.pci.func = CurrentPci->func;
354 if (Device.type != ISA) {
355 if (!Device.booted) {
356 if (!CurrentPci || (Device.type == PCI
357 && (!CurrentPci->active
358 && (Device.loc.pci.dev != CurrentPci->dev
359 || Device.loc.pci.bus != CurrentPci->bus
360 || Device.loc.pci.func != CurrentPci->func)))) {
361 printf("boot the device fist\n");
368 Device.booted = FALSE; /* we need this for sanity! */
377 if (Device.type == NONE) {
378 printf("select a device fist\n");
386 add_to_list(enum mem_type type, union mem_val *rec, void *next)
388 struct mem *mem_rec = (struct mem *) malloc(sizeof(mem_rec));
390 mem_rec->type = type;
391 mem_rec->next = next;
397 mem_rec->val.integer = rec->integer;
400 mem_rec->val.ptr = normalize_string(rec->ptr);
407 validRange(int addr,int len)
409 int end = addr + len;
411 if (addr < 0x1000 || end > 0xc0000)
417 do_list(struct mem *list, memType addr)
423 switch (list->type) {
425 if (!validRange(addr,1)) goto error;
426 *(CARD8*)addr = list->val.integer;
430 if (!validRange(addr,2)) goto error;
431 *(CARD16*)addr = list->val.integer;
435 if (!validRange(addr,4)) goto error;
436 *(CARD32*)addr = list->val.integer;
440 len = strlen((char*)list->val.ptr);
441 if (!validRange(addr,len)) goto error;
442 memcpy((CARD8*)addr,(void*)list->val.ptr,len);
452 printf("address out of range\n");
463 normalize_string(char *ptr)
465 int i = 0, j = 0, c = 0, esc= 0;
470 mem_ptr = malloc(size);
472 switch (*(ptr + i)) {
475 *(mem_ptr + j++) = *(ptr + i);
482 *(mem_ptr + j++) = *(ptr + i);
488 *(mem_ptr + j++) = *(ptr + i);
492 *(mem_ptr + j) = '\0';