From: John Hodge Date: Sat, 31 May 2014 05:41:32 +0000 (+0800) Subject: Usermode/libc - Makefile update, move stdin/... to .data for R_*_COPY to work X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=473bef48873f161b2b8ec9d1af8de214bbecb1ad;p=tpg%2Facess2.git Usermode/libc - Makefile update, move stdin/... to .data for R_*_COPY to work --- diff --git a/Usermode/Libraries/libc.so_src/Makefile b/Usermode/Libraries/libc.so_src/Makefile index c615b6e9..d5aa2162 100644 --- a/Usermode/Libraries/libc.so_src/Makefile +++ b/Usermode/Libraries/libc.so_src/Makefile @@ -4,9 +4,11 @@ -include ../Makefile.cfg CPPFLAGS += -CFLAGS += -Wall -Werror -Wextra +CFLAGS += -nostdlib -Wall -Werror -Wextra ASFLAGS += -LDFLAGS += -Map map.txt +LDFLAGS += -nostdlib +PRELINK := $(CRTI) $(CRTBEGIN) $(OUTPUTDIR)/Libs/crt0S.o +LIBS += $(LIBGCC_PATH) $(CRTEND) $(CRTN) INCFILES := stdio.h stdlib.h diff --git a/Usermode/Libraries/libc.so_src/signals.c b/Usermode/Libraries/libc.so_src/signals.c index 5e32fc86..532f09b7 100644 --- a/Usermode/Libraries/libc.so_src/signals.c +++ b/Usermode/Libraries/libc.so_src/signals.c @@ -41,6 +41,7 @@ int raise(int signal) void abort(void) { // raise(SIGABRT); + _SysDebug("abort() - %p", __builtin_return_address(0)); _exit(-1); } diff --git a/Usermode/Libraries/libc.so_src/stdio.c b/Usermode/Libraries/libc.so_src/stdio.c index 7969f4c4..a0008d3d 100644 --- a/Usermode/Libraries/libc.so_src/stdio.c +++ b/Usermode/Libraries/libc.so_src/stdio.c @@ -14,6 +14,9 @@ #define DEBUG_BUILD 0 +#define LOG_WARN(f,...) _SysDebug("WARN: %s: "f, __func__ ,## __VA_ARGS__) +#define LOG_NOTICE(f,...) _SysDebug("NOTE: %s: "f, __func__ ,## __VA_ARGS__) + // === CONSTANTS === #define _stdin 0 #define _stdout 1 @@ -27,9 +30,9 @@ struct sFILE *get_file_struct(); // === GLOBALS === struct sFILE _iob[STDIO_MAX_STREAMS]; // IO Buffer -struct sFILE *stdin; // Standard Input -struct sFILE *stdout; // Standard Output -struct sFILE *stderr; // Standard Error +struct sFILE *stdin = &_iob[0]; // Standard Input +struct sFILE *stdout = &_iob[1]; // Standard Output +struct sFILE *stderr = &_iob[2]; // Standard Error ///\note Initialised in SoMain static const int STDIN_BUFSIZ = 512; static const int STDOUT_BUFSIZ = 512; @@ -38,19 +41,16 @@ static const int STDOUT_BUFSIZ = 512; void _stdio_init(void) { // Init FileIO Pointers - stdin = &_iob[0]; stdin->FD = 0; stdin->Flags = FILE_FLAG_ALLOC|FILE_FLAG_MODE_READ|FILE_FLAG_LINEBUFFERED|FILE_FLAG_OURBUFFER; stdin->Buffer = malloc(STDIN_BUFSIZ); stdin->BufferSpace = STDIN_BUFSIZ; - stdout = &_iob[1]; stdout->FD = 1; stdout->Flags = FILE_FLAG_ALLOC|FILE_FLAG_MODE_WRITE|FILE_FLAG_LINEBUFFERED|FILE_FLAG_OURBUFFER; stdout->Buffer = malloc(STDOUT_BUFSIZ); stdout->BufferSpace = STDOUT_BUFSIZ; - stderr = &_iob[2]; stderr->FD = 2; stderr->Flags = FILE_FLAG_ALLOC|FILE_FLAG_MODE_WRITE; } @@ -682,19 +682,24 @@ EXPORT size_t fread(void *ptr, size_t size, size_t num, FILE *fp) { size_t ret; - if(!fp || fp->FD == -1) + if(!fp || fp->FD == -1) { + LOG_WARN("bad fp %p", fp); return -1; + } if( size == 0 || num == 0 ) return 0; if( _GetFileMode(fp) != FILE_FLAG_MODE_READ ) { errno = 0; + LOG_WARN("not open for read"); return -1; } // Don't read if EOF is set - if( fp->Flags & FILE_FLAG_EOF ) + if( fp->Flags & FILE_FLAG_EOF ) { + LOG_NOTICE("EOF"); return 0; + } if( fp->FD == FD_MEMFILE ) { @@ -702,6 +707,7 @@ EXPORT size_t fread(void *ptr, size_t size, size_t num, FILE *fp) } else if( fp->FD == FD_MEMSTREAM ) { //return _fread_memstream(ptr, size, num, fp); + LOG_WARN("Reading from a mem stream"); errno = EBADF; return 0; } @@ -745,6 +751,8 @@ EXPORT size_t fread(void *ptr, size_t size, size_t num, FILE *fp) extra, size, num ); } + LOG_NOTICE("Incomplete read %i/%i bytes (object size %i)", + ret, bytes, size); } return ret / size; diff --git a/Usermode/Libraries/libc.so_src/stub.c b/Usermode/Libraries/libc.so_src/stub.c index a1c67ffb..922943e1 100644 --- a/Usermode/Libraries/libc.so_src/stub.c +++ b/Usermode/Libraries/libc.so_src/stub.c @@ -45,21 +45,8 @@ tCPUID gCPU_Features; */ int SoMain(UNUSED(uintptr_t, BaseAddress), UNUSED(int, argc), UNUSED(char **, argv), char **envp) { - // Init for env.c environ = envp; - #if 0 - { - int i = 0; - char **tmp; - _SysDebug("envp = %p", envp); - for(tmp = envp; *tmp; tmp++,i++) - { - _SysDebug("envp[%i] = '%s'", i, *tmp); - } - } - #endif - _stdio_init(); #if USE_CPUID @@ -76,7 +63,7 @@ int SoMain(UNUSED(uintptr_t, BaseAddress), UNUSED(int, argc), UNUSED(char **, ar // Set Error handler _SysSetFaultHandler(ErrorHandler); - return 1; + return 0; } int ErrorHandler(int Fault)