/[gxemul]/trunk/src/devices/dev_cons.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/src/devices/dev_cons.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 10 by dpavlin, Mon Oct 8 16:18:27 2007 UTC revision 22 by dpavlin, Mon Oct 8 16:19:37 2007 UTC
# Line 1  Line 1 
1  /*  /*
2   *  Copyright (C) 2003-2005  Anders Gavare.  All rights reserved.   *  Copyright (C) 2003-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:
# Line 25  Line 25 
25   *  SUCH DAMAGE.   *  SUCH DAMAGE.
26   *     *  
27   *   *
28   *  $Id: dev_cons.c,v 1.26 2005/06/26 11:43:48 debug Exp $   *  $Id: dev_cons.c,v 1.33 2006/02/09 20:02:59 debug Exp $
29   *     *  
30   *  A console device.  (Fake, only useful for simple tests.)   *  A simple console device, useful for simple tests.
  *  It is hardwared to the lowest available MIPS hardware IRQ, and only  
  *  interrupts CPU 0.  
31   *   *
32   *  This device provides memory mapped I/O for a simple console supporting   *  This device provides memory mapped I/O for a simple console supporting
33   *  putchar (writing to memory) and getchar (reading from memory), and   *  putchar (writing to memory) and getchar (reading from memory), and
# Line 43  Line 41 
41    
42  #include "console.h"  #include "console.h"
43  #include "cpu.h"  #include "cpu.h"
44    #include "device.h"
45  #include "devices.h"  #include "devices.h"
46  #include "machine.h"  #include "machine.h"
47  #include "memory.h"  #include "memory.h"
# Line 51  Line 50 
50    
51  #define CONS_TICK_SHIFT         14  #define CONS_TICK_SHIFT         14
52    
 struct cons_data {  
         int             console_handle;  
         int             irq_nr;  
 };  
   
53    
54  /*  /*
55   *  dev_cons_tick():   *  dev_cons_tick():
# Line 75  void dev_cons_tick(struct cpu *cpu, void Line 69  void dev_cons_tick(struct cpu *cpu, void
69  /*  /*
70   *  dev_cons_access():   *  dev_cons_access():
71   */   */
72  int dev_cons_access(struct cpu *cpu, struct memory *mem,  DEVICE_ACCESS(cons)
         uint64_t relative_addr, unsigned char *data, size_t len,  
         int writeflag, void *extra)  
73  {  {
74          struct cons_data *d = extra;          struct cons_data *d = extra;
75          int i;          unsigned int i;
76    
77          /*  Exit the emulator:  */          /*  Exit the emulator:  */
78          if (relative_addr == DEV_CONS_HALT) {          if (relative_addr == DEV_CONS_HALT) {
# Line 118  int dev_cons_access(struct cpu *cpu, str Line 110  int dev_cons_access(struct cpu *cpu, str
110  }  }
111    
112    
113  /*  DEVINIT(cons)
  *  dev_cons_init():  
  */  
 int dev_cons_init(struct machine *machine, struct memory *mem,  
         uint64_t baseaddr, char *name, int irq_nr)  
114  {  {
115          struct cons_data *d;          struct cons_data *d;
116          char *name2;          char *name3;
117          size_t nlen;          size_t nlen;
118    
119          d = malloc(sizeof(struct cons_data));          d = malloc(sizeof(struct cons_data));
# Line 134  int dev_cons_init(struct machine *machin Line 122  int dev_cons_init(struct machine *machin
122                  exit(1);                  exit(1);
123          }          }
124          memset(d, 0, sizeof(struct cons_data));          memset(d, 0, sizeof(struct cons_data));
         d->irq_nr = irq_nr;  
         d->console_handle = console_start_slave(machine, name);  
125    
126          nlen = strlen(name) + 20;          nlen = strlen(devinit->name) + 10;
127          name2 = malloc(nlen);          if (devinit->name2 != NULL)
128          if (name2 == NULL) {                  nlen += strlen(devinit->name2) + 10;
129            name3 = malloc(nlen);
130            if (name3 == NULL) {
131                  fprintf(stderr, "out of memory in dev_cons_init()\n");                  fprintf(stderr, "out of memory in dev_cons_init()\n");
132                  exit(1);                  exit(1);
133          }          }
134          if (name != NULL && name[0])          if (devinit->name2 != NULL && devinit->name2[0])
135                  snprintf(name2, nlen, "cons [%s]", name);                  snprintf(name3, nlen, "%s [%s]", devinit->name, devinit->name2);
136          else          else
137                  snprintf(name2, nlen, "cons");                  snprintf(name3, nlen, "%s", devinit->name);
138    
139          memory_device_register(mem, name2, baseaddr, DEV_CONS_LENGTH,          d->irq_nr = devinit->irq_nr;
140              dev_cons_access, d, MEM_DEFAULT, NULL);          d->in_use = devinit->in_use;
141          machine_add_tickfunction(machine, dev_cons_tick, d, CONS_TICK_SHIFT);          d->console_handle = console_start_slave(devinit->machine, name3,
142                d->in_use);
143    
144            memory_device_register(devinit->machine->memory, name3,
145                devinit->addr, DEV_CONS_LENGTH, dev_cons_access, d,
146                DM_DEFAULT, NULL);
147            machine_add_tickfunction(devinit->machine, dev_cons_tick,
148                d, CONS_TICK_SHIFT);
149    
150          return d->console_handle;          /*  NOTE: Ugly cast into pointer  */
151            devinit->return_ptr = (void *)(size_t)d->console_handle;
152            return 1;
153  }  }
154    

Legend:
Removed from v.10  
changed lines
  Added in v.22

  ViewVC Help
Powered by ViewVC 1.1.26