/**
   * Instantiate and attach a dynamic PLPSimBusModule-based module to this I/O registry and to the
   * bus of the given simulation core. PLPDynamicModuleFramework is called to create a new instance
   * of the module.
   *
   * @param index Index of the dynamic module CLASS
   * @param addr Starting address of the module's memory map
   * @param size Number of registers
   * @param isWordAligned Denote whether the module's address space is word aligned
   * @param frame Frame object associated with this module
   * @return PLP_OK on completion, or PLP_DBUSMOD_INSTANTIATION_ERROR if the module object failed to
   *     initialize
   */
  public int attachDynamicModule(
      int index, long startAddr, long endAddr, boolean isWordAligned, Object frame) {
    moduleFrames.add(frame);
    PLPSimBusModule module = DynamicModuleFramework.newBusModuleInstance(index);

    if (module == null) return Constants.PLP_DMOD_INSTANTIATION_ERROR;

    module.setNewParameters(startAddr, endAddr, isWordAligned);
    modules.add(module);
    type.add(-1); // -1 for dynamic module
    regSize.add(isWordAligned ? (endAddr - startAddr) / 4 + 1 : endAddr - startAddr + 1);
    module.enable();
    positionInBus.add(plp.sim.bus.add(module));

    return Constants.PLP_OK;
  }