📄 ether.c
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES OR INDEMNITIES.
//
//------------------------------------------------------------------------------
//
// File: ether.c
//
// Core Ethernet routines for the Intel Mainstone II bootloader.
//
//------------------------------------------------------------------------------
/*
** Copyright 2000-2003 Intel Corporation All Rights Reserved.
**
** Portions of the source code contained or described herein and all documents
** related to such source code (Material) are owned by Intel Corporation
** or its suppliers or licensors and is licensed by Microsoft Corporation for distribution.
** Title to the Material remains with Intel Corporation or its suppliers and licensors.
** Use of the Materials is subject to the terms of the Microsoft license agreement which accompanied the Materials.
** No other license under any patent, copyright, trade secret or other intellectual
** property right is granted to or conferred upon you by disclosure or
** delivery of the Materials, either expressly, by implication, inducement,
** estoppel or otherwise
** Some portion of the Materials may be copyrighted by Microsoft Corporation.
*/
#include <windows.h>
#include <bulverde.h>
#include <plato.h>
#include <ethdbg.h>
#include <ndis.h>
#include <rndismini.h>
#include <mddpriv.h>
#include <halether.h>
#include <oal_memory.h>
#include <oal_ethdrv.h>
#include <ceddk.h>
#include "loader.h"
#include "wait.h"
// Global variables.
//
extern EBOOT_CFG g_EbootCFG;
// Miscellaneous definitions.
//
#define OSCR_OFFSET 0x10 // OSCR0
// Function pointers to the support library functions of the currently installed debug ethernet controller.
//
PFN_EDBG_INIT pfnEDbgInit;
PFN_EDBG_GET_FRAME pfnEDbgGetFrame;
PFN_EDBG_SEND_FRAME pfnEDbgSendFrame;
PFN_EDBG_ENABLE_INTS pfnEDbgEnableInts;
PFN_EDBG_DISABLE_INTS pfnEDbgDisableInts;
PFN_EDBG_GET_PENDING_INTS pfnEDbgGetPendingInts;
PFN_EDBG_READ_EEPROM pfnEDbgReadEEPROM;
PFN_EDBG_WRITE_EEPROM pfnEDbgWriteEEPROM;
PFN_EDBG_SET_OPTIONS pfnEDbgSetOptions;
#ifdef IMGSHAREETH
PFN_EDBG_CURRENT_PACKET_FILTER pfnCurrentPacketFilter;
PFN_EDBG_MULTICAST_LIST pfnMulticastList;
#endif
VOID OALStall(UINT32 microSeconds)
{
Wait(microSeconds);
}
// EthDevice == 0 --> Try to initialize RNDIS
UINT32 InitSpecifiedEthDevice(OAL_KITL_ARGS *pKITLArgs, UINT32 EthDevice)
{
UINT32 EbootDeviceAddress = 0;
UINT8 *pAttribute = NULL;
UINT32 SlotAddress = 0;
// This boot loader supports only ETH_DEVICE_USB
//
KITLOutputDebugString("\r\nINFO: Trying to initialize the USB for Eth...\r\n");
if (EthDevice == ETH_DEVICE_USB)
{
// Set address
EbootDeviceAddress = (UINT32)OALPAtoVA(BULVERDE_BASE_REG_PA_UDC, FALSE); // Base Address for USB Client
pKITLArgs->mac[0] = g_EbootCFG.RNDISMac[0];
pKITLArgs->mac[1] = g_EbootCFG.RNDISMac[1];
pKITLArgs->mac[2] = g_EbootCFG.RNDISMac[2];
// init USB registers
if (HostMiniInit((PCHAR) NULL, 1, pKITLArgs->mac))
{
pfnEDbgInit = RndisInit;
pfnEDbgEnableInts = RndisEnableInts;
pfnEDbgDisableInts = RndisDisableInts;
pfnEDbgGetFrame = RndisEDbgGetFrame;
pfnEDbgSendFrame = RndisEDbgSendFrame;
pfnEDbgReadEEPROM = NULL;
pfnEDbgWriteEEPROM = NULL;
pfnEDbgGetPendingInts = RndisGetPendingInts;
pfnEDbgSetOptions = RndisSetOptions;
#ifdef IMGSHAREETH
pfnCurrentPacketFilter = RndisCurrentPacketFilter;
pfnMulticastList = RndisMulticastList;
#endif
// Save the device location information for later use.
//
pKITLArgs->devLoc.IfcType = InterfaceTypeUndefined;
pKITLArgs->devLoc.BusNumber = 0;
pKITLArgs->devLoc.PhysicalLoc = 0;
pKITLArgs->devLoc.LogicalLoc = 0;
KITLOutputDebugString("Bulverde Rndis USB Ethernet controller initialized.\n");
return (EDBG_USB_RNDIS);
}
else
{
KITLOutputDebugString("ERROR: Failed to initialize Bulverde Rndis USB Ethernet controller.\n");
}
}
return (-1);
}
BOOL OEMEthGetFrame(BYTE *pData, // OUT - Receives frame data
UINT16 *pwLength) // IN - Length of Rx buffer
{
return (pfnEDbgGetFrame(pData, pwLength));
}
BOOL OEMEthSendFrame(BYTE *pData, // IN - Data buffer
DWORD dwLength) // IN - Length of buffer
{
int retries = 0;
// Let's be persistant here
while (retries++ < 4)
{
if (!pfnEDbgSendFrame(pData, dwLength))
return (TRUE);
KITLOutputDebugString("!OEMEthSendFrame failure, retry %u\n",retries);
}
return (FALSE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -