static unsigned int readdirectory(struct service_backend *backend, struct service_state *state, void *buffer, unsigned int count, unsigned int offset, unsigned int current, struct cpio_header *header) { struct record record; struct cpio_header *eheader; char *name; if (!current) return 0; eheader = mapheader(backend, state, current); if (!eheader) return 0; name = mapname(backend, state, eheader, current); if (!name) return 0; record.id = current; record.size = cpio_filesize(eheader); record.length = memory_read(record.name, RECORD_NAMESIZE, name, eheader->namesize - 1, header->namesize); return memory_read(buffer, count, &record, sizeof (struct record), offset); }
word memory_r16(memory * mem, word addr) { byte lsb = memory_read(mem, addr); byte msb = memory_read(mem, addr + 1); return ((msb << 8) | lsb); }
static unsigned int protocol_read(struct service_backend *backend, struct service_state *state, unsigned int id, unsigned int current, void *buffer, unsigned int count, unsigned int offset) { struct record record; record.id = current; record.size = 4096; record.length = memory_read(record.name, RECORD_NAMESIZE, "buffer", 6, 0); return memory_read(buffer, count, &record, sizeof (struct record), offset); }
static char * test_memory_read_memory_size_bit_0(void) { printf("test_memory_read_memory_size_bit_0\n"); mu_assert("Memory init failed", memory_init(16384)); word location; location.WORD = 0xFFDA; mu_assert("Memory read at FFDA did not return 1", memory_read(location) == 1); memory_destroy(); mu_assert("Memory init failed", memory_init(16385)); mu_assert("Memory read at FFDA did not return 0", memory_read(location) == 0); memory_destroy(); return 0; }
/**************************************************************************** ** ** ** Name: usim_api_read() ** ** ** ** Description: Reads data from the USIM application ** ** ** ** Inputs: None ** ** Others: File where are stored USIM data ** ** ** ** Outputs: data: Pointer to the USIM application data ** ** Return: RETURNerror, RETURNok ** ** Others: None ** ** ** ***************************************************************************/ int usim_api_read(usim_data_t* data) { LOG_FUNC_IN; /* Get USIM application pathname */ char* path = memory_get_path(USIM_API_NVRAM_DIRNAME, USIM_API_NVRAM_FILENAME); if (path == NULL) { LOG_TRACE(ERROR, "USIM-API - Failed to get USIM pathname"); LOG_FUNC_RETURN (RETURNerror); } /* Read USIM application data */ if (memory_read(path, data, sizeof(usim_data_t)) != RETURNok) { LOG_TRACE(ERROR, "USIM-API - %s file is either not valid " "or not present", path); free(path); LOG_FUNC_RETURN (RETURNerror); } /* initialize the subscriber authentication security key */ _usim_api_hex_string_to_hex_value(_usim_api_k, USIM_API_K_VALUE, USIM_API_K_SIZE); free(path); LOG_FUNC_RETURN (RETURNok); }
int memory_read_gdb(pid_t tid, uint64_t addr, uint8_t *data, size_t size, size_t *read_size) { int ret; ret = memory_read(tid, addr, data, size, read_size, true /*breakpoint check*/); return ret; }
static unsigned int readdirectory(struct service_backend *backend, void *buffer, unsigned int count, unsigned int current, struct cpio_header *header) { struct record *record = buffer; struct cpio_header eheader; unsigned char name[1024]; if (!current) return 0; if (!readheader(backend, &eheader, current)) return 0; if (!readname(backend, &eheader, current, name, 1024)) return 0; record->id = current; record->size = cpio_filesize(&eheader); record->length = memory_read(record->name, RECORD_NAMESIZE, name, eheader.namesize - 1, header->namesize); switch (eheader.mode & 0xF000) { case 0x4000: record->length += memory_write(record->name, RECORD_NAMESIZE, "/", 1, record->length); break; } return sizeof (struct record); }
static char * test_memory_read_reset_vector_correct(void) { word address; address.WORD = CPU_RESET_ADDR; printf("test_memory_read_reset_vector_correct\n"); mu_assert("Could not allocate memory", memory_init(4096)); mu_assert("Incorrect PC high byte start address", memory_read(address) == CPU_PC_START_HI); address.WORD += 1; mu_assert("Incorrect PC low byte start address", memory_read(address) == CPU_PC_START_LO); memory_destroy(); return 0; }
static unsigned int videointerface_rdata(unsigned int offset, void *buffer, unsigned int count) { unsigned int s = videointerface.settings.h * videointerface.settings.w * videointerface.settings.bpp / 8; return memory_read(buffer, count, gaddress, s, offset); }
static unsigned int root_read(struct system_node *self, struct system_node *current, struct service_state *state, void *buffer, unsigned int count, unsigned int offset) { unsigned int x = rand(&normal); return memory_read(buffer, count, &x, 4, offset); }
void memory_dump_state(memory_t* memory) { printf("Non-zero memory:\n"); for (uint32_t i = 0; i <= (memory->size - 4); i += 4) { uint32_t value = memory_read(memory, i); if (value) { printf("0x%08x: 0x%08x\n", i, endian_swap(value)); } } }
static unsigned int consoleinterface_readctrl(struct system_node *self, struct system_node *current, struct service_state *state, void *buffer, unsigned int count, unsigned int offset) { struct ctrl_consolesettings settings; settings.scroll = 1; return memory_read(buffer, count, &settings, sizeof (struct ctrl_consolesettings), offset); }
void external_dataset_sort(external_dataset_t* data) { struct runtime rt; void* results = NULL; size_t i; stream_t* tmp; stream_t* stream = data->stream; stream_seek(stream, 0); tmp = stream_create(stream->config, "tmp.stream"); stream_open(tmp, O_CREAT | O_TRUNC | O_RDWR | O_SYNC); /* sort each individual chunk of memory size */ for(i = 0; i < data->n_records / MEMORY_RECORDS(stream); i++) { memory_read(stream, RECORDS(data->mem), MEMORY_RECORDS(stream)); N_RECORDS(data->mem) = MEMORY_RECORDS(stream); results = NULL; start_timing(&rt); fp_im_sort(data->context, RECORDS(data->mem), N_RECORDS(data->mem), &results); stop_timing(&rt); printf("Sort time: %f\n", get_runtime(rt)); memory_write(tmp, RECORDS(data->mem), N_RECORDS(data->mem)); dataset_print(data->mem, TRUE); } if(data->n_records % MEMORY_RECORDS(stream)) { memory_read(stream, RECORDS(data->mem), data->n_records % MEMORY_RECORDS(stream)); N_RECORDS(data->mem) = data->n_records % MEMORY_RECORDS(stream); start_timing(&rt); results = NULL; fp_im_sort(data->context, RECORDS(data->mem), N_RECORDS(data->mem), &results); stop_timing(&rt); memory_write(tmp, RECORDS(data->mem), N_RECORDS(data->mem)); dataset_print(data->mem, TRUE); } /* merge memory chunks block by block */ }
int mmu_fetch(mmu *unit, uint8_t vpage) { struct tlb_entry read_entry; int i; for(i=0; i<4; i++) { if(unit->tlb[i].flags & MMU_ACTIVE && unit->tlb[i].vaddr == vpage) { return 1; } } for(i=0; i<32; i++) { memory_read(unit->mem, unit->baseaddr + 4 * i , 4, (uint8_t *)&read_entry); if(read_entry.vaddr == vpage && read_entry.flags & MMU_ACTIVE) { unit->tlb[(int)unit->lru] = read_entry; unit->lru++; unit->lru &= 0x3; return 1; } } return 0; }
static unsigned int videointerface_readdata(struct system_node *self, struct system_node *current, struct service_state *state, void *buffer, unsigned int count, unsigned int offset) { return memory_read(buffer, count, gaddress, videointerface.settings.w * videointerface.settings.h * videointerface.settings.bpp, offset); }
static unsigned int videointerface_readctrl(struct system_node *self, struct system_node *current, struct service_state *state, void *buffer, unsigned int count, unsigned int offset) { return memory_read(buffer, count, &videointerface.settings, sizeof (struct ctrl_videosettings), offset); }
/* access memory (read/write) according to the read_write bit setting */ void access_memory() { if(read_write==READ) memory_read(); else memory_write(); }
uint8 memory_readop(uint16 addr) { return memory_read(addr); }
static unsigned int read(struct service_state *state, void *buffer, unsigned int count, unsigned int offset) { return memory_read(buffer, count, (void *)address, limit, offset); }
uint8 memory_readop(void *userdata, uint16 addr) { return memory_read(userdata, addr); }
byte memory_r8(memory * mem, word addr) { return memory_read(mem, addr); }
int main(int argc, char const *argv[]) { unsigned flit; unsigned flit_type; unsigned payload; unsigned packet_counter = 1; /* Test UART */ setup_uart(CPU_SPEED, UART_BAUDRATE); uart_puts("UART TEST: If you can read this, then UART output works!\n"); #if (UART_IN_TEST == 1) uart_puts("Please press letter 'b' on the UART terminal:\n"); char uart_in = uart_getch(); if (uart_in == 'b') { uart_puts("UART INPUT TEST PASSED!\n\n"); } else { uart_puts("UART INPUT TEST FAILED!\n"); uart_puts("Received following letter: {ASCII:HEX}\n"); uart_putchar(uart_in); uart_putchar(':'); uart_print_hex(uart_in); uart_puts("\n\n"); } #endif #if (GPIO_TEST == 1) /* Test GPIO */ unsigned gpio_in = memory_read(GPIOA_IN); memory_write(GPIO0_SET, gpio_in); #endif uart_puts("\n\nBeginning communication test\n\n"); ni_write(build_header(DST_ADDR, 3)); ni_write(0b1111111111111111111111111111); ni_write(0); while (packet_counter <= SEND_PACKET_COUNT) { if ((ni_read_flags() & NI_READ_MASK) == 0) { flit = ni_read(); flit_type = get_flit_type(flit); if (flit_type == FLIT_TYPE_HEADER) { uart_puts("Sending packet number "); uart_print_num(packet_counter, 10, 0); uart_putchar('\n'); ni_write(build_header(DST_ADDR, 3)); packet_counter++; } else { payload = get_flit_payload(flit); ni_write(payload); } } } /* Run CPU test */ test_plasma_funcitons(); return 0; }
int main(int argc, char *argv[]) { FILE *out; FILE *dbg = NULL; //FILE *list = NULL; int i; int format = FORMAT_HEX; int create_list = 0; char *infile = NULL, *outfile = NULL; struct _asm_context asm_context; int error_flag=0; puts(credits); if (argc < 2) { printf("Usage: naken_asm [options] <infile>\n" " -o <outfile>\n" " -h [output hex file]\n" #ifndef DISABLE_ELF " -e [output elf file]\n" #endif " -b [output binary file]\n" " -s [output srec file]\n" " -l [create .lst listing file]\n" " -I [add to include path]\n" " -q Quiet (only output errors)\n" "\n"); exit(0); } memset(&asm_context, 0, sizeof(asm_context)); for (i = 1; i < argc; i++) { if (strcmp(argv[i], "-o") == 0) { outfile = argv[++i]; } else if (strcmp(argv[i], "-h") == 0) { format = FORMAT_HEX; } else if (strcmp(argv[i], "-b") == 0) { format = FORMAT_BIN; } else if (strcmp(argv[i], "-s") == 0) { format = FORMAT_SREC; } #ifndef DISABLE_ELF else if (strcmp(argv[i], "-e") == 0) { format = FORMAT_ELF; } #endif #if 0 else if (strcmp(argv[i], "-d") == 0) { asm_context.debug_file = 1; } #endif else if (strcmp(argv[i], "-l") == 0) { create_list = 1; } else if (strncmp(argv[i], "-I", 2) == 0) { char *s = argv[i]; if (s[2] == 0) { if (add_to_include_path(&asm_context, argv[++i]) != 0) { printf("Internal Error: Too many include paths\n"); exit(1); } } else { if (add_to_include_path(&asm_context, s+2) != 0) { printf("Internal Error: Too many include paths\n"); exit(1); } } } else if (strcmp(argv[i], "-q") == 0) { asm_context.quiet_output = 1; } else { if (infile != NULL) { printf("Error: Cannot use %s as input file since %s was already chosen.\n", argv[1], infile); exit(1); } infile = argv[i]; } } if (infile == NULL) { printf("No input file specified.\n"); exit(1); } if (outfile == NULL) { switch(format) { case FORMAT_HEX: outfile = "out.hex"; break; case FORMAT_BIN: outfile = "out.bin"; break; case FORMAT_ELF: outfile = "out.elf"; break; case FORMAT_SREC: outfile = "out.srec"; break; default: outfile = "out.err"; break; } } #ifdef INCLUDE_PATH if (add_to_include_path(&asm_context, INCLUDE_PATH) != 0) { printf("Internal Error: Too many include paths\n"); exit(1); } #endif if (tokens_open_file(&asm_context, infile) != 0) { printf("Couldn't open %s for reading.\n", infile); exit(1); } out = fopen(outfile, "wb"); if (out == NULL) { printf("Couldn't open %s for writing.\n", outfile); exit(1); } if (asm_context.quiet_output == 0) { printf(" Input file: %s\n", infile); printf("Output file: %s\n", outfile); } #if 0 if (asm_context.debug_file == 1) { char filename[1024]; strcpy(filename, outfile); new_extension(filename, "ndbg", 1024); dbg = fopen(filename,"wb"); if (dbg == NULL) { printf("Couldn't open %s for writing.\n",filename); exit(1); } printf(" Debug file: %s\n",filename); fprintf(dbg, "%s\n", infile); } #endif if (create_list == 1) { char filename[1024]; strcpy(filename, outfile); new_extension(filename, "lst", 1024); asm_context.list = fopen(filename, "wb"); if (asm_context.list == NULL) { printf("Couldn't open %s for writing.\n", filename); exit(1); } if (asm_context.quiet_output == 0) { printf(" List file: %s\n", filename); } } if (asm_context.quiet_output == 0) { printf("\nPass 1...\n"); } symbols_init(&asm_context.symbols); macros_init(&asm_context.macros); asm_context.pass = 1; assemble_init(&asm_context); error_flag = assemble(&asm_context); if (error_flag != 0) { printf("** Errors... bailing out\n"); unlink(outfile); } else { symbols_lock(&asm_context.symbols); // macros_lock(&asm_context.defines_heap); if (asm_context.quiet_output == 0) { printf("Pass 2...\n"); } asm_context.pass = 2; assemble_init(&asm_context); error_flag = assemble(&asm_context); if (format == FORMAT_HEX) { write_hex(&asm_context.memory, out); } else if (format == FORMAT_BIN) { write_bin(&asm_context.memory, out); } else if (format == FORMAT_SREC) { write_srec(&asm_context.memory, out); } #ifndef DISABLE_ELF else if (format == FORMAT_ELF) { write_elf(&asm_context.memory, out, &asm_context.symbols, asm_context.filename, asm_context.cpu_type); } #endif if (dbg != NULL) { for (i = 0; i < asm_context.memory.size; i++) { int debug_line = memory_debug_line(&asm_context, i); putc(debug_line >> 8, dbg); putc(debug_line & 0xff, dbg); } fclose(dbg); } } fclose(out); if (create_list == 1) { int ch = 0; char str[17]; int ptr = 0; fprintf(asm_context.list, "data sections:"); for (i = asm_context.memory.low_address; i <= asm_context.memory.high_address; i++) { if (memory_debug_line(&asm_context, i) == -2) { if (ch == 0) { if (ptr != 0) { output_hex_text(asm_context.list, str, ptr); } fprintf(asm_context.list, "\n%04x:", i/asm_context.bytes_per_address); ptr = 0; } unsigned char data = memory_read(&asm_context, i); fprintf(asm_context.list, " %02x", data); if (data >= ' ' && data <= 120) { str[ptr++] = data; } else { str[ptr++] = '.'; } ch++; if (ch == 16) { ch = 0; } } else { output_hex_text(asm_context.list, str, ptr); ch = 0; ptr = 0; } } output_hex_text(asm_context.list, str, ptr); fprintf(asm_context.list, "\n\n"); assemble_print_info(&asm_context, asm_context.list); } assemble_print_info(&asm_context, stdout); //symbols_free(&asm_context.symbols); //macros_free(&asm_context.macros); if (asm_context.list != NULL) { fclose(asm_context.list); } fclose(asm_context.in); if (error_flag != 0) { printf("*** Failed ***\n\n"); unlink(outfile); } //memory_free(&asm_context.memory); assemble_free(&asm_context); if (error_flag != 0) { return -1; } return 0; }
int main(int argc, char** argv) { FILE* f; metadata_t* meta; fp_context_t* context; struct sort_config sc; dataset_t* ds; char target[256]; stream_t* stream; config_t conf; external_dataset_t* ext; int i; if(argc < 2) { printf("Barf!\n"); exit(-1); } if((f = fopen(argv[1], "r")) == NULL) { printf("Cannot open dataset file %s.\n", argv[1]); return -1; } meta = metadata_read(f); sc.verbose = 1; sc.normalize = 0; sc.denormalize = 0; sc.benchmark = 1; sc.find_order = ITERATIVE; sc.index = KEEP; sc.cmp = HILBERT; sc.print = stdout; context = fp_create_context(&sc, meta->dimz, meta->dimf, meta->start_order); ds = dataset_read(f, meta, context); fclose(f); dataset_print(ds, FALSE); strcpy(target, argv[1]); strcat(target, ".stream"); printf("Number of records: %d\n", ds->n_records); printf("Record size: %d\n", context->record_size); conf.memory_size = 1000; conf.block_size = 0x100; conf.record_size = context->record_size; stream = stream_create(&conf, target); stream_open(stream, O_CREAT | O_TRUNC | O_SYNC | O_WRONLY); dataset_convert(ds, stream); stream_close(stream); stream_open(stream, O_SYNC | O_RDONLY); ext = external_dataset_create(stream, meta, ds->n_records); for(i = 0; i < ds->n_records / MEMORY_RECORDS(stream); i++) { memory_read(stream, ext->mem->records, MEMORY_RECORDS(stream)); ext->mem->n_records = MEMORY_RECORDS(stream); dataset_print(ext->mem, FALSE); } if(ds->n_records % MEMORY_RECORDS(stream)) { memory_read(stream, ext->mem->records, ds->n_records % MEMORY_RECORDS(stream)); ext->mem->n_records = ds->n_records % MEMORY_RECORDS(stream); dataset_print(ext->mem, FALSE); } printf("Stream position: %ld vs. %ld\n", stream->pos, stream_tell(stream)); external_dataset_sort(ext); external_dataset_destroy(ext); stream_destroy(stream); stats_print(); dataset_destroy(ds); fp_destroy_context(context); metadata_destroy(meta); return 0; }