FreeNOS
Namespaces | Data Structures | Macros | Functions | Variables
ARM

ARM architecture specific code such as caching, virtual memory and exception/interrupt handling. More...

Namespaces

 Arch
 

Data Structures

class  ARMCacheV6
 ARMv6 cache management implementation. More...
 
class  ARMCacheV7
 ARMv7 cache management implementation. More...
 
class  ARMControl
 ARM System Control Coprocessor (CP15). More...
 
struct  CPUState
 Contains all the CPU registers. More...
 
class  ARMCore
 Class representing an ARM processor core. More...
 
class  ARMException
 ARM exception handling functionality. More...
 
class  ARMFirstTable
 ARM first level page table. More...
 
class  ARMGenericInterrupt
 ARM Generic Interrupt Controller (GIC) version 2. More...
 
class  ARMIO
 Input/Output operations specific to the ARM architecture. More...
 
class  ARMMap
 Memory mapping for the kernel and user processes on the ARM architecture. More...
 
class  ARMPaging
 ARM virtual memory implementation. More...
 
class  ARMSecondTable
 ARM second level page table implementation. More...
 
class  ARMTimer
 ARM Generic Timer. More...
 
class  SunxiClockControl
 Allwinner Clock Control Unit (CCU) More...
 
class  SunxiCpuConfig
 Allwinner sunxi CPU configuration module support. More...
 
class  SunxiPowerManagement
 Allwinner Power, Reset and Clock Management (PRCM) module. More...
 
class  SunxiSystemControl
 Allwinner System Control (SYSCON) module. More...
 

Macros

#define IRQ(vector)   (vector)
 Remap interrupt vector (unused for ARM) More...
 
#define mrc(coproc, opcode1, opcode2, reg, subReg)
 Move to ARM from CoProcessor (MRC). More...
 
#define mcr(coproc, opcode1, opcode2, reg, subReg, value)
 Move to CoProcessor from ARM (MCR). More...
 
#define mrrc(coproc, opcode1, CRm)
 64-bit move to ARM from CoProcessor (MRC). More...
 
#define mcrr(coproc, opcode1, CRm, value)
 64-bit move to CoProcessor from ARM (MCR). More...
 
#define timestamp()   0
 Reads the CPU's timestamp counter. More...
 
#define cpu_reboot()
 Reboot the system. More...
 
#define cpu_shutdown()
 Shutdown the machine via ACPI. More...
 
#define idle()   asm volatile ("wfi")
 Puts the CPU in a lower power consuming state. More...
 
#define vbar_set(addr)   mcr(p15, 0, 0, c12, c0, (addr))
 Change Vector Base Address (VBAR) More...
 
#define sysctrl_read()   (mrc(p15, 0, 0, c1, c0))
 Read System Control register. More...
 
#define sysctrl_write(val)   mcr(p15, 0, 0, c1, c0, (val))
 Write System Control register. More...
 
#define read_core_id()   (mrc(p15, 0, 5, c0, c0) & 0xff)
 Read unique core identifier. More...
 
#define tlb_invalidate(page)
 
#define ARM_EX_VECTAB_SIZE   (64)
 Size of the ARM exception vector table in bytes. More...
 

Functions

void tlb_flush_all ()
 Flush the entire Translation Lookaside Buffer. More...
 
void dmb ()
 Data Memory Barrier. More...
 
void dsb ()
 Data Synchronisation Barrier. More...
 
void flushBranchPrediction ()
 Flush branch prediction. More...
 
void isb ()
 Instruction Synchronisation Barrier (ARMv7 and above) More...
 
void flushPrefetchBuffer ()
 Flush Prefetch Buffer. More...
 
struct CPUState ALIGN (4) CPUState
 Contains all the CPU registers. More...
 

Variables

class ARMCore ALIGN
 
#define USR_MODE   16
 ARM Program Status Register (CPSR) More...
 
#define IRQ_MODE   18
 
#define FIQ_MODE   17
 
#define SVC_MODE   19
 
