Skip to content

Commit

Permalink
protos: Reduce or remove mentions of 'kernel' where unnecessary
Browse files Browse the repository at this point in the history
This also introduces limine.h API revision 2
  • Loading branch information
mintsuki committed Dec 5, 2024
1 parent 03e211d commit da43c70
Show file tree
Hide file tree
Showing 12 changed files with 204 additions and 140 deletions.
12 changes: 7 additions & 5 deletions CONFIG.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ Editor control options:
*Locally assignable (non protocol specific) options* are:

* `comment` - An optional comment string that will be displayed by the bootloader on the menu when an entry is selected.
* `protocol` - The boot protocol that will be used to boot the kernel. Valid protocols are: `linux`, `limine`, `multiboot` (or `multiboot1`), `multiboot2`, `efi_chainload`, `bios_chainload`, and `chainload_next`.
* `protocol` - The boot protocol that will be used to boot the kernel/executable. Valid protocols are: `linux`, `limine`, `multiboot` (or `multiboot1`), `multiboot2`, `efi_chainload`, `bios_chainload`, and `chainload_next`.
* `cmdline` - The command line string to be passed to the kernel/executable. Can be omitted.
* `kernel_cmdline` - Alias of `cmdline`.

Expand All @@ -127,11 +127,12 @@ Editor control options:
* `dtb_path` - A device tree blob to pass instead of the one provided by the firmware.

* Limine protocol:
* `kernel_path` - The path of the kernel.
* `path` - The path of the executable.
* `kernel_path` - Alias of `path`.
* `module_path` - The path to a module. This option can be specified multiple times to specify multiple modules.
* `module_cmdline` - A command line to be passed to a module. This option can also be specified multiple times. It applies to the module described by the last module option specified.
* `resolution` - The resolution to be used. This setting takes the form of `<width>x<height>x<bpp>`. If the resolution is not available, Limine will pick another one automatically. Omitting `<bpp>` will default to 32.
* `kaslr` - For relocatable kernels, if set to `no`, disable kernel address space layout randomisation. KASLR is enabled by default.
* `kaslr` - For relocatable executables, if set to `no`, disable kernel address space layout randomisation. KASLR is enabled by default.
* `randomise_hhdm_base` - If set to `yes`, randomise the base address of the higher half direct map. If set to `no`, do not. By default it is `yes` if KASLR is supported and enabled, else it is `no`.
* `randomize_hhdm_base` - Alias of `randomise_hhdm_base`.
* `max_paging_mode`, `min_paging_mode` - Limit the maximum and minimum paging modes to one of the following:
Expand All @@ -142,10 +143,11 @@ Editor control options:
* `dtb_path` - A device tree blob to pass instead of the one provided by the firmware.

* multiboot1 and multiboot2 protocols:
* `kernel_path` - The path of the kernel.
* `path` - The path of the executable.
* `kernel_path` - Alias of `path`.
* `module_path` - The path to a module. This option can be specified multiple times to specify multiple modules.
* `module_string` - A string to be passed to a module. This option can also be specified multiple times. It applies to the module described by the last module option specified.
* `resolution` - The resolution to be used should the kernel request a graphical framebuffer. This setting takes the form of `<width>x<height>x<bpp>` and *overrides* any resolution requested by the kernel. If the resolution is not available, Limine will pick another one automatically. Omitting `<bpp>` will default to 32.
* `resolution` - The resolution to be used should the executable request a graphical framebuffer. This setting takes the form of `<width>x<height>x<bpp>` and *overrides* any resolution requested by the executable. If the resolution is not available, Limine will pick another one automatically. Omitting `<bpp>` will default to 32.
* `textmode` - If set to `yes`, prefer text mode. (BIOS only)

* EFI Chainload protocol:
Expand Down
141 changes: 74 additions & 67 deletions PROTOCOL.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion common/common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ override CPPFLAGS_FOR_TARGET := \
$(CPPFLAGS_FOR_TARGET) \
-DCOM_OUTPUT=$(COM_OUTPUT) \
-DE9_OUTPUT=$(E9_OUTPUT) \
-DLIMINE_API_REVISION=1 \
-DLIMINE_API_REVISION=2 \
-MMD \
-MP

