Prevent gcc converting block copies/sets to memcpy() and memset(), which don't exist.

This commit is contained in:
Toby Jaffey 2025-12-11 01:10:55 +00:00
parent 59e6ebfedf
commit 58f8caee5a
2 changed files with 10 additions and 20 deletions

View file

@ -1,7 +1,7 @@
PREFIX:=riscv64-elf- PREFIX:=riscv64-elf-
OPT ?= -Os OPT ?= -Os
CFLAGS+=-I${TOPDIR}/common CFLAGS+=-I${TOPDIR}/common
CFLAGS+=-fno-stack-protector CFLAGS+=-fno-stack-protector -fno-builtin-memcpy -fno-builtin
CFLAGS+=-static-libgcc -fdata-sections -ffunction-sections CFLAGS+=-static-libgcc -fdata-sections -ffunction-sections
CFLAGS+=-g ${OPT} -march=rv32im -mabi=ilp32 -static CFLAGS+=-g ${OPT} -march=rv32im -mabi=ilp32 -static
LDFLAGS:= -T ${TOPDIR}/apps/linker.ld -nostdlib -Wl,--gc-sections LDFLAGS:= -T ${TOPDIR}/apps/linker.ld -nostdlib -Wl,--gc-sections

View file

@ -8,16 +8,7 @@
char maze[HEIGHT * WIDTH]; char maze[HEIGHT * WIDTH];
void* memcpy(void* dst, const void* src, int len) { void* my_memset(void* buf, int c, int len) {
uint8_t* d = (uint8_t*)dst;
const uint8_t* s = (const uint8_t*)src;
while (len--) {
*(d++) = *(s++);
}
return dst;
}
void* memset(void* buf, int c, int len) {
uint8_t* b = (uint8_t*)buf; uint8_t* b = (uint8_t*)buf;
while (len--) { while (len--) {
*(b++) = c; *(b++) = c;
@ -28,18 +19,17 @@ void* memset(void* buf, int c, int len) {
int dx[] = {0, 1, 0, -1}; int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0}; int dy[] = {-1, 0, 1, 0};
int seed = 123456789; uint32_t state = 0x1;
int rand() { int32_t mulberry32(void) {
uint32_t a = 1103515245; uint32_t z = (state += 0x6D2B79F5UL);
uint32_t c = 12345; z = (z ^ (z >> 15)) * (z | 1UL);
uint32_t m = 0xFFFFFFFF; z ^= z + (z ^ (z >> 7)) * (z | 61UL);
seed = (a * seed + c) % m; return z ^ (z >> 14);
return seed;
} }
void init_maze() { void init_maze() {
memset(maze, '#', sizeof(maze)); my_memset(maze, '#', sizeof(maze));
} }
int in_bounds(int x, int y) { int in_bounds(int x, int y) {
@ -52,7 +42,7 @@ void carve(int x, int y) {
int dirs[] = {0, 1, 2, 3}; int dirs[] = {0, 1, 2, 3};
// Fisher-Yates shuffle // Fisher-Yates shuffle
for (int i = 3; i > 0; i--) { for (int i = 3; i > 0; i--) {
int j = rand() % (i + 1); int j = mulberry32() % (i + 1);
int tmp = dirs[i]; int tmp = dirs[i];
dirs[i] = dirs[j]; dirs[i] = dirs[j];
dirs[j] = tmp; dirs[j] = tmp;