2 * AcessOS Basic C Library
\r
4 #include "stdio_int.h"
\r
8 #include <acess/sys.h>
\r
18 // === PROTOTYPES ===
\r
20 static void cpuid(uint32_t Num, uint32_t *EAX, uint32_t *EBX, uint32_t *EDX, uint32_t *ECX);
\r
22 int ErrorHandler(int Fault);
\r
25 extern tLoadedLib gLoadedLibraries[64];
\r
26 extern void *_crt0_exit_handler;
\r
27 extern void _stdio_init(void);
\r
28 extern void _call_atexit_handlers(void);
\r
31 extern char **environ;
\r
32 // --- CPU Features ---
\r
34 tCPUID gCPU_Features;
\r
40 * \brief Stub Entrypoint
\r
41 * \param BaseAddress Unused - Load Address of libc
\r
42 * \param argc Unused - Argument Count (0 for current version of ld-acess)
\r
43 * \param argv Unused - Arguments (NULL for current version of ld-acess)
\r
44 * \param envp Environment Pointer
\r
46 int SoMain(UNUSED(uintptr_t, BaseAddress), UNUSED(int, argc), UNUSED(char **, argv), char **envp)
\r
55 _SysDebug("envp = %p", envp);
\r
56 for(tmp = envp; *tmp; tmp++,i++)
\r
58 _SysDebug("envp[%i] = '%s'", i, *tmp);
\r
68 cpuid(1, NULL, NULL, &edx, &ecx);
\r
69 gCPU_Features.SSE = edx & (1 << 25); // SSE
\r
70 gCPU_Features.SSE2 = edx & (1 << 26); // SSE2
\r
74 _crt0_exit_handler = _call_atexit_handlers;
\r
76 // Set Error handler
\r
77 _SysSetFaultHandler(ErrorHandler);
\r
82 int ErrorHandler(int Fault)
\r
86 extern void ldacess_DumpLoadedLibraries(void);
\r
87 ldacess_DumpLoadedLibraries();
\r
89 fprintf(stderr, "ErrorHandler: (Fault = %i)\n", Fault);
\r
90 fprintf(stderr, "Loaded Libraries:\n");
\r
91 for( i = 0; i < 64; i ++ )
\r
93 //if(gLoadedLibraries[i].Base == 0) continue;
\r
94 // fprintf(stderr, "%02i: %p %s\n", i, gLoadedLibraries[i].Base, gLoadedLibraries[i].Name);
\r
96 fprintf(stderr, "\n");
\r
103 * \brief Call the CPUID opcode
\r
105 static void cpuid(uint32_t Num, uint32_t *EAX, uint32_t *EBX, uint32_t *EDX, uint32_t *ECX)
\r
107 uint32_t eax, ebx, edx, ecx;
\r
109 __asm__ __volatile__ (
\r
111 : "=a"(eax), "=c"(ecx), "=d"(edx)
\r
115 if(EAX) *EAX = eax;
\r
116 if(EBX) *EBX = ebx;
\r
117 if(EDX) *EDX = edx;
\r
118 if(ECX) *ECX = ecx;
\r