Skip to content

Commit

Permalink
Great PowerPC emulation code resynchronisation and improvments:
Browse files Browse the repository at this point in the history
- Add status file to make regression tracking easier
- Move all micro-operations helpers definitions into a separate header:
  should never be seen outside of op.c
- Update copyrights
- Add new / missing PowerPC CPU definitions
- Add definitions for PowerPC BookE
- Add support for PowerPC 6xx/7xx software driven TLBs
  Allow use of PowerPC 603 as an example
- Add preliminary code for POWER, POWER2, PowerPC 403, 405, 440, 601, 602
  and BookE support
- Avoid compiling priviledged only resources support for user-mode emulation
- Remove unused helpers / micro-ops / dead code
- Add instructions usage statistics dump: useful to figure which instructions
  need strong optimizations.
- Micro-operation fixes:
  * add missing RETURN in some micro-ops
  * fix prototypes
  * use softfloat routines for all floating-point operations
  * fix tlbie instruction
  * move some huge micro-operations into helpers
- emulation fixes:
  * fix inverted opcodes for fcmpo / fcmpu
  * condition register update is always to be done after the whole
    instruction has completed
  * add missing NIP updates when calling helpers that may generate an
    exception
- optimizations and improvments:
  * optimize very often used instructions (li, mr, rlwixx...)
  * remove specific micro-ops for rarely used instructions
  * add routines for addresses computations to avoid bugs due to multiple
    different implementations
  * fix TB linking: do not reset T0 at the end of every TB.


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2473 c046a42c-6fe2-441c-8c8c-71466251a162
  • Loading branch information
j_mayer committed Mar 7, 2007
1 parent 1c7b375 commit 76a6625
Show file tree
Hide file tree
Showing 19 changed files with 7,753 additions and 2,678 deletions.
3 changes: 3 additions & 0 deletions cpu-all.h
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,9 @@ CPUState *cpu_copy(CPUState *env);
void cpu_dump_state(CPUState *env, FILE *f,
int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
int flags);
void cpu_dump_statistics (CPUState *env, FILE *f,
int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
int flags);

void cpu_abort(CPUState *env, const char *fmt, ...);
extern CPUState *first_cpu;
Expand Down
4 changes: 2 additions & 2 deletions gdbstub.c
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ static int cpu_gdb_read_registers(CPUState *env, uint8_t *mem_buf)
registers[98] = tswapl(tmp);
registers[99] = tswapl(env->lr);
registers[100] = tswapl(env->ctr);
registers[101] = tswapl(do_load_xer(env));
registers[101] = tswapl(ppc_load_xer(env));
registers[102] = 0;

return 103 * 4;
Expand Down Expand Up @@ -335,7 +335,7 @@ static void cpu_gdb_write_registers(CPUState *env, uint8_t *mem_buf, int size)
env->crf[i] = (registers[98] >> (32 - ((i + 1) * 4))) & 0xF;
env->lr = tswapl(registers[99]);
env->ctr = tswapl(registers[100]);
do_store_xer(env, tswapl(registers[101]));
ppc_store_xer(env, tswapl(registers[101]));
}
#elif defined (TARGET_SPARC)
static int cpu_gdb_read_registers(CPUState *env, uint8_t *mem_buf)
Expand Down
91 changes: 69 additions & 22 deletions hw/ppc.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* QEMU generic PPC hardware System Emulator
*
* Copyright (c) 2003-2004 Jocelyn Mayer
* Copyright (c) 2003-2007 Jocelyn Mayer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -41,7 +41,7 @@ static inline uint64_t cpu_ppc_get_tb (ppc_tb_t *tb_env)
{
/* TB time in tb periods */
return muldiv64(qemu_get_clock(vm_clock) + tb_env->tb_offset,
tb_env->tb_freq, ticks_per_sec);
tb_env->tb_freq, ticks_per_sec);
}

uint32_t cpu_ppc_load_tbl (CPUState *env)
Expand All @@ -52,14 +52,14 @@ uint32_t cpu_ppc_load_tbl (CPUState *env)
tb = cpu_ppc_get_tb(tb_env);
#ifdef DEBUG_TB
{
static int last_time;
int now;
now = time(NULL);
if (last_time != now) {
last_time = now;
printf("%s: tb=0x%016lx %d %08lx\n",
__func__, tb, now, tb_env->tb_offset);
}
static int last_time;
int now;
now = time(NULL);
if (last_time != now) {
last_time = now;
printf("%s: tb=0x%016lx %d %08lx\n",
__func__, tb, now, tb_env->tb_offset);
}
}
#endif

