Hi,

below you'll find hopefully the final solution of problem with
"Load-to-TT-RAM" flag on AfterBurner040 and Centurbo2 FastRAM cards.
It's actually generic and should take care of any FastRAM&MMU problem.

--- /tmp/m68kboot/common/atari/linuxboot.c      2004-08-14 09:37:23.000000000 
+0200
+++ common/atari/linuxboot.c    2004-08-14 10:23:15.000000000 +0200
@@ -132,6 +132,35 @@
     } while(0)
 

+/* taken from arch/m68k/kernel/sys_m68k.c */
+#define MMU_R_040      0x0001
+#define PAGE_SHIFT     (12)
+#define PAGE_SIZE      (1UL << PAGE_SHIFT)
+#define PAGE_MASK      (~(PAGE_SIZE-1))
+/* Convert virtual (user) address VADDR to physical address PADDR */
+#define virt_to_phys_040(vaddr)                                                
\
+({                                                                     \
+  unsigned long _mmusr, _paddr;                                                
\
+                                                                       \
+  __asm__ __volatile__ (".chip 68040\n\t"                              \
+                       "ptestr (%1)\n\t"                               \
+                       "movec %%mmusr,%0\n\t"                          \
+                       ".chip 68k"                                     \
+                       : "=r" (_mmusr)                                 \
+                       : "a" (vaddr));                                 \
+  _paddr = (_mmusr & MMU_R_040) ? (_mmusr & PAGE_MASK) : 0;            \
+  _paddr;                                                              \
+})
+
+/* return offset between physical and virtual (MMU remapped) address */
+long phys_offset(u_long vaddr) {
+    if (bi.mch_type == ATARI_MACH_AB40 && ((unsigned long)vaddr & 0xff000000))
+       return virt_to_phys_040(vaddr & PAGE_MASK) - (vaddr & PAGE_MASK);
+    if (getcookie("_CT2", NULL) != -1 && ((unsigned long)vaddr & 0xff000000))
+       return CT2_FAST_START - TT_RAM_BASE;
+    return 0;
+}
+
 void linux_boot( void )
 {
     char *kname;
@@ -141,6 +170,9 @@
     u_long kernel_size;                /* size of kernel image */
     char *memptr;              /* addr and size of load region */
     u_long memreq;
+    long memptr_mmu_offset;    /* physical memptr addr offset */
+    long kernel_mmu_offset;    /* physical kernel dest addr offset */
+    long ramdisk_mmu_offset;   /* physical ramdisk dest addr offset */
     u_long rd_size;            /* size of ramdisk and array of pointers to
                                 * its data */
 
@@ -239,14 +271,6 @@
     if (!(memptr = malloc( memreq )))
        ERROR( "Unable to allocate %ld kB of memory for kernel%s\n",
                memreq / 1024, (rd_size > 0) ? " and ramdisk" : "" );
-    /* Second part of the AB40 no-FastRAM test */
-    if (bi.mch_type == ATARI_MACH_AB40 && ((unsigned long)memptr & 0xff000000))
-       ERROR( "Error: Bootstrap may not allocate memory from FastRAM "
-              "on Afterburner040\n" );
-    if (getcookie("_CT2", NULL) != -1 &&
-       ((unsigned long)memptr & 0xff000000))
-       ERROR( "Error: Bootstrap may not allocate memory from TT-RAM "
-               "on Centurbo2\n" );
 
     /* clearing the kernel's memory perhaps avoids "uninitialized bss"
      * types of bugs... */
@@ -282,6 +306,11 @@
     /* copy the boot_info struct to the end of the kernel image */
     memcpy( memptr + kernel_size, bi_ptr, bi_size );
 
+    /* find out the physical offsets if the memory is MMU mapped */
+    memptr_mmu_offset = phys_offset((u_long)memptr);
+    kernel_mmu_offset = phys_offset(start_mem);
+    ramdisk_mmu_offset = phys_offset(bi.ramdisk.addr);
+
     /* for those who want to debug */
     if (debugflag) {
        if (rd_size) {
@@ -294,6 +323,13 @@
        printf ("boot_info is at %#lx\n",
                start_mem + kernel_size);
 
+       if (memptr_mmu_offset)
+           printf ("kernel src offset = %#lx\n", memptr_mmu_offset);
+       if (kernel_mmu_offset)
+           printf ("kernel dest offset = %#lx\n", kernel_mmu_offset);
+       if (ramdisk_mmu_offset)
+           printf ("ramdisk dest offset = %#lx\n", ramdisk_mmu_offset);
+
        printf ("\nType a key to continue the Linux boot...");
        fflush (stdout);
        getchar();
@@ -312,6 +348,11 @@
     /* ..and any MMU translation */
     disable_mmu();
 
+    /* correct pointers to physical memory after MMU translation was disabled 
*/
+    memptr += memptr_mmu_offset;
+    start_mem += kernel_mmu_offset;
+    bi.ramdisk.addr += ramdisk_mmu_offset;
+
     /* ++guenther: allow reset if launched with MiNT */
     *(long*)0x426 = 0;
 


Reply via email to