From nobody Sun Feb 8 13:59:13 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=cloud.com ARC-Seal: i=1; a=rsa-sha256; t=1725985011; cv=none; d=zohomail.com; s=zohoarc; b=eixYxWut25moubGyt4F6Hfhm73rWE0TmuQkGtMoY9RUh8t5ZMVRxZrNFYPXLOypj4h2BI72g9oo1ZVgXvidUTvjymG0jF28wH9dtjC//4WlB7Gm02ctLq15998fh+klDRhOXGxK8T7ZIpuikaO3agIVcrgiV9nL75NTTCyAY+mM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1725985011; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=733LuTti2vz+EFR0bf9WFVrkc1aXhrThkAewtQ4pEBM=; b=GlV4/BH37dyF66fBmx0cqbe7CzWr38XZ6nIdN5P6O4IGCe+/HOhvnGiEmuAy3qN7/FoOqyEuZ5ZXgPQrLbHwWWRljijid3oF94K5UH3ReFLUiBeZTcdnSAC2Y82PXVdDsgKTsU6uNNuYwTIutHeHT3PfIutbEZjcv1/y/y6bwUc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1725985011630167.7367459763367; Tue, 10 Sep 2024 09:16:51 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.795865.1205347 (Exim 4.92) (envelope-from ) id 1so3XY-0007R6-3U; Tue, 10 Sep 2024 16:16:28 +0000 Received: by outflank-mailman (output) from mailman id 795865.1205347; Tue, 10 Sep 2024 16:16:28 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1so3XX-0007PK-Ve; Tue, 10 Sep 2024 16:16:27 +0000 Received: by outflank-mailman (input) for mailman id 795865; Tue, 10 Sep 2024 16:16:26 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1so3XW-00073b-Tw for xen-devel@lists.xenproject.org; Tue, 10 Sep 2024 16:16:26 +0000 Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [2a00:1450:4864:20::532]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 06ac1364-6f90-11ef-99a1-01e77a169b0f; Tue, 10 Sep 2024 18:16:25 +0200 (CEST) Received: by mail-ed1-x532.google.com with SMTP id 4fb4d7f45d1cf-5c26311c6f0so7151690a12.3 for ; Tue, 10 Sep 2024 09:16:25 -0700 (PDT) Received: from fziglio-desktop.. ([185.25.67.249]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c3ebd468a1sm4397405a12.26.2024.09.10.09.16.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 09:16:23 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 06ac1364-6f90-11ef-99a1-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1725984984; x=1726589784; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=733LuTti2vz+EFR0bf9WFVrkc1aXhrThkAewtQ4pEBM=; b=fFND9lh1eonI7MVJk7KSL+jucQB/1024/f0poR1BVZ1mR3MYpe8xkSiGe6ShJraipO GV7pineQyB6i1B6HKh+vd/MrdFjRCwjSzN2MR72tWSfVbybYAfO2XYh34A1OX4jHLEKc H0uj2dNfkI/NhSkuUk2xaJgMqDfExfAZaqODo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725984984; x=1726589784; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=733LuTti2vz+EFR0bf9WFVrkc1aXhrThkAewtQ4pEBM=; b=lU8e03ZW0pbjfbVNJ68JD/7JiSCw8qaEdaFHqsTjvq8vjRmOKaCIwLCp9FqpEpHPRK b9YFOnmOTaca9++3Q57QHksqNilliYV6WBdM3YwE1jZrZsAhIWkbfprRp5oPc0rGXP5w Z364ds4zsOvkTsfsM1cN0wi3IJ10yq8DWWwoHIaE/jRVvNZUfwd7Z7KYoOBFxkYMYXsF tz/ECHHUrEmcXucvzhZkIRB+JjuwkP86vbei1b7idpxPbRLckvfdiJMJI2iqNWM8W6dz P3JejkhLhLQetHWAEHleTew9P0RzwTkwOWyLs8it5gfciBIt85KSK20zeMXnEH+Zbk14 NnlQ== X-Gm-Message-State: AOJu0Yy7k1A49St+sM+dQW2wP9ja0wsbKtLKgNDbjO/sLe0ymwf6l+eD +jQWARoS+sq7ftjQXAAXvdL+Thm0U3wSipUONdVmk1MzyEmHChDUqdp/iNoaHdaT7sUOZd8DzS9 D X-Google-Smtp-Source: AGHT+IH161caz/hrEEDmu9rbaORyuKaIBN8RaZW2Jp2SQC5GDgiJwwYUecWOIrC97hdu248Z+GXJJQ== X-Received: by 2002:a05:6402:5254:b0:5c2:caf6:64d4 with SMTP id 4fb4d7f45d1cf-5c3dc78dbaamr10636424a12.12.1725984984320; Tue, 10 Sep 2024 09:16:24 -0700 (PDT) From: Frediano Ziglio To: xen-devel@lists.xenproject.org Cc: Frediano Ziglio , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [PATCH 2/3] x86/boot: Refactor BIOS/PVH start Date: Tue, 10 Sep 2024 17:16:11 +0100 Message-Id: <20240910161612.242702-3-frediano.ziglio@cloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240910161612.242702-1-frediano.ziglio@cloud.com> References: <20240910161612.242702-1-frediano.ziglio@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1725985012810116600 Content-Type: text/plain; charset="utf-8" The 2 code paths were sharing quite some common code, reuse it instead of having duplications. Use %ebp register to store boot type before running common code. Signed-off-by: Frediano Ziglio --- xen/arch/x86/boot/head.S | 113 +++++++++++++++------------------------ 1 file changed, 44 insertions(+), 69 deletions(-) diff --git a/xen/arch/x86/boot/head.S b/xen/arch/x86/boot/head.S index de118d72f2..a91413184c 100644 --- a/xen/arch/x86/boot/head.S +++ b/xen/arch/x86/boot/head.S @@ -25,6 +25,9 @@ #define MB2_HT(name) (MULTIBOOT2_HEADER_TAG_##name) #define MB2_TT(name) (MULTIBOOT2_TAG_TYPE_##name) =20 +#define BOOT_TYPE_BIOS 1 +#define BOOT_TYPE_PVH 2 + .macro mb2ht_args arg:req, args:vararg .long \arg .ifnb \args @@ -409,13 +412,28 @@ cs32_switch: ELFNOTE(Xen, XEN_ELFNOTE_PHYS32_ENTRY, .long sym_offs(__pvh_start)) =20 __pvh_start: - cld cli + mov $BOOT_TYPE_PVH, %ebp + jmp common_bios_pvh +#endif /* CONFIG_PVH_GUEST */ + +__start: + cli + mov $BOOT_TYPE_BIOS, %ebp + +common_bios_pvh: + cld =20 /* - * We need one call (i.e. push) to determine the load address. See - * __start for a discussion on how to do this safely using the PVH - * info structure. + * Multiboot (both 1 and 2) and PVH specify the stack pointer as + * undefined. This is unhelpful for relocatable images, where one + * call (i.e. push) is required to calculate the image's load addr= ess. + * + * Durig BIOS boot, there is one area of memory we know about with + * reasonable confidence that it isn't overlapped by Xen, and that= 's + * the Multiboot info structure in %ebx. Use it as a temporary st= ack. + * + * During PVH boot use info structure in %ebx. */ =20 /* Preserve the field we're about to clobber. */ @@ -433,14 +451,9 @@ __pvh_start: /* Set up stack. */ lea STACK_SIZE - CPUINFO_sizeof + sym_esi(cpu0_stack), %esp =20 - call initialise_bss - - mov %ebx, sym_esi(pvh_start_info_pa) - - /* Force xen console. Will revert to user choice in init code. */ - movb $-1, sym_esi(opt_console_xen) - - /* Prepare gdt and segments */ + /* + * Initialize GDTR and basic data segments. + */ add %esi, sym_esi(gdt_boot_base) lgdt sym_esi(gdt_boot_descr) =20 @@ -449,67 +462,44 @@ __pvh_start: mov %ecx, %es mov %ecx, %ss =20 - /* Skip bootloader setup and bios setup, go straight to trampoline= */ - movb $1, sym_esi(pvh_boot) - movb $1, sym_esi(skip_realmode) - - /* Set trampoline_phys to use mfn 1 to avoid having a mapping at V= A 0 */ - movw $0x1000, sym_esi(trampoline_phys) - mov (%ebx), %eax /* mov $XEN_HVM_START_MAGIC_VALUE, %eax */ - jmp trampoline_setup - -#endif /* CONFIG_PVH_GUEST */ + /* Load null descriptor to unused segment registers. */ + xor %ecx, %ecx + mov %ecx, %fs + mov %ecx, %gs =20 -initialise_bss: /* * Initialise the BSS. * * !!! WARNING - also zeroes the current stack !!! */ - pop %ebp mov %eax, %edx - lea sym_esi(__bss_start), %edi lea sym_esi(__bss_end), %ecx sub %edi, %ecx xor %eax, %eax shr $2, %ecx rep stosl - mov %edx, %eax - jmp *%ebp - -__start: - cld - cli =20 - /* - * Multiboot (both 1 and 2) specify the stack pointer as undefined - * when entering in BIOS circumstances. This is unhelpful for - * relocatable images, where one call (i.e. push) is required to - * calculate the image's load address. - * - * This early in boot, there is one area of memory we know about w= ith - * reasonable confidence that it isn't overlapped by Xen, and that= 's - * the Multiboot info structure in %ebx. Use it as a temporary st= ack. - */ - - /* Preserve the field we're about to clobber. */ - mov (%ebx), %edx - lea 4(%ebx), %esp +#ifdef CONFIG_PVH_GUEST + cmp $BOOT_TYPE_PVH, %ebp + jne 1f =20 - /* Calculate the load base address. */ - call 1f -1: pop %esi - sub $sym_offs(1b), %esi + mov %ebx, sym_esi(pvh_start_info_pa) =20 - /* Restore the clobbered field. */ - mov %edx, (%ebx) + /* Force xen console. Will revert to user choice in init code. */ + movb $-1, sym_esi(opt_console_xen) =20 - /* Set up stack. */ - lea STACK_SIZE - CPUINFO_sizeof + sym_esi(cpu0_stack), %esp + /* Skip bootloader setup and bios setup, go straight to trampoline= */ + movb $1, sym_esi(pvh_boot) + movb $1, sym_esi(skip_realmode) =20 - call initialise_bss + /* Set trampoline_phys to use mfn 1 to avoid having a mapping at V= A 0 */ + movw $0x1000, sym_esi(trampoline_phys) + mov (%ebx), %eax /* mov $XEN_HVM_START_MAGIC_VALUE, %eax */ + jmp trampoline_setup +1: +#endif /* CONFIG_PVH_GUEST */ =20 /* Bootloaders may set multiboot{1,2}.mem_lower to a nonzero value= . */ xor %edx,%edx @@ -568,22 +558,7 @@ __start: trampoline_bios_setup: /* * Called on legacy BIOS platforms only. - * - * Initialize GDTR and basic data segments. */ - add %esi,sym_esi(gdt_boot_base) - lgdt sym_esi(gdt_boot_descr) - - mov $BOOT_DS,%ecx - mov %ecx,%ds - mov %ecx,%es - mov %ecx,%ss - /* %esp is initialized later. */ - - /* Load null descriptor to unused segment registers. */ - xor %ecx,%ecx - mov %ecx,%fs - mov %ecx,%gs =20 /* Set up trampoline segment 64k below EBDA */ movzwl 0x40e,%ecx /* EBDA segment */ --=20 2.34.1