Skip to content

Commit 9f41038

Browse files
Release: v2.0
Highlights: - Added support for xc-dsc toolchain: CMake scripts, linker files - Arch bring-up for dsPIC (Curiosity board): thread creation, early boot, swap - CMake: Improved path detection, removed debug messages, static lib fixes - Interrupt vector table (IVT) initialization and macro definition - MISRA compliance fixes - Various bug fixes, stylistic cleanup, and compliance-related updates Changes: * cmake: Add xc-dsc toolchain support and linker script * arch: dspic: Rename isr_table_vt.ld to vector_table.ld * camke: Fix path detection for build dependencies * cmake: Resolve include path issues * cmake: Remove debug messages * arch: dspic: Add thread creation and init logic * arch: Resolve arch_swap implicit declaration warning * arch: Add vector tables and common ISR wrapper * cmake: Enable compiling assembly files * cmake: Fix static library linking * arch: Support IVT table placement and macros * cmake: Skip init priorities check for xc-dsc * toolchain: Remove stdlib usage (use picolibc instead) * arch: Remove use of unimplemented functions * arch: Early boot sequence implementation * arch: Task swap and main thread entry logic Signed-off-by: Udhayanandhan Jayakumar <[email protected]>
1 parent e11e459 commit 9f41038

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+5456
-20
lines changed

arch/Kconfig

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,28 @@ config RX
171171
help
172172
Renesas RX architecture
173173

174+
config DSPIC
175+
bool
176+
select ARCH_IS_SET
177+
select STACK_GROWS_UP
178+
select ARCH_HAS_CUSTOM_SWAP_TO_MAIN
179+
select LITTLE_ENDIAN
180+
select ARCH_HAS_THREAD_LOCAL_STORAGE
181+
select TOOLCHAIN_SUPPORTS_THREAD_LOCAL_STORAGE
182+
select THREAD_LOCAL_STORAGE
183+
select INIT_STACKS
184+
select STACK_SENTINAL
185+
select ATOMIC_OPERATIONS_C
186+
select ARCH_HAS_VECTOR_TABLE_RELOCATION
187+
select CPU_HAS_ICACHE
188+
select ARCH_HAS_CUSTOM_CPU_IDLE
189+
select ARCH_HAS_CUSTOM_CPU_ATOMIC_IDLE
190+
select DYNAMIC_INTERRUPTS
191+
select CACHE_MANAGEMENT
192+
select TICKLESS_CAPABLE
193+
help
194+
dspic architecture
195+
174196
config ARCH_IS_SET
175197
bool
176198
help
@@ -400,6 +422,11 @@ config STACK_GROWS_UP
400422
Select this option if the architecture has upward growing thread
401423
stacks. This is not common.
402424

425+
config STACK_SENTINAL
426+
bool
427+
help
428+
It is a debugging and safety feature at the boundaries of the stack.
429+
403430
config NO_UNUSED_STACK_INSPECTION
404431
bool
405432
help

arch/archs.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,6 @@ archs:
2929
- name: rx
3030
path: rx
3131
full_name: Renesas RX
32+
- name: dspic
33+
path: dspic
34+
full_name: Microchip dsPIC

arch/dspic/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
if(CONFIG_BIG_ENDIAN)
2+
set_property(GLOBAL PROPERTY PROPERTY_OUTPUT_FORMAT elf32-big)
3+
else()
4+
set_property(GLOBAL PROPERTY PROPERTY_OUTPUT_FORMAT elf32-little)
5+
endif()
6+
zephyr_include_directories(${XCDSC_TOOLCHAIN_PATH}/support/generic/h/)
7+
zephyr_include_directories(include)
8+
add_subdirectory(core)

arch/dspic/Kconfig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
menu "DSPIC Options"
2+
depends on DSPIC
3+
4+
config ARCH
5+
string
6+
default "dspic"
7+
8+
config NUM_IRQS
9+
default 287
10+
11+
config GEN_IRQ_START_VECTOR
12+
default 8
13+
14+
endmenu

