ARM64 Bare Metal Memory Allocator
A custom memory allocator implementation for ARM64 bare-metal systems, featuring a minimal operating system kernel with UART communication and interactive shell.
Overview
This project implements a complete bare-metal system that includes:
Custom Memory Allocator: A heap-based memory management system with block splitting and coalescing
ARM64 Kernel: Minimal kernel that boots on ARM64 hardware/emulation
UART Communication: Serial communication for input/output
Interactive Shell: Command-line interface for testing the allocator
Linker Script: Custom memory layout for bare-metal execution
Features
Memory Allocator
Dynamic allocation:
malloc-like functionality with my_malloc()Memory deallocation:
free-like functionality with my_free()Block splitting: Efficiently splits large blocks when allocating smaller sizes
Block coalescing: Merges adjacent free blocks to prevent fragmentation
Alignment: All allocations are aligned to 8-byte boundaries
Debug information: Real-time memory statistics and block visualization
System Features
Bare-metal kernel: No operating system dependencies
UART I/O: Full serial communication stack
Interactive shell: Real-time testing environment
Memory safety: Double-free detection and error handling
Project Structure
Prerequisites
macOS
Linux (Ubuntu/Debian)
Building and Running
Build the Kernel
Run in QEMU
Exit QEMU
To exit the emulator, press:
Ctrl+A then XUsage
Once the kernel boots, you'll see:
Available Commands
alloc <size>Allocates memory of the specified size in bytes.
free <address>Frees memory at the specified hexadecimal address.
infoDisplays detailed memory allocator statistics and block information.
helpShows all available commands and their usage.
Memory Management Details
Allocation Algorithm
Size Alignment: All allocations are aligned to 8-byte boundaries
First Fit: Searches for the first free block large enough
Block Splitting: Splits blocks when they're significantly larger than needed
Metadata: Each allocated block has a header containing size and status information
Deallocation Algorithm
Validation: Checks for double-free attempts
Status Update: Marks block as free and updates statistics
Coalescing: Merges with adjacent free blocks to reduce fragmentation
Memory Layout
Technical Details
Architecture
Target: ARM64 (AArch64) Cortex-A53
Memory Model: 1MB heap starting at
0x40081000Alignment: 8-byte alignment for all allocations
Endianness: Little-endian
Compilation Flags
-ffreestanding: Bare-metal compilation-nostdinc -nostdlib -nostartfiles: No standard library dependencies-mcpu=cortex-a53: Target ARM Cortex-A53 processor-Wall -O2: Warnings enabled, optimization level 2Linker Configuration
The
linker.ld script defines:Code placement in memory
Stack location
Heap boundaries (
heap_start and heap_end symbols)Testing Examples
Basic Allocation Test
Fragmentation Test
Error Handling Test
Development
Adding New Features
New Commands: Add cases to the command parser in
kernel.cAllocator Features: Extend functions in
allocator.cI/O Functions: Add UART utilities in
uart.cDebugging
Use
info command to inspect memory stateUART output provides real-time feedback
QEMU monitor commands available with
Ctrl+A, CPerformance Characteristics
Time Complexity
Allocation: O(n) where n is the number of blocks
Deallocation: O(1) for marking free, O(1) for simple coalescing
Memory info: O(n) for traversing all blocks
Space Complexity
Overhead:
sizeof(block_header_t) bytes per allocated blockAlignment: Up to 7 bytes padding per allocation
Fragmentation: Minimal due to coalescing strategy
Limitations
Single-threaded: No concurrency support
No advanced coalescing: Only merges with next block
Fixed heap size: 1MB heap defined at compile time
No garbage collection: Manual memory management only
Contributing
Fork the repository
Create a feature branch
Test changes in QEMU
Submit a pull request
License
This project is provided as educational material for understanding bare-metal systems programming and memory management.
Built for ARM64 bare-metal systems • Tested on QEMU ARM64 emulation
0 likes · 7 views · Oct 24, 2025
Developed a custom memory allocator for ARM64 bare-metal systems with UART and shell.