\r
KERNEL_SRC = ../../KernelLand/Kernel/\r
\r
-KERNEL_OBJ := logging.o adt.o lib.o libc.o debug.o messages.o drvutil_disk.o drvutil_video.o\r
+KERNEL_OBJ := logging.o adt.o lib.o debug.o messages.o drvutil_disk.o drvutil_video.o\r
+#KERNEL_OBJ += libc.o\r
KERNEL_OBJ += vfs/main.o vfs/open.o vfs/acls.o vfs/io.o vfs/dir.o\r
KERNEL_OBJ += vfs/nodecache.o vfs/mount.o vfs/memfile.o vfs/select.o\r
KERNEL_OBJ += vfs/fs/root.o vfs/fs/devfs.o\r
\r
KCPPFLAGS = -I include/ -I $(KERNEL_SRC)include/\r
CFLAGS += -Wall -g -std=gnu99\r
-LDFLAGS += -lSDL -lSDLmain -g -Wl,--defsym,__buildnum=$(BUILD_NUM)\r
+CPPFLAGS += $(shell sdl-config --cflags) -I /usr/include/\r
+LDFLAGS += $(shell sdl-config --libs) -g -Wl,--defsym,__buildnum=$(BUILD_NUM)\r
\r
ifeq ($(PLATFORM),win)\r
BIN := ../AcessKernel.exe\r
$(K_OBJ): $(KERNEL_SRC)obj-native-$(PLATFORM)/%.o: $(KERNEL_SRC)%.c\r
@mkdir -p $(dir $@)\r
@echo [CC] -o $@\r
- $(CC) -ffreestanding -c $< -o $@ $(CFLAGS) $(KCPPFLAGS) $(CPPFLAGS)\r
+ @$(CC) -ffreestanding -c $< -o $@ $(CFLAGS) $(KCPPFLAGS) $(CPPFLAGS)\r
\r
\r
\r
$(BUILDINFO_SRC): $(filter-out $(BUILDINFO_OBJ), $(OBJ)) Makefile\r
@echo "" > $@\r
- $(eval _GITHASH=$(shell (git log -n 1 | head -n 1 | awk '{print $$2}') || echo UNK))\r
- $(eval _GITCHANGED=$(shell (git status --porcelain | grep -c '^ M ') || echo UNK))\r
+ $(eval _GITHASH=$(shell (git log -n 1 | head -n 1 | awk '{print $$2}') 2>/dev/null || echo UNK))\r
+ $(eval _GITCHANGED=$(shell (git status --porcelain | grep -c '^ M ') 2>/dev/null || echo UNK))\r
+ $(eval _HOSTNAME=$(shell hostname --fqdn 2>/dev/null || hostname || echo UNK))\r
@echo "const char gsKernelVersion[] = \"$(ACESS_VERSION)\";" >> $@\r
@echo "const char gsGitHash[] = \"$(_GITHASH)\";" >> $@\r
- @echo "const char gsBuildInfo[] = \"Acess2 v$(KERNEL_VERSION) $(ARCH)-$(PLATFORM)\\\\r\\\\n\"" >> $@\r
- @echo " \"Build $(shell hostname --fqdn):$(BUILD_NUM) Git $(_GITHASH) - $(_GITCHANGED) modified\";" >> $@\r
+ @echo "const char gsBuildInfo[] = \"AcessNative $(ACESS_VERSION) $(ARCH)-$(PLATFORM)\\\\r\\\\n\"" >> $@\r
+ @echo " \"Build $(_HOSTNAME):$(BUILD_NUM) Git $(_GITHASH) - $(_GITCHANGED) modified\";" >> $@\r
@echo "const int giBuildNumber = $(BUILD_NUM);" >> $@\r
$(BUILDINFO_OBJ): $(BUILDINFO_SRC)\r
@echo [CC] -o $@\r
#include <stdlib.h>
#include <stdarg.h>
#include <sys/time.h>
+#include <string.h>
#if 0
void LogF(const char *Fmt, ...)
void Debug_PutCharDebug(char ch)
{
printf("%c", ch);
+ if( ch == '\n' )
+ fflush(stdout);
}
void Debug_PutStringDebug(const char *String)
{
printf("%s", String);
+ if( strchr(String, '\n') )
+ fflush(stdout);
}
void *Heap_Allocate(const char *File, int Line, int ByteCount)
free(Ptr);
}
+char *Heap_StringDup(const char *File, int Line, const char *Str)
+{
+ return strdup(Str);
+}
+
void Heap_Dump(void)
{
}
// nop
}
+int strpos(const char *str, char ch)
+{
+ const char *retptr = strchr(str, ch);
+ int rv = retptr ? retptr - str : -1;
+ fprintf(stderr, "strpos: str = %p'%s', retptr = %p, rv = %i\n", str, str, retptr, rv);
+ return rv;
+}
+
+int CheckString(const char *string)
+{
+ if( (intptr_t)string < 0x1000 )
+ return 0;
+ strlen(string);
+ return 1;
+}
+
+int CheckMem(const void *buf, size_t len)
+{
+ if( (intptr_t)buf < 0x1000 )
+ return 0;
+ return 1;
+}
+
typedef int BOOL;
#include <stddef.h>
-#undef NULL
#undef offsetof
struct sShortSpinlock
extern void Heap_Deallocate(void *Ptr);
extern int Heap_IsHeapAddr(void *Ptr);
extern void Heap_Validate(void);
+extern char *Heap_StringDup(const char *File, int Line, const char *Str);
#define malloc(size) Heap_Allocate(_MODULE_NAME_"/"__FILE__, __LINE__, (size))
#define calloc(num,size) Heap_AllocateZero(_MODULE_NAME_"/"__FILE__, __LINE__, (num)*(size))
#define free(ptr) Heap_Deallocate((ptr))
#define IsHeap(ptr) Heap_IsHeapAddr((ptr))
-#define strdup(Str) _strdup(_MODULE_NAME_"/"__FILE__, __LINE__, (Str))
+#define strdup(Str) Heap_StringDup(_MODULE_NAME_"/"__FILE__, __LINE__, (Str))
#endif
tProcess *Process;
- Uint32 Events, WaitMask;
+ Uint32 EventState, WaitMask;
void *EventSem; // Should be SDL_sem, but I don't want SDL in this header
// Message queue
* nativefs.c\r
* - Host filesystem access\r
*/\r
-#define DEBUG 0\r
+#define DEBUG 1\r
#define off_t _acess_off_t\r
+#define sprintf _acess_sprintf\r
#include <acess.h> // Acess\r
#include <vfs.h> // Acess\r
#undef off_t\r
+#undef sprintf\r
#include <dirent.h> // Posix\r
#include <sys/stat.h> // Posix\r
#include <stdio.h> // Posix\r
*
* Syscall Distribution
*/
-#define DEBUG 0
+#define DEBUG 1
#include <acess.h>
#include <threads.h>
#include <events.h>
}
// === CODE ===
-int Syscall_Null(Uint*Errno, const char *Format, void *Args, int *Sizes)
+int Syscall_Null(Uint *Errno, const char *Format, void *Args, int *Sizes)
{
return 0;
}
);
SYSCALL2(Syscall_Open, "si", const char *, int,
- return VFS_Open(a0, a1|VFS_OPENFLAG_USER);
+ int rv = VFS_Open(a0, a1|VFS_OPENFLAG_USER);
+ if(rv == -1) *Errno = errno;
+ return rv;
);
SYSCALL1(Syscall_Close, "i", int,
VFS_Close(a0);
Log_Warning("Syscalls", "Read - %i < %i", Sizes[2], a1);
return -1;
}
- return VFS_Read(a0, a1, a2);
+ size_t rv = VFS_Read(a0, a1, a2);
+ if(rv == -1) *Errno = errno;
+ return rv;
);
SYSCALL3(Syscall_Write, "iid", int, int, const void *,
- if( Sizes[2] < a1 )
+ if( Sizes[2] < a1 ) {
+ *Errno = EINVAL;
return -1;
- return VFS_Write(a0, a1, a2);
+ }
+ size_t rv = VFS_Write(a0, a1, a2);
+ if(rv == -1) *Errno = errno;
+ return rv;
);
SYSCALL3(Syscall_Seek, "iIi", int, int64_t, int,
return VFS_Seek(a0, a1, a2);
);
SYSCALL3(Syscall_FInfo, "idi", int, void *, int,
if( Sizes[1] < sizeof(tFInfo)+a2*sizeof(tVFS_ACL)) {
- LOG("offsetof(size) = %i", offsetof(tFInfo, size));
+ //LOG("offsetof(size) = %i", offsetof(tFInfo, size));
LOG("Bad size %i < %i", Sizes[1], sizeof(tFInfo)+a2*sizeof(tVFS_ACL));
*Errno = -EINVAL;
return -1;
}
}
+ // --- Perform request
retVal = caSyscalls[Request->CallID](&ret_errno, formatString, argListData, argSizes);
}
+ // ---------- Return
+
+ if( ret_errno == 0 ) {
+ perror("Syscall?");
+ ret_errno = errno;
+ }
+
// Allocate the return
size_t msglen = sizeof(tRequestHeader) + retValueCount * sizeof(tRequestValue) + retDataLen;
ret = malloc(msglen);
//Log_Debug("Threads", "Mask = %x, ->Events = %x", Mask, gpCurrentThread->Events);
gpCurrentThread->WaitMask = Mask;
- if( !(gpCurrentThread->Events & Mask) )
+ if( !(gpCurrentThread->EventState & Mask) )
{
if( Threads_Glue_SemWait(gpCurrentThread->EventSem, INT_MAX) == -1 ) {
Log_Warning("Threads", "Wait on eventsem of %p, %p failed",
}
//Log_Debug("Threads", "Woken from nap (%i here)", SDL_SemValue(gpCurrentThread->EventSem));
}
- rv = gpCurrentThread->Events & Mask;
- gpCurrentThread->Events &= ~Mask;
+ rv = gpCurrentThread->EventState & Mask;
+ gpCurrentThread->EventState &= ~Mask;
gpCurrentThread->WaitMask = -1;
//Log_Debug("Threads", "- rv = %x", rv);
void Threads_PostEvent(tThread *Thread, Uint32 Events)
{
- Thread->Events |= Events;
+ Thread->EventState |= Events;
// Log_Debug("Threads", "Trigger event %x (->Events = %p) on %p", Events, Thread->Events, Thread);
if( Events == 0 || Thread->WaitMask & Events ) {
void Threads_ClearEvent(Uint32 EventMask)
{
- gpCurrentThread->Events &= ~EventMask;
+ gpCurrentThread->EventState &= ~EventMask;
}
// === PROTOTYPES ===
int Video_Install(char **Arguments);
-Uint64 Video_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer);
-Uint64 Video_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, const void *Buffer);
+size_t Video_Read(tVFS_Node *Node, Uint64 Offset, size_t Length, void *Buffer);
+size_t Video_Write(tVFS_Node *Node, Uint64 Offset, size_t Length, const void *Buffer);
int Video_IOCtl(tVFS_Node *Node, int ID, void *Data);
// --- 2D Acceleration Functions --
void Video_2D_Fill(void *Ent, Uint16 X, Uint16 Y, Uint16 W, Uint16 H, Uint32 Colour);
/**
* \brief Read from framebuffer (unimplemented)
*/
-Uint64 Video_Read(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer)
+size_t Video_Read(tVFS_Node *Node, Uint64 Offset, size_t Length, void *Buffer)
{
return 0;
}
/**
* \brief Write to the framebuffer
*/
-Uint64 Video_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, const void *Buffer)
+size_t Video_Write(tVFS_Node *Node, Uint64 Offset, size_t Length, const void *Buffer)
{
int i;
ENTER("pNode XOffset XLength pBuffer", Node, Offset, Length, Buffer);
ifeq ($(PLATFORM),win)
BIN := ../ld-acess.exe
- LDFLAGS += -lws2_32
+ LINKADDR := 0x70000000
+ LDFLAGS += -lws2_32 -Wl,--image-base,$(LINKADDR)
endif
ifeq ($(PLATFORM),lin)
BIN := ../ld-acess
Binary_SetReadyToUse(Base);
}
-static inline int SysSetMemFlags(uintptr_t Addr, unsigned int flags, unsigned int mask)
+static inline int _SysSetMemFlags(uintptr_t Addr, unsigned int flags, unsigned int mask)
{
return 0;
}
#include <stdarg.h>
#include <stddef.h>
-#define DEBUG(v...) do{}while(0)//Debug(v)
+#define DEBUG(v...) Debug(v)
+//#define DEBUG(v...) do{}while(0)//Debug(v)
#define PAGE_SIZE 4096
typedef struct sFILE FILE;
return _Syscall(SYS_READDIR, ">i <d", fd, 256, dest);
}
-int acess__SysSelect(int nfds, fd_set *read, fd_set *write, fd_set *error, time_t *timeout, uint32_t events)
+int acess__SysSelect(int nfds, fd_set *read, fd_set *write, fd_set *error, int64_t *timeout, uint32_t events)
{
DEBUG("_SysSelect(%i, %p, %p, %p, %p, 0x%x)", nfds, read, write, error, timeout, events);
return _Syscall(SYS_SELECT, ">i ?d ?d ?d >d >i", nfds,
);
}
-int acess_select(int nfds, fd_set *read, fd_set *write, fd_set *error, time_t *timeout)
+int acess_select(int nfds, fd_set *read, fd_set *write, fd_set *error, int64_t *timeout)
{
return acess__SysSelect(nfds, read, write, error, timeout, 0);
}
}
// --- Memory Management ---
-uint64_t acess__SysAllocate(uint vaddr)
+uint64_t acess__SysAllocate(uintptr_t vaddr)
{
if( AllocateMemory(vaddr, 0x1000) == -1 ) // Allocate a page
return 0;
exit(Status);
}
+uint32_t acess__SysSetMemFlags(uintptr_t vaddr, uint32_t flags, uint32_t mask)
+{
+ // TODO: Impliment acess__SysSetMemFlags?
+ return 0;
+}
+
// === Symbol List ===
#define DEFSYM(name) {#name, &acess_##name}
DEFSYM(SysGetMessage),
DEFSYM(_SysAllocate),
+ DEFSYM(_SysSetMemFlags),
DEFSYM(_SysDebug),
DEFSYM(_SysSetFaultHandler),
DEFSYM(_SysWaitEvent),
base = Binary_Load(appPath, (uintptr_t*)&appMain);
printf("[DEBUG %i] base = %p\n", giSyscall_ClientID, base);
- if( !base ) return 127;
+ if( !base ) {
+ *((char*)NULL) = 0;
+ return 127;
+ }
printf("==============================\n");
printf("[DEBUG %i] %i ", giSyscall_ClientID, appArgc);
size_t size = (VirtAddr & 0xFFF) + ByteCount;
void *tmp;
#if __WIN32__
- tmp = VirtualAlloc((void*)base, size, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
+ do
+ {
+ MEMORY_BASIC_INFORMATION info;
+ VirtualQuery( (void*)base, &info, sizeof(info) );
+ if( info.State != MEM_FREE ) {
+ printf("ERROR: Unable to allocate memory %p+0x%x, already allocated\n",
+ (void*)base, size);
+ base += 0x1000;
+ if( size < 0x1000 )
+ return 0;
+ size -= 0x1000;
+ }
+ else
+ break;
+ } while( size >= 0x1000 );
+ tmp = VirtualAlloc((void*)base, size, MEM_RESERVE|MEM_COMMIT, PAGE_EXECUTE_READWRITE);
if( tmp == NULL ) {
- printf("ERROR: Unable to allocate memory (0x%x)\n", (int)GetLastError());
+ printf("ERROR: Unable to allocate memory %p+%x (0x%x)\n",
+ (void*)base, size,
+ (int)GetLastError());
return -1;
}
#else
/*
*/
-#define DEBUG 0
+#define DEBUG 1
#if DEBUG
memset((void *)&gSyscall_ServerAddr, '\0', sizeof(struct sockaddr_in));
gSyscall_ServerAddr.sin_family = AF_INET;
gSyscall_ServerAddr.sin_port = htons(SERVER_PORT);
+ gSyscall_ServerAddr.sin_addr.s_addr = htonl(0x7F000001);
}
int _InitSyscalls(void)
exit(0);
}
- #if 0
- // Set client address
- memset((void *)&client, '\0', sizeof(struct sockaddr_in));
- client.sin_family = AF_INET;
- client.sin_port = htons(0);
- client.sin_addr.s_addr = htonl(0x7F000001);
- #endif
-
#if USE_TCP
if( connect(gSocket, (struct sockaddr *)&gSyscall_ServerAddr, sizeof(struct sockaddr_in)) < 0 )
{
fprintf(stderr, "[ERROR -] Cannot connect to server (localhost:%i)\n", SERVER_PORT);
perror("_InitSyscalls");
#if __WIN32__
+ fprintf(stderr, "[ERROR -] - WSAGetLastError said %i", WSAGetLastError());
closesocket(gSocket);
WSACleanup();
#else
#endif
#if 0
+ // Set client address
+ memset((void *)&client, '\0', sizeof(struct sockaddr_in));
+ client.sin_family = AF_INET;
+ client.sin_port = htons(0);
+ client.sin_addr.s_addr = htonl(0x7F000001);
// Bind
if( bind(gSocket, (struct sockaddr *)&client, sizeof(struct sockaddr_in)) == -1 )
{
}
if( ret == 0 ) {
fprintf(stderr, "[ERROR %i] Connection closed.\n", giSyscall_ClientID);
+ #if __WIN32__
+ closesocket(gSocket);
+ #else
close(gSocket);
+ #endif
exit(0);
}
#include <string.h>
#include <stddef.h>
#include <unistd.h>
-#include <spawn.h> // posix_spawn
+#ifndef __WIN32__
+# include <spawn.h> // posix_spawn
+#endif
#include "request.h"
#if SYSCALL_TRACE
{
int rv;
+ #if __WIN32__
+ rv = _spawnve(_P_NOWAIT, filename, argv, envp);
+ #else
rv = posix_spawn(NULL, filename, NULL, NULL, (void*)argv, (void*)envp);
+ #endif
return rv;
}
-../x86/pci.c
\ No newline at end of file
+#include "../x86/pci.c"
\ No newline at end of file
if( !child )
{
child = calloc( 1, sizeof(tSysFS_Ent)+tmp+1 );
+ if( !child ) {
+ Log_Error("SysFS", "calloc(%i) failure", sizeof(tSysFS_Ent)+tmp+1);
+ return -1;
+ }
child->Next = NULL;
memcpy(child->Name, &Path[start], tmp);
child->Name[tmp] = '\0';
ent->Node.Size ++;
else
gSysFS_DriverInfo.RootNode.Size ++;
- Log_Log("SysFS", "Added directory '%s'", child->Name);
+ Log_Log("SysFS", "Added directory '%.*s'", tmp, &Path[start]);
+ Log_Log("SysFS", "Added directory '%.*s'", tmp, child->Name);
}
ent = child;
if( strcmp(opt, "Video") == 0 ) {
if( !gsVT_OutputDevice )
- gsVT_OutputDevice = strdup(val);
+ gsVT_OutputDevice = val;
}
else if( strcmp(opt, "Input") == 0 ) {
if( !gsVT_InputDevice )
- gsVT_InputDevice = strdup(val);
+ gsVT_InputDevice = val;
}
else if( strcmp(opt, "Width") == 0 ) {
giVT_RealWidth = atoi( val );
tVFS_ACL acls[]; //!< ACL buffer (size is passed in the \a MaxACLs argument to VFS_FInfo)
} PACKED tFInfo;
+// --- fd_set --
+#include "../../../Usermode/Libraries/ld-acess.so_src/include_exp/acess/fd_set.h"
+
+#if 0
/**
* \brief fd_set for select()
*/
* \param fdsetp Set to modify
*/
#define FD_ISSET(fd, fdsetp) ((fdsetp)->flags[(fd)/16]&(1<<((fd)%16)))
+#endif
// === FUNCTIONS ===
/**
if( Level >= NUM_LOG_LEVELS ) return;
va_copy(args_tmp, Args);
- len = vsnprintf(NULL, 256, Format, args_tmp);
+ len = vsnprintf(NULL, 0, Format, args_tmp);
#if USE_RING_BUFFER || !CACHE_MESSAGES
{
} fd_set;
-extern void FD_ZERO(fd_set *fdsetp);
-extern void FD_CLR(int fd, fd_set *fdsetp);
-extern void FD_SET(int fd, fd_set *fdsetp);
-extern int FD_ISSET(int fd, fd_set *fdsetp);
+static inline void FD_ZERO(fd_set *fdsetp)
+{
+ int i = FD_SETSIZE/16;
+ while( i-- )
+ fdsetp->flags[i] = 0;
+}
+static inline void FD_CLR(int fd, fd_set *fdsetp)
+{
+ if(fd < 0 || fd > FD_SETSIZE) return;
+ fdsetp->flags[fd/16] &= (fd_set_ent_t) ((~1 << (fd%16))) & 0xFFFF;
+}
+static inline void FD_SET(int fd, fd_set *fdsetp)
+{
+ if(fd < 0 || fd > FD_SETSIZE) return;
+ fdsetp->flags[fd/16] |= (fd_set_ent_t) (1 << (fd%16));
+}
+static inline int FD_ISSET(int fd, fd_set *fdsetp)
+{
+ if(fd < 0 || fd > FD_SETSIZE) return 0;
+ return !!( fdsetp->flags[fd/16] & (1<<(fd%16)) );
+}
#endif
-../../../../../KernelLand/Kernel/include/keysyms.h
\ No newline at end of file
+#include "../../../../../KernelLand/Kernel/include/keysyms.h"
\ No newline at end of file
\r
INCFILES := stdio.h stdlib.h\r
\r
-OBJ = stub.o heap.o stdlib.o env.o stdio.o string.o select.o rand.o\r
+OBJ = stub.o heap.o stdlib.o env.o stdio.o string.o rand.o\r
OBJ += perror.o scanf.o signals.o strtoi.o strtof.o\r
OBJ += arch/$(ARCHDIR).ao\r
# signals.o\r
+++ /dev/null
-/*
- * Acess2 C Library
- * - By John Hodge (thePowersGang)
- *
- * select.c
- */
-
-//#include <sys/select.h>
-#include <sys/types.h>
-
-void FD_ZERO(fd_set *fdsetp)
-{
- int i = FD_SETSIZE/16;
- while( i-- )
- fdsetp->flags[i]=0;
-}
-
-void FD_CLR(int fd, fd_set *fdsetp)
-{
- if(fd < 0 || fd > FD_SETSIZE) return;
- fdsetp->flags[fd/16] &= (fd_set_ent_t) ((~1 << (fd%16))) & 0xFFFF;
-}
-
-void FD_SET(int fd, fd_set *fdsetp)
-{
- if(fd < 0 || fd > FD_SETSIZE) return;
- fdsetp->flags[fd/16] |= (fd_set_ent_t) (1 << (fd%16));
-}
-
-int FD_ISSET(int fd, fd_set *fdsetp)
-{
- if(fd < 0 || fd > FD_SETSIZE) return 0;
- return !!( fdsetp->flags[fd/16] & (1<<(fd%16)) );
-}
-