summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--asm/int_syscall_handler.asm8
-rw-r--r--boot1/disk_load_16.asm3
-rw-r--r--kernel/config.h2
-rw-r--r--kernel/syscalls.c46
-rw-r--r--kernel/syscalls.h1
-rw-r--r--userspace/Makefile8
-rw-r--r--userspace/add.c39
-rw-r--r--userspace/crt0.S14
-rw-r--r--userspace/linker.ld21
-rw-r--r--userspace/simple.c3
-rw-r--r--userspace/syscalls.c2
11 files changed, 96 insertions, 51 deletions
diff --git a/asm/int_syscall_handler.asm b/asm/int_syscall_handler.asm
index 23b9f84..a2236fe 100644
--- a/asm/int_syscall_handler.asm
+++ b/asm/int_syscall_handler.asm
@@ -1,5 +1,6 @@
global int_syscall_handler
+[extern syscall_exit]
[extern syscall_write]
[extern syscall_read]
[extern syscall_readdir]
@@ -20,6 +21,9 @@ int_syscall_handler:
push ecx
push edx
+ cmp eax, 60
+ je call_exit
+
cmp eax, 61
je call_write
@@ -104,6 +108,10 @@ call_sbrk:
call syscall_sbrk
jmp done
+call_exit:
+ call syscall_exit
+ jmp done
+
;;; THIS CALLS NEED REENABLE INTERRUPTS BEFORE calling workers
call_read:
diff --git a/boot1/disk_load_16.asm b/boot1/disk_load_16.asm
index 76102ad..6d1e4b3 100644
--- a/boot1/disk_load_16.asm
+++ b/boot1/disk_load_16.asm
@@ -8,7 +8,7 @@ STR_LBA:
db "LBA Support Detected",0
STR_CHS:
- db "CHS BROKEN SORRY(?)",0
+ db "No CHS Support!)",0
STR_ERROR:
db "Disk Read Error",0
@@ -50,6 +50,7 @@ disk_load_chs:
mov bx, STR_CHS
call print_string
call print_nextline
+ jmp $
mov bx,0 ;target es:bx
mov es,bx
diff --git a/kernel/config.h b/kernel/config.h
index ef0fa71..e48c63c 100644
--- a/kernel/config.h
+++ b/kernel/config.h
@@ -6,7 +6,7 @@
//#define FOOLOS_COMPILE_FLOPPY // compile floppy drivers
#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_CONSOLE // otherwise VESA will be used!
#define MEM_PRINT_MEMORYMAP
#define LOG_BUF_SIZE 4069
diff --git a/kernel/syscalls.c b/kernel/syscalls.c
index b0a4ba1..d2efbc8 100644
--- a/kernel/syscalls.c
+++ b/kernel/syscalls.c
@@ -9,8 +9,6 @@
#include <sys/stat.h>
-static int preread;
-static int alloc=0xa00000; // TODO: implement properly sbrk!!!
int syscall_write(int file, char *buf, int len)
{
@@ -74,6 +72,13 @@ int syscall_execve(char *name, char **argv, char **env)
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"execve (name=0x%08X, argvs=0x%08X, env=0x%08X)", name,argv,env);
#endif
+ // lets first clean some area for loading our prog!
+ // we need this to zero-initalize bss
+ for(uint32_t *addr=0x800000; addr<=0xb00000; addr++)
+ {
+ *addr=0;
+ }
+
ext2_inode_content(EXT2_RAM_ADDRESS,name,0x800000,0x100000);
@@ -84,10 +89,10 @@ int syscall_execve(char *name, char **argv, char **env)
asm("ret");
}
-int syscall_open(char *name, int flags, int len)
+int syscall_open(char *name, int flags, int mode)
{
#ifdef LOG_SYSCALLS
- log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"open (name=0x%08X(\"%s\"), flags=%d, len=%d)",name, name,flags,len);
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"open (name=0x%08X(\"%s\"), flags=%d, mode=%d)",name, name,flags,mode);
#endif
return 99;
@@ -130,17 +135,35 @@ int syscall_lseek(int file,int ptr,int dir)
#ifdef LOG_SYSCALLS
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"lseek (file=%d, ptr=%d, dir=%d)", file,ptr,dir);
#endif
-
+/*
if(dir==0)preread=ptr;
else{ while(1);}
- return preread;
+*/
+ return 0;
+
}
uint32_t syscall_sbrk(int incr, int none1, int none2)
{
- if(incr==0)alloc=0xa00000; // TODO: implement properly sbrk!!!
+ static uint32_t alloc;
+
+ // fool-os-convention to set bss_end:
+ if(incr==0)
+ {
+ alloc=0;
+ return 0;
+ }
+ if(alloc==0)
+ {
+ #ifdef LOG_SYSCALLS
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"sbrk RESET to 0x%08X", incr);
+ #endif
+
+ alloc=incr;
+ return alloc;
+ }
- int oldalloc=alloc;
+ uint32_t oldalloc=alloc;
alloc+=incr;
#ifdef LOG_SYSCALLS
@@ -171,3 +194,10 @@ uint32_t syscall_sbrk(int incr, int none1, int none2)
*/
}
+int syscall_exit(int ret, int none1, int none2)
+{
+ #ifdef LOG_SYSCALLS
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"exit (ret=%d)", ret);
+ #endif
+ syscall_execve(15,0,0); // start shell
+}
diff --git a/kernel/syscalls.h b/kernel/syscalls.h
index 63aafc4..5fb62db 100644
--- a/kernel/syscalls.h
+++ b/kernel/syscalls.h
@@ -1,5 +1,6 @@
#include "fs/fs.h"
+#define SYSCALL_EXIT 60
#define SYSCALL_WRITE 61
#define SYSCALL_READ 62
#define SYSCALL_READDIR 63
diff --git a/userspace/Makefile b/userspace/Makefile
index 564ffe0..18b5ded 100644
--- a/userspace/Makefile
+++ b/userspace/Makefile
@@ -26,16 +26,16 @@ ext2.img: shell simple brainfuck add
rm mnt -rf
brainfuck: brainfuck.o crt0.o
- ${CC} -T linker.ld ${LDFLAGS} $< -Wl,--oformat,binary -o brainfuck
+ ${CC} -T linker.ld ${LDFLAGS} $< -o $@
shell: foolshell.o crt0.o
- ${CC} -T linker.ld ${LDFLAGS} $< -Wl,--oformat,binary -o shell
+ ${CC} -T linker.ld ${LDFLAGS} $< -o $@
simple: simple.o crt0.o
- ${CC} -T linker.ld ${LDFLAGS} $< -Wl,--oformat,binary -o simple
+ ${CC} -T linker.ld ${LDFLAGS} $< -o $@
add: add.o crt0.o
- ${CC} -T linker.ld ${LDFLAGS} $< -Wl,--oformat,binary -o add
+ ${CC} -T linker.ld ${LDFLAGS} $< -o $@
clean:
-rm *.o *.out shell simple ext2.img brainfuck add
diff --git a/userspace/add.c b/userspace/add.c
index 8f1dc56..254ee35 100644
--- a/userspace/add.c
+++ b/userspace/add.c
@@ -6,47 +6,18 @@
int main(int argc, char **argv)
{
- sbrk(1024);
- sbrk(1024);
- sbrk(1024);
- write(1,"dupa",4);
- puts("started ADD");
+ FILE *input;
+ input=fopen("input2.txt","r"); //stdin
- while(1);
-// FILE *input;
-// input=fopen("input2.txt","r"); //stdin
-/*
int sum=0;
int i=0;
- while(1);
-
char *buf=malloc(256);
- //printf("(buf= 0x%08X)\n",buf);
-
-
-
- while(1)
- {
- char *ret=gets(buf);
- if(ret==NULL)
- {
- printf("returned NULL. ABORTING");
- break;
- }
- printf("entered %s: ",buf);
-
- //buf[strlen(buf)-1]=0; // remove \n
- //process(buf);
- }
-
-
while(1)
{
- printf("enter numer %i: ",i+1);
+ printf("enter numer (or 'exit' to finish) %i: ",i+1);
fgets(buf,255,input);
- printf("entered %s: ",buf);
if(buf[1]=='x')break;
@@ -54,10 +25,10 @@ int main(int argc, char **argv)
sum+=atoi(buf);
}
+ printf("sum = %i \n",sum);
printf("avg = %i \n\n",sum/i);
-*/
- execve(15,0,0);
+ return 0;
}
diff --git a/userspace/crt0.S b/userspace/crt0.S
index 9f7dab1..e3bfa3b 100644
--- a/userspace/crt0.S
+++ b/userspace/crt0.S
@@ -1,9 +1,23 @@
.global _start
+
.extern main
.extern exit
+
_start:
+
+push $0
+call sbrk
+
+push $[_BSS_END_]
+call sbrk
+
call main
+
+
+push %eax
call _exit
+
+# this should never be reached anyway!
.wait:
hlt
jmp .wait
diff --git a/userspace/linker.ld b/userspace/linker.ld
index 9fe0ac2..4eee8eb 100644
--- a/userspace/linker.ld
+++ b/userspace/linker.ld
@@ -1,4 +1,25 @@
+OUTPUT_FORMAT(binary)
+
SECTIONS
{
. = 0x800000;
+
+ .text : ALIGN(0x1000) {
+ _TEXT_START_ = .;
+ *(.text)
+ _TEXT_END_ = .;
+ }
+
+ .data : ALIGN(0x1000) {
+ _DATA_START_ = .;
+ *(.data)
+ _DATA_END_ = .;
+ }
+
+ .bss : ALIGN(0x1000) {
+ _BSS_START_ = .;
+ *(.bss)
+ _BSS_END_ = .;
+ }
+
}
diff --git a/userspace/simple.c b/userspace/simple.c
index e3bca65..6dcf766 100644
--- a/userspace/simple.c
+++ b/userspace/simple.c
@@ -11,8 +11,7 @@ int main(int argc, char **argv)
}
- // replace with foolshell after finishing!
- execve(15,0,0);
+ return 0;
}
diff --git a/userspace/syscalls.c b/userspace/syscalls.c
index fd9b5ba..8c8bfc9 100644
--- a/userspace/syscalls.c
+++ b/userspace/syscalls.c
@@ -12,7 +12,7 @@ char **environ={__env1,__env2,__env3};
void _exit(int ret)
{
- while(1);
+ return syscall(SYSCALL_EXIT,ret,0,0);
}
// generic syscall interface!