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

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

Point of no return.

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