]> gitweb.factorcode.org Git - factor.git/blob - basis/bootstrap/assembler/arm.64.unix.factor
4f4fe7d1b94f80820c9bb0b10016ccd34dff0a72
[factor.git] / basis / bootstrap / assembler / arm.64.unix.factor
1 ! Copyright (C) 2020 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: cpu.arm.assembler cpu.arm.assembler.opcodes kernel layouts
4 parser sequences ;
5 IN: bootstrap.assembler.arm
6
7 ! Stack frame
8 ! https://docs.microsoft.com/en-us/cpp/build/arm64-exception-handling?view=vs-2019
9
10
11 ! x0    Volatile        Parameter/scratch register 1, result register
12 ! x1-x7 Volatile        Parameter/scratch register 2-8
13 ! x8-x15        Volatile        Scratch registers
14 ! x16-x17       Volatile        Intra-procedure-call scratch registers
15 ! x18   Non-volatile    Platform register: in kernel mode, points to KPCR for the current processor;
16 !   in user mode, points to TEB
17 ! x19-x28       Non-volatile    Scratch registers
18 ! x29/fp        Non-volatile    Frame pointer
19 ! x30/lr        Non-volatile    Link registers
20
21
22 : stack-frame-size ( -- n ) 4 bootstrap-cells ;
23 : volatile-regs ( -- seq ) { X0 X1 X2 X3 X4 X5 X6 X7 X8 X9 X10 X11 X12 X13 X14 X15 X16 X17 } ;
24 : nv-regs ( -- seq ) { X18 X19 X20 X21 X22 X23 X24 X25 X26 X27 X28 X29 X30 } ;
25
26
27 ! callee-save = non-volatile aka call-preserved
28
29 ! x30 is the link register (used to return from subroutines)
30 ! x29 is the frame register
31 ! x19 to x29 are callee-saved
32 ! x18 is the 'platform register', used for some operating-system-specific special purpose,
33 !   or an additional caller-saved register
34 ! x16 and x17 are the Intra-Procedure-call scratch register
35 ! x9 to x15: used to hold local variables (caller saved)
36 ! x8: used to hold indirect return value address
37 ! x0 to x7: used to hold argument values passed to a subroutine, and also hold
38 !   results returned from a subroutine
39
40
41 ! https://en.wikichip.org/wiki/arm/aarch64
42 ! Generally, X0 through X18 can corrupt while X19-X29 must be preserved
43 ! Register   Role    Requirement
44 ! X0 -  X7   Parameter/result registers   Can Corrupt
45 ! X8         Indirect result location register
46 ! X9 -  X15  Temporary registers
47 ! X16 - X17  Intra-procedure call temporary
48 ! X18        Platform register, otherwise temporary
49
50 ! X19 - X29    Callee-saved register    Must preserve
51 ! X30    Link Register    Can Corrupt
52
53 : arg1 ( -- reg ) X0 ;
54 : arg2 ( -- reg ) X1 ;
55 : arg3 ( -- reg ) X2 ;
56 : arg4 ( -- reg ) X3 ;
57 : red-zone-size ( -- n ) 16 ;
58
59 << "vocab:bootstrap/assembler/arm.unix.factor" parse-file suffix! >> call
60 << "vocab:bootstrap/assembler/arm.64.factor" parse-file suffix! >> call
61 << "vocab:bootstrap/assembler/arm.factor" parse-file suffix! >> call