From 7e09e37938852ef2c604a9f7254faab734f5e6ca Mon Sep 17 00:00:00 2001 From: lephe Date: Tue, 16 Jul 2019 15:17:32 -0400 Subject: [PATCH] libc: implement malloc() etc. through syscalls Currently only used by libprof itself. --- src/core/syscalls.S | 47 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 7 deletions(-) diff --git a/src/core/syscalls.S b/src/core/syscalls.S index fa34180..c0d5d48 100644 --- a/src/core/syscalls.S +++ b/src/core/syscalls.S @@ -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