Skip to content

Commit 1babcda

Browse files
committed
Introduce base ARM support
This adds basic bare-bones support for aarch32 & aarch64 execution modes of the ARM architecture. Signed-off-by: Daniil Tatianin <[email protected]>
1 parent be0e1c8 commit 1babcda

File tree

12 files changed

+201
-3
lines changed

12 files changed

+201
-3
lines changed

CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,25 @@ cmake_minimum_required(VERSION 3.16)
22

33
if (NOT ULTRA_ARCH)
44
set(ULTRA_ARCH x86)
5-
elseif (NOT ULTRA_ARCH STREQUAL "x86")
5+
elseif (NOT ULTRA_ARCH STREQUAL "x86" AND
6+
NOT ULTRA_ARCH STREQUAL "arm")
67
message(FATAL_ERROR "Invalid architecture ${ULTRA_ARCH}")
78
endif ()
89

910
if (NOT ULTRA_ARCH_EXECUTION_MODE)
1011
if (ULTRA_ARCH STREQUAL "x86")
1112
set(ULTRA_ARCH_EXECUTION_MODE "x86_64")
13+
elseif (ULTRA_ARCH STREQUAL "arm")
14+
set(ULTRA_ARCH_EXECUTION_MODE "aarch64")
1215
endif ()
1316
endif ()
1417

1518
set(ULTRA_FULL_ARCH "${ULTRA_ARCH}/${ULTRA_ARCH_EXECUTION_MODE}")
1619

1720
if (ULTRA_ARCH STREQUAL "x86")
1821
set(ULTRA_VALID_EXECUTION_MODES i686 x86_64)
22+
elseif (ULTRA_ARCH STREQUAL "arm")
23+
set(ULTRA_VALID_EXECUTION_MODES aarch32 aarch64)
1924
endif ()
2025

2126
if (NOT ULTRA_ARCH_EXECUTION_MODE IN_LIST ULTRA_VALID_EXECUTION_MODES)

kernel/arch/arm/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
link-aarch32.ld
2+
link-aarch64.ld

kernel/arch/arm/CMakeLists.txt

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
if (ULTRA_ARCH_EXECUTION_MODE STREQUAL "aarch32")
2+
target_compile_definitions(${ULTRA_KERNEL} PUBLIC ULTRA_ARCH_WIDTH=4)
3+
target_compile_definitions(${ULTRA_KERNEL} PUBLIC ULTRA_PHYS_ADDR_WIDTH=4)
4+
ultra_target_compile_options(
5+
${ULTRA_KERNEL}
6+
-mfloat-abi=soft
7+
)
8+
message(
9+
FATAL_ERROR
10+
"aarch32 is not implemented (TODO: soft math helpers, loader support)"
11+
)
12+
else ()
13+
target_compile_definitions(${ULTRA_KERNEL} PUBLIC ULTRA_ARCH_WIDTH=8)
14+
target_compile_definitions(${ULTRA_KERNEL} PUBLIC ULTRA_PHYS_ADDR_WIDTH=8)
15+
ultra_target_compile_options(
16+
${ULTRA_KERNEL}
17+
-mgeneral-regs-only
18+
)
19+
20+
# GCC doesn't support red-zone on aarch64
21+
if (ULTRA_TOOLCHAIN STREQUAL "clang")
22+
ultra_target_compile_options(
23+
${ULTRA_KERNEL}
24+
PRIVATE
25+
-mno-red-zone
26+
)
27+
endif()
28+
endif()
29+
30+
target_sources(
31+
${ULTRA_KERNEL}
32+
PRIVATE
33+
entry.c
34+
io.c
35+
)
36+
target_include_directories(
37+
${ULTRA_KERNEL}
38+
PRIVATE
39+
include
40+
)
41+
42+
set(ULTRA_LD_TEMPLATE "${CMAKE_CURRENT_SOURCE_DIR}/link.ld.template")
43+
set(ULTRA_LD_SCRIPT
44+
"${CMAKE_CURRENT_SOURCE_DIR}/link-${ULTRA_ARCH_EXECUTION_MODE}.ld")
45+
add_ultra_ld_template(
46+
NAME
47+
kernel-link-script
48+
TEMPLATE_PATH
49+
${ULTRA_LD_TEMPLATE}
50+
OUT_PATH
51+
${ULTRA_LD_SCRIPT}
52+
DEPENDANT
53+
${ULTRA_KERNEL}
54+
)
55+
56+
ultra_target_link_options(
57+
${ULTRA_KERNEL}
58+
-T${ULTRA_LD_SCRIPT}
59+
-z max-page-size=4096
60+
)

