2 * arch/v850/kernel/sim.c -- Machine-specific stuff for GDB v850e simulator
4 * Copyright (C) 2001,02 NEC Corporation
5 * Copyright (C) 2001,02 Miles Bader <miles@gnu.org>
7 * This file is subject to the terms and conditions of the GNU General
8 * Public License. See the file COPYING in the main directory of this
9 * archive for more details.
11 * Written by Miles Bader <miles@gnu.org>
14 #include <linux/config.h>
15 #include <linux/kernel.h>
16 #include <linux/module.h>
17 #include <linux/init.h>
19 #include <linux/swap.h>
20 #include <linux/bootmem.h>
21 #include <linux/irq.h>
23 #include <asm/atomic.h>
25 #include <asm/machdep.h>
26 #include <asm/simsyscall.h>
30 /* The name of a file containing the root filesystem. */
31 #define ROOT_FS "rootfs.image"
33 extern void simcons_setup (void);
34 extern void simcons_poll_ttys (void);
35 extern void set_mem_root (void *addr, size_t len, char *cmd_line);
37 static int read_file (const char *name,
38 unsigned long *addr, unsigned long *len,
41 void __init mach_setup (char **cmdline)
44 unsigned long root_dev_addr, root_dev_len;
48 printk (KERN_INFO "Reading root filesystem: %s", ROOT_FS);
50 if (read_file (ROOT_FS, &root_dev_addr, &root_dev_len, &err)) {
51 printk (" (size %luK)\n", root_dev_len / 1024);
52 set_mem_root ((void *)root_dev_addr, (size_t)root_dev_len,
55 printk ("...%s failed!\n", err);
58 void mach_get_physical_ram (unsigned long *ram_start, unsigned long *ram_len)
60 *ram_start = RAM_ADDR;
64 void __init mach_sched_init (struct irqaction *timer_action)
66 /* ...do magic timer initialization?... */
67 mach_tick = simcons_poll_ttys;
68 setup_irq (0, timer_action);
72 static void irq_nop (unsigned irq) { }
73 static unsigned irq_zero (unsigned irq) { return 0; }
75 static struct hw_interrupt_type sim_irq_type = {
77 irq_zero, /* startup */
78 irq_nop, /* shutdown */
80 irq_nop, /* disable */
85 void __init mach_init_irqs (void)
87 init_irq_handlers (0, NUM_MACH_IRQS, 1, &sim_irq_type);
91 void mach_gettimeofday (struct timespec *tv)
93 long timeval[2], timezone[2];
94 int rval = V850_SIM_SYSCALL (gettimeofday, timeval, timezone);
96 tv->tv_sec = timeval[0];
97 tv->tv_nsec = timeval[1] * 1000;
101 void machine_restart (char *__unused)
103 V850_SIM_SYSCALL (write, 1, "RESTART\n", 8);
104 V850_SIM_SYSCALL (exit, 0);
107 EXPORT_SYMBOL(machine_restart);
109 void machine_halt (void)
111 V850_SIM_SYSCALL (write, 1, "HALT\n", 5);
112 V850_SIM_SYSCALL (exit, 0);
115 EXPORT_SYMBOL(machine_halt);
117 void machine_power_off (void)
119 V850_SIM_SYSCALL (write, 1, "POWER OFF\n", 10);
120 V850_SIM_SYSCALL (exit, 0);
123 EXPORT_SYMBOL(machine_power_off);
126 /* Load data from a file called NAME into ram. The address and length
127 of the data image are returned in ADDR and LEN. */
129 read_file (const char *name,
130 unsigned long *addr, unsigned long *len,
134 unsigned long cur, left;
135 /* Note this is not a normal stat buffer, it's an ad-hoc
136 structure defined by the simulator. */
137 unsigned long stat_buf[10];
139 /* Stat the file to find out the length. */
140 rval = V850_SIM_SYSCALL (stat, name, stat_buf);
142 if (err) *err = "stat";
147 /* Open the file; `0' is O_RDONLY. */
148 fd = V850_SIM_SYSCALL (open, name, 0);
150 if (err) *err = "open";
154 *addr = (unsigned long)alloc_bootmem(*len);
156 V850_SIM_SYSCALL (close, fd);
157 if (err) *err = "alloc_bootmem";
164 int chunk = V850_SIM_SYSCALL (read, fd, cur, left);
170 V850_SIM_SYSCALL (close, fd);
172 /* Some read failed. */
173 free_bootmem (*addr, *len);
174 if (err) *err = "read";