printk("child regs: %x %x\n", child_regs, regs);
memcpy(child_regs, regs, sizeof(*regs));
- child_regs->eax = 0;
- child_regs->eflags |= 0x200; // enable IF
-
tsk->esp0 = TASK_SIZE + (unsigned long)tsk;
tsk->esp = (unsigned long)child_regs;
tsk->eip = (unsigned long)ret_from_fork_user;
if (flags & FORK_KRNL) {
+ strcpy(tsk->name, (char *)(child_regs->eax));
tsk->eip = (unsigned long)ret_from_fork_krnl;
}
+ child_regs->eax = 0;
+ child_regs->eflags |= 0x200; // enable IF
+
printk("tsk %08x child_regs esp %08x esp0 %08x\n", tsk, tsk->esp, tsk->esp0);
tsk->state = TASK_INITING;
}
}
-void user_task_entry(char *name) {
- strcpy(current->name, name);
-
+void user_task_entry() {
current->priority = 90;
unsigned long ring3_text_page = va2pa(ring3_entry);
asm volatile("sysexit;" ::"d"(0x08000000), "c"(0x30000000 + PAGE_SIZE - 100));
}
-void init_task_entry(char *name) {
+void init_task_entry() {
int cnt = 0;
pid_t id = sysc_getpid();
- strcpy(current->name, name);
-
// 赋予不同的优先级
current->priority = id * 30;
}
}
+void disk_task_entry() {
+ while (1) {
+ schedule();
+ }
+}
+
void kernel_task(char *name, void *entry) {
pt_regs_t regs;
// 内核任务入口
regs.edx = (unsigned long)entry;
+ regs.eax = (u32)name;
+
// 创建内核任务的时候就直接指定其在fork后走的路径
// 就不用走sysexit那个路径了
extern void ret_from_fork_krnl();
regs.fs = SELECTOR_KRNL_DS;
regs.gs = SELECTOR_KRNL_DS;
- regs.ebx = (unsigned long)name; // 用ebx传递参数
-
int pid = do_fork(®s, FORK_KRNL);
printk("kernel[%s] task pid is %d\n", name, pid);
setup_under_irq();
kernel_task("init", init_task_entry);
- kernel_task("test", init_task_entry);
+ kernel_task("disk", disk_task_entry);
kernel_task("user", user_task_entry);
- int cnt = 0;
-
while (1) {
- // sysc_test();
- // printl(MPL_TASK_0, "root:0 [%08x] weight %d cnt %d", current, root_task.weight, cnt++);
- // printk("root:0 [%08x] weight %d cnt %d", current, current->weight, cnt++);
asm("hlt;");
- // asm("nop;nop;nop;");
- // sysc_test();
- // syscall0(SYSC_TEST);
}
}
LIST_HEAD(delay_tasks);
-void init_root_tsk() {
+void init_root_task() {
int i;
root_task.preempt_cnt = 0;
INIT_LIST_HEAD(&all_tasks);
INIT_LIST_HEAD(&delay_tasks);
- init_root_tsk();
+ init_root_task();
task_union_cache = kmem_cache_create("task_union", sizeof(task_union), PAGE_SIZE);
if (0 == task_union_cache) {
" ERROR", "RUNNING", " WAIT", "INITING", "EXITING",
};
- if (state >= TASK_END) state = TASK_UNUSED;
+ if (state >= TASK_END) {
+ state = TASK_UNUSED;
+ }
return s[state];
}