public static void Main(string[] args) { CancellationTokenSource tokenSource = new CancellationTokenSource(); //Display logging messages in console Trace.Listeners.Add(new TextWriterTraceListener(Console.Out)); new Thread(() => { CPUCore.Start(tokenSource.Token); }).Start(); Console.WriteLine("Press 'A' to abort"); while (true) { ConsoleKeyInfo keyInfo = Console.ReadKey(intercept: true); if (keyInfo.Key == ConsoleKey.A) { tokenSource.Cancel(); break; } } Console.WriteLine("Terminated"); Thread.Sleep(1000); Debug.Write("Terminated"); }
// Start is called before the first frame update void Start() { // Fetch the display print("Getting graphics view!"); GameObject uiview = GameObject.FindWithTag("VirtualDisplay"); VirtualDisplayHAL display = uiview.GetComponent <VirtualDisplayHAL>(); // Create and launch a system! print("Building system components"); CPUCore mainCore = gameObject.AddComponent <CPUCore>(); ALU alu0 = gameObject.AddComponent <ALU>(); Memory ram = gameObject.AddComponent <Memory>(); CPU processor = gameObject.AddComponent <CPU>(); print("Building boot disk!"); Memory bootDisk = getBootDisk(); print("Building RAM!"); ram.Instantiate(1024); print("Building CORE0"); alu0.Instantiate(mainCore); mainCore.setALU(alu0); print("Building CPU"); processor.Instantiate(new CPUCore[] { mainCore }, ram, bootDisk, display); mainCore.setParent(processor); print("Booting!"); processor.bootup(); }
// Virtual System Methods private void vga_int_handler(CPUCore core) { uint task = core.readRegister(REGISTERS.GENERAL_0); if (task == 0x1) { // Set pixel! uint x = core.readRegister(REGISTERS.GENERAL_1); uint y = core.readRegister(REGISTERS.GENERAL_2); uint r = core.readRegister(REGISTERS.GENERAL_4); uint g = core.readRegister(REGISTERS.GENERAL_5); uint b = core.readRegister(REGISTERS.GENERAL_6); if (this.display != null) { this.display.set_pixel((int)x, (int)y, (int)r, (int)g, (int)b); } } else if (task == 0x03) { print("Telling them the resolution is (" + display.getWidth() + "," + display.getHeight() + ")!"); core.writeRegister(REGISTERS.GENERAL_1, (uint)display.getWidth()); core.writeRegister(REGISTERS.GENERAL_2, (uint)display.getHeight()); } }
public void call_interrupt(CPUCore core, uint address) { print("INTERRUPT " + address + " called!"); if (address == 0x10) { // VGA! vga_int_handler(core); } }
public HitTestResult(BuildHost host, CPUCore core, BuildEvent ev) { _host = host; _core = core; _event = ev; }
public void Start(CPUCore core) { _core = core; _brush = _sRunningBrush; _toolTipText = "BUILDING: " + _name.Replace("\"", ""); }
public void OnStartEvent(BuildEvent newEvent) { bool bAssigned = false; for (int i = 0; i < _cores.Count; ++i) { if (_cores[i].ScheduleEvent(newEvent)) { //Console.WriteLine("START {0} (Core {1}) [{2}]", _name, i, newEvent._name); bAssigned = true; break; } } // we discovered a new core if (!bAssigned) { CPUCore core = new CPUCore(this, _cores.Count); core.ScheduleEvent(newEvent); //Console.WriteLine("START {0} (Core {1}) [{2}]", _name, _cores.Count, newEvent._name); _cores.Add(core); } }
/// <summary> /// Thread loop for each worker. /// </summary> private void WorkerThreadMain() { // find my index int workerIndex = -1; for (var i = 0; i < _threads.Length; i++) { if (Thread.CurrentThread == _threads[i]) { workerIndex = i; break; } } if (workerIndex == -1) { return; } // force processor selector if available CPUCore.SetThreadProcessor(workerIndex); // set the name for vs.net debugging Thread.CurrentThread.Name = "Worker #" + workerIndex; // TODO: allow shutdown politely to be registered with ThreadManager and have it call stop ThreadManager.Current.Register(Thread.CurrentThread); try { try { // work until it's quittin' time while (Running) { // run this task var nextTask = _work[workerIndex]; if (nextTask != null) { try { #if DEBUG_TASKS Util.LPConsole.WriteLine("Worker #" + workerIndex, nextTask.ToString()); #endif nextTask.RunTask(); } catch (Exception ex) { Session.UserSession.Current.Console.Add("UNCAUGHT EXCEPTION IN TASK: " + ex.Message, "Kernel"); } } // block until there's more work lock (_workerDoneSignal) { _work[workerIndex] = null; Monitor.PulseAll(_workerDoneSignal); } lock (_newWorkSignal) { while (_work[workerIndex] == null) { Thread.Sleep(0); Monitor.Wait(_newWorkSignal, 100); } } } } catch (ThreadAbortException) { } catch (Exception ex) { Session.UserSession.Current.Console.Add("KERNEL PANIC: " + ex.Message, "Kernel"); } } finally { ThreadManager.Current.Unregister(Thread.CurrentThread); } }
private void Initialize() { registers = new RegistersCPU(); core = new CPUCore(registers); }
// Constructor public void Instantiate(CPUCore parent) { this.parent = parent; }