summary refs log tree commit diff stats
path: root/lib/arch/x86/amd64.S
blob: 47a26f627c40e7f1debbe4c9ee3b0caad938a3b5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#
#
#            Nim's Runtime Library
#        (c) Copyright 2015 Rokas Kupstys
#
#    See the file "copying.txt", included in this
#    distribution, for details about the copyright.
#
# Partially based on code from musl libc Copyright © 2005-2014 Rich Felker, et al.

.globl narch_coroExecWithStack
.globl narch_setjmp
.globl narch_longjmp
.text


# SysV ABI - first argument is rdi.
# MS ABI   - first argument is rcx.
#if defined(__MINGW32__) || defined(__MINGW64__)
  #define REG_ARG1 rcx
  #define REG_ARG2 rdx
#else
  #define REG_ARG1 rdi
  #define REG_ARG2 rsi
#endif


narch_coroExecWithStack:
  mov  %REG_ARG2, %rsp        # swap stack with one passed to func
  sub  $0x30, %rsp            # shadow space (for ms ABI) 0x20 + 0x10 for possible misalignment
  and  $-0x10, %rsp           # 16-byte stack alignment
  call *%REG_ARG1


narch_setjmp:
  add   $0x10, %REG_ARG1      # 16-byte alignment
  and   $-0x10, %REG_ARG1
  mov   %rbx, 0x00(%REG_ARG1) # jmp_buf, move registers onto it
  mov   %rbp, 0x08(%REG_ARG1)
  mov   %r12, 0x10(%REG_ARG1)
  mov   %r13, 0x18(%REG_ARG1)
  mov   %r14, 0x20(%REG_ARG1)
  mov   %r15, 0x28(%REG_ARG1)
  lea   0x08(%rsp), %rdx      # this is our rsp WITHOUT current ret addr
  mov   %rdx, 0x30(%REG_ARG1)
  mov   (%rsp), %rdx          # save return addr ptr for new rip
  mov   %rdx, 0x38(%REG_ARG1)
  mov   %rsi, 0x40(%REG_ARG1)
  mov   %rdi, 0x48(%REG_ARG1)
#if defined(__MINGW32__) || defined(__MINGW64__)
  movaps %xmm6,  0x50(%REG_ARG1)
  movaps %xmm7,  0x60(%REG_ARG1)
  movaps %xmm8,  0x70(%REG_ARG1)
  movaps %xmm9,  0x80(%REG_ARG1)
  movaps %xmm10, 0x90(%REG_ARG1)
  movaps %xmm11, 0xA0(%REG_ARG1)
  movaps %xmm12, 0xB0(%REG_ARG1)
  movaps %xmm13, 0xC0(%REG_ARG1)
  movaps %xmm14, 0xD0(%REG_ARG1)
  movaps %xmm15, 0xE0(%REG_ARG1)
#endif
  xor   %rax, %rax            # always return 0
  ret


narch_longjmp:
  add   $0x10, %REG_ARG1      # 16-byte alignment
  and   $-0x10, %REG_ARG1     #
  mov   %REG_ARG2, %rax       # val will be longjmp return
  test  %rax, %rax
  jnz   narch_longjmp_1
  inc   %rax                  # if val==0, val=1 per longjmp semantics
narch_longjmp_1:
  mov   0x00(%REG_ARG1), %rbx # jmp_buf, restore regs from it
  mov   0x08(%REG_ARG1), %rbp
  mov   0x10(%REG_ARG1), %r12
  mov   0x18(%REG_ARG1), %r13
  mov   0x20(%REG_ARG1), %r14
  mov   0x28(%REG_ARG1), %r15
  mov   0x30(%REG_ARG1), %rsp # this ends up being the stack pointer
  mov   0x38(%REG_ARG1), %rdx # this is the instruction pointer
  mov   0x40(%REG_ARG1), %rsi
  mov   0x48(%REG_ARG1), %rdi
