usrWdb.c
上传用户:luoyougen
上传日期:2008-05-12
资源大小:23136k
文件大小:44k
源码类别:

VxWorks

开发平台:

C/C++

  1. /* usrWdb.c - configuration file for the WDB agent */
  2. /* Copyright 1994-2002 Wind River Systems, Inc. */
  3. /*
  4. modification history
  5. --------------------
  6. 03q,07jun02,g_h  SPR#78283, rename call fron wdbTmdPktDevInit() to
  7.                  wdbVisionPktDevInit() in wdbCommIfInit()
  8. 03p,31mar02,jkf  SPR#74251, using bootLib.h macros for array sizes
  9. 03o,21mar02,jhw  Remove network initialization calls. (SPR 73517)
  10. 03n,13mar02,j_s  return error if end device table is empty (SPR 73604)
  11. 03m,21dec01,g_h  Change the name of the files that include for the TMD to
  12.                  follow the WR naming convention
  13. 03l,06dec01,kab  SPR 71985: Fixed test of wdbTgtHasAltivec()
  14. 03k,93dec01,g_h  Adding command line support for Transparent Mode Driver.
  15. 03j,21nov01,jhw  Get WDB END device from sysBootParams (SPR 71595). 
  16.  Remove diab compiler warnings in wdbConfig.
  17.  Move wdbInfo back into WIND_TCB.
  18. 03i,20oct01,jhw  Moved wdbExitHook out of WIND_TCB.
  19. 03h,04oct01,c_c  Added wdbToolName symbol.
  20. 03g,06jun01,pch  Fix length of copy to vxBootFile.
  21. 03f,22may01,kab  Removed spurious warning message
  22. 03e,16may01,pch  Fix "`wdbTgtHasAltivec' defined but not used" message when
  23.                  building non-AltiVec BSP's.
  24. 03d,09may01,dtr  Addition of wdbTgtHasCoprocessor.
  25. 03c,05feb01,zl   merged NPT
  26. 03b,10nov00,zl   fixed code causing warnings.
  27. 03a,03mar00,zl   merged SH support into T2.
  28. 03o,12apr01,pch  Add comments to various #else & #endif
  29. 03n,30mar01,pcs  Putting wdbTgtHasAltivec to replace OK/ERROR with TRUE/FALSE.
  30. 03m,26mar01,pcs  Remove the erronous commenting of the following line
  31.                  "pAltivecRegs = wdbAltivecLibInit();"
  32. 03l,19mar01,tpw  Rename WDB_REG_SET_ALTIVEC to WDB_REG_SET_AV for consistency
  33.                  with WTX and other REG_SET names.
  34. 03k,15mar01,pcs  Change include filename altiVecLib.h to altivecLib.h
  35. 03j,07feb01,dtr  Addition of hasAltivec to RtInfoGet.
  36. 03i,30jan01,dtr  Adding altivec register support.
  37. 03h,19dec00,pai  Included (uncommented) wdbPipePktDrv.h.  This does not
  38.                  conflict with recent NPT modifications.  Moreover, it is
  39.                  needed for T2 WDB_COMM_PIPE configuration.
  40. 03g,25aug99,sj  dont include private muxLib header file 
  41. 03f,30jul99,pul  modifications to support NPT
  42. 03e,29apr99,pul  Upgraded NPT phase3 code to tor2.0.0
  43. 03d,31mar99,sj  commenting out #include wdbPipePktDrv.h until tor2_0_x merge
  44. 03c,18mar99,sj  removed INCLUDE_NPT check
  45. 03b,05mar99,sj  eliminated call to muxTkLibInit. Must set muxMaxBinds
  46. 03a,15feb99,dbt remove task creation hook only if it has been previously
  47.                 installed (SPR #24195)
  48. 02z,08nov98,sj  added NPT support 
  49. 02y,12aug98,gnn fixed return values from wdbCommIfInit
  50. 02x,06aug98,pdn make sure that WDB_MTU is less or equal WDB_PIPE_PKT_MTU.
  51. 02w,03jun98,cym specified type int for local variable in taskCreateHookAdd.
  52. 02v,02jun98,dbt wdbTgtHasFpp() routine is now LOCAL.
  53. 02u,20may98,dbt test if wdbPipePktDevInit() returns an error.
  54. completed error checking for other communication links.
  55. 02t,13may98,dbt reworked HPSIM fix for SLIP communication link.
  56. check if sysBootLine is empty before parsing it.
  57. 02s,24apr98,dbt test pFpContext before reading task floating point registers
  58.                 (SPR #9940).
  59. 02r,19mar98,dbt added support for user events and context start notification.
  60. fixed some problems due to various merges.
  61. 02q,18mar98,jmb fix ifdef in previous patch 
  62. 02p,18mar98,jmb merge HPSIM poll for connect code 
  63. 02o,11mar98,pdn added WDB_COMM_PIPE for VxSims
  64. 02n,26jan98,gnn remerged from sirocco, was missing wdbSp function.
  65. 02m,21jan98,dbt added more error checking (SPR #9422, SPR #5651).
  66. vxTaskCreate() returns ERROR instead of NULL when taskCreat()
  67. fails (SPR #9050).
  68. Removed vxTaskLock() and vxTaskUnlock().
  69. Added wdbEvtptLibInit() call.
  70. 02l,12jan98,dbt modified for new breakpoint scheme.
  71. Replaced wdbBpRemove() with wdbDbgBpRemoveAll(). 
  72. Moved wdbBpSet() to usrBreakpoint.c.
  73. 02k,03oct97,gnn fixed a warning in the endLoad call
  74. 02j,25sep97,gnn SENS beta feedback fixes
  75. 02i,19sep97,vin added WDB_NUM_CL_BLKS and the logic for clBlks.
  76. 02c,06aug97,cdp gave type to 'initialised' in vxTaskDeleteHookAdd.
  77. 02h,17apr97,gnn added support for configNet type support for END.
  78. 02g,07apr97,gnn added new routines for MUX functionality.
  79. 02f,17mar97,hdn added sysIntLock() and sysIntUnlock() for I80X86.
  80. 02e,05mar97,ms  fixed IU_REGS_GET bug introduced by 01y checkin.
  81. 02d,04feb97,ms  Added support for NetROM 500 series.
  82. 02c,21jan97,gnn added code to load the device if we are booted standalone.
  83. 02b,17dec96,ms  WDB now uses FP_CONTEXT instead of FPREG_SET (SPR 7654).
  84. 02a,02oct96,elp changed casts due to TGT_ADDR_T type change.
  85. 01z,04nov96,gnn added code to handle smaller END MTU.
  86. 01y,28aug96,gnn added WDB_COMM_END stuff.
  87. 01w,09aug96,ms  added "wdbSp" for windsh system mode "sp" (SPR 6254).
  88. 01x,23jul96,vin added BSD4.4 changes for mbufs. 
  89. 01v,22jul96,jmb added kab (ease) sanity check to wdbBpSet; HPUX can have tasks 
  90. with "unset" registers, and that gets propogated as addr 0x0.
  91. 01u,12mar96,ms  redid host pool init. made exteral agent run in kernelState.
  92. 01t,05mar96,tpr put the wdbHostPool always static for PPC (24bits limitation PB)
  93. + added VX_FP_TASK flag to WDB_TASK_OPTIONS macro.
  94. 01s,24oct95,ms moved wdbBpSet here.
  95. 01r,16oct95,ms  host mem pool created via static buffer instead of malloc
  96. 01q,11oct95,ms  turned off character echoing in TTY_TEST to fix SPR 5116
  97. 01p,21sep95,ms  macro shuffle + fix for SPR 4936.
  98. 01o,31aug95,ms  INCLUDE_WDB_TTY_TEST works if started before kernel (SPR #4808)
  99. 01n,23aug95,ms  bump intCnt to fake ISR context in extern agents extern hook
  100. 01m,28jun95,tpr added NETROM_TASK_POLL_DELAY macro.
  101. 01l,23jun95,ms changed logMsg to _func_logMsg
  102. 01k,21jun95,ms added taskRestart for the agent on exception.
  103. 01j,20jun95,tpr added wdbMemCoreLibInit().
  104. 01i,20jun95,ms moved gopher buffer back to gopherLib.o for DSA
  105. 01h,19jun95,ms moved event lib initialization near the begining of wdbConfig
  106. fixed vxTaskDeleteHookAdd to return OK or ERROR
  107. added initialization for INCLUDE_WDB_TTY_TEST
  108. 01g,15jun95,ms updated for new serial drivers.
  109. 01f,07jun95,ms exit hook no longer uses the spare TCB field
  110. memory size based on sysMemTop() instead of LOCAL_MEM_SIZE
  111. added some scalability
  112. WDB_STACK_SIZE used for both task and system agent.
  113. WDB_COMM_TYCO changed to WDB_COMM_TTY
  114. 01e,01jun95,ms added taskLock/unlock.
  115. pass buffer to wdbGopherLibInit().
  116. decreace WDB_MTU when going over serial line.
  117. changed MTU->WDB_MTU, EXC_NOTIFY->WDB_EXC_NOTIFY,
  118. MAX_SERVICES->WDB_MAX_SERVICES,
  119. AGENT_POOL_SIZE->WDB_POOL_SIZE.
  120. 01d,25may95,ms added fpp support for the system agent.
  121. 01c,23may95,ms added some include files.
  122. 01b,17jan95,ms  cleaned up.
  123. 01a,21sep94,ms  written.
  124. */
  125. /*
  126. DESCRIPTION
  127. This library configures and initializes the WDB agent.
  128. The only user callable routine is wdbConfig(). This routine
  129. initializes the agents OS function pointers, the communication
  130. function pointers, and then the agent itself.
  131. */
  132. #include "vxWorks.h"
  133. #include "sysLib.h"
  134. #include "stdlib.h"
  135. #include "vxLib.h"
  136. #include "taskLib.h"
  137. #include "taskHookLib.h"
  138. #ifdef INCLUDE_ALTIVEC
  139. #include "altivecLib.h"
  140. #endif /* INCLUDE_ALTIVEC */
  141. #include "fppLib.h"
  142. #include "intLib.h"
  143. #include "rebootLib.h"
  144. #include "bootLib.h"
  145. #include "version.h"
  146. #include "cacheLib.h"
  147. #include "excLib.h"
  148. #include "config.h"
  149. #include "string.h"
  150. #include "bufLib.h"
  151. #include "sioLib.h"
  152. #include "private/taskLibP.h"
  153. #include "private/kernelLibP.h"
  154. #include "private/vmLibP.h"
  155. #include "private/funcBindP.h"
  156. #include "wdb/wdb.h"
  157. #include "wdb/wdbLib.h"
  158. #include "wdb/wdbLibP.h"
  159. #include "wdb/wdbBpLib.h"
  160. #include "wdb/wdbSvcLib.h"
  161. #include "wdb/wdbUdpLib.h"
  162. #include "wdb/wdbUdpSockLib.h"
  163. #include "wdb/wdbTyCoDrv.h"
  164. #include "wdb/wdbRtIfLib.h"
  165. #include "wdb/wdbCommIfLib.h"
  166. #include "wdb/wdbMbufLib.h"
  167. #include "wdb/wdbRpcLib.h"
  168. #include "wdb/wdbRegs.h"
  169. #include "wdb/wdbVioLib.h"
  170. #include "drv/wdb/wdbVioDrv.h"
  171. #include "drv/wdb/wdbSlipPktDrv.h"
  172. #include "drv/wdb/wdbUlipPktDrv.h"
  173. #include "drv/wdb/wdbNetromPktDrv.h"
  174. #include "drv/wdb/wdbEndPktDrv.h"
  175. #include "drv/wdb/wdbPipePktDrv.h"
  176. #if defined (INCLUDE_WDB_COMM_VTMD)
  177. #include "wdb/vision/wdbVisionDrv.c"
  178. #include "drv/wdb/vision/wdbVisionPktDrv.h"
  179. #include "wdb/vision/wdbVisionPktDrv.c"
  180. #include "wdb/vision/visionTmdDrv.c"
  181. #if   ((CPU == PPC603) || (CPU == PPC860) || (CPU == PPC604) || (CPU == PPC405))
  182. #include "wdb/vision/visionTmdAsmPpc.c"
  183. #elif (CPU == MIPS32)
  184. #include "wdb/vision/visionTmdAsmMips.c"
  185. #elif (CPU == ARMARCH4)
  186. #include "wdb/vision/visionTmdAsmArm.c"
  187. #elif (CPU == XSCALE)
  188. #include "wdb/vision/visionTmdAsmXscale.c"
  189. #elif ((CPU == SH7700) || (CPU == SH7750) || (CPU == SH7600))
  190. #include "wdb/vision/visionTmdAsmSh.c"
  191. #elif (CPU == MCF5200)
  192. #include "wdb/vision/visionTmdAsmCfire.c"
  193. #else
  194. #error "This CPU is not supported !!!"
  195. #endif
  196. #endif /* (INCLUDE_WDB_COMM_VTMD) */
  197. #if (CPU==SIMHPPA) && defined(INCLUDE_SLIP) && 
  198. (WDB_COMM_TYPE == WDB_COMM_NETWORK)
  199. #include "wdLib.h"
  200. #include "drv/sio/unixSio.h"
  201. IMPORT void intCatch ();
  202. extern int s_asyncio ();
  203. LOCAL void usrWdbPollForConnect ();
  204. LOCAL WDOG_ID wdSlipConnect;
  205. #endif /* CPU==SIMHPPA && INCLUDE_SLIP */
  206. #if (WDB_COMM_TYPE == WDB_COMM_END)
  207. #include "end.h"
  208. #include "muxLib.h"
  209. #include "muxTkLib.h"
  210. #include "configNet.h"
  211. IMPORT END_TBL_ENTRY endDevTbl[];
  212. #endif /* WDB_COMM_TYPE == WDB_COMM_END */
  213. /* defines */
  214. #define NUM_MBUFS 5
  215. #define WDB_NUM_CL_BLKS 5
  216. #define MILLION 1000000
  217. #define MAX_LEN BOOT_LINE_SIZE
  218. #define INCLUDE_VXWORKS_KERNEL /* don't remove this */
  219. #define WDB_RESTART_TIME 10
  220. #define WDB_MAX_RESTARTS 5
  221. #define WDB_BP_MAX 50 /* max # of break points */
  222. #define WDB_MAX_SERVICES        50 /* max # of agent services */
  223. #define WDB_TASK_PRIORITY       3 /* priority of task agent */
  224. /* Currently, DSP and ALTIVEC are mutually exclusive */
  225. #ifdef INCLUDE_ALTIVEC
  226. #define WDB_TASK_OPTIONS        (VX_UNBREAKABLE | VX_FP_TASK | VX_ALTIVEC_TASK)
  227. #else /* INCLUDE_ALTIVEC */
  228. #ifdef INCLUDE_DSP
  229. #define WDB_TASK_OPTIONS        (VX_UNBREAKABLE | VX_FP_TASK | VX_DSP_TASK)
  230. #else
  231. #define WDB_TASK_OPTIONS        VX_UNBREAKABLE | VX_FP_TASK /* agent options */
  232. #endif /* INCLUDE_DSP */
  233. #endif /* INCLUDE_ALTIVEC */
  234. #define WDB_POOL_BASE ((char *)(FREE_RAM_ADRS))
  235. /* lower WDB_MTU to SLMTU bytes for serial connection */
  236. #if (WDB_COMM_TYPE == WDB_COMM_TYCODRV_5_2) || 
  237. (WDB_COMM_TYPE == WDB_COMM_SERIAL)
  238. #if WDB_MTU > SLMTU
  239. #undef WDB_MTU
  240. #define WDB_MTU SLMTU
  241. #endif /* WDB_MTU > SLMTU */
  242. #endif /* WDB_COMM_TYPE */
  243. /* lower WDB_MTU to NETROM_MTU for netrom connections */
  244. #if (WDB_COMM_TYPE == WDB_COMM_NETROM)
  245. #if WDB_NETROM_TYPE == 400
  246. #include "wdb/wdbNetromPktDrv.c"
  247. #elif WDB_NETROM_TYPE == 500
  248. #include "wdb/amc500/wdbNetromPktDrv.c"
  249. #else /* WDB_NETROM_TYPE */
  250. #error WDB_NETROM_TYPE unknown
  251. #endif /* WDB_NETROM_TYPE */
  252. #if WDB_MTU > NETROM_MTU
  253. #undef WDB_MTU
  254. #define WDB_MTU NETROM_MTU
  255. #endif /* WDB_MTU > NETROM_MTU */
  256. #endif /* WDB_COMM_TYPE == WDB_COMM_NETROM */
  257. /* lower WDB_MTU to ULIP_MTU for ULIP connections */
  258. #if (WDB_COMM_TYPE == WDB_COMM_ULIP)
  259. #if WDB_MTU > ULIP_MTU
  260. #undef WDB_MTU
  261. #define WDB_MTU ULIP_MTU
  262. #endif /* WDB_MTU > ULIP_MTU */
  263. #endif /* WDB_COMM_TYPE == WDB_COMM_ULIP */
  264. #if (WDB_COMM_TYPE == WDB_COMM_END)
  265. #if WDB_MTU > WDB_END_PKT_MTU
  266. #undef WDB_MTU
  267. #define WDB_MTU WDB_END_PKT_MTU
  268. #endif /* WDB_MTU > WDB_END_PKT_MTU */
  269. #ifndef MUX_MAX_BINDS
  270. #define MUX_MAX_BINDS 16
  271. #endif /* MUX_MAX_BINDS */
  272. #endif /* (WDB_COMM_TYPE == WDB_COMM_END) */
  273. #if (WDB_COMM_TYPE == WDB_COMM_PIPE)
  274. #if WDB_MTU > WDB_PIPE_PKT_MTU
  275. #undef WDB_MTU
  276. #define WDB_MTU WDB_PIPE_PKT_MTU
  277. #endif /* WDB_MTU > WDB_PIPE_PKT_MTU */
  278. #endif /* WDB_COMM_TYPE == WDB_COMM_PIPE */
  279. /* change agent mode to task mode for NETWORK or TYCODRV_5_2 connections */
  280. #if (WDB_COMM_TYPE == WDB_COMM_TYCODRV_5_2) || (WDB_COMM_TYPE == WDB_COMM_NETWORK)
  281. #undef WDB_MODE
  282. #define WDB_MODE WDB_MODE_TASK
  283. #endif /* WDB_COMM_TYPE */
  284. /* globals */
  285. uint_t  wdbCommMtu = WDB_MTU;
  286. int  wdbNumMemRegions = 0; /* number of extra memory regions */
  287. WDB_MEM_REGION * pWdbMemRegions = NULL; /* array of regions */
  288. /* This two macros transform TOOL define into the string "TOOL" */
  289. #define MKSTR(MACRO) MKSTR_FIRST_PASS(MACRO)
  290. #define MKSTR_FIRST_PASS(MACRO) #MACRO
  291. /* 
  292.  * This symbol "wdbToolName" is used by the tgtsvr to retrieve the name of the
  293.  * tool used to build vxWorks run-time. DO NOT REMOVE !!!
  294.  */
  295.  
  296. #ifdef TOOL
  297. const char wdbToolName[] = MKSTR(TOOL);
  298. #else /* TOOL */
  299. const char  wdbToolName[] = "Unknown";
  300. #endif /* TOOL */
  301. #if (CPU==SIMHPPA)
  302. extern void sysSerialWDBSetup ();
  303. #endif /* (CPU==SIMHPPA) */
  304. /* locals */
  305. LOCAL BUF_POOL wdbMbufPool;
  306. LOCAL BUF_POOL wdbClBlkPool;
  307. LOCAL char vxBootFile [MAX_LEN];
  308. LOCAL WDB_RT_IF wdbRtIf;
  309. LOCAL BOOL prevKernelState;
  310. LOCAL VOIDFUNCPTR wdbCreateHook = NULL; /* WDB task create hook */
  311. /*
  312.  * These are private - but configurable size arrays can't be malloc'ed
  313.  * in external mode, so we define them here.
  314.  */
  315. #if     (WDB_MODE & WDB_MODE_EXTERN)
  316. LOCAL uint_t wdbExternStackArray [WDB_STACK_SIZE/sizeof(uint_t)];
  317. #endif /* (WDB_MODE & WDB_MODE_EXTERN) */
  318. LOCAL WDB_SVC wdbSvcArray       [WDB_MAX_SERVICES];
  319. LOCAL uint_t wdbSvcArraySize = WDB_MAX_SERVICES;
  320. #ifdef INCLUDE_WDB_BP
  321. LOCAL struct brkpt wdbBreakPoints [WDB_BP_MAX];
  322. #endif /* INCLUDE_WDB_BP */
  323. /* forward static declarations */
  324. LOCAL void wdbMbufInit ();
  325. LOCAL void wdbRtIfInit ();
  326. LOCAL STATUS wdbCommIfInit ();
  327. LOCAL bool_t wdbTgtHasFpp (void);
  328. #ifdef INCLUDE_DSP
  329. LOCAL bool_t wdbTgtHasDsp (void);
  330. #endif /* INCLUDE_DSP */
  331. #ifdef  INCLUDE_ALTIVEC
  332. LOCAL bool_t wdbTgtHasAltivec (void);
  333. #endif /* INCLUDE_ALTIVEC */
  334. /******************************************************************************
  335. *
  336. * wdbConfig - configure and initialize the WDB agent.
  337. *
  338. * This routine configures and initializes the WDB agent.
  339. *
  340. * RETURNS :
  341. * OK if at least one of the agents (task or system) was correctly
  342. * initialized. ERROR otherwise.
  343. *
  344. * NOMANUAL
  345. */
  346. STATUS wdbConfig (void)
  347.     {
  348. #if     (WDB_MODE & WDB_MODE_DUAL)
  349.     STATUS status1 = ERROR;
  350.     STATUS status2 = ERROR;
  351. #elif     (WDB_MODE & WDB_MODE_TASK)
  352.     STATUS status1 = ERROR;
  353. #elif     (WDB_MODE & WDB_MODE_EXTERN)
  354.     STATUS status2 = ERROR;
  355. #endif /* WDB_MODE_[DUAL||TASK||EXTERN] */
  356.  
  357. #if     (WDB_MODE & WDB_MODE_EXTERN)
  358.     caddr_t pExternStack;
  359. #endif /* WDB_MODE & WDB_MODE_EXTERN */
  360.     /* Initialize the agents interface function pointers */
  361.     wdbRtIfInit (); /* run-time interface functions */
  362.     if (wdbCommIfInit () == ERROR) /* communication interface functions */
  363. {
  364. if (_func_printErr != NULL)
  365.     _func_printErr ("wdbConfig: error configuring WDB communication interfacen");
  366. return (ERROR);
  367. }
  368.     /* Install some agent services */
  369.     wdbSvcLibInit (wdbSvcArray, wdbSvcArraySize);
  370.     wdbConnectLibInit (); /* required agent service */
  371.     wdbMemCoreLibInit (); /* required agent service */
  372. #ifdef INCLUDE_WDB_MEM
  373.     wdbMemLibInit (); /* extra memory services */
  374. #endif /* INCLUDE_WDB_MEM */
  375. #ifdef INCLUDE_WDB_EVENTS
  376.     wdbEventLibInit();
  377. #endif /* INCLUDE_WDB_EVENTS */
  378. #ifdef INCLUDE_WDB_EVENTPOINTS
  379.     wdbEvtptLibInit();
  380. #endif /* INCLUDE_WDB_EVENTPOINTS */
  381. #ifdef  INCLUDE_WDB_DIRECT_CALL
  382.     wdbDirectCallLibInit ();
  383. #endif  /* INCLUDE_WDB_DIRECT_CALL */
  384. #ifdef INCLUDE_WDB_CTXT
  385.     wdbCtxLibInit ();
  386. #endif /* INCLUDE_WDB_CTXT */
  387. #ifdef INCLUDE_WDB_REG
  388.     wdbRegsLibInit ();
  389. #endif /* INCLUDE_WDB_REG */
  390. #ifdef INCLUDE_WDB_GOPHER
  391.     wdbGopherLibInit();
  392. #endif /* INCLUDE_WDB_GOPHER */
  393. #ifdef INCLUDE_WDB_EXIT_NOTIFY
  394.     wdbCtxExitLibInit();
  395. #endif /* INCLUDE_WDB_EXIT_NOTIFY */
  396. #ifdef INCLUDE_WDB_EXC_NOTIFY
  397.     wdbExcLibInit();
  398. #endif /* INCLUDE_WDB_EXC_NOTIFY */
  399. #ifdef INCLUDE_WDB_FUNC_CALL
  400.     wdbFuncCallLibInit ();
  401. #endif /* INCLUDE_WDB_FUNC_CALL */
  402. #ifdef INCLUDE_WDB_VIO
  403.     wdbVioLibInit();
  404.     wdbVioDrv("/vio");
  405. #endif /* INCLUDE_WDB_VIO */
  406. #ifdef  INCLUDE_WDB_TSFS
  407.     wdbTsfsDrv ("/tgtsvr");
  408. #endif  /* INCLUDE_WDB_TSFS */
  409. #ifdef  INCLUDE_WDB_BP
  410.     wdbSysBpLibInit (wdbBreakPoints, WDB_BP_MAX);
  411. #if (WDB_MODE & WDB_MODE_TASK)
  412.     wdbTaskBpLibInit ();
  413. #endif /* WDB_MODE & WDB_MODE_TASK */
  414. #endif /* INCLUDE_WDB_BP */
  415. #ifdef INCLUDE_WDB_START_NOTIFY
  416.     wdbCtxStartLibInit ();
  417. #endif /* INCLUDE_WDB_START_NOTIFY */
  418. #ifdef INCLUDE_WDB_USER_EVENT
  419.     wdbUserEvtLibInit ();
  420. #endif /* INCLUDE_WDB_USER_EVENT */
  421.     /* Initialize the agent(s) */
  422. #if (WDB_MODE & WDB_MODE_TASK)
  423.     status1 = wdbTaskInit (WDB_TASK_PRIORITY,
  424. WDB_TASK_OPTIONS, NULL, WDB_STACK_SIZE);
  425. #endif
  426. #if (WDB_MODE & WDB_MODE_EXTERN)
  427. #if _STACK_DIR == _STACK_GROWS_DOWN
  428.     pExternStack = (caddr_t)&wdbExternStackArray
  429. [WDB_STACK_SIZE/sizeof(uint_t)];
  430.     pExternStack = (caddr_t)STACK_ROUND_DOWN (pExternStack);
  431. #else /* _STACK_DIR == _STACK_GROWS_UP */
  432.     pExternStack = (caddr_t)wdbExternStackArray;
  433.     pExternStack = (caddr_t)STACK_ROUND_UP (pExternStack);
  434. #endif /* _STACK_DIR == _STACK_GROWS_DOWN */
  435.     status2 = wdbExternInit (pExternStack);
  436. #ifdef INCLUDE_HW_FP
  437.     if (wdbTgtHasFpp())
  438. {
  439. WDB_REG_SET_OBJ * pFpRegs;
  440. pFpRegs = wdbFpLibInit();
  441. wdbExternRegSetObjAdd (pFpRegs);
  442. }
  443. #endif /* INCLUDE_HW_FP */
  444. #ifdef INCLUDE_DSP
  445.     if (wdbTgtHasDsp ())
  446. {
  447. WDB_REG_SET_OBJ * pDspRegs;
  448. pDspRegs = wdbDspLibInit();
  449. wdbExternRegSetObjAdd (pDspRegs);
  450. }
  451. #endif /* INCLUDE_DSP */
  452. #ifdef  INCLUDE_ALTIVEC
  453.     if (wdbTgtHasAltivec())
  454. {
  455. WDB_REG_SET_OBJ * pAltivecRegs;
  456. pAltivecRegs = wdbAltivecLibInit();
  457. wdbExternRegSetObjAdd (pAltivecRegs);
  458. }
  459. #endif /* INCLUDE_ALTIVEC */
  460. #endif /* WDB_MODE & WDB_MODE_EXTERN */
  461.     /* activate one agent only */
  462. #if (WDB_MODE & WDB_MODE_TASK)
  463.     wdbModeSet (WDB_MODE_TASK);
  464. #else
  465.     wdbModeSet (WDB_MODE_EXTERN);
  466. #endif
  467. #if (WDB_MODE & WDB_MODE_DUAL)
  468.     return ((status1 && status2) ? ERROR : OK);
  469. #elif (WDB_MODE & WDB_MODE_TASK)
  470.     return ((status1) ? ERROR : OK);
  471. #elif (WDB_MODE & WDB_MODE_EXTERN)
  472.     return ((status2) ? ERROR : OK);
  473. #else
  474.     return ERROR;
  475. #endif
  476.     }
  477. /******************************************************************************
  478. *
  479. * wdbExternEnterHook - hook to call when external agent is entered.
  480. */
  481. void wdbExternEnterHook (void)
  482.     {
  483.     intCnt++; /* always fake an interrupt context */
  484.     prevKernelState = kernelState;
  485.     kernelState = TRUE; /* always run in kernel state */
  486. #if (CPU_FAMILY==I80X86)
  487.     sysIntLock ();
  488. #endif /* CPU_FAMILY==I80X86 */
  489. #ifdef INCLUDE_WDB_BP
  490.     wdbDbgBpRemoveAll ();
  491. #endif
  492.     }
  493. /******************************************************************************
  494. *
  495. * wdbExternExitHook - hook to call when the external agent resumes the system.
  496. */
  497. void wdbExternExitHook (void)
  498.     {
  499.     intCnt--; /* restore original intCnt value */
  500.     kernelState = prevKernelState; /* restore original kernelState value */
  501. #if (CPU_FAMILY==I80X86)
  502.     intLock ();
  503.     sysIntUnlock ();
  504. #endif /* CPU_FAMILY==I80X86 */
  505. #ifdef  INCLUDE_WDB_BP
  506.     wdbBpInstall ();
  507. #endif
  508.     }
  509. /******************************************************************************
  510. *
  511. * wdbTgtHasFpp - TRUE if target has floating point support.
  512. */
  513. LOCAL bool_t wdbTgtHasFpp (void)
  514.     {
  515. #ifdef INCLUDE_HW_FP
  516.     if (fppProbe() == OK)
  517. return (TRUE);
  518.     return (FALSE);
  519. #else
  520.     return (FALSE);
  521. #endif
  522.     }
  523. #ifdef INCLUDE_DSP
  524. /******************************************************************************
  525. *
  526. * wdbTgtHasDsp - TRUE if target has DSP support.
  527. */
  528. LOCAL bool_t wdbTgtHasDsp (void)
  529.     {
  530.     if (dspProbe() == OK)
  531. return (TRUE);
  532.     return (FALSE);
  533.     }
  534. #endif /* INCLUDE_DSP */
  535. #ifdef  INCLUDE_ALTIVEC
  536. /******************************************************************************
  537. *
  538. * wdbTgtHasAltivec - TRUE if target has altivec support.
  539. */
  540. LOCAL bool_t wdbTgtHasAltivec (void)
  541.     {
  542.     if (altivecProbe() == OK)
  543.         return (TRUE);
  544.     return (FALSE);
  545.     }
  546. #endif /* INCLUDE_ALTIVEC */
  547. /******************************************************************************
  548. * wdbTgtHasCoprocessor - this function's result contains bit fields for each 
  549. *  co-processor. Coprocessors include floating-point,altivec(PPC) and 
  550. * dsp(SH).
  551. */ 
  552. LOCAL UINT32 wdbTgtHasCoprocessor (void)
  553.     {
  554.     UINT32 result;
  555.     result = wdbTgtHasFpp();
  556. #ifdef INCLUDE_ALTIVEC
  557.     result |= (wdbTgtHasAltivec() << WDB_CO_PROC_ALTIVEC);
  558. #endif
  559. #ifdef INCLUDE_DSP
  560.     result |= (wdbTgtHasDsp() << WDB_CO_PROC_DSP);
  561. #endif
  562.     return result;
  563.     }
  564. /******************************************************************************
  565. *
  566. * wdbRtInfoGet - get info on the VxWorks run time system.
  567. */
  568. LOCAL void wdbRtInfoGet
  569.     (
  570.     WDB_RT_INFO * pRtInfo
  571.     )
  572.     {
  573.     pRtInfo->rtType = WDB_RT_VXWORKS;
  574.     pRtInfo->rtVersion = vxWorksVersion;
  575.     pRtInfo->cpuType = CPU;
  576.     pRtInfo->hasCoprocessor = wdbTgtHasCoprocessor();
  577. #ifdef INCLUDE_PROTECT_TEXT
  578.     pRtInfo->hasWriteProtect = (vmLibInfo.pVmTextProtectRtn != NULL);
  579. #else /* !INCLUDE_PROTECT_TEXT */
  580.     pRtInfo->hasWriteProtect = FALSE;
  581. #endif /* !INCLUDE_PROTECT_TEXT */
  582.     pRtInfo->pageSize   = VM_PAGE_SIZE_GET();
  583.     pRtInfo->endian = _BYTE_ORDER;
  584.     pRtInfo->bspName = sysModel();
  585.     pRtInfo->bootline = vxBootFile;
  586. #ifdef HITACHI_SH_KERNEL_ON_SDRAM
  587.     pRtInfo->memBase = (TGT_ADDR_T)(FREE_RAM_ADRS);
  588.     pRtInfo->memSize = (int)sysMemTop() - (int)FREE_RAM_ADRS;
  589. #else /* HITACHI_SH_KERNEL_ON_SDRAM */
  590.     pRtInfo->memBase = (TGT_ADDR_T)(LOCAL_MEM_LOCAL_ADRS);
  591.     pRtInfo->memSize = (int)sysMemTop() - (int)LOCAL_MEM_LOCAL_ADRS;
  592. #endif /* HITACHI_SH_KERNEL_ON_SDRAM */
  593.     pRtInfo->numRegions = wdbNumMemRegions;
  594.     pRtInfo->memRegion = pWdbMemRegions;
  595.     pRtInfo->hostPoolBase = (TGT_ADDR_T)WDB_POOL_BASE;
  596.     pRtInfo->hostPoolSize = WDB_POOL_SIZE;
  597.     }
  598. /******************************************************************************
  599. *
  600. * vxReboot - reboot the system.
  601. */
  602. LOCAL void vxReboot (void)
  603.     {
  604.     reboot (0);
  605.     }
  606. /******************************************************************************
  607. *
  608. * vxMemProtect - protect a region of memory.
  609. */
  610. LOCAL STATUS vxMemProtect
  611.     (
  612.     char * addr,
  613.     u_int  nBytes,
  614.     bool_t protect /* TRUE = protect, FALSE = unprotect */
  615.     )
  616.     {
  617.     return (VM_STATE_SET (NULL, addr, nBytes, VM_STATE_MASK_WRITABLE, 
  618.                      (protect ? VM_STATE_WRITABLE_NOT : VM_STATE_WRITABLE)));
  619.     }
  620. #ifdef INCLUDE_VXWORKS_KERNEL
  621. /******************************************************************************
  622. *
  623. * wdbSp - spawn a task with default params
  624. */ 
  625. #define PRIORITY        100
  626. #define OPTIONS         VX_FP_TASK
  627. void wdbSp
  628.     (
  629.     int (*func)(),
  630.     int arg0,
  631.     int arg1,
  632.     int arg2,
  633.     int arg3,
  634.     int arg4
  635.     )
  636.     {
  637.     taskSpawn (NULL, PRIORITY, OPTIONS, WDB_SPAWN_STACK_SIZE, func, arg0,
  638.         arg1, arg2, arg3, arg4, 0, 0, 0, 0, 0);
  639.     }
  640. /******************************************************************************
  641. *
  642. * vxTaskCreate - WDB callout to create a task (and leave suspended).
  643. *
  644. * RETURNS : Task ID or ERROR if unable to create a task
  645. *
  646. * NOMANUAL
  647. */
  648. LOCAL int vxTaskCreate
  649.     (
  650.     char *   name,       /* name of new task (stored at pStackBase)   */
  651.     int      priority,   /* priority of new task                      */
  652.     int      options,    /* task option word                          */
  653.     caddr_t  stackBase,  /* base of stack. ignored by VxWorks       */
  654.     int      stackSize,  /* size (bytes) of stack needed plus name    */
  655.     caddr_t  entryPt,    /* entry point of new task                   */
  656.     int      arg[10],  /* 1st of 10 req'd task args to pass to func */
  657.     int      fdIn,  /* fd for input redirection       */
  658.     int      fdOut,  /* fd for output redirection       */
  659.     int      fdErr  /* fd for error output redirection       */
  660.     )
  661.     {
  662.     int tid;
  663.     if (stackSize == 0)
  664. stackSize = WDB_SPAWN_STACK_SIZE;
  665.     tid = taskCreat (name, priority, options, stackSize, (int (*)())entryPt,
  666. arg[0], arg[1], arg[2], arg[3], arg[4], arg[5], arg[6],
  667. arg[7], arg[8], arg[9]);
  668.     if (tid == (int)NULL) /* create failed */
  669. return (ERROR);
  670. #ifdef INCLUDE_IO_SYSTEM
  671.     if (fdIn != 0)
  672. ioTaskStdSet (tid, 0, fdIn);
  673.     if (fdOut != 0)
  674. ioTaskStdSet (tid, 1, fdOut);
  675.     if (fdErr != 0)
  676. ioTaskStdSet (tid, 2, fdErr);
  677. #endif /* INCLUDE_IO_SYSTEM */
  678.     return (tid);
  679.     }
  680. /******************************************************************************
  681. *
  682. * vxTaskResume - WDB callout to resume a suspended task.
  683. */
  684. LOCAL STATUS vxTaskResume
  685.     (
  686.     WDB_CTX * pContext
  687.     )
  688.     {
  689.     if (pContext->contextType != WDB_CTX_TASK)
  690. return (ERROR);
  691.     return (taskResume (pContext->contextId));
  692.     }
  693. /******************************************************************************
  694. *
  695. * vxTaskSuspend - WDB callout to suspend a task.
  696. */
  697. LOCAL STATUS vxTaskSuspend
  698.     (
  699.     WDB_CTX * pContext
  700.     )
  701.     {
  702.     if (pContext->contextType != WDB_CTX_TASK)
  703. return (ERROR);
  704.     return (taskSuspend (pContext->contextId));
  705.     }
  706. /******************************************************************************
  707. *
  708. * vxTaskDelete - WDB callout to delete a task.
  709. */
  710. LOCAL STATUS vxTaskDelete
  711.     (
  712.     WDB_CTX * pContext
  713.     )
  714.     {
  715.     if (pContext->contextType != WDB_CTX_TASK)
  716. return (ERROR);
  717.     return (taskDelete (pContext->contextId));
  718.     }
  719. /******************************************************************************
  720. *
  721. * vxTaskRegsSet - WDB callout to get a task register set.
  722. */
  723. LOCAL STATUS vxTaskRegsSet
  724.     (
  725.     WDB_CTX *  pContext,
  726.     WDB_REG_SET_TYPE regSetType,
  727.     char *  pRegSet
  728.     )
  729.     {
  730.     STATUS status;
  731.     if (pContext->contextType != WDB_CTX_TASK)
  732. return (ERROR);
  733.     switch (regSetType)
  734. {
  735. case WDB_REG_SET_IU:
  736.     status = taskRegsSet (pContext->contextId, (REG_SET *)pRegSet);
  737.     break;
  738. #ifdef  INCLUDE_HW_FP
  739. case WDB_REG_SET_FPU:
  740.     {
  741.     WIND_TCB * pTcb = taskTcb (pContext->contextId);
  742.     if ((pTcb == NULL) || (pTcb->pFpContext == NULL))
  743. return (ERROR);
  744.     bcopy (pRegSet, (char *)(pTcb->pFpContext), sizeof (FP_CONTEXT));
  745.     return (OK);
  746.     }
  747. #endif /* INCLUDE_HW_FP */
  748. #ifdef  INCLUDE_ALTIVEC
  749. case WDB_REG_SET_AV:
  750.     {
  751.     WIND_TCB * pTcb = taskTcb (pContext->contextId);
  752.             if ((pTcb == NULL) || (ALTIVEC_CONTEXT_GET(pTcb) == NULL))
  753. return (ERROR);
  754.             bcopy (pRegSet, (char *)(ALTIVEC_CONTEXT_GET(pTcb)), sizeof (ALTIVEC_CONTEXT));
  755.     return (OK);
  756.     }
  757. #endif /* INCLUDE_ALTIVEC */
  758. #ifdef  INCLUDE_DSP
  759. case WDB_REG_SET_DSP:
  760.     {
  761.     WIND_TCB * pTcb = taskTcb (pContext->contextId);
  762.     if ((pTcb == NULL) || (pTcb->pDspContext == NULL))
  763. return (ERROR);
  764.     /*
  765.      * If modifying last DSP task to run, force it to restore
  766.      * when it runs next.  There is no need to do a dspSave()
  767.      * here as the entire DSP_CONTEXT is about to be overwritten.
  768.      */
  769.     if (pTcb == pTaskLastDspTcb)
  770. pTaskLastDspTcb = NULL;
  771.     bcopy (pRegSet, (char *)(pTcb->pDspContext), sizeof (DSP_CONTEXT));
  772.     return (OK);
  773.     }
  774. #endif /* INCLUDE_DSP */
  775. default:
  776.     status = ERROR;
  777. }
  778.     return (status);
  779.     }
  780. /******************************************************************************
  781. *
  782. * vxTaskRegsGet - WDB callout to get a tasks register set.
  783. *
  784. * This routine is not reentrant, but it it only called by one thread (the
  785. * WDB agent).
  786. */
  787. LOCAL STATUS vxTaskRegsGet
  788.     (
  789.     WDB_CTX * pContext,
  790.     WDB_REG_SET_TYPE  regSetType,
  791.     char ** ppRegSet
  792.     )
  793.     {
  794.     WIND_TCB * pTcb;
  795.     if (pContext->contextType != WDB_CTX_TASK)
  796. return (ERROR);
  797.     pTcb = taskTcb (pContext->contextId);
  798.     if (pTcb == NULL)
  799. return (ERROR);
  800.     switch (regSetType)
  801. {
  802. case WDB_REG_SET_IU:
  803.     {
  804.     REG_SET dummy;
  805.     taskRegsGet (pContext->contextId, &dummy);
  806.     *ppRegSet = (char *) &pTcb->regs;
  807.     return (OK);
  808.     }
  809. #ifdef  INCLUDE_HW_FP
  810. case WDB_REG_SET_FPU:
  811.     if (pTcb->pFpContext == NULL)
  812. return (ERROR); /* no coprocessor support */
  813.     *ppRegSet = (char *) pTcb->pFpContext;
  814.     return (OK);
  815. #endif /* INCLUDE_HW_FP */
  816. #ifdef INCLUDE_ALTIVEC
  817. case WDB_REG_SET_AV:
  818.             if (ALTIVEC_CONTEXT_GET(pTcb) == NULL)
  819. return (ERROR); /* no coprocessor support */
  820.     *ppRegSet = (char *) pTcb->spare4;
  821.     return (OK);
  822. #endif /* INCLUDE_ALTIVEC */
  823. #ifdef  INCLUDE_DSP
  824. case WDB_REG_SET_DSP:
  825.     if (pTcb == pTaskLastDspTcb)
  826. dspSave (pTaskLastDspTcb->pDspContext);
  827.     if (pTcb->pDspContext)
  828. {
  829. *ppRegSet = (char *) pTcb->pDspContext;
  830. return (OK);
  831. }
  832.     return (ERROR);
  833. #endif /* INCLUDE_DSP */
  834. default:
  835.     return (ERROR);
  836. }
  837.     }
  838. /******************************************************************************
  839. *
  840. * vxSemCreate - create a SEMAPHORE
  841. */
  842. LOCAL void * vxSemCreate (void)
  843.     {
  844.     return ((void *)semBCreate (0, 0));
  845.     }
  846. /******************************************************************************
  847. *
  848. * vxSemGive - give a semaphore
  849. */
  850. LOCAL STATUS vxSemGive
  851.     (
  852.     void * semId
  853.     )
  854.     {
  855.     return (semGive ((SEM_ID)semId));
  856.     }
  857. /******************************************************************************
  858. *
  859. * vxSemTake - take a semaphore
  860. */
  861. LOCAL STATUS vxSemTake
  862.     (
  863.     void * semId,
  864.     struct timeval * tv
  865.     )
  866.     {
  867.     return (semTake ((SEM_ID) semId, 
  868. (tv == NULL ? WAIT_FOREVER :
  869. tv->tv_sec * sysClkRateGet() +
  870. (tv->tv_usec * sysClkRateGet()) / MILLION)));
  871.     }
  872. #endif /* INCLUDE_VXWORKS_KERNEL */
  873. /******************************************************************************
  874. *
  875. * vxExcHookAdd -
  876. */
  877. LOCAL void (*vxExcHook)();
  878. LOCAL int vxExcHookWrapper (int vec, char *pESF, WDB_IU_REGS *pRegs)
  879.     {
  880.     WDB_CTX context;
  881.     static int restartCnt;
  882.     extern int wdbTaskId;
  883.     if (INT_CONTEXT() || wdbIsNowExternal() || (taskIdCurrent == 0))
  884. context.contextType = WDB_CTX_SYSTEM;
  885.     else
  886. context.contextType = WDB_CTX_TASK;
  887.     context.contextId = (int)taskIdCurrent;
  888.     (*vxExcHook)(context, vec, pESF, pRegs);
  889.     /*
  890.      * if the exception is in the agent task, restart the agent
  891.      * after a delay.
  892.      */
  893.     if (((int)taskIdCurrent == wdbTaskId) && (restartCnt < WDB_MAX_RESTARTS))
  894. {
  895. restartCnt++;
  896. if (_func_logMsg != NULL)
  897.     _func_logMsg ("WDB exception. restarting agent in %d seconds...n",
  898. WDB_RESTART_TIME, 0,0,0,0,0);
  899. taskDelay (sysClkRateGet() * WDB_RESTART_TIME);
  900. taskRestart (0);
  901. }
  902.     return (FALSE);
  903.     }
  904. LOCAL void vxExcHookAdd
  905.     (
  906.     void (*hook)()
  907.     )
  908.     {
  909.     vxExcHook = hook;
  910.     _func_excBaseHook = vxExcHookWrapper;
  911.     }
  912. /******************************************************************************
  913. *
  914. * __wdbTaskDeleteHook -
  915. */ 
  916. LOCAL int __wdbTaskDeleteHook
  917.     (
  918.     WIND_TCB *pTcb
  919.     )
  920.     {
  921.     WDB_CTX ctx;
  922.     void (*hook)();
  923.     hook = pTcb->wdbInfo.wdbExitHook;
  924.     if (hook != NULL)
  925. {
  926. ctx.contextType = WDB_CTX_TASK;
  927. ctx.contextId = (UINT32)pTcb;
  928. (*hook) (ctx, pTcb->exitCode, pTcb->errorStatus);
  929. }
  930.     return (OK);
  931.     }
  932. /******************************************************************************
  933. *
  934. * vxTaskDeleteHookAdd - task-specific delete hook (one per task).
  935. *
  936. * currently only one hook per task.
  937. */ 
  938. LOCAL STATUS vxTaskDeleteHookAdd
  939.     (
  940.     UINT32 tid,
  941.     void (*hook)()
  942.     )
  943.     {
  944.     static int initialized = FALSE;
  945.     if (taskIdVerify ((int)tid) == ERROR)
  946. return (ERROR);
  947.     (taskTcb (tid)->wdbInfo).wdbExitHook = hook;
  948.     if (!initialized)
  949. {
  950. taskDeleteHookAdd (__wdbTaskDeleteHook);
  951. initialized = TRUE;
  952. }
  953.     return (OK);
  954.     }
  955. /******************************************************************************
  956. *
  957. * __wdbTaskCreateHook - task create hook
  958. *
  959. * This hook is called each time a task is created.
  960. *
  961. * RETURNS : OK always
  962. */ 
  963. LOCAL int __wdbTaskCreateHook
  964.     (
  965.     WIND_TCB * pTcb
  966.     )
  967.     {
  968.     WDB_CTX createdCtx;
  969.     WDB_CTX creationCtx;
  970.     if (wdbCreateHook != NULL)
  971. {
  972. /* fill createdCtx structure */
  973. createdCtx.contextType = WDB_CTX_TASK;
  974. createdCtx.contextId = (UINT32)pTcb;
  975. /* fill creationCtx structure */
  976. creationCtx.contextType = WDB_CTX_TASK;
  977. creationCtx.contextId = (UINT32)taskIdCurrent;
  978. (*wdbCreateHook) (&createdCtx, &creationCtx);
  979. }
  980.     return (OK);
  981.     }
  982. /******************************************************************************
  983. *
  984. * vxTaskCreateHookAdd - install WDB task create hook.
  985. *
  986. * This routine installs or remove the WDB task create hook. 
  987. *
  988. * RETURNS : OK always.
  989. */ 
  990. LOCAL STATUS vxTaskCreateHookAdd
  991.     (
  992.     void (*hook)()
  993.     )
  994.     {
  995.     static int initialized = FALSE;
  996.     wdbCreateHook = hook;
  997.     if ((hook == NULL) && initialized) /* remove task creation hook */
  998. {
  999. taskCreateHookDelete (__wdbTaskCreateHook);
  1000. initialized = FALSE;
  1001. }
  1002.     else if (!initialized) /* install task creation hook */
  1003. {
  1004. taskCreateHookAdd (__wdbTaskCreateHook);
  1005. initialized = TRUE;
  1006. }
  1007.     return (OK);
  1008.     }
  1009. /******************************************************************************
  1010. *
  1011. * wdbRtIfInit - Initialize pointers to the VxWorks routines.
  1012. */
  1013. LOCAL void wdbRtIfInit ()
  1014.     {
  1015.     int  ix = 0;
  1016.     WDB_RT_IF * pRtIf = &wdbRtIf;
  1017.     bzero ((char *)pRtIf, sizeof (WDB_RT_IF));
  1018.     pRtIf->rtInfoGet = wdbRtInfoGet;
  1019.     pRtIf->reboot = vxReboot;
  1020.     pRtIf->cacheTextUpdate = (void (*)())cacheLib.textUpdateRtn;
  1021.     pRtIf->memProtect   = vxMemProtect;
  1022.     pRtIf->memProbe = (STATUS (*)())vxMemProbe;
  1023.     pRtIf->excHookAdd = vxExcHookAdd;
  1024. #ifdef INCLUDE_VXWORKS_KERNEL
  1025.     pRtIf->taskCreate = vxTaskCreate;
  1026.     pRtIf->taskResume = vxTaskResume;
  1027.     pRtIf->taskSuspend = vxTaskSuspend;
  1028.     pRtIf->taskDelete = vxTaskDelete;
  1029.     pRtIf->taskLock = (VOIDFUNCPTR) taskLock;
  1030.     pRtIf->taskUnlock = (VOIDFUNCPTR) taskUnlock;
  1031.     pRtIf->taskRegsSet = vxTaskRegsSet;
  1032.     pRtIf->taskRegsGet  = vxTaskRegsGet;
  1033.     pRtIf->malloc = malloc;
  1034.     pRtIf->free = free;
  1035.     pRtIf->semCreate = vxSemCreate;
  1036.     pRtIf->semGive = vxSemGive;
  1037.     pRtIf->semTake = vxSemTake;
  1038.     pRtIf->taskDeleteHookAdd = vxTaskDeleteHookAdd;
  1039.     pRtIf->taskSwitchHookAdd = (STATUS (*)())taskSwitchHookAdd;
  1040.     pRtIf->taskCreateHookAdd = vxTaskCreateHookAdd;
  1041. #endif /* INCLUDE_VXWORKS_KERNEL */
  1042.     /* first check if boot line is empty (eg : no network) */
  1043.     if (*sysBootLine != EOS)
  1044. {
  1045. for (ix = 0; ix < MAX_LEN; ix ++)
  1046.     {
  1047.     if (*(sysBootLine + ix) == ')')
  1048. {
  1049. ix++;
  1050. break;
  1051. }
  1052.     }
  1053. /* Copy the bootline following the ')' to vxBootFile */
  1054. strncpy (vxBootFile, sysBootLine + ix, sizeof(vxBootFile));
  1055. /* Truncate vxBootFile at the first space */
  1056. for (ix = 0; ix < MAX_LEN - 1; ix ++)
  1057.     {
  1058.     if (*(vxBootFile + ix) == ' ')
  1059. break;
  1060.     }
  1061. }
  1062.     *(vxBootFile + ix) = '';
  1063.     wdbInstallRtIf (pRtIf);
  1064.     }
  1065. /******************************************************************************
  1066. *
  1067. * wdbCommIfInit - Initialize the agent's communction interface
  1068. *
  1069. * RETURNS : OK or error if we can't initialize the communication interface.
  1070. *
  1071. * NOMANUAL
  1072. */
  1073. LOCAL STATUS wdbCommIfInit ()
  1074.     {
  1075.     static uint_t wdbInBuf   [WDB_MTU/4];
  1076.     static uint_t wdbOutBuf   [WDB_MTU/4];
  1077.     static WDB_XPORT wdbXport;
  1078.     static WDB_COMM_IF wdbCommIf;
  1079.     WDB_COMM_IF * pCommIf = &wdbCommIf;
  1080.     wdbMbufInit ();
  1081. #if (WDB_COMM_TYPE == WDB_COMM_NETWORK)
  1082.     /* UDP sockets - supports a task agent */
  1083.     if (wdbUdpSockIfInit (pCommIf) == ERROR)
  1084. return (ERROR);
  1085. #endif /* (WDB_COMM_TYPE == WDB_COMM_NETWORK) */
  1086. #if (WDB_COMM_TYPE == WDB_COMM_TYCODRV_5_2)
  1087.     {
  1088.     /* SLIP lite built on a VxWorks serial driver - supports a task agent */
  1089.     static WDB_TYCO_SIO_CHAN tyCoSioChan; /* serial I/O device */
  1090.     static WDB_SLIP_PKT_DEV  wdbSlipPktDev; /* SLIP packet device */
  1091.     if (wdbTyCoDevInit (&tyCoSioChan, WDB_TTY_DEV_NAME, WDB_TTY_BAUD))
  1092. return (ERROR);
  1093. #ifdef INCLUDE_WDB_TTY_TEST
  1094.     wdbSioTest ((SIO_CHAN *)&tyCoSioChan, SIO_MODE_INT, 0);
  1095. #endif /* INCLUDE_WDB_TTY_TEST */
  1096.     wdbSlipPktDevInit (&wdbSlipPktDev, (SIO_CHAN *)&tyCoSioChan, udpRcv);
  1097.     if (udpCommIfInit (pCommIf, &wdbSlipPktDev.wdbDrvIf))
  1098. return (ERROR);
  1099.     }
  1100. #endif /* (WDB_COMM_TYPE == WDB_COMM_TYCODRV_5_2) */
  1101. #if (WDB_COMM_TYPE == WDB_COMM_ULIP)
  1102.     {
  1103.     /* ULIP packet driver (VxSim only) - supports task or external agent */
  1104.     static WDB_ULIP_PKT_DEV wdbUlipPktDev; /* ULIP packet device */
  1105.     wdbUlipPktDevInit (&wdbUlipPktDev, WDB_ULIP_DEV, udpRcv);
  1106.     if (udpCommIfInit (pCommIf, &wdbUlipPktDev.wdbDrvIf))
  1107. return (ERROR);
  1108.     }
  1109. #endif /* (WDB_COMM_TYPE == WDB_COMM_ULIP) */
  1110. #if (WDB_COMM_TYPE == WDB_COMM_SERIAL)
  1111.     {
  1112.     /* SLIP-lite over a raw serial channel - supports task or external agent */
  1113.     SIO_CHAN * pSioChan; /* serial I/O channel */
  1114.     static WDB_SLIP_PKT_DEV wdbSlipPktDev; /* SLIP packet device */
  1115.     if ((pSioChan = sysSerialChanGet (WDB_TTY_CHANNEL)) == (SIO_CHAN *)ERROR)
  1116. return (ERROR);
  1117.     sioIoctl (pSioChan, SIO_BAUD_SET, (void *)WDB_TTY_BAUD);
  1118. #ifdef INCLUDE_WDB_TTY_TEST
  1119.     /* test in polled mode if the kernel hasn't started */
  1120.     if (taskIdCurrent == 0)
  1121. wdbSioTest (pSioChan, SIO_MODE_POLL, 0);
  1122.     else
  1123. wdbSioTest (pSioChan, SIO_MODE_INT, 0);
  1124. #endif /* INCLUDE_WDB_TTY_TEST */
  1125.     wdbSlipPktDevInit (&wdbSlipPktDev, pSioChan, udpRcv);
  1126.     if (udpCommIfInit (pCommIf, &wdbSlipPktDev.wdbDrvIf))
  1127. return (ERROR);
  1128. #if (CPU==SIMHPPA)
  1129.     sysSerialWDBSetup ();
  1130. #endif /* CPU==SIMHPPA */
  1131.     }
  1132. #endif /* (WDB_COMM_TYPE == WDB_COMM_SERIAL) */
  1133. #if     (WDB_COMM_TYPE == WDB_COMM_NETROM)
  1134.     {
  1135.     /* netrom packet driver - supports task or external agent */
  1136.     int dpOffset; /* offset of dualport RAM */
  1137.     static WDB_NETROM_PKT_DEV wdbNetromPktDev; /* NETROM packet device */
  1138.     dpOffset = (WDB_NETROM_ROMSIZE - DUALPORT_SIZE) * WDB_NETROM_WIDTH;
  1139.     wdbNetromPktDevInit (&wdbNetromPktDev, (caddr_t)ROM_BASE_ADRS + dpOffset,
  1140.  WDB_NETROM_WIDTH, WDB_NETROM_INDEX,
  1141.  WDB_NETROM_NUM_ACCESS, udpRcv,
  1142.  WDB_NETROM_POLL_DELAY);
  1143.     if (udpCommIfInit (pCommIf, &wdbNetromPktDev.wdbDrvIf))
  1144. return (ERROR);
  1145.     }
  1146. #endif  /* (WDB_COMM_TYPE == WDB_COMM_NETROM) */
  1147. #if     (WDB_COMM_TYPE == WDB_COMM_VTMD)
  1148.     {
  1149.     /* vision packet driver - supports task or external agent */
  1150.     static WDB_VISION_PKT_DEV wdbVisionPktDev; /* custom packet device */
  1151.     wdbVisionPktDevInit (&wdbVisionPktDev, udpRcv);
  1152.     if (udpCommIfInit (pCommIf, &wdbVisionPktDev.wdbDrvIf) == ERROR)
  1153. return (ERROR);
  1154.     }
  1155. #endif  /* (WDB_COMM_TYPE == WDB_COMM_VTMD) */
  1156. #if     (WDB_COMM_TYPE == WDB_COMM_CUSTOM)
  1157.     {
  1158.     /* custom packet driver - supports task or external agent */
  1159.     static WDB_CUSTOM_PKT_DEV wdbCustomPktDev; /* custom packet device */
  1160.     wdbCustomPktDevInit (&wdbCustomPktDev, udpRcv);
  1161.     if (udpCommIfInit (pCommIf, &wdbCustomPktDev.wdbDrvIf) == ERROR)
  1162. return (ERROR);
  1163.     }
  1164. #endif  /* (WDB_COMM_TYPE == WDB_COMM_CUSTOM) */
  1165. #if (WDB_COMM_TYPE == WDB_COMM_END)
  1166.     {
  1167.     /* END agent - supports a network MUX/END agent */
  1168.     static WDB_END_PKT_DEV wdbEndPktDev; /* END packet device */
  1169.     END_TBL_ENTRY * pDevTbl;
  1170.     END_OBJ * pEnd = NULL;
  1171.     char devName[END_NAME_MAX];
  1172.     char wdbDev[END_NAME_MAX];
  1173.     int unit = 0;
  1174.     int i;
  1175.     char *pStr;
  1176.     /* find the END Device Table entry corresponding to the boot device */
  1177.     bzero(wdbDev, END_NAME_MAX);
  1178.     if (strncmp("flash", sysBootParams.bootDev, 5) == 0)
  1179.     {
  1180.         pStr = (char *)&sysBootParams.other;
  1181.         if (pStr != EOS)
  1182.         {
  1183.             i = 0;
  1184.             while (!isdigit (*pStr) && *pStr != EOS && i < END_NAME_MAX)
  1185.             {
  1186.                 wdbDev[i++] = *pStr;
  1187.                 pStr++;
  1188.             }
  1189.     
  1190.             if (*pStr != EOS && i < END_NAME_MAX)
  1191.             {
  1192.                 sscanf (pStr, "%d", &unit);
  1193.             }
  1194.         }
  1195.     }
  1196.     else
  1197.     {
  1198.         strncpy(wdbDev, sysBootParams.bootDev, END_NAME_MAX);
  1199.         unit = sysBootParams.unitNum;
  1200.     }
  1201.     for(pDevTbl = endDevTbl; pDevTbl->endLoadFunc != NULL; pDevTbl++)
  1202. {
  1203. /* get the name of the device by passing argument devName = '' */
  1204.     
  1205. bzero (devName, END_NAME_MAX);
  1206. if (pDevTbl->endLoadFunc(devName, NULL) != 0)
  1207.     {
  1208.     if (_func_logMsg != NULL)
  1209. _func_logMsg ("could not get device name!n",0,0,0,0,0,0);
  1210.     return (ERROR);
  1211.     }
  1212. /* compare the name of the device to the boot device selected */
  1213. if (strncmp (wdbDev, (const char *) devName,
  1214.      strlen((const char *) devName)) == 0)
  1215.     {
  1216.     /* Verify that the device unit number matches */ 
  1217.     if (pDevTbl->unit == unit)
  1218. break;
  1219.     }
  1220. }
  1221.     /* if no END Device found, default to first valid table entry */
  1222.     if (pDevTbl->endLoadFunc == NULL)
  1223. {
  1224. if (endDevTbl->endLoadFunc == NULL)
  1225.     {
  1226.     if (_func_logMsg != NULL)
  1227. _func_logMsg ("no device in END device table!n", 0, 0, 0,
  1228.       0, 0, 0);
  1229.     return (ERROR);
  1230.     }
  1231. else
  1232.     pDevTbl = endDevTbl;
  1233. }
  1234.     /* Check END device initialization by netLibInit */ 
  1235.     if (!pDevTbl->processed)
  1236.         {
  1237. if (_func_logMsg != NULL)
  1238.     _func_logMsg ("Network END device not initialized!n",
  1239.        0, 0, 0, 0, 0, 0);
  1240. return (ERROR);
  1241.         }
  1242.     /* get the END_OBJ by name and unit */
  1243.     pEnd = endFindByName (devName, pDevTbl->unit);
  1244.     if (pEnd == NULL)
  1245. {
  1246. if (_func_logMsg != NULL)
  1247.     _func_logMsg ("Could not find device %s unit %d!n",
  1248.   sysBootParams.bootDev, sysBootParams.unitNum,
  1249.   0, 0, 0, 0);
  1250.             return (ERROR);
  1251. }
  1252.     if (wdbEndPktDevInit(&wdbEndPktDev, udpRcv,
  1253.                      (char *)pEnd->devObject.name,
  1254.                      pEnd->devObject.unit) == ERROR)
  1255. return (ERROR);
  1256.     if (udpCommIfInit(pCommIf, &wdbEndPktDev.wdbDrvIf) == ERROR)
  1257. return (ERROR);
  1258.     }
  1259. #endif /* (WDB_COMM_TYPE == WDB_COMM_END) */
  1260. #if     (WDB_COMM_TYPE == WDB_COMM_PIPE)
  1261.     {
  1262.     static WDB_PIPE_PKT_DEV wdbPipePktDev; /* Pipe packet device */
  1263.     if (wdbPipePktDevInit(&wdbPipePktDev, udpRcv) == ERROR)
  1264. return (ERROR);
  1265.     if (udpCommIfInit(pCommIf, &wdbPipePktDev.wdbDrvIf) == ERROR)
  1266. return (ERROR);
  1267.     }
  1268. #endif  /* (WDB_COMM_TYPE == WDB_COMM_PIPE) */
  1269.     /*
  1270.      * Install the agents communication interface and RPC transport handle.
  1271.      * Currently only one agent will be active at a time, so both
  1272.      * agents can share the same communication interface and XPORT handle.
  1273.      */
  1274.     wdbRpcXportInit  (&wdbXport, pCommIf, (char *)wdbInBuf,
  1275.       (char *)wdbOutBuf, WDB_MTU);
  1276.     wdbInstallCommIf (pCommIf, &wdbXport);
  1277. #if (CPU==SIMHPPA) && defined(INCLUDE_SLIP) && 
  1278. (WDB_COMM_TYPE == WDB_COMM_NETWORK)
  1279.     {
  1280.     UNIX_CHAN *pChan = (UNIX_CHAN *) sysSerialChanGet (SLIP_TTY);
  1281.     /*
  1282.      * Begin polling for connection request from tgtsvr.  This is necessary
  1283.      * because an earlier connection may have left the pipe in a state in
  1284.      * which SIGIO will not be generated until pipe is read.
  1285.      */
  1286.     wdSlipConnect = wdCreate ();
  1287.     usrWdbPollForConnect (FD_TO_IVEC (pChan->u_fd));
  1288.     }
  1289. #endif /* (CPU==SIMHPPA) && defined(INCLUDE_SLIP) ... */
  1290.     return (OK);
  1291.     }
  1292. /******************************************************************************
  1293. *
  1294. * wdbMbufInit - initialize the agent's mbuf memory allocator.
  1295. *
  1296. * wdbMbufLib manages I/O buffers for the agent since the agent
  1297. * can't use malloc().
  1298. *
  1299. * If the agent is ever hooked up to a network driver that uses standard
  1300. * MGET/MFREE for mbuf managment, then the routines wdbMBufAlloc()
  1301. * and wdbMBufFree() below should be changed accordingly.
  1302. */ 
  1303. LOCAL void wdbMbufInit (void)
  1304.     {
  1305.     static struct mbuf mbufs[NUM_MBUFS];
  1306.     static CL_BLK      wdbClBlks [WDB_NUM_CL_BLKS];
  1307.     bufPoolInit (&wdbMbufPool, (char *)mbufs, NUM_MBUFS, sizeof (struct mbuf));
  1308.     bufPoolInit (&wdbClBlkPool, (char *)wdbClBlks, WDB_NUM_CL_BLKS,
  1309.                  sizeof (CL_BLK));
  1310.     }
  1311. /******************************************************************************
  1312. *
  1313. * wdbMbufAlloc - allocate an mbuf
  1314. *
  1315. * RETURNS: a pointer to an mbuf, or NULL on error.
  1316. */ 
  1317. struct mbuf * wdbMbufAlloc (void)
  1318.     {
  1319.     struct mbuf * pMbuf;
  1320.     CL_BLK_ID   pClBlk;
  1321.     pMbuf = (struct mbuf *)bufAlloc (&wdbMbufPool);
  1322.     if (pMbuf == NULL)
  1323.         return (NULL); 
  1324.     pClBlk = (CL_BLK_ID) bufAlloc (&wdbClBlkPool);
  1325.     
  1326.     if (pClBlk == NULL)
  1327.         {
  1328.         wdbMbufFree (pMbuf);
  1329. return (NULL);
  1330.         }
  1331.     pMbuf->m_next = NULL;
  1332.     pMbuf->m_nextpkt = NULL;
  1333.     pMbuf->m_flags = 0;
  1334.     pMbuf->pClBlk  = pClBlk;
  1335.     return (pMbuf);
  1336.     }
  1337. /******************************************************************************
  1338. *
  1339. * wdbMbufFree - free an mbuf
  1340. */ 
  1341. void wdbMbufFree
  1342.     (
  1343.     struct mbuf * pMbuf /* mbuf chain to free */
  1344.     )
  1345.     {
  1346.     /* if it is a cluster, see if we need to perform a callback */
  1347.     if (pMbuf->m_flags & M_EXT)
  1348. {
  1349. if (--(pMbuf->m_extRefCnt) <= 0)
  1350.             {
  1351.             if (pMbuf->m_extFreeRtn != NULL)
  1352.                 {
  1353.                 (*pMbuf->m_extFreeRtn) (pMbuf->m_extArg1, pMbuf->m_extArg2, 
  1354.                                         pMbuf->m_extArg3);
  1355.                 }
  1356.             /* free the cluster blk */
  1357.             bufFree (&wdbClBlkPool, (char *) pMbuf->pClBlk);
  1358.             }
  1359. }
  1360.     bufFree (&wdbMbufPool, (char *)pMbuf);
  1361.     }
  1362. #if (CPU==SIMHPPA) && defined(INCLUDE_SLIP) && 
  1363. (WDB_COMM_TYPE == WDB_COMM_NETWORK)
  1364. /******************************************************************************
  1365. *
  1366. *  usrWdbPollForConnect - poll SLIP input pipe
  1367. *
  1368. * INTERNAL
  1369. * This routine is not normally part of a BSP.
  1370. *
  1371. * RETURNS: N/A
  1372. *
  1373. * NOMANUAL
  1374. */
  1375. LOCAL void usrWdbPollForConnect
  1376.     (
  1377.     int slipIntr                                /* SLIP interrupt number */
  1378.     )
  1379.     {
  1380.     intCatch (slipIntr);                        /* fake I/O interrupt */
  1381.     if (wdbTargetIsConnected ())
  1382. {
  1383. wdDelete (wdSlipConnect);               /* stop polling */
  1384. s_asyncio (0);
  1385. s_asyncio (1);
  1386. }
  1387.     else
  1388. wdStart (wdSlipConnect, sysClkRateGet() * 3,
  1389. (FUNCPTR) usrWdbPollForConnect, slipIntr);
  1390.     }
  1391. #endif /* (CPU==SIMHPPA) && defined(INCLUDE_SLIP) */