📄 cpu_support.s
字号:
/*
* TOPPERS/OSEK Kernel
* Toyohashi Open Platform for Embedded Real-Time Systems/
* OSEK Kernel
*
* Copyright (C) 2000-2003 by Embedded and Real-Time Systems Laboratory
* Toyohashi Univ. of Technology, JAPAN
* Copyright (C) 2004 by Embedded and Real-Time Systems Laboratory
* Graduate School of Information Science, Nagoya Univ., JAPAN
* Copyright (C) 2006 by Witz Corporation, JAPAN
*
* 忋婰挊嶌尃幰偼丆埲壓偺 (1)乣(4) 偺忦審偐丆Free Software Foundation
* 偵傛偭偰岞昞偝傟偰偄傞 GNU General Public License 偺 Version 2 偵婰
* 弎偝傟偰偄傞忦審傪枮偨偡応崌偵尷傝丆杮僜僼僩僂僃傾乮杮僜僼僩僂僃傾
* 傪夵曄偟偨傕偺傪娷傓丏埲壓摨偠乯傪巊梡丒暋惢丒夵曄丒嵞攝晍乮埲壓丆
* 棙梡偲屇傇乯偡傞偙偲傪柍彏偱嫋戻偡傞丏
* (1) 杮僜僼僩僂僃傾傪僜乕僗僐乕僪偺宍偱棙梡偡傞応崌偵偼丆忋婰偺挊嶌
* 尃昞帵丆偙偺棙梡忦審偍傛傃壓婰偺柍曐徹婯掕偑丆偦偺傑傑偺宍偱僜乕
* 僗僐乕僪拞偵娷傑傟偰偄傞偙偲丏
* (2) 杮僜僼僩僂僃傾傪丆儔僀僽儔儕宍幃側偳丆懠偺僜僼僩僂僃傾奐敪偵巊
* 梡偱偒傞宍偱嵞攝晍偡傞応崌偵偼丆嵞攝晍偵敽偆僪僉儏儊儞僩乮棙梡
* 幰儅僯儏傾儖側偳乯偵丆忋婰偺挊嶌尃昞帵丆偙偺棙梡忦審偍傛傃壓婰
* 偺柍曐徹婯掕傪宖嵹偡傞偙偲丏
* (3) 杮僜僼僩僂僃傾傪丆婡婍偵慻傒崬傓側偳丆懠偺僜僼僩僂僃傾奐敪偵巊
* 梡偱偒側偄宍偱嵞攝晍偡傞応崌偵偼丆師偺偄偢傟偐偺忦審傪枮偨偡偙
* 偲丏
* (a) 嵞攝晍偵敽偆僪僉儏儊儞僩乮棙梡幰儅僯儏傾儖側偳乯偵丆忋婰偺挊
* 嶌尃昞帵丆偙偺棙梡忦審偍傛傃壓婰偺柍曐徹婯掕傪宖嵹偡傞偙偲丏
* (b) 嵞攝晍偺宍懺傪丆暿偵掕傔傞曽朄偵傛偭偰丆TOPPERS僾儘僕僃僋僩偵
* 曬崘偡傞偙偲丏
* (4) 杮僜僼僩僂僃傾偺棙梡偵傛傝捈愙揑傑偨偼娫愙揑偵惗偠傞偄偐側傞懝
* 奞偐傜傕丆忋婰挊嶌尃幰偍傛傃TOPPERS僾儘僕僃僋僩傪柶愑偡傞偙偲丏
*
* 杮僜僼僩僂僃傾偼丆柍曐徹偱採嫙偝傟偰偄傞傕偺偱偁傞丏忋婰挊嶌尃幰偍
* 傛傃TOPPERS僾儘僕僃僋僩偼丆杮僜僼僩僂僃傾偵娭偟偰丆偦偺揔梡壜擻惈傕
* 娷傔偰丆偄偐側傞曐徹傕峴傢側偄丏傑偨丆杮僜僼僩僂僃傾偺棙梡偵傛傝捈
* 愙揑傑偨偼娫愙揑偵惗偠偨偄偐側傞懝奞偵娭偟偰傕丆偦偺愑擟傪晧傢側偄丏
*
* This program is covered by the TOPPERS License as published
* by the TOPPERS PROJECT (http://www.toppers.jp/en/index.html).
*
*/
/* 僾儘僙僢僒埶懚儌僕儏乕儖 傾僙儞僽儕尵岅晹乮AT91SAM7S梡乯 */
/* Processor Dependent Module (for AT91SAM7S)
*
* Copyright (C) 2007 Masaaki Mizuno
* Department of Computing and Information Sciences,
* Kansas State University (masaaki@cis.ksu.edu)
*/
#define _MACRO_ONLY
.extern debug1
.extern debug2
/* 奜晹嶲徠愰尵 */
.extern runtsk
.extern schedtsk
.extern tcxb_pc
.extern tcxb_sp
.extern tinib_task
.extern callevel
.extern runisr
.extern tinib_exepri
.extern tcb_curpri
.extern call_pretaskhook
.extern call_posttaskhook
.extern PreTaskHook
.extern PostTaskHook
.extern lock_flag
.extern __system_stack__
.extern tcxb_lr
.extern tcxb_spsr
/* 奜晹岞奐愰尵 */
.global dispatch
.global start_dispatch
.global exit_and_dispatch
.global activate_r
.global _interrupt
.global dispatch_r
.global disable_int
.global enable_int
.global nop
.global int_return
.text
.code 32
.align 4
/////////////////////////////////////////////////////////////////////////////////////////////////
// dispatch:
// this function is called by a task
// save the non-distructive registers (r4-r11, lr)
// save sp in the sp saving area in TCB
// save "dispatcher_r" in the pc saving area in TCB
// jump to "dispatcher"
/////////////////////////////////////////////////////////////////////////////////////////////////
dispatch:
stmfd sp!, {r4-r11, lr} // save the non-distructive registers
ldr r0, =tcxb_sp // save sp in the sp saving area in TCB
ldr r1, =runtsk
ldrb r1, [r1] // "ldrb" performs zero-extension
str sp, [r0, r1, asl #2] // tcxb_sp[runtsk] = sp
ldr r2, =dispatcher_r // save "dispatcher_r" in the pc saving area in TCB
ldr r0, =tcxb_pc
str r2, [r0, r1, asl #2] // tcxb_pc[runtsk] = "dispatcher_r"
b dispatcher // jump to "dispatcher"
.align 4
////////////////////////////////////////////////////////////////////////////////////////////////
// dispacth_r:
// If a task relinquishes the CPU through "dispatch",
// it executes this function to be dispatched when it is scheduled again.
// restore the non-desctructive registers (r4-r11)
// restore the value of LR (the address to return from "dispatch") in PC
////////////////////////////////////////////////////////////////////////////////////////////////
dispatcher_r:
ldmfd sp!, {r4-r11}
ldmfd sp!, {r0} // the return address is found abovce the destructive registers in the stack
bx r0 //. jump to the address
.align 4
////////////////////////////////////////////////////////////////////////////////////////////////
// activate_r:
// When a task is scheduled and dispatched for the first time, this function is called
// Address "activare_r" is set to the PC saving area in TCB by activate_context( ) in cpu_context.h
// set tinib_exepri[runtsk] to tcb_curpri[runtsk], where runtsk is the ID of the task to be dispatched
// enabe interrupt
// jump to tinib_task[runtsk]
/////////////////////////////////////////////////////////////////////////////////////////////////
activate_r:
ldr r0, =tinib_exepri // tcb_curpri[runtsk] = tinib_exepri[runtsk]
ldr r1, =runtsk
ldrb r1, [r1]
ldrb r0, [r0, r1] // r0 <- tinib_exepri[runtsk]
ldr r2, =tcb_curpri
strb r0, [r2, r1] // tcb_curpri[runtsk] = tinib_exepri[runtsk]
ldr r0, =tinib_task
ldr r0, [r0, r1, asl #2] // r0 <- tinib_task[runtsk], which is the address of the function that the task first executes
msr cpsr, #0x5f // enable interrupt
bx r0 // jump to tinib_task[runtsk]
.align 4
//////////////////////////////////////////////////////////////////////////////////////////////
// exit_and_dispatch:
// this is called from TerminateTask() and ChainTask(), when one task relinquishes CPU
// and another task is scheduled and dispatched
// if (PostTaskHook != 0) PosTaskHook();
// continue on to "start_dispatch"
///////////////////////////////////////////////////////////////////////////////////////////////
exit_and_dispatch:
dispatcher:
ldr r0, =PostTaskHook
cmp r0, #0
beq start_dispatch
bl call_posttaskhook
// fall to start_dispatch
/////////////////////////////////////////////////////////////////////////////////////////////////
// start_dispatch:
// this function is called to dispatch schedtsk (the task that the scheduler has just selected)
// set schedtsk to runtsk
// if (runtsk == INVALID_TASK) jump to "pre_idle"
// restore sp from tcxb_sp[runtsk]
// if (PreTaskHook != 0) call_pretaskhook()
// continue on to dispatch_task
//////////////////////////////////////////////////////////////////////////////////////////////////
start_dispatch:
ldr r0, =schedtsk // runtsk = schedtsk
ldrb r0, [r0]
ldr r1, =runtsk
strb r0, [r1]
cmp r0, #INVALID_TASK // if (runtsk == INVALID) jump to "pre_idle"
beq pre_idle
ldr r1, =tcxb_sp // sp = tcxb_sp[runtsk]
ldr sp, [r1,r0, asl #2]
ldr r0, =PreTaskHook // if (PreTaskHook !=0) call_pretaskhook()
cmp r0, #0
beq dispatch_task
bl call_pretaskhook
// fall to "dispatch_task"
/////////////////////////////////////////////////////////////////////////////////////////////////////
// dispatch_task: this is called only from start_dispatch
// dispatch to the locatoin saved in tcxb_pc[runtsk]
///////////////////////////////////////////////////////////////////////////////////////////////////
dispatch_task:
ldr r0, =tcxb_pc
ldr r1, =runtsk
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -