URL
https://opencores.org/ocsvn/or1k/or1k/trunk
Subversion Repositories or1k
[/] [or1k/] [tags/] [nog_patch_66/] [or1ksim/] [sim-config.c] - Rev 535
Go to most recent revision | Compare with Previous | Blame | View Log
/* config.c -- Simulator configuration Copyright (C) 1999 Damjan Lampret, lampret@opencores.org This file is part of OpenRISC 1000 Architectural Simulator. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* Simulator configuration. Eventually this one will be a lot bigger. */ #include <stdlib.h> #include "sim-config.h" #include "abstract.h" #include "sprs.h" #include "spr_defs.h" #include "pic.h" #include "stats.h" #include "icache_model.h" #include "dcache_model.h" #define WARNING(s) fprintf (stderr, "WARNING: config.%s: %s\n", sections[section].name, (s)) #define ERROR(s) {fprintf (stderr, "ERROR: config.%s:%s\n", sections[section].name, s); if (runtime.sim.init) exit (1);} #define MERROR(s) {fprintf (stderr, "ERROR: %s\n", s); if (runtime.sim.init) exit (1);} struct config config; struct runtime runtime; int section = 0; extern struct section { char *name; int flags; } sections[]; void init_defconfig() { int i; memset(&config, 0, sizeof(config)); memset(&runtime, 0, sizeof(runtime)); /* Sim */ config.sim.exe_log = 0; runtime.sim.fexe_log = NULL; strcpy (config.sim.exe_log_fn, "executed.log"); config.sim.debug = 0; config.sim.verbose = 1; config.sim.iprompt = 0; config.sim.profile = 0; runtime.sim.fprof = NULL; strcpy (config.sim.prof_fn, "sim.profile"); runtime.sim.init = 1; runtime.sim.script_file_specified = 0; config.sim.clkcycle_ps = 4000; /* 4000 for 4ns (250MHz) */ /* Memory */ config.memory.type = MT_PATTERN; config.memory.pattern = 0; config.memory.random_seed = -1; /* Generate new seed */ for (i = 0; i < MAX_MEMORIES; i++) { config.memory.table[i].ce = -1; /* memory is disabled by default */ } /* IMMU & DMMU*/ config.immu.enabled = 0; config.dmmu.enabled = 0; /* IC & DC */ config.ic.enabled = 0; config.ic.tagtype = CT_PHYSICAL/*CT_VIRTUAL*/; config.dc.enabled = 0; config.dc.tagtype = CT_PHYSICAL/*CT_VIRTUAL*/; /* Memory Controller */ config.mc.enabled = 0; /* Uarts */ config.nuarts = 0; config.uarts_enabled = 0; /* DMAs */ config.ndmas = 0; config.dmas_enabled = 0; /* CPU */ config.cpu.superscalar = 0; config.sim.history = 0; config.cpu.hazards = 0; config.cpu.dependstats = 0; config.cpu.upr = SPR_UPR_UP | SPR_UPR_DCP | SPR_UPR_ICP | SPR_UPR_DMP | SPR_UPR_IMP | SPR_UPR_OB32P | SPR_UPR_DUP | SPR_UPR_PICP | SPR_UPR_PMP | SPR_UPR_TTP; /* Debug */ config.debug.enabled = 0; config.debug.gdb_enabled = 0; config.debug.server_port = 0; /* VAPI */ config.vapi.enabled = 0; strcpy (config.vapi.vapi_fn, "vapi.log"); runtime.vapi.vapi_file = NULL; /* Ethernet */ config.ethernets_enabled = 0; /* GPIO */ config.gpios_enabled = 0; /* Tick timer */ config.tick.enabled = 0; } int parse_args(int argc, char *argv[]) { unsigned long val; argv++; argc--; while (argc) { if (argc && (*argv[0] != '-')) { runtime.sim.filename = argv[0]; argc--; argv++; } else if (strcmp(*argv, "-f") == 0 || strcmp(*argv, "--file") == 0) { argv++; argc--; if (argv[0]) { read_script_file(argv[0]); argv++; argc--; } else { fprintf(stderr, "Configure filename not specified!\n"); return 1; } } else if (strcmp(*argv, "--nosrv") == 0) { /* (CZ) */ config.debug.gdb_enabled = 0; argv++; argc--; } else if (strcmp(*argv, "--srv") == 0) { /* (CZ) */ char *s; if(!--argc) return 1; config.debug.enabled = 1; config.debug.gdb_enabled = 0; config.debug.server_port = strtol(*(++argv),&s,10); if(*s) return 1; argv++; argc--; } else if (strcmp(*argv, "-i") == 0) { config.sim.iprompt = 1; argv++; argc--; } else if (strcmp(*argv, "-v") == 0) { version(); exit(0); } else if (strcmp(*argv, "--profile") == 0) { config.sim.profile = 1; argv++; argc--; } else { fprintf(stderr, "Unknown option: %s\n", *argv); return 1; } } if (!argc) return 0; return 0; } #define CNV(x) ((isspace(x) || (x) == 0) ? ' ' : (x)) /* Substitute for less powerful fscanf */ int fscanf_ex (FILE *f, char *fmt, void *buf, char *str) { char tmp[STR_SIZE]; char ch; int i = 0; while (*fmt) { switch (*fmt) { case '%': while(*fmt != 0 && !isalpha (*fmt)) tmp[i++] = *(fmt++); tmp[i++] = *(fmt++); if (tmp[i - 1] == 's') { char *cbuf = (char *)buf; i = 0; while (ch = (f ? fgetc (f) : *str++), isspace(ch)) if (f ? feof (f) : *str) return 1; if (f) ungetc (ch, f); else str--; while ((*(cbuf++) = ch = (f ? fgetc (f) : *str++), CNV(ch) ) != *fmt) { if ((f ? feof (f) : *str)) return 1; if (++i >= STR_SIZE) { fprintf (stderr, "ERROR: string too long.\n"); return 1; } } *(--cbuf) = 0; fmt++; } else { tmp[i++] = 0; if (f) fscanf (f, tmp, buf); else sscanf (str, tmp, buf); } break; default: while ((ch = (f ? fgetc (f) : *str++)) != *fmt) { if (!isspace (ch)) { char tmp[200]; sprintf (tmp, "unexpected char '%c' (expecting '%c')\n", ch, *fmt); fprintf (stderr, "WARNING: config.%s: %s\n", sections[section], tmp); WARNING(tmp); } if ((f ? feof (f) : *str)) return 1; } fmt++; break; } } return 0; } void print_config() { if (config.sim.verbose) { char temp[20]; printf("Verbose on, "); if (config.sim.debug) printf("simdebug on, "); else printf("simdebug off, "); if (config.sim.iprompt) printf("interactive prompt on\n"); else printf("interactive prompt off\n"); printf("Machine initialization...\n"); generate_time_pretty (temp, config.sim.clkcycle_ps); printf("Clock cycle: %s\n", temp); if (testsprbits(SPR_UPR, SPR_UPR_DCP)) printf("Data cache tag: %s\n", config.dc.tagtype == CT_VIRTUAL ? "virtual" : "physical"); else printf("No data cache.\n"); if (testsprbits(SPR_UPR, SPR_UPR_ICP)) printf("Insn cache tag: %s\n", config.ic.tagtype == CT_VIRTUAL ? "virtual" : "physical"); else printf("No instruction cache.\n"); if (config.cpu.bpb) printf("BPB simulation on.\n"); else printf("BPB simulation off.\n"); if (config.cpu.btic) printf("BTIC simulation on.\n"); else printf("BTIC simulation off.\n"); } } /* Forward declarations of functions */ void sim_clkcycle (); void change_device (); void end_device (); void uart_nuarts (); void uart_baseaddr (); void uart_rxfile (); void uart_txfile (); void uart_jitter (); void uart_irq (); void uart_16550 (); void uart_vapi_id (); void dma_ndmas (); void dma_baseaddr (); void dma_irq (); void dma_vapi_id (); void memory_type (); void memory_nmemories (); void memory_ce (); void memory_baseaddr (); void memory_size (); void memory_name (); void memory_log (); void memory_delayr (); void memory_delayw (); void cpu_raw_range (); void eth_nethernets (); void eth_baseaddr (); void eth_dma (); void eth_rx_channel (); void eth_tx_channel (); void eth_rxfile (); void eth_txfile (); void eth_vapi_id (); void gpio_ngpios (); void gpio_baseaddr (); void gpio_irq (); void gpio_base_vapi_id (); void immu_enabled (); void immu_nsets (); void immu_nways (); void immu_pagesize (); void immu_entrysize (); void immu_ustates (); void dmmu_enabled (); void dmmu_nsets (); void dmmu_nways (); void dmmu_pagesize (); void dmmu_entrysize (); void dmmu_ustates (); void ic_enabled (); void ic_nsets (); void ic_nways (); void ic_blocksize (); void ic_ustates (); void ic_tagtype (); void dc_enabled (); void dc_nsets (); void dc_nways (); void dc_blocksize (); void dc_ustates (); void dc_tagtype (); unsigned long tempL; unsigned long tempUL; char tempS[STR_SIZE]; #define CPF_SUBSECTION 1 #define CPF_SUBFIELD 2 struct section sections[] = { {"?", 0}, /* 0 */ {"mc", 0}, {"uart", 0}, {"dma", 0}, {"memory", 0}, {"cpu", 0}, {"sim", 0}, {"debug", 0}, {"VAPI", 0}, {"ethernet",0}, {"tick", 0}, /* 10 */ {"immu", 0}, {"dmmu", 0}, {"ic", 0}, {"dc", 0}, {"gpio", 0} }; /* *INDENT-OFF* */ /* Parameter definitions */ struct config_params { int section; int attr; char *name; char *type; void (*func)(); void *addr; } config_params[] = { {1, 0, "enabled", "=%i", NULL, (void *)(&config.mc.enabled)}, {1, 0, "baseaddr", "=0x%x", NULL, (void *)(&config.mc.baseaddr)}, {1, 0, "POC", "=0x%x", NULL, (void *)(&config.mc.POC)}, {2, 0, "enabled", "=%i", NULL, (void *)(&config.uarts_enabled)}, {2, 0, "nuarts", "=%i", uart_nuarts, (void *)(&tempL)}, {2, 0, "device", "%i", change_device, (void *)(&tempL)}, {2, 0, "enddevice", "", end_device, NULL}, {2, 0, "baseaddr", "=0x%x", uart_baseaddr, (void *)(&tempUL)}, {2, 0, "irq", "=%i", uart_irq, (void *)(&tempL)}, {2, 0, "16550", "=%i", uart_16550, (void *)(&tempL)}, {2, 0, "jitter", "=%i", uart_jitter, (void *)(&tempL)}, {2, 0, "rxfile", "=\"%s\"", uart_rxfile, (void *)(&tempS[0])}, {2, 0, "txfile", "=\"%s\"", uart_txfile, (void *)(&tempS[0])}, {2, 0, "vapi_id", "=0x%x", uart_vapi_id, (void *)(&tempUL)}, {3, 0, "enabled", "=%i", NULL, (void *)(&config.dmas_enabled)}, {3, 0, "ndmas", "=%i", dma_ndmas, (void *)(&tempL)}, {3, 0, "device", "%i", change_device, (void *)(&tempL)}, {3, 0, "enddevice", "", end_device, NULL}, {3, 0, "baseaddr", "=0x%x", dma_baseaddr, (void *)(&tempUL)}, {3, 0, "irq", "=%i", dma_irq, (void *)(&tempL)}, {3, 0, "vapi_id", "=0x%x", dma_vapi_id, (void *)(&tempUL)}, {4, 0, "random_seed", "=%i", NULL, (void *)(&config.memory.random_seed)}, {4, 0, "pattern", "=%i", NULL, (void *)(&config.memory.pattern)}, {4, 0, "type", "=%s ", memory_type, (void *)(&tempS[0])}, {4, 0, "nmemories", "=%i", memory_nmemories,(void *)(&tempL)}, {4, 0, "device", "%i", change_device, (void *)(&tempL)}, {4, 0, "enddevice", "", end_device, NULL}, {4, 0, "ce", "=%i", memory_ce, (void *)(&tempL)}, {4, 0, "baseaddr", "=0x%x", memory_baseaddr,(void *)(&tempUL)}, {4, 0, "size", "=0x%x", memory_size, (void *)(&tempUL)}, {4, 0, "name", "=\"%s\"", memory_name, (void *)(&tempS[0])}, {4, 0, "log", "=\"%s\"", memory_log, (void *)(&tempS[0])}, {4, 0, "delayr", "=%i", memory_delayr, (void *)(&tempL)}, {4, 0, "delayw", "=%i", memory_delayw, (void *)(&tempL)}, {5, 0, "ver", "=0x%x", NULL, (void *)(&config.cpu.ver)}, {5, 0, "rev", "=0x%x", NULL, (void *)(&config.cpu.rev)}, {5, 0, "upr", "=0x%x", NULL, (void *)(&config.cpu.upr)}, {5, 0, "hazards", "=%i", NULL, (void *)(&config.cpu.hazards)}, {5, 0, "superscalar", "=%i", NULL, (void *)(&config.cpu.superscalar)}, {5, 0, "dependstats", "=%i", NULL, (void *)(&config.cpu.dependstats)}, {5, 0, "sbp_bnf_fwd", "=%i", NULL, (void *)(&config.cpu.sbp_bnf_fwd)}, {5, 0, "sbp_bf_fwd", "=%i", NULL, (void *)(&config.cpu.sbp_bf_fwd)}, {5, 0, "raw_range", "=%i", cpu_raw_range, (void *)(&config.cpu.raw_range)}, {5, 0, "bpb", "=%i", NULL, (void *)(&config.cpu.bpb)}, {5, 0, "btic", "=%i", NULL, (void *)(&config.cpu.btic)}, {6, 0, "debug", "=%i", NULL, (void *)(&config.sim.debug)}, {6, 0, "iprompt", "=%i", NULL, (void *)(&config.sim.iprompt)}, {6, 0, "verbose", "=%i", NULL, (void *)(&config.sim.verbose)}, {6, 0, "profile", "=%i", NULL, (void *)(&config.sim.profile)}, {6, 0, "prof_fn", "=\"%s\"", NULL, (void *)(&config.sim.prof_fn[0])}, {6, 0, "history", "=%i", NULL, (void *)(&config.sim.history)}, {6, 0, "exe_log", "=%i", NULL, (void *)(&config.sim.exe_log)}, {6, 0, "exe_log_fn", "=\"%s\"", NULL, (void *)(&config.sim.exe_log_fn[0])}, {6, 0, "clkcycle", "=%s ", sim_clkcycle, (void *)(&tempS[0])}, {7, 0, "enabled", "=%i", NULL, (void *)(&config.debug.enabled)}, {7, 0, "gdb_enabled", "=%i", NULL, (void *)(&config.debug.gdb_enabled)}, {7, 0, "server_port", "=%i", NULL, (void *)(&config.debug.server_port)}, {7, 0, "vapi_id", "=0x%x", NULL, (void *)(&config.debug.vapi_id)}, {8, 0, "enabled", "=%i", NULL, (void *)(&config.vapi.enabled)}, {8, 0, "server_port", "=%i", NULL, (void *)(&config.vapi.server_port)}, {8, 0, "log_enabled", "=%i", NULL, (void *)(&config.vapi.log_enabled)}, {8, 0, "hide_device_id", "=%i", NULL, (void *)(&config.vapi.hide_device_id)}, {8, 0, "vapi_log_fn", "=\"%s\"", NULL, (void *)(&config.vapi.vapi_fn[0])}, {9, 0, "enabled", "=%i", NULL, (void *)(&config.ethernets_enabled)}, {9, 0, "nethernets", "=%i", eth_nethernets,(void *)(&tempL)}, {9, 0, "device", "%i", change_device, (void *)(&tempL)}, {9, 0, "enddevice", "", end_device, NULL}, {9, 0, "baseaddr", "=0x%x", eth_baseaddr, (void *)(&tempUL)}, {9, 0, "dma", "=%i", eth_dma, (void *)(&tempL)}, {9, 0, "rx_channel", "=%i", eth_rx_channel,(void *)(&tempL)}, {9, 0, "tx_channel", "=%i", eth_tx_channel,(void *)(&tempL)}, {9, 0, "rxfile", "=\"%s\"", eth_rxfile, (void *)(&tempS[0])}, {9, 0, "txfile", "=\"%s\"", eth_txfile, (void *)(&tempS[0])}, {9, 0, "vapi_id", "=0x%x", eth_vapi_id, (void *)(&tempUL)}, {10,0, "enabled", "=%i", NULL, (void *)(&config.tick.enabled)}, {10,0, "irq", "=%i", NULL, (void *)(&config.tick.irq)}, {11,0, "enabled", "=%i", immu_enabled, (void *)(&tempL)}, {11,0, "nsets", "=%i", immu_nsets, (void *)(&tempL)}, {11,0, "nways", "=%i", immu_nways, (void *)(&tempL)}, {11,0, "pagesize", "=%i", immu_pagesize, (void *)(&tempL)}, {11,0, "entrysize", "=%i", immu_entrysize,(void *)(&tempL)}, {11,0, "ustates", "=%i", immu_ustates, (void *)(&tempL)}, {12,0, "enabled", "=%i", dmmu_enabled, (void *)(&tempL)}, {12,0, "nsets", "=%i", dmmu_nsets, (void *)(&tempL)}, {12,0, "nways", "=%i", dmmu_nways, (void *)(&tempL)}, {12,0, "pagesize", "=%i", dmmu_pagesize, (void *)(&tempL)}, {12,0, "entrysize", "=%i", dmmu_entrysize,(void *)(&tempL)}, {12,0, "ustates", "=%i", dmmu_ustates, (void *)(&tempL)}, {13,0, "enabled", "=%i", ic_enabled, (void *)(&tempL)}, {13,0, "nsets", "=%i", ic_nsets, (void *)(&tempL)}, {13,0, "nways", "=%i", ic_nways, (void *)(&tempL)}, {13,0, "blocksize", "=%i", ic_blocksize, (void *)(&tempL)}, {13,0, "ustates", "=%i", ic_ustates, (void *)(&tempL)}, {13,0, "tagtype", "=%s ", ic_tagtype, (void *)(&tempS)}, {14,0, "enabled", "=%i", dc_enabled, (void *)(&tempL)}, {14,0, "nsets", "=%i", dc_nsets, (void *)(&tempL)}, {14,0, "nways", "=%i", dc_nways, (void *)(&tempL)}, {14,0, "blocksize", "=%i", dc_blocksize, (void *)(&tempL)}, {14,0, "ustates", "=%i", dc_ustates, (void *)(&tempL)}, {14,0, "tagtype", "=%s ", dc_tagtype, (void *)(&tempS)}, {15,0, "enabled", "=%i", NULL, (void *)(&config.gpios_enabled)}, {15,0, "ngpios", "=%i", gpio_ngpios, (void *)(&tempL)}, {15,0, "device", "%i", change_device, (void *)(&tempL)}, {15,0, "baseaddr", "=0x%x", gpio_baseaddr, (void *)(&tempUL)}, {15,0, "irq", "=%i", gpio_irq, (void *)(&tempL)}, {15,0, "base_vapi_id", "=0x%x", gpio_base_vapi_id, (void *)(&tempUL)}, {15, 0, "enddevice", "", end_device, NULL} }; /* *INDENT-ON* */ int current_device = -1; void change_device () { current_device = tempL; } void end_device () { current_device = -1; } void sim_clkcycle () { int len = strlen (tempS); int pos = len - 1; long time; if (len < 2) goto err; if (tempS[pos--] != 's') goto err; switch (tempS[pos--]) { case 'p': time = 1; break; case 'n': time = 1000; break; case 'u': time = 1000000; break; case 'm': time = 1000000000; break; default: goto err; } tempS[pos + 1] = 0; config.sim.clkcycle_ps = time * atol (tempS); return; err: ERROR("invalid time format."); } void uart_nuarts () { if (tempL >= 0 && tempL < MAX_UARTS) config.nuarts = tempL; else ERROR("invalid number of devices."); } void uart_baseaddr () { if (current_device >= 0 && current_device < config.nuarts) config.uarts[current_device].baseaddr = tempUL; else ERROR("invalid device number."); } void uart_jitter () { if (current_device >= 0 && current_device < config.nuarts) config.uarts[current_device].jitter = tempL; else ERROR("invalid device number."); } void uart_irq () { if (current_device >= 0 && current_device < config.nuarts) config.uarts[current_device].irq = tempL; else ERROR("invalid device number."); } void uart_16550 () { if (current_device >= 0 && current_device < config.nuarts) config.uarts[current_device].uart16550 = tempL; else ERROR("invalid device number."); } void uart_rxfile () { if (current_device >= 0 && current_device < config.nuarts) strcpy (config.uarts[current_device].rxfile, tempS); else ERROR("invalid device number."); } void uart_txfile () { if (current_device >= 0 && current_device < config.nuarts) strcpy (config.uarts[current_device].txfile, tempS); else ERROR("invalid device number."); } void uart_vapi_id () { if (current_device >= 0 && current_device < config.nuarts) config.uarts[current_device].vapi_id = tempUL; else ERROR("invalid device number."); } void dma_ndmas () { if (tempL >= 0 && tempL < MAX_DMAS) config.ndmas = tempL; else ERROR("invalid number of devices."); } void dma_baseaddr () { if (current_device >= 0 && current_device < config.ndmas) config.dmas[current_device].baseaddr = tempUL; else ERROR("invalid device number."); } void dma_irq () { if (current_device >= 0 && current_device < config.ndmas) config.dmas[current_device].irq = tempL; else ERROR("invalid device number."); } void dma_vapi_id () { if (current_device >= 0 && current_device < config.ndmas) config.dmas[current_device].vapi_id = tempUL; else ERROR("invalid device number."); } void memory_nmemories () { if (tempL >= 0 && tempL < MAX_MEMORIES) config.memory.nmemories = tempL; else ERROR("invalid number of devices."); } void memory_type () { if (strcmp (tempS, "unknown") == 0) config.memory.type = MT_UNKNOWN; else if (strcmp (tempS, "random") == 0) config.memory.type = MT_RANDOM; else if (strcmp (tempS, "pattern") == 0) config.memory.type = MT_PATTERN; else if (strcmp (tempS, "zero") == 0) { config.memory.type = MT_PATTERN; config.memory.pattern = 0; } else { char tmp[200]; sprintf (tmp, "invalid memory type '%s'.\n", tempS); ERROR(tmp); } } void memory_ce () { if (current_device >= 0 && current_device < config.memory.nmemories) config.memory.table[current_device].ce = tempL; else ERROR("invalid device number."); } void memory_baseaddr () { if (current_device >= 0 && current_device < config.memory.nmemories) config.memory.table[current_device].baseaddr = tempUL; else ERROR("invalid device number."); } void memory_size () { if (current_device >= 0 && current_device < config.memory.nmemories) config.memory.table[current_device].size = tempUL; else ERROR("invalid device number."); } void memory_name () { if (current_device >= 0 && current_device < config.memory.nmemories) strcpy (config.memory.table[current_device].name, tempS); else ERROR("invalid device number."); } void memory_log () { if (current_device >= 0 && current_device < config.memory.nmemories) strcpy (config.memory.table[current_device].log, tempS); else ERROR("invalid device number."); } void memory_delayr () { if (current_device >= 0 && current_device < config.memory.nmemories) config.memory.table[current_device].delayr = tempL; else ERROR("invalid device number."); } void memory_delayw () { if (current_device >= 0 && current_device < config.memory.nmemories) config.memory.table[current_device].delayw = tempL; else ERROR("invalid device number."); } void cpu_raw_range () { if (config.cpu.raw_range >= RAW_RANGE) { config.cpu.raw_range = RAW_RANGE - 1; WARNING("raw range too large; truncated."); } else if (config.cpu.raw_range < 0) { config.cpu.raw_range = 0; WARNING("raw range negative; disabled."); } } void eth_nethernets () { if (tempL >= 0 && tempL < MAX_ETHERNETS) config.nethernets = tempL; else ERROR("invalid number of devices."); } void eth_baseaddr () { if (current_device >= 0 && current_device < config.nethernets) config.ethernets[current_device].baseaddr = tempUL; else ERROR("invalid device number."); } void eth_dma () { if (current_device >= 0 && current_device < config.nethernets) config.ethernets[current_device].dma = tempL; else ERROR("invalid device number."); } void eth_rx_channel () { if (current_device >= 0 && current_device < config.nethernets) config.ethernets[current_device].rx_channel = tempL; else ERROR("invalid device number."); } void eth_tx_channel () { if (current_device >= 0 && current_device < config.nethernets) config.ethernets[current_device].rx_channel = tempL; else ERROR("invalid device number."); } void eth_rxfile () { if (current_device >= 0 && current_device < config.nethernets) strcpy (config.ethernets[current_device].rxfile, tempS); else ERROR("invalid device number."); } void eth_txfile () { if (current_device >= 0 && current_device < config.nethernets) strcpy (config.ethernets[current_device].txfile, tempS); else ERROR("invalid device number."); } void eth_vapi_id () { if (current_device >= 0 && current_device < config.nethernets) config.ethernets[current_device].vapi_id = tempUL; else ERROR("invalid device number."); } void gpio_ngpios () { if (tempL >= 0 && tempL < MAX_GPIOS) config.ngpios = tempL; else ERROR("invalid number of devices."); } void gpio_baseaddr () { if (current_device >= 0 && current_device < config.ngpios) config.gpios[current_device].baseaddr = tempUL; else ERROR("invalid device number."); } void gpio_irq () { if (current_device >= 0 && current_device < config.ngpios) config.gpios[current_device].irq = tempL; else ERROR("invalid device number."); } void gpio_base_vapi_id () { if (current_device >= 0 && current_device < config.ngpios) config.gpios[current_device].base_vapi_id = tempUL; else ERROR("invalid device number."); } int is_power2 (int x) { while (!(x & 1)) x >>= 1; return x == 1; } void immu_enabled () { setsprbits (SPR_UPR, SPR_UPR_IMP, tempL & 1); } void dmmu_enabled () { setsprbits (SPR_UPR, SPR_UPR_DMP, tempL & 1); } void immu_nsets () { if (is_power2(tempL) && tempL <= 256) config.immu.nsets = tempL; else ERROR("value of power of two and lower or equal than 256 expected."); } void dmmu_nsets () { if (is_power2(tempL) && tempL <= 256) config.dmmu.nsets = tempL; else ERROR("value of power of two and lower or equal than 256 expected."); } void immu_nways () { if (tempL >= 1 && tempL <= 4) config.immu.nways = tempL; else ERROR("value 1, 2, 3 or 4 expected."); } void dmmu_nways () { if (tempL >= 1 && tempL <= 4) config.dmmu.nways = tempL; else ERROR("value 1, 2, 3 or 4 expected."); } void immu_pagesize () { if (is_power2(tempL)) config.immu.pagesize = tempL; else ERROR("value of power of two expected."); } void dmmu_pagesize () { if (is_power2(tempL)) config.dmmu.pagesize = tempL; else ERROR("value of power of two expected."); } void immu_entrysize () { if (is_power2(tempL)) config.immu.entrysize = tempL; else ERROR("value of power of two expected."); } void dmmu_entrysize () { if (is_power2(tempL)) config.dmmu.entrysize = tempL; else ERROR("value of power of two expected."); } void immu_ustates () { if (tempL >= 2 && tempL <= 4) config.immu.ustates = tempL; else ERROR("invalid USTATE."); } void dmmu_ustates () { if (tempL >= 2 && tempL <= 4) config.dmmu.ustates = tempL; else ERROR("invalid USTATE."); } void ic_enabled () { setsprbits (SPR_UPR, SPR_UPR_ICP, tempL & 1); } void ic_nsets () { if (is_power2(tempL) && tempL <= MAX_IC_SETS) config.ic.nsets = tempL; else { char tmp[200]; sprintf (tmp, "value of power of two and lower or equal than %i expected.", MAX_IC_SETS); ERROR(tmp); } } void ic_nways () { if (tempL >= 1 && tempL <= MAX_IC_WAYS) config.ic.nways = tempL; else ERROR("value 1, 2, 3 or 4 expected."); } void ic_blocksize () { if (is_power2(tempL)) config.ic.blocksize = tempL; else ERROR("value of power of two expected."); } void ic_ustates () { if (tempL >= 2 && tempL <= 4) config.ic.ustates = tempL; else ERROR("invalid USTATE."); } void ic_tagtype () { if (strcmp (tempS, "none") == 0) config.ic.tagtype = CT_NONE; else if (strcmp (tempS, "physical") == 0) config.ic.tagtype = CT_PHYSICAL; else if (strcmp (tempS, "virtual") == 0) config.ic.tagtype = CT_VIRTUAL; else { char tmp[200]; sprintf (tmp, "invalid cache type '%s'.\n", tempS); ERROR(tmp); } } void dc_enabled () { setsprbits (SPR_UPR, SPR_UPR_DCP, tempL & 1); } void dc_nsets () { if (is_power2(tempL) && tempL <= MAX_DC_SETS) config.dc.nsets = tempL; else { char tmp[200]; sprintf (tmp, "value of power of two and lower or equal than %i expected.", MAX_DC_SETS); ERROR(tmp); } } void dc_nways () { if (tempL >= 1 && tempL <= MAX_IC_WAYS) config.dc.nways = tempL; else ERROR("value 1, 2, 3 or 4 expected."); } void dc_blocksize () { if (is_power2(tempL)) config.dc.blocksize = tempL; else ERROR("value of power of two expected."); } void dc_ustates () { if (tempL >= 2 && tempL <= 4) config.dc.ustates = tempL; else ERROR("invalid USTATE."); } void dc_tagtype () { if (strcmp (tempS, "none") == 0) config.dc.tagtype = CT_NONE; else if (strcmp (tempS, "physical") == 0) config.dc.tagtype = CT_PHYSICAL; else if (strcmp (tempS, "virtual") == 0) config.dc.tagtype = CT_VIRTUAL; else { char tmp[200]; sprintf (tmp, "invalid cache type '%s'.\n", tempS); ERROR(tmp); } } /* Read environment from a script file. Does not fail - assumes defaukt configuration instead. The syntax of script file is: param = value section x data param = value end Example: section mc memory_table_file = sim.mem enable = 1 POC = 0x47892344 end */ void read_script_file (char *filename) { FILE *f; unsigned long memory_needed = 0; char *home = getenv("HOME"); char ctmp[STR_SIZE]; int local = 1; section = 0; sprintf(ctmp, "%s/.or1k/%s", home, filename); if ((f = fopen (filename, "rt")) != NULL || home != NULL && !(local = 0) && (f = fopen (ctmp, "rt")) != NULL) { unsigned long start, length; char type[STR_SIZE]; int nparam; int rd, wd; if (config.sim.verbose) printf ("Reading script file from '%s'...\n", local ? filename : ctmp); while (!feof(f)) { char param[STR_SIZE]; if (fscanf(f, "%s ", ¶m) != 1) break; /* Is this a sections? */ if (strcmp (param, "section") == 0) { int i; section = 0; if (fscanf (f, "%s\n", ¶m) != 1) { fprintf (stderr, "%s: ERROR: Section name required.\n", local ? filename : ctmp); exit (1); } for (i = 1; i < sizeof(sections) / sizeof(struct section); i++) if (strcmp (sections[i].name, param) == 0) { section = i; break; } if (!section) { char tmp[200]; sprintf (tmp, "Unknown section: %s; ignoring.", param); WARNING(tmp); /* just skip section */ while (fscanf (f, "%s\n", ¶m) != 1 && strcmp (param, "end")); } } else if (strcmp (param, "end") == 0) { section = 0; } else if (strncmp (param, "/*", 2) == 0) { char c0 = 0, c1 = 0; while (c0 != '*' || c1 != '/') { c0 = c1; c1 = fgetc(f); if (feof(f)) { fprintf (stderr, "%s: ERROR: Comment reached EOF.\n", local ? filename : ctmp); exit (1); } } } else { int i, found = -1; for (i = 0; i < sizeof(config_params)/sizeof(struct config_params); i++) if (config_params[i].section == section && strcmp (config_params[i].name, param) == 0) { found = i; break; } if (found < 0) { char tmp[200]; sprintf (tmp, "Invalid parameter: %s; ignoring.\n", param); WARNING(tmp); while (fgetc(f) != '\n' || feof(f)); continue; } /* Parse parameter value */ { if (config_params[found].type[0]) if(fscanf_ex (f, config_params[found].type, config_params[found].addr, 0)) exit (1); } if (config_params[found].func) config_params[found].func(); } } fclose (f); runtime.sim.script_file_specified = 1; } else if (config.sim.verbose) fprintf (stderr, "WARNING: Cannot read script file from '%s',\nneither '%s'.\n", filename, ctmp); } /* Utility for execution of set sim command. */ static int set_config (char *s) { char *sec, *item, *params; int noparams = 0, i, noitem = 0; while (*s && isspace (*s)) s++; sec = s; printf ("s:%s\n", s); while (*s && *s != ' ') s++; if (!(*s)) noitem = 1; *s = 0; printf ("sec:%s\n", sec); section = 0; for (i = 1; i < sizeof(sections) / sizeof(struct section); i++) if (strcmp (sections[i].name, sec) == 0) { section = i; break; } if (!section) return 1; if (noitem) return 2; item = ++s; while (*s && *s != ' ') s++; if (!(*s)) { noparams = 1; params = ""; } else params = s + 1; *s = 0; printf ("item:%s\n", item); printf ("params:%s\n", params); { int i, found = -1; for (i = 0; i < sizeof(config_params)/sizeof(struct config_params); i++) if (config_params[i].section == section && strcmp (config_params[i].name, item) == 0) { found = i; break; } if (found < 0) return 2; /* Parse parameter value */ if (config_params[found].type[0]) if(fscanf_ex (0, config_params[found].type, config_params[found].addr, params)) return 3; if (config_params[found].func) config_params[found].func(); } return 0; } /* Executes set sim command, displays error. */ void set_config_command(char *s) { int i; switch (set_config (s)) { case 1: printf ("Invalid or missing section name. One of valid sections must be specified:\n"); for (i = 1; i < sizeof(sections) / sizeof(struct section); i++) printf ("%s ", sections[i].name); printf ("\n"); break; case 2: printf ("Invalid or missing item name. One of valid items must be specified:\n"); for (i = 0; i < sizeof(config_params)/sizeof(struct config_params); i++) if (config_params[i].section == section) printf ("%s ", config_params[i].name); printf ("\n"); break; case 3: printf ("Invalid parameters specified.\n"); break; } }
Go to most recent revision | Compare with Previous | Blame | View Log