More common code cleanup; actually use the code to compress vkernels
authorhpa <hpa>
Sun, 19 Dec 2004 07:08:48 +0000 (07:08 +0000)
committerhpa <hpa>
Sun, 19 Dec 2004 07:08:48 +0000 (07:08 +0000)
conio.inc
extlinux.asm
font.inc
init.inc [new file with mode: 0644]
isolinux.asm
ldlinux.asm
parseconfig.inc
pxelinux.asm
runkernel.inc
ui.inc

index c0dcecc..b652eb4 100644 (file)
--- a/conio.inc
+++ b/conio.inc
@@ -373,6 +373,9 @@ debug_tracer:       pushad
                ret
 %endif ; DEBUG_TRACERS
 
+               section .data
+ScrollAttribute        db 07h                  ; Grey on white (normal text color)
+
                section .bss
                alignb 2
 NextCharJump    resw 1                 ; Routine to interpret next print char
index fd841c8..757609a 100644 (file)
@@ -1268,20 +1268,6 @@ exten_table_end:
 %ifdef debug                           ; This code for debugging only
 debug_magic    dw 0D00Dh               ; Debug code sentinel
 %endif
-AppendLen       dw 0                    ; Bytes in append= command
-OntimeoutLen   dw 0                    ; Bytes in ontimeout command
-OnerrorLen     dw 0                    ; Bytes in onerror command
-KbdTimeOut      dw 0                    ; Keyboard timeout (if any)
-CmdLinePtr     dw cmd_line_here        ; Command line advancing pointer
-initrd_flag    equ $
-initrd_ptr     dw 0                    ; Initial ramdisk pointer/flag
-VKernelCtr     dw 0                    ; Number of registered vkernels
-ForcePrompt    dw 0                    ; Force prompt
-AllowImplicit   dw 1                    ; Allow implicit kernels
-AllowOptions   dw 1                    ; User-specified options allowed
-SerialPort     dw 0                    ; Serial port base (or 0 for no serial port)
-VGAFontSize    dw 16                   ; Defaults to 16 byte font
-UserFont       db 0                    ; Using a user-specified font
 ScrollAttribute        db 07h                  ; White on black (for text mode)
 
                alignb 4, db 0
@@ -1294,14 +1280,5 @@ EndOfGetCBuf     dw getcbuf+trackbufsize ; = getcbuf+BufSafeBytes
 %error trackbufsize must be a multiple of SECTOR_SIZE
 %endif
 %endif
-;
-; Stuff for the command line; we do some trickery here with equ to avoid
-; tons of zeros appended to our file and wasting space
-;
-linuxauto_cmd  db 'linux auto',0
-linuxauto_len   equ $-linuxauto_cmd
-boot_image      db 'BOOT_IMAGE='
-boot_image_len  equ $-boot_image
-
                align 4, db 0           ; Pad out any unfinished dword
 ldlinux_end    equ $
index e8e610a..9600b30 100644 (file)
--- a/font.inc
+++ b/font.inc
@@ -123,5 +123,9 @@ vidrows_ok: mov [VidRows],al
                section vgafont nobits start=0E000h
 vgafontbuf     resb 8192
 
-               section .text
+               section .data
+               align 2, db 0
+VGAFontSize    dw 16                   ; Defaults to 16 byte font
+UserFont       db 0                    ; Using a user-specified font
+
 
