limine: PXE and HHDM work

This commit is contained in:
mintsuki 2022-03-17 23:46:48 +01:00
parent ee5e776c2c
commit fb54571b34
6 changed files with 38 additions and 7 deletions

View File

@ -22,6 +22,9 @@ struct file_handle {
#if uefi == 1 #if uefi == 1
EFI_HANDLE efi_part_handle; EFI_HANDLE efi_part_handle;
#endif #endif
bool pxe;
uint32_t pxe_ip;
uint16_t pxe_port;
}; };
struct file_handle *fopen(struct volume *part, const char *filename); struct file_handle *fopen(struct volume *part, const char *filename);

View File

@ -22,6 +22,8 @@ struct limine_uuid {
struct limine_file_location { struct limine_file_location {
uint64_t partition_index; uint64_t partition_index;
uint32_t pxe_ip;
uint32_t pxe_port;
uint32_t mbr_disk_id; uint32_t mbr_disk_id;
struct limine_uuid gpt_disk_uuid; struct limine_uuid gpt_disk_uuid;
struct limine_uuid gpt_part_uuid; struct limine_uuid gpt_part_uuid;
@ -35,6 +37,7 @@ struct limine_file_location {
struct limine_boot_info_response { struct limine_boot_info_response {
uint64_t flags; uint64_t flags;
LIMINE_PTR(char *) loader; LIMINE_PTR(char *) loader;
LIMINE_PTR(void *) hhdm;
}; };
struct limine_boot_info_request { struct limine_boot_info_request {

View File

@ -39,9 +39,17 @@ static uint64_t physical_base, virtual_base, slide, direct_map_offset;
static size_t requests_count; static size_t requests_count;
static void *requests[MAX_REQUESTS]; static void *requests[MAX_REQUESTS];
static struct limine_file_location get_file_loc(struct volume *vol) { static struct limine_file_location get_file_loc(struct file_handle *file) {
struct limine_file_location ret = {0}; struct limine_file_location ret = {0};
if (file->pxe) {
ret.pxe_ip = file->pxe_ip;
ret.pxe_port = file->pxe_port;
return ret;
}
struct volume *vol = file->vol;
ret.partition_index = vol->partition; ret.partition_index = vol->partition;
ret.mbr_disk_id = mbr_get_id(vol); ret.mbr_disk_id = mbr_get_id(vol);
@ -111,7 +119,8 @@ bool limine_load(char *config, char *cmdline) {
size_t kernel_file_size = kernel_file->size; size_t kernel_file_size = kernel_file->size;
struct volume *kernel_volume = kernel_file->vol; struct limine_file_location *kl = ext_mem_alloc(sizeof(struct limine_file_location));
*kl = get_file_loc(kernel_file);
fclose(kernel_file); fclose(kernel_file);
@ -234,6 +243,7 @@ FEAT_START
ext_mem_alloc(sizeof(struct limine_boot_info_response)); ext_mem_alloc(sizeof(struct limine_boot_info_response));
boot_info_response->loader = reported_addr("Limine " LIMINE_VERSION); boot_info_response->loader = reported_addr("Limine " LIMINE_VERSION);
boot_info_response->hhdm = direct_map_offset;
boot_info_request->response = reported_addr(boot_info_response); boot_info_request->response = reported_addr(boot_info_response);
FEAT_END FEAT_END
@ -306,9 +316,6 @@ FEAT_START
modules[0].path = reported_addr(kernel_path); modules[0].path = reported_addr(kernel_path);
modules[0].cmdline = reported_addr(cmdline); modules[0].cmdline = reported_addr(cmdline);
struct limine_file_location *kl = ext_mem_alloc(sizeof(struct limine_file_location));
*kl = get_file_loc(kernel_volume);
modules[0].file_location = reported_addr(kl); modules[0].file_location = reported_addr(kl);
for (size_t i = 1; i < module_count; i++) { for (size_t i = 1; i < module_count; i++) {
@ -337,7 +344,7 @@ FEAT_START
m->cmdline = reported_addr(module_cmdline); m->cmdline = reported_addr(module_cmdline);
struct limine_file_location *l = ext_mem_alloc(sizeof(struct limine_file_location)); struct limine_file_location *l = ext_mem_alloc(sizeof(struct limine_file_location));
*l = get_file_loc(f->vol); *l = get_file_loc(f);
m->file_location = reported_addr(l); m->file_location = reported_addr(l);

View File

@ -45,6 +45,10 @@ bool tftp_open(struct file_handle *handle, uint32_t server_ip, uint16_t server_p
handle->size = fsize.file_size; handle->size = fsize.file_size;
handle->is_memfile = true; handle->is_memfile = true;
handle->pxe = true;
handle->pxe_ip = server_ip;
handle->pxe_port = server_port;
struct pxenv_open open = { struct pxenv_open open = {
.status = 0, .status = 0,
.sip = server_ip, .sip = server_ip,

View File

@ -67,6 +67,12 @@ static char *get_memmap_type(uint64_t type) {
static void print_file_loc(struct limine_file_location *file_location) { static void print_file_loc(struct limine_file_location *file_location) {
e9_printf("Loc->PartIndex: %d", file_location->partition_index); e9_printf("Loc->PartIndex: %d", file_location->partition_index);
e9_printf("Loc->PXEIP: %d.%d.%d.%d",
(file_location->pxe_ip & (0xff << 0)) >> 0,
(file_location->pxe_ip & (0xff << 8)) >> 8,
(file_location->pxe_ip & (0xff << 16)) >> 16,
(file_location->pxe_ip & (0xff << 24)) >> 24);
e9_printf("Loc->PXEPort: %d", file_location->pxe_port);
e9_printf("Loc->MBRDiskId: %x", file_location->mbr_disk_id); e9_printf("Loc->MBRDiskId: %x", file_location->mbr_disk_id);
e9_printf("Loc->GPTDiskUUID: %x-%x-%x-%x", e9_printf("Loc->GPTDiskUUID: %x-%x-%x-%x",
file_location->gpt_disk_uuid.a, file_location->gpt_disk_uuid.a,
@ -88,8 +94,14 @@ static void print_file_loc(struct limine_file_location *file_location) {
#define FEAT_START do { #define FEAT_START do {
#define FEAT_END } while (0); #define FEAT_END } while (0);
extern char kernel_start[];
static void limine_main(void) { static void limine_main(void) {
e9_printf("We're alive"); e9_printf("\nWe're alive");
uint64_t kernel_slide = (uint64_t)kernel_start - 0xffffffff80000000;
e9_printf("Kernel slide: %x", kernel_slide);
FEAT_START FEAT_START
if (boot_info_request.response == NULL) { if (boot_info_request.response == NULL) {
@ -99,6 +111,7 @@ FEAT_START
struct limine_boot_info_response *boot_info_response = boot_info_request.response; struct limine_boot_info_response *boot_info_response = boot_info_request.response;
e9_printf("Boot info response:"); e9_printf("Boot info response:");
e9_printf("Bootloader name: %s", boot_info_response->loader); e9_printf("Bootloader name: %s", boot_info_response->loader);
e9_printf("Higher half direct map: %x", boot_info_response->hhdm);
FEAT_END FEAT_END
FEAT_START FEAT_START

View File

@ -12,6 +12,7 @@ PHDRS
SECTIONS SECTIONS
{ {
. = 0xffffffff80000000; . = 0xffffffff80000000;
kernel_start = .;
.text : { .text : {
*(.text*) *(.text*)