Where is the “Zero divide” done in kernel for Arm Cortex A-9

半城伤御伤魂 提交于 2019-12-08 08:56:16

问题


I am looking into kernel source code (2.6.35 ) for Zero divide .

I inserted Zero divide in user space program and all threads stopped.

So I want to know Where is the "Zero divide" done in kernel for Arm Cortex A-9?

I am not able to find any trap for this ....

Thanks


回答1:


It depends on the architecture. Given the following user space code on an x86 system:

main() {                                                                                                                                                                             
   int x = 42 / 0;                                                                                                                                                                   
}                                                                                                                                                                                    

the compiler inserts a idivl command into the object code. When this command is executed with a divisor of 0, the CPU generates a division by zero trap (similar to an interrupt). This calls the divide_error trap handler inside the kernel, in case of x86 it is located in arch/x86/kernel/entry_32.S:

ENTRY(divide_error)
        RING0_INT_FRAME
        pushl_cfi $0                    # no error code
        pushl_cfi $do_divide_error
        jmp error_code
        CFI_ENDPROC
END(divide_error)

The error_code target then takes care of all necessary actions to handle the error and finally returns from the trap.


On ARM, things are different: With a few exceptions, ARM CPUs do not have a hardware division instruction (e.g. Arm Cortex A-9 does not have one). Division needs to be implemented as a library function. For the kernel, this is implemented in arch/arm/lib/lib1funcs.S where you also find the division by zero handling. For user space applications, I suppose this is implemented as a library function in the libgcc library.



来源:https://stackoverflow.com/questions/12526276/where-is-the-zero-divide-done-in-kernel-for-arm-cortex-a-9

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!