pure sdk for main

This commit is contained in:
divadiow
2025-08-27 09:51:58 +01:00
parent f0d033f1c9
commit 0571416e7c
3283 changed files with 1577720 additions and 1 deletions
@@ -0,0 +1,59 @@
/*
* Copyright (C) 2016 YunOS Project. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <k_api.h>
#include "csi_core.h"
void *cpu_task_stack_init(cpu_stack_t *stack_base, size_t stack_size,
void *arg, task_entry_t entry)
{
cpu_stack_t *stk;
uint32_t temp = (uint32_t)(stack_base + stack_size);
temp &= 0xfffffffc;
stk = (cpu_stack_t *)temp;
*(--stk) = (uint32_t)0x28282828L; /* R28 */
*(--stk) = (uint32_t)entry; /* entry point */
*(--stk) = (uint32_t)0x80000140L; /* PSR */
*(--stk) = (uint32_t)krhino_task_deathbed; /* R15 (LR) */
*(--stk) = (uint32_t)0x13131313L; /* R13 */
*(--stk) = (uint32_t)0x12121212L; /* R12 */
*(--stk) = (uint32_t)0x11111111L; /* R11 */
*(--stk) = (uint32_t)0x10101010L; /* R10 */
*(--stk) = (uint32_t)0x09090909L; /* R9 */
*(--stk) = (uint32_t)0x00000000L; /* R8 */
*(--stk) = (uint32_t)0x07070707L; /* R7 */
*(--stk) = (uint32_t)0x06060606L; /* R6 */
*(--stk) = (uint32_t)0x05050505L; /* R5 */
*(--stk) = (uint32_t)0x04040404L; /* R4 */
*(--stk) = (uint32_t)0x03030303L; /* R3 */
*(--stk) = (uint32_t)0x02020202L; /* R2 */
*(--stk) = (uint32_t)0x01010101L; /* R1 */
*(--stk) = (uint32_t)arg; /* R0 : argument */
return stk;
}
uint32_t cpu_cycle_diff(uint8_t sub, uint32_t last_cycle)
{
uint32_t cycle = csi_coret_get_value();
if (sub) {
return (last_cycle > cycle) ? (last_cycle - cycle) : (csi_coret_get_load() - cycle + last_cycle);
} else {
return cycle;
}
}
@@ -0,0 +1,180 @@
/*
* Copyright (C) 2016 YunOS Project. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <k_config.h>
#define VIC_TSPDR 0XE000EC08
.extern g_active_task
.extern g_preferred_ready_task
.extern krhino_task_sched_stats_get
.extern krhino_stack_ovf_check
/******************************************************************************
* EXPORT FUNCTIONS
******************************************************************************/
.global cpu_intrpt_save
.global cpu_intrpt_restore
.global cpu_task_switch
.global cpu_intrpt_switch
.global cpu_first_task_start
.global tspend_handler
/******************************************************************************
* EQUATES
******************************************************************************/
/******************************************************************************
* CODE GENERATION DIRECTIVES
******************************************************************************/
.text
.align 2
/******************************************************************************
* Functions:
* size_t cpu_intrpt_save(void);
* void cpu_intrpt_restore(size_t psr);
******************************************************************************/
.type cpu_intrpt_save, %function
cpu_intrpt_save:
mfcr r0, psr
psrclr ie
rts
.type cpu_intrpt_restore, %function
cpu_intrpt_restore:
mtcr r0, psr
btsti r0, 6
bf .Lret
lrw r1, 0x00ff0000
and r1, r0
cmpnei r1, 0
bt .Lret
lrw r1, VIC_TSPDR
.Lloop:
ldw r2, (r1)
btsti r2, 0
bt .Lloop
.Lret:
rts
/******************************************************************************
* Functions:
* void cpu_intrpt_switch(void);
* void cpu_task_switch(void);
******************************************************************************/
.type cpu_task_switch, %function
cpu_task_switch:
lrw r0, VIC_TSPDR
bgeni r1, 0
stw r1, (r0)
rts
.type cpu_intrpt_switch, %function
cpu_intrpt_switch:
lrw r0, VIC_TSPDR
bgeni r1, 0
stw r1, (r0)
rts
/******************************************************************************
* Functions:
* void cpu_first_task_start(void);
******************************************************************************/
.type cpu_first_task_start, %function
cpu_first_task_start:
psrclr ie
jbr __tspend_handler_nosave
/******************************************************************************
* Functions:
* void __task_switch(void);
******************************************************************************/
.type tspend_handler, %function
tspend_handler:
#ifdef __CK803__
subi sp, 72
#else
subi sp, 68
#endif
stm r0-r13, (sp)
stw r15, (sp, 56)
mfcr r0, epsr
stw r0, (sp, 60)
mfcr r0, epc
stw r0, (sp, 64)
#ifdef __CK803__
stw r28, (sp, 68)
#endif
lrw r0, g_sched_lock
ldb r1, (r0)
cmpnei r1, 0
bt .Lnot_switch
lrw r2, g_active_task
ldw r2, (r2)
stw sp, (r2)
#if (RHINO_CONFIG_TASK_STACK_OVF_CHECK > 0)
jbsr krhino_stack_ovf_check
#endif
#if (RHINO_CONFIG_TASK_SCHED_STATS > 0)
jbsr krhino_task_sched_stats_get
#endif
__tspend_handler_nosave:
lrw r4, g_active_task
lrw r5, g_preferred_ready_task
ldw r6, (r5)
stw r6, (r4)
#ifdef CONFIG_STACK_GUARD
jbsr csky_set_stackbound
#endif
ldw sp, (r6)
#ifdef CONFIG_STACK_GUARD
mfcr r3, cr<0, 4>
bseti r3, 0
bseti r3, 1
mtcr r3, cr<0, 4>
#endif
.Lnot_switch:
#ifdef __CK803__
ldw r28, (sp, 68)
#endif
ldw r0, (sp, 64)
mtcr r0, epc
ldw r0, (sp, 60)
mtcr r0, epsr
ldw r15, (sp, 56)
ldm r0-r13, (sp)
#ifdef __CK803__
addi sp, 72
#else
addi sp, 68
#endif
rte
@@ -0,0 +1,93 @@
/*
* Copyright (C) 2016 YunOS Project. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <k_api.h>
#include <k_config.h>
#if (RHINO_CONFIG_STACK_OVF_CHECK_HW != 0)
void cpu_intrpt_stack_protect(void)
{
}
void task_stack_crash_warning(void)
{
printf("****The task stack base has been broken !!!****\n");
}
void cpu_task_stack_protect(cpu_stack_t *base, size_t size)
{
uint32_t base_addr = (uint32_t)base;
int num_return = wp_register(base_addr, AWATCH, task_stack_crash_warning);
if (num_return == 1) {
wp_enable(1);
} else if (num_return == 2 || num_return == -1) {
wp_unregister(1);
int number_tmp = wp_register(base_addr, AWATCH, task_stack_crash_warning);
if (number_tmp == 1){
wp_enable(1);
}
}
}
#endif
#ifdef CONFIG_STACK_GUARD
void csky_set_stackbound(void)
{
uint32_t size;
cpu_stack_t *base;
ktask_t *get_task = (ktask_t *)g_active_task;
base = get_task->task_stack_base;
size = get_task->stack_size;
asm volatile(
"mfcr r9, cr<0, 4>\n\r"
"bclri r9, 0\n\r"
"mtcr r9, cr<0, 4>\n\r"
"mtcr %0, cr<2, 4>\n\r"
"lsli %1, %1, 2\n\r"
"add %0, %0, %1\n\r"
"mtcr %0, cr<1, 4>\n\r"
::"r"(base), "r"(size):"r9");
}
int stack_guard_save(void)
{
int value;
asm volatile(
"mfcr %0, cr<0, 4>\n\t"
"mov r0, %0\n\t"
"bclri r0, 0\n\t"
"mtcr r0, cr<0, 4>\n\t"
:"=r"(value)
::"r0");
return value;
}
void stack_guard_restore(int value)
{
asm volatile(
"mtcr %0, cr<0, 4>\n\t"
::"r"(value):
);
}
#endif
@@ -0,0 +1,92 @@
/*
* Copyright (C) 2016 YunOS Project. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <k_api.h>
#undef PSR_SP
#define PSR_SP (1UL << 29)
static ktask_t *tee_caller_task = NULL;
static inline uint32_t getcurrentpsr(void)
{
uint32_t flags;
__asm__ __volatile__(
"mfcr %0, psr \n"
:"=r"(flags)
:
:
);
return flags;
}
static inline void clear_psr_sp(void)
{
__asm__ __volatile__ (
"mfcr r0, psr \n"
"bclri r0, 29 \n"
"mtcr r0, psr \n"
:
:
:"r0"
);
}
static inline void set_psr_sp(void)
{
__asm__ __volatile__ (
"mfcr r0, psr \n"
"bseti r0, 29 \n"
"mtcr r0, psr \n"
:
:
:"r0"
);
}
void csky_get_tee_caller_task(void)
{
uint32_t temp_psr;
temp_psr = getcurrentpsr();
if (temp_psr & PSR_SP) {
tee_caller_task = (tee_caller_task == NULL) ? g_active_task[cpu_cur_get()] : tee_caller_task;
}
}
void csky_deal_tee_caller_task(void)
{
uint32_t temp_psr;
temp_psr = getcurrentpsr();
if (temp_psr & PSR_SP) {
if (tee_caller_task != NULL) {
if (tee_caller_task == g_active_task[cpu_cur_get()]) {
tee_caller_task = NULL;
} else {
clear_psr_sp();
}
}
} else {
if (tee_caller_task != NULL) {
if (tee_caller_task == g_active_task[cpu_cur_get()]) {
tee_caller_task = NULL;
set_psr_sp();
}
}
}
}
@@ -0,0 +1,111 @@
/*
* Copyright (C) 2016 YunOS Project. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <csi_config.h>
#ifdef CONFIG_BACKTRACE
#include <stdio.h>
#include <stdlib.h>
#include <backtrace.h>
#define BT_SIZE 40
void *g_bt_buffer[BT_SIZE];
#define BT_STACK_SIZE 600
int g_bt_stack[BT_STACK_SIZE / 4];
char *g_dumpbuf = NULL;
int g_dump_len = 0;
int g_dump_max = 0;
void dump_backtrace(void)
{
int i;
int nptr;
g_dump_len = 0;
nptr = backtrace(g_bt_buffer, BT_SIZE);
if (nptr <= 0) {
printf("error: backtrace_symbols\n");
return;
}
for (i = 0; i < nptr; i++) {
if (g_dumpbuf == NULL) {
printf("[<%p>]\n", g_bt_buffer[i]);
} else {
g_dump_len += snprintf(&g_dumpbuf[g_dump_len], g_dump_max - g_dump_len, "[<%p>]\n", g_bt_buffer[i]);
if (g_dump_len >= g_dump_max) {
printf("error, user buffer no space \n");
return;
}
}
}
}
void __attribute__((naked))csky_show_backtrace(void *stack)
{
asm volatile(
"subi sp, 68\n\t"
"stm r0-r13, (sp)\n\t"
"mtcr sp, cr<14, 1>\n\t"
"stw r15, (sp, 56)\n\t"
"mov sp, %0\n\t"
"lrw r0, g_bt_stack\n\t"
"mov r1, sp\n\t"
"sub r1, %1\n\t"
"mov r2, %1\n\t"
"mov r4, %1\n\t"
"jbsr memcpy\n\t"
"ldw r8, (sp, 32)\n\t"
"ldw r15, (sp, 64)\n\t"
"subi sp, 16\n\t"
"stw r8, (sp, 0)\n\t"
"stw r15, (sp, 4)\n\t"
"mov r8, sp\n\t"
"jbsr dump_backtrace\n\t"
"addi sp, 16\n\t"
"lrw r1, g_bt_stack\n\t"
"mov r0, sp\n\t"
"sub r0, r4\n\t"
"mov r2, r4\n\t"
"jbsr memcpy\n\t"
"mfcr sp, cr<14, 1>\n\t"
"ldw r15, (sp, 56)\n\t"
"ldm r0-r13, (sp)\n\t"
"addi sp, 68\n\t"
"jmp r15\n\t"
::"r"(stack), "r"(BT_STACK_SIZE):);
}
int csky_task_backtrace(void *stack, void *buf, int len)
{
g_dumpbuf = buf;
g_dump_max = len;
csky_show_backtrace(stack);
return g_dump_len;
}
#endif
@@ -0,0 +1,49 @@
/*
* Copyright (C) 2016 YunOS Project. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <k_api.h>
void *cpu_task_stack_init(cpu_stack_t *stack_base, size_t stack_size,
void *arg, task_entry_t entry)
{
cpu_stack_t *stk;
uint32_t temp = (uint32_t)(stack_base + stack_size);
temp &= 0xfffffffc;
stk = (cpu_stack_t *)temp;
*(--stk) = (uint32_t)entry; /* entry point */
*(--stk) = (uint32_t)0x80000140L; /* PSR */
*(--stk) = (uint32_t)krhino_task_deathbed; /* R15 (LR) */
*(--stk) = (uint32_t)0x13131313L; /* R13 */
*(--stk) = (uint32_t)0x12121212L; /* R12 */
*(--stk) = (uint32_t)0x11111111L; /* R11 */
*(--stk) = (uint32_t)0x10101010L; /* R10 */
*(--stk) = (uint32_t)0x09090909L; /* R9 */
*(--stk) = (uint32_t)0x00000000L; /* R8 */
*(--stk) = (uint32_t)0x07070707L; /* R7 */
*(--stk) = (uint32_t)0x06060606L; /* R6 */
*(--stk) = (uint32_t)0x05050505L; /* R5 */
*(--stk) = (uint32_t)0x04040404L; /* R4 */
*(--stk) = (uint32_t)0x03030303L; /* R3 */
*(--stk) = (uint32_t)0x02020202L; /* R2 */
*(--stk) = (uint32_t)0x01010101L; /* R1 */
*(--stk) = (uint32_t)arg; /* R0 : argument */
return stk;
}
@@ -0,0 +1,180 @@
/*
* Copyright (C) 2016 YunOS Project. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <k_config.h>
#define VIC_TSPDR 0XE000EC08
.extern g_active_task
.extern g_preferred_ready_task
.extern krhino_task_sched_stats_get
.extern krhino_stack_ovf_check
/******************************************************************************
* EXPORT FUNCTIONS
******************************************************************************/
.global cpu_intrpt_save
.global cpu_intrpt_restore
.global cpu_task_switch
.global cpu_intrpt_switch
.global cpu_first_task_start
.global tspend_handler
/******************************************************************************
* EQUATES
******************************************************************************/
/******************************************************************************
* CODE GENERATION DIRECTIVES
******************************************************************************/
.text
.align 2
/******************************************************************************
* Functions:
* size_t cpu_intrpt_save(void);
* void cpu_intrpt_restore(size_t psr);
******************************************************************************/
.type cpu_intrpt_save, %function
cpu_intrpt_save:
mfcr r0, psr
psrclr ie
rts
.type cpu_intrpt_restore, %function
cpu_intrpt_restore:
mtcr r0, psr
btsti r0, 6
bf .Lret
lrw r1, 0x00ff0000
and r1, r0
cmpnei r1, 0
bt .Lret
lrw r1, VIC_TSPDR
.Lloop:
ldw r2, (r1)
btsti r2, 0
bt .Lloop
.Lret:
rts
/******************************************************************************
* Functions:
* void cpu_intrpt_switch(void);
* void cpu_task_switch(void);
******************************************************************************/
.type cpu_task_switch, %function
cpu_task_switch:
lrw r0, VIC_TSPDR
bgeni r1, 0
stw r1, (r0)
rts
.type cpu_intrpt_switch, %function
cpu_intrpt_switch:
lrw r0, VIC_TSPDR
bgeni r1, 0
stw r1, (r0)
rts
/******************************************************************************
* Functions:
* void cpu_first_task_start(void);
******************************************************************************/
.type cpu_first_task_start, %function
cpu_first_task_start:
psrclr ie
jbr __tspend_handler_nosave
/******************************************************************************
* Functions:
* void __task_switch(void);
******************************************************************************/
.type tspend_handler, %function
tspend_handler:
#ifdef __CK803__
subi sp, 72
#else
subi sp, 68
#endif
stm r0-r13, (sp)
stw r15, (sp, 56)
mfcr r0, epsr
stw r0, (sp, 60)
mfcr r0, epc
stw r0, (sp, 64)
#ifdef __CK803__
stw r28, (sp, 68)
#endif
lrw r0, g_sched_lock
ldb r1, (r0)
cmpnei r1, 0
bt .Lnot_switch
lrw r2, g_active_task
ldw r2, (r2)
stw sp, (r2)
#if (RHINO_CONFIG_TASK_STACK_OVF_CHECK > 0)
jbsr krhino_stack_ovf_check
#endif
#if (RHINO_CONFIG_TASK_SCHED_STATS > 0)
jbsr krhino_task_sched_stats_get
#endif
__tspend_handler_nosave:
lrw r4, g_active_task
lrw r5, g_preferred_ready_task
ldw r6, (r5)
stw r6, (r4)
#ifdef CONFIG_STACK_GUARD
jbsr csky_set_stackbound
#endif
ldw sp, (r6)
#ifdef CONFIG_STACK_GUARD
mfcr r3, cr<0, 4>
bseti r3, 0
bseti r3, 1
mtcr r3, cr<0, 4>
#endif
.Lnot_switch:
#ifdef __CK803__
ldw r28, (sp, 68)
#endif
ldw r0, (sp, 64)
mtcr r0, epc
ldw r0, (sp, 60)
mtcr r0, epsr
ldw r15, (sp, 56)
ldm r0-r13, (sp)
#ifdef __CK803__
addi sp, 72
#else
addi sp, 68
#endif
rte
@@ -0,0 +1,81 @@
/*
* Copyright (C) 2016 YunOS Project. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <k_api.h>
void *cpu_task_stack_init(cpu_stack_t *stack_base, size_t stack_size,
void *arg, task_entry_t entry)
{
cpu_stack_t *stk;
uint32_t temp = (uint32_t)(stack_base + stack_size);
temp &= 0xFFFFFFFCUL;
stk = (cpu_stack_t *)temp;
*(--stk) = (uint32_t)entry; /* Entry Point */
*(--stk) = (uint32_t)0x80000140L; /* PSR */
*(--stk) = (uint32_t)0x12345678L; /* VR15 */
*(--stk) = (uint32_t)0x12345678L; /* VR14 */
*(--stk) = (uint32_t)0x12345678L; /* VR13 */
*(--stk) = (uint32_t)0x12345678L; /* VR12 */
*(--stk) = (uint32_t)0x12345678L; /* VR11 */
*(--stk) = (uint32_t)0x12345678L; /* VR10 */
*(--stk) = (uint32_t)0x12345678L; /* VR9 */
*(--stk) = (uint32_t)0x12345678L; /* VR8 */
*(--stk) = (uint32_t)0x12345678L; /* VR7 */
*(--stk) = (uint32_t)0x12345678L; /* VR6 */
*(--stk) = (uint32_t)0x12345678L; /* VR5 */
*(--stk) = (uint32_t)0x12345678L; /* VR4 */
*(--stk) = (uint32_t)0x12345678L; /* VR3 */
*(--stk) = (uint32_t)0x12345678L; /* VR2 */
*(--stk) = (uint32_t)0x12345678L; /* VR1 */
*(--stk) = (uint32_t)0x12345678L; /* VR0 */
*(--stk) = (uint32_t)0x31313131L; /* R31 */
*(--stk) = (uint32_t)0x30303030L; /* R30 */
*(--stk) = (uint32_t)0x29292929L; /* R29 */
*(--stk) = (uint32_t)0x28282828L; /* R28 */
*(--stk) = (uint32_t)0x27272727L; /* R27 */
*(--stk) = (uint32_t)0x26262626L; /* R26 */
*(--stk) = (uint32_t)0x25252525L; /* R25 */
*(--stk) = (uint32_t)0x24242424L; /* R24 */
*(--stk) = (uint32_t)0x23232323L; /* R23 */
*(--stk) = (uint32_t)0x22222222L; /* R22 */
*(--stk) = (uint32_t)0x21212121L; /* R21 */
*(--stk) = (uint32_t)0x20202020L; /* R20 */
*(--stk) = (uint32_t)0x19191919L; /* R19 */
*(--stk) = (uint32_t)0x18181818L; /* R18 */
*(--stk) = (uint32_t)0x17171717L; /* R17 */
*(--stk) = (uint32_t)0x16161616L; /* R16 */
*(--stk) = (uint32_t)krhino_task_deathbed; /* R15 (LR) */
*(--stk) = (uint32_t)0x13131313L; /* R13 */
*(--stk) = (uint32_t)0x12121212L; /* R12 */
*(--stk) = (uint32_t)0x11111111L; /* R11 */
*(--stk) = (uint32_t)0x10101010L; /* R10 */
*(--stk) = (uint32_t)0x09090909L; /* R9 */
*(--stk) = (uint32_t)0x00000000L; /* R8 */
*(--stk) = (uint32_t)0x07070707L; /* R7 */
*(--stk) = (uint32_t)0x06060606L; /* R6 */
*(--stk) = (uint32_t)0x05050505L; /* R5 */
*(--stk) = (uint32_t)0x04040404L; /* R4 */
*(--stk) = (uint32_t)0x03030303L; /* R3 */
*(--stk) = (uint32_t)0x02020202L; /* R2 */
*(--stk) = (uint32_t)0x01010101L; /* R1 */
*(--stk) = (uint32_t)arg; /* R0 : Argument */
return stk;
}
@@ -0,0 +1,157 @@
/*
* Copyright (C) 2016 YunOS Project. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <k_config.h>
#define VIC_TSPDR 0XE000EC08
.extern g_active_task
.extern g_preferred_ready_task
.extern krhino_task_sched_stats_get
.extern krhino_stack_ovf_check
/******************************************************************************
* EXPORT FUNCTIONS
******************************************************************************/
.global cpu_intrpt_save
.global cpu_intrpt_restore
.global cpu_task_switch
.global cpu_intrpt_switch
.global cpu_first_task_start
.global tspend_handler
/******************************************************************************
* EQUATES
******************************************************************************/
/******************************************************************************
* CODE GENERATION DIRECTIVES
******************************************************************************/
.text
.align 2
/******************************************************************************
* Functions:
* size_t cpu_intrpt_save(void);
* void cpu_intrpt_restore(size_t psr);
******************************************************************************/
.type cpu_intrpt_save, %function
cpu_intrpt_save:
mfcr r0, psr
psrclr ie
rts
.type cpu_intrpt_restore, %function
cpu_intrpt_restore:
mtcr r0, psr
rts
/******************************************************************************
* Functions:
* void cpu_intrpt_switch(void);
* void cpu_task_switch(void);
******************************************************************************/
.type cpu_task_switch, %function
cpu_task_switch:
lrw r0, VIC_TSPDR
bgeni r1, 0
stw r1, (r0)
rts
.type cpu_intrpt_switch, %function
cpu_intrpt_switch:
lrw r0, VIC_TSPDR
bgeni r1, 0
stw r1, (r0)
rts
/******************************************************************************
* Functions:
* void cpu_first_task_start(void);
******************************************************************************/
.type cpu_first_task_start, %function
cpu_first_task_start:
psrclr ie
jbr __tspend_handler_nosave
/******************************************************************************
* Functions:
* void __task_switch(void);
******************************************************************************/
.type tspend_handler, %function
tspend_handler:
subi sp, 196
stm r0-r13, (sp)
stw r15, (sp, 56)
addi r0, sp, 60
stm r16-r31, (r0)
addi r0, 64
fstms vr0-vr15, (r0)
mfcr r1, epsr
stw r1, (r0, 64)
mfcr r1, epc
stw r1, (r0, 68)
lrw r2, g_active_task
ldw r2, (r2)
stw sp, (r2)
#if (RHINO_CONFIG_TASK_STACK_OVF_CHECK > 0)
jbsr krhino_stack_ovf_check
#endif
#if (RHINO_CONFIG_TASK_SCHED_STATS > 0)
jbsr krhino_task_sched_stats_get
#endif
__tspend_handler_nosave:
lrw r4, g_active_task
lrw r5, g_preferred_ready_task
ldw r6, (r5)
stw r6, (r4)
#ifdef CONFIG_STACK_GUARD
jbsr csky_set_stackbound
#endif
ldw sp, (r6)
#ifdef CONFIG_STACK_GUARD
mfcr r3, cr<0, 4>
bseti r3, 0
bseti r3, 1
mtcr r3, cr<0, 4>
#endif
ldw r0, (sp, 192)
mtcr r0, epc
ldw r0, (sp, 188)
mtcr r0, epsr
ldm r0-r13, (sp)
ldw r15, (sp, 56)
addi sp, 60
ldm r16-r31, (sp)
addi sp, 64
fldms vr0-vr15, (sp)
addi sp, 72
rte
@@ -0,0 +1,153 @@
/*
* Copyright (C) 2016 YunOS Project. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef CONFIG_H
#define CONFIG_H
#include <csi_config.h>
#if defined (__CSKY_DSP__) || defined(__CSKY_DSPV2__) || defined(__CSKY_VDSPV2__) || defined (__CSKY_HARD_FLOAT__) || defined(__C807__)
#define CSK_CPU_STACK_EXTRAL 68
#elif defined (__I805__)
#define CSK_CPU_STACK_EXTRAL 260
#else
#define CSK_CPU_STACK_EXTRAL 0
#endif
#define RHINO_CONFIG_STD_MALLOC 1
#define K_MM_STATISTIC 1
/* chip level conf */
#define RHINO_CONFIG_LITTLE_ENDIAN 1
#define RHINO_CONFIG_CPU_STACK_DOWN 1
/* kernel feature conf */
#define RHINO_CONFIG_SEM 1
#define RHINO_CONFIG_QUEUE 1
#define RHINO_CONFIG_TASK_SEM 1
#define RHINO_CONFIG_EVENT_FLAG 1
#define RHINO_CONFIG_TIMER 1
#define RHINO_CONFIG_BUF_QUEUE 1
#define RHINO_CONFIG_MM_BLK 1
#define RHINO_CONFIG_MM_TLF_BLK_SIZE 4096
#ifdef CONFIG_DEBUG_MM
#define RHINO_CONFIG_MM_DEBUG 1
#define RHINO_CONFIG_GCC_RETADDR 1
#else
#define RHINO_CONFIG_MM_DEBUG 0
#define RHINO_CONFIG_GCC_RETADDR 0
#endif
#define RHINO_CONFIG_KOBJ_SET 1
#define RHINO_CONFIG_RINGBUF_VENDOR 0
/* kernel dynamic tick conf */
#ifdef CONFIG_KERNEL_PWR_MGMT
#define RHINO_CONFIG_CPU_PWR_MGMT 1
#else
#define RHINO_CONFIG_CPU_PWR_MGMT 0
#endif
/*
#define RHINO_CONFIG_TICKS_PER_SECOND 100
#define RHINO_CONFIG_TICK_HEAD_ARRAY 1
#define RHINO_CONFIG_SCHED_RR 0
#define RHINO_CONFIG_TIMER_RATE 1
#define RHINO_CONFIG_TIMER 1
*/
/* kernel task conf */
#define RHINO_CONFIG_TASK_SUSPEND 1
#define RHINO_CONFIG_TASK_INFO 0
#define RHINO_CONFIG_TASK_DEL 1
#define RHINO_CONFIG_TASK_WAIT_ABORT 0
#define RHINO_CONFIG_TASK_STACK_OVF_CHECK 1
#define RHINO_CONFIG_SCHED_RR 1
#define RHINO_CONFIG_TIME_SLICE_DEFAULT 5
#define RHINO_CONFIG_PRI_MAX 62
#define RHINO_CONFIG_USER_PRI_MAX (RHINO_CONFIG_PRI_MAX - 2)
#define RHINO_CONFIG_MM_REGION_MUTEX 0
/* kernel workqueue conf */
#ifdef CONFIG_KERNEL_WORKQUEUE
#define RHINO_CONFIG_WORKQUEUE 1
#else
#define RHINO_CONFIG_WORKQUEUE 0
#endif
/* kernel timer&tick conf */
#define RHINO_CONFIG_HW_COUNT 0
#define RHINO_CONFIG_TICK_TASK 1
#if (RHINO_CONFIG_TICK_TASK > 0)
#define RHINO_CONFIG_TICK_TASK_STACK_SIZE (50 + CSK_CPU_STACK_EXTRAL)
#define RHINO_CONFIG_TICK_TASK_PRI 1
#endif
#ifdef CONFIG_SYSTICK_HZ
#define RHINO_CONFIG_TICKS_PER_SECOND CONFIG_SYSTICK_HZ
#else
#define RHINO_CONFIG_TICKS_PER_SECOND 100
#endif
/* must be 2^n size!, such as 1, 2, 4, 8, 16,32, etc....... */
#define RHINO_CONFIG_TICK_HEAD_ARRAY 1
#ifdef CONFIG_TIMER_TASK_STACK_SIZE
#define RHINO_CONFIG_TIMER_TASK_STACK_SIZE (CONFIG_TIMER_TASK_STACK_SIZE + CSK_CPU_STACK_EXTRAL)
#else
#define RHINO_CONFIG_TIMER_TASK_STACK_SIZE (200 + CSK_CPU_STACK_EXTRAL)
#endif
#define RHINO_CONFIG_TIMER_RATE 1
#define RHINO_CONFIG_TIMER_TASK_PRI 5
/* kernel intrpt conf */
#define RHINO_CONFIG_INTRPT_STACK_REMAIN_GET 1
#define RHINO_CONFIG_INTRPT_STACK_OVF_CHECK 0
#define RHINO_CONFIG_INTRPT_MAX_NESTED_LEVEL 188u
#define RHINO_CONFIG_INTRPT_GUARD 0
#define RHINO_CONFIG_STACK_OVF_CHECK_HW 0
#define RHINO_CONFIG_KOBJ_DYN_ALLOC 1
#if (RHINO_CONFIG_KOBJ_DYN_ALLOC > 0)
#define RHINO_CONFIG_K_DYN_QUEUE_MSG 30
#define RHINO_CONFIG_K_DYN_TASK_STACK (64 + CSK_CPU_STACK_EXTRAL)
#define RHINO_CONFIG_K_DYN_MEM_TASK_PRI RHINO_CONFIG_USER_PRI_MAX
#endif
/* kernel idle conf */
#ifdef CONFIG_IDLE_TASK_STACK_SIZE
#define RHINO_CONFIG_IDLE_TASK_STACK_SIZE CONFIG_IDLE_TASK_STACK_SIZE
#else
#define RHINO_CONFIG_IDLE_TASK_STACK_SIZE (256 + CSK_CPU_STACK_EXTRAL)
#endif
/* kernel hook conf */
#define RHINO_CONFIG_USER_HOOK 0
/* kernel stats conf */
#define RHINO_CONFIG_SYSTEM_STATS 1
#define RHINO_CONFIG_DISABLE_SCHED_STATS 0
#define RHINO_CONFIG_DISABLE_INTRPT_STATS 0
#define RHINO_CONFIG_CPU_USAGE_STATS 0
#define RHINO_CONFIG_CPU_USAGE_TASK_PRI (RHINO_CONFIG_PRI_MAX - 2)
#define RHINO_CONFIG_TASK_SCHED_STATS 0
#define RHINO_CONFIG_CPU_USAGE_TASK_STACK (50 + CSK_CPU_STACK_EXTRAL)
#endif /* CONFIG_H */
@@ -0,0 +1,51 @@
/*
* Copyright (C) 2016 YunOS Project. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef TYPES_H
#define TYPES_H
#define RHINO_NO_WAIT 0u
//#define RHINO_WAIT_FOREVER 0xffffffffu /* 32 bit value, if tick type is 64 bit, you need change it to 64 bit */
#define RHINO_TASK_STACK_OVF_MAGIC 0xdeadbeafu /* 32 bit or 64 bit stack overflow magic value */
#define RHINO_INTRPT_STACK_OVF_MAGIC 0xdeaddeadu /* 32 bit or 64 bit stack overflow magic value */
#define RHINO_MM_FRAG_ALLOCATED 0xabcddcabu /* 32 bit value, if 64 bit system, you need change it to 64 bit */
#define RHINO_MM_FRAG_FREE 0xfefdecdbu /* 32 bit value, if 64 bit system, you need change it to 64 bit */
#define RHINO_INLINE static __inline /* inline keyword, it may change under different compilers */
#define RHINO_MM_CORRUPT_DYE 0xFEFEFEFE
#define RHINO_MM_FREE_DYE 0xABABABAB
typedef char name_t;
typedef uint32_t sem_count_t;
typedef uint32_t cpu_stack_t;
typedef uint32_t cpu_cpsr_t;
/* you may change here depend on your hardware timer */
typedef uint32_t hr_timer_t; /* 32 bit or 64 bit unsigned value */
typedef uint32_t lr_timer_t; /* 32 bit or 64 bit unsigned value */
//typedef uint64_t tick_t; /* 32 bit or 64 bit unsigned value */
//typedef uint64_t idle_count_t; /* 64 bit unsigned value */
//typedef uint64_t sys_time_t; /* 64 bit unsigned value */
typedef uint32_t mutex_nested_t; /* 8 bit or 16bit or 32bit unsigned value */
typedef uint8_t suspend_nested_t; /* 8 bit normally */
typedef uint64_t ctx_switch_t; /* 32 bit or 64 bit unsigned value */
//typedef int32_t ssize_t;
#endif /* TYPES_H */
+43
View File
@@ -0,0 +1,43 @@
/*
* Copyright (C) 2016 YunOS Project. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef PORT_H
#define PORT_H
#include <k_types.h>
#include <k_task.h>
size_t cpu_intrpt_save(void);
void cpu_intrpt_restore(size_t psr);
void cpu_intrpt_switch(void);
void cpu_task_switch(void);
void cpu_first_task_start(void);
void *cpu_task_stack_init(cpu_stack_t *base, size_t size,
void *arg, task_entry_t entry);
RHINO_INLINE uint8_t cpu_cur_get(void)
{
return 0;
}
#define CPSR_ALLOC() size_t psr
#define RHINO_CPU_INTRPT_DISABLE() { psr = cpu_intrpt_save(); }
#define RHINO_CPU_INTRPT_ENABLE() { cpu_intrpt_restore(psr); }
#endif /* PORT_H */