From a5fc4258e37df6e64b09ee814401c6ac7793bd7e Mon Sep 17 00:00:00 2001 From: Daniel Kirschten Date: Mon, 30 Sep 2019 14:07:55 +0200 Subject: [PATCH] Lauch configuration attribute "Initial RAM" now has an effect --- .../launch/MachineLaunchConfigType.java | 45 +++++++++++++++++-- 1 file changed, 41 insertions(+), 4 deletions(-) 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 2c2c19c4..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; @@ -69,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()) @@ -87,7 +91,23 @@ public class MachineLaunchConfigType extends LaunchConfigurationDelegate throw new CoreException(new Status(IStatus.ERROR, MograsimActivator.PLUGIN_ID, "Unexpected IO exception reading MPM file", e)); } - // TODO parse RAM + 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); } @@ -107,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, "")); @@ -120,14 +141,30 @@ public class MachineLaunchConfigType extends LaunchConfigurationDelegate throw new CoreException(new Status(IStatus.ERROR, MograsimActivator.PLUGIN_ID, "Unexpected IO exception reading MPM file", e)); } - // TODO parse RAM + 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); - // TODO bind RAM + if (mem != null) + machine.getMainMemory().bind(mem); machine.reset(); } -- 2.17.1