1*** Variables ***
2${SCRIPT}                     ${CURDIR}/../../scripts/single-node/leon3_zephyr.resc
3${UART}                       sysbus.uart
4${PROMPT}                     uart:~$
5
6*** Keywords ***
7Prepare Machine
8    Execute Script            ${SCRIPT}
9
10    Create Terminal Tester    ${UART}
11
12ASR18 Should Be Equal
13    [Arguments]  ${expected}
14
15    Register Should Be Equal  39  ${expected}
16
17*** Test Cases ***
18Should Boot Zephyr
19    [Documentation]           Boots Zephyr on the Leon3 platform.
20    [Tags]                    zephyr  uart
21    Prepare Machine
22
23    Start Emulation
24
25    Wait For Prompt On Uart   ${PROMPT}
26
27    Provides                  booted-zephyr
28
29Should Print Version
30    [Documentation]           Tests shell responsiveness in Zephyr on the Leon3 platform.
31    [Tags]                    zephyr  uart
32    Requires                  booted-zephyr
33
34    Write Line To Uart        version
35    Wait For Line On Uart     Zephyr version 2.6.99
36
37Should Handle WRASR
38    Prepare Machine
39
40    # Note that these writes to memory are in the emulation target's endianness (which is big-endian here), NOT the host's.
41    # For example, after `sysbus WriteDoubleWord 0x00000000 0x03100000`, the memory content as a byte array is `[0x03, 0x10, 0x00, 0x00]`.
42    # sethi  %hi(0xa5a5a400), %g1
43    Execute Command           sysbus WriteDoubleWord 0x40000000 0x03296969
44    # or     %g1, 0x1a5, %g1
45    Execute Command           sysbus WriteDoubleWord 0x40000004 0x821061a5
46    # orn    %g0, %g0, %g2
47    Execute Command           sysbus WriteDoubleWord 0x40000008 0x84300000
48    # wr     0x1555, %asr18
49    Execute Command           sysbus WriteDoubleWord 0x4000000c 0xa5803555
50    # wr     %g1, %asr18
51    Execute Command           sysbus WriteDoubleWord 0x40000010 0xa5800001
52    # wr     %g2, 0x1555, %asr18
53    Execute Command           sysbus WriteDoubleWord 0x40000014 0xa580b555
54    # wr     %g1, %g2, %asr18
55    Execute Command           sysbus WriteDoubleWord 0x40000018 0xa5804002
56    # wr     %g2, %asr15
57    Execute Command           sysbus WriteDoubleWord 0x4000001c 0x9f800002
58    # nop
59    Execute Command           sysbus WriteDoubleWord 0x40000020 0x01000000
60    # ba .
61    Execute Command           sysbus WriteDoubleWord 0x40000024 0x10800000
62    # nop
63    Execute Command           sysbus WriteDoubleWord 0x40000028 0x01000000
64
65    PC Should Be Equal        0x40000000
66
67    Execute Command           cpu Step 3
68    PC Should Be Equal        0x4000000c
69    ASR18 Should Be Equal     0x0
70
71    Execute Command           cpu Step
72    PC Should Be Equal        0x40000010
73    ASR18 Should Be Equal     0xfffff555
74
75    Execute Command           cpu Step
76    PC Should Be Equal        0x40000014
77    ASR18 Should Be Equal     0xa5a5a5a5
78
79    Execute Command           cpu Step
80    PC Should Be Equal        0x40000018
81    ASR18 Should Be Equal     0xaaa
82
83    Execute Command           cpu Step
84    PC Should Be Equal        0x4000001c
85    ASR18 Should Be Equal     0x5a5a5a5a
86
87    Execute Command           cpu Step
88    # If we get here, we didn't crash on the write to ASR15.
89    PC Should Be Equal        0x40000020
90    ASR18 Should Be Equal     0x5a5a5a5a
91