sched: irq: move all IRQs to new scheduling system
This commit is contained in:
parent
ce4c1aaf40
commit
6ad5fe88b2
2 changed files with 87 additions and 65 deletions
121
sched/entry.S
121
sched/entry.S
|
|
@ -69,11 +69,65 @@
|
||||||
.global _irq_\nr
|
.global _irq_\nr
|
||||||
_irq_\nr:
|
_irq_\nr:
|
||||||
cli
|
cli
|
||||||
push_regs
|
/* push scratch registers */
|
||||||
|
pushq %rax
|
||||||
|
pushq %rcx
|
||||||
|
pushq %rdx
|
||||||
|
pushq %rsi
|
||||||
|
pushq %rdi
|
||||||
|
pushq %r8
|
||||||
|
pushq %r9
|
||||||
|
pushq %r10
|
||||||
|
pushq %r11
|
||||||
|
|
||||||
|
/* get current task registers */
|
||||||
|
call proc_current_regs
|
||||||
|
|
||||||
|
/* save current task registers */
|
||||||
|
popq %rdi
|
||||||
|
movq %rdi, 80(%rax) /* r11 */
|
||||||
|
popq %rdi
|
||||||
|
movq %rdi, 72(%rax) /* r10 */
|
||||||
|
popq %rdi
|
||||||
|
movq %rdi, 64(%rax) /* r9 */
|
||||||
|
popq %rdi
|
||||||
|
movq %rdi, 56(%rax) /* r8 */
|
||||||
|
popq %rdi
|
||||||
|
movq %rdi, 40(%rax) /* rdi */
|
||||||
|
popq %rdi
|
||||||
|
movq %rdi, 32(%rax) /* rsi */
|
||||||
|
popq %rdi
|
||||||
|
movq %rdi, 24(%rax) /* rdx */
|
||||||
|
popq %rdi
|
||||||
|
movq %rdi, 16(%rax) /* rcx */
|
||||||
|
popq %rdi
|
||||||
|
movq %rdi, 0(%rax) /* rax */
|
||||||
|
|
||||||
|
/* save remaining registers */
|
||||||
|
movq %rbx, 8(%rax)
|
||||||
|
movq %rbp, 48(%rax)
|
||||||
|
movq %r12, 88(%rax)
|
||||||
|
movq %r13, 96(%rax)
|
||||||
|
movq %r14, 104(%rax)
|
||||||
|
movq %r15, 112(%rax)
|
||||||
|
|
||||||
|
/* save IRETQ frame */
|
||||||
|
popq %rdi
|
||||||
|
movq %rdi, 120(%rax)
|
||||||
|
popq %rdi
|
||||||
|
movq %rdi, 128(%rax)
|
||||||
|
popq %rdi
|
||||||
|
movq %rdi, 136(%rax)
|
||||||
|
popq %rdi
|
||||||
|
movq %rdi, 144(%rax)
|
||||||
|
popq %rdi
|
||||||
|
movq %rdi, 152(%rax)
|
||||||
|
|
||||||
|
/* call irq handler */
|
||||||
movq $\nr, %rdi
|
movq $\nr, %rdi
|
||||||
call irq
|
call irq
|
||||||
pop_regs
|
|
||||||
iretq
|
call schedule
|
||||||
.endm
|
.endm
|
||||||
|
|
||||||
.global sti
|
.global sti
|
||||||
|
|
@ -136,66 +190,9 @@ irq 0x0D
|
||||||
irq 0x0E
|
irq 0x0E
|
||||||
irq 0x0F
|
irq 0x0F
|
||||||
|
|
||||||
.global _irq_schedule
|
|
||||||
_irq_schedule:
|
|
||||||
cli
|
|
||||||
/* push scratch registers */
|
|
||||||
pushq %rax
|
|
||||||
pushq %rcx
|
|
||||||
pushq %rdx
|
|
||||||
pushq %rsi
|
|
||||||
pushq %rdi
|
|
||||||
pushq %r8
|
|
||||||
pushq %r9
|
|
||||||
pushq %r10
|
|
||||||
pushq %r11
|
|
||||||
|
|
||||||
/* get current task registers */
|
|
||||||
call proc_current_regs
|
|
||||||
|
|
||||||
/* save current task registers */
|
|
||||||
popq %rdi
|
|
||||||
movq %rdi, 80(%rax) /* r11 */
|
|
||||||
popq %rdi
|
|
||||||
movq %rdi, 72(%rax) /* r10 */
|
|
||||||
popq %rdi
|
|
||||||
movq %rdi, 64(%rax) /* r9 */
|
|
||||||
popq %rdi
|
|
||||||
movq %rdi, 56(%rax) /* r8 */
|
|
||||||
popq %rdi
|
|
||||||
movq %rdi, 40(%rax) /* rdi */
|
|
||||||
popq %rdi
|
|
||||||
movq %rdi, 32(%rax) /* rsi */
|
|
||||||
popq %rdi
|
|
||||||
movq %rdi, 24(%rax) /* rdx */
|
|
||||||
popq %rdi
|
|
||||||
movq %rdi, 16(%rax) /* rcx */
|
|
||||||
popq %rdi
|
|
||||||
movq %rdi, 0(%rax) /* rax */
|
|
||||||
|
|
||||||
/* save remaining registers */
|
|
||||||
movq %rbx, 8(%rax)
|
|
||||||
movq %rbp, 48(%rax)
|
|
||||||
movq %r12, 88(%rax)
|
|
||||||
movq %r13, 96(%rax)
|
|
||||||
movq %r14, 104(%rax)
|
|
||||||
movq %r15, 112(%rax)
|
|
||||||
|
|
||||||
/* save IRETQ frame */
|
|
||||||
popq %rdi
|
|
||||||
movq %rdi, 120(%rax)
|
|
||||||
popq %rdi
|
|
||||||
movq %rdi, 128(%rax)
|
|
||||||
popq %rdi
|
|
||||||
movq %rdi, 136(%rax)
|
|
||||||
popq %rdi
|
|
||||||
movq %rdi, 144(%rax)
|
|
||||||
popq %rdi
|
|
||||||
movq %rdi, 152(%rax)
|
|
||||||
|
|
||||||
/* void return_from_irq(struct procregs *regs, paddr_t cr3); */
|
/* void return_from_irq(struct procregs *regs, paddr_t cr3); */
|
||||||
.global return_from_irq
|
.global _return_to_user
|
||||||
return_from_irq:
|
_return_to_user:
|
||||||
/* restore IRETQ frame */
|
/* restore IRETQ frame */
|
||||||
pushq 152(%rdi)
|
pushq 152(%rdi)
|
||||||
pushq 144(%rdi)
|
pushq 144(%rdi)
|
||||||
|
|
|
||||||
27
sched/proc.c
27
sched/proc.c
|
|
@ -8,7 +8,7 @@
|
||||||
static struct rbtree *proc_tree;
|
static struct rbtree *proc_tree;
|
||||||
static pid_t *proc_current;
|
static pid_t *proc_current;
|
||||||
|
|
||||||
void return_to_user(struct procregs *regs, paddr_t cr3);
|
void _return_to_user(struct procregs *regs, paddr_t cr3);
|
||||||
|
|
||||||
struct procregs *proc_current_regs()
|
struct procregs *proc_current_regs()
|
||||||
{
|
{
|
||||||
|
|
@ -23,6 +23,31 @@ struct procregs *proc_current_regs()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct proc *proc_find(pid_t pid)
|
||||||
|
{
|
||||||
|
struct rbnode *proc_node = rbt_search(proc_tree, pid);
|
||||||
|
|
||||||
|
if (proc_node) {
|
||||||
|
return (void *)proc_node->value;
|
||||||
|
} else {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void schedule()
|
||||||
|
{
|
||||||
|
uint8_t id = lapic_idno();
|
||||||
|
|
||||||
|
struct proc *proc = proc_find(proc_current[id]);
|
||||||
|
|
||||||
|
if(proc) {
|
||||||
|
_return_to_user(&proc->regs, proc->cr3);
|
||||||
|
} else {
|
||||||
|
kprintf(LOG_ERROR "proc: schedule: proc_current[%u] is NULL\n", id);
|
||||||
|
panic();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void proc_init(unsigned num_cpus)
|
void proc_init(unsigned num_cpus)
|
||||||
{
|
{
|
||||||
/* allocate current process structs */
|
/* allocate current process structs */
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue