.balign

本文详细介绍了BALIGN指令的使用方法及其变化形式.BALIGN用于调整存储器的位置计数器至特定的边界,支持不同的填充字节长度。文章解释了如何通过不同参数设置边界基准、填充字节及最大偏移量。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

.balign[wl] abs-expr, abs-expr, abs-expr

增 加位置计数器(在当前子段)使它指向规定的存储边界。第一个表达式参数(结果必须是纯粹的数字)是必需参数:边界基准,单位为字节。例 如,'.balign 8'向后移动位置计数器直至计数器的值等于8的倍数。如果位置计数器已经是8的倍数,则无需移动。第2个表达式参数(结果必须是纯粹的数字)给出填充字节 的值,用这个值填充位置计数器越过的地方。第2个参数(和逗点)可以省略。如果省略它,填充字节的值通常是0。但在某些系统上,如果本段标识为包含代码, 而填充值被省略,则使用no-op指令填充空白区。第3个参数的结果也必须是纯粹的数字,这个参数是可选的。如果存在第3个参数,它代表本对齐命令允许跳 过字节数的最大值。如果完成这个对齐需要跳过的字节数比规定的最大值还多,则根本无法完成对齐。您可以在边界基准参数后简单地使用两个逗号,以省略填充值 参数(第二参数);如果您在想在适当的时候,对齐操作自动使用no-op指令填充,本方法将非常奏效。

.balignw 和.balignl是.balign命令的变化形式。.balignw使用2个字节来填充空白区。.balignl使用4字节来填充。例 如,.balignw 4,0x368d将地址对齐到4的倍数,如果它跳过2个字节,GAS将使用0x368d填充这2个字节(字节的确切存放位置视处理器的存储方式而定)。
如果它跳过1或3个字节,则填充值不明确。

帮我分析这个代码,是arm a52的cpu,32位: //----------------------------------------------------------------------------- // The confidential and proprietary information contained in this file may // only be used by a person authorised under and to the extent permitted // by a subsisting licensing agreement from ARM Limited or its affiliates. // // (C) COPYRIGHT 2014-2021 ARM Limited or its affiliates. // ALL RIGHTS RESERVED // // This entire notice must be reproduced on all copies of this file // and copies of this file may only be made by a person if such person is // permitted to do so under the terms of a subsisting license agreement // from ARM Limited or its affiliates. // // Release Information : Cortex-R52 Processor MP040-r1p4-00rel0 // //----------------------------------------------------------------------------- .include "shared/bootcode/boot_defs.hs" // Enable UAL syntax .syntax unified .section .text.vectors, "ax", %progbits .global vector_table .type vector_table, %function // Weakly import replacement handlers. This allows a test to redefine // handlers. If it doesn't, the default ones below will be used. .weak bootcode_other .weak undef_handler .weak svc_handler .weak pf_abort_handler .weak data_abort_handler .type data_abort_handler, %function .weak irq_handler .type irq_handler, %function .weak fiq_handler .type print, %function //------------------------------------------------------------------------------ // Vector table //------------------------------------------------------------------------------ vector_table: ldr pc, reset_handler_addr // Reset ldr pc, undef_handler_addr // Undef ldr pc, svc_handler_addr // SVC ldr pc, pf_abort_handler_addr // Prefetch abort ldr pc, data_abort_handler_addr // Data abort nop // Not used ldr pc, irq_handler_addr // IRQ ldr pc, fiq_handler_addr // FIQ //------------------------------------------------------------------------------ // Handler addresses //------------------------------------------------------------------------------ reset_handler_addr: .word def_reset_handler undef_handler_addr: .word def_undef_handler svc_handler_addr: .word def_svc_handler pf_abort_handler_addr: .word def_pf_abort_handler data_abort_handler_addr: .word def_data_abort_handler irq_handler_addr: .word def_irq_handler fiq_handler_addr: .word def_fiq_handler //---------------------------------------------------------------------------- // Handler strings //---------------------------------------------------------------------------- // The default handlers print an error message and terminate the simulation // by writing the EOT character to the tube. The error strings are defined // here. undef_exception_str: .asciz "undefined instruction\n" svc_exception_str: .asciz "SVC\n" pf_abort_exception_str: .asciz "prefetch abort\n" data_abort_exception_str: .asciz "data abort\n" irq_exception_str: .asciz "IRQ\n" fiq_exception_str: .asciz "FIQ\n" // Ensure 4-byte alignment for following code .balign 4 //------------------------------------------------------------------------------ // Default handlers // // The default handlers all contain one branch to a weakly-imported exception // handler label followed by default handler code. This allows tests to // define their own handlers, with fall-back default handlers if they do not. // // When a test defines a replacement handler, it must end with an excpetion // return instruction so that the default handler code is never executed. // // When a test does not define a replacement handler, the branch to the // weakly-imported symbol in the default handler is effectively a NOP and // the default handler code is therefore executed. // // The default handlers all print an "Unexpected exception" error message // and terminate the simulation by writing the EOT character to the tube. //------------------------------------------------------------------------------ def_reset_handler: b bootcode def_undef_handler: b undef_handler ldr r0, =undef_exception_str b unexpected_handler def_svc_handler: b svc_handler ldr r0, =svc_exception_str b unexpected_handler def_pf_abort_handler: b pf_abort_handler ldr r0, =pf_abort_exception_str b unexpected_handler def_data_abort_handler: b data_abort_handler ldr r0, =data_abort_exception_str b unexpected_handler def_irq_handler: b irq_handler ldr r0, =irq_exception_str b unexpected_handler def_fiq_handler: b fiq_handler ldr r0, =fiq_exception_str b unexpected_handler // Generic unexpected handler routine. This prints an error message and // terminates the simulation by writing the EOT character to the tube. // Expects r0 to contain a pointer to a string that is the name of the // exception. As this is a terminal routine, no registers are preserved. unexpected_handler: ldr r1, =TUBE_ADDRESS ldr r2, =unexpected_str // Message bl print mov r2, r0 bl print ldr r2, =fail_str bl print // Write EOT character to terminate the simulation mov r2, #0x4 strb r2, [r1] dsb wfi b . // Print a string to the tube // Expects: r1 -> tube // r2 -> message // Modifies r3 print: ldrb r3, [r2], #1 cmp r3, #0 strbne r3, [r1] bne print bx lr unexpected_str: .asciz "Unexpected exception: " fail_str: .asciz "** TEST FAILED **\n" .balign 4 .end
06-25
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值