void sscapeintr(int irq) { u_char bits, tmp; DEB(printf("sscapeintr(0x%02x)\n", (bits = sscape_read(devc, GA_INTSTAT_REG)))); if ((sscape_sleep_flag.mode & WK_SLEEP)) { sscape_sleep_flag.mode = WK_WAKEUP; wakeup(sscape_sleeper); } if (bits & 0x02) { /* Host interface interrupt */ printf("SSCAPE: Host interrupt, data=%02x\n", host_read(devc)); } #if (defined(CONFIG_MPU401) || defined(CONFIG_MPU_EMU)) && defined(CONFIG_MIDI) if (bits & 0x01) { static int debug = 0; mpuintr(irq); if (debug++ > 10) { /* Temporary debugging hack */ sscape_write(devc, GA_INTENA_REG, 0x00); /* Disable all interr. */ } } #endif /* * Acknowledge interrupts (toggle the interrupt bits) */ tmp = sscape_read(devc, GA_INTENA_REG); sscape_write(devc, GA_INTENA_REG, (~bits & 0x0e) | (tmp & 0xf1)); }
int hostif_getch() { unsigned char ch = 0; if(host_read(STDIN_FILENO, &ch, 1) != 1) { return EOF; } return (int)ch; }
static void set_control(struct sscape_info *devc, int ctrl, int value) { host_open(devc); host_command3(devc, CMD_SET_CONTROL, ctrl, value); if (host_read(devc) != CMD_ACK) { /* printk( "SNDSCAPE: Setting control (%d) failed\n", ctrl); */ } host_close(devc); }
static void set_mt32(struct sscape_info *devc, int value) { host_open(devc); host_command2(devc, CMD_SET_MT32, value ? 1 : 0); if (host_read(devc) != CMD_ACK) { /* printk( "SNDSCAPE: Setting MT32 mode failed\n"); */ } host_close(devc); }
static int hostcons_getchar() { uint8_t ch; int rv; rv = host_read(0, &ch, 1); if (rv == 1) return (ch); return (-1); }
//Copy file operation int copy_file() { int in_fd; FILE* out_fd; int fsize = 0; char file_name[MAX_BUFFER_SIZE]; /* Get the file name to copy to * This will activate our hook on the invalid opcode in the python script. */ host_get_file_name(agent_buffer, sizeof(agent_buffer)); strncpy(file_name,agent_buffer,sizeof(file_name)); /* Open file on the host. */ if ((in_fd = host_open(file_name)) == -1){ fprintf(stderr, "Error opening file on host\n"); return 2; } /* Read file from the host and output it on stdout. */ if ((out_fd = fopen(file_name, "wb")) == NULL){ fprintf(stderr, "Error opening file %s on guest for writing\n", file_name); return 3; } /* Data read loop */ while (1) { int ret = host_read(in_fd, agent_buffer, sizeof(agent_buffer)); if (ret == -1) { fprintf(stderr, "Error reading from host file\n"); return 4; } else if (ret == 0) { break; } if (fwrite(agent_buffer, 1, ret, out_fd) != ret) { fprintf(stderr, "Error writing to file on guest\n"); return 5; } fsize += ret; } /* Don't forget to close the file on the host. */ host_close(in_fd); fclose(out_fd); fprintf(stderr, "File %s of size %d was successfully transferred\n", file_name, fsize); return 0; }
// Fault any disk block that is read or written in to memory by // loading it from disk. // Hint: Use ide_read and BLKSECTS. static void bc_pgfault(struct UTrapframe *utf) { void *addr = (void *) utf->utf_fault_va; uint64_t blockno = ((uint64_t)addr - DISKMAP) / BLKSIZE; int r; // Check that the fault was within the block cache region if (addr < (void*)DISKMAP || addr >= (void*)(DISKMAP + DISKSIZE)) panic("page fault in FS: eip %08x, va %08x, err %04x", utf->utf_rip, addr, utf->utf_err); // Sanity check the block number. if (super && blockno >= super->s_nblocks) panic("reading non-existent block %08x\n", blockno); // Allocate a page in the disk map region, read the contents // of the block from the disk into that page, and mark the // page not-dirty (since reading the data from disk will mark // the page dirty). // // LAB 5: Your code here if((r= sys_page_alloc(0, ROUNDDOWN(addr,PGSIZE), PTE_SYSCALL)) < 0) panic("File System page fault handler couldn't alloc new page at addr %d. %e",addr, r); //if(super) // cprintf("12 %d\n",super->s_nblocks); #ifndef VMM_GUEST if((r = ide_read(blockno*BLKSECTS, ROUNDDOWN(addr,BLKSIZE), BLKSECTS)) < 0) #else if((r = host_read(BLKSECTS*blockno, ROUNDDOWN(addr,BLKSIZE), BLKSECTS)) < 0) #endif panic("File System page fault handler couldn't read in the data from disk. %e", r); //if(super) // cprintf("13 %d\n",super->s_nblocks); if((r = sys_page_map(0, ROUNDDOWN(addr,PGSIZE), 0, ROUNDDOWN(addr,BLKSIZE), PTE_P| PTE_U | PTE_W)) < 0) //PTE_SYSCALL&~PTE_D panic("Couldn't map page not dirty bc_pageflt %e",r); //if(super) // cprintf("14 %d\n",super->s_nblocks); //cprintf("Handled the Fault\n"); //panic("bc_pgfault not implemented"); // Check that the block we read was allocated. (exercise for // the reader: why do we do this *after* reading the block // in?) if (bitmap && block_is_free(blockno)) panic("reading free block %08x\n", blockno); }
static int get_board_type (struct sscape_info *devc) { int tmp; host_open (devc); if (!host_command1 (devc, CMD_GET_BOARD_TYPE)) tmp = -1; else tmp = host_read (devc); host_close (devc); return tmp; }
// Fault any disk block that is read in to memory by // loading it from disk. // Hint: Use ide_read and BLKSECTS. static void bc_pgfault(struct UTrapframe *utf) { void *addr = (void *) utf->utf_fault_va; uint64_t blockno = ((uint64_t)addr - DISKMAP) / BLKSIZE; int r; // Check that the fault was within the block cache region if (addr < (void*)DISKMAP || addr >= (void*)(DISKMAP + DISKSIZE)) panic("page fault in FS: eip %08x, va %08x, err %04x", utf->utf_rip, addr, utf->utf_err); // Sanity check the block number. if (super && blockno >= super->s_nblocks) panic("reading non-existent block %08x\n", blockno); // Allocate a page in the disk map region, read the contents // of the block from the disk into that page. // Hint: first round addr to page boundary. // // LAB 5: your code here: addr = ROUNDDOWN(addr, PGSIZE); if(0 != sys_page_alloc(0, (void*)addr, PTE_SYSCALL)){ panic("Page Allocation Failed during handling page fault in FS"); } #ifdef VMM_GUEST if(0 != host_read((uint32_t) (blockno * BLKSECTS), (void*)addr, BLKSECTS)) { panic("ide read failed in Page Fault Handling"); } #else if(0 != ide_read((uint32_t) (blockno * BLKSECTS), (void*)addr, BLKSECTS)) { panic("ide read failed in Page Fault Handling"); } #endif if ((r = sys_page_map(0, addr, 0, addr, uvpt[PGNUM(addr)] & PTE_SYSCALL)) < 0) panic("in bc_pgfault, sys_page_map: %e", r); // Check that the block we read was allocated. (exercise for // the reader: why do we do this *after* reading the block // in?) if (bitmap && block_is_free(blockno)) panic("reading free block %08x\n", blockno); }
// Fault any disk block that is read in to memory by // loading it from disk. static void bc_pgfault(struct UTrapframe *utf) { void *addr = (void *) utf->utf_fault_va; uint64_t blockno = ((uint64_t)addr - DISKMAP) / BLKSIZE; int r; // Check that the fault was within the block cache region if (addr < (void*)DISKMAP || addr >= (void*)(DISKMAP + DISKSIZE)) panic("page fault in FS: eip %08x, va %08x, err %04x", utf->utf_rip, addr, utf->utf_err); // Sanity check the block number. if (super && blockno >= super->s_nblocks) panic("reading non-existent block %08x\n", blockno); // Allocate a page in the disk map region, read the contents // of the block from the disk into that page. // Hint: first round addr to page boundary. // // LAB 5: your code here: // Check that the block we read was allocated. (exercise for // the reader: why do we do this *after* reading the block // in?) if (bitmap && block_is_free(blockno)) //doubtful panic("reading free block %08x\n", blockno); void *new_addr = ROUNDDOWN(addr, PGSIZE); r = sys_page_alloc(0, new_addr, PTE_P|PTE_W|PTE_U); if(r<0) panic("Something wrong with allocation %e",r); uint64_t sec_no = BLKSECTS * blockno; size_t nsecs = BLKSECTS; #ifdef VMM_GUEST r = host_read(sec_no, new_addr, nsecs); #else r = ide_read(sec_no, new_addr, nsecs); #endif if(r<0) panic("Something wrong with reading from the disk %e",r); }
void nuse_vif_pipe_read(struct nuse_vif *vif, struct SimDevice *dev) { int sock = vif->sock; char buf[8192]; ssize_t size; while (1) { size = host_read(sock, buf, sizeof(buf)); if (size < 0) { perror("read"); host_close(sock); return; } else if (size == 0) { host_close(sock); return; } nuse_dev_rx(dev, buf, size); } }
void sscapeintr (int irq, void *dev_id, struct pt_regs *dummy) { unsigned char bits, tmp; static int debug = 0; bits = sscape_read (devc, GA_INTSTAT_REG); if ((sscape_sleep_flag.flags & WK_SLEEP)) { { sscape_sleep_flag.flags = WK_WAKEUP; module_wake_up (&sscape_sleeper); }; } if (bits & 0x02) /* Host interface interrupt */ { printk ("SSCAPE: Host interrupt, data=%02x\n", host_read (devc)); } #if defined(CONFIG_MPU_EMU) && defined(CONFIG_MIDI) if (bits & 0x01) { mpuintr (irq, NULL, NULL); if (debug++ > 10) /* Temporary debugging hack */ { sscape_write (devc, GA_INTENA_REG, 0x00); /* Disable all interrupts */ } } #endif /* * Acknowledge interrupts (toggle the interrupt bits) */ tmp = sscape_read (devc, GA_INTENA_REG); sscape_write (devc, GA_INTENA_REG, (~bits & 0x0e) | (tmp & 0xf1)); }
static int sscape_read_host_ctrl(sscape_info* devc) { return host_read(devc); }