libc: implement malloc() etc. through syscalls

Currently only used by libprof itself.
This commit is contained in:
lephe 2019-07-16 15:17:32 -04:00
parent 24fbeab55b
commit 7e09e37938
1 changed files with 40 additions and 7 deletions

View File

@ -9,14 +9,16 @@
** * File system, because it's a mess and we might ruin the ROM.
*/
/* Dynamic allocation */
.global ___malloc
.global ___calloc
.global ___free
.global ___realloc
/* OS version, for debugging purposes */
/* OS version */
.global ___os_version
/* Bfile calls */
/* Dynamic allocation */
.global _malloc
.global _free
.global _calloc
.global _realloc
/* Bfile driver */
.global _BFile_Remove
.global _BFile_Create
.global _BFile_Open
@ -26,6 +28,13 @@
.section ".pretext"
#define syscall(id) \
mov.l syscall_table, r2 ;\
mov.l 1f, r0 ;\
jmp @r2 ;\
nop ;\
1: .long id
#ifdef FX9860G
/* OS version */
@ -37,6 +46,17 @@ ___os_version:
nop
1: .long 0x02ee
/* Dynamic allocation */
_malloc:
syscall(0x0acd)
_free:
syscall(0x0acc)
_calloc:
syscall(0x0e6b)
_realloc:
syscall(0x0e6d)
/* BFile driver */
# int BFile_Remove(const uint16_t *file)
@ -94,6 +114,8 @@ syscall_table:
#ifdef FXCG50
/* OS version */
___os_version:
mov.l syscall_table, r2
mov.l 1f, r0
@ -101,6 +123,17 @@ ___os_version:
nop
1: .long 0x1406
/* Dynamic allocation */
_malloc:
syscall(0x1f44)
_free:
syscall(0x1f42)
_calloc:
syscall(0x1f40)
_realloc:
syscall(0x1f46)
syscall_table:
.long 0x80020070