提交 ad85fc11 编写于 作者: 饶先宏's avatar 饶先宏

202109051002

上级 6f8db5d8
PLL_Name pllqsys:comb_9|pllqsys_altpll_0:altpll_0|pllqsys_altpll_0_altpll_m342:sd1|pll7
PLL_Name pllqsys:clk|pllqsys_altpll_0:altpll_0|pllqsys_altpll_0_altpll_m342:sd1|pll7
PLLJITTER 30
PLLSPEmax 84
PLLSPEmin -53
......
......@@ -380,7 +380,7 @@ inout [35:0] GPIO;
`else
wire clk100MHz;
wire nwReset = KEY[3];
pllqsys (
pllqsys clk(
.clk_clk(CLOCK_50), // clk.clk
.reset_reset_n(nwReset), // reset.reset_n
.altpll_0_c0_clk(clk100MHz), // altpll_0_c0.clk
......
......@@ -78,7 +78,7 @@ static int _gets(char* s, int buflen)
return ind;
}
static int _d2s(char* buf, int num)
static int _d2s(char* buf, long long num)
{
int i;
int len;
......@@ -89,12 +89,16 @@ static int _d2s(char* buf, int num)
num = -num;
sign = 0;
}
while (num > 0) {
buf[len++] = (num % 10) + '0';
num /= 10;
if (num == 0)
buf[len++] = '0';
else {
while (num > 0) {
buf[len++] = (num % 10) + '0';
num /= 10;
}
if (sign)
buf[len++] = '-';
}
if (sign)
buf[len++] = '-';
for (i = 0; i < len / 2; i++) {
int di = len - 1 - i;
char temp;
......@@ -303,7 +307,7 @@ static void dispmem()
if ( (startaddr & 0xff) == 0)
break;
}
_puts("\n");
_puts("\n\r");
displayaddr = startaddr;
}
......@@ -326,34 +330,108 @@ static unsigned int num2seg(unsigned int num)
return segcode[num % 10];
}
static unsigned long long cycle() {
unsigned long long ret;
unsigned int retl, reth;
asm volatile (
"csrrsi %0, %1, %2 " : "=r"(retl) : "i"(0xc00),"i"(0):"a0"
);
asm volatile (
"csrrsi %0, %1, %2 " : "=r"(reth) : "i"(0xc80), "i"(0) : "a0"
);
ret = reth;
ret <<= 32;
ret |= retl;
return ret;
#define DEFINECSRGET(csrname, csrno) \
static unsigned long long csrname() { \
unsigned long long ret; \
unsigned int retl, reth; \
asm volatile ( \
"csrrsi %0, %1, %2 " : "=r"(retl) : "i"(csrno), "i"(0) : "a0" \
); \
asm volatile ( \
"csrrsi %0, %1, %2 " : "=r"(reth) : "i"(csrno + 0x080), "i"(0) : "a0" \
); \
ret = reth; \
ret <<= 32; \
ret |= retl; \
return ret; \
}
static unsigned long long instrcount() {
unsigned long long ret;
unsigned int retl, reth;
asm volatile (
"csrrsi %0, %1, %2 " : "=r"(retl) : "i"(0xc02), "i"(0) : "a0"
);
asm volatile (
"csrrsi %0, %1, %2 " : "=r"(reth) : "i"(0xc82), "i"(0) : "a0"
);
ret = reth;
ret <<= 32;
ret |= retl;
return ret;
#define DEFINECSRGETCLEAR(csrname, csrno) \
static unsigned long long csrname() { \
unsigned long long ret; \
unsigned int retl = 0, reth = 0; \
asm volatile ( \
"csrrw %0, %1, %2 " : "=r"(retl) : "i"(csrno), "r"(retl) : "a0" \
); \
asm volatile ( \
"csrrw %0, %1, %2 " : "=r"(reth) : "i"(csrno + 0x080), "r"(reth) : "a0" \
); \
ret = reth; \
ret <<= 32; \
ret |= retl; \
return ret; \
}
DEFINECSRGET(cycle, 0xc00)
DEFINECSRGETCLEAR(cycle_clear, 0xc00)
DEFINECSRGET(instrcount, 0xc02)
DEFINECSRGETCLEAR(instrcount_clear, 0xc02)
DEFINECSRGET(get_counter_addsub, 0xc20)
DEFINECSRGETCLEAR(get_counter_addsub_clear, 0xc20)
DEFINECSRGET(get_counter_mul, 0xc21)
DEFINECSRGETCLEAR(get_counter_mul_clear, 0xc21)
DEFINECSRGET(get_counter_div, 0xc22)
DEFINECSRGETCLEAR(get_counter_div_clear, 0xc22)
DEFINECSRGET(get_counter_ld, 0xc23)
DEFINECSRGETCLEAR(get_counter_ld_clear, 0xc23)
DEFINECSRGET(get_counter_st, 0xc24)
DEFINECSRGETCLEAR(get_counter_st_clear, 0xc24)
DEFINECSRGET(get_counter_jmp, 0xc25)
DEFINECSRGETCLEAR(get_counter_jmp_clear, 0xc25)
DEFINECSRGET(get_counter_j, 0xc26)
DEFINECSRGETCLEAR(get_counter_j_clear, 0xc26)
DEFINECSRGET(get_counter_alui, 0xc27)
DEFINECSRGETCLEAR(get_counter_alui_clear, 0xc27)
DEFINECSRGET(get_counter_alu, 0xc28)
DEFINECSRGETCLEAR(get_counter_alu_clear, 0xc28)
typedef unsigned long long (*statusget)();
statusget statusgetfuncs[10] = {
instrcount,
get_counter_addsub,
get_counter_mul,
get_counter_div,
get_counter_ld,
get_counter_st,
get_counter_jmp,
get_counter_j,
get_counter_alui,
get_counter_alu
};
const char* statusname[10] = {
"total : ",
"add/sub : ",
"mul : ",
"div : ",
"ld : ",
"st : ",
"jmp : ",
"j : ",
"alui : ",
"alu : ",
};
static void liststatus()
{
char buf[40];
unsigned long long total = instrcount();
unsigned long long num;
int i;
for (i = 0; i < 10; i++) {
_puts("\n");
_puts(statusname[i]);
num = statusgetfuncs[i]();
_d2s(buf, num);
_puts(buf);
_puts(", ");
///num *= 10000;
num /= total / 10000;
_d2s(buf, num);
_puts(buf);
}
_puts("\n\r");
}
static void printhelp()
......@@ -440,6 +518,15 @@ int main(int argc, char* argv[])
if (_strncmp(buf, "help ", 4) == 0) {
printhelp();
}
/*
else if (buf[0] == 'c') {
cycle_clear();
instrcount_clear();
}
*/
else if (buf[0] == 'l') {
liststatus();
}
else if (buf[0] == 'b') {
int baud = _s2d(buf+2, 0);
if (baud > 0) {
......@@ -506,6 +593,8 @@ int main(int argc, char* argv[])
_puts(")\n\r");
}
}
while (_canputchar() == 0)
;
} while (1);
return 1;
}
......@@ -10,7 +10,7 @@ ELF Header:
Version: 0x1
Entry point address: 0x8c
Start of program headers: 52 (bytes into file)
Start of section headers: 20312 (bytes into file)
Start of section headers: 38636 (bytes into file)
Flags: 0x0
Size of this header: 52 (bytes)
Size of program headers: 32 (bytes)
......@@ -22,28 +22,28 @@ ELF Header:
Section Headers:
[Nr] Name Type Addr Off Size ES Flg Lk Inf Al
[ 0] NULL 00000000 000000 000000 00 0 0 0
[ 1] .text PROGBITS 00000074 000074 001a5c 00 AX 0 0 4
[ 2] .rodata PROGBITS 00001ad0 001ad0 000210 00 A 0 0 4
[ 3] .eh_frame PROGBITS 00002000 002000 00002c 00 WA 0 0 4
[ 4] .init_array INIT_ARRAY 0000202c 00202c 000008 04 WA 0 0 4
[ 5] .fini_array FINI_ARRAY 00002034 002034 000004 04 WA 0 0 4
[ 6] .data PROGBITS 00002038 002038 000428 00 WA 0 0 8
[ 7] .sdata PROGBITS 00002460 002460 00000c 00 WA 0 0 4
[ 8] .sbss NOBITS 0000246c 00246c 000008 00 WA 0 0 4
[ 9] .bss NOBITS 00002474 00246c 00001c 00 WA 0 0 4
[10] .comment PROGBITS 00000000 00246c 000012 01 MS 0 0 1
[11] .riscv.attributes RISCV_ATTRIBUTE 00000000 00247e 000025 00 0 0 1
[12] .debug_aranges PROGBITS 00000000 0024a3 000038 00 0 0 1
[13] .debug_info PROGBITS 00000000 0024db 000839 00 0 0 1
[14] .debug_abbrev PROGBITS 00000000 002d14 000216 00 0 0 1
[15] .debug_line PROGBITS 00000000 002f2a 000766 00 0 0 1
[16] .debug_str PROGBITS 00000000 003690 000296 01 MS 0 0 1
[17] .debug_line_str PROGBITS 00000000 003926 0000b0 01 MS 0 0 1
[18] .debug_loclists PROGBITS 00000000 0039d6 000a99 00 0 0 1
[19] .debug_rnglists PROGBITS 00000000 00446f 000111 00 0 0 1
[20] .symtab SYMTAB 00000000 004580 0005d0 10 21 71 4
[21] .strtab STRTAB 00000000 004b50 000319 00 0 0 1
[22] .shstrtab STRTAB 00000000 004e69 0000ee 00 0 0 1
[ 1] .text PROGBITS 00000074 000074 0029d4 00 AX 0 0 4
[ 2] .rodata PROGBITS 00002a48 002a48 00028c 00 A 0 0 4
[ 3] .eh_frame PROGBITS 00003000 003000 000054 00 WA 0 0 4
[ 4] .init_array INIT_ARRAY 00003054 003054 000008 04 WA 0 0 4
[ 5] .fini_array FINI_ARRAY 0000305c 00305c 000004 04 WA 0 0 4
[ 6] .data PROGBITS 00003060 003060 000478 00 WA 0 0 8
[ 7] .sdata PROGBITS 000034d8 0034d8 00000c 00 WA 0 0 4
[ 8] .sbss NOBITS 000034e4 0034e4 000008 00 WA 0 0 4
[ 9] .bss NOBITS 000034ec 0034e4 00001c 00 WA 0 0 4
[10] .comment PROGBITS 00000000 0034e4 000012 01 MS 0 0 1
[11] .riscv.attributes RISCV_ATTRIBUTE 00000000 0034f6 000025 00 0 0 1
[12] .debug_aranges PROGBITS 00000000 00351b 000078 00 0 0 1
[13] .debug_info PROGBITS 00000000 003593 0017b0 00 0 0 1
[14] .debug_abbrev PROGBITS 00000000 004d43 00059f 00 0 0 1
[15] .debug_line PROGBITS 00000000 0052e2 001792 00 0 0 1
[16] .debug_str PROGBITS 00000000 006a74 0002a8 01 MS 0 0 1
[17] .debug_line_str PROGBITS 00000000 006d1c 0000b0 01 MS 0 0 1
[18] .debug_loclists PROGBITS 00000000 006dcc 001aba 00 0 0 1
[19] .debug_rnglists PROGBITS 00000000 008886 0002c6 00 0 0 1
[20] .symtab SYMTAB 00000000 008b4c 0006d0 10 21 83 4
[21] .strtab STRTAB 00000000 00921c 0003e0 00 0 0 1
[22] .shstrtab STRTAB 00000000 0095fc 0000ee 00 0 0 1
Key to Flags:
W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
L (link order), O (extra OS processing required), G (group), T (TLS),
......@@ -54,8 +54,8 @@ There are no section groups in this file.
Program Headers:
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
LOAD 0x000000 0x00000000 0x00000000 0x01ce0 0x01ce0 R E 0x1000
LOAD 0x002000 0x00002000 0x00002000 0x0046c 0x00490 RW 0x1000
LOAD 0x000000 0x00000000 0x00000000 0x02cd4 0x02cd4 R E 0x1000
LOAD 0x003000 0x00003000 0x00003000 0x004e4 0x00508 RW 0x1000
Section to Segment mapping:
Segment Sections...
......@@ -68,18 +68,18 @@ There are no relocations in this file.
The decoding of unwind sections for machine type RISC-V is not currently supported.
Symbol table '.symtab' contains 93 entries:
Symbol table '.symtab' contains 109 entries:
Num: Value Size Type Bind Vis Ndx Name
0: 00000000 0 NOTYPE LOCAL DEFAULT UND
1: 00000074 0 SECTION LOCAL DEFAULT 1 .text
2: 00001ad0 0 SECTION LOCAL DEFAULT 2 .rodata
3: 00002000 0 SECTION LOCAL DEFAULT 3 .eh_frame
4: 0000202c 0 SECTION LOCAL DEFAULT 4 .init_array
5: 00002034 0 SECTION LOCAL DEFAULT 5 .fini_array
6: 00002038 0 SECTION LOCAL DEFAULT 6 .data
7: 00002460 0 SECTION LOCAL DEFAULT 7 .sdata
8: 0000246c 0 SECTION LOCAL DEFAULT 8 .sbss
9: 00002474 0 SECTION LOCAL DEFAULT 9 .bss
2: 00002a48 0 SECTION LOCAL DEFAULT 2 .rodata
3: 00003000 0 SECTION LOCAL DEFAULT 3 .eh_frame
4: 00003054 0 SECTION LOCAL DEFAULT 4 .init_array
5: 0000305c 0 SECTION LOCAL DEFAULT 5 .fini_array
6: 00003060 0 SECTION LOCAL DEFAULT 6 .data
7: 000034d8 0 SECTION LOCAL DEFAULT 7 .sdata
8: 000034e4 0 SECTION LOCAL DEFAULT 8 .sbss
9: 000034ec 0 SECTION LOCAL DEFAULT 9 .bss
10: 00000000 0 SECTION LOCAL DEFAULT 10 .comment
11: 00000000 0 SECTION LOCAL DEFAULT 11 .riscv.attributes
12: 00000000 0 SECTION LOCAL DEFAULT 12 .debug_aranges
......@@ -93,76 +93,92 @@ Symbol table '.symtab' contains 93 entries:
20: 00000000 0 FILE LOCAL DEFAULT ABS __call_atexit.c
21: 00000074 24 FUNC LOCAL DEFAULT 1 register_fini
22: 00000000 0 FILE LOCAL DEFAULT ABS crtstuff.c
23: 00002000 0 OBJECT LOCAL DEFAULT 3 __EH_FRAME_BEGIN__
23: 00003000 0 OBJECT LOCAL DEFAULT 3 __EH_FRAME_BEGIN__
24: 000000d8 0 FUNC LOCAL DEFAULT 1 __do_global_dtors_aux
25: 00002474 1 OBJECT LOCAL DEFAULT 9 completed.1
26: 00002034 0 OBJECT LOCAL DEFAULT 5 __do_global_dtor[...]
25: 000034ec 1 OBJECT LOCAL DEFAULT 9 completed.1
26: 0000305c 0 OBJECT LOCAL DEFAULT 5 __do_global_dtor[...]
27: 0000011c 0 FUNC LOCAL DEFAULT 1 frame_dummy
28: 00002478 24 OBJECT LOCAL DEFAULT 9 object.0
29: 00002030 0 OBJECT LOCAL DEFAULT 4 __frame_dummy_in[...]
28: 000034f0 24 OBJECT LOCAL DEFAULT 9 object.0
29: 00003058 0 OBJECT LOCAL DEFAULT 4 __frame_dummy_in[...]
30: 00000000 0 FILE LOCAL DEFAULT ABS console.c
31: 00002464 4 OBJECT LOCAL DEFAULT 7 _uartaddr
32: 0000246c 4 OBJECT LOCAL DEFAULT 8 _uartstate
31: 000034dc 4 OBJECT LOCAL DEFAULT 7 _uartaddr
32: 000034e4 4 OBJECT LOCAL DEFAULT 8 _uartstate
33: 0000013c 60 FUNC LOCAL DEFAULT 1 _canputchar
34: 00000178 64 FUNC LOCAL DEFAULT 1 _haschar
35: 000001b8 88 FUNC LOCAL DEFAULT 1 _putchar
36: 00000210 76 FUNC LOCAL DEFAULT 1 _getchar
37: 0000025c 104 FUNC LOCAL DEFAULT 1 _puts
38: 000002c4 216 FUNC LOCAL DEFAULT 1 _gets
39: 0000039c 348 FUNC LOCAL DEFAULT 1 _d2s
40: 000004f8 424 FUNC LOCAL DEFAULT 1 _h2s
41: 000006a0 252 FUNC LOCAL DEFAULT 1 _s2d
42: 0000079c 312 FUNC LOCAL DEFAULT 1 _s2h
43: 000008d4 140 FUNC LOCAL DEFAULT 1 _strcat
44: 00000960 152 FUNC LOCAL DEFAULT 1 _strncmp
45: 000009f8 64 FUNC LOCAL DEFAULT 1 _buadrateset
46: 00002470 4 OBJECT LOCAL DEFAULT 8 displayaddr
47: 00000a38 628 FUNC LOCAL DEFAULT 1 dispmem
48: 00000cac 124 FUNC LOCAL DEFAULT 1 cycle
49: 00000d28 124 FUNC LOCAL DEFAULT 1 instrcount
50: 00000da4 96 FUNC LOCAL DEFAULT 1 printhelp
51: 00000000 0 FILE LOCAL DEFAULT ABS libgcc2.c
52: 00000000 0 FILE LOCAL DEFAULT ABS exit.c
53: 00000000 0 FILE LOCAL DEFAULT ABS init.c
54: 00000000 0 FILE LOCAL DEFAULT ABS fini.c
55: 00000000 0 FILE LOCAL DEFAULT ABS atexit.c
56: 00000000 0 FILE LOCAL DEFAULT ABS __atexit.c
57: 00000000 0 FILE LOCAL DEFAULT ABS sys_exit.c
58: 00000000 0 FILE LOCAL DEFAULT ABS errno.c
59: 00000000 0 FILE LOCAL DEFAULT ABS libgcc2.c
60: 00000000 0 FILE LOCAL DEFAULT ABS crtstuff.c
61: 00002028 0 OBJECT LOCAL DEFAULT 3 __FRAME_END__
62: 00000000 0 FILE LOCAL DEFAULT ABS impure.c
63: 00002038 1064 OBJECT LOCAL DEFAULT 6 impure_data
64: 00000000 0 FILE LOCAL DEFAULT ABS
65: 00002038 0 NOTYPE LOCAL DEFAULT 5 __fini_array_end
66: 00002034 0 NOTYPE LOCAL DEFAULT 5 __fini_array_start
67: 00002034 0 NOTYPE LOCAL DEFAULT 4 __init_array_end
68: 0000202c 0 NOTYPE LOCAL DEFAULT 4 __preinit_array_end
69: 0000202c 0 NOTYPE LOCAL DEFAULT 4 __init_array_start
70: 0000202c 0 NOTYPE LOCAL DEFAULT 4 __preinit_array_start
71: 00002838 0 NOTYPE GLOBAL DEFAULT ABS __global_pointer$
72: 00001ac8 8 FUNC GLOBAL DEFAULT 1 __errno
73: 00002460 0 NOTYPE GLOBAL DEFAULT 7 __SDATA_BEGIN__
74: 00002460 4 OBJECT GLOBAL DEFAULT 7 _global_impure_ptr
75: 000016f8 156 FUNC GLOBAL DEFAULT 1 __libc_init_array
76: 00001298 1072 FUNC GLOBAL HIDDEN 1 __udivdi3
77: 00001990 92 FUNC GLOBAL DEFAULT 1 __libc_fini_array
78: 00001870 288 FUNC GLOBAL DEFAULT 1 __call_exitprocs
79: 0000008c 76 FUNC GLOBAL DEFAULT 1 _start
80: 00001a00 152 FUNC GLOBAL DEFAULT 1 __register_exitproc
81: 00002490 0 NOTYPE GLOBAL DEFAULT 9 __BSS_END__
82: 0000246c 0 NOTYPE GLOBAL DEFAULT 8 __bss_start
83: 00001794 220 FUNC GLOBAL DEFAULT 1 memset
84: 00000e04 1172 FUNC GLOBAL DEFAULT 1 main
85: 00001be0 256 OBJECT GLOBAL HIDDEN 2 __clz_tab
86: 000019ec 20 FUNC GLOBAL DEFAULT 1 atexit
87: 00002468 4 OBJECT GLOBAL DEFAULT 7 _impure_ptr
88: 00002038 0 NOTYPE GLOBAL DEFAULT 6 __DATA_BEGIN__
89: 0000246c 0 NOTYPE GLOBAL DEFAULT 7 _edata
90: 00002490 0 NOTYPE GLOBAL DEFAULT 9 _end
91: 000016c8 48 FUNC GLOBAL DEFAULT 1 exit
92: 00001a98 48 FUNC GLOBAL DEFAULT 1 _exit
39: 0000039c 512 FUNC LOCAL DEFAULT 1 _d2s
40: 0000059c 424 FUNC LOCAL DEFAULT 1 _h2s
41: 00000744 252 FUNC LOCAL DEFAULT 1 _s2d
42: 00000840 312 FUNC LOCAL DEFAULT 1 _s2h
43: 00000978 140 FUNC LOCAL DEFAULT 1 _strcat
44: 00000a04 152 FUNC LOCAL DEFAULT 1 _strncmp
45: 00000a9c 64 FUNC LOCAL DEFAULT 1 _buadrateset
46: 000034e8 4 OBJECT LOCAL DEFAULT 8 displayaddr
47: 00000adc 628 FUNC LOCAL DEFAULT 1 dispmem
48: 00000d50 124 FUNC LOCAL DEFAULT 1 cycle
49: 00000dcc 124 FUNC LOCAL DEFAULT 1 instrcount
50: 00000e48 124 FUNC LOCAL DEFAULT 1 get_counter_addsub
51: 00000ec4 124 FUNC LOCAL DEFAULT 1 get_counter_mul
52: 00000f40 124 FUNC LOCAL DEFAULT 1 get_counter_div
53: 00000fbc 124 FUNC LOCAL DEFAULT 1 get_counter_ld
54: 00001038 124 FUNC LOCAL DEFAULT 1 get_counter_st
55: 000010b4 124 FUNC LOCAL DEFAULT 1 get_counter_jmp
56: 00001130 124 FUNC LOCAL DEFAULT 1 get_counter_j
57: 000011ac 124 FUNC LOCAL DEFAULT 1 get_counter_alui
58: 00001228 124 FUNC LOCAL DEFAULT 1 get_counter_alu
59: 000012a4 340 FUNC LOCAL DEFAULT 1 liststatus
60: 000013f8 96 FUNC LOCAL DEFAULT 1 printhelp
61: 00000000 0 FILE LOCAL DEFAULT ABS libgcc2.c
62: 00000000 0 FILE LOCAL DEFAULT ABS libgcc2.c
63: 00000000 0 FILE LOCAL DEFAULT ABS libgcc2.c
64: 00000000 0 FILE LOCAL DEFAULT ABS exit.c
65: 00000000 0 FILE LOCAL DEFAULT ABS init.c
66: 00000000 0 FILE LOCAL DEFAULT ABS fini.c
67: 00000000 0 FILE LOCAL DEFAULT ABS atexit.c
68: 00000000 0 FILE LOCAL DEFAULT ABS __atexit.c
69: 00000000 0 FILE LOCAL DEFAULT ABS sys_exit.c
70: 00000000 0 FILE LOCAL DEFAULT ABS errno.c
71: 00000000 0 FILE LOCAL DEFAULT ABS libgcc2.c
72: 00000000 0 FILE LOCAL DEFAULT ABS crtstuff.c
73: 00003050 0 OBJECT LOCAL DEFAULT 3 __FRAME_END__
74: 00000000 0 FILE LOCAL DEFAULT ABS impure.c
75: 000030b0 1064 OBJECT LOCAL DEFAULT 6 impure_data
76: 00000000 0 FILE LOCAL DEFAULT ABS
77: 00003060 0 NOTYPE LOCAL DEFAULT 5 __fini_array_end
78: 0000305c 0 NOTYPE LOCAL DEFAULT 5 __fini_array_start
79: 0000305c 0 NOTYPE LOCAL DEFAULT 4 __init_array_end
80: 00003054 0 NOTYPE LOCAL DEFAULT 4 __preinit_array_end
81: 00003054 0 NOTYPE LOCAL DEFAULT 4 __init_array_start
82: 00003054 0 NOTYPE LOCAL DEFAULT 4 __preinit_array_start
83: 00001948 1144 FUNC GLOBAL HIDDEN 1 __divdi3
84: 00003860 0 NOTYPE GLOBAL DEFAULT ABS __global_pointer$
85: 00002a40 8 FUNC GLOBAL DEFAULT 1 __errno
86: 000034d8 0 NOTYPE GLOBAL DEFAULT 7 __SDATA_BEGIN__
87: 000034d8 4 OBJECT GLOBAL DEFAULT 7 _global_impure_ptr
88: 00002670 156 FUNC GLOBAL DEFAULT 1 __libc_init_array
89: 00002210 1072 FUNC GLOBAL HIDDEN 1 __udivdi3
90: 00002908 92 FUNC GLOBAL DEFAULT 1 __libc_fini_array
91: 000027e8 288 FUNC GLOBAL DEFAULT 1 __call_exitprocs
92: 0000008c 76 FUNC GLOBAL DEFAULT 1 _start
93: 00002978 152 FUNC GLOBAL DEFAULT 1 __register_exitproc
94: 00003088 40 OBJECT GLOBAL DEFAULT 6 statusname
95: 00003508 0 NOTYPE GLOBAL DEFAULT 9 __BSS_END__
96: 000034e4 0 NOTYPE GLOBAL DEFAULT 8 __bss_start
97: 0000270c 220 FUNC GLOBAL DEFAULT 1 memset
98: 00001458 1264 FUNC GLOBAL DEFAULT 1 main
99: 00002bd4 256 OBJECT GLOBAL HIDDEN 2 __clz_tab
100: 00002964 20 FUNC GLOBAL DEFAULT 1 atexit
101: 000034e0 4 OBJECT GLOBAL DEFAULT 7 _impure_ptr
102: 00003060 0 NOTYPE GLOBAL DEFAULT 6 __DATA_BEGIN__
103: 000034e4 0 NOTYPE GLOBAL DEFAULT 7 _edata
104: 00003508 0 NOTYPE GLOBAL DEFAULT 9 _end
105: 00003060 40 OBJECT GLOBAL DEFAULT 6 statusgetfuncs
106: 00002640 48 FUNC GLOBAL DEFAULT 1 exit
107: 00001dc0 1104 FUNC GLOBAL HIDDEN 1 __moddi3
108: 00002a10 48 FUNC GLOBAL DEFAULT 1 _exit
No version information found in this file.
Attribute Section: riscv
......
......@@ -45,6 +45,8 @@
`define RAMSIZE 4096
`define CSROPCOUNTER
(*
HDL4SE="LCOM",
CLSID="638E8BC3-B0E0-41DC-9EDD-D35A39FD8051",
......@@ -89,32 +91,58 @@ module riscv_core(
/* CSR register */
reg [31:0] misa; /*0301*/
reg [31:0] ucycle; /*0c00*/
reg [31:0] utime; /*0c01*/
reg [31:0] uinstret; /*0c02*/
reg [31:0] ucycleh; /*0c80*/
reg [31:0] utimeh; /*0c81*/
reg [31:0] uinstreth; /*0c82*/
reg [31:0] mcycle; /*0b00*/
reg [31:0] minstret; /*0b02*/
reg [31:0] mcycleh; /*0b80*/
reg [31:0] minstreth; /*0b82*/
reg [63:0] ucycle64; /*0c00/0c80*/
reg [63:0] utime64; /*0c01/0c81*/
reg [63:0] uinstret64; /*0c02/0c82*/
reg [63:0] mcycle64; /*0b00/0b80*/
reg [63:0] minstret64; /*0b02/0b82*/
`ifdef CSROPCOUNTER
reg [63:0] opcounter_addsub64; /*0c20/0ca0*/
reg [63:0] opcounter_mul64; /*0c21/0ca0*/
reg [63:0] opcounter_div64; /*0c22/0ca0*/
reg [63:0] opcounter_ld64; /*0c23/0ca0*/
reg [63:0] opcounter_st64; /*0c24/0ca0*/
reg [63:0] opcounter_jmp64; /*0c25/0ca0*/
reg [63:0] opcounter_j64; /*0c26/0ca0*/
reg [63:0] opcounter_alui64; /* 0c27/0ca7*/
reg [63:0] opcounter_alu64; /* 0c28/0ca8*/
`endif
reg [31:0] csr_r;
always @(posedge wClk)
if (state == `RISCVSTATE_READ_REGS)
case (bReadData[31:20])
12'h301: csr_r <= misa;
12'hc00: csr_r <= ucycle;
12'hc01: csr_r <= utime;
12'hc02: csr_r <= uinstret;
12'hc80: csr_r <= ucycleh;
12'hc81: csr_r <= utimeh;
12'hc82: csr_r <= uinstreth;
12'hb00: csr_r <= mcycle;
12'hb02: csr_r <= minstret;
12'hb80: csr_r <= mcycleh;
12'hb82: csr_r <= minstreth;
12'hc00: csr_r <= ucycle64[31:0];
12'hc80: csr_r <= ucycle64[63:32];
12'hc01: csr_r <= utime64[31:0];
12'hc81: csr_r <= utime64[63:32];
12'hc02: csr_r <= uinstret64[31:0];
12'hc82: csr_r <= uinstret64[63:32];
12'hb00: csr_r <= mcycle64[31:0];
12'hb80: csr_r <= mcycle64[63:32];
12'hb02: csr_r <= minstret64[31:0];
12'hb82: csr_r <= minstret64[63:32];
`ifdef CSROPCOUNTER
12'hc20: csr_r <= opcounter_addsub64[31:0];
12'hca0: csr_r <= opcounter_addsub64[63:32];
12'hc21: csr_r <= opcounter_mul64[31:0];
12'hca1: csr_r <= opcounter_mul64[63:32];
12'hc22: csr_r <= opcounter_div64[31:0];
12'hca2: csr_r <= opcounter_div64[63:32];
12'hc23: csr_r <= opcounter_ld64[31:0];
12'hca3: csr_r <= opcounter_ld64[63:32];
12'hc24: csr_r <= opcounter_st64[31:0];
12'hca4: csr_r <= opcounter_st64[63:32];
12'hc25: csr_r <= opcounter_jmp64[31:0];
12'hca5: csr_r <= opcounter_jmp64[63:32];
12'hc26: csr_r <= opcounter_j64[31:0];
12'hca6: csr_r <= opcounter_j64[63:32];
12'hc27: csr_r <= opcounter_alui64[31:0];
12'hca7: csr_r <= opcounter_alui64[63:32];
12'hc28: csr_r <= opcounter_alu64[31:0];
12'hca8: csr_r <= opcounter_alu64[63:32];
`endif
default: csr_r <= 0;
endcase
......@@ -131,18 +159,15 @@ module riscv_core(
wire [31:0] rs2 = regrddata2;
wire signed [31:0] rs1_s = rs1;
wire signed [31:0] rs2_s = rs2;
wire [31:0] rs1_abs = rs1[31] ? (-rs1_s) : rs1_s;
wire [31:0] rs2_abs = rs2[31] ? (-rs2_s) : rs2_s;
wire signed [31:0] imm_s = imm;
wire [31:0] add_result;
wire [31:0] sub_result;
wire [63:0] mul_result;
wire [63:0] muls_result;
wire [71:0] mulsu_result;
wire [31:0] div_result_r, mod_result_r, divs_result_r, mods_result_r;
wire [31:0] div_result, mod_result, divs_result, mods_result;
adder add(rs1, rs2, add_result);
suber sub(rs1, rs2, sub_result);
`define USE3MUL
`ifdef USE3MUL
......@@ -152,8 +177,6 @@ module riscv_core(
`else
wire signed [63:0] mul_result_sign = mul_result;
reg [31:0] mul_rs1, mul_rs2;
wire [31:0] rs1_abs = rs1[31] ? (~rs1 + 1) : rs1;
wire [31:0] rs2_abs = rs2[31] ? (~rs2 + 1) : rs2;
mult mul(mul_rs1, mul_rs2, mul_result);
......@@ -207,35 +230,19 @@ module riscv_core(
Total combinational functions 7,107 / 114,480 ( 6 % )
Dedicated logic registers 4,309 / 114,480 ( 4 % )
Total registers 4309
Total memory bits 151,274 / 3,981,312 ( 4 % )
Embedded Multiplier 9-bit elements 0 / 532 ( 0 % )
一个除法器:
Total logic elements 6,264 / 114,480 ( 5 % )
Total combinational functions 5,607 / 114,480 ( 5 % )
Total logic elements 6,319 / 114,480 ( 6 % )
Total combinational functions 5,601 / 114,480 ( 5 % )
Dedicated logic registers 2,916 / 114,480 ( 3 % )
Total registers 2916
Embedded Multiplier 9-bit elements 0 / 532 ( 0 % )
去掉两个乘法器:(比较怪异的是,逻辑门数反而增加了,这个很奇怪,难度综合的时候它能合并乘法器?)
Total logic elements 6,331 / 114,480 ( 6 % )
Total combinational functions 5,609 / 114,480 ( 5 % )
Dedicated logic registers 2,917 / 114,480 ( 3 % )
Total registers 2917
Total memory bits 150,192 / 3,981,312 ( 4 % )
Embedded Multiplier 9-bit elements 0 / 532 ( 0 % )
Total logic elements 6,238 / 114,480 ( 5 % )
Total combinational functions 5,527 / 114,480 ( 5 % )
Dedicated logic registers 2,916 / 114,480 ( 3 % )
Total registers 2916
Total pins 436 / 529 ( 82 % )
Total virtual pins 0
Total memory bits 150,192 / 3,981,312 ( 4 % )
Embedded Multiplier 9-bit elements 0 / 532 ( 0 % )
Total PLLs 1 / 4 ( 25 % )
*/
`define USE1DIV_
`define USE1DIV
`ifdef USE1DIV
wire div_unsign_op = func3[0];
......@@ -539,72 +546,101 @@ module riscv_core(
default: begin csr_v = 0; csr_op = 0; end
endcase
//DEFINE_FUNC(riscv_core_gen_csr, "nwReset, ucycle, ucycleh, misa, mcycle, mcycleh, utime,utimeh, uinstret, uinstreth, minstret, minstreth, instr, imm, regrddata") {
//DEFINE_FUNC(riscv_core_gen_csr, "nwReset, ucycle64, misa, mcycle64, utime64, uinstret64, minstret64, instr, imm, regrddata") {
always @(posedge wClk)
if (nwReset == 0) begin
misa <= 32'b0100_0000_0001_0000_0001_0001_0000_0000;// RV32IM
ucycle <= 0;
ucycleh <= 0;
mcycle <= 0;
mcycleh <= 0;
utime <= 0;
utimeh <= 0;
uinstret <= 0;
uinstreth <= 0;
minstret <= 0;
minstreth <= 0;
ucycle64 <= 0;
mcycle64 <= 0;
utime64 <= 0;
uinstret64 <= 0;
minstret64 <= 0;
`ifdef CSROPCOUNTER
opcounter_addsub64 <= 0;
opcounter_alui64 <= 0;
opcounter_alu64 <= 0;
opcounter_mul64 <= 0;
opcounter_div64 <= 0;
opcounter_ld64 <= 0;
opcounter_st64 <= 0;
opcounter_jmp64 <= 0;
opcounter_j64 <= 0;
`endif
end
else begin
if (ucycle == 32'hffffffff) begin
ucycleh <= ucycleh + 1;
ucycle <= 0;
end
else begin
ucycle <= ucycle + 1;
end
if (utime == 32'hffffffff) begin
utimeh <= utimeh + 1;
utime <= 0;
end
else begin
utime <= utime + 1;
end
if (mcycle == 32'hffffffff) begin
mcycleh <= mcycleh + 1;
mcycle <= 0;
end
else begin
mcycle <= mcycle + 1;
end
ucycle64 <= ucycle64 + 1;
utime64 <= utime64 + 1;
mcycle64 <= mcycle64 + 1;
if (state == `RISCVSTATE_EXEC_INST) begin
if (uinstret == 32'hffffffff) begin
uinstreth <= uinstreth + 1;
uinstret <= 0;
end
else begin
uinstret <= uinstret + 1;
end
if (minstret == 32'hffffffff) begin
minstreth <= minstreth + 1;
minstret <= 0;
end
else begin
minstret <= minstret + 1;
uinstret64 <= uinstret64 + 1;
minstret64 <= minstret64 + 1;
`ifdef CSROPCOUNTER
case (opcode)
5'h0d: ;//riscv_core_exec_lui_inst(pobj, pc, instr); break;
5'h05: ;//riscv_core_exec_auipc_inst(pobj, pc, instr); break;
5'h1b: //riscv_core_exec_jal_inst(pobj, pc, instr); break;
opcounter_jmp64 <= opcounter_jmp64 + 1;
5'h19: //riscv_core_exec_jalr_inst(pobj, pc, instr); break;
opcounter_jmp64 <= opcounter_jmp64 + 1;
5'h18: //riscv_core_exec_b_inst(pobj, pc, instr); break;
opcounter_j64 <= opcounter_j64 + 1;
5'h00: //riscv_core_exec_ld_inst(pobj, pc, instr); break;
opcounter_ld64 <= opcounter_ld64 + 1;
5'h08: //riscv_core_exec_st_inst(pobj, pc, instr); break;
opcounter_st64 <= opcounter_st64 + 1;
5'h04: //riscv_core_exec_alui_inst(pobj, pc, instr); break;
opcounter_alui64 <= opcounter_alui64 + 1;
5'h0c: begin //riscv_core_exec_alu_inst(pobj, pc, instr); break;
opcounter_alu64 <= opcounter_alu64 + 1;
if (instr[25]) begin/* MUL/DIV */
if (func3[2]) begin
opcounter_div64 <= opcounter_div64 + 1;
end else begin
opcounter_mul64 <= opcounter_mul64 + 1;
end
end else begin
if (func3 == 0)
opcounter_addsub64 <= opcounter_addsub64 + 1;
end
end
5'h03: ;//riscv_core_exec_fence_inst(pobj, pc, instr); break;
5'h1c: ;//riscv_core_exec_sys_inst(pobj, pc, instr); break;
endcase
`endif
if (opcode == 5'h1c) begin /* CSR */
if (csr_op) begin
case (instr[31:20])
12'h301: misa <= csr_v;
12'hc00: ucycle <= csr_v;
12'hc01: utime <= csr_v;
12'hc02: uinstret <= csr_v;
12'hc80: ucycleh <= csr_v;
12'hc81: utimeh <= csr_v;
12'hc82: uinstreth <= csr_v;
12'hb00: mcycle <= csr_v;
12'hb02: minstret <= csr_v;
12'hb80: mcycleh <= csr_v;
12'hb82: minstreth <= csr_v;
12'hc00: ucycle64[31:0] <= csr_v;
12'hc80: ucycle64[63:32] <= csr_v;
12'hc01: utime64[31:0] <= csr_v;
12'hc81: utime64[63:32] <= csr_v;
12'hc02: uinstret64[31:0] <= csr_v;
12'hc82: uinstret64[63:32] <= csr_v;
12'hb00: mcycle64[31:0] <= csr_v;
12'hb80: mcycle64[63:32] <= csr_v;
12'hb02: minstret64[31:0] <= csr_v;
12'hb82: minstret64[63:32] <= csr_v;
`ifdef CSROPCOUNTER
12'hc20: opcounter_addsub64[31:0] <= csr_v;
12'hca0: opcounter_addsub64[63:32] <= csr_v;
12'hc21: opcounter_mul64[31:0] <= csr_v;
12'hca1: opcounter_mul64[63:32] <= csr_v;
12'hc22: opcounter_div64[31:0] <= csr_v;
12'hca2: opcounter_div64[63:32] <= csr_v;
12'hc23: opcounter_ld64[31:0] <= csr_v;
12'hca3: opcounter_ld64[63:32] <= csr_v;
12'hc24: opcounter_st64[31:0] <= csr_v;
12'hca4: opcounter_st64[63:32] <= csr_v;
12'hc25: opcounter_jmp64[31:0] <= csr_v;
12'hca5: opcounter_jmp64[63:32] <= csr_v;
12'hc26: opcounter_j64[31:0] <= csr_v;
12'hca6: opcounter_j64[63:32] <= csr_v;
12'hc27: opcounter_alui64[31:0] <= csr_v;
12'hca7: opcounter_alui64[63:32] <= csr_v;
12'hc28: opcounter_alu64[31:0] <= csr_v;
12'hca8: opcounter_alu64[63:32] <= csr_v;
`endif
endcase
end
end
......@@ -684,7 +720,6 @@ module riscv_core(
//DEFINE_FUNC(riscv_core_gen_dstreg, "state, instr, ldaddr, readreg, bReadData, pc, rs1, regrddata, imm") {
always @(state or readreg or instr or func3 or ldaddr or bReadData or rd or rs1 or rs2 or rs1_s or rs2_s or lastv or divclk
or divs_result or div_result or mods_result or mod_result or muls_result or mulsu_result or mul_result
or sub_result or add_result
or opcode or imm or pc) begin
dstreg = 0;
dstvalue = 0;
......@@ -896,11 +931,9 @@ module riscv_core(
case (func3)
0: begin
if (instr[30])
dstvalue = sub_result;
//rs1 - rs2;//sub_result;
dstvalue = rs1 - rs2;
else
dstvalue = add_result;
//rs1 + rs2;//add_result;
dstvalue = rs1 + rs2;
end
1: begin //sll
dstvalue = rs1 << rs2[4:0];
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册