--- trunk/src/include/cpu.h 2007/10/08 16:20:40 30 +++ trunk/src/include/cpu.h 2007/10/08 16:22:11 40 @@ -2,7 +2,7 @@ #define CPU_H /* - * Copyright (C) 2005-2006 Anders Gavare. All rights reserved. + * Copyright (C) 2005-2007 Anders Gavare. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -28,7 +28,7 @@ * SUCH DAMAGE. * * - * $Id: cpu.h,v 1.90 2006/08/12 11:43:13 debug Exp $ + * $Id: cpu.h,v 1.116 2007/04/19 15:18:16 debug Exp $ * * CPU-related definitions. */ @@ -194,21 +194,17 @@ #include "cpu_alpha.h" #include "cpu_arm.h" #include "cpu_avr.h" -#include "cpu_hppa.h" -#include "cpu_i960.h" -#include "cpu_ia64.h" -#include "cpu_m68k.h" +#include "cpu_m88k.h" #include "cpu_mips.h" #include "cpu_ppc.h" #include "cpu_sh.h" #include "cpu_sparc.h" -#include "cpu_transputer.h" -#include "cpu_x86.h" struct cpu; struct emul; struct machine; struct memory; +struct settings; /* @@ -239,11 +235,6 @@ /* List available CPU types for this architecture. */ void (*list_available_types)(void); - /* 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); - /* Disassemble an instruction. */ int (*disassemble_instr)(struct cpu *cpu, unsigned char *instr, int running, @@ -260,20 +251,10 @@ void (*tlbdump)(struct machine *m, int x, int rawflag); - /* 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); - /* Print architecture-specific function call arguments. (This is called for each function call, if running with -t.) */ void (*functioncall_trace)(struct cpu *, uint64_t f, int n_args); - - /* GDB command handler. */ - char *(*gdb_stub)(struct cpu *, char *cmd); }; @@ -293,13 +274,22 @@ #define N_SAFE_DYNTRANS_LIMIT_SHIFT 14 #define N_SAFE_DYNTRANS_LIMIT ((1 << (N_SAFE_DYNTRANS_LIMIT_SHIFT - 1)) - 1) -#define DYNTRANS_CACHE_SIZE (24*1048576) -#define DYNTRANS_CACHE_MARGIN 300000 +#define DEFAULT_DYNTRANS_CACHE_SIZE (40*1048576) +#define DYNTRANS_CACHE_MARGIN 200000 -#define N_BASE_TABLE_ENTRIES 32768 +#define N_BASE_TABLE_ENTRIES 65536 #define PAGENR_TO_TABLE_INDEX(a) ((a) & (N_BASE_TABLE_ENTRIES-1)) +#ifdef NATIVE_CODE_GENERATION +/* + * Intermediate Native Representation (INR). + * Used for native code generation. + */ +#include "inr.h" +#endif + + /* * The generic CPU struct: */ @@ -308,9 +298,15 @@ /* Pointer back to the machine this CPU is in: */ struct machine *machine; + /* Settings: */ + struct settings *settings; + /* CPU-specific name, e.g. "R2000", "21164PC", etc. */ char *name; + /* Full "path" to the CPU, e.g. "emul[0].machine[0].cpu[0]": */ + char *path; + /* EMUL_LITTLE_ENDIAN or EMUL_BIG_ENDIAN. */ int byte_order; @@ -357,8 +353,13 @@ * If is_halted is true when an interrupt trap occurs, the pointer * to the next instruction to execute will be the instruction * following the halt instruction, not the halt instrucion itself. + * + * If has_been_idling is true when printing the number of executed + * instructions per second, "idling" is printed instead. (The number + * of instrs per second when idling is meaningless anyway.) */ int is_halted; + int has_been_idling; /* * Dynamic translation: @@ -372,14 +373,25 @@ * Note that it can also be adjusted negatively, that is, the way * to "get out" of a dyntrans loop is to set the current instruction * call pointer to the "nothing" instruction. This instruction - * _decreases_ n_translated_instrs. That way, once the dyntrans loop - * exits, only real instructions will be counted, and not the + * _decreases_ n_translated_instrs by 1. That way, once the dyntrans + * loop exits, only real instructions will be counted, and not the * "nothing" instructions. + * + * The translation cache is a relative large chunk of memory (say, + * 32 MB) which is used for translations. When it has been used up, + * everything restarts from scratch. + * + * The INR struct contains the Intermediate Native Representation, + * used during native code generation. */ int n_translated_instrs; unsigned char *translation_cache; size_t translation_cache_cur_ofs; +#ifdef NATIVE_CODE_GENERATION + struct inr inr; +#endif + /* * CPU-family dependent: * @@ -390,16 +402,11 @@ struct alpha_cpu alpha; struct arm_cpu arm; struct avr_cpu avr; - struct hppa_cpu hppa; - struct i960_cpu i960; - struct ia64_cpu ia64; - struct m68k_cpu m68k; + struct m88k_cpu m88k; struct mips_cpu mips; struct ppc_cpu ppc; struct sh_cpu sh; struct sparc_cpu sparc; - struct transputer_cpu transputer; - struct x86_cpu x86; } cd; }; @@ -407,24 +414,26 @@ /* cpu.c: */ struct cpu *cpu_new(struct memory *mem, struct machine *machine, int cpu_id, char *cpu_type_name); +void cpu_destroy(struct cpu *cpu); + 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); void cpu_register_dump(struct machine *m, struct cpu *cpu, int gprs, int coprocs); int cpu_disassemble_instr(struct machine *m, struct cpu *cpu, unsigned char *instr, int running, uint64_t addr); -char *cpu_gdb_stub(struct cpu *cpu, char *cmd); -int cpu_interrupt(struct cpu *cpu, uint64_t irq_nr); -int cpu_interrupt_ack(struct cpu *cpu, uint64_t irq_nr); + void cpu_functioncall_trace(struct cpu *cpu, uint64_t f); void cpu_functioncall_trace_return(struct cpu *cpu); + void cpu_create_or_reset_tc(struct cpu *cpu); + void cpu_run_init(struct machine *machine); void cpu_run_deinit(struct machine *machine); + void cpu_dumpinfo(struct machine *m, struct cpu *cpu); void cpu_list_available_types(void); void cpu_show_cycles(struct machine *machine, int forced); + struct cpu_family *cpu_family_ptr_by_number(int arch); void cpu_init(void); @@ -436,20 +445,33 @@ #define INVALIDATE_VADDR_UPPER4 16 /* useful for PPC emulation */ +/* Note: 64-bit processors running in 32-bit mode use a 32-bit + display format, even though the underlying data is 64-bits. */ +#define CPU_SETTINGS_ADD_REGISTER64(name, var) \ + settings_add(cpu->settings, name, 1, SETTINGS_TYPE_UINT64, \ + cpu->is_32bit? SETTINGS_FORMAT_HEX32 : SETTINGS_FORMAT_HEX64, \ + (void *) &(var)); +#define CPU_SETTINGS_ADD_REGISTER32(name, var) \ + settings_add(cpu->settings, name, 1, SETTINGS_TYPE_UINT32, \ + SETTINGS_FORMAT_HEX32, (void *) &(var)); +#define CPU_SETTINGS_ADD_REGISTER16(name, var) \ + settings_add(cpu->settings, name, 1, SETTINGS_TYPE_UINT16, \ + SETTINGS_FORMAT_HEX16, (void *) &(var)); +#define CPU_SETTINGS_ADD_REGISTER8(name, var) \ + settings_add(cpu->settings, name, 1, SETTINGS_TYPE_UINT8, \ + SETTINGS_FORMAT_HEX8, (void *) &(var)); + + #define CPU_FAMILY_INIT(n,s) int n ## _cpu_family_init( \ struct cpu_family *fp) { \ /* Fill in the cpu_family struct with valid data for this arch. */ \ fp->name = s; \ fp->cpu_new = n ## _cpu_new; \ fp->list_available_types = n ## _cpu_list_available_types; \ - fp->register_match = n ## _cpu_register_match; \ fp->disassemble_instr = n ## _cpu_disassemble_instr; \ fp->register_dump = n ## _cpu_register_dump; \ fp->dumpinfo = n ## _cpu_dumpinfo; \ - fp->interrupt = n ## _cpu_interrupt; \ - fp->interrupt_ack = n ## _cpu_interrupt_ack; \ fp->functioncall_trace = n ## _cpu_functioncall_trace; \ - fp->gdb_stub = n ## _cpu_gdb_stub; \ fp->tlbdump = n ## _cpu_tlbdump; \ fp->init_tables = n ## _cpu_init_tables; \ return 1; \