From patchwork Tue Feb 12 10:31:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 158145 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3668855jaa; Tue, 12 Feb 2019 02:36:41 -0800 (PST) X-Google-Smtp-Source: AHgI3IYPHZeZ/tIUjaFd2XCVL4YoKLf23EnAifmfoSO3REiaxbnFIsHKWjb7twK5eGrLm5S7W2Ju X-Received: by 2002:a0d:e607:: with SMTP id p7mr2156037ywe.329.1549967801285; Tue, 12 Feb 2019 02:36:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549967801; cv=none; d=google.com; s=arc-20160816; b=f1cTE3RYY9Uq9lojFPjh6QCvkvhFM0AZgkQyhhNEwOaUddBxUP7b7+r3yj6n/OEXPR YGUF3jlSCjacj5LRt6STa/Hvv6pyVwf8kCx2yd3Li00vx+jM1+UiXuAW0383mDGy9IxK roRwpu/QUt1nMw+HaDx25GG4goGpXwwelZZrZQ5D6vad4wVT7q8lsJyyEYbClI3obRWf EwDZk7eAAb8KHLP9AT7fJbsUpl86rQn7xJY8T1uMlszHzjI2dO9oVp0j2afhot1MvdI9 PsCCZJZm3eeTr2oc5QCnrOQfng7sl0nAORLSizT4e2yGJ6Ab/qjE30lo3KMfK8tc+BU1 6pLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:references:in-reply-to:message-id:date:subject :to:from; bh=TTRgXmHwvJ6JpfAy/O4PRb77Vr7iMfme++lWJBpdzWw=; b=njL3RTMH8Oo+qCXh0YlaxW1CEGZAtX/iPsiqs4M09v+5RO77vtCqVsWhNGGh4y5w+i MZG8pnXbzTuslTJxQTYGtFuBY3prLltJ4ID5k4FTY1Mr3JX7rr9FLEiXA/jC8gZN7EoL kL4SB6JcD/VDnk+VvYONkfbGK1NQj3h0vUfai2jUrol19O/LL+Rst65L200crxRD5xOu zYBymmcPIp8/WSozOYgS+dILZbGkyC1kXPKo8L+/2SaJ5RJ/I4kgH+4Jg6TCJvPZKVVb VV1YsPP/ImZpZM4dYZUKjLbtYvdKp2IoUJ0VNtrmeAA3OHOzoODTKT6D1uDzCpK+CrDk 270A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="grub-devel-bounces+patch=linaro.org@gnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id h5si7417951ywa.260.2019.02.12.02.36.41 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 12 Feb 2019 02:36:41 -0800 (PST) Received-SPF: pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of grub-devel-bounces+patch=linaro.org@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="grub-devel-bounces+patch=linaro.org@gnu.org" Received: from localhost ([127.0.0.1]:36990 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gtVQe-0003zz-KQ for patch@linaro.org; Tue, 12 Feb 2019 05:36:40 -0500 Received: from eggs.gnu.org ([209.51.188.92]:37313) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gtVML-0000vm-0g for grub-devel@gnu.org; Tue, 12 Feb 2019 05:32:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gtVMB-00048n-UZ for grub-devel@gnu.org; Tue, 12 Feb 2019 05:32:11 -0500 Received: from mx2.suse.de ([195.135.220.15]:51846 helo=mx1.suse.de) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gtVM8-0002ut-1I for grub-devel@gnu.org; Tue, 12 Feb 2019 05:32:02 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 98AB8AF45; Tue, 12 Feb 2019 10:31:11 +0000 (UTC) From: Alexander Graf To: grub-devel@gnu.org Subject: [PATCH v6 04/11] RISC-V: Add setjmp implementation Date: Tue, 12 Feb 2019 11:31:01 +0100 Message-Id: <20190212103108.56963-5-agraf@suse.de> X-Mailer: git-send-email 2.12.3 In-Reply-To: <20190212103108.56963-1-agraf@suse.de> References: <20190212103108.56963-1-agraf@suse.de> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] X-Received-From: 195.135.220.15 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: The development of GNU GRUB Cc: "rickchen36 @ gmail . com" , David Abdurachmanov , schwab@suse.de, "greentime @ andestech . com" , leif.lindholm@linaro.org, atish.patra@wdc.com, Michael Chang , Alistair Francis , Lukas Auer , Paul Walmsley , Bin Meng , Daniel Kiper MIME-Version: 1.0 Errors-To: grub-devel-bounces+patch=linaro.org@gnu.org Sender: "Grub-devel" This patch adds a 32/64 capable setjmp implementation for RISC-V. Signed-off-by: Alexander Graf Reviewed-by: Alistair Francis Reviewed-by: Bin Meng Tested-by: Bin Meng Reviewed-by: Daniel Kiper --- v3 -> v4: - Change copyright from 2013 to 2018 v4 -> v5: - Add blank lines before and after license tag --- grub-core/lib/riscv/setjmp.S | 84 +++++++++++++++++++++++++++++++++++++++++++ include/grub/riscv32/setjmp.h | 27 ++++++++++++++ include/grub/riscv64/setjmp.h | 27 ++++++++++++++ 3 files changed, 138 insertions(+) create mode 100644 grub-core/lib/riscv/setjmp.S create mode 100644 include/grub/riscv32/setjmp.h create mode 100644 include/grub/riscv64/setjmp.h -- 2.12.3 _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel diff --git a/grub-core/lib/riscv/setjmp.S b/grub-core/lib/riscv/setjmp.S new file mode 100644 index 000000000..b48ef29ea --- /dev/null +++ b/grub-core/lib/riscv/setjmp.S @@ -0,0 +1,84 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2018 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#include +#include + + .file "setjmp.S" + +GRUB_MOD_LICENSE "GPLv3+" + + .text + +#if __riscv_xlen == 64 +#define STORE_IDX(reg, idx) sd reg, (idx*8)(a0) +#define LOAD_IDX(reg, idx) ld reg, (idx*8)(a0) +#else +#define STORE_IDX(reg, idx) sw reg, (idx*4)(a0) +#define LOAD_IDX(reg, idx) lw reg, (idx*4)(a0) +#endif + +/* + * int grub_setjmp (grub_jmp_buf env) + */ +FUNCTION(grub_setjmp) + /* Preserve all callee-saved registers and the SP */ + STORE_IDX(s0, 0) + STORE_IDX(s1, 1) + STORE_IDX(s2, 2) + STORE_IDX(s3, 3) + STORE_IDX(s4, 4) + STORE_IDX(s5, 5) + STORE_IDX(s6, 6) + STORE_IDX(s7, 7) + STORE_IDX(s8, 8) + STORE_IDX(s9, 9) + STORE_IDX(s10, 10) + STORE_IDX(s11, 11) + STORE_IDX(ra, 12) + STORE_IDX(sp, 13) + li a0, 0 + ret + +/* + * int grub_longjmp (grub_jmp_buf env, int val) + */ +FUNCTION(grub_longjmp) + LOAD_IDX(s0, 0) + LOAD_IDX(s1, 1) + LOAD_IDX(s2, 2) + LOAD_IDX(s3, 3) + LOAD_IDX(s4, 4) + LOAD_IDX(s5, 5) + LOAD_IDX(s6, 6) + LOAD_IDX(s7, 7) + LOAD_IDX(s8, 8) + LOAD_IDX(s9, 9) + LOAD_IDX(s10, 10) + LOAD_IDX(s11, 11) + LOAD_IDX(ra, 12) + LOAD_IDX(sp, 13) + + /* Move the return value in place, but return 1 if passed 0. */ + beq a1, zero, longjmp_1 + mv a0, a1 + ret + + longjmp_1: + li a0, 1 + ret diff --git a/include/grub/riscv32/setjmp.h b/include/grub/riscv32/setjmp.h new file mode 100644 index 000000000..5a2123846 --- /dev/null +++ b/include/grub/riscv32/setjmp.h @@ -0,0 +1,27 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2018 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#ifndef GRUB_SETJMP_CPU_HEADER +#define GRUB_SETJMP_CPU_HEADER 1 + +typedef unsigned long long grub_jmp_buf[14]; + +int grub_setjmp (grub_jmp_buf env) RETURNS_TWICE; +void grub_longjmp (grub_jmp_buf env, int val) __attribute__ ((noreturn)); + +#endif /* ! GRUB_SETJMP_CPU_HEADER */ diff --git a/include/grub/riscv64/setjmp.h b/include/grub/riscv64/setjmp.h new file mode 100644 index 000000000..5a2123846 --- /dev/null +++ b/include/grub/riscv64/setjmp.h @@ -0,0 +1,27 @@ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2018 Free Software Foundation, Inc. + * + * GRUB is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GRUB is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GRUB. If not, see . + */ + +#ifndef GRUB_SETJMP_CPU_HEADER +#define GRUB_SETJMP_CPU_HEADER 1 + +typedef unsigned long long grub_jmp_buf[14]; + +int grub_setjmp (grub_jmp_buf env) RETURNS_TWICE; +void grub_longjmp (grub_jmp_buf env, int val) __attribute__ ((noreturn)); + +#endif /* ! GRUB_SETJMP_CPU_HEADER */