mtkernel_3/kernel/tkernel/memory.h | bare source | permlink (0.02 seconds) |
1: /* 2: *---------------------------------------------------------------------- 3: * micro T-Kernel 3.00.00 4: * 5: * Copyright (C) 2006-2019 by Ken Sakamura. 6: * This software is distributed under the T-License 2.1. 7: *---------------------------------------------------------------------- 8: * 9: * Released by TRON Forum(http://www.tron.org) at 2019/12/11. 10: * 11: *---------------------------------------------------------------------- 12: */ 13: 14: /* 15: * memory.h 16: * In-kernel dynamic memory management 17: */ 18: 19: #ifndef _MEMORY_H_ 20: #define _MEMORY_H_ 21: 22: #include "limits.h" 23: 24: /* 25: * Memory allocation management information 26: * 27: * Order of members must not be changed because members are used 28: * with casting from MPLCB. 29: */ 30: typedef struct { 31: W memsz; 32: 33: /* AreaQue for connecting each area where reserved pages are 34: divided Sort in ascending order of addresses in a page. 35: Do not sort between pages. */ 36: QUEUE areaque; 37: /* FreeQue for connecting unused area in reserved pages 38: Sort from small to large free spaces. */ 39: QUEUE freeque; 40: } IMACB; 41: 42: /* 43: * Compensation for aligning "&areaque" position to 2 bytes border 44: */ 45: #define AlignIMACB(imacb) ( (IMACB*)((UW)(imacb) & ~0x00000001UL) ) 46: 47: /* 48: * Minimum unit of subdivision 49: * The lower 1 bit of address is always 0 50: * because memory is allocated by ROUNDSZ. 51: * AreaQue uses the lower 1 bit for flag. 52: */ 53: #define ROUNDSZ ( sizeof(QUEUE) ) /* 8 bytes */ 54: #define ROUND(sz) ( ((UW)(sz) + (UW)(ROUNDSZ-1)) & ~(UW)(ROUNDSZ-1) ) 55: 56: /* Minimum fragment size */ 57: #define MIN_FRAGMENT ( sizeof(QUEUE) * 2 ) 58: 59: /* 60: * Maximum allocatable size (to check for parameter) 61: */ 62: #define MAX_ALLOCATE ( INT_MAX & ~(ROUNDSZ-1) ) 63: 64: /* 65: * Adjusting the size which can be allocated 66: */ 67: Inline W roundSize( W sz ) 68: { 69: if ( sz < (W)MIN_FRAGMENT ) { 70: sz = (W)MIN_FRAGMENT; 71: } 72: return (W)(((UW)sz + (UW)(ROUNDSZ-1)) & ~(UW)(ROUNDSZ-1)); 73: } 74: 75: 76: /* 77: * Flag that uses the lower bits of AreaQue's 'prev'. 78: */ 79: #define AREA_USE 0x00000001UL /* In-use */ 80: #define AREA_MASK 0x00000001UL 81: 82: #define setAreaFlag(q, f) ( (q)->prev = (QUEUE*)((UW)(q)->prev | (UW)(f)) ) 83: #define clrAreaFlag(q, f) ( (q)->prev = (QUEUE*)((UW)(q)->prev & ~(UW)(f)) ) 84: #define chkAreaFlag(q, f) ( ((UW)(q)->prev & (UW)(f)) != 0 ) 85: 86: #define Mask(x) ( (QUEUE*)((UW)(x) & ~AREA_MASK) ) 87: #define Assign(x, y) ( (x) = (QUEUE*)(((UW)(x) & AREA_MASK) | (UW)(y)) ) 88: /* 89: * Area size 90: */ 91: #define AreaSize(aq) ( (VB*)(aq)->next - (VB*)((aq) + 1) ) 92: #define FreeSize(fq) ( (W)((fq) + 1)->prev ) 93: 94: 95: IMPORT QUEUE* knl_searchFreeArea( IMACB *imacb, W blksz ); 96: IMPORT void knl_appendFreeArea( IMACB *imacb, QUEUE *aq ); 97: IMPORT void knl_removeFreeQue( QUEUE *fq ); 98: IMPORT void knl_insertAreaQue( QUEUE *que, QUEUE *ent ); 99: IMPORT void knl_removeAreaQue( QUEUE *aq ); 100: 101: IMPORT IMACB *knl_imacb; 102: 103: #endif /* _MEMORY_H_ */