From 862e8347cbe776e08c5f89b8faa45e13e0b92ed4 Mon Sep 17 00:00:00 2001 From: Richard Braun Date: Sat, 30 Sep 2017 02:39:10 +0200 Subject: Make the kernel run its first instructions --- arch/arm/Makefile | 10 ++++- arch/arm/machine/boot.c | 3 +- arch/arm/machine/boot.h | 11 +++++ arch/arm/machine/boot_asm.S | 25 +++++++++++ arch/arm/machine/cpu.c | 4 ++ arch/arm/machine/cpu.h | 13 ++++-- arch/arm/machine/pmap.c | 1 + arch/arm/machine/pmap.h | 17 +++++--- arch/arm/machine/tcb.c | 2 + arch/arm/x15.lds.S | 103 ++++++++++++++++++++++++++++++++++++++++++++ 10 files changed, 178 insertions(+), 11 deletions(-) create mode 100644 arch/arm/machine/boot_asm.S create mode 100644 arch/arm/x15.lds.S 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 +#include 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 +#include + +#define BOOT_OFFSET DECL_CONST(0x0, UL) + +#define BOOT_VTOP(addr) ((addr) - PMAP_KERNEL_OFFSET) + +#ifndef __ASSEMBLER__ + #include /* @@ -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 . + */ + +.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 -#include -#include - -#include /* * L1 cache line size. @@ -36,6 +32,13 @@ */ #define CPU_DATA_ALIGN (LONG_BIT / 8) +#ifndef __ASSEMBLER__ + +#include +#include + +#include + 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 -#include - -#include #include -#include #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 +#include + +#include +#include + /* * 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 . */ +#include #include #include @@ -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 +#include +#include +#include +#include + +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) + } +} -- cgit v1.2.3