/* Copyright (C) 2021 Rain */ /* This file is part of XNIX. */ /* XNIX is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) and later version. */ /* XNIX is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. */ /* You should have received a copy of the GNU General Public License along with XNIX. If not, see . */ #include #include #include #include #include #include #include #include #include #include #include #include struct task init_task; struct task *current; struct task *task_queues[16]; __uint32_t next_pid = 0; int task_init(void) { /* initial the init-tss */ init_tss.rsp0 = init_tss.rsp1 = init_tss.rsp2 = get_rsp(); init_tss.ist1 = init_tss.ist2 = init_tss.ist3 = get_rsp(); init_tss.ist4 = init_tss.ist5 = init_tss.ist6 = get_rsp(); init_tss.ist7 = get_rsp(); set_tss(&init_tss, 0); /* initial the task struct for init task */ memset(&init_task, 0x00, sizeof(struct task)); next_pid++; init_task.state = STATE_RUNNING; init_task.ktime = init_task.utime = 0; /* min priority */ init_task.priority = 15; init_task.signal = 0; /* init_task can't have any signals */ init_task.signal_mask = 0xffffffff; init_task.exit_code = 0; init_task.pid = init_task.father = INIT_PID; init_task.tss = &init_tss; init_task.cr3 = PAGE_TABLE_BASE; init_task.rsp0 = get_rsp(); init_task.rsp = get_rsp(); init_task.dataseg = KERNEL_DS; init_task.codeseg = KERNEL_CS; init_task.rip = 0; /* copy registers to top of its stack */ init_task.next = NULL; current = &init_task; task_queues[15] = &init_task; // switch_to(&init_task); return 0; } int ktask_create(__uint64_t (* entry) (__uint64_t), __uint64_t arg) { return 0; } void do_clock(void) { printk(0x00ff0000, 0x00000000, "%d\n", jiffies / 100); return; } void set_tss(struct tss *table, __uint64_t dpl) { __uint64_t tss = (__uint64_t) table; /* create a descriptor (in gdt) and register it */ struct tss_entry *entry = (struct tss_entry *) (gdt_table + 5); entry->low = entry->high = 0x0000000000000000; /* `103` is the size of a tss table */ entry->low = 103ul | ((tss & 0xffff) << 16) | (((tss >> 16) & 0xff) << 32) | ((0x80 + dpl + 0x09) << 40) | (tss << 56 & 0xff); entry->high = (tss >> 32) & 0xffffffff; /* load it to tr */ ltr(40); return; }