xref: /aosp_15_r20/external/boringssl/src/crypto/perlasm/readme (revision 8fb009dc861624b67b6cdb62ea21f0f22d0c584b)
1*8fb009dcSAndroid Build Coastguard WorkerThe perl scripts in this directory are my 'hack' to generate
2*8fb009dcSAndroid Build Coastguard Workermultiple different assembler formats via the one origional script.
3*8fb009dcSAndroid Build Coastguard Worker
4*8fb009dcSAndroid Build Coastguard WorkerThe way to use this library is to start with adding the path to this directory
5*8fb009dcSAndroid Build Coastguard Workerand then include it.
6*8fb009dcSAndroid Build Coastguard Worker
7*8fb009dcSAndroid Build Coastguard Workerpush(@INC,"perlasm","../../perlasm");
8*8fb009dcSAndroid Build Coastguard Workerrequire "x86asm.pl";
9*8fb009dcSAndroid Build Coastguard Worker
10*8fb009dcSAndroid Build Coastguard WorkerThe first thing we do is setup the file and type of assembler
11*8fb009dcSAndroid Build Coastguard Worker
12*8fb009dcSAndroid Build Coastguard Worker&asm_init($ARGV[0]);
13*8fb009dcSAndroid Build Coastguard Worker
14*8fb009dcSAndroid Build Coastguard WorkerThe first argument is the 'type'.  Currently
15*8fb009dcSAndroid Build Coastguard Worker'cpp', 'sol', 'a.out', 'elf' or 'win32'.
16*8fb009dcSAndroid Build Coastguard WorkerArgument 2 is the file name.
17*8fb009dcSAndroid Build Coastguard Worker
18*8fb009dcSAndroid Build Coastguard WorkerThe reciprocal function is
19*8fb009dcSAndroid Build Coastguard Worker&asm_finish() which should be called at the end.
20*8fb009dcSAndroid Build Coastguard Worker
21*8fb009dcSAndroid Build Coastguard WorkerThere are 2 main 'packages'. x86ms.pl, which is the Microsoft assembler,
22*8fb009dcSAndroid Build Coastguard Workerand x86unix.pl which is the unix (gas) version.
23*8fb009dcSAndroid Build Coastguard Worker
24*8fb009dcSAndroid Build Coastguard WorkerFunctions of interest are:
25*8fb009dcSAndroid Build Coastguard Worker&external_label("des_SPtrans");	declare and external variable
26*8fb009dcSAndroid Build Coastguard Worker&LB(reg);			Low byte for a register
27*8fb009dcSAndroid Build Coastguard Worker&HB(reg);			High byte for a register
28*8fb009dcSAndroid Build Coastguard Worker&BP(off,base,index,scale)	Byte pointer addressing
29*8fb009dcSAndroid Build Coastguard Worker&DWP(off,base,index,scale)	Word pointer addressing
30*8fb009dcSAndroid Build Coastguard Worker&stack_push(num)		Basically a 'sub esp, num*4' with extra
31*8fb009dcSAndroid Build Coastguard Worker&stack_pop(num)			inverse of stack_push
32*8fb009dcSAndroid Build Coastguard Worker&function_begin(name,extra)	Start a function with pushing of
33*8fb009dcSAndroid Build Coastguard Worker				edi, esi, ebx and ebp.  extra is extra win32
34*8fb009dcSAndroid Build Coastguard Worker				external info that may be required.
35*8fb009dcSAndroid Build Coastguard Worker&function_begin_B(name,extra)	Same as normal function_begin but no pushing.
36*8fb009dcSAndroid Build Coastguard Worker&function_end(name)		Call at end of function.
37*8fb009dcSAndroid Build Coastguard Worker&function_end_A(name)		Standard pop and ret, for use inside functions
38*8fb009dcSAndroid Build Coastguard Worker&function_end_B(name)		Call at end but with poping or 'ret'.
39*8fb009dcSAndroid Build Coastguard Worker&swtmp(num)			Address on stack temp word.
40*8fb009dcSAndroid Build Coastguard Worker&wparam(num)			Parameter number num, that was push
41*8fb009dcSAndroid Build Coastguard Worker				in C convention.  This all works over pushes
42*8fb009dcSAndroid Build Coastguard Worker				and pops.
43*8fb009dcSAndroid Build Coastguard Worker&comment("hello there")		Put in a comment.
44*8fb009dcSAndroid Build Coastguard Worker&label("loop")			Refer to a label, normally a jmp target.
45*8fb009dcSAndroid Build Coastguard Worker&set_label("loop")		Set a label at this point.
46*8fb009dcSAndroid Build Coastguard Worker&data_word(word)		Put in a word of data.
47*8fb009dcSAndroid Build Coastguard Worker
48*8fb009dcSAndroid Build Coastguard WorkerSo how does this all hold together?  Given
49*8fb009dcSAndroid Build Coastguard Worker
50*8fb009dcSAndroid Build Coastguard Workerint calc(int len, int *data)
51*8fb009dcSAndroid Build Coastguard Worker	{
52*8fb009dcSAndroid Build Coastguard Worker	int i,j=0;
53*8fb009dcSAndroid Build Coastguard Worker
54*8fb009dcSAndroid Build Coastguard Worker	for (i=0; i<len; i++)
55*8fb009dcSAndroid Build Coastguard Worker		{
56*8fb009dcSAndroid Build Coastguard Worker		j+=other(data[i]);
57*8fb009dcSAndroid Build Coastguard Worker		}
58*8fb009dcSAndroid Build Coastguard Worker	}
59*8fb009dcSAndroid Build Coastguard Worker
60*8fb009dcSAndroid Build Coastguard WorkerSo a very simple version of this function could be coded as
61*8fb009dcSAndroid Build Coastguard Worker
62*8fb009dcSAndroid Build Coastguard Worker	push(@INC,"perlasm","../../perlasm");
63*8fb009dcSAndroid Build Coastguard Worker	require "x86asm.pl";
64*8fb009dcSAndroid Build Coastguard Worker
65*8fb009dcSAndroid Build Coastguard Worker	&asm_init($ARGV[0]);
66*8fb009dcSAndroid Build Coastguard Worker
67*8fb009dcSAndroid Build Coastguard Worker	&external_label("other");
68*8fb009dcSAndroid Build Coastguard Worker
69*8fb009dcSAndroid Build Coastguard Worker	$tmp1=	"eax";
70*8fb009dcSAndroid Build Coastguard Worker	$j=	"edi";
71*8fb009dcSAndroid Build Coastguard Worker	$data=	"esi";
72*8fb009dcSAndroid Build Coastguard Worker	$i=	"ebp";
73*8fb009dcSAndroid Build Coastguard Worker
74*8fb009dcSAndroid Build Coastguard Worker	&comment("a simple function");
75*8fb009dcSAndroid Build Coastguard Worker	&function_begin("calc");
76*8fb009dcSAndroid Build Coastguard Worker	&mov(	$data,		&wparam(1)); # data
77*8fb009dcSAndroid Build Coastguard Worker	&xor(	$j,		$j);
78*8fb009dcSAndroid Build Coastguard Worker	&xor(	$i,		$i);
79*8fb009dcSAndroid Build Coastguard Worker
80*8fb009dcSAndroid Build Coastguard Worker	&set_label("loop");
81*8fb009dcSAndroid Build Coastguard Worker	&cmp(	$i,		&wparam(0));
82*8fb009dcSAndroid Build Coastguard Worker	&jge(	&label("end"));
83*8fb009dcSAndroid Build Coastguard Worker
84*8fb009dcSAndroid Build Coastguard Worker	&mov(	$tmp1,		&DWP(0,$data,$i,4));
85*8fb009dcSAndroid Build Coastguard Worker	&push(	$tmp1);
86*8fb009dcSAndroid Build Coastguard Worker	&call(	"other");
87*8fb009dcSAndroid Build Coastguard Worker	&add(	$j,		"eax");
88*8fb009dcSAndroid Build Coastguard Worker	&pop(	$tmp1);
89*8fb009dcSAndroid Build Coastguard Worker	&inc(	$i);
90*8fb009dcSAndroid Build Coastguard Worker	&jmp(	&label("loop"));
91*8fb009dcSAndroid Build Coastguard Worker
92*8fb009dcSAndroid Build Coastguard Worker	&set_label("end");
93*8fb009dcSAndroid Build Coastguard Worker	&mov(	"eax",		$j);
94*8fb009dcSAndroid Build Coastguard Worker
95*8fb009dcSAndroid Build Coastguard Worker	&function_end("calc");
96*8fb009dcSAndroid Build Coastguard Worker
97*8fb009dcSAndroid Build Coastguard Worker	&asm_finish();
98*8fb009dcSAndroid Build Coastguard Worker
99*8fb009dcSAndroid Build Coastguard WorkerThe above example is very very unoptimised but gives an idea of how
100*8fb009dcSAndroid Build Coastguard Workerthings work.
101