home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / simtel / sigm / vols000 / vol050 / bios3 < prev    next >
Encoding:
Text File  |  1984-04-29  |  11.8 KB  |  636 lines

  1. ;    B o o t   C P / M   f r o m   d i s k.
  2. ;
  3. ;    The CBOOT entry point gets control from the cold start
  4. ;    loader and is responsible for the basic system initial-
  5. ;    ization.  This includes outputting a sign-on message and
  6. ;    initializing the following page zero locations:
  7. ;
  8. ;       0,1,2: Set to the warmstart jump vector.
  9. ;           3: Set to the initial IOBYTE value.
  10. ;           4: Default and logged on drive.
  11. ;       5,6,7: Set to a jump to BDOS.
  12. ;
  13. ;    It also constructs the BIOS tables DPH, DSKOFF and DSKMSK
  14. ;    for the current configuration.
  15. ;
  16. ;    Register A contains the logical unit number of the boot
  17. ;    drive on entry.  The exit address is to the CCP routine.
  18. ;
  19. ;
  20.  
  21.  
  22.     JMP    STSINI        ;STSCOPY initialization entry.
  23.                 ;Must be at CBOOT-3.
  24. ;
  25. CBOOT:
  26.     STA    BTLUN        ;Set boot logical unit number
  27.     STA    CIOBFS+1
  28. CBOOT0:
  29. ;
  30.     LXI    SP,DBUF
  31.  
  32.     CALL    URINIT        ;Initialize unit record I/O
  33.  
  34. STS:
  35. ;Configure disk controller and BIOS.
  36. ;
  37.     MVI    C,16*NDSK-1    ;Clear DPH table
  38.     LXI    H,DPH
  39.     XRA    A
  40.     MOV    M,A
  41.     LXI    D,DPH+1
  42.     CALL    MOVDTA
  43. ;
  44.     LXI    H,CONTBL    ;HL=address of configuration table entry
  45.     MVI    B,CONTLN    ;B=# entries in configuration table
  46. ;
  47. ;
  48. CON1:                ;Major loop
  49. ;
  50. ;    Assign drive type
  51. ;
  52.     MVI    A,0FFh        ;Initialize 2nd byte of DTYPE entry.
  53.     STA    CONFS
  54.     MOV    A,M        ;Set LUN into command buffer
  55.     STA    CIOADT+1
  56.     RLC            ;Put LUN into message.
  57.     RLC
  58.     RLC
  59.     ANI    7
  60.     ADI    '0'
  61.     STA    ADTLUN
  62.     LDA    BTLUN        ;Boot LUN?
  63.     CMP    M
  64.     JNZ    CN1
  65.     INX    H        ;Yes
  66.     MOV    A,M        ;Set boot TFC
  67.     STA    CIOBFS+5
  68.     INX    H        ;Set CCP beginning sector
  69.     MOV    A,M
  70.     STA    BTSLA0
  71.     INX    H        ;Set # sectors in CCP
  72.     MOV    A,M
  73.     STA    BTNSEC
  74.     PUSH    H
  75.     LXI    D,-DSKMSK    ;Select the boot drive
  76.     LHLD    CONMSK
  77.     DAD    D
  78.     MOV    A,L
  79.     STA    CDISK
  80.     POP    H
  81.     JMP    CN2
  82. CN1:
  83.     INX    H        ;Skip warm boot parameters
  84.     INX    H
  85.     INX    H
  86. CN2:
  87.     INX    H
  88.     MOV    A,M        ;Set drive type into command buffer
  89.     STA    CIOADT+4
  90.     INX    H
  91.     CPI    0FFh        ;Does controller have Class 6, op code 1
  92.     JZ    CON2
  93.     PUSH    B        ;Yes. Save major loop count
  94.     PUSH    H        ;Save table pointer
  95.     LXI    H,CIOADT    ;Output command buffer
  96.     CALL    EXEC
  97.     CZ    WAITF        ;Wait for function to complete
  98.     MOV    A,C        ;Completion status
  99.     POP    H        ;Restore table pointer
  100.     POP    B        ;Restore major loop count
  101.     ANI    FERR
  102.     JZ    CON2
  103.     PUSH    B        ;Save major loop count
  104.     PUSH    H        ;Save table pointer
  105.     LXI    H,ADTMES
  106.     CALL    CONCHK        ;Print message & check for host
  107.     POP    H        ;Restore table pointer
  108. CON2:
  109.     MOV    A,M        ;Get LUNiTYPE
  110.     STA    CONTYPE        ; and save it.
  111.     INX    H
  112.     MOV    A,M        ;Get track format codes
  113.     STA    CONTFC
  114.     INX    H
  115.     MOV    E,M        ;Get # allocation blocks
  116.     INX    H
  117.     MOV    D,M
  118.     INX    H
  119.     XCHG            ;  and save it.
  120.     SHLD    ALLBKS
  121.     XCHG
  122.     MOV    C,M        ;Get minor loop count
  123.     INX    H
  124.     MOV    E,M        ;Get number of sectors
  125.     INX    H
  126.     MOV    D,M
  127.     INX    H
  128. ;
  129. ;    Find DPB for this type
  130. ;
  131.     PUSH    H        ;Save table pointer
  132.     PUSH    B        ;Save counts
  133.     LXI    H,FPYTYP    ;Initialize floppy type pointer
  134.     LDA    CONTYPE
  135.     MOV    B,A
  136.     ANI    TYPEDRV        ;Floppy?
  137.     MOV    A,B
  138.     POP    B        ;Restore counts
  139.     JZ    CON4
  140.     ANI    TYPEN48+TYPEN96        ;No. Mini?
  141.     JNZ    CON3
  142.     MVI    A,2        ;No. Hard disk.
  143.     JMP    CON6
  144. CON3:
  145.     LXI    H,MINTYP
  146. CON4:
  147.     SHLD    FPYTY        ;Save pointer to TFC table
  148.     LHLD    ALLBKS        ;Normalize allocation block
  149.                 ; specification to single-density,
  150.     LDA    CONTYPE        ; single-sided.
  151.     ANI    TYPESEC
  152.     RAR
  153.     MOV    D,A
  154.     CNZ    DBLSHR
  155.     MVI    D,1
  156.     LDA    CONTFC
  157.     ANI    10101010b    ;Double-sided format codes
  158.     CNZ    DBLSHR
  159.     SHLD    ALLINC
  160.     LXI    D,0        ;DSKOFF increment is 0.
  161. CON5:                ;Minor loop return for floppy
  162.     LHLD    CONFS        ;H=TFC selection bits, L=current TFC
  163.     MOV    A,H        ;This TFC selected?
  164. CON51:
  165.     INR    L
  166.     RAR
  167.     JNC    CON51
  168.     MOV    H,A        ;Save selection bits
  169.     SHLD    CONFS
  170.     PUSH    D        ;Get DPB type and model
  171.     MVI    H,0
  172.     XCHG
  173.     LHLD    FPYTY
  174.     DAD    D
  175.     DAD    D
  176.     POP    D
  177.     MOV    A,M
  178.     STA    CONTYPE        ;Save DPB type
  179.     INX    H
  180.     MOV    A,M        ;Get DPB model
  181. CON6:
  182.     XCHG            ;Save DSKOFF increment
  183.     SHLD    OFFINC
  184.     LXI    D,16        ;Find prototype DPB
  185.     LXI    H,CONPBT
  186. CON7:
  187.     CMP    M
  188.     JZ    CON8
  189.  
  190.     DAD    D
  191.     JMP    CON7
  192. CON8:
  193.     PUSH    B        ;Save loop counts
  194.     LXI    D,CURDPB    ;Move prototype DPB to buffer
  195.     MVI    C,16
  196.     CALL    MOVDTA
  197.     LXI    H,CURDPB    ;Set type in DPB
  198.     LDA    CONTYPE
  199.     CPI    TYPEFPY+0    ;Standard distribution format?
  200.     JZ    CON11        ;If so, use DPB as is.
  201.     MOV    M,A
  202.     LXI    D,6        ;Offset to # allocation blocks
  203.     DAD    D
  204.     XCHG
  205.     LHLD    ALLBKS        ;Compute # allocation blocks for this TFC
  206.     MVI    C,0
  207.     MOV    B,A
  208.     ANI    TYPEFPY+TYPEMIN
  209.     JZ    CON10
  210.     LHLD    ALLINC
  211.     MOV    A,B
  212.     ANI    TYPESEC
  213.     RAR
  214.     MOV    C,A
  215.     MOV    A,B
  216.     ANI    1
  217.     JZ    CON9
  218.     INR    C
  219. CON9:
  220.     DCR    C
  221.     JM    CON10
  222.     DAD    H
  223.     JMP    CON9
  224. CON10:
  225.     DCX    H
  226.     XCHG
  227.     MOV    M,E        ;Set # allocation blocks
  228.     INX    H
  229.     MOV    M,D
  230. CON11:
  231.     LXI    H,DPB
  232. CON12:                ;Do we already have this DPB?
  233.     XCHG            ;End of DPB table?
  234.     LHLD    CONPB
  235.     MOV    A,D
  236.     CMP    H
  237.     JNZ    CON13
  238.     MOV    A,E
  239.     CMP    L
  240.     JZ    CON16
  241. CON13:
  242.     PUSH    D        ;Save entry pointer
  243.     MVI    C,16        ;Compare entry
  244.     LXI    H,CURDPB
  245. CON14:
  246.     LDAX    D
  247.     CMP    M
  248.     JNZ    CON15
  249.     INX    D
  250.     INX    H
  251.     DCR    C
  252.     JNZ    CON14
  253.     JMP    CON17        ;Have a match
  254. CON15:
  255.     POP    H        ;Restore entry pointer
  256.     LXI    D,16        ;Index to next entry
  257.     DAD    D
  258.     JMP    CON12
  259. CON16:
  260.     PUSH    H
  261.     XCHG            ;Put new entry in DPB table
  262.     LXI    H,CURDPB
  263.     MVI    C,16
  264.     CALL    MOVDTA
  265.     XCHG
  266.     SHLD    CONPB        ;Set new end of DPB table
  267. CON17:
  268.     POP    H
  269.     INX    H
  270.     SHLD    CONDPB        ;Save DPB address
  271. ;
  272. ;  Compute allocation vector increment
  273. ;
  274.     LHLD    CURDPB+6    ;Get # allocation blocks
  275.     LXI    D,7        ;Round up
  276.     DAD    D
  277.     MVI    D,3
  278.     CALL    DBLSHR
  279.     SHLD    ALVINC
  280. ;
  281. ;    Initialize current DPH entry
  282. ;
  283.     LDA    CURDPB
  284.     CPI    TYPEFPY+0
  285.     LXI    H,0        ;Set translate table address to zero
  286.     JNZ    CON18        ;Standard distribution format?
  287.     LXI    H,XLTS        ;Yes.  Do translation.
  288. CON18:
  289.     SHLD    CONXLT        ;Save translate table address
  290.     LXI    H,0        ;Set check vector address in CONDPH
  291.     LDA    CONTYPE
  292.     ANI    TYPEFPY+TYPEMIN        ;Floppy?
  293.     JZ    CON20
  294. CON19:
  295.     LHLD    CSVALUE
  296. CON20:
  297.     SHLD    CONCSV
  298.     LXI    H,0        ;Initialize current offset value
  299.     SHLD    OFFVAL
  300.     SHLD    OFFVAL+1
  301.     POP    B        ;Restore counts
  302. ;
  303. ;
  304. ;
  305. CON21:                ;Minor loop return for hard disk
  306.     LHLD    CONTY        ;Set DTYPE entry
  307.     LDA    CURDPB
  308.     MOV    M,A
  309.     INX    H
  310.     LDA    CONFS
  311.     MOV    M,A
  312.     INX    H
  313.     SHLD    CONTY
  314.  
  315.     LHLD    CONMSK        ;Set DSKMSK entry
  316.     LDA    CIOADT+1
  317.     MOV    M,A
  318.     INX    H
  319.     SHLD    CONMSK
  320.  
  321.     LHLD    OFFVAL+1    ;Set DSKOFF entry
  322.     XCHG
  323.     LHLD    CONOFF
  324.     LDA    OFFVAL
  325.     MOV    M,A
  326.     INX    H
  327.     MOV    M,D
  328.     INX    H
  329.     MOV    M,E
  330.     INX    H
  331.     SHLD    CONOFF
  332.     LHLD    OFFINC
  333.     DAD    D
  334.     SHLD    OFFVAL+1
  335.     JNC    CON22
  336.     LXI    H,OFFVAL
  337.     INR    M
  338. CON22:
  339.  
  340.     PUSH    B        ;Save loop counts
  341.     LHLD    CONDPH        ;Move DPH entry
  342.     XCHG
  343.     LXI    H,CURDPH
  344.     MVI    C,16
  345.     CALL    MOVDTA
  346.     XCHG
  347.     SHLD    CONDPH
  348.     POP    B        ;Restore loop counts
  349.     LDA    CONTYPE    
  350.     ANI    TYPEFPY+TYPEMIN        ;Floppy?
  351.     LHLD    ALVINC
  352.     XCHG
  353.     JZ    CON24
  354. CON23:
  355.     PUSH    D        ;Yes.  Floppy.
  356.     LHLD    CURDPB+12
  357.     XCHG
  358.     LHLD    CSVALUE        ;Increment CSV value
  359.     SHLD    CONCSV
  360.     DAD    D
  361.     SHLD    CSVALUE
  362.     POP    D
  363. CON24:
  364.     LHLD    CONALV        ;Increment ALV value
  365.     DAD    D
  366.     SHLD    CONALV
  367.  
  368.     DCR    C        ;Decrement minor loop count
  369.     JZ    CON25
  370.     LDA    CONTYPE
  371.     ANI    TYPEFPY+TYPEMIN        ;Floppy?
  372.     JNZ    CON5
  373.     JMP    CON21
  374. ;
  375. ;
  376. CON25:
  377.     POP    H        ;Restore table pointer
  378.     DCR    B        ;Decrement major loop count
  379.     JNZ    CON1
  380.     LDA    CIOBFS+5    ;Is boot drive a hard disk?
  381.     CPI    0FFh
  382.     JZ    CBOOT1
  383.     LXI    H,DTYPE+1    ;No.  Find the boot drive.
  384.     MOV    B,A
  385.     LDA    CDISK
  386.     MOV    E,A
  387.     MVI    D,0
  388.     DAD    D
  389.     DAD    D
  390.     MOV    A,B
  391. CON26:
  392.     CMP    M        ;This TFC?
  393.     JZ    CON27
  394.     INX    H        ;No.
  395.     INX    H
  396.     INR    E
  397.     JMP    CON26
  398. CON27:
  399.     MOV    A,E
  400.     STA    CDISK
  401.  
  402. CBOOT1:
  403.     LXI    H,SIGNON
  404.     CALL    PRINT
  405.  
  406.     XRA    A
  407.     STA    IOBYTE
  408.     JMP    GOCPM        ;Initialize for CP/M
  409.  
  410. DBLSHR:
  411.     XRA    A        ;Clear carry
  412.     MOV    A,H
  413.     RAR
  414.     MOV    H,A
  415.     MOV    A,L
  416.     RAR
  417.     MOV    L,A
  418.     DCR    D
  419.     JNZ    DBLSHR
  420.     RET
  421. ;
  422. ;Print error message and halt if host drive
  423. ;
  424. ;    Entry:    HL = address of error message
  425. ;    Exit:    Only if not host drive
  426. ;
  427. CONCHK:
  428.     CALL    PRINT
  429.     LXI    H,BTLUN        ;Is error on host drive?
  430.     LDA    CIOADT+1
  431.     CMP    M
  432.     RNZ
  433.     LXI    H,ADTMS1    ;Yes.  Thats all.
  434.     CALL    PRINT
  435.     HLT
  436. ;
  437. ;    STSCOPY initialization
  438. ;
  439. STSERR:                ;Fatal error return
  440.     LHLD    STSTACK        ;Restore stack pointer
  441.     SPHL
  442.     MVI    A,0FFh        ;Set error flag
  443.     RET
  444.  
  445. STSINI:
  446.     LXI    H,0        ;Save stack pointer
  447.     DAD    SP
  448.     SHLD    STSTACK
  449.     PUSH    PSW        ;Save LUN
  450.     MVI    A,0C9h        ;RET
  451.     STA    CBOOT0        ;Don't do URINIT
  452.     STA    CBOOT1        ;Return to STSINI
  453.     STA    PRINT        ;No printouts
  454.     XRA    A        ;NOP the HLT
  455.     STA    STSERR-1
  456.     POP    PSW        ;Restore LUN
  457.     CALL    CBOOT
  458.     CALL    STS
  459.     XRA    A        ;Clear error flag
  460.     RET
  461.  
  462. STSTACK: DS    2        ;STSCOPY stack pointer
  463.  
  464.  
  465. CIOADT:    DB    ADCMD,0,0,0,0,0
  466. ;
  467. ;    # SECTORS PER WARM BOOT
  468. ;
  469. HCCPLN:    EQU    (CBIOS-CCP)/256        ;Hard disk
  470. FCCPLN:    EQU    24+(CBIOS-CCP-24*128)/256    ;8" floppy
  471. MCCPLN:    EQU    14+(CBIOS-CCP-14*128)/256    ;5.25" floppy
  472. ;
  473. ;
  474. ;    Configuration Table
  475. ;
  476. CONTBL:
  477.     IF    LUN0
  478.     DB    0 SHL 5
  479.     DB    B0
  480.     DB    1+NF0+N48M0+N96M0
  481.     DB    NH0*HCCPLN+NF0*FCCPLN+(N48M0+N96M0)*MCCPLN
  482.     DB    LUN0DAT
  483.     DB    LUN0TYPE+TYPEN48*N48M0+TYPEN96*N96M0
  484.     DB    LUN0TFC
  485.     DW    ((LUN0SEC/HSTSPT-2-N48M0-N96M0)*CPMSPT/HSTSIB)
  486.     DB    LUN0NLD
  487.     DW    LUN0SEC
  488.     ENDIF
  489.     IF    LUN1
  490.     DB    1 SHL 5
  491.     DB    B1
  492.     DB    1+NF1+N48M1+N96M1
  493.     DB    NH1*HCCPLN+NF1*FCCPLN+(N48M1+N96M1)*MCCPLN
  494.     DB    LUN1DAT
  495.     DB    LUN1TYPE+TYPEN48*N48M1+TYPEN96*N96M1
  496.     DB    LUN1TFC
  497.     DW    ((LUN1SEC/HSTSPT-2-N48M1-N96M1)*CPMSPT/HSTSIB)
  498.     DB    LUN1NLD
  499.     DW    LUN1SEC
  500.     ENDIF
  501.     IF    LUN2
  502.     DB    2 SHL 5
  503.     DB    B2
  504.     DB    1+NF2+N48M2+N96M2
  505.     DB    NH2*HCCPLN+NF2*FCCPLN+(N48M2+N96M2)*MCCPLN
  506.     DB    LUN2DAT
  507.     DB    LUN2TYPE+TYPEN48*N48M2+TYPEN96*N96M2
  508.     DB    LUN2TFC
  509.     DW    ((LUN2SEC/HSTSPT-2-N48M2-N96M2)*CPMSPT/HSTSIB)
  510.     DB    LUN2NLD
  511.     DW    LUN2SEC
  512.     ENDIF
  513.     IF    LUN3
  514.     DB    3 SHL 5
  515.     DB    B3
  516.     DB    1+NF3+N48M3+N96M3
  517.     DB    NH3*HCCPLN+NF3*FCCPLN+(N48M3+N96M3)*MCCPLN
  518.     DB    LUN3DAT
  519.     DB    LUN3TYPE+TYPEN48*N48M3+TYPEN96*N96M3
  520.     DB    LUN3TFC
  521.     DW    ((LUN3SEC/HSTSPT-2-N48M3-N96M3)*CPMSPT/HSTSIB)
  522.     DB    LUN3NLD
  523.     DW    LUN3SEC
  524.     ENDIF
  525. CONTLN:    EQU    ($-CONTBL)/12
  526.  
  527. ADTMES:    DB    CR,LF,'Assign Drive Type error on logical unit '
  528. ADTLUN:    DB    '0.',0
  529. ADTMS1:    DB    CR,LF,'Cannot continue!',0
  530.  
  531. ;
  532. ;    Variables
  533. ;
  534. CONTYPE: DS    1        ;Current LUN type
  535. CONFS:    DS    1        ;Current track format code
  536. CONTFC:    DS    1        ;Track format code selection
  537. ALLINC:    DS    2        ;Normalized allocation blocks
  538. ALLBKS:    DW    0        ;# allocation blocks - 1
  539. CSVALUE: DW    CSV        ;Current check vector address
  540. OFFVAL:    DB    0        ;Current offset value
  541.     DW    0
  542. OFFINC:    DS    2        ;Current offset increment
  543. ALVINC:    DS    2        ;Logical hard disk allocation
  544.                 ; vector increment
  545. ;
  546.  
  547. ;    Table Pointers
  548. ;
  549. CONDPH:    DW    DPH        ;Address of current DPH entry
  550. CONPB:    DW    DPB        ;Address of next DPB entry
  551. CONTY:    DW    DTYPE        ;Address of current DTYPE entry
  552. CONMSK:    DW    DSKMSK        ;Address of current DSKMSK entry
  553. CONOFF:    DW    DSKOFF        ;Address of current DSKOFF entry
  554. FPYTY:    DW    FPYTYP        ;Address of next floppy type
  555. ;
  556. ;    Current DPH entry
  557. ;
  558. CURDPH:
  559. CONXLT:    DS    2        ;Translate table address
  560.     DW    0,0,0        ;Work area for CP/M
  561.     DW    DIRBUF        ;Directory address
  562. CONDPB:    DS    2        ;DPB address
  563. CONCSV:    DW    0        ;Check vector address
  564. CONALV:    DW    ALV        ;Allocation vector address
  565.  
  566. ; Current DPB entry
  567. ;
  568. CURDPB:    DS    16
  569. ;
  570. ;8" Floppy Type Generation Table
  571. ;Format:
  572. ;    DB    DPB type or 0FFh
  573. ;    DB    DPB model #
  574. ;
  575. ;DPB type bit 0 is # sided, bits 1-2 is sector size (0,1,2,3)
  576. ;
  577. FPYTYP:
  578.     DB    TYPEFPY+0,0    ;Single density, single-sided, FM
  579.     DB    TYPEFPY+1,1    ;Single density, double-sided, FM
  580.     DB    0FFh,0        ;Invalid
  581.     DB    0FFh,0        ;Invalid
  582.     DB    0FFh,0        ;Invalic
  583.     DB    0FFh,0        ;Invalid
  584.     DB    TYPEFPY+2,1    ;Double density, single-sided, MFM
  585.     DB    TYPEFPY+3,1    ;Double density, double-sided, MFM
  586. ;
  587. ;5.25" Floppy
  588. TYPEMIN:  EQU    10000b        ;Mini floppy
  589. ;
  590. ;
  591. MINTYP:
  592.     DB    TYPEMIN+0,3    ;Single density, single-sided, 48 TPI
  593.     DB    TYPEMIN+1,3    ;Single density, double-sided, 48 TPI
  594.     DB    TYPEMIN+0,3    ;Single density, single-sided, 96 TPI
  595.     DB    TYPEMIN+1,3    ;Single density, double-sided, 96 TPI
  596.     DB    TYPEMIN+2,3    ;Double density, single-sided, 48 TPI
  597.     DB    TYPEMIN+3,3    ;Double density, double-sided, 48 TPI
  598.     DB    TYPEMIN+2,3    ;Double density, single-sided, 96 TPI
  599.     DB    TYPEMIN+3,3    ;Double density, double-sided, 96 TPI
  600. ;
  601. ;Prototype DPBs
  602. ;
  603. CONPBT:
  604.     DB    0
  605.     DW    26
  606.     DB    3,7,0
  607.     DW    ((77-2)*26/CPMSIB)-1
  608.     DW    63
  609.     DB    11000000b,00000000b
  610.     DW    16,2
  611.  
  612.     DB    1    ;256 bytes/sector, MFM
  613.     DW    CPMSPT
  614.     DB    4,15,0
  615.     DW    0,127
  616.     DB    11000000b,00000000b
  617.     DW    32,2
  618.  
  619.     DB    2    ;logical hard disk
  620.     DW    CPMSPT
  621.     DB    4,15,0
  622.     DW    0,511
  623.     DB    11111111b,00000000b
  624.     DW    0,2
  625.  
  626.     DB    3    ;5.25" floppy
  627.     DW    CPMSPT
  628.     DB    4,15,0
  629.     DW    0,63
  630.     DB    10000000b,00000000b
  631.     DW    16,3
  632.  
  633. CONPLN:    EQU    ($-CONPBT)/16
  634.  
  635. SIGNON:    DB    CR,LF,LF,'DTC '
  636.