-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4c9e504
commit 46d6f75
Showing
5 changed files
with
155 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#ifndef HEAP_H | ||
#define HEAP_H | ||
|
||
#define HEAP_MAGIC 0xA0B0C0 | ||
|
||
#include <types.h> | ||
#include <mm/paging.h> | ||
|
||
typedef struct heap_header { | ||
int magic; // sanity check: 0xA0B0C0 | ||
size_t size; | ||
int is_free; | ||
struct heap_header *next; | ||
} heap_header_t; | ||
|
||
typedef struct { | ||
size_t size; | ||
vmm_addr_t *start; | ||
size_t used; | ||
heap_header_t *first_header; | ||
} heap_info_t; | ||
|
||
void heap_init(vmm_addr_t *addr); | ||
void *umalloc(size_t len, vmm_addr_t *heap); | ||
void ufree(void *ptr, vmm_addr_t *heap); | ||
void *umalloc_sys(size_t len); | ||
void ufree_sys(void *ptr); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#ifndef KHEAP_H | ||
#define KHEAP_H | ||
|
||
#include <mm/heap.h> | ||
|
||
void kheap_init(); | ||
void *kmalloc(size_t len); | ||
void kfree(void *ptr); | ||
|
||
void *first_free(size_t len); | ||
|
||
int get_heap_size(); | ||
int get_used_heap(); | ||
|
||
void print_header(heap_header_t *head); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#ifndef MEMORY_H | ||
#define MEMORY_H | ||
|
||
#include <mm/kheap.h> | ||
#include <mm/mm.h> | ||
#include <mm/paging.h> | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#ifndef PROC_H | ||
#define PROC_H | ||
|
||
#include <hal/tss.h> | ||
#include <mm/memory.h> | ||
#include <types.h> | ||
#include <proc/thread.h> | ||
|
||
#define PROC_NULL -1 | ||
|
||
#define PROC_STOPPED 0 | ||
#define PROC_ACTIVE 1 | ||
#define PROC_NEW 2 | ||
|
||
#define RETURN_ADDR 0x400000 | ||
|
||
struct regs { | ||
uint32_t ds; | ||
uint32_t es; | ||
uint32_t fs; | ||
uint32_t gs; | ||
uint32_t edi; | ||
uint32_t esi; | ||
uint32_t ebp; | ||
uint32_t esp; | ||
uint32_t ebx; | ||
uint32_t edx; | ||
uint32_t ecx; | ||
uint32_t eax; | ||
uint32_t eip; | ||
uint32_t cs; | ||
}; | ||
|
||
struct regs_error { | ||
uint32_t ds; | ||
uint32_t es; | ||
uint32_t fs; | ||
uint32_t gs; | ||
uint32_t edi; | ||
uint32_t esi; | ||
uint32_t ebp; | ||
uint32_t esp; | ||
uint32_t ebx; | ||
uint32_t edx; | ||
uint32_t ecx; | ||
uint32_t eax; | ||
uint32_t error; | ||
uint32_t eip; | ||
uint32_t cs; | ||
}; | ||
|
||
typedef struct proc { | ||
char name[16]; | ||
int state; | ||
page_dir_t *pdir; | ||
int threads; | ||
thread_t *thread_list; | ||
struct proc *next; | ||
struct proc *prec; | ||
} process_t; | ||
|
||
extern void end_process(); | ||
|
||
int start_proc(char *name, char *arguments); | ||
int build_stack(thread_t *thread, page_dir_t *pdir, int nthreads); | ||
int heap_fill(thread_t *thread, char *name, char *arguments, uint32_t *argc, uint32_t *argv1); | ||
int stack_fill(thread_t *thread, uint32_t argc, uint32_t argv); | ||
int build_heap(thread_t *thread, page_dir_t *pdir, int nthreads); | ||
void end_proc(int ret); | ||
void remove_proc(int pid); | ||
int start_kernel_proc(char *name, void *addr); | ||
int proc_state(int id); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#ifndef THREAD_H | ||
#define THREAD_H | ||
|
||
#include <types.h> | ||
|
||
typedef struct thread { | ||
pid_t pid; // thread id | ||
int time; // thread's time slice in ms | ||
int main; // if it's the main thread | ||
int state; // thread's state | ||
void *parent; // pointer to proc | ||
uint32_t eip; // start instruction pointer | ||
uint32_t esp; // start thread's stack pointer | ||
uint32_t stack_limit; // thread's stack limit pointer | ||
uint32_t esp_kernel; // thread's kernel stack pointer | ||
uint32_t stack_kernel_limit; // thread's kernel stack limit | ||
uint32_t heap; // thread's heap pointer | ||
uint32_t heap_limit; // thread's heap limit pointer | ||
uint32_t image_base; | ||
uint32_t image_size; | ||
struct thread *next; | ||
struct thread *prec; | ||
} thread_t; | ||
|
||
thread_t *create_thread(); | ||
int start_thread(); | ||
void stop_thread(int code); | ||
|
||
#endif |