Module Name: src Committed By: phx Date: Thu Aug 3 09:42:34 UTC 2017
Modified Files: src/sys/arch/sandpoint/stand/altboot: brdsetup.c Log Message: Fixed overflow in delay() for delays greater than 2 seconds. Replaced u_long by uint32_t and u_quad by uint64_t whenever the exact 32- or 64-bit word is needed. To generate a diff of this commit: cvs rdiff -u -r1.37 -r1.38 src/sys/arch/sandpoint/stand/altboot/brdsetup.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/arch/sandpoint/stand/altboot/brdsetup.c diff -u src/sys/arch/sandpoint/stand/altboot/brdsetup.c:1.37 src/sys/arch/sandpoint/stand/altboot/brdsetup.c:1.38 --- src/sys/arch/sandpoint/stand/altboot/brdsetup.c:1.37 Thu Oct 15 12:00:02 2015 +++ src/sys/arch/sandpoint/stand/altboot/brdsetup.c Thu Aug 3 09:42:34 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: brdsetup.c,v 1.37 2015/10/15 12:00:02 nisimura Exp $ */ +/* $NetBSD: brdsetup.c,v 1.38 2017/08/03 09:42:34 phx Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -65,7 +65,7 @@ static void send_iomega(int, int, int, i static inline uint32_t mfmsr(void); static inline void mtmsr(uint32_t); static inline uint32_t cputype(void); -static inline u_quad_t mftb(void); +static inline uint64_t mftb(void); static void init_uart(unsigned, unsigned, uint8_t); static void send_sat(char *); static unsigned mpc107memsize(void); @@ -1012,7 +1012,7 @@ _rtt(void) satime_t getsecs(void) { - u_quad_t tb = mftb(); + uint64_t tb = mftb(); return (tb / ticks_per_sec); } @@ -1021,13 +1021,13 @@ getsecs(void) * Wait for about n microseconds (at least!). */ void -delay(u_int n) +delay(unsigned n) { - u_quad_t tb; - u_long scratch, tbh, tbl; + uint64_t tb; + uint32_t scratch, tbh, tbl; tb = mftb(); - tb += (n * 1000 + ns_per_tick - 1) / ns_per_tick; + tb += ((uint64_t)n * 1000 + ns_per_tick - 1) / ns_per_tick; tbh = tb >> 32; tbl = tb; asm volatile ("1: mftbu %0; cmpw %0,%1; blt 1b; bgt 2f; mftb %0; cmpw 0, %0,%2; blt 1b; 2:" : "=&r"(scratch) : "r"(tbh), "r"(tbl)); @@ -1113,11 +1113,11 @@ cputype(void) return pvr >> 16; } -static inline u_quad_t +static inline uint64_t mftb(void) { - u_long scratch; - u_quad_t tb; + uint32_t scratch; + uint64_t tb; asm ("1: mftbu %0; mftb %0+1; mftbu %1; cmpw %0,%1; bne 1b" : "=r"(tb), "=r"(scratch));