4 IO_MemoryControl sys_mem_ctrl;
\r
7 uint Memory_Test(uint start, uint end)
\r
12 eflg = IO_Load_EFlags();
\r
13 eflg |= EFLAGS_AC_BIT;
\r
14 IO_Store_EFlags(eflg);
\r
16 eflg = IO_Load_EFlags();
\r
17 if((eflg & EFLAGS_AC_BIT) != 0){
\r
20 eflg &= ~EFLAGS_AC_BIT;
\r
21 IO_Store_EFlags(eflg);
\r
25 cr0 |= CR0_ALL_CACHE_DISABLE;
\r
28 i = Memory_Test_Sub(start, end);
\r
31 cr0 &= ~CR0_ALL_CACHE_DISABLE;
\r
37 void MemoryControl_Initialise(IO_MemoryControl *ctrl, void *start, uint size)
\r
39 ctrl->start = start;
\r
42 ((IO_MemoryControlTag *)ctrl->next)->size = ctrl->size;
\r
43 ((IO_MemoryControlTag *)ctrl->next)->next = 0;
\r
47 uint MemoryControl_FreeSize(IO_MemoryControl *ctrl)
\r
56 size += ((IO_MemoryControlTag *)tag)->size;
\r
57 if(((IO_MemoryControlTag *)tag)->next == 0){
\r
60 tag = ((IO_MemoryControlTag *)tag)->next;
\r
65 void *MemoryControl_Allocate(IO_MemoryControl *ctrl, uint size)
\r
69 size = (size + 7) & ~7;
\r
71 before = &ctrl->next;
\r
73 if((((IO_MemoryControlTag *)*before)->size - 8) > size){
\r
76 if(((IO_MemoryControlTag *)*before)->next == 0){
\r
79 before = &((IO_MemoryControlTag *)*before)->next;
\r
81 ((IO_MemoryControlTag *)(*before + size))->size = ((IO_MemoryControlTag *)*before)->size - size;
\r
82 ((IO_MemoryControlTag *)(*before + size))->next = ((IO_MemoryControlTag *)*before)->next;
\r
83 *before = *before + size;
\r
85 return *before - size;
\r
88 int MemoryControl_Free(IO_MemoryControl *ctrl, void *addr0, uint size)
\r
92 size = (size + 7) & ~7;
\r
94 before = &ctrl->next;
\r
95 for(; before != 0;){
\r
96 if((uint)((IO_MemoryControlTag *)*before) == (uint)(addr0 + size)){ //
\89ð
\95ú
\82µ
\82½
\82¢
\83\81\83\82\83\8a\82Ì
\8cã
\91±
\82É
\8bó
\82«
\82ª
\82 \82é
\8fê
\8d\87\81B
\r
97 ((IO_MemoryControlTag *)addr0)->size = ((IO_MemoryControlTag *)(*before))->size + size;
\r
98 ((IO_MemoryControlTag *)addr0)->next = ((IO_MemoryControlTag *)(*before))->next;
\r
102 if((uint)((IO_MemoryControlTag *)*before)->next >= (uint)(addr0 + size)){
\r
103 Send_SerialPort("Have to Free!1 or 2\r\n");
\r
106 if(((IO_MemoryControlTag *)*before)->next == 0){
\r
107 Send_SerialPort("Have to Free!0\r\n");
\r
110 before = ((IO_MemoryControlTag *)*before)->next;
\r
115 void *MemoryControl_Allocate_Page(IO_MemoryControl *ctrl)
\r
117 void *addr, *mem_head_4k, *offset;
\r
119 addr = MemoryControl_Allocate(ctrl, 0x2000);
\r
120 if(addr == 0) return 0;
\r
121 mem_head_4k = (void *)(((uint)addr + 0xfff) & 0xfffff000);
\r
122 (uint)offset = (uint)mem_head_4k - (uint)addr;
\r
124 MemoryControl_Free(ctrl, addr, (uint)offset);
\r
126 MemoryControl_Free(ctrl, mem_head_4k + 0x1000, 0x1000 - (uint)offset);
\r
128 return mem_head_4k;
\r
131 void MemoryControl_Output_Info(IO_MemoryControl *ctrl)
\r
135 debug("Memory Free Info.\n");
\r
138 debug("Addr:0x%08X Size:0x%08X\n", (uint)tag, ((IO_MemoryControlTag *)tag)->size);
\r
139 if(((IO_MemoryControlTag *)tag)->next == 0){
\r
142 tag = ((IO_MemoryControlTag *)tag)->next;
\r
147 void System_MemoryControl_Initialise(void)
\r
149 sys_mem_size = Memory_Test(0x00400000, 0xbfffffff) & 0xFFFFF000;
\r
150 MemoryControl_Initialise(&sys_mem_ctrl, (void *)0x00400000, sys_mem_size - 0x00400000);
\r
154 uint System_MemoryControl_FullSize(void)
\r
156 return sys_mem_size;
\r
159 uint System_MemoryControl_FreeSize(void)
\r
161 return MemoryControl_FreeSize(&sys_mem_ctrl);
\r
164 void *System_MemoryControl_Allocate(uint size)
\r
171 addr = MemoryControl_Allocate(&sys_mem_ctrl, size);
\r
173 debug("[0x%08X]Memory Allocate Request.[0x%08X](%dByte)\n", *(retaddr - 1), addr, size);
\r
178 int System_MemoryControl_Free(void *addr0, uint size)
\r
180 return MemoryControl_Free(&sys_mem_ctrl, addr0, size);
\r
183 void *System_MemoryControl_Allocate_Page(void)
\r
185 return MemoryControl_Allocate_Page(&sys_mem_ctrl);
\r
188 void System_MemoryControl_Output_Info(void)
\r
190 MemoryControl_Output_Info(&sys_mem_ctrl);
\r