Commit 5a6919af authored by ARM64 Builder's avatar ARM64 Builder
Browse files

add stack trace on 64 bit ARM

parent 6e25ed5a
......@@ -14,6 +14,7 @@ $(ODIR)scon.o: $(SDIR)scon.c
gcc -fno-stack-protector -O $(DEFINES) -ffunction-sections -fdata-sections $(SDIR)scon.c -S -o $(ODIR)scon.s
mv $(ODIR)scon.s $(ODIR)scon.s.copy
grep -v -w ___main $(ODIR)scon.s.copy > $(ODIR)scon.s
rm $(ODIR)scon.s.copy
as $(DEFINES_A) $(ODIR)scon.s -o $(ODIR)scon.o
$(ODIR)ufileIO2.o: $(SDIR)ufileIO2.c
......
SDIR = ./
ODIR = ./
DEFINES = -DUSE_CLIB -DLINUX -DARM -DGNU_C -DELF -DTIME_PROFILE -DPROFILE
all: $(ODIR)_startupTrace.o
$(ODIR)_startupTrace.o: $(ODIR)arm64startup.o $(ODIR)arm64fileIO3.o $(ODIR)scon.o $(ODIR)arm64trace.o $(ODIR)ufileIO2.o
ld -r -o $(ODIR)_startupTrace.o $(ODIR)arm64startup.o $(ODIR)scon.o $(ODIR)arm64trace.o $(ODIR)arm64fileIO3.o $(ODIR)ufileIO2.o
$(ODIR)scon.o: $(SDIR)scon.c
# gcc -c -O $(DEFINES) -o $(ODIR)scon.o $(SDIR)scon.c
gcc -fno-stack-protector -O $(DEFINES) -ffunction-sections -fdata-sections $(SDIR)scon.c -S -o $(ODIR)scon.s
mv $(ODIR)scon.s $(ODIR)scon.s.copy
grep -v -w ___main $(ODIR)scon.s.copy > $(ODIR)scon.s
rm $(ODIR)scon.s.copy
as $(DEFINES_A) $(ODIR)scon.s -o $(ODIR)scon.o
$(ODIR)ufileIO2.o: $(SDIR)ufileIO2.c
gcc -fno-stack-protector -c -O $(DEFINES) -ffunction-sections -fdata-sections -o $(ODIR)ufileIO2.o $(SDIR)ufileIO2.c
$(ODIR)arm64startup.o: $(SDIR)arm64startup.s $(SDIR)arm64copy.s $(SDIR)arm64mark.s \
$(SDIR)arm64compact.s $(SDIR)arm64compact_rmark.s \
$(SDIR)arm64compact_rmarkr.s $(SDIR)arm64ap.s
as $(ODIR)arm64startup.s --defsym PROFILE=1 --defsym TRACE=1 --defsym LINUX=1 -o $(ODIR)arm64startup.o
$(ODIR)arm64fileIO3.o: $(SDIR)arm64fileIO3.s
as $(ODIR)arm64fileIO3.s -o $(ODIR)arm64fileIO3.o
$(ODIR)arm64trace.o: $(SDIR)arm64trace.s
as $(ODIR)arm64trace.s -o $(ODIR)arm64trace.o
......@@ -4,13 +4,14 @@
# Machine: AArch64
# B stack registers: x6 x5 x4 x3 x2 x1 x0
# A stack registers: x8 x9 x10 x17 (fp)
# scratch register: x16 (ip)
# A stack registers: x8 x9 x10 x11 x12 x13 x14 x15
# scratch registers x16 (ip) x17 (fp)
# n free heap words: x25
# A stack pointer: x26
# heap pointer: x27
# B stack pointer: x28
# link/scratch register: x30
# descriptor registers: x20 x21 x22 x23 x24
USE_CLIB = 1
......@@ -31,7 +32,6 @@ MARK_AND_COPY_GC = 1
NEW_DESCRIPTORS = 1
# #define PROFILE
MODULE_NAMES_IN_TIME_PROFILER = 1
COMPACT_GC_ONLY = 0
......@@ -269,7 +269,6 @@ marked_gc_string_1:
.endif
.ifdef PROFILE
.p2align 2
.if MODULE_NAMES_IN_TIME_PROFILER
.ifdef LINUX
.globl m_system
.endif
......@@ -278,11 +277,11 @@ m_system:
.ascii "System"
.byte 0
.byte 0
.long m_system
.endif
.p2align 3
garbage_collector_name:
.long 0
.quad 0
.long m_system
.asciz "garbage_collector"
.p2align 2
.endif
......@@ -424,7 +423,10 @@ start_address:
.ifdef PROFILE
.globl init_profiler
.globl profile_s,profile_n,profile_r,profile_t
.globl write_profile_information,write_profile_stack
.globl write_profile_stack
.ifndef TRACE
.globl write_profile_information
.endif
.endif
.globl __driver
......@@ -958,8 +960,10 @@ no_print_execution_time:
bl free
.ifdef PROFILE
.ifndef TRACE
str x30,[x28,#-8]!
bl write_profile_information
.endif
.endif
ldr x30,[sp],#16
......@@ -1677,9 +1681,9 @@ add_IO_time:
collect_3:
.ifdef PROFILE
adrp x10,garbage_collector_name
add x10,x10,#:lo12:garbage_collector_name
str x30,[sp,#-4]!
adrp x16,garbage_collector_name
add x16,x16,#:lo12:garbage_collector_name
mov x29,x30
bl profile_s
.endif
str x30,[x28,#-8]!
......@@ -1698,9 +1702,9 @@ collect_3:
collect_2:
.ifdef PROFILE
adrp x10,garbage_collector_name
add x10,x10,#:lo12:garbage_collector_name
str x30,[sp,#-4]!
adrp x16,garbage_collector_name
add x16,x16,#:lo12:garbage_collector_name
mov x29,x30
bl profile_s
.endif
stp x8,x9,[x26],#16
......@@ -1717,9 +1721,9 @@ collect_2:
collect_1:
.ifdef PROFILE
adrp x10,garbage_collector_name
add x10,x10,#:lo12:garbage_collector_name
str x30,[sp,#-4]!
adrp x16,garbage_collector_name
add x16,x16,#:lo12:garbage_collector_name
mov x29,x30
bl profile_s
.endif
str x8,[x26],#8
......@@ -1736,9 +1740,9 @@ collect_1:
.ifdef PROFILE
collect_0:
adrp x10,garbage_collector_name
add x10,x10,#:lo12:garbage_collector_name
str x30,[x28,#-8]!
adrp x16,garbage_collector_name
add x16,x16,#:lo12:garbage_collector_name
mov x29,x30
bl profile_s
str x30,[x28,#-8]!
bl collect_0_
......@@ -2879,9 +2883,8 @@ eval_fill2:
.endif
.ifdef PROFILE
str x30,[x28,#-8]!
mov x29,x30
bl profile_n
mov x10,x4
.endif
eval_upd_0:
adrp x16,e__system__nind
......@@ -2891,9 +2894,8 @@ eval_upd_0:
br x11
.ifdef PROFILE
str x30,[x28,#-8]!
mov x29,x30
bl profile_n
mov x10,x4
.endif
eval_upd_1:
adrp x16,e__system__nind
......@@ -2905,9 +2907,8 @@ eval_upd_1:
br x11
.ifdef PROFILE
str x30,[x28,#-8]!
mov x29,x30
bl profile_n
mov x10,x4
.endif
eval_upd_2:
adrp x16,e__system__nind
......@@ -2919,9 +2920,8 @@ eval_upd_2:
br x11
.ifdef PROFILE
str x30,[x28,#-8]!
mov x29,x30
bl profile_n
mov x10,x4
.endif
eval_upd_3:
adrp x16,e__system__nind
......@@ -2935,9 +2935,8 @@ eval_upd_3:
br x11
.ifdef PROFILE
str x30,[x28,#-8]!
mov x29,x30
bl profile_n
mov x10,x4
.endif
eval_upd_4:
adrp x16,e__system__nind
......@@ -2954,9 +2953,8 @@ eval_upd_4:
br x11
.ifdef PROFILE
str x30,[x28,#-8]!
mov x29,x30
bl profile_n
mov x10,x4
.endif
eval_upd_5:
adrp x16,e__system__nind
......@@ -2975,9 +2973,8 @@ eval_upd_5:
br x11
.ifdef PROFILE
str x30,[x28,#-8]!
mov x29,x30
bl profile_n
mov x10,x4
.endif
eval_upd_6:
adrp x16,e__system__nind
......@@ -2998,9 +2995,8 @@ eval_upd_6:
br x11
.ifdef PROFILE
str x30,[x28,#-8]!
mov x29,x30
bl profile_n
mov x10,x4
.endif
eval_upd_7:
mov x4,#0
......@@ -3032,9 +3028,8 @@ eval_upd_n_lp:
br x11
.ifdef PROFILE
str x30,[x28,#-8]!
mov x29,x30
bl profile_n
mov x10,x4
.endif
eval_upd_8:
mov x4,#1
......@@ -3042,9 +3037,8 @@ eval_upd_8:
b eval_upd_n
.ifdef PROFILE
str x30,[x28,#-8]!
mov x29,x30
bl profile_n
mov x10,x4
.endif
eval_upd_9:
mov x4,#2
......@@ -3052,9 +3046,8 @@ eval_upd_9:
b eval_upd_n
.ifdef PROFILE
str x30,[x28,#-8]!
mov x29,x30
bl profile_n
mov x10,x4
.endif
eval_upd_10:
mov x4,#3
......@@ -3062,9 +3055,8 @@ eval_upd_10:
b eval_upd_n
.ifdef PROFILE
str x30,[x28,#-8]!
mov x29,x30
bl profile_n
mov x10,x4
.endif
eval_upd_11:
mov x4,#4
......@@ -3072,9 +3064,8 @@ eval_upd_11:
b eval_upd_n
.ifdef PROFILE
str x30,[x28,#-8]!
mov x29,x30
bl profile_n
mov x10,x4
.endif
eval_upd_12:
mov x4,#5
......@@ -3082,9 +3073,8 @@ eval_upd_12:
b eval_upd_n
.ifdef PROFILE
str x30,[x28,#-8]!
mov x29,x30
bl profile_n
mov x10,x4
.endif
eval_upd_13:
mov x4,#6
......@@ -3092,9 +3082,8 @@ eval_upd_13:
b eval_upd_n
.ifdef PROFILE
str x30,[x28,#-8]!
mov x29,x30
bl profile_n
mov x10,x4
.endif
eval_upd_14:
mov x4,#7
......@@ -3102,9 +3091,8 @@ eval_upd_14:
b eval_upd_n
.ifdef PROFILE
str x30,[x28,#-8]!
mov x29,x30
bl profile_n
mov x10,x4
.endif
eval_upd_15:
mov x4,#8
......@@ -3112,9 +3100,8 @@ eval_upd_15:
b eval_upd_n
.ifdef PROFILE
str x30,[x28,#-8]!
mov x29,x30
bl profile_n
mov x10,x4
.endif
eval_upd_16:
mov x4,#9
......@@ -3122,9 +3109,8 @@ eval_upd_16:
b eval_upd_n
.ifdef PROFILE
str x30,[x28,#-8]!
mov x29,x30
bl profile_n
mov x10,x4
.endif
eval_upd_17:
mov x4,#10
......@@ -3132,9 +3118,8 @@ eval_upd_17:
b eval_upd_n
.ifdef PROFILE
str x30,[x28,#-8]!
mov x29,x30
bl profile_n
mov x10,x4
.endif
eval_upd_18:
mov x4,#11
......@@ -3142,9 +3127,8 @@ eval_upd_18:
b eval_upd_n
.ifdef PROFILE
str x30,[x28,#-8]!
mov x29,x30
bl profile_n
mov x10,x4
.endif
eval_upd_19:
mov x4,#12
......@@ -3152,9 +3136,8 @@ eval_upd_19:
b eval_upd_n
.ifdef PROFILE
str x30,[x28,#-8]!
mov x29,x30
bl profile_n
mov x10,x4
.endif
eval_upd_20:
mov x4,#13
......@@ -3162,9 +3145,8 @@ eval_upd_20:
b eval_upd_n
.ifdef PROFILE
str x30,[x28,#-8]!
mov x29,x30
bl profile_n
mov x10,x4
.endif
eval_upd_21:
mov x4,#14
......@@ -3172,9 +3154,8 @@ eval_upd_21:
b eval_upd_n
.ifdef PROFILE
str x30,[x28,#-8]!
mov x29,x30
bl profile_n
mov x10,x4
.endif
eval_upd_22:
mov x4,#15
......@@ -3182,9 +3163,8 @@ eval_upd_22:
b eval_upd_n
.ifdef PROFILE
str x30,[x28,#-8]!
mov x29,x30
bl profile_n
mov x10,x4
.endif
eval_upd_23:
mov x4,#16
......@@ -3192,9 +3172,8 @@ eval_upd_23:
b eval_upd_n
.ifdef PROFILE
str x30,[x28,#-8]!
mov x29,x30
bl profile_n
mov x10,x4
.endif
eval_upd_24:
mov x4,#17
......@@ -3202,9 +3181,8 @@ eval_upd_24:
b eval_upd_n
.ifdef PROFILE
str x30,[x28,#-8]!
mov x29,x30
bl profile_n
mov x10,x4
.endif
eval_upd_25:
mov x4,#18
......@@ -3212,9 +3190,8 @@ eval_upd_25:
b eval_upd_n
.ifdef PROFILE
str x30,[x28,#-8]!
mov x29,x30
bl profile_n
mov x10,x4
.endif
eval_upd_26:
mov x4,#19
......@@ -3222,9 +3199,8 @@ eval_upd_26:
b eval_upd_n
.ifdef PROFILE
str x30,[x28,#-8]!
mov x29,x30
bl profile_n
mov x10,x4
.endif
eval_upd_27:
mov x4,#20
......@@ -3232,9 +3208,8 @@ eval_upd_27:
b eval_upd_n
.ifdef PROFILE
str x30,[x28,#-8]!
mov x29,x30
bl profile_n
mov x10,x4
.endif
eval_upd_28:
mov x4,#21
......@@ -3242,9 +3217,8 @@ eval_upd_28:
b eval_upd_n
.ifdef PROFILE
str x30,[x28,#-8]!
mov x29,x30
bl profile_n
mov x10,x4
.endif
eval_upd_29:
mov x4,#22
......@@ -3252,9 +3226,8 @@ eval_upd_29:
b eval_upd_n
.ifdef PROFILE
str x30,[x28,#-8]!
mov x29,x30
bl profile_n
mov x10,x4
.endif
eval_upd_30:
mov x4,#23
......@@ -3262,9 +3235,8 @@ eval_upd_30:
b eval_upd_n
.ifdef PROFILE
str x30,[x28,#-8]!
mov x29,x30
bl profile_n
mov x10,x4
.endif
eval_upd_31:
mov x4,#24
......@@ -3272,9 +3244,8 @@ eval_upd_31:
b eval_upd_n
.ifdef PROFILE
str x30,[x28,#-8]!
mov x29,x30
bl profile_n
mov x10,x4
.endif
eval_upd_32:
mov x4,#25
......
.globl profile_t
.globl profile_l
.globl profile_n
.globl profile_s
.globl profile_r
.globl profile_l2
.globl profile_n2
.globl profile_s2
.globl init_profiler
.globl write_profile_stack
.text
profile_l:
profile_n:
profile_s:
adrp x17,profile_stack_pointer
ldr x17,[x17,#:lo12:profile_stack_pointer]
str x16,[x17],#8
adrp x16,profile_stack_pointer
str x17,[x16,#:lo12:profile_stack_pointer]
mov x17,x30
mov x30,x29
ret x17
profile_l2:
profile_n2:
profile_s2:
adrp x17,profile_stack_pointer
ldr x17,[x17,#:lo12:profile_stack_pointer]
stp x16,x16,[x17],#16
adrp x16,profile_stack_pointer
str x17,[x16,#:lo12:profile_stack_pointer]
mov x17,x30
mov x30,x29
ret x17
profile_t:
adrp x17,profile_stack_pointer
ldr x16,[x17,#:lo12:profile_stack_pointer]
sub x16,x16,8
str x16,[x17,#:lo12:profile_stack_pointer]
mov x17,x30
mov x30,x29
ret x17
profile_r:
adrp x17,profile_stack_pointer
ldr x16,[x17,#:lo12:profile_stack_pointer]
sub x16,x16,8
str x16,[x17,#:lo12:profile_stack_pointer]
mov x29,x30
ldr x30,[x28],#8
ret x29
init_profiler:
mov x29,x30
adrp x16,ab_stack_size
ldr x16,[x16,#:lo12:ab_stack_size]
add x0,x16,#7
bl malloc
cbz x0,init_profiler_error
adrp x1,start_string
add x1,x1,#:lo12:start_string
stp xzr,x1,[x0],#16
adrp x16,profile_stack_pointer
str x0,[x16,#:lo12:profile_stack_pointer]
ldr x30,[x28],#8
ret x29
init_profiler_error:
adrp x16,profile_stack_pointer
str x0,[x16,#:lo12:profile_stack_pointer]
adrp x10,not_enough_memory_for_profile_stack
add x10,x10,#:lo12:not_enough_memory_for_profile_stack
b print_error
write_profile_stack:
mov x29,x30
mov x19,sp
and sp,x19,#-16
sub x28,x28,24
adrp x16,profile_stack_pointer
ldr x6,[x16,#:lo12:profile_stack_pointer]
cbz x6,end_profile_stack
adrp x16,stack_trace_depth
ldr x5,[x16,#:lo12:stack_trace_depth]
stp x5,x6,[x28]
adrp x0,stack_trace_string
add x0,x0,#:lo12:stack_trace_string
bl ew_print_string
ldp x5,x6,[x28]
write_functions_on_stack:
ldr x4,[x6,#-8]!
cbz x4,end_profile_stack
stp x5,x6,[x28]
str x4,[x28,#16]
add x0,x4,#12
bl ew_print_string
adrp x0,module_string
add x0,x0,#:lo12:module_string
bl ew_print_string
ldr x4,[x28,#16]
ldr w0,[x4,#8]