5 changed files with 138 additions and 2 deletions
@ -0,0 +1,80 @@ |
|||||||
|
#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; |
||||||
|
} |
||||||
@ -0,0 +1,14 @@ |
|||||||
|
/* start.S */ |
||||||
|
.section .text |
||||||
|
.global _start
|
||||||
|
|
||||||
|
_start: |
||||||
|
/* 1. 初始化栈指针 (Stack Pointer) */ |
||||||
|
/* tb.v里内存大小是 4096 words (16KB) */ |
||||||
|
li sp, 0x4000 |
||||||
|
|
||||||
|
call main |
||||||
|
|
||||||
|
/* 3. 如果 main 返回了(理论上不该返回),死循环兜底 */ |
||||||
|
loop: |
||||||
|
j loop |
||||||
@ -0,0 +1,22 @@ |
|||||||
|
#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; |
||||||
|
|
||||||
|
int main() { |
||||||
|
sink = 0; |
||||||
|
|
||||||
|
MISR_START(); |
||||||
|
|
||||||
|
// Your Code here.
|
||||||
|
sink = 1; |
||||||
|
|
||||||
|
MISR_STOP(); |
||||||
|
SIM_FINISH(); |
||||||
|
while(1) { |
||||||
|
__asm__ volatile ("nop"); |
||||||
|
} |
||||||
|
return 0; |
||||||
|
} |
||||||
Loading…
Reference in new issue