Skip to content

Commit

Permalink
unicore32 core architecture: processor and system headers
Browse files Browse the repository at this point in the history
This patch includes processor and system headers. System call interface is here.
We used the syscall interface the same as asm-generic version.

Signed-off-by: Guan Xuetao <gxt@mprc.pku.edu.cn>
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
  • Loading branch information
GuanXuetao committed Mar 17, 2011
1 parent 87c1a3f commit 79725df
Show file tree
Hide file tree
Showing 10 changed files with 810 additions and 0 deletions.
24 changes: 24 additions & 0 deletions arch/unicore32/include/asm/byteorder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* linux/arch/unicore32/include/asm/byteorder.h
*
* Code specific to PKUnity SoC and UniCore ISA
*
* Copyright (C) 2001-2010 GUAN Xue-tao
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* UniCore ONLY support Little Endian mode, the data bus is connected such
* that byte accesses appear as:
* 0 = d0...d7, 1 = d8...d15, 2 = d16...d23, 3 = d24...d31
* and word accesses (data or instruction) appear as:
* d0...d31
*/
#ifndef __UNICORE_BYTEORDER_H__
#define __UNICORE_BYTEORDER_H__

#include <linux/byteorder/little_endian.h>

#endif

45 changes: 45 additions & 0 deletions arch/unicore32/include/asm/cpu-single.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* linux/arch/unicore32/include/asm/cpu-single.h
*
* Code specific to PKUnity SoC and UniCore ISA
*
* Copyright (C) 2001-2010 GUAN Xue-tao
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
#ifndef __UNICORE_CPU_SINGLE_H__
#define __UNICORE_CPU_SINGLE_H__

#include <asm/page.h>
#include <asm/memory.h>

#ifdef __KERNEL__
#ifndef __ASSEMBLY__

#define cpu_switch_mm(pgd, mm) cpu_do_switch_mm(virt_to_phys(pgd), mm)

#define cpu_get_pgd() \
({ \
unsigned long pg; \
__asm__("movc %0, p0.c2, #0" \
: "=r" (pg) : : "cc"); \
pg &= ~0x0fff; \
(pgd_t *)phys_to_virt(pg); \
})

struct mm_struct;

/* declare all the functions as extern */
extern void cpu_proc_fin(void);
extern int cpu_do_idle(void);
extern void cpu_dcache_clean_area(void *, int);
extern void cpu_do_switch_mm(unsigned long pgd_phys, struct mm_struct *mm);
extern void cpu_set_pte(pte_t *ptep, pte_t pte);
extern void cpu_reset(unsigned long addr) __attribute__((noreturn));

#endif /* __ASSEMBLY__ */
#endif /* __KERNEL__ */

#endif /* __UNICORE_CPU_SINGLE_H__ */
33 changes: 33 additions & 0 deletions arch/unicore32/include/asm/cputype.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* linux/arch/unicore32/include/asm/cputype.h
*
* Code specific to PKUnity SoC and UniCore ISA
*
* Copyright (C) 2001-2010 GUAN Xue-tao
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
#ifndef __UNICORE_CPUTYPE_H__
#define __UNICORE_CPUTYPE_H__

#include <linux/stringify.h>

#define CPUID_CPUID 0
#define CPUID_CACHETYPE 1

#define read_cpuid(reg) \
({ \
unsigned int __val; \
asm("movc %0, p0.c0, #" __stringify(reg) \
: "=r" (__val) \
: \
: "cc"); \
__val; \
})

#define uc32_cpuid read_cpuid(CPUID_CPUID)
#define uc32_cachetype read_cpuid(CPUID_CACHETYPE)

#endif
32 changes: 32 additions & 0 deletions arch/unicore32/include/asm/hwcap.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* linux/arch/unicore32/include/asm/hwcap.h
*
* Code specific to PKUnity SoC and UniCore ISA
*
* Copyright (C) 2001-2010 GUAN Xue-tao
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
#ifndef __UNICORE_HWCAP_H__
#define __UNICORE_HWCAP_H__

