forked from PoliEcho-holding-org/kern
Added sti() and cli() assembly wrappers
This commit is contained in:
@@ -11,7 +11,7 @@ TODO
|
|||||||
[x] Paging
|
[x] Paging
|
||||||
[x] Serial monitor
|
[x] Serial monitor
|
||||||
[x] kmalloc()
|
[x] kmalloc()
|
||||||
[ ] Make dedicated asm functions like lidt(), sti(), ...
|
[x] Make dedicated asm functions like lidt(), sti(), ...
|
||||||
[ ] Add something like <errno.h> in the kernel
|
[ ] Add something like <errno.h> in the kernel
|
||||||
[ ] Improve kmalloc() to reduce fragmentation
|
[ ] Improve kmalloc() to reduce fragmentation
|
||||||
[ ] Improve kmalloc() for better alignment
|
[ ] Improve kmalloc() for better alignment
|
||||||
@@ -20,9 +20,10 @@ TODO
|
|||||||
[ ] HPET
|
[ ] HPET
|
||||||
[ ] System calls
|
[ ] System calls
|
||||||
[ ] Userspace
|
[ ] Userspace
|
||||||
[ ] Processes/Tasks
|
[x] Processes/Tasks
|
||||||
[ ] Scheduler
|
[x] Scheduler
|
||||||
[ ] Task switching
|
[ ] Priority scheduler
|
||||||
|
[x] Task switching
|
||||||
[ ] Inter-process communication
|
[ ] Inter-process communication
|
||||||
[ ] Graphics
|
[ ] Graphics
|
||||||
[ ] Multicore support
|
[ ] Multicore support
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
#define _SYSTEM_H
|
#define _SYSTEM_H
|
||||||
|
|
||||||
#include <kernel.h>
|
#include <kernel.h>
|
||||||
|
#include <gdt.h>
|
||||||
|
#include <idt.h>
|
||||||
|
|
||||||
// cpuid
|
// cpuid
|
||||||
void cpuid(uint32_t* eax, uint32_t* ebx, uint32_t* ecx, uint32_t* edx);
|
void cpuid(uint32_t* eax, uint32_t* ebx, uint32_t* ecx, uint32_t* edx);
|
||||||
@@ -15,4 +17,8 @@ void outw(uint16_t port, uint16_t data);
|
|||||||
uint32_t inl(uint16_t port);
|
uint32_t inl(uint16_t port);
|
||||||
void outl(uint16_t port, uint32_t data);
|
void outl(uint16_t port, uint32_t data);
|
||||||
|
|
||||||
|
// x86
|
||||||
|
void cli(void);
|
||||||
|
void sti(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+1
-2
@@ -1,6 +1,5 @@
|
|||||||
#include <syscall.h>
|
#include <syscall.h>
|
||||||
#include <kernel.h>
|
#include <kernel.h>
|
||||||
#include <string.h>
|
|
||||||
#include <system.h>
|
#include <system.h>
|
||||||
#include <idt.h>
|
#include <idt.h>
|
||||||
#include <isr.h>
|
#include <isr.h>
|
||||||
@@ -69,7 +68,7 @@ int isr_init(void) {
|
|||||||
idt_set_gate(0x80, (void*)(uint32_t)isr128, IDT_FLAG_USER);
|
idt_set_gate(0x80, (void*)(uint32_t)isr128, IDT_FLAG_USER);
|
||||||
|
|
||||||
// Let interrupts interrupt
|
// Let interrupts interrupt
|
||||||
__asm__ volatile ("sti");
|
sti();
|
||||||
|
|
||||||
debugf("[isr] ISR initialized.\n");
|
debugf("[isr] ISR initialized.\n");
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -42,3 +42,11 @@ void outl(uint16_t port, uint32_t data) {
|
|||||||
__asm__ volatile ("outl %1, %0" :: "dN"(port), "a"(data));
|
__asm__ volatile ("outl %1, %0" :: "dN"(port), "a"(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cli(void) {
|
||||||
|
__asm__ volatile ("cli");
|
||||||
|
}
|
||||||
|
|
||||||
|
void sti(void) {
|
||||||
|
__asm__ volatile ("sti");
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
+7
-8
@@ -2,6 +2,8 @@
|
|||||||
#include <kernel.h>
|
#include <kernel.h>
|
||||||
#include <paging.h>
|
#include <paging.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <system.h>
|
||||||
|
#include <sched.h>
|
||||||
#include <gdt.h>
|
#include <gdt.h>
|
||||||
#include <isr.h>
|
#include <isr.h>
|
||||||
#include <pmm.h>
|
#include <pmm.h>
|
||||||
@@ -31,7 +33,7 @@ int task_init(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void task_create(size_t id, uint32_t eip, int kernel_task, uint32_t* pagedir, int argc, char** argv) {
|
void task_create(size_t id, uint32_t eip, int kernel_task, uint32_t* pagedir, int argc, char** argv) {
|
||||||
__asm__ volatile ("cli"); // Make sure we don't get interrupted
|
cli();
|
||||||
|
|
||||||
uint32_t kstack = (uint32_t)kmalloc(0x1000 - 16) + (0x1000 - 16);
|
uint32_t kstack = (uint32_t)kmalloc(0x1000 - 16) + (0x1000 - 16);
|
||||||
uint8_t* kesp = (uint8_t*)kstack;
|
uint8_t* kesp = (uint8_t*)kstack;
|
||||||
@@ -82,12 +84,9 @@ void task_create(size_t id, uint32_t eip, int kernel_task, uint32_t* pagedir, in
|
|||||||
new->heap_start = USER_HEAP;
|
new->heap_start = USER_HEAP;
|
||||||
new->heap_end = USER_HEAP;
|
new->heap_end = USER_HEAP;
|
||||||
|
|
||||||
debugf("[task] NEW! Task #%d - EIP = 0x%08x, ESP = 0x%08x%s\n",
|
|
||||||
id, eip, kesp, kernel_task ? " (kernel)" : "");
|
|
||||||
|
|
||||||
// We don't need to setup a stack frame
|
// We don't need to setup a stack frame
|
||||||
if (kernel_task) {
|
if (kernel_task) {
|
||||||
__asm__ volatile ("sti");
|
sti();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,7 +130,7 @@ void task_create(size_t id, uint32_t eip, int kernel_task, uint32_t* pagedir, in
|
|||||||
}
|
}
|
||||||
|
|
||||||
void task_kill(size_t id) {
|
void task_kill(size_t id) {
|
||||||
__asm__ volatile ("cli");
|
cli();
|
||||||
|
|
||||||
struct task* current = task_first;
|
struct task* current = task_first;
|
||||||
while (current != NULL) {
|
while (current != NULL) {
|
||||||
@@ -171,8 +170,8 @@ void task_kill(size_t id) {
|
|||||||
}
|
}
|
||||||
kfree(task);
|
kfree(task);
|
||||||
|
|
||||||
// schedule();
|
schedule();
|
||||||
__asm__ volatile ("sti");
|
sti();
|
||||||
}
|
}
|
||||||
|
|
||||||
void task_set_user_heap(struct task* task, size_t heap_end) {
|
void task_set_user_heap(struct task* task, size_t heap_end) {
|
||||||
|
|||||||
+2
-2
@@ -27,7 +27,7 @@ int pit_init(void) {
|
|||||||
void pit_phase(uint8_t ch, uint8_t mode, uint32_t hz) {
|
void pit_phase(uint8_t ch, uint8_t mode, uint32_t hz) {
|
||||||
if (ch > 2 || mode > 7) return;
|
if (ch > 2 || mode > 7) return;
|
||||||
|
|
||||||
__asm__ volatile ("cli");
|
cli();
|
||||||
|
|
||||||
outb(PIT_CMD, ((ch << 6) | (3 << 4) | (mode << 1)));
|
outb(PIT_CMD, ((ch << 6) | (3 << 4) | (mode << 1)));
|
||||||
|
|
||||||
@@ -36,7 +36,7 @@ void pit_phase(uint8_t ch, uint8_t mode, uint32_t hz) {
|
|||||||
outb(PIT_CH0 + ch, div >> 8);
|
outb(PIT_CH0 + ch, div >> 8);
|
||||||
debugf("[PIT] Set PIT divisor to %d (%d Hz).\n", div, hz);
|
debugf("[PIT] Set PIT divisor to %d (%d Hz).\n", div, hz);
|
||||||
|
|
||||||
__asm__ volatile ("sti");
|
sti();
|
||||||
}
|
}
|
||||||
|
|
||||||
void pit_handler(struct isr_int_frame* iframe) {
|
void pit_handler(struct isr_int_frame* iframe) {
|
||||||
|
|||||||
Reference in New Issue
Block a user