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.
43 /* current instruction address */
44 unsigned_word program_counter
;
47 core
*physical
; /* all of memory */
49 vm_instruction_map
*instruction_map
; /* instructions */
50 vm_data_map
*data_map
; /* data */
52 /* current state of interrupt inputs */
53 int external_exception_pending
;
55 /* the system this processor is contained within */
57 os_emul
*os_emulation
;
62 /* Current CPU model information */
63 model_data
*model_ptr
;
65 #if WITH_IDECODE_CACHE_SIZE
66 /* a cache to store cracked instructions */
67 idecode_cache icache
[WITH_IDECODE_CACHE_SIZE
];
70 /* address reservation: keep the physical address and the contents
71 of memory at that address */
72 memory_reservation reservation
;
74 /* offset from event time to this cpu's idea of the local time */
75 signed64 time_base_local_time
;
76 signed64 decrementer_local_time
;
77 event_entry_tag decrementer_event
;
83 cpu_create(psim
*system
,
87 os_emul
*os_emulation
,
90 cpu
*processor
= ZALLOC(cpu
);
92 /* create the virtual memory map from the core */
93 processor
->physical
= memory
;
94 processor
->virtual = vm_create(memory
);
95 processor
->instruction_map
= vm_create_instruction_map(processor
->virtual);
96 processor
->data_map
= vm_create_data_map(processor
->virtual);
98 if (CURRENT_MODEL_ISSUE
> 0)
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
;
106 processor
->os_emulation
= os_emulation
;
114 cpu_init(cpu
*processor
)
116 memset(&processor
->regs
, 0, sizeof(processor
->regs
));
117 /* vm init is delayed until after the device tree has been init as
118 the devices may further init the cpu */
119 if (CURRENT_MODEL_ISSUE
> 0)
120 model_init (processor
->model_ptr
);
124 /* find ones way home */
128 cpu_system(cpu
*processor
)
130 return processor
->system
;
135 cpu_nr(cpu
*processor
)
137 return processor
->cpu_nr
;
142 cpu_event_queue(cpu
*processor
)
144 return processor
->events
;
149 cpu_monitor(cpu
*processor
)
151 return processor
->monitor
;
156 cpu_os_emulation(cpu
*processor
)
158 return processor
->os_emulation
;
163 cpu_model(cpu
*processor
)
165 return processor
->model_ptr
;
168 /* 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
);
180 cpu_set_time_base(cpu
*processor
,
183 processor
->time_base_local_time
= (event_queue_time(processor
->events
)
189 cpu_get_decrementer(cpu
*processor
)
191 return (processor
->decrementer_local_time
192 - event_queue_time(processor
->events
));
197 cpu_decrement_event(event_queue
*queue
,
200 cpu
*processor
= (cpu
*)data
;
201 if (!decrementer_interrupt(processor
)) {
202 processor
->decrementer_event
= event_queue_schedule(processor
->events
,
211 cpu_set_decrementer(cpu
*processor
,
212 signed32 decrementer
)
214 signed64 old_decrementer
= (processor
->decrementer_local_time
215 - event_queue_time(processor
->events
));
216 event_queue_deschedule(processor
->events
, processor
->decrementer_event
);
217 processor
->decrementer_local_time
= (event_queue_time(processor
->events
)
219 if (decrementer
< 0 && old_decrementer
>= 0)
220 /* dec interrupt occures if the sign of the decrement reg is
221 changed by the load operation */
222 processor
->decrementer_event
= event_queue_schedule(processor
->events
,
226 else if (decrementer
>= 0)
227 processor
->decrementer_event
= event_queue_schedule(processor
->events
,
234 /* program counter manipulation */
238 cpu_set_program_counter(cpu
*processor
,
239 unsigned_word new_program_counter
)
241 processor
->program_counter
= new_program_counter
;
246 cpu_get_program_counter(cpu
*processor
)
248 return processor
->program_counter
;
253 cpu_restart(cpu
*processor
,
256 processor
->program_counter
= nia
;
257 psim_restart(processor
->system
, processor
->cpu_nr
);
262 cpu_halt(cpu
*processor
,
267 if (processor
== NULL
) {
268 error("cpu_halt() processor=NULL, cia=0x%x, reason=%d, signal=%d\n",
274 if (CURRENT_MODEL_ISSUE
> 0)
275 model_halt(processor
->model_ptr
);
277 processor
->program_counter
= cia
;
278 psim_halt(processor
->system
, processor
->cpu_nr
, cia
, reason
, signal
);
283 #if WITH_IDECODE_CACHE_SIZE
284 /* allow access to the cpu's instruction cache */
287 cpu_icache_entry(cpu
*processor
,
290 return &processor
->icache
[cia
/ 4 % WITH_IDECODE_CACHE_SIZE
];
296 cpu_flush_icache(cpu
*processor
)
299 /* force all addresses to 0xff... so that they never hit */
300 for (i
= 0; i
< WITH_IDECODE_CACHE_SIZE
; i
++)
301 processor
->icache
[i
].address
= MASK(0, 63);
306 /* address map revelation */
309 (vm_instruction_map
*)
310 cpu_instruction_map(cpu
*processor
)
312 return processor
->instruction_map
;
317 cpu_data_map(cpu
*processor
)
319 return processor
->data_map
;
324 cpu_page_tlb_invalidate_entry(cpu
*processor
,
327 vm_page_tlb_invalidate_entry(processor
->virtual, ea
);
332 cpu_page_tlb_invalidate_all(cpu
*processor
)
334 vm_page_tlb_invalidate_all(processor
->virtual);
338 /* reservation access */
341 (memory_reservation
*)
342 cpu_reservation(cpu
*processor
)
344 return &processor
->reservation
;
348 /* register access */
352 cpu_registers(cpu
*processor
)
354 return &processor
->regs
;
359 cpu_synchronize_context(cpu
*processor
)
361 #if (WITH_IDECODE_CACHE)
362 /* kill of the cache */
363 cpu_flush_icache(processor
);
366 /* update virtual memory */
367 vm_synchronize_context(processor
->virtual,
370 processor
->regs
.msr
);
374 /* might again be useful one day */
378 cpu_print_info(cpu
*processor
, int verbose
)