From patchwork Sun Sep 25 21:27:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 674721 X-Patchwork-Delegate: bmeng.cn@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 3sj0Yz3VXfz9s5w for ; Mon, 26 Sep 2016 07:27:51 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b=kKY9WX9L; dkim-atps=neutral Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 0CBCBA76A1; Sun, 25 Sep 2016 23:27:49 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id CcAy6x1wSAys; Sun, 25 Sep 2016 23:27:48 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 64FFAA766B; Sun, 25 Sep 2016 23:27:48 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 8F59BA766B for ; Sun, 25 Sep 2016 23:27:45 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id pS2nEM0nrwqY for ; Sun, 25 Sep 2016 23:27:45 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-io0-f173.google.com (mail-io0-f173.google.com [209.85.223.173]) by theia.denx.de (Postfix) with ESMTPS id 22033A7640 for ; Sun, 25 Sep 2016 23:27:42 +0200 (CEST) Received: by mail-io0-f173.google.com with SMTP id e66so75516235iod.1 for ; Sun, 25 Sep 2016 14:27:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=sender:from:to:cc:subject:date:message-id; bh=bV77PiZ9wlf8JyMpo0iJEEpNoLljYwNBYaW74vKAOdA=; b=kKY9WX9LZLvu5BXhKEKQ6qDh/YlGE8BX7k+GNW3u2NGWsUNWLmFAK96ffcrgGEf5Np 3wLZPceIpCAhal4NrHh3SqIgb9qEgoaw0eP/5Npqd0a81it0Jz87ni7OTpjg8y/ojhGo WwnoM32BEmzwNvdC3/2eHkMDSLVRojQ4tqKO+vkmVEpjnoWGeV9sDRnku2exvBXMnHuz NEn0DuBaaneFZLgUEWKn9qaaP9mToc/UvIzQtJGdrHL3i/adpeF6j/isW7+VQOTzmtcG PMRgBPBzarV3hDaR1XpqyHu9yZXFNKVFOPkWz/FC02bleeSaNNsPCOzB4+tZJAHkq/ZH YshA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=bV77PiZ9wlf8JyMpo0iJEEpNoLljYwNBYaW74vKAOdA=; b=Z2JK7HemGN1mtVXtZEFrEO4IN+m5i3HPO1IF64SDYo7/kIKuTl/AERSgifuWEM5t6J UmhfMfzUplA33JT3Nk+jH8l0ZJboz7soV1mjAQB9P72thyL/FWI0ODDcU3GTPYt1HoG0 XK8r73JZ+YWW3oRAfTBbd/J9G/Pv+rS7JX2pkW3cbF3xF9M1G5umhAdxFodT8l7FW1+p UN4/Xq36D58nUMfZaJ+Ce/B5R0DxJnk0v6OKb//0wGR6WxQ0nJDRfhrspDci8SQSVgeO etHl+GvP1sOroT7AoCsuyrjqvvZteV3s2slRCJ/yMWu8a58TkO/19uGx+56a5es04gAa 3Szw== X-Gm-Message-State: AE9vXwOi4MWUyrMqfFANyo3XAMxs3934ME4J5gXCQjsYJ2kq8nTXRSBe9guUyHk3v8sx0qcq X-Received: by 10.107.164.228 with SMTP id d97mr18747540ioj.185.1474838860708; Sun, 25 Sep 2016 14:27:40 -0700 (PDT) Received: from kaki.bld.corp.google.com ([100.100.202.55]) by smtp.gmail.com with ESMTPSA id m11sm7017012ioa.16.2016.09.25.14.27.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 25 Sep 2016 14:27:40 -0700 (PDT) Received: by kaki.bld.corp.google.com (Postfix, from userid 121222) id CC1E4220DB0; Sun, 25 Sep 2016 15:27:38 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Sun, 25 Sep 2016 15:27:30 -0600 Message-Id: <1474838857-25045-1-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 2.8.0.rc3.226.g39d4020 Subject: [U-Boot] [PATCH v2 1/8] x86: Add implementations of setjmp() and longjmp() X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 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" Bring in these functions from Linux v4.4. They will be needed for EFI loader support. Signed-off-by: Simon Glass --- Changes in v2: - Drop irrelevant comment - Add a comment about .size - Drop unnecessary .text directive - Make longjmp() always cause setjmp() to return 1 arch/x86/cpu/Makefile | 2 +- arch/x86/cpu/setjmp.S | 66 +++++++++++++++++++++++++++++++++++++++++++ arch/x86/include/asm/setjmp.h | 24 ++++++++++++++++ 3 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 arch/x86/cpu/setjmp.S create mode 100644 arch/x86/include/asm/setjmp.h diff --git a/arch/x86/cpu/Makefile b/arch/x86/cpu/Makefile index 2667e0b..f5b8c9e 100644 --- a/arch/x86/cpu/Makefile +++ b/arch/x86/cpu/Makefile @@ -10,7 +10,7 @@ extra-y = start.o obj-$(CONFIG_X86_RESET_VECTOR) += resetvec.o start16.o -obj-y += interrupts.o cpu.o cpu_x86.o call64.o +obj-y += interrupts.o cpu.o cpu_x86.o call64.o setjmp.o AFLAGS_REMOVE_call32.o := -mregparm=3 \ $(if $(CONFIG_EFI_STUB_64BIT),-march=i386 -m32) diff --git a/arch/x86/cpu/setjmp.S b/arch/x86/cpu/setjmp.S new file mode 100644 index 0000000..7443274 --- /dev/null +++ b/arch/x86/cpu/setjmp.S @@ -0,0 +1,66 @@ +/* + * Written by H. Peter Anvin + * Brought in from Linux v4.4 and modified for U-Boot + * From Linux arch/um/sys-i386/setjmp.S + * + * SPDX-License-Identifier: GPL-2.0 + */ + +#include +#include +#include + +#define _REGPARM + +/* + * The jmp_buf is assumed to contain the following, in order: + * %ebx + * %esp + * %ebp + * %esi + * %edi + * + */ + + .text + .align 4 + .globl setjmp + .type setjmp, @function +setjmp: +#ifdef _REGPARM + movl %eax, %edx +#else + movl 4(%esp), %edx +#endif + popl %ecx /* Return address, and adjust the stack */ + xorl %eax, %eax /* Return value */ + movl %ebx, (%edx) + movl %esp, 4(%edx) /* Post-return %esp! */ + pushl %ecx /* Make the call/return stack happy */ + movl %ebp, 8(%edx) + movl %esi, 12(%edx) + movl %edi, 16(%edx) + movl %ecx, 20(%edx) /* Return address */ + ret + + /* Provide function size if needed */ + .size setjmp, .-setjmp + + .align 4 + .globl longjmp + .type longjmp, @function +longjmp: +#ifdef _REGPARM + xchgl %eax, %edx +#else + movl 4(%esp), %edx /* jmp_ptr address */ +#endif + movl 1, %eax + movl (%edx), %ebx + movl 4(%edx), %esp + movl 8(%edx), %ebp + movl 12(%edx), %esi + movl 16(%edx), %edi + jmp *20(%edx) + + .size longjmp, .-longjmp diff --git a/arch/x86/include/asm/setjmp.h b/arch/x86/include/asm/setjmp.h new file mode 100644 index 0000000..deef67e --- /dev/null +++ b/arch/x86/include/asm/setjmp.h @@ -0,0 +1,24 @@ +/* + * Written by H. Peter Anvin + * Brought in from Linux v4.4 and modified for U-Boot + * From Linux arch/um/sys-i386/setjmp.S + * + * SPDX-License-Identifier: GPL-2.0 + */ + +#ifndef __setjmp_h +#define __setjmp_h + +struct jmp_buf_data { + unsigned int __ebx; + unsigned int __esp; + unsigned int __ebp; + unsigned int __esi; + unsigned int __edi; + unsigned int __eip; +}; + +int setjmp(struct jmp_buf_data *jmp_buf); +void longjmp(struct jmp_buf_data *jmp_buf); + +#endif