# --- T2-COPYRIGHT-BEGIN --- # t2/package/*/linux/0000.patch.i860 # Copyright (C) 2026 The T2 SDE Project # SPDX-License-Identifier: GPL-2.0 or patched project license # --- T2-COPYRIGHT-END --- From: René Rebe Subject: [PATCH] i860: add port for the Samsung MAGIC Station II arch/i860, SCSI, LAN and other drivers, FP traps with IEEE results, gdb support and kernel modules. Against upstream commit 36aad21d50d1af3f6954bb0c988257a908202477 (Merge tag 'ksmbd-for-7.4-rc1-part2' of git://git.kernel.org/pub/scm/linux/kernel/git/linkinjeon/smb). Branch i860 at 54649bf6006b. Tested in the MAME magicst2 model only, not on real hardware. Signed-off-by: René Rebe Co-Authored-By: Claude Opus 5.5 --- arch/i860/Kbuild | 5 + arch/i860/Kconfig | 96 +++ arch/i860/Kconfig.debug | 1 + arch/i860/Makefile | 46 ++ arch/i860/boot/Makefile | 42 ++ arch/i860/boot/bootblock.S | 88 +++ arch/i860/configs/magicst2_defconfig | 77 +++ arch/i860/include/asm/Kbuild | 11 + arch/i860/include/asm/asm-offsets.h | 2 + arch/i860/include/asm/cache.h | 9 + arch/i860/include/asm/cacheflush.h | 55 ++ arch/i860/include/asm/clocksource.h | 8 + arch/i860/include/asm/dma.h | 28 + arch/i860/include/asm/elf.h | 37 ++ arch/i860/include/asm/entry-common.h | 15 + arch/i860/include/asm/floppy.h | 77 +++ arch/i860/include/asm/i860-dma.h | 29 + arch/i860/include/asm/i860.h | 103 +++ arch/i860/include/asm/io.h | 18 + arch/i860/include/asm/irq.h | 11 + arch/i860/include/asm/irqflags.h | 48 ++ arch/i860/include/asm/linkage.h | 9 + arch/i860/include/asm/mc146818rtc.h | 8 + arch/i860/include/asm/mmu.h | 10 + arch/i860/include/asm/mmu_context.h | 25 + arch/i860/include/asm/module.h | 29 + arch/i860/include/asm/module.lds.h | 5 + arch/i860/include/asm/page.h | 59 ++ arch/i860/include/asm/pgalloc.h | 61 ++ arch/i860/include/asm/pgtable.h | 171 +++++ arch/i860/include/asm/processor.h | 43 ++ arch/i860/include/asm/ptrace.h | 40 ++ arch/i860/include/asm/setup.h | 14 + arch/i860/include/asm/string.h | 15 + arch/i860/include/asm/switch_to.h | 19 + arch/i860/include/asm/syscall.h | 90 +++ arch/i860/include/asm/syscalls.h | 16 + arch/i860/include/asm/thread_info.h | 45 ++ arch/i860/include/asm/timex.h | 11 + arch/i860/include/asm/tlb.h | 8 + arch/i860/include/asm/tlbflush.h | 31 + arch/i860/include/asm/traps.h | 31 + arch/i860/include/asm/uaccess.h | 35 + arch/i860/include/asm/unistd.h | 13 + arch/i860/include/asm/vdso.h | 15 + arch/i860/include/asm/vdso/clocksource.h | 6 + arch/i860/include/asm/vdso/gettimeofday.h | 53 ++ arch/i860/include/asm/vdso/processor.h | 12 + arch/i860/include/asm/vdso/vsyscall.h | 10 + arch/i860/include/asm/vmalloc.h | 4 + arch/i860/include/uapi/asm/Kbuild | 3 + arch/i860/include/uapi/asm/auxvec.h | 8 + arch/i860/include/uapi/asm/byteorder.h | 8 + arch/i860/include/uapi/asm/ptrace.h | 41 ++ arch/i860/include/uapi/asm/sigcontext.h | 14 + arch/i860/include/uapi/asm/signal.h | 10 + arch/i860/include/uapi/asm/unistd.h | 3 + arch/i860/kernel/Makefile | 11 + arch/i860/kernel/Makefile.syscalls | 3 + arch/i860/kernel/asm-offsets.c | 35 + arch/i860/kernel/dma.c | 171 +++++ arch/i860/kernel/early_printk.c | 68 ++ arch/i860/kernel/entry.S | 462 ++++++++++++++ arch/i860/kernel/fpemu.c | 593 +++++++++++++++++ arch/i860/kernel/head.S | 42 ++ arch/i860/kernel/i860_ksyms.c | 32 + arch/i860/kernel/irq.c | 137 ++++ arch/i860/kernel/module.c | 176 +++++ arch/i860/kernel/process.c | 138 ++++ arch/i860/kernel/ptrace.c | 117 ++++ arch/i860/kernel/setup.c | 260 ++++++++ arch/i860/kernel/signal.c | 167 +++++ arch/i860/kernel/syscall_table.c | 17 + arch/i860/kernel/time.c | 131 ++++ arch/i860/kernel/traps.c | 553 ++++++++++++++++ arch/i860/kernel/vdso.c | 113 ++++ arch/i860/kernel/vdso/Makefile | 35 + arch/i860/kernel/vdso/gen_vdso_offsets.sh | 5 + arch/i860/kernel/vdso/sigreturn.S | 10 + arch/i860/kernel/vdso/vdso.S | 16 + arch/i860/kernel/vdso/vdso.lds.S | 50 ++ arch/i860/kernel/vdso/vgettimeofday.c | 17 + arch/i860/kernel/vmlinux.lds.S | 58 ++ arch/i860/lib/Makefile | 6 + arch/i860/lib/delay.c | 35 + arch/i860/lib/memcpy.S | 309 +++++++++ arch/i860/lib/memset.S | 74 +++ arch/i860/lib/usercopy.S | 124 ++++ arch/i860/mm/Makefile | 6 + arch/i860/mm/cache.S | 90 +++ arch/i860/mm/cacheflush.c | 65 ++ arch/i860/mm/extable.c | 17 + arch/i860/mm/fault.c | 133 ++++ arch/i860/mm/init.c | 165 +++++ drivers/input/serio/i8042-i860io.h | 54 ++ drivers/input/serio/i8042.h | 3 + drivers/net/ethernet/i825xx/Kconfig | 7 + drivers/net/ethernet/i825xx/Makefile | 1 + drivers/net/ethernet/i825xx/magicst2_82596.c | 636 +++++++++++++++++++ drivers/rtc/rtc-msm6242.c | 13 +- drivers/scsi/Kconfig | 8 + drivers/scsi/Makefile | 1 + drivers/scsi/magicst2.c | 228 +++++++ drivers/video/fbdev/Kconfig | 8 + drivers/video/fbdev/Makefile | 1 + drivers/video/fbdev/magicst2fb.c | 170 +++++ include/linux/platform_data/rtc-msm6242.h | 11 + include/uapi/linux/audit.h | 2 + scripts/syscall.tbl | 1 + tools/include/nolibc/Makefile | 2 + tools/include/nolibc/arch-i860.h | 159 +++++ tools/include/nolibc/arch.h | 3 + 112 files changed, 7527 insertions(+), 3 deletions(-) diff --git a/arch/i860/Kbuild b/arch/i860/Kbuild new file mode 100644 index 000000000000..e14316d4a5f4 --- /dev/null +++ b/arch/i860/Kbuild @@ -0,0 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0 +obj-y += kernel/ mm/ + +# for cleaning +subdir- += boot diff --git a/arch/i860/Kconfig b/arch/i860/Kconfig new file mode 100644 index 000000000000..3d5e235e9812 --- /dev/null +++ b/arch/i860/Kconfig @@ -0,0 +1,96 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Intel i860 (Samsung MAGIC Station II) +# Copyright (C) 2026 René Rebe +# + +config I860 + def_bool y + select ARCH_32BIT_OFF_T + select ARCH_MIGHT_HAVE_PC_SERIO + select ARCH_NO_PREEMPT + select CPU_NO_EFFICIENT_FFS + select GENERIC_ATOMIC64 + select GENERIC_CPU_DEVICES + select GENERIC_ENTRY + select GENERIC_SCHED_CLOCK + select GENERIC_IRQ_PROBE + select GENERIC_IRQ_SHOW + select GENERIC_IRQ_MULTI_HANDLER + select GENERIC_IOREMAP + select GENERIC_SMP_IDLE_THREAD + select GENERIC_GETTIMEOFDAY + select HAVE_ARCH_TRACEHOOK + select HAVE_GENERIC_VDSO + select HAVE_MOD_ARCH_SPECIFIC + select MODULES_USE_ELF_RELA + select HAVE_GENERIC_TIF_BITS + select HAVE_PAGE_SIZE_4KB + select HAVE_SYSCALL_TRACEPOINTS + select LOCK_MM_AND_FIND_VMA + select MMU_GATHER_NO_RANGE + select MODULES_USE_ELF_RELA + select NEED_DMA_MAP_STATE + select TRACE_IRQFLAGS_SUPPORT + +config MMU + def_bool y + +config GENERIC_CSUM + def_bool y + +config GENERIC_HWEIGHT + def_bool y + +config GENERIC_CALIBRATE_DELAY + def_bool y + +config NO_IOPORT_MAP + def_bool y + +config STACKTRACE_SUPPORT + def_bool n + +config LOCKDEP_SUPPORT + def_bool n + +config ARCH_MAY_HAVE_PC_FDC + def_bool y + +config NR_CPUS + int + default "1" + +config PGTABLE_LEVELS + int + default 2 + +menu "Processor type and features" + +config I860_MAGICST2 + def_bool y + help + Samsung i860 MAGIC Station II: i860XR, Intel 82380, WD33C93, + 82077 floppy, 82596 LAN, 16450 UARTs and DRAM at the top of the + physical address space. + +config I860_KERNEL_BASE + hex "Kernel load and link address" + default 0xff800000 + help + Physical (= virtual) address the kernel image is loaded to. The + default is the start of the smallest (8 MB) DRAM configuration. + +source "kernel/Kconfig.hz" + +config CMDLINE + string "Default kernel command line" + default "console=tty0 console=ttyS0,9600" + +config CMDLINE_FORCE + bool "Always use the default kernel command line" + default y + help + The boot loader does not pass a command line yet. + +endmenu diff --git a/arch/i860/Kconfig.debug b/arch/i860/Kconfig.debug new file mode 100644 index 000000000000..f66554cd5c45 --- /dev/null +++ b/arch/i860/Kconfig.debug @@ -0,0 +1 @@ +# SPDX-License-Identifier: GPL-2.0 diff --git a/arch/i860/Makefile b/arch/i860/Makefile new file mode 100644 index 000000000000..c95c1f645272 --- /dev/null +++ b/arch/i860/Makefile @@ -0,0 +1,46 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Intel i860 architecture Makefile +# Copyright (C) 2026 René Rebe +# + +KBUILD_DEFCONFIG := magicst2_defconfig + +LIBGCC := $(shell $(CC) $(KBUILD_CFLAGS) -print-libgcc-file-name) + +KBUILD_CFLAGS += -pipe -D__linux__ -fno-pic +# show_stack walks the frame pointers; these come after the -fomit-frame-pointer of the top Makefile +KBUILD_CFLAGS_KERNEL += -fno-omit-frame-pointer +KBUILD_CFLAGS_MODULE += -fno-omit-frame-pointer +KBUILD_AFLAGS += -fno-pic +LDFLAGS_vmlinux += -N + +libs-y += arch/i860/lib/ $(LIBGCC) + +boot := arch/i860/boot + +ifeq ($(KBUILD_EXTMOD),) +PHONY += vdso_prepare +vdso_prepare: prepare0 + $(Q)$(MAKE) $(build)=arch/i860/kernel/vdso include/generated/vdso-offsets.h + +prepare: vdso_prepare +endif + +all: vmlinux.bin + +PHONY += vmlinux.bin bootdisk + +vmlinux.bin: vmlinux + $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@ + +bootdisk: vmlinux.bin + $(Q)$(MAKE) $(build)=$(boot) $(boot)/bootdisk.img + +archclean: + $(Q)$(MAKE) $(clean)=$(boot) + +define archhelp + echo '* vmlinux.bin - Raw kernel image (arch/$(ARCH)/boot/vmlinux.bin)' + echo ' bootdisk - SCSI disk image with boot block and kernel' +endef diff --git a/arch/i860/boot/Makefile b/arch/i860/boot/Makefile new file mode 100644 index 000000000000..6d2a312797c8 --- /dev/null +++ b/arch/i860/boot/Makefile @@ -0,0 +1,42 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Copyright (C) 2026 René Rebe +# + +targets := vmlinux.bin bootblock.o bootblock.elf bootblock.bin bootdisk.img + +OBJCOPYFLAGS_vmlinux.bin := -O binary -R .note -R .comment -S + +$(obj)/vmlinux.bin: vmlinux FORCE + $(call if_changed,objcopy) + +# The kernel follows the boot block on the disk. +kernel_sectors = $(shell echo $$(( ($$(stat -c %s $(obj)/vmlinux.bin) + 511) / 512 ))) + +AFLAGS_bootblock.o = -DKERNEL_LBA=1 -DKERNEL_SECTORS=$(kernel_sectors) \ + -DKERNEL_LOAD=$(CONFIG_I860_KERNEL_BASE) \ + -DKERNEL_ENTRY=$(CONFIG_I860_KERNEL_BASE) + +$(obj)/bootblock.o: $(obj)/vmlinux.bin + +quiet_cmd_bootblock = LD $@ + cmd_bootblock = $(LD) $(call ld-option,--no-warn-rwx-segments) -N \ + -Ttext 0xffff8000 -e _start -o $@ $< + +$(obj)/bootblock.elf: $(obj)/bootblock.o FORCE + $(call if_changed,bootblock) + +OBJCOPYFLAGS_bootblock.bin := -O binary + +$(obj)/bootblock.bin: $(obj)/bootblock.elf FORCE + $(call if_changed,objcopy) + @test $$(stat -c %s $@) -le 512 || { echo "$@ exceeds 512 bytes"; false; } + +quiet_cmd_bootdisk = DISK $@ + cmd_bootdisk = rm -f $@; \ + dd if=$(obj)/bootblock.bin of=$@ bs=512 conv=sync status=none && \ + dd if=$(obj)/vmlinux.bin of=$@ bs=512 seek=1 conv=sync,notrunc status=none && \ + truncate -s %1M $@ + +$(obj)/bootdisk.img: $(obj)/bootblock.bin $(obj)/vmlinux.bin FORCE + $(call if_changed,bootdisk) diff --git a/arch/i860/boot/bootblock.S b/arch/i860/boot/bootblock.S new file mode 100644 index 000000000000..21811732209a --- /dev/null +++ b/arch/i860/boot/bootblock.S @@ -0,0 +1,88 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * SCSI disk boot block for the Samsung MAGIC Station II ROM monitor. + * The ROM loads LBA 0 to 0xffff8000 and enters it in supervisor mode with + * the firmware page tables, interrupts off and r1 = return to the monitor. + * It reads the kernel with the ROM disk service, stops the LAN controller + * and masks the 82380 interrupt banks, then enters the kernel. + * + * ROM ABI: vector table at 0xfffe0000, arguments in r16-r27, result in + * r16, r1-r15 preserved. + * + * Copyright (C) 2026 René Rebe + */ + +#define ROM_HD_READ 0x04 +#define ROM_PUTS 0x3c +#define ROM_LAN_INIT 0x40 +#define CHUNK 64 /* blocks per read: the DMA SRAM holds 256 KB */ + + .text + .globl _start +_start: + mov %r1,%r15 + orh 0xfffe,%r0,%r14 /* ROM vectors */ + orh [msg_load]@h,%r0,%r16 + or [msg_load]@l,%r16,%r16 + ld.l ROM_PUTS(%r14),%r31 + calli %r31 + nop + + orh [KERNEL_LBA]@h,%r0,%r4 + or [KERNEL_LBA]@l,%r4,%r4 /* next LBA */ + orh [KERNEL_SECTORS]@h,%r0,%r5 + or [KERNEL_SECTORS]@l,%r5,%r5 /* blocks left */ + orh [KERNEL_LOAD]@h,%r0,%r6 + or [KERNEL_LOAD]@l,%r6,%r6 /* destination */ + +1: bte 0,%r5,3f + mov %r5,%r7 + subs CHUNK,%r5,%r0 /* CC = left > CHUNK */ + bnc 2f + or CHUNK,%r0,%r7 +2: mov %r6,%r16 + mov %r4,%r17 + mov %r7,%r18 + ld.l ROM_HD_READ(%r14),%r31 + calli %r31 + nop + btne 0,%r16,9f + addu %r7,%r4,%r4 + subs %r5,%r7,%r5 + shl 9,%r7,%r7 + br 1b + addu %r7,%r6,%r6 + + /* lan_init(0, io, nvram, 0x20) only resets the 82596 */ +3: mov %r0,%r16 + orh 0x1c00,%r0,%r17 + orh 0x1f00,%r0,%r18 + or 0x20,%r0,%r19 + ld.l ROM_LAN_INIT(%r14),%r31 + calli %r31 + nop + + orh 0x1c00,%r0,%r4 + or 0xff,%r0,%r5 + st.b %r5,0x260(%r4) /* bank A IMR */ + st.b %r5,0x240(%r4) /* bank B IMR */ + st.b %r5,0x340(%r4) /* bank C IMR */ + + orh [KERNEL_ENTRY]@h,%r0,%r4 + or [KERNEL_ENTRY]@l,%r4,%r4 + mov %r0,%r16 + bri %r4 + nop + +9: orh [msg_err]@h,%r0,%r16 + or [msg_err]@l,%r16,%r16 + ld.l ROM_PUTS(%r14),%r31 + calli %r31 + nop + bri %r15 + nop + +msg_load: + .ascii "Loading Linux...\r\n\0" +msg_err: + .ascii "Disk read error\r\n\0" diff --git a/arch/i860/configs/magicst2_defconfig b/arch/i860/configs/magicst2_defconfig new file mode 100644 index 000000000000..734c4545033f --- /dev/null +++ b/arch/i860/configs/magicst2_defconfig @@ -0,0 +1,77 @@ +CONFIG_LOCALVERSION="-i860" +# CONFIG_LOCALVERSION_AUTO is not set +CONFIG_SWAP=y +CONFIG_SYSVIPC=y +CONFIG_LOG_BUF_SHIFT=14 +CONFIG_BLK_DEV_INITRD=y +CONFIG_CC_OPTIMIZE_FOR_SIZE=y +CONFIG_EXPERT=y +CONFIG_MULTIUSER=y +CONFIG_EPOLL=y +# CONFIG_IO_URING is not set +CONFIG_ADVISE_SYSCALLS=y +CONFIG_MEMBARRIER=y +# CONFIG_KALLSYMS_ALL is not set +# CONFIG_RSEQ is not set +# CONFIG_PROFILING is not set +CONFIG_HZ_100=y +CONFIG_MODULES=y +CONFIG_MODULE_UNLOAD=y +CONFIG_DEVTMPFS=y +CONFIG_DEVTMPFS_MOUNT=y +# CONFIG_FW_LOADER is not set +# CONFIG_LEGACY_PTYS is not set +CONFIG_SERIAL_8250=y +CONFIG_SERIAL_8250_CONSOLE=y +CONFIG_SERIAL_8250_NR_UARTS=2 +CONFIG_SERIAL_8250_RUNTIME_UARTS=2 +# CONFIG_HW_RANDOM is not set +# CONFIG_HWMON is not set +# CONFIG_USB_SUPPORT is not set +CONFIG_FILE_LOCKING=y +CONFIG_TMPFS=y +CONFIG_PRINTK_TIME=y +CONFIG_PANIC_TIMEOUT=0 +# CONFIG_DEBUG_MISC is not set +# CONFIG_FTRACE is not set +CONFIG_NET=y +CONFIG_PACKET=y +CONFIG_UNIX=y +CONFIG_INET=y +CONFIG_IPV6=y +# CONFIG_WIRELESS is not set +CONFIG_PARTITION_ADVANCED=y +CONFIG_MSDOS_PARTITION=y +CONFIG_BLK_DEV_FD=y +CONFIG_SCSI=y +CONFIG_BLK_DEV_SD=y +CONFIG_MAGICST2_SCSI=y +CONFIG_NETDEVICES=y +CONFIG_NET_VENDOR_INTEL=y +CONFIG_NET_VENDOR_I825XX=y +CONFIG_MAGICST2_82596=y +CONFIG_INPUT_KEYBOARD=y +CONFIG_KEYBOARD_ATKBD=y +# CONFIG_INPUT_MOUSE is not set +CONFIG_SERIO=y +CONFIG_SERIO_I8042=y +CONFIG_VT=y +CONFIG_VT_CONSOLE=y +CONFIG_FB=y +CONFIG_FB_MAGICST2=y +CONFIG_FRAMEBUFFER_CONSOLE=y +CONFIG_FRAMEBUFFER_CONSOLE_LEGACY_ACCELERATION=y +CONFIG_RTC_CLASS=y +CONFIG_RTC_DRV_MSM6242=y +CONFIG_EXT2_FS=y +CONFIG_MSDOS_FS=y +CONFIG_VFAT_FS=y +CONFIG_NLS_CODEPAGE_437=y +CONFIG_NLS_ISO8859_1=y +CONFIG_POSIX_MQUEUE=y +CONFIG_CGROUPS=y +CONFIG_BLK_DEV_LOOP=y +CONFIG_EXT4_FS=y +CONFIG_COMPACTION=y +CONFIG_HIGH_RES_TIMERS=y +CONFIG_ISO9660_FS=m diff --git a/arch/i860/include/asm/Kbuild b/arch/i860/include/asm/Kbuild new file mode 100644 index 000000000000..d69f4fdcadc2 --- /dev/null +++ b/arch/i860/include/asm/Kbuild @@ -0,0 +1,11 @@ +# SPDX-License-Identifier: GPL-2.0 +syscall-y += syscall_table_32.h + +generic-y += cmpxchg.h +generic-y += extable.h +generic-y += kvm_para.h +generic-y += mcs_spinlock.h +generic-y += parport.h +generic-y += spinlock.h +generic-y += text-patching.h +generic-y += user.h diff --git a/arch/i860/include/asm/asm-offsets.h b/arch/i860/include/asm/asm-offsets.h new file mode 100644 index 000000000000..9f8535716392 --- /dev/null +++ b/arch/i860/include/asm/asm-offsets.h @@ -0,0 +1,2 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#include diff --git a/arch/i860/include/asm/cache.h b/arch/i860/include/asm/cache.h new file mode 100644 index 000000000000..605b8bc81931 --- /dev/null +++ b/arch/i860/include/asm/cache.h @@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (C) 2026 René Rebe */ +#ifndef _ASM_I860_CACHE_H +#define _ASM_I860_CACHE_H + +#define L1_CACHE_SHIFT 5 +#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT) + +#endif diff --git a/arch/i860/include/asm/cacheflush.h b/arch/i860/include/asm/cacheflush.h new file mode 100644 index 000000000000..673cc6177d11 --- /dev/null +++ b/arch/i860/include/asm/cacheflush.h @@ -0,0 +1,55 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * The i860XR data cache (8 KB, 2-way, 32-byte lines; XP: 16 KB, 4-way) is + * virtually tagged without address-space IDs, and only a whole-cache + * write-back by set and way exists: one way spans a page, so even a single + * page needs all of it. The gain is in flushing less often, see cacheflush.c. + * Instruction cache and TLB are invalidated together through dirbase.ITI. + * Copyright (C) 2026 René Rebe + */ +#ifndef _ASM_I860_CACHEFLUSH_H +#define _ASM_I860_CACHEFLUSH_H + +#include + +void i860_flush_dcache_all(void); +void local_flush_tlb_all(void); + +/* write back the data cache, then drop stale instructions and TLB entries */ +static inline void i860_flush_icache_all(void) +{ + i860_flush_dcache_all(); + local_flush_tlb_all(); +} + +#define flush_cache_all() i860_flush_dcache_all() +#define flush_cache_mm(mm) i860_flush_dcache_all() +#define flush_cache_dup_mm(mm) i860_flush_dcache_all() +#define flush_cache_range(vma, start, end) i860_flush_dcache_all() +#define flush_cache_page(vma, vmaddr, pfn) i860_flush_dcache_all() +#define flush_cache_vmap(start, end) i860_flush_dcache_all() +#define flush_cache_vunmap(start, end) i860_flush_dcache_all() + +#define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1 +void flush_dcache_folio(struct folio *folio); +#define flush_dcache_folio flush_dcache_folio +void flush_dcache_page(struct page *page); + +#define flush_icache_range(start, end) i860_flush_icache_all() +#define flush_icache_user_page(vma, page, addr, len) i860_flush_icache_all() + +#define copy_to_user_page(vma, page, vaddr, dst, src, len) \ + do { \ + memcpy(dst, src, len); \ + i860_flush_icache_all(); \ + } while (0) + +#define copy_from_user_page(vma, page, vaddr, dst, src, len) \ + do { \ + i860_flush_dcache_all(); \ + memcpy(dst, src, len); \ + } while (0) + +#include + +#endif diff --git a/arch/i860/include/asm/clocksource.h b/arch/i860/include/asm/clocksource.h new file mode 100644 index 000000000000..0145fe22bbf9 --- /dev/null +++ b/arch/i860/include/asm/clocksource.h @@ -0,0 +1,8 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (C) 2026 René Rebe */ +#ifndef _ASM_I860_CLOCKSOURCE_H +#define _ASM_I860_CLOCKSOURCE_H + +#include + +#endif diff --git a/arch/i860/include/asm/dma.h b/arch/i860/include/asm/dma.h new file mode 100644 index 000000000000..9c67dae12c57 --- /dev/null +++ b/arch/i860/include/asm/dma.h @@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (C) 2026 René Rebe */ +#ifndef _ASM_I860_DMA_H +#define _ASM_I860_DMA_H + +#include + +#define MAX_DMA_ADDRESS PAGE_OFFSET + +/* used by floppy.c to tell the transfer direction */ +#define DMA_MODE_READ 0x44 +#define DMA_MODE_WRITE 0x48 + +/* no ISA DMA: the floppy driver only needs the lock helpers */ +static inline unsigned long claim_dma_lock(void) +{ + unsigned long flags; + + local_irq_save(flags); + return flags; +} + +static inline void release_dma_lock(unsigned long flags) +{ + local_irq_restore(flags); +} + +#endif diff --git a/arch/i860/include/asm/elf.h b/arch/i860/include/asm/elf.h new file mode 100644 index 000000000000..c7b06fcd529b --- /dev/null +++ b/arch/i860/include/asm/elf.h @@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (C) 2026 René Rebe */ +#ifndef _ASM_I860_ELF_H +#define _ASM_I860_ELF_H + +#include +#include + +#define ELF_ARCH EM_860 +#define ELF_CLASS ELFCLASS32 +#define ELF_DATA ELFDATA2LSB + +#define elf_check_arch(x) ((x)->e_machine == EM_860) + +typedef unsigned long elf_greg_t; +#define ELF_NGREG (sizeof(struct user_regs_struct) / sizeof(elf_greg_t)) +typedef elf_greg_t elf_gregset_t[ELF_NGREG]; +typedef unsigned long elf_fpregset_t[32]; + +#define CORE_DUMP_USE_REGSET + +#define ELF_EXEC_PAGESIZE 4096 + +#define ARCH_DLINFO \ + NEW_AUX_ENT(AT_SYSINFO_EHDR, (elf_addr_t)current->mm->context.vdso) + +#define ARCH_HAS_SETUP_ADDITIONAL_PAGES +struct linux_binprm; +int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp); +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2) + +#define ELF_HWCAP 0 +#define ELF_PLATFORM NULL + +#define ELF_PLAT_INIT(regs, load_addr) do { } while (0) + +#endif diff --git a/arch/i860/include/asm/entry-common.h b/arch/i860/include/asm/entry-common.h new file mode 100644 index 000000000000..fe0bbd6d0c38 --- /dev/null +++ b/arch/i860/include/asm/entry-common.h @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (C) 2026 René Rebe */ +#ifndef _ASM_I860_ENTRY_COMMON_H +#define _ASM_I860_ENTRY_COMMON_H + +#include +#include + +static __always_inline bool on_thread_stack(void) +{ + return !((current_stack_pointer ^ (unsigned long)task_stack_page(current)) & + ~(THREAD_SIZE - 1)); +} + +#endif diff --git a/arch/i860/include/asm/floppy.h b/arch/i860/include/asm/floppy.h new file mode 100644 index 000000000000..6471699ed231 --- /dev/null +++ b/arch/i860/include/asm/floppy.h @@ -0,0 +1,77 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * 82077 floppy controller on the MAGIC Station II: registers at + * 0x1c000c00 + 8 * n, IRQ 15, 82380 DMA channel 0 through the DMA buffer + * SRAM. floppy_interrupt() calls fd_disable_dma() first, which copies a + * completed read back from the SRAM. + * Copyright (C) 2026 René Rebe + */ +#ifndef _ASM_I860_FLOPPY_H +#define _ASM_I860_FLOPPY_H + +#include +#include +#include + +/* floppy.c's FLOPPY_IRQ/FLOPPY_DMA parameters do not apply: both are fixed */ +#define I860_FLOPPY_IRQ 15 +#define FDC_PHYS 0x1c000c00 + +/* fdc_state[].address only has to be valid; the registers are fixed */ +static int FDC1 = 0x3f0; + +#define N_FDC 1 +#define N_DRIVE 8 +#define FLOPPY0_TYPE 4 /* 1.44 MB, 3.5" */ +#define FLOPPY1_TYPE 0 + +#define fd_inb(base, reg) readb(I860_IO(FDC_PHYS) + ((reg) << 3)) +#define fd_outb(value, base, reg) writeb(value, I860_IO(FDC_PHYS) + ((reg) << 3)) + +#define fd_request_dma() ((void)FLOPPY_DMA, 0) +#define fd_free_dma() do { } while (0) +#define fd_enable_irq() enable_irq(I860_FLOPPY_IRQ) +#define fd_disable_irq() disable_irq(I860_FLOPPY_IRQ) +#define fd_free_irq() free_irq(I860_FLOPPY_IRQ, NULL) +#define fd_get_dma_residue() i860_dma_residue(I860_DMA_FLOPPY) + +static inline int fd_request_irq(void) +{ + (void)FLOPPY_IRQ; + (void)virtual_dma_port; + return request_irq(I860_FLOPPY_IRQ, floppy_interrupt, 0, "floppy", NULL); +} + +static char *fd_dma_buf; +static size_t fd_dma_len; +static bool fd_dma_read; + +static inline void fd_disable_dma(void) +{ + size_t done; + + i860_dma_stop(I860_DMA_FLOPPY); + if (fd_dma_buf && fd_dma_read) { + done = fd_dma_len - min(i860_dma_residue(I860_DMA_FLOPPY), fd_dma_len); + i860_sram_read(fd_dma_buf, I860_SRAM_FLOPPY, done); + } + fd_dma_buf = NULL; +} + +static inline int fd_dma_setup(char *addr, unsigned long size, int mode, int io) +{ + if (size > I860_SRAM_FLOPPY_SIZE) + return -EINVAL; + fd_dma_read = mode == DMA_MODE_READ; + if (!fd_dma_read) + i860_sram_write(I860_SRAM_FLOPPY, addr, size); + fd_dma_buf = addr; + fd_dma_len = size; + i860_dma_start(I860_DMA_FLOPPY, I860_SRAM_FLOPPY, size, !fd_dma_read); + return 0; +} +#define fd_dma_setup fd_dma_setup + +#define EXTRA_FLOPPY_PARAMS + +#endif diff --git a/arch/i860/include/asm/i860-dma.h b/arch/i860/include/asm/i860-dma.h new file mode 100644 index 000000000000..1a223df167b3 --- /dev/null +++ b/arch/i860/include/asm/i860-dma.h @@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * 82380 DMA on the MAGIC Station II: fly-by transfers between a device and + * the 256 KB DMA buffer SRAM at 0x18000000, which holds one 32-bit word + * per 8 CPU bytes. Data is bounced between memory and the SRAM by the CPU. + * Copyright (C) 2026 René Rebe + */ +#ifndef _ASM_I860_I860_DMA_H +#define _ASM_I860_I860_DMA_H + +#include + +#define I860_DMA_FLOPPY 0 +#define I860_DMA_SCSI 1 + +/* SRAM partition (DMA byte offsets), as in the Stardent kernel */ +#define I860_SRAM_SCSI 0x00000 +#define I860_SRAM_SCSI_SIZE 0x30000 +#define I860_SRAM_FLOPPY 0x30000 +#define I860_SRAM_FLOPPY_SIZE 0x08000 + +void i860_dma_start(unsigned int ch, unsigned long sram, size_t len, + bool to_device); +void i860_dma_stop(unsigned int ch); +size_t i860_dma_residue(unsigned int ch); +void i860_sram_write(unsigned long sram, const void *buf, size_t len); +void i860_sram_read(void *buf, unsigned long sram, size_t len); + +#endif diff --git a/arch/i860/include/asm/i860.h b/arch/i860/include/asm/i860.h new file mode 100644 index 000000000000..2de2544d83f3 --- /dev/null +++ b/arch/i860/include/asm/i860.h @@ -0,0 +1,103 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Intel i860 control registers and fixed kernel layout. + * Copyright (C) 2026 René Rebe + */ +#ifndef _ASM_I860_I860_H +#define _ASM_I860_I860_H + +#include + +/* psr */ +#define PSR_BR 0x00000001 +#define PSR_BW 0x00000002 +#define PSR_CC 0x00000004 +#define PSR_LCC 0x00000008 +#define PSR_IM 0x00000010 +#define PSR_PIM 0x00000020 +#define PSR_U 0x00000040 +#define PSR_PU 0x00000080 +#define PSR_IT 0x00000100 +#define PSR_IN 0x00000200 +#define PSR_IAT 0x00000400 +#define PSR_DAT 0x00000800 +#define PSR_FT 0x00001000 +#define PSR_DS 0x00002000 +#define PSR_DIM 0x00004000 +#define PSR_KNF 0x00008000 +#define PSR_TRAPS 0x00001f00 + +/* epsr */ +#define EPSR_TYPE 0x000000ff +#define EPSR_IL 0x00002000 +#define EPSR_WP 0x00004000 +#define EPSR_INT 0x00020000 +#define EPSR_BE 0x00800000 +#define EPSR_OF 0x01000000 +#define EPSR_OF_H 0x0100 /* for andh */ +#define EPSR_TYPE_XP 2 + +/* dirbase */ +#define DIRBASE_ATE 0x00000001 +#define DIRBASE_ITI 0x00000020 +#define DIRBASE_CS8 0x00000080 +#define DIRBASE_RB 0x00000300 +#define DIRBASE_RC 0x00000c00 +#define DIRBASE_RC_FLUSH 0x00000800 +#define DIRBASE_DTB 0xfffff000 + +/* fsr */ +#define FSR_FZ 0x00000001 +#define FSR_TI 0x00000002 +#define FSR_RM 0x0000000c +#define FSR_U 0x00000010 +#define FSR_FTE 0x00000020 +#define FSR_RESULT 0x0000ee00 /* M and A underflow, overflow, inexact */ +#define FSR_SI 0x00000080 +#define FSR_SE 0x00000100 + +/* + * The CPU enters every trap at virtual 0xffffff00 with no free register. + * The last page holds the vector and scratch words that the entry code + * reaches as negative offsets from r0. + */ +#define I860_TRAP_PAGE _AC(0xfffff000, UL) +/* Firmware page tables, data, stack and code; unused once we own the MMU. */ +#define I860_FW_START _AC(0xfffae000, UL) +/* paging_init allocates from what lies between: 64 MB of page tables and the directory */ +#define I860_EARLY_ALLOC _AC(0x14000, UL) +#define I860_TRAP_VECTOR _AC(0xffffff00, UL) +#define I860_TRAP_VECTOR_MAX 0xb0 +#define SCR_KSP -4 /* top of the current kernel stack */ +#define SCR_PSR -8 +#define SCR_R2 -12 +#define SCR_R1 -16 +#define SCR_EXIT -20 + +/* DRAM is identity mapped: virtual = physical. */ +#define I860_LOWMEM_BASE _AC(0xfc000000, UL) + +/* Physical 0x1c000000-0x1fffffff (82380, SCSI, FDC, LAN, RTC, UART, NVRAM) */ +#define I860_IO_PHYS _AC(0x1c000000, UL) +#define I860_IO_SIZE _AC(0x04000000, UL) +#define I860_IO_VIRT _AC(0xf8000000, UL) + +#define I860_VMALLOC_START _AC(0xe0000000, UL) +#define I860_VMALLOC_END I860_IO_VIRT +#define I860_MODULES_VADDR (I860_IO_VIRT - _AC(0x08000000, UL)) + +#ifndef __ASSEMBLER__ + +#define i860_ld_c(reg) \ +({ \ + unsigned long __v; \ + asm volatile("ld.c %%" #reg ",%0" : "=r" (__v)); \ + __v; \ +}) + +#define i860_st_c(reg, v) \ + asm volatile("st.c %0,%%" #reg : : "r" ((unsigned long)(v)) : "memory") + +#endif + +#endif diff --git a/arch/i860/include/asm/io.h b/arch/i860/include/asm/io.h new file mode 100644 index 000000000000..0c32b560c9f1 --- /dev/null +++ b/arch/i860/include/asm/io.h @@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (C) 2026 René Rebe */ +#ifndef _ASM_I860_IO_H +#define _ASM_I860_IO_H + +#include +#include +#include + +/* On-board devices sit in the static window at I860_IO_VIRT. */ +#define I860_IO(phys) ((void __iomem *)((phys) - I860_IO_PHYS + I860_IO_VIRT)) + +#define ioremap_prot ioremap_prot +#define iounmap iounmap + +#include + +#endif diff --git a/arch/i860/include/asm/irq.h b/arch/i860/include/asm/irq.h new file mode 100644 index 000000000000..5d9a3cd9b231 --- /dev/null +++ b/arch/i860/include/asm/irq.h @@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (C) 2026 René Rebe */ +#ifndef _ASM_I860_IRQ_H +#define _ASM_I860_IRQ_H + +/* 82380: three cascaded 8-input banks, vector = IRQ number. */ +#define NR_IRQS 24 + +#include + +#endif diff --git a/arch/i860/include/asm/irqflags.h b/arch/i860/include/asm/irqflags.h new file mode 100644 index 000000000000..66217dfeb865 --- /dev/null +++ b/arch/i860/include/asm/irqflags.h @@ -0,0 +1,48 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (C) 2026 René Rebe */ +#ifndef _ASM_I860_IRQFLAGS_H +#define _ASM_I860_IRQFLAGS_H + +#include + +static inline unsigned long arch_local_save_flags(void) +{ + return i860_ld_c(psr); +} + +static inline void arch_local_irq_restore(unsigned long flags) +{ + unsigned long psr = i860_ld_c(psr); + + i860_st_c(psr, (psr & ~PSR_IM) | (flags & PSR_IM)); +} + +static inline unsigned long arch_local_irq_save(void) +{ + unsigned long psr = i860_ld_c(psr); + + i860_st_c(psr, psr & ~PSR_IM); + return psr; +} + +static inline void arch_local_irq_disable(void) +{ + i860_st_c(psr, i860_ld_c(psr) & ~PSR_IM); +} + +static inline void arch_local_irq_enable(void) +{ + i860_st_c(psr, i860_ld_c(psr) | PSR_IM); +} + +static inline int arch_irqs_disabled_flags(unsigned long flags) +{ + return !(flags & PSR_IM); +} + +static inline int arch_irqs_disabled(void) +{ + return arch_irqs_disabled_flags(arch_local_save_flags()); +} + +#endif diff --git a/arch/i860/include/asm/linkage.h b/arch/i860/include/asm/linkage.h new file mode 100644 index 000000000000..9ddca4503b0a --- /dev/null +++ b/arch/i860/include/asm/linkage.h @@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (C) 2026 René Rebe */ +#ifndef _ASM_I860_LINKAGE_H +#define _ASM_I860_LINKAGE_H + +#define __ALIGN .align 8 +#define __ALIGN_STR ".align 8" + +#endif diff --git a/arch/i860/include/asm/mc146818rtc.h b/arch/i860/include/asm/mc146818rtc.h new file mode 100644 index 000000000000..32817ffd4a9c --- /dev/null +++ b/arch/i860/include/asm/mc146818rtc.h @@ -0,0 +1,8 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (C) 2026 René Rebe */ +#ifndef _ASM_I860_MC146818RTC_H +#define _ASM_I860_MC146818RTC_H + +/* no MC146818 CMOS: the RTC is an MSM6242 (rtc-msm6242) */ + +#endif diff --git a/arch/i860/include/asm/mmu.h b/arch/i860/include/asm/mmu.h new file mode 100644 index 000000000000..63e0fb6752f5 --- /dev/null +++ b/arch/i860/include/asm/mmu.h @@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (C) 2026 René Rebe */ +#ifndef _ASM_I860_MMU_H +#define _ASM_I860_MMU_H + +typedef struct { + void *vdso; +} mm_context_t; + +#endif diff --git a/arch/i860/include/asm/mmu_context.h b/arch/i860/include/asm/mmu_context.h new file mode 100644 index 000000000000..dedea452f233 --- /dev/null +++ b/arch/i860/include/asm/mmu_context.h @@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (C) 2026 René Rebe */ +#ifndef _ASM_I860_MMU_CONTEXT_H +#define _ASM_I860_MMU_CONTEXT_H + +#include +#include +#include + +extern void i860_set_pgd(pgd_t *pgd); + +static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next, + struct task_struct *tsk) +{ + /* virtually tagged cache: write back while the old mapping is live */ + if (prev != next) { + i860_flush_dcache_all(); + i860_set_pgd(next->pgd); + } +} + +#include +#include + +#endif diff --git a/arch/i860/include/asm/module.h b/arch/i860/include/asm/module.h new file mode 100644 index 000000000000..a08748dc69a6 --- /dev/null +++ b/arch/i860/include/asm/module.h @@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (C) 2026 René Rebe */ +#ifndef _ASM_I860_MODULE_H +#define _ASM_I860_MODULE_H + +#include + +/* the types that non-PIC kernel code uses */ +#define R_860_NONE 0x00 +#define R_860_32 0x01 +#define R_860_PC26 0x30 +#define R_860_PC16 0x32 +#define R_860_LOW0 0x40 +#define R_860_SPLIT0 0x42 +#define R_860_LOW1 0x44 +#define R_860_SPLIT1 0x46 +#define R_860_LOW2 0x48 +#define R_860_SPLIT2 0x4a +#define R_860_LOW3 0x4c +#define R_860_HIGHADJ 0x80 +#define R_860_HIGH 0xc0 + +struct mod_arch_specific { + unsigned int plt_shndx; + unsigned int plt_max; + unsigned int plt_used; +}; + +#endif diff --git a/arch/i860/include/asm/module.lds.h b/arch/i860/include/asm/module.lds.h new file mode 100644 index 000000000000..dfa7d766ee7b --- /dev/null +++ b/arch/i860/include/asm/module.lds.h @@ -0,0 +1,5 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (C) 2026 René Rebe */ +SECTIONS { + .plt 0 : { BYTE(0) } +} diff --git a/arch/i860/include/asm/page.h b/arch/i860/include/asm/page.h new file mode 100644 index 000000000000..014f98b01ac2 --- /dev/null +++ b/arch/i860/include/asm/page.h @@ -0,0 +1,59 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (C) 2026 René Rebe */ +#ifndef _ASM_I860_PAGE_H +#define _ASM_I860_PAGE_H + +#include +#include +#include + +#define PAGE_OFFSET I860_LOWMEM_BASE + +#ifndef __ASSEMBLER__ + +#include + +/* Lowest DRAM page: the bank layout is only known at boot. */ +extern unsigned long i860_pfn_offset; +#define ARCH_PFN_OFFSET i860_pfn_offset + +#define clear_page(page) memset((page), 0, PAGE_SIZE) +#define copy_page(to, from) memcpy((to), (from), PAGE_SIZE) + +#define clear_user_page(page, vaddr, pg) \ + do { (void)(vaddr); (void)(pg); clear_page(page); } while (0) +#define copy_user_page(to, from, vaddr, pg) \ + do { (void)(vaddr); (void)(pg); copy_page(to, from); } while (0) + +typedef struct { unsigned long pte; } pte_t; +typedef struct { unsigned long pgd; } pgd_t; +typedef struct { unsigned long pgprot; } pgprot_t; +typedef struct page *pgtable_t; + +#define pte_val(x) ((x).pte) +#define pgd_val(x) ((x).pgd) +#define pgprot_val(x) ((x).pgprot) + +#define __pte(x) ((pte_t) { (x) }) +#define __pgd(x) ((pgd_t) { (x) }) +#define __pgprot(x) ((pgprot_t) { (x) }) + +#define __pa(x) ((unsigned long)(x)) +#define __va(x) ((void *)(unsigned long)(x)) + +#define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT) +#define virt_to_pfn(kaddr) (__pa(kaddr) >> PAGE_SHIFT) +#define virt_to_page(kaddr) pfn_to_page(virt_to_pfn(kaddr)) +#define page_to_virt(page) pfn_to_kaddr(page_to_pfn(page)) +#define virt_addr_valid(kaddr) \ + ((unsigned long)(kaddr) >= PAGE_OFFSET && \ + pfn_valid(virt_to_pfn(kaddr))) + +#define VMA_DATA_DEFAULT_FLAGS VMA_DATA_FLAGS_NON_EXEC + +#include +#include + +#endif /* __ASSEMBLER__ */ + +#endif diff --git a/arch/i860/include/asm/pgalloc.h b/arch/i860/include/asm/pgalloc.h new file mode 100644 index 000000000000..f4ac76c55798 --- /dev/null +++ b/arch/i860/include/asm/pgalloc.h @@ -0,0 +1,61 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (C) 2026 René Rebe */ +#ifndef _ASM_I860_PGALLOC_H +#define _ASM_I860_PGALLOC_H + +#include +#include + +#define __HAVE_ARCH_PTE_ALLOC_ONE_KERNEL +#define __HAVE_ARCH_PTE_ALLOC_ONE +#define __HAVE_ARCH_PGD_FREE +#include + +/* The hardware walks page tables in memory: keep them uncached. */ +static inline pte_t *pte_alloc_one_kernel_noprof(struct mm_struct *mm) +{ + pte_t *pte = __pte_alloc_one_kernel_noprof(mm); + + if (pte) + i860_set_cacheable(pte, false); + return pte; +} +#define pte_alloc_one_kernel(...) alloc_hooks(pte_alloc_one_kernel_noprof(__VA_ARGS__)) + +static inline pgtable_t pte_alloc_one_noprof(struct mm_struct *mm) +{ + pgtable_t pte = __pte_alloc_one_noprof(mm, GFP_PGTABLE_USER); + + if (pte) + i860_set_cacheable(page_address(pte), false); + return pte; +} +#define pte_alloc_one(...) alloc_hooks(pte_alloc_one_noprof(__VA_ARGS__)) + +static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd) +{ + i860_set_cacheable(pgd, true); + __pgd_free(mm, pgd); +} + +static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd, + pte_t *pte) +{ + set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE)); +} + +static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd, + pgtable_t pte) +{ + set_pmd(pmd, __pmd(page_to_phys(pte) | _PAGE_TABLE)); +} + +extern pgd_t *pgd_alloc(struct mm_struct *mm); + +#define __pte_free_tlb(tlb, pte, addr) \ + do { \ + i860_set_cacheable(page_address(pte), true); \ + tlb_remove_ptdesc((tlb), page_ptdesc(pte)); \ + } while (0) + +#endif diff --git a/arch/i860/include/asm/pgtable.h b/arch/i860/include/asm/pgtable.h new file mode 100644 index 000000000000..af1c59234caa --- /dev/null +++ b/arch/i860/include/asm/pgtable.h @@ -0,0 +1,171 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * i860 two-level page tables: 1024 PDEs of 4 MB, 1024 PTEs of 4 KB. + * The hardware walks them physically, sets A, and traps writes to pages + * with D clear, so dirty tracking is done in software. + * + * Copyright (C) 2026 René Rebe + */ +#ifndef _ASM_I860_PGTABLE_H +#define _ASM_I860_PGTABLE_H + +#include +#include +#include + +#define _PAGE_PRESENT 0x001 +#define _PAGE_RW 0x002 +#define _PAGE_USER 0x004 +#define _PAGE_WT 0x008 +#define _PAGE_CD 0x010 +#define _PAGE_ACCESSED 0x020 +#define _PAGE_DIRTY 0x040 +/* bits 9-11 are free for software */ +#define _PAGE_PROTNONE 0x200 +#define _PAGE_SWP_EXCLUSIVE 0x400 + +/* + * Memory is cached (see asm/cacheflush.h for the maintenance rules). + * The page-table walker reads memory, so page-table pages are uncached + * in the linear map (i860_set_cacheable). + */ +#define _PAGE_CACHE 0 + +#define _PAGE_TABLE (_PAGE_PRESENT | _PAGE_RW | _PAGE_USER | \ + _PAGE_ACCESSED | _PAGE_DIRTY | _PAGE_CD) +#define _PAGE_CHG_MASK (PAGE_MASK | _PAGE_ACCESSED | _PAGE_DIRTY) + +#define PAGE_NONE __pgprot(_PAGE_PROTNONE | _PAGE_ACCESSED | _PAGE_CACHE) +#define PAGE_SHARED __pgprot(_PAGE_PRESENT | _PAGE_RW | _PAGE_USER | \ + _PAGE_ACCESSED | _PAGE_CACHE) +#define PAGE_COPY __pgprot(_PAGE_PRESENT | _PAGE_USER | \ + _PAGE_ACCESSED | _PAGE_CACHE) +#define PAGE_READONLY PAGE_COPY +#define PAGE_KERNEL __pgprot(_PAGE_PRESENT | _PAGE_RW | _PAGE_ACCESSED | \ + _PAGE_DIRTY | _PAGE_CACHE) +#define PAGE_KERNEL_RO __pgprot(_PAGE_PRESENT | _PAGE_ACCESSED | \ + _PAGE_DIRTY | _PAGE_CACHE) +#define PAGE_KERNEL_EXEC PAGE_KERNEL +#define PAGE_KERNEL_NOCACHE __pgprot(pgprot_val(PAGE_KERNEL) | _PAGE_CD) +#define _PAGE_IOREMAP (_PAGE_PRESENT | _PAGE_RW | _PAGE_ACCESSED | \ + _PAGE_DIRTY | _PAGE_CD) + +#define PTRS_PER_PGD 1024 +#define PTRS_PER_PTE 1024 +#define PGDIR_SHIFT 22 +#define PGDIR_SIZE (1UL << PGDIR_SHIFT) +#define PGDIR_MASK (~(PGDIR_SIZE - 1)) +#define USER_PTRS_PER_PGD (TASK_SIZE / PGDIR_SIZE) +#define FIRST_USER_ADDRESS 0UL + +#define VMALLOC_START I860_VMALLOC_START +#define VMALLOC_END I860_VMALLOC_END +#define MODULES_VADDR I860_MODULES_VADDR +#define MODULES_END I860_VMALLOC_END + +#ifndef __ASSEMBLER__ + +#include + +extern pgd_t swapper_pg_dir[PTRS_PER_PGD]; + +static inline int pte_none(pte_t pte) { return !pte_val(pte); } +static inline int pte_present(pte_t pte) +{ + return pte_val(pte) & (_PAGE_PRESENT | _PAGE_PROTNONE); +} +static inline int pte_write(pte_t pte) { return pte_val(pte) & _PAGE_RW; } +static inline int pte_dirty(pte_t pte) { return pte_val(pte) & _PAGE_DIRTY; } +static inline int pte_young(pte_t pte) { return pte_val(pte) & _PAGE_ACCESSED; } + +#define PTE_BIT_FUNC(fn, op) \ + static inline pte_t pte_##fn(pte_t pte) { pte_val(pte) op; return pte; } + +PTE_BIT_FUNC(wrprotect, &= ~_PAGE_RW); +PTE_BIT_FUNC(mkwrite_novma, |= _PAGE_RW); +PTE_BIT_FUNC(mkclean, &= ~_PAGE_DIRTY); +PTE_BIT_FUNC(mkdirty, |= _PAGE_DIRTY); +PTE_BIT_FUNC(mkold, &= ~_PAGE_ACCESSED); +PTE_BIT_FUNC(mkyoung, |= _PAGE_ACCESSED); + +static inline pte_t pte_modify(pte_t pte, pgprot_t newprot) +{ + return __pte((pte_val(pte) & _PAGE_CHG_MASK) | + (pgprot_val(newprot) & ~_PAGE_CHG_MASK)); +} + +#define PFN_PTE_SHIFT PAGE_SHIFT +#define pte_pfn(pte) (pte_val(pte) >> PAGE_SHIFT) +#define pfn_pte(pfn, prot) __pte(((pfn) << PAGE_SHIFT) | pgprot_val(prot)) +#define pte_page(pte) pfn_to_page(pte_pfn(pte)) + +static inline void set_pte(pte_t *ptep, pte_t pte) +{ + *ptep = pte; +} + +static inline void pte_clear(struct mm_struct *mm, unsigned long addr, + pte_t *ptep) +{ + set_pte(ptep, __pte(0)); +} + +static inline int pmd_none(pmd_t pmd) { return !pmd_val(pmd); } +static inline int pmd_present(pmd_t pmd) { return pmd_val(pmd) & _PAGE_PRESENT; } +static inline int pmd_bad(pmd_t pmd) +{ + return (pmd_val(pmd) & ~PAGE_MASK) != _PAGE_TABLE; +} +static inline void set_pmd(pmd_t *pmdp, pmd_t pmd) { *pmdp = pmd; } +static inline void pmd_clear(pmd_t *pmdp) { set_pmd(pmdp, __pmd(0)); } + +#define pmd_pfn(pmd) (pmd_val(pmd) >> PAGE_SHIFT) +#define pmd_page(pmd) pfn_to_page(pmd_pfn(pmd)) + +static inline unsigned long pmd_page_vaddr(pmd_t pmd) +{ + return (unsigned long)__va(pmd_val(pmd) & PAGE_MASK); +} + +#define pgprot_noncached(prot) __pgprot(pgprot_val(prot) | _PAGE_CD) +#define pgprot_writecombine pgprot_noncached + +/* Swap entries: P = PROTNONE = 0, type in bits 1-5, offset in bits 12-31. */ +#define __swp_type(x) (((x).val >> 1) & 0x1f) +#define __swp_offset(x) ((x).val >> PAGE_SHIFT) +#define __swp_entry(type, offset) \ + ((swp_entry_t) { ((type) << 1) | ((offset) << PAGE_SHIFT) }) +#define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) }) +#define __swp_entry_to_pte(x) ((pte_t) { (x).val }) + +static inline bool pte_swp_exclusive(pte_t pte) +{ + return pte_val(pte) & _PAGE_SWP_EXCLUSIVE; +} + +static inline pte_t pte_swp_mkexclusive(pte_t pte) +{ + pte_val(pte) |= _PAGE_SWP_EXCLUSIVE; + return pte; +} + +static inline pte_t pte_swp_clear_exclusive(pte_t pte) +{ + pte_val(pte) &= ~_PAGE_SWP_EXCLUSIVE; + return pte; +} + +struct vm_fault; +struct vm_area_struct; + +void i860_set_cacheable(void *addr, bool cacheable); +void i860_flush_dcache_all(void); + +void update_mmu_cache_range(struct vm_fault *vmf, struct vm_area_struct *vma, + unsigned long addr, pte_t *ptep, unsigned int nr); +#define update_mmu_cache(vma, addr, ptep) \ + update_mmu_cache_range(NULL, vma, addr, ptep, 1) + +#endif /* __ASSEMBLER__ */ + +#endif diff --git a/arch/i860/include/asm/processor.h b/arch/i860/include/asm/processor.h new file mode 100644 index 000000000000..dfacb472935e --- /dev/null +++ b/arch/i860/include/asm/processor.h @@ -0,0 +1,43 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (C) 2026 René Rebe */ +#ifndef _ASM_I860_PROCESSOR_H +#define _ASM_I860_PROCESSOR_H + +#include +#include + +#define TASK_SIZE I860_VMALLOC_START +#define TASK_SIZE_MAX TASK_SIZE +#define STACK_TOP TASK_SIZE +#define STACK_TOP_MAX STACK_TOP +#define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3)) + +#ifndef __ASSEMBLER__ + +#include + +struct task_struct; +struct pt_regs; + +/* Callee-saved state lives in the switch frame on the kernel stack. */ +struct thread_struct { + unsigned long ksp; + unsigned long db; +}; + +#define INIT_THREAD { } + +#define task_pt_regs(tsk) \ + ((struct pt_regs *)(task_stack_page(tsk) + THREAD_SIZE) - 1) + +#define KSTK_EIP(tsk) (task_pt_regs(tsk)->user.fir) +#define KSTK_ESP(tsk) (task_pt_regs(tsk)->user.gpr[2]) + +void start_thread(struct pt_regs *regs, unsigned long pc, unsigned long sp); +unsigned long __get_wchan(struct task_struct *p); + +#define cpu_relax() barrier() + +#endif + +#endif diff --git a/arch/i860/include/asm/ptrace.h b/arch/i860/include/asm/ptrace.h new file mode 100644 index 000000000000..fbefce6aed58 --- /dev/null +++ b/arch/i860/include/asm/ptrace.h @@ -0,0 +1,40 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (C) 2026 René Rebe */ +#ifndef _ASM_I860_PTRACE_H +#define _ASM_I860_PTRACE_H + +#include +#include + +/* user thread pointer register of the Linux ABI */ +#define I860_TP_REG 30 + +#ifndef __ASSEMBLER__ + +/* Trap frame; the size keeps the stack 16-byte aligned for fst.q. */ +struct pt_regs { + struct user_regs_struct user; + unsigned long orig_r16; + long syscallno; + /* the trap instruction and mode, for a system call restart */ + unsigned long orig_fir; + unsigned long orig_psr; + struct i860_fp_pipe pipe; +}; + +#define user_mode(regs) (((regs)->user.psr & PSR_PU) != 0) +#define instruction_pointer(regs) ((regs)->user.fir) +#define user_stack_pointer(regs) ((regs)->user.gpr[2]) +#define profile_pc(regs) instruction_pointer(regs) +#define regs_return_value(regs) ((regs)->user.gpr[16]) + +static inline bool regs_irqs_disabled(struct pt_regs *regs) +{ + return !(regs->user.psr & PSR_PIM); +} + +#define current_pt_regs() task_pt_regs(current) + +#endif + +#endif diff --git a/arch/i860/include/asm/setup.h b/arch/i860/include/asm/setup.h new file mode 100644 index 000000000000..60e4f688dc25 --- /dev/null +++ b/arch/i860/include/asm/setup.h @@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (C) 2026 René Rebe */ +#ifndef _ASM_I860_SETUP_H +#define _ASM_I860_SETUP_H + +#include + +#ifndef __ASSEMBLER__ +void paging_init(void); +void i860_early_console_init(void); +void i860_flush_dcache_all(void); +#endif + +#endif diff --git a/arch/i860/include/asm/string.h b/arch/i860/include/asm/string.h new file mode 100644 index 000000000000..04b79173f4f1 --- /dev/null +++ b/arch/i860/include/asm/string.h @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (C) 2026 René Rebe */ +#ifndef _ASM_I860_STRING_H +#define _ASM_I860_STRING_H + +/* arch/i860/lib: 128-bit fld.q/fst.q transfers */ +#define __HAVE_ARCH_MEMCPY +#define __HAVE_ARCH_MEMMOVE +#define __HAVE_ARCH_MEMSET + +extern void *memcpy(void *dst, const void *src, __kernel_size_t n); +extern void *memmove(void *dst, const void *src, __kernel_size_t n); +extern void *memset(void *s, int c, __kernel_size_t n); + +#endif diff --git a/arch/i860/include/asm/switch_to.h b/arch/i860/include/asm/switch_to.h new file mode 100644 index 000000000000..67cf7ce8cd92 --- /dev/null +++ b/arch/i860/include/asm/switch_to.h @@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (C) 2026 René Rebe */ +#ifndef _ASM_I860_SWITCH_TO_H +#define _ASM_I860_SWITCH_TO_H + +#include + +struct task_struct; + +extern struct task_struct *__switch_to(struct task_struct *prev, + struct task_struct *next); + +#define switch_to(prev, next, last) \ + do { \ + i860_st_c(db, (next)->thread.db); \ + (last) = __switch_to(prev, next); \ + } while (0) + +#endif diff --git a/arch/i860/include/asm/syscall.h b/arch/i860/include/asm/syscall.h new file mode 100644 index 000000000000..2a72a3de712d --- /dev/null +++ b/arch/i860/include/asm/syscall.h @@ -0,0 +1,90 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Syscall ABI: trap r0,r0,r0 with the number in r28 and the arguments in + * r16-r21; the result comes back in r16. + * Copyright (C) 2026 René Rebe + */ +#ifndef _ASM_I860_SYSCALL_H +#define _ASM_I860_SYSCALL_H + +#include +#include +#include +#include +#include + +#define I860_SYSCALL_NR_REG 28 +#define I860_SYSCALL_ARG_REG 16 + +extern void * const sys_call_table[]; + +static inline int syscall_get_nr(struct task_struct *task, + struct pt_regs *regs) +{ + return regs->syscallno; +} + +static inline void syscall_set_nr(struct task_struct *task, + struct pt_regs *regs, int nr) +{ + regs->syscallno = nr; +} + +static inline void syscall_rollback(struct task_struct *task, + struct pt_regs *regs) +{ + regs->user.gpr[16] = regs->orig_r16; +} + +static inline long syscall_get_error(struct task_struct *task, + struct pt_regs *regs) +{ + unsigned long error = regs->user.gpr[16]; + + return IS_ERR_VALUE(error) ? error : 0; +} + +static inline long syscall_get_return_value(struct task_struct *task, + struct pt_regs *regs) +{ + return regs->user.gpr[16]; +} + +static inline void syscall_set_return_value(struct task_struct *task, + struct pt_regs *regs, + int error, long val) +{ + regs->user.gpr[16] = (long)error ?: val; +} + +static inline void syscall_get_arguments(struct task_struct *task, + struct pt_regs *regs, + unsigned long *args) +{ + args[0] = regs->orig_r16; + memcpy(&args[1], ®s->user.gpr[I860_SYSCALL_ARG_REG + 1], + 5 * sizeof(args[0])); +} + +static inline void syscall_set_arguments(struct task_struct *task, + struct pt_regs *regs, + const unsigned long *args) +{ + regs->orig_r16 = args[0]; + memcpy(®s->user.gpr[I860_SYSCALL_ARG_REG], args, + 6 * sizeof(args[0])); +} + +static inline int syscall_get_arch(struct task_struct *task) +{ + return AUDIT_ARCH_I860; +} + +static inline bool arch_syscall_is_vdso_sigreturn(struct pt_regs *regs) +{ + unsigned long sigreturn = VDSO_SYMBOL(current->mm->context.vdso, rt_sigreturn); + + return regs->user.fir - sigreturn <= 8; +} + +#endif diff --git a/arch/i860/include/asm/syscalls.h b/arch/i860/include/asm/syscalls.h new file mode 100644 index 000000000000..edfa3260c485 --- /dev/null +++ b/arch/i860/include/asm/syscalls.h @@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (C) 2026 René Rebe */ +#ifndef _ASM_I860_SYSCALLS_H +#define _ASM_I860_SYSCALLS_H + +#include + +/* takes its registers from current_pt_regs() */ +asmlinkage long sys_rt_sigreturn(void); +#define sys_rt_sigreturn sys_rt_sigreturn + +asmlinkage long sys_cacheflush(unsigned long addr, unsigned long len, int op); + +#include + +#endif diff --git a/arch/i860/include/asm/thread_info.h b/arch/i860/include/asm/thread_info.h new file mode 100644 index 000000000000..9b9b66fe1b04 --- /dev/null +++ b/arch/i860/include/asm/thread_info.h @@ -0,0 +1,45 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (C) 2026 René Rebe */ +#ifndef _ASM_I860_THREAD_INFO_H +#define _ASM_I860_THREAD_INFO_H + +#include + +#define THREAD_SIZE_ORDER 1 +#define THREAD_SIZE (PAGE_SIZE << THREAD_SIZE_ORDER) + +#ifndef __ASSEMBLER__ + +#include + +/* At the bottom of the kernel stack. */ +struct thread_info { + struct task_struct *task; + unsigned long flags; + unsigned long syscall_work; + int preempt_count; + __u32 cpu; +}; + +#define INIT_THREAD_INFO(tsk) \ +{ \ + .task = &tsk, \ + .flags = 0, \ + .cpu = 0, \ + .preempt_count = INIT_PREEMPT_COUNT, \ +} + +register unsigned long current_stack_pointer asm("sp"); + +static inline struct thread_info *current_thread_info(void) +{ + return (struct thread_info *) + (current_stack_pointer & ~(THREAD_SIZE - 1)); +} + +#endif + +#define HAVE_TIF_RESTORE_SIGMASK +#include + +#endif diff --git a/arch/i860/include/asm/timex.h b/arch/i860/include/asm/timex.h new file mode 100644 index 000000000000..a4378fd44d32 --- /dev/null +++ b/arch/i860/include/asm/timex.h @@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (C) 2026 René Rebe */ +#ifndef _ASM_I860_TIMEX_H +#define _ASM_I860_TIMEX_H + +/* 82380 counter clock (inferred from the Stardent kernel constants) */ +#define CLOCK_TICK_RATE 499200 + +#include + +#endif diff --git a/arch/i860/include/asm/tlb.h b/arch/i860/include/asm/tlb.h new file mode 100644 index 000000000000..1e2c511d497b --- /dev/null +++ b/arch/i860/include/asm/tlb.h @@ -0,0 +1,8 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (C) 2026 René Rebe */ +#ifndef _ASM_I860_TLB_H +#define _ASM_I860_TLB_H + +#include + +#endif diff --git a/arch/i860/include/asm/tlbflush.h b/arch/i860/include/asm/tlbflush.h new file mode 100644 index 000000000000..f87663f9e2e2 --- /dev/null +++ b/arch/i860/include/asm/tlbflush.h @@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * The i860XR TLB can only be invalidated as a whole (dirbase.ITI, which + * also invalidates the instruction cache). + * Copyright (C) 2026 René Rebe + */ +#ifndef _ASM_I860_TLBFLUSH_H +#define _ASM_I860_TLBFLUSH_H + +#ifndef __ASSEMBLER__ + +struct mm_struct; +struct vm_area_struct; + +extern void local_flush_tlb_all(void); + +#define flush_tlb_all() local_flush_tlb_all() +#define flush_tlb_mm(mm) local_flush_tlb_all() +#define flush_tlb_page(vma, addr) local_flush_tlb_all() +/* mprotect to executable: fetches read memory, not the data cache */ +#define flush_tlb_range(vma, s, e) \ + do { \ + if ((vma)->vm_flags & VM_EXEC) \ + i860_flush_dcache_all(); \ + local_flush_tlb_all(); \ + } while (0) +#define flush_tlb_kernel_range(s, e) local_flush_tlb_all() + +#endif + +#endif diff --git a/arch/i860/include/asm/traps.h b/arch/i860/include/asm/traps.h new file mode 100644 index 000000000000..e73b83cb3e3a --- /dev/null +++ b/arch/i860/include/asm/traps.h @@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (C) 2026 René Rebe */ +#ifndef _ASM_I860_TRAPS_H +#define _ASM_I860_TRAPS_H + +#include +#include + +struct pt_regs; +struct task_struct; + +void die(const char *str, struct pt_regs *regs, long err); +int fixup_exception(struct pt_regs *regs); +void i860_do_page_fault(struct pt_regs *regs, unsigned long addr, + bool write, bool fetch); +bool i860_decode_access(struct pt_regs *regs, u32 insn, unsigned long *addr, + unsigned int *size, bool *write); +void i860_syscall_rewind(struct pt_regs *regs); +void i860_set_kernel_stack(unsigned long top); +void i860_trap_init(void); +extern unsigned long i860_irq_seq; +asmlinkage void i860_handle_trap(struct pt_regs *regs); +asmlinkage void i860_ret_from_fork(struct task_struct *prev, + struct pt_regs *regs, + int (*fn)(void *), void *fn_arg); + +bool i860_fp_result_pending(unsigned long fsr); +void i860_fp_result(struct pt_regs *regs); +int i860_fp_source(struct pt_regs *regs, u32 insn); + +#endif diff --git a/arch/i860/include/asm/uaccess.h b/arch/i860/include/asm/uaccess.h new file mode 100644 index 000000000000..edd302d371b3 --- /dev/null +++ b/arch/i860/include/asm/uaccess.h @@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * User space shares the address space with the kernel, so user accesses + * are plain loads and stores; faults are resolved through __ex_table. + * Copyright (C) 2026 René Rebe + */ +#ifndef _ASM_I860_UACCESS_H +#define _ASM_I860_UACCESS_H + +#include + +/* Return the number of bytes not copied. */ +extern unsigned long __copy_user(void *to, const void *from, unsigned long n); +extern unsigned long __clear_user_asm(void __user *to, unsigned long n); + +static inline unsigned long +raw_copy_from_user(void *to, const void __user *from, unsigned long n) +{ + return __copy_user(to, (__force const void *)from, n); +} + +static inline unsigned long +raw_copy_to_user(void __user *to, const void *from, unsigned long n) +{ + return __copy_user((__force void *)to, from, n); +} + +#define INLINE_COPY_FROM_USER +#define INLINE_COPY_TO_USER + +#define __clear_user __clear_user_asm + +#include + +#endif diff --git a/arch/i860/include/asm/unistd.h b/arch/i860/include/asm/unistd.h new file mode 100644 index 000000000000..a974bffbe56c --- /dev/null +++ b/arch/i860/include/asm/unistd.h @@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (C) 2026 René Rebe */ +#ifndef _ASM_I860_UNISTD_H +#define _ASM_I860_UNISTD_H + +#include + +#define NR_syscalls __NR_syscalls + +#define __ARCH_WANT_SYS_CLONE +#define __ARCH_WANT_SYS_CLONE3 + +#endif diff --git a/arch/i860/include/asm/vdso.h b/arch/i860/include/asm/vdso.h new file mode 100644 index 000000000000..75805dfef4f7 --- /dev/null +++ b/arch/i860/include/asm/vdso.h @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (C) 2026 René Rebe */ +#ifndef _ASM_I860_VDSO_H +#define _ASM_I860_VDSO_H + +#define __VDSO_PAGES 4 + +#ifndef __ASSEMBLER__ +#include + +#define VDSO_SYMBOL(base, name) \ + ((unsigned long)(base) + __vdso_##name##_offset) +#endif + +#endif diff --git a/arch/i860/include/asm/vdso/clocksource.h b/arch/i860/include/asm/vdso/clocksource.h new file mode 100644 index 000000000000..09f5f5db0ae7 --- /dev/null +++ b/arch/i860/include/asm/vdso/clocksource.h @@ -0,0 +1,6 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (C) 2026 René Rebe */ +#ifndef _ASM_I860_VDSO_CLOCKSOURCE_H +#define _ASM_I860_VDSO_CLOCKSOURCE_H + +#endif diff --git a/arch/i860/include/asm/vdso/gettimeofday.h b/arch/i860/include/asm/vdso/gettimeofday.h new file mode 100644 index 000000000000..f8a33235f8ae --- /dev/null +++ b/arch/i860/include/asm/vdso/gettimeofday.h @@ -0,0 +1,53 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (C) 2026 René Rebe */ +#ifndef _ASM_I860_VDSO_GETTIMEOFDAY_H +#define _ASM_I860_VDSO_GETTIMEOFDAY_H + +#ifndef __ASSEMBLER__ +#include +#include + +#define VDSO_HAS_CLOCK_GETRES 1 + +static __always_inline long i860_vdso_syscall2(long nr, long a, long b) +{ + register long r28 __asm__("r28") = nr; + register long r16 __asm__("r16") = a; + register long r17 __asm__("r17") = b; + + __asm__ __volatile__("trap %%r0,%%r0,%%r0" + : "+r" (r28), "+r" (r16) : "r" (r17) : "memory"); + return r16; +} + +static __always_inline long clock_gettime_fallback(clockid_t clock, struct __kernel_timespec *ts) +{ + return i860_vdso_syscall2(__NR_clock_gettime64, clock, (long)ts); +} + +static __always_inline long clock_getres_fallback(clockid_t clock, struct __kernel_timespec *res) +{ + return i860_vdso_syscall2(__NR_clock_getres_time64, clock, (long)res); +} + +/* no such system call with a 64-bit time, and not exported */ +static __always_inline long gettimeofday_fallback(struct __kernel_old_timeval *tv, + struct timezone *tz) +{ + return -38; +} + +/* no counter that user mode could read: see kernel/vdso.c */ +#define __arch_vdso_hres_capable __arch_vdso_hres_capable +static __always_inline bool __arch_vdso_hres_capable(void) +{ + return false; +} + +static __always_inline u64 __arch_get_hw_counter(s32 clock_mode, const struct vdso_time_data *vd) +{ + return ~0ULL; +} +#endif + +#endif diff --git a/arch/i860/include/asm/vdso/processor.h b/arch/i860/include/asm/vdso/processor.h new file mode 100644 index 000000000000..c4110d70ed3e --- /dev/null +++ b/arch/i860/include/asm/vdso/processor.h @@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (C) 2026 René Rebe */ +#ifndef _ASM_I860_VDSO_PROCESSOR_H +#define _ASM_I860_VDSO_PROCESSOR_H + +#ifndef __ASSEMBLER__ +#include + +#define cpu_relax() barrier() +#endif + +#endif diff --git a/arch/i860/include/asm/vdso/vsyscall.h b/arch/i860/include/asm/vdso/vsyscall.h new file mode 100644 index 000000000000..a18ff5017fbf --- /dev/null +++ b/arch/i860/include/asm/vdso/vsyscall.h @@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (C) 2026 René Rebe */ +#ifndef _ASM_I860_VDSO_VSYSCALL_H +#define _ASM_I860_VDSO_VSYSCALL_H + +#ifndef __ASSEMBLER__ +#include +#endif + +#endif diff --git a/arch/i860/include/asm/vmalloc.h b/arch/i860/include/asm/vmalloc.h new file mode 100644 index 000000000000..d04c409c7d7a --- /dev/null +++ b/arch/i860/include/asm/vmalloc.h @@ -0,0 +1,4 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_I860_VMALLOC_H +#define _ASM_I860_VMALLOC_H +#endif diff --git a/arch/i860/include/uapi/asm/Kbuild b/arch/i860/include/uapi/asm/Kbuild new file mode 100644 index 000000000000..dc402f5f3b0a --- /dev/null +++ b/arch/i860/include/uapi/asm/Kbuild @@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0 +syscall-y += unistd_32.h +generic-y += ucontext.h diff --git a/arch/i860/include/uapi/asm/auxvec.h b/arch/i860/include/uapi/asm/auxvec.h new file mode 100644 index 000000000000..eea0e72fe7ce --- /dev/null +++ b/arch/i860/include/uapi/asm/auxvec.h @@ -0,0 +1,8 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* Copyright (C) 2026 René Rebe */ +#ifndef _UAPI_ASM_I860_AUXVEC_H +#define _UAPI_ASM_I860_AUXVEC_H + +#define AT_SYSINFO_EHDR 33 + +#endif diff --git a/arch/i860/include/uapi/asm/byteorder.h b/arch/i860/include/uapi/asm/byteorder.h new file mode 100644 index 000000000000..fa7cfa69b7b1 --- /dev/null +++ b/arch/i860/include/uapi/asm/byteorder.h @@ -0,0 +1,8 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* Copyright (C) 2026 René Rebe */ +#ifndef _UAPI_ASM_I860_BYTEORDER_H +#define _UAPI_ASM_I860_BYTEORDER_H + +#include + +#endif diff --git a/arch/i860/include/uapi/asm/ptrace.h b/arch/i860/include/uapi/asm/ptrace.h new file mode 100644 index 000000000000..b7536ff234c2 --- /dev/null +++ b/arch/i860/include/uapi/asm/ptrace.h @@ -0,0 +1,41 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* Copyright (C) 2026 René Rebe */ +#ifndef _UAPI_ASM_I860_PTRACE_H +#define _UAPI_ASM_I860_PTRACE_H + +#define PTRACE_SYSEMU 31 +#define PTRACE_SYSEMU_SINGLESTEP 32 +/* one data watchpoint per thread: exact address, aligned to the size of the access */ +#define PTRACE_GETDB 34 +#define PTRACE_SETDB 35 +#define PTRACE_DB_READ 1 +#define PTRACE_DB_WRITE 2 + +#ifndef __ASSEMBLER__ + +struct ptrace_db { + unsigned long addr; + unsigned long type; +}; + +/* The FP pipelines of the interrupted code; 8-byte values aligned to 8. */ +struct i860_fp_pipe { + unsigned long m[3][2], a[3][2], l[3][2]; /* last stage first */ + unsigned long g[2], kr[2], ki[2], t[2], merge[2]; + unsigned long fsr[3]; /* the status of each round */ + unsigned long used; +}; + +/* Register state as saved on a trap; the layout is shared with sigcontext. */ +struct user_regs_struct { + unsigned long gpr[32]; /* r0 slot is unused */ + unsigned long fpr[32]; /* f0/f1 read as zero */ + unsigned long psr; + unsigned long epsr; + unsigned long fir; /* resume address */ + unsigned long fsr; +}; + +#endif + +#endif diff --git a/arch/i860/include/uapi/asm/sigcontext.h b/arch/i860/include/uapi/asm/sigcontext.h new file mode 100644 index 000000000000..d2c4c65adbcc --- /dev/null +++ b/arch/i860/include/uapi/asm/sigcontext.h @@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* Copyright (C) 2026 René Rebe */ +#ifndef _UAPI_ASM_I860_SIGCONTEXT_H +#define _UAPI_ASM_I860_SIGCONTEXT_H + +#include + +struct sigcontext { + struct user_regs_struct regs; + unsigned long oldmask; + struct i860_fp_pipe pipe; +}; + +#endif diff --git a/arch/i860/include/uapi/asm/signal.h b/arch/i860/include/uapi/asm/signal.h new file mode 100644 index 000000000000..6a80bdbcf5db --- /dev/null +++ b/arch/i860/include/uapi/asm/signal.h @@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* Copyright (C) 2026 René Rebe */ +#ifndef _UAPI_ASM_I860_SIGNAL_H +#define _UAPI_ASM_I860_SIGNAL_H + +#define SA_RESTORER 0x04000000 + +#include + +#endif diff --git a/arch/i860/include/uapi/asm/unistd.h b/arch/i860/include/uapi/asm/unistd.h new file mode 100644 index 000000000000..93564978633d --- /dev/null +++ b/arch/i860/include/uapi/asm/unistd.h @@ -0,0 +1,3 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* Copyright (C) 2026 René Rebe */ +#include diff --git a/arch/i860/kernel/Makefile b/arch/i860/kernel/Makefile new file mode 100644 index 000000000000..7f05d976ab9d --- /dev/null +++ b/arch/i860/kernel/Makefile @@ -0,0 +1,11 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Copyright (C) 2026 René Rebe +# + +always-$(KBUILD_BUILTIN) += vmlinux.lds + +obj-y += head.o entry.o traps.o fpemu.o setup.o irq.o time.o process.o \ + signal.o ptrace.o syscall_table.o early_printk.o dma.o i860_ksyms.o +obj-$(CONFIG_MODULES) += module.o +obj-y += vdso.o vdso/ diff --git a/arch/i860/kernel/Makefile.syscalls b/arch/i860/kernel/Makefile.syscalls new file mode 100644 index 000000000000..f8e020271dfe --- /dev/null +++ b/arch/i860/kernel/Makefile.syscalls @@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0 + +syscall_abis_32 += i860 diff --git a/arch/i860/kernel/asm-offsets.c b/arch/i860/kernel/asm-offsets.c new file mode 100644 index 000000000000..1585e1266370 --- /dev/null +++ b/arch/i860/kernel/asm-offsets.c @@ -0,0 +1,35 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (C) 2026 René Rebe */ + +#define COMPILE_OFFSETS + +#include +#include +#include +#include + +int main(void) +{ + DEFINE(PT_SIZE, sizeof(struct pt_regs)); + DEFINE(PT_GPR, offsetof(struct pt_regs, user.gpr)); + DEFINE(PT_FPR, offsetof(struct pt_regs, user.fpr)); + DEFINE(PT_PSR, offsetof(struct pt_regs, user.psr)); + DEFINE(PT_EPSR, offsetof(struct pt_regs, user.epsr)); + DEFINE(PT_FIR, offsetof(struct pt_regs, user.fir)); + DEFINE(PT_FSR, offsetof(struct pt_regs, user.fsr)); + DEFINE(PT_PIPE, offsetof(struct pt_regs, pipe)); + DEFINE(PIPE_M, offsetof(struct i860_fp_pipe, m)); + DEFINE(PIPE_A, offsetof(struct i860_fp_pipe, a)); + DEFINE(PIPE_L, offsetof(struct i860_fp_pipe, l)); + DEFINE(PIPE_G, offsetof(struct i860_fp_pipe, g)); + DEFINE(PIPE_KR, offsetof(struct i860_fp_pipe, kr)); + DEFINE(PIPE_KI, offsetof(struct i860_fp_pipe, ki)); + DEFINE(PIPE_T, offsetof(struct i860_fp_pipe, t)); + DEFINE(PIPE_MERGE, offsetof(struct i860_fp_pipe, merge)); + DEFINE(PIPE_FSR, offsetof(struct i860_fp_pipe, fsr)); + DEFINE(PIPE_USED, offsetof(struct i860_fp_pipe, used)); + BLANK(); + DEFINE(TASK_THREAD_KSP, offsetof(struct task_struct, thread.ksp)); + DEFINE(TASK_STACK, offsetof(struct task_struct, stack)); + return 0; +} diff --git a/arch/i860/kernel/dma.c b/arch/i860/kernel/dma.c new file mode 100644 index 000000000000..d15ce39fee63 --- /dev/null +++ b/arch/i860/kernel/dma.c @@ -0,0 +1,171 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * 82380 DMA channels and the DMA buffer SRAM (see asm/i860-dma.h). + * Register sequence as in the firmware's dma_init/dma_setup. + * Copyright (C) 2026 René Rebe + */ + +#include +#include +#include +#include +#include + +#define ISP_BASE 0x1c000000 +#define SRAM_BASE 0x18000000 +#define SRAM_WINDOW 0x80000 + +#define DMA_CMD1 0x010 /* 08h write: command I ch0-3, read: status */ +#define DMA_CMD1_HI 0x190 /* C8h command I ch4-7 */ +#define DMA_MASK 0x410 /* 0Ah mask set/reset */ +#define DMA_MODE1 0x610 /* 0Bh mode I */ +#define DMA_CLRFF 0x018 /* 0Ch clear byte pointer flip-flop */ +#define DMA_BUSSIZE 0x030 /* 18h */ +#define DMA_CMD2 0x430 /* 1Ah command II ch0-3 */ +#define DMA_CMD2_HI 0x5b0 /* DAh command II ch4-7 */ +#define DMA_MODE2 0x630 /* 1Bh mode II */ + +#define MODE1_TO_MEMORY 0x04 /* demand mode, device -> memory */ +#define MODE1_TO_DEVICE 0x08 /* demand mode, memory -> device */ + +struct i860_dma_regs { + u16 target_lo; /* A0-A15, byte pointer pair */ + u16 target_mid; /* A16-A23 */ + u16 target_hi; /* A24-A31 */ + u16 count_lo; /* B0-B15, byte pointer pair */ + u16 count_hi; /* B16-B23 */ + u16 requester_lo; /* requester A0-A15 */ + u16 requester_hi; /* requester A16-A31 */ +}; + +static const struct i860_dma_regs dma_regs[] = { + [0] = { 0x000, 0x708, 0x020, 0x200, 0x220, 0x120, 0x320 }, + [1] = { 0x400, 0x700, 0x420, 0x600, 0x620, 0x520, 0x720 }, +}; + +static void __iomem *isp; +static void __iomem *sram; +static DEFINE_SPINLOCK(dma_lock); +static u8 dma_tc; /* TC bits; reading the status clears them all */ + +static void dma_wr2(u16 reg, unsigned long val) +{ + writeb(val & 0xff, isp + reg); + writeb((val >> 8) & 0xff, isp + reg); +} + +void i860_dma_start(unsigned int ch, unsigned long sram_off, size_t len, + bool to_device) +{ + const struct i860_dma_regs *r = &dma_regs[ch]; + unsigned long flags; + + spin_lock_irqsave(&dma_lock, flags); + writeb(ch | 4, isp + DMA_MASK); + dma_tc |= readb(isp + DMA_CMD1); + dma_tc &= ~BIT(ch); + /* the transfer ends when the count decrements past zero */ + writeb(0, isp + DMA_CLRFF); + dma_wr2(r->count_lo, len - 1); + writeb(((len - 1) >> 16) & 0xff, isp + r->count_hi); + writeb(0, isp + DMA_CLRFF); + dma_wr2(r->target_lo, sram_off); + writeb((sram_off >> 16) & 0xff, isp + r->target_mid); + writeb(0, isp + r->target_hi); + writeb((to_device ? MODE1_TO_DEVICE : MODE1_TO_MEMORY) | ch, + isp + DMA_MODE1); + writeb(ch, isp + DMA_MASK); + spin_unlock_irqrestore(&dma_lock, flags); +} +EXPORT_SYMBOL_GPL(i860_dma_start); + +void i860_dma_stop(unsigned int ch) +{ + unsigned long flags; + + spin_lock_irqsave(&dma_lock, flags); + writeb(ch | 4, isp + DMA_MASK); + spin_unlock_irqrestore(&dma_lock, flags); +} +EXPORT_SYMBOL_GPL(i860_dma_stop); + +/* Bytes not transferred, 0 after terminal count. */ +size_t i860_dma_residue(unsigned int ch) +{ + const struct i860_dma_regs *r = &dma_regs[ch]; + unsigned long flags; + size_t count; + + spin_lock_irqsave(&dma_lock, flags); + dma_tc |= readb(isp + DMA_CMD1); + if (dma_tc & BIT(ch)) { + spin_unlock_irqrestore(&dma_lock, flags); + return 0; + } + writeb(0, isp + DMA_CLRFF); + count = readb(isp + r->count_lo); + count |= readb(isp + r->count_lo) << 8; + count |= readb(isp + r->count_hi) << 16; + spin_unlock_irqrestore(&dma_lock, flags); + return (count + 1) & 0xffffff; +} +EXPORT_SYMBOL_GPL(i860_dma_residue); + +/* SRAM byte n is at CPU offset (n / 4) * 8 + n % 4. */ +static inline void __iomem *sram_addr(unsigned long off) +{ + return sram + ((off & ~3UL) << 1) + (off & 3); +} + +void i860_sram_write(unsigned long off, const void *buf, size_t len) +{ + const u8 *p = buf; + + if (!((off | (unsigned long)p) & 3)) { + for (; len >= 4; len -= 4, off += 4, p += 4) + __raw_writel(*(const u32 *)p, sram_addr(off)); + } + for (; len; len--, off++, p++) + __raw_writeb(*p, sram_addr(off)); + wmb(); +} +EXPORT_SYMBOL_GPL(i860_sram_write); + +void i860_sram_read(void *buf, unsigned long off, size_t len) +{ + u8 *p = buf; + + rmb(); + if (!((off | (unsigned long)p) & 3)) { + for (; len >= 4; len -= 4, off += 4, p += 4) + *(u32 *)p = __raw_readl(sram_addr(off)); + } + for (; len; len--, off++, p++) + *p = __raw_readb(sram_addr(off)); +} +EXPORT_SYMBOL_GPL(i860_sram_read); + +static int __init i860_dma_init(void) +{ + unsigned int ch; + + isp = ioremap(ISP_BASE, 0x1000); + sram = ioremap(SRAM_BASE, SRAM_WINDOW); + if (!isp || !sram) + return -ENOMEM; + + writeb(0x00, isp + DMA_CMD1); + writeb(0x04, isp + DMA_CMD1_HI); /* group 4-7 disabled */ + writeb(0x0f, isp + DMA_CMD2); + writeb(0x0f, isp + DMA_CMD2_HI); + for (ch = 0; ch < ARRAY_SIZE(dma_regs); ch++) { + writeb(ch | 4, isp + DMA_MASK); + writeb(0x50 | ch, isp + DMA_MODE2); /* fly-by, I/O requester, memory target */ + writeb(0xf0 | ch, isp + DMA_BUSSIZE); /* 8-bit requester and target */ + writeb(0, isp + DMA_CLRFF); + dma_wr2(dma_regs[ch].requester_lo, 0); + dma_wr2(dma_regs[ch].requester_hi, 0); + } + return 0; +} +arch_initcall(i860_dma_init); diff --git a/arch/i860/kernel/early_printk.c b/arch/i860/kernel/early_printk.c new file mode 100644 index 000000000000..f1f1c6f4fded --- /dev/null +++ b/arch/i860/kernel/early_printk.c @@ -0,0 +1,68 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Polled boot console on UART A (16450, registers at stride 8). + * Copyright (C) 2026 René Rebe + */ + +#include +#include +#include +#include + +#define UART_A_PHYS 0x1e000600 +#define UART_REG(n) ((n) << 3) +#define UART_THR UART_REG(0) +#define UART_DLL UART_REG(0) +#define UART_DLM UART_REG(1) +#define UART_IER UART_REG(1) +#define UART_LCR UART_REG(3) +#define UART_MCR UART_REG(4) +#define UART_LSR UART_REG(5) +#define UART_LSR_THRE 0x20 + +static void __iomem *early_uart; + +static void early_uart_putc(char c) +{ + while (!(readb(early_uart + UART_LSR) & UART_LSR_THRE)) + ; + writeb(c, early_uart + UART_THR); +} + +static void early_uart_write(struct console *con, const char *s, + unsigned int n) +{ + while (n--) { + if (*s == '\n') + early_uart_putc('\r'); + early_uart_putc(*s++); + } +} + +static struct console early_uart_console = { + .name = "early", + .write = early_uart_write, + .flags = CON_PRINTBUFFER | CON_BOOT, + .index = -1, +}; + +/* + * First call: the firmware identity mapping is live; set 9600 8N1 (the + * firmware leaves 7N1 for its host link). Second call, after + * paging_init: switch to the kernel I/O window. + */ +void __init i860_early_console_init(void) +{ + if (early_uart) { + early_uart = I860_IO(UART_A_PHYS); + return; + } + early_uart = (void __iomem *)UART_A_PHYS; + writeb(0x00, early_uart + UART_IER); + writeb(0x83, early_uart + UART_LCR); + writeb(12, early_uart + UART_DLL); + writeb(0, early_uart + UART_DLM); + writeb(0x03, early_uart + UART_LCR); + writeb(0x03, early_uart + UART_MCR); + register_console(&early_uart_console); +} diff --git a/arch/i860/kernel/entry.S b/arch/i860/kernel/entry.S new file mode 100644 index 000000000000..60cf39866277 --- /dev/null +++ b/arch/i860/kernel/entry.S @@ -0,0 +1,462 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * i860 trap entry/exit and context switch. + * Copyright (C) 2026 René Rebe + */ + +#include +#include +#include +#include + +#define GPR(n) (PT_GPR + 4 * (n)) +#define FPR(n) (PT_FPR + 4 * (n)) + + .text + +/* + * Copied to the trap vector at 0xffffff00. On entry U = IM = 0 and no + * register is free, so r1, r2 and psr go to scratch words in the trap page. + * The trap bits are cleared before the first bri, which would otherwise + * be a trap return. + */ + .align 8 +ENTRY(i860_trap_vector) + /* as the Stardent kernel: let the pipelines settle */ + nop + nop + nop + nop + nop + nop + nop + nop + st.l %r1,SCR_R1(%r0) + st.l %r2,SCR_R2(%r0) + ld.c %psr,%r1 + st.l %r1,SCR_PSR(%r0) + /* KNF, DS, DIM stay in the saved psr: live, KNF would kill a kernel FP instruction */ + andnot PSR_TRAPS | PSR_KNF | PSR_DS | PSR_DIM,%r1,%r1 + st.c %r1,%psr + and PSR_PU,%r1,%r0 + bc 1f + ld.l SCR_KSP(%r0),%r2 /* from user mode: kernel stack */ +1: orh [i860_trap_entry]@h,%r0,%r1 + or [i860_trap_entry]@l,%r1,%r1 + bri %r1 + nop +ENTRY(i860_trap_vector_end) + +ENTRY(i860_trap_entry) + /* the first add below sets EPSR.OF, which belongs to the interrupted code */ + ld.c %epsr,%r1 + andnot 15,%r2,%r2 + adds -PT_SIZE,%r2,%r2 + st.l %r3,GPR(3)(%r2) + st.l %r4,GPR(4)(%r2) + st.l %r5,GPR(5)(%r2) + st.l %r6,GPR(6)(%r2) + st.l %r7,GPR(7)(%r2) + st.l %r8,GPR(8)(%r2) + st.l %r9,GPR(9)(%r2) + st.l %r10,GPR(10)(%r2) + st.l %r11,GPR(11)(%r2) + st.l %r12,GPR(12)(%r2) + st.l %r13,GPR(13)(%r2) + st.l %r14,GPR(14)(%r2) + st.l %r15,GPR(15)(%r2) + st.l %r16,GPR(16)(%r2) + st.l %r17,GPR(17)(%r2) + st.l %r18,GPR(18)(%r2) + st.l %r19,GPR(19)(%r2) + st.l %r20,GPR(20)(%r2) + st.l %r21,GPR(21)(%r2) + st.l %r22,GPR(22)(%r2) + st.l %r23,GPR(23)(%r2) + st.l %r24,GPR(24)(%r2) + st.l %r25,GPR(25)(%r2) + st.l %r26,GPR(26)(%r2) + st.l %r27,GPR(27)(%r2) + st.l %r28,GPR(28)(%r2) + st.l %r29,GPR(29)(%r2) + st.l %r30,GPR(30)(%r2) + st.l %r31,GPR(31)(%r2) + st.l %r0,GPR(0)(%r2) + ld.l SCR_R1(%r0),%r4 + st.l %r4,GPR(1)(%r2) + ld.l SCR_R2(%r0),%r4 + st.l %r4,GPR(2)(%r2) + ld.l SCR_PSR(%r0),%r4 + st.l %r4,PT_PSR(%r2) + /* only the first read of fir after a trap returns the trap address */ + ld.c %fir,%r4 + st.l %r4,PT_FIR(%r2) + st.l %r1,PT_EPSR(%r2) + ld.c %fsr,%r4 + st.l %r4,PT_FSR(%r2) + /* kernel FP state: round to nearest, no FP traps, also for the saves here */ + st.c %r0,%fsr + fst.q %f0,FPR(0)(%r2) + fst.q %f4,FPR(4)(%r2) + fst.q %f8,FPR(8)(%r2) + fst.q %f12,FPR(12)(%r2) + fst.q %f16,FPR(16)(%r2) + fst.q %f20,FPR(20)(%r2) + fst.q %f24,FPR(24)(%r2) + fst.q %f28,FPR(28)(%r2) + /* the pipelines of user code, not for a system call, as SVR4 d0401ed0; also for + a pending result exception, whose value is in the last stages */ + st.l %r0,PT_PIPE+PIPE_USED(%r2) + ld.l PT_PSR(%r2),%r5 + and PSR_PU,%r5,%r0 + bc 1f + and PSR_IT,%r5,%r0 + bc 2f + and FSR_FTE,%r4,%r0 + bc 1f + and FSR_RESULT,%r4,%r0 + bc 1f +2: call i860_pipe_save + nop +1: mov %r0,%fp + call i860_handle_trap + mov %r2,%r16 + +/* r2 = pt_regs; interrupts are disabled */ +ENTRY(ret_from_exception) + ld.c %psr,%r4 + andnot PSR_IM,%r4,%r4 + st.c %r4,%psr + ld.l PT_PIPE+PIPE_USED(%r2),%r4 + bte 0,%r4,1f + call i860_pipe_restore + nop +1: + ld.l PT_FSR(%r2),%r4 + /* U would load the first stages, whose status the restore has set */ + andnot FSR_U,%r4,%r4 + fld.q FPR(0)(%r2),%f0 + fld.q FPR(4)(%r2),%f4 + fld.q FPR(8)(%r2),%f8 + fld.q FPR(12)(%r2),%f12 + fld.q FPR(16)(%r2),%f16 + fld.q FPR(20)(%r2),%f20 + fld.q FPR(24)(%r2),%f24 + fld.q FPR(28)(%r2),%f28 + st.c %r4,%fsr + /* only OF: no add may follow up to the return */ + ld.l PT_EPSR(%r2),%r4 + andh EPSR_OF_H,%r4,%r4 + ld.c %epsr,%r5 + andnoth EPSR_OF_H,%r5,%r5 + or %r4,%r5,%r5 + st.c %r5,%epsr + ld.l GPR(3)(%r2),%r3 + ld.l GPR(4)(%r2),%r4 + ld.l GPR(5)(%r2),%r5 + ld.l GPR(6)(%r2),%r6 + ld.l GPR(7)(%r2),%r7 + ld.l GPR(8)(%r2),%r8 + ld.l GPR(9)(%r2),%r9 + ld.l GPR(10)(%r2),%r10 + ld.l GPR(11)(%r2),%r11 + ld.l GPR(12)(%r2),%r12 + ld.l GPR(13)(%r2),%r13 + ld.l GPR(14)(%r2),%r14 + ld.l GPR(15)(%r2),%r15 + ld.l GPR(16)(%r2),%r16 + ld.l GPR(17)(%r2),%r17 + ld.l GPR(18)(%r2),%r18 + ld.l GPR(19)(%r2),%r19 + ld.l GPR(20)(%r2),%r20 + ld.l GPR(21)(%r2),%r21 + ld.l GPR(22)(%r2),%r22 + ld.l GPR(23)(%r2),%r23 + ld.l GPR(24)(%r2),%r24 + ld.l GPR(25)(%r2),%r25 + ld.l GPR(26)(%r2),%r26 + ld.l GPR(27)(%r2),%r27 + ld.l GPR(28)(%r2),%r28 + ld.l GPR(29)(%r2),%r29 + ld.l GPR(30)(%r2),%r30 + ld.l GPR(31)(%r2),%r31 + /* + * With a trap bit set in psr, bri returns from the trap (U = PU, + * IM = PIM). Its delay slot still runs in supervisor mode and + * reloads r1 from the trap page. + */ + ld.l PT_PSR(%r2),%r1 + or PSR_IT,%r1,%r1 + st.c %r1,%psr + ld.l GPR(1)(%r2),%r1 + st.l %r1,SCR_EXIT(%r0) + ld.l PT_FIR(%r2),%r1 + ld.l GPR(2)(%r2),%r2 + ld.l SCR_EXIT(%r0),%r0 + bri %r1 + ld.l SCR_EXIT(%r0),%r1 + +/* + * struct task_struct *__switch_to(prev = r16, next = r17) + * Saves the callee-saved state in a frame on the old kernel stack. + */ +#define SW_SIZE 80 +ENTRY(__switch_to) + adds -SW_SIZE,%sp,%sp + st.l %r1,0(%sp) + st.l %fp,4(%sp) + st.l %r4,8(%sp) + st.l %r5,12(%sp) + st.l %r6,16(%sp) + st.l %r7,20(%sp) + st.l %r8,24(%sp) + st.l %r9,28(%sp) + st.l %r10,32(%sp) + st.l %r11,36(%sp) + st.l %r12,40(%sp) + st.l %r13,44(%sp) + st.l %r14,48(%sp) + st.l %r15,52(%sp) + fst.l %f2,56(%sp) + fst.l %f3,60(%sp) + fst.l %f4,64(%sp) + fst.l %f5,68(%sp) + fst.l %f6,72(%sp) + fst.l %f7,76(%sp) + st.l %sp,TASK_THREAD_KSP(%r16) + ld.l TASK_THREAD_KSP(%r17),%sp + ld.l TASK_STACK(%r17),%r18 + addu THREAD_SIZE,%r18,%r18 + st.l %r18,SCR_KSP(%r0) + ld.l 0(%sp),%r1 + ld.l 4(%sp),%fp + ld.l 8(%sp),%r4 + ld.l 12(%sp),%r5 + ld.l 16(%sp),%r6 + ld.l 20(%sp),%r7 + ld.l 24(%sp),%r8 + ld.l 28(%sp),%r9 + ld.l 32(%sp),%r10 + ld.l 36(%sp),%r11 + ld.l 40(%sp),%r12 + ld.l 44(%sp),%r13 + ld.l 48(%sp),%r14 + ld.l 52(%sp),%r15 + fld.l 56(%sp),%f2 + fld.l 60(%sp),%f3 + fld.l 64(%sp),%f4 + fld.l 68(%sp),%f5 + fld.l 72(%sp),%f6 + fld.l 76(%sp),%f7 + bri %r1 + adds SW_SIZE,%sp,%sp + +/* + * First return of a new task, from __switch_to: r16 = prev, sp = pt_regs, + * r4 = kernel thread function or 0, r5 = its argument. + */ +ENTRY(ret_from_fork) + mov %sp,%r17 + mov %r4,%r18 + call i860_ret_from_fork + mov %r5,%r19 + br ret_from_exception + nop + +/* + * The FP pipelines, as SVR4 d0401ed8 and d04022d8: three rounds pop the stages of the + * multiplier, adder and load pipes, last stage first, the status of the next one shows in + * fsr. r2 = pt_regs, FTE is clear, the FP registers are saved or get reloaded after this. + */ + .section .rodata + .align 16 +i860_pipe_const: + .long 0, 0, 0x3f800000, 0, 0, 0x3ff00000 + .previous + +#define PIPE(f, n) PT_PIPE + PIPE_##f + (n) + + .macro PIPE_POP n + pfmul.ss %f0,%f0,%f16 + fst.d %f16,PIPE(M, 8 * \n)(%r2) + pfadd.ss %f0,%f0,%f18 + fst.d %f18,PIPE(A, 8 * \n)(%r2) + pfld.d 0(%r16),%f20 + fst.d %f20,PIPE(L, 8 * \n)(%r2) + .endm + + .macro PIPE_READ_FSR n + ld.c %fsr,%r17 + nop + nop + nop + st.l %r17,PIPE(FSR, 4 * \n)(%r2) + .endm + + .text +ENTRY(i860_pipe_save) + st.l %r4,PIPE(FSR, 0)(%r2) + orh [i860_pipe_const]@h,%r0,%r16 + or [i860_pipe_const]@l,%r16,%r16 + fld.d 16(%r16),%f4 + PIPE_POP 0 + PIPE_READ_FSR 1 + PIPE_POP 1 + PIPE_READ_FSR 2 + PIPE_POP 2 + pfiadd.dd %f0,%f0,%f16 + fst.d %f16,PIPE(G, 0)(%r2) + andnot FSR_RM | FSR_FTE,%r17,%r31 + or 4,%r31,%r31 + st.c %r31,%fsr + r2p1.dd %f0,%f4,%f0 + ld.c %fsr,%r17 + nop + nop + nop + i2p1.dd %f0,%f4,%f0 + ld.c %fsr,%r18 + nop + nop + nop + pfmul.dd %f0,%f0,%f16 + and FSR_SE,%r17,%r0 + bc.t 1f + fst.d %f16,PIPE(KR, 0)(%r2) + fxfr %f17,%r17 + andh 0x7ff0,%r17,%r0 + bc.t 1f + fst.d %f16,PIPE(KR, 0)(%r2) + orh 0x7ff0,%r17,%r17 + ixfr %r17,%f17 + fst.d %f16,PIPE(KR, 0)(%r2) +1: pfmul.dd %f0,%f0,%f16 + and FSR_SE,%r18,%r0 + bc.t 2f + fst.d %f16,PIPE(KI, 0)(%r2) + fxfr %f17,%r18 + andh 0x7ff0,%r18,%r0 + bc.t 2f + fst.d %f16,PIPE(KI, 0)(%r2) + orh 0x7ff0,%r18,%r18 + ixfr %r18,%f17 + fst.d %f16,PIPE(KI, 0)(%r2) +2: m12tpm.dd %f0,%f0,%f0 + ld.c %fsr,%r17 + nop + nop + nop + m12tsm.dd %f0,%f0,%f0 + pfadd.dd %f0,%f0,%f0 + pfadd.dd %f0,%f0,%f16 + pfadd.dd %f0,%f0,%f18 + and FSR_SE,%r17,%r0 + bc.t 4f + fst.d %f16,PIPE(T, 0)(%r2) + fxfr %f17,%r17 + andh 0x8000,%r17,%r0 + bc 3f + fiadd.dd %f18,%f0,%f16 + fxfr %f17,%r17 +3: andh 0x7ff0,%r17,%r0 + bc.t 4f + fst.d %f16,PIPE(T, 0)(%r2) + orh 0x7ff0,%r17,%r17 + ixfr %r17,%f17 + fst.d %f16,PIPE(T, 0)(%r2) +4: form %f0,%f16 + fst.d %f16,PIPE(MERGE, 0)(%r2) + st.c %r0,%fsr + or 1,%r0,%r17 + bri %r1 + st.l %r17,PIPE(USED, 0)(%r2) + + /* a sign preserving add, r = the status of the round */ + .macro PIPE_ADD n, r + fld.d PIPE(A, 8 * \n)(%r2),%f18 + andh 0x2000,\r,%r0 + bc 1f + fxfr %f19,%r31 + andh 0x8000,%r31,%r0 + bc.t 3f + pfadd.dd %f18,%f0,%f0 + br 3f + pfsub.dd %f18,%f0,%f0 +1: fxfr %f18,%r31 + andh 0x8000,%r31,%r0 + bc.t 3f + pfadd.ss %f18,%f0,%f0 + br 3f + pfsub.ss %f18,%f0,%f0 +3: + .endm + + .macro PIPE_LOAD n, r + andh 0x0400,\r,%r0 + bc.t 4f + pfld.l PIPE(L, 8 * \n)(%r2),%f0 + pfld.d PIPE(L, 8 * \n)(%r2),%f0 +4: + .endm + + .macro PIPE_MUL n, r + fld.d PIPE(M, 8 * \n)(%r2),%f16 + andh 0x1000,\r,%r0 + bc.t 5f + pfmul.ss %f16,%f12,%f0 + pfmul3.dd %f16,%f4,%f0 +5: + .endm + + .macro PIPE_STATUS r + or FSR_U,\r,%r20 + andnot FSR_FTE,%r20,%r20 + st.c %r20,%fsr + .endm + +/* The registers are loaded after this. */ +ENTRY(i860_pipe_restore) + st.c %r0,%fsr + orh [i860_pipe_const]@h,%r0,%r16 + or [i860_pipe_const]@l,%r16,%r16 + fld.l 8(%r16),%f12 + fld.d 16(%r16),%f4 + fld.d PIPE(T, 0)(%r2),%f16 + fld.d PIPE(KR, 0)(%r2),%f18 + fld.d PIPE(KI, 0)(%r2),%f20 + pfmul.dd %f4,%f16,%f0 + r2pt.dd %f18,%f0,%f0 + i2apt.dd %f20,%f0,%f0 + ld.l PIPE(MERGE, 0)(%r2),%r16 + ld.l PIPE(MERGE, 4)(%r2),%r18 + shl 16,%r16,%r20 + ixfr %r20,%f6 + shl 16,%r18,%r20 + ixfr %r20,%f7 + ixfr %r16,%f8 + ixfr %r18,%f9 + faddz %f0,%f6,%f0 + faddz %f0,%f8,%f0 + ld.l PIPE(FSR, 0)(%r2),%r16 + ld.l PIPE(FSR, 4)(%r2),%r17 + ld.l PIPE(FSR, 8)(%r2),%r18 + PIPE_ADD 0,%r16 + PIPE_LOAD 0,%r16 + PIPE_MUL 0,%r16 + PIPE_STATUS %r16 + PIPE_ADD 1,%r17 + PIPE_LOAD 1,%r17 + PIPE_MUL 1,%r17 + PIPE_STATUS %r17 + PIPE_ADD 2,%r18 + PIPE_LOAD 2,%r18 + PIPE_MUL 2,%r18 + fld.d PIPE(G, 0)(%r2),%f28 + andh 0x0800,%r18,%r0 + bc.t 6f + pfiadd.ss %f28,%f0,%f0 + pfiadd.dd %f28,%f0,%f0 +6: PIPE_STATUS %r18 + bri %r1 + nop + diff --git a/arch/i860/kernel/fpemu.c b/arch/i860/kernel/fpemu.c new file mode 100644 index 000000000000..4fdbc7db80fc --- /dev/null +++ b/arch/i860/kernel/fpemu.c @@ -0,0 +1,593 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Floating-point traps, after the protocol of the Stardent SVR4 kernel handler + * (no manual was available, see the project's tmp/notes/fp-trap.md). + * + * Source exception: an operand is NaN, infinity or denormal, or frcp/frsqr has + * no result. fir is the unexecuted instruction: emulate it here and set PSR.KNF, + * which kills it on resume. Result exception: the instruction ran earlier, fir is + * a later one; the entry code popped the value with the exponent wrapped into + * pipe.m[0] and pipe.a[0], RR names the register it was meant for. + * + * Everything is masked: the default IEEE result, no SIGFPE, as SVR4 does by + * default. Integer arithmetic only, this runs on the kernel side of user FP state. + * + * Copyright (C) 2026 René Rebe + */ + +#include +#include +#include +#include +#include +#include + +#define FSR_RM_SHIFT 2 +#define RM_NEAREST 0 +#define RM_DOWN 1 +#define RM_UP 2 +#define RM_CHOP 3 + +#define FSR_MU 0x00000200 +#define FSR_MO 0x00000400 +#define FSR_MI 0x00000800 +#define FSR_MA 0x00001000 +#define FSR_AU 0x00002000 +#define FSR_AO 0x00004000 +#define FSR_AI 0x00008000 +#define FSR_AA 0x00010000 +#define FSR_RR_SHIFT 17 +#define FSR_RR 0x003e0000 +#define FSR_AE_SHIFT 22 +#define FSR_AE (7UL << FSR_AE_SHIFT) +#define FSR_MRP 0x10000000 +#define FSR_ARP 0x20000000 + +/* A number being worked on: value = m * 2^(exp - 62), bit 62 of m set */ +enum fp_class { FP_ZERO, FP_NORMAL, FP_INF, FP_NAN }; + +struct fp_num { + enum fp_class cls; + bool sign; + int exp; + u64 m; + u64 raw; /* NaN: the value as a double */ +}; + +static const struct fp_fmt { + int bias, p; /* exponent bias, significand bits with the hidden one */ +} fmt_s = { 127, 24 }, fmt_d = { 1023, 53 }; + +static u64 get_reg(const struct pt_regs *regs, unsigned int r, bool dbl) +{ + if (dbl) + return regs->user.fpr[r & ~1u] | ((u64)regs->user.fpr[r | 1] << 32); + return regs->user.fpr[r]; +} + +static void set_reg(struct pt_regs *regs, unsigned int r, bool dbl, u64 v) +{ + if (r < 2) /* f0 and f1 read as zero */ + return; + if (dbl) { + regs->user.fpr[r & ~1u] = (u32)v; + regs->user.fpr[r | 1] = v >> 32; + } else { + regs->user.fpr[r] = (u32)v; + } +} + +static struct fp_num unpack(u64 raw, bool dbl) +{ + struct fp_num n = { .raw = raw }; + u64 frac; + int e; + + if (dbl) { + n.sign = raw >> 63; + e = (raw >> 52) & 0x7ff; + frac = raw & GENMASK_ULL(51, 0); + if (e == 0x7ff) { + n.cls = frac ? FP_NAN : FP_INF; + return n; + } + if (!e && !frac) + return n; + n.m = e ? frac | BIT_ULL(52) : frac; + n.exp = (e ? e : 1) - 1023; + n.m <<= 10; + } else { + n.sign = (raw >> 31) & 1; + e = (raw >> 23) & 0xff; + frac = raw & GENMASK_ULL(22, 0); + if (e == 0xff) { + n.cls = frac ? FP_NAN : FP_INF; + /* as a double, quieted later */ + n.raw = ((u64)n.sign << 63) | GENMASK_ULL(62, 52) | (frac << 29); + return n; + } + if (!e && !frac) + return n; + n.m = e ? frac | BIT_ULL(23) : frac; + n.exp = (e ? e : 1) - 127; + n.m <<= 39; + } + n.cls = FP_NORMAL; + while (!(n.m & BIT_ULL(62))) { + n.m <<= 1; + n.exp--; + } + return n; +} + +static u64 make_inf(bool sign, bool dbl) +{ + return dbl ? ((u64)sign << 63) | GENMASK_ULL(62, 52) + : ((u64)sign << 31) | GENMASK_ULL(30, 23); +} + +static u64 make_max(bool sign, bool dbl) +{ + return dbl ? ((u64)sign << 63) | GENMASK_ULL(62, 53) | GENMASK_ULL(51, 0) + : ((u64)sign << 31) | GENMASK_ULL(30, 24) | GENMASK_ULL(22, 0); +} + +static u64 make_nan(bool dbl) +{ + return dbl ? 0xfff8000000000000ULL : 0xffc00000ULL; +} + +static u64 overflow_value(bool sign, bool dbl, int rm) +{ + switch (rm) { + case RM_DOWN: + return sign ? make_inf(sign, dbl) : make_max(sign, dbl); + case RM_UP: + return sign ? make_max(sign, dbl) : make_inf(sign, dbl); + case RM_CHOP: + return make_max(sign, dbl); + default: + return make_inf(sign, dbl); + } +} + +/* Add one to the kept bits? LOST holds the dropped bits, HALF the first of them */ +static bool fp_round_up(bool sign, bool odd, u64 lost, u64 half, int rm) +{ + switch (rm) { + case RM_NEAREST: + return lost > half || (lost == half && odd); + case RM_DOWN: + return sign && lost; + case RM_UP: + return !sign && lost; + default: + return false; + } +} + +static u64 shift_sticky(u64 m, unsigned int n) +{ + if (n >= 64) + return m != 0; + return (m >> n) | ((m & (BIT_ULL(n) - 1)) != 0); +} + +/* Round and pack M * 2^(EXP - 62), bit 62 of M set. FZ flushes underflow to +0 */ +static u64 pack(bool sign, int exp, u64 m, bool dbl, int rm, bool fz) +{ + const struct fp_fmt *f = dbl ? &fmt_d : &fmt_s; + unsigned int drop = 63 - f->p; + int be = exp + f->bias; + u64 lost, half, mant; + + if (be <= 0) { + if (fz) + return 0; + /* subnormal: more bits drop, the exponent field stays 0 */ + m = shift_sticky(m, 1 - be); + be = 0; + } + half = BIT_ULL(drop - 1); + lost = m & (BIT_ULL(drop) - 1); + mant = m >> drop; + if (fp_round_up(sign, mant & 1, lost, half, rm)) + mant++; + if (mant >> f->p) { /* carried out: one bit more */ + mant >>= 1; + be++; + } + if (be == 0 && mant >> (f->p - 1)) + be = 1; /* rounded up to the smallest normal */ + if (be >= 2 * f->bias + 1) + return overflow_value(sign, dbl, rm); + + mant &= BIT_ULL(f->p - 1) - 1; + return ((u64)sign << (dbl ? 63 : 31)) | ((u64)be << (f->p - 1)) | mant; +} + +static u64 nan_result(const struct fp_num *n, bool dbl) +{ + u64 q = n->raw | BIT_ULL(51); /* quieted, the raw form is a double */ + + if (dbl) + return q; + return ((q >> 63) << 31) | GENMASK_ULL(30, 23) | ((q >> 29) & GENMASK_ULL(22, 0)); +} + +static u64 do_add(struct fp_num a, struct fp_num b, bool sub, bool dbl, int rm, bool fz) +{ + u64 m; + int exp; + bool sign; + + if (sub) + b.sign = !b.sign; + if (a.cls == FP_NAN) + return nan_result(&a, dbl); + if (b.cls == FP_NAN) + return nan_result(&b, dbl); + if (a.cls == FP_INF || b.cls == FP_INF) { + if (a.cls == FP_INF && b.cls == FP_INF && a.sign != b.sign) + return make_nan(dbl); + return make_inf(a.cls == FP_INF ? a.sign : b.sign, dbl); + } + if (a.cls == FP_ZERO && b.cls == FP_ZERO) { + sign = a.sign == b.sign ? a.sign : rm == RM_DOWN; + return (u64)sign << (dbl ? 63 : 31); + } + if (a.cls == FP_ZERO) + a = b; + else if (b.cls != FP_ZERO) { + if (a.exp < b.exp || (a.exp == b.exp && a.m < b.m)) + swap(a, b); + /* one guard bit below the sticky: m moves down one */ + exp = a.exp; + a.m >>= 1; + b.m = shift_sticky(b.m >> 1, a.exp - b.exp); + if (a.sign == b.sign) { + m = a.m + b.m; + } else { + m = a.m - b.m; + if (!m) + return (u64)(rm == RM_DOWN) << (dbl ? 63 : 31); + } + a.m = m; + a.exp = exp + 1; + while (!(a.m & BIT_ULL(62))) { + a.m <<= 1; + a.exp--; + } + } + return pack(a.sign, a.exp, a.m, dbl, rm, fz); +} + +static u64 do_mul(const struct fp_num *a, const struct fp_num *b, bool dbl, int rm, bool fz) +{ + bool sign = a->sign != b->sign; + u64 al = (u32)a->m, ah = a->m >> 32, bl = (u32)b->m, bh = b->m >> 32; + u64 ll, lh, hl, hh, mid, hi, lo, m; + int exp; + + if (a->cls == FP_NAN) + return nan_result(a, dbl); + if (b->cls == FP_NAN) + return nan_result(b, dbl); + if (a->cls == FP_INF || b->cls == FP_INF) { + if (a->cls == FP_ZERO || b->cls == FP_ZERO) + return make_nan(dbl); + return make_inf(sign, dbl); + } + if (a->cls == FP_ZERO || b->cls == FP_ZERO) + return (u64)sign << (dbl ? 63 : 31); + + ll = al * bl; + lh = al * bh; + hl = ah * bl; + hh = ah * bh; + mid = (ll >> 32) + (u32)lh + (u32)hl; + lo = (mid << 32) | (u32)ll; + hi = hh + (lh >> 32) + (hl >> 32) + (mid >> 32); + + /* two bits 62 multiplied: the product's top bit is 124 or 125 */ + exp = a->exp + b->exp; + if (hi & BIT_ULL(61)) { /* bit 125 */ + m = (hi << 1) | (lo >> 63); + lo <<= 1; + exp++; + } else { + m = (hi << 2) | (lo >> 62); + lo <<= 2; + } + return pack(sign, exp, m | (lo != 0), dbl, rm, fz); +} + +/* frcp: the hardware gives only an approximation, the exact value is fine */ +static u64 do_frcp(const struct fp_num *a, bool dbl, int rm, bool fz) +{ + u64 rem = BIT_ULL(62), q = 0; + int i, exp = -a->exp; + + if (a->cls == FP_NAN) + return nan_result(a, dbl); + if (a->cls == FP_ZERO) + return make_inf(a->sign, dbl); + if (a->cls == FP_INF) + return (u64)a->sign << (dbl ? 63 : 31); + + for (i = 0; i <= 62; i++) { + q <<= 1; + if (rem >= a->m) { + rem -= a->m; + q |= 1; + } + rem <<= 1; + } + while (!(q & BIT_ULL(62))) { + q <<= 1; + exp--; + } + return pack(a->sign, exp, q | (rem != 0), dbl, rm, fz); +} + +/* frsqr: 1 / sqrt(x), also an approximation in hardware */ +static u64 do_frsqr(const struct fp_num *a, bool dbl, int rm, bool fz) +{ + struct fp_num r = { .cls = FP_NORMAL }; + u64 v, root = 0, bit = BIT_ULL(62), m; + int exp = a->exp; + + if (a->cls == FP_NAN) + return nan_result(a, dbl); + if (a->cls == FP_ZERO) + return make_inf(false, dbl); + if (a->sign) + return make_nan(dbl); + if (a->cls == FP_INF) + return 0; + + /* the square root of m with 31 significant bits is plenty */ + m = a->m; + if (exp & 1) { + v = m >> 1; + exp++; + } else { + v = m; + } + while (bit > v) + bit >>= 2; + while (bit) { + if (v >= root + bit) { + v -= root + bit; + root = (root >> 1) + bit; + } else { + root >>= 1; + } + bit >>= 2; + } + r.m = root; + r.exp = (exp - 62) / 2 + 62; /* exp - 62 is even */ + while (!(r.m & BIT_ULL(62))) { + r.m <<= 1; + r.exp--; + } + return do_frcp(&r, dbl, rm, fz); +} + +/* To the low 32 bits: fix rounds by RM, ftrunc chops */ +static u64 do_fix(const struct fp_num *a, bool dbl, int rm) +{ + u64 mant, lost, half; + int shift; + + if (a->cls == FP_NAN || a->cls == FP_INF) + return make_nan(true); + if (a->cls == FP_ZERO) + return 0; + + shift = 62 - a->exp; + if (shift <= 0) + return make_nan(true); + if (shift > 63) { + mant = 0; + lost = 1; + half = BIT_ULL(63); + } else { + mant = a->m >> shift; + lost = a->m & (BIT_ULL(shift) - 1); + half = BIT_ULL(shift - 1); + } + if (fp_round_up(a->sign, mant & 1, lost, half, rm)) + mant++; + return (u32)(a->sign ? -(s64)mant : (s64)mant); +} + +/* a > b; both are not NaN */ +static bool fp_greater(const struct fp_num *a, const struct fp_num *b) +{ + int mag; + + if (a->cls == FP_ZERO && b->cls == FP_ZERO) + return false; + if (a->cls != FP_ZERO && b->cls != FP_ZERO && a->sign != b->sign) + return b->sign; + if (a->cls == FP_ZERO) + return b->sign; + if (b->cls == FP_ZERO) + return !a->sign; + + if (a->cls == FP_INF || b->cls == FP_INF) + mag = (a->cls == FP_INF) - (b->cls == FP_INF); + else if (a->exp != b->exp) + mag = a->exp > b->exp ? 1 : -1; + else + mag = a->m == b->m ? 0 : a->m > b->m ? 1 : -1; + return a->sign ? mag < 0 : mag > 0; +} + +/* + * Pending result exception: the value popped at entry, RR its register. Mask + * status bits follow the hardware, per pipeline unit. + */ +bool i860_fp_result_pending(unsigned long fsr) +{ + return (fsr & FSR_FTE) && + ((fsr & (FSR_MU | FSR_MO | FSR_AU | FSR_AO)) || + ((fsr & FSR_TI) && (fsr & (FSR_MI | FSR_AI)))); +} + +/* The value has a wrapped exponent. Return it as a denormal, rounded by RM */ +static u64 denormalize(u64 val, bool dbl, bool adder, unsigned long fsr, int rm) +{ + unsigned int ebits = dbl ? (val >> 52) & 0x7ff : (val >> 23) & 0xff; + bool sign = dbl ? val >> 63 : (val >> 31) & 1; + u64 m = dbl ? (val & GENMASK_ULL(51, 0)) | BIT_ULL(52) + : (val & GENMASK_ULL(22, 0)) | BIT_ULL(23); + int e = ebits; + + /* single: the adder has 3 more bits in AE, a product is always in range */ + if (!dbl) + e |= (adder ? (fsr >> FSR_AE_SHIFT) & 7 : 7) << 8; + if (ebits || (!dbl && adder && e)) + e -= 2048; + else + e = 0; + + /* e is the biased exponent, zero or below */ + m <<= dbl ? 10 : 39; + return pack(sign, e - (dbl ? 1023 : 127), m, dbl, rm, false); +} + +#define FSR_MSTAT (FSR_MU | FSR_MO | FSR_MI | FSR_MA) +#define FSR_ASTAT (FSR_AU | FSR_AO | FSR_AI | FSR_AA | FSR_AE) + +void i860_fp_result(struct pt_regs *regs) +{ + unsigned long fsr = regs->user.fsr; + unsigned int rr = (fsr & FSR_RR) >> FSR_RR_SHIFT; + int rm = (fsr >> FSR_RM_SHIFT) & 3; + u64 m3 = regs->pipe.m[0][0] | ((u64)regs->pipe.m[0][1] << 32); + u64 a3 = regs->pipe.a[0][0] | ((u64)regs->pipe.a[0][1] << 32); + bool mdbl = fsr & FSR_MRP, adbl = fsr & FSR_ARP; + + if (fsr & FSR_MO) + m3 = overflow_value(mdbl ? m3 >> 63 : (m3 >> 31) & 1, mdbl, rm); + else if (fsr & FSR_MU) + m3 = denormalize(m3, mdbl, false, fsr, rm); + if (fsr & (FSR_MO | FSR_MU)) + set_reg(regs, rr, mdbl, m3); + if (fsr & FSR_AO) + a3 = overflow_value(adbl ? a3 >> 63 : (a3 >> 31) & 1, adbl, rm); + else if (fsr & FSR_AU) + a3 = denormalize(a3, adbl, true, fsr, rm); + if (fsr & (FSR_AO | FSR_AU)) + set_reg(regs, rr, adbl, a3); + + /* as SVR4: the result goes on through the last stage, for a pipelined pop; only RR is set */ + regs->pipe.m[0][0] = (u32)m3; + regs->pipe.m[0][1] = m3 >> 32; + regs->pipe.a[0][0] = (u32)a3; + regs->pipe.a[0][1] = a3 >> 32; + regs->pipe.fsr[0] &= ~(FSR_MSTAT | FSR_ASTAT); + + /* an inexact result is only recorded once: TI off, as for a masked one */ + regs->user.fsr = fsr & ~(FSR_TI | FSR_MU | FSR_MO | FSR_MI | FSR_MA | FSR_AU | FSR_AO | + FSR_AI | FSR_AA | FSR_MRP | FSR_ARP | FSR_RR); +} + +/* What the instruction would do to its pipe: last stage to FDEST, RES into the first. */ +static void fp_pipe_advance(struct pt_regs *regs, bool mul, unsigned int stages, + unsigned int fdest, u64 res, bool r) +{ + unsigned long (*st)[2] = mul ? regs->pipe.m : regs->pipe.a; + unsigned long prec = mul ? FSR_MRP : FSR_ARP; + unsigned long mask = (mul ? FSR_MSTAT : FSR_ASTAT) | prec; + bool last_dbl = regs->pipe.fsr[0] & prec; + unsigned int i; + + set_reg(regs, fdest, last_dbl, st[0][0] | ((u64)st[0][1] << 32)); + for (i = 0; i + 1 < stages; i++) { + st[i][0] = st[i + 1][0]; + st[i][1] = st[i + 1][1]; + regs->pipe.fsr[i] = (regs->pipe.fsr[i] & ~mask) | (regs->pipe.fsr[i + 1] & mask); + } + st[i][0] = (u32)res; + st[i][1] = res >> 32; + regs->pipe.fsr[i] = (regs->pipe.fsr[i] & ~mask) | (r ? prec : 0); + /* RR of an earlier scalar result would get the value of a pending pipelined one */ + regs->user.fsr &= ~FSR_RR; +} + +/* Source exception on the instruction INSN: result in the registers or CC */ +int i860_fp_source(struct pt_regs *regs, u32 insn) +{ + unsigned long fsr = regs->user.fsr; + unsigned int op = insn & 0x7f, fdest = (insn >> 16) & 31; + unsigned int fsrc1 = (insn >> 11) & 31, fsrc2 = (insn >> 21) & 31; + bool s = insn & 0x100, r = insn & 0x80, fz = fsr & FSR_FZ; + int rm = (fsr >> FSR_RM_SHIFT) & 3; + struct fp_num a = unpack(get_reg(regs, fsrc1, s), s); + struct fp_num b = unpack(get_reg(regs, fsrc2, s), s); + u64 res; + + /* the compares have only a pipelined format */ + if ((insn & 0x400) && op != 0x20 && op != 0x30 && op != 0x31 && op != 0x34 && op != 0x35) + return -EOPNOTSUPP; + + switch (op) { + case 0x20: + res = do_mul(&a, &b, r, rm, fz); + break; + case 0x22: + res = do_frcp(&b, r, rm, fz); + break; + case 0x23: + res = do_frsqr(&b, r, rm, fz); + break; + case 0x30: + case 0x31: + res = do_add(a, b, op & 1, r, rm, fz); + break; + case 0x32: + res = do_fix(&a, r, rm); + break; + case 0x3a: + res = do_fix(&a, r, RM_CHOP); + break; + case 0x33: + switch (a.cls) { + case FP_NAN: + res = nan_result(&a, r); + break; + case FP_INF: + res = make_inf(a.sign, r); + break; + case FP_ZERO: + res = (u64)a.sign << (r ? 63 : 31); + break; + default: + res = pack(a.sign, a.exp, a.m, r, rm, fz); + } + break; + case 0x34: + case 0x35: { + bool cc = false; + + if (a.cls != FP_NAN && b.cls != FP_NAN) { + if (op == 0x34) + cc = fp_greater(&a, &b); + else + cc = !fp_greater(&a, &b) && !fp_greater(&b, &a); + } + regs->user.psr = cc ? regs->user.psr | PSR_CC : regs->user.psr & ~PSR_CC; + return 0; + } + default: + return -EOPNOTSUPP; + } + if (insn & 0x400) + fp_pipe_advance(regs, op == 0x20, op == 0x20 && s ? 2 : 3, fdest, res, r); + else + set_reg(regs, fdest, r, res); + return 0; +} diff --git a/arch/i860/kernel/head.S b/arch/i860/kernel/head.S new file mode 100644 index 000000000000..013e315c030c --- /dev/null +++ b/arch/i860/kernel/head.S @@ -0,0 +1,42 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Kernel entry from the boot block: supervisor mode, interrupts off, the + * firmware page tables (identity, uncached) still active. + * Copyright (C) 2026 René Rebe + */ + +#include +#include +#include +#include +#include + + __HEAD +ENTRY(_start) + st.c %r0,%psr + st.c %r0,%fsr + /* supervisor writes honour read-only pages (copy-on-write) */ + ld.c %epsr,%r4 + or EPSR_WP,%r4,%r4 + st.c %r4,%epsr + + orh [init_thread_union]@h,%r0,%sp + or [init_thread_union]@l,%sp,%sp + addu THREAD_SIZE-PT_SIZE,%sp,%sp + mov %r0,%fp + + orh [__bss_start]@h,%r0,%r4 + or [__bss_start]@l,%r4,%r4 + orh [__bss_stop]@h,%r0,%r5 + or [__bss_stop]@l,%r5,%r5 + br 2f + nop +1: st.l %r0,0(%r4) + addu 4,%r4,%r4 +2: subs %r4,%r5,%r0 /* CC = r4 < r5 */ + bc 1b + + call start_kernel + nop +3: br 3b + nop diff --git a/arch/i860/kernel/i860_ksyms.c b/arch/i860/kernel/i860_ksyms.c new file mode 100644 index 000000000000..e2c8a49bd3d8 --- /dev/null +++ b/arch/i860/kernel/i860_ksyms.c @@ -0,0 +1,32 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Symbols for modules from assembler code and libgcc. + * Copyright (C) 2026 René Rebe + */ + +#include +#include +#include + +EXPORT_SYMBOL(memcpy); +EXPORT_SYMBOL(memmove); +EXPORT_SYMBOL(memset); +EXPORT_SYMBOL(__copy_user); +EXPORT_SYMBOL(__clear_user_asm); + +#define LIBGCC(name) extern void name(void); EXPORT_SYMBOL(name) + +LIBGCC(__divsi3); +LIBGCC(__udivsi3); +LIBGCC(__modsi3); +LIBGCC(__umodsi3); +LIBGCC(__muldi3); +LIBGCC(__divdi3); +LIBGCC(__udivdi3); +LIBGCC(__moddi3); +LIBGCC(__umoddi3); +LIBGCC(__ashldi3); +LIBGCC(__ashrdi3); +LIBGCC(__lshrdi3); +LIBGCC(__cmpdi2); +LIBGCC(__ucmpdi2); diff --git a/arch/i860/kernel/irq.c b/arch/i860/kernel/irq.c new file mode 100644 index 000000000000..ef2a656f09d6 --- /dev/null +++ b/arch/i860/kernel/irq.c @@ -0,0 +1,137 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Intel 82380 interrupt controller: three 8259A-style banks, internally + * cascaded C -> B IR2 -> A IR2 -> CPU INT, level triggered. Each IRQ has a + * vector register; it is programmed with the IRQ number, which one load + * from 0x1c000800 (interrupt acknowledge) returns. + * + * Copyright (C) 2026 René Rebe + */ + +#include +#include +#include +#include +#include + +#define ISP_BASE 0x1c000000 +#define ISP_INTA 0x800 + +#define BANK_A 0 +#define BANK_B 1 +#define BANK_C 2 +#define NBANKS 3 +#define CASCADE_LINE 2 + +static const u16 cmd_port[NBANKS] = { 0x060, 0x040, 0x140 }; +static const u16 imr_port[NBANKS] = { 0x260, 0x240, 0x340 }; +static const u16 icw2_port[NBANKS] = { 0x460, 0x440, 0x540 }; + +/* vector register offsets; slot 2 is IRQ1.5 ("ICW2 written") */ +static const s16 vector_port[NR_IRQS] = { + 0x070, 0x270, 0x470, 0x670, 0x078, -1, -1, 0x678, + 0x050, 0x250, -1, 0x650, 0x058, 0x258, 0x458, 0x658, + 0x150, 0x350, 0x550, 0x750, 0x158, 0x358, 0x558, 0x758, +}; + +static void __iomem *isp; +static u8 imr[NBANKS] = { + 0xff & ~BIT(CASCADE_LINE), 0xff & ~BIT(CASCADE_LINE), 0xff +}; + +static void i82380_write_imr(unsigned int bank) +{ + writeb(imr[bank], isp + imr_port[bank]); +} + +static void i82380_mask(struct irq_data *d) +{ + unsigned int irq = d->irq; + + imr[irq >> 3] |= BIT(irq & 7); + i82380_write_imr(irq >> 3); +} + +static void i82380_unmask(struct irq_data *d) +{ + unsigned int irq = d->irq; + + imr[irq >> 3] &= ~BIT(irq & 7); + i82380_write_imr(irq >> 3); +} + +/* Specific EOI for the level, then for the cascade lines above it. */ +static void i82380_eoi(unsigned int irq) +{ + unsigned int bank = irq >> 3; + + writeb(0x60 | (irq & 7), isp + cmd_port[bank]); + while (bank-- > BANK_A) + writeb(0x60 | CASCADE_LINE, isp + cmd_port[bank]); +} + +static void i82380_mask_ack(struct irq_data *d) +{ + i82380_mask(d); + i82380_eoi(d->irq); +} + +static struct irq_chip i82380_chip = { + .name = "82380", + .irq_mask = i82380_mask, + .irq_unmask = i82380_unmask, + .irq_mask_ack = i82380_mask_ack, +}; + +/* The lowest priority level reads as 7 when no request is in service. */ +static bool i82380_spurious(unsigned int irq) +{ + unsigned int bank = irq >> 3; + + if ((irq & 7) != 7) + return false; + if (readb(isp + cmd_port[bank]) & 0x80) /* ISR (OCW3 0x0b) */ + return false; + while (bank-- > BANK_A) + writeb(0x20, isp + cmd_port[bank]); + return true; +} + +static void i82380_handle_irq(struct pt_regs *regs) +{ + unsigned int irq = readl(isp + ISP_INTA) & 0xff; + + if (irq >= NR_IRQS || i82380_spurious(irq)) + return; + generic_handle_irq(irq); +} + +void __init init_IRQ(void) +{ + unsigned int irq, bank; + + isp = ioremap(ISP_BASE, 0x1000); + + for (bank = BANK_A; bank < NBANKS; bank++) + writeb(0xff, isp + imr_port[bank]); + + for (irq = 0; irq < NR_IRQS; irq++) + if (vector_port[irq] >= 0) + writeb(irq, isp + vector_port[irq]); + + for (bank = BANK_A; bank < NBANKS; bank++) { + writeb(0x1a, isp + cmd_port[bank]); /* ICW1: level, single, no ICW4 */ + writeb(0x08, isp + imr_port[bank]); /* ICW2 */ + readb(isp + icw2_port[bank]); /* clears the IRQ1.5 request */ + writeb(0x0b, isp + cmd_port[bank]); /* OCW3: read ISR */ + i82380_write_imr(bank); + } + + for (irq = 0; irq < NR_IRQS; irq++) { + if ((irq == CASCADE_LINE) || (irq == 8 + CASCADE_LINE)) + continue; + irq_set_chip_and_handler(irq, &i82380_chip, handle_level_irq); + } + + set_handle_irq(i82380_handle_irq); +} diff --git a/arch/i860/kernel/module.c b/arch/i860/kernel/module.c new file mode 100644 index 000000000000..0350d80eedb1 --- /dev/null +++ b/arch/i860/kernel/module.c @@ -0,0 +1,176 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Module relocation. call and br reach 128 MB, the kernel is about 500 MB above vmalloc: + * modules share a window that fits that reach and call the kernel through veneers. + * Copyright (C) 2026 René Rebe + */ + +#include +#include +#include +#include +#include +#include +#include + +/* orh h(S),r0,r31; or l(S),r31,r31; bri r31; nop. r31 is a per instruction temporary. */ +struct i860_veneer { + u32 insn[4]; +}; + +static struct execmem_info execmem_info __ro_after_init; + +struct execmem_info __init *execmem_arch_setup(void) +{ + execmem_info = (struct execmem_info){ + .ranges = { + [EXECMEM_DEFAULT] = { + .start = MODULES_VADDR, + .end = MODULES_END, + .pgprot = PAGE_KERNEL_EXEC, + .alignment = 1, + }, + }, + }; + return &execmem_info; +} + +int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs, + char *secstrings, struct module *mod) +{ + Elf_Shdr *plt = NULL; + unsigned long n = 0; + unsigned int i; + + for (i = 1; i < hdr->e_shnum; i++) + if (!strcmp(secstrings + sechdrs[i].sh_name, ".plt")) + plt = &sechdrs[i]; + if (!plt) { + pr_err("%s: module has no .plt section\n", mod->name); + return -ENOEXEC; + } + + /* upper bound: a veneer for every call, equal targets then share one */ + for (i = 1; i < hdr->e_shnum; i++) { + const Elf_Rela *rela = (void *)hdr + sechdrs[i].sh_offset; + unsigned long j, count = sechdrs[i].sh_size / sizeof(*rela); + + if (sechdrs[i].sh_type != SHT_RELA || + !(sechdrs[sechdrs[i].sh_info].sh_flags & SHF_ALLOC)) + continue; + for (j = 0; j < count; j++) + if (ELF32_R_TYPE(rela[j].r_info) == R_860_PC26) + n++; + } + + plt->sh_type = SHT_NOBITS; + plt->sh_flags = SHF_EXECINSTR | SHF_ALLOC; + plt->sh_addralign = sizeof(u32); + plt->sh_size = n * sizeof(struct i860_veneer); + mod->arch.plt_shndx = plt - sechdrs; + mod->arch.plt_max = n; + mod->arch.plt_used = 0; + return 0; +} + +static unsigned long i860_veneer(Elf_Shdr *sechdrs, struct module *me, unsigned long target) +{ + struct i860_veneer *v = (void *)sechdrs[me->arch.plt_shndx].sh_addr; + struct i860_veneer new = { { + 0xec1f0000 | (target >> 16), /* orh */ + 0xe7ff0000 | (target & 0xffff), /* or */ + 0x4000f800, /* bri r31 */ + 0xa0000000, /* shl r0,r0,r0 */ + } }; + unsigned int i; + + for (i = 0; i < me->arch.plt_used; i++) + if (!memcmp(&v[i], &new, sizeof(new))) + return (unsigned long)&v[i]; + if (WARN_ON(i >= me->arch.plt_max)) + return 0; + v[i] = new; + me->arch.plt_used++; + return (unsigned long)&v[i]; +} + +static inline u32 i860_split(u32 value) +{ + return ((value & 0xf800) << 5) | (value & 0x7ff); +} + +int apply_relocate_add(Elf_Shdr *sechdrs, const char *strtab, unsigned int symindex, + unsigned int relsec, struct module *me) +{ + const Elf_Rela *rela = (void *)sechdrs[relsec].sh_addr; + unsigned long count = sechdrs[relsec].sh_size / sizeof(*rela), i; + const Elf_Sym *symtab = (void *)sechdrs[symindex].sh_addr; + unsigned long base = sechdrs[sechdrs[relsec].sh_info].sh_addr; + + for (i = 0; i < count; i++) { + const Elf_Sym *sym = &symtab[ELF32_R_SYM(rela[i].r_info)]; + unsigned int type = ELF32_R_TYPE(rela[i].r_info); + u32 *where = (u32 *)(base + rela[i].r_offset); + u32 value = sym->st_value + rela[i].r_addend; + long rel; + + switch (type) { + case R_860_NONE: + break; + case R_860_32: + *where = value; + break; + case R_860_PC26: + rel = (long)value - (long)where - 4; + if (rel < -0x8000000 || rel >= 0x8000000) { + value = i860_veneer(sechdrs, me, value); + if (!value) + return -ENOEXEC; + rel = (long)value - (long)where - 4; + } + *where = (*where & ~0x3ffffff) | ((rel >> 2) & 0x3ffffff); + break; + case R_860_PC16: + rel = (long)value - (long)where - 4; + if (rel < -0x20000 || rel >= 0x20000) { + pr_err("%s: PC16 reach exceeded for %s\n", me->name, + strtab + sym->st_name); + return -ENOEXEC; + } + *where = (*where & ~0x1f07ff) | (i860_split(rel >> 2) & 0x1f07ff); + break; + case R_860_HIGH: + *where = (*where & 0xffff0000) | (value >> 16); + break; + case R_860_HIGHADJ: + *where = (*where & 0xffff0000) | ((value + 0x8000) >> 16); + break; + case R_860_LOW0: + *where = (*where & ~0xffff) | (value & 0xffff); + break; + case R_860_LOW1: + *where = (*where & ~0xfffe) | (value & 0xfffe); + break; + case R_860_LOW2: + *where = (*where & ~0xfffc) | (value & 0xfffc); + break; + case R_860_LOW3: + *where = (*where & ~0xfff8) | (value & 0xfff8); + break; + case R_860_SPLIT0: + *where = (*where & ~0x1f07ff) | i860_split(value); + break; + case R_860_SPLIT1: + *where = (*where & ~0x1f07fe) | (i860_split(value) & 0x1f07fe); + break; + case R_860_SPLIT2: + *where = (*where & ~0x1f07fc) | (i860_split(value) & 0x1f07fc); + break; + default: + pr_err("%s: unknown relocation %u against %s\n", me->name, type, + strtab + sym->st_name); + return -ENOEXEC; + } + } + return 0; +} diff --git a/arch/i860/kernel/process.c b/arch/i860/kernel/process.c new file mode 100644 index 000000000000..e06f64318a77 --- /dev/null +++ b/arch/i860/kernel/process.c @@ -0,0 +1,138 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (C) 2026 René Rebe */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +void (*pm_power_off)(void); +EXPORT_SYMBOL(pm_power_off); + +/* Layout of the frame __switch_to pops (entry.S SW_SIZE). */ +struct switch_frame { + unsigned long r1, fp; + unsigned long r4_r15[12]; + unsigned long f2_f7[6]; +}; + +asmlinkage void ret_from_fork(void); + +asmlinkage void i860_ret_from_fork(struct task_struct *prev, + struct pt_regs *regs, + int (*fn)(void *), void *fn_arg) +{ + schedule_tail(prev); + if (unlikely(fn)) { + fn(fn_arg); + /* kernel_execve() succeeded: return to the new user image */ + } + syscall_exit_to_user_mode(regs); +} + +int copy_thread(struct task_struct *p, const struct kernel_clone_args *args) +{ + unsigned long clone_flags = args->flags; + unsigned long usp = args->stack; + struct pt_regs *childregs = task_pt_regs(p); + struct switch_frame *sw = (struct switch_frame *)childregs - 1; + + memset(sw, 0, sizeof(*sw)); + sw->r1 = (unsigned long)ret_from_fork; + + if (unlikely(args->fn)) { + memset(childregs, 0, sizeof(*childregs)); + childregs->user.psr = PSR_IT; + sw->r4_r15[0] = (unsigned long)args->fn; + sw->r4_r15[1] = (unsigned long)args->fn_arg; + } else { + *childregs = *current_pt_regs(); + childregs->user.gpr[16] = 0; + if (usp) + childregs->user.gpr[2] = usp; + if (clone_flags & CLONE_SETTLS) + childregs->user.gpr[I860_TP_REG] = args->tls; + } + + childregs->pipe.used = 0; + /* a watchpoint belongs to the thread that was told about it */ + childregs->user.psr &= ~(PSR_BR | PSR_BW); + p->thread.db = 0; + + p->thread.ksp = (unsigned long)sw; + return 0; +} + +void start_thread(struct pt_regs *regs, unsigned long pc, unsigned long sp) +{ + memset(regs, 0, sizeof(*regs)); + /* return from a trap into user mode with interrupts on */ + regs->user.psr = PSR_IT | PSR_PU | PSR_PIM; + regs->user.fir = pc; + /* FP traps for IEEE results with gradual underflow, round to nearest */ + regs->user.fsr = FSR_FTE; + regs->user.gpr[2] = sp; +} + +void flush_thread(void) +{ + current->thread.db = 0; +} + +unsigned long __get_wchan(struct task_struct *p) +{ + unsigned long fp, pc; + int count = 0; + + fp = ((struct switch_frame *)p->thread.ksp)->fp; + do { + if (fp < (unsigned long)task_stack_page(p) || + fp >= (unsigned long)task_stack_page(p) + THREAD_SIZE - 8) + return 0; + pc = ((unsigned long *)fp)[1]; + if (!in_sched_functions(pc)) + return pc; + fp = ((unsigned long *)fp)[0]; + } while (count++ < 16); + return 0; +} + +void arch_cpu_idle(void) +{ + unsigned long seq = READ_ONCE(i860_irq_seq), tmp; + + raw_local_irq_enable(); + /* no halt instruction: wait for an interrupt to have run */ + asm volatile("1: ld.l 0(%1),%0\n" + " bte %0,%2,1b" + : "=&r" (tmp) : "r" (&i860_irq_seq), "r" (seq)); +} + +void machine_restart(char *cmd) +{ + local_irq_disable(); + pr_emerg("System restart not supported, halting\n"); + for (;;) + ; +} + +void machine_halt(void) +{ + local_irq_disable(); + for (;;) + ; +} + +void machine_power_off(void) +{ + if (pm_power_off) + pm_power_off(); + machine_halt(); +} diff --git a/arch/i860/kernel/ptrace.c b/arch/i860/kernel/ptrace.c new file mode 100644 index 000000000000..bd7ef8acd8e3 --- /dev/null +++ b/arch/i860/kernel/ptrace.c @@ -0,0 +1,117 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (C) 2026 René Rebe */ + +#include +#include +#include +#include +#include +#include + +enum i860_regset { + REGSET_GPR, +}; + +static int gpr_get(struct task_struct *target, + const struct user_regset *regset, struct membuf to) +{ + return membuf_write(&to, &task_pt_regs(target)->user, + sizeof(struct user_regs_struct)); +} + +static int gpr_set(struct task_struct *target, + const struct user_regset *regset, unsigned int pos, + unsigned int count, const void *kbuf, const void __user *ubuf) +{ + struct pt_regs *regs = task_pt_regs(target); + struct user_regs_struct uregs = regs->user; + int ret; + + ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &uregs, 0, + sizeof(uregs)); + if (ret) + return ret; + /* the trap state in psr stays under kernel control, the mode goes with fir */ + regs->user.psr = (regs->user.psr & ~(PSR_DS | PSR_DIM | PSR_KNF)) | + (uregs.psr & (PSR_DS | PSR_DIM | PSR_KNF)); + /* in a system call stop: the number the entry code rereads */ + if (regs->syscallno >= 0 && + uregs.gpr[I860_SYSCALL_NR_REG] != regs->user.gpr[I860_SYSCALL_NR_REG]) + regs->syscallno = uregs.gpr[I860_SYSCALL_NR_REG]; + memcpy(regs->user.gpr, uregs.gpr, sizeof(uregs.gpr)); + memcpy(regs->user.fpr, uregs.fpr, sizeof(uregs.fpr)); + regs->user.gpr[0] = 0; + regs->user.fir = uregs.fir; + regs->user.fsr = uregs.fsr; + return 0; +} + +static const struct user_regset i860_regsets[] = { + [REGSET_GPR] = { + USER_REGSET_NOTE_TYPE(PRSTATUS), + .n = ELF_NGREG, + .size = sizeof(elf_greg_t), + .align = sizeof(elf_greg_t), + .regset_get = gpr_get, + .set = gpr_set, + }, +}; + +static const struct user_regset_view user_i860_view = { + .name = "i860", + .e_machine = EM_860, + .regsets = i860_regsets, + .n = ARRAY_SIZE(i860_regsets), +}; + +const struct user_regset_view *task_user_regset_view(struct task_struct *task) +{ + return &user_i860_view; +} + +void ptrace_disable(struct task_struct *child) +{ + task_pt_regs(child)->user.psr &= ~(PSR_BR | PSR_BW); + child->thread.db = 0; +} + +static long i860_ptrace_setdb(struct task_struct *child, const struct ptrace_db __user *arg) +{ + struct pt_regs *regs = task_pt_regs(child); + struct ptrace_db db; + + if (copy_from_user(&db, arg, sizeof(db))) + return -EFAULT; + if (db.type & ~(PTRACE_DB_READ | PTRACE_DB_WRITE) || db.addr >= TASK_SIZE) + return -EINVAL; + child->thread.db = db.addr; + regs->user.psr &= ~(PSR_BR | PSR_BW); + if (db.type & PTRACE_DB_READ) + regs->user.psr |= PSR_BR; + if (db.type & PTRACE_DB_WRITE) + regs->user.psr |= PSR_BW; + return 0; +} + +static long i860_ptrace_getdb(struct task_struct *child, struct ptrace_db __user *arg) +{ + unsigned long psr = task_pt_regs(child)->user.psr; + struct ptrace_db db = { + .addr = child->thread.db, + .type = (psr & PSR_BR ? PTRACE_DB_READ : 0) | (psr & PSR_BW ? PTRACE_DB_WRITE : 0), + }; + + return copy_to_user(arg, &db, sizeof(db)) ? -EFAULT : 0; +} + +long arch_ptrace(struct task_struct *child, long request, unsigned long addr, + unsigned long data) +{ + switch (request) { + case PTRACE_GETDB: + return i860_ptrace_getdb(child, (void __user *)data); + case PTRACE_SETDB: + return i860_ptrace_setdb(child, (const void __user *)data); + } + return ptrace_request(child, request, addr, data); +} diff --git a/arch/i860/kernel/setup.c b/arch/i860/kernel/setup.c new file mode 100644 index 000000000000..d6a5c0ac4c8b --- /dev/null +++ b/arch/i860/kernel/setup.c @@ -0,0 +1,260 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Samsung i860 MAGIC Station II setup. + * Copyright (C) 2026 René Rebe + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +unsigned long i860_pfn_offset; +EXPORT_SYMBOL(i860_pfn_offset); + +#define NVRAM_MEMSIZE 0x1f000000UL /* reset code: 1/2/4/8 = 8/16/32/64 MB */ + +/* + * DRAM ends at 4 GB. The last page (trap vector) is left out of memblock + * so that no memory range or high_memory wraps to 0. + */ +static void __init i860_add_bank(unsigned long base, unsigned long size) +{ + if (base + (size - 1) == ~0UL) + size -= PAGE_SIZE; + memblock_add(base, size); +} + +static void __init i860_add_memory(void) +{ + u8 code = *(volatile u8 *)NVRAM_MEMSIZE & 0x0f; + int i; + + switch (code) { + case 1: + i860_add_bank(0xff800000, SZ_8M); + break; + case 2: + i860_add_bank(0xff000000, SZ_16M); + break; + case 4: + /* large modules in bank H only: A23 = 1 */ + for (i = 0; i < 4; i++) + i860_add_bank(0xfc800000 + i * SZ_16M, SZ_8M); + break; + case 8: + i860_add_bank(0xfc000000, SZ_64M); + break; + default: + pr_warn("NVRAM memory size code %x unknown, assuming 8 MB\n", + code); + i860_add_bank(0xff800000, SZ_8M); + break; + } +} + +void __init arch_zone_limits_init(unsigned long *max_zone_pfns) +{ + max_zone_pfns[ZONE_NORMAL] = max_low_pfn; +} + +void __init setup_arch(char **cmdline_p) +{ + i860_trap_init(); + i860_early_console_init(); + + strscpy(boot_command_line, CONFIG_CMDLINE, COMMAND_LINE_SIZE); + *cmdline_p = boot_command_line; + + setup_initial_init_mm(_stext, _etext, _edata, _end); + + i860_add_memory(); + memblock_reserve(__pa_symbol(_text), _end - _text); + memblock_reserve(I860_FW_START, I860_TRAP_PAGE - I860_FW_START); + + parse_early_param(); + memblock_allow_resize(); + + min_low_pfn = PFN_UP(memblock_start_of_DRAM()); + max_low_pfn = max_pfn = PFN_DOWN(memblock_end_of_DRAM()); + i860_pfn_offset = min_low_pfn; + + paging_init(); + i860_early_console_init(); + + /* the firmware wrote cached data there; write it back first */ + i860_flush_dcache_all(); + memblock_phys_free(I860_FW_START, I860_TRAP_PAGE - I860_FW_START); + + memblock_dump_all(); +} + +static struct plat_serial8250_port i860_uart_data[] = { + { + .mapbase = 0x1e000600, + .membase = I860_IO(0x1e000600), + .irq = 19, + .uartclk = 1843200, + .regshift = 3, + .iotype = UPIO_MEM, + .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST, + }, + { + .mapbase = 0x1e000700, + .membase = I860_IO(0x1e000700), + .uartclk = 1843200, + .regshift = 3, + .iotype = UPIO_MEM, + .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST, + }, + { }, +}; + +static struct platform_device i860_uart = { + .name = "serial8250", + .id = PLAT8250_DEV_PLATFORM, + .dev = { + .platform_data = i860_uart_data, + }, +}; + +/* MSM6242-type RTC: one nibble register per 8 bytes */ +static struct resource i860_rtc_res[] = { + DEFINE_RES_MEM(0x1e000000, 0x80), +}; + +static struct msm6242_platform_data i860_rtc_data = { + .reg_shift = 1, +}; + +static struct resource i860_scsi_res[] = { + DEFINE_RES_MEM(0x1c000a00, 0x10), + DEFINE_RES_IRQ(13), +}; + +/* 82596 registers, NVRAM MAC address (one byte per 8 bytes), IRQ */ +static struct resource i860_lan_res[] = { + DEFINE_RES_MEM(0x1c000e00, 0x20), + DEFINE_RES_MEM(0x1f008000, 0x30), + DEFINE_RES_IRQ(14), +}; + +/* + * Frame buffer: 32 bpp at physical 0, 2048-pixel pitch, 1280 x 1024 shown + * (the firmware programs the TMS34020 timing). Each byte lane goes through + * its own Bt459 palette: byte 0 red, 1 green, 2 blue. + */ +#define I860_FB_PHYS 0x00000000 +#define I860_FB_SIZE 0x00800000 +#define I860_RAMDAC_PHYS 0x04000000 +#define I860_GSP_PHYS 0x08000000 +#define I860_GSP_SIZE 0x00000080 +#define BT459_ADDR_LO 0x00 +#define BT459_ADDR_HI 0x10 +#define BT459_PALETTE 0x30 + +static struct resource i860_fb_res[] = { + DEFINE_RES_MEM(I860_FB_PHYS, I860_FB_SIZE), + DEFINE_RES_MEM(I860_GSP_PHYS, I860_GSP_SIZE), +}; + +/* identity palettes in all four RAMDACs: 32-bit writes reach every lane */ +static int __init i860_ramdac_init(void) +{ + void __iomem *dac = ioremap(I860_RAMDAC_PHYS, 0x40); + unsigned int i; + + if (!dac) + return -ENOMEM; + writel(0, dac + BT459_ADDR_LO); + writel(0, dac + BT459_ADDR_HI); + for (i = 0; i < 256; i++) { + writel(i * 0x01010101, dac + BT459_PALETTE); + writel(i * 0x01010101, dac + BT459_PALETTE); + writel(i * 0x01010101, dac + BT459_PALETTE); + } + iounmap(dac); + return 0; +} + +static int __init i860_devices_init(void) +{ + struct platform_device *pdev; + + platform_device_register(&i860_uart); + + pdev = platform_device_register_resndata(NULL, "rtc-msm6242", -1, + i860_rtc_res, ARRAY_SIZE(i860_rtc_res), + &i860_rtc_data, sizeof(i860_rtc_data)); + if (IS_ERR(pdev)) + pr_err("RTC registration failed\n"); + + pdev = platform_device_register_simple("magicst2-scsi", -1, + i860_scsi_res, ARRAY_SIZE(i860_scsi_res)); + if (IS_ERR(pdev)) + pr_err("SCSI registration failed\n"); + + pdev = platform_device_register_simple("magicst2-82596", -1, + i860_lan_res, ARRAY_SIZE(i860_lan_res)); + if (IS_ERR(pdev)) + pr_err("LAN registration failed\n"); + + if (!i860_ramdac_init()) { + pdev = platform_device_register_simple("magicst2fb", -1, + i860_fb_res, ARRAY_SIZE(i860_fb_res)); + if (IS_ERR(pdev)) + pr_err("frame buffer registration failed\n"); + } + return 0; +} +arch_initcall(i860_devices_init); + +static int show_cpuinfo(struct seq_file *m, void *v) +{ + unsigned long epsr = i860_ld_c(epsr); + + seq_printf(m, "cpu\t\t: Intel i860%s\n", + (epsr & EPSR_TYPE) == EPSR_TYPE_XP ? "XP" : "XR"); + seq_printf(m, "epsr\t\t: %08lx\n", epsr); + seq_printf(m, "machine\t\t: Samsung MAGIC Station II\n"); + seq_printf(m, "BogoMIPS\t: %lu.%02lu\n", + loops_per_jiffy / (500000 / HZ), + (loops_per_jiffy / (5000 / HZ)) % 100); + return 0; +} + +static void *c_start(struct seq_file *m, loff_t *pos) +{ + return *pos < 1 ? (void *)1 : NULL; +} + +static void *c_next(struct seq_file *m, void *v, loff_t *pos) +{ + ++*pos; + return NULL; +} + +static void c_stop(struct seq_file *m, void *v) +{ +} + +const struct seq_operations cpuinfo_op = { + .start = c_start, + .next = c_next, + .stop = c_stop, + .show = show_cpuinfo, +}; diff --git a/arch/i860/kernel/signal.c b/arch/i860/kernel/signal.c new file mode 100644 index 000000000000..719d90a4ed1f --- /dev/null +++ b/arch/i860/kernel/signal.c @@ -0,0 +1,167 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (C) 2026 René Rebe */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct rt_sigframe { + struct siginfo info; + struct ucontext uc; +}; + +/* Writable user registers; psr keeps the kernel controlled bits. */ +#define PSR_USER_MASK (PSR_CC | PSR_KNF | PSR_LCC | PSR_DS | PSR_DIM) + +static int restore_sigcontext(struct pt_regs *regs, + struct sigcontext __user *sc) +{ + struct user_regs_struct uregs; + + if (__copy_from_user(&uregs, &sc->regs, sizeof(uregs))) + return -EFAULT; + + memcpy(regs->user.gpr, uregs.gpr, sizeof(uregs.gpr)); + memcpy(regs->user.fpr, uregs.fpr, sizeof(uregs.fpr)); + regs->user.gpr[0] = 0; + regs->user.fir = uregs.fir; + regs->user.fsr = uregs.fsr; + regs->user.psr = (regs->user.psr & ~PSR_USER_MASK) | + (uregs.psr & PSR_USER_MASK); + if (__copy_from_user(®s->pipe, &sc->pipe, sizeof(regs->pipe))) + return -EFAULT; + regs->syscallno = -1; + return 0; +} + +SYSCALL_DEFINE0(rt_sigreturn) +{ + struct pt_regs *regs = current_pt_regs(); + struct rt_sigframe __user *frame; + sigset_t set; + + current->restart_block.fn = do_no_restart_syscall; + + frame = (struct rt_sigframe __user *)regs->user.gpr[2]; + if (!access_ok(frame, sizeof(*frame))) + goto badframe; + if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set))) + goto badframe; + set_current_blocked(&set); + + if (restore_sigcontext(regs, &frame->uc.uc_mcontext)) + goto badframe; + if (restore_altstack(&frame->uc.uc_stack)) + goto badframe; + + return regs->user.gpr[16]; + +badframe: + force_sig(SIGSEGV); + return 0; +} + +static int setup_rt_frame(struct ksignal *ksig, sigset_t *set, + struct pt_regs *regs) +{ + struct rt_sigframe __user *frame; + unsigned long sp = sigsp(regs->user.gpr[2], ksig); + unsigned long ret; + int err = 0; + + /* 16-byte aligned, below the interrupted frame */ + frame = (struct rt_sigframe __user *)((sp - sizeof(*frame)) & ~15UL); + if (!access_ok(frame, sizeof(*frame))) + return -EFAULT; + + if (ksig->ka.sa.sa_flags & SA_SIGINFO) + err |= copy_siginfo_to_user(&frame->info, &ksig->info); + + err |= __put_user(0, &frame->uc.uc_flags); + err |= __put_user(NULL, &frame->uc.uc_link); + err |= __save_altstack(&frame->uc.uc_stack, regs->user.gpr[2]); + err |= __copy_to_user(&frame->uc.uc_mcontext.regs, ®s->user, + sizeof(regs->user)); + err |= __put_user(set->sig[0], &frame->uc.uc_mcontext.oldmask); + /* the handler starts with no state in the pipelines to preserve */ + err |= __copy_to_user(&frame->uc.uc_mcontext.pipe, ®s->pipe, sizeof(regs->pipe)); + regs->pipe.used = 0; + err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set)); + + if (ksig->ka.sa.sa_flags & SA_RESTORER) + ret = (unsigned long)ksig->ka.sa.sa_restorer; + else + ret = VDSO_SYMBOL(current->mm->context.vdso, rt_sigreturn); + if (err) + return -EFAULT; + + regs->user.gpr[1] = ret; + regs->user.gpr[2] = (unsigned long)frame; + regs->user.gpr[16] = ksig->sig; + regs->user.gpr[17] = (unsigned long)&frame->info; + regs->user.gpr[18] = (unsigned long)&frame->uc; + regs->user.fir = (unsigned long)ksig->ka.sa.sa_handler; + /* a killed FP instruction and the dual mode are for the interrupted code, in the frame */ + regs->user.psr &= ~(PSR_KNF | PSR_DS | PSR_DIM); + return 0; +} + +void arch_do_signal_or_restart(struct pt_regs *regs) +{ + struct ksignal ksig; + bool in_syscall = regs->syscallno >= 0; + long ret = regs->user.gpr[16]; + + if (get_signal(&ksig)) { + if (in_syscall) { + switch (ret) { + case -ERESTART_RESTARTBLOCK: + case -ERESTARTNOHAND: + regs->user.gpr[16] = -EINTR; + break; + case -ERESTARTSYS: + if (!(ksig.ka.sa.sa_flags & SA_RESTART)) { + regs->user.gpr[16] = -EINTR; + break; + } + fallthrough; + case -ERESTARTNOINTR: + regs->user.gpr[16] = regs->orig_r16; + i860_syscall_rewind(regs); + break; + } + regs->syscallno = -1; + } + signal_setup_done(setup_rt_frame(&ksig, sigmask_to_save(), regs), + &ksig, 0); + return; + } + + if (in_syscall) { + switch (ret) { + case -ERESTARTNOHAND: + case -ERESTARTSYS: + case -ERESTARTNOINTR: + regs->user.gpr[16] = regs->orig_r16; + i860_syscall_rewind(regs); + break; + case -ERESTART_RESTARTBLOCK: + regs->user.gpr[16] = regs->orig_r16; + regs->user.gpr[I860_SYSCALL_NR_REG] = __NR_restart_syscall; + i860_syscall_rewind(regs); + break; + } + regs->syscallno = -1; + } + + restore_saved_sigmask(); +} diff --git a/arch/i860/kernel/syscall_table.c b/arch/i860/kernel/syscall_table.c new file mode 100644 index 000000000000..11d38f5a6f92 --- /dev/null +++ b/arch/i860/kernel/syscall_table.c @@ -0,0 +1,17 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (C) 2026 René Rebe */ + +#include +#include +#include +#include + +#define __SYSCALL(nr, call) [nr] = (call), +#define __SYSCALL_WITH_COMPAT(nr, native, compat) __SYSCALL(nr, native) + +#define sys_mmap2 sys_mmap_pgoff + +void * const sys_call_table[__NR_syscalls] = { + [0 ... __NR_syscalls - 1] = sys_ni_syscall, +#include +}; diff --git a/arch/i860/kernel/time.c b/arch/i860/kernel/time.c new file mode 100644 index 000000000000..b87094143c59 --- /dev/null +++ b/arch/i860/kernel/time.c @@ -0,0 +1,131 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * 82380 counter 0 (499.2 kHz, inferred from the Stardent kernel) drives + * IRQ8 through an edge-detect flip-flop, for clock events. Counter 3 runs + * free as the clocksource: its output goes to IRQ0, which stays masked. Its + * 16 bits wrap every 131 ms, and printing to the serial console can hold off + * interrupts for longer, so the count is extended in software on every read. + * Time then only loses a wrap, it cannot get stuck inside one. No NO_HZ: the + * i860 has no halt, idle spins anyway. + * Copyright (C) 2026 René Rebe + */ + +#include +#include +#include +#include +#include +#include +#include + +#define PIT_COUNTER0 0x080 +#define PIT_COUNTER3 0x088 +#define PIT_CONTROL 0x680 +#define PIT_CONTROL2 0x688 +#define PIT_PORT61 0x2c0 /* write only: D6 gates counter 3 */ +#define PIT_IRQ 8 +#define PIT_CLOCK 499200 + +static void __iomem *pit; + +static int pit_set_periodic(struct clock_event_device *evt) +{ + unsigned int count = DIV_ROUND_CLOSEST(PIT_CLOCK, HZ); + + writeb(0x34, pit + PIT_CONTROL); /* counter 0, LSB/MSB, mode 2 */ + writeb(count & 0xff, pit + PIT_COUNTER0); + writeb(count >> 8, pit + PIT_COUNTER0); + return 0; +} + +static int pit_set_oneshot(struct clock_event_device *evt) +{ + /* mode 4: a pulse, so every expiry gives the edge that IRQ8 detects */ + writeb(0x38, pit + PIT_CONTROL); + return 0; +} + +static int pit_next_event(unsigned long delta, struct clock_event_device *evt) +{ + writeb(delta & 0xff, pit + PIT_COUNTER0); + writeb(delta >> 8, pit + PIT_COUNTER0); + return 0; +} + +static int pit_shutdown(struct clock_event_device *evt) +{ + writeb(0x30, pit + PIT_CONTROL); /* mode 0, no count: idle */ + return 0; +} + +static struct clock_event_device pit_clockevent = { + .name = "82380", + .features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT, + .rating = 200, + .set_state_periodic = pit_set_periodic, + .set_state_oneshot = pit_set_oneshot, + .set_next_event = pit_next_event, + .set_state_shutdown = pit_shutdown, + .tick_resume = pit_set_periodic, +}; + +static irqreturn_t pit_interrupt(int irq, void *dev_id) +{ + struct clock_event_device *evt = dev_id; + + evt->event_handler(evt); + return IRQ_HANDLED; +} + +/* Two byte reads and the extension: nothing may read the counter in between. */ +static notrace u64 pit_count(void) +{ + static u64 total; + static u16 last; + unsigned long flags; + unsigned int count; + u16 now; + + local_irq_save(flags); + writeb(0x00, pit + PIT_CONTROL2); /* latch counter 3 */ + count = readb(pit + PIT_COUNTER3); + count |= readb(pit + PIT_COUNTER3) << 8; + now = -count; + total += (u16)(now - last); + last = now; + local_irq_restore(flags); + return total; +} + +static u64 pit_clocksource_read(struct clocksource *cs) +{ + return pit_count(); +} + +static struct clocksource pit_clocksource = { + .name = "82380", + .rating = 300, + .read = pit_clocksource_read, + .mask = CLOCKSOURCE_MASK(64), + .flags = CLOCK_SOURCE_IS_CONTINUOUS, +}; + +void __init time_init(void) +{ + pit = ioremap(0x1c000000, 0x1000); + + writeb(0x34, pit + PIT_CONTROL2); /* counter 3: LSB/MSB, mode 2 */ + writeb(0, pit + PIT_COUNTER3); /* the full 16 bits */ + writeb(0, pit + PIT_COUNTER3); + writeb(0x40, pit + PIT_PORT61); /* gate it, leave the speaker off */ + clocksource_register_hz(&pit_clocksource, PIT_CLOCK); + sched_clock_register(pit_count, 64, PIT_CLOCK); + + pit_clockevent.cpumask = cpumask_of(0); + /* half a wrap at most, so that a wait cannot hide one from the extension */ + clockevents_config_and_register(&pit_clockevent, PIT_CLOCK, 0x10, 0x7fff); + + if (request_irq(PIT_IRQ, pit_interrupt, IRQF_TIMER, "timer", + &pit_clockevent)) + pr_err("82380: cannot request timer IRQ\n"); +} diff --git a/arch/i860/kernel/traps.c b/arch/i860/kernel/traps.c new file mode 100644 index 000000000000..3e93ff266a2a --- /dev/null +++ b/arch/i860/kernel/traps.c @@ -0,0 +1,553 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * i860 trap dispatch. The CPU has a single trap vector; the cause is in + * the saved psr. The i860 reports no fault address, so data access traps + * decode the faulting load or store. + * + * Copyright (C) 2026 René Rebe + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +typedef long (*syscall_fn_t)(unsigned long, unsigned long, unsigned long, + unsigned long, unsigned long, unsigned long); + +#define I860_INSN_LOCK 0x4c000001 /* core escape 1 */ +#define I860_INSN_INTOVR 0x4c000004 /* core escape 4 */ +#define I860_INSN_FNOP 0xb0000000 /* shrd r0,r0,r0, in the FP half of a pair */ + +static inline unsigned long reg(struct pt_regs *regs, unsigned int n) +{ + return n ? regs->user.gpr[n] : 0; +} + +void show_regs(struct pt_regs *regs) +{ + int i; + + show_regs_print_info(KERN_DEFAULT); + pr_info("fir %08lx psr %08lx epsr %08lx fsr %08lx\n", + regs->user.fir, regs->user.psr, regs->user.epsr, + regs->user.fsr); + for (i = 0; i < 32; i += 4) + pr_info("r%-2d %08lx %08lx %08lx %08lx\n", i, reg(regs, i), + regs->user.gpr[i + 1], regs->user.gpr[i + 2], + regs->user.gpr[i + 3]); +} + +void die(const char *str, struct pt_regs *regs, long err) +{ + console_verbose(); + pr_emerg("%s: %04lx\n", str, err & 0xffff); + show_regs(regs); + if (!user_mode(regs)) + show_stack(NULL, (unsigned long *)regs->user.gpr[2], KERN_EMERG); + make_task_dead(SIGSEGV); +} + +/* + * Effective address and direction of the faulting load/store. An FP access has + * already updated its autoincrement base, undo that for the rerun: SVR4 d0401e08. + */ +bool i860_decode_access(struct pt_regs *regs, u32 insn, unsigned long *addr, + unsigned int *size, bool *write) +{ + unsigned int op = insn >> 26; + unsigned int src1 = (insn >> 11) & 31; + unsigned int src2 = (insn >> 21) & 31; + bool imm = insn & 0x04000000; + bool inc = false; + long off = (s16)insn; + static const unsigned char fsizes[4] = { 8, 4, 16, 4 }; + + switch (op) { + case 0x00: case 0x01: case 0x04: case 0x05: /* ld.{b,s,l} */ + *size = (op & 4) ? ((insn & 1) ? 4 : 2) : 1; + *write = false; + break; + case 0x03: case 0x07: /* st.{b,s,l} */ + *size = (op & 4) ? ((insn & 1) ? 4 : 2) : 1; + off = (s16)(((insn >> 5) & 0xf800) | (insn & 0x7ff)); + *write = true; + break; + case 0x08: case 0x09: case 0x18: case 0x19: /* fld, pfld */ + *size = fsizes[(insn >> 1) & 3]; + *write = false; + inc = insn & 1; + break; + case 0x0a: case 0x0b: /* fst */ + *size = fsizes[(insn >> 1) & 3]; + *write = true; + inc = insn & 1; + break; + case 0x0f: /* pst.d */ + *size = 8; + *write = true; + inc = insn & 1; + break; + case 0x0d: /* flush */ + *size = 32; + *write = false; + break; + default: + return false; + } + + if (imm || op == 0x03 || op == 0x07 || op == 0x0f || op == 0x0d) + off &= ~(long)(*size - 1); + else + off = reg(regs, src1); + if (inc && src2) + regs->user.gpr[src2] -= off; + *addr = off + reg(regs, src2); + return true; +} + +static bool i860_get_insn(struct pt_regs *regs, unsigned long pc, u32 *insn) +{ + if (user_mode(regs)) + return !get_user(*insn, (u32 __user *)pc); + return !get_kernel_nofault(*insn, (u32 *)pc); +} + +static bool i860_delayed_branch(u32 insn) +{ + switch (insn >> 26) { + case 0x10: case 0x1a: case 0x1b: case 0x1d: case 0x1f: case 0x2d: + return true; + case 0x13: /* core escape */ + return (insn & 0x1f) == 2; /* calli */ + } + return false; +} + +/* + * A faulting instruction in a branch delay slot leaves fir at the slot; + * resume at the branch so that it is taken again. bla must also have its + * increment undone. Dual mode as SVR4 fixes() d042eb84: run the core half of + * the branch alone, with DS set, to get the slot as a pair again. + */ +static bool i860_fixup_delay_slot(struct pt_regs *regs) +{ + unsigned long pc = regs->user.fir - 4; + unsigned long psr = regs->user.psr; + u32 insn; + + if (!i860_get_insn(regs, pc, &insn) || !i860_delayed_branch(insn)) + return true; + + if (psr & PSR_DS) { + u32 fp; + + /* DS would not survive that: rerun the branch's pair, KNF is then taken */ + if ((psr & PSR_KNF) && + (!i860_get_insn(regs, regs->user.fir, &fp) || + (fp & ~0x200u) != I860_INSN_FNOP)) + return false; + psr = (psr & PSR_DIM ? psr & ~PSR_DS : psr | PSR_DIM | PSR_DS) | PSR_KNF; + pc -= 4; + } else if (psr & PSR_DIM) { + psr = (psr & ~PSR_DIM) | PSR_DS; + } + + if (insn >> 26 == 0x2d) { /* bla */ + unsigned int src1 = (insn >> 11) & 31; + unsigned int src2 = (insn >> 21) & 31; + + if (src2) + regs->user.gpr[src2] -= reg(regs, src1); + } + regs->user.fir = pc; + regs->user.psr = psr; + return true; +} + +#define I860_INSN_TRAP 0x44000000 /* trap r0,r0,r0 */ +#define I860_INSN_BREAK 0x44010000 /* trap r0,r0,r1 */ +#define I860_LOCK_MAX 32 /* instructions inside lock/unlock */ + +/* + * A trap inside a lock/unlock sequence (EPSR.IL) broke the bus lock: + * resume at the lock instruction so that the sequence runs again as a + * whole, e.g. the load and store of a compare-and-swap. + */ +static bool i860_lock_restart(struct pt_regs *regs) +{ + unsigned long pc = regs->user.fir; + bool dim = regs->user.psr & PSR_DIM; + u32 insn; + int i; + + if (!(regs->user.epsr & EPSR_IL) || (regs->user.psr & PSR_DS)) + return false; + if (dim) + pc += 4; + /* the sequence, its lock and unlock and the access after the unlock */ + for (i = 0; i < I860_LOCK_MAX + 3; i++, pc -= 4) { + if (!i860_get_insn(regs, pc, &insn)) + break; + if (insn == I860_INSN_LOCK) { + if (dim) { + /* only the core half of its pair runs again */ + if (!(pc & 4)) + return false; + regs->user.psr = (regs->user.psr & ~(PSR_DIM | PSR_KNF)) | PSR_DS; + } + regs->user.fir = pc; + return true; + } + /* FP halves after it would run a second time */ + if (dim && !(pc & 4) && (insn & ~0x200u) != I860_INSN_FNOP) + return false; + } + return false; +} + +/* Past the trap in dual mode: fir, and the mode from the state and the D bit. */ +static void i860_syscall_dim(struct pt_regs *regs) +{ + unsigned long psr = regs->user.psr; + bool next = !(psr & PSR_DIM) != !(psr & PSR_DS); + bool ds = false; + u32 fp; + + if (psr & PSR_DIM) { + regs->user.fir += 4; + ds = i860_get_insn(regs, regs->orig_fir, &fp) && + !!(fp & 0x200) != next; + } + psr &= ~(PSR_DIM | PSR_DS); + regs->user.psr = psr | (next ? PSR_DIM : 0) | (ds ? PSR_DS : 0); +} + +/* Back to the trap of a restarted system call, whose FP half has run. */ +void i860_syscall_rewind(struct pt_regs *regs) +{ + unsigned long psr = regs->orig_psr; + + if (likely(!(psr & (PSR_DIM | PSR_DS)))) { + regs->user.fir -= 4; + return; + } + regs->user.fir = regs->orig_fir; + regs->user.psr = (regs->user.psr & ~(PSR_DIM | PSR_DS | PSR_KNF)) | + (psr & (PSR_DIM | PSR_DS)) | + (psr & PSR_DIM ? PSR_KNF : 0); +} + +static void i860_syscall(struct pt_regs *regs) +{ + long nr = regs->user.gpr[I860_SYSCALL_NR_REG]; + + regs->orig_psr = regs->user.psr; + regs->orig_fir = regs->user.fir; + regs->user.fir += 4; + if (unlikely(regs->user.psr & (PSR_DIM | PSR_DS))) + i860_syscall_dim(regs); + regs->orig_r16 = regs->user.gpr[16]; + regs->syscallno = nr; + /* A tracer sees the arguments at the entry stop, and can skip the call with number -1. */ + if (likely(syscall_enter_from_user_mode_randomize_stack(regs, &nr))) { + if (nr >= 0 && nr < NR_syscalls) { + syscall_fn_t fn; + + regs->orig_r16 = regs->user.gpr[16]; + fn = sys_call_table[array_index_nospec(nr, NR_syscalls)]; + regs->user.gpr[16] = fn(regs->orig_r16, regs->user.gpr[17], + regs->user.gpr[18], regs->user.gpr[19], + regs->user.gpr[20], regs->user.gpr[21]); + } else if (regs->user.gpr[16] == regs->orig_r16) { + /* no result set by a tracer */ + regs->user.gpr[16] = -ENOSYS; + } + } + syscall_exit_to_user_mode(regs); +} + +/* + * In dual mode: SIGILL for a misaligned pair or wrong formats. The core half's + * FP half is done: SVR4 sets KNF for intovr d042ec04, trap goes past it d042f28c. + * Returns false for a system call. + */ +static bool i860_trap_insn_dim(struct pt_regs *regs) +{ + unsigned long fir = regs->user.fir; + u32 fp = 0, core = 0, prev = 0; + int sig = SIGILL, code = ILL_ILLADR; + + if (!(fir & 7) && i860_get_insn(regs, fir, &fp) && + i860_get_insn(regs, fir + 4, &core)) { + code = ILL_ILLOPC; + if ((fp >> 26) == 0x12 || (fp >> 26) == 0x2c) { + if (core == I860_INSN_INTOVR) { + regs->user.psr |= PSR_KNF; + sig = SIGFPE; + code = FPE_INTOVF; + } else if ((core >> 26) == 0x11) { + if (core == I860_INSN_BREAK && current->ptrace) { + regs->user.psr |= PSR_KNF; + sig = SIGTRAP; + code = TRAP_BRKPT; + } else if (!i860_get_insn(regs, fir - 4, &prev) || + !i860_delayed_branch(prev)) { + return false; + } + } + } + } + irqentry_enter_from_user_mode(regs); + force_sig_fault(sig, code, (void __user *)fir); + irqentry_exit_to_user_mode(regs); + return true; +} + +static void i860_trap_insn(struct pt_regs *regs) +{ + u32 insn = 0; + + /* IT with EPSR.IL: a lock sequence ran past its 32 instructions */ + if (user_mode(regs) && (regs->user.epsr & EPSR_IL)) { + irqentry_enter_from_user_mode(regs); + force_sig_fault(SIGILL, ILL_ILLOPN, (void __user *)regs->user.fir); + irqentry_exit_to_user_mode(regs); + return; + } + if (user_mode(regs) && unlikely(regs->user.psr & PSR_DIM)) { + if (i860_trap_insn_dim(regs)) + return; + } else if (user_mode(regs) && unlikely(regs->user.epsr & EPSR_OF) && + i860_get_insn(regs, regs->user.fir, &insn) && insn == I860_INSN_INTOVR) { + /* also an instruction trap: not a system call */ + irqentry_enter_from_user_mode(regs); + regs->user.fir += 4; + force_sig_fault(SIGFPE, FPE_INTOVF, (void __user *)(regs->user.fir - 4)); + irqentry_exit_to_user_mode(regs); + return; + } else if (user_mode(regs) && unlikely(current->ptrace) && + /* only a traced process has breakpoints: others save the read of the insn */ + i860_get_insn(regs, regs->user.fir, &insn) && insn == I860_INSN_BREAK) { + irqentry_enter_from_user_mode(regs); + force_sig_fault(SIGTRAP, TRAP_BRKPT, (void __user *)regs->user.fir); + irqentry_exit_to_user_mode(regs); + return; + } + if (user_mode(regs)) { + i860_syscall(regs); + return; + } + i860_get_insn(regs, regs->user.fir, &insn); + die("kernel trap instruction", regs, insn); +} + +static void i860_access_trap(struct pt_regs *regs, bool fetch) +{ + irqentry_state_t state = irqentry_enter(regs); + unsigned long fault_pc = regs->user.fir; + unsigned long addr = fault_pc; + unsigned int size = 4; + bool write = false; + bool dim = regs->user.psr & PSR_DIM; + bool restart = i860_lock_restart(regs); + u32 insn; + + /* no lock to go back to: continuing would silently lose atomicity */ + if (user_mode(regs) && (regs->user.epsr & EPSR_IL) && !restart) { + force_sig_fault(SIGILL, ILL_ILLOPN, (void __user *)fault_pc); + goto out; + } + if (!fetch) { + /* in the core half; the FP half is done, as SVR4 d042ec08 */ + if (dim) { + fault_pc += 4; + if (!restart && !(regs->user.psr & (PSR_IT | PSR_IN | PSR_IAT | PSR_FT))) + regs->user.psr |= PSR_KNF; + } + if (!i860_get_insn(regs, fault_pc, &insn) || + !i860_decode_access(regs, insn, &addr, &size, &write)) { + if (user_mode(regs)) + force_sig_fault(SIGILL, ILL_ILLOPC, + (void __user *)regs->user.fir); + else + die("data access trap at unknown instruction", + regs, 0); + goto out; + } + /* before the access, which runs when the debugger resumes without the watchpoint */ + if (user_mode(regs) && (addr & ~(unsigned long)(size - 1)) == current->thread.db && + (regs->user.psr & (write ? PSR_BW : PSR_BR))) { + if (!restart) + i860_fixup_delay_slot(regs); + force_sig_fault(SIGTRAP, TRAP_HWBKPT, (void __user *)addr); + goto out; + } + if (addr & (size - 1)) { + if (user_mode(regs)) { + if (!restart) + i860_fixup_delay_slot(regs); + force_sig_fault(SIGBUS, BUS_ADRALN, + (void __user *)addr); + } else if (!fixup_exception(regs)) + die("unaligned kernel access", regs, addr); + goto out; + } + } + /* also for a fetch: the page of the slot may be the one that faulted */ + if (!restart && !i860_fixup_delay_slot(regs)) { + force_sig_fault(SIGILL, ILL_ILLOPN, (void __user *)fault_pc); + goto out; + } + i860_do_page_fault(regs, addr, write, fetch); +out: + local_irq_disable(); + irqentry_exit(regs, state); +} + +/* + * A source exception, or only a result exception that is already handled. A + * compare in the delay slot of bc.t or bnc.t would change the CC that the branch + * tests when rerun: it was taken, or the slot would not run, so go to its target. + */ +static void i860_fp_trap(struct pt_regs *regs) +{ + irqentry_state_t state = irqentry_enter(regs); + unsigned long fir = regs->user.fir; + u32 insn, prev = 0; + + if (!user_mode(regs)) { + die("kernel floating point trap", regs, regs->user.fsr); + } else if (!(regs->user.fsr & FSR_SE)) { + /* the result exception was handled on entry, the trap may be in a slot */ + i860_fixup_delay_slot(regs); + } else if (!i860_get_insn(regs, fir, &insn)) { + force_sig_fault(SIGFPE, FPE_FLTINV, (void __user *)fir); + } else if (insn >> 26 != 0x12) { + regs->user.fsr &= ~FSR_SE; /* stale */ + } else if (i860_fp_source(regs, insn)) { + force_sig_fault(SIGFPE, FPE_FLTINV, (void __user *)fir); + } else { + unsigned int op = insn & 0x7f; + + regs->user.fsr &= ~FSR_SE; + i860_get_insn(regs, fir - 4, &prev); + if ((op == 0x34 || op == 0x35) && + (prev >> 26 == 0x1d || prev >> 26 == 0x1f)) { + /* lbroff: 26 bits of words from after the branch */ + regs->user.fir = fir + (((s32)(prev << 6) >> 6) << 2); + } else { + regs->user.psr |= PSR_KNF; + i860_fixup_delay_slot(regs); + } + } + irqentry_exit(regs, state); +} + +unsigned long i860_irq_seq; + +static void i860_interrupt(struct pt_regs *regs) +{ + irqentry_state_t state = irqentry_enter(regs); + struct pt_regs *old_regs; + + WRITE_ONCE(i860_irq_seq, i860_irq_seq + 1); + + /* in case hardware interrupts on a slot; SVR4 fixes up after every user trap */ + pagefault_disable(); + i860_fixup_delay_slot(regs); + pagefault_enable(); + irq_enter_rcu(); + old_regs = set_irq_regs(regs); + handle_arch_irq(regs); + set_irq_regs(old_regs); + irq_exit_rcu(); + irqentry_exit(regs, state); +} + +/* + * Several trap bits can be set at once. The interrupt line is level + * triggered, so a pending IN re-traps after the other cause is handled. + */ +asmlinkage void i860_handle_trap(struct pt_regs *regs) +{ + unsigned long psr = regs->user.psr; + + regs->syscallno = -1; + /* a watchpoint is for user code: the frame keeps the bits for the return */ + if (psr & (PSR_BR | PSR_BW)) + i860_st_c(psr, i860_ld_c(psr) & ~(PSR_BR | PSR_BW)); + /* the saved epsr keeps IL for the handlers; clear the live bit */ + if (regs->user.epsr & EPSR_IL) + i860_st_c(epsr, i860_ld_c(epsr) & ~EPSR_IL); + + /* before any other cause: it stays pending and its status is popped */ + if (user_mode(regs) && i860_fp_result_pending(regs->user.fsr)) + i860_fp_result(regs); + + if (psr & PSR_IT) + i860_trap_insn(regs); + else if (psr & PSR_IAT) + i860_access_trap(regs, true); + else if (psr & PSR_DAT) + i860_access_trap(regs, false); + else if (psr & PSR_FT) + i860_fp_trap(regs); + else if (psr & PSR_IN) + i860_interrupt(regs); + else + die("trap without cause", regs, psr); +} + +extern char i860_trap_vector[], i860_trap_vector_end[]; + +void i860_set_kernel_stack(unsigned long top) +{ + *(volatile unsigned long *)(I860_TRAP_PAGE + PAGE_SIZE + SCR_KSP) = top; +} + +/* Called first thing in setup_arch, while the firmware MMU set-up is live. */ +void __init i860_trap_init(void) +{ + size_t len = i860_trap_vector_end - i860_trap_vector; + + BUG_ON(len > I860_TRAP_VECTOR_MAX); + i860_set_kernel_stack((unsigned long)task_stack_page(current) + + THREAD_SIZE); + memcpy((void *)I860_TRAP_VECTOR, i860_trap_vector, len); + flush_icache_range(I860_TRAP_VECTOR, I860_TRAP_VECTOR + len); +} + +void show_stack(struct task_struct *task, unsigned long *sp, + const char *loglvl) +{ + unsigned long fp, pc, stack; + int depth = 0; + + if (!task) + task = current; + stack = (unsigned long)task_stack_page(task); + if (task == current) + fp = (unsigned long)__builtin_frame_address(0); + else + fp = *(unsigned long *)(task->thread.ksp + 4); + + printk("%sCall trace:\n", loglvl); + while (depth++ < 32 && fp >= stack && fp < stack + THREAD_SIZE - 8 && + !(fp & 3)) { + pc = ((unsigned long *)fp)[1]; + printk("%s [<%08lx>] %pS\n", loglvl, pc, (void *)pc); + fp = ((unsigned long *)fp)[0]; + } +} diff --git a/arch/i860/kernel/vdso.c b/arch/i860/kernel/vdso.c new file mode 100644 index 000000000000..8a893135a923 --- /dev/null +++ b/arch/i860/kernel/vdso.c @@ -0,0 +1,113 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * vDSO. The 82380 counter needs a privileged write to latch it and there is no cycle + * counter, so only the coarse clocks work without a system call. + * + * The cache is virtually tagged and a kernel update must be visible to a running process + * at once, so both sides use the time page uncached. + * + * Copyright (C) 2026 René Rebe + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +extern char vdso_start[], vdso_end[]; + +static struct page *vdso_time_page __ro_after_init; + +static vm_fault_t i860_vvar_fault(const struct vm_special_mapping *sm, + struct vm_area_struct *vma, struct vm_fault *vmf) +{ + if (vmf->pgoff != VDSO_TIME_PAGE_OFFSET) + return VM_FAULT_SIGBUS; + return vmf_insert_pfn_prot(vma, vmf->address, page_to_pfn(vdso_time_page), + pgprot_noncached(vma->vm_page_prot)); +} + +static const struct vm_special_mapping i860_vvar_mapping = { + .name = "[vvar]", + .fault = i860_vvar_fault, +}; + +static int i860_vdso_mremap(const struct vm_special_mapping *sm, struct vm_area_struct *vma) +{ + current->mm->context.vdso = (void *)vma->vm_start; + return 0; +} + +static struct vm_special_mapping i860_vdso_mapping __ro_after_init = { + .name = "[vdso]", + .mremap = i860_vdso_mremap, +}; + +static int __init i860_vdso_init(void) +{ + unsigned int i, pages = (vdso_end - vdso_start) >> PAGE_SHIFT; + struct page **list = kcalloc(pages, sizeof(*list), GFP_KERNEL); + unsigned long flags; + void *alias; + + BUILD_BUG_ON(VDSO_NR_PAGES != __VDSO_PAGES); + + if (!list || memcmp(vdso_start, "\177ELF", 4)) + panic("vDSO setup failed\n"); + for (i = 0; i < pages; i++) + list[i] = virt_to_page(vdso_start + i * PAGE_SIZE); + i860_vdso_mapping.pages = list; + + vdso_time_page = virt_to_page(vdso_k_time_data); + alias = vmap(&vdso_time_page, 1, VM_MAP, PAGE_KERNEL_NOCACHE); + if (!alias) + panic("vDSO time page mapping failed\n"); + local_irq_save(flags); + i860_flush_dcache_all(); + vdso_k_time_data = alias; + local_irq_restore(flags); + return 0; +} +arch_initcall(i860_vdso_init); + +int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp) +{ + unsigned long text = vdso_end - vdso_start, data = __VDSO_PAGES * PAGE_SIZE, base; + struct mm_struct *mm = current->mm; + struct vm_area_struct *vma; + int ret = 0; + + if (mmap_write_lock_killable(mm)) + return -EINTR; + + base = get_unmapped_area(NULL, 0, data + text, 0, 0); + if (IS_ERR_VALUE(base)) { + ret = base; + goto out; + } + vma = _install_special_mapping(mm, base, data, + VM_READ | VM_MAYREAD | VM_IO | VM_DONTDUMP | + VM_PFNMAP | VM_SEALED_SYSMAP, &i860_vvar_mapping); + if (IS_ERR(vma)) { + ret = PTR_ERR(vma); + goto out; + } + vma = _install_special_mapping(mm, base + data, text, + VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC | + VM_SEALED_SYSMAP, &i860_vdso_mapping); + if (IS_ERR(vma)) { + ret = PTR_ERR(vma); + goto out; + } + mm->context.vdso = (void *)(base + data); +out: + mmap_write_unlock(mm); + return ret; +} diff --git a/arch/i860/kernel/vdso/Makefile b/arch/i860/kernel/vdso/Makefile new file mode 100644 index 000000000000..f3219631e739 --- /dev/null +++ b/arch/i860/kernel/vdso/Makefile @@ -0,0 +1,35 @@ +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2026 René Rebe +include $(srctree)/lib/vdso/Makefile.include + +obj-vdso := vgettimeofday.o sigreturn.o +vdso-syms := clock_gettime clock_getres rt_sigreturn + +targets := $(obj-vdso) vdso.so vdso.so.dbg vdso.lds +obj-vdso := $(addprefix $(obj)/, $(obj-vdso)) +obj-y += vdso.o + +ccflags-y := -fno-stack-protector -fno-builtin -DDISABLE_BRANCH_PROFILING \ + -fno-asynchronous-unwind-tables -fno-exceptions +CFLAGS_vgettimeofday.o += -fPIC -include $(c-gettimeofday-y) +CPPFLAGS_vdso.lds += -P -C -U$(ARCH) + +$(obj)/vdso.o: $(obj)/vdso.so + +LDFLAGS_vdso.so.dbg = -shared -soname=linux-vdso.so.1 --hash-style=both --build-id=sha1 + +$(obj)/vdso.so.dbg: $(obj)/vdso.lds $(obj-vdso) FORCE + $(call if_changed,vdsold_and_check) + +OBJCOPYFLAGS_vdso.so := -S +$(obj)/vdso.so: $(obj)/vdso.so.dbg FORCE + $(call if_changed,objcopy) + +quiet_cmd_vdsosym = VDSOSYM $@ + cmd_vdsosym = $(NM) $< | sh $(src)/gen_vdso_offsets.sh | LC_ALL=C sort > $@ + +include/generated/vdso-offsets.h: $(obj)/vdso.so.dbg FORCE + $(call if_changed,vdsosym) + +quiet_cmd_vdsold_and_check = VDSOLD $@ + cmd_vdsold_and_check = $(LD) $(ld_flags) -T $(filter-out FORCE,$^) -o $@ && $(cmd_vdso_check) diff --git a/arch/i860/kernel/vdso/gen_vdso_offsets.sh b/arch/i860/kernel/vdso/gen_vdso_offsets.sh new file mode 100755 index 000000000000..62668978625f --- /dev/null +++ b/arch/i860/kernel/vdso/gen_vdso_offsets.sh @@ -0,0 +1,5 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2026 René Rebe +LC_ALL=C +sed -n -e 's/^[0]*\([0-9a-fA-F]\{1,\}\) . \(__vdso_[a-zA-Z0-9_]*\)$/#define \2_offset\t0x\1/p' diff --git a/arch/i860/kernel/vdso/sigreturn.S b/arch/i860/kernel/vdso/sigreturn.S new file mode 100644 index 000000000000..4e6b86b89cc5 --- /dev/null +++ b/arch/i860/kernel/vdso/sigreturn.S @@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (C) 2026 René Rebe */ +#include +#include + + .text +ENTRY(__vdso_rt_sigreturn) + or __NR_rt_sigreturn,%r0,%r28 + trap %r0,%r0,%r0 + nop diff --git a/arch/i860/kernel/vdso/vdso.S b/arch/i860/kernel/vdso/vdso.S new file mode 100644 index 000000000000..b787d741a5cf --- /dev/null +++ b/arch/i860/kernel/vdso/vdso.S @@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (C) 2026 René Rebe */ +#include +#include +#include + + __PAGE_ALIGNED_DATA + + .globl vdso_start, vdso_end + .balign PAGE_SIZE +vdso_start: + .incbin "arch/i860/kernel/vdso/vdso.so" + .balign PAGE_SIZE +vdso_end: + + .previous diff --git a/arch/i860/kernel/vdso/vdso.lds.S b/arch/i860/kernel/vdso/vdso.lds.S new file mode 100644 index 000000000000..e7bafa23fff7 --- /dev/null +++ b/arch/i860/kernel/vdso/vdso.lds.S @@ -0,0 +1,50 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (C) 2026 René Rebe */ +#include +#include +#include + +OUTPUT_ARCH(i860) + +SECTIONS +{ + VDSO_VVAR_SYMS + + . = SIZEOF_HEADERS; + + .hash : { *(.hash) } :text + .gnu.hash : { *(.gnu.hash) } + .dynsym : { *(.dynsym) } + .dynstr : { *(.dynstr) } + .gnu.version : { *(.gnu.version) } + .gnu.version_d : { *(.gnu.version_d) } + .gnu.version_r : { *(.gnu.version_r) } + .dynamic : { *(.dynamic) } :text :dynamic + .rodata : { + *(.rodata .rodata.*) + *(.got) + *(.data .data.*) + *(.dynbss) + *(.bss .bss.*) + } :text + . = ALIGN(16); + .text : { *(.text .text.*) } :text + /DISCARD/ : { *(.eh_frame) *(.note.*) *(.comment) } +} + +PHDRS +{ + text PT_LOAD FLAGS(5) FILEHDR PHDRS; + dynamic PT_DYNAMIC FLAGS(4); +} + +VERSION +{ + LINUX_2.6 { + global: + __vdso_clock_gettime; + __vdso_clock_getres; + __vdso_rt_sigreturn; + local: *; + }; +} diff --git a/arch/i860/kernel/vdso/vgettimeofday.c b/arch/i860/kernel/vdso/vgettimeofday.c new file mode 100644 index 000000000000..ea7bd1181674 --- /dev/null +++ b/arch/i860/kernel/vdso/vgettimeofday.c @@ -0,0 +1,17 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (C) 2026 René Rebe */ +#include +#include + +int __vdso_clock_gettime(clockid_t clock, struct __kernel_timespec *ts); +int __vdso_clock_getres(clockid_t clock, struct __kernel_timespec *res); + +int __vdso_clock_gettime(clockid_t clock, struct __kernel_timespec *ts) +{ + return __cvdso_clock_gettime(clock, ts); +} + +int __vdso_clock_getres(clockid_t clock, struct __kernel_timespec *res) +{ + return __cvdso_clock_getres(clock, res); +} diff --git a/arch/i860/kernel/vmlinux.lds.S b/arch/i860/kernel/vmlinux.lds.S new file mode 100644 index 000000000000..e58612e65ce9 --- /dev/null +++ b/arch/i860/kernel/vmlinux.lds.S @@ -0,0 +1,58 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (C) 2026 René Rebe */ + +#include +#include +#include +#include +#include + +OUTPUT_FORMAT("elf32-i860-little", "elf32-i860", "elf32-i860-little") +OUTPUT_ARCH(i860) +ENTRY(_start) + +jiffies = jiffies_64; + +SECTIONS +{ + . = CONFIG_I860_KERNEL_BASE; + + _text = .; + _stext = .; + HEAD_TEXT_SECTION + .text : { + TEXT_TEXT + SCHED_TEXT + LOCK_TEXT + IRQENTRY_TEXT + SOFTIRQENTRY_TEXT + KPROBES_TEXT + *(.fixup) + } =0 + _etext = .; + + EXCEPTION_TABLE(L1_CACHE_BYTES) + + . = ALIGN(PAGE_SIZE); + __init_begin = .; + INIT_TEXT_SECTION(PAGE_SIZE) + INIT_DATA_SECTION(PAGE_SIZE) + PERCPU_SECTION(L1_CACHE_BYTES) + __init_end = .; + + _sdata = .; + RO_DATA(PAGE_SIZE) + RW_DATA(L1_CACHE_BYTES, PAGE_SIZE, THREAD_SIZE) + _edata = .; + + BSS_SECTION(0, PAGE_SIZE, 4) + _end = .; + ASSERT(_end <= I860_FW_START - I860_EARLY_ALLOC, "the image leaves no room below the firmware area") + + STABS_DEBUG + DWARF_DEBUG + MODINFO + ELF_DETAILS + + DISCARDS +} diff --git a/arch/i860/lib/Makefile b/arch/i860/lib/Makefile new file mode 100644 index 000000000000..8b5d06907f39 --- /dev/null +++ b/arch/i860/lib/Makefile @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Copyright (C) 2026 René Rebe +# + +lib-y := usercopy.o delay.o memcpy.o memset.o diff --git a/arch/i860/lib/delay.c b/arch/i860/lib/delay.c new file mode 100644 index 000000000000..71185657dc64 --- /dev/null +++ b/arch/i860/lib/delay.c @@ -0,0 +1,35 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (C) 2026 René Rebe */ + +#include +#include +#include +#include + +void __delay(unsigned long loops) +{ + if (!loops) + return; + asm volatile("1:\tadds -1,%0,%0\n\tbtne 0,%0,1b" : "+r" (loops)); +} +EXPORT_SYMBOL(__delay); + +void __const_udelay(unsigned long xloops) +{ + u64 loops = (u64)xloops * loops_per_jiffy * HZ; + + __delay(loops >> 32); +} +EXPORT_SYMBOL(__const_udelay); + +void __udelay(unsigned long usecs) +{ + __const_udelay(usecs * 0x10c7UL); +} +EXPORT_SYMBOL(__udelay); + +void __ndelay(unsigned long nsecs) +{ + __const_udelay(nsecs * 5UL); +} +EXPORT_SYMBOL(__ndelay); diff --git a/arch/i860/lib/memcpy.S b/arch/i860/lib/memcpy.S new file mode 100644 index 000000000000..d1b25cd38877 --- /dev/null +++ b/arch/i860/lib/memcpy.S @@ -0,0 +1,309 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * memcpy/memmove with 128-bit fld.q/fst.q transfers. + * + * Mutually 16-byte aligned buffers move in 64-byte blocks of four quad + * loads and stores, 8 or 4-byte aligned ones in 32-byte blocks of doublewords + * or words, and the others word wise with shifts. Only the caller-saved FP + * registers f8-f23 are used. No auto-increment + * addressing: every access can fault and be re-executed (vmalloc PDE + * sync). + * + * Copyright (C) 2026 René Rebe + */ + +#include + + .text + +/* void *memcpy(void *dst = r16, const void *src = r17, size_t n = r18) */ +ENTRY(memcpy) + mov %r16,%r19 /* r19 = d, r16 is returned */ +.Lfwd: + xor %r19,%r17,%r20 + subu 15,%r18,%r0 /* CC = n < 16 */ + bc .Lfsmall + and 15,%r20,%r0 /* CC = d, s equally aligned mod 16 */ + bnc .Lf8 + + /* bytes up to a 16-byte boundary */ +.Lfhead16: + and 15,%r19,%r0 + bc .Lfq + ld.b 0(%r17),%r20 + st.b %r20,0(%r19) + addu 1,%r17,%r17 + addu 1,%r19,%r19 + br .Lfhead16 + adds -1,%r18,%r18 + +.Lfq: + subu 63,%r18,%r0 /* CC = n < 64 */ + bc .Lfq16 +.Lfq64: + fld.q 0(%r17),%f8 + fld.q 16(%r17),%f12 + fld.q 32(%r17),%f16 + fld.q 48(%r17),%f20 + fst.q %f8,0(%r19) + fst.q %f12,16(%r19) + fst.q %f16,32(%r19) + fst.q %f20,48(%r19) + addu 64,%r17,%r17 + addu 64,%r19,%r19 + adds -64,%r18,%r18 + subu 63,%r18,%r0 + bnc .Lfq64 +.Lfq16: + subu 15,%r18,%r0 + bc .Lfbytes + fld.q 0(%r17),%f8 + fst.q %f8,0(%r19) + addu 16,%r17,%r17 + addu 16,%r19,%r19 + br .Lfq16 + adds -16,%r18,%r18 + + /* doublewords */ +.Lf8: + and 7,%r20,%r0 /* CC = equally aligned mod 8 */ + bnc .Lf4 +.Lfhead8: + and 7,%r19,%r0 + bc .Lfd32 + ld.b 0(%r17),%r20 + st.b %r20,0(%r19) + addu 1,%r17,%r17 + addu 1,%r19,%r19 + br .Lfhead8 + adds -1,%r18,%r18 +.Lfd32: + subu 31,%r18,%r0 /* CC = n < 32 */ + bc .Lfd + fld.d 0(%r17),%f8 + fld.d 8(%r17),%f10 + fld.d 16(%r17),%f12 + fld.d 24(%r17),%f14 + fst.d %f8,0(%r19) + fst.d %f10,8(%r19) + fst.d %f12,16(%r19) + fst.d %f14,24(%r19) + addu 32,%r17,%r17 + addu 32,%r19,%r19 + br .Lfd32 + adds -32,%r18,%r18 +.Lfd: + subu 7,%r18,%r0 /* CC = n < 8 */ + bc .Lfbytes + fld.d 0(%r17),%f8 + fst.d %f8,0(%r19) + addu 8,%r17,%r17 + addu 8,%r19,%r19 + br .Lfd + adds -8,%r18,%r18 + + /* words */ +.Lfsmall: + subu 3,%r18,%r0 /* CC = n < 4 */ + bc .Lfbytes +.Lf4: + and 3,%r20,%r0 /* CC = equally aligned mod 4 */ + bnc .Lfmerge +.Lfhead4: + and 3,%r19,%r0 + bc .Lfw32 + ld.b 0(%r17),%r20 + st.b %r20,0(%r19) + addu 1,%r17,%r17 + addu 1,%r19,%r19 + br .Lfhead4 + adds -1,%r18,%r18 +.Lfw32: + subu 31,%r18,%r0 /* CC = n < 32 */ + bc .Lfw + ld.l 0(%r17),%r20 + ld.l 4(%r17),%r21 + ld.l 8(%r17),%r22 + ld.l 12(%r17),%r23 + ld.l 16(%r17),%r24 + ld.l 20(%r17),%r25 + ld.l 24(%r17),%r26 + ld.l 28(%r17),%r27 + st.l %r20,0(%r19) + st.l %r21,4(%r19) + st.l %r22,8(%r19) + st.l %r23,12(%r19) + st.l %r24,16(%r19) + st.l %r25,20(%r19) + st.l %r26,24(%r19) + st.l %r27,28(%r19) + addu 32,%r17,%r17 + addu 32,%r19,%r19 + br .Lfw32 + adds -32,%r18,%r18 +.Lfw: + subu 3,%r18,%r0 /* CC = n < 4 */ + bc .Lfbytes + ld.l 0(%r17),%r20 + st.l %r20,0(%r19) + addu 4,%r17,%r17 + addu 4,%r19,%r19 + br .Lfw + adds -4,%r18,%r18 + + /* + * Different alignment mod 4: aligned words of the source, shifted into + * place. Only words holding bytes to copy are read, so no fault past + * the end of the source. + */ +.Lfmerge: + subu 15,%r18,%r0 /* CC = n < 16 */ + bc .Lfbytes +.Lfmhead: + and 3,%r19,%r0 + bc .Lfmgo + ld.b 0(%r17),%r20 + st.b %r20,0(%r19) + addu 1,%r17,%r17 + addu 1,%r19,%r19 + br .Lfmhead + adds -1,%r18,%r18 +.Lfmgo: + and 3,%r17,%r21 + shl 3,%r21,%r21 /* bits to shift right */ + or 32,%r0,%r22 + subu %r22,%r21,%r22 /* bits to shift left */ + andnot 3,%r17,%r17 + ld.l 0(%r17),%r20 +.Lfm16: + subu 15,%r18,%r0 /* CC = n < 16 */ + bc .Lfmend + ld.l 4(%r17),%r23 + ld.l 8(%r17),%r24 + ld.l 12(%r17),%r25 + ld.l 16(%r17),%r26 + shr %r21,%r20,%r20 + shl %r22,%r23,%r27 + or %r27,%r20,%r20 + st.l %r20,0(%r19) + shr %r21,%r23,%r23 + shl %r22,%r24,%r27 + or %r27,%r23,%r23 + st.l %r23,4(%r19) + shr %r21,%r24,%r24 + shl %r22,%r25,%r27 + or %r27,%r24,%r24 + st.l %r24,8(%r19) + shr %r21,%r25,%r25 + shl %r22,%r26,%r27 + or %r27,%r25,%r25 + st.l %r25,12(%r19) + mov %r26,%r20 + addu 16,%r17,%r17 + addu 16,%r19,%r19 + br .Lfm16 + adds -16,%r18,%r18 +.Lfmend: + shr 3,%r21,%r21 + addu %r21,%r17,%r17 /* back to the next byte to copy */ + +.Lfbytes: + bte 0,%r18,.Ldone +1: ld.b 0(%r17),%r20 + st.b %r20,0(%r19) + addu 1,%r17,%r17 + addu 1,%r19,%r19 + adds -1,%r18,%r18 + btne 0,%r18,1b +.Ldone: + bri %r1 + nop +ENDPROC(memcpy) + +/* void *memmove(void *dst = r16, const void *src = r17, size_t n = r18) */ +ENTRY(memmove) + mov %r16,%r19 + subu %r17,%r16,%r0 /* CC = d <= s: forward copy is safe */ + bc .Lfwd + addu %r18,%r17,%r21 /* s + n */ + subu %r16,%r21,%r0 /* CC = s + n <= d: no overlap */ + bc .Lfwd + + /* overlapping with d > s: copy backwards from the end */ + addu %r18,%r16,%r19 /* r19 = d end, r17 = s end */ + mov %r21,%r17 + subu 15,%r18,%r0 + bc .Lbbytes + xor %r19,%r17,%r20 + and 15,%r20,%r0 + bnc .Lb4 + +.Lbhead16: + and 15,%r19,%r0 + bc .Lbq + ld.b -1(%r17),%r20 + st.b %r20,-1(%r19) + adds -1,%r17,%r17 + adds -1,%r19,%r19 + br .Lbhead16 + adds -1,%r18,%r18 +.Lbq: + subu 63,%r18,%r0 + bc .Lbq16 +.Lbq64: + fld.q -16(%r17),%f8 + fld.q -32(%r17),%f12 + fld.q -48(%r17),%f16 + fld.q -64(%r17),%f20 + fst.q %f8,-16(%r19) + fst.q %f12,-32(%r19) + fst.q %f16,-48(%r19) + fst.q %f20,-64(%r19) + adds -64,%r17,%r17 + adds -64,%r19,%r19 + adds -64,%r18,%r18 + subu 63,%r18,%r0 + bnc .Lbq64 +.Lbq16: + subu 15,%r18,%r0 + bc .Lbbytes + fld.q -16(%r17),%f8 + fst.q %f8,-16(%r19) + adds -16,%r17,%r17 + adds -16,%r19,%r19 + br .Lbq16 + adds -16,%r18,%r18 + +.Lb4: + and 3,%r20,%r0 + bnc .Lbbytes +.Lbhead4: + and 3,%r19,%r0 + bc .Lbw + ld.b -1(%r17),%r20 + st.b %r20,-1(%r19) + adds -1,%r17,%r17 + adds -1,%r19,%r19 + br .Lbhead4 + adds -1,%r18,%r18 +.Lbw: + subu 3,%r18,%r0 + bc .Lbbytes + ld.l -4(%r17),%r20 + st.l %r20,-4(%r19) + adds -4,%r17,%r17 + adds -4,%r19,%r19 + br .Lbw + adds -4,%r18,%r18 + +.Lbbytes: + bte 0,%r18,2f +1: ld.b -1(%r17),%r20 + st.b %r20,-1(%r19) + adds -1,%r17,%r17 + adds -1,%r19,%r19 + adds -1,%r18,%r18 + btne 0,%r18,1b +2: bri %r1 + nop +ENDPROC(memmove) diff --git a/arch/i860/lib/memset.S b/arch/i860/lib/memset.S new file mode 100644 index 000000000000..f65bae255cd1 --- /dev/null +++ b/arch/i860/lib/memset.S @@ -0,0 +1,74 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * memset with 128-bit fst.q stores of a pattern held in f8-f11. + * No auto-increment addressing, so every store can fault and be + * re-executed. + * + * Copyright (C) 2026 René Rebe + */ + +#include + + .text + +/* void *memset(void *s = r16, int c = r17, size_t n = r18) */ +ENTRY(memset) + mov %r16,%r19 /* r19 = cursor, r16 is returned */ + and 0xff,%r17,%r17 + shl 8,%r17,%r20 + or %r20,%r17,%r17 + shl 16,%r17,%r20 + or %r20,%r17,%r17 /* byte replicated into a word */ + subu 15,%r18,%r0 /* CC = n < 16 */ + bc .Lbytes + +.Lhead: + and 15,%r19,%r0 + bc .Lq + st.b %r17,0(%r19) + addu 1,%r19,%r19 + br .Lhead + adds -1,%r18,%r18 + +.Lq: + ixfr %r17,%f8 + ixfr %r17,%f9 + ixfr %r17,%f10 + ixfr %r17,%f11 + subu 63,%r18,%r0 /* CC = n < 64 */ + bc .Lq16 +.Lq64: + fst.q %f8,0(%r19) + fst.q %f8,16(%r19) + fst.q %f8,32(%r19) + fst.q %f8,48(%r19) + addu 64,%r19,%r19 + adds -64,%r18,%r18 + subu 63,%r18,%r0 + bnc .Lq64 +.Lq16: + subu 15,%r18,%r0 + bc .Lwords + fst.q %f8,0(%r19) + addu 16,%r19,%r19 + br .Lq16 + adds -16,%r18,%r18 + + /* the cursor is 16-byte aligned here */ +.Lwords: + subu 3,%r18,%r0 /* CC = n < 4 */ + bc .Lbytes + st.l %r17,0(%r19) + addu 4,%r19,%r19 + br .Lwords + adds -4,%r18,%r18 + +.Lbytes: + bte 0,%r18,2f +1: st.b %r17,0(%r19) + addu 1,%r19,%r19 + adds -1,%r18,%r18 + btne 0,%r18,1b +2: bri %r1 + nop +ENDPROC(memset) diff --git a/arch/i860/lib/usercopy.S b/arch/i860/lib/usercopy.S new file mode 100644 index 000000000000..a2fcdba3c6e2 --- /dev/null +++ b/arch/i860/lib/usercopy.S @@ -0,0 +1,124 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * User copies; every access that can fault has an __ex_table entry that + * returns the number of bytes not copied (at most one 16-byte block more + * than the exact count). Mutually 16-byte aligned buffers move with + * fld.q/fst.q. No auto-increment addressing: a resolved fault re-executes + * the access. + * + * Copyright (C) 2026 René Rebe + */ + +#include + +#define EX(insn, fixup) \ + .section __ex_table,"a"; \ + .long insn, fixup; \ + .previous + + .text + +/* unsigned long __copy_user(void *to = r16, const void *from = r17, n = r18) */ +ENTRY(__copy_user) + mov %r16,%r19 + subu 15,%r18,%r0 /* CC = n < 16 */ + bc .Lbytes + xor %r19,%r17,%r20 + and 15,%r20,%r0 /* CC = equally aligned mod 16 */ + bnc .Lw4 + +.Lhead16: + and 15,%r19,%r0 + bc .Lq +1: ld.b 0(%r17),%r20 +2: st.b %r20,0(%r19) + addu 1,%r17,%r17 + addu 1,%r19,%r19 + br .Lhead16 + adds -1,%r18,%r18 +.Lq: + subu 15,%r18,%r0 + bc .Lbytes +3: fld.q 0(%r17),%f8 +4: fst.q %f8,0(%r19) + addu 16,%r17,%r17 + addu 16,%r19,%r19 + br .Lq + adds -16,%r18,%r18 + +.Lw4: + and 3,%r20,%r0 /* CC = equally aligned mod 4 */ + bnc .Lbytes +.Lhead4: + and 3,%r19,%r0 + bc .Lw +5: ld.b 0(%r17),%r20 +6: st.b %r20,0(%r19) + addu 1,%r17,%r17 + addu 1,%r19,%r19 + br .Lhead4 + adds -1,%r18,%r18 +.Lw: + subu 3,%r18,%r0 + bc .Lbytes +7: ld.l 0(%r17),%r20 +8: st.l %r20,0(%r19) + addu 4,%r17,%r17 + addu 4,%r19,%r19 + br .Lw + adds -4,%r18,%r18 + +.Lbytes: + bte 0,%r18,.Ldone +9: ld.b 0(%r17),%r20 +10: st.b %r20,0(%r19) + addu 1,%r17,%r17 + addu 1,%r19,%r19 + adds -1,%r18,%r18 + btne 0,%r18,9b +.Ldone: + bri %r1 + mov %r18,%r16 + + EX(1b, .Ldone) + EX(2b, .Ldone) + EX(3b, .Ldone) + EX(4b, .Ldone) + EX(5b, .Ldone) + EX(6b, .Ldone) + EX(7b, .Ldone) + EX(8b, .Ldone) + EX(9b, .Ldone) + EX(10b, .Ldone) + +/* unsigned long __clear_user_asm(void *to = r16, unsigned long n = r17) */ +ENTRY(__clear_user_asm) + subu 7,%r17,%r0 /* CC = n < 8 */ + bc .Lcbytes +.Lchead: + and 7,%r16,%r0 + bc .Lcd +11: st.b %r0,0(%r16) + addu 1,%r16,%r16 + br .Lchead + adds -1,%r17,%r17 +.Lcd: + subu 7,%r17,%r0 + bc .Lcbytes +12: fst.d %f0,0(%r16) /* f0/f1 read as zero */ + addu 8,%r16,%r16 + br .Lcd + adds -8,%r17,%r17 +.Lcbytes: + bte 0,%r17,.Lcdone +13: st.b %r0,0(%r16) + addu 1,%r16,%r16 + adds -1,%r17,%r17 + btne 0,%r17,13b +.Lcdone: + bri %r1 + mov %r17,%r16 + + EX(11b, .Lcdone) + EX(12b, .Lcdone) + EX(13b, .Lcdone) diff --git a/arch/i860/mm/Makefile b/arch/i860/mm/Makefile new file mode 100644 index 000000000000..a30dd829afca --- /dev/null +++ b/arch/i860/mm/Makefile @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Copyright (C) 2026 René Rebe +# + +obj-y := init.o fault.o cache.o cacheflush.o extable.o diff --git a/arch/i860/mm/cache.S b/arch/i860/mm/cache.S new file mode 100644 index 000000000000..2bb393ef198a --- /dev/null +++ b/arch/i860/mm/cache.S @@ -0,0 +1,90 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * i860 TLB, instruction and data cache control. + * Copyright (C) 2026 René Rebe + */ + +#include +#include + + .text + +/* void i860_set_pgd(pgd_t *pgd): new page directory, TLB invalidated */ +ENTRY(i860_set_pgd) + orh [i860_current_pgd]@ha,%r0,%r31 + st.l %r16,[i860_current_pgd]@l(%r31) + ld.c %dirbase,%r17 + and 0x00df,%r17,%r17 /* keep DPS/BL/LB, drop DTB, ITI, RB, RC */ + or %r16,%r17,%r17 + or DIRBASE_ITI | DIRBASE_ATE,%r17,%r17 + st.c %r17,%dirbase + nop + nop + nop + nop + nop + nop + bri %r1 + nop + +/* Invalidate the TLB and the instruction cache. */ +ENTRY(local_flush_tlb_all) + ld.c %psr,%r16 + andnot PSR_IM,%r16,%r17 + st.c %r17,%psr + ld.c %dirbase,%r17 + or DIRBASE_ITI,%r17,%r17 + st.c %r17,%dirbase + nop + nop + nop + nop + nop + nop + st.c %r16,%psr + bri %r1 + nop + +/* + * Write back and invalidate the whole data cache: for each way (RB) flush + * the 128 lines with dirbase.RC = 2, after the Intel reference routine. + * The ixfr before each flush is the firmware's workaround for the XR. + * The XR has 2 ways, the XP 4. + */ +ENTRY(i860_flush_dcache_all) + mov %r1,%r28 + ld.c %psr,%r29 + andnot PSR_IM,%r29,%r30 + st.c %r30,%psr + ld.c %epsr,%r27 + and EPSR_TYPE,%r27,%r27 + or 2,%r0,%r26 + xor EPSR_TYPE_XP,%r27,%r0 + bnc 1f + or 4,%r0,%r26 +1: ld.c %dirbase,%r25 + andnot DIRBASE_RB | DIRBASE_RC | DIRBASE_ITI,%r25,%r25 + mov %r0,%r24 +2: or DIRBASE_RC_FLUSH,%r25,%r23 + or %r24,%r23,%r23 + st.c %r23,%dirbase + orh [_stext]@h,%r0,%r21 + or [_stext]@l,%r21,%r21 + adds -32,%r21,%r21 + or 127,%r0,%r20 + adds -1,%r0,%r19 + ld.l 32(%r21),%r31 + shl 0,%r31,%r31 + bla %r19,%r20,3f + nop +3: ixfr %r0,%f0 + bla %r19,%r20,3b + flush 32(%r21)++ + ld.l -512(%r21),%r0 + addu 0x100,%r24,%r24 + adds -1,%r26,%r26 + btne %r0,%r26,2b + st.c %r25,%dirbase + st.c %r29,%psr + bri %r28 + nop diff --git a/arch/i860/mm/cacheflush.c b/arch/i860/mm/cacheflush.c new file mode 100644 index 000000000000..5588d4b25001 --- /dev/null +++ b/arch/i860/mm/cacheflush.c @@ -0,0 +1,65 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Fewer data cache flushes and dirbase.ITI. The kernel writes pages through + * the linear map, and the virtual tags hide those lines from a user mapping. + * PG_arch_1 set: the page has no such lines. So a page written while nobody + * has it mapped, like file data read from disk, is flushed when it gets mapped. + * + * Copyright (C) 2026 René Rebe + */ + +#include +#include +#include +#include +#include + +#define PG_dcache_clean PG_arch_1 + +void flush_dcache_folio(struct folio *folio) +{ + if (folio_flush_mapping(folio) && !folio_mapped(folio)) { + clear_bit(PG_dcache_clean, &folio->flags.f); + return; + } + i860_flush_dcache_all(); +} + +void flush_dcache_page(struct page *page) +{ + flush_dcache_folio(page_folio(page)); +} + +/* + * For code written at run time, such as GCC's trampolines on the stack: user + * mode cannot reach dirbase. The range is only checked: the hardware can only + * flush the whole cache. + */ +SYSCALL_DEFINE3(cacheflush, unsigned long, addr, unsigned long, len, int, op) +{ + if (op) + return -EINVAL; + if (!access_ok((void __user *)addr, len)) + return -EFAULT; + i860_flush_icache_all(); + return 0; +} + +void update_mmu_cache_range(struct vm_fault *vmf, struct vm_area_struct *vma, + unsigned long addr, pte_t *ptep, unsigned int nr) +{ + pte_t pte = ptep_get(ptep); + unsigned long pfn = pte_pfn(pte); + + if (pfn_valid(pfn) && + !test_and_set_bit(PG_dcache_clean, &page_folio(pfn_to_page(pfn))->flags.f)) + i860_flush_dcache_all(); + + /* + * Faults are not cached in the TLB, and instructions of an earlier + * mapping went with the ITI when it was unmapped. So only a change + * of a present entry needs one. + */ + if (!vmf || pte_present(vmf->orig_pte)) + local_flush_tlb_all(); +} diff --git a/arch/i860/mm/extable.c b/arch/i860/mm/extable.c new file mode 100644 index 000000000000..89e326af2ec6 --- /dev/null +++ b/arch/i860/mm/extable.c @@ -0,0 +1,17 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (C) 2026 René Rebe */ + +#include +#include +#include + +int fixup_exception(struct pt_regs *regs) +{ + const struct exception_table_entry *e; + + e = search_exception_tables(regs->user.fir); + if (!e) + return 0; + regs->user.fir = e->fixup; + return 1; +} diff --git a/arch/i860/mm/fault.c b/arch/i860/mm/fault.c new file mode 100644 index 000000000000..5d904a5bf7ab --- /dev/null +++ b/arch/i860/mm/fault.c @@ -0,0 +1,133 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (C) 2026 René Rebe */ + +#include +#include +#include +#include +#include +#include +#include + +extern pgd_t *i860_current_pgd; + +/* Kernel PDEs added after a pgd was copied (vmalloc) are synced lazily. */ +static bool i860_vmalloc_fault(unsigned long addr) +{ + unsigned int idx = pgd_index(addr); + pgd_t *pgd = i860_current_pgd + idx; + pgd_t *pgd_k = swapper_pg_dir + idx; + + if (!pgd_val(*pgd_k) || pgd_val(*pgd)) + return false; + *pgd = *pgd_k; + local_flush_tlb_all(); + return true; +} + +static void i860_kernel_fault(struct pt_regs *regs, unsigned long addr) +{ + if (fixup_exception(regs)) + return; + pr_alert("Unable to handle kernel %s at virtual address %08lx\n", + addr < PAGE_SIZE ? "NULL pointer dereference" : "paging request", + addr); + die("Oops", regs, 0); +} + +void i860_do_page_fault(struct pt_regs *regs, unsigned long addr, + bool write, bool fetch) +{ + struct mm_struct *mm = current->mm; + struct vm_area_struct *vma; + unsigned int flags = FAULT_FLAG_DEFAULT; + vm_fault_t fault; + int code = SEGV_MAPERR; + + if (!user_mode(regs) && addr >= VMALLOC_START && addr < VMALLOC_END) { + if (!i860_vmalloc_fault(addr)) + i860_kernel_fault(regs, addr); + return; + } + + if (!regs_irqs_disabled(regs)) + local_irq_enable(); + + if (faulthandler_disabled() || !mm) { + if (!user_mode(regs)) + i860_kernel_fault(regs, addr); + else + force_sig_fault(SIGSEGV, code, (void __user *)addr); + return; + } + + if (user_mode(regs)) + flags |= FAULT_FLAG_USER; + if (write) + flags |= FAULT_FLAG_WRITE; + if (fetch) + flags |= FAULT_FLAG_INSTRUCTION; + + perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, addr); + +retry: + vma = lock_mm_and_find_vma(mm, addr, regs); + if (unlikely(!vma)) + goto bad_area_nosemaphore; + + code = SEGV_ACCERR; + if (write) { + if (!(vma->vm_flags & VM_WRITE)) + goto bad_area; + } else if (!(vma->vm_flags & (VM_READ | VM_EXEC | VM_WRITE))) { + goto bad_area; + } + + fault = handle_mm_fault(vma, addr, flags, regs); + + if (fault_signal_pending(fault, regs)) { + if (!user_mode(regs)) + i860_kernel_fault(regs, addr); + return; + } + + if (fault & VM_FAULT_COMPLETED) + return; + + if (unlikely(fault & VM_FAULT_ERROR)) { + mmap_read_unlock(mm); + if (fault & VM_FAULT_OOM) { + if (!user_mode(regs)) + i860_kernel_fault(regs, addr); + else + pagefault_out_of_memory(); + return; + } + if (!user_mode(regs)) { + i860_kernel_fault(regs, addr); + return; + } + if (fault & VM_FAULT_SIGBUS) + force_sig_fault(SIGBUS, BUS_ADRERR, (void __user *)addr); + else + force_sig_fault(SIGSEGV, code, (void __user *)addr); + return; + } + + if (fault & VM_FAULT_RETRY) { + flags |= FAULT_FLAG_TRIED; + goto retry; + } + + mmap_read_unlock(mm); + return; + +bad_area: + mmap_read_unlock(mm); +bad_area_nosemaphore: + if (user_mode(regs)) { + force_sig_fault(SIGSEGV, code, (void __user *)addr); + return; + } + i860_kernel_fault(regs, addr); +} diff --git a/arch/i860/mm/init.c b/arch/i860/mm/init.c new file mode 100644 index 000000000000..358aeb68fae2 --- /dev/null +++ b/arch/i860/mm/init.c @@ -0,0 +1,165 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (C) 2026 René Rebe */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +pgd_t swapper_pg_dir[PTRS_PER_PGD] __page_aligned_bss; + +pgd_t *i860_current_pgd = swapper_pg_dir; + +/* On-board I/O mapped statically into the window at I860_IO_VIRT. */ +static const struct { + unsigned long phys, size; +} i860_io_regions[] = { + { 0x1c000000, 0x1000 }, /* 82380, SCSI, FDC, LAN */ + { 0x1e000000, 0x1000 }, /* RTC, UARTs, keyboard, POST */ + { 0x1f000000, 0x10000 }, /* NVRAM */ +}; + +static pte_t * __init i860_pte(unsigned long va) +{ + pgd_t *pgd = swapper_pg_dir + pgd_index(va); + pte_t *pte; + + if (!pgd_val(*pgd)) { + pte = memblock_alloc_or_panic(PAGE_SIZE, PAGE_SIZE); + *pgd = __pgd(__pa(pte) | _PAGE_TABLE); + } + pte = (pte_t *)__va(pgd_val(*pgd) & PAGE_MASK); + return pte + ((va >> PAGE_SHIFT) & (PTRS_PER_PTE - 1)); +} + +static void __init i860_map(unsigned long va, unsigned long pa, + unsigned long size, pgprot_t prot) +{ + for (; size; size -= PAGE_SIZE, va += PAGE_SIZE, pa += PAGE_SIZE) + set_pte(i860_pte(va), pfn_pte(pa >> PAGE_SHIFT, prot)); +} + +static pte_t *i860_linear_pte(unsigned long va) +{ + pgd_t *pgd = swapper_pg_dir + pgd_index(va); + + return (pte_t *)__va(pgd_val(*pgd) & PAGE_MASK) + + ((va >> PAGE_SHIFT) & (PTRS_PER_PTE - 1)); +} + +/* + * Change the caching of one lowmem page in the linear map. Cached data is + * written back before the page becomes uncached; an uncached page leaves + * no lines behind. + */ +void i860_set_cacheable(void *addr, bool cacheable) +{ + pte_t *pte = i860_linear_pte((unsigned long)addr); + unsigned long val = pte_val(*pte); + + if (!!(val & _PAGE_CD) == !cacheable) + return; + if (!cacheable) + i860_flush_dcache_all(); + set_pte(pte, __pte(cacheable ? val & ~_PAGE_CD : val | _PAGE_CD)); + local_flush_tlb_all(); +} + +void __init paging_init(void) +{ + phys_addr_t start, end; + u64 i; + int r; + + for_each_mem_range(i, &start, &end) + i860_map(start, start, end - start, PAGE_KERNEL); + /* the trap vector page is not part of memblock */ + i860_map(I860_TRAP_PAGE, I860_TRAP_PAGE, PAGE_SIZE, PAGE_KERNEL); + + for (r = 0; r < ARRAY_SIZE(i860_io_regions); r++) + i860_map((unsigned long)I860_IO(i860_io_regions[r].phys), + i860_io_regions[r].phys, i860_io_regions[r].size, + __pgprot(_PAGE_IOREMAP)); + + /* + * The page directory and tables are walked in memory. This still runs + * on the uncached firmware mapping, so the stores reach memory. + */ + set_pte(i860_linear_pte((unsigned long)swapper_pg_dir), + __pte(pte_val(*i860_linear_pte((unsigned long)swapper_pg_dir)) | + _PAGE_CD)); + for (r = 0; r < PTRS_PER_PGD; r++) { + unsigned long table = pgd_val(swapper_pg_dir[r]) & PAGE_MASK; + pte_t *pte; + + if (!table) + continue; + pte = i860_linear_pte(table); + set_pte(pte, __pte(pte_val(*pte) | _PAGE_CD)); + } + + /* write back the firmware's cached data while its mapping is live */ + i860_flush_dcache_all(); + i860_set_pgd(swapper_pg_dir); +} + +void __iomem *ioremap_prot(phys_addr_t phys, size_t size, pgprot_t prot) +{ + int r; + + for (r = 0; r < ARRAY_SIZE(i860_io_regions); r++) + if (phys >= i860_io_regions[r].phys && + phys + size <= i860_io_regions[r].phys + + i860_io_regions[r].size) + return I860_IO(phys); + return generic_ioremap_prot(phys, size, prot); +} +EXPORT_SYMBOL(ioremap_prot); + +void iounmap(volatile void __iomem *addr) +{ + unsigned long va = (unsigned long)addr; + + if (va >= I860_IO_VIRT && va < I860_IO_VIRT + I860_IO_SIZE) + return; + generic_iounmap(addr); +} +EXPORT_SYMBOL(iounmap); + +pgd_t *pgd_alloc(struct mm_struct *mm) +{ + pgd_t *pgd = __pgd_alloc(mm, 0); + + if (pgd) { + memcpy(pgd + USER_PTRS_PER_PGD, + swapper_pg_dir + USER_PTRS_PER_PGD, + (PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t)); + i860_set_cacheable(pgd, false); + } + return pgd; +} + +static const pgprot_t protection_map[16] = { + [VM_NONE] = PAGE_NONE, + [VM_READ] = PAGE_READONLY, + [VM_WRITE] = PAGE_COPY, + [VM_WRITE | VM_READ] = PAGE_COPY, + [VM_EXEC] = PAGE_READONLY, + [VM_EXEC | VM_READ] = PAGE_READONLY, + [VM_EXEC | VM_WRITE] = PAGE_COPY, + [VM_EXEC | VM_WRITE | VM_READ] = PAGE_COPY, + [VM_SHARED] = PAGE_NONE, + [VM_SHARED | VM_READ] = PAGE_READONLY, + [VM_SHARED | VM_WRITE] = PAGE_SHARED, + [VM_SHARED | VM_WRITE | VM_READ] = PAGE_SHARED, + [VM_SHARED | VM_EXEC] = PAGE_READONLY, + [VM_SHARED | VM_EXEC | VM_READ] = PAGE_READONLY, + [VM_SHARED | VM_EXEC | VM_WRITE] = PAGE_SHARED, + [VM_SHARED | VM_EXEC | VM_WRITE | VM_READ] = PAGE_SHARED, +}; +DECLARE_VM_GET_PAGE_PROT diff --git a/drivers/input/serio/i8042-i860io.h b/drivers/input/serio/i8042-i860io.h new file mode 100644 index 000000000000..0005c9044bdc --- /dev/null +++ b/drivers/input/serio/i8042-i860io.h @@ -0,0 +1,54 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * i8042 on the Samsung i860 MAGIC Station II: data at 0x1e000a00, + * status/command at 0x1e000a08, keyboard IRQ 18. No AUX (mouse) port is + * known to be wired. + * Copyright (C) 2026 René Rebe + */ +#ifndef _I8042_I860IO_H +#define _I8042_I860IO_H + +#include + +#define I8042_KBD_PHYS_DESC "i8042/serio0" +#define I8042_AUX_PHYS_DESC "i8042/serio1" +#define I8042_MUX_PHYS_DESC "i8042/serio%d" + +#define I8042_KBD_IRQ 18 +#define I8042_AUX_IRQ 18 + +#define I8042_DATA_REG 0x1e000a00 +#define I8042_COMMAND_REG 0x1e000a08 +#define I8042_STATUS_REG 0x1e000a08 + +static inline int i8042_read_data(void) +{ + return readb(I860_IO(I8042_DATA_REG)); +} + +static inline int i8042_read_status(void) +{ + return readb(I860_IO(I8042_STATUS_REG)); +} + +static inline void i8042_write_data(int val) +{ + writeb(val, I860_IO(I8042_DATA_REG)); +} + +static inline void i8042_write_command(int val) +{ + writeb(val, I860_IO(I8042_COMMAND_REG)); +} + +static inline int i8042_platform_init(void) +{ + i8042_noaux = true; + return 0; +} + +static inline void i8042_platform_exit(void) +{ +} + +#endif diff --git a/drivers/input/serio/i8042.h b/drivers/input/serio/i8042.h index 5f61672d55b7..3f58d025bf22 100644 --- a/drivers/input/serio/i8042.h +++ b/drivers/input/serio/i8042.h @@ -5,6 +5,7 @@ /* * Copyright (c) 1999-2002 Vojtech Pavlik + * Copyright (C) 2026 René Rebe */ /* @@ -19,6 +20,8 @@ #include "i8042-snirm.h" #elif defined(CONFIG_SPARC) #include "i8042-sparcio.h" +#elif defined(CONFIG_I860) +#include "i8042-i860io.h" #elif defined(CONFIG_X86) || defined(CONFIG_LOONGARCH) #include "i8042-acpipnpio.h" #else diff --git a/drivers/net/ethernet/i825xx/Kconfig b/drivers/net/ethernet/i825xx/Kconfig index 3b5fab123824..6faf89ef882b 100644 --- a/drivers/net/ethernet/i825xx/Kconfig +++ b/drivers/net/ethernet/i825xx/Kconfig @@ -40,6 +40,13 @@ config LASI_82596 Say Y here to support the builtin Intel 82596 ethernet controller found in Hewlett-Packard PA-RISC machines with 10Mbit ethernet. +config MAGICST2_82596 + tristate "Samsung MAGIC Station II 82596 Ethernet" + depends on I860 + help + Say Y here to support the on-board Intel 82596 Ethernet controller + of the Samsung i860 MAGIC Station II. + config MVME16x_NET tristate "MVME16x Ethernet support" depends on MVME16x diff --git a/drivers/net/ethernet/i825xx/Makefile b/drivers/net/ethernet/i825xx/Makefile index 422a19a5d94f..d002596127f7 100644 --- a/drivers/net/ethernet/i825xx/Makefile +++ b/drivers/net/ethernet/i825xx/Makefile @@ -7,5 +7,6 @@ obj-$(CONFIG_ARM_ETHER1) += ether1.o obj-$(CONFIG_SUN3_82586) += sun3_82586.o obj-$(CONFIG_LASI_82596) += lasi_82596.o obj-$(CONFIG_SNI_82596) += sni_82596.o +obj-$(CONFIG_MAGICST2_82596) += magicst2_82596.o obj-$(CONFIG_MVME16x_NET) += 82596.o obj-$(CONFIG_BVME6000_NET) += 82596.o diff --git a/drivers/net/ethernet/i825xx/magicst2_82596.c b/drivers/net/ethernet/i825xx/magicst2_82596.c new file mode 100644 index 000000000000..635d47fc7918 --- /dev/null +++ b/drivers/net/ethernet/i825xx/magicst2_82596.c @@ -0,0 +1,636 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Intel 82596 Ethernet on the Samsung i860 MAGIC Station II. + * + * The 82596 (linear mode) is a bus master on DRAM, but its 32-bit data bus + * is wired to the low half of the 64-bit memory bus: chip address = + * physical address / 2, and each chip word is the low word of a CPU + * doubleword. lib82596 assumes contiguous descriptors, so this driver + * keeps all chip structures in an uncached window and reaches every chip + * word through stride-aware accessors. Frames use simplified descriptors + * with the whole frame in the data area (configure byte 3 = 0x2e). + * + * Registers (base 0x1c000e00): +0x00 channel attention, +0x10 PORT + * (low 16 bits, then high 16 bits), +0x18 interrupt clear. IRQ 14. + * + * Copyright (C) 2026 René Rebe + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define DRV_NAME "magicst2-82596" + +#define REG_CA 0x00 +#define REG_PORT 0x10 +#define REG_IRQ_CLR 0x18 + +#define PORT_RESET 0 +#define PORT_ALT_SCP 2 + +/* chip space layout (chip byte offsets) */ +#define CHIP_SIZE 0x8000 +#define OFF_SCP 0x0000 +#define OFF_ISCP 0x0010 +#define OFF_SCB 0x0020 +#define OFF_CMD 0x0060 /* configure / IA setup */ +#define OFF_TX 0x0080 +#define FRAME_SIZE 0x0600 /* descriptor + 1520 data bytes */ +#define DATA_SIZE (FRAME_SIZE - 16) +#define OFF_RX (OFF_TX + FRAME_SIZE) +#define N_RX ((CHIP_SIZE - OFF_RX) / FRAME_SIZE) + +/* SCB */ +#define SCB_STATUS 0 +#define SCB_CMD 2 +#define SCB_CBL 4 +#define SCB_RFA 8 +#define SCB_TON 36 +#define SCB_TOFF 38 + +#define STAT_CX 0x8000 +#define STAT_FR 0x4000 +#define STAT_CNA 0x2000 +#define STAT_RNR 0x1000 +#define STAT_ACK 0xf000 +#define RUS_MASK 0x00f0 +#define RUS_READY 0x0040 + +#define CUC_START 0x0100 +#define RUC_START 0x0010 +#define RUC_ABORT 0x0040 +#define CUC_ABORT 0x0400 + +/* command blocks and receive frame descriptors */ +#define CB_STATUS 0 +#define CB_CMD 2 +#define CB_LINK 4 +#define CB_PARAM 8 +#define CB_TBD 8 +#define CB_COUNT 12 +#define CB_DATA 16 + +#define C_DONE 0x8000 +#define C_OK 0x2000 +#define CMD_EL 0x8000 +#define CMD_SUSP 0x4000 +#define CMD_INTR 0x2000 +#define CMD_IA 1 +#define CMD_CONFIGURE 2 +#define CMD_TX 4 +#define COUNT_EOF 0x8000 +#define COUNT_MASK 0x3fff + +#define CHIP_NULL 0xffffffff + +/* RFD status error bits */ +#define RFD_CRC 0x0800 +#define RFD_ALIGN 0x0400 +#define RFD_OVERRUN 0x0100 +#define RFD_SHORT 0x0080 + +static const u8 i596_config[14] = { + 0x8e, 0xc8, 0x80, 0x2e, 0x00, 0x60, 0x00, 0xf2, + 0x00, 0x00, 0x40, 0xff, 0x00, 0x7f, +}; +#define CFG_LOOPBACK_BYTE 3 +#define CFG_INT_LOOPBACK 0x40 +#define CFG_PROMISC_BYTE 8 +#define CFG_PROMISC 0x01 + +struct ms2_lan { + struct net_device *dev; + void __iomem *regs; + void *shm; /* uncached CPU view, 2 * CHIP_SIZE bytes */ + void *shm_pages; /* linear map view, only for freeing */ + u32 chip_base; /* chip address of shm */ + unsigned int rx_head; + struct sk_buff *tx_skb; + spinlock_t lock; +}; + +/* chip word n lives in the low half of CPU doubleword n */ +static inline void __iomem *lan_ptr(struct ms2_lan *lp, u32 off) +{ + return (void __iomem *)(lp->shm + ((off & ~3U) << 1) + (off & 3)); +} + +static inline void lan_w32(struct ms2_lan *lp, u32 off, u32 v) +{ + __raw_writel(v, lan_ptr(lp, off)); +} + +static inline u32 lan_r32(struct ms2_lan *lp, u32 off) +{ + return __raw_readl(lan_ptr(lp, off)); +} + +static inline void lan_w16(struct ms2_lan *lp, u32 off, u16 v) +{ + __raw_writew(v, lan_ptr(lp, off)); +} + +static inline u16 lan_r16(struct ms2_lan *lp, u32 off) +{ + return __raw_readw(lan_ptr(lp, off)); +} + +static inline u32 lan_chip(struct ms2_lan *lp, u32 off) +{ + return lp->chip_base + off; +} + +static void lan_put_data(struct ms2_lan *lp, u32 off, const u8 *src, + unsigned int len) +{ + unsigned int i; + + for (i = 0; i + 4 <= len; i += 4) + lan_w32(lp, off + i, get_unaligned_le32(src + i)); + for (; i < len; i++) + __raw_writeb(src[i], lan_ptr(lp, off + i)); +} + +static void lan_get_data(struct ms2_lan *lp, u8 *dst, u32 off, + unsigned int len) +{ + unsigned int i; + + for (i = 0; i + 4 <= len; i += 4) + put_unaligned_le32(lan_r32(lp, off + i), dst + i); + for (; i < len; i++) + dst[i] = __raw_readb(lan_ptr(lp, off + i)); +} + +static void lan_ca(struct ms2_lan *lp) +{ + wmb(); + writel(1, lp->regs + REG_CA); +} + +static void lan_port(struct ms2_lan *lp, u32 cmd) +{ + writel(cmd & 0xffff, lp->regs + REG_PORT); + udelay(10); + writel(cmd >> 16, lp->regs + REG_PORT); + udelay(10); +} + +/* The SCB command field reads 0 once the chip has accepted a command. */ +static int lan_wait_scb(struct ms2_lan *lp) +{ + int i; + + for (i = 0; i < 10000; i++) { + if (!lan_r16(lp, OFF_SCB + SCB_CMD)) + return 0; + udelay(5); + } + netdev_err(lp->dev, "SCB command timeout, status %04x\n", + lan_r16(lp, OFF_SCB + SCB_STATUS)); + return -ETIMEDOUT; +} + +static int lan_scb_cmd(struct ms2_lan *lp, u16 cmd) +{ + int ret = lan_wait_scb(lp); + + lan_w16(lp, OFF_SCB + SCB_CMD, cmd); + lan_ca(lp); + return ret; +} + +/* Run one action command at OFF_CMD and wait for it to complete. */ +static int lan_action(struct ms2_lan *lp, u16 cmd, const u8 *param, + unsigned int len) +{ + int i; + + lan_w16(lp, OFF_CMD + CB_STATUS, 0); + lan_w16(lp, OFF_CMD + CB_CMD, CMD_EL | cmd); + lan_w32(lp, OFF_CMD + CB_LINK, CHIP_NULL); + lan_put_data(lp, OFF_CMD + CB_PARAM, param, len); + lan_w32(lp, OFF_SCB + SCB_CBL, lan_chip(lp, OFF_CMD)); + if (lan_scb_cmd(lp, CUC_START)) + return -ETIMEDOUT; + + for (i = 0; i < 10000; i++) { + u16 status = lan_r16(lp, OFF_CMD + CB_STATUS); + + if (status & C_DONE) { + /* acknowledge CX/CNA only: FR/RNR stay for the interrupt */ + lan_scb_cmd(lp, lan_r16(lp, OFF_SCB + SCB_STATUS) & + (STAT_CX | STAT_CNA)); + return (status & C_OK) ? 0 : -EIO; + } + udelay(10); + } + netdev_err(lp->dev, "command %d timeout\n", cmd); + return -ETIMEDOUT; +} + +static int lan_configure(struct ms2_lan *lp) +{ + u8 cfg[sizeof(i596_config)]; + + memcpy(cfg, i596_config, sizeof(cfg)); + if (lp->dev->features & NETIF_F_LOOPBACK) + cfg[CFG_LOOPBACK_BYTE] |= CFG_INT_LOOPBACK; + if (lp->dev->flags & IFF_PROMISC) + cfg[CFG_PROMISC_BYTE] |= CFG_PROMISC; + return lan_action(lp, CMD_CONFIGURE, cfg, sizeof(cfg)); +} + +static u32 rfd_off(unsigned int n) +{ + return OFF_RX + n * FRAME_SIZE; +} + +static void lan_init_rx(struct ms2_lan *lp) +{ + unsigned int n; + + for (n = 0; n < N_RX; n++) { + u32 rfd = rfd_off(n); + + lan_w16(lp, rfd + CB_STATUS, 0); + lan_w16(lp, rfd + CB_CMD, n == N_RX - 1 ? CMD_EL : 0); + lan_w32(lp, rfd + CB_LINK, lan_chip(lp, rfd_off((n + 1) % N_RX))); + lan_w32(lp, rfd + CB_TBD, CHIP_NULL); + lan_w16(lp, rfd + CB_COUNT, 0); + lan_w16(lp, rfd + CB_COUNT + 2, DATA_SIZE); + } + lp->rx_head = 0; +} + +static int lan_start_rx(struct ms2_lan *lp) +{ + lan_w32(lp, OFF_SCB + SCB_RFA, lan_chip(lp, rfd_off(lp->rx_head))); + return lan_scb_cmd(lp, RUC_START); +} + +static int lan_hw_init(struct ms2_lan *lp) +{ + struct net_device *dev = lp->dev; + int i, ret; + + lan_port(lp, PORT_RESET); + udelay(100); + + memset(lp->shm, 0, 2 * CHIP_SIZE); + lan_w32(lp, OFF_SCP, 0x005c0000); /* SYSBUS: linear mode */ + lan_w32(lp, OFF_SCP + 8, lan_chip(lp, OFF_ISCP)); + lan_w32(lp, OFF_ISCP, 1); /* busy */ + lan_w32(lp, OFF_ISCP + 4, lan_chip(lp, OFF_SCB)); + lan_w32(lp, OFF_SCB + SCB_CBL, CHIP_NULL); + lan_w32(lp, OFF_SCB + SCB_RFA, CHIP_NULL); + + lan_port(lp, lan_chip(lp, OFF_SCP) | PORT_ALT_SCP); + lan_ca(lp); + + for (i = 0; i < 10000 && (lan_r32(lp, OFF_ISCP) & 0xff); i++) + udelay(10); + if (lan_r32(lp, OFF_ISCP) & 0xff) { + netdev_err(dev, "82596 initialisation timeout\n"); + return -ETIMEDOUT; + } + lan_scb_cmd(lp, lan_r16(lp, OFF_SCB + SCB_STATUS) & STAT_ACK); + + ret = lan_configure(lp); + if (!ret) + ret = lan_action(lp, CMD_IA, dev->dev_addr, ETH_ALEN); + if (ret) { + netdev_err(dev, "82596 setup failed (%d)\n", ret); + return ret; + } + + lan_init_rx(lp); + return lan_start_rx(lp); +} + +static void lan_rx(struct ms2_lan *lp) +{ + struct net_device *dev = lp->dev; + + for (;;) { + u32 rfd = rfd_off(lp->rx_head); + u32 prev = rfd_off((lp->rx_head + N_RX - 1) % N_RX); + u16 status = lan_r16(lp, rfd + CB_STATUS); + unsigned int len; + struct sk_buff *skb; + + if (!(status & C_DONE)) + break; + + len = lan_r16(lp, rfd + CB_COUNT) & COUNT_MASK; + if ((status & C_OK) && len >= ETH_HLEN) { + skb = netdev_alloc_skb(dev, len + NET_IP_ALIGN); + if (skb) { + skb_reserve(skb, NET_IP_ALIGN); + lan_get_data(lp, skb_put(skb, len), rfd + CB_DATA, len); + skb->protocol = eth_type_trans(skb, dev); + netif_rx(skb); + dev->stats.rx_packets++; + dev->stats.rx_bytes += len; + } else { + dev->stats.rx_dropped++; + } + } else { + dev->stats.rx_errors++; + if (status & RFD_CRC) + dev->stats.rx_crc_errors++; + if (status & RFD_ALIGN) + dev->stats.rx_frame_errors++; + if (status & RFD_OVERRUN) + dev->stats.rx_over_errors++; + if (status & RFD_SHORT) + dev->stats.rx_length_errors++; + } + + /* this RFD becomes the end of the list */ + lan_w16(lp, rfd + CB_STATUS, 0); + lan_w16(lp, rfd + CB_COUNT, 0); + lan_w16(lp, rfd + CB_CMD, CMD_EL); + lan_w16(lp, prev + CB_CMD, 0); + lp->rx_head = (lp->rx_head + 1) % N_RX; + } +} + +static irqreturn_t lan_interrupt(int irq, void *dev_id) +{ + struct net_device *dev = dev_id; + struct ms2_lan *lp = netdev_priv(dev); + u16 status; + + spin_lock(&lp->lock); + writel(0, lp->regs + REG_IRQ_CLR); + lan_wait_scb(lp); + status = lan_r16(lp, OFF_SCB + SCB_STATUS); + if (status & STAT_ACK) + lan_scb_cmd(lp, status & STAT_ACK); + + if (status & (STAT_FR | STAT_RNR)) + lan_rx(lp); + if ((status & STAT_RNR) || ((status & RUS_MASK) != RUS_READY && + netif_running(dev))) + lan_start_rx(lp); + + if (lp->tx_skb && (lan_r16(lp, OFF_TX + CB_STATUS) & C_DONE)) { + if (lan_r16(lp, OFF_TX + CB_STATUS) & C_OK) { + dev->stats.tx_packets++; + dev->stats.tx_bytes += lp->tx_skb->len; + } else { + dev->stats.tx_errors++; + } + dev_consume_skb_irq(lp->tx_skb); + lp->tx_skb = NULL; + netif_wake_queue(dev); + } + spin_unlock(&lp->lock); + return IRQ_HANDLED; +} + +static netdev_tx_t lan_start_xmit(struct sk_buff *skb, struct net_device *dev) +{ + struct ms2_lan *lp = netdev_priv(dev); + unsigned long flags; + unsigned int len; + + if (skb_put_padto(skb, ETH_ZLEN)) + return NETDEV_TX_OK; + len = skb->len; + if (len > DATA_SIZE) { + dev->stats.tx_dropped++; + dev_kfree_skb_any(skb); + return NETDEV_TX_OK; + } + + spin_lock_irqsave(&lp->lock, flags); + netif_stop_queue(dev); + lp->tx_skb = skb; + lan_w16(lp, OFF_TX + CB_STATUS, 0); + lan_w16(lp, OFF_TX + CB_CMD, CMD_EL | CMD_INTR | CMD_TX); + lan_w32(lp, OFF_TX + CB_LINK, CHIP_NULL); + lan_w32(lp, OFF_TX + CB_TBD, CHIP_NULL); + lan_w16(lp, OFF_TX + CB_COUNT, len | COUNT_EOF); + lan_put_data(lp, OFF_TX + CB_DATA, skb->data, len); + lan_w32(lp, OFF_SCB + SCB_CBL, lan_chip(lp, OFF_TX)); + lan_scb_cmd(lp, CUC_START); + spin_unlock_irqrestore(&lp->lock, flags); + + netif_trans_update(dev); + return NETDEV_TX_OK; +} + +static void lan_tx_timeout(struct net_device *dev, unsigned int txqueue) +{ + struct ms2_lan *lp = netdev_priv(dev); + unsigned long flags; + + netdev_warn(dev, "transmit timeout, status %04x\n", + lan_r16(lp, OFF_SCB + SCB_STATUS)); + spin_lock_irqsave(&lp->lock, flags); + if (lp->tx_skb) { + dev_kfree_skb_any(lp->tx_skb); + lp->tx_skb = NULL; + dev->stats.tx_errors++; + } + lan_hw_init(lp); + spin_unlock_irqrestore(&lp->lock, flags); + netif_wake_queue(dev); +} + +static int lan_open(struct net_device *dev) +{ + struct ms2_lan *lp = netdev_priv(dev); + int ret; + + ret = request_irq(dev->irq, lan_interrupt, 0, dev->name, dev); + if (ret) + return ret; + ret = lan_hw_init(lp); + if (ret) { + free_irq(dev->irq, dev); + return ret; + } + netif_start_queue(dev); + return 0; +} + +static int lan_stop(struct net_device *dev) +{ + struct ms2_lan *lp = netdev_priv(dev); + + netif_stop_queue(dev); + lan_port(lp, PORT_RESET); + free_irq(dev->irq, dev); + if (lp->tx_skb) { + dev_kfree_skb(lp->tx_skb); + lp->tx_skb = NULL; + } + return 0; +} + +/* Re-run Configure; the CU is idle while no frame is in flight. */ +static void lan_reconfigure(struct net_device *dev) +{ + struct ms2_lan *lp = netdev_priv(dev); + unsigned long flags; + + if (!netif_running(dev)) + return; + spin_lock_irqsave(&lp->lock, flags); + if (!lp->tx_skb && lan_configure(lp)) + netdev_warn(dev, "reconfiguration failed\n"); + spin_unlock_irqrestore(&lp->lock, flags); +} + +static void lan_set_rx_mode(struct net_device *dev) +{ + lan_reconfigure(dev); +} + +static int lan_set_features(struct net_device *dev, netdev_features_t features) +{ + netdev_features_t changed = dev->features ^ features; + + dev->features = features; + if (changed & NETIF_F_LOOPBACK) + lan_reconfigure(dev); + return 0; +} + +static const struct net_device_ops lan_netdev_ops = { + .ndo_open = lan_open, + .ndo_stop = lan_stop, + .ndo_start_xmit = lan_start_xmit, + .ndo_tx_timeout = lan_tx_timeout, + .ndo_set_rx_mode = lan_set_rx_mode, + .ndo_set_features = lan_set_features, + .ndo_set_mac_address = eth_mac_addr, + .ndo_validate_addr = eth_validate_addr, +}; + +/* 64 KB of contiguous memory, used through an uncached mapping only. */ +static int lan_alloc_shm(struct ms2_lan *lp) +{ + unsigned int n = (2 * CHIP_SIZE) >> PAGE_SHIFT, i; + struct page **pages; + struct page *page; + + lp->shm_pages = alloc_pages_exact(2 * CHIP_SIZE, GFP_KERNEL | __GFP_ZERO); + if (!lp->shm_pages) + return -ENOMEM; + /* no dirty lines of the cached alias may be written back later */ + flush_cache_all(); + + pages = kmalloc_array(n, sizeof(*pages), GFP_KERNEL); + if (!pages) + goto err; + page = virt_to_page(lp->shm_pages); + for (i = 0; i < n; i++) + pages[i] = page + i; + lp->shm = vmap(pages, n, VM_MAP, pgprot_noncached(PAGE_KERNEL)); + kfree(pages); + if (!lp->shm) + goto err; + lp->chip_base = virt_to_phys(lp->shm_pages) >> 1; + return 0; +err: + free_pages_exact(lp->shm_pages, 2 * CHIP_SIZE); + return -ENOMEM; +} + +static void lan_free_shm(struct ms2_lan *lp) +{ + vunmap(lp->shm); + free_pages_exact(lp->shm_pages, 2 * CHIP_SIZE); +} + +static int lan_probe(struct platform_device *pdev) +{ + struct resource *regs, *mac; + void __iomem *nvram; + struct net_device *dev; + struct ms2_lan *lp; + u8 addr[ETH_ALEN]; + int irq, i, ret; + + regs = platform_get_resource(pdev, IORESOURCE_MEM, 0); + mac = platform_get_resource(pdev, IORESOURCE_MEM, 1); + irq = platform_get_irq(pdev, 0); + if (!regs || !mac || irq < 0) + return -ENODEV; + + dev = devm_alloc_etherdev(&pdev->dev, sizeof(*lp)); + if (!dev) + return -ENOMEM; + SET_NETDEV_DEV(dev, &pdev->dev); + lp = netdev_priv(dev); + lp->dev = dev; + spin_lock_init(&lp->lock); + + lp->regs = devm_ioremap(&pdev->dev, regs->start, resource_size(regs)); + nvram = devm_ioremap(&pdev->dev, mac->start, resource_size(mac)); + if (!lp->regs || !nvram) + return -ENOMEM; + + /* MAC address: NVRAM, one byte per 8-byte location */ + for (i = 0; i < ETH_ALEN; i++) + addr[i] = readb(nvram + 8 * i); + if (is_valid_ether_addr(addr)) { + eth_hw_addr_set(dev, addr); + } else { + dev_warn(&pdev->dev, "invalid NVRAM MAC address %pM\n", addr); + eth_hw_addr_random(dev); + } + + ret = lan_alloc_shm(lp); + if (ret) + return ret; + + dev->irq = irq; + dev->netdev_ops = &lan_netdev_ops; + dev->hw_features |= NETIF_F_LOOPBACK; + dev->watchdog_timeo = HZ; + lan_port(lp, PORT_RESET); + + ret = register_netdev(dev); + if (ret) { + lan_free_shm(lp); + return ret; + } + platform_set_drvdata(pdev, dev); + netdev_info(dev, "82596 at %pa, IRQ %d, MAC %pM\n", ®s->start, irq, + dev->dev_addr); + return 0; +} + +static void lan_remove(struct platform_device *pdev) +{ + struct net_device *dev = platform_get_drvdata(pdev); + + unregister_netdev(dev); + lan_free_shm(netdev_priv(dev)); +} + +static struct platform_driver lan_driver = { + .probe = lan_probe, + .remove = lan_remove, + .driver = { + .name = DRV_NAME, + }, +}; +module_platform_driver(lan_driver); + +MODULE_DESCRIPTION("Samsung MAGIC Station II 82596 Ethernet"); +MODULE_LICENSE("GPL"); diff --git a/drivers/rtc/rtc-msm6242.c b/drivers/rtc/rtc-msm6242.c index 80e364baac53..021c8d678f8c 100644 --- a/drivers/rtc/rtc-msm6242.c +++ b/drivers/rtc/rtc-msm6242.c @@ -3,6 +3,7 @@ * Oki MSM6242 RTC Driver * * Copyright 2009 Geert Uytterhoeven + * Copyright (C) 2026 René Rebe * * Based on the A2000 TOD code in arch/m68k/amiga/config.c * Copyright (C) 1993 Hamish Macdonald @@ -15,6 +16,7 @@ #include #include #include +#include #include #include @@ -72,20 +74,21 @@ enum { struct msm6242_priv { - u32 __iomem *regs; + void __iomem *regs; + unsigned int stride; /* bytes per register */ struct rtc_device *rtc; }; static inline unsigned int msm6242_read(struct msm6242_priv *priv, unsigned int reg) { - return __raw_readl(&priv->regs[reg]) & 0xf; + return __raw_readl(priv->regs + reg * priv->stride) & 0xf; } static inline void msm6242_write(struct msm6242_priv *priv, unsigned int val, unsigned int reg) { - __raw_writel(val, &priv->regs[reg]); + __raw_writel(val, priv->regs + reg * priv->stride); } static void msm6242_lock(struct msm6242_priv *priv) @@ -189,6 +192,7 @@ static const struct rtc_class_ops msm6242_rtc_ops = { static int __init msm6242_rtc_probe(struct platform_device *pdev) { struct resource *res; + const struct msm6242_platform_data *pdata; struct msm6242_priv *priv; struct rtc_device *rtc; @@ -200,6 +204,9 @@ static int __init msm6242_rtc_probe(struct platform_device *pdev) if (!priv) return -ENOMEM; + /* registers are 32 bits apart unless the platform says otherwise */ + pdata = dev_get_platdata(&pdev->dev); + priv->stride = 4 << (pdata ? pdata->reg_shift : 0); priv->regs = devm_ioremap(&pdev->dev, res->start, resource_size(res)); if (!priv->regs) return -ENOMEM; diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig index 1eec66195cf4..63335b81ede9 100644 --- a/drivers/scsi/Kconfig +++ b/drivers/scsi/Kconfig @@ -1415,6 +1415,14 @@ config MVME147_SCSI Support for the on-board SCSI controller on the Motorola MVME147 single-board computer. +config MAGICST2_SCSI + tristate "WD33C93A SCSI driver for the Samsung MAGIC Station II" + depends on I860 && SCSI + select SCSI_SPI_ATTRS + help + Support for the on-board WD33C93A SCSI controller of the Samsung + i860 MAGIC Station II. + config MVME16x_SCSI tristate "NCR53C710 SCSI driver for MVME16x" depends on MVME16x && SCSI diff --git a/drivers/scsi/Makefile b/drivers/scsi/Makefile index 5b9328dc3b62..611b86d9db5e 100644 --- a/drivers/scsi/Makefile +++ b/drivers/scsi/Makefile @@ -57,6 +57,7 @@ obj-$(CONFIG_A3000_SCSI) += a3000.o wd33c93.o obj-$(CONFIG_A2091_SCSI) += a2091.o wd33c93.o obj-$(CONFIG_GVP11_SCSI) += gvp11.o wd33c93.o obj-$(CONFIG_MVME147_SCSI) += mvme147.o wd33c93.o +obj-$(CONFIG_MAGICST2_SCSI) += magicst2.o wd33c93.o obj-$(CONFIG_SGIWD93_SCSI) += sgiwd93.o wd33c93.o obj-$(CONFIG_ATARI_SCSI) += atari_scsi.o obj-$(CONFIG_MAC_SCSI) += mac_scsi.o diff --git a/drivers/scsi/magicst2.c b/drivers/scsi/magicst2.c new file mode 100644 index 000000000000..75ceb5152428 --- /dev/null +++ b/drivers/scsi/magicst2.c @@ -0,0 +1,228 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Samsung i860 MAGIC Station II WD33C93A SCSI glue. + * + * The WD33C93A (indirect register access at 0x1c000a00/0x1c000a08, IRQ 13) + * transfers data with 82380 DMA channel 1 into the DMA buffer SRAM; the CPU + * bounces it to and from memory. As all data passes the SRAM, the whole + * remaining scatter-gather list is presented to the wd33c93 core as one + * segment: one DMA per command, and the chip is only resumed in the data + * phase after a disconnect. + * + * Copyright (C) 2026 René Rebe + */ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "wd33c93.h" + +#define CAN_QUEUE 16 +#define CMD_PER_LUN 2 + +struct magicst2_scsi { + struct WD33C93_hostdata wh; /* must be first */ + size_t dma_len; +}; + +/* per-command data; the wd33c93 core uses the scsi_pointer at the start */ +struct magicst2_cmd { + struct scsi_pointer scp; + size_t offset; /* bytes of the data phase done */ +}; + +static inline struct magicst2_cmd *magicst2_cmd(struct scsi_cmnd *cmd) +{ + return scsi_cmd_priv(cmd); +} + +/* Copy len bytes at offset skip of the command's data to or from the SRAM. */ +static void magicst2_sg_copy(struct scsi_cmnd *cmd, size_t skip, size_t len, + bool to_sram) +{ + struct sg_mapping_iter miter; + unsigned long sram = I860_SRAM_SCSI; + + sg_miter_start(&miter, scsi_sglist(cmd), scsi_sg_count(cmd), + SG_MITER_ATOMIC | + (to_sram ? SG_MITER_FROM_SG : SG_MITER_TO_SG)); + if (sg_miter_skip(&miter, skip)) { + while (len && sg_miter_next(&miter)) { + size_t n = min(miter.length, len); + + if (to_sram) + i860_sram_write(sram, miter.addr, n); + else + i860_sram_read(miter.addr, sram, n); + sram += n; + len -= n; + } + } + sg_miter_stop(&miter); +} + +static enum scsi_qc_status magicst2_queuecommand(struct Scsi_Host *instance, + struct scsi_cmnd *cmd) +{ + magicst2_cmd(cmd)->offset = 0; + return wd33c93_queuecommand(instance, cmd); +} + +static irqreturn_t magicst2_scsi_intr(int irq, void *data) +{ + struct Scsi_Host *instance = data; + unsigned long flags; + + spin_lock_irqsave(&instance->host_lock, flags); + wd33c93_intr(instance); + spin_unlock_irqrestore(&instance->host_lock, flags); + return IRQ_HANDLED; +} + +static int magicst2_dma_setup(struct scsi_cmnd *cmd, int dir_in) +{ + struct scsi_pointer *scsi_pointer = WD33C93_scsi_pointer(cmd); + struct magicst2_scsi *hdata = shost_priv(cmd->device->host); + size_t offset = magicst2_cmd(cmd)->offset; + size_t len = scsi_bufflen(cmd) - offset; + + /* max_sectors keeps commands within the SRAM partition */ + if (!len || len > I860_SRAM_SCSI_SIZE) + return 1; + + /* the core programs the WD33C93 count from this_residual */ + scsi_pointer->this_residual = len; + scsi_pointer->buffers_residual = 0; + if (!dir_in) + magicst2_sg_copy(cmd, offset, len, true); + hdata->wh.dma_dir = dir_in; + hdata->dma_len = len; + i860_dma_start(I860_DMA_SCSI, I860_SRAM_SCSI, len, !dir_in); + return 0; +} + +static void magicst2_dma_stop(struct Scsi_Host *instance, + struct scsi_cmnd *cmd, int status) +{ + struct magicst2_scsi *hdata = shost_priv(instance); + struct magicst2_cmd *mcmd = magicst2_cmd(cmd); + size_t done; + + i860_dma_stop(I860_DMA_SCSI); + if (!hdata->dma_len) + return; + /* this_residual is updated from the WD33C93 count after we return */ + done = hdata->dma_len - min(i860_dma_residue(I860_DMA_SCSI), + hdata->dma_len); + if (hdata->wh.dma_dir) + magicst2_sg_copy(cmd, mcmd->offset, done, false); + mcmd->offset += done; + hdata->dma_len = 0; +} + +static const struct scsi_host_template magicst2_scsi_template = { + .module = THIS_MODULE, + .proc_name = "magicst2", + .name = "MAGIC Station II WD33C93A SCSI", + .queuecommand = magicst2_queuecommand, + .eh_abort_handler = wd33c93_abort, + .eh_host_reset_handler = wd33c93_host_reset, + .show_info = wd33c93_show_info, + .write_info = wd33c93_write_info, + .can_queue = CAN_QUEUE, + .this_id = 7, + .sg_tablesize = SG_ALL, + .cmd_per_lun = CMD_PER_LUN, + .max_sectors = I860_SRAM_SCSI_SIZE / 512, + .cmd_size = sizeof(struct magicst2_cmd), +}; + +static int magicst2_scsi_probe(struct platform_device *pdev) +{ + struct Scsi_Host *instance; + struct magicst2_scsi *hdata; + struct resource *res; + wd33c93_regs regs; + void __iomem *base; + int irq, error, i; + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + irq = platform_get_irq(pdev, 0); + if (!res || irq < 0) + return -ENODEV; + base = devm_ioremap(&pdev->dev, res->start, resource_size(res)); + if (!base) + return -ENOMEM; + + instance = scsi_host_alloc(&magicst2_scsi_template, sizeof(*hdata)); + if (!instance) + return -ENOMEM; + instance->irq = irq; + instance->base = res->start; + + /* address/aux status at +0, data at +8 */ + regs.SASR = (volatile unsigned char *)base; + regs.SCMD = (volatile unsigned char *)(base + 8); + + hdata = shost_priv(instance); + hdata->wh.no_sync = 0xff; + hdata->wh.fast = 0; + hdata->wh.dma_mode = CTRL_BURST; + wd33c93_init(instance, regs, magicst2_dma_setup, magicst2_dma_stop, + WD33C93_FS_8_10); + /* + * The bus runs asynchronously, as with the firmware and the Stardent + * kernel: skip the SDTR exchange, which costs the first command its data. + */ + for (i = 0; i < 8; i++) + hdata->wh.sync_stat[i] = SS_SET; + + error = request_irq(irq, magicst2_scsi_intr, 0, "wd33c93", instance); + if (error) + goto err_put; + + error = scsi_add_host(instance, &pdev->dev); + if (error) + goto err_irq; + platform_set_drvdata(pdev, instance); + scsi_scan_host(instance); + return 0; + +err_irq: + free_irq(irq, instance); +err_put: + scsi_host_put(instance); + return error; +} + +static void magicst2_scsi_remove(struct platform_device *pdev) +{ + struct Scsi_Host *instance = platform_get_drvdata(pdev); + + scsi_remove_host(instance); + free_irq(instance->irq, instance); + scsi_host_put(instance); +} + +static struct platform_driver magicst2_scsi_driver = { + .probe = magicst2_scsi_probe, + .remove = magicst2_scsi_remove, + .driver = { + .name = "magicst2-scsi", + }, +}; +module_platform_driver(magicst2_scsi_driver); + +MODULE_DESCRIPTION("Samsung MAGIC Station II WD33C93A SCSI"); +MODULE_LICENSE("GPL"); diff --git a/drivers/video/fbdev/Kconfig b/drivers/video/fbdev/Kconfig index e8cd8cb76874..e45fce240ec8 100644 --- a/drivers/video/fbdev/Kconfig +++ b/drivers/video/fbdev/Kconfig @@ -1759,6 +1759,14 @@ config FB_BROADSHEET and could also have been called by other names when coupled with a bridge adapter. +config FB_MAGICST2 + bool "Samsung MAGIC Station II frame buffer" + depends on FB=y && I860 + select FB_IOMEM_HELPERS + help + Frame buffer of the i860 workstation, scrolling by moving the display + start of its TMS34020. Set up by the firmware. + config FB_SIMPLE tristate "Simple framebuffer support" depends on FB diff --git a/drivers/video/fbdev/Makefile b/drivers/video/fbdev/Makefile index 0b17c878154d..e1f18559cfe4 100644 --- a/drivers/video/fbdev/Makefile +++ b/drivers/video/fbdev/Makefile @@ -120,6 +120,7 @@ obj-$(CONFIG_FB_EFI) += efifb.o obj-$(CONFIG_FB_VGA16) += vga16fb.o obj-$(CONFIG_FB_OF) += offb.o obj-$(CONFIG_FB_SSD1307) += ssd1307fb.o +obj-$(CONFIG_FB_MAGICST2) += magicst2fb.o obj-$(CONFIG_FB_SIMPLE) += simplefb.o # the test framebuffer is last diff --git a/drivers/video/fbdev/magicst2fb.c b/drivers/video/fbdev/magicst2fb.c new file mode 100644 index 000000000000..ab0179969d57 --- /dev/null +++ b/drivers/video/fbdev/magicst2fb.c @@ -0,0 +1,170 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Samsung MAGIC Station II frame buffer: 8 MB, 2048 x 1024 x 32 bpp with 1280 x 1024 visible, + * timing by the firmware. Scrolling moves the display start of the TMS34020, whose + * processor stays halted. + * + * All 1024 lines are visible, so this needs the display address to wrap at 8 MB, as the + * MAME model does; unverified on the board. magicst2fb.ywrap=0 turns panning off. + * + * Copyright (C) 2026 René Rebe + */ + +#include +#include +#include +#include +#include + +#define MAGICST2FB_WIDTH 1280 +#define MAGICST2FB_HEIGHT 1024 +#define MAGICST2FB_STRIDE 8192 +/* DPYSTL in the low half, DPYSTH in the high one: a bit address, one line is 0x10000 */ +#define GSP_DPYST 0x40 + +static bool ywrap = true; +module_param(ywrap, bool, 0444); +MODULE_PARM_DESC(ywrap, "Scroll by moving the display start, needs the address to wrap at 8 MB"); + +struct magicst2fb_par { + void __iomem *gsp; + u32 pseudo_palette[16]; +}; + +static int magicst2fb_setcolreg(unsigned int regno, unsigned int red, unsigned int green, + unsigned int blue, unsigned int transp, struct fb_info *info) +{ + u32 *pal = info->pseudo_palette; + + if (regno >= 16) + return -EINVAL; + pal[regno] = (red >> 8) << info->var.red.offset | + (green >> 8) << info->var.green.offset | + (blue >> 8) << info->var.blue.offset; + return 0; +} + +static int magicst2fb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info) +{ + struct magicst2fb_par *par = info->par; + + writel(var->yoffset << 16, par->gsp + GSP_DPYST); + return 0; +} + +/* The 128-bit string routines, as the generic loops move 32 bits at a time */ +static void magicst2fb_fillrect(struct fb_info *info, const struct fb_fillrect *r) +{ + u32 pixel = ((u32 *)info->pseudo_palette)[r->color & 15]; + u8 *p = (u8 __force *)info->screen_base + r->dy * MAGICST2FB_STRIDE + r->dx * 4; + unsigned int y; + + if (info->state != FBINFO_STATE_RUNNING) + return; + if (r->rop != ROP_COPY || r->color >= 16 || (pixel & 0xff) * 0x01010101u != pixel) { + cfb_fillrect(info, r); + return; + } + for (y = 0; y < r->height; y++, p += MAGICST2FB_STRIDE) + memset(p, pixel, r->width * 4); +} + +static void magicst2fb_copyarea(struct fb_info *info, const struct fb_copyarea *a) +{ + u8 *base = (u8 __force *)info->screen_base; + u8 *d = base + a->dy * MAGICST2FB_STRIDE + a->dx * 4; + u8 *s = base + a->sy * MAGICST2FB_STRIDE + a->sx * 4; + long step = MAGICST2FB_STRIDE; + unsigned int y; + + if (info->state != FBINFO_STATE_RUNNING) + return; + if (a->dy > a->sy) { + d += (a->height - 1) * step; + s += (a->height - 1) * step; + step = -step; + } + for (y = 0; y < a->height; y++, d += step, s += step) + memmove(d, s, a->width * 4); +} + +static const struct fb_ops magicst2fb_ops = { + .owner = THIS_MODULE, + __FB_DEFAULT_IOMEM_OPS_RDWR, + .fb_fillrect = magicst2fb_fillrect, + .fb_copyarea = magicst2fb_copyarea, + .fb_imageblit = cfb_imageblit, + __FB_DEFAULT_IOMEM_OPS_MMAP, + .fb_setcolreg = magicst2fb_setcolreg, + .fb_pan_display = magicst2fb_pan_display, +}; + +static int magicst2fb_probe(struct platform_device *pdev) +{ + struct resource *vram = platform_get_resource(pdev, IORESOURCE_MEM, 0); + struct magicst2fb_par *par; + struct fb_info *info; + int err; + + if (!vram) + return -ENODEV; + + info = framebuffer_alloc(sizeof(*par), &pdev->dev); + if (!info) + return -ENOMEM; + par = info->par; + platform_set_drvdata(pdev, info); + + info->screen_base = devm_ioremap(&pdev->dev, vram->start, resource_size(vram)); + par->gsp = devm_platform_ioremap_resource(pdev, 1); + if (!info->screen_base || IS_ERR(par->gsp)) { + err = -ENOMEM; + goto err_release; + } + + strscpy(info->fix.id, "magicst2fb", sizeof(info->fix.id)); + info->fix.type = FB_TYPE_PACKED_PIXELS; + info->fix.visual = FB_VISUAL_TRUECOLOR; + info->fix.smem_start = vram->start; + info->fix.smem_len = resource_size(vram); + info->fix.line_length = MAGICST2FB_STRIDE; + info->fix.accel = FB_ACCEL_NONE; + + info->var.xres = MAGICST2FB_WIDTH; + info->var.yres = MAGICST2FB_HEIGHT; + info->var.xres_virtual = MAGICST2FB_STRIDE / 4; + info->var.yres_virtual = resource_size(vram) / MAGICST2FB_STRIDE; + info->var.bits_per_pixel = 32; + info->var.red = (struct fb_bitfield){ 0, 8, 0 }; + info->var.green = (struct fb_bitfield){ 8, 8, 0 }; + info->var.blue = (struct fb_bitfield){ 16, 8, 0 }; + info->var.activate = FB_ACTIVATE_NOW; + info->var.height = -1; + info->var.width = -1; + info->var.vmode = FB_VMODE_NONINTERLACED; + + info->fbops = &magicst2fb_ops; + info->pseudo_palette = par->pseudo_palette; + /* fbcon pans with this, without FBINFO_READS_FAST small regions are redrawn: reading is slow */ + if (ywrap) { + info->fix.ywrapstep = 1; + info->flags = FBINFO_HWACCEL_YWRAP | FBINFO_HWACCEL_COPYAREA; + } + + err = register_framebuffer(info); + if (err) + goto err_release; + fb_info(info, "%ux%u, %zu KB, %s\n", info->var.xres, info->var.yres, + (size_t)(resource_size(vram) >> 10), ywrap ? "display start scrolling" : "no panning"); + return 0; + +err_release: + framebuffer_release(info); + return err; +} + +static struct platform_driver magicst2fb_driver = { + .driver.name = "magicst2fb", + .probe = magicst2fb_probe, +}; +builtin_platform_driver(magicst2fb_driver); diff --git a/include/linux/platform_data/rtc-msm6242.h b/include/linux/platform_data/rtc-msm6242.h new file mode 100644 index 000000000000..e085fce08289 --- /dev/null +++ b/include/linux/platform_data/rtc-msm6242.h @@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (C) 2026 René Rebe */ +#ifndef __LINUX_PLATFORM_DATA_RTC_MSM6242_H +#define __LINUX_PLATFORM_DATA_RTC_MSM6242_H + +struct msm6242_platform_data { + /* register n is at n * (4 << reg_shift); 0 without platform data */ + unsigned int reg_shift; +}; + +#endif diff --git a/include/uapi/linux/audit.h b/include/uapi/linux/audit.h index abae0524746e..60cce480ef6b 100644 --- a/include/uapi/linux/audit.h +++ b/include/uapi/linux/audit.h @@ -2,6 +2,7 @@ /* audit.h -- Auditing support * * Copyright 2003-2004 Red Hat Inc., Durham, North Carolina. + * Copyright (C) 2026 René Rebe * All Rights Reserved. * * This program is free software; you can redistribute it and/or modify @@ -410,6 +411,7 @@ enum { #define AUDIT_ARCH_H8300 (EM_H8_300) #define AUDIT_ARCH_HEXAGON (EM_HEXAGON) #define AUDIT_ARCH_I386 (EM_386|__AUDIT_ARCH_LE) +#define AUDIT_ARCH_I860 (EM_860|__AUDIT_ARCH_LE) #define AUDIT_ARCH_IA64 (EM_IA_64|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE) #define AUDIT_ARCH_M32R (EM_M32R) #define AUDIT_ARCH_M68K (EM_68K) diff --git a/scripts/syscall.tbl b/scripts/syscall.tbl index 0ab531605120..08d50673ec17 100644 --- a/scripts/syscall.tbl +++ b/scripts/syscall.tbl @@ -290,6 +290,7 @@ 243 64 recvmmsg sys_recvmmsg # Architectures may provide up to 16 syscalls of their own between 244 and 259 244 arc cacheflush sys_cacheflush +244 i860 cacheflush sys_cacheflush 245 arc arc_settls sys_arc_settls 246 arc arc_gettls sys_arc_gettls 247 arc sysfs sys_sysfs