X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=AcessNative%2Facesskernel_src%2Fmain.c;h=eb0883d7b729a73cdd76273263cfe379107b613e;hb=03900b58142ae00b0bf708accbbe97e1ba83188b;hp=1dcf61a772d0ed0abc0676bfb31c81fe317f77f0;hpb=c0758a3d1053010f2c6f122365acde3efda2ba77;p=tpg%2Facess2.git diff --git a/AcessNative/acesskernel_src/main.c b/AcessNative/acesskernel_src/main.c index 1dcf61a7..eb0883d7 100644 --- a/AcessNative/acesskernel_src/main.c +++ b/AcessNative/acesskernel_src/main.c @@ -4,85 +4,161 @@ * * Kernel Main */ -#include #include #include -#include +#include +#include +#ifdef __LINUX__ +#include +#endif +#include +#include +#include "../../KernelLand/Kernel/include/logdebug.h" -int main(int argc, char *argv[]) -{ - return 0; -} +#define VALGRIND_CLIENT 0 -void LogF(const char *Fmt, ...) -{ - va_list args; - va_start(args, Fmt); - vprintf(Fmt, args); - va_end(args); -} +// === IMPORTS === +extern int UI_Initialise(int Width, int Height); +extern void UI_MainLoop(void); +extern int VFS_Init(void); +extern int Video_Install(char **Arguments); +extern int NativeKeyboard_Install(char **Arguments); +extern int NativeFS_Install(char **Arguments); +extern void Debug_SetKTerminal(char *Path); +extern int VT_Install(char **Arguments); +extern int Mouse_Install(char **Arguments); +extern int VFS_Mount(const char *Device, const char *MountPoint, const char *Filesystem, const char *Options); +extern int VFS_MkDir(const char *Path); +extern int SyscallServer(void); +extern int Server_Shutdown(void); +extern const char gsKernelVersion[]; +extern const char gsGitHash[]; +extern int giBuildNumber; -void Log(const char *Fmt, ...) -{ - va_list args; - printf("Log: "); - va_start(args, Fmt); - vprintf(Fmt, args); - va_end(args); - printf("\n"); -} +// === GLOBALS === +const char *gsAcessDir = "../Usermode/Output/x86_64"; -void Warning(const char *Fmt, ...) +// === CODE === +#ifndef __WIN32__ +#define P_NOWAIT 0 +int spawnv(int flags, const char *execuable, char * const argv[]) { - va_list args; - printf("Warning: "); - va_start(args, Fmt); - vprintf(Fmt, args); - va_end(args); - printf("\n"); -} + int pid = fork(); + if( pid != 0 ) return pid; -void Panic(const char *Format, ...) -{ - va_list args; - printf("Panic: "); - va_start(args, Format); - vprintf(Format, args); - va_end(args); - printf("\n"); - exit(-1); + execv(execuable, argv); + perror("spawnv - execve"); + for(;;); } +#endif -void Debug_SetKTerminal(const char *Path) +int main(int argc, char *argv[]) { - // Ignored, kernel debug goes to stdout -} + char **rootapp = NULL; + int rootapp_argc, i; + // Parse command line settings + for( i = 1; i < argc; i ++ ) + { + if( strcmp(argv[i], "--distroot") == 0 ) { + gsAcessDir = argv[++i]; + } + else if( strcmp(argv[i], "--rootapp") == 0 ) { + rootapp = &argv[++i]; + rootapp_argc = argc - i; + break; + } + else { + fprintf(stderr, "Unknown command line option '%s'\n", argv[i]); + return -1; + } + } -void *Heap_Allocate(int Count, const char *File, int Line) -{ - return malloc(Count); -} + // Kernel build information + printf("Acess2 Native v%s\n", gsKernelVersion); + printf(" Build %i, Git Hash %s\n", giBuildNumber, gsGitHash); -tPAddr MM_GetPhysAddr(tVAddr VAddr) -{ - return VAddr; // HACK! + // Start UI subsystem + UI_Initialise(800, 480); + + // - Ignore SIGUSR1 (used to wake threads) + #ifdef SIGUSR1 + signal(SIGUSR1, SIG_IGN); + #endif + + // Initialise VFS + VFS_Init(); + // - Start IO Drivers + if( Video_Install(NULL) ) { + Log_Error("Init", "Unable to load NativeVideo"); + } + if( NativeKeyboard_Install(NULL) ) { + Log_Error("Init", "Unable to load NativeKeyboard"); + } + NativeFS_Install(NULL); + Mouse_Install(NULL); + // - Start VTerm + { + char *args[] = { + "Video=NativeVideo", + "Input=NativeKeyboard", + NULL + }; + VT_Install(args); + } + + VFS_MkDir("/Acess"); + VFS_Mount(gsAcessDir, "/Acess", "nativefs", ""); + + Debug_SetKTerminal("/Devices/VTerm/8"); + + // Start syscall server + SyscallServer(); + + // Spawn root application + if( rootapp ) + { + int pid; + int argcount = 0; + const char *args[7+rootapp_argc+1+1]; + + #if VALGRIND_CLIENT + args[argcount++] = "valgrind"; + #endif + args[argcount++] = "./ld-acess"; + args[argcount++] = "--open"; args[argcount++] = "/Devices/VTerm/0"; + args[argcount++] = "--open"; args[argcount++] = "/Devices/VTerm/0"; + args[argcount++] = "--open"; args[argcount++] = "/Devices/VTerm/0"; + for( i = 0; i < rootapp_argc; i ++ ) + args[argcount+i] = rootapp[i]; + args[argcount+rootapp_argc] = NULL; + pid = spawnv(P_NOWAIT, "./ld-acess", args); + if(pid < 0) { + perror("Starting root application [fork(2)]"); + return 1; + } + printf("Root application running as PID %i\n", pid); + } + + UI_MainLoop(); + + return 0; } -Uint MM_GetFlags(tVAddr VAddr) +void AcessNative_Exit(void) { - return 0; + // TODO: Close client applications too + Server_Shutdown(); + exit(0); } -int Modules_InitialiseBuiltin(const char *Name) +uint64_t DivMod64U(uint64_t Num, uint64_t Den, uint64_t *Rem) { - return 0; // Ignored + if(Rem) *Rem = Num % Den; + return Num / Den; } -Sint64 now(void) +int Module_EnsureLoaded(const char *Name) { - struct timeval tv; - struct timezone tz; - gettimeofday(&tv, &tz); - return tv.tv_sec * 1000 + tv.tv_usec/1000; + return 0; }