Skip to content

Commit

Permalink
Merge pull request #263 from flaviojs/fix-debugging-log-message-dev_r…
Browse files Browse the repository at this point in the history
…emote_control_access

Fix debugging/log message in dev_remote_control_access.
  • Loading branch information
grossmj authored Oct 6, 2024
2 parents f351cef + 6d24c7b commit aa8b40b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
9 changes: 4 additions & 5 deletions common/dev_remote.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,10 @@ void *dev_remote_control_access(cpu_gen_t *cpu,struct vdevice *dev,
/* Debugging/Log message: /!\ physical address */
case 0x038:
if (op_type == MTS_WRITE) {
len = physmem_strlen(vm,*data);
if (len < sizeof(d->con_buffer)) {
physmem_copy_from_vm(vm,d->con_buffer,*data,len+1);
vm_log(vm,"ROM",d->con_buffer);
}
len = physmem_strnlen(vm,*data,sizeof(d->con_buffer));
physmem_copy_from_vm(vm,d->con_buffer,*data,len);
d->con_buffer[m_min(len,sizeof(d->con_buffer)-1)] = 0;
vm_log(vm,"ROM","%s",d->con_buffer);
}
break;

Expand Down
9 changes: 5 additions & 4 deletions common/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,16 +294,17 @@ void physmem_dma_transfer(vm_instance_t *vm,m_uint64_t src,m_uint64_t dst,
}
}

/* strlen in VM physical memory */
size_t physmem_strlen(vm_instance_t *vm,m_uint64_t paddr)
/* strnlen in VM physical memory */
size_t physmem_strnlen(vm_instance_t *vm,m_uint64_t paddr,size_t maxlen)
{
struct vdevice *vm_ram;
size_t len = 0;
char *ptr;

if ((vm_ram = dev_lookup(vm,paddr,TRUE)) != NULL) {
if ((vm_ram = dev_lookup(vm,paddr,TRUE)) != NULL && vm_ram->host_addr) {
ptr = (char *)vm_ram->host_addr + (paddr - vm_ram->phys_addr);
len = strlen(ptr);
maxlen = m_min(maxlen, vm_ram->phys_len - (paddr - vm_ram->phys_addr));
len = strnlen(ptr,maxlen);
}

return(len);
Expand Down
4 changes: 2 additions & 2 deletions stable/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ void physmem_copy_u8_to_vm(vm_instance_t *vm,m_uint64_t paddr,m_uint8_t val);
void physmem_dma_transfer(vm_instance_t *vm,m_uint64_t src,m_uint64_t dst,
size_t len);

/* strlen in VM physical memory */
size_t physmem_strlen(vm_instance_t *vm,m_uint64_t paddr);
/* strnlen in VM physical memory */
size_t physmem_strnlen(vm_instance_t *vm,m_uint64_t paddr,size_t maxlen);

/* find sequence of bytes in VM cacheable physical memory interval [first,last] */
int physmem_cfind(vm_instance_t *vm,m_uint8_t *bytes,size_t len,
Expand Down
4 changes: 2 additions & 2 deletions unstable/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ void physmem_copy_u8_to_vm(vm_instance_t *vm,m_uint64_t paddr,m_uint8_t val);
void physmem_dma_transfer(vm_instance_t *vm,m_uint64_t src,m_uint64_t dst,
size_t len);

/* strlen in VM physical memory */
size_t physmem_strlen(vm_instance_t *vm,m_uint64_t paddr);
/* strnlen in VM physical memory */
size_t physmem_strnlen(vm_instance_t *vm,m_uint64_t paddr,size_t maxlen);

/* find sequence of bytes in VM cacheable physical memory interval [first,last] */
int physmem_cfind(vm_instance_t *vm,m_uint8_t *bytes,size_t len,
Expand Down

0 comments on commit aa8b40b

Please sign in to comment.