1 /****^  ***********************************************************
  2         *                                                         *
  3         * Copyright, (C) Honeywell Bull Inc., 1987                *
  4         *                                                         *
  5         * Copyright, (C) Honeywell Information Systems Inc., 1984 *
  6         *                                                         *
  7         *********************************************************** */
  8 /* INIT_CLOCKS -- read time string from operator, set all clocks */
  9 /* format: style2 */
 10 /* BIM 10/82 */
 11 /* Modified 2/83 by Keith Loepere to use bce_command_processor_ and
 12      environment */
 13 /* Modified 6/83 by Keith Loepere so operator doesn't have to enter time. */
 14 /* Modified 4/84 by Keith Loepere for simplification */
 15 /* Modified 7/84 by J Falksen for new date/time software */
 16 /* Modified 1/85 by Keith Loepere to check RPV time unmounted. */
 17 /* Modified 1/85 by Keith Loepere to not set date/time defaults and to use
 18      time_info_ to automatically set delta given a zone. */
 19 
 20 
 21 
 22 /****^  HISTORY COMMENTS:
 23   1) change(1986-12-04,Fawcett), approve(1986-12-17,MECR0006),
 24      audit(1986-12-12,GDixon), install(1986-12-17,MR12.0-1250):
 25      Changed to call date_time_$set_time_defaults. If the operator inputs
 26      a new time string with a time zone the correct time will set.
 27   2) change(1987-01-08,Fawcett), approve(1987-01-08,MCR7600),
 28      audit(1987-01-13,GJohnson), install(1987-01-13,MR12.0-1270):
 29      This closes MECR0006.
 30   3) change(1999-06-23,Haggett), audit(2018-01-13,GDixon),
 31      install(2018-01-16,MR12.6g-0004):
 32      Y2K
 33   4) change(2018-01-13,Swenson), approve(2018-01-13,MCR10041),
 34      audit(2018-01-13,GDixon), install(2018-01-16,MR12.6g-0004):
 35      Fix issue with boot_delta clok card param handling when param not present.
 36   5) change(2020-01-22,Swenson), approve(2020-01-22,MCR10075),
 37      audit(2020-02-01,GDixon), install(2020-02-01,MR12.6g-0040):
 38      Fix typo in message telling when system was last shutdown.
 39                                                    END HISTORY COMMENTS */
 40 
 41 
 42 init_clocks:
 43      procedure (success);
 44 
 45 /* Parameters */
 46 
 47           declare success                bit (1) aligned parameter;
 48 
 49 /* Constants */
 50 
 51           declare me                     char (11) init ("init_clocks") static options (constant);
 52           declare time_format            char (41) int static options (constant)
 53                                          init ("^dn, ^mn ^Z9dm, ^9999yc ^Z9Hd:^MH:^SM ^za");
 54 
 55 /* Entries */
 56 
 57           declare bce_query              entry options (variable);
 58           declare bce_query$yes_no       entry options (variable);
 59           declare com_err_               entry options (variable);
 60           declare convert_date_to_binary_
 61                                          entry (char (*), fixed bin (71), fixed bin (35));
 62           declare date_time_$format      entry (char (*), fixed bin (71), char (*), char (*)) returns (char (250) var);
 63           declare date_time_$set_time_defaults
 64                                          entry ();
 65           declare ioa_                   entry () options (variable);
 66           declare privileged_mode_ut$sscr
 67                                          entry (fixed bin (3), fixed bin (6), fixed bin (71));
 68           declare read_disk              entry (fixed bin, fixed bin, ptr, fixed bin (35));
 69 
 70 /* Variables */
 71 
 72           declare TIME                   fixed bin (71);
 73           declare bootload_scu           fixed bin (3);
 74           declare code                   fixed bin (35);
 75           declare line                   char (80);
 76           declare time_correction        fixed bin (71);
 77           declare time_string            char (64) var;
 78           declare zone                   char (4);
 79           declare 1 rpv_label            aligned like label;
 80 
 81 /* External */
 82 
 83           declare disk_config_deck$      external static;
 84           declare pvt$root_pvtx          fixed bin external static;
 85           declare sys_info$clock_        bit (3) aligned external static;
 86           declare sys_info$first_reasonable_time
 87                                          fixed bin (71) external static;
 88           declare sys_info$last_reasonable_time
 89                                          fixed bin (71) external static;
 90           declare sys_info$time_correction_constant
 91                                          fixed bin (71) aligned external static;
 92           declare sys_info$time_zone     char (4) aligned external static;
 93 
 94 /* Misc */
 95 
 96           declare (addr, addrel, bin, clock, divide, fixed, hbound, lbound, rtrim, size, substr, unspec)
 97                                          builtin;
 98 %page;
 99           success = "0"b;
