int cnt = 0;
pid_t id = sysc_getpid();
+ // 赋予不同的优先级
+ current->priority = id * 30;
+ if (current->priority <= 0) {
+ current->priority = 1;
+ }
+ if (current->priority > 100) {
+ current->priority = 100;
+ }
+
while (1) {
sysc_test();
printl(MPL_TASK_1 + id - 1, "task:%d [%08x] weight %d cnt %d", id, current, current->weight, cnt++);
regs.ds = SELECTOR_KRNL_DS;
regs.es = SELECTOR_KRNL_DS;
regs.ss = SELECTOR_KRNL_DS;
+ regs.fs = SELECTOR_KRNL_DS;
+ regs.gs = SELECTOR_KRNL_DS;
int pid = do_fork(®s, FORK_KRNL);
- printk("kernel task pid is %d\n", pid);
+ printk("kernel[%s] task pid is %d\n", name, pid);
}
void root_task_entry() {
+ sti();
+
kernel_task("init", init_task_entry);
+ kernel_task("test", init_task_entry);
// kernel_task(user_task_entry);
- // kernel_task(init_task_entry);
int cnt = 0;
while (1) {
printl(MPL_ROOT, "root:0 [%08x] weight %d cnt %d", current, root_task.weight, cnt++);
// printk("root:0 [%08x] weight %d cnt %d", current, current->weight, cnt++);
asm("sti;hlt;");
+ // asm("nop;nop;nop;");
sysc_test();
// syscall0(SYSC_TEST);
}
#include "init.h"
#include "mm.h"
#include "msr.h"
+#include "system.h"
task_union root_task __attribute__((__aligned__(PAGE_SIZE)));
void init_root_tsk() {
int i;
- // never use memset to init root_task
- // because the stack is at top of the root_task
- // memset((char*)&root_task, 0, sizeof(root_task));
-
root_task.preempt_cnt = 0;
root_task.pid = get_next_pid();
root_task.ppid = 0;
root_task.cr3 = (unsigned long)init_pgd;
tss.esp0 = root_task.esp0;
+
wrmsr(MSR_SYSENTER_ESP, root_task.esp0, 0);
printk("init_root_task tss.esp0 %08x\n", tss.esp0);
static const char *task_state(unsigned int state) {
static const char s[][16] = {
- " ERROR",
- "RUNNING",
- " WAIT",
- "EXITING",
+ " ERROR", "RUNNING", " WAIT", "INITING", "EXITING",
};
if (state >= TASK_END) state = TASK_UNUSED;
task_union *next = sel;
if (prev != next) {
+ // printk("switch to: %s:%d\n", next->name, next->pid);
context_switch(prev, next);
}
}
extern void init_i8259();
init_i8259();
- int i;
- for (i = 0; i < NR_IRQS; i++) {
+ for (int i = 0; i < NR_IRQS; i++) {
irq_desc[i] = no_irq_desc;
- if (i < 16) irq_desc[i].chip = &i8259_chip;
+ if (i < 16) {
+ irq_desc[i].chip = &i8259_chip;
+ }
}
void kbd_handler(unsigned int irq, pt_regs_t *regs, void *dev_id);
request_irq(0x01, kbd_handler, "Intel 8042", "PS/2 Keyboard");
request_irq(0x0A, default_ide_irq_handler, "hard", "IDE");
request_irq(0x0E, default_ide_irq_handler, "hard", "IDE");
- for (i = 0; i < 16; i++) {
- if (i != 0 && i != 1 && i != 10 && i != 14) request_irq(i, default_irq_handler, "default", "default");
+ for (int i = 0; i < 16; i++) {
+ if (i != 0 && i != 1 && i != 10 && i != 14) {
+ request_irq(i, default_irq_handler, "default", "default");
+ }
}
- for (i = 0; i < 16; i++) open_irq(i);
+ for (int i = 0; i < 16; i++) {
+ close_irq(i);
+ }
- enable_irq();
+ open_irq(0x00);
+ open_irq(0x01);
+ open_irq(0x0A);
+ open_irq(0x0E);
}
void set_tss() {
pTSS p = &tss;
}
void memset(void *dest, char ch, size_t size) {
- char *d = (char *)dest;
- while (size--) *d++ = ch;
+ char *p = (char *)dest;
+ for (size_t i = 0; i < size; i++) {
+ *p = ch;
+ p++;
+ }
}
int memcmp(const void *a, const void *b, size_t count) {