home *** CD-ROM | disk | FTP | other *** search
/ Boot Disc 15 / boot-disc-1997-11.iso / Debian / Tools / LODLIN16.ZIP / LODLIN16 / SRC / LOADLINI.ASM < prev    next >
Assembly Source File  |  1996-04-28  |  28KB  |  1,077 lines

  1. ;   >>> this is file LOADLINI.ASM
  2. ;============================================================================
  3. ;   LOADLIN v1.6 (C) 1994..1996 Hans Lermen (lermen@elserv.ffm.fgan.de)
  4. ;
  5. ;   This program is free software; you can redistribute it and/or modify
  6. ;   it under the terms of the GNU General Public License as published by
  7. ;   the Free Software Foundation; either version 2 of the License, or
  8. ;   (at your option) any later version.
  9. ;
  10. ;   This program is distributed in the hope that it will be useful,
  11. ;   but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. ;   GNU General Public License for more details.
  14. ;
  15. ;   You should have received a copy of the GNU General Public License
  16. ;   along with this program; if not, write to the Free Software
  17. ;   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. ;
  19. ;----------------------------------------------------------------------------
  20. ;   Comments and bug reports are welcome and may be sent to:
  21. ;   E-Mail:    lermen@elserv.ffm.fgan.de
  22. ;   SnailMail: Hans Lermen
  23. ;              Am Muehlenweg 38
  24. ;              D53424 REMAGEN-Unkelbach
  25. ;              GERMANY
  26. ;
  27. ;============================================================================
  28.  
  29. relocate_setup_code proc near
  30. ; NOTE: This routine has to be updated whenever a new access to
  31. ;       High_seg or High_addr is inserted in the code !
  32. ;       It relocates those addresses, if the setup code is
  33. ;       not loaded at 9000h
  34. ;
  35.          push_  eax,bx
  36.          mov    have_relocated_setup,1
  37.                 ; these can simply overwriten
  38.          mov    ax,High_seg
  39.          mov    reloc_hseg_1,ax
  40.          mov    reloc_hseg_2,ax
  41.  
  42. @@relocd macro  desc
  43.          lea    bx,desc
  44.          call   relocate_descriptor
  45.          endm
  46.                 ; these descriptors have to get added the displacement
  47.          @@relocd gdt_code
  48.          @@relocd gdt_data
  49.          @@relocd gdt_ldt
  50.          @@relocd gdt_tss
  51.  
  52.                 ; these DWORDS have to get added the displacement
  53.          sub    ax,High_seg_
  54.          movsx  eax,ax
  55.          shl    eax,4
  56.          add    our_CR3,eax
  57.          add    our_GDTRptr,eax
  58.          add    our_IDTRptr,eax
  59.          add    laddr_GDT,eax
  60.          add    laddr_IDT,eax
  61.          add    pagedir_template,eax
  62.          call   preset_pagedir_from_template
  63.  
  64.          pop_   eax,bx
  65.          ret
  66. relocate_setup_code endp
  67.  
  68.  
  69. relocate_descriptor proc near
  70. ; input:
  71. ;   AX  =  new 'High_seg' frame
  72. ;   BX  =  offset of descriptor
  73. ;          bases address of descriptor must be relative to 'High_seg_'
  74. ; outpout:
  75. ;   all registers preserved, descriptor bases updated
  76.          push_  ecx,eax
  77.          mov    ch,[bx].base24
  78.          mov    cl,[bx].base16
  79.          shl    ecx,16
  80.          mov    cx,[bx].base0
  81.          sub    ax,High_seg_
  82.          movsx  eax,ax
  83.          shl    eax,4
  84.          add    eax,ecx
  85.          mov    [bx].base0,ax
  86.          shr    eax,16
  87.          mov    [bx].base16,al
  88.          mov    [bx].base24,ah
  89.          pop_   ecx,eax
  90.          ret
  91. relocate_descriptor endp
  92.  
  93.  
  94. read_comline_from_file proc near
  95. ;;        mov      ax,DOS_OPEN_FILE shl 8
  96. ;;        lea      dx,image_name+1
  97. ;;        DosInt
  98.         push     fs
  99.         call     @@open
  100.         jnc      @@isopen
  101. @@err:
  102.         lea      dx,err_comfile_tx
  103.         call     print
  104.         mov      word ptr comline-1,0
  105.         jmp      @@ex
  106. @@ioerr:
  107. ;;        DosCall  DOS_CLOSE_FILE
  108.         call     @@close
  109.         jmp      @@err
  110. @@isopen:
  111.         mov      bx,ax
  112.         cld
  113.         lea      di,comline+1
  114. @@loop:
  115.         mov      dx,di
  116.         mov      cx,1
  117. ;;        DosCall  DOS_READ_FROM_HANDLE
  118.         call     @@read
  119.         jc       @@ioerr
  120.         cmp      ax,1
  121.         jne      @@eof
  122.         mov      al,byte ptr [di]
  123.         cmp      al,13
  124.         je       @@loop
  125.         cmp      al,'#'
  126.         je       @@skipeol
  127. @@skipcontinue:
  128.         inc      di
  129.         cmp      di, offset comline_end-1
  130.         jnb      @@eof
  131.         cmp      al,' '
  132.         ja       @@loop
  133.         cmp      di,offset comline+2
  134.         jna      @@1
  135.         cmp      byte ptr [di-2],' '  ; ignore multiple spaces
  136.         jne      @@1
  137.         dec      di
  138.         jmp      @@loop
  139. @@1:
  140.         mov      byte ptr [di-1],' '
  141.         jmp      @@loop
  142. @@eof:
  143.         mov      byte ptr [di],0
  144.         mov      ax,di
  145.         sub      ax,offset comline+1
  146.         xchg     al,ah
  147.         mov      word ptr comline-1,ax
  148. ;;        DosCall  DOS_CLOSE_FILE
  149.         call     @@close
  150.         jmp      @@ex
  151. @@skipeol:
  152.         mov      dx,di
  153.         mov      cx,1
  154. ;;        DosCall  DOS_READ_FROM_HANDLE
  155.         call     @@read
  156.         jc       @@ioerr
  157.         cmp      ax,1
  158.         jne      @@eof
  159.         cmp      byte ptr [di],10
  160.         jne      @@skipeol
  161.         jmp      @@skipcontinue
  162.  
  163. @@ex:
  164.         pop      fs
  165.         ret
  166.  
  167. ; -----------
  168.  
  169. @@virtual db     0
  170.  
  171. @@open:                    ; virtual open routine
  172.         cmp      dword ptr image_name,'ol@@'
  173.         jne      @@open_d
  174.         cmp      dword ptr image_name+4,'ilda'
  175.         je      @@open_v
  176. @@open_d:
  177.         mov      @@virtual,0
  178.         lea      dx,image_name+1
  179.         mov      ax,DOS_OPEN_FILE shl 8
  180.         DosInt
  181.         ret
  182. @@open_v:
  183.         mov      @@virtual,1
  184.         mov      ax,High_Seg
  185.         cmp      dword ptr image_name+4+4,'@@xn'
  186.         jne      @@open_vhex
  187.         mov      fs,ax
  188.         lea      ax,params_from_loadlinX
  189.         clc
  190.         ret
  191. @@open_vhex:
  192.         push     si
  193.         lea      si,image_name+4+2
  194.         mov      word ptr [si],'x0'
  195.         call     value_of
  196.         mov      fs,ax
  197.         xor      ax,ax ; carry is also 0
  198.         pop      si
  199.         ret
  200.  
  201. @@close:
  202.         cmp      @@virtual,0
  203.         jz       @@close_d
  204.         ret
  205. @@close_d:
  206.         DosCall  DOS_CLOSE_FILE
  207.         ret
  208. @@read:
  209.         cmp      @@virtual,0
  210.         jz       @@read_d
  211.         mov      al, byte ptr fs:[bx]
  212.         or       al,al
  213.         jz       @@read_eof
  214.         inc      bx
  215.         mov      byte ptr [di],al
  216.         mov      ax,1
  217.         clc
  218.         ret
  219. @@read_eof:
  220.         xor      ax,ax
  221.         clc
  222.         ret
  223. @@read_d:
  224.         DosCall  DOS_READ_FROM_HANDLE
  225.         ret
  226.  
  227. read_comline_from_file endp
  228.  
  229. build_arglist proc near
  230. ; input:
  231. ;   ES=DS=CS= seg of all pointers
  232. ;   SI      = pointing to commandline like string
  233. ;   DI      = target buffer
  234. ; output:
  235. ;   DI      = pointing to next free byte in target buffer
  236. ;   all other registers preserved
  237. @@stack struc
  238.   pushA_struc @@
  239. @@stack ends
  240.         pusha
  241.         mov     bp,sp
  242.         xor     cx,cx
  243. @@1:
  244.         inc     cx
  245.         call    get_token
  246.         jnz     @@1
  247.  
  248.         mov     di,[bp].@@di
  249.         mov     bx,di
  250.         inc     cx
  251.         shl     cx,1
  252.         add     di,cx
  253.         mov     si,[bp].@@si
  254. @@2:
  255.         mov     word ptr [bx],di
  256.         inc     bx
  257.         inc     bx
  258.         call    get_token
  259.         mov     di,ax
  260.         jnz     @@2
  261.         mov     word ptr [bx-2],0
  262.         mov     [bp].@@di,ax
  263.         popa
  264.         ret
  265. build_arglist endp
  266.  
  267. handle_response_file proc near
  268. IF 0
  269.         call    read_comline_from_file
  270. ELSE
  271.         pushad
  272.         cld
  273.         lea     di,aligned_auxbuff
  274.         mov     @@list,di
  275.         call    build_arglist     ; we save the rest of the old commandline
  276.         mov     @@ptr,di
  277.         call    read_comline_from_file
  278.         cmp     word ptr aligned_auxbuff,0 ; nothing left in the old ?
  279.         jz      @@ex
  280.         lea     si,comline+1
  281.         mov     @@cptr,si
  282.         cld
  283.         mov     di,@@ptr
  284.         call    build_arglist      ;we scan the read-in commandline
  285.                          ; now we check if there are overwrites
  286.         mov     si,word ptr aligned_auxbuff
  287.         mov     @@list,si
  288.         mov     dx,@@ptr
  289.         mov     si,dx
  290.         mov     si,word ptr [si]
  291.         or      si,si
  292.         jz      @@ex_0
  293.                 ; check if we have to replace the image
  294.         lea     di,@@image
  295.         mov     bx,@@list ; string list of old args
  296.         call    check_token
  297.         js      @@2
  298.         mov     bx,word ptr aligned_auxbuff[bx]
  299.         mov     byte ptr [bx],1    ; mark as 'used'
  300.         cmp     byte ptr [bx+5],0
  301.         je      @@2
  302.         cmp     byte ptr [bx+6],0
  303.         je      @@2
  304.         lea     si,[bx+6]    ; take what is behind 'image='
  305.         jmp     @@2
  306. @@1:
  307.         mov     si,dx
  308.         mov     si,word ptr [si]
  309.         or      si,si
  310.         jz      @@ex_0
  311.                            ; we check for the special case 'ro','rw'
  312.         cmp     byte ptr [si+2],0
  313.         jne     @@1_3
  314.         cmp     word ptr [si],'or'
  315.         jne     @@1_1
  316.         lea     di,@@rw    ; search the opposite (rw replaces ro)
  317.         jmp     @@1_2
  318. @@1_1:
  319.         cmp     word ptr [si],'wr'
  320.         jne     @@1_3
  321.         lea     di,@@ro    ; search the opposite (ro replaces rw)
  322. @@1_2:
  323.         mov     bx,@@list ; string list of old args
  324.         call    check_token
  325.         jmp     @@1_4
  326. @@1_3:
  327.         mov     di,si
  328.         mov     bx,@@list ; string list of old args
  329.         call    check_token
  330. @@1_4:
  331.         js      @@2
  332.                 ; we have to take the old one
  333.         mov     si,word ptr aligned_auxbuff[bx]
  334. @@2:
  335.         push    si
  336.         mov     di,@@cptr
  337.         call    stringcpy
  338.         pop     si
  339.         mov     @@cptr,di
  340.         mov     byte ptr [di-1],' '
  341.         add     dx,2
  342.         cmp     si,@@list       ; avoid overwriting our constants
  343.         jb      @@1
  344.         mov     byte ptr [si],1
  345.         jmp     @@1
  346. @@ex_0:
  347.                 ; we have to take the rest of the old commandline
  348.         lea     bx,aligned_auxbuff ; string list of old args
  349. @@ex_1:
  350.         mov     si,word ptr [bx]
  351.         add     bx,2
  352.         or      si,si
  353.         jz      @@ex_2
  354.         cmp     byte ptr [si],1
  355.         je      @@ex_1       ; skip, what we already replaced
  356.         mov     di,@@cptr
  357.         call    stringcpy
  358.         mov     @@cptr,di
  359.         mov     byte ptr [di-1],' '
  360.         jmp     @@ex_1
  361. @@ex_2:
  362.         mov     bx,@@cptr
  363.         mov     byte ptr [bx-1],0
  364.         sub     bx, offset comline+1
  365.         jz      @@ex_5
  366.         dec     bx
  367. @@ex_5:
  368.         xchg    bh,bl
  369.         mov     word ptr comline-1,bx
  370. @@ex:
  371.         popad
  372.         ret
  373. @@ptr   dw      0
  374. @@list  dw      0
  375. @@cptr  dw      0
  376. @@image db      'image=',0
  377. @@rw    db      'rw',0
  378. @@ro    db      'ro',0
  379. ENDIF
  380. handle_response_file endp
  381.  
  382.  
  383. check_token proc near
  384. ; input:
  385. ;   ES=DS=CS= seg of all pointers
  386. ;   DI = pointing to token
  387. ;   BX = pointing to string-table, terminated by a ZERO-string
  388. ; output:
  389. ;   AX = -1, no match found
  390. ;      =  0, found a matching string, BX = index*2 of that string
  391. ;      =  1, same as AX=0, but token was terminated by '='
  392. ;   DI =  pointing to token behind terminator (0 or '=')
  393. ;
  394.         push_   cx,dx
  395.         cld
  396.         xor     dx,dx
  397.         jmp     @@loop_entry
  398. @@loop:
  399.         pop     di
  400.         inc     dx
  401.         xchg    bx,di
  402.         xor     ax,ax
  403.         mov     cx,-1
  404.         repnz scasb       ; skip to next string in table
  405.         xchg    bx,di
  406.         cmp     byte ptr [bx],0
  407.         jz      @@not_found
  408. @@loop_entry:
  409.         push    di
  410.         mov     cx,size aux_token
  411.         call    name_compare
  412.         jz      @@loop
  413.         pop     ax     ; clean up stack
  414.         xchg    dx,bx  ; get index
  415.         shl     bx,1
  416.         xor     ax,ax
  417.         cmp     byte ptr [di-1],'='
  418.         jne     @@ex
  419.         inc     ax
  420. @@ex:
  421.         pop_    cx,dx
  422.         test    ax,ax
  423.         ret
  424. @@not_found:
  425.         mov     ax,-1
  426.         jmp     @@ex
  427. check_token endp
  428.  
  429. get_setup_version proc near
  430.         mov      cs:setup_version,0
  431.         cmp      dword ptr ds:setup_header_sign,SIGNATURE
  432.         jne      @@ex
  433.         push     word ptr cs:setup_header_version
  434.         pop      cs:setup_version
  435. @@ex:
  436.         ret
  437. get_setup_version endp
  438.  
  439.  
  440. parscommandline proc near
  441.         mov     image_name,0
  442. parscommandline_:
  443.         call    clear_to_default
  444.         mov     cx,word ptr comline-1
  445.         xchg    ch,cl
  446.         jcxz    @@ex_carry
  447.         mov     si,cx
  448.         mov     comline[si+1],0
  449.         mov     command_line,0
  450.         mov     cl_pointer,offset command_line
  451.         lea     si,comline+1
  452.         cld
  453.         cmp     image_name,0
  454.         jnz     @@1
  455.         lea     di,image_name
  456.         call    get_token   ; get the zImage-file name
  457.         jz      @@ex_carry
  458.  
  459.         cmp     image_name,'-'
  460.         jne     @@0
  461.         mov     dword ptr image_name,'amiz'
  462.         mov     word ptr image_name+4,'eg'
  463.         mov     image_name+6,0
  464.         jmp     parscommandline_
  465. @@0:
  466.                             ; got zImage-name
  467.                             ; try to get params
  468.         cmp     image_name,'@'
  469.         jne     @@1
  470.         call    handle_response_file
  471.         jmp     parscommandline
  472. @@1:
  473.         lea     di,image_name
  474.         call    tolower
  475.         jmp     @@next_token
  476.  
  477. @@token_table label byte
  478.               db    'ramdisk',0
  479.               db    'vga',0
  480.               db    'mem',0
  481.               db    'root',0
  482.               db    'ro',0
  483.               db    'rw',0
  484.               db    'no387',0
  485.               db    'single',0
  486.               db    'auto',0
  487.               db    '-v',0
  488.               db    '-t',0
  489.               db    '-d',0
  490.               db    '-rb',0
  491.               db    '-rx',0
  492.               db    '-ja',0
  493.               db    '-clone',0
  494. ;              db    '-oldxd',0
  495.               db    'debug',0
  496.               db    'no-hlt',0
  497.               db    'reserve',0
  498.               db    'hd',0
  499.               db    'bmouse',0
  500.               db    'max_scsi_luns',0
  501.               db    'xd',0
  502.               db    '-n',0
  503.               db    '-txmode',0
  504.               db    '-f',0
  505.               db    'initrd',0
  506.               db    '-noheap',0
  507.               db    '-wait',0
  508.               db    '-dskreset',0
  509.               db    0
  510.  
  511.  
  512. @@jmp_table   dw  @@ramdisk
  513.               dw  @@vga
  514.               dw  @@mem      ;@@tolower  ; mem
  515.               dw  @@tolower  ; root
  516.               dw  @@tolower  ; ro
  517.               dw  @@tolower  ; rw
  518.               dw  @@tolower  ; no387
  519.               dw  @@tolower  ; single
  520.               dw  @@tolower  ; auto
  521.               dw  @@option_v
  522.               dw  @@option_t
  523.               dw  @@option_d
  524.               dw  @@option_realbios
  525.               dw  @@option_rx
  526.               dw  @@option_ja
  527.               dw  @@option_clone
  528. ;              dw  @@option_oldxd
  529.               dw  @@tolower  ; debug
  530.               dw  @@tolower  ; no-hlt
  531.               dw  @@tolower  ; reserve=
  532.               dw  @@tolower  ; hd=
  533.               dw  @@tolower  ; bmouse=
  534.               dw  @@tolower  ; max_scsi_luns=
  535.               dw  @@tolower  ; xd=
  536.               dw  @@option_n
  537.               dw  @@option_txmode
  538.               dw  @@option_force
  539.               dw  @@option_initrd
  540.               dw  @@option_noheap
  541.               dw  @@option_wait
  542.               dw  @@option_dskreset
  543.  
  544. @@next_token:
  545.         lea     di,aux_token
  546.         call    get_token
  547.         jz      @@ex0
  548.         lea     di,aux_token
  549.         lea     bx,@@token_table
  550.         call    check_token
  551.         js      @@not_my_token
  552.         jmp     @@jmp_table[bx]
  553.  
  554. @@mem:
  555.         jz      @@not_my_token
  556.         push    di
  557.         lea     di,aux_token
  558.         call    tolower
  559.         pop     di
  560.         cmp     byte ptr [di],'n'  ; = 'nopentium'
  561.         je      @@not_my_token
  562.         xchg    si,di
  563.         call    value_of
  564.         call    adjust_k_or_m
  565.         xchg    si,di
  566.         mov     end_of_physmem,eax
  567.         jmp     @@not_my_token
  568.  
  569. @@option_wait:
  570.         jz      @@not_my_token
  571.         push    di
  572.         lea     di,aux_token
  573.         call    tolower
  574.         pop     di
  575.         xchg    si,di
  576.         call    value_of
  577.         xchg    si,di
  578.         mov     option_wait,ax
  579.         jmp     @@next_token
  580.  
  581. @@option_initrd:
  582.         jz      @@not_my_token
  583.         push_   si,di
  584.         xchg    si,di
  585.         lea     di,rdimage_name
  586.         call    stringcpy
  587.         pop_    si,di
  588.         mov     option_initrd,1
  589.         jmp     @@next_token
  590.  
  591.  
  592.  
  593. @@ramdisk:      ; have ramdisk param
  594.         mov     got_ram_disk,1
  595.         mov     new_ram_disk,1440
  596.         jz      @@next_token
  597.         xchg    si,di
  598.         call    value_of
  599.         cmp     word ptr [si],'on' ; disable diskchange prompt ?
  600.         jne     @@ramdisk_1
  601.         mov     option_nodiskprompt,1
  602. @@ramdisk_1:
  603.         xchg    si,di
  604.         mov     new_ram_disk,ax
  605.         jmp     @@next_token
  606.  
  607. @@token_table_vga label byte
  608.               db    'normal',0
  609.               db    'extended',0
  610.               db    'ask',0
  611.               db    0
  612.  
  613. @@vga:          ; have vga - param
  614.         mov     got_vga_mode,1
  615.         mov     new_vga_mode,-1  ; default = NORMAL
  616.         jz      @@next_token
  617.         mov     bx,di
  618.         cmp     byte ptr [bx],'-'
  619.         jne     @@vga_1
  620.         inc     bx
  621. @@vga_1:
  622.         cmp     byte ptr [bx],'0'
  623.         jb      @@check_vga_sym
  624.         cmp     byte ptr [bx],'9'
  625.         jna     @@check_vga_num
  626. @@check_vga_sym:
  627.         ; DI already pointing to value
  628.         lea     bx,@@token_table_vga
  629.         call    check_token
  630.         js      @@next_token
  631.         shr     bx,1
  632.         not     bx
  633.         mov     new_vga_mode,bx
  634.         jmp     @@next_token
  635. @@check_vga_num:
  636.         xchg    si,di
  637.         call    value_of
  638.         xchg    si,di
  639.         mov     new_vga_mode,ax
  640.         jmp     @@next_token
  641.  
  642. @@option_t:
  643.         mov     option_t,1     ; forces also option -v
  644. @@option_v:
  645.         mov     option_v,1
  646.         jmp     @@next_token
  647. @@option_noheap:
  648.         mov     option_noheap,1
  649.         jmp     @@next_token
  650.  
  651. @@option_d:
  652.         lea     di,aux_token   ; get output file name
  653.         call    get_token
  654.         jz      @@option_t     ; no file name
  655.         push_   bx,cx,dx
  656.         xor     cx,cx
  657.         lea     dx,aux_token
  658.         DosCall DOS_CREATE_FILE
  659.         pop_    bx,cx,dx
  660.         jc      @@option_t
  661.         mov     debug_file_handle,ax
  662.         jmp     @@option_t
  663.  
  664. @@option_realbios:
  665.         mov     option_realbios,1
  666.         jmp     @@next_token
  667. @@option_rx:
  668.         mov     option_rx,1
  669.         jmp     @@next_token
  670. @@option_ja:
  671.         mov     option_ja,1
  672.         jmp     @@next_token
  673. @@option_clone:
  674.         mov     option_clone,1
  675.         dec     token_count
  676.         jmp     @@next_token
  677. @@option_n:
  678.         mov     option_n,1
  679.         jmp     @@next_token
  680. @@option_force:
  681.         mov     option_force,1
  682.         jmp     @@next_token
  683. @@option_dskreset:
  684.         mov     option_dskreset,1
  685.         jmp     @@next_token
  686.  
  687. @@option_txmode:
  688.         pusha
  689.         push_   ds,es
  690.         xor     ax,ax
  691.         mov     es,ax
  692.         mov     ax,3003h ; al = color mode
  693.         and     ah,byte ptr es:[0410h] ; get EQUIPPEMENT-flags
  694.         cmp     ah,30h
  695.         jne     @@option_txmode6
  696.         mov     al,7     ; al = mono mode
  697. @@option_txmode6:
  698.         xor     ah,ah
  699.         INT     10h
  700.         pop_    ds,es
  701.         popa
  702.         jmp     @@next_token
  703.  
  704.  
  705. @@not_my_token:
  706.         push    si
  707.         lea     si,aux_token
  708.         call    @@append_to_commandline
  709.         pop     si
  710.         jmp     @@next_token
  711. @@tolower:
  712.         lea     di,aux_token
  713.         call    tolower
  714.         jmp     @@not_my_token
  715.  
  716.  
  717.  
  718. @@ex0:
  719.         lea     si,@@boot_tx
  720.         call    @@append_to_commandline
  721.         dec     cl_pointer
  722.         lea     si,image_name
  723.         cld
  724.         mov     di,si
  725. @@ex1:
  726.         lodsb
  727.         test    al,al
  728.         jz      @@ex3
  729.         cmp     al,':'
  730.         je      @@ex2
  731.         cmp     al,'\'
  732.         je      @@ex2
  733.         cmp     al,'/'
  734.         jne     @@ex1
  735. @@ex2:
  736.         mov     di,si
  737.         jmp     @@ex1
  738. @@ex3:
  739.         mov     si,di
  740.         call    @@append_to_commandline
  741. @@ex:
  742.         clc
  743.         ret
  744. @@ex_carry:
  745.         stc
  746.         ret
  747.  
  748. @@append_to_commandline:
  749.         mov     di,cl_pointer
  750. @@append_to_1:
  751.         lodsb
  752.         stosb
  753.         test    al,al
  754.         jnz     @@append_to_1
  755.         mov     byte ptr [di-1],' '
  756.         mov     byte ptr [di],al
  757.         mov     cl_pointer,di
  758.         ret
  759.  
  760. @@boot_tx     db    'BOOT_IMAGE=',0
  761.  
  762. parscommandline endp
  763.  
  764.  
  765. handle_kernel_specifics proc near
  766. IF 0
  767.         cmp     kernelversion,0
  768.         jz      @@ex
  769. ; put here kernel dependent stuff
  770. @@ex:
  771. ENDIF
  772.         ret
  773. handle_kernel_specifics endp
  774.  
  775. get_token proc near
  776. ; returns:
  777. ;   ZFLAG = 1 on EOF
  778. ;   AX = increased DI
  779.         push    di
  780. @@skip_loop:
  781.         lodsb
  782.         cmp     al,' '
  783.         je      @@skip_loop
  784.         jmp     @@ok
  785. @@loop:
  786.         lodsb
  787.         cmp     al,' '
  788.         jne     @@ok
  789.         xor     al,al
  790. @@ok:
  791.         stosb
  792.         test    al,al
  793.         jne     @@loop
  794.         dec     si
  795.         mov     ax,di
  796.         pop     di
  797.         cmp     byte ptr es:[di],0
  798.         jz      @@ex
  799.         inc     token_count
  800. @@ex:
  801.         test    byte ptr es:[di],255
  802.         ret
  803. get_token endp
  804.  
  805.  
  806. readstring proc near
  807.         push    dx
  808.         mov     comline-1,255-2
  809.         lea     dx,comline-1
  810.         DosCall DOS_BUFFERED_INPUT
  811.         lea     dx,newline_tx
  812.         call    print
  813.         push    bx
  814.         movzx   bx,comline
  815.         mov     comline[bx+1],0
  816.         mov     comline-1,0
  817.         pop     bx
  818.         pop     dx
  819.         ret
  820. readstring endp
  821.  
  822.  
  823. stringcpy proc near
  824. ; input:
  825. ;   DS:SI= source address
  826. ;   DS:DI= target address
  827.         push_    ds,ds
  828.         pop     es
  829.         cld
  830. @@loop:
  831.         lodsb
  832.         stosb
  833.         or      al,al
  834.         jnz     @@loop
  835. @@ex:
  836.         pop     ds
  837.         ret
  838. stringcpy endp
  839.  
  840.  
  841. tolower proc near
  842. ; input:
  843. ;   DS:DI= address to ASCIIZ-string
  844.         cld
  845.         xchg    si,di
  846. @@loop:
  847.         lodsb
  848.         or      al,al
  849.         jz      @@ex
  850.         cmp     al,'A'        ; tolower !
  851.         jb      @@loop
  852.         cmp     al,'Z'
  853.         ja      @@loop
  854.         add     byte ptr [si-1],'a'-'A'
  855.         jmp     @@loop
  856. @@ex:
  857.         xchg    si,di
  858.         ret
  859. tolower endp
  860.  
  861. name_compare proc near
  862. ; input:
  863. ;   DS:DI= address to ASCIIZ-string  (name1)
  864. ;          (a "=" marks end of string also)
  865. ;   CS:BX= address to ASCIIZ-string  (name2)
  866. ;          (a "=" marks end of string also)
  867. ;   CX=    max number of character to compare
  868. ;   compare is done by ignoring upper/lower-case
  869. ; Output:
  870. ;   AX=    0 if not equal else equal
  871. ;   DI=    as changed by lodsb, pointing behind terminator (0 or '=')
  872. ;   all other register preserved
  873.           cld
  874.           push    bx
  875.           xchg    si,di
  876.           sub     bx,si
  877. @@m3:
  878.           lodsb
  879.           cmp     al,'='        ; may be name in environement
  880.           jne     short @@32
  881.           xor     al,al
  882.           jmp     short @@m35
  883. @@32:
  884.           cmp     al,'A'        ; tolower !
  885.           jb      short @@m35
  886.           cmp     al,'Z'
  887.           ja      short @@m35
  888.           add     al,'a'-'A'
  889. @@m35:
  890.           mov     ah,al
  891.           mov     al,byte ptr cs:[si+bx-1]
  892.           cmp     al,'='        ; may be name in environement
  893.           jne     short @@34
  894.           xor     al,al
  895.           jmp     short @@m36
  896. @@34:
  897.           cmp     al,'A'        ; tolower !
  898.           jb      short @@m36
  899.           cmp     al,'Z'
  900.           ja      short @@m36
  901.           add     al,'a'-'A'
  902. @@m36:
  903.           or      al,al
  904.           jz      short @@ex_
  905.           or      ah,ah
  906.           jz      short @@exfalse
  907.           cmp     ah,al
  908.           jne     @@exfalse
  909.           loop    @@m3
  910. @@extrue:
  911.           mov     ax,1
  912. @@ex:
  913.           xchg    si,di
  914.           pop     bx
  915.           or      ax,ax
  916.           ret
  917. @@ex_:
  918.           or      ax,ax
  919.           jz      @@extrue
  920. @@exfalse:
  921.           xor     ax,ax         ;  not equal
  922.           jmp     @@ex
  923. name_compare endp
  924.  
  925.  
  926. get_env_variable proc near
  927. ; Input
  928. ;    CS:BX= Pointer to string (ASCIIZ) of desired env-variable
  929. ; Output:
  930. ;    ES:DI=    pointer to string (ASCIIZ) of variable contents (without "=")
  931. ;            or ZERO-string if not found
  932. ;    All other registers preserved
  933.           push    ds
  934.           push    ax
  935.           push    si
  936.           mov     ds,PSP_frame
  937.           mov     ds,ds:PSP_envir_frame
  938.           xor     si,si
  939.  
  940.           mov     al,byte ptr [si]
  941. @@m1:
  942.           mov     cx,80
  943.           or      al,al
  944.           mov     di,si
  945.           jz      @@ex
  946.           call    name_compare
  947.           jnz     @@found    ; string is equal, found the variable
  948.           cld
  949. @@m2:                   ; skip to next string
  950.           lodsb
  951.           or      al,al
  952.           jnz     @@m2
  953.           mov     al,byte ptr [si]
  954.           jmp     @@m1
  955. @@found:
  956. @@ex:
  957.           push    ds
  958.           pop     es
  959.           pop     si
  960.           pop     ax
  961.           pop     ds
  962.           ret
  963. get_env_variable endp
  964.  
  965.  
  966. adjust_k_or_m proc near
  967.   ; Input:
  968.   ;   DS:SI, EAX as delivered by 'value_of'
  969.           pushf
  970.           push    cx
  971.           xor     cx,cx
  972.           mov     ch, byte ptr [si-1]
  973.           cmp     ch,'k'
  974.           jne     @@1
  975.           mov     cl,10
  976. @@ex:
  977.           shl     eax,cl
  978. @@ex0:
  979.           pop     cx
  980.           popf
  981.           ret
  982. @@1:
  983.           cmp     ch,'m'
  984.           jne     @@ex0
  985.           mov     cl,20
  986.           jmp     @@ex
  987. adjust_k_or_m endp
  988.  
  989. value_of proc near
  990.   ; Input:
  991.   ;   DS:SI= pointer to string (ASCIIZ), which contains number to be converted
  992.   ;          (i.e.: 1234, 0xa00, ... ), all non-digit-characters (0..9,a..f,A..F)
  993.   ;          are "delimiters" and mark the end of the string
  994.   ; Output:
  995.   ;   EAX= converted number
  996.   ;   SI= pointing at the first byte behind the delimiter
  997.           cmp    byte ptr [si],'-'
  998.           pushf
  999.           jnz    @@m0
  1000.           inc    si
  1001.   @@m0:
  1002.           push_  ebx,ecx,edx,edi,esi
  1003.           mov    ebx,10
  1004.           xor    edx,edx
  1005.           xor    edi,edi
  1006.           inc    edi
  1007.           cld
  1008.           lodsb
  1009.           call   @@check_white
  1010.           jc     @@ex
  1011.           jne    @@m1
  1012.           lodsb
  1013.           or     al,20h   ; convert to lowercase
  1014.           cmp    al,'x'
  1015.           jne    @@m1
  1016.           mov    ebx,16
  1017.           lodsb
  1018. @@m1:
  1019.           call   @@check_white
  1020.           jb     @@ex
  1021.           xor    ecx,ecx
  1022. @@m2:
  1023.           inc    ecx
  1024.           lodsb
  1025.           call   @@check_white
  1026.           jnc    @@m2
  1027.           std
  1028.           mov    [esp],esi ;advance pointer
  1029.           dec    si
  1030.           dec    si
  1031. @@m3:
  1032.           lodsb
  1033.           or     al,20h    ; convert to lowercase
  1034.           cmp    al,'9'
  1035.           jna    short @@m4
  1036.           add    al,9
  1037. @@m4:
  1038.           and    al,0fh
  1039.           movzx  eax,al
  1040.           imul   eax,edi
  1041.           imul   edi,ebx
  1042.           add    edx,eax
  1043.           loop   @@m3
  1044. @@ex:
  1045.           mov    eax,edx
  1046.           pop_   ebx,ecx,edx,edi,esi
  1047.           popf
  1048.           jnz    @@ex_
  1049.           neg    eax
  1050. @@ex_:
  1051.           ret
  1052.  
  1053. @@check_white:
  1054.           mov    ah,'f'
  1055.           cmp    bl,16
  1056.           je     short @@7
  1057.           mov    ah,'9'
  1058. @@7:
  1059.           or     al,20h
  1060.           cmp    al,'0'
  1061.           jb     short @@9
  1062.           cmp    al,ah
  1063.           ja     short @@9
  1064.           cmp    al,'9'
  1065.           jbe    short @@8
  1066.           cmp    al,'a'
  1067.           jae    short @@8
  1068. @@9:
  1069.           mov    al,' '
  1070. @@8:
  1071.           cmp    al,'0'
  1072.           ret
  1073.  
  1074. value_of endp
  1075.  
  1076.  
  1077.