Initial commit: TXW82x FPV v2.7.0.7-42229 SDK + project sources
This commit is contained in:
49
csky/csi_kernel/rhino/arch/csky/ck803/port_c.c
Normal file
49
csky/csi_kernel/rhino/arch/csky/ck803/port_c.c
Normal file
@@ -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>
|
||||
#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;
|
||||
}
|
||||
|
||||
180
csky/csi_kernel/rhino/arch/csky/ck803/port_s.S
Normal file
180
csky/csi_kernel/rhino/arch/csky/ck803/port_s.S
Normal file
@@ -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
|
||||
|
||||
93
csky/csi_kernel/rhino/arch/csky/cpu_impl.c
Normal file
93
csky/csi_kernel/rhino/arch/csky/cpu_impl.c
Normal file
@@ -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
|
||||
92
csky/csi_kernel/rhino/arch/csky/csky_sched.c
Normal file
92
csky/csi_kernel/rhino/arch/csky/csky_sched.c
Normal file
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
111
csky/csi_kernel/rhino/arch/csky/dump_backtrace.c
Normal file
111
csky/csi_kernel/rhino/arch/csky/dump_backtrace.c
Normal file
@@ -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
|
||||
49
csky/csi_kernel/rhino/arch/csky/e802/port_c.c
Normal file
49
csky/csi_kernel/rhino/arch/csky/e802/port_c.c
Normal file
@@ -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 <csi_core.h>
|
||||
#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;
|
||||
}
|
||||
|
||||
180
csky/csi_kernel/rhino/arch/csky/e802/port_s.S
Normal file
180
csky/csi_kernel/rhino/arch/csky/e802/port_s.S
Normal file
@@ -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
|
||||
|
||||
66
csky/csi_kernel/rhino/arch/csky/e804d/port_c.c
Normal file
66
csky/csi_kernel/rhino/arch/csky/e804d/port_c.c
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* 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 <core_804.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)0x80000340L; /* PSR */
|
||||
*(--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;
|
||||
}
|
||||
|
||||
153
csky/csi_kernel/rhino/arch/csky/e804d/port_s.S
Normal file
153
csky/csi_kernel/rhino/arch/csky/e804d/port_s.S
Normal file
@@ -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.
|
||||
*/
|
||||
|
||||
#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, 132
|
||||
stm r0-r13, (sp)
|
||||
stw r15, (sp, 56)
|
||||
addi r0, sp, 60
|
||||
stm r16-r31, (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, 128)
|
||||
mtcr r0, epc
|
||||
ldw r0, (sp, 124)
|
||||
mtcr r0, epsr
|
||||
|
||||
ldm r0-r13, (sp)
|
||||
ldw r15, (sp, 56)
|
||||
addi sp, 60
|
||||
ldm r16-r31, (sp)
|
||||
addi sp, 72
|
||||
|
||||
rte
|
||||
82
csky/csi_kernel/rhino/arch/csky/e804df/port_c.c
Normal file
82
csky/csi_kernel/rhino/arch/csky/e804df/port_c.c
Normal file
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* 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 <core_804.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)0x80000340L; /* 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;
|
||||
}
|
||||
|
||||
157
csky/csi_kernel/rhino/arch/csky/e804df/port_s.S
Normal file
157
csky/csi_kernel/rhino/arch/csky/e804df/port_s.S
Normal file
@@ -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
|
||||
166
csky/csi_kernel/rhino/arch/include/k_config.h
Normal file
166
csky/csi_kernel/rhino/arch/include/k_config.h
Normal file
@@ -0,0 +1,166 @@
|
||||
/*
|
||||
* 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 1
|
||||
//#define RHINO_CONFIG_ISR_TASK 1
|
||||
|
||||
/* 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)
|
||||
|
||||
#ifdef RHINO_CONFIG_ISR_TASK
|
||||
#ifndef RHINO_CONFIG_ISR_BUFF_SIZE
|
||||
#define RHINO_CONFIG_ISR_BUFF_SIZE (16)
|
||||
#endif
|
||||
#ifndef RHINO_CONFIG_ISR_TASK_PRI
|
||||
#define RHINO_CONFIG_ISR_TASK_PRI (1)
|
||||
#endif
|
||||
#ifndef RHINO_CONFIG_ISR_TASK_STACK_SIZE
|
||||
#define RHINO_CONFIG_ISR_TASK_STACK_SIZE (1024)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif /* CONFIG_H */
|
||||
|
||||
51
csky/csi_kernel/rhino/arch/include/k_types.h
Normal file
51
csky/csi_kernel/rhino/arch/include/k_types.h
Normal file
@@ -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
csky/csi_kernel/rhino/arch/include/port.h
Normal file
43
csky/csi_kernel/rhino/arch/include/port.h
Normal 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 */
|
||||
|
||||
45
csky/csi_kernel/rhino/arch/riscv/cpu_impl.c
Normal file
45
csky/csi_kernel/rhino/arch/riscv/cpu_impl.c
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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
|
||||
79
csky/csi_kernel/rhino/arch/riscv/csky_sched.c
Normal file
79
csky/csi_kernel/rhino/arch/riscv/csky_sched.c
Normal file
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* 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 = 0;
|
||||
|
||||
__asm__ __volatile__(
|
||||
"ebreak\n" /* TODO */
|
||||
);
|
||||
|
||||
return flags;
|
||||
}
|
||||
|
||||
static inline void clear_psr_sp(void)
|
||||
{
|
||||
__asm__ __volatile__ (
|
||||
"ebreak\n" /* TODO */
|
||||
);
|
||||
}
|
||||
|
||||
static inline void set_psr_sp(void)
|
||||
{
|
||||
__asm__ __volatile__ (
|
||||
"ebreak\n" /* TODO */
|
||||
);
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
64
csky/csi_kernel/rhino/arch/riscv/e906/port_c.c
Normal file
64
csky/csi_kernel/rhino/arch/riscv/e906/port_c.c
Normal file
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* 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;
|
||||
register int *gp asm("x3");
|
||||
uint32_t temp = (uint32_t)(stack_base + stack_size);
|
||||
|
||||
temp &= 0xFFFFFFF8UL;
|
||||
|
||||
stk = (cpu_stack_t *)temp;
|
||||
|
||||
*(--stk) = (uint32_t)entry; /* PC */
|
||||
*(--stk) = (uint32_t)0x31313131L; /* X31 */
|
||||
*(--stk) = (uint32_t)0x30303030L; /* X30 */
|
||||
*(--stk) = (uint32_t)0x29292929L; /* X29 */
|
||||
*(--stk) = (uint32_t)0x28282828L; /* X28 */
|
||||
*(--stk) = (uint32_t)0x27272727L; /* X27 */
|
||||
*(--stk) = (uint32_t)0x26262626L; /* X26 */
|
||||
*(--stk) = (uint32_t)0x25252525L; /* X25 */
|
||||
*(--stk) = (uint32_t)0x24242424L; /* X24 */
|
||||
*(--stk) = (uint32_t)0x23232323L; /* X23 */
|
||||
*(--stk) = (uint32_t)0x22222222L; /* X22 */
|
||||
*(--stk) = (uint32_t)0x21212121L; /* X21 */
|
||||
*(--stk) = (uint32_t)0x20202020L; /* X20 */
|
||||
*(--stk) = (uint32_t)0x19191919L; /* X19 */
|
||||
*(--stk) = (uint32_t)0x18181818L; /* X18 */
|
||||
*(--stk) = (uint32_t)0x17171717L; /* X17 */
|
||||
*(--stk) = (uint32_t)0x16161616L; /* X16 */
|
||||
*(--stk) = (uint32_t)0x15151515L; /* X15 */
|
||||
*(--stk) = (uint32_t)0x14141414L; /* X14 */
|
||||
*(--stk) = (uint32_t)0x13131313L; /* X13 */
|
||||
*(--stk) = (uint32_t)0x12121212L; /* X12 */
|
||||
*(--stk) = (uint32_t)0x11111111L; /* X11 */
|
||||
*(--stk) = (uint32_t)arg; /* X10 */
|
||||
*(--stk) = (uint32_t)0x09090909L; /* X9 */
|
||||
*(--stk) = (uint32_t)0x08080808L; /* X8 */
|
||||
*(--stk) = (uint32_t)0x07070707L; /* X7 */
|
||||
*(--stk) = (uint32_t)0x06060606L; /* X6 */
|
||||
*(--stk) = (uint32_t)0x05050505L; /* X5 */
|
||||
*(--stk) = (uint32_t)0x04040404L; /* X4 */
|
||||
*(--stk) = (uint32_t)gp; /* X3 */
|
||||
*(--stk) = (uint32_t)krhino_task_deathbed; /* X1 */
|
||||
|
||||
return stk;
|
||||
}
|
||||
|
||||
172
csky/csi_kernel/rhino/arch/riscv/e906/port_s.S
Normal file
172
csky/csi_kernel/rhino/arch/riscv/e906/port_s.S
Normal file
@@ -0,0 +1,172 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/* Enable interrupts when returning from the handler */
|
||||
#define MSTATUS_PRV1 0x1880
|
||||
|
||||
/******************************************************************************
|
||||
* Functions:
|
||||
* size_t cpu_intrpt_save(void);
|
||||
* void cpu_intrpt_restore(size_t psr);
|
||||
******************************************************************************/
|
||||
|
||||
.global cpu_intrpt_save
|
||||
.type cpu_intrpt_save, %function
|
||||
cpu_intrpt_save:
|
||||
csrr a0, mstatus
|
||||
csrc mstatus, 8
|
||||
ret
|
||||
|
||||
.global cpu_intrpt_restore
|
||||
.type cpu_intrpt_restore, %function
|
||||
cpu_intrpt_restore:
|
||||
csrw mstatus, a0
|
||||
ret
|
||||
|
||||
/******************************************************************************
|
||||
* Functions:
|
||||
* void cpu_intrpt_switch(void);
|
||||
* void cpu_task_switch(void);
|
||||
******************************************************************************/
|
||||
|
||||
.global cpu_task_switch
|
||||
.type cpu_task_switch, %function
|
||||
cpu_task_switch:
|
||||
li t0, 0xE080100C
|
||||
lb t1, (t0)
|
||||
li t2, 0x01
|
||||
or t1, t1, t2
|
||||
sb t1, (t0)
|
||||
|
||||
ret
|
||||
|
||||
.global cpu_intrpt_switch
|
||||
.type cpu_intrpt_switch, %function
|
||||
cpu_intrpt_switch:
|
||||
li t0, 0xE080100C
|
||||
lb t1, (t0)
|
||||
li t2, 0x01
|
||||
or t1, t1, t2
|
||||
sb t1, (t0)
|
||||
|
||||
ret
|
||||
|
||||
/******************************************************************************
|
||||
* Functions:
|
||||
* void cpu_first_task_start(void);
|
||||
******************************************************************************/
|
||||
.global cpu_first_task_start
|
||||
.type cpu_first_task_start, %function
|
||||
cpu_first_task_start:
|
||||
j __task_switch_nosave
|
||||
|
||||
/******************************************************************************
|
||||
* Functions:
|
||||
* void tspend_handler(void);
|
||||
******************************************************************************/
|
||||
|
||||
.global tspend_handler
|
||||
.type tspend_handler, %function
|
||||
tspend_handler:
|
||||
csrrw sp, mscratch, sp
|
||||
addi sp, sp, -124
|
||||
|
||||
sw x1, 0(sp)
|
||||
sw x3, 4(sp)
|
||||
sw x4, 8(sp)
|
||||
sw x5, 12(sp)
|
||||
sw x6, 16(sp)
|
||||
sw x7, 20(sp)
|
||||
sw x8, 24(sp)
|
||||
sw x9, 28(sp)
|
||||
sw x10, 32(sp)
|
||||
sw x11, 36(sp)
|
||||
sw x12, 40(sp)
|
||||
sw x13, 44(sp)
|
||||
sw x14, 48(sp)
|
||||
sw x15, 52(sp)
|
||||
sw x16, 56(sp)
|
||||
sw x17, 60(sp)
|
||||
sw x18, 64(sp)
|
||||
sw x19, 68(sp)
|
||||
sw x20, 72(sp)
|
||||
sw x21, 76(sp)
|
||||
sw x22, 80(sp)
|
||||
sw x23, 84(sp)
|
||||
sw x24, 88(sp)
|
||||
sw x25, 92(sp)
|
||||
sw x26, 96(sp)
|
||||
sw x27, 100(sp)
|
||||
sw x28, 104(sp)
|
||||
sw x29, 108(sp)
|
||||
sw x30, 112(sp)
|
||||
sw x31, 116(sp)
|
||||
csrr t0, mepc
|
||||
sw t0, 120(sp)
|
||||
|
||||
la a1, g_active_task
|
||||
lw a1, (a1)
|
||||
sw sp, (a1)
|
||||
|
||||
__task_switch_nosave:
|
||||
la a0, g_preferred_ready_task
|
||||
la a1, g_active_task
|
||||
lw a2, (a0)
|
||||
sw a2, (a1)
|
||||
|
||||
lw sp, (a2)
|
||||
|
||||
/* Run in machine mode */
|
||||
li t0, MSTATUS_PRV1
|
||||
csrs mstatus, t0
|
||||
|
||||
lw t0, 120(sp)
|
||||
csrw mepc, t0
|
||||
|
||||
lw x1, 0(sp)
|
||||
lw x3, 4(sp)
|
||||
lw x4, 8(sp)
|
||||
lw x5, 12(sp)
|
||||
lw x6, 16(sp)
|
||||
lw x7, 20(sp)
|
||||
lw x8, 24(sp)
|
||||
lw x9, 28(sp)
|
||||
lw x10, 32(sp)
|
||||
lw x11, 36(sp)
|
||||
lw x12, 40(sp)
|
||||
lw x13, 44(sp)
|
||||
lw x14, 48(sp)
|
||||
lw x15, 52(sp)
|
||||
lw x16, 56(sp)
|
||||
lw x17, 60(sp)
|
||||
lw x18, 64(sp)
|
||||
lw x19, 68(sp)
|
||||
lw x20, 72(sp)
|
||||
lw x21, 76(sp)
|
||||
lw x22, 80(sp)
|
||||
lw x23, 84(sp)
|
||||
lw x24, 88(sp)
|
||||
lw x25, 92(sp)
|
||||
lw x26, 96(sp)
|
||||
lw x27, 100(sp)
|
||||
lw x28, 104(sp)
|
||||
lw x29, 108(sp)
|
||||
lw x30, 112(sp)
|
||||
lw x31, 116(sp)
|
||||
|
||||
addi sp, sp, 124
|
||||
csrrw sp, mscratch, sp
|
||||
mret
|
||||
Reference in New Issue
Block a user