Skip to content

Commit

Permalink
✨ 047 系统调用 1
Browse files Browse the repository at this point in the history
  • Loading branch information
StevenBaby committed Apr 8, 2022
1 parent 690166b commit 82f1aba
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 3 deletions.
6 changes: 6 additions & 0 deletions docs/07 任务管理/046 创建内核线程.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@
## 内核线程调度

![](./images/setup_task.drawio.svg)

## ROP

Return Oreiented Programming 面向返回编程

iret 返回到用户态
2 changes: 1 addition & 1 deletion src/include/onix/task.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ typedef struct task_t
u32 priority; // 任务优先级
u32 ticks; // 剩余时间片
u32 jiffies; // 上次执行时全局时间片
u32 name[TASK_NAME_LEN]; // 任务名
char name[TASK_NAME_LEN]; // 任务名
u32 uid; // 用户 id
u32 pde; // 页目录物理地址
struct bitmap_t *vmap; // 进程虚拟内存位图
Expand Down
1 change: 0 additions & 1 deletion src/kernel/clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ void clock_handler(int vector)
task->ticks--;
if (!task->ticks)
{
task->ticks = task->priority;
schedule();
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/kernel/console.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <onix/console.h>
#include <onix/io.h>
#include <onix/string.h>
#include <onix/interrupt.h>

#define CRT_ADDR_REG 0x3D4 // CRT(6845)索引寄存器
#define CRT_DATA_REG 0x3D5 // CRT(6845)数据寄存器
Expand Down Expand Up @@ -156,6 +157,8 @@ extern void start_beep();

void console_write(char *buf, u32 count)
{
bool intr = interrupt_disable(); // 禁止中断

char ch;
while (count--)
{
Expand Down Expand Up @@ -205,6 +208,9 @@ void console_write(char *buf, u32 count)
}
}
set_cursor();

// 恢复中断
set_interrupt_state(intr);
}

void console_init()
Expand Down
7 changes: 6 additions & 1 deletion src/kernel/task.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ void schedule()
current->state = TASK_READY;
}

if (!current->ticks)
{
current->ticks = current->priority;
}

next->state = TASK_RUNNING;
if (next == current)
return;
Expand Down Expand Up @@ -102,7 +107,7 @@ static task_t *task_create(target_t target, const char *name, u32 priority, u32
task->state = TASK_READY;
task->uid = uid;
task->vmap = &kernel_map;
task->pde = KERNEL_PAGE_DIR;
task->pde = KERNEL_PAGE_DIR; // page directory entry
task->magic = ONIX_MAGIC;

return task;
Expand Down

0 comments on commit 82f1aba

Please sign in to comment.