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 | |
Subrata Banik | bb937c8 | 2024-04-30 05:12:21 +0000 | [diff] [blame^] | 66 | #if CONFIG(LP_MULTIBOOT) |
Jordan Crouse | 20c9cf1 | 2008-10-20 16:51:43 +0000 | [diff] [blame] | 67 | /* Store EAX and EBX */ |
Mathias Krause | d2f16ca | 2017-02-11 22:47:04 +0100 | [diff] [blame] | 68 | movl %eax, loader_eax |
| 69 | movl %ebx, loader_ebx |
Subrata Banik | bb937c8 | 2024-04-30 05:12:21 +0000 | [diff] [blame^] | 70 | #endif |
Jordan Crouse | 20c9cf1 | 2008-10-20 16:51:43 +0000 | [diff] [blame] | 71 | |
Maximilian Brune | 9d475bf | 2023-05-05 15:10:24 +0200 | [diff] [blame] | 72 | /* save pointer to coreboot tables */ |
| 73 | movl 4(%esp), %eax |
| 74 | movl %eax, cb_header_ptr |
Jordan Crouse | f6145c3 | 2008-03-19 23:56:58 +0000 | [diff] [blame] | 75 | |
Mathias Krause | d2f16ca | 2017-02-11 22:47:04 +0100 | [diff] [blame] | 76 | /* Store current stack pointer and set up new stack. */ |
| 77 | movl %esp, %eax |
Yi Chou | 32ea2ab | 2023-11-18 12:12:01 +0800 | [diff] [blame] | 78 | movl $_estack, %esp |
Mathias Krause | d2f16ca | 2017-02-11 22:47:04 +0100 | [diff] [blame] | 79 | pushl %eax |
Jordan Crouse | f6145c3 | 2008-03-19 23:56:58 +0000 | [diff] [blame] | 80 | |
Patrick Rudolph | b854ae2 | 2017-01-15 10:49:48 +0100 | [diff] [blame] | 81 | /* 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 | |
| 97 | cpuid_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 | |
| 108 | cpuid_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 | |
| 117 | cpuid_done: |
| 118 | popl %edx |
| 119 | popl %ecx |
| 120 | popl %ebx |
| 121 | popl %eax |
| 122 | |
Klaus Schnass | 2c6b33c | 2008-03-31 21:02:29 +0000 | [diff] [blame] | 123 | /* Let's rock. */ |
| 124 | call start_main |
Jordan Crouse | 9dac1b4 | 2008-05-20 20:10:49 +0000 | [diff] [blame] | 125 | |
| 126 | /* %eax has the return value - pass it on unmolested */ |
Jordan Crouse | f6145c3 | 2008-03-19 23:56:58 +0000 | [diff] [blame] | 127 | _leave: |
Klaus Schnass | 2c6b33c | 2008-03-31 21:02:29 +0000 | [diff] [blame] | 128 | /* Restore old stack. */ |
Mathias Krause | d2f16ca | 2017-02-11 22:47:04 +0100 | [diff] [blame] | 129 | popl %esp |
Jordan Crouse | f6145c3 | 2008-03-19 23:56:58 +0000 | [diff] [blame] | 130 | |
Uwe Hermann | 6a441bf | 2008-03-20 19:54:59 +0000 | [diff] [blame] | 131 | /* Return to the original context. */ |
Jordan Crouse | 9dac1b4 | 2008-05-20 20:10:49 +0000 | [diff] [blame] | 132 | ret |