ctxswapc.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*++
  2. Copyright (c) 2012 Minoca Corp.
  3. This file is licensed under the terms of the GNU General Public License
  4. version 3. Alternative licensing terms are available. Contact
  5. info@minocacorp.com for details. See the LICENSE file at the root of this
  6. project for complete licensing information.
  7. Module Name:
  8. ctxswapc.c
  9. Abstract:
  10. This module implements context swapping support routines.
  11. Author:
  12. Evan Green 25-Aug-2012
  13. Environment:
  14. Kernel
  15. --*/
  16. //
  17. // ------------------------------------------------------------------- Includes
  18. //
  19. #include <minoca/kernel/kernel.h>
  20. #include <minoca/kernel/arm.h>
  21. //
  22. // ---------------------------------------------------------------- Definitions
  23. //
  24. //
  25. // ----------------------------------------------- Internal Function Prototypes
  26. //
  27. //
  28. // ------------------------------------------------------ Data Type Definitions
  29. //
  30. //
  31. // -------------------------------------------------------------------- Globals
  32. //
  33. //
  34. // ------------------------------------------------------------------ Functions
  35. //
  36. VOID
  37. KepArchPrepareForContextSwap (
  38. PPROCESSOR_BLOCK ProcessorBlock,
  39. PKTHREAD CurrentThread,
  40. PKTHREAD NewThread
  41. )
  42. /*++
  43. Routine Description:
  44. This routine performs any architecture specific work before context swapping
  45. between threads. This must be called at dispatch level.
  46. Arguments:
  47. ProcessorBlock - Supplies a pointer to the processor block of the current
  48. processor.
  49. CurrentThread - Supplies a pointer to the current (old) thread.
  50. NewThread - Supplies a pointer to the thread that's about to be switched to.
  51. Return Value:
  52. None.
  53. --*/
  54. {
  55. PULONG StorageAddress;
  56. ASSERT((KeGetRunLevel() == RunLevelDispatch) ||
  57. (ArAreInterruptsEnabled() == FALSE));
  58. //
  59. // Store the user read/write thread pointer in the upper 32-bits.
  60. //
  61. StorageAddress = ((PULONG)&(CurrentThread->ThreadPointer)) + 1;
  62. *StorageAddress = ArGetThreadPointerUser();
  63. //
  64. // If the thread is using the FPU, save it. Some FPU state (d8-d15) must be
  65. // preserved across function calls, so the FPU state cannot be abandoned by
  66. // virtue of simply being in a system call.
  67. //
  68. if ((CurrentThread->FpuFlags & THREAD_FPU_FLAG_IN_USE) != 0) {
  69. //
  70. // The FPU context could be NULL if a thread got context swapped while
  71. // terminating.
  72. //
  73. if (CurrentThread->FpuContext != NULL) {
  74. //
  75. // Save the FPU state if it was used this iteration. A thread may
  76. // be using the FPU in general but not have used it for its
  77. // duration on this processor, so it would be bad to save in that
  78. // case.
  79. //
  80. if ((CurrentThread->FpuFlags & THREAD_FPU_FLAG_OWNER) != 0) {
  81. ArSaveFpuState(CurrentThread->FpuContext);
  82. }
  83. }
  84. CurrentThread->FpuFlags &= ~THREAD_FPU_FLAG_OWNER;
  85. ArDisableFpu();
  86. }
  87. return;
  88. }
  89. //
  90. // --------------------------------------------------------- Internal Functions
  91. //