-
Notifications
You must be signed in to change notification settings - Fork 13
/
pdump-file.c
162 lines (132 loc) · 4.08 KB
/
pdump-file.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
/* Copyright (C) 2013 Lars Brinkhoff <lars@nocrew.org>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <stdio.h>
#include <stdlib.h>
#include "dis.h"
#include "memory.h"
#define PAGE_ABS (0400000000000LL)
#define PAGE_CBCPY (0200000000000LL)
#define PAGE_SHARE (0100000000000LL)
#define PAGE_WRITE (0000000400000LL)
#define PAGE_READ (0000000200000LL)
#define PAGE_NUM (0000000000777LL)
#define PAGE_BITS (PAGE_ABS & PAGE_CBCPY & PAGE_SHARE & \
PAGE_WRITE & PAGE_READ & PAGE_NUM)
static int page_present (word_t info)
{
/* If the page map slot is zero, there is no page. */
if (info == 0)
return 0;
/* If it's an absolute or shared page, it's not in the file. */
if (info & (PAGE_ABS + PAGE_SHARE))
return 0;
/* If it's a readable or writable page, it's in the file. */
return (info & (PAGE_READ + PAGE_WRITE)) != 0;
}
static void
read_pdump (FILE *f, struct pdp10_memory *memory, int cpu_model)
{
word_t page_map[256];
word_t word;
int i, j;
fprintf (output_file, "PDUMP format\n\n");
/* zero word */
word = get_word (f);
fprintf (output_file, "Page map:\n");
fprintf (output_file, "Page Address Page description\n");
for (i = 0; i < 256; i++)
{
word = get_word (f);
page_map[i] = word;
if (word != 0)
{
fprintf (output_file, "%03o %06o %06o,,%06o ",
i, ITS_PAGESIZE * i, (int)(word >> 18), (int)word & 0777777);
fprintf (output_file, word & PAGE_ABS ? "a" : "-");
fprintf (output_file, word & PAGE_CBCPY ? "c" : "-");
fprintf (output_file, word & PAGE_SHARE ? "s" : "-");
fprintf (output_file, word & PAGE_WRITE ? "w" : "-");
fprintf (output_file, word & PAGE_READ ? "r" : "-");
if (word & PAGE_NUM)
fprintf (output_file, " %03o", (int)(word & PAGE_NUM));
fprintf (output_file, "\n");
}
}
/* the rest of the page is unused */
for (i = 0; i < ITS_PAGESIZE - 257; i++)
{
get_word (f);
}
for (i = 0; i < 256; i++)
{
word_t *data, *ptr;
if (!page_present (page_map[i]))
continue;
data = malloc (ITS_PAGESIZE * sizeof *data);
if (data == NULL)
{
fprintf (stderr, "out of memory\n");
exit (1);
}
ptr = data;
for (j = 0; j < ITS_PAGESIZE; j++)
{
*ptr++ = get_word (f);
}
add_memory (memory, ITS_PAGESIZE * i, ITS_PAGESIZE, data);
if ((page_map[i] & PAGE_WRITE) == 0)
purify_memory (memory, ITS_PAGESIZE * i, ITS_PAGESIZE);
}
fprintf (output_file, "\n");
word = get_word (f);
start_instruction = word;
sblk_info (f, word, cpu_model);
}
static void
write_pdump (FILE *f, struct pdp10_memory *memory)
{
word_t page_map[256];
int i, j;
/* First word must be zero. */
write_word (f, 0);
/* Page map follows. */
for (i = 0; i < 256; i++)
{
if (get_word_at (memory, i * ITS_PAGESIZE) == -1)
page_map[i] = 0;
else if (pure_word_at (memory, i * ITS_PAGESIZE))
page_map[i] = PAGE_READ;
else
page_map[i] = PAGE_READ | PAGE_WRITE;
write_word (f, page_map[i]);
}
/* Last part of first page is unused. */
for (; i < 1023; i++)
write_word (f, 0);
/* Page contents follows. */
for (i = 0; i < 256; i++)
{
if (!page_present (page_map[i]))
continue;
for (j = 0; j < ITS_PAGESIZE; j++)
write_word (f, get_word_at (memory, ITS_PAGESIZE * i + j));
}
/* Round off like an SBLK file. */
write_word (f, start_instruction);
write_sblk_symbols (f);
write_word (f, start_instruction);
}
struct file_format pdump_file_format = {
"pdump",
read_pdump,
write_pdump
};