forked from datajerk/x49gp
-
Notifications
You must be signed in to change notification settings - Fork 7
/
sram.c
793 lines (650 loc) · 16.2 KB
/
sram.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
/* $Id: sram.c,v 1.18 2008/12/11 12:18:17 ecd Exp $
*/
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <errno.h>
#include <x49gp.h>
#include <memory.h>
#include <byteorder.h>
#include <saturn.h>
typedef struct {
void *data;
void *shadow;
char *filename;
int fd;
size_t size;
uint32_t offset;
x49gp_t *x49gp;
} x49gp_sram_t;
#define S3C2410_SRAM_BASE 0x08000000
#define S3C2410_SRAM_SIZE 0x00080000
#define BASE 0xbcbb5
#define SATURN(r) ((target_phys_addr_t) &((saturn_cpu_t *)0)->r)
#if defined(DEBUG_X49GP_SYSRAM_READ) || defined(DEBUG_X49GP_SYSRAM_WRITE) || \
defined(DEBUG_X49GP_IRAM_READ) || defined(DEBUG_X49GP_IRAM_WRITE) || \
defined(DEBUG_X49GP_ERAM_READ) || defined(DEBUG_X49GP_ERAM_WRITE)
#define DEBUG_X49GP_SRAM 1
#endif
typedef struct {
uint32_t x;
uint32_t ml;
uint32_t mh;
uint8_t m;
uint8_t s;
} hp_real_t;
#ifdef DEBUG_X49GP_SRAM
static uint32_t
saturn_map_s2a(saturn_cpu_t *saturn, uint32_t saddr)
{
uint32_t addr;
addr = ldl_p(&saturn->read_map[saddr >> 12]) | ((saddr >> 1) & 0x7ff);
// printf("SATURN: saddr %05x, addr %08x\n", saddr, addr);
return addr;
}
static uint32_t
saturn_peek(saturn_cpu_t *saturn, uint32_t saddr, uint32_t size)
{
uint32_t addr, rot, mask, data;
uint64_t value;
addr = saturn_map_s2a(saturn, saddr) & 0xfffffffc;
if (addr > 0x08080000)
return 0;
// printf("SATURN: addr %08x\n", addr);
value = ((uint64_t) ldl_phys(addr)) | (((uint64_t) ldl_phys(addr + 4)) << 32);
// printf("SATURN: value %016llx\n", value);
rot = (saddr & 7) << 2;
mask = (1ULL << (size << 2)) - 1;
// printf("SATURN: rot %u, mask %08x\n", rot, mask);
data = ((uint32_t) (value >> rot)) & mask;
// printf("SATURN: data %08x\n", data);
return data;
}
static uint32_t
saturn_peek_address(saturn_cpu_t *saturn, uint32_t saddr)
{
return saturn_peek(saturn, saddr, 5);
}
static int
hxs2real(int hxs)
{
int n = 0, c = 1;
while (hxs) {
n += (hxs & 0xf) * c;
c *= 10;
hxs >>= 4;
}
return n;
}
static char *
real_number(saturn_cpu_t *saturn, uint32_t saddr, char *buffer, int ml, int xl)
{
char *p = buffer;
char fmt[20];
char m[16];
hp_real_t r;
int re, xs;
int i;
uint32_t pc;
pc = saddr;
/*
* Read the number
*/
r.x = saturn_peek(saturn, pc, xl);
pc += xl;
r.ml = saturn_peek(saturn, pc, ml - 8);
pc += ml - 8;
r.mh = saturn_peek(saturn, pc, 8);
pc += 8;
r.m = saturn_peek(saturn, pc, 1);
pc += 1;
r.s = saturn_peek(saturn, pc, 1);
pc += 1;
/*
* Figure out the exponent
*/
xs = 5;
while (--xl)
xs *= 10;
re = hxs2real(r.x);
if (re >= xs)
re = re - 2 * xs;
if ((re >= 0) && (re < ml + 1)) {
if (r.s >= 5)
*p++ = '-';
sprintf(fmt, "%%.1X%%.8X%%.%dX", ml - 8);
sprintf(m, fmt, r.m, r.mh, r.ml);
for (i = 0; i <= re; i++)
*p++ = m[i];
*p++ = '.';
for ( ; i < ml + 1; i++)
*p++ = m[i];
p--;
while(*p == '0')
p--;
if (*p == '.')
p--;
*++p = '\0';
return buffer;
}
if ((re < 0) && (re >= -ml - 1)) {
sprintf(fmt, "%%.1X%%.8X%%.%dX", ml - 8);
sprintf(m, fmt, r.m, r.mh, r.ml);
for (i = ml; m[i] == '0'; i--)
;
if (-re <= ml - i + 1) {
if (r.s >= 5)
*p++ = '-';
*p++ = '.';
for (i = 1; i < -re; i++)
*p++ = '0';
for (i = 0; i < ml + 1; i++)
*p++ = m[i];
p--;
while(*p == '0')
p--;
*++p = '\0';
return buffer;
}
}
sprintf(fmt, "%%s%%X.%%.8X%%.%dX", ml - 8);
sprintf(p, fmt, (r.s >= 5) ? "-" : "", r.m, r.mh, r.ml);
p += strlen(p) - 1;
while(*p == '0')
p--;
*++p = '\0';
if (re) {
sprintf(p, "E%d", re);
p += strlen(p);
*p = '\0';
}
return buffer;
}
static uint32_t
dump_object(x49gp_t *x49gp, x49gp_sram_t *sram, uint32_t saddr)
{
saturn_cpu_t *saturn = (sram->data + 0x3340);
char buffer[128];
uint32_t prolog, pc;
char c;
int i, n;
pc = saddr;
prolog = saturn_peek(saturn, pc, 5);
pc += 5;
switch (prolog) {
case 0x02e48:
case 0x02e6d:
printf(" ");
n = saturn_peek(saturn, pc, 2);
pc += 2;
for (i = 0; i < n; i++) {
c = saturn_peek(saturn, pc, 2);
printf("%c", c);
pc += 2;
}
break;
case 0x02a4e:
n = saturn_peek(saturn, pc, 5);
pc += 5;
if (n <= 16) {
printf(" #%08x%08xh", saturn_peek(saturn, pc + 8, 8),
saturn_peek(saturn, pc + 0, 8));
} else {
printf(" C#");
for (i = 0; i < n; i++) {
printf("%x", saturn_peek(saturn, pc + i, 1));
}
}
pc += n;
break;
case 0x02911:
printf(" <%05x>", saturn_peek(saturn, pc, 5));
pc += 5;
break;
case 0x02933:
printf(" %%%s", real_number(saturn, pc, buffer, 11, 3));
pc += 16;
break;
case 0x02955:
printf(" %%%%%s", real_number(saturn, pc, buffer, 14, 5));
pc += 21;
break;
case 0x02e92:
printf(" <%03x %03x>", saturn_peek(saturn, pc + 0, 3),
saturn_peek(saturn, pc + 3, 3));
pc += 6;
break;
case 0x026ac:
printf(" <%03x %04x>", saturn_peek(saturn, pc + 0, 3),
saturn_peek(saturn, pc + 3, 4));
pc += 7;
break;
case 0x02ab8:
printf(" '");
while (1) {
prolog = saturn_peek(saturn, pc, 5);
if (prolog == 0x0312b) {
pc += 5;
break;
}
pc += dump_object(x49gp, sram, pc);
}
printf(" '");
break;
case 0x02d9d:
printf(" :");
while (1) {
prolog = saturn_peek(saturn, pc, 5);
if (prolog == 0x0312b) {
pc += 5;
break;
}
pc += dump_object(x49gp, sram, pc);
}
printf(" ;");
break;
default:
printf(" %05x", prolog);
break;
}
return pc - saddr;
}
static void
debug_saturn(x49gp_t *x49gp, x49gp_sram_t *sram)
{
saturn_cpu_t *saturn = (sram->data + 0x3340);
uint32_t sp, se;
uint32_t prolog;
uint32_t rsp;
uint32_t first;
static uint32_t prev_first = 0;
static int state = 0;
int depth;
int i;
// printf("SATURN: %p, RPLTOP: %08x\n", saturn, saturn_map_s2a(saturn, SAT_RPLTOP));
// printf("SATURN: %p, RSKTOP: %08x\n", saturn, saturn_map_s2a(saturn, SAT_RSKTOP));
// rpltop = saturn_peek_address(saturn, SAT_RPLTOP);
// printf("SATURN: RPLTOP: %05x\n", rpltop);
rsp = saturn_peek_address(saturn, SAT_RSKTOP);
if (rsp == 0)
return;
first = saturn_peek_address(saturn, rsp - 5);
if (first == prev_first) {
return;
}
prev_first = first;
if (first == (BASE + 0x14a54)) {
state = 1;
}
if (state == 0)
return;
printf("SATURN: %p, rsp: %05x %08x\n", saturn, rsp, saturn_map_s2a(saturn, rsp));
for (i = 0; ; i++) {
rsp -= 5;
se = saturn_peek_address(saturn, rsp);
if (se == 0)
break;
if (se > BASE)
printf("SATURN: RSTK %02u: %05x <%05x>\n", i, se, se - BASE);
else
printf("SATURN: RSTK %02u: %05x\n", i, se);
}
depth = (saturn_peek_address(saturn, SAT_EDITLINE) - saturn_peek_address(saturn, SAT_DSKTOP) - 5) / 5;
printf("SATURN: depth %d\n", depth);
sp = saturn_peek_address(saturn, SAT_EDITLINE) - 10;
for (i = 0; i < depth; i++) {
se = saturn_peek_address(saturn, sp);
sp -= 5;
prolog = saturn_peek(saturn, se, 5);
printf("SATURN: %02u: <%05x> <%05x>", depth - i, se, prolog);
dump_object(x49gp, sram, se);
printf("\n");
}
}
static uint32_t
sram_get_word(void *opaque, target_phys_addr_t offset)
{
x49gp_sram_t *sram = opaque;
uint32_t data;
data = ldl_p(sram->data + offset);
#if 0
if (offset == 0x00000a1c) {
printf("read SRAM at offset %08x: %08x (pc %08x)\n", offset, data, x49gp->arm->Reg[15]);
}
#endif
#ifdef DEBUG_X49GP_SYSRAM_READ
if ((offset & ~(0x0001ffff)) == 0x00000000) {
printf("read SRAM 4 at offset %08x: %08x\n", offset, data);
}
#endif
#ifdef DEBUG_X49GP_ERAM_READ
if ((offset & ~(0x0001ffff)) == 0x00020000) {
printf("read SRAM 4 at offset %08x: %08x\n", offset, data);
}
#endif
#ifdef DEBUG_X49GP_IRAM_READ
if ((offset & ~(0x0003ffff)) == 0x00040000) {
printf("read SRAM 4 at offset %08x: %08x\n", offset, data);
}
#endif
return data;
}
static uint32_t
sram_get_halfword(void *opaque, target_phys_addr_t offset)
{
x49gp_sram_t *sram = opaque;
unsigned short data;
data = lduw_p(sram->data + offset);
#ifdef DEBUG_X49GP_SYSRAM_READ
if ((offset & ~(0x0001ffff)) == 0x00000000) {
printf("read SRAM 2 at offset %08x: %04x\n", offset, data);
}
#endif
#ifdef DEBUG_X49GP_ERAM_READ
if ((offset & ~(0x0001ffff)) == 0x00020000) {
printf("read SRAM 2 at offset %08x: %04x\n", offset, data);
}
#endif
#ifdef DEBUG_X49GP_IRAM_READ
if ((offset & ~(0x0003ffff)) == 0x00040000) {
printf("read SRAM 2 at offset %08x: %04x\n", offset, data);
}
#endif
return data;
}
static uint32_t
sram_get_byte(void *opaque, target_phys_addr_t offset)
{
x49gp_sram_t *sram = opaque;
unsigned char data;
data = ldub_p(sram->data + offset);
#ifdef DEBUG_X49GP_SYSRAM_READ
if ((offset & ~(0x0001ffff)) == 0x00000000) {
printf("read SRAM 1 at offset %08x: %02x\n", offset, data);
}
#endif
#ifdef DEBUG_X49GP_ERAM_READ
if ((offset & ~(0x0001ffff)) == 0x00020000) {
printf("read SRAM 1 at offset %08x: %02x\n", offset, data);
}
#endif
#ifdef DEBUG_X49GP_IRAM_READ
if ((offset & ~(0x0003ffff)) == 0x00040000) {
printf("read SRAM 1 at offset %08x: %02x\n", offset, data);
}
#endif
return data;
}
static void
sram_put_word(void *opaque, target_phys_addr_t offset, uint32_t data)
{
x49gp_sram_t *sram = opaque;
if (offset == 0x00000a1c) {
printf("write SRAM 4 at offset %08x: %08x (pc %08x)\n",
offset, data, sram->x49gp->env->regs[15]);
}
debug_saturn(sram->x49gp, sram);
#if 0
if (offset == 0x3340 + SATURN(D1)) {
printf("write D1 at offset %08x: %08x (pc %08x)\n",
offset, data, sram->x49gp->env->regs[15]);
}
if (offset == 0x3340 + SATURN(A)) {
printf("write A at offset %08x: %08x (pc %08x)\n",
offset, data, sram->x49gp->env->regs[15]);
}
if (offset == 0x3340 + SATURN(A) + 8) {
printf("write Al at offset %08x: %08x (pc %08x)\n",
offset, data, sram->x49gp->env->regs[15]);
}
#endif
#ifdef DEBUG_X49GP_SYSRAM_WRITE
if ((offset & ~(0x0001ffff)) == 0x00000000) {
printf("write SRAM 4 at offset %08x: %08x\n", offset, data);
}
#endif
#ifdef DEBUG_X49GP_ERAM_WRITE
if ((offset & ~(0x0001ffff)) == 0x00020000) {
printf("write SRAM 4 at offset %08x: %08x\n", offset, data);
}
#endif
#ifdef DEBUG_X49GP_IRAM_WRITE
if ((offset & ~(0x0003ffff)) == 0x00040000) {
printf("write SRAM 4 at offset %08x: %08x\n", offset, data);
}
#endif
stl_p(sram->data + offset, data);
}
static void
sram_put_halfword(void *opaque, target_phys_addr_t offset, uint32_t data)
{
x49gp_sram_t *sram = opaque;
data &= 0xffff;
#ifdef DEBUG_X49GP_SYSRAM_WRITE
if ((offset & ~(0x0001ffff)) == 0x00000000) {
printf("write SRAM 2 at offset %08x: %04x\n", offset, data);
}
#endif
#ifdef DEBUG_X49GP_ERAM_WRITE
if ((offset & ~(0x0001ffff)) == 0x00020000) {
printf("write SRAM 2 at offset %08x: %04x\n", offset, data);
}
#endif
#ifdef DEBUG_X49GP_IRAM_WRITE
if ((offset & ~(0x0003ffff)) == 0x00040000) {
printf("write SRAM 2 at offset %08x: %04x\n", offset, data);
}
#endif
stw_p(sram->data + offset, data);
}
static void
sram_put_byte(void *opaque, target_phys_addr_t offset, uint32_t data)
{
x49gp_sram_t *sram = opaque;
data &= 0xff;
#ifdef DEBUG_X49GP_SYSRAM_WRITE
if ((offset & ~(0x0001ffff)) == 0x00000000) {
printf("write SRAM 1 at offset %08x: %02x\n", offset, data);
}
#endif
#ifdef DEBUG_X49GP_ERAM_WRITE
if ((offset & ~(0x0001ffff)) == 0x00020000) {
printf("write SRAM 1 at offset %08x: %02x\n", offset, data);
}
#endif
#ifdef DEBUG_X49GP_IRAM_WRITE
if ((offset & ~(0x0003ffff)) == 0x00040000) {
printf("write SRAM 1 at offset %08x: %02x\n", offset, data);
}
#endif
stb_p(sram->data + offset, data);
}
static CPUReadMemoryFunc *sram_readfn[] =
{
sram_get_byte,
sram_get_halfword,
sram_get_word
};
static CPUWriteMemoryFunc *sram_writefn[] =
{
sram_put_byte,
sram_put_halfword,
sram_put_word
};
#endif /* DEBUG_X49GP_SRAM */
static int
sram_load(x49gp_module_t *module, GKeyFile *key)
{
x49gp_sram_t *sram = module->user_data;
char *filename;
int error;
#ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__);
#endif
error = x49gp_module_get_filename(module, key, "filename", "sram",
&(sram->filename), &filename);
sram->fd = open(filename, O_RDWR | O_CREAT, 0644);
if (sram->fd < 0) {
error = -errno;
fprintf(stderr, "%s: %s:%u: open %s: %s\n",
module->name, __FUNCTION__, __LINE__,
filename, strerror(errno));
g_free(filename);
return error;
}
sram->size = 0x00080000;
if (ftruncate(sram->fd, sram->size) < 0) {
error = -errno;
fprintf(stderr, "%s: %s:%u: ftruncate %s: %s\n",
module->name, __FUNCTION__, __LINE__,
filename, strerror(errno));
g_free(filename);
close(sram->fd);
sram->fd = -1;
return error;
}
sram->data = mmap(phys_ram_base + sram->offset, sram->size,
PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED,
sram->fd, 0);
if (sram->data == (void *) -1) {
error = -errno;
fprintf(stderr, "%s: %s:%u: mmap %s: %s\n",
module->name, __FUNCTION__, __LINE__,
filename, strerror(errno));
g_free(filename);
close(sram->fd);
sram->fd = -1;
return error;
}
sram->shadow = mmap(phys_ram_base + sram->offset + sram->size,
sram->size,
PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED,
sram->fd, 0);
if (sram->shadow == (void *) -1) {
error = -errno;
fprintf(stderr, "%s: %s:%u: mmap %s (shadow): %s\n",
module->name, __FUNCTION__, __LINE__,
filename, strerror(errno));
g_free(filename);
close(sram->fd);
sram->fd = -1;
return error;
}
sram->x49gp->sram = phys_ram_base + sram->offset;
g_free(filename);
return error;
}
static int
sram_save(x49gp_module_t *module, GKeyFile *key)
{
x49gp_sram_t *sram = module->user_data;
int error;
#ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__);
#endif
x49gp_module_set_filename(module, key, "filename", sram->filename);
error = msync(sram->data, sram->size, MS_ASYNC);
if (error) {
fprintf(stderr, "%s:%u: msync: %s\n",
__FUNCTION__, __LINE__, strerror(errno));
return error;
}
error = fsync(sram->fd);
if (error) {
fprintf(stderr, "%s:%u: fsync: %s\n",
__FUNCTION__, __LINE__, strerror(errno));
return error;
}
return 0;
}
static int
sram_reset(x49gp_module_t *module, x49gp_reset_t reset)
{
#ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__);
#endif
return 0;
}
static int
sram_init(x49gp_module_t *module)
{
x49gp_sram_t *sram;
#ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__);
#endif
sram = malloc(sizeof(x49gp_sram_t));
if (NULL == sram) {
fprintf(stderr, "%s:%u: Out of memory\n",
__FUNCTION__, __LINE__);
return -ENOMEM;
}
memset(sram, 0, sizeof(x49gp_sram_t));
sram->fd = -1;
module->user_data = sram;
sram->x49gp = module->x49gp;
sram->data = (void *) -1;
sram->shadow = (void *) -1;
sram->offset = phys_ram_size;
phys_ram_size += S3C2410_SRAM_SIZE;
phys_ram_size += S3C2410_SRAM_SIZE;
#ifdef DEBUG_X49GP_SRAM
{
int iotype;
iotype = cpu_register_io_memory(0, sram_readfn, sram_writefn, sram);
printf("%s: iotype %08x\n", __FUNCTION__, iotype);
cpu_register_physical_memory(S3C2410_SRAM_BASE,
S3C2410_SRAM_SIZE,
sram->offset | iotype | IO_MEM_ROMD);
iotype = cpu_register_io_memory(0, sram_readfn, sram_writefn, sram);
printf("%s: iotype %08x\n", __FUNCTION__, iotype);
cpu_register_physical_memory(S3C2410_SRAM_BASE + S3C2410_SRAM_SIZE,
S3C2410_SRAM_SIZE,
(sram->offset + S3C2410_SRAM_SIZE) | iotype | IO_MEM_ROMD);
}
#else
cpu_register_physical_memory(S3C2410_SRAM_BASE, S3C2410_SRAM_SIZE,
sram->offset | IO_MEM_RAM);
cpu_register_physical_memory(S3C2410_SRAM_BASE + S3C2410_SRAM_SIZE,
S3C2410_SRAM_SIZE,
(sram->offset + S3C2410_SRAM_SIZE) | IO_MEM_RAM);
#endif
return 0;
}
static int
sram_exit(x49gp_module_t *module)
{
x49gp_sram_t *sram;
#ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__);
#endif
if (module->user_data) {
sram = module->user_data;
if (sram->shadow != (void *) -1) {
munmap(sram->shadow, sram->size);
}
if (sram->data != (void *) -1) {
munmap(sram->data, sram->size);
}
if (sram->fd >= 0) {
close(sram->fd);
}
free(sram);
}
x49gp_module_unregister(module);
free(module);
return 0;
}
int
x49gp_sram_init(x49gp_t *x49gp)
{
x49gp_module_t *module;
if (x49gp_module_init(x49gp, "sram", sram_init, sram_exit,
sram_reset, sram_load, sram_save, NULL,
&module)) {
return -1;
}
return x49gp_module_register(module);
}