Source code of Windows XP (NT5)
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.

215 lines
5.3 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. rom.c
  5. Abstract:
  6. Boot loader ROM routines.
  7. Author:
  8. Chuck Lenzmeier (chuckl) December 27, 1996
  9. Revision History:
  10. Notes:
  11. --*/
  12. #include "precomp.h"
  13. #pragma hdrstop
  14. #include <udp_api.h>
  15. #include <tftp_api.h>
  16. #include "bldr.h"
  17. #include "efi.h"
  18. #include "efip.h"
  19. #include "bldria64.h"
  20. #include "extern.h"
  21. //
  22. // We'll use this to keep track of which port we're communicating through.
  23. //
  24. EFI_PXE_BASE_CODE_UDP_PORT MachineLocalPort = 2000;
  25. #define STALL_TIME (40000)
  26. extern VOID
  27. FwStallExecution(
  28. IN ULONG Microseconds
  29. );
  30. VOID
  31. RomSetReceiveStatus (
  32. IN USHORT UnicastUdpDestinationPort
  33. #if 0
  34. ,
  35. IN USHORT MulticastUdpDestinationPort,
  36. IN ULONG MulticastUdpDestinationAddress,
  37. IN USHORT MulticastUdpSourcePort,
  38. IN ULONG MulticastUdpSourceAddress
  39. #endif
  40. )
  41. {
  42. return;
  43. } // RomSetReceiveStatus
  44. ULONG
  45. RomSendUdpPacket (
  46. IN PVOID Buffer,
  47. IN ULONG Length,
  48. IN ULONG RemoteHost,
  49. IN USHORT pServerPort
  50. )
  51. {
  52. EFI_STATUS EfiStatus = EFI_SUCCESS;
  53. EFI_IP_ADDRESS DestinationIpAddress;
  54. INTN Count = 0;
  55. EFI_PXE_BASE_CODE_UDP_PORT ServerPort = pServerPort;
  56. UINTN BufferLength = Length;
  57. PVOID MyBuffer = NULL;
  58. //
  59. // Get the server's EFI_IP_ADDRESS from the handle to the PXE base code.
  60. //
  61. for( Count = 0; Count < 4; Count++ ) {
  62. DestinationIpAddress.v4.Addr[Count] = PXEClient->Mode->ProxyOffer.Dhcpv4.BootpSiAddr[Count];
  63. }
  64. FlipToPhysical();
  65. //
  66. // Make sure the address is a physical address, then do the UdpWrite.
  67. //
  68. MyBuffer = (PVOID)((ULONG_PTR)Buffer & ~KSEG0_BASE);
  69. EfiStatus = PXEClient->UdpWrite( PXEClient,
  70. 0,
  71. &DestinationIpAddress,
  72. &ServerPort,
  73. NULL,
  74. NULL,
  75. &MachineLocalPort,
  76. NULL,
  77. NULL,
  78. &BufferLength,
  79. MyBuffer );
  80. //
  81. // This is really gross, but on retail builds with no debugger, EFI will go
  82. // off in the weeds unless we slow down transactions over the network. So
  83. // after Udp operations, take a short nap.
  84. //
  85. FwStallExecution( STALL_TIME );
  86. FlipToVirtual();
  87. if( EfiStatus != EFI_SUCCESS ) {
  88. if( BdDebuggerEnabled ) {
  89. DbgPrint( "RomSendUdpPacket: UdpWrite failed. MachineLocalPort: %d ServerPort: %d (%d)\r\n", MachineLocalPort, ServerPort, EfiStatus );
  90. }
  91. return 0;
  92. }
  93. return Length;
  94. } // RomSendUdpPacket
  95. ULONG
  96. RomReceiveUdpPacket (
  97. IN PVOID Buffer,
  98. IN ULONG Length,
  99. IN ULONG Timeout,
  100. IN OUT PULONG RemoteHost,
  101. IN OUT PUSHORT LocalPort
  102. )
  103. {
  104. EFI_STATUS EfiStatus = EFI_SUCCESS;
  105. UINTN BufferLength = Length;
  106. EFI_IP_ADDRESS ServerIpAddress;
  107. EFI_IP_ADDRESS MyIpAddress;
  108. INTN Count = 0;
  109. EFI_PXE_BASE_CODE_UDP_PORT ServerPort = (EFI_PXE_BASE_CODE_UDP_PORT)(0xFAB); // hardcode to 4011
  110. PVOID MyBuffer = NULL;
  111. //
  112. // Get The server's EFI_IP_ADDRESS from the handle to the PXE base code.
  113. //
  114. for( Count = 0; Count < 4; Count++ ) {
  115. ServerIpAddress.v4.Addr[Count] = PXEClient->Mode->ProxyOffer.Dhcpv4.BootpSiAddr[Count];
  116. }
  117. //
  118. // Get our EFI_IP_ADDRESS from the handle to the PXE base code.
  119. //
  120. for( Count = 0; Count < 4; Count++ ) {
  121. MyIpAddress.v4.Addr[Count] = PXEClient->Mode->StationIp.v4.Addr[Count];
  122. }
  123. FlipToPhysical();
  124. //
  125. // Make sure the address is a physical address, then do the UdpWrite.
  126. //
  127. MyBuffer = (PVOID)((ULONG_PTR)Buffer & ~KSEG0_BASE);
  128. EfiStatus = PXEClient->UdpRead( PXEClient,
  129. 0,
  130. &MyIpAddress,
  131. &MachineLocalPort,
  132. &ServerIpAddress,
  133. &ServerPort,
  134. NULL, // &HeaderLength
  135. NULL, // HeaderBuffer
  136. &BufferLength,
  137. MyBuffer );
  138. //
  139. // This is really gross, but on retail builds with no debugger, EFI will go
  140. // off in the weeds unless we slow down transactions over the network. So
  141. // after Udp operations, take a short nap.
  142. //
  143. FwStallExecution( STALL_TIME );
  144. FlipToVirtual();
  145. if( EfiStatus != EFI_SUCCESS ) {
  146. if( BdDebuggerEnabled ) {
  147. DbgPrint( "RomReceiveUdpPacket: UdpRead failed. MachineLocalPort: %d ServerPort: %d (%d)\r\n", MachineLocalPort, ServerPort, EfiStatus );
  148. }
  149. return 0;
  150. }
  151. return Length;
  152. } // RomReceiveUdpPacket
  153. ULONG
  154. RomGetNicType (
  155. OUT t_PXENV_UNDI_GET_NIC_TYPE *NicType
  156. )
  157. {
  158. return 0;
  159. }