:: commit 21f8640510456a2fc97881f7a6a7cbb93395111f

mintsuki <mintsuki@protonmail.com> — 2022-03-24 01:18

parents: c4f04dab95

docs: limine: Document SMP request

diff --git a/PROTOCOL.md b/PROTOCOL.md
index 8bd8fab1..44ed6a15 100644
--- a/PROTOCOL.md
+++ b/PROTOCOL.md
@@ -10,6 +10,11 @@ the Limine boot protocol is composed of. Other bootloaders may support extra
 unofficial features, but it is strongly recommended to avoid fragmentation
 and submit new features by opening a pull request to this repository.
 
+## General Notes
+
+All pointers are 64-bit wide. All pointers point to the object with the
+higher half direct map offset already added to them, unless otherwise noted.
+
 ## Features
 
 The protocol is centered around the concept of request/response - collectively
@@ -131,12 +136,12 @@ Legacy PIC and IO APIC IRQs are all masked.
 If booted by EFI/UEFI, boot services are exited.
 
 `rsp` is set to point to a stack, in bootloader-reserved memory, which is
-at least 8KiB (8192 bytes) in size. An invalid return address of 0 is pushed
+at least 16KiB (16384 bytes) in size. An invalid return address of 0 is pushed
 to the stack before jumping to the kernel.
 
 All other general purpose registers are set to 0.
 
-# Feature List
+## Feature List
 
 Request IDs are composed of 4 64-bit unsigned integers, but the first 2 are
 common to every request:
@@ -144,7 +149,7 @@ common to every request:
 #define LIMINE_COMMON_MAGIC 0xc7b1dd30df4c8b88, 0x0a82e883a194f07b
 ```
 
-## Bootloader Info Feature
+### Bootloader Info Feature
 
 ID:
 ```c
