home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / system / linux_bo / netboot.zoo / floboot.asm < prev    next >
Encoding:
Assembly Source File  |  1993-05-06  |  4.7 KB  |  261 lines

  1. ;
  2. ; ideas - snippets of this were lifted from bootsect.s by Linus
  3. ; these consist of - patching the drive parameter table
  4. ;                  - trying to read sectors 18, 15 and 9 to determine
  5. ;                    the number of sectors per track
  6. ; The rest is pretty well mine.
  7. ;
  8. ; Don't be tempted to replace all those ugly [BASE+...] operands.
  9. ; you'll find exe2bin won't like it
  10. ;
  11. ;
  12. BOOT_TEXT     SEGMENT BYTE PUBLIC 'BOOTT'
  13. BOOT_TEXT              ENDS
  14.  
  15. Loaded          segment at 9800h
  16.  
  17.                 assume cs:Loaded
  18.                 assume ds:Loaded
  19.  
  20.                 org 0
  21. JMP_HERE    label far
  22. Loaded          ends
  23.  
  24. BOOT_TEXT     SEGMENT BYTE PUBLIC 'BOOTT'
  25.     ASSUME  CS:BOOT_TEXT
  26.     ASSUME    DS:BOOT_TEXT
  27.  
  28.     org 0h
  29.  
  30. BASE EQU    7c00h
  31.  
  32. go:
  33. ;    mov    dx, BASE + offset BOOT_TEXT:go
  34. ;    sub    dx,200h
  35. ;    mov    cl,4
  36. ;    shr    dx,cl
  37.     mov    dx,cs
  38.  
  39.     mov    ax, 100h
  40.     mov    dx, 6200h
  41.     mov    ss,ax        ; put stack at 100:6200 -> 7200
  42.     mov    sp,dx
  43.  
  44.     xor    ax,ax
  45.     mov    es,ax
  46.  
  47.     lds    si,es:[078h]        ; ds:si is source
  48.  
  49.     mov    es,dx            ; our data segment
  50.  
  51.     mov    di,BASE + offset dt_table        ; es:di is destination
  52.     mov    cx,6            ; copy 12 bytes
  53.     cld
  54.     rep
  55.     movsw
  56.  
  57.     mov    ds,dx
  58.  
  59.     mov    [BASE+dt_sec_trak], 18        ; patch sector count
  60.  
  61.     xor    ax,ax
  62.     mov    es,ax
  63.     mov    bx, BASE + offset dt_table        ; es:di is destination
  64.     mov    es:[078h],bx
  65.     mov    ax,ds
  66.     mov    es:[07ah],ax
  67.  
  68.     xor    ah,ah            ; reset FDC 
  69.     xor    dl,dl
  70.     int     13h    
  71.  
  72.     mov    si, BASE + offset BOOT_TEXT:booting
  73.     call    outs_cs_si
  74.  
  75.     mov    ax,seg Loaded        ; convenient place
  76.     mov    es,ax
  77.     xor    bx,bx
  78.  
  79. ; pinched this bit from linux - simply determine which
  80. ; is the last sector    
  81.  
  82.     xor    dx, dx            ; drive 0, head 0
  83.     mov    cx,18            ; sector 18, track 0
  84.     mov    ax,201h            ; read one sector
  85.     int    13h
  86.     jnc    sectors_known
  87.     mov    cx,15            ; sector 15
  88.     mov    ax,201h            ; read one sector
  89.     int    13h
  90.     jnc    sectors_known
  91.     mov    cx,9
  92.  
  93. sectors_known:
  94.     mov    [BASE+sectors], cx        ; 
  95.     
  96.     ; for (ax = 2, cx = numsects; cx > 0 ; cx--, ax++)
  97.     ;    read sector ax
  98.     ;    es:bx += sector size
  99.  
  100.                     ; going to read 32k
  101.     mov    cx, 32 * 2        ; number of sectors
  102.  
  103.     mov    ax,seg Loaded        ; convenient place
  104.     mov    es,ax
  105.     xor    bx,bx
  106.  
  107.     mov    ax,1            ;  starting sector
  108.                     ; our numbers start at 0, theirs at 1
  109. rd_loop:
  110.     cmp    cx,0
  111.     jle    finito
  112.     push    cx
  113.     push    ax
  114.     
  115.     call    convertsect
  116.                     ; es:bx points to buffer
  117.     mov    ax,0201h
  118.     int    13h
  119.  
  120.     pop    ax
  121.     pop    cx
  122.     jc    bad_read
  123.     
  124.     dec    cx
  125.     inc    ax
  126.     add    bx,512
  127.     jmp    rd_loop
  128.  
  129. finito:
  130. ifdef TESTING
  131.     mov    si, BASE + offset BOOT_TEXT:bootok
  132.     call    outs_cs_si
  133. endif
  134.     call far ptr JMP_HERE
  135.     mov    si, BASE + offset BOOT_TEXT:pank
  136.     call    outs_cs_si
  137.     jmp    bad_exit
  138.  
  139. bad_read:
  140.     mov    si, BASE + offset BOOT_TEXT:diskerror
  141.     call    outs_cs_si
  142. bad_exit:
  143.     xor    ah,ah        ; wait for user press key
  144.     int    16h
  145.                 ; try to boot the system again
  146.     int    19h
  147.  
  148.  
  149. convertsect:
  150.             ; convert absolute sector to track head sector
  151.             ; sector in ax (assume small)
  152.             
  153.     xor    dx,dx        ; assume high word zero
  154.     div     [BASE+sectors]        ; sectors per track
  155.     inc     dl            ; my 486 book says the remainder is in ax!
  156.                     ; remainder is really in dx
  157.     xor    dh,dh
  158.     push    dx        ; keep secno handy
  159.     mov    dx,ax        ; copy remainder
  160.     shr    ax,1        ; divide by number of heads -> track no
  161.     and    dx,1        ; mask all but head number
  162.     xchg    dh,dl        ; HEAD DH
  163.                 ; ax is the track number
  164.                 ; top two bits of track should be
  165.                 ; placed in the sector number -  we ignore
  166.     
  167.     mov    ch, al        ; track no
  168.     pop    ax        ; sector number
  169.     mov    cl,al        ; sector
  170.  
  171.     ret
  172.  
  173. outch:
  174.     mov     ah,0eh
  175.     mov     bx,0007h
  176.     int     10h
  177.  
  178. outs_cs_si:
  179.     mov    al,cs:[si]
  180.     inc    si
  181.     or     al,al    ; end of string
  182.     jnz     outch
  183.     ret
  184.  
  185. diskerror:
  186.     db 0Dh, 0Ah, 'Disk controller error ...', 0
  187.  
  188. booting:
  189.     db 0Dh, 0Ah, 'Loading net boot ...', 0
  190. pank:
  191.     db 0Dh, 0Ah, 'Press any key...', 0
  192. ifdef TESTING
  193. bootok:
  194.     db 0Dh, 0Ah, 'read all, now jumping..', 0
  195. endif
  196.  
  197. dt_table        label    byte
  198. dt_spec1    db    0
  199. dt_spec2    db    0
  200. dt_moffc    db    0
  201. dt_byt_sec    db    0    ; bytes per sector
  202. dt_sec_trak    db    0    ; sectors per track
  203. dt_gap        db    0    ;
  204. dt_dtl        db    0
  205. dt_gap3        db    0
  206. dt_fil_byt    db    0
  207. dt_hd_tim    db    0
  208. dt_most        db    0
  209. dt_maxtrak    db    0
  210. dt_other    db    0
  211.  
  212. sectors        dw    0
  213.  
  214.  
  215. fill:    db (512-(offset BOOT_TEXT:fill-offset BOOT_TEXT:go)-2) dup (0)
  216.  
  217. signature    dw 0AA55h
  218.  
  219.  
  220. BOOT_TEXT              ENDS
  221.  
  222. ifdef TESTING
  223.  
  224. FUNNY_TEXT     SEGMENT BYTE PUBLIC 'BOOTF'
  225.     ASSUME  CS:FUNNY_TEXT
  226.     ASSUME    DS:FUNNY_TEXT
  227.  
  228.     org 0
  229.  
  230.     mov    si, offset xbooted
  231.     call    xouts_cs_si
  232.  
  233.     xor     ah,ah        ; wait for user press key
  234.     int     16h
  235.                 ; try to boot the system again
  236.     int     19h
  237.  
  238.     
  239. xoutch:
  240.     mov     ah,0eh
  241.     mov     bx,0007h
  242.     int     10h
  243.  
  244. xouts_cs_si:
  245.     mov    al,cs:[si]
  246.     inc    si
  247.     or     al,al    ; end of string
  248.     jnz     xoutch
  249.     ret
  250.  
  251. xbooted:
  252.     db 0Dh, 0Ah, 'I booted... press key', 0
  253.  
  254. ;    db 32768 dup (?)
  255.  
  256. FUNNY_TEXT              ENDS
  257. endif
  258.  
  259.     END    go
  260.