static size_t serial_gotdata( struct handle *h, const void *data, size_t len, int err) { Serial *serial = (Serial *)handle_get_privdata(h); if (err || len == 0) { const char *error_msg; /* * Currently, len==0 should never happen because we're * ignoring EOFs. However, it seems not totally impossible * that this same back end might be usable to talk to named * pipes or some other non-serial device, in which case EOF * may become meaningful here. */ if (!err) error_msg = "End of file reading from serial device"; else error_msg = "Error reading from serial device"; serial_terminate(serial); seat_notify_remote_exit(serial->seat); logevent(serial->logctx, error_msg); seat_connection_fatal(serial->seat, "%s", error_msg); return 0; } else { return seat_stdout(serial->seat, data, len); } }
static int serial_gotdata(struct handle *h, void *data, int len) { Serial serial = (Serial)handle_get_privdata(h); if (len <= 0) { const char *error_msg; /* * Currently, len==0 should never happen because we're * ignoring EOFs. However, it seems not totally impossible * that this same back end might be usable to talk to named * pipes or some other non-serial device, in which case EOF * may become meaningful here. */ if (len == 0) error_msg = "End of file reading from serial device"; else error_msg = "Error reading from serial device"; serial_terminate(serial); notify_remote_exit(serial->frontend); logevent(serial->frontend, error_msg); connection_fatal(serial->frontend, "%s", error_msg); return 0; /* placate optimiser */ } else { return from_backend(serial->frontend, 0, data, len); } }
static void serial_free(Backend *be) { Serial *serial = container_of(be, Serial, backend); serial_terminate(serial); expire_timer_context(serial); sfree(serial); }
static void serial_free(void *handle) { Serial serial = (Serial) handle; serial_terminate(serial); expire_timer_context(serial); sfree(serial); }
static void serial_sentdata(struct handle *h, size_t new_backlog, int err) { Serial *serial = (Serial *)handle_get_privdata(h); if (err) { const char *error_msg = "Error writing to serial device"; serial_terminate(serial); seat_notify_remote_exit(serial->seat); logevent(serial->logctx, error_msg); seat_connection_fatal(serial->seat, "%s", error_msg); } else { serial->bufsize = new_backlog; } }
static void serial_sentdata(struct handle *h, int new_backlog) { Serial serial = (Serial)handle_get_privdata(h); if (new_backlog < 0) { const char *error_msg = "Error writing to serial device"; serial_terminate(serial); notify_remote_exit(serial->frontend); logevent(serial->frontend, error_msg); connection_fatal(serial->frontend, "%s", error_msg); } else { serial->bufsize = new_backlog; } }
void main(uint32_t magic, struct multiboot_info *mbi, uintptr_t esp, uintptr_t stack_end) { stack_start = esp; stack_size = stack_end - stack_start; vga_driver = vga_init(); com_driver = serial_init(); logging_init(vga_driver, com_driver); assert(magic == MULTIBOOT_MAGIC); assert(mbi->flags & MULTIBOOT_LOADER); kprintf(INFO, "\033\012Toutatis kernel booting from %s\033\017\n", (char *)(mbi->boot_loader_name + (uint32_t)&kernel_voffset)); arch_init(); initrd_init(mbi); assert(mbi->flags & MULTIBOOT_MEMINFO); paging_init((mbi->mem_lower + mbi->mem_upper) * 1024); paging_mark_reserved((uint32_t)mbi - (uint32_t)&kernel_voffset); assert(mbi->flags & MULTIBOOT_MMAP); for (mmap_entry_t *mmap = (mmap_entry_t *)(mbi->mmap_addr + (uint32_t)&kernel_voffset); (uint32_t)mmap < mbi->mmap_addr + (uint32_t)&kernel_voffset + mbi->mmap_length; mmap = (mmap_entry_t *)((uint32_t)mmap + mmap->size + sizeof(mmap->size))) { if (mmap->type == 2) { for (uint64_t i = 0; i < mmap->length; i += FRAME_SIZE) { paging_mark_reserved((mmap->addr + i) & 0xfffff000); } } } paging_finalize(); void *p1 = kmalloc(8); void *p2 = kmalloc(8); *((char *)p1) = 'a'; kprintf(INFO, "p1 @ 0x%x\n", (uint32_t)p1); kprintf(INFO, "p2 @ 0x%x\n", (uint32_t)p2); kfree(p2); kfree(p1); void *p3 = kmalloc(16); kprintf(INFO, "p3 @ 0x%x\n", (uint32_t)p3); uintptr_t phys; void *p4 = kmalloc_ap(0x1a0000, &phys); memset(p4, 0, 0x1a0000); *((char *)p4) = 'z'; kprintf(INFO, "p4 @ 0x%x phys = %x\n", (uint32_t)p4, phys); void *p5 = kmalloc(0x02); kprintf(INFO, "p5 @ 0x%x\n", (uint32_t)p5); kfree(p5); kfree(p4); kfree(p3); print_mmap(mbi); syscall_init(); scheduling_init(); keyboard_init(); process_t *proc1 = create_process("Process 1", 1); process_t *proc2 = create_process("Process 2", 1); process_t *proc3 = create_process("Process 3", 1); process_t *procs[] = { proc1, proc2, proc3 }; unsigned int k = 0; unsigned int off = 0; for (k = 0; k < 10; ++k) { if (!create_thread(procs[k % 3], func2, (void *)(off + 80*2), 1, 0, 0)) { kprintf(INFO, "Oups\n"); stop(); } if (!create_thread(procs[k % 3], func1, (void *)k, 1, 1, 0)) { kprintf(INFO, "Oups\n"); stop(); } off += 2; } //create_thread(proc1, func3, (void *)0, 1, 1, 1); k = 0; unsigned int i = 0; off = 0; for (;;) { uint16_t *video = (uint16_t *)(0xc00b8000 + 80); *video = (uint16_t)alph[i++ % sizeof(alph)] | 0x0f00; if (k % 1 == 0) { //set_pos(0, 23); //vga_print_dec(k); //kprintf(INFO, "mem used: %6x num threads:%3d \n", mem_used(kheap), get_num_threads()); } /* if (!create_thread(proc1, func2, (void *)(off + 80*2), 1, 0, 0)) { kprintf(INFO, "Oups\n"); break; } off += 2; off %= (60 * (25-2)); */ char c = keyboard_lastchar(); if (c == 'u') { create_thread(proc1, func1, (void *)5, 1, 1, 0); } else if (c == 'k') { create_thread(proc1, func2, (void *)off, 1, 0, 0); off += 2; } ++k; } serial_terminate(); stop(); }