1 |
/* |
2 |
* Copyright (C) 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: mvmeprom.c,v 1.4 2007/06/17 23:32:20 debug Exp $ |
29 |
* |
30 |
* COMMENT: MVME PROM emulation |
31 |
* |
32 |
* For mvme88k emulation. |
33 |
* |
34 |
* TODO: Perhaps this could be reused for mvme68k emulation too? |
35 |
*/ |
36 |
|
37 |
#include <stdio.h> |
38 |
#include <stdlib.h> |
39 |
#include <string.h> |
40 |
#include <sys/types.h> |
41 |
|
42 |
#include "console.h" |
43 |
#include "cpu.h" |
44 |
#include "machine.h" |
45 |
#include "memory.h" |
46 |
#include "misc.h" |
47 |
|
48 |
#include "mvmeprom.h" |
49 |
|
50 |
|
51 |
#define MVMEPROM_BRDID_ADDR 0x1100 |
52 |
|
53 |
|
54 |
/* |
55 |
* mvmeprom_init(): |
56 |
*/ |
57 |
void mvmeprom_init(struct machine *machine) |
58 |
{ |
59 |
struct cpu *cpu = machine->cpus[0]; |
60 |
struct mvmeprom_brdid mvmeprom_brdid; |
61 |
uint32_t vbr = 0x00000000; |
62 |
int model = 0x187; |
63 |
|
64 |
switch (machine->machine_subtype) { |
65 |
case MACHINE_MVME88K_187: model = 0x187; break; |
66 |
case MACHINE_MVME88K_188: model = 0x188; break; |
67 |
case MACHINE_MVME88K_197: model = 0x197; break; |
68 |
} |
69 |
|
70 |
cpu->cd.m88k.cr[M88K_CR_VBR] = vbr; |
71 |
|
72 |
/* A magic prom call instruction, followed by an 'rte': */ |
73 |
store_32bit_word(cpu, vbr + 8 * MVMEPROM_VECTOR, M88K_PROM_INSTR); |
74 |
store_32bit_word(cpu, vbr + 8 * MVMEPROM_VECTOR + 4, 0xf400fc00); |
75 |
|
76 |
/* brdid struct: */ |
77 |
memset(&mvmeprom_brdid, 0, sizeof(mvmeprom_brdid)); |
78 |
store_16bit_word_in_host(cpu, (unsigned char *) |
79 |
&(mvmeprom_brdid.model), model); |
80 |
mvmeprom_brdid.speed[0] = '3'; /* 33 MHz, for now */ |
81 |
mvmeprom_brdid.speed[1] = '3'; |
82 |
mvmeprom_brdid.speed[2] = '0'; |
83 |
mvmeprom_brdid.speed[3] = '0'; |
84 |
store_buf(cpu, MVMEPROM_BRDID_ADDR, |
85 |
(char *)&mvmeprom_brdid, sizeof(struct mvmeprom_brdid)); |
86 |
} |
87 |
|
88 |
|
89 |
/* |
90 |
* mvmeprom_emul(): |
91 |
* |
92 |
* For MVME88K: |
93 |
* |
94 |
* Input: |
95 |
* r9 = requested function number |
96 |
* r2 = first argument (for functions that take arguments) |
97 |
* |
98 |
* Output: |
99 |
* r2 = result |
100 |
*/ |
101 |
int mvmeprom_emul(struct cpu *cpu) |
102 |
{ |
103 |
int func = cpu->cd.m88k.r[9]; |
104 |
|
105 |
switch (func) { |
106 |
|
107 |
case MVMEPROM_OUTCHR: |
108 |
console_putchar(cpu->machine->main_console_handle, |
109 |
cpu->cd.m88k.r[2]); |
110 |
break; |
111 |
|
112 |
case MVMEPROM_OUTCRLF: |
113 |
console_putchar(cpu->machine->main_console_handle, '\n'); |
114 |
break; |
115 |
|
116 |
case MVMEPROM_EXIT: |
117 |
fatal("[ MVME PROM: exit ]\n"); |
118 |
cpu->running = 0; |
119 |
break; |
120 |
|
121 |
case MVMEPROM_GETBRDID: |
122 |
/* Return a pointer in r2 to a mvmeprom_brdid struct. */ |
123 |
cpu->cd.m88k.r[2] = MVMEPROM_BRDID_ADDR; |
124 |
break; |
125 |
|
126 |
default: |
127 |
cpu_register_dump(cpu->machine, cpu, 1, 0); |
128 |
cpu_register_dump(cpu->machine, cpu, 0, 1); |
129 |
fatal("[ MVME PROM emulation: unimplemented function 0x%" |
130 |
PRIx32" ]\n", func); |
131 |
cpu->running = 0; |
132 |
return 0; |
133 |
} |
134 |
|
135 |
return 1; |
136 |
} |
137 |
|