mirror of
https://github.com/yourtion/30dayMakeOS.git
synced 2026-05-01 22:20:50 +08:00
任务管理自动化
This commit is contained in:
@@ -7,13 +7,6 @@ void make_window8(unsigned char *buf, int xsize, int ysize, char *title);
|
|||||||
void putfonts8_asc_sht(struct SHEET *sht, int x, int y, int c, int b, char *s, int l);
|
void putfonts8_asc_sht(struct SHEET *sht, int x, int y, int c, int b, char *s, int l);
|
||||||
void make_textbox8(struct SHEET *sht, int x0, int y0, int sx, int sy, int c);
|
void make_textbox8(struct SHEET *sht, int x0, int y0, int sx, int sy, int c);
|
||||||
|
|
||||||
struct TSS32 {
|
|
||||||
int backlink, esp0, ss0, esp1, ss1, esp2, ss2, cr3;
|
|
||||||
int eip, eflags, eax, ecx, edx, ebx, esp, ebp, esi, edi;
|
|
||||||
int es, cs, ss, ds, fs, gs;
|
|
||||||
int ldtr, iomap;
|
|
||||||
};
|
|
||||||
|
|
||||||
void task_b_main(struct SHEET *sht_back);
|
void task_b_main(struct SHEET *sht_back);
|
||||||
|
|
||||||
void HariMain(void)
|
void HariMain(void)
|
||||||
@@ -23,7 +16,7 @@ void HariMain(void)
|
|||||||
char s[40];
|
char s[40];
|
||||||
int fifobuf[128];
|
int fifobuf[128];
|
||||||
struct TIMER *timer, *timer2, *timer3;
|
struct TIMER *timer, *timer2, *timer3;
|
||||||
int mx, my, i, cursor_x, cursor_c, task_b_esp;
|
int mx, my, i, cursor_x, cursor_c;
|
||||||
unsigned int memtotal;
|
unsigned int memtotal;
|
||||||
struct MOUSE_DEC mdec;
|
struct MOUSE_DEC mdec;
|
||||||
struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR;
|
struct MEMMAN *memman = (struct MEMMAN *) MEMMAN_ADDR;
|
||||||
@@ -38,8 +31,7 @@ void HariMain(void)
|
|||||||
0, 0, 0, 0, 0, 0, 0, '7', '8', '9', '-', '4', '5', '6', '+', '1',
|
0, 0, 0, 0, 0, 0, 0, '7', '8', '9', '-', '4', '5', '6', '+', '1',
|
||||||
'2', '3', '0', '.'
|
'2', '3', '0', '.'
|
||||||
};
|
};
|
||||||
struct TSS32 tss_a, tss_b;
|
struct TASK *task_b;
|
||||||
struct SEGMENT_DESCRIPTOR *gdt = (struct SEGMENT_DESCRIPTOR *) ADR_GDT;
|
|
||||||
|
|
||||||
init_gdtidt();
|
init_gdtidt();
|
||||||
init_pic();
|
init_pic();
|
||||||
@@ -96,32 +88,18 @@ void HariMain(void)
|
|||||||
memtotal / (1024 * 1024), memman_total(memman) / 1024);
|
memtotal / (1024 * 1024), memman_total(memman) / 1024);
|
||||||
putfonts8_asc_sht(sht_back, 0, 32, COL8_FFFFFF, COL8_008484, s, 40);
|
putfonts8_asc_sht(sht_back, 0, 32, COL8_FFFFFF, COL8_008484, s, 40);
|
||||||
|
|
||||||
tss_a.ldtr = 0;
|
task_init(memman);
|
||||||
tss_a.iomap = 0x40000000;
|
task_b = task_alloc();
|
||||||
tss_b.ldtr = 0;
|
task_b->tss.esp = memman_alloc_4k(memman, 64 * 1024) + 64 * 1024 - 8;
|
||||||
tss_b.iomap = 0x40000000;
|
task_b->tss.eip = (int) &task_b_main;
|
||||||
set_segmdesc(gdt + 3, 103, (int) &tss_a, AR_TSS32);
|
task_b->tss.es = 1 * 8;
|
||||||
set_segmdesc(gdt + 4, 103, (int) &tss_b, AR_TSS32);
|
task_b->tss.cs = 2 * 8;
|
||||||
load_tr(3 * 8);
|
task_b->tss.ss = 1 * 8;
|
||||||
task_b_esp = memman_alloc_4k(memman, 64 * 1024) + 64 * 1024 - 8;
|
task_b->tss.ds = 1 * 8;
|
||||||
tss_b.eip = (int) &task_b_main;
|
task_b->tss.fs = 1 * 8;
|
||||||
tss_b.eflags = 0x00000202; /* IF = 1; */
|
task_b->tss.gs = 1 * 8;
|
||||||
tss_b.eax = 0;
|
*((int *) (task_b->tss.esp + 4)) = (int) sht_back;
|
||||||
tss_b.ecx = 0;
|
task_run(task_b);
|
||||||
tss_b.edx = 0;
|
|
||||||
tss_b.ebx = 0;
|
|
||||||
tss_b.esp = task_b_esp;
|
|
||||||
tss_b.ebp = 0;
|
|
||||||
tss_b.esi = 0;
|
|
||||||
tss_b.edi = 0;
|
|
||||||
tss_b.es = 1 * 8;
|
|
||||||
tss_b.cs = 2 * 8;
|
|
||||||
tss_b.ss = 1 * 8;
|
|
||||||
tss_b.ds = 1 * 8;
|
|
||||||
tss_b.fs = 1 * 8;
|
|
||||||
tss_b.gs = 1 * 8;
|
|
||||||
*((int *) (task_b_esp + 4)) = (int) sht_back;
|
|
||||||
mt_init();
|
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
io_cli();
|
io_cli();
|
||||||
|
|||||||
@@ -185,6 +185,26 @@ void timer_settime(struct TIMER *timer, unsigned int timeout);
|
|||||||
void inthandler20(int *esp);
|
void inthandler20(int *esp);
|
||||||
|
|
||||||
/* mtask.c */
|
/* mtask.c */
|
||||||
extern struct TIMER *mt_timer;
|
#define MAX_TASKS 1000 /*最大任务数量*/
|
||||||
void mt_init(void);
|
#define TASK_GDT0 3 /*定义从GDT的几号开始分配给TSS */
|
||||||
void mt_taskswitch(void);
|
struct TSS32 {
|
||||||
|
int backlink, esp0, ss0, esp1, ss1, esp2, ss2, cr3;
|
||||||
|
int eip, eflags, eax, ecx, edx, ebx, esp, ebp, esi, edi;
|
||||||
|
int es, cs, ss, ds, fs, gs;
|
||||||
|
int ldtr, iomap;
|
||||||
|
};
|
||||||
|
struct TASK {
|
||||||
|
int sel, flags; /* sel用来存放GDT的编号*/
|
||||||
|
struct TSS32 tss;
|
||||||
|
};
|
||||||
|
struct TASKCTL {
|
||||||
|
int running; /*正在运行的任务数量*/
|
||||||
|
int now; /*这个变量用来记录当前正在运行的是哪个任务*/
|
||||||
|
struct TASK *tasks[MAX_TASKS];
|
||||||
|
struct TASK tasks0[MAX_TASKS];
|
||||||
|
};
|
||||||
|
extern struct TIMER *task_timer;
|
||||||
|
struct TASK *task_init(struct MEMMAN *memman);
|
||||||
|
struct TASK *task_alloc(void);
|
||||||
|
void task_run(struct TASK *task);
|
||||||
|
void task_switch(void);
|
||||||
|
|||||||
@@ -2,26 +2,78 @@
|
|||||||
|
|
||||||
#include "bootpack.h"
|
#include "bootpack.h"
|
||||||
|
|
||||||
struct TIMER *mt_timer;
|
struct TASKCTL *taskctl;
|
||||||
int mt_tr;
|
struct TIMER *task_timer;
|
||||||
|
|
||||||
void mt_init(void)
|
struct TASK *task_init(struct MEMMAN *memman)
|
||||||
{
|
{
|
||||||
mt_timer = timer_alloc();
|
int i;
|
||||||
/*这里没有必要使用timer_init */
|
struct TASK *task;
|
||||||
timer_settime(mt_timer, 2);
|
struct SEGMENT_DESCRIPTOR *gdt = (struct SEGMENT_DESCRIPTOR *) ADR_GDT;
|
||||||
mt_tr = 3 * 8;
|
taskctl = (struct TASKCTL *) memman_alloc_4k(memman, sizeof (struct TASKCTL));
|
||||||
|
|
||||||
|
for (i = 0; i < MAX_TASKS; i++) {
|
||||||
|
taskctl->tasks0[i].flags = 0;
|
||||||
|
taskctl->tasks0[i].sel = (TASK_GDT0 + i) * 8;
|
||||||
|
set_segmdesc(gdt + TASK_GDT0 + i, 103, (int) &taskctl->tasks0[i].tss, AR_TSS32);
|
||||||
|
}
|
||||||
|
|
||||||
|
task = task_alloc();
|
||||||
|
task->flags = 2; /*活动中标志*/
|
||||||
|
taskctl->running = 1;
|
||||||
|
taskctl->now = 0;
|
||||||
|
taskctl->tasks[0] = task;
|
||||||
|
load_tr(task->sel);
|
||||||
|
task_timer = timer_alloc();
|
||||||
|
timer_settime(task_timer, 2);
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct TASK *task_alloc(void)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
struct TASK *task;
|
||||||
|
for (i = 0; i < MAX_TASKS; i++) {
|
||||||
|
if (taskctl->tasks0[i].flags == 0) {
|
||||||
|
task = &taskctl->tasks0[i];
|
||||||
|
task->flags = 1; /*正在使用的标志*/
|
||||||
|
task->tss.eflags = 0x00000202; /* IF = 1; */
|
||||||
|
task->tss.eax = 0; /*这里先置为0*/
|
||||||
|
task->tss.ecx = 0;
|
||||||
|
task->tss.edx = 0;
|
||||||
|
task->tss.ebx = 0;
|
||||||
|
task->tss.ebp = 0;
|
||||||
|
task->tss.esi = 0;
|
||||||
|
task->tss.edi = 0;
|
||||||
|
task->tss.es = 0;
|
||||||
|
task->tss.ds = 0;
|
||||||
|
task->tss.fs = 0;
|
||||||
|
task->tss.gs = 0;
|
||||||
|
task->tss.ldtr = 0;
|
||||||
|
task->tss.iomap = 0x40000000;
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0; /*全部正在使用*/
|
||||||
|
}
|
||||||
|
|
||||||
|
void task_run(struct TASK *task)
|
||||||
|
{
|
||||||
|
task->flags = 2; /*活动中标志*/
|
||||||
|
taskctl->tasks[taskctl->running] = task;
|
||||||
|
taskctl->running++;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void mt_taskswitch(void)
|
void task_switch(void)
|
||||||
{
|
{
|
||||||
if (mt_tr == 3 * 8) {
|
timer_settime(task_timer, 2);
|
||||||
mt_tr = 4 * 8;
|
if (taskctl->running >= 2) {
|
||||||
} else {
|
taskctl->now++;
|
||||||
mt_tr = 3 * 8;
|
if (taskctl->now == taskctl->running) {
|
||||||
|
taskctl->now = 0;
|
||||||
|
}
|
||||||
|
farjmp(0, taskctl->tasks[taskctl->now]->sel);
|
||||||
}
|
}
|
||||||
timer_settime(mt_timer, 2);
|
|
||||||
farjmp(0, mt_tr);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ void inthandler20(int *esp)
|
|||||||
}
|
}
|
||||||
/* 超时 */
|
/* 超时 */
|
||||||
timer->flags = TIMER_FLAGS_ALLOC;
|
timer->flags = TIMER_FLAGS_ALLOC;
|
||||||
if (timer != mt_timer) {
|
if (timer != task_timer) {
|
||||||
fifo32_put(timer->fifo, timer->data);
|
fifo32_put(timer->fifo, timer->data);
|
||||||
} else {
|
} else {
|
||||||
ts = 1; /* mt_timer超时*/
|
ts = 1; /* mt_timer超时*/
|
||||||
@@ -112,7 +112,7 @@ void inthandler20(int *esp)
|
|||||||
timerctl.t0 = timer;
|
timerctl.t0 = timer;
|
||||||
timerctl.next = timer->timeout;
|
timerctl.next = timer->timeout;
|
||||||
if (ts != 0) {
|
if (ts != 0) {
|
||||||
mt_taskswitch();
|
task_switch();
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user