2 |
#define CPU_H |
#define CPU_H |
3 |
|
|
4 |
/* |
/* |
5 |
* Copyright (C) 2005-2006 Anders Gavare. All rights reserved. |
* Copyright (C) 2005-2007 Anders Gavare. All rights reserved. |
6 |
* |
* |
7 |
* Redistribution and use in source and binary forms, with or without |
* Redistribution and use in source and binary forms, with or without |
8 |
* modification, are permitted provided that the following conditions are met: |
* modification, are permitted provided that the following conditions are met: |
28 |
* SUCH DAMAGE. |
* SUCH DAMAGE. |
29 |
* |
* |
30 |
* |
* |
31 |
* $Id: cpu.h,v 1.90 2006/08/12 11:43:13 debug Exp $ |
* $Id: cpu.h,v 1.109 2007/02/10 14:29:54 debug Exp $ |
32 |
* |
* |
33 |
* CPU-related definitions. |
* CPU-related definitions. |
34 |
*/ |
*/ |
194 |
#include "cpu_alpha.h" |
#include "cpu_alpha.h" |
195 |
#include "cpu_arm.h" |
#include "cpu_arm.h" |
196 |
#include "cpu_avr.h" |
#include "cpu_avr.h" |
|
#include "cpu_hppa.h" |
|
|
#include "cpu_i960.h" |
|
|
#include "cpu_ia64.h" |
|
197 |
#include "cpu_m68k.h" |
#include "cpu_m68k.h" |
198 |
#include "cpu_mips.h" |
#include "cpu_mips.h" |
199 |
#include "cpu_ppc.h" |
#include "cpu_ppc.h" |
200 |
|
#include "cpu_rca180x.h" |
201 |
#include "cpu_sh.h" |
#include "cpu_sh.h" |
202 |
#include "cpu_sparc.h" |
#include "cpu_sparc.h" |
203 |
#include "cpu_transputer.h" |
#include "cpu_transputer.h" |
|
#include "cpu_x86.h" |
|
204 |
|
|
205 |
struct cpu; |
struct cpu; |
206 |
struct emul; |
struct emul; |
207 |
struct machine; |
struct machine; |
208 |
struct memory; |
struct memory; |
209 |
|
struct settings; |
210 |
|
|
211 |
|
|
212 |
/* |
/* |
237 |
/* List available CPU types for this architecture. */ |
/* List available CPU types for this architecture. */ |
238 |
void (*list_available_types)(void); |
void (*list_available_types)(void); |
239 |
|
|
|
/* Read or write a CPU register, given a name. */ |
|
|
void (*register_match)(struct machine *m, |
|
|
char *name, int writeflag, |
|
|
uint64_t *valuep, int *match_register); |
|
|
|
|
240 |
/* Disassemble an instruction. */ |
/* Disassemble an instruction. */ |
241 |
int (*disassemble_instr)(struct cpu *cpu, |
int (*disassemble_instr)(struct cpu *cpu, |
242 |
unsigned char *instr, int running, |
unsigned char *instr, int running, |
253 |
void (*tlbdump)(struct machine *m, int x, |
void (*tlbdump)(struct machine *m, int x, |
254 |
int rawflag); |
int rawflag); |
255 |
|
|
|
/* Assert an interrupt. */ |
|
|
int (*interrupt)(struct cpu *cpu, uint64_t irq_nr); |
|
|
|
|
|
/* De-assert an interrupt. */ |
|
|
int (*interrupt_ack)(struct cpu *cpu, |
|
|
uint64_t irq_nr); |
|
|
|
|
256 |
/* Print architecture-specific function call arguments. |
/* Print architecture-specific function call arguments. |
257 |
(This is called for each function call, if running with -t.) */ |
(This is called for each function call, if running with -t.) */ |
258 |
void (*functioncall_trace)(struct cpu *, |
void (*functioncall_trace)(struct cpu *, |
279 |
#define N_SAFE_DYNTRANS_LIMIT_SHIFT 14 |
#define N_SAFE_DYNTRANS_LIMIT_SHIFT 14 |
280 |
#define N_SAFE_DYNTRANS_LIMIT ((1 << (N_SAFE_DYNTRANS_LIMIT_SHIFT - 1)) - 1) |
#define N_SAFE_DYNTRANS_LIMIT ((1 << (N_SAFE_DYNTRANS_LIMIT_SHIFT - 1)) - 1) |
281 |
|
|
282 |
#define DYNTRANS_CACHE_SIZE (24*1048576) |
#define DEFAULT_DYNTRANS_CACHE_SIZE (40*1048576) |
283 |
#define DYNTRANS_CACHE_MARGIN 300000 |
#define DYNTRANS_CACHE_MARGIN 200000 |
284 |
|
|
285 |
#define N_BASE_TABLE_ENTRIES 32768 |
#define N_BASE_TABLE_ENTRIES 32768 |
286 |
#define PAGENR_TO_TABLE_INDEX(a) ((a) & (N_BASE_TABLE_ENTRIES-1)) |
#define PAGENR_TO_TABLE_INDEX(a) ((a) & (N_BASE_TABLE_ENTRIES-1)) |
294 |
/* Pointer back to the machine this CPU is in: */ |
/* Pointer back to the machine this CPU is in: */ |
295 |
struct machine *machine; |
struct machine *machine; |
296 |
|
|
297 |
|
/* Settings: */ |
298 |
|
struct settings *settings; |
299 |
|
|
300 |
/* CPU-specific name, e.g. "R2000", "21164PC", etc. */ |
/* CPU-specific name, e.g. "R2000", "21164PC", etc. */ |
301 |
char *name; |
char *name; |
302 |
|
|
303 |
|
/* Full "path" to the CPU, e.g. "emul[0].machine[0].cpu[0]": */ |
304 |
|
char *path; |
305 |
|
|
306 |
/* EMUL_LITTLE_ENDIAN or EMUL_BIG_ENDIAN. */ |
/* EMUL_LITTLE_ENDIAN or EMUL_BIG_ENDIAN. */ |
307 |
int byte_order; |
int byte_order; |
308 |
|
|
349 |
* If is_halted is true when an interrupt trap occurs, the pointer |
* If is_halted is true when an interrupt trap occurs, the pointer |
350 |
* to the next instruction to execute will be the instruction |
* to the next instruction to execute will be the instruction |
351 |
* following the halt instruction, not the halt instrucion itself. |
* following the halt instruction, not the halt instrucion itself. |
352 |
|
* |
353 |
|
* If has_been_idling is true when printing the number of executed |
354 |
|
* instructions per second, "idling" is printed instead. (The number |
355 |
|
* of instrs per second when idling is meaningless anyway.) |
356 |
*/ |
*/ |
357 |
int is_halted; |
int is_halted; |
358 |
|
int has_been_idling; |
359 |
|
|
360 |
/* |
/* |
361 |
* Dynamic translation: |
* Dynamic translation: |
372 |
* _decreases_ n_translated_instrs. That way, once the dyntrans loop |
* _decreases_ n_translated_instrs. That way, once the dyntrans loop |
373 |
* exits, only real instructions will be counted, and not the |
* exits, only real instructions will be counted, and not the |
374 |
* "nothing" instructions. |
* "nothing" instructions. |
375 |
|
* |
376 |
|
* The translation cache is a relative large chunk of memory (say, |
377 |
|
* 32 MB) which is used for translations. When it has been used up, |
378 |
|
* everything restarts from scratch. |
379 |
|
* |
380 |
|
* When translating to native code, currently_translating_to_native |
381 |
|
* is non-zero, and native_code_function_pointer points to the |
382 |
|
* "ic->f" which will be modified (once the translation has finished) |
383 |
|
* to point to the newly translated code. |
384 |
*/ |
*/ |
385 |
int n_translated_instrs; |
int n_translated_instrs; |
386 |
unsigned char *translation_cache; |
unsigned char *translation_cache; |
387 |
size_t translation_cache_cur_ofs; |
size_t translation_cache_cur_ofs; |
388 |
|
int currently_translating_to_native; |
389 |
|
int nr_of_instructions_translated_to_native; |
390 |
|
unsigned char *native_cur_output_ptr; |
391 |
|
void **native_code_function_pointer; |
392 |
|
|
393 |
/* |
/* |
394 |
* CPU-family dependent: |
* CPU-family dependent: |
400 |
struct alpha_cpu alpha; |
struct alpha_cpu alpha; |
401 |
struct arm_cpu arm; |
struct arm_cpu arm; |
402 |
struct avr_cpu avr; |
struct avr_cpu avr; |
|
struct hppa_cpu hppa; |
|
|
struct i960_cpu i960; |
|
|
struct ia64_cpu ia64; |
|
403 |
struct m68k_cpu m68k; |
struct m68k_cpu m68k; |
404 |
struct mips_cpu mips; |
struct mips_cpu mips; |
405 |
struct ppc_cpu ppc; |
struct ppc_cpu ppc; |
406 |
|
struct rca180x_cpu rca180x; |
407 |
struct sh_cpu sh; |
struct sh_cpu sh; |
408 |
struct sparc_cpu sparc; |
struct sparc_cpu sparc; |
409 |
struct transputer_cpu transputer; |
struct transputer_cpu transputer; |
|
struct x86_cpu x86; |
|
410 |
} cd; |
} cd; |
411 |
}; |
}; |
412 |
|
|
414 |
/* cpu.c: */ |
/* cpu.c: */ |
415 |
struct cpu *cpu_new(struct memory *mem, struct machine *machine, |
struct cpu *cpu_new(struct memory *mem, struct machine *machine, |
416 |
int cpu_id, char *cpu_type_name); |
int cpu_id, char *cpu_type_name); |
417 |
|
void cpu_destroy(struct cpu *cpu); |
418 |
|
|
419 |
void cpu_tlbdump(struct machine *m, int x, int rawflag); |
void cpu_tlbdump(struct machine *m, int x, int rawflag); |
|
void cpu_register_match(struct machine *m, char *name, |
|
|
int writeflag, uint64_t *valuep, int *match_register); |
|
420 |
void cpu_register_dump(struct machine *m, struct cpu *cpu, |
void cpu_register_dump(struct machine *m, struct cpu *cpu, |
421 |
int gprs, int coprocs); |
int gprs, int coprocs); |
422 |
int cpu_disassemble_instr(struct machine *m, struct cpu *cpu, |
int cpu_disassemble_instr(struct machine *m, struct cpu *cpu, |
423 |
unsigned char *instr, int running, uint64_t addr); |
unsigned char *instr, int running, uint64_t addr); |
424 |
char *cpu_gdb_stub(struct cpu *cpu, char *cmd); |
char *cpu_gdb_stub(struct cpu *cpu, char *cmd); |
425 |
int cpu_interrupt(struct cpu *cpu, uint64_t irq_nr); |
|
|
int cpu_interrupt_ack(struct cpu *cpu, uint64_t irq_nr); |
|
426 |
void cpu_functioncall_trace(struct cpu *cpu, uint64_t f); |
void cpu_functioncall_trace(struct cpu *cpu, uint64_t f); |
427 |
void cpu_functioncall_trace_return(struct cpu *cpu); |
void cpu_functioncall_trace_return(struct cpu *cpu); |
428 |
|
|
429 |
void cpu_create_or_reset_tc(struct cpu *cpu); |
void cpu_create_or_reset_tc(struct cpu *cpu); |
430 |
|
|
431 |
void cpu_run_init(struct machine *machine); |
void cpu_run_init(struct machine *machine); |
432 |
void cpu_run_deinit(struct machine *machine); |
void cpu_run_deinit(struct machine *machine); |
433 |
|
|
434 |
void cpu_dumpinfo(struct machine *m, struct cpu *cpu); |
void cpu_dumpinfo(struct machine *m, struct cpu *cpu); |
435 |
void cpu_list_available_types(void); |
void cpu_list_available_types(void); |
436 |
void cpu_show_cycles(struct machine *machine, int forced); |
void cpu_show_cycles(struct machine *machine, int forced); |
437 |
|
|
438 |
struct cpu_family *cpu_family_ptr_by_number(int arch); |
struct cpu_family *cpu_family_ptr_by_number(int arch); |
439 |
void cpu_init(void); |
void cpu_init(void); |
440 |
|
|
446 |
#define INVALIDATE_VADDR_UPPER4 16 /* useful for PPC emulation */ |
#define INVALIDATE_VADDR_UPPER4 16 /* useful for PPC emulation */ |
447 |
|
|
448 |
|
|
449 |
|
/* Note: 64-bit processors running in 32-bit mode use a 32-bit |
450 |
|
display format, even though the underlying data is 64-bits. */ |
451 |
|
#define CPU_SETTINGS_ADD_REGISTER64(name, var) \ |
452 |
|
settings_add(cpu->settings, name, 1, SETTINGS_TYPE_UINT64, \ |
453 |
|
cpu->is_32bit? SETTINGS_FORMAT_HEX32 : SETTINGS_FORMAT_HEX64, \ |
454 |
|
(void *) &(var)); |
455 |
|
#define CPU_SETTINGS_ADD_REGISTER32(name, var) \ |
456 |
|
settings_add(cpu->settings, name, 1, SETTINGS_TYPE_UINT32, \ |
457 |
|
SETTINGS_FORMAT_HEX32, (void *) &(var)); |
458 |
|
#define CPU_SETTINGS_ADD_REGISTER16(name, var) \ |
459 |
|
settings_add(cpu->settings, name, 1, SETTINGS_TYPE_UINT16, \ |
460 |
|
SETTINGS_FORMAT_HEX16, (void *) &(var)); |
461 |
|
#define CPU_SETTINGS_ADD_REGISTER8(name, var) \ |
462 |
|
settings_add(cpu->settings, name, 1, SETTINGS_TYPE_UINT8, \ |
463 |
|
SETTINGS_FORMAT_HEX8, (void *) &(var)); |
464 |
|
|
465 |
|
|
466 |
#define CPU_FAMILY_INIT(n,s) int n ## _cpu_family_init( \ |
#define CPU_FAMILY_INIT(n,s) int n ## _cpu_family_init( \ |
467 |
struct cpu_family *fp) { \ |
struct cpu_family *fp) { \ |
468 |
/* Fill in the cpu_family struct with valid data for this arch. */ \ |
/* Fill in the cpu_family struct with valid data for this arch. */ \ |
469 |
fp->name = s; \ |
fp->name = s; \ |
470 |
fp->cpu_new = n ## _cpu_new; \ |
fp->cpu_new = n ## _cpu_new; \ |
471 |
fp->list_available_types = n ## _cpu_list_available_types; \ |
fp->list_available_types = n ## _cpu_list_available_types; \ |
|
fp->register_match = n ## _cpu_register_match; \ |
|
472 |
fp->disassemble_instr = n ## _cpu_disassemble_instr; \ |
fp->disassemble_instr = n ## _cpu_disassemble_instr; \ |
473 |
fp->register_dump = n ## _cpu_register_dump; \ |
fp->register_dump = n ## _cpu_register_dump; \ |
474 |
fp->dumpinfo = n ## _cpu_dumpinfo; \ |
fp->dumpinfo = n ## _cpu_dumpinfo; \ |
|
fp->interrupt = n ## _cpu_interrupt; \ |
|
|
fp->interrupt_ack = n ## _cpu_interrupt_ack; \ |
|
475 |
fp->functioncall_trace = n ## _cpu_functioncall_trace; \ |
fp->functioncall_trace = n ## _cpu_functioncall_trace; \ |
476 |
fp->gdb_stub = n ## _cpu_gdb_stub; \ |
fp->gdb_stub = n ## _cpu_gdb_stub; \ |
477 |
fp->tlbdump = n ## _cpu_tlbdump; \ |
fp->tlbdump = n ## _cpu_tlbdump; \ |