1# 2# %CopyrightBegin% 3# 4# Copyright Ericsson AB 1998-2018. All Rights Reserved. 5# 6# Licensed under the Apache License, Version 2.0 (the "License"); 7# you may not use this file except in compliance with the License. 8# You may obtain a copy of the License at 9# 10# http://www.apache.org/licenses/LICENSE-2.0 11# 12# Unless required by applicable law or agreed to in writing, software 13# distributed under the License is distributed on an "AS IS" BASIS, 14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15# See the License for the specific language governing permissions and 16# limitations under the License. 17# 18# %CopyrightEnd% 19# 20BEAM_FORMAT_NUMBER=0 21 22# 23# Generic instructions, generated by the compiler. If any of them change number, 24# arity or semantics, the format number above must be bumped. 25# 26 27## @spec label Lbl 28## @doc Specify a module local label. 29## Label gives this code address a name (Lbl) and marks the start of 30## a basic block. 311: label/1 32 33## @spec func_info M F A 34## @doc Define a function M:F/A 352: func_info/3 36 373: int_code_end/0 38 39# 40# Function and BIF calls. 41# 42 43## @spec call Arity Label 44## @doc Call the function at Label. 45## Save the next instruction as the return address in the CP register. 464: call/2 47 48## @spec call_last Arity Label Deallocate 49## @doc Deallocate and do a tail recursive call to the function at Label. 50## Do not update the CP register. 51## Before the call deallocate Deallocate words of stack. 525: call_last/3 53 54## @spec call_only Arity Label 55## @doc Do a tail recursive call to the function at Label. 56## Do not update the CP register. 576: call_only/2 58 59## @spec call_ext Arity Destination 60## @doc Call the function of arity Arity pointed to by Destination. 61## Save the next instruction as the return address in the CP register. 627: call_ext/2 63 64## @spec call_ext_last Arity Destination Deallocate 65## @doc Deallocate and do a tail call to function of arity Arity 66## pointed to by Destination. 67## Do not update the CP register. 68## Deallocate Deallocate words from the stack before the call. 698: call_ext_last/3 70 71## @spec bif0 Bif Reg 72## @doc Call the bif Bif and store the result in Reg. 739: bif0/2 74 75## @spec bif1 Lbl Bif Arg Reg 76## @doc Call the bif Bif with the argument Arg, and store the result in Reg. 77## On failure jump to Lbl. 7810: bif1/4 79 80## @spec bif2 Lbl Bif Arg1 Arg2 Reg 81## @doc Call the bif Bif with the arguments Arg1 and Arg2, 82## and store the result in Reg. 83## On failure jump to Lbl. 8411: bif2/5 85 86# 87# Allocating, deallocating and returning. 88# 89 90## @spec allocate StackNeed Live 91## @doc Allocate space for StackNeed words on the stack. If a GC is needed 92## during allocation there are Live number of live X registers. 93## Also save the continuation pointer (CP) on the stack. 9412: allocate/2 95 96## @spec allocate_heap StackNeed HeapNeed Live 97## @doc Allocate space for StackNeed words on the stack and ensure there is 98## space for HeapNeed words on the heap. If a GC is needed 99## save Live number of X registers. 100## Also save the continuation pointer (CP) on the stack. 10113: allocate_heap/3 102 103## @spec allocate_zero StackNeed Live 104## @doc Allocate space for StackNeed words on the stack. If a GC is needed 105## during allocation there are Live number of live X registers. 106## Clear the new stack words. (By writing NIL.) 107## Also save the continuation pointer (CP) on the stack. 108## 109## OTP 24: This instruction has been superseded by allocate/2 followed 110## by init_yregs/1. 11114: allocate_zero/2 112 113## @spec allocate_heap_zero StackNeed HeapNeed Live 114## @doc Allocate space for StackNeed words on the stack and HeapNeed words 115## on the heap. If a GC is needed 116## during allocation there are Live number of live X registers. 117## Clear the new stack words. (By writing NIL.) 118## Also save the continuation pointer (CP) on the stack. 119## 120## OTP 24: This instruction has been superseded by allocate_heap/2 121## followed by init_yregs/1. 12215: allocate_heap_zero/3 123 124## @spec test_heap HeapNeed Live 125## @doc Ensure there is space for HeapNeed words on the heap. If a GC is needed 126## save Live number of X registers. 12716: test_heap/2 128 129## @spec init N 130## @doc Clear the Nth stack word. (By writing NIL.) 131## 132## OTP 24: This instruction has been superseded by init_yregs/1. 13317: init/1 134 135## @spec deallocate N 136## @doc Restore the continuation pointer (CP) from the stack and deallocate 137## N+1 words from the stack (the + 1 is for the CP). 13818: deallocate/1 139 140## @spec return 141## @doc Return to the address in the continuation pointer (CP). 14219: return/0 143 144# 145# Sending & receiving. 146# 147## @spec send 148## @doc Send argument in x(1) as a message to the destination process in x(0). 149## The message in x(1) ends up as the result of the send in x(0). 15020: send/0 151 152## @spec remove_message 153## @doc Unlink the current message from the message queue. Remove any timeout. 15421: remove_message/0 155 156## @spec timeout 157## @doc Reset the save point of the mailbox and clear the timeout flag. 15822: timeout/0 159 160## @spec loop_rec Label Source 161## @doc Loop over the message queue, if it is empty jump to Label. 16223: loop_rec/2 163 164## @spec loop_rec_end Label 165## @doc Advance the save pointer to the next message and jump back to Label. 16624: loop_rec_end/1 167 168## @spec wait Label 169## @doc Suspend the processes and set the entry point to the beginning of the 170## receive loop at Label. 17125: wait/1 172 173## @spec wait_timeout Lable Time 174## @doc Sets up a timeout of Time milliseconds and saves the address of the 175## following instruction as the entry point if the timeout triggers. 17626: wait_timeout/2 177 178# 179# Arithmetic opcodes. 180# 18127: -m_plus/4 18228: -m_minus/4 18329: -m_times/4 18430: -m_div/4 18531: -int_div/4 18632: -int_rem/4 18733: -int_band/4 18834: -int_bor/4 18935: -int_bxor/4 19036: -int_bsl/4 19137: -int_bsr/4 19238: -int_bnot/3 193 194# 195# Comparision operators. 196# 197 198## @spec is_lt Lbl Arg1 Arg2 199## @doc Compare two terms and jump to Lbl if Arg1 is not less than Arg2. 20039: is_lt/3 201 202## @spec is_ge Lbl Arg1 Arg2 203## @doc Compare two terms and jump to Lbl if Arg1 is less than Arg2. 20440: is_ge/3 205 206## @spec is_eq Lbl Arg1 Arg2 207## @doc Compare two terms and jump to Lbl if Arg1 is not (numerically) equal to Arg2. 20841: is_eq/3 209 210## @spec is_ne Lbl Arg1 Arg2 211## @doc Compare two terms and jump to Lbl if Arg1 is (numerically) equal to Arg2. 21242: is_ne/3 213 214## @spec is_eq_exact Lbl Arg1 Arg2 215## @doc Compare two terms and jump to Lbl if Arg1 is not exactly equal to Arg2. 21643: is_eq_exact/3 217 218## @spec is_ne_exact Lbl Arg1 Arg2 219## @doc Compare two terms and jump to Lbl if Arg1 is exactly equal to Arg2. 22044: is_ne_exact/3 221 222# 223# Type tests. 224# 225 226## @spec is_integer Lbl Arg1 227## @doc Test the type of Arg1 and jump to Lbl if it is not an integer. 22845: is_integer/2 229 230## @spec is_float Lbl Arg1 231## @doc Test the type of Arg1 and jump to Lbl if it is not a float. 23246: is_float/2 233 234## @spec is_number Lbl Arg1 235## @doc Test the type of Arg1 and jump to Lbl if it is not a number. 23647: is_number/2 237 238## @spec is_atom Lbl Arg1 239## @doc Test the type of Arg1 and jump to Lbl if it is not an atom. 24048: is_atom/2 241 242## @spec is_pid Lbl Arg1 243## @doc Test the type of Arg1 and jump to Lbl if it is not a pid. 24449: is_pid/2 245 246## @spec is_reference Lbl Arg1 247## @doc Test the type of Arg1 and jump to Lbl if it is not a reference. 24850: is_reference/2 249 250## @spec is_port Lbl Arg1 251## @doc Test the type of Arg1 and jump to Lbl if it is not a port. 25251: is_port/2 253 254## @spec is_nil Lbl Arg1 255## @doc Test the type of Arg1 and jump to Lbl if it is not nil. 25652: is_nil/2 257 258## @spec is_binary Lbl Arg1 259## @doc Test the type of Arg1 and jump to Lbl if it is not a binary. 26053: is_binary/2 261 26254: -is_constant/2 263 264## @spec is_list Lbl Arg1 265## @doc Test the type of Arg1 and jump to Lbl if it is not a cons or nil. 26655: is_list/2 267 268## @spec is_nonempty_list Lbl Arg1 269## @doc Test the type of Arg1 and jump to Lbl if it is not a cons. 27056: is_nonempty_list/2 271 272## @spec is_tuple Lbl Arg1 273## @doc Test the type of Arg1 and jump to Lbl if it is not a tuple. 27457: is_tuple/2 275 276## @spec test_arity Lbl Arg1 Arity 277## @doc Test the arity of (the tuple in) Arg1 and jump 278## to Lbl if it is not equal to Arity. 27958: test_arity/3 280 281# 282# Indexing & jumping. 283# 284 285## @spec select_val Arg FailLabel Destinations 286## @doc Jump to the destination label corresponding to Arg 287## in the Destinations list, if no arity matches, jump to FailLabel. 28859: select_val/3 289 290## @spec select_tuple_arity Tuple FailLabel Destinations 291## @doc Check the arity of the tuple Tuple and jump to the corresponding 292## destination label, if no arity matches, jump to FailLabel. 29360: select_tuple_arity/3 294 295## @spec jump Label 296## @doc Jump to Label. 29761: jump/1 298 299# 300# Catch. 301# 30262: catch/2 30363: catch_end/1 304 305# 306# Moving, extracting, modifying. 307# 308 309## @spec move Source Destination 310## @doc Move the source Source (a literal or a register) to 311## the destination register Destination. 31264: move/2 313 314## @spec get_list Source Head Tail 315## @doc Get the head and tail (or car and cdr) parts of a list 316## (a cons cell) from Source and put them into the registers 317## Head and Tail. 31865: get_list/3 319 320## @spec get_tuple_element Source Element Destination 321## @doc Get element number Element from the tuple in Source and put 322## it in the destination register Destination. 32366: get_tuple_element/3 324 325## @spec set_tuple_element NewElement Tuple Position 326## @doc Update the element at position Position of the tuple Tuple 327## with the new element NewElement. 32867: set_tuple_element/3 329 330# 331# Building terms. 332# 33368: -put_string/3 33469: put_list/3 33570: put_tuple/2 33671: put/1 337 338# 339# Raising errors. 340# 34172: badmatch/1 34273: if_end/0 34374: case_end/1 344 345# 346# 'fun' support. 347# 348## @spec call_fun Arity 349## @doc Call a fun of arity Arity. Assume arguments in 350## registers x(0) to x(Arity-1) and that the fun is in x(Arity). 351## Save the next instruction as the return address in the CP register. 35275: call_fun/1 353 35476: -make_fun/3 355 356## @spec is_function Lbl Arg1 357## @doc Test the type of Arg1 and jump to Lbl if it is not a 358## function (i.e. fun or closure). 35977: is_function/2 360 361# 362# Late additions to R5. 363# 364 365## @spec call_ext_only Arity Label 366## Do a tail recursive call to the function at Label. 367## Do not update the CP register. 36878: call_ext_only/2 369 370# 371# Binary matching (R7). 372# 37379: -bs_start_match/2 37480: -bs_get_integer/5 37581: -bs_get_float/5 37682: -bs_get_binary/5 37783: -bs_skip_bits/4 37884: -bs_test_tail/2 37985: -bs_save/1 38086: -bs_restore/1 381 382# 383# Binary construction (R7A). 384# 38587: -bs_init/2 38688: -bs_final/2 38789: bs_put_integer/5 38890: bs_put_binary/5 38991: bs_put_float/5 39092: bs_put_string/2 391 392# 393# Binary construction (R7B). 394# 39593: -bs_need_buf/1 396 397# 398# Floating point arithmetic (R8). 399# 400# The fclearerror and fcheckerror instructions are not used in OTP 24 401# and later. 402# 40394: fclearerror/0 40495: fcheckerror/1 40596: fmove/2 40697: fconv/2 40798: fadd/4 40899: fsub/4 409100: fmul/4 410101: fdiv/4 411102: fnegate/3 412 413# New fun construction (R8). 414103: make_fun2/1 415 416# Try/catch/raise (R10B). 417104: try/2 418105: try_end/1 419106: try_case/1 420107: try_case_end/1 421108: raise/2 422 423# New instructions in R10B. 424109: bs_init2/6 425110: -bs_bits_to_bytes/3 426111: bs_add/5 427112: apply/1 428113: apply_last/2 429## @spec is_boolean Lbl Arg1 430## @doc Test the type of Arg1 and jump to Lbl if it is not a Boolean. 431114: is_boolean/2 432 433# New instructions in R10B-6. 434## @spec is_function2 Lbl Arg1 Arity 435## @doc Test the type of Arg1 and jump to Lbl if it is not a 436## function of arity Arity. 437115: is_function2/3 438 439# New bit syntax matching in R11B. 440 441116: bs_start_match2/5 442117: bs_get_integer2/7 443118: bs_get_float2/7 444119: bs_get_binary2/7 445120: bs_skip_bits2/5 446121: bs_test_tail2/3 447122: bs_save2/2 448123: bs_restore2/2 449 450# New GC bifs introduced in R11B. 451 452## @spec gc_bif1 Lbl Live Bif Arg Reg 453## @doc Call the bif Bif with the argument Arg, and store the result in Reg. 454## On failure jump to Lbl. 455## Do a garbage collection if necessary to allocate space on the heap 456## for the result (saving Live number of X registers). 457124: gc_bif1/5 458 459## @spec gc_bif2 Lbl Live Bif Arg1 Arg2 Reg 460## @doc Call the bif Bif with the arguments Arg1 and Arg2, 461## and store the result in Reg. 462## On failure jump to Lbl. 463## Do a garbage collection if necessary to allocate space on the heap 464## for the result (saving Live number of X registers). 465125: gc_bif2/6 466 467# Experimental new bit_level bifs introduced in R11B. 468# NOT used in R12B. 469126: -bs_final2/2 470127: -bs_bits_to_bytes2/2 471 472# R11B-4 473128: -put_literal/2 474 475# R11B-5 476## @spec is_bitstr Lbl Arg1 477## @doc Test the type of Arg1 and jump to Lbl if it is not a bit string. 478129: is_bitstr/2 479 480# R12B 481130: bs_context_to_binary/1 482131: bs_test_unit/3 483132: bs_match_string/4 484133: bs_init_writable/0 485134: bs_append/8 486135: bs_private_append/6 487 488## @spec trim N Remaining 489## @doc Reduce the stack usage by N words, 490## keeping the CP on the top of the stack. 491136: trim/2 492 493137: bs_init_bits/6 494 495# R12B-5 496138: bs_get_utf8/5 497139: bs_skip_utf8/4 498 499140: bs_get_utf16/5 500141: bs_skip_utf16/4 501 502142: bs_get_utf32/5 503143: bs_skip_utf32/4 504 505144: bs_utf8_size/3 506145: bs_put_utf8/3 507 508146: bs_utf16_size/3 509147: bs_put_utf16/3 510 511148: bs_put_utf32/3 512 513# R13B03 514 515149: on_load/0 516 517# R14A 518 519## @spec recv_mark Label 520## @doc Save the end of the message queue and the address of 521## the label Label so that a recv_set instruction can start 522## scanning the inbox from this position. 523150: recv_mark/1 524 525## @spec recv_set Label 526## @doc Check that the saved mark points to Label and set the 527## save pointer in the message queue to the last position 528## of the message queue saved by the recv_mark instruction. 529151: recv_set/1 530 531## @spec gc_bif3 Lbl Live Bif Arg1 Arg2 Arg3 Reg 532## @doc Call the bif Bif with the arguments Arg1, Arg2 and Arg3, 533## and store the result in Reg. 534## On failure jump to Lbl. 535## Do a garbage collection if necessary to allocate space on the heap 536## for the result (saving Live number of X registers). 537152: gc_bif3/7 538 539# R15A 540 541153: line/1 542 543# R17 544 545154: put_map_assoc/5 546155: put_map_exact/5 547156: is_map/2 548157: has_map_fields/3 549158: get_map_elements/3 550 551# OTP 20 552 553## @spec is_tagged_tuple Lbl Reg N Atom 554## @doc Test the type of Reg and jumps to Lbl if it is not a tuple. 555## Test the arity of Reg and jumps to Lbl if it is not N. 556## Test the first element of the tuple and jumps to Lbl if it is not Atom. 557159: is_tagged_tuple/4 558 559# OTP 21 560 561## @spec build_stacktrace 562## @doc Given the raw stacktrace in x(0), build a cooked stacktrace suitable 563## for human consumption. Store it in x(0). Destroys all other registers. 564## Do a garbage collection if necessary to allocate space on the heap 565## for the result. 566160: build_stacktrace/0 567 568## @spec raw_raise 569## @doc This instruction works like the erlang:raise/3 BIF, except that the 570## stacktrace in x(2) must be a raw stacktrace. 571## x(0) is the class of the exception (error, exit, or throw), 572## x(1) is the exception term, and x(2) is the raw stackframe. 573## If x(0) is not a valid class, the instruction will not throw an 574## exception, but store the atom 'badarg' in x(0) and execute the 575## next instruction. 576161: raw_raise/0 577 578## @spec get_hd Source Head 579## @doc Get the head (or car) part of a list (a cons cell) from Source and 580## put it into the register Head. 581162: get_hd/2 582 583## @spec get_tl Source Tail 584## @doc Get the tail (or cdr) part of a list (a cons cell) from Source and 585## put it into the register Tail. 586163: get_tl/2 587 588# OTP 22 589 590## @spec put_tuple2 Destination Elements 591## @doc Build a tuple with the elements in the list Elements and put it 592## into register Destination. 593164: put_tuple2/2 594 595## @spec bs_get_tail Ctx Dst Live 596## @doc Sets Dst to the tail of Ctx at the current position 597165: bs_get_tail/3 598 599## @spec bs_start_match3 Fail Bin Live Dst 600## @doc Starts a binary match sequence 601166: bs_start_match3/4 602 603## @spec bs_get_position Ctx Dst Live 604## @doc Sets Dst to the current position of Ctx 605167: bs_get_position/3 606 607## @spec bs_set_positon Ctx Pos 608## @doc Sets the current position of Ctx to Pos 609168: bs_set_position/2 610 611# OTP 23 612 613## @spec swap Register1 Register2 614## @doc Swaps the contents of two registers. 615169: swap/2 616 617## @spec bs_start_match4 Fail Bin Live Dst 618## @doc As bs_start_match3, but the fail label can be 'no_fail' when we know 619## it will never fail at runtime, or 'resume' when we know the input is 620## a match context. 621170: bs_start_match4/4 622 623# OTP 24 624 625## @spec make_fun3 OldIndex Dst EnvTerms 626## @doc Build a fun with the environment in the list EnvTerms and put it 627## into register Dst. 628171: make_fun3/3 629 630## @spec init_yregs ListOfYRegs 631## @doc Initialize the Y registers in the list. 632172: init_yregs/1 633 634## @spec recv_marker_bind Marker Reference 635## @doc Associates Reference with a previously reserved marker. 636173: recv_marker_bind/2 637 638## @spec recv_marker_clear Reference 639## @doc Clears the receive marker associated with the given Reference. 640174: recv_marker_clear/1 641 642## @spec recv_marker_reserve Marker 643## @doc Creates a receive marker which can be later bound to a reference. 644175: recv_marker_reserve/1 645 646## @spec recv_marker_use Reference 647## @doc Sets the current receive cursor to the marker associated with 648## the given Reference. 649176: recv_marker_use/1 650