Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1GhLbI-0003jE-A1 for qemu-devel@nongnu.org; Tue, 07 Nov 2006 02:42:28 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1GhLbH-0003gZ-5u for qemu-devel@nongnu.org; Tue, 07 Nov 2006 02:42:27 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GhLbG-0003gA-OC for qemu-devel@nongnu.org; Tue, 07 Nov 2006 02:42:26 -0500 Received: from [194.84.254.251] (helo=mx.globalone.ru) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA:32) (Exim 4.52) id 1GhLbG-00025o-4Y for qemu-devel@nongnu.org; Tue, 07 Nov 2006 02:42:26 -0500 Received: from mx.globalone.ru (localhost [127.0.0.1]) by mx.globalone.ru (8.13.1/8.13.1) with ESMTP id kA77g3VK021797 for ; Tue, 7 Nov 2006 10:42:10 +0300 Received: from smtp.globalone.ru (smtp.globalone.ru [172.16.38.5]) by mx.globalone.ru (8.13.1/8.13.1) with ESMTP id kA77fgvn021743 for ; Tue, 7 Nov 2006 10:41:42 +0300 Received: from voropaya ([172.16.38.7]) by smtp.globalone.ru (Netscape Messaging Server 4.15) with SMTP id J8CO1I00.81D for ; Tue, 7 Nov 2006 10:41:42 +0300 Message-ID: <17de01c70240$303aa260$e90d11ac@spb.in.rosprint.ru> From: "Alexander Voropay" Date: Tue, 7 Nov 2006 10:41:33 +0300 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_17D9_01C70259.4B2CA370" Subject: [Qemu-devel] [PATCH] MIPS timer Reply-To: Alexander Voropay , qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org This is a multi-part message in MIME format. ------=_NextPart_000_17D9_01C70259.4B2CA370 Content-Type: text/plain; format=flowed; charset="koi8-r"; reply-type=original Content-Transfer-Encoding: 7bit Hi! This patch separates MIPS CPU timer and R4K "machine", please review. It's required to add a new MIPS machines. -- -=AV=- ------=_NextPart_000_17D9_01C70259.4B2CA370 Content-Type: application/octet-stream; name="mipstimer.diff" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="mipstimer.diff" diff -urP --exclude-from=3Dexclude qemu/Makefile.target = ../qemu-20061002/Makefile.target=0A= --- qemu/Makefile.target 2006-10-30 16:51:47.000000000 +0300=0A= +++ ../qemu-20061002/Makefile.target 2006-11-02 22:06:42.181789824 +0300=0A= @@ -357,7 +357,7 @@=0A= DEFINES +=3D -DHAS_AUDIO=0A= endif=0A= ifeq ($(TARGET_ARCH), mips)=0A= -VL_OBJS+=3D mips_r4k.o dma.o vga.o serial.o i8254.o i8259.o ide.o=0A= +VL_OBJS+=3D mips_r4k.o mips_timer.o dma.o vga.o serial.o i8254.o = i8259.o ide.o=0A= #VL_OBJS+=3D #pckbd.o fdc.o m48t59.o=0A= endif=0A= ifeq ($(TARGET_BASE_ARCH), sparc)=0A= diff -urP --exclude-from=3Dexclude qemu/hw/mips_r4k.c = ../qemu-20061002/hw/mips_r4k.c=0A= --- qemu/hw/mips_r4k.c 2006-10-30 16:51:47.000000000 +0300=0A= +++ ../qemu-20061002/hw/mips_r4k.c 2006-11-02 23:42:21.544274104 +0300=0A= @@ -1,3 +1,12 @@=0A= +/*=0A= + * QEMU/MIPS pseudo-board=0A= + *=0A= + * emulates a simple machine with ISA-like bus.=0A= + * ISA IO space mapped to the 0x14000000 (PHYS) and=0A= + * ISA memory at the 0x10000000 (PHYS, 16Mb in size).=0A= + * All peripherial devices are attached to this "bus" with=0A= + * the standard PC ISA addresses. =0A= +*/=0A= #include "vl.h"=0A= =0A= #define BIOS_FILENAME "mips_bios.bin"=0A= @@ -13,8 +22,10 @@=0A= =0A= extern FILE *logfile;=0A= =0A= -static PITState *pit;=0A= +static PITState *pit; /* PIT i8254 */=0A= =0A= +/*i8254 PIT is attached to the IRQ0 at PIC i8259 */=0A= +/*The PIC is attached to the MIPS CPU INT0 pin */=0A= static void pic_irq_request(void *opaque, int level)=0A= {=0A= CPUState *env =3D first_cpu;=0A= @@ -27,90 +38,6 @@=0A= }=0A= }=0A= =0A= -void cpu_mips_irqctrl_init (void)=0A= -{=0A= -}=0A= -=0A= -/* XXX: do not use a global */=0A= -uint32_t cpu_mips_get_random (CPUState *env)=0A= -{=0A= - static uint32_t seed =3D 0;=0A= - uint32_t idx;=0A= - seed =3D seed * 314159 + 1;=0A= - idx =3D (seed >> 16) % (MIPS_TLB_NB - env->CP0_Wired) + = env->CP0_Wired;=0A= - return idx;=0A= -}=0A= -=0A= -/* MIPS R4K timer */=0A= -uint32_t cpu_mips_get_count (CPUState *env)=0A= -{=0A= - return env->CP0_Count +=0A= - (uint32_t)muldiv64(qemu_get_clock(vm_clock),=0A= - 100 * 1000 * 1000, ticks_per_sec);=0A= -}=0A= -=0A= -static void cpu_mips_update_count (CPUState *env, uint32_t count,=0A= - uint32_t compare)=0A= -{=0A= - uint64_t now, next;=0A= - uint32_t tmp;=0A= - =0A= - tmp =3D count;=0A= - if (count =3D=3D compare)=0A= - tmp++;=0A= - now =3D qemu_get_clock(vm_clock);=0A= - next =3D now + muldiv64(compare - tmp, ticks_per_sec, 100 * 1000 * = 1000);=0A= - if (next =3D=3D now)=0A= - next++;=0A= -#if 0=0A= - if (logfile) {=0A= - fprintf(logfile, "%s: 0x%08" PRIx64 " %08x %08x =3D> 0x%08" = PRIx64 "\n",=0A= - __func__, now, count, compare, next - now);=0A= - }=0A= -#endif=0A= - /* Store new count and compare registers */=0A= - env->CP0_Compare =3D compare;=0A= - env->CP0_Count =3D=0A= - count - (uint32_t)muldiv64(now, 100 * 1000 * 1000, = ticks_per_sec);=0A= - /* Adjust timer */=0A= - qemu_mod_timer(env->timer, next);=0A= -}=0A= -=0A= -void cpu_mips_store_count (CPUState *env, uint32_t value)=0A= -{=0A= - cpu_mips_update_count(env, value, env->CP0_Compare);=0A= -}=0A= -=0A= -void cpu_mips_store_compare (CPUState *env, uint32_t value)=0A= -{=0A= - cpu_mips_update_count(env, cpu_mips_get_count(env), value);=0A= - env->CP0_Cause &=3D ~0x00008000;=0A= - cpu_reset_interrupt(env, CPU_INTERRUPT_HARD);=0A= -}=0A= -=0A= -static void mips_timer_cb (void *opaque)=0A= -{=0A= - CPUState *env;=0A= -=0A= - env =3D opaque;=0A= -#if 0=0A= - if (logfile) {=0A= - fprintf(logfile, "%s\n", __func__);=0A= - }=0A= -#endif=0A= - cpu_mips_update_count(env, cpu_mips_get_count(env), = env->CP0_Compare);=0A= - env->CP0_Cause |=3D 0x00008000;=0A= - cpu_interrupt(env, CPU_INTERRUPT_HARD);=0A= -}=0A= -=0A= -void cpu_mips_clock_init (CPUState *env)=0A= -{=0A= - env->timer =3D qemu_new_timer(vm_clock, &mips_timer_cb, env);=0A= - env->CP0_Compare =3D 0;=0A= - cpu_mips_update_count(env, 1, 0);=0A= -}=0A= -=0A= -=0A= void mips_r4k_init (int ram_size, int vga_ram_size, int boot_device,=0A= DisplayState *ds, const char **fd_filename, int = snapshot,=0A= const char *kernel_filename, const char = *kernel_cmdline,=0A= @@ -180,7 +107,7 @@=0A= *(int *)(phys_ram_base + (16 << 20) - 264) =3D tswap32 = (ram_size);=0A= }=0A= =0A= - /* Init internal devices */=0A= + /* Init CPU internal devices */=0A= cpu_mips_clock_init(env);=0A= cpu_mips_irqctrl_init();=0A= =0A= diff -urP --exclude-from=3Dexclude qemu/hw/mips_timer.c = ../qemu-20061002/hw/mips_timer.c=0A= --- qemu/hw/mips_timer.c 1970-01-01 03:00:00.000000000 +0300=0A= +++ ../qemu-20061002/hw/mips_timer.c 2006-11-02 22:09:45.618903144 +0300=0A= @@ -0,0 +1,85 @@=0A= +#include "vl.h"=0A= +=0A= +void cpu_mips_irqctrl_init (void)=0A= +{=0A= +}=0A= +=0A= +/* XXX: do not use a global */=0A= +uint32_t cpu_mips_get_random (CPUState *env)=0A= +{=0A= + static uint32_t seed =3D 0;=0A= + uint32_t idx;=0A= + seed =3D seed * 314159 + 1;=0A= + idx =3D (seed >> 16) % (MIPS_TLB_NB - env->CP0_Wired) + = env->CP0_Wired;=0A= + return idx;=0A= +}=0A= +=0A= +/* MIPS R4K timer */=0A= +uint32_t cpu_mips_get_count (CPUState *env)=0A= +{=0A= + return env->CP0_Count +=0A= + (uint32_t)muldiv64(qemu_get_clock(vm_clock),=0A= + 100 * 1000 * 1000, ticks_per_sec);=0A= +}=0A= +=0A= +static void cpu_mips_update_count (CPUState *env, uint32_t count,=0A= + uint32_t compare)=0A= +{=0A= + uint64_t now, next;=0A= + uint32_t tmp;=0A= + =0A= + tmp =3D count;=0A= + if (count =3D=3D compare)=0A= + tmp++;=0A= + now =3D qemu_get_clock(vm_clock);=0A= + next =3D now + muldiv64(compare - tmp, ticks_per_sec, 100 * 1000 * = 1000);=0A= + if (next =3D=3D now)=0A= + next++;=0A= +#if 0=0A= + if (logfile) {=0A= + fprintf(logfile, "%s: 0x%08" PRIx64 " %08x %08x =3D> 0x%08" = PRIx64 "\n",=0A= + __func__, now, count, compare, next - now);=0A= + }=0A= +#endif=0A= + /* Store new count and compare registers */=0A= + env->CP0_Compare =3D compare;=0A= + env->CP0_Count =3D=0A= + count - (uint32_t)muldiv64(now, 100 * 1000 * 1000, = ticks_per_sec);=0A= + /* Adjust timer */=0A= + qemu_mod_timer(env->timer, next);=0A= +}=0A= +=0A= +void cpu_mips_store_count (CPUState *env, uint32_t value)=0A= +{=0A= + cpu_mips_update_count(env, value, env->CP0_Compare);=0A= +}=0A= +=0A= +void cpu_mips_store_compare (CPUState *env, uint32_t value)=0A= +{=0A= + cpu_mips_update_count(env, cpu_mips_get_count(env), value);=0A= + env->CP0_Cause &=3D ~0x00008000;=0A= + cpu_reset_interrupt(env, CPU_INTERRUPT_HARD);=0A= +}=0A= +=0A= +static void mips_timer_cb (void *opaque)=0A= +{=0A= + CPUState *env;=0A= +=0A= + env =3D opaque;=0A= +#if 0=0A= + if (logfile) {=0A= + fprintf(logfile, "%s\n", __func__);=0A= + }=0A= +#endif=0A= + cpu_mips_update_count(env, cpu_mips_get_count(env), = env->CP0_Compare);=0A= + env->CP0_Cause |=3D 0x00008000;=0A= + cpu_interrupt(env, CPU_INTERRUPT_HARD);=0A= +}=0A= +=0A= +void cpu_mips_clock_init (CPUState *env)=0A= +{=0A= + env->timer =3D qemu_new_timer(vm_clock, &mips_timer_cb, env);=0A= + env->CP0_Compare =3D 0;=0A= + cpu_mips_update_count(env, 1, 0);=0A= +}=0A= +=0A= diff -urP --exclude-from=3Dexclude qemu/vl.h ../qemu-20061002/vl.h=0A= --- qemu/vl.h 2006-10-26 21:15:37.000000000 +0400=0A= +++ ../qemu-20061002/vl.h 2006-11-02 22:25:20.963709120 +0300=0A= @@ -1024,6 +1024,10 @@=0A= /* mips_r4k.c */=0A= extern QEMUMachine mips_machine;=0A= =0A= +/* mips_timer.c */=0A= +extern void cpu_mips_clock_init(CPUState *);=0A= +extern void cpu_mips_irqctrl_init (void);=0A= +=0A= /* shix.c */=0A= extern QEMUMachine shix_machine;=0A= =0A= ------=_NextPart_000_17D9_01C70259.4B2CA370--