[BUG] ARM_CRx_MPU: tasks start with CPSR.E = 0, so big-endian Cortex-R4/R5 parts (e.g. TI TMS570) run tasks with little-endian data
Maintainer thường phản hồi trong vòng 3 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 78/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- c
- Lĩnh vực
- operating-systems
Hướng nghiên cứu
Bắt đầu tại portable/GCC/ARM_CRx_MPU/port.c và kiểm tra hai phần khởi tạo CPSR trong pxPortInitialiseStack() dành cho các tác vụ có đặc quyền và không có đặc quyền. Kiểm tra cách trình biên dịch nhận diện các bản dựng big-endian và cách port biểu diễn các bit CPSR; báo cáo bao gồm một đề xuất thay đổi tối thiểu và xác nhận đề xuất đó trên TMS570. Hoàn tất khi cả hai chế độ tác vụ vẫn giữ quyền truy cập dữ liệu big-endian và tác vụ bộ định thời chạy mà không gặp lỗi abort đã báo cáo.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Describe the bug
On a big-endian Cortex-R target, every task created by the ARM_CRx_MPU port runs with little-endian data accesses. Any multi-byte value shared between task code and code running with the correct byte order (interrupt handlers, start-up code, the scheduler before the first task) is then read byte-reversed.
On the Cortex-R4/R5, the CPSR E bit (bit 9) selects data endianness. Big-endian parts such as the TI Hercules TMS570 need E = 1; the core sets it at reset and on every exception entry (SCTLR.EE). But pxPortInitialiseStack() builds each task's initial CPSR from a constant, which clears E:
/* portable/GCC/ARM_CRx_MPU/port.c */
if( xRunPrivileged == pdTRUE )
{
xMPUSettings->ulTaskFlags |= portTASK_IS_PRIVILEGED_FLAG;
/* Current Program Status Register (CPSR). */
xMPUSettings->ulContext[ ulIndex ] = SYS_MODE; /* 0x1F: E = 0 */
}
else
{
xMPUSettings->ulTaskFlags &= ( ~portTASK_IS_PRIVILEGED_FLAG );
/* Current Program Status Register (CPSR). */
xMPUSettings->ulContext[ ulIndex ] = USER_MODE; /* 0x10: E = 0 */
}
The port's system-call entry and exit paths in portASM.S modify SPSR read-modify-write, so they keep E. Only these two initialisations are affected.
For comparison, the older portable/CCS/ARM_Cortex-R4 port keeps the upper CPSR bits, and so keeps E, by building the value from the current CPSR: ( _get_CPSR() & ~0xFF ) | portINITIAL_SPSR. TI's HALCoGen FreeRTOS port for the TMS570 does the same. The reference demo for this port (CORTEX_MPU_R4F_TI_RM46_HERCULES_GCC) runs on the little-endian RM46, which is why the bug doesn't show there.
Target
- Development board: TI TMDX570LS31HDK (TMS570LS3137, Cortex-R4F r1p3, big-endian BE32)
- Instruction set: ARMv7-R (ARM state)
- IDE and version: TI Code Composer Studio 21.0.1
- Toolchain and version: TI Arm Clang (
tiarmclang) 5.1.1 LTS,-mcpu=cortex-r4 -mbig-endian -mfloat-abi=hard -mfpu=vfpv3-d16 -marm, linked with--be32
Host
- Host OS: Windows 11
- Version: build 26200, ARM64
To Reproduce
- Build any FreeRTOS V11.3.3 application with the
ARM_CRx_MPUport for a big-endian Cortex-R4/R5 (-mbig-endian). UseconfigUSE_TIMERS 1and create one task. - Run it on the target.
- The timer service task takes a data abort on its first pass through
prvTimerTask()(timers.cline 853): it loadspxCurrentTimerList, which the scheduler start-up code stored with E = 1, and gets the byte-reversed value. In our case the stored address 0x080024D0 came back as 0xD0240008. Dereferencing it gives a synchronous external abort (DFSR 0x8, DFAR 0xD0240008). - At the abort, SPSR_abt is 0x0000001F: the task was in SYS mode with E = 0.
Expected behavior
Tasks run with the same data endianness as the rest of the system: E = 1 on big-endian targets.
Screenshots
None. The register values above were captured with the debugger.
Additional context
A minimal fix that keeps E on big-endian builds, using the ACLE macro __ARM_BIG_ENDIAN (defined by GCC and Clang under -mbig-endian):
+#if defined( __ARM_BIG_ENDIAN )
+ #define portINITIAL_CPSR_ENDIAN_BIT ( 0x200UL ) /* CPSR.E = 1: big-endian data */
+#else
+ #define portINITIAL_CPSR_ENDIAN_BIT ( 0x0UL )
+#endif
...
- xMPUSettings->ulContext[ ulIndex ] = SYS_MODE;
+ xMPUSettings->ulContext[ ulIndex ] = SYS_MODE | portINITIAL_CPSR_ENDIAN_BIT;
...
- xMPUSettings->ulContext[ ulIndex ] = USER_MODE;
+ xMPUSettings->ulContext[ ulIndex ] = USER_MODE | portINITIAL_CPSR_ENDIAN_BIT;
With this change, the same application runs correctly on the TMDX570LS31HDK in both debug and optimised builds:
- tasks run with CPSR 0x21F (privileged) and 0x210 (user)
- the timer task, task delays and the tick all behave as expected
- no faults occur
An alternative is to copy the upper CPSR bits from the current CPSR, as the CCS ARM_Cortex-R4 port does. That also keeps any other configuration bits, but it needs a CPSR read in C (an MRS intrinsic or inline assembly).
We're happy to open a pull request with whichever approach you prefer.
- Ngôn ngữ chính
- C
- Star
- 4.6k
- Fork
- 1.6k
- Merge trung bình
- 2 ngày 22 giờ
- Pull request đã merge (30 ngày)
- 4
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của FreeRTOS/FreeRTOS-Kernel
-
[BUG] Release asset FreeRTOS-KernelV11.3.2.zip has the files of main, not of the tag V11.3.2Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
FreeRTOS/FreeRTOS-Kernel#1520 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
FreeRTOS/FreeRTOS-Kernel#1494 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 3 ngày
-
enhancement
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
FreeRTOS/FreeRTOS-Kernel#1554 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
[BUG] event_wait_timed can't return falseCó thể đã có người làm @TedLyngmo đã nhận 39 ngày trước. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 38/100
FreeRTOS/FreeRTOS-Kernel#1546 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
bug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 22/100
FreeRTOS/FreeRTOS-Kernel#1545 ·
Maintainer thường phản hồi trong vòng 3 ngày
Tất cả issue của FreeRTOS/FreeRTOS-Kernel
Issue tương tự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
bug
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 63/100
FreeRTOS/FreeRTOS-Plus-TCP#1395 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
qoretechnologies/qore#8222 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
c easy first-contributor first-contributors good first issue help wanted up-for-grabs
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 96/100
fork-commit-merge/fork-commit-merge#8696 ·
Maintainer thường phản hồi trong vòng 1 ngày