home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / BOOTANY1.ZIP / BSTRAP.ASM < prev    next >
Assembly Source File  |  1990-10-29  |  16KB  |  339 lines

  1.         page    61,132
  2.         title   Bstrap - update fixed disk bootstrap
  3.         subttl  Code
  4.         page    +
  5. Code    segment
  6.         assume  cs:Code, ds:Code, es:Code, ss:Code
  7.         org     80h
  8. parmLen db      ?
  9. parm    db      ?
  10.         org     100h
  11.         include bootany.inc
  12. Bstrap  proc    far
  13.         mov     SI,DS                           ; Get data segment
  14.         mov     ES,SI                           ; Make sure the same
  15. ;
  16. ;       Read current bootstrap record
  17. ;
  18.         mov     AX,201h                         ; read 1 sector
  19.         lea     BX,Boot                         ; buffer address
  20.         mov     CX,1                            ; cyl 0, sector 1
  21.         mov     DX,80h                          ; head 0, drive 0
  22.         int     13h                             ; read fixed disk boot
  23.         jnc     ReadOk                          ; Go on if ok
  24.         mov     bx,2                            ; write to stderr
  25.         mov     cx,Err1l                        ; length of message
  26.         lea     dx,Err1                         ; message address
  27.         mov     ah,40h                          ; write to stream
  28.         int     21h                             ; send message
  29.         jmp     Exit                            ; Exit program
  30. ReadOk:
  31. ;
  32. ;       Read in file named as parm (boot program)
  33. ;       First find the program name
  34. ;
  35.         sub     CX,CX                           ; clear register
  36.         sub     SI,SI                           ; clear register
  37.         mov     CL,parmLen                      ; Get length of parm
  38.         cmp     CL,0                            ; Better be there
  39.         jbe     NameError                       ; its not
  40.         lea     DI,parm                         ; get name address
  41.         mov     AL,' '                          ; what we will ignore
  42.         repe scasb
  43.         jcxz    NameError                       ; No parm - write msg
  44.         jmp     NameThere                       ; it is
  45. NameError:
  46.         mov     bx,2                            ; write to stderr
  47.         mov     cx,NameErrl                     ; length of message
  48.         lea     dx,NameErr                      ; message address
  49.         mov     ah,40h                          ; write to stream
  50.         int     21h                             ; send message
  51.         jmp     Exit
  52. ;
  53. ;       Found the name - Open and Read the file
  54. ;
  55. NameThere:
  56.         dec     DI                              ; Point to first byte
  57.         inc     CX                              ; Correct the count
  58.         mov     BX,CX                           ; get bytes left
  59.         mov     [BX+DI],BYTE PTR 0              ; move in terminator
  60.         mov     DX,DI                           ; Get file name start
  61.         sub     AL,AL                           ; Open for read
  62.         mov     AH,3dh                          ; Open function
  63.         int     21h                             ; Call DOS
  64.         jc      FileError
  65.         lea     DX,Boot                         ; buffer address
  66.         mov     CX,PartAddr                     ; maximum boot length
  67.         mov     BX,AX                           ; read from file
  68.         mov     AH,3fh                          ; read from stream
  69.         int     21h                             ; dos service
  70.         jnc     FileOk                          ; continue if file ok
  71. FileError:
  72.         mov     AH,3Eh                          ; Close the file
  73.         int     21h                             ; dos service
  74.         mov     BX,2                            ; write to stderr
  75.         mov     CX,Err2l                        ; length of message
  76.         lea     DX,Err2                         ; message address
  77.         mov     AH,40h                          ; write to stream
  78.         int     21h                             ; send message
  79.         jmp     Exit                            ; Exit program
  80. ;
  81. ;       The new boot program is not in our "in-memory" copy of the
  82. ;       boot sector
  83. ;
  84. FileOk:
  85. ;
  86. ;       Close the file
  87. ;
  88.         mov     AH,3Eh                          ; Close the file
  89.         int     21h                             ; dos service
  90. ;
  91. ;       Update the boot sector with User Data
  92. ;       Put out first message
  93. ;
  94.         mov     bx,2                            ; write to stderr
  95.         mov     cx,Msg1l                        ; length of message
  96.         lea     dx,Msg1                         ; message address
  97.         mov     ah,40h                          ; write to stream
  98.         int     21h                             ; send message
  99.  
  100.         mov     CX,max_partitions               ; get loop count
  101.  
  102. PartLoop:
  103. ;
  104. ;       Find out what partition this Function Key will be for
  105. ;
  106.         mov     Index,CX                        ; Save index
  107.         sub     CL,max_partitions+1             ; get negative index
  108.         neg     CL                              ; turn positive
  109.         add     CL,Numeric                      ; make displayable
  110.         mov     Q1FKey,CL                       ; move into message
  111.         mov     Q2FKey,CL                       ; move into message
  112.         mov     Q3FKey,CL                       ; move into message
  113.         mov     AL,max_partitions               ; get max value
  114.         add     AL,Numeric                      ; make displayable
  115.         mov     Q1Max,AL                        ; move into message
  116.         mov     BX,2                            ; write to stderr
  117.         mov     CX,Q1l                          ; length of message
  118.         lea     DX,Q1                           ; message address
  119.         mov     AH,40h                          ; write to stream
  120.         int     21h                             ; send message
  121.         call    GetChar                         ; Get the number
  122.         cmp     AL,'0'                          ; See if '0'
  123.         jne     NoExit                          ; If not continue
  124.         jmp     TestNumLock                     ; Exit loop
  125. NoExit:
  126.         cmp     AL,'1'                          ; See if valid value
  127.         jl      PartError                       ; No - reprompt
  128.         cmp     AL,Numeric+max_partitions       ; Check max value
  129.         ja      PartError                       ; Too big - reprompt
  130.         mov     Q2Pnum,AL                       ; Save part number
  131.         mov     Err3P,AL                        ; Save part number
  132.         sub     AL,Numeric+1                    ; Turn into index
  133.         push    AX                              ; Save for later
  134.         mov     AH,SIZE PartData                ; Get entry size
  135.         mul     AH                              ; Get offset into table
  136.         mov     Data,AX                         ; Get data address
  137.         mov     BX,AX                           ; Get data address
  138.         pop     AX                              ; Restore value
  139.         mov     AH,SIZE PartitionEntry          ; Get entry size
  140.         mul     AH                              ; Get offset into table
  141.         mov     Entry,AX                        ; Get entry address
  142.         cmp     part.partition[BX],0            ; Already in use?
  143.         je      BootTest                        ; No - use it
  144.         mov     BX,2                            ; write to stderr
  145.         mov     CX,Err3l                        ; length of message
  146.         lea     DX,Err3                         ; message address
  147.         mov     AH,40h                          ; write to stream
  148.         int     21h                             ; send message
  149. PartError:
  150.         mov     CX,Index                        ; restore index
  151.         jmp     Partloop
  152.  
  153. BootTest:
  154. ;       Check to see if the partition is marked bootable -
  155. ;       If not, see if it should be made bootable
  156. ;
  157.         mov     BX,Entry                        ; Get Entry address
  158.         cmp     partitionTable.BootIndicator[BX],0 ; Can partition boot
  159.         jne     PartBoot                        ; Yes - use it
  160.         push    AX                              ; Save for later
  161.         mov     BX,2                            ; write to stderr
  162.         mov     CX,Q2l                          ; length of message
  163.         lea     DX,Q2                           ; message address
  164.         mov     AH,40h                          ; write to stream
  165.         int     21h                             ; send message
  166.         call    GetChar                         ; Get the number
  167.         pop     CX                              ; Restore value
  168.         and     AL,0DFh                         ; Convert to upper case
  169.         cmp     AL,'Y'                          ; See if 'Y'
  170.         je      MakeBoot                        ;  Make it bootable
  171.         cmp     AL,'N'                          ; See if 'N'
  172.         jne     BootTest                        ;  Bad reply
  173.         jmp     PartError                       ;  Don't make it boot
  174. MakeBoot:
  175.         mov     partitionTable.BootIndicator[BX],80h ; Turn on boot flag
  176.         mov     AX,CX                           ; Restore part #
  177.  
  178. PartBoot:
  179.         mov     BX,Data                         ; Get table offset
  180.         mov     AL,Q2Pnum                       ; Get part number
  181.         sub     AL,Numeric                      ; Convert to binary
  182.         mov     part.partition[BX],AL           ; Save partition #
  183.  
  184. PartBootLoop:
  185. ;
  186. ;       Get partitition description from user
  187. ;
  188.         mov     BX,2                            ; write to stderr
  189.         mov     CX,Q3l                          ; length of message
  190.         lea     DX,Q3                           ; message address
  191.         mov     AH,40h                          ; write to stream
  192.         int     21h                             ; send message
  193.  
  194.         mov     CX,part_text_len                ; set to text length
  195.         cld                                     ; copy forward
  196.         lea     DI,part.text                    ; Get base
  197.         add     DI,Data                         ; Add entry offset
  198.         mov     AL,' '                          ; Get data start
  199.         rep stosb                               ; Copy the data
  200.         lea     DX,TextBuffer                   ; get input area addr
  201.         mov     AH,10                           ; Buffered Input Code
  202.         int     21h                             ; Get data
  203.         sub     CX,CX                           ; Clear register
  204.         mov     CL,TextBuffer+1                 ; Get length entered
  205.         jcxz    PartBootLoop                    ; Reprompt if null
  206.         cld                                     ; copy forward
  207.         lea     DI,part.text                    ; Get base
  208.         add     DI,Data                         ; Add entry offset
  209.         lea     SI,TextBuffer+2                 ; Get data start
  210.         rep movsb                               ; Copy the data
  211.         mov     CX,Index                        ; Restore loop index
  212.         loop    NextPart                        ; Set up next partition
  213.         jmp     TestNumLock
  214. NextPart:
  215.         jmp     PartLoop
  216. ;
  217. ;       See if Num Lock should be turned off
  218. ;
  219. TestNumLock:
  220.         mov     bx,2                            ; write to stderr
  221.         mov     cx,Q4l                          ; length of message
  222.         lea     dx,Q4                           ; message address
  223.         mov     ah,40h                          ; write to stream
  224.         int     21h                             ; send message
  225.         call    GetChar                         ; Get the number
  226.         and     AL,0DFh                         ; Convert to upper case
  227.         cmp     AL,'Y'                          ; See if 'Y'
  228.         je      ResetTable                      ;  Off is default
  229.         cmp     AL,'N'                          ; See if 'N'
  230.         jne     TestNumLock                     ;  Bad reply
  231.         mov     AL,NumLockOn                    ; Get NumLock on mask
  232.         mov     bootOpts.numlockMask,AL         ; Reset Mask
  233. ;
  234. ;       Swap the BootIndicator with the System Id to insure that there
  235. ;       will be only one bootable partition at a time.
  236. ;
  237. ResetTable:
  238.         mov     CX,max_partitions               ; Get number of parts
  239.         sub     BX,BX                           ; Clear index
  240. ResetTableLoop:
  241.         mov     AL,partitionTable.BootIndicator[BX] ; get indicator
  242.         cmp     AL,80h                          ; bootable partition?
  243.         jne     PartOk                          ; don't mess with it
  244.         mov     AL,partitionTable.SystemId[BX]  ; Get System ID
  245.         mov     partitionTable.BootIndicator[BX],AL ; Save here
  246.         mov     partitionTable.SystemId[BX],80h ; Make System ID inv.
  247. PartOk:
  248.         add     BX,SIZE PartitionEntry          ; Next Entry
  249.         loop    ResetTableLoop
  250. ;
  251. ;       Rewrite the boot record
  252. ;
  253.         lea     BX,Boot                         ; buffer address
  254.         mov     CX,1                            ; cyl 0, sector 1
  255.         mov     DX,80h                          ; head 0, drive 0
  256.         mov     AX,301h                         ; write 1 sector
  257.         int     13h                             ; update boot record
  258.         jc      Exit                            ; exit if error
  259. ;
  260. ;       Write out message
  261. ;
  262.         mov     BX,2                            ; write to stderr
  263.         mov     CX,Msgl                         ; length of message
  264.         lea     DX,Msg                          ; message address
  265.         mov     AH,40h                          ; write to stream
  266.         int     21h                             ; send message
  267. Exit:
  268.         int     20h                             ; exit program
  269.  
  270. TextBuffer db   16,0
  271.         db      16 dup(0)
  272.  
  273. Msg1    db      13,10,'<CTRL><BREAK> may be used to end the install '
  274.         db      'at any time',10
  275. Msg1l   equ     $-Msg1
  276.  
  277. Q1      db      13,10,'What partition should be assigned to F'
  278. Q1Fkey  db      '#? (1-'
  279. Q1Max   db      '#, 0 to end) '
  280. Q1l     equ     $-Q1
  281.  
  282. Q2      db      13,10,'Partition '
  283. Q2Pnum  db      '# is not bootable.',13,10
  284.         db      '      Reply Y to make it bootable, '
  285.         db      'N to assign F'
  286. Q2Fkey  db      '# to a new partition. '
  287. Q2l     equ     $-Q2
  288.  
  289. Q3      db      13,10,'Enter partition description to be assigned to F'
  290. Q3Fkey  db      '# (15 chars max) '
  291. Q3l     equ     $-Q3
  292.  
  293. Q4      db      13,10,'Do you want Num Lock turned off at boot? '
  294.         db      '(Y or N) '
  295. Q4l     equ     $-Q4
  296.  
  297. Err1    db      13,10,'Error Reading Boot Sector'
  298. Err1l   equ     $-Err1
  299.  
  300. NameErr db      13,10,'Invalid file name for new boot program'
  301. NameErrl equ    $-NameErr
  302.  
  303. Err2    db      13,10,'Error Reading New Boot Program'
  304. Err2l   equ     $-Err2
  305.  
  306. Err3    db      13,10,'Partition '
  307. Err3P   db      '# is already defined'
  308. Err3l   equ     $-Err3
  309.  
  310. msg     db      13,10,'Boot record updated.',13,10
  311. msgl    equ     $-msg
  312.  
  313. Index   dw     0
  314. Entry   dw     0
  315. Data    dw     0
  316.  
  317. Boot           db      DataAddr dup(?)
  318. part           PartData max_partitions dup(<>)
  319. bootOpts       BootData <>
  320. partitionTable PartitionEntry 4 dup(<>)
  321. Validation     db      2 dup(0)
  322.  
  323. Bstrap  endp
  324.  
  325. GetChar proc    near
  326.         mov     AH,1                   ; Get keyboard input
  327.         int     21h
  328.         cmp     AL,0
  329.         jne     GetCharRet
  330.         mov     AH,1                   ; Get extended code
  331.         int     21h
  332.         sub     AL,AL                  ; show bad, not ASCII
  333. GetCharRet:
  334.         ret
  335. GetChar endp
  336.  
  337. Code    ends
  338.         end     Bstrap
  339.