Windows NT 4.0 source code leak
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.0 KiB

4 years ago
  1. //#pragma comment(exestr, "$Header: /usr4/winnt/SOURCES/ddk35/src/hal/halsni/mips/RCS/jxenvirv.c,v 1.1 1994/10/13 15:47:06 holli Exp $")
  2. /*++
  3. Copyright (c) 1991 Microsoft Corporation
  4. Copyright (c) 1993 Siemens Nixdorf Informationssyteme AG
  5. Module Name:
  6. jxenvirv.c
  7. Abstract:
  8. This module implements the HAL get and set environment variable routines
  9. for a MIPS system.
  10. Environment:
  11. Kernel mode
  12. NOTES:
  13. --- Preliminary using ARC function calls ---
  14. --*/
  15. #include "halp.h"
  16. #include "arccodes.h"
  17. #include "arc.h"
  18. // preliminary calls to the ARC functions (function vector call)
  19. /* NOTE:
  20. This is strongly discouraged by the ARC specifications.
  21. Only "reset"/return calls to the prom are recommended.
  22. All other system access to the NVRAM should be handled
  23. by operating systems functions directly. For that the
  24. operating system has to know the algorithms for handling
  25. those data structures (e.g. the checksum calculations).
  26. Though is a drawback in terms of HW/FW-independance NT
  27. seems to avoid side effects of ARC function code that way,
  28. e.g. via register/stack manipulations.
  29. */
  30. //
  31. // The following addresses are defined by ARC and handed over to the osloader.
  32. // For now we assume that the osloader will leave this memory part unchanged
  33. // for the operating system (NT), which itself also doesn't overwrite that
  34. // data structure.
  35. // We don't (yet) know yet know whether the firmware copies or maps/banks
  36. // runnable code into the physical memory (or if it just sets up a vector
  37. // into the prom). We also do not know whether the NVRAM variables are copied
  38. // into physical memory or mapped/banked by the (ARC) firmware.
  39. //
  40. //
  41. // Therefore we preliminary use the ARC entry vectors from ARC.H
  42. //
  43. ARC_STATUS
  44. HalGetEnvironmentVariable (
  45. IN PCHAR Variable,
  46. IN USHORT Length,
  47. OUT PCHAR Buffer
  48. )
  49. /*++
  50. Routine Description:
  51. This function locates an environment variable and returns its value.
  52. Arguments:
  53. Variable - Supplies a pointer to a zero terminated environment variable
  54. name.
  55. Length - Supplies the length of the value buffer in bytes.
  56. Buffer - Supplies a pointer to a buffer that receives the variable value.
  57. Return Value:
  58. ESUCCESS is returned if the enviroment variable is located. Otherwise,
  59. ENOENT is returned.
  60. NOTE:
  61. This implementation returns the error code ENOMEM if the output buffer
  62. is too small.
  63. --*/
  64. {
  65. PUCHAR Environment_var;
  66. ULONG Index;
  67. ARC_STATUS Status;
  68. //
  69. // retrieve the variable
  70. //
  71. Environment_var = (PUCHAR)ArcGetEnvironmentVariable(Variable);
  72. if (Environment_var == (PUCHAR)NULL) {
  73. Status = ENOENT;
  74. } else {
  75. //
  76. // Copy the specified value to the output buffer.
  77. //
  78. for (Index = 0; Index < Length; Index += 1) {
  79. *Buffer = READ_REGISTER_UCHAR(Environment_var);
  80. if (*Buffer == 0) {
  81. break;
  82. }
  83. Buffer += 1;
  84. Environment_var += 1;
  85. }
  86. //
  87. // If the length terminated the loop, then return not enough memory.
  88. // Otherwise, return success.
  89. //
  90. if (Index == Length) {
  91. Status = ENOMEM;
  92. } else {
  93. Status = ESUCCESS;
  94. }
  95. }
  96. return Status;
  97. }
  98. ARC_STATUS
  99. HalSetEnvironmentVariable (
  100. IN PCHAR Variable,
  101. IN PCHAR Value
  102. )
  103. /*++
  104. Routine Description:
  105. This function creates an environment variable with the specified value.
  106. Arguments:
  107. Variable - Supplies a pointer to an environment variable name.
  108. Value - Supplies a pointer to the environment variable value.
  109. Return Value:
  110. ESUCCESS is returned if the environment variable is created. Otherwise,
  111. ENOMEM is returned.
  112. NOTES:
  113. This preliminary implementation always returns ESUCCESS even in case of
  114. error.
  115. --*/
  116. {
  117. ARC_STATUS Status;
  118. Status = ArcSetEnvironmentVariable(Variable, Value);
  119. switch (Status) {
  120. case ESUCCESS:
  121. break;
  122. case ENOSPC:
  123. break; // until further we assume NT can handle that
  124. case ENOMEM:
  125. default:
  126. Status = ENOMEM;
  127. break;
  128. }
  129. return Status;
  130. }