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
This commit is contained in:
Yann MAGNIN 2022-05-14 11:49:08 +02:00
parent d50e44c563
commit 996b2b8ded
9 changed files with 34 additions and 102 deletions

View File

@ -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

View File

@ -1,12 +0,0 @@
#include <bits/asm/unistd_32.h>
.text
.global __Exit
.type __Exit, @function
.align 2
__Exit:
trapa #__NR_exit
rts
nop
.end

View File

@ -1,21 +0,0 @@
#include <bits/asm/unistd_32.h>
.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

View File

@ -0,0 +1,8 @@
#include <stdlib.h>
extern void kfree(void *ptr);
void free(void *ptr)
{
return kfree(ptr);
}

View File

@ -1,21 +0,0 @@
#include <bits/asm/unistd_32.h>
.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

View File

@ -0,0 +1,12 @@
#include <stdlib.h>
#include <errno.h>
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;
}

View File

@ -1,41 +0,0 @@
#include <bits/asm/unistd_32.h>
.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

View File

@ -0,0 +1,8 @@
#include <stdlib.h>
extern void *krealloc(void *ptr, size_t size);
void *realloc(void *ptr, size_t size)
{
return krealloc(ptr, size);
}

View File

@ -1,6 +1,6 @@
[package]
[project]
name = 'fxlibc'
version = '1.3.0'
version = '1.4.1'
type = 'app'
[build]