Skip to content

Commit 6d51da5

Browse files
committed
gem5: add m5 fail 1 to /m5op.out
Document that m5 fail is not actually exiting status 1 on fs.py.
1 parent 6fadc5e commit 6d51da5

File tree

2 files changed

+63
-16
lines changed

2 files changed

+63
-16
lines changed

README.adoc

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8221,16 +8221,36 @@ It is possible to guess what most tools do from the corresponding <<m5ops>>, but
82218221

82228222
===== m5 exit
82238223

8224-
Quit gem5 with exit status 0.
8224+
End the simulation.
8225+
8226+
Sane Python scripts will exit gem5 with status 0, which is what `fs.py` does.
82258227

82268228
===== m5 fail
82278229

8228-
Quit gem5 with the given exit status.
8230+
End the simulation with a failure exit event:
82298231

82308232
....
82318233
m5 fail 1
82328234
....
82338235

8236+
Sane Python scripts would use that as the exit status of gem5, which would be useful for testing purposes, but `fs.py` at 200281b08ca21f0d2678e23063f088960d3c0819 just prints an error message:
8237+
8238+
....
8239+
Simulated exit code not 0! Exit code is 1
8240+
....
8241+
8242+
and exits with status 0.
8243+
8244+
TODO: it used to exit non 0, be like that, but it actually got changed to just print the message. Why? https://gem5-review.googlesource.com/c/public/gem5/+/4880
8245+
8246+
`m5 fail` is just a superset of `m5 exit`, which is just:
8247+
8248+
....
8249+
m5 fail 0
8250+
....
8251+
8252+
as can be seen from the source: https://github.com/gem5/gem5/blob/50a57c0376c02c912a978c4443dd58caebe0f173/src/sim/pseudo_inst.cc#L303
8253+
82348254
===== m5 writefile
82358255

82368256
Send a guest file to the host. <<9p>> is a more advanced alternative.
@@ -8294,10 +8314,13 @@ The executable `/m5ops.out` illustrates how to hard code with inline assembly th
82948314
....
82958315
# checkpoint
82968316
/m5ops.out c
8317+
82978318
# dumpstats
82988319
/m5ops.out d
8299-
# dump exit
8320+
8321+
# exit
83008322
/m5ops.out e
8323+
83018324
# dump resetstats
83028325
/m5ops.out r
83038326
....
@@ -8359,7 +8382,20 @@ Finally, `m5.c` calls the defined functions as in:
83598382
m5_exit(ints[0]);
83608383
....
83618384

8362-
Therefore, the runtime "argument" that gets passed to the instruction, e.g. the desired exit status in the case of `exit`, gets passed directly through the link:https://en.wikipedia.org/wiki/Calling_convention#ARM_(A64)[aarch64 calling convention].
8385+
Therefore, the runtime "argument" that gets passed to the instruction, e.g. the delay in ticks until the exit for `m5 exit`, gets passed directly through the link:https://en.wikipedia.org/wiki/Calling_convention#ARM_(A64)[aarch64 calling convention].
8386+
8387+
Keep in mind that for all archs, `m5.c` does the calls with 64-bit integers:
8388+
8389+
....
8390+
uint64_t ints[2] = {0,0};
8391+
parse_int_args(argc, argv, ints, argc);
8392+
m5_fail(ints[1], ints[0]);
8393+
....
8394+
8395+
Therefore, for example:
8396+
8397+
* aarch64 uses `x0` for the first argument and `x1` for the second, since each is 64 bits log already
8398+
* arm uses `r0` and `r1` for the first argument, and `r2` and `r3` for the second, since each register is only 32 bits long
83638399

83648400
That convention specifies that `x0` to `x7` contain the function arguments, so `x0` contains the first argument, and `x1` the second.
83658401

kernel_module/user/m5ops.c

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,44 @@
66

77
#define ENABLED 1
88
#if defined(__arm__)
9-
static void m5_checkpoint()
9+
static void m5_checkpoint(void)
1010
{
11-
__asm__ __volatile__ ("mov r0, #0; mov r1, #0; .inst 0xEE000110 | (0x43 << 16);");
11+
__asm__ __volatile__ ("mov r0, #0; mov r1, #0; mov r2, #0; mov r3, #0; .inst 0xEE000110 | (0x43 << 16);");
1212
};
13-
static void m5_dump_stats()
13+
static void m5_dump_stats(void)
1414
{
15-
__asm__ __volatile__ ("mov r0, #0; mov r1, #0; .inst 0xEE000110 | (0x41 << 16);");
15+
__asm__ __volatile__ ("mov r0, #0; mov r1, #0; mov r2, #0; mov r3, #0; .inst 0xEE000110 | (0x41 << 16);");
1616
};
1717
static void m5_exit()
1818
{
1919
__asm__ __volatile__ ("mov r0, #0; .inst 0xEE000110 | (0x21 << 16);");
2020
};
21-
static void m5_reset_stats()
21+
static void m5_fail_1(void)
2222
{
23-
__asm__ __volatile__ ("mov r0, #0; mov r1, #0; .inst 0xEE000110 | (0x40 << 16);");
23+
__asm__ __volatile__ ("mov r0, #0; mov r1, #0; mov r2, #1; mov r3, #0; .inst 0xEE000110 | (0x22 << 16);");
24+
};
25+
static void m5_reset_stats(void)
26+
{
27+
__asm__ __volatile__ ("mov r0, #0; mov r1, #0; mov r2, #0; mov r3, #0; .inst 0xEE000110 | (0x40 << 16);");
2428
};
2529
#elif defined(__aarch64__)
26-
static void m5_checkpoint()
30+
static void m5_checkpoint(void)
2731
{
2832
__asm__ __volatile__ ("mov x0, #0; mov x1, #0; .inst 0xFF000110 | (0x43 << 16);");
2933
};
30-
static void m5_dump_stats()
34+
static void m5_dump_stats(void)
3135
{
3236
__asm__ __volatile__ ("mov x0, #0; mov x1, #0; .inst 0xFF000110 | (0x41 << 16);");
3337
};
34-
static void m5_exit()
38+
static void m5_exit(void)
3539
{
3640
__asm__ __volatile__ ("mov x0, #0; .inst 0XFF000110 | (0x21 << 16);");
3741
};
38-
static void m5_reset_stats()
42+
static void m5_fail_1(void)
43+
{
44+
__asm__ __volatile__ ("mov x0, #0; mov x1, #1; .inst 0xFF000110 | (0x22 << 16);");
45+
};
46+
static void m5_reset_stats(void)
3947
{
4048
__asm__ __volatile__ ("mov x0, #0; mov x1, #0; .inst 0XFF000110 | (0x40 << 16);");
4149
};
@@ -62,14 +70,17 @@ void
6270
switch (action)
6371
{
6472
case 'c':
65-
m5_checkpoint(0, 0);
73+
m5_checkpoint();
6674
break;
6775
case 'd':
68-
m5_dump_stats(0, 0);
76+
m5_dump_stats();
6977
break;
7078
case 'e':
7179
m5_exit();
7280
break;
81+
case 'f':
82+
m5_fail_1();
83+
break;
7384
case 'r':
7485
m5_reset_stats();
7586
break;

0 commit comments

Comments
 (0)