]> Zhao Yanbai Git Server - kernel.git/commitdiff
authorzhaoyanbai <zhaoyanbai@126.com>
Fri, 9 Jun 2023 13:32:51 +0000 (21:32 +0800)
committerzhaoyanbai <zhaoyanbai@126.com>
Mon, 12 Jun 2023 16:09:28 +0000 (00:09 +0800)
16 files changed:
.gitignore
.vscode/launch.json
Makefile
include/task.h
kernel/clock.c
kernel/sched.c
kernel/semaphore.c
kernel/syscall.c
kernel/task_disk.c
kernel/task_root.c
kernel/wait.c
qemu.sh
scripts/copy.sh
scripts/docker_copy.sh
scripts/init.sh
scripts/mkiso.sh

index 49809ab..cba73dc 100644 (file)
@@ -21,7 +21,9 @@
 *.img
 *build*
 *.BIN
+*.ELF
 *.bin
+*.elf
 *.map
 *.sym
 *.diff
index fe909e8..56f7a5d 100644 (file)
@@ -1,5 +1,5 @@
 {
-    // 使用 IntelliSense 了解相关属性。 
+    // 使用 IntelliSense 了解相关属性。
     // 悬停以查看现有属性的描述。
     // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
     "version": "0.2.0",
@@ -8,7 +8,7 @@
             "name": "kernel",
             "type": "cppdbg",
             "request": "launch",
-            "program": "${workspaceFolder}/KERNEL.BIN",
+            "program": "${workspaceFolder}/KERNEL.ELF",
             "args": [],
             "stopAtEntry": false,
             "cwd": "${fileDirname}",
@@ -32,4 +32,4 @@
             "miDebuggerPath": "i386-elf-gdb"
         }
     ]
-}
\ No newline at end of file
+}
index 625e1b1..ba1ce6a 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -28,7 +28,7 @@ CFLAGS     += -DNR_TTYS=3
 CFLAGS     += -DFIX_SYSENTER_ESP_MODE=1
 #CFLAGS     += -DENABLE_BOOT_WAIT=1
 SYSTEMMAP      = System.map
-KERNELBIN      = KERNEL.BIN
+KERNELBIN      = KERNEL.ELF
 LINKSCRIPT     = scripts/link.ld
 
 SRC_DIRS = boot mm lib fs kernel drivers
@@ -63,10 +63,10 @@ clean:
 
 .PHONY: install
 install:
-       cp -p KERNEL.BIN /boot/
+       cp -p KERNEL.ELF /boot/
        sync
-       md5sum /boot/KERNEL.BIN
-       md5sum KERNEL.BIN
+       md5sum /boot/KERNEL.ELF
+       md5sum KERNEL.ELF
        mkdir -p /kernel/bin/
        cp bin/hello /kernel/bin/
        cp bin/shell /kernel/bin/
