#define ASM
#include "boot/boot.h"
#include "system.h"
+#include "task.h"
.global kernel_entry
.extern CheckKernel
.extern SetupKernel
.extern init_pgd
.extern init_pgt
.extern kernel_virtual_addr_start
-.extern kernel_init_stack
+.extern root_task
+.extern root_task_entry
.section .multiboot_header
.align 32
Label:
call CheckKernel
addl $8,%esp
- movl $kernel_init_stack + KRNL_INIT_STACK_SIZE, %esp
+ movl $root_task + TASK_SIZE, %esp
call KernelEntry
+ xorl %eax, %eax
+ sti
+ pushfl
+ movw %cs, %ax
+ pushl %eax
+ movl $root_task_entry, %eax
+ pushl %eax
+ iret
+
Die:
jmp Die # Should never come to here.
#define TASK_CNT 64
+extern task_union root_task;
+
#endif //_SCHED_H
*--------------------------------------------------------------------------
*/
-#ifndef _TASK_H
+#ifndef _TASK_H
#define _TASK_H
+#define TASK_SIZE 4096
+
+#ifndef ASM
#include <page.h>
#include <list.h>
#include <types.h>
#include <system.h>
#include <wait.h>
#include <fs.h>
-#define TASK_PAGES (2)
-#define TASK_SIZE (TASK_PAGES<<PAGE_SHIFT)
enum
{
long tty;
- ListHead list;
+ list_head_t list;
WaitQueue wait;
#define add_tsk2list(tsk) list_add_tail((&(tsk)->list), &tsk_list)
#define get_tsk_from_list(p) list_entry((p), Task, list)
#define del_tsk_from_list(tsk) list_del((&tsk->list))
+#endif
#endif //_TASK_H
if(tsk->cr3 == 0)
panic("failed init tsk cr3");
- memcpy((void *)tsk->cr3, (void*)current->cr3, PAGE_SIZE);
+ task_union *t = current;
unsigned int i, j;
pde_t *pde_src = (pde_t*) current->cr3;
pde_t *pde_dst = (pde_t*) tsk->cr3;
+
+ memcpy((void *)tsk->cr3, (void*)current->cr3, PAGE_SIZE);
+
for(i=0; i<PAGE_PDE_CNT; ++i)
{
unsigned long spde = (unsigned long) pde_src[i];
tsk->state = TASK_RUNNING;
+
+ INIT_LIST_HEAD(&tsk->list);
+ list_add(&tsk->list, &root_task.list);
+
return (int)tsk->pid;
}
pushl %%eax; \
iret;"::"b"(root_task_user_space_stack+PAGE_SIZE));
#else
+#if 0
asm("xorl %eax, %eax; \
sti;\
pushfl; \
pushl %eax;\
leal root_task_entry,%eax; \
pushl %eax; \
- iret;");
+ iret;"::"b"(root_task.cr3 + TASK_SIZE));
+#endif
#endif
return 0; /* never come to here */
#else
void root_task_entry()
{
- while(1)
+ pt_regs_t regs;
+ int pid = do_fork(regs, 0);
+
+ printk("pid is %d\n", pid);
+
+ if(pid > 0)
{
- asm("hlt;");
- sysc_test();
- //syscall0(SYSC_TEST);
+ while(1)
+ {
+ asm("hlt;");
+ sysc_test();
+ //syscall0(SYSC_TEST);
+ }
}
- pid_t pid;
+ else if(pid == 0)
+ {
+
+ }
+ else
+ {
+ printk("err\n");
+ }
+ //pid_t pid;
/*
int fd = open("/boot/grub/grub.conf", O_RDONLY);
//int fd = open("/bin/hw", O_RDONLY);
.extern irq_handler
.extern schedule
_irq_handler:
+ cli #FOR TEST ONLY
SAVE_REGS
movw %ss,%ax
movl %esp, %eax
call irq_handler
- # call schedule
+ call schedule
# movl current, %esp
#include "sched.h"
#include "assert.h"
#include "mm.h"
+#include "init.h"
task_union root_task __attribute__((__aligned__(PAGE_SIZE)));
tsk->cr3 = va2pa(tsk->cr3);
}
+extern pde_t __initdata init_pgd[PDECNT_PER_PAGE] __attribute__((__aligned__(PAGE_SIZE)));
void init_root_tsk()
{
int i;
root_task.pid = get_next_pid();
root_task.ppid = 0;
+ INIT_LIST_HEAD(&root_task.list);
for(i=0; i<NR_OPENS; i++)
root_task.fps[i] = 0;
tss.esp0 = ((unsigned long)&root_task) + sizeof(root_task);
root_task.esp0 = tss.esp0;
+ root_task.cr3 = (unsigned long)init_pgd;
printk("init_root_task tss.esp0 %08x\n", tss.esp0);
init_root_tsk();
- kmem_cache_t *task_union_cache = kmem_cache_create("task_union", sizeof(task_union), PAGE_SIZE);
+ task_union_cache = kmem_cache_create("task_union", sizeof(task_union), PAGE_SIZE);
if(0 == task_union_cache)
panic("setup tasks failed. out of memory");
//asm("xchg %bx, %bx");
asm volatile(
"pushfl;"
- "pushl %%ebp;"
- "movl %%esp,%[prev_esp];"
- "movl %[next_esp],%%esp;"
- "movl $1f,%[prev_eip];"
- "pushl %[next_eip];"
+ "pushl %%ebp;"
+ "movl %%esp,%[prev_esp];"
+ "movl %[next_esp],%%esp;"
+ "movl $1f,%[prev_eip];"
+ "pushl %[next_eip];"
"jmp switch_to;"
"1:"
- "popl %%ebp;"
+ "popl %%ebp;"
"popfl;"
: [prev_esp] "=m" (prev->esp),
[prev_eip] "=m" (prev->eip),
unsigned long schedule()
{
+ static task_union *p = &root_task;
+
+ if(p == &root_task)
+ p = list_entry(root_task.list.next, task_union, list);
+ else
+ p = &root_task;
+
+ if(p == &root_task)
+ return ;
+
+ task_union *prev, *next;
+ prev = current;
+ next = p;
+
+ context_switch(prev, next);
+
#if 0
task_union * tsk, prev, next;