Compare commits

...

5 commits

Author SHA1 Message Date
Lephe
aba6c280b6
hh2: provide metadata macros and a non-metadata marker by default
If none of the HH2_*() macros are used, the binary will show up as its
own filename instead of random garbage.

If HH2_NAME() is used the metadata will be read, and the binary format
requires that all fields by specified. Using only a subset of the macros
is invalid, but not reported.
2024-08-17 18:05:43 +02:00
Lephe
979873288a
defs: allow bool * pointer variants in GINT_CALL 2024-08-15 22:17:22 +02:00
Lephe
6ebfe8484e
Revert "meta: build with -ffreestanding"
This reverts commit b0c4e6fd2f.

After investigation, this is related to builtin functions. Using
-fno-builtin is a less invasive way to solve the problem. However this
appears to be a bug [1]; in theory fat LTO objects should solve that. I
will handle this matter at the fxSDK level by adding -fno-builtin right
and experimenting with the bugfix in binutils 2.43.

[1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114337
2024-08-07 10:13:47 +02:00
Lephe
93329ab697
fix new GCC 14 warnings 2024-08-06 19:02:43 +02:00
Lephe
85e50658ea
libc: provide the fxlibc HAL
See 8cedf41 in fxlibc for rationale.
2024-08-06 19:01:43 +02:00
9 changed files with 85 additions and 7 deletions

View file

@ -23,6 +23,8 @@ endif()
configure_file(include/gint/config.h.in include/gint/config.h) configure_file(include/gint/config.h.in include/gint/config.h)
set(SOURCES set(SOURCES
# Hardware Abstraction Layer for the standard library
src/fxlibc_hal.c
# Clock Pulse Generator driver # Clock Pulse Generator driver
src/cpg/cpg.c src/cpg/cpg.c
src/cpg/overclock.c src/cpg/overclock.c
@ -261,7 +263,7 @@ fxconv_declare_assets(${ASSETS_FX} ${ASSETS_CG})
include_directories( include_directories(
"${PROJECT_SOURCE_DIR}/include" "${PROJECT_SOURCE_DIR}/include"
"${PROJECT_BINARY_DIR}/include") "${PROJECT_BINARY_DIR}/include")
add_compile_options(-Wall -Wextra -std=c11 -Os -g -fstrict-volatile-bitfields -mtas -ffreestanding -flto) add_compile_options(-Wall -Wextra -std=c11 -Os -g -fstrict-volatile-bitfields -mtas -flto)
if("${FXSDK_PLATFORM_LONG}" STREQUAL fx9860G) if("${FXSDK_PLATFORM_LONG}" STREQUAL fx9860G)
add_compile_definitions(FX9860G) add_compile_definitions(FX9860G)

View file

@ -43,7 +43,10 @@ SECTIONS
- All text from .text and .text.* (including user code) */ - All text from .text and .text.* (including user code) */
.hh2 : { .hh2 : {
KEEP(*(.hh2.header)) KEEP(*(.hh2.header))
KEEP(*(.hh2.info)) KEEP(*(.hh2.info.name))
KEEP(*(.hh2.info.description))
KEEP(*(.hh2.info.author))
KEEP(*(.hh2.info.version))
KEEP(*(.hh2.stage2)) KEEP(*(.hh2.stage2))
. = ALIGN(16); . = ALIGN(16);
} > eram AT> bin } > eram AT> bin

View file

@ -80,4 +80,26 @@
#define GINT_RENDER_MONO (GINT_HW_FX || GINT_FX9860G_G3A) #define GINT_RENDER_MONO (GINT_HW_FX || GINT_FX9860G_G3A)
#define GINT_RENDER_RGB ((GINT_HW_CG || GINT_HW_CP) && !GINT_FX9860G_G3A) #define GINT_RENDER_RGB ((GINT_HW_CG || GINT_HW_CP) && !GINT_FX9860G_G3A)
/* Macros for specifying HH2 binary metadata fields. Here because this header
is guaranteed to be included with every gint header. */
#if GINT_HW_CP
#define HH2_NAME(STR) \
GSECTION(".hh2.info.name") GVISIBLE \
char _hh2info_name[] = (STR);
#define HH2_DESCRIPTION(STR) \
GSECTION(".hh2.info.description") GVISIBLE \
char _hh2info_description[] = (STR);
#define HH2_AUTHOR(STR) \
GSECTION(".hh2.info.author") GVISIBLE \
char _hh2info_author[] = (STR);
#define HH2_VERSION(STR) \
GSECTION(".hh2.info.version") GVISIBLE \
char _hh2info_version[] = (STR);
#else
#define HH2_NAME(STR)
#define HH2_DESCRIPTION(STR)
#define HH2_AUTHOR(STR)
#define HH2_VERSION(STR)
#endif
#endif /* GINT_CONFIG */ #endif /* GINT_CONFIG */

View file

@ -11,6 +11,8 @@
#ifndef GINT_DEFS_CALL #ifndef GINT_DEFS_CALL
#define GINT_DEFS_CALL #define GINT_DEFS_CALL
#include <stdbool.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@ -38,6 +40,7 @@ typedef union {
type volatile const *name ## _cv; type volatile const *name ## _cv;
POINTER(void, pv) POINTER(void, pv)
POINTER(bool, pb)
POINTER(char, pc) POINTER(char, pc)
POINTER(unsigned char, puc) POINTER(unsigned char, puc)
POINTER(short, ps) POINTER(short, ps)

40
src/fxlibc_hal.c Normal file
View file

@ -0,0 +1,40 @@
/* Hardware Abstraction Layer (HAL) implementation for fxlibc. We can group
this in a single file because LTO will prune away unused functions. */
#include <fxlibc/hal.h>
#include <gint/rtc.h>
#include <gint/kmalloc.h>
#include <errno.h>
void *fxlibc_hal_malloc(size_t size)
{
return kmalloc(size, NULL);
}
void fxlibc_hal_free(void *ptr)
{
return kfree(ptr);
}
void *fxlibc_hal_realloc(void *ptr, size_t size)
{
return krealloc(ptr, size);
}
void fxlibc_hal_rawtime(struct tm *tm)
{
rtc_time_t rtc;
rtc_get_time(&rtc);
tm->tm_sec = rtc.seconds;
tm->tm_min = rtc.minutes;
tm->tm_hour = rtc.hours;
tm->tm_mday = rtc.month_day;
tm->tm_mon = rtc.month;
tm->tm_year = rtc.year - 1900;
tm->tm_isdst = 0;
}
clock_t fxlibc_hal_clock(void)
{
return (CLOCKS_PER_SEC * (uint64_t)rtc_ticks()) / 128;
}

View file

@ -629,7 +629,7 @@ static bool gdb_handle_stubcall(gdb_cpu_state_t* cpu_state)
int sc_num = cpu_state->reg.r3; int sc_num = cpu_state->reg.r3;
if(sc_num == 64) { /* write */ if(sc_num == 64) { /* write */
int len = snprintf(str, sizeof str, "Fwrite,%x,%08x,%x", int len = snprintf(str, sizeof str, "Fwrite,%lx,%08lx,%lx",
cpu_state->reg.r4, cpu_state->reg.r4,
cpu_state->reg.r5, cpu_state->reg.r5,
cpu_state->reg.r6); cpu_state->reg.r6);

View file

@ -122,4 +122,12 @@ _stage2:
it's overriding the correct location. */ it's overriding the correct location. */
.long 1, 2, 3, 4, 5, 6, 7, 8 .long 1, 2, 3, 4, 5, 6, 7, 8
/* Also provide default values for metadata fields. */
.section .hh2.info.name
.global __hh2info_name
.weak __hh2info_name
/* Zero byte will skip specifiying any of the data */
__hh2info_name: .byte 0x00
#endif /* GINT_OS_CP */ #endif /* GINT_OS_CP */

View file

@ -247,7 +247,7 @@ static void prepend_link(block_t *b, index_t *index)
//--- //---
/* Round a size to the closest allocatable size */ /* Round a size to the closest allocatable size */
static size_t round(size_t size) static size_t round_size(size_t size)
{ {
return (size < 8) ? 8 : ((size + 3) & ~3); return (size < 8) ? 8 : ((size + 3) & ~3);
} }
@ -256,7 +256,7 @@ static void *gint_malloc(size_t size, void *data)
{ {
index_t *index = data; index_t *index = data;
stats_t *s = index->stats; stats_t *s = index->stats;
size = round(size); size = round_size(size);
int c = size_class(size); int c = size_class(size);
/* Try to find a class that has a free block available */ /* Try to find a class that has a free block available */
@ -330,7 +330,7 @@ static void *gint_realloc(void *ptr, size_t size, void *data)
index_t *index = data; index_t *index = data;
stats_t *s = index->stats; stats_t *s = index->stats;
block_t *b = ptr - sizeof(block_t); block_t *b = ptr - sizeof(block_t);
size = round(size); size = round_size(size);
int size_before = b->size; int size_before = b->size;
/* When requesting a smaller size, split the original block */ /* When requesting a smaller size, split the original block */

View file

@ -539,7 +539,7 @@ static void USB_LOG_TR(char const *p, asyncio_op_t *t, char const *fmt, ...)
if(t->shbuf_size >= 4) if(t->shbuf_size >= 4)
sprintf(shbuf, "!!%d", t->shbuf_size); sprintf(shbuf, "!!%d", t->shbuf_size);
else else
snprintf(shbuf, t->shbuf_size * 2 + 1, "%08x", t->shbuf); snprintf(shbuf, t->shbuf_size * 2 + 1, "%08lx", t->shbuf);
char str[128]; char str[128];
snprintf(str, sizeof str - 1, "%s: %s buf=%d%s%s req=%d/%d%s |%s| ", snprintf(str, sizeof str - 1, "%s: %s buf=%d%s%s req=%d/%d%s |%s| ",