]> Zhao Yanbai Git Server - kernel.git/commitdiff
修复底半逻辑可能丢失造成disk tskA tskB会一直WAIT信号量的问题
authoracevest <zhaoyanbai@126.com>
Tue, 30 May 2023 15:14:32 +0000 (23:14 +0800)
committeracevest <zhaoyanbai@126.com>
Tue, 30 May 2023 15:14:32 +0000 (23:14 +0800)
.gitignore
.vscode/launch.json [new file with mode: 0644]
.vscode/tasks.json [new file with mode: 0644]
kernel/clock.c
kernel/irq.c
kernel/syscall.c
kernel/task_init.c
kernel/task_root.c
kernel/wait.c

index c04f383149227711c97827bb02eb89da96d0e43d..49809ab9799c7e4c413c98b97b60b001394b39fc 100644 (file)
@@ -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 (file)
index 0000000..fe909e8
--- /dev/null
@@ -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 (file)
index 0000000..5c768b1
--- /dev/null
@@ -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
index aabd0b69db858dd4fbedce8be2d19e6509986846..3921de5d1c6d177392b7f885c931dab20d63f2cf 100644 (file)
@@ -16,7 +16,7 @@
 #include <system.h>
 #include <wait.h>
 
-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; }
 
index cbc190c007b1cdf8d7fc3c7b25029ed0e608cfc5..4517a85658979348c0297b48eada5ab1f26bdbae 100644 (file)
@@ -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); }
index 8292f19d76a573e2fae773934254c523d501af00..d4f01d8c6333fd7bf5394198990f9083d1b2b57b 100644 (file)
@@ -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(&current->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);
index 8ce0a76c7872b04c0315e30d89049b18f2079ff8..7c7383da9353d7eb7ae5852b27bb3dfc5d5944ce 100644 (file)
@@ -9,7 +9,7 @@
 #include <syscall.h>
 #include <system.h>
 #include <types.h>
-int sysc_wait(unsigned long cnt);
+int sysc_wait(uint32_t ticks);
 void init_task_entry() {
     current->priority = 10;
 
index 4baa76819a48458bb1b964c50802afe18187f694..5721beb814b00e5f498ea346f2f00dd4fd7ff9a8 100644 (file)
@@ -21,7 +21,7 @@
 #include <types.h>
 
 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;
index aee71040382b6d123df7367d775fc40a47c3a138..bb7360caa3ec77d733e9a540d6cb59bdb1722265 100644 (file)
@@ -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(&current->pend, &delay_tasks);
-    irq_restore(flags);
-
-    schedule();
-}