summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md3
-rw-r--r--grubiso/boot/grub/grub.cfg2
-rw-r--r--kernel/kernel.h8
-rw-r--r--kernel/kmalloc.c2
-rw-r--r--kernel/log.h2
-rw-r--r--kernel/scheduler.c46
-rw-r--r--kernel/smp.c3
-rw-r--r--kernel/syscalls.c19
-rw-r--r--kernel/syscalls.h7
-rw-r--r--kernel/vmem.c9
-rw-r--r--newlib/crt0.s21
-rw-r--r--userspace/init.c17
12 files changed, 77 insertions, 62 deletions
diff --git a/README.md b/README.md
index f3fa4fd..ee84a1e 100644
--- a/README.md
+++ b/README.md
@@ -88,7 +88,7 @@ Todos
* Cleanup Virtual Memory Manager / Flush TLB (?)
* Mouse & KB processing in seperate task.
-* Kernel Stuff Reentrancy & Newlib Reeentrancy Struct
+* Kernel Stuff Reent?
* Posix getdents and cleanup syscalls
* Writing to ext2 RAM-image
* Mutexes
@@ -98,6 +98,7 @@ Todos
* Ethernet driver E1000 / NS2000 & Networking stack (ipxe network drivers?)
* Unit Testing
+
* GUI / Window Manager (update\_rect, etc..)
* Porting (ncurses, gcc, binutils, vim, apache...)
diff --git a/grubiso/boot/grub/grub.cfg b/grubiso/boot/grub/grub.cfg
index 9c78bfb..08f1fe1 100644
--- a/grubiso/boot/grub/grub.cfg
+++ b/grubiso/boot/grub/grub.cfg
@@ -1,4 +1,4 @@
-set timeout=1 //seconds
+set timeout=0 //seconds
menuentry "FoolOS (640x480x32)" {
multiboot /boot/foolos.bin
diff --git a/kernel/kernel.h b/kernel/kernel.h
index df8432a..9fc9601 100644
--- a/kernel/kernel.h
+++ b/kernel/kernel.h
@@ -47,6 +47,7 @@ REFERENCES
// We leave some space around them
// 1 page 0x1000 bytes
// 8192 pages = 0x2000000 bytes
+// minimal space between user and kernel pages 1024 pages!
#define VMEM_KERNEL 0x00000000 // 8192 pages (32megs) / identity mapped
#define VMEM_KERNEL_END 0x02000000
@@ -62,8 +63,11 @@ REFERENCES
#define VMEM_CPU_PRIVATE 0xF000A000 // 4 pages / per cpu
#define VMEM_CPU_STACK_PAGES 4 // 4 pages / per thread
-#define VMEM_CPU_STACK_TOP 0xF4000000 // 4 pages / per cpu
-#define VMEM_COPY_PAGE 0xF5000000 // 1 page / temporery map-in tables for copying
+#define VMEM_CPU_STACK_TOP 0xF3000000 // 4 pages / per cpu
+
+#define VMEM_COPY_PAGE 0xF4000000 // 1 page / temporery map-in tables for copying
+//TODO: do not hardcode in crt0.s
+#define VMEM_USER_NEWLIB 0xF5000000 // 1 page / newlib reentrancy struct. 1 per thread
#define VMEM_FRAMEBUFFER 0xF6000000 // 8192 pages (32megs) / identity mapped
#define VMEM_EXT2_RAMIMAGE 0xF8000000 // 8192 pages (32megs) / identity mapped
diff --git a/kernel/kmalloc.c b/kernel/kmalloc.c
index f4242cc..eb35a44 100644
--- a/kernel/kmalloc.c
+++ b/kernel/kmalloc.c
@@ -49,7 +49,7 @@ uint32_t kballoc(uint32_t size)
kpanic("kballoc ran out of memory! maybe increase KMALLOC_MEM_SIZE in kmalloc.c?");
}
- klog("(%d) : 0x%08X (~%dKB left)",size,old,(KMALLOC_MEM_SIZE-next+first)/1024);
+// klog("(%d) : 0x%08X (~%dKB left)",size,old,(KMALLOC_MEM_SIZE-next+first)/1024);
return old;
}
diff --git a/kernel/log.h b/kernel/log.h
index e46a7b2..ba92788 100644
--- a/kernel/log.h
+++ b/kernel/log.h
@@ -17,7 +17,7 @@ void log(bool color,char *module_name, int prio, char *format_string, ...);
#ifndef FOOLOS_LOG_OFF
#define kpanic(...) {log(FOOLOS_LOG_COLOR,__FILE__,0," \033[41;37m [KERNEL PANIC] \033[37;40m " __VA_ARGS__ ); while(1);}
#define klog(...) log(FOOLOS_LOG_COLOR,__FILE__ ":" S2(__LINE__), 10, __VA_ARGS__)
-#define fixme(...) log(FOOLOS_LOG_COLOR,__FILE__ ":" S2(__LINE__) "[FIXME/TODO]:" , 10, __VA_ARGS__)
+#define fixme(...) log(FOOLOS_LOG_COLOR,__FILE__ ":" S2(__LINE__) , 10, " \033[46;37m [FIXME] \033[37;40m "__VA_ARGS__)
#endif
#ifdef FOOLOS_LOG_OFF
diff --git a/kernel/scheduler.c b/kernel/scheduler.c
index 6c7df28..985b3bf 100644
--- a/kernel/scheduler.c
+++ b/kernel/scheduler.c
@@ -102,10 +102,9 @@ volatile uint32_t scheduler_run(uint32_t oldesp,uint32_t force_pid)
if(task_list[cpu][idx].active && !task_list[cpu][idx].wait) // find active non-blocked task
{
- //TODO: do NOT do this!
- //klog("schedule %d->%d in cpu %d",current_task[cpu],idx,cpu );
+ //TODO: do NOT do this! deadlock imminent!
+ //if(cpu==0)klog("schedule %d->%d on cpu %d",current_task[cpu],idx,cpu );
current_task[cpu]=idx;
-
install_tss(cpu,task_list[cpu][idx].esp0);
x86_set_page_directory(task_list[cpu][idx].vmem);
return task_list[cpu][idx].esp;
@@ -138,12 +137,9 @@ void scheduler_func()
uint32_t alloc;
uint32_t entry_global=load_elf(BIN_INIT,&alloc);
task_set_brk(alloc);
- klog("breakpoint: 0x%08x",alloc);
asm_usermode(entry_global);
- while(1);
+ while(1);
}
-// else syscall_write(1, "x",1); // stdout
-
}
}
@@ -174,7 +170,7 @@ volatile int add_task(uint32_t parent,uint32_t vmem)
uint32_t *source=(uint32_t *)task_list[cpu][parent].esp;
uint32_t *dst=(uint32_t *)task_list[cpu][i].esp;
- for(int x=0;x<100;x++) //TODO: better copy this page too instead of stack
+ for(int x=0;x<100;x++) //TODO: maybe better copy this page too instead of stack
{
*dst=*source;
dst++;
@@ -189,7 +185,6 @@ volatile int add_task(uint32_t parent,uint32_t vmem)
return i;
}
}
-
kpanic("out of task slots!");
}
@@ -206,8 +201,6 @@ void task_syscall_worker()
uint32_t cpu=smp_get(SMP_APIC_ID);
while(1)
{
- //klog("checking if any pending syscalls.");
-
bool nowork=true;
for(int i=0;i<MAX_TASKS;i++)
{
@@ -215,8 +208,8 @@ void task_syscall_worker()
{
uint32_t syscall=task_list[cpu][i].eax;
klog("task %d waiting on syscall %d/%s. processing...",i,syscall,syscall_get_name(syscall));
- task_list[cpu][2].vmem=task_list[cpu][i].vmem; // switch syscall worker to pagedir of calling userprog
- x86_set_page_directory(task_list[cpu][2].vmem);
+ task_list[cpu][0].vmem=task_list[cpu][i].vmem; // switch syscall worker to pagedir of calling userprog
+ x86_set_page_directory(task_list[cpu][0].vmem);
if(task_list[cpu][i].eax==SYSCALL_WAIT)
{
@@ -225,12 +218,12 @@ void task_syscall_worker()
if(task_list[cpu][i].eax==SYSCALL_READ)
{
- uint32_t ok= chk_syscall_read(
- task_list[cpu][i].edx,
- task_list[cpu][i].ecx,
- task_list[cpu][i].ebx
- );
- if(!ok)continue;
+ uint32_t ok= chk_syscall_read(
+ task_list[cpu][i].edx,
+ task_list[cpu][i].ecx,
+ task_list[cpu][i].ebx
+ );
+ if(!ok)continue;
}
nowork=false;
@@ -249,9 +242,9 @@ void task_syscall_worker()
}
}
- //task_list[2].wait=true;
- if (nowork)__asm__("hlt");
- else __asm__("int $0x81"); // wake scheduler!
+ //task_list[cpu][0].wait=true;
+ //if (nowork)__asm__("hlt");
+ __asm__("int $0x81"); // wake scheduler!
}
}
@@ -264,8 +257,7 @@ volatile uint32_t task_syscall(uint32_t eax,uint32_t ebx, uint32_t ecx, uint32_t
task_list[cpu][current_task[cpu]].ebx=ebx;
task_list[cpu][current_task[cpu]].ecx=ecx;
task_list[cpu][current_task[cpu]].edx=edx;
-
- task_list[cpu][2].wait=false;
+ task_list[cpu][0].wait=false;
return 1;
}
@@ -294,16 +286,14 @@ volatile uint32_t task_wait(uint32_t pid)
volatile uint32_t task_fork(uint32_t pid)
{
- uint32_t cpu=smp_get(SMP_APIC_ID);
-//TODO: what will happen if we get rescheduled!?!?!
+ uint32_t cpu=smp_get(SMP_APIC_ID);
int ret=add_task(pid,vmem_new_space_dir(task_list[cpu][pid].vmem,false));
klog("[%d] forked -> [%d] (free blocks remaining: %d )", pid, ret,0);
return ret;
}
volatile uint32_t task_clone(uint32_t pid)
{
- uint32_t cpu=smp_get(SMP_APIC_ID);
-//TODO: what will happen if we get rescheduled!?!?!
+ uint32_t cpu=smp_get(SMP_APIC_ID);
int ret=add_task(pid,vmem_new_space_dir(task_list[cpu][pid].vmem,true));
klog("[%d] cloned -> [%d] (free blocks remaining: %d )", pid, ret,0);
return ret;
diff --git a/kernel/smp.c b/kernel/smp.c
index cd9f5ad..8eb8dad 100644
--- a/kernel/smp.c
+++ b/kernel/smp.c
@@ -82,6 +82,7 @@ static void run_smp()
// this will start all our application processors!
void smp_start_aps(acpi_information *pros)
{
+ /*
for(int i=0;i<pros->processors;i++)
{
if(pros->boot==i)continue; // skib bsp
@@ -90,6 +91,6 @@ void smp_start_aps(acpi_information *pros)
klog("starting cpu %d (destination apic id: 0x%x) ",i,dest);
apic_sipi(dest,0x7); // start on 0x7000
}
-
+*/
smp_main_generic(true);
}
diff --git a/kernel/syscalls.c b/kernel/syscalls.c
index 71feeb7..f092a75 100644
--- a/kernel/syscalls.c
+++ b/kernel/syscalls.c
@@ -219,24 +219,25 @@ int copy_args(char **in, char **out)
int syscall_execve(char *name, char **argv, char **env,int pid)
{
-
+
+ //TODO copy environment to target pages somehow//
int arg_count=0;
while(argv[arg_count]!=NULL)arg_count++;
- char **argv1=0x08000000;
+ char **argv1=VMEM_USER_ENV;
if(argv!=NULL)
{
- copy_args(argv,argv1);
+// copy_args(argv,argv1);
}
else{
argv1=NULL;
}
- char **env1=0x08020000;
+ char **env1=VMEM_USER_ENV+1024;
if(env!=NULL)
{
- copy_args(env,env1);
+// copy_args(env,env1);
}
else{
@@ -246,14 +247,13 @@ int syscall_execve(char *name, char **argv, char **env,int pid)
uint32_t alloc;
uint32_t entry_global=load_elf(name,&alloc);
task_set_brk(alloc);
- fixme("fix brk!");
if(!entry_global)
{
return -1; // errror loading
}
- uint32_t *stack=0x08fff000;
+ uint32_t *stack=VMEM_USER_STACK_TOP-3*32;
*++stack=argv1;
*++stack=arg_count;
*++stack=env1;
@@ -263,7 +263,7 @@ int syscall_execve(char *name, char **argv, char **env,int pid)
/* try to move this to asm */
// asm volatile("jmp ."); // loop forever
//klog("returning to jump addy (0x%08X)", entry_global);
-/*
+ /*
asm volatile("mov $0x08fff000,%esp"); // set stack at high end of process image
asm volatile ("push %0" :: "r" (argv1));
@@ -352,8 +352,9 @@ int syscall_isatty(int file,int none1,int none2)
uint32_t fuckalloc=0x8500000;
// TODO: per process basis!
-uint32_t syscall_sbrk(int incr, int none1, int none2)
+uint32_t syscall_sbrk(uint32_t incr, int none1, int none2)
{
+ fixme("fake syscall_sbrk! 0x%08X",incr);
uint32_t alloc=task_get_brk();
uint32_t oldalloc=fuckalloc;
diff --git a/kernel/syscalls.h b/kernel/syscalls.h
index 9018852..8b88e6a 100644
--- a/kernel/syscalls.h
+++ b/kernel/syscalls.h
@@ -1,12 +1,14 @@
#define SYSCALL_EXIT 60
-#define SYSCALL_CLOSE 66
#define SYSCALL_EXECVE 64
#define SYSCALL_FORK 72
+
+#define SYSCALL_CLOSE 66
+#define SYSCALL_OPEN 65
+
#define SYSCALL_GETPID 78
#define SYSCALL_ISATTY 68
#define SYSCALL_LINK 82
#define SYSCALL_LSEEK 69
-#define SYSCALL_OPEN 65
#define SYSCALL_READ 62
#define SYSCALL_SBRK 70
#define SYSCALL_STAT 74
@@ -28,7 +30,6 @@ int chk_syscall_read(int file, char *buf, int len);
int syscall_open(char *name, int flags, int mode);
int syscall_write(int file, char *buf, int len);
-
// new planned syscalls for graphx
// TODO: split ncurses and our syscalls??
diff --git a/kernel/vmem.c b/kernel/vmem.c
index ade0a01..4faf93e 100644
--- a/kernel/vmem.c
+++ b/kernel/vmem.c
@@ -305,7 +305,9 @@ pdirectory* vmem_kernel_dir()
vmem_add_alloc(dir,VMEM_CPU_PRIVATE,4,false);
vmem_add_alloc(dir,VMEM_CPU_STACK_TOP-4096*VMEM_CPU_STACK_PAGES,VMEM_CPU_STACK_PAGES,false);
- vmem_add_alloc(dir,VMEM_USER_PROG,1024*4,true);
+ vmem_add_alloc(dir,VMEM_USER_PROG,1024*2,true);
+ vmem_add_alloc(dir,VMEM_USER_ENV,2,true);
+ vmem_add_alloc(dir,VMEM_USER_NEWLIB,2,true);
vmem_add_alloc(dir,VMEM_USER_STACK_TOP-4096*VMEM_USER_STACK_PAGES,VMEM_USER_STACK_PAGES,true);
return dir;
@@ -323,6 +325,8 @@ pdirectory* vmem_new_space_dir(pdirectory *copy_dir,bool stack_only)
}
vmem_add_alloc(dir,VMEM_USER_PROG,1024*4,true);
+ vmem_add_alloc(dir,VMEM_USER_ENV,2,true);
+ vmem_add_alloc(dir,VMEM_USER_NEWLIB,2,true);
vmem_add_alloc(dir,VMEM_USER_STACK_TOP-4096*VMEM_USER_STACK_PAGES,VMEM_USER_STACK_PAGES,true);
pdirectory* mydir=x86_get_page_directory();
@@ -349,7 +353,7 @@ pdirectory* vmem_new_space_dir(pdirectory *copy_dir,bool stack_only)
if(src_pd)
{
- klog("copy virt: %x / phys: %x -> %x",virt,src_phys,dst_phys);
+ //klog("copy virt: %x / phys: %x -> %x",virt,src_phys,dst_phys);
vmem_clear_one(mydir,VMEM_COPY_PAGE);
vmem_clear_one(mydir,VMEM_COPY_PAGE+4096);
@@ -362,7 +366,6 @@ pdirectory* vmem_new_space_dir(pdirectory *copy_dir,bool stack_only)
memcpy(VMEM_COPY_PAGE+4096,VMEM_COPY_PAGE,4096);
}
-
virt+=4096;
}
}
diff --git a/newlib/crt0.s b/newlib/crt0.s
index e8f0405..ad9884f 100644
--- a/newlib/crt0.s
+++ b/newlib/crt0.s
@@ -2,10 +2,31 @@
_start:
+# copy reent to this page
+push %ebx
+push %ecx
+
+mov _impure_ptr,%eax
+mov $0xf5000000,%ebx
+copy:
+mov (%eax),%ecx
+mov %ecx,(%ebx)
+add $4, %ebx
+add $4, %eax
+cmp $0xf5001000,%ebx
+jne copy
+
+pop %ecx
+pop %ebx
+
# environment adress was passed on stack
+
+movl $0xf5000000, _impure_ptr
+
pop %eax
mov %eax, environ
+
# call main (argc and argv are on the stack)
call main
diff --git a/userspace/init.c b/userspace/init.c
index f674fcd..b27dc8d 100644
--- a/userspace/init.c
+++ b/userspace/init.c
@@ -10,7 +10,8 @@ int main(int argc, char **argv)
time_t ltime;
time(&ltime);
- printf("Current time: %s", ctime(&ltime));
+ printf("fool-init: starting...\n");
+ printf("fool-init: current time: %s", ctime(&ltime));
printf("fool-init: spawning a Fool's Shell\n");
// loop forever and spawn shells if the top-shell exits
@@ -18,28 +19,20 @@ int main(int argc, char **argv)
{
int pid=_fork();
- printf("fool-init: pid: %i\n",pid);
- while(1);
+ printf("fool-init forked / pid: %i\n",pid);
int status;
-
- if(pid==1)
- {
- printf("fool-init: pid: %i\n",pid);
- }
if(pid==0)
{
- printf("fool-init: pid: %i\n",pid);
_execve("/bin/foolshell",argv1,env1); // 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
}
// wait until our child process state changes (exits)
// and respawn SHELL
- while(1);
- _wait(&status);
+ //_wait(&status);
+ while(1)printf(".");
printf("fool-init: catched exit of process %d.\n",pid);
printf("fool-init: respawning a Fools Shell\n");