Subversion Repositories pentevo

Rev

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

  1. /* onoff_common.c */
  2. /*****************************************************************************/
  3. /* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only                     */
  4. /*                                                                           */
  5. /* AS-Port                                                                   */
  6. /*                                                                           */
  7. /* ON/OFF flags used by several targets                                      */
  8. /*                                                                           */
  9. /*****************************************************************************/
  10.  
  11. #include "stdinc.h"
  12. #include "asmdef.h"
  13. #include "asmsub.h"
  14. #include "asmpars.h"
  15. #include "asmallg.h"
  16. #include "cmdarg.h"
  17. #include "onoff_common.h"
  18.  
  19. Boolean FPUAvail,    /* floating point co processor instructions allowed? */
  20.         PMMUAvail,   /* PMMU instructions allowed? */
  21.         SupAllowed,  /* supervisor mode enabled */
  22.         MaxMode,     /* CPU in maximum mode */
  23.         CompMode,    /* Enable Compatibility Mode */
  24.         TargetBigEndian, /* Data storage Big Endian? */
  25.         DoPadding,   /* align to even address? */
  26.         Packing;     /* packed data storage? */
  27. unsigned registered;
  28.  
  29. #define SupAllowedCmdName "SUPMODE"   /* Privileged instructions allowed */
  30. #define SupAllowedSymName "INSUPMODE"
  31. static Boolean DefSupAllowed;
  32.  
  33. #define BigEndianCmdName  "BIGENDIAN"
  34. #define BigEndianSymName  "BIGENDIAN"  /* Data storage MSB first */
  35. static Boolean DefBigEndian;
  36.  
  37. #define CompModeCmdName   "COMPMODE"   /* Compatibility Mode */
  38. #define CompModeSymName   "COMPMODE"
  39. static Boolean DefCompMode;
  40.  
  41. #define PackingCmdName    "PACKING"
  42. #define PackingSymName    "PACKING"
  43. static Boolean DefPacking, DefPackingSet;
  44.  
  45. /*!------------------------------------------------------------------------
  46.  * \fn     onoff_test_and_set(unsigned mask)
  47.  * \brief  check whether on/off insn is registered first time during pass
  48.  * \param  mask insn to test
  49.  * \return mask if first time, otherwise 0
  50.  * ------------------------------------------------------------------------ */
  51.  
  52. unsigned onoff_test_and_set(unsigned mask)
  53. {
  54.   unsigned curr = registered;
  55.   registered |= mask;
  56.   return curr & mask;
  57. }
  58.  
  59. /*!------------------------------------------------------------------------
  60.  * \fn     onoff_fpu_add(void)
  61.  * \brief  register on/off command to enable/disable FPU instruction extensions
  62.  * ------------------------------------------------------------------------ */
  63.  
  64. void onoff_fpu_add(void)
  65. {
  66.   if (!onoff_test_and_set(e_onoff_reg_fpu))
  67.     SetFlag(&FPUAvail, FPUAvailName, False);
  68.   AddONOFF("FPU", &FPUAvail, FPUAvailName, False);
  69. }
  70.  
  71. /*!------------------------------------------------------------------------
  72.  * \fn     onoff_pmmu_add(void)
  73.  * \brief  register on/off command to enable/disable PMMU instruction extensions
  74.  * ------------------------------------------------------------------------ */
  75.  
  76. void onoff_pmmu_add(void)
  77. {
  78.   if (!onoff_test_and_set(e_onoff_reg_pmmu))
  79.     SetFlag(&PMMUAvail, PMMUAvailName, False);
  80.   AddONOFF("PMMU", &PMMUAvail, PMMUAvailName, False);
  81. }
  82.  
  83. /*!------------------------------------------------------------------------
  84.  * \fn     onoff_supmode_add(void)
  85.  * \brief  register on/off command to enable/disable supervisor mode-only instructions
  86.  * ------------------------------------------------------------------------ */
  87.  
  88. void onoff_supmode_add(void)
  89. {
  90.   if (!onoff_test_and_set(e_onoff_reg_supmode))
  91.     SetFlag(&SupAllowed, SupAllowedSymName, DefSupAllowed);
  92.   AddONOFF(SupAllowedCmdName, &SupAllowed, SupAllowedSymName, False);
  93. }
  94.  
  95. /*!------------------------------------------------------------------------
  96.  * \fn     onoff_maxmode_add(void)
  97.  * \brief  register on/off command to enable/disable maximum mode-only instructions
  98.  * ------------------------------------------------------------------------ */
  99.  
  100. void onoff_maxmode_add(void)
  101. {
  102.   if (!onoff_test_and_set(e_onoff_reg_maxmode))
  103.     SetFlag(&MaxMode, MaxModeSymName, False);
  104.   AddONOFF(MaxModeCmdName, &MaxMode, MaxModeSymName, False);
  105. }
  106.  
  107. /*!------------------------------------------------------------------------
  108.  * \fn     onoff_compmode_add(void)
  109.  * \brief  register on/off command to enable/disable compatibility mode
  110.  * ------------------------------------------------------------------------ */
  111.  
  112. void onoff_compmode_add(void)
  113. {
  114.   if (!onoff_test_and_set(e_onoff_reg_compmode))
  115.     SetFlag(&CompMode, CompModeSymName, DefCompMode);
  116.   AddONOFF(CompModeCmdName, &CompMode, CompModeSymName, False);
  117. }
  118.  
  119. /*!------------------------------------------------------------------------
  120.  * \fn     onoff_bigendian_add(void)
  121.  * \brief  register on/off command to set big/little endian data storage
  122.  * ------------------------------------------------------------------------ */
  123.  
  124. void onoff_bigendian_add(void)
  125. {
  126.   if (!onoff_test_and_set(e_onoff_reg_bigendian))
  127.     SetFlag(&TargetBigEndian, BigEndianSymName, DefBigEndian);
  128.   AddONOFF(BigEndianCmdName, &TargetBigEndian, BigEndianSymName, False);
  129. }
  130.  
  131. /*!------------------------------------------------------------------------
  132.  * \fn     onoff_packing_add(Boolean def_value)
  133.  * \brief  register on/off command to set packed data storage
  134.  * \param  def_value to set as default
  135.  * ------------------------------------------------------------------------ */
  136.  
  137. void onoff_packing_add(Boolean def_value)
  138. {
  139.   if (!onoff_test_and_set(e_onoff_reg_packing))
  140.     SetFlag(&Packing, PackingSymName, DefPackingSet ? DefPacking : def_value);
  141.   AddONOFF(PackingCmdName, &Packing, PackingSymName, False);
  142. }
  143.  
  144. /*!------------------------------------------------------------------------
  145.  * \fn     initpass_onoff(void)
  146.  * \brief  per-pass initialization of module
  147.  * ------------------------------------------------------------------------ */
  148.  
  149. static void initpass_onoff(void)
  150. {
  151.   registered = 0;
  152. }
  153.  
  154. /*!------------------------------------------------------------------------
  155.  * \fn     onoff_common_init(void)
  156.  * \brief  module initialization
  157.  * ------------------------------------------------------------------------ */
  158.  
  159. static as_cmd_result_t CMD_SupAllowed(Boolean Negate, const char *pArg)
  160. {
  161.   UNUSED(pArg);
  162.  
  163.   DefSupAllowed = !Negate;
  164.   return e_cmd_ok;
  165. }
  166.  
  167. static as_cmd_result_t CMD_BigEndian(Boolean Negate, const char *pArg)
  168. {
  169.   UNUSED(pArg);
  170.  
  171.   DefBigEndian = !Negate;
  172.   return e_cmd_ok;
  173. }
  174.  
  175. static as_cmd_result_t CMD_CompMode(Boolean Negate, const char *Arg)
  176. {
  177.   UNUSED(Arg);
  178.  
  179.   DefCompMode = !Negate;
  180.   return e_cmd_ok;
  181. }
  182.  
  183. static as_cmd_result_t CMD_Packing(Boolean Negate, const char *Arg)
  184. {
  185.   UNUSED(Arg);
  186.  
  187.   DefPacking = !Negate;
  188.   DefPackingSet = True;
  189.   return e_cmd_ok;
  190. }
  191.  
  192. static const as_cmd_rec_t onoff_params[] =
  193. {
  194.   { BigEndianCmdName  , CMD_BigEndian       },
  195.   { CompModeCmdName   , CMD_CompMode        },
  196.   { PackingCmdName    , CMD_Packing         },
  197.   { SupAllowedCmdName , CMD_SupAllowed      }
  198. };
  199.  
  200. extern void onoff_common_init(void)
  201. {
  202.   as_cmd_register(onoff_params, as_array_size(onoff_params));
  203.   DefSupAllowed = False;
  204.   DefBigEndian = False;
  205.   DefCompMode = False;
  206.   DefPacking = DefPackingSet = False;
  207.   AddInitPassProc(initpass_onoff);
  208. }
  209.