base: avoid implicit conversions

This patch is a prerequisite for compiling the code with
the warnings -Wconversion enabled.

Issue #23
This commit is contained in:
Norman Feske
2021-12-02 11:21:14 +01:00
parent c79a59655d
commit 03047009b1
189 changed files with 947 additions and 819 deletions

View File

@ -23,7 +23,7 @@ using namespace Genode;
void Timer::Time_source::set_timeout(Genode::Microseconds duration,
Genode::Timeout_handler &handler)
{
unsigned long const ticks = (1ULL * duration.value * TICKS_PER_MS) / 1000;
unsigned long const ticks = (unsigned long)((1ULL * duration.value * TICKS_PER_MS) / 1000);
_handler = &handler;
_timer_irq.ack_irq();
_cleared_ticks = 0;

View File

@ -17,6 +17,9 @@
#include <util/misc_math.h>
#include <base/attached_rom_dataspace.h>
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
/* Fiasco includes */
namespace Fiasco {
#include <l4/sys/ipc.h>
@ -34,6 +37,7 @@ namespace Fiasco {
#include <l4/sys/kernel.h>
}
#endif /* L4_SYS_KIP_H__ */
#pragma GCC diagnostic pop
/* local includes */
#include <time_source.h>
@ -52,17 +56,20 @@ static l4_timeout_s mus_to_timeout(uint64_t mus)
return L4_IPC_TIMEOUT_NEVER;
long e = Genode::log2((unsigned long)mus) - 7;
unsigned long m;
if (e < 0) e = 0;
m = mus / (1UL << e);
uint64_t m = mus / (1UL << e);
enum { M_MASK = 0x3ff };
/* check corner case */
if ((e > 31 ) || (m > 1023)) {
if ((e > 31 ) || (m > M_MASK)) {
Genode::warning("invalid timeout ", mus, ", using max. values");
e = 0;
m = 1023;
m = M_MASK;
}
return l4_timeout_rel(m, e);
return l4_timeout_rel(m & M_MASK, (unsigned)e);
}

View File

@ -21,10 +21,10 @@ void Timer::Time_source::set_timeout(Genode::Microseconds duration,
Timeout_handler &handler)
{
_handler = &handler;
/* set to minimum ticks value to not miss a too short timeout */
Genode::uint32_t const ticks =
Genode::max(1UL, (duration.value * TICKS_PER_MS) / 1000);
uint32_t const ticks =
max((uint32_t)1, (uint32_t)((duration.value * TICKS_PER_MS) / 1000));
/* clear interrupts */
if (read<Sr>()) {
@ -40,15 +40,14 @@ void Timer::Time_source::set_timeout(Genode::Microseconds duration,
Duration Timer::Time_source::curr_time()
{
Cnt::access_t cur_cnt = read<Cnt>();
Genode::Microseconds us(timer_ticks_to_us(cur_cnt - _last_cnt,
TICKS_PER_MS));
Genode::Microseconds us(timer_ticks_to_us(cur_cnt - _last_cnt, TICKS_PER_MS));
_last_cnt = cur_cnt;
_curr_time.add(us);
return _curr_time;
}
Genode::Microseconds Timer::Time_source::max_timeout() const
Microseconds Timer::Time_source::max_timeout() const
{
static unsigned long max = timer_ticks_to_us(0xffffffff, TICKS_PER_MS);
return Genode::Microseconds(max);

View File

@ -24,8 +24,8 @@ using namespace Genode;
void Timer::Time_source::_set_counter(uint16_t value)
{
_handled_wrap = false;
_io_port.outb(PIT_DATA_PORT_0, value & 0xff);
_io_port.outb(PIT_DATA_PORT_0, (value >> 8) & 0xff);
_io_port.outb(PIT_DATA_PORT_0, (uint8_t)(value & 0xff));
_io_port.outb(PIT_DATA_PORT_0, (uint8_t)((value >> 8) & 0xff));
}
@ -45,7 +45,7 @@ uint16_t Timer::Time_source::_read_counter(bool *wrapped)
uint16_t hi = _io_port.inb(PIT_DATA_PORT_0);
*wrapped = status & PIT_STAT_INT_LINE ? true : false;
return (hi << 8) | lo;
return (uint16_t)((hi << 8) | lo);
}
@ -69,7 +69,7 @@ void Timer::Time_source::set_timeout(Microseconds duration,
duration_us = max_timeout().value;
}
_counter_init_value = (PIT_TICKS_PER_MSEC * duration_us) / 1000;
_counter_init_value = (uint16_t)((PIT_TICKS_PER_MSEC * duration_us) / 1000);
_set_counter(_counter_init_value);
if (duration.value)