assembly - 在 AMR7TDMI 处理器中从 `User` 切换到 `Supervisor` 模式

标签 assembly arm embedded-linux cpu-architecture processor

我试图在运行 ARM7TDMI 处理器的旧板上从User 切换到Supervisor 模式。它有七种操作模式:用户、 FIQ、IRQ、主管、中止、未定义和系统。 User 是唯一的非priv 模式。我希望进入主管模式。我正在使用 qemu 来模拟该板,并使用 Gnu GCC 编译器工具链。我的主板上也有 Linux 内核。

从处理器手册的技术文档中我可以看到,这样做我需要生成一个SWI(软件中断)。这是文档所说的

http://bear.ces.cwru.edu/eecs_382/ARM7-TDMI-manual-pt2.pdf [第4.13节]

The software interrupt instruction is used to enter Supervisor mode in a controlled
manner. The instruction causes the software interrupt trap to be taken, which effects
the mode change.

我想我需要为 SWI 编写自己的中断处理程序。我可以看到一些关于它的帖子

writing interrupt routines using gcc for arm

Simplest bare metal program for ARM

但是,当我按照上面概述的说明进行操作时,我遇到了段错误。我在这里有点困惑。阅读了我需要编码中断处理程序的方式后,我意识到我需要调整中断向量表以包含我的新 SWI 处理程序。对于用户空间程序来说,这似乎存在太大的安全风险。我的段错误可能是因为我损坏了内存空间,或者只是因为不允许我更改内存(即将我的处理程序添加到 IVT)

任何人都可以指导我获得更好的资源来实现这一目标吗?

有关如何解决此问题的任何建议。我是嵌入式编程新手,所以我认为我的知识不是很好。

最佳答案

https://groups.google.com/forum/#!topic/comp.sys.arm/3ybxWHwKKcA

However no ARM chip allows the processor to be switched from user mode to a privileged via an MSR, as this would completely invalidate any process protection implemented by the operating system.

The only way to switch out of user mode is to cause an exception which results in the processor switching to a privileged mode in order to service it via the hardware vectors. The normal way is to use a SWI (software interrupt) instruction either directly or via an OS API, however it is entirely up to the operating system whether implement this facility or grant permission to a particular task.

因此,您确实需要在操作系统级别解决问题,而不仅仅是编写“ARM 中断处理程序”。换句话说,你需要研究如何编写Linux内核驱动程序(进而调用ARM命令来切换模式)。

有很多很多资源可以向您介绍内核编程。例如:

关于assembly - 在 AMR7TDMI 处理器中从 `User` 切换到 `Supervisor` 模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31556000/

相关文章:

android - "bitsperlong.h": trouble cross-building Perf for ARM (Android)

linux - 将 busybox 编译为 BFLT 可执行文件

c - 并行端口计算机间通信的可能性

c - 汇编中的无符号整数

c++ - C 和 C++ 标准库是用什么语言编写的?

assembly - XOR寄存器,寄存器(汇编器)

linux - 充当代理的 IO 服务器

loops - 如何仅使用 3 条指令和一个 8 位寄存器(8086 指令集)编写循环 256 次的代码?

c - 如何在 ARM 中使用字符串?

c - STM32 HAL库RTC闹钟