Posts: 14
Threads: 7
Joined: Jun 2020
Hi,
I am trying to compile a simple code which has global arrays. I have initialized all the global arrays to make sure the compiler does not generate the code to initialize them to 0. However, I am still getting these "memset" calls in the _start section of the assembly.
Code: Disassembly of section .text:
1c000000 <_start>:
1c000000: 00001197 auipc gp,0x1
1c000004: 18018193 addi gp,gp,384 # 1c001180 <__global_pointer$>
1c000008: 00001517 auipc a0,0x1
1c00000c: 95850513 addi a0,a0,-1704 # 1c000960 <__FRAME_END__>
1c000010: 00001617 auipc a2,0x1
1c000014: 97060613 addi a2,a2,-1680 # 1c000980 <completed.1>
1c000018: 40a60633 sub a2,a2,a0
1c00001c: 00000593 li a1,0
1c000020: 1a8000ef jal ra,1c0001c8 <memset>
1c000024: 00000517 auipc a0,0x0
The program is not return to start section after executing till 1C0001f8
Code: 1c0001c8 <memset>:
1c0001c8: 00f00313 li t1,15
1c0001cc: 00050713 mv a4,a0
1c0001d0: 02c37e63 bgeu t1,a2,1c00020c <memset+0x44>
1c0001d4: 00f77793 andi a5,a4,15
1c0001d8: 0a079063 bnez a5,1c000278 <memset+0xb0>
1c0001dc: 08059263 bnez a1,1c000260 <memset+0x98>
1c0001e0: ff067693 andi a3,a2,-16
1c0001e4: 00f67613 andi a2,a2,15
1c0001e8: 00e686b3 add a3,a3,a4
1c0001ec: 00b72023 sw a1,0(a4)
1c0001f0: 00b72223 sw a1,4(a4)
1c0001f4: 00b72423 sw a1,8(a4)
1c0001f8: 00b72623 sw a1,12(a4)
1c0001fc: 01070713 addi a4,a4,16
1c000200: fed766e3 bltu a4,a3,1c0001ec <memset+0x24>
1c000204: 00061463 bnez a2,1c00020c <memset+0x44>
What should I do to load complete hex file to my verilator model? how can I get rid of this memset? I tried with
PHP Code: <?php
-fno-zero-initialized-in-bss
in my gcc, but not solved my issue. Currently using riscv gnu toolchain 10.1.0.
Posts: 43
Threads: 0
Joined: Mar 2019
Is this the crt0.S code you are showing? If so, that is written in assembly and thus might contain the calls to memset.
Posts: 14
Threads: 7
Joined: Jun 2020
09-11-2020, 02:09 PM
(This post was last modified: 09-11-2020, 02:26 PM by RiscV.)
No.. This is not crt0.s code, the above showing is my program code disassembly section.
Code: #include "newlib.h"
#=========================================================================
# crt0.S : Entry point for RISC-V user programs
#=========================================================================
.text
.global _start
.type _start, @function
_start:
# Initialize global pointer
.option push
.option norelax
1:auipc gp, %pcrel_hi(__global_pointer$)
addi gp, gp, %pcrel_lo(1b)
.option pop
# Clear the bss segment
la a0, _edata
la a2, _end
sub a2, a2, a0
li a1, 0
call memset
#ifdef _LITE_EXIT
# Make reference to atexit weak to avoid unconditionally pulling in
# support code. Refer to comments in __atexit.c for more details.
.weak atexit
la a0, atexit
beqz a0, .Lweak_atexit
.weak __libc_fini_array
#endif
la a0, __libc_fini_array # Register global termination functions
call atexit # to be called upon exit
#ifdef _LITE_EXIT
.Lweak_atexit:
#endif
call __libc_init_array # Run global initialization functions
lw a0, 0(sp) # a0 = argc
addi a1, sp, __SIZEOF_POINTER__ # a1 = argv
crt0.S code
my Program code
Code: add3.out: file format elf32-littleriscv
Disassembly of section .text:
1c000000 <_start>:
1c000000: 00001197 auipc gp,0x1
1c000004: 1a018193 addi gp,gp,416 # 1c0011a0 <__global_pointer$>
1c000008: 00001517 auipc a0,0x1
1c00000c: 98c50513 addi a0,a0,-1652 # 1c000994 <_edata>
1c000010: 00001617 auipc a2,0x1
1c000014: 99060613 addi a2,a2,-1648 # 1c0009a0 <_end>
1c000018: 40a60633 sub a2,a2,a0
1c00001c: 00000593 li a1,0
1c000020: 1a8000ef jal ra,1c0001c8 <memset>
1c000024: 00000517 auipc a0,0x0
1c000028: 3f850513 addi a0,a0,1016 # 1c00041c <atexit>
1c00002c: 00050863 beqz a0,1c00003c <_start+0x3c>
1c000030: 00000517 auipc a0,0x0
1c000034: 39850513 addi a0,a0,920 # 1c0003c8 <__libc_fini_array>
1c000038: 3e4000ef jal ra,1c00041c <atexit>
1c00003c: 100000ef jal ra,1c00013c <__libc_init_array>
1c000040: 00012503 lw a0,0(sp)
1c000044: 00410593 addi a1,sp,4
1c000048: 00000613 li a2,0
1c00004c: 07c000ef jal ra,1c0000c8 <main>
1c000050: 0b80006f j 1c000108 <exit>
1c000054 <__do_global_dtors_aux>:
1c000054: 1c0017b7 lui a5,0x1c001
1c000058: 9787c703 lbu a4,-1672(a5) # 1c000978 <completed.1>
1c00005c: 04071263 bnez a4,1c0000a0 <__do_global_dtors_aux+0x4c>
1c000060: ff010113 addi sp,sp,-16
1c000064: 00812423 sw s0,8(sp)
1c000068: 00078413 mv s0,a5
1c00006c: 00112623 sw ra,12(sp)
1c000070: 00000793 li a5,0
1c000074: 00078a63 beqz a5,1c000088 <__do_global_dtors_aux+0x34>
1c000078: 1c001537 lui a0,0x1c001
1c00007c: 96050513 addi a0,a0,-1696 # 1c000960 <__FRAME_END__>
1c000080: 00000097 auipc ra,0x0
1c000084: 000000e7 jalr zero # 0 <_start-0x1c000000>
1c000088: 00100793 li a5,1
1c00008c: 00c12083 lw ra,12(sp)
1c000090: 96f40c23 sb a5,-1672(s0)
1c000094: 00812403 lw s0,8(sp)
1c000098: 01010113 addi sp,sp,16
1c00009c: 00008067 ret
1c0000a0: 00008067 ret
1c0000a4 <frame_dummy>:
1c0000a4: 00000793 li a5,0
1c0000a8: 00078e63 beqz a5,1c0000c4 <frame_dummy+0x20>
1c0000ac: 1c0015b7 lui a1,0x1c001
1c0000b0: 1c001537 lui a0,0x1c001
1c0000b4: 97c58593 addi a1,a1,-1668 # 1c00097c <object.0>
1c0000b8: 96050513 addi a0,a0,-1696 # 1c000960 <__FRAME_END__>
1c0000bc: 00000317 auipc t1,0x0
1c0000c0: 00000067 jr zero # 0 <_start-0x1c000000>
1c0000c4: 00008067 ret
1c0000c8 <main>:
1c0000c8: fe010113 addi sp,sp,-32
1c0000cc: 00812e23 sw s0,28(sp)
1c0000d0: 02010413 addi s0,sp,32
1c0000d4: 02000793 li a5,32
1c0000d8: fef42623 sw a5,-20(s0)
1c0000dc: 01700793 li a5,23
1c0000e0: fef42423 sw a5,-24(s0)
1c0000e4: fec42703 lw a4,-20(s0)
1c0000e8: fe842783 lw a5,-24(s0)
1c0000ec: 00f707b3 add a5,a4,a5
1c0000f0: fef42223 sw a5,-28(s0)
1c0000f4: 00000793 li a5,0
1c0000f8: 00078513 mv a0,a5
1c0000fc: 01c12403 lw s0,28(sp)
1c000100: 02010113 addi sp,sp,32
1c000104: 00008067 ret
1c000108 <exit>:
1c000108: ff010113 addi sp,sp,-16
1c00010c: 00000593 li a1,0
1c000110: 00812423 sw s0,8(sp)
1c000114: 00112623 sw ra,12(sp)
1c000118: 00050413 mv s0,a0
1c00011c: 188000ef jal ra,1c0002a4 <__call_exitprocs>
1c000120: 1c0007b7 lui a5,0x1c000
1c000124: 5347a503 lw a0,1332(a5) # 1c000534 <_global_impure_ptr>
1c000128: 03c52783 lw a5,60(a0)
1c00012c: 00078463 beqz a5,1c000134 <exit+0x2c>
1c000130: 000780e7 jalr a5
1c000134: 00040513 mv a0,s0
1c000138: 394000ef jal ra,1c0004cc <_exit>
1c00013c <__libc_init_array>:
1c00013c: ff010113 addi sp,sp,-16
1c000140: 00812423 sw s0,8(sp)
1c000144: 01212023 sw s2,0(sp)
1c000148: 00000793 li a5,0
1c00014c: 00000913 li s2,0
1c000150: 40f90933 sub s2,s2,a5
1c000154: 00112623 sw ra,12(sp)
1c000158: 00912223 sw s1,4(sp)
1c00015c: 40295913 srai s2,s2,0x2
1c000160: 02090063 beqz s2,1c000180 <__libc_init_array+0x44>
1c000164: 00000413 li s0,0
1c000168: 00000493 li s1,0
1c00016c: 00042783 lw a5,0(s0)
1c000170: 00148493 addi s1,s1,1
1c000174: 00440413 addi s0,s0,4
1c000178: 000780e7 jalr a5
1c00017c: fe9918e3 bne s2,s1,1c00016c <__libc_init_array+0x30>
1c000180: 00000793 li a5,0
1c000184: 00000913 li s2,0
1c000188: 40f90933 sub s2,s2,a5
1c00018c: 40295913 srai s2,s2,0x2
1c000190: 02090063 beqz s2,1c0001b0 <__libc_init_array+0x74>
1c000194: 00000413 li s0,0
1c000198: 00000493 li s1,0
1c00019c: 00042783 lw a5,0(s0)
1c0001a0: 00148493 addi s1,s1,1
1c0001a4: 00440413 addi s0,s0,4
1c0001a8: 000780e7 jalr a5
1c0001ac: fe9918e3 bne s2,s1,1c00019c <__libc_init_array+0x60>
1c0001b0: 00c12083 lw ra,12(sp)
1c0001b4: 00812403 lw s0,8(sp)
1c0001b8: 00412483 lw s1,4(sp)
1c0001bc: 00012903 lw s2,0(sp)
1c0001c0: 01010113 addi sp,sp,16
1c0001c4: 00008067 ret
1c0001c8 <memset>:
1c0001c8: 00f00313 li t1,15
1c0001cc: 00050713 mv a4,a0
1c0001d0: 02c37e63 bgeu t1,a2,1c00020c <memset+0x44>
1c0001d4: 00f77793 andi a5,a4,15
1c0001d8: 0a079063 bnez a5,1c000278 <memset+0xb0>
1c0001dc: 08059263 bnez a1,1c000260 <memset+0x98>
1c0001e0: ff067693 andi a3,a2,-16
1c0001e4: 00f67613 andi a2,a2,15
1c0001e8: 00e686b3 add a3,a3,a4
1c0001ec: 00b72023 sw a1,0(a4)
1c0001f0: 00b72223 sw a1,4(a4)
1c0001f4: 00b72423 sw a1,8(a4)
1c0001f8: 00b72623 sw a1,12(a4)
1c0001fc: 01070713 addi a4,a4,16
1c000200: fed766e3 bltu a4,a3,1c0001ec <memset+0x24>
1c000204: 00061463 bnez a2,1c00020c <memset+0x44>
1c000208: 00008067 ret
1c00020c: 40c306b3 sub a3,t1,a2
1c000210: 00269693 slli a3,a3,0x2
1c000214: 00000297 auipc t0,0x0
1c000218: 005686b3 add a3,a3,t0
1c00021c: 00c68067 jr 12(a3)
1c000220: 00b70723 sb a1,14(a4)
1c000224: 00b706a3 sb a1,13(a4)
1c000228: 00b70623 sb a1,12(a4)
1c00022c: 00b705a3 sb a1,11(a4)
1c000230: 00b70523 sb a1,10(a4)
1c000234: 00b704a3 sb a1,9(a4)
1c000238: 00b70423 sb a1,8(a4)
1c00023c: 00b703a3 sb a1,7(a4)
1c000240: 00b70323 sb a1,6(a4)
1c000244: 00b702a3 sb a1,5(a4)
1c000248: 00b70223 sb a1,4(a4)
1c00024c: 00b701a3 sb a1,3(a4)
1c000250: 00b70123 sb a1,2(a4)
1c000254: 00b700a3 sb a1,1(a4)
1c000258: 00b70023 sb a1,0(a4)
1c00025c: 00008067 ret
1c000260: 0ff5f593 andi a1,a1,255
1c000264: 00859693 slli a3,a1,0x8
1c000268: 00d5e5b3 or a1,a1,a3
1c00026c: 01059693 slli a3,a1,0x10
1c000270: 00d5e5b3 or a1,a1,a3
1c000274: f6dff06f j 1c0001e0 <memset+0x18>
1c000278: 00279693 slli a3,a5,0x2
1c00027c: 00000297 auipc t0,0x0
1c000280: 005686b3 add a3,a3,t0
1c000284: 00008293 mv t0,ra
1c000288: fa0680e7 jalr -96(a3)
1c00028c: 00028093 mv ra,t0
1c000290: ff078793 addi a5,a5,-16
1c000294: 40f70733 sub a4,a4,a5
1c000298: 00f60633 add a2,a2,a5
1c00029c: f6c378e3 bgeu t1,a2,1c00020c <memset+0x44>
1c0002a0: f3dff06f j 1c0001dc <memset+0x14>
1c0002a4 <__call_exitprocs>:
1c0002a4: fd010113 addi sp,sp,-48
1c0002a8: 1c0007b7 lui a5,0x1c000
1c0002ac: 01412c23 sw s4,24(sp)
1c0002b0: 5347aa03 lw s4,1332(a5) # 1c000534 <_global_impure_ptr>
1c0002b4: 03212023 sw s2,32(sp)
1c0002b8: 02112623 sw ra,44(sp)
1c0002bc: 148a2903 lw s2,328(s4)
1c0002c0: 02812423 sw s0,40(sp)
1c0002c4: 02912223 sw s1,36(sp)
1c0002c8: 01312e23 sw s3,28(sp)
1c0002cc: 01512a23 sw s5,20(sp)
1c0002d0: 01612823 sw s6,16(sp)
1c0002d4: 01712623 sw s7,12(sp)
1c0002d8: 01812423 sw s8,8(sp)
1c0002dc: 04090063 beqz s2,1c00031c <__call_exitprocs+0x78>
1c0002e0: 00050b13 mv s6,a0
1c0002e4: 00058b93 mv s7,a1
1c0002e8: 00100a93 li s5,1
1c0002ec: fff00993 li s3,-1
1c0002f0: 00492483 lw s1,4(s2)
1c0002f4: fff48413 addi s0,s1,-1
1c0002f8: 02044263 bltz s0,1c00031c <__call_exitprocs+0x78>
1c0002fc: 00249493 slli s1,s1,0x2
1c000300: 009904b3 add s1,s2,s1
1c000304: 040b8463 beqz s7,1c00034c <__call_exitprocs+0xa8>
1c000308: 1044a783 lw a5,260(s1)
1c00030c: 05778063 beq a5,s7,1c00034c <__call_exitprocs+0xa8>
1c000310: fff40413 addi s0,s0,-1
1c000314: ffc48493 addi s1,s1,-4
1c000318: ff3416e3 bne s0,s3,1c000304 <__call_exitprocs+0x60>
1c00031c: 02c12083 lw ra,44(sp)
1c000320: 02812403 lw s0,40(sp)
1c000324: 02412483 lw s1,36(sp)
1c000328: 02012903 lw s2,32(sp)
1c00032c: 01c12983 lw s3,28(sp)
1c000330: 01812a03 lw s4,24(sp)
1c000334: 01412a83 lw s5,20(sp)
1c000338: 01012b03 lw s6,16(sp)
1c00033c: 00c12b83 lw s7,12(sp)
1c000340: 00812c03 lw s8,8(sp)
1c000344: 03010113 addi sp,sp,48
1c000348: 00008067 ret
1c00034c: 00492783 lw a5,4(s2)
1c000350: 0044a683 lw a3,4(s1)
1c000354: fff78793 addi a5,a5,-1
1c000358: 04878e63 beq a5,s0,1c0003b4 <__call_exitprocs+0x110>
1c00035c: 0004a223 sw zero,4(s1)
1c000360: fa0688e3 beqz a3,1c000310 <__call_exitprocs+0x6c>
1c000364: 18892783 lw a5,392(s2)
1c000368: 008a9733 sll a4,s5,s0
1c00036c: 00492c03 lw s8,4(s2)
1c000370: 00f777b3 and a5,a4,a5
1c000374: 02079263 bnez a5,1c000398 <__call_exitprocs+0xf4>
1c000378: 000680e7 jalr a3
1c00037c: 00492703 lw a4,4(s2)
1c000380: 148a2783 lw a5,328(s4)
1c000384: 01871463 bne a4,s8,1c00038c <__call_exitprocs+0xe8>
1c000388: f92784e3 beq a5,s2,1c000310 <__call_exitprocs+0x6c>
1c00038c: f80788e3 beqz a5,1c00031c <__call_exitprocs+0x78>
1c000390: 00078913 mv s2,a5
1c000394: f5dff06f j 1c0002f0 <__call_exitprocs+0x4c>
1c000398: 18c92783 lw a5,396(s2)
1c00039c: 0844a583 lw a1,132(s1)
1c0003a0: 00f77733 and a4,a4,a5
1c0003a4: 00071c63 bnez a4,1c0003bc <__call_exitprocs+0x118>
1c0003a8: 000b0513 mv a0,s6
1c0003ac: 000680e7 jalr a3
1c0003b0: fcdff06f j 1c00037c <__call_exitprocs+0xd8>
1c0003b4: 00892223 sw s0,4(s2)
1c0003b8: fa9ff06f j 1c000360 <__call_exitprocs+0xbc>
1c0003bc: 00058513 mv a0,a1
1c0003c0: 000680e7 jalr a3
1c0003c4: fb9ff06f j 1c00037c <__call_exitprocs+0xd8>
1c0003c8 <__libc_fini_array>:
1c0003c8: ff010113 addi sp,sp,-16
1c0003cc: 00812423 sw s0,8(sp)
1c0003d0: 00000413 li s0,0
1c0003d4: 00000793 li a5,0
1c0003d8: 408787b3 sub a5,a5,s0
1c0003dc: 00912223 sw s1,4(sp)
1c0003e0: 00112623 sw ra,12(sp)
1c0003e4: 4027d493 srai s1,a5,0x2
1c0003e8: 02048063 beqz s1,1c000408 <__libc_fini_array+0x40>
1c0003ec: ffc78793 addi a5,a5,-4
1c0003f0: 00878433 add s0,a5,s0
1c0003f4: 00042783 lw a5,0(s0)
1c0003f8: fff48493 addi s1,s1,-1
1c0003fc: ffc40413 addi s0,s0,-4
1c000400: 000780e7 jalr a5
1c000404: fe0498e3 bnez s1,1c0003f4 <__libc_fini_array+0x2c>
1c000408: 00c12083 lw ra,12(sp)
1c00040c: 00812403 lw s0,8(sp)
1c000410: 00412483 lw s1,4(sp)
1c000414: 01010113 addi sp,sp,16
1c000418: 00008067 ret
1c00041c <atexit>:
1c00041c: 00050593 mv a1,a0
1c000420: 00000693 li a3,0
1c000424: 00000613 li a2,0
1c000428: 00000513 li a0,0
1c00042c: 0040006f j 1c000430 <__register_exitproc>
1c000430 <__register_exitproc>:
1c000430: 1c0007b7 lui a5,0x1c000
1c000434: 5347a703 lw a4,1332(a5) # 1c000534 <_global_impure_ptr>
1c000438: 14872783 lw a5,328(a4)
1c00043c: 04078c63 beqz a5,1c000494 <__register_exitproc+0x64>
1c000440: 0047a703 lw a4,4(a5)
1c000444: 01f00813 li a6,31
1c000448: 06e84e63 blt a6,a4,1c0004c4 <__register_exitproc+0x94>
1c00044c: 00271813 slli a6,a4,0x2
1c000450: 02050663 beqz a0,1c00047c <__register_exitproc+0x4c>
1c000454: 01078333 add t1,a5,a6
1c000458: 08c32423 sw a2,136(t1) # 1c000144 <__libc_init_array+0x8>
1c00045c: 1887a883 lw a7,392(a5)
1c000460: 00100613 li a2,1
1c000464: 00e61633 sll a2,a2,a4
1c000468: 00c8e8b3 or a7,a7,a2
1c00046c: 1917a423 sw a7,392(a5)
1c000470: 10d32423 sw a3,264(t1)
1c000474: 00200693 li a3,2
1c000478: 02d50463 beq a0,a3,1c0004a0 <__register_exitproc+0x70>
1c00047c: 00170713 addi a4,a4,1
1c000480: 00e7a223 sw a4,4(a5)
1c000484: 010787b3 add a5,a5,a6
1c000488: 00b7a423 sw a1,8(a5)
1c00048c: 00000513 li a0,0
1c000490: 00008067 ret
1c000494: 14c70793 addi a5,a4,332
1c000498: 14f72423 sw a5,328(a4)
1c00049c: fa5ff06f j 1c000440 <__register_exitproc+0x10>
1c0004a0: 18c7a683 lw a3,396(a5)
1c0004a4: 00170713 addi a4,a4,1
1c0004a8: 00e7a223 sw a4,4(a5)
1c0004ac: 00c6e633 or a2,a3,a2
1c0004b0: 18c7a623 sw a2,396(a5)
1c0004b4: 010787b3 add a5,a5,a6
1c0004b8: 00b7a423 sw a1,8(a5)
1c0004bc: 00000513 li a0,0
1c0004c0: 00008067 ret
1c0004c4: fff00513 li a0,-1
1c0004c8: 00008067 ret
1c0004cc <_exit>:
1c0004cc: 00000593 li a1,0
1c0004d0: 00000613 li a2,0
1c0004d4: 00000693 li a3,0
1c0004d8: 00000713 li a4,0
1c0004dc: 00000793 li a5,0
1c0004e0: 05d00893 li a7,93
1c0004e4: 00000073 ecall
1c0004e8: 00054463 bltz a0,1c0004f0 <_exit+0x24>
1c0004ec: 0000006f j 1c0004ec <_exit+0x20>
1c0004f0: ff010113 addi sp,sp,-16
1c0004f4: 00812423 sw s0,8(sp)
1c0004f8: 00050413 mv s0,a0
1c0004fc: 00112623 sw ra,12(sp)
1c000500: 40800433 neg s0,s0
1c000504: 00c000ef jal ra,1c000510 <__errno>
1c000508: 00852023 sw s0,0(a0)
1c00050c: 0000006f j 1c00050c <_exit+0x40>
1c000510 <__errno>:
1c000510: 1c0017b7 lui a5,0x1c001
1c000514: 9687a503 lw a0,-1688(a5) # 1c000968 <_impure_ptr>
1c000518: 00008067 ret
Disassembly of section .text.startup:
1c00051c <register_fini>:
1c00051c: 00000793 li a5,0
1c000520: 00078863 beqz a5,1c000530 <register_fini+0x14>
1c000524: 1c000537 lui a0,0x1c000
1c000528: 3c850513 addi a0,a0,968 # 1c0003c8 <__libc_fini_array>
1c00052c: ef1ff06f j 1c00041c <atexit>
1c000530: 00008067 ret
Posts: 14
Threads: 7
Joined: Jun 2020
I want to load full hex code to my verilator model but becoz of this jumping, the pgm not loading completely. Please help me..
Posts: 43
Threads: 0
Joined: Mar 2019
I don't understand your problem. If the memset call gets stuck then you probably are trying to access some address that is not mapped to anything causing the sw to get stuck (unfortunately we don't have bus abort errors to signal this condition). This means your program is buggy.
Posts: 14
Threads: 7
Joined: Jun 2020
Hi,
The problem is with my crt0.S code and linker script, I corrected these files. Now the complete hex code is loading to my verilator model and getting the correct output.
Thank You bluewww for the support
|