diff options
| author | Michal Idziorek <m.i@gmx.at> | 2014-12-01 21:49:22 +0100 |
|---|---|---|
| committer | Michal Idziorek <m.i@gmx.at> | 2014-12-01 21:49:22 +0100 |
| commit | d8331335ff1720ce28eba45afe1a02814b38b033 (patch) | |
| tree | f671279d258477321699d158765f576512851e3a | |
| parent | 100be313c22bd6116b1adc5eb30f5db56f4b0772 (diff) | |
finally implemented fork() syscall
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | README.md | 2 | ||||
| -rw-r--r-- | asm/int_clock_handler.asm | 44 | ||||
| -rw-r--r-- | asm/int_syscall_handler.asm | 38 | ||||
| -rw-r--r-- | bochs/bochsrc | 2 | ||||
| -rw-r--r-- | boot2/stage2.asm | 2 | ||||
| -rw-r--r-- | fs/elf.c | 64 | ||||
| -rw-r--r-- | kernel/kernel.c | 5 | ||||
| -rw-r--r-- | kernel/syscalls.c | 92 | ||||
| -rw-r--r-- | kernel/task.c | 124 | ||||
| -rw-r--r-- | kernel/vmem.c | 91 | ||||
| -rw-r--r-- | kernel/x86.c | 18 | ||||
| -rw-r--r-- | kernel/x86.h | 2 | ||||
| -rw-r--r-- | userspace/Makefile | 5 | ||||
| -rw-r--r-- | userspace/init.c | 14 | ||||
| -rw-r--r-- | video/console.c | 3 |
16 files changed, 266 insertions, 242 deletions
@@ -34,8 +34,8 @@ CFLAGS+=-w CFLAGS+=-ffreestanding CFLATS+=-Wall CFLAGS+=-Wextra +#CFLAGS+=-O3 #CFLAGS+=-O0 -CFLAGS+=-O3 #CFLAGS+=-nostdlib CFLAGS+=-std=gnu11 CFLAGS+=-I. @@ -80,7 +80,7 @@ Some might be disabled temporarily due to conflicts or regressions. Todos ----- -* Allow GRUB as alternative bootloader (multiboot spec/ grub-mkrescue) +* Implement Multiboot Spec. * Support some TTY standard * Real User space * /dev/console diff --git a/asm/int_clock_handler.asm b/asm/int_clock_handler.asm index 627e432..6301dc6 100644 --- a/asm/int_clock_handler.asm +++ b/asm/int_clock_handler.asm @@ -1,45 +1,25 @@ global int_clock_handler [extern task_switch_next] - [bits 32] -int_clock_handler: - - cli - - ;Notice there is no IRQ number or error code - we don't need them - -; inc byte [CLOCK_COUNTER] - -; cmp byte [CLOCK_COUNTER], 0x2 -; jne skip_clock - -; mov byte [CLOCK_COUNTER], 0x00 +int_clock_handler: +cli pusha ;Push all standard registers - mov eax, esp - mov esp,0x1000 ;put the stack outside of virtual memory in kernel space! - push eax ;Push pointer to all the stuff we just pushed - call task_switch_next ;Call C code - - ;pop ebx +mov eax, esp ;save current stack pointer in esp +mov esp, 0x1000 ;now put the stack outside of virtual memory in kernel space! - ;compare: - ;cmp eax,ebx - ;jne compare - - mov esp, eax ;Replace the stack with what the C code gave us +push eax ;Push pointer to all the stuff we just pushed +call task_switch_next ;Call C code +mov esp, eax ;Replace the stack with what the C code gave us -; skip_clock: - mov al, 0x20 ;Port number AND command number to Acknowledge IRQ - out 0x20, al ;Acknowledge IRQ, so we keep getting interrupts +mov al, 0x20 ;Port number AND command number to Acknowledge IRQ +out 0x20, al ;Acknowledge IRQ, so we keep getting interrupts - popa ;Put the standard registers back +popa ;Put the standard registers back +sti - ;We didn't push an error code or IRQ number, so we don't have to edit esp now - sti - - iretd ;Interrupt-Return +iretd ;Interrupt-Return diff --git a/asm/int_syscall_handler.asm b/asm/int_syscall_handler.asm index 50202d3..89f152b 100644 --- a/asm/int_syscall_handler.asm +++ b/asm/int_syscall_handler.asm @@ -1,4 +1,5 @@ global int_syscall_handler +[extern task_fork] [extern syscall_exit] [extern syscall_write] @@ -13,11 +14,18 @@ global int_syscall_handler [extern syscall_sbrk] [extern syscall_stat] [extern syscall_lstat] +[extern syscall_fork] [extern syscall_unhandled] [bits 32] + +pid: dd 0x0 + int_syscall_handler: +cmp eax, 72 +je call_fork + cli push ebx @@ -63,6 +71,7 @@ int_syscall_handler: cmp eax, 79 je call_lstat + push eax jmp call_unhandled @@ -89,6 +98,34 @@ done_blocking: iret ;Interrupt-Return +call_fork: + + cli + + pusha ;Push all standard registers + + mov ebx, esp ;save current stack pointer in esp + mov esp, 0x7000 ;now put the stack outside of virtual memory in kernel space! + + push ebx ;Push pointer to all the stuff we just pushed + call task_fork ;Call C code + mov [pid],eax + + mov esp, ebx ;Replace the stack with what the C code gave us + + mov al, 0x20 ;Port number AND command number to Acknowledge IRQ + out 0x20, al ;Acknowledge IRQ, so we keep getting interrupts + + + popa ;Put the standard registers back + + mov ebx,[pid] + + sti + + iretd ;Interrupt-Return + ;;;; + call_stat: call syscall_stat jmp done @@ -139,6 +176,7 @@ call_unhandled: ;;; THIS CALLS NEED REENABLE INTERRUPTS BEFORE calling workers + ;; TODO: redesign this shit! call_read: mov al, 0x20 ;Port number AND command number to Acknowledge IRQ diff --git a/bochs/bochsrc b/bochs/bochsrc index 3d5b316..fc56d19 100644 --- a/bochs/bochsrc +++ b/bochs/bochsrc @@ -224,7 +224,7 @@ cpu: count=2, ips=10000000 #, reset_on_triple_fault=1, ignore_bad_msrs=1, msrs=" # used all allocated host memory and wants more. # #======================================================================= -#memory: guest=16, host=1024 +memory: guest=128, host=1024 #======================================================================= # OPTROMIMAGE[1-4]: diff --git a/boot2/stage2.asm b/boot2/stage2.asm index e5ce600..832b005 100644 --- a/boot2/stage2.asm +++ b/boot2/stage2.asm @@ -251,7 +251,7 @@ reinit_16: ;16 bit protected mode realmode: - mov sp,0x07bff + mov sp,0x07000 mov bp,sp mov ax,0 diff --git a/fs/elf.c b/fs/elf.c new file mode 100644 index 0000000..3b2f2b3 --- /dev/null +++ b/fs/elf.c @@ -0,0 +1,64 @@ +#include <stdint.h> + +#define EI_NIDENT 16 + + +typedef uint32_t Elf32_Addr; +typedef uint32_t Elf32_Off; +typedef uint16_t Elf32_Section; +typedef uint16_t Elf32_Versym; +typedef unsigned char Elf_Byte; +typedef uint16_t Elf32_Half; +typedef int32_t Elf32_Sword; +typedef uint32_t Elf32_Word; +typedef int64_t Elf32_Sxword; +typedef uint64_t Elf32_Xword; + + +typedef struct +{ + + unsigned char e_ident[EI_NIDENT]; + Elf32_Half e_type; + Elf32_Half e_machine; + Elf32_Word e_version; + Elf32_Addr e_entry; + Elf32_Off e_phoff; + Elf32_Off e_shoff; + Elf32_Word e_flags; + Elf32_Half e_ehsize; + Elf32_Half e_phentsize; + Elf32_Half e_phnum; + Elf32_Half e_shentsize; + Elf32_Half e_shnum; + Elf32_Half e_shstrndx; + +} +Elf32_Ehdr; + + +typedef struct { + Elf32_Word sh_name; + Elf32_Word sh_type; + Elf32_Word sh_flags; + Elf32_Addr sh_addr; + Elf32_Off sh_offset; + Elf32_Word sh_size; + Elf32_Word sh_link; + Elf32_Word sh_info; + Elf32_Word sh_addralign; + Elf32_Word sh_entsize; +} Elf32_Shdr; + +typedef struct { + + Elf32_Word p_type; + Elf32_Off p_offset; + Elf32_Addr p_vaddr; + Elf32_Addr p_paddr; + Elf32_Word p_filesz; + Elf32_Word p_memsz; + Elf32_Word p_flags; + Elf32_Word p_align; +} +Elf32_Phdr; diff --git a/kernel/kernel.c b/kernel/kernel.c index 5e52a68..a0aaa7f 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -48,6 +48,7 @@ void __stack_chk_fail(void) // mp informs us if this if this is the main processor void kernel_main(uint32_t initial_stack, int mp) { + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"initial_stack: 0x%08X",initial_stack); // // Configuring the PIT timer. // @@ -97,8 +98,8 @@ 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(); //; this will never return! + // load and run foolshell // we will come back into the kernel only on interrupts... diff --git a/kernel/syscalls.c b/kernel/syscalls.c index f328248..7bdb639 100644 --- a/kernel/syscalls.c +++ b/kernel/syscalls.c @@ -8,69 +8,7 @@ #include "kernel/console.h" #include "kernel/config.h" #include <sys/stat.h> - -#define EI_NIDENT 16 - - -typedef uint32_t Elf32_Addr; -typedef uint32_t Elf32_Off; -typedef uint16_t Elf32_Section; -typedef uint16_t Elf32_Versym; -typedef unsigned char Elf_Byte; -typedef uint16_t Elf32_Half; -typedef int32_t Elf32_Sword; -typedef uint32_t Elf32_Word; -typedef int64_t Elf32_Sxword; -typedef uint64_t Elf32_Xword; - - -typedef struct -{ - - unsigned char e_ident[EI_NIDENT]; - Elf32_Half e_type; - Elf32_Half e_machine; - Elf32_Word e_version; - Elf32_Addr e_entry; - Elf32_Off e_phoff; - Elf32_Off e_shoff; - Elf32_Word e_flags; - Elf32_Half e_ehsize; - Elf32_Half e_phentsize; - Elf32_Half e_phnum; - Elf32_Half e_shentsize; - Elf32_Half e_shnum; - Elf32_Half e_shstrndx; - -} -Elf32_Ehdr; - - -typedef struct { - Elf32_Word sh_name; - Elf32_Word sh_type; - Elf32_Word sh_flags; - Elf32_Addr sh_addr; - Elf32_Off sh_offset; - Elf32_Word sh_size; - Elf32_Word sh_link; - Elf32_Word sh_info; - Elf32_Word sh_addralign; - Elf32_Word sh_entsize; -} Elf32_Shdr; - -typedef struct { - - Elf32_Word p_type; - Elf32_Off p_offset; - Elf32_Addr p_vaddr; - Elf32_Addr p_paddr; - Elf32_Word p_filesz; - Elf32_Word p_memsz; - Elf32_Word p_flags; - Elf32_Word p_align; -} -Elf32_Phdr; +#include "fs/elf.c" static uint32_t alloc; @@ -98,7 +36,7 @@ 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); + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"[%d] write(file=%d, buf=0x%08X, len=%d)", task_get_current_pid(),file,buf,len); #endif if(file!=1&&file!=2) panic(FOOLOS_MODULE_NAME,"unhandled syscall"); @@ -174,6 +112,7 @@ int syscall_read(int file, char *buf, int len) //TODO: replace with dirent! int syscall_readdir(const char *name,fs_dirent *dirs,int max) { + #ifdef LOG_SYSCALLS log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"readdir(name=0x%08X, dirs=0x%08X, %d)", name,dirs,max); #endif @@ -181,18 +120,31 @@ int syscall_readdir(const char *name,fs_dirent *dirs,int max) return fs_readdir(name,dirs,max); } -int syscall_wait() +int syscall_wait(int *wait, int none1, int none2) { + #ifdef LOG_SYSCALLS + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"[%d] wait ",task_get_current_pid()); + #endif } -int syscall_fork() +int syscall_fork(int none, int none2, int none3) { + //int pid=add_task(esp,vmem_new_space_dir()); + int pid=task_get_current_pid(); + int esp=0; + + #ifdef LOG_SYSCALLS + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"[%d] fork: current esp: 0x%08X, pid: %d ",task_get_current_pid(),esp,pid); + #endif + + return 0; + } -int syscall_execve(char *name, char **argv, char **env) +int syscall_execve(char *name, char **argv1, char **env1) { - //x86_int_disable(); - // watchout this is called with esp in virtual memory of running process! + char *argv[]={"/bin/foolshell",NULL}; + char *env[]={"PATH=/bin","PWD=/home/miguel","PS1=$ ",NULL}; #ifdef LOG_SYSCALLS log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"execve (name=0x%08X(%s), argvs=0x%08X, env=0x%08X)", name,name,argv,env); @@ -242,7 +194,6 @@ int syscall_execve(char *name, char **argv, char **env) log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"elf sh-strndx: %d",elf->e_shstrndx); */ - // iterate over section headers for(int phidx=0;phidx<elf->e_phnum;phidx++) { @@ -312,7 +263,6 @@ 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 c9554b5..1780b77 100644 --- a/kernel/task.c +++ b/kernel/task.c @@ -21,57 +21,32 @@ static volatile int current_task=-2; static volatile struct task_list_struct { + int parent; bool active; uint32_t esp; // stack pointer of the task; uint32_t vmem; // number of virtual memory table to switch to -}task_list[MAX_TASKS]; +}volatile task_list[MAX_TASKS]; - -void task_create(int pid,void(*thread)()) +int add_task(uint32_t esp, uint32_t vmem) { - 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 = 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); - - //First, this stuff is pushed by the processor - *--stack = 0x0202; //This is EFLAGS - *--stack = 0x08; //This is CS, our code segment - *--stack = (uint32_t)thread; //This is EIP - - //Next, the stuff pushed by 'pusha' - *--stack = 0; //EDI - *--stack = 0; //ESI - *--stack = 0; //EBP - *--stack = 0; //Just an offset, no value - *--stack = 0; //EBX - *--stack = 0; //EDX - *--stack = 0; //ECX - *--stack = 0; //EAX - - //Now these are the data segments pushed by the IRQ handler - /* - *--stack = 0x10; //DS - *--stack = 0x10; //ES - *--stack = 0x10; //FS - *--stack = 0x10; //GS - */ - - task_list[pid].esp = (uint32_t)stack; //Update the stack pointer - task_list[pid].active=true; + for(int i=0;i<MAX_TASKS;i++) + { + if(task_list[i].active!=true) + { - x86_set_pdbr(0x0502000); + task_list[i].parent=current_task; + task_list[i].vmem=vmem; + task_list[i].esp=esp; + task_list[i].active=true; -}; + return i; + } + } + + panic(FOOLOS_MODULE_NAME,"out of task slots!"); +} // this gets called by our clock interrupt regularly! uint32_t task_switch_next(uint32_t oldesp) @@ -79,7 +54,8 @@ uint32_t task_switch_next(uint32_t oldesp) timer_tick(); if(current_task==-2)return oldesp; - if(current_task!=-1)task_list[current_task].esp=oldesp; + + task_list[current_task].esp=oldesp; for(int i=0;i<MAX_TASKS;i++) { @@ -87,12 +63,10 @@ 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) vmem: %d ", current_task,pid,task_list[pid].esp,task_list[pid].vmem); + // 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); - + vmem_set_dir(task_list[pid].vmem); return task_list[pid].esp; } @@ -103,55 +77,29 @@ uint32_t task_switch_next(uint32_t oldesp) } -// task testing // -volatile void test1() +uint32_t task_fork(uint32_t oldesp) +{ + return add_task(oldesp,vmem_new_space_dir()); +} + +// init task (root of all other tasks / processes) // +void task_init() { + // this is our main task on slot 0 + task_list[0].active=true; + task_list[0].vmem=0; + task_list[0].esp = 0; // will be set by next task_switch_next() call. + current_task=0; - - 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); - } + syscall_execve("/bin/init",argv,env); } -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++) - { - syscall_write(1,&i,1); - } - } - -} -volatile void test3() -{ - while(1) - { - syscall_write(1," ",1); - } - -} -void task_init() +int task_get_current_pid() { - task_create(0,test2); - task_create(1,test1); -// task_create(2,test3); - current_task=-1; + return current_task; } diff --git a/kernel/vmem.c b/kernel/vmem.c index 53e33c4..0a9e4b1 100644 --- a/kernel/vmem.c +++ b/kernel/vmem.c @@ -85,7 +85,7 @@ typedef struct pdirectory_struct { #define MAX_PAGEDIRS 10 pdirectory *page_dirs[MAX_PAGEDIRS]; -int last_page_dir=0; +int next_page_dir=0; int current_dir=0; //// @@ -107,8 +107,6 @@ void pt_entry_set_frame (pt_entry* e , physical_addr addr) } physical_addr pt_entry_get_frame (pt_entry* e) { - // *e = (*e & ~I86_PTE_FRAME) | addr; - return *e&I86_PTE_FRAME; } @@ -140,6 +138,12 @@ void pd_entry_set_frame (pd_entry* e, physical_addr add) { *e|=I86_PDE_FRAME&add; } +physical_addr pd_entry_get_frame (pd_entry* e) +{ + return *e&I86_PDE_FRAME; + +} + bool pd_entry_is_present (pd_entry e) { return e&I86_PDE_PRESENT; @@ -249,7 +253,8 @@ uint32_t vmem_alloc_block_at(uint32_t virt_addr) } */ -int vmem_new_space_dir() +// vmem init and also copies all the shit for FORK +volatile int vmem_new_space_dir() { x86_paging_disable(); @@ -266,41 +271,58 @@ int vmem_new_space_dir() for(int j=0;j<3;j++) { - ptable* table = (ptable*) pmmngr_alloc_block (); - if (!table)panic(FOOLOS_MODULE_NAME,"unable to alloc table"); -// log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"table: 0x%X",table); - + // this is the table for our page directory. It maps 1024*4096 bytes + ptable* table; - //! idenitity mapping - for (int i=0, frame=phys_addr, virt=virt_addr; i<1024; i++, frame+=4096, virt+=4096) + // create new tables on init + if(next_page_dir==0) { - //! 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); + // alloc space for our new table + table = (ptable*) pmmngr_alloc_block (); + if (!table)panic(FOOLOS_MODULE_NAME,"unable to alloc table"); + + //! idenitity mapping + for (int i=0, frame=phys_addr, virt=virt_addr; i<1024; i++, frame+=4096, virt+=4096) + { + //! 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); + + } + // otherwise simply take existing stuff from pdir 0 + else + { + dir->m_entries[PAGE_DIRECTORY_INDEX(virt_addr)]= + page_dirs[0]->m_entries[PAGE_DIRECTORY_INDEX(virt_addr)]; - //! ...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); phys_addr+=1024*4096; virt_addr+=1024*4096; - } - // programm space (for init) + // programm space virt_addr=0x8048000; for(int j=0;j<2;j++) { ptable* table = (ptable*) pmmngr_alloc_block (); + pd_entry *oldentry= &(page_dirs[0]->m_entries[PAGE_DIRECTORY_INDEX(virt_addr)]); + ptable* oldtable=pd_entry_get_frame(oldentry); + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"oldtable at: 0x%08X",oldtable); + if (!table)panic(FOOLOS_MODULE_NAME,"unable to alloc table"); log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"alloc table: %08X",table); @@ -309,6 +331,16 @@ int vmem_new_space_dir() phys_addr=pmmngr_alloc_block(); // get free space from the memory manager if (!phys_addr)panic(FOOLOS_MODULE_NAME,"unable to alloc spce for frame"); + // if this is not init , copy contents from current space! + if(next_page_dir!=0) + { + uint32_t addr_old=pt_entry_get_frame(&oldtable->m_entries[PAGE_TABLE_INDEX(virt)]); + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"physical memcpy(0x%08X,0x%08X,4096)",phys_addr, addr_old); + memcpy(phys_addr,addr_old,4096); + + } + + int frame=phys_addr; //! create a new page @@ -331,19 +363,16 @@ int vmem_new_space_dir() } - page_dirs[last_page_dir]=dir; - if(last_page_dir!=0)x86_paging_enable(); - return last_page_dir++; + page_dirs[next_page_dir]=dir; + if(next_page_dir!=0)x86_paging_enable(); + return next_page_dir++; } void vmem_set_dir(int 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(); } diff --git a/kernel/x86.c b/kernel/x86.c index 65552cd..4163481 100644 --- a/kernel/x86.c +++ b/kernel/x86.c @@ -10,23 +10,25 @@ // +/* volatile void sleep(int i) { uint64_t clock=timer_get_ticks(); while(clock+i>timer_get_ticks()); } +*/ // disable interrupts void x86_int_disable() { - __asm__("cli"); + asm volatile("cli"); } // enable interrupts void x86_int_enable() { - __asm__("sti"); + asm volatile("sti"); } // get control registers (cr0-cr4) @@ -74,37 +76,37 @@ uint32_t x86_get_cr4() } void x86_outb(int port, uint8_t data) { - __asm __volatile("outb %0,%w1" : : "a" (data), "d" (port)); + asm volatile("outb %0,%w1" : : "a" (data), "d" (port)); } uint8_t x86_inb(int port) { uint8_t data; - __asm __volatile("inb %w1,%0" : "=a" (data) : "d" (port)); + asm volatile("inb %w1,%0" : "=a" (data) : "d" (port)); return data; } void x86_outw(int port, uint16_t data) { - __asm __volatile("outw %0,%w1" : : "a" (data), "d" (port)); + asm volatile("outw %0,%w1" : : "a" (data), "d" (port)); } uint16_t x86_inw(int port) { uint16_t data; - __asm __volatile("inw %w1,%0" : "=a" (data) : "d" (port)); + asm volatile("inw %w1,%0" : "=a" (data) : "d" (port)); return data; } void x86_outl(int port, uint32_t data) { - __asm __volatile("outl %0,%w1" : : "a" (data), "d" (port)); + asm volatile("outl %0,%w1" : : "a" (data), "d" (port)); } uint32_t x86_inl(int port) { uint32_t data; - __asm __volatile("inl %w1,%0" : "=a" (data) : "d" (port)); + asm volatile("inl %w1,%0" : "=a" (data) : "d" (port)); return data; } diff --git a/kernel/x86.h b/kernel/x86.h index 919879a..2cd9e8e 100644 --- a/kernel/x86.h +++ b/kernel/x86.h @@ -5,7 +5,7 @@ // http://wiki.osdev.org/Interrupt_Service_Routines -void sleep(int i); // TODO : Real sleep! +//void sleep(int i); // TODO : Real sleep! void x86_outb(int port, uint8_t data); uint8_t x86_inb(int port); diff --git a/userspace/Makefile b/userspace/Makefile index 53dab5f..0c41347 100644 --- a/userspace/Makefile +++ b/userspace/Makefile @@ -7,10 +7,10 @@ CFLAGS+=-w CFLAGS+=-std=gnu11 CFLAGS+=-O3 -PROGS=foolshell ls simple brainfuck add checker clear task1 task2 +PROGS=foolshell ls simple brainfuck add checker clear task1 task2 init ext2.img: $(PROGS) - dd if=/dev/zero of=ext2.img bs=512 count=5000 + dd if=/dev/zero of=ext2.img bs=512 count=7000 sudo mkfs.ext2 -O none ext2.img -F mkdir mnt sudo mount ext2.img mnt @@ -34,6 +34,7 @@ add: add.o checker: checker.o task1: task1.o task2: task2.o +init: init.o clean: -rm *.o $(PROGS) ext2.img diff --git a/userspace/init.c b/userspace/init.c new file mode 100644 index 0000000..d03d173 --- /dev/null +++ b/userspace/init.c @@ -0,0 +1,14 @@ +int main(int argc, char **argv) +{ + printf("Fool OS Init 0.1 \n"); + + int pid=fork(); + + while(1) + { + printf("I am pid: %i\n",pid); + } + return 0; +} + + diff --git a/video/console.c b/video/console.c index 6eeaf0b..d53d2d7 100644 --- a/video/console.c +++ b/video/console.c @@ -1,5 +1,4 @@ #include "console.h" -#include "kernel/spinlock.h" #include "kernel/config.h" //#define FOOLOS_CONSOLE @@ -111,7 +110,6 @@ void scr_nextline() void scr_put_char(char ch,char col) { - // lock_spin(6); if(ch=='\n')scr_nextline(); else if(posx<SCR_WIDTH) @@ -124,7 +122,6 @@ void scr_put_char(char ch,char col) if(posx>=SCR_WIDTH)scr_nextline(); #endif - //lock_release(6); } /* |
