source: buchla-68k/rom/booter.c@ 6262b5c

Last change on this file since 6262b5c was 6262b5c, checked in by Thomas Lopatic <thomas@…>, 7 years ago

Added include files for global functions and variables.

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