Modestus Moon OS  R4
CS 450 project
heap.h
Go to the documentation of this file.
1 #ifndef _HEAP_H
2 #define _HEAP_H
3 
4 /* Kernel heap */
5 #define TABLE_SIZE 0x1000
6 #define KHEAP_BASE 0xD000000
7 #define KHEAP_MIN 0x10000
8 #define KHEAP_SIZE 0x1000000
9 
10 /* Heap allocation header */
11 typedef struct {
12  int size;
13  int index_id;
14 } header;
15 
16 typedef struct {
18 } footer;
19 
20 typedef struct {
21  int size;
22  int empty;
24 } index_entry;
25 
26 /* Kernel heap index table */
27 typedef struct {
29  int id;
30 } index_table;
31 
32 /* Heap structure */
33 typedef struct {
38 } heap;
39 
40 /*
41  Procedure..: _kmalloc
42  Description..: Base-level kernel memory allocation routine. Used to
43  provide page alignment and access physical addresses of allocations.
44  Called by kmalloc with align=0, physical_address=0.
45 */
46 u32int _kmalloc(u32int size, int align, u32int *phys_addr);
47 
48 /*
49  Procedure..: kmalloc
50  Description..: Standard kernel memory allocation rountine. Use this unless you
51  need to specify alignment or obtain a physical address. Calls _kmalloc.
52 */
53 u32int kmalloc(u32int size);
54 
55 /*
56  Procedure..: kfree
57  Description..: Free kernel memory.
58 */
59 u32int kfree();
60 
61 /*
62  Procedure..: init_kheap
63  Description..: Initialize the kernel heap, and set it as the current heap.
64 */
65 void init_kheap();
66 
67 /*
68  Procedure..: alloc
69  Description..: Allocate some memory using the given heap. Can specify page-alignment.
70 */
71 u32int alloc(u32int size, heap *hp, int align);
72 
73 /*
74  Procedure..: make_heap
75  Description..: Create a new heap.
76  Parameters..: base - physical start address of the heap
77  max - maximum size the heap may grow to
78  min - minimum/initial size
79 */
81 
82 #endif
int index_id
Definition: heap.h:13
#define TABLE_SIZE
Definition: heap.h:5
u32int kmalloc(u32int size)
Definition: heap.c:52
u32int base
Definition: tables.h:53
Definition: heap.h:16
int size
Definition: heap.h:12
Definition: heap.h:20
u32int alloc(u32int size, heap *hp, int align)
Definition: heap.c:57
u32int _kmalloc(u32int size, int align, u32int *phys_addr)
Definition: heap.c:24
u32int min_size
Definition: heap.h:37
u32int max_size
Definition: heap.h:36
int size
Definition: heap.h:21
u32int block
Definition: heap.h:23
header head
Definition: heap.h:17
void init_kheap()
Definition: heap.h:11
u32int kfree()
heap * make_heap(u32int base, u32int max, u32int min)
Definition: heap.c:71
Definition: heap.h:33
int id
Definition: heap.h:29
unsigned long u32int
Definition: system.h:27
index_table index
Definition: heap.h:34
u32int base
Definition: heap.h:35
int empty
Definition: heap.h:22