Skip to content

Commit d30bde3

Browse files
committed
firmware: Move memcpy/memset mapping to fw_base.S
Some of the external firmwares using OpenSBI as library are facing issues with the weak memcpy() and memset() aliases in libsbi.a so we move these to fw_base.S. This way mapping of implicit memcpy() or memset() calls to sbi_memcpy() or sbi_memset() will only be done for OpenSBI firmwares. (Refer, #234) In addition, we also add memmove() and memcmp() mappings in fw_base.S because as-per the GCC documentation the freestanding environment must provide memcpy(), memmove(), memset(), and memcmp(). Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atishp@rivosinc.com>
1 parent 2082153 commit d30bde3

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

firmware/fw_base.S

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,34 @@ fw_platform_init:
561561
add a0, a1, zero
562562
ret
563563

564+
/* Map implicit memcpy() added by compiler to sbi_memcpy() */
565+
.section .text
566+
.align 3
567+
.globl memcpy
568+
memcpy:
569+
tail sbi_memcpy
570+
571+
/* Map implicit memset() added by compiler to sbi_memset() */
572+
.section .text
573+
.align 3
574+
.globl memset
575+
memset:
576+
tail sbi_memset
577+
578+
/* Map implicit memmove() added by compiler to sbi_memmove() */
579+
.section .text
580+
.align 3
581+
.globl memmove
582+
memmove:
583+
tail sbi_memmove
584+
585+
/* Map implicit memcmp() added by compiler to sbi_memcmp() */
586+
.section .text
587+
.align 3
588+
.globl memcmp
589+
memcmp:
590+
tail sbi_memcmp
591+
564592
.macro TRAP_SAVE_AND_SETUP_SP_T0
565593
/* Swap TP and MSCRATCH */
566594
csrrw tp, CSR_MSCRATCH, tp

lib/sbi/sbi_string.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,6 @@ void *sbi_memset(void *s, int c, size_t count)
122122
return s;
123123
}
124124

125-
void *memset(void *s, int c, size_t count) \
126-
__attribute__((weak, alias("sbi_memset")));
127-
128125
void *sbi_memcpy(void *dest, const void *src, size_t count)
129126
{
130127
char *temp1 = dest;
@@ -138,9 +135,6 @@ void *sbi_memcpy(void *dest, const void *src, size_t count)
138135
return dest;
139136
}
140137

141-
void *memcpy(void *dest, const void *src, size_t count) \
142-
__attribute__((weak, alias("sbi_memcpy")));
143-
144138
void *sbi_memmove(void *dest, const void *src, size_t count)
145139
{
146140
char *temp1 = (char *)dest;

0 commit comments

Comments
 (0)