dev_pmppc.cc Source File

Back to the index.

dev_pmppc.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2009 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: Artesyn PM/PPC motherboard registers
29  *
30  * NOTE/TODO: Only enough to boot NetBSD/pmppc has been implemented.
31  */
32 
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <string.h>
36 
37 #include "cpu.h"
38 #include "device.h"
39 #include "machine.h"
40 #include "memory.h"
41 #include "misc.h"
42 
43 #include "thirdparty/pmppc.h"
44 
45 
46 struct pmppc_data {
47  uint8_t config0;
48  uint8_t config1;
49 
50  uint8_t reset_reg;
51 };
52 
53 
54 DEVICE_ACCESS(pmppc_board)
55 {
56  struct pmppc_data *d = (struct pmppc_data *) extra;
57  uint64_t idata = 0, odata = 0;
58 
59  if (writeflag == MEM_WRITE)
60  idata = memory_readmax64(cpu, data, len);
61 
62  relative_addr += PMPPC_CONFIG0;
63 
64  switch (relative_addr) {
65 
66  case PMPPC_CONFIG0:
67  if (writeflag==MEM_READ) {
68  odata = d->config0;
69  } else {
70  debug("[ pmppc: UNIMPLEMENTED write to PMPPC_CONFIG0:"
71  " 0x%02x ]\n", (int)idata);
72  }
73  break;
74 
75  case PMPPC_CONFIG1:
76  if (writeflag==MEM_READ) {
77  odata = d->config1;
78  } else {
79  debug("[ pmppc: UNIMPLEMENTED write to PMPPC_CONFIG1:"
80  " 0x%02x ]\n", (int)idata);
81  }
82  break;
83 
84  case PMPPC_RESET:
85  if (writeflag==MEM_READ) {
86  odata = d->reset_reg;
87  } else {
88  if (d->reset_reg == PMPPC_RESET_SEQ_STEP1 &&
89  idata == PMPPC_RESET_SEQ_STEP2) {
90  cpu->running = 0;
91  cpu->machine->
92  exit_without_entering_debugger = 1;
93  }
94  d->reset_reg = idata;
95  }
96  break;
97 
98  default:
99  if (writeflag==MEM_READ) {
100  debug("[ pmppc: UNIMPLEMENTED read from 0x%08lx ]\n",
101  (long)relative_addr);
102  } else {
103  debug("[ pmppc: UNIMPLEMENTED write to 0x%08lx:"
104  " 0x%02x ]\n", (long)relative_addr, (int)idata);
105  }
106  }
107 
108  if (writeflag == MEM_READ)
109  memory_writemax64(cpu, data, len, odata);
110 
111  return 1;
112 }
113 
114 
115 DEVINIT(pmppc)
116 {
117  struct pmppc_data *d;
118  struct memory *mem = devinit->machine->memory;
119 
120  CHECK_ALLOCATION(d = (struct pmppc_data *) malloc(sizeof(struct pmppc_data)));
121  memset(d, 0, sizeof(struct pmppc_data));
122 
123  /*
124  * Based on how NetBSD/pmppc's pmppc_setup() works:
125  *
126  * config0:
127  * bit 7 Is monarch (?).
128  * bit 5 Has ethernet.
129  * bit 4 1 = No RTC.
130  * bits 3..2 Flash size (00 = 256 MB, 01 = 128 MB,
131  * 10 = 64 MB, 11 = 32 MB).
132  * bits 1..0 Flash width (00 = 64, 01 = 32, 10 = 16, 11 = 0).
133  *
134  * config1:
135  * bit 7 Boot device is FLASH (1) or ROM (0).
136  * bit 6 Has ECC.
137  * bits 5..4 Memory size: 00 = 32 MB, 01 = 64 MB,
138  * 10 = 128 MB, 11 = 256 MB.
139  * bits 3..2 L2 cache.
140  * bits 1..0 Bus frequency: 00 = 66.66 MHz, 01 = 83.33 MHz,
141  * 10 = 100.00 MHz, 11 = reserved?
142  */
143  d->config0 = 0x20;
144  d->config1 = 0;
145 
146  if (mem->physical_max == 32*1048576) {
147  } else if (mem->physical_max == 64*1048576) {
148  d->config1 |= 0x01;
149  } else if (mem->physical_max == 128*1048576) {
150  d->config1 |= 0x10;
151  } else if (mem->physical_max == 256*1048576) {
152  d->config1 |= 0x11;
153  } else {
154  fatal("A PM/PPC can have 32, 64, 128, or 256 MB RAM.\n");
155  exit(1);
156  }
157 
158  memory_device_register(mem, "pmppc_board",
159  PMPPC_CONFIG0, 0x10, dev_pmppc_board_access, d, DM_DEFAULT, NULL);
160 
161  return 1;
162 }
163 
uint64_t memory_readmax64(struct cpu *cpu, unsigned char *buf, int len)
Definition: memory.cc:55
void fatal(const char *fmt,...)
Definition: main.cc:152
#define DM_DEFAULT
Definition: memory.h:130
struct machine * machine
Definition: cpu.h:328
#define MEM_READ
Definition: memory.h:116
struct memory * memory
Definition: machine.h:126
#define PMPPC_RESET_SEQ_STEP1
Definition: pmppc.h:65
#define PMPPC_RESET_SEQ_STEP2
Definition: pmppc.h:66
#define CHECK_ALLOCATION(ptr)
Definition: misc.h:239
#define PMPPC_CONFIG0
Definition: pmppc.h:61
u_short data
Definition: siireg.h:79
DEVICE_ACCESS(pmppc_board)
Definition: dev_pmppc.cc:54
uint8_t config1
Definition: dev_pmppc.cc:48
uint8_t running
Definition: cpu.h:353
#define MEM_WRITE
Definition: memory.h:117
DEVINIT(pmppc)
Definition: dev_pmppc.cc:115
Definition: device.h:40
#define debug
Definition: dev_adb.cc:57
Definition: cpu.h:326
struct machine * machine
Definition: device.h:41
void memory_writemax64(struct cpu *cpu, unsigned char *buf, int len, uint64_t data)
Definition: memory.cc:89
void memory_device_register(struct memory *mem, const char *, uint64_t baseaddr, uint64_t len, int(*f)(struct cpu *, struct memory *, uint64_t, unsigned char *, size_t, int, void *), void *extra, int flags, unsigned char *dyntrans_data)
Definition: memory.cc:339
uint8_t reset_reg
Definition: dev_pmppc.cc:50
#define PMPPC_CONFIG1
Definition: pmppc.h:62
uint64_t physical_max
Definition: memory.h:76
Definition: memory.h:75
#define PMPPC_RESET
Definition: pmppc.h:64
uint8_t config0
Definition: dev_pmppc.cc:47

Generated on Fri Dec 7 2018 19:52:23 for GXemul by doxygen 1.8.13