Skip to content

Commit 533c963

Browse files
committed
re-enable i386 build
1 parent b402baa commit 533c963

File tree

12 files changed

+130
-52
lines changed

12 files changed

+130
-52
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ jobs:
5959
run: |
6060
mkdir -p build
6161
cp ntloader build/
62+
cp ntloader.i386 build/
6263
cp ntloader.arm64 build/
6364
cp initrd.cpio build/
6465
cp fsuuid.exe build/

Makefile

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Versioning information
22
#
3-
VERSION := v3.0.4
3+
VERSION := v3.0.5
4+
WIMBOOT_VERSION := v2.8.0
5+
SBAT_GENERATION := 1
46

57
# Abstract target-independent objects
68
#
@@ -95,6 +97,8 @@ OBJCOPY_arm64 ?= $(CROSS_arm64)$(OBJCOPY)
9597
CFLAGS += -Os -ffreestanding -Wall -W -Werror
9698
CFLAGS += -nostdinc -Iinclude/ -fshort-wchar
9799
CFLAGS += -DVERSION="\"$(VERSION)\""
100+
CFLAGS += -DWIMBOOT_VERSION="\"$(WIMBOOT_VERSION)\""
101+
CFLAGS += -DSBAT_GENERATION="\"$(SBAT_GENERATION)\""
98102
CFLAGS += -include compiler.h
99103
ifneq ($(DEBUG),)
100104
CFLAGS += -DDEBUG=$(DEBUG)
@@ -175,7 +179,7 @@ CFLAGS_arm64 += $(call CFLAGS_COND,arm64)
175179
#
176180
# Final targets
177181

178-
all : ntloader ntloader.x86_64 ntloader.arm64
182+
all : ntloader ntloader.i386 ntloader.x86_64 ntloader.arm64
179183

180184
ntloader : ntloader.x86_64 Makefile
181185
$(CP) $< $@
@@ -184,6 +188,10 @@ ntloader.%.elf : lib.%.a script.lds Makefile
184188
$(LD_$*) $(LDFLAGS) $(LDFLAGS_$*) -T script.lds -o $@ -q \
185189
-Map ntloader.$*.map prefix.$*.o lib.$*.a
186190

191+
ntloader.i386.efi : \
192+
ntloader.%.efi : ntloader.%.elf elf2efi32 Makefile
193+
./elf2efi32 $< $@
194+
187195
ntloader.x86_64.efi ntloader.arm64.efi : \
188196
ntloader.%.efi : ntloader.%.elf elf2efi64 Makefile
189197
./elf2efi64 --hybrid $< $@
@@ -204,6 +212,13 @@ include utils/build.mk
204212
%.i386.s : %.c $(HEADERS) Makefile
205213
$(CC_i386) $(CFLAGS) $(CFLAGS_i386) -S $< -o $@
206214

215+
%.i386.o : %.i386.s i386.i Makefile
216+
$(AS_i386) $(ASFLAGS) $(ASFLAGS_i386) i386.i $< -o $@
217+
218+
lib.i386.a : $(OBJECTS_i386) Makefile
219+
$(RM) -f $@
220+
$(AR_i386) -r -s $@ $(OBJECTS_i386)
221+
207222
###############################################################################
208223
#
209224
# i386 objects to be linked into an x86_64 binary
@@ -255,6 +270,7 @@ lib.arm64.a : $(OBJECTS_arm64) Makefile
255270
clean :
256271
$(RM) -f $(RM_FILES)
257272
$(RM) -f *.s *.o *.a *.elf *.map
273+
$(RM) -f ntloader.i386 ntloader.i386.*
258274
$(RM) -f ntloader.x86_64 ntloader.x86_64.*
259275
$(RM) -f ntloader.arm64 ntloader.arm64.*
260276
$(RM) -f ntloader

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
## Compatibility
77

8-
**Ntloader** supports BIOS (i386) and UEFI (x86_64, arm64) environments.
8+
**Ntloader** supports BIOS (i386) and UEFI (i386, x86_64, arm64) environments.
99
It is recommended to use GRUB2 (>=2.12) or GRUB4DOS to boot NTloader.
1010

1111
## Download

docs/header.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,16 @@
88

99
## Compatibility
1010

11-
**Ntloader** supports BIOS (i386) and UEFI (x86_64, arm64) environments.
11+
**Ntloader** supports BIOS (i386) and UEFI (i386, x86_64, arm64) environments.
1212
It is recommended to use GRUB2 (>=2.12) or GRUB4DOS to boot NTloader.
1313

