From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JSM5O-0005Tw-CU for qemu-devel@nongnu.org; Thu, 21 Feb 2008 19:48:22 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JSM5M-0005TQ-VZ for qemu-devel@nongnu.org; Thu, 21 Feb 2008 19:48:22 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JSM5M-0005TN-Mp for qemu-devel@nongnu.org; Thu, 21 Feb 2008 19:48:20 -0500 Received: from li2-213.members.linode.com ([69.56.173.213] helo=mail.zilogic.com) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1JSM5M-00087q-El for qemu-devel@nongnu.org; Thu, 21 Feb 2008 19:48:20 -0500 Received: from [192.168.1.4] (unknown [59.92.37.144]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.zilogic.com (Postfix) with ESMTP id B9742106B4 for ; Thu, 21 Feb 2008 19:48:15 -0500 (EST) Message-ID: <47BE1B61.8080604@bravegnu.org> Date: Fri, 22 Feb 2008 06:16:25 +0530 From: Vijay Kumar MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] [PATCH] mipsnet incorrect device ID fix Reply-To: 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 The mipsnet device returns wrong values for device ID, since it returns the contents of the pointer rather that the contents of the device ID string. Also the contents of the string is returned such that the order is host endianess dependent. The patch fixes both these issues. Signed-off-by: Vijay Kumar B. --- qemu-orig/hw/mipsnet.c 2007-12-27 11:18:52.000000000 +0530 +++ qemu-mod/hw/mipsnet.c 2008-02-20 20:23:44.000000000 +0530 @@ -101,6 +101,19 @@ mipsnet_update_irq(s); } +static uint32_t bytes_to_int32(const unsigned char *arr) +{ + int i; + uint32_t ret = 0; + int nbytes = sizeof(int32_t); + + for (i = 0; i < nbytes; i++) { + ret = ret << 8 | arr[nbytes - 1 - i]; + } + + return ret; +} + static uint32_t mipsnet_ioport_read(void *opaque, uint32_t addr) { MIPSnetState *s = opaque; @@ -110,10 +123,10 @@ addr &= 0x3f; switch (addr) { case MIPSNET_DEV_ID: - ret = *((uint32_t *)&devid); + ret = bytes_to_int32(devid); break; case MIPSNET_DEV_ID + 4: - ret = *((uint32_t *)(&devid + 4)); + ret = bytes_to_int32(devid + 4); break; case MIPSNET_BUSY: ret = s->busy;