~ubuntu-branches/ubuntu/quantal/gclcvs/quantal

« back to all changes in this revision

Viewing changes to o/saveu370.c

  • Committer: Bazaar Package Importer
  • Author(s): Camm Maguire
  • Date: 2004-06-24 15:13:46 UTC
  • Revision ID: james.westby@ubuntu.com-20040624151346-xh0xaaktyyp7aorc
Tags: 2.7.0-26
C_GC_OFFSET is 2 on m68k-linux

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 Copyright (C) 1994 M. Hagiya, W. Schelter, T. Yuasa
 
3
 
 
4
This file is part of GNU Common Lisp, herein referred to as GCL
 
5
 
 
6
GCL is free software; you can redistribute it and/or modify it under
 
7
the terms of the GNU LIBRARY GENERAL PUBLIC LICENSE as published by
 
8
the Free Software Foundation; either version 2, or (at your option)
 
9
any later version.
 
10
 
 
11
GCL is distributed in the hope that it will be useful, but WITHOUT
 
12
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 
13
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public 
 
14
License for more details.
 
15
 
 
16
You should have received a copy of the GNU Library General Public License 
 
17
along with GCL; see the file COPYING.  If not, write to the Free Software
 
18
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 
19
 
 
20
*/
 
21
 
 
22
/*
 
23
        unixsave.c
 
24
*/
 
25
 
 
26
 
 
27
#include <fcntl.h>
 
28
#include <filehdr.h>
 
29
#include <scnhdr.h>
 
30
#ifdef u370
 
31
#undef u370
 
32
#include <aouthdr.h>
 
33
 
 
34
filecpy(to, from, n)
 
35
FILE *to, *from;
 
36
register int n;
 
37
{
 
38
        char buffer[BUFSIZ];
 
39
 
 
40
        for (;;)
 
41
                if (n > BUFSIZ) {
 
42
                        fread(buffer, BUFSIZ, 1, from);
 
43
                        fwrite(buffer, BUFSIZ, 1, to);
 
44
                        n -= BUFSIZ;
 
45
                } else if (n > 0) {
 
46
                        fread(buffer, 1, n, from);
 
47
                        fwrite(buffer, 1, n, to);
 
48
                        break;
 
49
                } else
 
50
                        break;
 
51
}
 
52
 
 
53
 
 
54
memory_save(original_file, save_file)
 
55
char *original_file, *save_file;
 
56
{       MEM_SAVE_LOCALS;
 
57
        struct scnhdr shdrs[15];
 
58
        char *data_begin, *data_end;
 
59
        int original_data;
 
60
        FILE *original, *save;
 
61
        register int n;
 
62
        register char *p;
 
63
        extern char *sbrk();
 
64
 
 
65
 
 
66
        fclose(stdin);
 
67
        original = fopen(original_file, "r");
 
68
        if (stdin != original || original->_file != 0) {
 
69
                fprintf(stderr, "Can't open the original file.\n");
 
70
                exit(1);
 
71
        }
 
72
        setbuf(original, stdin_buf);
 
73
        fclose(stdout);
 
74
        unlink(save_file);
 
75
        n = open(save_file, O_CREAT|O_WRONLY, 0777);
 
76
        if (n != 1 || (save = fdopen(n, "w")) != stdout) {
 
77
                fprintf(stderr, "Can't open the save file.\n");
 
78
                exit(1);
 
79
        }
 
80
        setbuf(save, stdout_buf);
 
81
 
 
82
        /* READ_HEADER; */
 
83
        fread(&fileheader, sizeof(fileheader), 1, original); 
 
84
        fread(&header, fileheader.f_opthdr, 1, original);
 
85
        fread(&shdrs[1],sizeof(sectionheader),fileheader.f_nscns,original);
 
86
        data_begin = (char *) shdrs[2].s_paddr;
 
87
        data_end = core_end; 
 
88
        original_data = header.a_data; 
 
89
        header.a_data = data_end - data_begin; 
 
90
        diff = header.a_data - original_data; 
 
91
        header.a_bss = sbrk(0) - core_end;  
 
92
        fileheader.f_symptr += diff;
 
93
        fwrite(&fileheader, sizeof(fileheader), 1, save);
 
94
        fwrite(&header,fileheader.f_opthdr , 1, save);
 
95
 
 
96
         /* .text */
 
97
#define INC_IF(x) if(x) x = x+diff;
 
98
 
 
99
         /* .data */
 
100
        INC_IF(shdrs[2].s_size);
 
101
        
 
102
         /* .bss */
 
103
        shdrs[3].s_paddr += diff;
 
104
        shdrs[3].s_vaddr += diff;
 
105
        shdrs[3].s_size = header.a_bss; 
 
106
 
 
107
        for (n = 1;  n <= fileheader.f_nscns;  n++) {
 
108
                INC_IF(shdrs[n].s_lnnoptr);
 
109
                if(n>=3) {INC_IF(shdrs[n].s_scnptr);}
 
110
 
 
111
        };
 
112
        fwrite(&shdrs[1],sizeof(sectionheader),fileheader.f_nscns,save);
 
113
 
 
114
        filecpy(save,original,shdrs[2].s_scnptr - ftell(save));
 
115
 
 
116
        for (n = header.a_data, p = data_begin;  ;  n -= BUFSIZ, p += BUFSIZ)
 
117
                if (n > BUFSIZ)
 
118
                        fwrite(p, BUFSIZ, 1, save);
 
119
                else if (n > 0) {
 
120
                        fwrite(p, 1, n, save);
 
121
                        break;
 
122
                } else
 
123
                        break;
 
124
 
 
125
        fseek(original, original_data, 1);
 
126
 
 
127
        COPY_TO_SAVE;
 
128
 
 
129
        fclose(original);
 
130
        fclose(save);
 
131
}
 
132
 
 
133
Lsave()
 
134
{
 
135
        char filename[256];
 
136
 
 
137
        check_arg(1);
 
138
        check_type_or_pathname_string_symbol_stream(&vs_base[0]);
 
139
        coerce_to_filename(vs_base[0], filename);
 
140
 
 
141
        _cleanup();
 
142
/*
 
143
        {
 
144
                FILE *p;
 
145
                int nfile;
 
146
 
 
147
 
 
148
                nfile = NUMBER_OPEN_FILES;
 
149
 
 
150
                for (p = &_iob[3];  p < &_iob[nfile];  p++)
 
151
                        fclose(p);
 
152
        }
 
153
*/
 
154
        memory_save(kcl_self, filename);
 
155
/*
 
156
        _exit(0);
 
157
*/
 
158
        exit(0);
 
159
        /*  no return  */
 
160
}
 
161
 
 
162
 
 
163
 
 
164
#include "page.h"
 
165
#undef sbrk
 
166
char *sbrk ();
 
167
char *
 
168
sbrk1(n)
 
169
{ char *m1;
 
170
  char * m = sbrk(0);
 
171
/* printf("Calling sbrk(0x%08x),[cur,rently sbrk(0)=0x%08x,core_end=0x%08x,"
 
172
   ,n,m,core_end);
 
173
   */
 
174
 m1 =  sbrk(n);
 
175
 if (core_end && m1!= m)
 
176
   { if (m1 < m ||
 
177
         ((int)m1 % PAGESIZE))
 
178
         { error("unexpected sbrk");
 
179
         }
 
180
     while ( m < m1)
 
181
      {type_map[page(m)] = t_other;
 
182
       m += PAGESIZE;
 
183
     }
 
184
    core_end = m;}
 
185
/*  printf("Returning 0x%08x\n",m); */
 
186
 return m;}
 
187
 
 
188