From d04645198d648a17ccb83e70aa5e6d60a06121aa Mon Sep 17 00:00:00 2001 From: Alexis211 Date: Fri, 18 Dec 2009 16:22:58 +0100 Subject: [nonworking commit] Started porting newlib --- Source/Applications/Demos/Makefile | 2 +- Source/Applications/PaperWork/Makefile | 2 +- Source/Applications/Shell/Makefile | 2 +- Source/Library/App.ld | 33 ++++++++++++++++++++++ Source/Library/Link.ld | 33 ---------------------- Source/UnixUserland/App.ld | 33 ++++++++++++++++++++++ Source/UnixUserland/Makefile | 50 ++++++++++++++++++++++++++++++++++ Source/UnixUserland/_exit.c | 2 ++ Source/UnixUserland/_start.c | 7 +++++ Source/UnixUserland/close.c | 3 ++ Source/UnixUserland/environ.c | 2 ++ Source/UnixUserland/execve.c | 8 ++++++ Source/UnixUserland/fork.c | 8 ++++++ Source/UnixUserland/fstat.c | 6 ++++ Source/UnixUserland/getpid.c | 3 ++ Source/UnixUserland/isatty.c | 3 ++ Source/UnixUserland/kill.c | 8 ++++++ Source/UnixUserland/link.c | 8 ++++++ Source/UnixUserland/lseek.c | 3 ++ Source/UnixUserland/open.c | 3 ++ Source/UnixUserland/read.c | 3 ++ Source/UnixUserland/sbrk.c | 16 +++++++++++ Source/UnixUserland/stat.c | 2 ++ Source/UnixUserland/times.c | 1 + Source/UnixUserland/unlink.c | 8 ++++++ Source/UnixUserland/wait.c | 8 ++++++ Source/UnixUserland/write.c | 10 +++++++ 27 files changed, 231 insertions(+), 36 deletions(-) create mode 100644 Source/Library/App.ld delete mode 100644 Source/Library/Link.ld create mode 100644 Source/UnixUserland/App.ld create mode 100644 Source/UnixUserland/Makefile create mode 100644 Source/UnixUserland/_exit.c create mode 100644 Source/UnixUserland/_start.c create mode 100644 Source/UnixUserland/close.c create mode 100644 Source/UnixUserland/environ.c create mode 100644 Source/UnixUserland/execve.c create mode 100644 Source/UnixUserland/fork.c create mode 100644 Source/UnixUserland/fstat.c create mode 100644 Source/UnixUserland/getpid.c create mode 100644 Source/UnixUserland/isatty.c create mode 100644 Source/UnixUserland/kill.c create mode 100644 Source/UnixUserland/link.c create mode 100644 Source/UnixUserland/lseek.c create mode 100644 Source/UnixUserland/open.c create mode 100644 Source/UnixUserland/read.c create mode 100644 Source/UnixUserland/sbrk.c create mode 100644 Source/UnixUserland/stat.c create mode 100644 Source/UnixUserland/times.c create mode 100644 Source/UnixUserland/unlink.c create mode 100644 Source/UnixUserland/wait.c create mode 100644 Source/UnixUserland/write.c (limited to 'Source') 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/App.ld b/Source/Library/App.ld new file mode 100644 index 0000000..68591fd --- /dev/null +++ b/Source/Library/App.ld @@ -0,0 +1,33 @@ +ENTRY (start) +INPUT (Melon.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/Library/Link.ld b/Source/Library/Link.ld deleted file mode 100644 index 68591fd..0000000 --- a/Source/Library/Link.ld +++ /dev/null @@ -1,33 +0,0 @@ -ENTRY (start) -INPUT (Melon.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/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 +#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 +#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 + +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 +#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 +#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 + +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 + 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 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 +#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 +#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; +} -- cgit v1.2.3