2
0

A2onArm.tex 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. \documentclass[a4paper]{article}
  2. \usepackage[T1]{fontenc}
  3. \usepackage[utf8]{inputenc}
  4. % Uncomment/Add packages as needed. Try to keep it minimal.
  5. %\usepackage[bookmarks,bookmarksopen,bookmarksdepth=3]{hyperref}
  6. %\usepackage{color}
  7. %\usepackage{calc}
  8. %\usepackage{amsfonts}
  9. %\usepackage{float}
  10. \usepackage{graphicx,epstopdf}
  11. %\usepackage{amsmath}
  12. %\usepackage[percent]{overpic}
  13. %\usepackage{multicol}
  14. %\usepackage{multirow}
  15. %\usepackage{algorithm}
  16. \newcommand{\file}[1]{\texttt{#1}}
  17. \newcommand{\module}[1]{\texttt{#1}}
  18. \title{\texttt{A2} on ARM}
  19. \author{Dmytro Shulga \and Timothée Martiel}
  20. \begin{document}
  21. \maketitle
  22. \tableofcontents
  23. \section*{Introduction}
  24. This paper provides the description of A2 for ARM. This port of A2 operating
  25. system to the ARM is currently maintained by Timothée Martiel.
  26. This document is organized as follows: section~\ref{sec:core} describes the
  27. minimal set of modules needed to run A2 on ARM, section~\ref{sec:port} explains
  28. how to adapt A2 to a new ARM CPU or board. Section~\ref{sec:drivers} describes
  29. the specificities of common ARM device drivers available on A2, and how to adapt
  30. them to your new hardware. At last, section~\ref{sec:design} details design and
  31. implementation choices of A2 on ARM for the interested reader.
  32. \section{Core Kernel Modules}
  33. \label{sec:core}
  34. The core kernel modules are the minimum set of modules needed to run A2 on ARM.
  35. These modules are usually linked together (and with other modules needed to
  36. provide dynamic module loading) into an executable file: the A2 static image.
  37. The core modules can be divided into 2 categories:
  38. \begin{enumerate}
  39. \item low-level runtime modules, that provide runtime services for the lower
  40. layers of the operating system and
  41. \item the A2 core, which implements Active Oberon runtime services and is
  42. the core of the A2 operating system.
  43. \end{enumerate}
  44. We will go through all modules in these categories and detail their purposes.
  45. \subsection{Low-Level Runtime}
  46. Modules in the low-level runtime provide basic support that is not directly
  47. related to the A2 core services (heaps, scheduling, synchronization, module
  48. loading).
  49. The modules present in the low-level runtime are:
  50. \begin{enumerate}
  51. \item \module{Initializer},
  52. \item \module{Runtime},
  53. \item \module{Platform},
  54. \item \module{FPE64},
  55. \item \module{ARMRuntime},
  56. \item \module{Trace},
  57. \item \module{Uart}.
  58. \end{enumerate}
  59. \module{Initializer} provides the interrupt vector, placed at memory address
  60. $0$. It also provides basic processor initialization: default stack, disabling
  61. caches and MMU.
  62. The module \module{Runtime} is needed for dynamic module loading. It records
  63. every module loaded (from the kernel image) before \module{Modules}. When
  64. \module{Modules} is loaded, it will retrieve that information and use it to make
  65. these early modules available to the linker.
  66. \module{Platform} defines platform-specific constants. These constants are
  67. mostly memory-mapped register addresses.
  68. Modules \module{FPE64} and \module{ARMRuntime} provide a small computation
  69. library. \module{FPE64} implements 64 bits floating-point emulation.
  70. \module{ARMRuntime} provides integer division and modulo and a wrapper for
  71. floating-point emulation. Procedures exported in \module{ARMRuntime} are used
  72. automatically in compiler-generated code.
  73. \module{Trace} provides an output mechanism for the core A2 modules. On ARM it
  74. uses UART. So naturally, \module{Uart} is the UART driver.
  75. Note that, since the A2 services are not yet available when these modules are
  76. loaded and used, they must not rely on these services. That is, they are
  77. forbidden to use:
  78. \begin{enumerate}
  79. \item \texttt{NEW}
  80. \item \texttt{ACTIVE} objects
  81. \item \texttt{EXCLUSIVE} blocks and procedures
  82. \item dynamic module loading
  83. \item scheduling
  84. \end{enumerate}
  85. To develop and maintain these modules, stick to a procedural style, using only
  86. static variables and no parallelism.
  87. \subsection{A2 Core}
  88. The A2 core modules implement Active Oberon language features that require
  89. runtime components. This makes the core of the operating system. The modules
  90. composing the A2 core are:
  91. \begin{enumerate}
  92. \item \module{Machine},
  93. \item \module{Heaps},
  94. \item \module{Modules},
  95. \item \module{Objects},
  96. \item \module{Kernel}.
  97. \end{enumerate}
  98. \module{Machine} provides an abstraction of the processor and memory. It is
  99. responsible for providing various machine-dependent services, such as interrupt
  100. handling, cache maintenance, virtual memory management, spinlocks, etc. It also
  101. does the basic initialization of the booting processor.
  102. \module{Heaps} implements the heap and garbage collector.
  103. \module{Modules} maintains the list of available modules and provides module
  104. management services (loading, unloading, linking information, etc).
  105. \module{Objects} implements language features related to objects. It implements
  106. the scheduler(for \texttt{ACTIVE} objects) and object monitors (for
  107. \texttt{EXCLUSIVE} blocks and procedures). After initialization of this module,
  108. the scheduler is working: processes can be used.
  109. \module{Kernel} provides an abstraction layer of the kernel, finalizes the boot
  110. process (starting non-booting processors) and provides timer services.
  111. \section{Adapting A2 to new Hardware}
  112. \label{sec:port}
  113. % This section describes where platform and proc-specific code is and what might
  114. % require changes for a new board and proc
  115. % Organized by modules
  116. \section{Drivers and Services}
  117. \label{sec:drivers}
  118. % Organization and portability and specificities of drivers.
  119. \subsection{UART}
  120. \subsection{Ethernet}
  121. \subsection{USB}
  122. \subsection{DMA}
  123. \section{Design of A2 on ARM}
  124. % ARM-specific design and implementation, by topics
  125. \subsection{Memory}
  126. \subsection{Cache Management}
  127. \subsection{Locks}
  128. \subsection{Scheduling}
  129. \subsection{FPU}
  130. \subsection{Compiler}
  131. \end{document}
  132. %\section{A2 for ARM Description}
  133. \subsection{Kernel support modules}
  134. Following files are providing basic support for ARM platforms:
  135. \begin{enumerate}
  136. \item Initializer.Zynq.Mod
  137. \item Runtime.Mod
  138. \item Platform.Mod
  139. \item FPE64.Mod
  140. \item ARMRuntime.Mod
  141. \item Trace.Mod
  142. \item Zynq.Uart.Mod
  143. \end{enumerate}
  144. Now we go through the purposes of these modules with a little description.
  145. \subsubsection{Initializer.Zynq.Mod}
  146. This module provides \textbf{Init} procedure. This procedure is placed first in the image file (because of \{INITIAL\} modifier). It provides basic CPU initialization: disables MMU and sets the stack pointer. We disable MMU it make sure that we are working with physical addresses. And we set up the stack to be able to call procedures. We set stack address as $0x00030000$: this is the top of the stack. The stack grows downwards, so the new data will be written into the smallest stack address. See Fig.\ref{figStack}.
  147. \begin{figure}[H]
  148. \center
  149. \includegraphics[scale=0.5]{stack.png}
  150. \caption{Stack} \label{figStack}
  151. \end{figure}
  152. It also calls procedure \textbf{InvalidateDCache}.
  153. Module also has \textbf{Finalize} procedure that is written at the end of the image file because of \{FINAL\} modifier. This procedure is necessary to terminate the initial process. We will explain later what the initial process does.
  154. \subsubsection{Runtime.Mod}
  155. This module is used for dynamic module loading and it gives to the module \textbf{Modules.Mod} information on the statically linked modules that are linked in the image before \textbf{Modules.Mod}.
  156. \textbf{Modules.Mod} needs to know about every module loaded in the system including those that are in the static image. In order to make those modules that are linked before \textbf{Modules.Mod} available to \textbf{Modules.Mod} the module \textbf{Runtime.Mod} provides the procedure \textbf{InsertModule}.
  157. \subsubsection{Platform.Mod}
  158. This module contains constants that are used by \textbf{Machine.Mod}. Most constants are essential I/O register addresses.
  159. \subsubsection{FPE64.Mod}
  160. It is a 64-bits floating point emulation runtime.
  161. \subsubsection{ARMRuntime.Mod}
  162. This module provides runtime support for integer and floating point computations.
  163. \subsubsection{Trace.Mod}
  164. This is kernel output procedures. It is wired to the UART.
  165. \subsubsection{Zynq.Uart.Mod}
  166. This is the UART driver. It is loaded before the system kernel. It makes it available to all the loaded code. It supports several UARTs. The UART that is used by \textbf{Trace.Mod} is determined by constant \textit{Platform.KernelOutputUart}, that represents an index in the \textit{uarts} array.
  167. \subsection{A2 Kernel}
  168. Here we describe the kernel itself that does everything. It is composed of the following modules:
  169. \begin{enumerate}
  170. \item ARM.Machine.Mod
  171. \item Heaps.Mod
  172. \item oc/Generic.Modules.Mod
  173. \item Objects.Mod
  174. \item Kernel.Mod
  175. \end{enumerate}
  176. \subsubsection{ARM.Machine.Mod}
  177. This module provides an abstraction of the platform (CPU, memory, etc.). It provides abstract processor manipulations, for example cache maintenance operations, interrupt handling, low-level locks, virtual memory management, stack management, default trap handling and multiprocessor booting.
  178. The steps of the initialization sequence within \textbf{ARM.Machine.Mod}:
  179. \begin{enumerate}
  180. \item setup interrupt stacks;
  181. \item install UART drivers and setup tracing;
  182. \item initialize the boot processor: enabling caches, FPU, memory sharing;
  183. \item install default interrupt handlers;
  184. \item initialize virtual memory: setup page tables, enable MMU;
  185. \item initialize low-level locks.
  186. \end{enumerate}
  187. \subsubsection{Heaps.Mod}
  188. It implements the heap. That is to say it provides:
  189. \begin{enumerate}
  190. \item the \textit{new} procedure;
  191. \item garbage collection.
  192. \end{enumerate}
  193. \subsubsection{oc/Generic.Modules.Mod}
  194. It maintains the list of loaded modules (\textit{root} variable) and it provides a generic interface for module management.
  195. \subsubsection{Objects.Mod}
  196. This module provides scheduling and object synchronization. Synchronization is provided by \{EXCLUSIVE\} modifier in the ActiveOberon language.
  197. \subsubsection{Kernel.Mod}
  198. It provides mainly timers for applications. It starts the non-booting processors. It also enables interrupts.
  199. \end{document}