sh_ipl_g.cc Source File
Back to the index.
src
promemul
sh_ipl_g.cc
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2007-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: SH-IPL+G emulation
29
*
30
* Very basic, only what is needed to get OpenBSD/landisk booting.
31
* (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
45
#include "
thirdparty/sh4_exception.h
"
46
47
48
/*
49
* sh_ipl_g_emul_init():
50
*/
51
void
sh_ipl_g_emul_init
(
struct
machine
*
machine
)
52
{
53
struct
cpu
*
cpu
=
machine
->
cpus
[0];
54
55
cpu
->
cd
.
sh
.
vbr
= 0x8c000000;
56
store_16bit_word
(
cpu
, 0x8c000100,
SH_INVALID_INSTR
);
57
store_16bit_word
(
cpu
, 0x8c000102, 0x002b);
/* rte */
58
store_16bit_word
(
cpu
, 0x8c000104, 0x0009);
/* nop */
59
}
60
61
62
/*
63
* sh_ipl_g_promcall():
64
*
65
* SH-IPL+G PROM call emulation.
66
*/
67
static
int
sh_ipl_g_promcall(
struct
cpu
*
cpu
)
68
{
69
/*
70
* SH-IPL+G call numbers are in R0:
71
*
72
* NOTE: r_bank[0], since this is in a trap handler!
73
*/
74
switch
(
cpu
->
cd
.
sh
.
r_bank
[0]) {
75
76
case
4:
/* Get memory size. */
77
cpu
->
cd
.
sh
.
r_bank
[0] = 64 * 1048576;
78
/* Note: cpu->machine->physical_ram_in_mb * 1048576
79
would be more correct, but physical_ram_in_mb is
80
set to 2 for landisk emulation... */
81
break
;
82
83
default
:
cpu_register_dump
(
cpu
->
machine
,
cpu
, 1, 0);
84
printf(
"\n"
);
85
fatal
(
"[ SH-IPL+G PROM emulation: unimplemented function 0x%"
86
PRIx32
" ]\n"
,
cpu
->
cd
.
sh
.
r_bank
[0]);
87
cpu
->
running
= 0;
88
return
0;
89
}
90
91
return
1;
92
}
93
94
95
/*
96
* sh_ipl_g_emul():
97
*/
98
int
sh_ipl_g_emul
(
struct
cpu
*
cpu
)
99
{
100
/* SH-IPL+G calls are "trapa #63": */
101
if
(
cpu
->
cd
.
sh
.
expevt
==
EXPEVT_TRAPA
&&
102
cpu
->
cd
.
sh
.
tra
== 0xfc) {
103
return
sh_ipl_g_promcall(
cpu
);
104
}
else
{
105
cpu_register_dump
(
cpu
->
machine
,
cpu
, 1, 0);
106
printf(
"\n"
);
107
fatal
(
"[ SH-IPL+G PROM emulation: expevt=0x%x, "
108
" tra=0x%x ]\n"
, (
int
)
cpu
->
cd
.
sh
.
expevt
,
109
(
int
)
cpu
->
cd
.
sh
.
tra
);
110
cpu
->
running
= 0;
111
return
0;
112
}
113
}
114
cpu_register_dump
void cpu_register_dump(struct machine *m, struct cpu *cpu, int gprs, int coprocs)
Definition:
cpu.cc:203
cpu_sh.h
cpu::running
uint8_t running
Definition:
cpu.h:353
machine::cpus
struct cpu ** cpus
Definition:
machine.h:140
sh_cpu::r_bank
uint32_t r_bank[SH_N_GPRS_BANKED]
Definition:
cpu_sh.h:101
sh_cpu::vbr
uint32_t vbr
Definition:
cpu_sh.h:116
sh_ipl_g_emul_init
void sh_ipl_g_emul_init(struct machine *machine)
Definition:
sh_ipl_g.cc:51
fatal
void fatal(const char *fmt,...)
Definition:
main.cc:152
misc.h
cpu::cd
union cpu::@1 cd
machine.h
sh_cpu::tra
uint32_t tra
Definition:
cpu_sh.h:138
machine
Definition:
machine.h:97
cpu::sh
struct sh_cpu sh
Definition:
cpu.h:445
cpu.h
sh4_exception.h
cpu::machine
struct machine * machine
Definition:
cpu.h:328
sh_ipl_g_emul
int sh_ipl_g_emul(struct cpu *cpu)
Definition:
sh_ipl_g.cc:98
sh_cpu::expevt
uint32_t expevt
Definition:
cpu_sh.h:139
SH_INVALID_INSTR
#define SH_INVALID_INSTR
Definition:
cpu_sh.h:93
store_16bit_word
int store_16bit_word(struct cpu *cpu, uint64_t addr, uint64_t data16)
Definition:
memory.cc:807
cpu
Definition:
cpu.h:326
EXPEVT_TRAPA
#define EXPEVT_TRAPA
Definition:
sh4_exception.h:70
memory.h
Generated on Tue Mar 24 2020 14:04:48 for GXemul by
1.8.17