index d246066..4c3f74e 100644 (file)
@@ -42,11 +42,11 @@ enum {
 
 typedef union task_union {
     struct {
-        unsigned long esp0; /* kernel stack */
+        uint32_t esp0; /* kernel stack */
 
         /* for context switch */
-        unsigned long esp;
-        unsigned long eip;
+        uint32_t esp;
+        uint32_t eip;
 
         uint32_t ticks;
         uint32_t turn;  // 时间片用完次数
@@ -57,9 +57,12 @@ typedef union task_union {
 
         pid_t pid;
         pid_t ppid;
+
         volatile unsigned int state;
+        const char *reason;
+
         long exit_code;
-        unsigned long cr3;
+        uint32_t cr3;
 
         long tty;
 
index 3cf9330..b104efe 100644 (file)
@@ -65,6 +65,7 @@ void clk_bh_handler(void *arg) {
             list_del(&p->pend);
             p->delay_jiffies = 0;
             p->state = TASK_READY;
+            p->reason = "clk_bh";
         }
     }
 
index b710ee3..9c8aa3e 100644 (file)
@@ -56,6 +56,7 @@ void init_root_task() {
     root_task.pid = get_next_pid();
     root_task.ppid = 0;
     root_task.state = TASK_READY;
+    root_task.reason = "root";
     root_task.priority = 7;
     root_task.ticks = root_task.priority;
     root_task.turn = 0;
@@ -166,12 +167,12 @@ const char *task_state(unsigned int state) {
 void debug_print_all_tasks() {
     task_union *p = 0;
     list_head_t *pos = 0, *t = 0;
-    printl(MPL_TASK_TITLE, "         NAME       STATE TK/PI TURN       SCHED      KEEP");
+    printl(MPL_TASK_TITLE, "         NAME       STATE TK/PI REASON     SCHED      KEEP");
     list_for_each_safe(pos, t, &all_tasks) {
         p = list_entry(pos, task_union, list);
-        printl(MPL_TASK_0 + p->pid, "%08x%s%-6s:%u %s %02u/%02u %-10u %-10u %-10u", p,
+        printl(MPL_TASK_0 + p->pid, "%08x%s%-6s:%u %s %02u/%02u %-10s %-10u %-10u", p,
                p->state == TASK_RUNNING ? ">" : " ", p->name, p->pid, task_state(p->state), p->ticks, p->priority,
-               p->turn, p->sched_cnt, p->sched_keep_cnt);
+               p->reason, p->sched_cnt, p->sched_keep_cnt);
     }
 }
 
index 29b42ad..199b17c 100644 (file)
@@ -33,7 +33,7 @@ volatile void __down(semaphore_t *s) {
 
     while (true) {
         task->state = TASK_WAIT;
-
+        task->reason = "down";
         schedule();
 
         if (waiter.up) {
@@ -61,6 +61,7 @@ volatile void __up(semaphore_t *s) {
     waiter->up = 1;
 
     waiter->task->state = TASK_READY;
+    waiter->task->reason = "up";
 }
 
 volatile void up(semaphore_t *s) {
index d4f01d8..a6d4414 100644 (file)
@@ -51,6 +51,7 @@ int sysc_wait(uint32_t ticks) {
     unsigned long flags;
     irq_save(flags);
     current->state = TASK_WAIT;
+    current->reason = "sysc_wait";
     current->delay_jiffies = jiffies + ticks;
     list_add(&current->pend, &delay_tasks);
     irq_restore(flags);
index d53cd8d..c02bc1a 100644 (file)
@@ -63,7 +63,8 @@ void disk_task_entry(void *arg) {
         ide_pci_controller_t *ide_ctrl = ide_pci_controller + channel;
 
         // 为了在DEBUG时看到RUNNING
-        for (int i = 0; i < 1; i++) {
+        int cnt = 2;
+        for (int i = 0; i < cnt; i++) {
             asm("hlt;");
         }
 
index 6028d41..394332f 100644 (file)
@@ -126,7 +126,6 @@ void taskB_entry() {
 
     while (1) {
         sysc_wait(7);
-
         uint64_t sect_nr = get_next_deubug_sect_nr();
         memset(disk_buf2, 0, 512);
         disk_request_t r;
@@ -148,7 +147,7 @@ void taskC_entry() {
     current->priority = 17;
 
     while (1) {
-        sysc_wait(1);
+        sysc_wait(100);
 
         for (int i = 0; i < 7; i++) {
             asm("hlt;");
index bb7360c..86ea8f2 100644 (file)
@@ -53,6 +53,7 @@ volatile void sleep_on(wait_queue_head_t *head) {
     irq_save(flags);
 
     current->state = TASK_WAIT;
+    current->reason = "sleep_on";
 
     list_add_tail(&wait.task_list, &head->task_list);
 
@@ -72,6 +73,7 @@ volatile void __wake_up(wait_queue_head_t *head, int nr) {
         list_del(&p->task_list);
         // printk("wakeup: %s\n", p->task->name);
         p->task->state = TASK_READY;
+        current->reason = "wake_up";
 
         --nr;
         if (nr == 0) {
diff --git a/qemu.sh b/qemu.sh
index fa9ce47..efff4d2 100755 (executable)
--- a/qemu.sh
+++ b/qemu.sh
@@ -17,7 +17,7 @@ qemu-system-i386 \
 pid=$!
 echo "pid is ${pid}"
 
-i386-elf-gdb KERNEL.BIN -x gdbscript; kill -9 $pid
+i386-elf-gdb KERNEL.ELF -x gdbscript; kill -9 $pid
 
 echo "kill pid ${pid}"
 
index c10d0b0..fc1e011 100755 (executable)
@@ -10,7 +10,7 @@ PART=${lodev}p1
 
 mount $PART /mnt/
 
-cp ./KERNEL.BIN /mnt/boot/Kernel
+cp ./KERNEL.ELF /mnt/boot/Kernel
 cp scripts/grub.cfg /mnt/boot/grub2/
 
 md5sum /mnt/boot/Kernel
index 15ea2a9..d9cf241 100755 (executable)
@@ -13,7 +13,7 @@ kpartx -u HD.IMG
 
 mount $PART /mnt/
 
-cp ./KERNEL.BIN /mnt/boot/Kernel
+cp ./KERNEL.ELF /mnt/boot/Kernel
 cp scripts/grub.cfg /mnt/boot/grub2/
 
 md5sum /mnt/boot/Kernel
index e15671b..b8dfdd0 100755 (executable)
@@ -53,7 +53,7 @@ cp grub.cfg ${MNT}/boot/grub2/
 sleep 1
 
 # 拷贝内核文件
-cp ../KERNEL.BIN ${MNT}/boot/Kernel
+cp ../KERNEL.ELF ${MNT}/boot/Kernel
 sleep 1
 
 umount $MNT
index 8fc2b98..fb98eb0 100755 (executable)
@@ -3,5 +3,5 @@
 # 因为如果在其它机器上运行,其grub就不是x86版本
 mkdir -p /tmp/iso/boot/grub/
 cp scripts/iso.grub.cfg /tmp/iso/boot/grub/grub.cfg
-cp KERNEL.BIN /tmp/iso/boot/Kernel
+cp KERNEL.ELF /tmp/iso/boot/Kernel
 grub2-mkrescue -o kernel.iso /tmp/iso/