Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


moved over the a real linked list implementation
[palacios.git] / palacios / src / devices / nvram.c
1 #include <devices/nvram.h>
2 #include <palacios/vmm.h>
3 #include <palacios/vmm_types.h>
4
5 extern struct vmm_os_hooks *os_hooks;
6
7
8 #define NVRAM_REG_PORT  0x70
9 #define NVRAM_DATA_PORT 0x71
10
11
12
13 typedef enum {NVRAM_READY, NVRAM_REG_POSTED} nvram_state_t;
14
15
16 #define NVRAM_REG_MAX   256
17
18
19 // These are borrowed from Bochs, which borrowed from
20 // Ralf Brown's interupt list
21 #define NVRAM_REG_SEC                     0x00
22 #define NVRAM_REG_SEC_ALARM               0x01
23 #define NVRAM_REG_MIN                     0x02
24 #define NVRAM_REG_MIN_ALARM               0x03
25 #define NVRAM_REG_HOUR                    0x04
26 #define NVRAM_REG_HOUR_ALARM              0x05
27 #define NVRAM_REG_WEEK_DAY                0x06
28 #define NVRAM_REG_MONTH_DAY               0x07
29 #define NVRAM_REG_MONTH                   0x08
30 #define NVRAM_REG_YEAR                    0x09
31 #define NVRAM_REG_STAT_A                  0x0a
32 #define NVRAM_REG_STAT_B                  0x0b
33 #define NVRAM_REG_STAT_C                  0x0c
34 #define NVRAM_REG_STAT_D                  0x0d
35 #define NVRAM_REG_DIAGNOSTIC_STATUS       0x0e  
36 #define NVRAM_REG_SHUTDOWN_STATUS         0x0f
37 #define NVRAM_REG_EQUIPMENT_BYTE          0x14
38 #define NVRAM_REG_CSUM_HIGH               0x2e
39 #define NVRAM_REG_CSUM_LOW                0x2f
40 #define NVRAM_REG_IBM_CENTURY_BYTE        0x32  
41 #define NVRAM_REG_IBM_PS2_CENTURY_BYTE    0x37  
42
43
44
45 struct nvram_internal {
46   nvram_state_t dev_state;
47   uchar_t       thereg;
48   uchar_t       mem_state[NVRAM_REG_MAX];
49 };
50
51
52
53
54
55 int nvram_reset_device(struct vm_device * dev)
56 {
57   struct nvram_internal *data = (struct nvram_internal *) dev->private_data;
58   
59   data->dev_state = NVRAM_READY;
60   data->thereg=0;
61   
62   return 0;
63
64 }
65
66
67
68
69
70 int nvram_start_device(struct vm_device *dev)
71 {
72   return 0;
73 }
74
75
76 int nvram_stop_device(struct vm_device *dev)
77 {
78   return 0;
79 }
80
81
82
83
84 int nvram_write_reg_port(ushort_t port,
85                         void * src, 
86                         uint_t length,
87                         struct vm_device * dev)
88 {
89   struct nvram_internal *data = (struct nvram_internal *) dev->private_data;
90
91   memcpy(&(data->thereg), src, 1);
92
93   return 0;
94 }
95
96
97 int nvram_read_data_port(ushort_t port,
98                        void   * dst, 
99                        uint_t length,
100                        struct vm_device * dev)
101 {
102   struct nvram_internal *data = (struct nvram_internal *) dev->private_data;
103
104   memcpy(dst, &(data->mem_state[data->thereg]), 1);
105
106   return 0;
107 }
108
109 int nvram_write_data_port(ushort_t port,
110                         void * src, 
111                         uint_t length,
112                         struct vm_device * dev)
113 {
114   struct nvram_internal *data = (struct nvram_internal *) dev->private_data;
115
116   memcpy(&(data->mem_state[data->thereg]), src, 1);
117
118   return 0;
119 }
120
121
122
123 int nvram_init_device(struct vm_device * dev) {
124   struct nvram_internal *data = (struct nvram_internal *) dev->private_data;
125  
126   memset(data->mem_state, 0, NVRAM_REG_MAX);
127
128   nvram_reset_device(dev);
129
130   // hook ports
131   dev_hook_io(dev, NVRAM_REG_PORT, NULL, &nvram_write_reg_port);
132   dev_hook_io(dev, NVRAM_DATA_PORT, &nvram_read_data_port, &nvram_write_data_port);
133   
134   return 0;
135 }
136
137 int nvram_deinit_device(struct vm_device *dev)
138 {
139
140
141   dev_unhook_io(dev, NVRAM_REG_PORT);
142   dev_unhook_io(dev, NVRAM_DATA_PORT);
143
144   nvram_reset_device(dev);
145   return 0;
146 }
147
148
149
150
151
152 static struct vm_device_ops dev_ops = { 
153   .init = nvram_init_device, 
154   .deinit = nvram_deinit_device,
155   .reset = nvram_reset_device,
156   .start = nvram_start_device,
157   .stop = nvram_stop_device,
158 };
159
160
161
162 struct vm_device *create_nvram() {
163   struct nvram_internal * nvram_state = os_hooks->malloc(sizeof(struct nvram_internal));
164
165   struct vm_device *device = create_device("NVRAM", &dev_ops, nvram_state);
166
167   return device;
168 }