diff --git a/kernel/kernel.asm b/kernel/kernel.asm
index 77c6f8e..f613168 100644
--- a/kernel/kernel.asm
+++ b/kernel/kernel.asm
@@ -56,6 +56,7 @@ entry:
 ;************************************************************       
                 global _LowKernelConfig                                        
 _LowKernelConfig:
+config_signature:
                 db 'CONFIG'             ; constant
                 dw configend-configstart; size of config area
                                         ; to be checked !!!
@@ -76,6 +77,9 @@ Version_Revision            dw 41       ; REVISION_SEQ
 Version_Release             dw 1        ; 0=release build, >0=svn#
 
 configend:
+kernel_config_size: equ configend - config_signature
+	; must be below-or-equal the size of struct _KernelConfig
+	;  in the file kconfig.h !
 
 ;************************************************************       
 ; KERNEL CONFIGURATION AREA END
@@ -94,7 +98,11 @@ configend:
 
                 cpu 8086                ; (keep initial entry compatible)
 
+global realentry
 realentry:                              ; execution continues here
+	clc			; this is patched to stc by exeflat
+	adc byte [cs:use_upx_config], 0
+				; ! ZF used later in kernel_start
 
                 push ax
                 push bx
@@ -107,6 +115,9 @@ realentry:                              ; execution continues here
                 pop ax
 
                 jmp     IGROUP:kernel_start
+
+use_upx_config:	db 0
+
 beyond_entry:   times   256-(beyond_entry-entry) db 0
                                         ; scratch area for data (DOS_PSP)
 
@@ -128,10 +139,51 @@ kernel_start:
                 popf
                 pop bx
 
-                mov     ax,I_GROUP
+
+extern _kernel_command_line
+
+	; preserve unit in bl
+init_command_line_buffer:
+	mov dx, I_GROUP
+	mov es, dx
+	mov ax, ss
+	mov ds, ax
+	mov ax, sp			; ds:ax = ss:sp
+	mov si, bp			; si = bp
+	jz .notupx			; ! ZF still left by adc
+
+	xor ax, ax
+	mov ds, ax			; => UPX help data
+	lds si, [5E0h + 1Ch]		; -> original ss:sp - 2
+	lea ax, [si + 2]		; ax = original sp
+	mov si, word [si]		; si = original bp
+
+.notupx:
+	cmp si, 114h
+	jb .none
+	cmp word [si - 14h], "CL"
+	jne .none
+	lea si, [si - 114h]		; -> command line buffer
+	cmp ax, si
+	ja .none
+	mov di, _kernel_command_line	; our buffer
+	mov cx, 255
+	xor ax, ax
+	push di
+	rep movsb		; copy up to 255 bytes
+	stosb			; truncate
+	pop di
+	mov ch, 1		; = 256
+	repne scasb		; scan for terminator
+	rep stosb		; clear remainder of buffer
+				; (make sure we do not have 0x00 0xFF
+				;  even if the command line given is
+				;  actually the empty string)
+.none:
+
                 cli
-                mov     ss,ax
-                mov     sp,init_tos
+                mov     ss, dx
+                mov     sp, init_tos
                 int     12h             ; move init text+data to higher memory
                 mov     cl,6
                 shl     ax,cl           ; convert kb to para
@@ -212,10 +264,40 @@ cont:           ; Now set up call frame
                 cpu XCPU
 %endif
                 mov     [_CPULevel], al
-                
+
+	push ds
+	pop es
                 mov     ax,ss
+
+extern _debugger_present
+	mov bl, 1
+	clc
+	int3
+	jc .skip_ints_00_06
+	xor bx, bx
+.skip_ints_00_06:
+	mov byte [ss:_debugger_present], bl
+
+extern _InitKernelConfig
+	mov si, 60h
+	mov ds, si
+	mov si, _LowKernelConfig
+	cmp byte [use_upx_config], 0
+	je .notupx
+	mov si, 5Eh
+	mov ds, si
+	mov si, 2
+	mov bl, [0]
+	mov byte [es:_BootDrive], bl
+.notupx:
+	mov es, ax
+	mov di, _InitKernelConfig
+	mov cx, kernel_config_size / 2
+	rep movsw
+%if kernel_config_size & 1
+	movsb
+%endif
                 mov     ds,ax
