From owner-svn-src-projects@FreeBSD.ORG Sun Apr 7 10:07:19 2013 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 3E214668; Sun, 7 Apr 2013 10:07:19 +0000 (UTC) (envelope-from cherry@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id 16BA1CA; Sun, 7 Apr 2013 10:07:19 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.6/8.14.6) with ESMTP id r37A7Itr099906; Sun, 7 Apr 2013 10:07:18 GMT (envelope-from cherry@svn.freebsd.org) Received: (from cherry@localhost) by svn.freebsd.org (8.14.6/8.14.5/Submit) id r37A7IuQ099905; Sun, 7 Apr 2013 10:07:18 GMT (envelope-from cherry@svn.freebsd.org) Message-Id: <201304071007.r37A7IuQ099905@svn.freebsd.org> From: "Cherry G. Mathew" Date: Sun, 7 Apr 2013 10:07:18 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r249225 - projects/amd64_xen_pv/sys/amd64/xen X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 07 Apr 2013 10:07:19 -0000 Author: cherry Date: Sun Apr 7 10:07:18 2013 New Revision: 249225 URL: http://svnweb.freebsd.org/changeset/base/249225 Log: Normalise stackframe exit layout for both errorcode bearing exceptions and others. This makes INTR_EXIT() work as expected. Fixes: Return to guest from events, exceptions and traps. Approved by: gibbs(implicit) Modified: projects/amd64_xen_pv/sys/amd64/xen/exception.S Modified: projects/amd64_xen_pv/sys/amd64/xen/exception.S ============================================================================== --- projects/amd64_xen_pv/sys/amd64/xen/exception.S Sun Apr 7 06:47:44 2013 (r249224) +++ projects/amd64_xen_pv/sys/amd64/xen/exception.S Sun Apr 7 10:07:18 2013 (r249225) @@ -105,8 +105,29 @@ #define RESTORE_SEGMENT_REGS \ call restore_segment_regs -/* stackframe management for trap() */ -/* Undo the work of the Xen template code */ +/* stackframe management for trap() + * + * Xen creates a "bounce frame" in the following format: + * { RCX, R11, [DS-GS,] [ERRCODE,] RIP, CS, RFLAGS, RSP, SS } + * + * Erratum: Comments in the Xen sources talk about [CR2] saved on the + * stackframe, but the code for this is not to be found. + * c.f: xen/arch/x86/x86_64/entry.S + * + * [DS-GS,] is only saved for the failsafe callback. + * + * [ERRCODE], is optional, depending on the type of (hardware) exception. + * See: the "AMD64 Architecture Programmer's Manuel, Volume 2: + * System Programming: Section 8.2 for individual error code + * reporting status + * + */ +/* + * Prepare the frame for a non-failsafe entry point. + * We frob the stack so it looks like the native entry point. + * See: "hardware defined" part of x86/frame.h struct trapframe; + */ + #define TRAP_FRAME_PREPARE \ movq (%rsp), %rcx ; \ movq 8(%rsp), %r11 ; \ @@ -130,11 +151,21 @@ TRAP_FRAME_PREPARE ; \ subq $TF_ERR, %rsp +/* + * Setting up the exit stackframe involves resetting the stack layout + * identically to that of an exception without error code. The reason + * for this is that in order to "iret", we make a hypervisor call, and + * this hypervisor call is a syscall which expects an 'error code' on + * the stack. We accomplish this by pushing quadword '0' onto the + * stack in the INTR_EXIT() stub. + * + */ + #define TRAP_FRAME_EXIT_NOERR \ addq $TF_RIP, %rsp #define TRAP_FRAME_EXIT_ERR \ - addq $TF_ERR, %rsp + addq $TF_RIP, %rsp #define TRAP_PROLOGUE(a) \ movl $(a), TF_TRAPNO(%rsp) ; \