diff --git a/init.inc b/init.inc
new file mode 100644 (file)
index 0000000..d2289d7
--- /dev/null
+++ b/init.inc
@@ -0,0 +1,67 @@
+; -*- fundamental -*-
+; -----------------------------------------------------------------------
+;   
+;   Copyright 2004 H. Peter Anvin - All Rights Reserved
+;
+;   This program is free software; you can redistribute it and/or modify
+;   it under the terms of the GNU General Public License as published by
+;   the Free Software Foundation, Inc., 53 Temple Place Ste 330,
+;   Boston MA 02111-1307, USA; either version 2 of the License, or
+;   (at your option) any later version; incorporated herein by reference.
+;
+; -----------------------------------------------------------------------
+; $Id$
+
+;
+; init.inc
+;
+; Common initialization code (inline)
+;
+
+               section .text
+common_init:
+               ; Now set up screen parameters
+               call adjust_screen
+
+               ; Wipe the F-key area
+               mov al,NULLFILE
+               mov di,FKeyName
+               mov cx,10*(1 << FILENAME_MAX_LG2)
+               rep stosb
+
+               mov si,linuxauto_cmd            ; Default command: "linux auto"
+               mov di,default_cmd
+                mov cx,linuxauto_len
+               rep movsb
+
+               mov di,KbdMap                   ; Default keymap 1:1
+               xor al,al
+               inc ch                          ; CX <- 256
+mkkeymap:      stosb
+               inc al
+               loop mkkeymap
+
+;
+; Clear Files structures
+;
+               mov di,Files
+               mov cx,(MAX_OPEN*open_file_t_size)/4
+               xor eax,eax
+               rep stosd
+
+%if IS_PXELINUX
+               mov di,Files+tftp_pktbuf
+               mov cx,MAX_OPEN
+.setbufptr:
+               mov [di],ax
+               add di,open_file_t_size
+               add ax,PKTBUF_SIZE
+               loop .setbufptr
+%endif
+
+               section .data
+linuxauto_cmd  db 'linux auto',0
+linuxauto_len   equ $-linuxauto_cmd
+
+               section .text                   ; This is an inline file...
+
index c545b01..faab78c 100644 (file)
@@ -835,17 +835,10 @@ all_read:
 ;
 ; Common initialization code
 ;
+%include "init.inc"
 %include "cpuinit.inc"
 
 ;
-; Clear Files structures
-;
-               mov di,Files
-               mov cx,(MAX_OPEN*open_file_t_size)/4
-               xor eax,eax
-               rep stosd
-
-;
 ; Now we're all set to start with our *real* business. First load the
 ; configuration file (if any) and parse it.
 ;
@@ -858,17 +851,6 @@ all_read:
 ; to take'm out.  In fact, we may want to put them back if we're going
 ; to boot ELKS at some point.
 ;
-               mov si,linuxauto_cmd            ; Default command: "linux auto"
-               mov di,default_cmd
-                mov cx,linuxauto_len
-               rep movsb
-
-               mov di,KbdMap                   ; Default keymap 1:1
-               xor al,al
-               mov cx,256
-mkkeymap:      stosb
-               inc al
-               loop mkkeymap
 
 ;
 ; Now, we need to sniff out the actual filesystem data structures.
@@ -1627,22 +1609,6 @@ img_table:
 ;
 ; Misc initialized (data) variables
 ;
-               align 4, db 0
-AppendLen       dw 0                    ; Bytes in append= command
-OntimeoutLen   dw 0                    ; Bytes in ontimeout command
-OnerrorLen     dw 0                    ; Bytes in onerror command
-KbdTimeOut      dw 0                    ; Keyboard timeout (if any)
-CmdLinePtr     dw cmd_line_here        ; Command line advancing pointer
-initrd_flag    equ $
-initrd_ptr     dw 0                    ; Initial ramdisk pointer/flag
-VKernelCtr     dw 0                    ; Number of registered vkernels
-ForcePrompt    dw 0                    ; Force prompt
-AllowImplicit   dw 1                    ; Allow implicit kernels
-AllowOptions   dw 1                    ; User-specified options allowed
-SerialPort     dw 0                    ; Serial port base (or 0 for no serial port)
-VGAFontSize    dw 16                   ; Defaults to 16 byte font
-UserFont       db 0                    ; Using a user-specified font
-ScrollAttribute        db 07h                  ; White on black (for text mode)
 
 ;
 ; Spec packet for disk image emulation
@@ -1677,12 +1643,4 @@ EndOfGetCBuf     dw getcbuf+trackbufsize ; = getcbuf+BufSafeBytes
 %endif
 %endif
 
-;
-; Stuff for the command line; we do some trickery here with equ to avoid
-; tons of zeros appended to our file and wasting space
-;
-linuxauto_cmd  db 'linux auto',0
-linuxauto_len   equ $-linuxauto_cmd
-boot_image      db 'BOOT_IMAGE='
-boot_image_len  equ $-boot_image
 ldlinux_end     equ $
index b976068..b8f2303 100644 (file)
@@ -850,6 +850,7 @@ getfattype:
 ; Common initialization code
 ;
 %include "cpuinit.inc"
+%include "init.inc"
 
 ;
 ; Clear Files structures
@@ -865,19 +866,6 @@ getfattype:
                call initcache
 
 ;
-; Initialization that does not need to go into the any of the pre-load
-; areas
-;
-               ; Now set up screen parameters
-               call adjust_screen
-
-               ; Wipe the F-key area
-               mov al,NULLFILE
-               mov di,FKeyName
-               mov cx,10*(1 << FILENAME_MAX_LG2)
-               rep stosb
-
-;
 ; Now, everything is "up and running"... patch kaboom for more
 ; verbosity and using the full screen system
 ;
@@ -897,17 +885,6 @@ getfattype:
 ; to take'm out.  In fact, we may want to put them back if we're going
 ; to boot ELKS at some point.
 ;
-               mov si,linuxauto_cmd            ; Default command: "linux auto"
-               mov di,default_cmd
-                mov cx,linuxauto_len
-               rep movsb
-
-               mov di,KbdMap                   ; Default keymap 1:1
-               xor al,al
-               inc ch                          ; CX <- 256
-mkkeymap:      stosb
-               inc al
-               loop mkkeymap
 
 ;
 ; Load configuration file
@@ -1558,21 +1535,6 @@ exten_table_end:
 %ifdef debug                           ; This code for debugging only
 debug_magic    dw 0D00Dh               ; Debug code sentinel
 %endif
-AppendLen       dw 0                    ; Bytes in append= command
-OntimeoutLen   dw 0                    ; Bytes in ontimeout command
-OnerrorLen     dw 0                    ; Bytes in onerror command
-KbdTimeOut      dw 0                    ; Keyboard timeout (if any)
-CmdLinePtr     dw cmd_line_here        ; Command line advancing pointer
-initrd_flag    equ $
-initrd_ptr     dw 0                    ; Initial ramdisk pointer/flag
-VKernelCtr     dw 0                    ; Number of registered vkernels
-ForcePrompt    dw 0                    ; Force prompt
-AllowImplicit   dw 1                    ; Allow implicit kernels
-AllowOptions   dw 1                    ; User-specified options allowed
-SerialPort     dw 0                    ; Serial port base (or 0 for no serial port)
-VGAFontSize    dw 16                   ; Defaults to 16 byte font
-UserFont       db 0                    ; Using a user-specified font
-ScrollAttribute        db 07h                  ; White on black (for text mode)
 
                alignb 4, db 0
 BufSafe                dw trackbufsize/SECTOR_SIZE     ; Clusters we can load into trackbuf
@@ -1584,14 +1546,6 @@ EndOfGetCBuf     dw getcbuf+trackbufsize ; = getcbuf+BufSafeBytes
 %error trackbufsize must be a multiple of SECTOR_SIZE
 %endif
 %endif
-;
-; Stuff for the command line; we do some trickery here with equ to avoid
-; tons of zeros appended to our file and wasting space
-;
-linuxauto_cmd  db 'linux auto',0
-linuxauto_len   equ $-linuxauto_cmd
-boot_image      db 'BOOT_IMAGE='
-boot_image_len  equ $-boot_image
 
                align 4, db 0           ; Pad out any unfinished dword
 ldlinux_end    equ $
index f738daf..0a42769 100644 (file)
@@ -47,7 +47,7 @@ pc_onerror:   mov di,Onerror
 ;
 ; "append" command
 ;
-pc_append:      cmp word [VKernelCtr],byte 0
+pc_append:      cmp byte [VKernel],0
                ja .vk
                 mov di,AppendBuf
                call getline
@@ -71,7 +71,7 @@ pc_append:      cmp word [VKernelCtr],byte 0
 %if IS_PXELINUX
 pc_ipappend:   call getint
                jc .err
-               cmp word [VKernelCtr], byte 0
+               cmp byte [VKernel],0
                jne .vk
                mov [IPAppend],bl
 .err:          ret
