1 |
dpavlin |
36 |
/* |
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: sh_ipl_g.c,v 1.2 2007/03/16 18:47:26 debug Exp $ |
29 |
|
|
* |
30 |
|
|
* SH-IPL+G emulation; very basic, only what is needed to get OpenBSD/landisk |
31 |
|
|
* booting. (SH-IPL+G stands for SuperH Initial Program Loader + GDB stub.) |
32 |
|
|
*/ |
33 |
|
|
|
34 |
|
|
#include <stdio.h> |
35 |
|
|
#include <stdlib.h> |
36 |
|
|
#include <string.h> |
37 |
|
|
#include <sys/types.h> |
38 |
|
|
|
39 |
|
|
#include "cpu.h" |
40 |
|
|
#include "cpu_sh.h" |
41 |
|
|
#include "machine.h" |
42 |
|
|
#include "memory.h" |
43 |
|
|
#include "misc.h" |
44 |
|
|
#include "net.h" |
45 |
|
|
|
46 |
|
|
|
47 |
|
|
#ifdef ENABLE_SH |
48 |
|
|
|
49 |
|
|
#include "sh4_exception.h" |
50 |
|
|
|
51 |
|
|
|
52 |
|
|
/* |
53 |
|
|
* sh_ipl_g_emul_init(): |
54 |
|
|
*/ |
55 |
|
|
void sh_ipl_g_emul_init(struct machine *machine) |
56 |
|
|
{ |
57 |
|
|
struct cpu *cpu = machine->cpus[0]; |
58 |
|
|
|
59 |
|
|
cpu->cd.sh.vbr = 0x8c000000; |
60 |
|
|
store_16bit_word(cpu, 0x8c000100, SH_INVALID_INSTR); |
61 |
|
|
store_16bit_word(cpu, 0x8c000102, 0x002b); /* rte */ |
62 |
|
|
store_16bit_word(cpu, 0x8c000104, 0x0009); /* nop */ |
63 |
|
|
} |
64 |
|
|
|
65 |
|
|
|
66 |
|
|
/* |
67 |
|
|
* sh_ipl_g_promcall(): |
68 |
|
|
* |
69 |
|
|
* SH-IPL+G PROM call emulation. |
70 |
|
|
*/ |
71 |
|
|
static int sh_ipl_g_promcall(struct cpu *cpu) |
72 |
|
|
{ |
73 |
|
|
/* |
74 |
|
|
* SH-IPL+G call numbers are in R0: |
75 |
|
|
* |
76 |
|
|
* NOTE: r_bank[0], since this is in a trap handler! |
77 |
|
|
*/ |
78 |
|
|
switch (cpu->cd.sh.r_bank[0]) { |
79 |
|
|
|
80 |
|
|
case 4: /* Get memory size. */ |
81 |
|
|
cpu->cd.sh.r_bank[0] = 64 * 1048576; |
82 |
|
|
/* Note: cpu->machine->physical_ram_in_mb * 1048576 |
83 |
|
|
would be more correct, but physical_ram_in_mb is |
84 |
|
|
set to 2 for landisk emulation... */ |
85 |
|
|
break; |
86 |
|
|
|
87 |
|
|
default:cpu_register_dump(cpu->machine, cpu, 1, 0); |
88 |
|
|
printf("\n"); |
89 |
|
|
fatal("[ SH-IPL+G PROM emulation: unimplemented function 0x%" |
90 |
|
|
PRIx32" ]\n", cpu->cd.sh.r_bank[0]); |
91 |
|
|
cpu->running = 0; |
92 |
|
|
return 0; |
93 |
|
|
} |
94 |
|
|
|
95 |
|
|
return 1; |
96 |
|
|
} |
97 |
|
|
|
98 |
|
|
|
99 |
|
|
/* |
100 |
|
|
* sh_ipl_g_emul(): |
101 |
|
|
*/ |
102 |
|
|
int sh_ipl_g_emul(struct cpu *cpu) |
103 |
|
|
{ |
104 |
|
|
/* SH-IPL+G calls are "trapa #63": */ |
105 |
|
|
if (cpu->cd.sh.expevt == EXPEVT_TRAPA && |
106 |
|
|
cpu->cd.sh.tra == 0xfc) { |
107 |
|
|
return sh_ipl_g_promcall(cpu); |
108 |
|
|
} else { |
109 |
|
|
cpu_register_dump(cpu->machine, cpu, 1, 0); |
110 |
|
|
printf("\n"); |
111 |
|
|
fatal("[ SH-IPL+G PROM emulation: expevt=0x%x, " |
112 |
|
|
" tra=0x%x ]\n", (int)cpu->cd.sh.expevt, |
113 |
|
|
(int)cpu->cd.sh.tra); |
114 |
|
|
cpu->running = 0; |
115 |
|
|
return 0; |
116 |
|
|
} |
117 |
|
|
} |
118 |
|
|
|
119 |
|
|
#endif /* ENABLE_SH */ |
120 |
|
|
|