Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

192 lines
4.3 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. ixenvirv.c
  5. Abstract:
  6. This module implements the HAL get and set environment variable routines
  7. for a x86 system.
  8. Note that this particular implementation only supports the LastKnownGood
  9. environment variable. This is done by using the Daylight Savings Time
  10. bit in the Real Time Clock NVRAM. (Not pretty, but it's all we've got)
  11. Attempts to read or write any environment variable other than
  12. LastKnownGood will fail.
  13. Author:
  14. John Vert (jvert) 22-Apr-1992
  15. Environment:
  16. Kernel mode
  17. Revision History:
  18. --*/
  19. #include "halp.h"
  20. #include "arc.h"
  21. #include "arccodes.h"
  22. #include "string.h"
  23. #define CMOS_CONTROL_PORT ((PUCHAR)0x70)
  24. #define CMOS_DATA_PORT ((PUCHAR)0x71)
  25. #define CMOS_STATUS_B 0x0B
  26. #define CMOS_DAYLIGHT_BIT 1
  27. const UCHAR LastKnownGood[] = "LastKnownGood";
  28. const UCHAR True[] = "TRUE";
  29. const UCHAR False[] = "FALSE";
  30. ARC_STATUS
  31. HalGetEnvironmentVariable (
  32. IN PCHAR Variable,
  33. IN USHORT Length,
  34. OUT PCHAR Buffer
  35. )
  36. /*++
  37. Routine Description:
  38. This function locates an environment variable and returns its value.
  39. The only environment variable this implementation supports is
  40. "LastKnownGood" It uses the Daylight Savings Time bit in the Real
  41. TimeClock to indicate the state (TRUE/FALSE only) of this environment
  42. variable.
  43. Arguments:
  44. Variable - Supplies a pointer to a zero terminated environment variable
  45. name.
  46. Length - Supplies the length of the value buffer in bytes.
  47. Buffer - Supplies a pointer to a buffer that receives the variable value.
  48. Return Value:
  49. ESUCCESS is returned if the enviroment variable is located. Otherwise,
  50. ENOENT is returned.
  51. --*/
  52. {
  53. UCHAR StatusByte;
  54. UNREFERENCED_PARAMETER( Length );
  55. UNREFERENCED_PARAMETER( Buffer );
  56. if (_stricmp(Variable, LastKnownGood) != 0) {
  57. return ENOENT;
  58. }
  59. //
  60. // Read the Daylight Savings Bit out of the RTC to determine whether
  61. // the LastKnownGood environment variable is TRUE or FALSE.
  62. //
  63. HalpAcquireCmosSpinLock();
  64. WRITE_PORT_UCHAR(CMOS_CONTROL_PORT, CMOS_STATUS_B);
  65. StatusByte = READ_PORT_UCHAR(CMOS_DATA_PORT);
  66. HalpReleaseCmosSpinLock ();
  67. if (StatusByte & CMOS_DAYLIGHT_BIT) {
  68. strncpy(Buffer, True, Length);
  69. } else {
  70. strncpy(Buffer, False, Length);
  71. }
  72. return ESUCCESS;
  73. }
  74. ARC_STATUS
  75. HalSetEnvironmentVariable (
  76. IN PCHAR Variable,
  77. IN PCHAR Value
  78. )
  79. /*++
  80. Routine Description:
  81. This function creates an environment variable with the specified value.
  82. The only environment variable this implementation supports is
  83. "LastKnownGood" It uses the Daylight Savings Time bit in the Real
  84. TimeClock to indicate the state (TRUE/FALSE only) of this environment
  85. variable.
  86. Arguments:
  87. Variable - Supplies a pointer to an environment variable name.
  88. Value - Supplies a pointer to the environment variable value.
  89. Return Value:
  90. ESUCCESS is returned if the environment variable is created. Otherwise,
  91. ENOMEM is returned.
  92. --*/
  93. {
  94. UCHAR StatusByte;
  95. if (_stricmp(Variable, LastKnownGood) != 0) {
  96. return ENOMEM;
  97. }
  98. if (_stricmp(Value, True) == 0) {
  99. HalpAcquireCmosSpinLock();
  100. //
  101. // Turn Daylight Savings Bit on.
  102. //
  103. WRITE_PORT_UCHAR(CMOS_CONTROL_PORT, CMOS_STATUS_B);
  104. StatusByte = READ_PORT_UCHAR(CMOS_DATA_PORT);
  105. StatusByte |= CMOS_DAYLIGHT_BIT;
  106. WRITE_PORT_UCHAR(CMOS_CONTROL_PORT, CMOS_STATUS_B);
  107. WRITE_PORT_UCHAR(CMOS_DATA_PORT, StatusByte);
  108. HalpReleaseCmosSpinLock();
  109. } else if (_stricmp(Value, False) == 0) {
  110. HalpAcquireCmosSpinLock();
  111. //
  112. // Turn Daylight Savings Bit off.
  113. //
  114. WRITE_PORT_UCHAR(CMOS_CONTROL_PORT, CMOS_STATUS_B);
  115. StatusByte = READ_PORT_UCHAR(CMOS_DATA_PORT);
  116. StatusByte &= ~CMOS_DAYLIGHT_BIT;
  117. WRITE_PORT_UCHAR(CMOS_CONTROL_PORT, CMOS_STATUS_B);
  118. WRITE_PORT_UCHAR(CMOS_DATA_PORT, StatusByte);
  119. HalpReleaseCmosSpinLock();
  120. } else {
  121. return(ENOMEM);
  122. }
  123. return ESUCCESS;
  124. }