com32r: verify the COM32R magic number
authorH. Peter Anvin <hpa@zytor.com>
Mon, 25 May 2009 21:56:11 +0000 (14:56 -0700)
committerH. Peter Anvin <hpa@zytor.com>
Mon, 25 May 2009 21:56:11 +0000 (14:56 -0700)
Since we might be having COM32 and COM32R in the same filesystem, do
check for the appropriate COM32R magic before doing anything else.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
core/com32.inc
doc/comboot.txt

index 1ab4248..1f14125 100644 (file)
@@ -54,6 +54,15 @@ is_com32_image:
                mov bx,abort_check      ; Don't print dots, but allow abort
                call load_high
 
+               mov esi,com32_entry
+               mov edi,trackbuf
+               mov ecx,5
+               call bcopy
+               cmp dword [trackbuf],0xcd4cfeb8
+               jne not_com32r
+               cmp byte [trackbuf+4],0x21
+               jne not_com32r
+
 com32_start:
                ;
                ; Point the stack to the end of (permitted) high memory
@@ -94,3 +103,13 @@ com32_exit:
                mov dword [PMESP],__stack_end   ; Stop use of COM32 stack
                sti
                jmp enter_command
+
+not_com32r:
+               mov si,KernelCName
+               call writestr
+               mov si,not_com32r_msg
+               call writestr
+               jmp enter_command
+
+               section .data16
+not_com32r_msg db ': not a COM32R image', CR, LF, 0
index 1b087a1..101b173 100644 (file)
@@ -61,8 +61,8 @@ be possible to create a COM32 execution engine that would run under
 something like Linux DOSEMU, it is recommended that the code does not
 assume CPL 0 unless absolutely necessary.
 
-It is highly recommended that every COM32R program begins with the byte
-sequence B8 FE 4C CD 21 (mov eax,21cd4cfeh) as a magic number.
+A COM32R program must start with the byte sequence B8 FE 4C CD 21 (mov
+eax,21cd4cfeh) as a magic number.
 
 The COM32R format replaces the earlier COM32 format, which was linked
 to a fixed address (0x101000).