4th Module MC Sem Exam Preparation
4th Module MC Sem Exam Preparation
ARM must decide which exception to handle first — that's why it uses a priority mechanism.
Table 9.3 (from the text) lists exceptions from highest to lowest priority.
📌 When an exception is taken, ARM automatically sets these bits to prevent further interrupts:
o ⚠ Must avoid instructions like SWI, aborts, undefined ops early on.
2. Data Abort
5. Prefetch Abort
7. Undefined Instruction
✅ What is LR in Exceptions?
🔧 Each exception sets LR to a different offset from PC depending on when it's taken.
✅ Purpose:
The Link Register (LR) is used to store the return address when an exception occurs. It allows the
processor to return to the instruction that was being executed before the exception interrupted the
normal flow.
1. 🔁 The current Program Counter (PC) value is stored in LR of the exception mode (e.g.,
r14_irq, r14_fiq, r14_svc, etc.).
4. Later, to return, the value in LR is used to restore PC, and the processor resumes normal
execution.
asm
CopyEdit
<handler code>
...
📝 Explanation:
SUBS subtracts 4 from the Link Register (r14) and stores the result in pc (Program Counter).
Since the destination is pc and the instruction ends with S, it also causes the processor to:
This is the standard method used to return from IRQ or FIQ exceptions in ARM processors.
✅ This ensures both program flow and status flags are restored properly after handling the
exception.
⚙️ARM Firmware Suite (AFS), Firmware Execution Flow, and Red
Hat RedBoot
📘 As per VTU syllabus – Module 5: Firmware and Bootloader
ARM has developed a firmware package called the ARM Firmware Suite (AFS).
AFS is specially designed for ARM-based embedded systems and supports many ARM processors
such as Intel XScale and StrongARM.
It offers a standard API, which makes it easier to port firmware to new platforms because only the
hardware-specific parts need to follow the API functions.
1. System Initialization
When any embedded system like an ARM processor is powered on, the first thing it does is prepare
itself to work properly. This preparation step is called system initialization.
o This sets up the target platform and processor core when the system starts.
It’s easy: just a few steps like turning on memory or enabling a timer.
This part talks about how the board (target) and the computer or host communicate with each
other during early stages of booting.
💬 What is it?
It means the board can send or receive messages (like logs or commands) to/from a
connected computer (host).
🔄 What is “Polled”?
The board keeps checking again and again ("polling") if any data has arrived.
It's like a person looking at their phone screen every few seconds to see if they got a
message 📱.
✅ When is it used?
When interrupts are not yet enabled, because using interrupts needs more setup.
🎯 Why it matters:
What is μHAL?
μHAL (Micro Hardware Abstraction Layer) is a small piece of software that helps your code
talk to the hardware.
It hides the hardware complexity and gives easy functions to control things like LEDs.
It lets your program turn ON, OFF, or blink LEDs on the board.
🧠 Why is it useful?
Even if there's no screen, you can still know what's happening by looking at LED behavior.
4. Timer Support
Preemptive operating systems (like real-time OS) use these timer interrupts to:
✅ Result
Thanks to timers, multiple things can run smoothly on the processor, like a clock, sensor
reading, or LED blinking—all at the right time.
5. Interrupt Controllers
Devices like UART, timers, or sensors send interrupts (signals) to the processor when they
need attention.
The interrupt controller makes sure these signals are:
o Received correctly
✅ Result
With μHAL, interrupts work smoothly, and the processor knows what to respond to and
when 🧠.
o μHAL includes a CLI-based boot monitor, which provides a user interface to interact
with the board during boot.
o This allows developers to run commands, check system status, and control startup
behavior.
Angel is a debugging tool that allows communication between the host debugger and the target
ARM board.
Angel must be integrated with SWI, IRQ, or FIQ vectors, which are the special memory locations for
exceptions.
Reading and writing files on the host using SWI (Software Interrupts).
For communication, Angel may also use IRQ or FIQ interrupts, depending on configuration.
🔷 2️⃣ Firmware Execution Flow
The firmware execution flow describes the steps followed by the ARM processor from reset to
handing over control to the operating system.
1. Reset Occurs
o When power is applied, the processor enters the Reset state and starts executing the
firmware.
o It sets up memory, cache, and stack pointers for each processor mode (User,
Supervisor, IRQ, etc.).
o μHAL configures basic device drivers for components like timers, serial ports, LEDs,
and communication interfaces.
1. Communication Support
RedBoot can connect to a host system (like your PC) using two main methods:
✅ This protocol makes sure files (like firmware) are transferred reliably without errors.
🔸 B. Ethernet Communication
RedBoot can also talk to the host using Ethernet (network cable).
telnet – Lets you remotely connect and run commands on RedBoot from your PC.
tftp – Helps you download firmware/images from the host system to the target device.
2. Flash ROM Memory Management
RedBoot helps you manage the flash memory (the permanent storage area) on your development
board:
RedBoot can receive firmware or OS images (via serial or network) and store them in flash
memory.
You can use RedBoot to overwrite old images or completely erase flash before writing new
data.
RedBoot includes routines (functions) that help organize and manage the flash storage
efficiently, so you don’t overwrite or corrupt anything
Embedded Linux
o RedBoot can also define and pass parameters to the OS kernel when booting.
This is useful to configure the OS at startup based on hardware or user settings.
📌 IRQ and FIQ exceptions are only recognized when their respective interrupt mask bits in the
CPSR are cleared (i.e., not masked).
🟡 Standard Procedure Followed on IRQ or FIQ Exception
When either IRQ or FIQ is triggered, and the corresponding mask is cleared, ARM performs a
standard set of steps:
🔄 Steps:
o Changes the mode to IRQ mode or FIQ mode depending on the interrupt.
o The current status register (CPSR) of the previous mode is copied into SPSR_irq or
SPSR_fiq.
o The current program counter (PC) is stored in Link Register (r14_irq or r14_fiq) of
the new mode.
➡️The processor is now ready to execute the Interrupt Service Routine (ISR).
Let’s understand what happens during an IRQ exception using a simplified stepwise flow:
Mode: User
💥 IRQ Occurs:
1. The processor:
6. After the interrupt is serviced, the processor returns to User mode, restoring CPSR from
SPSR_irq.
🧪 3️⃣ Example of FIQ Exception Handling
Mode: User
1. The processor:
5. FIQ handler runs with banked registers (r8–r12) which need not be saved, improving speed.
The ARM core allows interrupts to be manually enabled or disabled by changing the CPSR bits when
in privileged mode (e.g., Supervisor mode).
asm
CopyEdit
asm
CopyEdit
asm
CopyEdit
MSR cpsr_c, r1
asm
CopyEdit
MSR cpsr_c, r1
The firmware is deeply embedded low-level software that provides an interface between the
hardware and the application or operating system-level software.
📌 It resides in ROM and starts executing when power is applied to the embedded system.
Firmware may remain active even after system initialization to support basic operations.
💡 Purpose:
The bootloader is a small application that installs the operating system or application onto a
hardware target. The bootloader only exists up to the point that the operating system or
application is executing, and it is commonly incorporated into the firmware.”
The OS expects certain system registers, memory layout, and peripherals to be in place.
Firmware initializes hardware like memory controllers, timers, or system control registers.
o The core: via coprocessor 15, register 0 (contains processor ID and manufacturer).
Diagnostics Software is used to check for hardware errors specific to the platform.
After platform setup, the firmware abstracts hardware using a software layer called HAL.
HAL hides hardware details and offers standard programming interfaces (APIs).
This allows the same higher-level code to run on different platforms with different hardware.
🔧 Device Drivers:
Part of HAL, they handle communication with specific hardware (like timers, serial ports).
From where?
How?
Binary (plain)
ELF format (Executable and Linking Format – includes headers, debug info)
o Updating the vector table (interrupts & exceptions now handled by OS handlers)
o Changing the Program Counter (PC) to point to the OS entry point
🧠 For more complex OS like Linux, firmware also passes a standard data structure to the kernel:
o Available RAM
o MMU type
o Hardware settings
📌 In some systems, firmware remains active as a background HAL layer (exposed via SWI interface),
but in others, it becomes inactive once the OS takes over.
Stage Description
Diagnostics & Debug Run diagnostic checks, provide debug access via CLI or host
Use HAL and device drivers to abstract hardware and create a standard
Hardware Abstraction
interface
Load Bootable Image Load OS/app image from ROM, storage, or network (supports binary or ELF)
What Happens:
The processor begins execution from the reset vector, which is the very first instruction at
address 0x00000000.
Only the reset vector has real functionality — others branch to dummy handlers (infinite
loops) to avoid unhandled exceptions.
Code Snippet:
ENTRY
ex_dabt B ex_dabt
ex_pabt B ex_pabt
int_irq B int_irq
int_fiq B int_fiq
Result:
✔ Dummy handlers setup
✔ Control moves to hardware initialization (sandstone_init1)
Goal:
Set system registers and prepare display for user feedback.
Code Snippet:
sandstone_init1
LDR r4, =0x03ffffa0 ; New settings: top 16 bits = address, bottom = attributes
What It Means:
r3 is used to point to the system config register. r4 has new configuration data.
This sets the system registers and enables the 7-segment display to show firmware status.
Result:
✔ System registers set
✔ Display initialized for visual feedback
Goal:
Move Flash ROM to a higher address and make SRAM available.
Code Snippet:
What It Does:
Result:
✔ Memory remapped
✔ pc updated to continue from new memory
Goal:
Setup serial communication (UART) and send a startup message.
Serial Settings:
9600 baud, No parity, 1 stop bit, No flow control
Output Message:
Goal:
Load payload (main program or OS) into SRAM and hand over control.
Code Snippet:
sandstone_load_and_boot
_copy
BLT _copy
How It Works:
Final Output:
initialized ...... ok
🔹⚙️Instructions Used:
assembly
CopyEdit
➡️Explanation:
assembly
CopyEdit
assembly
CopyEdit
assembly
CopyEdit
⚠️Note:
Both IRQ and FIQ can be disabled/enabled together by changing the bitmask to 0xC0 (0x80 |
0x40).
Changes take effect only after the final MSR instruction completes the execution stage of
the pipeline.
Provides a stable mechanism to load Loads the OS/application into memory and then
Purpose
and support OS hands over control
Shows status messages, diagnostics, Usually just displays boot progress or message
Output
CLI, hardware abstraction like “booting...”
📌 In summary:
✅ Purpose:
Type Description
SWI (Software Interrupt) Triggered by executing the SWI instruction—used for system calls
Type Description
Prefetch Abort Triggered on error in instruction fetch (e.g., from protected memory)
Occurs on system reset; resets the CPU and starts execution from
Reset
address 0x00
✅ Definition:
The Vector Table is a set of memory locations starting at address 0x00000000 (or 0xFFFF0000 in high
vectors) where the processor branches when an exception/interrupt occurs.
Reserved — 0x14 —
B <address>
Loads the interrupt service routine (ISR) address from memory location like 0xFFFFF030.
asm
CopyEdit
ARM does not allow any random number as #some_address. Instead, the number must
follow a special rule:
✅ It should be:
❗ So this means:
Only those addresses that can be created by rotating a small 8-bit value are allowed.
📌 Example:
asm
CopyEdit
⛔ This will NOT work because 0x12345678 can't be formed from an 8-bit number with right
rotation.
But this:
asm
CopyEdit
✅ This will work because 0x80 (8-bit) rotated right by 24 gives 0x80000000.
You can only use addresses that fit ARM's "8-bit rotate" rule. You can’t move just any
address into pc.
.
css
CopyEdit
---------------------------------------------------------------
✍️Summary
ARM uses a vector table starting from 0x00000000 to branch to appropriate handlers.
Multiple types of interrupts (IRQ, FIQ, SWI, etc.) each have dedicated vector entries.
Different branching techniques (B, LDR, MOV) are supported based on speed and address
range.
10) 📦 Interrupt Stack Design and Implementation in ARM-Based Systems
✅ Definition:
An interrupt stack is a portion of memory used to temporarily store register values and data when
an exception or interrupt occurs, allowing the processor to resume normal execution after handling
the event.
In ARM, each processor mode (like IRQ, FIQ, SVC, etc.) has its own dedicated stack pointer register
(SP). This helps in isolating stacks and prevents data corruption between different modes.
o Each OS (e.g., Embedded Linux, RTOS) defines how much stack is required and how
it should be managed.
o Hardware defines the available memory, which places limits on the stack size and
placement.
ARM stacks are usually descending, meaning they grow downward in memory.
Stack starts from a high memory address and expands towards lower addresses.
o Nested interrupt → needs more stack to store multiple return addresses and register
values.
Stack overflow leads to memory corruption and unpredictable behavior. To detect or prevent this:
Stack Check Functions: Call a function at the start of each routine to check available stack
space.
Implementation Steps
ARM has banked stack pointer (SP) for modes like IRQ, FIQ, SVC.
During system boot-up, set stack pointers for each mode.
Set using:
assembly
CopyEdit
less
CopyEdit
High Address
| Vector Table |
| IRQ Stack |
| Code |
| Data |
| Heap |
| User Stack |
Low Address
Disadvantage: If IRQ stack overflows, it may corrupt the code segment or vector table.
less
CopyEdit
High Address
| User Stack |
| Heap |
| Data |
| Code |
| Vector Table |
Low Address
Advantage: Safer as overflow is away from critical data/code, and system can still recover.