8 #define STACK_SIZE 4096
21 struct memrange *next;
22 unsigned char start[];
26 static struct memrange *pool[NUM_POOLS];
27 static uint32_t stack_base, stack_top;
29 extern int _mem_start;
31 void move_init_stack(uint32_t newtop); /* in startup.s */
37 struct alib_memnode *mem;
38 uint32_t mem_start = (uint32_t)&_mem_start;
40 printf("mem_start: %lu\n", mem_start);
42 printf("Memory ranges:\n");
43 mem = execbase->memlist.head;
45 unsigned long start, end, size;
49 /* assume we're dealing with at least 64k blocks */
50 start = (unsigned long)mem->start & 0xff0000;
51 end = ((unsigned long)mem->end + 0xffff) & 0xff0000;
54 if(mem->attrib & ALIB_MEMF_CHIP) {
57 } else if(mem->attrib & ALIB_MEMF_FAST) {
58 if(start >= 0xc00000 && end <= 0xd80000) {
66 printf("ignoring memory range %06lx - %06lx of unknown type: %u\n",
67 start, end, mem->attrib);
72 printf(" %06lx - %06lx: %s (%ldk)\n", start, end, stype, size >> 10);
75 if(mem_start >= start && mem_start < end) {
76 size -= mem_start - start;
80 mr = (struct memrange*)start;
83 mr->size = size - sizeof *mr;
84 mr->next = pool[type];
88 /* allocate stack space at the top of a memory range, order of preference:
91 for(i=0; i<NUM_POOLS; i++) {
93 if(mr && mr->size >= STACK_SIZE) {
94 stack_top = (uint32_t)mr->start + mr->size;
95 stack_base = stack_top - STACK_SIZE;
96 mr->size -= STACK_SIZE;
102 panic("Failed to allocate stack, no suitable memory ranges found!\n");
105 printf("Allocated %dk stack space: %06lx - %06lx\n", STACK_SIZE >> 10, stack_base, stack_top);
106 move_init_stack(stack_top);