bochsout.txt
*.lock
*.DS_Store
-.vscode
+.vscode/settings.json
*.iso
--- /dev/null
+{
+ // 使用 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
--- /dev/null
+{
+ "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
#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; }
#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) {
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); }
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);
#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;
#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;
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();
-}