Skip to content

Commit 9947137

Browse files
committed
Revert previous (wrong commit message, obviously).
1 parent 15ce047 commit 9947137

1 file changed

Lines changed: 171 additions & 6 deletions

File tree

sys/arch/mac68k/mac68k/pmap_bootstrap.c

Lines changed: 171 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $NetBSD: pmap_bootstrap.c,v 1.111 2025/12/02 02:08:11 thorpej Exp $ */
1+
/* $NetBSD: pmap_bootstrap.c,v 1.112 2025/12/02 02:22:34 thorpej Exp $ */
22

33
/*
44
* Copyright (c) 1991, 1993
@@ -36,12 +36,15 @@
3636
*/
3737

3838
#include <sys/cdefs.h>
39-
__KERNEL_RCSID(0, "$NetBSD: pmap_bootstrap.c,v 1.111 2025/12/02 02:08:11 thorpej Exp $");
39+
__KERNEL_RCSID(0, "$NetBSD: pmap_bootstrap.c,v 1.112 2025/12/02 02:22:34 thorpej Exp $");
4040

41+
#include "audio.h"
4142
#include "opt_ddb.h"
4243
#include "opt_kgdb.h"
4344
#include "opt_m68k_arch.h"
4445

46+
#include "zsc.h"
47+
4548
#include <sys/param.h>
4649
#include <sys/systm.h>
4750
#include <sys/reboot.h>
@@ -62,10 +65,23 @@ __KERNEL_RCSID(0, "$NetBSD: pmap_bootstrap.c,v 1.111 2025/12/02 02:08:11 thorpej
6265
extern char *etext;
6366
extern char *extiobase;
6467

68+
extern paddr_t avail_start, avail_end;
6569
extern vaddr_t kernel_reloc_offset;
6670

67-
extern int vidlen;
68-
extern vaddr_t newvideoaddr;
71+
#if NZSC > 0
72+
extern int zsinited;
73+
#endif
74+
75+
/*
76+
* These are used to map the RAM:
77+
*/
78+
int numranges; /* = 0 == don't use the ranges */
79+
u_long low[8];
80+
u_long high[8];
81+
u_long last_page; /* PA of the last physical page */
82+
int vidlen;
83+
#define VIDMAPSIZE btoc(vidlen)
84+
static vaddr_t newvideoaddr;
6985

7086
extern void * ROMBase;
7187

@@ -81,6 +97,9 @@ void *CADDR1, *CADDR2;
8197
char *vmmap;
8298
void *msgbufaddr;
8399

100+
paddr_t pmap_bootstrap1(paddr_t, paddr_t);
101+
void bootstrap_mac68k(int);
102+
84103
/*
85104
* Bootstrap the VM system.
86105
*
@@ -135,7 +154,7 @@ pmap_bootstrap1(paddr_t nextpa, paddr_t firstpa)
135154
nextpa += PAGE_SIZE;
136155
kptpa = nextpa;
137156
nptpages = Sysptsize +
138-
(IIOMAPSIZE + ROMMAPSIZE + btoc(vidlen) + NPTEPG - 1) / NPTEPG;
157+
(IIOMAPSIZE + ROMMAPSIZE + VIDMAPSIZE + NPTEPG - 1) / NPTEPG;
139158
/*
140159
* New kmem arena is allocated prior to pmap_init(), so we need
141160
* additiona PT pages to account for that allocation, which is based
@@ -399,7 +418,7 @@ pmap_bootstrap1(paddr_t nextpa, paddr_t firstpa)
399418
PG_RW | PG_V | PG_CI;
400419
newvideoaddr = PTE2VA(pte)
401420
+ m68k_page_offset(mac68k_video.mv_phys);
402-
epte = &pte[btoc(vidlen)];
421+
epte = &pte[VIDMAPSIZE];
403422
while (pte < epte) {
404423
*pte++ = protopte;
405424
protopte += PAGE_SIZE;
@@ -456,3 +475,149 @@ pmap_bootstrap1(paddr_t nextpa, paddr_t firstpa)
456475

457476
return nextpa;
458477
}
478+
479+
void
480+
pmap_machine_check_bootstrap_allocations(paddr_t nextpa, paddr_t firstpa)
481+
{
482+
int i;
483+
484+
for (i = 0; i < numranges; i++)
485+
if (low[i] <= firstpa && firstpa < high[i])
486+
break;
487+
if (i >= numranges || nextpa > high[i]) {
488+
if (mac68k_machine.do_graybars) {
489+
printf("Failure in NetBSD boot; ");
490+
if (i < numranges)
491+
printf("nextpa=0x%lx, high[%d]=0x%lx.\n",
492+
nextpa, i, high[i]);
493+
else
494+
printf("can't find kernel RAM segment.\n");
495+
printf("You're hosed! Try booting with 32-bit ");
496+
printf("addressing enabled in the memory control ");
497+
printf("panel.\n");
498+
printf("Older machines may need Mode32 to get that ");
499+
printf("option.\n");
500+
}
501+
panic("Cannot work with the current memory mappings.");
502+
}
503+
}
504+
505+
void
506+
bootstrap_mac68k(int tc)
507+
{
508+
#if NZSC > 0
509+
extern void zs_init(void);
510+
#endif
511+
extern int *esym;
512+
paddr_t nextpa;
513+
void *oldROMBase;
514+
char use_bootmem = 0;
515+
int i;
516+
517+
#ifdef DJMEMCMAX
518+
if(mac68k_machine.machineid == MACH_MACC650 ||
519+
mac68k_machine.machineid == MACH_MACQ650 ||
520+
mac68k_machine.machineid == MACH_MACQ610 ||
521+
mac68k_machine.machineid == MACH_MACC610 ||
522+
mac68k_machine.machineid == MACH_MACQ800) {
523+
use_bootmem = 1;
524+
}
525+
#endif
526+
527+
if (mac68k_machine.do_graybars)
528+
printf("Bootstrapping NetBSD/mac68k.\n");
529+
530+
oldROMBase = ROMBase;
531+
mac68k_video.mv_phys = mac68k_video.mv_kvaddr;
532+
533+
if ((!use_bootmem) && (((tc & 0x80000000) && (mmutype == MMU_68030)) ||
534+
((tc & 0x8000) && (mmutype == MMU_68040)))) {
535+
if (mac68k_machine.do_graybars)
536+
printf("Getting mapping from MMU.\n");
537+
(void) get_mapping();
538+
if (mac68k_machine.do_graybars)
539+
printf("Done.\n");
540+
} else {
541+
/* MMU not enabled. Fake up ranges. */
542+
numranges = 1;
543+
low[0] = 0;
544+
high[0] = mac68k_machine.mach_memsize * (1024 * 1024);
545+
if (mac68k_machine.do_graybars)
546+
printf("Faked range to byte 0x%lx.\n", high[0]);
547+
}
548+
nextpa = load_addr + m68k_round_page(esym);
549+
550+
if (mac68k_machine.do_graybars)
551+
printf("Bootstrapping the pmap system.\n");
552+
553+
vidlen = m68k_round_page(mac68k_video.mv_height *
554+
mac68k_video.mv_stride + m68k_page_offset(mac68k_video.mv_phys));
555+
556+
/* Sum up the memory for pmap_bootstrap1(). */
557+
vsize_t mem_size = 0;
558+
for (i = 0; i < numranges; i++)
559+
mem_size += high[i] - low[i];
560+
physmem = m68k_btop(mem_size);
561+
562+
nextpa = pmap_bootstrap1(nextpa, load_addr);
563+
564+
/*
565+
* VM data structures are now initialized, set up data for
566+
* the pmap module.
567+
*
568+
* Note about avail_end: msgbuf is initialized just after
569+
* avail_end in machdep.c. Since the last page is used
570+
* for rebooting the system (code is copied there and
571+
* execution continues from copied code before the MMU
572+
* is disabled), the msgbuf will get trounced between
573+
* reboots if it's placed in the last physical page.
574+
* To work around this, we move avail_end back one more
575+
* page so the msgbuf can be preserved.
576+
*/
577+
avail_start = m68k_round_page(nextpa);
578+
last_page = high[numranges - 1] - m68k_ptob(1);
579+
#if NAUDIO > 0
580+
/*
581+
* Reduce high by an extra 7 pages which are used by the EASC on some
582+
* machines. last_page is unchanged as the last page can still be
583+
* safetly used to reboot the system.
584+
*/
585+
high[numranges - 1] -= (m68k_round_page(MSGBUFSIZE) + m68k_ptob(8));
586+
#else
587+
high[numranges - 1] -= (m68k_round_page(MSGBUFSIZE) + m68k_ptob(1));
588+
#endif
589+
avail_end = high[numranges - 1];
590+
591+
if (mac68k_machine.do_graybars)
592+
printf("Pmap bootstrapped.\n");
593+
594+
if (!vidlen)
595+
panic("Don't know how to relocate video!");
596+
597+
if (mac68k_machine.do_graybars)
598+
printf("Moving ROMBase from %p to %p.\n", oldROMBase, ROMBase);
599+
600+
mrg_fixupROMBase(oldROMBase, ROMBase);
601+
602+
if (mac68k_machine.do_graybars)
603+
printf("Video address %p -> %p.\n",
604+
(void *)mac68k_video.mv_kvaddr, (void *)newvideoaddr);
605+
606+
mac68k_set_io_offsets(IOBase);
607+
608+
/*
609+
* If the serial ports are going (for console or 'echo'), then
610+
* we need to make sure the IO change gets propagated properly.
611+
* This resets the base addresses for the 8530 (serial) driver.
612+
*
613+
* WARNING!!! No printfs() (etc) BETWEEN zs_init() and the end
614+
* of this function (where we start using the MMU, so the new
615+
* address is correct.
616+
*/
617+
#if NZSC > 0
618+
if (zsinited != 0)
619+
zs_init();
620+
#endif
621+
622+
mac68k_video.mv_kvaddr = newvideoaddr;
623+
}

0 commit comments

Comments
 (0)