Process linked list
This commit is contained in:
2
Makefile
2
Makefile
@@ -1,4 +1,4 @@
|
|||||||
SOURCES = src/mem/heap/kheap.c src/mem/paging/vmm.c src/mem/paging/paging.c src/mem/paging/pmm.c src/string/string.c src/io/kbd/ps2.c src/io/serial/serial.c src/io/term/printf.c src/io/term/term.c src/idt/idt.c src/mem/gdt/gdt.c src/mem/misc/utils.c src/time/timer.c src/kmain.c
|
SOURCES = src/sched/scheduler.c src/sched/process.c src/mem/heap/kheap.c src/mem/paging/vmm.c src/mem/paging/paging.c src/mem/paging/pmm.c src/string/string.c src/io/kbd/ps2.c src/io/serial/serial.c src/io/term/printf.c src/io/term/term.c src/idt/idt.c src/mem/gdt/gdt.c src/mem/misc/utils.c src/time/timer.c src/kmain.c
|
||||||
|
|
||||||
build:
|
build:
|
||||||
rm -f *.o
|
rm -f *.o
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include "io/kbd/ps2.h"
|
#include "io/kbd/ps2.h"
|
||||||
#include <kernel.h>
|
#include <kernel.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include "sched/scheduler.h"
|
||||||
|
|
||||||
struct interrupt_descriptor idt[256];
|
struct interrupt_descriptor idt[256];
|
||||||
struct idtr idt_reg;
|
struct idtr idt_reg;
|
||||||
@@ -187,6 +188,7 @@ struct cpu_status_t* interrupt_dispatch(struct cpu_status_t* context)
|
|||||||
case 32:
|
case 32:
|
||||||
//DEBUG("Timer Interrupt");
|
//DEBUG("Timer Interrupt");
|
||||||
ticks++;
|
ticks++;
|
||||||
|
scheduler_schedule();
|
||||||
// Send an EOI so that we can continue having interrupts
|
// Send an EOI so that we can continue having interrupts
|
||||||
outb(0x20, 0x20);
|
outb(0x20, 0x20);
|
||||||
break;
|
break;
|
||||||
|
|||||||
10
src/kmain.c
10
src/kmain.c
@@ -14,6 +14,7 @@
|
|||||||
#include "mem/paging/paging.h"
|
#include "mem/paging/paging.h"
|
||||||
#include "mem/paging/vmm.h"
|
#include "mem/paging/vmm.h"
|
||||||
#include "mem/heap/kheap.h"
|
#include "mem/heap/kheap.h"
|
||||||
|
#include "sched/process.h"
|
||||||
|
|
||||||
// Limine version used
|
// Limine version used
|
||||||
__attribute__((used, section(".limine_requests")))
|
__attribute__((used, section(".limine_requests")))
|
||||||
@@ -76,6 +77,9 @@ const char* splash = "pepperOS version "PEPPEROS_VERSION_MAJOR"."PEPPEROS_VERSIO
|
|||||||
|
|
||||||
struct boot_context boot_ctx;
|
struct boot_context boot_ctx;
|
||||||
|
|
||||||
|
extern struct process_t* processes_list;
|
||||||
|
extern struct process_t* current_process;
|
||||||
|
|
||||||
// This is our entry point
|
// This is our entry point
|
||||||
void kmain()
|
void kmain()
|
||||||
{
|
{
|
||||||
@@ -122,7 +126,11 @@ void kmain()
|
|||||||
{
|
{
|
||||||
printf("testing, attention please %d\n", i);
|
printf("testing, attention please %d\n", i);
|
||||||
}
|
}
|
||||||
// term_scroll();
|
|
||||||
|
struct process_t* pedicel = process_create();
|
||||||
|
|
||||||
|
process_add(&processes_list, pedicel);
|
||||||
|
process_display_list(processes_list);
|
||||||
|
|
||||||
hcf();
|
hcf();
|
||||||
}
|
}
|
||||||
|
|||||||
99
src/sched/process.c
Normal file
99
src/sched/process.c
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
#include <stddef.h>
|
||||||
|
#include "process.h"
|
||||||
|
#include "mem/heap/kheap.h"
|
||||||
|
#include "kernel.h"
|
||||||
|
|
||||||
|
struct process_t* processes_list;
|
||||||
|
struct process_t* current_process;
|
||||||
|
|
||||||
|
void process_init()
|
||||||
|
{
|
||||||
|
processes_list = NULL;
|
||||||
|
current_process = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only for debug
|
||||||
|
void process_display_list(struct process_t* processes_list)
|
||||||
|
{
|
||||||
|
int process_view_id = 0;
|
||||||
|
struct process_t* tmp = processes_list;
|
||||||
|
while (tmp != NULL)
|
||||||
|
{
|
||||||
|
DEBUG("{%d: } -> ", process_view_id);
|
||||||
|
tmp = tmp->next;
|
||||||
|
process_view_id++;
|
||||||
|
}
|
||||||
|
DEBUG("NULL");
|
||||||
|
}
|
||||||
|
|
||||||
|
struct process_t* process_create()
|
||||||
|
{
|
||||||
|
struct process_t* proc = (struct process_t*)kmalloc(sizeof(struct process_t));
|
||||||
|
|
||||||
|
if (!proc) return NULL;
|
||||||
|
|
||||||
|
proc->context = NULL;
|
||||||
|
proc->status = READY;
|
||||||
|
proc->next = NULL;
|
||||||
|
|
||||||
|
return proc;
|
||||||
|
}
|
||||||
|
|
||||||
|
void process_add(struct process_t** processes_list, struct process_t* process)
|
||||||
|
{
|
||||||
|
if (!process) return;
|
||||||
|
process->next = NULL;
|
||||||
|
|
||||||
|
if (*processes_list == NULL)
|
||||||
|
{
|
||||||
|
// List is empty
|
||||||
|
*processes_list = process;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct process_t* tmp = *processes_list;
|
||||||
|
while (tmp->next != NULL)
|
||||||
|
{
|
||||||
|
tmp = tmp->next;
|
||||||
|
}
|
||||||
|
// We're at last process before NULL
|
||||||
|
tmp->next = process;
|
||||||
|
// process->next = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void process_delete(struct process_t** processes_list, struct process_t* process)
|
||||||
|
{
|
||||||
|
if (!processes_list || !*processes_list || !process) return;
|
||||||
|
|
||||||
|
if (*processes_list == process)
|
||||||
|
{
|
||||||
|
// process to delete is at head
|
||||||
|
*processes_list = process->next;
|
||||||
|
process->next = NULL;
|
||||||
|
kfree(process);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct process_t* tmp = *processes_list;
|
||||||
|
while (tmp->next && tmp->next != process)
|
||||||
|
{
|
||||||
|
tmp = tmp->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tmp->next == NULL)
|
||||||
|
{
|
||||||
|
// Didn't find the process
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// We're at process before the one we want to delete
|
||||||
|
tmp->next = process->next;
|
||||||
|
process->next = NULL;
|
||||||
|
kfree(process);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct process_t* process_get_next(struct process_t* process)
|
||||||
|
{
|
||||||
|
if (!process) return NULL;
|
||||||
|
return process->next;
|
||||||
|
}
|
||||||
26
src/sched/process.h
Normal file
26
src/sched/process.h
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
#ifndef PROCESS_H
|
||||||
|
#define PROCESS_H
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
READY,
|
||||||
|
RUNNING,
|
||||||
|
DEAD
|
||||||
|
} status_t;
|
||||||
|
|
||||||
|
struct process_t
|
||||||
|
{
|
||||||
|
status_t status;
|
||||||
|
struct cpu_status_t* context;
|
||||||
|
struct process_t* next;
|
||||||
|
};
|
||||||
|
|
||||||
|
void process_init();
|
||||||
|
struct process_t* process_create();
|
||||||
|
void process_add(struct process_t** processes_list, struct process_t* process);
|
||||||
|
void process_delete(struct process_t** processes_list, struct process_t* process);
|
||||||
|
struct process_t* process_get_next(struct process_t* process);
|
||||||
|
|
||||||
|
void process_display_list(struct process_t* processes_list);
|
||||||
|
|
||||||
|
#endif
|
||||||
9
src/sched/scheduler.c
Normal file
9
src/sched/scheduler.c
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#include "kernel.h"
|
||||||
|
|
||||||
|
extern struct process_t* processes_list;
|
||||||
|
extern struct process_t* current_process;
|
||||||
|
|
||||||
|
void scheduler_schedule()
|
||||||
|
{
|
||||||
|
DEBUG("Scheduler called!");
|
||||||
|
}
|
||||||
6
src/sched/scheduler.h
Normal file
6
src/sched/scheduler.h
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#ifndef SCHEDULER_H
|
||||||
|
#define SCHEDULER_H
|
||||||
|
|
||||||
|
void scheduler_schedule();
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user