Core Concepts
This paper details the implementation of the C programming language for resource-constrained Padauk microcontrollers and proposes architectural improvements to enhance their suitability for C programming, particularly in multicore settings.
Abstract
This research paper details the implementation of the C programming language for Padauk microcontrollers, tiny 8-bit devices with limited RAM. The authors successfully implemented C support for single-core Padauk architectures (pdk13, pdk14, pdk15) using the Small Device C Compiler (SDCC).
Key challenges and solutions:
- Limited Resources: The absence of general-purpose registers led to the use of a pseudo-register at a fixed memory address. To handle multiple address spaces, 16-bit pointers were used, with the top bit indicating code or data memory.
- Inefficient Stack Handling: The lack of stack-pointer-relative addressing made stack access inefficient. The authors addressed this by placing local variables at fixed memory locations, sacrificing reentrancy. The
__reentrant
keyword and –stack-auto
compiler option were introduced to enable reentrant functions when needed.
- Multicore Challenges: Multicore devices demanded reentrant functions, necessitating locks to protect the pseudo-register. Implementing atomics, especially
atomic_flag
, proved complex due to the lack of lock-free primitives. The authors devised a workaround using two locks to emulate lock-free behavior.
Proposed Architectural Improvements:
To enhance the Padauk architecture for C programming, the authors propose:
- Stack Handling Instructions: Adding an
spadd #k
instruction to adjust the stack pointer efficiently.
- Stack-Pointer-Relative Addressing: Introducing a dedicated addressing mode or extending existing instructions (e.g.,
mov
) to support stack-relative addressing.
- Exposing Interrupt Enable Bit: Allowing access to the global interrupt enable bit via an I/O register for efficient critical section implementation.
- Enhanced Atomic Operations: Implementing a
swap
instruction with indirect addressing for efficient atomic_flag
and adding atomic compare-and-exchange instructions for other atomic types.
- Core Identification: Introducing an instruction to determine the currently executing core.
- Binary Coded Decimal (BCD) Support: Adding support for BCD arithmetic to optimize decimal string conversions.
Evaluation:
The authors evaluated the impact of the proposed changes on code size using benchmarks like Dhrystone, Coremark, and stdcbench. Results showed significant code size reductions, especially when compiling all functions as reentrant.
Conclusion:
The paper demonstrates the feasibility of using C for programming Padauk microcontrollers and highlights the architectural limitations hindering its efficiency. The proposed improvements offer valuable insights for future Padauk microcontroller designs, aiming to make them more suitable for C programming, particularly in multicore environments.
Stats
Padauk microcontrollers have 60 B to 256 B of RAM.
The smallest established integer benchmarks (Dhrystone 2.1, Coremark 1.0, stdcbench 0.6) require more data memory than available on Padauk microcontrollers.
Code size reductions of up to 60% were observed when compiling all functions as reentrant with the proposed architectural changes.
The program memory on a Padauk microcontroller occupies roughly the same die space as all other digital logic combined.
Quotes
"The architecture was clearly not designed to be programmed in a high-level language."
"C standards are supported to the full extent that they are supported by SDCC."
"Since nearly all instructions are single-cycle, we expect runtime and energy use to closely follow code size."