From 1df447c91dcfe497348a4980e565144b943fa000 Mon Sep 17 00:00:00 2001 From: "Chloe M." Date: Tue, 23 Jun 2026 02:34:13 +0000 Subject: [PATCH] stos: ke: Add PBI image parser Signed-off-by: Chloe M. --- paw/stos/ex/pbi.c | 90 ++++++++++++++++++++++++++++++++++++++++++ paw/stos/head/ex/pbi.h | 39 ++++++++++++++++++ paw/stos/ke/Makefile | 1 + 3 files changed, 130 insertions(+) create mode 100644 paw/stos/ex/pbi.c create mode 100644 paw/stos/head/ex/pbi.h diff --git a/paw/stos/ex/pbi.c b/paw/stos/ex/pbi.c new file mode 100644 index 0000000..1485f91 --- /dev/null +++ b/paw/stos/ex/pbi.c @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2026, Chloe M. + * Provided under the BSD-3 clause. + * + * Description: Pre-boot image manager + * Author: Chloe M. + */ + +#include +#include +#include +#include + +#define REF_MAGIC "CUMHOLE" +#define REF_MAGIC_LEN 8 +#define REF_PATH_LEN 256 + +static BPAL_MODULE Pbi; + +/* + * A reference is an entry within the table that refers + * to a block of data after the reference table. + * + * @Magic: Reference magic + * @Path: File path + * @Size: File size + * @DataOff: Data offset + */ +typedef PACKED struct { + CHAR Magic[REF_MAGIC_LEN]; + CHAR Path[REF_PATH_LEN]; + USIZE Size; + USIZE DataOff; +} HOLE_REF; + +ST_STATUS +ExPbiLookup(CHAR *Path, EX_BPI_FILE *Result) +{ + HOLE_REF *Ref; + USIZE PathLen; + + if (Path == NULL || Result == NULL) { + return STATUS_INVALID_PARAM; + } + + if (*Path != '/') { + return STATUS_NOT_FOUND; + } + + ++Path; + Ref = Pbi.Data; + PathLen = RtlStrLen(Path); + + for (;;) { + if (RtlMemCmp(Ref->Magic, REF_MAGIC, REF_MAGIC_LEN) != 0) { + break; + } + + if (Ref->Path[0] != *Path) { + ++Ref; + continue; + } + + if (RtlMemCmp(Ref->Path, Path, PathLen) == 0) { + Result->Data = PTR_OFFSET(Pbi.Data, Ref->DataOff); + Result->Size = Ref->Size; + return STATUS_SUCCESS; + } + + ++Ref; + } + + return STATUS_NOT_FOUND; +} + +ST_STATUS +ExPbiInit(VOID) +{ + BPAL_HANDLE Bpal; + ST_STATUS Status; + + KeBpalGetHandle(&Bpal); + + Status = Bpal.ModuleLookup("/boot/pbi.hole", &Pbi); + if (Status != STATUS_SUCCESS) { + return Status; + } + + return STATUS_SUCCESS; +} diff --git a/paw/stos/head/ex/pbi.h b/paw/stos/head/ex/pbi.h new file mode 100644 index 0000000..0b597be --- /dev/null +++ b/paw/stos/head/ex/pbi.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2026, Chloe M. + * Provided under the BSD-3 clause. + * + * Description: Pre-boot image manager + * Author: Chloe M. + */ + +#ifndef _EX_PBI_H_ +#define _EX_PBI_H_ 1 + +#include +#include + +/* + * Represents an BPI file + * + * @Data: Actual raw data + * @Size: Byte count + */ +typedef struct { + VOID *Data; + USIZE Size; +} EX_BPI_FILE; + +/* + * Look up a file from the pre-boot image + * + * @Path: Path to file to lookup + * @Result: Result is written here + */ +ST_STATUS ExPbiLookup(CHAR *Path, EX_BPI_FILE *Result); + +/* + * Initialize the pre-boot image manaer + */ +ST_STATUS ExPbiInit(VOID); + +#endif /* !_EX_PBI_H_ */ diff --git a/paw/stos/ke/Makefile b/paw/stos/ke/Makefile index 1ddab20..3fc0cb7 100644 --- a/paw/stos/ke/Makefile +++ b/paw/stos/ke/Makefile @@ -14,6 +14,7 @@ CFILES += $(shell find ../xt -name "*.c") CFILES += $(shell find ../lib -name "*.c") CFILES += $(shell find ../drivers -name "*.c") CFILES += $(shell find ../mm -name "*.c") +CFILES += $(shell find ../ex -name "*.c") CFILES += $(shell find bpal -name "*.c") DFILES = $(CFILES:.c=.d) OFILES = $(CFILES:.c=.o)