public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Marvin Häuser" <Marvin.Haeuser@outlook.com>
To: "edk2-devel@lists.01.org" <edk2-devel@lists.01.org>
Cc: Jordan Justen <jordan.l.justen@intel.com>,
	Laszlo Ersek <lersek@redhat.com>
Subject: Re: [PATCH v2] OvmfPkg/ResetVector: Depend on PCD values of the page tables.
Date: Thu, 3 Nov 2016 21:46:55 +0000	[thread overview]
Message-ID: <AM5PR0601MB25796A61F975087F88DDC4C980A30@AM5PR0601MB2579.eurprd06.prod.outlook.com> (raw)
In-Reply-To: <147820676171.25634.8108696649790140093@jljusten-ivb>

Hey Jordan,
Hey Laszlo,

I just pushed a v3. Changes:
* Pushed a patch to remove ResetVector.asm. As this is not really connected to the change after, I made it a separate patch rather than a series.

* Don't abstract or use the PCD size as, as Laszlo pointed out, it makes little sense, because the rest of the ASM needs to be adapter to the size change anyway, if one changes it. Do you see a way to make this dynamic too? Maybe calculate the offsets by division?
* Make clear in the comment that the PCD value is used for the address.
* Move PT_ADDR() to the ResetVector file so there is no need to abstract the Address PCD for the PageTables file.
* Include addition/subtractions after PT_ADDR() into the brackets, as suggested by Jordan.

Regards,
Marvin.

