void thd_print_regs(struct thread *t) { struct pt_regs *r = &t->regs; struct spd *s = thd_get_thd_spd(t); printk("cos: spd %d, thd %d w/ regs: \ncos:\t\t" "eip %10x, esp %10x, eax %10x, ebx %10x, ecx %10x,\ncos:\t\t" "edx %10x, edi %10x, esi %10x, ebp %10x \n", spd_get_index(s), thd_get_id(t), (unsigned int)r->ip, (unsigned int)r->sp, (unsigned int)r->ax, (unsigned int)r->bx, (unsigned int)r->cx, (unsigned int)r->dx, (unsigned int)r->di, (unsigned int)r->si, (unsigned int)r->bp); return; }
/* * Return -1 if there is some form of error (couldn't find ring * buffer, or buffer is of inappropriate size), 1 if there is no * error, but there is no available buffer, 0 if found_buff and * found_len are set to the buffer's values. * * See cos_types.h for a description of the structure of the buffer. */ int rb_retrieve_buff(struct thread *brand, int desired_len, void **found_buf, int *found_len) { ring_buff_t *rb; int position; void *addr; vaddr_t kaddr; unsigned short int status, len; struct spd *bspd; assert(brand); rb = brand->k_rb; if (!rb) { return -1; } position = brand->rb_next; addr = rb->packets[position].ptr; len = rb->packets[position].len; status = rb->packets[position].status; if (RB_READY != status || NULL == addr) { return 1; } if (len < desired_len) { printk("ring_buff: length of user buffer not sufficient.\n"); return -1; } bspd = thd_get_thd_spd(brand); kaddr = pgtbl_vaddr_to_kaddr(bspd->spd_info.pg_tbl, (unsigned long)addr); if (!kaddr || !user_struct_fits_on_page(kaddr, len)) { rb->packets[position].status = RB_ERR; brand->rb_next = (position+1) & (RB_SIZE-1); printk("ring_buff: user buffer either not in memory, or not page_aligned.\n"); return -1; } assert(kaddr); // printk("kaddr to copy to is %x from ptr %x\n", kaddr, addr); *found_buf = (void*)kaddr; *found_len = len; rb->packets[position].status = RB_USED; brand->rb_next = (position+1) & (RB_SIZE-1); return 0; }
/* * Is the thread currently in an atomic section? If so, rollback its * instruction pointer to the beginning of the section (the commit has * not yet happened). */ int thd_check_atomic_preempt(struct thread *thd) { struct spd *spd = thd_get_thd_spd(thd); vaddr_t ip = thd_get_ip(thd); int i; /* assert(host_in_syscall() || host_in_idle() || */ /* thd->flags & THD_STATE_PREEMPTED); */ for (i = 0 ; i < COS_NUM_ATOMIC_SECTIONS/2 ; i+=2) { if (ip > spd->atomic_sections[i] && ip < spd->atomic_sections[i+1]) { thd->regs.ip = spd->atomic_sections[i]; cos_meas_event(COS_MEAS_ATOMIC_RBK); return 1; } } return 0; }