OSDN Git Service

* public snapshot of sid simulator
[pf3gnuchains/pf3gnuchains3x.git] / sid / component / memory / components.cxx
1 // components.cxx - definitions for this component library. -*- C++ -*-
2
3 // Copyright (C) 1999, 2000 Red Hat.
4 // This file is part of SID and is licensed under the GPL.
5 // See the file COPYING.SID for conditions for redistribution.
6
7 #include "config.h"
8
9 #include <sidcomp.h>
10 #include <sidso.h>
11
12 #include <vector>
13 #include <string>
14
15 #include "am29.h"
16 #include "at29.h"
17 #include "ramrom.h"
18
19 using std::vector;
20 using std::string;
21
22 using sid::component;
23 using sid::component_library;
24 using sid::COMPONENT_LIBRARY_MAGIC;
25
26
27
28 // ----------------------------------------------------------------------------
29
30
31 static
32 vector<string>
33 compMemoryListTypes()
34 {
35   vector<string> types;
36
37   types.push_back("hw-memory-ram/rom-basic");
38
39   types.push_back("hw-memory-flash-at29");
40   for (const at29_flash_memory_type* ft = at29_flash_memory::types;
41        ft->name != 0;
42        ft++)
43     {
44       types.push_back(string("hw-memory-flash-at29") + ft->name);
45     }
46
47   types.push_back("hw-memory-flash-am29");
48   for (const am29_flash_memory_type* ft = am29_flash_memory::types;
49        ft->name != 0;
50        ft++)
51     {
52       types.push_back(string("hw-memory-flash-am29") + ft->name);
53     }
54
55   return types;
56 }
57
58
59 static
60 component*
61 compMemoryCreate(const string& typeName)
62 {
63   // Protect against the constructors throwing exceptions
64   try
65     {
66       if (typeName == "hw-memory-ram/rom-basic")
67         return new ramrom_memory();
68       
69       if (typeName == "hw-memory-flash-at29")
70         return new at29_flash_memory(512*1024, 512, 0x5B); // default: AT29C040
71       for (const at29_flash_memory_type* ft = at29_flash_memory::types;
72            ft->name != 0;
73            ft++)
74         {
75           string that_type = string("hw-memory-flash-at29") + ft->name;
76           if (that_type == typeName)
77             return new at29_flash_memory(ft->memory_size, ft->sector_size, ft->device_id);
78         }
79
80       if (typeName == "hw-memory-flash-am29")
81         {
82           // default: Am29LV040B
83           return new am29_flash_memory(512*1024, 64*1024, 0x4F);
84         }
85       for (const am29_flash_memory_type* ft = am29_flash_memory::types;
86            ft->name != 0;
87            ft++)
88         {
89           string that_type = string("hw-memory-flash-am29") + ft->name;
90           if (that_type == typeName)
91             return new am29_flash_memory(ft->memory_size, ft->sector_size, ft->device_id);
92         }
93     }
94   catch (...) { }
95
96   return 0;
97 }
98
99
100 static
101 void
102 compMemoryDelete(component* c)
103 {
104   // generic_memory is a base class for all components that may have come from here
105   delete dynamic_cast<generic_memory*>(c);
106 }
107
108
109
110 // static object
111 extern const component_library mem_component_library;
112
113 const component_library mem_component_library DLLEXPORT = 
114 {
115   COMPONENT_LIBRARY_MAGIC,
116   & compMemoryListTypes, 
117   & compMemoryCreate,
118   & compMemoryDelete
119 };