Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

lm32: Directly link against libgcc

Instead of copying files from libgcc over just directly link against libgcc.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
  • Loading branch information...
commit d9b73e7c50bb795ea70962980b183db6675f8049 1 parent ac44f7f
@larsclausen larsclausen authored
View
3  arch/lm32/Makefile
@@ -22,6 +22,8 @@
# MA 02111-1307 USA
#
+LIBGCC := $(shell $(CC) $(KBUILD_CFLAGS) -print-libgcc-file-name)
+
board-$(CONFIG_BOARD_MILKYMIST_ONE) := milkymist-one
board-$(CONFIG_BOARD_MILKYMIST_SOC) := milkymist-soc
BOARD := $(board-y)
@@ -41,6 +43,7 @@ head-y := arch/lm32/kernel/head.o
core-y += arch/lm32/
core-y += arch/lm32/platforms/
libs-y += arch/lm32/lib/
+libs-y += $(LIBGCC)
boot := arch/lm32/boot
View
2  arch/lm32/lib/Makefile
@@ -2,5 +2,5 @@
# Makefile for lm32 specific library files..
#
-lib-y := memset.o memcpy.o arithmetic.o libgcc2.o
+lib-y := memset.o memcpy.o
View
223 arch/lm32/lib/arithmetic.c
@@ -1,223 +0,0 @@
-/* Arithmetic functions taken from libgcc2 for lm32 */
-
-/* Fixed-point arithmetic. */
-
-typedef unsigned long UQItype __attribute__ ((mode (QI)));
-typedef long SItype __attribute__ ((mode (SI)));
-typedef unsigned long USItype __attribute__ ((mode (SI)));
-
-/* Prototypes */
-
-USItype __mulsi3 (USItype a, USItype b);
-
-USItype __udivmodsi4 (USItype num, USItype den, int modwanted);
-SItype __divsi3 (SItype a, SItype b);
-SItype __modsi3 (SItype a, SItype b);
-USItype __udivsi3 (USItype a, USItype b);
-USItype __umodsi3 (USItype a, USItype b);
-
-SItype __ashlsi3 (SItype a, SItype b);
-SItype __ashrsi3 (SItype a, SItype b);
-USItype __lshrsi3 (USItype a, USItype b);
-
-/* Multiplication */
-
-USItype
-__mulsi3 (USItype a, USItype b)
-{
- USItype result;
-
- result = 0;
-
- if (a==0)
- return 0;
-
- while (b!=0)
- {
- if (b & 1)
- result += a;
- a <<= 1;
- b >>= 1;
- }
-
- return result;
-}
-
-/* Division */
-
-USItype
-__udivmodsi4 (USItype num, USItype den, int modwanted)
-{
- USItype bit = 1;
- USItype res = 0;
-
- while (den < num && bit && !(den & (1L<<31)))
- {
- den <<=1;
- bit <<=1;
- }
- while (bit)
- {
- if (num >= den)
- {
- num -= den;
- res |= bit;
- }
- bit >>=1;
- den >>=1;
- }
- if (modwanted)
- return num;
- return res;
-}
-
-static const UQItype __divsi3_table[] = {
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 3, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 4, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 5, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 6, 3, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 7, 3, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 8, 4, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0,
- 0, 9, 4, 3, 2, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
- 0, 10, 5, 3, 2, 2, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
- 0, 11, 5, 3, 2, 2, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0,
- 0, 12, 6, 4, 3, 2, 2, 1, 1, 1, 1, 1, 1, 0, 0, 0,
- 0, 13, 6, 4, 3, 2, 2, 1, 1, 1, 1, 1, 1, 1, 0, 0,
- 0, 14, 7, 4, 3, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 0,
- 0, 15, 7, 5, 3, 3, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1,
-};
-
-SItype
-__divsi3 (SItype a, SItype b)
-{
- int neg = 0;
- SItype res;
- int cfg;
-
- if (b == 0)
- {
- /* Raise divide by zero exception */
- int eba;
- __asm__ __volatile__ ("rcsr %0, EBA" : "=r" (eba));
- eba += 32 * 5;
- __asm__ __volatile__ ("mv ea, ra");
- __asm__ __volatile__ ("b %0" : : "r" (eba));
- }
-
- if ((a | b) < 16)
- {
- res = __divsi3_table[(a << 4) + b];
- }
- else
- {
-
- if (a < 0)
- {
- a = -a;
- neg = !neg;
- }
-
- if (b < 0)
- {
- b = -b;
- neg = !neg;
- }
-
- __asm__ ("rcsr %0, CFG" : "=r" (cfg));
- if (cfg & 2)
- __asm__ ("divu %0, %1, %2" : "=r" (res) : "r" (a), "r" (b));
- else
- res = __udivmodsi4 (a, b, 0);
-
- if (neg)
- res = -res;
- }
-
- return res;
-}
-
-
-SItype
-__modsi3 (SItype a, SItype b)
-{
- int neg = 0;
- SItype res;
- int cfg;
-
- if (b == 0)
- {
- /* Raise divide by zero exception */
- int eba;
- __asm__ __volatile__ ("rcsr %0, EBA" : "=r" (eba));
- eba += 32 * 5;
- __asm__ __volatile__ ("mv ea, ra");
- __asm__ __volatile__ ("b %0" : : "r" (eba));
- }
-
- if (a < 0)
- {
- a = -a;
- neg = 1;
- }
-
- if (b < 0)
- b = -b;
-
- __asm__ ("rcsr %0, CFG" : "=r" (cfg));
- if (cfg & 2)
- __asm__ ("modu %0, %1, %2" : "=r" (res) : "r" (a), "r" (b));
- else
- res = __udivmodsi4 (a, b, 1);
-
- if (neg)
- res = -res;
-
- return res;
-}
-
-USItype
-__udivsi3 (USItype a, USItype b)
-{
- return __udivmodsi4 (a, b, 0);
-}
-
-USItype
-__umodsi3 (USItype a, USItype b)
-{
- return __udivmodsi4 (a, b, 1);
-}
-
-
-/* Shifts - Optimized versions implemented in assembly. Use these if code space is preferred to performance. */
-SItype
-__ashlsi3 (SItype a, SItype b)
-{
- int i;
-
- for (i = (b & 0x1f); i > 0; --i)
- a += a;
- return a;
-}
-
-SItype
-__ashrsi3 (SItype a, SItype b)
-{
- int i;
-
- for (i = (b & 0x1f); i > 0; --i)
- __asm__ ("sri %0, %0, 1" : "=r" (a) : "0" (a));
- return a;
-}
-
-USItype
-__lshrsi3 (USItype a, USItype b)
-{
- int i;
-
- for (i = (b & 0x1f); i > 0; --i)
- __asm__ ("srui %0, %0, 1" : "=r" (a) : "0" (a));
- return a;
-}
View
181 arch/lm32/lib/libgcc2.c
@@ -1,181 +0,0 @@
-/* Arithmetic functions taken from libgcc2 for lm32 */
-
-typedef int QItype __attribute__ ((mode (QI)));
-typedef unsigned int UQItype __attribute__ ((mode (QI)));
-typedef int HItype __attribute__ ((mode (HI)));
-typedef unsigned int UHItype __attribute__ ((mode (HI)));
-typedef int SItype __attribute__ ((mode (SI)));
-typedef unsigned int USItype __attribute__ ((mode (SI)));
-typedef int DItype __attribute__ ((mode (DI)));
-typedef unsigned int UDItype __attribute__ ((mode (DI)));
-
-typedef float SFtype __attribute__ ((mode (SF)));
-typedef float DFtype __attribute__ ((mode (DF)));
-
-typedef int word_type __attribute__ ((mode (__word__)));
-
-#define BITS_PER_UNIT 8
-
-#define Wtype SItype
-#define UWtype USItype
-#define HWtype SItype
-#define UHWtype USItype
-#define DWtype DItype
-#define UDWtype UDItype
-
-extern UDWtype __umulsidi3 (UWtype, UWtype);
-extern DWtype __muldi3 (DWtype, DWtype);
-extern DWtype __divdi3 (DWtype, DWtype);
-extern UDWtype __udivdi3 (UDWtype, UDWtype);
-extern UDWtype __umoddi3 (UDWtype, UDWtype);
-extern DWtype __moddi3 (DWtype, DWtype);
-extern DWtype __negdi2 (DWtype);
-extern DWtype __lshrdi3 (DWtype, word_type);
-extern DWtype __ashldi3 (DWtype, word_type);
-extern DWtype __ashrdi3 (DWtype, word_type);
-
-// big endian
-struct DWstruct {
- Wtype high, low;
-};
-
-typedef union
-{
- struct DWstruct s;
- DWtype ll;
-} DWunion;
-
-DWtype
-__negdi2 (DWtype u)
-{
- const DWunion uu = {.ll = u};
- const DWunion w = { {.low = -uu.s.low,
- .high = -uu.s.high - ((UWtype) -uu.s.low > 0) } };
-
- return w.ll;
-}
-
-#define W_TYPE_SIZE 32
-#define __ll_B ((UWtype) 1 << (W_TYPE_SIZE / 2))
-#define __ll_lowpart(t) ((UWtype) (t) & (__ll_B - 1))
-#define __ll_highpart(t) ((UWtype) (t) >> (W_TYPE_SIZE / 2))
-#define umul_ppmm(w1, w0, u, v) \
- do { \
- UWtype __x0, __x1, __x2, __x3; \
- UHWtype __ul, __vl, __uh, __vh; \
- \
- __ul = __ll_lowpart (u); \
- __uh = __ll_highpart (u); \
- __vl = __ll_lowpart (v); \
- __vh = __ll_highpart (v); \
- \
- __x0 = (UWtype) __ul * __vl; \
- __x1 = (UWtype) __ul * __vh; \
- __x2 = (UWtype) __uh * __vl; \
- __x3 = (UWtype) __uh * __vh; \
- \
- __x1 += __ll_highpart (__x0);/* this can't give carry */ \
- __x1 += __x2; /* but this indeed can */ \
- if (__x1 < __x2) /* did we get it? */ \
- __x3 += __ll_B; /* yes, add it in the proper pos. */ \
- \
- (w1) = __x3 + __ll_highpart (__x1); \
- (w0) = __ll_lowpart (__x1) * __ll_B + __ll_lowpart (__x0); \
- } while (0)
-
-#define __umulsidi3(u, v) \
- ({DWunion __w; \
- umul_ppmm (__w.s.high, __w.s.low, u, v); \
- __w.ll; })
-
-DWtype
-__muldi3 (DWtype u, DWtype v)
-{
- const DWunion uu = {.ll = u};
- const DWunion vv = {.ll = v};
- DWunion w = {.ll = __umulsidi3 (uu.s.low, vv.s.low)};
-
- w.s.high += ((UWtype) uu.s.low * (UWtype) vv.s.high
- + (UWtype) uu.s.high * (UWtype) vv.s.low);
-
- return w.ll;
-}
-
-DWtype
-__lshrdi3 (DWtype u, word_type b)
-{
- const DWunion uu = {.ll = u};
- const word_type bm = (sizeof (Wtype) * BITS_PER_UNIT) - b;
- DWunion w;
-
- if (b == 0)
- return u;
-
- if (bm <= 0)
- {
- w.s.high = 0;
- w.s.low = (UWtype) uu.s.high >> -bm;
- }
- else
- {
- const UWtype carries = (UWtype) uu.s.high << bm;
-
- w.s.high = (UWtype) uu.s.high >> b;
- w.s.low = ((UWtype) uu.s.low >> b) | carries;
- }
-
- return w.ll;
-}
-
-DWtype
-__ashldi3 (DWtype u, word_type b)
-{
- const DWunion uu = {.ll = u};
- const word_type bm = (sizeof (Wtype) * BITS_PER_UNIT) - b;
- DWunion w;
-
- if (b == 0)
- return u;
-
- if (bm <= 0)
- {
- w.s.low = 0;
- w.s.high = (UWtype) uu.s.low << -bm;
- }
- else
- {
- const UWtype carries = (UWtype) uu.s.low >> bm;
-
- w.s.low = (UWtype) uu.s.low << b;
- w.s.high = ((UWtype) uu.s.high << b) | carries;
- }
-
- return w.ll;
-}
-
-DWtype
-__ashrdi3 (DWtype u, word_type b)
-{
- const DWunion uu = {.ll = u};
- const word_type bm = (sizeof (Wtype) * BITS_PER_UNIT) - b;
- DWunion w;
-
- if (b == 0)
- return u;
-
- if (bm <= 0)
- {
- /* w.s.high = 1..1 or 0..0 */
- w.s.high = uu.s.high >> (sizeof (Wtype) * BITS_PER_UNIT - 1);
- w.s.low = uu.s.high >> -bm;
- }
- else
- {
- const UWtype carries = (UWtype) uu.s.high << bm;
-
- w.s.high = uu.s.high >> b;
- w.s.low = ((UWtype) uu.s.low >> b) | carries;
- }
-
- return w.ll;
-}
Please sign in to comment.
Something went wrong with that request. Please try again.