static void do_write(os_emul_data *emul, unsigned call, const int arg0, cpu *processor, unsigned_word cia) { void *scratch_buffer = NULL; 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(write); 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); /* FIXME - nbytes == 0 */ /* copy in */ emul_read_buffer(scratch_buffer, buf, nbytes, processor, cia); /* write */ status = write(d, scratch_buffer, nbytes); emul_write_status(processor, status, errno); free(scratch_buffer); flush_stdoutput(); }
static void emul_bugapi_do_write(os_emul_data *bugapi, cpu *processor, unsigned_word cia, unsigned_word buf, int nbytes, const char *suffix) { void *scratch_buffer = NULL; /* get a tempoary bufer */ if (nbytes > 0) { scratch_buffer = zalloc(nbytes); /* copy in */ emul_read_buffer(scratch_buffer, buf, nbytes, processor, cia); /* write */ device_instance_write(bugapi->output, scratch_buffer, nbytes); zfree(scratch_buffer); } if (suffix) device_instance_write(bugapi->output, suffix, strlen(suffix)); flush_stdoutput (); }
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 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"); } } } }