Commit 05a2ae7c authored by Joerg Roedel's avatar Joerg Roedel Committed by Borislav Petkov

x86/insn: Make inat-tables.c suitable for pre-decompression code

The inat-tables.c file has some arrays in it that contain pointers to
other arrays. These pointers need to be relocated when the kernel
image is moved to a different location.

The pre-decompression boot-code has no support for applying ELF
relocations, so initialize these arrays at runtime in the
pre-decompression code to make sure all pointers are correctly
initialized.
Signed-off-by: default avatarJoerg Roedel <jroedel@suse.de>
Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
Acked-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
Link: https://lkml.kernel.org/r/20200907131613.12703-8-joro@8bytes.org
parent 05a2fdf3
...@@ -362,6 +362,9 @@ function convert_operands(count,opnd, i,j,imm,mod) ...@@ -362,6 +362,9 @@ function convert_operands(count,opnd, i,j,imm,mod)
END { END {
if (awkchecked != "") if (awkchecked != "")
exit 1 exit 1
print "#ifndef __BOOT_COMPRESSED\n"
# print escape opcode map's array # print escape opcode map's array
print "/* Escape opcode map array */" print "/* Escape opcode map array */"
print "const insn_attr_t * const inat_escape_tables[INAT_ESC_MAX + 1]" \ print "const insn_attr_t * const inat_escape_tables[INAT_ESC_MAX + 1]" \
...@@ -388,6 +391,51 @@ END { ...@@ -388,6 +391,51 @@ END {
for (j = 0; j < max_lprefix; j++) for (j = 0; j < max_lprefix; j++)
if (atable[i,j]) if (atable[i,j])
print " ["i"]["j"] = "atable[i,j]"," print " ["i"]["j"] = "atable[i,j]","
print "};" print "};\n"
print "#else /* !__BOOT_COMPRESSED */\n"
print "/* Escape opcode map array */"
print "static const insn_attr_t *inat_escape_tables[INAT_ESC_MAX + 1]" \
"[INAT_LSTPFX_MAX + 1];"
print ""
print "/* Group opcode map array */"
print "static const insn_attr_t *inat_group_tables[INAT_GRP_MAX + 1]"\
"[INAT_LSTPFX_MAX + 1];"
print ""
print "/* AVX opcode map array */"
print "static const insn_attr_t *inat_avx_tables[X86_VEX_M_MAX + 1]"\
"[INAT_LSTPFX_MAX + 1];"
print ""
print "static void inat_init_tables(void)"
print "{"
# print escape opcode map's array
print "\t/* Print Escape opcode map array */"
for (i = 0; i < geid; i++)
for (j = 0; j < max_lprefix; j++)
if (etable[i,j])
print "\tinat_escape_tables["i"]["j"] = "etable[i,j]";"
print ""
# print group opcode map's array
print "\t/* Print Group opcode map array */"
for (i = 0; i < ggid; i++)
for (j = 0; j < max_lprefix; j++)
if (gtable[i,j])
print "\tinat_group_tables["i"]["j"] = "gtable[i,j]";"
print ""
# print AVX opcode map's array
print "\t/* Print AVX opcode map array */"
for (i = 0; i < gaid; i++)
for (j = 0; j < max_lprefix; j++)
if (atable[i,j])
print "\tinat_avx_tables["i"]["j"] = "atable[i,j]";"
print "}"
print "#endif"
} }
...@@ -362,6 +362,9 @@ function convert_operands(count,opnd, i,j,imm,mod) ...@@ -362,6 +362,9 @@ function convert_operands(count,opnd, i,j,imm,mod)
END { END {
if (awkchecked != "") if (awkchecked != "")
exit 1 exit 1
print "#ifndef __BOOT_COMPRESSED\n"
# print escape opcode map's array # print escape opcode map's array
print "/* Escape opcode map array */" print "/* Escape opcode map array */"
print "const insn_attr_t * const inat_escape_tables[INAT_ESC_MAX + 1]" \ print "const insn_attr_t * const inat_escape_tables[INAT_ESC_MAX + 1]" \
...@@ -388,6 +391,51 @@ END { ...@@ -388,6 +391,51 @@ END {
for (j = 0; j < max_lprefix; j++) for (j = 0; j < max_lprefix; j++)
if (atable[i,j]) if (atable[i,j])
print " ["i"]["j"] = "atable[i,j]"," print " ["i"]["j"] = "atable[i,j]","
print "};" print "};\n"
print "#else /* !__BOOT_COMPRESSED */\n"
print "/* Escape opcode map array */"
print "static const insn_attr_t *inat_escape_tables[INAT_ESC_MAX + 1]" \
"[INAT_LSTPFX_MAX + 1];"
print ""
print "/* Group opcode map array */"
print "static const insn_attr_t *inat_group_tables[INAT_GRP_MAX + 1]"\
"[INAT_LSTPFX_MAX + 1];"
print ""
print "/* AVX opcode map array */"
print "static const insn_attr_t *inat_avx_tables[X86_VEX_M_MAX + 1]"\
"[INAT_LSTPFX_MAX + 1];"
print ""
print "static void inat_init_tables(void)"
print "{"
# print escape opcode map's array
print "\t/* Print Escape opcode map array */"
for (i = 0; i < geid; i++)
for (j = 0; j < max_lprefix; j++)
if (etable[i,j])
print "\tinat_escape_tables["i"]["j"] = "etable[i,j]";"
print ""
# print group opcode map's array
print "\t/* Print Group opcode map array */"
for (i = 0; i < ggid; i++)
for (j = 0; j < max_lprefix; j++)
if (gtable[i,j])
print "\tinat_group_tables["i"]["j"] = "gtable[i,j]";"
print ""
# print AVX opcode map's array
print "\t/* Print AVX opcode map array */"
for (i = 0; i < gaid; i++)
for (j = 0; j < max_lprefix; j++)
if (atable[i,j])
print "\tinat_avx_tables["i"]["j"] = "atable[i,j]";"
print "}"
print "#endif"
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment