Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added status LED signal after disabling three cores #6

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ all: $(KERNEL)
%.o: %.c
${CROSS}gcc ${CFLAGS} -c -o $@ $<

$(NAME): main.o startup.o
${CROSS}ld $(LDFLAGS) -o $@ -T linkerscript.ld $<
$(NAME): main.o startup.o led.o
${CROSS}ld $(LDFLAGS) -o $@ -T linkerscript.ld $^

$(KERNEL): $(NAME)
${CROSS}objcopy --gap-fill=0xff -j .text -j .rodata -j .data -O binary $< $@

clean:
rm -f $(KERNEL) $(NAME) main.o startup.o
rm -f $(KERNEL) $(NAME) main.o startup.o led.o
62 changes: 62 additions & 0 deletions led.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*

-> taken fram the led01 example of https://github.com/adamransom/bare_metal
-> ... and adapted

@;
@; This turns on the ACT LED for the Raspberry Pi 3 Model B v1.2
@;
@; The ACT LED is no longer wired directly to a GPIO pin and now belongs on
@; the GPIO expander, which is controlled by the GPU. In order to communicate
@; with the GPIO expander, we need to use the GPU's mailbox interface (in
@; particular, we need to send a message to the property tag channel).
@;
@; Mailbox base address: 0x3f00b880
@; Mailbox 1 write address: [0x3f00b880, #0x20]
@; Property tag channel: 8
@; Property tag ID: 0x00038041 (SET_GPIO_STATE)
@; Property tag message: 130 1 (ACT_LED pin number followed by state)
@;
*/

.globl _set_led// @; Make _set_led available to the outside world

.section .data
.align 4// @; This ensures lowest 4 bits are 0 for the following label
PropertyInfo:
// @; = Message Header =
.int PropertyInfoEnd - PropertyInfo// @; Calculate buffer size
.int 0// @; Request code: Process Request
// @; = Tag Header =
.int 0x00038041// @; Tag ID (SET_GPIO_STATE)
.int 8// @; Value buffer size
.int 0// @; Request/response size
// @; = Tag Value Buffer =
.int 130// @; ACT_LED pin number
.int 1// @; Turn it on
.int 0// @; End tag
PropertyInfoEnd:

.section .text
_set_led:
mailbox .req x0// @; Alias mailbox to r0
ldr mailbox, =0x3f00b880// @; Load the mailbox's base address into r0

wait1$:
status .req x1// @; Alias status to r1
ldr status, [mailbox, #0x18]// @; Load the Mailbox 0 status address
tst status, #0x80000000// @; Check the status against the FULL bit
.unreq status// @; Unset the alias
bne wait1$// @; Keep checking the mailbox until it isn't full

message .req x1// @; Alias message to r1
ldr message, =PropertyInfo// @; Load r1 with address of our message buffer
add message, message, #8// @; Put the channel in the last 4 bits
str message, [mailbox, #0x20]// @; Put the message in the mailbox
.unreq message// @; Unset the alias
.unreq mailbox

ret // return from the led setting function

// hang:
// b hang// @; Give the CPU something to do ad infinitum
5 changes: 4 additions & 1 deletion startup.asm
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ _start:
and x2, x2, #0xFF
cbnz x2, hang

// then, core0 can move on to execute the main c function
// then, core0 can move on to call the function setting the status LED, and ...
bl _set_led

// ... to execute the main c function
ldr x5, =0x00100000
mov sp, x5
bl main
Expand Down