xref: /DragonStub/inc/riscv64/efibind.h (revision 0f9c15fe4fd4b37691fdb505794b0d73df21d4d5)
1*0f9c15feSbmeng@tinylab.org /* SPDX-License-Identifier: GPL-2.0+ OR BSD-2-Clause */
2b1364609SPete Batard /*
3b1364609SPete Batard  * Copright (C) 2014 - 2015 Linaro Ltd.
4b1364609SPete Batard  * Author: Ard Biesheuvel <ard.biesheuvel@linaro.org>
5b1364609SPete Batard  *
6b1364609SPete Batard  * Redistribution and use in source and binary forms, with or without
7b1364609SPete Batard  * modification, are permitted provided that the following conditions
8b1364609SPete Batard  * are met:
9b1364609SPete Batard  * 1. Redistributions of source code must retain the above copyright
10b1364609SPete Batard  *    notice and this list of conditions, without modification.
11b1364609SPete Batard  * 2. The name of the author may not be used to endorse or promote products
12b1364609SPete Batard  *    derived from this software without specific prior written permission.
13b1364609SPete Batard  *
14b1364609SPete Batard  * Alternatively, this software may be distributed under the terms of the
15b1364609SPete Batard  * GNU General Public License as published by the Free Software Foundation;
16b1364609SPete Batard  * either version 2 of the License, or (at your option) any later version.
17b1364609SPete Batard  */
18b95f138fSHeinrich Schuchardt 
19b95f138fSHeinrich Schuchardt #include <stdint.h>
20b95f138fSHeinrich Schuchardt 
21b1364609SPete Batard //
22b1364609SPete Batard // Basic EFI types of various widths
23b1364609SPete Batard //
24b95f138fSHeinrich Schuchardt 
25b1364609SPete Batard 
26b1364609SPete Batard 
27b1364609SPete Batard typedef uint64_t                UINT64;
28b1364609SPete Batard typedef int64_t                 INT64;
29b1364609SPete Batard typedef uint32_t                UINT32;
30b1364609SPete Batard typedef int32_t                 INT32;
31b1364609SPete Batard typedef uint16_t                UINT16;
32b1364609SPete Batard typedef int16_t                 INT16;
33b1364609SPete Batard typedef uint8_t                 UINT8;
34b1364609SPete Batard typedef int8_t                  INT8;
35b1364609SPete Batard #ifndef __WCHAR_TYPE__
36b1364609SPete Batard #define __WCHAR_TYPE__          short
37b1364609SPete Batard #endif
38b1364609SPete Batard typedef __WCHAR_TYPE__          WCHAR;
39b1364609SPete Batard #ifndef BOOLEAN
40b95f138fSHeinrich Schuchardt typedef uint8_t                 BOOLEAN;
41b1364609SPete Batard #endif
42b1364609SPete Batard #undef VOID
43b1364609SPete Batard #define VOID                    void
44b95f138fSHeinrich Schuchardt typedef int64_t                 INTN;
45b95f138fSHeinrich Schuchardt typedef uint64_t                UINTN;
46b1364609SPete Batard 
47b1364609SPete Batard #define EFI_ERROR_MASK          0x8000000000000000
48b1364609SPete Batard #define EFIERR(a)               (EFI_ERROR_MASK | a)
49b1364609SPete Batard #define EFIERR_OEM(a)           (0xc000000000000000 | a)
50b1364609SPete Batard 
51b1364609SPete Batard #define BAD_POINTER             0xFBFBFBFBFBFBFBFB
52b1364609SPete Batard #define MAX_ADDRESS             0xFFFFFFFFFFFFFFFF
53b95f138fSHeinrich Schuchardt 
54b95f138fSHeinrich Schuchardt #define BREAKPOINT()            while(1);
55b95f138fSHeinrich Schuchardt 
56b1364609SPete Batard //
57b1364609SPete Batard // Pointers must be aligned to these address to function
58b1364609SPete Batard //
59b1364609SPete Batard #define MIN_ALIGNMENT_SIZE      8
60b1364609SPete Batard 
61b1364609SPete Batard #define ALIGN_VARIABLE(Value, Adjustment) \
62b1364609SPete Batard    (UINTN)Adjustment = 0; \
63b1364609SPete Batard    if((UINTN)Value % MIN_ALIGNMENT_SIZE) \
64b1364609SPete Batard        (UINTN)Adjustment = MIN_ALIGNMENT_SIZE - ((UINTN)Value % MIN_ALIGNMENT_SIZE); \
65b1364609SPete Batard    Value = (UINTN)Value + (UINTN)Adjustment
66b1364609SPete Batard 
67b1364609SPete Batard //
68b1364609SPete Batard // Define macros to build data structure signatures from characters.
69b1364609SPete Batard //
70b95f138fSHeinrich Schuchardt #define EFI_SIGNATURE_16(A,B)             ((A) | (B<<8))
71b95f138fSHeinrich Schuchardt #define EFI_SIGNATURE_32(A,B,C,D)         (EFI_SIGNATURE_16(A,B)     | (EFI_SIGNATURE_16(C,D)     << 16))
72b95f138fSHeinrich Schuchardt #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))
73b5f98d40SHeinrich Schuchardt 
74b1364609SPete Batard //
75b1364609SPete Batard // EFIAPI - prototype calling convention for EFI function pointers
76b1364609SPete Batard // BOOTSERVICE - prototype for implementation of a boot service interface
77b1364609SPete Batard // RUNTIMESERVICE - prototype for implementation of a runtime service interface
78b1364609SPete Batard // RUNTIMEFUNCTION - prototype for implementation of a runtime function that is not a service
79b1364609SPete Batard // RUNTIME_CODE - pragma macro for declaring runtime code
80b1364609SPete Batard //
81b1364609SPete Batard #ifndef EFIAPI                  // Forces EFI calling conventions reguardless of compiler options
82b1364609SPete Batard #define EFIAPI                  // Substitute expresion to force C calling convention
83b1364609SPete Batard #endif
84b1364609SPete Batard #define BOOTSERVICE
85b1364609SPete Batard #define RUNTIMESERVICE
86b1364609SPete Batard #define RUNTIMEFUNCTION
87b1364609SPete Batard #define RUNTIME_CODE(a)         alloc_text("rtcode", a)
88b1364609SPete Batard #define BEGIN_RUNTIME_DATA()    data_seg("rtdata")
89b1364609SPete Batard #define END_RUNTIME_DATA()      data_seg("")
90b1364609SPete Batard 
91b1364609SPete Batard #define VOLATILE                volatile
92b1364609SPete Batard #define MEMORY_FENCE            __sync_synchronize
93b1364609SPete Batard 
94b1364609SPete Batard //
95b1364609SPete Batard // When build similiar to FW, then link everything together as
96b1364609SPete Batard // one big module. For the MSVC toolchain, we simply tell the
97b1364609SPete Batard // linker what our driver init function is using /ENTRY.
98b1364609SPete Batard //
99b1364609SPete Batard #if defined(_MSC_EXTENSIONS)
100b1364609SPete Batard #define EFI_DRIVER_ENTRY_POINT(InitFunction) \
101b1364609SPete Batard     __pragma(comment(linker, "/ENTRY:" # InitFunction))
102b1364609SPete Batard #else
103b1364609SPete Batard #define EFI_DRIVER_ENTRY_POINT(InitFunction)    \
104b1364609SPete Batard     UINTN                                       \
105b1364609SPete Batard     InitializeDriver (                          \
106b1364609SPete Batard         VOID    *ImageHandle,                   \
107b1364609SPete Batard         VOID    *SystemTable                    \
108b1364609SPete Batard         )                                       \
109b1364609SPete Batard     {                                           \
110b1364609SPete Batard         return InitFunction(ImageHandle,        \
111b1364609SPete Batard                 SystemTable);                   \
112b1364609SPete Batard     }                                           \
113b1364609SPete Batard                                                 \
114b1364609SPete Batard     EFI_STATUS efi_main(                        \
115b1364609SPete Batard         EFI_HANDLE image,                       \
116b1364609SPete Batard         EFI_SYSTEM_TABLE *systab                \
117b1364609SPete Batard         ) __attribute__((weak,                  \
118b1364609SPete Batard                 alias ("InitializeDriver")));
119b1364609SPete Batard #endif
120b1364609SPete Batard 
121b1364609SPete Batard #define LOAD_INTERNAL_DRIVER(_if, type, name, entry) \
122b1364609SPete Batard    (_if)->LoadInternal(type, name, entry)
123b1364609SPete Batard 
124b1364609SPete Batard //
125b1364609SPete Batard // Some compilers don't support the forward reference construct:
126b1364609SPete Batard //  typedef struct XXXXX
127b1364609SPete Batard //
128b1364609SPete Batard // The following macro provide a workaround for such cases.
129b1364609SPete Batard #define INTERFACE_DECL(x)       struct x
130b1364609SPete Batard 
131b1364609SPete Batard #define uefi_call_wrapper(func, va_num, ...) func(__VA_ARGS__)
132b5f98d40SHeinrich Schuchardt #define EFI_FUNCTION
133