*/\r
#include "stdio_int.h"\r
#include "lib.h"\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <acess/sys.h>\r
\r
#define USE_CPUID 0\r
\r
+// === TYPES ===\r
+typedef struct {\r
+ intptr_t Base;\r
+ char *Name;\r
+} tLoadedLib;\r
+\r
// === PROTOTYPES ===\r
#if USE_CPUID\r
static void cpuid(uint32_t Num, uint32_t *EAX, uint32_t *EBX, uint32_t *EDX, uint32_t *ECX);\r
#endif\r
+ int ErrorHandler(int Fault);\r
+\r
+// === IMPORTS ===\r
+extern tLoadedLib gLoadedLibraries[64];\r
+extern void *_crt0_exit_handler;\r
+extern void _stdio_init(void);\r
+extern void _call_atexit_handlers(void);\r
\r
// === GLOBALS ===\r
extern char **_envp;\r
-extern struct sFILE _iob[];\r
-extern struct sFILE *stdin;\r
-extern struct sFILE *stdout;\r
-extern struct sFILE *stderr;\r
// --- CPU Features ---\r
#if USE_CPUID\r
tCPUID gCPU_Features;\r
* \param argv Unused - Arguments (NULL for current version of ld-acess)\r
* \param envp Environment Pointer\r
*/\r
-int SoMain(unsigned int BaseAddress, int argc, char **argv, char **envp)\r
+int SoMain(UNUSED(uintptr_t, BaseAddress), UNUSED(int, argc), UNUSED(char **, argv), char **envp)\r
{\r
// Init for env.c\r
_envp = envp;\r
- \r
- // Init FileIO Pointers\r
- stdin = &_iob[0];\r
- stdin->FD = 0; stdin->Flags = FILE_FLAG_MODE_READ;\r
- stdout = &_iob[1];\r
- stdout->FD = 1; stdout->Flags = FILE_FLAG_MODE_WRITE;\r
- stderr = &_iob[2];\r
- stderr->FD = 2; stderr->Flags = FILE_FLAG_MODE_WRITE;\r
+\r
+ #if 0 \r
+ {\r
+ int i = 0;\r
+ char **tmp;\r
+ _SysDebug("envp = %p", envp);\r
+ for(tmp = envp; *tmp; tmp++,i++)\r
+ {\r
+ _SysDebug("envp[%i] = '%s'", i, *tmp);\r
+ }\r
+ }\r
+ #endif\r
+\r
+ _stdio_init(); \r
\r
#if USE_CPUID\r
{\r
}\r
#endif\r
\r
+ _crt0_exit_handler = _call_atexit_handlers;\r
+\r
+ // Set Error handler\r
+ _SysSetFaultHandler(ErrorHandler);\r
+ \r
return 1;\r
}\r
\r
+int ErrorHandler(int Fault)\r
+{\r
+ int i;\r
+ fprintf(stderr, "ErrorHandler: (Fault = %i)\n", Fault);\r
+ fprintf(stderr, "Loaded Libraries:\n");\r
+ for( i = 0; i < 64; i ++ )\r
+ {\r
+ //if(gLoadedLibraries[i].Base == 0) continue;\r
+ // fprintf(stderr, "%02i: %p %s\n", i, gLoadedLibraries[i].Base, gLoadedLibraries[i].Name);\r
+ }\r
+ fprintf(stderr, "\n");\r
+ exit(-1);\r
+ return -1;\r
+}\r
+\r
+EXPORT int *libc_geterrno()\r
+{\r
+ return &_errno;\r
+}\r
\r
#if USE_CPUID\r
/**\r