From 40ea3746d5392688c08921d952f870b682b5be7d Mon Sep 17 00:00:00 2001 From: Laurent Vivier Date: Thu, 26 Feb 2004 22:56:39 +0000 Subject: [PATCH] Manage noMMU and powerPC --- second/bank.c | 86 +++++++++++++++++++++++++++++++++++++++++---------- second/bank.h | 2 ++ 2 files changed, 72 insertions(+), 16 deletions(-) diff --git a/second/bank.c b/second/bank.c index dce79d5..9813795 100644 --- a/second/bank.c +++ b/second/bank.c @@ -8,10 +8,19 @@ #include +#include "arch.h" #include "lowmem.h" #include "MMU.h" #include "bank.h" +/* MacOS nanokernel data structures (nubus powerPC only) + * found in Boot/X, thank you Ben ;-) + */ + +#define MACOS_MEMMAP_PTR_ADDR 0x5FFFEFF0 +#define MACOS_MEMMAP_SIZE_ADDR 0x5FFFEFF6 +#define MACOS_MEMMAP_BANK_0FFSET 48 + memory_map_t memory_map = { { { 0, 0 } }, 0 }; static void bank_add_mem(unsigned long logiAddr, @@ -76,34 +85,67 @@ static void bank_add_mem(unsigned long logiAddr, memory_map.bank_number++; } -void init_memory_map() +void m68k_init_memory_map() { unsigned long logical; unsigned long physical; - int ps = get_page_size(); + int ps; -#ifdef DUMP_MEMMAP - for (logical = 0; logical < MemTop ; logical += ps) + if (mmu_type == gestaltNoMMU) { - printf("%08lx->", logical); - if (logical2physical(logical, &physical) == 0) - printf("%08lx ", physical); - else - printf("INVALID! "); + bank_add_mem(0, 0, MemTop); } - while(1); -#endif - memory_map.bank_number = 0; - logical = 0; - for (logical = 0; logical < MemTop ; logical += ps) + else { - if (logical2physical(logical, &physical) == 0) + ps = MMU_get_page_size(); + memory_map.bank_number = 0; + logical = 0; + for (logical = 0; logical < MemTop ; logical += ps) { - bank_add_mem(logical, physical, ps); + if (logical2physical(logical, &physical) == 0) + { + bank_add_mem(logical, physical, ps); + } } } } +void ppc_init_memory_map() +{ + /* Nubus powerPC */ + + unsigned long *base = *(unsigned long**)MACOS_MEMMAP_PTR_ADDR; + unsigned long len = *(unsigned short*)MACOS_MEMMAP_SIZE_ADDR; + int i; + + if (len <= MACOS_MEMMAP_BANK_0FFSET) + return; + + base += MACOS_MEMMAP_BANK_0FFSET; + len -= MACOS_MEMMAP_BANK_0FFSET; + i = 0; + + while(len >= 8) + { + unsigned long addr = *(unsigned long*)base; + unsigned long size = *(unsigned long*)(base+4); + + if (size) + bank_add_mem(addr, addr, size); + + base += 8; + len -= 8; + } +} + +void init_memory_map() +{ + if (arch_type == gestaltPowerPC) + ppc_init_memory_map(); + else + m68k_init_memory_map(); +} + static int bank_find_by_physical(unsigned long physical) { int i; @@ -118,6 +160,18 @@ static int bank_find_by_physical(unsigned long physical) return -1; } +int logical2physical(unsigned long logical, unsigned long *physical) +{ + if ( (mmu_type == gestaltNoMMU) || (mmu_type == gestaltEMMU1) ) + { + *physical = logical; + + return 0; + } + + return MMU_logical2physical(logical, physical); +} + int physical2logical(unsigned long physical, unsigned long *logical) { int bank; diff --git a/second/bank.h b/second/bank.h index f8e0307..b75ec3c 100644 --- a/second/bank.h +++ b/second/bank.h @@ -24,3 +24,5 @@ extern memory_map_t memory_map; extern void init_memory_map(); extern unsigned long bank_mem_avail(); extern void bank_dump(); +extern int logical2physical(unsigned long logical, unsigned long *physical); +extern int physical2logical(unsigned long physical, unsigned long *logical);