diff options
author | Alexis211 <alexis211@gmail.com> | 2009-12-18 16:22:58 +0100 |
---|---|---|
committer | Alexis211 <alexis211@gmail.com> | 2009-12-18 16:22:58 +0100 |
commit | d04645198d648a17ccb83e70aa5e6d60a06121aa (patch) | |
tree | 4ee3203112c2fda42a85ec00f3f78eee14689869 /Source | |
parent | 5f87c447bdcb82beacbfb930942fe9995dcdb60f (diff) | |
download | Melon-d04645198d648a17ccb83e70aa5e6d60a06121aa.tar.gz Melon-d04645198d648a17ccb83e70aa5e6d60a06121aa.zip |
[nonworking commit] Started porting newlib
Diffstat (limited to 'Source')
26 files changed, 198 insertions, 3 deletions
diff --git a/Source/Applications/Demos/Makefile b/Source/Applications/Demos/Makefile index e66acce..82489ba 100644 --- a/Source/Applications/Demos/Makefile +++ b/Source/Applications/Demos/Makefile @@ -7,7 +7,7 @@ CXX = g++ CXXFLAGS = -nostartfiles -nostdlib -ffreestanding -fno-exceptions -fno-rtti -I ../../Library/Common -I ../../Library/Interface -I ../../Library/Userland -D THIS_IS_MELON_USERLAND LD = ld -LDFLAGS = -T ../../Library/Link.ld -L ../../Library +LDFLAGS = -T ../../Library/App.ld -L ../../Library Applications = asmdemo cxxdemo GOL diff --git a/Source/Applications/PaperWork/Makefile b/Source/Applications/PaperWork/Makefile index fe8d564..c39fc83 100644 --- a/Source/Applications/PaperWork/Makefile +++ b/Source/Applications/PaperWork/Makefile @@ -4,7 +4,7 @@ CXX = g++ CXXFLAGS = -nostartfiles -nostdlib -ffreestanding -fno-exceptions -fno-rtti -I ../../Library/Common -I ../../Library/Interface -I ../../Library/Userland -D THIS_IS_MELON_USERLAND LD = ld -LDFLAGS = -T ../../Library/Link.ld -L ../../Library +LDFLAGS = -T ../../Library/App.ld -L ../../Library Objects = main.o OutFile = PaperWork diff --git a/Source/Applications/Shell/Makefile b/Source/Applications/Shell/Makefile index bf81af6..a5587d8 100644 --- a/Source/Applications/Shell/Makefile +++ b/Source/Applications/Shell/Makefile @@ -4,7 +4,7 @@ CXX = g++ CXXFLAGS = -nostartfiles -nostdlib -ffreestanding -fno-exceptions -fno-rtti -I ../../Library/Common -I ../../Library/Interface -I ../../Library/Userland -D THIS_IS_MELON_USERLAND LD = ld -LDFLAGS = -T ../../Library/Link.ld -L ../../Library +LDFLAGS = -T ../../Library/App.ld -L ../../Library Objects = main.o \ Shell.ns.o \ diff --git a/Source/Library/Link.ld b/Source/Library/App.ld index 68591fd..68591fd 100644 --- a/Source/Library/Link.ld +++ b/Source/Library/App.ld 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; +} |