/*
* HWCAP flags
*/
#define HWCAP_MSP 1
#define HWCAP_UNICORE16 2
#define HWCAP_CMOV 4
#define HWCAP_UNICORE_F64 8
#define HWCAP_TLS 0x80

#if defined(__KERNEL__) && !defined(__ASSEMBLY__)
/*
* This yields a mask that user programs can use to figure out what
* instruction set this cpu supports.
*/
#define ELF_HWCAP (HWCAP_CMOV | HWCAP_UNICORE_F64)
#endif

#endif
92 changes: 92 additions & 0 deletions arch/unicore32/include/asm/processor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* linux/arch/unicore32/include/asm/processor.h
*
* Code specific to PKUnity SoC and UniCore ISA
*
* Copyright (C) 2001-2010 GUAN Xue-tao
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/

#ifndef __UNICORE_PROCESSOR_H__
#define __UNICORE_PROCESSOR_H__

/*
* Default implementation of macro that returns current
* instruction pointer ("program counter").
*/
#define current_text_addr() ({ __label__ _l; _l: &&_l; })

#ifdef __KERNEL__

#include <asm/ptrace.h>
#include <asm/types.h>

#ifdef __KERNEL__
#define STACK_TOP TASK_SIZE
#define STACK_TOP_MAX TASK_SIZE
#endif

struct debug_entry {
u32 address;
u32 insn;
};

struct debug_info {
int nsaved;
struct debug_entry bp[2];
};

struct thread_struct {
/* fault info */
unsigned long address;
unsigned long trap_no;
unsigned long error_code;
/* debugging */
struct debug_info debug;
};

#define INIT_THREAD { }

#define start_thread(regs, pc, sp) \
({ \
unsigned long *stack = (unsigned long *)sp; \
set_fs(USER_DS); \
memset(regs->uregs, 0, sizeof(regs->uregs)); \
regs->UCreg_asr = USER_MODE; \
regs->UCreg_pc = pc & ~1; /* pc */ \
regs->UCreg_sp = sp; /* sp */ \
regs->UCreg_02 = stack[2]; /* r2 (envp) */ \
regs->UCreg_01 = stack[1]; /* r1 (argv) */ \
regs->UCreg_00 = stack[0]; /* r0 (argc) */ \
})

/* Forward declaration, a strange C thing */
struct task_struct;

/* Free all resources held by a thread. */
extern void release_thread(struct task_struct *);

/* Prepare to copy thread state - unlazy all lazy status */
#define prepare_to_copy(tsk) do { } while (0)

unsigned long get_wchan(struct task_struct *p);

#define cpu_relax() barrier()

/*
* Create a new kernel thread
*/
extern int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags);

#define task_pt_regs(p) \
((struct pt_regs *)(THREAD_START_SP + task_stack_page(p)) - 1)

#define KSTK_EIP(tsk) (task_pt_regs(tsk)->UCreg_pc)
#define KSTK_ESP(tsk) (task_pt_regs(tsk)->UCreg_sp)

#endif

#endif /* __UNICORE_PROCESSOR_H__ */
161 changes: 161 additions & 0 deletions arch/unicore32/include/asm/system.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
/*
* linux/arch/unicore32/include/asm/system.h
*
* Code specific to PKUnity SoC and UniCore ISA
*
* Copyright (C) 2001-2010 GUAN Xue-tao
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
#ifndef __UNICORE_SYSTEM_H__
#define __UNICORE_SYSTEM_H__

#ifdef __KERNEL__

/*
* CR1 bits (CP#0 CR1)
*/
#define CR_M (1 << 0) /* MMU enable */
#define CR_A (1 << 1) /* Alignment abort enable */
#define CR_D (1 << 2) /* Dcache enable */
#define CR_I (1 << 3) /* Icache enable */
#define CR_B (1 << 4) /* Dcache write mechanism: write back */
#define CR_T (1 << 5) /* Burst enable */
#define CR_V (1 << 13) /* Vectors relocated to 0xffff0000 */

#ifndef __ASSEMBLY__

#include <linux/linkage.h>
#include <linux/irqflags.h>

