Skip to content

Commit

Permalink
Added gettimeofday() implementation - Upstream 828566b
Browse files Browse the repository at this point in the history
  • Loading branch information
gdwnldsKSC committed Aug 8, 2024
1 parent ec9e9f0 commit 4b05b62
Show file tree
Hide file tree
Showing 30 changed files with 1,224 additions and 656 deletions.
1 change: 1 addition & 0 deletions WinQemu.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@
</PrecompiledHeader>
<CompileAsManaged Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</CompileAsManaged>
</ClCompile>
<ClCompile Include="gettimeofday.c" />
<ClCompile Include="outside_qemu_tree_custom\clock_gettime.c" />
<ClCompile Include="outside_qemu_tree_custom\FAKE_KVM_FUNCTIONS.c" />
<ClCompile Include="outside_qemu_tree_custom\XGetopt.c" />
Expand Down
3 changes: 3 additions & 0 deletions WinQemu.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -1272,6 +1272,9 @@
<ClCompile Include="qemu\check-qstring.c">
<Filter>qemu\src</Filter>
</ClCompile>
<ClCompile Include="gettimeofday.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="float80-port.h">
Expand Down
32 changes: 32 additions & 0 deletions gettimeofday.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Source: https://stackoverflow.com/questions/10905892/equivalent-of-gettimeofday-for-windows

#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <stdint.h> // portable: uint64_t MSVC: __int64

// MSVC defines this in winsock2.h!?
typedef struct timeval {
long tv_sec;
long tv_usec;
} timeval;

int gettimeofday(struct timeval* tp, struct timezone* tzp)
{
// Note: some broken versions only have 8 trailing zero's, the correct epoch has 9 trailing zero's
// This magic number is the number of 100 nanosecond intervals since January 1, 1601 (UTC)
// until 00:00:00 January 1, 1970
static const uint64_t EPOCH = ((uint64_t)116444736000000000ULL);

SYSTEMTIME system_time;
FILETIME file_time;
uint64_t time;

GetSystemTime(&system_time);
SystemTimeToFileTime(&system_time, &file_time);
time = ((uint64_t)file_time.dwLowDateTime);
time += ((uint64_t)file_time.dwHighDateTime) << 32;

tp->tv_sec = (long)((time - EPOCH) / 10000000L);
tp->tv_usec = (long)(system_time.wMilliseconds * 1000);
return 0;
}
61 changes: 29 additions & 32 deletions qemu/arm-dis.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,12 @@
*/

#include "dis-asm.h"
#define FALSE 0
#define TRUE (!FALSE)

#ifndef _MSC_VER
#define ATTRIBUTE_UNUSED __attribute__((unused))
#else
#define ATTRIBUTE_UNUSED
#endif

#define ISSPACE(x) ((x) == ' ' || (x) == '\t' || (x) == '\n')

#define ARM_EXT_V1 0
Expand Down Expand Up @@ -1547,7 +1544,7 @@ static unsigned int regname_selected = 1;
#define NUM_ARM_REGNAMES NUM_ELEM (regnames)
#define arm_regnames regnames[regname_selected].reg_names

static bfd_boolean force_thumb = FALSE;
static bfd_boolean force_thumb = false;

/* Current IT instruction state. This contains the same state as the IT
bits in the CPSR. */
Expand Down Expand Up @@ -1644,7 +1641,7 @@ arm_decode_shift (long given, fprintf_ftype func, void *stream,
}

/* Print one coprocessor instruction on INFO->STREAM.
Return TRUE if the instuction matched, FALSE if this is not a
Return true if the instuction matched, false if this is not a
recognised coprocessor instruction. */

static bfd_boolean
Expand Down Expand Up @@ -2137,10 +2134,10 @@ print_insn_coprocessor (bfd_vma pc, struct disassemble_info *info, long given,
else
func (stream, "%c", *c);
}
return TRUE;
return true;
}
}
return FALSE;
return false;
}

static void
Expand Down Expand Up @@ -2234,7 +2231,7 @@ print_arm_address (bfd_vma pc, struct disassemble_info *info, long given)
}

/* Print one neon instruction on INFO->STREAM.
Return TRUE if the instuction matched, FALSE if this is not a
Return true if the instuction matched, false if this is not a
recognised neon instruction. */

static bfd_boolean
Expand All @@ -2260,7 +2257,7 @@ print_insn_neon (struct disassemble_info *info, long given, bfd_boolean thumb)
else if ((given & 0xff000000) == 0xf9000000)
given ^= 0xf9000000 ^ 0xf4000000;
else
return FALSE;
return false;
}

for (insn = neon_opcodes; insn->assembler; insn++)
Expand Down Expand Up @@ -2350,34 +2347,34 @@ print_insn_neon (struct disassemble_info *info, long given, bfd_boolean thumb)
{
int amask = (1 << size) - 1;
if ((idx_align & (1 << size)) != 0)
return FALSE;
return false;
if (size > 0)
{
if ((idx_align & amask) == amask)
align = 8 << size;
else if ((idx_align & amask) != 0)
return FALSE;
return false;
}
}
break;

