Toggle navigation
首页
问答
文章
积分商城
专家
专区
更多专区...
文档中心
返回主站
搜索
提问
会员
中心
登录
注册
Kernel
imx6
在imx6q中到最后调用rt_system_scheduler_start总会出现undefined abort
发布于 2019-04-24 12:01:59 浏览:1760
订阅该版
```c void rt_system_scheduler_start(void) { register struct rt_thread *to_thread; rt_ubase_t highest_ready_priority; to_thread = _get_highest_priority_thread(&highest_ready_priority); #ifdef RT_USING_SMP to_thread->oncpu = rt_hw_cpu_id(); #else rt_current_thread = to_thread; #endif /*RT_USING_SMP*/ rt_schedule_remove_thread(to_thread); to_thread->stat = RT_THREAD_RUNNING; /* switch to new thread */ #ifdef RT_USING_SMP rt_hw_context_switch_to((rt_ubase_t)&to_thread->sp, to_thread); #else rt_hw_context_switch_to((rt_ubase_t)&to_thread->sp); #endif /*RT_USING_SMP*/ /* never come back */ }```#ifdef RT_USING_SMP rt_hw_context_switch_to((rt_ubase_t)&to_thread->sp, to_thread); #else rt_hw_context_switch_to((rt_ubase_t)&to_thread->sp); ``` 用IAR DEBUG时,打断点发现每次一到这最后一句然后跳转到初始化过的 thread时,总会出现异常指令退出,rt_hw_context_switch_to 定义位于context.s参考的是qemu_vexpress_a9中的例子context_gcc.S,都是多核按理说这个应该是一致的,无须修改。 下面给出修改过的适用于IAR的汇编文件context.s ```c PUBLIC rt_hw_context_switch_interrupt PUBLIC rt_hw_context_switch PUBLIC rt_hw_context_switch_to ; PUBLIC rt_hw_interrupt_enable ; PUBLIC rt_hw_interrupt_disable SECTION .text:CODE:ROOT(2) ARM IMPORT rt_cpus_lock_status_restore IMPORT rt_interrupt_to_thread IMPORT rt_thread_switch_interrupt_flag IMPORT rt_interrupt_from_thread #include "rtconfig.h" #ifdef RT_USING_SMP PUBLIC rt_hw_local_irq_enable PUBLIC rt_hw_local_irq_disable ; rt_base_t rt_hw_interrupt_disable(); rt_hw_local_irq_disable: mrs r0, cpsr cpsid i bx lr ;void rt_hw_interrupt_enable(rt_base_t level); rt_hw_local_irq_enable: msr cpsr, r0 bx lr #else PUBLIC rt_hw_interrupt_disable PUBLIC rt_hw_interrupt_enable ; rt_base_t rt_hw_interrupt_disable(); rt_hw_interrupt_disable: mrs r0, cpsr cpsid i bx lr ; void rt_hw_interrupt_enable(rt_base_t level); rt_hw_interrupt_enable: msr cpsr, r0 bx lr #endif ; void rt_hw_context_switch_to(rt_ubase_t to, struct rt_thread *to_thread); ; r0 --> to rt_hw_context_switch_to: ldr sp, [r0] ; get new task stack pointer #ifdef RT_USING_SMP mov r0, r1 bl rt_cpus_lock_status_restore #endif ;/*RT_USING_SMP*/ #ifdef RT_USING_LWP ldmfd sp, {r13, r14}^ ; pop usr_sp usr_lr add sp, #8 #endif ldmfd sp!, {r4} ; pop new task spsr msr spsr_cxsf, r4 ldmfd sp!, {r0-r12, lr, pc}^ ; pop new task r0-r12, lr & pc ;.section .bss.share.isr ;_guest_switch_lvl: ; DCD 0 ;.section .text.isr, "ax" ; void rt_hw_context_switch(rt_ubase_t from, rt_ubase_t to, struct rt_thread *to_thread); ; r0 --> from ; r1 --> to rt_hw_context_switch: stmfd sp!, {lr} ; push pc (lr should be pushed in place of PC) stmfd sp!, {r0-r12, lr} ; push lr & register file mrs r4, cpsr tst lr, #0x01 orrne r4, r4, #0x20 ; it's thumb code stmfd sp!, {r4} ; push cpsr #ifdef RT_USING_LWP stmfd sp, {r13, r14}^ ; push usr_sp usr_lr sub sp, #8 #endif str sp, [r0] ; store sp in preempted tasks TCB ldr sp, [r1] ; get new task stack pointer #ifdef RT_USING_SMP mov r0, r2 bl rt_cpus_lock_status_restore #endif ;/*RT_USING_SMP*/ #ifdef RT_USING_LWP ldmfd sp, {r13, r14}^ ; pop usr_sp usr_lr add sp, #8 #endif ldmfd sp!, {r4} ; pop new task cpsr to spsr msr spsr_cxsf, r4 ldmfd sp!, {r0-r12, lr, pc}^ ; pop new task r0-r12, lr & pc, copy spsr to cpsr #define Mode_USR 0x10 #define Mode_FIQ 0x11 #define Mode_IRQ 0x12 #define Mode_SVC 0x13 #define Mode_ABT 0x17 #define Mode_UND 0x1B #define Mode_SYS 0x1F #define I_Bit 0x80 ; when I bit is set, IRQ is disabled #define F_Bit 0x40 ; when F bit is set, FIQ is disabled ; void rt_hw_context_switch_interrupt(void *context, rt_ubase_t from, rt_ubase_t to, struct rt_thread *to_thread); rt_hw_context_switch_interrupt: #ifdef RT_USING_SMP ; r0 :irq_mod context ; r1 :addr of from_thread's sp ; r2 :addr of to_thread's sp ; r3 :to_thread's tcb ; r0 point to {r0-r3} in stack push {r1 - r3} mov r1, r0 add r0, r0, #4*4 ldmfd r0!, {r4-r12,lr}; reload saved registers mrs r3, spsr ; get cpsr of interrupt thread sub r2, lr, #4 ; save old task's pc to r2 msr cpsr_c, #I_Bit|F_Bit|Mode_SVC stmfd sp!, {r2} ; push old task's pc stmfd sp!, {r4-r12,lr}; push old task's lr,r12-r4 ldmfd r1, {r4-r7} ; restore r0-r3 of the interrupt thread stmfd sp!, {r4-r7} ; push old task's r0-r3 stmfd sp!, {r3} ; push old task's cpsr #ifdef RT_USING_LWP stmfd sp, {r13,r14}^ ;push usr_sp usr_lr sub sp, #8 #endif msr cpsr_c, #I_Bit|F_Bit|Mode_IRQ pop {r1 - r3} mov sp, r0 msr cpsr_c, #I_Bit|F_Bit|Mode_SVC str sp, [r1] ldr sp, [r2] mov r0, r3 bl rt_cpus_lock_status_restore #ifdef RT_USING_LWP ldmfd sp, {r13,r14}^ ;pop usr_sp usr_lr add sp, #8 #endif ldmfd sp!, {r4} ; pop new task's cpsr to spsr msr spsr_cxsf, r4 ldmfd sp!, {r0-r12,lr,pc}^ ; pop new task's r0-r12,lr & pc, copy spsr to cpsr #else ;/*RT_USING_SMP*/ ldr r2, =rt_thread_switch_interrupt_flag ldr r3, [r2] cmp r3, #1 beq _reswitch ldr sp, =rt_interrupt_from_thread ; set rt_interrupt_from_thread mov r3, #1 ; set rt_thread_switch_interrupt_flag to 1 str r0, [sp] str r3, [r2] _reswitch: ldr r2, =rt_interrupt_to_thread ; set rt_interrupt_to_thread str r1, [r2] bx lr #endif ;/*RT_USING_SMP*/ END ``` QEMU_VEXPRESS_A9中的context.s是这样的 ```c #include "rtconfig.h" .section .text, "ax" #ifdef RT_USING_SMP #define rt_hw_interrupt_disable rt_hw_local_irq_disable #define rt_hw_interrupt_enable rt_hw_local_irq_enable #endif /* * rt_base_t rt_hw_interrupt_disable(); */ .globl rt_hw_interrupt_disable rt_hw_interrupt_disable: mrs r0, cpsr cpsid i bx lr /* * void rt_hw_interrupt_enable(rt_base_t level); */ .globl rt_hw_interrupt_enable rt_hw_interrupt_enable: msr cpsr, r0 bx lr /* * void rt_hw_context_switch_to(rt_uint32 to); * r0 --> to */ .globl rt_hw_context_switch_to rt_hw_context_switch_to: ldr sp, [r0] @ get new task stack pointer #ifdef RT_USING_SMP mov r0, r1 bl rt_cpus_lock_status_restore #endif /*RT_USING_SMP*/ #ifdef RT_USING_LWP ldmfd sp, {r13, r14}^ @ pop usr_sp usr_lr add sp, #8 #endif ldmfd sp!, {r4} @ pop new task spsr msr spsr_cxsf, r4 ldmfd sp!, {r0-r12, lr, pc}^ @ pop new task r0-r12, lr & pc .section .bss.share.isr _guest_switch_lvl: .word 0 .section .text.isr, "ax" /* * void rt_hw_context_switch(rt_uint32 from, rt_uint32 to); * r0 --> from * r1 --> to */ .globl rt_hw_context_switch rt_hw_context_switch: stmfd sp!, {lr} @ push pc (lr should be pushed in place of PC) stmfd sp!, {r0-r12, lr} @ push lr & register file mrs r4, cpsr tst lr, #0x01 orrne r4, r4, #0x20 @ it's thumb code stmfd sp!, {r4} @ push cpsr #ifdef RT_USING_LWP stmfd sp, {r13, r14}^ @ push usr_sp usr_lr sub sp, #8 #endif str sp, [r0] @ store sp in preempted tasks TCB ldr sp, [r1] @ get new task stack pointer #ifdef RT_USING_SMP mov r0, r2 bl rt_cpus_lock_status_restore #endif /*RT_USING_SMP*/ #ifdef RT_USING_LWP ldmfd sp, {r13, r14}^ @ pop usr_sp usr_lr add sp, #8 #endif ldmfd sp!, {r4} @ pop new task cpsr to spsr msr spsr_cxsf, r4 ldmfd sp!, {r0-r12, lr, pc}^ @ pop new task r0-r12, lr & pc, copy spsr to cpsr /* * void rt_hw_context_switch_interrupt(rt_ubase_t from, rt_ubase_t to); */ .equ Mode_USR, 0x10 .equ Mode_FIQ, 0x11 .equ Mode_IRQ, 0x12 .equ Mode_SVC, 0x13 .equ Mode_ABT, 0x17 .equ Mode_UND, 0x1B .equ Mode_SYS, 0x1F .equ I_Bit, 0x80 @ when I bit is set, IRQ is disabled .equ F_Bit, 0x40 @ when F bit is set, FIQ is disabled .globl rt_thread_switch_interrupt_flag .globl rt_interrupt_from_thread .globl rt_interrupt_to_thread .globl rt_hw_context_switch_interrupt rt_hw_context_switch_interrupt: #ifdef RT_USING_SMP /* r0 :irq_mod context * r1 :addr of from_thread's sp * r2 :addr of to_thread's sp * r3 :to_thread's tcb */ @ r0 point to {r0-r3} in stack push {r1 - r3} mov r1, r0 add r0, r0, #4*4 ldmfd r0!, {r4-r12,lr}@ reload saved registers mrs r3, spsr @ get cpsr of interrupt thread sub r2, lr, #4 @ save old task's pc to r2 msr cpsr_c, #I_Bit|F_Bit|Mode_SVC stmfd sp!, {r2} @ push old task's pc stmfd sp!, {r4-r12,lr}@ push old task's lr,r12-r4 ldmfd r1, {r4-r7} @ restore r0-r3 of the interrupt thread stmfd sp!, {r4-r7} @ push old task's r0-r3 stmfd sp!, {r3} @ push old task's cpsr #ifdef RT_USING_LWP stmfd sp, {r13,r14}^ @push usr_sp usr_lr sub sp, #8 #endif msr cpsr_c, #I_Bit|F_Bit|Mode_IRQ pop {r1 - r3} mov sp, r0 msr cpsr_c, #I_Bit|F_Bit|Mode_SVC str sp, [r1] ldr sp, [r2] mov r0, r3 bl rt_cpus_lock_status_restore #ifdef RT_USING_LWP ldmfd sp, {r13,r14}^ @pop usr_sp usr_lr add sp, #8 #endif ldmfd sp!, {r4} @ pop new task's cpsr to spsr msr spsr_cxsf, r4 ldmfd sp!, {r0-r12,lr,pc}^ @ pop new task's r0-r12,lr & pc, copy spsr to cpsr #else /*RT_USING_SMP*/ ldr r2, =rt_thread_switch_interrupt_flag ldr r3, [r2] cmp r3, #1 beq _reswitch ldr ip, =rt_interrupt_from_thread @ set rt_interrupt_from_thread mov r3, #1 @ set rt_thread_switch_interrupt_flag to 1 str r0, [ip] str r3, [r2] _reswitch: ldr r2, =rt_interrupt_to_thread @ set rt_interrupt_to_thread str r1, [r2] bx lr #endif /*RT_USING_SMP*/ ``` 弄了好几天一直卡在这,求大神指点
查看更多
7
个回答
默认排序
按发布时间排序
bernard
2019-04-24
这家伙很懒,什么也没写!
多核版本?移植部分都弄好了?
hwx628
2019-04-24
这家伙很懒,什么也没写!
>多核版本?移植部分都弄好了? 移植肯定弄好了 ,否则IAR编译也不能通过,原来是在不带系统的时候,改好了底层驱动,后来一点道移植到rt_thread上的,现在卡在这略尴尬,原来是我向老板推荐的这个系统,要是做不出来就坑了 ``` beq _reswitch ldr ip, =rt_interrupt_from_thread @ set rt_interrupt_from_thread mov r3, #1 @ set rt_thread_switch_interrupt_flag to 1 str r0, [ip] str r3, [r2] ``` 上面这段汇编里边有个困惑的if ,为什么会用到ip寄存器,是不是写错了 arm里边没有ip寄存器吧
hwx628
2019-04-24
这家伙很懒,什么也没写!
>多核版本?移植部分都弄好了? 原来在不带系统的情况下,就是基于imx给出SDK,自己实现了SPI通信,还有一些定时模块,现在要充分释放这块单核1GHz的四核板性难,必须找个开源的支持SMP的多核系统
hwx628
2019-04-24
这家伙很懒,什么也没写!
>移植肯定弄好了 ,否则IAR编译也不能通过,原来是在不带系统的时候,改好了底层驱动,后来一点道移植到r ... 我把ip改成了SP才编译通过的,但是两个含义完全不一样,这个文件中在SMP模式下,就用的sp,为什么单核就突然冒出了ip
bernard
2019-04-24
这家伙很懒,什么也没写!
那你先用gcc跑通,跑起来吧
bernard
2019-04-24
这家伙很懒,什么也没写!
>移植肯定弄好了 ,否则IAR编译也不能通过,原来是在不带系统的时候,改好了底层驱动,后来一点道移植到r ... 移植做好不等于编译做好,这个是两个概念。 需要底层的代码,汇编代码都处理好。 多核部分,还和多核的启动方式也相关
memeda
2023-11-14
这家伙很懒,什么也没写!
您好,想问下您这个imx6q开发板在rt-thread上移植OK了吗
撰写答案
登录
注册新账号
关注者
0
被浏览
1.8k
关于作者
hwx628
这家伙很懒,什么也没写!
提问
5
回答
12
被采纳
0
关注TA
发私信
相关问题
1
请教cpu使用率分析
2
选择FreeRTOS, 还是RT-Thread。
3
thread heap stack overflow ?
4
rtt消息队列delay问题
5
释放被删除线程的内存地方在哪里啊
6
请教:各线程结束后,释放其中的内存的连续性问题
7
STM32F103中断关于信号量、邮箱问题
8
RTT中的线程栈大小如何控制
9
关于线程由执行态变为挂起态的代码实现,,,
10
rt_malloc(rt_size_t size)内存分配函数最小分配尺寸问题
推荐文章
1
RT-Thread应用项目汇总
2
玩转RT-Thread系列教程
3
国产MCU移植系列教程汇总,欢迎查看!
4
机器人操作系统 (ROS2) 和 RT-Thread 通信
5
五分钟玩转RT-Thread新社区
6
【技术三千问】之《玩转ART-Pi》,看这篇就够了!干货汇总
7
关于STM32H7开发板上使用SDIO接口驱动SD卡挂载文件系统的问题总结
8
STM32的“GPU”——DMA2D实例详解
9
RT-Thread隐藏的宝藏之completion
10
【ART-PI】RT-Thread 开启RTC 与 Alarm组件
最新文章
1
使用百度AI助手辅助编写一个rt-thread下的ONVIF设备发现功能的功能代码
2
RT-Thread 发布 EtherKit开源以太网硬件!
3
rt-thread使用cherryusb实现虚拟串口
4
《C++20 图形界面程序:速度与渲染效率的双重优化秘籍》
5
《原子操作:程序世界里的“最小魔法单位”解析》
热门标签
RT-Thread Studio
串口
Env
LWIP
SPI
AT
Bootloader
Hardfault
CAN总线
FinSH
ART-Pi
USB
DMA
文件系统
RT-Thread
SCons
RT-Thread Nano
线程
MQTT
STM32
RTC
FAL
rt-smart
ESP8266
I2C_IIC
WIZnet_W5500
UART
ota在线升级
PWM
cubemx
freemodbus
flash
packages_软件包
BSP
潘多拉开发板_Pandora
定时器
ADC
GD32
flashDB
socket
中断
Debug
编译报错
msh
SFUD
keil_MDK
rt_mq_消息队列_msg_queue
at_device
ulog
C++_cpp
本月问答贡献
踩姑娘的小蘑菇
7
个答案
3
次被采纳
a1012112796
13
个答案
2
次被采纳
张世争
9
个答案
2
次被采纳
rv666
5
个答案
2
次被采纳
用户名由3_15位
11
个答案
1
次被采纳
本月文章贡献
程序员阿伟
7
篇文章
2
次点赞
hhart
3
篇文章
4
次点赞
大龄码农
1
篇文章
3
次点赞
ThinkCode
1
篇文章
1
次点赞
Betrayer
1
篇文章
1
次点赞
回到
顶部
发布
问题
分享
好友
手机
浏览
扫码手机浏览
投诉
建议
回到
底部