@@ -84,7 +84,7 @@ pc_ipappend:  call getint
 ;
 %if IS_PXELINUX || IS_ISOLINUX
 pc_localboot:  call getint
-               cmp word [VKernelCtr],byte 0    ; ("label" section only)
+               cmp byte [VKernel],0            ; ("label" section only)
                je .err
                mov di,VKernelBuf+vk_rname
                xor ax,ax
@@ -96,7 +96,7 @@ pc_localboot: call getint
 
 ;
 ; "kernel" command
-pc_kernel:     cmp word [VKernelCtr],byte 0
+pc_kernel:     cmp byte [VKernel],0
                je .err                         ; ("label" section only)
                call pc_getline
                mov di,VKernelBuf+vk_rname
@@ -246,7 +246,7 @@ pc_label:   call commit_vk                  ; Commit any current vkernel
                call pc_getline
                mov di,VKernelBuf+vk_vname
                call mangle_name                ; Mangle virtual name
-               inc word [VKernelCtr]           ; One more vkernel
+               mov byte [VKernel],1            ; We've seen a "label" statement
                mov si,VKernelBuf+vk_vname      ; By default, rname == vname
                mov di,VKernelBuf+vk_rname
                mov cx,FILENAME_MAX
@@ -308,22 +308,51 @@ commit_vk:
                xor ax,ax
                rep stosb
 
-               cmp word [VKernelCtr],byte 0
-               je cvk_ret                      ; No VKernel = return
-               cmp word [VKernelCtr],max_vk    ; Above limit?
-               ja cvk_overflow
-               mov di,[VKernelCtr]
-               dec di
-               shl di,vk_shift
+               ; Pack temporarily into trackbuf
                mov si,VKernelBuf
-               mov cx,(vk_size >> 2)
+               mov di,trackbuf
+               mov cx,vk_size
+               call rllpack
+               ; Now DX = number of bytes
+               mov di,[VKernelBytes]
+               mov cx,dx
+               add dx,di
+               jc .overflow                    ; If > 1 segment
+               mov [VKernelBytes],dx
+               mov si,trackbuf
                push es
                push word vk_seg
                pop es
-               rep movsd                       ; Copy to buffer segment
+               rep movsb
                pop es
-cvk_ret:       ret
-cvk_overflow:  mov word [VKernelCtr],max_vk    ; No more than max_vk, please
                ret
+.overflow:
+               mov si,vk_overflow_msg
+               call writestr
+               ret
+
+               section .data
+vk_overflow_msg        db 'Out of memory parsing config file', CR, LF, 0
+
+               align 2, db 0
+AppendLen       dw 0                    ; Bytes in append= command
+OntimeoutLen   dw 0                    ; Bytes in ontimeout command
+OnerrorLen     dw 0                    ; Bytes in onerror command
+KbdTimeOut      dw 0                    ; Keyboard timeout (if any)
+CmdLinePtr     dw cmd_line_here        ; Command line advancing pointer
+initrd_flag    equ $
+initrd_ptr     dw 0                    ; Initial ramdisk pointer/flag
+ForcePrompt    dw 0                    ; Force prompt
+AllowImplicit   dw 1                    ; Allow implicit kernels
+AllowOptions   dw 1                    ; User-specified options allowed
+SerialPort     dw 0                    ; Serial port base (or 0 for no serial port)
+VKernelBytes   dw 0                    ; Number of bytes used by vkernels
+VKernel                db 0                    ; Have we seen any "label" statements?
+
+               section .bss
+                alignb 4               ; For the good of REP MOVSD
+command_line   resb max_cmd_len+2      ; Command line buffer
+               alignb 4
+default_cmd    resb max_cmd_len+1      ; "default" command line
 
 %include "rllpack.inc"
index 4b1c6b1..be550a1 100644 (file)
@@ -35,9 +35,9 @@ FILENAME_MAX  equ (1 << FILENAME_MAX_LG2)
 NULLFILE       equ 0                   ; Zero byte == null file name
 REBOOT_TIME    equ 5*60                ; If failure, time until full reset
 %assign HIGHMEM_SLOP 128*1024          ; Avoid this much memory near the top
