summaryrefslogtreecommitdiff
path: root/Source/UnixUserland
diff options
context:
space:
mode:
Diffstat (limited to 'Source/UnixUserland')
-rw-r--r--Source/UnixUserland/App.ld33
-rw-r--r--Source/UnixUserland/Makefile50
-rw-r--r--Source/UnixUserland/_exit.c2
-rw-r--r--Source/UnixUserland/_start.c7
-rw-r--r--Source/UnixUserland/close.c3
-rw-r--r--Source/UnixUserland/environ.c2
-rw-r--r--Source/UnixUserland/execve.c8
-rw-r--r--Source/UnixUserland/fork.c8
-rw-r--r--Source/UnixUserland/fstat.c6
-rw-r--r--Source/UnixUserland/getpid.c3
-rw-r--r--Source/UnixUserland/isatty.c3
-rw-r--r--Source/UnixUserland/kill.c8
-rw-r--r--Source/UnixUserland/link.c8
-rw-r--r--Source/UnixUserland/lseek.c3
-rw-r--r--Source/UnixUserland/open.c3
-rw-r--r--Source/UnixUserland/read.c3
-rw-r--r--Source/UnixUserland/sbrk.c16
-rw-r--r--Source/UnixUserland/stat.c2
-rw-r--r--Source/UnixUserland/times.c1
-rw-r--r--Source/UnixUserland/unlink.c8
-rw-r--r--Source/UnixUserland/wait.c8
-rw-r--r--Source/UnixUserland/write.c10
22 files changed, 195 insertions, 0 deletions
diff --git a/Source/UnixUserland/App.ld b/Source/UnixUserland/App.ld
new file mode 100644
index 0000000..03ac84f
--- /dev/null
+++ b/Source/UnixUserland/App.ld
@@ -0,0 +1,33 @@
+ENTRY (_start)
+INPUT (MelonUnix.o)
+
+SECTIONS{
+ . = 0x10000000;
+
+ .text : {
+ *(.text)
+ }
+
+ .rodata ALIGN (0x1000) :{
+ *(.rodata)
+ }
+
+ .data ALIGN (0x1000) : {
+ start_ctors = .;
+ *(.ctor*)
+ end_ctors = .;
+ start_dtors = .;
+ *(.dtor*)
+ end_dtors = .;
+ *(.data)
+ }
+
+ .bss : {
+ sbss = .;
+ *(COMMON)
+ *(.bss)
+ ebss = .;
+ }
+
+ end = .; _end = .; __end = .;
+}
diff --git a/Source/UnixUserland/Makefile b/Source/UnixUserland/Makefile
new file mode 100644
index 0000000..44fa29f
--- /dev/null
+++ b/Source/UnixUserland/Makefile
@@ -0,0 +1,50 @@
+.PHONY: clean, mrproper
+
+CC = gcc
+CCFLAGS = -nostdlib -nostartfiles -nodefaultlibs -fno-builtin -fno-stack-protector -Wall -Wextra -Werror -I../../Ports/newlib-1.15.0/newlib/libc/include
+
+LD = ld
+LDFLAGS = -r
+
+OutFile = MelonUnix.o
+Objects = _exit.o \
+ _start.o \
+ close.o \
+ environ.o \
+ execve.o \
+ fork.o \
+ fstat.o \
+ getpid.o \
+ isatty.o \
+ kill.o \
+ link.o \
+ lseek.o \
+ open.o \
+ read.o \
+ sbrk.o \
+ stat.o \
+ times.o \
+ unlink.o \
+ wait.o \
+ write.o
+
+all: $(OutFile)
+ echo "* Done with $(OutFile)."
+
+rebuild: mrproper all
+
+$(OutFile): $(Objects)
+ echo "* Linking executable : $(OutFile)..."
+ $(LD) $(LDFLAGS) -o $(OutFile) $^
+
+%.o: %.c
+ echo "* Compiling $<..."
+ $(CC) -c $< -o $@ $(CFLAGS)
+
+clean:
+ echo "* Removing object files..."
+ rm -rf $(Objects)
+
+mrproper: clean
+ echo "* Removing executable: $(OutFile)"
+ rm -rf $(OutFile)
diff --git a/Source/UnixUserland/_exit.c b/Source/UnixUserland/_exit.c
new file mode 100644
index 0000000..8753f0c
--- /dev/null
+++ b/Source/UnixUserland/_exit.c
@@ -0,0 +1,2 @@
+void _exit(int errcode) {
+}
diff --git a/Source/UnixUserland/_start.c b/Source/UnixUserland/_start.c
new file mode 100644
index 0000000..00dc77e
--- /dev/null
+++ b/Source/UnixUserland/_start.c
@@ -0,0 +1,7 @@
+int main();
+
+void _start() {
+ main();
+ asm volatile("int $66;");
+ while(1);
+}
diff --git a/Source/UnixUserland/close.c b/Source/UnixUserland/close.c
new file mode 100644
index 0000000..d1e0a16
--- /dev/null
+++ b/Source/UnixUserland/close.c
@@ -0,0 +1,3 @@
+int close(int file) {
+ return -1;
+}
diff --git a/Source/UnixUserland/environ.c b/Source/UnixUserland/environ.c
new file mode 100644
index 0000000..7a59da1
--- /dev/null
+++ b/Source/UnixUserland/environ.c
@@ -0,0 +1,2 @@
+char *_env[1] = { 0 };
+char **environ = _env;
diff --git a/Source/UnixUserland/execve.c b/Source/UnixUserland/execve.c
new file mode 100644
index 0000000..b066745
--- /dev/null
+++ b/Source/UnixUserland/execve.c
@@ -0,0 +1,8 @@
+#include <errno.h>
+#undef errno
+extern int errno;
+
+int execve(char *name, char **argv, char **env) {
+ errno = ENOMEM;
+ return -1;
+}
diff --git a/Source/UnixUserland/fork.c b/Source/UnixUserland/fork.c
new file mode 100644
index 0000000..012bc17
--- /dev/null
+++ b/Source/UnixUserland/fork.c
@@ -0,0 +1,8 @@
+#include <errno.h>
+#undef errno
+extern int errno;
+
+int fork() {
+ errno = EAGAIN;
+ return -1;
+}
diff --git a/Source/UnixUserland/fstat.c b/Source/UnixUserland/fstat.c
new file mode 100644
index 0000000..78d32f2
--- /dev/null
+++ b/Source/UnixUserland/fstat.c
@@ -0,0 +1,6 @@
+#include <sys/stat.h>
+
+int fstat(int file, struct stat *st) {
+ st->st_mode = S_IFCHR;
+ return 0;
+}
diff --git a/Source/UnixUserland/getpid.c b/Source/UnixUserland/getpid.c
new file mode 100644
index 0000000..c5e6884
--- /dev/null
+++ b/Source/UnixUserland/getpid.c
@@ -0,0 +1,3 @@
+int getpid() {
+ return 1;
+}
diff --git a/Source/UnixUserland/isatty.c b/Source/UnixUserland/isatty.c
new file mode 100644
index 0000000..8a0d1e7
--- /dev/null
+++ b/Source/UnixUserland/isatty.c
@@ -0,0 +1,3 @@
+int isatty(int file) {
+ return 1;
+}
diff --git a/Source/UnixUserland/kill.c b/Source/UnixUserland/kill.c
new file mode 100644
index 0000000..c1f438b
--- /dev/null
+++ b/Source/UnixUserland/kill.c
@@ -0,0 +1,8 @@
+#include <errno.h>
+#undef errno
+extern int errno;
+
+int kill(int pid, int sig) {
+ errno = EINVAL;
+ return -1;
+}
diff --git a/Source/UnixUserland/link.c b/Source/UnixUserland/link.c
new file mode 100644
index 0000000..17c08dd
--- /dev/null
+++ b/Source/UnixUserland/link.c
@@ -0,0 +1,8 @@
+#include <errno.h>
+#undef errno
+extern int errno;
+
+int link(char *old, char *new) {
+ errno = EMLINK;
+ return -1;
+}
diff --git a/Source/UnixUserland/lseek.c b/Source/UnixUserland/lseek.c
new file mode 100644
index 0000000..d3d24d8
--- /dev/null
+++ b/Source/UnixUserland/lseek.c
@@ -0,0 +1,3 @@
+int lseek(int file, int ptr, int dir) {
+ return 0;
+}
diff --git a/Source/UnixUserland/open.c b/Source/UnixUserland/open.c
new file mode 100644
index 0000000..eb9bed7
--- /dev/null
+++ b/Source/UnixUserland/open.c
@@ -0,0 +1,3 @@
+int open(const char* name, int flags, int mode) {
+ return -1;
+}
diff --git a/Source/UnixUserland/read.c b/Source/UnixUserland/read.c
new file mode 100644
index 0000000..303c413
--- /dev/null
+++ b/Source/UnixUserland/read.c
@@ -0,0 +1,3 @@
+int read(int file, char *ptr, int len) {
+ return 0;
+}
diff --git a/Source/UnixUserland/sbrk.c b/Source/UnixUserland/sbrk.c
new file mode 100644
index 0000000..26df466
--- /dev/null
+++ b/Source/UnixUserland/sbrk.c
@@ -0,0 +1,16 @@
+#include <sys/types.h>
+
+caddr_t sbrk(int incr) {
+ extern char end;
+ static char *heap_end;
+ char *prev_heap_end;
+
+ if (heap_end == 0) {
+ heap_end = &end;
+ }
+ prev_heap_end = heap_end;
+
+ heap_end += incr;
+ return (caddr_t) prev_heap_end;
+
+}
diff --git a/Source/UnixUserland/stat.c b/Source/UnixUserland/stat.c
new file mode 100644
index 0000000..1dada06
--- /dev/null
+++ b/Source/UnixUserland/stat.c
@@ -0,0 +1,2 @@
+#include <sys/stat.h>
+
diff --git a/Source/UnixUserland/times.c b/Source/UnixUserland/times.c
new file mode 100644
index 0000000..39ebf29
--- /dev/null
+++ b/Source/UnixUserland/times.c
@@ -0,0 +1 @@
+#include <sys/times.h>
diff --git a/Source/UnixUserland/unlink.c b/Source/UnixUserland/unlink.c
new file mode 100644
index 0000000..112ca54
--- /dev/null
+++ b/Source/UnixUserland/unlink.c
@@ -0,0 +1,8 @@
+#include <errno.h>
+#undef errno
+extern int errno;
+
+int unlink(char *name) {
+ errno = ENOENT;
+ return -1;
+}
diff --git a/Source/UnixUserland/wait.c b/Source/UnixUserland/wait.c
new file mode 100644
index 0000000..5073c77
--- /dev/null
+++ b/Source/UnixUserland/wait.c
@@ -0,0 +1,8 @@
+#include <errno.h>
+#undef errno
+extern int errno;
+
+int wait(int *status) {
+ errno = ECHILD;
+ return -1;
+}
diff --git a/Source/UnixUserland/write.c b/Source/UnixUserland/write.c
new file mode 100644
index 0000000..3cd436b
--- /dev/null
+++ b/Source/UnixUserland/write.c
@@ -0,0 +1,10 @@
+int write(int file, char *ptr, int len) {
+ int i;
+ for (i = 0; i < len; i++) {
+ int t = ptr[i];
+ asm volatile("mov $0xFFFFFF01, %%eax; \
+ mov %0, %%ebx; \
+ int $64;" : : "r"(t));
+ }
+ return len;
+}