--- trunk/src/emul_parse.c 2007/10/08 16:19:23 20 +++ upstream/0.4.4/src/emul_parse.c 2007/10/08 16:21:26 35 @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005 Anders Gavare. All rights reserved. + * Copyright (C) 2005-2007 Anders Gavare. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -25,13 +25,11 @@ * SUCH DAMAGE. * * - * $Id: emul_parse.c,v 1.35 2005/11/06 21:15:55 debug Exp $ + * $Id: emul_parse.c,v 1.45 2006/12/30 13:30:52 debug Exp $ * * Set up an emulation by parsing a config file. * - * TODO: This could be extended to support XML config files as well, but - * XML is ugly. It is ugly right now as well. The question is: which - * solution is the least ugly? + * TODO: REWRITE THIS FROM SCRATCH! :-) */ #include @@ -49,11 +47,14 @@ (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || \ ch == '_' || ch == '$' || (ch >= '0' && ch <= '9') ) +#define MAX_WORD_LEN 200 #define EXPECT_WORD 1 #define EXPECT_LEFT_PARENTHESIS 2 #define EXPECT_RIGHT_PARENTHESIS 4 +static int parenthesis_level = 0; + /* * read_one_word(): @@ -173,10 +174,12 @@ done = 1; } else { if ((expect & EXPECT_LEFT_PARENTHESIS) && ch == '(') { + parenthesis_level ++; buf[curlen++] = ch; break; } if ((expect & EXPECT_RIGHT_PARENTHESIS) && ch == ')') { + parenthesis_level --; buf[curlen++] = ch; break; } @@ -211,13 +214,9 @@ static char cur_machine_bootname[150]; static char cur_machine_bootarg[250]; static char cur_machine_slowsi[10]; -static char cur_machine_debugger_on_badaddr[10]; static char cur_machine_prom_emulation[10]; static char cur_machine_use_x11[10]; static char cur_machine_x11_scaledown[10]; -static char cur_machine_bintrans[10]; -static char cur_machine_old_bintrans[10]; -static char cur_machine_bintrans_size[10]; static char cur_machine_byte_order[20]; static char cur_machine_random_mem[10]; static char cur_machine_random_cpu[10]; @@ -228,7 +227,6 @@ static char cur_machine_serial_nr[10]; static char cur_machine_emulated_hz[10]; static char cur_machine_memory[10]; -static char cur_machine_max_random_cycles[10]; #define MAX_N_LOAD 15 #define MAX_LOAD_LEN 2000 static char *cur_machine_load[MAX_N_LOAD]; @@ -258,6 +256,9 @@ } \ } +static void parse__machine(struct emul *e, FILE *f, int *in_emul, int *line, + int *parsestate, char *word, size_t maxbuflen); + /* * parse_on_off(): @@ -275,34 +276,9 @@ strcasecmp(s, "disable") == 0 || strcasecmp(s, "0") == 0) return 0; - fatal("parse_on_off(): unknown value '%s'\n", s); - exit(1); -} - - -/* - * parse__none(): - * - * emul ( [...] ) - */ -static void parse__none(struct emul *e, FILE *f, int *in_emul, int *line, - int *parsestate, char *word, size_t maxbuflen) -{ - if (strcmp(word, "emul") == 0) { - if (*in_emul) { - fatal("line %i: only one emul per config " - "file is supported!\n", *line); - exit(1); - } - *parsestate = PARSESTATE_EMUL; - *in_emul = 1; - read_one_word(f, word, maxbuflen, - line, EXPECT_LEFT_PARENTHESIS); - return; - } + fprintf(stderr, "parse_on_off(): WARNING: unknown value '%s'\n", s); - fatal("line %i: expecting 'emul', not '%s'\n", *line, word); - exit(1); + return 0; } @@ -345,8 +321,10 @@ line, EXPECT_LEFT_PARENTHESIS); /* Default net: */ - strlcpy(cur_net_ipv4net, "10.0.0.0", sizeof(cur_net_ipv4net)); - strlcpy(cur_net_ipv4len, "8", sizeof(cur_net_ipv4len)); + strlcpy(cur_net_ipv4net, NET_DEFAULT_IPV4_MASK, + sizeof(cur_net_ipv4net)); + snprintf(cur_net_ipv4len, sizeof(cur_net_ipv4len), "%i", + NET_DEFAULT_IPV4_LEN); strlcpy(cur_net_local_port, "", sizeof(cur_net_local_port)); cur_net_n_remote = 0; return; @@ -369,13 +347,9 @@ cur_machine_n_device = 0; cur_machine_n_x11_disp = 0; cur_machine_slowsi[0] = '\0'; - cur_machine_debugger_on_badaddr[0] = '\0'; cur_machine_prom_emulation[0] = '\0'; cur_machine_use_x11[0] = '\0'; cur_machine_x11_scaledown[0] = '\0'; - cur_machine_bintrans[0] = '\0'; - cur_machine_old_bintrans[0] = '\0'; - cur_machine_bintrans_size[0] = '\0'; cur_machine_byte_order[0] = '\0'; cur_machine_random_mem[0] = '\0'; cur_machine_random_cpu[0] = '\0'; @@ -386,7 +360,6 @@ cur_machine_serial_nr[0] = '\0'; cur_machine_emulated_hz[0] = '\0'; cur_machine_memory[0] = '\0'; - cur_machine_max_random_cycles[0] = '\0'; return; } @@ -426,7 +399,7 @@ e->net = net_init(e, NET_INIT_FLAG_GATEWAY, cur_net_ipv4net, atoi(cur_net_ipv4len), cur_net_remote, cur_net_n_remote, - atoi(cur_net_local_port)); + atoi(cur_net_local_port), NULL); if (e->net == NULL) { fatal("line %i: fatal error: could not create" @@ -509,12 +482,6 @@ m->slow_serial_interrupts_hack_for_linux = parse_on_off(cur_machine_slowsi); - if (!cur_machine_debugger_on_badaddr[0]) - strlcpy(cur_machine_debugger_on_badaddr, "no", - sizeof(cur_machine_debugger_on_badaddr)); - m->single_step_on_bad_addr = - parse_on_off(cur_machine_debugger_on_badaddr); - if (!cur_machine_prom_emulation[0]) strlcpy(cur_machine_prom_emulation, "yes", sizeof(cur_machine_prom_emulation)); @@ -546,28 +513,6 @@ } } - if (!cur_machine_bintrans[0]) - strlcpy(cur_machine_bintrans, "yes", - sizeof(cur_machine_bintrans)); - m->bintrans_enable = m->bintrans_enabled_from_start = - parse_on_off(cur_machine_bintrans); - - if (!cur_machine_old_bintrans[0]) - strlcpy(cur_machine_old_bintrans, "yes", - sizeof(cur_machine_old_bintrans)); - m->old_bintrans_enable = parse_on_off(cur_machine_old_bintrans); - - if (!m->bintrans_enable && m->old_bintrans_enable) - m->old_bintrans_enable = 0; - - /* TODO: Hm... */ - if (m->bintrans_enable && m->arch == ARCH_MIPS) - m->speed_tricks = 0; - - if (cur_machine_bintrans_size[0]) - m->bintrans_size = 1048576 * - atoi(cur_machine_bintrans_size); - if (!cur_machine_force_netboot[0]) strlcpy(cur_machine_force_netboot, "no", sizeof(cur_machine_force_netboot)); @@ -595,7 +540,6 @@ if (cur_machine_emulated_hz[0]) { m->emulated_hz = mystrtoull(cur_machine_emulated_hz, NULL, 0); - m->automatic_clock_adjustment = 0; } /* NOTE: Default nr of CPUs is 0: */ @@ -604,16 +548,6 @@ sizeof(cur_machine_memory)); m->physical_ram_in_mb = atoi(cur_machine_memory); - if (cur_machine_max_random_cycles[0]) { - if (m->bintrans_enable) { - fprintf(stderr, "max_random_cycles doesn't" - " work with bintrans\n"); - exit(1); - } - m->max_random_cycles_per_chunk = atoi( - cur_machine_max_random_cycles); - } - if (!cur_machine_x11_scaledown[0]) m->x11_scaledown = 1; else { @@ -685,13 +619,9 @@ WORD("bootname", cur_machine_bootname); WORD("bootarg", cur_machine_bootarg); WORD("slow_serial_interrupts_hack_for_linux", cur_machine_slowsi); - WORD("debugger_on_badaddr", cur_machine_debugger_on_badaddr); WORD("prom_emulation", cur_machine_prom_emulation); WORD("use_x11", cur_machine_use_x11); WORD("x11_scaledown", cur_machine_x11_scaledown); - WORD("bintrans", cur_machine_bintrans); - WORD("old_bintrans", cur_machine_old_bintrans); - WORD("bintrans_size", cur_machine_bintrans_size); WORD("byte_order", cur_machine_byte_order); WORD("random_mem_contents", cur_machine_random_mem); WORD("use_random_bootstrap_cpu", cur_machine_random_cpu); @@ -701,7 +631,6 @@ WORD("n_gfx_cards", cur_machine_n_gfx_cards); WORD("emulated_hz", cur_machine_emulated_hz); WORD("memory", cur_machine_memory); - WORD("max_random_cycles", cur_machine_max_random_cycles); WORD("start_paused", cur_machine_start_paused); if (strcmp(word, "load") == 0) { @@ -797,14 +726,19 @@ * * Set up an emulation by parsing a config file. */ -void emul_parse_config(struct emul *e, FILE *f) +void emul_parse_config(struct emul *e, char *fname) { - char word[500]; + FILE *f = fopen(fname, "r"); + char word[MAX_WORD_LEN]; int in_emul = 0; int line = 1; - int parsestate = PARSESTATE_NONE; + int parsestate = PARSESTATE_EMUL; /* debug("emul_parse_config()\n"); */ + if (f == NULL) { + perror(fname); + exit(1); + } while (!feof(f)) { read_one_word(f, word, sizeof(word), &line, @@ -815,10 +749,6 @@ /* debug("word = '%s'\n", word); */ switch (parsestate) { - case PARSESTATE_NONE: - parse__none(e, f, &in_emul, &line, &parsestate, - word, sizeof(word)); - break; case PARSESTATE_EMUL: parse__emul(e, f, &in_emul, &line, &parsestate, word, sizeof(word)); @@ -831,6 +761,8 @@ parse__machine(e, f, &in_emul, &line, &parsestate, word, sizeof(word)); break; + case PARSESTATE_NONE: + break; default: fatal("INTERNAL ERROR in emul_parse.c (" "parsestate %i is not imlemented yet?)\n", @@ -839,9 +771,11 @@ } } - if (parsestate != PARSESTATE_NONE) { + if (parenthesis_level != 0) { fatal("EOF but not enough right parentheses?\n"); exit(1); } + + fclose(f); }