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/sched/debug.h>
  17#include <linux/sched/task.h>
  18#include <linux/sched/task_stack.h>
  19#include <linux/kernel.h>
  20#include <linux/mm.h>
  21#include <linux/smp.h>
  22#include <linux/stddef.h>
  23#include <linux/unistd.h>
  24#include <linux/ptrace.h>
  25#include <linux/slab.h>
  26#include <linux/user.h>
  27#include <linux/elf.h>
  28#include <linux/reboot.h>
  29#include <linux/interrupt.h>
  30#include <linux/pagemap.h>
  31#include <linux/rcupdate.h>
  32
  33#include <asm/asm-offsets.h>
  34#include <linux/uaccess.h>
  35#include <asm/setup.h>
  36#include <asm/pgtable.h>
  37#include <asm/tlb.h>
  38#include <asm/gdb-stub.h>
  39#include <asm/mb-regs.h>
  40
  41#include "local.h"
  42
  43asmlinkage void ret_from_fork(void);
  44asmlinkage void ret_from_kernel_thread(void);
  45
  46#include <asm/pgalloc.h>
  47
  48void (*pm_power_off)(void);
  49EXPORT_SYMBOL(pm_power_off);
  50
  51static void core_sleep_idle(void)
  52{
  53#ifdef LED_DEBUG_SLEEP
  54        /* Show that we're sleeping... */
  55        __set_LEDS(0x55aa);
  56#endif
  57        frv_cpu_core_sleep();
  58#ifdef LED_DEBUG_SLEEP
  59        /* ... and that we woke up */
  60        __set_LEDS(0);
  61#endif
  62        mb();
  63}
  64
  65void arch_cpu_idle(void)
  66{
  67        if (!frv_dma_inprogress)
  68                core_sleep_idle();
  69        else
  70                local_irq_enable();
  71}
  72
  73void machine_restart(char * __unused)
  74{
  75        unsigned long reset_addr;
  76#ifdef CONFIG_GDBSTUB
  77        gdbstub_exit(0);
  78#endif
  79
  80        if (PSR_IMPLE(__get_PSR()) == PSR_IMPLE_FR551)
  81                reset_addr = 0xfefff500;
  82        else
  83                reset_addr = 0xfeff0500;
  84
  85        /* Software reset. */
  86        asm volatile("      dcef @(gr0,gr0),1 ! membar !"
  87                     "      sti     %1,@(%0,0) !"
  88                     "      nop ! nop ! nop ! nop ! nop ! "
  89                     "      nop ! nop ! nop ! nop ! nop ! "
  90                     "      nop ! nop ! nop ! nop ! nop ! "
  91                     "      nop ! nop ! nop ! nop ! nop ! "
  92                     : : "r" (reset_addr), "r" (1) );
  93
  94        for (;;)
  95                ;
  96}
  97
  98void machine_halt(void)
  99{
 100#ifdef CONFIG_GDBSTUB
 101        gdbstub_exit(0);
 102#endif
 103
 104        for (;;);
 105}
 106
 107void machine_power_off(void)
 108{
 109#ifdef CONFIG_GDBSTUB
 110        gdbstub_exit(0);
 111#endif
 112
 113        for (;;);
 114}
 115
 116void flush_thread(void)
 117{
 118        /* nothing */
 119}
 120
 121inline unsigned long user_stack(const struct pt_regs *regs)
 122{
 123        while (regs->next_frame)
 124                regs = regs->next_frame;
 125        return user_mode(regs) ? regs->sp : 0;
 126}
 127
 128/*
 129 * set up the kernel stack and exception frames for a new process
 130 */
 131int copy_thread(unsigned long clone_flags,
 132                unsigned long usp, unsigned long arg,
 133                struct task_struct *p)
 134{
 135        struct pt_regs *childregs;
 136
 137        childregs = (struct pt_regs *)
 138                (task_stack_page(p) + THREAD_SIZE - FRV_FRAME0_SIZE);
 139
 140        /* set up the userspace frame (the only place that the USP is stored) */
 141        *childregs = *current_pt_regs();
 142
 143        p->thread.frame  = childregs;
 144        p->thread.curr   = p;
 145        p->thread.sp     = (unsigned long) childregs;
 146        p->thread.fp     = 0;
 147        p->thread.lr     = 0;
 148        p->thread.frame0 = childregs;
 149
 150        if (unlikely(p->flags & PF_KTHREAD)) {
 151                childregs->gr9 = usp; /* function */
 152                childregs->gr8 = arg;
 153                p->thread.pc = (unsigned long) ret_from_kernel_thread;
 154                save_user_regs(p->thread.user);
 155                return 0;
 156        }
 157        if (usp)
 158                childregs->sp = usp;
 159        childregs->next_frame   = NULL;
 160
 161        p->thread.pc = (unsigned long) ret_from_fork;
 162
 163        /* the new TLS pointer is passed in as arg #5 to sys_clone() */
 164        if (clone_flags & CLONE_SETTLS)
 165                childregs->gr29 = childregs->gr12;
 166
 167        save_user_regs(p->thread.user);
 168
 169        return 0;
 170} /* end copy_thread() */
 171
 172unsigned long get_wchan(struct task_struct *p)
 173{
 174        struct pt_regs *regs0;
 175        unsigned long fp, pc;
 176        unsigned long stack_limit;
 177        int count = 0;
 178        if (!p || p == current || p->state == TASK_RUNNING)
 179                return 0;
 180
 181        stack_limit = (unsigned long) (p + 1);
 182        fp = p->thread.fp;
 183        regs0 = p->thread.frame0;
 184
 185        do {
 186                if (fp < stack_limit || fp >= (unsigned long) regs0 || fp & 3)
 187                        return 0;
 188
 189                pc = ((unsigned long *) fp)[2];
 190
 191                /* FIXME: This depends on the order of these functions. */
 192                if (!in_sched_functions(pc))
 193                        return pc;
 194
 195                fp = *(unsigned long *) fp;
 196        } while (count++ < 16);
 197
 198        return 0;
 199}
 200
 201int elf_check_arch(const struct elf32_hdr *hdr)
 202{
 203        unsigned long hsr0 = __get_HSR(0);
 204        unsigned long psr = __get_PSR();
 205
 206        if (hdr->e_machine != EM_FRV)
 207                return 0;
 208
 209        switch (hdr->e_flags & EF_FRV_GPR_MASK) {
 210        case EF_FRV_GPR64:
 211                if ((hsr0 & HSR0_GRN) == HSR0_GRN_32)
 212                        return 0;
 213        case EF_FRV_GPR32:
 214        case 0:
 215                break;
 216        default:
 217                return 0;
 218        }
 219
 220        switch (hdr->e_flags & EF_FRV_FPR_MASK) {
 221        case EF_FRV_FPR64:
 222                if ((hsr0 & HSR0_FRN) == HSR0_FRN_32)
 223                        return 0;
 224        case EF_FRV_FPR32:
 225        case EF_FRV_FPR_NONE:
 226        case 0:
 227                break;
 228        default:
 229                return 0;
 230        }
 231
 232        if ((hdr->e_flags & EF_FRV_MULADD) == EF_FRV_MULADD)
 233                if (PSR_IMPLE(psr) != PSR_IMPLE_FR405 &&
 234                    PSR_IMPLE(psr) != PSR_IMPLE_FR451)
 235                        return 0;
 236
 237        switch (hdr->e_flags & EF_FRV_CPU_MASK) {
 238        case EF_FRV_CPU_GENERIC:
 239                break;
 240        case EF_FRV_CPU_FR300:
 241        case EF_FRV_CPU_SIMPLE:
 242        case EF_FRV_CPU_TOMCAT:
 243        default:
 244                return 0;
 245        case EF_FRV_CPU_FR400:
 246                if (PSR_IMPLE(psr) != PSR_IMPLE_FR401 &&
 247                    PSR_IMPLE(psr) != PSR_IMPLE_FR405 &&
 248                    PSR_IMPLE(psr) != PSR_IMPLE_FR451 &&
 249                    PSR_IMPLE(psr) != PSR_IMPLE_FR551)
 250                        return 0;
 251                break;
 252        case EF_FRV_CPU_FR450:
 253                if (PSR_IMPLE(psr) != PSR_IMPLE_FR451)
 254                        return 0;
 255                break;
 256        case EF_FRV_CPU_FR500:
 257                if (PSR_IMPLE(psr) != PSR_IMPLE_FR501)
 258                        return 0;
 259                break;
 260        case EF_FRV_CPU_FR550:
 261                if (PSR_IMPLE(psr) != PSR_IMPLE_FR551)
 262                        return 0;
 263                break;
 264        }
 265
 266        return 1;
 267}
 268
 269int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpregs)
 270{
 271        memcpy(fpregs,
 272               &current->thread.user->f,
 273               sizeof(current->thread.user->f));
 274        return 1;
 275}
 276