···11/*22- * Copyright (C) 2008 Michal Simek33- * Copyright (C) 2008 PetaLogix22+ * Copyright (C) 2008-2009 Michal Simek <monstr@monstr.eu>33+ * Copyright (C) 2008-2009 PetaLogix44 * Copyright (C) 2006 Atmark Techno, Inc.55 *66 * This file is subject to the terms and conditions of the GNU General Public···2626# define cpu_sleep() do {} while (0)2727# define prepare_to_copy(tsk) do {} while (0)28282929-# endif /* __ASSEMBLY__ */3030-3129#define task_pt_regs(tsk) \3230 (((struct pt_regs *)(THREAD_SIZE + task_stack_page(tsk))) - 1)33313432/* Do necessary setup to start up a newly executed thread. */3533void start_thread(struct pt_regs *regs, unsigned long pc, unsigned long usp);36343535+# endif /* __ASSEMBLY__ */3636+3737+# ifndef CONFIG_MMU3738/*3839 * User space process size: memory size3940 *···8685# define KSTK_EIP(tsk) (0)8786# define KSTK_ESP(tsk) (0)88878888+# else /* CONFIG_MMU */8989+9090+/*9191+ * This is used to define STACK_TOP, and with MMU it must be below9292+ * kernel base to select the correct PGD when handling MMU exceptions.9393+ */9494+# define TASK_SIZE (CONFIG_KERNEL_START)9595+9696+/*9797+ * This decides where the kernel will search for a free chunk of vm9898+ * space during mmap's.9999+ */100100+# define TASK_UNMAPPED_BASE (TASK_SIZE / 8 * 3)101101+102102+# define THREAD_KSP 0103103+104104+# ifndef __ASSEMBLY__105105+106106+/*107107+ * Default implementation of macro that returns current108108+ * instruction pointer ("program counter").109109+ */110110+# define current_text_addr() ({ __label__ _l; _l: &&_l; })111111+112112+/* If you change this, you must change the associated assembly-languages113113+ * constants defined below, THREAD_*.114114+ */115115+struct thread_struct {116116+ /* kernel stack pointer (must be first field in structure) */117117+ unsigned long ksp;118118+ unsigned long ksp_limit; /* if ksp <= ksp_limit stack overflow */119119+ void *pgdir; /* root of page-table tree */120120+ struct pt_regs *regs; /* Pointer to saved register state */121121+};122122+123123+# define INIT_THREAD { \124124+ .ksp = sizeof init_stack + (unsigned long)init_stack, \125125+ .pgdir = swapper_pg_dir, \126126+}127127+128128+/* Do necessary setup to start up a newly executed thread. */129129+void start_thread(struct pt_regs *regs,130130+ unsigned long pc, unsigned long usp);131131+132132+/* Free all resources held by a thread. */133133+extern inline void release_thread(struct task_struct *dead_task)134134+{135135+}136136+137137+extern int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags);138138+139139+/* Free current thread data structures etc. */140140+static inline void exit_thread(void)141141+{142142+}143143+144144+/* Return saved (kernel) PC of a blocked thread. */145145+# define thread_saved_pc(tsk) \146146+ ((tsk)->thread.regs ? (tsk)->thread.regs->r15 : 0)147147+148148+unsigned long get_wchan(struct task_struct *p);149149+150150+/* The size allocated for kernel stacks. This _must_ be a power of two! */151151+# define KERNEL_STACK_SIZE 0x2000152152+153153+/* Return some info about the user process TASK. */154154+# define task_tos(task) ((unsigned long)(task) + KERNEL_STACK_SIZE)155155+# define task_regs(task) ((struct pt_regs *)task_tos(task) - 1)156156+157157+# define task_pt_regs_plus_args(tsk) \158158+ (((void *)task_pt_regs(tsk)) - STATE_SAVE_ARG_SPACE)159159+160160+# define task_sp(task) (task_regs(task)->r1)161161+# define task_pc(task) (task_regs(task)->pc)162162+/* Grotty old names for some. */163163+# define KSTK_EIP(task) (task_pc(task))164164+# define KSTK_ESP(task) (task_sp(task))165165+166166+/* FIXME */167167+# define deactivate_mm(tsk, mm) do { } while (0)168168+169169+# define STACK_TOP TASK_SIZE170170+# define STACK_TOP_MAX STACK_TOP171171+172172+# endif /* __ASSEMBLY__ */173173+# endif /* CONFIG_MMU */89174#endif /* _ASM_MICROBLAZE_PROCESSOR_H */
+19-2
arch/microblaze/include/asm/registers.h
···11/*22- * Copyright (C) 2008 Michal Simek33- * Copyright (C) 2008 PetaLogix22+ * Copyright (C) 2008-2009 Michal Simek <monstr@monstr.eu>33+ * Copyright (C) 2008-2009 PetaLogix44 * Copyright (C) 2006 Atmark Techno, Inc.55 *66 * This file is subject to the terms and conditions of the GNU General Public···3030#define FSR_UF (1<<1) /* Underflow */3131#define FSR_DO (1<<0) /* Denormalized operand error */32323333+# ifdef CONFIG_MMU3434+/* Machine State Register (MSR) Fields */3535+# define MSR_UM (1<<11) /* User Mode */3636+# define MSR_UMS (1<<12) /* User Mode Save */3737+# define MSR_VM (1<<13) /* Virtual Mode */3838+# define MSR_VMS (1<<14) /* Virtual Mode Save */3939+4040+# define MSR_KERNEL (MSR_EE | MSR_VM)4141+/* # define MSR_USER (MSR_KERNEL | MSR_UM | MSR_IE) */4242+# define MSR_KERNEL_VMS (MSR_EE | MSR_VMS)4343+/* # define MSR_USER_VMS (MSR_KERNEL_VMS | MSR_UMS | MSR_IE) */4444+4545+/* Exception State Register (ESR) Fields */4646+# define ESR_DIZ (1<<11) /* Zone Protection */4747+# define ESR_S (1<<10) /* Store instruction */4848+4949+# endif /* CONFIG_MMU */3350#endif /* _ASM_MICROBLAZE_REGISTERS_H */
+13-7
arch/microblaze/include/asm/segment.h
···11/*22- * Copyright (C) 2008 Michal Simek33- * Copyright (C) 2008 PetaLogix22+ * Copyright (C) 2008-2009 Michal Simek <monstr@monstr.eu>33+ * Copyright (C) 2008-2009 PetaLogix44 * Copyright (C) 2006 Atmark Techno, Inc.55 *66 * This file is subject to the terms and conditions of the GNU General Public···1111#ifndef _ASM_MICROBLAZE_SEGMENT_H1212#define _ASM_MICROBLAZE_SEGMENT_H13131414-#ifndef __ASSEMBLY__1414+# ifndef __ASSEMBLY__15151616typedef struct {1717 unsigned long seg;···2929 *3030 * For non-MMU arch like Microblaze, KERNEL_DS and USER_DS is equal.3131 */3232-# define KERNEL_DS ((mm_segment_t){0})3232+# define MAKE_MM_SEG(s) ((mm_segment_t) { (s) })3333+3434+# ifndef CONFIG_MMU3535+# define KERNEL_DS MAKE_MM_SEG(0)3336# define USER_DS KERNEL_DS3737+# else3838+# define KERNEL_DS MAKE_MM_SEG(0xFFFFFFFF)3939+# define USER_DS MAKE_MM_SEG(TASK_SIZE - 1)4040+# endif34413542# define get_ds() (KERNEL_DS)3643# define get_fs() (current_thread_info()->addr_limit)3737-# define set_fs(x) \3838- do { current_thread_info()->addr_limit = (x); } while (0)4444+# define set_fs(val) (current_thread_info()->addr_limit = (val))39454040-# define segment_eq(a, b) ((a).seg == (b).seg)4646+# define segment_eq(a, b) ((a).seg == (b).seg)41474248# endif /* __ASSEMBLY__ */4349#endif /* _ASM_MICROBLAZE_SEGMENT_H */
+58
arch/microblaze/kernel/process.c
···126126 else127127 childregs->r1 = ((unsigned long) ti) + THREAD_SIZE;128128129129+#ifndef CONFIG_MMU129130 memset(&ti->cpu_context, 0, sizeof(struct cpu_context));130131 ti->cpu_context.r1 = (unsigned long)childregs;131132 ti->cpu_context.msr = (unsigned long)childregs->msr;133133+#else134134+135135+ /* if creating a kernel thread then update the current reg (we don't136136+ * want to use the parent's value when restoring by POP_STATE) */137137+ if (kernel_mode(regs))138138+ /* save new current on stack to use POP_STATE */139139+ childregs->CURRENT_TASK = (unsigned long)p;140140+ /* if returning to user then use the parent's value of this register */141141+142142+ /* if we're creating a new kernel thread then just zeroing all143143+ * the registers. That's OK for a brand new thread.*/144144+ /* Pls. note that some of them will be restored in POP_STATE */145145+ if (kernel_mode(regs))146146+ memset(&ti->cpu_context, 0, sizeof(struct cpu_context));147147+ /* if this thread is created for fork/vfork/clone, then we want to148148+ * restore all the parent's context */149149+ /* in addition to the registers which will be restored by POP_STATE */150150+ else {151151+ ti->cpu_context = *(struct cpu_context *)regs;152152+ childregs->msr |= MSR_UMS;153153+ }154154+155155+ /* FIXME STATE_SAVE_PT_OFFSET; */156156+ ti->cpu_context.r1 = (unsigned long)childregs - STATE_SAVE_ARG_SPACE;157157+ /* we should consider the fact that childregs is a copy of the parent158158+ * regs which were saved immediately after entering the kernel state159159+ * before enabling VM. This MSR will be restored in switch_to and160160+ * RETURN() and we want to have the right machine state there161161+ * specifically this state must have INTs disabled before and enabled162162+ * after performing rtbd163163+ * compose the right MSR for RETURN(). It will work for switch_to also164164+ * excepting for VM and UMS165165+ * don't touch UMS , CARRY and cache bits166166+ * right now MSR is a copy of parent one */167167+ childregs->msr |= MSR_BIP;168168+ childregs->msr &= ~MSR_EIP;169169+ childregs->msr |= MSR_IE;170170+ childregs->msr &= ~MSR_VM;171171+ childregs->msr |= MSR_VMS;172172+ childregs->msr |= MSR_EE; /* exceptions will be enabled*/173173+174174+ ti->cpu_context.msr = (childregs->msr|MSR_VM);175175+ ti->cpu_context.msr &= ~MSR_UMS; /* switch_to to kernel mode */176176+#endif132177 ti->cpu_context.r15 = (unsigned long)ret_from_fork - 8;133178134179 if (clone_flags & CLONE_SETTLS)···182137 return 0;183138}184139140140+#ifndef CONFIG_MMU185141/*186142 * Return saved PC of a blocked thread.187143 */···197151 else198152 return ctx->r14;199153}154154+#endif200155201156static void kernel_thread_helper(int (*fn)(void *), void *arg)202157{···236189 regs->r1 = usp;237190 regs->pt_mode = 0;238191}192192+193193+#ifdef CONFIG_MMU194194+#include <linux/elfcore.h>195195+/*196196+ * Set up a thread for executing a new program197197+ */198198+int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpregs)199199+{200200+ return 0; /* MicroBlaze has no separate FPU registers */201201+}202202+#endif /* CONFIG_MMU */