coco3: autodetect and use up to 2M of RAM
authorBrett Gordon <beretta42@gmail.com>
Thu, 2 Jun 2016 17:53:21 +0000 (13:53 -0400)
committerBrett Gordon <beretta42@gmail.com>
Thu, 2 Jun 2016 17:53:21 +0000 (13:53 -0400)
Kernel/platform-coco3/coco3.s
Kernel/platform-coco3/config.h
Kernel/platform-coco3/main.c

index a44e45d..405c05b 100644 (file)
@@ -37,6 +37,7 @@
            .globl nmi_handler
            .globl null_handler
            .globl video_init
+           .globl _scanmem
 
             include "kernel.def"
             include "../kernel09.def"
@@ -142,9 +143,16 @@ init_hardware:
        ;; High speed poke
        sta     0xffd9          ; high speed poke
        ;; set system RAM size
-       ldd     #512
+       jsr     _scanmem        ; X = number of pages
+       tfr     x,d
+       lslb
+       rola
+       lslb
+       rola
+       lslb
+       rola
        std     _ramsize
-       ldd     #512-64
+       subd    #64+16
        std     _procmem
        ;; set initial user mmu
        ldd     #8
index 3564978..d9108dc 100644 (file)
@@ -17,7 +17,7 @@
 /* We use flexible 16K banks so use the helper */
 #define CONFIG_BANK16
 #define CONFIG_BANKS   4
-#define MAX_MAPS 32-3
+#define MAX_MAPS 128-3
 #define MAPBASE 0x0000
 /* And swapping */
 /* #define SWAPDEV  2051        */
index 39fcb74..34d9557 100644 (file)
@@ -33,6 +33,27 @@ void do_beep(void)
 {
 }
 
+/* Scan memory return number of 8k pages found */
+__attribute__((section(".discard")))
+int scanmem(void)
+{
+       volatile uint8_t *mmu=(uint8_t *)0xffa8;
+       volatile uint8_t *ptr=(uint8_t *)0x0100;
+       int i;
+       for( i = 0; i<256; i++ ){
+               *mmu=i;
+               *ptr=0;
+       }
+       *mmu=0;
+       *ptr=0xff;
+       *mmu=1;
+       for( i = 1; i<256 && !*ptr ; )
+               *mmu=++i;
+       *mmu=0;
+       return i;
+}
+
+
 /*
  Map handling: We have flexible paging. Each map table consists
  of a set of pages with the last page repeated to fill any holes.
@@ -41,15 +62,18 @@ void do_beep(void)
 void pagemap_init(void)
 {
     int i;
+    int max = scanmem();
+    
     /*  We have 64 8k pages for a CoCo3 so insert every other one
      *  into the kernel allocator map.
      */
-    for (i = 10; i < 64; i+=2)
+    for (i = 10; i < max ; i+=2)
         pagemap_add(i);
     /* add common page last so init gets it */
     pagemap_add(6);
 }
 
+
 void map_init(void)
 {
 }