Commit 06ff51bc authored by David Howells's avatar David Howells Committed by Linus Torvalds

[PATCH] FRV: Fujitsu FR-V CPU arch implementation part 2

The attached patches provides part 2 of an architecture implementation
for the Fujitsu FR-V CPU series, configurably as Linux or uClinux.
Signed-Off-By: default avatarDavid Howells <dhowells@redhat.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 7ec80311
This diff is collapsed.
/* cmode.S: clock mode management
*
* Copyright (C) 2004 Red Hat, Inc. All Rights Reserved.
* Written by David Woodhouse (dwmw2@redhat.com)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*
*/
#include <linux/sys.h>
#include <linux/config.h>
#include <linux/linkage.h>
#include <asm/setup.h>
#include <asm/segment.h>
#include <asm/ptrace.h>
#include <asm/errno.h>
#include <asm/cache.h>
#include <asm/spr-regs.h>
#define __addr_MASK 0xfeff9820 /* interrupt controller mask */
#define __addr_SDRAMC 0xfe000400 /* SDRAM controller regs */
#define SDRAMC_DSTS 0x28 /* SDRAM status */
#define SDRAMC_DSTS_SSI 0x00000001 /* indicates that the SDRAM is in self-refresh mode */
#define SDRAMC_DRCN 0x30 /* SDRAM refresh control */
#define SDRAMC_DRCN_SR 0x00000001 /* transition SDRAM into self-refresh mode */
#define __addr_CLKC 0xfeff9a00
#define CLKC_SWCMODE 0x00000008
#define __addr_LEDS 0xe1200004
.macro li v r
sethi.p %hi(\v),\r
setlo %lo(\v),\r
.endm
.text
.balign 4
###############################################################################
#
# Change CMODE
# - void frv_change_cmode(int cmode)
#
###############################################################################
.globl frv_change_cmode
.type frv_change_cmode,@function
.macro LEDS v
#ifdef DEBUG_CMODE
setlos #~\v,gr10
sti gr10,@(gr11,#0)
membar
#endif
.endm
frv_change_cmode:
movsg lr,gr9
#ifdef DEBUG_CMODE
li __addr_LEDS,gr11
#endif
dcef @(gr0,gr0),#1
# Shift argument left by 24 bits to fit in SWCMODE register later.
slli gr8,#24,gr8
# (1) Set '0' in the PSR.ET bit, and prohibit interrupts.
movsg psr,gr14
andi gr14,#~PSR_ET,gr3
movgs gr3,psr
#if 0 // Fujitsu recommend to skip this and will update docs.
# (2) Set '0' to all bits of the MASK register of the interrupt
# controller, and mask interrupts.
li __addr_MASK,gr12
ldi @(gr12,#0),gr13
li 0xffff0000,gr4
sti gr4,@(gr12,#0)
#endif
# (3) Stop the transfer function of DMAC. Stop all the bus masters
# to access SDRAM and the internal resources.
# (already done by caller)
# (4) Preload a series of following instructions to the instruction
# cache.
li #__cmode_icache_lock_start,gr3
li #__cmode_icache_lock_end,gr4
1: icpl gr3,gr0,#1
addi gr3,#L1_CACHE_BYTES,gr3
cmp gr4,gr3,icc0
bhi icc0,#0,1b
# Set up addresses in regs for later steps.
setlos SDRAMC_DRCN_SR,gr3
li __addr_SDRAMC,gr4
li __addr_CLKC,gr5
ldi @(gr5,#0),gr6
li #0x80000000,gr7
or gr6,gr7,gr6
bra __cmode_icache_lock_start
.balign L1_CACHE_BYTES
__cmode_icache_lock_start:
# (5) Flush the content of all caches by the DCEF instruction.
dcef @(gr0,gr0),#1
# (6) Execute loading the dummy for SDRAM.
ldi @(gr9,#0),gr0
# (7) Set '1' to the DRCN.SR bit, and change SDRAM to the
# self-refresh mode. Execute the dummy load to all memory
# devices set to cacheable on the external bus side in parallel
# with this.
sti gr3,@(gr4,#SDRAMC_DRCN)
# (8) Execute memory barrier instruction (MEMBAR).
membar
# (9) Read the DSTS register repeatedly until '1' stands in the
# DSTS.SSI field.
1: ldi @(gr4,#SDRAMC_DSTS),gr3
andicc gr3,#SDRAMC_DSTS_SSI,gr3,icc0
beq icc0,#0,1b
# (10) Execute memory barrier instruction (MEMBAR).
membar
#if 1
# (11) Set the value of CMODE that you want to change to
# SWCMODE.SWCM[3:0].
sti gr8,@(gr5,#CLKC_SWCMODE)
# (12) Set '1' to the CLKC.SWEN bit. In that case, do not change
# fields other than SWEN of the CLKC register.
sti gr6,@(gr5,#0)
#endif
# (13) Execute the instruction just after the memory barrier
# instruction that executes the self-loop 256 times. (Meanwhile,
# the CMODE switch is done.)
membar
setlos #256,gr7
2: subicc gr7,#1,gr7,icc0
bne icc0,#2,2b
LEDS 0x36
# (14) Release the self-refresh of SDRAM.
sti gr0,@(gr4,#SDRAMC_DRCN)
# Wait for it...
3: ldi @(gr4,#SDRAMC_DSTS),gr3
andicc gr3,#SDRAMC_DSTS_SSI,gr3,icc0
bne icc0,#2,3b
#if 0
li 0x0100000,gr10
4: subicc gr10,#1,gr10,icc0
bne icc0,#0,4b
#endif
__cmode_icache_lock_end:
li #__cmode_icache_lock_start,gr3
li #__cmode_icache_lock_end,gr4
4: icul gr3
addi gr3,#L1_CACHE_BYTES,gr3
cmp gr4,gr3,icc0
bhi icc0,#0,4b
#if 0 // Fujitsu recommend to skip this and will update docs.
# (15) Release the interrupt mask setting of the MASK register of
# the interrupt controller if necessary.
sti gr13,@(gr12,#0)
#endif
# (16) Set 1' in the PSR.ET bit, and permit interrupt.
movgs gr14,psr
bralr
.size frv_change_cmode, .-frv_change_cmode
/* debug-stub.c: debug-mode stub
*
* Copyright (C) 2004 Red Hat, Inc. All Rights Reserved.
* Written by David Howells (dhowells@redhat.com)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*/
#include <linux/string.h>
#include <linux/kernel.h>
#include <linux/signal.h>
#include <linux/sched.h>
#include <linux/init.h>
#include <linux/serial_reg.h>
#include <asm/system.h>
#include <asm/serial-regs.h>
#include <asm/timer-regs.h>
#include <asm/irc-regs.h>
#include <asm/gdb-stub.h>
#include "gdb-io.h"
/* CPU board CON5 */
#define __UART0(X) (*(volatile uint8_t *)(UART0_BASE + (UART_##X)))
#define LSR_WAIT_FOR0(STATE) \
do { \
} while (!(__UART0(LSR) & UART_LSR_##STATE))
#define FLOWCTL_QUERY0(LINE) ({ __UART0(MSR) & UART_MSR_##LINE; })
#define FLOWCTL_CLEAR0(LINE) do { __UART0(MCR) &= ~UART_MCR_##LINE; } while (0)
#define FLOWCTL_SET0(LINE) do { __UART0(MCR) |= UART_MCR_##LINE; } while (0)
#define FLOWCTL_WAIT_FOR0(LINE) \
do { \
gdbstub_do_rx(); \
} while(!FLOWCTL_QUERY(LINE))
static void __init debug_stub_init(void);
extern asmlinkage void __break_hijack_kernel_event(void);
extern asmlinkage void __break_hijack_kernel_event_breaks_here(void);
/*****************************************************************************/
/*
* debug mode handler stub
* - we come here with the CPU in debug mode and with exceptions disabled
* - handle debugging services for userspace
*/
asmlinkage void debug_stub(void)
{
unsigned long hsr0;
int type = 0;
static u8 inited = 0;
if (!inited) {
debug_stub_init();
type = -1;
inited = 1;
}
hsr0 = __get_HSR(0);
if (hsr0 & HSR0_ETMD)
__set_HSR(0, hsr0 & ~HSR0_ETMD);
/* disable single stepping */
__debug_regs->dcr &= ~DCR_SE;
/* kernel mode can propose an exception be handled in debug mode by jumping to a special
* location */
if (__debug_frame->pc == (unsigned long) __break_hijack_kernel_event_breaks_here) {
/* replace the debug frame with the kernel frame and discard
* the top kernel context */
*__debug_frame = *__frame;
__frame = __debug_frame->next_frame;
__debug_regs->brr = (__debug_frame->tbr & TBR_TT) << 12;
__debug_regs->brr |= BRR_EB;
}
if (__debug_frame->pc == (unsigned long) __debug_bug_trap + 4) {
__debug_frame->pc = __debug_frame->lr;
type = __debug_frame->gr8;
}
#ifdef CONFIG_GDBSTUB
gdbstub(type);
#endif
if (hsr0 & HSR0_ETMD)
__set_HSR(0, __get_HSR(0) | HSR0_ETMD);
} /* end debug_stub() */
/*****************************************************************************/
/*
* debug stub initialisation
*/
static void __init debug_stub_init(void)
{
__set_IRR(6, 0xff000000); /* map ERRs to NMI */
__set_IITMR(1, 0x20000000); /* ERR0/1, UART0/1 IRQ detect levels */
asm volatile(" movgs gr0,ibar0 \n"
" movgs gr0,ibar1 \n"
" movgs gr0,ibar2 \n"
" movgs gr0,ibar3 \n"
" movgs gr0,dbar0 \n"
" movgs gr0,dbmr00 \n"
" movgs gr0,dbmr01 \n"
" movgs gr0,dbdr00 \n"
" movgs gr0,dbdr01 \n"
" movgs gr0,dbar1 \n"
" movgs gr0,dbmr10 \n"
" movgs gr0,dbmr11 \n"
" movgs gr0,dbdr10 \n"
" movgs gr0,dbdr11 \n"
);
/* deal with debugging stub initialisation and initial pause */
if (__debug_frame->pc == (unsigned long) __debug_stub_init_break)
__debug_frame->pc = (unsigned long) start_kernel;
/* enable the debug events we want to trap */
__debug_regs->dcr = DCR_EBE;
#ifdef CONFIG_GDBSTUB
gdbstub_init();
#endif
__clr_MASK_all();
__clr_MASK(15);
__clr_RC(15);
} /* end debug_stub_init() */
/*****************************************************************************/
/*
* kernel "exit" trap for gdb stub
*/
void debug_stub_exit(int status)
{
#ifdef CONFIG_GDBSTUB
gdbstub_exit(status);
#endif
} /* end debug_stub_exit() */
/*****************************************************************************/
/*
* send string to serial port
*/
void debug_to_serial(const char *p, int n)
{
char ch;
for (; n > 0; n--) {
ch = *p++;
FLOWCTL_SET0(DTR);
LSR_WAIT_FOR0(THRE);
// FLOWCTL_WAIT_FOR(CTS);
if (ch == 0x0a) {
__UART0(TX) = 0x0d;
mb();
LSR_WAIT_FOR0(THRE);
// FLOWCTL_WAIT_FOR(CTS);
}
__UART0(TX) = ch;
mb();
FLOWCTL_CLEAR0(DTR);
}
} /* end debug_to_serial() */
/*****************************************************************************/
/*
* send string to serial port
*/
void debug_to_serial2(const char *fmt, ...)
{
va_list va;
char buf[64];
int n;
va_start(va, fmt);
n = vsprintf(buf, fmt, va);
va_end(va);
debug_to_serial(buf, n);
} /* end debug_to_serial2() */
/*****************************************************************************/
/*
* set up the ttyS0 serial port baud rate timers
*/
void __init console_set_baud(unsigned baud)
{
unsigned value, high, low;
u8 lcr;
/* work out the divisor to give us the nearest higher baud rate */
value = __serial_clock_speed_HZ / 16 / baud;
/* determine the baud rate range */
high = __serial_clock_speed_HZ / 16 / value;
low = __serial_clock_speed_HZ / 16 / (value + 1);
/* pick the nearest bound */
if (low + (high - low) / 2 > baud)
value++;
lcr = __UART0(LCR);
__UART0(LCR) |= UART_LCR_DLAB;
mb();
__UART0(DLL) = value & 0xff;
__UART0(DLM) = (value >> 8) & 0xff;
mb();
__UART0(LCR) = lcr;
mb();
} /* end console_set_baud() */
/*****************************************************************************/
/*
*
*/
int __init console_get_baud(void)
{
unsigned value;
u8 lcr;
lcr = __UART0(LCR);
__UART0(LCR) |= UART_LCR_DLAB;
mb();
value = __UART0(DLM) << 8;
value |= __UART0(DLL);
__UART0(LCR) = lcr;
mb();
return value;
} /* end console_get_baud() */
/*****************************************************************************/
/*
* display BUG() info
*/
#ifndef CONFIG_NO_KERNEL_MSG
void __debug_bug_printk(const char *file, unsigned line)
{
printk("kernel BUG at %s:%d!\n", file, line);
} /* end __debug_bug_printk() */
#endif
This diff is collapsed.
/* entry-table.S: main trap vector tables and exception jump table
*
* Copyright (C) 2003 Red Hat, Inc. All Rights Reserved.
* Written by David Howells (dhowells@redhat.com)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*
*/
#include <linux/sys.h>
#include <linux/config.h>
#include <linux/linkage.h>
#include <asm/spr-regs.h>
###############################################################################
#
# declare the main trap and vector tables
#
# - the first instruction in each slot is a branch to the appropriate
# kernel-mode handler routine
#
# - the second instruction in each slot is a branch to the debug-mode hardware
# single-step bypass handler - this is called from break.S to deal with the
# CPU stepping in to exception handlers (particular where external interrupts
# are concerned)
#
# - the linker script places the user mode and kernel mode trap tables on to
# the same 8Kb page, so that break.S can be more efficient when performing
# single-step bypass management
#
###############################################################################
# trap table for entry from debug mode
.section .trap.break,"ax"
.balign 256*16
.globl __entry_breaktrap_table
__entry_breaktrap_table:
# trap table for entry from user mode
.section .trap.user,"ax"
.balign 256*16
.globl __entry_usertrap_table
__entry_usertrap_table:
# trap table for entry from kernel mode
.section .trap.kernel,"ax"
.balign 256*16
.globl __entry_kerneltrap_table
__entry_kerneltrap_table:
# exception handler jump table
.section .trap.vector,"ax"
.balign 256*4
.globl __entry_vector_table
__entry_vector_table:
# trap fixup table for single-stepping in user mode
.section .trap.fixup.user,"a"
.balign 256*4
.globl __break_usertrap_fixup_table
__break_usertrap_fixup_table:
# trap fixup table for single-stepping in user mode
.section .trap.fixup.kernel,"a"
.balign 256*4
.globl __break_kerneltrap_fixup_table
__break_kerneltrap_fixup_table:
# handler declaration for a sofware or program interrupt
.macro VECTOR_SOFTPROG tbr_tt, vec
.section .trap.user
.org \tbr_tt
bra __entry_uspace_softprog_interrupt
.section .trap.fixup.user
.org \tbr_tt >> 2
.long __break_step_uspace_softprog_interrupt
.section .trap.kernel
.org \tbr_tt
bra __entry_kernel_softprog_interrupt
.section .trap.fixup.kernel
.org \tbr_tt >> 2
.long __break_step_kernel_softprog_interrupt
.section .trap.vector
.org \tbr_tt >> 2
.long \vec
.endm
# handler declaration for a maskable external interrupt
.macro VECTOR_IRQ tbr_tt, vec
.section .trap.user
.org \tbr_tt
bra __entry_uspace_external_interrupt
.section .trap.fixup.user
.org \tbr_tt >> 2
.long __break_step_uspace_external_interrupt
.section .trap.kernel
.org \tbr_tt
bra __entry_kernel_external_interrupt
.section .trap.fixup.kernel
.org \tbr_tt >> 2
.long __break_step_kernel_external_interrupt
.section .trap.vector
.org \tbr_tt >> 2
.long \vec
.endm
# handler declaration for an NMI external interrupt
.macro VECTOR_NMI tbr_tt, vec
.section .trap.user
.org \tbr_tt
break
break
break
break
.section .trap.kernel
.org \tbr_tt
break
break
break
break
.section .trap.vector
.org \tbr_tt >> 2
.long \vec
.endm
# handler declaration for an MMU only sofware or program interrupt
.macro VECTOR_SP_MMU tbr_tt, vec
#ifdef CONFIG_MMU
VECTOR_SOFTPROG \tbr_tt, \vec
#else
VECTOR_NMI \tbr_tt, 0
#endif
.endm
###############################################################################
#
# specification of the vectors
# - note: each macro inserts code into multiple sections
#
###############################################################################
VECTOR_SP_MMU TBR_TT_INSTR_MMU_MISS, __entry_insn_mmu_miss
VECTOR_SOFTPROG TBR_TT_INSTR_ACC_ERROR, __entry_insn_access_error
VECTOR_SOFTPROG TBR_TT_INSTR_ACC_EXCEP, __entry_insn_access_exception
VECTOR_SOFTPROG TBR_TT_PRIV_INSTR, __entry_privileged_instruction
VECTOR_SOFTPROG TBR_TT_ILLEGAL_INSTR, __entry_illegal_instruction
VECTOR_SOFTPROG TBR_TT_FP_EXCEPTION, __entry_media_exception
VECTOR_SOFTPROG TBR_TT_MP_EXCEPTION, __entry_media_exception
VECTOR_SOFTPROG TBR_TT_DATA_ACC_ERROR, __entry_data_access_error
VECTOR_SP_MMU TBR_TT_DATA_MMU_MISS, __entry_data_mmu_miss
VECTOR_SOFTPROG TBR_TT_DATA_ACC_EXCEP, __entry_data_access_exception
VECTOR_SOFTPROG TBR_TT_DATA_STR_ERROR, __entry_data_store_error
VECTOR_SOFTPROG TBR_TT_DIVISION_EXCEP, __entry_division_exception
#ifdef CONFIG_MMU
.section .trap.user
.org TBR_TT_INSTR_TLB_MISS
.globl __trap_user_insn_tlb_miss
__trap_user_insn_tlb_miss:
movsg ear0,gr28 /* faulting address */
movsg scr0,gr31 /* get mapped PTD coverage start address */
xor.p gr28,gr31,gr31 /* compare addresses */
bra __entry_user_insn_tlb_miss
.org TBR_TT_DATA_TLB_MISS
.globl __trap_user_data_tlb_miss
__trap_user_data_tlb_miss:
movsg ear0,gr28 /* faulting address */
movsg scr1,gr31 /* get mapped PTD coverage start address */
xor.p gr28,gr31,gr31 /* compare addresses */
bra __entry_user_data_tlb_miss
.section .trap.kernel
.org TBR_TT_INSTR_TLB_MISS
.globl __trap_kernel_insn_tlb_miss
__trap_kernel_insn_tlb_miss:
movsg ear0,gr29 /* faulting address */
movsg scr0,gr31 /* get mapped PTD coverage start address */
xor.p gr29,gr31,gr31 /* compare addresses */
bra __entry_kernel_insn_tlb_miss
.org TBR_TT_DATA_TLB_MISS
.globl __trap_kernel_data_tlb_miss
__trap_kernel_data_tlb_miss:
movsg ear0,gr29 /* faulting address */
movsg scr1,gr31 /* get mapped PTD coverage start address */
xor.p gr29,gr31,gr31 /* compare addresses */
bra __entry_kernel_data_tlb_miss
.section .trap.fixup.user
.org TBR_TT_INSTR_TLB_MISS >> 2
.globl __trap_fixup_user_insn_tlb_miss
__trap_fixup_user_insn_tlb_miss:
.long __break_user_insn_tlb_miss
.org TBR_TT_DATA_TLB_MISS >> 2
.globl __trap_fixup_user_data_tlb_miss
__trap_fixup_user_data_tlb_miss:
.long __break_user_data_tlb_miss
.section .trap.fixup.kernel
.org TBR_TT_INSTR_TLB_MISS >> 2
.globl __trap_fixup_kernel_insn_tlb_miss
__trap_fixup_kernel_insn_tlb_miss:
.long __break_kernel_insn_tlb_miss
.org TBR_TT_DATA_TLB_MISS >> 2
.globl __trap_fixup_kernel_data_tlb_miss
__trap_fixup_kernel_data_tlb_miss:
.long __break_kernel_data_tlb_miss
.section .trap.vector
.org TBR_TT_INSTR_TLB_MISS >> 2
.long __entry_insn_mmu_fault
.org TBR_TT_DATA_TLB_MISS >> 2
.long __entry_data_mmu_fault
#endif
VECTOR_SP_MMU TBR_TT_DATA_DAT_EXCEP, __entry_data_dat_fault
VECTOR_NMI TBR_TT_DECREMENT_TIMER, __entry_do_NMI
VECTOR_SOFTPROG TBR_TT_COMPOUND_EXCEP, __entry_compound_exception
VECTOR_IRQ TBR_TT_INTERRUPT_1, __entry_do_IRQ
VECTOR_IRQ TBR_TT_INTERRUPT_2, __entry_do_IRQ
VECTOR_IRQ TBR_TT_INTERRUPT_3, __entry_do_IRQ
VECTOR_IRQ TBR_TT_INTERRUPT_4, __entry_do_IRQ
VECTOR_IRQ TBR_TT_INTERRUPT_5, __entry_do_IRQ
VECTOR_IRQ TBR_TT_INTERRUPT_6, __entry_do_IRQ
VECTOR_IRQ TBR_TT_INTERRUPT_7, __entry_do_IRQ
VECTOR_IRQ TBR_TT_INTERRUPT_8, __entry_do_IRQ
VECTOR_IRQ TBR_TT_INTERRUPT_9, __entry_do_IRQ
VECTOR_IRQ TBR_TT_INTERRUPT_10, __entry_do_IRQ
VECTOR_IRQ TBR_TT_INTERRUPT_11, __entry_do_IRQ
VECTOR_IRQ TBR_TT_INTERRUPT_12, __entry_do_IRQ
VECTOR_IRQ TBR_TT_INTERRUPT_13, __entry_do_IRQ
VECTOR_IRQ TBR_TT_INTERRUPT_14, __entry_do_IRQ
VECTOR_NMI TBR_TT_INTERRUPT_15, __entry_do_NMI
# miscellaneous user mode entry points
.section .trap.user
.org TBR_TT_TRAP0
.rept 127
bra __entry_uspace_softprog_interrupt
bra __break_step_uspace_softprog_interrupt
.long 0,0
.endr
.org TBR_TT_BREAK
bra __entry_break
.long 0,0,0
# miscellaneous kernel mode entry points
.section .trap.kernel
.org TBR_TT_TRAP0
.rept 127
bra __entry_kernel_softprog_interrupt
bra __break_step_kernel_softprog_interrupt
.long 0,0
.endr
.org TBR_TT_BREAK
bra __entry_break
.long 0,0,0
# miscellaneous debug mode entry points
.section .trap.break
.org TBR_TT_BREAK
movsg bpcsr,gr30
jmpl @(gr30,gr0)
# miscellaneous vectors
.section .trap.vector
.org TBR_TT_TRAP0 >> 2
.long system_call
.rept 126
.long __entry_unsupported_trap
.endr
.org TBR_TT_BREAK >> 2
.long __entry_debug_exception
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment