public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Yao, Jiewen" <jiewen.yao@intel.com>
To: Laszlo Ersek <lersek@redhat.com>, Andrew Fish <afish@apple.com>,
	edk2-devel <edk2-devel@lists.01.org>
Subject: Re: UefiCpuPkg CpuDxe GDT init question?
Date: Fri, 8 Mar 2019 14:13:11 +0000	[thread overview]
Message-ID: <74D8A39837DF1E4DA445A8C0B3885C503F55C19B@shsmsx102.ccr.corp.intel.com> (raw)
In-Reply-To: <480fe32f-032e-0bf8-a561-c41a16213b82@redhat.com>

I guess the historic reason is that AP and BSP share same GDT before. As such, the GDT need to be below 4G, to let AP switch from real mode to protected mode.
We don't get issue, because Runtime memory is in BIN, and most platform allocates BIN under 4G.

Some thought:
1) I am think we not sure if AP is using same GDT as BSP today. If yes, we need GDT under 4G, by using MaxAddress. If no, there should be no restriction for BSP GDT. The (UINT32) case should be removed for BSP. But we still AP GDT below 4G, to support wake from INIT-SIPI-SIPI.
2) I am not sure why we need runtime memory. Do we need touch GDT at UEFI runtime?



Thank you
Yao Jiewen


> -----Original Message-----
> From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of
> Laszlo Ersek
> Sent: Friday, March 8, 2019 12:00 AM
> To: Andrew Fish <afish@apple.com>; edk2-devel <edk2-devel@lists.01.org>
> Subject: Re: [edk2] UefiCpuPkg CpuDxe GDT init question?
> 
> Hi Andrew,
> 
> On 03/07/19 23:37, Andrew Fish via edk2-devel wrote:
> > I'm trying to understand why gdtPtr.Base is casting to (UINT32)?
> > 1) gdtPtr.Base is a a UINTN
> > 2) It is legal for AllocateRuntimePool() to return an address > 4GB
> >
> > It seems like the code should just cast to (UINTN)?
> >
> >
> >
> https://github.com/tianocore/edk2/blob/master/UefiCpuPkg/CpuDxe/CpuG
> dt.c#L151
> 
> I think you are right.
> 
> I'm missing the background on this too. I tried to see if any
> justification was given in a git commit message, but according to "git
> blame", this code dates back to the original addition of the driver,
> namely commit a47463f28382 ("Add CPU DXE driver for IA32 & X64
> processor
> architectures.", 2009-05-27). The commit message is unhelpful (for 3119
> lines added).
> 
> Thanks
> Laszlo
> 
> >
> >
> >
> > VOID
> > InitGlobalDescriptorTable (
> >   VOID
> >   )
> > {
> >   GDT_ENTRIES *gdt;
> >   IA32_DESCRIPTOR gdtPtr;
> >
> >   //
> >   // Allocate Runtime Data for the GDT
> >   //
> >   gdt = AllocateRuntimePool (sizeof (GdtTemplate) + 8);
> >   ASSERT (gdt != NULL);
> >   gdt = ALIGN_POINTER (gdt, 8);
> >
> >   //
> >   // Initialize all GDT entries
> >   //
> >   CopyMem (gdt, &GdtTemplate, sizeof (GdtTemplate));
> >
> >   //
> >   // Write GDT register
> >   //
> >   gdtPtr.Base = (UINT32)(UINTN)(VOID*) gdt;
> >   gdtPtr.Limit = (UINT16) (sizeof (GdtTemplate) - 1);
> >   AsmWriteGdtr (&gdtPtr);
> >
> > Thanks,
> >
> > Andrew Fish
> > _______________________________________________
> > edk2-devel mailing list
> > edk2-devel@lists.01.org
> > https://lists.01.org/mailman/listinfo/edk2-devel
> >
> 
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel


  reply	other threads:[~2019-03-08 14:13 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-07 22:37 UefiCpuPkg CpuDxe GDT init question? Andrew Fish
2019-03-08  5:02 ` Andrew Fish
2019-03-08  7:59 ` Laszlo Ersek
2019-03-08 14:13   ` Yao, Jiewen [this message]
2019-03-08 15:08     ` Laszlo Ersek
2019-03-09  3:10       ` Andrew Fish
2019-03-11 15:59         ` Andrew Fish
2019-03-11 16:04           ` Yao, Jiewen
2019-03-11 16:30             ` Andrew Fish
2019-03-11 21:04               ` Yao, Jiewen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=74D8A39837DF1E4DA445A8C0B3885C503F55C19B@shsmsx102.ccr.corp.intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox