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/kernel.h>
15 #include <linux/module.h>
16 #include <linux/init.h>
18 #include <linux/swap.h>
19 #include <linux/bootmem.h>
20 #include <linux/irq.h>
22 #include <asm/atomic.h>
24 #include <asm/machdep.h>
25 #include <asm/simsyscall.h>
29 /* The name of a file containing the root filesystem. */
30 #define ROOT_FS "rootfs.image"
32 extern void simcons_setup (void);
33 extern void simcons_poll_ttys (void);
34 extern void set_mem_root (void *addr
, size_t len
, char *cmd_line
);
36 static int read_file (const char *name
,
37 unsigned long *addr
, unsigned long *len
,
40 void __init
mach_setup (char **cmdline
)
43 unsigned long root_dev_addr
, root_dev_len
;
47 printk (KERN_INFO
"Reading root filesystem: %s", ROOT_FS
);
49 if (read_file (ROOT_FS
, &root_dev_addr
, &root_dev_len
, &err
)) {
50 printk (" (size %luK)\n", root_dev_len
/ 1024);
51 set_mem_root ((void *)root_dev_addr
, (size_t)root_dev_len
,
54 printk ("...%s failed!\n", err
);
57 void mach_get_physical_ram (unsigned long *ram_start
, unsigned long *ram_len
)
59 *ram_start
= RAM_ADDR
;
63 void __init
mach_sched_init (struct irqaction
*timer_action
)
65 /* ...do magic timer initialization?... */
66 mach_tick
= simcons_poll_ttys
;
67 setup_irq (0, timer_action
);
71 static void irq_nop (unsigned irq
) { }
72 static unsigned irq_zero (unsigned irq
) { return 0; }
74 static struct hw_interrupt_type sim_irq_type
= {
76 .startup
= irq_zero
, /* startup */
77 .shutdown
= irq_nop
, /* shutdown */
78 .enable
= irq_nop
, /* enable */
79 .disable
= irq_nop
, /* disable */
80 .ack
= irq_nop
, /* ack */
81 .end
= irq_nop
, /* end */
84 void __init
mach_init_irqs (void)
86 init_irq_handlers (0, NUM_MACH_IRQS
, 1, &sim_irq_type
);
90 void mach_gettimeofday (struct timespec
*tv
)
92 long timeval
[2], timezone
[2];
93 int rval
= V850_SIM_SYSCALL (gettimeofday
, timeval
, timezone
);
95 tv
->tv_sec
= timeval
[0];
96 tv
->tv_nsec
= timeval
[1] * 1000;
100 void machine_restart (char *__unused
)
102 V850_SIM_SYSCALL (write
, 1, "RESTART\n", 8);
103 V850_SIM_SYSCALL (exit
, 0);
106 void machine_halt (void)
108 V850_SIM_SYSCALL (write
, 1, "HALT\n", 5);
109 V850_SIM_SYSCALL (exit
, 0);
112 void machine_power_off (void)
114 V850_SIM_SYSCALL (write
, 1, "POWER OFF\n", 10);
115 V850_SIM_SYSCALL (exit
, 0);
119 /* Load data from a file called NAME into ram. The address and length
120 of the data image are returned in ADDR and LEN. */
122 read_file (const char *name
,
123 unsigned long *addr
, unsigned long *len
,
127 unsigned long cur
, left
;
128 /* Note this is not a normal stat buffer, it's an ad-hoc
129 structure defined by the simulator. */
130 unsigned long stat_buf
[10];
132 /* Stat the file to find out the length. */
133 rval
= V850_SIM_SYSCALL (stat
, name
, stat_buf
);
135 if (err
) *err
= "stat";
140 /* Open the file; `0' is O_RDONLY. */
141 fd
= V850_SIM_SYSCALL (open
, name
, 0);
143 if (err
) *err
= "open";
147 *addr
= (unsigned long)alloc_bootmem(*len
);
149 V850_SIM_SYSCALL (close
, fd
);
150 if (err
) *err
= "alloc_bootmem";
157 int chunk
= V850_SIM_SYSCALL (read
, fd
, cur
, left
);
163 V850_SIM_SYSCALL (close
, fd
);
165 /* Some read failed. */
166 free_bootmem (*addr
, *len
);
167 if (err
) *err
= "read";