Subject: port-arm32/12119: Current kernels do not boot on Risc PC
To: None <gnats-bugs@gnats.netbsd.org>
From: None <chris@paradox.demon.co.uk>
List: netbsd-bugs
Date: 02/03/2001 05:33:23
>Number:         12119
>Category:       port-arm32
>Synopsis:       Due to the addition of UBC more kernel VM space is needed
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    port-arm32-maintainer
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Sat Feb 03 05:36:00 PST 2001
>Closed-Date:
>Last-Modified:
>Originator:     
>Release:        02-02-2001
>Organization:
>Environment:
	
System: NetBSD pinky.paradox.demon.co.uk 1.5R NetBSD 1.5R (PINKY2) #10: Fri Feb 2 23:47:51 GMT 2001 chris@pinky.paradox.demon.co.uk:/usr/src/src/sys/arch/i386/compile/PINKY2 i386
Architecture: i386
Machine: i386
>Description:
	Since the addition of UBC more kernel VM space is required, RiscPC's only have 48MB available.  This appears not to be enough as the kernel fails to boot.
>How-To-Repeat:
	Compile and boot a current Risc-PC kernel.
>Fix:
	Attached is a patch that doubles the kernel VM space available.  Note that due to the rearranging of the VM map that boot messages can not be seen until the kernel has completed the first page table switch.
	Also worth noting is that the patch also halves the number of buffers allocated.
	The patch is based on work by myself and Mike Pumford.
	
Index: sys/arch/arm32/include/io.h
===================================================================
RCS file: /usr/src/local.cvs/netbsd/sys/arch/arm32/include/io.h,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 io.h
--- sys/arch/arm32/include/io.h	2000/12/08 22:13:35	1.1.1.1
+++ sys/arch/arm32/include/io.h	2001/01/25 00:10:12
@@ -50,30 +50,29 @@
  * This is difficuly as the podule addresses are interleaved with the
  * other IO devices thus making it difficult to separate them.
  */
- 
 #define IO_CONF_BASE			0xf6000000
 
 #define IO_HW_BASE			0x03000000
 
-#define IO_BASE				0xf6200000
+#define IO_BASE				(IO_CONF_BASE + 0x00200000)
 
-#define COMBO_BASE			0xf6210000
+#define COMBO_BASE			(IO_BASE + 0x00010000)
 
-#define IDE_CONTROLLER_BASE		0xf62107c0
+#define IDE_CONTROLLER_BASE		(COMBO_BASE + 0x000007c0)
 
-#define FLOPPY_CONTROLLER_BASE		0xf6210fc0
+#define FLOPPY_CONTROLLER_BASE		(COMBO_BASE + 0x00000fc0)
 
 #define FLOPPY_DACK			0x00002000
 
-#define SERIAL0_CONTROLLER_BASE		0xf6210fe0
+#define SERIAL0_CONTROLLER_BASE		(COMBO_BASE + 0x00000fe0)
 
-#define SERIAL1_CONTROLLER_BASE		0xf6210be0
+#define SERIAL1_CONTROLLER_BASE		(COMBO_BASE + 0x00000be0)
 
-#define PARALLEL_CONTROLLER_BASE	0xf62109e0
+#define PARALLEL_CONTROLLER_BASE	(COMBO_BASE + 0x000009e0)
 
 #ifdef RC7500
 
-#define IDE_CONTROLLER_BASE2		0xf622B000
+#define IDE_CONTROLLER_BASE2		(IO_BASE + 0x0002B000)
 
 /*
  * a bit low turns attached LED on
@@ -98,17 +97,17 @@
 
 #define SIMPLE_PODULE_SIZE	0x00004000
 
-#define MOD_PODULE_BASE		0xf6200000
-#define SYNC_PODULE_BASE	0xf63c0000
+#define MOD_PODULE_BASE		(IO_BASE)
+#define SYNC_PODULE_BASE	(IO_BASE + 0x001c0000)
 #define SYNC_PODULE_HW_BASE	0x033c0000
-#define FAST_PODULE_BASE	0xf6340000
-#define MEDIUM_PODULE_BASE	0xf60c0000
-#define SLOW_PODULE_BASE	0xf6040000
+#define FAST_PODULE_BASE	(IO_CONF_BASE + 0x00340000)
+#define MEDIUM_PODULE_BASE	(IO_CONF_BASE + 0x000c0000)
+#define SLOW_PODULE_BASE	(IO_CONF_BASE + 0x00040000)
 
 #define PODULE_GAP		0x00020000
 #define MAX_PODULES		8
 
-#define NETSLOT_BASE		0xf622b000
+#define NETSLOT_BASE		(IO_CONF_BASE + 0x0022b000)
 #define MAX_NETSLOTS		1
 
 /* End of io.h */
Index: sys/arch/arm32/include/vidc.h
===================================================================
RCS file: /usr/src/local.cvs/netbsd/sys/arch/arm32/include/vidc.h,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 vidc.h
--- sys/arch/arm32/include/vidc.h	2000/12/08 22:13:36	1.1.1.1
+++ sys/arch/arm32/include/vidc.h	2001/01/25 00:09:29
@@ -62,9 +62,7 @@
 /* VIDC20 Base addresses */
 
 #define VIDC_HW_BASE 0x03400000
-
-#define VIDC_BASE    0xf6100000
-
+#define VIDC_BASE    0xf7100000
 /* Video registers */
 
 #define VIDC_PALETTE 0x00000000
@@ -154,9 +152,9 @@
 /* Video display addresses */
 
 /* Where the display memory is mapped */
-
-#define VMEM_VBASE 0xf4000000
-
+/* note that there's not normally more than 2MB */
+#define VMEM_VBASE 0xf7400000
+ 
 /* Where the VRAM will be found */
 
 #define VRAM_BASE 0x02000000
Index: sys/arch/arm32/include/vmparam.h
===================================================================
RCS file: /usr/src/local.cvs/netbsd/sys/arch/arm32/include/vmparam.h,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 vmparam.h
--- sys/arch/arm32/include/vmparam.h	2000/12/08 22:13:36	1.1.1.1
+++ sys/arch/arm32/include/vmparam.h	2001/01/24 21:22:46
@@ -122,10 +122,11 @@
 #define	KERNEL_VM_SIZE		0x04000000
 #else
 /*
- * The range 0xf1000000 - 0xf3ffffff is available for kernel VM space
- * Fixed mappings exist from 0xf4000000 - 0xffffffff
+ * The range 0xf1000000 - 0xf6ffffff is available for kernel VM space
+ * Fixed mappings exist from 0xf7000000 - 0xffffffff
+ * well we've shifted stuff up to be in 0xffxxxxxx
  */
-#define	KERNEL_VM_SIZE		0x03000000
+#define	KERNEL_VM_SIZE		0x06000000
 #endif
 #define	PROCESS_PAGE_TBLS_BASE	PAGE_TABLE_SPACE_START
 
@@ -155,7 +156,7 @@
 /* XXX max. amount of KVM to be used by buffers. */
 #ifndef VM_MAX_KERNEL_BUF
 #define VM_MAX_KERNEL_BUF \
-	((VM_MAXKERN_ADDRESS - KERNEL_VM_BASE) * 4 / 10)
+	((VM_MAXKERN_ADDRESS - KERNEL_VM_BASE) * 2 / 10)
 #endif
 
 /* virtual sizes (bytes) for various kernel submaps */
Index: sys/arch/arm32/iomd/iomdreg.h
===================================================================
RCS file: /usr/src/local.cvs/netbsd/sys/arch/arm32/iomd/iomdreg.h,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 iomdreg.h
--- sys/arch/arm32/iomd/iomdreg.h	2000/12/08 22:13:36	1.1.1.1
+++ sys/arch/arm32/iomd/iomdreg.h	2001/01/24 21:23:37
@@ -47,7 +47,7 @@
 
 #define IOMD_HW_BASE	0x03200000
 
-#define IOMD_BASE	0xf6000000
+#define IOMD_BASE	0xf7000000
 
 #define IOMD_IOCR	0x00000000
 #define IOMD_KBDDAT	0x00000001
