int selfTest() { kprintln ("Running self test to ensure stability."); kprintln ("--> Testing heap functions"); void *p1 = kmalloc (15); void *p2 = kmalloc (12); kprintf ("--> Allocated memory: 0x%x and 0x%x\n", p1, p2); kfree (p1); kfree (p2); void *p3 = kmalloc (15); void *p4 = kmalloc (12); if (p3 != p1 || p2 != p4) { kprintln ("--> Freeing and allocating memory does not work!"); kprintf ("--> Allocated memory: 0x%x and 0x%x\n", p3, p4); return 1; } kfree (p1); kfree (p2); kprintln ("--> Heap test passed!"); return 0; }
void init (struct multiboot_info *mb_info, uint32_t kernel_esp) { // Clear screen cls(); // HAL-Services kprintln ("Booting up..."); detect_cpu(); InitSerial (115200, 0, 8); InitGlobalDescriptors (kernel_esp); InitInterruptDescriptors(); InitPit (CLOCKS_PER_SEC); InitPmm (mb_info); InitVmm (mb_info); kinit_heap(); #ifdef SELF_TEST if (selfTest() != 0) { kprintln ("Will not start up because of self test errors!"); while (1); } #endif // Erstes Modul ist unsere RAM-Disk InitRamdisk ( ( (struct multiboot_module *) mb_info->mbs_mods_addr)->mod_start); InitMultitasking(); // while(1); // kprintf((char*) ((struct multiboot_module*) // mb_info->mbs_mods_addr)->mod_start); InitBootDrivers(); //int32_test(); __asm ("sti"); for (;;); }
// int32 test void int32_test() { int y; regs16_t regs; cls(); kprintln ("Executing VGA graphics test. Press any key to continue."); // wait for key regs.ax = 0x0000; int32 (0x16, ®s); // switch to 320x200x256 graphics mode regs.ax = 0x0013; int32 (0x10, ®s); // full screen with blue color (1) memset ( (char *) 0xA0000, 1, (320 * 200)); // draw horizontal line from 100,80 to 100,240 in multiple colors for (y = 0; y < 200; y++) memset ( (char *) 0xA0000 + (y * 320 + 80), y, 160); // wait for key regs.ax = 0x0000; int32 (0x16, ®s); // switch to 80x25x16 text mode regs.ax = 0x0003; int32 (0x10, ®s); __asm ("cli"); }
/** * @brief Kill the current process * * The process passed in arg is moved in the terminated list and get the zombie * state. Waiting for his parent to read the return register. * The return register is set to the KILLED error code. * * @param pid the pid of the process to kill * @return an error code */ int32_t kkill_pcb(pcb * p) { pcb *s, *tmp; uint32_t i; pcb_set_ret(p, KILLED); pcb_set_state(p, OMG_ZOMBIE); pls_move_pcb(p, &plsterminate); /* * Now we can warn the supervisor * (if it's not the kernel) */ if (pcb_get_supervisor(p) != -1) { s = search_all_list(pcb_get_supervisor(p)); /* * Hey, the supervisor is waiting for me ! * Wake it up! */ if (pcb_get_state(s) == WAITING_PCB && pcb_get_waitfor(s) == pcb_get_pid(p)) { kwakeup_pcb(s); } } /* * Init adopt all the supervised process */ s = search_all_list(0); if (s == NULL) { /* * Ultra fatal error ! Init not here Oo */ kprintln ("OMG! No more init process Oo Computer will explode in 5..4..3..."); while (1); } for (i = 0; i < MAXPCB; i++) { pcb_set_supervised(s, pcb_get_supervised(p)[i]); tmp = search_all_list(pcb_get_supervised(p)[i]); if (tmp != NULL) pcb_set_supervisor(p, 0); } return OMGROXX; }
void test_kprogram() { int e; char c; kprintln("------------TEST MODULE KPROGRAM BEGIN------------"); kprint("Test search_prgm\t\t\t\t"); e = test_search_prgm(); if (e == OMGROXX) kprintln("OK"); else { kprint("FAIL: "); kprintln(itos(e, &c)); } kprintln("-------------TEST MODULE KPROGRAM END-------------"); kprintln(""); }
void kmain(){ cli("kmain()"); clear_screen(); kprintln("KERNEL STARTED"); if(mb_magic != 0x2BADB002){ /* Something went not according to specs. Print an error */ /* message and halt, but do *not* rely on the multiboot */ /* data structure. */ kprint("ERROR: Invalid multiboot magic number: "); kprintln_uint32(mb_magic); return; } kutil_init(); kprintln("kutil initialised"); memory_init(); kprintln("memory initialised"); interrupts_init(); add_interrupt_handler(0x80, (uint32_t) interrupt_handler); kprintln("interrupts initialised"); processes_init(); kprintln("processes initialised"); clear_screen(); add_process(&print_A); add_process(&print_B); //check_process_stack(); sti("kmain()"); halt(); }
void test_ksleep() { int e; char c; kprintln("--------------TEST MODULE SLEEP BEGIN-------------"); kprint("Test process_sleep\t\t\t\t"); e = test_process_sleep(); if (e == OMGROXX) kprintln("OK"); else { kprint("FAIL: "); kprintln(itos(e, &c)); } kprintln("--------------TEST MODULE KSLEEP END---------------\n"); pls_reset(&plsready); pls_reset(&plswaiting); }
void test_uart_fifo() { int e; char c; kprintln("-----------TEST MODULE UART FIFO BEGIN------------"); kprint("Test reset_fifo_buffer\t\t\t\t"); e = test_uart_reset_fifo(); if (e == OMGROXX) kprintln("OK"); else { kprint("FAIL: "); kprintln(itos(e, &c)); } kprint("Test push_fifo_buffer\t\t\t\t"); e = test_uart_push_fifo(); if (e == OMGROXX) kprintln("OK"); else { kprint("FAIL: "); kprintln(itos(e, &c)); } kprint("Test pop_fifo_buffer\t\t\t\t"); e = test_uart_pop_fifo(); if (e == OMGROXX) kprintln("OK"); else { kprint("FAIL: "); kprintln(itos(e, &c)); } kprintln("------------TEST MODULE UART FIFO END-------------"); kprintln(""); }
void interrupt_handler(void){ kprintln("Kernel interrupt"); }
/** * Call by the exeption to handle the syscall * \private */ void syscall_handler(registers_t * regs) { int32_t res = 0; int32_t syscall = regs->v_reg[0]; // code of the syscall switch (syscall) { case FOURCHETTE: res = create_proc(get_arg((char **) regs->a_reg[2], 0), regs->a_reg[0], regs->a_reg[1], (char **) regs->a_reg[2]); break; case PRINT: res = print_string((char *) regs->a_reg[0]); return; /* We save the good return value in the pcb */ case READ: res = read_string((char *) regs->a_reg[0], regs->a_reg[1]); return; /* We save the good return value in the pcb */ case FPRINT: if (regs->a_reg[0] == CONSOLE) kprint((char *) regs->a_reg[1]); else kmaltaprint8((char *) regs->a_reg[1]); break; case SLEEP: res = go_to_sleep(regs->a_reg[0]); break; case BLOCK: res = kblock(regs->a_reg[0], BLOCKED); break; case UNBLOCK: kwakeup(regs->a_reg[0]); break; case WAIT: res = waitfor(regs->a_reg[0], (int32_t *) regs->a_reg[1]); break; case SEND: res = send_msg(pcb_get_pid(get_current_pcb()), (msg_arg *) regs->a_reg[0]); break; case RECV: res = recv_msg(pcb_get_pid(get_current_pcb()), (msg_arg *) regs->a_reg[0]); if (res == NOTFOUND) go_to_sleep(((msg_arg *) regs->a_reg[0])->timeout); break; case PERROR: kperror((char *) regs->a_reg[0]); break; case GERROR: res = kgerror(); break; case SERROR: kserror(regs->a_reg[0]); break; case GETPINFO: res = get_pinfo(regs->a_reg[0], (pcbinfo *) regs->a_reg[1]); break; case GETPID: res = pcb_get_pid(get_current_pcb()); break; case GETALLPID: res = get_all_pid((int *) regs->a_reg[0]); break; case CHGPPRI: res = chg_ppri(regs->a_reg[0], regs->a_reg[1]); break; case KILL: res = kkill(regs->a_reg[0]); break; case EXIT: kexit(regs->a_reg[0]); break; default: kprintln("ERROR: Unknown syscall"); break; } // saves the return code regs->v_reg[0] = res; return; }
void checkForAdminMsg () { if (Serial.peek () == startAdminChar) { timeBeforeScript = millis (); Serial.read (); //DROP ADMIN START CHAR while (!Serial.available () > 0) { delay (10); } ackToken = Serial.read (); if (ackToken == 'g' || ackToken == 'p') { if (ackToken == 'g') { printScriptFromEEPROM (); } else if (ackToken == 'p') { while (!Serial.available () > 0) { delay (10); } ackToken = Serial.read (); Serial.print ("ack"); Serial.println (ackToken); } else { // error } } else { while (!Serial.available () > 0) { delay (10); } if (Serial.read () == startBAdminChar) { parsingAdmin = true; eepromPreviousIndex = eepromIndex; eepromIndex++; firstAdd = true; while (parsingAdmin) { if (Serial.available () > 0 && serialIndex < BUFFERSIZE) { inBytes[serialIndex] = Serial.read (); if (inBytes[serialIndex] == sepAdminChar) { inBytes[serialIndex] = '\0'; //saveScriptCommand(); if (!firstAdd) { save2Memory (sepAdminChar); } parseAndSaveAdminMsg (); flushAdminBuffer (); firstAdd = false; } else { if (inBytes[serialIndex] == endAdminChar) { parsingAdmin = false; inBytes[serialIndex] = '\0'; //saveScriptCommand(); if (!firstAdd) { save2Memory (sepAdminChar); } parseAndSaveAdminMsg (); flushAdminBuffer (); save2MemoryNoInc (eepromIndex, endAdminChar); eepromIndex = eepromPreviousIndex + 1; executeScriptFromEEPROM (); save2MemoryNoInc (eepromPreviousIndex, sepAdminChar); //CLOSE TRANSACTION //COMPRESS EEPROM IF NECESSARY , DON'T GO TO LIMIT if (eepromIndex > (EEPROM_MAX_SIZE - 100)) { //TODO REMOVE MAGIC NUMBER !!! compressEEPROM (); } kprint ("ms"); Serial.println (millis () - timeBeforeScript); kprint ("mem"); Serial.println (freeRam ()); kprint ("emem"); Serial.println (eepromIndex); kprint ("ack"); Serial.println (ackToken); firstAdd = false; } else { serialIndex++; } } } if (serialIndex >= BUFFERSIZE) { kprintln ("BFO"); flushAdminBuffer (); Serial.flush (); parsingAdmin = false; //KILL PARSING ADMIN } } } else { kprintln ("BAM"); flushAdminBuffer (); Serial.flush (); } } } else { processUserMessage (); } }