KERNEL_OBJ += vfs/fs/root.o vfs/fs/devfs.o\r
KERNEL_OBJ += drv/vterm.o drv/fifo.o drv/proc.o\r
\r
-OBJ := main.o helpers.o threads.o server.o syscalls.o\r
+N_OBJ := main.o\r
+\r
+OBJ := helpers.o threads.o server.o syscalls.o\r
OBJ += video.o keyboard.o mouse.o nativefs.o vfs_handle.o ui_sdl.o\r
OBJ += $(addprefix $(KERNEL_SRC),$(KERNEL_OBJ))\r
\r
OBJ := $(addsuffix .$(PLATFORM),$(OBJ))\r
-DEPFILES = $(filter %.o.$(PLATFORM),$(OBJ))\r
+N_OBJ := $(addsuffix .$(PLATFORM),$(N_OBJ))\r
+DEPFILES = $(filter %.o.$(PLATFORM),$(OBJ) $(N_OBJ))\r
DEPFILES := $(DEPFILES:%.o.$(PLATFORM)=%.d.$(PLATFORM))\r
\r
CPPFLAGS += -I include/ -I $(KERNEL_SRC)include/\r
all: $(BIN)\r
\r
clean:\r
- $(RM) $(BIN) $(OBJ) $(DEPFILES)\r
+ $(RM) $(BIN) $(OBJ) $(N_OBJ) $(DEPFILES)\r
\r
-$(BIN): $(OBJ)\r
+$(BIN): $(OBJ) $(N_OBJ)\r
@echo [LINK] -o $@\r
- @$(CC) $(LDFLAGS) -o $@ $(OBJ)\r
+ @$(CC) $(LDFLAGS) -o $@ $(N_OBJ) $(OBJ)\r
\r
-%.o.$(PLATFORM): %.c\r
+$(OBJ): %.o.$(PLATFORM): %.c\r
@echo [CC] -o $@\r
@$(CC) -c $< -o $@ $(CFLAGS) $(CPPFLAGS)\r
@$(CC) -M $(CPPFLAGS) -MT $@ -o $*.d.$(PLATFORM) $<\r
\r
+$(N_OBJ): %.o.$(PLATFORM): %.c\r
+ @echo [CC] -o $@\r
+ @$(CC) -c $< -o $@ $(CFLAGS)\r
+ @$(CC) -M -MT $@ -o $*.d.$(PLATFORM) $<\r
+\r
-include $(DEPFILES)\r
*/
#include <stdio.h>
#include <stdlib.h>
+#include <signal.h>
// === IMPORTS ===
extern int UI_Initialise(int Width, int Height);
int main(int argc, char *argv[])
{
// Parse command line settings
-
+
+ // - Ignore SIGUSR1 (used to wake threads)
+ signal(SIGUSR1, SIG_IGN);
+
// Start UI subsystem
UI_Initialise(800, 480);
ntohl(addr.sin_addr.s_addr), ntohs(addr.sin_port));
client = Server_GetClient(req->ClientID);
- if( req->ClientID == 0 )
+ // NOTE: Hack - Should check if all zero
+ if( req->ClientID == 0 || client->ClientAddr.sin_port == 0 )
{
memcpy(&client->ClientAddr, &addr, sizeof(addr));
}
typedef int (*tSyscallHandler)(Uint *Errno, const char *Format, void *Args, int *Sizes);
// === MACROS ===
+#define SYSCALL5(_name, _fmtstr, _t0, _t1, _t2, _t3, _t4, _call) int _name(Uint*Errno,const char*Fmt,void*Args,int*Sizes){\
+ _t0 a0;_t1 a1;_t2 a2;_t3 a3;_t4 a4;\
+ if(strcmp(Fmt,_fmtstr)!=0)return 0;\
+ a0 = *(_t0*)Args;Args+=sizeof(_t0);\
+ a1 = *(_t1*)Args;Args+=sizeof(_t1);\
+ a2 = *(_t2*)Args;Args+=sizeof(_t2);\
+ a3 = *(_t3*)Args;Args+=sizeof(_t3);\
+ a4 = *(_t4*)Args;Args+=sizeof(_t4);\
+ _call\
+}
#define SYSCALL4(_name, _fmtstr, _t0, _t1, _t2, _t3, _call) int _name(Uint*Errno,const char*Fmt,void*Args,int*Sizes){\
_t0 a0;_t1 a1;_t2 a2;_t3 a3;\
if(strcmp(Fmt,_fmtstr)!=0)return 0;\
return -1;
return VFS_ReadDir(a0, a1);
);
+SYSCALL5(Syscall_select, "idddd", int, fd_set *, fd_set *, fd_set *, time_t *,
+ return VFS_Select(a0, a1, a2, a3, a4, 0);
+);
SYSCALL3(Syscall_OpenChild, "isi", int, const char *, int,
return VFS_OpenChild(NULL, a0, a1, a2|VFS_OPENFLAG_USER);
);
return Threads_SetGID(Errno, a0);
);
-SYSCALL0(Syscall_Fork,
- return Threads_Fork();
+SYSCALL1(Syscall_Fork, "d", int *,
+ if(Sizes[0] < sizeof(int))
+ return -1;
+ *a0 = Threads_Fork();
+ return *a0;
);
const tSyscallHandler caSyscalls[] = {
Syscall_SetGID,
Syscall_Sleep,
- Syscall_Fork
+ Syscall_Fork,
+
+ NULL,
+ NULL,
+ Syscall_select
};
const int ciNumSyscalls = sizeof(caSyscalls)/sizeof(caSyscalls[0]);
/**
// Fast return
if( gUI_Keymap[shiftState][Sym] )
return gUI_Keymap[shiftState][Sym];
+
+ // Enter key on acess returns \n, but SDL returns \r
+ if( Sym == SDLK_RETURN )
+ Unicode = '\n';
// How nice of you, a unicode value
if( Unicode )
case SDLK_F10: ret = KEY_F10; break;
case SDLK_F11: ret = KEY_F11; break;
case SDLK_F12: ret = KEY_F12; break;
+ case SDLK_RETURN: ret = '\n'; break;
default:
printf("Unhandled key code %i\n", Sym);
break;
#if 0
case VIDEO_IOCTL_SETCURSOR: // Set cursor position
#if !BLINKING_CURSOR
- if(giVesaCursorX > 0)
- Vesa_FlipCursor(Node);
+ if(giVideo_CursorX > 0)
+ Video_FlipCursor(Node);
#endif
- giVesaCursorX = ((tVideo_IOCtl_Pos*)Data)->x;
- giVesaCursorY = ((tVideo_IOCtl_Pos*)Data)->y;
- //Log_Debug("VESA", "Cursor position (%i,%i)", giVesaCursorX, giVesaCursorY);
- if(
- giVesaCursorX < 0 || giVesaCursorY < 0
- || giVesaCursorX >= gpVesaCurMode->width/giVT_CharWidth
- || giVesaCursorY >= gpVesaCurMode->height/giVT_CharHeight)
+ giVideo_CursorX = ((tVideo_IOCtl_Pos*)Data)->x;
+ giVideo_CursorY = ((tVideo_IOCtl_Pos*)Data)->y;
+ if( giVideo_CursorX < 0 || giVesaCursorY < 0
+ || giVideo_CursorX >= gpVesaCurMode->width/giVT_CharWidth
+ || giVideo_CursorY >= gpVesaCurMode->height/giVT_CharHeight)
{
#if BLINKING_CURSOR
if(giVesaCursorTimer != -1) {
extern void Warning(const char *Format, ...);
extern void Notice(const char *Format, ...);
+extern void Debug(const char *Format, ...);
#define ACESS_SEEK_CUR 0
#define ACESS_SEEK_SET 1
#include <stdarg.h>
#include <string.h>
+// === IMPORTS ===
+extern int giSyscall_ClientID;
+
// === PROTOTYPES ===
void CallUser(void *Entry, int argc, char *argv[], char **envp) __attribute__((noreturn));
int (*appMain)(int, char *[], char **);
void *base;
- int syscall_handle = -1;
+// int syscall_handle = -1;
for( i = 1; i < argc; i ++ )
{
if(strcmp(argv[i], "--key") == 0) {
- syscall_handle = atoi(argv[++i]);
+ giSyscall_ClientID = atoi(argv[++i]);
continue ;
}
appArgc = argc - i;
appArgv = &argv[i];
- printf("Exectutable Path: '%s'\n", appPath);
- printf("Executable argc = %i\n", appArgc);
+// printf("Exectutable Path: '%s'\n", appPath);
+// printf("Executable argc = %i\n", appArgc);
base = Binary_Load(appPath, (uintptr_t*)&appMain);
- printf("base = %p\n", base);
+ printf("[DEBUG %i] base = %p\n", giSyscall_ClientID, base);
if( !base ) return 127;
printf("==============================\n");
- printf("%i %p ", appArgc, appArgv);
+ printf("[DEBUG %i] %i %p ", giSyscall_ClientID, appArgc, appArgv);
for(i = 0; i < appArgc; i ++)
printf("\"%s\" ", appArgv[i]);
printf("\n");
- printf("appMain = %p\n", appMain);
+ printf("[DEBUG %i] appMain = %p\n", giSyscall_ClientID, appMain);
#if 0
__asm__ __volatile__ (
"push %0;\n\t"
void Warning(const char *Format, ...)
{
va_list args;
- printf("Warning: ");
+ printf("[WARN %i] ", giSyscall_ClientID);
va_start(args, Format);
vprintf(Format, args);
va_end(args);
void Notice(const char *Format, ...)
{
va_list args;
- printf("Notice: ");
+ printf("[NOTICE %i] ", giSyscall_ClientID);
+ va_start(args, Format);
+ vprintf(Format, args);
+ va_end(args);
+ printf("\n");
+}
+
+void Debug(const char *Format, ...)
+{
+ va_list args;
+ printf("[DEBUG %i] ", giSyscall_ClientID);
va_start(args, Format);
vprintf(Format, args);
va_end(args);
#if USE_TCP
if( connect(gSocket, (struct sockaddr *)&gSyscall_ServerAddr, sizeof(struct sockaddr_in)) < 0 )
{
- fprintf(stderr, "Cannot connect to server (localhost:%i)\n", SERVER_PORT);
+ fprintf(stderr, "[ERROR -] Cannot connect to server (localhost:%i)\n", SERVER_PORT);
+ fprintf(stderr, "[ERROR -] ", giSyscall_ClientID);
perror("_InitSyscalls");
#if __WIN32__
closesocket(gSocket);
#if !USE_TCP
// Ask server for a client ID
+ if( !giSyscall_ClientID )
{
tRequestHeader req;
int len;
#endif
if( len != Length ) {
+ fprintf(stderr, "[ERROR %i] ", giSyscall_ClientID);
perror("SendData");
exit(-1);
}
ret = select(gSocket+1, &fds, NULL, NULL, timeoutPtr);
if( ret == -1 ) {
+ fprintf(stderr, "[ERROR %i] ", giSyscall_ClientID);
perror("ReadData - select");
exit(-1);
}
if( !ret ) {
- printf("Timeout reading from socket\n");
+ printf("[ERROR %i] Timeout reading from socket\n", giSyscall_ClientID);
return 0; // Timeout
}
#endif
if( ret < 0 ) {
+ fprintf(stderr, "[ERROR %i] ", giSyscall_ClientID);
perror("ReadData");
exit(-1);
}
#include "request.h"
#include "../syscalls.h"
-#define DEBUG(x...) printf(x)
+#define DEBUG(str, x...) Debug(str, x)
#define NATIVE_FILE_MASK 0x40000000
#define MAX_FPS 16
case 'i':
if( direction != 1 ) {
- fprintf(stderr, "ReadEntry: Recieving an integer is not defined\n");
+ Warning("ReadEntry: Recieving an integer is not defined");
return NULL;
}
free( req );
free( retPtrs );
- DEBUG(": %llx\n", retValue);
+ DEBUG(": %llx", retValue);
return retValue;
}
int acess_ioctl(int fd, int id, void *data) {
// NOTE: 1024 byte size is a hack
+ DEBUG("ioctl(%i, %i, %p)", fd, id, data);
return _Syscall(SYS_IOCTL, ">i >i ?d", fd, id, 1024, data);
}
int acess_finfo(int fd, t_sysFInfo *info, int maxacls) {
}
int acess_readdir(int fd, char *dest) {
+ DEBUG("readdir(%i, %p)", fd, dest);
return _Syscall(SYS_READDIR, ">i <d", fd, 256, dest);
}
+int acess_select(int nfds, fd_set *read, fd_set *write, fd_set *error, time_t *timeout)
+{
+ DEBUG("select(%i, %p, %p, %p, %p)", nfds, read, write, error, timeout);
+ return _Syscall(SYS_SELECT, ">i ?d ?d ?d >d", nfds,
+ read ? (nfds+7)/8 : 0, read,
+ write ? (nfds+7)/8 : 0, write,
+ error ? (nfds+7)/8 : 0, error,
+ sizeof(*timeout), timeout
+ );
+}
+
int acess__SysOpenChild(int fd, char *name, int flags) {
return _Syscall(SYS_OPENCHILD, ">i >s >i", fd, name, flags);
}
return 0;
}
- // TODO: Return the acess TID instead
+ // Return the acess TID instead
return kernel_tid;
}
else
{
int i, argc;
- printf("acess_execve: (path='%s', argv=%p, envp=%p)\n", path, argv, envp);
+ DEBUG("acess_execve: (path='%s', argv=%p, envp=%p)", path, argv, envp);
// Get argument count
for( argc = 0; argv[argc]; argc ++ ) ;
- printf(" acess_execve: argc = %i\n", argc);
+ DEBUG(" acess_execve: argc = %i", argc);
char *new_argv[5+argc+1];
char key[11];
return _Syscall(SYS_SETGID, ">i", ID);
}
+int acess_SysSendMessage(int DestTID, int Length, void *Data)
+{
+ return _Syscall(SYS_SENDMSG, ">i >d", DestTID, Length, Data);
+}
+
+int acess_SysGetMessage(int *SourceTID, void *Data)
+{
+ return _Syscall(SYS_GETMSG, "<d <d",
+ SourceTID ? sizeof(int) : 0, SourceTID,
+ Data ? 4096 : 0, Data
+ );
+}
+
// --- Logging
void acess__SysDebug(const char *Format, ...)
{
va_start(args, Format);
- printf("[_SysDebug] ");
+ printf("[_SysDebug %i]", giSyscall_ClientID);
vprintf(Format, args);
printf("\n");
void acess__exit(int Status)
{
+ DEBUG("_exit(%i)", Status);
_Syscall(SYS_EXIT, ">i", Status);
exit(Status);
}
DEFSYM(ioctl),
DEFSYM(finfo),
DEFSYM(readdir),
+ DEFSYM(select),
DEFSYM(_SysOpenChild),
DEFSYM(_SysGetACL),
DEFSYM(_SysMount),
DEFSYM(waittid),
DEFSYM(setuid),
DEFSYM(setgid),
+
+ DEFSYM(SysSendMessage),
+ DEFSYM(SysGetMessage),
DEFSYM(_SysAllocate),
DEFSYM(_SysDebug),
// IPC
SYS_SLEEP,
SYS_FORK,
+ SYS_SENDMSG,
+ SYS_GETMSG,
+ SYS_SELECT,
N_SYSCALLS
};