OSDN Git Service

* public snapshot of sid simulator
[pf3gnuchains/pf3gnuchains3x.git] / sid / component / memory / am29.h
1 // am29.h - A specialisation of the generic uniform sector flash memory
2 // class which models the AMD 29xxx series of flash memory.  -*- C++ -*-
3
4 // Copyright (C) 1999, 2000 Red Hat.
5 // This file is part of SID and is licensed under the GPL.
6 // See the file COPYING.SID for conditions for redistribution.
7
8 // More details on this component can be found on AMD's web site
9 // <http://www.amd.com/> in various data sheets.
10
11 #ifndef AM29_H
12 #define AM29_H
13
14 #include <assert.h>
15 #include <iostream>
16 #include "flash.h"
17
18 using std::ostream;
19 using std::istream;
20 using std::string;
21
22 using sid::bus;
23 using sid::host_int_1;
24 using sid::host_int_4;
25 using sid::little_int_1;
26 using sid::little_int_2;
27 using sid::little_int_4;
28 using sid::little_int_8;
29 using sid::big_int_1;
30 using sid::big_int_2;
31 using sid::big_int_4;
32 using sid::big_int_8;
33
34 struct am29_flash_memory_type
35 {
36   const char* name;
37   size_t memory_size;
38   size_t sector_size;
39   unsigned device_id;
40 };
41
42
43 class am29_flash_memory: public flash_uniform_sector_memory
44 {
45 public:
46   am29_flash_memory(size_t memory_size, size_t sector_size, 
47                          host_int_1 device_id);
48
49   static const am29_flash_memory_type types[];
50
51 protected:
52   void stream_state (ostream&) const;
53   void destream_state (istream&);  
54
55 private:
56   class am29_bus: public bus
57   {
58   public:
59     am29_bus(am29_flash_memory* target):
60       target(target) {}
61
62     bus::status write(host_int_4 address, big_int_1 data) 
63                                                                     throw ( );
64
65     bus::status write(host_int_4 address, little_int_1 data)
66                                                                     throw ( );
67
68     bus::status read(host_int_4 address, big_int_1& data) throw ( );
69     bus::status read(host_int_4 address, little_int_1& data) throw ( );
70
71 #define NOPERM_WRITE(type) \
72     bus::status write(host_int_4 address, type data) throw () \
73               { return bus::unpermitted; }
74   
75 #define NOPERM_READ(type) \
76     bus::status read(host_int_4 address, type& data) throw () \
77               { return bus::unpermitted; }
78   
79     NOPERM_WRITE(big_int_2);
80     NOPERM_WRITE(little_int_2);
81     NOPERM_WRITE(big_int_4);
82     NOPERM_WRITE(little_int_4);
83     NOPERM_WRITE(big_int_8);
84     NOPERM_WRITE(little_int_8);
85
86     NOPERM_READ(big_int_2);
87     NOPERM_READ(little_int_2);
88     NOPERM_READ(big_int_4);
89     NOPERM_READ(little_int_4);
90     NOPERM_READ(big_int_8);
91     NOPERM_READ(little_int_8);
92   
93 #undef NOPERM_WRITE  
94 #undef NOPERM_READ
95
96   private:
97     am29_flash_memory* target;
98   };
99
100   friend class am29_bus;
101   am29_bus my_bus;
102
103   bool write_ok(host_int_4 address);
104
105   // Erase the entire chip.
106   void erase();
107
108   // Erase a given sector.
109   void erase(unsigned sector);
110
111   host_int_1 manufacturerCode;
112   host_int_1 deviceIdCode;
113
114   int mode;
115 };
116
117 #endif // AM29_H
118
119
120
121
122
123