From nobody Tue Jan 24 22:10:13 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4P1h3n6khjz3bdkK; Tue, 24 Jan 2023 22:10:13 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4P1h3n5rxBz4JSs; Tue, 24 Jan 2023 22:10:13 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674598213; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=E8Y2uuB6Bskq7mAXAafhDcyR0KngcFpg53uNBiM7o4M=; b=rsyhCx06h1F6G0OnxRiTJMcNigQ0O8wen3/kogOEox7pwqojdzZ5MmhtKz62Z7SNxOkrtM TQzGmkW2+/8+nDmG5+erBBMygvw5arb2bVjvBmDH+7pGpPxUWNUNiItMYOk2KcEx6v3bIT wONHiV+NGt44S/nph6eVKEk7sxJ3scfEtWlNj/uiX6LsSTwb6EA0T34VFU5xP2UBstQkRk F5DFrTkc6TM+amp10PU260gg3yBace+6Gm9CzFjBmcVDJ8eyAVqcFAsZP2EkbVVqosxm/T lHRhk8QomS/5e1joDi7evyzS57uZtMorlrDAy0E3PMJvZIh7v8b1aduuD3n+qw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674598213; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=E8Y2uuB6Bskq7mAXAafhDcyR0KngcFpg53uNBiM7o4M=; b=mhRSClSuwhRdXLRm5klE+HxSnsZ7jhOJNW3IFqloc2eeet9mFkgwPkzz5G10NTKQKYgDlV dQtIWVAqbul0Kns/DvtJEIBuaxH23xkzoA27BI7xYLHz7TOikd6wgDBsOj1ouxs2PIl8Lw cNvhkE3l/P/2SpZQkl/jRmHJveyU/kEpos78MGdV6b4jOzLIGwqwpDJy01cBC+Cx6kVAas C+f7qwaWILNWwADDwqnUv+RXuNFJivpcTZD7ApJdcND9XG25d30Y3g5fpDdbh+LS/14Mev cfCyTbiOjPqlUOtmosUpuoiejh0JbIlg9xNNA2gsWqqP7HIP+QJQwf/R3fgW9A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1674598213; a=rsa-sha256; cv=none; b=semALtaNHXoVaCERlkW2zNv4TpchJlz7f3KoPcLuOT6Pzbhmzk5Y9xxE0/w3z0oNH73ziI 3atDlSt+yAtF6N8e5dKO5iXvx0dMxGg1hVBswAxPhwAzZgWUBx2Yu0bJDF8tEbOdSFgnyT k38DwzSPTlKrF8nOJP4246N1WX7LNPK2W4YPxmcFFV6aa0CiYXW6I0cDRWSwgBqS7bus3U SU7Sm+qwJUJMgYpHb+MXtl//uIUHGu0djqefaaWOEFlVtrhToQ/k/MlGb3XBHVjBJBlHrW HzrHeZwHgYwSe38Lb9aAiHtNw//VHk9Tcbk3zjeUzsFzWdTBR4iB/nb2DHfI2A== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4P1h3n4tsZzQFF; Tue, 24 Jan 2023 22:10:13 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 30OMADFx077630; Tue, 24 Jan 2023 22:10:13 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 30OMADN9077627; Tue, 24 Jan 2023 22:10:13 GMT (envelope-from git) Date: Tue, 24 Jan 2023 22:10:13 GMT Message-Id: <202301242210.30OMADN9077627@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Warner Losh Subject: git: 6c7ccb922462 - stable/13 - kboot: move to generic syscall interface List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 6c7ccb922462e77bbcf755310e6bba1666a90d5a Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=6c7ccb922462e77bbcf755310e6bba1666a90d5a commit 6c7ccb922462e77bbcf755310e6bba1666a90d5a Author: Warner Losh AuthorDate: 2021-12-30 23:07:20 +0000 Commit: Warner Losh CommitDate: 2023-01-24 21:49:19 +0000 kboot: move to generic syscall interface Just have the MD code provide syscall and have generic code for the rest. Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D33515 (cherry picked from commit 5974cfe1ba47ac756fc0d5e48306730e1115b36c) --- stand/kboot/Makefile | 2 +- stand/kboot/arch/powerpc64/host_syscall.S | 116 ++++++++---------------------- stand/kboot/arch/powerpc64/syscall_nr.h | 15 ++++ stand/kboot/host_syscall.h | 10 +-- stand/kboot/host_syscalls.c | 86 ++++++++++++++++++++++ 5 files changed, 138 insertions(+), 91 deletions(-) diff --git a/stand/kboot/Makefile b/stand/kboot/Makefile index aa5511d915a9..24ab77af66db 100644 --- a/stand/kboot/Makefile +++ b/stand/kboot/Makefile @@ -17,7 +17,7 @@ NEWVERSWHAT= "kboot loader" ${MACHINE_ARCH} INSTALLFLAGS= -b # Architecture-specific loader code -SRCS= vers.c main.c hostcons.c hostdisk.c kbootfdt.c gfx_fb_stub.c +SRCS= vers.c main.c host_syscalls.c hostcons.c hostdisk.c kbootfdt.c gfx_fb_stub.c CFLAGS.gfx_fb_stub.c += -I${SRCTOP}/contrib/pnglite -I${SRCTOP}/sys/teken diff --git a/stand/kboot/arch/powerpc64/host_syscall.S b/stand/kboot/arch/powerpc64/host_syscall.S index a5556aa1b2dc..729bc6baa082 100644 --- a/stand/kboot/arch/powerpc64/host_syscall.S +++ b/stand/kboot/arch/powerpc64/host_syscall.S @@ -1,88 +1,32 @@ -/* - * - * $FreeBSD$ - */ - #include -ENTRY(host_read) - li %r0, 3 # SYS_read - sc - bso 1f - blr -1: - li %r3, 0 - blr -END(host_read) - -ENTRY(host_write) - li %r0, 4 # SYS_write - sc - blr -END(host_write) - -ENTRY(host_llseek) - li %r0, 140 # SYS_llseek - sc - blr -END(host_llseek) - -ENTRY(host_open) - li %r0, 5 # SYS_open - sc - bso 1f - blr -1: - li %r3, 0 - blr -END(host_open) - -ENTRY(host_close) - li %r0, 6 # SYS_close - sc - blr -END(host_close) - -ENTRY(host_mmap) - li %r0, 90 # SYS_mmap - sc - blr -END(host_mmap) - -ENTRY(host_uname) - li %r0, 122 # SYS_uname - sc - blr -END(host_uname) - -ENTRY(host_gettimeofday) - li %r0, 78 # SYS_gettimeofday - sc - blr -END(host_gettimeofday) - -ENTRY(host_select) - li %r0, 142 # SYS_select - sc - blr -END(host_select) - -ENTRY(kexec_load) - lis %r6,21 # KEXEC_ARCH_PPC64 - li %r0,268 # __NR_kexec_load - sc - blr -END(kexec_load) - -ENTRY(host_reboot) - li %r0,88 # SYS_reboot - sc - blr -END(host_reboot) - -ENTRY(host_getdents) - li %r0,141 # SYS_getdents - sc - blr -END(host_getdents) - +/* + * Emulate the Linux system call interface. The system call number is set in + * %r0, and %r3 -> %r8 have the 6 system call arguments. errno is returned + * as a negative value, but we use it more as a flag something went wrong + * rather than using its value. + * + * Return value in %r3. If it is positive or < -4096, it's a successful + * system call. If it is between -1 and -4095 then it's an failed system + * call with -x as the errno. Errors from the kernel are signaled via the + * the 'so' bit, but we don't test that here at all. There are at most 6 + * arguments to system calls in Linux. + * + * We expose the raw system call result, rather than do the POSIX + * converion to -1 and setting errno. + * + * Note: The code this replaced used bso to set %r3 to 0 for the read and + * open system calls for reasons that are still under investigation. + */ +ENTRY(host_syscall) + mr %r0, %r3 /* SYS_ number in $r0 */ + mr %r3, %r4 /* arg2 -> 1 */ + mr %r4, %r5 /* arg3 -> 2 */ + mr %r5, %r6 /* arg4 -> 3 */ + mr %r6, %r7 /* arg5 -> 4 */ + mr %r7, %r8 /* arg6 -> 5 */ + mr %r8, %r9 /* arg7 -> 6 */ + sc + blr +/* Note: We're exposing the raw return value to the caller */ +END(host_syscall) diff --git a/stand/kboot/arch/powerpc64/syscall_nr.h b/stand/kboot/arch/powerpc64/syscall_nr.h new file mode 100644 index 000000000000..2854124153a2 --- /dev/null +++ b/stand/kboot/arch/powerpc64/syscall_nr.h @@ -0,0 +1,15 @@ +#define SYS_read 3 +#define SYS_write 4 +#define SYS_open 5 +#define SYS_close 6 +#define SYS_gettimeofday 78 +#define SYS_reboot 88 +#define SYS_mmap 90 +#define SYS_uname 120 +#define SYS_llseek 140 +#define SYS_getdents 141 +#define SYS_select 142 +#define __NR_kexec_load 268 + +#define KEXEC_ARCH_PPC64 21 +#define KEXEC_ARCH KEXEC_ARCH_PPC64 diff --git a/stand/kboot/host_syscall.h b/stand/kboot/host_syscall.h index 60b006e5dba4..f6f22a736d53 100644 --- a/stand/kboot/host_syscall.h +++ b/stand/kboot/host_syscall.h @@ -30,12 +30,14 @@ #include +long host_syscall(int number, ...); + ssize_t host_read(int fd, void *buf, size_t nbyte); ssize_t host_write(int fd, const void *buf, size_t nbyte); int host_open(const char *path, int flags, int mode); ssize_t host_llseek(int fd, int32_t offset_high, int32_t offset_lo, uint64_t *result, int whence); int host_close(int fd); -void *host_mmap(void *addr, size_t len, int prot, int flags, int fd, int); +void *host_mmap(void *addr, size_t len, int prot, int flags, int fd, off_t off); #define host_getmem(size) host_mmap(0, size, 3 /* RW */, 0x22 /* ANON */, -1, 0); struct old_utsname { char sysname[65]; @@ -46,14 +48,14 @@ struct old_utsname { }; int host_uname(struct old_utsname *); struct host_timeval { - int tv_sec; - int tv_usec; + time_t tv_sec; + long tv_usec; }; int host_gettimeofday(struct host_timeval *a, void *b); int host_select(int nfds, long *readfds, long *writefds, long *exceptfds, struct host_timeval *timeout); int kexec_load(uint32_t start, int nsegs, uint32_t segs); -int host_reboot(int, int, int, uint32_t); +int host_reboot(int, int, int, uintptr_t); int host_getdents(int fd, void *dirp, int count); #endif diff --git a/stand/kboot/host_syscalls.c b/stand/kboot/host_syscalls.c new file mode 100644 index 000000000000..53be0c166374 --- /dev/null +++ b/stand/kboot/host_syscalls.c @@ -0,0 +1,86 @@ +#include "host_syscall.h" +#include "syscall_nr.h" +#include + +ssize_t +host_read(int fd, void *buf, size_t nbyte) +{ + return host_syscall(SYS_read, fd, (uintptr_t)buf, nbyte); + /* XXX original overrode errors */ +} + +ssize_t +host_write(int fd, const void *buf, size_t nbyte) +{ + return host_syscall(SYS_write, fd, (uintptr_t)buf, nbyte); +} + +int +host_open(const char *path, int flags, int mode) +{ + return host_syscall(SYS_open, (uintptr_t)path, flags, mode); + /* XXX original overrode errors */ +} + +ssize_t +host_llseek(int fd, int32_t offset_high, int32_t offset_lo, uint64_t *result, int whence) +{ +#ifdef SYS_llseek + return host_syscall(SYS_llseek, fd, offset_high, offset_lo, (uintptr_t)result, whence); +#else + int64_t rv = host_syscall(SYS_lseek, fd, + (int64_t)((uint64_t)offset_high << 32 | (uint32_t)offset_lo), whence); + if (rv > 0) + *result = (uint64_t)rv; + return (rv); +#endif +} + +int +host_close(int fd) +{ + return host_syscall(SYS_close, fd); +} + +void * +host_mmap(void *addr, size_t len, int prot, int flags, int fd, off_t off) +{ + return (void *)host_syscall(SYS_mmap, (uintptr_t)addr, len, prot, flags, fd, off); +} + +int +host_uname(struct old_utsname *uts) +{ + return host_syscall(SYS_uname, (uintptr_t)uts); +} + +int +host_gettimeofday(struct host_timeval *a, void *b) +{ + return host_syscall(SYS_gettimeofday, (uintptr_t)a, (uintptr_t)b); +} + +int +host_select(int nfds, long *readfds, long *writefds, long *exceptfds, + struct host_timeval *timeout) +{ + return host_syscall(SYS_select, nfds, (uintptr_t)readfds, (uintptr_t)writefds, (uintptr_t)exceptfds, (uintptr_t)timeout, 0); +} + +int +kexec_load(uint32_t start, int nsegs, uint32_t segs) +{ + return host_syscall(__NR_kexec_load, start, nsegs, segs, KEXEC_ARCH << 16); +} + +int +host_reboot(int magic1, int magic2, int cmd, uintptr_t arg) +{ + return host_syscall(SYS_reboot, magic1, magic2, cmd, arg); +} + +int +host_getdents(int fd, void *dirp, int count) +{ + return host_syscall(SYS_getdents, fd, (uintptr_t)dirp, count); +}