summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichal Idziorek <m.i@gmx.at>2015-05-24 23:30:12 +0200
committerMichal Idziorek <m.i@gmx.at>2015-05-24 23:30:12 +0200
commit8ea3e244d44190e44a092ffb004e13ad94174c68 (patch)
tree2365b0ec35b4fbdc82d49bcefc014fc8af59b251
parent1b64f1e69bfbffc0e70ba3a1baff00ed3fd8cb51 (diff)
porting ncurses...
-rw-r--r--Makefile1
-rw-r--r--fs/elf.c2
-rw-r--r--fs/ext2.c8
-rw-r--r--kernel/config.h15
-rw-r--r--kernel/kernel.c3
-rw-r--r--kernel/syscalls.c1
-rw-r--r--kernel/usermode.c4
-rw-r--r--lib/logger/log.c14
-rw-r--r--lib/string/string.c4
-rw-r--r--lib/string/string.h1
-rw-r--r--packages/ncurses-5.9/README6
-rw-r--r--userspace/Makefile4
-rw-r--r--userspace/foolshell.c16
-rw-r--r--userspace/init.c1
-rw-r--r--userspace/snake.c16
-rw-r--r--userspace/sys/Makefile1
-rw-r--r--userspace/sys/crt0.S3
-rw-r--r--userspace/sys/crt0.obin660 -> 660 bytes
-rw-r--r--userspace/sys/libfool.abin37292 -> 37550 bytes
-rw-r--r--userspace/sys/sys.c10
-rw-r--r--userspace/sys/sys.obin17956 -> 18236 bytes
-rw-r--r--userspace/sys/syscalls.c3
-rw-r--r--userspace/sys/syscalls.obin18572 -> 18544 bytes
-rw-r--r--userspace/sys/termios.h18
24 files changed, 107 insertions, 24 deletions
diff --git a/Makefile b/Makefile
index 9b0742f..7450e58 100644
--- a/Makefile
+++ b/Makefile
@@ -161,6 +161,7 @@ run-bochs: all
# run in qemu
run-qemu: all
qemu-system-i386 -enable-kvm disk.img -smp 4 -s
+ #qemu-system-i386 -enable-kvm -s -kernel foolos.img -smp 4 -initrd userspace/ext2.img
run-qemu-debug: all
# qemu -enable-kvm -s -S ~/temp/FoolOs/disk.img
diff --git a/fs/elf.c b/fs/elf.c
index f9f479c..dc5f472 100644
--- a/fs/elf.c
+++ b/fs/elf.c
@@ -77,12 +77,12 @@ uint32_t load_elf(char *name, uint32_t *alloc)
//TODO: load ELF binary and move this to own compilation unit
//load binary
-// uint32_t vaddr=0x08048000;
uint32_t vaddr=0x08000000;
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"loading %s",name);
ext2_check(ext2_ramimage);
ext2_inode_content(ext2_ramimage,inode_nr,vaddr,0x100000); // load 1mb;
+
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_DEBUG,"ELF File loaded to final destination.");
Elf32_Ehdr *elf;
diff --git a/fs/ext2.c b/fs/ext2.c
index 4f00000..1f4d04e 100644
--- a/fs/ext2.c
+++ b/fs/ext2.c
@@ -201,7 +201,9 @@ int ext2_inode_content(char *ram,int inode_nr,uint8_t *ramdest,int max)
int sum=0;
int count=0;
- log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"Loading %d %d bytes",inode.size_high, inode.size_low);
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"Loading %d.%d bytes",inode.size_high, inode.size_low);
+
+ if(inode.size_high>0)panic(FOOLOS_MODULE_NAME,"inode with high.size unsupported, i am sorry.");
while(pos<inode.size_low) // TODO: use size high!
{
@@ -266,8 +268,8 @@ int ext2_filename_to_inode_traverse(uint8_t *ram, char *path,int inode_start)
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_DEBUG,"looking for %s '%s' in inode: %d",final?"file":"dir",first,inode_start);
- fs_dirent dirs[15];
- int count= ext2_read_dir(ram, inode_start,dirs,15); // get dir
+ fs_dirent dirs[25];
+ int count= ext2_read_dir(ram, inode_start,dirs,25); // get dir
for(int i=0;i<count;i++)
{
diff --git a/kernel/config.h b/kernel/config.h
index 0a6fd3c..5c58245 100644
--- a/kernel/config.h
+++ b/kernel/config.h
@@ -1,14 +1,21 @@
+
/********************************************
- *
- * Fool OS Central Configuration File
- *
+ * *
+ * Fool OS Central Configuration File *
+ * *
********************************************/
+#include <lib/logger/log.h>
+
#ifndef FOOLOS_CONFIG_H
#define FOOLOS_CONFIG_H
#define FOOLOS_CONSOLE_AUTOBREAK // add newline automatically at end of line
-#define FOOLOS_LOG_OFF // do not log anything
+
+#define FOOLOS_LOG_OFF // do not log anything
+#define FOOLOS_LOG_WHITELIST "elf","ext2","" // make exceptions for these modules. wmpty string marks the end
+#define FOOLOS_LOG_LEVEL FOOLOS_LOG_FINE // minimal severity level to log
+
#define FOOLOS_CONSOLE // otherwise VESA will be used!
#define FOOLSOS_SHOW_VESAMODES
#define MEM_PRINT_MEMORYMAP
diff --git a/kernel/kernel.c b/kernel/kernel.c
index d54baf6..cea1056 100644
--- a/kernel/kernel.c
+++ b/kernel/kernel.c
@@ -102,7 +102,6 @@ void kernel_main(uint32_t eax,uint32_t ebx)
//
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"%s - compiled on %s at %s",KERNEL_VERSION,__DATE__,__TIME__);
-
//
// Configuring the PIT timer.
//
@@ -167,11 +166,13 @@ void kernel_main(uint32_t eax,uint32_t ebx)
// Its driver will be hopefully implemented one day ;) TODO
//
//pci_init();
+ //
//empty stdin!
while(fifo_has(&get_fool()->std_in))
fifo_get(&get_fool()->std_in);
+
//
// Initialize Multitasking
//
diff --git a/kernel/syscalls.c b/kernel/syscalls.c
index c935ecd..3a898fc 100644
--- a/kernel/syscalls.c
+++ b/kernel/syscalls.c
@@ -191,6 +191,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" (env1));
// push addr and return to it
diff --git a/kernel/usermode.c b/kernel/usermode.c
index 1c7a726..e6568a4 100644
--- a/kernel/usermode.c
+++ b/kernel/usermode.c
@@ -56,7 +56,9 @@ void install_tss(int cpu_no){
void switch_to_user_mode()
{
- asm_usermode();
+ asm_usermode();
+ // userfunc();
+
}
char *argv_init[]={"/bin/init",NULL};
diff --git a/lib/logger/log.c b/lib/logger/log.c
index ef68a2e..e95f089 100644
--- a/lib/logger/log.c
+++ b/lib/logger/log.c
@@ -10,13 +10,14 @@
#include "kernel/timer.h"
#include "kernel/fifo.h"
+#include "lib/string/string.h"
+
static char buffer[LOG_BUF_SIZE];
static int first=0;
static int last=0;
static bool init=true;//
-
static void log_string(char *str)
{
while(*str!=0)
@@ -26,14 +27,21 @@ static void log_string(char *str)
}
}
+static char* whitelist[]={FOOLOS_LOG_WHITELIST};
+
void log(char *module_name, int log_level, char *format_string, ...)
{
#ifdef FOOLOS_LOG_OFF
- return;
+ for(int i=0;i<3;i++)
+ {
+
+ if(!strcmp(module_name,whitelist[i]))break;
+ if(!strcmp("",whitelist[i]))return;
+ }
#endif
- if(log_level<FOOLOS_LOG_INFO)return;
+ if(log_level<FOOLOS_LOG_LEVEL)return;
char buf_info[256];
char buf_log[256];
diff --git a/lib/string/string.c b/lib/string/string.c
index be2c7ed..2405483 100644
--- a/lib/string/string.c
+++ b/lib/string/string.c
@@ -29,12 +29,12 @@ int strcmp_l(char *str1, char *str2, int length)
}
}
-static int strcmp(char *str1, char *str2)
+
+strcmp(char *str1, char *str2)
{
return strcmp_l(str1,str2,0);
}
-
int strlen(const char* string)
{
int result = 0;
diff --git a/lib/string/string.h b/lib/string/string.h
index e41eb94..bd43b34 100644
--- a/lib/string/string.h
+++ b/lib/string/string.h
@@ -3,6 +3,7 @@
void* memcpy(void* restrict dstptr, const void* restrict srcptr, int size);
+int strcmp(char *str1, char *str2);
int strcmp_l(char *str1, char *str2, int length);
#endif
diff --git a/packages/ncurses-5.9/README b/packages/ncurses-5.9/README
index a723682..d5bcc5a 100644
--- a/packages/ncurses-5.9/README
+++ b/packages/ncurses-5.9/README
@@ -2,6 +2,8 @@
2. cd ncurses
3. exchange config.sub (just add foolos) and add +x
4. put termios.h in sysroot/usr/include/sys
-5. ./configure --host=i686-foolos --without-tests --with-fallbacks=xterm
-(or $ ./configure --host=i686-foolos --without-tests --with-fallbacks=xterm --with-debug CFLAGS="-gstabs -O0" CXXFLAGS="-gstabs -O0"
+5. ./configure --host=i686-foolos --without-tests --with-fallbacks=linux
+(or $ ./configure --host=i686-foolos --without-tests --with-fallbacks=linux --with-debug CFLAGS="-gstabs -O0" CXXFLAGS="-gstabs -O0"
6. make
+
+AS A WORKAROUND PASS: LDFLAGS=-lfool CC=i686-foolos-gcc
diff --git a/userspace/Makefile b/userspace/Makefile
index 801326b..1f562ab 100644
--- a/userspace/Makefile
+++ b/userspace/Makefile
@@ -18,7 +18,7 @@ PROGS=foolshell ls simple brainfuck add checker clear task1 task2 init cat snake
include ../Makefile.common
ext2.img: $(PROGS) ../mp/mp.bin
- dd if=/dev/zero of=ext2.img bs=512 count=10000
+ dd if=/dev/zero of=ext2.img bs=512 count=50000
sudo mkfs.ext2 -O none ext2.img -F
mkdir mnt
sudo mount ext2.img mnt
@@ -31,7 +31,7 @@ ext2.img: $(PROGS) ../mp/mp.bin
echo "++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++." > mnt/home/miguel/hello.brain
# cp ~/temp/fool-os-stuff/binutils-build-host-foolos/binutils/readelf mnt/bin
# cp ../font/binfont.bin mnt/
- cp ~/temp/fool-os-stuff/ncurses-5.9/progs/tput mnt/bin
+ cp ~/temp/fool-os-stuff/ncurses-5.9-foolos-new/progs/* mnt/bin/
cp ../mp/mp.bin mnt/boot/
mkdir -p mnt/etc
echo "127.0.0.1 localhost" > mnt/etc/hosts
diff --git a/userspace/foolshell.c b/userspace/foolshell.c
index 0ec7e88..fa62094 100644
--- a/userspace/foolshell.c
+++ b/userspace/foolshell.c
@@ -3,7 +3,17 @@
#include <stdbool.h>
#include <string.h>
+#include <reent.h>
+
extern char **environ;
+extern struct _reent *_impure_ptr;
+
+
+
+uint8_t buf_test[1024*300];
+
+
+
//
void hello()
@@ -50,6 +60,7 @@ void prompt()
int main(int argc, char **argv)
{
/*
+ printf("_impure_ptr: 0x%08x\n",_impure_ptr);
printf("argv= 0x%08x \n",argv);
printf("environ= 0x%08x \n",environ);
*/
@@ -62,7 +73,8 @@ int main(int argc, char **argv)
if(!silent)hello();
- char *buf=malloc(256);
+ //char *buf=malloc(256);
+ char buf[256];
while(1)
{
@@ -89,7 +101,7 @@ char **tokenize(char *buf)
for(i=0;i<l;i++)
{
// init space for next token
- token[c]=malloc(256);
+ token[c]=calloc(sizeof(char),256);
//skip all the whitespace
while(buf[i]==' '&&i<l)i++;
diff --git a/userspace/init.c b/userspace/init.c
index 73848f5..d3ab751 100644
--- a/userspace/init.c
+++ b/userspace/init.c
@@ -15,6 +15,7 @@ int main(int argc, char **argv)
char *argv[]={"/bin/foolshell",0};
char *env[]={"PS1=\033[34m$\033[37m","PWD=/home/miguel","PATH=/bin","TERM=linux",0};
execve("/bin/foolshell",argv,env); // replace process with our foolshell :)
+ //execve("/bin/clear",argv,env); // replace process with our foolshell :)
puts("FATAL ERROR: Something terrible happened. Unable to Execute SHELL!");
while(1);// hang
diff --git a/userspace/snake.c b/userspace/snake.c
index 7deaa6c..4eb5b5e 100644
--- a/userspace/snake.c
+++ b/userspace/snake.c
@@ -1,8 +1,22 @@
#include <stdio.h>
+int data4[100];
+
+int data1=1;
+int data2=2;
+int data3=3;
+
int main()
{
- printf("Hello I am FoolSnake 0.1\n");
+ printf("Hello I am FoolSnake 0.1\n some data test: %i %i %i", data1,data2,data3 );
+
+ puts("+++");
+ for(int i=0;i<100;i++)
+ {
+ if(data4[i]!=0)printf("WOW");
+ }
+ puts("+++");
+
printf("setvbuf returned %i\n",setvbuf(stdin,NULL,_IONBF,0));
fool_tune(1,0,0); // activate gaming mode
diff --git a/userspace/sys/Makefile b/userspace/sys/Makefile
index cdcd3b7..2e71714 100644
--- a/userspace/sys/Makefile
+++ b/userspace/sys/Makefile
@@ -17,7 +17,6 @@ crt0.o: crt0.S
crt_install: crt0.o
cp crt0.o $(SYSROOT)/usr/lib/
-
header_install:
cp termios.h $(SYSROOT)/usr/include/sys/
diff --git a/userspace/sys/crt0.S b/userspace/sys/crt0.S
index 025c21b..d09f8ca 100644
--- a/userspace/sys/crt0.S
+++ b/userspace/sys/crt0.S
@@ -5,6 +5,9 @@ _start:
pop %eax
mov %eax, environ
+pop %eax
+#mov %eax, _impure_ptr
+
call main
push environ
diff --git a/userspace/sys/crt0.o b/userspace/sys/crt0.o
index db292b0..1b71404 100644
--- a/userspace/sys/crt0.o
+++ b/userspace/sys/crt0.o
Binary files differ
diff --git a/userspace/sys/libfool.a b/userspace/sys/libfool.a
index 81a4f16..0823595 100644
--- a/userspace/sys/libfool.a
+++ b/userspace/sys/libfool.a
Binary files differ
diff --git a/userspace/sys/sys.c b/userspace/sys/sys.c
index adf6ff9..7639307 100644
--- a/userspace/sys/sys.c
+++ b/userspace/sys/sys.c
@@ -169,3 +169,13 @@ char *getlogin(void)
return NULL;
}
+int gtty()
+{
+ return -1;
+}
+
+int stty()
+{
+ return -1;
+}
+
diff --git a/userspace/sys/sys.o b/userspace/sys/sys.o
index d04089e..dc5a2e3 100644
--- a/userspace/sys/sys.o
+++ b/userspace/sys/sys.o
Binary files differ
diff --git a/userspace/sys/syscalls.c b/userspace/sys/syscalls.c
index 4b29451..c3ff909 100644
--- a/userspace/sys/syscalls.c
+++ b/userspace/sys/syscalls.c
@@ -1,6 +1,7 @@
#include "kernel/syscalls.h"
-char **environ;
+extern char **environ;
+//struct _reent *_impure_ptr;
// generic syscall interface!
int syscall(int call, int p1, int p2, int p3)
diff --git a/userspace/sys/syscalls.o b/userspace/sys/syscalls.o
index f8fd94b..a0a4265 100644
--- a/userspace/sys/syscalls.o
+++ b/userspace/sys/syscalls.o
Binary files differ
diff --git a/userspace/sys/termios.h b/userspace/sys/termios.h
index ff1e838..b6625be 100644
--- a/userspace/sys/termios.h
+++ b/userspace/sys/termios.h
@@ -1,2 +1,20 @@
typedef uint32_t speed_t;
typedef uint32_t DIR;
+
+#define B0 0000000 /* hang up */
+#define B50 0000001
+#define B75 0000002
+#define B110 0000003
+#define B134 0000004
+#define B150 0000005
+#define B200 0000006
+#define B300 0000007
+#define B600 0000010
+#define B1200 0000011
+#define B1800 0000012
+#define B2400 0000013
+#define B4800 0000014
+#define B9600 0000015
+#define B19200 0000016
+#define B38400 0000017
+