limine: Add stack size feature

This commit is contained in:
mintsuki 2022-03-28 08:00:40 +02:00
parent b4fd10afd4
commit a688a1dd4f
3 changed files with 63 additions and 5 deletions

View File

@ -141,7 +141,8 @@ Legacy PIC and IO APIC IRQs are all masked.
If booted by EFI/UEFI, boot services are exited. If booted by EFI/UEFI, boot services are exited.
`rsp` is set to point to a stack, in bootloader-reserved memory, which is `rsp` is set to point to a stack, in bootloader-reserved memory, which is
at least 16KiB (16384 bytes) in size. An invalid return address of 0 is pushed at least 16KiB (16384 bytes) in size, or the size specified in the Stack
Size Request (see below). An invalid return address of 0 is pushed
to the stack before jumping to the kernel. to the stack before jumping to the kernel.
All other general purpose registers are set to 0. All other general purpose registers are set to 0.
@ -182,6 +183,32 @@ struct limine_bootloader_info_response {
`name` and `version` are 0-terminated ASCII strings containing the name and `name` and `version` are 0-terminated ASCII strings containing the name and
version of the loading bootloader. version of the loading bootloader.
### Stack Size Feature
ID:
```c
#define LIMINE_STACK_SIZE_REQUEST { LIMINE_COMMON_MAGIC, 0x224ef0460a8e8926, 0xe1cb0fc25f46ea3d }
```
Request:
```c
struct limine_stack_size_request {
uint64_t id[4];
uint64_t revision;
struct limine_stack_size_response *response;
uint64_t stack_size;
};
```
* `stack_size` - The requested stack size (also used for SMP processors).
Response:
```c
struct limine_stack_size_response {
uint64_t revision;
};
```
### HHDM (Higher Half Direct Map) Feature ### HHDM (Higher Half Direct Map) Feature
ID: ID:
@ -384,7 +411,7 @@ struct limine_smp_info {
* `processor_id` - ACPI Processor UID as specified by the MADT * `processor_id` - ACPI Processor UID as specified by the MADT
* `lapic_id` - Local APIC ID of the processor as specified by the MADT * `lapic_id` - Local APIC ID of the processor as specified by the MADT
* `goto_address` - An atomic write to this field causes the parked CPU to * `goto_address` - An atomic write to this field causes the parked CPU to
jump to the written address, on a 16KiB stack. A pointer to the jump to the written address, on a 16KiB (or Stack Size Request size) stack. A pointer to the
`struct limine_smp_info` structure of the CPU is passed in `RDI`. Other than `struct limine_smp_info` structure of the CPU is passed in `RDI`. Other than
that, the CPU state will be the same as described for the bootstrap that, the CPU state will be the same as described for the bootstrap
processor. This field is unused for the structure describing the bootstrap processor. This field is unused for the structure describing the bootstrap

View File

@ -348,6 +348,22 @@ FEAT_START
FEAT_END FEAT_END
#endif #endif
// Stack size
uint64_t stack_size = 16384;
FEAT_START
struct limine_stack_size_request *stack_size_request = get_request(LIMINE_STACK_SIZE_REQUEST);
if (stack_size_request == NULL) {
break; // next feature
}
struct limine_stack_size_response *stack_size_response =
ext_mem_alloc(sizeof(struct limine_stack_size_response));
stack_size = stack_size_request->stack_size;
stack_size_request->response = reported_addr(stack_size_response);
FEAT_END
// Kernel file // Kernel file
FEAT_START FEAT_START
struct limine_kernel_file_request *kernel_file_request = get_request(LIMINE_KERNEL_FILE_REQUEST); struct limine_kernel_file_request *kernel_file_request = get_request(LIMINE_KERNEL_FILE_REQUEST);
@ -553,7 +569,7 @@ FEAT_END
local_gdt->ptr_hi = local_gdt_base >> 32; local_gdt->ptr_hi = local_gdt_base >> 32;
#endif #endif
void *stack = ext_mem_alloc(16384) + 16384; void *stack = ext_mem_alloc(stack_size) + stack_size;
pagemap_t pagemap = {0}; pagemap_t pagemap = {0};
pagemap = stivale_build_pagemap(want_5lv, true, ranges, ranges_count, true, pagemap = stivale_build_pagemap(want_5lv, true, ranges, ranges_count, true,
@ -585,8 +601,8 @@ FEAT_START
} }
for (size_t i = 0; i < cpu_count; i++) { for (size_t i = 0; i < cpu_count; i++) {
void *cpu_stack = ext_mem_alloc(16384) + 16384; void *cpu_stack = ext_mem_alloc(stack_size) + stack_size;
smp_info[i].stack_addr = reported_addr(cpu_stack + 16384); smp_info[i].stack_addr = reported_addr(cpu_stack + stack_size);
} }
struct limine_smp_response *smp_response = struct limine_smp_response *smp_response =

View File

@ -52,6 +52,21 @@ struct limine_bootloader_info_request {
LIMINE_PTR(struct limine_bootloader_info_response *) response; LIMINE_PTR(struct limine_bootloader_info_response *) response;
}; };
/* Stack size */
#define LIMINE_STACK_SIZE_REQUEST { LIMINE_COMMON_MAGIC, 0x224ef0460a8e8926, 0xe1cb0fc25f46ea3d }
struct limine_stack_size_response {
uint64_t revision;
};
struct limine_stack_size_request {
uint64_t id[4];
uint64_t revision;
LIMINE_PTR(struct limine_stack_size_response *) response;
uint64_t stack_size;
};
/* HHDM */ /* HHDM */
#define LIMINE_HHDM_REQUEST { LIMINE_COMMON_MAGIC, 0x48dcf1cb8ad2b852, 0x63984e959a98244b } #define LIMINE_HHDM_REQUEST { LIMINE_COMMON_MAGIC, 0x48dcf1cb8ad2b852, 0x63984e959a98244b }