From patchwork Wed May 16 15:42:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 914711 X-Patchwork-Delegate: agraf@suse.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="qkgD++GX"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 40mJmp5kJxz9s2R for ; Thu, 17 May 2018 01:50:34 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 6E454C21FD5; Wed, 16 May 2018 15:48:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 625F9C21FEA; Wed, 16 May 2018 15:44:15 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id B9FA9C21FEC; Wed, 16 May 2018 15:43:04 +0000 (UTC) Received: from mail-it0-f67.google.com (mail-it0-f67.google.com [209.85.214.67]) by lists.denx.de (Postfix) with ESMTPS id 63C39C21F9A for ; Wed, 16 May 2018 15:42:53 +0000 (UTC) Received: by mail-it0-f67.google.com with SMTP id j186-v6so3073211ita.5 for ; Wed, 16 May 2018 08:42:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=Qfkn/mnZ/iPeqwWrRwbMntsIvRIqiCW1KW5T+cjQz+c=; b=qkgD++GXekV3LybsLD3iHXlhYBG6Oj7u+vpRDrqnfDpdM2Eiq1M70YKBDvQ+8kC7XZ T0sj8Y38NyILb3Z16f15A6IwFKBPxULAvRvSeFtRiG7yxEBDCS7lyy62ZrPCT/EEJOzU U1DRH9n8mARYEjrFL9VCT1S5syFIaPnzGJu1FX+KUbEGdgeR7NMK2ZLRasR+7daHzMj3 mx+CEPksO99snbHEfi+eyL++51UuPQYfVnZryWakvLYfTpA0Up229+3fl1xzPloEYIob JqekzPNTCXchOpQVTEjX4jZeiyZan7weAc3mpPPubu8GUUH5Hl5hD8M1emGthOPDfz+N w3eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=Qfkn/mnZ/iPeqwWrRwbMntsIvRIqiCW1KW5T+cjQz+c=; b=MXrGkUwu2A1jJ/CjbKalEe/QH9RYWgkp4Az+aYFt4Zkog1yyZ7iBj+lwlOfPQxMnWj JtEH74k1JRHAdZqtBsM/QItIatwPDkOwBtCbd0ppBf1YsdnBbH3d+1k/DUWQxznnd/J+ x/1t+B8oWOAMT4GVGvuCG4RPpl5I1QphNEAuEMVpZ0h4OchDEK3+7xPDoMDOWVKA7L6v 5bOTxSZO0S9eto6zXV8t0Vthin3SCm/qLcTVge6uYDStYOh4uOo6yisagig9P++1fFcf TcXWhzt+LDsTEfMY4Ph8cMm87Rwnj5vmYciTQ8mbAZzM5W2EXlVqIlYpHZ2dyH8WRBN6 fQbA== X-Gm-Message-State: ALKqPwfpGGxNuTi1Q28qMSAqtD0oxCR5okGe9MeU3Zon1WJpDffr653/ gja7Vbp6Hqqtm62HaoLPlQfPLQ== X-Google-Smtp-Source: AB8JxZp5K7c/q9n2iG+mRKhpiRorT2YU0vSDfjOm68A1sLl52jNccAFeClpJSp/HB1fpDQyPD/FanA== X-Received: by 2002:a24:e9c1:: with SMTP id f184-v6mr1508681ith.79.1526485371883; Wed, 16 May 2018 08:42:51 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([100.67.80.24]) by smtp.gmail.com with ESMTPSA id r23-v6sm1660162ioe.9.2018.05.16.08.42.50 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 16 May 2018 08:42:50 -0700 (PDT) Received: by kiwi.bld.corp.google.com (Postfix, from userid 121222) id DFC14140208; Wed, 16 May 2018 09:42:49 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Wed, 16 May 2018 09:42:22 -0600 Message-Id: <20180516154233.21457-6-sjg@chromium.org> X-Mailer: git-send-email 2.17.0.441.gb46fe60e1d-goog In-Reply-To: <20180516154233.21457-1-sjg@chromium.org> References: <20180516154233.21457-1-sjg@chromium.org> Cc: Andy Shevchenko , Heinrich Schuchardt , Alexander Graf Subject: [U-Boot] [PATCH v4 05/16] sandbox: Add a setjmp() implementation X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Add an implementation of setjmp() and longjmp() which rely on the underlying host C library. Since we cannot know how large the jump buffer needs to be, pick something that should be suitable and check it at runtime. At present we need access to the underlying struct as well. Signed-off-by: Simon Glass --- Changes in v4: - Fix up the sizeof() operations on jmp_buf - Update SPDX tags Changes in v3: None Changes in v2: None arch/sandbox/cpu/cpu.c | 13 +++++++++++++ arch/sandbox/cpu/os.c | 23 +++++++++++++++++++++++ arch/sandbox/include/asm/setjmp.h | 30 ++++++++++++++++++++++++++++++ include/os.h | 21 +++++++++++++++++++++ 4 files changed, 87 insertions(+) create mode 100644 arch/sandbox/include/asm/setjmp.h diff --git a/arch/sandbox/cpu/cpu.c b/arch/sandbox/cpu/cpu.c index d4ad020012e..cde0b055a67 100644 --- a/arch/sandbox/cpu/cpu.c +++ b/arch/sandbox/cpu/cpu.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -164,3 +165,15 @@ ulong timer_get_boot_us(void) return (count - base_count) / 1000; } + +int setjmp(jmp_buf jmp) +{ + return os_setjmp((ulong *)jmp, sizeof(*jmp)); +} + +void longjmp(jmp_buf jmp, int ret) +{ + os_longjmp((ulong *)jmp, ret); + while (1) + ; +} diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c index d76d0211a2d..5839932b005 100644 --- a/arch/sandbox/cpu/os.c +++ b/arch/sandbox/cpu/os.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -628,3 +629,25 @@ void os_localtime(struct rtc_time *rt) rt->tm_yday = tm->tm_yday; rt->tm_isdst = tm->tm_isdst; } + +int os_setjmp(ulong *jmp, int size) +{ + jmp_buf dummy; + + /* + * We cannot rely on the struct name that jmp_buf uses, so use a + * local variable here + */ + if (size < sizeof(dummy)) { + printf("setjmp: jmpbuf is too small (%d bytes, need %d)\n", + size, sizeof(jmp_buf)); + return -ENOSPC; + } + + return setjmp((struct __jmp_buf_tag *)jmp); +} + +void os_longjmp(ulong *jmp, int ret) +{ + longjmp((struct __jmp_buf_tag *)jmp, ret); +} diff --git a/arch/sandbox/include/asm/setjmp.h b/arch/sandbox/include/asm/setjmp.h new file mode 100644 index 00000000000..0fb1a11f234 --- /dev/null +++ b/arch/sandbox/include/asm/setjmp.h @@ -0,0 +1,30 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * (C) 2018 Google, Inc + * Written by Simon Glass + */ + +#ifndef _SETJMP_H_ +#define _SETJMP_H_ + +struct jmp_buf_data { + /* + * We're not sure how long this should be: + * + * amd64: 200 bytes + * arm64: 392 bytes + * armhf: 392 bytes + * + * So allow space for all of those, plus some extra. + * We don't need to worry about 16-byte alignment, since this does not + * run on Windows. + */ + ulong data[128]; +}; + +typedef struct jmp_buf_data jmp_buf[1]; + +int setjmp(jmp_buf jmp); +__noreturn void longjmp(jmp_buf jmp, int ret); + +#endif /* _SETJMP_H_ */ diff --git a/include/os.h b/include/os.h index 64e89a06c94..c8e0f52d306 100644 --- a/include/os.h +++ b/include/os.h @@ -330,4 +330,25 @@ int os_spl_to_uboot(const char *fname); */ void os_localtime(struct rtc_time *rt); +/** + * os_setjmp() - Call setjmp() + * + * Call the host system's setjmp() function. + * + * @jmp: Buffer to store current execution state + * @size: Size of buffer + * @return normal setjmp() value if OK, -ENOSPC if @size is too small + */ +int os_setjmp(ulong *jmp, int size); + +/** + * os_longjmp() - Call longjmp() + * + * Call the host system's longjmp() function. + * + * @jmp: Buffer where previous execution state was stored + * @ret: Value to pass to longjmp() + */ +void os_longjmp(ulong *jmp, int ret); + #endif