aboutsummaryrefslogtreecommitdiffstats
path: root/src/ortho/llvm4-nodebug/llvm-target.ads
blob: c5c89d84f913b687d72aa9fe338bfef1fee01bf5 (plain)
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
97
--  LLVM binding
--  Copyright (C) 2014 Tristan Gingold
--
--  GHDL is free software; you can redistribute it and/or modify it under
--  the terms of the GNU General Public License as published by the Free
--  Software Foundation; either version 2, or (at your option) any later
--  version.
--
--  GHDL is distributed in the hope that it will be useful, but WITHOUT ANY
--  WARRANTY; without even the implied warranty of MERCHANTABILITY or
--  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
--  for more details.
--
--  You should have received a copy of the GNU General Public License
--  along with GHDL; see the file COPYING.  If not, write to the Free
--  Software Foundation, 59 Temple Place - Suite 330, Boston, MA
--  02111-1307, USA.
with System;
with Interfaces; use Interfaces;
with Interfaces.C; use Interfaces.C;
with LLVM.Core; use LLVM.Core;

package LLVM.Target is

   type TargetDataRef is new System.Address;

   --  LLVMInitializeNativeTarget - The main program should call this function
   --  to initialize the native target corresponding to the host.  This is
   --  useful for JIT applications to ensure that the target gets linked in
   --  correctly.
   procedure InitializeNativeTarget;
   pragma Import (C, InitializeNativeTarget,
                  "LLVMInitializeNativeTarget_noinline");

   --  LLVMInitializeNativeTargetAsmPrinter - The main program should call this
   --  function to initialize the printer for the native target corresponding
   --  to the host.
   procedure InitializeNativeAsmPrinter;
   pragma Import (C, InitializeNativeAsmPrinter,
                  "LLVMInitializeNativeAsmPrinter_noinline");

   --  Target Data

   --  Obtain the data layout for a module.
   --  see Module::getDataLayout()
   function GetModuleDataLayout (M : ModuleRef) return TargetDataRef;
   pragma Import (C, GetModuleDataLayout, "LLVMGetModuleDataLayout");

   --  Set the data layout for a module.
   --  see Module::setDataLayout()
   procedure SetModuleDataLayout (M : ModuleRef; DL : TargetDataRef);
   pragma Import (C, SetModuleDataLayout, "LLVMSetModuleDataLayout");

   --  Creates target data from a target layout string.
   --  See the constructor llvm::DataLayout::DataLayout.
   function CreateTargetData (StringRep : Cstring) return TargetDataRef;
   pragma Import (C, CreateTargetData, "LLVMCreateTargetData");

   --  Removed in LLVM 3.9 !!
   --  Adds target data information to a pass manager. This does not take
   --  ownership of the target data.
   --  See the method llvm::PassManagerBase::add.
   procedure AddTargetData(TD : TargetDataRef; PM : PassManagerRef);
   pragma Import (C, AddTargetData, "LLVMAddTargetData");

   --  Converts target data to a target layout string. The string must be
   --  disposed with LLVMDisposeMessage.
   --  See the constructor llvm::DataLayout::DataLayout. */
   function CopyStringRepOfTargetData(TD :TargetDataRef) return Cstring;
   pragma Import (C, CopyStringRepOfTargetData,
                  "LLVMCopyStringRepOfTargetData");

   --  Returns the pointer size in bytes for a target.
   --  See the method llvm::DataLayout::getPointerSize.
   function PointerSize(TD : TargetDataRef) return unsigned;
   pragma Import (C, PointerSize, "LLVMPointerSize");

   --  Computes the ABI size of a type in bytes for a target.
   --  See the method llvm::DataLayout::getTypeAllocSize.
   function ABISizeOfType (TD : TargetDataRef; Ty: TypeRef) return Unsigned_64;
   pragma Import (C, ABISizeOfType, "LLVMABISizeOfType");

   --  Computes the ABI alignment of a type in bytes for a target.
   --  See the method llvm::DataLayout::getTypeABISize.
   function ABIAlignmentOfType (TD : TargetDataRef; Ty: TypeRef)
                               return Unsigned_32;
   pragma Import (C, ABIAlignmentOfType, "LLVMABIAlignmentOfType");

   --  Computes the byte offset of the indexed struct element for a target.
   --  See the method llvm::StructLayout::getElementContainingOffset.
   function OffsetOfElement(TD : TargetDataRef;
                            StructTy : TypeRef;
                            Element : Unsigned_32)
                           return Unsigned_64;
   pragma Import (C, OffsetOfElement, "LLVMOffsetOfElement");

