fix a bug in the elf loader/mmu stuff in the bootloader that would cause
[newos.git] / boot / sparc / dvma.c
blob03e801926c8be89f4788d01bf1474dfd3dae6bc2
1 /* $OpenBSD: dvma.c,v 1.1 1997/09/17 10:46:18 downsj Exp $ */
2 /* $NetBSD: dvma.c,v 1.2 1995/09/17 00:50:56 pk Exp $ */
3 /*
4 * Copyright (c) 1995 Gordon W. Ross
5 * All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 * 4. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by Gordon Ross
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 * The easiest way to deal with the need for DVMA mappings is
35 * to just map the entire third megabyte of RAM into DVMA space.
36 * That way, dvma_mapin can just compute the DVMA alias address,
37 * and dvma_mapout does nothing. Note that this assumes all
38 * standalone programs stay in the range SA_MIN_VA .. SA_MAX_VA
41 #include <sys/param.h>
42 #include <machine/pte.h>
43 #include <machine/ctlreg.h>
45 #include <promdev.h>
47 #define DVMA_BASE 0xFFF00000
48 #define DVMA_MAPLEN 0xE0000 /* 1 MB - 128K (save MONSHORTSEG) */
50 #define SA_MIN_VA (RELOC - 0x40000) /* XXX - magic constant */
51 #define SA_MAX_VA (SA_MIN_VA + DVMA_MAPLEN)
53 void
54 dvma_init()
56 register int segva, dmava;
58 dmava = DVMA_BASE;
59 for (segva = SA_MIN_VA; segva < SA_MAX_VA; segva += NBPSG) {
60 setsegmap(dmava, getsegmap(segva));
61 dmava += NBPSG;
66 * Convert a local address to a DVMA address.
68 char *
69 dvma_mapin(char *addr, size_t len)
71 register int va = (int)addr;
73 /* Make sure the address is in the DVMA map. */
74 if ((va < SA_MIN_VA) || (va >= SA_MAX_VA))
75 panic("dvma_mapin");
77 va += DVMA_BASE - SA_MIN_VA;
79 return ((char *)va);
83 * Convert a DVMA address to a local address.
85 char *
86 dvma_mapout(char *addr, size_t len)
88 int va = (int)addr;
90 /* Make sure the address is in the DVMA map. */
91 if ((va < DVMA_BASE) || (va >= (DVMA_BASE + DVMA_MAPLEN)))
92 panic("dvma_mapout");
94 va -= DVMA_BASE - SA_MIN_VA;
96 return ((char *)va);
99 extern char *alloc __P((int));
101 char *
102 dvma_alloc(int len)
104 char *mem;
106 mem = alloc(len);
107 if (!mem)
108 return (mem);
109 return (dvma_mapin(mem, len));
112 extern void free(void *ptr, int len);
113 void
114 dvma_free(char *dvma, int len)
116 char *mem;
118 mem = dvma_mapout(dvma, len);
119 if (mem)
120 free(mem, len);