aboutsummaryrefslogtreecommitdiff
path: root/arch/cris/arch-v10/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'arch/cris/arch-v10/kernel')
-rw-r--r--arch/cris/arch-v10/kernel/Makefile17
-rw-r--r--arch/cris/arch-v10/kernel/asm-offsets.c47
-rw-r--r--arch/cris/arch-v10/kernel/crisksyms.c17
-rw-r--r--arch/cris/arch-v10/kernel/debugport.c531
-rw-r--r--arch/cris/arch-v10/kernel/entry.S1132
-rw-r--r--arch/cris/arch-v10/kernel/fasttimer.c977
-rw-r--r--arch/cris/arch-v10/kernel/head.S882
-rw-r--r--arch/cris/arch-v10/kernel/irq.c204
-rw-r--r--arch/cris/arch-v10/kernel/kgdb.c1568
-rw-r--r--arch/cris/arch-v10/kernel/process.c270
-rw-r--r--arch/cris/arch-v10/kernel/ptrace.c314
-rw-r--r--arch/cris/arch-v10/kernel/setup.c103
-rw-r--r--arch/cris/arch-v10/kernel/shadows.c36
-rw-r--r--arch/cris/arch-v10/kernel/signal.c580
-rw-r--r--arch/cris/arch-v10/kernel/time.c369
-rw-r--r--arch/cris/arch-v10/kernel/traps.c132
16 files changed, 7179 insertions, 0 deletions
diff --git a/arch/cris/arch-v10/kernel/Makefile b/arch/cris/arch-v10/kernel/Makefile
new file mode 100644
index 00000000000..52761603b6a
--- /dev/null
+++ b/arch/cris/arch-v10/kernel/Makefile
@@ -0,0 +1,17 @@
+# $Id: Makefile,v 1.5 2004/06/02 08:24:38 starvik Exp $
+#
+# Makefile for the linux kernel.
+#
+
+extra-y := head.o
+
+
+obj-y := entry.o traps.o shadows.o debugport.o irq.o \
+ process.o setup.o signal.o traps.o time.o ptrace.o
+
+obj-$(CONFIG_ETRAX_KGDB) += kgdb.o
+obj-$(CONFIG_ETRAX_FAST_TIMER) += fasttimer.o
+obj-$(CONFIG_MODULES) += crisksyms.o
+
+clean:
+
diff --git a/arch/cris/arch-v10/kernel/asm-offsets.c b/arch/cris/arch-v10/kernel/asm-offsets.c
new file mode 100644
index 00000000000..1aa3cc4e710
--- /dev/null
+++ b/arch/cris/arch-v10/kernel/asm-offsets.c
@@ -0,0 +1,47 @@
+#include <linux/sched.h>
+#include <asm/thread_info.h>
+
+/*
+ * Generate definitions needed by assembly language modules.
+ * This code generates raw asm output which is post-processed to extract
+ * and format the required data.
+ */
+
+#define DEFINE(sym, val) \
+ asm volatile("\n->" #sym " %0 " #val : : "i" (val))
+
+#define BLANK() asm volatile("\n->" : : )
+
+int main(void)
+{
+#define ENTRY(entry) DEFINE(PT_ ## entry, offsetof(struct pt_regs, entry))
+ ENTRY(orig_r10);
+ ENTRY(r13);
+ ENTRY(r12);
+ ENTRY(r11);
+ ENTRY(r10);
+ ENTRY(r9);
+ ENTRY(mof);
+ ENTRY(dccr);
+ ENTRY(srp);
+ BLANK();
+#undef ENTRY
+#define ENTRY(entry) DEFINE(TI_ ## entry, offsetof(struct thread_info, entry))
+ ENTRY(task);
+ ENTRY(flags);
+ ENTRY(preempt_count);
+ BLANK();
+#undef ENTRY
+#define ENTRY(entry) DEFINE(THREAD_ ## entry, offsetof(struct thread_struct, entry))
+ ENTRY(ksp);
+ ENTRY(usp);
+ ENTRY(dccr);
+ BLANK();
+#undef ENTRY
+#define ENTRY(entry) DEFINE(TASK_ ## entry, offsetof(struct task_struct, entry))
+ ENTRY(pid);
+ BLANK();
+ DEFINE(LCLONE_VM, CLONE_VM);
+ DEFINE(LCLONE_UNTRACED, CLONE_UNTRACED);
+ return 0;
+}
diff --git a/arch/cris/arch-v10/kernel/crisksyms.c b/arch/cris/arch-v10/kernel/crisksyms.c
new file mode 100644
index 00000000000..b332bf9b312
--- /dev/null
+++ b/arch/cris/arch-v10/kernel/crisksyms.c
@@ -0,0 +1,17 @@
+#include <linux/config.h>
+#include <linux/module.h>
+#include <asm/io.h>
+#include <asm/arch/svinto.h>
+
+/* Export shadow registers for the CPU I/O pins */
+EXPORT_SYMBOL(genconfig_shadow);
+EXPORT_SYMBOL(port_pa_data_shadow);
+EXPORT_SYMBOL(port_pa_dir_shadow);
+EXPORT_SYMBOL(port_pb_data_shadow);
+EXPORT_SYMBOL(port_pb_dir_shadow);
+EXPORT_SYMBOL(port_pb_config_shadow);
+EXPORT_SYMBOL(port_g_data_shadow);
+
+/* Cache flush functions */
+EXPORT_SYMBOL(flush_etrax_cache);
+EXPORT_SYMBOL(prepare_rx_descriptor);
diff --git a/arch/cris/arch-v10/kernel/debugport.c b/arch/cris/arch-v10/kernel/debugport.c
new file mode 100644
index 00000000000..6cf069e5e7b
--- /dev/null
+++ b/arch/cris/arch-v10/kernel/debugport.c
@@ -0,0 +1,531 @@
+/* Serialport functions for debugging
+ *
+ * Copyright (c) 2000 Axis Communications AB
+ *
+ * Authors: Bjorn Wesen
+ *
+ * Exports:
+ * console_print_etrax(char *buf)
+ * int getDebugChar()
+ * putDebugChar(int)
+ * enableDebugIRQ()
+ * init_etrax_debug()
+ *
+ * $Log: debugport.c,v $
+ * Revision 1.19 2004/10/21 07:26:16 starvik
+ * Made it possible to specify console settings on kernel command line.
+ *
+ * Revision 1.18 2004/10/19 13:07:37 starvik
+ * Merge of Linux 2.6.9
+ *
+ * Revision 1.17 2004/09/29 10:33:46 starvik
+ * Resolved a dealock when printing debug from kernel.
+ *
+ * Revision 1.16 2004/08/24 06:12:19 starvik
+ * Whitespace cleanup
+ *
+ * Revision 1.15 2004/08/16 12:37:19 starvik
+ * Merge of Linux 2.6.8
+ *
+ * Revision 1.14 2004/05/17 13:11:29 starvik
+ * Disable DMA until real serial driver is up
+ *
+ * Revision 1.13 2004/05/14 07:58:01 starvik
+ * Merge of changes from 2.4
+ *
+ * Revision 1.12 2003/09/11 07:29:49 starvik
+ * Merge of Linux 2.6.0-test5
+ *
+ * Revision 1.11 2003/07/07 09:53:36 starvik
+ * Revert all the 2.5.74 merge changes to make the console work again
+ *
+ * Revision 1.9 2003/02/17 17:07:23 starvik
+ * Solved the problem with corrupted debug output (from Linux 2.4)
+ * * Wait until DMA, FIFO and pipe is empty before and after transmissions
+ * * Buffer data until a FIFO flush can be triggered.
+ *
+ * Revision 1.8 2003/01/22 06:48:36 starvik
+ * Fixed warnings issued by GCC 3.2.1
+ *
+ * Revision 1.7 2002/12/12 08:26:32 starvik
+ * Don't use C-comments inside CVS comments
+ *
+ * Revision 1.6 2002/12/11 15:42:02 starvik
+ * Extracted v10 (ETRAX 100LX) specific stuff from arch/cris/kernel/
+ *
+ * Revision 1.5 2002/11/20 06:58:03 starvik
+ * Compiles with kgdb
+ *
+ * Revision 1.4 2002/11/19 14:35:24 starvik
+ * Changes from linux 2.4
+ * Changed struct initializer syntax to the currently prefered notation
+ *
+ * Revision 1.3 2002/11/06 09:47:03 starvik
+ * Modified for new interrupt macros
+ *
+ * Revision 1.2 2002/01/21 15:21:50 bjornw
+ * Update for kdev_t changes
+ *
+ * Revision 1.6 2001/04/17 13:58:39 orjanf
+ * * Renamed CONFIG_KGDB to CONFIG_ETRAX_KGDB.
+ *
+ * Revision 1.5 2001/03/26 14:22:05 bjornw
+ * Namechange of some config options
+ *
+ * Revision 1.4 2000/10/06 12:37:26 bjornw
+ * Use physical addresses when talking to DMA
+ *
+ *
+ */
+
+#include <linux/config.h>
+#include <linux/console.h>
+#include <linux/init.h>
+#include <linux/major.h>
+#include <linux/delay.h>
+#include <linux/tty.h>
+#include <asm/system.h>
+#include <asm/arch/svinto.h>
+#include <asm/io.h> /* Get SIMCOUT. */
+
+struct dbg_port
+{
+ unsigned int index;
+ const volatile unsigned* read;
+ volatile char* write;
+ volatile unsigned* xoff;
+ volatile char* baud;
+ volatile char* tr_ctrl;
+ volatile char* rec_ctrl;
+ unsigned long irq;
+ unsigned int started;
+ unsigned long baudrate;
+ unsigned char parity;
+ unsigned int bits;
+};
+
+struct dbg_port ports[]=
+{
+ {
+ 0,
+ R_SERIAL0_READ,
+ R_SERIAL0_TR_DATA,
+ R_SERIAL0_XOFF,
+ R_SERIAL0_BAUD,
+ R_SERIAL0_TR_CTRL,
+ R_SERIAL0_REC_CTRL,
+ IO_STATE(R_IRQ_MASK1_SET, ser0_data, set)
+ },
+ {
+ 1,
+ R_SERIAL1_READ,
+ R_SERIAL1_TR_DATA,
+ R_SERIAL1_XOFF,
+ R_SERIAL1_BAUD,
+ R_SERIAL1_TR_CTRL,
+ R_SERIAL1_REC_CTRL,
+ IO_STATE(R_IRQ_MASK1_SET, ser1_data, set)
+ },
+ {
+ 2,
+ R_SERIAL2_READ,
+ R_SERIAL2_TR_DATA,
+ R_SERIAL2_XOFF,
+ R_SERIAL2_BAUD,
+ R_SERIAL2_TR_CTRL,
+ R_SERIAL2_REC_CTRL,
+ IO_STATE(R_IRQ_MASK1_SET, ser2_data, set)
+ },
+ {
+ 3,
+ R_SERIAL3_READ,
+ R_SERIAL3_TR_DATA,
+ R_SERIAL3_XOFF,
+ R_SERIAL3_BAUD,
+ R_SERIAL3_TR_CTRL,
+ R_SERIAL3_REC_CTRL,
+ IO_STATE(R_IRQ_MASK1_SET, ser3_data, set)
+ }
+};
+
+static struct tty_driver *serial_driver;
+
+struct dbg_port* port =
+#if defined(CONFIG_ETRAX_DEBUG_PORT0)
+ &ports[0];
+#elif defined(CONFIG_ETRAX_DEBUG_PORT1)
+ &ports[1];
+#elif defined(CONFIG_ETRAX_DEBUG_PORT2)
+ &ports[2];
+#elif defined(CONFIG_ETRAX_DEBUG_PORT3)
+ &ports[3];
+#else
+ NULL;
+#endif
+/* Used by serial.c to register a debug_write_function so that the normal
+ * serial driver is used for kernel debug output
+ */
+typedef int (*debugport_write_function)(int i, const char *buf, unsigned int len);
+
+debugport_write_function debug_write_function = NULL;
+
+static void
+start_port(void)
+{
+ unsigned long rec_ctrl = 0;
+ unsigned long tr_ctrl = 0;
+
+ if (!port)
+ return;
+
+ if (port->started)
+ return;
+ port->started = 1;
+
+ if (port->index == 0)
+ {
+ genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG, dma6);
+ genconfig_shadow |= IO_STATE(R_GEN_CONFIG, dma6, unused);
+ }
+ else if (port->index == 1)
+ {
+ genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG, dma8);
+ genconfig_shadow |= IO_STATE(R_GEN_CONFIG, dma8, usb);
+ }
+ else if (port->index == 2)
+ {
+ genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG, dma2);
+ genconfig_shadow |= IO_STATE(R_GEN_CONFIG, dma2, par0);
+ genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG, dma3);
+ genconfig_shadow |= IO_STATE(R_GEN_CONFIG, dma3, par0);
+ genconfig_shadow |= IO_STATE(R_GEN_CONFIG, ser2, select);
+ }
+ else
+ {
+ genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG, dma4);
+ genconfig_shadow |= IO_STATE(R_GEN_CONFIG, dma4, par1);
+ genconfig_shadow &= ~IO_MASK(R_GEN_CONFIG, dma5);
+ genconfig_shadow |= IO_STATE(R_GEN_CONFIG, dma5, par1);
+ genconfig_shadow |= IO_STATE(R_GEN_CONFIG, ser3, select);
+ }
+
+ *R_GEN_CONFIG = genconfig_shadow;
+
+ *port->xoff =
+ IO_STATE(R_SERIAL0_XOFF, tx_stop, enable) |
+ IO_STATE(R_SERIAL0_XOFF, auto_xoff, disable) |
+ IO_FIELD(R_SERIAL0_XOFF, xoff_char, 0);
+
+ switch (port->baudrate)
+ {
+ case 0:
+ case 115200:
+ *port->baud =
+ IO_STATE(R_SERIAL0_BAUD, tr_baud, c115k2Hz) |
+ IO_STATE(R_SERIAL0_BAUD, rec_baud, c115k2Hz);
+ break;
+ case 1200:
+ *port->baud =
+ IO_STATE(R_SERIAL0_BAUD, tr_baud, c1200Hz) |
+ IO_STATE(R_SERIAL0_BAUD, rec_baud, c1200Hz);
+ break;
+ case 2400:
+ *port->baud =
+ IO_STATE(R_SERIAL0_BAUD, tr_baud, c2400Hz) |
+ IO_STATE(R_SERIAL0_BAUD, rec_baud, c2400Hz);
+ break;
+ case 4800:
+ *port->baud =
+ IO_STATE(R_SERIAL0_BAUD, tr_baud, c4800Hz) |
+ IO_STATE(R_SERIAL0_BAUD, rec_baud, c4800Hz);
+ break;
+ case 9600:
+ *port->baud =
+ IO_STATE(R_SERIAL0_BAUD, tr_baud, c9600Hz) |
+ IO_STATE(R_SERIAL0_BAUD, rec_baud, c9600Hz);
+ break;
+ case 19200:
+ *port->baud =
+ IO_STATE(R_SERIAL0_BAUD, tr_baud, c19k2Hz) |
+ IO_STATE(R_SERIAL0_BAUD, rec_baud, c19k2Hz);
+ break;
+ case 38400:
+ *port->baud =
+ IO_STATE(R_SERIAL0_BAUD, tr_baud, c38k4Hz) |
+ IO_STATE(R_SERIAL0_BAUD, rec_baud, c38k4Hz);
+ break;
+ case 57600:
+ *port->baud =
+ IO_STATE(R_SERIAL0_BAUD, tr_baud, c57k6Hz) |
+ IO_STATE(R_SERIAL0_BAUD, rec_baud, c57k6Hz);
+ break;
+ default:
+ *port->baud =
+ IO_STATE(R_SERIAL0_BAUD, tr_baud, c115k2Hz) |
+ IO_STATE(R_SERIAL0_BAUD, rec_baud, c115k2Hz);
+ break;
+ }
+
+ if (port->parity == 'E') {
+ rec_ctrl =
+ IO_STATE(R_SERIAL0_REC_CTRL, rec_par, even) |
+ IO_STATE(R_SERIAL0_REC_CTRL, rec_par_en, enable);
+ tr_ctrl =
+ IO_STATE(R_SERIAL0_TR_CTRL, tr_par, even) |
+ IO_STATE(R_SERIAL0_TR_CTRL, tr_par_en, enable);
+ } else if (port->parity == 'O') {
+ rec_ctrl =
+ IO_STATE(R_SERIAL0_REC_CTRL, rec_par, odd) |
+ IO_STATE(R_SERIAL0_REC_CTRL, rec_par_en, enable);
+ tr_ctrl =
+ IO_STATE(R_SERIAL0_TR_CTRL, tr_par, odd) |
+ IO_STATE(R_SERIAL0_TR_CTRL, tr_par_en, enable);
+ } else {
+ rec_ctrl =
+ IO_STATE(R_SERIAL0_REC_CTRL, rec_par, even) |
+ IO_STATE(R_SERIAL0_REC_CTRL, rec_par_en, disable);
+ tr_ctrl =
+ IO_STATE(R_SERIAL0_TR_CTRL, tr_par, even) |
+ IO_STATE(R_SERIAL0_TR_CTRL, tr_par_en, disable);
+ }
+
+ if (port->bits == 7)
+ {
+ rec_ctrl |= IO_STATE(R_SERIAL0_REC_CTRL, rec_bitnr, rec_7bit);
+ tr_ctrl |= IO_STATE(R_SERIAL0_TR_CTRL, tr_bitnr, tr_7bit);
+ }
+ else
+ {
+ rec_ctrl |= IO_STATE(R_SERIAL0_REC_CTRL, rec_bitnr, rec_8bit);
+ tr_ctrl |= IO_STATE(R_SERIAL0_TR_CTRL, tr_bitnr, tr_8bit);
+ }
+
+ *port->rec_ctrl =
+ IO_STATE(R_SERIAL0_REC_CTRL, dma_err, stop) |
+ IO_STATE(R_SERIAL0_REC_CTRL, rec_enable, enable) |
+ IO_STATE(R_SERIAL0_REC_CTRL, rts_, active) |
+ IO_STATE(R_SERIAL0_REC_CTRL, sampling, middle) |
+ IO_STATE(R_SERIAL0_REC_CTRL, rec_stick_par, normal) |
+ rec_ctrl;
+
+ *port->tr_ctrl =
+ IO_FIELD(R_SERIAL0_TR_CTRL, txd, 0) |
+ IO_STATE(R_SERIAL0_TR_CTRL, tr_enable, enable) |
+ IO_STATE(R_SERIAL0_TR_CTRL, auto_cts, disabled) |
+ IO_STATE(R_SERIAL0_TR_CTRL, stop_bits, one_bit) |
+ IO_STATE(R_SERIAL0_TR_CTRL, tr_stick_par, normal) |
+ tr_ctrl;
+}
+
+static void
+console_write_direct(struct console *co, const char *buf, unsigned int len)
+{
+ int i;
+ unsigned long flags;
+ local_irq_save(flags);
+ /* Send data */
+ for (i = 0; i < len; i++) {
+ /* Wait until transmitter is ready and send.*/
+ while (!(*port->read & IO_MASK(R_SERIAL0_READ, tr_ready)))
+ ;
+ *port->write = buf[i];
+ }
+ local_irq_restore(flags);
+}
+
+static void
+console_write(struct console *co, const char *buf, unsigned int len)
+{
+ if (!port)
+ return;
+
+#ifdef CONFIG_SVINTO_SIM
+ /* no use to simulate the serial debug output */
+ SIMCOUT(buf, len);
+ return;
+#endif
+
+ start_port();
+
+#ifdef CONFIG_ETRAX_KGDB
+ /* kgdb needs to output debug info using the gdb protocol */
+ putDebugString(buf, len);
+ return;
+#endif
+
+ if (debug_write_function)
+ debug_write_function(co->index, buf, len);
+ else
+ console_write_direct(co, buf, len);
+}
+
+/* legacy function */
+
+void
+console_print_etrax(const char *buf)
+{
+ console_write(NULL, buf, strlen(buf));
+}
+
+/* Use polling to get a single character FROM the debug port */
+
+int
+getDebugChar(void)
+{
+ unsigned long readval;
+
+ do {
+ readval = *port->read;
+ } while (!(readval & IO_MASK(R_SERIAL0_READ, data_avail)));
+
+ return (readval & IO_MASK(R_SERIAL0_READ, data_in));
+}
+
+/* Use polling to put a single character to the debug port */
+
+void
+putDebugChar(int val)
+{
+ while (!(*port->read & IO_MASK(R_SERIAL0_READ, tr_ready)))
+ ;
+ *port->write = val;
+}
+
+/* Enable irq for receiving chars on the debug port, used by kgdb */
+
+void
+enableDebugIRQ(void)
+{
+ *R_IRQ_MASK1_SET = port->irq;
+ /* use R_VECT_MASK directly, since we really bypass Linux normal
+ * IRQ handling in kgdb anyway, we don't need to use enable_irq
+ */
+ *R_VECT_MASK_SET = IO_STATE(R_VECT_MASK_SET, serial, set);
+
+ *port->rec_ctrl = IO_STATE(R_SERIAL0_REC_CTRL, rec_enable, enable);
+}
+
+static struct tty_driver*
+etrax_console_device(struct console* co, int *index)
+{
+ return serial_driver;
+}
+
+static int __init
+console_setup(struct console *co, char *options)
+{
+ char* s;
+
+ if (options) {
+ port = &ports[co->index];
+ port->baudrate = 115200;
+ port->parity = 'N';
+ port->bits = 8;
+ port->baudrate = simple_strtoul(options, NULL, 10);
+ s = options;
+ while(*s >= '0' && *s <= '9')
+ s++;
+ if (*s) port->parity = *s++;
+ if (*s) port->bits = *s++ - '0';
+ port->started = 0;
+ start_port();
+ }
+ return 0;
+}
+
+static struct console sercons = {
+ name : "ttyS",
+ write: console_write,
+ read : NULL,
+ device : etrax_console_device,
+ unblank : NULL,
+ setup : console_setup,
+ flags : CON_PRINTBUFFER,
+ index : -1,
+ cflag : 0,
+ next : NULL
+};
+static struct console sercons0 = {
+ name : "ttyS",
+ write: console_write,
+ read : NULL,
+ device : etrax_console_device,
+ unblank : NULL,
+ setup : console_setup,
+ flags : CON_PRINTBUFFER,
+ index : 0,
+ cflag : 0,
+ next : NULL
+};
+
+static struct console sercons1 = {
+ name : "ttyS",
+ write: console_write,
+ read : NULL,
+ device : etrax_console_device,
+ unblank : NULL,
+ setup : console_setup,
+ flags : CON_PRINTBUFFER,
+ index : 1,
+ cflag : 0,
+ next : NULL
+};
+static struct console sercons2 = {
+ name : "ttyS",
+ write: console_write,
+ read : NULL,
+ device : etrax_console_device,
+ unblank : NULL,
+ setup : console_setup,
+ flags : CON_PRINTBUFFER,
+ index : 2,
+ cflag : 0,
+ next : NULL
+};
+static struct console sercons3 = {
+ name : "ttyS",
+ write: console_write,
+ read : NULL,
+ device : etrax_console_device,
+ unblank : NULL,
+ setup : console_setup,
+ flags : CON_PRINTBUFFER,
+ index : 3,
+ cflag : 0,
+ next : NULL
+};
+/*
+ * Register console (for printk's etc)
+ */
+
+int __init
+init_etrax_debug(void)
+{
+ static int first = 1;
+
+ if (!first) {
+ if (!port) {
+ register_console(&sercons0);
+ register_console(&sercons1);
+ register_console(&sercons2);
+ register_console(&sercons3);
+ unregister_console(&sercons);
+ }
+ return 0;
+ }
+ first = 0;
+ if (port)
+ register_console(&sercons);
+ return 0;
+}
+
+int __init
+init_console(void)
+{
+ serial_driver = alloc_tty_driver(1);
+ if (!serial_driver)
+ return -ENOMEM;
+ return 0;
+}
+
+__initcall(init_etrax_debug);
diff --git a/arch/cris/arch-v10/kernel/entry.S b/arch/cris/arch-v10/kernel/entry.S
new file mode 100644
index 00000000000..1bc44f481c3
--- /dev/null
+++ b/arch/cris/arch-v10/kernel/entry.S
@@ -0,0 +1,1132 @@
+/* $Id: entry.S,v 1.23 2004/10/19 13:07:37 starvik Exp $
+ *
+ * linux/arch/cris/entry.S
+ *
+ * Copyright (C) 2000, 2001, 2002 Axis Communications AB
+ *
+ * Authors: Bjorn Wesen (bjornw@axis.com)
+ *
+ * $Log: entry.S,v $
+ * Revision 1.23 2004/10/19 13:07:37 starvik
+ * Merge of Linux 2.6.9
+ *
+ * Revision 1.22 2004/06/21 10:29:55 starvik
+ * Merge of Linux 2.6.7
+ *
+ * Revision 1.21 2004/06/09 05:30:27 starvik
+ * Clean up multiple interrupt handling.
+ * Prevent interrupts from interrupting each other.
+ * Handle all active interrupts.
+ *
+ * Revision 1.20 2004/06/08 08:55:32 starvik
+ * Removed unused code
+ *
+ * Revision 1.19 2004/06/04 11:56:15 starvik
+ * Implemented page table lookup for refills in assembler for improved performance.
+ *
+ * Revision 1.18 2004/05/11 12:28:25 starvik
+ * Merge of Linux 2.6.6
+ *
+ * Revision 1.17 2003/09/11 07:29:49 starvik
+ * Merge of Linux 2.6.0-test5
+ *
+ * Revision 1.16 2003/07/04 08:27:41 starvik
+ * Merge of Linux 2.5.74
+ *
+ * Revision 1.15 2003/04/09 07:32:55 starvik
+ * resume should return task_struct, not thread_info
+ *
+ * Revision 1.14 2003/04/09 05:20:44 starvik
+ * Merge of Linux 2.5.67
+ *
+ * Revision 1.13 2002/12/11 15:42:02 starvik
+ * Extracted v10 (ETRAX 100LX) specific stuff from arch/cris/kernel/*.c
+ *
+ * Revision 1.12 2002/12/10 09:00:10 starvik
+ * Merge of Linux 2.5.51
+ *
+ * Revision 1.11 2002/12/05 07:53:10 starvik
+ * Corrected constants used with btstq
+ *
+ * Revision 1.10 2002/11/27 08:45:10 starvik
+ * pid is in task_struct, not thread_info
+ *
+ * Revision 1.9 2002/11/26 09:52:05 starvik
+ * Added preemptive kernel scheduling (if CONFIG_PREEMPT)
+ *
+ * Revision 1.8 2002/11/20 11:56:11 starvik
+ * Merge of Linux 2.5.48
+ *
+ * Revision 1.7 2002/11/18 13:02:42 starvik
+ * Added fourth parameter to do_notify_resume
+ * Minor cleanup
+ *
+ * Revision 1.6 2002/11/11 10:37:50 starvik
+ * Use new asm-offset defines
+ * Modified for new location of current->work etc
+ * Removed SYMBOL_NAME from syscalls
+ * Added some new syscalls
+ *
+ * Revision 1.5 2002/11/05 06:45:11 starvik
+ * Merge of Linux 2.5.45
+ *
+ * Revision 1.4 2002/02/05 15:41:31 bjornw
+ * Rewritten to conform better to current 2.5 code (similar to arch/i386)
+ *
+ * Revision 1.3 2002/01/21 15:22:20 bjornw
+ * NICE_DOGGY fix from 2.4 arch/cris
+ *
+ * Revision 1.37 2001/12/07 17:03:55 bjornw
+ * Call a c-hook called watchdog_bite_hook instead of show_registers directly
+ *
+ * Revision 1.36 2001/11/22 13:36:36 bjornw
+ * * In ret_from_intr, check regs->dccr for usermode reentrance instead of
+ * DCCR explicitely (because the latter might not reflect current reality)
+ * * In mmu_bus_fault, set $r9 _after_ calling the C-code instead of before
+ * since $r9 is call-clobbered and is potentially needed afterwards
+ *
+ * Revision 1.35 2001/10/30 17:10:15 bjornw
+ * Add some syscalls
+ *
+ * Revision 1.34 2001/10/01 14:45:03 bjornw
+ * Removed underscores and added register prefixes
+ *
+ * Revision 1.33 2001/08/21 13:48:01 jonashg
+ * Added fix by HP to avoid oops when doing a hard_reset_now.
+ *
+ * Revision 1.32 2001/08/14 04:32:02 hp
+ * In _resume, add comment why R9 is saved; don't sound like it's call-saved.
+ *
+ * Revision 1.31 2001/07/25 16:07:42 bjornw
+ * softirq_active/mask -> softirq_pending only
+ *
+ * Revision 1.30 2001/07/05 01:03:32 hp
+ * - include asm/errno.h to get ENOSYS.
+ * - Use ENOSYS, not local constant LENOSYS; tweak comments.
+ * - Explain why .include, not #include is used.
+ * - Make oops-register-dump if watchdog bits and it's not expected.
+ * - Don't jsr, use jump _hard_reset_now, and skip spurious nop.
+ * - Use correct section attribute for section .rodata.
+ * - Adjust sys_ni_syscall fill number.
+ *
+ * Revision 1.29 2001/06/25 14:07:00 hp
+ * Fix review comment.
+ * * head.S: Use IO_STATE, IO_FIELD and IO_MASK constructs instead of
+ * magic numbers. Add comment that -traditional must not be used.
+ * * entry.S (SYMBOL_NAME): Change redefinition to use ## concatenation.
+ * Correct and update comment.
+ * * Makefile (.S.o): Don't use -traditional. Add comment why the
+ * toplevel rule can't be used (now that there's a reason).
+ *
+ * Revision 1.28 2001/06/21 02:00:40 hp
+ * * entry.S: Include asm/unistd.h.
+ * (_sys_call_table): Use section .rodata, not .data.
+ * (_kernel_thread): Move from...
+ * * process.c: ... here.
+ * * entryoffsets.c (VAL): Break out from...
+ * (OF): Use VAL.
+ * (LCLONE_VM): New asmified value from CLONE_VM.
+ *
+ * Revision 1.27 2001/05/29 11:25:27 markusl
+ * In case of "spurious_interrupt", do hard_reset instead of hanging system in a loop...
+ *
+ * Revision 1.26 2001/05/15 15:46:03 bjornw
+ * Include config.h now that we use some CONFIG_ options
+ *
+ * Revision 1.25 2001/05/15 05:38:47 hp
+ * Tweaked code in _ret_from_sys_call
+ *
+ * Revision 1.24 2001/05/15 05:27:49 hp
+ * Save r9 in r1 over function call rather than on stack.
+ *
+ * Revision 1.23 2001/05/15 05:10:00 hp
+ * Generate entry.S structure offsets from C
+ *
+ * Revision 1.22 2001/04/17 13:58:39 orjanf
+ * * Renamed CONFIG_KGDB to CONFIG_ETRAX_KGDB.
+ *
+ * Revision 1.21 2001/04/17 11:33:29 orjanf
+ * Updated according to review:
+ * * Included asm/sv_addr_ag.h to get macro for internal register.
+ * * Corrected comment regarding system call argument passing.
+ * * Removed comment about instruction being in a delay slot.
+ * * Added comment about SYMBOL_NAME macro.
+ *
+ * Revision 1.20 2001/04/12 08:51:07 hp
+ * - Add entry for sys_fcntl64. In fact copy last piece from i386 including ...
+ * - .rept to fill table to safe state with sys_ni_syscall.
+ *
+ * Revision 1.19 2001/04/04 09:43:32 orjanf
+ * * Moved do_sigtrap from traps.c to entry.S.
+ * * LTASK_PID need not be global anymore.
+ *
+ * Revision 1.18 2001/03/26 09:25:02 markusl
+ * Updated after review, should now handle USB interrupts correctly.
+ *
+ * Revision 1.17 2001/03/21 16:12:55 bjornw
+ * * Always make room for the cpu status record in the frame, in order to
+ * use the same framelength and layout for both mmu busfaults and normal
+ * irqs. No need to check for the explicit CRIS_FRAME_FIXUP type anymore.
+ * * Fixed bug with using addq for popping the stack in the epilogue - it
+ * destroyed the flag register. Use instructions that don't affect the
+ * flag register instead.
+ * * Removed write to R_PORT_PA_DATA during spurious_interrupt
+ *
+ * Revision 1.16 2001/03/20 19:43:02 bjornw
+ * * Get rid of esp0 setting
+ * * Give a 7th argument to a systemcall - the stackframe
+ *
+ * Revision 1.15 2001/03/05 13:14:30 bjornw
+ * Spelling fix
+ *
+ * Revision 1.14 2001/02/23 08:36:36 perf
+ * New ABI; syscallnr=r9, arg5=mof, arg6=srp.
+ * Corrected tracesys call check.
+ *
+ * Revision 1.13 2001/02/15 08:40:55 perf
+ * H-P by way of perf;
+ * - (_system_call): Don't read system call function address into r1.
+ * - (RBFExit): There is no such thing as a null pop. Adjust sp by addq.
+ * - (_system_call): Don't use r10 and don't save and restore it.
+ * - (THREAD_ESP0): New constant.
+ * - (_system_call): Inline set_esp0.
+ *
+ * Revision 1.12 2001/01/31 17:56:25 orjanf
+ * Added definition of LTASK_PID and made it global.
+ *
+ * Revision 1.11 2001/01/10 21:13:29 bjornw
+ * SYMBOL_NAME is defined incorrectly for the compiler options we currently use
+ *
+ * Revision 1.10 2000/12/18 23:47:56 bjornw
+ * * Added syscall trace support (ptrace), completely untested of course
+ * * Removed redundant check for NULL entries in syscall_table
+ *
+ * Revision 1.9 2000/11/21 16:40:51 bjornw
+ * * New frame type used when an SBFS frame needs to be popped without
+ * actually restarting the instruction
+ * * Enable interrupts in signal_return (they did so in x86, I hope it's a good
+ * idea)
+ *
+ * Revision 1.8 2000/11/17 16:53:35 bjornw
+ * Added detection of frame-type in Rexit, so that mmu_bus_fault can
+ * use ret_from_intr in the return-path to check for signals (like SEGV)
+ * and other foul things that might have occurred during the fault.
+ *
+ * Revision 1.7 2000/10/06 15:04:28 bjornw
+ * Include mof in register savings
+ *
+ * Revision 1.6 2000/09/12 16:02:44 bjornw
+ * Linux-2.4.0-test7 derived updates
+ *
+ * Revision 1.5 2000/08/17 15:35:15 bjornw
+ * 2.4.0-test6 changed local_irq_count and friends API
+ *
+ * Revision 1.4 2000/08/02 13:59:30 bjornw
+ * Removed olduname and uname from the syscall list
+ *
+ * Revision 1.3 2000/07/31 13:32:58 bjornw
+ * * Export ret_from_intr
+ * * _resume updated (prev/last tjohejsan)
+ * * timer_interrupt obsolete
+ * * SIGSEGV detection in mmu_bus_fault temporarily disabled
+ *
+ *
+ */
+
+/*
+ * entry.S contains the system-call and fault low-level handling routines.
+ *
+ * NOTE: This code handles signal-recognition, which happens every time
+ * after a timer-interrupt and after each system call.
+ *
+ * Stack layout in 'ret_from_system_call':
+ * ptrace needs to have all regs on the stack.
+ * if the order here is changed, it needs to be
+ * updated in fork.c:copy_process, signal.c:do_signal,
+ * ptrace.c and ptrace.h
+ *
+ */
+
+#include <linux/config.h>
+#include <linux/linkage.h>
+#include <linux/sys.h>
+#include <asm/unistd.h>
+#include <asm/arch/sv_addr_ag.h>
+#include <asm/errno.h>
+#include <asm/thread_info.h>
+#include <asm/arch/offset.h>
+#include <asm/page.h>
+#include <asm/pgtable.h>
+
+ ;; functions exported from this file
+
+ .globl system_call
+ .globl ret_from_intr
+ .globl ret_from_fork
+ .globl resume
+ .globl multiple_interrupt
+ .globl hwbreakpoint
+ .globl IRQ1_interrupt
+ .globl spurious_interrupt
+ .globl hw_bp_trigs
+ .globl mmu_bus_fault
+ .globl do_sigtrap
+ .globl gdb_handle_breakpoint
+ .globl sys_call_table
+
+ ;; below are various parts of system_call which are not in the fast-path
+
+#ifdef CONFIG_PREEMPT
+ ; Check if preemptive kernel scheduling should be done
+_resume_kernel:
+ ; Load current task struct
+ movs.w -8192, $r0 ; THREAD_SIZE = 8192
+ and.d $sp, $r0
+ move.d [$r0+TI_preempt_count], $r10 ; Preemption disabled?
+ bne _Rexit
+ nop
+_need_resched:
+ move.d [$r0+TI_flags], $r10
+ btstq TIF_NEED_RESCHED, $r10 ; Check if need_resched is set
+ bpl _Rexit
+ nop
+ ; Ok, lets's do some preemptive kernel scheduling
+ move.d PREEMPT_ACTIVE, $r10
+ move.d $r10, [$r0+TI_preempt_count] ; Mark as active
+ ei
+ jsr schedule
+ clear.d [$r0+TI_preempt_count] ; Mark as inactive
+ di
+ ; Load new task struct
+ movs.w -8192, $r0 ; THREAD_SIZE = 8192
+ and.d $sp, $r0
+ ; One more time (with new task)
+ ba _need_resched
+ nop
+#else
+#define _resume_kernel _Rexit
+#endif
+
+ ; Called at exit from fork. schedule_tail must be called to drop
+ ; spinlock if CONFIG_PREEMPT
+ret_from_fork:
+ jsr schedule_tail
+ ba ret_from_sys_call
+ nop
+
+ret_from_intr:
+ ;; check for resched if preemptive kernel or if we're going back to user-mode
+ ;; this test matches the user_regs(regs) macro
+ ;; we cannot simply test $dccr, because that does not necessarily
+ ;; reflect what mode we'll return into.
+
+ move.d [$sp + PT_dccr], $r0; regs->dccr
+ btstq 8, $r0 ; U-flag
+ bpl _resume_kernel
+ ; Note that di below is in delay slot
+
+_resume_userspace:
+ di ; so need_resched and sigpending don't change
+
+ movs.w -8192, $r0 ; THREAD_SIZE == 8192
+ and.d $sp, $r0
+
+ move.d [$r0+TI_flags], $r10 ; current->work
+ and.d _TIF_WORK_MASK, $r10 ; is there any work to be done on return
+ bne _work_pending
+ nop
+ ba _Rexit
+ nop
+
+ ;; The system_call is called by a BREAK instruction, which works like
+ ;; an interrupt call but it stores the return PC in BRP instead of IRP.
+ ;; Since we dont really want to have two epilogues (one for system calls
+ ;; and one for interrupts) we push the contents of BRP instead of IRP in the
+ ;; system call prologue, to make it look like an ordinary interrupt on the
+ ;; stackframe.
+ ;;
+ ;; Since we can't have system calls inside interrupts, it should not matter
+ ;; that we don't stack IRP.
+ ;;
+ ;; In r9 we have the wanted syscall number. Arguments come in r10,r11,r12,r13,mof,srp
+ ;;
+ ;; This function looks on the _surface_ like spaghetti programming, but it's
+ ;; really designed so that the fast-path does not force cache-loading of non-used
+ ;; instructions. Only the non-common cases cause the outlined code to run..
+
+system_call:
+ ;; stack-frame similar to the irq heads, which is reversed in ret_from_sys_call
+ move $brp,[$sp=$sp-16]; instruction pointer and room for a fake SBFS frame
+ push $srp
+ push $dccr
+ push $mof
+ subq 14*4, $sp ; make room for r0-r13
+ movem $r13, [$sp] ; push r0-r13
+ push $r10 ; push orig_r10
+ clear.d [$sp=$sp-4] ; frametype == 0, normal stackframe
+
+ movs.w -ENOSYS, $r0
+ move.d $r0, [$sp+PT_r10] ; put the default return value in r10 in the frame
+
+ ;; check if this process is syscall-traced
+
+ movs.w -8192, $r0 ; THREAD_SIZE == 8192
+ and.d $sp, $r0
+
+ move.d [$r0+TI_flags], $r0
+ btstq TIF_SYSCALL_TRACE, $r0
+ bmi _syscall_trace_entry
+ nop
+
+_syscall_traced:
+
+ ;; check for sanity in the requested syscall number
+
+ cmpu.w NR_syscalls, $r9
+ bcc ret_from_sys_call
+ lslq 2, $r9 ; multiply by 4, in the delay slot
+
+ ;; as a bonus 7th parameter, we give the location on the stack
+ ;; of the register structure itself. some syscalls need this.
+
+ push $sp
+
+ ;; the parameter carrying registers r10, r11, r12 and 13 are intact.
+ ;; the fifth and sixth parameters (if any) was in mof and srp
+ ;; respectively, and we need to put them on the stack.
+
+