Sfoglia il codice sorgente

在EFI config table安装DRAGONSTUB_EFI_PAYLOAD_EFI_GUID (#13)

其值为

```
(EFI_GUID) { 0xddf1d47c, 0x102c & 0xffff, 0xaaf9 & 0xffff, { 0xce, 0x34, 0xbc, 0xef, 0x98, 0x12, 0x00, 0x31 } }
```

内容为内核被加载到的物理地址以及空间大小
LoGin 1 anno fa
parent
commit
7fc3806da7
2 ha cambiato i file con 42 aggiunte e 1 eliminazioni
  1. 27 0
      apps/elf.c
  2. 15 1
      inc/dragonstub/dragonstub.h

+ 27 - 0
apps/elf.c

@@ -2,6 +2,7 @@
 #include "dragonstub/linux-efi.h"
 #include "dragonstub/linux/align.h"
 #include "dragonstub/printk.h"
+#include "dragonstub/riscv64.h"
 #include "dragonstub/types.h"
 #include "efidef.h"
 #include <efi.h>
@@ -450,5 +451,31 @@ efi_status_t load_elf(struct payload_info *payload_info)
 	efi_debug("image_size: %d\n", image_size);
 	efi_remap_image_all_rwx((u64)&_start, (image_size + 4095) & ~4095);
 
+	// 添加地址到efi configuration table
+
+	struct dragonstub_payload_efi *tbl = NULL;
+	status = efi_bs_call(AllocatePool, EfiLoaderData,
+			     sizeof(struct dragonstub_payload_efi),
+			     (void **)&tbl);
+
+	if (status != EFI_SUCCESS) {
+		efi_err("Failed to allocate memory for dragonstub_payload_efi\n");
+		return status;
+	}
+
+	tbl->payload_addr = payload_info->payload_addr;
+	tbl->payload_size = payload_info->payload_size;
+
+	efi_guid_t dragonstub_payload_efi_guid =
+		DRAGONSTUB_EFI_PAYLOAD_EFI_GUID;
+
+	status = efi_bs_call(InstallConfigurationTable,
+			     &dragonstub_payload_efi_guid, tbl);
+
+	if (status != EFI_SUCCESS) {
+		efi_err("Failed to install dragonstub_payload_efi\n");
+		return status;
+	}
+
 	return EFI_SUCCESS;
 }

+ 15 - 1
inc/dragonstub/dragonstub.h

@@ -464,4 +464,18 @@ union efi_memory_attribute_protocol {
 		u32 set_memory_attributes;
 		u32 clear_memory_attributes;
 	} mixed_mode;
-};
+};
+
+/**
+ * 安装到efi config table的信息
+ * 
+ * 表示dragonstub加载的内核的地址和大小
+*/
+struct dragonstub_payload_efi {
+	u64 payload_addr;
+	u64 payload_size;
+};
+
+#define DRAGONSTUB_EFI_PAYLOAD_EFI_GUID                               \
+	MAKE_EFI_GUID(0xddf1d47c, 0x102c, 0xaaf9, 0xce, 0x34, 0xbc, 0xef, \
+		      0x98, 0x12, 0x00, 0x31)