Skip to content

Commit 6c4e0f5

Browse files
committed
[cortex-m] Use fast 64-bit copy and zero tables
1 parent 5b4125f commit 6c4e0f5

File tree

3 files changed

+31
-25
lines changed

3 files changed

+31
-25
lines changed

src/modm/platform/core/cortex/linker.macros

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ EXCEPTION_FRAME_SIZE = {{ exception_frame_size }};
5353
__vector_table_rom_start = .;
5454
__vector_table_ram_load = .;
5555
KEEP(*(.vector_rom))
56+
. = ALIGN(8);
5657
__vector_table_rom_end = .;
5758
} >{{memory}}
5859
%% endmacro
@@ -65,7 +66,7 @@ EXCEPTION_FRAME_SIZE = {{ exception_frame_size }};
6566
{
6667
__vector_table_ram_start = .;
6768
KEEP(*(.vector_ram))
68-
. = ALIGN(4);
69+
. = ALIGN(8);
6970
__vector_table_ram_end = .;
7071
} >{{memory}}
7172
%% endmacro
@@ -144,10 +145,11 @@ EXCEPTION_FRAME_SIZE = {{ exception_frame_size }};
144145
%#
145146
.{{section}} :
146147
{
148+
. = ALIGN(8);
147149
__{{section}}_load = LOADADDR(.{{section}});
148150
__{{section}}_start = .;
149151
*(.{{section}} .{{section}}.*)
150-
. = ALIGN(4);
152+
. = ALIGN(8);
151153
__{{section}}_end = .;
152154
} >{{memory}}
153155
%% endfor
@@ -284,11 +286,11 @@ EXCEPTION_FRAME_SIZE = {{ exception_frame_size }};
284286
%% do table_copy.append("data")
285287
.data :
286288
{
287-
. = ALIGN(4);
289+
. = ALIGN(8);
288290
__data_load = LOADADDR(.data);
289291
__data_start = .;
290292
*(.data .data.* .gnu.linkonce.d.*)
291-
. = ALIGN(4);
293+
. = ALIGN(8);
292294
__data_end = .;
293295
} >{{memory}} AT >{{rom}}
294296
%% do table_copy.extend(sections_data)
@@ -299,7 +301,7 @@ EXCEPTION_FRAME_SIZE = {{ exception_frame_size }};
299301
__{{section}}_load = LOADADDR(.{{section}});
300302
__{{section}}_start = .;
301303
*(.{{section}} .{{section}}.*)
302-
. = ALIGN(4);
304+
. = ALIGN(8);
303305
__{{section}}_end = .;
304306
} >{{memory}} AT >{{rom}}
305307
%% endfor
@@ -320,6 +322,7 @@ EXCEPTION_FRAME_SIZE = {{ exception_frame_size }};
320322
. = ALIGN(4);
321323
__{{section}}_end = .;
322324
%% endfor
325+
. = ALIGN(8);
323326
__bss_end = .;
324327
} >{{memory}}
325328
%#
@@ -330,7 +333,7 @@ EXCEPTION_FRAME_SIZE = {{ exception_frame_size }};
330333
{
331334
__{{section}}_start = . ;
332335
*(.{{section}} .{{section}}.*)
333-
. = ALIGN(4);
336+
. = ALIGN(8);
334337
__{{section}}_end = .;
335338
} >{{memory}}
336339
%% endfor

src/modm/platform/core/cortex/module.lb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,10 +365,13 @@ def build(env):
365365

366366
# startup script
367367
env.template("reset_handler.sx.in")
368-
env.template("startup.c.in")
368+
ops = env.template("startup.c.in")
369+
# Prevent use of slow bytewise memcpy and memset in startup code
370+
env.collect(":build:cflags", "-fno-builtin", operations=ops)
371+
env.collect(":build:linkflags", "-nostartfiles")
372+
369373
env.template("vectors.c.in")
370374
env.template("vectors.hpp.in")
371-
env.collect(":build:linkflags", "-nostartfiles")
372375

373376
# dealing with runtime assertions
374377
if env.has_module(":architecture:assert"):

src/modm/platform/core/cortex/startup.c.in

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@ extern int main(void);
2929

3030
// ----------------------------------------------------------------------------
3131
// Linker section start and end pointers
32-
extern const uint32_t __table_copy_intern_start[];
33-
extern const uint32_t __table_copy_intern_end[];
32+
extern const uint64_t __table_copy_intern_start[];
33+
extern const uint64_t __table_copy_intern_end[];
3434

35-
extern const uint32_t __table_zero_intern_start[];
36-
extern const uint32_t __table_zero_intern_end[];
35+
extern const uint64_t __table_zero_intern_start[];
36+
extern const uint64_t __table_zero_intern_end[];
3737

38-
extern const uint32_t __table_copy_extern_start[];
39-
extern const uint32_t __table_copy_extern_end[];
38+
extern const uint64_t __table_copy_extern_start[];
39+
extern const uint64_t __table_copy_extern_end[];
4040

41-
extern const uint32_t __table_zero_extern_start[];
42-
extern const uint32_t __table_zero_extern_end[];
41+
extern const uint64_t __table_zero_extern_start[];
42+
extern const uint64_t __table_zero_extern_end[];
4343

4444
extern const uint32_t __vector_table_{{ vector_table_location }}_start[];
4545

@@ -64,13 +64,13 @@ table_call(const FunctionPointer *const start, const FunctionPointer *const end)
6464

6565
// Copies the section defined by a table of {loadaddr, dest start, dest end}
6666
static inline void
67-
table_copy(const uint32_t *const start, const uint32_t *const end)
67+
table_copy(const uint64_t *const start, const uint64_t *const end)
6868
{
69-
uint32_t **table = (uint32_t **)start;
70-
while(table < (uint32_t **)end)
69+
uint64_t **table = (uint64_t **)start;
70+
while(table < (uint64_t **)end)
7171
{
72-
const uint32_t *src = table[0]; // load address
73-
uint32_t *dest = table[1]; // destination start
72+
const uint64_t *src = table[0]; // load address
73+
uint64_t *dest = table[1]; // destination start
7474
while (dest < table[2]) // destination end
7575
*(dest++) = *(src++);
7676
table += 3;
@@ -79,12 +79,12 @@ table_copy(const uint32_t *const start, const uint32_t *const end)
7979

8080
// Zeros the section defined by a table of {start, end}
8181
static inline void
82-
table_zero(const uint32_t *const start, const uint32_t *const end)
82+
table_zero(const uint64_t *const start, const uint64_t *const end)
8383
{
84-
uint32_t **table = (uint32_t **)start;
85-
while(table < (uint32_t **)end)
84+
uint64_t **table = (uint64_t **)start;
85+
while(table < (uint64_t **)end)
8686
{
87-
uint32_t *dest = table[0]; // destination start
87+
uint64_t *dest = table[0]; // destination start
8888
while (dest < table[1]) // destination end
8989
*(dest++) = 0;
9090
table += 2;

0 commit comments

Comments
 (0)