1 |
/* |
/* |
2 |
* Copyright (C) 2004-2005 Anders Gavare. All rights reserved. |
* Copyright (C) 2004-2006 Anders Gavare. All rights reserved. |
3 |
* |
* |
4 |
* Redistribution and use in source and binary forms, with or without |
* Redistribution and use in source and binary forms, with or without |
5 |
* modification, are permitted provided that the following conditions are met: |
* modification, are permitted provided that the following conditions are met: |
25 |
* SUCH DAMAGE. |
* SUCH DAMAGE. |
26 |
* |
* |
27 |
* |
* |
28 |
* $Id: dev_8250.c,v 1.17 2005/10/26 14:37:03 debug Exp $ |
* $Id: dev_8250.c,v 1.24 2006/07/21 16:55:41 debug Exp $ |
29 |
* |
* |
30 |
* 8250 serial controller. |
* 8250 serial controller. |
31 |
* |
* |
45 |
|
|
46 |
|
|
47 |
struct dev_8250_data { |
struct dev_8250_data { |
|
int reg[8]; |
|
|
|
|
48 |
int console_handle; |
int console_handle; |
49 |
|
char *name; |
50 |
|
|
51 |
int irq_enable; |
int irq_enable; |
52 |
int irqnr; |
int irqnr; |
53 |
|
int in_use; |
54 |
int addrmult; |
int addrmult; |
55 |
|
|
56 |
|
int reg[8]; |
57 |
|
|
58 |
int dlab; /* Divisor Latch Access bit */ |
int dlab; /* Divisor Latch Access bit */ |
59 |
int divisor; |
int divisor; |
60 |
int databits; |
int databits; |
63 |
}; |
}; |
64 |
|
|
65 |
#define DEV_8250_LENGTH 8 |
#define DEV_8250_LENGTH 8 |
66 |
|
#define DEV_8250_TICKSHIFT 15 |
67 |
|
|
68 |
|
|
69 |
/* |
DEVICE_TICK(8250) |
|
* dev_8250_tick(): |
|
|
* |
|
|
*/ |
|
|
void dev_8250_tick(struct cpu *cpu, void *extra) |
|
70 |
{ |
{ |
71 |
#if 0 |
#if 0 |
72 |
/* This stuff works for 16550. TODO for 8250 */ |
/* This stuff works for 16550. TODO for 8250 */ |
96 |
} |
} |
97 |
|
|
98 |
|
|
99 |
/* |
DEVICE_ACCESS(8250) |
|
* dev_8250_access(): |
|
|
*/ |
|
|
int dev_8250_access(struct cpu *cpu, struct memory *mem, uint64_t relative_addr, |
|
|
unsigned char *data, size_t len, int writeflag, void *extra) |
|
100 |
{ |
{ |
101 |
uint64_t idata = 0, odata = 0; |
uint64_t idata = 0, odata = 0; |
102 |
struct dev_8250_data *d = extra; |
struct dev_8250_data *d = extra; |
106 |
|
|
107 |
relative_addr /= d->addrmult; |
relative_addr /= d->addrmult; |
108 |
|
|
109 |
if (writeflag == MEM_WRITE && relative_addr == 0) |
if (writeflag == MEM_WRITE && relative_addr == 0) { |
110 |
console_putchar(d->console_handle, idata); |
console_putchar(d->console_handle, idata); |
111 |
else |
} else if (writeflag == MEM_READ && relative_addr == 5) { |
|
if (writeflag == MEM_READ && relative_addr == 5) |
|
112 |
odata = 64 + 32; |
odata = 64 + 32; |
113 |
else { |
} else { |
114 |
#if 0 |
#if 0 |
115 |
if (writeflag == MEM_WRITE) |
if (writeflag == MEM_WRITE) |
116 |
fatal("[ 8250: write addr=0x%02x idata = 0x%02x ]\n", |
fatal("[ 8250: write addr=0x%02x idata = 0x%02x ]\n", |
127 |
} |
} |
128 |
|
|
129 |
|
|
130 |
/* |
DEVINIT(8250) |
|
* devinit_8250(): |
|
|
*/ |
|
|
int devinit_8250(struct devinit *devinit) |
|
131 |
{ |
{ |
132 |
|
size_t nlen; |
133 |
|
char *name; |
134 |
struct dev_8250_data *d; |
struct dev_8250_data *d; |
135 |
|
|
136 |
d = malloc(sizeof(struct dev_8250_data)); |
d = malloc(sizeof(struct dev_8250_data)); |
139 |
exit(1); |
exit(1); |
140 |
} |
} |
141 |
memset(d, 0, sizeof(struct dev_8250_data)); |
memset(d, 0, sizeof(struct dev_8250_data)); |
142 |
d->irqnr = devinit->irq_nr; |
d->irqnr = devinit->irq_nr; |
143 |
d->addrmult = devinit->addr_mult; |
d->addrmult = devinit->addr_mult; |
144 |
d->console_handle = console_start_slave(devinit->machine, "console"); |
d->in_use = devinit->in_use; |
145 |
d->dlab = 0; |
d->dlab = 0; |
146 |
d->divisor = 115200 / 9600; |
d->divisor = 115200 / 9600; |
147 |
d->databits = 8; |
d->databits = 8; |
148 |
d->parity = 'N'; |
d->parity = 'N'; |
149 |
d->stopbits = "1"; |
d->stopbits = "1"; |
150 |
|
d->name = devinit->name2 != NULL? devinit->name2 : ""; |
151 |
|
d->console_handle = |
152 |
|
console_start_slave(devinit->machine, devinit->name2 != NULL? |
153 |
|
devinit->name2 : devinit->name, d->in_use); |
154 |
|
|
155 |
|
nlen = strlen(devinit->name) + 10; |
156 |
|
if (devinit->name2 != NULL) |
157 |
|
nlen += strlen(devinit->name2); |
158 |
|
name = malloc(nlen); |
159 |
|
if (name == NULL) { |
160 |
|
fprintf(stderr, "out of memory\n"); |
161 |
|
exit(1); |
162 |
|
} |
163 |
|
if (devinit->name2 != NULL && devinit->name2[0]) |
164 |
|
snprintf(name, nlen, "%s [%s]", devinit->name, devinit->name2); |
165 |
|
else |
166 |
|
snprintf(name, nlen, "%s", devinit->name); |
167 |
|
|
168 |
memory_device_register(devinit->machine->memory, devinit->name, |
memory_device_register(devinit->machine->memory, name, |
169 |
devinit->addr, DEV_8250_LENGTH * devinit->addr_mult, |
devinit->addr, DEV_8250_LENGTH * devinit->addr_mult, |
170 |
dev_8250_access, d, MEM_DEFAULT, NULL); |
dev_8250_access, d, DM_DEFAULT, NULL); |
171 |
machine_add_tickfunction(devinit->machine, dev_8250_tick, d, 14); |
machine_add_tickfunction(devinit->machine, dev_8250_tick, d, |
172 |
|
DEV_8250_TICKSHIFT, 0.0); |
173 |
|
|
174 |
return 1; |
return 1; |
175 |
} |
} |