Mercurial > projects > ldc
comparison druntime/src/compiler/ldc/minit.asm @ 1458:e0b2d67cfe7c
Added druntime (this should be removed once it works).
author | Robert Clipsham <robert@octarineparrot.com> |
---|---|
date | Tue, 02 Jun 2009 17:43:06 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1456:7b218ec1044f | 1458:e0b2d67cfe7c |
---|---|
1 ;_ minit.asm | |
2 ; Module initialization support. | |
3 ; | |
4 ; Copyright: Copyright Digital Mars 2000 - 2009. | |
5 ; License: <a href="http://www.boost.org/LICENSE_1_0.txt>Boost License 1.0</a>. | |
6 ; Authors: Walter Bright | |
7 ; | |
8 ; Copyright Digital Mars 2000 - 2009. | |
9 ; Distributed under the Boost Software License, Version 1.0. | |
10 ; (See accompanying file LICENSE_1_0.txt or copy at | |
11 ; http://www.boost.org/LICENSE_1_0.txt) | |
12 ; | |
13 include macros.asm | |
14 | |
15 ifdef _WIN32 | |
16 DATAGRP EQU FLAT | |
17 else | |
18 DATAGRP EQU DGROUP | |
19 endif | |
20 | |
21 ; Provide a default resolution for weak extern records, no way in C | |
22 ; to define an omf symbol with a specific value | |
23 public __nullext | |
24 __nullext equ 0 | |
25 | |
26 extrn __moduleinfo_array:near | |
27 | |
28 ; This bit of assembler is needed because, from C or D, one cannot | |
29 ; specify the names of data segments. Why does this matter? | |
30 ; All the ModuleInfo pointers are placed into a segment named 'FM'. | |
31 ; The order in which they are placed in 'FM' is arbitrarily up to the linker. | |
32 ; In order to walk all the pointers, we need to be able to find the | |
33 ; beginning and the end of the 'FM' segment. | |
34 ; This is done by bracketing the 'FM' segment with two other, empty, | |
35 ; segments named 'FMB' and 'FME'. Since this module is the only one that | |
36 ; ever refers to 'FMB' and 'FME', we get to control the order in which | |
37 ; these segments appear relative to 'FM' by using a GROUP statement. | |
38 ; So, we have in memory: | |
39 ; FMB empty segment | |
40 ; FM contains all the pointers | |
41 ; FME empty segment | |
42 ; and finding the limits of FM is as easy as taking the address of FMB | |
43 ; and the address of FME. | |
44 | |
45 ; These segments bracket FM, which contains the list of ModuleInfo pointers | |
46 FMB segment dword use32 public 'DATA' | |
47 FMB ends | |
48 FM segment dword use32 public 'DATA' | |
49 FM ends | |
50 FME segment dword use32 public 'DATA' | |
51 FME ends | |
52 | |
53 ; This leaves room in the _fatexit() list for _moduleDtor() | |
54 XOB segment dword use32 public 'BSS' | |
55 XOB ends | |
56 XO segment dword use32 public 'BSS' | |
57 dd ? | |
58 XO ends | |
59 XOE segment dword use32 public 'BSS' | |
60 XOE ends | |
61 | |
62 DGROUP group FMB,FM,FME | |
63 | |
64 begcode minit | |
65 | |
66 ; extern (C) void _minit(); | |
67 ; Converts array of ModuleInfo pointers to a D dynamic array of them, | |
68 ; so they can be accessed via D. | |
69 ; Result is written to: | |
70 ; extern (C) ModuleInfo[] _moduleinfo_array; | |
71 | |
72 public __minit | |
73 __minit proc near | |
74 mov EDX,offset DATAGRP:FMB | |
75 mov EAX,offset DATAGRP:FME | |
76 mov dword ptr __moduleinfo_array+4,EDX | |
77 sub EAX,EDX ; size in bytes of FM segment | |
78 shr EAX,2 ; convert to array length | |
79 mov dword ptr __moduleinfo_array,EAX | |
80 ret | |
81 __minit endp | |
82 | |
83 endcode minit | |
84 | |
85 end |