📄 context_switch.h
字号:
// This file is part of MANTIS OS, Operating System for Nymph.// See http://mantis.cs.colorado.edu///// Copyright (C) 2003 University of Colorado, Boulder//// This program is free software; you can redistribute it and/or// modify it under the terms of the GNU General Public License// as published by the Free Software Foundation; either version 2// of the License, or (at your option) any later version.//// This program is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the// GNU General Public License for more details.//// You should have received a copy of the GNU General Public License// (See http://www.gnu.org/copyleft/gpl.html)// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307,// USA, or send email to help@mantis.cs.colorado.edu./** @file context_switch.h * @brief Assembly routines required to preform a context switch. */#ifndef __context_switch_h__#define __context_switch_h__/** @file avr/include/context_switch.h * @brief save the necessary registers for a context switch * on the AVR architecture * * Save current stack pointer * Change stack pointer to process stack * Push address of start_thread function onto stack * Push zeroes for initial register vals and sreg * Save adjusted stack ptr to thread struct * Restore kernel stack ptr */#define CONTEXT_SWITCH_PREAMBLE() \ { \ asm volatile( \ "in %A0, __SP_L__\n\t" \ "in %B0, __SP_H__\n\t" \ : "=r" (_current_thread->sp) : ); \ \ asm volatile( \ "out __SP_H__, %B0\n\t" \ "out __SP_L__, %A0\n\t" \ :: "r" (stack_addr) ); \ \ asm volatile( \ "push %A0\n\t" \ "push %B0\n\t" \ :: "r" (start_wrapper) ); \ \ for(i = 0; i < 31; i++) \ asm volatile("push __zero_reg__\n\t" ::); \ \ asm volatile( \ "in %A0, __SP_L__\n\t" \ "in %B0, __SP_H__\n\t" \ : "=r" (threads[id].sp) : ); \ \ asm volatile( \ "out __SP_H__, %B0\n\t" \ "out __SP_L__, %A0\n\t" \ :: "r" (_current_thread->sp) ); \ \ }/** @brief save the current thread's context to the stack * Save all the registers * Save SREG * Push the stack pointer */#define PUSH_THREAD_STACK() \ { \ asm volatile( \ "push r24\n\t" \ "in r24, __SREG__\n\t" \ "cli\n\t" \ "push r24\n\t" \ ); \ asm volatile( \ "push r31\n\t" \ "push r30\n\t" \ "push r29\n\t" \ "push r28\n\t" \ "push r27\n\t" \ "push r26\n\t" \ "push r25\n\t" \ "push r23\n\t" \ "push r22\n\t" \ "push r21\n\t" \ "push r20\n\t" \ "push r19\n\t" \ "push r18\n\t" \ "push r17\n\t" \ "push r16\n\t" \ "push r15\n\t" \ "push r14\n\t" \ "push r13\n\t" \ "push r12\n\t" \ "push r11\n\t" \ "push r10\n\t" \ "push r9\n\t" \ "push r8\n\t" \ "push r7\n\t" \ "push r6\n\t" \ "push r5\n\t" \ "push r4\n\t" \ "push r3\n\t" \ "push r2\n\t" \ /*"push r1\n\t"*/ \ /*"push r0\n\t"*/ \ ); \ asm volatile( \ "in %A0, __SP_L__\n\t" \ "in %B0, __SP_H__\n\t" \ : "=r" (_current_thread->sp) : ); \ }/** @brief retrieve a thread and context from the stack * Restore the stack pointer * Restore SREG * Restore the other registers */#define POP_THREAD_STACK() \ { \ asm volatile( \ "out __SP_H__, %B0\n\t" \ "out __SP_L__, %A0\n\t" \ :: "r" (_current_thread->sp)); \ asm volatile( \ /*"pop r0\n\t"*/ \ /*"pop r1\n\t"*/ \ "pop r2\n\t" \ "pop r3\n\t" \ "pop r4\n\t" \ "pop r5\n\t" \ "pop r6\n\t" \ "pop r7\n\t" \ "pop r8\n\t" \ "pop r9\n\t" \ "pop r10\n\t" \ "pop r11\n\t" \ "pop r12\n\t" \ "pop r13\n\t" \ "pop r14\n\t" \ "pop r15\n\t" \ "pop r16\n\t" \ "pop r17\n\t" \ "pop r18\n\t" \ "pop r19\n\t" \ "pop r20\n\t" \ "pop r21\n\t" \ "pop r22\n\t" \ "pop r23\n\t" \ "pop r25\n\t" \ "pop r26\n\t" \ "pop r27\n\t" \ "pop r28\n\t" \ "pop r29\n\t" \ "pop r30\n\t" \ "pop r31\n\t" \ "pop r24\n\t" \ "out __SREG__, r24\n\t" \ "pop r24\n\t" \ /*"sei\n\t"*/ \ ); \ }#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -