aboutsummaryrefslogtreecommitdiff
path: root/linux/lnxabs.h
diff options
context:
space:
mode:
authorJavier <dev.git@javispedro.com>2026-10-26 00:50:06 +0100
committerJavier <dev.git@javispedro.com>2026-10-26 00:50:06 +0100
commit6b8a368c51082fdd010ef5e1b0be4eb9b5059d1a (patch)
treee274d41a8dd5e912e20617a937a1fda5af91f8de /linux/lnxabs.h
parent9b1cf601360fb194047e6dcc2af75c2f38c611ec (diff)
downloadchu-6b8a368c51082fdd010ef5e1b0be4eb9b5059d1a.tar.gz
chu-6b8a368c51082fdd010ef5e1b0be4eb9b5059d1a.zip
refactor common parts into inc/ch375.h and add win9x, linux drivers
Diffstat (limited to 'linux/lnxabs.h')
-rw-r--r--linux/lnxabs.h139
1 files changed, 139 insertions, 0 deletions
diff --git a/linux/lnxabs.h b/linux/lnxabs.h
new file mode 100644
index 0000000..47adcea
--- /dev/null
+++ b/linux/lnxabs.h
@@ -0,0 +1,139 @@
+/*
+ * Abstractions between different versions of Linux
+ * Currently only tested amonst the latest versions of 2.0 and 2.2
+ * Copyright (C) 2026 Javier S. Pedro
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#ifdef MODVERSIONS
+#include <linux/modversions.h>
+#endif
+
+#include <linux/version.h>
+
+#define MAKE_VERSION_CODE(vers, rel, seq) ( (vers)<<16 | (rel)<<8 | (seq) )
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+
+// Module entry point abstraction
+#if LINUX_VERSION_CODE < MAKE_VERSION_CODE(2,1,36)
+ #define __init /**/
+ #define module_init(x) int init_module(void) { return x(); }
+ #define module_exit(x) void cleanup_module(void) { x(); }
+#else
+ #include <linux/init.h>
+#endif
+
+// Module params
+#if LINUX_VERSION_CODE < MAKE_VERSION_CODE(2,1,26)
+ #define MODULE_PARM(var, type) /**/
+ #define MODULE_PARM_DESC(var, s) /**/
+ #define MODULE_DESCRIPTION(s) /**/
+#endif
+#if LINUX_VERSION_CODE < MAKE_VERSION_CODE(2,4,0)
+ #define MODULE_LICENSE(s) /**/
+#endif
+
+#include <linux/ioport.h>
+#include <linux/fs.h>
+#include <linux/errno.h>
+
+#include <linux/blk.h>
+#include <linux/blkdev.h>
+#include <linux/hdreg.h>
+
+#if LINUX_VERSION_CODE < MAKE_VERSION_CODE(2,1,0)
+#define invalidate_inodes_dev(devno) invalidate_inodes(devno)
+#else
+static inline void invalidate_inodes_dev(kdev_t devno) {
+ struct super_block *sb = get_super(devno);
+ if (sb) invalidate_inodes(sb);
+}
+#endif
+
+#include <linux/delay.h>
+
+// time before/after
+#if LINUX_VERSION_CODE < MAKE_VERSION_CODE(2,1,95)
+ #define time_after(a,b) ((long)(b) - (long)(a) < 0)
+ #define time_before(a,b) time_after(b,a)
+#endif
+
+// mdelay
+#if LINUX_VERSION_CODE < MAKE_VERSION_CODE(2,1,0)
+static inline void mdelay(int milliseconds)
+{
+ int i;
+ for(i=0; i<milliseconds; i++)
+ udelay(1000);
+}
+#endif
+
+// put_user/copy_to_user
+#if LINUX_VERSION_CODE < MAKE_VERSION_CODE(2,1,0)
+ #undef put_user
+ #undef get_user
+
+ #define put_user(x,ptr) ({ \
+ int i = verify_area(VERIFY_WRITE, (ptr), sizeof(*(ptr))); \
+ if (i == 0) { __put_user((unsigned long)(x),(ptr),sizeof(*(ptr))); } \
+ i; \
+ })
+ #define get_user(x,ptr) ({ \
+ int i = verify_area(VERIFY_READ, (ptr), sizeof(*(ptr))); \
+ if (i == 0) { x = ((__typeof__(*(ptr)))__get_user((ptr),sizeof(*(ptr)))); } \
+ i; \
+ })
+
+ extern inline int copy_from_user(void *to, const void *from, unsigned long n)
+ {
+ int i = verify_area(VERIFY_READ, from, n);
+ if (i)
+ return i;
+ memcpy_fromfs(to, from, n);
+ return 0;
+ }
+
+ extern inline int copy_to_user(void *to, const void *from, unsigned long n)
+ {
+ int i = verify_area(VERIFY_WRITE, to, n);
+ if (i)
+ return i;
+ memcpy_tofs(to, from, n);
+ return 0;
+ }
+#else
+ #include <asm/uaccess.h>
+#endif
+
+// capabilities
+#if LINUX_VERSION_CODE < MAKE_VERSION_CODE(2,1,0)
+#define is_sys_admin() suser()
+#else
+#define is_sys_admin() capable(CAP_SYS_ADMIN)
+#endif
+
+// stdtypes
+#if LINUX_VERSION_CODE < MAKE_VERSION_CODE(2,1,0)
+ typedef __s8 int8_t;
+ typedef __s16 int16_t;
+ typedef __s32 int32_t;
+ typedef __u8 uint8_t;
+ typedef __u16 uint16_t;
+ typedef __u32 uint32_t;
+#endif
+
+#include <asm/byteorder.h>