From 2470ef3c7e4ea175d8b70ff2676d0e715ac50816 Mon Sep 17 00:00:00 2001 From: Paulo Flabiano Smorigo Date: Wed, 13 Aug 2014 19:00:19 +0000 Subject: [PATCH 485/506] Files reorganization and include some libgcc fuctions As we avoid libgcc dependency for powerpc64el, we moved some functions to other files and add the necessary ones. * Makefile.core.def: Include compiler-rt.S. * misc.c: Add the necessary libgcc functions. * compiler-rt.S: New file. * libgcc.h: Move some content from here ... * compiler.h: ... to here. Also-By: Brent Baude Also-By: Vladimir 'phcoder' Serbinenko --- grub-core/kern/misc.c | 107 ++++++++++++++++++++++++++++++++++++++++++++++++ include/grub/compiler.h | 61 +++++++++++++++++++++++++++ include/grub/libgcc.h | 24 +++++++++++ 3 files changed, 192 insertions(+) create mode 100644 include/grub/libgcc.h diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c index 6b3397f..66f11f8 100644 --- a/grub-core/kern/misc.c +++ b/grub-core/kern/misc.c @@ -1144,3 +1144,110 @@ grub_real_boot_time (const char *file, grub_error_pop (); } #endif + +#if defined (NO_LIBGCC) + +/* Based on libgcc2.c from gcc suite. */ +int +__ucmpdi2 (grub_uint64_t a, grub_uint64_t b) +{ + union component64 ac, bc; + ac.full = a; + bc.full = b; + + if (ac.high < bc.high) + return 0; + else if (ac.high > bc.high) + return 2; + + if (ac.low < bc.low) + return 0; + else if (ac.low > bc.low) + return 2; + return 1; +} + + +/* Based on libgcc2.c from gcc suite. */ +grub_uint64_t +__lshrdi3 (grub_uint64_t u, int b) +{ + if (b == 0) + return u; + + const union component64 uu = {.full = u}; + const int bm = 32 - b; + union component64 w; + + if (bm <= 0) + { + w.high = 0; + w.low = (grub_uint32_t) uu.high >> -bm; + } + else + { + const grub_uint32_t carries = (grub_uint32_t) uu.high << bm; + + w.high = (grub_uint32_t) uu.high >> b; + w.low = ((grub_uint32_t) uu.low >> b) | carries; + } + + return w.full; +} + +/* Based on libgcc2.c from gcc suite. */ +grub_uint64_t +__ashrdi3 (grub_uint64_t u, int b) +{ + if (b == 0) + return u; + + const union component64 uu = {.full = u}; + const int bm = 32 - b; + union component64 w; + + if (bm <= 0) + { + /* w.high = 1..1 or 0..0 */ + w.high = uu.high >> (32 - 1); + w.low = uu.high >> -bm; + } + else + { + const grub_uint32_t carries = (grub_uint32_t) uu.high << bm; + + w.high = uu.high >> b; + w.low = ((grub_uint32_t) uu.low >> b) | carries; + } + + return w.full; +} + +/* Based on libgcc2.c from gcc suite. */ +grub_uint64_t +__ashldi3 (grub_uint64_t u, int b) +{ + if (b == 0) + return u; + + const union component64 uu = {.full = u}; + const int bm = 32 - b; + union component64 w; + + if (bm <= 0) + { + w.low = 0; + w.high = (grub_uint32_t) uu.low << -bm; + } + else + { + const grub_uint32_t carries = (grub_uint32_t) uu.low >> bm; + + w.low = (grub_uint32_t) uu.low << b; + w.high = ((grub_uint32_t) uu.high << b) | carries; + } + + return w.full; +} + +#endif diff --git a/include/grub/compiler.h b/include/grub/compiler.h index c9e1d7a..a9a684c 100644 --- a/include/grub/compiler.h +++ b/include/grub/compiler.h @@ -48,4 +48,65 @@ # define WARN_UNUSED_RESULT #endif +#include "types.h" + +union component64 +{ + grub_uint64_t full; + struct + { +#ifdef GRUB_CPU_WORDS_BIGENDIAN + grub_uint32_t high; + grub_uint32_t low; +#else + grub_uint32_t low; + grub_uint32_t high; +#endif + }; +}; + +#if defined (__powerpc__) +grub_uint64_t EXPORT_FUNC (__lshrdi3) (grub_uint64_t u, int b); +grub_uint64_t EXPORT_FUNC (__ashrdi3) (grub_uint64_t u, int b); +grub_uint64_t EXPORT_FUNC (__ashldi3) (grub_uint64_t u, int b); +int EXPORT_FUNC(__ucmpdi2) (grub_uint64_t a, grub_uint64_t b); +void EXPORT_FUNC (_restgpr_14_x) (void); +void EXPORT_FUNC (_restgpr_15_x) (void); +void EXPORT_FUNC (_restgpr_16_x) (void); +void EXPORT_FUNC (_restgpr_17_x) (void); +void EXPORT_FUNC (_restgpr_18_x) (void); +void EXPORT_FUNC (_restgpr_19_x) (void); +void EXPORT_FUNC (_restgpr_20_x) (void); +void EXPORT_FUNC (_restgpr_21_x) (void); +void EXPORT_FUNC (_restgpr_22_x) (void); +void EXPORT_FUNC (_restgpr_23_x) (void); +void EXPORT_FUNC (_restgpr_24_x) (void); +void EXPORT_FUNC (_restgpr_25_x) (void); +void EXPORT_FUNC (_restgpr_26_x) (void); +void EXPORT_FUNC (_restgpr_27_x) (void); +void EXPORT_FUNC (_restgpr_28_x) (void); +void EXPORT_FUNC (_restgpr_29_x) (void); +void EXPORT_FUNC (_restgpr_30_x) (void); +void EXPORT_FUNC (_restgpr_31_x) (void); +void EXPORT_FUNC (_savegpr_14) (void); +void EXPORT_FUNC (_savegpr_15) (void); +void EXPORT_FUNC (_savegpr_16) (void); +void EXPORT_FUNC (_savegpr_17) (void); +void EXPORT_FUNC (_savegpr_18) (void); +void EXPORT_FUNC (_savegpr_19) (void); +void EXPORT_FUNC (_savegpr_20) (void); +void EXPORT_FUNC (_savegpr_21) (void); +void EXPORT_FUNC (_savegpr_22) (void); +void EXPORT_FUNC (_savegpr_23) (void); +void EXPORT_FUNC (_savegpr_24) (void); +void EXPORT_FUNC (_savegpr_25) (void); +void EXPORT_FUNC (_savegpr_26) (void); +void EXPORT_FUNC (_savegpr_27) (void); +void EXPORT_FUNC (_savegpr_28) (void); +void EXPORT_FUNC (_savegpr_29) (void); +void EXPORT_FUNC (_savegpr_30) (void); +void EXPORT_FUNC (_savegpr_31) (void); + +#endif + #endif /* ! GRUB_COMPILER_HEADER */ diff --git a/include/grub/libgcc.h b/include/grub/libgcc.h new file mode 100644 index 0000000..5bdb8fb --- /dev/null +++ b/include/grub/libgcc.h @@ -0,0 +1,24 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2004,2007,2009 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#if defined (__arm__) +void EXPORT_FUNC (__aeabi_lasr) (void); +void EXPORT_FUNC (__aeabi_llsl) (void); +void EXPORT_FUNC (__aeabi_llsr) (void); +void EXPORT_FUNC (__aeabi_ulcmp) (void); +#endif -- 2.4.3