1 |
/* |
2 |
* Copyright (C) 2005-2007 Anders Gavare. All rights reserved. |
3 |
* |
4 |
* Redistribution and use in source and binary forms, with or without |
5 |
* modification, are permitted provided that the following conditions are met: |
6 |
* |
7 |
* 1. Redistributions of source code must retain the above copyright |
8 |
* notice, this list of conditions and the following disclaimer. |
9 |
* 2. Redistributions in binary form must reproduce the above copyright |
10 |
* notice, this list of conditions and the following disclaimer in the |
11 |
* documentation and/or other materials provided with the distribution. |
12 |
* 3. The name of the author may not be used to endorse or promote products |
13 |
* derived from this software without specific prior written permission. |
14 |
* |
15 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
16 |
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
17 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
18 |
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
19 |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
20 |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
21 |
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
22 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
23 |
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
24 |
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
25 |
* SUCH DAMAGE. |
26 |
* |
27 |
* |
28 |
* $Id: machine_alpha.c,v 1.14 2007/06/15 18:08:10 debug Exp $ |
29 |
* |
30 |
* COMMENT: DEC Alpha machines |
31 |
*/ |
32 |
|
33 |
#include <stdio.h> |
34 |
#include <string.h> |
35 |
#include <stdlib.h> |
36 |
|
37 |
#include "cpu.h" |
38 |
#include "device.h" |
39 |
#include "devices.h" |
40 |
#include "machine.h" |
41 |
#include "memory.h" |
42 |
#include "misc.h" |
43 |
|
44 |
#include "alpha_autoconf.h" |
45 |
#include "alpha_rpb.h" |
46 |
|
47 |
|
48 |
MACHINE_SETUP(alpha) |
49 |
{ |
50 |
struct rpb rpb; |
51 |
struct crb crb; |
52 |
struct ctb ctb; |
53 |
struct mddt mddt; |
54 |
struct pcs *pcs = malloc(sizeof(struct pcs) * machine->ncpus); |
55 |
int i; |
56 |
|
57 |
switch (machine->machine_subtype) { |
58 |
|
59 |
case ST_ALPHABOOK1: |
60 |
machine->machine_name = "AlphaBook 1"; |
61 |
if (machine->emulated_hz == 0) |
62 |
machine->emulated_hz = 233000000; |
63 |
device_add(machine, "lca"); |
64 |
break; |
65 |
|
66 |
case ST_DEC_4100: |
67 |
machine->machine_name = "AlphaServer 4100"; |
68 |
break; |
69 |
|
70 |
case ST_DEC_3000_300: |
71 |
machine->machine_name = "DEC 3000/300"; |
72 |
machine->main_console_handle = (size_t)device_add(machine, |
73 |
"z8530 addr=0x1b0200000 irq=0 addr_mult=4"); |
74 |
break; |
75 |
|
76 |
case ST_EB164: |
77 |
machine->machine_name = "EB164"; |
78 |
break; |
79 |
|
80 |
default:fatal("Unimplemented Alpha machine type %i\n", |
81 |
machine->machine_subtype); |
82 |
exit(1); |
83 |
} |
84 |
|
85 |
if (!machine->prom_emulation) |
86 |
return; |
87 |
|
88 |
/* These are used by NetBSD/alpha: */ |
89 |
/* a0 = First free Page Frame Number */ |
90 |
/* a1 = PFN of current Level 1 page table */ |
91 |
/* a2 = Bootinfo magic */ |
92 |
/* a3 = Bootinfo pointer */ |
93 |
/* a4 = Bootinfo version */ |
94 |
cpu->cd.alpha.r[ALPHA_A0] = 16*1024*1024 / 8192; |
95 |
cpu->cd.alpha.r[ALPHA_A1] = 0; /* TODO */ |
96 |
cpu->cd.alpha.r[ALPHA_A2] = 0; /* Note: NOT ALPHA_BOOTINFO_MAGIC */ |
97 |
cpu->cd.alpha.r[ALPHA_A3] = 0; /* TODO */ |
98 |
cpu->cd.alpha.r[ALPHA_A4] = 1; |
99 |
|
100 |
/* |
101 |
* HWRPB: Hardware Restart Parameter Block |
102 |
* |
103 |
* TODO: Almost everything. |
104 |
*/ |
105 |
memset(&rpb, 0, sizeof(struct rpb)); |
106 |
store_64bit_word_in_host(cpu, (unsigned char *) |
107 |
&(rpb.rpb_phys), 0x14000); |
108 |
strlcpy((char *)&(rpb.rpb_magic), "HWRPB", 8); |
109 |
store_64bit_word_in_host(cpu, (unsigned char *) |
110 |
&(rpb.rpb_size), sizeof(struct rpb)); |
111 |
store_64bit_word_in_host(cpu, (unsigned char *) |
112 |
&(rpb.rpb_page_size), 8192); |
113 |
strlcpy((char *)&(rpb.rpb_ssn), "123456789", 10); |
114 |
store_64bit_word_in_host(cpu, (unsigned char *) |
115 |
&(rpb.rpb_type), machine->machine_subtype); |
116 |
store_64bit_word_in_host(cpu, (unsigned char *) |
117 |
&(rpb.rpb_cc_freq), machine->emulated_hz); |
118 |
store_64bit_word_in_host(cpu, (unsigned char *) |
119 |
&(rpb.rpb_intr_freq), 1024 << 12); |
120 |
store_64bit_word_in_host(cpu, (unsigned char *) |
121 |
&(rpb.rpb_pcs_cnt), machine->ncpus); |
122 |
store_64bit_word_in_host(cpu, (unsigned char *) |
123 |
&(rpb.rpb_pcs_size), sizeof(struct pcs)); |
124 |
store_64bit_word_in_host(cpu, (unsigned char *) |
125 |
&(rpb.rpb_pcs_off), PCS_ADDR - HWRPB_ADDR); |
126 |
store_64bit_word_in_host(cpu, (unsigned char *) |
127 |
&(rpb.rpb_ctb_off), CTB_ADDR - HWRPB_ADDR); |
128 |
store_64bit_word_in_host(cpu, (unsigned char *) |
129 |
&(rpb.rpb_crb_off), CRB_ADDR - HWRPB_ADDR); |
130 |
store_64bit_word_in_host(cpu, (unsigned char *) |
131 |
&(rpb.rpb_memdat_off), MEMDAT_ADDR - HWRPB_ADDR); |
132 |
|
133 |
/* CTB: Console Terminal Block */ |
134 |
memset(&ctb, 0, sizeof(struct ctb)); |
135 |
store_64bit_word_in_host(cpu, (unsigned char *) |
136 |
&(ctb.ctb_term_type), machine->x11_md.in_use? |
137 |
CTB_GRAPHICS : CTB_PRINTERPORT); |
138 |
|
139 |
/* CRB: Console Routine Block */ |
140 |
memset(&crb, 0, sizeof(struct crb)); |
141 |
store_64bit_word_in_host(cpu, (unsigned char *) |
142 |
&(crb.crb_v_dispatch), CRB_ADDR - 0x100); |
143 |
store_64bit_word(cpu, CRB_ADDR - 0x100 + 8, PROM_ENTRY_PADDR); |
144 |
store_64bit_word_in_host(cpu, (unsigned char *) |
145 |
&(crb.crb_v_fixup), CRB_ADDR - 0x80); |
146 |
store_64bit_word(cpu, CRB_ADDR - 0x80 + 8, PROM_ENTRY_PADDR + 0x800); |
147 |
|
148 |
/* PCS: Processor ID etc. */ |
149 |
for (i=0; i<machine->ncpus; i++) { |
150 |
memset(&pcs[i], 0, sizeof(struct pcs)); |
151 |
store_64bit_word_in_host(cpu, (unsigned char *) |
152 |
&(pcs[i].pcs_flags), PCS_RC | PCS_PA | PCS_PP | |
153 |
PCS_CV | PCS_PV | PCS_PMV | PCS_PL); |
154 |
store_64bit_word_in_host(cpu, (unsigned char *) |
155 |
&(pcs[i].pcs_proc_type), |
156 |
machine->cpus[i]->cd.alpha.cpu_type.pcs_type); |
157 |
} |
158 |
|
159 |
/* |
160 |
* MDDT: Memory Data Descriptor Table. For now, it is a simple |
161 |
* two-entry table with half of the available RAM in each entry. |
162 |
* (The values are in number of 8K pages.) |
163 |
* The first 16 MB are not included (the kernel lives there). |
164 |
* The last 1 MB is not included either, it is reserved for bootup |
165 |
* and similar. |
166 |
*/ |
167 |
memset(&mddt, 0, sizeof(struct mddt)); |
168 |
memset(&mddt.mddt_clusters[0], 0, sizeof(struct mddt_cluster)); |
169 |
memset(&mddt.mddt_clusters[1], 0, sizeof(struct mddt_cluster)); |
170 |
store_64bit_word_in_host(cpu, (unsigned char *) |
171 |
&(mddt.mddt_cluster_cnt), 2); |
172 |
store_64bit_word_in_host(cpu, (unsigned char *) |
173 |
&(mddt.mddt_clusters[0].mddt_pfn), 16 * 128); |
174 |
store_64bit_word_in_host(cpu, (unsigned char *) |
175 |
&(mddt.mddt_clusters[0].mddt_pg_cnt), |
176 |
(machine->physical_ram_in_mb/2 - 16) * 128); |
177 |
store_64bit_word_in_host(cpu, (unsigned char *) |
178 |
&(mddt.mddt_clusters[1].mddt_pfn), |
179 |
machine->physical_ram_in_mb/2 * 128); |
180 |
store_64bit_word_in_host(cpu, (unsigned char *) |
181 |
&(mddt.mddt_clusters[1].mddt_pg_cnt), |
182 |
(machine->physical_ram_in_mb/2) * 128); |
183 |
|
184 |
/* |
185 |
* Place a special "hack" palcode call at PROM_ENTRY_PADDR and |
186 |
* PROM_ENTRY_PADDR + 0x800: |
187 |
* (Hopefully nothing else will be there.) |
188 |
*/ |
189 |
store_32bit_word(cpu, PROM_ENTRY_PADDR, 0x3fffffe); |
190 |
store_32bit_word(cpu, PROM_ENTRY_PADDR + 0x800, 0x3fffffd); |
191 |
|
192 |
store_buf(cpu, HWRPB_ADDR, (char *)&rpb, sizeof(struct rpb)); |
193 |
store_buf(cpu, CTB_ADDR, (char *)&ctb, sizeof(struct ctb)); |
194 |
store_buf(cpu, CRB_ADDR, (char *)&crb, sizeof(struct crb)); |
195 |
store_buf(cpu, MEMDAT_ADDR, (char *)&mddt, sizeof(struct mddt)); |
196 |
store_buf(cpu, PCS_ADDR, (char *)pcs, sizeof(struct pcs) * |
197 |
machine->ncpus); |
198 |
|
199 |
free(pcs); |
200 |
} |
201 |
|
202 |
|
203 |
MACHINE_DEFAULT_CPU(alpha) |
204 |
{ |
205 |
switch (machine->machine_subtype) { |
206 |
|
207 |
case ST_ALPHABOOK1: |
208 |
machine->cpu_name = strdup("21066"); |
209 |
break; |
210 |
|
211 |
case ST_DEC_4100: |
212 |
machine->cpu_name = strdup("21164A-2"); |
213 |
break; |
214 |
|
215 |
case ST_DEC_3000_300: |
216 |
machine->cpu_name = strdup("21064"); |
217 |
break; |
218 |
|
219 |
case ST_EB164: |
220 |
machine->cpu_name = strdup("21164PC"); |
221 |
break; |
222 |
|
223 |
default:fatal("Unimplemented Alpha machine type %i\n", |
224 |
machine->machine_subtype); |
225 |
exit(1); |
226 |
} |
227 |
} |
228 |
|
229 |
|
230 |
MACHINE_DEFAULT_RAM(alpha) |
231 |
{ |
232 |
machine->physical_ram_in_mb = 128; |
233 |
} |
234 |
|
235 |
|
236 |
MACHINE_REGISTER(alpha) |
237 |
{ |
238 |
MR_DEFAULT(alpha, "Alpha", ARCH_ALPHA, MACHINE_ALPHA); |
239 |
|
240 |
machine_entry_add_alias(me, "alpha"); |
241 |
|
242 |
machine_entry_add_subtype(me, "AlphaBook 1", ST_ALPHABOOK1, |
243 |
"alphabook1", NULL); |
244 |
|
245 |
machine_entry_add_subtype(me, "AlphaServer 4100", ST_DEC_4100, |
246 |
"alphaserver4100", NULL); |
247 |
|
248 |
machine_entry_add_subtype(me, "DEC 3000/300", ST_DEC_3000_300, |
249 |
"3000/300", NULL); |
250 |
|
251 |
machine_entry_add_subtype(me, "EB164", ST_EB164, |
252 |
"eb164", NULL); |
253 |
|
254 |
me->set_default_ram = machine_default_ram_alpha; |
255 |
} |
256 |
|