Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

machine/icd2061a: Fix out of bounds array access #12207

Merged
merged 2 commits into from
Apr 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions src/devices/machine/icd2061a.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@

#define LOG_PINS (1 << 1)
#define LOG_STATE (1 << 2)
#define LOG_TODO (1 << 3)

// #define VERBOSE (LOG_GENERAL | LOG_PINS | LOG_STATE)
// #define VERBOSE (LOG_GENERAL | LOG_PINS | LOG_STATE | LOG_TODO)
#define VERBOSE (LOG_TODO)

#include "logmacro.h"

#define LOGTODO(...) LOGMASKED(LOG_TODO, __VA_ARGS__)


DEFINE_DEVICE_TYPE(ICD2061A, icd2061a_device, "icd2061a", "IC Designs 2061A Dual Programmable Graphics Clock Generator")

Expand Down Expand Up @@ -168,6 +172,8 @@ TIMER_CALLBACK_MEMBER( icd2061a_device::update_clock_callback )
const int m = BIT(m_regs[MREG], 7, 3); // post-vco divisor
const int q = BIT(m_regs[MREG], 0, 7) + 2; // q counter value
m_reg_clocks[MREG] = (clock() * m_prescale[a] * (p / double(q))) / (1 << m);
} else {
LOGTODO("unimplemented mclkout selected %d\n", m_mclkout_select);
}

if (m_reg_clocks[MREG] != m_mclkout_clock) {
Expand All @@ -189,18 +195,23 @@ TIMER_CALLBACK_MEMBER( icd2061a_device::update_clock_callback )
else if (m_outdis == 1 && m_pwrdwn == 1 && m_sel1 == 1 && (m_intclk == 1 || m_sel0 == 1))
m_vclkout_select = VCLKOUT_REG2;

uint32_t vclkout_clock = m_vclkout_clock;
if (m_vclkout_select == VCLKOUT_FEATCLK) {
m_reg_clocks[m_vclkout_select] = m_featclock;
vclkout_clock = m_featclock;
} else if (m_vclkout_select >= VCLKOUT_REG0 && m_vclkout_select <= VCLKOUT_REG2) {
const int a = BIT(m_regs[m_vclkout_select], 21, 2); // register addr
const int p = BIT(m_regs[m_vclkout_select], 10, 7) + 3; // p counter value
const int m = BIT(m_regs[m_vclkout_select], 7, 3); // post-vco divisor
const int q = BIT(m_regs[m_vclkout_select], 0, 7) + 2; // q counter value
m_reg_clocks[m_vclkout_select] = (clock() * m_prescale[a] * (p / double(q))) / (1 << m);
vclkout_clock = m_reg_clocks[m_vclkout_select] = (clock() * m_prescale[a] * (p / double(q))) / (1 << m);
} else {
LOGTODO("unimplemented vclkout selected %d\n", m_vclkout_select);
}

m_vclkout_changed_cb(m_reg_clocks[m_vclkout_select]);
m_vclkout_clock = m_reg_clocks[m_vclkout_select];
if (vclkout_clock != m_vclkout_clock) {
m_vclkout_clock = vclkout_clock;
m_vclkout_changed_cb(vclkout_clock);
}
}

void icd2061a_device::update_clock()
Expand Down