process #9
@@ -188,7 +188,12 @@ struct cpu_status_t* interrupt_dispatch(struct cpu_status_t* context)
|
||||
case 32:
|
||||
//DEBUG("Timer Interrupt");
|
||||
ticks++;
|
||||
scheduler_schedule();
|
||||
if (ticks % SCHEDULER_QUANTUM == 0)
|
||||
{
|
||||
CLEAR_INTERRUPTS;
|
||||
scheduler_schedule();
|
||||
SET_INTERRUPTS;
|
||||
}
|
||||
// Send an EOI so that we can continue having interrupts
|
||||
outb(0x20, 0x20);
|
||||
break;
|
||||
|
||||
@@ -36,4 +36,7 @@ struct boot_context
|
||||
struct limine_kernel_address_response* kaddr;
|
||||
};
|
||||
|
||||
// 1 tick = 1 ms => quantum = 10ms
|
||||
#define SCHEDULER_QUANTUM 10
|
||||
|
||||
#endif
|
||||
|
||||
27
src/kmain.c
27
src/kmain.c
@@ -15,6 +15,7 @@
|
||||
#include "mem/paging/vmm.h"
|
||||
#include "mem/heap/kheap.h"
|
||||
#include "sched/process.h"
|
||||
#include "sched/scheduler.h"
|
||||
|
||||
// Limine version used
|
||||
__attribute__((used, section(".limine_requests")))
|
||||
@@ -57,6 +58,7 @@ static volatile LIMINE_REQUESTS_END_MARKER;
|
||||
// Panic (should dump registers etc. in the future)
|
||||
void hcf()
|
||||
{
|
||||
//CLEAR_INTERRUPTS;
|
||||
for (;;)
|
||||
{
|
||||
asm("hlt");
|
||||
@@ -101,7 +103,6 @@ void kmain()
|
||||
gdt_init();
|
||||
idt_init();
|
||||
timer_init();
|
||||
SET_INTERRUPTS;
|
||||
|
||||
pmm_init(boot_ctx.mmap, boot_ctx.hhdm);
|
||||
|
||||
@@ -116,21 +117,23 @@ void kmain()
|
||||
void* ptr3 = kmalloc(5); DEBUG("(KMALLOC TEST) Allocated 5 bytes at 0x%p", ptr3);
|
||||
|
||||
vmm_init();
|
||||
|
||||
struct process_t* pedicel = process_create();
|
||||
struct process_t* two = process_create();
|
||||
struct process_t* three = process_create();
|
||||
|
||||
process_add(&processes_list, pedicel);
|
||||
process_add(&processes_list, two);
|
||||
process_add(&processes_list, three);
|
||||
process_display_list(processes_list);
|
||||
|
||||
scheduler_init();
|
||||
|
||||
SET_INTERRUPTS;
|
||||
|
||||
keyboard_init(FR);
|
||||
|
||||
term_init();
|
||||
kputs(splash);
|
||||
|
||||
for (int i=0; i<10; i++)
|
||||
{
|
||||
printf("testing, attention please %d\n", i);
|
||||
}
|
||||
|
||||
struct process_t* pedicel = process_create();
|
||||
|
||||
process_add(&processes_list, pedicel);
|
||||
process_display_list(processes_list);
|
||||
|
||||
hcf();
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ void process_display_list(struct process_t* processes_list)
|
||||
struct process_t* tmp = processes_list;
|
||||
while (tmp != NULL)
|
||||
{
|
||||
DEBUG("{%d: } -> ", process_view_id);
|
||||
DEBUG("{%d: %p} -> ", process_view_id, tmp);
|
||||
tmp = tmp->next;
|
||||
process_view_id++;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,35 @@
|
||||
#include "kernel.h"
|
||||
#include "process.h"
|
||||
|
||||
extern struct process_t* processes_list;
|
||||
extern struct process_t* current_process;
|
||||
|
||||
// DEBUG: how many times we did schedule
|
||||
int scheduled = 0;
|
||||
|
||||
void scheduler_init()
|
||||
{
|
||||
// Choose first process?
|
||||
current_process = processes_list;
|
||||
}
|
||||
|
||||
void scheduler_schedule()
|
||||
{
|
||||
DEBUG("Scheduler called!");
|
||||
//DEBUG("Scheduler called!");
|
||||
if (current_process->next != NULL)
|
||||
{
|
||||
current_process = current_process->next;
|
||||
} else
|
||||
{
|
||||
current_process = processes_list;
|
||||
}
|
||||
scheduled++;
|
||||
DEBUG("SCHEDULER CALLED: current_process=%p", current_process);
|
||||
|
||||
// debug
|
||||
/* if (scheduled == 5)
|
||||
{
|
||||
DEBUG("enough, halting");
|
||||
hcf();
|
||||
} */
|
||||
}
|
||||
@@ -2,5 +2,6 @@
|
||||
#define SCHEDULER_H
|
||||
|
||||
void scheduler_schedule();
|
||||
void scheduler_init();
|
||||
|
||||
#endif
|
||||
@@ -1,6 +1,19 @@
|
||||
#include <stddef.h>
|
||||
|
||||
char* strcpy(char *dest, const char *src)
|
||||
{
|
||||
char *temp = dest;
|
||||
while((*dest++ = *src++));
|
||||
return temp;
|
||||
}
|
||||
|
||||
// https://stackoverflow.com/questions/2488563/strcat-implementation
|
||||
char *strcat(char *dest, const char *src){
|
||||
size_t i,j;
|
||||
for (i = 0; dest[i] != '\0'; i++)
|
||||
;
|
||||
for (j = 0; src[j] != '\0'; j++)
|
||||
dest[i+j] = src[j];
|
||||
dest[i+j] = '\0';
|
||||
return dest;
|
||||
}
|
||||
@@ -2,5 +2,6 @@
|
||||
#define STRING_H
|
||||
|
||||
char *strcpy(char *dest, const char *src);
|
||||
char *strcat(char *dest, const char *src);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user