-MAX_SOCKETS_LG2        equ 5                   ; log2(Max number of open sockets)
-MAX_SOCKETS    equ (1 << MAX_SOCKETS_LG2)
-PKTBUF_SIZE    equ (65536/MAX_SOCKETS) ; Per-socket packet buffer size
+MAX_OPEN_LG2   equ 5                   ; log2(Max number of open sockets)
+MAX_OPEN       equ (1 << MAX_OPEN_LG2)
+PKTBUF_SIZE    equ (65536/MAX_OPEN)    ; Per-socket packet buffer size
 TFTP_PORT      equ htons(69)           ; Default TFTP port 
 PKT_RETRY      equ 6                   ; Packet transmit retry count
 PKT_TIMEOUT    equ 12                  ; Initial timeout, timer ticks @ 55 ms
@@ -160,7 +160,7 @@ BOOTP_OPTION_MAGIC  equ htonl(0x63825363)   ; See RFC 2132
 ; HBO = host byte order; NBO = network byte order
 ; (*) = written by options negotiation code, must be dword sized
 ;
-               struc tftp_port_t
+               struc open_file_t
 tftp_localport resw 1                  ; Local port number     (0 = not in use)
 tftp_remoteport        resw 1                  ; Remote port number
 tftp_remoteip  resd 1                  ; Remote IP address
@@ -174,12 +174,9 @@ tftp_dataptr       resw 1                  ; Pointer to available data
                ; At end since it should not be zeroed on socked close
 tftp_pktbuf    resw 1                  ; Packet buffer offset
                endstruc
-
-tftp_clear_words equ (tftp_pktbuf/2)   ; Number of words to zero on socket close
-
 %ifndef DEPEND
-%if (tftp_port_t_size & (tftp_port_t_size-1))
-%error "tftp_port_t is not a power of 2"
+%if (open_file_t_size & (open_file_t_size-1))
+%error "open_file_t is not a power of 2"
 %endif
 %endif
 
@@ -236,8 +233,8 @@ pxe_unload_stack_pkt:
 .reserved:     resw 10                 ; Reserved
 pxe_unload_stack_pkt_len       equ $-pxe_unload_stack_pkt
 
-               alignb tftp_port_t_size
-Sockets                resb MAX_SOCKETS*tftp_port_t_size
+               alignb open_file_t_size
+Files          resb MAX_OPEN*open_file_t_size
 
                alignb 16
                ; BOOTP/DHCP packet buffer
@@ -508,26 +505,6 @@ have_pxe:
 have_entrypoint:
 
 ;
-; Clear Sockets structures
-;
-clear_sockets:
-               mov ax,ds       ; Set ES <- DS
-               mov es,ax
-
-               mov di,Sockets
-               mov cx,(MAX_SOCKETS*tftp_port_t_size)/4
-               xor eax,eax
-               push di
-               rep stosd
-               pop di          ; di <- Sockets
-               mov cx,MAX_SOCKETS
-.setbufptr:
-               mov [di+tftp_pktbuf],ax
-               add di,tftp_port_t_size
-               add ax,PKTBUF_SIZE
-               loop .setbufptr
-
-;
 ; Now attempt to get the BOOTP/DHCP packet that brought us life (and an IP
 ; address).  This lives in the DHCPACK packet (query info 2).
 ;
@@ -685,6 +662,7 @@ udp_init:
 ;
 ; Common initialization code
 ;
+%include "init.inc"
 %include "cpuinit.inc"
 
 ;
@@ -700,18 +678,6 @@ udp_init:
 ; to take'm out.  In fact, we may want to put them back if we're going
 ; to boot ELKS at some point.
 ;
-               mov si,linuxauto_cmd            ; Default command: "linux auto"
-               mov di,default_cmd
-                mov cx,linuxauto_len
-               rep movsb
-
-               mov di,KbdMap                   ; Default keymap 1:1
-               xor al,al
-               mov cx,256
-mkkeymap:      stosb
-               inc al
-               loop mkkeymap
-
 
 ;
 ; Store standard filename prefix
@@ -1375,11 +1341,11 @@ searchdir:
 ;
 allocate_socket:
                push cx