100 
101           call find_zone;                                   /* zone defined by current clock "card" */
102 
103           bootload_scu = fixed (sys_info$clock_, 3);
104 
105           TIME = clock ();
106 
107           call read_rpv_label ();
108           time_string = date_time_$format (time_format, label.time_unmounted, zone, "");
109           call ioa_ ("System was last shutdown at:^/^a", time_string);
110 
111           call check_time;
112           line = "xxx";
113           do while (^(line = "n" | line = "no"));
114                call bce_query (line, "Is this correct? ");
115                if line = "y" | line = "yes"
116                then do;
117                          call set_defaults;                 /* if things were correct set the date_time defaults */
118                          call check_rpv;
119                          success = "1"b;
120                          return;
121                     end;
122                else if line = "abort"
123                then return;
124           end;
125 
126 CHECK_TIME:
127           call bce_query (line, "Enter time: ");
128           if line = "abort"
129           then do;
130 ABORT:
131                     success = "0"b;
132                     return;
133                end;
134 
135           call set_defaults;
136 
137           call convert_date_to_binary_ (line, TIME, code);
138 
139           if code ^= 0
140           then do;                                          /* Operator's time string invalid?                */
141                     call com_err_ (code, me, "^a", rtrim (line));
142                     go to CHECK_TIME;
143                end;
144 
145           if scs$controller_data (bootload_scu).type < "0010"b
146           then do;                                          /* help out operator */
147                     call ioa_ ("SCU Switches (octal): ^w ^w", substr (unspec (TIME), 1, 36), substr (unspec (TIME), 37));
148 
149                     call bce_query (line, "Enter anything after the switches have been set. ");
150                     TIME = clock ();
151                end;
152 
153           call check_time;
154           line = "xxx";
155           do while (^(line = "n" | line = "no"));
156                call bce_query (line, "Is this correct? ");
157                if line = "y" | line = "yes"
158                then do;
159                          if scs$controller_data (bootload_scu).type < "0010"b
160                          then ;
161                          else call set_clocks;              /* set in all controllers */
162                          call check_rpv;
163                          success = "1"b;
164                          return;
165                     end;
166                else if line = "abort"
167                then return;
168           end;
169           go to CHECK_TIME;
170 %page;
171 
172 set_defaults:
173      proc;
174           sys_info$time_zone = zone;
175           sys_info$time_correction_constant = time_correction;
176           call date_time_$set_time_defaults ();
177      end set_defaults;
178 
179 set_clocks:
180      proc;
181 
182           declare controllerx            fixed bin (3);
183 
184           do controllerx = lbound (scs$controller_data, 1) to hbound (scs$controller_data, 1);
185                if bin (scs$controller_data (controllerx).type, 4) >= 0010b & scs$controller_data (controllerx).online
186                then call privileged_mode_ut$sscr (controllerx, SC_ETC, TIME);
187           end;
188           return;
189      end;
190 
191 find_zone:
192      proc;
193 
194 /* Find time zone, checking that it is in time_info_.
195    We must do this by looking at disk_config_deck. */
196 
197           declare idx                    fixed bin;
198           declare lang_index             fixed bin;
199           declare zone_index             fixed bin;
200 
201           cardp = addr (disk_config_deck$);
202           config_max_cards = divide (4096 - 1, size (config_card), 17, 0);
203                                                             /* Assume four page default */
204 
205           do idx = 1 to config_max_cards while (config_card.word ^= FREE_CARD_WORD & config_card.word ^= CLOK_CARD_WORD);
206                cardp = addrel (cardp, size (config_card));  /* on to the next card */
207           end;
208 
209           if idx <= config_max_cards
210           then if config_card.word = CLOK_CARD_WORD
211                then do;
212                          clok_cardp = cardp;
213                          zone = clok_card.zone;
214                          do lang_index = 1 to ti_zone.number_lang;
215                               do zone_index = 1 to ti_zone.number_zone;
216                                    if ti_zone.short (lang_index, zone_index) = clok_card.zone
217                                    then go to found_zone;
218                               end;
219                          end;
220                          call com_err_ (0, me, "The zone named on the CLOK card is not in time_info_");
221                          goto ABORT;
222 found_zone:
223                          time_correction = ti_zone.delta (lang_index, zone_index);
224                     end;
225                else go to no_clok;
226           else do;
227 no_clok:
228                     call com_err_ (0, me, "No clok card in config deck.");
229                     go to ABORT;
230                end;
231           return;
232      end;
233 
234 check_time:
235      proc;
236 
237           time_string = date_time_$format (time_format, TIME, zone, "");
238           call ioa_ ("Current system time is: ^a.", time_string);
239           if TIME <= sys_info$first_reasonable_time | TIME >= sys_info$last_reasonable_time | TIME < label.time_unmounted
240           then do;
241                     call ioa_ ("This is clearly incorrect.");
242                     go to CHECK_TIME;
243                end;
244           return;
245      end;
246 %page;
247 check_rpv:
248      proc;
249 
250 /* Make sure the time is reasonable relative to the RPV time unmounted. */
251 
252           dcl     yes_no                 bit (1) aligned;
253 
254           if label.time_unmounted <= sys_info$first_reasonable_time
255                | label.time_unmounted >= sys_info$last_reasonable_time
256           then return;                                      /* bogus label times */
257 
258           if clock () < label.time_unmounted
259           then do;
260                     call bce_query$yes_no (yes_no,
261                          "The current time is *before* the last shutdown time recorded in the RPV.
262 Are you sure the time is correct? ");
263                     if ^yes_no
264                     then go to CHECK_TIME;
265                end;
266 
267           if clok_card.boot_delta ^= -1 & clock () > label.time_unmounted + clok_card.boot_delta * 3600 * 1000000
268           then do;
269                     call bce_query$yes_no (yes_no, "The current time is more than the supplied boot_delta hours beyond the
270 unmounted time recorded in the RPV label.  Is this correct? ");
271                     if ^yes_no
272                     then go to CHECK_TIME;
273 
274                     if (divide (clock () - label.time_unmounted, 3600 * 1000000, 17, 0) > 12) then do;
275                          call bce_query$yes_no (yes_no, "The current time I'm using is more than 12 hours
276 after the last shutdown time recorded in the RPV label.
277 Are you sure this is correct? ");
278                          if ^yes_no then
279                               goto CHECK_TIME;
280                     end;
281                end;
282           return;                                           /* okay */
283      end;
284 %skip;
285 read_rpv_label:
286      proc;
287 
288           labelp = addr (rpv_label);
289           call read_disk (pvt$root_pvtx, LABEL_ADDR, labelp, code);
290           if code ^= 0
291           then do;
292                     call com_err_ (code, me, "RPV label");
293                     go to ABORT;
294                end;
295           return;
296 
297 end read_rpv_label;
298 %page;
299 %include config_deck;
300 %page;
301 %include config_clok_card;
302 %page;
303 %include disk_pack;
304 %page;
305 %include fs_vol_label;
306 %page;
307 %include scr;
308 %page;
309 %include scs;
310 %page;
311 %include time_names;
312      end init_clocks;