summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Braun <rbraun@sceen.net>2017-09-30 02:39:10 +0200
committerRichard Braun <rbraun@sceen.net>2017-09-30 02:39:10 +0200
commit862e8347cbe776e08c5f89b8faa45e13e0b92ed4 (patch)
treec11bc3af74a6277935fb64bb387e17d06d222405
parentca45067329704257d094618cdf2418d83053c14f (diff)
Make the kernel run its first instructions
-rw-r--r--arch/arm/Makefile10
-rw-r--r--arch/arm/machine/boot.c3
-rw-r--r--arch/arm/machine/boot.h11
-rw-r--r--arch/arm/machine/boot_asm.S25
-rw-r--r--arch/arm/machine/cpu.c4
-rw-r--r--arch/arm/machine/cpu.h13
-rw-r--r--arch/arm/machine/pmap.c1
-rw-r--r--arch/arm/machine/pmap.h17
-rw-r--r--arch/arm/machine/tcb.c2
-rw-r--r--arch/arm/x15.lds.S103
10 files changed, 178 insertions, 11 deletions
diff --git a/arch/arm/Makefile b/arch/arm/Makefile
index 921e76d9..7c74a409 100644
--- a/arch/arm/Makefile
+++ b/arch/arm/Makefile
@@ -1,3 +1,11 @@
KCONFIG_DEFCONFIG := qemu_virt_defconfig
-#x15_SOURCES-y += \
+XBUILD_CFLAGS += -mcpu=cortex-a15
+
+x15_SOURCES-y += \
+ arch/arm/machine/boot_asm.S \
+ arch/arm/machine/boot.c \
+ arch/arm/machine/cpu.c \
+ arch/arm/machine/pmap.c \
+ arch/arm/machine/strace.c \
+ arch/arm/machine/tcb.c
diff --git a/arch/arm/machine/boot.c b/arch/arm/machine/boot.c
index d476621a..121ad92a 100644
--- a/arch/arm/machine/boot.c
+++ b/arch/arm/machine/boot.c
@@ -16,6 +16,7 @@
*/
#include <kern/init.h>
+#include <machine/boot.h>
void __init
boot_log_info(void)
@@ -43,7 +44,7 @@ boot_setup_console(void)
INIT_OP_DEFINE(boot_setup_console);
static int __init
-boot_setup_intr(void)
+boot_load_vm_page_zones(void)
{
return 0;
}
diff --git a/arch/arm/machine/boot.h b/arch/arm/machine/boot.h
index 812dd7b5..6459e80b 100644
--- a/arch/arm/machine/boot.h
+++ b/arch/arm/machine/boot.h
@@ -18,6 +18,15 @@
#ifndef _ARM_BOOT_H
#define _ARM_BOOT_H
+#include <kern/macros.h>
+#include <machine/pmap.h>
+
+#define BOOT_OFFSET DECL_CONST(0x0, UL)
+
+#define BOOT_VTOP(addr) ((addr) - PMAP_KERNEL_OFFSET)
+
+#ifndef __ASSEMBLER__
+
#include <kern/init.h>
/*
@@ -55,4 +64,6 @@ INIT_OP_DECLARE(boot_setup_intr);
*/
INIT_OP_DECLARE(boot_setup_shutdown);
+#endif /* __ASSEMBLER__ */
+
#endif /* _ARM_BOOT_H */
diff --git a/arch/arm/machine/boot_asm.S b/arch/arm/machine/boot_asm.S
new file mode 100644
index 00000000..ccf3eb05
--- /dev/null
+++ b/arch/arm/machine/boot_asm.S
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2017 Richard Braun.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+.section .boot.hdr, "awx"
+
+.long _start
+
+.global _start
+_start:
+ mov %r0, #0x12
+ b .
diff --git a/arch/arm/machine/cpu.c b/arch/arm/machine/cpu.c
index a38c948a..a79200fe 100644
--- a/arch/arm/machine/cpu.c
+++ b/arch/arm/machine/cpu.c
@@ -27,6 +27,10 @@ void cpu_log_info(const struct cpu *cpu)
(void)cpu;
}
+void cpu_mp_setup(void)
+{
+}
+
static int __init
cpu_setup(void)
{
diff --git a/arch/arm/machine/cpu.h b/arch/arm/machine/cpu.h
index d6b8e892..80e11a05 100644
--- a/arch/arm/machine/cpu.h
+++ b/arch/arm/machine/cpu.h
@@ -19,10 +19,6 @@
#define _ARM_CPU_H
#include <limits.h>
-#include <stdbool.h>
-#include <stdnoreturn.h>
-
-#include <kern/init.h>
/*
* L1 cache line size.
@@ -36,6 +32,13 @@
*/
#define CPU_DATA_ALIGN (LONG_BIT / 8)
+#ifndef __ASSEMBLER__
+
+#include <stdbool.h>
+#include <stdnoreturn.h>
+
+#include <kern/init.h>
+
struct cpu {
};
@@ -138,4 +141,6 @@ INIT_OP_DECLARE(cpu_setup);
*/
INIT_OP_DECLARE(cpu_mp_probe);
+#endif /* __ASSEMBLER__ */
+
#endif /* _ARM_CPU_H */
diff --git a/arch/arm/machine/pmap.c b/arch/arm/machine/pmap.c
index aa2516f4..b97d3427 100644
--- a/arch/arm/machine/pmap.c
+++ b/arch/arm/machine/pmap.c
@@ -34,6 +34,7 @@ pmap_kextract(uintptr_t va, phys_addr_t *pap)
{
(void)va;
(void)pap;
+ return ERROR_AGAIN;
}
int
diff --git a/arch/arm/machine/pmap.h b/arch/arm/machine/pmap.h
index 3ec6ec92..bae0c060 100644
--- a/arch/arm/machine/pmap.h
+++ b/arch/arm/machine/pmap.h
@@ -18,12 +18,7 @@
#ifndef _ARM_PMAP_H
#define _ARM_PMAP_H
-#include <stddef.h>
-#include <stdint.h>
-
-#include <kern/cpumap.h>
#include <kern/macros.h>
-#include <machine/types.h>
#define PMAP_START_ADDRESS DECL_CONST(0, UL)
#define PMAP_END_ADDRESS DECL_CONST(0xc0000000, UL)
@@ -34,9 +29,19 @@
#define PMAP_START_DIRECTMAP_ADDRESS PMAP_END_ADDRESS
#define PMAP_END_DIRECTMAP_ADDRESS DECL_CONST(0xf8000000, UL)
+#define PMAP_KERNEL_OFFSET PMAP_START_DIRECTMAP_ADDRESS
+
#define PMAP_START_KMEM_ADDRESS PMAP_END_DIRECTMAP_ADDRESS
#define PMAP_END_KMEM_ADDRESS PMAP_END_KERNEL_ADDRESS
+#ifndef __ASSEMBLER__
+
+#include <stddef.h>
+#include <stdint.h>
+
+#include <kern/cpumap.h>
+#include <machine/types.h>
+
/*
* Mapping creation flags.
*/
@@ -77,4 +82,6 @@ INIT_OP_DECLARE(pmap_bootstrap);
*/
INIT_OP_DECLARE(pmap_setup);
+#endif /* __ASSEMBLER__ */
+
#endif /* _ARM_PMAP_H */
diff --git a/arch/arm/machine/tcb.c b/arch/arm/machine/tcb.c
index a1695ec1..074e5172 100644
--- a/arch/arm/machine/tcb.c
+++ b/arch/arm/machine/tcb.c
@@ -15,6 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <kern/error.h>
#include <kern/init.h>
#include <machine/tcb.h>
@@ -25,6 +26,7 @@ tcb_build(struct tcb *tcb, void *stack, void (*fn)(void *), void *arg)
(void)stack;
(void)fn;
(void)arg;
+ return ERROR_AGAIN;
}
void
diff --git a/arch/arm/x15.lds.S b/arch/arm/x15.lds.S
new file mode 100644
index 00000000..a5c6cd3b
--- /dev/null
+++ b/arch/arm/x15.lds.S
@@ -0,0 +1,103 @@
+/* OUTPUT_FORMAT("elf32-little") */
+/* OUTPUT_ARCH(arm) */
+
+ENTRY(_start)
+
+#include <kern/init.h>
+#include <machine/boot.h>
+#include <machine/cpu.h>
+#include <machine/page.h>
+#include <machine/pmap.h>
+
+PHDRS
+{
+ /* Flags are actually similar to classic Unix permissions */
+ boot PT_LOAD FLAGS(7);
+ init PT_LOAD FLAGS(7);
+ percpu PT_LOAD FLAGS(6);
+ text PT_LOAD FLAGS(5);
+ rodata PT_LOAD FLAGS(4);
+ data PT_LOAD FLAGS(6);
+}
+
+SECTIONS
+{
+ . = BOOT_OFFSET;
+ _boot = .;
+
+ .boot ALIGN(PAGE_SIZE) : {
+ *(.boot.hdr)
+ *(.boot.text)
+ *(.boot.data)
+ } : boot
+
+ . = ALIGN(PAGE_SIZE);
+ _boot_end = .;
+
+ . += PMAP_KERNEL_OFFSET;
+ _init = .;
+
+ .init ALIGN(PAGE_SIZE) : AT(BOOT_VTOP(ADDR(.init))) {
+ *(.init.text)
+ *(.init.data)
+
+ . = ALIGN(INIT_OP_ALIGN);
+ _init_ops = .;
+ *(.init.ops)
+ _init_ops_end = .;
+
+ } : init
+
+ . = ALIGN(PAGE_SIZE);
+ _init_end = .;
+ _percpu = .;
+
+ .percpu 0 : AT(BOOT_VTOP(_percpu)) {
+ *(.percpu)
+ } : percpu
+
+ . = _percpu + SIZEOF(.percpu);
+ . = ALIGN(PAGE_SIZE);
+ _percpu_end = .;
+ _text = .;
+
+ .text ALIGN(PAGE_SIZE) : AT(BOOT_VTOP(ADDR(.text))) {
+ *(.text)
+ } : text
+
+ . = ALIGN(PAGE_SIZE);
+ _rodata = .;
+
+ .rodata ALIGN(PAGE_SIZE) : AT(BOOT_VTOP(ADDR(.rodata))) {
+ *(.rodata)
+ } : rodata
+
+ .notes ALIGN(CPU_DATA_ALIGN) : AT(BOOT_VTOP(ADDR(.notes))) {
+ *(.note.*)
+ } : rodata
+
+ . = ALIGN(PAGE_SIZE);
+ _data = .;
+
+ .data ALIGN(PAGE_SIZE) : AT(BOOT_VTOP(ADDR(.data))) {
+ . = ALIGN(CPU_L1_SIZE);
+ *(.data.read_mostly)
+ . = ALIGN(CPU_L1_SIZE);
+ *(.data)
+ } : data
+
+ .bss ALIGN(CPU_DATA_ALIGN) : AT(BOOT_VTOP(ADDR(.bss))) {
+ *(.bss)
+ } : data
+
+ . = ALIGN(PAGE_SIZE);
+ _end = .;
+
+ /*
+ * XXX A global offset section is created because of linking with libgcc.
+ * Is it safe to discard it ?
+ */
+ /DISCARD/ : {
+ *(.eh_frame)
+ }
+}