-                mov     es,ax
                 jmp     _FreeDOSmain
 
 %if XCPU != 86
diff --git a/kernel/main.c b/kernel/main.c
index f99492c..2b3f3c6 100644
--- a/kernel/main.c
+++ b/kernel/main.c
@@ -44,8 +44,6 @@ static char copyright[] =
     "GNU General Public License as published by the Free Software Foundation;\n"
     "either version 2, or (at your option) any later version.\n";
 
-struct _KernelConfig InitKernelConfig BSS_INIT({0});
-
 STATIC VOID InitIO(void);
 
 STATIC VOID update_dcb(struct dhdr FAR *);
@@ -69,6 +67,11 @@ __segment DosTextSeg = 0;
 #endif
 
 struct lol FAR *LoL = &DATASTART;
+struct _KernelConfig InitKernelConfig = { 0xFF };
+UBYTE kernel_command_line[256] = { 0x00, 0xFF }; /* special none value */
+UBYTE debugger_present = 0xFF;	/* initialised in kernel.asm
+				   do NOT set 0 here or compiler may
+				   move it into bss that we zero out */
 
 VOID ASMCFUNC FreeDOSmain(void)
 {
@@ -92,17 +95,8 @@ VOID ASMCFUNC FreeDOSmain(void)
 
   drv = LoL->BootDrive + 1;
   p = MK_FP(0, 0x5e0);
-  if (fmemcmp(p+2,"CONFIG",6) == 0)      /* UPX */
   {
-    fmemcpy(&InitKernelConfig, p+2, sizeof(InitKernelConfig));
-
-    drv = *p + 1;
-    *(DWORD FAR *)(p+2) = 0;
-  }
-  else
-  {
-    *p = drv - 1;
-    fmemcpy(&InitKernelConfig, &LowKernelConfig, sizeof(InitKernelConfig));
+    *p = drv - 1;	/* compatibility with older kernels */
   }
 
   if (drv >= 0x80)
@@ -112,6 +106,12 @@ VOID ASMCFUNC FreeDOSmain(void)
   /* install DOS API and other interrupt service routines, basic kernel functionality works */
   setup_int_vectors();
 
+  if (kernel_command_line[0] == 0x00 && kernel_command_line[1] == 0xFF) {
+    printf("KERNEL: Command line is not specified.\n");
+  } else {
+    printf("KERNEL: Command line is \"%s\"\n", kernel_command_line);
+  }
+
   /* check if booting from floppy/CD */
   CheckContinueBootFromHarddisk();
 
@@ -244,10 +244,10 @@ STATIC void setup_int_vectors(void)
   } vectors[] =
     {
       /* all of these are in the DOS DS */
-      { 0x0, FP_OFF(int0_handler) },   /* zero divide */
-      { 0x1, FP_OFF(empty_handler) },  /* single step */
-      { 0x3, FP_OFF(empty_handler) },  /* debug breakpoint */
-      { 0x6, FP_OFF(int6_handler) },   /* invalid opcode */
+      { 0x80 | 0x0, FP_OFF(int0_handler) },   /* zero divide */
+      { 0x80 | 0x1, FP_OFF(empty_handler) },  /* single step */
+      { 0x80 | 0x3, FP_OFF(empty_handler) },  /* debug breakpoint */
+      { 0x80 | 0x6, FP_OFF(int6_handler) },   /* invalid opcode */
       { 0x19, FP_OFF(int19_handler) }, /* BIOS bootstrap loader, vdisk */
       { 0x20, FP_OFF(int20_handler) },
       { 0x21, FP_OFF(int21_handler) }, /* primary DOS API */
@@ -270,10 +270,11 @@ STATIC void setup_int_vectors(void)
 
   /* install default handlers */
   for (i = 0x23; i <= 0x3f; i++)
-    setvec(i, empty_handler);
+    setvec(i, empty_handler); /* note: int 31h segment should be DOS DS */
   HaltCpuWhileIdle = 0;
   for (pvec = vectors; pvec < vectors + (sizeof vectors/sizeof *pvec); pvec++)
-    setvec(pvec->intno, (intvec)MK_FP(FP_SEG(empty_handler), pvec->handleroff));
+    if ((pvec->intno & 0x80) == 0 || debugger_present == 0)
+      setvec(pvec->intno & 0x7F, (intvec)MK_FP(FP_SEG(empty_handler), pvec->handleroff));
   pokeb(0, 0x30 * 4, 0xea);
   pokel(0, 0x30 * 4 + 1, (ULONG)cpm_entry);
 
diff --git a/utils/exeflat.c b/utils/exeflat.c
index d055f98..7765d7e 100644
--- a/utils/exeflat.c
+++ b/utils/exeflat.c
@@ -54,6 +54,11 @@ large portions copied from task.c
 #define BUFSIZE 32768u
 
 #define KERNEL_START 0x16 /* the kernel code really starts here at 60:16 */
+#define KERNEL_CONFIG_LENGTH 32 - 2 - 4
+	/* 32 entrypoint structure,
+	   2 entrypoint short jump,
+	   4 near jump / ss:sp storage  */
+char kernel_config[KERNEL_CONFIG_LENGTH];
 
 typedef struct {
   UWORD off, seg;
@@ -85,7 +90,7 @@ static void usage(void)
 
 static int exeflat(const char *srcfile, const char *dstfile,
                    const char *start, short *silentSegments, short silentcount,
-                   int UPX, exe_header *header)
+                   int UPX, int patchsignal, exe_header *header)
 {
   int i, j;
   size_t bufsize;
@@ -94,6 +99,7 @@ static int exeflat(const char *srcfile, const char *dstfile,
   ULONG size, to_xfer;
   UBYTE **buffers;
   UBYTE **curbuf;
+  UBYTE *signal;
   FILE *src, *dest;
   short silentdone = 0;
   int compress_sys_file;
@@ -199,6 +205,14 @@ static int exeflat(const char *srcfile, const char *dstfile,
   printf("\nProcessed %d relocations, %d not shown\n",
          header->exRelocItems, silentdone);
 
+  if (UPX)
+  {
+    struct x {
+      char y[(KERNEL_CONFIG_LENGTH + 2) <= BUFSIZE ? 1 : -1];
+    };
+    memcpy(kernel_config, &buffers[0][2], KERNEL_CONFIG_LENGTH);
+  }
+
   realentry = KERNEL_START;
   if (buffers[0][0] == 0xeb /* jmp short */)
   {
@@ -209,6 +223,31 @@ static int exeflat(const char *srcfile, const char *dstfile,
     realentry = ((UWORD)(buffers[0][2]) << 8) + buffers[0][1] + 3;
   }
 
+  signal = &buffers[(size_t)(realentry / BUFSIZE)][(size_t)(realentry % BUFSIZE)];
+  if (patchsignal && UPX)
+  {
+    if (*signal == 0xF8) /* clc */
+    {
+      *signal = 0xF9; /* stc */
+      printf("Signal patched to indicate compression\n", dstfile);
+    }
+    else if (*signal == 0xF9)
+    {
+      printf("Signal is already patched to indicate compression\n", dstfile);
+    }
+  }
+  else if (patchsignal)
+  {
+    if (*signal == 0xF8) /* clc */
+    {
+      printf("Signal not patched as no compression used\n", dstfile);
+    }
+    else if (*signal == 0xF9)
+    {
+      printf("Signal wrongly patched to indicate compression ??\n", dstfile);
+    }
+  }
+
   if ((dest = fopen(dstfile, "wb+")) == NULL)
   {
     printf("Destination file %s could not be created\n", dstfile);
@@ -289,6 +328,18 @@ static void write_header(FILE *dest, size_t size)
     0xe9, 0, 0                /* 100: jmp 103 */
   };
 
+  if (0 == memcmp(kernel_config, "CONFIG", 6)) {
+    unsigned int length = kernel_config[6] + kernel_config[7] * 256U + 8;
+    if (length <= KERNEL_CONFIG_LENGTH) {
+      memcpy(&JumpBehindCode[2], kernel_config, length);
+      printf("Copied %u bytes of kernel config block to header\n", length);
+    } else {
+      printf("Error: Found %u bytes of kernel config block, too long!\n", length);
+    }
+  } else {
+    printf("Error: Found no kernel config block!\n");
+  }
+
   struct x {
     char y[sizeof(JumpBehindCode) == 0x20 ? 1 : -1];
   };
@@ -324,25 +375,28 @@ static void write_trailer(FILE *dest, size_t size, int compress_sys_file,
     0xAA,                     /* 15 stosb (store drive number)*/
     0x8B, 0xF7,               /* 16 mov si,di                 */
     0xF3, 0xA4,               /* 18 rep movsb                 */
-    0x1E,                     /* 20 push ds                   */
-    0x58,                     /* 21 pop  ax                   */
-    0x05, 0x00, 0x00,         /* 22 add ax,...                */
-    0x8E, 0xD0,               /* 25 mov ss,ax                 */
-    0xBC, 0x00, 0x00,         /* 27 mov sp,...                */
-    0x31, 0xC0,               /* 30 xor ax,ax                 */
-    0xFF, 0xE0                /* 32 jmp ax                    */
+0x55,				/* 20 push bp */
+0x26, 0x8C, 0x16, 0x1E, 0x00,	/* 21 mov word [es:(#32 - 2)], ss */
+0x26, 0x89, 0x26, 0x1C, 0x00,	/* 26 mov word [es:(#32 - 4)], sp */
+    0x1E,                     /* 31 push ds                   */
+    0x58,                     /* 32 pop  ax                   */
+    0x05, 0x00, 0x00,         /* 33 add ax,...                */
+    0x8E, 0xD0,               /* 36 mov ss,ax                 */
+    0xBC, 0x00, 0x00,         /* 38 mov sp,...                */
+    0x31, 0xC0,               /* 41 xor ax,ax                 */
+    0xFF, 0xE0                /* 43 jmp ax                    */
   };
 
   *(short *)&trailer[1] = (short)size + 0x20;
-  *(short *)&trailer[23] = header->exInitSS;
-  *(short *)&trailer[28] = header->exInitSP;
+  *(short *)&trailer[34] = header->exInitSS;
+  *(short *)&trailer[39] = header->exInitSP;
   if (compress_sys_file) {
     /* replace by jmp word ptr [6]: ff 26 06 00
        (the .SYS strategy handler which will unpack) */
-    *(long *)&trailer[30] = 0x000626ffL;
+    *(long *)&trailer[41] = 0x000626ffL;
     /* set up a 4K stack for the UPX decompressor to work with */
-    *(short *)&trailer[23] = 0x1000;
-    *(short *)&trailer[28] = 0x1000;
+    *(short *)&trailer[34] = 0x1000;
+    *(short *)&trailer[39] = 0x1000;
   }
   fwrite(trailer, 1, sizeof trailer, dest);
 }
@@ -398,7 +452,7 @@ int main(int argc, char **argv)
 
   compress_sys_file = exeflat(argv[1], argv[2], argv[3],
                               silentSegments, silentcount,
-                              UPX, &header);
+                              UPX, 1, &header);
   if (!UPX)
     exit(0);
 
@@ -445,7 +499,7 @@ int main(int argc, char **argv)
   {
     exeflat(tmpexe, argv[2], argv[3],
             silentSegments, silentcount,
-            FALSE, &header);
+            FALSE, 0, &header);
     remove(tmpexe);
   }
 
