base/include/asm-x86_64/rtai_sched.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 1999-2003 Paolo Mantegazza  <mantegazza@aero.polimi.it>
00003  * Copyright (C) 2000      Stuart Hughes     <shughes@zentropix.com>
00004  * Copyright (C) 2007      Antonio Barbalace <barbalace@igi.cnr.it>
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License as
00008  * published by the Free Software Foundation; either version 2 of the
00009  * License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00019  */
00020 
00021 #ifndef _RTAI_ASM_X8664_SCHED_H
00022 #define _RTAI_ASM_X8664_SCHED_H
00023 
00024 #if 1
00025 // adapted from Linux kernel 2.6.20.1 (include/asm-x86_64/calling.h)
00026 #define rt_exchange_tasks(oldtask, newtask) \
00027     __asm__ __volatile__( \
00028     "subq $9*8, %%rsp\n\t" \
00029     "movq %%rdi, 8*8(%%rsp)\n\t" \
00030     "movq %%rsi, 7*8(%%rsp)\n\t" \
00031     "movq %%rdx, 6*8(%%rsp)\n\t" \
00032     "movq %%rcx, 5*8(%%rsp)\n\t" \
00033     "movq %%rax, 4*8(%%rsp)\n\t" \
00034     "movq %%r8, 3*8(%%rsp)\n\t" \
00035     "movq %%r9, 2*8(%%rsp)\n\t" \
00036     "movq %%r10, 1*8(%%rsp)\n\t" \
00037     "movq %%r11, 0*8(%%rsp)\n\t" \
00038 \
00039     "subq $6*8, %%rsp\n\t" \
00040     "movq %%rbx, 5*8(%%rsp)\n\t" \
00041     "movq %%rbp, 4*8(%%rsp)\n\t" \
00042     "movq %%r12, 3*8(%%rsp)\n\t" \
00043     "movq %%r13, 2*8(%%rsp)\n\t" \
00044     "movq %%r14, 1*8(%%rsp)\n\t" \
00045     "movq %%r15, 0*8(%%rsp)\n\t" \
00046 \
00047     "pushq $1f\n\t" \
00048 \
00049     "movq (%%rcx), %%rbx\n\t" \
00050     "movq %%rsp, (%%rbx)\n\t" \
00051     "movq (%%rdx), %%rsp\n\t" \
00052     "movq %%rdx, (%%rcx)\n\t" \
00053     "ret\n\t" \
00054 \
00055 "1:  movq 0*8(%%rsp), %%r15\n\t" \
00056     "movq 1*8(%%rsp), %%r14\n\t" \
00057     "movq 2*8(%%rsp), %%r13\n\t" \
00058     "movq 3*8(%%rsp), %%r12\n\t" \
00059     "movq 4*8(%%rsp), %%rbp\n\t" \
00060     "movq 5*8(%%rsp), %%rbx\n\t" \
00061     "addq $6*8, %%rsp\n\t" \
00062 \
00063     "movq 0*8(%%rsp), %%r11\n\t" \
00064     "movq 1*8(%%rsp), %%r10\n\t" \
00065     "movq 2*8(%%rsp), %%r9\n\t" \
00066     "movq 3*8(%%rsp), %%r8\n\t" \
00067     "movq 4*8(%%rsp), %%rax\n\t" \
00068     "movq 5*8(%%rsp), %%rcx\n\t" \
00069     "movq 6*8(%%rsp), %%rdx\n\t" \
00070     "movq 7*8(%%rsp), %%rsi\n\t" \
00071     "movq 8*8(%%rsp), %%rdi\n\t" \
00072     "addq $9*8, %%rsp\n\t" \
00073 \
00074     : \
00075     : "c" (&oldtask), "d" (newtask) \
00076     );
00077 #endif
00078 
00079 #if 0
00080 // two instruction less
00081 #define rt_exchange_tasks(oldtask, newtask) \
00082     __asm__ __volatile__( \
00083     "subq $15*8, %%rsp\n\t" \
00084     "movq %%rdi, 14*8(%%rsp)\n\t" \
00085     "movq %%rsi, 13*8(%%rsp)\n\t" \
00086     "movq %%rdx, 12*8(%%rsp)\n\t" \
00087     "movq %%rcx, 11*8(%%rsp)\n\t" \
00088     "movq %%rax, 10*8(%%rsp)\n\t" \
00089     "movq %%r8, 9*8(%%rsp)\n\t" \
00090     "movq %%r9, 8*8(%%rsp)\n\t" \
00091     "movq %%r10, 7*8(%%rsp)\n\t" \
00092     "movq %%r11, 6*8(%%rsp)\n\t" \
00093     "movq %%rbx, 5*8(%%rsp)\n\t" \
00094     "movq %%rbp, 4*8(%%rsp)\n\t" \
00095     "movq %%r12, 3*8(%%rsp)\n\t" \
00096     "movq %%r13, 2*8(%%rsp)\n\t" \
00097     "movq %%r14, 1*8(%%rsp)\n\t" \
00098     "movq %%r15, 0*8(%%rsp)\n\t" \
00099 \
00100     "pushq $1f\n\t" \
00101 \
00102     "movq (%%rcx), %%rbx\n\t" \
00103     "movq %%rsp, (%%rbx)\n\t" \
00104     "movq (%%rdx), %%rsp\n\t" \
00105     "movq %%rdx, (%%rcx)\n\t" \
00106     "ret\n" \
00107 \
00108 "1:  movq 0*8(%%rsp), %%r15\n\t" \
00109     "movq 1*8(%%rsp), %%r14\n\t" \
00110     "movq 2*8(%%rsp), %%r13\n\t" \
00111     "movq 3*8(%%rsp), %%r12\n\t" \
00112     "movq 4*8(%%rsp), %%rbp\n\t" \
00113     "movq 5*8(%%rsp), %%rbx\n\t" \
00114     "movq 6*8(%%rsp), %%r11\n\t" \
00115     "movq 7*8(%%rsp), %%r10\n\t" \
00116     "movq 8*8(%%rsp), %%r9\n\t" \
00117     "movq 9*8(%%rsp), %%r8\n\t" \
00118     "movq 10*8(%%rsp), %%rax\n\t" \
00119     "movq 11*8(%%rsp), %%rcx\n\t" \
00120     "movq 12*8(%%rsp), %%rdx\n\t" \
00121     "movq 13*8(%%rsp), %%rsi\n\t" \
00122     "movq 14*8(%%rsp), %%rdi\n\t" \
00123     "addq $15*8, %%rsp\n\t" \
00124 \
00125     : \
00126     : "c" (&oldtask), "d" (newtask) \
00127     );
00128 #endif
00129 
00130 #if 0
00131 // with push and pop 
00132 #define rt_exchange_tasks(oldtask, newtask) \
00133     __asm__ __volatile__( \
00134     "pushq %%rdi\n\t" \
00135     "pushq %%rsi\n\t" \
00136     "pushq %%rdx\n\t" \
00137     "pushq %%rcx\n\t" \
00138     "pushq %%rax\n\t" \
00139     "pushq %%r8\n\t" \
00140     "pushq %%r9\n\t" \
00141     "pushq %%r10\n\t" \
00142     "pushq %%r11\n\t" \
00143     "pushq %%rbx\n\t" \
00144     "pushq %%rbp\n\t" \
00145     "pushq %%r12\n\t" \
00146     "pushq %%r13\n\t" \
00147     "pushq %%r14\n\t" \
00148     "pushq %%r15\n\t" \
00149 \
00150     "pushq $1f\n\t" \
00151 \
00152     "movq (%%rcx), %%rbx\n\t" \
00153     "movq %%rsp, (%%rbx)\n\t" \
00154     "movq (%%rdx), %%rsp\n\t" \
00155     "movq %%rdx, (%%rcx)\n\t" \
00156     "ret\n" \
00157 \
00158 "1:  popq %%r15\n\t" \
00159     "popq %%r14\n\t" \
00160     "popq %%r13\n\t" \
00161     "popq %%r12\n\t" \
00162     "popq %%rbp\n\t" \
00163     "popq %%rbx\n\t" \
00164     "popq %%r11\n\t" \
00165     "popq %%r10\n\t" \
00166     "popq %%r9\n\t" \
00167     "popq %%r8\n\t" \
00168     "popq %%rax\n\t" \
00169     "popq %%rcx\n\t" \
00170     "popq %%rdx\n\t" \
00171     "popq %%rsi\n\t" \
00172     "popq %%rdi\n\t" \
00173 \
00174     : \
00175     : "c" (&oldtask), "d" (newtask) \
00176     );
00177 #endif
00178 
00179 #if 0
00180 // push and pop -4 instruction
00181 #define rt_exchange_tasks(oldtask, newtask) \
00182     __asm__ __volatile__( \
00183     "pushq %%rdi\n\t" \
00184     "pushq %%rsi\n\t" \
00185     "pushq %%rax\n\t" \
00186     "pushq %%r8\n\t" \
00187     "pushq %%r9\n\t" \
00188     "pushq %%r10\n\t" \
00189     "pushq %%r11\n\t" \
00190     "pushq %%rbx\n\t" \
00191     "pushq %%rbp\n\t" \
00192     "pushq %%r12\n\t" \
00193     "pushq %%r13\n\t" \
00194     "pushq %%r14\n\t" \
00195     "pushq %%r15\n\t" \
00196 \
00197     "pushq $1f\n\t" \
00198 \
00199     "movq (%%rcx), %%rbx\n\t" \
00200     "movq %%rsp, (%%rbx)\n\t" \
00201     "movq (%%rdx), %%rsp\n\t" \
00202     "movq %%rdx, (%%rcx)\n\t" \
00203     "ret\n" \
00204 \
00205 "1:  popq %%r15\n\t" \
00206     "popq %%r14\n\t" \
00207     "popq %%r13\n\t" \
00208     "popq %%r12\n\t" \
00209     "popq %%rbp\n\t" \
00210     "popq %%rbx\n\t" \
00211     "popq %%r11\n\t" \
00212     "popq %%r10\n\t" \
00213     "popq %%r9\n\t" \
00214     "popq %%r8\n\t" \
00215     "popq %%rax\n\t" \
00216     "popq %%rsi\n\t" \
00217     "popq %%rdi\n\t" \
00218 \
00219     : \
00220     : "c" (&oldtask), "d" (newtask) \
00221     );
00222 #endif
00223 
00224 #if 0
00225 // mov -4 instruction
00226 #define rt_exchange_tasks(oldtask, newtask) \
00227     __asm__ __volatile__( \
00228     "subq $13*8, %%rsp\n\t" \
00229     "movq %%rdi, 12*8(%%rsp)\n\t" \
00230     "movq %%rsi, 11*8(%%rsp)\n\t" \
00231     "movq %%rax, 10*8(%%rsp)\n\t" \
00232     "movq %%r8, 9*8(%%rsp)\n\t" \
00233     "movq %%r9, 8*8(%%rsp)\n\t" \
00234     "movq %%r10, 7*8(%%rsp)\n\t" \
00235     "movq %%r11, 6*8(%%rsp)\n\t" \
00236     "movq %%rbx, 5*8(%%rsp)\n\t" \
00237     "movq %%rbp, 4*8(%%rsp)\n\t" \
00238     "movq %%r12, 3*8(%%rsp)\n\t" \
00239     "movq %%r13, 2*8(%%rsp)\n\t" \
00240     "movq %%r14, 1*8(%%rsp)\n\t" \
00241     "movq %%r15, 0*8(%%rsp)\n\t" \
00242 \
00243     "pushq $1f\n\t" \
00244 \
00245     "movq (%%rcx), %%rbx\n\t" \
00246     "movq %%rsp, (%%rbx)\n\t" \
00247     "movq (%%rdx), %%rsp\n\t" \
00248     "movq %%rdx, (%%rcx)\n\t" \
00249     "ret\n" \
00250 \
00251 "1:  movq 0*8(%%rsp), %%r15\n\t" \
00252     "movq 1*8(%%rsp), %%r14\n\t" \
00253     "movq 2*8(%%rsp), %%r13\n\t" \
00254     "movq 3*8(%%rsp), %%r12\n\t" \
00255     "movq 4*8(%%rsp), %%rbp\n\t" \
00256     "movq 5*8(%%rsp), %%rbx\n\t" \
00257     "movq 6*8(%%rsp), %%r11\n\t" \
00258     "movq 7*8(%%rsp), %%r10\n\t" \
00259     "movq 8*8(%%rsp), %%r9\n\t" \
00260     "movq 9*8(%%rsp), %%r8\n\t" \
00261     "movq 10*8(%%rsp), %%rax\n\t" \
00262     "movq 11*8(%%rsp), %%rsi\n\t" \
00263     "movq 12*8(%%rsp), %%rdi\n\t" \
00264     "addq $13*8, %%rsp\n\t" \
00265 \
00266     : \
00267     : "c" (&oldtask), "d" (newtask) \
00268     );
00269 #endif
00270 
00271 #define init_arch_stack() \
00272 do { \
00273     *--(task->stack) = data;        \
00274     *--(task->stack) = (unsigned long) rt_thread;   \
00275     *--(task->stack) = 0;           \
00276     *--(task->stack) = (unsigned long) rt_startup;  \
00277 } while(0)
00278 
00279 #define DEFINE_LINUX_CR0      static unsigned long linux_cr0;
00280 
00281 #define DEFINE_LINUX_SMP_CR0  static unsigned long linux_smp_cr0[NR_RT_CPUS];
00282 
00283 #define init_task_fpenv(task)  do { init_fpenv((task)->fpu_reg); } while(0)
00284 
00285 static inline void *get_stack_pointer(void)
00286 {
00287     void *sp;
00288     asm volatile ("movq %%rsp, %0" : "=r" (sp));
00289     return sp;
00290 }
00291 
00292 #define RT_SET_RTAI_TRAP_HANDLER(x)  rt_set_rtai_trap_handler(x)
00293 
00294 #define DO_TIMER_PROPER_OP()
00295 
00296 #endif /* !_RTAI_ASM_X8664_SCHED_H */

Generated on Tue Feb 2 17:46:04 2010 for RTAI API by  doxygen 1.4.7