> -----Original Message-----
> From: Jordan Justen [mailto:jordan.l.justen@intel.com]
> Sent: Thursday, November 3, 2016 9:59 PM
> To: Marvin Häuser <Marvin.Haeuser@outlook.com>; edk2-
> devel@lists.01.org
> Cc: lersek@redhat.com
> Subject: Re: [PATCH v2] OvmfPkg/ResetVector: Depend on PCD values of the
> page tables.
> 
> On 2016-11-03 12:18:56, Marvin Häuser wrote:
> > Currently, the values of the page tables' address and size are
> > hard-coded in the ResetVector. This patch replaces this with a PCD
> > dependency for the NASM Reset Vector. The ASM Reset Vector remains
> > using a hard-coded value due to the lack of C preprocessing.
> >
> > Checks for the size have been added to alert the developer to rewrite
> > the ASM according to the new size, if it has been changed.
> >
> > Contributed-under: TianoCore Contribution Agreement 1.0
> > Signed-off-by: Marvin Haeuser <Marvin.Haeuser@outlook.com>
> > ---
> >  OvmfPkg/ResetVector/Ia32/PageTables64.asm | 23 ++++++++++----------
> >  OvmfPkg/ResetVector/ResetVector.inf       |  5 +++++
> >  OvmfPkg/ResetVector/ResetVector.nasmb     |  7 ++++++
> >  OvmfPkg/ResetVector/ResetVectorCode.asm   | 16 ++++++++++++++
> >  4 files changed, 39 insertions(+), 12 deletions(-)
> >
> > diff --git a/OvmfPkg/ResetVector/Ia32/PageTables64.asm
> > b/OvmfPkg/ResetVector/Ia32/PageTables64.asm
> > index b5a4cf8d7187..7ff394b1afc3 100644
> > --- a/OvmfPkg/ResetVector/Ia32/PageTables64.asm
> > +++ b/OvmfPkg/ResetVector/Ia32/PageTables64.asm
> > @@ -37,6 +37,8 @@ BITS    32
> >                         PAGE_READ_WRITE + \
> >                         PAGE_PRESENT)
> >
> > +%define PT_ADDR(Offset) (OVMF_SEC_PAGE_TABLES_BASE + (Offset))
> > +
> >
> >  ;
> >  ; Modified:  EAX, ECX
> > @@ -46,31 +48,28 @@ SetCr3ForPageTables64:
> >      ;
> >      ; For OVMF, build some initial page tables at 0x800000-0x806000.
> >      ;
> > -    ; This range should match with PcdOvmfSecPageTablesBase and
> > -    ; PcdOvmfSecPageTablesSize which are declared in the FDF files.
> > -    ;
> >      ; At the end of PEI, the pages tables will be rebuilt into a
> >      ; more permanent location by DxeIpl.
> >      ;
> >
> > -    mov     ecx, 6 * 0x1000 / 4
> > +    mov     ecx, OVMF_SEC_PAGE_TABLES_SIZE / 4
> >      xor     eax, eax
> >  clearPageTablesMemoryLoop:
> > -    mov     dword[ecx * 4 + 0x800000 - 4], eax
> > +    mov     dword[ecx * 4 + PT_ADDR (0) - 4], eax
> >      loop    clearPageTablesMemoryLoop
> >
> >      ;
> >      ; Top level Page Directory Pointers (1 * 512GB entry)
> >      ;
> > -    mov     dword[0x800000], 0x801000 + PAGE_PDP_ATTR
> > +    mov     dword[PT_ADDR (0)], PT_ADDR (0x1000) + PAGE_PDP_ATTR
> >
> >      ;
> >      ; Next level Page Directory Pointers (4 * 1GB entries => 4GB)
> >      ;
> > -    mov     dword[0x801000], 0x802000 + PAGE_PDP_ATTR
> > -    mov     dword[0x801008], 0x803000 + PAGE_PDP_ATTR
> > -    mov     dword[0x801010], 0x804000 + PAGE_PDP_ATTR
> > -    mov     dword[0x801018], 0x805000 + PAGE_PDP_ATTR
> > +    mov     dword[PT_ADDR (0x1000)], PT_ADDR (0x2000) +
> PAGE_PDP_ATTR
> > +    mov     dword[PT_ADDR (0x1008)], PT_ADDR (0x3000) +
> PAGE_PDP_ATTR
> > +    mov     dword[PT_ADDR (0x1010)], PT_ADDR (0x4000) +
> PAGE_PDP_ATTR
> > +    mov     dword[PT_ADDR (0x1018)], PT_ADDR (0x5000) +
> PAGE_PDP_ATTR
> >
> >      ;
> >      ; Page Table Entries (2048 * 2MB entries => 4GB) @@ -81,13 +80,13
> > @@ pageTableEntriesLoop:
> >      dec     eax
> >      shl     eax, 21
> >      add     eax, PAGE_2M_PDE_ATTR
> > -    mov     [ecx * 8 + 0x802000 - 8], eax
> > +    mov     [ecx * 8 + PT_ADDR (0x2000) - 8], eax
> 
> I think the '- 8' should be in the PT_ADDR.
> 
> This patch is basically
> 
> Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
> 
> except, like Laszlo pointed out, I think that ResetVectorCode.asm should
> have been deleted in 70e46f44cd13.
> 
> So, before this patch, I think we should add a patch to delete it.
> Then you won't need to modify it, and only the PCD's will be used.
> 
> Would you like to make these changes, or would you like me to?
> 
> Thanks,
> 
> -Jordan
> 
> >      loop    pageTableEntriesLoop
> >
> >      ;
> >      ; Set CR3 now that the paging structures are available
> >      ;
> > -    mov     eax, 0x800000
> > +    mov     eax, OVMF_SEC_PAGE_TABLES_BASE
> >      mov     cr3, eax
> >
> >      OneTimeCallRet SetCr3ForPageTables64 diff --git
> > a/OvmfPkg/ResetVector/ResetVector.inf
> > b/OvmfPkg/ResetVector/ResetVector.inf
> > index 46610d243ecf..d1e5d4d9bdea 100644
> > --- a/OvmfPkg/ResetVector/ResetVector.inf
> > +++ b/OvmfPkg/ResetVector/ResetVector.inf
> > @@ -29,9 +29,14 @@ [Sources]
> >    ResetVector.nasmb
> >
> >  [Packages]
> > +  OvmfPkg/OvmfPkg.dec
> >    MdePkg/MdePkg.dec
> >    UefiCpuPkg/UefiCpuPkg.dec
> >
> >  [BuildOptions]
> >     *_*_IA32_NASMB_FLAGS = -
> I$(WORKSPACE)/UefiCpuPkg/ResetVector/Vtf0/
> >     *_*_X64_NASMB_FLAGS = -
> I$(WORKSPACE)/UefiCpuPkg/ResetVector/Vtf0/
> > +
> > +[Pcd]
> > +  gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesBase
> > +  gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesSize
> > diff --git a/OvmfPkg/ResetVector/ResetVector.nasmb
> > b/OvmfPkg/ResetVector/ResetVector.nasmb
> > index 31ac06ae4a8c..62597ea95cf5 100644
> > --- a/OvmfPkg/ResetVector/ResetVector.nasmb
> > +++ b/OvmfPkg/ResetVector/ResetVector.nasmb
> > @@ -53,6 +53,13 @@
> >  %include "Ia32/SearchForSecEntry.asm"
> >
> >  %ifdef ARCH_X64
> > +  #include <AutoGen.h>
> > +  %define OVMF_SEC_PAGE_TABLES_BASE FixedPcdGet32
> > + (PcdOvmfSecPageTablesBase)  %define OVMF_SEC_PAGE_TABLES_SIZE
> > + FixedPcdGet32 (PcdOvmfSecPageTablesSize)
> > +
> > +  %if (FixedPcdGet32 (PcdOvmfSecPageTablesSize) != 0x006000)
> > +    %error "This implementation inherently depends on
> PcdOvmfSecPageTablesSize"
> > +  %endif
> >  %include "Ia32/Flat32ToFlat64.asm"
> >  %include "Ia32/PageTables64.asm"
> >  %endif
> > diff --git a/OvmfPkg/ResetVector/ResetVectorCode.asm
> > b/OvmfPkg/ResetVector/ResetVectorCode.asm
> > index 052c821f212c..1a1d92fb1415 100644
> > --- a/OvmfPkg/ResetVector/ResetVectorCode.asm
> > +++ b/OvmfPkg/ResetVector/ResetVectorCode.asm
> > @@ -40,6 +40,22 @@
> >  %include "Ia32/SearchForSecEntry.asm"
> >
> >  %ifdef ARCH_X64
> > +  ;
> > +  ; These values should match with PcdOvmfSecPageTablesBase and  ;
> > + PcdOvmfSecPageTablesSize which are declared in the FDF files.
> > +  ;
> > +
> > +  %ifndef OVMF_SEC_PAGE_TABLES_BASE
> > +    %define OVMF_SEC_PAGE_TABLES_BASE 0x800000  %endif
> > +
> > +  %ifndef OVMF_SEC_PAGE_TABLES_SIZE
> > +    %define OVMF_SEC_PAGE_TABLES_SIZE 6 * 0x1000  %endif
> > +
> > +  %if (OVMF_SEC_PAGE_TABLES_SIZE != 0x006000)
> > +    %error "This implementation inherently depends on
> OVMF_SEC_PAGE_TABLES_SIZE"
> > +  %endif
> >  %include "Ia32/Flat32ToFlat64.asm"
> >  %include "Ia32/PageTables64.asm"
> >  %endif
> > --
> > 2.10.1.windows.1
> >

  reply	other threads:[~2016-11-03 21:47 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <AM5PR0601MB25794FB82411C0C6AC2B0FF280A30@AM5PR0601MB2579.eurprd06.prod.outlook.com>
2016-11-03 20:59 ` [PATCH v2] OvmfPkg/ResetVector: Depend on PCD values of the page tables Jordan Justen
2016-11-03 21:46   ` Marvin Häuser [this message]
2016-11-03 22:55 ` Laszlo Ersek
2016-11-03 23:10   ` Jordan Justen
2016-11-03 23:19     ` Marvin Häuser
2016-11-03 23:43       ` Laszlo Ersek

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=AM5PR0601MB25796A61F975087F88DDC4C980A30@AM5PR0601MB2579.eurprd06.prod.outlook.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