case 2:
if (size == 2 && (idx_align & 2) != 0)
return FALSE;
return false;
align = (idx_align & 1) ? 16 << size : 0;
break;

case 3:
if ((size == 2 && (idx_align & 3) != 0)
|| (idx_align & 1) != 0)
return FALSE;
return false;
break;

case 4:
if (size == 2)
{
if ((idx_align & 3) == 3)
return FALSE;
return false;
align = (idx_align & 3) * 64;
}
else
Expand Down Expand Up @@ -2686,10 +2683,10 @@ print_insn_neon (struct disassemble_info *info, long given, bfd_boolean thumb)
else
func (stream, "%c", *c);
}
return TRUE;
return true;
}
}
return FALSE;
return false;
}

/* Print one ARM instruction from PC on INFO->STREAM. */
Expand All @@ -2701,10 +2698,10 @@ print_insn_arm_internal (bfd_vma pc, struct disassemble_info *info, long given)
void *stream = info->stream;
fprintf_ftype func = info->fprintf_func;

if (print_insn_coprocessor (pc, info, given, FALSE))
if (print_insn_coprocessor (pc, info, given, false))
return;

if (print_insn_neon (info, given, FALSE))
if (print_insn_neon (info, given, false))
return;

for (insn = arm_opcodes; insn->assembler; insn++)
Expand Down Expand Up @@ -3337,10 +3334,10 @@ print_insn_thumb32 (bfd_vma pc, struct disassemble_info *info, long given)
void *stream = info->stream;
fprintf_ftype func = info->fprintf_func;

if (print_insn_coprocessor (pc, info, given, TRUE))
if (print_insn_coprocessor (pc, info, given, true))
return;

if (print_insn_neon (info, given, TRUE))
if (print_insn_neon (info, given, true))
return;

for (insn = thumb32_opcodes; insn->assembler; insn++)
Expand Down Expand Up @@ -3475,7 +3472,7 @@ print_insn_thumb32 (bfd_vma pc, struct disassemble_info *info, long given)
unsigned int op = (given & 0x00000f00) >> 8;
unsigned int i12 = (given & 0x00000fff);
unsigned int i8 = (given & 0x000000ff);
bfd_boolean writeback = FALSE, postind = FALSE;
bfd_boolean writeback = false, postind = false;
int offset = 0;

func (stream, "[%s", arm_regnames[Rn]);
Expand Down Expand Up @@ -3505,22 +3502,22 @@ print_insn_thumb32 (bfd_vma pc, struct disassemble_info *info, long given)

case 0xF: /* 8-bit + preindex with wb */
offset = i8;
writeback = TRUE;
writeback = true;
break;

case 0xD: /* 8-bit - preindex with wb */
offset = -i8;
writeback = TRUE;
writeback = true;
break;

case 0xB: /* 8-bit + postindex */
offset = i8;
postind = TRUE;
postind = true;
break;

case 0x9: /* 8-bit - postindex */
offset = -i8;
postind = TRUE;
postind = true;
break;

default:
Expand Down Expand Up @@ -3893,12 +3890,12 @@ print_insn_arm (bfd_vma pc, struct disassemble_info *info)
unsigned char b[4];
long given;
int status;
int is_thumb = FALSE;
int is_data = FALSE;
int is_thumb = false;
int is_data = false;
unsigned int size = 4;
void (*printer) (bfd_vma, struct disassemble_info *, long);
#if 0
bfd_boolean found = FALSE;
bfd_boolean found = false;

if (info->disassembler_options)
{
Expand All @@ -3921,7 +3918,7 @@ print_insn_arm (bfd_vma pc, struct disassemble_info *info)
if (pc <= last_mapping_addr)
last_mapping_sym = -1;
is_thumb = (last_type == MAP_THUMB);
found = FALSE;
found = false;
/* Start scanning at the start of the function, or wherever
we finished last time. */
n = info->symtab_pos + 1;
Expand All @@ -3939,7 +3936,7 @@ print_insn_arm (bfd_vma pc, struct disassemble_info *info)
&& get_sym_code_type (info, n, &type))
{
last_sym = n;
found = TRUE;
found = true;
}
}

Expand All @@ -3956,7 +3953,7 @@ print_insn_arm (bfd_vma pc, struct disassemble_info *info)
if (get_sym_code_type (info, n, &type))
{
last_sym = n;
found = TRUE;
found = true;
break;
}
}
Expand Down Expand Up @@ -4028,7 +4025,7 @@ print_insn_arm (bfd_vma pc, struct disassemble_info *info)
#endif

if (force_thumb)
is_thumb = TRUE;
is_thumb = true;

info->bytes_per_line = 4;

