From nobody Fri Jul 15 18:03:52 2022 X-Original-To: dev-commits-src-main@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 4Lkzkc5l4kz4TGL1; Fri, 15 Jul 2022 18:03:52 +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 4Lkzkc5G47z3RCs; Fri, 15 Jul 2022 18:03:52 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1657908232; 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=eUBJ/YfYROmVFXZRkKoh8yz6EAJZde2Y3llPGmclExw=; b=tNhu1dAvzgSAgOXOoo3PWz43ExQT9NjiAkzV3hyoHvj/O14GcnmQyrqbigiPUn72PCLH2p kInZ030f3J50KiyxKs/xbign5NGd8r8gEM/9Cdsua0azOrQQggzWarFhwvnfEQ2EJA+XtH dLWX1aQbkesgNzmQURozdcGV86QzYvC94O3HYemzh+aLf1rqwpkq2/WeLL/P3nLhczsG6l l7i+WM95n6KWcdWxIpxXE7s0daYIN17aZmv/xZPibhjWzlY6dsE7+fJZw1c6nS2YH50o+t fJZELwzKmGmzX4iuBNQBy1pgy940VQCIwAx4jCsvnBhSuCRtuOCINvpdfUHYXw== 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 4Lkzkc4Ljbzrk2; Fri, 15 Jul 2022 18:03:52 +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 26FI3qJd060085; Fri, 15 Jul 2022 18:03:52 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 26FI3q7u060084; Fri, 15 Jul 2022 18:03:52 GMT (envelope-from git) Date: Fri, 15 Jul 2022 18:03:52 GMT Message-Id: <202207151803.26FI3q7u060084@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Warner Losh Subject: git: f5ed1b0f84bf - main - kboot: Rework _start List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: f5ed1b0f84bf06839f0947981ebdb3646c3c433a Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1657908232; 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=eUBJ/YfYROmVFXZRkKoh8yz6EAJZde2Y3llPGmclExw=; b=QGyX/L078QiDMZwqGjcubR5a6qncVzQ4E83FTg4hse7OhzMpIkOE/5K7/zbnqLUSBHS1Ak +CRJLWrevcX/lUXHPjmuG1AigdE201p48iRI384ghpH0Thb0b8MVVmrIssT1S+Un5GZoUb Q+jnaxMAGp6aQyEViL53LT7kq55rNqGxqTHaXcOnUyD0Lreb57S0g00w2W+JlQnicePBkZ 5JcCmzT9QQhhjRTAFKu16ZSED7swKzlUOBCEH1cQzel8p4ckysUXglDlTUKs1Asq8KSyX+ 1/3hMkhHYHUJj3FuEDtkoWVEiM5mc/OVakQZvt3rgzFEHZZN4Sww5nlszwXyPA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1657908232; a=rsa-sha256; cv=none; b=YCrycpuJtfxOodmYmtF/3FBTlXfk4d7YrWe6Oz4p+EsoKw5BSzTp66u2YFPRoDkmEdFwp/ mCWfEB8LWD/oHAvX9AGzXYe5aULcq4ms9TqYTDpRDOfBQDHXMy9tJogEvaa5O6XF5L8sD6 YPbq1eaINqDuKPUCy5Abrdox1+JN+XduQHaHVueHUYhJGC7dMHk1m4TcYP+L+oRjXvGEDY nMRhe/zhzOY+iBGQM/OiypfIBigN3cWlfYzKjZbCvMaS9PPxTJSAFsw18JY4gKrWpqO97/ V1YoJQbwJxxeg9pnQbHMNn8negOGQQFlLfKAc3bBWGrBCN5yirOEc3LRrlj9HA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=f5ed1b0f84bf06839f0947981ebdb3646c3c433a commit f5ed1b0f84bf06839f0947981ebdb3646c3c433a Author: Warner Losh AuthorDate: 2022-07-14 03:41:17 +0000 Commit: Warner Losh CommitDate: 2022-07-15 18:00:49 +0000 kboot: Rework _start Split _start into _start and _start_c (inspired by musl and the powerpc impl is copied from there). This allows us to actually get the command line arguments on all the platforms. We have a very simplified startup that supports only static linking. Sponsored by: Netflix --- stand/kboot/Makefile | 3 +- stand/kboot/arch/amd64/start_arch.h | 34 +++++++++++++++ stand/kboot/arch/powerpc64/start_arch.h | 30 +++++++++++++ stand/kboot/crt1.c | 74 +++++++++++++++++++++++++++++++++ stand/kboot/main.c | 6 --- 5 files changed, 140 insertions(+), 7 deletions(-) diff --git a/stand/kboot/Makefile b/stand/kboot/Makefile index 24ab77af66db..ce0868264acf 100644 --- a/stand/kboot/Makefile +++ b/stand/kboot/Makefile @@ -1,5 +1,6 @@ # $FreeBSD$ +LOADER_DISK_SUPPORT?= yes LOADER_CD9660_SUPPORT?= yes LOADER_MSDOS_SUPPORT?= no LOADER_EXT2FS_SUPPORT?= yes @@ -17,7 +18,7 @@ NEWVERSWHAT= "kboot loader" ${MACHINE_ARCH} INSTALLFLAGS= -b # Architecture-specific loader code -SRCS= vers.c main.c host_syscalls.c hostcons.c hostdisk.c kbootfdt.c gfx_fb_stub.c +SRCS= crt1.c 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/amd64/start_arch.h b/stand/kboot/arch/amd64/start_arch.h new file mode 100644 index 000000000000..57c514daf019 --- /dev/null +++ b/stand/kboot/arch/amd64/start_arch.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2022, Netflix, Inc. + * + * SPDX-Licnse-Identifier: BSD-2-Clause + */ + +/* + * Provides a _start routine that calls a _start_c routine that takes a pointer + * to the stack as documented in crt1.c. We skip the pointer to _DYNAMIC since + * we don't support dynamic libraries, at all. And while _start_c is our own + * thing, we comport to the calling conventions that glibc and musl have and + * make sure the second argument (%esi) is 0 for _DYNAMIC placeholder. We + * likely could call main directly with only a few more lines of code, but this + * is simple enough and concentrates all the expressable in C stuff there. We + * also generate eh_frames should we need to debug things (it doesn't change the + * genreated code, but leaves enough breadcrumbs to keep gdb happy). + */ + +__asm__( +".text\n" /* ENTRY(_start) */ +".p2align 4,0x90\n" +".global _start\n" +".type _start, @function\n" +"_start:\n" +".cfi_startproc\n" +" xor %rbp, %rbp\n" /* Clear out the stack frame pointer */ +" mov %rsp, %rdi\n" /* Pass pointer to current stack with argc, argv and envp on it */ +" xor %rsi, %rsi\n" /* No dynamic pointer for us, to keep it simple */ +" andq $-16, %rsp\n" /* Align stack to 16-byte boundary */ +" call _start_c\n" /* Our MI code takes it from here and won't return */ +/* NORETURN */ +".size _start, . - _start\n" /* END(_start) */ +".cfi_endproc" +); diff --git a/stand/kboot/arch/powerpc64/start_arch.h b/stand/kboot/arch/powerpc64/start_arch.h new file mode 100644 index 000000000000..cd2fad433cde --- /dev/null +++ b/stand/kboot/arch/powerpc64/start_arch.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2022 Netflix, Inc + * + * SPDX-Licnse-Identifier: BSD-2-Clause + */ + +/* + * Due to the PowerPC ABI, We can call main directly from here, so do so. + * + * Note: there may be some static initializers that aren't called, but we don't + * worry about that elsewhere. This is a stripped down environment. + * + * I think we could also do something like + * + * mflr r0 + * stw r0,4(r1) + * stwu r1,-16(r1) + * b _start_c + * + * But my powerpc assembler fu is quite lacking... + */ + +#define __unused __attribute__((__unused__)) + +void +_start(int argc, const char **argv, char **env, void *obj __unused, + void (*cleanup)(void) __unused) +{ + main(argc, argv, env); +} diff --git a/stand/kboot/crt1.c b/stand/kboot/crt1.c new file mode 100644 index 000000000000..c4525ad6c35e --- /dev/null +++ b/stand/kboot/crt1.c @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2022, Netflix, Inc. + * + * SPDX-Licnse-Identifier: BSD-2-Clause + */ + +/* + * MI part of the C startup code. We take a long * pointer (we assume long is + * the same size as a pointer, as the Linux world is wont to do). We get a + * pointer to the stack with the main args on it. We don't bother decoding the + * aux vector, but may need to do so in the future. + * + * The long *p points to: + * + * +--------------------+ + * | argc | Small address + * +--------------------+ + * | argv[0] | argv + * +--------------------+ + * | argv[1] | + * +--------------------+ + * ... + * +--------------------+ + * | NULL | &argv[argc] + * +--------------------+ + * | envp[0] | envp + * +--------------------+ + * | envp[1] | + * +--------------------+ + * ... + * +--------------------+ + * | NULL | + * +--------------------+ + * | aux type | AT_xxxx + * +--------------------+ + * | aux value | + * +--------------------+ + * | aux type | AT_xxxx + * +--------------------+ + * | aux value | + * +--------------------+ + * | aux type | AT_xxxx + * +--------------------+ + * | aux value | + * +--------------------+ + *... + * +--------------------+ + * | NULL | + * +--------------------+ + * + * The AUX vector contains additional information for the process to know from + * the kernel (not parsed currently). AT_xxxx constants are small (< 50). + */ + +extern void _start_c(long *); +extern int main(int, const char **, char **); + +#include "start_arch.h" + +void +_start_c(long *p) +{ + int argc; + const char **argv; + char **envp; + + argc = p[0]; + argv = (const char **)(p + 1); + envp = (char **)argv + argc + 1; + + /* Note: we don't ensure that fd 0, 1, and 2 are sane at this level */ + /* Also note: we expect main to exit, not return off the end */ + main(argc, argv, envp); +} diff --git a/stand/kboot/main.c b/stand/kboot/main.c index 9b99c859070b..90b31a611476 100644 --- a/stand/kboot/main.c +++ b/stand/kboot/main.c @@ -479,12 +479,6 @@ kboot_kseg_get(int *nseg, void **ptr) *ptr = &loaded_segments[0]; } -void -_start(int argc, const char **argv, char **env) -{ - main(argc, argv); -} - /* * Since proper fdt command handling function is defined in fdt_loader_cmd.c, * and declaring it as extern is in contradiction with COMMAND_SET() macro