;;; -*- Mode: Common-Lisp; Package: User; Base: 10.; Patch-File: T -*-

;;; Reason: Fix Hardware-Boot-Initializations to skip processor spin if not MP and to support CSIB
;;; (won't take effect until after a disk save).

;;;                           RESTRICTED RIGHTS LEGEND
;;;
;;; Use, duplication, or disclosure by the Government is subject to
;;; restrictions as set forth in subdivision (c)(1)(ii) of the Rights in
;;; Technical Data and Computer Software clause at 52.227-7013.
;;;
;;;   TEXAS INSTRUMENTS INCORPORATED      
;;;   P.O. BOX 2909, M/S 2151             
;;;   AUSTIN, TEXAS 78769                 
;;;
;;; Copyright (C) 1989 Texas Instruments Incorporated.
;;; All rights reserved.

;;; Written 04/25/89 08:23:41 by SWEDE,
;;; while running on ERIK from band LODX
;;; With Experimental REL6G 6.1, Experimental SYSTEM 6.0, Experimental VIRTUAL-MEMORY 6.0,
;;;  Experimental EH 6.0, Experimental MAKE-SYSTEM 6.0, Experimental MICRONET 6.0,
;;;  Experimental LOCAL-FILE 6.0, Experimental BASIC-PATHNAME 6.0, Experimental NETWORK-SUPPORT-COLD 6.0,
;;;  Experimental BASIC-NAMESPACE 6.0, Experimental NETWORK-NAMESPACE 6.0, Experimental DISK-IO 6.0,
;;;  Experimental DISK-LABEL 6.0, Experimental BASIC-FILE 6.0, Experimental MAC-PATHNAME 6.0,
;;;  Experimental NETWORK-PATHNAME 6.0, Experimental COMPILER 6.0, Experimental TV 6.0,
;;;  Experimental DATALINK 6.0, Experimental CHAOSNET 6.0, Experimental GC 6.0, Experimental MEMORY-AUX 6.0,
;;;  Experimental NVRAM 6.0, Experimental SYSLOG 6.0, Experimental STREAMER-TAPE 6.0,
;;;  Experimental CLEH 1.0, Experimental UCL 6.0, Experimental INPUT-EDITOR 6.0, Experimental METER 6.0,
;;;  Experimental ZWEI 6.0, Experimental DEBUG-TOOLS 6.0, Experimental NETWORK-SUPPORT 6.0,
;;;  Experimental NETWORK-SERVICE 6.0, DATALINK-DISPLAYS 6.0, Experimental FONT-EDITOR 6.0,
;;;  Experimental SERIAL 6.0, Experimental PRINTER 6.0, Experimental MAC-PRINTER-TYPES 6.0,
;;;  Experimental PRINTER-TYPES 6.0, Experimental IMAGEN 6.0, Experimental SUGGESTIONS 6.0,
;;;  Experimental MAIL-DAEMON 6.0, Experimental MAIL-READER 6.0, Experimental TELNET 6.0,
;;;  Experimental VT100 6.0, Experimental NAMESPACE-EDITOR 6.0, Experimental PROFILE 6.0,
;;;  VISIDOC 6.0, Experimental TI-CLOS 16.5, Experimental CLX 4.0, Experimental X11M 2.0,
;;;  Experimental CLUE 19.0, Experimental RPC 6.0, NFS 3.5, Experimental BUG 11.4,
;;;  IP 3.43, Experimental DOCUMENTER 617.0,  microcode 423, Band Name: Rel 6.0 + SLE 4/19

#!C
; From file LISP-REINITIALIZE.LISP#> KERNEL; MR-X:
#10R SYSTEM#:
(COMPILER-LET ((*PACKAGE* (FIND-PACKAGE "SYSTEM"))
                          (SI:*LISP-MODE* :COMMON-LISP)
                          (*READTABLE* COMMON-LISP-READTABLE)
                          (SI:*READER-SYMBOL-SUBSTITUTIONS* *COMMON-LISP-SYMBOL-SUBSTITUTIONS*))
  (COMPILER#:PATCH-SOURCE-FILE "SYS: KERNEL; LISP-REINITIALIZE.#"


(Defun Hardware-Boot-Initializations (Cold-Boot)
  (DECLARE (SPECIAL tv:sib-is-csib tv:csib-expans-no-transp-va
		    *bw-tv-io-space-virtual-address* %%csib-tv-mono-blank-mask))

  (Setup-Physical-Resources)

  (COND ((AND (Boundp 'Cold-Hardware-Initializations)
	      *sib-present*)
	 (Mapc #'*EVAL Cold-Hardware-Initializations) ;<<======= first use of interpreter
	 ;; The following spin is deisgned for an MP system.  When more than one processor is booting,
	 ;; the processors not in lowest slot MUST wait for the Lowest slot proc to get moving
	 ;; currently, we use slot 6 as lowest (this needs to be changed to scan for lowest booting processor
	 (when (and (mp-system-p)			; jlm 4/25/89
		    (not (si:cool-boot-p)))		;; marky 12-19-88
	   (let ((powerfail-addr (if tv:sib-is-csib
				     %csib-powerfail-event-address-1
				     %sib-powerfail-event-address-1)))
	     (do ((val (logand #xffffffff (si:%nubus-read tv:tv-slot-number powerfail-addr))
		       (logand #xffffffff (si:%nubus-read tv:tv-slot-number powerfail-addr))))
		 ((= val (logior #xf6000000 %slot-power-fail-event)))
	       (do ((x 100. (1- x))) ((< x 0)))
	       ))))
	((NOT *sib-present*)
	 (MAKUNBOUND 'tv:sib-slot-number)	;so we will trap if we try to use it (which cannot work)!
	 (MAKUNBOUND 'tv:tv-slot-number)))

  ;;**AB** Event generator used for sequence breaking.
  (COND ((AND cold-boot (OR (mx-p) (exp2-p)))
	 (and (fboundp 'setup-event-generator) (setup-event-generator))
	 (and (fboundp 'setup-processor-slot) (setup-processor-slot)))
	((OR (mx-p) (exp2-p))			;warm boot
	 (and (fboundp 'enable-event-timer-interrupt) (enable-event-timer-interrupt))))

  (When Cold-Boot
    (UNLESS (mx-p) (INITIALIZE-NuBUS-SLOTS))
    ;; Hack notes:
    ;; %BOOT-VIRTUAL-MEMORY must come before CLEAR-SCREEN-BUFFER
    ;; so that the screen buffer virtual memory is set up before
    ;; we touch it.
    ;; Consequences:
    ;;  o %BOOT-VIRTUAL-MEMORY can't rely on anything on the
    ;;    crash list (not yet run)
    ;;  o After these h/w inits, you will have use of your
    ;;    full physical memory.
    (%boot-virtual-memory)
    (WHEN *sib-present*
      (%initialize-tv-screen-memory)
      (unless (cool-boot-p)
	(CLEAR-SCREEN-BUFFER	
	  (if tv:sib-is-csib
	      TV:CSIB-EXPANS-NO-TRANSP-VA	;these are currently the same value
	      *BW-TV-IO-SPACE-VIRTUAL-ADDRESS*)))))
  (WHEN (and *sib-present*
	     (not (cool-boot-p)))
    ;; Unblank the screen on both COLD and WARM boots.
    (IF tv:sib-is-csib
	;; CSIB is already reverse-video (and is at a different address)
	(%NuBus-write TV:TV-Slot-Number
		      %CSIB-TV-Video-Attribute
		      (dpb 1 %%csib-tv-mono-blank-mask
			   (DPB 1 %%CSIB-TV-Video-Blank-Mask 0)))
	(%NuBus-write TV:TV-Slot-Number
		      %SIB-TV-Video-Attribute
		      (DPB 0 %%SIB-TV-Video-Not-Blanked
			   (DPB 0 %%SIB-TV-Video-Black-on-White 0)))))

  ;; set up pointer to processor run light
  (COND (*sib-present* (SETQ REALLY-RUN-LIGHT (- %DISK-RUN-LIGHT 4)))
	(t (MAKUNBOUND 'really-run-light)))	;so we'll trap if we try to write to it!
  )
))
