coding style and #define cleanups

avoid using ull modifyer for consts, use BX_CONST64() instead
move definitions from header file to cpp file when possible
add 'const' modifyer for obviosly const methods and pointers
This commit is contained in:
Shwartsman 2023-11-05 15:35:50 +02:00
parent 83c71dd7a2
commit 5bb77620c3
6 changed files with 63 additions and 70 deletions

View File

@ -30,10 +30,12 @@
#define LOG_THIS theDmaDevice->
#define DMA_MODE_DEMAND 0
#define DMA_MODE_SINGLE 1
#define DMA_MODE_BLOCK 2
#define DMA_MODE_CASCADE 3
enum {
DMA_MODE_DEMAND = 0,
DMA_MODE_SINGLE = 1,
DMA_MODE_BLOCK = 2,
DMA_MODE_CASCADE = 3
};
bx_dma_c *theDmaDevice = NULL;

View File

@ -37,6 +37,23 @@
#include "hpet.h"
/* HPET will set up timers to fire after a certain period of time.
* These values can be used to clamp this period to reasonable/supported values.
* The values are in ticks.
*/
const Bit64u HPET_MAX_ALLOWED_PERIOD = BX_CONST64(0x0400000000000000); // Must not overflow when multiplied by HPET_CLK_PERIOD
const Bit64u HPET_MIN_ALLOWED_PERIOD = BX_CONST64(1);
#define HPET_BASE 0xfed00000
#define HPET_LEN 0x400
#define RTC_ISA_IRQ 8
#define HPET_CLK_PERIOD 10 // 10 ns
#define HPET_ROUTING_CAP BX_CONST64(0xffffff) // allowed irq routing
#define FS_PER_NS 1000000 /* 1000000 femtosectons == 1 ns */
#define LOG_THIS theHPET->
bx_hpet_c *theHPET = NULL;
@ -73,40 +90,40 @@ static Bit32u hpet_time_between(Bit64u start, Bit64u end, Bit64u value)
/* Returns earliest 64-bit tick value that is after reference
* and has same lower 32 bits as value
*/
static Bit64u hpet_cmp32_to_cmp64(Bit64u reference, Bit32u value)
static BX_CPP_INLINE Bit64u hpet_cmp32_to_cmp64(Bit64u reference, Bit32u value)
{
if ((Bit32u)reference <= value) {
return (reference & 0xFFFFFFFF00000000ull) | (Bit64u)value;
return (reference & BX_CONST64(0xFFFFFFFF00000000)) | (Bit64u)value;
} else {
return ((reference + 0x100000000ull) & 0xFFFFFFFF00000000ull) | (Bit64u)value;
return ((reference + BX_CONST64(0x100000000)) & BX_CONST64(0xFFFFFFFF00000000)) | (Bit64u)value;
}
}
static Bit64u ticks_to_ns(Bit64u value)
static BX_CPP_INLINE Bit64u ticks_to_ns(Bit64u value)
{
return value * HPET_CLK_PERIOD;
return value * HPET_CLK_PERIOD;
}
static Bit64u ns_to_ticks(Bit64u value)
static BX_CPP_INLINE Bit64u ns_to_ticks(Bit64u value)
{
return value / HPET_CLK_PERIOD;
return value / HPET_CLK_PERIOD;
}
static Bit64u hpet_fixup_reg(Bit64u _new, Bit64u old, Bit64u mask)
static BX_CPP_INLINE Bit64u hpet_fixup_reg(Bit64u _new, Bit64u old, Bit64u mask)
{
_new &= mask;
_new |= old & ~mask;
return _new;
_new &= mask;
_new |= old & ~mask;
return _new;
}
static int activating_bit(Bit64u old, Bit64u _new, Bit64u mask)
static BX_CPP_INLINE int activating_bit(Bit64u old, Bit64u _new, Bit64u mask)
{
return (!(old & mask) && (_new & mask));
return (!(old & mask) && (_new & mask));
}
static int deactivating_bit(Bit64u old, Bit64u _new, Bit64u mask)
static BX_CPP_INLINE int deactivating_bit(Bit64u old, Bit64u _new, Bit64u mask)
{
return ((old & mask) && !(_new & mask));
return ((old & mask) && !(_new & mask));
}
// static memory read/write functions
@ -241,7 +258,7 @@ Bit64u bx_hpet_c::hpet_get_ticks(void)
/*
* calculate diff between comparator value and current ticks
*/
Bit64u bx_hpet_c::hpet_calculate_diff(HPETTimer *t, Bit64u current)
Bit64u bx_hpet_c::hpet_calculate_diff(const HPETTimer *t, Bit64u current) const
{
if (t->config & HPET_TN_32BIT) {
Bit32u diff, cmp;
@ -360,7 +377,7 @@ void bx_hpet_c::hpet_set_timer(HPETTimer *t)
Bit64u diff = hpet_calculate_diff(t, cur_tick);
if (diff == 0) {
if (t->config & HPET_TN_32BIT) {
diff = 0x100000000ull;
diff = BX_CONST64(0x100000000);
} else {
diff = HPET_MAX_ALLOWED_PERIOD;
}
@ -370,7 +387,7 @@ void bx_hpet_c::hpet_set_timer(HPETTimer *t)
*/
if (!timer_is_periodic(t)) {
if (t->config & HPET_TN_32BIT) {
Bit64u wrap_diff = 0x100000000ull - (Bit64u)(Bit32u)cur_tick;
Bit64u wrap_diff = BX_CONST64(0x100000000) - (Bit64u)(Bit32u)cur_tick;
if (wrap_diff < diff) diff = wrap_diff;
}
}
@ -436,7 +453,7 @@ Bit32u bx_hpet_c::read_aligned(bx_phy_address address)
BX_ERROR(("read: timer id out of range"));
return 0;
}
HPETTimer *timer = &s.timer[id];
const HPETTimer *timer = &s.timer[id];
switch (index & 0x1f) {
case HPET_TN_CFG:
value = (Bit32u)timer->config;

View File

@ -32,21 +32,6 @@
#if BX_SUPPORT_PCI
/* HPET will set up timers to fire after a certain period of time.
* These values can be used to clamp this period to reasonable/supported values.
* The values are in ticks.
*/
#define HPET_MAX_ALLOWED_PERIOD 0x0400000000000000ull // Must not overflow when multiplied by HPET_CLK_PERIOD
#define HPET_MIN_ALLOWED_PERIOD 1
#define RTC_ISA_IRQ 8
#define HPET_BASE 0xfed00000
#define HPET_LEN 0x400
#define HPET_CLK_PERIOD 10 // 10 ns
#define HPET_ROUTING_CAP 0xffffffull // allowed irq routing
#define FS_PER_NS 1000000 /* 1000000 femtosectons == 1 ns */
#define HPET_MIN_TIMERS 3
#define HPET_MAX_TIMERS 32
@ -100,17 +85,17 @@ public:
void write_aligned(bx_phy_address address, Bit32u data, bool trailing_write);
private:
Bit32u hpet_in_legacy_mode(void) {return s.config & HPET_CFG_LEGACY;}
Bit32u timer_int_route(HPETTimer *timer)
Bit32u hpet_in_legacy_mode(void) const { return s.config & HPET_CFG_LEGACY; }
Bit32u timer_int_route(const HPETTimer *timer) const
{
return (timer->config & HPET_TN_INT_ROUTE_MASK) >> HPET_TN_INT_ROUTE_SHIFT;
}
Bit32u timer_fsb_route(HPETTimer *t) {return t->config & HPET_TN_FSB_ENABLE;}
Bit32u hpet_enabled(void) {return s.config & HPET_CFG_ENABLE;}
Bit32u timer_is_periodic(HPETTimer *t) {return t->config & HPET_TN_PERIODIC;}
Bit32u timer_enabled(HPETTimer *t) {return t->config & HPET_TN_ENABLE;}
Bit32u timer_fsb_route(const HPETTimer *t) const { return t->config & HPET_TN_FSB_ENABLE; }
Bit32u hpet_enabled(void) const { return s.config & HPET_CFG_ENABLE; }
Bit32u timer_is_periodic(const HPETTimer *t) const { return t->config & HPET_TN_PERIODIC; }
Bit32u timer_enabled(const HPETTimer *t) const { return t->config & HPET_TN_ENABLE; }
Bit64u hpet_get_ticks(void);
Bit64u hpet_calculate_diff(HPETTimer *t, Bit64u current);
Bit64u hpet_calculate_diff(const HPETTimer *t, Bit64u current) const;
void update_irq(HPETTimer *timer, bool set);
void hpet_set_timer(HPETTimer *t);
void hpet_del_timer(HPETTimer *t);

View File

@ -958,21 +958,11 @@ Bit32u pit_82C54::get_next_event_time(void)
return out;
}
Bit16u pit_82C54::get_inlatch(int counternum)
{
return counter[counternum].inlatch;
}
bool pit_82C54::new_count_ready(int countnum)
bool pit_82C54::new_count_ready(int countnum) const
{
return (counter[countnum].write_state != MSByte_multiple);
}
Bit8u pit_82C54::get_mode(int countnum)
{
return counter[countnum].mode;
}
void pit_82C54::set_OUT_handler(Bit8u counternum, out_handler_t outh)
{
counter[counternum].out_handler = outh;

View File

@ -140,9 +140,9 @@ public:
Bit32u get_clock_event_time(Bit8u cnum);
Bit32u get_next_event_time(void);
Bit16u get_inlatch(int countnum);
bool new_count_ready(int countnum);
Bit8u get_mode(int countnum);
Bit16u get_inlatch(int countnum) const { return counter[countnum].inlatch; }
bool new_count_ready(int countnum) const;
Bit8u get_mode(int countnum) const { return counter[countnum].mode; }
void print_cnum(Bit8u cnum);
};

View File

@ -65,7 +65,7 @@
const Bit64u BX_MAX_VIRTUAL_TIME = BX_CONST64(0x7fffffff);
//Important constant #defines:
#define USEC_PER_SECOND (1000000)
const Bit64u USEC_PER_SECOND = BX_CONST64(1000000);
// define a macro to convert floating point numbers into 64-bit integers.
// In MSVC++ you can convert a 64-bit float into a 64-bit signed integer,
@ -85,7 +85,7 @@ const Bit64u BX_MAX_VIRTUAL_TIME = BX_CONST64(0x7fffffff);
//Minimum number of emulated useconds per second.
// Now calculated using BX_MIN_IPS, the minimum number of
// instructions per second.
#define MIN_USEC_PER_SECOND (((((Bit64u)USEC_PER_SECOND)*((Bit64u)BX_MIN_IPS))/((Bit64u)ips))+(Bit64u)1)
#define MIN_USEC_PER_SECOND (((USEC_PER_SECOND*((Bit64u)BX_MIN_IPS))/((Bit64u)ips))+(Bit64u)1)
//DEBUG configuration:
@ -222,12 +222,12 @@ int bx_virt_timer_c::register_timer(void *this_ptr, bx_timer_handler_t handler,
const char *id)
{
//We don't like starting with a zero period timer.
BX_ASSERT((!active) || (useconds>0));
BX_ASSERT(!active || useconds > 0);
//Search for an unused timer.
unsigned int i;
for (i=0; i < numTimers; i++) {
if ((timer[i].inUse == 0) || (i == numTimers))
if (!timer[i].inUse || (i == numTimers))
break;
}
// If we didn't find a free slot, increment the bound, numTimers.
@ -281,8 +281,7 @@ void bx_virt_timer_c::start_timers(void)
}
//activate a deactivated but registered timer.
void bx_virt_timer_c::activate_timer(unsigned timer_index, Bit32u useconds,
bool continuous)
void bx_virt_timer_c::activate_timer(unsigned timer_index, Bit32u useconds, bool continuous)
{
BX_ASSERT(timer_index < BX_MAX_VIRTUAL_TIMERS);
@ -441,7 +440,7 @@ void bx_virt_timer_c::timer_handler(bool mode)
return;
}
Bit64u usec_delta = bx_pc_system.time_usec()-last_usec;
Bit64u usec_delta = bx_pc_system.time_usec() - last_usec;
if (usec_delta) {
#if BX_HAVE_REALTIME_USEC
@ -463,7 +462,7 @@ void bx_virt_timer_c::timer_handler(bool mode)
// probably only an issue on startup, but it solves some problems.
ticks_delta = 0;
}
if (ticks_delta + total_ticks - last_realtime_ticks > (F2I(MAX_MULT * I2F(last_realtime_delta)))) {
if (ticks_delta + total_ticks - last_realtime_ticks > F2I(MAX_MULT * I2F(last_realtime_delta))) {
//This keeps us from going too fast in relation to real time.
#if 0
ticks_delta = (F2I(MAX_MULT * I2F(last_realtime_delta))) + last_realtime_ticks - total_ticks;
@ -509,10 +508,10 @@ void bx_virt_timer_c::timer_handler(bool mode)
if (real_time_delta) {
//FIXME
Bit64u em_realtime_delta = last_system_usec + stored_delta - em_last_realtime;
b=((Bit64u)USEC_PER_SECOND * em_realtime_delta / real_time_delta);
b = (USEC_PER_SECOND * em_realtime_delta / real_time_delta);
em_last_realtime = last_system_usec + stored_delta;
} else {
b=a;
b = a;
}
usec_per_second = ALPHA_LOWER(a,b);
#else
@ -523,7 +522,7 @@ void bx_virt_timer_c::timer_handler(bool mode)
#endif
}
last_usec=last_usec + usec_delta;
last_usec += usec_delta;
bx_pc_system.deactivate_timer(s[1].system_timer_id);
BX_ASSERT(s[1].virtual_next_event_time);
bx_pc_system.activate_timer(s[1].system_timer_id,