From 24ab4678b96dec56129f7e36b9304b6767777e0a Mon Sep 17 00:00:00 2001 From: Wojtek Kosior Date: Thu, 3 Oct 2019 14:04:31 +0200 Subject: specify load address only in linker script; change it to 0x10000 (for now); avoid padding --- Makefile | 10 +++------- boot.S | 8 +++++--- linker.ld | 7 +++++-- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index 2e2f062..8ad7c03 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ all : kernel7.img kernel.o : kernel.c - arm-none-eabi-gcc -mcpu=cortex-a7 -ffreestanding -std=gnu99 -c -O2 -Wall -Wextra $^ -o $@ + arm-none-eabi-gcc -mcpu=cortex-a7 -ffreestanding -std=gnu99 -c -Wall -Wextra $^ -o $@ boot.o : boot.S arm-none-eabi-as -mcpu=cortex-a7 boot.S -o boot.o @@ -9,13 +9,9 @@ boot.o : boot.S kernel.elf : boot.o kernel.o arm-none-eabi-gcc -T linker.ld -o $@ -ffreestanding -O2 -nostdlib boot.o kernel.o -lgcc -# objcopy pads 0x0000 to 0x8000 with zeros, we get rid of them in the next recipe -kernel_padded.img : kernel.elf +kernel7.img : kernel.elf arm-none-eabi-objcopy $^ -O binary $@ -kernel7.img : kernel_padded.img - dd bs=4096 skip=8 if=$^ of=$@ - qemu-elf : kernel.elf qemu-system-arm -m 256 -M raspi2 -serial stdio -kernel $^ @@ -23,6 +19,6 @@ qemu-bin : kernel7.img qemu-system-arm -m 256 -M raspi2 -serial stdio -kernel $^ clean : - -rm kernel7.img kernel_padded.img kernel.elf boot.o kernel.o + -rm kernel7.img kernel.elf boot.o kernel.o .PHONY: all qemu-elf qemu-bin clean diff --git a/boot.S b/boot.S index da8aca7..20cf155 100644 --- a/boot.S +++ b/boot.S @@ -2,11 +2,12 @@ // To keep this in the first portion of the binary. .section ".text.boot" - + +//.org 0x8000 + // Make _start global. .globl _start -.org 0x8000 // Entry point for the kernel. // r15 -> should begin execution at 0x8000. // r0 -> 0x00000000 @@ -21,7 +22,8 @@ _start: bne halt // Setup the stack. - ldr r5, =_start + // It shall be directly below our kernel image + ldr r5, =__start mov sp, r5 // Clear out bss. diff --git a/linker.ld b/linker.ld index 7f3ee57..0cbd1fb 100644 --- a/linker.ld +++ b/linker.ld @@ -3,8 +3,11 @@ ENTRY(_start) SECTIONS { /* Starts at LOADER_ADDR. */ - . = 0x8000; - /* For AArch64, use . = 0x80000; */ + /* Warning! Internet says RPis in 32-bit mode load kernel at 0x8000! */ + /* My experiments do, however, show, that qemu emulating RPi2 */ + /* Loads the kernel at 0x10000! (took some pain to find out) */ + . = 0x10000; + /* For AArch64, use . = 0x80000; Unless this too is wrong */ __start = .; __text_start = .; .text : -- cgit v1.2.3