diff --git a/fx9860g.ld b/fx9860g.ld index accaa19..f86ffa2 100644 --- a/fx9860g.ld +++ b/fx9860g.ld @@ -109,6 +109,7 @@ SECTIONS *(.rodata.4) *(.rodata .rodata.*) + *(.gint.rodata.sh3) } > rom diff --git a/fxcg50.ld b/fxcg50.ld index 0f986af..eba6014 100644 --- a/fxcg50.ld +++ b/fxcg50.ld @@ -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 */ diff --git a/include/gint/defs/attributes.h b/include/gint/defs/attributes.h index 4ca6037..04cab22 100644 --- a/include/gint/defs/attributes.h +++ b/include/gint/defs/attributes.h @@ -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 */ diff --git a/include/gint/mpu/intc.h b/include/gint/mpu/intc.h index 87a0844..7ccb06a 100644 --- a/include/gint/mpu/intc.h +++ b/include/gint/mpu/intc.h @@ -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 } diff --git a/src/fs/fs.c b/src/fs/fs.c index 57ca51b..f5487fc 100644 --- a/src/fs/fs.c +++ b/src/fs/fs.c @@ -2,13 +2,14 @@ #include #include #include +#include /* 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; diff --git a/src/intc/intc.c b/src/intc/intc.c index 677a173..10c471a 100644 --- a/src/intc/intc.c +++ b/src/intc/intc.c @@ -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,