14+
| Platform | ntloader | ntloader.i386 | ntloader.arm64 |
15+
| :------------ | :-: | :-: | :-: |
16+
| BIOS (i386) | yes | no | no |
17+
| UEFI (i386) | no | yes | no |
18+
| UEFI (x86_64) | yes | no | no |
19+
| UEFI (arm64) | no | no | yes |
20+
1421
## Download
1522

1623
The source code is maintained in a git repository at https://github.com/grub4dos/ntloader.

kern/die.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
*/
3838
void die (const char *fmt, ...)
3939
{
40+
EFI_RUNTIME_SERVICES *rs;
4041
va_list args;
4142

4243
/* Print message */
@@ -50,13 +51,17 @@ void die (const char *fmt, ...)
5051
printf ("\n");
5152

5253
/* Reboot system */
53-
#ifdef __i386__
54-
reboot ();
55-
#else
56-
EFI_RUNTIME_SERVICES *rs = efi_systab->RuntimeServices;
57-
rs->ResetSystem (EfiResetWarm, 0, 0, NULL);
58-
printf ("Failed to reboot\n");
59-
#endif
54+
if (efi_systab)
55+
{
56+
rs = efi_systab->RuntimeServices;
57+
rs->ResetSystem (EfiResetWarm, 0, 0, NULL);
58+
printf ("Failed to reboot\n");
59+
60+
}
61+
else
62+
{
63+
reboot();
64+
}
6065

6166
/* Should be impossible to reach this */
6267
__builtin_unreachable();

kern/efimain.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,27 @@
2727
#include "efidisk.h"
2828
#include "efi/Protocol/LoadedImage.h"
2929

30+
/** SBAT section attributes */
31+
#define __sbat __attribute__ ((section (".sbat"), aligned (512)))
32+
33+
/** SBAT metadata */
34+
#define SBAT_CSV \
35+
/* SBAT version */ \
36+
"sbat,1,SBAT Version,sbat,1," \
37+
"https://github.com/rhboot/shim/blob/main/SBAT.md" \
38+
"\n" \
39+
/* wimboot version */ \
40+
"wimboot," SBAT_GENERATION ",iPXE,wimboot," WIMBOOT_VERSION "," \
41+
"https://ipxe.org/wimboot" \
42+
"\n" \
43+
/* ntloader version */ \
44+
"ntloader," SBAT_GENERATION ",a1ive,ntloader," VERSION "," \
45+
"https://github.com/grub4dos/ntloader" \
46+
"\n"
47+
48+
/** SBAT metadata (with no terminating NUL) */
49+
const char sbat[ sizeof (SBAT_CSV) - 1 ] __sbat = SBAT_CSV;
50+
3051
/**
3152
* Process command line
3253
*

kern/payload.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ static void read_mem_file (struct vdisk_file *file, void *data,
5656
memcpy (data, (file->opaque + offset), len);
5757
}
5858

59-
#ifndef __i386__
6059
/**
6160
* Get architecture-specific boot filename
6261
*
@@ -75,7 +74,6 @@ static const CHAR16 *efi_bootarch (void)
7574
}
7675
return bootarch;
7776
}
78-
#endif
7977

8078
/**
8179
* File handler
@@ -87,17 +85,15 @@ static const CHAR16 *efi_bootarch (void)
8785
*/
8886
static int add_file (const char *name, void *data, size_t len)
8987
{
90-
#ifdef __i386__
91-
const char *bootarch = "bootmgr.exe";
92-
#else
9388
char bootarch[32];
89+
9490
snprintf (bootarch, sizeof (bootarch), "%ls", efi_bootarch());
95-
#endif
9691

9792
vdisk_add_file (name, data, len, read_mem_file);
9893

9994
/* Check for special-case files */
100-
if (strcasecmp (name, bootarch) == 0)
95+
if ((efi_systab && strcasecmp (name, bootarch) == 0) ||
96+
(!efi_systab && strcasecmp (name, "bootmgr.exe") == 0))
10197
{
10298
DBG ("...found bootmgr file %s\n", name);
10399
nt_cmdline->bootmgr_length = len;

libnt/bcd.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "bcd.h"
2929
#include "cmdline.h"
3030
#include "charset.h"
31+
#include "efi.h"
3132

3233
static void
3334
bcd_replace_suffix (const wchar_t *src, const wchar_t *dst)
@@ -351,9 +352,8 @@ bcd_patch_data (void)
351352
bcd_patch_sz (&hive, objects, entry_guid,
352353
BCDOPT_SYSROOT, nt_cmdline->sysroot);
353354

354-
#ifdef __i386__
355-
bcd_replace_suffix (L".efi", L".exe");
356-
#else
357-
bcd_replace_suffix (L".exe", L".efi");
358-
#endif
355+
if (efi_systab)
356+
bcd_replace_suffix (L".exe", L".efi");
357+
else
358+
bcd_replace_suffix (L".efi", L".exe");
359359
}

posix/stdio.c

Lines changed: 46 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -37,26 +37,37 @@
3737
*/
3838
int putchar (int character)
3939
{
40+
EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *conout;
41+
struct bootapp_callback_params params;
42+
wchar_t wbuf[2];
43+
4044
/* Convert LF to CR,LF */
4145
if (character == '\n')
4246
putchar ('\r');
4347

44-
/* Print character to EFI/BIOS console as applicable */
45-
#ifdef __i386__
46-
struct bootapp_callback_params params;
47-
memset (&params, 0, sizeof (params));
48-
params.vector.interrupt = 0x10;
49-
params.eax = (0x0e00 | character);
50-
params.ebx = 0x0007;
51-
call_interrupt (&params);
52-
#else
53-
wchar_t wbuf[2];
54-
EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *conout = efi_systab->ConOut;
55-
wbuf[0] = character;
56-
wbuf[1] = 0;
57-
conout->OutputString (conout, wbuf);
48+
/* Print character to bochs debug port */
49+
#if defined(__i386__) || defined(__x86_64__)
50+
__asm__ __volatile__ ("outb %b0, $0xe9"
51+
: : "a" (character));
5852
#endif
5953

54+
/* Print character to EFI/BIOS console as applicable */
55+
if (efi_systab)
56+
{
57+
conout = efi_systab->ConOut;
58+
wbuf[0] = character;
59+
wbuf[1] = 0;
60+
conout->OutputString (conout, wbuf);
61+
}
62+
else
63+
{
64+
memset (&params, 0, sizeof (params));
65+
params.vector.interrupt = 0x10;
66+
params.eax = (0x0e00 | character);
67+
params.ebx = 0x0007;
68+
call_interrupt (&params);
69+
}
70+
6071
return 0;
6172
}
6273

@@ -67,23 +78,29 @@ int putchar (int character)
6778
*/
6879
int getchar (void)
6980
{
70-
int character;
71-
72-
#ifdef __i386__
73-
struct bootapp_callback_params params;
74-
memset (&params, 0, sizeof (params));
75-
params.vector.interrupt = 0x16;
76-
call_interrupt (&params);
77-
character = params.al;
78-
#else
81+
EFI_BOOT_SERVICES *bs;
82+
EFI_SIMPLE_TEXT_INPUT_PROTOCOL *conin;
7983
EFI_INPUT_KEY key;
8084
UINTN index;
81-
EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
82-
EFI_SIMPLE_TEXT_INPUT_PROTOCOL *conin = efi_systab->ConIn;
83-
bs->WaitForEvent (1, &conin->WaitForKey, &index);
84-
conin->ReadKeyStroke (conin, &key);
85-
character = key.UnicodeChar;
86-
#endif
85+
struct bootapp_callback_params params;
86+
int character;
87+
88+
/* Get character */
89+
if (efi_systab)
90+
{
91+
bs = efi_systab->BootServices;
92+
conin = efi_systab->ConIn;
93+
bs->WaitForEvent (1, &conin->WaitForKey, &index);
94+
conin->ReadKeyStroke (conin, &key);
95+
character = key.UnicodeChar;
96+
}
97+
else
98+
{
99+
memset (&params, 0, sizeof (params));
100+
params.vector.interrupt = 0x16;
101+
call_interrupt (&params);
102+
character = params.al;
103+
}
87104

88105
return character;
89106
}

script.lds

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,18 @@ SECTIONS {
134134
}
135135
_bcd_len = ABSOLUTE ( _ebcd ) - ABSOLUTE ( _bcd );
136136

137+
/* Secure Boot Advanced Targeting (SBAT) section */
138+
_sbat_pos = ( _bcd_pos + _bcd_len );
139+
.sbat : AT ( _sbat_pos ) {
140+
_sbat = .;
141+
*(.sbat)
142+
*(.sbat.*)
143+
_esbat = .;
144+
ASSERT ( ABSOLUTE ( . ) <= ABSOLUTE ( _ebda_start ),
145+
"Binary is too large (overlap the EBDA)" );
146+
}
147+
_sbat_len = ABSOLUTE ( _esbat ) - ABSOLUTE ( _sbat );
148+
137149
_end = .;
138150

139151
/* Symbols required by i386.x86_64 objects */

0 commit comments

Comments
 (0)