Star InactiveStar InactiveStar InactiveStar InactiveStar Inactive
 
%ifndef _got_inc_
%ifndef _got_inc_
%define _got_inc_

;stack at the end of the prologue:
; return address
; rbx old
; rbp old

extern  _GLOBAL_OFFSET_TABLE_

%macro prologue 0
	push    rbp
	mov     rbp,rsp
	push    rbx
	call    .get_GOT
.get_GOT:
	pop     rbx
	add     rbx,_GLOBAL_OFFSET_TABLE_+$$-.get_GOT wrt ..gotpc
%endmacro

%macro epilogue 0
	mov		rbx,[rbp-8]
	mov		rsp,rbp
	pop		rbp
	ret
%endmacro

%macro proc 1
	global	%1:function
%1:
	prologue
%endmacro

; macro to end the procedure
%macro endp 1
	epilogue
%endmacro

;macro global data
;use: globaldata name,type,content
;to access the global variable
;mov		rax,qword [rbx + global_var wrt ..got]		;memory address to global_var
;mov		rax,[rax]									;value of global_var

%macro globaldata 3
	global    %1:data (%1.end - %1)
	section   .data
		%1:	%2	%3
		%1.end:
%endmacro

%endif 		;; got.inc