1
0
mirror of https://github.com/TomHarte/CLK.git synced 2026-04-20 10:17:05 +00:00

Attempt to support reset-by-8042, resulting in boot loop.

This commit is contained in:
Thomas Harte
2025-03-08 00:47:56 -05:00
parent 7a88d31fd9
commit 98f20c57c1
5 changed files with 88 additions and 12 deletions
+45
View File
@@ -0,0 +1,45 @@
//
// CPUControl.hpp
// Clock Signal
//
// Created by Thomas Harte on 08/03/2025.
// Copyright © 2025 Thomas Harte. All rights reserved.
//
#pragma once
#include "Memory.hpp"
#include "ProcessorByModel.hpp"
#include "Registers.hpp"
#include "Segments.hpp"
#include "Analyser/Static/PCCompatible/Target.hpp"
namespace PCCompatible {
template <Analyser::Static::PCCompatible::Model model>
class CPUControl {
public:
CPUControl(
Registers<processor_model(model)> &registers,
Segments<processor_model(model)> &segments,
Memory<model> &memory
) : registers_(registers), segments_(segments), memory_(memory) {}
void reset() {
registers_.reset();
segments_.reset();
}
void set_a20_enabled(bool) {
// Assumed: this'll be something to set on Memory.
}
private:
Registers<processor_model(model)> &registers_;
Segments<processor_model(model)> &segments_;
Memory<model> &memory_;
};
}
+35 -10
View File
@@ -8,6 +8,7 @@
#pragma once
#include "CPUControl.hpp"
#include "PIC.hpp"
#include "Speaker.hpp"
@@ -92,6 +93,8 @@ public:
pics_.pic[0].template apply_edge<1>(true);
}
void set_cpu_control(CPUControl<model> *) {}
private:
enum class Mode {
NormalOperation = 0b01,
@@ -117,7 +120,11 @@ public:
void run_for([[maybe_unused]] const Cycles cycles) {
}
void post([[maybe_unused]] const uint8_t value) {
void post(const uint8_t value) {
parameter_ = value;
has_input_ = true;
is_command_ = false;
pics_.pic[0].template apply_edge<1>(true);
}
void write(const uint16_t port, const uint8_t value) {
@@ -141,11 +148,6 @@ public:
case 0x0064:
is_command_ = true;
const auto set_input = [&](const uint8_t input) {
parameter_ = input;
has_input_ = true;
is_command_ = false;
};
auto info = log_.info();
info.append("AT keyboard command %04x", value);
@@ -156,10 +158,23 @@ public:
case 0xaa: // Self-test; 0x55 => no issues found.
log_.error().append("Keyboard self-test");
set_input(0x55);
post(0x55);
break;
case 0xd1: // Set output byte. b0 = the A20 gate.
case 0xd1: // Set output byte. b1 = the A20 gate.
log_.error().append("Should set A20 gate: %d", value & 0x02);
cpu_control_->set_a20_enabled(value & 0x02);
break;
case 0xf0: case 0xf1: case 0xf2: case 0xf3:
case 0xf4: case 0xf5: case 0xf6: case 0xf7:
case 0xf8: case 0xf9: case 0xfa: case 0xfb:
case 0xfc: case 0xfd: case 0xfe: case 0xff:
log_.error().append("Should reset: %x", value & 0x0f);
if(!(value & 1)) {
cpu_control_->reset();
}
break;
}
break;
@@ -167,7 +182,7 @@ public:
}
template <typename IntT>
IntT read([[maybe_unused]] const uint16_t port) {
IntT read(const uint16_t port) {
switch(port) {
default:
log_.error().append("Unimplemented AT keyboard read from %04x", port);
@@ -175,7 +190,10 @@ public:
case 0x0060:
log_.error().append("Read keyboard parameter of %02x", parameter_);
has_input_ = false;
// TODO: disabled in response to BIOS expectations but possibly a false
// positive because commands are responded to instantly?
// has_input_ = false;
return parameter_;
case 0x0061:
@@ -198,6 +216,7 @@ public:
// b1 = 1 => 'input' buffer full (i.e. don't write 0x60 or 0x64 now — this is input to the controller);
// b0 = 1 => 'output' data is full (i.e. reading from 0x60 now makes sense — output is to PC).
const uint8_t status =
0x10 |
(is_command_ ? 0x08 : 0x00) |
(has_output_ ? 0x02 : 0x00) |
(has_input_ ? 0x01 : 0x00);
@@ -208,11 +227,17 @@ public:
return IntT(~0);
}
void set_cpu_control(CPUControl<model> *const control) {
cpu_control_ = control;
}
private:
Log::Logger<Log::Source::PCCompatible> log_;
PICs<model> &pics_;
Speaker &speaker_;
CPUControl<model> *cpu_control_ = nullptr;
uint8_t refresh_toggle_ = 0;
bool has_input_ = false;
+5 -2
View File
@@ -9,6 +9,7 @@
#include "PCCompatible.hpp"
#include "CGA.hpp"
#include "CPUControl.hpp"
#include "DMA.hpp"
#include "FloppyController.hpp"
#include "KeyboardController.hpp"
@@ -884,14 +885,15 @@ private:
segments(registers),
memory(registers, segments),
flow_controller(registers, segments),
cpu_control(registers, segments, memory),
io(pit, dma, ppi, pics, card, fdc, keyboard, rtc)
{
keyboard.set_cpu_control(&cpu_control);
reset();
}
void reset() {
registers.reset();
segments.reset();
cpu_control.reset();
}
InstructionSet::x86::Flags flags;
@@ -899,6 +901,7 @@ private:
Segments<x86_model> segments;
Memory<pc_model> memory;
FlowController<pc_model> flow_controller;
CPUControl<pc_model> cpu_control;
IO<pc_model, video> io;
static constexpr auto model = processor_model(pc_model);
} context_;
+1
View File
@@ -9,6 +9,7 @@
#pragma once
#include "InstructionSets/x86/Model.hpp"
#include "Numeric/RegisterSizes.hpp"
namespace PCCompatible {
@@ -1457,6 +1457,7 @@
4B1FBE222D7B739700BAC888 /* FloppyController.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = FloppyController.hpp; sourceTree = "<group>"; };
4B1FBE232D7B73C800BAC888 /* Speaker.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = Speaker.hpp; sourceTree = "<group>"; };
4B1FBE242D7B753000BAC888 /* KeyboardController.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = KeyboardController.hpp; sourceTree = "<group>"; };
4B1FBE252D7C0B2200BAC888 /* CPUControl.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = CPUControl.hpp; sourceTree = "<group>"; };
4B2005402B804AA300420C5C /* OperationMapper.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = OperationMapper.hpp; sourceTree = "<group>"; };
4B2005422B804D6400420C5C /* ARMDecoderTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ARMDecoderTests.mm; sourceTree = "<group>"; };
4B2005462B8BD7A500420C5C /* Registers.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = Registers.hpp; sourceTree = "<group>"; };
@@ -2560,6 +2561,7 @@
children = (
425739372B051EA800B7D1E4 /* PCCompatible.cpp */,
429B13632B20234B006BB4CB /* CGA.hpp */,
4B1FBE252D7C0B2200BAC888 /* CPUControl.hpp */,
4267A9C92B0D4F17008A59BB /* DMA.hpp */,
4B1FBE222D7B739700BAC888 /* FloppyController.hpp */,
4B1FBE242D7B753000BAC888 /* KeyboardController.hpp */,