Home | History | Annotate | Download | only in AArch64
      1 //
      2 //  Copyright (c) 2012-2014, ARM Limited. All rights reserved.
      3 //
      4 //  This program and the accompanying materials
      5 //  are licensed and made available under the terms and conditions of the BSD License
      6 //  which accompanies this distribution.  The full text of the license may be found at
      7 //  http://opensource.org/licenses/bsd-license.php
      8 //
      9 //  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
     10 //  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
     11 //
     12 //
     13 
     14 #include <AsmMacroIoLibV8.h>
     15 #include <Base.h>
     16 #include <AutoGen.h>
     17 
     18 .text
     19 .align 3
     20 
     21 GCC_ASM_EXPORT(ArmPlatformStackSet)
     22 GCC_ASM_EXPORT(ArmPlatformStackSetPrimary)
     23 GCC_ASM_EXPORT(ArmPlatformStackSetSecondary)
     24 
     25 GCC_ASM_IMPORT(ArmPlatformIsPrimaryCore)
     26 GCC_ASM_IMPORT(ArmPlatformGetCorePosition)
     27 GCC_ASM_IMPORT(ArmPlatformGetPrimaryCoreMpId)
     28 
     29 GCC_ASM_IMPORT(gPcd_FixedAtBuild_PcdCoreCount)
     30 
     31 //VOID
     32 //ArmPlatformStackSet (
     33 //  IN UINTN StackBase,
     34 //  IN UINTN MpId,
     35 //  IN UINTN PrimaryStackSize,
     36 //  IN UINTN SecondaryStackSize
     37 //  );
     38 ASM_PFX(ArmPlatformStackSet):
     39   // Save parameters
     40   mov   x6, x3
     41   mov   x5, x2
     42   mov   x4, x1
     43   mov   x3, x0
     44 
     45   // Save the Link register
     46   mov   x7, x30
     47 
     48   // Identify Stack
     49   mov   x0, x1
     50   bl    ASM_PFX(ArmPlatformIsPrimaryCore)
     51   cmp   x0, #1
     52 
     53   // Restore parameters
     54   mov   x0, x3
     55   mov   x1, x4
     56   mov   x2, x5
     57   mov   x3, x6
     58 
     59   // Restore the Link register
     60   mov   x30, x7
     61 
     62   // Should be ASM_PFX(ArmPlatformStackSetPrimary) but generate linker error 'unsupported ELF EM_AARCH64'
     63   b.eq  ArmPlatformStackSetPrimaryL
     64   // Should be ASM_PFX(ArmPlatformStackSetSecondary) but generate linker error 'unsupported ELF EM_AARCH64'
     65   b.ne  ArmPlatformStackSetSecondaryL
     66 
     67 //VOID
     68 //ArmPlatformStackSetPrimary (
     69 //  IN UINTN StackBase,
     70 //  IN UINTN MpId,
     71 //  IN UINTN PrimaryStackSize,
     72 //  IN UINTN SecondaryStackSize
     73 //  );
     74 ArmPlatformStackSetPrimaryL:
     75 ASM_PFX(ArmPlatformStackSetPrimary):
     76   // Save the Link register
     77   mov   x4, x30
     78 
     79   // Add stack of primary stack to StackBase
     80   add   x0, x0, x2
     81 
     82   // Compute SecondaryCoresCount * SecondaryCoreStackSize
     83   LoadConstantToReg (_gPcd_FixedAtBuild_PcdCoreCount, x1)
     84   ldr   w1, [x1]
     85   sub   x1, x1, #1
     86   mul   x3, x3, x1
     87 
     88   // Set Primary Stack ((StackBase + PrimaryStackSize) + (SecondaryCoresCount * SecondaryCoreStackSize))
     89   add   sp, x0, x3
     90 
     91   br    x4
     92 
     93 //VOID
     94 //ArmPlatformStackSetSecondary (
     95 //  IN UINTN StackBase,
     96 //  IN UINTN MpId,
     97 //  IN UINTN PrimaryStackSize,
     98 //  IN UINTN SecondaryStackSize
     99 //  );
    100 ArmPlatformStackSetSecondaryL:
    101 ASM_PFX(ArmPlatformStackSetSecondary):
    102   // Save the Link register
    103   mov   x4, x30
    104   mov   sp, x0
    105 
    106   // Get Core Position
    107   mov   x0, x1
    108   bl    ASM_PFX(ArmPlatformGetCorePosition)
    109   mov   x5, x0
    110 
    111   // Get Primary Core Position
    112   bl    ASM_PFX(ArmPlatformGetPrimaryCoreMpId)
    113   bl    ASM_PFX(ArmPlatformGetCorePosition)
    114 
    115   // Get Secondary Core Position. We should get consecutive secondary stack number from 1...(CoreCount-1)
    116   cmp   x5, x0
    117   b.ls  1f
    118   // Decrement the position if after the primary core
    119   sub   x5, x5, #1
    120 1:
    121   add   x5, x5, #1
    122 
    123   // Compute top of the secondary stack
    124   mul   x3, x3, x5
    125 
    126   // Set stack
    127   add   sp, sp, x3
    128 
    129   br    x4
    130