source: buchla-68k/orig/ROM/BOOTER.C@ 6888aa2

Last change on this file since 6888aa2 was 3ae31e9, checked in by Thomas Lopatic <thomas@…>, 7 years ago

Imported original source code.

  • Property mode set to 100755
File size: 4.1 KB
Line 
1/*
2 ============================================================================
3 booter.c -- load an absolute format Alcyon object file
4 Version 18 -- 1987-11-06 -- D.N. Lynx Crowe
5 ============================================================================
6*/
7
8#define PRINTIT 1 /* define non-zero to get printf output from booter */
9
10#include "stdio.h"
11#include "io.h"
12#include "stddefs.h"
13#include "portab.h"
14#include "objdefs.h"
15#include "biosdefs.h"
16
17extern FILE *fopenb();
18extern int fclose(), fread(), flread();
19extern long getl();
20
21#if PRINTIT
22extern struct fcb *SnapFCB();
23extern int ClusMap();
24#endif
25
26static FILE *B_file; /* boot file pointer */
27
28struct EXFILE B_fhdr; /* executable file header */
29
30long B_txt_o, /* test origin from file header */
31 B_dat_o, /* data origin from file header */
32 B_bss_o, /* bss origin from file header */
33 B_txt_l, /* text length from file header */
34 B_dat_l, /* data length from file header */
35 B_bss_l, /* bss length from file header */
36 B_lod_l, /* total data length loaded */
37 B_end, /* end address */
38 B_chk; /* checksum */
39
40char *B_buf_a; /* boot load address */
41
42short B_log_s; /* boot log switch */
43short B_dbg_s; /* boot debug switch */
44
45/*
46 */
47
48/*
49 ============================================================================
50 booter(fn, textadr) -- load file named by string 'fn' at 'textadr'.
51 If 'textadr' is 0, the text origin from the file will be used.
52 Returns 0 if load was OK, non-zero error code otherwise.
53 ============================================================================
54*/
55
56short
57booter(fn, textadr)
58char *fn;
59long textadr;
60{
61 register long i, bgnbss, endbss;
62 register char *cp;
63#if PRINTIT
64 register struct fcb *fcp;
65#endif
66
67 /* initialize the origins and lengths to 0 */
68
69 B_txt_o = 0L;
70 B_dat_o = 0L;
71 B_bss_o = 0L;
72 B_txt_l = 0L;
73 B_dat_l = 0L;
74 B_bss_l = 0L;
75 B_lod_l = 0L;
76
77 /* open the file */
78
79 if (NULL EQ (B_file = fopenb(fn, "r"))) {
80
81#if PRINTIT
82 if (B_log_s)
83 printf("booter: Unable to open \042%s\042\n", fn);
84#endif
85 return(1);
86 }
87
88#if PRINTIT
89 if (B_dbg_s) { /* if we're debugging, print the FCB stuff */
90
91 fcp = (struct fcb *)(chantab[B_file->_unit].c_arg);
92
93 SnapFCB(fcp);
94 ClusMap(fcp);
95 waitcr();
96 }
97#endif
98
99 /* read in the file header */
100
101 if (1 NE fread(&B_fhdr, sizeof B_fhdr, 1, B_file)) {
102
103#if PRINTIT
104 if (B_log_s)
105 printf("booter: Unable to read header for \042%s\042\n", fn);
106#endif
107 fclose(B_file);
108 return(2);
109 }
110
111 /* check the magic */
112
113 if ((B_fhdr.F_Magic NE F_R_C) AND (B_fhdr.F_Magic NE F_R_D)) {
114
115#if PRINTIT
116 if (B_log_s)
117 printf("booter: Bad magic [0x%04x] in file \042%s\042",
118 B_fhdr.F_Magic, fn);
119#endif
120 fclose(B_file);
121 return(3);
122 }
123
124/*
125
126*/
127
128 /* if it's a discontinuous file, read the origins */
129
130 if (B_fhdr.F_Magic EQ F_R_D) {
131
132 B_dat_o = getl(B_file);
133 B_bss_o = getl(B_file);
134 }
135
136 B_txt_o = B_fhdr.F_Res2;
137
138 B_buf_a = textadr ? textadr : B_txt_o;
139 B_lod_l = B_fhdr.F_Text + B_fhdr.F_Data;
140
141 if (0 NE flread(B_buf_a, B_lod_l, B_file)) {
142
143#if PRINTIT
144 if (B_log_s)
145 printf("booter: Unable to read \042%s\042\n", fn);
146#endif
147 fclose(B_file);
148 return(4);
149 }
150
151 B_end = B_buf_a + B_lod_l - 1L;
152
153 B_txt_l = B_fhdr.F_Text;
154 B_dat_l = B_fhdr.F_Data;
155 B_bss_l = B_fhdr.F_BSS;
156
157 cp = B_buf_a; /* calculate checksum */
158 B_chk = 0L;
159
160 for (i = 0; i < B_lod_l; i++)
161 B_chk += *cp++ & 0x000000FFL;
162
163 if (B_bss_o)
164 bgnbss = B_bss_o;
165 else
166 bgnbss = B_end + 1L;
167
168 endbss = bgnbss + B_bss_l - 1L;
169
170#if PRINTIT
171 if (B_log_s) {
172
173 printf("File \042%s\042 loaded from $%08lX to $%08lX\r\n",
174 fn, B_buf_a, B_end);
175 printf(" BSS $%08lX to $%08lX\r\n", bgnbss, endbss);
176 printf("Checksum = $%08lX, Load length = %ld ($%08lX)\r\n",
177 B_chk, B_lod_l, B_lod_l);
178 printf(" B_txt_o = $%08lX, B_dat_o = $%08lX, B_bss_o = $%08lX\r\n",
179 B_txt_o, B_dat_o, B_bss_o);
180 printf(" B_txt_l = $%08lX, B_dat_l = $%08lX, B_bss_l = $%08lX\r\n",
181 B_txt_l, B_dat_l, B_bss_l);
182 }
183#endif
184
185 fclose(B_file);
186 return(0);
187}
Note: See TracBrowser for help on using the repository browser.