25 |
* SUCH DAMAGE. |
* SUCH DAMAGE. |
26 |
* |
* |
27 |
* |
* |
28 |
* $Id: emul_parse.c,v 1.29 2005/03/14 19:14:04 debug Exp $ |
* $Id: emul_parse.c,v 1.35 2005/11/06 21:15:55 debug Exp $ |
29 |
* |
* |
30 |
* Set up an emulation by parsing a config file. |
* Set up an emulation by parsing a config file. |
31 |
* |
* |
|
* |
|
32 |
* TODO: This could be extended to support XML config files as well, but |
* TODO: This could be extended to support XML config files as well, but |
33 |
* XML is ugly. |
* XML is ugly. It is ugly right now as well. The question is: which |
34 |
|
* solution is the least ugly? |
35 |
*/ |
*/ |
36 |
|
|
37 |
#include <stdio.h> |
#include <stdio.h> |
198 |
|
|
199 |
static char cur_net_ipv4net[50]; |
static char cur_net_ipv4net[50]; |
200 |
static char cur_net_ipv4len[50]; |
static char cur_net_ipv4len[50]; |
201 |
|
static char cur_net_local_port[10]; |
202 |
|
#define MAX_N_REMOTE 20 |
203 |
|
#define MAX_REMOTE_LEN 100 |
204 |
|
static char *cur_net_remote[MAX_N_REMOTE]; |
205 |
|
static int cur_net_n_remote; |
206 |
|
|
207 |
static char cur_machine_name[50]; |
static char cur_machine_name[50]; |
208 |
static char cur_machine_cpu[50]; |
static char cur_machine_cpu[50]; |
228 |
static char cur_machine_serial_nr[10]; |
static char cur_machine_serial_nr[10]; |
229 |
static char cur_machine_emulated_hz[10]; |
static char cur_machine_emulated_hz[10]; |
230 |
static char cur_machine_memory[10]; |
static char cur_machine_memory[10]; |
231 |
|
static char cur_machine_max_random_cycles[10]; |
232 |
#define MAX_N_LOAD 15 |
#define MAX_N_LOAD 15 |
233 |
#define MAX_LOAD_LEN 2000 |
#define MAX_LOAD_LEN 2000 |
234 |
static char *cur_machine_load[MAX_N_LOAD]; |
static char *cur_machine_load[MAX_N_LOAD]; |
345 |
line, EXPECT_LEFT_PARENTHESIS); |
line, EXPECT_LEFT_PARENTHESIS); |
346 |
|
|
347 |
/* Default net: */ |
/* Default net: */ |
348 |
strcpy(cur_net_ipv4net, "10.0.0.0"); |
strlcpy(cur_net_ipv4net, "10.0.0.0", sizeof(cur_net_ipv4net)); |
349 |
strcpy(cur_net_ipv4len, "8"); |
strlcpy(cur_net_ipv4len, "8", sizeof(cur_net_ipv4len)); |
350 |
|
strlcpy(cur_net_local_port, "", sizeof(cur_net_local_port)); |
351 |
|
cur_net_n_remote = 0; |
352 |
return; |
return; |
353 |
} |
} |
354 |
|
|
386 |
cur_machine_serial_nr[0] = '\0'; |
cur_machine_serial_nr[0] = '\0'; |
387 |
cur_machine_emulated_hz[0] = '\0'; |
cur_machine_emulated_hz[0] = '\0'; |
388 |
cur_machine_memory[0] = '\0'; |
cur_machine_memory[0] = '\0'; |
389 |
|
cur_machine_max_random_cycles[0] = '\0'; |
390 |
return; |
return; |
391 |
} |
} |
392 |
|
|
399 |
/* |
/* |
400 |
* parse__net(): |
* parse__net(): |
401 |
* |
* |
402 |
* Simple words: ipv4net, ipv4len |
* Simple words: ipv4net, ipv4len, local_port |
403 |
|
* |
404 |
|
* Complex: add_remote |
405 |
* |
* |
406 |
* TODO: more words? for example an option to disable the gateway? that would |
* TODO: more words? for example an option to disable the gateway? that would |
407 |
* have to be implemented correctly in src/net.c first. |
* have to be implemented correctly in src/net.c first. |
409 |
static void parse__net(struct emul *e, FILE *f, int *in_emul, int *line, |
static void parse__net(struct emul *e, FILE *f, int *in_emul, int *line, |
410 |
int *parsestate, char *word, size_t maxbuflen) |
int *parsestate, char *word, size_t maxbuflen) |
411 |
{ |
{ |
412 |
|
int i; |
413 |
|
|
414 |
if (word[0] == ')') { |
if (word[0] == ')') { |
415 |
/* Finished with the 'net' section. Let's create the net: */ |
/* Finished with the 'net' section. Let's create the net: */ |
416 |
if (e->net != NULL) { |
if (e->net != NULL) { |
419 |
exit(1); |
exit(1); |
420 |
} |
} |
421 |
|
|
422 |
|
if (!cur_net_local_port[0]) |
423 |
|
strlcpy(cur_net_local_port, "0", |
424 |
|
sizeof(cur_net_local_port)); |
425 |
|
|
426 |
e->net = net_init(e, NET_INIT_FLAG_GATEWAY, |
e->net = net_init(e, NET_INIT_FLAG_GATEWAY, |
427 |
cur_net_ipv4net, atoi(cur_net_ipv4len)); |
cur_net_ipv4net, atoi(cur_net_ipv4len), |
428 |
|
cur_net_remote, cur_net_n_remote, |
429 |
|
atoi(cur_net_local_port)); |
430 |
|
|
431 |
if (e->net == NULL) { |
if (e->net == NULL) { |
432 |
fatal("line %i: fatal error: could not create" |
fatal("line %i: fatal error: could not create" |
434 |
exit(1); |
exit(1); |
435 |
} |
} |
436 |
|
|
437 |
|
for (i=0; i<cur_net_n_remote; i++) { |
438 |
|
free(cur_net_remote[i]); |
439 |
|
cur_net_remote[i] = NULL; |
440 |
|
} |
441 |
|
|
442 |
*parsestate = PARSESTATE_EMUL; |
*parsestate = PARSESTATE_EMUL; |
443 |
return; |
return; |
444 |
} |
} |
445 |
|
|
446 |
WORD("ipv4net", cur_net_ipv4net); |
WORD("ipv4net", cur_net_ipv4net); |
447 |
WORD("ipv4len", cur_net_ipv4len); |
WORD("ipv4len", cur_net_ipv4len); |
448 |
|
WORD("local_port", cur_net_local_port); |
449 |
|
|
450 |
|
if (strcmp(word, "add_remote") == 0) { |
451 |
|
read_one_word(f, word, maxbuflen, |
452 |
|
line, EXPECT_LEFT_PARENTHESIS); |
453 |
|
if (cur_net_n_remote >= MAX_N_REMOTE) { |
454 |
|
fprintf(stderr, "too many remote networks\n"); |
455 |
|
exit(1); |
456 |
|
} |
457 |
|
cur_net_remote[cur_net_n_remote] = malloc(MAX_REMOTE_LEN); |
458 |
|
if (cur_net_remote[cur_net_n_remote] == NULL) { |
459 |
|
fprintf(stderr, "out of memory\n"); |
460 |
|
exit(1); |
461 |
|
} |
462 |
|
read_one_word(f, cur_net_remote[cur_net_n_remote], |
463 |
|
MAX_REMOTE_LEN, line, EXPECT_WORD); |
464 |
|
cur_net_n_remote ++; |
465 |
|
read_one_word(f, word, maxbuflen, line, |
466 |
|
EXPECT_RIGHT_PARENTHESIS); |
467 |
|
return; |
468 |
|
} |
469 |
|
|
470 |
fatal("line %i: not expecting '%s' in a 'net' section\n", *line, word); |
fatal("line %i: not expecting '%s' in a 'net' section\n", *line, word); |
471 |
exit(1); |
exit(1); |
485 |
struct machine *m; |
struct machine *m; |
486 |
|
|
487 |
if (!cur_machine_name[0]) |
if (!cur_machine_name[0]) |
488 |
strcpy(cur_machine_name, "no_name"); |
strlcpy(cur_machine_name, "no_name", |
489 |
|
sizeof(cur_machine_name)); |
490 |
|
|
491 |
m = emul_add_machine(e, cur_machine_name); |
m = emul_add_machine(e, cur_machine_name); |
492 |
|
|
499 |
m->cpu_name = strdup(cur_machine_cpu); |
m->cpu_name = strdup(cur_machine_cpu); |
500 |
|
|
501 |
if (!cur_machine_use_x11[0]) |
if (!cur_machine_use_x11[0]) |
502 |
strcpy(cur_machine_use_x11, "no"); |
strlcpy(cur_machine_use_x11, "no", |
503 |
|
sizeof(cur_machine_use_x11)); |
504 |
m->use_x11 = parse_on_off(cur_machine_use_x11); |
m->use_x11 = parse_on_off(cur_machine_use_x11); |
505 |
|
|
506 |
if (!cur_machine_slowsi[0]) |
if (!cur_machine_slowsi[0]) |
507 |
strcpy(cur_machine_slowsi, "no"); |
strlcpy(cur_machine_slowsi, "no", |
508 |
|
sizeof(cur_machine_slowsi)); |
509 |
m->slow_serial_interrupts_hack_for_linux = |
m->slow_serial_interrupts_hack_for_linux = |
510 |
parse_on_off(cur_machine_slowsi); |
parse_on_off(cur_machine_slowsi); |
511 |
|
|
512 |
if (!cur_machine_debugger_on_badaddr[0]) |
if (!cur_machine_debugger_on_badaddr[0]) |
513 |
strcpy(cur_machine_debugger_on_badaddr, "no"); |
strlcpy(cur_machine_debugger_on_badaddr, "no", |
514 |
|
sizeof(cur_machine_debugger_on_badaddr)); |
515 |
m->single_step_on_bad_addr = |
m->single_step_on_bad_addr = |
516 |
parse_on_off(cur_machine_debugger_on_badaddr); |
parse_on_off(cur_machine_debugger_on_badaddr); |
517 |
|
|
518 |
if (!cur_machine_prom_emulation[0]) |
if (!cur_machine_prom_emulation[0]) |
519 |
strcpy(cur_machine_prom_emulation, "yes"); |
strlcpy(cur_machine_prom_emulation, "yes", |
520 |
|
sizeof(cur_machine_prom_emulation)); |
521 |
m->prom_emulation = parse_on_off(cur_machine_prom_emulation); |
m->prom_emulation = parse_on_off(cur_machine_prom_emulation); |
522 |
|
|
523 |
if (!cur_machine_random_mem[0]) |
if (!cur_machine_random_mem[0]) |
524 |
strcpy(cur_machine_random_mem, "no"); |
strlcpy(cur_machine_random_mem, "no", |
525 |
|
sizeof(cur_machine_random_mem)); |
526 |
m->random_mem_contents = |
m->random_mem_contents = |
527 |
parse_on_off(cur_machine_random_mem); |
parse_on_off(cur_machine_random_mem); |
528 |
|
|
529 |
if (!cur_machine_random_cpu[0]) |
if (!cur_machine_random_cpu[0]) |
530 |
strcpy(cur_machine_random_cpu, "no"); |
strlcpy(cur_machine_random_cpu, "no", |
531 |
|
sizeof(cur_machine_random_cpu)); |
532 |
m->use_random_bootstrap_cpu = |
m->use_random_bootstrap_cpu = |
533 |
parse_on_off(cur_machine_random_cpu); |
parse_on_off(cur_machine_random_cpu); |
534 |
|
|
547 |
} |
} |
548 |
|
|
549 |
if (!cur_machine_bintrans[0]) |
if (!cur_machine_bintrans[0]) |
550 |
strcpy(cur_machine_bintrans, "yes"); |
strlcpy(cur_machine_bintrans, "yes", |
551 |
|
sizeof(cur_machine_bintrans)); |
552 |
m->bintrans_enable = m->bintrans_enabled_from_start = |
m->bintrans_enable = m->bintrans_enabled_from_start = |
553 |
parse_on_off(cur_machine_bintrans); |
parse_on_off(cur_machine_bintrans); |
554 |
|
|
555 |
if (!cur_machine_old_bintrans[0]) |
if (!cur_machine_old_bintrans[0]) |
556 |
strcpy(cur_machine_old_bintrans, "no"); |
strlcpy(cur_machine_old_bintrans, "yes", |
557 |
|
sizeof(cur_machine_old_bintrans)); |
558 |
m->old_bintrans_enable = parse_on_off(cur_machine_old_bintrans); |
m->old_bintrans_enable = parse_on_off(cur_machine_old_bintrans); |
559 |
|
|
560 |
if (!m->bintrans_enable && m->old_bintrans_enable) { |
if (!m->bintrans_enable && m->old_bintrans_enable) |
561 |
fatal("cannot use old bintrans when bintrans is" |
m->old_bintrans_enable = 0; |
|
" disabled.\n"); |
|
|
exit(1); |
|
|
} |
|
562 |
|
|
563 |
/* TODO: Hm... */ |
/* TODO: Hm... */ |
564 |
if (m->bintrans_enable) |
if (m->bintrans_enable && m->arch == ARCH_MIPS) |
565 |
m->speed_tricks = 0; |
m->speed_tricks = 0; |
566 |
|
|
567 |
if (cur_machine_bintrans_size[0]) |
if (cur_machine_bintrans_size[0]) |
569 |
atoi(cur_machine_bintrans_size); |
atoi(cur_machine_bintrans_size); |
570 |
|
|
571 |
if (!cur_machine_force_netboot[0]) |
if (!cur_machine_force_netboot[0]) |
572 |
strcpy(cur_machine_force_netboot, "no"); |
strlcpy(cur_machine_force_netboot, "no", |
573 |
|
sizeof(cur_machine_force_netboot)); |
574 |
m->force_netboot = parse_on_off(cur_machine_force_netboot); |
m->force_netboot = parse_on_off(cur_machine_force_netboot); |
575 |
|
|
576 |
if (!cur_machine_start_paused[0]) |
if (!cur_machine_start_paused[0]) |
577 |
strcpy(cur_machine_start_paused, "no"); |
strlcpy(cur_machine_start_paused, "no", |
578 |
|
sizeof(cur_machine_start_paused)); |
579 |
m->start_paused = parse_on_off(cur_machine_start_paused); |
m->start_paused = parse_on_off(cur_machine_start_paused); |
580 |
|
|
581 |
/* NOTE: Default nr of CPUs is 0: */ |
/* NOTE: Default nr of CPUs is 0: */ |
582 |
if (!cur_machine_ncpus[0]) |
if (!cur_machine_ncpus[0]) |
583 |
strcpy(cur_machine_ncpus, "0"); |
strlcpy(cur_machine_ncpus, "0", |
584 |
|
sizeof(cur_machine_ncpus)); |
585 |
m->ncpus = atoi(cur_machine_ncpus); |
m->ncpus = atoi(cur_machine_ncpus); |
586 |
|
|
587 |
if (cur_machine_n_gfx_cards[0]) |
if (cur_machine_n_gfx_cards[0]) |
600 |
|
|
601 |
/* NOTE: Default nr of CPUs is 0: */ |
/* NOTE: Default nr of CPUs is 0: */ |
602 |
if (!cur_machine_memory[0]) |
if (!cur_machine_memory[0]) |
603 |
strcpy(cur_machine_memory, "0"); |
strlcpy(cur_machine_memory, "0", |
604 |
|
sizeof(cur_machine_memory)); |
605 |
m->physical_ram_in_mb = atoi(cur_machine_memory); |
m->physical_ram_in_mb = atoi(cur_machine_memory); |
606 |
|
|
607 |
|
if (cur_machine_max_random_cycles[0]) { |
608 |
|
if (m->bintrans_enable) { |
609 |
|
fprintf(stderr, "max_random_cycles doesn't" |
610 |
|
" work with bintrans\n"); |
611 |
|
exit(1); |
612 |
|
} |
613 |
|
m->max_random_cycles_per_chunk = atoi( |
614 |
|
cur_machine_max_random_cycles); |
615 |
|
} |
616 |
|
|
617 |
if (!cur_machine_x11_scaledown[0]) |
if (!cur_machine_x11_scaledown[0]) |
618 |
m->x11_scaledown = 1; |
m->x11_scaledown = 1; |
619 |
else { |
else { |
620 |
m->x11_scaledown = atoi(cur_machine_x11_scaledown); |
m->x11_scaledown = atoi(cur_machine_x11_scaledown); |
621 |
if (m->x11_scaledown < 0) { |
if (m->x11_scaledown < 0) { |
622 |
|
m->x11_scaleup = 0 - m->x11_scaledown; |
623 |
|
m->x11_scaledown = 1; |
624 |
|
} |
625 |
|
if (m->x11_scaledown < 1) { |
626 |
fprintf(stderr, "Invalid scaledown value" |
fprintf(stderr, "Invalid scaledown value" |
627 |
" (%i)\n", m->x11_scaledown); |
" (%i)\n", m->x11_scaledown); |
628 |
exit(1); |
exit(1); |
701 |
WORD("n_gfx_cards", cur_machine_n_gfx_cards); |
WORD("n_gfx_cards", cur_machine_n_gfx_cards); |
702 |
WORD("emulated_hz", cur_machine_emulated_hz); |
WORD("emulated_hz", cur_machine_emulated_hz); |
703 |
WORD("memory", cur_machine_memory); |
WORD("memory", cur_machine_memory); |
704 |
|
WORD("max_random_cycles", cur_machine_max_random_cycles); |
705 |
WORD("start_paused", cur_machine_start_paused); |
WORD("start_paused", cur_machine_start_paused); |
706 |
|
|
707 |
if (strcmp(word, "load") == 0) { |
if (strcmp(word, "load") == 0) { |