@@ -199,6 +199,9 @@ uint64_t mtimecmp;
199
199
/* virtual start address for index 0 in the ram array */
200
200
uint32_t ram_start ;
201
201
202
+ /* program entry point */
203
+ uint32_t start ;
204
+
202
205
/* last byte of the memory initialized and temporary value */
203
206
uint32_t ram_last = 0 ;
204
207
uint32_t ram_curr = 0 ;
@@ -2036,26 +2039,45 @@ int main(int argc, char** argv)
2036
2039
2037
2040
/* for compliance test */
2038
2041
if (strcmp (name , "_start" ) == 0 ) {
2039
- ram_start = sym .st_value ;
2042
+ start = sym .st_value ;
2040
2043
}
2041
2044
2042
2045
/* for zephyr */
2043
2046
if (strcmp (name , "__reset" ) == 0 ) {
2044
- ram_start = sym .st_value ;
2047
+ start = sym .st_value ;
2045
2048
}
2046
2049
if (strcmp (name , "__irq_wrapper" ) == 0 ) {
2047
2050
mtvec = sym .st_value ;
2048
2051
}
2049
2052
}
2050
2053
}
2051
2054
}
2055
+
2056
+ /* set .text segment as the base address */
2057
+ scn = NULL ;
2058
+ size_t shstrndx ;
2059
+ elf_getshdrstrndx (elf , & shstrndx );
2060
+ while ((scn = elf_nextscn (elf , scn )) != NULL ) {
2061
+ gelf_getshdr (scn , & shdr );
2062
+ const char * name = elf_strptr (elf , shstrndx , shdr .sh_name );
2063
+
2064
+ if (shdr .sh_type == SHT_PROGBITS ) {
2065
+ if (strcmp (name , ".text" ) == 0 ) {
2066
+ ram_start = shdr .sh_addr ;
2067
+ break ;
2068
+ }
2069
+ }
2070
+ }
2071
+
2052
2072
#ifdef DEBUG_OUTPUT
2053
2073
printf ("begin_signature: 0x%08x\n" , begin_signature );
2054
2074
printf ("end_signature: 0x%08x\n" , end_signature );
2055
- printf ("start: 0x%08x\n" , ram_start );
2075
+ printf ("ram_start: 0x%08x\n" , ram_start );
2076
+ printf ("entry point: 0x%08x\n" , start );
2056
2077
#endif
2057
2078
2058
2079
/* scan for program */
2080
+ scn = NULL ;
2059
2081
while ((scn = elf_nextscn (elf , scn )) != NULL ) {
2060
2082
gelf_getshdr (scn , & shdr );
2061
2083
if (shdr .sh_type == SHT_PROGBITS ) {
@@ -2144,7 +2166,8 @@ int main(int argc, char** argv)
2144
2166
uint64_t ns1 = get_clock ();
2145
2167
2146
2168
/* run program in emulator */
2147
- pc = ram_start ;
2169
+ pc = start ;
2170
+ reg [2 ] = ram_start + RAM_SIZE ;
2148
2171
riscv_cpu_interp_x32 ();
2149
2172
2150
2173
uint64_t ns2 = get_clock ();
0 commit comments