Skip to content

Commit 08ddd83

Browse files
krystian-hebelrossphilipson
authored andcommitted
head: don't test for boot protocol, use hand-off that works for all
Linux, Multiboot2 and simple payload don't have overlapping uses for values passed through registers or stack. All of those can be set at the same time. Signed-off-by: Krystian Hebel <[email protected]>
1 parent 729d480 commit 08ddd83

File tree

3 files changed

+23
-34
lines changed

3 files changed

+23
-34
lines changed

head.S

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -195,13 +195,12 @@ GLOBAL(_entry)
195195
* skl_main() is magic. It returns two pointers by register:
196196
*
197197
* %eax - protected mode kernel entry
198-
* %edx - ZP base
198+
* %edx - argument for kernel entry point, depends on type of kernel
199199
*
200-
* We stash the entry point in %ebx and the Zero Page pointer in %esi.
201-
* This both protects them from clobbering during teardown, and
202-
* matches the ABI for entering Linux.
200+
* We stash the entry point in %edi and the argument in %esi to protect
201+
* them from clobbering during teardown.
203202
*/
204-
mov %eax, %ebx
203+
mov %eax, %edi
205204
mov %edx, %esi
206205

207206
#ifdef __x86_64__
@@ -235,28 +234,28 @@ GLOBAL(_entry)
235234
push $0
236235
popf
237236

238-
mov boot_protocol(%ebp), %edx
239-
cmp $MULTIBOOT2, %edx
240-
je multiboot2_kernel
241-
242-
cmp $SIMPLE_PAYLOAD, %edx
243-
je simple_payload
244-
245-
/* Jump to entry target - EBX: startup_32, ESI: ZP base, EDX: SKL base */
246-
mov %ebp, %edx
247-
jmp *%ebx
248-
249-
multiboot2_kernel:
250-
/* Jump to entry target - EBX: MBI pointer, EAX: Multiboot2 magic number */
251-
xchg %esi, %ebx
237+
/*
238+
* Various kernels use different boot protocols, SKL supports some of
239+
* the common ones. Because of that, we are saving the same argument in
240+
* every possible place that any of the supported kernel types may look
241+
* for it. As of now, supported protocols include:
242+
*
243+
* - Linux x86 protected mode entry, not UEFI
244+
* - Multiboot2, also not UEFI
245+
* - simple payload started as 'entry(u32 arg)' function call. As we
246+
* don't expect it to return, __cdecl, __stdcall and __pascal calling
247+
* conventions work the same.
248+
*/
249+
/* Linux expects Zero Page address in %esi, it is already there */
250+
/* Multiboot2 expects MBI address in %ebx and magic number in %eax */
251+
mov %esi, %ebx
252252
mov $MULTIBOOT2_BOOTLOADER_MAGIC, %eax
253-
jmp *%esi
254-
255-
simple_payload:
256-
/* Jump to entry target - argument and dummy return address on stack */
253+
/* Simple payload expects argument on stack followed by return address */
257254
push %esi
258255
push $0
259-
jmp *%ebx
256+
257+
/* All set, jump to the kernel */
258+
jmp *%edi
260259
ENDFUNC(_entry)
261260

262261
.section .rodata, "a", @progbits

include/defs.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@
2323
*/
2424
#pragma GCC visibility push(hidden)
2525

26-
#define LINUX_BOOT 0
27-
#define SIMPLE_PAYLOAD 1
28-
#define MULTIBOOT2 2
29-
3026
/* Update if code changes significantly. */
3127
#define MAX_STACK_SIZE 0x280
3228

main.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333
#include <printk.h>
3434
#include <dev.h>
3535

36-
u32 boot_protocol;
37-
3836
const skl_info_t __used skl_info = {
3937
.uuid = {
4038
0x78, 0xf1, 0x26, 0x8e, 0x04, 0x92, 0x11, 0xe9,
@@ -438,17 +436,13 @@ static asm_return_t skl_multiboot2(struct tpm *tpm, struct skl_tag_boot_mb2 *skl
438436
reboot();
439437
}
440438

441-
boot_protocol = MULTIBOOT2;
442-
443439
return (asm_return_t){ kernel_entry, _p(skl_tag->mbi) };
444440
}
445441

446442
static asm_return_t skl_simple_payload(struct tpm *tpm, struct skl_tag_boot_simple_payload *skl_tag)
447443
{
448444
extend_pcr(tpm, _p(skl_tag->base), skl_tag->size, 17, "Measured payload into PCR17");
449445

450-
boot_protocol = SIMPLE_PAYLOAD;
451-
452446
return (asm_return_t){ _p(skl_tag->entry), _p(skl_tag->arg) };
453447
}
454448

0 commit comments

Comments
 (0)