BR 3392590: add warning for valid but obsolete instructions

Just becase one is compiling for an old CPU doesn't mean one wants to
use obsolete instructions that would not be forward compatible. Rename
the "obsolete" warning to "obsolete-removed" and create a new
"obsolete-valid" warning to go with it (-w[+-]obsolete controls both
options, as usual.)

Suggested-by: C. Masloch <pushbx@38.de>
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
This commit is contained in:
H. Peter Anvin (Intel) 2019-08-09 14:21:42 -07:00
parent 63cacad271
commit fb11889040
2 changed files with 25 additions and 6 deletions

View File

@ -782,21 +782,31 @@ int64_t assemble(int32_t segment, int64_t start, int bits, insn *instruction)
/* Matches! */
if (unlikely(itemp_has(temp, IF_OBSOLETE))) {
/*
* If IF_OBSOLETE is set, warn unless we have *exactly*
* the correct CPU level set.
* If IF_OBSOLETE is set, warn the user. Different
* warning classes for "obsolete but valid for this
* specific CPU" and "obsolete and gone."
*
*!obsolete [on] instruction obsolete for the target CPU
*! warns if an instruction which has been removed
*!obsolete-removed [on] instruction obsolete and removed on the target CPU
*! warns for an instruction which has been removed
*! from the architecture, and is no longer included
*! in the CPU definition given in the \c{[CPU]}
*! directive, for example \c{POP CS}, the opcode for
*! which, \c{0Fh}, instead is an opcode prefix on
*! CPUs newer than the first generation 8086.
*
*!obsolete-valid [on] instruction obsolete but valid on the target CPU
*! warns for an instruction which has been removed
*! from the architecture, but is still valid on the
*! specific CPU given in the \c{CPU} directive. Code
*! using these instructions is not forward compatible.
*/
if (iflag_cmp_cpu_level(&insns_flags[temp->iflag_idx], &cpu)) {
nasm_warn(WARN_OBSOLETE,
"obsolete instruction invalid on the target CPU");
nasm_warn(WARN_OBSOLETE_REMOVED,
"instruction obsolete and removed on the target CPU");
} else {
nasm_warn(WARN_OBSOLETE_VALID,
"instruction obsolete but valid on the target CPU");
}
}

9
test/obsolete.asm Normal file
View File

@ -0,0 +1,9 @@
bits 16
cpu 8086
pop cs
mov cs,ax
cpu 386
pop cs
mov cs,ax