Skip to content

Commit 2bd9c26

Browse files
committed
Turn on the ACT LED
1 parent 686a4a8 commit 2bd9c26

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed

Makefile

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Distributed under the terms of the GNU General Public License v2
2+
3+
CC ?= arm-none-eabi
4+
LD ?= $(CC)-ld
5+
AS ?= $(CC)-as
6+
7+
BUILD = build
8+
SOURCE = src
9+
TARGET = kernel.img
10+
LIST = kernel.list
11+
MAP = kernel.map
12+
LINKER = kernel.ld
13+
14+
OBJECTS := $(patsubst $(SOURCE)/%.s,$(BUILD)/%.o,$(wildcard $(SOURCE)/*.s))
15+
16+
all: $(TARGET) $(LIST)
17+
18+
$(LIST): $(BUILD)/output.elf
19+
$(CC)-objdump -d $< > $@
20+
21+
$(TARGET): $(BUILD)/output.elf
22+
$(CC)-objcopy $< -O binary $@
23+
24+
$(BUILD)/output.elf: $(OBJECTS) $(LINKER)
25+
$(LD) --no-undefined $< -Map $(MAP) -o $@ -T $(LINKER)
26+
27+
$(BUILD)/%.o: $(SOURCE)/%.s
28+
$(AS) -I $(SOURCE) $< -o $@
29+
30+
clean:
31+
rm -f $(BUILD)/*.o
32+
33+
mrproper: clean
34+
rm -f $(TARGET)
35+
rm -f $(LIST)
36+
rm -f $(MAP)

kernel.ld

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/* Distributed under the terms of the GNU General Public License v2 */
2+
3+
SECTIONS {
4+
/* Init section at 0x8000 according to the bootloader expectations. */
5+
.init 0x8000: {
6+
*(.init)
7+
}
8+
9+
/DISCARD/: {
10+
*(*)
11+
}
12+
}
13+

src/main.s

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Distributed under the terms of the GNU General Public License v2
2+
.section .init
3+
.glob _start
4+
5+
_start:
6+
7+
# Put the GPIO address in a registry
8+
ldr r0,=0x20200000
9+
10+
# Enable output to the 16th GPIO pin
11+
# => 2^18 stored at 0x20200004
12+
# The 16th GPIO pin is represented by the 6th set of 3 bits (#18=3×6) of the
13+
# second set of 4 bytes (#4=4×1).
14+
# Finally, we want to put #1 in the selected set of 3 bits to enable output
15+
mov r1,#1
16+
lsl r1,#18
17+
str r1,[r0,#4]
18+
19+
# Turn off (#40) the 16th pin (#16) of the GPIO to turn on the ACT LED.
20+
mov r1,#1
21+
lsl r1,#16
22+
str r1,[r0,#40]
23+
24+
# End
25+
loop$:
26+
b loop$
27+

0 commit comments

Comments
 (0)