#define ABT_MODE   23
 
#define UND_MODE   27
 
#define SYS_MODE   31
 
#define HYP_MODE   0x1a
 
#define MODE_MASK   0x1f
 
#define IRQ_BIT   (1 << 7)
 
#define FIQ_BIT   (1 << 6)
 
#define ASYNC_ABORT_BIT   (1 << 8)
 
#define ELR   .long 0xe12ef30e
 ARM Model-Specific Instructions. More...
 
#define ERET   .long 0xe160006e
 eret More...
 
#define PAGESHIFT   12
 ARM Memory Constants. More...
 
#define DIRSHIFT   20
 Page table bit shift. More...
 
#define PAGESIZE   4096
 ARM uses 4K pages. More...
 
#define PAGEDIR_MAX   4096
 Number of entries in the first-level page table. More...
 
#define PAGEDIR_SIZE   (PAGEDIR_MAX * sizeof(u32))
 
#define PAGETAB_MAX   256
 Number of entries in a second-level page table. More...
 
#define PAGETAB_SIZE   (PAGETAB_MAX * sizeof(u32))
 
#define PAGETAB_SPAN   (PAGETAB_MAX*PAGESIZE)
 
#define PAGEMASK   0xfffff000
 Mask to find the page. More...
 
#define SECTIONMASK   0xfff00000
 Mask for large 1MiB section mappings. More...
 
#define MEMALIGN   4
 Memory address alignment. More...
 

ARM Kernel Traps

ARM specific software interrupts.

These functions are called by the user program to invoke the kernel APIs, also known as system calls.

On ARM, there are no machine-specific input operand constraints to specify registers for inline assembly. Therefore, we need to use Local Register Variables syntax to guarantee that specific registers are used.

See also
https://gcc.gnu.org/onlinedocs/gcc/Local-Register-Variables.html#Local-Register-Variables
ulong trapKernel1 (ulong api, ulong arg1)
 Perform a kernel trap with 1 argument. More...
 
ulong trapKernel2 (ulong api, ulong arg1, ulong arg2)
 Perform a kernel trap with 2 arguments. More...
 
ulong trapKernel3 (ulong api, ulong arg1, ulong arg2, ulong arg3)
 Perform a kernel trap with 3 arguments. More...
 
ulong trapKernel4 (ulong api, ulong arg1, ulong arg2, ulong arg3, ulong arg4)
 Perform a kernel trap with 4 arguments. More...
 
ulong trapKernel5 (ulong api, ulong arg1, ulong arg2, ulong arg3, ulong arg4, ulong arg5)
 Perform a kernel trap with 5 arguments. More...
 

Detailed Description

ARM architecture specific code such as caching, virtual memory and exception/interrupt handling.

Macro Definition Documentation

◆ ABT_MODE

#define ABT_MODE   23

Definition at line 50 of file ARMConstant.h.

◆ ARM_EX_VECTAB_SIZE

#define ARM_EX_VECTAB_SIZE   (64)

Size of the ARM exception vector table in bytes.

Definition at line 39 of file ARMException.h.

◆ ASYNC_ABORT_BIT

#define ASYNC_ABORT_BIT   (1 << 8)

Definition at line 57 of file ARMConstant.h.

◆ cpu_reboot

#define cpu_reboot ( )

Reboot the system.

Definition at line 102 of file ARMCore.h.

◆ cpu_shutdown

#define cpu_shutdown ( )

Shutdown the machine via ACPI.

Note
We do not have ACPI yet. Shutdown now has a bit naive implementation.
See also
http://forum.osdev.org/viewtopic.php?t=16990

Definition at line 110 of file ARMCore.h.

◆ DIRSHIFT

#define DIRSHIFT   20

Page table bit shift.

In ARM, the first-level page directory entry is selected by bits [31:20] from the virtual address, plus two 0 bytes.

See also
ARM Architecture Reference Manual, page 724.

Definition at line 94 of file ARMConstant.h.

◆ ELR

