reduce static user RAM footprint for mono targets

* Make INTC data const (it should've always been)
* Introduce GRODATA3/.gint.rodata.sh3 for that purpose
* Dynamically allocate file descriptor table
This commit is contained in:
Lephe 2023-01-01 19:22:41 +01:00
parent 478fdaea76
commit 736b58f205
Signed by untrusted user: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
6 changed files with 21 additions and 10 deletions

View File

@ -109,6 +109,7 @@ SECTIONS
*(.rodata.4)
*(.rodata .rodata.*)
*(.gint.rodata.sh3)
} > rom

View File

@ -175,7 +175,7 @@ SECTIONS
/DISCARD/ : {
/* SH3-only data sections */
*(.gint.data.sh3 .gint.bss.sh3)
*(.gint.rodata.sh3 .gint.data.sh3 .gint.bss.sh3)
/* Java class registration (why are they even here?!) */
*(.jcr)
/* Asynchronous unwind tables: no C++ exception handling */

View File

@ -10,6 +10,7 @@
/* Objects from the gint's uninitialized BSS section */
#define GBSS __attribute__((section(".gint.bss")))
/* Additional sections that are only needed on SH3 */
#define GRODATA3 __attribute__((section(".gint.rodata.sh3")))
#define GDATA3 __attribute__((section(".gint.data.sh3")))
#define GBSS3 __attribute__((section(".gint.bss.sh3")))
/* Objects for the ILRAM, XRAM and YRAM regions */

View File

@ -298,8 +298,8 @@ typedef struct
//---
/* Provided by intc/intc.c */
extern sh7705_intc_t SH7705_INTC;
extern sh7305_intc_t SH7305_INTC;
extern sh7705_intc_t const SH7705_INTC;
extern sh7305_intc_t const SH7305_INTC;
#ifdef __cplusplus
}

View File

@ -2,13 +2,14 @@
#include <gint/defs/attributes.h>
#include <unistd.h>
#include <errno.h>
#include <stdlib.h>
/* File descriptor table */
static fs_descriptor_t fdtable[FS_FD_MAX] = { 0 };
static fs_descriptor_t *fdtable;
fs_descriptor_t const *fs_get_descriptor(int fd)
{
if((unsigned)fd >= FS_FD_MAX)
if(!fdtable || (unsigned)fd >= FS_FD_MAX)
return NULL;
if(fdtable[fd].type == NULL)
return NULL;
@ -18,7 +19,7 @@ fs_descriptor_t const *fs_get_descriptor(int fd)
int fs_create_descriptor(fs_descriptor_t const *data)
{
if(data->type == NULL)
if(!fdtable || data->type == NULL)
return -1;
/* Leave 0/1/2 for stdin, stdout and stderr */
@ -34,7 +35,7 @@ int fs_create_descriptor(fs_descriptor_t const *data)
void fs_free_descriptor(int fd)
{
if((unsigned)fd >= FS_FD_MAX)
if(!fdtable || (unsigned)fd >= FS_FD_MAX)
return;
fdtable[fd].type = NULL;
@ -43,6 +44,10 @@ void fs_free_descriptor(int fd)
int open_generic(fs_descriptor_type_t *type, void *data, int fd)
{
if(!fdtable) {
errno = ENOMEM;
return -1;
}
if(!type) {
errno = EINVAL;
return -1;
@ -81,8 +86,12 @@ static fs_descriptor_type_t devnull = {
.close = NULL,
};
GCONSTRUCTOR static void init_standard_streams(void)
GCONSTRUCTOR static void init_fs(void)
{
fdtable = malloc(FS_FD_MAX * sizeof *fdtable);
if(!fdtable)
return;
fdtable[STDIN_FILENO].type = &devnull;
fdtable[STDIN_FILENO].data = NULL;

View File

@ -12,7 +12,7 @@
// Interrupt controllers
//---
GDATA3 sh7705_intc_t SH7705_INTC = {
GRODATA3 sh7705_intc_t const SH7705_INTC = {
.IPR = {
(void *)0xfffffee2, (void *)0xfffffee4,
(void *)0xa4000016, (void *)0xa4000018, (void *)0xa400001a,
@ -21,7 +21,7 @@ GDATA3 sh7705_intc_t SH7705_INTC = {
.ICR1 = (void *)0xa4000010,
};
sh7305_intc_t SH7305_INTC = {
sh7305_intc_t const SH7305_INTC = {
.IPR = (void *)0xa4080000,
.MSK = (void *)0xa4080080,
.MSKCLR = (void *)0xa40800c0,