Skip to content

Commit

Permalink
Fixed keyboard interrupt when doing int 0x14 causing interrupt routin…
Browse files Browse the repository at this point in the history
…e early return
  • Loading branch information
Anivice committed Jan 23, 2025
1 parent cb3a58b commit 0d909f1
Show file tree
Hide file tree
Showing 12 changed files with 284 additions and 65 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Sysdarft
![Lines of Code](https://img.shields.io/badge/ProjectLines-29066-cyan)
![Size of Code](https://img.shields.io/badge/ProjectSize-1412%20K-yellow)
![Lines of Code](https://img.shields.io/badge/ProjectLines-46524-cyan)
![Size of Code](https://img.shields.io/badge/ProjectSize-5128%20K-yellow)
[![Automated CMake Test Workflow](https://github.com/Anivice/Sysdarft/actions/workflows/CMake_GitHub_Action.yml/badge.svg)](https://github.com/Anivice/Sysdarft/actions/workflows/CMake_GitHub_Action.yml)

Sysdarft is a hypothetical binary 64bit architecture.
Expand Down
Binary file added doc/BitAndByteOrder.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/BitAndByteOrder.xcf
Binary file not shown.
280 changes: 222 additions & 58 deletions doc/Sysdarft.md

Large diffs are not rendered by default.

42 changes: 42 additions & 0 deletions doc/references.bib
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,45 @@ @book{ComputerScienceIlluminated
year = {2012},
publisher = {Jones & Bartlett Learning}
}

@book{TheJargonFile,
title = {The Jargon File, version 4.4.7},
author = {Eric Raymond},
year = {2003},
publisher = {Public Domain}
}

@book{LinuxDeviceDriversThirdEdition,
title = {Linux Device Drivers, Third Edition},
author = {Jonathan Corbet; Alessandro Rubini; Greg Kroah-Hartman},
year = {2005},
publisher = {O'Reilly Media}
}

@book{Intel64AndIA32ArchitecturesSoftwareDevelopersManualCombinedVolumes,
title = {Intel® 64 and IA-32 Architectures Software Developer’s Manual Combined Volumes: 1, 2A, 2B, 2C, 2D, 3A, 3B, 3C, 3D, and 4},
author = {Intel},
year = {2024},
publisher = {© Intel Corporation}
}

@book{OxfordEnglishDictionary,
title = {Oxford English Dictionary 7th Edition},
author = {Oxford University Press},
year = {2013},
publisher = {Oxford University Press}
}

@book{GulliversTravels,
title = {Travels into Several Remote Nations of the World. In Four Parts. By Lemuel Gulliver, First a Surgeon, and then a Captain of Several Ships},
author = {Jonathan Swift},
year = {1726},
publisher = {Public Domain}
}

@book{OnHolyWarsAndAPleaForPeace,
title = {On Holy Wars and a Plea for Peace},
author = {Danny Cohen},
year = {1981},
publisher = {IEEE Computer}
}
Binary file modified doc/stack.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/stack.xcf
Binary file not shown.
17 changes: 14 additions & 3 deletions src/cpu/SysdarftCPUInterruption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ SysdarftCPUInterruption::SysdarftCPUInterruption(const uint64_t memory) :

void SysdarftCPUInterruption::do_interruption(const uint64_t code)
{
if (code > MAX_INTERRUPTION_ENTRY) {
throw SysdarftBadInterruption("Interruption out of range");
}

auto fg = SysdarftRegister::load<FlagRegisterType>();

auto mask_fg = [&]()
Expand Down Expand Up @@ -119,7 +123,7 @@ void SysdarftCPUInterruption::do_interruption(const uint64_t code)

void SysdarftCPUInterruption::do_ext_dev_interruption(const uint64_t code)
{
if (code > 0x1F && code < 512)
if (code > 0x1F && code < MAX_INTERRUPTION_ENTRY)
{
if (!protector.try_lock()) {
return; // ignore this interruption, the system is currently masked
Expand Down Expand Up @@ -244,10 +248,17 @@ void SysdarftCPUInterruption::do_interruption_newline_0x13()

void SysdarftCPUInterruption::do_interruption_getinput_0x14()
{
char ch;
while (!SystemHalted && !do_abort_int)
char ch = 0;
while (!SystemHalted)
// abort if external halt or device interruption triggered
{
if (do_abort_int)
{
// revert ip to int <$(0x14)>
SysdarftRegister::store<InstructionPointerType>(ip_before_pop);
return;
}

if (input_source != 0) {
SysdarftRegister::store<ExtendedRegisterType, 0>(input_source);
input_source = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/cpu/SysdarftInstructionExec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void SysdarftCPUInstructionExecutor::execute(const __uint128_t timestamp)
try {
try
{
const auto ip_before_pop = SysdarftRegister::load<InstructionPointerType>();
ip_before_pop = SysdarftRegister::load<InstructionPointerType>();
const bool breakpoint_reached = is_break_here(timestamp);

const auto &[opcode, width, operands, literal]
Expand Down
2 changes: 1 addition & 1 deletion src/ext_dev/RealTimeClock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void SysdarftRealTimeClock::update_time(std::atomic < bool > & running)
} else {
scale_count = interruption_scale;
try {
if (interruption_number > 0x1F && interruption_number < 512) {
if (interruption_number > 0x1F && interruption_number < MAX_INTERRUPTION_ENTRY) {
m_cpu.do_ext_dev_interruption(interruption_number);
}
} catch (...) {
Expand Down
1 change: 1 addition & 0 deletions src/include/SysdarftCPUDecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ class SYSDARFT_EXPORT_SYMBOL SysdarftCPUInterruption : public DecoderDataAccess
std::atomic < bool > external_device_requested = false;
std::atomic < uint64_t > current_routine_pop_len = 0;
std::atomic < int > input_source = 0;
std::atomic < uint64_t > ip_before_pop = 0;

struct InterruptionPointer {
uint64_t InterruptionTargetCodeBase;
Expand Down
1 change: 1 addition & 0 deletions src/include/SysdarftMemory.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#define INTERRUPTION_VECTOR (0xA0000)
#define INTERRUPTION_VEC_ED (0xA0FFF)
#define INTERRUPTION_VEC_LN (INTERRUPTION_VEC_ED - INTERRUPTION_VECTOR + 1)
#define MAX_INTERRUPTION_ENTRY (INTERRUPTION_VEC_LN / (sizeof(uint64_t) * 2))
#define VIDEO_MEMORY_START (0xB8000)
#define VIDEO_MEMORY_END (0xB87CF)
#define VIDEO_MEMORY_SIZE (VIDEO_MEMORY_END - VIDEO_MEMORY_START + 1)
Expand Down

0 comments on commit 0d909f1

Please sign in to comment.