#define ELR   .long 0xe12ef30e

ARM Model-Specific Instructions.

msr ELR_hyp, lr

Definition at line 69 of file ARMConstant.h.

◆ ERET

#define ERET   .long 0xe160006e

eret

Definition at line 72 of file ARMConstant.h.

◆ FIQ_BIT

#define FIQ_BIT   (1 << 6)

Definition at line 56 of file ARMConstant.h.

◆ FIQ_MODE

#define FIQ_MODE   17

Definition at line 48 of file ARMConstant.h.

◆ HYP_MODE

#define HYP_MODE   0x1a

Definition at line 53 of file ARMConstant.h.

◆ idle

#define idle ( )    asm volatile ("wfi")

Puts the CPU in a lower power consuming state.

Definition at line 115 of file ARMCore.h.

◆ IRQ

#define IRQ (   vector)    (vector)

Remap interrupt vector (unused for ARM)

Parameters
vectorInterrupt vector number
Returns
Same interrupt vector

Definition at line 44 of file ARMCore.h.

◆ IRQ_BIT

#define IRQ_BIT   (1 << 7)

Definition at line 55 of file ARMConstant.h.

◆ IRQ_MODE

#define IRQ_MODE   18

Definition at line 47 of file ARMConstant.h.

◆ mcr

#define mcr (   coproc,
  opcode1,
  opcode2,
  reg,
  subReg,
  value 
)
Value:
({ \
u32 val = (value); \
asm volatile("mcr " QUOTE(coproc) ", " QUOTE(opcode1) ", %0, " QUOTE(reg) ", " QUOTE(subReg) ", " QUOTE(opcode2) "\n" : : "r"(val) : "memory"); \
})

Move to CoProcessor from ARM (MCR).

Write data to CoProcessor connected to the ARM.

Definition at line 63 of file ARMCore.h.

◆ mcrr

#define mcrr (   coproc,
  opcode1,
  CRm,
  value 
)
Value:
({ \
u64 val = (value); \
asm volatile("mcrr " QUOTE(coproc) ", " QUOTE(opcode1) ", %Q0, %R0, " QUOTE(CRm) "\n" : : "r"(val) : "memory"); \
})

64-bit move to CoProcessor from ARM (MCR).

Write 64-bit data to CoProcessor connected to the ARM.

Definition at line 86 of file ARMCore.h.

◆ MEMALIGN

#define MEMALIGN   4

Memory address alignment.

Definition at line 127 of file ARMConstant.h.

◆ MODE_MASK

#define MODE_MASK   0x1f

Definition at line 54 of file ARMConstant.h.

◆ mrc

#define mrc (   coproc,
  opcode1,
  opcode2,
  reg,
  subReg 
)
Value:
({ \
ulong r; \
asm volatile("mrc " QUOTE(coproc) ", " QUOTE(opcode1) ", %0, " QUOTE(reg) ", " QUOTE(subReg) ", " QUOTE(opcode2) "\n" : "=r"(r) :: "memory"); \
r; \
})

Move to ARM from CoProcessor (MRC).

Read data from a CoProcessor connected to the ARM.

Definition at line 51 of file ARMCore.h.

◆ mrrc

#define mrrc (   coproc,
  opcode1,
  CRm 
)
Value:
({ \
u64 r; \
asm volatile("mrrc " QUOTE(coproc) ", " QUOTE(opcode1) ", %Q0, %R0, " QUOTE(CRm) "\n" : "=r"(r) :: "memory"); \
r; \
})

64-bit move to ARM from CoProcessor (MRC).

Read 64-bit data from a CoProcessor connected to the ARM.

Definition at line 74 of file ARMCore.h.

◆ PAGEDIR_MAX

#define PAGEDIR_MAX   4096

Number of entries in the first-level page table.

TTBR0 is the first-level page table for the application. TTBR1 is always 16KB, the first-level page table of the kernel/OS.

Definition at line 105 of file ARMConstant.h.

◆ PAGEDIR_SIZE

