Skip to content

Commit e227ad2

Browse files
committed
edk2-libc: Add LoongArch64 support.
REF: https://github.com/bminor/glibc https://github.com/loongson/glibc Signed-off-by: Dongyan Qian <[email protected]>
1 parent 2cc0f4d commit e227ad2

File tree

32 files changed

+1527
-10
lines changed

32 files changed

+1527
-10
lines changed

AppPkg/AppPkg.dsc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
PLATFORM_VERSION = 0.01
1818
DSC_SPECIFICATION = 0x00010006
1919
OUTPUT_DIRECTORY = Build/AppPkg
20-
SUPPORTED_ARCHITECTURES = IA32|X64|ARM|AARCH64
20+
SUPPORTED_ARCHITECTURES = IA32|X64|ARM|AARCH64|LOONGARCH64
2121
BUILD_TARGETS = DEBUG|RELEASE|NOOPT
2222
SKUID_IDENTIFIER = DEFAULT
2323

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/** @file
2+
3+
Copyright (c) 2014, ARM Limited. All rights reserved.
4+
Modified by Loongson Technology Co., Ltd. on 2024.
5+
6+
This program and the accompanying materials
7+
are licensed and made available under the terms and conditions of the BSD License
8+
which accompanies this distribution. The full text of the license may be found at
9+
http://opensource.org/licenses/bsd-license.php
10+
11+
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13+
14+
**/
15+
16+
17+
/* $NetBSD: arm-gcc.h,v 1.4 2013/01/26 07:08:14 matt Exp $ */
18+
19+
/*
20+
-------------------------------------------------------------------------------
21+
One of the macros `BIGENDIAN' or `LITTLEENDIAN' must be defined.
22+
-------------------------------------------------------------------------------
23+
*/
24+
#define LITTLEENDIAN
25+
26+
/*
27+
-------------------------------------------------------------------------------
28+
The macro `BITS64' can be defined to indicate that 64-bit integer types are
29+
supported by the compiler.
30+
-------------------------------------------------------------------------------
31+
*/
32+
#define BITS64
33+
34+
/*
35+
-------------------------------------------------------------------------------
36+
Each of the following `typedef's defines the most convenient type that holds
37+
integers of at least as many bits as specified. For example, `uint8' should
38+
be the most convenient type that can hold unsigned integers of as many as
39+
8 bits. The `flag' type must be able to hold either a 0 or 1. For most
40+
implementations of C, `flag', `uint8', and `int8' should all be `typedef'ed
41+
to the same as `int'.
42+
-------------------------------------------------------------------------------
43+
*/
44+
typedef int flag;
45+
typedef int uint8;
46+
typedef int int8;
47+
typedef int uint16;
48+
typedef int int16;
49+
typedef unsigned int uint32;
50+
typedef signed int int32;
51+
#ifdef BITS64
52+
typedef unsigned long long int uint64;
53+
typedef signed long long int int64;
54+
#endif
55+
56+
/*
57+
-------------------------------------------------------------------------------
58+
Each of the following `typedef's defines a type that holds integers
59+
of _exactly_ the number of bits specified. For instance, for most
60+
implementation of C, `bits16' and `sbits16' should be `typedef'ed to
61+
`unsigned short int' and `signed short int' (or `short int'), respectively.
62+
-------------------------------------------------------------------------------
63+
*/
64+
typedef unsigned char bits8;
65+
typedef signed char sbits8;
66+
typedef unsigned short int bits16;
67+
typedef signed short int sbits16;
68+
typedef unsigned int bits32;
69+
typedef signed int sbits32;
70+
#ifdef BITS64
71+
typedef unsigned long long int bits64;
72+
typedef signed long long int sbits64;
73+
#endif
74+
75+
#ifdef BITS64
76+
/*
77+
-------------------------------------------------------------------------------
78+
The `LIT64' macro takes as its argument a textual integer literal and
79+
if necessary ``marks'' the literal as having a 64-bit integer type.
80+
For example, the GNU C Compiler (`gcc') requires that 64-bit literals be
81+
appended with the letters `LL' standing for `long long', which is `gcc's
82+
name for the 64-bit integer type. Some compilers may allow `LIT64' to be
83+
defined as the identity macro: `#define LIT64( a ) a'.
84+
-------------------------------------------------------------------------------
85+
*/
86+
#define LIT64( a ) a##ULL
87+
#endif
88+
89+
/*
90+
-------------------------------------------------------------------------------
91+
The macro `INLINE' can be used before functions that should be inlined. If
92+
a compiler does not support explicit inlining, this macro should be defined
93+
to be `static'.
94+
-------------------------------------------------------------------------------
95+
*/
96+
#define INLINE static inline
97+
98+
/* Modified by Loongson Technology Co., Ltd. on [2024]:\
99+
* Changed the endianness detection for new architecture */
100+
101+
#if defined(SOFTFLOAT_FOR_GCC)
102+
#define FLOAT64_DEMANGLE(a) (a)
103+
#define FLOAT64_MANGLE(a) (a)
104+
#endif
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/** @file
2+
Machine dependent ANSI type definitions.
3+
4+
Copyright (c) 2010-2012, Intel Corporation. All rights reserved.<BR>
5+
This program and the accompanying materials are licensed and made available
6+
under the terms and conditions of the BSD License that accompanies this
7+
distribution. The full text of the license may be found at
8+
http://opensource.org/licenses/bsd-license.php.
9+
10+
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12+
13+
* Copyright (c) 1990, 1993
14+
* The Regents of the University of California. All rights reserved.
15+
*
16+
* Redistribution and use in source and binary forms, with or without
17+
* modification, are permitted provided that the following conditions
18+
* are met:
19+
* 1. Redistributions of source code must retain the above copyright
20+
* notice, this list of conditions and the following disclaimer.
21+
* 2. Redistributions in binary form must reproduce the above copyright
22+
* notice, this list of conditions and the following disclaimer in the
23+
* documentation and/or other materials provided with the distribution.
24+
* 3. Neither the name of the University nor the names of its contributors
25+
* may be used to endorse or promote products derived from this software
26+
* without specific prior written permission.
27+
*
28+
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31+
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37+
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38+
* SUCH DAMAGE.
39+
*
40+
* from: @(#)ansi.h 8.2 (Berkeley) 1/4/94
41+
NetBSD: ansi.h,v 1.7 2006/10/04 13:51:59 tnozaki Exp
42+
**/
43+
#ifndef _ANSI_H_
44+
#define _ANSI_H_
45+
46+
#include <sys/EfiCdefs.h>
47+
48+
#include <machine/int_types.h>
49+
50+
/*
51+
* Types which are fundamental to the implementation and may appear in
52+
* more than one standard header are defined here. Standard headers
53+
* then use:
54+
* #ifdef _BSD_SIZE_T_
55+
* typedef _BSD_SIZE_T_ size_t;
56+
* #undef _BSD_SIZE_T_
57+
* #endif
58+
*/
59+
#define _BSD_CLOCK_T_ _EFI_CLOCK_T /* clock() */
60+
#define _BSD_PTRDIFF_T_ _EFI_PTRDIFF_T_ /* ptr1 - ptr2 */
61+
#define _BSD_SIZE_T_ _EFI_SIZE_T_ /* sizeof() */
62+
#define _BSD_SSIZE_T_ INTN /* byte count or error */
63+
#define _BSD_TIME_T_ _EFI_TIME_T /* time() */
64+
#define _BSD_VA_LIST_ VA_LIST
65+
#define _BSD_CLOCKID_T_ INT64 /* clockid_t */
66+
#define _BSD_TIMER_T_ INT64 /* timer_t */
67+
#define _BSD_SUSECONDS_T_ INT64 /* suseconds_t */
68+
#define _BSD_USECONDS_T_ UINT64 /* useconds_t */
69+
70+
/*
71+
* NOTE: rune_t is not covered by ANSI nor other standards, and should not
72+
* be instantiated outside of lib/libc/locale. use wchar_t.
73+
*
74+
* Runes (wchar_t) is declared to be an ``int'' instead of the more natural
75+
* ``unsigned long'' or ``long''. Two things are happening here. It is not
76+
* unsigned so that EOF (-1) can be naturally assigned to it and used. Also,
77+
* it looks like 10646 will be a 31 bit standard. This means that if your
78+
* ints cannot hold 32 bits, you will be in trouble. The reason an int was
79+
* chosen over a long is that the is*() and to*() routines take ints (says
80+
* ANSI C), but they use _RUNE_T_ instead of int. By changing it here, you
81+
* lose a bit of ANSI conformance, but your programs will still work.
82+
*
83+
* Note that _WCHAR_T_ and _RUNE_T_ must be of the same type. When wchar_t
84+
* and rune_t are typedef'd, _WCHAR_T_ will be undef'd, but _RUNE_T remains
85+
* defined for ctype.h.
86+
*/
87+
#define _BSD_WCHAR_T_ _EFI_WCHAR_T /* wchar_t */
88+
#define _BSD_WINT_T_ _EFI_WINT_T /* wint_t */
89+
#define _BSD_RUNE_T_ _EFI_WCHAR_T /* rune_t */
90+
#define _BSD_WCTRANS_T_ void * /* wctrans_t */
91+
#define _BSD_WCTYPE_T_ unsigned int /* wctype_t */
92+
93+
/*
94+
* mbstate_t is an opaque object to keep conversion state, during multibyte
95+
* stream conversions. The content must not be referenced by user programs.
96+
*/
97+
typedef struct {
98+
UINT32 A; // Np;
99+
UINT32 B; // U;
100+
UINT32 E; // L
101+
UINT8 C[4]; // n[4]
102+
UINT16 D[2]; // w[2]
103+
} __mbstate_t;
104+
#define _BSD_MBSTATE_T_ __mbstate_t /* mbstate_t */
105+
106+
#endif /* _ANSI_H_ */
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/* $NetBSD: bswap.h,v 1.4 2006/01/31 07:49:18 dsl Exp $ */
2+
3+
/* Written by Manuel Bouyer. Public domain */
4+
5+
#ifndef _MACHINE_BSWAP_H_
6+
#define _MACHINE_BSWAP_H_
7+
8+
#include <machine/byte_swap.h>
9+
10+
#define __BSWAP_RENAME
11+
#include <sys/bswap.h>
12+
13+
#endif /* !_MACHINE_BSWAP_H_ */
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*-
2+
* Copyright (c) 1997, 1999, 2002 The NetBSD Foundation, Inc.
3+
* All rights reserved.
4+
*
5+
* This code is derived from software contributed to The NetBSD Foundation
6+
* by Charles M. Hannum, Neil A. Carson, and Jason R. Thorpe.
7+
*
8+
* Modified by Loongson Technology Co., Ltd. on 2024/12/08.
9+
*
10+
* Redistribution and use in source and binary forms, with or without
11+
* modification, are permitted provided that the following conditions
12+
* are met:
13+
* 1. Redistributions of source code must retain the above copyright
14+
* notice, this list of conditions and the following disclaimer.
15+
* 2. Redistributions in binary form must reproduce the above copyright
16+
* notice, this list of conditions and the following disclaimer in the
17+
* documentation and/or other materials provided with the distribution.
18+
*
19+
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20+
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21+
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23+
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29+
* POSSIBILITY OF SUCH DAMAGE.
30+
*/
31+
32+
#ifndef _LOONGARCH64_BYTE_SWAP_H_
33+
#define _LOONGARCH64_BYTE_SWAP_H_
34+
35+
#ifdef __GNUC__
36+
#include <sys/types.h>
37+
__BEGIN_DECLS
38+
39+
#define __BYTE_SWAP_U32_VARIABLE __byte_swap_u32_variable
40+
static __inline uint32_t
41+
__byte_swap_u32_variable(uint32_t v)
42+
{
43+
uint32_t t1;
44+
45+
t1 = v ^ ((v << 16) | (v >> 16));
46+
t1 &= 0xff00ffffU;
47+
v = (v >> 8) | (v << 24);
48+
v ^= (t1 >> 8);
49+
return (v);
50+
}
51+
52+
#define __BYTE_SWAP_U16_VARIABLE __byte_swap_u16_variable
53+
static __inline uint16_t
54+
__byte_swap_u16_variable(uint16_t v)
55+
{
56+
57+
v &= 0xffff;
58+
v = (v >> 8) | (v << 8);
59+
return (v);
60+
}
61+
62+
__END_DECLS
63+
#endif
64+
65+
#endif /* _LOONGARCH64_BYTE_SWAP_H_ */
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/* $NetBSD: endian.h,v 1.3 2001/06/23 12:20:27 bjh21 Exp $ */
2+
3+
#include <sys/endian.h>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/* $NetBSD: endian_machdep.h,v 1.8 2006/01/30 21:52:38 dsl Exp $ */
2+
3+
#define _BYTE_ORDER _LITTLE_ENDIAN
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/* $NetBSD: fenv.h,v 1.2 2014/01/29 00:22:09 matt Exp $ */
2+
3+
/*
4+
* Based on ieeefp.h written by J.T. Conklin, Apr 28, 1995
5+
* Public domain.
6+
*
7+
* Modified by Loongson Technology Co., Ltd. on 2024/12/08.
8+
*
9+
*/
10+
11+
#ifndef _LOONGARCH64_FENV_H_
12+
#define _LOONGARCH64_FENV_H_
13+
14+
typedef int fexcept_t;
15+
16+
#define FE_INVALID 0x01 /* invalid operation exception */
17+
#define FE_DIVBYZERO 0x02 /* divide-by-zero exception */
18+
#define FE_OVERFLOW 0x04 /* overflow exception */
19+
#define FE_UNDERFLOW 0x08 /* underflow exception */
20+
#define FE_INEXACT 0x10 /* imprecise (loss of precision; "inexact") */
21+
22+
#define FE_ALL_EXCEPT 0x1f
23+
24+
#define FE_TONEAREST 0 /* round to nearest representable number */
25+
#define FE_UPWARD 1 /* round toward positive infinity */
26+
#define FE_DOWNWARD 2 /* round toward negative infinity */
27+
#define FE_TOWARDZERO 3 /* round to zero (truncate) */
28+
29+
#endif /* _LOONGARCH64_FENV_H_ */

0 commit comments

Comments
 (0)