/* testing */ void rtl8139_test(void) { net_buf_t* nb_head; net_buf_t* nb_tail; net_buf_t* nb_pos; rtl8139_dev_t* dev; TRACE_ENTRY(); dev = (rtl8139_dev_t*)g_device->priv; while (1) { /* icmp_ping(g_device, NET_REMOTE_ADDR); */ cpu_hlt(); #if 0 cpu_cli(); arp_print_table(); cpu_sti(); #endif } while (1) { nb_head = null; nb_tail = null; cpu_hlt(); /* safely get the net buffers */ cpu_cli(); if (!is_null(dev->nb_head)) { for (nb_pos = dev->nb_head; nb_pos->next; nb_pos = nb_pos->next) ; if (!is_null(nb_tail)) nb_tail->next = dev->nb_head; else nb_head = dev->nb_head; nb_tail = nb_pos; } dev->nb_head = null; cpu_sti(); /* print and release net buffers */ while (nb_head) { nb_pos = nb_head; nb_head = nb_head->next; /* hexdump(nb_pos->buf, nb_pos->size); */ mm_free(nb_pos->buf); mm_free(nb_pos); } arp_print_table(); } }
/* * public, thread-safe interface to read a single key from the buffer * returns 0 on success and 1 on empty buffer. */ int kbd_read(uint16_t *key) { int ret; uint64_t flags; flags = cpu_get_flags(); cpu_cli(); ret = kbd_buf_pop(key); cpu_set_flags(flags); return ret; }
error_t sched_start(void) { if (g_sched.is_started == true) return ERROR_FAILURE; cpu_cli(); g_sched.is_started = true; timer_initialize(SCHED_TIMER_FREQ); cpu_sti(); return ERROR_SUCCESS; }
error_t sched_yield(void) { struct task* first; struct task* pos; struct task* ready; bool_t is_done; cpu_cli(); task_set_timeslice(g_current_task, 0); /* find next ready task */ is_done = false; ready = NULL; first = g_current_task->next; pos = g_current_task->next; while (is_done == false) { if (pos->state == TASK_STATE_READY) { ready = pos; ready->timeslice = TASK_SCHED_TIMESLICE; is_done = true; } else { pos = pos->next; if (pos == first) is_done = true; } } /* switch to ready */ if (ready != NULL) { if (ready->timeslice == 0) task_set_timeslice(ready, TASK_SCHED_TIMESLICE); task_switch(g_current_task, ready); } else { cpu_sti(); } return ERROR_SUCCESS; }
void kernel_main(unsigned long magic, unsigned long addr) { multiboot_info_t *mbi; if (magic != MULTIBOOT_BOOTLOADER_MAGIC) return; mbi = (multiboot_info_t*)addr; /* kernel init */ serial_init(DEBUG_SERIAL_PORT, DEBUG_SERIAL_SPEED, UART_8BITS_WORD, UART_NO_PARITY, UART_1_STOP_BIT); cls(); cpu_cli(); printf("[x] interrupts disabled\n"); gdt_initialize(); printf("[x] gdt initialized\n"); idt_initialize(); printf("[x] idt initialized\n"); breakpoint_initialize(); #if defined(USE_APIC) apic_initialize(); serial_printl("[x] apic initialized\n"); #else pic_initialize(); serial_printl("[x] pic initialized\n"); #endif /* USE_APIC */ /* initialize the kernel */ { kernel_init(mbi); } /* memory initialization */ { phys_init(mbi); phys_debug(); /* vm_init(); */ /* unit_test_vm(); */ /* cpu_hlt(); */ } #if defined(USE_PCI) pci_initialize(); pci_list(); #endif cpu_sti(); #if defined(USE_TASK) { /* subsystems */ event_initialize(); sched_initialize(); task_initialize(); /* tasks */ idle_initialize(); muksh_initialize(); net_initialize(); /* task_test(); */ /* start scheduling */ sched_start(); } #endif /* endless loop */ serial_printl("[?] kernel loop\n"); while (1) { serial_printl("k"); cpu_hlt(); } }