25 |
* SUCH DAMAGE. |
* SUCH DAMAGE. |
26 |
* |
* |
27 |
* |
* |
28 |
* $Id: dev_ns16550.c,v 1.58 2006/12/30 13:30:58 debug Exp $ |
* $Id: dev_ns16550.c,v 1.62 2007/06/15 19:57:33 debug Exp $ |
29 |
* |
* |
30 |
* NS16550 serial controller. |
* COMMENT: NS16550 serial controller |
|
* |
|
31 |
* |
* |
32 |
* TODO: Implement the FIFO. |
* TODO: Implement the FIFO. |
33 |
*/ |
*/ |
321 |
|
|
322 |
DEVINIT(ns16550) |
DEVINIT(ns16550) |
323 |
{ |
{ |
324 |
struct ns_data *d = malloc(sizeof(struct ns_data)); |
struct ns_data *d; |
325 |
size_t nlen; |
size_t nlen; |
326 |
char *name; |
char *name; |
327 |
|
|
328 |
if (d == NULL) { |
CHECK_ALLOCATION(d = malloc(sizeof(struct ns_data))); |
|
fprintf(stderr, "out of memory\n"); |
|
|
exit(1); |
|
|
} |
|
329 |
memset(d, 0, sizeof(struct ns_data)); |
memset(d, 0, sizeof(struct ns_data)); |
330 |
|
|
331 |
d->addrmult = devinit->addr_mult; |
d->addrmult = devinit->addr_mult; |
346 |
nlen = strlen(devinit->name) + 10; |
nlen = strlen(devinit->name) + 10; |
347 |
if (devinit->name2 != NULL) |
if (devinit->name2 != NULL) |
348 |
nlen += strlen(devinit->name2); |
nlen += strlen(devinit->name2); |
349 |
name = malloc(nlen); |
CHECK_ALLOCATION(name = malloc(nlen)); |
|
if (name == NULL) { |
|
|
fprintf(stderr, "out of memory\n"); |
|
|
exit(1); |
|
|
} |
|
350 |
if (devinit->name2 != NULL && devinit->name2[0]) |
if (devinit->name2 != NULL && devinit->name2[0]) |
351 |
snprintf(name, nlen, "%s [%s]", devinit->name, devinit->name2); |
snprintf(name, nlen, "%s [%s]", devinit->name, devinit->name2); |
352 |
else |
else |
356 |
DEV_NS16550_LENGTH * d->addrmult, dev_ns16550_access, d, |
DEV_NS16550_LENGTH * d->addrmult, dev_ns16550_access, d, |
357 |
DM_DEFAULT, NULL); |
DM_DEFAULT, NULL); |
358 |
machine_add_tickfunction(devinit->machine, |
machine_add_tickfunction(devinit->machine, |
359 |
dev_ns16550_tick, d, TICK_SHIFT, 0.0); |
dev_ns16550_tick, d, TICK_SHIFT); |
360 |
|
|
361 |
/* |
/* |
362 |
* NOTE: Ugly cast into a pointer, because this is a convenient way |
* NOTE: Ugly cast into a pointer, because this is a convenient way |
363 |
* to return the console handle to code in src/machine.c. |
* to return the console handle to code in src/machines/. |
364 |
*/ |
*/ |
365 |
devinit->return_ptr = (void *)(size_t)d->console_handle; |
devinit->return_ptr = (void *)(size_t)d->console_handle; |
366 |
|
|