stivale1&2: Allocate root struct on the heap
This commit is contained in:
parent
d815c3d732
commit
735afcc4ee
|
@ -55,16 +55,16 @@ bool stivale_load_by_anchor(void **_anchor, const char *magic,
|
|||
return true;
|
||||
}
|
||||
|
||||
struct stivale_struct stivale_struct = {0};
|
||||
|
||||
bool stivale_load(char *config, char *cmdline) {
|
||||
struct stivale_struct *stivale_struct = ext_mem_alloc(sizeof(struct stivale_struct));
|
||||
|
||||
// BIOS or UEFI?
|
||||
#if bios == 1
|
||||
stivale_struct.flags |= (1 << 0);
|
||||
stivale_struct->flags |= (1 << 0);
|
||||
#endif
|
||||
|
||||
stivale_struct.flags |= (1 << 1); // we give colour information
|
||||
stivale_struct.flags |= (1 << 2); // we give SMBIOS information
|
||||
stivale_struct->flags |= (1 << 1); // we give colour information
|
||||
stivale_struct->flags |= (1 << 2); // we give SMBIOS information
|
||||
|
||||
struct file_handle *kernel_file;
|
||||
|
||||
|
@ -207,8 +207,8 @@ bool stivale_load(char *config, char *cmdline) {
|
|||
panic("stivale: The stack cannot be 0 for 32-bit kernels");
|
||||
}
|
||||
|
||||
stivale_struct.module_count = 0;
|
||||
uint64_t *prev_mod_ptr = &stivale_struct.modules;
|
||||
stivale_struct->module_count = 0;
|
||||
uint64_t *prev_mod_ptr = &stivale_struct->modules;
|
||||
for (int i = 0; ; i++) {
|
||||
struct conf_tuple conf_tuple =
|
||||
config_get_tuple(config, i, "MODULE_PATH", "MODULE_STRING");
|
||||
|
@ -219,7 +219,7 @@ bool stivale_load(char *config, char *cmdline) {
|
|||
if (module_path == NULL)
|
||||
break;
|
||||
|
||||
stivale_struct.module_count++;
|
||||
stivale_struct->module_count++;
|
||||
|
||||
struct stivale_module *m = ext_mem_alloc(sizeof(struct stivale_module));
|
||||
|
||||
|
@ -270,20 +270,20 @@ bool stivale_load(char *config, char *cmdline) {
|
|||
uint64_t rsdp = (uint64_t)(size_t)acpi_get_rsdp();
|
||||
|
||||
if (rsdp)
|
||||
stivale_struct.rsdp = REPORTED_ADDR(rsdp);
|
||||
stivale_struct->rsdp = REPORTED_ADDR(rsdp);
|
||||
|
||||
uint64_t smbios_entry_32 = 0, smbios_entry_64 = 0;
|
||||
acpi_get_smbios((void **)&smbios_entry_32, (void **)&smbios_entry_64);
|
||||
|
||||
if (smbios_entry_32)
|
||||
stivale_struct.smbios_entry_32 = REPORTED_ADDR(smbios_entry_32);
|
||||
stivale_struct->smbios_entry_32 = REPORTED_ADDR(smbios_entry_32);
|
||||
if (smbios_entry_64)
|
||||
stivale_struct.smbios_entry_64 = REPORTED_ADDR(smbios_entry_64);
|
||||
stivale_struct->smbios_entry_64 = REPORTED_ADDR(smbios_entry_64);
|
||||
|
||||
stivale_struct.cmdline = REPORTED_ADDR((uint64_t)(size_t)cmdline);
|
||||
stivale_struct->cmdline = REPORTED_ADDR((uint64_t)(size_t)cmdline);
|
||||
|
||||
stivale_struct.epoch = time();
|
||||
printv("stivale: Current epoch: %U\n", stivale_struct.epoch);
|
||||
stivale_struct->epoch = time();
|
||||
printv("stivale: Current epoch: %U\n", stivale_struct->epoch);
|
||||
|
||||
term_deinit();
|
||||
|
||||
|
@ -304,18 +304,18 @@ bool stivale_load(char *config, char *cmdline) {
|
|||
(uint64_t)fbinfo.framebuffer_pitch * fbinfo.framebuffer_height,
|
||||
MEMMAP_FRAMEBUFFER, false, false, false, true);
|
||||
|
||||
stivale_struct.framebuffer_addr = REPORTED_ADDR((uint64_t)fbinfo.framebuffer_addr);
|
||||
stivale_struct.framebuffer_width = fbinfo.framebuffer_width;
|
||||
stivale_struct.framebuffer_height = fbinfo.framebuffer_height;
|
||||
stivale_struct.framebuffer_bpp = fbinfo.framebuffer_bpp;
|
||||
stivale_struct.framebuffer_pitch = fbinfo.framebuffer_pitch;
|
||||
stivale_struct.fb_memory_model = STIVALE_FBUF_MMODEL_RGB;
|
||||
stivale_struct.fb_red_mask_size = fbinfo.red_mask_size;
|
||||
stivale_struct.fb_red_mask_shift = fbinfo.red_mask_shift;
|
||||
stivale_struct.fb_green_mask_size = fbinfo.green_mask_size;
|
||||
stivale_struct.fb_green_mask_shift = fbinfo.green_mask_shift;
|
||||
stivale_struct.fb_blue_mask_size = fbinfo.blue_mask_size;
|
||||
stivale_struct.fb_blue_mask_shift = fbinfo.blue_mask_shift;
|
||||
stivale_struct->framebuffer_addr = REPORTED_ADDR((uint64_t)fbinfo.framebuffer_addr);
|
||||
stivale_struct->framebuffer_width = fbinfo.framebuffer_width;
|
||||
stivale_struct->framebuffer_height = fbinfo.framebuffer_height;
|
||||
stivale_struct->framebuffer_bpp = fbinfo.framebuffer_bpp;
|
||||
stivale_struct->framebuffer_pitch = fbinfo.framebuffer_pitch;
|
||||
stivale_struct->fb_memory_model = STIVALE_FBUF_MMODEL_RGB;
|
||||
stivale_struct->fb_red_mask_size = fbinfo.red_mask_size;
|
||||
stivale_struct->fb_red_mask_shift = fbinfo.red_mask_shift;
|
||||
stivale_struct->fb_green_mask_size = fbinfo.green_mask_size;
|
||||
stivale_struct->fb_green_mask_shift = fbinfo.green_mask_shift;
|
||||
stivale_struct->fb_blue_mask_size = fbinfo.blue_mask_size;
|
||||
stivale_struct->fb_blue_mask_shift = fbinfo.blue_mask_shift;
|
||||
} else {
|
||||
#if uefi == 1
|
||||
panic("stivale: Cannot use text mode with UEFI.");
|
||||
|
@ -351,17 +351,18 @@ bool stivale_load(char *config, char *cmdline) {
|
|||
|
||||
memcpy(mmap_copy, mmap, mmap_entries * sizeof(struct e820_entry_t));
|
||||
|
||||
stivale_struct.memory_map_entries = (uint64_t)mmap_entries;
|
||||
stivale_struct.memory_map_addr = REPORTED_ADDR((uint64_t)(size_t)mmap_copy);
|
||||
stivale_struct->memory_map_entries = (uint64_t)mmap_entries;
|
||||
stivale_struct->memory_map_addr = REPORTED_ADDR((uint64_t)(size_t)mmap_copy);
|
||||
|
||||
stivale_spinup(bits, want_5lv, &pagemap,
|
||||
entry_point, REPORTED_ADDR((uint64_t)(uintptr_t)&stivale_struct),
|
||||
entry_point, REPORTED_ADDR((uint64_t)(uintptr_t)stivale_struct),
|
||||
stivale_hdr.stack, false);
|
||||
|
||||
__builtin_unreachable();
|
||||
|
||||
fail:
|
||||
pmm_free(kernel, kernel_file_size);
|
||||
pmm_free(stivale_struct, sizeof(struct stivale_struct));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -31,8 +31,6 @@
|
|||
((PTR) + ((stivale2_hdr.flags & (1 << 1)) ? \
|
||||
direct_map_offset : 0))
|
||||
|
||||
struct stivale2_struct stivale2_struct = {0};
|
||||
|
||||
#define get_phys_addr(addr) ({ \
|
||||
uintptr_t r1; \
|
||||
if ((addr) & ((uint64_t)1 << 63)) { \
|
||||
|
@ -77,6 +75,8 @@ void stivale2_term_callback(uint64_t, uint64_t, uint64_t, uint64_t);
|
|||
#endif
|
||||
|
||||
bool stivale2_load(char *config, char *cmdline) {
|
||||
struct stivale2_struct *stivale2_struct = ext_mem_alloc(sizeof(struct stivale2_struct));
|
||||
|
||||
struct file_handle *kernel_file;
|
||||
|
||||
char *kernel_path = config_get_value(config, 0, "KERNEL_PATH");
|
||||
|
@ -266,8 +266,8 @@ failed_to_load_header_section:
|
|||
panic("stivale2: The stack cannot be 0 for 32-bit kernels");
|
||||
}
|
||||
|
||||
strcpy(stivale2_struct.bootloader_brand, "Limine");
|
||||
strcpy(stivale2_struct.bootloader_version, LIMINE_VERSION);
|
||||
strcpy(stivale2_struct->bootloader_brand, "Limine");
|
||||
strcpy(stivale2_struct->bootloader_version, LIMINE_VERSION);
|
||||
|
||||
//////////////////////////////////////////////
|
||||
// Create boot volume tag
|
||||
|
@ -286,7 +286,7 @@ failed_to_load_header_section:
|
|||
memcpy(&tag->part_guid, &kernel_volume->part_guid, sizeof(struct stivale2_guid));
|
||||
}
|
||||
|
||||
append_tag(&stivale2_struct, (struct stivale2_tag *)tag);
|
||||
append_tag(stivale2_struct, (struct stivale2_tag *)tag);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////
|
||||
|
@ -298,7 +298,7 @@ failed_to_load_header_section:
|
|||
|
||||
tag->kernel_file = REPORTED_ADDR((uint64_t)(uintptr_t)kernel);
|
||||
|
||||
append_tag(&stivale2_struct, (struct stivale2_tag *)tag);
|
||||
append_tag(stivale2_struct, (struct stivale2_tag *)tag);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////
|
||||
|
@ -311,7 +311,7 @@ failed_to_load_header_section:
|
|||
tag->kernel_file = REPORTED_ADDR((uint64_t)(uintptr_t)kernel);
|
||||
tag->kernel_size = kernel_file_size;
|
||||
|
||||
append_tag(&stivale2_struct, (struct stivale2_tag *)tag);
|
||||
append_tag(stivale2_struct, (struct stivale2_tag *)tag);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////
|
||||
|
@ -323,7 +323,7 @@ failed_to_load_header_section:
|
|||
|
||||
tag->kernel_slide = slide;
|
||||
|
||||
append_tag(&stivale2_struct, (struct stivale2_tag *)tag);
|
||||
append_tag(stivale2_struct, (struct stivale2_tag *)tag);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////
|
||||
|
@ -337,7 +337,7 @@ failed_to_load_header_section:
|
|||
tag->flags = 1 << 0; // bit 0 = BIOS boot
|
||||
#endif
|
||||
|
||||
append_tag(&stivale2_struct, (struct stivale2_tag *)tag);
|
||||
append_tag(stivale2_struct, (struct stivale2_tag *)tag);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////
|
||||
|
@ -406,7 +406,7 @@ failed_to_load_header_section:
|
|||
}
|
||||
}
|
||||
|
||||
append_tag(&stivale2_struct, (struct stivale2_tag *)tag);
|
||||
append_tag(stivale2_struct, (struct stivale2_tag *)tag);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////
|
||||
|
@ -420,7 +420,7 @@ failed_to_load_header_section:
|
|||
if (rsdp)
|
||||
tag->rsdp = REPORTED_ADDR(rsdp);
|
||||
|
||||
append_tag(&stivale2_struct, (struct stivale2_tag *)tag);
|
||||
append_tag(stivale2_struct, (struct stivale2_tag *)tag);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////
|
||||
|
@ -438,7 +438,7 @@ failed_to_load_header_section:
|
|||
if (smbios_entry_64)
|
||||
tag->smbios_entry_64 = REPORTED_ADDR(smbios_entry_64);
|
||||
|
||||
append_tag(&stivale2_struct, (struct stivale2_tag *)tag);
|
||||
append_tag(stivale2_struct, (struct stivale2_tag *)tag);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////
|
||||
|
@ -450,7 +450,7 @@ failed_to_load_header_section:
|
|||
|
||||
tag->cmdline = REPORTED_ADDR((uint64_t)(size_t)cmdline);
|
||||
|
||||
append_tag(&stivale2_struct, (struct stivale2_tag *)tag);
|
||||
append_tag(stivale2_struct, (struct stivale2_tag *)tag);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////
|
||||
|
@ -463,7 +463,7 @@ failed_to_load_header_section:
|
|||
tag->epoch = time();
|
||||
printv("stivale2: Current epoch: %U\n", tag->epoch);
|
||||
|
||||
append_tag(&stivale2_struct, (struct stivale2_tag *)tag);
|
||||
append_tag(stivale2_struct, (struct stivale2_tag *)tag);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////
|
||||
|
@ -561,7 +561,7 @@ failed_to_load_header_section:
|
|||
tag->cols = term_cols;
|
||||
tag->rows = term_rows;
|
||||
|
||||
append_tag(&stivale2_struct, (struct stivale2_tag *)tag);
|
||||
append_tag(stivale2_struct, (struct stivale2_tag *)tag);
|
||||
|
||||
if (textmode) {
|
||||
#if bios == 1
|
||||
|
@ -599,7 +599,7 @@ have_fb_tag:;
|
|||
tag->blue_mask_size = fb->blue_mask_size;
|
||||
tag->blue_mask_shift = fb->blue_mask_shift;
|
||||
|
||||
append_tag(&stivale2_struct, (struct stivale2_tag *)tag);
|
||||
append_tag(stivale2_struct, (struct stivale2_tag *)tag);
|
||||
}
|
||||
} else {
|
||||
#if bios == 1
|
||||
|
@ -615,7 +615,7 @@ have_tm_tag:;
|
|||
tmtag->cols = 80;
|
||||
tmtag->bytes_per_char = 2;
|
||||
|
||||
append_tag(&stivale2_struct, (struct stivale2_tag *)tmtag);
|
||||
append_tag(stivale2_struct, (struct stivale2_tag *)tmtag);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
@ -634,7 +634,7 @@ have_tm_tag:;
|
|||
|
||||
memcpy(tag->edid_information, edid_info, sizeof(struct edid_info_struct));
|
||||
|
||||
append_tag(&stivale2_struct, (struct stivale2_tag *)tag);
|
||||
append_tag(stivale2_struct, (struct stivale2_tag *)tag);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -647,7 +647,7 @@ have_tm_tag:;
|
|||
|
||||
tag->addr = direct_map_offset;
|
||||
|
||||
append_tag(&stivale2_struct, (struct stivale2_tag *)tag);
|
||||
append_tag(stivale2_struct, (struct stivale2_tag *)tag);
|
||||
}
|
||||
|
||||
#if bios == 1
|
||||
|
@ -658,7 +658,7 @@ have_tm_tag:;
|
|||
struct stivale2_struct_tag_pxe_server_info *tag = ext_mem_alloc(sizeof(struct stivale2_struct_tag_pxe_server_info));
|
||||
tag->tag.identifier = STIVALE2_STRUCT_TAG_PXE_SERVER_INFO;
|
||||
tag->server_ip = get_boot_server_info();
|
||||
append_tag(&stivale2_struct, (struct stivale2_tag *)tag);
|
||||
append_tag(stivale2_struct, (struct stivale2_tag *)tag);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -677,7 +677,7 @@ have_tm_tag:;
|
|||
|
||||
memcpy(tag->pmrs, ranges, ranges_count * sizeof(struct stivale2_pmr));
|
||||
|
||||
append_tag(&stivale2_struct, (struct stivale2_tag *)tag);
|
||||
append_tag(stivale2_struct, (struct stivale2_tag *)tag);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -694,7 +694,7 @@ have_tm_tag:;
|
|||
tag->physical_base_address = physical_base;
|
||||
tag->virtual_base_address = virtual_base;
|
||||
|
||||
append_tag(&stivale2_struct, (struct stivale2_tag *)tag);
|
||||
append_tag(stivale2_struct, (struct stivale2_tag *)tag);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -708,7 +708,7 @@ have_tm_tag:;
|
|||
|
||||
tag->system_table = REPORTED_ADDR((uint64_t)(uintptr_t)gST);
|
||||
|
||||
append_tag(&stivale2_struct, (struct stivale2_tag *)tag);
|
||||
append_tag(stivale2_struct, (struct stivale2_tag *)tag);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -747,7 +747,7 @@ have_tm_tag:;
|
|||
tag->cpu_count = cpu_count;
|
||||
tag->flags |= (smp_hdr_tag->flags & 1) && x2apic_check();
|
||||
|
||||
append_tag(&stivale2_struct, (struct stivale2_tag *)tag);
|
||||
append_tag(stivale2_struct, (struct stivale2_tag *)tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -780,7 +780,7 @@ have_tm_tag:;
|
|||
memcpy((void*)tag + sizeof(struct stivale2_struct_tag_memmap),
|
||||
mmap, sizeof(struct e820_entry_t) * mmap_entries);
|
||||
|
||||
append_tag(&stivale2_struct, (struct stivale2_tag *)tag);
|
||||
append_tag(stivale2_struct, (struct stivale2_tag *)tag);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////
|
||||
|
@ -789,7 +789,7 @@ have_tm_tag:;
|
|||
if (verbose) {
|
||||
print("stivale2: Generated tags:\n");
|
||||
struct stivale2_tag *taglist =
|
||||
(void*)(uintptr_t)(stivale2_struct.tags - ((stivale2_hdr.flags & (1 << 1)) ? direct_map_offset : 0));
|
||||
(void*)(uintptr_t)(stivale2_struct->tags - ((stivale2_hdr.flags & (1 << 1)) ? direct_map_offset : 0));
|
||||
for (size_t i = 0; ; i++) {
|
||||
print(" Tag #%u ID: %X\n", i, taglist->identifier);
|
||||
if (taglist->next) {
|
||||
|
@ -806,12 +806,13 @@ have_tm_tag:;
|
|||
term_runtime = true;
|
||||
|
||||
stivale_spinup(bits, want_5lv, &pagemap, entry_point,
|
||||
REPORTED_ADDR((uint64_t)(uintptr_t)&stivale2_struct),
|
||||
REPORTED_ADDR((uint64_t)(uintptr_t)stivale2_struct),
|
||||
stivale2_hdr.stack, want_pmrs);
|
||||
|
||||
__builtin_unreachable();
|
||||
|
||||
fail:
|
||||
pmm_free(kernel, kernel_file_size);
|
||||
pmm_free(stivale2_struct, sizeof(struct stivale2_struct));
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue