Module Name: src Committed By: uwe Date: Mon Aug 3 21:53:25 UTC 2020
Modified Files: src/sys/arch/sh3/include: cpu.h src/sys/arch/sh3/sh3: db_interface.c Log Message: SH3_P2SEG_FUNC(f) - get a P2 address of a function. Just SH3_P1SEG_TO_P2SEG + cast, but we now define SH3_P1SEG_TO_P2SEG and SH3_P2SEG_TO_P1SEG to use arithmetic, not bitwise ops. That gives the same result for the correct P1/P2 input values, but addition can be done at link time with addends. Thus SH3_P2SEG_FUNC compiles to a constant P2 address. To generate a diff of this commit: cvs rdiff -u -r1.59 -r1.60 src/sys/arch/sh3/include/cpu.h cvs rdiff -u -r1.64 -r1.65 src/sys/arch/sh3/sh3/db_interface.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/sh3/include/cpu.h diff -u src/sys/arch/sh3/include/cpu.h:1.59 src/sys/arch/sh3/include/cpu.h:1.60 --- src/sys/arch/sh3/include/cpu.h:1.59 Sun Dec 1 15:34:45 2019 +++ src/sys/arch/sh3/include/cpu.h Mon Aug 3 21:53:25 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: cpu.h,v 1.59 2019/12/01 15:34:45 ad Exp $ */ +/* $NetBSD: cpu.h,v 1.60 2020/08/03 21:53:25 uwe Exp $ */ /*- * Copyright (c) 2002, 2019 The NetBSD Foundation, Inc. All rights reserved. @@ -151,8 +151,14 @@ do { \ #define SH3_P2SEG_TO_PHYS(x) ((uint32_t)(x) & SH3_PHYS_MASK) #define SH3_PHYS_TO_P1SEG(x) ((uint32_t)(x) | SH3_P1SEG_BASE) #define SH3_PHYS_TO_P2SEG(x) ((uint32_t)(x) | SH3_P2SEG_BASE) -#define SH3_P1SEG_TO_P2SEG(x) ((uint32_t)(x) | 0x20000000) -#define SH3_P2SEG_TO_P1SEG(x) ((uint32_t)(x) & ~0x20000000) +#define SH3_P1SEG_TO_P2SEG(x) ((uint32_t)(x) + 0x20000000u) +#define SH3_P2SEG_TO_P1SEG(x) ((uint32_t)(x) - 0x20000000u) + +#ifdef __GNUC__ +#define SH3_P2SEG_FUNC(f) ((__typeof__(f) *)SH3_P1SEG_TO_P2SEG(f)) +#else +#define SH3_P2SEG_FUNC(f) ((void *)SH3_P1SEG_TO_P2SEG(f)) +#endif #ifndef __lint__ Index: src/sys/arch/sh3/sh3/db_interface.c diff -u src/sys/arch/sh3/sh3/db_interface.c:1.64 src/sys/arch/sh3/sh3/db_interface.c:1.65 --- src/sys/arch/sh3/sh3/db_interface.c:1.64 Mon Aug 3 01:56:18 2020 +++ src/sys/arch/sh3/sh3/db_interface.c Mon Aug 3 21:53:25 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: db_interface.c,v 1.64 2020/08/03 01:56:18 uwe Exp $ */ +/* $NetBSD: db_interface.c,v 1.65 2020/08/03 21:53:25 uwe Exp $ */ /*- * Copyright (C) 2002 UCHIYAMA Yasushi. All rights reserved. @@ -28,7 +28,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: db_interface.c,v 1.64 2020/08/03 01:56:18 uwe Exp $"); +__KERNEL_RCSID(0, "$NetBSD: db_interface.c,v 1.65 2020/08/03 21:53:25 uwe Exp $"); #include "opt_ddb.h" #include "opt_kgdb.h" @@ -331,8 +331,8 @@ db_tlbdump_cmd(db_expr_t addr, bool have void (*get_utlb_p2)(uint32_t, uint32_t *, uint32_t *, uint32_t *); uint32_t aa, da1, da2; - get_itlb_p2 = (void *)SH3_P1SEG_TO_P2SEG(__db_get_itlb_sh4); - get_utlb_p2 = (void *)SH3_P1SEG_TO_P2SEG(__db_get_utlb_sh4); + get_itlb_p2 = SH3_P2SEG_FUNC(__db_get_itlb_sh4); + get_utlb_p2 = SH3_P2SEG_FUNC(__db_get_utlb_sh4); /* MMU configuration */ r = _reg_read_4(SH4_MMUCR); @@ -478,11 +478,11 @@ db_cachedump_cmd(db_expr_t addr, bool ha #ifdef SH3 if (CPU_IS_SH3) - cachedump_p2 = (void *)SH3_P1SEG_TO_P2SEG(__db_cachedump_sh3); + cachedump_p2 = SH3_P2SEG_FUNC(__db_cachedump_sh3); #endif #ifdef SH4 if (CPU_IS_SH4) - cachedump_p2 = (void *)SH3_P1SEG_TO_P2SEG(__db_cachedump_sh4); + cachedump_p2 = SH3_P2SEG_FUNC(__db_cachedump_sh4); #endif (*cachedump_p2)(have_addr ? addr : 0); }