kernel/arch/arm/entry.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include <boot/ultra_protocol.h>
2+
#include <boot/entry.h>
3+
#include <common/helpers.h>
4+
5+
void arm_entry(struct ultra_boot_context *ctx, uint32_t magic)
6+
{
7+
if (magic != ULTRA_MAGIC)
8+
for (;;);
9+
10+
UNUSED(ctx);
11+
entry();
12+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#pragma once
2+
3+
#define PAGE_SIZE 4096
4+
#define PAGE_SHIFT 12
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#pragma once
2+
3+
#include <common/types.h>
4+
#include <common/error.h>
5+
6+
#define ULTRA_ARCH_PORT_IO_WINDOW_OFFSET 0x1000000
7+
#define ULTRA_ARCH_PORT_IO_WINDOW_LEN 0x1000000
8+
#define ULTRA_ARCH_PORT_IO_WINDOW_END \
9+
(ULTRA_ARCH_PORT_IO_WINDOW_OFFSET + ULTRA_ARCH_PORT_IO_WINDOW_LEN + 1)
10+
11+
typedef void *pio_addr_t;
12+
typedef pio_addr_t pio_addr_or_error_t;
13+
14+
#define encode_error_pio_addr(ret) encode_error_ptr(ret)
15+
#define decode_error_pio_addr(ret) decode_error_ptr(ret)
16+
#define error_pio_addr(ret) error_ptr(ret)

kernel/arch/arm/io.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include <common/types.h>
2+
#include <common/error.h>
3+
#include <private/arch/io.h>
4+
5+
ptr_or_error_t arch_map_memory_io(phys_addr_t phys_base, size_t length)
6+
{
7+
UNUSED(phys_base);
8+
UNUSED(length);
9+
return encode_error_ptr(ENOTSUP);
10+
}
11+
12+
pio_addr_t arch_map_port_io(phys_addr_t phys_base, size_t length)
13+
{
14+
UNUSED(phys_base);
15+
UNUSED(length);
16+
return encode_error_pio_addr(ENOTSUP);
17+
}

kernel/arch/arm/link.ld.template

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
ENTRY(arm_entry)
2+
3+
#ifdef ULTRA_ARCH_EXECUTION_MODE_AARCH32
4+
VIRTUAL_BASE = 0xC0000000;
5+
PHYSICAL_OFFSET = 0;
6+
#else
7+
VIRTUAL_BASE = 0xFFFFFFFF80000000;
8+
PHYSICAL_OFFSET = 0;
9+
#endif
10+
11+
#include <linker_common.ld.h>
12+
13+
// NOTE: These flags are currently not enforced by anyone
14+
PHDRS
15+
{
16+
text PT_LOAD FLAGS(PHDR_READ | PHDR_EXEC);
17+
rodata PT_LOAD FLAGS(PHDR_READ);
18+
data PT_LOAD FLAGS(PHDR_READ | PHDR_WRITE);
19+
}
20+
21+
SECTIONS
22+
{
23+
. = VIRTUAL_BASE + PHYSICAL_OFFSET;
24+
25+
NORELOCS_GUARD
26+
27+
.text : VIRTUAL_BASE_RELATIVE(.text)
28+
{
29+
TEXT
30+
} :text
31+
32+
. = ALIGN(4K);
33+
34+
.rodata : VIRTUAL_BASE_RELATIVE(.rodata)
35+
{
36+
RODATA(ULTRA_ARCH_WIDTH)
37+
} :rodata =0xDEADBEEF
38+
39+
. = ALIGN(4K);
40+
41+
.data : VIRTUAL_BASE_RELATIVE(.data)
42+
{
43+
DATA
44+
} :data
45+
46+
.bss : VIRTUAL_BASE_RELATIVE(.bss)
47+
{
48+
BSS
49+
} :data
50+
51+
SECTION_DEBUG
52+
SECTION_TABS
53+
54+
. = ALIGN(8);
55+
56+
/*
57+
* We don't use these for now but keep them anyway,
58+
* otherwise linker complains.
59+
*/
60+
.ARM.exidx : {
61+
unwind_idx_begin = .;
62+
*(.ARM.exidx*)
63+
unwind_idx_end = .;
64+
}
65+
.ARM.extab : {
66+
unwind_table_begin = .;
67+
*(.ARM.extab*)
68+
unwind_table_end = .;
69+
}
70+
71+
ARM.attributes 0x000000000 : {
72+
*(.ARM.attributes)
73+
}
74+
75+
DISCARDS
76+
}

kernel/include/linker_common.ld.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
.debug_frame 0x000000000 : { *(.debug_frame) } \
4646
.debug_line 0x000000000 : { *(.debug_line) } \
4747
.debug_line_str 0x000000000 : { *(.debug_line_str) } \
48+
.debug_loc 0x000000000 : { *(.debug_loc) } \
4849
.debug_addr 0x000000000 : { *(.debug_addr) } \
4950
.debug_macro 0x000000000 : { *(.debug_macro) *(.debug_macro[*]) } \
5051
.debug_aranges 0x000000000 : { *(.debug_aranges) } \

toolchain/toolchain_clang.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ endif ()
1616
# Do this because cmake attempts to link against -lc and crt0
1717
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
1818

19-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --target=${ULTRA_ARCH_EXECUTION_MODE}-none-none")
19+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --target=${ULTRA_TARGET_PREFIX}-none-none")
2020
set(CMAKE_C_COMPILER clang)
2121
set(CMAKE_LINKER ${LLD_LINKER})

0 commit comments

Comments
 (0)