aboutsummaryrefslogtreecommitdiff
path: root/kernel/include
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/include')
-rw-r--r--kernel/include/buffer.h40
-rw-r--r--kernel/include/dbglog.h9
-rw-r--r--kernel/include/frame.h14
-rw-r--r--kernel/include/gdt.h17
-rw-r--r--kernel/include/hashtbl.h34
-rw-r--r--kernel/include/idt.h79
-rw-r--r--kernel/include/kmalloc.h14
-rw-r--r--kernel/include/multiboot.h63
-rw-r--r--kernel/include/mutex.h21
-rw-r--r--kernel/include/paging.h31
-rw-r--r--kernel/include/printf.h10
-rw-r--r--kernel/include/region.h38
-rw-r--r--kernel/include/slab_alloc.h44
-rw-r--r--kernel/include/string.h17
-rw-r--r--kernel/include/sys.h57
-rw-r--r--kernel/include/thread.h46
16 files changed, 0 insertions, 534 deletions
diff --git a/kernel/include/buffer.h b/kernel/include/buffer.h
deleted file mode 100644
index c47e2b4..0000000
--- a/kernel/include/buffer.h
+++ /dev/null
@@ -1,40 +0,0 @@
-#pragma once
-
-#include <stdint.h>
-#include <stddef.h>
-
-// The buffer_t type is a simple reference-counted buffer type
-// enabling the creation, sharing, slicing and concatenation of buffers
-// without having to copy everything each time
-
-// Buffers are always allocated on the core kernel heap (kmalloc/kfree)
-
-// Once a buffer is allocated, its contents is immutable
-
-// Encoding and decoding functions for buffer contents are provided in
-// a separate file (encode.h)
-
-struct buffer;
-typedef struct buffer buffer_t;
-
-void buffer_ref(buffer_t*); // increase reference counter
-void buffer_unref(buffer_t*); // decrease reference counter
-
-size_t buffer_len(buffer_t* buf);
-size_t read_buffer(buffer_t* buf, char* to, size_t begin, size_t n); // returns num of bytes read
-
-buffer_t* buffer_from_bytes(const char* data, size_t n); // bytes are COPIED
-buffer_t* buffer_from_bytes_nocopy(const char* data, size_t n, bool own_bytes); // bytes are NOT COPIED
-
-// these functions GIVE the buffer in order to create the new buffer, ie they do not increase RC
-// the buffer is NOT GIVED if the new buffer could not be created (ie retval == 0)
-buffer_t* buffer_slice(buffer_t* b, size_t begin, size_t n);
-buffer_t* buffer_concat(buffer_t* a, buffer_t* b);
-
-// these functions KEEP a reference on the buffer (ie RC is incremented)
-// the RC is NOT INCREMENTED if the new buffer cannot be created
-buffer_t* buffer_slice_k(buffer_t* b, size_t begin, size_t n);
-buffer_t* buffer_concat_k(buffer_t* a, buffer_t* b);
-
-
-/* vim: set ts=4 sw=4 tw=0 noet :*/
diff --git a/kernel/include/dbglog.h b/kernel/include/dbglog.h
deleted file mode 100644
index 2f670e8..0000000
--- a/kernel/include/dbglog.h
+++ /dev/null
@@ -1,9 +0,0 @@
-#pragma once
-
-#include <config.h>
-
-void dbglog_setup();
-void dbg_print(const char* str);
-void dbg_printf(const char* format, ...);
-
-/* vim: set ts=4 sw=4 tw=0 noet :*/
diff --git a/kernel/include/frame.h b/kernel/include/frame.h
deleted file mode 100644
index 9ffafb3..0000000
--- a/kernel/include/frame.h
+++ /dev/null
@@ -1,14 +0,0 @@
-#pragma once
-
-#include <sys.h>
-
-// frame.h : physical memory allocator
-
-void frame_init_allocator(size_t total_ram, void** kernel_data_end);
-
-uint32_t frame_alloc(size_t n); // allocate n consecutive frames (returns 0 on failure)
-void frame_free(uint32_t base, size_t n);
-
-void dbg_print_frame_stats();
-
-/* vim: set ts=4 sw=4 tw=0 noet :*/
diff --git a/kernel/include/gdt.h b/kernel/include/gdt.h
deleted file mode 100644
index a62d0db..0000000
--- a/kernel/include/gdt.h
+++ /dev/null
@@ -1,17 +0,0 @@
-#pragma once
-
-#include <stddef.h>
-#include <stdint.h>
-
-/* The GDT is one of the x86's descriptor tables. It is used for memory segmentation.
- Here, we don't use segmentation to separate processes from one another (this is done with paging).
- We only use segmentation to make the difference between kernel mode (ring 3) and user mode (ring 0) */
-
-void gdt_init();
-
-#define K_CODE_SEGMENT 0x08
-#define K_DATA_SEGMENT 0x10
-#define U_CODE_SEGMENT 0x18
-#define U_DATA_SEGMENT 0x20
-
-/* vim: set ts=4 sw=4 tw=0 noet :*/
diff --git a/kernel/include/hashtbl.h b/kernel/include/hashtbl.h
deleted file mode 100644
index 16dfefb..0000000
--- a/kernel/include/hashtbl.h
+++ /dev/null
@@ -1,34 +0,0 @@
-#pragma once
-
-#include <stdint.h>
-#include <stddef.h>
-#include <stdbool.h>
-
-// Simple hashtable structure (key -> void*)
-// Supports adding, seeking, removing
-// When adding a binding to the table, the previous binding for same key (if exists) is removed
-
-// TODO : possibility to allocate the hashtbl structure on any heap
-// (currently uses kmalloc/kfree)
-
-struct hashtbl;
-typedef struct hashtbl hashtbl_t;
-
-typedef size_t hash_t;
-typedef hash_t (*hash_fun_t)(const void*);
-typedef bool (*key_eq_fun_t)(const void*, const void*);
-
-hashtbl_t* create_hashtbl(key_eq_fun_t ef, hash_fun_t hf, size_t initial_size); // 0 -> default size
-void delete_hashtbl(hashtbl_t* ht);
-
-int hashtbl_add(hashtbl_t* ht, void* key, void* v); // non-null on error (OOM for instance)
-void* hashtbl_find(hashtbl_t* ht, void* key); // null when not found
-void hashtbl_remove(hashtbl_t* ht, void* key);
-size_t hashtbl_count(hashtbl_t* ht);
-
-hash_t id_hash_fun(const void* v);
-hash_t str_hash_fun(const void* v);
-bool id_key_eq_fun(const void* a, const void* b);
-bool str_key_eq_fun(const void* a, const void* b);
-
-/* vim: set ts=4 sw=4 tw=0 noet :*/
diff --git a/kernel/include/idt.h b/kernel/include/idt.h
deleted file mode 100644
index 8e84cea..0000000
--- a/kernel/include/idt.h
+++ /dev/null
@@ -1,79 +0,0 @@
-#pragma once
-
-/* The IDT is the system descriptor table that tells the CPU what to do when an interrupt fires.
- There are three categories of interrupts :
- - Exceptions ; eg page fault, divide by 0
- - IRQ : interrupts caused by hardware
- - System calls : when an applications asks the system to do something */
-
-#include <config.h>
-
-#define IRQ0 0
-#define IRQ1 1
-#define IRQ2 2
-#define IRQ3 3
-#define IRQ4 4
-#define IRQ5 5
-#define IRQ6 6
-#define IRQ7 7
-#define IRQ8 8
-#define IRQ9 9
-#define IRQ10 10
-#define IRQ11 11
-#define IRQ12 12
-#define IRQ13 13
-#define IRQ14 14
-#define IRQ15 15
-
-#define EX_DIVIDE_ERROR 0 // No error code
-#define EX_DEBUG 1 // No error code
-#define EX_NMI_INTERRUPT 2 // No error code
-#define EX_BREAKPOINT 3 // No error code
-#define EX_OVERFLOW 4 // No error code
-#define EX_BOUND_RANGE_EXCEDEED 5 // No error code
-#define EX_INVALID_OPCODE 6 // No error code
-#define EX_DEVICE_NOT_AVAILABLE 7 // No error code
-#define EX_DOUBLE_FAULT 8 // Yes (Zero)
-#define EX_COPROCESSOR_SEGMENT_OVERRUN 9 // No error code
-#define EX_INVALID_TSS 10 // Yes
-#define EX_SEGMENT_NOT_PRESENT 11 // Yes
-#define EX_STACK_SEGMENT_FAULT 12 // Yes
-#define EX_GENERAL_PROTECTION 13 // Yes
-#define EX_PAGE_FAULT 14 // Yes
-#define EX_INTEL_RESERVED_1 15 // No
-#define EX_FLOATING_POINT_ERROR 16 // No
-#define EX_ALIGNEMENT_CHECK 17 // Yes (Zero)
-#define EX_MACHINE_CHECK 18 // No
-#define EX_INTEL_RESERVED_2 19 // No
-#define EX_INTEL_RESERVED_3 20 // No
-#define EX_INTEL_RESERVED_4 21 // No
-#define EX_INTEL_RESERVED_5 22 // No
-#define EX_INTEL_RESERVED_6 23 // No
-#define EX_INTEL_RESERVED_7 24 // No
-#define EX_INTEL_RESERVED_8 25 // No
-#define EX_INTEL_RESERVED_9 26 // No
-#define EX_INTEL_RESERVED_10 27 // No
-#define EX_INTEL_RESERVED_11 28 // No
-#define EX_INTEL_RESERVED_12 29 // No
-#define EX_INTEL_RESERVED_13 30 // No
-#define EX_INTEL_RESERVED_14 31 // No
-
-#define EFLAGS_IF (0x1 << 9)
-
-typedef struct registers {
- uint32_t ds; // Data segment selector
- uint32_t edi, esi, ebp, useless_esp, ebx, edx, ecx, eax; // Pushed by pusha.
- uint32_t int_no, err_code; // Interrupt number and error code (if applicable)
- uint32_t eip, cs, eflags, esp, ss; // Pushed by the processor automatically.
-} registers_t;
-
-typedef void (*isr_handler_t)(registers_t*);
-
-void idt_init();
-
-void idt_set_ex_handler(int number, isr_handler_t func); //Set exception handler
-void idt_set_irq_handler(int number, isr_handler_t func); //Set IRQ handler
-
-void dbg_dump_registers(registers_t*);
-
-/* vim: set ts=4 sw=4 tw=0 noet :*/
diff --git a/kernel/include/kmalloc.h b/kernel/include/kmalloc.h
deleted file mode 100644
index a409865..0000000
--- a/kernel/include/kmalloc.h
+++ /dev/null
@@ -1,14 +0,0 @@
-#pragma once
-
-#include <stdint.h>
-#include <stddef.h>
-
-// Kernel memory allocator : one slab allocator for shared memory
-// Thread-safe.
-
-void kmalloc_setup();
-
-void* kmalloc(size_t sz);
-void kfree(void* ptr);
-
-/* vim: set ts=4 sw=4 tw=0 noet :*/
diff --git a/kernel/include/multiboot.h b/kernel/include/multiboot.h
deleted file mode 100644
index 581337a..0000000
--- a/kernel/include/multiboot.h
+++ /dev/null
@@ -1,63 +0,0 @@
-#pragma once
-
-#define MULTIBOOT_HEADER_MAGIC 0x1BADB002
-#define MULTIBOOT_BOOTLOADER_MAGIC 0x2BADB002
-
-struct multiboot_header_t{
- unsigned long magic;
- unsigned long flags;
- unsigned long checksum;
- unsigned long header_addr;
- unsigned long load_addr;
- unsigned long load_end_addr;
- unsigned long bss_end_addr;
- unsigned long entry_addr;
-};
-
-struct aout_symbol_table_t {
- unsigned long tabsize;
- unsigned long strsize;
- unsigned long addr;
- unsigned long reserved;
-};
-
-struct elf_section_header_table_t {
- unsigned long num;
- unsigned long size;
- unsigned long addr;
- unsigned long shndx;
-};
-
-struct multiboot_info_t {
- unsigned long flags;
- unsigned long mem_lower;
- unsigned long mem_upper;
- unsigned long boot_device;
- unsigned long cmdline;
- unsigned long mods_count;
- unsigned long mods_addr;
- union {
- struct aout_symbol_table_t aout_sym;
- struct elf_section_header_table_t elf_sec;
- } u;
- unsigned long mmap_length;
- unsigned long mmap_addr;
-};
-
-struct module_t {
- unsigned long mod_start;
- unsigned long mod_end;
- unsigned long string;
- unsigned long reserved;
-};
-
-struct memory_map_t {
- unsigned long size;
- unsigned long base_addr_low;
- unsigned long base_addr_high;
- unsigned long length_low;
- unsigned long length_high;
- unsigned long type;
-};
-
-/* vim: set ts=4 sw=4 tw=0 noet :*/
diff --git a/kernel/include/mutex.h b/kernel/include/mutex.h
deleted file mode 100644
index 6814adf..0000000
--- a/kernel/include/mutex.h
+++ /dev/null
@@ -1,21 +0,0 @@
-#pragma once
-
-#include <stdint.h>
-
-#define MUTEX_LOCKED 1
-#define MUTEX_UNLOCKED 0
-
-
-typedef uint32_t mutex_t;
-
-void mutex_lock(mutex_t* mutex); //wait for mutex to be free
-int mutex_try_lock(mutex_t* mutex); //lock mutex only if free, returns !0 if locked, 0 if was busy
-void mutex_unlock(mutex_t* mutex);
-
-// the mutex code assumes a yield() function is defined somewhere
-void yield();
-
-#define STATIC_MUTEX(name) static mutex_t name __attribute__((section("locks"))) = MUTEX_UNLOCKED;
-
-
-/* vim: set ts=4 sw=4 tw=0 noet :*/
diff --git a/kernel/include/paging.h b/kernel/include/paging.h
deleted file mode 100644
index 44014a2..0000000
--- a/kernel/include/paging.h
+++ /dev/null
@@ -1,31 +0,0 @@
-#pragma once
-
-#include <sys.h>
-#include <stdbool.h>
-
-struct page_directory;
-typedef struct page_directory pagedir_t;
-
-
-void paging_setup(void* kernel_data_end);
-
-pagedir_t *get_current_pagedir();
-pagedir_t *get_kernel_pagedir();
-
-void switch_pagedir(pagedir_t *pd);
-
-// these functions are always relative to the currently mapped page directory
-uint32_t pd_get_frame(void* vaddr); // get physical frame for virtual address
-int pd_map_page(void* vaddr, uint32_t frame_id, bool rw); // returns nonzero on error
-void pd_unmap_page(void* vaddr); // does nothing if page not mapped
-
-// Note on concurrency : we expect that multiple threads will not try to map/unmap
-// pages in the same region at the same time. It can nevertheless happen that
-// several threads try to map pages that belong to the same 4M-section, and in that
-// case both might require the allocation of a new PT at the same location. These
-// cases are well-handled (the pagedir_t type contains a mutex used for this)
-
-pagedir_t *create_pagedir(); // returns zero on error
-void delete_pagedir(pagedir_t *pd);
-
-/* vim: set ts=4 sw=4 tw=0 noet :*/
diff --git a/kernel/include/printf.h b/kernel/include/printf.h
deleted file mode 100644
index b4e1c1b..0000000
--- a/kernel/include/printf.h
+++ /dev/null
@@ -1,10 +0,0 @@
-#pragma once
-
-#include <stddef.h>
-#include <stdint.h>
-#include <stdarg.h>
-
-int snprintf(char* s, size_t n, const char* format, ...);
-int vsnprintf(char* s, size_t n, const char* format, va_list arg);
-
-/* vim: set ts=4 sw=4 tw=0 noet :*/
diff --git a/kernel/include/region.h b/kernel/include/region.h
deleted file mode 100644
index 1fef582..0000000
--- a/kernel/include/region.h
+++ /dev/null
@@ -1,38 +0,0 @@
-#pragma once
-
-// Kernel virtual memory region allocator
-
-// This is entirely thread-safe
-
-#include <sys.h>
-#include <paging.h>
-
-struct region_info;
-typedef void (*page_fault_handler_t)(pagedir_t *pd, struct region_info *r, void* addr);
-
-typedef struct region_info {
- void* addr;
- size_t size;
- char* type;
- page_fault_handler_t pf;
-} region_info_t;
-
-void region_allocator_init(void* kernel_data_end);
-
-void* region_alloc(size_t size, char* type, page_fault_handler_t pf); // returns 0 on error
-region_info_t *find_region(void* addr);
-void region_free(void* addr);
-
-// some usefull PF handlers
-// default_allocator_pf_handler : just allocates new frames on page faults
-void default_allocator_pf_handler(pagedir_t *pd, struct region_info *r, void* addr);
-
-// some functions for freeing regions and frames
-// region_free_unmap_free : deletes a region and frees all frames that were mapped in it
-void region_free_unmap_free(void* addr);
-// region_free_unmap : deletes a region and unmaps all frames that were mapped in it, without freeing them
-void region_free_unmap(void* addr);
-
-void dbg_print_region_info();
-
-/* vim: set ts=4 sw=4 tw=0 noet :*/
diff --git a/kernel/include/slab_alloc.h b/kernel/include/slab_alloc.h
deleted file mode 100644
index eb9588d..0000000
--- a/kernel/include/slab_alloc.h
+++ /dev/null
@@ -1,44 +0,0 @@
-#pragma once
-
-// Self-contained piece of library : a slab allocator...
-// Depends on page_alloc_fun_t and page_free_fun_t : a couple of functions
-// that can allocate/free multiples of one page at a time
-
-#include <stdint.h>
-#include <stddef.h>
-#include <stdbool.h>
-
-#if defined(__linux__)
-//redefine necessary stuff
-#include <assert.h>
-#define ASSERT assert
-#define PAGE_SIZE 0x1000
-#include <stdio.h>
-#define dbg_printf printf
-#else
-#include <sys.h> // this is macroscope
-#include <dbglog.h>
-#endif
-
-// expected format for the array of slab_type_t given to slab_create :
-// an array of slab_type descriptors, with last descriptor full of zeroes
-// and with obj_size increasing (strictly) in the array
-typedef struct slab_type {
- const char *descr;
- size_t obj_size;
- size_t pages_per_cache;
-} slab_type_t;
-
-struct mem_allocator;
-typedef struct mem_allocator mem_allocator_t;
-
-typedef void* (*page_alloc_fun_t)(size_t bytes);
-typedef void (*page_free_fun_t)(void* ptr);
-
-mem_allocator_t* create_slab_allocator(const slab_type_t *types, page_alloc_fun_t af, page_free_fun_t ff);
-void destroy_slab_allocator(mem_allocator_t*);
-
-void* slab_alloc(mem_allocator_t* a, size_t sz);
-void slab_free(mem_allocator_t* a, void* ptr);
-
-/* vim: set ts=4 sw=4 tw=0 noet :*/
diff --git a/kernel/include/string.h b/kernel/include/string.h
deleted file mode 100644
index 682b25a..0000000
--- a/kernel/include/string.h
+++ /dev/null
@@ -1,17 +0,0 @@
-#pragma once
-
-#include <stddef.h>
-#include <stdint.h>
-
-void *memcpy(void *dest, const void *src, size_t count);
-void *memset(void *dest, int val, size_t count);
-int memcmp(const void *s1, const void *s2, size_t n);
-void *memmove(void *dest, const void *src, size_t count);
-
-size_t strlen(const char *str);
-char *strchr(const char *str, char c);
-char *strcpy(char *dest, const char *src);
-char *strcat(char *dest, const char *src);
-int strcmp(const char *s1, const char *s2);
-
-/* vim: set ts=4 sw=4 tw=0 noet :*/
diff --git a/kernel/include/sys.h b/kernel/include/sys.h
deleted file mode 100644
index c8721ec..0000000
--- a/kernel/include/sys.h
+++ /dev/null
@@ -1,57 +0,0 @@
-#pragma once
-
-#include <config.h>
-
-static inline void outb(uint16_t port, uint8_t value) {
- asm volatile("outb %1, %0" : : "dN"(port), "a"(value));
-}
-
-static inline void outw(uint16_t port, uint16_t value) {
- asm volatile("outw %1, %0" : : "dN"(port), "a"(value));
-}
-
-static inline uint8_t inb(uint16_t port) {
- uint8_t ret;
- asm volatile("inb %1, %0" : "=a"(ret) : "dN"(port));
- return ret;
-}
-
-static inline uint16_t inw(uint16_t port) {
- uint16_t ret;
- asm volatile("inw %1, %0" : "=a"(ret) : "dN"(port));
- return ret;
-}
-
-static inline void invlpg(void* addr) {
- asm volatile("invlpg (%0)" : : "r"(addr) : "memory");
-}
-
-void panic(const char* message, const char* file, int line);
-void panic_assert(const char* assertion, const char* file, int line);
-#define PANIC(s) panic(s, __FILE__, __LINE__);
-#define ASSERT(s) { if (!(s)) panic_assert(#s, __FILE__, __LINE__); }
-
-#define BOCHS_BREAKPOINT asm volatile("xchg %bx, %bx")
-
-
-// Utility functions for memory alignment
-
-#define PAGE_SIZE 0x1000
-#define PAGE_MASK 0xFFFFF000
-#define PAGE_ALIGN_DOWN(x) (((size_t)x) & PAGE_MASK)
-#define PAGE_ALIGN_UP(x) ((((size_t)x)&(~PAGE_MASK)) == 0 ? ((size_t)x) : (((size_t)x) & PAGE_MASK) + PAGE_SIZE)
-#define PAGE_ID(x) (((size_t)x) / PAGE_SIZE)
-#define PAGE_SHIFT 12
-#define PT_SHIFT 10
-// PAGE_SHIFT + PT_SHIFT + PT_SHIFT = 32
-#define N_PAGES_IN_PT 1024
-#define PD_MIRROR_ADDR 0xFFC00000 // last 4MB used for PD mirroring
-#define LAST_KERNEL_ADDR PD_MIRROR_ADDR
-#define FIRST_KERNEL_PT (K_HIGHHALF_ADDR >> (PAGE_SHIFT+PT_SHIFT)) // must be 768
-
-#define MASK4 0xFFFFFFFC
-#define ALIGN4_UP(x) ((((size_t)x)&(~MASK4)) == 0 ? ((size_t)x) : (((size_t)x) & MASK4) + 4)
-#define ALIGN4_DOWN(x) (((size_t)x)&MASK4)
-
-
-/* vim: set ts=4 sw=4 tw=0 noet :*/
diff --git a/kernel/include/thread.h b/kernel/include/thread.h
deleted file mode 100644
index 757ba00..0000000
--- a/kernel/include/thread.h
+++ /dev/null
@@ -1,46 +0,0 @@
-#pragma once
-
-#include <sys.h>
-#include <paging.h>
-#include <region.h>
-
-#define T_STATE_RUNNING 1
-#define T_STATE_PAUSED 2
-#define T_STATE_FINISHED 3
-
-#define KPROC_STACK_SIZE 0x8000 // 8Kb
-
-#define TASK_SWITCH_FREQUENCY 100 // in herz
-
-typedef struct saved_context {
- uint32_t *esp;
- void (*eip)();
-} saved_context_t;
-
-struct process;
-typedef struct thread {
- saved_context_t ctx;
- pagedir_t *current_pd_d;
-
- uint32_t state;
-
- region_info_t *stack_region;
-
- struct process *proc; // process : L1 data structure
-
- struct thread *next_in_queue;
-} thread_t;
-
-typedef void (*entry_t)(void*);
-
-void threading_setup(entry_t cont, void* data); // never returns
-thread_t *new_thread(entry_t entry, void* data); // thread is PAUSED, and must be resume_thread'ed
-
-extern thread_t *current_thread;
-
-void yield();
-void pause();
-
-void resume_thread(thread_t *thread, bool run_at_once);
-
-/* vim: set ts=4 sw=4 tw=0 noet :*/