-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
be7cdc6
commit e62f3e1
Showing
66 changed files
with
35,362 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
build/ | ||
test/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
cmake_minimum_required(VERSION 3.10) | ||
|
||
set(CROSS_COMPILE "arm-none-eabi-") | ||
|
||
set(CROSS_COMPILE ${CROSS_COMPILE} CACHE STRING "CROSS_COMPILE Toolchain") | ||
|
||
set(CMAKE_C_COMPILER "${CROSS_COMPILE}gcc") | ||
set(CMAKE_CXX_COMPILER "${CROSS_COMPILE}g++") | ||
|
||
set(CMAKE_COMMON_FLAGS "-nostdlib -mcpu=cortex-a7 -mthumb-interwork -mthumb -mno-unaligned-access -mfpu=neon-vfpv4 -mfloat-abi=hard") | ||
set(CMAKE_DISABLE_WARN_FLAGS "-Wno-int-to-pointer-cast -Wno-implicit-function-declaration") | ||
|
||
set(CMAKE_C_FLAGS "${CMAKE_DISABLE_WARN_FLAGS} ${CMAKE_C_FLAGS} ${CMAKE_COMMON_FLAGS}" CACHE STRING "c flags") | ||
set(CMAKE_CXX_FLAGS "${CMAKE_DISABLE_WARN_FLAGS} ${CMAKE_CXX_FLAGS} ${CMAKE_COMMON_FLAGS}" CACHE STRING "c++ flags") | ||
set(CMAKE_ASM_FLAGS "${CMAKE_DISABLE_WARN_FLAGS} ${CMAKE_ASM_FLAGS} ${CMAKE_COMMON_FLAGS}" CACHE STRING "asm flags") | ||
|
||
# Set Version, Release need cmake | ||
set(PROJECT_VERSION_MAJOR 0) | ||
set(PROJECT_VERSION_MINOR 0) | ||
|
||
# use git version as library version | ||
find_package(Git QUIET) | ||
if (Git_FOUND AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/../.git") | ||
execute_process( | ||
COMMAND ${GIT_EXECUTABLE} rev-list --count HEAD | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} | ||
OUTPUT_VARIABLE _git_version | ||
OUTPUT_STRIP_TRAILING_WHITESPACE | ||
) | ||
execute_process( | ||
COMMAND ${GIT_EXECUTABLE} log -1 --pretty=format:%h | ||
OUTPUT_VARIABLE PROJECT_GIT_HASH | ||
OUTPUT_STRIP_TRAILING_WHITESPACE | ||
ERROR_QUIET | ||
WORKING_DIRECTORY | ||
${CMAKE_CURRENT_SOURCE_DIR} | ||
) | ||
else () | ||
set(_git_version 0) | ||
set(PROJECT_GIT_HASH "") | ||
endif () | ||
|
||
project(SyterKit C CXX ASM) | ||
|
||
include(cmake/add_syterkit_app.cmake) | ||
|
||
configure_file( | ||
"${PROJECT_SOURCE_DIR}/config.h.in" | ||
"${PROJECT_BINARY_DIR}/config.h" | ||
) | ||
|
||
set(CMAKE_AR "${CROSS_COMPILE}ar") | ||
set(CMAKE_OBJCOPY "${CROSS_COMPILE}objcopy") | ||
|
||
set(LINK_SCRIPT_FEL ${CMAKE_SOURCE_DIR}/link/link_elf.ld) | ||
set(LINK_SCRIPT_BIN ${CMAKE_SOURCE_DIR}/link/link_bin.ld) | ||
|
||
include_directories( | ||
include | ||
include/arch | ||
include/drivers | ||
include/reg | ||
include/lib/fatfs | ||
include/lib/fdt | ||
${PROJECT_BINARY_DIR} | ||
) | ||
|
||
add_library(SyterKit | ||
# log | ||
src/log/log.c | ||
src/log/xformat.c | ||
# string | ||
src/string/string.c | ||
src/string/memcpy.S | ||
# exception & common | ||
src/exception.c | ||
src/common.c | ||
# deiver | ||
drivers/sys-clk.c | ||
drivers/sys-dma.c | ||
drivers/sys-gpio.c | ||
drivers/sys-dram.c | ||
drivers/sys-sdcard.c | ||
drivers/sys-sdhci.c | ||
drivers/sys-spi.c | ||
drivers/sys-timer.c | ||
drivers/sys-uart.c | ||
) | ||
|
||
target_link_libraries(SyterKit gcc) | ||
|
||
add_subdirectory(lib) | ||
|
||
add_subdirectory(app) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
add_subdirectory(hello_world) | ||
add_subdirectory(syter_boot) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
add_syterkit_app(helloworld | ||
start.S | ||
main.c | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include <stdint.h> | ||
#include <stddef.h> | ||
#include <stdbool.h> | ||
#include <types.h> | ||
|
||
#include <log.h> | ||
|
||
#include <common.h> | ||
|
||
extern uint32_t _start; | ||
extern uint32_t __spl_start; | ||
extern uint32_t __spl_end; | ||
extern uint32_t __spl_size; | ||
extern uint32_t __stack_srv_start; | ||
extern uint32_t __stack_srv_end; | ||
extern uint32_t __stack_ddr_srv_start; | ||
extern uint32_t __stack_ddr_srv_end; | ||
|
||
sunxi_uart_t uart_dbg = { | ||
.base = 0x02500000, | ||
.id = 2, | ||
.gpio_tx = {GPIO_PIN(PORTH, 9), GPIO_PERIPH_MUX5}, | ||
.gpio_rx = {GPIO_PIN(PORTH, 10), GPIO_PERIPH_MUX5}, | ||
}; | ||
|
||
int main(void) | ||
{ | ||
sunxi_uart_init(&uart_dbg); | ||
|
||
sunxi_clk_init(); | ||
|
||
printk(LOG_LEVEL_INFO, "Hello World!\r\n"); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,222 @@ | ||
#include <linkage.h> | ||
|
||
#define ARMV7_USR_MODE 0x10 | ||
#define ARMV7_FIQ_MODE 0x11 | ||
#define ARMV7_IRQ_MODE 0x12 | ||
#define ARMV7_SVC_MODE 0x13 | ||
#define ARMV7_MON_MODE 0x16 | ||
#define ARMV7_ABT_MODE 0x17 | ||
#define ARMV7_UND_MODE 0x1b | ||
#define ARMV7_SYSTEM_MODE 0x1f | ||
#define ARMV7_MODE_MASK 0x1f | ||
#define ARMV7_FIQ_MASK 0x40 | ||
#define ARMV7_IRQ_MASK 0x80 | ||
|
||
.arm | ||
.globl reset | ||
.text | ||
|
||
reset: | ||
/* Boot head information for BROM */ | ||
.long 0xea000016 | ||
.byte 'e', 'G', 'O', 'N', '.', 'B', 'T', '0' | ||
.long 0x12345678 /* checksum */ | ||
.long __spl_size /* spl size */ | ||
.long 0x30 /* boot header size */ | ||
.long 0x30303033 /* boot header version */ | ||
.long 0x00020000 /* return value */ | ||
.long 0x00028000 /* run address */ | ||
.long 0x0 /* eGON version */ | ||
.byte 0x00, 0x00, 0x00, 0x00 /* platform information - 8byte */ | ||
.byte 0x34, 0x2e, 0x30, 0x00 | ||
|
||
/* | ||
* The actual reset code | ||
*/ | ||
mrs r0, cpsr | ||
bic r0, r0, #ARMV7_MODE_MASK | ||
orr r0, r0, #ARMV7_SVC_MODE | ||
orr r0, r0, #(ARMV7_IRQ_MASK | ARMV7_FIQ_MASK) | ||
bic r0, r0, #(1<<9) @set little-endian | ||
msr cpsr_c, r0 | ||
|
||
/* Set vector base address register */ | ||
|
||
ldr r0, =_vector | ||
mcr p15, 0, r0, c12, c0, 0 | ||
mrc p15, 0, r0, c1, c0, 0 | ||
bic r0, #(1 << 13) | ||
mcr p15, 0, r0, c1, c0, 0 | ||
|
||
mrc p15, 0, r0, c1, c0, 0 | ||
bic r0, r0, #0x00002000 @ clear bits 13 (--V-) | ||
bic r0, r0, #0x00000007 @ clear bits 2:0 (-CAM) | ||
orr r0, r0, #0x00000800 @ set bit 11 (Z---) BTB | ||
bic r0, r0, #0x00001000 @ clear bit 12 (I) I-cache | ||
mcr p15, 0, r0, c1, c0, 0 | ||
|
||
/* Enable neon/vfp unit */ | ||
mrc p15, 0, r0, c1, c0, 2 | ||
orr r0, r0, #(0xf << 20) | ||
mcr p15, 0, r0, c1, c0, 2 | ||
isb | ||
mov r0, #0x40000000 | ||
vmsr fpexc, r0 | ||
|
||
/* Set stack pointer */ | ||
ldr sp, =__stack_srv_end | ||
|
||
bl clear_bss | ||
|
||
/* | ||
* disable interrupts (FIQ and IRQ), also set the cpu to SVC32 mode, | ||
* except if in HYP mode already | ||
*/ | ||
mrs r0, cpsr | ||
and r1, r0, #0x1f @ mask mode bits | ||
teq r1, #0x1a @ test for HYP mode | ||
bicne r0, r0, #0x1f @ clear all mode bits | ||
orrne r0, r0, #0x13 @ set SVC mode | ||
orr r0, r0, #0xc0 @ disable FIQ and IRQ | ||
msr cpsr,r0 | ||
|
||
@set cntfrq to 24M | ||
ldr r0, =24000000 | ||
mcr p15, 0, r0, c14, c0, 0 | ||
|
||
bl main | ||
|
||
clear_bss: | ||
ldr r0, =_sbss | ||
ldr r1, =_ebss | ||
mov r2, #0 | ||
|
||
clbss_1: | ||
stmia r0!, {r2} | ||
cmp r0, r1 | ||
blt clbss_1 | ||
|
||
mov pc, lr | ||
|
||
_vector: | ||
b reset | ||
ldr pc, _undefined_instruction | ||
ldr pc, _software_interrupt | ||
ldr pc, _prefetch_abort | ||
ldr pc, _data_abort | ||
ldr pc, _not_used | ||
ldr pc, _irq | ||
ldr pc, _fiq | ||
|
||
_undefined_instruction: | ||
.word undefined_instruction | ||
_software_interrupt: | ||
.word software_interrupt | ||
_prefetch_abort: | ||
.word prefetch_abort | ||
_data_abort: | ||
.word data_abort | ||
_not_used: | ||
.word not_used | ||
_irq: | ||
.word irq | ||
_fiq: | ||
.word fiq | ||
|
||
.macro save_regs | ||
str lr, [sp, #-4] | ||
mrs lr, spsr_all | ||
str lr, [sp, #-8] | ||
str r1, [sp, #-12] | ||
str r0, [sp, #-16] | ||
mov r0, sp | ||
cps #0x13 | ||
ldr r1, [r0, #-4] | ||
str r1, [sp, #-4]! | ||
ldr r1, [r0, #-8] | ||
str r1, [sp, #-(4 * 16)] | ||
ldr r1, [r0, #-12] | ||
ldr r0, [r0, #-16] | ||
stmdb sp, {r0 - r14}^ | ||
sub sp, sp, #(4 * 16) | ||
ldr r4, [sp] | ||
and r0, r4, #0x1f | ||
cmp r0, #0x10 | ||
beq 10f | ||
cmp r0, #0x13 | ||
beq 11f | ||
b . | ||
11: add r1, sp, #(4 * 17) | ||
str r1, [sp, #(4 * 14)] | ||
str lr, [sp, #(4 * 15)] | ||
10: add r1, sp, #(4 * 17) | ||
str r1, [sp, #-4]! | ||
mov r0, sp | ||
.endm | ||
|
||
.macro restore_regs | ||
mov r12, sp | ||
ldr sp, [r12], #4 | ||
ldr r1, [r12], #4 | ||
msr spsr_cxsf, r1 | ||
and r0, r1, #0x1f | ||
cmp r0, #0x10 | ||
beq 20f | ||
cmp r0, #0x13 | ||
beq 21f | ||
b . | ||
20: ldr lr, [r12, #(4 * 15)] | ||
ldmia r12, {r0 - r14}^ | ||
movs pc, lr | ||
21: ldm r12, {r0 - r15}^ | ||
mov r0, r0 | ||
.endm | ||
|
||
/* | ||
* Exception handlers | ||
*/ | ||
.align 5 | ||
undefined_instruction: | ||
sub lr, lr, #4 | ||
save_regs | ||
bl arm32_do_undefined_instruction | ||
restore_regs | ||
|
||
.align 5 | ||
software_interrupt: | ||
sub lr, lr, #4 | ||
save_regs | ||
bl arm32_do_software_interrupt | ||
restore_regs | ||
|
||
.align 5 | ||
prefetch_abort: | ||
sub lr, lr, #4 | ||
save_regs | ||
bl arm32_do_prefetch_abort | ||
restore_regs | ||
|
||
.align 5 | ||
data_abort: | ||
sub lr, lr, #8 | ||
save_regs | ||
bl arm32_do_data_abort | ||
restore_regs | ||
|
||
.align 5 | ||
not_used: | ||
b . | ||
|
||
.align 5 | ||
irq: | ||
sub lr, lr, #4 | ||
save_regs | ||
bl arm32_do_irq | ||
restore_regs | ||
|
||
.align 5 | ||
fiq: | ||
sub lr, lr, #4 | ||
save_regs | ||
bl arm32_do_fiq | ||
restore_regs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
add_syterkit_app(syter_boot | ||
start.S | ||
main.c | ||
) |
Oops, something went wrong.