📄 halkitl.c
字号:
/*
* The content of this file or document is CONFIDENTIAL and PROPRIETARY
* to Jade Technologies Co., Ltd. It is subjected to the terms of a
* License Agreement between Licensee and Jade Technologies Co., Ltd.
* restricting among other things, the use, reproduction, distribution
* and transfer. Each of the embodiments, including this information
* and any derivative work shall retain this copyright notice.
*
* Copyright (c) 2004 - 2005 Jade Technologies Co., Ltd.
* All rights reserved.
*/
// ----------------------------------------------------------------
// File: halkitl.c,v
// Revision: 1.0
// ----------------------------------------------------------------
// $
/*++
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.
Module Name:
halkitl.c
Abstract:
Platform specific code for KITL services.
NOTE: this file is included from kernel\buildexe\kitlnokd\kitlnokd.c, NOT
built as part of the hal.lib. The reason is to support dual build (KITL
and non-KITL). Once we have all the tools supporting KITL, we may
consider taking the original EDBG support out of the directory.
Functions:
Notes:
--*/
#include <windows.h>
#include <nkintr.h>
#include <kitl.h>
#include <halether.h>
#include <kitlprot.h>
#include <platform.h>
#include <drv_glob.h>
void CreateDeviceName(EDBG_ADDR *pMyAddr, char *szBuf);
static EDBG_ADDR g_MyAddr;
void InitDebugEther(HARP_BOOT_ARGS *pBootArgs)
{
// Initialize KITL transport
if( KitlInit( !(pBootArgs->ucLoaderFlags & LDRFL_KITL_PSV) ) )
{
KITLOutputDebugString ("KITL Initialized\n");
// No longer need to start kernel services
// since KITL config message told us what to start and
// kitl will start it accordingly - these are just an example
// if (gpKitl->dwBootFlags & KITL_FL_DBGMSG)
// SetKernelCommDev (KERNEL_SVC_DBGMSG, KERNEL_COMM_ETHER);
// if (gpKitl->dwBootFlags & KITL_FL_PPSH)
// SetKernelCommDev (KERNEL_SVC_PPSH, KERNEL_COMM_ETHER);
// if (gpKitl->dwBootFlags & KITL_FL_KDBG)
// SetKernelCommDev (KERNEL_SVC_KDBG, KERNEL_COMM_ETHER);
}
else
{
KITLOutputDebugString ("KITL Initialization Failed, No debugging support available\n");
}
}
BOOL InitParallelSerial (PKITLTRANSPORT pKitl)
{
return FALSE;
}
void
KitlEthEnableInts(BOOL bEnable)
{
if (bEnable)
OEMEthEnableInts();
else
OEMEthDisableInts();
}
static BOOL GetDevCfg (LPBYTE pBuf, PUSHORT pcbBuf)
{
// put our IP info in the buffer
if (*pcbBuf < sizeof (g_MyAddr)) {
return FALSE;
}
memcpy (pBuf, &g_MyAddr, sizeof (g_MyAddr));
*pcbBuf = sizeof (g_MyAddr);
return TRUE;
}
static BOOL SetHostCfg (LPBYTE pData, USHORT cbData)
{
// we automatically figure out the host address info during initial
// handshake. No need to handle host cfg data here.
return TRUE;
}
static BOOL EthSendFrame(LPBYTE pData, USHORT nLength)
{
return (OEMEthSendFrame(pData, (DWORD)nLength));
}
/* InitEther
*
* Initialize KITL Ether transport. The platform uses a SMSC 91c111 Ethernet
* controller.
*
* Return Value:
* Return TRUE if init is successful, FALSE if error.
*/
BOOL InitEther (PKITLTRANSPORT pKitl)
{
EDBG_ADAPTER adp;
DWORD dwDHCPLeaseTime;
DWORD dwSubnetMask;
KITLOutputDebugString ("+InitEther\n");
memset (&adp, 0, sizeof(adp));
memset (pKitl, 0, sizeof (KITLTRANSPORT));
// use existing code for ether initialization
if (!OEMEthInit (&adp))
return FALSE;
// we are going to completely ignore the info in bootargs and the adaptor
// info returned from OEMEthInit, except MAC address. Just to prove that
// KITL will connect standalone
// get the MAC address
g_MyAddr.wMAC[0] = adp.Addr.wMAC[0];
g_MyAddr.wMAC[1] = adp.Addr.wMAC[1];
g_MyAddr.wMAC[2] = adp.Addr.wMAC[2];
CreateDeviceName(&g_MyAddr, pKitl->szName);
KITLOutputDebugString ("Using device name: %s\n", pKitl->szName);
// If we haven't been given an IP address from our loader (or if we're not
// using static IP), get an IP address from a DHCP server.
if (adp.Addr.dwIP)
{
// Static IP or we got the IP from our bootloader...
g_MyAddr.dwIP = adp.Addr.dwIP;
dwSubnetMask = 0; // Don't care about subnet mask...
dwDHCPLeaseTime = adp.DHCPLeaseTime;
}
else
{
// Get a DHCP address...
if (!EbootGetDHCPAddr (&g_MyAddr, &dwSubnetMask, &dwDHCPLeaseTime))
return FALSE;
}
g_MyAddr.wPort = htons (EDBG_SVC_PORT);
KITLOutputDebugString ("Device %s, IP %s, Port %d\n", pKitl->szName,
inet_ntoa (g_MyAddr.dwIP), htons (g_MyAddr.wPort));
// initialize KITL Ethernet transport layer
if (!KitlEtherInit (&g_MyAddr, dwDHCPLeaseTime)) {
KITLOutputDebugString ("Unable to initialize KITL Ether transport\n");
return FALSE;
}
// fill in the blanks in KITLTRANSPORT structure.
pKitl->FrmHdrSize = KitlEtherGetFrameHdrSize ();
pKitl->Interrupt = (UCHAR) adp.SysIntrVal;
pKitl->dwPhysBuffer = EDBG_MEMORY_START;
pKitl->dwPhysBufLen = EDBG_MEMORY_SIZE; // 128K of buffer available
pKitl->dwBootFlags = 0;
pKitl->WindowSize = EDBG_WINDOW_SIZE;
pKitl->pfnDecode = KitlEtherDecodeUDP;
pKitl->pfnEncode = KitlEtherEncodeUDP;
pKitl->pfnSend = EthSendFrame;
pKitl->pfnRecv = OEMEthGetFrame;
pKitl->pfnEnableInt = KitlEthEnableInts;
pKitl->pfnSetHostCfg = SetHostCfg;
pKitl->pfnGetDevCfg = GetDevCfg;
KITLOutputDebugString ("-InitEther\n");
return TRUE;
}
/* OEMKitlInit
*
* Initialization routine - called from KitlInit() to perform platform specific
* HW init.
*
* Return Value:
* Return TRUE if init is successful, FALSE if error.
*/
BOOL OEMKitlInit (PKITLTRANSPORT pKitl)
{
KITLOutputDebugString ("+OEMKitlInit\n");
// try to find a transport available
if (!InitEther (pKitl)
&& !InitParallelSerial (pKitl)) {
KITLOutputDebugString ("Unable to initialize KITL Transports!\n");
return FALSE;
}
KITLOutputDebugString ("-OEMKitlInit\n");
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -