1- /* $NetBSD: machdep.c,v 1.373 2025/11/30 19:17:52 thorpej Exp $ */
1+ /* $NetBSD: machdep.c,v 1.374 2025/12/02 02:26:18 thorpej Exp $ */
22
33/*
44 * Copyright (c) 1988 University of Utah.
7474 */
7575
7676#include <sys/cdefs.h>
77- __KERNEL_RCSID (0 , "$NetBSD: machdep.c,v 1.373 2025/11/30 19:17:52 thorpej Exp $" );
77+ __KERNEL_RCSID (0 , "$NetBSD: machdep.c,v 1.374 2025/12/02 02:26:18 thorpej Exp $" );
7878
7979#include "opt_adb.h"
8080#include "opt_compat_netbsd.h"
@@ -86,6 +86,7 @@ __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.373 2025/11/30 19:17:52 thorpej Exp $"
8686#include "opt_modular.h"
8787
8888#include "akbd.h"
89+ #include "audio.h"
8990#include "genfb.h"
9091#include "macfb.h"
9192#include "zsc.h"
@@ -175,9 +176,15 @@ u_long IOBase;
175176vaddr_t SCSIBase ;
176177
177178/* These are used to map kernel space: */
178- extern int numranges ;
179- extern u_long low [8 ];
180- extern u_long high [8 ];
179+ int numranges ;
180+ u_long low [8 ];
181+ u_long high [8 ];
182+ u_long last_page ; /* PA of last physical page */
183+ vaddr_t newvideoaddr ;
184+ int vidlen ;
185+
186+ extern paddr_t avail_start , avail_end ;
187+
181188extern int machineid ;
182189
183190/* These are used to map NuBus space: */
250257mac68k_init (void )
251258{
252259 int i ;
253- extern vaddr_t avail_start ;
254260
255261 /*
256262 * Tell the VM system about available physical memory.
@@ -2640,3 +2646,155 @@ mm_md_physacc(paddr_t pa, vm_prot_t prot)
26402646
26412647 return (pa < last_page ) ? 0 : EFAULT ;
26422648}
2649+
2650+ void __attribute__((no_instrument_function ))
2651+ pmap_machine_check_bootstrap_allocations (paddr_t nextpa , paddr_t firstpa )
2652+ {
2653+ int i ;
2654+
2655+ for (i = 0 ; i < numranges ; i ++ ) {
2656+ if (low [i ] <= firstpa && firstpa < high [i ]) {
2657+ break ;
2658+ }
2659+ }
2660+ if (i >= numranges || nextpa > high [i ]) {
2661+ if (mac68k_machine .do_graybars ) {
2662+ printf ("Failure in NetBSD boot; " );
2663+ if (i < numranges ) {
2664+ printf ("nextpa=0x%lx, high[%d]=0x%lx.\n" ,
2665+ nextpa , i , high [i ]);
2666+ } else {
2667+ printf ("can't find kernel RAM segment.\n" );
2668+ }
2669+ printf ("You're hosed! Try booting with 32-bit " );
2670+ printf ("addressing enabled in the memory control " );
2671+ printf ("panel.\n" );
2672+ printf ("Older machines may need Mode32 to get that " );
2673+ printf ("option.\n" );
2674+ }
2675+ panic ("Cannot work with the current memory mappings." );
2676+ }
2677+ }
2678+
2679+ void bootstrap_mac68k (int );
2680+
2681+ void __attribute__((no_instrument_function ))
2682+ bootstrap_mac68k (int tc )
2683+ {
2684+ #if NZSC > 0
2685+ extern int zsinited ;
2686+ extern void zs_init (void );
2687+ #endif
2688+ extern int * esym ;
2689+ paddr_t nextpa ;
2690+ void * oldROMBase ;
2691+ char use_bootmem = 0 ;
2692+ int i ;
2693+
2694+ #ifdef DJMEMCMAX
2695+ if (mac68k_machine .machineid == MACH_MACC650 ||
2696+ mac68k_machine .machineid == MACH_MACQ650 ||
2697+ mac68k_machine .machineid == MACH_MACQ610 ||
2698+ mac68k_machine .machineid == MACH_MACC610 ||
2699+ mac68k_machine .machineid == MACH_MACQ800 ) {
2700+ use_bootmem = 1 ;
2701+ }
2702+ #endif
2703+
2704+ if (mac68k_machine .do_graybars )
2705+ printf ("Bootstrapping NetBSD/mac68k.\n" );
2706+
2707+ oldROMBase = ROMBase ;
2708+ mac68k_video .mv_phys = mac68k_video .mv_kvaddr ;
2709+
2710+ if ((!use_bootmem ) && (((tc & 0x80000000 ) && (mmutype == MMU_68030 )) ||
2711+ ((tc & 0x8000 ) && (mmutype == MMU_68040 )))) {
2712+ if (mac68k_machine .do_graybars )
2713+ printf ("Getting mapping from MMU.\n" );
2714+ (void ) get_mapping ();
2715+ if (mac68k_machine .do_graybars )
2716+ printf ("Done.\n" );
2717+ } else {
2718+ /* MMU not enabled. Fake up ranges. */
2719+ numranges = 1 ;
2720+ low [0 ] = 0 ;
2721+ high [0 ] = mac68k_machine .mach_memsize * (1024 * 1024 );
2722+ if (mac68k_machine .do_graybars )
2723+ printf ("Faked range to byte 0x%lx.\n" , high [0 ]);
2724+ }
2725+ nextpa = load_addr + m68k_round_page (esym );
2726+
2727+ if (mac68k_machine .do_graybars )
2728+ printf ("Bootstrapping the pmap system.\n" );
2729+
2730+ vidlen = m68k_round_page (mac68k_video .mv_height *
2731+ mac68k_video .mv_stride + m68k_page_offset (mac68k_video .mv_phys ));
2732+
2733+ /* Sum up the memory for pmap_bootstrap1(). */
2734+ vsize_t mem_size = 0 ;
2735+ for (i = 0 ; i < numranges ; i ++ )
2736+ mem_size += high [i ] - low [i ];
2737+ physmem = m68k_btop (mem_size );
2738+
2739+ nextpa = pmap_bootstrap1 (nextpa , load_addr );
2740+
2741+ /*
2742+ * VM data structures are now initialized, set up data for
2743+ * the pmap module.
2744+ *
2745+ * Note about avail_end: msgbuf is initialized just after
2746+ * avail_end in machdep.c. Since the last page is used
2747+ * for rebooting the system (code is copied there and
2748+ * execution continues from copied code before the MMU
2749+ * is disabled), the msgbuf will get trounced between
2750+ * reboots if it's placed in the last physical page.
2751+ * To work around this, we move avail_end back one more
2752+ * page so the msgbuf can be preserved.
2753+ */
2754+ avail_start = m68k_round_page (nextpa );
2755+ last_page = high [numranges - 1 ] - m68k_ptob (1 );
2756+ #if NAUDIO > 0
2757+ /*
2758+ * Reduce high by an extra 7 pages which are used by the EASC on some
2759+ * machines. last_page is unchanged as the last page can still be
2760+ * safetly used to reboot the system.
2761+ */
2762+ high [numranges - 1 ] -= (m68k_round_page (MSGBUFSIZE ) + m68k_ptob (8 ));
2763+ #else
2764+ high [numranges - 1 ] -= (m68k_round_page (MSGBUFSIZE ) + m68k_ptob (1 ));
2765+ #endif
2766+ avail_end = high [numranges - 1 ];
2767+
2768+ if (mac68k_machine .do_graybars )
2769+ printf ("Pmap bootstrapped.\n" );
2770+
2771+ if (!vidlen )
2772+ panic ("Don't know how to relocate video!" );
2773+
2774+ if (mac68k_machine .do_graybars )
2775+ printf ("Moving ROMBase from %p to %p.\n" , oldROMBase , ROMBase );
2776+
2777+ mrg_fixupROMBase (oldROMBase , ROMBase );
2778+
2779+ if (mac68k_machine .do_graybars )
2780+ printf ("Video address %p -> %p.\n" ,
2781+ (void * )mac68k_video .mv_kvaddr , (void * )newvideoaddr );
2782+
2783+ mac68k_set_io_offsets (IOBase );
2784+
2785+ /*
2786+ * If the serial ports are going (for console or 'echo'), then
2787+ * we need to make sure the IO change gets propagated properly.
2788+ * This resets the base addresses for the 8530 (serial) driver.
2789+ *
2790+ * WARNING!!! No printfs() (etc) BETWEEN zs_init() and the end
2791+ * of this function (where we start using the MMU, so the new
2792+ * address is correct.
2793+ */
2794+ #if NZSC > 0
2795+ if (zsinited != 0 )
2796+ zs_init ();
2797+ #endif
2798+
2799+ mac68k_video .mv_kvaddr = newvideoaddr ;
2800+ }
0 commit comments