home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / BOOTANY1.ZIP / BOOTANY.ASM < prev    next >
Assembly Source File  |  1990-12-28  |  11KB  |  238 lines

  1. F1_scancode     equ     59
  2. reply_interval  equ     5               ; wait up to 5 seconds for reply
  3.  
  4.                 include bootany.inc
  5.  
  6. code            segment
  7.  
  8.  
  9.                 assume  cs:Code, ds:Code, es:Code, ss:Code
  10.                 org     0
  11.  
  12. bootany         proc    near
  13. ;
  14. ;               Setup the stack
  15. ;
  16.                 mov     AX,CS           ; Get current segment
  17.                 mov     DS,AX           ; Set DS temporarily
  18.                 cli                     ; disable interrupts
  19.                 mov     SS,AX           ; set stack segment
  20.                 mov     SP,NewBootLocation ; initialize stack pointer
  21.                 sti                     ; reenable interrupts
  22. ;
  23. ;               DOS loads this pgm at 0000:7C00. Any boot routine
  24. ;               we call also expects to execute there so the first
  25. ;               exercise is to move this code somewhere else.
  26. ;
  27.                 mov     CX,512          ; bytes to move
  28.                 mov     SI,BootLocation ; Get boot address
  29.                 les     DI,DWORD PTR SecBoot[SI] ; Load ES=07A0,DI=0000
  30.                 rep     movsb           ; Copy to new location
  31.  
  32.                 lea     SI,down+NewBootLocation ; address relocated e.p.
  33.                 jmp     SI
  34.  
  35. down            equ     $
  36. ;
  37. ;               Turn off Numlock (Insure DS is still 0)
  38. ;
  39.                 sub     AX,AX          ; Clear register
  40.                 mov     DS,AX          ; Set Data segment
  41.                 mov     AL,DS:[KeyboardFlags] ; Get keyboard flags
  42.                 and     AL,bootOpts.numlockMask[DI] ; Mask numlock flag
  43.                 mov     DS:[KeyboardFlags],AL ; Save keyboard flags
  44. ;
  45. ;               Set up data segment
  46. ;
  47.                 mov     AX,ES           ; Get current segment
  48.                 mov     DS,AX           ; Set data segment
  49. prompt:
  50. ;
  51. ;               Display the menu
  52. ;
  53.                 call    Clear           ; clear the screen
  54.                 mov     CX,max_partitions ; set to max partitions
  55.                 xor     BX,BX           ; set base offset into table
  56.                 mov     SI,-1           ; set index
  57.                 mov     DL,Numeric      ; get first numeric value
  58. promptloop:
  59.                 inc     DL              ; Increment Func Key number
  60.                 cmp     part.partition[BX],0 ; any entry?
  61.                 je      finishPrompt    ; No skip rest
  62.  
  63.                 mov     key,DL          ;  save in message
  64.                 lea     SI,FkeyMsg      ; get msg addr
  65.                 call    Send
  66.  
  67.                 lea     SI,part.text[BX] ; get data addr
  68.                 call    Send
  69.  
  70.                 add     BX,SIZE PartData ; next entry address
  71.                 loop    promptloop
  72. finishPrompt:
  73.                 inc     DL              ; get Func key number
  74.                 mov     basicKey,DL     ; save in message
  75.                 lea     SI,rombasic     ; get msg address
  76.                 call    Send
  77.  
  78.                 sub     AH,AH           ; GetTickCount
  79.                 int     1ah             ; BiosTimerService
  80.                 add     DX,182*reply_interval/10 ; Set timeout time
  81.                 mov     BX,DX           ; Save the timeout value
  82. ;
  83. ;               Get the reply
  84. ;
  85. reply:
  86.                 mov     AH,1            ; keyboard status
  87.                 int     16h             ; keybd bios service
  88.                 jnz     read_scancode   ; jump if reply
  89.                 sub     AH,AH           ; GetTickCount
  90.                 int     1ah             ; BiosTimerService
  91.                 cmp     AL,1            ; check for passing midnight
  92.                 je      prompt          ; Reprompt if we did
  93.                 cmp     DX,BX           ; check for timeout
  94.                 jb      reply           ; wait for scancode
  95.                 mov     AL,default      ; prior system id
  96.                 cmp     AL,'?'          ; validate key
  97.                 je      error           ; no default
  98.                 jmp     system          ; boot default system
  99. read_scancode:
  100.                 sub     AH,AH           ; read keyboard
  101.                 int     16h             ; keybd bios service
  102.                 sub     AH,F1_scancode-1 ; Turn into index
  103.                 jbe     error           ; Invalid code check
  104.                 mov     AL,AH           ; Copy to AL
  105.                 add     AL,Numeric      ; Make numeric
  106.                 cmp     AL,basicKey     ; max Function key
  107.                 ja      error           ; branch if bad response
  108.                 jne     system          ; if not basic, branch
  109.                 int     18h             ; else invoke rom basic
  110. error:
  111.                 jmp     prompt          ; reissue prompt
  112. ;
  113. ;               A valid function key was depressed (or defaulted)
  114. ;               Attempt to boot the corresponding partition.
  115. ;
  116. system:
  117.                 mov     key,AL          ; save function key number
  118.                 dec     AL              ; subtract for offset
  119.                 sub     AL,Numeric      ; convert to binary
  120.                 mov     AH,SIZE PartData ; Get entry size
  121.                 mul     AH              ; Get offset
  122.                 mov     BX,AX           ; move to usable register
  123.                 mov     AL,part.partition[BX] ; get partition number
  124.                 dec     AL              ; subtract for offset
  125.                 mov     BL,SIZE PartitionEntry ; Get entry size
  126.                 mul     BL              ; Get offset
  127.                 mov     BX,AX           ; move to usable register
  128. ;
  129. ;               Only boot bootable partitions.
  130. ;
  131. check:
  132.                 cmp     partitionTable.BootIndicator[BX],0
  133.                                         ; bootable partition?
  134.                 je      error           ; No - display menu again
  135. ;
  136. ;               Read in and validate the partition's boot sector.
  137. ;
  138. select:
  139.                 mov     DH,partitionTable.BeginHead[BX]
  140.                                         ; head from partition table
  141.                 mov     DL,80h          ; drive 0
  142.                 mov     CL,partitionTable.BeginSector[BX]
  143.                                         ; sector from table
  144.                 mov     CH,partitionTable.BeginCyl[BX]
  145.                                         ; cylinder from partition table
  146.                 push    BX              ; Save index
  147.                 les     BX,DWORD PTR PrimBoot ; address primary boot loc
  148.                 mov     AX,201h         ; function, # of sectors
  149.                 int     13h             ; read system boot record
  150.                 pop     BX              ; Restore index
  151.                 jc      error           ; exit if error
  152.                 cmp     word ptr ES:510,0aa55h ; test signature
  153.                 jne     error           ; reprompt if invalid
  154. ;
  155. ;               Hide the previously booted partition and unhide the
  156. ;               partition to be booted.
  157. ;
  158.                 mov     AL,key          ; get depressed key number
  159.                 mov     DL,default      ; get last booted
  160.                 mov     default,AL      ; save Function key number
  161.                 mov     DI,defaultPart  ; Get default index
  162.                 mov     defaultPart,BX  ; Save new index
  163.                 cmp     DL,'?'          ; any default?
  164.                 je      SetCurrent      ; no - Only set up current
  165.                 cmp     AL,DL           ; current = default?
  166.                 je      EndBoot         ; yes - skip reset
  167.                 mov     AL,partitionTable.SystemId[DI]
  168.                                         ; Get partition type
  169.                 mov     partitionTable.BootIndicator[DI],AL
  170.                                         ; Save as boot indicator
  171.                 mov     partitionTable.SystemId[DI],80h
  172.                                         ; Booted part. won't see it now
  173. SetCurrent:
  174.                 mov     AL,partitionTable.BootIndicator[BX]
  175.                                         ; Get partition type
  176.                 mov     partitionTable.SystemId[BX],AL
  177.                                         ; Put it where it belongs
  178.                 mov     partitionTable.BootIndicator[BX],80h
  179.                                         ; Show partition is bootable
  180. ;
  181. ;               Clear the screen, update the boot sector with new
  182. ;               values, and give control to the partitions boot program
  183. ;
  184. EndBoot:
  185.                 call    Clear           ; clear the screen
  186.                 mov     AX,301h         ; write sector
  187.                 les     BX,DWORD PTR SecBoot ; buffer address
  188.                 mov     CX,1            ; cylinder 0, sector 1
  189.                 mov     DX,80h          ; head 0, drive 0
  190.                 int     13h             ; replace boot record
  191.                 cli                     ; disable interrupts
  192.                 mov     SI,BootLocation ; get address of area read
  193.                 jmp     SI              ; enter second level boot
  194. Clear:
  195.                 mov     AH,15           ; return current video mode
  196.                 int     10h             ; bios service
  197.                 sub     AH,AH           ; set mode
  198.                 int     10h             ; reset video mode
  199.                 ret
  200. Send:
  201.                 cld                     ; reset direction flag
  202.                 lodsb                   ; load argument from string
  203.                 test    AL,80h          ; test for end of string
  204.                 pushf                   ; save flags
  205.                 and     AL,7fh          ; insure valid character
  206.                 mov     AH,14           ; write tty
  207.                 int     10h             ; bios video service
  208.                 popf                    ; restore flags
  209.                 jz      Send            ; do until end of string
  210.                 ret                     ; return to caller
  211.  
  212. SecBoot         dw      0,NewBootSeg    ; ES=7A0, BX=0
  213. PrimBoot        dw      0,BootSeg       ; ES=7C0, BX=0
  214. FkeyMsg         db      13,10,'F'
  215. key             db      'X . . .',+0A0h
  216. rombasic        db      13,10,'F'
  217. basicKey        db      'X . . . ROM BASIC',13,10,10
  218.                 db      'Default: F'
  219. default         db      '?',+0A0h
  220. defaultPart     dw      -1
  221. used            equ     $ - bootany
  222. clearAmt        equ     DataAddr - used ; Assembly error if code too big
  223.  
  224.     IF clearAmt
  225.                 db      clearAmt dup(0) ; clear rest of record
  226.     ENDIF
  227.  
  228. part            PartData max_partitions dup(<>)
  229.  
  230. bootOpts        BootData <>
  231.  
  232. partitionTable  PartitionEntry 4 dup(<>)
  233.  
  234. bootany         endp
  235. code            ends
  236.  
  237.                 end
  238.