end LLVM.Target;
n> struct evtchn_close close; printk("port %d still bound!\n", i); mask_evtchn(i); close.port = i; rc = HYPERVISOR_event_channel_op(EVTCHNOP_close, &close); if ( rc ) printk("WARN: close_port %s failed rc=%d. ignored\n", i, rc); clear_evtchn(i); } } vcpu_info->evtchn_upcall_pending = 0; vcpu_info->evtchn_pending_sel = 0; } /* * Demux events to different handlers. */ int do_event(evtchn_port_t port, struct pt_regs *regs) { ev_action_t *action; clear_evtchn(port); if ( port >= NR_EVS ) { printk("WARN: do_event(): Port number too large: %d\n", port); return 1; } action = &ev_actions[port]; action->count++; /* call the handler */ action->handler(port, regs, action->data); return 1; } evtchn_port_t bind_evtchn(evtchn_port_t port, evtchn_handler_t handler, void *data) { if ( ev_actions[port].handler != default_handler ) printk("WARN: Handler for port %d already registered, replacing\n", port); ev_actions[port].data = data; wmb(); ev_actions[port].handler = handler; set_bit(port, bound_ports); return port; } void unbind_evtchn(evtchn_port_t port ) { struct evtchn_close close; int rc; if ( ev_actions[port].handler == default_handler ) printk("WARN: No handler for port %d when unbinding\n", port); mask_evtchn(port); clear_evtchn(port); ev_actions[port].handler = default_handler; wmb(); ev_actions[port].data = NULL; clear_bit(port, bound_ports); close.port = port; rc = HYPERVISOR_event_channel_op(EVTCHNOP_close, &close); if ( rc ) printk("WARN: close_port %s failed rc=%d. ignored\n", port, rc); } evtchn_port_t bind_virq(uint32_t virq, evtchn_handler_t handler, void *data) { evtchn_bind_virq_t op; int rc; /* Try to bind the virq to a port */ op.virq = virq; op.vcpu = smp_processor_id(); if ( (rc = HYPERVISOR_event_channel_op(EVTCHNOP_bind_virq, &op)) != 0 ) { printk("Failed to bind virtual IRQ %d with rc=%d\n", virq, rc); return -1; } bind_evtchn(op.port, handler, data); return op.port; } evtchn_port_t bind_pirq(uint32_t pirq, int will_share, evtchn_handler_t handler, void *data) { evtchn_bind_pirq_t op; int rc; /* Try to bind the pirq to a port */ op.pirq = pirq; op.flags = will_share ? BIND_PIRQ__WILL_SHARE : 0; if ( (rc = HYPERVISOR_event_channel_op(EVTCHNOP_bind_pirq, &op)) != 0 ) { printk("Failed to bind physical IRQ %d with rc=%d\n", pirq, rc); return -1; } bind_evtchn(op.port, handler, data); return op.port; } #if defined(__x86_64__) char irqstack[2 * STACK_SIZE]; static struct pda { int irqcount; /* offset 0 (used in x86_64.S) */ char *irqstackptr; /* 8 */ } cpu0_pda; #endif /* * Initially all events are without a handler and disabled */ void init_events(void) { int i; #if defined(__x86_64__) asm volatile("movl %0,%%fs ; movl %0,%%gs" :: "r" (0)); wrmsrl(0xc0000101, &cpu0_pda); /* 0xc0000101 is MSR_GS_BASE */ cpu0_pda.irqcount = -1; cpu0_pda.irqstackptr = (void*) (((unsigned long)irqstack + 2 * STACK_SIZE) & ~(STACK_SIZE - 1)); #endif /* initialize event handler */ for ( i = 0; i < NR_EVS; i++ ) { ev_actions[i].handler = default_handler; mask_evtchn(i); } } void fini_events(void) { /* Dealloc all events */ unbind_all_ports(); #if defined(__x86_64__) wrmsrl(0xc0000101, NULL); /* 0xc0000101 is MSR_GS_BASE */ #endif } void default_handler(evtchn_port_t port, struct pt_regs *regs, void *ignore) { printk("[Port %d] - event received\n", port); } /* Create a port available to the pal for exchanging notifications. Returns the result of the hypervisor call. */ /* Unfortunate confusion of terminology: the port is unbound as far as Xen is concerned, but we automatically bind a handler to it from inside mini-os. */ int evtchn_alloc_unbound(domid_t pal, evtchn_handler_t handler, void *data, evtchn_port_t *port) { int rc; evtchn_alloc_unbound_t op; op.dom = DOMID_SELF; op.remote_dom = pal; rc = HYPERVISOR_event_channel_op(EVTCHNOP_alloc_unbound, &op); if ( rc ) { printk("ERROR: alloc_unbound failed with rc=%d", rc); return rc; } *port = bind_evtchn(op.port, handler, data); return rc; } /* Connect to a port so as to allow the exchange of notifications with the pal. Returns the result of the hypervisor call. */ int evtchn_bind_interdomain(domid_t pal, evtchn_port_t remote_port, evtchn_handler_t handler, void *data, evtchn_port_t *local_port) { int rc; evtchn_port_t port; evtchn_bind_interdomain_t op; op.remote_dom = pal; op.remote_port = remote_port; rc = HYPERVISOR_event_channel_op(EVTCHNOP_bind_interdomain, &op); if ( rc ) { printk("ERROR: bind_interdomain failed with rc=%d", rc); return rc; } port = op.local_port; *local_port = bind_evtchn(port, handler, data); return rc; } /* * Local variables: * mode: C * c-file-style: "BSD" * c-basic-offset: 4 * tab-width: 4 * indent-tabs-mode: nil * End: */