xref: /DragonStub/inc/loongarch64/efibind.h (revision c2102ae05917d81ffc7b854003415e575fc90764)
1e7db4418Szhoumingtao /*
2e7db4418Szhoumingtao  * Copright (C) 2014 - 2015 Linaro Ltd.
3e7db4418Szhoumingtao  * Author: Ard Biesheuvel <ard.biesheuvel@linaro.org>
4e7db4418Szhoumingtao  * Copright (C) 2017 Lemote Co.
5e7db4418Szhoumingtao  * Author: Heiher <r@hev.cc>
6e7db4418Szhoumingtao  * Copright (C) 2021 Loongson Technology Corporation Limited.
7e7db4418Szhoumingtao  * Author: zhoumingtao <zhoumingtao@loongson.cn>
8e7db4418Szhoumingtao  *
9e7db4418Szhoumingtao  * Redistribution and use in source and binary forms, with or without
10e7db4418Szhoumingtao  * modification, are permitted provided that the following conditions
11e7db4418Szhoumingtao  * are met:
12e7db4418Szhoumingtao  * 1. Redistributions of source code must retain the above copyright
13e7db4418Szhoumingtao  *    notice and this list of conditions, without modification.
14e7db4418Szhoumingtao  * 2. The name of the author may not be used to endorse or promote products
15e7db4418Szhoumingtao  *    derived from this software without specific prior written permission.
16e7db4418Szhoumingtao  *
17e7db4418Szhoumingtao  * Alternatively, this software may be distributed under the terms of the
18e7db4418Szhoumingtao  * GNU General Public License as published by the Free Software Foundation;
19e7db4418Szhoumingtao  * either version 2 of the License, or (at your option) any later version.
20e7db4418Szhoumingtao  */
21e7db4418Szhoumingtao 
22e7db4418Szhoumingtao #if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L ) && !defined(__cplusplus)
23e7db4418Szhoumingtao 
24e7db4418Szhoumingtao // ANSI C 1999/2000 stdint.h integer width declarations
25e7db4418Szhoumingtao 
26e7db4418Szhoumingtao typedef unsigned long       uint64_t;
27e7db4418Szhoumingtao typedef long                int64_t;
28e7db4418Szhoumingtao typedef unsigned int        uint32_t;
29e7db4418Szhoumingtao typedef int                 int32_t;
30e7db4418Szhoumingtao typedef unsigned short      uint16_t;
31e7db4418Szhoumingtao typedef short               int16_t;
32e7db4418Szhoumingtao typedef unsigned char       uint8_t;
33*5849eacdSzhoumingtao typedef signed char         int8_t;
34e7db4418Szhoumingtao typedef uint64_t            uintptr_t;
35e7db4418Szhoumingtao typedef int64_t             intptr_t;
36e7db4418Szhoumingtao 
37e7db4418Szhoumingtao #else
38e7db4418Szhoumingtao #include <stdint.h>
39e7db4418Szhoumingtao #endif
40e7db4418Szhoumingtao 
41e7db4418Szhoumingtao //
42e7db4418Szhoumingtao // Basic EFI types of various widths
43e7db4418Szhoumingtao //
44e7db4418Szhoumingtao 
45e7db4418Szhoumingtao #ifndef __WCHAR_TYPE__
46e7db4418Szhoumingtao # define __WCHAR_TYPE__ short
47e7db4418Szhoumingtao #endif
48e7db4418Szhoumingtao 
49e7db4418Szhoumingtao typedef uint64_t   UINT64;
50e7db4418Szhoumingtao typedef int64_t    INT64;
51e7db4418Szhoumingtao 
52e7db4418Szhoumingtao typedef uint32_t   UINT32;
53e7db4418Szhoumingtao typedef int32_t    INT32;
54e7db4418Szhoumingtao 
55e7db4418Szhoumingtao typedef uint16_t   UINT16;
56e7db4418Szhoumingtao typedef int16_t    INT16;
57e7db4418Szhoumingtao typedef uint8_t    UINT8;
58e7db4418Szhoumingtao typedef int8_t     INT8;
59e7db4418Szhoumingtao typedef __WCHAR_TYPE__ WCHAR;
60e7db4418Szhoumingtao 
61e7db4418Szhoumingtao #undef VOID
62e7db4418Szhoumingtao #define VOID    void
63e7db4418Szhoumingtao 
64e7db4418Szhoumingtao typedef int64_t    INTN;
65e7db4418Szhoumingtao typedef uint64_t   UINTN;
66e7db4418Szhoumingtao 
67e7db4418Szhoumingtao #define EFIERR(a)           (0x8000000000000000 | a)
68e7db4418Szhoumingtao #define EFI_ERROR_MASK      0x8000000000000000
69e7db4418Szhoumingtao #define EFIERR_OEM(a)       (0xc000000000000000 | a)
70e7db4418Szhoumingtao 
71e7db4418Szhoumingtao #define BAD_POINTER         0xFBFBFBFBFBFBFBFB
72e7db4418Szhoumingtao #define MAX_ADDRESS         0xFFFFFFFFFFFFFFFF
73e7db4418Szhoumingtao 
74e7db4418Szhoumingtao #define BREAKPOINT()        while (TRUE);    // Make it hang on Bios[Dbg]32
75e7db4418Szhoumingtao 
76e7db4418Szhoumingtao //
77e7db4418Szhoumingtao // Pointers must be aligned to these address to function
78e7db4418Szhoumingtao //
79e7db4418Szhoumingtao 
80e7db4418Szhoumingtao #define MIN_ALIGNMENT_SIZE  8
81e7db4418Szhoumingtao 
82e7db4418Szhoumingtao #define ALIGN_VARIABLE(Value ,Adjustment) \
83e7db4418Szhoumingtao             (UINTN)Adjustment = 0; \
84e7db4418Szhoumingtao             if((UINTN)Value % MIN_ALIGNMENT_SIZE) \
85e7db4418Szhoumingtao                 (UINTN)Adjustment = MIN_ALIGNMENT_SIZE - ((UINTN)Value % MIN_ALIGNMENT_SIZE); \
86e7db4418Szhoumingtao             Value = (UINTN)Value + (UINTN)Adjustment
87e7db4418Szhoumingtao 
88e7db4418Szhoumingtao 
89e7db4418Szhoumingtao //
90e7db4418Szhoumingtao // Define macros to build data structure signatures from characters.
91e7db4418Szhoumingtao //
92e7db4418Szhoumingtao 
93e7db4418Szhoumingtao #define EFI_SIGNATURE_16(A,B)             ((A) | (B<<8))
94e7db4418Szhoumingtao #define EFI_SIGNATURE_32(A,B,C,D)         (EFI_SIGNATURE_16(A,B)     | (EFI_SIGNATURE_16(C,D)     << 16))
95e7db4418Szhoumingtao #define EFI_SIGNATURE_64(A,B,C,D,E,F,G,H) (EFI_SIGNATURE_32(A,B,C,D) | ((UINT64)(EFI_SIGNATURE_32(E,F,G,H)) << 32))
96e7db4418Szhoumingtao 
97e7db4418Szhoumingtao //
98e7db4418Szhoumingtao // EFIAPI - prototype calling convention for EFI function pointers
99e7db4418Szhoumingtao // BOOTSERVICE - prototype for implementation of a boot service interface
100e7db4418Szhoumingtao // RUNTIMESERVICE - prototype for implementation of a runtime service interface
101e7db4418Szhoumingtao // RUNTIMEFUNCTION - prototype for implementation of a runtime function that is not a service
102e7db4418Szhoumingtao // RUNTIME_CODE - pragma macro for declaring runtime code
103e7db4418Szhoumingtao //
104e7db4418Szhoumingtao 
105e7db4418Szhoumingtao #ifndef EFIAPI          // Forces EFI calling conventions reguardless of compiler options
106e7db4418Szhoumingtao #define EFIAPI          // Substitute expresion to force C calling convention
107e7db4418Szhoumingtao #endif
108e7db4418Szhoumingtao 
109e7db4418Szhoumingtao #define BOOTSERVICE
110e7db4418Szhoumingtao #define RUNTIMESERVICE
111e7db4418Szhoumingtao #define RUNTIMEFUNCTION
112e7db4418Szhoumingtao 
113e7db4418Szhoumingtao 
114e7db4418Szhoumingtao #define RUNTIME_CODE(a)         alloc_text("rtcode", a)
115e7db4418Szhoumingtao #define BEGIN_RUNTIME_DATA()    data_seg("rtdata")
116e7db4418Szhoumingtao #define END_RUNTIME_DATA()      data_seg("")
117e7db4418Szhoumingtao 
118e7db4418Szhoumingtao #define VOLATILE                volatile
119e7db4418Szhoumingtao 
120e7db4418Szhoumingtao #define MEMORY_FENCE            __sync_synchronize
121e7db4418Szhoumingtao 
122e7db4418Szhoumingtao //
123e7db4418Szhoumingtao // When build similiar to FW, then link everything together as
124e7db4418Szhoumingtao // one big module.
125e7db4418Szhoumingtao //
126e7db4418Szhoumingtao 
127e7db4418Szhoumingtao #define EFI_DRIVER_ENTRY_POINT(InitFunction)    \
128e7db4418Szhoumingtao     UINTN                                       \
129e7db4418Szhoumingtao     InitializeDriver (                          \
130e7db4418Szhoumingtao         VOID    *ImageHandle,                   \
131e7db4418Szhoumingtao         VOID    *SystemTable                    \
132e7db4418Szhoumingtao         )                                       \
133e7db4418Szhoumingtao     {                                           \
134e7db4418Szhoumingtao         return InitFunction(ImageHandle,        \
135e7db4418Szhoumingtao                 SystemTable);                   \
136e7db4418Szhoumingtao     }                                           \
137e7db4418Szhoumingtao                                                 \
138e7db4418Szhoumingtao     EFI_STATUS efi_main(                        \
139e7db4418Szhoumingtao         EFI_HANDLE image,                       \
140e7db4418Szhoumingtao         EFI_SYSTEM_TABLE *systab                \
141e7db4418Szhoumingtao         ) __attribute__((weak,                  \
142e7db4418Szhoumingtao                 alias ("InitializeDriver")));
143e7db4418Szhoumingtao 
144e7db4418Szhoumingtao #define LOAD_INTERNAL_DRIVER(_if, type, name, entry)    \
145e7db4418Szhoumingtao         (_if)->LoadInternal(type, name, entry)
146e7db4418Szhoumingtao 
147e7db4418Szhoumingtao 
148e7db4418Szhoumingtao //
149e7db4418Szhoumingtao // Some compilers don't support the forward reference construct:
150e7db4418Szhoumingtao //  typedef struct XXXXX
151e7db4418Szhoumingtao //
152e7db4418Szhoumingtao // The following macro provide a workaround for such cases.
153e7db4418Szhoumingtao 
154e7db4418Szhoumingtao #define INTERFACE_DECL(x) struct x
155e7db4418Szhoumingtao 
156e7db4418Szhoumingtao #define uefi_call_wrapper(func, va_num, ...) func(__VA_ARGS__)
157e7db4418Szhoumingtao #define EFI_FUNCTION
158