| [466] | 1 | ////////////////////////////////////////////////////////////////////////////////// |
|---|
| 2 | // File : kernel_malloc.h |
|---|
| 3 | // Date : 05/12/2014 |
|---|
| 4 | // Author : alain greiner |
|---|
| 5 | // Copyright (c) UPMC-LIP6 |
|---|
| 6 | ////////////////////////////////////////////////////////////////////////////////// |
|---|
| 7 | // The kernel_malloc.c and kernel_malloc.h files are part of the giet_vm kernel. |
|---|
| 8 | ////////////////////////////////////////////////////////////////////////////////// |
|---|
| 9 | |
|---|
| 10 | #ifndef KERNEL_MALLOC_H_ |
|---|
| 11 | #define KERNEL_MALLOC_H_ |
|---|
| 12 | |
|---|
| [495] | 13 | #include "kernel_locks.h" |
|---|
| [466] | 14 | #include "hard_config.h" |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | #define MIN_BLOCK_SIZE 0x40 |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | ////////////////////////////////////////////////////////////////////////////////// |
|---|
| 21 | // heap descriptor (one per cluster) |
|---|
| 22 | ////////////////////////////////////////////////////////////////////////////////// |
|---|
| 23 | |
|---|
| 24 | typedef struct kernel_heap_s |
|---|
| 25 | { |
|---|
| 26 | spin_lock_t lock; // lock protecting exclusive access |
|---|
| 27 | unsigned int heap_base; // heap base address |
|---|
| 28 | unsigned int heap_size; // heap size (bytes) |
|---|
| [594] | 29 | unsigned int alloc_base; // alloc[] array base address |
|---|
| 30 | unsigned int alloc_size; // alloc[] array size (bytes) |
|---|
| [466] | 31 | unsigned int free[32]; // array of base addresses of free blocks |
|---|
| 32 | // (address of first block of a given size) |
|---|
| 33 | } kernel_heap_t; |
|---|
| 34 | |
|---|
| 35 | ////////////////////////////////////////////////////////////////////////////////// |
|---|
| 36 | // global variables |
|---|
| 37 | ////////////////////////////////////////////////////////////////////////////////// |
|---|
| 38 | |
|---|
| 39 | extern kernel_heap_t kernel_heap[X_SIZE][Y_SIZE]; |
|---|
| 40 | |
|---|
| 41 | ////////////////////////////////////////////////////////////////////////////////// |
|---|
| 42 | // access functions |
|---|
| 43 | ////////////////////////////////////////////////////////////////////////////////// |
|---|
| 44 | |
|---|
| [594] | 45 | extern void* _malloc( unsigned int size ); |
|---|
| 46 | |
|---|
| [466] | 47 | extern void* _remote_malloc( unsigned int size, |
|---|
| 48 | unsigned int x, |
|---|
| 49 | unsigned int y ); |
|---|
| 50 | |
|---|
| [594] | 51 | extern void _free( void* ptr ); |
|---|
| 52 | |
|---|
| [466] | 53 | extern void _heap_init(); |
|---|
| 54 | |
|---|
| 55 | |
|---|
| 56 | #endif |
|---|
| 57 | |
|---|
| 58 | // Local Variables: |
|---|
| 59 | // tab-width: 4 |
|---|
| 60 | // c-basic-offset: 4 |
|---|
| 61 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
|---|
| 62 | // indent-tabs-mode: nil |
|---|
| 63 | // End: |
|---|
| 64 | // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
|---|
| 65 | |
|---|