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 functional unit information */
66 function_unit *func_unit;
68 /* Current CPU model information */
69 model_data *model_ptr;
71 #if WITH_IDECODE_CACHE_SIZE
72 /* a cache to store cracked instructions */
73 idecode_cache icache[WITH_IDECODE_CACHE_SIZE];
76 /* address reservation: keep the physical address and the contents
77 of memory at that address */
78 memory_reservation reservation;
80 /* offset from event time to this cpu's idea of the local time */
81 signed64 time_base_local_time;
82 signed64 decrementer_local_time;
83 event_entry_tag decrementer_event;
89 cpu_create(psim *system,
95 cpu *processor = ZALLOC(cpu);
97 /* create the virtual memory map from the core */
98 processor->physical = memory;
99 processor->virtual = vm_create(memory);
100 processor->instruction_map = vm_create_instruction_map(processor->virtual);
101 processor->data_map = vm_create_data_map(processor->virtual);
102 processor->model_ptr = model_create (processor);
104 /* link back to core system */
105 processor->system = system;
106 processor->events = events;
107 processor->cpu_nr = cpu_nr;
108 processor->monitor = monitor;
110 /* Create function unit if desired */
111 if (WITH_FUNCTION_UNIT)
112 processor->func_unit = function_unit_create ();
119 cpu_init(cpu *processor)
121 memset(&processor->regs, 0, sizeof(processor->regs));
122 /* FIXME - should any of VM be inited also ? */
124 if (WITH_FUNCTION_UNIT)
125 function_unit_init (processor->func_unit);
127 model_init (processor, processor->model_ptr);
131 /* find ones way home */
134 cpu_system(cpu *processor)
136 return processor->system;
140 cpu_nr(cpu *processor)
142 return processor->cpu_nr;
145 INLINE_CPU event_queue *
146 cpu_event_queue(cpu *processor)
148 return processor->events;
152 cpu_monitor(cpu *processor)
154 return processor->monitor;
157 INLINE_CPU function_unit *
158 cpu_function_unit(cpu *processor)
160 return processor->func_unit;
163 INLINE_CPU model_data *
164 cpu_model(cpu *processor)
166 return processor->model_ptr;
169 /* The processors local concept of time */
172 cpu_get_time_base(cpu *processor)
174 return (event_queue_time(processor->events)
175 - processor->time_base_local_time);
179 cpu_set_time_base(cpu *processor,
182 processor->time_base_local_time = (event_queue_time(processor->events)
187 cpu_get_decrementer(cpu *processor)
189 return (processor->decrementer_local_time
190 - event_queue_time(processor->events));
193 STATIC_INLINE_CPU void
194 cpu_decrement_event(event_queue *queue,
197 cpu *processor = (cpu*)data;
198 if (!decrementer_interrupt(processor)) {
199 processor->decrementer_event = event_queue_schedule(processor->events,
207 cpu_set_decrementer(cpu *processor,
208 signed32 decrementer)
210 signed64 old_decrementer = (processor->decrementer_local_time
211 - event_queue_time(processor->events));
212 event_queue_deschedule(processor->events, processor->decrementer_event);
213 processor->decrementer_local_time = (event_queue_time(processor->events)
215 if (decrementer < 0 && old_decrementer >= 0)
216 /* dec interrupt occures if the sign of the decrement reg is
217 changed by the load operation */
218 processor->decrementer_event = event_queue_schedule(processor->events,
222 else if (decrementer >= 0)
223 processor->decrementer_event = event_queue_schedule(processor->events,
230 /* program counter manipulation */
233 cpu_set_program_counter(cpu *processor,
234 unsigned_word new_program_counter)
236 processor->program_counter = new_program_counter;
239 INLINE_CPU unsigned_word
240 cpu_get_program_counter(cpu *processor)
242 return processor->program_counter;
246 cpu_restart(cpu *processor,
249 processor->program_counter = nia;
250 psim_restart(processor->system, processor->cpu_nr);
254 cpu_halt(cpu *processor,
259 if (processor == NULL) {
260 error("cpu_halt() processor=NULL, cia=0x%x, reason=%d, signal=%d\n",
266 if (WITH_FUNCTION_UNIT)
267 function_unit_halt(processor, processor->func_unit);
269 model_halt(processor, processor->model_ptr);
270 processor->program_counter = cia;
271 psim_halt(processor->system, processor->cpu_nr, cia, reason, signal);
276 #if WITH_IDECODE_CACHE_SIZE
277 /* allow access to the cpu's instruction cache */
278 INLINE_CPU idecode_cache *
279 cpu_icache_entry(cpu *processor,
282 return &processor->icache[cia / 4 % WITH_IDECODE_CACHE_SIZE];
287 cpu_flush_icache(cpu *processor)
290 /* force all addresses to 0xff... so that they never hit */
291 for (i = 0; i < WITH_IDECODE_CACHE_SIZE; i++)
292 processor->icache[i].address = MASK(0, 63);
297 /* address map revelation */
299 INLINE_CPU vm_instruction_map *
300 cpu_instruction_map(cpu *processor)
302 return processor->instruction_map;
305 INLINE_CPU vm_data_map *
306 cpu_data_map(cpu *processor)
308 return processor->data_map;
312 /* reservation access */
314 INLINE_CPU memory_reservation *
315 cpu_reservation(cpu *processor)
317 return &processor->reservation;
321 /* register access */
323 INLINE_CPU registers *
324 cpu_registers(cpu *processor)
326 return &processor->regs;
330 cpu_synchronize_context(cpu *processor)
332 #if (WITH_IDECODE_CACHE)
333 /* kill of the cache */
334 cpu_flush_icache(processor);
337 /* update virtual memory */
338 vm_synchronize_context(processor->virtual,
341 processor->regs.msr);
345 /* might again be useful one day */
348 cpu_print_info(cpu *processor, int verbose)