Rename map to memory_map and export it

This commit is contained in:
Laurent Vivier 2004-02-19 13:09:41 +00:00
parent 09aa0fdf33
commit 9bb63653bf
4 changed files with 84 additions and 43 deletions

View File

@ -6,51 +6,55 @@
*
*/
#include <stdio.h>
#include "lowmem.h"
#include "MMU.h"
#include "bank.h"
static void bank_add_mem(memory_map_t* map, unsigned long logiAddr,
memory_map_t memory_map = { { { 0, 0 } }, 0 };
static void bank_add_mem(unsigned long logiAddr,
unsigned long physAddr, unsigned long size)
{
int i;
int j;
for (i = 0; i < map->bank_number; i++)
for (i = 0; i < memory_map.bank_number; i++)
{
if ( (map->bank[i].physAddr <= physAddr) &&
(physAddr < map->bank[i].physAddr + map->bank[i].size) )
if ( (memory_map.bank[i].physAddr <= physAddr) &&
(physAddr < memory_map.bank[i].physAddr + memory_map.bank[i].size) )
return; /* several logical address to one physical */
if (map->bank[i].physAddr + map->bank[i].size == physAddr)
if (memory_map.bank[i].physAddr + memory_map.bank[i].size == physAddr)
{
map->bank[i].size += size;
memory_map.bank[i].size += size;
/* can we merge 2 banks */
for (j = 0; j < map->bank_number; j++)
for (j = 0; j < memory_map.bank_number; j++)
{
if (map->bank[i].physAddr + map->bank[i].size == map->bank[j].physAddr)
if (memory_map.bank[i].physAddr + memory_map.bank[i].size == memory_map.bank[j].physAddr)
{
map->bank[i].size += map->bank[j].size;
memory_map.bank[i].size += memory_map.bank[j].size;
/* remove bank */
map->bank_number--;
map->bank[j].physAddr = map->bank[map->bank_number].physAddr;
map->bank[j].logiAddr = map->bank[map->bank_number].logiAddr;
map->bank[j].size = map->bank[map->bank_number].size;
memory_map.bank_number--;
memory_map.bank[j].physAddr = memory_map.bank[memory_map.bank_number].physAddr;
memory_map.bank[j].logiAddr = memory_map.bank[memory_map.bank_number].logiAddr;
memory_map.bank[j].size = memory_map.bank[memory_map.bank_number].size;
return;
}
}
return;
}
else if (physAddr + size == map->bank[i].physAddr)
else if (physAddr + size == memory_map.bank[i].physAddr)
{
map->bank[i].physAddr = physAddr;
map->bank[i].logiAddr = logiAddr;
map->bank[i].size += size;
memory_map.bank[i].physAddr = physAddr;
memory_map.bank[i].logiAddr = logiAddr;
memory_map.bank[i].size += size;
return;
}
@ -58,16 +62,16 @@ static void bank_add_mem(memory_map_t* map, unsigned long logiAddr,
/* not found, create new bank */
if (map->bank_number >= MAX_MEM_MAP_SIZE)
if (memory_map.bank_number >= MAX_MEM_MAP_SIZE)
return;
map->bank[map->bank_number].physAddr = physAddr;
map->bank[map->bank_number].logiAddr = logiAddr;
map->bank[map->bank_number].size = size;
map->bank_number++;
memory_map.bank[memory_map.bank_number].physAddr = physAddr;
memory_map.bank[memory_map.bank_number].logiAddr = logiAddr;
memory_map.bank[memory_map.bank_number].size = size;
memory_map.bank_number++;
}
void get_memory_map(memory_map_t* map)
void init_memory_map()
{
unsigned long logical;
unsigned long physical;
@ -84,12 +88,62 @@ void get_memory_map(memory_map_t* map)
}
while(1);
#endif
map->bank_number = 0;
memory_map.bank_number = 0;
for (logical = 0; logical < MemTop; logical += ps)
{
if (logical2physical(logical, &physical) == 0)
{
bank_add_mem(map, logical, physical, ps);
bank_add_mem(logical, physical, ps);
}
}
}
static int bank_find_by_physical(unsigned long physical)
{
int i;
for (i = 0; i < memory_map.bank_number; i++)
{
if ( (memory_map.bank[i].physAddr <= physical) &&
( physical < memory_map.bank[i].physAddr + memory_map.bank[i].size) )
return i;
}
return -1;
}
int physical2logical(unsigned long physical, unsigned long *logical)
{
int bank;
bank = bank_find_by_physical(physical);
if (bank == -1)
return -1;
if (memory_map.bank[bank].physAddr > memory_map.bank[bank].logiAddr)
*logical = physical - (memory_map.bank[bank].physAddr -
memory_map.bank[bank].logiAddr);
else
*logical = physical + (memory_map.bank[bank].logiAddr -
memory_map.bank[bank].physAddr);
return 0;
}
void bank_dump()
{
int i;
unsigned long size = 0;
printf("Physical memory map:\n");
for (i = 0; i < memory_map.bank_number; i++)
{
printf("%d: 0x%08lx -> 0x%08lx mapped at 0x%08lx\n", i,
memory_map.bank[i].physAddr,
memory_map.bank[i].physAddr + memory_map.bank[i].size,
memory_map.bank[i].logiAddr);
size += memory_map.bank[i].size;
}
printf("Available Memory: %ld kB\n", size / 1024);
}

View File

@ -2,11 +2,8 @@
*
* (c) 2004 Laurent Vivier <LaurentVivier@wanadoo.fr>
*
* portion from penguin booter
*
*/
/* physical memory information */
#define MAX_MEM_MAP_SIZE 26
@ -23,5 +20,6 @@ typedef struct memory_map {
} memory_map_t;
extern memory_map_t memory_map;
extern void get_memory_map(memory_map_t* map);
extern void init_memory_map();
extern void bank_dump();

View File

@ -30,25 +30,16 @@ int main(int argc, char** argv)
unsigned long kernel_image_size = &_kernel_end - &_kernel_start;
unsigned long kernel_size = (unsigned long)&_KERNEL_SIZE;
unsigned long physEntry;
int i;
printf("Early Macintosh Image LoadEr\n");
printf("EMILE v"VERSION" (c) 2004 Laurent Vivier\n");
printf("This is free software, redistribute it under GPL\n");
bank_dump();
printf("Kernel image found at %p\n", kernel_image_start);
printf("Kernel image size is %ld Bytes\n", kernel_image_size);
printf("Available Memory: %ld KB\n", MemTop / 1024);
printf("Physical memory map:\n");
for (i = 0; i < memory_map.bank_number; i++)
{
printf("%d: 0x%08lx -> 0x%08lx mapped at 0x%08lx\n", i,
memory_map.bank[i].physAddr,
memory_map.bank[i].physAddr + memory_map.bank[i].size,
memory_map.bank[i].logiAddr);
}
if (kernel_image_size != 0)
{
/* add KERNEL_ALIGN if we have to align

View File

@ -31,8 +31,6 @@ typedef struct memory_pool {
memory_pool_t* pool = NULL;
memory_map_t memory_map = { { { 0, 0 } }, 0 };
static int memory_find_area_by_addr(unsigned long start)
{
int i;
@ -175,7 +173,7 @@ void memory_init()
/* we are currently using the MMU to have only one linear memory area */
get_memory_map(&memory_map);
init_memory_map();
/* we put memory pool array just before us */