2 /* SPDX-License-Identifier: GPL-2.0-only */
4 /* NOTE: THIS CODE MUST REMAIN POSITION INDEPENDENT
5 * IT SHOULDN'T USE THE STACK
6 * AND IN GENERAL EXPECT NOTHING BUT RAM TO WORK
11 #include "linux_trampoline.h"
12 #define HEADER_SIG 0x4f49424c // LBIO little endian
13 #define CB_TAG_FORWARD 0x11
14 #define CB_TAG_MEMORY 0x1
15 #define CB_TAG_FRAMEBUFFER 0x12
17 #define E820_NR_OFFSET 0x1e8
18 #define LINUX_ENTRY_OFFSET 0x214
19 #define E820_OFFSET 0x2d0
31 je .headerSearchDone // found the header
37 cmp %ecx, %ebx // reached the end == not found anything?
40 // we assume the checksum is okay, no test
42 add %ecx, %ebx // ebx = cb_header + header_bytes
43 mov 20(%ecx), %ecx // ecx = table_entries
46 cmp $CB_TAG_FORWARD, (%ebx)
49 /* forward tag: assume 32bit pointer */
54 cmp $CB_TAG_MEMORY, (%ebx)
57 /* memory tag: copy e820 map and entry count. also determine alt_mem_k */
60 shr $2, %eax /* eax = number of dwords of e820 data */
61 cmp $(32 * 5), %eax /* linux wants at most 32 entries of 5 dwords */
63 mov $(32 * 5), %eax /* only copy 32 entries */
68 mov %eax, (LINUX_PARAM_LOC + E820_NR_OFFSET)
71 lea 8(%ebx), %esi /* e820 data source */
72 mov $(LINUX_PARAM_LOC + E820_OFFSET), %edi
78 cmp $CB_TAG_FRAMEBUFFER, (%ebx)
80 /* TODO: handle framebuffer tag */
87 /* Setup basic code and data segment selectors for Linux
89 ** Flat code segment descriptor:
93 ** type : code, execute, read
95 ** Flat data segment descriptor:
99 ** type : data, read/write
101 ** Use TRAMPOLINE_ENTRY_LOC as a scratchpad.
103 mov $TRAMPOLINE_ENTRY_LOC, %eax
104 movl $0x0000ffff, 16(%eax) // Set up the 2 new descriptors
105 movl $0x00cf9b00, 20(%eax)
106 movl $0x0000ffff, 24(%eax)
107 movl $0x00cf9300, 28(%eax)
108 movb $0x2b, 0(%eax) // Set the size
109 movl %eax, 2(%eax) // Set pointer to new GDT
110 lgdt (%eax) // Load it
112 /* finally: jump to kernel */
113 mov $LINUX_PARAM_LOC, %esi
114 jmp *(LINUX_PARAM_LOC + LINUX_ENTRY_OFFSET)