Initial commit
This commit is contained in:
commit
ef80f65fbf
136 changed files with 13728 additions and 0 deletions
9
include/mm/kmalloc.h
Normal file
9
include/mm/kmalloc.h
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
#include <error.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
void _kmalloc_init(void);
|
||||
|
||||
void *kmalloc(size_t size);
|
||||
void *kzalloc(size_t size);
|
||||
kstatus kfree(void *addr);
|
||||
10
include/mm/page.h
Normal file
10
include/mm/page.h
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
#include "slab.h"
|
||||
|
||||
typedef struct page {
|
||||
struct ma_bufctl *bufctls; // The bufctls associated with the slab stored on this page. NULL if page isn't associated with a slab
|
||||
struct ma_slab *slab;
|
||||
}page;
|
||||
|
||||
struct page *get_page(void *addr);
|
||||
|
||||
void init_page_array();
|
||||
13
include/mm/pmm.h
Normal file
13
include/mm/pmm.h
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define BLOCK_SIZE 4096
|
||||
|
||||
typedef struct free_page_t {
|
||||
struct free_page_t *next;
|
||||
uint8_t _padding[4088];
|
||||
} __attribute((packed)) free_page_t;
|
||||
|
||||
void pmm_init(void);
|
||||
uint64_t *pmm_alloc();
|
||||
void pmm_free(uint64_t *addr);
|
||||
60
include/mm/slab.h
Normal file
60
include/mm/slab.h
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
#include <stdatomic.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <error.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#pragma once
|
||||
#define KCACHE_NAME_LEN 16
|
||||
|
||||
|
||||
struct ma_bufctl {
|
||||
struct ma_bufctl *next;
|
||||
size_t *startaddr;
|
||||
};
|
||||
// ADD COLORING
|
||||
struct ma_slab {
|
||||
struct ma_cache *cache;
|
||||
|
||||
struct ma_slab *next;
|
||||
struct ma_slab *prev;
|
||||
|
||||
uint32_t refcount; // The amount of active (not free) objects in the slabs
|
||||
|
||||
atomic_flag lock;
|
||||
|
||||
struct ma_bufctl *free; // Linked list of free buffers in the slab. Is equal to NULL once there are no more free objects
|
||||
};
|
||||
|
||||
/* objrefs are used to be able to quickly find out which slab and cache a object belongs to. objrefs belonging to the same slab are kept in one page, there is no mixing. */
|
||||
struct ma_objref {
|
||||
struct ma_objref *next;
|
||||
struct ma_objref *prev;
|
||||
void *addr; // Addr of the object
|
||||
struct ma_slab *slab; // The slab which the obj belongs to
|
||||
struct ma_cache *kcache; // The cache which the obj belongs to
|
||||
};
|
||||
|
||||
struct ma_cache {
|
||||
struct ma_cache *next;
|
||||
struct ma_cache *prev;
|
||||
|
||||
uint32_t objsize; // Size of the object which the cache stores
|
||||
uint16_t flags; // Not useful yet
|
||||
uint32_t num; // Number of objects per slab
|
||||
uint32_t slabsize; // How many pages does a single slab take up. Useful for objects > PAGE_SIZE
|
||||
|
||||
struct ma_slab *slabs_free;
|
||||
struct ma_slab *slabs_partial;
|
||||
struct ma_slab *slabs_used;
|
||||
|
||||
atomic_flag lock;
|
||||
|
||||
char name[KCACHE_NAME_LEN];
|
||||
};
|
||||
|
||||
void *ma_cache_alloc(struct ma_cache *kcache, uint32_t flags);
|
||||
kstatus ma_cache_dealloc(void *object);
|
||||
struct ma_cache *ma_cache_create(char *name, size_t size, uint32_t flags, void (*constructor)(void *, size_t), void (*destructor)(void *, size_t));
|
||||
void cache_info(struct ma_cache *cache);
|
||||
void create_base_caches();
|
||||
25
include/mm/vmm.h
Normal file
25
include/mm/vmm.h
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
|
||||
#include <stdint.h>
|
||||
|
||||
#define PTE_BIT_PRESENT 0x1 // Present bit
|
||||
#define PTE_BIT_RW 0x2 // Read/write bit
|
||||
#define PTE_BIT_US 0x4 // User and Supervisor bit
|
||||
#define PTE_BIT_NX 0x4000000000000000 // Non-executable bit
|
||||
#define PTE_BIT_UNCACHABLE (1 << 4)
|
||||
|
||||
#define PAGE_SIZE 4096
|
||||
|
||||
void tlb_flush(void);
|
||||
void vmm_map_page(uint64_t *page_map, uint64_t virt_address, uint64_t phys_address, uint64_t flags);
|
||||
int vmm_map_contigious_pages(uint64_t *page_map, uint64_t virt_addr, uint64_t phys_addr, uint64_t size, uint64_t flags);
|
||||
void vmm_free_page(uint64_t *page_map, uint64_t virt_addr);
|
||||
void vmm_init();
|
||||
void vmm_set_ctx(uint64_t *page_map);
|
||||
uint64_t vmm_get_phys_addr(uint64_t *page_map, uint64_t virt_addr);
|
||||
uint64_t kget_phys_addr(uint64_t *virt_addr);
|
||||
void *va_alloc_contigious_pages(uint64_t size);
|
||||
void kmap_pages(void *phys_addr, uint64_t size, uint64_t flags);
|
||||
void kunmap_pages(void *addr, uint64_t size);
|
||||
|
||||
typedef char link_symbol_ptr[];
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue