home *** CD-ROM | disk | FTP | other *** search
/ Chip 2005 August (Alt) / CHIP 2005-08.1.iso / program / guvenlik / syslinux-3.07.exe / com32 / lib / sys / entry.S < prev    next >
Encoding:
Text File  |  2004-12-20  |  2.6 KB  |  91 lines

  1. #ident "$Id: entry.S,v 1.3 2004/12/21 02:47:08 hpa Exp $"
  2. # -----------------------------------------------------------------------
  3. #   
  4. #   Copyright 2003-2004 H. Peter Anvin - All Rights Reserved
  5. #
  6. #   Permission is hereby granted, free of charge, to any person
  7. #   obtaining a copy of this software and associated documentation
  8. #   files (the "Software"), to deal in the Software without
  9. #   restriction, including without limitation the rights to use,
  10. #   copy, modify, merge, publish, distribute, sublicense, and/or
  11. #   sell copies of the Software, and to permit persons to whom
  12. #   the Software is furnished to do so, subject to the following
  13. #   conditions:
  14. #   
  15. #   The above copyright notice and this permission notice shall
  16. #   be included in all copies or substantial portions of the Software.
  17. #   
  18. #   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  19. #   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  20. #   OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  21. #   NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  22. #   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  23. #   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  24. #   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  25. #   OTHER DEALINGS IN THE SOFTWARE.
  26. #
  27. # -----------------------------------------------------------------------
  28.  
  29. # COM32 start up code - must be linked first in the binary
  30.  
  31.     
  32.         .section ".init","ax"
  33.         .globl _start
  34.         .type _start, @function
  35. _start:
  36.         # This first instruction acts as COM32 magic number
  37.         movl $0x21cd4cff,%eax
  38.  
  39.         # Upwards string operations
  40.         cld
  41.  
  42.         # Zero the .bss segment
  43.         xorl %eax,%eax
  44.         movl $__bss_start,%edi        # Symbol provided by linker
  45.         movl $_end+3,%ecx        # Symbol provided by linker
  46.         subl %edi,%ecx
  47.         shrl $2,%ecx
  48.         rep ; stosl
  49.  
  50.         # Copy COM32 invocation parameters
  51.         leal 4(%esp),%esi        # Argument list
  52.         movl $__com32,%edi
  53.         movl $6,%ecx
  54.         movl %esp,-4(%edi)        # Save the initial stack ptr
  55.         cmpl (%esi),%ecx
  56.         jbe 1f
  57.         movl (%esi),%ecx
  58. 1:        rep ; movsl
  59.  
  60.         # Parse the command line (assumes REGPARM)
  61.         movl __com32+4,%edx        # Command line
  62.         pushl %edx            # Make space for argv
  63.         movl %esp,%eax
  64.         call __parse_argv
  65.         pushl %eax            # Save argc
  66.  
  67.         # Look for library initialization functions
  68.         movl $__ctors_start, %esi
  69. 2:
  70.         cmpl $__ctors_end, %esi
  71.         jae 3f
  72.         call *(%esi)
  73.         addl $4,%esi
  74.         jmp 2b
  75. #
  76. # Actually run main.  This assumes REGPARM is used!!!!
  77. #
  78. 3:
  79.         popl %eax            # argc
  80.         popl %edx            # argv
  81.         call main
  82.         call *(__exit_handler)
  83.         hlt
  84.         .size _start, .-_start
  85.             
  86.         .bss
  87.         .globl __entry_esp
  88. __entry_esp:    .space 4
  89.         .globl __com32
  90. __com32:    .space 4*6
  91.