intmmu.S revision 1.2.2.5 1 1.2.2.5 jdolecek /* $NetBSD: intmmu.S,v 1.2.2.5 2002/09/06 08:34:07 jdolecek Exp $ */
2 1.2.2.2 thorpej
3 1.2.2.2 thorpej /*
4 1.2.2.2 thorpej * Copyright (c) 2001 ARM Ltd
5 1.2.2.2 thorpej * All rights reserved.
6 1.2.2.2 thorpej *
7 1.2.2.2 thorpej * Redistribution and use in source and binary forms, with or without
8 1.2.2.2 thorpej * modification, are permitted provided that the following conditions
9 1.2.2.2 thorpej * are met:
10 1.2.2.2 thorpej * 1. Redistributions of source code must retain the above copyright
11 1.2.2.2 thorpej * notice, this list of conditions and the following disclaimer.
12 1.2.2.2 thorpej * 2. Redistributions in binary form must reproduce the above copyright
13 1.2.2.2 thorpej * notice, this list of conditions and the following disclaimer in the
14 1.2.2.2 thorpej * documentation and/or other materials provided with the distribution.
15 1.2.2.2 thorpej * 3. The name of the company may not be used to endorse or promote
16 1.2.2.2 thorpej * products derived from this software without specific prior written
17 1.2.2.2 thorpej * permission.
18 1.2.2.2 thorpej *
19 1.2.2.2 thorpej * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
20 1.2.2.2 thorpej * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 1.2.2.2 thorpej * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 1.2.2.2 thorpej * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23 1.2.2.2 thorpej * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 1.2.2.2 thorpej * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 1.2.2.2 thorpej * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 1.2.2.2 thorpej * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 1.2.2.2 thorpej * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 1.2.2.2 thorpej * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 1.2.2.2 thorpej * SUCH DAMAGE.
30 1.2.2.2 thorpej */
31 1.2.2.2 thorpej
32 1.2.2.2 thorpej #include "assym.h"
33 1.2.2.2 thorpej #include <machine/asm.h>
34 1.2.2.2 thorpej #include <arm/armreg.h>
35 1.2.2.2 thorpej #include <arm/arm32/pte.h>
36 1.2.2.2 thorpej
37 1.2.2.5 jdolecek .section .start,"ax",%progbits
38 1.2.2.2 thorpej
39 1.2.2.2 thorpej ASENTRY_NP(integrator_start)
40 1.2.2.2 thorpej mov r6, #0x16000000 /* UART0 Physical base*/
41 1.2.2.2 thorpej mov r3, #'A'
42 1.2.2.2 thorpej str r3, [r6] /* Let the world know we are alive */
43 1.2.2.2 thorpej
44 1.2.2.2 thorpej /*
45 1.2.2.2 thorpej * At this time the MMU is off.
46 1.2.2.2 thorpej * We build up an initial memory map at 0x8000 that we can use to get
47 1.2.2.2 thorpej * the kernel running from the top of memory. All mappings in this table
48 1.2.2.2 thorpej * use L1 section maps.
49 1.2.2.2 thorpej */
50 1.2.2.2 thorpej
51 1.2.2.2 thorpej /*
52 1.2.2.2 thorpej * Set Virtual == Physical
53 1.2.2.2 thorpej */
54 1.2.2.4 jdolecek mov r3, #(L1_S_AP(AP_KRW))
55 1.2.2.4 jdolecek add r3, r3, #(L1_TYPE_S)
56 1.2.2.2 thorpej mov r2, #0x100000 /* advance by 1MB */
57 1.2.2.2 thorpej mov r1, #0x8000 /* page table start */
58 1.2.2.2 thorpej mov r0, #0x1000 /* page table size */
59 1.2.2.2 thorpej
60 1.2.2.2 thorpej Lflat:
61 1.2.2.2 thorpej str r3, [r1], #0x0004
62 1.2.2.2 thorpej add r3, r3, r2
63 1.2.2.2 thorpej subs r0, r0, #1
64 1.2.2.2 thorpej bgt Lflat
65 1.2.2.2 thorpej
66 1.2.2.2 thorpej /*
67 1.2.2.5 jdolecek * Map VA 0xc0000000->0xc03fffff to PA 0x00000000->0x003fffff
68 1.2.2.2 thorpej */
69 1.2.2.4 jdolecek mov r3, #(L1_S_AP(AP_KRW))
70 1.2.2.4 jdolecek add r3, r3, #(L1_TYPE_S)
71 1.2.2.2 thorpej mov r1, #0x8000 /* page table start */
72 1.2.2.3 jdolecek add r1, r1, #(0xc00 * 4) /* offset to 0xc00xxxxx */
73 1.2.2.5 jdolecek # add r1, r1, #(0x001 * 4) /* offset to 0xc01xxxxx */
74 1.2.2.5 jdolecek mov r0, #63
75 1.2.2.2 thorpej Lkern:
76 1.2.2.5 jdolecek str r3, [r1], #0x0004 /* 0xc000000-0xc03fffff */
77 1.2.2.2 thorpej add r3, r3, r2
78 1.2.2.2 thorpej subs r0, r0, #1
79 1.2.2.2 thorpej bgt Lkern
80 1.2.2.2 thorpej /*
81 1.2.2.2 thorpej * Mapping the peripheral register region (0x10000000->0x1fffffff) linearly
82 1.2.2.2 thorpej * would require 256MB of virtual memory (as much space as the entire kernel
83 1.2.2.2 thorpej * virtual space). So we map the first 1M of each 16MB sub-space into the
84 1.2.2.2 thorpej * region VA 0xfd000000->0xfdffffff; this should map enough of the peripheral
85 1.2.2.2 thorpej * space to at least get us up and running.
86 1.2.2.2 thorpej */
87 1.2.2.4 jdolecek mov r3, #(L1_S_AP(AP_KRW))
88 1.2.2.4 jdolecek add r3, r3, #L1_TYPE_S
89 1.2.2.2 thorpej add r3, r3, #0x10000000 /* Peripherals base */
90 1.2.2.2 thorpej mov r1, #0x8000 /* page table start */
91 1.2.2.2 thorpej add r1, r1, #(0xfd0 * 4)
92 1.2.2.2 thorpej mov r2, #0x01000000 /* 16MB increment. */
93 1.2.2.2 thorpej mov r0, #16
94 1.2.2.2 thorpej Lperiph:
95 1.2.2.2 thorpej str r3, [r1], #4 /* 0xfd000000-0xfdffffff */
96 1.2.2.2 thorpej add r3, r3, r2
97 1.2.2.2 thorpej subs r0, r0, #1
98 1.2.2.2 thorpej bgt Lperiph
99 1.2.2.2 thorpej
100 1.2.2.2 thorpej /*
101 1.2.2.2 thorpej * We now have our page table ready, so load it up and light the blue
102 1.2.2.2 thorpej * touch paper.
103 1.2.2.2 thorpej */
104 1.2.2.2 thorpej
105 1.2.2.2 thorpej /* set the location of the L1 page table */
106 1.2.2.2 thorpej mov r1, #0x8000
107 1.2.2.2 thorpej mcr p15, 0, r1, c2, c0, 0
108 1.2.2.2 thorpej
109 1.2.2.2 thorpej /* Flush the old TLBs (just in case) */
110 1.2.2.2 thorpej mcr p15, 0, r1, c8, c7, 0
111 1.2.2.2 thorpej mov r2, #'B'
112 1.2.2.2 thorpej strb r2, [r6]
113 1.2.2.2 thorpej
114 1.2.2.2 thorpej /* Set the Domain Access register. Very important! */
115 1.2.2.2 thorpej mov r1, #1
116 1.2.2.2 thorpej mcr p15, 0, r1, c3, c0, 0
117 1.2.2.2 thorpej
118 1.2.2.2 thorpej /*
119 1.2.2.2 thorpej * set mmu bit (don't set anything else for now, we don't know
120 1.2.2.2 thorpej * what sort of CPU we have yet.
121 1.2.2.2 thorpej */
122 1.2.2.2 thorpej mov r1, #CPU_CONTROL_MMU_ENABLE
123 1.2.2.2 thorpej
124 1.2.2.2 thorpej /*
125 1.2.2.2 thorpej * This is where it might all start to go wrong if the cpu fitted to your
126 1.2.2.2 thorpej * integrator does not have an MMU.
127 1.2.2.2 thorpej */
128 1.2.2.2 thorpej /* fetch current control state */
129 1.2.2.2 thorpej mrc p15, 0, r2, c1, c0, 0
130 1.2.2.2 thorpej orr r2, r2, r1
131 1.2.2.2 thorpej
132 1.2.2.2 thorpej /* set new control state */
133 1.2.2.2 thorpej mcr p15, 0, r2, c1, c0, 0
134 1.2.2.2 thorpej
135 1.2.2.2 thorpej mov r0, r0
136 1.2.2.2 thorpej mov r0, r0
137 1.2.2.2 thorpej mov r0, r0
138 1.2.2.2 thorpej
139 1.2.2.2 thorpej /* emit a char. Uart is now at 0xfd600000 */
140 1.2.2.2 thorpej mov r6, #0xfd000000
141 1.2.2.2 thorpej add r6, r6, #0x00600000
142 1.2.2.2 thorpej mov r2, #'C'
143 1.2.2.2 thorpej strb r2, [r6]
144 1.2.2.2 thorpej
145 1.2.2.2 thorpej /* jump to kernel space */
146 1.2.2.2 thorpej mov r0, #0x0200
147 1.2.2.2 thorpej
148 1.2.2.2 thorpej /* Switch to kernel VM and really set the ball rolling. */
149 1.2.2.2 thorpej ldr pc, Lstart
150 1.2.2.2 thorpej
151 1.2.2.2 thorpej Lstart: .long start
152