1 /* This file is part of the program psim.
3 Copyright (C) 1994-1995, Andrew Cagney <cagney@highland.com.au>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #ifndef _EMUL_BUGAPI_C_
23 #define _EMUL_BUGAPI_C_
26 /* from bug.S - Dale Rahn */
47 /* Note: this module is called via a table. There is no benefit in
50 #include "emul_generic.h"
51 #include "emul_bugapi.h"
53 /* Any starting address less than this is assumed to be an OEA program
55 #ifndef OEA_START_ADDRESS
56 #define OEA_START_ADDRESS 0x4000
59 #ifndef OEA_MEMORY_SIZE
60 #define OEA_MEMORY_SIZE 0x100000
63 /* All but CPU 0 are put into an infinate loop, this loop instruction
64 is stored at the address below */
65 #ifndef OEA_STALL_CPU_LOOP_ADDRESS
66 #define OEA_STALL_CPU_LOOP_ADDRESS 0x00c10
69 /* At initiallization, the system call exception branches to the BUG
72 #ifndef OEA_SYSTEM_CALL_ADDRESS
73 #define OEA_SYSTEM_CALL_ADDRESS 0x00c00
78 emul_bugapi_create(device
*root
,
83 /* check it really is for us */
85 && strcmp(name
, "bugapi") != 0
86 && strcmp(name
, "bug") != 0)
90 && bfd_get_start_address(image
) > OEA_START_ADDRESS
)
95 const memory_size
= OEA_MEMORY_SIZE
;
96 const elf_binary
= (image
!= NULL
97 && image
->xvec
->flavour
== bfd_target_elf_flavour
);
98 #ifdef bfd_little_endian /* new bfd */
99 const little_endian
= (image
!= NULL
&& bfd_little_endian(image
));
101 const little_endian
= (image
!= NULL
&&
102 !image
->xvec
->byteorder_big_p
);
106 device
*options
= device_tree_add_found(root
, "/", "options");
107 device_add_integer_property(options
,
110 device_add_boolean_property(options
,
113 device_add_string_property(options
,
116 device_add_boolean_property(options
,
118 (WITH_ALIGNMENT
== STRICT_ALIGNMENT
120 device_add_boolean_property(options
,
122 WITH_FLOATING_POINT
);
123 device_add_string_property(options
,
129 device_tree_add_found_uw_u_u(root
, "/", "memory",
130 0, memory_size
, access_read_write_exec
);
131 device_tree_add_found(root
, "/", "iobus@0x400000");
132 device_tree_add_found(root
, "/iobus", "console@0x000000,16");
133 device_tree_add_found(root
, "/iobus", "halt@0x100000,4");
134 device_tree_add_found(root
, "/iobus", "icu@0x200000,4");
136 { /* initialization */
137 device
*init
= device_tree_add_found(root
, "/", "init");
139 device
*init_register
= device_tree_add_found(init
, "", "register");
140 device_add_integer_property(init_register
,
142 OEA_STALL_CPU_LOOP_ADDRESS
);
143 device_add_integer_property(init_register
,
145 bfd_get_start_address(image
));
146 device_add_integer_property(init_register
,
149 device_add_integer_property(init_register
,
151 (msr_recoverable_interrupt
153 ? msr_little_endian_mode
156 device_tree_add_found_uw_u_u(init
, "",
158 OEA_SYSTEM_CALL_ADDRESS
,
159 4, emul_call_instruction
);
160 device_tree_add_found_uw_u_u(init
, "",
162 OEA_SYSTEM_CALL_ADDRESS
+ 4,
163 4, emul_rfi_instruction
);
164 device_tree_add_found_uw_u_u(init
, "",
166 OEA_STALL_CPU_LOOP_ADDRESS
,
167 4, emul_loop_instruction
);
170 device
*init_stack
= device_tree_add_found(init
, "", "stack");
171 device_add_null_property(init_stack
,
177 device
*init_load_binary
= device_tree_add_found(init
, "",
179 device_add_null_property(init_load_binary
,
180 bfd_get_filename(image
));
185 return (os_emul_data
*)-1;
189 emul_bugapi_init(os_emul_data
*emul_data
,
192 /* nothing happens here */
196 emul_bugapi_instruction_call(cpu
*processor
,
199 os_emul_data
*emul_data
)
201 const int call_id
= cpu_registers(processor
)->gpr
[10];
202 /* check that this isn't an invalid instruction */
203 if (cia
!= OEA_SYSTEM_CALL_ADDRESS
)
207 printf_filtered("%c", (char)cpu_registers(processor
)->gpr
[3]);
210 printf_filtered("\n");
213 cpu_halt(processor
, cia
, was_exited
, 0); /* always succeeds */
216 error("emul-bugapi: unimplemented bugapi call 0x%x from address 0x%lx\n",
221 /* the instruction following this one is a RFI. Thus by just
222 continuing the return from system call is performed */
225 const os_emul emul_bugapi
= {
230 emul_bugapi_instruction_call
,