home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1999 November / VPR9911B.ISO / misc / src / trees / syslinux-1.42 / genstupid.pl < prev    next >
Text File  |  1998-12-05  |  2KB  |  78 lines

  1. #ident "$Id: genstupid.pl,v 1.1 1998/04/14 05:27:20 hpa Exp $"
  2. ## -----------------------------------------------------------------------
  3. ##   
  4. ##   Copyright 1998 H. Peter Anvin - All Rights Reserved
  5. ##
  6. ##   This program is free software; you can redistribute it and/or modify
  7. ##   it under the terms of the GNU General Public License as published by
  8. ##   the Free Software Foundation, Inc., 675 Mass Ave, Cambridge MA 02139,
  9. ##   USA; either version 2 of the License, or (at your option) any later
  10. ##   version; incorporated herein by reference.
  11. ##
  12. ## -----------------------------------------------------------------------
  13.  
  14. #
  15. # This file is part of the SYSLINUX compilation sequence.
  16. #
  17.  
  18. undef $addr, $begin, $end;
  19. $isbegin = 0;  $isend = 0;
  20.  
  21. while ( $line = <STDIN> ) {
  22.     if ( $line =~ /^\s*([0-9]+) ([0-9A-F]{8}) / ) {
  23.     $addr = hex $2;
  24.     if ( $isbegin ) {
  25.         $begin = $addr;
  26.         $isbegin = 0;
  27.     }
  28.     if ( $isend ) {
  29.         $end = $addr;
  30.         $isend = 0;
  31.     }
  32.     }
  33.     if ( $line =~ /^[0-9A-F\s]+__BEGIN_STUPID_PATCH_AREA\:/ ) {
  34.     $isbegin = 1;
  35.     } elsif ( $line =~ /^[0-9A-F\s]+__END_STUPID_PATCH_AREA\:/ ) {
  36.     $isend = 1;
  37.     }
  38. }
  39.  
  40. if ( !defined($begin) || !defined($end) || $end > 512 || ($end-$begin) < 3 ) {
  41.     print STDERR "$0: error locating STUPID_PATCH_AREA\n";
  42.     exit 1;
  43. }
  44.  
  45. open(CFILE, "> stupid.c") || die "$0: cannot create stupid.c: $!\n";
  46.  
  47. $addr = $begin;
  48. printf CFILE "extern unsigned char bootsect[];\n";
  49. printf CFILE "void make_stupid(void)\n";
  50. printf CFILE "{\n";
  51. printf CFILE "\tbootsect[0x%x] = 0xbd;\n", $addr++;
  52. printf CFILE "\tbootsect[0x%x] = 0x01;\n", $addr++;
  53. printf CFILE "\tbootsect[0x%x] = 0x00;\n", $addr++;
  54. while ( $addr < $end ) {
  55.     printf CFILE "\tbootsect[0x%x] = 0x90;\n", $addr++;
  56. }
  57. print CFILE "}\n";
  58.  
  59. close(CFILE);
  60.  
  61. open(ASMFILE, "> stupid.inc") || die "$0: cannot open stupid.inc: $!\n";
  62.  
  63. printf ASMFILE "\tsection .text\n";
  64. printf ASMFILE "make_stupid:\n";
  65. printf ASMFILE "\tmov si, .stupid_patch\n";
  66. printf ASMFILE "\tmov di, BootSector+0%Xh\n", $begin;
  67. printf ASMFILE "\tmov cx, %d\n", $end-$begin;
  68. printf ASMFILE "\trep movsb\n";
  69. printf ASMFILE "\tret\n";
  70. printf ASMFILE "\tsection .data\n";
  71. printf ASMFILE ".stupid_patch:\n";
  72. printf ASMFILE "\tmov bp,1\n";
  73. for ( $addr = $begin + 3 ; $addr < $end ; $addr++ ) {
  74.     printf ASMFILE "\tnop\n";
  75. }
  76.  
  77. close(ASMFILE);
  78.