#if defined(__MINGW32__) || defined(__MINGW64__)
  movaps 0x50(%REG_ARG1), %xmm6
  movaps 0x60(%REG_ARG1), %xmm7
  movaps 0x70(%REG_ARG1), %xmm8
  movaps 0x80(%REG_ARG1), %xmm9
  movaps 0x90(%REG_ARG1), %xmm10
  movaps 0xA0(%REG_ARG1), %xmm11
  movaps 0xB0(%REG_ARG1), %xmm12
  movaps 0xC0(%REG_ARG1), %xmm13
  movaps 0xD0(%REG_ARG1), %xmm14
  movaps 0xE0(%REG_ARG1), %xmm15
#endif
  jmp  *%rdx                  # goto saved address without altering rsp
"># template names. #html_additional_pages = {} # If false, no module index is generated. #html_domain_indices = True # If false, no index is generated. #html_use_index = True # If true, the index is split into individual pages for each letter. #html_split_index = False # If true, links to the reST sources are added to the pages. html_show_sourcelink = False # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. html_show_sphinx = False # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. html_show_copyright = False # If true, an OpenSearch description file will be output, and all pages will # contain a <link> tag referring to it. The value of this option must be the # base URL from which the finished HTML is served. #html_use_opensearch = '' # This is the file name suffix for HTML files (e.g. ".xhtml"). #html_file_suffix = None # Language to be used for generating the HTML full-text search index. # Sphinx supports the following languages: # 'da', 'de', 'en', 'es', 'fi', 'fr', 'hu', 'it', 'ja' # 'nl', 'no', 'pt', 'ro', 'ru', 'sv', 'tr' #html_search_language = 'en' # A dictionary with options for the search language support, empty by default. # Now only 'ja' uses this config value #html_search_options = {'type': 'default'} # The name of a javascript file (relative to the configuration directory) that # implements a search results scorer. If empty, the default will be used. #html_search_scorer = 'scorer.js' # Output file base name for HTML help builder. htmlhelp_basename = 'ProfanityPythonPluginsAPIdoc' # -- Options for LaTeX output --------------------------------------------- latex_elements = { # The paper size ('letterpaper' or 'a4paper'). #'papersize': 'letterpaper', # The font size ('10pt', '11pt' or '12pt'). #'pointsize': '10pt', # Additional stuff for the LaTeX preamble. #'preamble': '', # Latex figure (float) alignment #'figure_align': 'htbp', } # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ (master_doc, 'ProfanityPythonPluginsAPI.tex', u'Profanity Python Plugins API Documentation', u'boothj5', 'manual'), ] # The name of an image file (relative to this directory) to place at the top of # the title page. #latex_logo = None # For "manual" documents, if this is true, then toplevel headings are parts, # not chapters. #latex_use_parts = False # If true, show page references after internal links. #latex_show_pagerefs = False # If true, show URL addresses after external links. #latex_show_urls = False # Documents to append as an appendix to all manuals. #latex_appendices = [] # If false, no module index is generated. #latex_domain_indices = True # -- Options for manual page output --------------------------------------- # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ (master_doc, 'profanitypythonpluginsapi', u'Profanity Python Plugins API Documentation', [author], 1) ] # If true, show URL addresses after external links. #man_show_urls = False # -- Options for Texinfo output ------------------------------------------- # Grouping the document tree into Texinfo files. List of tuples # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ (master_doc, 'ProfanityPythonPluginsAPI', u'Profanity Python Plugins API Documentation', author, 'ProfanityPythonPluginsAPI', 'One line description of project.', 'Miscellaneous'), ] # Documents to append as an appendix to all manuals. #texinfo_appendices = [] # If false, no module index is generated. #texinfo_domain_indices = True # How to display URL addresses: 'footnote', 'no', or 'inline'. #texinfo_show_urls = 'footnote' # If true, do not generate a @detailmenu in the "Top" node's menu. #texinfo_no_detailmenu = False