为什么 __start 是处理器执行的第一条指令?

(嵌入式 实时操作系统 rtos nuttx 7.1 stm32 源代码分析)

为什么 __start 是处理器执行的第一条指令?

转载请注明出处: http://blog.csdn.net/zhumaill/article/details/23426605

在《 NuttX 启动流程》一文中提到, __start 是处理器执行的第一条指令。那么,为什么在 NuttX 中 __start 是处理器执行的第一条指令?为什么我要把 __start 称为“处理器执行的第一条指令”,而不是称为“程序入口点”?

nuttx/configs/shenzhou/scripts/ld.script:
......
OUTPUT_ARCH(arm)
ENTRY(_stext)
SECTIONS
......
这里的 ENTRY(_stext) 定义的程序入口点是 _stext。

nuttx/arch/arm/src/Makefile:
......
nuttx$(EXEEXT): $(HEAD_OBJ) board/libboard$(LIBEXT)
    $(Q) echo "LD: nuttx"
    $(Q) $(LD) --entry=__start $(LD
  • 3
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是使用汇编代码实现CPUID指令并输出处理器识别字符串的示例: ```assembly section .data cpuid_string db "Processor identification string: ", 0 buffer db 13,10, " ", 0 eax_value dd 0 ebx_value dd 0 ecx_value dd 0 edx_value dd 0 section .text global _start _start: ; print the CPUID string mov eax, 0x80000002 ; set EAX to start of processor identification string mov esi, buffer ; set ESI to point to buffer for storing identification string mov edi, eax_value ; set EDI to point to buffer for storing the four DWORDs returned by CPUID ; execute CPUID four times to get all four DWORDs of the identification string cpuid ; first execution of CPUID mov dword [edi], eax ; store first DWORD in buffer mov dword [edi+4], ebx ; store second DWORD in buffer mov dword [edi+8], ecx ; store third DWORD in buffer mov dword [edi+12], edx ; store fourth DWORD in buffer add edi, 16 ; move buffer pointer to next 16 bytes cmp eax, 0x80000004 ; check if we need to execute CPUID again jb print_string ; if not, print the identification string cpuid ; second execution of CPUID mov dword [edi], eax ; store first DWORD in buffer mov dword [edi+4], ebx ; store second DWORD in buffer mov dword [edi+8], ecx ; store third DWORD in buffer mov dword [edi+12], edx ; store fourth DWORD in buffer add edi, 16 ; move buffer pointer to next 16 bytes cmp eax, 0x80000005 ; check if we need to execute CPUID again jb print_string ; if not, print the identification string cpuid ; third execution of CPUID mov dword [edi], eax ; store first DWORD in buffer mov dword [edi+4], ebx ; store second DWORD in buffer mov dword [edi+8], ecx ; store third DWORD in buffer mov dword [edi+12], edx ; store fourth DWORD in buffer add edi, 16 ; move buffer pointer to next 16 bytes cmp eax, 0x80000006 ; check if we need to execute CPUID again jb print_string ; if not, print the identification string cpuid ; fourth execution of CPUID mov dword [edi], eax ; store first DWORD in buffer mov dword [edi+4], ebx ; store second DWORD in buffer mov dword [edi+8], ecx ; store third DWORD in buffer mov dword [edi+12], edx ; store fourth DWORD in buffer print_string: ; print the CPUID string mov eax, 4 ; set EAX to 4 to call the "write" system call mov ebx, 1 ; set EBX to 1 to specify stdout mov ecx, cpuid_string ; set ECX to point to the CPUID string to print int 0x80 ; call the system call to print the string mov eax, 4 ; set EAX to 4 to call the "write" system call mov ebx, 1 ; set EBX to 1 to specify stdout mov ecx, buffer ; set ECX to point to the buffer containing the identification string int 0x80 ; call the system call to print the identification string exit: ; exit the program mov eax, 1 ; set EAX to 1 to call the "exit" system call xor ebx, ebx ; set EBX to 0 to indicate success int 0x80 ; call the system call to exit the program ``` 这段代码使用CPUID指令获取处理器的识别字符串,并将其输出到控制台中。你可以将它保存为一个文件(例如`cpuid.asm`),使用汇编器和链接器将其编译成可执行文件,然后在终端中运行它。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值