static struct remoteproc * platform_create_proc(int proc_index, int rsc_index) { void *rsc_table; int rsc_size; int ret; metal_phys_addr_t pa; (void) proc_index; rsc_table = get_resource_table(rsc_index, &rsc_size); /* Register IPI device */ (void)metal_register_generic_device(&scugic_device); /* Initialize remoteproc instance */ if (!remoteproc_init(&rproc_inst, &zynq_a9_proc_ops, &rproc_priv)) return NULL; /* * Mmap shared memories * Or shall we constraint that they will be set as carved out * in the resource table? */ /* mmap resource table */ pa = (metal_phys_addr_t)rsc_table; (void *)remoteproc_mmap(&rproc_inst, &pa, NULL, rsc_size, NORM_NONCACHE | STRONG_ORDERED, &rproc_inst.rsc_io); /* mmap shared memory */ pa = SHARED_MEM_PA; (void *)remoteproc_mmap(&rproc_inst, &pa, NULL, SHARED_MEM_SIZE, NORM_NONCACHE | STRONG_ORDERED, NULL); /* parse resource table to remoteproc */ ret = remoteproc_set_rsc_table(&rproc_inst, rsc_table, rsc_size); if (ret) { xil_printf("Failed to intialize remoteproc\r\n"); remoteproc_remove(&rproc_inst); return NULL; } xil_printf("Initialize remoteproc successfully.\r\n"); return &rproc_inst; }
int main(int argc, char **argv) { unsigned char* lpdata = NULL; int fd; parse_options( argc, argv); if( (fd = open( g_lpstrInputFile, O_RDONLY | O_BINARY)) ) { int i; struct stat file_stat; fstat( fd, &file_stat); i = get_resource_table( fd, &lpdata, file_stat.st_size ); switch(i) { case FILE_DLL: if( lpdata ) { int j, count = 0; NE_TYPEINFO* pTInfo = (NE_TYPEINFO*)(lpdata + 2); NE_NAMEINFO* pFontStorage = NULL; while( (i = return_data_value(dfShort, &pTInfo->type_id)) ) { j = return_data_value(dfShort, &pTInfo->count); if( i == NE_RSCTYPE_FONT ) { count = j; pFontStorage = (NE_NAMEINFO*)(pTInfo + 1); break; /* found one */ } pTInfo = (NE_TYPEINFO *)((char*)(pTInfo+1) + j*sizeof(NE_NAMEINFO)); } if( pFontStorage && count ) { unsigned short size_shift = return_data_value(dfShort, lpdata); unsigned char* lpfont = NULL; unsigned offset; int length; for( j = 0; j < count; j++, pFontStorage++ ) { length = return_data_value(dfShort, &pFontStorage->length) << size_shift; offset = return_data_value(dfShort, &pFontStorage->offset) << size_shift; if( !(lpfont = (unsigned char*) realloc( lpfont, length )) ) { fprintf(stderr, "Memory allocation error.\n" ); exit(1); } lseek( fd, offset, SEEK_SET ); if( read(fd, lpfont, length) != length ) { fprintf(stderr, "Unable to read Windows DLL.\n" ); exit(1); } if( (i = parse_fnt_data( lpfont, length )) ) { fprintf(stderr, "Unable to parse font data: Error %d\n", i ); exit(1); } } free(lpfont); free(lpdata); exit(0); } else { fprintf(stderr, "No fonts found.\n" ); exit(1); } free( lpdata ); } else { fprintf(stderr, "Unable to read Windows DLL.\n" ); exit(1); } break; case FILE_FNT: if( lpdata ) { if( (i = parse_fnt_data( lpdata, file_stat.st_size )) ) { fprintf(stderr, "Unable to parse font data: Error %d\n", i ); exit(1); } free( lpdata ); } else { fprintf(stderr, "Unable to read .FNT file.\n" ); exit(1); } break; case FILE_ERROR: fprintf(stderr, "Corrupt or invalid file.\n" ); exit(1); } close(fd); exit(0); } else { fprintf(stderr, "Unable to open '%s'.\n", g_lpstrInputFile ); exit(1); } }
bool CONFIG::parse_config_file(const char *cf, void *caller_ctx, LEX_ERROR_HANDLER *scan_error, LEX_WARNING_HANDLER *scan_warning, int32_t err_type) { bool result = true; LEX *lc = NULL; int token, i, pass; int res_type = 0; enum parse_state state = p_none; RES_TABLE *res_table = NULL; RES_ITEM *items = NULL; RES_ITEM *item = NULL; int level = 0; /* * Make two passes. The first builds the name symbol table, * and the second picks up the items. */ Dmsg0(900, "Enter parse_config()\n"); for (pass = 1; pass <= 2; pass++) { Dmsg1(900, "parse_config pass %d\n", pass); if ((lc = lex_open_file(lc, cf, scan_error, scan_warning)) == NULL) { berrno be; /* * We must create a lex packet to print the error */ lc = (LEX *)malloc(sizeof(LEX)); memset(lc, 0, sizeof(LEX)); if (scan_error) { lc->scan_error = scan_error; } else { lex_set_default_error_handler(lc); } if (scan_warning) { lc->scan_warning = scan_warning; } else { lex_set_default_warning_handler(lc); } lex_set_error_handler_error_type(lc, err_type) ; scan_err2(lc, _("Cannot open config file \"%s\": %s\n"), cf, be.bstrerror()); free(lc); return 0; } lex_set_error_handler_error_type(lc, err_type); lc->error_counter = 0; lc->caller_ctx = caller_ctx; while ((token=lex_get_token(lc, T_ALL)) != T_EOF) { Dmsg3(900, "parse state=%d pass=%d got token=%s\n", state, pass, lex_tok_to_str(token)); switch (state) { case p_none: if (token == T_EOL) { break; } else if (token == T_UTF8_BOM) { /* * We can assume the file is UTF-8 as we have seen a UTF-8 BOM */ break; } else if (token == T_UTF16_BOM) { scan_err0(lc, _("Currently we cannot handle UTF-16 source files. " "Please convert the conf file to UTF-8\n")); goto bail_out; } else if (token != T_IDENTIFIER) { scan_err1(lc, _("Expected a Resource name identifier, got: %s"), lc->str); goto bail_out; } res_table = get_resource_table(lc->str); if(res_table && res_table->items) { items = res_table->items; state = p_resource; res_type = res_table->rcode; init_resource(res_type, items, pass); } if (state == p_none) { scan_err1(lc, _("expected resource name, got: %s"), lc->str); goto bail_out; } break; case p_resource: switch (token) { case T_BOB: level++; break; case T_IDENTIFIER: if (level != 1) { scan_err1(lc, _("not in resource definition: %s"), lc->str); goto bail_out; } i = get_resource_item_index(items, lc->str); if (i>=0) { item = &items[i]; /* * If the CFG_ITEM_NO_EQUALS flag is set we do NOT * scan for = after the keyword */ if (!(item->flags & CFG_ITEM_NO_EQUALS)) { token = lex_get_token(lc, T_SKIP_EOL); Dmsg1 (900, "in T_IDENT got token=%s\n", lex_tok_to_str(token)); if (token != T_EQUALS) { scan_err1(lc, _("expected an equals, got: %s"), lc->str); goto bail_out; } } /* * See if we are processing a deprecated keyword if so warn the user about it. */ if (item->flags & CFG_ITEM_DEPRECATED) { scan_warn2(lc, _("using deprecated keyword %s on line %d"), item->name, lc->line_no); /* * As we only want to warn we continue parsing the config. So no goto bail_out here. */ } Dmsg1(800, "calling handler for %s\n", item->name); /* * Call item handler */ if (!store_resource(item->type, lc, item, i, pass)) { /* * None of the generic types fired if there is a registered callback call that now. */ if (m_store_res) { m_store_res(lc, item, i, pass); } } } else { Dmsg2(900, "level=%d id=%s\n", level, lc->str); Dmsg1(900, "Keyword = %s\n", lc->str); scan_err1(lc, _("Keyword \"%s\" not permitted in this resource.\n" "Perhaps you left the trailing brace off of the previous resource."), lc->str); goto bail_out; } break; case T_EOB: level--; state = p_none; Dmsg0(900, "T_EOB => define new resource\n"); if (((URES *)m_res_all)->hdr.name == NULL) { scan_err0(lc, _("Name not specified for resource")); goto bail_out; } /* save resource */ if (!save_resource(res_type, items, pass)) { scan_err0(lc, _("save_resource failed")); goto bail_out; }; break; case T_EOL: break; default: scan_err2(lc, _("unexpected token %d %s in resource definition"), token, lex_tok_to_str(token)); goto bail_out; } break; default: scan_err1(lc, _("Unknown parser state %d\n"), state); goto bail_out; } } if (state != p_none) { scan_err0(lc, _("End of conf file reached with unclosed resource.")); goto bail_out; } if (debug_level >= 900 && pass == 2) { int i; for (i = m_r_first; i <= m_r_last; i++) { dump_resource(i, m_res_head[i-m_r_first], prtmsg, NULL, false); } } if (lc->error_counter > 0) { result = false; } lc = lex_close_file(lc); } Dmsg0(900, "Leave parse_config_file()\n"); return result; bail_out: if (lc) { lc = lex_close_file(lc); } return false; }