xref: /DragonStub/inc/mips64el/efibind.h (revision 14899d899b230eff3e3ff41011405f742aad6724)
13f234f5bSNigel Croxon /*
23f234f5bSNigel Croxon  * Copright (C) 2014 - 2015 Linaro Ltd.
33f234f5bSNigel Croxon  * Author: Ard Biesheuvel <ard.biesheuvel@linaro.org>
43f234f5bSNigel Croxon  * Copright (C) 2017 Lemote Co.
53f234f5bSNigel Croxon  * Author: Heiher <r@hev.cc>
63f234f5bSNigel Croxon  *
73f234f5bSNigel Croxon  * Redistribution and use in source and binary forms, with or without
83f234f5bSNigel Croxon  * modification, are permitted provided that the following conditions
93f234f5bSNigel Croxon  * are met:
103f234f5bSNigel Croxon  * 1. Redistributions of source code must retain the above copyright
113f234f5bSNigel Croxon  *    notice and this list of conditions, without modification.
123f234f5bSNigel Croxon  * 2. The name of the author may not be used to endorse or promote products
133f234f5bSNigel Croxon  *    derived from this software without specific prior written permission.
143f234f5bSNigel Croxon  *
153f234f5bSNigel Croxon  * Alternatively, this software may be distributed under the terms of the
163f234f5bSNigel Croxon  * GNU General Public License as published by the Free Software Foundation;
173f234f5bSNigel Croxon  * either version 2 of the License, or (at your option) any later version.
183f234f5bSNigel Croxon  */
193f234f5bSNigel Croxon 
206685cd00SAlexander von Gluck IV #if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L ) && !defined(__cplusplus)
213f234f5bSNigel Croxon 
223f234f5bSNigel Croxon // ANSI C 1999/2000 stdint.h integer width declarations
233f234f5bSNigel Croxon 
243f234f5bSNigel Croxon typedef unsigned long       uint64_t;
253f234f5bSNigel Croxon typedef long                int64_t;
263f234f5bSNigel Croxon typedef unsigned int        uint32_t;
273f234f5bSNigel Croxon typedef int                 int32_t;
283f234f5bSNigel Croxon typedef unsigned short      uint16_t;
293f234f5bSNigel Croxon typedef short               int16_t;
303f234f5bSNigel Croxon typedef unsigned char       uint8_t;
313f234f5bSNigel Croxon typedef signed char         int8_t;   // unqualified 'char' is unsigned on ARM
321a53d8f8SEsben Haabendal typedef uint64_t            uintptr_t;
331a53d8f8SEsben Haabendal typedef int64_t             intptr_t;
343f234f5bSNigel Croxon 
353f234f5bSNigel Croxon #else
363f234f5bSNigel Croxon #include <stdint.h>
373f234f5bSNigel Croxon #endif
383f234f5bSNigel Croxon 
393f234f5bSNigel Croxon //
403f234f5bSNigel Croxon // Basic EFI types of various widths
413f234f5bSNigel Croxon //
423f234f5bSNigel Croxon 
433f234f5bSNigel Croxon #ifndef __WCHAR_TYPE__
443f234f5bSNigel Croxon # define __WCHAR_TYPE__ short
453f234f5bSNigel Croxon #endif
46*14899d89SPeter Jones #ifndef __CHAR16_TYPE__
47*14899d89SPeter Jones # define __CHAR16_TYPE__ unsigned short
48*14899d89SPeter Jones #endif
493f234f5bSNigel Croxon 
503f234f5bSNigel Croxon typedef uint64_t   UINT64;
513f234f5bSNigel Croxon typedef int64_t    INT64;
523f234f5bSNigel Croxon 
533f234f5bSNigel Croxon typedef uint32_t   UINT32;
543f234f5bSNigel Croxon typedef int32_t    INT32;
553f234f5bSNigel Croxon 
563f234f5bSNigel Croxon typedef uint16_t   UINT16;
57*14899d89SPeter Jones typedef __CHAR16_TYPE__ CHAR16;
583f234f5bSNigel Croxon typedef int16_t    INT16;
59*14899d89SPeter Jones 
603f234f5bSNigel Croxon typedef uint8_t    UINT8;
61*14899d89SPeter Jones typedef char       CHAR8;
623f234f5bSNigel Croxon typedef int8_t     INT8;
63*14899d89SPeter Jones 
643f234f5bSNigel Croxon typedef __WCHAR_TYPE__ WCHAR;
653f234f5bSNigel Croxon 
663f234f5bSNigel Croxon #undef VOID
673f234f5bSNigel Croxon #define VOID    void
683f234f5bSNigel Croxon 
693f234f5bSNigel Croxon typedef int64_t    INTN;
703f234f5bSNigel Croxon typedef uint64_t   UINTN;
713f234f5bSNigel Croxon 
723f234f5bSNigel Croxon #define EFIERR(a)           (0x8000000000000000 | a)
733f234f5bSNigel Croxon #define EFI_ERROR_MASK      0x8000000000000000
743f234f5bSNigel Croxon #define EFIERR_OEM(a)       (0xc000000000000000 | a)
753f234f5bSNigel Croxon 
763f234f5bSNigel Croxon #define BAD_POINTER         0xFBFBFBFBFBFBFBFB
773f234f5bSNigel Croxon #define MAX_ADDRESS         0xFFFFFFFFFFFFFFFF
783f234f5bSNigel Croxon 
793f234f5bSNigel Croxon #define BREAKPOINT()        while (TRUE);    // Make it hang on Bios[Dbg]32
803f234f5bSNigel Croxon 
813f234f5bSNigel Croxon //
823f234f5bSNigel Croxon // Pointers must be aligned to these address to function
833f234f5bSNigel Croxon //
843f234f5bSNigel Croxon 
853f234f5bSNigel Croxon #define MIN_ALIGNMENT_SIZE  8
863f234f5bSNigel Croxon 
873f234f5bSNigel Croxon #define ALIGN_VARIABLE(Value ,Adjustment) \
883f234f5bSNigel Croxon             (UINTN)Adjustment = 0; \
893f234f5bSNigel Croxon             if((UINTN)Value % MIN_ALIGNMENT_SIZE) \
903f234f5bSNigel Croxon                 (UINTN)Adjustment = MIN_ALIGNMENT_SIZE - ((UINTN)Value % MIN_ALIGNMENT_SIZE); \
913f234f5bSNigel Croxon             Value = (UINTN)Value + (UINTN)Adjustment
923f234f5bSNigel Croxon 
933f234f5bSNigel Croxon 
943f234f5bSNigel Croxon //
953f234f5bSNigel Croxon // Define macros to build data structure signatures from characters.
963f234f5bSNigel Croxon //
973f234f5bSNigel Croxon 
983f234f5bSNigel Croxon #define EFI_SIGNATURE_16(A,B)             ((A) | (B<<8))
993f234f5bSNigel Croxon #define EFI_SIGNATURE_32(A,B,C,D)         (EFI_SIGNATURE_16(A,B)     | (EFI_SIGNATURE_16(C,D)     << 16))
1003f234f5bSNigel Croxon #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))
1013f234f5bSNigel Croxon 
1023f234f5bSNigel Croxon //
1033f234f5bSNigel Croxon // EFIAPI - prototype calling convention for EFI function pointers
1043f234f5bSNigel Croxon // BOOTSERVICE - prototype for implementation of a boot service interface
1053f234f5bSNigel Croxon // RUNTIMESERVICE - prototype for implementation of a runtime service interface
1063f234f5bSNigel Croxon // RUNTIMEFUNCTION - prototype for implementation of a runtime function that is not a service
1073f234f5bSNigel Croxon // RUNTIME_CODE - pragma macro for declaring runtime code
1083f234f5bSNigel Croxon //
1093f234f5bSNigel Croxon 
1103f234f5bSNigel Croxon #ifndef EFIAPI          // Forces EFI calling conventions reguardless of compiler options
1113f234f5bSNigel Croxon #define EFIAPI          // Substitute expresion to force C calling convention
1123f234f5bSNigel Croxon #endif
1133f234f5bSNigel Croxon 
1143f234f5bSNigel Croxon #define BOOTSERVICE
1153f234f5bSNigel Croxon #define RUNTIMESERVICE
1163f234f5bSNigel Croxon #define RUNTIMEFUNCTION
1173f234f5bSNigel Croxon 
1183f234f5bSNigel Croxon 
1193f234f5bSNigel Croxon #define RUNTIME_CODE(a)         alloc_text("rtcode", a)
1203f234f5bSNigel Croxon #define BEGIN_RUNTIME_DATA()    data_seg("rtdata")
1213f234f5bSNigel Croxon #define END_RUNTIME_DATA()      data_seg("")
1223f234f5bSNigel Croxon 
1233f234f5bSNigel Croxon #define VOLATILE                volatile
1243f234f5bSNigel Croxon 
1253f234f5bSNigel Croxon #define MEMORY_FENCE            __sync_synchronize
1263f234f5bSNigel Croxon 
1273f234f5bSNigel Croxon //
1283f234f5bSNigel Croxon // When build similiar to FW, then link everything together as
1293f234f5bSNigel Croxon // one big module.
1303f234f5bSNigel Croxon //
1313f234f5bSNigel Croxon 
1323f234f5bSNigel Croxon #define EFI_DRIVER_ENTRY_POINT(InitFunction)    \
1333f234f5bSNigel Croxon     UINTN                                       \
1343f234f5bSNigel Croxon     InitializeDriver (                          \
1353f234f5bSNigel Croxon         VOID    *ImageHandle,                   \
1363f234f5bSNigel Croxon         VOID    *SystemTable                    \
1373f234f5bSNigel Croxon         )                                       \
1383f234f5bSNigel Croxon     {                                           \
1393f234f5bSNigel Croxon         return InitFunction(ImageHandle,        \
1403f234f5bSNigel Croxon                 SystemTable);                   \
1413f234f5bSNigel Croxon     }                                           \
1423f234f5bSNigel Croxon                                                 \
1433f234f5bSNigel Croxon     EFI_STATUS efi_main(                        \
1443f234f5bSNigel Croxon         EFI_HANDLE image,                       \
1453f234f5bSNigel Croxon         EFI_SYSTEM_TABLE *systab                \
1463f234f5bSNigel Croxon         ) __attribute__((weak,                  \
1473f234f5bSNigel Croxon                 alias ("InitializeDriver")));
1483f234f5bSNigel Croxon 
1493f234f5bSNigel Croxon #define LOAD_INTERNAL_DRIVER(_if, type, name, entry)    \
1503f234f5bSNigel Croxon         (_if)->LoadInternal(type, name, entry)
1513f234f5bSNigel Croxon 
1523f234f5bSNigel Croxon 
1533f234f5bSNigel Croxon //
1543f234f5bSNigel Croxon // Some compilers don't support the forward reference construct:
1553f234f5bSNigel Croxon //  typedef struct XXXXX
1563f234f5bSNigel Croxon //
1573f234f5bSNigel Croxon // The following macro provide a workaround for such cases.
1583f234f5bSNigel Croxon 
1593f234f5bSNigel Croxon #define INTERFACE_DECL(x) struct x
1603f234f5bSNigel Croxon 
1613f234f5bSNigel Croxon #define uefi_call_wrapper(func, va_num, ...) func(__VA_ARGS__)
1623f234f5bSNigel Croxon #define EFI_FUNCTION
1633f234f5bSNigel Croxon 
1643f234f5bSNigel Croxon static inline UINT64 swap_uint64 (UINT64 v)
1653f234f5bSNigel Croxon {
1663f234f5bSNigel Croxon 	asm volatile (
1673f234f5bSNigel Croxon 		"dsbh	%[v], %[v] \n\t"
1683f234f5bSNigel Croxon 		"dshd	%[v], %[v] \n\t"
1693f234f5bSNigel Croxon 		:[v]"+r"(v)
1703f234f5bSNigel Croxon 	);
1713f234f5bSNigel Croxon 
1723f234f5bSNigel Croxon 	return v;
1733f234f5bSNigel Croxon }
174