Merge working to master #1
41
arch/cpu.h
Normal file
41
arch/cpu.h
Normal file
@ -0,0 +1,41 @@
|
||||
#pragma once
|
||||
|
||||
#include <kern/cdef.h>
|
||||
|
||||
void KABI out_8(uint16 port, uint8 data);
|
||||
|
||||
void KABI out_16(uint16 port, uint16 data);
|
||||
|
||||
void KABI out_32(uint16 port, uint32 data);
|
||||
|
||||
uint8 KABI in_8(uint16 port);
|
||||
|
||||
uint16 KABI in_16(uint16 port);
|
||||
|
||||
uint32 KABI in_32(uint16 port);
|
||||
|
||||
void KABI flush_gdt(void *gdt_ptr, uint16 code_slct, uint16 data_slct);
|
||||
|
||||
void KABI flush_idt(void *idt_ptr);
|
||||
|
||||
void KABI flush_tss(uint16 tss_slct);
|
||||
|
||||
void KABI cpuid(uint32 *eax, uint32 *ebx, uint32 *ecx, uint32 *edx);
|
||||
|
||||
void KABI read_msr(uint32 *ecx, uint32 *edx, uint32 *eax);
|
||||
|
||||
void KABI write_msr(uint32 *ecx, uint32 *edx, uint32 *eax);
|
||||
|
||||
void KABI sti();
|
||||
|
||||
void KABI cli();
|
||||
|
||||
uint64 KABI read_cr8();
|
||||
|
||||
void KABI write_cr8(uint64 val);
|
||||
|
||||
uint64 KABI read_cr3();
|
||||
|
||||
void KABI write_cr3(uint64 val);
|
||||
|
||||
void KABI flush_tlb();
|
@ -1,8 +1,8 @@
|
||||
|
||||
|
||||
#include <kern/cdef.h>
|
||||
#include <arch/cpu.h>
|
||||
#include <arch/mem.h>
|
||||
#include <arch/intr.h>
|
||||
#include <arch/mlayout.h>
|
||||
|
||||
/**
|
||||
@ -50,7 +50,7 @@
|
||||
#define PT_ENTRY_NUM(vaddr) (((vaddr) >> 12) & 0x1FF)
|
||||
|
||||
void
|
||||
arch_write_page_tbl(void *base, uintptr pdpt_addr, uint64 attr)
|
||||
write_page_tbl(void *base, uintptr pdpt_addr, uint64 attr)
|
||||
{
|
||||
if (base == NULL)
|
||||
{
|
||||
|
@ -2,9 +2,6 @@
|
||||
|
||||
#include <kern/cdef.h>
|
||||
|
||||
void
|
||||
arch_write_page_tbl(void *base, uintptr pdpt_addr, uint64 attr);
|
||||
|
||||
void*
|
||||
void *
|
||||
arch_pmap_map(uintptr paddr, usize size);
|
||||
|
||||
|
28
mm/balloc.c
Normal file
28
mm/balloc.c
Normal file
@ -0,0 +1,28 @@
|
||||
#include <mm/balloc.h>
|
||||
#include <math.h>
|
||||
#include <ke/clib.h>
|
||||
#include <ke/bitmap.h>
|
||||
|
||||
// for each size
|
||||
// we have - bitmap representing each frame_size
|
||||
|
||||
int32 balloc_init(struct balloc_desc* desc, void* start, usize length, usize frame_size)
|
||||
{
|
||||
// calculate size required
|
||||
// calculate the # of levels
|
||||
usize aligned_len = ALIGN(usize, length, frame_size);
|
||||
usize total_frames = aligned_len / frame_size;
|
||||
usize levels = (usize)ceil(log2(total_frames)) + 1; // include the 0th level
|
||||
|
||||
|
||||
}
|
||||
|
||||
void* balloc(struct balloc_desc* desc, usize num_frames)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void bfree(struct balloc_desc* desc, uintptr ptr)
|
||||
{
|
||||
|
||||
}
|
104
mm/ssalloc.c
Normal file
104
mm/ssalloc.c
Normal file
@ -0,0 +1,104 @@
|
||||
#include "kern/cdef.h"
|
||||
#include "kern/mlayout.h"
|
||||
#include "lb/dlist.h"
|
||||
|
||||
/**
|
||||
* Simplified Slab Allocator
|
||||
*/
|
||||
|
||||
#define LARGE_THRESHOLD (8)
|
||||
|
||||
struct ssalloc_page_desc
|
||||
{
|
||||
struct dlist_node node;
|
||||
uint32 used_obj_num;
|
||||
uint8 free_list[0]; /* free list inside each slab */
|
||||
};
|
||||
|
||||
struct ssalloc_obj_desc
|
||||
{
|
||||
struct dlist free_list;
|
||||
struct dlist full_list;
|
||||
struct dlist empty_list;
|
||||
usize obj_size;
|
||||
uint32 align;
|
||||
};
|
||||
|
||||
struct ssalloc_desc
|
||||
{
|
||||
uint32 chunk_size;
|
||||
void* malloc_chunk(void); // allocate a chunk
|
||||
void* free_chunk(void); // free a chunk
|
||||
};
|
||||
|
||||
static void* scalloc_large(struct ssalloc_desc* desc, struct ssalloc_obj_desc* obj_desc)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static void scfree_large(struct ssalloc_desc* desc, struct ssalloc_obj_desc* obj_desc, void* addr)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static void* scalloc_small(struct ssalloc_desc* desc, struct ssalloc_obj_desc* obj_desc)
|
||||
{
|
||||
// check the current free list first
|
||||
if (lb_dlist_size(&obj_desc->free_list) > 0)
|
||||
{
|
||||
// if it exists then we grab something from the list
|
||||
struct llist_node* node = lb_dlist_first(node);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
static void scfree_small(struct ssalloc_desc* desc, struct ssalloc_obj_desc* obj_desc, void* addr)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ssalloc_desc_init(struct ssalloc_desc* desc)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ssalloc_obj_desc_init(struct ssalloc_obj_desc* obj_desc, usize obj_size, uint32 align)
|
||||
{
|
||||
obj_desc->obj_size = obj_size;
|
||||
obj_desc->align = align;
|
||||
lb_dlist_init(&obj_desc->empty_list);
|
||||
lb_dlist_init(&obj_desc->full_list);
|
||||
lb_dlist_init(&obj_desc->free_list);
|
||||
}
|
||||
|
||||
void* scalloc(struct ssalloc_desc* desc, struct ssalloc_obj_desc* obj_desc)
|
||||
{
|
||||
void* ret = NULL;
|
||||
if(obj_desc->obj_size < desc->chunk_size / LARGE_THRESHOLD)
|
||||
{
|
||||
ret = scalloc_small(desc, obj_desc);
|
||||
}
|
||||
else
|
||||
{
|
||||
// large objects
|
||||
ret = scalloc_large(desc, obj_desc);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void scfree(struct ssalloc_desc* desc, struct ssalloc_obj_desc* obj_desc, void* address)
|
||||
{
|
||||
if(obj_desc->obj_size < desc->chunk_size)
|
||||
{
|
||||
scfree_small(desc, obj_desc, address);
|
||||
}
|
||||
else
|
||||
{
|
||||
// large objects
|
||||
scfree_large(desc, obj_desc, address);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user