arch/dspic/core/CMakeLists.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
zephyr_library()
2+
3+
zephyr_library_sources(
4+
cpu_idle.c
5+
fatal.c
6+
irq_manage.c
7+
isr_wrapper.c
8+
prep_c.c
9+
thread.c
10+
swap.c
11+
tls.c
12+
reset0.S
13+
init.S
14+
vector_table.S
15+
reset1.S
16+
)
17+
18+
zephyr_linker_sources(ROM_START SORT_KEY 0x04 vector_table.ld)

arch/dspic/core/cpu_idle.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* Copyright (c) 2025, Microchip Technology Inc.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#include <zephyr/irq.h>
7+
#include <zephyr/tracing/tracing.h>
8+
#include <zephyr/arch/cpu.h>
9+
10+
#ifndef CONFIG_ARCH_HAS_CUSTOM_CPU_IDLE
11+
void arch_cpu_idle(void)
12+
{
13+
}
14+
#endif
15+
16+
#ifndef CONFIG_ARCH_HAS_CUSTOM_CPU_ATOMIC_IDLE
17+
void arch_cpu_atomic_idle(unsigned int key)
18+
{
19+
(void)key;
20+
}
21+
#endif
22+
23+
FUNC_NORETURN void arch_system_halt(unsigned int reason)
24+
{
25+
(void)reason;
26+
CODE_UNREACHABLE;
27+
}

arch/dspic/core/fatal.c

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* Copyright (c) 2025, Microchip Technology Inc.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#include <zephyr/kernel.h>
7+
8+
volatile uint32_t reason, address;
9+
10+
#define EXCEPTION_HANDLER __attribute__((interrupt, no_auto_psv, keep))
11+
12+
void EXCEPTION_HANDLER _ReservedTrap7(void);
13+
void __attribute__((weak)) TRAPS_halt_on_error(void);
14+
void EXCEPTION_HANDLER _BusErrorTrap(void);
15+
void EXCEPTION_HANDLER _AddressErrorTrap(void);
16+
void EXCEPTION_HANDLER _IllegalInstructionTrap(void);
17+
void EXCEPTION_HANDLER _MathErrorTrap(void);
18+
void EXCEPTION_HANDLER _StackErrorTrap(void);
19+
void EXCEPTION_HANDLER _GeneralTrap(void);
20+
void EXCEPTION_HANDLER _ReservedTrap0(void);
21+
void EXCEPTION_HANDLER _ReservedTrap7(void);
22+
23+
void __attribute__((weak)) TRAPS_halt_on_error(void)
24+
{
25+
}
26+
27+
/** Bus error.**/
28+
void EXCEPTION_HANDLER _BusErrorTrap(void)
29+
{
30+
__asm__("nop");
31+
__asm__("retfie");
32+
}
33+
34+
/** Address error.**/
35+
void EXCEPTION_HANDLER _AddressErrorTrap(void)
36+
{
37+
__asm__("nop");
38+
__asm__("retfie");
39+
}
40+
41+
/** Illegal instruction.**/
42+
void EXCEPTION_HANDLER _IllegalInstructionTrap(void)
43+
{
44+
__asm__("nop");
45+
__asm__("retfie");
46+
}
47+
48+
/** Math error.**/
49+
void EXCEPTION_HANDLER _MathErrorTrap(void)
50+
{
51+
__asm__("nop");
52+
__asm__("retfie");
53+
}
54+
55+
/** Stack error.**/
56+
void EXCEPTION_HANDLER _StackErrorTrap(void)
57+
{
58+
__asm__("nop");
59+
__asm__("retfie");
60+
}
61+
62+
/** Generic error.**/
63+
void EXCEPTION_HANDLER _GeneralTrap(void)
64+
{
65+
__asm__("nop");
66+
__asm__("retfie");
67+
}
68+
69+
/** Reserved Trap0.**/
70+
void EXCEPTION_HANDLER _ReservedTrap0(void)
71+
{
72+
__asm__("nop");
73+
__asm__("retfie");
74+
}
75+
76+
/** Reserved Trap7.**/
77+
void EXCEPTION_HANDLER _ReservedTrap7(void)
78+
{
79+
__asm__("nop");
80+
__asm__("retfie");
81+
}

