blob: 17049aaa8f11832cf4a431e9a9e4a09282dd2208 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * arch/v850/kernel/sim.c -- Machine-specific stuff for GDB v850e simulator
3 *
4 * Copyright (C) 2001,02 NEC Corporation
5 * Copyright (C) 2001,02 Miles Bader <miles@gnu.org>
6 *
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.
10 *
11 * Written by Miles Bader <miles@gnu.org>
12 */
13
14#include <linux/config.h>
15#include <linux/kernel.h>
16#include <linux/module.h>
17#include <linux/init.h>
18#include <linux/mm.h>
19#include <linux/swap.h>
20#include <linux/bootmem.h>
21#include <linux/irq.h>
22
23#include <asm/atomic.h>
24#include <asm/page.h>
25#include <asm/machdep.h>
26#include <asm/simsyscall.h>
27
28#include "mach.h"
29
30/* The name of a file containing the root filesystem. */
31#define ROOT_FS "rootfs.image"
32
33extern void simcons_setup (void);
34extern void simcons_poll_ttys (void);
35extern void set_mem_root (void *addr, size_t len, char *cmd_line);
36
37static int read_file (const char *name,
38 unsigned long *addr, unsigned long *len,
39 const char **err);
40
41void __init mach_setup (char **cmdline)
42{
43 const char *err;
44 unsigned long root_dev_addr, root_dev_len;
45
46 simcons_setup ();
47
48 printk (KERN_INFO "Reading root filesystem: %s", ROOT_FS);
49
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,
53 *cmdline);
54 } else
55 printk ("...%s failed!\n", err);
56}
57
58void mach_get_physical_ram (unsigned long *ram_start, unsigned long *ram_len)
59{
60 *ram_start = RAM_ADDR;
61 *ram_len = RAM_SIZE;
62}
63
64void __init mach_sched_init (struct irqaction *timer_action)
65{
66 /* ...do magic timer initialization?... */
67 mach_tick = simcons_poll_ttys;
68 setup_irq (0, timer_action);
69}
70
71
72static void irq_nop (unsigned irq) { }
73static unsigned irq_zero (unsigned irq) { return 0; }
74
75static struct hw_interrupt_type sim_irq_type = {
Thomas Gleixneraecd4562005-09-10 00:26:43 -070076 .typename = "IRQ",
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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070083};
84
85void __init mach_init_irqs (void)
86{
87 init_irq_handlers (0, NUM_MACH_IRQS, 1, &sim_irq_type);
88}
89
90
91void mach_gettimeofday (struct timespec *tv)
92{
93 long timeval[2], timezone[2];
94 int rval = V850_SIM_SYSCALL (gettimeofday, timeval, timezone);
95 if (rval == 0) {
96 tv->tv_sec = timeval[0];
97 tv->tv_nsec = timeval[1] * 1000;
98 }
99}
100
101void machine_restart (char *__unused)
102{
103 V850_SIM_SYSCALL (write, 1, "RESTART\n", 8);
104 V850_SIM_SYSCALL (exit, 0);
105}
106
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107void machine_halt (void)
108{
109 V850_SIM_SYSCALL (write, 1, "HALT\n", 5);
110 V850_SIM_SYSCALL (exit, 0);
111}
112
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113void machine_power_off (void)
114{
115 V850_SIM_SYSCALL (write, 1, "POWER OFF\n", 10);
116 V850_SIM_SYSCALL (exit, 0);
117}
118
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
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. */
122static int __init
123read_file (const char *name,
124 unsigned long *addr, unsigned long *len,
125 const char **err)
126{
127 int rval, fd;
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];
132
133 /* Stat the file to find out the length. */
134 rval = V850_SIM_SYSCALL (stat, name, stat_buf);
135 if (rval < 0) {
136 if (err) *err = "stat";
137 return 0;
138 }
139 *len = stat_buf[4];
140
141 /* Open the file; `0' is O_RDONLY. */
142 fd = V850_SIM_SYSCALL (open, name, 0);
143 if (fd < 0) {
144 if (err) *err = "open";
145 return 0;
146 }
147
148 *addr = (unsigned long)alloc_bootmem(*len);
149 if (! *addr) {
150 V850_SIM_SYSCALL (close, fd);
151 if (err) *err = "alloc_bootmem";
152 return 0;
153 }
154
155 cur = *addr;
156 left = *len;
157 while (left > 0) {
158 int chunk = V850_SIM_SYSCALL (read, fd, cur, left);
159 if (chunk <= 0)
160 break;
161 cur += chunk;
162 left -= chunk;
163 }
164 V850_SIM_SYSCALL (close, fd);
165 if (left > 0) {
166 /* Some read failed. */
167 free_bootmem (*addr, *len);
168 if (err) *err = "read";
169 return 0;
170 }
171
172 return 1;
173}