@@ -190,7 +190,7 @@
  */
 
 #define IO_HW_MOUSE_BUTTONS	0x03210000
-#define IO_MOUSE_BUTTONS	0xf6010000
+#define IO_MOUSE_BUTTONS	(IOMD_BASE + 0x00010000)
 
 #define MOUSE_BUTTON_RIGHT  0x10
 #define MOUSE_BUTTON_MIDDLE 0x20
Index: sys/arch/arm32/riscpc/rpc_machdep.c
===================================================================
RCS file: /usr/src/local.cvs/netbsd/sys/arch/arm32/riscpc/rpc_machdep.c,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 rpc_machdep.c
--- sys/arch/arm32/riscpc/rpc_machdep.c	2000/12/08 22:13:39	1.1.1.1
+++ sys/arch/arm32/riscpc/rpc_machdep.c	2001/02/03 13:20:51
@@ -345,7 +345,7 @@ cpu_reboot(howto, bootstr)
  */
 
 /* This routine is frightening mess ! This is what my mind looks like -mark */
-
+ 
 /*
  * This code is looking even worse these days ...
  * This is the problem you get when you are booting from another Operating System
@@ -386,14 +386,6 @@ initarm(bootconf)
 	 * should go via this structure.
 	 */
 
-	/*
-	 * In the future ...
-	 *
-	 * All console output will be postponed until the primary bootstrap
-	 * has been completed so that we have had a chance to reserve some
-	 * memory for the video system if we do not have separate VRAM.
-	 */
-
 	/* Hardwire it in case we have an old boot loader */
 
 	videomemory.vidm_vbase = bootconfig.display_start;
@@ -412,47 +404,6 @@ initarm(bootconf)
 	}
 
 	/*
-	 * Initialise the physical console
-	 * This is done in main() but for the moment we do it here so that
-	 * we can use printf in initarm() before main() has been called.
-	 */
-	consinit();
-
-	/* Talk to the user */
-	printf("initarm...\n");
-
-	/* Tell the user if his boot loader is too old */
-	if (bootconfig.magic != BOOTCONFIG_MAGIC) {
-		printf("\nNO MAGIC NUMBER IN BOOTCONFIG. PLEASE UPGRADE YOUR BOOT LOADER\n\n");
-		delay(5000000);
-	}
-
-	printf("Kernel loaded from file %s\n", bootconfig.kernelname);
-	printf("Kernel arg string %s\n", (char *)bootconfig.argvirtualbase);
-
-	printf("\nBoot configuration structure reports the following memory\n");
-
-	printf("  DRAM block 0a at %08x size %08x  DRAM block 0b at %08x size %08x\n\r",
-	    bootconfig.dram[0].address,
-	    bootconfig.dram[0].pages * bootconfig.pagesize,
-	    bootconfig.dram[1].address,
-	    bootconfig.dram[1].pages * bootconfig.pagesize);
-	printf("  DRAM block 1a at %08x size %08x  DRAM block 1b at %08x size %08x\n\r",
-	    bootconfig.dram[2].address,
-	    bootconfig.dram[2].pages * bootconfig.pagesize,
-	    bootconfig.dram[3].address,
-	    bootconfig.dram[3].pages * bootconfig.pagesize);
-	printf("  VRAM block 0  at %08x size %08x\n\r",
-	    bootconfig.vram[0].address,
-	    bootconfig.vram[0].pages * bootconfig.pagesize);
-
-/*	printf("  videomem: VA=%08x PA=%08x\n", videomemory.vidm_vbase, videomemory.vidm_pbase);*/
-
-	/* Check to make sure the page size is correct */
-	if (NBPG != bootconfig.pagesize)
-		panic("Page size is not %d bytes\n", NBPG);
-
-	/*
 	 * Ok now we have the hard bit.
 	 * We have the kernel allocated up high. The rest of the memory map is
 	 * available. We are still running on RISC OS page tables.
@@ -463,26 +414,10 @@ initarm(bootconf)
 	 * The booter will have left us 6 pages at the top of memory.
 	 * Two of these are used as L2 page tables and the other 4 form the L1
 	 * page table.
-	 */
-
-	/*
+	 * 
 	 * Ok we must construct own own page table tables.
 	 * Once we have these we can reorganise the memory as required
-	 */
-
-	/*
-	 * We better check to make sure the booter has set up the scratch
-	 * area for us correctly. We use this area to create temporary pagetables
-	 * while we reorganise the memory map.
-	 */
-
-	if ((bootconfig.scratchphysicalbase & 0x3fff) != 0)
-		panic("initarm: Scratch area not aligned on 16KB boundry\n");
-
-	if ((bootconfig.scratchsize < 0xc000) != 0)
-		panic("initarm: Scratch area too small (need >= 48KB)\n");
-
-	/*
+	 *
 	 * Ok start the primary bootstrap.
 	 * The primary bootstrap basically replaces the booter page tables with
 	 * new ones that it creates in the boot scratch area. These page tables
@@ -490,9 +425,8 @@ initarm(bootconf)
 	 * This allows low physical memory to be accessed to create the
 	 * kernels page tables, relocate the kernel code from high physical
 	 * memory to low physical memory etc.
+	 *
 	 */
