X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=plugins%2Fnet.mograsim.plugin.core%2Fsrc%2Fnet%2Fmograsim%2Fplugin%2Flaunch%2FMachineLaunchConfigType.java;h=82d7e8be8d96d7f1aa0b8165638aed0e6d2cca32;hb=0eb525202d3c871a2a20f789af1728248f3cff11;hp=32ea832596651cb261bfb8db76db0e64e90502fb;hpb=da1a7df25582ae1fe277762c2ba5640d4697a71c;p=Mograsim.git diff --git a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/launch/MachineLaunchConfigType.java b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/launch/MachineLaunchConfigType.java index 32ea8325..82d7e8be 100644 --- a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/launch/MachineLaunchConfigType.java +++ b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/launch/MachineLaunchConfigType.java @@ -20,9 +20,12 @@ import org.eclipse.ui.statushandlers.StatusManager; import net.mograsim.machine.Machine; import net.mograsim.machine.MachineDefinition; +import net.mograsim.machine.MainMemory; +import net.mograsim.machine.MainMemoryDefinition; import net.mograsim.machine.mi.MicroInstructionMemory; import net.mograsim.machine.mi.MicroInstructionMemoryDefinition; import net.mograsim.machine.mi.MicroInstructionMemoryParser; +import net.mograsim.machine.standard.memory.MainMemoryParser; import net.mograsim.plugin.MograsimActivator; import net.mograsim.plugin.nature.MachineContext; import net.mograsim.plugin.nature.MograsimNature; @@ -30,8 +33,9 @@ import net.mograsim.plugin.nature.ProjectMachineContext; public class MachineLaunchConfigType extends LaunchConfigurationDelegate { - public static final String PROJECT_ATTR = MograsimActivator.PLUGIN_ID + "project"; - public static final String MPM_FILE_ATTR = MograsimActivator.PLUGIN_ID + "mpm"; + public static final String PROJECT_ATTR = MograsimActivator.PLUGIN_ID + ".project"; + public static final String MPM_FILE_ATTR = MograsimActivator.PLUGIN_ID + ".mpm"; + public static final String INITIAL_RAM_FILE_ATTR = MograsimActivator.PLUGIN_ID + ".initialram"; private final IResourceChangeListener resChangedListener; @@ -68,13 +72,14 @@ public class MachineLaunchConfigType extends LaunchConfigurationDelegate MachineDefinition machineDefinition = machDefOptional.orElseThrow(); MicroInstructionMemoryDefinition miMemDef = machineDefinition.getMicroInstructionMemoryDefinition(); + MainMemoryDefinition mainMemDef = machineDefinition.getMainMemoryDefinition(); String mpmFileName = configuration.getAttribute(MPM_FILE_ATTR, ""); if ("".equals(mpmFileName)) return showErrorAndReturnFalse("No MPM file specified"); IFile mpmFile = project.getFile(mpmFileName); - if (!mpmFile.isAccessible()) + if (mpmFile == null || !mpmFile.isAccessible()) return showErrorAndReturnFalse("MPM file not accessible"); try (InputStream mpmStream = mpmFile.getContents()) @@ -86,6 +91,24 @@ public class MachineLaunchConfigType extends LaunchConfigurationDelegate throw new CoreException(new Status(IStatus.ERROR, MograsimActivator.PLUGIN_ID, "Unexpected IO exception reading MPM file", e)); } + String initialRAMFileName = configuration.getAttribute(INITIAL_RAM_FILE_ATTR, ""); + if (!"".equals(initialRAMFileName)) + { + IFile initialRAMFile = project.getFile(initialRAMFileName); + if (initialRAMFile == null || !initialRAMFile.isAccessible()) + return showErrorAndReturnFalse("Initial RAM file not accessible"); + + try (InputStream initialRAMStream = initialRAMFile.getContents()) + { + MainMemoryParser.parseMemory(mainMemDef, initialRAMStream); + } + catch (IOException e) + { + throw new CoreException( + new Status(IStatus.ERROR, MograsimActivator.PLUGIN_ID, "Unexpected IO exception reading initial RAM file", e)); + } + } + return super.preLaunchCheck(configuration, mode, monitor); } @@ -104,6 +127,7 @@ public class MachineLaunchConfigType extends LaunchConfigurationDelegate MachineContext machineContext = ProjectMachineContext.getMachineContextOf(project); MachineDefinition machineDefinition = machineContext.getMachineDefinition().orElseThrow(); MicroInstructionMemoryDefinition miMemDef = machineDefinition.getMicroInstructionMemoryDefinition(); + MainMemoryDefinition mainMemDef = machineDefinition.getMainMemoryDefinition(); IFile mpmFile = project.getFile(configuration.getAttribute(MPM_FILE_ATTR, "")); @@ -117,10 +141,30 @@ public class MachineLaunchConfigType extends LaunchConfigurationDelegate throw new CoreException(new Status(IStatus.ERROR, MograsimActivator.PLUGIN_ID, "Unexpected IO exception reading MPM file", e)); } - MachineDebugTarget debugTarget = new MachineDebugTarget(new MachineProcess(launch, machineDefinition)); + String initialRAMFileName = configuration.getAttribute(INITIAL_RAM_FILE_ATTR, ""); + MainMemory mem; + if (!"".equals(initialRAMFileName)) + { + IFile initialRAMFile = project.getFile(initialRAMFileName); + try (InputStream initialRAMStream = initialRAMFile.getContents()) + { + mem = MainMemoryParser.parseMemory(mainMemDef, initialRAMStream); + } + catch (IOException e) + { + throw new CoreException( + new Status(IStatus.ERROR, MograsimActivator.PLUGIN_ID, "Unexpected IO exception reading initial RAM file", e)); + } + } else + mem = null; + + MachineDebugTarget debugTarget = new MachineDebugTarget(launch, machineDefinition); + debugTarget.suspend(); debugTarget.setExecutionSpeed(1); Machine machine = debugTarget.getMachine(); machine.getMicroInstructionMemory().bind(mpm); + if (mem != null) + machine.getMainMemory().bind(mem); machine.reset(); }