~jderose/ubuntu/raring/qemu/vde-again

« back to all changes in this revision

Viewing changes to hw/ppc.c

  • Committer: Bazaar Package Importer
  • Author(s): Aurelien Jarno, Aurelien Jarno
  • Date: 2009-03-07 06:20:34 UTC
  • mfrom: (1.1.9 upstream)
  • mto: This revision was merged to the branch mainline in revision 7.
  • Revision ID: james.westby@ubuntu.com-20090307062034-i3pead4mw653v2el
Tags: 0.10.0-1
[ Aurelien Jarno ]
* New upstream release:
  - Fix fr-be keyboard mapping (closes: bug#514462).
  - Fix stat64 structure on ppc-linux-user (closes: bug#470231).
  - Add a chroot option (closes: bug#415996).
  - Add evdev support (closes: bug#513210).
  - Fix loop on symlinks in user mode (closes: bug#297572).
  - Bump depends on openbios-sparc.
  - Depends on openbios-ppc.
  - Update 12_signal_powerpc_support.patch.
  - Update 21_net_soopts.patch.
  - Drop 44_socklen_t_check.patch (merged upstream).
  - Drop 49_null_check.patch (merged upstream).
  - Update 64_ppc_asm_constraints.patch.
  - Drop security/CVE-2008-0928-fedora.patch (merged upstream).
  - Drop security/CVE-2007-5730.patch (merged upstream).
* patches/80_stable-branch.patch: add patches from stable branch:
  - Fix race condition between signal handler/execution loop (closes:
    bug#474386, bug#501731).
* debian/copyright: update.
* Compile and install .dtb files:
  - debian/control: build-depends on device-tree-compiler.
  - debian/patches/81_compile_dtb.patch: new patch from upstream.
  - debian/rules: compile and install bamboo.dtb and mpc8544.dtb.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
#include "qemu-timer.h"
27
27
#include "sysemu.h"
28
28
#include "nvram.h"
 
29
#include "qemu-log.h"
29
30
 
30
31
//#define PPC_DEBUG_IRQ
31
32
//#define PPC_DEBUG_TB
32
33
 
33
 
extern FILE *logfile;
34
 
extern int loglevel;
 
34
#ifdef PPC_DEBUG_IRQ
 
35
#  define LOG_IRQ(...) qemu_log_mask(CPU_LOG_INT, ## __VA_ARGS__)
 
36
#else
 
37
#  define LOG_IRQ(...) do { } while (0)
 
38
#endif
 
39
 
 
40
 
 
41
#ifdef PPC_DEBUG_TB
 
42
#  define LOG_TB(...) qemu_log(__VA_ARGS__)
 
43
#else
 
44
#  define LOG_TB(...) do { } while (0)
 
45
#endif
35
46
 
36
47
static void cpu_ppc_tb_stop (CPUState *env);
37
48
static void cpu_ppc_tb_start (CPUState *env);
46
57
        if (env->pending_interrupts == 0)
47
58
            cpu_reset_interrupt(env, CPU_INTERRUPT_HARD);
48
59
    }
49
 
#if defined(PPC_DEBUG_IRQ)
50
 
    if (loglevel & CPU_LOG_INT) {
51
 
        fprintf(logfile, "%s: %p n_IRQ %d level %d => pending %08" PRIx32
 
60
    LOG_IRQ("%s: %p n_IRQ %d level %d => pending %08" PRIx32
52
61
                "req %08x\n", __func__, env, n_IRQ, level,
53
62
                env->pending_interrupts, env->interrupt_request);
54
 
    }
55
 
#endif
56
63
}
57
64
 
58
65
/* PowerPC 6xx / 7xx internal IRQ controller */
61
68
    CPUState *env = opaque;
62
69
    int cur_level;
63
70
 
64
 
#if defined(PPC_DEBUG_IRQ)
65
 
    if (loglevel & CPU_LOG_INT) {
66
 
        fprintf(logfile, "%s: env %p pin %d level %d\n", __func__,
 
71
    LOG_IRQ("%s: env %p pin %d level %d\n", __func__,
67
72
                env, pin, level);
68
 
    }
69
 
#endif
70
73
    cur_level = (env->irq_input_state >> pin) & 1;
71
74
    /* Don't generate spurious events */
72
75
    if ((cur_level == 1 && level == 0) || (cur_level == 0 && level != 0)) {
73
76
        switch (pin) {
74
77
        case PPC6xx_INPUT_TBEN:
75
78
            /* Level sensitive - active high */
76
 
#if defined(PPC_DEBUG_IRQ)
77
 
            if (loglevel & CPU_LOG_INT) {
78
 
                fprintf(logfile, "%s: %s the time base\n",
 
79
            LOG_IRQ("%s: %s the time base\n",
79
80
                        __func__, level ? "start" : "stop");
80
 
            }
81
 
#endif
82
81
            if (level) {
83
82
                cpu_ppc_tb_start(env);
84
83
            } else {
86
85
            }
87
86
        case PPC6xx_INPUT_INT:
88
87
            /* Level sensitive - active high */
89
 
#if defined(PPC_DEBUG_IRQ)
90
 
            if (loglevel & CPU_LOG_INT) {
91
 
                fprintf(logfile, "%s: set the external IRQ state to %d\n",
 
88
            LOG_IRQ("%s: set the external IRQ state to %d\n",
92
89
                        __func__, level);
93
 
            }
94
 
#endif
95
90
            ppc_set_irq(env, PPC_INTERRUPT_EXT, level);
96
91
            break;
97
92
        case PPC6xx_INPUT_SMI:
98
93
            /* Level sensitive - active high */
99
 
#if defined(PPC_DEBUG_IRQ)
100
 
            if (loglevel & CPU_LOG_INT) {
101
 
                fprintf(logfile, "%s: set the SMI IRQ state to %d\n",
 
94
            LOG_IRQ("%s: set the SMI IRQ state to %d\n",
102
95
                        __func__, level);
103
 
            }
104
 
#endif
105
96
            ppc_set_irq(env, PPC_INTERRUPT_SMI, level);
106
97
            break;
107
98
        case PPC6xx_INPUT_MCP:
110
101
             *            603/604/740/750: check HID0[EMCP]
111
102
             */
112
103
            if (cur_level == 1 && level == 0) {
113
 
#if defined(PPC_DEBUG_IRQ)
114
 
                if (loglevel & CPU_LOG_INT) {
115
 
                    fprintf(logfile, "%s: raise machine check state\n",
 
104
                LOG_IRQ("%s: raise machine check state\n",
116
105
                            __func__);
117
 
                }
118
 
#endif
119
106
                ppc_set_irq(env, PPC_INTERRUPT_MCK, 1);
120
107
            }
121
108
            break;
124
111
            /* XXX: TODO: relay the signal to CKSTP_OUT pin */
125
112
            /* XXX: Note that the only way to restart the CPU is to reset it */
126
113
            if (level) {
127
 
#if defined(PPC_DEBUG_IRQ)
128
 
                if (loglevel & CPU_LOG_INT) {
129
 
                    fprintf(logfile, "%s: stop the CPU\n", __func__);
130
 
                }
131
 
#endif
 
114
                LOG_IRQ("%s: stop the CPU\n", __func__);
132
115
                env->halted = 1;
133
116
            }
134
117
            break;
135
118
        case PPC6xx_INPUT_HRESET:
136
119
            /* Level sensitive - active low */
137
120
            if (level) {
138
 
#if defined(PPC_DEBUG_IRQ)
139
 
                if (loglevel & CPU_LOG_INT) {
140
 
                    fprintf(logfile, "%s: reset the CPU\n", __func__);
141
 
                }
142
 
#endif
 
121
                LOG_IRQ("%s: reset the CPU\n", __func__);
143
122
                env->interrupt_request |= CPU_INTERRUPT_EXITTB;
144
123
                /* XXX: TOFIX */
145
124
#if 0
150
129
            }
151
130
            break;
152
131
        case PPC6xx_INPUT_SRESET:
153
 
#if defined(PPC_DEBUG_IRQ)
154
 
            if (loglevel & CPU_LOG_INT) {
155
 
                fprintf(logfile, "%s: set the RESET IRQ state to %d\n",
 
132
            LOG_IRQ("%s: set the RESET IRQ state to %d\n",
156
133
                        __func__, level);
157
 
            }
158
 
#endif
159
134
            ppc_set_irq(env, PPC_INTERRUPT_RESET, level);
160
135
            break;
161
136
        default:
162
137
            /* Unknown pin - do nothing */
163
 
#if defined(PPC_DEBUG_IRQ)
164
 
            if (loglevel & CPU_LOG_INT) {
165
 
                fprintf(logfile, "%s: unknown IRQ pin %d\n", __func__, pin);
166
 
            }
167
 
#endif
 
138
            LOG_IRQ("%s: unknown IRQ pin %d\n", __func__, pin);
168
139
            return;
169
140
        }
170
141
        if (level)
187
158
    CPUState *env = opaque;
188
159
    int cur_level;
189
160
 
190
 
#if defined(PPC_DEBUG_IRQ)
191
 
    if (loglevel & CPU_LOG_INT) {
192
 
        fprintf(logfile, "%s: env %p pin %d level %d\n", __func__,
 
161
    LOG_IRQ("%s: env %p pin %d level %d\n", __func__,
193
162
                env, pin, level);
194
 
    }
195
 
#endif
196
163
    cur_level = (env->irq_input_state >> pin) & 1;
197
164
    /* Don't generate spurious events */
198
165
    if ((cur_level == 1 && level == 0) || (cur_level == 0 && level != 0)) {
199
166
        switch (pin) {
200
167
        case PPC970_INPUT_INT:
201
168
            /* Level sensitive - active high */
202
 
#if defined(PPC_DEBUG_IRQ)
203
 
            if (loglevel & CPU_LOG_INT) {
204
 
                fprintf(logfile, "%s: set the external IRQ state to %d\n",
 
169
            LOG_IRQ("%s: set the external IRQ state to %d\n",
205
170
                        __func__, level);
206
 
            }
207
 
#endif
208
171
            ppc_set_irq(env, PPC_INTERRUPT_EXT, level);
209
172
            break;
210
173
        case PPC970_INPUT_THINT:
211
174
            /* Level sensitive - active high */
212
 
#if defined(PPC_DEBUG_IRQ)
213
 
            if (loglevel & CPU_LOG_INT) {
214
 
                fprintf(logfile, "%s: set the SMI IRQ state to %d\n", __func__,
 
175
            LOG_IRQ("%s: set the SMI IRQ state to %d\n", __func__,
215
176
                        level);
216
 
            }
217
 
#endif
218
177
            ppc_set_irq(env, PPC_INTERRUPT_THERM, level);
219
178
            break;
220
179
        case PPC970_INPUT_MCP:
223
182
             *            603/604/740/750: check HID0[EMCP]
224
183
             */
225
184
            if (cur_level == 1 && level == 0) {
226
 
#if defined(PPC_DEBUG_IRQ)
227
 
                if (loglevel & CPU_LOG_INT) {
228
 
                    fprintf(logfile, "%s: raise machine check state\n",
 
185
                LOG_IRQ("%s: raise machine check state\n",
229
186
                            __func__);
230
 
                }
231
 
#endif
232
187
                ppc_set_irq(env, PPC_INTERRUPT_MCK, 1);
233
188
            }
234
189
            break;
236
191
            /* Level sensitive - active low */
237
192
            /* XXX: TODO: relay the signal to CKSTP_OUT pin */
238
193
            if (level) {
239
 
#if defined(PPC_DEBUG_IRQ)
240
 
                if (loglevel & CPU_LOG_INT) {
241
 
                    fprintf(logfile, "%s: stop the CPU\n", __func__);
242
 
                }
243
 
#endif
 
194
                LOG_IRQ("%s: stop the CPU\n", __func__);
244
195
                env->halted = 1;
245
196
            } else {
246
 
#if defined(PPC_DEBUG_IRQ)
247
 
                if (loglevel & CPU_LOG_INT) {
248
 
                    fprintf(logfile, "%s: restart the CPU\n", __func__);
249
 
                }
250
 
#endif
 
197
                LOG_IRQ("%s: restart the CPU\n", __func__);
251
198
                env->halted = 0;
252
199
            }
253
200
            break;
255
202
            /* Level sensitive - active low */
256
203
            if (level) {
257
204
#if 0 // XXX: TOFIX
258
 
#if defined(PPC_DEBUG_IRQ)
259
 
                if (loglevel & CPU_LOG_INT) {
260
 
                    fprintf(logfile, "%s: reset the CPU\n", __func__);
261
 
                }
262
 
#endif
 
205
                LOG_IRQ("%s: reset the CPU\n", __func__);
263
206
                cpu_reset(env);
264
207
#endif
265
208
            }
266
209
            break;
267
210
        case PPC970_INPUT_SRESET:
268
 
#if defined(PPC_DEBUG_IRQ)
269
 
            if (loglevel & CPU_LOG_INT) {
270
 
                fprintf(logfile, "%s: set the RESET IRQ state to %d\n",
 
211
            LOG_IRQ("%s: set the RESET IRQ state to %d\n",
271
212
                        __func__, level);
272
 
            }
273
 
#endif
274
213
            ppc_set_irq(env, PPC_INTERRUPT_RESET, level);
275
214
            break;
276
215
        case PPC970_INPUT_TBEN:
277
 
#if defined(PPC_DEBUG_IRQ)
278
 
            if (loglevel & CPU_LOG_INT) {
279
 
                fprintf(logfile, "%s: set the TBEN state to %d\n", __func__,
 
216
            LOG_IRQ("%s: set the TBEN state to %d\n", __func__,
280
217
                        level);
281
 
            }
282
 
#endif
283
218
            /* XXX: TODO */
284
219
            break;
285
220
        default:
286
221
            /* Unknown pin - do nothing */
287
 
#if defined(PPC_DEBUG_IRQ)
288
 
            if (loglevel & CPU_LOG_INT) {
289
 
                fprintf(logfile, "%s: unknown IRQ pin %d\n", __func__, pin);
290
 
            }
291
 
#endif
 
222
            LOG_IRQ("%s: unknown IRQ pin %d\n", __func__, pin);
292
223
            return;
293
224
        }
294
225
        if (level)
311
242
    CPUState *env = opaque;
312
243
    int cur_level;
313
244
 
314
 
#if defined(PPC_DEBUG_IRQ)
315
 
    if (loglevel & CPU_LOG_INT) {
316
 
        fprintf(logfile, "%s: env %p pin %d level %d\n", __func__,
 
245
    LOG_IRQ("%s: env %p pin %d level %d\n", __func__,
317
246
                env, pin, level);
318
 
    }
319
 
#endif
320
247
    cur_level = (env->irq_input_state >> pin) & 1;
321
248
    /* Don't generate spurious events */
322
249
    if ((cur_level == 1 && level == 0) || (cur_level == 0 && level != 0)) {
323
250
        switch (pin) {
324
251
        case PPC40x_INPUT_RESET_SYS:
325
252
            if (level) {
326
 
#if defined(PPC_DEBUG_IRQ)
327
 
                if (loglevel & CPU_LOG_INT) {
328
 
                    fprintf(logfile, "%s: reset the PowerPC system\n",
 
253
                LOG_IRQ("%s: reset the PowerPC system\n",
329
254
                            __func__);
330
 
                }
331
 
#endif
332
255
                ppc40x_system_reset(env);
333
256
            }
334
257
            break;
335
258
        case PPC40x_INPUT_RESET_CHIP:
336
259
            if (level) {
337
 
#if defined(PPC_DEBUG_IRQ)
338
 
                if (loglevel & CPU_LOG_INT) {
339
 
                    fprintf(logfile, "%s: reset the PowerPC chip\n", __func__);
340
 
                }
341
 
#endif
 
260
                LOG_IRQ("%s: reset the PowerPC chip\n", __func__);
342
261
                ppc40x_chip_reset(env);
343
262
            }
344
263
            break;
345
264
        case PPC40x_INPUT_RESET_CORE:
346
265
            /* XXX: TODO: update DBSR[MRR] */
347
266
            if (level) {
348
 
#if defined(PPC_DEBUG_IRQ)
349
 
                if (loglevel & CPU_LOG_INT) {
350
 
                    fprintf(logfile, "%s: reset the PowerPC core\n", __func__);
351
 
                }
352
 
#endif
 
267
                LOG_IRQ("%s: reset the PowerPC core\n", __func__);
353
268
                ppc40x_core_reset(env);
354
269
            }
355
270
            break;
356
271
        case PPC40x_INPUT_CINT:
357
272
            /* Level sensitive - active high */
358
 
#if defined(PPC_DEBUG_IRQ)
359
 
            if (loglevel & CPU_LOG_INT) {
360
 
                fprintf(logfile, "%s: set the critical IRQ state to %d\n",
 
273
            LOG_IRQ("%s: set the critical IRQ state to %d\n",
361
274
                        __func__, level);
362
 
            }
363
 
#endif
364
275
            ppc_set_irq(env, PPC_INTERRUPT_CEXT, level);
365
276
            break;
366
277
        case PPC40x_INPUT_INT:
367
278
            /* Level sensitive - active high */
368
 
#if defined(PPC_DEBUG_IRQ)
369
 
            if (loglevel & CPU_LOG_INT) {
370
 
                fprintf(logfile, "%s: set the external IRQ state to %d\n",
 
279
            LOG_IRQ("%s: set the external IRQ state to %d\n",
371
280
                        __func__, level);
372
 
            }
373
 
#endif
374
281
            ppc_set_irq(env, PPC_INTERRUPT_EXT, level);
375
282
            break;
376
283
        case PPC40x_INPUT_HALT:
377
284
            /* Level sensitive - active low */
378
285
            if (level) {
379
 
#if defined(PPC_DEBUG_IRQ)
380
 
                if (loglevel & CPU_LOG_INT) {
381
 
                    fprintf(logfile, "%s: stop the CPU\n", __func__);
382
 
                }
383
 
#endif
 
286
                LOG_IRQ("%s: stop the CPU\n", __func__);
384
287
                env->halted = 1;
385
288
            } else {
386
 
#if defined(PPC_DEBUG_IRQ)
387
 
                if (loglevel & CPU_LOG_INT) {
388
 
                    fprintf(logfile, "%s: restart the CPU\n", __func__);
389
 
                }
390
 
#endif
 
289
                LOG_IRQ("%s: restart the CPU\n", __func__);
391
290
                env->halted = 0;
392
291
            }
393
292
            break;
394
293
        case PPC40x_INPUT_DEBUG:
395
294
            /* Level sensitive - active high */
396
 
#if defined(PPC_DEBUG_IRQ)
397
 
            if (loglevel & CPU_LOG_INT) {
398
 
                fprintf(logfile, "%s: set the debug pin state to %d\n",
 
295
            LOG_IRQ("%s: set the debug pin state to %d\n",
399
296
                        __func__, level);
400
 
            }
401
 
#endif
402
297
            ppc_set_irq(env, PPC_INTERRUPT_DEBUG, level);
403
298
            break;
404
299
        default:
405
300
            /* Unknown pin - do nothing */
406
 
#if defined(PPC_DEBUG_IRQ)
407
 
            if (loglevel & CPU_LOG_INT) {
408
 
                fprintf(logfile, "%s: unknown IRQ pin %d\n", __func__, pin);
409
 
            }
410
 
#endif
 
301
            LOG_IRQ("%s: unknown IRQ pin %d\n", __func__, pin);
411
302
            return;
412
303
        }
413
304
        if (level)
423
314
                                                  env, PPC40x_INPUT_NB);
424
315
}
425
316
 
 
317
/* PowerPC E500 internal IRQ controller */
 
318
static void ppce500_set_irq (void *opaque, int pin, int level)
 
319
{
 
320
    CPUState *env = opaque;
 
321
    int cur_level;
 
322
 
 
323
    LOG_IRQ("%s: env %p pin %d level %d\n", __func__,
 
324
                env, pin, level);
 
325
    cur_level = (env->irq_input_state >> pin) & 1;
 
326
    /* Don't generate spurious events */
 
327
    if ((cur_level == 1 && level == 0) || (cur_level == 0 && level != 0)) {
 
328
        switch (pin) {
 
329
        case PPCE500_INPUT_MCK:
 
330
            if (level) {
 
331
                LOG_IRQ("%s: reset the PowerPC system\n",
 
332
                            __func__);
 
333
                qemu_system_reset_request();
 
334
            }
 
335
            break;
 
336
        case PPCE500_INPUT_RESET_CORE:
 
337
            if (level) {
 
338
                LOG_IRQ("%s: reset the PowerPC core\n", __func__);
 
339
                ppc_set_irq(env, PPC_INTERRUPT_MCK, level);
 
340
            }
 
341
            break;
 
342
        case PPCE500_INPUT_CINT:
 
343
            /* Level sensitive - active high */
 
344
            LOG_IRQ("%s: set the critical IRQ state to %d\n",
 
345
                        __func__, level);
 
346
            ppc_set_irq(env, PPC_INTERRUPT_CEXT, level);
 
347
            break;
 
348
        case PPCE500_INPUT_INT:
 
349
            /* Level sensitive - active high */
 
350
            LOG_IRQ("%s: set the core IRQ state to %d\n",
 
351
                        __func__, level);
 
352
            ppc_set_irq(env, PPC_INTERRUPT_EXT, level);
 
353
            break;
 
354
        case PPCE500_INPUT_DEBUG:
 
355
            /* Level sensitive - active high */
 
356
            LOG_IRQ("%s: set the debug pin state to %d\n",
 
357
                        __func__, level);
 
358
            ppc_set_irq(env, PPC_INTERRUPT_DEBUG, level);
 
359
            break;
 
360
        default:
 
361
            /* Unknown pin - do nothing */
 
362
            LOG_IRQ("%s: unknown IRQ pin %d\n", __func__, pin);
 
363
            return;
 
364
        }
 
365
        if (level)
 
366
            env->irq_input_state |= 1 << pin;
 
367
        else
 
368
            env->irq_input_state &= ~(1 << pin);
 
369
    }
 
370
}
 
371
 
 
372
void ppce500_irq_init (CPUState *env)
 
373
{
 
374
    env->irq_inputs = (void **)qemu_allocate_irqs(&ppce500_set_irq,
 
375
                                        env, PPCE500_INPUT_NB);
 
376
}
426
377
/*****************************************************************************/
427
378
/* PowerPC time base and decrementer emulation */
428
379
struct ppc_tb_t {
455
406
    uint64_t tb;
456
407
 
457
408
    tb = cpu_ppc_get_tb(tb_env, qemu_get_clock(vm_clock), tb_env->tb_offset);
458
 
#if defined(PPC_DEBUG_TB)
459
 
    if (loglevel != 0) {
460
 
        fprintf(logfile, "%s: tb %016" PRIx64 "\n", __func__, tb);
461
 
    }
462
 
#endif
 
409
    LOG_TB("%s: tb %016" PRIx64 "\n", __func__, tb);
463
410
 
464
411
    return tb & 0xFFFFFFFF;
465
412
}
470
417
    uint64_t tb;
471
418
 
472
419
    tb = cpu_ppc_get_tb(tb_env, qemu_get_clock(vm_clock), tb_env->tb_offset);
473
 
#if defined(PPC_DEBUG_TB)
474
 
    if (loglevel != 0) {
475
 
        fprintf(logfile, "%s: tb %016" PRIx64 "\n", __func__, tb);
476
 
    }
477
 
#endif
 
420
    LOG_TB("%s: tb %016" PRIx64 "\n", __func__, tb);
478
421
 
479
422
    return tb >> 32;
480
423
}
489
432
                                            uint64_t value)
490
433
{
491
434
    *tb_offsetp = value - muldiv64(vmclk, tb_env->tb_freq, ticks_per_sec);
492
 
#ifdef PPC_DEBUG_TB
493
 
    if (loglevel != 0) {
494
 
        fprintf(logfile, "%s: tb %016" PRIx64 " offset %08" PRIx64 "\n",
 
435
    LOG_TB("%s: tb %016" PRIx64 " offset %08" PRIx64 "\n",
495
436
                __func__, value, *tb_offsetp);
496
 
    }
497
 
#endif
498
437
}
499
438
 
500
439
void cpu_ppc_store_tbl (CPUState *env, uint32_t value)
530
469
    uint64_t tb;
531
470
 
532
471
    tb = cpu_ppc_get_tb(tb_env, qemu_get_clock(vm_clock), tb_env->atb_offset);
533
 
#if defined(PPC_DEBUG_TB)
534
 
    if (loglevel != 0) {
535
 
        fprintf(logfile, "%s: tb %016" PRIx64 "\n", __func__, tb);
536
 
    }
537
 
#endif
 
472
    LOG_TB("%s: tb %016" PRIx64 "\n", __func__, tb);
538
473
 
539
474
    return tb & 0xFFFFFFFF;
540
475
}
545
480
    uint64_t tb;
546
481
 
547
482
    tb = cpu_ppc_get_tb(tb_env, qemu_get_clock(vm_clock), tb_env->atb_offset);
548
 
#if defined(PPC_DEBUG_TB)
549
 
    if (loglevel != 0) {
550
 
        fprintf(logfile, "%s: tb %016" PRIx64 "\n", __func__, tb);
551
 
    }
552
 
#endif
 
483
    LOG_TB("%s: tb %016" PRIx64 "\n", __func__, tb);
553
484
 
554
485
    return tb >> 32;
555
486
}
631
562
        decr = muldiv64(diff, tb_env->decr_freq, ticks_per_sec);
632
563
    else
633
564
        decr = -muldiv64(-diff, tb_env->decr_freq, ticks_per_sec);
634
 
#if defined(PPC_DEBUG_TB)
635
 
    if (loglevel != 0) {
636
 
        fprintf(logfile, "%s: %08" PRIx32 "\n", __func__, decr);
637
 
    }
638
 
#endif
 
565
    LOG_TB("%s: %08" PRIx32 "\n", __func__, decr);
639
566
 
640
567
    return decr;
641
568
}
670
597
static always_inline void cpu_ppc_decr_excp (CPUState *env)
671
598
{
672
599
    /* Raise it */
673
 
#ifdef PPC_DEBUG_TB
674
 
    if (loglevel != 0) {
675
 
        fprintf(logfile, "raise decrementer exception\n");
676
 
    }
677
 
#endif
 
600
    LOG_TB("raise decrementer exception\n");
678
601
    ppc_set_irq(env, PPC_INTERRUPT_DECR, 1);
679
602
}
680
603
 
681
604
static always_inline void cpu_ppc_hdecr_excp (CPUState *env)
682
605
{
683
606
    /* Raise it */
684
 
#ifdef PPC_DEBUG_TB
685
 
    if (loglevel != 0) {
686
 
        fprintf(logfile, "raise decrementer exception\n");
687
 
    }
688
 
#endif
 
607
    LOG_TB("raise decrementer exception\n");
689
608
    ppc_set_irq(env, PPC_INTERRUPT_HDECR, 1);
690
609
}
691
610
 
698
617
    ppc_tb_t *tb_env = env->tb_env;
699
618
    uint64_t now, next;
700
619
 
701
 
#ifdef PPC_DEBUG_TB
702
 
    if (loglevel != 0) {
703
 
        fprintf(logfile, "%s: %08" PRIx32 " => %08" PRIx32 "\n", __func__,
 
620
    LOG_TB("%s: %08" PRIx32 " => %08" PRIx32 "\n", __func__,
704
621
                decr, value);
705
 
    }
706
 
#endif
707
622
    now = qemu_get_clock(vm_clock);
708
623
    next = now + muldiv64(value, ticks_per_sec, tb_env->decr_freq);
709
624
    if (is_excp)
790
705
    ppc_tb_t *tb_env;
791
706
 
792
707
    tb_env = qemu_mallocz(sizeof(ppc_tb_t));
793
 
    if (tb_env == NULL)
794
 
        return NULL;
795
708
    env->tb_env = tb_env;
796
709
    /* Create new timer */
797
710
    tb_env->decr_timer = qemu_new_timer(vm_clock, &cpu_ppc_decr_cb, env);
808
721
}
809
722
 
810
723
/* Specific helpers for POWER & PowerPC 601 RTC */
811
 
clk_setup_cb cpu_ppc601_rtc_init (CPUState *env)
 
724
#if 0
 
725
static clk_setup_cb cpu_ppc601_rtc_init (CPUState *env)
812
726
{
813
727
    return cpu_ppc_tb_init(env, 7812500);
814
728
}
 
729
#endif
815
730
 
816
731
void cpu_ppc601_store_rtcu (CPUState *env, uint32_t value)
817
732
{
882
797
    env->spr[SPR_40x_TSR] |= 1 << 26;
883
798
    if ((env->spr[SPR_40x_TCR] >> 23) & 0x1)
884
799
        ppc_set_irq(env, PPC_INTERRUPT_FIT, 1);
885
 
#ifdef PPC_DEBUG_TB
886
 
    if (loglevel != 0) {
887
 
        fprintf(logfile, "%s: ir %d TCR " ADDRX " TSR " ADDRX "\n", __func__,
 
800
    LOG_TB("%s: ir %d TCR " ADDRX " TSR " ADDRX "\n", __func__,
888
801
                (int)((env->spr[SPR_40x_TCR] >> 23) & 0x1),
889
802
                env->spr[SPR_40x_TCR], env->spr[SPR_40x_TSR]);
890
 
    }
891
 
#endif
892
803
}
893
804
 
894
805
/* Programmable interval timer */
902
813
        !((env->spr[SPR_40x_TCR] >> 26) & 0x1) ||
903
814
        (is_excp && !((env->spr[SPR_40x_TCR] >> 22) & 0x1))) {
904
815
        /* Stop PIT */
905
 
#ifdef PPC_DEBUG_TB
906
 
        if (loglevel != 0) {
907
 
            fprintf(logfile, "%s: stop PIT\n", __func__);
908
 
        }
909
 
#endif
 
816
        LOG_TB("%s: stop PIT\n", __func__);
910
817
        qemu_del_timer(tb_env->decr_timer);
911
818
    } else {
912
 
#ifdef PPC_DEBUG_TB
913
 
        if (loglevel != 0) {
914
 
            fprintf(logfile, "%s: start PIT %016" PRIx64 "\n",
 
819
        LOG_TB("%s: start PIT %016" PRIx64 "\n",
915
820
                    __func__, ppcemb_timer->pit_reload);
916
 
        }
917
 
#endif
918
821
        now = qemu_get_clock(vm_clock);
919
822
        next = now + muldiv64(ppcemb_timer->pit_reload,
920
823
                              ticks_per_sec, tb_env->decr_freq);
940
843
    if ((env->spr[SPR_40x_TCR] >> 26) & 0x1)
941
844
        ppc_set_irq(env, PPC_INTERRUPT_PIT, 1);
942
845
    start_stop_pit(env, tb_env, 1);
943
 
#ifdef PPC_DEBUG_TB
944
 
    if (loglevel != 0) {
945
 
        fprintf(logfile, "%s: ar %d ir %d TCR " ADDRX " TSR " ADDRX " "
 
846
    LOG_TB("%s: ar %d ir %d TCR " ADDRX " TSR " ADDRX " "
946
847
                "%016" PRIx64 "\n", __func__,
947
848
                (int)((env->spr[SPR_40x_TCR] >> 22) & 0x1),
948
849
                (int)((env->spr[SPR_40x_TCR] >> 26) & 0x1),
949
850
                env->spr[SPR_40x_TCR], env->spr[SPR_40x_TSR],
950
851
                ppcemb_timer->pit_reload);
951
 
    }
952
 
#endif
953
852
}
954
853
 
955
854
/* Watchdog timer */
984
883
    next = now + muldiv64(next, ticks_per_sec, tb_env->decr_freq);
985
884
    if (next == now)
986
885
        next++;
987
 
#ifdef PPC_DEBUG_TB
988
 
    if (loglevel != 0) {
989
 
        fprintf(logfile, "%s: TCR " ADDRX " TSR " ADDRX "\n", __func__,
 
886
    LOG_TB("%s: TCR " ADDRX " TSR " ADDRX "\n", __func__,
990
887
                env->spr[SPR_40x_TCR], env->spr[SPR_40x_TSR]);
991
 
    }
992
 
#endif
993
888
    switch ((env->spr[SPR_40x_TSR] >> 30) & 0x3) {
994
889
    case 0x0:
995
890
    case 0x1:
1031
926
 
1032
927
    tb_env = env->tb_env;
1033
928
    ppcemb_timer = tb_env->opaque;
1034
 
#ifdef PPC_DEBUG_TB
1035
 
    if (loglevel != 0) {
1036
 
        fprintf(logfile, "%s val" ADDRX "\n", __func__, val);
1037
 
    }
1038
 
#endif
 
929
    LOG_TB("%s val" ADDRX "\n", __func__, val);
1039
930
    ppcemb_timer->pit_reload = val;
1040
931
    start_stop_pit(env, tb_env, 0);
1041
932
}
1047
938
 
1048
939
void store_booke_tsr (CPUState *env, target_ulong val)
1049
940
{
1050
 
#ifdef PPC_DEBUG_TB
1051
 
    if (loglevel != 0) {
1052
 
        fprintf(logfile, "%s: val " ADDRX "\n", __func__, val);
1053
 
    }
1054
 
#endif
 
941
    LOG_TB("%s: val " ADDRX "\n", __func__, val);
1055
942
    env->spr[SPR_40x_TSR] &= ~(val & 0xFC000000);
1056
943
    if (val & 0x80000000)
1057
944
        ppc_set_irq(env, PPC_INTERRUPT_PIT, 0);
1062
949
    ppc_tb_t *tb_env;
1063
950
 
1064
951
    tb_env = env->tb_env;
1065
 
#ifdef PPC_DEBUG_TB
1066
 
    if (loglevel != 0) {
1067
 
        fprintf(logfile, "%s: val " ADDRX "\n", __func__, val);
1068
 
    }
1069
 
#endif
 
952
    LOG_TB("%s: val " ADDRX "\n", __func__, val);
1070
953
    env->spr[SPR_40x_TCR] = val & 0xFFC00000;
1071
954
    start_stop_pit(env, tb_env, 1);
1072
955
    cpu_4xx_wdt_cb(env);
1077
960
    CPUState *env = opaque;
1078
961
    ppc_tb_t *tb_env = env->tb_env;
1079
962
 
1080
 
#ifdef PPC_DEBUG_TB
1081
 
    if (loglevel != 0) {
1082
 
        fprintf(logfile, "%s set new frequency to %" PRIu32 "\n", __func__,
 
963
    LOG_TB("%s set new frequency to %" PRIu32 "\n", __func__,
1083
964
                freq);
1084
 
    }
1085
 
#endif
1086
965
    tb_env->tb_freq = freq;
1087
966
    tb_env->decr_freq = freq;
1088
967
    /* XXX: we should also update all timers */
1094
973
    ppcemb_timer_t *ppcemb_timer;
1095
974
 
1096
975
    tb_env = qemu_mallocz(sizeof(ppc_tb_t));
1097
 
    if (tb_env == NULL) {
1098
 
        return NULL;
1099
 
    }
1100
976
    env->tb_env = tb_env;
1101
977
    ppcemb_timer = qemu_mallocz(sizeof(ppcemb_timer_t));
1102
978
    tb_env->tb_freq = freq;
1103
979
    tb_env->decr_freq = freq;
1104
980
    tb_env->opaque = ppcemb_timer;
1105
 
#ifdef PPC_DEBUG_TB
1106
 
    if (loglevel != 0) {
1107
 
        fprintf(logfile, "%s freq %" PRIu32 "\n", __func__, freq);
1108
 
    }
1109
 
#endif
 
981
    LOG_TB("%s freq %" PRIu32 "\n", __func__, freq);
1110
982
    if (ppcemb_timer != NULL) {
1111
983
        /* We use decr timer for PIT */
1112
984
        tb_env->decr_timer = qemu_new_timer(vm_clock, &cpu_4xx_pit_cb, env);
1207
1079
    ppc_dcr_t *dcr_env;
1208
1080
 
1209
1081
    dcr_env = qemu_mallocz(sizeof(ppc_dcr_t));
1210
 
    if (dcr_env == NULL)
1211
 
        return -1;
1212
1082
    dcr_env->read_error = read_error;
1213
1083
    dcr_env->write_error = write_error;
1214
1084
    env->dcr_env = dcr_env;
1305
1175
}
1306
1176
 
1307
1177
void NVRAM_set_string (nvram_t *nvram, uint32_t addr,
1308
 
                       const unsigned char *str, uint32_t max)
 
1178
                       const char *str, uint32_t max)
1309
1179
{
1310
1180
    int i;
1311
1181
 
1345
1215
    return tmp;
1346
1216
}
1347
1217
 
1348
 
uint16_t NVRAM_compute_crc (nvram_t *nvram, uint32_t start, uint32_t count)
 
1218
static uint16_t NVRAM_compute_crc (nvram_t *nvram, uint32_t start, uint32_t count)
1349
1219
{
1350
1220
    uint32_t i;
1351
1221
    uint16_t crc = 0xFFFF;
1366
1236
#define CMDLINE_ADDR 0x017ff000
1367
1237
 
1368
1238
int PPC_NVRAM_set_params (nvram_t *nvram, uint16_t NVRAM_size,
1369
 
                          const unsigned char *arch,
 
1239
                          const char *arch,
1370
1240
                          uint32_t RAM_size, int boot_device,
1371
1241
                          uint32_t kernel_image, uint32_t kernel_size,
1372
1242
                          const char *cmdline,
1387
1257
    NVRAM_set_lword(nvram,  0x3C, kernel_size);
1388
1258
    if (cmdline) {
1389
1259
        /* XXX: put the cmdline in NVRAM too ? */
1390
 
        strcpy(phys_ram_base + CMDLINE_ADDR, cmdline);
 
1260
        strcpy((char *)(phys_ram_base + CMDLINE_ADDR), cmdline);
1391
1261
        NVRAM_set_lword(nvram,  0x40, CMDLINE_ADDR);
1392
1262
        NVRAM_set_lword(nvram,  0x44, strlen(cmdline));
1393
1263
    } else {