unit test for "hello multiverse"

four cores started all at once, each responsible for updating
a byte of the GPIO range, in unison.
This commit is contained in:
bunnie 2024-03-01 23:31:42 +08:00
parent 0045e32508
commit 153db680f2

View file

@ -49,24 +49,40 @@ pub fn hello_multiverse() {
bio_ss.bio.wo(utra::bio::SFR_QDIV1, 0x20_0000); bio_ss.bio.wo(utra::bio::SFR_QDIV1, 0x20_0000);
bio_ss.bio.wo(utra::bio::SFR_QDIV2, 0x20_0000); bio_ss.bio.wo(utra::bio::SFR_QDIV2, 0x20_0000);
bio_ss.bio.wo(utra::bio::SFR_QDIV3, 0x20_0000); bio_ss.bio.wo(utra::bio::SFR_QDIV3, 0x20_0000);
// snap GPIO outputs to the quantum
bio_ss.bio.wo(utra::bio::SFR_CONFIG,
bio_ss.bio.ms(utra::bio::SFR_CONFIG_SNAP_TO_QUANTUM, 1)
| bio_ss.bio.ms(utra::bio::SFR_CONFIG_SNAP_TO_QUANTUM, 2) // arbitrary choice, they should all be the same
);
// start all the machines, all at once // start all the machines, all at once
bio_ss.bio.wo(utra::bio::SFR_CTRL, 0xfff); bio_ss.bio.wo(utra::bio::SFR_CTRL, 0xfff);
report_api(0x1310_10FF); report_api(0x1310_10FF);
} }
bio_code!(multiverse_code, MULTIVERSE_START, MULTIVERSE_END, bio_code!(multiverse_code, MULTIVERSE_START, MULTIVERSE_END,
"jal x0, 0f", // Reset vectors for each core are aligned to 4-byte boundaries
// reset vectors for each machine // As long as the jump target is <2kiB from reset, this will emit
// use `jal x0, target` encoding to force non-C interpretation // a C-instruction, so it needs padding with a NOP. Unfortunately,
// as the reset vectors for each core are aligned to 4-byte boundaries // I can't seem to figure out a way to force the assembler to always
"jal x0, 0f", // encode as uncompressed, so, you have to be aware of the jump destination
"jal x0, 1f", // for the assembler output to line up according to your expectation :(
"jal x0, 2f", //
"jal x0, 3f", // using 'c.j' syntax for the jump causes the assembler to emit an error,
// but the code still compiles, so...avoiding that for now. might be a bug,
// but I am very not interested in fixing that today.
"j 0f",
"nop",
"j 1f",
"nop",
"j 2f",
"nop",
"j 3f",
"nop",
// mach 0 code // mach 0 code
"0:", "0:",
// x26 sets the GPIO mask // x26 sets the GPIO mask
"li x26, 0xFF", "li x2, 0xFF", // load constants into r0-15 bank first
"mv x26, x2", // it's not legal to do anything other than mv to x26
"add x1, zero, 0x10", "add x1, zero, 0x10",
"4:", "4:",
"add x1, x1, 0x1", "add x1, x1, 0x1",
@ -77,7 +93,8 @@ bio_code!(multiverse_code, MULTIVERSE_START, MULTIVERSE_END,
"j 4b", "j 4b",
// mach 1 code // mach 1 code
"1:", "1:",
"li x26, 0xFF00", "li x2, 0xFF00",
"mv x26, x2",
"add x1, zero, 0x20", "add x1, zero, 0x20",
"5:", "5:",
"add x1, x1, 0x1", "add x1, x1, 0x1",
@ -86,8 +103,9 @@ bio_code!(multiverse_code, MULTIVERSE_START, MULTIVERSE_END,
"j 5b", "j 5b",
// mach 2 code // mach 2 code
"2:", "2:",
"li x26, 0xFF0000", "li x2, 0xFF0000",
"add x1, zero, 0x20", "mv x26, x2",
"add x1, zero, 0x30",
"6:", "6:",
"add x1, x1, 0x1", "add x1, x1, 0x1",
"slli x21, x1, 16", "slli x21, x1, 16",
@ -95,8 +113,9 @@ bio_code!(multiverse_code, MULTIVERSE_START, MULTIVERSE_END,
"j 6b", "j 6b",
// mach 3 code // mach 3 code
"3:", "3:",
"li x26, 0xFF0000", "li x2, 0xFF000000",
"add x1, zero, 0x20", "mv x26, x2",
"add x1, zero, 0x40",
"7:", "7:",
"add x1, x1, 0x1", "add x1, x1, 0x1",
"slli x21, x1, 24", "slli x21, x1, 24",