void INI::load_string(const chowstring & data, bool merge) { #ifndef CHOWDREN_AUTOSAVE_ON_CHANGE if (auto_save && changed) save_file(false); #endif if (!merge) reset(false); int e = ini_parse_string(data, _parse_handler, this); if (e != 0) { std::cout << "INI load failed with code " << e << std::endl; } }
EFI_STATUS efi_main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) { InitializeLib(ImageHandle, SystemTable); CallConstructors(); EFI_STATUS Status; const char16_t* searchdir = u"\\EFI\\ChaiOS\\"; if (Status = SetWorkingDirectory(searchdir)) printf(u"Error setting working directory: %s\r\n", getError(Status)); CHAIOS_BOOT_FILES* bootfile = nullptr; while (bootfile = iterateBootFiles(bootfile)) { if (bootfile->loadLocation != nullptr) continue; //Support in-memory images EFI_FILE* file = OpenFile(bootfile->fileName, "r"); if (!file) { printf(u"Error: could not open %s: %s\r\n", bootfile->fileName, getError(getErrno())); } UINT64 fileSize = GetFileSize(file); VOID* bootfilebuf = kmalloc(fileSize+1); UINTN read = ReadFile(bootfilebuf, 1, fileSize, file); if (read < fileSize) printf(u"Read %d bytes, failed\r\n", read); else printf(u"Successfully read %d bytes\r\n", read); //Boot file is now loaded into memory CloseFile(file); bootfile->loadLocation = bootfilebuf; bootfile->fileSize = fileSize; if (bootfile->bootType == CHAIOS_BOOT_CONFIGURATION) { //We need to parse this now. INI format ((char*)bootfilebuf)[fileSize] = '\0'; ini_parse_string((const char*)bootfilebuf, &bootini_handler, nullptr); } } //size_t value = GetIntegerInput(u"Enter scrolling lines configuration: "); //set_scrolllines(value); UINT32 AutoMode = IterateGraphicsMode(&match_config_resoultion); EFI_GRAPHICS_OUTPUT_MODE_INFORMATION* info; UINTN SizeOfInfo; if (AutoMode == UINT32_MAX) { if (!EFI_ERROR(GetGraphicsModeInfo(AutoMode, &info, &SizeOfInfo))) { IterateGraphicsMode(&print_graphics_mode); size_t value = GetIntegerInput(u"Enter boot graphics mode: "); SetGraphicsMode(value); AutoMode = value; } } else { SetGraphicsMode(AutoMode); } if (!EFI_ERROR(GetGraphicsModeInfo(AutoMode, &info, &SizeOfInfo))) { printf(u"Graphics mode %d: %dx%d\r\n", AutoMode, info->HorizontalResolution, info->VerticalResolution); } puts(u"ChaiOS 0.09 UEFI Loader\r\n"); int majorver = SystemTable->Hdr.Revision / (1 << 16); int minorver = SystemTable->Hdr.Revision % (1 << 16); printf(u"Firmware Vendor: %s, version: %d (UEFI:%d.%d)\r\n", SystemTable->FirmwareVendor, SystemTable->FirmwareRevision, majorver, minorver); //Read ACPI configuration tables //startup_acpi(SystemTable); //startup_multiprocessor(); const size_t EARLY_PAGE_STACK_SIZE = 1024*1024; EFI_PHYSICAL_ADDRESS earlyPhypageStack = 0; if (EFI_ERROR(SystemTable->BootServices->AllocatePages(AllocateAnyPages, EfiLoaderData, EARLY_PAGE_STACK_SIZE / EFI_PAGE_SIZE, &earlyPhypageStack))) { puts(u"Could not allocate page stack\r\n"); return EFI_OUT_OF_RESOURCES; } SystemTable->BootServices->SetWatchdogTimer(0, 0, 0, nullptr); PrepareExitBootServices(); EfiMemoryMap map; map.MemMapSize = map.MapKey = map.DescriptorSize = map.DescriptorVersion = 0; SystemTable->BootServices->GetMemoryMap(&map.MemMapSize, nullptr, &map.MapKey, &map.DescriptorSize, &map.DescriptorVersion); //Give a nice bit of room to spare (memory map can change) map.MemMapSize += 16 * map.DescriptorSize; map.memmap = (EFI_MEMORY_DESCRIPTOR*)kmalloc(map.MemMapSize); //Allocate a nice buffer SystemTable->BootServices->GetMemoryMap(&map.MemMapSize, map.memmap, &map.MapKey, &map.DescriptorSize, &map.DescriptorVersion); printf(u"EFI Memory Map: Descriptor size %d\n", map.DescriptorSize); #if 0 //Dump the UEFI memory map to a file for testing EFI_FILE* file = OpenFile(u"efimap.dat", "w"); if (!file) { printf(u"Error: could not open %s: %s\r\n", u"efimap.dat", getError(getErrno())); } WriteFile(map.memmap, 1, map.MemMapSize, file); CloseFile(file); #endif if (EFI_ERROR(Status = SystemTable->BootServices->ExitBootServices(ImageHandle, map.MapKey))) { printf(u"Failed to exit boot services: %s\r\n", getError(Status)); UINTN index; SystemTable->BootServices->WaitForEvent(1, &SystemTable->ConIn->WaitForKey, &index); return EFI_SUCCESS; } //We need to take control of the hardware now. Setup basic memory management setLiballocAllocator(nullptr, nullptr); InitializePmmngr(map, (void*)earlyPhypageStack, EARLY_PAGE_STACK_SIZE); puts(u"Physical memory manager intialized\n"); arch_initialize_paging(); puts(u"Paging initialized\n"); setLiballocAllocator(&arch_allocate_pages, &arch_free_pages); //Now load the OS! bootfile = nullptr; kimage_entry kentry = nullptr; KLOAD_HANDLE kernel = NULL; while (bootfile = iterateBootFiles(bootfile)) { printf(u"Boot file: %s @ %x, length %d, type %d\n", bootfile->fileName, bootfile->loadLocation, bootfile->fileSize, bootfile->bootType); if (!bootfile->loadLocation) continue; if (bootfile->bootType == CHAIOS_DLL) { KLOAD_HANDLE dll = LoadImage(bootfile->loadLocation, bootfile->fileName); if (GetProcAddress(dll, "memcpy")) { set_memcpy((memcpy_proc)GetProcAddress(dll, "memcpy")); } } else if (bootfile->bootType == CHAIOS_KERNEL) { kernel = LoadImage(bootfile->loadLocation, bootfile->fileName); kentry = GetEntryPoint(kernel); } } size_t kstacksize = GetStackSize(kernel); if (!paging_map(stackaddr, PADDR_T_MAX, kstacksize, PAGE_ATTRIBUTE_WRITABLE)) { puts(u"Error: could not allocate kernel stack\n"); while (1); } KERNEL_BOOT_INFO bootinfo; fill_pmmngr_info(bootinfo.pmmngr_info); fill_arch_paging_info(bootinfo.paging_info); fill_modloader_info(bootinfo.modloader_info); get_framebuffer_info(bootinfo.fbinfo); populate_kterm_info(bootinfo.kterm_status); bootinfo.efi_system_table = SystemTable; bootinfo.memory_map = ↦ bootinfo.loaded_files = &bootfiles; bootinfo.boottype = CHAIOS_BOOT_TYPE_UEFI; bootinfo.printf_proc = &printf; bootinfo.puts_proc = &puts; printf(u"Success: Kernel entry point at %x, stack at %x, length %x\n", kentry, stackaddr, kstacksize); call_kernel(&bootinfo, kentry, stackaddr, kstacksize); puts(u"Kernel returned"); while (1); }
void INI::load_file(const chowstring & fn, bool read_only, bool merge, bool overwrite) { chowstring new_filename = convert_path(fn); #ifdef CHOWDREN_CACHE_INI if (new_filename == filename) return; #endif #ifndef CHOWDREN_AUTOSAVE_ON_CHANGE if (auto_save && changed) save_file(false); #endif this->read_only = read_only; filename = new_filename; #ifdef CHOWDREN_USE_BLOWFISH_CACHE const chowstring & cache = BlowfishObject::get_cache(filename); if (!cache.empty()) { std::cout << "Using Blowfish cache for " << filename << std::endl; load_string(cache, merge); return; } #endif #ifdef CHOWDREN_CACHE_INI chowstring cache_key = filename; to_lower(cache_key); data = &ini_cache[cache_key]; is_global = true; if (!data->empty()) return; #else if (!merge) reset(false); #endif std::cout << "Loading " << filename << " (" << get_name() << ")" << std::endl; platform_create_directories(get_path_dirname(filename)); chowstring new_data; if (!encrypt_key.empty() || use_compression) { bool decompressed = false; if (use_compression) { if (decompress_huffman(filename.c_str(), new_data)) decompressed = true; } if (!use_compression || !decompressed) { if (!read_file(filename.c_str(), new_data)) return; } if (!encrypt_key.empty()) { encrypt_ini_data(new_data, encrypt_key); } } else { if (!read_file(filename.c_str(), new_data)) return; } int e = ini_parse_string(new_data, _parse_handler, this); if (e != 0) { std::cout << "INI load failed (" << filename << ") with code " << e << std::endl; } }