*.img
*build*
*.BIN
+*.ELF
*.bin
+*.elf
*.map
*.sym
*.diff
{
- // 使用 IntelliSense 了解相关属性。
+ // 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"name": "kernel",
"type": "cppdbg",
"request": "launch",
- "program": "${workspaceFolder}/KERNEL.BIN",
+ "program": "${workspaceFolder}/KERNEL.ELF",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"miDebuggerPath": "i386-elf-gdb"
}
]
-}
\ No newline at end of file
+}
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
.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/
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; // 时间片用完次数
pid_t pid;
pid_t ppid;
+
volatile unsigned int state;
+ const char *reason;
+
long exit_code;
- unsigned long cr3;
+ uint32_t cr3;
long tty;
list_del(&p->pend);
p->delay_jiffies = 0;
p->state = TASK_READY;
+ p->reason = "clk_bh";
}
}
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;
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);
}
}
while (true) {
task->state = TASK_WAIT;
-
+ task->reason = "down";
schedule();
if (waiter.up) {
waiter->up = 1;
waiter->task->state = TASK_READY;
+ waiter->task->reason = "up";
}
volatile void up(semaphore_t *s) {
unsigned long flags;
irq_save(flags);
current->state = TASK_WAIT;
+ current->reason = "sysc_wait";
current->delay_jiffies = jiffies + ticks;
list_add(¤t->pend, &delay_tasks);
irq_restore(flags);
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;");
}
while (1) {
sysc_wait(7);
-
uint64_t sect_nr = get_next_deubug_sect_nr();
memset(disk_buf2, 0, 512);
disk_request_t r;
current->priority = 17;
while (1) {
- sysc_wait(1);
+ sysc_wait(100);
for (int i = 0; i < 7; i++) {
asm("hlt;");
irq_save(flags);
current->state = TASK_WAIT;
+ current->reason = "sleep_on";
list_add_tail(&wait.task_list, &head->task_list);
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) {
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}"
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
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
sleep 1
# 拷贝内核文件
-cp ../KERNEL.BIN ${MNT}/boot/Kernel
+cp ../KERNEL.ELF ${MNT}/boot/Kernel
sleep 1
umount $MNT
# 因为如果在其它机器上运行,其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/