comparison druntime/src/compiler/dmd/minit.asm @ 759:d3eb054172f9

Added copy of druntime from DMD 2.020 modified for LDC.
author Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
date Tue, 11 Nov 2008 01:52:37 +0100
parents
children
comparison
equal deleted inserted replaced
758:f04dde6e882c 759:d3eb054172f9
1 ;_ minit.asm
2 ; Written by Walter Bright
3 ; Digital Mars
4 ; http://www.digitalmars.com/d/
5 ; Placed into the Public Domain
6
7 include macros.asm
8
9 ifdef _WIN32
10 DATAGRP EQU FLAT
11 else
12 DATAGRP EQU DGROUP
13 endif
14
15 ; Provide a default resolution for weak extern records, no way in C
16 ; to define an omf symbol with a specific value
17 public __nullext
18 __nullext equ 0
19
20 extrn __moduleinfo_array:near
21
22 ; This bit of assembler is needed because, from C or D, one cannot
23 ; specify the names of data segments. Why does this matter?
24 ; All the ModuleInfo pointers are placed into a segment named 'FM'.
25 ; The order in which they are placed in 'FM' is arbitrarily up to the linker.
26 ; In order to walk all the pointers, we need to be able to find the
27 ; beginning and the end of the 'FM' segment.
28 ; This is done by bracketing the 'FM' segment with two other, empty,
29 ; segments named 'FMB' and 'FME'. Since this module is the only one that
30 ; ever refers to 'FMB' and 'FME', we get to control the order in which
31 ; these segments appear relative to 'FM' by using a GROUP statement.
32 ; So, we have in memory:
33 ; FMB empty segment
34 ; FM contains all the pointers
35 ; FME empty segment
36 ; and finding the limits of FM is as easy as taking the address of FMB
37 ; and the address of FME.
38
39 ; These segments bracket FM, which contains the list of ModuleInfo pointers
40 FMB segment dword use32 public 'DATA'
41 FMB ends
42 FM segment dword use32 public 'DATA'
43 FM ends
44 FME segment dword use32 public 'DATA'
45 FME ends
46
47 ; This leaves room in the _fatexit() list for _moduleDtor()
48 XOB segment dword use32 public 'BSS'
49 XOB ends
50 XO segment dword use32 public 'BSS'
51 dd ?
52 XO ends
53 XOE segment dword use32 public 'BSS'
54 XOE ends
55
56 DGROUP group FMB,FM,FME
57
58 begcode minit
59
60 ; extern (C) void _minit();
61 ; Converts array of ModuleInfo pointers to a D dynamic array of them,
62 ; so they can be accessed via D.
63 ; Result is written to:
64 ; extern (C) ModuleInfo[] _moduleinfo_array;
65
66 public __minit
67 __minit proc near
68 mov EDX,offset DATAGRP:FMB
69 mov EAX,offset DATAGRP:FME
70 mov dword ptr __moduleinfo_array+4,EDX
71 sub EAX,EDX ; size in bytes of FM segment
72 shr EAX,2 ; convert to array length
73 mov dword ptr __moduleinfo_array,EAX
74 ret
75 __minit endp
76
77 endcode minit
78
79 end