Jordan Crouse | f6145c3 | 2008-03-19 23:56:58 +0000 | [diff] [blame] | 1 | /* |
Jordan Crouse | f6145c3 | 2008-03-19 23:56:58 +0000 | [diff] [blame] | 2 | * |
| 3 | * Copyright (C) 2008 Advanced Micro Devices, Inc. |
Patrick Rudolph | b854ae2 | 2017-01-15 10:49:48 +0100 | [diff] [blame] | 4 | * Copyright (C) 2017 Patrick Rudolph <siro@das-labor.org> |
Jordan Crouse | f6145c3 | 2008-03-19 23:56:58 +0000 | [diff] [blame] | 5 | * |
| 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 Hermann | 6a441bf | 2008-03-20 19:54:59 +0000 | [diff] [blame] | 29 | |
Jordan Crouse | 20c9cf1 | 2008-10-20 16:51:43 +0000 | [diff] [blame] | 30 | .code32 |
Mathias Krause | d2f16ca | 2017-02-11 22:47:04 +0100 | [diff] [blame] | 31 | .global _entry |
Jordan Crouse | f6145c3 | 2008-03-19 23:56:58 +0000 | [diff] [blame] | 32 | .text |
| 33 | .align 4 |
| 34 | |
Uwe Hermann | 6a441bf | 2008-03-20 19:54:59 +0000 | [diff] [blame] | 35 | /* |
| 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 Crouse | f6145c3 | 2008-03-19 23:56:58 +0000 | [diff] [blame] | 39 | */ |
Jordan Crouse | f6145c3 | 2008-03-19 23:56:58 +0000 | [diff] [blame] | 40 | _entry: |
Marc Jones | 5f145fa | 2011-10-06 16:38:35 -0600 | [diff] [blame] | 41 | jmp _init |
Jordan Crouse | f6145c3 | 2008-03-19 23:56:58 +0000 | [diff] [blame] | 42 | |
Jordan Crouse | 20c9cf1 | 2008-10-20 16:51:43 +0000 | [diff] [blame] | 43 | .align 4 |
| 44 | |
| 45 | #define MB_MAGIC 0x1BADB002 |
| 46 | #define MB_FLAGS 0x00010003 |
| 47 | |
| 48 | mb_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 Hermann | 6a441bf | 2008-03-20 19:54:59 +0000 | [diff] [blame] | 58 | /* |
| 59 | * This function saves off the previous stack and switches us to our |
| 60 | * own execution environment. |
| 61 | */ |
Jordan Crouse | f6145c3 | 2008-03-19 23:56:58 +0000 | [diff] [blame] | 62 | _init: |
Uwe Hermann | 6a441bf | 2008-03-20 19:54:59 +0000 | [diff] [blame] | 63 | /* No interrupts, please. */ |
Jordan Crouse | f6145c3 | 2008-03-19 23:56:58 +0000 | [diff] [blame] | 64 | cli |
| 65 | |
Jordan Crouse | 20c9cf1 | 2008-10-20 16:51:43 +0000 | [diff] [blame] | 66 | /* Store EAX and EBX */ |
Mathias Krause | d2f16ca | 2017-02-11 22:47:04 +0100 | [diff] [blame] | 67 | movl %eax, loader_eax |
| 68 | movl %ebx, loader_ebx |
Jordan Crouse | 20c9cf1 | 2008-10-20 16:51:43 +0000 | [diff] [blame] | 69 | |
Maximilian Brune | 9d475bf | 2023-05-05 15:10:24 +0200 | [diff] [blame] | 70 | /* save pointer to coreboot tables */ |
| 71 | movl 4(%esp), %eax |
| 72 | movl %eax, cb_header_ptr |
Jordan Crouse | f6145c3 | 2008-03-19 23:56:58 +0000 | [diff] [blame] | 73 | |
Mathias Krause | d2f16ca | 2017-02-11 22:47:04 +0100 | [diff] [blame] | 74 | /* Store current stack pointer and set up new stack. */ |
| 75 | movl %esp, %eax |
Yi Chou | 32ea2ab | 2023-11-18 12:12:01 +0800 | [diff] [blame^] | 76 | movl $_estack, %esp |
Mathias Krause | d2f16ca | 2017-02-11 22:47:04 +0100 | [diff] [blame] | 77 | pushl %eax |
Jordan Crouse | f6145c3 | 2008-03-19 23:56:58 +0000 | [diff] [blame] | 78 | |
Patrick Rudolph | b854ae2 | 2017-01-15 10:49:48 +0100 | [diff] [blame] | 79 | /* 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 | |
| 95 | cpuid_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 | |
| 106 | cpuid_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 | |
| 115 | cpuid_done: |
| 116 | popl %edx |
| 117 | popl %ecx |
| 118 | popl %ebx |
| 119 | popl %eax |
| 120 | |
Klaus Schnass | 2c6b33c | 2008-03-31 21:02:29 +0000 | [diff] [blame] | 121 | /* Let's rock. */ |
| 122 | call start_main |
Jordan Crouse | 9dac1b4 | 2008-05-20 20:10:49 +0000 | [diff] [blame] | 123 | |
| 124 | /* %eax has the return value - pass it on unmolested */ |
Jordan Crouse | f6145c3 | 2008-03-19 23:56:58 +0000 | [diff] [blame] | 125 | _leave: |
Klaus Schnass | 2c6b33c | 2008-03-31 21:02:29 +0000 | [diff] [blame] | 126 | /* Restore old stack. */ |
Mathias Krause | d2f16ca | 2017-02-11 22:47:04 +0100 | [diff] [blame] | 127 | popl %esp |
Jordan Crouse | f6145c3 | 2008-03-19 23:56:58 +0000 | [diff] [blame] | 128 | |
Uwe Hermann | 6a441bf | 2008-03-20 19:54:59 +0000 | [diff] [blame] | 129 | /* Return to the original context. */ |
Jordan Crouse | 9dac1b4 | 2008-05-20 20:10:49 +0000 | [diff] [blame] | 130 | ret |