summaryrefslogtreecommitdiff
path: root/libcpu
diff options
context:
space:
mode:
authorBernard Xiong <[email protected]>2020-04-17 13:30:22 +0800
committerGitHub <[email protected]>2020-04-17 13:30:22 +0800
commit33f7124b3644314ca4ce96d9352b4ac973664a29 (patch)
treed518f581f34313ea8786fd4d2a0ccf4f8af0b54c /libcpu
parent198c0d914cc62e95f97ed2782fb8c37474061bc2 (diff)
parent709e0d5799a57e9904d856fd94a935bd1deb153d (diff)
Merge pull request #3541 from bigmagic123/add_raspi4
Add raspi4 bsp
Diffstat (limited to 'libcpu')
-rw-r--r--libcpu/aarch64/SConscript3
-rw-r--r--libcpu/aarch64/common/SConscript24
-rw-r--r--libcpu/aarch64/common/armv8.h (renamed from libcpu/aarch64/cortex-a53/armv8.h)0
-rw-r--r--libcpu/aarch64/common/cache.S (renamed from libcpu/aarch64/cortex-a53/cache.S)0
-rw-r--r--libcpu/aarch64/common/context_gcc.S (renamed from libcpu/aarch64/cortex-a53/context_gcc.S)0
-rw-r--r--libcpu/aarch64/common/cp15.h (renamed from libcpu/aarch64/cortex-a53/cp15.h)0
-rw-r--r--libcpu/aarch64/common/cpu.c (renamed from libcpu/aarch64/cortex-a53/cpu.c)0
-rw-r--r--libcpu/aarch64/common/cpu_gcc.S (renamed from libcpu/aarch64/cortex-a53/cpu_gcc.S)0
-rw-r--r--libcpu/aarch64/common/gic/SConscript24
-rw-r--r--libcpu/aarch64/common/gic/gic_pl400.c262
-rw-r--r--libcpu/aarch64/common/gic/gic_pl400.h61
-rw-r--r--libcpu/aarch64/common/mmu.c (renamed from libcpu/aarch64/cortex-a53/mmu.c)0
-rw-r--r--libcpu/aarch64/common/mmu.h (renamed from libcpu/aarch64/cortex-a53/mmu.h)0
-rw-r--r--libcpu/aarch64/common/startup_gcc.S (renamed from libcpu/aarch64/cortex-a53/startup_gcc.S)0
-rw-r--r--libcpu/aarch64/common/vector_gcc.S (renamed from libcpu/aarch64/cortex-a53/vector_gcc.S)0
-rw-r--r--libcpu/aarch64/cortex-a53/SConscript15
-rw-r--r--libcpu/aarch64/cortex-a53/interrupt.h6
-rw-r--r--libcpu/aarch64/cortex-a72/SConscript13
-rw-r--r--libcpu/aarch64/cortex-a72/entry_point.S111
-rw-r--r--libcpu/aarch64/cortex-a72/interrupt.c119
-rw-r--r--libcpu/aarch64/cortex-a72/interrupt.h27
-rw-r--r--libcpu/aarch64/cortex-a72/stack.c90
-rw-r--r--libcpu/aarch64/cortex-a72/trap.c98
23 files changed, 840 insertions, 13 deletions
diff --git a/libcpu/aarch64/SConscript b/libcpu/aarch64/SConscript
index 453afe4b3e..5fca2b473b 100644
--- a/libcpu/aarch64/SConscript
+++ b/libcpu/aarch64/SConscript
@@ -9,6 +9,9 @@ cwd = GetCurrentDir()
group = []
list = os.listdir(cwd)
+# add common code files
+group = group + SConscript(os.path.join('common', 'SConscript'))
+
# cpu porting code files
if rtconfig.CPU != 'common':
group = group + SConscript(os.path.join(rtconfig.CPU, 'SConscript'))
diff --git a/libcpu/aarch64/common/SConscript b/libcpu/aarch64/common/SConscript
new file mode 100644
index 0000000000..72fb8e26c3
--- /dev/null
+++ b/libcpu/aarch64/common/SConscript
@@ -0,0 +1,24 @@
+# RT-Thread building script for component
+
+from building import *
+
+Import('rtconfig')
+
+cwd = GetCurrentDir()
+src = Glob('*.c') + Glob('*.cpp') + Glob('*.S')
+CPPPATH = [cwd]
+
+group = DefineGroup('common', src, depend = [''], CPPPATH = CPPPATH)
+
+# build for sub-directory
+list = os.listdir(cwd)
+objs = []
+
+for d in list:
+ path = os.path.join(cwd, d)
+ if os.path.isfile(os.path.join(path, 'SConscript')):
+ objs = objs + SConscript(os.path.join(d, 'SConscript'))
+group = group + objs
+
+
+Return('group')
diff --git a/libcpu/aarch64/cortex-a53/armv8.h b/libcpu/aarch64/common/armv8.h
index 4350890544..4350890544 100644
--- a/libcpu/aarch64/cortex-a53/armv8.h
+++ b/libcpu/aarch64/common/armv8.h
diff --git a/libcpu/aarch64/cortex-a53/cache.S b/libcpu/aarch64/common/cache.S
index 7f295a2b02..7f295a2b02 100644
--- a/libcpu/aarch64/cortex-a53/cache.S
+++ b/libcpu/aarch64/common/cache.S
diff --git a/libcpu/aarch64/cortex-a53/context_gcc.S b/libcpu/aarch64/common/context_gcc.S
index 934db7ed84..934db7ed84 100644
--- a/libcpu/aarch64/cortex-a53/context_gcc.S
+++ b/libcpu/aarch64/common/context_gcc.S
diff --git a/libcpu/aarch64/cortex-a53/cp15.h b/libcpu/aarch64/common/cp15.h
index f3ffd6f857..f3ffd6f857 100644
--- a/libcpu/aarch64/cortex-a53/cp15.h
+++ b/libcpu/aarch64/common/cp15.h
diff --git a/libcpu/aarch64/cortex-a53/cpu.c b/libcpu/aarch64/common/cpu.c
index 962a53a071..962a53a071 100644
--- a/libcpu/aarch64/cortex-a53/cpu.c
+++ b/libcpu/aarch64/common/cpu.c
diff --git a/libcpu/aarch64/cortex-a53/cpu_gcc.S b/libcpu/aarch64/common/cpu_gcc.S
index b8c8b8768c..b8c8b8768c 100644
--- a/libcpu/aarch64/cortex-a53/cpu_gcc.S
+++ b/libcpu/aarch64/common/cpu_gcc.S
diff --git a/libcpu/aarch64/common/gic/SConscript b/libcpu/aarch64/common/gic/SConscript
new file mode 100644
index 0000000000..b114ba7678
--- /dev/null
+++ b/libcpu/aarch64/common/gic/SConscript
@@ -0,0 +1,24 @@
+# RT-Thread building script for component
+
+from building import *
+
+cwd = GetCurrentDir()
+CPPPATH = [cwd]
+
+gic400_group = Split('''
+gic_pl400.c
+''')
+
+gic500_group = Split('''
+gic_pl500.c
+''')
+
+src = ()
+if GetDepend('BSP_USING_GIC400'):
+ src = gic400_group
+if GetDepend('BSP_USING_GIC500'):
+ src = gic500_group
+
+group = DefineGroup('gic', src, depend = ['BSP_USING_GIC'], CPPPATH = CPPPATH)
+
+Return('group')
diff --git a/libcpu/aarch64/common/gic/gic_pl400.c b/libcpu/aarch64/common/gic/gic_pl400.c
new file mode 100644
index 0000000000..4d003a9dcd
--- /dev/null
+++ b/libcpu/aarch64/common/gic/gic_pl400.c
@@ -0,0 +1,262 @@
+/*
+ * Copyright (c) 2006-2018, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2013-07-20 Bernard first version
+ * 2014-04-03 Grissiom many enhancements
+ * 2018-11-22 Jesven add rt_hw_ipi_send()
+ * add rt_hw_ipi_handler_install()
+ */
+#include <rtthread.h>
+
+#include "gic_pl400.h"
+#include "cp15.h"
+#include "iomap.h"
+
+#define ARM_GIC_MAX_NR 1
+struct arm_gic
+{
+ rt_uint32_t offset; /* the first interrupt index in the vector table */
+
+ rt_uint32_t dist_hw_base; /* the base address of the gic distributor */
+ rt_uint32_t cpu_hw_base; /* the base addrees of the gic cpu interface */
+};
+
+/* 'ARM_GIC_MAX_NR' is the number of cores */
+static struct arm_gic _gic_table[ARM_GIC_MAX_NR];
+
+static unsigned int _gic_max_irq;
+
+int arm_gic_get_active_irq(rt_uint32_t index)
+{
+ int irq;
+
+ RT_ASSERT(index < ARM_GIC_MAX_NR);
+
+ irq = GIC_CPU_INTACK(_gic_table[index].cpu_hw_base);
+ irq += _gic_table[index].offset;
+ return irq;
+}
+
+void arm_gic_ack(rt_uint32_t index, int irq)
+{
+ rt_uint32_t mask = 1 << (irq % 32);
+
+ RT_ASSERT(index < ARM_GIC_MAX_NR);
+
+ irq = irq - _gic_table[index].offset;
+ RT_ASSERT(irq >= 0);
+
+ GIC_DIST_ENABLE_CLEAR(_gic_table[index].dist_hw_base, irq) = mask;
+ GIC_CPU_EOI(_gic_table[index].cpu_hw_base) = irq;
+ GIC_DIST_ENABLE_SET(_gic_table[index].dist_hw_base, irq) = mask;
+}
+
+void arm_gic_mask(rt_uint32_t index, int irq)
+{
+ rt_uint32_t mask = 1 << (irq % 32);
+
+ RT_ASSERT(index < ARM_GIC_MAX_NR);
+
+ irq = irq - _gic_table[index].offset;
+ RT_ASSERT(irq >= 0);
+
+ GIC_DIST_ENABLE_CLEAR(_gic_table[index].dist_hw_base, irq) = mask;
+}
+
+void arm_gic_clear_pending(rt_uint32_t index, int irq)
+{
+ rt_uint32_t mask = 1 << (irq % 32);
+
+ RT_ASSERT(index < ARM_GIC_MAX_NR);
+
+ irq = irq - _gic_table[index].offset;
+ RT_ASSERT(irq >= 0);
+
+ GIC_DIST_PENDING_CLEAR(_gic_table[index].dist_hw_base, irq) = mask;
+}
+
+void arm_gic_clear_active(rt_uint32_t index, int irq)
+{
+ rt_uint32_t mask = 1 << (irq % 32);
+
+ RT_ASSERT(index < ARM_GIC_MAX_NR);
+
+ irq = irq - _gic_table[index].offset;
+ RT_ASSERT(irq >= 0);
+
+ GIC_DIST_ACTIVE_CLEAR(_gic_table[index].dist_hw_base, irq) = mask;
+}
+
+/* Set up the cpu mask for the specific interrupt */
+void arm_gic_set_cpu(rt_uint32_t index, int irq, unsigned int cpumask)
+{
+ rt_uint32_t old_tgt;
+
+ RT_ASSERT(index < ARM_GIC_MAX_NR);
+
+ irq = irq - _gic_table[index].offset;
+ RT_ASSERT(irq >= 0);
+
+ old_tgt = GIC_DIST_TARGET(_gic_table[index].dist_hw_base, irq);
+
+ old_tgt &= ~(0x0FFUL << ((irq % 4)*8));
+ old_tgt |= cpumask << ((irq % 4)*8);
+
+ GIC_DIST_TARGET(_gic_table[index].dist_hw_base, irq) = old_tgt;
+}
+
+void arm_gic_umask(rt_uint32_t index, int irq)
+{
+ rt_uint32_t mask = 1 << (irq % 32);
+
+ RT_ASSERT(index < ARM_GIC_MAX_NR);
+
+ irq = irq - _gic_table[index].offset;
+ RT_ASSERT(irq >= 0);
+
+ GIC_DIST_ENABLE_SET(_gic_table[index].dist_hw_base, irq) = mask;
+}
+
+void arm_gic_dump_type(rt_uint32_t index)
+{
+ unsigned int gic_type;
+
+ gic_type = GIC_DIST_TYPE(_gic_table[index].dist_hw_base);
+ rt_kprintf("GICv%d on %p, max IRQs: %d, %s security extension(%08x)\n",
+ (GIC_DIST_ICPIDR2(_gic_table[index].dist_hw_base) >> 4) & 0xf,
+ _gic_table[index].dist_hw_base,
+ _gic_max_irq,
+ gic_type & (1 << 10) ? "has" : "no",
+ gic_type);
+}
+
+void arm_gic_dump(rt_uint32_t index)
+{
+ unsigned int i, k;
+
+ k = GIC_CPU_HIGHPRI(_gic_table[index].cpu_hw_base);
+ rt_kprintf("--- high pending priority: %d(%08x)\n", k, k);
+ rt_kprintf("--- hw mask ---\n");
+ for (i = 0; i < _gic_max_irq / 32; i++)
+ {
+ rt_kprintf("0x%08x, ",
+ GIC_DIST_ENABLE_SET(_gic_table[index].dist_hw_base,
+ i * 32));
+ }
+ rt_kprintf("\n--- hw pending ---\n");
+ for (i = 0; i < _gic_max_irq / 32; i++)
+ {
+ rt_kprintf("0x%08x, ",
+ GIC_DIST_PENDING_SET(_gic_table[index].dist_hw_base,
+ i * 32));
+ }
+ rt_kprintf("\n--- hw active ---\n");
+ for (i = 0; i < _gic_max_irq / 32; i++)
+ {
+ rt_kprintf("0x%08x, ",
+ GIC_DIST_ACTIVE_SET(_gic_table[index].dist_hw_base,
+ i * 32));
+ }
+ rt_kprintf("\n");
+}
+#ifdef RT_USING_FINSH
+#include <finsh.h>
+FINSH_FUNCTION_EXPORT_ALIAS(arm_gic_dump, gic, show gic status);
+#endif
+
+int arm_gic_dist_init(rt_uint32_t index, rt_uint32_t dist_base, int irq_start)
+{
+ unsigned int gic_type, i;
+ rt_uint32_t cpumask = 1 << 0;
+
+ RT_ASSERT(index < ARM_GIC_MAX_NR);
+
+ _gic_table[index].dist_hw_base = dist_base;
+ _gic_table[index].offset = irq_start;
+
+ /* Find out how many interrupts are supported. */
+ gic_type = GIC_DIST_TYPE(dist_base);
+ _gic_max_irq = ((gic_type & 0x1f) + 1) * 32;
+
+ /*
+ * The GIC only supports up to 1020 interrupt sources.
+ * Limit this to either the architected maximum, or the
+ * platform maximum.
+ */
+ if (_gic_max_irq > 1020)
+ _gic_max_irq = 1020;
+ if (_gic_max_irq > ARM_GIC_NR_IRQS) /* the platform maximum interrupts */
+ _gic_max_irq = ARM_GIC_NR_IRQS;
+
+ cpumask |= cpumask << 8;
+ cpumask |= cpumask << 16;
+ cpumask |= cpumask << 24;
+
+ GIC_DIST_CTRL(dist_base) = 0x0;
+
+ /* Set all global interrupts to be level triggered, active low. */
+ for (i = 32; i < _gic_max_irq; i += 16)
+ GIC_DIST_CONFIG(dist_base, i) = 0x0;
+
+ /* Set all global interrupts to this CPU only. */
+ for (i = 32; i < _gic_max_irq; i += 4)
+ GIC_DIST_TARGET(dist_base, i) = cpumask;
+
+ /* Set priority on all interrupts. */
+ for (i = 0; i < _gic_max_irq; i += 4)
+ GIC_DIST_PRI(dist_base, i) = 0xa0a0a0a0;
+
+ /* Disable all interrupts. */
+ for (i = 0; i < _gic_max_irq; i += 32)
+ GIC_DIST_ENABLE_CLEAR(dist_base, i) = 0xffffffff;
+
+#if 0
+ /* All interrupts defaults to IGROUP1(IRQ). */
+ for (i = 0; i < _gic_max_irq; i += 32)
+ GIC_DIST_IGROUP(dist_base, i) = 0xffffffff;
+#endif
+ for (i = 0; i < _gic_max_irq; i += 32)
+ GIC_DIST_IGROUP(dist_base, i) = 0;
+
+ /* Enable group0 and group1 interrupt forwarding. */
+ GIC_DIST_CTRL(dist_base) = 0x01;
+
+ return 0;
+}
+
+int arm_gic_cpu_init(rt_uint32_t index, rt_uint32_t cpu_base)
+{
+ RT_ASSERT(index < ARM_GIC_MAX_NR);
+
+ _gic_table[index].cpu_hw_base = cpu_base;
+
+ GIC_CPU_PRIMASK(cpu_base) = 0xf0;
+ GIC_CPU_BINPOINT(cpu_base) = 0x7;
+ /* Enable CPU interrupt */
+ GIC_CPU_CTRL(cpu_base) = 0x01;
+
+ return 0;
+}
+
+void arm_gic_set_group(rt_uint32_t index, int vector, int group)
+{
+ /* As for GICv2, there are only group0 and group1. */
+ RT_ASSERT(group <= 1);
+ RT_ASSERT(vector < _gic_max_irq);
+
+ if (group == 0)
+ {
+ GIC_DIST_IGROUP(_gic_table[index].dist_hw_base,
+ vector) &= ~(1 << (vector % 32));
+ }
+ else if (group == 1)
+ {
+ GIC_DIST_IGROUP(_gic_table[index].dist_hw_base,
+ vector) |= (1 << (vector % 32));
+ }
+}
+
diff --git a/libcpu/aarch64/common/gic/gic_pl400.h b/libcpu/aarch64/common/gic/gic_pl400.h
new file mode 100644
index 0000000000..fa20846ea2
--- /dev/null
+++ b/libcpu/aarch64/common/gic/gic_pl400.h
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2006-2018, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2013-07-20 Bernard first version
+ */
+
+#ifndef __GIC_PL400_H__
+#define __GIC_PL400_H__
+
+#include <rthw.h>
+#include <board.h>
+
+#define __REG32(x) (*((volatile unsigned int*)((rt_uint64_t)x)))
+
+#define GIC_CPU_CTRL(hw_base) __REG32((hw_base) + 0x00)
+#define GIC_CPU_PRIMASK(hw_base) __REG32((hw_base) + 0x04)
+#define GIC_CPU_BINPOINT(hw_base) __REG32((hw_base) + 0x08)
+#define GIC_CPU_INTACK(hw_base) __REG32((hw_base) + 0x0c)
+#define GIC_CPU_EOI(hw_base) __REG32((hw_base) + 0x10)
+#define GIC_CPU_RUNNINGPRI(hw_base) __REG32((hw_base) + 0x14)
+#define GIC_CPU_HIGHPRI(hw_base) __REG32((hw_base) + 0x18)
+
+#define GIC_DIST_CTRL(hw_base) __REG32((hw_base) + 0x000)
+#define GIC_DIST_TYPE(hw_base) __REG32((hw_base) + 0x004)
+#define GIC_DIST_IGROUP(hw_base, n) __REG32((hw_base) + 0x080 + ((n)/32) * 4)
+#define GIC_DIST_ENABLE_SET(hw_base, n) __REG32((hw_base) + 0x100 + ((n)/32) * 4)
+#define GIC_DIST_ENABLE_CLEAR(hw_base, n) __REG32((hw_base) + 0x180 + ((n)/32) * 4)
+#define GIC_DIST_PENDING_SET(hw_base, n) __REG32((hw_base) + 0x200 + ((n)/32) * 4)
+#define GIC_DIST_PENDING_CLEAR(hw_base, n) __REG32((hw_base) + 0x280 + ((n)/32) * 4)
+#define GIC_DIST_ACTIVE_SET(hw_base, n) __REG32((hw_base) + 0x300 + ((n)/32) * 4)
+#define GIC_DIST_ACTIVE_CLEAR(hw_base, n) __REG32((hw_base) + 0x380 + ((n)/32) * 4)
+#define GIC_DIST_PRI(hw_base, n) __REG32((hw_base) + 0x400 + ((n)/4) * 4)
+#define GIC_DIST_TARGET(hw_base, n) __REG32((hw_base) + 0x800 + ((n)/4) * 4)
+#define GIC_DIST_CONFIG(hw_base, n) __REG32((hw_base) + 0xc00 + ((n)/16) * 4)
+#define GIC_DIST_SOFTINT(hw_base) __REG32((hw_base) + 0xf00)
+#define GIC_DIST_CPENDSGI(hw_base, n) __REG32((hw_base) + 0xf10 + ((n)/4) * 4)
+#define GIC_DIST_ICPIDR2(hw_base) __REG32((hw_base) + 0xfe8)
+
+int arm_gic_dist_init(rt_uint32_t index, rt_uint32_t dist_base, int irq_start);
+int arm_gic_cpu_init(rt_uint32_t index, rt_uint32_t cpu_base);
+
+void arm_gic_mask(rt_uint32_t index, int irq);
+void arm_gic_umask(rt_uint32_t index, int irq);
+void arm_gic_set_cpu(rt_uint32_t index, int irq, unsigned int cpumask);
+void arm_gic_set_group(rt_uint32_t index, int vector, int group);
+
+int arm_gic_get_active_irq(rt_uint32_t index);
+void arm_gic_ack(rt_uint32_t index, int irq);
+
+void arm_gic_clear_active(rt_uint32_t index, int irq);
+void arm_gic_clear_pending(rt_uint32_t index, int irq);
+
+void arm_gic_dump_type(rt_uint32_t index);
+void arm_gic_dump(rt_uint32_t index);
+
+#endif
+
diff --git a/libcpu/aarch64/cortex-a53/mmu.c b/libcpu/aarch64/common/mmu.c
index b799143084..b799143084 100644
--- a/libcpu/aarch64/cortex-a53/mmu.c
+++ b/libcpu/aarch64/common/mmu.c
diff --git a/libcpu/aarch64/cortex-a53/mmu.h b/libcpu/aarch64/common/mmu.h
index 6a66472c79..6a66472c79 100644
--- a/libcpu/aarch64/cortex-a53/mmu.h
+++ b/libcpu/aarch64/common/mmu.h
diff --git a/libcpu/aarch64/cortex-a53/startup_gcc.S b/libcpu/aarch64/common/startup_gcc.S
index ea4268148c..ea4268148c 100644
--- a/libcpu/aarch64/cortex-a53/startup_gcc.S
+++ b/libcpu/aarch64/common/startup_gcc.S
diff --git a/libcpu/aarch64/cortex-a53/vector_gcc.S b/libcpu/aarch64/common/vector_gcc.S
index fc88cce7f8..fc88cce7f8 100644
--- a/libcpu/aarch64/cortex-a53/vector_gcc.S
+++ b/libcpu/aarch64/common/vector_gcc.S
diff --git a/libcpu/aarch64/cortex-a53/SConscript b/libcpu/aarch64/cortex-a53/SConscript
index 75e170a0cf..c6a4817802 100644
--- a/libcpu/aarch64/cortex-a53/SConscript
+++ b/libcpu/aarch64/cortex-a53/SConscript
@@ -1,16 +1,13 @@
+# RT-Thread building script for component
+
from building import *
+Import('rtconfig')
+
cwd = GetCurrentDir()
-src = Glob('*.c') + Glob('*.cpp')
-asm_src = Split('''
-context_gcc.S
-vector_gcc.S
-entry_point.S
-cpu_gcc.S
-cache.S
-''')
+src = Glob('*.c') + Glob('*.cpp') + Glob('*.S')
CPPPATH = [cwd]
-group = DefineGroup('cpu', src + asm_src, depend = [''], CPPPATH = CPPPATH)
+group = DefineGroup('common', src, depend = [''], CPPPATH = CPPPATH)
Return('group')
diff --git a/libcpu/aarch64/cortex-a53/interrupt.h b/libcpu/aarch64/cortex-a53/interrupt.h
index 3533d3818c..8e741ed4e6 100644
--- a/libcpu/aarch64/cortex-a53/interrupt.h
+++ b/libcpu/aarch64/cortex-a53/interrupt.h
@@ -1,11 +1,11 @@
-
/*
* Copyright (c) 2006-2020, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
- * Date Author Notes
+ * Date Author Notes
+ * 2020-04-16 bigmagic first version
*/
#ifndef __INTERRUPT_H__
@@ -19,8 +19,6 @@
#define INT_IRQ 0x00
#define INT_FIQ 0x01
-//void rt_hw_vector_init(void);
-
void rt_hw_interrupt_init(void);
void rt_hw_interrupt_mask(int vector);
void rt_hw_interrupt_umask(int vector);
diff --git a/libcpu/aarch64/cortex-a72/SConscript b/libcpu/aarch64/cortex-a72/SConscript
new file mode 100644
index 0000000000..c6a4817802
--- /dev/null
+++ b/libcpu/aarch64/cortex-a72/SConscript
@@ -0,0 +1,13 @@
+# RT-Thread building script for component
+
+from building import *
+
+Import('rtconfig')
+
+cwd = GetCurrentDir()
+src = Glob('*.c') + Glob('*.cpp') + Glob('*.S')
+CPPPATH = [cwd]
+
+group = DefineGroup('common', src, depend = [''], CPPPATH = CPPPATH)
+
+Return('group')
diff --git a/libcpu/aarch64/cortex-a72/entry_point.S b/libcpu/aarch64/cortex-a72/entry_point.S
new file mode 100644
index 0000000000..6d2c69226b
--- /dev/null
+++ b/libcpu/aarch64/cortex-a72/entry_point.S
@@ -0,0 +1,111 @@
+/*
+ * Copyright (c) 2006-2020, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Date Author Notes
+ * 2020-01-15 bigmagic the first version
+ */
+
+.section ".text.entrypoint"
+
+.set EL1_stack, __el1_stack
+
+.global _start
+
+// This symbol is set to 0x80000 in ld script. That is the address that raspi3's firmware
+// loads 'kernel8.img' file in.
+_start:
+ // read cpu id, stop slave cores
+ mrs x1, mpidr_el1 // MPIDR_EL1: Multi-Processor Affinity Register
+ and x1, x1, #3
+ cbz x1, .L__cpu_0 // .L prefix is the local label in ELF
+
+ // cpu id > 0, stop
+ // cpu id == 0 will also goto here after returned from entry() if possible
+.L__current_cpu_idle:
+ wfe
+ b .L__current_cpu_idle
+
+.L__cpu_0: // cpu id == 0
+
+ // set stack before our code
+
+ /* Define stack pointer for current exception level */
+ // ldr x2, =EL1_stack
+ // mov sp, x2
+
+ ldr x1, =_start
+
+ // set up EL1
+ mrs x0, CurrentEL // CurrentEL Register. bit 2, 3. Others reserved
+ and x0, x0, #12 // clear reserved bits
+
+ // running at EL3?
+ cmp x0, #12 // 1100b. So, EL3
+ bne .L__not_in_el3 // 11? !EL3 -> 5:
+
+ // should never be executed, just for completeness. (EL3)
+ mov x2, #0x5b1
+ msr scr_el3, x2 // SCR_ELn Secure Configuration Register
+ mov x2, #0x3c9
+ msr spsr_el3, x2 // SPSR_ELn. Saved Program Status Register. 1111001001
+ adr x2, .L__not_in_el3
+ msr elr_el3, x2
+ eret // Exception Return: from EL3, continue from .L__not_in_el3
+
+ // running at EL2 or EL1
+.L__not_in_el3:
+ cmp x0, #4 // 0x04 0100 EL1
+ beq .L__in_el1 // EL1 -> 5:
+
+ // in EL2
+ msr sp_el1, x1 // Set sp of EL1 to _start
+
+ // enable CNTP for EL1
+ mrs x0, cnthctl_el2 // Counter-timer Hypervisor Control register
+ orr x0, x0, #3
+ msr cnthctl_el2, x0
+ msr cntvoff_el2, xzr
+
+ // enable AArch64 in EL1
+ mov x0, #(1 << 31) // AArch64
+ orr x0, x0, #(1 << 1) // SWIO hardwired on Pi3
+ msr hcr_el2, x0
+ mrs x0, hcr_el2
+
+ // change execution level to EL1
+ mov x2, #0x3c4
+ msr spsr_el2, x2 // 1111000100
+ adr x2, .L__in_el1
+ msr elr_el2, x2
+ eret // exception return. from EL2. continue from .L__in_el1
+
+.L__in_el1:
+ mov sp, x1 // in EL1. Set sp to _start
+
+ // Set CPACR_EL1 (Architecture Feature Access Control Register) to avoid trap from SIMD or float point instruction
+ mov x1, #0x00300000 // Don't trap any SIMD/FP instructions in both EL0 and EL1
+ msr cpacr_el1, x1
+
+ mrs x1, sctlr_el1
+ orr x1, x1, #(1 << 12)
+ bic x1, x1, #(3 << 3)
+ bic x1, x1, #(1 << 1)
+ msr sctlr_el1, x1
+
+ // clear bss
+ ldr x1, =__bss_start
+ ldr w2, =__bss_size
+
+.L__clean_bss_loop:
+ cbz w2, .L__jump_to_entry
+ str xzr, [x1], #8
+ sub w2, w2, #1
+ cbnz w2, .L__clean_bss_loop
+
+ // jump to C code, should not return
+.L__jump_to_entry:
+ bl entry
+ // for failsafe, halt this core too
+ b .L__current_cpu_idle
diff --git a/libcpu/aarch64/cortex-a72/interrupt.c b/libcpu/aarch64/cortex-a72/interrupt.c
new file mode 100644
index 0000000000..6fec968dc2
--- /dev/null
+++ b/libcpu/aarch64/cortex-a72/interrupt.c
@@ -0,0 +1,119 @@
+/*
+ * Copyright (c) 2006-2020, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2020-04-16 bigmagic first version
+ */
+
+#include <rthw.h>
+#include <rtthread.h>
+#include <gic_pl400.h>
+#include <board.h>
+#include <armv8.h>
+#include "iomap.h"
+
+#define MAX_HANDLERS 256
+#define GIC_ACK_INTID_MASK 0x000003ff
+
+#ifdef RT_USING_SMP
+#define rt_interrupt_nest rt_cpu_self()->irq_nest
+#else
+extern volatile rt_uint8_t rt_interrupt_nest;
+#endif
+
+extern int system_vectors;
+
+/* exception and interrupt handler table */
+struct rt_irq_desc isr_table[MAX_HANDLERS];
+
+rt_ubase_t rt_interrupt_from_thread;
+rt_ubase_t rt_interrupt_to_thread;
+rt_ubase_t rt_thread_switch_interrupt_flag;
+
+void rt_hw_vector_init(void)
+{
+ rt_hw_set_current_vbar((rt_ubase_t)&system_vectors); // cpu_gcc.S
+}
+
+/**
+ * This function will initialize hardware interrupt
+ */
+void rt_hw_interrupt_init(void)
+{
+
+ rt_uint32_t gic_cpu_base = 0;
+ rt_uint32_t gic_dist_base = 0;
+
+ /* initialize ARM GIC */
+ gic_dist_base = GIC_PL400_DISTRIBUTOR_PPTR;
+ gic_cpu_base = GIC_PL400_CONTROLLER_PPTR;
+ arm_gic_dist_init(0, gic_dist_base, 0);
+ arm_gic_cpu_init(0, gic_cpu_base);
+}
+
+/**
+ * This function will install a interrupt service routine to a interrupt.
+ * @param vector the interrupt number
+ * @param new_handler the interrupt service routine to be installed
+ * @param old_handler the old interrupt service routine
+ */
+rt_isr_handler_t rt_hw_interrupt_install(int vector, rt_isr_handler_t handler,
+ void *param, const char *name)
+{
+ rt_isr_handler_t old_handler = RT_NULL;
+
+ if (vector < MAX_HANDLERS)
+ {
+ old_handler = isr_table[vector].handler;
+
+ if (handler != RT_NULL)
+ {
+#ifdef RT_USING_INTERRUPT_INFO
+ rt_strncpy(isr_table[vector].name, name, RT_NAME_MAX);
+#endif /* RT_USING_INTERRUPT_INFO */
+ isr_table[vector].handler = handler;
+ isr_table[vector].param = param;
+ }
+ }
+
+ return old_handler;
+}
+
+/**
+ * This function will mask a interrupt.
+ * @param vector the interrupt number
+ */
+void rt_hw_interrupt_mask(int vector)
+{
+ arm_gic_mask(0, vector);
+}
+
+/**
+ * This function will un-mask a interrupt.
+ * @param vector the interrupt number
+ */
+void rt_hw_interrupt_umask(int vector)
+{
+ arm_gic_umask(0, vector);
+}
+
+/**
+ * This function returns the active interrupt number.
+ * @param none
+ */
+int rt_hw_interrupt_get_irq(void)
+{
+ return arm_gic_get_active_irq(0) & GIC_ACK_INTID_MASK;
+}
+
+/**
+ * This function acknowledges the interrupt.
+ * @param vector the interrupt number
+ */
+void rt_hw_interrupt_ack(int vector)
+{
+ arm_gic_ack(0, vector);
+}
diff --git a/libcpu/aarch64/cortex-a72/interrupt.h b/libcpu/aarch64/cortex-a72/interrupt.h
new file mode 100644
index 0000000000..0d2d4867c7
--- /dev/null
+++ b/libcpu/aarch64/cortex-a72/interrupt.h
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2006-2020, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2020-04-16 bigmagic first version
+ */
+
+#ifndef __INTERRUPT_H__
+#define __INTERRUPT_H__
+
+#include <rthw.h>
+#include <board.h>
+
+#define INT_IRQ 0x00
+#define INT_FIQ 0x01
+
+void rt_hw_interrupt_init(void);
+void rt_hw_interrupt_mask(int vector);
+void rt_hw_interrupt_umask(int vector);
+
+rt_isr_handler_t rt_hw_interrupt_install(int vector, rt_isr_handler_t handler,
+ void *param, const char *name);
+
+#endif
diff --git a/libcpu/aarch64/cortex-a72/stack.c b/libcpu/aarch64/cortex-a72/stack.c
new file mode 100644
index 0000000000..68222c2c67
--- /dev/null
+++ b/libcpu/aarch64/cortex-a72/stack.c
@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) 2006-2019, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2011-09-23 Bernard the first version
+ * 2011-10-05 Bernard add thumb mode
+ */
+#include <rtthread.h>
+#include <board.h>
+
+#include <armv8.h>
+
+#define INITIAL_SPSR_EL3 (PSTATE_EL3 | SP_EL0)
+#define INITIAL_SPSR_EL2 (PSTATE_EL2 | SP_EL0)
+#define INITIAL_SPSR_EL1 (PSTATE_EL1 | SP_EL0)
+
+/**
+ * This function will initialize thread stack
+ *
+ * @param tentry the entry of thread
+ * @param parameter the parameter of entry
+ * @param stack_addr the beginning stack address
+ * @param texit the function will be called when thread exit
+ *
+ * @return stack address
+ */
+rt_uint8_t *rt_hw_stack_init(void *tentry, void *parameter,
+ rt_uint8_t *stack_addr, void *texit)
+{
+ rt_ubase_t *stk;
+ rt_ubase_t current_el;
+
+ stk = (rt_ubase_t*)stack_addr;
+
+ *(--stk) = ( rt_ubase_t ) 11; /* X1 */
+ *(--stk) = ( rt_ubase_t ) parameter; /* X0 */
+ *(--stk) = ( rt_ubase_t ) 33; /* X3 */
+ *(--stk) = ( rt_ubase_t ) 22; /* X2 */
+ *(--stk) = ( rt_ubase_t ) 55; /* X5 */
+ *(--stk) = ( rt_ubase_t ) 44; /* X4 */
+ *(--stk) = ( rt_ubase_t ) 77; /* X7 */
+ *(--stk) = ( rt_ubase_t ) 66; /* X6 */
+ *(--stk) = ( rt_ubase_t ) 99; /* X9 */
+ *(--stk) = ( rt_ubase_t ) 88; /* X8 */
+ *(--stk) = ( rt_ubase_t ) 11; /* X11 */
+ *(--stk) = ( rt_ubase_t ) 10; /* X10 */
+ *(--stk) = ( rt_ubase_t ) 13; /* X13 */
+ *(--stk) = ( rt_ubase_t ) 12; /* X12 */
+ *(--stk) = ( rt_ubase_t ) 15; /* X15 */
+ *(--stk) = ( rt_ubase_t ) 14; /* X14 */
+ *(--stk) = ( rt_ubase_t ) 17; /* X17 */
+ *(--stk) = ( rt_ubase_t ) 16; /* X16 */
+ *(--stk) = ( rt_ubase_t ) 19; /* X19 */
+ *(--stk) = ( rt_ubase_t ) 18; /* X18 */
+ *(--stk) = ( rt_ubase_t ) 21; /* X21 */
+ *(--stk) = ( rt_ubase_t ) 20; /* X20 */
+ *(--stk) = ( rt_ubase_t ) 23; /* X23 */
+ *(--stk) = ( rt_ubase_t ) 22; /* X22 */
+ *(--stk) = ( rt_ubase_t ) 25; /* X25 */
+ *(--stk) = ( rt_ubase_t ) 24; /* X24 */
+ *(--stk) = ( rt_ubase_t ) 27; /* X27 */
+ *(--stk) = ( rt_ubase_t ) 26; /* X26 */
+ *(--stk) = ( rt_ubase_t ) 29; /* X29 */
+ *(--stk) = ( rt_ubase_t ) 28; /* X28 */
+ *(--stk) = ( rt_ubase_t ) 0; /* XZR - has no effect, used so there are an even number of registers. */
+ *(--stk) = ( rt_ubase_t ) texit; /* X30 - procedure call link register. */
+
+ current_el = rt_hw_get_current_el();
+
+ if(current_el == 3)
+ {
+ *(--stk) = INITIAL_SPSR_EL3;
+ }
+ else if(current_el == 2)
+ {
+ *(--stk) = INITIAL_SPSR_EL2;
+ }
+ else
+ {
+ *(--stk) = INITIAL_SPSR_EL1;
+ }
+
+ *(--stk) = ( rt_ubase_t ) tentry; /* Exception return address. */
+
+ /* return task's current stack address */
+ return (rt_uint8_t *)stk;
+}
diff --git a/libcpu/aarch64/cortex-a72/trap.c b/libcpu/aarch64/cortex-a72/trap.c
new file mode 100644
index 0000000000..d93aa18fd6
--- /dev/null
+++ b/libcpu/aarch64/cortex-a72/trap.c
@@ -0,0 +1,98 @@
+/*
+ * Copyright (c) 2006-2020, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Date Author Notes
+ * 2018-10-06 ZhaoXiaowei the first version
+ */
+
+#include <rtthread.h>
+#include <rthw.h>
+
+#include "interrupt.h"
+#include "armv8.h"
+
+extern struct rt_thread *rt_current_thread;
+#ifdef RT_USING_FINSH
+extern long list_thread(void);
+#endif
+
+/**
+ * this function will show registers of CPU
+ *
+ * @param regs the registers point
+ */
+void rt_hw_show_register(struct rt_hw_exp_stack *regs)
+{
+ rt_kprintf("Execption:\n");
+ rt_kprintf("r00:0x%16.16lx r01:0x%16.16lx r02:0x%16.16lx r03:0x%16.16lx\n", regs->x0, regs->x1, regs->x2, regs->x3);
+ rt_kprintf("r04:0x%16.16lx r05:0x%16.16lx r06:0x%16.16lx r07:0x%16.16lx\n", regs->x4, regs->x5, regs->x6, regs->x7);
+ rt_kprintf("r08:0x%16.16lx r09:0x%16.16lx r10:0x%16.16lx r11:0x%16.16lx\n", regs->x8, regs->x9, regs->x10, regs->x11);
+ rt_kprintf("r12:0x%16.16lx r13:0x%16.16lx r14:0x%16.16lx r15:0x%16.16lx\n", regs->x12, regs->x13, regs->x14, regs->x15);
+ rt_kprintf("r16:0x%16.16lx r17:0x%16.16lx r18:0x%16.16lx r19:0x%16.16lx\n", regs->x16, regs->x17, regs->x18, regs->x19);
+ rt_kprintf("r20:0x%16.16lx r21:0x%16.16lx r22:0x%16.16lx r23:0x%16.16lx\n", regs->x20, regs->x21, regs->x22, regs->x23);
+ rt_kprintf("r24:0x%16.16lx r25:0x%16.16lx r26:0x%16.16lx r27:0x%16.16lx\n", regs->x24, regs->x25, regs->x26, regs->x27);
+ rt_kprintf("r28:0x%16.16lx r29:0x%16.16lx r30:0x%16.16lx\n", regs->x28, regs->x29, regs->x30);
+ rt_kprintf("spsr:0x%16.16lx\n", regs->spsr);
+ rt_kprintf("return pc:0x%16.16lx\n", regs->pc);
+}
+
+/**
+ * When comes across an instruction which it cannot handle,
+ * it takes the undefined instruction trap.
+ *
+ * @param regs system registers
+ *
+ * @note never invoke this function in application
+ */
+void rt_hw_trap_error(struct rt_hw_exp_stack *regs)
+{
+ rt_kprintf("error exception:\n");
+ rt_hw_show_register(regs);
+#ifdef RT_USING_FINSH
+ list_thread();
+#endif
+ rt_hw_cpu_shutdown();
+}
+
+#define GIC_ACK_INTID_MASK 0x000003ff
+
+int rt_hw_interrupt_get_irq(void);
+void rt_hw_interrupt_ack(int fiq_irq);
+
+void rt_hw_trap_irq(void)
+{
+ void *param;
+ int ir;
+ rt_isr_handler_t isr_func;
+ extern struct rt_irq_desc isr_table[];
+
+ ir = rt_hw_interrupt_get_irq();
+ if (ir == 1023)
+ {
+ /* Spurious interrupt */
+ return;
+ }
+
+ /* get interrupt service routine */
+ isr_func = isr_table[ir].handler;
+#ifdef RT_USING_INTERRUPT_INFO
+ isr_table[ir].counter++;
+#endif
+ if (isr_func)
+ {
+ /* Interrupt for myself. */
+ param = isr_table[ir].param;
+ /* turn to interrupt service routine */
+ isr_func(ir, param);
+ }
+
+ /* end of interrupt */
+ rt_hw_interrupt_ack(ir);
+
+}
+
+void rt_hw_trap_fiq(void)
+{
+}