X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Usermode%2FLibraries%2Flibc.so_src%2Fstub.c;h=f723d54427b782c4946f3c8ed1f4fbc1e95ef2d5;hb=edddd69f17803d29b7f435da85ef23b7a5430c1f;hp=acb36539ce957e621a7acda3963d5165878bf8b4;hpb=91dd38c34820c03311738439125675d59bf9e3f1;p=tpg%2Facess2.git diff --git a/Usermode/Libraries/libc.so_src/stub.c b/Usermode/Libraries/libc.so_src/stub.c index acb36539..f723d544 100644 --- a/Usermode/Libraries/libc.so_src/stub.c +++ b/Usermode/Libraries/libc.so_src/stub.c @@ -2,10 +2,39 @@ * AcessOS Basic C Library */ #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[]; +// --- CPU Features --- +#if USE_CPUID +tCPUID gCPU_Features; +#endif +// === CODE === /** * \fn int SoMain() * \brief Stub Entrypoint @@ -14,15 +43,74 @@ extern struct sFILE _iob[]; * \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; + + #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 + { + 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 - // Init FileIO Pointers - _iob[0].FD = 0; _iob[0].Flags = FILE_FLAG_MODE_READ; - _iob[1].FD = 1; _iob[1].Flags = FILE_FLAG_MODE_WRITE; - _iob[2].FD = 2; _iob[2].Flags = FILE_FLAG_MODE_WRITE; + _crt0_exit_handler = _call_atexit_handlers; + + // Set Error handler + _SysSetFaultHandler(ErrorHandler); return 1; } + +int ErrorHandler(int Fault) +{ + int i; + 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 + */ +static void cpuid(uint32_t Num, uint32_t *EAX, uint32_t *EBX, uint32_t *EDX, uint32_t *ECX) +{ + uint32_t eax, ebx, edx, ecx; + + __asm__ __volatile__ ( + "cpuid" + : "=a"(eax), "=c"(ecx), "=d"(edx) + : "a"(Num) + ); + + if(EAX) *EAX = eax; + if(EBX) *EBX = ebx; + if(EDX) *EDX = edx; + if(ECX) *ECX = ecx; +} +#endif