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 .startup
= irq_zero
, /* startup */
78 .shutdown
= irq_nop
, /* shutdown */
79 .enable
= irq_nop
, /* enable */
80 .disable
= irq_nop
, /* disable */
81 .ack
= irq_nop
, /* ack */
82 .end
= irq_nop
, /* end */
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 void machine_halt (void)
109 V850_SIM_SYSCALL (write
, 1, "HALT\n", 5);
110 V850_SIM_SYSCALL (exit
, 0);
113 void machine_power_off (void)
115 V850_SIM_SYSCALL (write
, 1, "POWER OFF\n", 10);
116 V850_SIM_SYSCALL (exit
, 0);
120 /* Load data from a file called NAME into ram. The address and length
121 of the data image are returned in ADDR and LEN. */
123 read_file (const char *name
,
124 unsigned long *addr
, unsigned long *len
,
128 unsigned long cur
, left
;
129 /* Note this is not a normal stat buffer, it's an ad-hoc
130 structure defined by the simulator. */
131 unsigned long stat_buf
[10];
133 /* Stat the file to find out the length. */
134 rval
= V850_SIM_SYSCALL (stat
, name
, stat_buf
);
136 if (err
) *err
= "stat";
141 /* Open the file; `0' is O_RDONLY. */
142 fd
= V850_SIM_SYSCALL (open
, name
, 0);
144 if (err
) *err
= "open";
148 *addr
= (unsigned long)alloc_bootmem(*len
);
150 V850_SIM_SYSCALL (close
, fd
);
151 if (err
) *err
= "alloc_bootmem";
158 int chunk
= V850_SIM_SYSCALL (read
, fd
, cur
, left
);
164 V850_SIM_SYSCALL (close
, fd
);
166 /* Some read failed. */
167 free_bootmem (*addr
, *len
);
168 if (err
) *err
= "read";