#define PAGEDIR_SIZE   (PAGEDIR_MAX * sizeof(u32))

Definition at line 106 of file ARMConstant.h.

◆ PAGEMASK

#define PAGEMASK   0xfffff000

Mask to find the page.

Definition at line 121 of file ARMConstant.h.

◆ PAGESHIFT

#define PAGESHIFT   12

ARM Memory Constants.

Page entry bit shift.

Definition at line 84 of file ARMConstant.h.

◆ PAGESIZE

#define PAGESIZE   4096

ARM uses 4K pages.

Definition at line 97 of file ARMConstant.h.

◆ PAGETAB_MAX

#define PAGETAB_MAX   256

Number of entries in a second-level page table.

Second-level page tables are 1KB in size and map 1MB of virtual memory. Second-level page tables must be aligned on 1KB boundaries.

See also
ARM Architecture Reference Manual, page 734.

Definition at line 116 of file ARMConstant.h.

◆ PAGETAB_SIZE

#define PAGETAB_SIZE   (PAGETAB_MAX * sizeof(u32))

Definition at line 117 of file ARMConstant.h.

◆ PAGETAB_SPAN

#define PAGETAB_SPAN   (PAGETAB_MAX*PAGESIZE)

Definition at line 118 of file ARMConstant.h.

◆ read_core_id

#define read_core_id ( )    (mrc(p15, 0, 5, c0, c0) & 0xff)

Read unique core identifier.

This function reads the Multi-Processor Affinity Register (MPIDR) to determine the unique identifier of the processor. Note that only the most significant affinity level 0 is used and others are ignored.

Returns
Value of affinity level 0

Definition at line 145 of file ARMCore.h.

◆ SECTIONMASK

#define SECTIONMASK   0xfff00000

Mask for large 1MiB section mappings.

Definition at line 124 of file ARMConstant.h.

◆ SVC_MODE

#define SVC_MODE   19

Definition at line 49 of file ARMConstant.h.

◆ SYS_MODE

#define SYS_MODE   31

Definition at line 52 of file ARMConstant.h.

◆ sysctrl_read

#define sysctrl_read ( )    (mrc(p15, 0, 0, c1, c0))

Read System Control register.

Definition at line 127 of file ARMCore.h.

◆ sysctrl_write

#define sysctrl_write (   val)    mcr(p15, 0, 0, c1, c0, (val))

Write System Control register.

Definition at line 133 of file ARMCore.h.

◆ timestamp

#define timestamp ( )    0

Reads the CPU's timestamp counter.

Returns
64-bit integer.

Definition at line 97 of file ARMCore.h.

◆ tlb_invalidate

#define tlb_invalidate (   page)
Value:
({ \
mcr(p15, 0, 1, c8, c7, (page)); \
})

Definition at line 167 of file ARMCore.h.

◆ UND_MODE

#define UND_MODE   27

Definition at line 51 of file ARMConstant.h.

◆ USR_MODE

#define USR_MODE   16

ARM Program Status Register (CPSR)

Definition at line 46 of file ARMConstant.h.

◆ vbar_set

#define vbar_set (   addr)    mcr(p15, 0, 0, c12, c0, (addr))

Change Vector Base Address (VBAR)

Definition at line 121 of file ARMCore.h.

Function Documentation

◆ ALIGN()

struct CPUState ALIGN ( )

Contains all the CPU registers.

◆ dmb()

void dmb ( )
inline

Data Memory Barrier.

Ensures that all memory transactions are complete when the next instruction runs. If the next instruction is not a memory instruction, it is allowed to run out of order. The DMB provides slightly looser memory barrier than DSB on ARM.

Definition at line 180 of file ARMCore.h.

Referenced by ARMIO::read(), and ARMIO::write().

◆ dsb()

void dsb ( )
inline

Data Synchronisation Barrier.

Enforces a strict memory barrier which ensures all memory transactions are completed when the next instruction begins. The DSB is the most strict memory barrier available on ARM.