struct thread_info;
struct task_struct;

struct pt_regs;

void die(const char *msg, struct pt_regs *regs, int err);

struct siginfo;
void uc32_notify_die(const char *str, struct pt_regs *regs,
struct siginfo *info, unsigned long err, unsigned long trap);

void hook_fault_code(int nr, int (*fn)(unsigned long, unsigned int,
struct pt_regs *),
int sig, int code, const char *name);

#define xchg(ptr, x) \
((__typeof__(*(ptr)))__xchg((unsigned long)(x), (ptr), sizeof(*(ptr))))

extern asmlinkage void __backtrace(void);
extern asmlinkage void c_backtrace(unsigned long fp, int pmode);

struct mm_struct;
extern void show_pte(struct mm_struct *mm, unsigned long addr);
extern void __show_regs(struct pt_regs *);

extern int cpu_architecture(void);
extern void cpu_init(void);

#define vectors_high() (cr_alignment & CR_V)

#define isb() __asm__ __volatile__ ("" : : : "memory")
#define dsb() __asm__ __volatile__ ("" : : : "memory")
#define dmb() __asm__ __volatile__ ("" : : : "memory")

#define mb() barrier()
#define rmb() barrier()
#define wmb() barrier()
#define smp_mb() barrier()
#define smp_rmb() barrier()
#define smp_wmb() barrier()
#define read_barrier_depends() do { } while (0)
#define smp_read_barrier_depends() do { } while (0)

#define set_mb(var, value) do { var = value; smp_mb(); } while (0)
#define nop() __asm__ __volatile__("mov\tr0,r0\t@ nop\n\t");

extern unsigned long cr_no_alignment; /* defined in entry-unicore.S */
extern unsigned long cr_alignment; /* defined in entry-unicore.S */

static inline unsigned int get_cr(void)
{
unsigned int val;
asm("movc %0, p0.c1, #0" : "=r" (val) : : "cc");
return val;
}

static inline void set_cr(unsigned int val)
{
asm volatile("movc p0.c1, %0, #0 @set CR"
: : "r" (val) : "cc");
isb();
}

extern void adjust_cr(unsigned long mask, unsigned long set);

/*
* switch_to(prev, next) should switch from task `prev' to `next'
* `prev' will never be the same as `next'. schedule() itself
* contains the memory barrier to tell GCC not to cache `current'.
*/
extern struct task_struct *__switch_to(struct task_struct *,
struct thread_info *, struct thread_info *);
extern void panic(const char *fmt, ...);

#define switch_to(prev, next, last) \
do { \
last = __switch_to(prev, \
task_thread_info(prev), task_thread_info(next)); \
} while (0)

static inline unsigned long
__xchg(unsigned long x, volatile void *ptr, int size)
{
unsigned long ret;

switch (size) {
case 1:
asm volatile("@ __xchg1\n"
" swapb %0, %1, [%2]"
: "=&r" (ret)
: "r" (x), "r" (ptr)
: "memory", "cc");
break;
case 4:
asm volatile("@ __xchg4\n"
" swapw %0, %1, [%2]"
: "=&r" (ret)
: "r" (x), "r" (ptr)
: "memory", "cc");
break;
default:
panic("xchg: bad data size: ptr 0x%p, size %d\n",
ptr, size);
}

return ret;
}

#include <asm-generic/cmpxchg-local.h>

/*
* cmpxchg_local and cmpxchg64_local are atomic wrt current CPU. Always make
* them available.
*/
#define cmpxchg_local(ptr, o, n) \
((__typeof__(*(ptr)))__cmpxchg_local_generic((ptr), \
(unsigned long)(o), (unsigned long)(n), sizeof(*(ptr))))
#define cmpxchg64_local(ptr, o, n) \
__cmpxchg64_local_generic((ptr), (o), (n))

#include <asm-generic/cmpxchg.h>

#endif /* __ASSEMBLY__ */

#define arch_align_stack(x) (x)

#endif /* __KERNEL__ */

#endif
Loading

0 comments on commit 79725df

Please sign in to comment.