github.com/jlmucb/cloudproxy@v0.0.0-20170830161738-b5aa0b619bc4/cpvmm/vmm/bootstrap/bootstrap_startap.c (about)

     1  /*
     2   * Copyright (c) 2013 Intel Corporation
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *     http://www.apache.org/licenses/LICENSE-2.0
     8   * Unless required by applicable law or agreed to in writing, software
     9   * distributed under the License is distributed on an "AS IS" BASIS,
    10   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    11   * See the License for the specific language governing permissions and
    12   * limitations under the License.
    13   */
    14  
    15  
    16  #include "bootstrap_types.h"
    17  #include "bootstrap_print.h"
    18  #include "vmm_defs.h"
    19  #include "x32_init64.h"
    20  #include "bootstrap_ap_procs_init.h"
    21  #include "vmm_startup.h"
    22  
    23  #define JLMDEBUG
    24  
    25  
    26  typedef void (*LVMM_IMAGE_ENTRY_POINT) (uint32_t local_apic_id, 
    27                     void* any_data1, void* any_data2, void* any_data3); 
    28  
    29  typedef struct {
    30      void*           any_data1;
    31      void*           any_data2;
    32      void*           any_data3;
    33      UINT64          ep;
    34  } APPLICATION_PARAMS_STRUCT;
    35  
    36  static APPLICATION_PARAMS_STRUCT application_params;
    37  static INIT64_STRUCT *gp_init64= NULL;
    38  
    39  void start_application(uint32_t cpu_id, const APPLICATION_PARAMS_STRUCT *params);
    40  extern uint32_t evmm_stack_pointers_array[];  // stack pointers
    41  
    42  
    43  void startap_main(INIT32_STRUCT *p_init32, INIT64_STRUCT *p_init64,
    44                     VMM_STARTUP_STRUCT *p_startup, uint32_t entry_point)
    45  {
    46  #ifdef JLMDEBUG
    47      bprint("startap_main %p %u\n", p_startup, entry_point);
    48  #endif
    49      uint32_t application_processors;
    50      
    51      if(NULL!=p_init32) {
    52          // wakeup APs
    53          application_processors = ap_procs_startup(p_init32, p_startup);
    54      }
    55      else {
    56          application_processors = 0;
    57      }
    58  #ifdef JLMDEBUG
    59      bprint("back from ap_procs_startup\n");
    60  #endif
    61  
    62  #ifdef UNIPROC
    63      application_processors = 0;
    64  #endif
    65      gp_init64 = p_init64;
    66  
    67      if (BITMAP_GET(p_startup->flags, VMM_STARTUP_POST_OS_LAUNCH_MODE)==0) {
    68          // update the number of processors in VMM_STARTUP_STRUCT for pre os launch
    69          p_startup->number_of_processors_at_boot_time = application_processors+1;
    70      }
    71  
    72      application_params.ep = entry_point;
    73      application_params.any_data1 = (void*) p_startup;
    74      application_params.any_data2 = NULL;
    75      application_params.any_data3 = NULL;
    76  
    77  #ifdef JLMDEBUG
    78      bprint("startap_main %d application processors\n", application_processors);
    79  #endif
    80      // first launch application on AP cores
    81      if (application_processors>0) {
    82          ap_procs_run((FUNC_CONTINUE_AP_BOOT)start_application, &application_params);
    83      }
    84      // launch application on BSP
    85      // JLM: this is already done in bootstrap_entry
    86      // start_application(0, &application_params);
    87  #ifdef JLMDEBUG
    88      bprint("returning from startap_main\n");
    89  #endif
    90  }
    91  
    92  extern void init64_on_aps(uint32_t stack_pointer, INIT64_STRUCT *p_init64_data,
    93                      uint32_t start_address, uint32_t cpu_id);
    94  
    95  
    96  
    97  void start_application(uint32_t cpu_id, 
    98                    const APPLICATION_PARAMS_STRUCT *params)
    99  {
   100  #ifdef JLMDEBUG
   101      bprint("startap_application, cpu: %d, gp_init64: %p\n", cpu_id, gp_init64);
   102  #endif
   103      // JLM: stack pointers were set elsewhere
   104      uint32_t  stack_pointer= evmm_stack_pointers_array[cpu_id];
   105  
   106      if (NULL==gp_init64) {
   107          ((LVMM_IMAGE_ENTRY_POINT)((uint32_t)params->ep))
   108              (cpu_id, params->any_data1, params->any_data2, params->any_data3);
   109      }
   110      else {
   111          init64_on_aps(stack_pointer, gp_init64, (uint32_t)params->ep, cpu_id);
   112      }
   113  }
   114