1 /* This file is part of the program psim.
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 /* the system this processor is contained within */
54 os_emul *os_emulation;
59 /* Current CPU model information */
60 model_data *model_ptr;
62 #if WITH_IDECODE_CACHE_SIZE
63 /* a cache to store cracked instructions */
64 idecode_cache icache[WITH_IDECODE_CACHE_SIZE];
67 /* any interrupt state */
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,
86 os_emul *os_emulation,
89 cpu *processor = ZALLOC(cpu);
91 /* create the virtual memory map from the core */
92 processor->physical = memory;
93 processor->virtual = vm_create(memory);
94 processor->instruction_map = vm_create_instruction_map(processor->virtual);
95 processor->data_map = vm_create_data_map(processor->virtual);
97 if (CURRENT_MODEL_ISSUE > 0)
98 processor->model_ptr = model_create (processor);
100 /* link back to core system */
101 processor->system = system;
102 processor->events = psim_event_queue(system);
103 processor->cpu_nr = cpu_nr;
104 processor->monitor = monitor;
105 processor->os_emulation = os_emulation;
113 cpu_init(cpu *processor)
115 memset(&processor->regs, 0, sizeof(processor->regs));
116 /* vm init is delayed until after the device tree has been init as
117 the devices may further init the cpu */
118 if (CURRENT_MODEL_ISSUE > 0)
119 model_init (processor->model_ptr);
123 /* find ones way home */
127 cpu_system(cpu *processor)
129 return processor->system;
134 cpu_nr(cpu *processor)
136 return processor->cpu_nr;
141 cpu_monitor(cpu *processor)
143 return processor->monitor;
148 cpu_os_emulation(cpu *processor)
150 return processor->os_emulation;
155 cpu_model(cpu *processor)
157 return processor->model_ptr;
161 /* program counter manipulation */
165 cpu_set_program_counter(cpu *processor,
166 unsigned_word new_program_counter)
168 processor->program_counter = new_program_counter;
173 cpu_get_program_counter(cpu *processor)
175 return processor->program_counter;
181 cpu_restart(cpu *processor,
184 ASSERT(processor != NULL);
185 cpu_set_program_counter(processor, nia);
186 psim_restart(processor->system, processor->cpu_nr);
191 cpu_halt(cpu *processor,
196 ASSERT(processor != NULL);
197 if (CURRENT_MODEL_ISSUE > 0)
198 model_halt(processor->model_ptr);
199 cpu_set_program_counter(processor, nia);
200 psim_halt(processor->system, processor->cpu_nr, reason, signal);
205 cpu_error(cpu *processor,
213 /* format the message */
215 vsprintf(message, fmt, ap);
219 if (strlen(message) >= sizeof(message))
220 error("cpu_error: buffer overflow");
222 if (processor != NULL) {
223 printf_filtered("cpu %d, cia 0x%lx: %s\n",
224 processor->cpu_nr + 1, (unsigned long)cia, message);
225 cpu_halt(processor, cia, was_signalled, -1);
228 error("cpu: %s", message);
233 /* The processors local concept of time */
237 cpu_get_time_base(cpu *processor)
239 return (event_queue_time(processor->events)
240 - processor->time_base_local_time);
245 cpu_set_time_base(cpu *processor,
248 processor->time_base_local_time = (event_queue_time(processor->events)
254 cpu_get_decrementer(cpu *processor)
256 return (processor->decrementer_local_time
257 - event_queue_time(processor->events));
262 cpu_decrement_event(void *data)
264 cpu *processor = (cpu*)data;
265 processor->decrementer_event = NULL;
266 decrementer_interrupt(processor);
271 cpu_set_decrementer(cpu *processor,
272 signed32 decrementer)
274 signed64 old_decrementer = cpu_get_decrementer(processor);
275 event_queue_deschedule(processor->events, processor->decrementer_event);
276 processor->decrementer_event = NULL;
277 processor->decrementer_local_time = (event_queue_time(processor->events)
279 if (decrementer < 0 && old_decrementer >= 0)
280 /* A decrementer interrupt occures if the sign of the decrement
281 register is changed from positive to negative by the load
283 decrementer_interrupt(processor);
284 else if (decrementer >= 0)
285 processor->decrementer_event = event_queue_schedule(processor->events,
292 #if WITH_IDECODE_CACHE_SIZE
293 /* allow access to the cpu's instruction cache */
296 cpu_icache_entry(cpu *processor,
299 return &processor->icache[cia / 4 % WITH_IDECODE_CACHE_SIZE];
305 cpu_flush_icache(cpu *processor)
308 /* force all addresses to 0xff... so that they never hit */
309 for (i = 0; i < WITH_IDECODE_CACHE_SIZE; i++)
310 processor->icache[i].address = MASK(0, 63);
315 /* address map revelation */
318 (vm_instruction_map *)
319 cpu_instruction_map(cpu *processor)
321 return processor->instruction_map;
326 cpu_data_map(cpu *processor)
328 return processor->data_map;
333 cpu_page_tlb_invalidate_entry(cpu *processor,
336 vm_page_tlb_invalidate_entry(processor->virtual, ea);
341 cpu_page_tlb_invalidate_all(cpu *processor)
343 vm_page_tlb_invalidate_all(processor->virtual);
347 /* interrupt access */
351 cpu_interrupts(cpu *processor)
353 return &processor->ints;
358 /* reservation access */
361 (memory_reservation *)
362 cpu_reservation(cpu *processor)
364 return &processor->reservation;
368 /* register access */
372 cpu_registers(cpu *processor)
374 return &processor->regs;
379 cpu_synchronize_context(cpu *processor,
382 #if (WITH_IDECODE_CACHE_SIZE)
383 /* kill of the cache */
384 cpu_flush_icache(processor);
387 /* update virtual memory */
388 vm_synchronize_context(processor->virtual,
396 /* might again be useful one day */
400 cpu_print_info(cpu *processor, int verbose)