arch/dspic/core/init.S

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
.section .init,code
2+
.global __custom_data_init
3+
.global __custom_data_init_extended
4+
5+
.equ __custom_data_init, __custom_data_init_extended
6+
__custom_data_init_extended:
7+
8+
.equiv FMT_CLEAR,0
9+
.equiv FMT_COPY2,1
10+
.equiv FMT_COPY3,2
11+
.equiv FMT_CALL, 3
12+
.equiv FMT_DUO_COPY3,0x1F
13+
14+
#define DINIT w0
15+
#define TLSOFFSET w1
16+
#define TBLOFFSET w9
17+
#define DSTOFFSET w10
18+
#define LEN w11
19+
#define FORMAT w12
20+
21+
mov.l w0, TBLOFFSET
22+
bra 4f
23+
24+
1:
25+
add.l DSTOFFSET,TLSOFFSET,DSTOFFSET
26+
mov.l [TBLOFFSET++], LEN
27+
mov.l [TBLOFFSET++], FORMAT
28+
29+
cp.b FORMAT, #FMT_CALL
30+
bra nz, 2f
31+
call DSTOFFSET
32+
bra 4f
33+
34+
2:
35+
cp.b FORMAT, #FMT_CLEAR
36+
bra nz, 2f
37+
9:
38+
sub.l LEN, #1, LEN
39+
repeat LEN
40+
clr.b [DSTOFFSET++]
41+
bra 4f
42+
43+
2:
44+
cp.b FORMAT, #FMT_COPY2
45+
bra z, 3f
46+
47+
3:
48+
sub.l LEN, #1, LEN
49+
repeat LEN
50+
mov.b [TBLOFFSET++], [DSTOFFSET++]
51+
add.l TBLOFFSET, #3, TBLOFFSET
52+
and1.l TBLOFFSET, #0x7C, TBLOFFSET
53+
54+
4:
55+
sub.l [TBLOFFSET++], #0, DSTOFFSET
56+
bra nz, 1b
57+
return

arch/dspic/core/irq_manage.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright (c) 2025, Microchip Technology Inc.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#include <zephyr/kernel.h>
7+
#include <kswap.h>
8+
9+
void z_irq_spurious(const void *unused)
10+
{
11+
(void)unused;
12+
}
13+
14+
void arch_irq_enable(unsigned int irq)
15+
{
16+
(void)irq;
17+
}
18+
19+
int arch_irq_is_enabled(unsigned int irq)
20+
{
21+
(void)irq;
22+
return 0;
23+
}
24+
25+
void arch_irq_disable(unsigned int irq)
26+
{
27+
(void)irq;
28+
}

arch/dspic/core/isr_wrapper.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright (c) 2025, Microchip Technology Inc.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#include <zephyr/kernel.h>
7+
#include <zephyr/irq.h>
8+
#include <zephyr/pm/pm.h>
9+
#include <zephyr/sw_isr_table.h>
10+
#include <kernel_arch_func.h>
11+
12+
/* dsPIC33A interrtup exit routine. Will check if a context
13+
* switch is required. If so, z_dspic_do_swap() will be called
14+
* to affect the context switch
15+
*/
16+
void __attribute__((naked)) z_dspic_exc_exit(void)
17+
{
18+
}
19+
20+
void __attribute__((interrupt, naked)) _COMMONInterrupt(void)
21+
{
22+
}

0 commit comments

Comments
 (0)