1/*
2 * Copyright (c) 2019 Intel Corporation
3 * SPDX-License-Identifier: Apache-2.0
4 */
5
6#include <zephyr/arch/x86/multiboot.h>
7#include <zephyr/devicetree.h>
8
9/*
10 * This is included by ia32/crt0.S and intel64/locore.S
11 * at their 32-bit entry points to cover common ground.
12 */
13
14#ifdef CONFIG_MULTIBOOT_INFO
15        /*
16         * If we were loaded by a multiboot-compliant loader, then EAX
17         * contains MULTIBOOT_EAX_MAGIC and EBX points to a valid 'struct
18         * multiboot_info'; otherwise EBX is just junk. Check EAX early
19	 * before it's clobbered and leave a sentinel (0) in EBX if invalid.
20	 * The valid in EBX will be the argument to z_prep_c(), so the
21	 * subsequent code must, of course, be sure to preserve it meanwhile.
22	 */
23
24	cmpl $MULTIBOOT_EAX_MAGIC, %eax
25
26#ifndef CONFIG_DYNAMIC_BOOTARGS
27	je 1f
28	xorl %ebx, %ebx
291:
30#else
31	movl $multiboot_cmdline, %edi
32	je setup_copy_cmdline
33	xorl %ebx, %ebx
34	jmp end_cmdline
35
36setup_copy_cmdline:
37	testl $MULTIBOOT_INFO_FLAGS_CMDLINE, __multiboot_info_t_flags_OFFSET(%ebx)
38	jz end_cmdline
39
40	movl $multiboot_cmdline + CONFIG_BOOTARGS_ARGS_BUFFER_SIZE - 1, %edx
41	movl __multiboot_info_t_cmdline_OFFSET(%ebx), %esi
42copy_cmdline:
43	cmpl %esi, %edx
44	je end_cmdline
45	cmpb $0, (%esi)
46	je end_cmdline
47
48	movsb
49	jmp copy_cmdline
50end_cmdline:
51	movb $0, (%edi)
52#endif
53
54#endif
55
56#ifdef CONFIG_PIC_DISABLE
57	/*
58	 * "Disable" legacy i8259 interrupt controllers. Note that we
59	 * can't actually disable them, but we mask all their interrupt
60	 * sources which is effectively the same thing (almost).
61	 */
62
63	movb $0xff, %al
64	outb %al, $0x21
65	outb %al, $0xA1
66#endif
67
68#ifdef CONFIG_MULTIBOOT
69	jmp 1f
70
71	.align 4
72	.long MULTIBOOT_HEADER_MAGIC
73	.long MULTIBOOT_HEADER_FLAGS
74	.long -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
75#if DT_HAS_COMPAT_STATUS_OKAY(intel_multiboot_framebuffer)
76	.fill 5,4,0							/* (unused exec layout) */
77	.long 0								/* linear graphics mode */
78	.long DT_PROP(DT_INST(0, intel_multiboot_framebuffer), width)	/* width */
79	.long DT_PROP(DT_INST(0, intel_multiboot_framebuffer), height)	/* height */
80	.long 32							/* depth */
81#endif
821:
83#endif
84