home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / KERNELS / LODLIN15.ZIP / LOADLIN / BOOTSECT.ASM < prev    next >
Encoding:
Assembly Source File  |  1994-05-02  |  5.8 KB  |  199 lines

  1. ;
  2. ;       bootsect.s              Copyright (C) 1991, 1992 Linus Torvalds
  3. ;       cut and modified by     Alessandro Rubini for linux.exe
  4. ;                                 (rubini@ipvvis.unipv.it)
  5. ;       modified and converted to TASM by
  6. ;                               Hans Lermen for LOADLIN
  7. ;                                 (lermen@elserv.ffm.fgan.de)
  8.  
  9. BOOTSEG       = 07C0h            ; original address of boot-sector
  10.  
  11. VALID_FLAG    = (512-2-2)
  12. VERSION_FLAG  = ((4*512)-2-16-2)
  13. VERSION_MAGIC = 0A5A5h
  14. INT15RESULT   = ((4*512)-4-16-2)
  15.  
  16. code    segment para USE16
  17.         assume  cs:code,ds:nothing
  18.         org     0 ; NOTE: must really be 0
  19.  
  20. _main:                         ;
  21.         db      0eah           ; no way switch off optimization of TASM
  22.         dw      go,BOOTSEG     ; this is: JMP FAR PTR GO (jmpi go,BOOTSEG)
  23. go:
  24.         mov     bx,cs
  25.         mov     es,bx
  26.         mov     dx,4000h-12
  27.         mov     ss,bx           ; put stack at cs:0x4000-12.
  28.         mov     sp,dx
  29.                                 ; make a snapshot of all desired data
  30.         cld
  31.         cli                     ; keep the shop closed
  32.         xor     si,si
  33.         mov     ds,si
  34.         mov     di,512          ; destination just behind us
  35.         mov     cx,((3*512)-16-2)/2  ; 3 sectors - (16+2) bytes
  36.         rep movsw               ; intvector + bios-data
  37.         mov     si,0FFFFh
  38.         mov     ds,si
  39.         xor     si,si
  40.         mov     cx,8
  41.         rep movsw               ; top 16 bytes of BIOS-ROM
  42.         in      al,21h
  43.         stosb                   ; master-PIC-IMR
  44.         in      al,0a1h
  45.         stosb                   ; slave-PIC-IMR
  46.         mov     si,9FC0h
  47.         mov     ds,si
  48.         xor     si,si
  49.         mov     cx,2*(512/2)-1  ; 2 sectors
  50.         rep movsw               ; bios-scratch-RAM
  51.         sti
  52.  
  53.         mov     ds,bx           ; DS=CS
  54.         mov     word ptr ds:[VALID_FLAG],1 ; set the valid_flag
  55.         mov     ah,88h
  56.         int     15h
  57.         mov     word ptr ds:[INT15RESULT],ax
  58.         mov     word ptr ds:[VERSION_FLAG],VERSION_MAGIC
  59.  
  60.         xor     ah,ah                   ; reset FDC
  61.         xor     dl,dl
  62.         int     13h
  63.  
  64. ; save the bootsect an the snapshot (6 sectors)
  65.  
  66. save_snapshot:
  67.         xor     bx,bx                   ; address = ES:0
  68.         xor     dx, dx                  ; drive 0, head 0
  69.         mov     cx,0001h                ; sector 1, track 0
  70.         mov     ax,0306h                ; service 3 (write), 6 sectors
  71.                                         ; (assume all on head 0, track 0)
  72.         int     13h                     ; write it
  73.         jnc     ok_print_message        ; ok - continue
  74.  
  75.         push    ax                      ; dump error code
  76.         call    print_nl
  77.         mov     bp, sp
  78.         call    print_hex
  79.         pop     ax
  80.  
  81.         xor     dl, dl                  ; reset FDC
  82.         xor     ah, ah
  83.         int     13h
  84.         jmp     save_snapshot
  85.  
  86. ok_print_message:                       ; Print some inane message
  87.  
  88.         push    cs
  89.         pop     es
  90.         mov     ah,3                    ; read cursor pos
  91.         xor     bh,bh
  92.         int     10h
  93.  
  94.         mov     cx,msg1_end-msg1        ; char count
  95.         mov     bx,7                    ; page 0, attribute 7 (normal)
  96.         mov     bp,offset msg1
  97.         mov     ax,1301h                ; write string, move cursor
  98.         int     10h
  99.  
  100. ; ok, we've written the message, now hang...
  101.  
  102. hang:   jmp     hang
  103.  
  104.  
  105. comment /*
  106.  *      print_all is for debugging purposes.
  107.  *      It will print out all of the registers.  The assumption is that this is
  108.  *      called from a routine, with a stack frame like
  109.  *      dx
  110.  *      cx
  111.  *      bx
  112.  *      ax
  113.  *      error
  114.  *      ret <- sp
  115.  *
  116. */
  117.  
  118. print_all:
  119.         mov     cx, 5           ; error code + 4 registers
  120.         mov     bp, sp
  121.  
  122. print_loop:
  123.         push    cx              ; save count left
  124.         call    print_nl        ; nl for readability
  125.  
  126.         cmp     cl, 5
  127.         jae     no_reg          ; see if register name is needed
  128.  
  129.         mov     ax, 0e05h + 'A' - 1
  130.         sub     al, cl
  131.         int     10h
  132.  
  133.         mov     al, 'X'
  134.         int     10h
  135.  
  136.         mov     al, ':'
  137.         int     10h
  138.  
  139. no_reg:
  140.         add     bp, 2           ; next register
  141.         call    print_hex       ; print it
  142.         pop     cx
  143.         loop    print_loop
  144.         ret
  145.  
  146. print_nl:
  147.         mov     ax, 0e0dh       ; CR
  148.         int     10h
  149.         mov     al, 0ah         ; LF
  150.         int     10h
  151.         ret
  152.  
  153. comment /*
  154.  *      print_hex is for debugging purposes, and prints the word
  155.  *      pointed to by ss:bp in hexadecmial.
  156. */
  157.  
  158. print_hex:
  159.         mov     cx, 4           ; 4 hex digits
  160.         mov     dx, [bp]        ; load word into dx
  161. print_digit:
  162.         rol     dx, 4           ; rotate so that lowest 4 bits are used
  163.         mov     ah, 0eh
  164.         mov     al, dl          ; mask off so we have only next nibble
  165.         and     al, 0fh
  166.         add     al, '0'         ; convert to 0-based digit
  167.         cmp     al, '9'         ; check for overflow
  168.         jbe     good_digit
  169.         add     al, 'A' - '0' - 10
  170.  
  171. good_digit:
  172.         int     10h
  173.         loop    print_digit
  174.         ret
  175.  
  176.  
  177. comment /*
  178.  * This procedure turns off the floppy drive motor, so that we
  179.  * don't have to worry about it later.
  180.  */
  181. kill_motor:
  182.         push    dx
  183.         mov     dx,03f2h
  184.         xor     al, al
  185.         out     dx,al
  186.         pop     dx
  187.         ret
  188.  
  189.  
  190. msg1    label   byte
  191.         db      13,10
  192.         db      'Interrupt table and BIOS-data saved on floppy',13,10
  193.         db      'Open the floppy door and reboot from your hard drive,',13,10
  194.         db      'then run REALBIOS again (step 2)',13,10
  195. msg1_end label  byte
  196.  
  197. code    ends
  198.         end     _main
  199.