forked from lolo859/vystem
Vystem 0.2
This commit is contained in:
394
shelter/main.c
394
shelter/main.c
@@ -3,18 +3,38 @@
|
||||
#include "kernel/test.h"
|
||||
#include "kernel/log.h"
|
||||
#include "kernel/conf.h"
|
||||
#include "kernel/efifb.h"
|
||||
#include "cpu/tsc.h"
|
||||
#include "cpu/serial.h"
|
||||
#include "memory/page.h"
|
||||
#include "memory/slab.h"
|
||||
#include "memory/pba.h"
|
||||
#include "memory/heap.h"
|
||||
#include "memory/pez/radix.h"
|
||||
#include "memory/pez/pez.h"
|
||||
#include "cpu/ap.h"
|
||||
#include "memory/memory.h"
|
||||
#include "irq/tss.h"
|
||||
#include "irq/gdt.h"
|
||||
#include "irq/idt.h"
|
||||
#include "irq/gsi.h"
|
||||
#include "devs/acpi.h"
|
||||
#include "devs/acpi_tables/madt.h"
|
||||
#include "devs/apic/lapic.h"
|
||||
#include "devs/apic/ioapic.h"
|
||||
#include "devs/input/kbd.h"
|
||||
#include "devs/input/ps2.h"
|
||||
char temp[256];
|
||||
int main() {
|
||||
sh_tsc_init_tsc();
|
||||
sh_ap_CPU_STRUCT this_cpu_struct;
|
||||
this_cpu_struct.c_entry_point_stack_top_va=0;
|
||||
this_cpu_struct.lapic_id=SH_UINT32_MAX;
|
||||
this_cpu_struct.tss_selector=0;
|
||||
sh_ap_PER_CPU per_cpu;
|
||||
per_cpu.cpu_id=0;
|
||||
per_cpu.bytes_outputed=0;
|
||||
per_cpu.timer_state=SH_FALSE;
|
||||
per_cpu.temp_buffer=temp;
|
||||
per_cpu.temp_buffer_size=256;
|
||||
this_cpu_struct.per_cpu=(&per_cpu);
|
||||
sh_smp_write_gs_base((sh_uint64)&this_cpu_struct);
|
||||
sh_log_string("\n---------------------------\n\n");
|
||||
sh_log_log("Shelter v0.1",SH_LOG_SOURCE_MAIN);
|
||||
sh_log_log("Shelter v0.2",SH_LOG_SOURCE_MAIN);
|
||||
sh_conf_BOOT_CONFIG *boot_config=SH_NULLPTR;
|
||||
SH_STATUS status=sh_conf_get_boot_config(&boot_config);
|
||||
if (status==SH_STATUS_INVALID_SIGNATURE) {
|
||||
@@ -42,219 +62,203 @@ int main() {
|
||||
sh_log_uint64((sh_uint64)sh_log_get_log_level());
|
||||
sh_log_string("\n");
|
||||
sh_log_flog(SH_LOG_SOURCE_MAIN,"Set logging ring buffer to %2u pages.\n",boot_config->log_ring_size);
|
||||
sh_log_log("Trying to obtain memory map...",SH_LOG_SOURCE_MAIN);
|
||||
status=sh_page_copy_memory_map();
|
||||
sh_memory_MEMORY_SERVICES memory_services;
|
||||
status=sh_memory_init_subsystem(boot_config,&memory_services);
|
||||
if (sh_status_error(status)) {
|
||||
sh_log_fatal("Couldn't initialize memory subsystem.",SH_LOG_SOURCE_MAIN);
|
||||
while (SH_TRUE) {};
|
||||
}
|
||||
sh_log_log("Successfully initialized memory subsystem.",SH_LOG_SOURCE_MAIN);
|
||||
sh_efifb_set_bar(1);
|
||||
sh_tss_TSS tss;
|
||||
status=sh_tss_fill_tss(&tss);
|
||||
if (sh_status_error(status)) {
|
||||
sh_log_ffatal(SH_LOG_SOURCE_MAIN,"Couldn't setup TSS structure. Status: %8s",status);
|
||||
while (1) {};
|
||||
}
|
||||
sh_log_log("Successfully initialized TSS structure.",SH_LOG_SOURCE_MAIN);
|
||||
sh_gdt_GDT gdt;
|
||||
status=sh_gdt_fill_gdt(&tss,&gdt);
|
||||
if (sh_status_error(status)) {
|
||||
sh_log_fatal("Couldn't setup GDT structure.",SH_LOG_SOURCE_MAIN);
|
||||
while (1) {};
|
||||
}
|
||||
sh_gdt_load_gdtr(&gdt);
|
||||
sh_gdt_reload_registers();
|
||||
sh_smp_write_gs_base((sh_uint64)&this_cpu_struct);
|
||||
sh_log_log("Successfully loaded GDT.",SH_LOG_SOURCE_MAIN);
|
||||
sh_tss_load_tr(&tss);
|
||||
sh_log_log("Successfully loaded TSS.",SH_LOG_SOURCE_MAIN);
|
||||
sh_idt_IDT idt;
|
||||
status=sh_idt_fill_idt(&idt);
|
||||
if (sh_status_error(status)) {
|
||||
sh_log_fatal("Couldn't setup IDT structure.",SH_LOG_SOURCE_MAIN);
|
||||
while (1) {};
|
||||
}
|
||||
sh_log_log("Successfully initialized IDT structure.",SH_LOG_SOURCE_MAIN);
|
||||
sh_idt_load_idtr(&idt);
|
||||
sh_log_log("Successfully loaded IDT.",SH_LOG_SOURCE_MAIN);
|
||||
sh_efifb_set_bar(2);
|
||||
sh_log_log("IDT enabled. Parsing ACPI RSDP...",SH_LOG_SOURCE_MAIN);
|
||||
sh_apci_ACPI_POINTERS_ROOT acpi_pointers_root;
|
||||
status=sh_acpi_parse_rsdp(boot_config->acpi_rsdp,boot_config->acpi_ver,&acpi_pointers_root);
|
||||
if (sh_status_error(status)) {
|
||||
sh_log_ffatal(SH_LOG_SOURCE_MAIN,"Couldn't parse ACPI RSDP. Error code: %8s",status);
|
||||
while (1) {};
|
||||
}
|
||||
sh_log_log("Parsed ACPI RSDP.",SH_LOG_SOURCE_MAIN);
|
||||
if (acpi_pointers_root.xsdt==0) {
|
||||
sh_log_log("ACPI v1 is being used. It's not supported for the moment.",SH_LOG_SOURCE_MAIN);
|
||||
while (1) {};
|
||||
} else {
|
||||
sh_log_log("ACPI v2 is being used.",SH_LOG_SOURCE_MAIN);
|
||||
}
|
||||
sh_log_log("Parsing ACPI XSDT...",SH_LOG_SOURCE_MAIN);
|
||||
sh_acpi_ACPI_XSDT_BODY xsdt_body;
|
||||
status=sh_acpi_parse_xsdt(acpi_pointers_root.xsdt,&xsdt_body);
|
||||
if (sh_status_error(status)) {
|
||||
sh_log_ffatal(SH_LOG_SOURCE_MAIN,"Couldn't parse ACPI XSDT. Error code: %8s",status);
|
||||
while (1) {};
|
||||
}
|
||||
sh_log_log("Parsed ACPI XSDT.",SH_LOG_SOURCE_MAIN);
|
||||
sh_log_log("Parsing ACPI tables...",SH_LOG_SOURCE_MAIN);
|
||||
sh_acpi_ACPI_TABLES acpi_tables;
|
||||
status=sh_acpi_parse_tables(&xsdt_body,&acpi_tables);
|
||||
if (sh_status_error(status)) {
|
||||
sh_log_ffatal(SH_LOG_SOURCE_MAIN,"Couldn't parse ACPI tables. Error code: %8s",status);
|
||||
while (1) {};
|
||||
}
|
||||
sh_log_log("Parsed ACPI tables.",SH_LOG_SOURCE_MAIN);
|
||||
sh_log_log("Parsing MADT table...",SH_LOG_SOURCE_MAIN);
|
||||
if (acpi_tables.madt_physical_address==0) {
|
||||
sh_log_ffatal(SH_LOG_SOURCE_MAIN,"Didn't found MADT table. Can't continue.");
|
||||
while (1) {};
|
||||
}
|
||||
status=sh_acpi_madt_parse(acpi_tables.madt_physical_address);
|
||||
if (sh_status_error(status)) {
|
||||
sh_log_ffatal(SH_LOG_SOURCE_MAIN,"Couldn't parse ACPI MADT table. Error code: %8s",status);
|
||||
while (1) {};
|
||||
}
|
||||
sh_log_log("Parsed MADT table.",SH_LOG_SOURCE_MAIN);
|
||||
sh_efifb_set_bar(3);
|
||||
status=sh_ioapic_mask_all();
|
||||
if (sh_status_error(status)) {
|
||||
sh_log_fatal("Couldn't disable all IOAPIC GSI lines.",SH_LOG_SOURCE_MAIN);
|
||||
while (SH_TRUE) {};
|
||||
}
|
||||
sh_log_log("Checking somes flags...",SH_LOG_SOURCE_MAIN);
|
||||
sh_bool has_hypervisor=sh_tsc_has_hypervisor();
|
||||
if (has_hypervisor) {
|
||||
sh_log_log("Shelter is running on a hypervisor (according to CPUID).",SH_LOG_SOURCE_MAIN);
|
||||
sh_log_warning("This may result in jitter during the CPU frequency estimation.",SH_LOG_SOURCE_MAIN);
|
||||
} else {
|
||||
sh_log_log("Shelter isn't running on a hypervisor (according to CPUID).",SH_LOG_SOURCE_MAIN);
|
||||
}
|
||||
sh_bool constant_tsc=sh_tsc_is_tsc_constant();
|
||||
if (constant_tsc) {
|
||||
sh_log_log("TSC is constant (according to CPUID).",SH_LOG_SOURCE_MAIN);
|
||||
} else {
|
||||
sh_log_log("TSC isn't constant (according to CPUID).",SH_LOG_SOURCE_MAIN);
|
||||
}
|
||||
sh_uint64 cpu_freq;
|
||||
status=sh_tsc_get_cpu_freq_cpuid(&cpu_freq);
|
||||
if (status==SH_STATUS_UNAVAILABLE) {
|
||||
sh_log_log("CPU frequence from CPUID is unavailable.",SH_LOG_SOURCE_MAIN);
|
||||
} else {
|
||||
sh_log_flog(SH_LOG_SOURCE_MAIN,"CPU frequence from CPUID: %8u hz",cpu_freq);
|
||||
}
|
||||
if (status==SH_STATUS_SUCCESS) {
|
||||
sh_log_log("Successfully copied memory map.",SH_LOG_SOURCE_PAGE);
|
||||
sh_log_log("Successfully obtained memory map.",SH_LOG_SOURCE_MAIN);
|
||||
sh_log_log("Using provided CPU frequence by CPUID",SH_LOG_SOURCE_MAIN);
|
||||
} else {
|
||||
sh_log_error("Can't copy memory map.",SH_LOG_SOURCE_PAGE);
|
||||
sh_log_fatal("Can't obtain memory map.",SH_LOG_SOURCE_MAIN);
|
||||
while (SH_TRUE) {};
|
||||
sh_log_log("Estimating CPU frequence...",SH_LOG_SOURCE_MAIN);
|
||||
cpu_freq=sh_tsc_estimate_cpu_freq();
|
||||
sh_log_flog(SH_LOG_SOURCE_MAIN,"Estimated CPU frequence: %8u hz\n",cpu_freq);
|
||||
}
|
||||
sh_log_log("Checking memory map...",SH_LOG_SOURCE_MAIN);
|
||||
if (status==SH_STATUS_SUCCESS) {
|
||||
sh_log_log("Successfully checked memory map.",SH_LOG_SOURCE_MAIN);
|
||||
} else if (status==SH_STATUS_INVALID_SIGNATURE) {
|
||||
sh_log_fatal("Can't check memory map.",SH_LOG_SOURCE_MAIN);
|
||||
while (SH_TRUE) {};
|
||||
} else if (status==SH_STATUS_MMAP_BUFFER_OVERFLOW) {
|
||||
sh_log_fatal("Memory map is overflowing. Can't safely continue.",SH_LOG_SOURCE_MAIN);
|
||||
while (SH_TRUE) {};
|
||||
sh_tsc_load_cpu_freq(cpu_freq);
|
||||
sh_log_log("Calibrating LAPIC...",SH_LOG_SOURCE_MAIN);
|
||||
sh_lapic_DEVICE *lapic=sh_lapic_get_dev_apic_id(0);
|
||||
if (!lapic) {
|
||||
sh_log_ffatal(SH_LOG_SOURCE_MAIN,"Couldn't get LAPIC.");
|
||||
while (1) {};
|
||||
}
|
||||
sh_log_log("Initializing current page table pool...",SH_LOG_SOURCE_MAIN);
|
||||
sh_page_PAGE_TABLE_POOL kernel_ptp;
|
||||
status=sh_page_init_ptp(boot_config->page_table_pool_pa,sh_page_get_boot_ptp_va(),boot_config->page_table_allocator_level,&kernel_ptp);
|
||||
if (status==SH_STATUS_PT_POOL_NO_BITMAP_INIT) {
|
||||
sh_log_fatal("Couldn't initialize current page table pool.",SH_LOG_SOURCE_MAIN);
|
||||
while (SH_TRUE) {};
|
||||
} else if (status==SH_STATUS_PT_POOL_NO_PAGE_SET) {
|
||||
sh_log_fatal("Couldn't initialize current page table pool.",SH_LOG_SOURCE_MAIN);
|
||||
while (SH_TRUE) {};
|
||||
}
|
||||
sh_log_log("Successfully initialized current page table pool.",SH_LOG_SOURCE_MAIN);
|
||||
sh_log_log("Parsing memory map...",SH_LOG_SOURCE_MAIN);
|
||||
status=sh_page_analyse_memory_map(&kernel_ptp);
|
||||
sh_log_flog(SH_LOG_SOURCE_MAIN,"Obtained LAPIC.\n");
|
||||
status=sh_lapic_init_dev(0xFF,lapic);
|
||||
if (sh_status_error(status)) {
|
||||
sh_log_ffatal(SH_LOG_SOURCE_MAIN,"Couldn't parse memory map. Error code: %8s\n",status);
|
||||
while (SH_TRUE) {};
|
||||
sh_log_ffatal(SH_LOG_SOURCE_MAIN,"Couldn't initialize LAPIC.");
|
||||
while (1) {};
|
||||
}
|
||||
sh_log_log("Successfully parsed memory map.",SH_LOG_SOURCE_MAIN);
|
||||
sh_log_mem_stats(SH_LOG_SOURCE_MAIN);
|
||||
sh_log_log("Page managment subsystem successfully initialized",SH_LOG_SOURCE_MAIN);
|
||||
sh_slab_reg_phys_SLAB_ALLOCATOR slab_reg_phys;
|
||||
status=sh_slab_reg_phys_alloc_init(&slab_reg_phys,&kernel_ptp);
|
||||
sh_log_flog(SH_LOG_SOURCE_MAIN,"Initialized LAPIC.\n");
|
||||
status=sh_lapic_calibrate(lapic,cpu_freq);
|
||||
if (sh_status_error(status)) {
|
||||
sh_log_fatal("Couldn't initialize physical region object slab allocator.",SH_LOG_SOURCE_MAIN);
|
||||
while (SH_TRUE) {};
|
||||
sh_log_ffatal(SH_LOG_SOURCE_MAIN,"Couldn't calibrate LAPIC.");
|
||||
while (1) {};
|
||||
}
|
||||
sh_log_log("Successfully initialize physical region object slab allocator.",SH_LOG_SOURCE_MAIN);
|
||||
sh_log_log("Allocating first slab...",SH_LOG_SOURCE_MAIN);
|
||||
sh_slab_reg_phys_SLAB_STRUCT *first_slab_rp=SH_NULLPTR;
|
||||
status=sh_slab_reg_phys_add_slab(&slab_reg_phys,&kernel_ptp,&first_slab_rp);
|
||||
if (status!=SH_STATUS_SUCCESS) {
|
||||
sh_log_ffatal(SH_LOG_SOURCE_MAIN,"Couldn't allocate first slab. Error code: %8s\n",status);
|
||||
while (SH_TRUE) {};
|
||||
} else {
|
||||
sh_log_log("Successfully allocated first slab. Verifying data...",SH_LOG_SOURCE_MAIN);
|
||||
if (first_slab_rp->free_bitmap[0]!=1 ||
|
||||
first_slab_rp->slab_index!=0 ||
|
||||
first_slab_rp->next!=SH_NULLPTR ||
|
||||
first_slab_rp->prev!=SH_NULLPTR ||
|
||||
first_slab_rp->used_count!=0) {
|
||||
sh_log_error("One of the attributes inside first slab is wrong.",SH_LOG_SOURCE_MAIN);
|
||||
sh_log_fatal("Stopping for safety.",SH_LOG_SOURCE_MAIN);
|
||||
while (SH_TRUE) {};
|
||||
} else {
|
||||
sh_log_log("All attributes are good.",SH_LOG_SOURCE_MAIN);
|
||||
}
|
||||
sh_log_flog(SH_LOG_SOURCE_MAIN,"Calibration ended with LAPIC frequency being %8u hz.\n",sh_lapic_get_frequency());
|
||||
sh_int16 current_cpu=sh_lapic_get_current_core();
|
||||
if (current_cpu<0) {
|
||||
sh_log_ffatal(SH_LOG_SOURCE_MAIN,"Couldn't obtain current CPU LAPIC id.");
|
||||
while (1) {};
|
||||
}
|
||||
sh_slab_reg_virt_SLAB_ALLOCATOR slab_reg_virt;
|
||||
status=sh_slab_reg_virt_alloc_init(&slab_reg_virt,&kernel_ptp);
|
||||
sh_log_flog(SH_LOG_SOURCE_MAIN,"Current CPU have a LAPIC id of %1u.\n",(sh_uint8)current_cpu);
|
||||
lapic=sh_lapic_get_dev_apic_id((sh_uint64)current_cpu);
|
||||
if (!lapic) {
|
||||
sh_log_ffatal(SH_LOG_SOURCE_MAIN,"Couldn't get LAPIC.");
|
||||
while (1) {};
|
||||
}
|
||||
sh_log_flog(SH_LOG_SOURCE_MAIN,"Obtained LAPIC of this CPU.\n");
|
||||
sh_log_log("Preparing application processors initialization...",SH_LOG_SOURCE_MAIN);
|
||||
status=sh_ap_load_gdt_32();
|
||||
if (sh_status_error(status)) {
|
||||
sh_log_fatal("Couldn't initialize virtual region object slab allocator.",SH_LOG_SOURCE_MAIN);
|
||||
while (SH_TRUE) {};
|
||||
sh_log_ffatal(SH_LOG_SOURCE_MAIN,"Couldn't generate 32-bits GDT for AP trampoline. Status code: %8s\n",status);
|
||||
while (1) {};
|
||||
}
|
||||
sh_log_log("Successfully initialize virtual region object slab allocator.",SH_LOG_SOURCE_MAIN);
|
||||
sh_log_log("Allocating first slab...",SH_LOG_SOURCE_MAIN);
|
||||
sh_slab_reg_virt_SLAB_STRUCT *first_slab_rv=SH_NULLPTR;
|
||||
status=sh_slab_reg_virt_add_slab(&slab_reg_virt,&kernel_ptp,&first_slab_rv);
|
||||
if (status!=SH_STATUS_SUCCESS) {
|
||||
sh_log_ffatal(SH_LOG_SOURCE_MAIN,"Couldn't allocate first slab. Error code: %8s\n",status);
|
||||
while (SH_TRUE) {};
|
||||
} else {
|
||||
sh_log_log("Successfully allocated first slab. Verifying data...",SH_LOG_SOURCE_MAIN);
|
||||
if (first_slab_rv->free_bitmap[0]!=1 ||
|
||||
first_slab_rv->slab_index!=0 ||
|
||||
first_slab_rv->next!=SH_NULLPTR ||
|
||||
first_slab_rv->prev!=SH_NULLPTR ||
|
||||
first_slab_rv->used_count!=0) {
|
||||
sh_log_error("One of the attributes inside first slab is wrong.",SH_LOG_SOURCE_MAIN);
|
||||
sh_log_fatal("Stopping for safety.",SH_LOG_SOURCE_MAIN);
|
||||
while (SH_TRUE) {};
|
||||
} else {
|
||||
sh_log_log("All attributes are good.",SH_LOG_SOURCE_MAIN);
|
||||
}
|
||||
}
|
||||
sh_pba_PAGE_BLOCK_ALLOCATOR slab_radix_node_pba;
|
||||
status=sh_pba_init(&slab_radix_node_pba,SH_VMEM_LAYOUT_SLAB_RADIX_NODE_VA,SH_VMEM_LAYOUT_SLAB_RADIX_NODE_SIZE_BYTES/SH_PAGE_SIZE,SH_SLAB_RADIX_NODE_SLAB_DATA_PAGES);
|
||||
sh_log_log("Generated 32-bits GDT for AP trampoline.",SH_LOG_SOURCE_MAIN);
|
||||
status=sh_ap_prepare_for_smp_launch(sh_lapic_get_by_apic_id_array(),sh_lapic_get_max_apic_id(),sh_lapic_get_lapic_count(),boot_config,&idt);
|
||||
if (sh_status_error(status)) {
|
||||
sh_log_fatal("Couldn't initialize PBA for radix nodes slab allocator.",SH_LOG_SOURCE_MAIN);
|
||||
while (SH_TRUE) {};
|
||||
sh_log_ffatal(SH_LOG_SOURCE_MAIN,"Couldn't prepare for AP launch. Status code: %8s\n",status);
|
||||
while (1) {};
|
||||
}
|
||||
sh_log_log("Successfully initialize PBA for radix nodes slab allocator.",SH_LOG_SOURCE_MAIN);
|
||||
struct sh_slab_radix_node_SLAB_ALLOCATOR slab_radix_node;
|
||||
status=sh_slab_radix_node_alloc_init(&slab_radix_node,&slab_radix_node_pba);
|
||||
sh_log_log("Succesfully prepared for AP launch.",SH_LOG_SOURCE_MAIN);
|
||||
status=sh_ap_start_ap_boot_procedure(boot_config);
|
||||
if (sh_status_error(status)) {
|
||||
sh_log_fatal("Couldn't initialize radix nodes slab allocator.",SH_LOG_SOURCE_MAIN);
|
||||
while (SH_TRUE) {};
|
||||
sh_printf(SH_FATAL,"Couldn't start AP boot procedure. Status code: %8s\n",status);
|
||||
while (1) {};
|
||||
}
|
||||
sh_log_log("Successfully initialize radix nodes slab allocator.",SH_LOG_SOURCE_MAIN);
|
||||
sh_log_log("Allocating first slab...",SH_LOG_SOURCE_MAIN);
|
||||
sh_slab_radix_node_SLAB *first_slab_rn=SH_NULLPTR;
|
||||
status=sh_slab_radix_node_add_slab(&slab_radix_node,&kernel_ptp,&first_slab_rn);
|
||||
if (status!=SH_STATUS_SUCCESS) {
|
||||
sh_log_ffatal(SH_LOG_SOURCE_MAIN,"Couldn't allocate first slab. Error code: %8s\n",status);
|
||||
while (SH_TRUE) {};
|
||||
} else {
|
||||
sh_log_log("Successfully allocated first slab. Verifying data...",SH_LOG_SOURCE_MAIN);
|
||||
if (first_slab_rn->free_bitmap[0]!=0x3FFFF ||
|
||||
first_slab_rn->slab_index!=0 ||
|
||||
first_slab_rn->next_slab!=SH_NULLPTR ||
|
||||
first_slab_rn->prev_slab!=SH_NULLPTR ||
|
||||
first_slab_rn->next_partial!=SH_NULLPTR ||
|
||||
first_slab_rn->prev_partial!=SH_NULLPTR ||
|
||||
first_slab_rn->used_count!=0 ) {
|
||||
sh_log_error("One of the attributes inside first slab is wrong.",SH_LOG_SOURCE_MAIN);
|
||||
sh_log_fatal("Stopping for safety.",SH_LOG_SOURCE_MAIN);
|
||||
while (SH_TRUE) {};
|
||||
} else {
|
||||
sh_log_log("All attributes are good.",SH_LOG_SOURCE_MAIN);
|
||||
}
|
||||
sh_print(SH_LOG,"Succesfully started all APs.\n");
|
||||
status=sh_gsi_irq_switch();
|
||||
if (sh_status_error(status)) {
|
||||
sh_printf(SH_FATAL,"Couldn't switch legacy IRQ management to IOAPIC. Status code: %8s\n",status);
|
||||
while (1) {};
|
||||
}
|
||||
sh_printf(SH_LOG,"Succesfully switched legacy IRQ management to IOAPIC.\n");
|
||||
sh_efifb_set_bar(4);
|
||||
if (boot_config->test_benchmark) {
|
||||
status=sh_test_slabs_benchmark(&slab_reg_phys,&slab_reg_virt,&slab_radix_node,&kernel_ptp);
|
||||
status=sh_test_benchmark_queues();
|
||||
if (status!=SH_STATUS_SUCCESS) {
|
||||
sh_log_fatal("Couldn't benchmark one of the slab allocator.",SH_LOG_SOURCE_MAIN);
|
||||
while (SH_TRUE) {};
|
||||
}
|
||||
status=sh_test_radix_benchmark(&slab_radix_node,&kernel_ptp);
|
||||
if (status!=SH_STATUS_SUCCESS) {
|
||||
sh_log_fatal("Couldn't benchmark radix trees subsystem.",SH_LOG_SOURCE_MAIN);
|
||||
sh_print(SH_FATAL,"Couldn't benchmark keyboard events queues.\n");
|
||||
while (SH_TRUE) {};
|
||||
}
|
||||
}
|
||||
sh_log_log("Creating Pez physical plane...",SH_LOG_SOURCE_MAIN);
|
||||
sh_pez_PHYSICAL_PLANE physical_plane;
|
||||
status=sh_pez_init_physical_plane((sh_uint8*)sh_page_get_physical_bitmap_ptr(),sh_page_get_physical_memory_amount_pages(),&slab_reg_phys,&slab_radix_node,&kernel_ptp,&physical_plane);
|
||||
if (status!=SH_STATUS_SUCCESS) {
|
||||
sh_log_ffatal(SH_LOG_SOURCE_MAIN,"Couldn't create Pez physical plane. Error code: %8s\n",status);
|
||||
while (SH_TRUE) {};
|
||||
}
|
||||
sh_log_log("Succesfully created Pez physical plane.",SH_LOG_SOURCE_MAIN);
|
||||
if (boot_config->test_benchmark) {
|
||||
status=sh_test_pez_benchmark_physical(&physical_plane);
|
||||
if (status!=SH_STATUS_SUCCESS) {
|
||||
sh_log_fatal("Couldn't benchmark Pez physical plane.",SH_LOG_SOURCE_MAIN);
|
||||
while (SH_TRUE) {};
|
||||
}
|
||||
}
|
||||
sh_log_log("Creating Pez virtual plane for kernel heap...",SH_LOG_SOURCE_MAIN);
|
||||
sh_pez_VIRTUAL_PLANE virtual_plane_kernel_heap;
|
||||
status=sh_pez_init_virtual_plane(SH_VMEM_LAYOUT_HEAP_BIG_VA,&slab_reg_virt,&slab_radix_node,&kernel_ptp,&kernel_ptp,&virtual_plane_kernel_heap);
|
||||
if (status!=SH_STATUS_SUCCESS) {
|
||||
sh_log_ffatal(SH_LOG_SOURCE_MAIN,"Couldn't create Pez virtual plane for kernel heap. Error code: %8s\n",status);
|
||||
while (SH_TRUE) {};
|
||||
}
|
||||
sh_log_log("Succesfully created Pez virtual plane for kernel heap.",SH_LOG_SOURCE_MAIN);
|
||||
sh_pez_set_available();
|
||||
sh_heap_KERNEL_HEAP kernel_heap;
|
||||
status=sh_heap_init_heap(&physical_plane,&virtual_plane_kernel_heap,&kernel_ptp,&kernel_heap);
|
||||
status=sh_kbd_init_devs();
|
||||
if (sh_status_error(status)) {
|
||||
sh_log_ffatal(SH_LOG_SOURCE_MAIN,"Couldn't initialize kernel heap. Error code: %8s",status);
|
||||
while (SH_TRUE) {};
|
||||
sh_printf(SH_FATAL,"Couldn't initialized keyboard subsystem. Status code: %8s\n",status);
|
||||
while (1) {};
|
||||
}
|
||||
sh_uint64 slab_data_pages[8]=SH_SLAB_GENERIC_SLAB_DATA_PAGES;
|
||||
for (sh_iter64 i=0;i<8;i++) {
|
||||
status=sh_pba_init(&kernel_heap.pba[i],SH_VMEM_LAYOUT_HEAP_SLAB_LEVEL_0_VA+i*SH_VMEM_LAYOUT_HEAP_SLAB_SPACING,((SH_VMEM_LAYOUT_HEAP_SLAB_LEVEL_0_SIZE_BYTES/SH_PAGE_SIZE)/slab_data_pages[i])*slab_data_pages[i],slab_data_pages[i]);
|
||||
if (sh_status_error(status)) {
|
||||
sh_log_ffatal(SH_LOG_SOURCE_MAIN,"Couldn't create PBA for heap allocations level %8u. Error code: %8s\n",i,status);
|
||||
while (SH_TRUE);
|
||||
}
|
||||
status=sh_slab_generic_alloc_init((sh_uint8)i,&kernel_heap.slabs_allocator[i],&kernel_heap.pba[i]);
|
||||
if (sh_status_error(status)) {
|
||||
sh_log_ffatal(SH_LOG_SOURCE_MAIN,"Couldn't create slab allocator for heap allocations level %8u. Error code: %8s\n",i,status);
|
||||
while (SH_TRUE);
|
||||
}
|
||||
sh_slab_generic_SLAB *first_slab_generic;
|
||||
status=sh_slab_generic_add_slab(&kernel_heap.slabs_allocator[i],&kernel_ptp,&first_slab_generic);
|
||||
if (status!=SH_STATUS_SUCCESS) {
|
||||
sh_log_ffatal(SH_LOG_SOURCE_MAIN,"Couldn't allocate first slab for heap allocations level %8u. Error code: %8s\n",i,status);
|
||||
while (SH_TRUE) {};
|
||||
} else {
|
||||
if (first_slab_generic->free_bitmap[0]!=kernel_heap.slabs_allocator[i].bitmap_init ||
|
||||
first_slab_generic->slab_index!=0 ||
|
||||
first_slab_generic->next_slab!=SH_NULLPTR ||
|
||||
first_slab_generic->prev_slab!=SH_NULLPTR ||
|
||||
first_slab_generic->next_partial!=SH_NULLPTR ||
|
||||
first_slab_generic->prev_partial!=SH_NULLPTR ||
|
||||
first_slab_generic->used_count!=0 ) {
|
||||
sh_log_error("One of the attributes inside first slab is wrong.",SH_LOG_SOURCE_MAIN);
|
||||
sh_log_fatal("Stopping for safety.",SH_LOG_SOURCE_MAIN);
|
||||
while (SH_TRUE) {};
|
||||
}
|
||||
}
|
||||
sh_log_flog(SH_LOG_SOURCE_MAIN,"Succesfully created heap slab allocator with level %8u.\n",i);
|
||||
sh_printf(SH_LOG,"Succesfully initialized keyboard subsystem.\n");
|
||||
status=sh_ps2_driver_init();
|
||||
if (sh_status_error(status)) {
|
||||
sh_printf(SH_FATAL,"Couldn't initialized PS2 driver. Status code: %8s\n",status);
|
||||
while (1) {};
|
||||
}
|
||||
sh_heap_load_default_heap(&kernel_heap);
|
||||
sh_log_log("Succesfully created kernel heap.",SH_LOG_SOURCE_MAIN);
|
||||
if (boot_config->test_benchmark) {
|
||||
status=sh_test_malloc_benchmark();
|
||||
if (status!=SH_STATUS_SUCCESS) {
|
||||
sh_log_fatal("Couldn't benchmark Pez physical plane.",SH_LOG_SOURCE_MAIN);
|
||||
while (SH_TRUE) {};
|
||||
}
|
||||
sh_printf(SH_LOG,"Succesfully initialized PS2 driver.\n");
|
||||
status=sh_ps2_disable_scanning();
|
||||
if (sh_status_error(status)) {
|
||||
sh_printf(SH_FATAL,"Couldn't disable PS2 scanning. Status code: %8s\n",status);
|
||||
while (1) {};
|
||||
}
|
||||
sh_printf(SH_LOG,"Succesfully disabled PS2 scanning.\n");
|
||||
sh_efifb_set_bar(5);
|
||||
sh_efifb_set_bar(100);
|
||||
while (1) {};
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user