blob: 52fb93430e70d54ba6f619b8cfdc34bf6d4d57a6 [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:]
23 infile = open(infilename, 'rb')
24 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')
31 else:
32 out.append(line)
33 infile.close()
34 outfile = open(outfilename, 'wb')
35 outfile.write(''.join(out))
36 outfile.close()
37
38if __name__ == '__main__':
39 main()