home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / alt / sources / 2867 < prev    next >
Encoding:
Internet Message Format  |  1992-12-23  |  127.2 KB

  1. Path: sparky!uunet!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!princeton!rutgers!rochester!rit!moscom!pap
  2. From: pap@moscom.com (Patrick Palmer)
  3. Newsgroups: alt.sources
  4. Subject: YAMPC (part 2/2)
  5. Message-ID: <4809@moscom.com>
  6. Date: 23 Dec 92 17:27:55 GMT
  7. Organization: Moscom Corp., E. Rochester, NY
  8. Lines: 4857
  9. X-Newsreader: TIN [version 1.3 beta PL7]
  10.  
  11. --------CUT HERE--------
  12. cat << 'Zaphod for prez' | sed 's/X\(.*\)X/\1/' > brkpts.c
  13. XX
  14. X/* ----------------------------------------------------------------------- *\X
  15. X******************************************************************************X
  16. XX
  17. X  PROGRAM NAME: Break PointsX
  18. XX
  19. X  PROGRAMMER:    Patrick Palmer                        DATE: 8/17/90 X
  20. X          X
  21. X  DESCRIPTION OF PROGRAM: X
  22. X    These are all of the support routines for using break pointsX
  23. X  in the debugging mode.  Adding, Deleting, and listing are allX
  24. X  included.  A simple array of integers stores the break point list.X
  25. X X
  26. X******************************************************************************X
  27. XX
  28. X        This program is free software; you can redistribute it and/orX
  29. X        modify it under the terms of the GNU General Public LicenseX
  30. X        (version 2) as published by the Free Software Foundation.X
  31. XX
  32. X        This program is distributed in the hope that is will be useful,X
  33. X        but WITHOUT ANY WARRANTY; without even the implied warrenty ofX
  34. X        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See theX
  35. X        GNU General Public License for more details.X
  36. X        X
  37. X        You should have received a copy of the GNU General Public X
  38. X        License along with this program; if not, write to the FreeX
  39. X        Software Foundation, Inc., 675 Mass Ave, Cambridge, MAX
  40. X        02139, USA.X
  41. XX
  42. X        YAMPC Microcode Development KitX
  43. X        (C) 1992 by Patrick PalmerX
  44. XX
  45. X******************************************************************************X
  46. XX
  47. X  PROGRAM REVISION LOGX
  48. X  X
  49. X        DATE               DESCRIPTION OF CHANGE                PROGRAMMERX
  50. X      --------  ----------------------------------------------  ----------X
  51. X      08/17/90  YAMPC - Version 1.0                             PAPX
  52. X      11/17/90  Interrupts, Bug Fixes - Version 1.1             PAPX
  53. X      01/11/92  Distribution version - Version 1.2              PAPX
  54. XX
  55. X***************************************************************************  X
  56. X\* ------------------------------------------------------------------------ */X
  57. XX
  58. XX
  59. X#include <stdio.h>X
  60. X#include "main.h"X
  61. X#include "misc.h"X
  62. XX
  63. X/* need to the current mpc pointer */X
  64. Xextern int mpcptr;X
  65. XX
  66. X/* The pointer into the command line arguments */X
  67. Xextern int p_position;X
  68. XX
  69. X/* breakpoint list */X
  70. Xint brkpts[NUMBRKPTS];X
  71. XX
  72. XX
  73. X/****************************************************************************X
  74. X *X
  75. X * FUNCTION:        setBrkPts()X
  76. X * PURPOSE:            initialize all break points to not used (-1)X
  77. X * ARGUMENTS:        noneX
  78. X * RETURNS:            noneX
  79. X * NOTES:            X
  80. X *X
  81. X ***************************************************************************/X
  82. XX
  83. XVOIDX
  84. XsetBrkPts ( )X
  85. X{X
  86. X    int temp = 0;X
  87. XX
  88. X    for ( ; temp < NUMBRKPTS; temp++ )X
  89. X        brkpts[temp] = -1;X
  90. X}X
  91. XX
  92. XX
  93. XX
  94. X/****************************************************************************X
  95. X *X
  96. X * FUNCTION:        checkBrkPts()X
  97. X * PURPOSE:            determine if the execution should breakX
  98. X * ARGUMENTS:        noneX
  99. X * RETURNS:            1 - breakX
  100. X *                    0 - don't breakX
  101. X * NOTES:            this routine uses the mpcptr globalX
  102. X *X
  103. X ***************************************************************************/X
  104. XX
  105. XintX
  106. XcheckBrkPts ( )X
  107. X{X
  108. X    int temp;X
  109. XX
  110. X    /* check current mpc vs. breakpoint list */X
  111. X    for ( temp = 0; temp < NUMBRKPTS; temp++ )X
  112. X        if ( brkpts[temp] == mpcptr )X
  113. X            return 1;X
  114. XX
  115. X    /* none found */X
  116. X    return 0;X
  117. X}X
  118. XX
  119. XX
  120. X/****************************************************************************X
  121. X *X
  122. X * FUNCTION:        showBrkPts()X
  123. X * PURPOSE:            show all the current break pointsX
  124. X * ARGUMENTS:        command entry to display if misuseX
  125. X * RETURNS:            P_CONT - continue processingX
  126. X * NOTES:            noneX
  127. X *X
  128. X ***************************************************************************/X
  129. XX
  130. XintX
  131. XshowBrkPts ( which )X
  132. X    int which;X
  133. X{X
  134. X    int temp = 0, disp = 0;X
  135. X    U_Ret rv;X
  136. XX
  137. X    /* make sure there are no more arguments */X
  138. X    getEntry ( &rv, P_STR );X
  139. X    if ( p_position != -1 ) {X
  140. X        misuse ( which );X
  141. X        return P_CONT;X
  142. X    }X
  143. XX
  144. X    /* print out list */X
  145. X    for ( ; temp < NUMBRKPTS; temp++ )X
  146. X        if ( brkpts[temp] != -1 ) X
  147. X            if ( disp == 0 )X
  148. X                printf ( "The breakpoint list: %x", brkpts[temp], disp++ );X
  149. X            else    printf ( ", %x", brkpts[temp] );X
  150. XX
  151. X    /* End the list */X
  152. X    if ( disp == 0 )X
  153. X        printf ( "There are no breakpoints set.\n" );X
  154. X    else    printf ( ".\n" );X
  155. XX
  156. X    return P_CONT;X
  157. X}X
  158. XX
  159. XX
  160. XX
  161. X/****************************************************************************X
  162. X *X
  163. X * FUNCTION:        addBrkPts()X
  164. X * PURPOSE:            add an address into the breakpoint listX
  165. X * ARGUMENTS:        which - which command entry for misuse displayX
  166. X * RETURNS:            P_CONT - continue processingX
  167. X * NOTES:            noneX
  168. X *X
  169. X ***************************************************************************/X
  170. XX
  171. XintX
  172. XaddBrkPts ( which )X
  173. X    int which;X
  174. X{X
  175. X    int temp, place = -1;X
  176. X    U_Ret rv;X
  177. XX
  178. X    /* get entry off of the command line */X
  179. X    if ( ( getEntry ( &rv, P_NUM ) != 0 ) || p_position == -1 ) {X
  180. X        misuse ( which );X
  181. X        return P_CONT;X
  182. X    }X
  183. X    X
  184. X    /* make sure there are no more arguments */X
  185. X    getEntry ( &rv, P_STR );X
  186. X    if ( p_position != -1 ) {X
  187. X        misuse ( which );X
  188. X        return P_CONT;X
  189. X    }X
  190. X    X
  191. X    /* check if the address is already in the list */X
  192. X    for ( temp = 0; temp < NUMBRKPTS; temp++ )X
  193. X        if ( rv.ival == brkpts[temp] ) {X
  194. X            printf ( "Address already in breakpoint list.\n" );X
  195. X            return P_CONT;X
  196. X        }X
  197. XX
  198. X    /* look for an available spot */X
  199. X    temp = 0;X
  200. X    for ( temp = 0; temp < NUMBRKPTS && place == -1; temp++ )X
  201. X        if ( brkpts[temp] == -1 )X
  202. X            place = temp;X
  203. XX
  204. X    /* Tell user that there was no entry places */X
  205. X    if ( place == -1 ) {X
  206. X        printf ( "All %d of the breakpoint entries are filled.\n", NUMBRKPTS );X
  207. X        return P_CONT;X
  208. X    }X
  209. XX
  210. X    /* place the address into the list */X
  211. X    brkpts[place] = rv.ival;X
  212. XX
  213. X    return P_CONT;X
  214. X}X
  215. XX
  216. XX
  217. XX
  218. X/****************************************************************************X
  219. X *X
  220. X * FUNCTION:        delBrkPts()X
  221. X * PURPOSE:            delete an address from the breakpoint listX
  222. X * ARGUMENTS:        which - which command entry for misuse displayX
  223. X * RETURNS:            P_CONT - continue processingX
  224. X * NOTES:            noneX
  225. X *X
  226. X ***************************************************************************/X
  227. XX
  228. XdelBrkPts ( which )X
  229. X    int which;X
  230. X{X
  231. X    int temp, found = 0;X
  232. X    U_Ret rv;X
  233. XX
  234. X    /* get the address to delete from the list */X
  235. X    if ( ( getEntry ( &rv, P_NUM ) ) || p_position == -1 ) {X
  236. X        misuse ( which );X
  237. X        return P_CONT;X
  238. X    }X
  239. XX
  240. X    /* make sure there are no more entries */X
  241. X    getEntry ( &rv, P_STR );X
  242. X    if ( p_position != -1 ) {X
  243. X        misuse ( which );X
  244. X        return P_CONT;X
  245. X    }X
  246. XX
  247. X    /* look for the entry and delete it */X
  248. X    for ( temp = 0; temp < NUMBRKPTS; temp++ )X
  249. X        if ( brkpts[temp] == rv.ival )X
  250. X            brkpts[temp] = -1, found = 1;X
  251. XX
  252. X    /* Display message if there was no entry */X
  253. X    if ( ! found ) X
  254. X        printf ( "The address was not found in the breakpoint list.\n" );X
  255. XX
  256. X    return P_CONT;X
  257. X}X
  258. XX
  259. XX
  260. Zaphod for prez
  261. cat << 'Zaphod for prez' | sed 's/X\(.*\)X/\1/' > correct.c
  262. XX
  263. X/* ----------------------------------------------------------------------- *\X
  264. X******************************************************************************X
  265. XX
  266. X  PROGRAM NAME: Correctional File Support RoutinesX
  267. XX
  268. X  PROGRAMMER:    Patrick Palmer                    DATE: 8/17/90 X
  269. X          X
  270. X  DESCRIPTION OF PROGRAM: X
  271. X     This file contains all of the file support routines for theX
  272. X  correctional file use.  This includes the creation and the readingX
  273. X  in of the correction file. X
  274. X X
  275. X******************************************************************************X
  276. XX
  277. X        This program is free software; you can redistribute it and/orX
  278. X        modify it under the terms of the GNU General Public LicenseX
  279. X        (version 2) as published by the Free Software Foundation.X
  280. XX
  281. X        This program is distributed in the hope that is will be useful,X
  282. X        but WITHOUT ANY WARRANTY; without even the implied warrenty ofX
  283. X        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See theX
  284. X        GNU General Public License for more details.X
  285. X        X
  286. X        You should have received a copy of the GNU General Public X
  287. X        License along with this program; if not, write to the FreeX
  288. X        Software Foundation, Inc., 675 Mass Ave, Cambridge, MAX
  289. X        02139, USA.X
  290. XX
  291. X        YAMPC Microcode Development KitX
  292. X        (C) 1992 by Patrick PalmerX
  293. XX
  294. X******************************************************************************X
  295. XX
  296. XX
  297. X  PROGRAM REVISION LOGX
  298. X  X
  299. X        DATE               DESCRIPTION OF CHANGE                PROGRAMMERX
  300. X      --------  ----------------------------------------------  ----------X
  301. X      08/17/90  YAMPC - Version 1.0                             PAPX
  302. X      11/17/90  Interrupts, Bug Fixes - Version 1.1             PAPX
  303. X      01/11/92  Distribution version - Version 1.2              PAPX
  304. XX
  305. X***************************************************************************  X
  306. X\* ------------------------------------------------------------------------ */X
  307. XX
  308. XX
  309. X/* This is the module for the correction file routines */X
  310. XX
  311. X#include <stdio.h>X
  312. X#include <ctype.h>X
  313. X#include "main.h"X
  314. X#include "misc.h"X
  315. XX
  316. X/* needed parameters */X
  317. Xextern struct varlist var[];X
  318. Xextern int var_param[];X
  319. Xextern int mpcptr;X
  320. XX
  321. X/* definitions for readCorrect routine */X
  322. X#define RC_NUM        1        /* read in a number */X
  323. X#define RC_LINE        2        /* registers in a line */X
  324. XX
  325. X/* Correction File Pointer to the file */X
  326. XFILE * correctfp;X
  327. XX
  328. X/* next line value */X
  329. Xint nextCorrect;X
  330. XX
  331. XX
  332. XX
  333. X/****************************************************************************X
  334. X *X
  335. X * FUNCTION:        openCorrect()X
  336. X * PURPOSE:            open and check the file for readingX
  337. X * ARGUMENTS:        mode - file mode to open withX
  338. X *                    fname - file name to openX
  339. X * RETURNS:            noneX
  340. X * NOTES:            noneX
  341. X *X
  342. X ***************************************************************************/X
  343. XX
  344. X/* openCorrect - open and check the file for reading */X
  345. XVOIDX
  346. XopenCorrect ( mode, fname )X
  347. X    int mode;X
  348. X    char *fname;X
  349. X{X
  350. X    /* open up the file */X
  351. X    if ( ( correctfp = fopen ( fname, X
  352. X     ( mode == CORRECT ? "r" : "w" ) ) ) == NULL ) {X
  353. X        printf ( "Unable to open the file '%s' for correctional use.\n",fname );X
  354. X        exit ( 1 );X
  355. X    }X
  356. XX
  357. X    /* get the value for the first edit line */X
  358. X    if ( mode == CORRECT )X
  359. X        nextCorrect = readCorrect ( RC_NUM );X
  360. X}X
  361. XX
  362. XX
  363. XX
  364. X/****************************************************************************X
  365. X *X
  366. X * FUNCTION:        closeCorrect()X
  367. X * PURPOSE:            close the fileX
  368. X * ARGUMENTS:        noneX
  369. X * RETURNS:            none    X
  370. X * NOTES:            noneX
  371. X *X
  372. X ***************************************************************************/X
  373. XX
  374. XVOIDX
  375. XcloseCorrect ( )X
  376. X{X
  377. X    fclose ( correctfp );X
  378. X}X
  379. XX
  380. XX
  381. X/****************************************************************************X
  382. X *X
  383. X * FUNCTION:        checkCorrect()X
  384. X * PURPOSE:            check if the numbers in the file are correctX
  385. X * ARGUMENTS:        noneX
  386. X * RETURNS:            noneX
  387. X * NOTES:            noneX
  388. X *X
  389. X ***************************************************************************/X
  390. XX
  391. XVOIDX
  392. XcheckCorrect ( )X
  393. X{X
  394. X    static int attempt = 0;X
  395. XX
  396. X    /* increment number of attempts */X
  397. X    attempt++;X
  398. XX
  399. X    /* check if the attempt is same as next line */X
  400. X    if ( nextCorrect == attempt ) {X
  401. X        /* the line is the same, check registers */X
  402. X        nextCorrect = readCorrect ( RC_LINE );X
  403. X    }X
  404. X    X
  405. X}X
  406. XX
  407. XX
  408. XX
  409. X/****************************************************************************X
  410. X *X
  411. X * FUNCTION:        readCorrect()X
  412. X * PURPOSE:            read in a valuesX
  413. X * ARGUMENTS:        RC_LINE - read in lineX
  414. X *                    RC_NUM - read in a valueX
  415. X * RETURNS:            number/line read inX
  416. X * NOTES:            noneX
  417. X *X
  418. X ***************************************************************************/X
  419. XX
  420. XintX
  421. XreadCorrect ( reason )X
  422. X    int reason;X
  423. X{X
  424. X    char buffer[80];                        /* string buffer */X
  425. X    int c;                                    /* input character */X
  426. X    int temp;X
  427. X    static int sysCorrect = S_HEX;            /* Numbering system */X
  428. XX
  429. X    /* read in the information */X
  430. X    if ( (c = getWchar ( correctfp ) ) == EOF ) X
  431. X        return -1;X
  432. XX
  433. X    while ( 1 ) {X
  434. X        if ( c == '.' ) {X
  435. X            /* format command */X
  436. X            fscanf ( correctfp, "%s", buffer );X
  437. X            if ( !strcmp ( "octal", buffer )  ) X
  438. X                sysCorrect = S_OCT;X
  439. X            else if ( !strcmp ( "decimal", buffer )  ) X
  440. X                sysCorrect = S_DEC;X
  441. X            elseX
  442. X                fprintf ( stderr, "Inproper command in micro code\n" );X
  443. XX
  444. X        } else if ( c == '\n' ) {X
  445. X            /* new line - throw out - RC_LINE can't exist beyond 1 line */X
  446. X            if ( reason == RC_LINE )X
  447. X                reason = RC_NUM;X
  448. XX
  449. X        } else if ( reason == RC_NUM && number ( c, sysCorrect ) ) {X
  450. X            ungetc ( c, correctfp );    /* put it back */X
  451. XX
  452. X            /* scan in the number */X
  453. X            fscanf ( correctfp, ( sysCorrect == S_HEX ? "%x" :X
  454. X                ( sysCorrect == S_OCT ? "%o" : "%d" ) ), &temp );X
  455. X    X
  456. X            /* tell the system the next line */X
  457. X            return temp;X
  458. XX
  459. X        } else if ( reason == RC_LINE && c != ';' ) {X
  460. X            ungetc ( c, correctfp );    /* put it back */X
  461. XX
  462. X            /* registers for a line */X
  463. X            fscanf ( correctfp, "%s", buffer );X
  464. XX
  465. X            /* process string */X
  466. X            processCorrect ( buffer, sysCorrect );X
  467. X        }X
  468. XX
  469. XX
  470. X        /* see if there is a comment */X
  471. X        if ( c == ';' ) X
  472. X            while ( ( c = getWchar ( correctfp ) ) != '\n' && c != EOF )X
  473. X                printf ( '.' );X
  474. XX
  475. X            /* get another character */X
  476. X        else if ( (c = getWchar ( correctfp ) ) == EOF ) X
  477. X            return -1;X
  478. X    }X
  479. X}X
  480. XX
  481. XX
  482. XX
  483. X/****************************************************************************X
  484. X *X
  485. X * FUNCTION:        processCorrectX
  486. X * PURPOSE:            take a string (ie pc=8) and process itX
  487. X * ARGUMENTS:        buffer - file string containing dataX
  488. X *                    system - current numbering systemX
  489. X * RETURNS:            noneX
  490. X * NOTES:            noneX
  491. X *X
  492. X ***************************************************************************/X
  493. XX
  494. XVOIDX
  495. XprocessCorrect ( buffer, system )X
  496. X    char *buffer;            /* file string containing data */X
  497. X    int system;                /* numbering system */X
  498. X{X
  499. X    long sval = 0L;            /* the should-be value */X
  500. X    int entry = -1;            /* entry search */X
  501. X    int found = 0;X
  502. X    int temp;                /* temp variable */X
  503. X    char tempb[80];            /* temp buffer */X
  504. XX
  505. X    /* get variable name ( look for the '=' ) and place a \0 at the end */X
  506. X    sval = strlen ( buffer );    /* temporarily used */X
  507. X    for ( temp = 0; temp < sval; temp++ )X
  508. X        if ( buffer[temp] == '=' )X
  509. X            buffer[temp] = '\0', found = temp + 1;X
  510. X    sval = 0L;                    /* reset value */X
  511. XX
  512. X    /* find out what the proper value should be */X
  513. X    if ( found ) X
  514. X        /* scan in the number */X
  515. X        sscanf ( &buffer[found], ( system == S_HEX ? "%x" :X
  516. X                ( system == S_OCT ? "%o" : "%d" ) ), &sval );X
  517. X    else {X
  518. X        fscanf ( correctfp, "%s", tempb );X
  519. X        if ( tempb[0] == '=' && tempb[1] == '\0' )X
  520. X            /* scan in the number */X
  521. X            fscanf ( correctfp, ( system == S_HEX ? "%x" :X
  522. X                ( system == S_OCT ? "%o" : "%d" ) ), &sval );X
  523. X        else X
  524. X            /* scan in the number */X
  525. X            sscanf ( &tempb[1], ( system == S_HEX ? "%x" :X
  526. X                ( system == S_OCT ? "%o" : "%d" ) ), &sval );X
  527. X    }X
  528. XX
  529. X    /* find the entry in the variable list */X
  530. X    temp = var_param[FORMATNUM] + var_param[PARTSNUM] + var_param[VARSNUM];X
  531. X    for ( found = 0; found < temp; found++)X
  532. X        if ( !strcmp ( buffer, var[found].name ) ) X
  533. X            entry = found;X
  534. XX
  535. X    /* if there is no entry */X
  536. X    if ( entry == -1 ) {X
  537. X        printf ( ( system == S_HEX ? "%x" : X
  538. X         ( system == S_OCT ? "%o" : "%d" ) ), nextCorrect );X
  539. X        printf ( ": variable '%s' was not found in the list\n", buffer );X
  540. X        return;X
  541. X    }X
  542. XX
  543. X    /* check if they are the same */X
  544. X    if ( var[entry].val == sval )X
  545. X        return;X
  546. XX
  547. X    /* print out results if they are different */X
  548. X    printf ( ( system == S_HEX ? "%x" : X
  549. X     ( system == S_OCT ? "%o" : "%d" ) ), nextCorrect );X
  550. X    sprintf ( tempb, ": variable '%s' is '%s' but should be '%s'\n", buffer,X
  551. X         ( system == S_HEX ? "%x" : ( system == S_OCT ? "%o" : "%d" ) ),X
  552. X         ( system == S_HEX ? "%x" : ( system == S_OCT ? "%o" : "%d" ) ) );X
  553. X    printf ( tempb, var[entry].val, sval );X
  554. XX
  555. X    /* set the register to its proper value */X
  556. X    var[entry].val = sval & var[entry].bmask;X
  557. XX
  558. X    /* check if it is a connected register */X
  559. X    if ( var[entry].type == 1 ) {X
  560. X        mpc ( "set", var[entry].val );X
  561. X        mpcptr = var[entry].val;X
  562. X    }X
  563. XX
  564. X}X
  565. XX
  566. XX
  567. X/* variables needed for building the correction file */X
  568. Xstruct varlist *correctList;X
  569. Xint countnum;X
  570. XX
  571. XX
  572. X/****************************************************************************X
  573. X *X
  574. X * FUNCTION:        addCorrect()X
  575. X * PURPOSE:            add correction entry into listX
  576. X * ARGUMENTS:        str - string containing entryX
  577. X * RETURNS:            noneX
  578. X * NOTES:            noneX
  579. X *X
  580. X ***************************************************************************/X
  581. XX
  582. XVOIDX
  583. XaddCorrect ( str )X
  584. X    char *str;X
  585. X{X
  586. X    int temp = 0;X
  587. X    int count = 1;X
  588. X    int len;X
  589. XX
  590. X    /* determine if there is any registers, if none, error out */X
  591. X    if ( ! ( len = strlen ( str ) ) ) {X
  592. X        printf ( "Must specify which registers to set up correct file\n" );X
  593. X        exit ( 1 );X
  594. X    }X
  595. XX
  596. X    /* count commas to determine number of arguments */X
  597. X    while ( temp < len ) {X
  598. X        /* check commas */X
  599. X        if ( str[temp] == ',' )X
  600. X            count++;X
  601. XX
  602. X        temp++;X
  603. X    }X
  604. XX
  605. X    countnum = count;X
  606. X    /* allocate the needed space */X
  607. X    if ( ( correctList = (struct varlist *) malloc ( count * sizeof ( struct varlist ) ) ) == NULL ) {X
  608. X        printf ( "Unable to allocate enough memory to build the correction file\n" );X
  609. X        exit ( 1 );X
  610. X    }X
  611. XX
  612. X    /* place all the registers in the array */X
  613. X    count = temp = 0;X
  614. X    while ( temp < len ) {X
  615. X        if ( isalpha ( str[temp] ) ) {X
  616. X            int temp1 = temp;X
  617. X            int i;X
  618. XX
  619. X            while ( temp1 < len && str[temp1] != ',' )X
  620. X                temp1++;X
  621. X            strncpy ( correctList[count].name, &str[temp], temp1 - temp );X
  622. X            correctList[count].name[temp1-temp] = '\0';X
  623. X            correctList[count].val = 0L;X
  624. X            correctList[count].bmask = -1;X
  625. XX
  626. X            /* find entry in the variable list */X
  627. X            for ( i = 0; i < var_param[FORMATNUM] + var_param[PARTSNUM]; i++ )X
  628. X                if ( ! strcmp ( correctList[count].name, var[i].name ) ) X
  629. X                    correctList[count].bmask = i;X
  630. XX
  631. X            if ( correctList[count].bmask == -1 ) {X
  632. X                printf ( "Register '%s' is not defined.\n", correctList[count].name );X
  633. X                exit ( 1 );X
  634. X            }X
  635. XX
  636. X            temp = temp1 + 1, count++;X
  637. X        } else {X
  638. X            printf ( "Improper format of registers for building the correction file\n" );X
  639. X            exit ( 1 );X
  640. X        }X
  641. X    }X
  642. X     X
  643. X}X
  644. XX
  645. XX
  646. XX
  647. X/****************************************************************************X
  648. X *X
  649. X * FUNCTION:        doCorrect()X
  650. X * PURPOSE:            determine if there is a correction needed to be madeX
  651. X * ARGUMENTS:        noneX
  652. X * RETURNS:            none    X
  653. X * NOTES:            noneX
  654. X *X
  655. X ***************************************************************************/X
  656. XX
  657. XVOIDX
  658. XdoCorrect ( )X
  659. X{X
  660. X    static int line = 1;X
  661. X    int printLine = 0;X
  662. X    int temp = 0;X
  663. XX
  664. X    while ( temp < countnum ) {X
  665. X        if ( var[correctList[temp].bmask].val != correctList[temp].val ) {X
  666. X            correctList[temp].val = var[correctList[temp].bmask].val;X
  667. X            if ( ! printLine ) X
  668. X                fprintf ( correctfp, "%x %s=%x", line, correctList[temp].name,X
  669. X                    correctList[temp].val, printLine++ );X
  670. X            else X
  671. X                fprintf ( correctfp, " %s=%x", correctList[temp].name, correctList[temp].val );X
  672. X        }X
  673. XX
  674. X        temp++;X
  675. X    }X
  676. XX
  677. X    /* print a newline if there is data */X
  678. X    if ( printLine )X
  679. X        fprintf ( correctfp, "\n" );X
  680. XX
  681. X    /* increment the line counter */X
  682. X    line++;X
  683. X}X
  684. XX
  685. XX
  686. Zaphod for prez
  687. cat << 'Zaphod for prez' | sed 's/X\(.*\)X/\1/' > debug.c
  688. XX
  689. X/* ----------------------------------------------------------------------- *\X
  690. X******************************************************************************X
  691. XX
  692. X  PROGRAM NAME: Main debugging moduleX
  693. XX
  694. X  PROGRAMMER:    Patrick Palmer                     DATE: 8/17/90 X
  695. X          X
  696. X  DESCRIPTION OF PROGRAM: X
  697. X     This contains all of the support routines for the debuggingX
  698. X  mode of YAMPC.  The main debug routine is called "debug", go figure.X
  699. X  "prtregs" prints out the registers.  There is a parser and miscellaneousX
  700. X  debugging functions.X
  701. XX
  702. X******************************************************************************X
  703. XX
  704. X        This program is free software; you can redistribute it and/orX
  705. X        modify it under the terms of the GNU General Public LicenseX
  706. X        (version 2) as published by the Free Software Foundation.X
  707. XX
  708. X        This program is distributed in the hope that is will be useful,X
  709. X        but WITHOUT ANY WARRANTY; without even the implied warrenty ofX
  710. X        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See theX
  711. X        GNU General Public License for more details.X
  712. X        X
  713. X        You should have received a copy of the GNU General Public X
  714. X        License along with this program; if not, write to the FreeX
  715. X        Software Foundation, Inc., 675 Mass Ave, Cambridge, MAX
  716. X        02139, USA.X
  717. XX
  718. X        YAMPC Microcode Development KitX
  719. X        (C) 1992 by Patrick PalmerX
  720. XX
  721. X******************************************************************************X
  722. XX
  723. XX
  724. X  PROGRAM REVISION LOGX
  725. X  X
  726. X        DATE               DESCRIPTION OF CHANGE                PROGRAMMERX
  727. X      --------  ----------------------------------------------  ----------X
  728. X      08/17/90  YAMPC - Version 1.0                             PAPX
  729. X      11/17/90  Interrupts, Bug Fixes - Version 1.1             PAPX
  730. X      01/11/92  Distribution version - Version 1.2              PAPX
  731. XX
  732. X***************************************************************************  X
  733. X\* ------------------------------------------------------------------------ */X
  734. XX
  735. XX
  736. X#include <stdio.h>X
  737. X#include "main.h"X
  738. X#include "misc.h"X
  739. X#include "debug.h"X
  740. X#include "y.tab.h"X
  741. XX
  742. Xextern int cycles, subcycles;X
  743. Xextern struct varlist var[];X
  744. Xextern struct interruptlist interrupt[];X
  745. Xextern int var_param[];X
  746. Xextern long *cpu, *mem;X
  747. Xextern int mpcptr;X
  748. XX
  749. X/* running in debug mode for a certain number of cycles */X
  750. Xint debug_run = 0;X
  751. XX
  752. X/* trace change */X
  753. Xint traceChange;X
  754. XX
  755. XX
  756. XX
  757. X/****************************************************************************X
  758. X *X
  759. X * FUNCTION:        debug()X
  760. X * PURPOSE:            main focal point of the interactive debugger    X
  761. X * ARGUMENTS:        mode - mode of debuggingX
  762. X *                    state - current state of debuggingX
  763. X * RETURNS:            process to contine noteX
  764. X * NOTES:            noteX
  765. X *X
  766. X ***************************************************************************/X
  767. XX
  768. XintX
  769. Xdebug ( mode, state )X
  770. X    int *mode;X
  771. X    int state;X
  772. X{X
  773. X    int exitcode = P_GOON;        /* exit code */X
  774. X    int loop = 1;            /* continous loop */X
  775. X    int promptUser = 1;        /* prompt user with prompt (Default: YES) */X
  776. X    int breaklist = 1;        /* display the breakpt & bounds message once */X
  777. XX
  778. X    /* set traceChange mode to Non possible state */X
  779. X    traceChange = -1;X
  780. XX
  781. X    while ( loop ) {X
  782. XX
  783. X        /* now check the modes */X
  784. X        switch ( *mode ) {X
  785. X            case NOTRACE_FREG:        /* display registers at every fetch */X
  786. X                if ( mpcptr != var_param[FETCH] )X
  787. X                    return exitcode;X
  788. XX
  789. X            case NOTRACE_REG:        /* display registers at every cycle */X
  790. X                prtregs ( );X
  791. X                return exitcode;X
  792. XX
  793. X            case DEBUG_REG:            /* display registers at every prompt */X
  794. X                prtregs ( );X
  795. X                break;X
  796. XX
  797. X            case CORRECT:            /* correctional file */X
  798. X                if ( mpcptr != var_param[FETCH] )X
  799. X                    return exitcode;X
  800. X                checkCorrect ( );    /* check if there needs to do work */X
  801. X                return exitcode;X
  802. XX
  803. X            case CREATE_CORRECT:    /* create correctional file */X
  804. X                if ( mpcptr != var_param[FETCH] )X
  805. X                    return exitcode;X
  806. X                doCorrect ( );        /* check if there needs to do work */X
  807. X                return exitcode;X
  808. XX
  809. X        }X
  810. XX
  811. X        /* if trace state has changed, change the mode */X
  812. X        if ( traceChange != -1 ) {X
  813. X            *mode = traceChange;X
  814. X            traceChange = -1;X
  815. X        }X
  816. XX
  817. X        /* check if hit end of code */X
  818. X        if ( breaklist && state ) {X
  819. X            printf ( "Out of bound reached in micro code\n" );X
  820. X            debug_run = breaklist = 0;X
  821. X        }X
  822. XX
  823. X        /* check if this is a breakpoint */X
  824. X        else if ( breaklist && checkBrkPts ( ) ) {X
  825. X            printf ( "Breakpoint reached at %x(%d)\n", mpcptr, mpcptr );X
  826. X            debug_run = breaklist = 0;X
  827. X        }X
  828. XX
  829. X        /* prompt user for commands */X
  830. X        if ( debug_run ) {X
  831. X            if ( debug_run != -1 )X
  832. X                debug_run--;X
  833. X            loop = 0;X
  834. X        } else if ( ( exitcode = prompt ( ) ) != P_CONT )X
  835. X            loop = 0;X
  836. X    }X
  837. XX
  838. X    return exitcode;X
  839. X}X
  840. XX
  841. XX
  842. XX
  843. X/****************************************************************************X
  844. X *X
  845. X * FUNCTION:        prtregs()X
  846. X * PURPOSE:            print out the format values and registersX
  847. X * ARGUMENTS:        noneX
  848. X * RETURNS:            none    X
  849. X * NOTES:            noneX
  850. X *X
  851. X ******************************************************inter in the input string to zero */X
  852. X    p_position = 0;X
  853. XX
  854. X    /* check if NEWLINE is only pressed */X
  855. X    for ( i = strlen ( p_inp ); i > 0; --i ) X
  856. X        if ( p_inp[i-1] != ' ' && p_inp[i-1] != '\t' ) {X
  857. X            info = 1;X
  858. X            if ( p_inp[i-1] == '!' ) X
  859. X                found = i;X
  860. X        }X
  861. XX
  862. X    /* check if it is a shell (!) command */X
  863. X    if ( found ) {X
  864. X        system ( &p_inp[found] );X
  865. X        return P_CONT;X
  866. X    }X
  867. XX
  868. X    /* if there is information on the line, copy to last command */X
  869. X    if ( info ) {X
  870. X        strncpy ( last_p_inp, p_inp, 128 );X
  871. X        if ( ! anyCmds )X
  872. X            anyCmds = 1;X
  873. XX
  874. X    /* if NEWLINE and a last command then repeat last command */X
  875. X    } else if ( ! info && anyCmds ) {X
  876. X         /* copy in last command */X
  877. X        strncpy ( p_inp, last_p_inp, 128 );X
  878. X    } X
  879. X    X
  880. X    if ( ( ! getEntry ( &inpSing, P_STR ) ) && p_position != -1 ) {X
  881. X        while ( ! found && i < DEBUG_ENTRY ) {X
  882. X            /* string compare length */X
  883. X            if ( ( temp = strlen ( inpSing ) ) < cmds[i].matchnum )X
  884. X                i++;X
  885. X            else if ( ! strncmp ( inpSing.str, cmds[i].word, temp ) ) {X
  886. X                p_val = ( * cmds[i].func ) ( i );X
  887. X                found = 1;X
  888. X            } elseX
  889. X                i++;X
  890. X        }X
  891. X        if ( ! found ) X
  892. X            printf ( "Invalid command, type 'help' for a list of commands\n" );X
  893. X    } else X
  894. X        printf ( "Not a valid entry\n" );X
  895. XX
  896. X    /* return the value returned by the routine called */X
  897. X    return p_val;X
  898. X}X
  899. XX
  900. XX
  901. XX
  902. X/****************************************************************************X
  903. X *X
  904. X * FUNCTION:        getEntry()X
  905. X * PURPOSE:            get an entry in the string inputX
  906. X * ARGUMENTS:        rv - retrieved dataX
  907. X *                    type - type of information to retrieveX
  908. X * RETURNS:            1 - invalid entryX
  909. X *                    0 - ok entryX
  910. X * NOTES:            noneX
  911. X *X
  912. X ***************************************************************************/X
  913. XX
  914. X/* getEntry ( ) - get an entry in the string input */X
  915. XintX
  916. XgetEntry ( rv, type )X
  917. X    U_Ret *rv;X
  918. X    int type;X
  919. X{X
  920. X    int pos = 0;        /* position to start for number check */X
  921. X    int i;                /* temp for loop */X
  922. X    int total = 0;        /* running total of hex number in input */X
  923. X    int temp;X
  924. X    char istr[80];        /* input string subset */X
  925. XX
  926. X    if ( p_position == -1 )    /* end of the input string */X
  927. X        return 0;X
  928. XX
  929. X    /* make sure there are no leading spaces */X
  930. X    while ( p_inp[p_position] == ' ' || p_inp[p_position] == '\t' ) X
  931. X        p_position++;X
  932. X    if ( p_inp[p_position] == '\0' ) {X
  933. X        p_position = -1;    /* end of string found */X
  934. X        return 0;X
  935. X    }X
  936. XX
  937. X    if ( sscanf ( &p_inp[p_position], "%s", istr ) == 0 ) {X
  938. X        p_position = -1;    /* end of string found */X
  939. X        return 0;X
  940. X    }X
  941. XX
  942. X    /* reposition p_position */X
  943. X    p_position += strlen ( istr );X
  944. X    X
  945. X    /* string input */X
  946. X    if ( type == P_STR ) {X
  947. X        rv->str = istr;X
  948. X        return 0;X
  949. X    }X
  950. XX
  951. X    /* integer input */X
  952. X    if ( istr[0] == '-' )    /* negative number */X
  953. X        pos = 1;X
  954. XX
  955. X    /* check number to see if it is valid */X
  956. X    temp = strlen ( istr );X
  957. X    for ( i = pos; i < temp; i++ )X
  958. X        if ( istr[i] >= '0' && istr[i] <= '9' )X
  959. X            total = ( total * 16 ) + ( istr[i] - '0' );X
  960. X        else if ( istr[i] >= 'a' && istr[i] <= 'f' )X
  961. X            total = ( total * 16 ) + ( istr[i] - 'a' + 10 );X
  962. X        else X
  963. X            /* invalid number */X
  964. X            return 1;X
  965. X    X
  966. X    /* number is valid */X
  967. X    rv->ival = total;X
  968. X    return 0;X
  969. X}X
  970. XX
  971. XX
  972. X/***********************************\X
  973. X|* Debug Prompt Responce Functions *|X
  974. X\***********************************/X
  975. XX
  976. XX
  977. XX
  978. X/****************************************************************************X
  979. X *X
  980. X * FUNCTION:        exitProg()X
  981. X * PURPOSE:            exit program and return to previous applicationX
  982. X * ARGUMENTS:        entry - command entry numberX
  983. X * RETURNS:            P_LEAVE - leave command    X
  984. X * NOTES:            noneX
  985. X *X
  986. X ***************************************************************************/X
  987. XX
  988. XintX
  989. XexitProg ( entry )X
  990. X    int entry;X
  991. X{X
  992. X    return P_LEAVE;X
  993. X}X
  994. XX
  995. XX
  996. XX
  997. X/****************************************************************************X
  998. X *X
  999. X * FUNCTION:        help()X
  1000. X * PURPOSE:            display help list    X
  1001. X * ARGUMENTS:        entry - command entry numberX
  1002. X * RETURNS:            P_CONT - continue processingX
  1003. X * NOTES:            noneX
  1004. X *X
  1005. X ***************************************************************************/X
  1006. XX
  1007. XintX
  1008. Xhelp ( entry )X
  1009. X    int entry;X
  1010. X{X
  1011. X    int i = 0;X
  1012. XX
  1013. X    /* display title of help message */X
  1014. X    printf ( "Help list\n" );X
  1015. XX
  1016. X    /* display each entry */X
  1017. X    for ( ; i < DEBUG_ENTRY; i++ )X
  1018. X        printf ( cmds[i].help );X
  1019. XX
  1020. X    /* Other interesting points */X
  1021. X    printf ( "Pressing <RETURN> will repeat the last command\n" );X
  1022. X    return P_CONT;X
  1023. X}X
  1024. XX
  1025. XX
  1026. XX
  1027. X/****************************************************************************X
  1028. X *X
  1029. X * FUNCTION:        run()X
  1030. X * PURPOSE:            running with debug on not stopping unless break pointX
  1031. X *                    or addressX
  1032. X * ARGUMENTS:        entry - command entry numberX
  1033. X * RETURNS:            P_CONT - continue processing    X
  1034. X *                    P_GOON - start executing microcodeX
  1035. X * NOTES:            noneX
  1036. X *X
  1037. X ***************************************************************************/X
  1038. XX
  1039. XintX
  1040. Xrun ( entry )X
  1041. X    int entry;X
  1042. X{X
  1043. X    U_Ret val;X
  1044. X    int rv;X
  1045. XX
  1046. X    /* get value if one is available */X
  1047. X    if ( getEntry ( & val, P_NUM ) ) {X
  1048. X        misuse ( entry );X
  1049. X        return P_CONT;X
  1050. X    }X
  1051. XX
  1052. X    /* no entry - just run */X
  1053. X    if ( p_position == -1 ) {X
  1054. X        debug_run = -1;            /* keep running */X
  1055. X        return P_GOON;X
  1056. X    } else {X
  1057. X        /* make sure there are no more entries */X
  1058. X        getEntry ( & val, P_STR );X
  1059. X        if ( p_position != -1 ) {X
  1060. X            misuse ( entry );X
  1061. X            return P_CONT;X
  1062. X        }X
  1063. X    }X
  1064. XX
  1065. X    /* make sure the entry is positive */X
  1066. X    if ( val.ival <= 0 ) {X
  1067. X        printf ( "Invalid number, can only accept positive numbers.\n" );X
  1068. X        return P_CONT;X
  1069. X    }X
  1070. XX
  1071. X    /* set the running value to the inputed */X
  1072. X    debug_run = val.ival - 1;X
  1073. X    return P_GOON;X
  1074. X}X
  1075. XX
  1076. XX
  1077. XX
  1078. X/****************************************************************************X
  1079. X *X
  1080. X * FUNCTION:        display()X
  1081. X * PURPOSE:            display registers and memory    X
  1082. X * ARGUMENTS:        which - command entry numberX
  1083. X * RETURNS:            P_CONT - continue processing commands    X
  1084. X * NOTES:            noneX
  1085. X *X
  1086. X ***************************************************************************/X
  1087. XX
  1088. XintX
  1089. Xdisplay ( which )X
  1090. X    int which;X
  1091. X{X
  1092. X    int memlook = 0;X
  1093. X    int start, temp = 0;X
  1094. X    int found = 0;X
  1095. X    U_Ret rv;X
  1096. XX
  1097. X    /* get the first argument, if any */X
  1098. X    getEntry ( &rv, P_STR );X
  1099. X    if ( p_position == -1 ) {        /* no arguments */X
  1100. X        /* display all the registers */X
  1101. X        prtregs ( );X
  1102. X        return P_CONT;X
  1103. X    }X
  1104. XX
  1105. X    /* check the string to one of the registers, cpu, or mem */X
  1106. X    if ( ! strcmp ( rv.str, "cpu" ) )X
  1107. X        memlook = 1;        /* cpu memory */X
  1108. X    else if ( ! strcmp ( rv.str, "mem" ) ) X
  1109. X        memlook = 2;        /* main memory */X
  1110. XX
  1111. X    if ( ! memlook ) {        /* display a register */X
  1112. X        int val;X
  1113. XX
  1114. X        /* search for the register */X
  1115. X        for ( ; temp < var_param[FORMATNUM] + var_param[PARTSNUM]; temp++ )X
  1116. X            if ( ! strcmp ( var[temp].name, rv.str ) )X
  1117. X                found = 1, val = temp;X
  1118. XX
  1119. X        if ( ! found )         /* unable to find register */X
  1120. X            printf ( "Could not find the register specified\n" );X
  1121. X        else             /* found the register */X
  1122. X            printf ( "%s\t%-4lx\n", var[val].name, var[temp].val );X
  1123. X        return P_CONT;X
  1124. X    }X
  1125. XX
  1126. X    if ( ( getEntry ( &rv, P_NUM ) ) || p_position == -1 ) {X
  1127. X        misuse ( which );X
  1128. X        return P_CONT;X
  1129. X    }X
  1130. XX
  1131. X    start = rv.ival;X
  1132. X    if ( getEntry ( &rv, P_NUM ) ) {X
  1133. X        misuse ( which );X
  1134. X        return P_CONT;X
  1135. X    } else if ( p_position == -1 ) X
  1136. X        rv.ival = start;X
  1137. XX
  1138. X    /* print results */X
  1139. X    if ( memlook == 1 ) X
  1140. X        /* print out each line */X
  1141. X        for ( ; start <= rv.ival; start++ )X
  1142. X            prtCpuLine ( ( found++ == 0 ? 2 : 0 ), start );    X
  1143. X    else {X
  1144. X        printf ( "Main memory display\n" );X
  1145. X        for ( ; start <= rv.ival; start+=10 ) {X
  1146. X            for ( temp = 0; X
  1147. X             temp <= ( rv.ival - start > 10 ? 10 : rv.ival - start ) ; temp++ )X
  1148. X                printf ( "%-5.4x", mem[start+temp] );X
  1149. X            printf ( "\n" );X
  1150. X        }X
  1151. X    }X
  1152. X        X
  1153. X    return P_CONT;X
  1154. X}X
  1155. XX
  1156. XX
  1157. XX
  1158. X/****************************************************************************X
  1159. X *X
  1160. X * FUNCTION:        calculator()X
  1161. X * PURPOSE:            simple RPN line calculator    X
  1162. X * ARGUMENTS:        which - command entry numberX
  1163. X * RETURNS:            P_CONT - continue processing commands    X
  1164. X * NOTES:            noneX
  1165. X *X
  1166. X ***************************************************************************/X
  1167. XX
  1168. X/* calculator - a simple RPN line calculator */X
  1169. XintX
  1170. Xcalculator ( which )X
  1171. X    int which;X
  1172. X{X
  1173. X    int temp, stackCount = 1;X
  1174. X    int loop = 1, operation;X
  1175. X    int errop = 0;X
  1176. XX
  1177. X    while ( loop ) {X
  1178. X        switch ( operation = getOp ( &temp ) ) {X
  1179. X        X
  1180. X            case END:            /* end of input cmd string */X
  1181. X                loop = 0;X
  1182. XX
  1183. X                /* print item if and only if there is something on stack */X
  1184. X                if ( stackCount ) {X
  1185. X                    printf ( "$%x\n", (long) pop ( ) );X
  1186. X                    stackCount--;X
  1187. X                }X
  1188. X                break;X
  1189. X    X
  1190. X            case NUM:            /* number */X
  1191. X            case VAR:            /* variable */X
  1192. X                push ( operation, temp );X
  1193. X                stackCount++;X
  1194. X                break;X
  1195. XX
  1196. X            case UNKNOWN:        /* unknown expression */X
  1197. X                printf ( "Expression has a syntax error\n" );X
  1198. X                loop = 0;X
  1199. X                break;X
  1200. XX
  1201. X            default:            /* math operation */X
  1202. X                if ( ( operation == NOT || operation == BNOT ) && stackCount ) {X
  1203. X                    do_stack ( operation );X
  1204. X                } else if ( stackCount >= 2 ) {X
  1205. X                    do_stack ( operation );X
  1206. X                    stackCount--;X
  1207. X                } else X
  1208. X                    loop = 0, errop = 1;X
  1209. X        }X
  1210. X    }X
  1211. XX
  1212. X    /* remove all the values on the stack */X
  1213. X    for ( ; stackCount > 0 ; stackCount-- )X
  1214. X        pop ( );X
  1215. XX
  1216. X    /* check if there was a math operation error */X
  1217. X    if ( errop )X
  1218. X        printf ( "Not enough arguments on the stack to do such operation\n" );X
  1219. XX
  1220. X    return P_CONT;X
  1221. X}X
  1222. XX
  1223. XX
  1224. X/* define a macro needed a lot - ok, ok, 1-800-NO-MACRO, I had to, really! */X
  1225. X#define CHECKOP(x)    if ( rc == END )    /* no other character before */    \X
  1226. X                        rc = x;                                            \X
  1227. X                    else {                                                \X
  1228. X                        rc = UNKNOWN;    /* unknown operation */            \X
  1229. X                        loop = 0;                                        \X
  1230. X                    }X
  1231. XX
  1232. X            X
  1233. XX
  1234. X/****************************************************************************X
  1235. X *X
  1236. X * FUNCTION:        getOp()X
  1237. X * PURPOSE:            parse out one token and return the value    X
  1238. X * ARGUMENTS:        val - value of operation location to place itX
  1239. X * RETURNS:            NUM - retrieved numberX
  1240. X *                    VAR - retrived variableX
  1241. X *                    UNKNOWN - unknown contentsX
  1242. X * NOTES:            noneX
  1243. X *X
  1244. X ***************************************************************************/X
  1245. XX
  1246. X/* getOp - parse out one token and return the value */X
  1247. XintX
  1248. XgetOp ( val )X
  1249. X    int *val;X
  1250. X{X
  1251. X    int loop = 1;            /* keep looping while not sure of token */X
  1252. X    int rc = END;            /* return code ( token ) */X
  1253. X    int possibleNum = 1;    /* at this point, the string could be a num */X
  1254. X    char str[32];X
  1255. X    int s_ptr = 0;            /* pointer into the string */X
  1256. X    int temp;X
  1257. XX
  1258. X    /* check to see if there is data on the line */X
  1259. X    if ( p_position == -1 )X
  1260. X        return END;X
  1261. XX
  1262. X    /* set the number/variable pointer to non possible value */X
  1263. X    *val = -1;X
  1264. XX
  1265. X    /* make sure there are no leading spaces */X
  1266. X    while ( p_inp[p_position] == ' ' || p_inp[p_position] == '\t' ) X
  1267. X        p_position++;X
  1268. XX
  1269. X    /* parser */X
  1270. X    while ( loop ) {X
  1271. XX
  1272. X        switch ( p_inp[p_position] ) {X
  1273. XX
  1274. X            case '\0':                        /* END of string */X
  1275. X                p_position = -1;X
  1276. XX
  1277. X            case ' ':                        /* argument break */X
  1278. X            case '\t':X
  1279. X                loop = 0;X
  1280. X                break;X
  1281. XX
  1282. X            case '&':                        /* &, && */X
  1283. X                if ( rc == BAND )             /* already received 1 & */X
  1284. X                    rc = AND;X
  1285. X                else if ( rc == END )X
  1286. X                    rc = BAND;X
  1287. X                else {X
  1288. X                    rc = UNKNOWN;X
  1289. X                    loop = 0;X
  1290. X                }X
  1291. X                break;X
  1292. XX
  1293. X            case '|':                        /* |, || */X
  1294. X                if ( rc == BOR )             /* already received 1 | */X
  1295. X                    rc = OR;X
  1296. X                else if ( rc == END )X
  1297. X                    rc = BOR;X
  1298. X                else {X
  1299. X                    rc = UNKNOWN;X
  1300. X                    loop = 0;X
  1301. X                }X
  1302. X                break;X
  1303. XX
  1304. X            case '^':                        /* ^ */X
  1305. X                CHECKOP ( EOR );X
  1306. X                break;    X
  1307. XX
  1308. X            case '!':                        /* ! */X
  1309. X                CHECKOP ( NOT );X
  1310. X                break;X
  1311. XX
  1312. X            case '~':                        /* ~ */X
  1313. X                CHECKOP ( BNOT );X
  1314. X                break;X
  1315. XX
  1316. X            case '+':                        /* + */X
  1317. X            case '-':                        /* - */X
  1318. X            case '/':                        /* / */X
  1319. X            case '%':                        /* % */X
  1320. X            case '*':                        /* * */X
  1321. X                CHECKOP ( (int) p_inp[p_position] );X
  1322. X                break;X
  1323. XX
  1324. X            case '=':                        /* =, ==, >=, <= */X
  1325. X                switch ( rc ) {X
  1326. X                    case END:X
  1327. X                        rc = (int) '=';X
  1328. X                        break;X
  1329. X                    case (int) '=':X
  1330. X                        rc = EQ;X
  1331. X                        break;X
  1332. X                    case NOT:X
  1333. X                        rc = NE;X
  1334. X                        break;X
  1335. X                    case GT:X
  1336. X                        rc = GE;X
  1337. X                        break;X
  1338. X                    case LT:X
  1339. X                        rc = LE;X
  1340. X                        break;X
  1341. X                    default:X
  1342. X                        rc = UNKNOWN;X
  1343. X                        loop = 0;X
  1344. X                }X
  1345. X                break;X
  1346. XX
  1347. X            case '>':                        /* >, >> */X
  1348. X                if ( rc == END )X
  1349. X                    rc = GT;X
  1350. X                else if ( rc == GT )X
  1351. X                    rc = SR;X
  1352. X                else {X
  1353. X                    rc = UNKNOWN;X
  1354. X                    loop = 0;X
  1355. X                }X
  1356. X                break;X
  1357. XX
  1358. X            case '<':                        /* <, << */X
  1359. X                if ( rc == END )X
  1360. X                    rc = LT;X
  1361. X                else if ( rc == LT )X
  1362. X                    rc = SL;X
  1363. X                else {X
  1364. X                    rc = UNKNOWN;X
  1365. X                    loop = 0;X
  1366. X                }X
  1367. X                break;X
  1368. XX
  1369. X            default:                        /* number or string */X
  1370. X                /* see if it is a valid number */X
  1371. X                if ( ( p_inp[p_position] >= 'a' && p_inp[p_position] <= 'f' ) ||X
  1372. X                 ( p_inp[p_position] >= '0' && p_inp[p_position] <= '9' ) ) ;X
  1373. X                elseX
  1374. X                    possibleNum = 0;X
  1375. XX
  1376. X                /* see if the character can be stuffed into the array */X
  1377. X                if ( s_ptr == 32 ) {X
  1378. X                    printf ( "Variable specified is too big\n" );X
  1379. X                    rc = UNKNOWN;X
  1380. X                    loop = 0;X
  1381. X                    break;X
  1382. X                }X
  1383. XX
  1384. X                /* so far it is a string variable */X
  1385. X                rc = VAR;X
  1386. XX
  1387. X                str[s_ptr++] = p_inp[p_position];X
  1388. XX
  1389. X                break;X
  1390. X        X
  1391. X        }X
  1392. XX
  1393. X        /* increment p_position */X
  1394. X        if ( p_position > 0 )X
  1395. X            p_position++;X
  1396. XX
  1397. X    }X
  1398. XX
  1399. X    /* don't bother checking for number if it can't be */X
  1400. X    if ( rc != VAR )X
  1401. X        return rc;X
  1402. XX
  1403. X    str[s_ptr] ='\0';X
  1404. X    /* check if the string is a number or a variable (variable first) */X
  1405. X    for ( temp = 0; temp < var_param[FORMATNUM] + var_param[PARTSNUM]; temp++ )X
  1406. X        if ( ! strcmp ( var[temp].name, str ) ) {X
  1407. X            *val = temp;X
  1408. X            return VAR;X
  1409. X    }X
  1410. XX
  1411. X    /* if not a variable and can possibly be a number do so otherwise a error */X
  1412. X    if ( possibleNum ) {X
  1413. X        str[( s_ptr == 32 ? 0 : s_ptr )] = '\0';X
  1414. X        sscanf ( str, "%x", val );X
  1415. X        return NUM;X
  1416. XX
  1417. X    } X
  1418. XX
  1419. X    /* no exactly sure what it was */X
  1420. X    return UNKNOWN;X
  1421. XX
  1422. X}X
  1423. XX
  1424. XX
  1425. XX
  1426. X/****************************************************************************X
  1427. X *X
  1428. X * FUNCTION:        set()X
  1429. X * PURPOSE:            set a register or memory to a value    X
  1430. X * ARGUMENTS:        which - command entry numberX
  1431. X * RETURNS:            P_CONT - continue processing commands    X
  1432. X * NOTES:            noneX
  1433. X *X
  1434. X ***************************************************************************/X
  1435. XX
  1436. XintX
  1437. XsetSome ( which )X
  1438. X    int which;X
  1439. X{X
  1440. X    int found, temp, val;X
  1441. X    U_Ret rv;X
  1442. XX
  1443. X    /* get the first argument, if any */X
  1444. X    getEntry ( &rv, P_STR );X
  1445. X    if ( p_position == -1 ) {        /* no arguments */X
  1446. X        misuse ( which );X
  1447. X        return P_CONT;X
  1448. X    }X
  1449. XX
  1450. X    /* check if it is a memory set */X
  1451. X    if ( ! strcmp ( "mem", rv.str ) ) {X
  1452. X    X
  1453. X        /* get an integer */X
  1454. X        if ( ( getEntry ( &rv, P_NUM ) ) || p_position == -1 ) {X
  1455. X            misuse ( which );X
  1456. X            return P_CONT;X
  1457. X        }X
  1458. XX
  1459. X        /* set the location */X
  1460. X        val = rv.ival;X
  1461. XX
  1462. X        /* get an integer */X
  1463. X        if ( ( getEntry ( &rv, P_NUM ) ) || p_position == -1 ) {X
  1464. X            misuse ( which );X
  1465. X            return P_CONT;X
  1466. X        }X
  1467. X    X
  1468. X        /* do the math operation - equate */X
  1469. X        push ( MEM, val );            /* push onto stack */X
  1470. X        push ( NUM, rv.ival );X
  1471. X        do_stack ( (int) '=' );        /* equate them */X
  1472. X        pop ( );                    /* pop off the element */X
  1473. X    X
  1474. X        return P_CONT;    X
  1475. X    }X
  1476. XX
  1477. X    /* search for the register */X
  1478. X    for ( temp = 0; temp < var_param[FORMATNUM] + var_param[PARTSNUM]; temp++ )X
  1479. X        if ( ! strcmp ( var[temp].name, rv.str ) )X
  1480. X            found = 1, val = temp;X
  1481. XX
  1482. X    if ( ! found )         /* unable to find register */X
  1483. X        printf ( "Could not find the register specified\n" );X
  1484. X    else {            /* found the register */X
  1485. XX
  1486. X        /* get an integer */X
  1487. X        if ( ( getEntry ( &rv, P_NUM ) ) || p_position == -1 ) {X
  1488. X            misuse ( which );X
  1489. X            return P_CONT;X
  1490. X        }X
  1491. XX
  1492. X        /* do the math operation - equate */X
  1493. X        push ( VAR, val );            /* push onto stack */X
  1494. X        push ( NUM, rv.ival );X
  1495. X        do_stack ( (int) '=' );        /* equate them */X
  1496. X        pop ( );                    /* pop off the element */X
  1497. X    X
  1498. X        printf ( "%s\t%-4lx\n", var[val].name, var[temp].val );X
  1499. X    }X
  1500. XX
  1501. X    return P_CONT;X
  1502. X}X
  1503. XX
  1504. XX
  1505. XX
  1506. X/****************************************************************************X
  1507. X *X
  1508. X * FUNCTION:        D_interrupt()X
  1509. X * PURPOSE:            list, unset or set interrupts    X
  1510. X * ARGUMENTS:        which - command entry numberX
  1511. X * RETURNS:            P_CONT - continue processing commands    X
  1512. X * NOTES:            noneX
  1513. X *X
  1514. X ***************************************************************************/X
  1515. XX
  1516. XintX
  1517. XD_interrupt ( which )X
  1518. X    int which;X
  1519. X{X
  1520. X    U_Ret rv;X
  1521. X    int temp, found = 0;X
  1522. X    int num;X
  1523. XX
  1524. X    /* get the first argument */X
  1525. X    if ( getEntry ( &rv, P_NUM ) ) {X
  1526. X        misuse ( which );X
  1527. X        return P_CONT;X
  1528. X    }X
  1529. XX
  1530. X    /* check if any arguments */X
  1531. X    if ( p_position == -1 ) {        /* no arguments */X
  1532. X        printf ( "Number     Period     Next Interrupt (in fetchs)\n" );X
  1533. X        for ( temp = 0; temp < var_param[INTNUM]; temp++ ) X
  1534. X            if ( interrupt[temp].period != -1 ) {X
  1535. X                printf ( "%-12d%-12x%x\n", temp + 1, interrupt[temp].period,X
  1536. X                 interrupt[temp].next );X
  1537. X                found++;X
  1538. X            }X
  1539. XX
  1540. X        /* Print no-find message if didn't */X
  1541. X        if ( ! found )X
  1542. X            printf ( "No Interrupt Vectors Set\n" );X
  1543. XX
  1544. X        /* Return and continue */            X
  1545. X        return P_CONT;X
  1546. X    }X
  1547. XX
  1548. X    /* set and check the interrupt number */X
  1549. X    if ( ( num = rv.ival ) < 1 || rv.ival > var_param[INTNUM] ) {X
  1550. X        printf ( "Interrupt vectors range from 1 to %d\n", var_param[INTNUM] );X
  1551. X        return P_CONT;X
  1552. X    }X
  1553. XX
  1554. X    /* get the second argument */X
  1555. X    if ( getEntry ( &rv, P_NUM ) ) {X
  1556. X        misuse ( which );X
  1557. X        return P_CONT;X
  1558. X    }X
  1559. XX
  1560. X    /* if only one argument - delete it from the list */X
  1561. X    if ( p_position == -1 ) {X
  1562. X        interrupt[num].period = interrupt[num].next = -1;X
  1563. X        return P_CONT;X
  1564. X    }X
  1565. XX
  1566. X    /* check interrupt value */X
  1567. X    if ( rv.ival < 1 ) {X
  1568. X        printf ( "Interrupts can only occur during 1 or more cycles.\n" );X
  1569. X        return P_CONT;X
  1570. X    }X
  1571. XX
  1572. X    /* check for any other arguments */X
  1573. X    getEntry ( &rv, P_NUM );X
  1574. X    if ( p_position != -1 ) {X
  1575. X        misuse ( which );X
  1576. X        return P_CONT;X
  1577. X    }X
  1578. XX
  1579. X    /* set the value */X
  1580. X    interrupt[num-1].period = rv.ival;X
  1581. X    interrupt[num-1].next = cycles + rv.ival;X
  1582. XX
  1583. X    /* continue on as normal */X
  1584. X    return P_CONT;X
  1585. XX
  1586. X}X
  1587. XX
  1588. XX
  1589. XX
  1590. X/****************************************************************************X
  1591. X *X
  1592. X * FUNCTION:        trace()X
  1593. X * PURPOSE:            set the trace parameters for displaying stuff    X
  1594. X * ARGUMENTS:        which - command entry numberX
  1595. X * RETURNS:            P_CONT - continue processing commands    X
  1596. X * NOTES:            noneX
  1597. X *X
  1598. X ***************************************************************************/X
  1599. XX
  1600. XintX
  1601. Xtrace ( which )X
  1602. X    int which;X
  1603. X{X
  1604. X    U_Ret rv;X
  1605. XX
  1606. X    /* get the first argument */X
  1607. X    getEntry ( &rv, P_STR );X
  1608. X    if ( p_position == -1 ) {        /* no arguments */X
  1609. X        misuse ( which );X
  1610. X        return P_CONT;X
  1611. X    }X
  1612. XX
  1613. X    /* check if there any more - should not be */X
  1614. X    if ( getEntry ( &rv, P_NUM ) ) {X
  1615. X        misuse ( which );X
  1616. X        return P_CONT;X
  1617. X    }X
  1618. XX
  1619. X    /* check and see if the argument is valid */X
  1620. X    if ( !strcmp ( "on", rv.str ) || !strcmp ( "o", rv.str ) ) {X
  1621. X        /* set trace to ON */X
  1622. X        traceChange = DEBUG;X
  1623. XX
  1624. X    } else if ( !strcmp ( "off", rv.str ) || !strcmp ( "f", rv.str ) ) {X
  1625. X        /* set trace to OFF */X
  1626. X        traceChange = NOTRACE;X
  1627. XX
  1628. X    } else if ( !strcmp ( "header", rv.str ) || !strcmp ( "h", rv.str ) ) {X
  1629. X        /* set trace to register print */X
  1630. X        traceChange = DEBUG_REG;X
  1631. XX
  1632. X    } else X
  1633. X        /* print misuse message */X
  1634. X        misuse ( which );X
  1635. XX
  1636. X    return P_CONT;X
  1637. X}X
  1638. XX
  1639. XX
  1640. XX
  1641. X/****************************************************************************X
  1642. X *X
  1643. X * FUNCTION:        resetCPU()X
  1644. X * PURPOSE:            reset the CPU to the start state    X
  1645. X * ARGUMENTS:        which - command entry numberX
  1646. X * RETURNS:            P_GOON - start executingX
  1647. X * NOTES:            noneX
  1648. X *X
  1649. X ***************************************************************************/X
  1650. XX
  1651. XintX
  1652. XresetCPU ( which )X
  1653. X    int which;X
  1654. X{X
  1655. X    U_Ret rv;X
  1656. X    int saveFetch;X
  1657. XX
  1658. X    /* No arguments */X
  1659. X    getEntry ( &rv, P_STR );X
  1660. X    if ( p_position != -1 ) {X
  1661. X        misuse ( which );X
  1662. X        return P_CONT;X
  1663. X    }X
  1664. XX
  1665. X    /* Reset variables */X
  1666. X    subcycles = var_param[SUBNUM] + 1;        /* complete all subcycles */X
  1667. X    mpc ( "set", 0 );                        /* set the mpc to zero */X
  1668. X    mpcptr = -1;                            /* current mpc to nil */X
  1669. X    saveFetch = var_param[FETCH];            /* save the fetch */X
  1670. X    init ( var_param );                        /* re-initialize */X
  1671. X    var_param[FETCH] = saveFetch;            /* put the real fetch back */X
  1672. X    cycles = 0;                             /* reset number of cycles */X
  1673. XX
  1674. X    return P_GOON;X
  1675. X}X
  1676. XX
  1677. XX
  1678. XX
  1679. X/****************************************************************************X
  1680. X *X
  1681. X * FUNCTION:        misuse()X
  1682. X * PURPOSE:            display a misuse of a command    X
  1683. X * ARGUMENTS:        which - which command to display (cmd entry #)X
  1684. X * RETURNS:            none    X
  1685. X * NOTES:            noneX
  1686. X *X
  1687. X ***************************************************************************/X
  1688. XX
  1689. XVOIDX
  1690. Xmisuse ( which )X
  1691. X    int which;X
  1692. X{X
  1693. X    printf ( cmds[which].help );X
  1694. X    printf ( "usage: %s <RETURN>\n", cmds[which].usage );X
  1695. X}X
  1696. XX
  1697. XX
  1698. Zaphod for prez
  1699. cat << 'Zaphod for prez' | sed 's/X\(.*\)X/\1/' > debug.h
  1700. XX
  1701. XX
  1702. X/* ----------------------------------------------------------------------- *\X
  1703. X ***************************************************************************X
  1704. XX
  1705. X  PROGRAM NAME: Debug headerX
  1706. XX
  1707. X  PROGRAMMER:    Patrick Palmer                 DATE: 8/17/90 X
  1708. X          X
  1709. X  DESCRIPTION OF PROGRAM: X
  1710. X    Debug header containing the definitions for the debug command set.X
  1711. X X
  1712. X ***************************************************************************X
  1713. XX
  1714. X        This program is free software; you can redistribute it and/orX
  1715. X        modify it under the terms of the GNU General Public LicenseX
  1716. X        (version 2) as published by the Free Software Foundation.X
  1717. XX
  1718. X        This program is distributed in the hope that is will be useful,X
  1719. X        but WITHOUT ANY WARRANTY; without even the implied warrenty ofX
  1720. X        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See theX
  1721. X        GNU General Public License for more details.X
  1722. X        X
  1723. X        You should have received a copy of the GNU General Public X
  1724. X        License along with this program; if not, write to the FreeX
  1725. X        Software Foundation, Inc., 675 Mass Ave, Cambridge, MAX
  1726. X        02139, USA.X
  1727. XX
  1728. X        YAMPC Microcode Development KitX
  1729. X        (C) 1992 by Patrick PalmerX
  1730. XX
  1731. X ***************************************************************************X
  1732. XX
  1733. XX
  1734. X  PROGRAM REVISION LOGX
  1735. X  X
  1736. X        DATE               DESCRIPTION OF CHANGE                PROGRAMMERX
  1737. X      --------  ----------------------------------------------  ----------X
  1738. X      08/17/90  YAMPC - Version 1.0                             PAPX
  1739. X      11/17/90  Interrupts, Bug Fixes - Version 1.1             PAPX
  1740. X      01/11/92  Distribution version - Version 1.2              PAPX
  1741. XX
  1742. X ***************************************************************************  X
  1743. X\* ----------------------------------------------------------------------- */X
  1744. XX
  1745. X/* debug commands information and definitions */X
  1746. X#define DEBUG_ENTRY    14X
  1747. XX
  1748. X/* structure containing the debug routines */X
  1749. Xstruct debug_cmds {X
  1750. X    char *word;                /* the word spelling */X
  1751. X    int matchnum;            /* number of characters needed to match */X
  1752. X    char *usage;            /* usage message if used improperly */X
  1753. X    char *help;                /* help message */X
  1754. X    int (*func) ( );        /* function pointer */X
  1755. XX
  1756. X} cmds [DEBUG_ENTRY] = {X
  1757. XX
  1758. X    {    "breakpoint",X
  1759. X        1,X
  1760. X        "breakpoint [#]",X
  1761. X        "(b)reakpoint [#]\t- set a breakpoint for address #\n",X
  1762. X        addBrkPtsX
  1763. X    },X
  1764. XX
  1765. X    {X
  1766. X        "calculator", X
  1767. X        1, X
  1768. X        "(c)alculator [expr]", X
  1769. X        "(c)alculator [expr]\t- calculate an expression (RPN, numbers in hex)\n", X
  1770. X        calculatorX
  1771. X    },X
  1772. XX
  1773. X    {X
  1774. X        "delete", X
  1775. X        2, X
  1776. X        "delete [#]", X
  1777. X        "(de)lete [#]\t\t- delete a breakpoint given the address\n", X
  1778. X        delBrkPtsX
  1779. X    },X
  1780. XX
  1781. X    {X
  1782. X        "display", X
  1783. X        1, X
  1784. X        "display <regs|(cpu|mem #)>",X
  1785. X        "(d)isplay <regs|(cpu|mem #)>\n\t\t\t- display registers, cpu memory, or main memory\n",X
  1786. X        displayX
  1787. X    },X
  1788. XX
  1789. X    {X
  1790. X        "exit", X
  1791. X        1, X
  1792. X        "exit", X
  1793. X        "(e)xit\t\t\t- Exit this program\n", X
  1794. X        exitProgX
  1795. X    },X
  1796. XX
  1797. X    {X
  1798. X        "help", X
  1799. X        1, X
  1800. X        "help", X
  1801. X        "(h)elp\t\t\t- This list of commands\n",X
  1802. X        helpX
  1803. X    },X
  1804. XX
  1805. X    {X
  1806. X        "interrupt", X
  1807. X        1, X
  1808. X        "interrupt <#> <##>", X
  1809. X        "(i)nterrupt <#> <##>\t- list, unset or set interrupts\n", X
  1810. X        D_interruptX
  1811. X    },X
  1812. XX
  1813. X    {X
  1814. X        "list", X
  1815. X        1, X
  1816. X        "list", X
  1817. X        "(l)ist\t\t\t- list all set breakpoints\n", X
  1818. X        showBrkPtsX
  1819. X    },X
  1820. XX
  1821. X    {X
  1822. X        "quit", X
  1823. X        1, X
  1824. X        "quit", X
  1825. X        "(q)uit\t\t\t- Exit this program\n", X
  1826. X        exitProgX
  1827. X    },X
  1828. XX
  1829. X    {X
  1830. X        "run", X
  1831. X        1, X
  1832. X        "run <#>", X
  1833. X        "(r)un <#>\t\t- run continous or a certain number\n",X
  1834. X        runX
  1835. X    },X
  1836. XX
  1837. X    {X
  1838. X        "reset", X
  1839. X        2, X
  1840. X        "reset", X
  1841. X        "(re)set\t\t\t- Reset the system to initial state\n", X
  1842. X        resetCPUX
  1843. X    },X
  1844. XX
  1845. X    {X
  1846. X        "set", X
  1847. X        1, X
  1848. X        "set [regs|mem] [#] <#>", X
  1849. X        "(s)et [regs|mem] [#] <#>- set a register or memory to a value\n", X
  1850. X        setSomeX
  1851. X    },X
  1852. XX
  1853. X    {X
  1854. X        "trace", X
  1855. X        1, X
  1856. X        "trace [On|oFf|Header]", X
  1857. X        "(t)race [On|oFf|Header]\t- set the trace of the debug mode\n", X
  1858. X        traceX
  1859. X    },X
  1860. XX
  1861. X    {X
  1862. X        "version", X
  1863. X        1, X
  1864. X        "version", X
  1865. X        "(v)ersion\t\t- display current version of this program\n", X
  1866. X        versionX
  1867. X    }X
  1868. X};X
  1869. XX
  1870. Zaphod for prez
  1871. cat << 'Zaphod for prez' | sed 's/X\(.*\)X/\1/' > lalr.y
  1872. XX
  1873. X%{X
  1874. XX
  1875. X/* ----------------------------------------------------------------------- *\X
  1876. X******************************************************************************X
  1877. XX
  1878. X  PROGRAM NAME: YAMPC LALRX
  1879. XX
  1880. X  PROGRAMMER:    Patrick Palmer                 DATE: 8/17/90 X
  1881. X          X
  1882. X  DESCRIPTION OF PROGRAM: X
  1883. X    Parser for the input computer hardware file.X
  1884. X X
  1885. X******************************************************************************X
  1886. XX
  1887. X        This program is free software; you can redistribute it and/orX
  1888. X        modify it under the terms of the GNU General Public LicenseX
  1889. X        (version 2) as published by the Free Software Foundation.X
  1890. XX
  1891. X        This program is distributed in the hope that is will be useful,X
  1892. X        but WITHOUT ANY WARRANTY; without even the implied warrenty ofX
  1893. X        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See theX
  1894. X        GNU General Public License for more details.X
  1895. X        X
  1896. X        You should have received a copy of the GNU General Public X
  1897. X        License along with this program; if not, write to the FreeX
  1898. X        Software Foundation, Inc., 675 Mass Ave, Cambridge, MAX
  1899. X        02139, USA.X
  1900. XX
  1901. X        YAMPC Microcode Development KitX
  1902. X        (C) 1992 by Patrick PalmerX
  1903. XX
  1904. X******************************************************************************X
  1905. XX
  1906. XX
  1907. X  PROGRAM REVISION LOGX
  1908. X  X
  1909. X        DATE               DESCRIPTION OF CHANGE                PROGRAMMERX
  1910. X      --------  ----------------------------------------------  ----------X
  1911. X      08/17/90  YAMPC - Version 1.0                             PAPX
  1912. X      11/17/90  Interrupts, Bug Fixes - Version 1.1             PAPX
  1913. X      01/11/92  Distribution version - Version 1.2              PAPX
  1914. XX
  1915. X***************************************************************************  X
  1916. X\* ------------------------------------------------------------------------ */X
  1917. XX
  1918. X#include <stdio.h>X
  1919. X#include "yampc.h"X
  1920. X#include "misc.h"X
  1921. XX
  1922. X#define YYSTYPE struct ystack        /* yacc stack type */X
  1923. XX
  1924. Xextern int lineNo;X
  1925. XX
  1926. X/* current section */X
  1927. Xint section;X
  1928. XX
  1929. X/* number of defaults for switches */X
  1930. Xint def_num;X
  1931. XX
  1932. X/* temp buffer */X
  1933. Xchar buffer[128];X
  1934. XX
  1935. X%}X
  1936. XX
  1937. X/* start and end tokens */X
  1938. X%token    START ENDX
  1939. XX
  1940. X/* subparts of the hardware description file */X
  1941. X%token    FORMAT PARTS MEMORY SUBCYCLE INTERRUPT INIT ENGINE VARSX
  1942. XX
  1943. X/* memory tokens */X
  1944. X%token    CMEM MEMX
  1945. XX
  1946. X/* statement commands */X
  1947. X%token    IF ELSEX
  1948. X%token    SWITCH CASE DEFAULT BREAK RETURNX
  1949. XX
  1950. X/* others */X
  1951. X%token    UNKNOWN VAR NUM SUB SUBSCRIPT INTERX
  1952. XX
  1953. X/* set the left associative with other tokens */X
  1954. X%left '='X
  1955. X%left OR ANDX
  1956. X%left BOR EOR BANDX
  1957. X%left SL SRX
  1958. X%left EQ GT GE LT LE NEX
  1959. X%left '+' '-'X
  1960. X%left '*' '/' '%' X
  1961. X%left BNOT NOTX
  1962. XX
  1963. X/* Get rid of the Shift/Reduce Warning Messages */X
  1964. X%left ELSEX
  1965. XX
  1966. X%%X
  1967. XX
  1968. Xprogram:    list;X
  1969. X    ;X
  1970. XX
  1971. Xlist:X
  1972. X    |    START format parts vars memory sub interrupt init engine ENDX
  1973. X    |    errorX
  1974. X    {X
  1975. X        warning ( "File not properly formatted", (char *) 0 );X
  1976. X        return 1; X
  1977. X    }X
  1978. X    ;X
  1979. XX
  1980. Xformat:        formatcmd format_data ';'X
  1981. X    ;X
  1982. XX
  1983. Xformatcmd:    FORMATX
  1984. X    {X
  1985. X        section = FORMATNUM;X
  1986. X        init_var ( );X
  1987. X    }X
  1988. X    ;X
  1989. XX
  1990. Xparts:        partscmd parts_data ';'X
  1991. X    ;X
  1992. XX
  1993. Xpartscmd:    PARTSX
  1994. X    {X
  1995. X        section = PARTSNUM;X
  1996. X    }X
  1997. XX
  1998. Xvars:X
  1999. X    {X
  2000. X        end_struct ( );X
  2001. X    }X
  2002. X    |    varscmd format_data ';'X
  2003. X    {X
  2004. X        end_struct ( );X
  2005. X    }X
  2006. X    ;X
  2007. XX
  2008. Xvarscmd:    VARSX
  2009. X    {X
  2010. X        section = VARSNUM;X
  2011. X    }X
  2012. XX
  2013. Xmemory:        MEMORY CMEM '[' NUM ']' ',' MEM '[' NUM ']' '[' NUM ']' ';'X
  2014. X    {X
  2015. X        set_mem ( $4.val, $9.val, $12.val );X
  2016. X    }X
  2017. X    |    error X
  2018. X    {X
  2019. X        warning ( "Memory definitions not properly defined", (char *) 0 );X
  2020. X    }X
  2021. X    ;X
  2022. XX
  2023. Xsub:X
  2024. X    |    SUBCYCLE SUB '=' NUM ';'X
  2025. X    {X
  2026. X        set_entry ( SUBNUM, $4.val );X
  2027. X    }X
  2028. X    |    errorX
  2029. X    {X
  2030. X        warning ( "Subcycle definition not properly defined", (char *) 0 );X
  2031. X    }X
  2032. X    ;X
  2033. XX
  2034. Xinterrupt:X
  2035. X    {X
  2036. X        set_entry ( INTNUM, 0 );X
  2037. X    }X
  2038. X    |    INTERRUPT INTER '=' NUM ';'X
  2039. X    {X
  2040. X        set_entry ( INTNUM, $4.val );X
  2041. X    }X
  2042. X    |    error X
  2043. X    {X
  2044. X        warning ( "Interrupt definition not properly defined", (char *) 0 );X
  2045. X    }X
  2046. X    ;X
  2047. XX
  2048. Xinit:X
  2049. X    |    initcmd state_listX
  2050. X    {X
  2051. X        end_func ( );X
  2052. X    }X
  2053. X    |    errorX
  2054. X    {X
  2055. X        warning ( "Error in defining initializations", (char *) 0 );X
  2056. X    }X
  2057. X    ;X
  2058. XX
  2059. Xinitcmd:    INITX
  2060. X    {X
  2061. X        start_init ( );X
  2062. X    }X
  2063. X    ;X
  2064. XX
  2065. Xengine:        enginecmd state_listX
  2066. X    {X
  2067. X        end_engine ( );X
  2068. X    }X
  2069. X    |    errorX
  2070. X    {X
  2071. X        warning ( "Error in Microengine", (char *) 0 );X
  2072. X    }X
  2073. X    ;X
  2074. XX
  2075. Xenginecmd:    ENGINEX
  2076. X    {X
  2077. X        start_engine ( );X
  2078. X    }X
  2079. X    ;X
  2080. XX
  2081. Xformat_data:    format_varX
  2082. X    |    format_var ',' format_dataX
  2083. X    ;X
  2084. X    X
  2085. Xformat_var:    VAR '[' NUM ']'X
  2086. X    {X
  2087. X        add_var ( $1.str, $3.val, section, 0 );X
  2088. X    }X
  2089. X    |    error ';'X
  2090. X    {X
  2091. X        warning ( "Syntax error in declaration section", "" );X
  2092. X        yyerrok;X
  2093. X    }X
  2094. X    ;X
  2095. XX
  2096. Xparts_data:    parts_varX
  2097. X    |    parts_var ',' parts_dataX
  2098. X    ;X
  2099. X    X
  2100. Xparts_var:    '*' VAR    '[' NUM ']'X
  2101. X    {X
  2102. X        add_var ( $2.str, $4.val, section, 1 );X
  2103. X    }X
  2104. X    |    VAR '[' NUM ']'X
  2105. X    {X
  2106. X        add_var ( $1.str, $3.val, section, 0 );X
  2107. X    }X
  2108. X    |    error ';'X
  2109. X    {X
  2110. X        warning ( "Syntax error in declaration section", "" );X
  2111. X        yyerrok;X
  2112. X    }X
  2113. X    ;X
  2114. XX
  2115. Xstate:        start_brace state_list end_braceX
  2116. X    |    expr ';'X
  2117. X    {X
  2118. X        put_msg ( "pop ( );" );X
  2119. X    }X
  2120. X    |    IF if_clause state do_end_brace otherX
  2121. X    |    SWITCH switch '{' in_switch end_braceX
  2122. X    |    BREAK ';'X
  2123. X    {X
  2124. X        put_msg ( "break;" );X
  2125. X    }X
  2126. X    |    RETURN ';'X
  2127. X    {X
  2128. X        put_msg ( "return 1;" );X
  2129. X    }X
  2130. X    |    error ';'X
  2131. X    {X
  2132. X        warning ( "Syntax error", "with an expression" );X
  2133. X        yyerrok;X
  2134. X    }X
  2135. X    ;X
  2136. XX
  2137. Xstate_list:    stateX
  2138. X    |    state state_listX
  2139. X    ;X
  2140. XX
  2141. Xstart_brace:    '{'X
  2142. X    {X
  2143. X        put_msg ( "{" );X
  2144. X    }X
  2145. X    ;X
  2146. XX
  2147. Xend_brace:    '}'X
  2148. X    {X
  2149. X        put_msg ( "}" );X
  2150. X    }X
  2151. X    ;X
  2152. XX
  2153. Xdo_end_brace:X
  2154. X    {X
  2155. X        put_msg ( "}" );X
  2156. X    }X
  2157. X    ;X
  2158. X    X
  2159. Xif_clause:    '(' expr ')'X
  2160. X    {X
  2161. X        put_msg ( "if ( pop ( ) ) {" );X
  2162. X    }X
  2163. X    ;X
  2164. XX
  2165. Xother:    X
  2166. X    |    else stateX
  2167. X    {X
  2168. X        put_msg ( "}" );X
  2169. X    }X
  2170. X    ;X
  2171. XX
  2172. Xelse:    ELSEX
  2173. X    {X
  2174. X        put_msg ( "else {" );X
  2175. X    }X
  2176. X    ;X
  2177. XX
  2178. Xexpr:        valueX
  2179. X    |    '(' expr ')' X
  2180. X    |    uminas exprX
  2181. X    {X
  2182. X        sprintf ( buffer, "do_stack ( %d );    /* neg operation */",X
  2183. X         (int) '-' );X
  2184. X        put_msg ( buffer );X
  2185. X    }X
  2186. X    |    expr oper exprX
  2187. X    {X
  2188. X        sprintf ( buffer, "do_stack ( %d );    /* math operation */",X
  2189. X         $2.val );X
  2190. X        put_msg ( buffer );X
  2191. X    }X
  2192. X    |    MEM '[' expr ']'X
  2193. X    {X
  2194. X        sprintf ( buffer, "push ( %d, pop() );    /* memory access */",X
  2195. X         MEM );X
  2196. X        put_msg ( buffer );X
  2197. X    }X
  2198. X    ;X
  2199. XX
  2200. Xswitch:        '(' expr ')' X
  2201. X    {X
  2202. X        def_num = 1;X
  2203. X        put_msg ( "switch ( pop ( ) ) {" );X
  2204. X    }X
  2205. X    |    errorX
  2206. X    {X
  2207. X        warning ( "Inproper expression in switch", (char *) 0 );X
  2208. X    }X
  2209. X    ;X
  2210. XX
  2211. Xin_switch:    sub_switchX
  2212. X    |    sub_switch in_switchX
  2213. X    ;X
  2214. XX
  2215. Xsub_switch:    case state_listX
  2216. X    |    caseX
  2217. X    |    default state_list X
  2218. X    |    defaultX
  2219. X    |    error ';'X
  2220. X    {X
  2221. X        warning ( "Inproper switch statement", (char *) 0 );X
  2222. X        yyerrok;X
  2223. X    }X
  2224. X    ;X
  2225. XX
  2226. Xcase:        CASE NUM ':'X
  2227. X    {X
  2228. X        sprintf ( buffer, "case %d:", $2.val );X
  2229. X        put_msg ( buffer );X
  2230. X    }X
  2231. X    ;X
  2232. XX
  2233. Xdefault:    DEFAULT ':'X
  2234. X    {X
  2235. X        if ( ! def_num )X
  2236. X            warning ( "Multidefined default statements in switch",X
  2237. X             (char *) 0 );X
  2238. X        else def_num = 0;X
  2239. X        put_msg ( "default:" );X
  2240. X    }X
  2241. X    ;X
  2242. XX
  2243. Xuminas:        '-'X
  2244. X    {X
  2245. X        sprintf ( buffer, "push ( %d, 0 );", NUM );X
  2246. X        put_msg ( buffer );X
  2247. X    }X
  2248. X    ;X
  2249. XX
  2250. Xvalue:X
  2251. X    |    NUMX
  2252. X    {X
  2253. X        sprintf ( buffer, "push ( %d, %d );    /* number - %d */",X
  2254. X         NUM, $1.val, $1.val );X
  2255. X        put_msg ( buffer );X
  2256. X    }X
  2257. X    |    SUBX
  2258. X    {X
  2259. X        sprintf ( buffer, "push ( %d, 0 );    /* subcycle */", SUB );X
  2260. X        put_msg ( buffer );X
  2261. X    }X
  2262. X    |    CMEMX
  2263. X    {X
  2264. X        sprintf ( buffer, "push ( %d, 0 );    /* computer memory */",X
  2265. X         CMEM );X
  2266. X        put_msg ( buffer );X
  2267. X    }X
  2268. X    |    VARX
  2269. X    {X
  2270. X        sprintf ( buffer, "push ( %d, %d );    /* variable - %s */",X
  2271. X         VAR, queryLocalVar ( $1.str ), $1.str );X
  2272. X        put_msg ( buffer );X
  2273. X    }X
  2274. X    ;X
  2275. XX
  2276. Xoper:        EQ    {    $$.val = EQ;        }X
  2277. X    |    GT    {    $$.val = GT;        }X
  2278. X    |    GE    {    $$.val = GE;        }X
  2279. X    |    LT    {    $$.val = LT;        }X
  2280. X    |    LE    {    $$.val = LE;        }X
  2281. X    |    NE    {    $$.val = NE;        }X
  2282. X    |    AND    {    $$.val = AND;        }X
  2283. X    |    OR    {    $$.val = OR;        }X
  2284. X    |    NOT    {    $$.val = NOT;        }X
  2285. X    |    BAND    {    $$.val = BAND;        }X
  2286. X    |    BOR    {    $$.val = BOR;        }X
  2287. X    |    SR    {    $$.val = SR;        }X
  2288. X    |    SL    {    $$.val = SL;        }X
  2289. X    |    BNOT    {    $$.val = BNOT;        }X
  2290. X    |    EOR    {    $$.val = EOR;        }X
  2291. X    |    '='    {    $$.val = (int) '=';    }X
  2292. X    |    '+'    {    $$.val = (int) '+';    }X
  2293. X    |    '-'    {    $$.val = (int) '-';    }X
  2294. X    |    '*'    {    $$.val = (int) '*';    }X
  2295. X    |    '/'    {    $$.val = (int) '/';    }X
  2296. X    |    '%'    {    $$.val = (int) '%';    }X
  2297. X    ;X
  2298. XX
  2299. X%%X
  2300. XX
  2301. XX
  2302. X/****************************************************************************X
  2303. X *X
  2304. X * FUNCTION:        yyerror()X
  2305. X * PURPOSE:            When there is an error in parsing, error messageX
  2306. X * ARGUMENTS:        string - string containing reasoning of errorX
  2307. X * RETURNS:            nothingX
  2308. X * NOTES:            X
  2309. X *X
  2310. X ***************************************************************************/X
  2311. XX
  2312. XintX
  2313. Xyyerror ( str )X
  2314. X    char * str;X
  2315. X{X
  2316. X    warning ( str, (char *) 0 );X
  2317. X}X
  2318. XX
  2319. XX
  2320. X/****************************************************************************X
  2321. X *X
  2322. X * FUNCTION:        warning()X
  2323. X * PURPOSE:            display a warning messageX
  2324. X * ARGUMENTS:        s, t - two strings to display side-by-sideX
  2325. X * RETURNS:            nothingX
  2326. X * NOTES:            X
  2327. X *X
  2328. X ***************************************************************************/X
  2329. XX
  2330. XintX
  2331. Xwarning ( s, t )X
  2332. X    char *s, *t;X
  2333. X{X
  2334. X    fprintf ( stderr, "%s", s );X
  2335. X    if ( t )X
  2336. X        fprintf ( stderr, " %s", t );X
  2337. X    fprintf ( stderr, " in line %d\n", lineNo );X
  2338. X}X
  2339. XX
  2340. Zaphod for prez
  2341. cat << 'Zaphod for prez' | sed 's/X\(.*\)X/\1/' > lex.l
  2342. XX
  2343. X%{X
  2344. XX
  2345. X/* ---------------------------------------------------------------------- *\X
  2346. X **************************************************************************X
  2347. XX
  2348. X  PROGRAM NAME: Lexical ParserX
  2349. XX
  2350. X  PROGRAMMER:    Patrick Palmer                 DATE: 8/17/90 X
  2351. X          X
  2352. X  DESCRIPTION OF PROGRAM: X
  2353. X    A parser to break down the input computer hardware file.X
  2354. X X
  2355. X **************************************************************************X
  2356. XX
  2357. X        This program is free software; you can redistribute it and/orX
  2358. X        modify it under the terms of the GNU General Public LicenseX
  2359. X        (version 2) as published by the Free Software Foundation.X
  2360. XX
  2361. X        This program is distributed in the hope that is will be useful,X
  2362. X        but WITHOUT ANY WARRANTY; without even the implied warrenty ofX
  2363. X        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See theX
  2364. X        GNU General Public License for more details.X
  2365. X        X
  2366. X        You should have received a copy of the GNU General Public X
  2367. X        License along with this program; if not, write to the FreeX
  2368. X        Software Foundation, Inc., 675 Mass Ave, Cambridge, MAX
  2369. X        02139, USA.X
  2370. XX
  2371. X        YAMPC Microcode Development KitX
  2372. X        (C) 1992 by Patrick PalmerX
  2373. XX
  2374. X **************************************************************************X
  2375. XX
  2376. XX
  2377. X  PROGRAM REVISION LOGX
  2378. X  X
  2379. X        DATE               DESCRIPTION OF CHANGE                PROGRAMMERX
  2380. X      --------  ----------------------------------------------  ----------X
  2381. X      08/17/90  YAMPC - Version 1.0                             PAPX
  2382. X      11/17/90  Interrupts, Bug Fixes - Version 1.1             PAPX
  2383. X      01/11/92  Distribution version - Version 1.2              PAPX
  2384. XX
  2385. X **************************************************************************  X
  2386. X\* ------------------------------------------------------------------------ */X
  2387. XX
  2388. X#include "y.tab.h"X
  2389. X#include "yampc.h"X
  2390. XX
  2391. Xextern struct ystack yylval;X
  2392. XX
  2393. X/* line counter - should not use yylineno because it is incompatibleX
  2394. X *  with flex */X
  2395. Xint lineNo = 0;X
  2396. XX
  2397. X%}X
  2398. XX
  2399. X%o 20000X
  2400. XX
  2401. X%%X
  2402. X"/*"        /* ignore comments */ X
  2403. X            { X
  2404. X                int done = 0;X
  2405. X                char c = getc ( yyin );X
  2406. X                while ( ! done )             /* find end of comment */X
  2407. X                    if ( c == '\n' ) {X
  2408. X                        lineNo++;X
  2409. X                        c = getc ( yyin );X
  2410. X                    } else if ( c == '*' ) {X
  2411. X                        if ( ( c = getc ( yyin ) ) == '/' )X
  2412. X                            done = 1;X
  2413. X                        else if ( c != '*' )X
  2414. X                            c = getc ( yyin );X
  2415. X                    } elseX
  2416. X                        c = getc ( yyin );X
  2417. X            }X
  2418. XX
  2419. X[ \t]+        /* ignore whitespaces */X
  2420. X            ;X
  2421. XX
  2422. X"\n"+        /* count newlines */X
  2423. X            lineNo += yyleng;X
  2424. XX
  2425. XBEGIN        /* beginning of the hardware file */X
  2426. X             return START; X
  2427. XX
  2428. XEND            /* end of the hardware file */X
  2429. X            return END;X
  2430. XX
  2431. XFORMAT        /* defining the format of the microprogram */X
  2432. X            return FORMAT;X
  2433. XX
  2434. XPARTS        /* defining the variable parts */X
  2435. X            return PARTS;X
  2436. XX
  2437. XVARS        /* defining the local variables */X
  2438. X            return VARS;X
  2439. XX
  2440. XMEMORY        /* defining the memory structure */X
  2441. X            return MEMORY;X
  2442. XX
  2443. XSUBCYCLE    /* defining the number of subcycles */X
  2444. X            return SUBCYCLE;X
  2445. XX
  2446. XINTERRUPT    /* defining the number of interrupts */X
  2447. X            return INTERRUPT;X
  2448. XX
  2449. XINIT        /* the initialization of the variables */X
  2450. X            return INIT;X
  2451. XX
  2452. XMICROENGINE    /* beginning of the micro-engine section */X
  2453. X            return ENGINE;X
  2454. XX
  2455. Xcpu            /* computer memory - internal */X
  2456. X            return CMEM;X
  2457. XX
  2458. Xmem            /* external memory */X
  2459. X            return MEM;X
  2460. XX
  2461. Xsubcycle    /* the current subcycle variable */X
  2462. X            return SUB;X
  2463. XX
  2464. Xinterrupt    /* 'interrupt = X' value */X
  2465. X            return INTER;X
  2466. XX
  2467. Xif            /* 'if' - start of a compare */X
  2468. X            return IF;X
  2469. XX
  2470. Xelse        /* 'else' - an extra clause in an if */X
  2471. X            return ELSE;X
  2472. XX
  2473. Xswitch        /* 'switch' - beginning of a switch */X
  2474. X            return SWITCH;X
  2475. XX
  2476. Xcase        /* 'case' - subpart of a switch */X
  2477. X            return CASE;X
  2478. XX
  2479. Xdefault        /* 'default' - fall through in switch */X
  2480. X            return DEFAULT;X
  2481. XX
  2482. Xbreak        /* 'break' - command used in switches */X
  2483. X            return BREAK;X
  2484. XX
  2485. XIreturn        /* 'Ireturn' - return because unable to service interrupt */X
  2486. X            return RETURN;X
  2487. XX
  2488. X[a-zA-Z][a-zA-Z0-9]*    /* variable */X
  2489. X            {X
  2490. X            strcpy ( yylval.str, yytext );X
  2491. X            return VAR;X
  2492. X            }X
  2493. XX
  2494. X("0x"|\$)[0-9A-Fa-f]+    /* hexidecimal number */X
  2495. X            {X
  2496. X            yylval.val = convStr ( ( yytext[0] == '$' ? X
  2497. X                &yytext[1] : &yytext[2] ), HEX );X
  2498. X            return NUM;X
  2499. X            }X
  2500. XX
  2501. X"0"[0-9]*    /* Octal number or zero */ X
  2502. X            {X
  2503. X            yylval.val = convStr ( yytext, OCT );X
  2504. X            return NUM;X
  2505. X            }X
  2506. XX
  2507. X"=="        /* query if equal */X
  2508. X            return EQ;X
  2509. XX
  2510. X">"            /* greater than */X
  2511. X            return GT;X
  2512. XX
  2513. X">="        /* greater than or equal */X
  2514. X            return GE;X
  2515. XX
  2516. X"<"            /* less than */X
  2517. X            return LT;X
  2518. XX
  2519. X"<="        /* less than or equal */X
  2520. X            return LE;X
  2521. XX
  2522. X"!="        /* not equal */X
  2523. X            return NE;X
  2524. XX
  2525. X"&&"        /* and */X
  2526. X            return AND;X
  2527. XX
  2528. X"&"            /* binary and */X
  2529. X            return BAND;X
  2530. XX
  2531. X"||"        /* or */X
  2532. X            return OR;X
  2533. XX
  2534. X"|"            /* binary or */X
  2535. X            return BOR;X
  2536. XX
  2537. X"^"            /* X-or */X
  2538. X            return EOR;X
  2539. XX
  2540. X"~"            /* one's compliment  - not */X
  2541. X            return BNOT;X
  2542. XX
  2543. X"!"            /* logical NOT */X
  2544. X            return NOT;X
  2545. XX
  2546. X">>"        /* shift right */X
  2547. X            return SR;X
  2548. XX
  2549. X"<<"        /* shift left */X
  2550. X            return SL;X
  2551. XX
  2552. X[0-9]+        /* Decimal number */X
  2553. X            {X
  2554. X            yylval.val = convStr ( yytext, DEC );X
  2555. X            return NUM;X
  2556. X            }X
  2557. XX
  2558. X.            /* anything else */X
  2559. X            return yytext[0];X
  2560. XX
  2561. X%%X
  2562. XX
  2563. XX
  2564. X/****************************************************************************X
  2565. X *X
  2566. X * FUNCTION:        setInput()X
  2567. X * PURPOSE:            set the input file descriptor to the hardware spec fileX
  2568. X * ARGUMENTS:        fp - file pointer to the hardware spec fileX
  2569. X * RETURNS:            nothingX
  2570. X * NOTES:            X
  2571. X *X
  2572. X ***************************************************************************/X
  2573. XX
  2574. XintX
  2575. XsetInput ( fp )X
  2576. X    FILE *fp;                /* file pointer */X
  2577. X{X
  2578. X    yyin = fp;X
  2579. X}X
  2580. XX
  2581. XX
  2582. XX
  2583. X/****************************************************************************X
  2584. X *X
  2585. X * FUNCTION:        yywrap()X
  2586. X * PURPOSE:            stub functionX
  2587. X * ARGUMENTS:        noneX
  2588. X * RETURNS:            1 - completeX
  2589. X * NOTES:            the purpose of the routine is so the lex library X
  2590. X *                    isn't needed; this can be useful when using otherX
  2591. X *                    parsers besides the standard AT&T lex.X
  2592. X *X
  2593. X ***************************************************************************/X
  2594. XX
  2595. XintX
  2596. Xyywrap ( )X
  2597. X{X
  2598. X    return 1;                /* done with yywrap */X
  2599. X}X
  2600. XX
  2601. Zaphod for prez
  2602. cat << 'Zaphod for prez' | sed 's/X\(.*\)X/\1/' > main.c
  2603. XX
  2604. X/* ----------------------------------------------------------------------- *\X
  2605. X******************************************************************************X
  2606. XX
  2607. X  PROGRAM NAME: Main moduleX
  2608. XX
  2609. X  PROGRAMMER:    Patrick Palmer                    DATE: 8/17/90 X
  2610. X          X
  2611. X  DESCRIPTION OF PROGRAM: X
  2612. X    This is the first function executed.  It sets up the necessaryX
  2613. X  variables and then starts running the engine (runMicro).  X
  2614. X  X
  2615. X******************************************************************************X
  2616. XX
  2617. X        This program is free software; you can redistribute it and/orX
  2618. X        modify it under the terms of the GNU General Public LicenseX
  2619. X        (version 2) as published by the Free Software Foundation.X
  2620. XX
  2621. X        This program is distributed in the hope that is will be useful,X
  2622. X        but WITHOUT ANY WARRANTY; without even the implied warrenty ofX
  2623. X        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See theX
  2624. X        GNU General Public License for more details.X
  2625. X        X
  2626. X        You should have received a copy of the GNU General Public X
  2627. X        License along with this program; if not, write to the FreeX
  2628. X        Software Foundation, Inc., 675 Mass Ave, Cambridge, MAX
  2629. X        02139, USA.X
  2630. XX
  2631. X        YAMPC Microcode Development KitX
  2632. X        (C) 1992 by Patrick PalmerX
  2633. XX
  2634. X******************************************************************************X
  2635. XX
  2636. XX
  2637. X  PROGRAM REVISION LOGX
  2638. X  X
  2639. X        DATE               DESCRIPTION OF CHANGE                PROGRAMMERX
  2640. X      --------  ----------------------------------------------  ----------X
  2641. X      08/17/90  YAMPC - Version 1.0                             PAPX
  2642. X      11/17/90  Interrupts, Bug Fixes - Version 1.1             PAPX
  2643. X      01/11/92  Distribution version - Version 1.2              PAPX
  2644. XX
  2645. X***************************************************************************  X
  2646. X\* ------------------------------------------------------------------------ */X
  2647. XX
  2648. XX
  2649. X#include <stdio.h>X
  2650. X#include "main.h"X
  2651. X#include "misc.h"X
  2652. XX
  2653. Xextern struct varlist var[];X
  2654. Xint var_param[NUM_PARAM];X
  2655. Xstruct interruptlist *interrupt;X
  2656. Xint cycles, subcycles;X
  2657. Xint mpcptr;X
  2658. XX
  2659. XX
  2660. X/****************************************************************************X
  2661. X *X
  2662. X * FUNCTION:        main()X
  2663. X * PURPOSE:            first routine to start executing microcodeX
  2664. X * ARGUMENTS:        argc - number of command line argumentsX
  2665. X *                    argv - command line argumentsX
  2666. X * RETURNS:            nothing interesting    X
  2667. X * NOTES:            X
  2668. X *X
  2669. X ***************************************************************************/X
  2670. XX
  2671. XintX
  2672. Xmain ( argc, argv )X
  2673. X    int argc;X
  2674. X    char **argv;X
  2675. X{X
  2676. X    int mema[3];            /* cmemory, memory, correct argument */X
  2677. X    int temp, temp1;        /* temp variables used in loops */X
  2678. X    int memptr = 0;            /* argument memory ptr */X
  2679. X    int mode;                /* current debug mode */X
  2680. XX
  2681. X    /* print version of this program */X
  2682. X    version ( );X
  2683. XX
  2684. X    /* call the init program */X
  2685. X    init ( var_param );X
  2686. XX
  2687. X    /* initialize the interrupt list */X
  2688. X    initInterrupt ( );X
  2689. XX
  2690. X    /* mema[0] (cmemory) set to no new name */X
  2691. X    /* mema[1] (memory)  set to no new name */X
  2692. X    /* mema[2] (correct) set the correction file */X
  2693. X    mema[0] = mema[1] = mema[2] = 0;X
  2694. XX
  2695. X    /* call the memory allocation programs for access memory */X
  2696. X    allocCMem ( );            /* allocate memory for micro code */X
  2697. X    allocMMem ( );            /* allocate memory for main memory */X
  2698. XX
  2699. X    /* set all the break points to zero */X
  2700. X    setBrkPts ( );X
  2701. XX
  2702. X    /* set mode to NO DEBUGGING */X
  2703. X    mode = NOTRACE;X
  2704. XX
  2705. X    /* check arguments */X
  2706. X    for ( temp = 1; temp < argc; temp++ )X
  2707. X        if ( argv[temp][0] == '-' ) {X
  2708. X            for ( temp1 = 1; temp1 < strlen ( argv[temp] ); temp1++ )X
  2709. X                switch ( argv[temp][temp1] ) {X
  2710. X                    case 'c':        /* create correction file */X
  2711. X                        mode = CREATE;X
  2712. X                        addCorrect ( &argv[temp][temp1+1] );X
  2713. X                        temp1 = strlen ( argv[temp] );X
  2714. X                        break;X
  2715. XX
  2716. X                    case 'd':        /* debug mode */X
  2717. X                        mode = DEBUG;X
  2718. X                        break;X
  2719. XX
  2720. X                    case 'F':        /* display all regs at each cycle */X
  2721. X                        mode = NOTRACE_REG;X
  2722. X                        break;X
  2723. XX
  2724. X                    case 'f':        /* display all regs at each fetch */X
  2725. X                        mode = NOTRACE_FREG;X
  2726. X                        break;X
  2727. XX
  2728. X                    default:X
  2729. X                        usage ( argv[0] );X
  2730. X                }X
  2731. XX
  2732. X        } else if ( argv[temp][0] == '+' ) {X
  2733. X            int notperiod = 0, num[2];X
  2734. XX
  2735. X            /* initialize */X
  2736. X            num[0] = num[1] = 0;X
  2737. XX
  2738. X            /* check and get arguments */X
  2739. X            for ( temp1 = 1; temp1 < strlen ( argv[temp] ) + 1; temp1++ ) {X
  2740. X                if ( argv[temp][temp1] == '\0' ) {X
  2741. X                    notperiod++;X
  2742. X                    break;X
  2743. X                } else if ( ( argv[temp][temp1] >= '0' && argv[temp][temp1] <=X
  2744. X                 '9' ) || ( argv[temp][temp1] >='a' && argv[temp][temp1] <= 'f' ) ) {X
  2745. X                    if ( notperiod > 1 )X
  2746. X                        usage ( argv[0] );X
  2747. X                    num[notperiod] *= 16;X
  2748. X                    num[notperiod] += ( argv[temp][temp1] - ( argv[temp][temp1] X
  2749. X                     >= 'a' ? (int) 'a' : (int) '0' ) );X
  2750. X                } else if ( argv[temp][temp1] == ':' ) {X
  2751. X                    if ( temp1 == strlen ( argv[temp] ) )X
  2752. X                        usage ( argv[0] );X
  2753. X                    notperiod++;X
  2754. X                } elseX
  2755. X                    usage ( argv[0] );X
  2756. X            }X
  2757. XX
  2758. X            /* check values */X
  2759. X            if ( notperiod < 2 || num[0] > var_param[INTNUM] || num[0] < 1 )X
  2760. X                usage ( argv[0] );X
  2761. XX
  2762. X            /* set values */X
  2763. X            interrupt[num[0]-1].period = interrupt[num[0]-1].next = num[1];X
  2764. XX
  2765. X        } else if ( memptr < 3 )X
  2766. X            mema[memptr++] = temp;X
  2767. XX
  2768. X        else X
  2769. X            usage ( argv[0] );X
  2770. X        X
  2771. X    X
  2772. X    /* read in the memory */X
  2773. X    if ( mema[0] )X
  2774. X        readCmem ( argv[mema[0]] );X
  2775. X    elseX
  2776. X        readCmem ( "cmemory" );X
  2777. X    if ( mema[1] )X
  2778. X        readMmem ( argv[mema[1]] );X
  2779. X    elseX
  2780. X        readMmem ( "memory" );X
  2781. X    if ( mema[2] ) {X
  2782. X        if ( mode == CREATE ) X
  2783. X            mode = CREATE_CORRECT;X
  2784. X        elseX
  2785. X            mode = CORRECT;X
  2786. X        openCorrect ( mode, argv[mema[2]] );X
  2787. X    }X
  2788. XX
  2789. X    if ( mode == CREATE )X
  2790. X        printf ( "Correction file must be specified for its' creation\n" );X
  2791. X    elseX
  2792. X        runMicro ( mode );X
  2793. XX
  2794. X    /* close the correctional file if it is opened */X
  2795. X    if ( mode == CORRECT || mode == CREATE_CORRECT ) X
  2796. X        closeCorrect ( );X
  2797. XX
  2798. X    /* return no error */X
  2799. X    return 0;X
  2800. X}X
  2801. XX
  2802. XX
  2803. X/****************************************************************************X
  2804. X *X
  2805. X * FUNCTION:        runMicro()X
  2806. X * PURPOSE:            start executing the microcode    X
  2807. X * ARGUMENTS:        mode - mode to start executing (ie NOTRACE, CORRECT, etc)X
  2808. X * RETURNS:            none    X
  2809. X * NOTES:            X
  2810. X *X
  2811. X ***************************************************************************/X
  2812. XX
  2813. XVOID    X
  2814. XrunMicro ( mode )X
  2815. X    int mode;    X
  2816. X{X
  2817. X    int mpcold;X
  2818. X    int loop = 1;X
  2819. X    int temp;X
  2820. XX
  2821. X    /* set the number of cycles and subcycles */X
  2822. X    cycles = 0;X
  2823. X    subcycles = 1;X
  2824. XX
  2825. X    /* set old value of the mpc to the current one for start */X
  2826. X    mpcold = mpc ( "query", 0 ) - 1;X
  2827. XX
  2828. X    /* Execute micro code while mpc is within the addr space */X
  2829. X    do {X
  2830. X        if ( ( mpcptr = mpc ( "query", 0 ) ) < var_param[CPUSIZE] ) {X
  2831. XX
  2832. X            /* if the engine did not change the mpc, we will */X
  2833. X            if ( mpcptr == mpcold )X
  2834. X                mpcold = mpcptr = mpc ( "set", mpcptr + 1 );X
  2835. XX
  2836. X            getCpuMem ( mpcptr );X
  2837. XX
  2838. X            /* increment number of cycles executed */X
  2839. X            cycles++;X
  2840. XX
  2841. X            /* check debug mode and break points */X
  2842. X            if ( mode != NOTRACE )X
  2843. X                loop = debug ( & mode, 0 );X
  2844. XX
  2845. X            /* call the engine for possible subcycle */X
  2846. X            while ( subcycles <= var_param[SUBNUM] ) {X
  2847. X                engine ( subcycles );X
  2848. X                subcycles++;X
  2849. X            }X
  2850. XX
  2851. X            /* call the engine for possible interrupts */X
  2852. X            for ( temp = 0; temp < var_param[INTNUM]; temp++ )X
  2853. X                if ( interrupt[temp].next == cycles  ) {X
  2854. X                    /* see if display message */X
  2855. X                    if ( mode != NOTRACE && mode != NOTRACE_REG &&X
  2856. X                      mode != NOTRACE_FREG && mode != CORRECT &&X
  2857. X                     mode != CREATE_CORRECT )X
  2858. X                        printf ( "Interrupt Vector #%d at cycle $%x\n", X
  2859. X                         temp, cycles );X
  2860. XX
  2861. X                    /* call engine with interrupt */X
  2862. X                    if ( engine ( var_param[SUBNUM] + temp + 1 ) )X
  2863. X                        /* if interrupt was done, set up next interrupt */X
  2864. X                        interrupt[temp].next = interrupt[temp].period +X
  2865. X                         cycles;X
  2866. X                    elseX
  2867. X                        interrupt[temp].next++;X
  2868. X                }X
  2869. XX
  2870. X            subcycles = 1;X
  2871. X        } else {X
  2872. X            if ( mode == NOTRACE || mode == NOTRACE_REG || mode == NOTRACE_FREGX
  2873. X             || mode == CORRECT || mode == CREATE_CORRECT )X
  2874. X                loop = 0;X
  2875. X            else X
  2876. X                loop = debug ( & mode, 1 );X
  2877. X        }X
  2878. X    } while ( loop );X
  2879. XX
  2880. X    printf ( "Micro code executed in %d cycles\n", cycles );X
  2881. X}X
  2882. XX
  2883. XX
  2884. XX
  2885. X/****************************************************************************X
  2886. X *X
  2887. X * FUNCTION:        initInterrupt()X
  2888. X * PURPOSE:            initialize the interrupts    X
  2889. X * ARGUMENTS:        noneX
  2890. X * RETURNS:            OK - done    X
  2891. X * NOTES:            X
  2892. X *X
  2893. X ***************************************************************************/X
  2894. XX
  2895. XintX
  2896. XinitInterrupt ( )X
  2897. X{X
  2898. X    int temp;X
  2899. XX
  2900. X    /* check if need the memory */X
  2901. X    if ( var_param[INTNUM] == 0 ) {X
  2902. X        interrupt = (struct interruptlist *) NULL;X
  2903. X        return OK;X
  2904. X    }X
  2905. XX
  2906. X    /* get the memory */X
  2907. X    if ( ( interrupt = (struct interruptlist *) malloc (X
  2908. X     sizeof ( struct interruptlist ) * var_param[INTNUM] ) ) == NULL ) {X
  2909. X        fprintf ( stderr, "Unable to allocate memory for the interrupt list\n" );X
  2910. X        exit ( 1 );X
  2911. X    }X
  2912. XX
  2913. X    /* clear out the memory */X
  2914. X    for ( temp = 0; temp < var_param[INTNUM]; temp++ )X
  2915. X        interrupt[temp].period = interrupt[temp].next = -1;X
  2916. XX
  2917. X    return OK;X
  2918. X}X
  2919. XX
  2920. XX
  2921. X/****************************************************************************X
  2922. X *X
  2923. X * FUNCTION:        usage()X
  2924. X * PURPOSE:            display a usage message to the user    X
  2925. X * ARGUMENTS:        name - name of programX
  2926. X * RETURNS:            none    X
  2927. X * NOTES:            routine called exit() when doneX
  2928. X *X
  2929. X ***************************************************************************/X
  2930. XX
  2931. X/* usage - display usage message */X
  2932. XVOIDX
  2933. Xusage ( name )X
  2934. X    char *name;            /* name of command program */X
  2935. X{X
  2936. X    printf ( "usage: %s [-cdfF] [+#:##] [cmemory] [memory] [correction file]\n",X
  2937. X     name );X
  2938. X    printf ( "    -creg,..  Create the correction file\n" );X
  2939. X    printf ( "    -d        Debug mode\n" );X
  2940. X    printf ( "    -f        Display registers before each fetch\n" );X
  2941. X    printf ( "    -F        Display registers before each cycle\n" );X
  2942. X    printf ( "    +#:##     Set interrupt # every ## fetches (in hex)\n" );X
  2943. X    exit ( 1 );X
  2944. X}X
  2945. XX
  2946. Zaphod for prez
  2947. cat << 'Zaphod for prez' | sed 's/X\(.*\)X/\1/' > main.h
  2948. XX
  2949. XX
  2950. X/* ----------------------------------------------------------------------- *\X
  2951. X ***************************************************************************X
  2952. XX
  2953. X  PROGRAM NAME: Computer Hardware Main module HeaderX
  2954. XX
  2955. X  PROGRAMMER:    Patrick Palmer                 DATE: 8/17/90 X
  2956. X          X
  2957. X  DESCRIPTION OF PROGRAM: X
  2958. X    This is the header file for the main micro code program.X
  2959. XX
  2960. X ***************************************************************************X
  2961. XX
  2962. X        This program is free software; you can redistribute it and/orX
  2963. X        modify it under the terms of the GNU General Public LicenseX
  2964. X        (version 2) as published by the Free Software Foundation.X
  2965. XX
  2966. X        This program is distributed in the hope that is will be useful,X
  2967. X        but WITHOUT ANY WARRANTY; without even the implied warrenty ofX
  2968. X        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See theX
  2969. X        GNU General Public License for more details.X
  2970. X        X
  2971. X        You should have received a copy of the GNU General Public X
  2972. X        License along with this program; if not, write to the FreeX
  2973. X        Software Foundation, Inc., 675 Mass Ave, Cambridge, MAX
  2974. X        02139, USA.X
  2975. XX
  2976. X        YAMPC Microcode Development KitX
  2977. X        (C) 1992 by Patrick PalmerX
  2978. XX
  2979. X ***************************************************************************X
  2980. XX
  2981. X  PROGRAM REVISION LOGX
  2982. X  X
  2983. X        DATE               DESCRIPTION OF CHANGE                PROGRAMMERX
  2984. X      --------  ----------------------------------------------  ----------X
  2985. X      08/17/90  YAMPC - Version 1.0                             PAPX
  2986. X      11/17/90  Interrupts, Bug Fixes - Version 1.1             PAPX
  2987. X      01/11/92  Distribution version - Version 1.2              PAPX
  2988. XX
  2989. X ***************************************************************************  X
  2990. X\* ----------------------------------------------------------------------- */X
  2991. XX
  2992. Xtypedef int VOID;X
  2993. XX
  2994. X/* union structure used for returning the actual value for debug parameters */X
  2995. Xtypedef union u_ret {X
  2996. X    int ival;                /* integer value */X
  2997. X    char * str;                /* string */ X
  2998. X} U_Ret;X
  2999. XX
  3000. X/* trace modes */X
  3001. X#define NOTRACE            0    /* no debugging at all */X
  3002. X#define NOTRACE_REG        1    /* display registers at every cycle but don't stop */X
  3003. X#define NOTRACE_FREG    2    /* display registers at every fetch but don't stop */X
  3004. X#define DEBUG            3    /* debugging mode */X
  3005. X#define DEBUG_REG        4    /* display registers at every debug prompt */X
  3006. X#define CORRECT            5    /* Correctional file is being used */X
  3007. X#define CREATE_CORRECT    6    /* Correctional file is being created */X
  3008. X#define CREATE            7    /* Create the correction file was specified */X
  3009. XX
  3010. X/* prototypes */X
  3011. XX
  3012. X#ifdef ANSI_CX
  3013. X#define PROTO(x)        xX
  3014. X#elseX
  3015. X#define PROTO(x)        ()X
  3016. X#endifX
  3017. XX
  3018. X/* FILE: brkpts.c */X
  3019. Xint        checkBrkPts PROTO (( void )),X
  3020. X        showBrkPts PROTO (( int )),X
  3021. X        addBrkPts PROTO (( int )),X
  3022. X        delBrkPts PROTO (( int ));X
  3023. XVOID    setBrkPts PROTO (( void ));X
  3024. XX
  3025. X/* FILE: correct.c */X
  3026. Xint        readCorrect PROTO (( int ));X
  3027. XVOID    openCorrect PROTO (( int, char * )),X
  3028. X        closeCorrect PROTO (( void )),X
  3029. X        checkCorrect PROTO (( void )),X
  3030. X        processCorrect PROTO (( char *, int )),X
  3031. X        addCorrect PROTO (( char * )),X
  3032. X        doCorrect PROTO (( void ));X
  3033. XX
  3034. X/* FILE: debug.c */X
  3035. Xint        debug PROTO (( int*, int )),X
  3036. X        getEntry PROTO (( U_Ret *, int )),X
  3037. X        prompt PROTO (( void )),X
  3038. X        exitProg PROTO (( int )),X
  3039. X        help PROTO (( int )),X
  3040. X        run PROTO (( int )),X
  3041. X        display PROTO (( int )),X
  3042. X        calculator PROTO (( int )),X
  3043. X        getOp PROTO (( int * )),X
  3044. X        setSome PROTO (( int )),X
  3045. X        D_interrupt PROTO (( int )),X
  3046. X        resetCPU PROTO (( int )),X
  3047. X        trace PROTO (( int ));X
  3048. XVOID    prtregs PROTO (( void )),X
  3049. X        prtCpuLine PROTO (( int, int )),X
  3050. X        misuse PROTO (( int ));X
  3051. X        X
  3052. X/* FILE: main.c */X
  3053. Xint        main PROTO (( int, char ** )),X
  3054. X        initInterrupt PROTO (( void ));X
  3055. XVOID    runMicro PROTO (( int )),X
  3056. X        usage PROTO (( char * ));X
  3057. XX
  3058. X/* FILE: memory.c */X
  3059. Xint        getWchar PROTO (( FILE * )),X
  3060. X        number PROTO (( int, int ));X
  3061. XVOID    allocCMem PROTO (( void )),X
  3062. X        allocMMem PROTO (( void )),X
  3063. X        allocVarParam PROTO (( int * )),X
  3064. X        readCmem PROTO (( char * )),X
  3065. X        readMmem PROTO (( char * )),X
  3066. X        getCpuMem PROTO (( int ));X
  3067. Xlong    getMMem PROTO (( int ));X
  3068. XX
  3069. X/* FILE: stack.c */X
  3070. XVOID    push PROTO (( int, long )),X
  3071. X        do_stack PROTO (( int ));X
  3072. Xlong    pop PROTO (( void )),X
  3073. X        s_math PROTO (( int, long, long ));X
  3074. XX
  3075. XX
  3076. Zaphod for prez
  3077. cat << 'Zaphod for prez' | sed 's/X\(.*\)X/\1/' > makefile
  3078. XX
  3079. X#       Yet Another Micro-Programming Compiler (yampc)X
  3080. X#       MakefileX
  3081. XX
  3082. X#X
  3083. X#       This program is free software; you can redistribute it and/orX
  3084. X#       modify it under the terms of the GNU General Public LicenseX
  3085. X#       (version 2) as published by the Free Software Foundation.X
  3086. X#X
  3087. X#       This program is distributed in the hope that is will be useful,X
  3088. X#       but WITHOUT ANY WARRANTY; without even the implied warrenty ofX
  3089. X#       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See theX
  3090. X#       GNU General Public License for more details.X
  3091. X#        X
  3092. X#       You should have received a copy of the GNU General Public X
  3093. X#       License along with this program; if not, write to the FreeX
  3094. X#       Software Foundation, Inc., 675 Mass Ave, Cambridge, MAX
  3095. X#       02139, USA.X
  3096. X#X
  3097. X#       YAMPC Microcode Development KitX
  3098. X#       (C) 1992 by Patrick PalmerX
  3099. X#X
  3100. XX
  3101. X# Compiler (ANSI compliant)X
  3102. X#CC = gccX
  3103. XCC = ccX
  3104. XX
  3105. X# ANSI Compliant CompilerX
  3106. X#CFLAGS = -DANSI_CX
  3107. XX
  3108. X# Compiler Options (-g : debug info)X
  3109. XCFLAGS = -gX
  3110. XX
  3111. X# Yet Another Compiler Compiler FlagsX
  3112. XYFLAGS = -dvX
  3113. XX
  3114. X# Linker commandsX
  3115. X# System V.3X
  3116. X#LD_CMDS = -Wl,-xX
  3117. XX
  3118. X# Library nameX
  3119. XLIB = libyampc.aX
  3120. XX
  3121. X# Archive name X
  3122. XARCHIVE = yampc.arX
  3123. XX
  3124. X# binary and library directories used by installX
  3125. XDESTBIN = /usr/local/binX
  3126. XDESTLIB = /usr/local/libX
  3127. XX
  3128. X# Create SystemX
  3129. Xsys:    yampc $(LIB)X
  3130. XX
  3131. X# Create the Yet Another Micro-Programming CompilerX
  3132. Xyampc:    lalr.o lex.o yampc.o y_misc.o misc.oX
  3133. X    $(CC) $(LD_CMDS) lex.o lalr.o yampc.o y_misc.o misc.o -lcX
  3134. X    mv a.out yampcX
  3135. X    size yampcX
  3136. XX
  3137. X# Create libraryX
  3138. X$(LIB):    $(LIB)(main.o) $(LIB)(stack.o) $(LIB)(memory.o) $(LIB)(brkpts.o) \X
  3139. X    $(LIB)(misc.o) $(LIB)(debug.o) $(LIB)(correct.o)X
  3140. XX
  3141. X# Create an archiveX
  3142. Xarchive:X
  3143. X    ar r $(ARCHIVE) yampc.doc yampc.1 yampc.l yampc.y MakefileX
  3144. X    ar r $(ARCHIVE) misc.c misc.h yampc.h yampc.c y_misc.cX
  3145. X    ar r $(ARCHIVE) stack.c memory.c main.c mode.h debug.cX
  3146. X    ar r $(ARCHIVE) correct.c brkpts.c debug.hX
  3147. X    ar r $(ARCHIVE) hfile cfile mfileX
  3148. XX
  3149. X# Clean up systemX
  3150. Xclean:X
  3151. X    rm yampc yampc.ar *.o y.tab.h y.outputX
  3152. XX
  3153. X# Install the system - need to have proper authorityX
  3154. Xinstall:X
  3155. X    mv yampc $(DESTBIN)X
  3156. X    mv libyampc.a $(DESTLIB)X
  3157. XX
  3158. X# DependanciesX
  3159. Xyampc.o:    yampc.c yampc.h misc.hX
  3160. Xlex.o:        lex.l lalr.y yampc.hX
  3161. Xlalr.o:        lalr.y yampc.hX
  3162. Xy_misc.o:    y_misc.c yampc.h misc.hX
  3163. XX
  3164. Xmisc.o:        misc.c misc.hX
  3165. XX
  3166. Xmain.o:        main.c main.h misc.hX
  3167. Xstack.o:    stack.c main.h y.tab.h misc.hX
  3168. Xmemory.o:    memory.c main.h misc.hX
  3169. Xdebug.o:    debug.c main.h misc.h debug.hX
  3170. Xcorrect.o:    correct.c main.h misc.hX
  3171. Xbrkpts.o:    brkpts.c main.h misc.hX
  3172. XX
  3173. Zaphod for prez
  3174. cat << 'Zaphod for prez' | sed 's/X\(.*\)X/\1/' > memory.c
  3175. XX
  3176. X/* ----------------------------------------------------------------------- *\X
  3177. X ***************************************************************************X
  3178. XX
  3179. X  PROGRAM NAME: Memory moduleX
  3180. XX
  3181. X  PROGRAMMER:    Patrick Palmer                 DATE: 8/17/90 X
  3182. X          X
  3183. X  DESCRIPTION OF PROGRAM: X
  3184. X    These routines deal with the allocation, reading and manipulationX
  3185. X  of the computer memory (microcode) and the program in memory.X
  3186. X X
  3187. X ***************************************************************************X
  3188. XX
  3189. X        This program is free software; you can redistribute it and/orX
  3190. X        modify it under the terms of the GNU General Public LicenseX
  3191. X        (version 2) as published by the Free Software Foundation.X
  3192. XX
  3193. X        This program is distributed in the hope that is will be useful,X
  3194. X        but WITHOUT ANY WARRANTY; without even the implied warrenty ofX
  3195. X        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See theX
  3196. X        GNU General Public License for more details.X
  3197. X        X
  3198. X        You should have received a copy of the GNU General Public X
  3199. X        License along with this program; if not, write to the FreeX
  3200. X        Software Foundation, Inc., 675 Mass Ave, Cambridge, MAX
  3201. X        02139, USA.X
  3202. XX
  3203. X        YAMPC Microcode Development KitX
  3204. X        (C) 1992 by Patrick PalmerX
  3205. XX
  3206. X ***************************************************************************X
  3207. XX
  3208. XX
  3209. X  PROGRAM REVISION LOGX
  3210. X  X
  3211. X        DATE               DESCRIPTION OF CHANGE                PROGRAMMERX
  3212. X      --------  ----------------------------------------------  ----------X
  3213. X      08/17/90  YAMPC - Version 1.0                             PAPX
  3214. X      11/17/90  Interrupts, Bug Fixes - Version 1.1             PAPX
  3215. X      01/11/92  Distribution version - Version 1.2              PAPX
  3216. XX
  3217. X ****************************************************************************  X
  3218. X\* ------------------------------------------------------------------------ */X
  3219. XX
  3220. XX
  3221. X#include <stdio.h>X
  3222. X#include "main.h"X
  3223. X#include "misc.h"X
  3224. XX
  3225. Xlong *cpu, *mem; X
  3226. Xextern int var_param[];X
  3227. Xextern struct varlist var[];X
  3228. XX
  3229. XX
  3230. XX
  3231. X/****************************************************************************X
  3232. X *X
  3233. X * FUNCTION:        allocCMem()X
  3234. X * PURPOSE:            allocate the memory for the micro code    X
  3235. X * ARGUMENTS:        noneX
  3236. X * RETURNS:            none    X
  3237. X * NOTES:            X
  3238. X *X
  3239. X ***************************************************************************/X
  3240. XX
  3241. XVOIDX
  3242. XallocCMem ( )X
  3243. X{X
  3244. X    if ( ( cpu = (long *) mallocX
  3245. X     ( var_param[CPUSIZE]*var_param[FORMATNUM]*sizeof(long) ) ) == NULL ) {X
  3246. X        fprintf ( stderr, "Unable to allocate the micro code memory\n" );X
  3247. X        exit ( 1 );X
  3248. X    }X
  3249. X}X
  3250. XX
  3251. XX
  3252. X/****************************************************************************X
  3253. X *X
  3254. X * FUNCTION:        allocMMem()X
  3255. X * PURPOSE:            allocate the main memory    X
  3256. X * ARGUMENTS:        noneX
  3257. X * RETURNS:            none    X
  3258. X * NOTES:            X
  3259. X *X
  3260. X ***************************************************************************/X
  3261. XX
  3262. XVOIDX
  3263. XallocMMem ( )X
  3264. X{X
  3265. X    if ( ( mem = (long *) X
  3266. X     malloc ( var_param[MAINSIZE]*sizeof(long) ) ) == NULL ) {X
  3267. X        fprintf ( stderr, "Unable to allocate the main memory\n" );X
  3268. X        exit ( 1 );X
  3269. X    }X
  3270. X}X
  3271. XX
  3272. XX
  3273. X/****************************************************************************X
  3274. X *X
  3275. X * FUNCTION:        allocVarParam()X
  3276. X * PURPOSE:            allocate the memory needed to store the parameter table    X
  3277. X * ARGUMENTS:        int * var_param - the variable to place the variable X
  3278. X *                    memory pointerX
  3279. X * RETURNS:            none    X
  3280. X * NOTES:            X
  3281. X *X
  3282. X ***************************************************************************/X
  3283. XX
  3284. XVOIDX
  3285. XallocVarParam ( var_param )X
  3286. X    int * var_param;X
  3287. X{X
  3288. X    if ( ( var_param = (int *) X
  3289. X     malloc ( NUM_PARAM * sizeof ( int ) ) ) == NULL ) {X
  3290. X        fprintf ( stderr, "Unable to allocate memory\n" );X
  3291. X        exit ( 1 );X
  3292. X    }X
  3293. X}X
  3294. XX
  3295. XX
  3296. XX
  3297. X/****************************************************************************X
  3298. X *X
  3299. X * FUNCTION:        getCpuMem()X
  3300. X * PURPOSE:            copy the current micro code entry into the current value    X
  3301. X * ARGUMENTS:        int entry - micro code entryX
  3302. X * RETURNS:            none    X
  3303. X * NOTES:            X
  3304. X *X
  3305. X ***************************************************************************/X
  3306. XX
  3307. XVOIDX
  3308. XgetCpuMem ( entry )X
  3309. X    int entry;X
  3310. X{X
  3311. X    int temp = 0;X
  3312. XX
  3313. X    /* copy the entry */X
  3314. X    while ( temp < var_param[FORMATNUM] ) {X
  3315. X        var[temp].val = cpu[entry*var_param[FORMATNUM]+temp];X
  3316. X        temp++;X
  3317. X    }X
  3318. X}X
  3319. XX
  3320. XX
  3321. XX
  3322. X/****************************************************************************X
  3323. X *X
  3324. X * FUNCTION:        getMMem()X
  3325. X * PURPOSE:            get main memory entry bit and with the memory mask    X
  3326. X * ARGUMENTS:        int entry - memory entryX
  3327. X * RETURNS:            memory entry or -1 if there isn't such an address    X
  3328. X * NOTES:            X
  3329. X *X
  3330. X ***************************************************************************/X
  3331. XX
  3332. XlongX
  3333. XgetMMem ( entry )X
  3334. X    int entry;X
  3335. X{X
  3336. X    if ( entry < var_param[CPUSIZE] )X
  3337. X        return mem[entry] & MEM_MASK;X
  3338. X    elseX
  3339. X        return -1L;X
  3340. X}X
  3341. XX
  3342. XX
  3343. X/****************************************************************************X
  3344. X *X
  3345. X * FUNCTION:        readCmem()X
  3346. X * PURPOSE:            read in the micro code source into memory    X
  3347. X * ARGUMENTS:        char * file - filenameX
  3348. X * RETURNS:            none    X
  3349. X * NOTES:            X
  3350. X *X
  3351. X ***************************************************************************/X
  3352. XX
  3353. XVOIDX
  3354. XreadCmem ( file )X
  3355. X    char *file;X
  3356. X{X
  3357. X    char buffer[80];X
  3358. X    int c, entry = 0;X
  3359. X    int p_entry = 0;X
  3360. X    int dataline = 0;X
  3361. X    int system, temp;X
  3362. X    FILE *fp, *fopen ( );X
  3363. XX
  3364. X    /* numbering system set to HEX */X
  3365. X    system = S_HEX;X
  3366. XX
  3367. X    /* open the file */X
  3368. X    if ( ( fp =fopen ( file, "r" ) ) == NULL ) {X
  3369. X        printf ( "Unable to open %s for reading\n", file );X
  3370. X        exit ( 1 );X
  3371. X    }X
  3372. XX
  3373. X    /* read in the information */X
  3374. X    c = getWchar ( fp );X
  3375. X    while ( c != EOF ) {X
  3376. X        if ( c == '.' ) {X
  3377. X            /* format command */X
  3378. X            fscanf ( fp, "%s", buffer );X
  3379. X            if ( !strcmp ( "octal", buffer )  ) X
  3380. X                system = S_OCT;X
  3381. X            else if ( !strcmp ( "decimal", buffer )  ) X
  3382. X                system = S_DEC;X
  3383. X            else if ( !strcmp ( "fetch", buffer ) ) {X
  3384. X                if ( fscanf ( fp, "%d", &temp ) == 0 ) X
  3385. X                    fprintf ( stderr, "Inproper fetch in micro code\n" );X
  3386. X                var_param[FETCH] = temp;X
  3387. X            } elseX
  3388. X                fprintf ( stderr, "Inproper command in micro code\n" );X
  3389. XX
  3390. X        } else if ( c == '\n' ) {X
  3391. X            /* new line */X
  3392. X            if ( dataline ) X
  3393. X                entry++;X
  3394. X            p_entry = 0;X
  3395. X            dataline = 0;X
  3396. XX
  3397. X        } else if ( number ( c, system ) == OK ) {X
  3398. X            ungetc ( c, fp );    /* put it back */X
  3399. X            dataline = 1;        /* data on this line */X
  3400. XX
  3401. X            /* scan in the number */X
  3402. X            fscanf ( fp, ( system == S_HEX ? "%x" :X
  3403. X                ( system == S_OCT ? "%o" : "%d" ) ), &temp );X
  3404. XX
  3405. X            /* check if placement into memory is valid */X
  3406. X            if ( entry >= var_param[CPUSIZE] ) {X
  3407. X                fprintf ( stderr, "Micro code program too Large (%d %d)\n",X
  3408. X                 entry, var_param[CPUSIZE] );X
  3409. X                fclose ( fp );X
  3410. X                exit ( 1 );X
  3411. X            }X
  3412. XX
  3413. X            /* see if there is an entry */X
  3414. X            if ( p_entry < var_param[FORMATNUM] ) {X
  3415. X                cpu[entry*var_param[FORMATNUM]+p_entry] = (long) temp;X
  3416. X            } else X
  3417. X                while ( ( c = getWchar ( fp ) ) != '\n' && c != EOF ) ;X
  3418. X            p_entry++;X
  3419. X        }X
  3420. XX
  3421. X        /* see if there is a comment */X
  3422. X        if ( c == ';' ) X
  3423. X            while ( ( c = getWchar ( fp ) ) != '\n' && c != EOF ) ;X
  3424. X        elseX
  3425. X            /* get another character */X
  3426. X            c = getWchar ( fp );X
  3427. X    }X
  3428. XX
  3429. X    /* close the file */X
  3430. X    fclose ( fp );X
  3431. XX
  3432. X}X
  3433. XX
  3434. XX
  3435. XX
  3436. X/****************************************************************************X
  3437. X *X
  3438. X * FUNCTION:        readMmem()X
  3439. X * PURPOSE:            read in the main memory program    X
  3440. X * ARGUMENTS:        char * file - filenameX
  3441. X * RETURNS:            none    X
  3442. X * NOTES:            X
  3443. X *X
  3444. X ***************************************************************************/X
  3445. XX
  3446. XVOIDX
  3447. XreadMmem ( file )X
  3448. X    char *file;X
  3449. X{X
  3450. X    int system;X
  3451. X    int mptr = 0;X
  3452. X    int c, temp;X
  3453. X    char buffer[80];X
  3454. X    FILE *fp, *fopen ( );X
  3455. XX
  3456. X    if ( ( fp = fopen ( file, "r" ) ) == NULL ) {X
  3457. X        printf ( "Unable to open %s for reading\n", file );X
  3458. X        exit ( 1 );X
  3459. X    }X
  3460. XX
  3461. X    /* numbering system set to HEX */X
  3462. X    system = S_HEX;X
  3463. XX
  3464. X    /* read in the information */X
  3465. X    c = getWchar ( fp );X
  3466. X    while ( c != EOF ) {X
  3467. X        if ( c == '.' ) {X
  3468. X            /* format command */X
  3469. X            fscanf ( fp, "%s", buffer );X
  3470. X            if ( !strcmp ( "octal", buffer )  ) X
  3471. X                system = S_OCT;X
  3472. X            else if ( !strcmp ( "decimal", buffer )  ) X
  3473. X                system = S_DEC;X
  3474. X            elseX
  3475. X                fprintf ( stderr, "Inproper command in micro code\n" );X
  3476. XX
  3477. X        } else if ( number ( c, system ) == OK ) {X
  3478. X            ungetc ( c, fp );    /* put it back */X
  3479. XX
  3480. X            /* scan in the number */X
  3481. X            fscanf ( fp, ( system == S_HEX ? "%x" :X
  3482. X                ( system == S_OCT ? "%o" : "%d" ) ), &temp );X
  3483. XX
  3484. X            if ( mptr < var_param[MAINSIZE] ) {X
  3485. X                mem[mptr++] = (long) temp & MEM_MASK;X
  3486. X            } else {X
  3487. X                fprintf ( stderr, "Program too big for main memory\n" );X
  3488. X                fclose ( fp );X
  3489. X                exit ( 1 );X
  3490. X            }X
  3491. XX
  3492. X        } else if ( c == ';' ) X
  3493. X            /* see if there is a comment */X
  3494. X            while ( ( c = getWchar ( fp ) ) != '\n' && c != EOF ) ;X
  3495. XX
  3496. X        /* get another character */X
  3497. X        c = getWchar ( fp );X
  3498. XX
  3499. X    }X
  3500. XX
  3501. X    /* close the file */X
  3502. X    fclose ( fp );X
  3503. XX
  3504. X}X
  3505. XX
  3506. XX
  3507. X/****************************************************************************X
  3508. X *X
  3509. X * FUNCTION:        getWchar()X
  3510. X * PURPOSE:            read in a character from a file and throw out whitespace    X
  3511. X * ARGUMENTS:        FILE * fp - file pointerX
  3512. X * RETURNS:            read in character    X
  3513. X * NOTES:            X
  3514. X *X
  3515. X ***************************************************************************/X
  3516. XX
  3517. XintX
  3518. XgetWchar ( fp )X
  3519. X    FILE * fp;X
  3520. X{X
  3521. X    int c;X
  3522. XX
  3523. X    /* get a character until it isn't a whitespace */X
  3524. X    while ( ( c = getc ( fp ) ) == ' ' || c == '\t' ) ;X
  3525. XX
  3526. X    return c;X
  3527. X}X
  3528. XX
  3529. XX
  3530. XX
  3531. X/****************************************************************************X
  3532. X *X
  3533. X * FUNCTION:        number()X
  3534. X * PURPOSE:            determine if a read in character is a valid number        X
  3535. X * ARGUMENTS:        int c - read in characterX
  3536. X *                    int system - number system (Octal, Decimal, Hex)X
  3537. X * RETURNS:            OK - number validX
  3538. X *                    BAD - number invalid    X
  3539. X * NOTES:            X
  3540. X *X
  3541. X ***************************************************************************/X
  3542. XX
  3543. XintX
  3544. Xnumber ( c, system )X
  3545. X    int c, system;X
  3546. X{X
  3547. X    int retval = BAD;X
  3548. XX
  3549. X    switch ( system ) {X
  3550. XX
  3551. X        case S_OCT:X
  3552. X            if ( c >= '0' && c <= '7' )X
  3553. X                retval = OK;X
  3554. X            break;X
  3555. XX
  3556. X        case S_DEC:X
  3557. X            if ( c >= '0' && c <= '9' )X
  3558. X                retval = OK;X
  3559. X            break;X
  3560. XX
  3561. X        case S_HEX:X
  3562. X            if ( ( c >= '0' && c <= '9' ) || ( c >= 'a' && c <= 'f' ) )X
  3563. X                retval = OK;X
  3564. X            break;X
  3565. X    }X
  3566. XX
  3567. X    return retval;X
  3568. X}X
  3569. XX
  3570. Zaphod for prez
  3571. cat << 'Zaphod for prez' | sed 's/X\(.*\)X/\1/' > misc.c
  3572. XX
  3573. XX
  3574. X/* ----------------------------------------------------------------------- *\X
  3575. X******************************************************************************X
  3576. XX
  3577. X  PROGRAM NAME: Miscellaneous routinesX
  3578. XX
  3579. X  PROGRAMMER:    Patrick Palmer                 DATE: 8/17/90 X
  3580. X          X
  3581. X  DESCRIPTION OF PROGRAM: X
  3582. X     This module contains miscellaneous routines that are used throughX
  3583. X  out the program.X
  3584. X X
  3585. X******************************************************************************X
  3586. XX
  3587. X        This program is free software; you can redistribute it and/orX
  3588. X        modify it under the terms of the GNU General Public LicenseX
  3589. X        (version 2) as published by the Free Software Foundation.X
  3590. XX
  3591. X        This program is distributed in the hope that is will be useful,X
  3592. X        but WITHOUT ANY WARRANTY; without even the implied warrenty ofX
  3593. X        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See theX
  3594. X        GNU General Public License for more details.X
  3595. X        X
  3596. X        You should have received a copy of the GNU General Public X
  3597. X        License along with this program; if not, write to the FreeX
  3598. X        Software Foundation, Inc., 675 Mass Ave, Cambridge, MAX
  3599. X        02139, USA.X
  3600. XX
  3601. X        YAMPC Microcode Development KitX
  3602. X        (C) 1992 by Patrick PalmerX
  3603. XX
  3604. X******************************************************************************X
  3605. XX
  3606. XX
  3607. X  PROGRAM REVISION LOGX
  3608. X  X
  3609. X        DATE               DESCRIPTION OF CHANGE                PROGRAMMERX
  3610. X      --------  ----------------------------------------------  ----------X
  3611. X      08/17/90  YAMPC - Version 1.0                             PAPX
  3612. X      11/17/90  Interrupts, Bug Fixes - Version 1.1             PAPX
  3613. X      01/11/92  Distribution version - Version 1.2              PAPX
  3614. XX
  3615. X***************************************************************************  X
  3616. X\* ------------------------------------------------------------------------ */X
  3617. XX
  3618. XX
  3619. X#include "misc.h"X
  3620. XX
  3621. X/* variable parameter data */X
  3622. Xextern int var_param[];X
  3623. XX
  3624. XX
  3625. XX
  3626. X/****************************************************************************X
  3627. X *X
  3628. X * FUNCTION:        findLongSize()X
  3629. X * PURPOSE:            determine the number of bits is in a type longX
  3630. X * ARGUMENTS:        noneX
  3631. X * RETURNS:            bit countX
  3632. X * NOTES:            though sizeof(long)*8 would work in most cases, this X
  3633. X *                    may be easier to portX
  3634. X *X
  3635. X ***************************************************************************/X
  3636. XX
  3637. XintX
  3638. XfindLongSize ( )X
  3639. X{X
  3640. X    long val = 1L;X
  3641. X    int count = 1;X
  3642. XX
  3643. X    /* the loop */X
  3644. X    while ( ( val <<= 1 ) != 0 )X
  3645. X        count++;X
  3646. XX
  3647. X    /* return the number of bits that a long is */X
  3648. X    return count;X
  3649. X}X
  3650. XX
  3651. XX
  3652. X/****************************************************************************X
  3653. X *X
  3654. X * FUNCTION:        createMask()X
  3655. X * PURPOSE:            given the length in bits, this routine creates a maskX
  3656. X * ARGUMENTS:        lengthX
  3657. X * RETURNS:            mask    X
  3658. X * NOTES:            X
  3659. X *X
  3660. X ***************************************************************************/X
  3661. XX
  3662. XlongX
  3663. XcreateMask ( val )X
  3664. X    long val;X
  3665. X{X
  3666. X    int i; X
  3667. X    long p = 1L;X
  3668. XX
  3669. X    /* figure out 2 to the power of 'val' */X
  3670. X    for ( i = 1; i <= val; ++i )X
  3671. X        p *= 2;X
  3672. XX
  3673. X    /* create the mask, given 2 to the power of 'val' minus one */X
  3674. X    p -= 1;X
  3675. XX
  3676. X    return p;X
  3677. X}X
  3678. XX
  3679. XX
  3680. X/****************************************************************************X
  3681. X *X
  3682. X * FUNCTION:        version()X
  3683. X * PURPOSE:            display the current version of the software    X
  3684. X * ARGUMENTS:        noneX
  3685. X * RETURNS:            P_CONT - continue with operation    X
  3686. X * NOTES:            X
  3687. X *X
  3688. X ***************************************************************************/X
  3689. XX
  3690. XintX
  3691. Xversion ( )X
  3692. X{X
  3693. X    printf ( "YAMPC - Yet Another Micro Program Compiler\n" );X
  3694. X    printf ( "By Patrick Palmer\n" );X
  3695. X    printf ( "Version %s, %s\n\n", VERSION, V_DATE );X
  3696. XX
  3697. X    return P_CONT;X
  3698. X}X
  3699. XX
  3700. XX
  3701. XX
  3702. X/****************************************************************************X
  3703. X *X
  3704. X * FUNCTION:        mpc()X
  3705. X * PURPOSE:            set and query the mpc value    X
  3706. X * ARGUMENTS:        cmd - set/query commandX
  3707. X *                    val - value to set mpc toX
  3708. X * RETURNS:            the value of the mpcX
  3709. X * NOTES:            X
  3710. X *X
  3711. X ***************************************************************************/X
  3712. XX
  3713. XintX
  3714. Xmpc ( cmd, val )X
  3715. X    char *cmd;        /* "query", "set" */X
  3716. X    int val;X
  3717. X{X
  3718. X    static int mpcval = 0;X
  3719. XX
  3720. X    /* query command */X
  3721. X    if ( !strcmp ( cmd, "query" ) )X
  3722. X        return mpcval;X
  3723. XX
  3724. X    /* set command */X
  3725. X    if ( !strcmp ( cmd, "set" ) )X
  3726. X        return ( mpcval = val );X
  3727. XX
  3728. X    /* bad command */X
  3729. X    return -1;X
  3730. X}X
  3731. XX
  3732. Zaphod for prez
  3733. cat << 'Zaphod for prez' | sed 's/X\(.*\)X/\1/' > misc.h
  3734. XX
  3735. XX
  3736. X/* ----------------------------------------------------------------------- *\X
  3737. X ***************************************************************************X
  3738. XX
  3739. X  PROGRAM NAME: Common header.X
  3740. XX
  3741. X  PROGRAMMER:    Patrick Palmer                 DATE: 8/17/90 X
  3742. X          X
  3743. X  DESCRIPTION OF PROGRAM: X
  3744. X    This is a common header file for both YAMPC and the library.X
  3745. X X
  3746. X ***************************************************************************X
  3747. XX
  3748. X        This program is free software; you can redistribute it and/orX
  3749. X        modify it under the terms of the GNU General Public LicenseX
  3750. X        (version 2) as published by the Free Software Foundation.X
  3751. XX
  3752. X        This program is distributed in the hope that is will be useful,X
  3753. X        but WITHOUT ANY WARRANTY; without even the implied warrenty ofX
  3754. X        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See theX
  3755. X        GNU General Public License for more details.X
  3756. X        X
  3757. X        You should have received a copy of the GNU General Public X
  3758. X        License along with this program; if not, write to the FreeX
  3759. X        Software Foundation, Inc., 675 Mass Ave, Cambridge, MAX
  3760. X        02139, USA.X
  3761. XX
  3762. X        YAMPC Microcode Development KitX
  3763. X        (C) 1992 by Patrick PalmerX
  3764. XX
  3765. X ***************************************************************************X
  3766. XX
  3767. XX
  3768. X  PROGRAM REVISION LOGX
  3769. X  X
  3770. X        DATE               DESCRIPTION OF CHANGE                PROGRAMMERX
  3771. X      --------  ----------------------------------------------  ----------X
  3772. X      08/17/90  YAMPC - Version 1.0                             PAPX
  3773. X      11/17/90  Interrupts, Bug Fixes - Version 1.1             PAPX
  3774. X      01/11/92  Distribution version - Version 1.2              PAPX
  3775. XX
  3776. X ***************************************************************************  X
  3777. X\* ----------------------------------------------------------------------- */X
  3778. XX
  3779. X/* variable list definition structure */X
  3780. Xstruct varlist {X
  3781. X    char name[80];X
  3782. X    long bmask;X
  3783. X    int  type;X
  3784. X    long val;X
  3785. X};X
  3786. XX
  3787. X/* Interrupt structure */X
  3788. Xstruct interruptlist {X
  3789. X    int period;                            /* interrupt every period */X
  3790. X    int next;                            /* interrupt when cycles hits next */X
  3791. X};X
  3792. XX
  3793. X/* version of this software (string format) */X
  3794. X#define VERSION        "1.2"                /* Version number */X
  3795. X#define V_DATE        "January 17, 1992"    /* Version last updated */X
  3796. XX
  3797. X/* return values */X
  3798. X#define OK        0X
  3799. X#define BAD        1X
  3800. XX
  3801. X/* numbering systems for inputing files */X
  3802. X#define S_HEX    0X
  3803. X#define S_OCT    1X
  3804. X#define S_DEC    2X
  3805. XX
  3806. X/* Number of breakpoints defined */X
  3807. X#define NUMBRKPTS        10X
  3808. XX
  3809. X/* the global variables in an array */X
  3810. X#define NUM_PARAM    9X
  3811. XX
  3812. X#define FORMATNUM    0    /* number of format entries */X
  3813. X#define PARTSNUM    1    /* number of parts */X
  3814. X#define    VARSNUM        2    /* number of local variables */X
  3815. X#define CPUSIZE        3    /* cpu internal memory size */X
  3816. X#define MAINSIZE    4    /* main memory size */X
  3817. X#define MAINBSIZE    5    /* main memory bit size */X
  3818. X#define    SUBNUM        6    /* number of subcycles */X
  3819. X#define FETCH        7    /* mpc - start of fetch cycle */X
  3820. X#define INTNUM        8    /* number of interrupts */X
  3821. XX
  3822. X/* Main Memory mask used for killing off unwanted bits */X
  3823. X#define MEM_MASK    createMask ( var_param[ 5 /* <= # is MAINBSIZE defined above */ ] )X
  3824. XX
  3825. X/* Types of messages for the parameters at the debug prompt */X
  3826. X#define D_NUM        1    /* Number */X
  3827. X#define D_STR        2    /* string */X
  3828. X#define D_NOMORE    3    /* no more options */X
  3829. XX
  3830. X/* defines for debug prompt routines return codes */X
  3831. X#define P_LEAVE            0    /* leave the program */X
  3832. X#define P_CONT            1    /* continue in debug mode after next cmd */X
  3833. X#define P_GOON            2    /* return and do more work */X
  3834. XX
  3835. X/* defines for type needed from input string */X
  3836. X#define P_NUM        0    /* integer number */X
  3837. X#define P_STR        1    /* string input */X
  3838. XX
  3839. X/* prototypes */X
  3840. XX
  3841. X#ifdef ANSI_CX
  3842. X#define PROTO(x)        xX
  3843. X#elseX
  3844. X#define PROTO(x)        ()X
  3845. X#endifX
  3846. XX
  3847. X/* FILE: misc.c */X
  3848. Xint        findLongSize PROTO (( void )),X
  3849. X        version PROTO (( void )),X
  3850. X        mpc PROTO (( char *, int ));X
  3851. Xlong    createMask PROTO (( long ));X
  3852. XX
  3853. XX
  3854. Zaphod for prez
  3855. cat << 'Zaphod for prez' | sed 's/X\(.*\)X/\1/' > stack.c
  3856. XX
  3857. X/* ----------------------------------------------------------------------- *\X
  3858. X******************************************************************************X
  3859. XX
  3860. X  PROGRAM NAME: Stack moduleX
  3861. XX
  3862. X  PROGRAMMER:    Patrick Palmer                 DATE: 8/17/90 X
  3863. X          X
  3864. X  DESCRIPTION OF PROGRAM: X
  3865. X     This module deals with all access to the stack including theX
  3866. X  manipulation of variables in expressions.  The computer hardware memoryX
  3867. X  program access these routines HEAVILY!X
  3868. X X
  3869. X******************************************************************************X
  3870. XX
  3871. X        This program is free software; you can redistribute it and/orX
  3872. X        modify it under the terms of the GNU General Public LicenseX
  3873. X        (version 2) as published by the Free Software Foundation.X
  3874. XX
  3875. X        This program is distributed in the hope that is will be useful,X
  3876. X        but WITHOUT ANY WARRANTY; without even the implied warrenty ofX
  3877. X        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See theX
  3878. X        GNU General Public License for more details.X
  3879. X        X
  3880. X        You should have received a copy of the GNU General Public X
  3881. X        License along with this program; if not, write to the FreeX
  3882. X        Software Foundation, Inc., 675 Mass Ave, Cambridge, MAX
  3883. X        02139, USA.X
  3884. XX
  3885. X        YAMPC Microcode Development KitX
  3886. X        (C) 1992 by Patrick PalmerX
  3887. XX
  3888. X******************************************************************************X
  3889. XX
  3890. XX
  3891. X  PROGRAM REVISION LOGX
  3892. X  X
  3893. X        DATE               DESCRIPTION OF CHANGE                PROGRAMMERX
  3894. X      --------  ----------------------------------------------  ----------X
  3895. X      08/17/90  YAMPC - Version 1.0                             PAPX
  3896. X      11/17/90  Interrupts, Bug Fixes - Version 1.1             PAPX
  3897. X      01/11/92  Distribution version - Version 1.2              PAPX
  3898. XX
  3899. X***************************************************************************  X
  3900. X\* ------------------------------------------------------------------------ */X
  3901. XX
  3902. XX
  3903. X#include <stdio.h>X
  3904. X#include "main.h"X
  3905. X#include "misc.h"X
  3906. X#include "y.tab.h"X
  3907. XX
  3908. X#ifndef FALSEX
  3909. X#define FALSE    0X
  3910. X#define TRUE    ( ! FALSE )X
  3911. X#endifX
  3912. XX
  3913. X/* the variable list created by yampc */X
  3914. Xextern struct varlist var[];X
  3915. XX
  3916. Xextern int var_param[];X
  3917. Xextern int subcycles;X
  3918. Xextern int mpcptr;X
  3919. Xextern long *mem;X
  3920. XX
  3921. X/* the stack */X
  3922. Xstatic struct s_stack {X
  3923. X    int type;            /* value type on the stack */X
  3924. X    long val;            /* value of the type if not a ptr */X
  3925. X} stack[40];            /* 40 elements */X
  3926. X    X
  3927. X/* stack pointer */X
  3928. Xstatic int sptr = 0;X
  3929. XX
  3930. X/* masks needed for masking out unwanted bits */X
  3931. X#define BIGGER_MASK    ( var[ptr2->val].bmask >= var[ptr1->val].bmask ) \X
  3932. X    ? var[ptr2->val].bmask : var[ptr1->val].bmaskX
  3933. X#define LESSER_MASK    ( var[ptr2->val].bmask > var[ptr1->val].bmask ? \X
  3934. X    var[ptr1->val].bmask : var[ptr2->val].bmask )X
  3935. XX
  3936. XX
  3937. X/****************************************************************************X
  3938. X *X
  3939. X * FUNCTION:        push()X
  3940. X * PURPOSE:            push a value onto the stack    X
  3941. X * ARGUMENTS:        type - location type of valueX
  3942. X *                    value - value to place onto the stackX
  3943. X * RETURNS:            none    X
  3944. X * NOTES:            X
  3945. X *X
  3946. X ***************************************************************************/X
  3947. XX
  3948. XVOIDX
  3949. Xpush ( type, val )X
  3950. X    int type;X
  3951. X    long val;X
  3952. X{X
  3953. X    switch ( type ) {X
  3954. X        case NUM:X
  3955. X        case VAR:X
  3956. X            stack[sptr].type = type;X
  3957. X            stack[sptr++].val = val;X
  3958. X            break;X
  3959. XX
  3960. X        case MEM:X
  3961. X            stack[sptr].type = MEM;X
  3962. X            stack[sptr++].val = val & MEM_MASK;X
  3963. X            break;X
  3964. XX
  3965. X        case SUB:X
  3966. X            push ( NUM, subcycles );X
  3967. X            break;X
  3968. XX
  3969. X        default:X
  3970. X            fprintf ( stderr, "push: unknown operation (%d)\n", type );X
  3971. X    }X
  3972. X}X
  3973. XX
  3974. XX
  3975. X/****************************************************************************X
  3976. X *X
  3977. X * FUNCTION:        pop()X
  3978. X * PURPOSE:            remove the top elemnt off the stack    X
  3979. X * ARGUMENTS:        noneX
  3980. X * RETURNS:            value that was removed    X
  3981. X * NOTES:            if there is nothing on the stack, return zeroX
  3982. X *X
  3983. X ***************************************************************************/X
  3984. XX
  3985. XlongX
  3986. Xpop ( ) X
  3987. X{X
  3988. X    if ( sptr ) {X
  3989. X        if ( stack[--sptr].type == VAR ) X
  3990. X            return ( var[stack[sptr].val].val );X
  3991. X        else if ( stack[sptr].type == MEM )X
  3992. X            return ( (long) mem[stack[sptr].val] );X
  3993. X        elseX
  3994. X            return stack[sptr].val;X
  3995. X    } elseX
  3996. X        return 0L;X
  3997. X}X
  3998. XX
  3999. XX
  4000. X/****************************************************************************X
  4001. X *X
  4002. X * FUNCTION:        do_stack()X
  4003. X * PURPOSE:            do a stack operationX
  4004. X * ARGUMENTS:        oper - operation to perform onto the stackX
  4005. X * RETURNS:            none    X
  4006. X * NOTES:            X
  4007. X *X
  4008. X ***************************************************************************/X
  4009. XX
  4010. XVOIDX
  4011. Xdo_stack ( oper )X
  4012. X    int oper;X
  4013. X{X
  4014. X    struct s_stack *ptr1, *ptr2;X
  4015. X    long val1, val2;X
  4016. X    long sendmask;X
  4017. XX
  4018. X    ptr1 = &stack[sptr-1];X
  4019. X    ptr2 = &stack[sptr-2];X
  4020. XX
  4021. X    /* pop the used stuff */X
  4022. X    if ( oper != BNOT && oper != NOT )X
  4023. X        pop ( );X
  4024. X    pop ( );X
  4025. X    X
  4026. X    val1 = ( ptr1->type == VAR ) ? var[ptr1->val].val & X
  4027. X     var[ptr1->val].bmask : ( ptr1->type == NUM ) ? ptr1->val : mem[ptr1->val];X
  4028. X    val2 = ( ptr2->type == VAR ) ? var[ptr2->val].val & X
  4029. X     var[ptr2->val].bmask : ( ptr2->type == NUM ) ? ptr2->val : mem[ptr2->val];X
  4030. XX
  4031. X    switch ( oper ) {X
  4032. XX
  4033. X        case (int) '=':X
  4034. X            if ( ptr2->type == VAR ) {X
  4035. X                var[ptr2->val].val = val1 & var[ptr2->val].bmask;X
  4036. XX
  4037. X                /* check if variable is linked */X
  4038. X                if ( var[ptr2->val].type == 1 ) {X
  4039. X                    mpc ( "set", var[ptr2->val].val );X
  4040. X                    mpcptr = var[ptr2->val].val;X
  4041. X                }X
  4042. XX
  4043. X            } else if ( ptr2->type == MEM )X
  4044. X                mem[ptr2->val] = val1 & MEM_MASK;X
  4045. X            push ( NUM, val1 );X
  4046. X            break;X
  4047. XX
  4048. X        case AND:X
  4049. X            if ( val1 > 0 ) val1 = TRUE;X
  4050. X            if ( val2 > 0 ) val2 = TRUE;X
  4051. X            /* Note: no break */X
  4052. X        case BAND:X
  4053. X            push ( NUM, val1 & val2 ); X
  4054. X            break;X
  4055. XX
  4056. X        case OR:X
  4057. X            if ( val1 > 0 ) val1 = TRUE;X
  4058. X            if ( val2 > 0 ) val2 = TRUE;X
  4059. X        case BOR:  X
  4060. X            push ( NUM, val1 | val2 ); X
  4061. X            break;X
  4062. XX
  4063. X        case EOR:X
  4064. X            push ( NUM, val1 ^ val2 );X
  4065. X            break;X
  4066. X        X
  4067. X        case NOT:X
  4068. X            if ( val1 > 0 ) val1 = FALSE;X
  4069. X            else val1 = TRUE;X
  4070. X            push ( NUM, val1 );X
  4071. X            break;X
  4072. XX
  4073. X        case BNOT:X
  4074. X            push ( NUM, ~ val1 );X
  4075. X            break;X
  4076. XX
  4077. X        case SR:X
  4078. X        case SL:X
  4079. X        case (int) '+':X
  4080. X        case (int) '-':X
  4081. X        case (int) '/':X
  4082. X        case (int) '%':X
  4083. X        case (int) '*':X
  4084. X            push ( NUM, s_math ( oper, val1, val2 ) ); X
  4085. X            break;X
  4086. XX
  4087. X        case EQ:X
  4088. X            push ( NUM, ( val1 == val2 ) ? TRUE : FALSE ); X
  4089. X            break;X
  4090. XX
  4091. X        case NE:X
  4092. X            push ( NUM, ( val1 != val2 ) ? TRUE : FALSE ); X
  4093. X            break;X
  4094. XX
  4095. X        case GT:X
  4096. X            push ( NUM, ( val1 < val2 ) ? TRUE : FALSE ); X
  4097. X            break;X
  4098. XX
  4099. X        case GE:X
  4100. X            push ( NUM, ( val1 <= val2 ) ? TRUE : FALSE ); X
  4101. X            break;X
  4102. XX
  4103. X        case LT:X
  4104. X            push ( NUM, ( val1 > val2 ) ? TRUE : FALSE ); X
  4105. X            break;X
  4106. XX
  4107. X        case LE:X
  4108. X            push ( NUM, ( val1 >= val2 ) ? TRUE : FALSE ); X
  4109. X            break;X
  4110. XX
  4111. X        default:X
  4112. X            fprintf ( stderr, "Invalid stack operation\n" );X
  4113. X    }X
  4114. X}X
  4115. XX
  4116. XX
  4117. X/****************************************************************************X
  4118. X *X
  4119. X * FUNCTION:        s_math()X
  4120. X * PURPOSE:            perform a variety of operations    X
  4121. X * ARGUMENTS:        oper - operation to performX
  4122. X *                    val1, val2 - variables to perform operationX
  4123. X * RETURNS:            completed operation value    X
  4124. X * NOTES:            noneX
  4125. X *X
  4126. X ***************************************************************************/X
  4127. XX
  4128. XlongX
  4129. Xs_math ( oper, val1, val2 )X
  4130. X    int oper;X
  4131. X    long val1, val2;X
  4132. X{X
  4133. X    X
  4134. X    /* for each entry, do the correct operation */X
  4135. X    switch ( oper ) {X
  4136. X        case SR:        /* Shift Right */X
  4137. X            return val2 >> val1;X
  4138. XX
  4139. X        case SL:        /* Shift Left */X
  4140. X            return val2 << val1;X
  4141. XX
  4142. X        case (int) '+':        /* Addition */X
  4143. X            return val2 + val1;X
  4144. XX
  4145. X        case (int) '/':        /* Division */X
  4146. X            return val2 / val1;X
  4147. XX
  4148. X        case (int) '%':        /* Modulo */X
  4149. X            return val2 % val1;X
  4150. XX
  4151. X        case (int) '-':        /* Subtraction */X
  4152. X            return val2 - val1;X
  4153. XX
  4154. X        case (int) '*':        /* Multiplication */X
  4155. X            return val2 * val1;X
  4156. XX
  4157. X        default:        /* Fall through */X
  4158. X            return FALSE;X
  4159. X    }X
  4160. XX
  4161. X}X
  4162. XX
  4163. XX
  4164. Zaphod for prez
  4165. cat << 'Zaphod for prez' | sed 's/X\(.*\)X/\1/' > y_misc.c
  4166. XX
  4167. X/* ----------------------------------------------------------------------- *\X
  4168. X ***************************************************************************X
  4169. XX
  4170. X  PROGRAM NAME: Computer Hardware Compilation RoutinesX
  4171. XX
  4172. X  PROGRAMMER:    Patrick Palmer                 DATE: 8/17/90 X
  4173. X          X
  4174. X  DESCRIPTION OF PROGRAM: X
  4175. X     These are miscellaneous routines used when compiling the computerX
  4176. X  hardware description file.X
  4177. X X
  4178. X ***************************************************************************X
  4179. XX
  4180. X        This program is free software; you can redistribute it and/orX
  4181. X        modify it under the terms of the GNU General Public LicenseX
  4182. X        (version 2) as published by the Free Software Foundation.X
  4183. XX
  4184. X        This program is distributed in the hope that is will be useful,X
  4185. X        but WITHOUT ANY WARRANTY; without even the implied warrenty ofX
  4186. X        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See theX
  4187. X        GNU General Public License for more details.X
  4188. X        X
  4189. X        You should have received a copy of the GNU General Public X
  4190. X        License along with this program; if not, write to the FreeX
  4191. X        Software Foundation, Inc., 675 Mass Ave, Cambridge, MAX
  4192. X        02139, USA.X
  4193. XX
  4194. X        YAMPC Microcode Development KitX
  4195. X        (C) 1992 by Patrick PalmerX
  4196. XX
  4197. X ***************************************************************************X
  4198. XX
  4199. XX
  4200. X  PROGRAM REVISION LOGX
  4201. X  X
  4202. X        DATE               DESCRIPTION OF CHANGE                PROGRAMMERX
  4203. X      --------  ----------------------------------------------  ----------X
  4204. X      08/17/90  YAMPC - Version 1.0                             PAPX
  4205. X      11/17/90  Interrupts, Bug Fixes - Version 1.1             PAPX
  4206. X      01/11/92  Distribution version - Version 1.2              PAPX
  4207. XX
  4208. X ***************************************************************************  X
  4209. X\* ----------------------------------------------------------------------- */X
  4210. XX
  4211. XX
  4212. X#include <stdio.h>X
  4213. X#include <time.h>X
  4214. X#include "yampc.h"X
  4215. X#include "misc.h"X
  4216. XX
  4217. Xextern FILE *fph;                    /* file pointer */X
  4218. Xextern int var_param[];                /* variable parameters */X
  4219. Xextern struct s_var *localvar;        /* variable list */X
  4220. XX
  4221. XX
  4222. X/****************************************************************************X
  4223. X *X
  4224. X * FUNCTION:        start_hw()X
  4225. X * PURPOSE:            the first data placed into the compiled hardware fileX
  4226. X * ARGUMENTS:        filexe - name of the YAMPC executable on cmd lineX
  4227. X * RETURNS:            nothing    X
  4228. X * NOTES:            X
  4229. X *X
  4230. X ***************************************************************************/X
  4231. XX
  4232. XVOIDX
  4233. Xstart_hw ( filexe )X
  4234. X    char *filexe;X
  4235. X{X
  4236. X    long currtime, time ( );        /* current time */X
  4237. X    char *cptr, *ctime ( );X
  4238. XX
  4239. X    /* get the title info */X
  4240. X    currtime = time ( 0L );X
  4241. X    cptr = ctime ( &currtime );X
  4242. X    cptr[strlen ( cptr )-1] = '\0';X
  4243. XX
  4244. X    /* print the title info */X
  4245. X    fprintf ( fph, "\n/* Created on %s by %s, version %s */\n\n", cptr,X
  4246. X        filexe, VERSION );X
  4247. XX
  4248. X    /* the necessary defines */X
  4249. X    fprintf ( fph, "#define OK    0\n" );X
  4250. X    fprintf ( fph, "#define BAD    1\n\n" );X
  4251. XX
  4252. X    /* function declarations */X
  4253. X    fprintf ( fph, "void push ( ), do_stack ( );\n" );X
  4254. X    fprintf ( fph, "long pop ( );\n\n" );X
  4255. XX
  4256. X    /* set the current number of subcyles to 4 */X
  4257. X    var_param[SUBNUM] = 4;X
  4258. XX
  4259. X    /* set the current mpc fetch */X
  4260. X    var_param[FETCH] = 8;X
  4261. X}X
  4262. XX
  4263. XX
  4264. X/****************************************************************************X
  4265. X *X
  4266. X * FUNCTION:        end_struct()X
  4267. X * PURPOSE:            end a structure in the compiled hardware fileX
  4268. X * ARGUMENTS:        noneX
  4269. X * RETURNS:            none    X
  4270. X * NOTES:            X
  4271. X *X
  4272. X ***************************************************************************/X
  4273. XX
  4274. XVOIDX
  4275. Xend_struct ( )X
  4276. X{X
  4277. X    fprintf ( fph, "\n};\n\n" );X
  4278. X}X
  4279. XX
  4280. X/****************************************************************************X
  4281. X *X
  4282. X * FUNCTION:        end_func()X
  4283. X * PURPOSE:            end a routine in the compiled hardware fileX
  4284. X * ARGUMENTS:        noneX
  4285. X * RETURNS:            none    X
  4286. X * NOTES:            X
  4287. X *X
  4288. X ***************************************************************************/X
  4289. XX
  4290. XVOIDX
  4291. Xend_func ( )X
  4292. X{X
  4293. X    fprintf ( fph, "    return OK;\n}\n\n" );X
  4294. X}X
  4295. XX
  4296. XX
  4297. XX
  4298. X/****************************************************************************X
  4299. X *X
  4300. X * FUNCTION:        put_msg()X
  4301. X * PURPOSE:            place a message into the compiled hardware file    X
  4302. X * ARGUMENTS:        msg - message to place into fileX
  4303. X * RETURNS:            none    X
  4304. X * NOTES:            X
  4305. X *X
  4306. X ***************************************************************************/X
  4307. XX
  4308. XVOIDX
  4309. Xput_msg ( msg )X
  4310. X    char *msg;            /* msg to place into hw.c */X
  4311. X{X
  4312. X    fprintf ( fph, "%s\n", msg );X
  4313. X}X
  4314. XX
  4315. XX
  4316. X/****************************************************************************X
  4317. X *X
  4318. X * FUNCTION:        init_var()X
  4319. X * PURPOSE:            set up the variable list in the compiled hardware file    X
  4320. X * ARGUMENTS:        noneX
  4321. X * RETURNS:            noneX
  4322. X * NOTES:            X
  4323. X *X
  4324. X ***************************************************************************/X
  4325. XX
  4326. XVOIDX
  4327. Xinit_var ( )X
  4328. X{X
  4329. X    var_param[FORMATNUM] = 0;X
  4330. X    var_param[PARTSNUM] = 0;X
  4331. X    var_param[VARSNUM] = 0;X
  4332. X    fprintf ( fph, "struct varlist {\n" );X
  4333. X    fprintf ( fph, "    char name[80];\n" );X
  4334. X    fprintf ( fph, "    long bmask;\n" );X
  4335. X    fprintf ( fph, "    int type;\n" );X
  4336. X    fprintf ( fph, "    long val;\n" );X
  4337. X    fprintf ( fph, "} var[] = {\n" );X
  4338. X}X
  4339. XX
  4340. XX
  4341. XX
  4342. X/****************************************************************************X
  4343. X *X
  4344. X * FUNCTION:        add_var()X
  4345. X * PURPOSE:            add a variable to the variable listX
  4346. X * ARGUMENTS:        s - variable nameX
  4347. X *                    len - check bit lengthX
  4348. X *                    value - start valueX
  4349. X *                    type - TRUE/FALSE on whether it is a mpc pointer variableX
  4350. X * RETURNS:            noneX
  4351. X * NOTES:            X
  4352. X *X
  4353. X ***************************************************************************/X
  4354. XX
  4355. XVOIDX
  4356. Xadd_var ( s, len, value, type )X
  4357. X    char *s;X
  4358. X    int len;X
  4359. X    int value;X
  4360. X    int type;X
  4361. X{X
  4362. X    static int count = 0;X
  4363. X    long createMask ( );                /* create a bit mask */X
  4364. XX
  4365. X    /* add the variable to the list if not defined */X
  4366. X    if ( addLocalVar ( s, var_param[FORMATNUM] + var_param[PARTSNUM] + X
  4367. X     var_param[VARSNUM] ) == BAD )X
  4368. X        return;X
  4369. XX
  4370. X    /* check the bit length, can't be greater than sizeof (long) */X
  4371. X    if ( len > findLongSize ( ) ) {X
  4372. X        char temp[50];X
  4373. X        sprintf ( temp, "Size of variables can't be larger than %d", X
  4374. X         ( len = findLongSize( ) ) );X
  4375. X        warning ( temp, (char *) 0 );X
  4376. X    }X
  4377. XX
  4378. X    var_param[value]++;X
  4379. X    if ( count ) X
  4380. X        fprintf ( fph, ",\n" );X
  4381. X    elseX
  4382. X        count++;X
  4383. XX
  4384. X    fprintf ( fph, "    \"%s\", %dL, %d, 0L", s, createMask ( len ),X
  4385. X     type );X
  4386. X}X
  4387. XX
  4388. XX
  4389. X/****************************************************************************X
  4390. X *X
  4391. X * FUNCTION:        start_init()X
  4392. X * PURPOSE:            start compiling the initialization routineX
  4393. X * ARGUMENTS:        noneX
  4394. X * RETURNS:            none    X
  4395. X * NOTES:            X
  4396. X *X
  4397. X ***************************************************************************/X
  4398. XX
  4399. XVOIDX
  4400. Xstart_init ( )X
  4401. X{X
  4402. X    int temp = 0;X
  4403. XX
  4404. X    /* build the init function */X
  4405. X    fprintf ( fph, "int init ( var_param )\n" );X
  4406. X    fprintf ( fph, "int * var_param;\n{\n" );X
  4407. XX
  4408. X    while ( temp++ < NUM_PARAM )X
  4409. X        fprintf ( fph, "    var_param[%d] = %d;\n", temp-1, var_param[temp-1] );X
  4410. X}X
  4411. XX
  4412. XX
  4413. XX
  4414. X/****************************************************************************X
  4415. X *X
  4416. X * FUNCTION:        addLocalVar()X
  4417. X * PURPOSE:            add a local variable to the variable listX
  4418. X * ARGUMENTS:        name - variable nameX
  4419. X *                    value - variable valueX
  4420. X * RETURNS:            OK - variable addedX
  4421. X *                    BAD - variable already existsX
  4422. X * NOTES:            X
  4423. X *X
  4424. X ***************************************************************************/X
  4425. XX
  4426. XintX
  4427. XaddLocalVar ( name, value )X
  4428. X    char *name;X
  4429. X    int value;X
  4430. X{X
  4431. X    struct s_var *temp, *temp1, *temp2;X
  4432. X    char *malloc ( );X
  4433. XX
  4434. X    /* set up the structure */X
  4435. X    if ( ( temp = (struct s_var *) malloc ( sizeof (struct s_var) ) ) == NULL) {X
  4436. X        fprintf ( stderr, "Memory problems, Panic!\n" );X
  4437. X        exit ( 1 );X
  4438. X    }X
  4439. X    strcpy ( temp->str, name );X
  4440. X    temp->val = value;X
  4441. X    temp->next = NULL;X
  4442. XX
  4443. X    temp1 = NULL;X
  4444. XX
  4445. X    /* empty queue */X
  4446. X    if ( localvar == NULL ) {X
  4447. X        localvar = temp;X
  4448. X        return OK;X
  4449. X    }X
  4450. XX
  4451. X    /* see if there exists one */X
  4452. X    do {X
  4453. X        if ( temp1 == NULL )X
  4454. X            temp1 = localvar ; X
  4455. X        else {X
  4456. X            temp2 = temp1->next;X
  4457. X            temp1 = temp2;X
  4458. X        }X
  4459. XX
  4460. X        if ( !strcmp ( name, temp1->str ) ) {X
  4461. X            warning ( "Duplicate variable names", (char *) 0 );X
  4462. X            return BAD;X
  4463. X        }X
  4464. X    } while ( temp1->next != NULL );X
  4465. XX
  4466. X    temp1->next = temp;X
  4467. XX
  4468. X    return OK;X
  4469. X}X
  4470. XX
  4471. XX
  4472. XX
  4473. X/****************************************************************************X
  4474. X *X
  4475. X * FUNCTION:        queryLocalVar()X
  4476. X * PURPOSE:            return the current value of a local variableX
  4477. X * ARGUMENTS:        name - variable nameX
  4478. X * RETURNS:            variable value, -1 if not definedX
  4479. X * NOTES:            X
  4480. X *X
  4481. X ***************************************************************************/X
  4482. XX
  4483. XintX
  4484. XqueryLocalVar ( name )X
  4485. X    char *name;X
  4486. X{X
  4487. X    struct s_var *temp;X
  4488. XX
  4489. X    temp = localvar;X
  4490. XX
  4491. X    while ( temp != NULL ) {X
  4492. X        if ( ! strcmp ( name, temp->str ) ) X
  4493. X            return temp->val;X
  4494. X        temp = temp->next;X
  4495. X    }X
  4496. XX
  4497. X    /* no entry */X
  4498. X    warning ( "Undeclared variable", name ); X
  4499. X    return -1;X
  4500. X}X
  4501. XX
  4502. XX
  4503. X/****************************************************************************X
  4504. X *X
  4505. X * FUNCTION:        set_mem()X
  4506. X * PURPOSE:            set the memory sizes for the micro code, and mainX
  4507. X * ARGUMENTS:        cval - cpu size for microcodeX
  4508. X *                    mval1 - main memory sizeX
  4509. X *                    mval2 - main memory bit sizeX
  4510. X * RETURNS:            noneX
  4511. X * NOTES:            X
  4512. X *X
  4513. X ***************************************************************************/X
  4514. XX
  4515. XVOIDX
  4516. Xset_mem ( cval, mval1, mval2 )X
  4517. X    int cval, mval1, mval2;X
  4518. X{X
  4519. X    char buffer[80];X
  4520. XX
  4521. X    if ( mval2 > findLongSize ( ) ) {X
  4522. X        sprintf ( buffer, "Memory bit size too large, truncating to %d",X
  4523. X         findLongSize ( ) );X
  4524. X        warning ( buffer, (char *) 0 );X
  4525. X        mval2 = findLongSize ( );X
  4526. X    }X
  4527. XX
  4528. X    var_param[CPUSIZE] = cval;X
  4529. X    var_param[MAINSIZE] = mval1;X
  4530. X    var_param[MAINBSIZE] = mval2;X
  4531. X}X
  4532. XX
  4533. XX
  4534. XX
  4535. X/****************************************************************************X
  4536. X *X
  4537. X * FUNCTION:        set_entry()X
  4538. X * PURPOSE:            set an internal variable to a certain variableX
  4539. X * ARGUMENTS:        which - which variableX
  4540. X *                    val - value to set variable toX
  4541. X * RETURNS:            none    X
  4542. X * NOTES:            X
  4543. X *X
  4544. X ***************************************************************************/X
  4545. XX
  4546. XVOIDX
  4547. Xset_entry ( which, val )X
  4548. X    int which, val;X
  4549. X{X
  4550. X    var_param[which] = val;X
  4551. X}X
  4552. XX
  4553. XX
  4554. X/****************************************************************************X
  4555. X *X
  4556. X * FUNCTION:        start_engine()X
  4557. X * PURPOSE:            start the engine routine    X
  4558. X * ARGUMENTS:        noneX
  4559. X * RETURNS:            none    X
  4560. X * NOTES:            X
  4561. X *X
  4562. X ***************************************************************************/X
  4563. XX
  4564. XVOIDX
  4565. Xstart_engine ( )X
  4566. X{X
  4567. X    fprintf ( fph, "\nint engine ( subcycle )\n" );X
  4568. X    fprintf ( fph, "    int subcycle;\n" );X
  4569. X    fprintf ( fph, "{\n" );X
  4570. X}X
  4571. XX
  4572. XX
  4573. X/****************************************************************************X
  4574. X *X
  4575. X * FUNCTION:        end_engine()X
  4576. X * PURPOSE:            end the engine routineX
  4577. X * ARGUMENTS:        noneX
  4578. X * RETURNS:            none    X
  4579. X * NOTES:            X
  4580. X *X
  4581. X ***************************************************************************/X
  4582. XX
  4583. XVOIDX
  4584. Xend_engine ( )X
  4585. X{X
  4586. X    fprintf ( fph, "    return mpc ( \"query\", 0 );\n" );X
  4587. X    fprintf ( fph, "}\n\n" );X
  4588. X}X
  4589. XX
  4590. Zaphod for prez
  4591. cat << 'Zaphod for prez' | sed 's/X\(.*\)X/\1/' > yampc.c
  4592. XX
  4593. X/* ----------------------------------------------------------------------- *\X
  4594. X******************************************************************************X
  4595. XX
  4596. X  PROGRAM NAME: Computer Hardware Main moduleX
  4597. XX
  4598. X  PROGRAMMER:    Patrick Palmer                 DATE: 8/17/90 X
  4599. X          X
  4600. X  DESCRIPTION OF PROGRAM: X
  4601. X     This is the main module when compiling the computer hardwareX
  4602. X  description file.X
  4603. X X
  4604. X******************************************************************************X
  4605. XX
  4606. X        This program is free software; you can redistribute it and/orX
  4607. X        modify it under the terms of the GNU General Public LicenseX
  4608. X        (version 2) as published by the Free Software Foundation.X
  4609. XX
  4610. X        This program is distributed in the hope that is will be useful,X
  4611. X        but WITHOUT ANY WARRANTY; without even the implied warrenty ofX
  4612. X        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See theX
  4613. X        GNU General Public License for more details.X
  4614. X        X
  4615. X        You should have received a copy of the GNU General Public X
  4616. X        License along with this program; if not, write to the FreeX
  4617. X        Software Foundation, Inc., 675 Mass Ave, Cambridge, MAX
  4618. X        02139, USA.X
  4619. XX
  4620. X        YAMPC Microcode Development KitX
  4621. X        (C) 1992 by Patrick PalmerX
  4622. XX
  4623. X******************************************************************************X
  4624. XX
  4625. XX
  4626. X  PROGRAM REVISION LOGX
  4627. X  X
  4628. X        DATE               DESCRIPTION OF CHANGE                PROGRAMMERX
  4629. X      --------  ----------------------------------------------  ----------X
  4630. X      08/17/90  YAMPC - Version 1.0                             PAPX
  4631. X      11/17/90  Interrupts, Bug Fixes - Version 1.1             PAPX
  4632. X      01/11/92  Distribution version - Version 1.2              PAPX
  4633. XX
  4634. X***************************************************************************  X
  4635. X\* ------------------------------------------------------------------------ */X
  4636. XX
  4637. X#include <stdio.h>X
  4638. X#include <time.h>X
  4639. X#include "yampc.h"X
  4640. X#include "misc.h"X
  4641. XX
  4642. X/* file descriptors for the files creating */X
  4643. XFILE *fph;                /* hardware_file file pointer */X
  4644. XX
  4645. X/* the local variables list */X
  4646. Xstruct s_var *localvar;X
  4647. XX
  4648. X/* variable parameter list (global) */X
  4649. Xint var_param[NUM_PARAM];X
  4650. XX
  4651. XX
  4652. X/****************************************************************************X
  4653. X *X
  4654. X * FUNCTION:        main()X
  4655. X * PURPOSE:            set up system to compile the hardware spec file    X
  4656. X * ARGUMENTS:        argc - number of command line argumentsX
  4657. X *                    argv - argument listX
  4658. X * RETURNS:            nothing interesting    X
  4659. X * NOTES:            X
  4660. X *X
  4661. X ***************************************************************************/X
  4662. XX
  4663. Xmain ( argc, argv )X
  4664. X    int argc;                    /* argument counter */X
  4665. X    char *argv[];                /* arguments */X
  4666. X{X
  4667. X    char filename[128];            /* filename for extentions */X
  4668. X    FILE *fp, *fopen ( );        /* hardware file */X
  4669. XX
  4670. X    /* display the version of this system */X
  4671. X    version ( );X
  4672. XX
  4673. X    /* no entries in the variable list */X
  4674. X    localvar = NULL;X
  4675. XX
  4676. X    /* only requires 1 argument */X
  4677. X    if ( argc != 2 ) {X
  4678. X        printf ( "usage: %s <hardware file>\n", argv[0] );X
  4679. X        exit ( 1 );X
  4680. X    }X
  4681. XX
  4682. X    /* check the file */X
  4683. X    if ( ( fp = fopen ( argv[1], "r" ) ) == NULL ) {X
  4684. X        printf ( "%s: unable to open %s\n", argv[0], argv[1] );X
  4685. X        exit ( 1 );X
  4686. X    }X
  4687. XX
  4688. X    /* create the output file */X
  4689. X    sprintf ( filename, "%s.c", argv[1] );X
  4690. X    if ( ( fph = fopen ( filename, "w" ) ) == NULL ) {X
  4691. X        printf ( "%s: unable to open %s\n", argv[0], filename );X
  4692. X        exit ( 1 );X
  4693. X    }X
  4694. XX
  4695. X    /* write the needed information in the filename.c */X
  4696. X    start_hw ( argv[0] );X
  4697. XX
  4698. X    /* set the input file descriptor */X
  4699. X    setInput ( fp );X
  4700. XX
  4701. X    /* do it */    X
  4702. X    yyparse ( );X
  4703. XX
  4704. X    /* close the files */X
  4705. X    fclose ( fph );X
  4706. X    fclose ( fp );X
  4707. XX
  4708. X    /* return no error */X
  4709. X    return 0;X
  4710. X}X
  4711. XX
  4712. XX
  4713. X/****************************************************************************X
  4714. X *X
  4715. X * FUNCTION:        convStr()X
  4716. X * PURPOSE:            convert a string to a numberX
  4717. X * ARGUMENTS:        str - string containing the numberX
  4718. X *                    type - type of number within the stringX
  4719. X * RETURNS:            the converted numberX
  4720. X * NOTES:            supports hex, decimal and octalX
  4721. X *X
  4722. X ***************************************************************************/X
  4723. XX
  4724. XintX
  4725. XconvStr ( str, type )X
  4726. X    char *str;            /* string to convert */X
  4727. X    int type;            /* type of number */X
  4728. X{X
  4729. X    int val;            /* value to rebuild */X
  4730. X    int num = 0;            /* number being converted */X
  4731. XX
  4732. X    switch ( type ) {X
  4733. X        case DEC:X
  4734. X            val = 10;X
  4735. X            break;X
  4736. X        case OCT:X
  4737. X            val = 8;X
  4738. X            break;X
  4739. X        case HEX:X
  4740. X            val = 16;X
  4741. X            break;X
  4742. X        default:X
  4743. X            return 0;X
  4744. X    }X
  4745. XX
  4746. X    /* do the conversion */X
  4747. X    while ( *str ) {X
  4748. X        if ( type == HEX && *str >= 'a' && *str <= 'f' ) X
  4749. X            num = ( num * val ) + ( *str++ - 'a' + 10 );X
  4750. X        else if ( type == HEX && *str >= 'A' && *str <= 'F' )X
  4751. X            num = ( num * val ) + ( *str++ - 'A' + 10 );X
  4752. X        elseX
  4753. X            num = ( num * val ) + ( *str++ - '0' );X
  4754. X    }X
  4755. XX
  4756. X    /* return the number value in decimal */X
  4757. X    return num;X
  4758. X}X
  4759. XX
  4760. XX
  4761. Zaphod for prez
  4762. cat << 'Zaphod for prez' | sed 's/X\(.*\)X/\1/' > yampc.h
  4763. XX
  4764. XX
  4765. X/* ----------------------------------------------------------------------- *\X
  4766. X******************************************************************************X
  4767. XX
  4768. X  PROGRAM NAME: Computer Hardware Main module Header FileX
  4769. XX
  4770. X  PROGRAMMER:    Patrick Palmer                 DATE: 8/17/90 X
  4771. X          X
  4772. X  DESCRIPTION OF PROGRAM: X
  4773. X    This is the header file for the YAMPC compiler.X
  4774. X X
  4775. X******************************************************************************X
  4776. XX
  4777. X        This program is free software; you can redistribute it and/orX
  4778. X        modify it under the terms of the GNU General Public LicenseX
  4779. X        (version 2) as published by the Free Software Foundation.X
  4780. XX
  4781. X        This program is distributed in the hope that is will be useful,X
  4782. X        but WITHOUT ANY WARRANTY; without even the implied warrenty ofX
  4783. X        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See theX
  4784. X        GNU General Public License for more details.X
  4785. X        X
  4786. X        You should have received a copy of the GNU General Public X
  4787. X        License along with this program; if not, write to the FreeX
  4788. X        Software Foundation, Inc., 675 Mass Ave, Cambridge, MAX
  4789. X        02139, USA.X
  4790. XX
  4791. X        YAMPC Microcode Development KitX
  4792. X        (C) 1992 by Patrick PalmerX
  4793. XX
  4794. X******************************************************************************X
  4795. XX
  4796. XX
  4797. X  PROGRAM REVISION LOGX
  4798. X  X
  4799. X        DATE               DESCRIPTION OF CHANGE                PROGRAMMERX
  4800. X      --------  ----------------------------------------------  ----------X
  4801. X      08/17/90  YAMPC - Version 1.0                             PAPX
  4802. X      11/17/90  Interrupts, Bug Fixes - Version 1.1             PAPX
  4803. X      01/11/92  Distribution version - Version 1.2              PAPX
  4804. XX
  4805. X***************************************************************************  X
  4806. X\* ------------------------------------------------------------------------ */X
  4807. XX
  4808. Xtypedef int VOID;X
  4809. XX
  4810. X/* YACC stack type */X
  4811. Xstruct ystack {X
  4812. X    int val;        /* value of a number */X
  4813. X    char str[100];X
  4814. X};X
  4815. XX
  4816. X/* variables structure */X
  4817. Xstruct s_var {X
  4818. X    char str[200];X
  4819. X    int val;X
  4820. X    struct s_var *next;X
  4821. X};X
  4822. XX
  4823. X/* types of numbers */X
  4824. X#define HEX    1X
  4825. X#define DEC    2X
  4826. X#define OCT    3X
  4827. XX
  4828. XX
  4829. X/* prototypes */X
  4830. XX
  4831. X#ifdef ANSI_CX
  4832. X#define PROTO(x)        xX
  4833. X#elseX
  4834. X#define PROTO(x)        ()X
  4835. X#endifX
  4836. XX
  4837. X/* FILE: lalr.y */X
  4838. Xint        yyerror PROTO (( char * )),X
  4839. X        warning PROTO (( char *, char * ));X
  4840. XX
  4841. X/* FILE: lex.l */X
  4842. Xint        yywrap PROTO (( void )),X
  4843. X        setInput PROTO (( FILE * ));X
  4844. XX
  4845. X/* FILE: yampc.c */X
  4846. Xint        main PROTO (( int, char ** )),X
  4847. X        convStr PROTO (( char *, int ));X
  4848. XX
  4849. X/* FILE: y_misc.c */X
  4850. XVOID    start_hw PROTO (( char * )),X
  4851. X        end_struct PROTO (( void )),X
  4852. X        end_func PROTO (( void )),X
  4853. X        put_msg PROTO (( char * )),X
  4854. X        init_var PROTO (( void )),X
  4855. X        add_var PROTO (( char *, int, int, int )),X
  4856. X        start_init PROTO (( void )),X
  4857. X        set_mem PROTO (( int, int, int )),X
  4858. X        set_entry PROTO (( int, int )),X
  4859. X        start_engine PROTO (( void )),X
  4860. X        end_engine PROTO (( void ));X
  4861. Xint        addLocalVar PROTO (( char *, int )),X
  4862. X        queryLocalVar PROTO (( char * ));X
  4863. XX
  4864. XX
  4865. XX
  4866. Zaphod for prez
  4867. exit 0
  4868.