You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
2.2 KiB
80 lines
2.2 KiB
#include <stdint.h> |
|
|
|
#define MISR_START() (*(volatile uint32_t *)0x40000000 = 1) |
|
#define MISR_STOP() (*(volatile uint32_t *)0x40000000 = 0) |
|
#define SIM_FINISH() (*(volatile uint32_t *)0x20000000 = 1) |
|
volatile uint32_t sink; |
|
|
|
void trigger_untestable_counters() { |
|
uint32_t cycle_low, cycle_high; |
|
|
|
__asm__ volatile ("rdcycle %0" : "=r"(cycle_low)); |
|
__asm__ volatile ("rdcycleh %0" : "=r"(cycle_high)); |
|
|
|
sink = cycle_low ^ cycle_high; |
|
sink = cycle_low + cycle_high; |
|
} |
|
|
|
void bomb_alu_full_coverage() { |
|
volatile uint32_t p1 = 0xAAAAAAAA; // 10101010... |
|
volatile uint32_t p2 = 0x55555555; // 01010101... |
|
volatile uint32_t p3 = 0xFFFFFFFF; // 全 1 |
|
volatile uint32_t p4 = 0x80000000; // 仅最高位为 1 (符号位测试) |
|
volatile uint32_t p5 = 0x00000001; // 仅最低位为 1 |
|
|
|
for (int i = 0; i < 12; i++) { |
|
sink = p1 + p2; // 加法 |
|
sink = p3 + p5; |
|
sink = p3 + p4; |
|
sink = p1 - p2; // 减法 |
|
sink = p5 - p3; |
|
|
|
volatile uint32_t sink1 = p3 - p5; |
|
volatile uint32_t sink2; |
|
for(int lop = 0; lop < 5 ; lop++){ |
|
sink2 = sink1 - p5; |
|
sink1 = sink2 ^ 0xFFFFFFFF; |
|
} |
|
sink = sink1; |
|
|
|
sink = p1 ^ p2; // XOR |
|
sink = p1 ^ p3; |
|
sink = p2 ^ p3; |
|
sink = p1 & p2; // AND |
|
sink = p3 & p2; |
|
sink = p1 & p3; |
|
sink = p1 | p2; // OR |
|
sink = p3 | p2; |
|
sink = p1 | p3; |
|
|
|
sink = p1 << i; // 逻辑左移 (SLL) |
|
sink = p2 >> i; // 逻辑右移 (SRL) |
|
sink = (int32_t)p4 >> i; // 算术右移 (SRA) |
|
|
|
sink = (int32_t)p1 < (int32_t)p2; // 有符号比较 (Signed) |
|
sink = p1 < p2; // 无符号比较 (Unsigned) |
|
|
|
p1 = ~p1; |
|
p2 = ~p2; |
|
p4 = (p4 >> 1) | 0x80000000; |
|
p5 = p5 << 1; |
|
} |
|
} |
|
|
|
int main() { |
|
sink = 0; |
|
|
|
MISR_START(); |
|
|
|
for(int loop = 0; loop < 2; loop++) { |
|
trigger_untestable_counters(); |
|
bomb_alu_full_coverage(); |
|
} |
|
|
|
MISR_STOP(); |
|
SIM_FINISH(); |
|
while(1) { |
|
__asm__ volatile ("nop"); |
|
} |
|
return 0; |
|
}
|
|
|