2 ; Written by Walter Bright
4 ; http://www.digitalmars.com/d/
5 ; Placed into the Public Domain
15 ; Provide a default resolution for weak extern records, no way in C
16 ; to define an omf symbol with a specific value
20 extrn __moduleinfo_array:near
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:
34 ; FM contains all the pointers
36 ; and finding the limits of FM is as easy as taking the address of FMB
37 ; and the address of FME.
39 ; These segments bracket FM, which contains the list of ModuleInfo pointers
40 FMB segment dword use32 public 'DATA'
42 FM segment dword use32 public 'DATA'
44 FME segment dword use32 public 'DATA'
47 ; This leaves room in the _fatexit() list for _moduleDtor()
48 XOB segment dword use32 public 'BSS'
50 XO segment dword use32 public 'BSS'
53 XOE segment dword use32 public 'BSS'
56 DGROUP group FMB,FM,FME
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;
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