From 857d82d45c2bbcaf5234b756736596b1e6a9d28a Mon Sep 17 00:00:00 2001 From: Miguel Date: Sat, 18 Aug 2018 20:04:32 +0200 Subject: cleaning up (Also for newlib) --- README.md | 109 +++++++++++++++++++------------------------- kernel/syscalls.c | 2 +- newlib/crt0.s | 19 ++++++++ newlib/syscalls.c | 120 +++++++++++++++++++++++++++++++++++++++++++++++++ screenshots/foolos.png | Bin 8959 -> 0 bytes syscalls/syscalls.c | 120 ------------------------------------------------- userspace/crt0.S | 21 --------- 7 files changed, 187 insertions(+), 204 deletions(-) create mode 100644 newlib/crt0.s create mode 100644 newlib/syscalls.c delete mode 100644 screenshots/foolos.png delete mode 100644 syscalls/syscalls.c delete mode 100644 userspace/crt0.S diff --git a/README.md b/README.md index 6566420..c885f88 100644 --- a/README.md +++ b/README.md @@ -6,55 +6,36 @@ Disclaimer THIS IS A WORK IN PROGRESS. -This is a simple and useless "operating system", with very basic -features, sorry. It is the fruit of my fundamental explorations of -the x86 architectures and operating system design. +This is a simple and useless "operating system", with a very basic set +of features. It is the fruit of my fundamental explorations of the x86 +architecture and operating system design. -We have (or had) 32-bit protected mode, interrupt handling, -memory management, scheduling, a floppy disk controller, mouse -as well as VESA and a couple of other things. networking is a big goal. - -![Screenshot of FoolOS](/screenshots/foolos.png?raw=true "FoolOs Kernel") - -Copyright M.Idziorek 2014-2015,2018 unless stated otherwise! - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -Building --------- - -Adapt $SYSROOT in userspace/sys/Makefile +Copyright M.Idziorek 2014-2015,2018 unless stated otherwise. -Requirements: - -* OS Specific Toolchain [1] +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - binutils-* - gcc-* +Prequisites +----------- -* Newlib * [2] +GCC CROSS-COMPILER (i686-elf) -* GRUB2 + https://wiki.osdev.org/GCC_Cross-Compiler (18 AUG 2018) + ftp://ftp.fu-berlin.de/unix/languages/gcc/releases/gcc-8.2.0/gcc-8.2.0.tar.gz + https://sunsite.icm.edu.pl/pub/gnu/binutils/binutils-2.31.1.tar.gz -https://wiki.osdev.org/GCC_Cross-Compiler -ftp://ftp.fu-berlin.de/unix/languages/gcc/releases/gcc-8.2.0/gcc-8.2.0.tar.gz -https://sunsite.icm.edu.pl/pub/gnu/binutils/binutils-2.31.1.tar.gz +NEWLIB -https://wiki.osdev.org/Porting_Newlib -ftp://sourceware.org/pub/newlib/newlib-3.0.0.20180802.tar.gz -https://ftp.gnu.org/gnu/autoconf/autoconf-2.68.tar.gz -https://ftp.gnu.org/gnu/automake/automake-1.11.6.tar.gz + https://wiki.osdev.org/Porting_Newlib (18 AUG 2018) + ftp://sourceware.org/pub/newlib/newlib-3.0.0.20180802.tar.gz + https://ftp.gnu.org/gnu/autoconf/autoconf-2.68.tar.gz + https://ftp.gnu.org/gnu/automake/automake-1.11.6.tar.gz -MAKE DIFF OF NEWLIB ! - -DID NO TRY YET -https://www.musl-libc.org/releases/musl-1.1.19.tar.gz Usage ----- @@ -77,6 +58,10 @@ FoolOS is tested/developed on the following emulators/machines Features -------- +We have (or had) 32-bit protected mode, interrupt handling, +memory management, scheduling, a floppy disk controller, mouse + +as well as VESA and a couple of other things. networking is a big goal. Please note that all features are only very rudimentary and buggy. Some might have been disable (temporarily) due to conflicts or regressions. @@ -118,29 +103,29 @@ Todos Issues ------ -* sbrk() -* ESP collisions!? -* TSS-ESP0? -* kbfree() -* pg_directory alloc -* implement posix(?) getdents instead of our own readdir. -* Turning on some gcc optimizations breaks the kernel. (need debug so go for ELF!) -* Assumed support for VESA mode 0x114 with linear addressing. (let the user select) -* fixed size of process images! + sbrk() + ESP collisions!? + TSS-ESP0? + kbfree() + pg_directory alloc + implement posix(?) getdents instead of our own readdir. + Turning on some gcc optimizations breaks the kernel. (need debug so go for ELF!) + Assumed support for VESA mode 0x114 with linear addressing. (let the user select) + fixed size of process images! REFERENCES ========== -* http://www.brokenthorn.com/Resources/OSDev17.html -* http://www.jamesmolloy.co.uk/tutorial_html/9.-Multitasking.html -* http://pdos.csail.mit.edu/6.828/2011/labs/lab6/ -* http://pdos.csail.mit.edu/6.828/2011/xv6.html -* http://www.nongnu.org/ext2-doc/ -* http://www.osdever.net/tutorials/view/multiprocessing-support-for-hobby-oses-explained -* http://forum.osdev.org/viewtopic.php?f=1&t=10944 -* http://wiki.osdev.org/Virtual_8086_Mode -* http://wiki.xomb.org/index.php?title=ACPI_Tables -* http://wiki.osdev.org/Hosted_GCC_Cross-Compiler -* https://sourceware.org/newlib/ -* and many many more... + http://www.brokenthorn.com/Resources/OSDev17.html + http://www.jamesmolloy.co.uk/tutorial_html/9.-Multitasking.html + http://pdos.csail.mit.edu/6.828/2011/labs/lab6/ + http://pdos.csail.mit.edu/6.828/2011/xv6.html + http://www.nongnu.org/ext2-doc/ + http://www.osdever.net/tutorials/view/multiprocessing-support-for-hobby-oses-explained + http://forum.osdev.org/viewtopic.php?f=1&t=10944 + http://wiki.osdev.org/Virtual_8086_Mode + http://wiki.xomb.org/index.php?title=ACPI_Tables + http://wiki.osdev.org/Hosted_GCC_Cross-Compiler + https://sourceware.org/newlib/ + and many many more... diff --git a/kernel/syscalls.c b/kernel/syscalls.c index 0be0602..3f2a811 100644 --- a/kernel/syscalls.c +++ b/kernel/syscalls.c @@ -224,7 +224,7 @@ int syscall_execve(char *name, char **argv, char **env) asm volatile ("push %0" :: "r" (argv1)); asm volatile ("push %0" :: "r" (arg_count)); - asm volatile ("push %0" :: "r" (kballoc(1))); + //asm volatile ("push %0" :: "r" (kballoc(1))); asm volatile ("push %0" :: "r" (env1)); // push addr and return to it diff --git a/newlib/crt0.s b/newlib/crt0.s new file mode 100644 index 0000000..e8f0405 --- /dev/null +++ b/newlib/crt0.s @@ -0,0 +1,19 @@ +.global _start + +_start: + +# environment adress was passed on stack +pop %eax +mov %eax, environ + +# call main (argc and argv are on the stack) +call main + +# push exit code and pass to _exit syscall +push %eax +call _exit + +# this should never be reached! +.wait: + hlt +jmp .wait diff --git a/newlib/syscalls.c b/newlib/syscalls.c new file mode 100644 index 0000000..3cd1f95 --- /dev/null +++ b/newlib/syscalls.c @@ -0,0 +1,120 @@ +#include + +#include +#include +#include + +#include "fs.h" +#include "syscalls.h" + +extern char **environ; + +int _readdir(const char *name,fs_dirent *dirs,int max) +{ + return syscall(SYSCALL_READDIR,name,dirs,max); +} + +int _poll(int file) +{ + return syscall(SYSCALL_POLL,file,0,0); +} + +void _exit(int ret) +{ + return syscall(SYSCALL_EXIT,ret,environ,0); +} + +int _close(int file) +{ + return syscall(SYSCALL_CLOSE,file,0,0); +} + +int _isatty(int file) +{ + return syscall(SYSCALL_ISATTY,file,0,0); +} + +int _lseek(int file, int ptr, int dir) +{ + return syscall(SYSCALL_LSEEK,file,ptr,dir); +} + +int _read(int file, char *ptr, int len) +{ + return syscall(SYSCALL_READ,file,ptr,len); +} + +int _open(const char *name, int flags, int mode) +{ + return syscall(SYSCALL_OPEN,name,flags,mode); +} + +int _write(int file, char *ptr, int len) +{ + return syscall(SYSCALL_WRITE,file,ptr,len); +} + +int _execve(char *name, char **argv, char **env) +{ + return syscall(SYSCALL_EXECVE,name,argv,env); +} + +uint32_t _sbrk(int incr) +{ + return syscall(SYSCALL_SBRK,incr,0,0); +} + +int _gettimeofday(struct timeval *tv, void *tz) +{ + return syscall(SYSCALL_GETTIMEOFDAY,tv,tz,0); +} + +int _fork(void) +{ + return syscall(SYSCALL_FORK,0,0,0); +} + +int _getpid(void) +{ + return syscall(SYSCALL_GETPID,0,0,0); +} + +int _kill(int pid, int sig) +{ + return syscall(SYSCALL_KILL,pid,sig,0); +} + +int _link(char *old, char *ne) +{ + return syscall(SYSCALL_LINK,old,ne,0); +} + +int _unlink(char *name) +{ + return syscall(SYSCALL_UNLINK,name,0,0); +} + +int _times(struct tms *buf) +{ + return syscall(SYSCALL_TIMES,buf,0,0); +} + +int _wait(int *status) +{ + return syscall(SYSCALL_WAIT,status,0,0); +} + +int _stat(const char *file, struct stat *st) +{ + return syscall(SYSCALL_STAT,file,st,0); +} + +int _lstat(const char *file, struct stat *st) +{ + return syscall(SYSCALL_LSTAT,file,st,0); +} + +int _fstat(int file, struct stat *st) +{ + return syscall(SYSCALL_FSTAT,file,st,0); +} diff --git a/screenshots/foolos.png b/screenshots/foolos.png deleted file mode 100644 index d07eb1c..0000000 Binary files a/screenshots/foolos.png and /dev/null differ diff --git a/syscalls/syscalls.c b/syscalls/syscalls.c deleted file mode 100644 index 3cd1f95..0000000 --- a/syscalls/syscalls.c +++ /dev/null @@ -1,120 +0,0 @@ -#include - -#include -#include -#include - -#include "fs.h" -#include "syscalls.h" - -extern char **environ; - -int _readdir(const char *name,fs_dirent *dirs,int max) -{ - return syscall(SYSCALL_READDIR,name,dirs,max); -} - -int _poll(int file) -{ - return syscall(SYSCALL_POLL,file,0,0); -} - -void _exit(int ret) -{ - return syscall(SYSCALL_EXIT,ret,environ,0); -} - -int _close(int file) -{ - return syscall(SYSCALL_CLOSE,file,0,0); -} - -int _isatty(int file) -{ - return syscall(SYSCALL_ISATTY,file,0,0); -} - -int _lseek(int file, int ptr, int dir) -{ - return syscall(SYSCALL_LSEEK,file,ptr,dir); -} - -int _read(int file, char *ptr, int len) -{ - return syscall(SYSCALL_READ,file,ptr,len); -} - -int _open(const char *name, int flags, int mode) -{ - return syscall(SYSCALL_OPEN,name,flags,mode); -} - -int _write(int file, char *ptr, int len) -{ - return syscall(SYSCALL_WRITE,file,ptr,len); -} - -int _execve(char *name, char **argv, char **env) -{ - return syscall(SYSCALL_EXECVE,name,argv,env); -} - -uint32_t _sbrk(int incr) -{ - return syscall(SYSCALL_SBRK,incr,0,0); -} - -int _gettimeofday(struct timeval *tv, void *tz) -{ - return syscall(SYSCALL_GETTIMEOFDAY,tv,tz,0); -} - -int _fork(void) -{ - return syscall(SYSCALL_FORK,0,0,0); -} - -int _getpid(void) -{ - return syscall(SYSCALL_GETPID,0,0,0); -} - -int _kill(int pid, int sig) -{ - return syscall(SYSCALL_KILL,pid,sig,0); -} - -int _link(char *old, char *ne) -{ - return syscall(SYSCALL_LINK,old,ne,0); -} - -int _unlink(char *name) -{ - return syscall(SYSCALL_UNLINK,name,0,0); -} - -int _times(struct tms *buf) -{ - return syscall(SYSCALL_TIMES,buf,0,0); -} - -int _wait(int *status) -{ - return syscall(SYSCALL_WAIT,status,0,0); -} - -int _stat(const char *file, struct stat *st) -{ - return syscall(SYSCALL_STAT,file,st,0); -} - -int _lstat(const char *file, struct stat *st) -{ - return syscall(SYSCALL_LSTAT,file,st,0); -} - -int _fstat(int file, struct stat *st) -{ - return syscall(SYSCALL_FSTAT,file,st,0); -} diff --git a/userspace/crt0.S b/userspace/crt0.S deleted file mode 100644 index 30b56a9..0000000 --- a/userspace/crt0.S +++ /dev/null @@ -1,21 +0,0 @@ -.global _start - -_start: - -pop %eax -mov %eax, environ - -pop %eax -# mov %eax, _impure_ptr # TODO: use this ! - -call main - -push environ -push %eax -call _exit2 - -# this should never be reached anyway! - -.wait: - hlt -jmp .wait -- cgit v1.2.3