2020-08-11 18:43:39 +03:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdbool.h>
|
2020-09-02 10:55:56 +03:00
|
|
|
#include <protos/stivale.h>
|
2020-08-11 18:43:39 +03:00
|
|
|
#include <protos/stivale2.h>
|
|
|
|
#include <lib/elf.h>
|
|
|
|
#include <lib/blib.h>
|
|
|
|
#include <lib/acpi.h>
|
|
|
|
#include <lib/config.h>
|
|
|
|
#include <lib/time.h>
|
|
|
|
#include <lib/print.h>
|
|
|
|
#include <lib/real.h>
|
|
|
|
#include <lib/libc.h>
|
2020-11-02 11:20:34 +03:00
|
|
|
#include <lib/uri.h>
|
2020-09-18 21:02:10 +03:00
|
|
|
#include <sys/smp.h>
|
2020-10-12 22:49:17 +03:00
|
|
|
#include <sys/cpu.h>
|
2021-03-02 08:21:05 +03:00
|
|
|
#include <lib/fb.h>
|
2020-09-02 10:55:56 +03:00
|
|
|
#include <lib/term.h>
|
2020-09-18 21:02:10 +03:00
|
|
|
#include <sys/pic.h>
|
2020-09-27 02:32:47 +03:00
|
|
|
#include <sys/lapic.h>
|
2020-08-11 18:43:39 +03:00
|
|
|
#include <fs/file.h>
|
2020-09-20 13:03:44 +03:00
|
|
|
#include <mm/pmm.h>
|
2021-01-03 04:43:27 +03:00
|
|
|
#include <mm/mtrr.h>
|
2020-09-18 13:51:26 +03:00
|
|
|
#include <stivale/stivale2.h>
|
2020-12-10 16:10:47 +03:00
|
|
|
#include <pxe/tftp.h>
|
2021-03-14 08:13:19 +03:00
|
|
|
#include <drivers/edid.h>
|
2020-08-11 18:43:39 +03:00
|
|
|
|
|
|
|
struct stivale2_struct stivale2_struct = {0};
|
|
|
|
|
|
|
|
inline static size_t get_phys_addr(uint64_t addr) {
|
|
|
|
if (addr & ((uint64_t)1 << 63))
|
|
|
|
return addr - FIXED_HIGHER_HALF_OFFSET_64;
|
|
|
|
return addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *get_tag(struct stivale2_header *s, uint64_t id) {
|
|
|
|
struct stivale2_tag *tag = (void*)get_phys_addr(s->tags);
|
|
|
|
for (;;) {
|
|
|
|
if (tag == NULL)
|
|
|
|
return NULL;
|
|
|
|
if (tag->identifier == id)
|
|
|
|
return tag;
|
|
|
|
tag = (void*)get_phys_addr(tag->next);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void append_tag(struct stivale2_struct *s, struct stivale2_tag *tag) {
|
|
|
|
tag->next = s->tags;
|
|
|
|
s->tags = (uint64_t)(size_t)tag;
|
|
|
|
}
|
|
|
|
|
2021-03-14 08:13:19 +03:00
|
|
|
void stivale2_load(char *config, char *cmdline, bool pxe, void *efi_system_table) {
|
2021-03-28 16:46:59 +03:00
|
|
|
struct file_handle *kernel_file = ext_mem_alloc(sizeof(struct file_handle));
|
2020-10-17 07:23:11 +03:00
|
|
|
|
2020-11-27 21:33:34 +03:00
|
|
|
char *kernel_path = config_get_value(config, 0, "KERNEL_PATH");
|
|
|
|
if (kernel_path == NULL)
|
2020-10-17 07:23:11 +03:00
|
|
|
panic("KERNEL_PATH not specified");
|
|
|
|
|
2021-03-28 16:46:59 +03:00
|
|
|
if (!uri_open(kernel_file, kernel_path))
|
2020-10-17 07:23:11 +03:00
|
|
|
panic("Could not open kernel resource");
|
2020-08-11 18:43:39 +03:00
|
|
|
|
|
|
|
struct stivale2_header stivale2_hdr;
|
|
|
|
|
2021-03-28 16:46:59 +03:00
|
|
|
uint8_t *kernel = freadall(kernel_file, STIVALE2_MMAP_BOOTLOADER_RECLAIMABLE);
|
|
|
|
|
2020-10-17 07:23:11 +03:00
|
|
|
int bits = elf_bits(kernel);
|
2020-08-11 18:43:39 +03:00
|
|
|
|
|
|
|
int ret;
|
|
|
|
|
2021-03-26 17:47:59 +03:00
|
|
|
bool level5pg = false;
|
|
|
|
|
2020-08-11 18:43:39 +03:00
|
|
|
uint64_t slide = 0;
|
2021-03-26 17:47:59 +03:00
|
|
|
uint64_t entry_point = 0;
|
2020-08-11 18:43:39 +03:00
|
|
|
|
|
|
|
switch (bits) {
|
|
|
|
case 64: {
|
|
|
|
// Check if 64 bit CPU
|
|
|
|
uint32_t eax, ebx, ecx, edx;
|
2020-11-16 23:23:11 +03:00
|
|
|
if (!cpuid(0x80000001, 0, &eax, &ebx, &ecx, &edx) || !(edx & (1 << 29))) {
|
2021-03-26 17:47:59 +03:00
|
|
|
panic("stivale2: This CPU does not support 64-bit mode.");
|
2020-08-11 18:43:39 +03:00
|
|
|
}
|
|
|
|
// Check if 5-level paging is available
|
2020-11-16 23:23:11 +03:00
|
|
|
if (cpuid(0x00000007, 0, &eax, &ebx, &ecx, &edx) && (ecx & (1 << 16))) {
|
2021-03-26 17:47:59 +03:00
|
|
|
print("stivale2: CPU has 5-level paging support\n");
|
2020-08-11 18:43:39 +03:00
|
|
|
level5pg = true;
|
|
|
|
}
|
|
|
|
|
2021-03-26 17:47:59 +03:00
|
|
|
if (elf64_load(kernel, &entry_point, &slide, 10))
|
|
|
|
panic("stivale2: ELF64 load failure");
|
2020-08-11 18:43:39 +03:00
|
|
|
|
2020-12-28 01:11:11 +03:00
|
|
|
ret = elf64_load_section(kernel, &stivale2_hdr, ".stivale2hdr", sizeof(struct stivale2_header), slide);
|
|
|
|
|
2020-08-11 18:43:39 +03:00
|
|
|
break;
|
|
|
|
}
|
2021-03-26 17:47:59 +03:00
|
|
|
case 32: {
|
|
|
|
if (elf32_load(kernel, (uint32_t *)&entry_point, 10))
|
|
|
|
panic("stivale2: ELF32 load failure");
|
|
|
|
|
2020-10-17 07:23:11 +03:00
|
|
|
ret = elf32_load_section(kernel, &stivale2_hdr, ".stivale2hdr", sizeof(struct stivale2_header));
|
2021-03-26 17:47:59 +03:00
|
|
|
|
2020-08-11 18:43:39 +03:00
|
|
|
break;
|
2021-03-26 17:47:59 +03:00
|
|
|
}
|
2020-08-11 18:43:39 +03:00
|
|
|
default:
|
|
|
|
panic("stivale2: Not 32 nor 64 bit x86 ELF file.");
|
|
|
|
}
|
|
|
|
|
|
|
|
print("stivale2: %u-bit ELF file detected\n", bits);
|
|
|
|
|
|
|
|
switch (ret) {
|
|
|
|
case 1:
|
|
|
|
panic("stivale2: File is not a valid ELF.");
|
|
|
|
case 2:
|
|
|
|
panic("stivale2: Section .stivale2hdr not found.");
|
|
|
|
case 3:
|
|
|
|
panic("stivale2: Section .stivale2hdr exceeds the size of the struct.");
|
|
|
|
case 4:
|
|
|
|
panic("stivale2: Section .stivale2hdr is smaller than size of the struct.");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stivale2_hdr.entry_point != 0)
|
|
|
|
entry_point = stivale2_hdr.entry_point;
|
|
|
|
|
|
|
|
print("stivale2: Kernel slide: %X\n", slide);
|
|
|
|
|
2021-03-26 17:47:59 +03:00
|
|
|
print("stivale2: Entry point at: %X\n", entry_point);
|
|
|
|
print("stivale2: Requested stack at: %X\n", stivale2_hdr.stack);
|
2020-08-11 18:43:39 +03:00
|
|
|
|
2020-08-29 21:02:16 +03:00
|
|
|
strcpy(stivale2_struct.bootloader_brand, "Limine");
|
|
|
|
strcpy(stivale2_struct.bootloader_version, LIMINE_VERSION);
|
2020-08-11 18:43:39 +03:00
|
|
|
|
2021-03-28 16:46:59 +03:00
|
|
|
//////////////////////////////////////////////
|
|
|
|
// Create kernel file struct tag
|
|
|
|
//////////////////////////////////////////////
|
|
|
|
{
|
|
|
|
struct stivale2_struct_tag_kernel_file *tag = ext_mem_alloc(sizeof(struct stivale2_struct_tag_kernel_file));
|
|
|
|
tag->tag.identifier = STIVALE2_STRUCT_TAG_KERNEL_FILE_ID;
|
|
|
|
|
|
|
|
tag->kernel_file = (uint64_t)(uintptr_t)kernel;
|
|
|
|
|
|
|
|
append_tag(&stivale2_struct, (struct stivale2_tag *)tag);
|
|
|
|
}
|
|
|
|
|
2021-03-28 17:20:23 +03:00
|
|
|
//////////////////////////////////////////////
|
|
|
|
// Create kernel slide struct tag
|
|
|
|
//////////////////////////////////////////////
|
|
|
|
{
|
|
|
|
struct stivale2_struct_tag_kernel_slide *tag = ext_mem_alloc(sizeof(struct stivale2_struct_tag_kernel_slide));
|
|
|
|
tag->tag.identifier = STIVALE2_STRUCT_TAG_KERNEL_SLIDE_ID;
|
|
|
|
|
|
|
|
tag->kernel_slide = slide;
|
|
|
|
|
|
|
|
append_tag(&stivale2_struct, (struct stivale2_tag *)tag);
|
|
|
|
}
|
|
|
|
|
2020-08-11 18:43:39 +03:00
|
|
|
//////////////////////////////////////////////
|
|
|
|
// Create firmware struct tag
|
|
|
|
//////////////////////////////////////////////
|
|
|
|
{
|
2020-12-31 05:26:19 +03:00
|
|
|
struct stivale2_struct_tag_firmware *tag = ext_mem_alloc(sizeof(struct stivale2_struct_tag_firmware));
|
2020-08-11 18:43:39 +03:00
|
|
|
tag->tag.identifier = STIVALE2_STRUCT_TAG_FIRMWARE_ID;
|
|
|
|
|
2021-03-12 02:04:37 +03:00
|
|
|
#if defined (bios)
|
2020-08-11 18:43:39 +03:00
|
|
|
tag->flags = 1 << 0; // bit 0 = BIOS boot
|
2021-03-12 02:04:37 +03:00
|
|
|
#endif
|
2020-08-11 18:43:39 +03:00
|
|
|
|
|
|
|
append_tag(&stivale2_struct, (struct stivale2_tag *)tag);
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////
|
|
|
|
// Create modules struct tag
|
|
|
|
//////////////////////////////////////////////
|
|
|
|
{
|
2020-10-20 09:51:56 +03:00
|
|
|
size_t module_count;
|
|
|
|
for (module_count = 0; ; module_count++) {
|
2020-11-27 21:33:34 +03:00
|
|
|
char *module_file = config_get_value(config, module_count, "MODULE_PATH");
|
|
|
|
if (module_file == NULL)
|
2020-10-20 09:51:56 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct stivale2_struct_tag_modules *tag =
|
2020-12-31 05:26:19 +03:00
|
|
|
ext_mem_alloc(sizeof(struct stivale2_struct_tag_modules)
|
|
|
|
+ sizeof(struct stivale2_module) * module_count);
|
2020-08-11 18:43:39 +03:00
|
|
|
|
2020-10-20 09:51:56 +03:00
|
|
|
tag->tag.identifier = STIVALE2_STRUCT_TAG_MODULES_ID;
|
|
|
|
tag->module_count = module_count;
|
2020-08-11 18:43:39 +03:00
|
|
|
|
2020-11-27 21:33:34 +03:00
|
|
|
for (size_t i = 0; i < module_count; i++) {
|
|
|
|
char *module_path = config_get_value(config, i, "MODULE_PATH");
|
2020-08-11 18:43:39 +03:00
|
|
|
|
2020-10-20 09:51:56 +03:00
|
|
|
struct stivale2_module *m = &tag->modules[i];
|
2020-08-11 18:43:39 +03:00
|
|
|
|
2020-11-27 21:33:34 +03:00
|
|
|
char *module_string = config_get_value(config, i, "MODULE_STRING");
|
|
|
|
if (module_string == NULL) {
|
2020-08-11 18:43:39 +03:00
|
|
|
m->string[0] = '\0';
|
2020-11-27 21:33:34 +03:00
|
|
|
} else {
|
|
|
|
// TODO perhaps change this to be a pointer
|
|
|
|
size_t str_len = strlen(module_string);
|
|
|
|
if (str_len > 127)
|
|
|
|
str_len = 127;
|
|
|
|
memcpy(m->string, module_string, str_len);
|
2020-08-11 18:43:39 +03:00
|
|
|
}
|
|
|
|
|
2021-01-02 23:44:27 +03:00
|
|
|
print("stivale2: Loading module `%s`...\n", module_path);
|
|
|
|
|
2020-08-11 18:43:39 +03:00
|
|
|
struct file_handle f;
|
2020-11-27 21:33:34 +03:00
|
|
|
if (!uri_open(&f, module_path))
|
|
|
|
panic("Requested module with path \"%s\" not found!", module_path);
|
2020-08-11 18:43:39 +03:00
|
|
|
|
2021-01-02 23:44:27 +03:00
|
|
|
m->begin = (uint64_t)(size_t)freadall(&f, STIVALE2_MMAP_KERNEL_AND_MODULES);
|
2020-08-11 18:43:39 +03:00
|
|
|
m->end = m->begin + f.size;
|
|
|
|
|
|
|
|
print("stivale2: Requested module %u:\n", i);
|
2020-11-27 21:33:34 +03:00
|
|
|
print(" Path: %s\n", module_path);
|
2020-08-11 19:00:51 +03:00
|
|
|
print(" String: %s\n", m->string);
|
|
|
|
print(" Begin: %X\n", m->begin);
|
|
|
|
print(" End: %X\n", m->end);
|
2020-08-11 18:43:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
append_tag(&stivale2_struct, (struct stivale2_tag *)tag);
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////
|
|
|
|
// Create RSDP struct tag
|
|
|
|
//////////////////////////////////////////////
|
|
|
|
{
|
2020-12-31 05:26:19 +03:00
|
|
|
struct stivale2_struct_tag_rsdp *tag = ext_mem_alloc(sizeof(struct stivale2_struct_tag_rsdp));
|
2020-08-11 18:43:39 +03:00
|
|
|
tag->tag.identifier = STIVALE2_STRUCT_TAG_RSDP_ID;
|
|
|
|
|
2020-09-17 13:06:35 +03:00
|
|
|
tag->rsdp = (uint64_t)(size_t)acpi_get_rsdp();
|
2020-08-11 18:43:39 +03:00
|
|
|
|
|
|
|
append_tag(&stivale2_struct, (struct stivale2_tag *)tag);
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////
|
|
|
|
// Create cmdline struct tag
|
|
|
|
//////////////////////////////////////////////
|
|
|
|
{
|
2020-12-31 05:26:19 +03:00
|
|
|
struct stivale2_struct_tag_cmdline *tag = ext_mem_alloc(sizeof(struct stivale2_struct_tag_cmdline));
|
2020-08-11 18:43:39 +03:00
|
|
|
tag->tag.identifier = STIVALE2_STRUCT_TAG_CMDLINE_ID;
|
|
|
|
|
|
|
|
tag->cmdline = (uint64_t)(size_t)cmdline;
|
|
|
|
|
|
|
|
append_tag(&stivale2_struct, (struct stivale2_tag *)tag);
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////
|
|
|
|
// Create epoch struct tag
|
|
|
|
//////////////////////////////////////////////
|
|
|
|
{
|
2020-12-31 05:26:19 +03:00
|
|
|
struct stivale2_struct_tag_epoch *tag = ext_mem_alloc(sizeof(struct stivale2_struct_tag_epoch));
|
2020-08-11 18:43:39 +03:00
|
|
|
tag->tag.identifier = STIVALE2_STRUCT_TAG_EPOCH_ID;
|
|
|
|
|
|
|
|
tag->epoch = time();
|
|
|
|
print("stivale2: Current epoch: %U\n", tag->epoch);
|
|
|
|
|
|
|
|
append_tag(&stivale2_struct, (struct stivale2_tag *)tag);
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////
|
|
|
|
// Create framebuffer struct tag
|
|
|
|
//////////////////////////////////////////////
|
|
|
|
{
|
2020-09-18 13:51:26 +03:00
|
|
|
struct stivale2_header_tag_framebuffer *hdrtag = get_tag(&stivale2_hdr, STIVALE2_HEADER_TAG_FRAMEBUFFER_ID);
|
2020-08-11 18:43:39 +03:00
|
|
|
|
2020-09-02 10:55:56 +03:00
|
|
|
term_deinit();
|
|
|
|
|
|
|
|
if (hdrtag != NULL) {
|
2020-11-09 14:31:47 +03:00
|
|
|
int req_width = hdrtag->framebuffer_width;
|
|
|
|
int req_height = hdrtag->framebuffer_height;
|
|
|
|
int req_bpp = hdrtag->framebuffer_bpp;
|
|
|
|
|
2020-11-27 21:33:34 +03:00
|
|
|
char *resolution = config_get_value(config, 0, "RESOLUTION");
|
|
|
|
if (resolution != NULL)
|
|
|
|
parse_resolution(&req_width, &req_height, &req_bpp, resolution);
|
2020-11-09 14:31:47 +03:00
|
|
|
|
2021-03-02 08:21:05 +03:00
|
|
|
struct fb_info fbinfo;
|
|
|
|
if (fb_init(&fbinfo, req_width, req_height, req_bpp)) {
|
2020-12-31 05:26:19 +03:00
|
|
|
struct stivale2_struct_tag_framebuffer *tag = ext_mem_alloc(sizeof(struct stivale2_struct_tag_framebuffer));
|
2020-11-08 13:59:23 +03:00
|
|
|
tag->tag.identifier = STIVALE2_STRUCT_TAG_FRAMEBUFFER_ID;
|
|
|
|
|
|
|
|
tag->memory_model = STIVALE2_FBUF_MMODEL_RGB;
|
2020-11-09 14:31:47 +03:00
|
|
|
tag->framebuffer_addr = fbinfo.framebuffer_addr;
|
2020-11-08 13:59:23 +03:00
|
|
|
tag->framebuffer_width = fbinfo.framebuffer_width;
|
|
|
|
tag->framebuffer_height = fbinfo.framebuffer_height;
|
|
|
|
tag->framebuffer_bpp = fbinfo.framebuffer_bpp;
|
|
|
|
tag->framebuffer_pitch = fbinfo.framebuffer_pitch;
|
|
|
|
tag->red_mask_size = fbinfo.red_mask_size;
|
|
|
|
tag->red_mask_shift = fbinfo.red_mask_shift;
|
|
|
|
tag->green_mask_size = fbinfo.green_mask_size;
|
|
|
|
tag->green_mask_shift = fbinfo.green_mask_shift;
|
|
|
|
tag->blue_mask_size = fbinfo.blue_mask_size;
|
|
|
|
tag->blue_mask_shift = fbinfo.blue_mask_shift;
|
|
|
|
|
|
|
|
append_tag(&stivale2_struct, (struct stivale2_tag *)tag);
|
2021-01-03 04:43:27 +03:00
|
|
|
|
|
|
|
if (get_tag(&stivale2_hdr, STIVALE2_HEADER_TAG_FB_MTRR_ID) != NULL) {
|
|
|
|
mtrr_restore();
|
|
|
|
bool ret = mtrr_set_range(tag->framebuffer_addr,
|
|
|
|
(uint64_t)tag->framebuffer_pitch * tag->framebuffer_height,
|
|
|
|
MTRR_MEMORY_TYPE_WC);
|
|
|
|
if (ret) {
|
|
|
|
struct stivale2_tag *tag = ext_mem_alloc(sizeof(struct stivale2_tag));
|
|
|
|
tag->identifier = STIVALE2_STRUCT_TAG_FB_MTRR_ID;
|
|
|
|
append_tag(&stivale2_struct, (struct stivale2_tag *)tag);
|
|
|
|
}
|
|
|
|
mtrr_save();
|
|
|
|
}
|
2020-11-08 13:59:23 +03:00
|
|
|
}
|
2020-08-11 18:43:39 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-14 08:13:19 +03:00
|
|
|
//////////////////////////////////////////////
|
|
|
|
// Create EDID struct tag
|
|
|
|
//////////////////////////////////////////////
|
|
|
|
{
|
|
|
|
struct edid_info_struct *edid_info = get_edid_info();
|
|
|
|
|
|
|
|
if (edid_info != NULL) {
|
|
|
|
struct stivale2_struct_tag_edid *tag = ext_mem_alloc(sizeof(struct stivale2_struct_tag_edid) + sizeof(struct edid_info_struct));
|
|
|
|
tag->tag.identifier = STIVALE2_STRUCT_TAG_EDID_ID;
|
|
|
|
|
|
|
|
tag->edid_size = sizeof(struct edid_info_struct);
|
|
|
|
|
|
|
|
memcpy(tag->edid_information, edid_info, sizeof(struct edid_info_struct));
|
|
|
|
|
|
|
|
append_tag(&stivale2_struct, (struct stivale2_tag *)tag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////
|
|
|
|
// Create EFI system table struct tag
|
|
|
|
//////////////////////////////////////////////
|
|
|
|
{
|
|
|
|
if (efi_system_table != NULL) {
|
|
|
|
struct stivale2_struct_tag_efi_system_table *tag = ext_mem_alloc(sizeof(struct stivale2_struct_tag_efi_system_table));
|
|
|
|
tag->tag.identifier = STIVALE2_STRUCT_TAG_EFI_SYSTEM_TABLE_ID;
|
|
|
|
|
|
|
|
tag->system_table = (uint64_t)(uintptr_t)efi_system_table;
|
|
|
|
|
|
|
|
append_tag(&stivale2_struct, (struct stivale2_tag *)tag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-26 16:06:59 +03:00
|
|
|
// Check if 5-level paging tag is requesting support
|
|
|
|
bool level5pg_requested = get_tag(&stivale2_hdr, STIVALE2_HEADER_TAG_5LV_PAGING_ID) ? true : false;
|
|
|
|
|
|
|
|
pagemap_t pagemap = {0};
|
|
|
|
if (bits == 64)
|
2020-11-08 01:50:01 +03:00
|
|
|
pagemap = stivale_build_pagemap(level5pg && level5pg_requested);
|
2020-09-11 17:17:55 +03:00
|
|
|
|
2021-03-07 08:50:04 +03:00
|
|
|
#if defined (uefi)
|
|
|
|
efi_exit_boot_services();
|
|
|
|
#endif
|
|
|
|
|
2020-09-18 15:39:29 +03:00
|
|
|
//////////////////////////////////////////////
|
|
|
|
// Create SMP struct tag
|
|
|
|
//////////////////////////////////////////////
|
|
|
|
{
|
2021-01-03 04:43:27 +03:00
|
|
|
mtrr_restore();
|
|
|
|
|
2020-09-18 15:39:29 +03:00
|
|
|
struct stivale2_header_tag_smp *smp_hdr_tag = get_tag(&stivale2_hdr, STIVALE2_HEADER_TAG_SMP_ID);
|
|
|
|
if (smp_hdr_tag != NULL) {
|
2020-10-25 14:41:13 +03:00
|
|
|
struct stivale2_struct_tag_smp *tag;
|
2020-10-20 03:38:01 +03:00
|
|
|
struct smp_information *smp_info;
|
|
|
|
size_t cpu_count;
|
2020-10-25 06:58:53 +03:00
|
|
|
uint32_t bsp_lapic_id;
|
2020-10-25 14:41:13 +03:00
|
|
|
smp_info = init_smp(sizeof(struct stivale2_struct_tag_smp), (void **)&tag,
|
|
|
|
&cpu_count, &bsp_lapic_id,
|
2020-10-25 06:58:53 +03:00
|
|
|
bits == 64, level5pg && level5pg_requested,
|
2020-10-20 03:38:01 +03:00
|
|
|
pagemap, smp_hdr_tag->flags & 1);
|
|
|
|
|
2020-10-22 16:25:10 +03:00
|
|
|
if (smp_info != NULL) {
|
|
|
|
tag->tag.identifier = STIVALE2_STRUCT_TAG_SMP_ID;
|
2020-10-25 06:58:53 +03:00
|
|
|
tag->bsp_lapic_id = bsp_lapic_id;
|
2020-10-22 16:25:10 +03:00
|
|
|
tag->cpu_count = cpu_count;
|
|
|
|
tag->flags |= (smp_hdr_tag->flags & 1) && x2apic_check();
|
|
|
|
|
|
|
|
append_tag(&stivale2_struct, (struct stivale2_tag *)tag);
|
|
|
|
}
|
2020-09-18 15:39:29 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-02 12:23:43 +03:00
|
|
|
#if defined (bios)
|
2020-12-31 05:26:19 +03:00
|
|
|
//////////////////////////////////////////////
|
|
|
|
// Create PXE struct tag
|
|
|
|
//////////////////////////////////////////////
|
|
|
|
if (pxe) {
|
|
|
|
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);
|
2020-09-19 01:15:31 +03:00
|
|
|
}
|
2021-03-02 12:23:43 +03:00
|
|
|
#else
|
|
|
|
(void)pxe;
|
|
|
|
#endif
|
2020-09-19 01:15:31 +03:00
|
|
|
|
2020-11-14 15:29:30 +03:00
|
|
|
//////////////////////////////////////////////
|
|
|
|
// Create memmap struct tag
|
|
|
|
//////////////////////////////////////////////
|
|
|
|
{
|
|
|
|
size_t memmap_entries;
|
|
|
|
struct e820_entry_t *memmap = get_memmap(&memmap_entries);
|
|
|
|
|
|
|
|
struct stivale2_struct_tag_memmap *tag =
|
|
|
|
conv_mem_alloc(sizeof(struct stivale2_struct_tag_memmap) +
|
|
|
|
sizeof(struct e820_entry_t) * memmap_entries);
|
|
|
|
|
|
|
|
tag->tag.identifier = STIVALE2_STRUCT_TAG_MEMMAP_ID;
|
|
|
|
tag->entries = (uint64_t)memmap_entries;
|
|
|
|
|
|
|
|
memcpy((void*)tag + sizeof(struct stivale2_struct_tag_memmap),
|
|
|
|
memmap, sizeof(struct e820_entry_t) * memmap_entries);
|
|
|
|
|
|
|
|
append_tag(&stivale2_struct, (struct stivale2_tag *)tag);
|
|
|
|
}
|
|
|
|
|
2020-12-31 05:26:19 +03:00
|
|
|
//////////////////////////////////////////////
|
|
|
|
// List tags
|
|
|
|
//////////////////////////////////////////////
|
|
|
|
print("Generated tags:\n");
|
|
|
|
struct stivale2_tag *taglist = (void*)(size_t)stivale2_struct.tags;
|
|
|
|
for (size_t i = 0; ; i++) {
|
|
|
|
print("Tag #%u ID: %X\n", i, taglist->identifier);
|
|
|
|
if (taglist->next)
|
|
|
|
taglist = (void*)(size_t)taglist->next;
|
|
|
|
else
|
|
|
|
break;
|
2020-12-10 16:10:47 +03:00
|
|
|
}
|
|
|
|
|
2021-03-07 02:52:25 +03:00
|
|
|
stivale_spinup(bits, level5pg && level5pg_requested, &pagemap,
|
2020-09-18 15:39:29 +03:00
|
|
|
entry_point, &stivale2_struct, stivale2_hdr.stack);
|
2020-08-11 18:43:39 +03:00
|
|
|
}
|