-               mov bx,Sockets
-               mov cx,MAX_SOCKETS
+               mov bx,Files
+               mov cx,MAX_OPEN
 .check:                cmp word [bx], byte 0
                je .found
-               add bx,tftp_port_t_size
+               add bx,open_file_t_size
                loop .check
                xor cx,cx                       ; ZF = 1
                pop cx
@@ -1398,9 +1364,9 @@ allocate_socket:
                push ax
                mov ax,[NextSocket]
                inc ax
-               and ax,((1 << (13-MAX_SOCKETS_LG2))-1) | 0xC000
+               and ax,((1 << (13-MAX_OPEN_LG2))-1) | 0xC000
                mov [NextSocket],ax
-               shl cx,13-MAX_SOCKETS_LG2
+               shl cx,13-MAX_OPEN_LG2
                add cx,ax                       ; ZF = 0
                xchg ch,cl                      ; Convert to network byte order
                mov [bx],cx                     ; Socket in use
@@ -1417,7 +1383,7 @@ free_socket:
                xor ax,ax
                mov es,ax
                mov di,si
-               mov cx,tftp_clear_words
+               mov cx,tftp_pktbuf >> 1         ; tftp_pktbuf is not cleared
                rep stosw
                popa
                pop es
@@ -2402,26 +2368,6 @@ pxe_udp_read_pkt:
 ;
                alignb 4, db 0
 BaseStack      dd StackBuf             ; SS:ESP of base stack
-               dw 0
-AppendLen       dw 0                    ; Bytes in append= command
-OntimeoutLen   dw 0                    ; Bytes in ontimeout command
-OnerrorLen     dw 0                    ; Bytes in onerror command
-KbdTimeOut      dw 0                    ; Keyboard timeout (if any)
-CmdLinePtr     dw cmd_line_here        ; Command line advancing pointer
-initrd_flag    equ $
-initrd_ptr     dw 0                    ; Initial ramdisk pointer/flag
-VKernelCtr     dw 0                    ; Number of registered vkernels
-ForcePrompt    dw 0                    ; Force prompt
-AllowImplicit   dw 1                    ; Allow implicit kernels
-AllowOptions   dw 1                    ; User-specified options allowed
-SerialPort     dw 0                    ; Serial port base (or 0 for no serial port)
-VGAFontSize    dw 16                   ; Defaults to 16 byte font
-UserFont       db 0                    ; Using a user-specified font
-ScrollAttribute        db 07h                  ; White on black (for text mode)
-
-;
-; PXELINUX-specific variables
-; 
 NextSocket     dw 49152                ; Counter for allocating socket numbers
 KeepPXE                db 0                    ; Should PXE be kept around?
 
@@ -2484,12 +2430,4 @@ EndOfGetCBuf     dw getcbuf+trackbufsize ; = getcbuf+BufSafeBytes
 IPAppend       db 0                    ; Default IPAPPEND option
 DHCPMagic      db 0                    ; DHCP site-specific option info
 
-;
-; Stuff for the command line; we do some trickery here with equ to avoid
-; tons of zeros appended to our file and wasting space
-;
-linuxauto_cmd  db 'linux auto',0
-linuxauto_len   equ $-linuxauto_cmd
-boot_image      db 'BOOT_IMAGE='
-boot_image_len  equ $-boot_image
 ldlinux_end     equ $
index 0ff4562..148d083 100644 (file)
@@ -535,6 +535,10 @@ loadinitrd:
                 pop es                          ; Restore original ES
                 ret
 
+               section .data
+boot_image      db 'BOOT_IMAGE='
+boot_image_len  equ $-boot_image
+
                section .bss
                alignb 4
 RamdiskMax     resd 1                  ; Highest address for ramdisk
diff --git a/ui.inc b/ui.inc
index ac721b6..1339905 100644 (file)
--- a/ui.inc
+++ b/ui.inc
@@ -227,21 +227,63 @@ clin_opt_ok:
 ;
 ; Now check if it is a "virtual kernel"
 ;
-               mov cx,[VKernelCtr]
-               push ds
+vk_check:
+               xor si,si                       ; Beginning of vk_seg
                push word vk_seg
                pop ds
