|
|
1.1 root 1: /* $Id: sun2-control.c,v 1.3 2003/05/03 19:26:38 fredette Exp $ */
2:
3: /* machine/sun2/sun2-control.c - implementation of Sun 2 emulation control space: */
4:
5: /*
6: * Copyright (c) 2003 Matt Fredette
7: * All rights reserved.
8: *
9: * Redistribution and use in source and binary forms, with or without
10: * modification, are permitted provided that the following conditions
11: * are met:
12: * 1. Redistributions of source code must retain the above copyright
13: * notice, this list of conditions and the following disclaimer.
14: * 2. Redistributions in binary form must reproduce the above copyright
15: * notice, this list of conditions and the following disclaimer in the
16: * documentation and/or other materials provided with the distribution.
17: * 3. All advertising materials mentioning features or use of this software
18: * must display the following acknowledgement:
19: * This product includes software developed by Matt Fredette.
20: * 4. The name of the author may not be used to endorse or promote products
21: * derived from this software without specific prior written permission.
22: *
23: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26: * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
27: * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29: * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
31: * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32: * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33: * POSSIBILITY OF SUCH DAMAGE.
34: */
35:
36: #include <tme/common.h>
37: _TME_RCSID("$Id: sun2-control.c,v 1.3 2003/05/03 19:26:38 fredette Exp $");
38:
39: /* includes: */
40: #include "sun2-impl.h"
41:
42: /* macros: */
43:
44: /* the bus cycle handler for function code three space: */
45: int
46: _tme_sun2_control_cycle_handler(void *_sun2, struct tme_bus_cycle *cycle_init)
47: {
48: struct tme_sun2 *sun2;
49: struct tme_bus_cycle cycle_resp;
50: tme_bus_addr_t reg, address, index;
51: tme_uint32_t pte;
52: int rc;
53:
54: /* recover our sun2: */
55: sun2 = (struct tme_sun2 *) _sun2;
56:
57: /* get the register and address and index: */
58: reg = cycle_init->tme_bus_cycle_address & (TME_SUN2_PAGE_SIZE - 1);
59: reg = TME_MIN(reg, TME_SUN2_CONTROL_JUNK);
60: address = cycle_init->tme_bus_cycle_address & ~(TME_SUN2_PAGE_SIZE - 1);
61: index = address >> TME_SUN2_PAGE_SIZE_LOG2;
62:
63: /* this macro evaluates to TRUE whenever a register is maybe being
64: accessed: */
65: #define _TME_SUN2_REG_ACCESSED(icreg) \
66: TME_RANGES_OVERLAP(reg, \
67: reg \
68: + cycle_init->tme_bus_cycle_size - 1, \
69: TME_SUN2_CONTROL_ADDRESS(icreg), \
70: TME_SUN2_CONTROL_ADDRESS(icreg) \
71: + sizeof(sun2->icreg) - 1)
72:
73: /* whenever the page map register is accessed, we need to fill it
74: before running the cycle: */
75: if (_TME_SUN2_REG_ACCESSED(tme_sun2_pgmap_hi)
76: || _TME_SUN2_REG_ACCESSED(tme_sun2_pgmap_lo)) {
77:
78: /* get the PTE from the MMU: */
79: rc = _tme_sun2_mmu_pte_get(sun2, address, &pte);
80: assert(rc == TME_OK);
81: sun2->tme_sun2_pgmap_hi = (pte >> 16);
82: sun2->tme_sun2_pgmap_lo = (pte & 0xffff);
83: }
84:
85: /* whenever the segment map register is accessed, we need to fill it
86: before running the cycle: */
87: if (_TME_SUN2_REG_ACCESSED(tme_sun2_segmap)
88: && cycle_init->tme_bus_cycle_type == TME_BUS_CYCLE_READ) {
89: sun2->tme_sun2_segmap = tme_sun_mmu_segmap_get(sun2->tme_sun2_mmu, sun2->tme_sun2_context_user, address);
90: }
91:
92: /* whenever the IDPROM register is accessed, we need to fill it
93: before running the cycle: */
94: if (_TME_SUN2_REG_ACCESSED(tme_sun2_idprom)
95: && index < sizeof(sun2->tme_sun2_idprom_contents)) {
96: sun2->tme_sun2_idprom = sun2->tme_sun2_idprom_contents[index];
97: }
98:
99: /* run the cycle: */
100: TME_SUN2_CONTROL_BUS_CYCLE(sun2, reg, &cycle_resp);
101: cycle_resp.tme_bus_cycle_type = (cycle_init->tme_bus_cycle_type
102: ^ (TME_BUS_CYCLE_WRITE
103: | TME_BUS_CYCLE_READ));
104: cycle_resp.tme_bus_cycle_lane_routing = cycle_init->tme_bus_cycle_lane_routing;
105: tme_bus_cycle_xfer(cycle_init, &cycle_resp);
106:
107: /* whenever the bus error register is read or written, it is
108: cleared: */
109: if (_TME_SUN2_REG_ACCESSED(tme_sun2_buserr)) {
110: sun2->tme_sun2_buserr = 0;
111: }
112:
113: /* these registers only need action taken when they're written: */
114: if (cycle_init->tme_bus_cycle_type == TME_BUS_CYCLE_WRITE) {
115:
116: /* the page map has been written: */
117: if (_TME_SUN2_REG_ACCESSED(tme_sun2_pgmap_hi)
118: || _TME_SUN2_REG_ACCESSED(tme_sun2_pgmap_lo)) {
119: pte = sun2->tme_sun2_pgmap_hi;
120: pte = (pte << 16) | sun2->tme_sun2_pgmap_lo;
121: rc = _tme_sun2_mmu_pte_set(sun2, address, pte);
122: assert(rc == TME_OK);
123: }
124:
125: /* the segment map has been written: */
126: if (_TME_SUN2_REG_ACCESSED(tme_sun2_segmap)) {
127: tme_sun_mmu_segmap_set(sun2->tme_sun2_mmu, sun2->tme_sun2_context_user, address, sun2->tme_sun2_segmap);
128: }
129:
130: /* the system context register has been written: */
131: if (_TME_SUN2_REG_ACCESSED(tme_sun2_context_system)) {
132: _tme_sun2_mmu_context_system_set(sun2);
133: }
134:
135: /* the system context register has been written: */
136: if (_TME_SUN2_REG_ACCESSED(tme_sun2_context_user)) {
137: _tme_sun2_mmu_context_user_set(sun2);
138: }
139:
140: /* the diag register has been written: */
141: if (_TME_SUN2_REG_ACCESSED(tme_sun2_diag)) {
142: /* TBD */
143: }
144:
145: /* the system enable register has been written: */
146: if (_TME_SUN2_REG_ACCESSED(tme_sun2_enable)) {
147: rc = _tme_sun2_ipl_check(sun2);
148: assert(rc == TME_OK);
149: }
150: }
151:
152: return (TME_OK);
153: }
154:
155: #if 1
156: #include <stdio.h>
157:
158: /* this dumps out the sun2 state: */
159: void
160: tme_sun2_dump(struct tme_sun2 *sun2)
161: {
162:
163: /* dump out the page map register: */
164: fprintf(stderr, "PGMAP = 0x%04x%04x\n",
165: sun2->tme_sun2_pgmap_hi,
166: sun2->tme_sun2_pgmap_lo);
167: fprintf(stderr, "SEGMAP = 0x%02x\n", sun2->tme_sun2_segmap);
168: fprintf(stderr, "\n");
169: fprintf(stderr, "SCONTEXT = 0x%02x\n", sun2->tme_sun2_context_system);
170: fprintf(stderr, " CONTEXT = 0x%02x\n", sun2->tme_sun2_context_user);
171: fprintf(stderr, "\n");
172: fprintf(stderr, "IDPROM = 0x%02x\n", sun2->tme_sun2_idprom);
173: fprintf(stderr, "DIAG = 0x%02x\n", sun2->tme_sun2_diag);
174: fprintf(stderr, "BUSERR = 0x%04x\n", sun2->tme_sun2_buserr);
175: fprintf(stderr, "ENABLE = 0x%04x\n", sun2->tme_sun2_enable);
176: }
177: #endif /* 1 */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.