blob: a981bbf953fb53e497c6f8ab73184b5fc0369c95 [file] [log] [blame]
Kevin O'Connor35f42dc2012-03-05 17:45:55 -05001#!/usr/bin/env python
2# Work around x86emu bugs by replacing problematic instructions.
3#
4# Copyright (C) 2012 Kevin O'Connor <kevin@koconnor.net>
5#
6# This file may be distributed under the terms of the GNU GPLv3 license.
7
8# The x86emu code widely used in Linux distributions when running Xorg
9# in vesamode is known to have issues with "retl", "leavel", "entryl",
10# and some variants of "calll". This code modifies those instructions
11# (ret and leave) that are known to be generated by gcc to avoid
12# triggering the x86emu bugs.
13
14# It is also known that the Windows vgabios emulator has issues with
15# addressing negative offsets to the %esp register. That has been
Kevin O'Connorf9c30722012-12-07 12:23:27 -050016# worked around by not using the gcc parameter "-fomit-frame-pointer"
Kevin O'Connor35f42dc2012-03-05 17:45:55 -050017# when compiling.
18
19import sys
20
21def main():
22 infilename, outfilename = sys.argv[1:]
Johannes Krampf19f789b2014-01-19 16:03:49 +010023 infile = open(infilename, 'r')
Kevin O'Connor35f42dc2012-03-05 17:45:55 -050024 out = []
25 for line in infile:
26 sline = line.strip()
27 if sline == 'ret':
28 out.append('retw $2\n')
29 elif sline == 'leave':
30 out.append('movl %ebp, %esp ; popl %ebp\n')
Kevin O'Connor9332f9b2013-11-30 12:52:44 -050031 elif sline.startswith('call'):
32 out.append('pushw %ax ; callw' + sline[4:] + '\n')
Kevin O'Connor35f42dc2012-03-05 17:45:55 -050033 else:
34 out.append(line)
35 infile.close()
Johannes Krampf19f789b2014-01-19 16:03:49 +010036 outfile = open(outfilename, 'w')
Kevin O'Connor35f42dc2012-03-05 17:45:55 -050037 outfile.write(''.join(out))
38 outfile.close()
39
40if __name__ == '__main__':
41 main()