Start. S clear bss segment, start. sbss segment
Start. S
. Global _ start. global _ end. align 2. text_start: B reset ldr pc, _ undefined_instruction ldr pc, _ Your ldr pc, _ prefetch_abort ldr pc, _ data_abort ldr pc, _ not_used ldr pc, _ irq ldr pc, _ fiq_undefined_instruction :. word und_software_interrupt :. word svc_prefetch_abort :. word pre_abort_data_abort :. word data_abort_not_used :. word 0x12345678_irq :. word irq_fiq :. word fiqreset: mov ip, sp pu Sh {fp, ip, lr, pc} sub fp, ip, #4 bl clr_bss bl entry sub sp, sp, #200 sub sp, sp, #200 sub sp, sp, #200 sub sp, sp, #200 sub sp, sp, #200 sub sp, fp, #12 ldm sp, {fp, sp, pc} und: ldr sp, = 0x56000000 running FD sp !, {R0-r12, lr} mov lr, pc ldr pc, do_und _ ldmfd sp !, {R0-r12, pc} ^ do_und _:. word do_undsvc: stmfd sp !, {R0-r12, lr} @ when an exception occurs, the arm will always save the return address to lr = pc + 4 sub lr, #4 @ extract the command address mov r0 of svc abnormal source in the c program, lr @ Use r0 to transmit parameters mov lr, pc ldr pc, do_svc _ ldmfd sp !, {R0-r12, pc} do_svc _:. word do_svcpre_abort: data_abort: irq: ldr sp, = 0x58000000 sub lr, #4 @ irq is used to interrupt the program being executed. Therefore, you must upload FD sp at the breakpoint to be returned !, {R0-r12, lr} ldr r0, = 0x110002e0 ldr r1, = 0x1111 str r1, [r0] ldr r0, = 0x110002e4 ldr r1, = 0x0 str r1, [r0] mov lr, pc ldr pc, do_irq _ ldmfd sp !, {R0-r12, pc} ^ do_irq _:. word do_irqfiq :. globl _ bss_start_bss_start :. word _ bss_start.globl _ bss_end_bss_end :. word _ bss_endclr_bss: mov ip, sp push {fp, ip, lr, pc} sub fp, ip, #4 ldr r0, _ bss_start ldr r1, _ bss_end mov r2, #0 forclrbss: cmp r0, r1 bge endclrbss strb r2, [r0], #1 B forclrbss endclrbss: sub sp, fp, #12 ldm sp, {fp, sp, pc} _ end :. end
Link script ld. lds
1 OUTPUT_FORMAT ("elf32-littlearm", "elf32-littlearm", "elf32-littlearm") 2 OUTPUT_ARCH (arm) 3 ENTRY (_ start) 4 SECTIONS 5 {6/* Can this be noted? */7. = 0x40008000; 8 9. text: {10 start. o (. text); 11 *(. text); 12} 13 14. = ALIGN (4); 15 16. data: {17 *(. data); 18} 19 20. = ALIGN (4); 21 22 _ bss_start = .; 23. bss: {24 *(. bss); 25} 26 _ bss_end = .; 27}