File tree Expand file tree Collapse file tree 16 files changed +262
-0
lines changed
exercises/lesson01/3/stefanji Expand file tree Collapse file tree 16 files changed +262
-0
lines changed Original file line number Diff line number Diff line change 1+ ARMGNU ?= aarch64-linux-gnu
2+
3+ COPS = -Wall -nostdlib -nostartfiles -ffreestanding -Iinclude -mgeneral-regs-only
4+ ASMOPS = -Iinclude
5+
6+ BUILD_DIR = build
7+ SRC_DIR = src
8+
9+ all : kernel8.img
10+
11+ clean :
12+ rm -rf $(BUILD_DIR ) * .img
13+
14+ $(BUILD_DIR ) /% _c.o : $(SRC_DIR ) /% .c
15+ mkdir -p $(@D )
16+ $(ARMGNU ) -gcc $(COPS ) -MMD -c $< -o $@
17+
18+ $(BUILD_DIR ) /% _s.o : $(SRC_DIR ) /% .S
19+ $(ARMGNU ) -gcc $(ASMOPS ) -MMD -c $< -o $@
20+
21+ C_FILES = $(wildcard $(SRC_DIR ) /* .c)
22+ ASM_FILES = $(wildcard $(SRC_DIR ) /* .S)
23+ OBJ_FILES = $(C_FILES:$(SRC_DIR ) /%.c=$(BUILD_DIR ) /%_c.o )
24+ OBJ_FILES += $(ASM_FILES:$(SRC_DIR ) /%.S=$(BUILD_DIR ) /%_s.o )
25+
26+ DEP_FILES = $(OBJ_FILES:%.o=%.d )
27+ -include $(DEP_FILES )
28+
29+ kernel8.img : $(SRC_DIR ) /linker.ld $(OBJ_FILES )
30+ $(ARMGNU ) -ld -T $(SRC_DIR ) /linker.ld -o $(BUILD_DIR ) /kernel8.elf $(OBJ_FILES )
31+ $(ARMGNU ) -objcopy $(BUILD_DIR ) /kernel8.elf -O binary kernel8.img
Original file line number Diff line number Diff line change 1+ docker run --rm -v %cd% :/app -w /app smatyukevich/raspberry-pi-os-builder make %1
Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+
3+ docker run --rm -v $( pwd) :/app -w /app smatyukevich/raspberry-pi-os-builder make $1
Original file line number Diff line number Diff line change 1+ #ifndef _MINI_UART_H
2+ #define _MINI_UART_H
3+
4+ void uart_init ( void );
5+ char uart_recv ( void );
6+ void uart_send ( char c );
7+ void uart_send_string (char * str );
8+
9+ #endif /*_MINI_UART_H */
Original file line number Diff line number Diff line change 1+ #ifndef _MM_H
2+ #define _MM_H
3+
4+ #define PAGE_SHIFT 12
5+ #define TABLE_SHIFT 9
6+ #define SECTION_SHIFT (PAGE_SHIFT + TABLE_SHIFT)
7+
8+ #define PAGE_SIZE (1 << PAGE_SHIFT)
9+ #define SECTION_SIZE (1 << SECTION_SHIFT)
10+
11+ #define LOW_MEMORY (2 * SECTION_SIZE)
12+
13+ #define STACK_OFFSET 1 << 10 // 1KB
14+
15+ #ifndef __ASSEMBLER__
16+
17+ void memzero (unsigned long src , unsigned long n );
18+
19+ void init_memory (unsigned long begin , unsigned long end );
20+ void init_stack (unsigned int cort_id );
21+ int get_core_id ();
22+
23+ #endif
24+
25+ #endif /*_MM_H */
Original file line number Diff line number Diff line change 1+ #ifndef _P_BASE_H
2+ #define _P_BASE_H
3+
4+ #define PBASE 0x3F000000
5+
6+ #endif /*_P_BASE_H */
Original file line number Diff line number Diff line change 1+ #ifndef _P_GPIO_H
2+ #define _P_GPIO_H
3+
4+ #include "peripherals/base.h"
5+
6+ #define GPFSEL1 (PBASE+0x00200004)
7+ #define GPSET0 (PBASE+0x0020001C)
8+ #define GPCLR0 (PBASE+0x00200028)
9+ #define GPPUD (PBASE+0x00200094)
10+ #define GPPUDCLK0 (PBASE+0x00200098)
11+
12+ #endif /*_P_GPIO_H */
Original file line number Diff line number Diff line change 1+ #ifndef _P_MINI_UART_H
2+ #define _P_MINI_UART_H
3+
4+ #include "peripherals/base.h"
5+
6+ #define AUX_ENABLES (PBASE+0x00215004)
7+ #define AUX_MU_IO_REG (PBASE+0x00215040)
8+ #define AUX_MU_IER_REG (PBASE+0x00215044)
9+ #define AUX_MU_IIR_REG (PBASE+0x00215048)
10+ #define AUX_MU_LCR_REG (PBASE+0x0021504C)
11+ #define AUX_MU_MCR_REG (PBASE+0x00215050)
12+ #define AUX_MU_LSR_REG (PBASE+0x00215054)
13+ #define AUX_MU_MSR_REG (PBASE+0x00215058)
14+ #define AUX_MU_SCRATCH (PBASE+0x0021505C)
15+ #define AUX_MU_CNTL_REG (PBASE+0x00215060)
16+ #define AUX_MU_STAT_REG (PBASE+0x00215064)
17+ #define AUX_MU_BAUD_REG (PBASE+0x00215068)
18+
19+ #endif /*_P_MINI_UART_H */
Original file line number Diff line number Diff line change 1+ #ifndef _BOOT_H
2+ #define _BOOT_H
3+
4+ extern void delay ( unsigned long );
5+ extern void put32 ( unsigned long , unsigned int );
6+ extern unsigned int get32 ( unsigned long );
7+
8+ #endif /*_BOOT_H */
Original file line number Diff line number Diff line change 1+ #include "mm.h"
2+
3+ .section ".text.boot"
4+
5+ .globl _start
6+ _start:
7+ b master
8+
9+ proc_hang:
10+ b proc_hang
11+
12+ master:
13+ bl get_core_id
14+ cbz x0, init_memory
15+ bl get_core_id
16+ bl init_stack
17+ bl get_core_id
18+ bl kernel_main
You can’t perform that action at this time.
0 commit comments