X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Usermode%2FLibraries%2Flibc.so_src%2Fstub.c;h=922943e1e71a7d4a120e583f85ca0e07c5e58d1c;hb=bdab8e5cebaf249d291d19523d0358f8c1c98008;hp=0233b977d9e9674591f6c9eb38dc3b6a3e00aee2;hpb=5fc81fa5e050f48374a6aff5636f3e60313dfc78;p=tpg%2Facess2.git diff --git a/Usermode/Libraries/libc.so_src/stub.c b/Usermode/Libraries/libc.so_src/stub.c index 0233b977..922943e1 100644 --- a/Usermode/Libraries/libc.so_src/stub.c +++ b/Usermode/Libraries/libc.so_src/stub.c @@ -3,18 +3,36 @@ */ #include "stdio_int.h" #include "lib.h" +#include +#include +#include + +#define USE_CPUID 0 + +// === TYPES === +typedef struct { + intptr_t Base; + char *Name; +} tLoadedLib; // === PROTOTYPES === +#if USE_CPUID static void cpuid(uint32_t Num, uint32_t *EAX, uint32_t *EBX, uint32_t *EDX, uint32_t *ECX); +#endif + int ErrorHandler(int Fault); + +// === IMPORTS === +extern tLoadedLib gLoadedLibraries[64]; +extern void *_crt0_exit_handler; +extern void _stdio_init(void); +extern void _call_atexit_handlers(void); // === GLOBALS === -extern char **_envp; -extern struct sFILE _iob[]; -extern struct sFILE *stdin; -extern struct sFILE *stdout; -extern struct sFILE *stderr; +extern char **environ; // --- CPU Features --- +#if USE_CPUID tCPUID gCPU_Features; +#endif // === CODE === /** @@ -25,32 +43,49 @@ tCPUID gCPU_Features; * \param argv Unused - Arguments (NULL for current version of ld-acess) * \param envp Environment Pointer */ -int SoMain(unsigned int BaseAddress, int argc, char **argv, char **envp) +int SoMain(UNUSED(uintptr_t, BaseAddress), UNUSED(int, argc), UNUSED(char **, argv), char **envp) { - // Init for env.c - _envp = envp; - - // Init FileIO Pointers - stdin = &_iob[0]; - stdin->FD = 0; stdin->Flags = FILE_FLAG_MODE_READ; - stdout = &_iob[1]; - stdout->FD = 1; stdout->Flags = FILE_FLAG_MODE_WRITE; - stderr = &_iob[2]; - stderr->FD = 2; stderr->Flags = FILE_FLAG_MODE_WRITE; + environ = envp; + + _stdio_init(); - /* + #if USE_CPUID { uint32_t ecx, edx; cpuid(1, NULL, NULL, &edx, &ecx); gCPU_Features.SSE = edx & (1 << 25); // SSE gCPU_Features.SSE2 = edx & (1 << 26); // SSE2 } - */ + #endif + + _crt0_exit_handler = _call_atexit_handlers; + + // Set Error handler + _SysSetFaultHandler(ErrorHandler); - return 1; + return 0; } +int ErrorHandler(int Fault) +{ + int i; + + extern void ldacess_DumpLoadedLibraries(void); + ldacess_DumpLoadedLibraries(); + + fprintf(stderr, "ErrorHandler: (Fault = %i)\n", Fault); + fprintf(stderr, "Loaded Libraries:\n"); + for( i = 0; i < 64; i ++ ) + { + //if(gLoadedLibraries[i].Base == 0) continue; + // fprintf(stderr, "%02i: %p %s\n", i, gLoadedLibraries[i].Base, gLoadedLibraries[i].Name); + } + fprintf(stderr, "\n"); + exit(-1); + return -1; +} +#if USE_CPUID /** * \brief Call the CPUID opcode */ @@ -69,3 +104,4 @@ static void cpuid(uint32_t Num, uint32_t *EAX, uint32_t *EBX, uint32_t *EDX, uin if(EDX) *EDX = edx; if(ECX) *ECX = ecx; } +#endif