www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - [Help!] Use two different assembly symbol in D, but they are same

reply lili <akozhao tencent.com> writes:
Hi:
   definition _vga_x and _vga_y symbol in asm, compile use nasm -f 
elf64 -o boot.o boot.asm
   [section .bss]
     ...

   [global _vga_x]
   _vga_x:
           resb 8
   [global _vga_y]
   _vga_y:
           resb 8


   and nm boot.o show below
     ...
    00107000 B _vga_x
    00107008 B _vga_y

  and In another D file use this two symbol

extern(C) {
  extern __gshared int _vga_x; //definition in boot.asm
  extern __gshared int _vga_y; //definition in boot.asm
}

  void tt()
  {
     if (_vga_x == _vga_y)
       //where is true, why?
  }

  but when a run tt so strange things happend that the test is 
true.
  Is where has a coding mistake.
  src  https://github.com/lilijreey/OS-D
Aug 24 2019
parent reply a11e99z <black80 bk.ru> writes:
On Saturday, 24 August 2019 at 11:53:01 UTC, lili wrote:
 Hi:
   definition _vga_x and _vga_y symbol in asm, compile use nasm 
 -f elf64 -o boot.o boot.asm
   [section .bss]
     ...

   [global _vga_x]
   _vga_x:
           resb 8
   [global _vga_y]
   _vga_y:
           resb 8


   and nm boot.o show below
     ...
    00107000 B _vga_x
    00107008 B _vga_y

  and In another D file use this two symbol

 extern(C) {
  extern __gshared int _vga_x; //definition in boot.asm
  extern __gshared int _vga_y; //definition in boot.asm
 }

  void tt()
  {
     if (_vga_x == _vga_y)
       //where is true, why?
  }

  but when a run tt so strange things happend that the test is 
 true.
  Is where has a coding mistake.
  src  https://github.com/lilijreey/OS-D
resb 8 just reserving 8 bytes not initializing it. probably u compare some garbage. sometimes it equals, sometimes not. no?
Aug 24 2019
parent reply lili <akozhao tencent.com> writes:
On Saturday, 24 August 2019 at 12:09:19 UTC, a11e99z wrote:
 On Saturday, 24 August 2019 at 11:53:01 UTC, lili wrote:
  [...]
resb 8 just reserving 8 bytes not initializing it. probably u compare some garbage. sometimes it equals, sometimes not. no?
I write wrong, not if (_vga_x == _vga_y) but if (&_vga_x == &_vga_y)
Aug 24 2019
parent reply a11e99z <black80 bk.ru> writes:
On Saturday, 24 August 2019 at 12:16:34 UTC, lili wrote:
 On Saturday, 24 August 2019 at 12:09:19 UTC, a11e99z wrote:
 On Saturday, 24 August 2019 at 11:53:01 UTC, lili wrote:
  [...]
resb 8 just reserving 8 bytes not initializing it. probably u compare some garbage. sometimes it equals, sometimes not. no?
I write wrong, not if (_vga_x == _vga_y) but if (&_vga_x == &_vga_y)
try to do next: add funtion in asm that returns real addresses to vga_x,y extern(C) void asmVgas( int** px, int** py) call it int *px, *py; asmVgas( &px, &py); writefln( "%s=%s,%s=%s",px, &_vga_x,py, &_vga_y); and see result
Aug 24 2019
parent reply lili <akozhao tencent.com> writes:
On Saturday, 24 August 2019 at 12:55:57 UTC, a11e99z wrote:
 On Saturday, 24 August 2019 at 12:16:34 UTC, lili wrote:
 On Saturday, 24 August 2019 at 12:09:19 UTC, a11e99z wrote:
 On Saturday, 24 August 2019 at 11:53:01 UTC, lili wrote:
  [...]
resb 8 just reserving 8 bytes not initializing it. probably u compare some garbage. sometimes it equals, sometimes not. no?
I write wrong, not if (_vga_x == _vga_y) but if (&_vga_x == &_vga_y)
try to do next: add funtion in asm that returns real addresses to vga_x,y extern(C) void asmVgas( int** px, int** py) call it int *px, *py; asmVgas( &px, &py); writefln( "%s=%s,%s=%s",px, &_vga_x,py, &_vga_y); and see result
I followed your suggest, call asm_fn in d function. it return address not 0 but is a correct address same as the var address show in link map file. when a try define a __shared int xx, the &xx also 0. after linked all variables address is 0 that in .bss segment. do you know why occur this? [global asm_fn] asm_fn: mov rax, p2_table ret
Aug 25 2019
parent reply a11e99z <black80 bk.ru> writes:
On Sunday, 25 August 2019 at 13:24:57 UTC, lili wrote:
 On Saturday, 24 August 2019 at 12:55:57 UTC, a11e99z wrote:
 On Saturday, 24 August 2019 at 12:16:34 UTC, lili wrote:
 On Saturday, 24 August 2019 at 12:09:19 UTC, a11e99z wrote:
 On Saturday, 24 August 2019 at 11:53:01 UTC, lili wrote:
  [...]
resb 8 just reserving 8 bytes not initializing it. probably u compare some garbage. sometimes it equals, sometimes not. no?
I write wrong, not if (_vga_x == _vga_y) but if (&_vga_x == &_vga_y)
try to do next: add funtion in asm that returns real addresses to vga_x,y extern(C) void asmVgas( int** px, int** py) call it int *px, *py; asmVgas( &px, &py); writefln( "%s=%s,%s=%s",px, &_vga_x,py, &_vga_y); and see result
I followed your suggest, call asm_fn in d function. it return address not 0 but is a correct address same as the var address show in link map file. when a try define a __shared int xx, the &xx also 0. after linked all variables address is 0 that in .bss segment. do you know why occur this? [global asm_fn] asm_fn: mov rax, p2_table ret
no idea. u can to define _vga_x,_vga_y in D code and export it to asm (vice versa than now). see result again. in case still not working: make very simple app with global vars: 2 D-files OR 1 D-file and 1 asm-file (maybe its not working even for D+D files). try to get same bug from compiler/linker. fill the issue and attach both files as sample. add point (for case D+asm) "how to compile asm file for linking with D" as u did. then wait and hope.
Aug 25 2019
parent a11e99z <black80 bk.ru> writes:
On Sunday, 25 August 2019 at 13:43:42 UTC, a11e99z wrote:
 On Sunday, 25 August 2019 at 13:24:57 UTC, lili wrote:
 On Saturday, 24 August 2019 at 12:55:57 UTC, a11e99z wrote:
and try to use any compiler DMD/LDC/GDC. maybe result will be that u want.
Aug 25 2019