@@ -172,7 +177,7 @@ struct limine_bootloader_info_response {
 `name` and `version` are 0-terminated ASCII strings containing the name and
 version of the loading bootloader.
 
-## HHDM (Higher Half Direct Map) Feature
+### HHDM (Higher Half Direct Map) Feature
 
 ID:
 ```c
@@ -192,14 +197,14 @@ Response:
 ```c
 struct limine_hhdm_response {
     uint64_t revision;
-    uint64_t address;
+    uint64_t offset;
 };
 ```
 
-* `address` - the virtual address of the beginning of the higher half direct
-map.
+* `offset` - the virtual address offset of the beginning of the higher half
+direct map.
 
-## Framebuffer Feature
+### Framebuffer Feature
 
 ID:
 ```c
@@ -251,7 +256,7 @@ struct limine_framebuffer {
 };
 ```
 
-## 5-Level Paging Feature
+### 5-Level Paging Feature
 
 ID:
 ```c
@@ -276,9 +281,70 @@ struct limine_5_level_paging_response {
 
 Notes: The presence of this request will prompt the bootloader to turn on
 x86_64 5-level paging. It will not be turned on if this request is not present.
-If the response pointer is non-NULL, 5-level paging is engaged.
+If the response pointer is unchanged, 5-level paging is engaged.
+
+### SMP (multiprocessor) Feature
+
+ID:
+```c
+#define LIMINE_SMP_REQUEST { LIMINE_COMMON_MAGIC, 0x95a67b819a1b857e, 0xa0b61b723b6a73e0 }
+```
+
+Request:
+```c
+struct limine_smp_request {
+    uint64_t id[4];
+    uint64_t revision;
+    struct limine_smp_response *response;
+    uint64_t flags;
+};
+```
+
+* `flags` - Bit 0: Enable X2APIC, if possible.
+
+Response:
+```c
+struct limine_smp_response {
+    uint64_t revision;
+    uint32_t flags;
+    uint32_t bsp_lapic_id;
+    uint64_t cpu_count;
+    struct limine_smp_info **cpus;
+};
+```
+
+* `flags` - Bit 0: X2APIC has been enabled.
+* `bsp_lapic_id` - The Local APIC ID of the bootstrap processor.
+* `cpu_count` - How many CPUs are present. It includes the bootstrap processor.
+* `cpus` - Pointer to an array of `cpu_count` pointers to
+`struct limine_smp_info` structures.
+
+Notes: The presence of this request will prompt the bootloader to bootstrap
+the secondary processors. This will not be done if this request is not present.
 
-## Entry Point Feature
+```c
+typedef void (*limine_goto_address)(void);
+
+struct limine_smp_info {
+    uint32_t processor_id;
+    uint32_t lapic_id;
+    uint64_t reserved;
+    limine_goto_address goto_address;
+    uint64_t extra_argument;
+};
+```
+
+* `processor_id` - ACPI Processor UID 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
+jump to the written address, on a 16KiB stack. A pointer to the
+`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
+processor. This field is unused for the structure describing the bootstrap
+processor.
+* `extra_argument` - A free for use field.
+
+### Entry Point Feature
 
 ID:
 ```c
@@ -306,7 +372,88 @@ struct limine_entry_point_response {
 };
 ```
 
-## RSDP Feature
+### Module Feature
+
+ID:
+```c
+#define LIMINE_MODULE_REQUEST { LIMINE_COMMON_MAGIC, 0x3e7e279702be32af, 0xca1c4f3bd1280cee }
+```
+
+Request:
+```c
+struct limine_module_request {
+    uint64_t id[4];
+    uint64_t revision;
+    struct limine_module_response *response;
+};
+```
+
+Response:
+```c
+struct limine_module_response {
+    uint64_t revision;
+    uint64_t module_count;
+    struct limine_module **modules;
+};
+```
+
+* `module_count` - How many modules are present.
+* `modules` - Pointer to an array of `module_count` pointers to
+`struct limine_module` structures.
+
+```c
+struct limine_module {
+    void *base;
+    uint64_t length;
+    char *path;
+    char *cmdline;
+    struct limine_file_location *file_location;
+};
+```
+
+* `base` - The address of the module.
+* `length` - The size of the module.
+* `path` - The bootloader-specific path of the module.
+* `cmdline` - A command line associated with the module.
+* `file_location` - A pointer to the file location structure for the module.
+
+#### File Location Structure
+
+```c
+struct limine_uuid {
+    uint32_t a;
+    uint16_t b;
+    uint16_t c;
+    uint8_t d[8];
+};
+
+struct limine_file_location {
+    uint64_t revision;
+    uint64_t partition_index;
+    uint32_t tftp_ip;
+    uint32_t tftp_port;
+    uint32_t mbr_disk_id;
+    struct limine_uuid gpt_disk_uuid;
+    struct limine_uuid gpt_part_uuid;
+    struct limine_uuid part_uuid;
+};
+```
+
+* `revision` - Revision of the `struct limine_file_location` structure.
+* `partition_index` - 1-based partition index of the volume from which the
+module was loaded. If 0, it means invalid or unpartitioned.
+* `tftp_ip` - If non-0, this is the IP of the TFTP server the file was loaded from.
+* `tftp_port` - Likewise, but port.
+* `mbr_disk_id` - If non-0, this is the ID of the disk the module was loaded
+from as reported in its MBR.
+* `gpt_disk_uuid` - If non-0, this is the UUID of the disk the module was
+loaded from as reported in its GPT.
+* `gpt_part_uuid` - If non-0, this is the UUID of the partition the module
+was loaded from as reported in the GPT.
+* `part_uuid` - If non-0, this is the UUID of the filesystem of the partition
+the module was loaded from.
+
+### RSDP Feature
 
 ID:
 ```c
@@ -332,7 +479,7 @@ struct limine_rsdp_response {
 
 * `address` - Address of the RSDP table.
 
-## SMBIOS Feature
+### SMBIOS Feature
 
 ID:
 ```c
@@ -360,7 +507,7 @@ struct limine_smbios_response {
 * `entry_32` - Address of the 32-bit SMBIOS entry point. NULL if not present.
 * `entry_64` - Address of the 64-bit SMBIOS entry point. NULL if not present.
 
-## EFI System Table Feature
+### EFI System Table Feature
 
 ID:
 ```c
@@ -386,7 +533,7 @@ struct limine_efi_system_table_response {
 
 * `address` - Address of EFI system table.
 
-## Boot Time Feature
+### Boot Time Feature
 
 ID:
 ```c
@@ -412,7 +559,7 @@ struct limine_boot_time_response {
 
 * `boot_time` - The UNIX time on boot, in seconds, taken from the system RTC.
 
-## Kernel Address Feature
+### Kernel Address Feature
 
 ID:
 ```c
@@ -439,83 +586,3 @@ struct limine_kernel_address_response {
 
 * `physical_base` - The physical base address of the kernel.
 * `virtual_base` - The virtual base address of the kernel.
-
-## Module Feature
-
-ID:
-```c
-#define LIMINE_MODULE_REQUEST { LIMINE_COMMON_MAGIC, 0x3e7e279702be32af, 0xca1c4f3bd1280cee }
-```
-
-Request:
-```c
-struct limine_module_request {
-    uint64_t id[4];
-    uint64_t revision;
-    struct limine_module_response *response;
-};
-```
-
-Response:
-```c
-struct limine_module_response {
-    uint64_t revision;
-    uint64_t module_count;
-    struct limine_module **modules;
-};
-```
-
-* `module_count` - How many modules are present.
-* `modules` - Pointer to an array of `module_count` pointers to
-`struct limine_module` structures.
-
-```c
-struct limine_module {
-    uint64_t base;
-    uint64_t length;
-    char *path;
-    char *cmdline;
-    struct limine_file_location *file_location;
-};
-```
-
-* `base` - The address of the module.
-* `length` - The size of the module.
-* `path` - The bootloader-specific path of the module.
-* `cmdline` - A command line associated with the module.
-* `file_location` - A pointer to the file location structure for the module.
-
-### File Location Structure
-
-```c
-struct limine_uuid {
-    uint32_t a;
-    uint16_t b;
-    uint16_t c;
-    uint8_t d[8];
-};
-
-struct limine_file_location {
-    uint64_t revision;
-    uint64_t partition_index;
-    uint32_t tftp_ip;
-    uint32_t tftp_port;
-    uint32_t mbr_disk_id;
-    struct limine_uuid gpt_disk_uuid;
-    struct limine_uuid gpt_part_uuid;
-    struct limine_uuid part_uuid;
-};
-```
-
-* `partition_index` - 1-based partition index of the volume from which the
-module was loaded. If 0, it means invalid or unpartitioned.
-* `tftp_ip` - If non-0, this is the IP of the TFTP server the file was loaded from.
-* `tftp_port` - Likewise, but port.
-* `mbr_disk_id` - If non-0, this is the ID of the disk the module was loaded
-from as reported in its MBR.
-* `gpt_disk_uuid` - If non-0, this is the UUID of the disk the module was
-loaded from as reported in its GPT.
-* `gpt_part_uuid` - If non-0, this is the UUID of the partition the module
-was loaded from as reported in the GPT.
-* `part_uuid` - If non-0, this is the UUID of the filesystem of the partition
-the module was loaded from.
diff --git a/common/limine.h b/common/limine.h
index 78ca2eb1..f591856b 100644
--- a/common/limine.h
+++ b/common/limine.h
@@ -53,7 +53,7 @@ struct limine_bootloader_info_request {
 
 struct limine_hhdm_response {
     uint64_t revision;
-    uint64_t address;
+    uint64_t offset;
 };
 
 struct limine_hhdm_request {
@@ -139,11 +139,13 @@ struct limine_5_level_paging_request {
 
 #define LIMINE_SMP_X2APIC (1 << 0)
 
+typedef void (*limine_goto_address)(void);
+
 struct limine_smp_info {
     uint32_t processor_id;
     uint32_t lapic_id;
     uint64_t reserved;
-    LIMINE_PTR(void *) goto_address;
+    LIMINE_PTR(limine_goto_address) goto_address;
     uint64_t extra_argument;
 };
 
@@ -215,7 +217,7 @@ struct limine_entry_point_request {
 #define LIMINE_MODULE_REQUEST { LIMINE_COMMON_MAGIC, 0x3e7e279702be32af, 0xca1c4f3bd1280cee }
 
 struct limine_module {
-    uint64_t base;
+    LIMINE_PTR(void *) base;
     uint64_t length;
     LIMINE_PTR(char *) path;
     LIMINE_PTR(char *) cmdline;
diff --git a/common/protos/limine.c b/common/protos/limine.c
index 6af8e549..bba01494 100644
--- a/common/protos/limine.c
+++ b/common/protos/limine.c
@@ -279,7 +279,7 @@ FEAT_START
     struct limine_hhdm_response *hhdm_response =
         ext_mem_alloc(sizeof(struct limine_hhdm_response));
 
-    hhdm_response->address = direct_map_offset;
+    hhdm_response->offset = direct_map_offset;
 
     hhdm_request->response = reported_addr(hhdm_response);
 FEAT_END
@@ -455,7 +455,7 @@ FEAT_START
 
 #if defined (__i386__)
     if (stivale2_rt_stack == NULL) {
-        stivale2_rt_stack = ext_mem_alloc(8192);
+        stivale2_rt_stack = ext_mem_alloc(16384);
     }
 
     terminal_response->write = (uintptr_t)(void *)stivale2_term_write_entry;
@@ -548,7 +548,7 @@ FEAT_END
     local_gdt->ptr_hi = local_gdt_base >> 32;
 #endif
 
-    void *stack = ext_mem_alloc(8192) + 8192;
+    void *stack = ext_mem_alloc(16384) + 16384;
 
     pagemap_t pagemap = {0};
     pagemap = stivale_build_pagemap(want_5lv, true, ranges, ranges_count, true,
@@ -580,8 +580,8 @@ FEAT_START
     }
 
     for (size_t i = 0; i < cpu_count; i++) {
-        void *cpu_stack = ext_mem_alloc(8192) + 8192;
-        smp_info[i].stack_addr = reported_addr(cpu_stack + 8192);
+        void *cpu_stack = ext_mem_alloc(16384) + 16384;
+        smp_info[i].stack_addr = reported_addr(cpu_stack + 16384);
     }
 
     struct limine_smp_response *smp_response =
diff --git a/test/limine.c b/test/limine.c
index fb7403b4..732c3848 100644
--- a/test/limine.c
+++ b/test/limine.c
@@ -170,7 +170,7 @@ FEAT_START
     }
     struct limine_hhdm_response *hhdm_response = hhdm_request.response;
     e9_printf("HHDM feature, revision %d", hhdm_response->revision);
-    e9_printf("Higher half direct map at: %x", hhdm_response->address);
+    e9_printf("Higher half direct map at: %x", hhdm_response->offset);
 FEAT_END
 
 FEAT_START
diff --git a/test/limine.cfg b/test/limine.cfg
index 59ecb147..e23faa98 100644
--- a/test/limine.cfg
+++ b/test/limine.cfg
@@ -18,7 +18,7 @@ TERM_BACKDROP=008080
     KERNEL_PATH=${TEST_KERNEL}
     KERNEL_CMDLINE=This is an example kernel command line.
 
-    MODULE_PATH=${BACKGROUND_PATH}
+    MODULE_PATH=${WALLPAPER_PATH}
     MODULE_CMDLINE=This is the first module.
 
     MODULE_PATH=boot:///boot/bg.bmp
tab: 248 wrap: offon