STATIC_INLINE_EMUL_NETBSD void write_rusage(unsigned_word addr, struct rusage rusage, cpu *processor, unsigned_word cia) { H2T(rusage.ru_utime.tv_sec); /* user time used */ H2T(rusage.ru_utime.tv_usec); H2T(rusage.ru_stime.tv_sec); /* system time used */ H2T(rusage.ru_stime.tv_usec); H2T(rusage.ru_maxrss); /* integral max resident set size */ H2T(rusage.ru_ixrss); /* integral shared text memory size */ H2T(rusage.ru_idrss); /* integral unshared data size */ H2T(rusage.ru_isrss); /* integral unshared stack size */ H2T(rusage.ru_minflt); /* page reclaims */ H2T(rusage.ru_majflt); /* page faults */ H2T(rusage.ru_nswap); /* swaps */ H2T(rusage.ru_inblock); /* block input operations */ H2T(rusage.ru_oublock); /* block output operations */ H2T(rusage.ru_msgsnd); /* messages sent */ H2T(rusage.ru_msgrcv); /* messages received */ H2T(rusage.ru_nsignals); /* signals received */ H2T(rusage.ru_nvcsw); /* voluntary context switches */ H2T(rusage.ru_nivcsw); /* involuntary context switches */ emul_write_buffer(&rusage, addr, sizeof(rusage), processor, cia); }
STATIC_INLINE_EMUL_NETBSD void write_stat(unsigned_word addr, struct stat buf, cpu *processor, unsigned_word cia) { H2T(buf.st_dev); H2T(buf.st_ino); H2T(buf.st_mode); H2T(buf.st_nlink); H2T(buf.st_uid); H2T(buf.st_gid); H2T(buf.st_size); H2T(buf.st_atime); /* H2T(buf.st_spare1); */ H2T(buf.st_mtime); /* H2T(buf.st_spare2); */ H2T(buf.st_ctime); /* H2T(buf.st_spare3); */ #ifdef AC_STRUCT_ST_RDEV H2T(buf.st_rdev); #endif #ifdef AC_STRUCT_ST_BLKSIZE H2T(buf.st_blksize); #endif #ifdef AC_STRUCT_ST_BLOCKS H2T(buf.st_blocks); #endif #if WITH_NetBSD_HOST H2T(buf.st_flags); H2T(buf.st_gen); #endif emul_write_buffer(&buf, addr, sizeof(buf), processor, cia); }
STATIC_INLINE_EMUL_NETBSD void write_timezone(unsigned_word addr, struct timezone tz, cpu *processor, unsigned_word cia) { H2T(tz.tz_minuteswest); H2T(tz.tz_dsttime); emul_write_buffer(&tz, addr, sizeof(tz), processor, cia); }
STATIC_INLINE_EMUL_NETBSD void write_timeval(unsigned_word addr, struct timeval t, cpu *processor, unsigned_word cia) { H2T(t.tv_sec); H2T(t.tv_usec); emul_write_buffer(&t, addr, sizeof(t), processor, cia); }
static void do_read(os_emul_data *emul, unsigned call, const int arg0, cpu *processor, unsigned_word cia) { void *scratch_buffer; int d = (int)cpu_registers(processor)->gpr[arg0]; unsigned_word buf = cpu_registers(processor)->gpr[arg0+1]; int nbytes = cpu_registers(processor)->gpr[arg0+2]; int status; SYS(read); if (WITH_TRACE && ppc_trace[trace_os_emul]) printf_filtered ("%d, 0x%lx, %d", d, (long)buf, nbytes); /* get a tempoary bufer */ scratch_buffer = zalloc(nbytes); /* check if buffer exists by reading it */ emul_read_buffer(scratch_buffer, buf, nbytes, processor, cia); /* read */ #if 0 if (d == 0) { status = fread (scratch_buffer, 1, nbytes, stdin); if (status == 0 && ferror (stdin)) status = -1; } #endif status = read (d, scratch_buffer, nbytes); emul_write_status(processor, status, errno); if (status > 0) emul_write_buffer(scratch_buffer, buf, status, processor, cia); free(scratch_buffer); }
STATIC_INLINE_EMUL_NETBSD void write_direntries(unsigned_word addr, char *buf, int nbytes, cpu *processor, unsigned_word cia) { while (nbytes > 0) { struct dirent *out; struct dirent *in = (struct dirent*)buf; ASSERT(in->d_reclen <= nbytes); out = (struct dirent*)zalloc(in->d_reclen); memcpy(out/*dest*/, in/*src*/, in->d_reclen); H2T(out->d_fileno); H2T(out->d_reclen); H2T(out->d_type); H2T(out->d_namlen); emul_write_buffer(out, addr, in->d_reclen, processor, cia); nbytes -= in->d_reclen; addr += in->d_reclen; buf += in->d_reclen; free(out); } }
STATIC_INLINE_EMUL_NETBSD void write_statfs(unsigned_word addr, struct statfs buf, cpu *processor, unsigned_word cia) { H2T(buf.f_type); H2T(buf.f_flags); H2T(buf.f_bsize); H2T(buf.f_iosize); H2T(buf.f_blocks); H2T(buf.f_bfree); H2T(buf.f_bavail); H2T(buf.f_files); H2T(buf.f_ffree); H2T(buf.f_fsid.val[0]); H2T(buf.f_fsid.val[1]); H2T(buf.f_owner); /* f_spare[4]; */ /* f_fstypename[MFSNAMELEN]; */ /* f_mntonname[MNAMELEN]; */ /* f_mntfromname[MNAMELEN]; */ emul_write_buffer(&buf, addr, sizeof(buf), processor, cia); }
static int emul_bugapi_do_read(os_emul_data *bugapi, cpu *processor, unsigned_word cia, unsigned_word buf, int nbytes) { unsigned char *scratch_buffer; int status; /* get a tempoary bufer */ scratch_buffer = (unsigned char *) zalloc(nbytes); /* check if buffer exists by reading it */ emul_read_buffer((void *)scratch_buffer, buf, nbytes, processor, cia); /* read */ status = device_instance_read(bugapi->input, (void *)scratch_buffer, nbytes); /* -1 = error, -2 = nothing available - see "serial" [IEEE1275] */ if (status < 0) { status = 0; } if (status > 0) { emul_write_buffer((void *)scratch_buffer, buf, status, processor, cia); /* Bugapi chops off the trailing n, but leaves it in the buffer */ if (scratch_buffer[status-1] == '\n' || scratch_buffer[status-1] == '\r') status--; } zfree(scratch_buffer); return status; }
static void emul_bugapi_do_diskio(os_emul_data *bugapi, cpu *processor, unsigned_word cia, unsigned_word descriptor_addr, int call_id) { struct dskio_descriptor { unsigned_1 ctrl_lun; unsigned_1 dev_lun; unsigned_2 status; unsigned_word pbuffer; unsigned_4 blk_num; unsigned_2 blk_cnt; unsigned_1 flag; #define BUG_FILE_MARK 0x80 #define IGNORE_FILENUM 0x02 #define END_OF_FILE 0x01 unsigned_1 addr_mod; } descriptor; int block; emul_read_buffer(&descriptor, descriptor_addr, sizeof(descriptor), processor, cia); T2H(descriptor.ctrl_lun); T2H(descriptor.dev_lun); T2H(descriptor.status); T2H(descriptor.pbuffer); T2H(descriptor.blk_num); T2H(descriptor.blk_cnt); T2H(descriptor.flag); T2H(descriptor.addr_mod); if (descriptor.dev_lun >= nr_bugapi_disks || bugapi->disk[descriptor.dev_lun] == NULL) { error("emul_bugapi_do_diskio: attempt to access unconfigured disk /chosen/disk%d", descriptor.dev_lun); } else { for (block = 0; block < descriptor.blk_cnt; block++) { device_instance *disk = bugapi->disk[descriptor.dev_lun]; unsigned_1 buf[512]; /*????*/ unsigned_word block_nr = descriptor.blk_num + block; unsigned_word byte_nr = block_nr * sizeof(buf); unsigned_word block_addr = descriptor.pbuffer + block*sizeof(buf); if (device_instance_seek(disk, 0, byte_nr) < 0) error("emul_bugapi_do_diskio: bad seek\n"); switch (call_id) { case _DSKRD: if (device_instance_read(disk, buf, sizeof(buf)) != sizeof(buf)) error("emul_`bugapi_do_diskio: bad read\n"); emul_write_buffer(buf, block_addr, sizeof(buf), processor, cia); break; case _DSKWR: emul_read_buffer(buf, block_addr, sizeof(buf), processor, cia); if (device_instance_write(disk, buf, sizeof(buf)) != sizeof(buf)) error("emul_bugapi_do_diskio: bad write\n"); break; default: error("emul_bugapi_do_diskio: bad switch\n"); } } } }