Commit 49f9e83d authored by John van Groningen's avatar John van Groningen
Browse files

add stack trace on 32 bit ARM

parent 2447c8ff
SDIR = ./
ODIR = ./
DEFINES = -DUSE_CLIB -DLINUX -DARM -DGNU_C -DELF -DTIME_PROFILE -DPROFILE
all: $(ODIR)_startupTrace.o
$(ODIR)_startupTrace.o: $(ODIR)armstartup.o $(ODIR)armfileIO3.o $(ODIR)armtrace.o $(ODIR)scon.o $(ODIR)ufileIO2.o $(ODIR)armdivmod.o $(ODIR)armudiv.o $(ODIR)armludiv.o
ld -r -o $(ODIR)_startupTrace.o $(ODIR)armstartup.o $(ODIR)armdivmod.o $(ODIR)armudiv.o $(ODIR)armludiv.o $(ODIR)armtrace.o $(ODIR)scon.o $(ODIR)armfileIO3.o $(ODIR)ufileIO2.o
$(ODIR)scon.o: $(SDIR)scon.c
# gcc -marm -c -O $(DEFINES) -o $(ODIR)scon.o $(SDIR)scon.c
gcc -marm -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
as $(DEFINES_A) $(ODIR)scon.s -o $(ODIR)scon.o
$(ODIR)ufileIO2.o: $(SDIR)ufileIO2.c
gcc -marm -c -O $(DEFINES) -ffunction-sections -fdata-sections -o $(ODIR)ufileIO2.o $(SDIR)ufileIO2.c
$(ODIR)armstartup.o: $(SDIR)armstartup.s
as $(ODIR)armstartup.s --defsym PROFILE=1 --defsym TRACE=1 -o $(ODIR)armstartup.o
$(ODIR)armfileIO3.o: $(SDIR)armfileIO3.s
as $(ODIR)armfileIO3.s -o $(ODIR)armfileIO3.o
$(ODIR)armtrace.o: $(SDIR)armtrace.s
as $(ODIR)armtrace.s -o $(ODIR)armtrace.o
$(ODIR)armdivmod.o: $(SDIR)armdivmod.s
as $(ODIR)armdivmod.s -o $(ODIR)armdivmod.o
$(ODIR)armudiv.o: $(SDIR)armudiv.s
as $(ODIR)armudiv.s -o $(ODIR)armudiv.o
$(ODIR)armludiv.o: $(SDIR)armludiv.s
as $(ODIR)armludiv.s -o $(ODIR)armludiv.o
......@@ -278,9 +278,7 @@ marked_gc_string_1:
.ifdef PROFILE
.p2align 2
.if MODULE_NAMES_IN_TIME_PROFILER
.ifdef LINUX
.globl m_system
.endif
m_system:
.long 6
.ascii "System"
......@@ -428,7 +426,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
......@@ -548,10 +549,10 @@ clean_init:
lao r12,halt_sp,1
sto sp,r12,halt_sp,1
.ifdef PROFILE
.ifdef PROFILE
str pc,[sp,#-4]!
bl init_profiler
.endif
.endif
lao r12,saved_heap_p,0
otoa r12,saved_heap_p,0
......@@ -927,8 +928,10 @@ no_print_execution_time:
bl free
.ifdef PROFILE
.ifndef TRACE
str pc,[sp,#-4]!
bl write_profile_information
.endif
.endif
ldr pc,[sp],#4
......@@ -1778,9 +1781,8 @@ add_IO_time:
collect_3:
str lr,[sp,#-4]!
.ifdef PROFILE
lao r8,garbage_collector_name,0
otoa r8,garbage_collector_name,0
str pc,[sp,#-4]!
lao r11,garbage_collector_name,0
otoa r11,garbage_collector_name,0
bl profile_s
.endif
str r6,[r9]
......@@ -1800,9 +1802,8 @@ collect_3:
collect_2:
str lr,[sp,#-4]!
.ifdef PROFILE
lao r8,garbage_collector_name,1
otoa r8,garbage_collector_name,1
str pc,[sp,#-4]!
lao r11,garbage_collector_name,1
otoa r11,garbage_collector_name,1
bl profile_s
.endif
str r6,[r9]
......@@ -1820,9 +1821,8 @@ collect_2:
collect_1:
str lr,[sp,#-4]!
.ifdef PROFILE
lao r8,garbage_collector_name,2
otoa r8,garbage_collector_name,2
str pc,[sp,#-4]!
lao r11,garbage_collector_name,2
otoa r11,garbage_collector_name,2
bl profile_s
.endif
str r6,[r9],#4
......@@ -1837,9 +1837,8 @@ collect_1:
.ifdef PROFILE
collect_0:
str lr,[sp,#-4]!
lao r8,garbage_collector_name,3
otoa r8,garbage_collector_name,3
str pc,[sp,#-4]!
lao r11,garbage_collector_name,3
otoa r11,garbage_collector_name,3
bl profile_s
bl collect_0_
b profile_r
......@@ -3144,9 +3143,8 @@ eval_fill2:
.endif
.ifdef PROFILE
str pc,[sp,#-4]!
bl profile_n
mov r8,r4
mov r11,r4
.endif
eval_upd_0:
lao r12,e__system__nind,0
......@@ -3156,9 +3154,8 @@ eval_upd_0:
mov pc,r11
.ifdef PROFILE
str pc,[sp,#-4]!
bl profile_n
mov r8,r4
mov r11,r4
.endif
eval_upd_1:
lao r12,e__system__nind,1
......@@ -3170,9 +3167,8 @@ eval_upd_1:
mov pc,r11
.ifdef PROFILE
str pc,[sp,#-4]!
bl profile_n
mov r8,r4
mov r11,r4
.endif
eval_upd_2:
lao r12,e__system__nind,2
......@@ -3184,9 +3180,8 @@ eval_upd_2:
mov pc,r11
.ifdef PROFILE
str pc,[sp,#-4]!
bl profile_n
mov r8,r4
mov r11,r4
.endif
eval_upd_3:
lao r12,e__system__nind,3
......@@ -3200,9 +3195,8 @@ eval_upd_3:
mov pc,r11
.ifdef PROFILE
str pc,[sp,#-4]!
bl profile_n
mov r8,r4
mov r11,r4
.endif
eval_upd_4:
lao r12,e__system__nind,4
......@@ -3219,9 +3213,8 @@ eval_upd_4:
mov pc,r11
.ifdef PROFILE
str pc,[sp,#-4]!
bl profile_n
mov r8,r4
mov r11,r4
.endif
eval_upd_5:
lao r12,e__system__nind,5
......@@ -3240,9 +3233,8 @@ eval_upd_5:
mov pc,r11
.ifdef PROFILE
str pc,[sp,#-4]!
bl profile_n
mov r8,r4
mov r11,r4
.endif
eval_upd_6:
lao r12,e__system__nind,6
......@@ -3263,9 +3255,8 @@ eval_upd_6:
mov pc,r11
.ifdef PROFILE
str pc,[sp,#-4]!
bl profile_n
mov r8,r4
mov r11,r4
.endif
eval_upd_7:
mov r4,#0
......@@ -3297,9 +3288,8 @@ eval_upd_n_lp:
mov pc,r11
.ifdef PROFILE
str pc,[sp,#-4]!
bl profile_n
mov r8,r4
mov r11,r4
.endif
eval_upd_8:
mov r4,#1
......@@ -3307,9 +3297,8 @@ eval_upd_8:
b eval_upd_n
.ifdef PROFILE
str pc,[sp,#-4]!
bl profile_n
mov r8,r4
mov r11,r4
.endif
eval_upd_9:
mov r4,#2
......@@ -3317,9 +3306,8 @@ eval_upd_9:
b eval_upd_n
.ifdef PROFILE
str pc,[sp,#-4]!
bl profile_n
mov r8,r4
mov r11,r4
.endif
eval_upd_10:
mov r4,#3
......@@ -3327,9 +3315,8 @@ eval_upd_10:
b eval_upd_n
.ifdef PROFILE
str pc,[sp,#-4]!
bl profile_n
mov r8,r4
mov r11,r4
.endif
eval_upd_11:
mov r4,#4
......@@ -3337,9 +3324,8 @@ eval_upd_11:
b eval_upd_n
.ifdef PROFILE
str pc,[sp,#-4]!
bl profile_n
mov r8,r4
mov r11,r4
.endif
eval_upd_12:
mov r4,#5
......@@ -3347,9 +3333,8 @@ eval_upd_12:
b eval_upd_n
.ifdef PROFILE
str pc,[sp,#-4]!
bl profile_n
mov r8,r4
mov r11,r4
.endif
eval_upd_13:
mov r4,#6
......@@ -3357,9 +3342,8 @@ eval_upd_13:
b eval_upd_n
.ifdef PROFILE
str pc,[sp,#-4]!
bl profile_n
mov r8,r4
mov r11,r4
.endif
eval_upd_14:
mov r4,#7
......@@ -3367,9 +3351,8 @@ eval_upd_14:
b eval_upd_n
.ifdef PROFILE
str pc,[sp,#-4]!
bl profile_n
mov r8,r4
mov r11,r4
.endif
eval_upd_15:
mov r4,#8
......@@ -3377,9 +3360,8 @@ eval_upd_15:
b eval_upd_n
.ifdef PROFILE
str pc,[sp,#-4]!
bl profile_n
mov r8,r4
mov r11,r4
.endif
eval_upd_16:
mov r4,#9
......@@ -3387,9 +3369,8 @@ eval_upd_16:
b eval_upd_n
.ifdef PROFILE
str pc,[sp,#-4]!
bl profile_n
mov r8,r4
mov r11,r4
.endif
eval_upd_17:
mov r4,#10
......@@ -3397,9 +3378,8 @@ eval_upd_17:
b eval_upd_n
.ifdef PROFILE
str pc,[sp,#-4]!
bl profile_n
mov r8,r4
mov r11,r4
.endif
eval_upd_18:
mov r4,#11
......@@ -3407,9 +3387,8 @@ eval_upd_18:
b eval_upd_n
.ifdef PROFILE
str pc,[sp,#-4]!
bl profile_n
mov r8,r4
mov r11,r4
.endif
eval_upd_19:
mov r4,#12
......@@ -3417,9 +3396,8 @@ eval_upd_19:
b eval_upd_n
.ifdef PROFILE
str pc,[sp,#-4]!
bl profile_n
mov r8,r4
mov r11,r4
.endif
eval_upd_20:
mov r4,#13
......@@ -3427,9 +3405,8 @@ eval_upd_20:
b eval_upd_n
.ifdef PROFILE
str pc,[sp,#-4]!
bl profile_n
mov r8,r4
mov r11,r4
.endif
eval_upd_21:
mov r4,#14
......@@ -3437,9 +3414,8 @@ eval_upd_21:
b eval_upd_n
.ifdef PROFILE
str pc,[sp,#-4]!
bl profile_n
mov r8,r4
mov r11,r4
.endif
eval_upd_22:
mov r4,#15
......@@ -3447,9 +3423,8 @@ eval_upd_22:
b eval_upd_n
.ifdef PROFILE
str pc,[sp,#-4]!
bl profile_n
mov r8,r4
mov r11,r4
.endif
eval_upd_23:
mov r4,#16
......@@ -3457,9 +3432,8 @@ eval_upd_23:
b eval_upd_n
.ifdef PROFILE
str pc,[sp,#-4]!
bl profile_n
mov r8,r4
mov r11,r4
.endif
eval_upd_24:
mov r4,#17
......@@ -3467,9 +3441,8 @@ eval_upd_24:
b eval_upd_n
.ifdef PROFILE
str pc,[sp,#-4]!
bl profile_n
mov r8,r4
mov r11,r4
.endif
eval_upd_25:
mov r4,#18
......@@ -3477,9 +3450,8 @@ eval_upd_25:
b eval_upd_n
.ifdef PROFILE
str pc,[sp,#-4]!
bl profile_n
mov r8,r4
mov r11,r4
.endif
eval_upd_26:
mov r4,#19
......@@ -3487,9 +3459,8 @@ eval_upd_26:
b eval_upd_n
.ifdef PROFILE
str pc,[sp,#-4]!
bl profile_n
mov r8,r4
mov r11,r4
.endif
eval_upd_27:
mov r4,#20
......@@ -3497,9 +3468,8 @@ eval_upd_27:
b eval_upd_n
.ifdef PROFILE
str pc,[sp,#-4]!
bl profile_n
mov r8,r4
mov r11,r4
.endif
eval_upd_28:
mov r4,#21
......@@ -3507,9 +3477,8 @@ eval_upd_28:
b eval_upd_n
.ifdef PROFILE
str pc,[sp,#-4]!
bl profile_n
mov r8,r4
mov r11,r4
.endif
eval_upd_29:
mov r4,#22
......@@ -3517,9 +3486,8 @@ eval_upd_29:
b eval_upd_n
.ifdef PROFILE
str pc,[sp,#-4]!
bl profile_n
mov r8,r4
mov r11,r4
.endif
eval_upd_30:
mov r4,#23
......@@ -3527,9 +3495,8 @@ eval_upd_30:
b eval_upd_n
.ifdef PROFILE
str pc,[sp,#-4]!
bl profile_n
mov r8,r4
mov r11,r4
.endif
eval_upd_31:
mov r4,#24
......@@ -3537,9 +3504,8 @@ eval_upd_31:
b eval_upd_n
.ifdef PROFILE
str pc,[sp,#-4]!
bl profile_n
mov r8,r4
mov r11,r4
.endif
eval_upd_32:
mov r4,#25
......
.include "armmacros.s"
.globl profile_t
.globl profile_ti
.globl profile_r
.globl profile_l
.globl profile_n
.globl profile_s
.globl profile_l2
.globl profile_n2
.globl profile_s2
.globl init_profiler
.globl write_profile_stack
.text
profile_t:
lao r12,profile_stack_pointer,0
ldo r12,r12,profile_stack_pointer,0
sub r12,r12,#4
lao r11,profile_stack_pointer,1
sto r12,r11,profile_stack_pointer,1
bx lr
profile_ti:
lao r12,profile_stack_pointer,0
ldo r12,r12,profile_stack_pointer,0
sub r12,r12,#4
lao r14,profile_stack_pointer,1
sto r12,r14,profile_stack_pointer,1
bx r11
profile_r:
lao r12,profile_stack_pointer,0
ldo r12,r12,profile_stack_pointer,0
sub r12,r12,#4
lao r11,profile_stack_pointer,1
sto r12,r11,profile_stack_pointer,1
pop {pc}
profile_l:
profile_n:
profile_s:
lao r12,profile_stack_pointer,2
ldo r12,r12,profile_stack_pointer,2
str r11,[r12],#4
lao r11,profile_stack_pointer,3
sto r12,r11,profile_stack_pointer,3
bx lr
profile_l2:
profile_n2:
profile_s2:
lao r12,profile_stack_pointer,4
ldo r12,r12,profile_stack_pointer,4
str r11,[r12,#4]
str r11,[r12],#8
lao r11,profile_stack_pointer,5
sto r12,r11,profile_stack_pointer,5
bx lr
.ifdef PIC
lto profile_stack_pointer,0
lto profile_stack_pointer,1
lto profile_stack_pointer,2
lto profile_stack_pointer,3
lto profile_stack_pointer,4
lto profile_stack_pointer,5
.endif
init_profiler:
lao r0,ab_stack_size,0
ldo r0,r0,ab_stack_size,0
bl malloc
cmp r0,#0
beq init_profiler_error
lao r1,start_string,0
otoa r1,start_string,0
str r1,[r0,#4]
mov r1,#0
str r1,[r0],#8
lao r12,profile_stack_pointer,6
sto r0,r12,profile_stack_pointer,6
pop {pc}
init_profiler_error:
lao r12,profile_stack_pointer,7
sto r0,r12,profile_stack_pointer,7
lao r0,not_enough_memory_for_profile_stack,0
otoa r0,not_enough_memory_for_profile_stack,0
b print_error
.ifdef PIC
lto ab_stack_size,0
lto start_string,0
lto profile_stack_pointer,6
lto profile_stack_pointer,7
lto not_enough_memory_for_profile_stack,0
.endif
write_profile_stack:
lao r12,profile_stack_pointer,8
ldo r4,r12,profile_stack_pointer,8
cmp r4,#0
beq stack_not_initialised
lao r0,stack_trace_string,0
otoa r0,stack_trace_string,0
bl ew_print_string
lao r12,stack_trace_depth,0
ldo r6,r12,stack_trace_depth,0
write_functions_on_stack:
ldr r7,[r4,#-4]!
cmp r7,#0
beq end_profile_stack
add r0,r7,#4
bl ew_print_string
lao r0,module_string,0
otoa r0,module_string,0
bl ew_print_string
ldr r0,[r7,#-4]
ldr r1,[r0],#4
bl ew_print_text
mov r0,#']'
bl ew_print_char
mov r0,#10
bl ew_print_char
subs r6,r6,$1
bne write_functions_on_stack
stack_not_initialised:
end_profile_stack:
pop {pc}
.ifdef PIC
lto profile_stack_pointer,8
lto stack_trace_string,0
lto stack_trace_depth,0
lto module_string,0
.endif
.data
.p2align 2
profile_stack_pointer:
.long 0
stack_trace_depth:
.long 12
.long m_system
start_string:
.long 0
.asciz "start"
.p2align 2
not_enough_memory_for_profile_stack:
.ascii "not enough memory for profile stack"
.byte 10