boot2

Playing with the boostrap
git clone https://git.ryansepassi.com/git/boot2.git
Log | Files | Refs | README

P1.M1pp (4123B)


      1 # P1.M1M -- portable P1 macro front-end.
      2 #
      3 # This file assumes an arch-specific backend M1M has already been prepended.
      4 # The backend must provide the target hooks used below:
      5 #   %p1_li, %p1_la, %p1_labr, %p1_mov, %p1_rrr, %p1_addi, %p1_logi,
      6 #   %p1_shifti, %p1_mem, %p1_ldarg, %p1_b, %p1_br, %p1_call, %p1_callr,
      7 #   %p1_ret, %p1_eret, %p1_tail, %p1_tailr, %p1_condb, %p1_condbz,
      8 #   %p1_enter, %p1_syscall, and %p1_sys_*.
      9 
     10 # ---- Materialization ------------------------------------------------------
     11 
     12 %macro li(rd, imm)
     13 %p1_li(rd, imm)
     14 %endm
     15 
     16 %macro la(rd, target)
     17 %p1_la(rd)
     18 target
     19 %endm
     20 
     21 # ---- Moves ----------------------------------------------------------------
     22 
     23 %macro mov(rd, rs)
     24 %p1_mov(rd, rs)
     25 %endm
     26 
     27 # ---- Register arithmetic --------------------------------------------------
     28 
     29 %macro add(rd, ra, rb)
     30 %p1_rrr(ADD, rd, ra, rb)
     31 %endm
     32 
     33 %macro sub(rd, ra, rb)
     34 %p1_rrr(SUB, rd, ra, rb)
     35 %endm
     36 
     37 %macro and(rd, ra, rb)
     38 %p1_rrr(AND, rd, ra, rb)
     39 %endm
     40 
     41 %macro or(rd, ra, rb)
     42 %p1_rrr(OR, rd, ra, rb)
     43 %endm
     44 
     45 %macro xor(rd, ra, rb)
     46 %p1_rrr(XOR, rd, ra, rb)
     47 %endm
     48 
     49 %macro shl(rd, ra, rb)
     50 %p1_rrr(SHL, rd, ra, rb)
     51 %endm
     52 
     53 %macro shr(rd, ra, rb)
     54 %p1_rrr(SHR, rd, ra, rb)
     55 %endm
     56 
     57 %macro sar(rd, ra, rb)
     58 %p1_rrr(SAR, rd, ra, rb)
     59 %endm
     60 
     61 %macro mul(rd, ra, rb)
     62 %p1_rrr(MUL, rd, ra, rb)
     63 %endm
     64 
     65 %macro div(rd, ra, rb)
     66 %p1_rrr(DIV, rd, ra, rb)
     67 %endm
     68 
     69 %macro rem(rd, ra, rb)
     70 %p1_rrr(REM, rd, ra, rb)
     71 %endm
     72 
     73 # ---- Immediate arithmetic -------------------------------------------------
     74 
     75 %macro addi(rd, ra, imm)
     76 %p1_addi(rd, ra, imm)
     77 %endm
     78 
     79 %macro andi(rd, ra, imm)
     80 %p1_logi(ANDI, rd, ra, imm)
     81 %endm
     82 
     83 %macro ori(rd, ra, imm)
     84 %p1_logi(ORI, rd, ra, imm)
     85 %endm
     86 
     87 %macro shli(rd, ra, imm)
     88 %p1_shifti(SHLI, rd, ra, imm)
     89 %endm
     90 
     91 %macro shri(rd, ra, imm)
     92 %p1_shifti(SHRI, rd, ra, imm)
     93 %endm
     94 
     95 %macro sari(rd, ra, imm)
     96 %p1_shifti(SARI, rd, ra, imm)
     97 %endm
     98 
     99 # ---- Memory and ABI access ------------------------------------------------
    100 
    101 %macro ld(rt, rn, off)
    102 %p1_mem(LD, rt, rn, off)
    103 %endm
    104 
    105 %macro st(rt, rn, off)
    106 %p1_mem(ST, rt, rn, off)
    107 %endm
    108 
    109 %macro lb(rt, rn, off)
    110 %p1_mem(LB, rt, rn, off)
    111 %endm
    112 
    113 %macro sb(rt, rn, off)
    114 %p1_mem(SB, rt, rn, off)
    115 %endm
    116 
    117 %macro ldarg(rd, slot)
    118 %p1_ldarg(rd, slot)
    119 %endm
    120 
    121 # ---- Branching ------------------------------------------------------------
    122 
    123 %macro b(target)
    124 %p1_labr
    125 target
    126 %p1_b
    127 %endm
    128 
    129 %macro br(rs)
    130 %p1_br(rs)
    131 %endm
    132 
    133 %macro beq(ra, rb, target)
    134 %p1_labr
    135 target
    136 %p1_condb(BEQ, ra, rb)
    137 %endm
    138 
    139 %macro bne(ra, rb, target)
    140 %p1_labr
    141 target
    142 %p1_condb(BNE, ra, rb)
    143 %endm
    144 
    145 %macro blt(ra, rb, target)
    146 %p1_labr
    147 target
    148 %p1_condb(BLT, ra, rb)
    149 %endm
    150 
    151 %macro bltu(ra, rb, target)
    152 %p1_labr
    153 target
    154 %p1_condb(BLTU, ra, rb)
    155 %endm
    156 
    157 %macro beqz(ra, target)
    158 %p1_labr
    159 target
    160 %p1_condbz(BEQZ, ra)
    161 %endm
    162 
    163 %macro bnez(ra, target)
    164 %p1_labr
    165 target
    166 %p1_condbz(BNEZ, ra)
    167 %endm
    168 
    169 %macro bltz(ra, target)
    170 %p1_labr
    171 target
    172 %p1_condbz(BLTZ, ra)
    173 %endm
    174 
    175 # ---- Calls, returns, and frames ------------------------------------------
    176 
    177 %macro call(target)
    178 %p1_labr
    179 target
    180 %p1_call
    181 %endm
    182 
    183 %macro callr(rs)
    184 %p1_callr(rs)
    185 %endm
    186 
    187 %macro ret()
    188 %p1_ret
    189 %endm
    190 
    191 %macro tail(target)
    192 %p1_labr
    193 target
    194 %p1_tail
    195 %endm
    196 
    197 %macro tailr(rs)
    198 %p1_tailr(rs)
    199 %endm
    200 
    201 %macro enter(size)
    202 %p1_enter(size)
    203 %endm
    204 
    205 %macro eret()
    206 %p1_eret
    207 %endm
    208 
    209 # ---- System ---------------------------------------------------------------
    210 
    211 %macro syscall()
    212 %p1_syscall
    213 %endm
    214 
    215 %macro sys_read()
    216 %p1_sys_read
    217 %endm
    218 
    219 %macro sys_write()
    220 %p1_sys_write
    221 %endm
    222 
    223 %macro sys_close()
    224 %p1_sys_close
    225 %endm
    226 
    227 %macro sys_openat()
    228 %p1_sys_openat
    229 %endm
    230 
    231 %macro sys_exit()
    232 %p1_sys_exit
    233 %endm
    234 
    235 %macro sys_clone()
    236 %p1_sys_clone
    237 %endm
    238 
    239 %macro sys_execve()
    240 %p1_sys_execve
    241 %endm
    242 
    243 %macro sys_waitid()
    244 %p1_sys_waitid
    245 %endm
    246 
    247 # ---- Program entry --------------------------------------------------------
    248 #
    249 # The portable P1 program-entry model emits a backend-specific `:_start`
    250 # stub that captures argc/argv from the native entry state, calls the
    251 # portable label `p1_main` under the one-word direct-result convention
    252 # (a0=argc, a1=argv), and sys_exits p1_main's return value. The stub is
    253 # emitted unconditionally here so portable sources only need to define
    254 # `:p1_main` as an ordinary P1 function.
    255 
    256 %p1_entry