2 ; Written by Walter Bright
\r
4 ; http://www.digitalmars.com/d/
\r
5 ; Placed into the Public Domain
\r
15 ; Provide a default resolution for weak extern records, no way in C
\r
16 ; to define an omf symbol with a specific value
\r
20 extrn __moduleinfo_array:near
\r
22 ; This bit of assembler is needed because, from C or D, one cannot
\r
23 ; specify the names of data segments. Why does this matter?
\r
24 ; All the ModuleInfo pointers are placed into a segment named 'FM'.
\r
25 ; The order in which they are placed in 'FM' is arbitrarily up to the linker.
\r
26 ; In order to walk all the pointers, we need to be able to find the
\r
27 ; beginning and the end of the 'FM' segment.
\r
28 ; This is done by bracketing the 'FM' segment with two other, empty,
\r
29 ; segments named 'FMB' and 'FME'. Since this module is the only one that
\r
30 ; ever refers to 'FMB' and 'FME', we get to control the order in which
\r
31 ; these segments appear relative to 'FM' by using a GROUP statement.
\r
32 ; So, we have in memory:
\r
34 ; FM contains all the pointers
\r
36 ; and finding the limits of FM is as easy as taking the address of FMB
\r
37 ; and the address of FME.
\r
39 ; These segments bracket FM, which contains the list of ModuleInfo pointers
\r
40 FMB segment dword use32 public 'DATA'
\r
42 FM segment dword use32 public 'DATA'
\r
44 FME segment dword use32 public 'DATA'
\r
47 ; This leaves room in the _fatexit() list for _moduleDtor()
\r
48 XOB segment dword use32 public 'BSS'
\r
50 XO segment dword use32 public 'BSS'
\r
53 XOE segment dword use32 public 'BSS'
\r
56 DGROUP group FMB,FM,FME
\r
60 ; extern (C) void _minit();
\r
61 ; Converts array of ModuleInfo pointers to a D dynamic array of them,
\r
62 ; so they can be accessed via D.
\r
63 ; Result is written to:
\r
64 ; extern (C) ModuleInfo[] _moduleinfo_array;
\r
68 mov EDX,offset DATAGRP:FMB
\r
69 mov EAX,offset DATAGRP:FME
\r
70 mov dword ptr __moduleinfo_array+4,EDX
\r
71 sub EAX,EDX ; size in bytes of FM segment
\r
72 shr EAX,2 ; convert to array length
\r
73 mov dword ptr __moduleinfo_array,EAX
\r