Listtree.mcc: use internal inherited class of NListtree
[AROS.git] / arch / m68k-mac / exec / detect_memory.c
blob7f645bfda19eba459d7d0cc672eca0edd7d85830
1 /*
2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <exec/io.h>
7 #include <exec/types.h>
8 #include <exec/nodes.h>
9 #include <exec/memory.h>
10 #include <exec/resident.h>
11 #include <exec/libraries.h>
12 #include <exec/execbase.h>
13 #include <proto/exec.h>
14 #include "memory.h"
16 #define DBEUG 1
17 #include <aros/debug.h>
19 #include "pp_exec_internal.h"
21 #define MEM_START 0x400
25 * Detect memory in step sizes of 1kb. Keep it that way...
27 #define STEPSIZE 1024
29 UBYTE * check_memory(UBYTE * address)
31 int found = FALSE;
32 *(ULONG *)ADDRESS_ERROR_MARKER_ADDRESS = 0;
33 while (1) {
34 *(UBYTE *)address = 0xcc;
35 if (0xcc != *(UBYTE *)address) {
36 break;
38 if (0 == *(ULONG *)ADDRESS_ERROR_MARKER_ADDRESS) {
39 found = TRUE;
40 } else {
41 break;
43 address += STEPSIZE;
45 address -= STEPSIZE;
47 if (FALSE == found)
48 return NULL;
49 return address;
53 * Detect some initial memory. This should be enough
54 * to get the OS up and running. More detection follows
55 * later...
57 struct MemHeader * detect_memory(void)
59 struct MemHeader * mh;
61 * There is no SysBase available here!!
62 * It has not been initialized, yet.
66 * Must initialize the BusError handler
68 UBYTE * address = (UBYTE *)1024;
70 *(ULONG *)(2*4) = (ULONG)dm_bus_error_handler;
71 *(ULONG *)(3*4) = (ULONG)dm_addr_error_handler;
73 address = check_memory(address);
75 mh=(struct MemHeader*)MEM_START;
76 mh->mh_Node.ln_Succ = NULL;
77 mh->mh_Node.ln_Pred = NULL;
78 mh->mh_Node.ln_Type = NT_MEMORY;
79 mh->mh_Node.ln_Name = "chip memory";
80 mh->mh_Node.ln_Pri = -5;
81 mh->mh_Attributes = MEMF_CHIP | MEMF_PUBLIC | MEMF_LOCAL | MEMF_24BITDMA |
82 MEMF_KICK;
83 mh->mh_First = (struct MemChunk *)((UBYTE*)mh+MEMHEADER_TOTAL);
84 mh->mh_First->mc_Next = NULL;
85 mh->mh_First->mc_Bytes = ((ULONG)address - MEM_START) - MEMHEADER_TOTAL;
87 mh->mh_Lower = mh->mh_First;
88 mh->mh_Upper = (APTR)(address);
89 mh->mh_Free = mh->mh_First->mc_Bytes;
91 return mh;
95 * The locations where memory can be.
96 * Beware: Whatever is at 0x0 is also at 0x10000000 for 1MB.
97 * So I am trying to avoid detecting this part again
98 * and start later in memory.
100 struct memories
102 UBYTE * start;
103 UBYTE pri;
106 static struct memories memory[] = {{(UBYTE *)0x10100000,-10},
107 {(UBYTE *)0xf0000000,-10},
108 {(UBYTE *)NULL,0}};
111 * Detect the rest of the memory available on this device.
113 void detect_memory_rest(struct ExecBase * SysBase)
115 int c = 0;
116 *(ULONG *)(2*4) = (ULONG)dm_bus_error_handler;
117 *(ULONG *)(3*4) = (ULONG)dm_addr_error_handler;
119 while (0 != memory[c].start) {
120 UBYTE * end;
122 * Now try to detect sram size
124 end = check_memory(memory[c].start);
125 if (end != memory->start[c] && NULL != end) {
126 AddMemList((ULONG)end-(ULONG)memory[c].start,
127 MEMF_CHIP | MEMF_PUBLIC | MEMF_LOCAL | MEMF_24BITDMA | MEMF_KICK,
128 memory[c].pri,
129 memory[c].start,
130 "fast memory");
132 c++;