Skip to content

Commit 49aaeaf

Browse files
committed
bsp/qemu-riscv-virt64/: avoid link libc
1 parent d82a6d1 commit 49aaeaf

File tree

7 files changed

+123
-4
lines changed

7 files changed

+123
-4
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,5 @@ tags
3838
.idea
3939
CMakeLists.txt
4040
cmake-build-debug
41+
42+
.vscode

bsp/qemu-riscv-virt64/applications/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
int main(void)
1717
{
18-
printf("Hello RISC-V!\n");
18+
rt_kprintf("Hello RISC-V!\n");
1919

2020
return 0;
2121
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from building import *
2+
3+
cwd = GetCurrentDir()
4+
src = Glob('*.c')
5+
CPPPATH = [cwd]
6+
7+
if GetDepend('USING_RV64_LINUX_GNU_TOOLCHAIN'):
8+
group = DefineGroup('Drivers', src, depend = [''], CPPPATH = CPPPATH)
9+
else:
10+
group = []
11+
12+
objs = [group]
13+
14+
Return('objs')
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include <rthw.h>
2+
#include <rtconfig.h>
3+
4+
#ifdef USING_RV64_LINUX_GNU_TOOLCHAIN
5+
6+
int vsprintf(char *out, const char *fmt, va_list ap) {
7+
rt_vsprintf(out, fmt, ap);
8+
}
9+
10+
int sprintf(char *out, const char *fmt, ...) {
11+
va_list args;
12+
va_start(args, fmt);
13+
vsprintf(out, fmt, args);
14+
return 0;
15+
}
16+
17+
18+
#endif
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <rthw.h>
2+
#include <rtconfig.h>
3+
4+
#ifdef USING_RV64_LINUX_GNU_TOOLCHAIN
5+
6+
int atoi(const char* nptr) {
7+
int x = 0;
8+
while (*nptr == ' ') { nptr ++; }
9+
while (*nptr >= '0' && *nptr <= '9') {
10+
x = x * 10 + *nptr - '0';
11+
nptr ++;
12+
}
13+
return x;
14+
}
15+
16+
#endif
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#include <rthw.h>
2+
#include "../../rtconfig.h"
3+
4+
#ifdef USING_RV64_LINUX_GNU_TOOLCHAIN
5+
6+
size_t strlen(const char *s) {
7+
return rt_strlen(s);
8+
}
9+
10+
char *strcpy(char* dst, const char* src) {
11+
char *p1 = dst;
12+
const char *p2 = src;
13+
for( ; *p2 != 0; p1++, p2++) *p1 = *p2;
14+
*p1 = 0;
15+
return dst;
16+
}
17+
18+
char* strncpy(char* dst, const char* src, size_t n) {
19+
return rt_strncpy(dst, src, n);
20+
}
21+
22+
char* strcat(char* dst, const char* src) {
23+
size_t len = rt_strlen(dst);
24+
strcpy(dst + len, src);
25+
return dst;
26+
}
27+
28+
int strcmp(const char* s1, const char* s2) {
29+
return rt_strcmp(s1, s2);
30+
}
31+
32+
int strncmp(const char* s1, const char* s2, size_t n) {
33+
return rt_strncmp(s1, s2, n);
34+
}
35+
36+
void* memset(void* v,int c,size_t n) {
37+
return rt_memset(v, c, n);
38+
}
39+
40+
void* memmove(void* dst, const void* src,size_t n) {
41+
return rt_memmove(dst, src, n);
42+
}
43+
44+
void* memcpy(void* out, const void* in, size_t n) {
45+
rt_memcpy(out, in, n);
46+
}
47+
48+
int memcmp(const void* s1, const void* s2, size_t n) {
49+
return rt_memcmp(s1, s2, n);
50+
}
51+
52+
const char* strstr(const char* s1, const char* s2){
53+
return rt_strstr(s1, s2);
54+
}
55+
56+
char *strrchr(const char *s, int c)
57+
{
58+
if(s == RT_NULL) return RT_NULL;
59+
char *p_char = RT_NULL;
60+
while(*s != '\0')
61+
{
62+
if(*s == (char)c) p_char = (char *)s;
63+
s++;
64+
}
65+
return p_char;
66+
}
67+
68+
69+
#endif

bsp/qemu-riscv-virt64/rtconfig.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,16 @@
3232
CXX = PREFIX + 'g++'
3333
AS = PREFIX + 'gcc'
3434
AR = PREFIX + 'ar'
35-
LINK = PREFIX + 'gcc'
35+
LINK = PREFIX + 'ld'
3636
TARGET_EXT = 'elf'
3737
SIZE = PREFIX + 'size'
3838
OBJDUMP = PREFIX + 'objdump'
3939
OBJCPY = PREFIX + 'objcopy'
4040

41-
DEVICE = ' -mcmodel=medany -march=rv64imafdc -mabi=lp64d'
41+
DEVICE = ' -fno-pic -mcmodel=medany -march=rv64imafd -mabi=lp64d'
4242
CFLAGS = DEVICE + ' -fvar-tracking -ffreestanding -fno-common -ffunction-sections -fdata-sections -fstrict-volatile-bitfields '
4343
AFLAGS = ' -c' + DEVICE + ' -x assembler-with-cpp'
44-
LFLAGS = DEVICE + ' -nostartfiles -Wl,--gc-sections,-Map=rtthread.map,-cref,-u,_start -T link.lds -lc -lm '
44+
LFLAGS = ' --gc-sections -Map=rtthread.map -cref -u _start -T link.lds '
4545
CPATH = ''
4646
LPATH = ''
4747

0 commit comments

Comments
 (0)