static int io_handler(GIOChannel *chan, GIOCondition condition, gpointer data) { (void) condition; net_buf *b = (net_buf*)data; if(!b->size) { uint32_t size; if(read_io(chan, (char*)&size, 4)!=4) return 1; size=htonl(size); if(size==0) return 1; b->msg = malloc(size); if(!b->msg) return 1; b->size = size; b->got = 0; } b->got += read_io(chan, b->msg+b->got, b->size-b->got); if(b->got == b->size) { quassel_parse_message(chan, b->msg, NULL); //display_qvariant(b->msg); free(b->msg); b->got = 0; b->size = 0; } return 1; }
/* Load the first part the file and check if it's Linux */ static uint32_t load_linux_header(struct linux_header *hdr) { int load_high; uint32_t kern_addr; if (read_io(fd, hdr, sizeof *hdr) != sizeof *hdr) { debug("Can't read Linux header\n"); return 0; } if (hdr->boot_sector_magic != 0xaa55) { debug("Not a Linux kernel image\n"); return 0; } /* Linux is found. Print some information */ if (memcmp(hdr->header_magic, "HdrS", 4) != 0) { /* This may be floppy disk image or something. * Perform a simple (incomplete) sanity check. */ if (hdr->setup_sects >= 16 || file_size() - (hdr->setup_sects<<9) >= 512<<10) { debug("This looks like a bootdisk image but not like Linux...\n"); return 0; } printf("Possible very old Linux"); /* This kernel does not even have a protocol version. * Force the value. */ hdr->protocol_version = 0; /* pre-2.00 */ } else printf("Found Linux"); if (hdr->protocol_version >= 0x200 && hdr->kver_addr) { char kver[256]; seek_io(fd, hdr->kver_addr + 0x200); if (read_io(fd, kver, sizeof kver) != 0) { kver[255] = 0; printf(" version %s", kver); } } debug(" (protocol %#x)", hdr->protocol_version); load_high = 0; if (hdr->protocol_version >= 0x200) { debug(" (loadflags %#x)", hdr->loadflags); load_high = hdr->loadflags & 1; } if (load_high) { printf(" bzImage"); kern_addr = 0x100000; } else { printf(" zImage or Image"); kern_addr = 0x1000; } printf(".\n"); return kern_addr; }
void update_p1(void) { Byte p1 = read_io(HWREG_P1) | 0x0F; // set all buttons as unpressed // a 0 bit represents a button being pressed. // the following code unsets appropriate bits. if ((p1 & 0x10) == 0) { // p14 (direction buttons) if (is_pressed[BUTTON_RIGHT]) p1 &= ~0x01; if (is_pressed[BUTTON_LEFT]) p1 &= ~0x02; if (is_pressed[BUTTON_UP]) p1 &= ~0x04; if (is_pressed[BUTTON_DOWN]) p1 &= ~0x08; } if ((p1 & 0x20) == 0) { // p15 (other buttons) if (is_pressed[BUTTON_A]) p1 &= ~0x01; if (is_pressed[BUTTON_B]) p1 &= ~0x02; if (is_pressed[BUTTON_SELECT]) p1 &= ~0x04; if (is_pressed[BUTTON_START]) p1 &= ~0x08; } write_io(HWREG_P1, p1); }
int devread( unsigned long sector, unsigned long byte_offset, unsigned long byte_len, void *buf ) { llong offs = (llong)sector * 512 + byte_offset; #ifdef CONFIG_DEBUG_FS //printk("devread s=%x buf=%x, fd=%x\n",sector, buf, curfs->dev_fd); #endif if( !curfs ) { #ifdef CONFIG_DEBUG_FS printk("devread: fsys == NULL!\n"); #endif return -1; } if( seek_io(curfs->dev_fd, offs) ) { #ifdef CONFIG_DEBUG_FS printk("seek failure\n"); #endif return -1; } return (read_io(curfs->dev_fd, buf, byte_len) == byte_len) ? 1:0; }
static int load_elf_rom( unsigned long *entry, int fd ) { int i, lszz_offs, elf_offs; char buf[128], *addr; Elf_ehdr ehdr; Elf_phdr *phdr; size_t s; printk("Loading '%s'\n", get_file_path(fd)); /* the ELF-image (usually) starts at offset 0x4000 */ if( (elf_offs=find_elf(fd)) < 0 ) { printk("----> %s is not an ELF image\n", buf ); exit(1); } if( !(phdr=elf_readhdrs(fd, elf_offs, &ehdr)) ) fatal_error("elf_readhdrs failed\n"); *entry = ehdr.e_entry; /* load segments. Compressed ROM-image assumed to be located immediately * after the last segment */ lszz_offs = elf_offs; for( i=0; i<ehdr.e_phnum; i++ ) { /* p_memsz, p_flags */ s = MIN( phdr[i].p_filesz, phdr[i].p_memsz ); seek_io( fd, elf_offs + phdr[i].p_offset ); /* printk("filesz: %08lX memsz: %08lX p_offset: %08lX p_vaddr %08lX\n", phdr[i].p_filesz, phdr[i].p_memsz, phdr[i].p_offset, phdr[i].p_vaddr ); */ if( phdr[i].p_vaddr != phdr[i].p_paddr ) printk("WARNING: ELF segment virtual addr != physical addr\n"); lszz_offs = MAX( lszz_offs, elf_offs + phdr[i].p_offset + phdr[i].p_filesz ); if( !s ) continue; if( ofmem_claim( phdr[i].p_vaddr, phdr[i].p_memsz, 0 ) == -1 ) fatal_error("Claim failed!\n"); addr = (char*)phdr[i].p_vaddr; if( read_io(fd, addr, s) != s ) fatal_error("read failed\n"); #if 0 /* patch CODE segment */ if( *entry >= phdr[i].p_vaddr && *entry < phdr[i].p_vaddr + s ) { patch_newworld_rom( (char*)phdr[i].p_vaddr, s ); newworld_timer_hack( (char*)phdr[i].p_vaddr, s ); } #endif flush_icache_range( addr, addr+s ); /*printk("ELF ROM-section loaded at %08lX (size %08lX)\n", (unsigned long)phdr[i].p_vaddr, (unsigned long)phdr[i].p_memsz );*/ } free( phdr ); return lszz_offs; }
/* Load 32-bit part of kernel */ static int load_linux_kernel(struct linux_header *hdr, uint32_t kern_addr) { uint32_t kern_offset, kern_size; if (hdr->setup_sects == 0) hdr->setup_sects = 4; kern_offset = (hdr->setup_sects + 1) * 512; seek_io(fd, kern_offset); kern_size = file_size() - kern_offset; debug("offset=%#x addr=%#x size=%#x\n", kern_offset, kern_addr, kern_size); #if 0 if (using_devsize) { printf("Attempt to load up to end of device as kernel; " "specify the image size\n"); return 0; } #endif printf("Loading kernel... "); if (read_io(fd, phys_to_virt(kern_addr), kern_size) != kern_size) { printf("Can't read kernel\n"); return 0; } printf("ok\n"); return kern_size; }
int lfile_read(void *buf, unsigned long len) { int ret = 0; if (load_fd >= 0) ret=read_io(load_fd, buf, len); return ret; }
ulong os_read( int fd, void *buf, ulong len, int blksize_bits ) { /* printk("os_read %d\n", (int)len); */ int cnt = read_io( fd, buf, len << blksize_bits ); return (cnt > 0)? (cnt >> blksize_bits) : cnt; }
static unsigned long process_image_notes(Elf_phdr *phdr, int phnum, unsigned short *sum_ptr, unsigned int offset) { int i; char *buf = NULL; int retval = 0; unsigned long addr, end; Elf_Nhdr *nhdr; const char *name; void *desc; for (i = 0; i < phnum; i++) { if (phdr[i].p_type != PT_NOTE) continue; buf = malloc(phdr[i].p_filesz); seek_io(fd, offset + phdr[i].p_offset); if ((size_t)read_io(fd, buf, phdr[i].p_filesz) != phdr[i].p_filesz) { printf("Can't read note segment\n"); goto out; } addr = (unsigned long) buf; end = addr + phdr[i].p_filesz; while (addr < end) { nhdr = (Elf_Nhdr *) addr; addr += sizeof(Elf_Nhdr); name = (const char *) addr; addr += (nhdr->n_namesz+3) & ~3; desc = (void *) addr; addr += (nhdr->n_descsz+3) & ~3; if (nhdr->n_namesz==sizeof(ELF_NOTE_BOOT) && memcmp(name, ELF_NOTE_BOOT, sizeof(ELF_NOTE_BOOT))==0) { if (nhdr->n_type == EIN_PROGRAM_NAME) { image_name = ob_calloc(1, nhdr->n_descsz + 1); memcpy(image_name, desc, nhdr->n_descsz); } if (nhdr->n_type == EIN_PROGRAM_VERSION) { image_version = ob_calloc(1, nhdr->n_descsz + 1); memcpy(image_version, desc, nhdr->n_descsz); } if (nhdr->n_type == EIN_PROGRAM_CHECKSUM) { *sum_ptr = *(unsigned short *) desc; debug("Image checksum: %#04x\n", *sum_ptr); /* Where in the file */ retval = phdr[i].p_offset + (unsigned long) desc - (unsigned long) buf; } } } } out: close_io(fd); if (buf) free(buf); return retval; }
int bootcode_load(ihandle_t dev) { int retval = -1, count = 0, fd; unsigned long bootcode, loadbase, offset; /* Mark the saved-program-state as invalid */ feval("0 state-valid !"); fd = open_ih(dev); if (fd == -1) { goto out; } /* Default to loading at load-base */ fword("load-base"); loadbase = POP(); #ifdef CONFIG_PPC /* However Old World Macs need to load to a different address */ if (is_oldworld()) { loadbase = OLDWORLD_BOOTCODE_BASEADDR; } #endif bootcode = loadbase; offset = 0; while(1) { if (seek_io(fd, offset) == -1) break; count = read_io(fd, (void *)bootcode, 512); offset += count; bootcode += count; } /* If we didn't read anything then exit */ if (!count) { goto out; } /* Initialise saved-program-state */ PUSH(loadbase); feval("saved-program-state >sps.entry !"); PUSH(offset); feval("saved-program-state >sps.file-size !"); feval("bootcode saved-program-state >sps.file-type !"); feval("-1 state-valid !"); out: close_io(fd); return retval; }
void ext2_read_block(ext2_VOLUME* volume, unsigned int fsblock) { long long offset; if (fsblock == volume->current) return; volume->current = fsblock; offset = fsblock * EXT2_BLOCK_SIZE(volume->super); seek_io(volume->fd, offset); read_io(volume->fd, volume->buffer, EXT2_BLOCK_SIZE(volume->super)); }
void ext2_get_super(int fd, struct ext2_super_block *super) { seek_io(fd, 2 * 512); read_io(fd, super, sizeof (*super)); super->s_inodes_count = __le32_to_cpu(super->s_inodes_count); super->s_blocks_count = __le32_to_cpu(super->s_blocks_count); super->s_r_blocks_count = __le32_to_cpu(super->s_r_blocks_count); super->s_free_blocks_count = __le32_to_cpu(super->s_free_blocks_count); super->s_free_inodes_count = __le32_to_cpu(super->s_free_inodes_count); super->s_first_data_block = __le32_to_cpu(super->s_first_data_block); super->s_log_block_size = __le32_to_cpu(super->s_log_block_size); super->s_log_frag_size = __le32_to_cpu(super->s_log_frag_size); super->s_blocks_per_group = __le32_to_cpu(super->s_blocks_per_group); super->s_frags_per_group = __le32_to_cpu(super->s_frags_per_group); super->s_inodes_per_group = __le32_to_cpu(super->s_inodes_per_group); super->s_mtime = __le32_to_cpu(super->s_mtime); super->s_wtime = __le32_to_cpu(super->s_wtime); super->s_mnt_count = __le16_to_cpu(super->s_mnt_count); super->s_max_mnt_count = __le16_to_cpu(super->s_max_mnt_count); super->s_magic = __le16_to_cpu(super->s_magic); super->s_state = __le16_to_cpu(super->s_state); super->s_errors = __le16_to_cpu(super->s_errors); super->s_minor_rev_level = __le16_to_cpu(super->s_minor_rev_level); super->s_lastcheck = __le32_to_cpu(super->s_lastcheck); super->s_checkinterval = __le32_to_cpu(super->s_checkinterval); super->s_creator_os = __le32_to_cpu(super->s_creator_os); super->s_rev_level = __le32_to_cpu(super->s_rev_level); super->s_def_resuid = __le16_to_cpu(super->s_def_resuid); super->s_def_resgid = __le16_to_cpu(super->s_def_resgid); super->s_first_ino = __le32_to_cpu(super->s_first_ino); super->s_inode_size = __le16_to_cpu(super->s_inode_size); super->s_block_group_nr = __le16_to_cpu(super->s_block_group_nr); super->s_feature_compat = __le32_to_cpu(super->s_feature_compat); super->s_feature_incompat = __le32_to_cpu(super->s_feature_incompat); super->s_feature_ro_compat = __le32_to_cpu(super->s_feature_ro_compat); super->s_algorithm_usage_bitmap = __le32_to_cpu(super->s_algorithm_usage_bitmap); super->s_journal_inum = __le32_to_cpu(super->s_journal_inum); super->s_journal_dev = __le32_to_cpu(super->s_journal_dev); super->s_last_orphan = __le32_to_cpu(super->s_last_orphan); super->s_hash_seed[0] = __le32_to_cpu(super->s_hash_seed[0]); super->s_hash_seed[1] = __le32_to_cpu(super->s_hash_seed[1]); super->s_hash_seed[2] = __le32_to_cpu(super->s_hash_seed[2]); super->s_hash_seed[3] = __le32_to_cpu(super->s_hash_seed[3]); super->s_default_mount_opts = __le32_to_cpu(super->s_default_mount_opts); super->s_first_meta_bg = __le32_to_cpu(super->s_first_meta_bg); }
Elf_phdr * elf_readhdrs(int offset, Elf_ehdr *ehdr) { unsigned long phdr_size; Elf_phdr *phdr; phdr_size = ehdr->e_phnum * sizeof(Elf_phdr); phdr = malloc(phdr_size); seek_io(fd, offset + ehdr->e_phoff); if ((size_t)read_io(fd, phdr, phdr_size) != phdr_size) { printf("Can't read program header\n"); return NULL; } return phdr; }
int ext2_probe(int fd, long long offset) { struct ext2_super_block *super; super = (struct ext2_super_block*)malloc(sizeof(struct ext2_super_block)); seek_io(fd, 2 * 512 + offset); read_io(fd, super, sizeof (*super)); if (__le16_to_cpu(super->s_magic) != EXT2_SUPER_MAGIC) { free(super); return 0; } free(super); return -1; }
/* Library finalizer function */ static void __attribute__((destructor)) interpose_fini(void) { /* Look for descriptors not explicitly closed */ for(int i=0; i<max_descriptors; i++) { trace_close(i); } read_exe(); read_status(); read_stat(); read_io(); tprintf("stop: %lf\n", get_time()); /* Close trace file */ tclose(); }
uint8_t mem_read8(const Gameboy& gb, const uint16_t address) { if (address < 0x8000) return read_cart(gb.cart, address); else if (address >= 0xFF80) return read_hram(gb, address); else if (address >= 0xFF00) return read_io(gb, address); else if (address >= 0xFE00) return read_oam(gb.memory, address); else if (address >= 0xC000) return read_wram(gb.memory, address); else if (address >= 0xA000) return read_cart_ram(gb.cart, address); else return read_vram(gb.memory, address); }
int quassel_negotiate(GIOChannel* h, int ssl) { uint32_t magic = 0x42b33f00; magic |= !!ssl; //SSL magic |= 2; //Compression magic = htonl(magic); write_io(h, (char*)&magic, sizeof(magic)); //Send supported protocols { //Legacy protocol uint32_t v = 1; v = htonl(v); write_io(h, (char*)&v, sizeof(v)); //End of list v = 1 << 31; v = htonl(v); write_io(h, (char*)&v, sizeof(v)); } //Read answer uint32_t response; while(!read_io(h, (char*)&response, sizeof(response))); response = ntohl(response); //No support for legacy protocol if( (response&0xff)!= 1) return 0; if( (response>>24) & 1) { //switch to ssl fprintf(stderr, "Core asks for ssl\n"); } if( (response>>24) & 2) { //switch and compression fprintf(stderr, "Core asks for compression\n"); extern int useCompression; useCompression = 1; } return 1; }
static int load_segments(Elf_phdr *phdr, int phnum, unsigned long checksum_offset, unsigned int offset, unsigned long *bytes) { //unsigned int start_time, time; int i; *bytes = 0; // start_time = currticks(); for (i = 0; i < phnum; i++) { if (phdr[i].p_type != PT_LOAD) continue; debug("segment %d addr:" FMT_elf " file:" FMT_elf " mem:" FMT_elf " ", i, addr_fixup(phdr[i].p_paddr), phdr[i].p_filesz, phdr[i].p_memsz); seek_io(fd, offset + phdr[i].p_offset); debug("loading... "); if ((size_t)read_io(fd, phys_to_virt(addr_fixup(phdr[i].p_paddr)), phdr[i].p_filesz) != phdr[i].p_filesz) { printf("Can't read program segment %d\n", i); return 0; } bytes += phdr[i].p_filesz; debug("clearing... "); memset(phys_to_virt(addr_fixup(phdr[i].p_paddr) + phdr[i].p_filesz), 0, phdr[i].p_memsz - phdr[i].p_filesz); if (phdr[i].p_offset <= checksum_offset && phdr[i].p_offset + phdr[i].p_filesz >= checksum_offset+2) { debug("clearing checksum... "); memset(phys_to_virt(addr_fixup(phdr[i].p_paddr) + checksum_offset - phdr[i].p_offset), 0, 2); } debug("ok\n"); } // time = currticks() - start_time; //debug("Loaded %lu bytes in %ums (%luKB/s)\n", bytes, time, // time? bytes/time : 0); debug("Loaded %lu bytes \n", *bytes); return 1; }
char * get_hfs_vol_name( int fd, char *buf, int size ) { char sect[512]; hfs_mdb_t *mdb = (hfs_mdb_t*)§ seek_io( fd, 0x400 ); read_io( fd, sect, sizeof(sect) ); if( hfs_get_ushort(mdb->drSigWord) == HFS_SIGNATURE ) { unsigned int n = mdb->drVN[0]; if( n >= size ) n = size - 1; memcpy( buf, &mdb->drVN[1], n ); buf[n] = 0; } else if( hfs_get_ushort(mdb->drSigWord) == HFS_PLUS_SIGNATURE ) { strncpy( buf, "Unembedded HFS+", size ); } else { strncpy( buf, "Error", size ); } return buf; }
int find_elf(Elf_ehdr *ehdr) { int offset; for (offset = 0; offset < MAX_HEADERS * BS; offset += BS) { if ((size_t)read_io(fd, ehdr, sizeof ehdr) != sizeof ehdr) { debug("Can't read ELF header\n"); return 0; } if (is_elf(ehdr)) { debug("Found ELF header at offset %d\n", offset); return offset; } seek_io(fd, offset); } debug("Not a bootable ELF image\n"); return 0; }
UINT8 abc1600_state::read_user_memory(offs_t offset) { int segment = (offset >> 15) & 0x1f; int page = (offset >> 11) & 0x0f; UINT16 page_data = PAGE_DATA(segment, page); offs_t virtual_offset = ((page_data & 0x3ff) << 11) | (offset & 0x7ff); //if (PAGE_NONX) BUS ERROR UINT8 data = 0; if (virtual_offset < 0x1fe000) { data = read_ram(virtual_offset); } else { data = read_io(virtual_offset); } return data; }
static int load_initrd(struct linux_header *hdr, struct sys_info *info, uint32_t kern_end, struct linux_params *params, const char *initrd_file) { uint32_t max; uint32_t start, end, size; uint64_t forced; fd = open_io(initrd_file); if (fd == -1) { printf("Can't open initrd: %s\n", initrd_file); return -1; } #if 0 if (using_devsize) { printf("Attempt to load up to end of device as initrd; " "specify the image size\n"); return -1; } #endif size = file_size(); /* Find out the kernel's restriction on how high the initrd can be * placed */ if (hdr->protocol_version >= 0x203) max = hdr->initrd_addr_max; else max = 0x38000000; /* Hardcoded value for older kernels */ /* FILO itself is at the top of RAM. (relocated) * So, try putting initrd just below us. */ end = virt_to_phys(_start); if (end > max) end = max; /* If "mem=" option is given, we have to put the initrd within * the specified range. */ if (forced_memsize) { forced = forced_memsize; if (forced > max) forced = max; /* If the "mem=" is lower, it's easy */ if (forced <= end) end = forced; else { /* Otherwise, see if we can put it above us */ if (virt_to_phys(_end) + size <= forced) end = forced; /* Ok */ } } start = end - size; start &= ~0xfff; /* page align */ end = start + size; debug("start=%#x end=%#x\n", start, end); if (start < kern_end) { printf("Initrd is too big to fit in memory\n"); return -1; } printf("Loading initrd... "); if (read_io(fd, phys_to_virt(start), size) != size) { printf("Can't read initrd\n"); return -1; } printf("ok\n"); params->initrd_start = start; params->initrd_size = size; close_io(fd); return 0; }
size_t iso9660_read(iso9660_FILE *_file, char *buf, size_t count) { iso9660_FILE *file = (iso9660_FILE*)_file; size_t read = 0; if ( count > (file->size - file->offset) ) count = file->size - file->offset; while (count > 0) { size_t part; int offset_extent; int offset_index; offset_extent = file->base + (file->offset / ISOFS_BLOCK_SIZE); offset_index = file->offset % ISOFS_BLOCK_SIZE; if (file->current != offset_extent) { if ( (offset_index == 0) && (count >= ISOFS_BLOCK_SIZE) ) { /* direct i/o */ int extents_nb; extents_nb = count / ISOFS_BLOCK_SIZE; part = extents_nb * ISOFS_BLOCK_SIZE; seek_io(file->volume->fd, offset_extent * ISOFS_BLOCK_SIZE); read_io(file->volume->fd, buf + read, part); file->offset += part; count -= part; read += part; continue; } file->current = offset_extent; seek_io(file->volume->fd, offset_extent * ISOFS_BLOCK_SIZE); read_io(file->volume->fd, file->buffer, ISOFS_BLOCK_SIZE); } part = ISOFS_BLOCK_SIZE - offset_index; if (count < part) part = count; memcpy(buf + read, file->buffer + offset_index, part); file->offset += part; count -= part; read += part; } return read; }
int xcoff_load(ihandle_t dev) { COFF_filehdr_t fhdr; COFF_aouthdr_t ahdr; COFF_scnhdr_t shdr; uint32_t offset; size_t total_size = 0; int fd, i; int retval = -1; /* Mark the saved-program-state as invalid */ feval("0 state-valid !"); fd = open_ih(dev); if (fd == -1) { retval = LOADER_NOT_SUPPORT; goto out; } for (offset = 0; offset < 16 * 512; offset += 512) { seek_io(fd, offset); if (read_io(fd, &fhdr, sizeof fhdr) != sizeof fhdr) { DPRINTF("Can't read XCOFF header\n"); retval = LOADER_NOT_SUPPORT; goto out; } if (is_xcoff(&fhdr)) break; } /* Is it executable ? */ if (fhdr.f_magic != 0x01DF && (fhdr.f_flags & COFF_F_EXEC) == 0) { DPRINTF("Not an executable XCOFF file %02x\n", fhdr.f_flags); return LOADER_NOT_SUPPORT; } /* Optional header is a.out ? */ if (fhdr.f_opthdr != sizeof(COFF_aouthdr_t)) { DPRINTF("AOUT optional error size mismatch in XCOFF file\n"); return LOADER_NOT_SUPPORT; } seek_io(fd, sizeof(COFF_filehdr_t)); read_io(fd, &ahdr, sizeof(COFF_aouthdr_t)); /* check a.out magic number */ if (ahdr.magic != AOUT_MAGIC) { DPRINTF("Invalid AOUT optional header\n"); return LOADER_NOT_SUPPORT; } offset = sizeof(COFF_filehdr_t) + sizeof(COFF_aouthdr_t); DPRINTF("XCOFF file with %d sections\n", fhdr.f_nscns); for (i = 0; i < fhdr.f_nscns; i++) { DPRINTF("Read header at offset %0x\n", offset); seek_io(fd, offset); read_io(fd, &shdr, sizeof(COFF_scnhdr_t)); DPRINTF("Initializing '%s' section from %0x %0x to %0x (%0x)\n", shdr.s_name, offset, shdr.s_scnptr, shdr.s_vaddr, shdr.s_size); if (strcmp(shdr.s_name, ".text") == 0) { read_io(fd, (void *)shdr.s_vaddr, shdr.s_size); total_size += shdr.s_size; #ifdef CONFIG_PPC flush_icache_range((char*)(uintptr_t)shdr.s_vaddr, (char*)(uintptr_t)(shdr.s_vaddr + shdr.s_size)); #endif } else if (strcmp(shdr.s_name, ".data") == 0) { read_io(fd, (void *)shdr.s_vaddr, shdr.s_size); total_size += shdr.s_size; } else if (strcmp(shdr.s_name, ".bss") == 0) { memset((void *)(uintptr_t)shdr.s_vaddr, 0, shdr.s_size); total_size += shdr.s_size; } else { DPRINTF(" Skip '%s' section\n", shdr.s_name); } offset += sizeof(COFF_scnhdr_t); } DPRINTF("XCOFF entry point: %x\n", *(uint32_t*)ahdr.entry); // Initialise load-state PUSH(total_size); feval("load-state >ls.file-size !"); feval("xcoff load-state >ls.file-type !"); out: close_io(fd); return retval; }
inline UINT8 abc1600_state::dma_iorq_r(int index, UINT16 offset) { offs_t virtual_offset = get_dma_address(index, offset); return read_io(virtual_offset); }
int fcode_load(ihandle_t dev) { int retval = -1; uint8_t fcode_header[8]; unsigned long start, size; unsigned int offset; /* Mark the saved-program-state as invalid */ feval("0 state-valid !"); fd = open_ih(dev); if (fd == -1) { goto out; } for (offset = 0; offset < 16 * 512; offset += 512) { seek_io(fd, offset); if (read_io(fd, &fcode_header, sizeof(fcode_header)) != sizeof(fcode_header)) { debug("Can't read FCode header from ihandle " FMT_ucellx "\n", dev); retval = LOADER_NOT_SUPPORT; goto out; } if (is_fcode(fcode_header)) goto found; } debug("Not a bootable FCode image\n"); retval = LOADER_NOT_SUPPORT; goto out; found: size = (fcode_header[4] << 24) | (fcode_header[5] << 16) | (fcode_header[6] << 8) | fcode_header[7]; fword("load-base"); start = POP(); printf("\nLoading FCode image...\n"); seek_io(fd, offset); if ((size_t)read_io(fd, (void *)start, size) != size) { printf("Can't read file (size 0x%lx)\n", size); goto out; } debug("Loaded %lu bytes\n", size); debug("entry point is %#lx\n", start); // Initialise load-state PUSH(size); feval("load-state >ls.file-size !"); feval("fcode load-state >ls.file-type !"); out: close_io(fd); return retval; }
int aout_load(struct sys_info *info, ihandle_t dev) { int retval = -1; struct exec ehdr; unsigned long start, size; unsigned int offset; image_name = image_version = NULL; /* Mark the saved-program-state as invalid */ feval("0 state-valid !"); fd = open_ih(dev); if (fd == -1) { goto out; } for (offset = 0; offset < 16 * 512; offset += 512) { seek_io(fd, offset); if (read_io(fd, &ehdr, sizeof ehdr) != sizeof ehdr) { debug("Can't read a.out header\n"); retval = LOADER_NOT_SUPPORT; goto out; } if (is_aout(&ehdr)) break; } if (!is_aout(&ehdr)) { debug("Not a bootable a.out image\n"); retval = LOADER_NOT_SUPPORT; goto out; } if (ehdr.a_text == 0x30800007) ehdr.a_text=64*1024; if (N_MAGIC(ehdr) == NMAGIC) { size = addr_fixup(N_DATADDR(ehdr)) + addr_fixup(ehdr.a_data); } else { size = addr_fixup(ehdr.a_text) + addr_fixup(ehdr.a_data); } if (size < 7680) size = 7680; fword("load-base"); start = POP(); // N_TXTADDR(ehdr); memcpy((void *)start, &ehdr, sizeof(ehdr)); if (!check_mem_ranges(info, start, size)) goto out; printf("Loading a.out %s...\n", image_name ? image_name : "image"); seek_io(fd, offset + N_TXTOFF(ehdr)); if (N_MAGIC(ehdr) == NMAGIC) { if ((size_t)read_io(fd, (void *)(start + N_TXTOFF(ehdr)), ehdr.a_text) != ehdr.a_text) { printf("Can't read program text segment (size 0x" FMT_aout_ehdr ")\n", ehdr.a_text); goto out; } if ((size_t)read_io(fd, (void *)(start + N_DATADDR(ehdr)), ehdr.a_data) != ehdr.a_data) { printf("Can't read program data segment (size 0x" FMT_aout_ehdr ")\n", ehdr.a_data); goto out; } } else { if ((size_t)read_io(fd, (void *)(start + N_TXTOFF(ehdr)), size) != size) { printf("Can't read program (size 0x" FMT_sizet ")\n", size); goto out; } } debug("Loaded %lu bytes\n", size); debug("entry point is %#lx\n", start); // Initialise saved-program-state PUSH(size); feval("load-state >ls.file-size !"); feval("aout load-state >ls.file-type !"); out: close_io(fd); return retval; }