Expand Down
12 changes: 11 additions & 1 deletion qemu/configure
Original file line number Diff line number Diff line change
Expand Up @@ -1686,6 +1686,16 @@ QEMU_CFLAGS="-U_FORTIFY_SOURCE $QEMU_CFLAGS"
QEMU_CFLAGS="-I. -I\$(SRC_PATH) -MMD -MP -MT \$@ $QEMU_CFLAGS"
LDFLAGS="-g $LDFLAGS"

gcc_flags="-Wold-style-declaration -Wold-style-definition"
cat > $TMPC << EOF
int main(void) { }
EOF
for flag in $gcc_flags; do
if compile_prog "$QEMU_CFLAGS" "$flag" ; then
QEMU_CFLAGS="$flag $QEMU_CFLAGS"
fi
done

# Consult white-list to determine whether to enable werror
# by default. Only enable by default for git builds
if test -z "$werror" ; then
Expand Down Expand Up @@ -1861,7 +1871,7 @@ if test $profiler = "yes" ; then
fi
if test "$slirp" = "yes" ; then
echo "CONFIG_SLIRP=y" >> $config_host_mak
CFLAGS="-I\$(SRC_PATH)/slirp $CFLAGS"
QEMU_CFLAGS="-I\$(SRC_PATH)/slirp $QEMU_CFLAGS"
fi
if test "$vde" = "yes" ; then
echo "CONFIG_VDE=y" >> $config_host_mak
Expand Down
18 changes: 8 additions & 10 deletions qemu/cris-dis.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@

void *qemu_malloc(size_t len); /* can't include qemu-common.h here */

#define FALSE 0
#define TRUE 1
#define CONST_STRNEQ(STR1,STR2) (strncmp ((STR1), (STR2), sizeof (STR2) - 1) == 0)

/* cris-opc.c -- Table of opcodes for the CRIS processor.
Expand Down Expand Up @@ -1320,15 +1318,15 @@ cris_parse_disassembler_options (disassemble_info *info,
info->private_data = calloc (1, sizeof (struct cris_disasm_data));
disdata = (struct cris_disasm_data *) info->private_data;
if (disdata == NULL)
return FALSE;
return false;

/* Default true. */
disdata->trace_case
= (info->disassembler_options == NULL
|| (strcmp (info->disassembler_options, "nocase") != 0));

disdata->distype = distype;
return TRUE;
return true;
}

static const struct cris_spec_reg *
Expand Down Expand Up @@ -2779,7 +2777,7 @@ print_insn_cris_with_register_prefix (bfd_vma vma,
if (info->private_data == NULL
&& !cris_parse_disassembler_options (info, cris_dis_v0_v10))
return -1;
return print_insn_cris_generic (vma, info, TRUE);
return print_insn_cris_generic (vma, info, true);
}
#endif
/* Disassemble, prefixing register names with `$'. CRIS v32. */
Expand All @@ -2791,7 +2789,7 @@ print_insn_crisv32_with_register_prefix (bfd_vma vma,
if (info->private_data == NULL
&& !cris_parse_disassembler_options (info, cris_dis_v32))
return -1;
return print_insn_cris_generic (vma, info, TRUE);
return print_insn_cris_generic (vma, info, true);
}

#if 0
Expand All @@ -2805,7 +2803,7 @@ print_insn_crisv10_v32_with_register_prefix (bfd_vma vma,
if (info->private_data == NULL
&& !cris_parse_disassembler_options (info, cris_dis_common_v10_v32))
return -1;
return print_insn_cris_generic (vma, info, TRUE);
return print_insn_cris_generic (vma, info, true);
}

/* Disassemble, no prefixes on register names. CRIS v0..v10. */
Expand All @@ -2817,7 +2815,7 @@ print_insn_cris_without_register_prefix (bfd_vma vma,
if (info->private_data == NULL
&& !cris_parse_disassembler_options (info, cris_dis_v0_v10))
return -1;
return print_insn_cris_generic (vma, info, FALSE);
return print_insn_cris_generic (vma, info, false);
}

/* Disassemble, no prefixes on register names. CRIS v32. */
Expand All @@ -2829,7 +2827,7 @@ print_insn_crisv32_without_register_prefix (bfd_vma vma,
if (info->private_data == NULL
&& !cris_parse_disassembler_options (info, cris_dis_v32))
return -1;
return print_insn_cris_generic (vma, info, FALSE);
return print_insn_cris_generic (vma, info, false);
}

/* Disassemble, no prefixes on register names.
Expand All @@ -2842,7 +2840,7 @@ print_insn_crisv10_v32_without_register_prefix (bfd_vma vma,
if (info->private_data == NULL
&& !cris_parse_disassembler_options (info, cris_dis_common_v10_v32))
return -1;
return print_insn_cris_generic (vma, info, FALSE);
return print_insn_cris_generic (vma, info, false);
}
#endif

Expand Down
Loading

0 comments on commit 4b05b62

Please sign in to comment.