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.
25 #ifndef STATIC_INLINE_CPU
26 #define STATIC_INLINE_CPU STATIC_INLINE
47 /* current instruction address */
48 unsigned_word program_counter
;
51 core
*physical
; /* all of memory */
53 vm_instruction_map
*instruction_map
; /* instructions */
54 vm_data_map
*data_map
; /* data */
56 /* current state of interrupt inputs */
57 int external_exception_pending
;
59 /* the system this processor is contained within */
65 /* Current CPU model information */
66 model_data
*model_ptr
;
68 #if WITH_IDECODE_CACHE_SIZE
69 /* a cache to store cracked instructions */
70 idecode_cache icache
[WITH_IDECODE_CACHE_SIZE
];
73 /* address reservation: keep the physical address and the contents
74 of memory at that address */
75 memory_reservation reservation
;
77 /* offset from event time to this cpu's idea of the local time */
78 signed64 time_base_local_time
;
79 signed64 decrementer_local_time
;
80 event_entry_tag decrementer_event
;
86 cpu_create(psim
*system
,
92 cpu
*processor
= ZALLOC(cpu
);
94 /* create the virtual memory map from the core */
95 processor
->physical
= memory
;
96 processor
->virtual = vm_create(memory
);
97 processor
->instruction_map
= vm_create_instruction_map(processor
->virtual);
98 processor
->data_map
= vm_create_data_map(processor
->virtual);
99 processor
->model_ptr
= model_create (processor
);
101 /* link back to core system */
102 processor
->system
= system
;
103 processor
->events
= events
;
104 processor
->cpu_nr
= cpu_nr
;
105 processor
->monitor
= monitor
;
112 cpu_init(cpu
*processor
)
114 memset(&processor
->regs
, 0, sizeof(processor
->regs
));
115 /* FIXME - should any of VM be inited also ? */
117 model_init (processor
, processor
->model_ptr
);
121 /* find ones way home */
124 cpu_system(cpu
*processor
)
126 return processor
->system
;
130 cpu_nr(cpu
*processor
)
132 return processor
->cpu_nr
;
135 INLINE_CPU event_queue
*
136 cpu_event_queue(cpu
*processor
)
138 return processor
->events
;
142 cpu_monitor(cpu
*processor
)
144 return processor
->monitor
;
147 INLINE_CPU model_data
*
148 cpu_model(cpu
*processor
)
150 return processor
->model_ptr
;
153 /* The processors local concept of time */
156 cpu_get_time_base(cpu
*processor
)
158 return (event_queue_time(processor
->events
)
159 - processor
->time_base_local_time
);
163 cpu_set_time_base(cpu
*processor
,
166 processor
->time_base_local_time
= (event_queue_time(processor
->events
)
171 cpu_get_decrementer(cpu
*processor
)
173 return (processor
->decrementer_local_time
174 - event_queue_time(processor
->events
));
177 STATIC_INLINE_CPU
void
178 cpu_decrement_event(event_queue
*queue
,
181 cpu
*processor
= (cpu
*)data
;
182 if (!decrementer_interrupt(processor
)) {
183 processor
->decrementer_event
= event_queue_schedule(processor
->events
,
191 cpu_set_decrementer(cpu
*processor
,
192 signed32 decrementer
)
194 signed64 old_decrementer
= (processor
->decrementer_local_time
195 - event_queue_time(processor
->events
));
196 event_queue_deschedule(processor
->events
, processor
->decrementer_event
);
197 processor
->decrementer_local_time
= (event_queue_time(processor
->events
)
199 if (decrementer
< 0 && old_decrementer
>= 0)
200 /* dec interrupt occures if the sign of the decrement reg is
201 changed by the load operation */
202 processor
->decrementer_event
= event_queue_schedule(processor
->events
,
206 else if (decrementer
>= 0)
207 processor
->decrementer_event
= event_queue_schedule(processor
->events
,
214 /* program counter manipulation */
217 cpu_set_program_counter(cpu
*processor
,
218 unsigned_word new_program_counter
)
220 processor
->program_counter
= new_program_counter
;
223 INLINE_CPU unsigned_word
224 cpu_get_program_counter(cpu
*processor
)
226 return processor
->program_counter
;
230 cpu_restart(cpu
*processor
,
233 processor
->program_counter
= nia
;
234 psim_restart(processor
->system
, processor
->cpu_nr
);
238 cpu_halt(cpu
*processor
,
243 if (processor
== NULL
) {
244 error("cpu_halt() processor=NULL, cia=0x%x, reason=%d, signal=%d\n",
250 model_halt(processor
, processor
->model_ptr
);
251 processor
->program_counter
= cia
;
252 psim_halt(processor
->system
, processor
->cpu_nr
, cia
, reason
, signal
);
257 #if WITH_IDECODE_CACHE_SIZE
258 /* allow access to the cpu's instruction cache */
259 INLINE_CPU idecode_cache
*
260 cpu_icache_entry(cpu
*processor
,
263 return &processor
->icache
[cia
/ 4 % WITH_IDECODE_CACHE_SIZE
];
268 cpu_flush_icache(cpu
*processor
)
271 /* force all addresses to 0xff... so that they never hit */
272 for (i
= 0; i
< WITH_IDECODE_CACHE_SIZE
; i
++)
273 processor
->icache
[i
].address
= MASK(0, 63);
278 /* address map revelation */
280 INLINE_CPU vm_instruction_map
*
281 cpu_instruction_map(cpu
*processor
)
283 return processor
->instruction_map
;
286 INLINE_CPU vm_data_map
*
287 cpu_data_map(cpu
*processor
)
289 return processor
->data_map
;
293 /* reservation access */
295 INLINE_CPU memory_reservation
*
296 cpu_reservation(cpu
*processor
)
298 return &processor
->reservation
;
302 /* register access */
304 INLINE_CPU registers
*
305 cpu_registers(cpu
*processor
)
307 return &processor
->regs
;
311 cpu_synchronize_context(cpu
*processor
)
313 #if (WITH_IDECODE_CACHE)
314 /* kill of the cache */
315 cpu_flush_icache(processor
);
318 /* update virtual memory */
319 vm_synchronize_context(processor
->virtual,
322 processor
->regs
.msr
);
326 /* might again be useful one day */
329 cpu_print_info(cpu
*processor
, int verbose
)