source: buchla-68k/rom/booter.c@ 411371e

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

Removed redundant declarations.

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