-               cmp cx,byte 0
-               je not_vk
-               xor si,si                       ; Point to first vkernel
-vk_check:      pusha
+.scan:
+               cmp si,[VKernelBytes]
+               jae .not_vk
+               mov di,VKernelBuf
+               call rllunpack
+               ; SI updated on return
+               sub di,cx                       ; Return to beginning of buf
+               push si
                mov cx,FILENAME_MAX
-               repe cmpsb                      ; Is this it?
-               je vk_found
-               popa
-               add si,vk_size
-               loop vk_check
-not_vk:                pop ds
+               es repe cmpsb
+               je .found
+               jmp .scan
+
+;
+; We *are* using a "virtual kernel"
+;
+.found:
+               push es
+               push word real_mode_seg
+               pop es
+               mov di,cmd_line_here
+               mov si,VKernelBuf+vk_append
+               mov cx,[VKernelBuf+vk_appendlen]
+               rep movsb
+               mov [CmdLinePtr],di             ; Where to add rest of cmd
+               pop es
+               mov di,KernelName
+               push di 
+               mov si,VKernelBuf+vk_rname
+               mov cx,FILENAME_MAX             ; We need ECX == CX later
+               rep movsb
+               pop di
+%if IS_PXELINUX
+               mov al,[VKernelBuf+vk_ipappend]
+               mov [IPAppend],al
+%endif
+               xor bx,bx                       ; Try only one version
+
+%if IS_SYSLINUX || IS_MDSLINUX
+               jmp get_kernel
+%else
+               ; Is this a "localboot" pseudo-kernel?
+               cmp byte [VKernelBuf+vk_rname], 0
+               jne get_kernel          ; No, it's real, go get it
+
+               mov ax, [VKernelBuf+vk_rname+1]
+               jmp local_boot
+%endif
+
+.not_vk:
+               push cs
+               pop ds
+
 ;
 ; Not a "virtual kernel" - check that's OK and construct the command line
 ;
@@ -346,48 +388,6 @@ on_error:
                jmp load_kernel
 
 ;
-; vk_found: We *are* using a "virtual kernel"
-;
-vk_found:      popa
-               push di
-               mov di,VKernelBuf
-               mov cx,vk_size >> 2
-               rep movsd
-               push es                         ; Restore old DS
-               pop ds
-               push es
-               push word real_mode_seg
-               pop es
-               mov di,cmd_line_here
-               mov si,VKernelBuf+vk_append
-               mov cx,[VKernelBuf+vk_appendlen]
-               rep movsb
-               mov [CmdLinePtr],di             ; Where to add rest of cmd
-               pop es
-                pop di                          ; DI -> KernelName
-               push di 
-               mov si,VKernelBuf+vk_rname
-               mov cx,FILENAME_MAX             ; We need ECX == CX later
-               rep movsb
-               pop di
-%if IS_PXELINUX
-               mov al,[VKernelBuf+vk_ipappend]
-               mov [IPAppend],al
-%endif
-               xor bx,bx                       ; Try only one version
-
-%if IS_SYSLINUX || IS_MDSLINUX
-               jmp get_kernel
-%else
-               ; Is this a "localboot" pseudo-kernel?
-               cmp byte [VKernelBuf+vk_rname], 0
-               jne get_kernel          ; No, it's real, go get it
-
-               mov ax, [VKernelBuf+vk_rname+1]
-               jmp local_boot
-%endif
-
-;
 ; kernel_corrupt: Called if the kernel file does not seem healthy
 ;
 kernel_corrupt: mov si,err_notkernel
@@ -476,9 +476,5 @@ KernelExtPtr        resw 1                  ; During search, final null pointer
 CmdOptPtr       resw 1                 ; Pointer to first option on cmd line
 KbdFlags       resb 1                  ; Check for keyboard escapes
 FuncFlag       resb 1                  ; Escape sequences received from keyboard
-                alignb 4               ; For the good of REP MOVSD
-command_line   resb max_cmd_len+2      ; Command line buffer
-               alignb 4
-default_cmd    resb max_cmd_len+1      ; "default" command line
 
                section .text