Expand All @@ -75,6 +75,7 @@ uint32_t cpu_ppc_load_tbu (CPUState *env)
#ifdef DEBUG_TB
printf("%s: tb=0x%016lx\n", __func__, tb);
#endif

return tb >> 32;
}

Expand Down Expand Up @@ -117,6 +118,7 @@ uint32_t cpu_ppc_load_decr (CPUState *env)
#if defined(DEBUG_TB)
printf("%s: 0x%08x\n", __func__, decr);
#endif

return decr;
}

Expand Down Expand Up @@ -146,15 +148,15 @@ static void _cpu_ppc_store_decr (CPUState *env, uint32_t decr,
if (is_excp)
next += tb_env->decr_next - now;
if (next == now)
next++;
next++;
tb_env->decr_next = next;
/* Adjust timer */
qemu_mod_timer(tb_env->decr_timer, next);
/* If we set a negative value and the decrementer was positive,
* raise an exception.
*/
if ((value & 0x80000000) && !(decr & 0x80000000))
cpu_ppc_decr_excp(env);
cpu_ppc_decr_excp(env);
}

void cpu_ppc_store_decr (CPUState *env, uint32_t value)
Expand All @@ -177,20 +179,64 @@ ppc_tb_t *cpu_ppc_tb_init (CPUState *env, uint32_t freq)
return NULL;
env->tb_env = tb_env;
if (tb_env->tb_freq == 0 || 1) {
tb_env->tb_freq = freq;
/* Create new timer */
tb_env->decr_timer =
tb_env->tb_freq = freq;
/* Create new timer */
tb_env->decr_timer =
qemu_new_timer(vm_clock, &cpu_ppc_decr_cb, env);
/* There is a bug in 2.4 kernels:
* if a decrementer exception is pending when it enables msr_ee,
* it's not ready to handle it...
*/
_cpu_ppc_store_decr(env, 0xFFFFFFFF, 0xFFFFFFFF, 0);
/* There is a bug in Linux 2.4 kernels:
* if a decrementer exception is pending when it enables msr_ee,
* it's not ready to handle it...
*/
_cpu_ppc_store_decr(env, 0xFFFFFFFF, 0xFFFFFFFF, 0);
}

return tb_env;
}

/* Specific helpers for POWER & PowerPC 601 RTC */
ppc_tb_t *cpu_ppc601_rtc_init (CPUState *env)
{
return cpu_ppc_tb_init(env, 7812500);
}

void cpu_ppc601_store_rtcu (CPUState *env, uint32_t value)
__attribute__ (( alias ("cpu_ppc_store_tbu") ));

uint32_t cpu_ppc601_load_rtcu (CPUState *env)
__attribute__ (( alias ("cpu_ppc_load_tbu") ));

void cpu_ppc601_store_rtcl (CPUState *env, uint32_t value)
{
cpu_ppc_store_tbl(env, value & 0x3FFFFF80);
}

uint32_t cpu_ppc601_load_rtcl (CPUState *env)
{
return cpu_ppc_load_tbl(env) & 0x3FFFFF80;
}

/* Embedded PowerPC timers */
target_ulong load_40x_pit (CPUState *env)
{
/* XXX: TODO */
return 0;
}

void store_40x_pit (CPUState *env, target_ulong val)
{
/* XXX: TODO */
}

void store_booke_tcr (CPUState *env, target_ulong val)
{
/* XXX: TODO */
}

void store_booke_tsr (CPUState *env, target_ulong val)
{
/* XXX: TODO */
}

#if 0
/*****************************************************************************/
/* Handle system reset (for now, just stop emulation) */
Expand Down Expand Up @@ -264,6 +310,7 @@ uint32_t NVRAM_get_lword (m48t59_t *nvram, uint32_t addr)
tmp |= m48t59_read(nvram, addr + 1) << 16;
tmp |= m48t59_read(nvram, addr + 2) << 8;
tmp |= m48t59_read(nvram, addr + 3);

return tmp;
}

Expand Down Expand Up @@ -316,10 +363,10 @@ uint16_t NVRAM_compute_crc (m48t59_t *nvram, uint32_t start, uint32_t count)
odd = count & 1;
count &= ~1;
for (i = 0; i != count; i++) {
crc = NVRAM_crc_update(crc, NVRAM_get_word(nvram, start + i));
crc = NVRAM_crc_update(crc, NVRAM_get_word(nvram, start + i));
}
if (odd) {
crc = NVRAM_crc_update(crc, NVRAM_get_byte(nvram, start + i) << 8);
crc = NVRAM_crc_update(crc, NVRAM_get_byte(nvram, start + i) << 8);
}

