From e11b3c29a611ba1366bf321e2ff2d0ad5103a9d1 Mon Sep 17 00:00:00 2001 From: rin Date: Wed, 27 Apr 2022 11:48:26 +0000 Subject: [PATCH] Introduce SA_HARDCODED_SECSIZE hack, by which hardcoded DEV_BSIZE is used instead of secsize obtained by SAIOSECSIZE ioctl. This hack avoids divdi3 and friends from being linked, in order to support variable secsize. This is useful for amiga/boot(8); it is loaded by firmware into unpredictable address, and therefore all symbols should be addressable by PC relative mode with only 16-bit displacements. See sys/arch/amiga/stand/bootblock/{boot/bbstart.s,elf2bb,txlt} for more details. --- sys/lib/libsa/ext2fs.c | 10 ++-------- sys/lib/libsa/minixfs3.c | 10 ++-------- sys/lib/libsa/stand.h | 21 ++++++++++++++++++++- sys/lib/libsa/ufs.c | 12 +++--------- 4 files changed, 27 insertions(+), 26 deletions(-) diff --git a/sys/lib/libsa/ext2fs.c b/sys/lib/libsa/ext2fs.c index 007c732dfacf..f23bd0d1630d 100644 --- a/sys/lib/libsa/ext2fs.c +++ b/sys/lib/libsa/ext2fs.c @@ -1,4 +1,4 @@ -/* $NetBSD: ext2fs.c,v 1.31 2022/04/24 06:48:15 mlelstv Exp $ */ +/* $NetBSD: ext2fs.c,v 1.32 2022/04/27 11:48:26 rin Exp $ */ /* * Copyright (c) 1997 Manuel Bouyer. @@ -415,15 +415,9 @@ read_sblock(struct open_file *f, struct m_ext2fs *fs) struct ext2fs ext2fs; size_t buf_size; int rc; - u_int secsize; - - secsize = 0; - rc = DEV_IOCTL(f->f_dev)(f, SAIOSECSIZE, &secsize); - if (rc != 0 || secsize == 0) - secsize = DEV_BSIZE; rc = DEV_STRATEGY(f->f_dev)(f->f_devdata, F_READ, - SBOFF / secsize, SBSIZE, sbbuf, &buf_size); + SBOFF / GETSECSIZE(f), SBSIZE, sbbuf, &buf_size); if (rc) return rc; diff --git a/sys/lib/libsa/minixfs3.c b/sys/lib/libsa/minixfs3.c index 9903f12d4fd2..e50088f378a1 100644 --- a/sys/lib/libsa/minixfs3.c +++ b/sys/lib/libsa/minixfs3.c @@ -1,4 +1,4 @@ -/* $NetBSD: minixfs3.c,v 1.10 2022/04/24 06:48:15 mlelstv Exp $ */ +/* $NetBSD: minixfs3.c,v 1.11 2022/04/27 11:48:26 rin Exp $ */ /*- * Copyright (c) 2012 @@ -449,7 +449,6 @@ read_sblock(struct open_file *f, struct mfs_sblock *fs) static uint8_t sbbuf[MINBSIZE]; size_t buf_size; int rc; - u_int secsize; /* We must read amount multiple of sector size, hence we can't * read SBSIZE and read MINBSIZE. @@ -457,13 +456,8 @@ read_sblock(struct open_file *f, struct mfs_sblock *fs) if (SBSIZE > MINBSIZE) return EINVAL; - secsize = 0; - rc = DEV_IOCTL(f->f_dev)(f, SAIOSECSIZE, &secsize); - if (rc != 0 || secsize == 0) - secsize = DEV_BSIZE; - rc = DEV_STRATEGY(f->f_dev)(f->f_devdata, F_READ, - SUPER_BLOCK_OFF / secsize, MINBSIZE, sbbuf, &buf_size); + SUPER_BLOCK_OFF / GETSECSIZE(f), MINBSIZE, sbbuf, &buf_size); if (rc) return rc; diff --git a/sys/lib/libsa/stand.h b/sys/lib/libsa/stand.h index 7c92ea34eb97..48e6ed40cf95 100644 --- a/sys/lib/libsa/stand.h +++ b/sys/lib/libsa/stand.h @@ -1,4 +1,4 @@ -/* $NetBSD: stand.h,v 1.83 2021/05/17 08:50:36 mrg Exp $ */ +/* $NetBSD: stand.h,v 1.84 2022/04/27 11:48:26 rin Exp $ */ /* * Copyright (c) 1999 Christopher G. Demetriou. All rights reserved. @@ -64,6 +64,7 @@ #ifndef _LIBSA_STAND_H_ #define _LIBSA_STAND_H_ +#include #include #include #include @@ -320,4 +321,22 @@ void bzero(void *, size_t); int atoi(const char *); +#if !defined(SA_HARDCODED_SECSIZE) +#define GETSECSIZE(f) getsecsize(f) +static inline u_int +getsecsize(struct open_file *f) +{ + int rc; + u_int secsize = 0; + + rc = DEV_IOCTL(f->f_dev)(f, SAIOSECSIZE, &secsize); + if (rc != 0 || secsize == 0) + secsize = DEV_BSIZE; + + return secsize; +} +#else +#define GETSECSIZE(f) DEV_BSIZE +#endif + #endif /* _LIBSA_STAND_H_ */ diff --git a/sys/lib/libsa/ufs.c b/sys/lib/libsa/ufs.c index efde7592f2c8..9593711ea4b6 100644 --- a/sys/lib/libsa/ufs.c +++ b/sys/lib/libsa/ufs.c @@ -1,4 +1,4 @@ -/* $NetBSD: ufs.c,v 1.83 2022/04/24 06:52:59 mlelstv Exp $ */ +/* $NetBSD: ufs.c,v 1.84 2022/04/27 11:48:26 rin Exp $ */ /*- * Copyright (c) 1993 @@ -594,21 +594,15 @@ ffs_find_superblock(struct open_file *f, FS *fs) struct file *fp = (struct file *)f->f_fsdata; int rc; size_t buf_size; - u_int secsize; #ifdef LIBSA_FFSv2 static daddr_t sblock_try[] = SBLOCKSEARCH; int i; #endif - secsize = 0; - rc = DEV_IOCTL(f->f_dev)(f, SAIOSECSIZE, &secsize); - if (rc != 0 || secsize == 0) - secsize = DEV_BSIZE; - #ifdef LIBSA_FFSv2 for (i = 0; sblock_try[i] != -1; i++) { rc = DEV_STRATEGY(f->f_dev)(f->f_devdata, F_READ, - sblock_try[i] / secsize, SBLOCKSIZE, fs, &buf_size); + sblock_try[i] / GETSECSIZE(f), SBLOCKSIZE, fs, &buf_size); if (rc) return rc; if (buf_size != SBLOCKSIZE) @@ -623,7 +617,7 @@ ffs_find_superblock(struct open_file *f, FS *fs) return EINVAL; #else /* LIBSA_FFSv2 */ rc = DEV_STRATEGY(f->f_dev)(f->f_devdata, F_READ, - SBLOCKOFFSET / secsize, SBLOCKSIZE, fs, &buf_size); + SBLOCKOFFSET / GETSECSIZE(f), SBLOCKSIZE, fs, &buf_size); if (rc) return rc; if (buf_size != SBLOCKSIZE)