xref: /DragonStub/inc/riscv64/efibind.h (revision 189200d0b0f6fff473d302880d9569f45d4d8c4d)
10f9c15feSbmeng@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 
25*189200d0SCallum Farmer #include <stddef.h>
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;
35*189200d0SCallum Farmer typedef wchar_t                 CHAR16;
36*189200d0SCallum Farmer #define WCHAR                   CHAR16
37b1364609SPete Batard #ifndef BOOLEAN
38b95f138fSHeinrich Schuchardt typedef uint8_t                 BOOLEAN;
39b1364609SPete Batard #endif
40b1364609SPete Batard #undef VOID
41b1364609SPete Batard #define VOID                    void
42b95f138fSHeinrich Schuchardt typedef int64_t                 INTN;
43b95f138fSHeinrich Schuchardt typedef uint64_t                UINTN;
44b1364609SPete Batard 
45b1364609SPete Batard #define EFI_ERROR_MASK          0x8000000000000000
46b1364609SPete Batard #define EFIERR(a)               (EFI_ERROR_MASK | a)
47b1364609SPete Batard #define EFIERR_OEM(a)           (0xc000000000000000 | a)
48b1364609SPete Batard 
49b1364609SPete Batard #define BAD_POINTER             0xFBFBFBFBFBFBFBFB
50b1364609SPete Batard #define MAX_ADDRESS             0xFFFFFFFFFFFFFFFF
51b95f138fSHeinrich Schuchardt 
52b95f138fSHeinrich Schuchardt #define BREAKPOINT()            while(1);
53b95f138fSHeinrich Schuchardt 
54b1364609SPete Batard //
55b1364609SPete Batard // Pointers must be aligned to these address to function
56b1364609SPete Batard //
57b1364609SPete Batard #define MIN_ALIGNMENT_SIZE      8
58b1364609SPete Batard 
59b1364609SPete Batard #define ALIGN_VARIABLE(Value, Adjustment) \
60b1364609SPete Batard    (UINTN)Adjustment = 0; \
61b1364609SPete Batard    if((UINTN)Value % MIN_ALIGNMENT_SIZE) \
62b1364609SPete Batard        (UINTN)Adjustment = MIN_ALIGNMENT_SIZE - ((UINTN)Value % MIN_ALIGNMENT_SIZE); \
63b1364609SPete Batard    Value = (UINTN)Value + (UINTN)Adjustment
64b1364609SPete Batard 
65b1364609SPete Batard //
66b1364609SPete Batard // Define macros to build data structure signatures from characters.
67b1364609SPete Batard //
68b95f138fSHeinrich Schuchardt #define EFI_SIGNATURE_16(A,B)             ((A) | (B<<8))
69b95f138fSHeinrich Schuchardt #define EFI_SIGNATURE_32(A,B,C,D)         (EFI_SIGNATURE_16(A,B)     | (EFI_SIGNATURE_16(C,D)     << 16))
70b95f138fSHeinrich 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))
71b5f98d40SHeinrich Schuchardt 
72b1364609SPete Batard //
73b1364609SPete Batard // EFIAPI - prototype calling convention for EFI function pointers
74b1364609SPete Batard // BOOTSERVICE - prototype for implementation of a boot service interface
75b1364609SPete Batard // RUNTIMESERVICE - prototype for implementation of a runtime service interface
76b1364609SPete Batard // RUNTIMEFUNCTION - prototype for implementation of a runtime function that is not a service
77b1364609SPete Batard // RUNTIME_CODE - pragma macro for declaring runtime code
78b1364609SPete Batard //
79b1364609SPete Batard #ifndef EFIAPI                  // Forces EFI calling conventions reguardless of compiler options
80b1364609SPete Batard #define EFIAPI                  // Substitute expresion to force C calling convention
81b1364609SPete Batard #endif
82b1364609SPete Batard #define BOOTSERVICE
83b1364609SPete Batard #define RUNTIMESERVICE
84b1364609SPete Batard #define RUNTIMEFUNCTION
85b1364609SPete Batard #define RUNTIME_CODE(a)         alloc_text("rtcode", a)
86b1364609SPete Batard #define BEGIN_RUNTIME_DATA()    data_seg("rtdata")
87b1364609SPete Batard #define END_RUNTIME_DATA()      data_seg("")
88b1364609SPete Batard 
89b1364609SPete Batard #define VOLATILE                volatile
90b1364609SPete Batard #define MEMORY_FENCE            __sync_synchronize
91b1364609SPete Batard 
92b1364609SPete Batard //
93b1364609SPete Batard // When build similiar to FW, then link everything together as
94b1364609SPete Batard // one big module. For the MSVC toolchain, we simply tell the
95b1364609SPete Batard // linker what our driver init function is using /ENTRY.
96b1364609SPete Batard //
97b1364609SPete Batard #if defined(_MSC_EXTENSIONS)
98b1364609SPete Batard #define EFI_DRIVER_ENTRY_POINT(InitFunction) \
99b1364609SPete Batard     __pragma(comment(linker, "/ENTRY:" # InitFunction))
100b1364609SPete Batard #else
101b1364609SPete Batard #define EFI_DRIVER_ENTRY_POINT(InitFunction)    \
102b1364609SPete Batard     UINTN                                       \
103b1364609SPete Batard     InitializeDriver (                          \
104b1364609SPete Batard         VOID    *ImageHandle,                   \
105b1364609SPete Batard         VOID    *SystemTable                    \
106b1364609SPete Batard         )                                       \
107b1364609SPete Batard     {                                           \
108b1364609SPete Batard         return InitFunction(ImageHandle,        \
109b1364609SPete Batard                 SystemTable);                   \
110b1364609SPete Batard     }                                           \
111b1364609SPete Batard                                                 \
112b1364609SPete Batard     EFI_STATUS efi_main(                        \
113b1364609SPete Batard         EFI_HANDLE image,                       \
114b1364609SPete Batard         EFI_SYSTEM_TABLE *systab                \
115b1364609SPete Batard         ) __attribute__((weak,                  \
116b1364609SPete Batard                 alias ("InitializeDriver")));
117b1364609SPete Batard #endif
118b1364609SPete Batard 
119b1364609SPete Batard #define LOAD_INTERNAL_DRIVER(_if, type, name, entry) \
120b1364609SPete Batard    (_if)->LoadInternal(type, name, entry)
121b1364609SPete Batard 
122b1364609SPete Batard //
123b1364609SPete Batard // Some compilers don't support the forward reference construct:
124b1364609SPete Batard //  typedef struct XXXXX
125b1364609SPete Batard //
126b1364609SPete Batard // The following macro provide a workaround for such cases.
127b1364609SPete Batard #define INTERFACE_DECL(x)       struct x
128b1364609SPete Batard 
129b1364609SPete Batard #define uefi_call_wrapper(func, va_num, ...) func(__VA_ARGS__)
130b5f98d40SHeinrich Schuchardt #define EFI_FUNCTION
131