[PATCH 13/24] RISC-V sim: Add gettimeofday.

Mike Frysinger vapier@gentoo.org
Mon Apr 19 04:19:41 GMT 2021


On 17 Apr 2021 10:58, Jim Wilson wrote:
> +	    case TARGET_SYS_gettimeofday:
> +	      {
> +		int rv;
> +		struct timeval tv;
> +
> +		rv = gettimeofday (&tv, 0);
> +		if (RISCV_XLEN (cpu) == 32)
> +		  {
> +		    sim_core_write_unaligned_4 (cpu, cpu->pc, write_map,
> +						cpu->a0, tv.tv_sec);
> +		    sim_core_write_unaligned_4 (cpu, cpu->pc, write_map,
> +						cpu->a0 + 4,
> +						tv.tv_usec);
> +		  }
> +		else
> +		  {
> +		    sim_core_write_unaligned_8 (cpu, cpu->pc, write_map,
> +						cpu->a0, tv.tv_sec);
> +		    sim_core_write_unaligned_8 (cpu, cpu->pc, write_map,
> +						cpu->a0 + 8,
> +						tv.tv_usec);
> +		  }

this is incomplete/buggy.  if arg0==0, you'll write to the wrong place.
if arg1!=0, you leave the memory uninitialized.  if rv!=0, you write to
the arg0 struct.  see bfin/interp.c for a "full" implementation.

if we extended host_callback_struct to include a timeval_map, we would be
able to implement this in the common code and do so with full support for
everyone.
-mike


More information about the Gdb-patches mailing list