unsigned int memtest(multiboot_info_t* mbd, unsigned int magic) { magic = (int) magic; terminal_writestring(MULTIBOOT_TEST); if (CHECK_BIT(mbd->flags, 0)) { vgatestok(); terminal_writestring(MEMORY_MAP_TEST); if (CHECK_BIT(mbd->flags, 6)) { vgatestok(); terminal_printf("\nLower memory : %d KB\n", mbd->mem_lower); terminal_printf("Upper memory : %d KB\n\n", mbd->mem_upper); } else { vgatestko(); return (1); } return (0); } vgatestko(); return (1); }
uint64_t load_kernel(uint8_t *pack_start, uint8_t *pack_end) { terminal_printf("Packed kernel start: 0x%p; size: %u\n", pack_start, pack_end - pack_start); Elf64_Ehdr_t *ehdr = (Elf64_Ehdr_t*) pack_start; terminal_printf("entry: 0x%l; phoff: 0x%l\n", ehdr->e_entry, ehdr->e_phoff); Elf64_Phdr_t *phdr = (Elf64_Phdr_t*) (pack_start + ehdr->e_phoff); for (int i = 0; i < ehdr->e_phnum; i++, phdr++) { if (phdr->p_type != ELF64_PT_LOAD) continue; terminal_printf("+ section [%c%c%c]:0x%l[0x%l] va:0x%l[0x%l]\n", (phdr->p_flags & ELF64_PF_X) ? 'X' : '-', (phdr->p_flags & ELF64_PF_W) ? 'W' : '-', (phdr->p_flags & ELF64_PF_R) ? 'R' : '-', phdr->p_offset, phdr->p_filesz, phdr->p_vaddr, phdr->p_memsz); for (uint64_t ppos = 0; ppos < phdr->p_memsz; ppos += PAGE_SIZE) { uint64_t vaddr = phdr->p_vaddr + ppos; terminal_printf(" trying to alloc and map %l\n", vaddr); uint32_t pp = phys_alloc_to_virt4k(vaddr, !!(phdr->p_flags & ELF64_PF_W), !!(phdr->p_flags & ELF64_PF_X)); if (ppos < phdr->p_memsz) { uint32_t csize = (phdr->p_memsz - ppos) > PAGE_SIZE ? PAGE_SIZE : (phdr->p_memsz - ppos); memcpy((void*) pp, (void*)(pack_start + phdr->p_offset + ppos), csize); } } } return ehdr->e_entry; }
void greet() { const char* str = "Hallo Welt!"; hexdump(str, strlen(str)); terminal_printf("kernel end: %x\n", (int)end); char *page = kalloc(); terminal_printf("allocated page: %x\n", page); page = kalloc(); terminal_printf("allocated page: %x\n", page); }
bool process_multiboot(uint32_t uMagic, multiboot_info_t *pMultiboot, uint32_t *total_memory, multiboot_memory_map_t **multiboot_mmap, uint32_t *mmap_lenght) { bool magic_match = uMagic == MULTIBOOT_BOOTLOADER_MAGIC; print_requirement("Multiboot magic match", magic_match); if (!magic_match) { terminal_printf("Multiboot magic not correct 0x%p != 0x%p\n", uMagic, MULTIBOOT_BOOTLOADER_MAGIC); return false; } bool have_meminfo = pMultiboot->flags & MULTIBOOT_INFO_MEMORY; bool have_memmap = pMultiboot->flags & MULTIBOOT_INFO_MEM_MAP; print_requirement("Multiboot memory info", have_meminfo); print_requirement("Multiboot memory map", have_memmap); terminal_printf("Multiboot struct: 0x%p; magic: 0x%p\n", pMultiboot, uMagic); if (magic_match) { terminal_printf("Multiboot magic correct. Flags: b%b\n", pMultiboot->flags); } if (have_meminfo) { uint32_t memtotal = pMultiboot->mem_upper ? (pMultiboot->mem_upper + 1024) : pMultiboot->mem_lower; *total_memory = memtotal; terminal_printf("mem_lower = %uKB, mem_upper = %uKB (%uMb), total: %uMb(%ukB)\n", pMultiboot->mem_lower, pMultiboot->mem_upper, pMultiboot->mem_upper / 1024, memtotal / 1024, memtotal); } else return false; if (have_memmap) { multiboot_memory_map_t *mmap = (multiboot_memory_map_t*)pMultiboot->mmap_addr; uint32_t mmapEnd = pMultiboot->mmap_addr + pMultiboot->mmap_length; *multiboot_mmap = mmap; *mmap_lenght = pMultiboot->mmap_length; terminal_printf ("Multiboot mmap_addr: 0x%p, mmap_length: 0x%x\nMemmap:\n", pMultiboot->mmap_addr, pMultiboot->mmap_length); while((uint32_t)mmap < mmapEnd) { terminal_printf(" (0x%p[%u]) addr: 0x%l (%x:%x), len: 0x%l (%x:%x), type: 0x%x\n", mmap, mmap->size, mmap->addr, (uint32_t)(mmap->addr >> 32), (uint32_t) mmap->addr, mmap->len, (uint32_t)(mmap->len >> 32), (uint32_t) mmap->len, mmap->type); mmap = (multiboot_memory_map_t*)((uint32_t)mmap + mmap->size + sizeof(mmap->size)); } } return true; }
bool init_screen() { terminal_initialize(); terminal_setcolor(make_color(FGCOLOR, BGCOLOR)); terminal_clear(); terminal_printf("Welcome to "); terminal_setcolor(make_color(COLOR_MAGENTA, BGCOLOR)); terminal_printf("%s", __KERNEL_NAME); terminal_setcolor(make_color(FGCOLOR, BGCOLOR)); terminal_printf(" multiboot32 => kernel loader\n"); return true; }
int cmd_logout(int argc, char **argv) { static struct option long_options[] = { {"force", no_argument, NULL, 'f'}, {0, 0, 0, 0} }; int option; int option_index; bool force = false; struct session *session = NULL; unsigned char key[KDF_HASH_LEN]; while ((option = getopt_long(argc, argv, "f", long_options, &option_index)) != -1) { switch (option) { case 'f': force = true; break; case '?': default: die_usage(cmd_logout_usage); } } if (optind < argc) die_usage(cmd_logout_usage); if (!config_exists("verify")) die("Not currently logged in."); if (!force && !ask_yes_no(true, "Are you sure you would like to log out?")) { terminal_printf(TERMINAL_FG_YELLOW TERMINAL_BOLD "Log out" TERMINAL_RESET ": aborted.\n"); return 1; } init_all(0, key, &session, NULL); if (!config_unlink("verify") || !config_unlink("username") || !config_unlink("session_sessionid") || !config_unlink("iterations")) die_errno("could not log out."); config_unlink("blob"); config_unlink("session_token"); config_unlink("session_uid"); config_unlink("session_privatekey"); config_unlink("plaintext_key"); agent_kill(); upload_queue_kill(); lastpass_logout(session); terminal_printf(TERMINAL_FG_YELLOW TERMINAL_BOLD "Log out" TERMINAL_RESET ": complete.\n"); return 0; }
void init_kernel() { terminal_initialize(); init_serial(COM1); terminal_enable_serial_echo(COM1); terminal_printf("fOS version %s\n\n\n", KERNEL_VERSION); kinit(end + 4096, end + 4096 + (100 * 4096)); init_gdt(); load_gdt(); load_idt(); load_isrs(); irq_install(); asm volatile ( "sti" ); timer_install(); sleep(1); keyboard_install(); init_paging(); switch_to_paging(); }
void Alo_Main(multiboot_data *multibootdata) { HAL_init(multibootdata); terminal_putstring("Hello to Alo 2!\n"); terminal_putstring(" Just testing newlines....\n"); terminal_printf("-13 when put through itoa is: %d.", -13); terminal_printf("My name is %s.", "Alex"); terminal_printf("Today is %s %d, %d. It is a %s. It is %d:%d:%d military time.", GetMonth(), GetDayInMonth(), GetYear(), GetWeekDay(), GetHour(), GetMinute(), GetSecond()); /*testtimer.limit = 100; testtimer.func = OneSecondHandler; secondtimer.limit = 200; secondtimer.func = TheResponse; Timer_Register_Timer(&testtimer); Timer_Register_Timer(&secondtimer); */ /* int test = 8/(6 - (3 * 2)); */ };
void monitor_process_key_press(uint8_t scancode) { struct terminal_position p = terminal_position(); uint8_t code = scancodes[scancode]; const char *command = NULL; terminal_set_position(command_line_position); if (scancode == KEY_BACKSPACE && command_line_position.column > COMMAND_LINE_PROMPT_LEN) { command_line_position.column--; terminal_set_position(command_line_position); terminal_put(' '); } else if (code == '\n') { command = terminal_read_command(COMMAND_LINE_PROMPT_LEN); assert(command != NULL); terminal_clear_line(); } else if (code != 0) { if (command_line_position.column < TERMINAL_COL_COUNT-1) { command_line_position.column++; terminal_put(code); } } if (command != NULL) { // redraw command line prompt terminal_printf("%s", COMMAND_LINE_PROMPT); command_line_position = terminal_position(); } terminal_set_position(p); if (command != NULL) monitor_process_command(command); }
static void help(void) { terminal_printf("Usage:\n"); printf(" %s {--help|--version}\n", ARGV[0]); for (size_t i = 0; i < ARRAY_SIZE(commands); ++i) printf(" %s %s\n", ARGV[0], commands[i].usage); }
void kernel_main() { terminal_cls(COLOR_LIGHT_BLUE); terminal_setcolor(make_color(COLOR_WHITE, COLOR_LIGHT_BLUE)); /* Since there is no support for newlines in terminal_putchar yet, \n will produce some VGA specific character instead. This is normal. */ terminal_writestring("Hello, kernel World!\n"); terminal_printf("This is the base string terminal system !\n"); if(apros_setup_gdt() > 0) terminal_printf("GDT correctly setted !\n"); if(apros_setup_idt()) terminal_printf("IDT correctly setted ! \n"); for(;;) continue; }
void page_decref(struct page *p) { assert(p->ref > 0); p->ref--; terminal_printf("decref page %p, refs: %d\n", p, p->ref); if (p->ref == 0) page_free(p); }
int cmd_status(int argc, char **argv) { unsigned char key[KDF_HASH_LEN]; static struct option long_options[] = { {"quiet", no_argument, NULL, 'q'}, {"color", required_argument, NULL, 'C'}, {0, 0, 0, 0} }; int option; int option_index; bool quiet = false; _cleanup_free_ char *username = NULL; while ((option = getopt_long(argc, argv, "q", long_options, &option_index)) != -1) { switch (option) { case 'q': quiet = true; break; case 'C': terminal_set_color_mode( parse_color_mode_string(optarg)); break; case '?': default: die_usage(cmd_status_usage); } } if (!agent_ask(key)) { if(!quiet) { terminal_printf(TERMINAL_FG_RED TERMINAL_BOLD "Not logged in" TERMINAL_RESET ".\n"); } return 1; } else { if(!quiet) { username = config_read_string("username"); terminal_printf(TERMINAL_FG_GREEN TERMINAL_BOLD "Logged in" TERMINAL_RESET " as " TERMINAL_UNDERLINE "%s" TERMINAL_RESET ".\n", username); } return 0; } }
void monitor_init(void) { command_line_position.row = TERMINAL_ROW_COUNT; command_line_position.column = 0; struct terminal_position p = terminal_position(); terminal_set_position(command_line_position); terminal_printf("%s", COMMAND_LINE_PROMPT); command_line_position = terminal_position(); terminal_set_position(p); }
void fault_handler(struct idt_info* ptr) { if (ptr->code < 32) { die("fault_handler:%s, code=%d, error=%d\n", exception_messages[ptr->code], ptr->code, ptr->error); } switch (ptr->code) { default: { terminal_printf("defualt isr handler:code=%d, error=%d\n", ptr->code, ptr->error); } } }
void print_requirement(const char *text, bool have) { terminal_setcolor(make_color(FGCOLOR, BGCOLOR)); terminal_printf(" - %s ", text); size_t textlen = strlen(text); for (size_t pneed = textlen; pneed < 32; pneed++) { terminal_putchar('.'); } terminal_putchar('['); if (have) { terminal_setcolor(make_color(COLOR_GREEN, BGCOLOR)); terminal_writestring("OK"); } else { terminal_setcolor(make_color(COLOR_RED, BGCOLOR)); terminal_writestring("FAIL"); } terminal_setcolor(make_color(FGCOLOR, BGCOLOR)); terminal_writestring("]\n"); }
bool process_cpu_features() { uint32_t cpuidmax = __get_cpuid_max(0, 0); bool have_cpuid = cpuidmax != 0; print_requirement("CPUID instruction", have_cpuid); if (!have_cpuid) return false; uint32_t a, b, c, d; uint32_t cpuidext = __get_cpuid(0x80000001, &a, &b, &c, &d); bool have_ext_cpuid = cpuidext != 0; print_requirement("CPUID 0x80000001", have_ext_cpuid); if (!have_ext_cpuid) return false; bool have_64bit = d & (1 << 29); print_requirement("64 bit longmode support", have_64bit); terminal_printf("cpuid[0x80000001] edx:%p ecx:%p\n", d, c); return have_64bit; }
void AnimateDamage(int x, int y, int damage) { std::ostringstream ss; ss << damage; std::string s = ss.str(); int n_steps = duration * fps; float angle_delta = 2.0f * pi / n_steps; terminal_layer(animation_layer); for (int i=0; i<n_steps; i++) { if (terminal_has_input()) break; terminal_clear_area(0, 0, terminal_state(TK_WIDTH), terminal_state(TK_HEIGHT)); float dx = std::sin(i*angle_delta) * radius * terminal_state(TK_CELL_WIDTH) + i*2; float dy = -2.0f * radius * terminal_state(TK_CELL_WIDTH) / n_steps * i - terminal_state(TK_CELL_HEIGHT)/2; terminal_color(color_from_argb(255/n_steps*(n_steps-i), 255, 64, 0)); terminal_printf(x, y, "[offset=%dx%d]%s", (int)dx, (int)dy, s.c_str()); terminal_refresh(); terminal_delay(1000/fps); } terminal_color("white"); }
int cmd_login(int argc, char **argv) { static struct option long_options[] = { {"trust", no_argument, NULL, 't'}, {"plaintext-key", no_argument, NULL, 'P'}, {"force", no_argument, NULL, 'f'}, {"color", required_argument, NULL, 'C'}, {0, 0, 0, 0} }; int option; int option_index; bool trust = false; bool plaintext_key = false; bool force = false; char *username; _cleanup_free_ char *error = NULL; _cleanup_free_ char *password = NULL; int iterations; struct session *session; unsigned char key[KDF_HASH_LEN]; char hex[KDF_HEX_LEN]; while ((option = getopt_long(argc, argv, "f", long_options, &option_index)) != -1) { switch (option) { case 't': trust = true; break; case 'P': plaintext_key = true; break; case 'f': force = true; break; case 'C': terminal_set_color_mode( parse_color_mode_string(optarg)); break; case '?': default: die_usage(cmd_login_usage); } } if (argc - optind != 1) die_usage(cmd_login_usage); if (!force && plaintext_key && !ask_yes_no(false, "You have used the --plaintext-key option. This option will greatly reduce the security of your passwords. You are advised, instead, to use the agent, whose timeout can be disabled by settting LPASS_AGENT_TIMEOUT=0. Are you sure you would like to do this?")) die("Login aborted. Try again without --plaintext-key."); username = argv[optind]; iterations = lastpass_iterations(username); if (!iterations) die("Unable to fetch iteration count. Check your internet connection and be sure your username is valid."); do { free(password); password = password_prompt("Master Password", error, "Please enter the LastPass master password for <%s>.", username); if (!password) die("Failed to enter correct password."); kdf_login_key(username, password, iterations, hex); kdf_decryption_key(username, password, iterations, key); free(error); error = NULL; session = lastpass_login(username, hex, key, iterations, &error, trust); } while (!session_is_valid(session)); config_unlink("plaintext_key"); if (plaintext_key) config_write_buffer("plaintext_key", (char *)key, KDF_HASH_LEN); agent_save(username, iterations, key); session_save(session, key); session_free(session); session = NULL; terminal_printf(TERMINAL_FG_GREEN TERMINAL_BOLD "Success" TERMINAL_RESET ": Logged in as " TERMINAL_UNDERLINE "%s" TERMINAL_RESET ".\n", username); return 0; }
void panic(const char* msg) { terminal_printf("KERNEL PANIC: %s.", msg); __asm__ __volatile__("cli"); /* Disable interrupts */ for (;;) ; };
void OneSecondHandler(interrupt_stackstate *lstack) { terminal_printf("About one second has passed."); };
void TheResponse(interrupt_stackstate *lstack) { terminal_printf("About two seconds have passed."); };
void BasicOutput() { terminal_options("title=BearLibTerminal demo: output facilities"); terminal_options("font.name=default; font.supplement=Media/Omni/supplement-runic.png"); terminal_blending(BLENDING_ADDITIVE); terminal_color(COLOR_WHITE); terminal_clear(); // Simple output with postformatting terminal_printf(1, 1, "[color=gray]1. Most basic:[/color] ABC abc"); // Wide color range int n = terminal_printf(1, 3, "[color=gray]2. Colors: "); const char long_word[] = "Antidisestablishmentarianism"; const size_t long_word_length = sizeof(long_word)-1; for ( size_t i = 0; i < long_word_length; i++ ) { float factor = float(i)/long_word_length; int red = (1.0f - factor) * 255; int green = factor * 255; terminal_color(color_from_argb(255, red, green, 0)); terminal_put(n+1+i, 3, long_word[i]); } terminal_color(color_from_name("white")); // Tile backgrounds terminal_printf(1, 5, "[color=gray]3. Backgrounds: [color=black][bkcolor=gray] grey [/bkcolor] [bkcolor=red] red "); // Simple unicode output terminal_printf(1, 7, "[color=gray]4. Unicode:[/color] Latin Русский Ελληνικά"); // Composite (overlay) tiles n = terminal_printf(1, 9, "[color=gray]5. Tile overlay: "); terminal_printf(n+1, 9, "a+ = a, a+ = a, a vs. [color=red]ä"); terminal_printf(n+1, 9, "[color=red] / / ▔ ▔ [/color]a"); // Unicode Box Drawing characters terminal_printf(1, 11, "[color=gray]6. Box drawing:"); const char* box_lines[] = { " ┌──┬───┐ ╔═════╗ ", " ┌───┬─┘ │ ├──┐ ╟──┐ ║ ", " └─┐ └─┐ ├───┘ │ ║ └──╢ ", " └───┴──┴──────┘ ╚═════╝ " }; for ( size_t i = 0; i < sizeof(box_lines)/sizeof(box_lines[i]); i++ ) { terminal_printf(1, 12+i, "%s", box_lines[i]); } // Box drawing + overlay application terminal_printf(1, 17, "[color=gray]7. Box drawing + overlay:"); terminal_color(0xFF006000); for ( int y = 0; y < 6; y++ ) { for ( int x = 0; x < 19; x++ ) { terminal_put(1+x, 18+y, 'A'+(x+y)%26); } } DrawOverlayRectangle(3, 19, 15, 4, 0xFFFFFFFF, 0xA0909090); terminal_printf(4, 20, "[color=white]Itym:\nHeavy draggon"); terminal_printf(40, 17, "[color=gray]8. Font supplement:"); terminal_printf(40, 19, "fire ([color=red][uE001][/color]) - water ([color=lighter blue][uE004][/color]) - earth ([color=dark green][uE00F][/color])"); terminal_printf(40, 20, "\uE001\uE002\uE003, \uE004\uE005\uE006\uE007\uE008! \uE009\uE00A\uE00B \uE00C \uE00D\uE00E\uE00F\uE010."); terminal_refresh(); int key = 0; do { key = terminal_get(); } while ( key != VK_CLOSE && key != VK_ESCAPE ); }
void panic(const char* msg) { terminal_printf("KERNEL PANIC: %s", msg); interrupts_disable(); hang(); };
void handler_sigint (int sig) { if (builtin_waiting) { terminal_printf("\n"); // Retour a la ligne après le symbole de controle builtin_waiting = false; } }
static void version(void) { terminal_printf("LastPass CLI v" LASTPASS_CLI_VERSION "\n"); }