static void dump_xsdt(struct backend *be, const struct acpi_rsdp *rsdp) { const struct acpi_xsdt *xsdt; uint32_t rsdp_len = rsdp->rev > 0 ? rsdp->len : 20; uint32_t i, n; if (rsdp_len < 34) return; if (!addr_ok(rsdp->xsdt_addr)) return; xsdt = (const struct acpi_xsdt *)(size_t)rsdp->xsdt_addr; if (memcmp(xsdt->hdr.sig, "XSDT", 4) || is_valid_table(xsdt) > ERR_CSUM) return; dump_table(be, xsdt->hdr.sig, xsdt, xsdt->hdr.len); if (xsdt->hdr.len < 36) return; n = (xsdt->hdr.len - 36) >> 3; for (i = 0; i < n; i++) { const struct acpi_hdr *hdr; if (addr_ok(xsdt->entry[i])) { hdr = (const struct acpi_hdr *)(size_t)(xsdt->entry[i]); if (is_valid_table(hdr) <= ERR_CSUM) dump_table(be, hdr->sig, hdr, hdr->len); } } }
/*------------------------------------------------------------------------- * Function: dump_tables * * Purpose: display the contents of tables for debugging purposes * * Return: void * * Programmer: Ruey-Hsia Li * * Modifications: * *------------------------------------------------------------------------- */ void dump_tables(find_objs_t *info) { dump_table("group_table", info->group_table); dump_table("dset_table", info->dset_table); dump_table("type_table", info->type_table); }
// Write the compact table void CompactHashtableWriter::dump(char** top, char* end) { NumberSeq summary; char* old_top = *top; juint* p = (juint*)(*top); uintx base_address = uintx(MetaspaceShared::shared_rs()->base()); *p++ = high(base_address); *p++ = low (base_address); // base address *p++ = _num_entries; // number of entries in the table *p++ = _num_buckets; // number of buckets in the table juint* first_bucket = NULL; juint* compact_table = dump_table(p, &first_bucket, &summary); juint* bucket_end = dump_buckets(compact_table, first_bucket, &summary); assert(bucket_end <= (juint*)end, "cannot write past end"); *top = (char*)bucket_end; if (PrintSharedSpaces) { double avg_cost = 0.0; if (_num_entries > 0) { avg_cost = double(_required_bytes)/double(_num_entries); } tty->print_cr("Shared %s table stats -------- base: " PTR_FORMAT, _table_name, (intptr_t)base_address); tty->print_cr("Number of entries : %9d", _num_entries); tty->print_cr("Total bytes used : %9d", (int)((*top) - old_top)); tty->print_cr("Average bytes per entry : %9.3f", avg_cost); tty->print_cr("Average bucket size : %9.3f", summary.avg()); tty->print_cr("Variance of bucket size : %9.3f", summary.variance()); tty->print_cr("Std. dev. of bucket size: %9.3f", summary.sd()); tty->print_cr("Maximum bucket size : %9d", (int)summary.maximum()); } }
// Write the compact table void CompactHashtableWriter::dump(SimpleCompactHashtable *cht, const char* table_name) { NumberSeq summary; allocate_table(); dump_table(&summary); int table_bytes = _stats->bucket_bytes + _stats->hashentry_bytes; address base_address = address(MetaspaceShared::shared_rs()->base()); cht->init(base_address, _num_entries, _num_buckets, _compact_buckets->data(), _compact_entries->data()); if (PrintSharedSpaces) { double avg_cost = 0.0; if (_num_entries > 0) { avg_cost = double(table_bytes)/double(_num_entries); } tty->print_cr("Shared %s table stats -------- base: " PTR_FORMAT, table_name, (intptr_t)base_address); tty->print_cr("Number of entries : %9d", _num_entries); tty->print_cr("Total bytes used : %9d", table_bytes); tty->print_cr("Average bytes per entry : %9.3f", avg_cost); tty->print_cr("Average bucket size : %9.3f", summary.avg()); tty->print_cr("Variance of bucket size : %9.3f", summary.variance()); tty->print_cr("Std. dev. of bucket size: %9.3f", summary.sd()); tty->print_cr("Empty buckets : %9d", _num_empty_buckets); tty->print_cr("Value_Only buckets : %9d", _num_value_only_buckets); tty->print_cr("Other buckets : %9d", _num_other_buckets); } }
void dump_acpi(struct backend *be) { const struct acpi_rsdp *rsdp; uint32_t rsdp_len; rsdp = find_rsdp(); printf("Dumping ACPI... "); if (!rsdp) return; /* No ACPI information found */ cpio_mkdir(be, "acpi"); rsdp_len = rsdp->rev > 0 ? rsdp->len : 20; dump_table(be, "RSDP", rsdp, rsdp_len); dump_rsdt(be, rsdp); dump_xsdt(be, rsdp); rb_destroy(rb_types); rb_destroy(rb_addrs); printf("done.\n"); }
static void dump_table(TableListNode *head) { if (head == NULL) { return; } printf("key : %s, opaque data %p\n", head->key, head->opaque); dump_table(head->next); }
int main(int argc, char *argv[]) { QMP_thread_level_t qmp_unused_1; int i; QMP_init_msg_passing(&argc, &argv, QMP_THREAD_SINGLE, &qmp_unused_1); if (argc != 14) { printf("usage: %s Lx Ly Lz Lt Ls Nx Ny Nz Nt nx ny nz nt\n", argv[0]); return 1; } for (i = 0; i < 5; i++) lattice_size[i] = atoi(argv[1 + i]); for (i = 0; i < 4; i++) network[i] = atoi(argv[6 + i]); for (i = 0; i < 4; i++) node[i] = atoi(argv[10 + i]); printf("lattice %d %d %d %d %d\n", lattice_size[0], lattice_size[1], lattice_size[2], lattice_size[3], lattice_size[4]); printf("network %d %d %d %d\n", network[0], network[1], network[2], network[3]); printf("node %d %d %d %d\n", node[0], node[1], node[2], node[3]); L3(DWF_init)(lattice_size, NULL, NULL); dump_table("even_odd", &even_odd); dump_table("odd_even", &odd_even); return 0; }
static void equalizer_state_compute_impulse_response(EqualizerState *s){ void *fft_handle=ms_fft_init(s->nfft); ms_message("Spectral domain:"); dump_table(s->fft_cpx,s->nfft); ms_ifft(fft_handle,s->fft_cpx,s->fir); ms_fft_destroy(fft_handle); /* ms_message("Inverse fft result:"); dump_table(s->fir,s->fir_len); */ time_shift(s->fir,s->fir_len); /* ms_message("Time shifted:"); dump_table(s->fir,s->fir_len); */ norm_and_apodize(s->fir,s->fir_len); ms_message("Apodized impulse response:"); dump_table(s->fir,s->fir_len); s->needs_update=FALSE; }
static void dump_rsdt(struct backend *be, const struct acpi_rsdp *rsdp) { const struct acpi_rsdt *rsdt; uint32_t i, n; rsdt = (const struct acpi_rsdt *)rsdp->rsdt_addr; if (memcmp(rsdt->hdr.sig, "RSDT", 4) || is_valid_table(rsdt) > ERR_CSUM) return; dump_table(be, rsdt->hdr.sig, rsdt, rsdt->hdr.len); if (rsdt->hdr.len < 36) return; n = (rsdt->hdr.len - 36) >> 2; for (i = 0; i < n; i++) { const struct acpi_hdr *hdr = (const struct acpi_hdr *)(rsdt->entry[i]); if (is_valid_table(hdr) <= ERR_CSUM) dump_table(be, hdr->sig, hdr, hdr->len); } }
int main(int argc, char *argv[]) { int object_file = 0; if (argc > 1 && (strcmp(argv[1], "-o") == 0)) { object_file = 1; } char *passone = "/tmp/masm.passone"; p1 = fopen(passone, "w+"); unlink(passone); generate_first_pass(); if (object_file) { print_first_pass(); append_table(); } else { generate_code(); dump_table(); } return 0; }
int main(int argc, char **argv) { int port = 0; char *user = NULL; char *passwd = NULL; char *host = NULL; char *dbname = NULL; int trace = 0; int describe = 0; int functions = 0; int useinserts = 0; int c; Mapi mid; int quiet = 0; stream *out; char user_set_as_flag = 0; char *table = NULL; static struct option long_options[] = { {"host", 1, 0, 'h'}, {"port", 1, 0, 'p'}, {"database", 1, 0, 'd'}, {"describe", 0, 0, 'D'}, {"functions", 0, 0, 'f'}, {"table", 1, 0, 't'}, {"inserts", 0, 0, 'N'}, {"Xdebug", 0, 0, 'X'}, {"user", 1, 0, 'u'}, {"quiet", 0, 0, 'q'}, {"help", 0, 0, '?'}, {0, 0, 0, 0} }; parse_dotmonetdb(&user, &passwd, NULL, NULL, NULL, NULL); while ((c = getopt_long(argc, argv, "h:p:d:Dft:NXu:q?", long_options, NULL)) != -1) { switch (c) { case 'u': if (user) free(user); user = strdup(optarg); user_set_as_flag = 1; break; case 'h': host = optarg; break; case 'p': assert(optarg != NULL); port = atoi(optarg); break; case 'd': dbname = optarg; break; case 'D': describe = 1; break; case 'N': useinserts = 1; break; case 'f': if (table) usage(argv[0], -1); functions = 1; break; case 't': if (table || functions) usage(argv[0], -1); table = optarg; break; case 'q': quiet = 1; break; case 'X': trace = MAPI_TRACE; break; case '?': /* a bit of a hack: look at the option that the current `c' is based on and see if we recognize it: if -? or --help, exit with 0, else with -1 */ usage(argv[0], strcmp(argv[optind - 1], "-?") == 0 || strcmp(argv[optind - 1], "--help") == 0 ? 0 : -1); default: usage(argv[0], -1); } } if (optind == argc - 1) dbname = argv[optind]; else if (optind != argc) usage(argv[0], -1); /* when config file would provide defaults */ if (user_set_as_flag) passwd = NULL; if (user == NULL) user = simple_prompt("user", BUFSIZ, 1, prompt_getlogin()); if (passwd == NULL) passwd = simple_prompt("password", BUFSIZ, 0, NULL); mid = mapi_connect(host, port, user, passwd, "sql", dbname); if (user) free(user); if (passwd) free(passwd); if (mid == NULL) { fprintf(stderr, "failed to allocate Mapi structure\n"); exit(2); } if (mapi_error(mid)) { mapi_explain(mid, stderr); exit(2); } if (!quiet) { char *motd = mapi_get_motd(mid); if (motd) fprintf(stderr, "%s", motd); } mapi_trace(mid, trace); mapi_cache_limit(mid, 10000); out = file_wastream(stdout, "stdout"); if (out == NULL) { fprintf(stderr, "failed to allocate stream\n"); exit(2); } if (!quiet) { char buf[27]; time_t t = time(0); char *p; #ifdef HAVE_CTIME_R3 ctime_r(&t, buf, sizeof(buf)); #else #ifdef HAVE_CTIME_R ctime_r(&t, buf); #else strncpy(buf, ctime(&t), sizeof(buf)); #endif #endif if ((p = strrchr(buf, '\n')) != NULL) *p = 0; mnstr_printf(out, "-- msqldump %s %s%s %s\n", describe ? "describe" : "dump", functions ? "functions" : table ? "table " : "database", table ? table : "", buf); dump_version(mid, out, "--"); } if (functions) c = dump_functions(mid, out, NULL, NULL); else if (table) c = dump_table(mid, NULL, table, out, describe, 1, useinserts); else c = dump_database(mid, out, describe, useinserts); mnstr_flush(out); mapi_destroy(mid); if (mnstr_errnr(out)) { fprintf(stderr, "%s: %s", argv[0], mnstr_error(out)); return 1; } mnstr_destroy(out); return c; }
int main(int argc, char **argv) { static const struct option options[] = { { "help", no_argument, NULL, 'h' }, { "interactive", no_argument, NULL, 'i' }, {} }; int fd = -1; int opt_interactive = 0; int i; while (1) { int option; option = getopt_long(argc, argv, "hi", options, NULL); if (option == -1) break; switch (option) { case 'h': help(0); case 'i': opt_interactive = 1; break; default: return 1; } } if (argc < optind+1) help (1); if ((fd = evdev_open(argv[optind])) < 0) return 3; /* one argument (device): dump or interactive */ if (argc == optind+1) { if (opt_interactive) interactive(fd); else dump_table(fd); return 0; } /* two arguments (device, mapfile): set map file */ if (argc == optind+2) { merge_table(fd, default_keymap_path(argv[optind+1])); return 0; } /* more arguments (device, scancode/keyname pairs): set keys directly */ if ((argc - optind - 1) % 2 == 0) { for (i = optind+1; i < argc; i += 2) set_key(fd, argv[i], argv[i+1]); return 0; } /* invalid number of arguments */ help(1); return 1; /* not reached */ }
int main(int argc, char **argv) { static const struct option options[] = { { "help", no_argument, NULL, 'h' }, { "interactive", no_argument, NULL, 'i' }, {} }; int fd = -1; int opt_interactive = 0; int i; while (1) { int option; option = getopt_long(argc, argv, "hi", options, NULL); if (option == -1) break; switch (option) { case 'h': help(0); case 'i': opt_interactive = 1; break; default: return 1; } } if (argc < optind+1) help (1); if ((fd = evdev_open(argv[optind])) < 0) return 3; /* one argument (device): dump or interactive */ if (argc == optind+1) { if (opt_interactive) interactive(fd); else dump_table(fd); return 0; } /* two arguments (device, mapfile): set map file */ if (argc == optind+2) { const char *filearg = argv[optind+1]; if (strchr(filearg, '/')) { /* Keymap file argument is a path */ FILE *f = fopen(filearg, "re"); if (f) merge_table(fd, f); else perror(filearg); } else { /* Keymap file argument is a filename */ /* Open override file if present, otherwise default file */ char keymap_path[PATH_MAX]; FILE *f; snprintf(keymap_path, sizeof(keymap_path), "/etc/udev/keymaps/%s", filearg); f = fopen(keymap_path, "re"); if (f) { merge_table(fd, f); } else { snprintf(keymap_path, sizeof(keymap_path), UDEVLIBEXECDIR "/keymaps/%s", filearg); f = fopen(keymap_path, "re"); if (f) merge_table(fd, f); else perror(keymap_path); } } return 0; } /* more arguments (device, scancode/keyname pairs): set keys directly */ if ((argc - optind - 1) % 2 == 0) { for (i = optind+1; i < argc; i += 2) set_key(fd, argv[i], argv[i+1]); return 0; } /* invalid number of arguments */ help(1); return 1; /* not reached */ }
int search_bd_buf(char *buf, int len_bytes, unsigned long bd_offset_bytes, int *nr_populated_bdes) { unsigned long i; int total_entries = 0; dprintf3("%s(%p, %x, %lx, ...) buf end: %p\n", __func__, buf, len_bytes, bd_offset_bytes, buf + len_bytes); for (i = 0; i < len_bytes; i += sizeof(unsigned long)) { unsigned long bd_index = (bd_offset_bytes + i) / sizeof(unsigned long); unsigned long *bounds_dir_entry_ptr = (unsigned long *)&buf[i]; unsigned long bounds_dir_entry; unsigned long bd_for_vaddr; unsigned long bt_start; unsigned long bt_tail; int nr_entries; dprintf4("%s() loop i: %ld bounds_dir_entry_ptr: %p\n", __func__, i, bounds_dir_entry_ptr); bounds_dir_entry = *bounds_dir_entry_ptr; if (!bounds_dir_entry) { dprintf4("no bounds dir at index 0x%lx / 0x%lx " "start at offset:%lx %lx\n", bd_index, bd_index, bd_offset_bytes, i); continue; } dprintf3("found bounds_dir_entry: 0x%lx @ " "index 0x%lx buf ptr: %p\n", bounds_dir_entry, i, &buf[i]); /* mask off the enable bit: */ bounds_dir_entry &= ~0x1; (*nr_populated_bdes)++; dprintf4("nr_populated_bdes: %p\n", nr_populated_bdes); dprintf4("*nr_populated_bdes: %d\n", *nr_populated_bdes); bt_start = bounds_dir_entry; bt_tail = bounds_dir_entry + MPX_BOUNDS_TABLE_SIZE_BYTES - 1; if (!vaddr_mapped_by_range(bt_start)) { printf("bounds directory 0x%lx points to nowhere\n", bounds_dir_entry); mpx_dig_abort(); } if (!vaddr_mapped_by_range(bt_tail)) { printf("bounds directory end 0x%lx points to nowhere\n", bt_tail); mpx_dig_abort(); } /* * Each bounds directory entry controls 1MB of virtual address * space. This variable is the virtual address in the process * of the beginning of the area controlled by this bounds_dir. */ bd_for_vaddr = bd_index * (1UL<<20); nr_entries = dump_table(bounds_dir_entry, bd_for_vaddr, bounds_dir_global+bd_offset_bytes+i); total_entries += nr_entries; dprintf5("dir entry[%4ld @ %p]: 0x%lx %6d entries " "total this buf: %7d bd_for_vaddrs: 0x%lx -> 0x%lx\n", bd_index, buf+i, bounds_dir_entry, nr_entries, total_entries, bd_for_vaddr, bd_for_vaddr + (1UL<<20)); } dprintf3("%s(%p, %x, %lx, ...) done\n", __func__, buf, len_bytes, bd_offset_bytes); return total_entries; }
/* * perform some basic tests */ static void io_test(table_t *tab_p) { int ret, bucket_n, entry_n; table_t *tab2_p; (void)printf("Performing I/O tests:\n"); (void)fflush(stdout); #if 0 { long key, data; (void)table_clear(tab_p); key = 1; data = 2; (void)table_insert(tab_p, &key, sizeof(key), &data, sizeof(data), NULL, 0); key = 3; data = 4; (void)table_insert(tab_p, &key, sizeof(key), &data, sizeof(data), NULL, 0); key = 5; data = 6; (void)table_insert(tab_p, &key, sizeof(key), &data, sizeof(data), NULL, 0); (void)table_adjust(tab_p, 0); dump_table(tab_p); } #endif ret = table_info(tab_p, &bucket_n, &entry_n); if (ret != TABLE_ERROR_NONE) { (void)fprintf(stderr, "could not get info of table: %s\n", table_strerror(ret)); exit(1); } (void)printf("Table we are writing has %d buckets and %d entries\n", bucket_n, entry_n); /* * dump the table to disk */ int pmode = 0640; #ifdef win32 pmode = _S_IREAD | _S_IWRITE; #endif (void)unlink(TABLE_FILE); ret = table_write(tab_p, TABLE_FILE, pmode); if (ret != TABLE_ERROR_NONE) { (void)fprintf(stderr, "could not write table to '%s': %s\n", TABLE_FILE, table_strerror(ret)); exit(1); } #if 0 dump_table(tab_p); #endif /* * now read back in the table */ tab2_p = table_read(TABLE_FILE, &ret); if (tab2_p == NULL) { (void)fprintf(stderr, "could not read in file '%s': %s\n", TABLE_FILE, table_strerror(ret)); exit(1); } (void)printf("Testing table-read...\n"); if (test_eq(tab_p, tab2_p, 0)) { (void)printf(" equal.\n"); } else { (void)printf(" NOT equal.\n"); } ret = table_free(tab2_p); if (ret != TABLE_ERROR_NONE) { (void)fprintf(stderr, "could not free read table: %s\n", table_strerror(ret)); exit(1); } /* * mmap in the table */ tab2_p = table_mmap(TABLE_FILE, &ret); if (tab2_p == NULL) { (void)fprintf(stderr, "could not mmap file '%s': %s\n", TABLE_FILE, table_strerror(ret)); exit(1); } (void)printf("Testing table-mmap...\n"); if (test_eq(tab2_p, tab_p, 0)) { (void)printf(" equal.\n"); } else { (void)printf(" NOT equal.\n"); } ret = table_munmap(tab2_p); if (ret != TABLE_ERROR_NONE) { (void)fprintf(stderr, "could not munmap file '%s': %s\n", TABLE_FILE, table_strerror(ret)); exit(1); } }
void dump_inst_bind_table(void) { printf("FDT INSTANCE BINDING TABLE:\n"); dump_table(inst_bind_list_head); }
/* * Read configuration table from card under intalization phase * Returns 1 if ok, else 0 */ static int nozomi_read_config_table(struct nozomi *dc) { read_mem32((u32 *) &dc->config_table, dc->base_addr + 0, sizeof(struct config_table)); if (dc->config_table.signature != NOZOMI_CONFIG_MAGIC) { dev_err(&dc->pdev->dev, "ConfigTable Bad! 0x%08X != 0x%08X\n", dc->config_table.signature, NOZOMI_CONFIG_MAGIC); return 0; } if ((dc->config_table.version == 0) || (dc->config_table.toggle.enabled == TOGGLE_VALID)) { int i; DBG1("Second phase, configuring card"); nozomi_setup_memory(dc); dc->port[PORT_MDM].toggle_ul = dc->config_table.toggle.mdm_ul; dc->port[PORT_MDM].toggle_dl = dc->config_table.toggle.mdm_dl; dc->port[PORT_DIAG].toggle_dl = dc->config_table.toggle.diag_dl; DBG1("toggle ports: MDM UL:%d MDM DL:%d, DIAG DL:%d", dc->port[PORT_MDM].toggle_ul, dc->port[PORT_MDM].toggle_dl, dc->port[PORT_DIAG].toggle_dl); dump_table(dc); for (i = PORT_MDM; i < MAX_PORT; i++) { memset(&dc->port[i].ctrl_dl, 0, sizeof(struct ctrl_dl)); memset(&dc->port[i].ctrl_ul, 0, sizeof(struct ctrl_ul)); } /* Enable control channel */ dc->last_ier = dc->last_ier | CTRL_DL; writew(dc->last_ier, dc->reg_ier); dc->state = NOZOMI_STATE_ALLOCATED; dev_info(&dc->pdev->dev, "Initialization OK!\n"); return 1; } if ((dc->config_table.version > 0) && (dc->config_table.toggle.enabled != TOGGLE_VALID)) { u32 offset = 0; DBG1("First phase: pushing upload buffers, clearing download"); dev_info(&dc->pdev->dev, "Version of card: %d\n", dc->config_table.version); /* Here we should disable all I/O over F32. */ nozomi_setup_memory(dc); /* * We should send ALL channel pair tokens back along * with reset token */ /* push upload modem buffers */ write_mem32(dc->port[PORT_MDM].ul_addr[CH_A], (u32 *) &offset, 4); write_mem32(dc->port[PORT_MDM].ul_addr[CH_B], (u32 *) &offset, 4); writew(MDM_UL | DIAG_DL | MDM_DL, dc->reg_fcr); DBG1("First phase done"); } return 1; }
int main(int argc, char *argv[]) { int tok, i, dump_tab=0, linum=0; unsigned short temp; // if -s is included on masm command, set up to // dump the symbol table after the binary code if(argc > 1 && (strcmp(argv[1], "-s") == 0)) dump_tab = linum = 1; p1 = fopen("/tmp/passone", "w+"); unlink("/tmp/passone"); while(tok=yylex()){ switch(tok){ case LODD: switch(tok=yylex()){ case INTEG: str_12(yytext); fprintf(p1,"%d 0000%s\n", pc, cstr_12); break; case LABEL: fprintf(p1,"%d U0000000000000000 %s\n", pc, yytext); break; default: fprintf(stderr,"Bad operand after LODD is %s on line %d\n",yytext, pc); exit(1); } break; case STOD: switch(tok=yylex()){ case INTEG: str_12(yytext); fprintf(p1,"%d 0001%s\n", pc, cstr_12); break; case LABEL: fprintf(p1,"%d U0001000000000000 %s\n", pc, yytext); break; default: fprintf(stderr,"Bad operand after STOD is %s on line %d\n",yytext, pc); exit(1); } break; case ADDD: switch(tok=yylex()){ case INTEG: str_12(yytext); fprintf(p1,"%d 0010%s\n", pc, cstr_12); break; case LABEL: fprintf(p1,"%d U0010000000000000 %s\n", pc, yytext); break; default: fprintf(stderr,"Bad operand after ADDD is %s on line %d\n",yytext, pc); exit(1); } break; case SUBD: switch(tok=yylex()){ case INTEG: str_12(yytext); fprintf(p1,"%d 0011%s\n", pc, cstr_12); break; case LABEL: fprintf(p1,"%d U0011000000000000 %s\n", pc, yytext); break; default: fprintf(stderr,"Bad operand after SUBD is %s on line %d\n",yytext, pc); exit(1); } break; case JPOS: switch(tok=yylex()){ case INTEG: str_12(yytext); fprintf(p1,"%d 0100%s\n", pc, cstr_12); break; case LABEL: fprintf(p1,"%d U0100000000000000 %s\n", pc, yytext); break; default: fprintf(stderr,"Bad operand after JPOS is %s on line %d\n",yytext, pc); exit(1); } break; case JZER: switch(tok=yylex()){ case INTEG: str_12(yytext); fprintf(p1,"%d 0101%s\n", pc, cstr_12); break; case LABEL: fprintf(p1,"%d U0101000000000000 %s\n", pc, yytext); break; default: fprintf(stderr,"Bad operand after JZER is %s on line %d\n",yytext, pc); exit(1); } break; case JUMP: switch(tok=yylex()){ case INTEG: str_12(yytext); fprintf(p1,"%d 0110%s\n", pc, cstr_12); break; case LABEL: fprintf(p1,"%d U0110000000000000 %s\n", pc, yytext); break; default: fprintf(stderr,"Bad operand after JUMP is %s on line %d\n",yytext, pc); exit(1); } break; case LOCO: switch(tok=yylex()){ case INTEG: if(yytext[0] == '-'){ fprintf(stderr,"Negative operand after LOCO is %s on line %d, must be positive !\n",yytext, pc); exit(1); } str_12(yytext); fprintf(p1,"%d 0111%s\n", pc, cstr_12); break; case LABEL: fprintf(p1,"%d U0111000000000000 %s\n", pc, yytext); break; default: fprintf(stderr,"Bad operand after LOCO is %s on line %d\n",yytext, pc); exit(1); } break; case LODL: if((tok=yylex()) != INTEG){ fprintf(stderr,"Bad operand after LODL is %s\n",yytext); exit(1); } str_12(yytext); fprintf(p1,"%d 1000%s\n", pc, cstr_12); break; case STOL: if((tok=yylex()) != INTEG){ fprintf(stderr,"Bad operand after STOL is %s\n",yytext); exit(1); } str_12(yytext); fprintf(p1,"%d 1001%s\n", pc, cstr_12); break; case ADDL: if((tok=yylex()) != INTEG){ fprintf(stderr,"Bad operand after ADDL is %s\n",yytext); exit(1); } str_12(yytext); fprintf(p1,"%d 1010%s\n", pc, cstr_12); break; case SUBL: if((tok=yylex()) != INTEG){ fprintf(stderr,"Bad operand after SUBL is %s\n",yytext); exit(1); } str_12(yytext); fprintf(p1,"%d 1011%s\n", pc, cstr_12); break; case JNEG: switch(tok=yylex()){ case INTEG: str_12(yytext); fprintf(p1,"%d 1100%s\n", pc, cstr_12); break; case LABEL: fprintf(p1,"%d U1100000000000000 %s\n", pc, yytext); break; default: fprintf(stderr,"Bad operand after JNEG is %s on line %d\n",yytext, pc); exit(1); } break; case JNZE: switch(tok=yylex()){ case INTEG: str_12(yytext); fprintf(p1,"%d 1101%s\n", pc, cstr_12); break; case LABEL: fprintf(p1,"%d U11010000000000000 %s\n", pc, yytext); break; default: fprintf(stderr,"Bad operand after JNZE is %s on line %d\n",yytext, pc); exit(1); } break; case CALL: switch(tok=yylex()){ case INTEG: str_12(yytext); fprintf(p1,"%d 1110%s\n", pc, cstr_12); break; case LABEL: fprintf(p1,"%d U1110000000000000 %s\n", pc, yytext); break; default: fprintf(stderr,"Bad operand after CALL is %s on line %d\n",yytext, pc); exit(1); } break; case PSHI: fprintf(p1,"%d 1111000000000000\n",pc); break; case POPI: fprintf(p1,"%d 1111001000000000\n",pc); break; case PUSH: fprintf(p1,"%d 1111010000000000\n",pc); break; case POP: fprintf(p1,"%d 1111011000000000\n",pc); break; case RETN: fprintf(p1,"%d 1111100000000000\n",pc); break; case SWAP: fprintf(p1,"%d 1111101000000000\n",pc); break; case INSP: if((tok=yylex()) != INTEG){ fprintf(stderr,"Bad operand after INSP is %s\n",yytext); exit(1); } str_8(yytext); fprintf(p1,"%d 11111100%s\n", pc, cstr_8); break; case DESP: if((tok=yylex()) != INTEG){ fprintf(stderr,"Bad operand after DESP is %s\n",yytext); exit(1); } str_8(yytext); fprintf(p1,"%d 11111110%s\n", pc, cstr_8); break; case HALT: fprintf(p1,"%d 1111111111000000\n",pc); break; // case for MULT case MULT: if((tok=yylex()) != INTEG){ //trips if issue with mult call fprintf(stderr,"Bad operand after MULT is %s\n",yytext); exit(1); } str_6(yytext); //otherwise the bits are written fprintf(p1,"%d 1111111100%s\n", pc, cstr_6); break; //case for RSHIFT case RSHIFT: if((tok=yylex()) != INTEG){ // trips if issues with rshift call fprintf(stderr,"Bad operand after RSHIFT is %s\n",yytext); exit(1); } str_6(yytext); //else bits are written fprintf(p1,"%d 1111111101%s\n", pc, cstr_6); break; case DIV: fprintf(p1,"%d 1111111110000000\n",pc); // case for DIV break; //no error case for div, takes no input from .asm all from stack case INTEG: str_16(yytext); fprintf(p1,"%d %s\n", pc, cstr_16); break; case LABEL: if (label_pc == pc){/* for < lbx: lby: > */ fprintf(p1,"%d U0000000000000000 %s\n", pc, yytext); break; } search_sym_table(yytext); update_sym_table(yytext); label_pc = pc; pc--; break; case LOC: if((tok=yylex()) != INTEG){ fprintf(stderr,"Bad operand after .LOC is %s\n",yytext); exit(1); } if((temp = ((unsigned short)atoi(yytext) )) < pc){ fprintf(stderr,"Bad operand after .LOC is %s, TOO SMALL !\n",yytext); exit(1); } pc = temp - 1; break; case STR: i=1; do{ if(*(yytext+i) == '\"'){ bstr_16(0); fprintf(p1,"%d %s\n", pc, binstr_16); break; } temp = (unsigned short)*(yytext+i++); if(*(yytext+i) != '\"'){ temp = (temp | ((unsigned short)*(yytext+i) << 8)); } bstr_16(temp); fprintf(p1,"%d %s\n", pc, binstr_16); }while(*(yytext+i++) != '\"' && ++pc); break; case JUNK: fprintf(stderr,"Unrecognized token is %s\n",yytext); exit(26); default: fprintf(stderr,"Default case, unrecoverable error\n"); exit(26); } // end while pc++; } // end switch generate_code(linum); if(dump_tab)dump_table(); return; } // end main
/* Actually load the configuration file. * You will almost certainly want to replace this with something better. */ static int load_config(void) { FILE *fd = NULL; char buffer[256]; char *extname = NULL; char *threadname = NULL; char *directive = NULL; char *check = NULL; int matches = 0; /* Belt and braces - if already loaded, don't re-load */ if( cfg_loaded ) return cfg_loaded; /* Find out where we load from */ char const *filename = get_config_filename(); if ( !filename ) return 0; LOG("Load Config from %s", filename); /* Try and open that file */ fd = fopen(filename, "r"); if( !fd ) { LOG_E("Opening file \"%s\" failed (error %d: %s)", filename, errno, strerror(errno)); return -errno; } /* Loop over the file */ while( !feof(fd) ) { check = fgets(buffer, 255, fd); /* Check nothing went wrong */ if( ferror(fd) || (!check && !feof(fd)) ) LOG_E("Reading file \"%s\" failed: %d %s", filename, errno, strerror(errno)); buffer[255] = '\0'; /* sscanf isn't particularly safe - a real application should use a better parser */ matches = sscanf(buffer, "%ms%ms%ms", &directive, &threadname, &extname); if( matches < 3 ) break; LOG("Read: %s %s %s", directive, threadname, extname); if( !strncasecmp("set", directive, 4) ) directive_set(threadname, atoi(extname)); else if( !strncasecmp("name", directive, 5) ) add_mapping(threadname, extname); else if( !strncasecmp("num", directive, 4) ) add_numeric(atoi(threadname), extname); else LOG_E("Invalid directive: %s", directive); free(directive); free(threadname); free(extname); } LOG("Load Complete"); fclose(fd); /* Debug print the loaded table */ dump_table(); return 1; }
static void flow_list(void) { dump_table(&main_table); return; }
void dump_compat_table(void) { printf("FDT COMPATIBILITY TABLE:\n"); dump_table(compat_list_head); }