From 996b2b8ded02c469ccf5661c6069e5354452abfd Mon Sep 17 00:00:00 2001 From: Yann MAGNIN Date: Sat, 14 May 2022 11:49:08 +0200 Subject: [PATCH] fxlibc - v1.4.1 : update Vhex stdlib @update > malloc : do not use syscall, involve kmalloc > realloc : do not use syscall, involve krealloc > free : do not use syscall, involve kfree @fix > _Exit : remove syscall --- CMakeLists.txt | 9 +++--- src/libc/stdlib/target/vhex-sh/_Exit.S | 12 ------- src/libc/stdlib/target/vhex-sh/free.S | 21 ------------ src/libc/stdlib/target/vhex-sh/free.c | 8 +++++ src/libc/stdlib/target/vhex-sh/malloc.S | 21 ------------ src/libc/stdlib/target/vhex-sh/malloc.c | 12 +++++++ src/libc/stdlib/target/vhex-sh/realloc.S | 41 ------------------------ src/libc/stdlib/target/vhex-sh/realloc.c | 8 +++++ vxsdk.toml | 4 +-- 9 files changed, 34 insertions(+), 102 deletions(-) delete mode 100644 src/libc/stdlib/target/vhex-sh/_Exit.S delete mode 100644 src/libc/stdlib/target/vhex-sh/free.S create mode 100644 src/libc/stdlib/target/vhex-sh/free.c delete mode 100644 src/libc/stdlib/target/vhex-sh/malloc.S create mode 100644 src/libc/stdlib/target/vhex-sh/malloc.c delete mode 100644 src/libc/stdlib/target/vhex-sh/realloc.S create mode 100644 src/libc/stdlib/target/vhex-sh/realloc.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 7340d1e..4a01479 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.15) -project(FxLibc VERSION 1.4.0 LANGUAGES C ASM) +project(FxLibc VERSION 1.4.1 LANGUAGES C ASM) set(CMAKE_INSTALL_MESSAGE LAZY) @@ -242,10 +242,9 @@ if(vhex-sh IN_LIST TARGET_FOLDERS) list(APPEND SOURCES src/libc/signal/target/vhex-sh/kill.S src/libc/signal/target/vhex-sh/signal.S - src/libc/stdlib/target/vhex-sh/_Exit.S - src/libc/stdlib/target/vhex-sh/free.S - src/libc/stdlib/target/vhex-sh/malloc.S - src/libc/stdlib/target/vhex-sh/realloc.S + src/libc/stdlib/target/vhex-sh/free.c + src/libc/stdlib/target/vhex-sh/malloc.c + src/libc/stdlib/target/vhex-sh/realloc.c src/posix/fcntl/target/vhex-sh/open.S src/posix/sys/wait/target/vhex-sh/wait.S src/posix/sys/wait/target/vhex-sh/waitpid.S diff --git a/src/libc/stdlib/target/vhex-sh/_Exit.S b/src/libc/stdlib/target/vhex-sh/_Exit.S deleted file mode 100644 index 931d81f..0000000 --- a/src/libc/stdlib/target/vhex-sh/_Exit.S +++ /dev/null @@ -1,12 +0,0 @@ -#include -.text -.global __Exit -.type __Exit, @function - - -.align 2 -__Exit: - trapa #__NR_exit - rts - nop -.end diff --git a/src/libc/stdlib/target/vhex-sh/free.S b/src/libc/stdlib/target/vhex-sh/free.S deleted file mode 100644 index a757603..0000000 --- a/src/libc/stdlib/target/vhex-sh/free.S +++ /dev/null @@ -1,21 +0,0 @@ -#include -.text -.global _free -.type _free, @function - - -.align 2 -/* -** extern void free(void *ptr) -** Custom syscall which free a block allocated by `malloc', `realloc' or `calloc'. -** -** @note: -** The MMU is used by Casio so we cannot implement brk or skr for technical -** reason (non-continius heap, no shared page, ...), so all memory management -** is performed by the Vhex kernel. -*/ -_free: - trapa #__NR_proc_heap_free - rts - nop -.end diff --git a/src/libc/stdlib/target/vhex-sh/free.c b/src/libc/stdlib/target/vhex-sh/free.c new file mode 100644 index 0000000..5fad8d1 --- /dev/null +++ b/src/libc/stdlib/target/vhex-sh/free.c @@ -0,0 +1,8 @@ +#include + +extern void kfree(void *ptr); + +void free(void *ptr) +{ + return kfree(ptr); +} diff --git a/src/libc/stdlib/target/vhex-sh/malloc.S b/src/libc/stdlib/target/vhex-sh/malloc.S deleted file mode 100644 index b980af4..0000000 --- a/src/libc/stdlib/target/vhex-sh/malloc.S +++ /dev/null @@ -1,21 +0,0 @@ -#include -.text -.global _malloc -.type _malloc, @function - - -.align 2 -/* -** extern void *malloc(size_t size); -** Allocate SIZE bytes of memory. -** -** @note: -** The MMU is used by Casio so we cannot implement brk or skr for technical -** reason (non-continius heap, no shared page, ...), so all memory management -** is performed by the Vhex kernel. -*/ -_malloc: - trapa #__NR_proc_heap_alloc - rts - nop -.end diff --git a/src/libc/stdlib/target/vhex-sh/malloc.c b/src/libc/stdlib/target/vhex-sh/malloc.c new file mode 100644 index 0000000..1a9b8be --- /dev/null +++ b/src/libc/stdlib/target/vhex-sh/malloc.c @@ -0,0 +1,12 @@ +#include +#include + +extern void *kmalloc(size_t size, char const *arena_name); + +void *malloc(size_t size) +{ + void *ptr = kmalloc(size, NULL); + if(ptr == NULL) + errno = ENOMEM; + return ptr; +} diff --git a/src/libc/stdlib/target/vhex-sh/realloc.S b/src/libc/stdlib/target/vhex-sh/realloc.S deleted file mode 100644 index 2eea8da..0000000 --- a/src/libc/stdlib/target/vhex-sh/realloc.S +++ /dev/null @@ -1,41 +0,0 @@ -#include -.text -.global _realloc -.type _realloc, @function - - -.align 2 -/* -** extern void *realloc(void ptr, size_t size) -** -** @note: -** The MMU is used by Casio so we cannot implement brk or skr for technical -** reason (non-continius heap, no shared page, ...), so all memory management -** is performed by the Vhex kernel. -*/ -_realloc: - ! Check if the PTR is NULL - ! In this case, realloc() work like malloc(), so lets call it - tst r4, r4 - bf check_free - mov r5, r4 - trapa #__NR_proc_heap_alloc - rts - nop - - ! Check is the size is NULL - ! In this case, realloc() work like free(), so lets call it - ! then return NULL pointer -check_free: - tst r5, r5 - bf call_realloc - trapa #__NR_proc_heap_free - rts - xor r0, r0 - - ! Call realloc -call_realloc: - trapa #__NR_proc_heap_realloc - rts - nop -.end diff --git a/src/libc/stdlib/target/vhex-sh/realloc.c b/src/libc/stdlib/target/vhex-sh/realloc.c new file mode 100644 index 0000000..b37c445 --- /dev/null +++ b/src/libc/stdlib/target/vhex-sh/realloc.c @@ -0,0 +1,8 @@ +#include + +extern void *krealloc(void *ptr, size_t size); + +void *realloc(void *ptr, size_t size) +{ + return krealloc(ptr, size); +} diff --git a/vxsdk.toml b/vxsdk.toml index 66c5eeb..76aec72 100644 --- a/vxsdk.toml +++ b/vxsdk.toml @@ -1,6 +1,6 @@ -[package] +[project] name = 'fxlibc' -version = '1.3.0' +version = '1.4.1' type = 'app' [build]