summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichal Idziorek <m.i@gmx.at>2014-12-01 00:03:04 +0100
committerMichal Idziorek <m.i@gmx.at>2014-12-01 00:03:04 +0100
commit0ec5b4d78c0fa1e256577f22e4265fd8a9e12197 (patch)
treebf4b934adcbdd8ef21a194e845f629a5fbfdab60
parentb875bc86aac2c9a733ddb9b3db4ead94d2c4c053 (diff)
Paging between 2 'tasks' loaded from ELF files.
Both files are loaded at: 0x08048000 virutal!
-rw-r--r--README.md2
-rw-r--r--asm/int_clock_handler.asm4
-rw-r--r--kernel/config.h2
-rw-r--r--kernel/kernel.c21
-rw-r--r--kernel/syscalls.c5
-rw-r--r--kernel/task.c41
-rw-r--r--kernel/vmem.c90
-rw-r--r--kernel/x86.c5
-rw-r--r--userspace/Makefile4
-rw-r--r--userspace/task1.c11
-rw-r--r--userspace/task2.c11
-rw-r--r--video/console.c5
12 files changed, 98 insertions, 103 deletions
diff --git a/README.md b/README.md
index e475e17..14e87c6 100644
--- a/README.md
+++ b/README.md
@@ -84,6 +84,8 @@ Todos
* Begin to worry about reentrancy of clib!
* Support some TTY standard
* Real User space
+* /dev/console
+* /dev/kb
* USB driver
* E1000 driver
diff --git a/asm/int_clock_handler.asm b/asm/int_clock_handler.asm
index 7e55067..bcd45da 100644
--- a/asm/int_clock_handler.asm
+++ b/asm/int_clock_handler.asm
@@ -19,7 +19,9 @@ int_clock_handler:
pusha ;Push all standard registers
- push esp ;Push pointer to all the stuff we just pushed
+ mov eax, esp
+ mov esp,0x1000
+ push eax ;Push pointer to all the stuff we just pushed
call task_switch_next ;Call C code
;pop ebx
diff --git a/kernel/config.h b/kernel/config.h
index 4238578..fb68dec 100644
--- a/kernel/config.h
+++ b/kernel/config.h
@@ -8,7 +8,7 @@
#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_CONSOLE // otherwise VESA will be used!
#define MEM_PRINT_MEMORYMAP
#define LOG_BUF_SIZE 4069
diff --git a/kernel/kernel.c b/kernel/kernel.c
index 72af85d..5e52a68 100644
--- a/kernel/kernel.c
+++ b/kernel/kernel.c
@@ -83,18 +83,6 @@ void kernel_main(uint32_t initial_stack, int mp)
//
int_init(0x08);
- vmem_set_dir(vmem_new_space_dir());
-
-
- while(1);
-
-
-/* char *mem=0x88047000;
- *mem='x';
-
- while(1);
- */
-
//
// Gather Info about other processors. (APs)
// ACPI or MP
@@ -109,16 +97,17 @@ void kernel_main(uint32_t initial_stack, int mp)
panic(FOOLOS_MODULE_NAME,"ACPI and MP search failed! I do not want to continue!");
*/
-
-// task_init();
-// while(1);
+ task_init();
+ while(1);
// load and run foolshell
// we will come back into the kernel only on interrupts...
-
+/*
+
static char *argv[]={"/bin/foolshell",NULL};
static char *env[]={"PATH=/bin","PWD=/home/miguel","PS1=$ ",NULL};
syscall_execve("/bin/foolshell",argv,env);
+ */
//
diff --git a/kernel/syscalls.c b/kernel/syscalls.c
index 0f06479..f328248 100644
--- a/kernel/syscalls.c
+++ b/kernel/syscalls.c
@@ -96,6 +96,7 @@ int syscall_lseek(int file,int ptr,int dir)
int syscall_write(int file, char *buf, int len)
{
+ //x86_int_disable();
#ifdef LOG_SYSCALLS
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"write(file=%d, buf=0x%08X, len=%d)", file,buf,len);
#endif
@@ -107,6 +108,7 @@ int syscall_write(int file, char *buf, int len)
{
console_put_char_green(buf[i]);
}
+ //x86_int_enable();
return len;
}
@@ -189,6 +191,7 @@ int syscall_fork()
int syscall_execve(char *name, char **argv, char **env)
{
+ //x86_int_disable();
// watchout this is called with esp in virtual memory of running process!
#ifdef LOG_SYSCALLS
@@ -308,6 +311,8 @@ int syscall_execve(char *name, char **argv, char **env)
// push addr and return to it
asm("push %0"::"r"(elf->e_entry));
+
+// x86_int_enable();
asm("ret");
// this is never reached!
diff --git a/kernel/task.c b/kernel/task.c
index a7f5bc2..c9554b5 100644
--- a/kernel/task.c
+++ b/kernel/task.c
@@ -30,9 +30,14 @@ static volatile struct task_list_struct
void task_create(int pid,void(*thread)())
{
+ task_list[pid].vmem=vmem_new_space_dir();
+ if(pid==0)x86_set_pdbr(0x0D08000);
+ if(pid==1)x86_set_pdbr(0x150E000);
+
unsigned int *stack;
- task_list[pid].esp = pmmngr_alloc_block();
+
+ task_list[pid].esp = 0x8248000-4095;
stack = (unsigned int*)task_list[pid].esp+4095; //This makes a pointer to the stack for us
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"new task: stack: 0x%08X thread: 0x%08X", stack, thread);
@@ -59,10 +64,13 @@ void task_create(int pid,void(*thread)())
*--stack = 0x10; //FS
*--stack = 0x10; //GS
*/
-
+
+
task_list[pid].esp = (uint32_t)stack; //Update the stack pointer
task_list[pid].active=true;
+ x86_set_pdbr(0x0502000);
+
};
// this gets called by our clock interrupt regularly!
@@ -79,8 +87,12 @@ uint32_t task_switch_next(uint32_t oldesp)
if(task_list[pid].active)
{
- // log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"switch from %d to pid: %d (0x%08X)", current_task,pid,task_list[pid].esp);
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"switch from %d to pid: %d (0x%08X) vmem: %d ", current_task,pid,task_list[pid].esp,task_list[pid].vmem);
current_task=pid;
+
+ if(pid==0)x86_set_pdbr(0x0D08000);
+ if(pid==1)x86_set_pdbr(0x150E000);
+
return task_list[pid].esp;
}
@@ -94,6 +106,14 @@ uint32_t task_switch_next(uint32_t oldesp)
// task testing //
volatile void test1()
{
+
+
+
+ static char *argv[]={"/bin/foolshell",NULL};
+ static char *env[]={"PATH=/bin","PWD=/home/miguel","PS1=$ ",NULL};
+ syscall_execve("/bin/task1",argv,env);
+
+
while(1)
{
syscall_write(1,">",1);
@@ -102,9 +122,16 @@ volatile void test1()
volatile void test2()
{
+
+ static char *argv[]={"/bin/foolshell",NULL};
+ static char *env[]={"PATH=/bin","PWD=/home/miguel","PS1=$ ",NULL};
+ syscall_execve("/bin/task2",argv,env);
+
+
+
while(1)
{
- for(int i='a';i<='z';i++)
+ for(int i='a';i<'z';i++)
{
syscall_write(1,&i,1);
}
@@ -121,9 +148,9 @@ volatile void test3()
}
void task_init()
{
- task_create(0,test1);
- task_create(1,test2);
- task_create(2,test3);
+ task_create(0,test2);
+ task_create(1,test1);
+// task_create(2,test3);
current_task=-1;
}
diff --git a/kernel/vmem.c b/kernel/vmem.c
index 3d62e97..3079733 100644
--- a/kernel/vmem.c
+++ b/kernel/vmem.c
@@ -206,7 +206,9 @@ pt_entry* vmmngr_ptable_lookup_entry (ptable* p, virtual_addr addr)
return 0;
}
+
// TODO !? http://www.brokenthorn.com/Resources/OSDev18.html
+/*
void vmmngr_map_page (void* phys, void* virt)
{
@@ -245,13 +247,12 @@ uint32_t vmem_alloc_block_at(uint32_t virt_addr)
return phys_addr;
}
+*/
-
-void vmem_init()
+int vmem_new_space_dir()
{
- //log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"init paging (vesa base: 0x%08x)",vesa_physbase);
- log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"init paging");
-
+ x86_paging_disable();
+
pdirectory* dir = (pdirectory*) pmmngr_alloc_block ();
if (!dir)panic(FOOLOS_MODULE_NAME,"unable to alloc pdirectory");
log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"pdirectory: 0x%X",dir);
@@ -296,11 +297,12 @@ void vmem_init()
// programm space (for init)
virt_addr=0x8048000;
- for(int j=0;j<5;j++)
+ for(int j=0;j<2;j++)
{
ptable* table = (ptable*) pmmngr_alloc_block ();
if (!table)panic(FOOLOS_MODULE_NAME,"unable to alloc table");
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"alloc table: %08X",table);
for (int i=0, virt=virt_addr; i<1024; i++, virt+=4096)
{
@@ -329,86 +331,34 @@ void vmem_init()
}
- page_dirs[last_page_dir++]=dir;
-
-
- x86_set_pdbr(dir);
- log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"enabling paging...");
- x86_paging_enable();
+ page_dirs[last_page_dir]=dir;
+ if(last_page_dir!=0)x86_paging_enable();
+ return last_page_dir++;
}
void vmem_set_dir(int dir)
{
- log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"set pagedir to %d",dir);
+ x86_paging_disable();
x86_set_pdbr(page_dirs[dir]);
+ // log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"set pagedir to %d (0x%08X)",dir,page_dirs[dir]);
current_dir=dir;
+ x86_paging_enable();
}
-int vmem_new_space_dir()
-{
- uint32_t vaddr=vmem_alloc_block_at(0xF0000000);
- return 0;
- pdirectory* dir = vaddr;
- if (!dir)panic(FOOLOS_MODULE_NAME,"unable to alloc pdirectory");
-
- for(int i=0;i<1024;i++)dir->m_entries [i]=0;
-
- // first clone the kernel space!
- for(int i=0;i<3;i++)
- {
- dir->m_entries[i]=page_dirs[0]->m_entries[i];
+void vmem_init()
+{
+ //log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"init paging (vesa base: 0x%08x)",vesa_physbase);
+ log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"init paging");
+ vmem_set_dir(vmem_new_space_dir());
- }
- return 0;
-
- // programm space starts at 0x8048000 and let us reserve 4mb per programm!
- // lets start to build the directory for one single programm
- // uint32_t phys_addr=0;
- /*
- uint32_t virt_addr=0x8048000;
- uint32_t phys_addr;
- for(int j=0;j<5;j++)
- {
-
- ptable* table = (ptable*) pmmngr_alloc_block ();
- if (!table)panic(FOOLOS_MODULE_NAME,"unable to alloc table");
-
- for (int i=0, virt=virt_addr; i<1024; i++, virt+=4096)
- {
- phys_addr=pmmngr_alloc_block(); // get free space from the memory manager
- memcpy(phys_addr,virt_addr,4096); // duplicate current contents of this space!
- //
- if (!phys_addr)panic(FOOLOS_MODULE_NAME,"unable to alloc spce for frame");
-
- int frame=phys_addr;
+}
- //! create a new page
- pt_entry page=0;
- pt_entry_add_attrib (&page, I86_PTE_PRESENT);
- pt_entry_add_attrib (&page, I86_PTE_WRITABLE);
- pt_entry_set_frame (&page, frame);
- //! ...and add it to the page table
- table->m_entries [PAGE_TABLE_INDEX (virt) ] = page;
- }
-
- pd_entry* entry = &dir->m_entries [PAGE_DIRECTORY_INDEX (virt_addr) ];
- *entry=0;
- pd_entry_add_attrib (entry, I86_PDE_PRESENT);
- pd_entry_add_attrib (entry, I86_PDE_WRITABLE);
- pd_entry_set_frame (entry, (physical_addr)table);
-
- virt_addr+=1024*4096;
- }
- */
- page_dirs[last_page_dir]=dir;
- return last_page_dir++;
-}
diff --git a/kernel/x86.c b/kernel/x86.c
index 81b0e20..65552cd 100644
--- a/kernel/x86.c
+++ b/kernel/x86.c
@@ -10,13 +10,10 @@
//
-void sleep(int i)
+volatile void sleep(int i)
{
uint64_t clock=timer_get_ticks();
-
-
while(clock+i>timer_get_ticks());
-
}
diff --git a/userspace/Makefile b/userspace/Makefile
index 5d94a41..53dab5f 100644
--- a/userspace/Makefile
+++ b/userspace/Makefile
@@ -7,7 +7,7 @@ CFLAGS+=-w
CFLAGS+=-std=gnu11
CFLAGS+=-O3
-PROGS=foolshell ls simple brainfuck add checker clear
+PROGS=foolshell ls simple brainfuck add checker clear task1 task2
ext2.img: $(PROGS)
dd if=/dev/zero of=ext2.img bs=512 count=5000
@@ -32,6 +32,8 @@ foolshell: foolshell.o
simple: simple.o
add: add.o
checker: checker.o
+task1: task1.o
+task2: task2.o
clean:
-rm *.o $(PROGS) ext2.img
diff --git a/userspace/task1.c b/userspace/task1.c
new file mode 100644
index 0000000..ed686c4
--- /dev/null
+++ b/userspace/task1.c
@@ -0,0 +1,11 @@
+int main(int argc, char **argv)
+{
+ while(1)
+ {
+ write(1,"task 1 \n",8);
+ }
+
+ return 0;
+}
+
+
diff --git a/userspace/task2.c b/userspace/task2.c
new file mode 100644
index 0000000..f1164d7
--- /dev/null
+++ b/userspace/task2.c
@@ -0,0 +1,11 @@
+int main(int argc, char **argv)
+{
+ while(1)
+ {
+ write(1,"task 2 \n",8);
+ }
+
+ return 0;
+}
+
+
diff --git a/video/console.c b/video/console.c
index 4a04cf1..6eeaf0b 100644
--- a/video/console.c
+++ b/video/console.c
@@ -111,7 +111,7 @@ void scr_nextline()
void scr_put_char(char ch,char col)
{
- lock_spin(6);
+ // lock_spin(6);
if(ch=='\n')scr_nextline();
else if(posx<SCR_WIDTH)
@@ -124,8 +124,7 @@ void scr_put_char(char ch,char col)
if(posx>=SCR_WIDTH)scr_nextline();
#endif
- lock_release(6);
-
+ //lock_release(6);
}
/*