From 7ca2ae26eb77f3ab6b9cf92fb7bba35360f1352b Mon Sep 17 00:00:00 2001 From: acevest Date: Tue, 30 May 2023 23:14:32 +0800 Subject: [PATCH] =?utf8?q?=E4=BF=AE=E5=A4=8D=E5=BA=95=E5=8D=8A=E9=80=BB?= =?utf8?q?=E8=BE=91=E5=8F=AF=E8=83=BD=E4=B8=A2=E5=A4=B1=E9=80=A0=E6=88=90d?= =?utf8?q?isk=20tskA=20tskB=E4=BC=9A=E4=B8=80=E7=9B=B4WAIT=E4=BF=A1?= =?utf8?q?=E5=8F=B7=E9=87=8F=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 +- .vscode/launch.json | 35 ++++++++++++++++++++++++++++++ .vscode/tasks.json | 51 +++++++++++++++++++++++++++++++++++++++++++ kernel/clock.c | 2 +- kernel/irq.c | 6 ++--- kernel/syscall.c | 53 +++++++++++++++------------------------------ kernel/task_init.c | 2 +- kernel/task_root.c | 2 +- kernel/wait.c | 14 ------------ 9 files changed, 110 insertions(+), 57 deletions(-) create mode 100644 .vscode/launch.json create mode 100644 .vscode/tasks.json diff --git a/.gitignore b/.gitignore index c04f383..49809ab 100644 --- a/.gitignore +++ b/.gitignore @@ -33,5 +33,5 @@ snapshot.txt bochsout.txt *.lock *.DS_Store -.vscode +.vscode/settings.json *.iso diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..fe909e8 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,35 @@ +{ + // 使用 IntelliSense 了解相关属性。 + // 悬停以查看现有属性的描述。 + // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "kernel", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/KERNEL.BIN", + "args": [], + "stopAtEntry": false, + "cwd": "${fileDirname}", + "environment": [], + "externalConsole": false, + "MIMode": "gdb", + "miDebuggerServerAddress": "localhost:1234", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + }, + { + "description": "Set Disassembly Flavor to Intel", + "text": "-gdb-set disassembly-flavor intel", + "ignoreFailures": true + } + ], + "preLaunchTask": "", + "miDebuggerPath": "i386-elf-gdb" + } + ] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..5c768b1 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,51 @@ +{ + "tasks": [ + { + "type": "cppbuild", + "label": "C/C++: gcc 生成活动文件", + "command": "/usr/bin/gcc", + "args": [ + "-fdiagnostics-color=always", + "-g", + "${file}", + "-o", + "${fileDirname}/${fileBasenameNoExtension}" + ], + "options": { + "cwd": "${fileDirname}" + }, + "problemMatcher": [ + "$gcc" + ], + "group": { + "kind": "build", + "isDefault": true + }, + "detail": "调试器生成的任务。" + }, + { + "label": "gas", + "type": "shell", + "command": "i686-elf-as", + "args": [ + "-g", + "-m32", + "${fileDirname}/${fileBasenameNoExtension}", + "-o", + "${fileDirname}/${fileBasenameNoExtension}.o", + ], + "problemMatcher": { + "pattern": { + "regexp": "error" + } + }, + "presentation": { + "focus": true, + "panel": "dedicated", + "reveal": "silent", + "clear": true + } + }, + ], + "version": "2.0.0" +} \ No newline at end of file diff --git a/kernel/clock.c b/kernel/clock.c index aabd0b6..3921de5 100644 --- a/kernel/clock.c +++ b/kernel/clock.c @@ -16,7 +16,7 @@ #include #include -volatile uint32_t jiffies = 0; // TODO uint64: undefined reference to `__umoddi3' +volatile uint64_t jiffies = 0; // TODO uint64: undefined reference to `__umoddi3' unsigned int sys_clock() { return jiffies; } diff --git a/kernel/irq.c b/kernel/irq.c index cbc190c..4517a85 100644 --- a/kernel/irq.c +++ b/kernel/irq.c @@ -99,8 +99,8 @@ __attribute__((regparm(1))) void irq_handler(pt_regs_t *regs) { #if 1 unsigned long esp; asm("movl %%esp, %%eax" : "=a"(esp)); - printl(MPL_CURRENT, "current %08x cr3 %08x reenter %d esp %08x %u", current, current->cr3, reenter, esp, - current->ticks); + printl(MPL_CURRENT, "current %08x %s cr3 %08x reenter %d esp %08x ticks %u", current, current->name, current->cr3, + reenter, esp, current->ticks); #endif while (action && action->handler) { @@ -239,8 +239,6 @@ void add_irq_bh_handler(void (*handler)()) { irq_bh_actions_end = p; } p->next = NULL; - - irq_bh_actions = p; } int open_irq(unsigned int irq) { return irq_desc[irq].chip->enable(irq); } diff --git a/kernel/syscall.c b/kernel/syscall.c index 8292f19..d4f01d8 100644 --- a/kernel/syscall.c +++ b/kernel/syscall.c @@ -41,43 +41,26 @@ int sysc_none() { return 0; } -int sysc_pause(unsigned long tick) { return 0; } - -int sysc_test() { -#if 0 - static unsigned int cnt = 0; - - { // 这一段仅是测试代码 - - // 因为现在sysc还没切进程 - // 所以current把自己加到delay_tasks后不会被立即换出 - // 下一次系统调用还可能走到这里 - // 所以这里就直接判断不是RUNNING就返回 - // 不再操作delay_tasks链表 - if (current->state != TASK_READY) { - return 0; - } - - current->delay_jiffies = root_task.sched_cnt % 40; - - unsigned long iflags; - irq_save(iflags); - - current->state = TASK_WAIT; - // 现在sysc还没有实现进程切换 - // 这个要到下一次中断之后才生效 - list_add(&(current->pend), &delay_tasks); - - irq_restore(iflags); - } - - // printl(MPL_TEST, "systest cnt %u current %08x cnt %u ", - // cnt++, current, cnt); - // printk("systest cnt %u current %08x cnt %u\n",cnt++, current, cnt); - return 0; -#endif +extern uint64_t jiffies; + +// 特别说明:如果想把这个函数的参数ticks改为uint64_t +// 那么就需要在编写用户级的系统调用库函数的时候注意 +// 不仅需要填写 ebx,还要填写 ecx +// 不然就可能出现诡异的一直WAIT,不会调度到该任务的问题 +int sysc_wait(uint32_t ticks) { + unsigned long flags; + irq_save(flags); + current->state = TASK_WAIT; + current->delay_jiffies = jiffies + ticks; + list_add(¤t->pend, &delay_tasks); + irq_restore(flags); + + schedule(); } +int sysc_test() {} +int sysc_pause() {} + int sysc_debug(unsigned int v) { static unsigned int cnt = 0; printl(MPL_DEBUG, "task debug syscall %u value %08x", cnt++, v); diff --git a/kernel/task_init.c b/kernel/task_init.c index 8ce0a76..7c7383d 100644 --- a/kernel/task_init.c +++ b/kernel/task_init.c @@ -9,7 +9,7 @@ #include #include #include -int sysc_wait(unsigned long cnt); +int sysc_wait(uint32_t ticks); void init_task_entry() { current->priority = 10; diff --git a/kernel/task_root.c b/kernel/task_root.c index 4baa768..5721beb 100644 --- a/kernel/task_root.c +++ b/kernel/task_root.c @@ -21,7 +21,7 @@ #include int do_fork(pt_regs_t *regs, unsigned long flags); -int sysc_wait(unsigned long cnt); +int sysc_wait(uint32_t ticks); void kernel_task(char *name, void *entry) { pt_regs_t regs; diff --git a/kernel/wait.c b/kernel/wait.c index aee7104..bb7360c 100644 --- a/kernel/wait.c +++ b/kernel/wait.c @@ -120,17 +120,3 @@ int debug_wait_queue_put(unsigned int v) { debug_global_var = v; wake_up(&debug_wq); } - -DECLARE_WAIT_QUEUE_HEAD(sysc_wait_queue_head); - -extern uint32_t jiffies; -int sysc_wait(unsigned long cnt) { - unsigned long flags; - irq_save(flags); - current->state = TASK_WAIT; - current->delay_jiffies = jiffies + cnt; - list_add(¤t->pend, &delay_tasks); - irq_restore(flags); - - schedule(); -} -- 2.44.0