Date: Thu, 15 Mar 2012 23:53:24 +0000 (UTC) From: Oleksandr Tymoshenko <gonzo@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r233019 - head/sys/mips/mips Message-ID: <201203152353.q2FNrOia090086@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: gonzo Date: Thu Mar 15 23:53:24 2012 New Revision: 233019 URL: http://svn.freebsd.org/changeset/base/233019 Log: Clean-up fake preload data generator: - Use macros to push scalar values - Fix type mismatch for module size Modified: head/sys/mips/mips/machdep.c Modified: head/sys/mips/mips/machdep.c ============================================================================== --- head/sys/mips/mips/machdep.c Thu Mar 15 22:53:39 2012 (r233018) +++ head/sys/mips/mips/machdep.c Thu Mar 15 23:53:24 2012 (r233019) @@ -384,46 +384,41 @@ mips_postboot_fixup(void) caddr_t preload_ptr = (caddr_t)&fake_preload[0]; size_t size = 0; +#define PRELOAD_PUSH_VALUE(type, value) do { \ + *(type *)(preload_ptr + size) = (value); \ + size += sizeof(type); \ +} while (0); + /* * Provide kernel module file information */ - *(uint32_t*)(preload_ptr + size) = MODINFO_NAME; - size += sizeof(uint32_t); - *(uint32_t*)(preload_ptr + size) = strlen("kernel") + 1; - size += sizeof(uint32_t); + PRELOAD_PUSH_VALUE(uint32_t, MODINFO_NAME); + PRELOAD_PUSH_VALUE(uint32_t, strlen("kernel") + 1); strcpy((char*)(preload_ptr + size), "kernel"); size += strlen("kernel") + 1; size = roundup(size, sizeof(u_long)); - *(uint32_t*)(preload_ptr + size) = MODINFO_TYPE; - size += sizeof(uint32_t); - *(uint32_t*)(preload_ptr + size) = strlen("elf kernel") + 1; - size += sizeof(uint32_t); + PRELOAD_PUSH_VALUE(uint32_t, MODINFO_TYPE); + PRELOAD_PUSH_VALUE(uint32_t, strlen("elf kernel") + 1); strcpy((char*)(preload_ptr + size), "elf kernel"); size += strlen("elf kernel") + 1; size = roundup(size, sizeof(u_long)); - *(uint32_t*)(preload_ptr + size) = MODINFO_ADDR; - size += sizeof(uint32_t); - *(uint32_t*)(preload_ptr + size) = sizeof(vm_offset_t); - size += sizeof(uint32_t); - *(vm_offset_t*)(preload_ptr + size) = KERNLOADADDR; - size += sizeof(vm_offset_t); + PRELOAD_PUSH_VALUE(uint32_t, MODINFO_ADDR); + PRELOAD_PUSH_VALUE(uint32_t, sizeof(vm_offset_t)); + PRELOAD_PUSH_VALUE(vm_offset_t, KERNLOADADDR); size = roundup(size, sizeof(u_long)); - *(uint32_t*)(preload_ptr + size) = MODINFO_SIZE; - size += sizeof(uint32_t); - *(uint32_t*)(preload_ptr + size) = sizeof(size_t); - size += sizeof(uint32_t); - *(vm_offset_t*)(preload_ptr + size) = (size_t)&end - KERNLOADADDR; + PRELOAD_PUSH_VALUE(uint32_t, MODINFO_SIZE); + PRELOAD_PUSH_VALUE(uint32_t, sizeof(size_t)); + PRELOAD_PUSH_VALUE(size_t, (size_t)&end - KERNLOADADDR); size = roundup(size, sizeof(u_long)); - size += sizeof(size_t); /* End marker */ - *(uint32_t*)(preload_ptr + size) = 0; - size += sizeof(uint32_t); - *(uint32_t*)(preload_ptr + size) = 0; - size += sizeof(uint32_t); + PRELOAD_PUSH_VALUE(uint32_t, 0); + PRELOAD_PUSH_VALUE(uint32_t, 0); + +#undef PRELOAD_PUSH_VALUE KASSERT((size < sizeof(fake_preload)), ("fake preload size is more thenallocated"));
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201203152353.q2FNrOia090086>