diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 239039b..f3d47cd 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -65,7 +65,6 @@ jobs: cp fsuuid.exe build/ cp bmtool.exe build/ cp mkinitrd.exe build/ - cp utils/bcd.bat build/ - name: Download README.pdf uses: actions/download-artifact@v4 with: diff --git a/.gitignore b/.gitignore index 5f35f13..c4e9779 100644 --- a/.gitignore +++ b/.gitignore @@ -17,8 +17,10 @@ mkinitrd mkinitrd.exe bmtools bmtools.exe +bin2c ntloader.i386 ntloader.arm64 ntloader.x86_64 initrd.cpio docs/README.md +include/bcd_raw.h diff --git a/Makefile b/Makefile index b5bc70e..abe74c4 100644 --- a/Makefile +++ b/Makefile @@ -199,6 +199,9 @@ ntloader.%.efi : ntloader.%.elf elf2efi64 Makefile ntloader.% : ntloader.%.efi Makefile $(CP) $< $@ +# Utilities +include utils/build.mk + ############################################################################### # # i386 objects @@ -260,9 +263,6 @@ lib.arm64.a : $(OBJECTS_arm64) Makefile $(RM) -f $@ $(AR_arm64) -r -s $@ $(OBJECTS_arm64) -# Utilities -include utils/build.mk - ############################################################################### # # Cleanup diff --git a/docs/utils.md b/docs/utils.md index fbc29cb..3ed3b82 100644 --- a/docs/utils.md +++ b/docs/utils.md @@ -29,10 +29,5 @@ find * | cpio -o -H newc > ../initrd.cpio ### bmtool `bmtool` is a program for extracting bootmgr.exe from bootmgr. -### bcd.bat -`bcd.bat` is a batch script to create the BCD file. -Do not edit it unless you know how NTloader works. -:warning: Administrator privileges are required. -
diff --git a/kern/payload.c b/kern/payload.c index 65f92a9..fa81aa0 100644 --- a/kern/payload.c +++ b/kern/payload.c @@ -30,6 +30,18 @@ #include "cmdline.h" #include "efi.h" +#ifdef __x86_64__ +extern unsigned char +__i386_bcd_raw[] __attribute__ ((section (".bcd"), aligned (512))); +extern unsigned int __i386_bcd_raw_len; +#define BCD_RAW __i386_bcd_raw +#define BCD_LEN __i386_bcd_raw_len +#else +#include "bcd_raw.h" +#define BCD_RAW bcd_raw +#define BCD_LEN bcd_raw_len +#endif + /** * Read virtual file from memory * @@ -87,12 +99,6 @@ static int add_file (const char *name, void *data, size_t len) nt_cmdline->bootmgr_length = len; nt_cmdline->bootmgr = data; } - else if (strcasecmp (name, "BCD") == 0) - { - DBG ("...found BCD\n"); - nt_cmdline->bcd_length = len; - nt_cmdline->bcd = data; - } return 0; } @@ -105,6 +111,12 @@ static int add_file (const char *name, void *data, size_t len) */ void extract_initrd (void *ptr, size_t len) { + nt_cmdline->bcd_length = BCD_LEN; + nt_cmdline->bcd = BCD_RAW; + printf ("...load BCD @%p %c%c%c%c [%x]\n", BCD_RAW, + BCD_RAW[0], BCD_RAW[1], BCD_RAW[2], BCD_RAW[3], BCD_LEN); + vdisk_add_file ("BCD", BCD_RAW, BCD_LEN, read_mem_file); + if (cpio_extract (ptr, len, add_file) != 0) die ("FATAL: could not extract initrd files\n"); diff --git a/prefix.S b/prefix.S index eb0e84d..d224d9d 100644 --- a/prefix.S +++ b/prefix.S @@ -171,6 +171,15 @@ setup: cld rep movsb + /* Copy bcd */ + movl $(LOADED_HIGH_ADDRESS + _payload_pos - SETUP_LEN), %eax + addl $_payload_len, %eax + movl %eax, %esi + movl $_bcd, %edi + movl $_bcd_len, %ecx + cld + rep movsb + /* Copy parameters required by runtime */ movl %cs:( cmd_line_ptr - _prefix ), %eax movl %eax, i386(cmdline) diff --git a/script.lds b/script.lds index 4484037..1fc7528 100644 --- a/script.lds +++ b/script.lds @@ -122,8 +122,20 @@ SECTIONS { } _bss_len = ABSOLUTE ( _ebss ) - ABSOLUTE ( _bss ); + /* Windows Boot Configuration Data (BCD) section */ + _bcd_pos = ( _text_pos + _text_len ); + .bcd : AT ( _bcd_pos ) { + _bcd = .; + *(.bcd) + *(.bcd.*) + _ebcd = .; + ASSERT ( ABSOLUTE ( . ) <= ABSOLUTE ( _ebda_start ), + "Binary is too large (overlap the EBDA)" ); + } + _bcd_len = ABSOLUTE ( _ebcd ) - ABSOLUTE ( _bcd ); + /* Secure Boot Advanced Targeting (SBAT) section */ - _sbat_pos = ( _text_pos + _text_len ); + _sbat_pos = ( _bcd_pos + _bcd_len ); .sbat : AT ( _sbat_pos ) { _sbat = .; *(.sbat) diff --git a/utils/rootfs/bcd b/utils/bcd similarity index 100% rename from utils/rootfs/bcd rename to utils/bcd diff --git a/utils/bin2c.c b/utils/bin2c.c new file mode 100644 index 0000000..7e38bd4 --- /dev/null +++ b/utils/bin2c.c @@ -0,0 +1,84 @@ +/* + * This is bin2c program, which allows you to convert binary file to + * C language array, for use as embedded resource, for instance you + * can embed graphics or audio file directly into your program. + * This is public domain software, use it on your own risk. + * Contact Serge Fukanchik at fuxx@mail.ru if you have any questions. + * + * Some modifications were made by + * Gwilym Kuiper (kuiper.gwilym@gmail.com) + * I have decided not to change the licence. + */ + +#include