machine_alpha.cc Source File

Back to the index.

machine_alpha.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2011 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  * COMMENT: DEC Alpha machines
29  */
30 
31 #include <stdio.h>
32 #include <string.h>
33 #include <stdlib.h>
34 
35 #include "cpu.h"
36 #include "device.h"
37 #include "devices.h"
38 #include "machine.h"
39 #include "memory.h"
40 #include "misc.h"
41 
43 #include "thirdparty/alpha_rpb.h"
44 
45 
47 {
48  struct rpb rpb;
49  struct crb crb;
50  struct ctb ctb;
51  struct mddt mddt;
52  struct pcs *pcs = (struct pcs *) malloc(sizeof(struct pcs) * machine->ncpus);
53  int i;
54 
55  switch (machine->machine_subtype) {
56 
57  case ST_ALPHABOOK1:
58  machine->machine_name = strdup("AlphaBook 1");
59  if (machine->emulated_hz == 0)
60  machine->emulated_hz = 233000000;
61  device_add(machine, "lca");
62  break;
63 
64  case ST_DEC_4100:
65  machine->machine_name = strdup("AlphaServer 4100");
66  break;
67 
68  case ST_DEC_3000_300:
69  machine->machine_name = strdup("DEC 3000/300");
71  "z8530 addr=0x1b0200000 irq=0 addr_mult=4");
72  break;
73 
74  case ST_EB164:
75  machine->machine_name = strdup("EB164");
76  break;
77 
78  default:fatal("Unimplemented Alpha machine type %i\n",
80  exit(1);
81  }
82 
83  if (!machine->prom_emulation)
84  return;
85 
86  /* These are used by NetBSD/alpha: */
87  /* a0 = First free Page Frame Number */
88  /* a1 = PFN of current Level 1 page table */
89  /* a2 = Bootinfo magic */
90  /* a3 = Bootinfo pointer */
91  /* a4 = Bootinfo version */
92  cpu->cd.alpha.r[ALPHA_A0] = 16*1024*1024 / 8192;
93  cpu->cd.alpha.r[ALPHA_A1] = 0; /* TODO */
94  cpu->cd.alpha.r[ALPHA_A2] = 0; /* Note: NOT ALPHA_BOOTINFO_MAGIC */
95  cpu->cd.alpha.r[ALPHA_A3] = 0; /* TODO */
96  cpu->cd.alpha.r[ALPHA_A4] = 1;
97 
98  /*
99  * HWRPB: Hardware Restart Parameter Block
100  *
101  * TODO: Almost everything.
102  */
103  memset(&rpb, 0, sizeof(struct rpb));
104  store_64bit_word_in_host(cpu, (unsigned char *)
105  &(rpb.rpb_phys), 0x14000);
106  strlcpy((char *)&(rpb.rpb_magic), "HWRPB", 8);
107  store_64bit_word_in_host(cpu, (unsigned char *)
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 *)
132 
133  /* CTB: Console Terminal Block */
134  memset(&ctb, 0, sizeof(struct ctb));
135  store_64bit_word_in_host(cpu, (unsigned char *)
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);
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),
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  */
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 
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",
225  exit(1);
226  }
227 }
228 
229 
231 {
233 }
234 
235 
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 
void fatal(const char *fmt,...)
Definition: main.cc:152
#define ALPHA_A1
Definition: cpu_alpha.h:94
int emulated_hz
Definition: machine.h:165
int prom_emulation
Definition: machine.h:149
char * cpu_name
Definition: machine.h:133
Definition: alpha_rpb.h:233
int main_console_handle
Definition: machine.h:128
int store_32bit_word(struct cpu *cpu, uint64_t addr, uint64_t data32)
Definition: memory.cc:783
#define PCS_RC
Definition: alpha_rpb.h:237
struct mddt_cluster mddt_clusters[2]
Definition: alpha_rpb.h:476
#define CTB_PRINTERPORT
Definition: alpha_rpb.h:365
union cpu::@1 cd
char rpb_ssn[16]
Definition: alpha_rpb.h:63
u_int64_t pcs_flags
Definition: alpha_rpb.h:253
char rpb_magic[8]
Definition: alpha_rpb.h:55
#define ST_DEC_3000_300
Definition: alpha_rpb.h:70
u_int64_t rpb_cc_freq
Definition: alpha_rpb.h:198
#define HWRPB_DSRDB_MINVERS
Definition: alpha_rpb.h:496
#define CRB_ADDR
Definition: alpha_rpb.h:48
Definition: alpha_rpb.h:354
#define PCS_PV
Definition: alpha_rpb.h:242
#define ALPHA_A0
Definition: cpu_alpha.h:93
#define ST_DEC_4100
Definition: alpha_rpb.h:83
u_int64_t rpb_pcs_size
Definition: alpha_rpb.h:203
#define ALPHA_A2
Definition: cpu_alpha.h:95
#define CTB_ADDR
Definition: alpha_rpb.h:47
void * device_add(struct machine *machine, const char *name_and_params)
Definition: device.cc:252
struct cpu ** cpus
Definition: machine.h:140
int physical_ram_in_mb
Definition: machine.h:147
int store_64bit_word(struct cpu *cpu, uint64_t addr, uint64_t data64)
Definition: memory.cc:752
#define ST_ALPHABOOK1
Definition: alpha_rpb.h:82
Definition: alpha_rpb.h:441
#define CTB_GRAPHICS
Definition: alpha_rpb.h:366
u_int64_t rpb_crb_off
Definition: alpha_rpb.h:208
int ncpus
Definition: machine.h:139
u_int64_t mddt_pfn
Definition: alpha_rpb.h:456
u_int64_t rpb_type
Definition: alpha_rpb.h:101
u_int64_t rpb_intr_freq
Definition: alpha_rpb.h:197
#define PROM_ENTRY_PADDR
Definition: alpha_rpb.h:44
#define PCS_PMV
Definition: alpha_rpb.h:243
#define HWRPB_ADDR
Definition: alpha_rpb.h:41
#define PCS_PL
Definition: alpha_rpb.h:244
#define ARCH_ALPHA
Definition: machine.h:205
void machine_entry_add_subtype(struct machine_entry *me, const char *name, int oldstyle_subtype,...)
Definition: machine.cc:717
u_int64_t rpb_version
Definition: alpha_rpb.h:56
u_int64_t crb_v_fixup
Definition: alpha_rpb.h:446
void store_64bit_word_in_host(struct cpu *cpu, unsigned char *data, uint64_t data32)
Definition: memory.cc:945
uint64_t pcs_type
Definition: cpu_alpha.h:42
void machine_entry_add_alias(struct machine_entry *me, const char *name)
Definition: machine.cc:697
u_int64_t rpb_ctb_off
Definition: alpha_rpb.h:207
MACHINE_DEFAULT_RAM(alpha)
#define ALPHA_A4
Definition: cpu_alpha.h:97
u_int64_t rpb_memdat_off
Definition: alpha_rpb.h:209
#define PCS_PP
Definition: alpha_rpb.h:239
struct alpha_cpu_type_def cpu_type
Definition: cpu_alpha.h:144
struct x11_md x11_md
Definition: machine.h:179
uint64_t r[N_ALPHA_REGS]
Definition: cpu_alpha.h:151
u_int64_t rpb_size
Definition: alpha_rpb.h:57
Definition: cpu.h:326
u_int64_t rpb_phys
Definition: alpha_rpb.h:54
u_int64_t mddt_pg_cnt
Definition: alpha_rpb.h:457
#define MEMDAT_ADDR
Definition: alpha_rpb.h:49
#define PCS_PA
Definition: alpha_rpb.h:238
#define MACHINE_ALPHA
Definition: machine.h:235
struct alpha_cpu alpha
Definition: cpu.h:440
int in_use
Definition: machine.h:82
u_int64_t ctb_term_type
Definition: alpha_rpb.h:369
Definition: alpha_rpb.h:53
u_int64_t pcs_proc_type
Definition: alpha_rpb.h:283
u_int64_t rpb_pcs_off
Definition: alpha_rpb.h:204
void store_buf(struct cpu *cpu, uint64_t addr, const char *s, size_t len)
Definition: memory.cc:826
int machine_subtype
Definition: machine.h:112
MACHINE_DEFAULT_CPU(alpha)
MACHINE_SETUP(alpha)
u_int64_t mddt_cluster_cnt
Definition: alpha_rpb.h:475
#define MR_DEFAULT(x, name, arch, type)
Definition: machine.h:370
#define PCS_ADDR
Definition: alpha_rpb.h:50
#define ST_EB164
Definition: alpha_rpb.h:86
u_int64_t rpb_pcs_cnt
Definition: alpha_rpb.h:202
const char * machine_name
Definition: machine.h:115
#define PCS_CV
Definition: alpha_rpb.h:241
#define ALPHA_A3
Definition: cpu_alpha.h:96
u_int64_t rpb_page_size
Definition: alpha_rpb.h:59
u_int64_t crb_v_dispatch
Definition: alpha_rpb.h:443
MACHINE_REGISTER(alpha)

Generated on Sun Sep 30 2018 16:05:18 for GXemul by doxygen 1.8.13