-	printf("initarm: Primary bootstrap ... ");
-
 	kerneldatasize = bootconfig.kernsize + bootconfig.argsize;
 
 	l2pagetable = bootconfig.scratchvirtualbase;
@@ -518,9 +452,6 @@ initarm(bootconf)
 		videomemory.vidm_type = VIDEOMEM_TYPE_VRAM;
 		videomemory.vidm_size = bootconfig.vram[0].pages * NBPG;
 	} else {
-		if (bootconfig.display_phys != bootconfig.dram[0].address)
-			panic("video DRAM is being unpredictable\n");
-
 		/*
 		 * Now we construct a L2 pagetables for the DRAM
  		 */
@@ -580,48 +511,6 @@ initarm(bootconf)
 	map_pagetable(l1pagetable, VMEM_VBASE,
 	    bootconfig.scratchphysicalbase + 0x1000);
 
-	/* Print some debugging info */
-/*	printf("page tables look like this ...\n");
-	printf("V0x00000000 - %08x\n", ReadWord(l1pagetable + 0x0000));
-	printf("V0x00100000 - %08x\n", ReadWord(l1pagetable + 0x0004));
-	printf("V0x00200000 - %08x\n", ReadWord(l1pagetable + 0x0008));
-	printf("V0x00300000 - %08x\n", ReadWord(l1pagetable + 0x000C));
-	printf("V0x03500000 - %08x\n", ReadWord(l1pagetable + 0x00d4));
-	printf("V0x00200000 - %08x\n", ReadWord(l1pagetable + 0x0080));
-	printf("V0xf0000000 - %08x\n", ReadWord(l1pagetable + 0x3c00));
-	printf("V0xf0100000 - %08x\n", ReadWord(l1pagetable + 0x3c04));
-	printf("V0xf0200000 - %08x\n", ReadWord(l1pagetable + 0x3c08));
-	printf("V0xf0300000 - %08x\n", ReadWord(l1pagetable + 0x3c0C));
-	printf("V0xf1000000 - %08x\n", ReadWord(l1pagetable + 0x3c40));
-	printf("V0xf2000000 - %08x\n", ReadWord(l1pagetable + 0x3c80));
-	printf("V0xf3000000 - %08x\n", ReadWord(l1pagetable + 0x3cc0));
-	printf("V0xf4000000 - %08x\n", ReadWord(l1pagetable + 0x3d00));
-	printf("V0xf5000000 - %08x\n", ReadWord(l1pagetable + 0x3d40));
-	printf("V0xf6000000 - %08x\n", ReadWord(l1pagetable + 0x3d80));
-	printf("V0xf7000000 - %08x\n", ReadWord(l1pagetable + 0x3dc0));
-	printf("page dir = P%08x\n", bootconfig.scratchphysicalbase + 0x4000);
-	printf("l1= V%08x\n", l1pagetable);
-*/
-
-	/* Grind to a halt if no VRAM */
-
-/*	if (bootconfig.vram[0].pages == 0) {
-		printf("Switching to bootstrap pagetables\n");
-		printf("[Hit a key top continue]\n");
-		cngetc();
-	}*/
-
-	/* If no VRAM kill the VIDC DAC's until the end of the bootstrap */
-	if (bootconfig.vram[0].pages == 0)
-		vidcconsole_blank(vconsole_current, BLANK_OFF);
-
-	/* If we don't have VRAM ..
-	 * Ahhhhhhhhhhhhhhhhhhhhhh
-	 * We have just mapped the kernel across the video DRAM from RISCOS.
-	 * Better block all printing until we complete the secondary
-	 * bootstrap and have allocate new video DRAM.
-	 */
-
 	/*
 	 * Pheww right we are ready to switch page tables !!!
 	 * The L1 table is at bootconfig.scratchphysicalbase + 0x4000
@@ -642,6 +531,76 @@ initarm(bootconf)
 	 */
 	cpu_cache_cleanID();
 
+	/* now we can open up the console and give some info out */
+	consinit();
+	
+	/* If no VRAM kill the VIDC DAC's until the end of the bootstrap */
+	if (bootconfig.vram[0].pages == 0)
+		vidcconsole_blank(vconsole_current, BLANK_OFF);
+
+	/* Tell the user if his boot loader is too old */
+	if (bootconfig.magic != BOOTCONFIG_MAGIC) {
+		printf("\nNO MAGIC NUMBER IN BOOTCONFIG. PLEASE UPGRADE YOUR BOOT LOADER\n\n");
+		delay(5000000);
+	}
+
+	/* Check to make sure the page size is correct */
+	if (NBPG != bootconfig.pagesize)
+		panic("Page size is not %d bytes\n", NBPG);
+
+	printf("Primary bootstrap complete.\n");
+	printf("Kernel loaded from file %s\n", bootconfig.kernelname);
+	printf("Kernel arg string %s\n", (char *)bootconfig.argvirtualbase);
+
+	printf("\nBoot configuration structure reports the following memory\n");
+
+	/* show what memory we do have
+	 * I belive that it's possible to have 6 blocks of dram if you've
+	 * a kinetic (4 from the motherboard, 2 from the kinetic)
+	 */
+	{
+		int x;
+		for (x = 0; x < bootconfig.dramblocks; x++)
+		{
+			printf("  DRAM block %d at %08x size %08x\n\r",
+			    x,
+			    bootconfig.dram[x].address,
+			    bootconfig.dram[x].pages * bootconfig.pagesize);
+		}
+		for (x = 0; x < bootconfig.vramblocks; x++)
+		{
+			printf("  VRAM block %d at %08x size %08x\n\r",
+			    x,
+			    bootconfig.vram[x].address,
+			    bootconfig.vram[x].pages * bootconfig.pagesize);
+		}
+	}
+
+
+#ifdef VERBOSE_INIT_ARM
+	/* lots of debug info */
+	printf("page tables look like this ...\n");
+	printf("V0x00000000 - %08x\n", ReadWord(l1pagetable + 0x0000));
+	printf("V0x00100000 - %08x\n", ReadWord(l1pagetable + 0x0004));
+	printf("V0x00200000 - %08x\n", ReadWord(l1pagetable + 0x0008));
+	printf("V0x00300000 - %08x\n", ReadWord(l1pagetable + 0x000C));
+	printf("V0x03500000 - %08x\n", ReadWord(l1pagetable + 0x00d4));
+	printf("V0x00200000 - %08x\n", ReadWord(l1pagetable + 0x0080));
+	printf("V0xf0000000 - %08x\n", ReadWord(l1pagetable + 0x3c00));
+	printf("V0xf0100000 - %08x\n", ReadWord(l1pagetable + 0x3c04));
+	printf("V0xf0200000 - %08x\n", ReadWord(l1pagetable + 0x3c08));
+	printf("V0xf0300000 - %08x\n", ReadWord(l1pagetable + 0x3c0C));
+	printf("V0xf1000000 - %08x\n", ReadWord(l1pagetable + 0x3c40));
+	printf("V0xf2000000 - %08x\n", ReadWord(l1pagetable + 0x3c80));
+	printf("V0xf3000000 - %08x\n", ReadWord(l1pagetable + 0x3cc0));
+	printf("V0xf4000000 - %08x\n", ReadWord(l1pagetable + 0x3d00));
+	printf("V0xf5000000 - %08x\n", ReadWord(l1pagetable + 0x3d40));
+	printf("V0xf6000000 - %08x\n", ReadWord(l1pagetable + 0x3d80));
+	printf("V0xf7000000 - %08x\n", ReadWord(l1pagetable + 0x3dc0));
+	printf("page dir = P%08x\n", bootconfig.scratchphysicalbase + 0x4000);
+	printf("l1= V%08x\n", l1pagetable);
+#endif
+
 	/*
 	 * Since we have mapped the VRAM up into kernel space we must
 	 * now update the bootconfig and display structures by hand.
@@ -651,9 +610,6 @@ initarm(bootconf)
 		physcon_display_base(VMEM_VBASE);
 	}
 
-	if (bootconfig.vram[0].pages != 0)
-		printf("done.\n");
-
 	id = ReadByte(IOMD_BASE + (IOMD_ID0 << 2))
 	  | (ReadByte(IOMD_BASE + (IOMD_ID1 << 2)) << 8);
 	switch (id) {
@@ -679,8 +635,9 @@ initarm(bootconf)
 	 * we have a two stage booter.
 	 *
 	 * The secondary bootstrap has the responcibility to sort locating the
-	 * kernel to the correct address and for creating the kernel page tables.
-	 * It must also set up various memory pointers that are used by pmap etc.  
+	 * kernel to the correct address and for creating the kernel page
+	 * tables.  It must also set up various memory pointers that are used
+	 * by pmap etc.  
 	 */
 	process_kernel_args();
 
@@ -971,8 +928,9 @@ initarm(bootconf)
 	/* Map the COMBO (and module space) */
 	map_section(l1pagetable, IO_BASE, IO_HW_BASE, 0);
 
+#ifdef VERBOSE_INIT_ARM
 	/* Bit more debugging info */
-/*	printf("page tables look like this ...\n");
+	printf("page tables look like this ...\n");
 	printf("V0x00000000 - %08x\n", ReadWord(l1pagetable + 0x0000));
 	printf("V0x03200000 - %08x\n", ReadWord(l1pagetable + 0x00c8));
 	printf("V0x03500000 - %08x\n", ReadWord(l1pagetable + 0x00d4));
@@ -988,7 +946,7 @@ initarm(bootconf)
 	printf("V0xf7000000 - %08x\n", ReadWord(l1pagetable + 0x3dc0));
 	printf("V0xefc00000 - %08x\n", ReadWord(l1pagetable + 0x3bf8));
 	printf("V0xef800000 - %08x\n", ReadWord(l1pagetable + 0x3bfc));
-*/
+#endif
 
 	/*
 	 * Now we have the real page tables in place so we can switch to them.
@@ -1097,11 +1055,11 @@ initarm(bootconf)
 	 * We now have the kernel in physical memory from the bottom upwards.
 	 * Kernel page tables are physically above this.
 	 * The kernel is mapped to 0xf0000000
-	 * The kernel data PTs will handle the mapping of 0xf1000000-0xf1ffffff
-	 * 2Meg of VRAM is mapped to 0xf4000000
+	 * The kernel data PTs will handle the mapping of 0xf1000000-0xf6ffffff
 	 * The page tables are mapped to 0xefc00000
-	 * The IOMD is mapped to 0xf6000000
-	 * The VIDC is mapped to 0xf6100000
+	 * The IOMD is mapped to 0xf7000000
+	 * The VIDC is mapped to 0xf7100000
+	 * 2Meg of VRAM is mapped to 0xf7400000
 	 */
 
 	/* Initialise the undefined instruction handlers */
>Release-Note:
>Audit-Trail:
>Unformatted: