From d49ac097ab97fc1b5a96ef6f50ab7eaa8a6ba332 Mon Sep 17 00:00:00 2001 From: Yunjie Gu Date: Wed, 24 Aug 2022 22:12:11 +0100 Subject: [PATCH] =?UTF-8?q?[kernel]=20=E4=BF=AE=E5=A4=8D=20rt=5Fmemset=20?= =?UTF-8?q?=E4=BD=BF=E5=85=B6=20word=20size=20independent.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For compatibility with 16bit addressing 32bit CPU (e.g. TI C28x). --- src/kservice.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/kservice.c b/src/kservice.c index ef7f38ba2e..5665c37b57 100644 --- a/src/kservice.c +++ b/src/kservice.c @@ -21,6 +21,7 @@ * 2021-12-20 Meco Man implement rt_strcpy() * 2022-01-07 Gabriel add __on_rt_assert_hook * 2022-06-04 Meco Man remove strnlen + * 2022-08-24 Yunjie make rt_memset word-independent to adapt to ti c28x (16bit word) */ #include @@ -182,7 +183,7 @@ RT_WEAK void *rt_memset(void *s, int c, rt_ubase_t count) return s; #else -#define LBLOCKSIZE (sizeof(long)) +#define LBLOCKSIZE (sizeof(rt_ubase_t)) #define UNALIGNED(X) ((long)X & (LBLOCKSIZE - 1)) #define TOO_SMALL(LEN) ((LEN) < LBLOCKSIZE) @@ -190,8 +191,10 @@ RT_WEAK void *rt_memset(void *s, int c, rt_ubase_t count) char *m = (char *)s; unsigned long buffer; unsigned long *aligned_addr; - unsigned int d = c & 0xff; /* To avoid sign extension, copy C to an - unsigned variable. */ + unsigned char d = (unsigned int)c & (unsigned char)(-1); /* To avoid sign extension, copy C to an + unsigned variable. (unsigned)((char)(-1))=0xFF for 8bit and =0xFFFF for 16bit: word independent */ + + RT_ASSERT(LBLOCKSIZE == 2 || LBLOCKSIZE == 4 || LBLOCKSIZE == 8); if (!TOO_SMALL(count) && !UNALIGNED(s)) { @@ -201,16 +204,9 @@ RT_WEAK void *rt_memset(void *s, int c, rt_ubase_t count) /* Store d into each char sized location in buffer so that * we can set large blocks quickly. */ - if (LBLOCKSIZE == 4) + for (i = 0; i < LBLOCKSIZE; i++) { - buffer = (d << 8) | d; - buffer |= (buffer << 16); - } - else - { - buffer = 0; - for (i = 0; i < LBLOCKSIZE; i ++) - buffer = (buffer << 8) | d; + *(((unsigned char *)&buffer)+i) = d; } while (count >= LBLOCKSIZE * 4) @@ -643,7 +639,7 @@ void rt_show_version(void) rt_kprintf("\n \\ | /\n"); rt_kprintf("- RT - Thread Operating System\n"); rt_kprintf(" / | \\ %d.%d.%d build %s %s\n", - RT_VERSION, RT_SUBVERSION, RT_REVISION, __DATE__, __TIME__); + (rt_int32_t)RT_VERSION, (rt_int32_t)RT_SUBVERSION, (rt_int32_t)RT_REVISION, __DATE__, __TIME__); rt_kprintf(" 2006 - 2022 Copyright by RT-Thread team\n"); } RTM_EXPORT(rt_show_version);