static int dcload_stat(vfs_handler_t *vfs, const char *fn, struct stat *rv, int flag) { dcload_stat_t filestat; int retval; (void)flag; if(lwip_dclsc && irq_inside_int()) return 0; spinlock_lock(&mutex); retval = dclsc(DCLOAD_STAT, fn, &filestat); spinlock_unlock(&mutex); if(!retval) { memset(rv, 0, sizeof(struct stat)); rv->st_dev = (dev_t)((ptr_t)vfs); rv->st_ino = filestat.st_ino; rv->st_mode = filestat.st_mode; rv->st_nlink = filestat.st_nlink; rv->st_uid = filestat.st_uid; rv->st_gid = filestat.st_gid; rv->st_rdev = filestat.st_rdev; rv->st_size = filestat.st_size; rv->st_atime = filestat.st_atime; rv->st_mtime = filestat.st_mtime; rv->st_ctime = filestat.st_ctime; rv->st_blksize = filestat.st_blksize; rv->st_blocks = filestat.st_blocks; return 0; } return -1; }
void *dcload_open(vfs_handler_t * vfs, const char *fn, int mode) { int hnd = 0; uint32 h; int dcload_mode = 0; (void)vfs; if(lwip_dclsc && irq_inside_int()) return (void *)0; spinlock_lock(&mutex); if(mode & O_DIR) { if(fn[0] == '\0') { fn = "/"; } hnd = dclsc(DCLOAD_OPENDIR, fn); if(hnd) { if(dcload_path) free(dcload_path); if(fn[strlen(fn) - 1] == '/') { dcload_path = malloc(strlen(fn) + 1); strcpy(dcload_path, fn); } else { dcload_path = malloc(strlen(fn) + 2); strcpy(dcload_path, fn); strcat(dcload_path, "/"); } } } else { /* hack */ if((mode & O_MODE_MASK) == O_RDONLY) dcload_mode = 0; if((mode & O_MODE_MASK) == O_RDWR) dcload_mode = 2 | 0x0200; if((mode & O_MODE_MASK) == O_WRONLY) dcload_mode = 1 | 0x0200; if((mode & O_MODE_MASK) == O_APPEND) dcload_mode = 2 | 8 | 0x0200; if(mode & O_TRUNC) dcload_mode |= 0x0400; hnd = dclsc(DCLOAD_OPEN, fn, dcload_mode, 0644); hnd++; /* KOS uses 0 for error, not -1 */ } h = hnd; spinlock_unlock(&mutex); return (void *)h; }
/* VP : added this */ int dbgio_vprintf(const char *fmt, va_list args) { int i; /* XXX This isn't correct. We could be inside an int with IRQs enabled, and we could be outside an int with IRQs disabled, which would cause a deadlock here. We need an irq_is_enabled()! */ if (!irq_inside_int()) spinlock_lock(&lock); i = vsprintf(printf_buf, fmt, args); dbgio_write_str(printf_buf); if (!irq_inside_int()) spinlock_unlock(&lock); return i; }
static int eth_txts(uint8 *pkt, int len) { int res; for( ; ; ) { if (!irq_inside_int()) tx_lock(); res = net_tx(pkt, len, irq_inside_int()); if (!irq_inside_int()) tx_unlock(); if (!res || irq_inside_int()) break; thd_pass(); } return res; }
/* Kernel debug logging facility */ void dbglog(int level, const char *fmt, ...) { va_list args; /* If this log level is blocked out, don't even bother */ if(level > dbglog_level) return; /* We only try to lock if the message isn't urgent */ if(level >= DBG_ERROR && !irq_inside_int()) spinlock_lock(&mutex); va_start(args, fmt); (void)vsprintf(printf_buf, fmt, args); va_end(args); if(irq_inside_int()) dbgio_write_str(printf_buf); else fs_write(1, printf_buf, strlen(printf_buf)); if(level >= DBG_ERROR && !irq_inside_int()) spinlock_unlock(&mutex); }
int dcload_write_buffer(const uint8 *data, int len, int xlat) { (void)xlat; if(lwip_dclsc && irq_inside_int()) { errno = EAGAIN; return -1; } spinlock_lock(&mutex); dclsc(DCLOAD_WRITE, 1, data, len); spinlock_unlock(&mutex); return len; }
dirent_t *dcload_readdir(void * h) { dirent_t *rv = NULL; dcload_dirent_t *dcld; dcload_stat_t filestat; char *fn; uint32 hnd = (uint32)h; if(lwip_dclsc && irq_inside_int()) { errno = EAGAIN; return NULL; } if(hnd < 100) { errno = EBADF; return NULL; } spinlock_lock(&mutex); dcld = (dcload_dirent_t *)dclsc(DCLOAD_READDIR, hnd); if(dcld) { rv = &dirent; strcpy(rv->name, dcld->d_name); rv->size = 0; rv->time = 0; rv->attr = 0; /* what the hell is attr supposed to be anyways? */ fn = malloc(strlen(dcload_path) + strlen(dcld->d_name) + 1); strcpy(fn, dcload_path); strcat(fn, dcld->d_name); if(!dclsc(DCLOAD_STAT, fn, &filestat)) { if(filestat.st_mode & S_IFDIR) { rv->size = -1; rv->attr = O_DIR; } else rv->size = filestat.st_size; rv->time = filestat.st_mtime; } free(fn); } spinlock_unlock(&mutex); return rv; }
int dma_free(dma_chain_t * chain) { int irq = 0; if (chain == NULL) return -1; if (!irq_inside_int()) irq = irq_disable(); /* mark we won't wait on the semaphore */ chain->src = NULL; if (!chain->dest) { /* the semaphore has been signaled already */ assert(!sem_trywait(chain->sema)); free_chain(chain); } if (!irq_inside_int()) irq_restore(irq); return 0; }
static int eth_txts(uint8 *pkt, int len) { int res; int oldirq; for( ; ; ) { if (!irq_inside_int()) tx_lock(); #if 0 STOPIRQ; while (bba_dma_busy) { STARTIRQ; thd_pass(); STOPIRQ; } #endif #ifdef NICE res = net_tx(pkt, len, irq_inside_int()); #else res = net_tx(pkt, len, 1); #endif #if 0 STARTIRQ; #endif if (!irq_inside_int()) tx_unlock(); if (!res || irq_inside_int()) break; thd_pass(); } return res; }
int dcload_unlink(vfs_handler_t * vfs, const char *fn) { int ret; (void)vfs; if(lwip_dclsc && irq_inside_int()) return 0; spinlock_lock(&mutex); ret = dclsc(DCLOAD_UNLINK, fn); spinlock_unlock(&mutex); return ret; }
size_t dcload_gdbpacket(const char* in_buf, size_t in_size, char* out_buf, size_t out_size) { size_t ret = -1; if(lwip_dclsc && irq_inside_int()) return 0; spinlock_lock(&mutex); /* we have to pack the sizes together because the dcloadsyscall handler can only take 4 parameters */ ret = dclsc(DCLOAD_GDBPACKET, in_buf, (in_size << 16) | (out_size & 0xffff), out_buf); spinlock_unlock(&mutex); return ret; }
ssize_t dcload_write(void * h, const void *buf, size_t cnt) { ssize_t ret = -1; uint32 hnd = (uint32)h; if(lwip_dclsc && irq_inside_int()) return 0; spinlock_lock(&mutex); if(hnd) { hnd--; /* KOS uses 0 for error, not -1 */ ret = dclsc(DCLOAD_WRITE, hnd, buf, cnt); } spinlock_unlock(&mutex); return ret; }
off_t dcload_seek(void * h, off_t offset, int whence) { off_t ret = -1; uint32 hnd = (uint32)h; if(lwip_dclsc && irq_inside_int()) return 0; spinlock_lock(&mutex); if(hnd) { hnd--; /* KOS uses 0 for error, not -1 */ ret = dclsc(DCLOAD_LSEEK, hnd, offset, whence); } spinlock_unlock(&mutex); return ret; }
off_t dcload_tell(void * h) { off_t ret = -1; uint32 hnd = (uint32)h; if(lwip_dclsc && irq_inside_int()) return 0; spinlock_lock(&mutex); if(hnd) { hnd--; /* KOS uses 0 for error, not -1 */ ret = dclsc(DCLOAD_LSEEK, hnd, 0, SEEK_CUR); } spinlock_unlock(&mutex); return ret; }
int dcload_rename(vfs_handler_t * vfs, const char *fn1, const char *fn2) { int ret; (void)vfs; if(lwip_dclsc && irq_inside_int()) return 0; spinlock_lock(&mutex); /* really stupid hack, since I didn't put rename() in dcload */ ret = dclsc(DCLOAD_LINK, fn1, fn2); if(!ret) ret = dclsc(DCLOAD_UNLINK, fn1); spinlock_unlock(&mutex); return ret; }
size_t dcload_total(void * h) { size_t ret = -1; size_t cur; uint32 hnd = (uint32)h; if(lwip_dclsc && irq_inside_int()) return 0; spinlock_lock(&mutex); if(hnd) { hnd--; /* KOS uses 0 for error, not -1 */ cur = dclsc(DCLOAD_LSEEK, hnd, 0, SEEK_CUR); ret = dclsc(DCLOAD_LSEEK, hnd, 0, SEEK_END); dclsc(DCLOAD_LSEEK, hnd, cur, SEEK_SET); } spinlock_unlock(&mutex); return ret; }
int dcload_close(void * h) { uint32 hnd = (uint32)h; if(lwip_dclsc && irq_inside_int()) { errno = EINTR; return -1; } spinlock_lock(&mutex); if(hnd) { if(hnd > 100) /* hack */ dclsc(DCLOAD_CLOSEDIR, hnd); else { hnd--; /* KOS uses 0 for error, not -1 */ dclsc(DCLOAD_CLOSE, hnd); } } spinlock_unlock(&mutex); return 0; }
//#undef printf int dma_wait(dma_chain_t * chain) { if (chain == NULL) return -1; if (irq_inside_int()) { panic("dma_wait called inside an irq !\n"); dma_free(chain); return -1; } printf("\n !!!!!!!!!! waiting ... \n"); sem_wait(chain->sema); /* if (sem_wait_timed(chain->sema, 1000)) { */ /* printf("dma timeout...\n"); */ /* dma_free(chain); */ /* return -1; */ /* } */ printf("\n !!!!!!!!!! done !\n"); free_chain(chain); return 0; }
static int printk_func(const uint8 *data, int len, int xlat) { if (tool_ip) { int oldirq = 0; int res = -1; if (irq_inside_int()) return 0; if (net_trylock()) { STOPIRQ; res = sc_write(1, data, len); STARTIRQ; net_unlock(); } return res; } else { if (real_old_printk_func) return real_old_printk_func(data, len, xlat); else return len; } }
dma_chain_t * dma_initiate(void * dest, void * src, uint32 length, int type) { int irq = 0; dma_chain_t * chain = alloc_chain(); if (chain == NULL) return NULL; chain->dest = (uint32) dest; chain->src = (uint8 *) src; chain->count = length; chain->type = type; chain->waiting_thd = 0; if (type == DMA_TYPE_SPU || type == DMA_TYPE_BBA_RX) { if (type == DMA_TYPE_SPU && (0||nospudma)) { vid_border_color(0, 0, 255); spu_memload(chain->dest, chain->src, chain->count); vid_border_color(0, 0, 0); sem_signal(chain->sema); return chain; } else { //draw_lock(); vid_border_color(0, 0, 255); if (!irq_inside_int()) irq = irq_disable(); if (type == DMA_TYPE_BBA_RX) { /* if (spu_chain_head && spu_chain_head->type == DMA_TYPE_SPU) { */ /* if (!irq_inside_int()) */ /* irq_restore(irq); */ /* free_chain(chain); */ /* return NULL; */ /* } */ chain->waiting_thd = thd_current; } chain->next = spu_chain_head; spu_chain_head = chain; if (!spu_transfering) spu_cb(0); if (!irq_inside_int()) irq_restore(irq); return chain; } } else nospudma = 0; if (!irq_inside_int()) irq = irq_disable(); chain->next = chain_head; chain_head = chain; ta_render_done_cb = renderdone_cb; //vid_border_color(0, 0, 255); if (!irq_inside_int()) irq_restore(irq); return chain; }