6 void Initialise_MemoryBlock(IO_MemoryControl *mainctrl)
\r
8 SystemMemory.addr = 0;
\r
9 SystemMemory.size = 0;
\r
10 SystemMemory.next = 0;
\r
11 SystemMemory.ctrl = mainctrl;
\r
12 SystemMemory.description[0] = 0x00;
\r
16 void *MemoryBlock_Allocate_System(uint size)
\r
18 Memory *block = MemoryControl_Allocate(SystemMemory.ctrl, sizeof(Memory));
\r
24 Emergency_Out("[0x%08X]SysMemAlloc0 Failed.(%dBytes)", *(retaddr - 1), size);
\r
25 debug("[0x%08X]SysMemAlloc0 Failed.(%dBytes)", *(retaddr - 1), size);
\r
31 block->addr = MemoryControl_Allocate(SystemMemory.ctrl, size);
\r
33 if(block->addr == 0){
\r
34 Emergency_Out("[0x%08X]SysMemAlloc1 Failed.(%dBytes)", *(retaddr - 1), size);
\r
35 debug("[0x%08X]SysmMemAlloc1 Failed.(%dBytes)", *(retaddr - 1), size);
\r
42 block->next = SystemMemory.next;
\r
43 SystemMemory.next = block;
\r
44 SystemMemory.size++;
\r
45 block->ctrl = SystemMemory.ctrl;
\r
46 block->description[0] = 0x00;
\r
50 void *MemoryBlock_Allocate_User(uint size, IO_MemoryControl *ctrl)
\r
52 Memory *block = MemoryControl_Allocate(SystemMemory.ctrl, sizeof(Memory));
\r
58 Emergency_Out("[0x%08X]UsrMemAlloc0 Failed.(%dBytes)", *(retaddr - 1), size);
\r
59 debug("[0x%08X]UsrMemAlloc0 Failed.(%dBytes)", *(retaddr - 1), size);
\r
65 block->addr = MemoryControl_Allocate(ctrl, size);
\r
67 if(block->addr == 0){
\r
68 Emergency_Out("[0x%08X]UsrMemAlloc1 Failed.(%dBytes)", *(retaddr - 1), size);
\r
69 debug("[0x%08X]UsrMemAlloc1 Failed.(%dBytes)", *(retaddr - 1), size);
\r
75 block->size = (size + 7) & ~7;
\r
76 block->next = SystemMemory.next;
\r
77 SystemMemory.next = block;
\r
78 SystemMemory.size++;
\r
80 block->description[0] = 0x00;
\r
84 Memory *MemoryBlock_Verify(void *addr)
\r
88 for(next = &SystemMemory; next->next != 0; next = next->next){
\r
89 if(next->next->addr == addr){
\r
96 int MemoryBlock_Write_Description(void *addr, const uchar *description)
\r
101 block = MemoryBlock_Verify(addr);
\r
104 for(i = 0; i < (MEMORY_DESCRIPTION_LENGTH - 1); i++){
\r
105 if(description[i] == 0x00){
\r
108 block->description[i] = description[i];
\r
110 block->description[i] = 0x00;
\r
116 int MemoryBlock_Free(void *addr)
\r
118 Memory *next, *block;
\r
124 for(next = &SystemMemory; next->next != 0; next = next->next){
\r
125 if(next->next->addr == addr){
\r
126 block = next->next;
\r
127 next->next = block->next;
\r
128 if(MemoryControl_Free(block->ctrl, block->addr, block->size) != 0){
\r
131 if(MemoryControl_Free(SystemMemory.ctrl, block, sizeof(Memory)) != 0){
\r
134 SystemMemory.size--;
\r