boot: fix crash on early memory allocations
Signed-off-by: Michael Shaw <m@michaelsshaw.com>
This commit is contained in:
parent
be49cc4839
commit
1d1dad34ce
10 changed files with 120 additions and 32 deletions
|
|
@ -105,13 +105,16 @@ _timer_handler:
|
|||
jz 1f
|
||||
swapgs
|
||||
1:
|
||||
mov rdi, gs:[0] /* cur_thread */
|
||||
test rdi, rdi
|
||||
jz .Lno_thread
|
||||
|
||||
sub rsp, 8 /* reserve return address slot */
|
||||
push_all
|
||||
|
||||
lea rax, [rip + 2f]
|
||||
mov [rsp + 120], rax /* return address */
|
||||
|
||||
mov rdi, gs:[0] /* cur_thread */
|
||||
mov [rdi + 8], rsp /* cur_thread->kstack_ptr */
|
||||
call sched_add_thread
|
||||
call lapic_eoi
|
||||
|
|
@ -125,6 +128,14 @@ _timer_handler:
|
|||
3:
|
||||
iretq
|
||||
|
||||
.Lno_thread:
|
||||
call lapic_eoi
|
||||
test qword ptr [rsp + 8], 3
|
||||
jz 4f
|
||||
swapgs
|
||||
4:
|
||||
iretq
|
||||
|
||||
.global sched_restore_state
|
||||
sched_restore_state:
|
||||
mov rsp, [rdi + 8] /* load RSP from thread->kstack_ptr */
|
||||
|
|
|
|||
|
|
@ -116,10 +116,8 @@ void apic_init()
|
|||
lapic_eoi();
|
||||
|
||||
/* Register timer interrupt handler and enable APIC timer */
|
||||
extern int irq_map(uint8_t irq, void *func);
|
||||
|
||||
void _timer_handler();
|
||||
irq_map(0, _timer_handler);
|
||||
idt_insert(0x20, GATE_INTR, 0, GDT_SEGMENT_CODE_RING0, _timer_handler);
|
||||
|
||||
lapic_write(lapic_addr, LAPIC_TPR, 0);
|
||||
lapic_write(lapic_addr, LAPIC_TIMER_DIV, 0x3);
|
||||
|
|
|
|||
16
amd64/idt.c
16
amd64/idt.c
|
|
@ -170,14 +170,14 @@ void idt_init()
|
|||
idt_insert(0x2D, GATE_INTR, 0, GDT_SEGMENT_CODE_RING0, __irq(0x0D));
|
||||
idt_insert(0x2E, GATE_INTR, 0, GDT_SEGMENT_CODE_RING0, __irq(0x0E));
|
||||
idt_insert(0x2F, GATE_INTR, 0, GDT_SEGMENT_CODE_RING0, __irq(0x0F));
|
||||
idt_insert(0x2F, GATE_INTR, 0, GDT_SEGMENT_CODE_RING0, __irq(0x10));
|
||||
idt_insert(0x2F, GATE_INTR, 0, GDT_SEGMENT_CODE_RING0, __irq(0x11));
|
||||
idt_insert(0x2F, GATE_INTR, 0, GDT_SEGMENT_CODE_RING0, __irq(0x12));
|
||||
idt_insert(0x2F, GATE_INTR, 0, GDT_SEGMENT_CODE_RING0, __irq(0x13));
|
||||
idt_insert(0x2F, GATE_INTR, 0, GDT_SEGMENT_CODE_RING0, __irq(0x14));
|
||||
idt_insert(0x2F, GATE_INTR, 0, GDT_SEGMENT_CODE_RING0, __irq(0x15));
|
||||
idt_insert(0x2F, GATE_INTR, 0, GDT_SEGMENT_CODE_RING0, __irq(0x16));
|
||||
idt_insert(0x2F, GATE_INTR, 0, GDT_SEGMENT_CODE_RING0, __irq(0x17));
|
||||
idt_insert(0x30, GATE_INTR, 0, GDT_SEGMENT_CODE_RING0, __irq(0x10));
|
||||
idt_insert(0x31, GATE_INTR, 0, GDT_SEGMENT_CODE_RING0, __irq(0x11));
|
||||
idt_insert(0x32, GATE_INTR, 0, GDT_SEGMENT_CODE_RING0, __irq(0x12));
|
||||
idt_insert(0x33, GATE_INTR, 0, GDT_SEGMENT_CODE_RING0, __irq(0x13));
|
||||
idt_insert(0x34, GATE_INTR, 0, GDT_SEGMENT_CODE_RING0, __irq(0x14));
|
||||
idt_insert(0x35, GATE_INTR, 0, GDT_SEGMENT_CODE_RING0, __irq(0x15));
|
||||
idt_insert(0x36, GATE_INTR, 0, GDT_SEGMENT_CODE_RING0, __irq(0x16));
|
||||
idt_insert(0x37, GATE_INTR, 0, GDT_SEGMENT_CODE_RING0, __irq(0x17));
|
||||
|
||||
__idtr.size = sizeof(__idt) - 1;
|
||||
__idtr.offset = (uint64_t)__idt;
|
||||
|
|
|
|||
Loading…
Reference in a new issue