mirror of
https://github.com/vortexgpgpu/vortex.git
synced 2025-04-23 21:39:10 -04:00
minor update
This commit is contained in:
parent
daf1360d83
commit
c554f53e44
2 changed files with 58 additions and 33 deletions
|
@ -1,10 +1,10 @@
|
|||
// Copyright © 2019-2023
|
||||
//
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
@ -21,26 +21,26 @@
|
|||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
int _close(int file) { return -1; }
|
||||
|
||||
|
||||
int _fstat(int file, struct stat *st) { return -1; }
|
||||
|
||||
|
||||
int _isatty(int file) { return 0; }
|
||||
|
||||
|
||||
int _lseek(int file, int ptr, int dir) { return 0; }
|
||||
|
||||
|
||||
int _open(const char *name, int flags, int mode) { return -1; }
|
||||
|
||||
|
||||
int _read(int file, char *ptr, int len) { return -1; }
|
||||
|
||||
caddr_t _sbrk(int incr) {
|
||||
|
||||
caddr_t _sbrk(int incr) {
|
||||
__asm__ __volatile__("ebreak");
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int _write(int file, char *ptr, int len) {
|
||||
int i;
|
||||
int i;
|
||||
for (i = 0; i < len; ++i) {
|
||||
vx_putchar(*ptr++);
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ int _getpid() {
|
|||
return vx_hart_id();
|
||||
}
|
||||
|
||||
void __init_tls(void) {
|
||||
void __init_tls(void) {
|
||||
extern char __tdata_start[];
|
||||
extern char __tbss_offset[];
|
||||
extern char __tdata_size[];
|
||||
|
@ -108,7 +108,7 @@ extern void _fini (void);
|
|||
void __libc_fini_array (void) {
|
||||
size_t count;
|
||||
size_t i;
|
||||
|
||||
|
||||
count = __fini_array_end - __fini_array_start;
|
||||
for (i = count; i > 0; i--)
|
||||
__fini_array_start[i-1] ();
|
||||
|
@ -119,19 +119,41 @@ void __libc_fini_array (void) {
|
|||
}
|
||||
#endif
|
||||
|
||||
#define FEXIT_COUNT 64
|
||||
#define MAX_CORES 64
|
||||
|
||||
volatile int g_cxa_locks[MAX_CORES] = {0};
|
||||
|
||||
void __cxa_lock() {
|
||||
int core_id = vx_core_id();
|
||||
g_cxa_locks[core_id] = 1;
|
||||
vx_fence();
|
||||
for (int i = 1; i < MAX_CORES; ++i) {
|
||||
int other = (core_id + i) % MAX_CORES;
|
||||
while (g_cxa_locks[other]) {
|
||||
vx_fence(); // cache coherence not supported, so we need to flush the caches
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void __cxa_unlock() {
|
||||
vx_fence();
|
||||
int core_id = vx_core_id();
|
||||
g_cxa_locks[core_id] = 0;
|
||||
}
|
||||
|
||||
#define MAX_FEXITS 64
|
||||
|
||||
typedef struct {
|
||||
void (*f[FEXIT_COUNT])(void *);
|
||||
void *a[FEXIT_COUNT];
|
||||
void (*f[MAX_FEXITS])(void*);
|
||||
void *a[MAX_FEXITS];
|
||||
} fexit_list_t;
|
||||
|
||||
static fexit_list_t g_fexit_list;
|
||||
static int g_num_fexits;
|
||||
static int g_num_fexits = 0;
|
||||
|
||||
void __funcs_on_exit() {
|
||||
void (*func)(void *), *arg;
|
||||
fexit_list_t* fexit_list = &g_fexit_list;
|
||||
void (*func)(void *), *arg;
|
||||
fexit_list_t* fexit_list = &g_fexit_list;
|
||||
for (int i = 0; i < g_num_fexits; ++i) {
|
||||
func = fexit_list->f[i];
|
||||
arg = fexit_list->a[i];
|
||||
|
@ -142,12 +164,15 @@ void __funcs_on_exit() {
|
|||
void __cxa_finalize(void *dso) {}
|
||||
|
||||
int __cxa_atexit(void (*func)(void *), void *arg, void *dso) {
|
||||
if (g_num_fexits == FEXIT_COUNT)
|
||||
__cxa_lock();
|
||||
int num_fexits = g_num_fexits;
|
||||
if (num_fexits >= MAX_FEXITS)
|
||||
return -1;
|
||||
fexit_list_t* fexit_list = &g_fexit_list;
|
||||
fexit_list->f[g_num_fexits] = func;
|
||||
fexit_list->a[g_num_fexits] = arg;
|
||||
++g_num_fexits;
|
||||
fexit_list->f[num_fexits] = func;
|
||||
fexit_list->a[num_fexits] = arg;
|
||||
g_num_fexits = num_fexits + 1;
|
||||
__cxa_unlock();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -156,7 +181,7 @@ static void call(void *p) {
|
|||
}
|
||||
|
||||
int atexit(void (*func)(void)) {
|
||||
return __cxa_atexit(call, (void *)(uintptr_t)func, 0);
|
||||
return __cxa_atexit(call, (void*)(uintptr_t)func, 0);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -10,8 +10,8 @@ set(CMAKE_SYSTEM_PROCESSOR riscv32)
|
|||
|
||||
# Specify the binary utilities
|
||||
set(CMAKE_AR "${TOOLDIR}/llvm-vortex/bin/llvm-ar")
|
||||
set(CMAKE_ASM_COMPILER "${TOOLDIR}/llvm-vortex/bin/llvm-as")
|
||||
set(CMAKE_LINKER "${TOOLDIR}/llvm-vortex/bin/lld")
|
||||
#set(CMAKE_ASM_COMPILER "${TOOLDIR}/llvm-vortex/bin/llvm-as")
|
||||
set(CMAKE_LINKER "${TOOLDIR}/llvm-vortex/bin/llvm-lld")
|
||||
set(CMAKE_NM "${TOOLDIR}/llvm-vortex/bin/llvm-nm")
|
||||
set(CMAKE_RANLIB "${TOOLDIR}/llvm-vortex/bin/llvm-ranlib")
|
||||
|
||||
|
@ -20,17 +20,17 @@ set(CMAKE_C_COMPILER "${TOOLDIR}/llvm-vortex/bin/clang")
|
|||
set(CMAKE_CXX_COMPILER "${TOOLDIR}/llvm-vortex/bin/clang++")
|
||||
|
||||
# Compiler flags for C and C++
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -v --gcc-toolchain=${TOOLDIR}/riscv-gnu-toolchain -march=rv32imaf -mabi=ilp32f -Xclang -target-feature -Xclang +vortex -mcmodel=medany -fno-rtti -fno-exceptions -fdata-sections -ffunction-sections")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -v --gcc-toolchain=${TOOLDIR}/riscv-gnu-toolchain -march=rv32imaf -mabi=ilp32f -Xclang -target-feature -Xclang +vortex -mcmodel=medany -fno-rtti -fno-exceptions -fdata-sections -ffunction-sections")
|
||||
set(CMAKE_C_FLAGS "-v --gcc-toolchain=${TOOLDIR}/riscv-gnu-toolchain -march=rv32imaf -mabi=ilp32f -Xclang -target-feature -Xclang +vortex -mcmodel=medany -fno-rtti -fno-exceptions -fdata-sections -ffunction-sections")
|
||||
set(CMAKE_CXX_FLAGS "-v --gcc-toolchain=${TOOLDIR}/riscv-gnu-toolchain -march=rv32imaf -mabi=ilp32f -Xclang -target-feature -Xclang +vortex -mcmodel=medany -fno-rtti -fno-exceptions -fdata-sections -ffunction-sections")
|
||||
|
||||
# Set the sysroot
|
||||
set(CMAKE_SYSROOT "${TOOLDIR}/riscv-gnu-toolchain/riscv32-unknown-elf")
|
||||
set(CMAKE_SYSROOT "${TOOLDIR}/riscv32-gnu-toolchain/riscv32-unknown-elf")
|
||||
|
||||
# Linker flags
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=lld -nostartfiles -Wl,-Bstatic,--gc-sections,-T,${VORTEX_HOME}/kernel/scripts/link32.ld,--defsym=STARTUP_ADDR=${STARTUP_ADDR} ${VORTEX_BUILD}/kernel/libvortexrt.a")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "-fuse-ld=lld -nostartfiles -Wl,-Bstatic,--gc-sections,-T,${VORTEX_HOME}/kernel/scripts/link32.ld ${VORTEX_BUILD}/kernel/libvortexrt.a")
|
||||
|
||||
# Don't run the linker on compiler check
|
||||
#set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
|
||||
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
|
||||
|
||||
set(HAVE_CXX_ATOMICS64_WITHOUT_LIB True)
|
||||
set(HAVE_CXX_ATOMICS_WITHOUT_LIB True)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue