bugSimulavr: an AVR simulator - Bugs: bug #66044, core->dataAddressMask not...

 
 

bug #66044: core->dataAddressMask not applied correctly

Submitter:  Georg-Johann Lay <gjlayde>
Submitted:  Wed 31 Jul 2024 10:36:58 AM UTC
Votes: 1
 
Category:  Simulation Severity:  3 - Normal
Item Group:  None Status:  None
Privacy:  Public Assigned to:  None
Open/Closed:  Open Component Version:  * simulavr
* Mandatory Fields

Add a New Comment Rich Markup
   

Mon 30 Sep 2024 09:57:56 AM UTC, comment #1: 

Here is the respective clause from the "AVR Instruction Set Manual" at
https://ww1.microchip.com/downloads/en/DeviceDoc/AVR-InstructionSet-Manual-DS40002198.pdf

On page 87, section 6.66 LD - Load Indirect from Data Space to Register using X:

6.66.1 Description
[...] Note that only the low byte of the X-pointer is updated
in devices with no more than 256 bytes of data space.
For such devices, the high byte of the pointer is not used
by this instruction and can be used for other purposes. [...]

Similar notes exist for the Y and Z registers.

The issue came up in an AVR-LibC test case, and there is also a proposed patch for SimulAVR:
https://github.com/avrdudes/avr-libc/issues/954#issuecomment-2382476082

Georg-Johann Lay <gjlayde>
Wed 31 Jul 2024 10:36:58 AM UTC, original submission:  

In the code for ATtiny2313 below, the content of the XH register should be ignored (masked out) when X is used to access RAM (or more generally, data in the RAM address space, which extends from address 0 to 223).

However, XH is not ignored so that the code below runs into my_abort:


;;; avr-gcc foo.sx -o foo.elf -mmcu=attiny2313
;;; simulavr -d attiny2313 -f foo.elf -a 0x20 -e 0x21 -M

.data
var:
    .byte 123
.global __do_copy_data

.text
.global main
main:
    ldi XL, lo8(var)
    ;; Write garbage to XH which is in order for ATtiny2313:
    ;; That device has RAM_size = 128 and IO_space = 64,
    ;; which makes a valid RAM address range of 0...223, and hence a
    ;; core->dataAddressMask of 0xff.  This means that when simulavr is masking the
    ;; address in X for access, the XH part will be masked out entirely.
    ;; On the instruction level this means that it is sufficient to
    ;; specify the lo8 part of an address for indirect RAM accesses.
    ldi XH, 1
    ld  r16, X
    cpi r16, 123
    brne my_abort
my_exit:
    out 0x1, r0
my_abort:
    out 0x0, r0
    ret


Georg-Johann Lay <gjlayde>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #56330:  foo.sx added by gjlayde (786B - application/octet-stream - foo.sx: Assembly test case)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by sciprosk (Voted in favor of this item)
  • -email is unavailable- added by gjlayde (Submitted the item)
  •  

    There is 1 vote so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2024-09-30 sciprosk Carbon-Copy- Added sciprosk
    2024-07-31 gjlayde Attached File- Added foo.sx, #56330

    Back to the top

    Powered by Savane 3.15-26b0.
    Corresponding source code