diff --git a/include/mm/heap.h b/include/mm/heap.h new file mode 100644 index 000000000..5a9fbe96b --- /dev/null +++ b/include/mm/heap.h @@ -0,0 +1,29 @@ +#ifndef HEAP_H +#define HEAP_H + +#define HEAP_MAGIC 0xA0B0C0 + +#include +#include + +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 \ No newline at end of file diff --git a/include/mm/kheap.h b/include/mm/kheap.h new file mode 100644 index 000000000..da3bbd59e --- /dev/null +++ b/include/mm/kheap.h @@ -0,0 +1,17 @@ +#ifndef KHEAP_H +#define KHEAP_H + +#include + +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 \ No newline at end of file diff --git a/include/mm/memory.h b/include/mm/memory.h new file mode 100644 index 000000000..38ec05f58 --- /dev/null +++ b/include/mm/memory.h @@ -0,0 +1,8 @@ +#ifndef MEMORY_H +#define MEMORY_H + +#include +#include +#include + +#endif \ No newline at end of file diff --git a/include/proc/proc.h b/include/proc/proc.h new file mode 100644 index 000000000..0079e17a3 --- /dev/null +++ b/include/proc/proc.h @@ -0,0 +1,72 @@ +#ifndef PROC_H +#define PROC_H + +#include +#include +#include +#include + +#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); \ No newline at end of file diff --git a/include/proc/thread.h b/include/proc/thread.h new file mode 100644 index 000000000..61713e908 --- /dev/null +++ b/include/proc/thread.h @@ -0,0 +1,29 @@ +#ifndef THREAD_H +#define THREAD_H + +#include + +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 \ No newline at end of file