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

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

Fixed indentation.

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