See also
ARM1176JZF-S Technical Reference Manual, page 342, Data Synchronization Barrier

Definition at line 198 of file ARMCore.h.

Referenced by ARMCacheV7::cleanAddress(), ARMCacheV6::cleanInvalidate(), ARMCacheV7::cleanInvalidate(), ARMCacheV7::cleanInvalidateAddress(), ARMCacheV7::flushLevel(), ARMCacheV6::invalidate(), ARMCacheV7::invalidateAddress(), Sun8iEmac::receive(), Sun8iEmac::resetReceive(), and Sun8iEmac::startDMA().

◆ flushBranchPrediction()

void flushBranchPrediction ( )
inline

Flush branch prediction.

Definition at line 210 of file ARMCore.h.

Referenced by ARMCacheV6::cleanInvalidate(), and ARMCacheV7::cleanInvalidate().

◆ flushPrefetchBuffer()

void flushPrefetchBuffer ( )
inline

Flush Prefetch Buffer.

Definition at line 230 of file ARMCore.h.

Referenced by ARMCacheV6::cleanInvalidate(), and ARMControl::write().

◆ isb()

void isb ( )
inline

Instruction Synchronisation Barrier (ARMv7 and above)

Definition at line 218 of file ARMCore.h.

Referenced by ARMPaging::activate(), ARMCacheV7::cleanAddress(), ARMCacheV7::cleanInvalidate(), ARMCacheV7::cleanInvalidateAddress(), ARMPaging::map(), and ARMPaging::unmap().

◆ tlb_flush_all()

void tlb_flush_all ( )
inline

Flush the entire Translation Lookaside Buffer.

Definition at line 161 of file ARMCore.h.

Referenced by ARMPaging::activate().

◆ trapKernel1()

ulong trapKernel1 ( ulong  api,
ulong  arg1 
)
inline

Perform a kernel trap with 1 argument.

Parameters
apiUnique number of the handler to execute.
arg1First argument
Returns
An integer.

Definition at line 59 of file ARMTraps.h.

Referenced by SystemInfo().

◆ trapKernel2()

ulong trapKernel2 ( ulong  api,
ulong  arg1,
ulong  arg2 
)
inline

Perform a kernel trap with 2 arguments.

Parameters
apiUnique number of the handler to execute.
arg1First argument
arg2Second argument
Returns
An integer

Definition at line 80 of file ARMTraps.h.

Referenced by PrivExec().

◆ trapKernel3()

ulong trapKernel3 ( ulong  api,
ulong  arg1,
ulong  arg2,
ulong  arg3 
)
inline

Perform a kernel trap with 3 arguments.

Parameters
apiUnique number of the handler to execute.
arg1First argument
arg2Second argument
arg3Third argument
Returns
An integer.

Definition at line 103 of file ARMTraps.h.

Referenced by VMCtl(), and VMShare().

◆ trapKernel4()

ulong trapKernel4 ( ulong  api,
ulong  arg1,
ulong  arg2,
ulong  arg3,
ulong  arg4 
)
inline

Perform a kernel trap with 4 arguments.

Parameters
apiUnique number of the handler to execute.
arg1First argument
arg2Second argument
arg3Third argument
arg4Fourth argument
Returns
An integer.

Definition at line 128 of file ARMTraps.h.

Referenced by ProcessCtl().

◆ trapKernel5()

ulong trapKernel5 ( ulong  api,
ulong  arg1,
ulong  arg2,
ulong  arg3,
ulong  arg4,
ulong  arg5 
)
inline

Perform a kernel trap with 5 arguments.

Parameters
apiUnique number of the handler to execute.
arg1First argument
arg2Second argument
arg3Third argument
arg4Fourth argument
arg5Fifth argument
Returns
An integer.

Definition at line 156 of file ARMTraps.h.

Referenced by VMCopy().

Variable Documentation

◆ ALIGN

class ARMCore ALIGN
QUOTE
#define QUOTE(x)
Stringfies the given input.
Definition: Macros.h:46