Statistics
| Branch: | Revision:

root / cpu-defs.h @ d08d3bb8

History | View | Annotate | Download (5.8 kB)

1 ab93bbe2 bellard
/*
2 ab93bbe2 bellard
 * common defines for all CPUs
3 ab93bbe2 bellard
 * 
4 ab93bbe2 bellard
 * Copyright (c) 2003 Fabrice Bellard
5 ab93bbe2 bellard
 *
6 ab93bbe2 bellard
 * This library is free software; you can redistribute it and/or
7 ab93bbe2 bellard
 * modify it under the terms of the GNU Lesser General Public
8 ab93bbe2 bellard
 * License as published by the Free Software Foundation; either
9 ab93bbe2 bellard
 * version 2 of the License, or (at your option) any later version.
10 ab93bbe2 bellard
 *
11 ab93bbe2 bellard
 * This library is distributed in the hope that it will be useful,
12 ab93bbe2 bellard
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ab93bbe2 bellard
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 ab93bbe2 bellard
 * Lesser General Public License for more details.
15 ab93bbe2 bellard
 *
16 ab93bbe2 bellard
 * You should have received a copy of the GNU Lesser General Public
17 ab93bbe2 bellard
 * License along with this library; if not, write to the Free Software
18 ab93bbe2 bellard
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 ab93bbe2 bellard
 */
20 ab93bbe2 bellard
#ifndef CPU_DEFS_H
21 ab93bbe2 bellard
#define CPU_DEFS_H
22 ab93bbe2 bellard
23 ab93bbe2 bellard
#include "config.h"
24 ab93bbe2 bellard
#include <setjmp.h>
25 ed1c0bcb bellard
#include <inttypes.h>
26 ed1c0bcb bellard
#include "osdep.h"
27 ab93bbe2 bellard
28 35b66fc4 bellard
#ifndef TARGET_LONG_BITS
29 35b66fc4 bellard
#error TARGET_LONG_BITS must be defined before including this header
30 35b66fc4 bellard
#endif
31 35b66fc4 bellard
32 ab6d960f bellard
#ifndef TARGET_PHYS_ADDR_BITS 
33 4f2ac237 bellard
#if TARGET_LONG_BITS >= HOST_LONG_BITS
34 ab6d960f bellard
#define TARGET_PHYS_ADDR_BITS TARGET_LONG_BITS
35 4f2ac237 bellard
#else
36 4f2ac237 bellard
#define TARGET_PHYS_ADDR_BITS HOST_LONG_BITS
37 4f2ac237 bellard
#endif
38 ab6d960f bellard
#endif
39 ab6d960f bellard
40 35b66fc4 bellard
#define TARGET_LONG_SIZE (TARGET_LONG_BITS / 8)
41 35b66fc4 bellard
42 ab6d960f bellard
/* target_ulong is the type of a virtual address */
43 35b66fc4 bellard
#if TARGET_LONG_SIZE == 4
44 35b66fc4 bellard
typedef int32_t target_long;
45 35b66fc4 bellard
typedef uint32_t target_ulong;
46 c27004ec bellard
#define TARGET_FMT_lx "%08x"
47 35b66fc4 bellard
#elif TARGET_LONG_SIZE == 8
48 35b66fc4 bellard
typedef int64_t target_long;
49 35b66fc4 bellard
typedef uint64_t target_ulong;
50 26a76461 bellard
#define TARGET_FMT_lx "%016" PRIx64
51 35b66fc4 bellard
#else
52 35b66fc4 bellard
#error TARGET_LONG_SIZE undefined
53 35b66fc4 bellard
#endif
54 35b66fc4 bellard
55 ab6d960f bellard
/* target_phys_addr_t is the type of a physical address (its size can
56 4f2ac237 bellard
   be different from 'target_ulong'). We have sizeof(target_phys_addr)
57 4f2ac237 bellard
   = max(sizeof(unsigned long),
58 4f2ac237 bellard
   sizeof(size_of_target_physical_address)) because we must pass a
59 4f2ac237 bellard
   host pointer to memory operations in some cases */
60 4f2ac237 bellard
61 ab6d960f bellard
#if TARGET_PHYS_ADDR_BITS == 32
62 ab6d960f bellard
typedef uint32_t target_phys_addr_t;
63 ab6d960f bellard
#elif TARGET_PHYS_ADDR_BITS == 64
64 ab6d960f bellard
typedef uint64_t target_phys_addr_t;
65 ab6d960f bellard
#else
66 ab6d960f bellard
#error TARGET_PHYS_ADDR_BITS undefined
67 ab6d960f bellard
#endif
68 ab6d960f bellard
69 ff7b8f5b bellard
/* address in the RAM (different from a physical address) */
70 ff7b8f5b bellard
typedef unsigned long ram_addr_t;
71 ff7b8f5b bellard
72 f193c797 bellard
#define HOST_LONG_SIZE (HOST_LONG_BITS / 8)
73 f193c797 bellard
74 2be0071f bellard
#define EXCP_INTERRUPT         0x10000 /* async interruption */
75 2be0071f bellard
#define EXCP_HLT        0x10001 /* hlt instruction reached */
76 2be0071f bellard
#define EXCP_DEBUG      0x10002 /* cpu stopped after a breakpoint or singlestep */
77 5a1e3cfc bellard
#define EXCP_HALTED     0x10003 /* cpu is halted (waiting for external event) */
78 ab93bbe2 bellard
#define MAX_BREAKPOINTS 32
79 6658ffb8 pbrook
#define MAX_WATCHPOINTS 32
80 ab93bbe2 bellard
81 a316d335 bellard
#define TB_JMP_CACHE_BITS 12
82 a316d335 bellard
#define TB_JMP_CACHE_SIZE (1 << TB_JMP_CACHE_BITS)
83 a316d335 bellard
84 b362e5e0 pbrook
/* Only the bottom TB_JMP_PAGE_BITS of the jump cache hash bits vary for
85 b362e5e0 pbrook
   addresses on the same page.  The top bits are the same.  This allows
86 b362e5e0 pbrook
   TLB invalidation to quickly clear a subset of the hash table.  */
