Subversion Repositories pentevo

Rev

Blame | Last modification | View Log | Download | RSS feed | ?url?

  1. /* codetms1.c */
  2. /*****************************************************************************/
  3. /* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only                     */
  4. /*                                                                           */
  5. /* AS-Portierung                                                             */
  6. /*                                                                           */
  7. /* Codegenerator TMS1000-Familie                                             */
  8. /*                                                                           */
  9. /*****************************************************************************/
  10.  
  11. #include "stdinc.h"
  12. #include <ctype.h>
  13. #include <string.h>
  14.  
  15. #include "bpemu.h"
  16. #include "strutil.h"
  17. #include "asmdef.h"
  18. #include "asmsub.h"
  19. #include "asmpars.h"
  20. #include "asmitree.h"
  21. #include "codevars.h"
  22. #include "headids.h"
  23. #include "intpseudo.h"
  24. #include "errmsg.h"
  25.  
  26. #include "codetms1.h"
  27.  
  28. static CPUVar CPU1000, CPU1100, CPU1200, CPU1300;
  29. static IntType CodeAdrIntType, DataAdrIntType;
  30.  
  31. /* 2/3/4-bit-operand in instruction is bit-mirrored */
  32.  
  33. static const Byte BitMirr[16] =
  34. {
  35.    0,  8,  4, 12,  2, 10,  6, 14,
  36.    1,  9,  5, 13,  3, 11,  7, 15
  37. };
  38.  
  39. /*---------------------------------------------------------------------------*/
  40. /* Decoders */
  41.  
  42. static void DecodeFixed(Word Code)
  43. {
  44.   if (ChkArgCnt(0, 0))
  45.   {
  46.     BAsmCode[0] = Lo(Code);
  47.     CodeLen = 1;
  48.   }
  49. }
  50.  
  51. static void DecodeConst4(Word Code)
  52. {
  53.   if (ChkArgCnt(1, 1))
  54.   {
  55.     Boolean OK;
  56.     BAsmCode[0] = EvalStrIntExpression(&ArgStr[1], Int4, &OK);
  57.     if (OK)
  58.     {
  59.       BAsmCode[0] = BitMirr[BAsmCode[0] & 0x0f] | (Code & 0xf0);
  60.       CodeLen = 1;
  61.     }
  62.   }
  63. }
  64.  
  65. static void DecodeConst3(Word Code)
  66. {
  67.   if (ChkArgCnt(1, 1))
  68.   {
  69.     Boolean OK;
  70.     BAsmCode[0] = EvalStrIntExpression(&ArgStr[1], UInt3, &OK);
  71.     if (OK)
  72.     {
  73.       BAsmCode[0] = (BitMirr[BAsmCode[0] & 0x07] >> 1) | (Code & 0xf8);
  74.       CodeLen = 1;
  75.     }
  76.   }
  77. }
  78.  
  79. static void DecodeConst2(Word Code)
  80. {
  81.   if (ChkArgCnt(1, 1))
  82.   {
  83.     Boolean OK;
  84.     BAsmCode[0] = EvalStrIntExpression(&ArgStr[1], UInt2, &OK);
  85.     if (OK)
  86.     {
  87.       BAsmCode[0] = (BitMirr[BAsmCode[0] & 0x03] >> 2) | (Code & 0xfc);
  88.       CodeLen = 1;
  89.     }
  90.   }
  91. }
  92.  
  93. static void DecodeJmp(Word Code)
  94. {
  95.   if (ChkArgCnt(1, 1))
  96.   {
  97.     tEvalResult EvalResult;
  98.     Word Addr = EvalStrIntExpressionWithResult(&ArgStr[1], CodeAdrIntType, &EvalResult);
  99.     if (EvalResult.OK)
  100.     {
  101.       ChkSpace(SegCode, EvalResult.AddrSpaceMask);
  102.       CodeLen = 1;
  103.       BAsmCode[0] = (Code & 0xc0) | (Addr & 0x3f);
  104.     }
  105.   }
  106. }
  107.  
  108. static void DecodeJmpL(Word Code)
  109. {
  110.   UNUSED(Code);
  111.  
  112.   if (ChkArgCnt(1, 1))
  113.   {
  114.     tEvalResult EvalResult;
  115.     Word Addr = EvalStrIntExpressionWithResult(&ArgStr[1], CodeAdrIntType, &EvalResult);
  116.     if (EvalResult.OK)
  117.     {
  118.       ChkSpace(SegCode, EvalResult.AddrSpaceMask);
  119.       BAsmCode[0] = 0x10 | ((Addr >> 6) & 15); /* LDP... */
  120.       BAsmCode[1] = (Code & 0xc0) | (Addr & 0x3f);
  121.       CodeLen = 2;
  122.     }
  123.   }
  124. }
  125.  
  126. /*---------------------------------------------------------------------------*/
  127. /* Dynamic Instruction Table Handling */
  128.  
  129. static void InitFields(void)
  130. {
  131.   Boolean Is1100 = (MomCPU == CPU1100) || (MomCPU == CPU1300);
  132.  
  133.   InstTable = CreateInstTable(107);
  134.  
  135.   AddInstTable(InstTable, "TAY", Is1100 ? 0x20 : 0x24, DecodeFixed);
  136.   AddInstTable(InstTable, "TYA", 0x23, DecodeFixed);
  137.   AddInstTable(InstTable, "CLA", Is1100 ? 0x7f : 0x2f, DecodeFixed);
  138.  
  139.   AddInstTable(InstTable, "TAM", Is1100 ? 0x27 : 0x03, DecodeFixed);
  140.   if (Is1100)
  141.   {
  142.     AddInstTable(InstTable, "TAMIYC", 0x25, DecodeFixed);
  143.     AddInstTable(InstTable, "TAMDYN", 0x24, DecodeFixed);
  144.   }
  145.   else
  146.   {
  147.     AddInstTable(InstTable, "TAMIY", 0x20, DecodeFixed);
  148.   }
  149.   AddInstTable(InstTable, "TAMZA", Is1100 ? 0x26 : 0x04, DecodeFixed);
  150.   AddInstTable(InstTable, "TMY", 0x22, DecodeFixed);
  151.   AddInstTable(InstTable, "TMA", 0x21, DecodeFixed);
  152.   AddInstTable(InstTable, "XMA", Is1100 ? 0x03 : 0x2e, DecodeFixed);
  153.  
  154.   AddInstTable(InstTable, "AMAAC", Is1100 ? 0x06 : 0x25, DecodeFixed);
  155.   AddInstTable(InstTable, "SAMAN", Is1100 ? 0x3c : 0x27, DecodeFixed);
  156.   AddInstTable(InstTable, "IMAC", Is1100 ? 0x3e : 0x28, DecodeFixed);
  157.   AddInstTable(InstTable, "DMAN", Is1100 ? 0x07 : 0x2a, DecodeFixed);
  158.   if (Is1100)
  159.     AddInstTable(InstTable, "IAC", 0x70, DecodeFixed);
  160.   else
  161.     AddInstTable(InstTable, "IA", 0x0e, DecodeFixed);
  162.   AddInstTable(InstTable, "IYC", Is1100 ? 0x05 : 0x2b, DecodeFixed);
  163.   AddInstTable(InstTable, "DAN", Is1100 ? 0x77 : 0x07, DecodeFixed);
  164.   AddInstTable(InstTable, "DYN", Is1100 ? 0x04 : 0x2c, DecodeFixed);
  165.   AddInstTable(InstTable, "CPAIZ", Is1100 ? 0x3d : 0x2d, DecodeFixed);
  166.   AddInstTable(InstTable, "A6AAC", Is1100 ? 0x7a : 0x06, DecodeFixed);
  167.   AddInstTable(InstTable, "A8AAC", Is1100 ? 0x7e : 0x01, DecodeFixed);
  168.   AddInstTable(InstTable, "A10AAC", Is1100 ? 0x79 : 0x05, DecodeFixed);
  169.   if (Is1100)
  170.   {
  171.     AddInstTable(InstTable, "A2AAC", 0x78, DecodeFixed);
  172.     AddInstTable(InstTable, "A3AAC", 0x74, DecodeFixed);
  173.     AddInstTable(InstTable, "A4AAC", 0x7c, DecodeFixed);
  174.     AddInstTable(InstTable, "A5AAC", 0x72, DecodeFixed);
  175.     AddInstTable(InstTable, "A7AAC", 0x76, DecodeFixed);
  176.     AddInstTable(InstTable, "A9AAC", 0x71, DecodeFixed);
  177.     AddInstTable(InstTable, "A11AAC", 0x75, DecodeFixed);
  178.     AddInstTable(InstTable, "A12AAC", 0x7d, DecodeFixed);
  179.     AddInstTable(InstTable, "A13AAC", 0x73, DecodeFixed);
  180.     AddInstTable(InstTable, "A14AAC", 0x7b, DecodeFixed);
  181.   }
  182.  
  183.   AddInstTable(InstTable, "ALEM", Is1100 ? 0x01: 0x29, DecodeFixed);
  184.   if (!Is1100)
  185.   {
  186.     AddInstTable(InstTable, "ALEC", 0x70, DecodeConst4);
  187.   }
  188.  
  189.   if (Is1100)
  190.   {
  191.     AddInstTable(InstTable, "MNEA", 0x00, DecodeFixed);
  192.   }
  193.   AddInstTable(InstTable, "MNEZ", Is1100 ? 0x3f : 0x26, DecodeFixed);
  194.   AddInstTable(InstTable, "YNEA", Is1100 ? 0x02 : 0x02, DecodeFixed);
  195.   AddInstTable(InstTable, "YNEC", 0x50, DecodeConst4);
  196.  
  197.   AddInstTable(InstTable, "SBIT", 0x30, DecodeConst2);
  198.   AddInstTable(InstTable, "RBIT", 0x34, DecodeConst2);
  199.   AddInstTable(InstTable, "TBIT1", 0x38, DecodeConst2);
  200.  
  201.   AddInstTable(InstTable, "TCY", 0x40, DecodeConst4);
  202.   AddInstTable(InstTable, "TCMIY", 0x60, DecodeConst4);
  203.  
  204.   AddInstTable(InstTable, "KNEZ", Is1100 ? 0x0e : 0x09, DecodeFixed);
  205.   AddInstTable(InstTable, "TKA", 0x08, DecodeFixed);
  206.  
  207.   AddInstTable(InstTable, "SETR", 0x0d, DecodeFixed);
  208.   AddInstTable(InstTable, "RSTR", 0x0c, DecodeFixed);
  209.   AddInstTable(InstTable, "TDO", 0x0a, DecodeFixed);
  210.   if (!Is1100)
  211.   {
  212.     AddInstTable(InstTable, "CLO", 0x0b, DecodeFixed);
  213.   }
  214.  
  215.   if (Is1100)
  216.   {
  217.     AddInstTable(InstTable, "LDX", 0x28, DecodeConst3);
  218.   }
  219.   else
  220.   {
  221.     AddInstTable(InstTable, "LDX", 0x3c, DecodeConst2);
  222.   }
  223.   AddInstTable(InstTable, "COMX", Is1100 ? 0x09 : 0x00, DecodeFixed);
  224.  
  225.   AddInstTable(InstTable, "BR", 0x80, DecodeJmp);
  226.   AddInstTable(InstTable, "CALL", 0xc0, DecodeJmp);
  227.   AddInstTable(InstTable, "BL", 0x80, DecodeJmpL);
  228.   AddInstTable(InstTable, "CALLL", 0xc0, DecodeJmpL);
  229.   AddInstTable(InstTable, "RETN", 0x0f, DecodeFixed);
  230.   AddInstTable(InstTable, "LDP", 0x10, DecodeConst4);
  231.   if (Is1100)
  232.   {
  233.     AddInstTable(InstTable, "COMC", 0x0b, DecodeFixed);
  234.   }
  235. }
  236.  
  237. static void DeinitFields(void)
  238. {
  239.   DestroyInstTable(InstTable);
  240. }
  241.  
  242. /*---------------------------------------------------------------------------*/
  243. /* Interface */
  244.  
  245. static void MakeCode_TMS1(void)
  246. {
  247.   CodeLen = 0;
  248.   DontPrint = False;
  249.  
  250.   /* zu ignorierendes */
  251.  
  252.   if (Memo(""))
  253.     return;
  254.  
  255.   /* Pseudoanweisungen */
  256.  
  257.   if (DecodeIntelPseudo(True))
  258.     return;
  259.  
  260.   /* remainder */
  261.  
  262.   if (!LookupInstTable(InstTable, OpPart.str.p_str))
  263.     WrStrErrorPos(ErrNum_UnknownInstruction, &OpPart);
  264. }
  265.  
  266. static Boolean IsDef_TMS1(void)
  267. {
  268.   return False;
  269. }
  270.  
  271. static void SwitchFrom_TMS1(void)
  272. {
  273.   DeinitFields();
  274. }
  275.  
  276. static void SwitchTo_TMS1(void)
  277. {
  278.   const TFamilyDescr *pFoundDescr = FindFamilyByName("TMS1000");
  279.  
  280.   TurnWords = False;
  281.   SetIntConstMode(eIntConstModeIntel);
  282.  
  283.   PCSymbol = "$";
  284.   HeaderID = pFoundDescr->Id;
  285.   NOPCode = 0x100;
  286.   DivideChars = ",";
  287.   HasAttrs = False;
  288.  
  289.   ValidSegs = (1 << SegCode) | (1 << SegData);
  290.   Grans[SegCode] = 1; ListGrans[SegCode] = 1; SegInits[SegCode] = 0;
  291.   Grans[SegData] = 1; ListGrans[SegData] = 1; SegInits[SegData] = 0;
  292.   if ((MomCPU == CPU1000) || (MomCPU == CPU1200))
  293.   {
  294.     CodeAdrIntType = UInt10;
  295.     DataAdrIntType = UInt6;
  296.   }
  297.   else if ((MomCPU == CPU1100) || (MomCPU == CPU1300))
  298.   {
  299.     CodeAdrIntType = UInt11;
  300.     DataAdrIntType = UInt7;
  301.   }
  302.   SegLimits[SegCode] = IntTypeDefs[CodeAdrIntType].Max;
  303.   SegLimits[SegData] = IntTypeDefs[DataAdrIntType].Max;
  304.  
  305.   MakeCode = MakeCode_TMS1;
  306.   IsDef = IsDef_TMS1;
  307.   SwitchFrom = SwitchFrom_TMS1;
  308.  
  309.   InitFields();
  310. }
  311.  
  312. void codetms1_init(void)
  313. {
  314.   CPU1000 = AddCPU("TMS1000", SwitchTo_TMS1);
  315.   CPU1100 = AddCPU("TMS1100", SwitchTo_TMS1);
  316.   CPU1200 = AddCPU("TMS1200", SwitchTo_TMS1);
  317.   CPU1300 = AddCPU("TMS1300", SwitchTo_TMS1);
  318. }
  319.