Expand Down
1 change: 1 addition & 0 deletions common/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ static const char *VALID_KEYS[] = {
"COMMENT",
"PROTOCOL",
"CMDLINE",
"PATH",
"KERNEL_CMDLINE",
"KERNEL_PATH",
"INITRD_PATH",
Expand Down
54 changes: 29 additions & 25 deletions common/protos/limine.c
Original file line number Diff line number Diff line change
Expand Up @@ -409,15 +409,19 @@ noreturn void limine_load(char *config, char *cmdline) {
uint32_t eax, ebx, ecx, edx;
#endif

char *kernel_path = config_get_value(config, 0, "KERNEL_PATH");
if (kernel_path == NULL)
panic(true, "limine: KERNEL_PATH not specified");
char *kernel_path = config_get_value(config, 0, "PATH");
if (kernel_path == NULL) {
kernel_path = config_get_value(config, 0, "KERNEL_PATH");
}
if (kernel_path == NULL) {
panic(true, "limine: Executable path not specified");
}

print("limine: Loading kernel `%#`...\n", kernel_path);
print("limine: Loading executable `%#`...\n", kernel_path);

struct file_handle *kernel_file;
if ((kernel_file = uri_open(kernel_path)) == NULL)
panic(true, "limine: Failed to open kernel with path `%#`. Is the path correct?", kernel_path);
panic(true, "limine: Failed to open executable with path `%#`. Is the path correct?", kernel_path);

char *k_path_copy = ext_mem_alloc(strlen(kernel_path) + 1);
strcpy(k_path_copy, kernel_path);
Expand Down Expand Up @@ -787,18 +791,18 @@ FEAT_START
}

if (kern_max_mode < kern_min_mode) {
panic(true, "limine: Kernel's paging max_mode lower than min_mode");
panic(true, "limine: Executable's paging max_mode lower than min_mode");
}

if (paging_mode > kern_max_mode) {
if (kern_max_mode < min_supported_paging_mode) {
panic(true, "limine: Kernel's maximum supported paging mode lower than minimum allowable paging mode");
panic(true, "limine: Executable's maximum supported paging mode lower than minimum allowable paging mode");
}
paging_mode = kern_max_mode;
}
if (paging_mode < kern_min_mode) {
if (kern_min_mode > max_supported_paging_mode) {
panic(true, "limine: Kernel's minimum supported paging mode higher than maximum allowable paging mode");
panic(true, "limine: Executable's minimum supported paging mode higher than maximum allowable paging mode");
}
paging_mode = kern_min_mode;
}
Expand Down Expand Up @@ -898,20 +902,20 @@ FEAT_START
firmware_type_request->response = reported_addr(firmware_type_response);
FEAT_END

// Kernel address feature
// Executable address feature
FEAT_START
struct limine_kernel_address_request *kernel_address_request = get_request(LIMINE_KERNEL_ADDRESS_REQUEST);
if (kernel_address_request == NULL) {
struct limine_executable_address_request *executable_address_request = get_request(LIMINE_EXECUTABLE_ADDRESS_REQUEST);
if (executable_address_request == NULL) {
break; // next feature
}

struct limine_kernel_address_response *kernel_address_response =
ext_mem_alloc(sizeof(struct limine_kernel_address_response));
struct limine_executable_address_response *executable_address_response =
ext_mem_alloc(sizeof(struct limine_executable_address_response));

kernel_address_response->physical_base = physical_base;
kernel_address_response->virtual_base = virtual_base;
executable_address_response->physical_base = physical_base;
executable_address_response->virtual_base = virtual_base;

kernel_address_request->response = reported_addr(kernel_address_response);
executable_address_request->response = reported_addr(executable_address_response);
FEAT_END

// HHDM feature
Expand Down Expand Up @@ -1019,7 +1023,7 @@ FEAT_START

if (dtb) {
// Delete all /memory@... nodes.
// The kernel must use the given UEFI memory map instead.
// The executable must use the given UEFI memory map instead.
while (true) {
int offset = fdt_subnode_offset_namelen(dtb, 0, "memory@", 7);

Expand Down Expand Up @@ -1063,19 +1067,19 @@ FEAT_START
stack_size_request->response = reported_addr(stack_size_response);
FEAT_END

// Kernel file
// Executable file
FEAT_START
struct limine_kernel_file_request *kernel_file_request = get_request(LIMINE_KERNEL_FILE_REQUEST);
if (kernel_file_request == NULL) {
struct limine_executable_file_request *executable_file_request = get_request(LIMINE_EXECUTABLE_FILE_REQUEST);
if (executable_file_request == NULL) {
break; // next feature
}

struct limine_kernel_file_response *kernel_file_response =
ext_mem_alloc(sizeof(struct limine_kernel_file_response));
struct limine_executable_file_response *executable_file_response =
ext_mem_alloc(sizeof(struct limine_executable_file_response));

kernel_file_response->kernel_file = reported_addr(kf);
executable_file_response->executable_file = reported_addr(kf);

kernel_file_request->response = reported_addr(kernel_file_response);
executable_file_request->response = reported_addr(executable_file_response);
FEAT_END

// Modules
Expand Down Expand Up @@ -1533,7 +1537,7 @@ FEAT_START
_memmap[i].type = LIMINE_MEMMAP_BOOTLOADER_RECLAIMABLE;
break;
case MEMMAP_KERNEL_AND_MODULES:
_memmap[i].type = LIMINE_MEMMAP_KERNEL_AND_MODULES;
_memmap[i].type = LIMINE_MEMMAP_EXECUTABLE_AND_MODULES;
break;
case MEMMAP_FRAMEBUFFER:
_memmap[i].type = LIMINE_MEMMAP_FRAMEBUFFER;
Expand Down
14 changes: 9 additions & 5 deletions common/protos/multiboot1.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,18 @@ static void *mb1_info_alloc(void **mb1_info_raw, size_t size) {
noreturn void multiboot1_load(char *config, char *cmdline) {
struct file_handle *kernel_file;

char *kernel_path = config_get_value(config, 0, "KERNEL_PATH");
if (kernel_path == NULL)
panic(true, "multiboot1: KERNEL_PATH not specified");
char *kernel_path = config_get_value(config, 0, "PATH");
if (kernel_path == NULL) {
kernel_path = config_get_value(config, 0, "KERNEL_PATH");
}
if (kernel_path == NULL) {
panic(true, "multiboot1: Executable path not specified");
}

print("multiboot1: Loading kernel `%#`...\n", kernel_path);
print("multiboot1: Loading executable `%#`...\n", kernel_path);

if ((kernel_file = uri_open(kernel_path)) == NULL)
panic(true, "multiboot1: Failed to open kernel with path `%#`. Is the path correct?", kernel_path);
panic(true, "multiboot1: Failed to open executable with path `%#`. Is the path correct?", kernel_path);

uint8_t *kernel = freadall(kernel_file, MEMMAP_KERNEL_AND_MODULES);

Expand Down
16 changes: 10 additions & 6 deletions common/protos/multiboot2.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,18 @@ static size_t get_multiboot2_info_size(
noreturn void multiboot2_load(char *config, char* cmdline) {
struct file_handle *kernel_file;

char *kernel_path = config_get_value(config, 0, "KERNEL_PATH");
if (kernel_path == NULL)
panic(true, "multiboot2: KERNEL_PATH not specified");
char *kernel_path = config_get_value(config, 0, "PATH");
if (kernel_path == NULL) {
kernel_path = config_get_value(config, 0, "KERNEL_PATH");
}
if (kernel_path == NULL) {
panic(true, "multiboot2: Executable path not specified");
}

print("multiboot2: Loading kernel `%#`...\n", kernel_path);
print("multiboot2: Loading executable `%#`...\n", kernel_path);

if ((kernel_file = uri_open(kernel_path)) == NULL)
panic(true, "multiboot2: Failed to open kernel with path `%#`. Is the path correct?", kernel_path);
panic(true, "multiboot2: Failed to open executable with path `%#`. Is the path correct?", kernel_path);

uint8_t *kernel = freadall(kernel_file, MEMMAP_KERNEL_AND_MODULES);

Expand Down Expand Up @@ -365,7 +369,7 @@ noreturn void multiboot2_load(char *config, char* cmdline) {

if (!check_usable_memory(ranges->target, ranges->target + ranges->length)) {
reloc_fail:
panic(true, "multiboot2: Could not find viable load address for kernel");
panic(true, "multiboot2: Could not find viable load address for executable");
}

// Get the load base address (AKA the lowest target in the ranges)
Expand Down
52 changes: 46 additions & 6 deletions limine.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ extern "C" {
# define LIMINE_API_REVISION 0
#endif

#if LIMINE_API_REVISION > 1
#if LIMINE_API_REVISION > 2
# error "limine.h API revision unsupported"
#endif

Expand Down Expand Up @@ -444,7 +444,11 @@ struct LIMINE_MP(request) {
#define LIMINE_MEMMAP_ACPI_NVS 3
#define LIMINE_MEMMAP_BAD_MEMORY 4
#define LIMINE_MEMMAP_BOOTLOADER_RECLAIMABLE 5
#define LIMINE_MEMMAP_KERNEL_AND_MODULES 6
#if LIMINE_API_REVISION >= 2
# define LIMINE_MEMMAP_EXECUTABLE_AND_MODULES 6
#else
# define LIMINE_MEMMAP_KERNEL_AND_MODULES 6
#endif
#define LIMINE_MEMMAP_FRAMEBUFFER 7

struct limine_memmap_entry {
Expand Down Expand Up @@ -482,19 +486,39 @@ struct limine_entry_point_request {
LIMINE_PTR(limine_entry_point) entry;
};

/* Kernel File */
/* Executable File */

#define LIMINE_KERNEL_FILE_REQUEST { LIMINE_COMMON_MAGIC, 0xad97e90e83f1ed67, 0x31eb5d1c5ff23b69 }
#if LIMINE_API_REVISION >= 2
# define LIMINE_EXECUTABLE_FILE_REQUEST { LIMINE_COMMON_MAGIC, 0xad97e90e83f1ed67, 0x31eb5d1c5ff23b69 }
#else
# define LIMINE_KERNEL_FILE_REQUEST { LIMINE_COMMON_MAGIC, 0xad97e90e83f1ed67, 0x31eb5d1c5ff23b69 }
#endif

#if LIMINE_API_REVISION >= 2
struct limine_executable_file_response {
#else
struct limine_kernel_file_response {
#endif
uint64_t revision;
#if LIMINE_API_REVISION >= 2
LIMINE_PTR(struct limine_file *) executable_file;
#else
LIMINE_PTR(struct limine_file *) kernel_file;
#endif
};

#if LIMINE_API_REVISION >= 2
struct limine_executable_file_request {
#else
struct limine_kernel_file_request {
#endif
uint64_t id[4];
uint64_t revision;
#if LIMINE_API_REVISION >= 2
LIMINE_PTR(struct limine_executable_file_response *) response;
#else
LIMINE_PTR(struct limine_kernel_file_response *) response;
#endif
};

/* Module */
Expand Down Expand Up @@ -618,20 +642,36 @@ struct limine_boot_time_request {
LIMINE_PTR(struct limine_boot_time_response *) response;
};

/* Kernel address */
/* Executable address */

#define LIMINE_KERNEL_ADDRESS_REQUEST { LIMINE_COMMON_MAGIC, 0x71ba76863cc55f63, 0xb2644a48c516a487 }
#if LIMINE_API_REVISION >= 2
# define LIMINE_EXECUTABLE_ADDRESS_REQUEST { LIMINE_COMMON_MAGIC, 0x71ba76863cc55f63, 0xb2644a48c516a487 }
#else
# define LIMINE_KERNEL_ADDRESS_REQUEST { LIMINE_COMMON_MAGIC, 0x71ba76863cc55f63, 0xb2644a48c516a487 }
#endif

#if LIMINE_API_REVISION >= 2
struct limine_executable_address_response {
#else
struct limine_kernel_address_response {
#endif
uint64_t revision;
uint64_t physical_base;
uint64_t virtual_base;
};

#if LIMINE_API_REVISION >= 2
struct limine_executable_address_request {
#else
struct limine_kernel_address_request {
#endif
uint64_t id[4];
uint64_t revision;
#if LIMINE_API_REVISION >= 2
LIMINE_PTR(struct limine_executable_address_response *) response;
#else
LIMINE_PTR(struct limine_kernel_address_response *) response;
#endif
};

/* Device Tree Blob */
Expand Down
Loading

0 comments on commit da43c70

Please sign in to comment.