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

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