dev_palmbus.cc Source File
Back to the index.
src
devices
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;
50
int
console_handle
;
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
59
if
(writeflag ==
MEM_WRITE
)
60
idata =
memory_readmax64
(
cpu
,
data
, len);
61
62
switch
(relative_addr) {
63
64
case
0x0000:
65
odata = 0x30335452;
66
break
;
67
68
case
0x0004:
69
odata = 0x20203235;
70
break
;
71
72
case
0x000c:
73
/* Linux boot message says "SoC Type: Ralink RT5350 id:1 rev:3" */
74
odata = 0x00000103;
75
break
;
76
77
case
0x0c04:
78
console_putchar
(d->
console_handle
, idata);
79
break
;
80
81
case
0x0c1c:
82
odata = 0x20;
// Serial ready (?)
83
break
;
84
85
default
:
86
if
(writeflag ==
MEM_WRITE
) {
87
fatal
(
"[ palmbus: unimplemented write to address 0x%x"
88
", data=0x%02x ]\n"
,
89
(
int
)relative_addr, (
int
)idata);
90
}
else
{
91
fatal
(
"[ palmbus: unimplemented read from address 0x%x "
92
"]\n"
, (
int
)relative_addr);
93
}
94
/* exit(1); */
95
}
96
97
if
(writeflag ==
MEM_READ
)
98
memory_writemax64
(
cpu
,
data
, len, odata);
99
100
return
1;
101
}
102
103
104
DEVINIT
(palmbus)
105
{
106
char
*name2;
107
struct
palmbus_data
*d;
108
109
CHECK_ALLOCATION
(d = (
struct
palmbus_data
*) malloc(
sizeof
(
struct
palmbus_data
)));
110
memset(d, 0,
sizeof
(
struct
palmbus_data
));
111
112
// INTERRUPT_CONNECT(devinit->interrupt_path, d->irq);
113
114
d->
console_handle
=
console_start_slave
(
devinit
->
machine
,
"uartlite"
, 1);
115
116
memory_device_register
(
devinit
->
machine
->
memory
, name2,
117
devinit
->
addr
,
DEV_PALMBUS_LENGTH
,
118
dev_palmbus_access, (
void
*)d,
DM_DEFAULT
, NULL);
119
120
return
1;
121
}
122
data
u_short data
Definition:
siireg.h:79
DEVICE_ACCESS
DEVICE_ACCESS(palmbus)
Definition:
dev_palmbus.cc:54
console_putchar
void console_putchar(int handle, int ch)
Definition:
console.cc:405
DEV_PALMBUS_LENGTH
#define DEV_PALMBUS_LENGTH
Definition:
dev_palmbus.cc:46
devinit::addr
uint64_t addr
Definition:
device.h:46
memory_device_register
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
MEM_READ
#define MEM_READ
Definition:
memory.h:116
DM_DEFAULT
#define DM_DEFAULT
Definition:
memory.h:130
devinit::machine
struct machine * machine
Definition:
device.h:41
console.h
device.h
MEM_WRITE
#define MEM_WRITE
Definition:
memory.h:117
fatal
void fatal(const char *fmt,...)
Definition:
main.cc:152
palmbus_data::console_handle
int console_handle
Definition:
dev_palmbus.cc:50
misc.h
memory_readmax64
uint64_t memory_readmax64(struct cpu *cpu, unsigned char *buf, int len)
Definition:
memory.cc:55
machine.h
emul.h
devinit
Definition:
device.h:40
console_start_slave
int console_start_slave(struct machine *machine, const char *consolename, int use_for_input)
Definition:
console.cc:668
cpu.h
machine::memory
struct memory * memory
Definition:
machine.h:126
palmbus_data
Definition:
dev_palmbus.cc:48
memory_writemax64
void memory_writemax64(struct cpu *cpu, unsigned char *buf, int len, uint64_t data)
Definition:
memory.cc:89
DEVINIT
DEVINIT(palmbus)
Definition:
dev_palmbus.cc:104
cpu
Definition:
cpu.h:326
memory.h
CHECK_ALLOCATION
#define CHECK_ALLOCATION(ptr)
Definition:
misc.h:239
Generated on Tue Mar 24 2020 14:04:48 for GXemul by
1.8.17