From 4485fbb579619b6021ebb2616b0e8b46b1f89d23 Mon Sep 17 00:00:00 2001 From: greg Date: Sat, 25 Mar 2017 22:47:34 -0700 Subject: [PATCH] Add raspi_os here Eventually this is gonna be part of Ferrocyanide --- ferrocyanide/raspi_os/Makefile | 12 +++++ ferrocyanide/raspi_os/kernel.ld | 38 ++++++++++++++ ferrocyanide/raspi_os/kernel.map | 32 ++++++++++++ ferrocyanide/raspi_os/main.s | 36 +++++++++++++ ferrocyanide/raspi_os/template/LICENSE | 22 ++++++++ ferrocyanide/raspi_os/template/Makefile | 64 ++++++++++++++++++++++++ ferrocyanide/raspi_os/template/kernel.ld | 39 +++++++++++++++ 7 files changed, 243 insertions(+) create mode 100644 ferrocyanide/raspi_os/Makefile create mode 100755 ferrocyanide/raspi_os/kernel.ld create mode 100644 ferrocyanide/raspi_os/kernel.map create mode 100644 ferrocyanide/raspi_os/main.s create mode 100755 ferrocyanide/raspi_os/template/LICENSE create mode 100755 ferrocyanide/raspi_os/template/Makefile create mode 100755 ferrocyanide/raspi_os/template/kernel.ld diff --git a/ferrocyanide/raspi_os/Makefile b/ferrocyanide/raspi_os/Makefile new file mode 100644 index 0000000..48c0bb3 --- /dev/null +++ b/ferrocyanide/raspi_os/Makefile @@ -0,0 +1,12 @@ + +all: process + +process: + arm-none-eabi-as -I asm -o main.o main.s + arm-none-eabi-ld --no-undefined main.o -Map kernel.map -o output.elf -T kernel.ld + arm-none-eabi-objcopy output.elf -O binary kernel.img + +clean: + rm -f main.o + rm -f output.elf + rm -f kernel.img diff --git a/ferrocyanide/raspi_os/kernel.ld b/ferrocyanide/raspi_os/kernel.ld new file mode 100755 index 0000000..482e164 --- /dev/null +++ b/ferrocyanide/raspi_os/kernel.ld @@ -0,0 +1,38 @@ +/****************************************************************************** +* kernel.ld +* by Alex Chadwick +* +* A linker script for generation of raspberry pi kernel images. +******************************************************************************/ + +SECTIONS { + /* + * First and formost we need the .init section, containing the code to + * be run first. We allow room for the ATAGs and stack and conform to + * the bootloader's expectation by putting this code at 0x8000. + */ + .init 0x8000 : { + *(.init) + } + /* + * Next we put the rest of the code. + */ + .text : { + *(.text) + } + + /* + * Next we put the data. + */ + .data : { + *(.data) + } + + /* + * Finally comes everything else. A fun trick here is to put all other + * sections into this section, which will be discarded by default. + */ + /DISCARD/ : { + *(*) + } +} diff --git a/ferrocyanide/raspi_os/kernel.map b/ferrocyanide/raspi_os/kernel.map new file mode 100644 index 0000000..cfaafb1 --- /dev/null +++ b/ferrocyanide/raspi_os/kernel.map @@ -0,0 +1,32 @@ + +Discarded input sections + + .bss 0x0000000000000000 0x0 main.o + .ARM.attributes + 0x0000000000000000 0x14 main.o + +Memory Configuration + +Name Origin Length Attributes +*default* 0x0000000000000000 0xffffffffffffffff + +Linker script and memory map + +LOAD main.o + +.init 0x0000000000008000 0x50 + *(.init) + .init 0x0000000000008000 0x50 main.o + 0x0000000000008000 _start + +.text 0x0000000000008050 0x0 + *(.text) + .text 0x0000000000008050 0x0 main.o + +.data 0x0000000000008050 0x0 + *(.data) + .data 0x0000000000008050 0x0 main.o + +/DISCARD/ + *(*) +OUTPUT(output.elf elf32-littlearm) diff --git a/ferrocyanide/raspi_os/main.s b/ferrocyanide/raspi_os/main.s new file mode 100644 index 0000000..3b64068 --- /dev/null +++ b/ferrocyanide/raspi_os/main.s @@ -0,0 +1,36 @@ +.section .init + +.globl _start + +_start: + ldr r0,=0x20200000 //GPIO controller address + + mov r1, #1 // put 1 into r1 + lsl r1, #18 //logical shift left by 18 + str r1, [r0, #4] //store register + + loop: + mov r1, #1 + lsl r1, #16 //set pin 16 + str r1, [r0, #40] // toggle GPIO on + + mov r2, #0x3f0000 + wait: + sub r2, #1 + cmp r2, #0 + bne wait + + mov r1, #1 + lsl r1, #16 //set pin 16 + str r1, [r0, #28] // toggle GPIO ofrf + + mov r2, #0x3f0000 + wait2: + sub r2, #1 + cmp r2, #0 + bne wait2 + b loop + + + + diff --git a/ferrocyanide/raspi_os/template/LICENSE b/ferrocyanide/raspi_os/template/LICENSE new file mode 100755 index 0000000..548faef --- /dev/null +++ b/ferrocyanide/raspi_os/template/LICENSE @@ -0,0 +1,22 @@ +Copyright (c) 2012 Alex Chadwick + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the "Software"), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/ferrocyanide/raspi_os/template/Makefile b/ferrocyanide/raspi_os/template/Makefile new file mode 100755 index 0000000..8346b40 --- /dev/null +++ b/ferrocyanide/raspi_os/template/Makefile @@ -0,0 +1,64 @@ +############################################################################### +# makefile +# by Alex Chadwick +# +# A makefile script for generation of raspberry pi kernel images. +############################################################################### + +# The toolchain to use. arm-none-eabi works, but there does exist +# arm-bcm2708-linux-gnueabi. +ARMGNU ?= arm-none-eabi + +# The intermediate directory for compiled object files. +BUILD = build/ + +# The directory in which source files are stored. +SOURCE = source/ + +# The name of the output file to generate. +TARGET = kernel.img + +# The name of the assembler listing file to generate. +LIST = kernel.list + +# The name of the map file to generate. +MAP = kernel.map + +# The name of the linker script to use. +LINKER = kernel.ld + +# The names of all object files that must be generated. Deduced from the +# assembly code files in source. +OBJECTS := $(patsubst $(SOURCE)%.s,$(BUILD)%.o,$(wildcard $(SOURCE)*.s)) + +# Rule to make everything. +all: $(TARGET) $(LIST) + +# Rule to remake everything. Does not include clean. +rebuild: all + +# Rule to make the listing file. +$(LIST) : $(BUILD)output.elf + $(ARMGNU)-objdump -d $(BUILD)output.elf > $(LIST) + +# Rule to make the image file. +$(TARGET) : $(BUILD)output.elf + $(ARMGNU)-objcopy $(BUILD)output.elf -O binary $(TARGET) + +# Rule to make the elf file. +$(BUILD)output.elf : $(OBJECTS) $(LINKER) + $(ARMGNU)-ld --no-undefined $(OBJECTS) -Map $(MAP) -o $(BUILD)output.elf -T $(LINKER) + +# Rule to make the object files. +$(BUILD)%.o: $(SOURCE)%.s $(BUILD) + $(ARMGNU)-as -I $(SOURCE) $< -o $@ + +$(BUILD): + mkdir $@ + +# Rule to clean files. +clean : + -rm -rf $(BUILD) + -rm -f $(TARGET) + -rm -f $(LIST) + -rm -f $(MAP) \ No newline at end of file diff --git a/ferrocyanide/raspi_os/template/kernel.ld b/ferrocyanide/raspi_os/template/kernel.ld new file mode 100755 index 0000000..abc5c78 --- /dev/null +++ b/ferrocyanide/raspi_os/template/kernel.ld @@ -0,0 +1,39 @@ +/****************************************************************************** +* kernel.ld +* by Alex Chadwick +* +* A linker script for generation of raspberry pi kernel images. +******************************************************************************/ + +SECTIONS { + /* + * First and formost we need the .init section, containing the code to + * be run first. We allow room for the ATAGs and stack and conform to + * the bootloader's expectation by putting this code at 0x8000. + */ + .init 0x8000 : { + *(.init) + } + + /* + * Next we put the rest of the code. + */ + .text : { + *(.text) + } + + /* + * Next we put the data. + */ + .data : { + *(.data) + } + + /* + * Finally comes everything else. A fun trick here is to put all other + * sections into this section, which will be discarded by default. + */ + /DISCARD/ : { + *(*) + } +}