mirror of
https://github.com/Tom-on64/kern.git
synced 2026-11-03 18:22:22 +00:00
IMPLEMENTED TASKS!
This commit is contained in:
@@ -6,8 +6,8 @@
|
||||
// Interrupt frame (ie. what's on the stack on interrupt)
|
||||
struct isr_int_frame {
|
||||
// Pushed by OS
|
||||
uint32_t esp, ebx, ecx, edx, esi, edi, ebp;
|
||||
uint32_t ds, es, fs, gs, eax;
|
||||
uint32_t gs, fs, es, ds;
|
||||
uint32_t edi, esi, ebp, esp, ebx, edx, ecx, eax;
|
||||
uint32_t interrupt, error;
|
||||
|
||||
// Pushed by CPU
|
||||
@@ -20,6 +20,7 @@ void isr_register(uint8_t i, isr_handler_ptr handler);
|
||||
int isr_handle_interrupt(struct isr_int_frame iframe);
|
||||
|
||||
// Assembly definitions (isr.s)
|
||||
extern void isr_return(void);
|
||||
extern void* isr_redirect_table[48]; // ISR Table
|
||||
extern void isr128(); // int 0x80 - syscall
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ void pag_register_temp_frame(uint32_t target);
|
||||
uint32_t pag_temp_frame(void);
|
||||
void pag_map(uint32_t vaddr, uint32_t paddr, uint32_t flags);
|
||||
uint32_t pag_umap(uint32_t vaddr);
|
||||
void* pag_virt_to_phys(uint32_t vaddr);
|
||||
uint32_t pag_virt_to_phys(uint32_t vaddr);
|
||||
uint32_t* pag_get_pagedir();
|
||||
void pag_set_pagedir(uint32_t* pagedir);
|
||||
void pag_sync_pagedir();
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
extern bitmap_t pmm_bitmap;
|
||||
|
||||
int pmm_init(void);
|
||||
void* pmm_alloc(void);
|
||||
void pmm_free(void* page);
|
||||
uint32_t pmm_alloc(void);
|
||||
void pmm_free(uint32_t page);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
#ifndef _TASK_H
|
||||
#define _TASK_H
|
||||
|
||||
#include <kernel.h>
|
||||
|
||||
#define TASK_KERNEL 0 // Main kernel task ID
|
||||
|
||||
enum {
|
||||
TASK_STATE_DEAD,
|
||||
TASK_STATE_IDLE,
|
||||
TASK_STATE_READY,
|
||||
};
|
||||
|
||||
/*
|
||||
* Each task has an ID. This is used as a reference to the task.
|
||||
* A task has it's own paging setup, so it must have it's own pagedir.
|
||||
* Tasks have state. These states are defined as follows:
|
||||
* TASK_STATE_DEAD - This task has been killed
|
||||
* TASK_STATE_READY - This task is ready for scheduling
|
||||
* TASK_STATE_IDLE - This task doesn't need processor time
|
||||
* Each task has it's own kernel stack to push registers and such to when
|
||||
* context switching. To switch to a task, you load kstack_pointer into ESP and
|
||||
* pop the state.
|
||||
* The kstack_bottom is loaded into ESP using the TSS when switching from user
|
||||
* to kernel space on interrupts.
|
||||
* Tasks are stored in a linked list, so it must have a reference to the next
|
||||
* task.
|
||||
*
|
||||
* WARN: Be careful when modifing this struct, it's contents are accessed from
|
||||
* task.s which uses hardcoded offsets.
|
||||
*/
|
||||
struct task {
|
||||
size_t id;
|
||||
|
||||
size_t kstack_pointer;
|
||||
size_t kstack_bottom;
|
||||
|
||||
uint32_t* pagedir;
|
||||
uint8_t state;
|
||||
int kernel_task;
|
||||
|
||||
size_t heap_start;
|
||||
size_t heap_end;
|
||||
|
||||
struct task* next;
|
||||
};
|
||||
|
||||
// Describes contents of the kstack when task switching
|
||||
struct task_switch_ctx {
|
||||
uint32_t edi;
|
||||
uint32_t esi;
|
||||
uint32_t ebx;
|
||||
uint32_t ebp;
|
||||
uint32_t eip;
|
||||
};
|
||||
|
||||
extern struct task* task_first;
|
||||
extern struct task* task_current;
|
||||
|
||||
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_kill(size_t id);
|
||||
void task_set_user_heap(struct task* task, size_t heap_end);
|
||||
struct task* task_get(size_t id);
|
||||
uint8_t task_get_state(size_t id);
|
||||
void task_set_state(size_t id, uint8_t state);
|
||||
size_t task_create_id(void);
|
||||
|
||||
// Defined in task.s
|
||||
extern void task_switch(struct task* old, struct task* new);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user