dev_palmbus.cc Source File

Back to the index.

dev_palmbus.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2018 Anders Gavare. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * 1. Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * 3. The name of the author may not be used to endorse or promote products
13  * derived from this software without specific prior written permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  *
27  *
28  * COMMENT: VoCore Palmbus
29  *
30  * TODO
31  */
32 
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <string.h>
36 
37 #include "cpu.h"
38 #include "console.h"
39 #include "device.h"
40 #include "emul.h"
41 #include "machine.h"
42 #include "memory.h"
43 #include "misc.h"
44 
45 
46 #define DEV_PALMBUS_LENGTH 0x1000
47 
48 struct palmbus_data {
49  // struct interrupt irq;
51 };
52 
53 
54 DEVICE_ACCESS(palmbus)
55 {
56  struct palmbus_data *d = (struct palmbus_data *) extra;
57  uint64_t idata = 0, odata = 0;
58  int regnr;
59 
60  if (writeflag == MEM_WRITE)
61  idata = memory_readmax64(cpu, data, len);
62 
63  switch (relative_addr) {
64 
65  case 0x0000:
66  odata = 0x30335452;
67  break;
68 
69  case 0x0004:
70  odata = 0x20203235;
71  break;
72 
73  case 0x000c:
74  /* Linux boot message says "SoC Type: Ralink RT5350 id:1 rev:3" */
75  odata = 0x00000103;
76  break;
77 
78  case 0x0c04:
80  break;
81 
82  case 0x0c1c:
83  odata = 0x20; // Serial ready (?)
84  break;
85 
86  default:
87  if (writeflag == MEM_WRITE) {
88  fatal("[ palmbus: unimplemented write to address 0x%x"
89  ", data=0x%02x ]\n",
90  (int)relative_addr, (int)idata);
91  } else {
92  fatal("[ palmbus: unimplemented read from address 0x%x "
93  "]\n", (int)relative_addr);
94  }
95  /* exit(1); */
96  }
97 
98  if (writeflag == MEM_READ)
99  memory_writemax64(cpu, data, len, odata);
100 
101  return 1;
102 }
103 
104 
105 DEVINIT(palmbus)
106 {
107  char *name2;
108  size_t nlen = 55;
109  struct palmbus_data *d;
110 
111  CHECK_ALLOCATION(d = (struct palmbus_data *) malloc(sizeof(struct palmbus_data)));
112  memset(d, 0, sizeof(struct palmbus_data));
113 
114  // INTERRUPT_CONNECT(devinit->interrupt_path, d->irq);
115 
116  d->console_handle = console_start_slave(devinit->machine, "uartlite", 1);
117 
120  dev_palmbus_access, (void *)d, DM_DEFAULT, NULL);
121 
122  return 1;
123 }
124 
uint64_t memory_readmax64(struct cpu *cpu, unsigned char *buf, int len)
Definition: memory.cc:55
void fatal(const char *fmt,...)
Definition: main.cc:152
#define DM_DEFAULT
Definition: memory.h:130
int console_handle
Definition: dev_palmbus.cc:50
#define MEM_READ
Definition: memory.h:116
DEVICE_ACCESS(palmbus)
Definition: dev_palmbus.cc:54
struct memory * memory
Definition: machine.h:126
void console_putchar(int handle, int ch)
Definition: console.cc:405
#define DEV_PALMBUS_LENGTH
Definition: dev_palmbus.cc:46
#define CHECK_ALLOCATION(ptr)
Definition: misc.h:239
u_short data
Definition: siireg.h:79
#define MEM_WRITE
Definition: memory.h:117
Definition: device.h:40
Definition: cpu.h:326
struct machine * machine
Definition: device.h:41
DEVINIT(palmbus)
Definition: dev_palmbus.cc:105
void memory_writemax64(struct cpu *cpu, unsigned char *buf, int len, uint64_t data)
Definition: memory.cc:89
int console_start_slave(struct machine *machine, const char *consolename, int use_for_input)
Definition: console.cc:668
void memory_device_register(struct memory *mem, const char *, uint64_t baseaddr, uint64_t len, int(*f)(struct cpu *, struct memory *, uint64_t, unsigned char *, size_t, int, void *), void *extra, int flags, unsigned char *dyntrans_data)
Definition: memory.cc:339
uint64_t addr
Definition: device.h:46

Generated on Sun Sep 30 2018 16:05:18 for GXemul by doxygen 1.8.13