blob: 1e0e4a0d3d6b30db99ae3cbf4b0175f662bec596 [file] [log] [blame]
Jordan Crousef6145c32008-03-19 23:56:58 +00001/*
Jordan Crousef6145c32008-03-19 23:56:58 +00002 *
3 * Copyright (C) 2008 Advanced Micro Devices, Inc.
Patrick Rudolphb854ae22017-01-15 10:49:48 +01004 * Copyright (C) 2017 Patrick Rudolph <siro@das-labor.org>
Jordan Crousef6145c32008-03-19 23:56:58 +00005 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
Uwe Hermann6a441bf2008-03-20 19:54:59 +000029
Jordan Crouse20c9cf12008-10-20 16:51:43 +000030 .code32
Mathias Kraused2f16ca2017-02-11 22:47:04 +010031 .global _entry
Jordan Crousef6145c32008-03-19 23:56:58 +000032 .text
33 .align 4
34
Uwe Hermann6a441bf2008-03-20 19:54:59 +000035/*
36 * Our entry point - assume that the CPU is in 32 bit protected mode and
37 * all segments are in a flat model. That's our operating mode, so we won't
38 * change anything.
Jordan Crousef6145c32008-03-19 23:56:58 +000039 */
Jordan Crousef6145c32008-03-19 23:56:58 +000040_entry:
Marc Jones5f145fa2011-10-06 16:38:35 -060041 jmp _init
Jordan Crousef6145c32008-03-19 23:56:58 +000042
Jordan Crouse20c9cf12008-10-20 16:51:43 +000043 .align 4
44
45#define MB_MAGIC 0x1BADB002
46#define MB_FLAGS 0x00010003
47
48mb_header:
49 .long MB_MAGIC
50 .long MB_FLAGS
51 .long -(MB_MAGIC + MB_FLAGS)
52 .long mb_header
53 .long _start
54 .long _edata
55 .long _end
56 .long _init
57
Uwe Hermann6a441bf2008-03-20 19:54:59 +000058/*
59 * This function saves off the previous stack and switches us to our
60 * own execution environment.
61 */
Jordan Crousef6145c32008-03-19 23:56:58 +000062_init:
Uwe Hermann6a441bf2008-03-20 19:54:59 +000063 /* No interrupts, please. */
Jordan Crousef6145c32008-03-19 23:56:58 +000064 cli
65
Jordan Crouse20c9cf12008-10-20 16:51:43 +000066 /* Store EAX and EBX */
Mathias Kraused2f16ca2017-02-11 22:47:04 +010067 movl %eax, loader_eax
68 movl %ebx, loader_ebx
Jordan Crouse20c9cf12008-10-20 16:51:43 +000069
Maximilian Brune9d475bf2023-05-05 15:10:24 +020070 /* save pointer to coreboot tables */
71 movl 4(%esp), %eax
72 movl %eax, cb_header_ptr
Jordan Crousef6145c32008-03-19 23:56:58 +000073
Mathias Kraused2f16ca2017-02-11 22:47:04 +010074 /* Store current stack pointer and set up new stack. */
75 movl %esp, %eax
Yi Chou32ea2ab2023-11-18 12:12:01 +080076 movl $_estack, %esp
Mathias Kraused2f16ca2017-02-11 22:47:04 +010077 pushl %eax
Jordan Crousef6145c32008-03-19 23:56:58 +000078
Patrick Rudolphb854ae22017-01-15 10:49:48 +010079 /* Enable special x86 functions if present. */
80 pushl %eax
81 pushl %ebx
82 pushl %ecx
83 pushl %edx
84
85 movl $0, %eax
86 cpuid
87 /* Test if CPUID(eax=1) is available. */
88 test %eax, %eax
89 je cpuid_done
90
91 /* Get CPU features. */
92 movl $1, %eax
93 cpuid
94
95cpuid_fpu:
96 /* Test if x87 FPU is present */
97 test $1, %edx
98 je cpuid_sse
99
100 fninit
101 movl %cr0, %eax
102 andl $0xFFFFFFFB, %eax /* clear EM */
103 orl $0x00000022, %eax /* set MP, NE */
104 movl %eax, %cr0
105
106cpuid_sse:
107 /* Test if SSE is available */
108 test $0x02000000, %edx
109 je cpuid_done
110
111 movl %cr4, %eax
112 orl $0x00000600, %eax /* set OSFXSR, OSXMMEXCPT */
113 movl %eax, %cr4
114
115cpuid_done:
116 popl %edx
117 popl %ecx
118 popl %ebx
119 popl %eax
120
Klaus Schnass2c6b33c2008-03-31 21:02:29 +0000121 /* Let's rock. */
122 call start_main
Jordan Crouse9dac1b42008-05-20 20:10:49 +0000123
124 /* %eax has the return value - pass it on unmolested */
Jordan Crousef6145c32008-03-19 23:56:58 +0000125_leave:
Klaus Schnass2c6b33c2008-03-31 21:02:29 +0000126 /* Restore old stack. */
Mathias Kraused2f16ca2017-02-11 22:47:04 +0100127 popl %esp
Jordan Crousef6145c32008-03-19 23:56:58 +0000128
Uwe Hermann6a441bf2008-03-20 19:54:59 +0000129 /* Return to the original context. */
Jordan Crouse9dac1b42008-05-20 20:10:49 +0000130 ret