return crc;
Expand Down
21 changes: 13 additions & 8 deletions linux-user/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -670,18 +670,23 @@ void cpu_ppc_store_tbl (CPUState *env, uint32_t value)
{
cpu_ppc_store_tb(env, ((uint64_t)cpu_ppc_load_tbl(env) << 32) | value);
}

uint32_t cpu_ppc_load_decr (CPUState *env)

void cpu_ppc601_store_rtcu (CPUState *env, uint32_t value)
__attribute__ (( alias ("cpu_ppc_store_tbu") ));

uint32_t cpu_ppc601_load_rtcu (CPUState *env)
__attribute__ (( alias ("cpu_ppc_load_tbu") ));

void cpu_ppc601_store_rtcl (CPUState *env, uint32_t value)
{
/* TO FIX */
return -1;
cpu_ppc_store_tbl(env, value & 0x3FFFFF80);
}
void cpu_ppc_store_decr (CPUState *env, uint32_t value)

uint32_t cpu_ppc601_load_rtcl (CPUState *env)
{
/* TO FIX */
return cpu_ppc_load_tbl(env) & 0x3FFFFF80;
}

void cpu_loop(CPUPPCState *env)
{
target_siginfo_t info;
Expand Down
15 changes: 15 additions & 0 deletions monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,17 @@ static void do_info_history (void)
}
}

#if defined(TARGET_PPC)
/* XXX: not implemented in other targets */
static void do_info_cpu_stats (void)
{
CPUState *env;

env = mon_get_cpu();
cpu_dump_statistics(env, NULL, &monitor_fprintf, 0);
}
#endif

static void do_quit(void)
{
exit(0);
Expand Down Expand Up @@ -1303,6 +1314,10 @@ static term_cmd_t info_cmds[] = {
"", "show which guest mouse is receiving events" },
{ "vnc", "", do_info_vnc,
"", "show the vnc server status"},
#if defined(TARGET_PPC)
{ "cpustats", "", do_info_cpu_stats,
"", "show CPU statistics", },
#endif
{ NULL, NULL, },
};

Expand Down
91 changes: 91 additions & 0 deletions target-ppc/STATUS
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
PowerPC emulation status.
The goal of this file is to provide a reference status to avoid regressions.

===============================================================================
PowerPC core emulation status

PowerPC CPU known to work (ie booting at least Linux 2.4):
* main stream PowerPC cores
- PowerPC 603 & derivatives
- PowerPC 604 & derivatives
- PowerPC 740 & derivatives
- PowerPC 750 & derivatives

PowerPC that should work but are not supported by standard Linux kernel
(then remain mostly untested)
- PowerPC 745
- PowerPC 755

Work in progress:
* embedded PowerPC cores
- PowerPC 405
- BookE PowerPC
- e500 core (Freescale PowerQUICC)
* main stream PowerPC cores
- PowerPC 601
- PowerPC 602

TODO:
* embedded PowerPC cores
- PowerPC 401
- PowerPC 403
- PowerPC 440
- PowerPC 460
* main stream PowerPC cores
- PowerPC 7400 (aka G4)
- PowerPC 7410
- PowerPC 7450
- PowerPC 7455
- PowerPC 7457
- PowerPC 7457A
* original POWER
- POWER
- POWER2
* 64 bits PowerPC cores
- PowerPC 620
- PowerPC 630 (aka POWER3)
- PowerPC 631 (aka POWER3+)
- POWER4
- POWER4+
- POWER5
- POWER5+
- PowerPC 970
* RS64 series
- RS64
- RS64-II
- RS64-III
- RS64-IV

===============================================================================
PowerPC microcontrollers emulation status

TODO:
- PowerPC 40x microcontrollers emulation
- PowerQUICC microcontrollers emulation

===============================================================================
PowerPC based platforms emulation status

* PREP platform (RS/6000 7043...) - TO BE CHECKED (broken)
- Gentoo Linux live CDROM 1.4
- Debian Linux 3.0
- Mandrake Linux 9

* heathrow PowerMac platform (beige PowerMac) - TO BE CHECKED (broken)
- Gentoo Linux live CDROM 1.4
- Debian Linux 3.0
- Mandrake Linux 9

* mac99 platform (white and blue PowerMac, ...)
- Gentoo Linux live CDROM 1.4 - boots, compiles linux kernel
- Debian Linux woody - boots from CDROM and HDD
- Mandrake Linux 9 - boots from CDROM, freezes during install

TODO:
- MCA based RS/6000 emulation
- CHRP emulation (not PowerMac)
- PPAR emulation
- misc PowerPC reference boards emulation

===============================================================================
(to be completed)
Loading

0 comments on commit 76a6625

Please sign in to comment.