]> git.proxmox.com Git - mirror_edk2.git/blobdiff - UnixPkg/Sec/UnixThunk.c
Add special treatment for EFI_PCI_IO_ATTRIBUTE_EMBEDDED_DEVICE and EFI_PCI_IO_ATTRIBU...
[mirror_edk2.git] / UnixPkg / Sec / UnixThunk.c
index 6c9bb74ce0dcd6e2073c6693ce46256f4d8b9557..f65acab10062c09b096c32af622eeeb83a2fb2f6 100644 (file)
@@ -1,7 +1,7 @@
 /*++
 
 Copyright (c) 2004 - 2009, Intel Corporation. All rights reserved.<BR>
-Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
+Portions copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
 This program and the accompanying materials                          
 are licensed and made available under the terms and conditions of the BSD License         
 which accompanies this distribution.  The full text of the license may be found at        
@@ -36,7 +36,7 @@ Abstract:
 #include "Uefi.h"
 #include "Library/UnixLib.h"
 
-#ifdef __APPLE__
+#if defined(__APPLE__) || defined(MDE_CPU_X64)
 #include "Gasket.h"
 #endif
 
@@ -44,6 +44,9 @@ int settimer_initialized;
 struct timeval settimer_timeval;
 void (*settimer_callback)(UINT64 delta);
 
+BOOLEAN gEmulatorInterruptEnabled = FALSE;
+
+
 void
 settimer_handler (int sig)
 {
@@ -57,10 +60,10 @@ settimer_handler (int sig)
   settimer_timeval = timeval;
   
   if (settimer_callback) {
-#ifdef __APPLE__
+#if defined(__APPLE__) || defined(MDE_CPU_X64)
    ReverseGasketUint64 (settimer_callback, delta);
 #else
-   (*settimer_callback)(delta);
+    (*settimer_callback)(delta);
 #endif
   }
 }
@@ -78,6 +81,7 @@ SetTimer (UINT64 PeriodMs, VOID (*CallBack)(UINT64 DeltaMs))
     act.sa_handler = settimer_handler;
     act.sa_flags = 0;
     sigemptyset (&act.sa_mask);
+    gEmulatorInterruptEnabled = TRUE;
     if (sigaction (SIGALRM, &act, NULL) != 0) {
       printf ("SetTimer: sigaction error %s\n", strerror (errno));
     }
@@ -97,6 +101,43 @@ SetTimer (UINT64 PeriodMs, VOID (*CallBack)(UINT64 DeltaMs))
   settimer_callback = CallBack;
 }
 
+
+void
+UnixEnableInterrupt (void)
+{
+  sigset_t  sigset;
+
+  gEmulatorInterruptEnabled = TRUE;
+  // Since SetTimer() uses SIGALRM we emulate turning on and off interrupts 
+  // by enabling/disabling SIGALRM.
+  sigemptyset (&sigset);
+  sigaddset (&sigset, SIGALRM);
+  sigprocmask (SIG_UNBLOCK, &sigset, NULL);
+}
+
+
+void
+UnixDisableInterrupt (void)
+{
+  sigset_t  sigset;
+
+  // Since SetTimer() uses SIGALRM we emulate turning on and off interrupts 
+  // by enabling/disabling SIGALRM.
+  sigemptyset (&sigset);
+  sigaddset (&sigset, SIGALRM);
+  sigprocmask (SIG_BLOCK, &sigset, NULL);
+  gEmulatorInterruptEnabled = FALSE;
+}
+
+
+BOOLEAN
+UnixInterruptEanbled (void)
+{
+  return gEmulatorInterruptEnabled;
+}
+
+
+
 void
 msSleep (unsigned long Milliseconds)
 {
@@ -111,7 +152,7 @@ msSleep (unsigned long Milliseconds)
     }
     rq = rm;
   } 
-    
+
 }
 
 void
@@ -171,7 +212,7 @@ UgaCreate(struct _EFI_UNIX_UGA_IO_PROTOCOL **UgaIo, CONST CHAR16 *Title);
 
 EFI_UNIX_THUNK_PROTOCOL mUnixThunkTable = {
   EFI_UNIX_THUNK_PROTOCOL_SIGNATURE,
-#ifdef __APPLE__
+#if defined(__APPLE__) || defined(MDE_CPU_X64)
 //
 // Mac OS X requires the stack to be 16-byte aligned for IA-32. So on an OS X build
 // we add an assembly wrapper that makes sure the stack ges aligned. 
@@ -219,7 +260,14 @@ EFI_UNIX_THUNK_PROTOCOL mUnixThunkTable = {
   Gaskettcsetattr,
   GasketUnixPeCoffGetEntryPoint,                
   GasketUnixPeCoffRelocateImageExtraAction,     
-  GasketUnixPeCoffUnloadImageExtraAction  
+  GasketUnixPeCoffUnloadImageExtraAction,  
+  
+  GasketUnixEnableInterrupt,
+  GasketUnixDisableInterrupt,
+
+  Gasketgetifaddrs,
+  Gasketfreeifaddrs,
+  Gasketsocket,
 
 #else
   msSleep, /* Sleep */
@@ -263,7 +311,12 @@ EFI_UNIX_THUNK_PROTOCOL mUnixThunkTable = {
   tcsetattr,
   SecPeCoffGetEntryPoint,
   SecPeCoffRelocateImageExtraAction,
-  SecPeCoffLoaderUnloadImageExtraAction
+  SecPeCoffLoaderUnloadImageExtraAction,
+  UnixEnableInterrupt,
+  UnixDisableInterrupt,
+  getifaddrs,
+  freeifaddrs,
+  socket
 #endif
 };