xref: /freebsd/stand/efi/loader/arch/i386/setup.c (revision f8ca5d45c3c1829759ecd87cb95d53e5ab7d0811)
1*f8ca5d45SAhmad Khalifa /*-
2*f8ca5d45SAhmad Khalifa  * SPDX-License-Identifier: BSD-2-Clause
3*f8ca5d45SAhmad Khalifa  *
4*f8ca5d45SAhmad Khalifa  * Copyright (c) 2024 Ahmad Khalifa <ahmadkhalifa570@gmail.com>
5*f8ca5d45SAhmad Khalifa  *
6*f8ca5d45SAhmad Khalifa  * Redistribution and use in source and binary forms, with or without
7*f8ca5d45SAhmad Khalifa  * modification, are permitted provided that the following conditions
8*f8ca5d45SAhmad Khalifa  * are met:
9*f8ca5d45SAhmad Khalifa  * 1. Redistributions of source code must retain the above copyright
10*f8ca5d45SAhmad Khalifa  *    notice, this list of conditions and the following disclaimer.
11*f8ca5d45SAhmad Khalifa  * 2. Redistributions in binary form must reproduce the above copyright
12*f8ca5d45SAhmad Khalifa  *    notice, this list of conditions and the following disclaimer in the
13*f8ca5d45SAhmad Khalifa  *    documentation and/or other materials provided with the distribution.
14*f8ca5d45SAhmad Khalifa  *
15*f8ca5d45SAhmad Khalifa  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
16*f8ca5d45SAhmad Khalifa  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17*f8ca5d45SAhmad Khalifa  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18*f8ca5d45SAhmad Khalifa  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
19*f8ca5d45SAhmad Khalifa  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20*f8ca5d45SAhmad Khalifa  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21*f8ca5d45SAhmad Khalifa  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22*f8ca5d45SAhmad Khalifa  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23*f8ca5d45SAhmad Khalifa  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24*f8ca5d45SAhmad Khalifa  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25*f8ca5d45SAhmad Khalifa  * SUCH DAMAGE.
26*f8ca5d45SAhmad Khalifa  */
27*f8ca5d45SAhmad Khalifa 
28*f8ca5d45SAhmad Khalifa #include <sys/types.h>
29*f8ca5d45SAhmad Khalifa 
30*f8ca5d45SAhmad Khalifa #include <efi.h>
31*f8ca5d45SAhmad Khalifa #include <efilib.h>
32*f8ca5d45SAhmad Khalifa 
33*f8ca5d45SAhmad Khalifa #include <machine/specialreg.h>
34*f8ca5d45SAhmad Khalifa 
35*f8ca5d45SAhmad Khalifa /*
36*f8ca5d45SAhmad Khalifa  * Check for long mode then call efi_main
37*f8ca5d45SAhmad Khalifa  */
38*f8ca5d45SAhmad Khalifa EFI_STATUS
setup(EFI_HANDLE IH,EFI_SYSTEM_TABLE * ST)39*f8ca5d45SAhmad Khalifa setup(EFI_HANDLE IH, EFI_SYSTEM_TABLE *ST) {
40*f8ca5d45SAhmad Khalifa 	u_int edx;
41*f8ca5d45SAhmad Khalifa 
42*f8ca5d45SAhmad Khalifa 	asm("cpuid" : "=d"(edx) : "a"(0x80000001) : "ebx", "ecx");
43*f8ca5d45SAhmad Khalifa 	if ((edx & AMDID_LM) == 0) {
44*f8ca5d45SAhmad Khalifa 		ST->ConOut->OutputString(ST->ConOut, (CHAR16 *)
45*f8ca5d45SAhmad Khalifa 		    L"This CPU doesn't support long mode.\r\n"
46*f8ca5d45SAhmad Khalifa 		    L"Unable to proceed.\r\n");
47*f8ca5d45SAhmad Khalifa 		ST->BootServices->Exit(IH, EFI_UNSUPPORTED, 0, NULL);
48*f8ca5d45SAhmad Khalifa 	}
49*f8ca5d45SAhmad Khalifa 
50*f8ca5d45SAhmad Khalifa 	return (efi_main(IH, ST));
51*f8ca5d45SAhmad Khalifa }
52