87 b362e5e0 pbrook
#define TB_JMP_PAGE_BITS (TB_JMP_CACHE_BITS / 2)
88 b362e5e0 pbrook
#define TB_JMP_PAGE_SIZE (1 << TB_JMP_PAGE_BITS)
89 b362e5e0 pbrook
#define TB_JMP_ADDR_MASK (TB_JMP_PAGE_SIZE - 1)
90 b362e5e0 pbrook
#define TB_JMP_PAGE_MASK (TB_JMP_CACHE_SIZE - TB_JMP_PAGE_SIZE)
91 b362e5e0 pbrook
92 84b7b8e7 bellard
#define CPU_TLB_BITS 8
93 84b7b8e7 bellard
#define CPU_TLB_SIZE (1 << CPU_TLB_BITS)
94 ab93bbe2 bellard
95 ab93bbe2 bellard
typedef struct CPUTLBEntry {
96 db8d7466 bellard
    /* bit 31 to TARGET_PAGE_BITS : virtual address 
97 db8d7466 bellard
       bit TARGET_PAGE_BITS-1..IO_MEM_SHIFT : if non zero, memory io
98 db8d7466 bellard
                                              zone number
99 db8d7466 bellard
       bit 3                      : indicates that the entry is invalid
100 db8d7466 bellard
       bit 2..0                   : zero
101 db8d7466 bellard
    */
102 84b7b8e7 bellard
    target_ulong addr_read; 
103 84b7b8e7 bellard
    target_ulong addr_write; 
104 84b7b8e7 bellard
    target_ulong addr_code; 
105 db8d7466 bellard
    /* addend to virtual address to get physical address */
106 4f2ac237 bellard
    target_phys_addr_t addend; 
107 ab93bbe2 bellard
} CPUTLBEntry;
108 ab93bbe2 bellard
109 a316d335 bellard
#define CPU_COMMON                                                      \
110 a316d335 bellard
    struct TranslationBlock *current_tb; /* currently executing TB  */  \
111 a316d335 bellard
    /* soft mmu support */                                              \
112 a316d335 bellard
    /* in order to avoid passing too many arguments to the memory       \
113 a316d335 bellard
       write helpers, we store some rarely used information in the CPU  \
114 a316d335 bellard
       context) */                                                      \
115 a316d335 bellard
    unsigned long mem_write_pc; /* host pc at which the memory was      \
116 a316d335 bellard
                                   written */                           \
117 a316d335 bellard
    target_ulong mem_write_vaddr; /* target virtual addr at which the   \
118 a316d335 bellard
                                     memory was written */              \
119 a316d335 bellard
    /* 0 = kernel, 1 = user */                                          \
120 84b7b8e7 bellard
    CPUTLBEntry tlb_table[2][CPU_TLB_SIZE];                             \
121 a316d335 bellard
    struct TranslationBlock *tb_jmp_cache[TB_JMP_CACHE_SIZE];           \
122 a316d335 bellard
                                                                        \
123 a316d335 bellard
    /* from this point: preserved by CPU reset */                       \
124 a316d335 bellard
    /* ice debug support */                                             \
125 a316d335 bellard
    target_ulong breakpoints[MAX_BREAKPOINTS];                          \
126 a316d335 bellard
    int nb_breakpoints;                                                 \
127 a316d335 bellard
    int singlestep_enabled;                                             \
128 a316d335 bellard
                                                                        \
129 6658ffb8 pbrook
    struct {                                                            \
130 6658ffb8 pbrook
        target_ulong vaddr;                                             \
131 6658ffb8 pbrook
        int is_ram;                                                     \
132 6658ffb8 pbrook
    } watchpoint[MAX_WATCHPOINTS];                                      \
133 6658ffb8 pbrook
    int nb_watchpoints;                                                 \
134 6658ffb8 pbrook
    int watchpoint_hit;                                                 \
135 6658ffb8 pbrook
                                                                        \
136 6a00d601 bellard
    void *next_cpu; /* next CPU sharing TB cache */                     \
137 6a00d601 bellard
    int cpu_index; /* CPU index (informative) */                        \
138 a316d335 bellard
    /* user data */                                                     \
139 a316d335 bellard
    void *opaque;
140 a316d335 bellard
141 ab93bbe2 bellard
#endif