linux/arch/frv/kernel/process.c
<<
>>
Prefs
   1/* process.c: FRV specific parts of process handling
   2 *
   3 * Copyright (C) 2003-5 Red Hat, Inc. All Rights Reserved.
   4 * Written by David Howells (dhowells@redhat.com)
   5 * - Derived from arch/m68k/kernel/process.c
   6 *
   7 * This program is free software; you can redistribute it and/or
   8 * modify it under the terms of the GNU General Public License
   9 * as published by the Free Software Foundation; either version
  10 * 2 of the License, or (at your option) any later version.
  11 */
  12
  13#include <linux/module.h>
  14#include <linux/errno.h>
  15#include <linux/sched.h>
  16#include <linux/kernel.h>
  17#include <linux/mm.h>
  18#include <linux/smp.h>
  19#include <linux/smp_lock.h>
  20#include <linux/stddef.h>
  21#include <linux/unistd.h>
  22#include <linux/ptrace.h>
  23#include <linux/slab.h>
  24#include <linux/user.h>
  25#include <linux/elf.h>
  26#include <linux/reboot.h>
  27#include <linux/interrupt.h>
  28#include <linux/pagemap.h>
  29
  30#include <asm/asm-offsets.h>
  31#include <asm/uaccess.h>
  32#include <asm/system.h>
  33#include <asm/setup.h>
  34#include <asm/pgtable.h>
  35#include <asm/tlb.h>
  36#include <asm/gdb-stub.h>
  37#include <asm/mb-regs.h>
  38
  39#include "local.h"
  40
  41asmlinkage void ret_from_fork(void);
  42
  43#include <asm/pgalloc.h>
  44
  45void (*pm_power_off)(void);
  46EXPORT_SYMBOL(pm_power_off);
  47
  48struct task_struct *alloc_task_struct(void)
  49{
  50        struct task_struct *p = kmalloc(THREAD_SIZE, GFP_KERNEL);
  51        if (p)
  52                atomic_set((atomic_t *)(p+1), 1);
  53        return p;
  54}
  55
  56void free_task_struct(struct task_struct *p)
  57{
  58        if (atomic_dec_and_test((atomic_t *)(p+1)))
  59                kfree(p);
  60}
  61
  62static void core_sleep_idle(void)
  63{
  64#ifdef LED_DEBUG_SLEEP
  65        /* Show that we're sleeping... */
  66        __set_LEDS(0x55aa);
  67#endif
  68        frv_cpu_core_sleep();
  69#ifdef LED_DEBUG_SLEEP
  70        /* ... and that we woke up */
  71        __set_LEDS(0);
  72#endif
  73        mb();
  74}
  75
  76void (*idle)(void) = core_sleep_idle;
  77
  78/*
  79 * The idle thread. There's no useful work to be
  80 * done, so just try to conserve power and have a
  81 * low exit latency (ie sit in a loop waiting for
  82 * somebody to say that they'd like to reschedule)
  83 */
  84void cpu_idle(void)
  85{
  86        /* endless idle loop with no priority at all */
  87        while (1) {
  88                while (!need_resched()) {
  89                        check_pgt_cache();
  90
  91                        if (!frv_dma_inprogress && idle)
  92                                idle();
  93                }
  94
  95                preempt_enable_no_resched();
  96                schedule();
  97                preempt_disable();
  98        }
  99}
 100
 101void machine_restart(char * __unused)
 102{
 103        unsigned long reset_addr;
 104#ifdef CONFIG_GDBSTUB
 105        gdbstub_exit(0);
 106#endif
 107
 108        if (PSR_IMPLE(__get_PSR()) == PSR_IMPLE_FR551)
 109                reset_addr = 0xfefff500;
 110        else
 111                reset_addr = 0xfeff0500;
 112
 113        /* Software reset. */
 114        asm volatile("      dcef @(gr0,gr0),1 ! membar !"
 115                     "      sti     %1,@(%0,0) !"
 116                     "      nop ! nop ! nop ! nop ! nop ! "
 117                     "      nop ! nop ! nop ! nop ! nop ! "
 118                     "      nop ! nop ! nop ! nop ! nop ! "
 119                     "      nop ! nop ! nop ! nop ! nop ! "
 120                     : : "r" (reset_addr), "r" (1) );
 121
 122        for (;;)
 123                ;
 124}
 125
 126void machine_halt(void)
 127{
 128#ifdef CONFIG_GDBSTUB
 129        gdbstub_exit(0);
 130#endif
 131
 132        for (;;);
 133}
 134
 135void machine_power_off(void)
 136{
 137#ifdef CONFIG_GDBSTUB
 138        gdbstub_exit(0);
 139#endif
 140
 141        for (;;);
 142}
 143
 144void flush_thread(void)
 145{
 146#if 0 //ndef NO_FPU
 147        unsigned long zero = 0;
 148#endif
 149        set_fs(USER_DS);
 150}
 151
 152inline unsigned long user_stack(const struct pt_regs *regs)
 153{
 154        while (regs->next_frame)
 155                regs = regs->next_frame;
 156        return user_mode(regs) ? regs->sp : 0;
 157}
 158
 159asmlinkage int sys_fork(void)
 160{
 161#ifndef CONFIG_MMU
 162        /* fork almost works, enough to trick you into looking elsewhere:-( */
 163        return -EINVAL;
 164#else
 165        return do_fork(SIGCHLD, user_stack(__frame), __frame, 0, NULL, NULL);
 166#endif
 167}
 168
 169asmlinkage int sys_vfork(void)
 170{
 171        return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, user_stack(__frame), __frame, 0,
 172                       NULL, NULL);
 173}
 174
 175/*****************************************************************************/
 176/*
 177 * clone a process
 178 * - tlsptr is retrieved by copy_thread()
 179 */
 180asmlinkage int sys_clone(unsigned long clone_flags, unsigned long newsp,
 181                         int __user *parent_tidptr, int __user *child_tidptr,
 182                         int __user *tlsptr)
 183{
 184        if (!newsp)
 185                newsp = user_stack(__frame);
 186        return do_fork(clone_flags, newsp, __frame, 0, parent_tidptr, child_tidptr);
 187} /* end sys_clone() */
 188
 189/*****************************************************************************/
 190/*
 191 * This gets called before we allocate a new thread and copy
 192 * the current task into it.
 193 */
 194void prepare_to_copy(struct task_struct *tsk)
 195{
 196        //unlazy_fpu(tsk);
 197} /* end prepare_to_copy() */
 198
 199/*****************************************************************************/
 200/*
 201 * set up the kernel stack and exception frames for a new process
 202 */
 203int copy_thread(unsigned long clone_flags,
 204                unsigned long usp, unsigned long topstk,
 205                struct task_struct *p, struct pt_regs *regs)
 206{
 207        struct pt_regs *childregs0, *childregs, *regs0;
 208
 209        regs0 = __kernel_frame0_ptr;
 210        childregs0 = (struct pt_regs *)
 211                (task_stack_page(p) + THREAD_SIZE - FRV_FRAME0_SIZE);
 212        childregs = childregs0;
 213
 214        /* set up the userspace frame (the only place that the USP is stored) */
 215        *childregs0 = *regs0;
 216
 217        childregs0->gr8         = 0;
 218        childregs0->sp          = usp;
 219        childregs0->next_frame  = NULL;
 220
 221        /* set up the return kernel frame if called from kernel_thread() */
 222        if (regs != regs0) {
 223                childregs--;
 224                *childregs = *regs;
 225                childregs->sp = (unsigned long) childregs0;
 226                childregs->next_frame = childregs0;
 227                childregs->gr15 = (unsigned long) task_thread_info(p);
 228                childregs->gr29 = (unsigned long) p;
 229        }
 230
 231        p->set_child_tid = p->clear_child_tid = NULL;
 232
 233        p->thread.frame  = childregs;
 234        p->thread.curr   = p;
 235        p->thread.sp     = (unsigned long) childregs;
 236        p->thread.fp     = 0;
 237        p->thread.lr     = 0;
 238        p->thread.pc     = (unsigned long) ret_from_fork;
 239        p->thread.frame0 = childregs0;
 240
 241        /* the new TLS pointer is passed in as arg #5 to sys_clone() */
 242        if (clone_flags & CLONE_SETTLS)
 243                childregs->gr29 = childregs->gr12;
 244
 245        save_user_regs(p->thread.user);
 246
 247        return 0;
 248} /* end copy_thread() */
 249
 250/*
 251 * sys_execve() executes a new program.
 252 */
 253asmlinkage int sys_execve(char __user *name, char __user * __user *argv, char __user * __user *envp)
 254{
 255        int error;
 256        char * filename;
 257
 258        filename = getname(name);
 259        error = PTR_ERR(filename);
 260        if (IS_ERR(filename))
 261                return error;
 262        error = do_execve(filename, argv, envp, __frame);
 263        putname(filename);
 264        return error;
 265}
 266
 267unsigned long get_wchan(struct task_struct *p)
 268{
 269        struct pt_regs *regs0;
 270        unsigned long fp, pc;
 271        unsigned long stack_limit;
 272        int count = 0;
 273        if (!p || p == current || p->state == TASK_RUNNING)
 274                return 0;
 275
 276        stack_limit = (unsigned long) (p + 1);
 277        fp = p->thread.fp;
 278        regs0 = p->thread.frame0;
 279
 280        do {
 281                if (fp < stack_limit || fp >= (unsigned long) regs0 || fp & 3)
 282                        return 0;
 283
 284                pc = ((unsigned long *) fp)[2];
 285
 286                /* FIXME: This depends on the order of these functions. */
 287                if (!in_sched_functions(pc))
 288                        return pc;
 289
 290                fp = *(unsigned long *) fp;
 291        } while (count++ < 16);
 292
 293        return 0;
 294}
 295
 296unsigned long thread_saved_pc(struct task_struct *tsk)
 297{
 298        /* Check whether the thread is blocked in resume() */
 299        if (in_sched_functions(tsk->thread.pc))
 300                return ((unsigned long *)tsk->thread.fp)[2];
 301        else
 302                return tsk->thread.pc;
 303}
 304
 305int elf_check_arch(const struct elf32_hdr *hdr)
 306{
 307        unsigned long hsr0 = __get_HSR(0);
 308        unsigned long psr = __get_PSR();
 309
 310        if (hdr->e_machine != EM_FRV)
 311                return 0;
 312
 313        switch (hdr->e_flags & EF_FRV_GPR_MASK) {
 314        case EF_FRV_GPR64:
 315                if ((hsr0 & HSR0_GRN) == HSR0_GRN_32)
 316                        return 0;
 317        case EF_FRV_GPR32:
 318        case 0:
 319                break;
 320        default:
 321                return 0;
 322        }
 323
 324        switch (hdr->e_flags & EF_FRV_FPR_MASK) {
 325        case EF_FRV_FPR64:
 326                if ((hsr0 & HSR0_FRN) == HSR0_FRN_32)
 327                        return 0;
 328        case EF_FRV_FPR32:
 329        case EF_FRV_FPR_NONE:
 330        case 0:
 331                break;
 332        default:
 333                return 0;
 334        }
 335
 336        if ((hdr->e_flags & EF_FRV_MULADD) == EF_FRV_MULADD)
 337                if (PSR_IMPLE(psr) != PSR_IMPLE_FR405 &&
 338                    PSR_IMPLE(psr) != PSR_IMPLE_FR451)
 339                        return 0;
 340
 341        switch (hdr->e_flags & EF_FRV_CPU_MASK) {
 342        case EF_FRV_CPU_GENERIC:
 343                break;
 344        case EF_FRV_CPU_FR300:
 345        case EF_FRV_CPU_SIMPLE:
 346        case EF_FRV_CPU_TOMCAT:
 347        default:
 348                return 0;
 349        case EF_FRV_CPU_FR400:
 350                if (PSR_IMPLE(psr) != PSR_IMPLE_FR401 &&
 351                    PSR_IMPLE(psr) != PSR_IMPLE_FR405 &&
 352                    PSR_IMPLE(psr) != PSR_IMPLE_FR451 &&
 353                    PSR_IMPLE(psr) != PSR_IMPLE_FR551)
 354                        return 0;
 355                break;
 356        case EF_FRV_CPU_FR450:
 357                if (PSR_IMPLE(psr) != PSR_IMPLE_FR451)
 358                        return 0;
 359                break;
 360        case EF_FRV_CPU_FR500:
 361                if (PSR_IMPLE(psr) != PSR_IMPLE_FR501)
 362                        return 0;
 363                break;
 364        case EF_FRV_CPU_FR550:
 365                if (PSR_IMPLE(psr) != PSR_IMPLE_FR551)
 366                        return 0;
 367                break;
 368        }
 369
 370        return 1;
 371}
 372
 373int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpregs)
 374{
 375        memcpy(fpregs,
 376               &current->thread.user->f,
 377               sizeof(current->thread.user->f));
 378        return 1;
 379}
 380
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.