pxe: add stivale2 pxe server info tag
diff --git a/STIVALE2.md b/STIVALE2.md
index 556403cb..1243fc54 100644
--- a/STIVALE2.md
+++ b/STIVALE2.md
@@ -456,6 +456,17 @@ struct stivale2_smp_info {
} __attribute__((packed));
```
+#### PXE server info structure tag
+
+This tag reports that the kernel has been booted via PXE, and reports the server ip that it was booted from.
+
+```c
+struct stivale2_struct_tag_pxe_server_info {
+ struct stivale2_tag tag; // Identifier: 0x29d1e96239247032
+ uint32_t server_ip; // Server ip in network byte order
+} __attribute__((packed));
+```
+
#### MMIO32 UART tag
This tag reports that there is a memory mapped UART port and its address. To write to this port, write the character, zero extended to a 32 bit unsigned integer to the address provided.
diff --git a/limine-pxe.bin b/limine-pxe.bin
index 1aadc6f4..bebe5bb8 100644
Binary files a/limine-pxe.bin and b/limine-pxe.bin differ
diff --git a/limine.bin b/limine.bin
index ceb9238d..bd30fc22 100644
Binary files a/limine.bin and b/limine.bin differ
diff --git a/stage2.map b/stage2.map
index 48bd1c6f..92f6b4da 100644
Binary files a/stage2.map and b/stage2.map differ
diff --git a/stage2/main.c b/stage2/main.c
index 992fdb5a..6df9a322 100644
--- a/stage2/main.c
+++ b/stage2/main.c
@@ -80,7 +80,7 @@ void entry(uint8_t _boot_drive, int pxe_boot) {
if (!strcmp(proto, "stivale")) {
stivale_load(config, cmdline);
} else if (!strcmp(proto, "stivale2")) {
- stivale2_load(config, cmdline);
+ stivale2_load(config, cmdline, pxe_boot);
} else if (!strcmp(proto, "linux")) {
linux_load(config, cmdline);
} else if (!strcmp(proto, "chainload")) {
diff --git a/stage2/protos/stivale2.c b/stage2/protos/stivale2.c
index e1580486..cdcccdfc 100644
--- a/stage2/protos/stivale2.c
+++ b/stage2/protos/stivale2.c
@@ -23,6 +23,7 @@
#include <fs/file.h>
#include <mm/pmm.h>
#include <stivale/stivale2.h>
+#include <pxe/tftp.h>
#define KASLR_SLIDE_BITMASK 0x03FFFF000u
@@ -50,7 +51,7 @@ static void append_tag(struct stivale2_struct *s, struct stivale2_tag *tag) {
s->tags = (uint64_t)(size_t)tag;
}
-void stivale2_load(char *config, char *cmdline) {
+void stivale2_load(char *config, char *cmdline, bool pxe) {
struct file_handle *kernel = conv_mem_alloc(sizeof(struct file_handle));
char *kernel_path = config_get_value(config, 0, "KERNEL_PATH");
@@ -352,6 +353,15 @@ void stivale2_load(char *config, char *cmdline) {
append_tag(&stivale2_struct, (struct stivale2_tag *)tag);
}
+ {
+ if (pxe) {
+ struct stivale2_struct_tag_pxe_server_info *tag = conv_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);
+ }
+ }
+
stivale_spinup(bits, level5pg && level5pg_requested, pagemap,
entry_point, &stivale2_struct, stivale2_hdr.stack);
}
diff --git a/stage2/protos/stivale2.h b/stage2/protos/stivale2.h
index bc1b519d..8d076822 100644
--- a/stage2/protos/stivale2.h
+++ b/stage2/protos/stivale2.h
@@ -1,6 +1,6 @@
#ifndef __PROTOS__STIVALE2_H__
#define __PROTOS__STIVALE2_H__
-void stivale2_load(char *config, char *cmdline);
+void stivale2_load(char *config, char *cmdline, bool pxe);
#endif
diff --git a/stage2/pxe/tftp.c b/stage2/pxe/tftp.c
index 83435652..51693506 100644
--- a/stage2/pxe/tftp.c
+++ b/stage2/pxe/tftp.c
@@ -6,7 +6,15 @@
#include <mm/pmm.h>
#include <lib/blib.h>
-int tftp_open(struct tftp_file_handle* handle, uint32_t server_ip, uint16_t server_port, const char* name) {
+uint32_t get_boot_server_info() {
+ struct pxenv_get_cached_info cachedinfo = { 0 };
+ cachedinfo.packet_type = 2;
+ pxe_call(PXENV_GET_CACHED_INFO, ((uint16_t)rm_seg(&cachedinfo)), (uint16_t)rm_off(&cachedinfo));
+ struct bootph *ph = (struct bootph*)(void *) (((((uint32_t)cachedinfo.buffer) >> 16) << 4) + (((uint32_t)cachedinfo.buffer) & 0xFFFF));
+ return ph->sip;
+}
+
+int tftp_open(struct tftp_file_handle *handle, uint32_t server_ip, uint16_t server_port, const char *name) {
int ret = 0;
if (!server_ip) {
struct pxenv_get_cached_info cachedinfo = { 0 };
diff --git a/stage2/pxe/tftp.h b/stage2/pxe/tftp.h
index fa248cb1..0d0a64f3 100644
--- a/stage2/pxe/tftp.h
+++ b/stage2/pxe/tftp.h
@@ -47,5 +47,6 @@ struct pxenv_get_file_size {
//server_ip and server_port can be 0 for default
int tftp_open(struct tftp_file_handle* handle, uint32_t server_ip, uint16_t server_port, const char* name);
int tftp_read(void *fd, void *buf, uint64_t loc, uint64_t count);
+uint32_t get_boot_server_info();
#endif
diff --git a/stivale/stivale2.h b/stivale/stivale2.h
index 4c5485e1..4086c7da 100644
--- a/stivale/stivale2.h
+++ b/stivale/stivale2.h
@@ -159,4 +159,11 @@ struct stivale2_struct_tag_smp {
struct stivale2_smp_info smp_info[];
} __attribute__((packed));
+#define STIVALE2_STRUCT_TAG_PXE_SERVER_INFO 0x29d1e96239247032
+
+struct stivale2_struct_tag_pxe_server_info {
+ struct stivale2_tag tag;
+ uint32_t server_ip;
+} __attribute__((packed));
+
#endif
