blob: 2bac700bda3b33bd003abe1bdb9cb14bcf2e2d0b [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
Subrata Banikbb937c82024-04-30 05:12:21 +000066#if CONFIG(LP_MULTIBOOT)
Jordan Crouse20c9cf12008-10-20 16:51:43 +000067 /* Store EAX and EBX */
Mathias Kraused2f16ca2017-02-11 22:47:04 +010068 movl %eax, loader_eax
69 movl %ebx, loader_ebx
Subrata Banikbb937c82024-04-30 05:12:21 +000070#endif
Jordan Crouse20c9cf12008-10-20 16:51:43 +000071
Maximilian Brune9d475bf2023-05-05 15:10:24 +020072 /* save pointer to coreboot tables */
73 movl 4(%esp), %eax
74 movl %eax, cb_header_ptr
Jordan Crousef6145c32008-03-19 23:56:58 +000075
Mathias Kraused2f16ca2017-02-11 22:47:04 +010076 /* Store current stack pointer and set up new stack. */
77 movl %esp, %eax
Yi Chou32ea2ab2023-11-18 12:12:01 +080078 movl $_estack, %esp
Mathias Kraused2f16ca2017-02-11 22:47:04 +010079 pushl %eax
Jordan Crousef6145c32008-03-19 23:56:58 +000080
Patrick Rudolphb854ae22017-01-15 10:49:48 +010081 /* Enable special x86 functions if present. */
82 pushl %eax
83 pushl %ebx
84 pushl %ecx
85 pushl %edx
86
87 movl $0, %eax
88 cpuid
89 /* Test if CPUID(eax=1) is available. */
90 test %eax, %eax
91 je cpuid_done
92
93 /* Get CPU features. */
94 movl $1, %eax
95 cpuid
96
97cpuid_fpu:
98 /* Test if x87 FPU is present */
99 test $1, %edx
100 je cpuid_sse
101
102 fninit
103 movl %cr0, %eax
104 andl $0xFFFFFFFB, %eax /* clear EM */
105 orl $0x00000022, %eax /* set MP, NE */
106 movl %eax, %cr0
107
108cpuid_sse:
109 /* Test if SSE is available */
110 test $0x02000000, %edx
111 je cpuid_done
112
113 movl %cr4, %eax
114 orl $0x00000600, %eax /* set OSFXSR, OSXMMEXCPT */
115 movl %eax, %cr4
116
117cpuid_done:
118 popl %edx
119 popl %ecx
120 popl %ebx
121 popl %eax
122
Klaus Schnass2c6b33c2008-03-31 21:02:29 +0000123 /* Let's rock. */
124 call start_main
Jordan Crouse9dac1b42008-05-20 20:10:49 +0000125
126 /* %eax has the return value - pass it on unmolested */
Jordan Crousef6145c32008-03-19 23:56:58 +0000127_leave:
Klaus Schnass2c6b33c2008-03-31 21:02:29 +0000128 /* Restore old stack. */
Mathias Kraused2f16ca2017-02-11 22:47:04 +0100129 popl %esp
Jordan Crousef6145c32008-03-19 23:56:58 +0000130
Uwe Hermann6a441bf2008-03-20 19:54:59 +0000131 /* Return to the original context. */
Jordan Crouse9dac1b42008-05-20 20:10:49 +0000132 ret