text
stringlengths
1
1.05M
; Copyright (c) 2004, Intel Corporation. All rights reserved.<BR> ; 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: ; ; ReadDs.Asm ; ; Abstract: ; ; AsmReadDs function ; ; Notes: ; ;------------------------------------------------------------------------------ .code ;------------------------------------------------------------------------------ ; UINT16 ; EFIAPI ; AsmReadDs ( ; VOID ; ); ;------------------------------------------------------------------------------ AsmReadDs PROC mov eax, ds ret AsmReadDs ENDP END
;------------------------------------------------------------------------------ ; ; Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR> ; 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: ; ; ScanMem32.Asm ; ; Abstract: ; ; ScanMem32 function ; ; Notes: ; ; The following BaseMemoryLib instances contain the same copy of this file: ; ; BaseMemoryLibRepStr ; BaseMemoryLibMmx ; BaseMemoryLibSse2 ; BaseMemoryLibOptDxe ; BaseMemoryLibOptPei ; ;------------------------------------------------------------------------------ DEFAULT REL SECTION .text ;------------------------------------------------------------------------------ ; CONST VOID * ; EFIAPI ; InternalMemScanMem32 ( ; IN CONST VOID *Buffer, ; IN UINTN Length, ; IN UINT32 Value ; ); ;------------------------------------------------------------------------------ global ASM_PFX(InternalMemScanMem32) ASM_PFX(InternalMemScanMem32): push rdi mov rdi, rcx mov rax, r8 mov rcx, rdx repne scasd lea rax, [rdi - 4] cmovnz rax, rcx pop rdi ret
; A237588: Sigma(n) - 2n + 1. ; 0,0,-1,0,-3,1,-5,0,-4,-1,-9,5,-11,-3,-5,0,-15,4,-17,3,-9,-7,-21,13,-18,-9,-13,1,-27,13,-29,0,-17,-13,-21,20,-35,-15,-21,11,-39,13,-41,-3,-11,-19,-45,29,-40,-6,-29,-5,-51,13,-37,9,-33,-25,-57,49,-59,-27,-21,0 mov $1,$0 add $1,1 add $1,$0 cal $0,203 ; a(n) = sigma(n), the sum of the divisors of n. Also called sigma_1(n). sub $0,$1 mov $1,$0
; A022531: Nexus numbers (n+1)^15 - n^15. ; Submitted by Jon Maiga ; 1,32767,14316139,1059392917,29443836301,439667406451,4277376525367,30436810578889,170706760005817,794108867905351,3177248169415651,11229773405170717,35778871439504389,104382202543721467,282325794823047151,715027614225987601,1709501546902968817,3884217564967642639,8434486413397339867,17586872970125201701,35354318582951682301,68757749432460369667,129755167448979193639,238222047491654861017,426465291659432409001,745936767670247409751,1277053364265107773267,2143342648687557257389 sub $1,$0 add $0,1 pow $0,15 mov $2,$1 pow $2,15 add $0,$2
/* TEMPLATE GENERATED TESTCASE FILE Filename: CWE415_Double_Free__new_delete_int_11.cpp Label Definition File: CWE415_Double_Free__new_delete.label.xml Template File: sources-sinks-11.tmpl.cpp */ /* * @description * CWE: 415 Double Free * BadSource: Allocate data using new and Deallocae data using delete * GoodSource: Allocate data using new * Sinks: * GoodSink: do nothing * BadSink : Deallocate data using delete * Flow Variant: 11 Control flow: if(global_returns_t()) and if(global_returns_f()) * */ #include "std_testcase.h" #include <wchar.h> namespace CWE415_Double_Free__new_delete_int_11 { #ifndef OMITBAD void bad() { int * data; /* Initialize data */ data = NULL; if(global_returns_t()) { data = new int; /* POTENTIAL FLAW: delete data in the source - the bad sink deletes data as well */ delete data; } else { /* INCIDENTAL: CWE 561 Dead Code, the code below will never run */ data = new int; /* FIX: Do NOT delete data in the source - the bad sink deletes data */ } if(global_returns_t()) { /* POTENTIAL FLAW: Possibly deleting memory twice */ delete data; } else { /* INCIDENTAL: CWE 561 Dead Code, the code below will never run */ /* do nothing */ /* FIX: Don't attempt to delete the memory */ ; /* empty statement needed for some flow variants */ } } #endif /* OMITBAD */ #ifndef OMITGOOD /* goodB2G1() - use badsource and goodsink by changing the second global_returns_t() to global_returns_f() */ static void goodB2G1() { int * data; /* Initialize data */ data = NULL; if(global_returns_t()) { data = new int; /* POTENTIAL FLAW: delete data in the source - the bad sink deletes data as well */ delete data; } else { /* INCIDENTAL: CWE 561 Dead Code, the code below will never run */ data = new int; /* FIX: Do NOT delete data in the source - the bad sink deletes data */ } if(global_returns_f()) { /* INCIDENTAL: CWE 561 Dead Code, the code below will never run */ /* POTENTIAL FLAW: Possibly deleting memory twice */ delete data; } else { /* do nothing */ /* FIX: Don't attempt to delete the memory */ ; /* empty statement needed for some flow variants */ } } /* goodB2G2() - use badsource and goodsink by reversing the blocks in the second if */ static void goodB2G2() { int * data; /* Initialize data */ data = NULL; if(global_returns_t()) { data = new int; /* POTENTIAL FLAW: delete data in the source - the bad sink deletes data as well */ delete data; } else { /* INCIDENTAL: CWE 561 Dead Code, the code below will never run */ data = new int; /* FIX: Do NOT delete data in the source - the bad sink deletes data */ } if(global_returns_t()) { /* do nothing */ /* FIX: Don't attempt to delete the memory */ ; /* empty statement needed for some flow variants */ } else { /* INCIDENTAL: CWE 561 Dead Code, the code below will never run */ /* POTENTIAL FLAW: Possibly deleting memory twice */ delete data; } } /* goodG2B1() - use goodsource and badsink by changing the first global_returns_t() to global_returns_f() */ static void goodG2B1() { int * data; /* Initialize data */ data = NULL; if(global_returns_f()) { /* INCIDENTAL: CWE 561 Dead Code, the code below will never run */ data = new int; /* POTENTIAL FLAW: delete data in the source - the bad sink deletes data as well */ delete data; } else { data = new int; /* FIX: Do NOT delete data in the source - the bad sink deletes data */ } if(global_returns_t()) { /* POTENTIAL FLAW: Possibly deleting memory twice */ delete data; } else { /* INCIDENTAL: CWE 561 Dead Code, the code below will never run */ /* do nothing */ /* FIX: Don't attempt to delete the memory */ ; /* empty statement needed for some flow variants */ } } /* goodG2B2() - use goodsource and badsink by reversing the blocks in the first if */ static void goodG2B2() { int * data; /* Initialize data */ data = NULL; if(global_returns_t()) { data = new int; /* FIX: Do NOT delete data in the source - the bad sink deletes data */ } else { /* INCIDENTAL: CWE 561 Dead Code, the code below will never run */ data = new int; /* POTENTIAL FLAW: delete data in the source - the bad sink deletes data as well */ delete data; } if(global_returns_t()) { /* POTENTIAL FLAW: Possibly deleting memory twice */ delete data; } else { /* INCIDENTAL: CWE 561 Dead Code, the code below will never run */ /* do nothing */ /* FIX: Don't attempt to delete the memory */ ; /* empty statement needed for some flow variants */ } } void good() { goodB2G1(); goodB2G2(); goodG2B1(); goodG2B2(); } #endif /* OMITGOOD */ } // close namespace /* Below is the main(). It is only used when building this testcase on its own for testing or for building a binary to use in testing binary analysis tools. It is not used when compiling all the testcases as one application, which is how source code analysis tools are tested. */ #ifdef INCLUDEMAIN using namespace CWE415_Double_Free__new_delete_int_11; // so that we can use good and bad easily int main(int argc, char * argv[]) { /* seed randomness */ srand( (unsigned)time(NULL) ); #ifndef OMITGOOD printLine("Calling good()..."); good(); printLine("Finished good()"); #endif /* OMITGOOD */ #ifndef OMITBAD printLine("Calling bad()..."); bad(); printLine("Finished bad()"); #endif /* OMITBAD */ return 0; } #endif
//Seventh refinement of Adaptive Exterior Light and Speed Control System //Adaptive cruise control and distance warning //from SCS-18 to SCS-26 module CarSystem007AdaptiveCruiseC import ../../StandardLibrary import ../CarSystem006/CarSystem006Functions export * signature: // DOMAINS enum domain RangeRadarState = {READY | DIRTY | NOTREADY} domain RangeRadarSensor subsetof Integer domain SafetyDistance subsetof Real // Safety distance domain BrakePressure subsetof Integer domain TimeImpactBrake subsetof Integer enum domain Aceleration = {ACCP5 | DECM2 | NOACC} // FUNCTIONS derived adaptiveCruiseControlActivated: Boolean //Depending whether cruiseControlMode = CCM2 or not //derived adaptiveCruiseControlDeactivated: Boolean controlled acousticWarningOn: Boolean //Acoustic warning command True, False controlled visualWarningOn: Boolean monitored rangeRadarState: RangeRadarState monitored rangeRadarSensor: RangeRadarSensor derived obstacleAhead: Boolean monitored safetyDistance: Real //secondi monitored speedVehicleAhead: CurrentSpeed //Speed of preceding vehicle in unity controlled speedVehicleAhead_Prec: CurrentSpeed //Speed of precedeing vehicle in state n-1 controlled setSafetyDistance: Integer //metri derived bothVehicleStanding: Boolean controlled brakePressure: BrakePressure // Brake pressure controlled acceleration: Integer //m/s^2 controlled acousticCollisionSignals: Boolean // acoustic signal SCS-21 derived brakingDistance: Integer //in metri monitored setTargetFromAccDec: CurrentSpeed //new targhet when obstacle ahead derived manualSpeed: Boolean // True if user changes desired speed manually definitions: domain RangeRadarSensor = {0..200} //0 = no dectected obstacle in the travel corridor //1-200 = distance in meters of obstacle detected in the travel corridor // FUNCTION DEFINITIONS function adaptiveCruiseControlActivated = (cruiseControlMode = CCM2) //function adaptiveCruiseControlDeactivated = // (sCSLever = BACKWARD_SCS or not cruiseControlMode = CCM2) function obstacleAhead = (rangeRadarState = READY and not rangeRadarSensor = 0) function bothVehicleStanding = (currentSpeed = 0 and speedVehicleAhead = 0) function brakingDistance = rtoi((currentSpeed*currentSpeed)/20) //==================================== //It is true if user changes desired speed manually function manualSpeed = (sCSLever = UPWARD5_SCS or sCSLever = UPWARD7_SCS or sCSLever = DOWNWARD5_SCS or sCSLever = DOWNWARD7_SCS) // RULE DEFINITIONS //SCS-23 //@PE_MAPE_CC macro rule r_CalculateSafetyDistancePlan_CC = if currentSpeed<200 then par speedVehicleAhead_Prec := speedVehicleAhead if (speedVehicleAhead < 200 and speedVehicleAhead > 0) then setSafetyDistance := rtoi(2.5 * (currentSpeed/36)) // div 10 -> from unity to km/h, div3.6 -> from km/h to m/s endif if (bothVehicleStanding) then setSafetyDistance := 2 endif if (speedVehicleAhead > speedVehicleAhead_Prec and currentSpeed != 0) then setSafetyDistance := rtoi(3.0 * (currentSpeed/36)) endif endpar endif //SCS-24 //@PE_MAPE_CC macro rule r_SafetyDistanceByUser = if not adaptiveCruiseControlActivated then if (currentSpeed > 200) then if (sCSLever = HEAD) then setSafetyDistance := rtoi((currentSpeed/10)/3.6*(safetyDistance)) endif endif endif //SCS-21 //@PE_MAPE_CC macro rule r_CollisionDetection = par if (rangeRadarSensor < brakingDistance) then //SCS-21 checks if adaptation is necessary acousticCollisionSignals := true endif if (rangeRadarSensor > brakingDistance and acousticCollisionSignals = true) then //SCS-21 checks if adaptation is necessary acousticCollisionSignals := false endif endpar //@P_MAPE_CC macro rule r_AcceleratePlan_CC = if currentSpeed < setVehicleSpeed then par acceleration := 2 //Assumption: The scs lever has the priority when modifing setvehiclespeed if (not manualSpeed) then if (desiredSpeed > setVehicleSpeed) then if (setTargetFromAccDec> speedVehicleAhead) then setVehicleSpeed := speedVehicleAhead else setVehicleSpeed := setTargetFromAccDec endif endif endif endpar else acceleration := 0 endif //@P_MAPE_CC macro rule r_DeceleratePlan_CC = if (currentSpeed != 0) then par acceleration := -5 if (not manualSpeed) then setVehicleSpeed := setTargetFromAccDec endif endpar else acceleration := 0 endif //@PE_MAPE_CC macro rule r_WarningPlan_CC = par if (itor(rangeRadarSensor) < ((currentSpeed/10)/3.6)*1.5) then visualWarningOn := true else if visualWarningOn then visualWarningOn := false endif endif if (itor(rangeRadarSensor) < ((currentSpeed/10)/3.6)*0.8) then acousticWarningOn:= true else if acousticWarningOn then acousticWarningOn := false endif endif endpar //@MA_MAPE_CC //All MAPE computations of the MAPE loop are executed within one single ASM-step machine. macro rule r_Monitor_Analyze_CC = if adaptiveCruiseControlActivated then par if (obstacleAhead and rangeRadarSensor<setSafetyDistance) then //SCS-22 checks if adaptation is necessary r_AcceleratePlan_CC[] endif if (obstacleAhead and rangeRadarSensor>setSafetyDistance) then //SCS-20 checks if adaptation is necessary r_DeceleratePlan_CC[] endif r_CollisionDetection[] if obstacleAhead then //SCS-25, SCS-26 distance warning (if necessary) r_WarningPlan_CC[] endif r_CalculateSafetyDistancePlan_CC[] //SCS-23 endpar endif macro rule r_MAPE_CC = //MAPE loop may start and stop //par r_Monitor_Analyze_CC[] //if adaptiveCruiseControlDeactivated then //SCS-12 // r_SetModifySpeed[setVehicleSpeed] endif //endpar
.data ok: .asciiz "data is ok" # if checkParity return 0 bad: .asciiz "data has been corrupted" # if checkParity return 1 fout: .asciiz "input.txt" size: .word 1 buffer: .space 100 buffer2: .space 100 #"The quick brown fox jumped over the lazy river." length 47 .text ############################################################### # Open (for reading) a file that does exist li $v0, 13 # system call for open file la $a0, fout # input file name li $a1, 0 # Open for writing (flags are 0: read, 1: write) li $a2, 0 # mode is ignored syscall # open a file (file descriptor returned in $v0) move $s6, $v0 # save the file descriptor ############################################################### #Read file just opened li $v0, 14 # system call for read from the file move $a0, $s6 # file descriptor la $a1, buffer # address of buffer store which from read li $a2, 47 # hardcoded buffer length syscall # Read to file sw $v0, size # store the size of the buffer 1 from input ############################################################### #### check if read the correct text #li $v0, 4 #la $a0, buffer # syscall #################################### # Close the file li $v0, 16 # system call for close file move $a0, $s6 # file descriptor to close syscall # close file ############################################################### la $a0, buffer # $s1 contain the text li $v0, 4 syscall li $a0, '\n' li $v0, 11 syscall la $a0, buffer # input 1, the address of the string to check lw $a1, size # input 2 the size of the string la $a3, buffer2 # the string address to store the text + parity jal setParity # nothing return but change buffer 2 (input 3) la $a0, buffer2 # $s1 contain the text li $v0, 4 syscall li $a0, '\n' li $v0, 11 syscall la $a0, buffer2 # input 1 the address of buffer that need to check lw $a1, size # input 2 the size of the string jal checkParity # $v0 return 0 if data is ok else return 1 for corrupted beq $v0, $zero, good # check if parity return 1 or zero la $a0, bad # put the bad sentence address to $a0 to print j print # jump over good to print to print the sentence good: la $a0, ok # put the ok sentence address to $a0 to print print: li $v0, 4 # 4 for print a string syscall # exit li $v0, 10 # 10 for end program syscall checkParity: # start a funtion # $a0 is the address of the buffer one # $a1 is the size of the text # save s1, s2, s3 to the stack addi $sp, $sp, -20 # push 3 items to stack sw $s6, 16($sp) # store s6 to the stack for byte address sw $s5, 12($sp) # store s5 to the stack for a byte content sw $s3, 8($sp) # store s3 to the stack sw $s2, 4($sp) # store s2 to the stack sw $s1, 0($sp) # store s1 to the stack # funtion body add $s3, $zero, $zero # index number counter add $s2, $zero, $a1 # characters counter move $s1, $a0 # address of the sentence #add $t1, $zero, $zero # $t1 as the counter for loop loopC: add $s6, $s1, $s3 # get the address of each byte and store in $s6 lbu $s5, 0($s6) # store the byte into $s5 addi $sp, $sp, -8 # put $a0 to the stack sw $a0, 0($sp) # store $a0 before call the function checkByte sw $ra, 4($sp) # store the return address move $a0, $s5 # move the byte form $t1 to $a0 jal checkByte # check even or odd number of one lw $a0, 0($sp) # put $a0 back from the stack after checkByte finish lw $ra, 4($sp) # put the previous return address back addi $sp, $sp, 8 # take $a0 away from the stack beq $v0, $zero, zero # jump to zer if checkByte return 0 and $s6, $s5, 128 # change the 7th bit when checkByte return 1 beq $s6, $zero, corrupt j endLoopC zero: and $s6, $s5, 128 bne $s6, $zero, corrupt endLoopC: addi $s3, $s3, 1 # increase the char counter bne $s3, $s2, loopC #function end li $v0, 0 j endCheck corrupt: li $v0, 1 #j endCheck endCheck: lw $s1, 0($sp) # restore s1 from stack lw $s2, 4($sp) # restore s2 from stack lw $s3, 8($sp) # restore s3 from stack lw $s5, 12($sp) # restore s2 from stack lw $s6, 16($sp) # restore s3 from stack addi $sp, $sp, 20 # pop 3 items from stack jr $ra # go back to where function was called setParity: # start a funtion # $a0 is the address of the buffer one # $a1 is the size of the text # $a3 is the address of buffer two # save s1, s2, s3 to the stack addi $sp, $sp, -20 # push 3 items to stack sw $s6, 16($sp) # store s6 to the stack for byte address sw $s5, 12($sp) # store s5 to the stack for a byte content sw $s3, 8($sp) # store s3 to the stack sw $s2, 4($sp) # store s2 to the stack sw $s1, 0($sp) # store s1 to the stack # funtion body add $s3, $zero, $zero # index number counter add $s2, $zero, $a1 # characters counter move $s1, $a0 # address of the sentence #add $t1, $zero, $zero # $t1 as the counter for loop loop: add $s6, $s1, $s3 # get the address of each byte and store in $s6 lbu $s5, 0($s6) # store the byte into $s5 addi $sp, $sp, -8 # put $a0 to the stack sw $a0, 0($sp) # store $a0 before call the function checkByte sw $ra, 4($sp) # store the return address move $a0, $s5 # move the byte form $t1 to $a0 jal checkByte # check even or odd number of one add $s6, $a3, $s3 # change the byte address for buffer two beq $v0, $zero, zer # jump to zer if checkByte return 0 or $s5, 128 # change the 7th bit when checkByte return 1 zer: sb $s5, ($s6) # store the byte to buffer two addi $s3, $s3, 1 # increase the char counter lw $a0, 0($sp) # put $a0 back from the stack after checkByte finish lw $ra, 4($sp) # put the previous return address back addi $sp, $sp, 8 # take $a0 away from the stack bne $s3, $s2, loop #function end move $v0, $a3 lw $s1, 0($sp) # restore s1 from stack lw $s2, 4($sp) # restore s2 from stack lw $s3, 8($sp) # restore s3 from stack lw $s5, 12($sp) # restore s2 from stack lw $s6, 16($sp) # restore s3 from stack addi $sp, $sp, 20 # pop 3 items from stack jr $ra # go back to where function was called checkByte: # start a funtion # input $a0 the byte to check # save s1, s2, s3 to the stack addi $sp, $sp, -12 # push 3 items to stack sw $s1, 0($sp) # store s1 to the stack sw $s2, 4($sp) # store s2 to the stack sw $s3, 8($sp) # store s3 to the stack add $s1, $zero, $zero # bit number counter 0 to 6 add $s2, $zero, $zero # numbers of bit that has 1 addi $s3, $zero, 1 # check each bit that has one loopB: and $t6, $a0, $s3 # compare the bit between $a0 and $s3(change from right to left) bne $t6, $zero, one # increase the bit that has one if $t6 is not zero backOne: addi $s1, $s1, 1 # increase the number of bit that is finish sll $s3, $s3, 1 # shift the one bit to the left beq $s1, 7, funcEnd # check we finish compare all 7 bits(0-6) j loopB # loop again if not finish one: # found one addi $s2, $s2, 1 # increase the number of bit that has one j backOne # go back to the loop and increase $s1, $s3 funcEnd: addi $t7, $zero, 2 # put 2 into $t7 divu $s2, $t7 # divide $s2(the number of one bits) by $t7(2) mfhi $t7 # store the reminder to $t7 #beq $t7, $zero, leave # check if the reminder is zero, which mean $s2(the number of one bits) is a even number #or $a0, $a0, $s3 # if $s2(the number of one bits) is a odd number, then change the 7th bit to one #leave: lw $s1, 0($sp) # restore s1 from the stack lw $s2, 4($sp) # restore s2 from the stack lw $s3, 8($sp) # restore s3 from the stack addi $sp, $sp, 12 # fix the stack pointer move $v0, $t7 # move the address of the byte to $v0 jr $ra # go back to where the function was call
; A244842: a(n) = (10^n - 1)*(10^n - 10)/90. ; 0,99,10989,1109889,111098889,11110988889,1111109888889,111111098888889,11111110988888889,1111111109888888889,111111111098888888889,11111111110988888888889,1111111111109888888888889,111111111111098888888888889,11111111111110988888888888889,1111111111111109888888888888889,111111111111111098888888888888889,11111111111111110988888888888888889,1111111111111111109888888888888888889,111111111111111111098888888888888888889,11111111111111111110988888888888888888889 add $0,1 mov $1,10 pow $1,$0 sub $1,5 bin $1,2 div $1,45 mov $0,$1
BITS 32 ;TEST_FILE_META_BEGIN ;TEST_TYPE=TEST_F ;TEST_IGNOREFLAGS= ;TEST_FILE_META_END ; LAHF ;TEST_BEGIN_RECORDING lahf ;TEST_END_RECORDING
; =============================================================== ; Jan 2014 ; =============================================================== ; ; int fseek(FILE *stream, long offset, int whence) ; ; Move to new position in file indicated by the signed value ; offset. ; ; If whence is: ; ; STDIO_SEEK_SET (0) : offset is relative to start of file ; STDIO_SEEK_CUR (1) : offset is relative to current position ; STDIO_SEEK_END (2) : offset is relative to end of file ; ; For STDIO_SEEK_SET, offset is treated as unsigned. ; ; =============================================================== INCLUDE "clib_cfg.asm" SECTION code_clib SECTION code_stdio ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; IF __CLIB_OPT_MULTITHREAD & $02 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; PUBLIC asm_fseek EXTERN asm0_fseek_unlocked, __stdio_lock_release asm_fseek: ; enter : ix = FILE * ; dehl = offset ; c = whence ; ; exit : ix = FILE * ; ; success ; ; hl = 0 ; carry reset ; ; fail ; ; hl = -1 ; carry set ; ; uses : all except ix ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; IF __CLIB_OPT_STDIO & $01 EXTERN __stdio_verify_valid_lock call __stdio_verify_valid_lock ret c ELSE EXTERN __stdio_lock_acquire, error_enolck_mc call __stdio_lock_acquire jp c, error_enolck_mc ENDIF ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; call asm0_fseek_unlocked jp __stdio_lock_release ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ELSE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; PUBLIC asm_fseek EXTERN asm_fseek_unlocked defc asm_fseek = asm_fseek_unlocked ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ENDIF ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; uint in_LookupKey(uchar c) SECTION code_clib PUBLIC in_LookupKey PUBLIC _in_LookupKey EXTERN in_keytranstbl ; enter: L = ascii character code ; exit : L = scan row ; H = mask ; else: L = scan row, H = mask ; bit 7 of L set if SHIFT needs to be pressed ; bit 6 of L set if CTRL needs to be pressed ; uses : AF,BC,HL ; The 16-bit value returned is a scan code understood by ; in_KeyPressed. .in_LookupKey ._in_LookupKey ld a,l ld hl,in_keytranstbl ld de,0 ld b,96 loop1: cp (hl) jp z,gotit inc hl dec b jp nz,loop1 ld e,128 ;Shift ld b,96 loop2: cp (hl) jp z,gotit inc hl dec b jp nz,loop2 ld e,@01000000 ld b,96 loop3: cp (hl) jp z,gotit inc hl dec b jp nz,loop3 notfound: ld hl,0 scf ret ; e = modifiers ; b = position within table gotit: ld a,96 sub b ld b,a ; Divide by 8 to find the row rrca rrca rrca and 15 ;That gets the row or e ;Ctrl/shift modifiers ld e,a ;That's safe now ; Now calculate the mask, ld a,b and 7 ld b,a ld a,@00000001 inc b maskloop: dec b jp z,got_mask rlca jp maskloop got_mask: ld d,a ex de,hl and a ret
// Copyright (c) 2011-2013 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 "bitcoinunits.h" #include <QStringList> BitcoinUnits::BitcoinUnits(QObject *parent): QAbstractListModel(parent), unitlist(availableUnits()) { } QList<BitcoinUnits::Unit> BitcoinUnits::availableUnits() { QList<BitcoinUnits::Unit> unitlist; unitlist.append(BTC); unitlist.append(mBTC); unitlist.append(uBTC); return unitlist; } bool BitcoinUnits::valid(int unit) { switch(unit) { case BTC: case mBTC: case uBTC: return true; default: return false; } } QString BitcoinUnits::name(int unit) { switch(unit) { case BTC: return QString("SHRK"); case mBTC: return QString("mSHRK"); case uBTC: return QString::fromUtf8("μSHRK"); default: return QString("???"); } } QString BitcoinUnits::description(int unit) { switch(unit) { case BTC: return QString("Sharkcoins"); case mBTC: return QString("Milli-Sharkcoins (1 / 1,000)"); case uBTC: return QString("Micro-Sharkcoins (1 / 1,000,000)"); default: return QString("???"); } } qint64 BitcoinUnits::factor(int unit) { switch(unit) { case BTC: return 100000000; case mBTC: return 100000; case uBTC: return 100; default: return 100000000; } } int BitcoinUnits::amountDigits(int unit) { switch(unit) { case BTC: return 8; // 21,000,000 (# digits, without commas) case mBTC: return 11; // 21,000,000,000 case uBTC: return 14; // 21,000,000,000,000 default: return 0; } } int BitcoinUnits::decimals(int unit) { switch(unit) { case BTC: return 8; case mBTC: return 5; case uBTC: return 2; default: return 0; } } QString BitcoinUnits::format(int unit, qint64 n, bool fPlus) { // Note: not using straight sprintf here because we do NOT want // localized number formatting. if(!valid(unit)) return QString(); // Refuse to format invalid unit qint64 coin = factor(unit); int num_decimals = decimals(unit); qint64 n_abs = (n > 0 ? n : -n); qint64 quotient = n_abs / coin; qint64 remainder = n_abs % coin; QString quotient_str = QString::number(quotient); QString remainder_str = QString::number(remainder).rightJustified(num_decimals, '0'); // Right-trim excess zeros after the decimal point int nTrim = 0; for (int i = remainder_str.size()-1; i>=2 && (remainder_str.at(i) == '0'); --i) ++nTrim; remainder_str.chop(nTrim); if (n < 0) quotient_str.insert(0, '-'); else if (fPlus && n > 0) quotient_str.insert(0, '+'); return quotient_str + QString(".") + remainder_str; } QString BitcoinUnits::formatWithUnit(int unit, qint64 amount, bool plussign) { return format(unit, amount, plussign) + QString(" ") + name(unit); } bool BitcoinUnits::parse(int unit, const QString &value, qint64 *val_out) { if(!valid(unit) || value.isEmpty()) return false; // Refuse to parse invalid unit or empty string int num_decimals = decimals(unit); QStringList parts = value.split("."); if(parts.size() > 2) { return false; // More than one dot } QString whole = parts[0]; QString decimals; if(parts.size() > 1) { decimals = parts[1]; } if(decimals.size() > num_decimals) { return false; // Exceeds max precision } bool ok = false; QString str = whole + decimals.leftJustified(num_decimals, '0'); if(str.size() > 18) { return false; // Longer numbers will exceed 63 bits } qint64 retvalue = str.toLongLong(&ok); if(val_out) { *val_out = retvalue; } return ok; } int BitcoinUnits::rowCount(const QModelIndex &parent) const { Q_UNUSED(parent); return unitlist.size(); } QVariant BitcoinUnits::data(const QModelIndex &index, int role) const { int row = index.row(); if(row >= 0 && row < unitlist.size()) { Unit unit = unitlist.at(row); switch(role) { case Qt::EditRole: case Qt::DisplayRole: return QVariant(name(unit)); case Qt::ToolTipRole: return QVariant(description(unit)); case UnitRole: return QVariant(static_cast<int>(unit)); } } return QVariant(); }
asl {m1} rol {m1}+1 asl {m1} rol {m1}+1
// // Copyright (C) 2003-2021 greg Landrum and other RDKit contributors // // @@ All Rights Reserved @@ // This file is part of the RDKit. // The contents are covered by the terms of the BSD license // which is included in the file license.txt, found at the root // of the RDKit source tree. // #include <RDBoost/python.h> #include <DataStructs/BitVects.h> #include <DataStructs/BitOps.h> namespace python = boost::python; namespace { template <typename T> python::object BVToBinaryText(const T &bv) { std::string res = BitVectToBinaryText(bv); python::object retval = python::object( python::handle<>(PyBytes_FromStringAndSize(res.c_str(), res.length()))); return retval; } } // namespace template <typename T> double SimilarityWrapper(const T &bv1, const std::string &pkl, double (*metric)(const T &, const T &), bool returnDistance) { T bv2(pkl); return SimilarityWrapper(bv1, bv2, metric, returnDistance); } template <typename T> double SimilarityWrapper(const T &bv1, const std::string &pkl, double a, double b, double (*metric)(const T &, const T &, double, double), bool returnDistance) { T bv2(pkl); return SimilarityWrapper(bv1, bv2, a, b, metric, returnDistance); } template <typename T> python::list NeighborWrapper(python::object queries, python::object bvs, double (*metric)(const T &, const T &)) { python::list res; unsigned int nbvs = python::extract<unsigned int>(bvs.attr("__len__")()); unsigned int nqs = python::extract<unsigned int>(queries.attr("__len__")()); for (unsigned int i = 0; i < nqs; ++i) { const T *bv1 = python::extract<const T *>(queries[i])(); double closest = -1; unsigned nbr; for (unsigned int j = 0; j < nbvs; ++j) { const T *bv2 = python::extract<const T *>(bvs[j])(); auto sim = metric(*bv1, *bv2); if (sim > closest) { closest = sim; nbr = j; } } res.append(python::make_tuple(nbr, closest)); } return res; } template <typename T> python::list BulkWrapper(const T *bv1, python::object bvs, double (*metric)(const T &, const T &), bool returnDistance) { python::list res; unsigned int nbvs = python::extract<unsigned int>(bvs.attr("__len__")()); for (unsigned int i = 0; i < nbvs; ++i) { const T *bv2 = python::extract<const T *>(bvs[i])(); auto sim = metric(*bv1, *bv2); if (returnDistance) { sim = 1.0 - sim; } res.append(sim); } return res; } template <typename T> python::list BulkWrapper(const T *bv1, python::object bvs, double a, double b, double (*metric)(const T &, const T &, double, double), bool returnDistance) { python::list res; unsigned int nbvs = python::extract<unsigned int>(bvs.attr("__len__")()); for (unsigned int i = 0; i < nbvs; ++i) { const T *bv2 = python::extract<T *>(bvs[i])(); auto sim = metric(*bv1, *bv2, a, b); if (returnDistance) { sim = 1.0 - sim; } res.append(sim); } return res; } #define METRIC_DEFS(_metricname_) \ template <typename T1, typename T2> \ double _metricname_##_w(const T1 &bv1, const T2 &bv2, bool returnDistance) { \ return SimilarityWrapper(bv1, bv2, \ (double (*)(const T1 &, const T1 &))_metricname_, \ returnDistance); \ } \ template <typename T> \ python::list Bulk##_metricname_(const T *bv1, python::object bvs, \ bool returnDistance) { \ return BulkWrapper(bv1, bvs, \ (double (*)(const T &, const T &))_metricname_, \ returnDistance); \ } \ template <typename T> \ python::list _metricname_##Neighbors(python::object queries, \ python::object bvs) { \ return NeighborWrapper(queries, bvs, \ (double (*)(const T &, const T &))_metricname_); \ } METRIC_DEFS(TanimotoSimilarity) METRIC_DEFS(CosineSimilarity) METRIC_DEFS(KulczynskiSimilarity) METRIC_DEFS(DiceSimilarity) METRIC_DEFS(SokalSimilarity) METRIC_DEFS(McConnaugheySimilarity) METRIC_DEFS(AsymmetricSimilarity) METRIC_DEFS(BraunBlanquetSimilarity) METRIC_DEFS(RusselSimilarity) METRIC_DEFS(RogotGoldbergSimilarity) METRIC_DEFS(OnBitSimilarity) METRIC_DEFS(AllBitSimilarity) template <typename T1, typename T2> double TverskySimilarity_w(const T1 &bv1, const T2 &bv2, double a, double b, bool returnDistance) { return SimilarityWrapper( bv1, bv2, a, b, (double (*)(const T1 &, const T1 &, double, double))TverskySimilarity, returnDistance); } template <typename T> python::list BulkTverskySimilarity(const T *bv1, python::object bvs, double a, double b, bool returnDistance) { return BulkWrapper( bv1, bvs, a, b, (double (*)(const T &, const T &, double, double))TverskySimilarity, returnDistance); } #define DBL_DEF(_funcname_, _bulkname_, _help_) \ { \ python::def(#_funcname_, (double (*)(const SBV &, const SBV &))_funcname_, \ (python::args("v1"), python::args("v2"))); \ python::def(#_funcname_, (double (*)(const EBV &, const EBV &))_funcname_, \ (python::args("v1"), python::args("v2")), _help_); \ python::def( \ #_bulkname_, \ (python::list(*)(const EBV *, python::object, bool))_bulkname_, \ (python::args("v1"), python::args("v2"), \ python::args("returnDistance") = 0)); \ python::def( \ #_bulkname_, \ (python::list(*)(const EBV *, python::object, bool))_bulkname_, \ (python::args("v1"), python::args("v2"), \ python::args("returnDistance") = 0), \ _help_); \ } #define BIG_DEF(_funcname_, _name_w_, _bulkname_, _help_) \ { \ python::def(#_funcname_, \ (double (*)(const SBV &, const SBV &, bool))_name_w_, \ (python::args("bv1"), python::args("bv2"), \ python::args("returnDistance") = 0)); \ python::def(#_funcname_, \ (double (*)(const EBV &, const EBV &, bool))_name_w_, \ (python::args("bv1"), python::args("bv2"), \ python::args("returnDistance") = 0), \ _help_); \ python::def(#_funcname_, \ (double (*)(const SBV &, const std::string &, bool))_name_w_, \ (python::args("bv1"), python::args("pkl"), \ python::args("returnDistance") = 0)); \ python::def(#_funcname_, \ (double (*)(const EBV &, const std::string &, bool))_name_w_, \ (python::args("bv1"), python::args("pkl"), \ python::args("returnDistance") = 0), \ _help_); \ python::def( \ #_bulkname_, \ (python::list(*)(const SBV *, python::object, bool))_bulkname_, \ (python::args("bv1"), python::args("bvList"), \ python::args("returnDistance") = 0)); \ python::def( \ #_bulkname_, \ (python::list(*)(const EBV *, python::object, bool))_bulkname_, \ (python::args("bv1"), python::args("bvList"), \ python::args("returnDistance") = 0), \ _help_); \ python::def(#_funcname_ "Neighbors", \ (python::list(*)(python::object, python::object)) \ _funcname_##Neighbors<ExplicitBitVect>, \ (python::args("bvqueries"), python::args("bvList")), _help_); \ python::def(#_funcname_ "Neighbors_sparse", \ (python::list(*)(python::object, python::object)) \ _funcname_##Neighbors<SparseBitVect>, \ (python::args("bvqueries"), python::args("bvList")), _help_); \ } struct BitOps_wrapper { static void wrap() { BIG_DEF(TanimotoSimilarity, TanimotoSimilarity_w, BulkTanimotoSimilarity, "B(bv1&bv2) / (B(bv1) + B(bv2) - B(bv1&bv2))"); BIG_DEF(CosineSimilarity, CosineSimilarity_w, BulkCosineSimilarity, "B(bv1&bv2) / sqrt(B(bv1) * B(bv2))"); BIG_DEF(KulczynskiSimilarity, KulczynskiSimilarity_w, BulkKulczynskiSimilarity, "B(bv1&bv2)*(B(bv1) + B(bv2)) / (2 * B(bv1) * B(bv2))"); BIG_DEF(DiceSimilarity, DiceSimilarity_w, BulkDiceSimilarity, "2*B(bv1&bv2) / (B(bv1) + B(bv2))"); BIG_DEF(SokalSimilarity, SokalSimilarity_w, BulkSokalSimilarity, "B(bv1&bv2) / (2*B(bv1) + 2*B(bv2) - 3*B(bv1&bv2))"); BIG_DEF( McConnaugheySimilarity, McConnaugheySimilarity_w, BulkMcConnaugheySimilarity, "(B(bv1&bv2) * (B(bv1)+B(bv2)) - B(bv1)*B(bv2)) / (B(bv1) * B(bv2))"); BIG_DEF(AsymmetricSimilarity, AsymmetricSimilarity_w, BulkAsymmetricSimilarity, "B(bv1&bv2) / min(B(bv1),B(bv2))"); BIG_DEF(BraunBlanquetSimilarity, BraunBlanquetSimilarity_w, BulkBraunBlanquetSimilarity, "B(bv1&bv2) / max(B(bv1),B(bv2))"); BIG_DEF(RusselSimilarity, RusselSimilarity_w, BulkRusselSimilarity, "B(bv1&bv2) / B(bv1)"); BIG_DEF(RogotGoldbergSimilarity, RogotGoldbergSimilarity_w, BulkRogotGoldbergSimilarity, "B(bv1&bv2) / B(bv1)"); { std::string help = "B(bv1&bv2) / (a*B(bv1)+b*B(bv2)+(1-a-b)*B(bv1&bv2)"; python::def("TverskySimilarity", (double (*)(const SBV &, const SBV &, double, double, bool))TverskySimilarity_w, (python::args("bv1"), python::args("bv2"), python::args("a"), python::args("b"), python::args("returnDistance") = 0)); python::def("TverskySimilarity", (double (*)(const EBV &, const EBV &, double, double, bool))TverskySimilarity_w, (python::args("bv1"), python::args("bv2"), python::args("a"), python::args("b"), python::args("returnDistance") = 0), help.c_str()); python::def("TverskySimilarity", (double (*)(const SBV &, const std::string &, double, double, bool))TverskySimilarity_w, (python::args("bv1"), python::args("pkl"), python::args("a"), python::args("b"), python::args("returnDistance") = 0)); python::def("TverskySimilarity", (double (*)(const EBV &, const std::string &, double, double, bool))TverskySimilarity_w, (python::args("bv1"), python::args("pkl"), python::args("a"), python::args("b"), python::args("returnDistance") = 0), help.c_str()); python::def( "BulkTverskySimilarity", (python::list(*)(const SBV *, python::object, double, double, bool))BulkTverskySimilarity, (python::args("bv1"), python::args("bvList"), python::args("a"), python::args("b"), python::args("returnDistance") = 0)); python::def( "BulkTverskySimilarity", (python::list(*)(const EBV *, python::object, double, double, bool))BulkTverskySimilarity, (python::args("bv1"), python::args("bvList"), python::args("a"), python::args("b"), python::args("returnDistance") = 0), help.c_str()); } DBL_DEF(OnBitSimilarity, BulkOnBitSimilarity, "B(bv1&bv2) / B(bv1|bv2)"); DBL_DEF(AllBitSimilarity, BulkAllBitSimilarity, "(B(bv1) - B(bv1^bv2)) / B(bv1)"); python::def("OnBitProjSimilarity", (DoubleVect(*)(const SBV &, const SBV &))OnBitProjSimilarity); python::def( "OnBitProjSimilarity", (DoubleVect(*)(const EBV &, const EBV &))OnBitProjSimilarity, "Returns a 2-tuple: (B(bv1&bv2) / B(bv1), B(bv1&bv2) / B(bv2))"); python::def("OffBitProjSimilarity", (DoubleVect(*)(const SBV &, const SBV &))OffBitProjSimilarity); python::def("OffBitProjSimilarity", (DoubleVect(*)(const EBV &, const EBV &))OffBitProjSimilarity); python::def("NumBitsInCommon", (int (*)(const SBV &, const SBV &))NumBitsInCommon); python::def("NumBitsInCommon", (int (*)(const EBV &, const EBV &))NumBitsInCommon, "Returns the total number of bits in common between the two " "bit vectors"); python::def("OnBitsInCommon", (IntVect(*)(const SBV &, const SBV &))OnBitsInCommon); python::def( "OnBitsInCommon", (IntVect(*)(const EBV &, const EBV &))OnBitsInCommon, "Returns the number of on bits in common between the two bit vectors"); python::def("OffBitsInCommon", (IntVect(*)(const SBV &, const SBV &))OffBitsInCommon); python::def( "OffBitsInCommon", (IntVect(*)(const EBV &, const EBV &))OffBitsInCommon, "Returns the number of off bits in common between the two bit vectors"); python::def("FoldFingerprint", (SBV * (*)(const SBV &, unsigned int)) FoldFingerprint, (python::arg("bv"), python::arg("foldFactor") = 2), python::return_value_policy<python::manage_new_object>()); python::def("FoldFingerprint", (EBV * (*)(const EBV &, unsigned int)) FoldFingerprint, (python::arg("bv"), python::arg("foldFactor") = 2), python::return_value_policy<python::manage_new_object>(), "Folds the fingerprint by the provided amount. The default, " "foldFactor=2, returns a fingerprint that is half the size of " "the original."); python::def("AllProbeBitsMatch", (bool (*)(const SBV &, const SBV &))AllProbeBitsMatch); python::def("AllProbeBitsMatch", (bool (*)(const EBV &, const EBV &))AllProbeBitsMatch); python::def("AllProbeBitsMatch", (bool (*)(const SBV &, const std::string &))AllProbeBitsMatch); python::def( "AllProbeBitsMatch", (bool (*)(const EBV &, const std::string &))AllProbeBitsMatch, "Returns True if all bits in the first argument match all bits in the \n\ vector defined by the pickle in the second argument.\n"); python::def("BitVectToText", (std::string(*)(const SBV &))BitVectToText); python::def( "BitVectToText", (std::string(*)(const EBV &))BitVectToText, "Returns a string of zeros and ones representing the bit vector."); python::def("BitVectToFPSText", (std::string(*)(const SBV &))BitVectToFPSText); python::def("BitVectToFPSText", (std::string(*)(const EBV &))BitVectToFPSText, "Returns an FPS string representing the bit vector."); python::def("BitVectToBinaryText", (python::object(*)(const SBV &))BVToBinaryText); python::def( "BitVectToBinaryText", (python::object(*)(const EBV &))BVToBinaryText, "Returns a binary string (byte array) representing the bit vector."); } }; void wrap_BitOps() { BitOps_wrapper::wrap(); }
TSS_ADDR equ 0x00007100 PAGE_SIZE equ 0x00001000 SLT_K_CODE equ 0x08 ; 内核代码段选择子 [bits 32] EXTERN intr_exit GLOBAL switch_to ;void swich_to( pcb_t *from, pcb_t *to ) switch_to : push esi push edi push ebx push ebp mov eax, [esp+20] ; from -> eax ;cmp eax, 0 ; 判断from是不是NULL ;jz .get_to_ptr ; from 是从schedule传过来的,所以不会为NULL mov [eax], esp ; 保存的内核栈栈顶到 from .get_to_ptr : mov eax, [esp+24] ; to -> eax mov esp, [eax] ; 现在栈顶已经指向 to 的内核栈 mov ebx, TSS_ADDR ; 进程切换是需要更换TSS中的内核栈 mov ecx, eax ; eax 是 to, to的地址加PAGE_SIZE=内核栈栈顶 add ecx, PAGE_SIZE ; 进程内核栈的栈顶 mov [ebx+4], ecx ; 更换TSS中的esp0 mov ecx, [eax+8] ; pdt的地址 mov cr3, ecx ; 更换pdt jmp SLT_K_CODE:is_first ; 刷新tlb is_first : mov ecx, [eax+4] ; 将 to->all_used_ticks 拿出来 ; 判断是否是第一次调度上线 cmp ecx, 0 ; all_used_ticks == 0,表示第一次上cpu ja .normal_exit ; 不是第一次运行,正常结束 inc dword [eax+4] ; 增加all_used_ticks jmp intr_exit ; 直接跳转退出 .normal_exit : pop ebp pop ebx pop edi pop esi ret
#include "MyGUI_OpenGLESTexture.h" #include "MyGUI_OpenGLESRenderManager.h" #include "MyGUI_OpenGLESDiagnostic.h" #include "MyGUI_OpenGLESPlatform.h" #include "MyGUI_OpenGLESRTTexture.h" #include <GLES3/gl3.h> //#include <GLES3/gl2ext.h> #include "platform.h" namespace MyGUI { OpenGLESTexture::OpenGLESTexture(const std::string& _name, OpenGLESImageLoader* _loader) : mName(_name), mTextureId(0), mProgramId(0), mPboID(0), mWidth(0), mHeight(0), mLock(false), mPixelFormat(0), mDataSize(0), mUsage(0), mBuffer(nullptr), mInternalPixelFormat(0), mAccess(0), mNumElemBytes(0), mImageLoader(_loader), mRenderTarget(nullptr) { } OpenGLESTexture::~OpenGLESTexture() { destroy(); } const std::string& OpenGLESTexture::getName() const { return mName; } void OpenGLESTexture::setUsage(TextureUsage _usage) { mAccess = 0; mUsage = 0; } void OpenGLESTexture::createManual(int _width, int _height, TextureUsage _usage, PixelFormat _format) { createManual(_width, _height, _usage, _format, nullptr); } void OpenGLESTexture::createManual(int _width, int _height, TextureUsage _usage, PixelFormat _format, void* _data) { MYGUI_PLATFORM_ASSERT(!mTextureId, "Texture already exist"); //FIXME перенести в метод mInternalPixelFormat = 0; mPixelFormat = 0; mNumElemBytes = 0; if (_format == PixelFormat::L8) { mInternalPixelFormat = GL_LUMINANCE; mPixelFormat = GL_LUMINANCE; mNumElemBytes = 1; } else if (_format == PixelFormat::L8A8) { mInternalPixelFormat = GL_LUMINANCE_ALPHA; mPixelFormat = GL_LUMINANCE_ALPHA; mNumElemBytes = 2; } else if (_format == PixelFormat::R8G8B8) { mInternalPixelFormat = GL_RGB; mPixelFormat = GL_RGB; mNumElemBytes = 3; } else if (_format == PixelFormat::R8G8B8A8) { mInternalPixelFormat = GL_RGBA; mPixelFormat = GL_RGBA; mNumElemBytes = 4; } else { MYGUI_PLATFORM_EXCEPT("format not support"); } mWidth = _width; mHeight = _height; mDataSize = _width * _height * mNumElemBytes; setUsage(_usage); //MYGUI_PLATFORM_ASSERT(mUsage, "usage format not support"); mOriginalFormat = _format; mOriginalUsage = _usage; // Set unpack alignment to one byte int alignment = 0; glGetIntegerv(GL_UNPACK_ALIGNMENT, (GLint*) &alignment); CHECK_GL_ERROR_DEBUG(); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); CHECK_GL_ERROR_DEBUG(); // создаем тукстуру glGenTextures(1, (GLuint*) &mTextureId); CHECK_GL_ERROR_DEBUG(); glBindTexture(GL_TEXTURE_2D, mTextureId); CHECK_GL_ERROR_DEBUG(); // Set texture parameters glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); CHECK_GL_ERROR_DEBUG(); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); CHECK_GL_ERROR_DEBUG(); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); CHECK_GL_ERROR_DEBUG(); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); CHECK_GL_ERROR_DEBUG(); glTexImage2D( GL_TEXTURE_2D, 0, mInternalPixelFormat, mWidth, mHeight, 0, mPixelFormat, GL_UNSIGNED_BYTE, (GLvoid*)_data); CHECK_GL_ERROR_DEBUG(); glBindTexture(GL_TEXTURE_2D, 0); CHECK_GL_ERROR_DEBUG(); // Restore old unpack alignment //glPixelStorei( GL_UNPACK_ALIGNMENT, alignment ); //CHECK_GL_ERROR_DEBUG(); #ifdef PixelBufferObjectSupported if (!_data && OpenGLESRenderManager::getInstance().isPixelBufferObjectSupported()) { //создаем текстурнный буфер //glGenBuffersARB(1, (GLuint *)&mPboID); //glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, mPboID); //glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, mDataSize, 0, mUsage); //glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0); glGenBuffers(1, (GLuint*)&mPboID); CHECK_GL_ERROR_DEBUG(); glBindBuffer(GL_PIXEL_UNPACK_BUFFER, mPboID); CHECK_GL_ERROR_DEBUG(); glBufferData(GL_PIXEL_UNPACK_BUFFER, mDataSize, 0, mUsage); CHECK_GL_ERROR_DEBUG(); glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); CHECK_GL_ERROR_DEBUG(); } #endif } void OpenGLESTexture::destroy() { if (mRenderTarget != nullptr) { delete mRenderTarget; mRenderTarget = nullptr; } if (mTextureId != 0) { glDeleteTextures(1, (GLuint*)&mTextureId); mTextureId = 0; } if (mPboID != 0) { glDeleteBuffers(1, (GLuint*)&mPboID); mPboID = 0; } mWidth = 0; mHeight = 0; mLock = false; mPixelFormat = 0; mDataSize = 0; mUsage = 0; mBuffer = nullptr; mInternalPixelFormat = 0; mAccess = 0; mNumElemBytes = 0; mOriginalFormat = PixelFormat::Unknow; mOriginalUsage = TextureUsage::Default; } void* OpenGLESTexture::lock(TextureUsage _access) { MYGUI_PLATFORM_ASSERT(mTextureId, "Texture is not created"); /* if (_access == TextureUsage::Read) { glBindTexture(GL_TEXTURE_2D, mTextureId); CHECK_GL_ERROR_DEBUG(); mBuffer = new unsigned char[mDataSize]; //glGetTexImage(GL_TEXTURE_2D, 0, mPixelFormat, GL_UNSIGNED_BYTE, mBuffer); mLock = false; return mBuffer; }*/ // bind the texture glBindTexture(GL_TEXTURE_2D, mTextureId); CHECK_GL_ERROR_DEBUG(); if (!OpenGLESRenderManager::getInstance().isPixelBufferObjectSupported()) { //Fallback if PBO's are not supported mBuffer = new unsigned char[mDataSize]; } else { #ifdef PixelBufferObjectSupported // bind the PBO //glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, mPboID); glBindBuffer(GL_PIXEL_UNPACK_BUFFER, mPboID); CHECK_GL_ERROR_DEBUG(); // Note that glMapBufferARB() causes sync issue. // If GPU is working with this buffer, glMapBufferARB() will wait(stall) // until GPU to finish its job. To avoid waiting (idle), you can call // first glBufferDataARB() with nullptr pointer before glMapBufferARB(). // If you do that, the previous data in PBO will be discarded and // glMapBufferARB() returns a new allocated pointer immediately // even if GPU is still working with the previous data. //glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, mDataSize, 0, mUsage); glBufferData(GL_PIXEL_UNPACK_BUFFER, mDataSize, 0, mUsage); CHECK_GL_ERROR_DEBUG(); // map the buffer object into client's memory //mBuffer = (GLubyte*)glMapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, mAccess); mBuffer = (GLubyte*)glMapBufferOES(GL_PIXEL_UNPACK_BUFFER_ARB, mAccess); CHECK_GL_ERROR_DEBUG(); if (!mBuffer) { //glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0); glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, 0); CHECK_GL_ERROR_DEBUG(); glBindTexture(GL_TEXTURE_2D, 0); CHECK_GL_ERROR_DEBUG(); MYGUI_PLATFORM_EXCEPT("Error texture lock"); } #endif } mLock = true; return mBuffer; } void OpenGLESTexture::unlock() { if (!mLock && mBuffer) { delete (unsigned char*)mBuffer; mBuffer = nullptr; glBindTexture(GL_TEXTURE_2D, 0); CHECK_GL_ERROR_DEBUG(); return; } MYGUI_PLATFORM_ASSERT(mLock, "Texture is not locked"); if (!OpenGLESRenderManager::getInstance().isPixelBufferObjectSupported()) { //Fallback if PBO's are not supported glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, mWidth, mHeight, mPixelFormat, GL_UNSIGNED_BYTE, mBuffer); CHECK_GL_ERROR_DEBUG(); delete (unsigned char*)mBuffer; } else { #ifdef PixelBufferObjectSupported // release the mapped buffer //glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB); glUnmapBufferOES(GL_PIXEL_UNPACK_BUFFER_ARB); CHECK_GL_ERROR_DEBUG(); // copy pixels from PBO to texture object // Use offset instead of ponter. glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, mWidth, mHeight, mPixelFormat, GL_UNSIGNED_BYTE, 0); CHECK_GL_ERROR_DEBUG(); // it is good idea to release PBOs with ID 0 after use. // Once bound with 0, all pixel operations are back to normal ways. //glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0); glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, 0); CHECK_GL_ERROR_DEBUG(); #endif } glBindTexture(GL_TEXTURE_2D, 0); CHECK_GL_ERROR_DEBUG(); mBuffer = nullptr; mLock = false; } void OpenGLESTexture::loadFromFile(const std::string& _filename) { destroy(); if (mImageLoader) { int width = 0; int height = 0; PixelFormat format = PixelFormat::Unknow; void* data = mImageLoader->loadImage(width, height, format, _filename); if (data) { createManual(width, height, TextureUsage::Static | TextureUsage::Write, format, data); delete (unsigned char*)data; } } } void OpenGLESTexture::saveToFile(const std::string& _filename) { if (mImageLoader) { void* data = lock(TextureUsage::Read); mImageLoader->saveImage(mWidth, mHeight, mOriginalFormat, data, _filename); unlock(); } } void OpenGLESTexture::setShader(const std::string& _shaderName) { mProgramId = OpenGLESRenderManager::getInstance().getShaderProgramId(_shaderName); } IRenderTarget* OpenGLESTexture::getRenderTarget() { if (mRenderTarget == nullptr) mRenderTarget = new OpenGLESRTTexture(mTextureId); return mRenderTarget; } unsigned int OpenGLESTexture::getTextureId() const { return mTextureId; } unsigned int OpenGLESTexture::getShaderId() const { return mProgramId; } } // namespace MyGUI
; A083099: a(n) = 2*a(n-1) + 6*a(n-2), a(0) = 0, a(1) = 1. ; 0,1,2,10,32,124,440,1624,5888,21520,78368,285856,1041920,3798976,13849472,50492800,184082432,671121664,2446737920,8920205824,32520839168,118562913280,432250861568,1575879202816,5745263575040,20945802366976,76363186184192,278401186570240,1014981490245632,3700370099912704 add $0,1 mov $4,2 lpb $0,1 sub $0,1 mov $3,$1 mov $1,$2 mul $1,3 add $4,$3 mul $4,2 mov $2,$4 lpe div $1,12
#include <torch/script.h> #include <gtest/gtest.h> #include <test/cpp/api/support.h> using namespace torch::autograd; using namespace torch::test; namespace { torch::Tensor functional_op(torch::Tensor& x) { return x * x; } void inplace_op(torch::Tensor& x) { x.mul_(1); } torch::Tensor view_op(torch::Tensor& x) { return x.view({2, 3}); } /* Only the following combos of Autograd & ADInplaceOrView keys on tensors are valid: - Autograd=true, ADInplaceOrView=true (normal tensor) - Autograd=false, ADInplaceOrView=false (inference tensor) Tensors created in InferenceMode are mostly inference tensors. The only exception is that view of normal tensors created in InferenceMode still produce normal tensor. */ bool is_inference_tensor(torch::Tensor& x) { c10::DispatchKeySet ks = x.key_set(); bool has_Autograd = ks.has(c10::DispatchKey::AutogradCPU); bool has_ADInplaceOrView = ks.has(c10::DispatchKey::ADInplaceOrView); // They must be either both true or false. bool is_inference_tensor = !has_Autograd && !has_ADInplaceOrView && x.is_leaf(); return is_inference_tensor; } void assert_TLS_states(bool inference_mode) { ASSERT_EQ(InferenceMode::is_enabled(), inference_mode); ASSERT_FALSE(c10::impl::tls_is_dispatch_key_excluded(c10::DispatchKey::ADInplaceOrView)); ASSERT_FALSE(c10::impl::tls_is_dispatch_keyset_included(c10::autograd_dispatch_keyset)); ASSERT_EQ(c10::impl::tls_is_dispatch_keyset_excluded(c10::autograd_dispatch_keyset), inference_mode); ASSERT_EQ(c10::impl::tls_is_dispatch_key_included(c10::DispatchKey::ADInplaceOrView), !inference_mode); ASSERT_EQ(GradMode::is_enabled(), !inference_mode); } } // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) TEST(InferenceModeTest, TestTLSState) { assert_TLS_states(false); { InferenceMode guard; assert_TLS_states(true); { InferenceMode guard(false); assert_TLS_states(false); } assert_TLS_states(true); } assert_TLS_states(false); } // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) TEST(InferenceModeTest, TestInferenceTensorCreation) { { InferenceMode guard; // New tensor created through constructors are inference tensors. torch::Tensor c = torch::ones({1, 2, 3}); ASSERT_FALSE(c.requires_grad()); ASSERT_TRUE(is_inference_tensor(c)); // requires_grad doesn't change inference tensor behavior inside InferenceMode. torch::Tensor tmp = torch::ones({1, 2, 3}).set_requires_grad(true); ASSERT_TRUE(tmp.requires_grad()); ASSERT_TRUE(is_inference_tensor(tmp)); tmp = torch::ones({1, 2, 3}).set_requires_grad(false); ASSERT_FALSE(tmp.requires_grad()); ASSERT_TRUE(is_inference_tensor(tmp)); } } // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) TEST(InferenceModeTest, TestExistingAutogradSession) { torch::Tensor s = torch::ones({1, 2, 3}).set_requires_grad(true); torch::Tensor a = s.clone(); // Save `a` in an existing autograd session torch::Tensor out = a * a; { InferenceMode guard; inplace_op(a); } // Performing backward should trigger error since `a`'s version has been bumped. ASSERT_THROWS_WITH(out.backward(torch::ones_like(out)), "one of the variables needed for gradient computation has been modified by an inplace operation") } // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) TEST(InferenceModeTest, TestInferenceTensorInInferenceModeFunctionalOp) { c10::InferenceMode guard; for (bool requires_grad : {true, false}) { torch::Tensor c = torch::ones({1, 2, 3}).set_requires_grad(requires_grad); torch::Tensor func_out = functional_op(c); // go through kernels: CPU ASSERT_TRUE(is_inference_tensor(func_out)); ASSERT_FALSE(func_out.requires_grad()); } } // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) TEST(InferenceModeTest, TestInferenceTensorInInferenceModeInplaceOp) { c10::InferenceMode guard; for (bool requires_grad : {true, false}) { torch::Tensor c = torch::ones({1, 2, 3}).set_requires_grad(requires_grad); inplace_op(c); // go through kernels: CPU ASSERT_TRUE(is_inference_tensor(c)); ASSERT_EQ(c.requires_grad(), requires_grad); } } // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) TEST(InferenceModeTest, TestInferenceTensorInInferenceModeViewOp) { c10::InferenceMode guard; for (bool requires_grad : {true, false}) { torch::Tensor c = torch::ones({1, 2, 3}).set_requires_grad(requires_grad); torch::Tensor view_out = view_op(c); // go through kernels: CPU ASSERT_TRUE(is_inference_tensor(view_out)); // Note this is different from NoGradMode but makes sense. ASSERT_FALSE(view_out.requires_grad()); ASSERT_FALSE(view_out.is_view()); } } // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) TEST(InferenceModeTest, TestInferenceTensorInNormalModeFunctionalOp) { torch::Tensor inference_tensor; for (bool requires_grad: {true, false}) { { InferenceMode guard; inference_tensor = torch::ones({1, 2, 3}).set_requires_grad(requires_grad); } // Due to issue #54614, this might run slower compared to InferenceMode since // intermediate tensors are normal tensors, and they might dispatch to VariableType // kernels. This is fine since users can easily fix it by moving // it inside InferenceMode block. torch::Tensor tmp = functional_op(inference_tensor); // go through kernels: ADInplaceOrView(fallthrough), CPU ASSERT_FALSE(is_inference_tensor(tmp)); ASSERT_FALSE(tmp.requires_grad()); } } // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) TEST(InferenceModeTest, TestInferenceTensorInNormalModeInplaceOp) { torch::Tensor inference_tensor; for (bool requires_grad: {true, false}) { { InferenceMode guard; inference_tensor = torch::ones({1, 2, 3}).set_requires_grad(requires_grad); } ASSERT_THROWS_WITH(inplace_op(inference_tensor), // go through kernels: ADInplaceOrView, CPU "Inplace update to inference tensor outside InferenceMode is not allowed"); } } // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) TEST(InferenceModeTest, TestInferenceTensorInNormalModeViewOp) { torch::Tensor inference_tensor; for (bool requires_grad: {true, false}) { { InferenceMode guard; inference_tensor = torch::ones({1, 2, 3}).set_requires_grad(requires_grad); } torch::Tensor out = view_op(inference_tensor); // go through kernels: ADInplaceOrView, CPU ASSERT_TRUE(is_inference_tensor(out)); ASSERT_FALSE(out.requires_grad()); ASSERT_FALSE(out.is_view()); ASSERT_TRUE(out.is_leaf()); } } // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) TEST(InferenceModeTest, TestNormalTensorInplaceOutputInInferenceMode) { for (bool requires_grad: {true, false}) { torch::Tensor s = torch::ones({1, 2, 3}).set_requires_grad(requires_grad); torch::Tensor a = s.clone(); { c10::InferenceMode guard; inplace_op(a); // go through kernels: ADInplaceOrView, CPU ASSERT_FALSE(is_inference_tensor(a)); ASSERT_EQ(a.requires_grad(), requires_grad); // inplace -> inplace inplace_op(a); // go through kernels: ADInplaceOrView, CPU ASSERT_FALSE(is_inference_tensor(a)); ASSERT_EQ(a.requires_grad(), requires_grad); // inplace -> inplace -> view torch::Tensor view_out = view_op(a); // go through kernels: ADInplaceOrView, CPU ASSERT_FALSE(is_inference_tensor(view_out)); ASSERT_EQ(view_out.requires_grad(), requires_grad); } } } // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) TEST(InferenceModeTest, TestNormalTensorInplaceOutputInNormalMode) { for (bool requires_grad: {true, false}) { torch::Tensor s = torch::ones({1, 2, 3}).set_requires_grad(requires_grad); torch::Tensor a = s.clone(); { c10::InferenceMode guard; inplace_op(a); // go through kernels: ADInplaceOrView, CPU ASSERT_FALSE(is_inference_tensor(a)); ASSERT_EQ(a.requires_grad(), requires_grad); } torch::Tensor tmp = functional_op(a); // go through kernels: VariableType, ADInplaceOrView(fallthrough), CPU ASSERT_FALSE(is_inference_tensor(tmp)); ASSERT_EQ(tmp.requires_grad(), requires_grad); inplace_op(a); // go through kernels: VariableType, ADInplaceOrView, CPU ASSERT_FALSE(is_inference_tensor(a)); ASSERT_EQ(a.requires_grad(), requires_grad); tmp = view_op(a); // go through kernels: VariableType, ADInplaceOrView, CPU ASSERT_FALSE(is_inference_tensor(tmp)); ASSERT_EQ(tmp.requires_grad(), requires_grad); } } // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) TEST(InferenceModeTest, TestNormalTensorViewOutputInInferenceMode) { for (bool requires_grad: {true, false}) { torch::Tensor s = torch::ones({1, 2, 3}).set_requires_grad(requires_grad); torch::Tensor a = s.clone(); torch::Tensor view_out, tmp; { c10::InferenceMode guard; // View ops on normal tensor produce normal tensors as output. // - For view ops it has both dispatch keys since due to the way we create // view Tensors in alias_with_sizes_and_strides: // ``` // auto impl = c10::make_intrusive<TensorImpl>( // Storage(self.storage()), self.key_set(), self.dtype()); // ``` // In addition, these view output tensors are normal in the sense they // have both Autograd and ADInplaceOrView keys. But they're still special // since they'll have CreationMeta::INFERENCE_MODE. In other words they behave // exactly the same as a view tensor created in no_grad mode. view_out = view_op(a); // go through kernels: ADInplaceOrView, CPU ASSERT_FALSE(is_inference_tensor(view_out)); assert_tensor_creation_meta(view_out, CreationMeta::INFERENCE_MODE); ASSERT_EQ(view_out.requires_grad(), requires_grad); ASSERT_TRUE(view_out.is_leaf()); // view -> view tmp = view_op(view_out); // go through kernels: ADInplaceOrView, CPU ASSERT_FALSE(is_inference_tensor(tmp)); assert_tensor_creation_meta(tmp, CreationMeta::INFERENCE_MODE); ASSERT_EQ(tmp.requires_grad(), requires_grad); ASSERT_TRUE(tmp.is_leaf()); // view -> view -> inplace inplace_op(tmp); // kernels: ADInplaceOrView, CPU assert_tensor_creation_meta(tmp, CreationMeta::INFERENCE_MODE); ASSERT_FALSE(is_inference_tensor(tmp)); ASSERT_EQ(tmp.requires_grad(), requires_grad); ASSERT_TRUE(tmp.is_leaf()); ASSERT_EQ(a._version(), tmp._version()); } } } // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) TEST(InferenceModeTest, TestNormalTensorViewOutputInNormalMode) { for (bool requires_grad: {true, false}) { torch::Tensor s = torch::ones({1, 2, 3}).set_requires_grad(requires_grad); torch::Tensor a = s.clone(); torch::Tensor view_out, tmp; { c10::InferenceMode guard; view_out = view_op(a); // go through kernels: ADInplaceOrView, CPU ASSERT_FALSE(is_inference_tensor(view_out)); assert_tensor_creation_meta(view_out, CreationMeta::INFERENCE_MODE); ASSERT_EQ(view_out.requires_grad(), requires_grad); ASSERT_TRUE(view_out.is_leaf()); } tmp = functional_op(view_out); ASSERT_FALSE(is_inference_tensor(view_out)); ASSERT_EQ(tmp.requires_grad(), requires_grad); if (requires_grad) { ASSERT_THROWS_WITH(inplace_op(view_out), // go through kernels: VariableType, ADInplaceOrView, CPU "A view was created in inference mode and is being modified inplace") } else { inplace_op(view_out); } tmp = view_op(view_out); ASSERT_FALSE(is_inference_tensor(view_out)); ASSERT_EQ(tmp.requires_grad(), requires_grad); } } // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) TEST(InferenceModeTest, TestMixInferenceAndNormalTensorFunctionalOp) { for (bool requires_grad: {true, false}) { torch::Tensor s = torch::ones({1, 2, 3}).set_requires_grad(requires_grad); torch::Tensor c; { InferenceMode guard; c = torch::ones({1, 2, 3}).set_requires_grad(requires_grad); } // add(Tensor, Tensor) is safe with inference tensor since it doesn't save any variable for backward. torch::Tensor out = c.add(s); // go through kernels: VariableType, ADInplaceOrView(fallthrough), CPU ASSERT_FALSE(is_inference_tensor(out)); ASSERT_EQ(out.requires_grad(), requires_grad); if (requires_grad) { // leaf inference tensor with requires_grad=true can still have gradient. // Note this behavior is different from NoGradMode which has empty grad. out.backward(torch::ones_like(out)); assert_tensor_equal(c.grad(), torch::ones_like(c)); } if (requires_grad) { // mul(self, other) saves variable when requires_grad=true ASSERT_THROWS_WITH(c.mul(s), "Inference tensors cannot be saved for backward."); // Inference tensor in TensorList input std::vector<torch::Tensor> inputs = {s, c}; ASSERT_THROWS_WITH(torch::stack(inputs), // go through kernels: VariableType(ERROR)!, ADInplaceOrView(fallthrough), CPU "Inference tensors cannot be saved for backward.") } } } // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) TEST(InferenceModeTest, TestMixInferenceAndNormalTensorInplaceOp) { for (bool requires_grad: {true, false}) { torch::Tensor s = torch::ones({1, 2, 3}).set_requires_grad(requires_grad); torch::Tensor a = s.clone(); torch::Tensor c; { InferenceMode guard; c = torch::ones({1, 2, 3}); } if (requires_grad) { ASSERT_THROWS_WITH(a.mul_(c), // go through kernels: VariableType(ERROR!), InferenceMode, CPU "Inference tensors cannot be saved for backward."); ASSERT_THROWS_WITH(torch::mul_out(/*out=*/c, s, s), // go through kernels: VariableType(ERROR!), ADInplaceOrView, CPU "out=... arguments don't support automatic differentiation, but one of the arguments requires grad") } else { a.mul_(c); ASSERT_THROWS_WITH(torch::mul_out(/*out=*/c, s, s), // go through kernels: VariableType, ADInplaceOrView(ERROR!), CPU "Inplace update to inference tensor outside InferenceMode is not allowed"); } } } // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) TEST(InferenceModeTest, TestMixInferenceAndNormalTensorViewOp) { for (bool requires_grad: {true, false}) { torch::Tensor s = torch::ones({1, 2, 3}).set_requires_grad(requires_grad); torch::Tensor c; { InferenceMode guard; c = torch::ones({1, 2, 3}); } // view_as is a composite op which calls view() with only one tensor argument. // So there isn't a mixed inference tensor and normal tensor inputs for view ops. torch::Tensor tmp1 = c.view_as(s); // go through kernels: ADInplaceOrView, CPU ASSERT_TRUE(is_inference_tensor(tmp1)); ASSERT_FALSE(tmp1.requires_grad()); // This is fine since it's equivalent as s.view(c.sizes()) which // isn't a mixed input scenario. torch::Tensor tmp2 = s.view_as(c); // go through kernels: VariableType, ADInplaceOrView, CPU ASSERT_FALSE(is_inference_tensor(tmp2)); ASSERT_EQ(tmp2.requires_grad(), requires_grad); } } // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) TEST(InferenceModeTest, TestHandleDirectViewOnRebase) { for (bool requires_grad: {true, false}) { torch::Tensor s = torch::ones({1, 2, 3}).set_requires_grad(requires_grad); torch::Tensor a = s.clone(); torch::Tensor view_out; { InferenceMode guard; view_out = view_op(a); // go through kernels: ADInplaceOrView, CPU } if (requires_grad) { ASSERT_THROWS_WITH(inplace_op(view_out), "A view was created in inference mode and is being modified inplace") } else { inplace_op(view_out); } } } // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) TEST(InferenceModeTest, TestHandleInDirectViewOnRebase) { for (bool requires_grad: {true, false}) { torch::Tensor s = torch::ones({1, 2, 3}).set_requires_grad(requires_grad); torch::Tensor a = s.clone(); torch::Tensor view_out; { InferenceMode guard; view_out = view_op(a); // go through kernels: ADInplaceOrView, CPU } inplace_op(a); if (requires_grad) { ASSERT_THROWS_WITH(view_out.grad_fn(), "A view was created in inference mode and its base or another view of its base has been modified inplace"); } else { view_out.grad_fn(); } } } // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) TEST(InferenceModeTest, TestCreationMetaPropagation) { torch::Tensor s = torch::ones({1, 2, 3}).set_requires_grad(true); torch::Tensor b, c; { InferenceMode guard; b = s.view_as(s); } ASSERT_THROWS_WITH(b.add_(1), "A view was created in inference mode and is being modified inplace"); { AutoGradMode mode(false); c = b.view_as(b); } ASSERT_THROWS_WITH(c.add_(1), "A view was created in inference mode and is being modified inplace"); } // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) TEST(InferenceModeTest, TestCreationMetaPropagationInput) { torch::Tensor s = torch::ones({2, 2, 3}).set_requires_grad(true); auto s_view = s.view_as(s); std::vector<at::Tensor> b, c; { InferenceMode guard; b = s_view.split_with_sizes({1, 1}); s = s.view_as(s); c = s.split_with_sizes({1, 1}); } for (auto& b_el: b) { // TODO: fix the codegen not setting these properly in no_grad/inference mode // The next line should be assert_tensor_creation_meta(b_el, CreationMeta::INFERENCE_MODE); assert_tensor_creation_meta(b_el, CreationMeta::MULTI_OUTPUT_SAFE); // The error in the next line should be "A view was created in inference mode and is being..." ASSERT_THROWS_WITH(b_el.add_(1), "This view is an output of a function that returns multiple views."); } for (auto& c_el: c) { assert_tensor_creation_meta(c_el, CreationMeta::INFERENCE_MODE); ASSERT_THROWS_WITH(c_el.add_(1), "A view was created in inference mode and is being modified inplace"); } } // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) TEST(InferenceModeTest, TestInplaceCopyOnInferenceTensor) { for (bool requires_grad: {true, false}) { torch::Tensor s = torch::ones({1, 2, 3}).set_requires_grad(requires_grad); torch::Tensor t; { InferenceMode guard; t = torch::ones({1, 2, 3}); t.copy_(s); ASSERT_TRUE(is_inference_tensor(t)); ASSERT_FALSE(t.requires_grad()); } ASSERT_THROWS_WITH(t.copy_(s), "Inplace update to inference tensor outside InferenceMode is not allowed"); } } // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) TEST(InferenceModeTest, TestSetRequiresGradInNormalMode) { torch::Tensor t; { InferenceMode guard; t = torch::ones({1, 2, 3}); } t.set_requires_grad(false); ASSERT_THROWS_WITH(t.set_requires_grad(true), "Setting requires_grad=True on inference tensor outside InferenceMode is not allowed."); } // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) TEST(InferenceModeTest, TestAccessVersionCounter) { torch::Tensor t; { InferenceMode guard; t = torch::ones({1, 2, 3}); ASSERT_THROWS_WITH(t.unsafeGetTensorImpl()->version_counter().current_version(), "Inference tensor do not track version counter."); t.unsafeGetTensorImpl()->bump_version(); } ASSERT_THROWS_WITH(t.unsafeGetTensorImpl()->version_counter().current_version(), "Inference tensor do not track version counter."); ASSERT_THROWS_WITH(t.unsafeGetTensorImpl()->bump_version(), "Inplace update to inference tensor outside InferenceMode is not allowed."); // Suggested workaround torch::Tensor c = t.clone(); uint32_t v = c.unsafeGetTensorImpl()->version_counter().current_version(); c.unsafeGetTensorImpl()->bump_version(); ASSERT_EQ(c.unsafeGetTensorImpl()->version_counter().current_version(), v + 1); } // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) TEST(InferenceModeTest, TestInplaceUpdateInferenceTensorWithNormalTensor) { torch::Tensor s = torch::ones({1, 2, 3}); torch::Tensor t; { InferenceMode guard; t = torch::ones({1, 2, 3}); // Testing both copy_ from VariableTypeManual and add_ from generated code. s.copy_(t); s.add_(t); t.add_(s); t.copy_(s); } s.copy_(t); s.add_(t); ASSERT_THROWS_WITH(t.copy_(s), "Inplace update to inference tensor outside InferenceMode is not allowed"); ASSERT_THROWS_WITH(t.add_(s), "Inplace update to inference tensor outside InferenceMode is not allowed"); } // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) TEST(InferenceModeTest, TestComplexViewInInferenceMode) { torch::Tensor s = torch::ones({3, 3, 2}); torch::Tensor t = torch::view_as_complex(s); { InferenceMode guard; torch::Tensor tmp; tmp = torch::view_as_real(t); ASSERT_FALSE(is_inference_tensor(tmp)); tmp = torch::view_as_complex(s); ASSERT_FALSE(is_inference_tensor(tmp)); torch::Tensor e = torch::ones({3, 3, 2}); tmp = torch::view_as_complex(e); ASSERT_TRUE(is_inference_tensor(tmp)); tmp = torch::view_as_real(tmp); ASSERT_TRUE(is_inference_tensor(tmp)); } } // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) TEST(InferenceModeTest, TestComplexViewInNormalMode) { torch::Tensor s; { InferenceMode guard; s = torch::ones({3, 3, 2}); } torch::Tensor tmp = torch::view_as_complex(s); ASSERT_TRUE(is_inference_tensor(tmp)); tmp = torch::view_as_real(tmp); ASSERT_TRUE(is_inference_tensor(tmp)); } // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) TEST(InferenceModeTest, TestCustomFunction) { struct MyFunction : public Function<MyFunction> { static Variable forward(AutogradContext *ctx, Variable var1, int mul, Variable var2) { ctx->saved_data["mul"] = mul; ctx->save_for_backward({var1, var2}); return var1 + mul*var2 + var1*var2; } static variable_list backward(AutogradContext *ctx, variable_list grad_output) { int mul = ctx->saved_data["mul"].toInt(); auto saved = ctx->get_saved_variables(); auto var1 = saved[0]; auto var2 = saved[1]; variable_list output = {grad_output[0] + grad_output[0]*var2, Variable(), grad_output[0] * mul + grad_output[0] * var1}; return output; } }; { InferenceMode guard; torch::Tensor var1 = torch::ones({3, 3}).set_requires_grad(true); auto var2 = var1.clone(); int mul = 2; // If InferenceMode didn't set NoGradGuard automatically, this line // would error out when trying to save `var1` and `var2` for backward. auto y = MyFunction::apply(var1, mul, var2); torch::Tensor expected = var1 + mul * var2 + var1 * var2; assert_tensor_equal(y, expected); } } // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) TEST(InferenceModeTest, TestLegacyAutoNonVariableTypeModeWarning) { bool prev = c10::Warning::get_warnAlways(); c10::Warning::set_warnAlways(true); { WarningCapture warnings; at::AutoNonVariableTypeMode guard; ASSERT_TRUE( warnings.str().find("AutoNonVariableTypeMode is deprecated") != std::string::npos); } c10::Warning::set_warnAlways(prev); }
#include "p16f873.inc" c1 equ 0x20 ; for delays c2 equ 0x21 ; for delays LCDTemp equ 0x22 ; Yo keep LCD data tempararily LCDPORT equ PORTB LCDTRIS equ TRISB button_pressed equ 0x25 ; to store the pressed button KEYPORT equ PORTC KEYTRIS equ TRISC e1 equ 0x40 VALUE equ 0x30 org 0x00 goto Main Main: call LCD_Init call Key_Init movlw b'11000000' ;Goto 2nd row call LCD_Ins movlw b'00001111' ; Turn on Display/Cursor call LCD_Ins ;call Delay ;movlw b'00000001' ; Clear display ;call LCD_Ins movlw 0x40 movwf e1 movlw 'A' call Write_EEPROM incf e1,1 movlw 'B' call Write_EEPROM movlw 0x40 movwf e1 call Read_EEPROM call LCD_char incf e1,1 call Read_EEPROM call LCD_char l call Key_Check movf button_pressed,0 call LCD_char call Delay5 goto l Read_EEPROM: bsf STATUS, 6 ; bcf STATUS, 5 ;Bank 2 movf e1, 0 ;Write address movwf EEADR ;to read from bsf STATUS, 5 ;Bank 3 bcf EECON1, 7 ;Point to Data memory bsf EECON1, 0 ;Start read operation bcf STATUS, 5 ;Bank 2 movf EEDATA, 0 ;W = EEDATA bcf STATUS, 6 ;select bank 0 return Write_EEPROM: movwf VALUE ; move the value to register bsf STATUS, 6 ; ;bsf STATUS, 5 ;Bank 3 ;btfsc EECON1, 1 ;Wait for ;goto $-1 ;write to finish ;bcf STATUS, 5 ;Bank 2 movf e1, 0 ;Address to movwf EEADR ;write to movf VALUE, 0 ;Data to movwf EEDATA ;write bsf STATUS, 5 ;Bank 3 bcf EECON1, 7 ;Point to Data memory bsf EECON1, 2 ;Enable writes ;Only disable interrupts ;bcf INTCON, GIE ;if already enabled, ;otherwise discard movlw 0x55 ;Write 55h to movwf EECON2 ;EECON2 movlw 0xAA ;Write AAh to movwf EECON2 ;EECON2 bsf EECON1, 1 ;Start write operation ;Only enable interrupts ;bsf INTCON, GIE ;if using interrupts, ;otherwise discard bcf EECON1, 2 ;Disable writes btfsc EECON1, 1 ;Wait for write to finish goto $-1 bcf STATUS,5 bcf STATUS,6 ;select bank 0 return ;LCD routines........... LCD_Init: ; initialize LED to 4 bit mode bsf STATUS, 5 ; select bank 1 movlw b'00000000' ; LCDPORT Outputs movwf LCDTRIS ; Change PortB to output bcf STATUS, 5 ; select bank 0 call Delay5 ; Wait 15 msecs call Delay5 call Delay5 movlw b'00110000' ; Send the Reset Instruction movwf LCDPORT call Pulse_e ; Pulse LCD_E call Delay5 ; Delay 5ms call Pulse_e ; Pulse LCD_E call Delay2 ; Delay of 2ms call Pulse_e ; Pulse LCD_E call Delay2 ; Delay of 2ms movlw 0x020 ; Send the Data Length Specification movwf LCDPORT call Pulse_e ; Pulse LCD_E call Delay2 ; Delay of 2ms movlw b'00101000' ; Set Interface Length call LCD_Ins movlw b'00010000' ; Turn Off Display call LCD_Ins movlw b'00000001' ; Clear Display RAM call LCD_Ins movlw b'00000110' ; Set Cursor Movement call LCD_Ins movlw b'00001100' ; Turn on Display/Cursor call LCD_Ins movlw b'00000001' ; Clear LCD call LCD_Ins return ; LCD_Ins: ;Send the Instruction to the LCD movwf LCDTemp ; Save the Value andlw b'11110000' ; High Nibble first movwf LCDPORT bcf LCDPORT,2 call Pulse_e swapf LCDTemp, 0 ; Low Nibble Second andlw b'11110000' movwf LCDPORT bcf LCDPORT,2 call Pulse_e call Delay2 ; wait 2 ms return ; LCD_char: ; Send the Character to the LCD movwf LCDTemp ; Save the Value andlw 0xF0 ; High Nibble first movwf LCDPORT bsf LCDPORT,2 call Pulse_e ; swapf LCDTemp, 0 ; Low Nibble Second andlw 0xF0 movwf LCDPORT bsf LCDPORT,2 call Pulse_e call Delay2 nop return Pulse_e: ;LCD Enable pulse to write data from LCDPORT into LCD module. bsf LCDPORT,3 nop bcf LCDPORT,3 nop return ;Keypad routines............. Key_Init: ; initalize keypad bsf STATUS,5 ;select bank 1 movlw b'11110000' ;0-4 outputs,5-7 inputs. movwf KEYTRIS bcf STATUS,5 ;select bank0 clrf button_pressed ;clear the button return Key_Check: ; check what button has been pressed movlw 'X' movwf button_pressed bsf KEYPORT, 0 ; scan the first column of keys btfsc KEYPORT, 4 ; movlw '7' ; 7 is pressed. btfsc KEYPORT, 5 ; movlw '4' ; 4 is pressed. btfsc KEYPORT, 6 ; movlw '1' ; 1 is pressed. btfsc KEYPORT, 7 ; movlw '*' ; * is pressed. bcf KEYPORT, 0 ; take first column low. bsf KEYPORT, 1 ; scan the second column of keys btfsc KEYPORT, 4 ; movlw '8' ; 8 is pressed. btfsc KEYPORT, 5 ; movlw '5' ; 5 is pressed. btfsc KEYPORT, 6 ; movlw '2' ; 2 is pressed. btfsc KEYPORT, 7 ; movlw '0' ; 0 is pressed. bcf KEYPORT, 1 ; take second column low. bsf KEYPORT, 2 ; scan the third column of keys btfsc KEYPORT, 4 ; movlw '9' ; 9 is pressed. btfsc KEYPORT, 5 ; movlw '6' ; 6 is pressed. btfsc KEYPORT, 6 ; movlw '3' ; 3 is pressed. btfsc KEYPORT, 7 ; movlw '#' ; 1 is pressed. bcf KEYPORT, 2 ; take rhird column low. bsf KEYPORT, 3 ; scan the last column of keys btfsc KEYPORT, 4 ; movlw 'A' ; A is pressed. btfsc KEYPORT, 5 ; movlw 'B' ; B is pressed. btfsc KEYPORT, 6 ; movlw 'C' ; C is pressed. btfsc KEYPORT, 7 ; movlw 'D' ; D is pressed. bcf KEYPORT, 3 ; take last column low. movwf button_pressed movlw 'X' subwf button_pressed,0 btfsc STATUS,Z goto Key_Check ; return ; Delay routines........ Delay5: ;5ms movlw d'2' movwf c1 goto Delay Delay: ;0.7s decfsz c1,1 goto Delay decfsz c2,1 goto Delay return Delay2: ;2ms decfsz c1,1 goto Delay2 return end
; A011548: Decimal expansion of sqrt(2) rounded to n places. ; Submitted by Christian Krause ; 1,14,141,1414,14142,141421,1414214,14142136,141421356,1414213562,14142135624,141421356237,1414213562373,14142135623731,141421356237310,1414213562373095,14142135623730950,141421356237309505,1414213562373095049,14142135623730950488,141421356237309504880,1414213562373095048802,14142135623730950488017,141421356237309504880169,1414213562373095048801689,14142135623730950488016887,141421356237309504880168872,1414213562373095048801688724,14142135623730950488016887242,141421356237309504880168872421 mov $1,1 mov $2,1 mov $3,$0 mul $3,4 add $3,1 lpb $3 add $1,$2 add $2,$1 mul $1,2 sub $3,1 lpe mul $1,2 mov $4,10 pow $4,$0 div $2,$4 div $1,$2 mov $0,$1 add $0,1 div $0,2
.include "io.inc65" .include "macros_65C02.inc65" .zeropage .smart on .autoimport on .case on .debuginfo off .importzp sp, sreg, regsave, regbank .importzp tmp1, tmp2, tmp3, tmp4, ptr1, ptr2, ptr3, ptr4 .macpack longbranch .export _ym_write_data .export _ym_write_reg .export _ym_write_data_A1 .export _ym_write_reg_A1 .export _ym_init .export _delay .export _ym_setreg .export _ym_setreg_A1 .export _getByte .export _set_song_pos .import _acia_putc .data _song_pos: .word $003F .code _set_song_pos: STA _song_pos LDA #0 STA _song_pos + 1 STX _song_pos + 1 RTS _ym_setreg: jsr pusha ldy #$01 lda (sp),y JSR _ym_write_reg ;jsr _delay LDY #$00 LDA (sp),y JSR _ym_write_data jmp incsp2 _ym_setreg_A1: jsr pusha ldy #$01 lda (sp),y JSR _ym_write_reg_A1 ;jsr _delay LDY #$00 LDA (sp),y JSR _ym_write_data_A1 jmp incsp2 _ym_init: LDA #$FF STA VIA_DDRA STA VIA_DDRB LDA #%11111100 STA VIA_ORB jsr _delay LDA #%11111000 STA VIA_ORB jsr _delay2 jsr _delay2 LDA #%11111100 STA VIA_ORB RTS _ym_write_data: PHA LDX #%11110101 STX VIA_ORB ;jsr _delay PLA STA VIA_ORA ;JSR _delay LDX #%11010101 STX VIA_ORB ;jsr _delay LDX #%11110101 STX VIA_ORB ;jsr _delay LDX #%11111100 STX VIA_ORB RTS _ym_write_data_A1: PHA LDX #%11110111 STX VIA_ORB ;jsr _delay PLA STA VIA_ORA ;JSR _delay LDX #%11010111 STX VIA_ORB ;jsr _delay LDX #%11110111 STX VIA_ORB ;jsr _delay LDX #%11111100 STX VIA_ORB RTS _ym_write_reg: PHA LDX #%11110100 STX VIA_ORB ;jsr _delay PLA STA VIA_ORA ;jsr _delay LDX #%11010100 STX VIA_ORB ;jsr _delay LDX #%11110100 STX VIA_ORB ;jsr _delay LDX #%11111100 STX VIA_ORB RTS _ym_write_reg_A1: PHA LDX #%11110110 STX VIA_ORB ;jsr _delay PLA STA VIA_ORA ; jsr _delay LDX #%11010110 STX VIA_ORB ;jsr _delay LDX #%11110110 STX VIA_ORB ;jsr _delay LDX #%11111100 STX VIA_ORB RTS ; --------------------------------------------------------------- ; char __near__ getByte (void) ; --------------------------------------------------------------- .segment "CODE" .proc _getByte: near .segment "CODE" inc _song_pos bne L0002 inc _song_pos+1 L0002: lda _song_pos+1 cmp #$40 bne L0003 lda _song_pos bne L0003 stz _song_pos stz _song_pos+1 jsr _switch_bank L0003: lda #<(BANKDISK) sta ptr1 lda #>(BANKDISK) clc adc _song_pos+1 sta ptr1+1 ldy _song_pos ldx #$00 lda (ptr1),y rts .endproc _delay: LDX #$1 _delay1: DEX BNE _delay1 RTS _delay2: LDX #$FF _delay3: DEX BNE _delay3 RTS
; void heap_free_unlocked(void *heap, void *p) SECTION code_alloc_malloc PUBLIC _heap_free_unlocked EXTERN asm_heap_free_unlocked _heap_free_unlocked: pop af pop de pop hl push hl push de push af jp asm_heap_free_unlocked
// Copyright 2014 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "ipc/message_filter.h" #include "base/memory/ref_counted.h" #include "ipc/ipc_channel.h" namespace IPC { MessageFilter::MessageFilter() {} void MessageFilter::OnFilterAdded(Sender* sender) {} void MessageFilter::OnFilterRemoved() {} void MessageFilter::OnChannelConnected(int32 peer_pid) {} void MessageFilter::OnChannelError() {} void MessageFilter::OnChannelClosing() {} bool MessageFilter::OnMessageReceived(const Message& message) { return false; } bool MessageFilter::GetSupportedMessageClasses( std::vector<uint32>* /*supported_message_classes*/) const { return false; } MessageFilter::~MessageFilter() {} } // namespace IPC
; Sameboy CGB bootstrap ROM ; Todo: use friendly names for HW registers instead of magic numbers SECTION "BootCode", ROM0[$0] Start: ; Init stack pointer ld sp, $fffe ; Clear memory VRAM ld hl, $8000 .clearVRAMLoop ldi [hl], a bit 5, h jr z, .clearVRAMLoop ; Init Audio ld a, $80 ldh [$26], a ldh [$11], a ld a, $f3 ldh [$12], a ldh [$25], a ld a, $77 ldh [$24], a ; Init BG palette ld a, $fc ldh [$47], a ; Load logo from ROM. ; A nibble represents a 4-pixels line, 2 bytes represent a 4x4 tile, scaled to 8x8. ; Tiles are ordered left to right, top to bottom. ld de, $104 ; Logo start ld hl, $8010 ; This is where we load the tiles in VRAM .loadLogoLoop ld a, [de] ; Read 2 rows ld b, a call DoubleBitsAndWriteRow call DoubleBitsAndWriteRow inc de ld a, e xor $34 ; End of logo jr nz, .loadLogoLoop ; Load trademark symbol ld de, TrademarkSymbol ld c,$08 .loadTrademarkSymbolLoop: ld a,[de] inc de ldi [hl],a inc hl dec c jr nz, .loadTrademarkSymbolLoop ; Set up tilemap ld a,$19 ; Trademark symbol ld [$9910], a ; ... put in the superscript position ld hl,$992f ; Bottom right corner of the logo ld c,$c ; Tiles in a logo row .tilemapLoop dec a jr z, .tilemapDone ldd [hl], a dec c jr nz, .tilemapLoop ld l,$0f ; Jump to top row jr .tilemapLoop .tilemapDone ; Turn on LCD ld a, $91 ldh [$40], a ; Wait ~0.75 seconds ld b, 45 call WaitBFrames ; Play first sound ld a, $83 call PlaySound ld b, 5 call WaitBFrames ; Play second sound ld a, $c1 call PlaySound ; Wait ~1.15 seconds ld b, 70 call WaitBFrames ; Set registers to match the original DMG boot ld hl, $01B0 push hl pop af ld hl, $014D ld bc, $0013 ld de, $00D8 ; Boot the game jp BootGame DoubleBitsAndWriteRow: ; Double the most significant 4 bits, b is shifted by 4 ld a, 4 ld c, 0 .doubleCurrentBit sla b push af rl c pop af rl c dec a jr nz, .doubleCurrentBit ld a, c ; Write as two rows ldi [hl], a inc hl ldi [hl], a inc hl ret WaitFrame: push hl ld hl, $FF0F res 0, [hl] .wait bit 0, [hl] jr z, .wait pop hl ret WaitBFrames: call WaitFrame dec b jr nz, WaitBFrames ret PlaySound: ldh [$13], a ld a, $87 ldh [$14], a ret TrademarkSymbol: db $3c,$42,$b9,$a5,$b9,$a5,$42,$3c SECTION "BootGame", ROM0[$fe] BootGame: ldh [$50], a
; A092436: a(n) = 1/2 + (-1)^n*(1/2 - A010060(floor(n/2))). ; 0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0,0,1 lpb $0,1 sub $0,1 add $1,$0 div $0,2 lpe mod $1,2
.code EXTERN GetSyscallAddress: PROC EXTERN SW2_GetSyscallNumber: PROC SyscallNotFound PROC mov eax, 0C0000225h ret SyscallNotFound ENDP NtOpenProcess PROC push rcx push rdx push r8 push r9 sub rsp, 028h call GetSyscallAddress add rsp, 028h push rax sub rsp, 028h mov ecx, 0CD9B2A0Fh call SW2_GetSyscallNumber add rsp, 028h pop r11 pop r9 pop r8 pop rdx pop rcx mov r10, rcx jmp r11 NtOpenProcess ENDP NtGetNextProcess PROC push rcx push rdx push r8 push r9 sub rsp, 028h call GetSyscallAddress add rsp, 028h push rax sub rsp, 028h mov ecx, 0FFBF1A2Fh call SW2_GetSyscallNumber add rsp, 028h pop r11 pop r9 pop r8 pop rdx pop rcx mov r10, rcx jmp r11 NtGetNextProcess ENDP NtReadVirtualMemory PROC push rcx push rdx push r8 push r9 sub rsp, 028h call GetSyscallAddress add rsp, 028h push rax sub rsp, 028h mov ecx, 0118B7567h call SW2_GetSyscallNumber add rsp, 028h pop r11 pop r9 pop r8 pop rdx pop rcx mov r10, rcx jmp r11 NtReadVirtualMemory ENDP NtClose PROC push rcx push rdx push r8 push r9 sub rsp, 028h call GetSyscallAddress add rsp, 028h push rax sub rsp, 028h mov ecx, 02252D33Fh call SW2_GetSyscallNumber add rsp, 028h pop r11 pop r9 pop r8 pop rdx pop rcx mov r10, rcx jmp r11 NtClose ENDP NtOpenProcessToken PROC push rcx push rdx push r8 push r9 sub rsp, 028h call GetSyscallAddress add rsp, 028h push rax sub rsp, 028h mov ecx, 08FA915A2h call SW2_GetSyscallNumber add rsp, 028h pop r11 pop r9 pop r8 pop rdx pop rcx mov r10, rcx jmp r11 NtOpenProcessToken ENDP NtQueryInformationProcess PROC push rcx push rdx push r8 push r9 sub rsp, 028h call GetSyscallAddress add rsp, 028h push rax sub rsp, 028h mov ecx, 0BDBCBC20h call SW2_GetSyscallNumber add rsp, 028h pop r11 pop r9 pop r8 pop rdx pop rcx mov r10, rcx jmp r11 NtQueryInformationProcess ENDP NtQueryVirtualMemory PROC push rcx push rdx push r8 push r9 sub rsp, 028h call GetSyscallAddress add rsp, 028h push rax sub rsp, 028h mov ecx, 00393E980h call SW2_GetSyscallNumber add rsp, 028h pop r11 pop r9 pop r8 pop rdx pop rcx mov r10, rcx jmp r11 NtQueryVirtualMemory ENDP NtAdjustPrivilegesToken PROC push rcx push rdx push r8 push r9 sub rsp, 028h call GetSyscallAddress add rsp, 028h push rax sub rsp, 028h mov ecx, 017AB1B32h call SW2_GetSyscallNumber add rsp, 028h pop r11 pop r9 pop r8 pop rdx pop rcx mov r10, rcx jmp r11 NtAdjustPrivilegesToken ENDP NtAllocateVirtualMemory PROC push rcx push rdx push r8 push r9 sub rsp, 028h call GetSyscallAddress add rsp, 028h push rax sub rsp, 028h mov ecx, 00595031Bh call SW2_GetSyscallNumber add rsp, 028h pop r11 pop r9 pop r8 pop rdx pop rcx mov r10, rcx jmp r11 NtAllocateVirtualMemory ENDP NtFreeVirtualMemory PROC push rcx push rdx push r8 push r9 sub rsp, 028h call GetSyscallAddress add rsp, 028h push rax sub rsp, 028h mov ecx, 001932F05h call SW2_GetSyscallNumber add rsp, 028h pop r11 pop r9 pop r8 pop rdx pop rcx mov r10, rcx jmp r11 NtFreeVirtualMemory ENDP NtCreateFile PROC push rcx push rdx push r8 push r9 sub rsp, 028h call GetSyscallAddress add rsp, 028h push rax sub rsp, 028h mov ecx, 096018EB6h call SW2_GetSyscallNumber add rsp, 028h pop r11 pop r9 pop r8 pop rdx pop rcx mov r10, rcx jmp r11 NtCreateFile ENDP NtWriteFile PROC push rcx push rdx push r8 push r9 sub rsp, 028h call GetSyscallAddress add rsp, 028h push rax sub rsp, 028h mov ecx, 024B22A1Ah call SW2_GetSyscallNumber add rsp, 028h pop r11 pop r9 pop r8 pop rdx pop rcx mov r10, rcx jmp r11 NtWriteFile ENDP NtCreateProcess PROC push rcx push rdx push r8 push r9 sub rsp, 028h call GetSyscallAddress add rsp, 028h push rax sub rsp, 028h mov ecx, 0F538D0A0h call SW2_GetSyscallNumber add rsp, 028h pop r11 pop r9 pop r8 pop rdx pop rcx mov r10, rcx jmp r11 NtCreateProcess ENDP NtQuerySystemInformation PROC push rcx push rdx push r8 push r9 sub rsp, 028h call GetSyscallAddress add rsp, 028h push rax sub rsp, 028h mov ecx, 04A5B2C8Fh call SW2_GetSyscallNumber add rsp, 028h pop r11 pop r9 pop r8 pop rdx pop rcx mov r10, rcx jmp r11 NtQuerySystemInformation ENDP NtDuplicateObject PROC push rcx push rdx push r8 push r9 sub rsp, 028h call GetSyscallAddress add rsp, 028h push rax sub rsp, 028h mov ecx, 09CBFA413h call SW2_GetSyscallNumber add rsp, 028h pop r11 pop r9 pop r8 pop rdx pop rcx mov r10, rcx jmp r11 NtDuplicateObject ENDP NtQueryObject_ PROC push rcx push rdx push r8 push r9 sub rsp, 028h call GetSyscallAddress add rsp, 028h push rax sub rsp, 028h mov ecx, 00E23F64Fh call SW2_GetSyscallNumber add rsp, 028h pop r11 pop r9 pop r8 pop rdx pop rcx mov r10, rcx jmp r11 NtQueryObject_ ENDP NtWaitForSingleObject PROC push rcx push rdx push r8 push r9 sub rsp, 028h call GetSyscallAddress add rsp, 028h push rax sub rsp, 028h mov ecx, 0426376E3h call SW2_GetSyscallNumber add rsp, 028h pop r11 pop r9 pop r8 pop rdx pop rcx mov r10, rcx jmp r11 NtWaitForSingleObject ENDP NtDeleteFile PROC push rcx push rdx push r8 push r9 sub rsp, 028h call GetSyscallAddress add rsp, 028h push rax sub rsp, 028h mov ecx, 064B26A1Ah call SW2_GetSyscallNumber add rsp, 028h pop r11 pop r9 pop r8 pop rdx pop rcx mov r10, rcx jmp r11 NtDeleteFile ENDP NtTerminateProcess PROC push rcx push rdx push r8 push r9 sub rsp, 028h call GetSyscallAddress add rsp, 028h push rax sub rsp, 028h mov ecx, 0652E64A0h call SW2_GetSyscallNumber add rsp, 028h pop r11 pop r9 pop r8 pop rdx pop rcx mov r10, rcx jmp r11 NtTerminateProcess ENDP local_is_wow64 PROC mov rax, 0 ret local_is_wow64 ENDP end
; A263919: Triangle read by rows giving successive states of cellular automaton generated by "Rule 163" initiated with a single ON (black) cell. ; 1,1,0,0,1,0,0,1,0,1,0,0,1,0,1,0,1,0,0,1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0 mov $1,1 mov $2,$0 trn $0,2 lpb $2,1 lpb $0,1 add $1,2 trn $0,$1 sub $2,1 lpe lpb $1,1 trn $1,4 lpe add $1,$2 add $0,$1 trn $2,1 lpe
.size 8000 .text@48 jp lstatint .text@100 jp lbegin .data@143 80 .text@150 lbegin: ld b, 90 call lwaitly_b ld hl, fe00 ld(hl), 00 ld c, 41 ld b, 03 lbegin_waitm3: ldff a, (c) and a, b cmp a, b jrnz lbegin_waitm3 ld a, 20 ldff(c), a xor a, a ldff(0f), a ld a, 02 ldff(ff), a ei .text@1000 lstatint: nop .text@1068 ld(hl), 01 .text@10c0 ld a, (hl--) and a, b jp lprint_a .text@7000 lprint_a: push af ld b, 91 call lwaitly_b xor a, a ldff(40), a pop af ld(9800), a ld bc, 7a00 ld hl, 8000 ld d, a0 lprint_copytiles: ld a, (bc) inc bc ld(hl++), a dec d jrnz lprint_copytiles ld a, c0 ldff(47), a ld a, 80 ldff(68), a ld a, ff ldff(69), a ldff(69), a ldff(69), a ldff(69), a ldff(69), a ldff(69), a xor a, a ldff(69), a ldff(69), a ldff(43), a ld a, 91 ldff(40), a lprint_limbo: jr lprint_limbo .text@7400 lwaitly_b: ld c, 44 lwaitly_b_loop: ldff a, (c) cmp a, b jrnz lwaitly_b_loop ret .data@7a00 00 00 7f 7f 41 41 41 41 41 41 41 41 41 41 7f 7f 00 00 08 08 08 08 08 08 08 08 08 08 08 08 08 08 00 00 7f 7f 01 01 01 01 7f 7f 40 40 40 40 7f 7f 00 00 7f 7f 01 01 01 01 3f 3f 01 01 01 01 7f 7f 00 00 41 41 41 41 41 41 7f 7f 01 01 01 01 01 01 00 00 7f 7f 40 40 40 40 7e 7e 01 01 01 01 7e 7e 00 00 7f 7f 40 40 40 40 7f 7f 41 41 41 41 7f 7f 00 00 7f 7f 01 01 02 02 04 04 08 08 10 10 10 10 00 00 3e 3e 41 41 41 41 3e 3e 41 41 41 41 3e 3e 00 00 7f 7f 41 41 41 41 7f 7f 01 01 01 01 7f 7f
; A000204: Lucas numbers (beginning with 1): L(n) = L(n-1) + L(n-2) with L(1) = 1, L(2) = 3. ; 1,3,4,7,11,18,29,47,76,123,199,322,521,843,1364,2207,3571,5778,9349,15127,24476,39603,64079,103682,167761,271443,439204,710647,1149851,1860498,3010349,4870847,7881196,12752043,20633239,33385282,54018521,87403803,141422324,228826127,370248451,599074578,969323029,1568397607,2537720636,4106118243,6643838879,10749957122,17393796001,28143753123,45537549124,73681302247,119218851371,192900153618,312119004989,505019158607,817138163596,1322157322203,2139295485799,3461452808002,5600748293801,9062201101803,14662949395604,23725150497407,38388099893011,62113250390418,100501350283429,162614600673847,263115950957276,425730551631123,688846502588399,1114577054219522,1803423556807921,2918000611027443,4721424167835364,7639424778862807,12360848946698171,20000273725560978,32361122672259149,52361396397820127,84722519070079276,137083915467899403,221806434537978679,358890350005878082,580696784543856761,939587134549734843,1520283919093591604,2459871053643326447,3980154972736918051,6440026026380244498,10420180999117162549,16860207025497407047,27280388024614569596,44140595050111976643,71420983074726546239,115561578124838522882,186982561199565069121,302544139324403592003,489526700523968661124,792070839848372253127 mov $1,1 mov $3,3 lpb $0 sub $0,1 add $3,$2 mov $2,$1 mov $1,$3 lpe mov $0,$1
; ; Fast background save ; ; PC6001 version ; ; ; $Id: bksave.asm,v 1.4 2016/07/02 09:01:36 dom Exp $ ; SECTION code_clib PUBLIC bksave PUBLIC _bksave EXTERN pixeladdress .bksave ._bksave push ix ;save caller ld hl,4 add hl,sp ld e,(hl) inc hl ld d,(hl) ;sprite address push de pop ix inc hl ld e,(hl) inc hl inc hl ld d,(hl) ; x and y __gfx_coords ld h,d ld l,e call pixeladdress xor 7 ld h,d ld l,e ld (ix+2),h ; we save the current sprite position ld (ix+3),l ld a,(ix+0) ld b,(ix+1) cp 9 jr nc,bksavew ._sloop push bc push hl ld a,(hl) and @10101010 ld (ix+4),a inc hl ld a,(hl) rra and @01010101 or (ix+4) ld (ix+4),a inc hl ld a,(hl) and @10101010 ld (ix+5),a inc hl ld a,(hl) rra and @01010101 or (ix+5) ld (ix+5),a inc hl inc ix inc ix pop hl ld bc,32 ;Go to next line add hl,bc pop bc djnz _sloop pop ix ;restore callers ret .bksavew push bc push hl ld a,(hl) and @10101010 ld (ix+4),a inc hl ld a,(hl) rra and @01010101 or (ix+4) ld (ix+4),a inc hl ld a,(hl) and @10101010 ld (ix+5),a inc hl ld a,(hl) rra and @01010101 or (ix+5) ld (ix+5),a inc hl ld a,(hl) and @10101010 ld (ix+6),a inc hl ld a,(hl) rra and @01010101 or (ix+6) ld (ix+6),a inc ix inc ix inc ix pop hl ld bc,32 ;Go to next line add hl,bc pop bc djnz bksavew pop ix ;restore callers ret
;HEX to BCD .model small .data m1 db 10, 13, "Equivalent BCD no. is: $" no dw 0ffffh .code Disp macro xx mov ah, 09 lea dx, xx int 21h endm .startup Disp m1 mov cl, 0 mov ax, no mov bx, 0ah back: mov dx, 0 div bx push dx inc cl cmp ax, 0 jnz back back1: pop dx add dl, 30h mov ah, 02 int 21h dec cl jnz back1 .exit end
;; xOS Kernel API Reference ;; As of API version 1 XOS_WM_CREATE_WINDOW = 0x0000 XOS_YIELD = 0x0001 XOS_WM_PIXEL_OFFSET = 0x0002 XOS_WM_REDRAW = 0x0003 XOS_WM_READ_EVENT = 0x0004 XOS_WM_READ_MOUSE = 0x0005 XOS_WM_GET_WINDOW = 0x0006 XOS_WM_DRAW_TEXT = 0x0007 XOS_WM_CLEAR = 0x0008 XOS_MALLOC = 0x0009 XOS_FREE = 0x000A XOS_OPEN = 0x000B XOS_CLOSE = 0x000C XOS_SEEK = 0x000D XOS_TELL = 0x000E XOS_READ = 0x000F XOS_WRITE = 0x0010 XOS_WM_RENDER_CHAR = 0x0011 XOS_WM_KILL = 0x0012 XOS_GET_SCREEN_INFO = 0x0013 XOS_READ_KEY = 0x0014 XOS_TERMINATE = 0x0015 XOS_CREATE_TASK = 0x0016 XOS_GET_TIME = 0x0017 XOS_SHUTDOWN = 0x0018 XOS_REBOOT = 0x0019 XOS_GET_MEMORY_USAGE = 0x001A XOS_ENUM_TASKS = 0x001B XOS_GET_UPTIME = 0x001C XOS_NET_GET_CONNECTION = 0x001D XOS_NET_SEND = 0x001E XOS_NET_RECEIVE = 0x001F XOS_HTTP_HEAD = 0x0020 XOS_HTTP_GET = 0x0021 XOS_SOCKET_OPEN = 0x0022 XOS_SOCKET_CLOSE = 0x0023 XOS_SOCKET_READ = 0x0024 XOS_SOCKET_WRITE = 0x0025 XOS_REALLOC = 0x0026 XOS_KPRINT = 0x0027
;****************************************************************************** ;* AAC Spectral Band Replication decoding functions ;* Copyright (C) 2012 Christophe Gisquet <christophe.gisquet@gmail.com> ;* ;* This file is part of FFmpeg. ;* ;* FFmpeg is free software; you can redistribute it and/or ;* modify it under the terms of the GNU Lesser General Public ;* License as published by the Free Software Foundation; either ;* version 2.1 of the License, or (at your option) any later version. ;* ;* FFmpeg is distributed in the hope that it will be useful, ;* but WITHOUT ANY WARRANTY; without even the implied warranty of ;* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;* Lesser General Public License for more details. ;* ;* You should have received a copy of the GNU Lesser General Public ;* License along with FFmpeg; if not, write to the Free Software ;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ;****************************************************************************** %include "libavutil/x86/x86util.asm" SECTION_RODATA ; mask equivalent for multiply by -1.0 1.0 ps_mask times 2 dd 1<<31, 0 ps_mask2 times 2 dd 0, 1<<31 ps_mask3 dd 0, 0, 0, 1<<31 ps_noise0 times 2 dd 1.0, 0.0, ps_noise2 times 2 dd -1.0, 0.0 ps_noise13 dd 0.0, 1.0, 0.0, -1.0 dd 0.0, -1.0, 0.0, 1.0 dd 0.0, 1.0, 0.0, -1.0 cextern sbr_noise_table cextern ps_neg SECTION .text INIT_XMM sse cglobal sbr_sum_square, 2, 3, 6 mov r2, r1 xorps m0, m0 xorps m1, m1 sar r2, 3 jz .prepare .loop: movu m2, [r0 + 0] movu m3, [r0 + 16] movu m4, [r0 + 32] movu m5, [r0 + 48] mulps m2, m2 mulps m3, m3 mulps m4, m4 mulps m5, m5 addps m0, m2 addps m1, m3 addps m0, m4 addps m1, m5 add r0, 64 dec r2 jnz .loop .prepare: and r1, 7 sar r1, 1 jz .end ; len is a multiple of 2, thus there are at least 4 elements to process .endloop: movu m2, [r0] add r0, 16 mulps m2, m2 dec r1 addps m0, m2 jnz .endloop .end: addps m0, m1 movhlps m2, m0 addps m0, m2 movss m1, m0 shufps m0, m0, 1 addss m0, m1 %if ARCH_X86_64 == 0 movss r0m, m0 fld dword r0m %endif RET %define STEP 40*4*2 cglobal sbr_hf_g_filt, 5, 6, 5 lea r1, [r1 + 8*r4] ; offset by ixh elements into X_high mov r5, r3 and r3, 0xFC lea r2, [r2 + r3*4] lea r0, [r0 + r3*8] neg r3 jz .loop1 .loop4: movlps m0, [r2 + 4*r3 + 0] movlps m1, [r2 + 4*r3 + 8] movlps m2, [r1 + 0*STEP] movlps m3, [r1 + 2*STEP] movhps m2, [r1 + 1*STEP] movhps m3, [r1 + 3*STEP] unpcklps m0, m0 unpcklps m1, m1 mulps m0, m2 mulps m1, m3 movu [r0 + 8*r3 + 0], m0 movu [r0 + 8*r3 + 16], m1 add r1, 4*STEP add r3, 4 jnz .loop4 and r5, 3 ; number of single element loops jz .end .loop1: ; element 0 and 1 can be computed at the same time movss m0, [r2] movlps m2, [r1] unpcklps m0, m0 mulps m2, m0 movlps [r0], m2 add r0, 8 add r2, 4 add r1, STEP dec r5 jnz .loop1 .end: RET ; void ff_sbr_hf_gen_sse(float (*X_high)[2], const float (*X_low)[2], ; const float alpha0[2], const float alpha1[2], ; float bw, int start, int end) ; cglobal sbr_hf_gen, 4,4,8, X_high, X_low, alpha0, alpha1, BW, S, E ; load alpha factors %define bw m0 %if ARCH_X86_64 == 0 || WIN64 movss bw, BWm %endif movlps m2, [alpha1q] movlps m1, [alpha0q] shufps bw, bw, 0 mulps m2, bw ; (a1[0] a1[1])*bw mulps m1, bw ; (a0[0] a0[1])*bw = (a2 a3) mulps m2, bw ; (a1[0] a1[1])*bw*bw = (a0 a1) mova m3, m1 mova m4, m2 ; Set pointers %if ARCH_X86_64 == 0 || WIN64 ; start and end 6th and 7th args on stack mov r2d, Sm mov r3d, Em %define start r2q %define end r3q %else ; BW does not actually occupy a register, so shift by 1 %define start BWq %define end Sq %endif sub start, end ; neg num of loops lea X_highq, [X_highq + end*2*4] lea X_lowq, [X_lowq + end*2*4 - 2*2*4] shl start, 3 ; offset from num loops mova m0, [X_lowq + start] shufps m3, m3, q1111 shufps m4, m4, q1111 xorps m3, [ps_mask] shufps m1, m1, q0000 shufps m2, m2, q0000 xorps m4, [ps_mask] .loop2: movu m7, [X_lowq + start + 8] ; BbCc mova m6, m0 mova m5, m7 shufps m0, m0, q2301 ; aAbB shufps m7, m7, q2301 ; bBcC mulps m0, m4 mulps m7, m3 mulps m6, m2 mulps m5, m1 addps m7, m0 mova m0, [X_lowq + start +16] ; CcDd addps m7, m0 addps m6, m5 addps m7, m6 mova [X_highq + start], m7 add start, 16 jnz .loop2 RET cglobal sbr_sum64x5, 1,2,4,z lea r1q, [zq+ 256] .loop: mova m0, [zq+ 0] mova m2, [zq+ 16] mova m1, [zq+ 256] mova m3, [zq+ 272] addps m0, [zq+ 512] addps m2, [zq+ 528] addps m1, [zq+ 768] addps m3, [zq+ 784] addps m0, [zq+1024] addps m2, [zq+1040] addps m0, m1 addps m2, m3 mova [zq], m0 mova [zq+16], m2 add zq, 32 cmp zq, r1q jne .loop REP_RET INIT_XMM sse cglobal sbr_qmf_post_shuffle, 2,3,4,W,z lea r2q, [zq + (64-4)*4] mova m3, [ps_neg] .loop: mova m1, [zq] xorps m0, m3, [r2q] shufps m0, m0, m0, q0123 unpcklps m2, m0, m1 unpckhps m0, m0, m1 mova [Wq + 0], m2 mova [Wq + 16], m0 add Wq, 32 sub r2q, 16 add zq, 16 cmp zq, r2q jl .loop REP_RET INIT_XMM sse cglobal sbr_neg_odd_64, 1,2,4,z lea r1q, [zq+256] .loop: mova m0, [zq+ 0] mova m1, [zq+16] mova m2, [zq+32] mova m3, [zq+48] xorps m0, [ps_mask2] xorps m1, [ps_mask2] xorps m2, [ps_mask2] xorps m3, [ps_mask2] mova [zq+ 0], m0 mova [zq+16], m1 mova [zq+32], m2 mova [zq+48], m3 add zq, 64 cmp zq, r1q jne .loop REP_RET ; void ff_sbr_qmf_deint_bfly_sse2(float *v, const float *src0, const float *src1) %macro SBR_QMF_DEINT_BFLY 0 cglobal sbr_qmf_deint_bfly, 3,5,8, v,src0,src1,vrev,c mov cq, 64*4-2*mmsize lea vrevq, [vq + 64*4] .loop: mova m0, [src0q+cq] mova m1, [src1q] mova m4, [src0q+cq+mmsize] mova m5, [src1q+mmsize] %if cpuflag(sse2) pshufd m2, m0, q0123 pshufd m3, m1, q0123 pshufd m6, m4, q0123 pshufd m7, m5, q0123 %else shufps m2, m0, m0, q0123 shufps m3, m1, m1, q0123 shufps m6, m4, m4, q0123 shufps m7, m5, m5, q0123 %endif addps m5, m2 subps m0, m7 addps m1, m6 subps m4, m3 mova [vrevq], m1 mova [vrevq+mmsize], m5 mova [vq+cq], m0 mova [vq+cq+mmsize], m4 add src1q, 2*mmsize add vrevq, 2*mmsize sub cq, 2*mmsize jge .loop REP_RET %endmacro INIT_XMM sse SBR_QMF_DEINT_BFLY INIT_XMM sse2 SBR_QMF_DEINT_BFLY INIT_XMM sse2 cglobal sbr_qmf_pre_shuffle, 1,4,6,z %define OFFSET (32*4-2*mmsize) mov r3q, OFFSET lea r1q, [zq + (32+1)*4] lea r2q, [zq + 64*4] mova m5, [ps_neg] .loop: movu m0, [r1q] movu m2, [r1q + mmsize] movu m1, [zq + r3q + 4 + mmsize] movu m3, [zq + r3q + 4] pxor m2, m5 pxor m0, m5 pshufd m2, m2, q0123 pshufd m0, m0, q0123 SBUTTERFLY dq, 2, 3, 4 SBUTTERFLY dq, 0, 1, 4 mova [r2q + 2*r3q + 0*mmsize], m2 mova [r2q + 2*r3q + 1*mmsize], m3 mova [r2q + 2*r3q + 2*mmsize], m0 mova [r2q + 2*r3q + 3*mmsize], m1 add r1q, 2*mmsize sub r3q, 2*mmsize jge .loop movq m2, [zq] movq [r2q], m2 REP_RET %ifdef PIC %define NREGS 1 %if UNIX64 %define NOISE_TABLE r6q ; r5q is m_max %else %define NOISE_TABLE r5q %endif %else %define NREGS 0 %define NOISE_TABLE sbr_noise_table %endif %macro LOAD_NST 1 %ifdef PIC lea NOISE_TABLE, [%1] mova m0, [kxq + NOISE_TABLE] %else mova m0, [kxq + %1] %endif %endmacro INIT_XMM sse2 ; sbr_hf_apply_noise_0(float (*Y)[2], const float *s_m, ; const float *q_filt, int noise, ; int kx, int m_max) cglobal sbr_hf_apply_noise_0, 5,5+NREGS+UNIX64,8, Y,s_m,q_filt,noise,kx,m_max mova m0, [ps_noise0] jmp apply_noise_main ; sbr_hf_apply_noise_1(float (*Y)[2], const float *s_m, ; const float *q_filt, int noise, ; int kx, int m_max) cglobal sbr_hf_apply_noise_1, 5,5+NREGS+UNIX64,8, Y,s_m,q_filt,noise,kx,m_max and kxq, 1 shl kxq, 4 LOAD_NST ps_noise13 jmp apply_noise_main ; sbr_hf_apply_noise_2(float (*Y)[2], const float *s_m, ; const float *q_filt, int noise, ; int kx, int m_max) cglobal sbr_hf_apply_noise_2, 5,5+NREGS+UNIX64,8, Y,s_m,q_filt,noise,kx,m_max mova m0, [ps_noise2] jmp apply_noise_main ; sbr_hf_apply_noise_3(float (*Y)[2], const float *s_m, ; const float *q_filt, int noise, ; int kx, int m_max) cglobal sbr_hf_apply_noise_3, 5,5+NREGS+UNIX64,8, Y,s_m,q_filt,noise,kx,m_max and kxq, 1 shl kxq, 4 LOAD_NST ps_noise13+16 apply_noise_main: %if ARCH_X86_64 == 0 || WIN64 mov kxd, m_maxm %define count kxq %else %define count m_maxq %endif movsxdifnidn noiseq, noised dec noiseq shl count, 2 %ifdef PIC lea NOISE_TABLE, [sbr_noise_table] %endif lea Yq, [Yq + 2*count] add s_mq, count add q_filtq, count shl noiseq, 3 pxor m5, m5 neg count .loop: mova m1, [q_filtq + count] movu m3, [noiseq + NOISE_TABLE + 1*mmsize] movu m4, [noiseq + NOISE_TABLE + 2*mmsize] add noiseq, 2*mmsize and noiseq, 0x1ff<<3 punpckhdq m2, m1, m1 punpckldq m1, m1 mulps m1, m3 ; m2 = q_filt[m] * ff_sbr_noise_table[noise] mulps m2, m4 ; m2 = q_filt[m] * ff_sbr_noise_table[noise] mova m3, [s_mq + count] ; TODO: replace by a vpermd in AVX2 punpckhdq m4, m3, m3 punpckldq m3, m3 pcmpeqd m6, m3, m5 ; m6 == 0 pcmpeqd m7, m4, m5 ; m7 == 0 mulps m3, m0 ; s_m[m] * phi_sign mulps m4, m0 ; s_m[m] * phi_sign pand m1, m6 pand m2, m7 movu m6, [Yq + 2*count] movu m7, [Yq + 2*count + mmsize] addps m3, m1 addps m4, m2 addps m6, m3 addps m7, m4 movu [Yq + 2*count], m6 movu [Yq + 2*count + mmsize], m7 add count, mmsize jl .loop RET INIT_XMM sse cglobal sbr_qmf_deint_neg, 2,4,4,v,src,vrev,c %define COUNT 32*4 %define OFFSET 32*4 mov cq, -COUNT lea vrevq, [vq + OFFSET + COUNT] add vq, OFFSET-mmsize add srcq, 2*COUNT mova m3, [ps_neg] .loop: mova m0, [srcq + 2*cq + 0*mmsize] mova m1, [srcq + 2*cq + 1*mmsize] shufps m2, m0, m1, q2020 shufps m1, m0, q1313 xorps m2, m3 mova [vq], m1 mova [vrevq + cq], m2 sub vq, mmsize add cq, mmsize jl .loop REP_RET %macro SBR_AUTOCORRELATE 0 cglobal sbr_autocorrelate, 2,3,8,32, x, phi, cnt mov cntq, 37*8 add xq, cntq neg cntq %if cpuflag(sse3) %define MOVH movsd movddup m5, [xq+cntq] %else %define MOVH movlps movlps m5, [xq+cntq] movlhps m5, m5 %endif MOVH m7, [xq+cntq+8 ] MOVH m1, [xq+cntq+16] shufps m7, m7, q0110 shufps m1, m1, q0110 mulps m3, m5, m7 ; x[0][0] * x[1][0], x[0][1] * x[1][1], x[0][0] * x[1][1], x[0][1] * x[1][0] mulps m4, m5, m5 ; x[0][0] * x[0][0], x[0][1] * x[0][1]; mulps m5, m1 ; real_sum2 = x[0][0] * x[2][0], x[0][1] * x[2][1]; imag_sum2 = x[0][0] * x[2][1], x[0][1] * x[2][0] movaps [rsp ], m3 movaps [rsp+16], m4 add cntq, 8 MOVH m2, [xq+cntq+16] movlhps m7, m7 shufps m2, m2, q0110 mulps m6, m7, m1 ; real_sum1 = x[1][0] * x[2][0], x[1][1] * x[2][1]; imag_sum1 += x[1][0] * x[2][1], x[1][1] * x[2][0] mulps m4, m7, m2 mulps m7, m7 ; real_sum0 = x[1][0] * x[1][0], x[1][1] * x[1][1]; addps m5, m4 ; real_sum2 += x[1][0] * x[3][0], x[1][1] * x[3][1]; imag_sum2 += x[1][0] * x[3][1], x[1][1] * x[3][0] align 16 .loop: add cntq, 8 MOVH m0, [xq+cntq+16] movlhps m1, m1 shufps m0, m0, q0110 mulps m3, m1, m2 mulps m4, m1, m0 mulps m1, m1 addps m6, m3 ; real_sum1 += x[i][0] * x[i + 1][0], x[i][1] * x[i + 1][1]; imag_sum1 += x[i][0] * x[i + 1][1], x[i][1] * x[i + 1][0]; addps m5, m4 ; real_sum2 += x[i][0] * x[i + 2][0], x[i][1] * x[i + 2][1]; imag_sum2 += x[i][0] * x[i + 2][1], x[i][1] * x[i + 2][0]; addps m7, m1 ; real_sum0 += x[i][0] * x[i][0], x[i][1] * x[i][1]; add cntq, 8 MOVH m1, [xq+cntq+16] movlhps m2, m2 shufps m1, m1, q0110 mulps m3, m2, m0 mulps m4, m2, m1 mulps m2, m2 addps m6, m3 ; real_sum1 += x[i][0] * x[i + 1][0], x[i][1] * x[i + 1][1]; imag_sum1 += x[i][0] * x[i + 1][1], x[i][1] * x[i + 1][0]; addps m5, m4 ; real_sum2 += x[i][0] * x[i + 2][0], x[i][1] * x[i + 2][1]; imag_sum2 += x[i][0] * x[i + 2][1], x[i][1] * x[i + 2][0]; addps m7, m2 ; real_sum0 += x[i][0] * x[i][0], x[i][1] * x[i][1]; add cntq, 8 MOVH m2, [xq+cntq+16] movlhps m0, m0 shufps m2, m2, q0110 mulps m3, m0, m1 mulps m4, m0, m2 mulps m0, m0 addps m6, m3 ; real_sum1 += x[i][0] * x[i + 1][0], x[i][1] * x[i + 1][1]; imag_sum1 += x[i][0] * x[i + 1][1], x[i][1] * x[i + 1][0]; addps m5, m4 ; real_sum2 += x[i][0] * x[i + 2][0], x[i][1] * x[i + 2][1]; imag_sum2 += x[i][0] * x[i + 2][1], x[i][1] * x[i + 2][0]; addps m7, m0 ; real_sum0 += x[i][0] * x[i][0], x[i][1] * x[i][1]; jl .loop movlhps m1, m1 mulps m2, m1 mulps m1, m1 addps m2, m6 ; real_sum1 + x[38][0] * x[39][0], x[38][1] * x[39][1]; imag_sum1 + x[38][0] * x[39][1], x[38][1] * x[39][0]; addps m1, m7 ; real_sum0 + x[38][0] * x[38][0], x[38][1] * x[38][1]; addps m6, [rsp ] ; real_sum1 + x[ 0][0] * x[ 1][0], x[ 0][1] * x[ 1][1]; imag_sum1 + x[ 0][0] * x[ 1][1], x[ 0][1] * x[ 1][0]; addps m7, [rsp+16] ; real_sum0 + x[ 0][0] * x[ 0][0], x[ 0][1] * x[ 0][1]; xorps m2, [ps_mask3] xorps m5, [ps_mask3] xorps m6, [ps_mask3] %if cpuflag(sse3) movshdup m0, m1 haddps m2, m5 haddps m7, m6 addss m1, m0 %else movaps m3, m2 movaps m0, m5 movaps m4, m6 shufps m3, m3, q0301 shufps m0, m0, q0301 shufps m4, m4, q0301 addps m2, m3 addps m5, m0 addps m6, m4 movss m0, m7 movss m3, m1 shufps m7, m7, q0001 shufps m1, m1, q0001 addss m7, m0 addss m1, m3 shufps m2, m5, q2020 shufps m7, m6, q2020 %endif movaps [phiq ], m2 movhps [phiq+0x18], m7 movss [phiq+0x28], m7 movss [phiq+0x10], m1 RET %endmacro INIT_XMM sse SBR_AUTOCORRELATE INIT_XMM sse3 SBR_AUTOCORRELATE
; ;================================================================================================== ; EASY Z80 STANDARD CONFIGURATION ;================================================================================================== ; ; THE COMPLETE SET OF DEFAULT CONFIGURATION SETTINGS FOR THIS PLATFORM ARE FOUND IN THE ; CFG_<PLT>.ASM INCLUDED FILE WHICH IS FOUND IN THE PARENT DIRECTORY. THIS FILE CONTAINS ; COMMON CONFIGURATION SETTINGS THAT OVERRIDE THE DEFAULTS. IT IS INTENDED THAT YOU MAKE ; YOUR CUSTOMIZATIONS IN THIS FILE AND JUST INHERIT ALL OTHER SETTINGS FROM THE DEFAULTS. ; EVEN BETTER, YOU CAN MAKE A COPY OF THIS FILE WITH A NAME LIKE <PLT>_XXX.ASM AND SPECIFY ; YOUR FILE IN THE BUILD PROCESS. ; ; THE SETTINGS BELOW ARE THE SETTINGS THAT ARE MOST COMMONLY MODIFIED FOR THIS PLATFORM. ; MANY OF THEM ARE EQUAL TO THE SETTINGS IN THE INCLUDED FILE, SO THEY DON'T REALLY DO ; ANYTHING AS IS. THEY ARE LISTED HERE TO MAKE IT EASY FOR YOU TO ADJUST THE MOST COMMON ; SETTINGS. ; ; N.B., SINCE THE SETTINGS BELOW ARE REDEFINING VALUES ALREADY SET IN THE INCLUDED FILE, ; TASM INSISTS THAT YOU USE THE .SET OPERATOR AND NOT THE .EQU OPERATOR BELOW. ATTEMPTING ; TO REDEFINE A VALUE WITH .EQU BELOW WILL CAUSE TASM ERRORS! ; ; PLEASE REFER TO THE CUSTOM BUILD INSTRUCTIONS (README.TXT) IN THE SOURCE DIRECTORY (TWO ; DIRECTORIES ABOVE THIS ONE). ; #DEFINE BOOT_DEFAULT "H" ; DEFAULT BOOT LOADER CMD ON <CR> OR AUTO BOOT ; #include "cfg_ezz80.asm" ; CRTACT .SET FALSE ; ACTIVATE CRT (VDU,CVDU,PROPIO,ETC) AT STARTUP ; CPUOSC .SET 10000000 ; CPU OSC FREQ IN MHZ ; FDENABLE .SET TRUE ; FD: ENABLE FLOPPY DISK DRIVER (FD.ASM) FDMODE .SET FDMODE_RCWDC ; FD: DRIVER MODE: FDMODE_[DIO|ZETA|ZETA2|DIDE|N8|DIO3|RCSMC|RCWDC|DYNO|EPWDC] ; IDEENABLE .SET TRUE ; IDE: ENABLE IDE DISK DRIVER (IDE.ASM) ; PPIDEENABLE .SET TRUE ; PPIDE: ENABLE PARALLEL PORT IDE DISK DRIVER (PPIDE.ASM) ; PRPENABLE .SET FALSE ; PRP: ENABLE ECB PROPELLER IO BOARD DRIVER (PRP.ASM)
.global s_prepare_buffers s_prepare_buffers: push %r10 push %r13 push %r14 push %r15 push %r8 push %rcx push %rdi push %rsi lea addresses_A_ht+0x196d0, %r10 clflush (%r10) nop and $45317, %rdi movb (%r10), %r15b nop nop sub %r14, %r14 lea addresses_D_ht+0x174d0, %rsi nop nop nop dec %r13 movl $0x61626364, (%rsi) nop nop nop cmp $49754, %r13 lea addresses_WT_ht+0x127d0, %rsi lea addresses_WC_ht+0x10d30, %rdi nop sub %r8, %r8 mov $47, %rcx rep movsw sub $28460, %rsi lea addresses_normal_ht+0x6250, %rsi lea addresses_WC_ht+0x1d618, %rdi clflush (%rdi) xor %r13, %r13 mov $93, %rcx rep movsq nop nop sub $31929, %r15 lea addresses_WC_ht+0xeed0, %r10 nop nop nop nop cmp $18867, %r13 mov (%r10), %di nop nop nop nop cmp %r15, %r15 lea addresses_WT_ht+0x1b6d0, %r8 nop nop add $16863, %r10 mov $0x6162636465666768, %rdi movq %rdi, %xmm1 vmovups %ymm1, (%r8) nop cmp %rcx, %rcx lea addresses_normal_ht+0x12eda, %r8 nop nop nop cmp $36989, %rsi mov (%r8), %r10d nop cmp %rcx, %rcx lea addresses_D_ht+0xb730, %r13 clflush (%r13) nop nop cmp %rcx, %rcx movups (%r13), %xmm0 vpextrq $0, %xmm0, %r8 nop cmp %rcx, %rcx lea addresses_D_ht+0xb650, %rsi lea addresses_normal_ht+0x47f0, %rdi nop nop nop nop add %r10, %r10 mov $49, %rcx rep movsq nop nop nop nop nop and $17700, %rdi lea addresses_normal_ht+0x3f0, %rsi lea addresses_normal_ht+0x19319, %rdi nop nop nop nop nop cmp $19763, %r13 mov $113, %rcx rep movsw nop nop nop nop lfence lea addresses_A_ht+0x96d0, %r14 nop nop nop nop nop xor %r8, %r8 mov (%r14), %di nop nop nop nop nop cmp $41663, %r13 pop %rsi pop %rdi pop %rcx pop %r8 pop %r15 pop %r14 pop %r13 pop %r10 ret .global s_faulty_load s_faulty_load: push %r10 push %r11 push %r15 push %r8 push %rax push %rdi push %rsi // Store lea addresses_normal+0x176d0, %rax add %r11, %r11 mov $0x5152535455565758, %r10 movq %r10, %xmm3 movaps %xmm3, (%rax) // Exception!!! nop nop nop nop mov (0), %rax nop nop nop nop nop xor $59654, %r8 // Store lea addresses_WT+0x136d0, %rsi nop cmp $35761, %rdi mov $0x5152535455565758, %r15 movq %r15, %xmm2 vmovups %ymm2, (%rsi) nop nop nop cmp $26738, %r10 // Faulty Load lea addresses_normal+0x176d0, %r11 nop and %rax, %rax movups (%r11), %xmm7 vpextrq $0, %xmm7, %r8 lea oracles, %r10 and $0xff, %r8 shlq $12, %r8 mov (%r10,%r8,1), %r8 pop %rsi pop %rdi pop %rax pop %r8 pop %r15 pop %r11 pop %r10 ret /* <gen_faulty_load> [REF] {'OP': 'LOAD', 'src': {'same': False, 'NT': False, 'AVXalign': False, 'size': 32, 'type': 'addresses_normal', 'congruent': 0}} {'dst': {'same': True, 'NT': False, 'AVXalign': True, 'size': 16, 'type': 'addresses_normal', 'congruent': 0}, 'OP': 'STOR'} {'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 32, 'type': 'addresses_WT', 'congruent': 10}, 'OP': 'STOR'} [Faulty Load] {'OP': 'LOAD', 'src': {'same': True, 'NT': False, 'AVXalign': False, 'size': 16, 'type': 'addresses_normal', 'congruent': 0}} <gen_prepare_buffer> {'OP': 'LOAD', 'src': {'same': False, 'NT': False, 'AVXalign': False, 'size': 1, 'type': 'addresses_A_ht', 'congruent': 11}} {'dst': {'same': False, 'NT': False, 'AVXalign': True, 'size': 4, 'type': 'addresses_D_ht', 'congruent': 9}, 'OP': 'STOR'} {'dst': {'same': False, 'congruent': 5, 'type': 'addresses_WC_ht'}, 'OP': 'REPM', 'src': {'same': False, 'congruent': 8, 'type': 'addresses_WT_ht'}} {'dst': {'same': False, 'congruent': 2, 'type': 'addresses_WC_ht'}, 'OP': 'REPM', 'src': {'same': False, 'congruent': 6, 'type': 'addresses_normal_ht'}} {'OP': 'LOAD', 'src': {'same': False, 'NT': False, 'AVXalign': False, 'size': 2, 'type': 'addresses_WC_ht', 'congruent': 11}} {'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 32, 'type': 'addresses_WT_ht', 'congruent': 9}, 'OP': 'STOR'} {'OP': 'LOAD', 'src': {'same': False, 'NT': False, 'AVXalign': False, 'size': 4, 'type': 'addresses_normal_ht', 'congruent': 0}} {'OP': 'LOAD', 'src': {'same': False, 'NT': False, 'AVXalign': False, 'size': 16, 'type': 'addresses_D_ht', 'congruent': 4}} {'dst': {'same': False, 'congruent': 5, 'type': 'addresses_normal_ht'}, 'OP': 'REPM', 'src': {'same': False, 'congruent': 7, 'type': 'addresses_D_ht'}} {'dst': {'same': False, 'congruent': 0, 'type': 'addresses_normal_ht'}, 'OP': 'REPM', 'src': {'same': False, 'congruent': 5, 'type': 'addresses_normal_ht'}} {'OP': 'LOAD', 'src': {'same': False, 'NT': False, 'AVXalign': False, 'size': 2, 'type': 'addresses_A_ht', 'congruent': 9}} {'58': 21829} 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 */
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Copyright (c) GeoWorks 1992 -- All Rights Reserved PROJECT: PC GEOS MODULE: GeoDex/Database FILE: dbRecord.asm AUTHOR: Ted H. Kim ROUTINES: Name Description ---- ----------- BinarySearch Performs binary search on main table CompareKeys Compares the key field of two records CompareName Compares the index field of two records DeleteFromMainTable Remove a record from the main table InsertRecord Insert a new record into the database file InitRecord Reads in text strings from text objects InitPhone Initializes phone entries CopyPhone Copies old phone numbers into new record GetRecord Gets text strings into several temp blocks InsertIntoMainTable Inserts new record into main table FindLetter Finds and displays the record for a given tab FindEntryInCurTab Finds record handle for a given letter tab ID ClearRecord Clears all of the text edit fields ClearTextFields Clears given number of text edit fields ComparePhoneticName Compares the phonetic field of two records REVISION HISTORY: Name Date Description ---- ---- ----------- ted 8/29/89 Initial revision ted 3/3/92 Complete restructuring for 2.0 witt 2/7/94 Added sort mangling for Pizza/J DESCRIPTION: This file contains various record level routines for managing database. The term "sort mangling" refers to changing the first letter of the 'sortBuffer' and each key to perform comparisons. For instance, if you wanted the letters to appear in reverse order, you would write a routine that does: if( chr is alpha), chr = 'Z' - toupper(chr). This mangled value is then feed to the LocalCompareStringNoCase function. Since the mangled letter is used only for comparisions, the 'toupper' trick above will work. Only the first char needs mangling. ***** To sure the letter tabs follow this order ***** $Id: dbRecord.asm,v 1.1 97/04/04 15:49:43 newdeal Exp $ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ CommonCode segment resource COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% BinarySearch %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Performs binary search on main table. Returns a matching TableEntry pointer that points into the card database. **************************************************************************** Here is an overview of how GeoDex (Pizza) sorts its entries: A is the entry to be inserted. L[] is the array of existing entries. 1. -- To decide if A is < or > than L[x], GeoDex first compares the tabs under which A and L[x] lie. The tabs are ordered as such: A KA SA TA NA HA MA YA RA WA Roman A - any index beginning with Roman chars * - anything else, including all Kanji & punctuation For example, index fields beginning with the following chars would fall under the 'SA' tab and would be considered equal by the previous KeyCompare: {hiragana sa,si,su,se,so; katakana sa, si, su, se,so, and katakana halfwidth sa, si, su, se, so}. 2. -- If A and L[x] fall under the same tab, then GeoDex compares the index fields (SJIS order), treating halfwidth and fullwidth characters as the same. For example, halfwidth si would be greater than fullwidth sa, but halfwidth si and fullwidth si would be considered equal. Using SJIS order, all hiragana characters that fall under the 'SA' tab will come before any of the katakana half or fullwidth characters. Only the first two chars of the index fields are compared. 3. -- If the index fields of A and L[x] are found to be equal in (2), then the last check is of the Phonetic Fields. This check follows the same rules as the index compare (SJIS order, no difference between halfwidth and fullwidth), but the full length of these fields are compared. 4. -- If the phonetic fields are equal, then A is found to be less than L[x] and will be inserted directly before L[x]. 5. -- For non-Pizza, The tabs are the letters A-Z and each record is mapped to one of these tabs. Each TableEntry contains the tab (so we don't have to lock the entire DBRecord for the initial check). If the tabs are equal, then the entire Index fields are compared (ascii order). **************************************************************************** CALLED BY: UTILITY PASS: ds - dgroup ds:sortBuffer - key cx - number of entries in table es:si - points to the beginning of table to search for if PZ_PCGEOS (GEOS/J) ds:phoneticBuf - 2nd key RETURN: es:si - offset into the table to insert or delete dx - offset to the end of table carry set if es:si is equal to the key in sortBuffer DESTROYED: bx, cx, di PSEUDO CODE/STRATEGY: size = number of entries * (size TableEntry) bottom = size + top loop1: middle = (size / 2) + top while top != middle compare passed key to table key if greater compare: if middle = bottom exit else middle = middle + (size TableEntry) top = middle if top = bottom exit else go to loop1 if less loop3: if middle = top exit else middle = middle - (size TableEntry) bottom = middle if top = bottom exit else go to loop1 if equal compare secondary key if greater go to compare if less go to lopp3 if equal, exit KNOWN BUGS/SIDE EFFECTS/IDEAS: REVISION HISTORY: Name Date Description ---- ---- ----------- Ted 8/29/89 Initial version Ted 9/19/89 Now comparsions are done in upper cases Ted 3/28/90 The 1st two letters of index are already in CAPS witt 2/3/94 Works with 6 byte DBCS TableEntry size witt 2/7/94 Pizza specific sort mangling %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ BinarySearch proc near top local word ; ptr to top of current search area middle local word ; ptr to middle of current search area bottom local word ; ptr to bottom of current search area endPtr local word ; ptr to the end of 'gmb.GMB_mainTable' .enter ; initialize local variables mov top, si ; save pointer to top entry mov middle, si ; initially middle = top TableEntryIndexToOffset cx ; cx - size add si, cx ; si - points to the bottom of table ; the difference between 'bottom' and 'endPtr' is that 'endPtr' ; is pointing to the end of table all the time, whereas 'bottom' ; moves around as we keep halving the size of area to be searched. mov endPtr, si mov bottom, si tst_clc cx ; empty table? LONG je exit ; exit if so mainLoop: ; calculate 'middle' where middle = (size / 2) + top. ; cx = record offset mov si, top shr cx, 1 ; divided in half TableEntryOffsetMask cx ; make sure the result be in multiples of 4 add si, cx ; si - middle cmp si, endPtr ; is middle = end? jne compare ; if not, skip ; because I eliminate the middle entry from the search list ; on the next iteration, it is possible that the new list will ; contain only one item and have size value (= bottom - top) of ; sizeof(TableRecord). ; In this case, new middle value will be pointing at bottom, ; which is illegal. So following adjustment is necessary. sub si, cx ; restore middle value ; compare the middle entry. if greater, ; check bottom half of the table. if less, top half compare: mov middle, si ; we have new value for 'middle' call CompareKeys ; compare the key fields je equal ; if equal, check entire index field ja greater ; search the top half of the table less: mov si, middle cmp si, top ; middle = top? je specialCase ; if so, exit ; we don't have to include the entry pointed to by 'middle' ; in this search because it has already been compared sub si, size TableEntry mov bottom, si ; si - new bottom cmp top, si ; is bottom >= top? jae specialCase ; if so, exit jmp mainLoop ; if not, continue... ; search the bottom half of the table greater: mov si, middle cmp si, bottom ; is middle = bottom? je specialCase ; if so, exit ; we don't have to include the entry pointed to by 'middle' ; in this search because it has already been compared add si, size TableEntry mov top, si ; si - new top mov di, bottom cmp top, di ; bottom >= top? jae specialCase ; if so, exit sub di, top ; di = bottom - top mov cx, di ; cx = new size jmp mainLoop ; continue searching ; primary key fields match, now compare the entire index field equal: mov bx, ds:[curRecord] ; bx - current record handle cmp bx, es:[si].TE_item ; compare DB item handles je exit ; if equal, exit ; compare the entire index field call CompareName PZ < jnz endCompare ; if not equal, go ahead > PZ < call ComparePhoneticName ; compare phonetic fields > PZ <endCompare: > ja greater ; if greater, check bottom half jb less ; if less, check top half stc ; flag equality jmp exit ; since the entry pointed to by "middle" gets eliminated ; on the next iteration from the current search area, ; it is possible that the record being compared can be less ; than "middle"(which no longer is in the list) but greater ; than the last item in the new search list. (This is assuming ; the case where the top half of the table is selected ; for the next iteration of search.) In this case, ; the pointer has to be pushed down one entry and point ; to previous "middle", so the deletion or insertion can ; be performed properly. ; most likely there will be only one entry in the current ; search area. What we are trying to do here is to figure ; out whether the offset to insert at and delete from is ; the current one or the one entry after specialCase: cmp si, endPtr ; is it pointing to the last entry? je exit ; if so, exit (carry clear) call CompareKeys ; compare the key fields jb exitNotEqual ; if less, no need for adjustment ja adjust ; if greater, adjust the offset mov bx, ds:[curRecord] ; bx - current record item number cmp bx, es:[si].TE_item ; compare the item numbers je exit ; if equal, exit call CompareName ; compare the sort fields PZ < jnz endCompare2 ; if not equal, go ahead > PZ < call ComparePhoneticName ; compare the phonetic fields > PZ <endCompare2: > jb exitNotEqual ; if not greater, no need for adjustment ja adjust ; if greater, adjust the offset stc ; flag equal (XXX: will this ever?) jmp exit adjust: add si, size TableEntry ; move the pointer to next entry exitNotEqual: clc ; flag es:si != sortBuffer exit: mov dx, endPtr .leave ret BinarySearch endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CompareKeys %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Compares two key strings using localization driver. CALLED BY: BinarySearch, FindEntryInCurTab PASS: es:si - pointer to TableEntry with key string2 to compare ds:sortBuffer - pointer to key string1 to compare ds:curLetterLen - char count for string comparison ds - dgroup RETURN: flags set with the results of compare (Less,Equal,Greater) DESTROYED: nothing STRATEGIES/A.S.N.: Compare characters in key (doesn't require MemLock). If equal, call CompareName for complete index string comparison (needs MemLock). Return results of compare. KNOWN BUGS/SIDE EFFECTS/IDEAS: Changes ds:keyBuffer. ds:sortBuffer should be sort mangled. This routine handles any sort mangling for the record. Restores when done. In case of Pizza, first letters in sortBuffer is mangled. (e.g. C_HIRAGANA_LETTER_I -> C_HIRAGANA_LETTER_A) For this routine, when is 'curLetterLen' greater than 2? There is warning because DBCS section has not been converted. REVISION HISTORY: Name Date Description ---- ---- ----------- Ted 1/11/91 Initial version witt 2/7/94 DBCS conversion %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ CompareKeys proc near uses ax, cx, si, di, es .enter cmp ds:[curLetterLen], (length TE_key) ; two or less letters? jg long ; if not, skip if DBCS_PCGEOS mov ax, {wchar} es:[si].TE_key[0] ; first wchar mov {wchar} ds:[keyBuffer], ax mov ax, {wchar} es:[si].TE_key[2] ; second wchar mov {wchar} ds:[keyBuffer][2], ax else mov ax, es:[si].TE_key ; ax - key string2 mov ds:[keyBuffer], ah mov ds:[keyBuffer+1], al ; store it in a temp buffer endif segmov es, ds mov si, offset sortBuffer ; ds:si - ptr to key string1 mov di, offset keyBuffer ; es:di - ptr to key string2 mov cx, ds:[curLetterLen] ; cx - # of chars to compare if PZ_PCGEOS mov ax, {wchar} ds:[si] call GetPizzaLexicalValueNear cmp ax, {wchar} es:[di] ; compare Tabs else call CompareUsingSortOptionNoCase ; compare the strings endif jmp done ; exit with flags set long: DBCS < WARNING COMPARE_KEYS_LONG > mov di, es:[si].TE_item call DBLockNO ; lock this record chunk mov di, es:[di] ; di - offset to record data add di, size DB_Record ; es:di - ptr to index field mov si, offset sortBuffer ; ds:si - ptr to sort buffer mov cx, ds:[curLetterLen] ; cx - # of chars to compare call CompareUsingSortOptionNoCase ; compare two strings pushf ; save flags call DBUnlock ; unlock this block popf ; restore flags done: .leave ret CompareKeys endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CompareName %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Compares the sort fields of two records that have same first two characters. CALLED BY: BinarySearch, LinearSearch PASS: es:si - points to the entry in main table to be compared sortBuffer - contains sort field of record to compare RETURN: zero flag and carry flag are set to reflect the result of comparison DESTROYED: nothing KNOWN BUGS/SIDE EFFECTS/IDEAS: ds:sortBuffer should be sort mangled. This routine handles any sort mangling for the record. Restores when done. REVISION HISTORY: Name Date Description ---- ---- ----------- Ted 9/6/89 Initial version Ted 9/19/89 Now handles lower and upper cases witt 2/7/94 Pizza specific sort mangling %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ CompareName proc near uses ax, cx, si, di, es, bp .enter mov di, es:[si].TE_item ; di - item number call DBLockNO ; lock this record chunk mov di, es:[di] ; di - offset to record data add di, size DB_Record ; es:di - ptr to index field mov si, offset sortBuffer ; ds:si - ptr to 'sortBuffer' clr cx ; strings are null terminated call CompareUsingSortOptionNoCase ; compare two strings call DBUnlock ; (preserves flags) .leave ret CompareName endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DeleteFromMainTable %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Deletes the current record from main table. CALLED BY: UTILITY PASS: ds - segment of core block curRecord - record handle to delete sortBuffer - index field text of current record RETURN: gmb.GMB_numMainTab is updated the record item itself continues to live, just not in the main table DESTROYED: ax, bx, cx, dx, si, di, es PSEUDO CODE/STRATEGY: Locate the record handle from main table Move the data below this entry up four bytes Decrement the counter for main table KNOWN BUGS/SIDE EFFECTS/IDEAS: REVISION HISTORY: Name Date Description ---- ---- ----------- ted 8/29/89 Initial version ted 12/4/89 Added checks for non-alphabetical record %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ DeleteFromMainTable proc far ; do some extra work if we have the index name list up cmp ds:[displayStatus], CARD_VIEW ; is car view only? je skip ; if so, skip call DeleteFromNameList ; delete from name list skip: mov dx, ds:[curOffset] ; dx - offset to record to delete mov cx, size TableEntry ; cx - size of table entry mov di, ds:[gmb.GMB_mainTable] ; di - handle of main table call DBLockNO mov si, es:[di] ; es:si - points to beg of main table add si, dx mov ax, es:[si].TE_key ; ax - 1st two letters of last name call DBUnlock ; delete this entry from the main table mov di, ds:[gmb.GMB_mainTable] ; di - handle of main table call DBDeleteAtNO ; delete this record entry ; update proper number of entry variables call CheckForNonAlpha ; was this non-alphabetic record? jnc alpha ; if not, skip dec ds:[gmb.GMB_numNonAlpha] ; update number of non-alpha records jmp short exit alpha: sub ds:[gmb.GMB_offsetToNonAlpha], size TableEntry ; update offset exit: dec ds:[gmb.GMB_numMainTab] ; decrement the main table counter call MarkMapDirty ; mark the map block dirty tst ds:[gmb.GMB_numMainTab] ; is database empty? jne quit ; if not, skip ; if the database is empty, disable some menus GetResourceHandleNS MenuResource, bx mov si, offset EditCopyRecord ; bx:si - OD of copy record menu call DisableObject ; disable copy record menu mov si, offset RolPrintControl ; bx:si - OD of print menu call DisableObject ; disable print menu mov si, offset SortOptions ; bx:si - OD of Sorting Options menu call DisableObject ; disable sort options menu quit: sub ds:[gmb.GMB_endOffset], size TableEntry ; update GMB_endOffset EC < mov cx, ds:[gmb.GMB_numMainTab] ; cx - # of entries in table> EC < TableEntryIndexToOffset cx > EC < cmp cx, ds:[gmb.GMB_endOffset] ; this should be equal > EC < ERROR_NE CORRUPTED_DATA_FILE > ret DeleteFromMainTable endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% InsertRecord %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Inserts current record into database file. CALLED BY: UTILITY PASS: ds - segment of core block curRecord, gmb.GMB_curPhoneIndex, displayStatus RETURN: nothing DESTROYED: ax, bx, cx, dx, si, di, es PSEUDO CODE/STRATEGY: none KNOWN BUGS/SIDE EFFECTS/IDEAS: none REVISION HISTORY: Name Date Description ---- ---- ----------- ted 9/7/89 Initial version ted 12/5/89 Doesn't create the new record %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ InsertRecord proc far mov di, ds:[curRecord] ; di - current record handle call DBLockNO mov di, es:[di] ; open it mov dx, ds:[gmb.GMB_curPhoneIndex] ; dx - current phone number counter mov es:[di].DBR_phoneDisp, dl ; save it EC < cmp es:[di].DBR_noPhoneNo, dx > EC < ERROR_LE IN_INSERT_RECORD_WITH_PHONE_COUNT > call DBUnlock ; close it mov si, ds:[curRecord] ; si - current record handle call GetLastName ; read in index field into sortBuffer PZ < call GetPhoneticName ; read phonetic into sortPhoneticBuf> call InsertIntoMainTable ; insert record into main table cmp ds:[displayStatus], CARD_VIEW ; is card view up? je exit ; if so, skip call AddToNameList ; insert the name to name list exit: andnf ds:[recStatus], not mask RSF_NEW ; clear flag ret InsertRecord endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% InitRecord %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Creates a new record entry and initialize it. CALLED BY: UTILITY PASS: ds - segment of core block ax - flag to indicate whether to (0) copy everything or (-1) just phone fields RETURN: dx - handle of data block cx - size of data block carry set if error DESTROYED: ax, bx, si, di, bp, es PSEUDO CODE/STRATEGY: KNOWN BUGS/SIDE EFFECTS/IDEAS: REVISION HISTORY: Name Date Description ---- ---- ----------- ted 9/4/89 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ InitRecord proc far ; allocate a new DB block push ax ; save the flag mov cx, size DB_Record ; cx - size of a new record call DBAllocNO ; allocate a new data record mov ds:[curRecord], di ; save the handle call DBLockNO ; lock it mov si, es:[di] ; di - pointer to beg. of record data ; initialize the header clr es:[si].DBR_notes mov es:[si].DBR_noPhoneNo, NUM_DEFAULT_PHONE_TYPES mov es:[si].DBR_toAddr, size DB_Record mov es:[si].DBR_toPhone, size DB_Record PZ < mov es:[si].DBR_toPhonetic, size DB_Record > PZ < mov es:[si].DBR_toZip, size DB_Record > clr es:[si].DBR_indexSize clr es:[si].DBR_addrSize PZ < clr es:[si].DBR_phoneticSize > PZ < clr es:[si].DBR_zipSize > mov dx, ds:[gmb.GMB_curPhoneIndex] mov es:[si].DBR_phoneDisp, dl call DBUnlock ; if this is called by "UNDO" routine, then we need to copy ; all the phone numbers into this new record. So that when ; this old record is deleted or modified again, we can still ; reproduce all of the phone numbers from old record. cmp ds:[undoAction], UNDO_CHANGE ; was undo pressed? jl noUndo ; if not, skip tst ds:[undoItem] jz noUndo ; can't undo if there's no undo call CopyPhone ; if so, copy over all phone numbers jmp copy ; copy the rest of fields noUndo: call InitPhone ; initialize the phone # part of record copy: pop ax ; restore the flag tst ax ; should only phone fields updated? js phone ; if so, skip ; copy the text strings into DB block call UpdateIndex ; update index field call UpdateAddr ; update addres field call UpdateNotes ; update the notes field PZ < call UpdatePhonetic ; update phonetic field > PZ < call UpdateZip ; update zip field > phone: test ds:[dirtyFields], DFF_PHONE ; phone field modified? je exit ; if not, exit call UpdatePhone ; update phone number field jmp short quit exit: clc quit: ret InitRecord endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% InitPhone %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Initializes phone number entries in a record. Builds "NUM_DEFAULT_PHONE_TYPES" phones, all blank. CALLED BY: InitRecord PASS: curRecord - current record handle RETURN: nothing DESTROYED: cx, dx, si, di, es KNOWN BUGS/SIDE EFFECTS/IDEAS: * The index field has not been stored,ie, routine assumes it can use memory right after the DB_Record structure. REVISION HISTORY: Name Date Description ---- ---- ----------- Ted 12/7/89 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ InitPhone proc near mov cx, (size PhoneEntry)*NUM_DEFAULT_PHONE_TYPES ; cx - size of "default" phone entries mov di, ds:[curRecord] ; di - current record handle mov dx, size DB_Record ; dx - offset to insert at call DBInsertAtNO ; make room for phone numbers call DBLockNO ; lock it mov si, es:[di] ; si - pointer to beg. of record data add si, size DB_Record ; si - pointer to beg. of phone #'s clr dx ; initial phone type ID is 1 (really) clearPhoneLoop: inc dl ; dl <- increment the phone type ID clr es:[si].PE_count ; no calls made yet mov es:[si].PE_type, dl ; save phone number type mov es:[si].PE_length, 0 ; no phone number add si, size PhoneEntry ; go to the next entry cmp dl, NUM_DEFAULT_PHONE_TYPES ; are we done initializing? jne clearPhoneLoop ; if not, continue call DBUnlock ; if so, exit ret InitPhone endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CopyPhone %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Copies the phone number entries into a new record. CALLED BY: InitRecord PASS: ds - dgroup ds:[undoItem] - handle of undo record item RETURN: nothing DESTROYED: ax, bx, cx, dx, es, si, di PSEUDO CODE/STRATEGY: Calculate how many bytes need to be copied Make room for the string Copy the string into current record KNOWN BUGS/SIDE EFFECTS/IDEAS: none REVISION HISTORY: Name Date Description ---- ---- ----------- Ted 12/8/89 Initial version witt 1/21/94 DBCS-ized %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ CopyPhone proc near push ds ; save seg. address of core block mov di, ds:[undoItem] ; save the record handle in si clr ax ; ax - length of all phone numbers clr bx ; bx - length of all PhoneEntries call DBLockNO mov di, es:[di] ; open up this record mov cx, es:[di].DBR_noPhoneNo ; cx - total phone entries add di, es:[di].DBR_toPhone ; di - pointer to beg. phone entry moveForwardLoop: if DBCS_PCGEOS mov dx, es:[di].PE_length shl dx, 1 ; dx - phone number size add ax, dx ; ax - total phone number size add di, dx ; di - total record size else add ax, es:[di].PE_length ; ax - total phone number sizes add di, es:[di].PE_length endif add bx, size PhoneEntry ; bx - total phone entry length add di, size PhoneEntry ; di - pointer to the next entry loop moveForwardLoop ; continue... call DBUnlock mov cx, ax add cx, bx ; cx - total number of bytes to add mov di, ds:[curRecord] ; di - handle of record to insert mov dx, size DB_Record ; dx - offset to insert at call DBInsertAtNO ; make room for phone entries mov di, ds:[undoItem] ; di - handle of undone record call DBLockNO mov si, es:[di] ; open it up again mov dx, es:[si].DBR_noPhoneNo ; dx - total number of phone entries add si, es:[si].DBR_toPhone ; si - pointer to beg. of phone entries mov di, ds:[curRecord] ; di - handle of current record mov bx, ds:[fileHandle] ; bx - database file handle mov ax, ds:[groupHandle] ; ax - group handle segmov ds, es ; ds:si - source string call DBLock mov di, es:[di] ; open up current record mov es:[di].DBR_noPhoneNo, dx ; save new total # of phone entries add di, es:[di].DBR_toPhone ; es:di - destination DBCS<EC< test cx, 1 ; is size odd? > > DBCS<EC< ERROR_NZ SIZE_OF_PHONE_NO_IS_NOT_EVEN > > rep movsb ; copy the phone entries call DBUnlock segmov es, ds call DBUnlock ; close up records pop ds ; restore seg. address of core block ornf ds:[recStatus], mask RSF_UPDATE ; set update flag ret CopyPhone endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% GetRecord %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Reads in all the text strings into temporary buffers. CALLED BY: UTILITY PASS: ds - segment of core block cx - number of fields to read in di - offset to FieldTable (TEFO_xxx) RETURN: ds:fieldHandles - table of handles to data blocks ds:fieldLengths - table of lengths for each string DESTROYED: ax, bx, cx, dx, si, di PSEUDO CODE/STRATEGY: Clear empty flags, cuz there is probably something to save. For each text edit field read in each text string into a temporary buffer if the text field empty set the appropriate flag else save the handle to this buffer save the number of chars in each field Next field KNOWN BUGS/SIDE EFFECTS/IDEAS: If the text field is empty, zero is stored as block handle. REVISION HISTORY: Name Date Description ---- ---- ----------- Ted 9/4/89 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ GetRecord proc far ; assume not empty ; clear field flags - assume none of the text fields is empty andnf ds:[recStatus], not mask RSF_PHONE_NO_EMPTY and \ not mask RSF_PHONE_EMPTY and \ not mask RSF_EMPTY cmp cx, 2 ; read in phone fields only? jg allFields ; if not, skip if PZ_PCGEOS ornf ds:[recStatus], mask RSF_SORT_EMPTY or \ mask RSF_ADDR_EMPTY or \ mask RSF_NOTE_EMPTY or \ mask RSF_PHONETIC_EMPTY or \ mask RSF_ZIP_EMPTY else ornf ds:[recStatus], mask RSF_SORT_EMPTY or \ mask RSF_ADDR_EMPTY or \ mask RSF_NOTE_EMPTY endif jmp fieldLoop allFields: if PZ_PCGEOS andnf ds:[recStatus], not mask RSF_SORT_EMPTY and \ not mask RSF_ADDR_EMPTY and \ not mask RSF_NOTE_EMPTY and \ not mask RSF_ZIP_EMPTY and \ not mask RSF_PHONETIC_EMPTY else andnf ds:[recStatus], not mask RSF_SORT_EMPTY and \ not mask RSF_ADDR_EMPTY and \ not mask RSF_NOTE_EMPTY endif fieldLoop: push cx ; save # of text edit fields to examine GetResourceHandleNS Interface, bx ; get handle of UI block cmp di, TEFO_NOTE ; are we doing NoteText field? jne notNoteField ; if not, skip GetResourceHandleNS WindowResource, bx ; get handle of menu block notNoteField: mov si, ds:FieldTable[di] ; bx:si - OD of text edit object call GetTextInMemBlock ; returns cx - # chars or 0 ; returns ax - handle of mem block ifdef GPC ; ; ignore empty record instructions placed into text fields ; jcxz textEmpty push ax, cx, di mov ax, MSG_VIS_TEXT_GET_STATE mov di, mask MF_CALL call ObjMessage test cl, mask VTS_EDITABLE jnz textOkay pop bx, cx, di call MemFree ; free invalid text block clr ax, cx ; indicate no text jmp short textEmpty textOkay: pop ax, cx, di textEmpty: endif mov bx, ds:fieldHandles[di] ; bx - handle of text block tst bx ; is there an old text block to delete? je skip ; if not, skip call MemFree ; if so, delete it clr ds:fieldHandles[di] ; clear the handle skip: pop bx ; bx - # of text edit fields left jcxz empty ; is this field empty? (len==0) mov ds:fieldHandles[di], ax ; save handle of text block ; cx - number of chars in buffer inc cx ; add one for null terminator next: mov ds:fieldLengths[di], cx ; save length of string add di, (size nptr) ; di - points to the next field offset mov cx, bx ; cx - # of fields left to examine loop fieldLoop ; on to the next field jmp short setFlags ; jump to set flags empty: ; set the approriate RSF_****_EMPTY flag clr ds:fieldHandles[di] ; clear the handle mov ax, 1 mov cx, bx ; cx - # of fields left to examine shl ax, cl ; ax - mask RSF_****_EMPTY or ds:[recStatus], ax ; set the empty flag for this field clr cx ; cx - length of string jmp next setFlags: test ds:[recStatus], mask RSF_SORT_EMPTY ; is index empty? je exit ; if not, exit test ds:[recStatus], mask RSF_ADDR_EMPTY ; is addr empty? je exit ; if not, exit test ds:[recStatus], mask RSF_NOTE_EMPTY ; is note empty? je exit ; if not, exit test ds:[recStatus], mask RSF_PHONE_NO_EMPTY ; is phone # emtpy? je exit ; if not, exit PZ < test ds:[recStatus], mask RSF_PHONETIC_EMPTY ; is phonetic emtpy?> PZ < je exit ; if not, exit > PZ < test ds:[recStatus], mask RSF_ZIP_EMPTY ; is zip emtpy? > PZ < je exit ; if not, exit > ornf ds:[recStatus], mask RSF_EMPTY ; if so, record is blank exit: ret GetRecord endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% InsertIntoMainTable %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Inserts the new record into main table. CALLED BY: (INTERNAL) InsertRecord, SaveCurRecord PASS: ds - segment addr of core block curRecord - handle of new record RETURN: gmb.GMB_numMainTab updated DESTROYED: ax, bx, cx, dx, es, si, di PSEUDO CODE/STRATEGY: Locate a place to insert the new record Move down all the entries below it If first char of letter tab is non-alpha, incr non-alpha counter. Insert the new record KNOWN BUGS/SIDE EFFECTS/IDEAS: none REVISION HISTORY: Name Date Description ---- ---- ----------- ted 9/7/89 Initial version ted 12/5/89 Added checks for non-alphabetical records witt 2/1/94 DBCS-ized %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ InsertIntoMainTable proc far DBCS< PrintMessage <InsertIntoMainTable - Adapt for letter pairs> > if not PZ_PCGEOS ; since sortBuffer is not the same as Index field on pizza version ; we can't error check like this. EC < mov di, ds:[curRecord] > EC < call DBLockNO > EC < mov di, es:[di] > EC < mov cx, es:[di].DBR_indexSize > EC < add di, size DB_Record ; es:di - index field > EC < mov si, offset sortBuffer ; ds:si - sort buffer > EC < repe cmpsb > EC < call DBUnlock > EC < jcxz noError ; if reached end, then OK > EC < ERROR SORT_BUFFER_IS_NOT_CURRENT > EC <noError: > endif call FindSortBufInMainTable ; dx <- insertion point w/in main table mov cx, size TableEntry ; cx - number of bytes to move ; make room for one new entry in 'gmb.GMB_mainTable' mov di, ds:[gmb.GMB_mainTable] ; di - handle of table call DBInsertAtNO ; creates 'cx' bytes ; store the key and DB handle in 'gmb.GMB_mainTable' call DBLockNO mov si, es:[di] ; open up this data block add si, dx ; si - place to insert the new record mov di, ds:[curRecord] ; di - handle of new record mov es:[si].TE_item, di ; store the new item number SBCS < mov es:[si].TE_key, ax ; store the first two letters > if DBCS_PCGEOS PZ < mov es:[si].TE_key[0], ax ; store the first letter > NPZ < mov cx, ds:sortBuffer[0] > NPZ < mov es:[si].TE_key[0], cx > endif if DBCS_PCGEOS mov cx, ds:sortBuffer[2] mov es:[si].TE_key[2], cx ; store the second letter clr es:[si].TE_unused ; zero unused element endif call DBUnlock ; update number of entry variables ; ah/ax = first char in index field mov ds:[curOffset], dx ; is new rec inserted after cur. rec? call CheckForNonAlpha ; was this an alphabetical record? jnc alpha2 ; if so, skip inc ds:[gmb.GMB_numNonAlpha] ; update number of non-alpha jmp updateDB alpha2: add ds:[gmb.GMB_offsetToNonAlpha], (size TableEntry) ; update offset updateDB: inc ds:[gmb.GMB_numMainTab] ; increment main table counter call MarkMapDirty ; mark the map block dirty cmp ds:[gmb.GMB_numMainTab], 1 ; one entry in database? jne done ; if not, skip ; if the database was empty before this new entry was inserted ; enable 'CopyRecord', 'Print', 'Sorting Options' menu. GetResourceHandleNS MenuResource, bx mov si, offset EditCopyRecord ; bx:si - OD of copy record menu call EnableObject ; enable copy record menu mov si, offset RolPrintControl ; bx:si - OD of print menu call EnableObject ; enable print menu mov si, offset SortOptions ; bx:si - OD of Sorting Options menu call EnableObject ; enable sort options menu done: add ds:[gmb.GMB_endOffset], size TableEntry ; update the ptr to end EC < mov cx, ds:[gmb.GMB_numMainTab] ; cx - # of entries in table> EC < TableEntryIndexToOffset cx > EC < cmp cx, ds:[gmb.GMB_endOffset] ; this must be equal > EC < ERROR_NE CORRUPTED_DATA_FILE ; if not, send up a flag > ret InsertIntoMainTable endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% FindSortBufInMainTable %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Attempt to find the record whose index field is in ds:[sortBuffer] CALLED BY: (EXTERNAL) InsertIntoMainTable PASS: ds = dgroup sortBuffer = index for which to search RETURN: carry set if found record with identical index field carry clear if found insertion point dx = offset into table of found record/insertion point cx = handle of item at that offset ax = key (first two letters of index) DESTROYED: di, es SIDE EFFECTS: PSEUDO CODE/STRATEGY: REVISION HISTORY: Name Date Description ---- ---- ----------- ardeb 10/12/94 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ FindSortBufInMainTable proc far .enter ; 1st two letters of index field is the key field of main table mov di, ds:[gmb.GMB_mainTable] ; di - handle for main table call DBLockNO ; open up the main table SBCS < mov ah, ds:[sortBuffer] ; ax - key to search with > SBCS < mov al, ds:[sortBuffer+1] > DBCS < mov ax, {wchar} ds:[sortBuffer] ; one char for DBCS > if PZ_PCGEOS call GetPizzaLexicalValueNear ; change key character to alphabet endif ; update 'curLetterLen' if DBCS_PCGEOS mov ds:[curLetterLen], 1 ; always 1 in DBCS else mov ds:[curLetterLen], 2 ; assume there are two letters tst al ; second letter exists? jne twoLetter ; if so, skip mov ds:[curLetterLen], 1 ; there is only one letter in key twoLetter: endif mov si, es:[di] ; es:si - offset to the data mov dx, si push dx ; save the offset to beg of main table mov cx, ds:[gmb.GMB_numMainTab] ; cx - # records in main table ; don't have to search if the table is empty jcxz skipSearch ; if main table is empty, skip search ; figure out which area to search, non-alphabet or alphabet add dx, ds:[gmb.GMB_endOffset] ; dx - offset to end of main table call CheckForNonAlpha ; is this record alphabetical? jnc alpha1 ; if so, skip add si, ds:[gmb.GMB_offsetToNonAlpha] ; offset to non-alpha mov cx, ds:[gmb.GMB_numNonAlpha] ; cx - # of non-alpha records jmp search alpha1: sub cx, ds:[gmb.GMB_numNonAlpha] ; cx - # alphabetical records search: ; perform the binary search call BinarySearch ; returns es:si - ptr to insert ; insert this entry into the database skipSearch: pop dx ; dx - beg of table mov cx, es:[si].TE_item pushf sub si, dx ; si - place to insert mov dx, si ; dx - offset to place to insert call DBUnlock popf .leave ret FindSortBufInMainTable endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CheckIfRecordExists %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Attempt to find the record with passed index field CALLED BY: (EXTERNAL) InsertIntoMainTable PASS: ds = dgroup es:di = index RETURN: carry set if found record with identical index field carry clear if found insertion point dx = offset into table of found record/insertion point cx = handle of item at that offset DESTROYED: nothing SIDE EFFECTS: PSEUDO CODE/STRATEGY: REVISION HISTORY: Name Date Description ---- ---- ----------- brianc 9/6/99 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ ifdef GPC CheckIfRecordExists proc far uses ax, bx, si, es, di, bp .enter ; ; set up curLetterLen and sortBuffer ; call LocalStringLength push ds:[curLetterLen] ; save this mov ds:[curLetterLen], cx push ds ; save dgroup segxchg ds, es mov si, di ; ds:si = passed search key mov di, offset sortBuffer ; es:di = sortBuffer LocalCopyString pop ds ; ds = dgroup ; ; access database ; mov di, ds:[gmb.GMB_mainTable] ; di - handle for main table call DBLockNO ; open up the main table mov si, es:[di] ; es:si - offset to the data mov dx, si push dx ; save the offset to beg of main table mov cx, ds:[gmb.GMB_numMainTab] ; cx - # records in main table jcxz skipSearch ; if main table is empty, skip search ; ; figure out which area to search, non-alphabet or alphabet ; mov ah, ds:[sortBuffer] call CheckForNonAlpha ; is this record alphabetical? jnc alpha1 ; if so, skip add si, ds:[gmb.GMB_offsetToNonAlpha] ; offset to non-alpha mov cx, ds:[gmb.GMB_numNonAlpha] ; cx - # of non-alpha records jmp search alpha1: sub cx, ds:[gmb.GMB_numNonAlpha] ; cx - # alphabetical records search: ; perform the binary search push ds:[curRecord] mov ds:[curRecord], 0 ; make sure to search everything call BinarySearch ; returns es:si - ptr to insert pop ds:[curRecord] ; ; return search results ; skipSearch: pop dx ; dx - beg of table mov cx, es:[si].TE_item pushf sub si, dx ; si - place to insert mov dx, si ; dx - offset to place to insert call DBUnlock popf pop ds:[curLetterLen] ; restore this .leave ret CheckIfRecordExists endp endif COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% FindLetter %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Finds the handle of the first record in sorted order whose first letter in the last name field corresponds to the given letter and displays it. CALLED BY: (GLOBAL) PASS: ds - segment of core block dl - letter tab ID RETURN: nothing DESTROYED: ax, bx, cx, dx, es, si, di, bp PSEUDO CODE/STRATEGY: Updates the current record, if modified KNOWN BUGS/SIDE EFFECTS/IDEAS: Depends on FindEntryInCurTab to determine "sorted ordering." REVISION HISTORY: Name Date Description ---- ---- ----------- ted 9/7/89 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ FindLetter proc far class RolodexClass ; update the currently display record if it is modified push dx call SaveCurRecord pop dx test ds:[recStatus], mask RSF_WARNING ; was warning box up? je start ; if not, skip ; If the record is not blank and index field is empty, a warning box ; should have been put up by 'SaveCurRecord'. If the user click on YES, ; then exit this routine, thereby giving the user one more chance ; to enter data into idnex field. Otherwise, continue. cmp ax, IC_YES ; was YES selected? je exit ; if so, exit start: tst ds:[gmb.GMB_numMainTab] ; is database empty? je empty ; if so, skip ; get the handle of record that should be displayed call FindEntryInCurTab tst si ; no records with this letter tab? je noneFound ; skip if no record ; display this record clr ds:[recStatus] ; clear all record flags ornf ds:[recStatus], mask RSF_FIND_LETTER call DisplayCurRecord andnf ds:[searchFlag], not mask SOF_NEW andnf ds:[recStatus], not mask RSF_FIND_LETTER ; update the index list if it is enabled cmp ds:[displayStatus], CARD_VIEW ; is card view only? je skip ; if so, skip call UpdateNameList ; update the name list skip: call EnableCopyRecord ; enable 'CopyRecord' menu clr ds:[recStatus] ; clear all record flags jmp quit ; and exit ; no record to display, just clear the record fields noneFound: ifdef GPC noRecordCommon label far endif call ClearRecord ; clear text fields mov ds:[recStatus], mask RSF_EMPTY or mask RSF_NEW ; set flags clr ds:[curRecord] ; current record is blank cmp ds:[displayStatus], CARD_VIEW ; is card view only? je empty ; if so, skip call SetNewExclusive ; update the name list empty: ; do some housekeeping before exiting call DisableCopyRecord ; disable 'CopyRecord' menu call FocusSortField ; give focus to index field quit: clr ds:[undoItem] ; no undoable action exists exit: call DisableUndo ; disable 'undo' menu clr ds:[ignoreInput] ; accept mouse presses ret FindLetter endm ifdef GPC SimulateNoRecord proc far jmp noRecordCommon SimulateNoRecord endp endif COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% FindEntryInCurTab %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Given the letter tab ID, it returns the handle of record that starts with this letter. Possible that no letter is found, as user could have clicked on a blank. CALLED BY: FindLetter, FindNextTabLetterWithEntry, FindPrevTabLetterWithEntry PASS: dl - letter tab ID (0-based) RETURN: si - handle of record that should be displayed si = 0 if no entry under this letter tab DESTROYED: bx, cx, si, di, es SIDE EFFECTS: none PSEUDO CODE/STRATEGY: This routine determines the "search order", if any. Uses CompareKeys for equal/not-equal compare. REVISION HISTORY: Name Date Description ---- ---- ----------- THK 6/92 Initial revision %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ FindEntryInCurTab proc near uses ax, dx, bp .enter ; first get the letter tab string for the current tab mov si, offset MyLetters ; bx:si - OD of MyLetters GetResourceHandleNS MyLetters, bx mov ax, MSG_LETTERS_GET_TAB_LETTER mov di, mask MF_FIXUP_DS or mask MF_CALL call ObjMessage ; inspect string on letter tab. ; 'sortBuffer' has tab string; ; 'curLetterLen' has string length. tst ds:[gmb.GMB_numMainTab] ; is database empty? je notFound ; if so, skip mov di, ds:[gmb.GMB_mainTable] ; di - handle of main table call DBLockNO mov si, es:[di] ; open up the main table cmp ds:[curLetterLen], 1 ; tab with only one letter? jne alphabet ; if not, skip jb notFound ; don't search empty letter tabs. ; if the tab letter string starts with a space character (or NULL) ; then it is a blank tab. Just ignore it. ; WHEN LOCALIZING THESE TABS, MAKE SURE THAT TAB LETTER ; STRINGS DON'T START WITH A SPACE CHARACTER ted - 3/23/93 LocalGetChar ax, ds:[sortBuffer], NO_ADVANCE LocalIsNull ax ; NULL or space => empty je notFound LocalCmpChar ax, ' ' je notFound LocalCmpChar ax, '*' ; is it '*'? (wildcard) jne alphabet ; if not, skip ; the current entry is the "wildcard" entry mov cx, ds:[gmb.GMB_offsetToNonAlpha] ; cx - offset to 1st non-alpha mov ds:[curOffset], cx ; save the offset tst ds:[gmb.GMB_numNonAlpha]; are there any records under '*'? je notFound ; if none, skip add si, cx ; si - ptr to 1st non-alpha entry mov si, es:[si].TE_item ; si - record handle jmp exit ; display this record alphabet: mov cx, ds:[gmb.GMB_numMainTab] ; cx - number of records in main table sub cx, ds:[gmb.GMB_numNonAlpha] ; cx - # of alphabetical entries ; search the gmb.GMB_mainTable to find the handle of record that matches ; the given letter tab string push si ; save the ptr to the beg of main table push ds:[curRecord] clr ds:[curRecord] PZ < ; We have to clear sortPhoneticBuf since LetterTab does not > PZ < ; have phonetic field. > PZ < mov di, offset sortPhoneticBuf > PZ < LocalClrChar ds:[di] ; clr sortPhoneticBuf > call BinarySearch ; letter tabs always in ASCII order ; es:si - ptr to the entry found pop ds:[curRecord] pop bp ; bp - ptr to the beg. of main table ; update the variable 'curOffset' mov cx, si ; cx - ptr to the current record sub cx, bp ; cx - offset to current record mov ds:[curOffset], cx ; save the offset cmp si, dx ; is it the last entry? je notFound ; if so, no match ; make sure we have found the right entry call CompareKeys mov si, es:[si].TE_item ; si - record handle (assume OK) je exit ; skip if record with this lettter notFound: clr si ; no record found :-( exit: call DBUnlock ; close main table .leave ret FindEntryInCurTab endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ClearRecord %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Clears all the text edit fields and display 'HOME' for phone number type name. CALLED BY: UTILITY PASS: ds - segment addr of core block RETURN: nothing DESTROYED: ax, bx, cx, dx, si, di PSEUDO CODE/STRATEGY: Clear all of the text edit fields Display phone type name as "HOME" Set the flag KNOWN BUGS/SIDE EFFECTS/IDEAS: Setting the initial gmb.GMB_curPhoneIndex and curPhoneType is very touche! REVISION HISTORY: Name Date Description ---- ---- ----------- Ted 9/21/89 Initial version witt 1/31/94 Use symbolc constants instead of numbers %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ ClearRecord proc far mov cx, NUM_TEXT_EDIT_FIELDS+1 ; cx - number text fields to clear clr si ; si - points to table of field handles mov ds:[curPhoneType], PTI_HOME mov ds:[gmb.GMB_curPhoneIndex], 1 call ClearTextFields ; clear all the text edit fields call DisplayPhoneType ; display phone number type name ; enable phone number scroll icons mov si, offset ScrollUpTrigger ; bx:si - OD of down button GetResourceHandleNS ScrollUpTrigger, bx call EnableObject ; enable phone up button mov si, offset ScrollDownTrigger ; bx:si - OD of down button call EnableObject ; enable phone down button ornf ds:[recStatus], mask RSF_EMPTY ; set the record empty flag ifdef GPC call ClearPhoneNumbers call DisableRecords endif ret ClearRecord endp ifdef GPC ClearPhoneNumbers proc near uses ax, bx, cx, dx, si, di, bp .enter ; ; clear number field ; mov cx, length clearPhoneNumFields clr di GetResourceHandleNS Interface, bx clearLoop: push di, cx mov si, cs:clearPhoneNumFields[di] mov ax, MSG_VIS_TEXT_DELETE_ALL mov di, mask MF_FIXUP_DS call ObjMessage pop di, cx add di, size lptr loop clearLoop ; ; set default phone names ; mov cx, length clearPhoneNameFields clr di GetResourceHandleNS Interface, bx setLoop: push di, cx mov si, cs:clearPhoneNameFields[di] mov ax, MSG_VIS_TEXT_REPLACE_ALL_OPTR GetResourceHandleNS TextResource, dx mov bp, cs:clearPhoneNameStrings[di] clr cx mov di, mask MF_FIXUP_DS call ObjMessage pop di, cx add di, size lptr loop setLoop .leave ret ClearPhoneNumbers endp clearPhoneNumFields lptr \ offset Interface:StaticPhoneOneNumber, offset Interface:StaticPhoneTwoNumber, offset Interface:StaticPhoneThreeNumber, offset Interface:StaticPhoneFourNumber, offset Interface:StaticPhoneFiveNumber, offset Interface:StaticPhoneSixNumber, offset Interface:StaticPhoneSevenNumber, offset Interface:StaticPhoneSevenName clearPhoneNameFields lptr \ offset Interface:StaticPhoneOneName, offset Interface:StaticPhoneTwoName, offset Interface:StaticPhoneThreeName, offset Interface:StaticPhoneFourName, offset Interface:StaticPhoneFiveName, offset Interface:StaticPhoneSixName clearPhoneNameStrings lptr \ offset TextResource:PhoneHomeDisplayString, offset TextResource:PhoneWorkDisplayString, offset TextResource:PhoneCarDisplayString, offset TextResource:PhoneFaxDisplayString, offset TextResource:PhonePagerDisplayString, offset TextResource:PhoneEmailDisplayString .assert (length clearPhoneNameFields) eq (length clearPhoneNameStrings) endif COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ClearTextFields %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Clears all of the text edit fields. CALLED BY: UTILITY PASS: ds - segment addr of core block cx - number of edit fields to clear si - offset into FieldTable (word aligned) RETURN: recStatus set accordingly DESTROYED: ax, bx, cx, dx, si, di PSEUDO CODE/STRATEGY: For each text edit field Display empty text string Clear the dirty bit Set the corresponding flag Advance SI to next text string ptr Next text edit field REVISION HISTORY: Name Date Description ---- ---- ----------- Ted 12/5/89 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ ClearTextFields proc far ifdef GPC tst si jnz leavePhoneNumbers call ClearPhoneNumbers leavePhoneNumbers: endif mainLoop: push cx ; cx - number of text fields to clear mov dx, ds mov bp, offset noText ; dx:bp - points to string to display push si ; save offset to FieldTable clr cx ; string is null terminated ; load BX with the correct resource handle GetResourceHandleNS Interface, bx cmp si, TEFO_NOTE ; is this notes field? jne notNotes ; if not, skip GetResourceHandleNS WindowResource, bx notNotes: mov si, ds:FieldTable[si] ; bx:si - OD of text object mov ax, MSG_VIS_TEXT_REPLACE_ALL_PTR mov di, mask MF_CALL or mask MF_FIXUP_DS call ObjMessage ; display the text string pop si ; restore offset to FieldTable add si, (size nptr) ; update to the next text edit field pop cx ; restore number of fields ; set the RSF_***_EMPTY flag mov ax, 1 shl ax, cl ; ax - mask RSF_***_EMPTY or ds:[recStatus], ax ; set the corresponding flag loop mainLoop ; continue if not done ret ClearTextFields endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ClearTextFieldsSelection %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Clears selection in all text edit fields. CALLED BY: UTILITY PASS: nothing RETURN: nothing DESTROYED: ax, bx, cx, dx PSEUDO CODE/STRATEGY: REVISION HISTORY: Name Date Description ---- ---- ----------- Don 4/20/95 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ ClearTextFieldsSelection proc far uses di, si .enter ; loop through all of the text fields, clearing the selection in each clr si mov cx, NUM_TEXT_EDIT_FIELDS + 1 ; clear selection in a single text object clearLoop: push cx, si GetResourceHandleNS Interface, bx cmp si, 4 ; is this notes field? jne notNotes ; if not, skip GetResourceHandleNS WindowResource, bx notNotes: mov si, ds:FieldTable[si] ; bx:si - OD of text object mov ax, MSG_VIS_TEXT_SELECT_RANGE_SMALL clr cx, dx mov di, mask MF_CALL or mask MF_FIXUP_DS call ObjMessage ; display the text string pop cx, si add si, 2 ; update to the next text edit field loop clearLoop .leave ret ClearTextFieldsSelection endp if PZ_PCGEOS COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ComparePhoneticName %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Compares the sort fields of two records that have same index fields. CALLED BY: BinarySearch PASS: es:si - points to the entry in main table to be compared sortPhoneticBuf - contains sort field of record to compare RETURN: zero flag and carry flag are set to reflect the result of comparison DESTROYED: nothing KNOWN BUGS/SIDE EFFECTS/IDEAS: none. Copied from CompareName() REVISION HISTORY: Name Date Description ---- ---- ----------- owa 9/15/93 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ ComparePhoneticName proc near uses ax, cx, si, di, es, bp .enter mov di, es:[si].TE_item ; di - item number call DBLockNO ; lock this record chunk mov di, es:[di] ; di - offset to record data mov cx, es:[di].DBR_phoneticSize ; cx - size of phonetic add di, es:[di].DBR_toPhonetic; es:di - ptr to index field mov si, offset sortPhoneticBuf; ds:si - ptr to 'sortPhoneticBuf' tst cx ; Is phonetic field in item NULL? jnz doCompare ; if not, do compare clc ; assume ds:si >= es:di cmp {wchar} ds:[si], 0 ; is sortPhoneticBuf null? jmp done ; ok, ZF is set doCompare: clr cx ; strings are null terminated call CompareUsingSortOptionNoCase ; compare two strings done: pushf ; save flags call DBUnlock ; unlock this block popf ; restore flags .leave ret ComparePhoneticName endp endif ifdef GPC EnableRecords proc far uses ax, bx, cx, dx, bp, di, si .enter mov dx, mask VTS_SELECTABLE or mask VTS_EDITABLE ; turn on call ModifyFields .leave ret EnableRecords endp DisableRecords proc far uses ax, bx, cx, dx, bp, di, si .enter ; ; if there is no letter tab selected, don't say "No entries" ; GetResourceHandleNS MyLetters, bx mov si, offset MyLetters mov ax, MSG_LETTERS_GET_LETTER mov di, mask MF_CALL call ObjMessage ; cx = letter cmp cx, -1 je noNoRecord GetResourceHandleNS LastNameField, bx mov si, offset LastNameField mov ax, MSG_VIS_TEXT_REPLACE_ALL_OPTR GetResourceHandleNS NoRecordString, dx mov bp, offset NoRecordString clr cx, di call ObjMessage mov ax, MSG_VIS_TEXT_SET_NOT_USER_MODIFIED clr di call ObjMessage noNoRecord: GetResourceHandleNS AddrField, bx mov si, offset AddrField mov ax, MSG_VIS_TEXT_REPLACE_ALL_OPTR GetResourceHandleNS NoRecordInstruction, dx mov bp, offset NoRecordInstruction clr cx, di call ObjMessage mov ax, MSG_VIS_TEXT_SET_NOT_USER_MODIFIED clr di call ObjMessage mov dx, (mask VTS_SELECTABLE or mask VTS_EDITABLE) shl 8 ; turn off call ModifyFields .leave ret DisableRecords endp ModifyFields proc near mov cx, length disableEntryFields GetResourceHandleNS Interface, bx clr bp fieldsLoop: mov si, cs:disableEntryFields[bp] push cx, dx, bp mov ax, MSG_VIS_TEXT_MODIFY_EDITABLE_SELECTABLE mov cx, dx mov di, mask MF_CALL call ObjMessage pop cx, dx, bp add bp, size lptr loop fieldsLoop ret ModifyFields endp disableEntryFields lptr \ offset Interface:LastNameField, offset Interface:AddrField, offset Interface:StaticPhoneOneNumber, offset Interface:StaticPhoneTwoNumber, offset Interface:StaticPhoneThreeNumber, offset Interface:StaticPhoneFourNumber, offset Interface:StaticPhoneFiveNumber, offset Interface:StaticPhoneSixNumber, offset Interface:StaticPhoneSevenName, offset Interface:StaticPhoneSevenNumber endif CommonCode ends
; A215005: a(n) = a(n-2) + a(n-1) + floor(n/2) + 1 for n > 1 and a(0)=0, a(1)=1. ; 0,1,3,6,12,21,37,62,104,171,281,458,746,1211,1965,3184,5158,8351,13519,21880,35410,57301,92723,150036,242772,392821,635607,1028442,1664064,2692521,4356601,7049138,11405756,18454911,29860685,48315614,78176318,126491951,204668289,331160260,535828570,866988851,1402817443,2269806316,3672623782,5942430121,9615053927,15557484072,25172538024,40730022121,65902560171,106632582318,172535142516,279167724861,451702867405,730870592294,1182573459728,1913444052051,3096017511809,5009461563890,8105479075730,13114940639651,21220419715413,34335360355096,55555780070542,89891140425671,145446920496247,235338060921952,380784981418234,616123042340221,996908023758491,1613031066098748,2609939089857276,4222970155956061,6832909245813375,11055879401769474,17888788647582888,28944668049352401,46833456696935329,75778124746287770,122611581443223140,198389706189510951,321001287632734133,519390993822245126,840392281454979302,1359783275277224471,2200175556732203817,3559958832009428332,5760134388741632194,9320093220751060571,15080227609492692811,24400320830243753428,39480548439736446286,63880869269980199761,103361417709716646095,167242286979696845904,270603704689413492048,437845991669110338001,708449696358523830099,1146295688027634168150 lpb $0 mov $2,$0 seq $2,1595 ; a(n) = a(n-1) + a(n-2) + 1, with a(0) = a(1) = 1. add $1,$2 mov $3,$2 min $3,1 add $0,$3 trn $0,3 lpe mov $0,$1
.global s_prepare_buffers s_prepare_buffers: push %r15 push %r8 push %rax push %rbp push %rcx push %rdi push %rdx push %rsi lea addresses_normal_ht+0x13eef, %rsi lea addresses_WT_ht+0xd9df, %rdi nop nop nop nop nop cmp %rdx, %rdx mov $9, %rcx rep movsl nop and %r8, %r8 lea addresses_normal_ht+0x10e6f, %rax xor $61451, %rbp movw $0x6162, (%rax) nop nop nop nop nop xor %rcx, %rcx lea addresses_A_ht+0xa62f, %rsi lea addresses_normal_ht+0xe5ef, %rdi nop sub %r8, %r8 mov $73, %rcx rep movsb nop nop nop nop xor $33871, %rcx lea addresses_UC_ht+0xbfef, %rsi lea addresses_D_ht+0x606f, %rdi clflush (%rdi) nop nop nop nop nop dec %r15 mov $43, %rcx rep movsl nop nop nop sub $40663, %rsi lea addresses_UC_ht+0xb0ef, %rcx clflush (%rcx) nop nop nop dec %rbp movups (%rcx), %xmm3 vpextrq $1, %xmm3, %rax xor $61346, %rcx lea addresses_D_ht+0x14faf, %r15 nop nop nop nop nop cmp $31151, %rbp movups (%r15), %xmm5 vpextrq $1, %xmm5, %rsi nop nop nop nop xor %rdi, %rdi lea addresses_UC_ht+0xa18f, %rcx nop nop and $62871, %r8 movb (%rcx), %r15b nop nop nop and %rdi, %rdi lea addresses_WT_ht+0x3eaf, %rsi lea addresses_WC_ht+0x66ef, %rdi sub $49676, %rbp mov $18, %rcx rep movsq nop nop nop nop nop cmp %r8, %r8 lea addresses_normal_ht+0x150ef, %rsi nop nop nop nop sub $32395, %rdi movw $0x6162, (%rsi) nop nop cmp $30894, %rcx lea addresses_WT_ht+0x122e8, %rsi nop nop nop nop nop xor %rbp, %rbp and $0xffffffffffffffc0, %rsi vmovaps (%rsi), %ymm1 vextracti128 $0, %ymm1, %xmm1 vpextrq $1, %xmm1, %r15 nop nop nop nop cmp %rdx, %rdx lea addresses_WT_ht+0x13aef, %rsi clflush (%rsi) nop nop nop nop inc %r8 mov (%rsi), %rdx nop nop nop nop nop add $51262, %rdx lea addresses_A_ht+0x11e0f, %rdx clflush (%rdx) xor %rdi, %rdi movups (%rdx), %xmm1 vpextrq $1, %xmm1, %r8 nop nop nop nop add %rdx, %rdx lea addresses_WC_ht+0x12a8b, %rcx cmp $5987, %r8 movw $0x6162, (%rcx) nop add $44748, %rdi lea addresses_WC_ht+0x1a8ef, %rsi nop nop add $5930, %r15 mov (%rsi), %ebp nop nop nop nop nop dec %rdi pop %rsi pop %rdx pop %rdi pop %rcx pop %rbp pop %rax pop %r8 pop %r15 ret .global s_faulty_load s_faulty_load: push %r10 push %r12 push %r15 push %rbp push %rsi // Faulty Load lea addresses_PSE+0x178ef, %rbp nop nop nop xor %r15, %r15 mov (%rbp), %r10d lea oracles, %r12 and $0xff, %r10 shlq $12, %r10 mov (%r12,%r10,1), %r10 pop %rsi pop %rbp pop %r15 pop %r12 pop %r10 ret /* <gen_faulty_load> [REF] {'src': {'NT': False, 'same': True, 'congruent': 0, 'type': 'addresses_PSE', 'AVXalign': False, 'size': 2}, 'OP': 'LOAD'} [Faulty Load] {'src': {'NT': False, 'same': True, 'congruent': 0, 'type': 'addresses_PSE', 'AVXalign': False, 'size': 4}, 'OP': 'LOAD'} <gen_prepare_buffer> {'src': {'same': False, 'congruent': 8, 'type': 'addresses_normal_ht'}, 'OP': 'REPM', 'dst': {'same': False, 'congruent': 4, 'type': 'addresses_WT_ht'}} {'OP': 'STOR', 'dst': {'NT': False, 'same': False, 'congruent': 6, 'type': 'addresses_normal_ht', 'AVXalign': False, 'size': 2}} {'src': {'same': False, 'congruent': 5, 'type': 'addresses_A_ht'}, 'OP': 'REPM', 'dst': {'same': False, 'congruent': 6, 'type': 'addresses_normal_ht'}} {'src': {'same': False, 'congruent': 8, 'type': 'addresses_UC_ht'}, 'OP': 'REPM', 'dst': {'same': False, 'congruent': 7, 'type': 'addresses_D_ht'}} {'src': {'NT': False, 'same': False, 'congruent': 10, 'type': 'addresses_UC_ht', 'AVXalign': False, 'size': 16}, 'OP': 'LOAD'} {'src': {'NT': False, 'same': False, 'congruent': 6, 'type': 'addresses_D_ht', 'AVXalign': False, 'size': 16}, 'OP': 'LOAD'} {'src': {'NT': False, 'same': False, 'congruent': 5, 'type': 'addresses_UC_ht', 'AVXalign': False, 'size': 1}, 'OP': 'LOAD'} {'src': {'same': False, 'congruent': 6, 'type': 'addresses_WT_ht'}, 'OP': 'REPM', 'dst': {'same': False, 'congruent': 6, 'type': 'addresses_WC_ht'}} {'OP': 'STOR', 'dst': {'NT': False, 'same': False, 'congruent': 10, 'type': 'addresses_normal_ht', 'AVXalign': False, 'size': 2}} {'src': {'NT': False, 'same': False, 'congruent': 0, 'type': 'addresses_WT_ht', 'AVXalign': True, 'size': 32}, 'OP': 'LOAD'} {'src': {'NT': False, 'same': False, 'congruent': 8, 'type': 'addresses_WT_ht', 'AVXalign': False, 'size': 8}, 'OP': 'LOAD'} {'src': {'NT': False, 'same': False, 'congruent': 1, 'type': 'addresses_A_ht', 'AVXalign': False, 'size': 16}, 'OP': 'LOAD'} {'OP': 'STOR', 'dst': {'NT': False, 'same': False, 'congruent': 2, 'type': 'addresses_WC_ht', 'AVXalign': False, 'size': 2}} {'src': {'NT': False, 'same': False, 'congruent': 11, 'type': 'addresses_WC_ht', 'AVXalign': False, 'size': 4}, 'OP': 'LOAD'} {'33': 21829} 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 */
; A320565: a(n) = ((1 + sqrt(4*n^2 + 1))^n - (1 - sqrt(4*n^2 + 1))^n)/(2^n * sqrt(4*n^2 + 1)). ; Submitted by Jon Maiga ; 0,1,1,10,33,701,4033,132301,1089921,48460114,520210801,29215223489,386721507745,26250621340841,413242502386337,32899021525375426,600383148312628737,54846079150716441949,1138470675779123657425,117372939125452004885621 mov $4,1 mov $5,$0 pow $5,2 lpb $0 sub $0,1 mov $3,$2 mov $2,$4 mul $3,$5 add $4,$3 lpe mov $0,$2
;-------------------------------------------------------- ; File Created by SDCC : free open source ANSI-C Compiler ; Version 4.0.3 #11868 (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 __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 _am9511_round ;-------------------------------------------------------- ; Externals used ;-------------------------------------------------------- GLOBAL _hypot_callee GLOBAL _ldexp_callee GLOBAL _frexp_callee GLOBAL _sqrt_fastcall GLOBAL _sqr_fastcall GLOBAL _div2_fastcall GLOBAL _mul2_fastcall GLOBAL _am9511_modf GLOBAL _am9511_fmod GLOBAL _floor_fastcall GLOBAL _fabs_fastcall GLOBAL _ceil_fastcall GLOBAL _am9511_exp10 GLOBAL _am9511_exp2 GLOBAL _am9511_log2 GLOBAL _pow_callee GLOBAL _exp_fastcall GLOBAL _log10_fastcall GLOBAL _log_fastcall GLOBAL _am9511_atanh GLOBAL _am9511_acosh GLOBAL _am9511_asinh GLOBAL _am9511_tanh GLOBAL _am9511_cosh GLOBAL _am9511_sinh GLOBAL _am9511_atan2 GLOBAL _atan_fastcall GLOBAL _acos_fastcall GLOBAL _asin_fastcall GLOBAL _tan_fastcall GLOBAL _cos_fastcall GLOBAL _sin_fastcall GLOBAL _exp10_fastcall GLOBAL _exp10 GLOBAL _mul10u_fastcall GLOBAL _mul10u GLOBAL _mul2 GLOBAL _div2 GLOBAL _sqr GLOBAL _fam9511_f32_fastcall GLOBAL _fam9511_f32 GLOBAL _f32_fam9511_fastcall GLOBAL _f32_fam9511 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 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 GLOBAL _pow GLOBAL _hypot GLOBAL _fabs GLOBAL _logb_fastcall GLOBAL _logb GLOBAL _log2_fastcall GLOBAL _log2 GLOBAL _log1p_fastcall GLOBAL _log1p GLOBAL _log10 GLOBAL _log GLOBAL _scalbln_callee GLOBAL _scalbln GLOBAL _scalbn_callee GLOBAL _scalbn GLOBAL _ldexp GLOBAL _ilogb_fastcall GLOBAL _ilogb GLOBAL _frexp GLOBAL _expm1_fastcall GLOBAL _expm1 GLOBAL _exp2_fastcall GLOBAL _exp2 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 GLOBAL _sin GLOBAL _cos GLOBAL _atan2_callee GLOBAL _atan2 GLOBAL _atan GLOBAL _asin 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 am9511_round ; --------------------------------- _am9511_round: push ix ld ix,0 add ix,sp ld c, l ld b, h ld hl, -20 add hl, sp ld sp, hl ld hl,0 add hl, sp ld (ix-2),l ld (ix-1),h ld (hl), c inc hl ld (hl), b inc hl ld (hl), e inc hl ld (hl), d ld hl,0 add hl, sp ld (ix-16),l ld (ix-15),h push de push bc ld e,(ix-16) ld d,(ix-15) ld hl,0x0014 add hl, sp ex de, hl ld bc,0x0004 ldir pop bc pop de ld a,(ix-4) ld (ix-14),a ld a,(ix-3) ld (ix-13),a ld a,(ix-2) ld (ix-12),a ld a,(ix-1) ld (ix-11),a ld (ix-4),0x00 ld (ix-3),0x00 ld a,(ix-12) and a,0x80 ld (ix-2),a ld a,(ix-11) and a,0x7f ld (ix-1),a ld a,0x17 l_am9511_round_00141: srl (ix-1) rr (ix-2) rr (ix-3) rr (ix-4) dec a jr NZ, l_am9511_round_00141 ld h,(ix-3) ld a,(ix-4) add a,0x81 ld (ix-10),a ld a, h adc a,0xff ld (ix-9),a ld a,(ix-10) sub a,0x17 ld a,(ix-9) rla ccf rra sbc a,0x80 jp NC, l_am9511_round_00112 bit 7,(ix-9) jr Z,l_am9511_round_00106 ld bc,0x0000 ld e,0x00 ld a,(ix-11) and a,0x80 ld d, a ld a,(ix-10) and a,(ix-9) inc a jp NZ,l_am9511_round_00113 set 7, e ld a, d or a,0x3f ld d, a jp l_am9511_round_00113 l_am9511_round_00106: ld (ix-4),0xff ld (ix-3),0xff ld (ix-2),0x7f xor a, a ld (ix-1),a inc a jr l_am9511_round_00146 l_am9511_round_00145: sra (ix-1) rr (ix-2) rr (ix-3) rr (ix-4) l_am9511_round_00146: dec a jr NZ, l_am9511_round_00145 ld l,(ix-4) ld h,(ix-3) ld (ix-8),l ld (ix-7),h xor a, a ld (ix-6),a ld (ix-5),a ld a,(ix-14) and a,(ix-8) ld (ix-4),a ld a,(ix-13) and a,(ix-7) ld (ix-3),a ld a,(ix-12) and a,(ix-6) ld (ix-2),a ld a,(ix-11) and a,(ix-5) ld (ix-1),a or a,(ix-2) or a,(ix-3) or a,(ix-4) jr NZ,l_am9511_round_00104 ld l, c ld h, b jp l_am9511_round_00114 l_am9511_round_00104: ld a,(ix-10) inc a ld bc,0x0000 ld de,0x0040 jr l_am9511_round_00148 l_am9511_round_00147: sra d rr e rr b rr c l_am9511_round_00148: dec a jr NZ, l_am9511_round_00147 ld a,(ix-14) add a, c ld c, a ld a,(ix-13) adc a, b ld b, a ld a,(ix-12) adc a, e ld e, a ld a,(ix-11) adc a, d ld d, a ld a, l cpl ld l, a ld a, h cpl ld (ix-4),l ld (ix-3),a xor a, a ld (ix-2),a ld (ix-1),a ld a, c and a,(ix-4) ld c, a ld a, b and a,(ix-3) ld b, a ld a, e and a,(ix-2) ld e, a ld a, d and a,(ix-1) ld d, a jr l_am9511_round_00113 l_am9511_round_00112: ld a,(ix-10) sub a,0x80 or a,(ix-9) jr NZ,l_am9511_round_00109 push de push bc push de push bc call ___fsadd_callee jr l_am9511_round_00114 l_am9511_round_00109: ld l, c ld h, b jr l_am9511_round_00114 l_am9511_round_00113: ld l,(ix-16) ld h,(ix-15) ld (hl), c inc hl ld (hl), b inc hl ld (hl), e inc hl ld (hl), d ld hl,0 add hl, sp ld e, (hl) inc hl ld d, (hl) inc hl ld a,(hl) inc hl ld h,(hl) ld l,a ex de, hl l_am9511_round_00114: ld sp, ix pop ix ret SECTION IGNORE
///FunctionCalls\SimpleFunction\SimpleFunction.asm /// (SimpleFunction.test) @0 D=A @SP A=M M=D @SP M=M+1 @0 D=A @SP A=M M=D @SP M=M+1 @0 D=A @LCL A=M+D D=M @SP A=M M=D @SP M=M+1 @1 D=A @LCL A=M+D D=M @SP A=M M=D @SP M=M+1 @SP AM=M-1 D=M @SP A=M-1 M=M+D @SP A=M-1 M=!M @0 D=A @ARG A=M+D D=M @SP A=M M=D @SP M=M+1 @SP AM=M-1 D=M @SP A=M-1 M=M+D @1 D=A @ARG A=M+D D=M @SP A=M M=D @SP M=M+1 @SP AM=M-1 D=M @SP A=M-1 M=M-D @LCL D=M @R15 M=D @5 A=D-A D=M @R14 M=D @SP AM=M-1 D=M @ARG A=M M=D @ARG D=M+1 @SP M=D @R15 D=M-1 AM=D D=M @THAT M=D @R15 D=M-1 AM=D D=M @THIS M=D @R15 D=M-1 AM=D D=M @ARG M=D @R15 D=M-1 AM=D D=M @LCL M=D @R14 A=M 0;JMP
; ensures we jump into kmain [bits 32] ; this code runs in PM [extern kmain] ; reference for the linker (main is defined elsewhere) call kmain jmp $ ; this should not run. Just in case, hang.
SET A, 0 SET [xmax], [xsize] SUB [xmax], 2 SET [ymax], [ysize] SUB [ymax], 2 JSR clearScreen :main IFE A, 0x0300 JSR update ADD A, 1 SET PC, main :update SET B, ballData SET C, 0 :ballLoop JSR moveBall ADD B, [ballSize] ADD C, 1 IFG [numBalls], C SET PC, ballLoop SET PC, POP :moveBall SET [ballx], [B] SET [bally], [1+B] SET [ballvx], [2+B] SET [ballvy], [3+B] SET Z, 0x0000 JSR drawBall IFE [ballvx], 1 ADD [ballx], 1 IFE [ballvx], 0 SUB [ballx], 1 IFE [ballvy], 1 ADD [bally], 1 IFE [ballvy], 0 SUB [bally], 1 IFE [ballx], [xmax] XOR [ballvx], 1 IFE [ballx], 0 XOR [ballvx], 1 IFE [bally], [ymax] XOR [ballvy], 1 IFE [bally], 0 XOR [ballvy], 1 SET [B], [ballx] SET [1+B], [bally] SET [2+B], [ballvx] SET [3+B], [ballvy] SET Z, [4+B] JSR drawBall SET A, 0 SET PC, POP :drawBall SET X, [ballx] SET Y, [bally] JSR writeChar ADD X, 1 JSR writeChar ADD Y, 1 JSR writeChar SUB X, 1 JSR writeChar SET PC, POP :writeChar SET J, Y MUL J, 32 ADD J, X ADD J, 0x8000 SET [J], Z SET PC, POP :clearScreen SET Z, 0x0000 SET X, 0 :loopx SET Y, 0 :loopy JSR writeChar ADD Y, 1 IFG [ysize], y SET PC, loopy ADD X, 1 IFG [xsize], x SET PC, loopx SET PC, POP :end SUB PC, 1 :ballData ; X Y vX vY color DAT 3, 4, 1, 1, 0x0900 DAT 7, 6, 1, 0, 0x0A00 DAT 19, 3, 0, 0, 0x0E00 DAT 27, 8, 0, 1, 0x0C00 :numBalls DAT 4 :ballSize DAT 5 :ballx DAT 0 :bally DAT 0 :ballvx DAT 0 :ballvy DAT 0 :xmax DAT 0 :ymax DAT 0 :xsize DAT 32 :ysize DAT 16
_cat: file format elf32-i386 Disassembly of section .text: 00000000 <cat>: char buf[512]; void cat(int fd) { 0: 55 push %ebp 1: 89 e5 mov %esp,%ebp 3: 83 ec 28 sub $0x28,%esp int n; while((n = read(fd, buf, sizeof(buf))) > 0) 6: eb 1b jmp 23 <cat+0x23> write(1, buf, n); 8: 8b 45 f4 mov -0xc(%ebp),%eax b: 89 44 24 08 mov %eax,0x8(%esp) f: c7 44 24 04 a0 0b 00 movl $0xba0,0x4(%esp) 16: 00 17: c7 04 24 01 00 00 00 movl $0x1,(%esp) 1e: e8 82 03 00 00 call 3a5 <write> void cat(int fd) { int n; while((n = read(fd, buf, sizeof(buf))) > 0) 23: c7 44 24 08 00 02 00 movl $0x200,0x8(%esp) 2a: 00 2b: c7 44 24 04 a0 0b 00 movl $0xba0,0x4(%esp) 32: 00 33: 8b 45 08 mov 0x8(%ebp),%eax 36: 89 04 24 mov %eax,(%esp) 39: e8 5f 03 00 00 call 39d <read> 3e: 89 45 f4 mov %eax,-0xc(%ebp) 41: 83 7d f4 00 cmpl $0x0,-0xc(%ebp) 45: 7f c1 jg 8 <cat+0x8> write(1, buf, n); if(n < 0){ 47: 83 7d f4 00 cmpl $0x0,-0xc(%ebp) 4b: 79 19 jns 66 <cat+0x66> printf(1, "cat: read error\n"); 4d: c7 44 24 04 d1 08 00 movl $0x8d1,0x4(%esp) 54: 00 55: c7 04 24 01 00 00 00 movl $0x1,(%esp) 5c: e8 a4 04 00 00 call 505 <printf> exit(); 61: e8 1f 03 00 00 call 385 <exit> } } 66: c9 leave 67: c3 ret 00000068 <main>: int main(int argc, char *argv[]) { 68: 55 push %ebp 69: 89 e5 mov %esp,%ebp 6b: 83 e4 f0 and $0xfffffff0,%esp 6e: 83 ec 20 sub $0x20,%esp int fd, i; if(argc <= 1){ 71: 83 7d 08 01 cmpl $0x1,0x8(%ebp) 75: 7f 11 jg 88 <main+0x20> cat(0); 77: c7 04 24 00 00 00 00 movl $0x0,(%esp) 7e: e8 7d ff ff ff call 0 <cat> exit(); 83: e8 fd 02 00 00 call 385 <exit> } for(i = 1; i < argc; i++){ 88: c7 44 24 1c 01 00 00 movl $0x1,0x1c(%esp) 8f: 00 90: eb 79 jmp 10b <main+0xa3> if((fd = open(argv[i], 0)) < 0){ 92: 8b 44 24 1c mov 0x1c(%esp),%eax 96: 8d 14 85 00 00 00 00 lea 0x0(,%eax,4),%edx 9d: 8b 45 0c mov 0xc(%ebp),%eax a0: 01 d0 add %edx,%eax a2: 8b 00 mov (%eax),%eax a4: c7 44 24 04 00 00 00 movl $0x0,0x4(%esp) ab: 00 ac: 89 04 24 mov %eax,(%esp) af: e8 11 03 00 00 call 3c5 <open> b4: 89 44 24 18 mov %eax,0x18(%esp) b8: 83 7c 24 18 00 cmpl $0x0,0x18(%esp) bd: 79 2f jns ee <main+0x86> printf(1, "cat: cannot open %s\n", argv[i]); bf: 8b 44 24 1c mov 0x1c(%esp),%eax c3: 8d 14 85 00 00 00 00 lea 0x0(,%eax,4),%edx ca: 8b 45 0c mov 0xc(%ebp),%eax cd: 01 d0 add %edx,%eax cf: 8b 00 mov (%eax),%eax d1: 89 44 24 08 mov %eax,0x8(%esp) d5: c7 44 24 04 e2 08 00 movl $0x8e2,0x4(%esp) dc: 00 dd: c7 04 24 01 00 00 00 movl $0x1,(%esp) e4: e8 1c 04 00 00 call 505 <printf> exit(); e9: e8 97 02 00 00 call 385 <exit> } cat(fd); ee: 8b 44 24 18 mov 0x18(%esp),%eax f2: 89 04 24 mov %eax,(%esp) f5: e8 06 ff ff ff call 0 <cat> close(fd); fa: 8b 44 24 18 mov 0x18(%esp),%eax fe: 89 04 24 mov %eax,(%esp) 101: e8 a7 02 00 00 call 3ad <close> if(argc <= 1){ cat(0); exit(); } for(i = 1; i < argc; i++){ 106: 83 44 24 1c 01 addl $0x1,0x1c(%esp) 10b: 8b 44 24 1c mov 0x1c(%esp),%eax 10f: 3b 45 08 cmp 0x8(%ebp),%eax 112: 0f 8c 7a ff ff ff jl 92 <main+0x2a> exit(); } cat(fd); close(fd); } exit(); 118: e8 68 02 00 00 call 385 <exit> 0000011d <stosb>: "cc"); } static inline void stosb(void *addr, int data, int cnt) { 11d: 55 push %ebp 11e: 89 e5 mov %esp,%ebp 120: 57 push %edi 121: 53 push %ebx asm volatile("cld; rep stosb" : 122: 8b 4d 08 mov 0x8(%ebp),%ecx 125: 8b 55 10 mov 0x10(%ebp),%edx 128: 8b 45 0c mov 0xc(%ebp),%eax 12b: 89 cb mov %ecx,%ebx 12d: 89 df mov %ebx,%edi 12f: 89 d1 mov %edx,%ecx 131: fc cld 132: f3 aa rep stos %al,%es:(%edi) 134: 89 ca mov %ecx,%edx 136: 89 fb mov %edi,%ebx 138: 89 5d 08 mov %ebx,0x8(%ebp) 13b: 89 55 10 mov %edx,0x10(%ebp) "=D" (addr), "=c" (cnt) : "0" (addr), "1" (cnt), "a" (data) : "memory", "cc"); } 13e: 5b pop %ebx 13f: 5f pop %edi 140: 5d pop %ebp 141: c3 ret 00000142 <strcpy>: #include "user.h" #include "x86.h" char* strcpy(char *s, char *t) { 142: 55 push %ebp 143: 89 e5 mov %esp,%ebp 145: 83 ec 10 sub $0x10,%esp char *os; os = s; 148: 8b 45 08 mov 0x8(%ebp),%eax 14b: 89 45 fc mov %eax,-0x4(%ebp) while((*s++ = *t++) != 0) 14e: 90 nop 14f: 8b 45 08 mov 0x8(%ebp),%eax 152: 8d 50 01 lea 0x1(%eax),%edx 155: 89 55 08 mov %edx,0x8(%ebp) 158: 8b 55 0c mov 0xc(%ebp),%edx 15b: 8d 4a 01 lea 0x1(%edx),%ecx 15e: 89 4d 0c mov %ecx,0xc(%ebp) 161: 0f b6 12 movzbl (%edx),%edx 164: 88 10 mov %dl,(%eax) 166: 0f b6 00 movzbl (%eax),%eax 169: 84 c0 test %al,%al 16b: 75 e2 jne 14f <strcpy+0xd> ; return os; 16d: 8b 45 fc mov -0x4(%ebp),%eax } 170: c9 leave 171: c3 ret 00000172 <strcmp>: int strcmp(const char *p, const char *q) { 172: 55 push %ebp 173: 89 e5 mov %esp,%ebp while(*p && *p == *q) 175: eb 08 jmp 17f <strcmp+0xd> p++, q++; 177: 83 45 08 01 addl $0x1,0x8(%ebp) 17b: 83 45 0c 01 addl $0x1,0xc(%ebp) } int strcmp(const char *p, const char *q) { while(*p && *p == *q) 17f: 8b 45 08 mov 0x8(%ebp),%eax 182: 0f b6 00 movzbl (%eax),%eax 185: 84 c0 test %al,%al 187: 74 10 je 199 <strcmp+0x27> 189: 8b 45 08 mov 0x8(%ebp),%eax 18c: 0f b6 10 movzbl (%eax),%edx 18f: 8b 45 0c mov 0xc(%ebp),%eax 192: 0f b6 00 movzbl (%eax),%eax 195: 38 c2 cmp %al,%dl 197: 74 de je 177 <strcmp+0x5> p++, q++; return (uchar)*p - (uchar)*q; 199: 8b 45 08 mov 0x8(%ebp),%eax 19c: 0f b6 00 movzbl (%eax),%eax 19f: 0f b6 d0 movzbl %al,%edx 1a2: 8b 45 0c mov 0xc(%ebp),%eax 1a5: 0f b6 00 movzbl (%eax),%eax 1a8: 0f b6 c0 movzbl %al,%eax 1ab: 29 c2 sub %eax,%edx 1ad: 89 d0 mov %edx,%eax } 1af: 5d pop %ebp 1b0: c3 ret 000001b1 <strlen>: uint strlen(char *s) { 1b1: 55 push %ebp 1b2: 89 e5 mov %esp,%ebp 1b4: 83 ec 10 sub $0x10,%esp int n; for(n = 0; s[n]; n++) 1b7: c7 45 fc 00 00 00 00 movl $0x0,-0x4(%ebp) 1be: eb 04 jmp 1c4 <strlen+0x13> 1c0: 83 45 fc 01 addl $0x1,-0x4(%ebp) 1c4: 8b 55 fc mov -0x4(%ebp),%edx 1c7: 8b 45 08 mov 0x8(%ebp),%eax 1ca: 01 d0 add %edx,%eax 1cc: 0f b6 00 movzbl (%eax),%eax 1cf: 84 c0 test %al,%al 1d1: 75 ed jne 1c0 <strlen+0xf> ; return n; 1d3: 8b 45 fc mov -0x4(%ebp),%eax } 1d6: c9 leave 1d7: c3 ret 000001d8 <memset>: void* memset(void *dst, int c, uint n) { 1d8: 55 push %ebp 1d9: 89 e5 mov %esp,%ebp 1db: 83 ec 0c sub $0xc,%esp stosb(dst, c, n); 1de: 8b 45 10 mov 0x10(%ebp),%eax 1e1: 89 44 24 08 mov %eax,0x8(%esp) 1e5: 8b 45 0c mov 0xc(%ebp),%eax 1e8: 89 44 24 04 mov %eax,0x4(%esp) 1ec: 8b 45 08 mov 0x8(%ebp),%eax 1ef: 89 04 24 mov %eax,(%esp) 1f2: e8 26 ff ff ff call 11d <stosb> return dst; 1f7: 8b 45 08 mov 0x8(%ebp),%eax } 1fa: c9 leave 1fb: c3 ret 000001fc <strchr>: char* strchr(const char *s, char c) { 1fc: 55 push %ebp 1fd: 89 e5 mov %esp,%ebp 1ff: 83 ec 04 sub $0x4,%esp 202: 8b 45 0c mov 0xc(%ebp),%eax 205: 88 45 fc mov %al,-0x4(%ebp) for(; *s; s++) 208: eb 14 jmp 21e <strchr+0x22> if(*s == c) 20a: 8b 45 08 mov 0x8(%ebp),%eax 20d: 0f b6 00 movzbl (%eax),%eax 210: 3a 45 fc cmp -0x4(%ebp),%al 213: 75 05 jne 21a <strchr+0x1e> return (char*)s; 215: 8b 45 08 mov 0x8(%ebp),%eax 218: eb 13 jmp 22d <strchr+0x31> } char* strchr(const char *s, char c) { for(; *s; s++) 21a: 83 45 08 01 addl $0x1,0x8(%ebp) 21e: 8b 45 08 mov 0x8(%ebp),%eax 221: 0f b6 00 movzbl (%eax),%eax 224: 84 c0 test %al,%al 226: 75 e2 jne 20a <strchr+0xe> if(*s == c) return (char*)s; return 0; 228: b8 00 00 00 00 mov $0x0,%eax } 22d: c9 leave 22e: c3 ret 0000022f <gets>: char* gets(char *buf, int max) { 22f: 55 push %ebp 230: 89 e5 mov %esp,%ebp 232: 83 ec 28 sub $0x28,%esp int i, cc; char c; for(i=0; i+1 < max; ){ 235: c7 45 f4 00 00 00 00 movl $0x0,-0xc(%ebp) 23c: eb 4c jmp 28a <gets+0x5b> cc = read(0, &c, 1); 23e: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp) 245: 00 246: 8d 45 ef lea -0x11(%ebp),%eax 249: 89 44 24 04 mov %eax,0x4(%esp) 24d: c7 04 24 00 00 00 00 movl $0x0,(%esp) 254: e8 44 01 00 00 call 39d <read> 259: 89 45 f0 mov %eax,-0x10(%ebp) if(cc < 1) 25c: 83 7d f0 00 cmpl $0x0,-0x10(%ebp) 260: 7f 02 jg 264 <gets+0x35> break; 262: eb 31 jmp 295 <gets+0x66> buf[i++] = c; 264: 8b 45 f4 mov -0xc(%ebp),%eax 267: 8d 50 01 lea 0x1(%eax),%edx 26a: 89 55 f4 mov %edx,-0xc(%ebp) 26d: 89 c2 mov %eax,%edx 26f: 8b 45 08 mov 0x8(%ebp),%eax 272: 01 c2 add %eax,%edx 274: 0f b6 45 ef movzbl -0x11(%ebp),%eax 278: 88 02 mov %al,(%edx) if(c == '\n' || c == '\r') 27a: 0f b6 45 ef movzbl -0x11(%ebp),%eax 27e: 3c 0a cmp $0xa,%al 280: 74 13 je 295 <gets+0x66> 282: 0f b6 45 ef movzbl -0x11(%ebp),%eax 286: 3c 0d cmp $0xd,%al 288: 74 0b je 295 <gets+0x66> gets(char *buf, int max) { int i, cc; char c; for(i=0; i+1 < max; ){ 28a: 8b 45 f4 mov -0xc(%ebp),%eax 28d: 83 c0 01 add $0x1,%eax 290: 3b 45 0c cmp 0xc(%ebp),%eax 293: 7c a9 jl 23e <gets+0xf> break; buf[i++] = c; if(c == '\n' || c == '\r') break; } buf[i] = '\0'; 295: 8b 55 f4 mov -0xc(%ebp),%edx 298: 8b 45 08 mov 0x8(%ebp),%eax 29b: 01 d0 add %edx,%eax 29d: c6 00 00 movb $0x0,(%eax) return buf; 2a0: 8b 45 08 mov 0x8(%ebp),%eax } 2a3: c9 leave 2a4: c3 ret 000002a5 <stat>: int stat(char *n, struct stat *st) { 2a5: 55 push %ebp 2a6: 89 e5 mov %esp,%ebp 2a8: 83 ec 28 sub $0x28,%esp int fd; int r; fd = open(n, O_RDONLY); 2ab: c7 44 24 04 00 00 00 movl $0x0,0x4(%esp) 2b2: 00 2b3: 8b 45 08 mov 0x8(%ebp),%eax 2b6: 89 04 24 mov %eax,(%esp) 2b9: e8 07 01 00 00 call 3c5 <open> 2be: 89 45 f4 mov %eax,-0xc(%ebp) if(fd < 0) 2c1: 83 7d f4 00 cmpl $0x0,-0xc(%ebp) 2c5: 79 07 jns 2ce <stat+0x29> return -1; 2c7: b8 ff ff ff ff mov $0xffffffff,%eax 2cc: eb 23 jmp 2f1 <stat+0x4c> r = fstat(fd, st); 2ce: 8b 45 0c mov 0xc(%ebp),%eax 2d1: 89 44 24 04 mov %eax,0x4(%esp) 2d5: 8b 45 f4 mov -0xc(%ebp),%eax 2d8: 89 04 24 mov %eax,(%esp) 2db: e8 fd 00 00 00 call 3dd <fstat> 2e0: 89 45 f0 mov %eax,-0x10(%ebp) close(fd); 2e3: 8b 45 f4 mov -0xc(%ebp),%eax 2e6: 89 04 24 mov %eax,(%esp) 2e9: e8 bf 00 00 00 call 3ad <close> return r; 2ee: 8b 45 f0 mov -0x10(%ebp),%eax } 2f1: c9 leave 2f2: c3 ret 000002f3 <atoi>: int atoi(const char *s) { 2f3: 55 push %ebp 2f4: 89 e5 mov %esp,%ebp 2f6: 83 ec 10 sub $0x10,%esp int n; n = 0; 2f9: c7 45 fc 00 00 00 00 movl $0x0,-0x4(%ebp) while('0' <= *s && *s <= '9') 300: eb 25 jmp 327 <atoi+0x34> n = n*10 + *s++ - '0'; 302: 8b 55 fc mov -0x4(%ebp),%edx 305: 89 d0 mov %edx,%eax 307: c1 e0 02 shl $0x2,%eax 30a: 01 d0 add %edx,%eax 30c: 01 c0 add %eax,%eax 30e: 89 c1 mov %eax,%ecx 310: 8b 45 08 mov 0x8(%ebp),%eax 313: 8d 50 01 lea 0x1(%eax),%edx 316: 89 55 08 mov %edx,0x8(%ebp) 319: 0f b6 00 movzbl (%eax),%eax 31c: 0f be c0 movsbl %al,%eax 31f: 01 c8 add %ecx,%eax 321: 83 e8 30 sub $0x30,%eax 324: 89 45 fc mov %eax,-0x4(%ebp) atoi(const char *s) { int n; n = 0; while('0' <= *s && *s <= '9') 327: 8b 45 08 mov 0x8(%ebp),%eax 32a: 0f b6 00 movzbl (%eax),%eax 32d: 3c 2f cmp $0x2f,%al 32f: 7e 0a jle 33b <atoi+0x48> 331: 8b 45 08 mov 0x8(%ebp),%eax 334: 0f b6 00 movzbl (%eax),%eax 337: 3c 39 cmp $0x39,%al 339: 7e c7 jle 302 <atoi+0xf> n = n*10 + *s++ - '0'; return n; 33b: 8b 45 fc mov -0x4(%ebp),%eax } 33e: c9 leave 33f: c3 ret 00000340 <memmove>: void* memmove(void *vdst, void *vsrc, int n) { 340: 55 push %ebp 341: 89 e5 mov %esp,%ebp 343: 83 ec 10 sub $0x10,%esp char *dst, *src; dst = vdst; 346: 8b 45 08 mov 0x8(%ebp),%eax 349: 89 45 fc mov %eax,-0x4(%ebp) src = vsrc; 34c: 8b 45 0c mov 0xc(%ebp),%eax 34f: 89 45 f8 mov %eax,-0x8(%ebp) while(n-- > 0) 352: eb 17 jmp 36b <memmove+0x2b> *dst++ = *src++; 354: 8b 45 fc mov -0x4(%ebp),%eax 357: 8d 50 01 lea 0x1(%eax),%edx 35a: 89 55 fc mov %edx,-0x4(%ebp) 35d: 8b 55 f8 mov -0x8(%ebp),%edx 360: 8d 4a 01 lea 0x1(%edx),%ecx 363: 89 4d f8 mov %ecx,-0x8(%ebp) 366: 0f b6 12 movzbl (%edx),%edx 369: 88 10 mov %dl,(%eax) { char *dst, *src; dst = vdst; src = vsrc; while(n-- > 0) 36b: 8b 45 10 mov 0x10(%ebp),%eax 36e: 8d 50 ff lea -0x1(%eax),%edx 371: 89 55 10 mov %edx,0x10(%ebp) 374: 85 c0 test %eax,%eax 376: 7f dc jg 354 <memmove+0x14> *dst++ = *src++; return vdst; 378: 8b 45 08 mov 0x8(%ebp),%eax } 37b: c9 leave 37c: c3 ret 0000037d <fork>: name: \ movl $SYS_ ## name, %eax; \ int $T_SYSCALL; \ ret SYSCALL(fork) 37d: b8 01 00 00 00 mov $0x1,%eax 382: cd 40 int $0x40 384: c3 ret 00000385 <exit>: SYSCALL(exit) 385: b8 02 00 00 00 mov $0x2,%eax 38a: cd 40 int $0x40 38c: c3 ret 0000038d <wait>: SYSCALL(wait) 38d: b8 03 00 00 00 mov $0x3,%eax 392: cd 40 int $0x40 394: c3 ret 00000395 <pipe>: SYSCALL(pipe) 395: b8 04 00 00 00 mov $0x4,%eax 39a: cd 40 int $0x40 39c: c3 ret 0000039d <read>: SYSCALL(read) 39d: b8 05 00 00 00 mov $0x5,%eax 3a2: cd 40 int $0x40 3a4: c3 ret 000003a5 <write>: SYSCALL(write) 3a5: b8 10 00 00 00 mov $0x10,%eax 3aa: cd 40 int $0x40 3ac: c3 ret 000003ad <close>: SYSCALL(close) 3ad: b8 15 00 00 00 mov $0x15,%eax 3b2: cd 40 int $0x40 3b4: c3 ret 000003b5 <kill>: SYSCALL(kill) 3b5: b8 06 00 00 00 mov $0x6,%eax 3ba: cd 40 int $0x40 3bc: c3 ret 000003bd <exec>: SYSCALL(exec) 3bd: b8 07 00 00 00 mov $0x7,%eax 3c2: cd 40 int $0x40 3c4: c3 ret 000003c5 <open>: SYSCALL(open) 3c5: b8 0f 00 00 00 mov $0xf,%eax 3ca: cd 40 int $0x40 3cc: c3 ret 000003cd <mknod>: SYSCALL(mknod) 3cd: b8 11 00 00 00 mov $0x11,%eax 3d2: cd 40 int $0x40 3d4: c3 ret 000003d5 <unlink>: SYSCALL(unlink) 3d5: b8 12 00 00 00 mov $0x12,%eax 3da: cd 40 int $0x40 3dc: c3 ret 000003dd <fstat>: SYSCALL(fstat) 3dd: b8 08 00 00 00 mov $0x8,%eax 3e2: cd 40 int $0x40 3e4: c3 ret 000003e5 <link>: SYSCALL(link) 3e5: b8 13 00 00 00 mov $0x13,%eax 3ea: cd 40 int $0x40 3ec: c3 ret 000003ed <mkdir>: SYSCALL(mkdir) 3ed: b8 14 00 00 00 mov $0x14,%eax 3f2: cd 40 int $0x40 3f4: c3 ret 000003f5 <chdir>: SYSCALL(chdir) 3f5: b8 09 00 00 00 mov $0x9,%eax 3fa: cd 40 int $0x40 3fc: c3 ret 000003fd <dup>: SYSCALL(dup) 3fd: b8 0a 00 00 00 mov $0xa,%eax 402: cd 40 int $0x40 404: c3 ret 00000405 <getpid>: SYSCALL(getpid) 405: b8 0b 00 00 00 mov $0xb,%eax 40a: cd 40 int $0x40 40c: c3 ret 0000040d <sbrk>: SYSCALL(sbrk) 40d: b8 0c 00 00 00 mov $0xc,%eax 412: cd 40 int $0x40 414: c3 ret 00000415 <sleep>: SYSCALL(sleep) 415: b8 0d 00 00 00 mov $0xd,%eax 41a: cd 40 int $0x40 41c: c3 ret 0000041d <uptime>: 41d: b8 0e 00 00 00 mov $0xe,%eax 422: cd 40 int $0x40 424: c3 ret 00000425 <putc>: #include "stat.h" #include "user.h" static void putc(int fd, char c) { 425: 55 push %ebp 426: 89 e5 mov %esp,%ebp 428: 83 ec 18 sub $0x18,%esp 42b: 8b 45 0c mov 0xc(%ebp),%eax 42e: 88 45 f4 mov %al,-0xc(%ebp) write(fd, &c, 1); 431: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp) 438: 00 439: 8d 45 f4 lea -0xc(%ebp),%eax 43c: 89 44 24 04 mov %eax,0x4(%esp) 440: 8b 45 08 mov 0x8(%ebp),%eax 443: 89 04 24 mov %eax,(%esp) 446: e8 5a ff ff ff call 3a5 <write> } 44b: c9 leave 44c: c3 ret 0000044d <printint>: static void printint(int fd, int xx, int base, int sgn) { 44d: 55 push %ebp 44e: 89 e5 mov %esp,%ebp 450: 56 push %esi 451: 53 push %ebx 452: 83 ec 30 sub $0x30,%esp static char digits[] = "0123456789ABCDEF"; char buf[16]; int i, neg; uint x; neg = 0; 455: c7 45 f0 00 00 00 00 movl $0x0,-0x10(%ebp) if(sgn && xx < 0){ 45c: 83 7d 14 00 cmpl $0x0,0x14(%ebp) 460: 74 17 je 479 <printint+0x2c> 462: 83 7d 0c 00 cmpl $0x0,0xc(%ebp) 466: 79 11 jns 479 <printint+0x2c> neg = 1; 468: c7 45 f0 01 00 00 00 movl $0x1,-0x10(%ebp) x = -xx; 46f: 8b 45 0c mov 0xc(%ebp),%eax 472: f7 d8 neg %eax 474: 89 45 ec mov %eax,-0x14(%ebp) 477: eb 06 jmp 47f <printint+0x32> } else { x = xx; 479: 8b 45 0c mov 0xc(%ebp),%eax 47c: 89 45 ec mov %eax,-0x14(%ebp) } i = 0; 47f: c7 45 f4 00 00 00 00 movl $0x0,-0xc(%ebp) do{ buf[i++] = digits[x % base]; 486: 8b 4d f4 mov -0xc(%ebp),%ecx 489: 8d 41 01 lea 0x1(%ecx),%eax 48c: 89 45 f4 mov %eax,-0xc(%ebp) 48f: 8b 5d 10 mov 0x10(%ebp),%ebx 492: 8b 45 ec mov -0x14(%ebp),%eax 495: ba 00 00 00 00 mov $0x0,%edx 49a: f7 f3 div %ebx 49c: 89 d0 mov %edx,%eax 49e: 0f b6 80 64 0b 00 00 movzbl 0xb64(%eax),%eax 4a5: 88 44 0d dc mov %al,-0x24(%ebp,%ecx,1) }while((x /= base) != 0); 4a9: 8b 75 10 mov 0x10(%ebp),%esi 4ac: 8b 45 ec mov -0x14(%ebp),%eax 4af: ba 00 00 00 00 mov $0x0,%edx 4b4: f7 f6 div %esi 4b6: 89 45 ec mov %eax,-0x14(%ebp) 4b9: 83 7d ec 00 cmpl $0x0,-0x14(%ebp) 4bd: 75 c7 jne 486 <printint+0x39> if(neg) 4bf: 83 7d f0 00 cmpl $0x0,-0x10(%ebp) 4c3: 74 10 je 4d5 <printint+0x88> buf[i++] = '-'; 4c5: 8b 45 f4 mov -0xc(%ebp),%eax 4c8: 8d 50 01 lea 0x1(%eax),%edx 4cb: 89 55 f4 mov %edx,-0xc(%ebp) 4ce: c6 44 05 dc 2d movb $0x2d,-0x24(%ebp,%eax,1) while(--i >= 0) 4d3: eb 1f jmp 4f4 <printint+0xa7> 4d5: eb 1d jmp 4f4 <printint+0xa7> putc(fd, buf[i]); 4d7: 8d 55 dc lea -0x24(%ebp),%edx 4da: 8b 45 f4 mov -0xc(%ebp),%eax 4dd: 01 d0 add %edx,%eax 4df: 0f b6 00 movzbl (%eax),%eax 4e2: 0f be c0 movsbl %al,%eax 4e5: 89 44 24 04 mov %eax,0x4(%esp) 4e9: 8b 45 08 mov 0x8(%ebp),%eax 4ec: 89 04 24 mov %eax,(%esp) 4ef: e8 31 ff ff ff call 425 <putc> buf[i++] = digits[x % base]; }while((x /= base) != 0); if(neg) buf[i++] = '-'; while(--i >= 0) 4f4: 83 6d f4 01 subl $0x1,-0xc(%ebp) 4f8: 83 7d f4 00 cmpl $0x0,-0xc(%ebp) 4fc: 79 d9 jns 4d7 <printint+0x8a> putc(fd, buf[i]); } 4fe: 83 c4 30 add $0x30,%esp 501: 5b pop %ebx 502: 5e pop %esi 503: 5d pop %ebp 504: c3 ret 00000505 <printf>: // Print to the given fd. Only understands %d, %x, %p, %s. void printf(int fd, char *fmt, ...) { 505: 55 push %ebp 506: 89 e5 mov %esp,%ebp 508: 83 ec 38 sub $0x38,%esp char *s; int c, i, state; uint *ap; state = 0; 50b: c7 45 ec 00 00 00 00 movl $0x0,-0x14(%ebp) ap = (uint*)(void*)&fmt + 1; 512: 8d 45 0c lea 0xc(%ebp),%eax 515: 83 c0 04 add $0x4,%eax 518: 89 45 e8 mov %eax,-0x18(%ebp) for(i = 0; fmt[i]; i++){ 51b: c7 45 f0 00 00 00 00 movl $0x0,-0x10(%ebp) 522: e9 7c 01 00 00 jmp 6a3 <printf+0x19e> c = fmt[i] & 0xff; 527: 8b 55 0c mov 0xc(%ebp),%edx 52a: 8b 45 f0 mov -0x10(%ebp),%eax 52d: 01 d0 add %edx,%eax 52f: 0f b6 00 movzbl (%eax),%eax 532: 0f be c0 movsbl %al,%eax 535: 25 ff 00 00 00 and $0xff,%eax 53a: 89 45 e4 mov %eax,-0x1c(%ebp) if(state == 0){ 53d: 83 7d ec 00 cmpl $0x0,-0x14(%ebp) 541: 75 2c jne 56f <printf+0x6a> if(c == '%'){ 543: 83 7d e4 25 cmpl $0x25,-0x1c(%ebp) 547: 75 0c jne 555 <printf+0x50> state = '%'; 549: c7 45 ec 25 00 00 00 movl $0x25,-0x14(%ebp) 550: e9 4a 01 00 00 jmp 69f <printf+0x19a> } else { putc(fd, c); 555: 8b 45 e4 mov -0x1c(%ebp),%eax 558: 0f be c0 movsbl %al,%eax 55b: 89 44 24 04 mov %eax,0x4(%esp) 55f: 8b 45 08 mov 0x8(%ebp),%eax 562: 89 04 24 mov %eax,(%esp) 565: e8 bb fe ff ff call 425 <putc> 56a: e9 30 01 00 00 jmp 69f <printf+0x19a> } } else if(state == '%'){ 56f: 83 7d ec 25 cmpl $0x25,-0x14(%ebp) 573: 0f 85 26 01 00 00 jne 69f <printf+0x19a> if(c == 'd'){ 579: 83 7d e4 64 cmpl $0x64,-0x1c(%ebp) 57d: 75 2d jne 5ac <printf+0xa7> printint(fd, *ap, 10, 1); 57f: 8b 45 e8 mov -0x18(%ebp),%eax 582: 8b 00 mov (%eax),%eax 584: c7 44 24 0c 01 00 00 movl $0x1,0xc(%esp) 58b: 00 58c: c7 44 24 08 0a 00 00 movl $0xa,0x8(%esp) 593: 00 594: 89 44 24 04 mov %eax,0x4(%esp) 598: 8b 45 08 mov 0x8(%ebp),%eax 59b: 89 04 24 mov %eax,(%esp) 59e: e8 aa fe ff ff call 44d <printint> ap++; 5a3: 83 45 e8 04 addl $0x4,-0x18(%ebp) 5a7: e9 ec 00 00 00 jmp 698 <printf+0x193> } else if(c == 'x' || c == 'p'){ 5ac: 83 7d e4 78 cmpl $0x78,-0x1c(%ebp) 5b0: 74 06 je 5b8 <printf+0xb3> 5b2: 83 7d e4 70 cmpl $0x70,-0x1c(%ebp) 5b6: 75 2d jne 5e5 <printf+0xe0> printint(fd, *ap, 16, 0); 5b8: 8b 45 e8 mov -0x18(%ebp),%eax 5bb: 8b 00 mov (%eax),%eax 5bd: c7 44 24 0c 00 00 00 movl $0x0,0xc(%esp) 5c4: 00 5c5: c7 44 24 08 10 00 00 movl $0x10,0x8(%esp) 5cc: 00 5cd: 89 44 24 04 mov %eax,0x4(%esp) 5d1: 8b 45 08 mov 0x8(%ebp),%eax 5d4: 89 04 24 mov %eax,(%esp) 5d7: e8 71 fe ff ff call 44d <printint> ap++; 5dc: 83 45 e8 04 addl $0x4,-0x18(%ebp) 5e0: e9 b3 00 00 00 jmp 698 <printf+0x193> } else if(c == 's'){ 5e5: 83 7d e4 73 cmpl $0x73,-0x1c(%ebp) 5e9: 75 45 jne 630 <printf+0x12b> s = (char*)*ap; 5eb: 8b 45 e8 mov -0x18(%ebp),%eax 5ee: 8b 00 mov (%eax),%eax 5f0: 89 45 f4 mov %eax,-0xc(%ebp) ap++; 5f3: 83 45 e8 04 addl $0x4,-0x18(%ebp) if(s == 0) 5f7: 83 7d f4 00 cmpl $0x0,-0xc(%ebp) 5fb: 75 09 jne 606 <printf+0x101> s = "(null)"; 5fd: c7 45 f4 f7 08 00 00 movl $0x8f7,-0xc(%ebp) while(*s != 0){ 604: eb 1e jmp 624 <printf+0x11f> 606: eb 1c jmp 624 <printf+0x11f> putc(fd, *s); 608: 8b 45 f4 mov -0xc(%ebp),%eax 60b: 0f b6 00 movzbl (%eax),%eax 60e: 0f be c0 movsbl %al,%eax 611: 89 44 24 04 mov %eax,0x4(%esp) 615: 8b 45 08 mov 0x8(%ebp),%eax 618: 89 04 24 mov %eax,(%esp) 61b: e8 05 fe ff ff call 425 <putc> s++; 620: 83 45 f4 01 addl $0x1,-0xc(%ebp) } else if(c == 's'){ s = (char*)*ap; ap++; if(s == 0) s = "(null)"; while(*s != 0){ 624: 8b 45 f4 mov -0xc(%ebp),%eax 627: 0f b6 00 movzbl (%eax),%eax 62a: 84 c0 test %al,%al 62c: 75 da jne 608 <printf+0x103> 62e: eb 68 jmp 698 <printf+0x193> putc(fd, *s); s++; } } else if(c == 'c'){ 630: 83 7d e4 63 cmpl $0x63,-0x1c(%ebp) 634: 75 1d jne 653 <printf+0x14e> putc(fd, *ap); 636: 8b 45 e8 mov -0x18(%ebp),%eax 639: 8b 00 mov (%eax),%eax 63b: 0f be c0 movsbl %al,%eax 63e: 89 44 24 04 mov %eax,0x4(%esp) 642: 8b 45 08 mov 0x8(%ebp),%eax 645: 89 04 24 mov %eax,(%esp) 648: e8 d8 fd ff ff call 425 <putc> ap++; 64d: 83 45 e8 04 addl $0x4,-0x18(%ebp) 651: eb 45 jmp 698 <printf+0x193> } else if(c == '%'){ 653: 83 7d e4 25 cmpl $0x25,-0x1c(%ebp) 657: 75 17 jne 670 <printf+0x16b> putc(fd, c); 659: 8b 45 e4 mov -0x1c(%ebp),%eax 65c: 0f be c0 movsbl %al,%eax 65f: 89 44 24 04 mov %eax,0x4(%esp) 663: 8b 45 08 mov 0x8(%ebp),%eax 666: 89 04 24 mov %eax,(%esp) 669: e8 b7 fd ff ff call 425 <putc> 66e: eb 28 jmp 698 <printf+0x193> } else { // Unknown % sequence. Print it to draw attention. putc(fd, '%'); 670: c7 44 24 04 25 00 00 movl $0x25,0x4(%esp) 677: 00 678: 8b 45 08 mov 0x8(%ebp),%eax 67b: 89 04 24 mov %eax,(%esp) 67e: e8 a2 fd ff ff call 425 <putc> putc(fd, c); 683: 8b 45 e4 mov -0x1c(%ebp),%eax 686: 0f be c0 movsbl %al,%eax 689: 89 44 24 04 mov %eax,0x4(%esp) 68d: 8b 45 08 mov 0x8(%ebp),%eax 690: 89 04 24 mov %eax,(%esp) 693: e8 8d fd ff ff call 425 <putc> } state = 0; 698: 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++){ 69f: 83 45 f0 01 addl $0x1,-0x10(%ebp) 6a3: 8b 55 0c mov 0xc(%ebp),%edx 6a6: 8b 45 f0 mov -0x10(%ebp),%eax 6a9: 01 d0 add %edx,%eax 6ab: 0f b6 00 movzbl (%eax),%eax 6ae: 84 c0 test %al,%al 6b0: 0f 85 71 fe ff ff jne 527 <printf+0x22> putc(fd, c); } state = 0; } } } 6b6: c9 leave 6b7: c3 ret 000006b8 <free>: static Header base; static Header *freep; void free(void *ap) { 6b8: 55 push %ebp 6b9: 89 e5 mov %esp,%ebp 6bb: 83 ec 10 sub $0x10,%esp Header *bp, *p; bp = (Header*)ap - 1; 6be: 8b 45 08 mov 0x8(%ebp),%eax 6c1: 83 e8 08 sub $0x8,%eax 6c4: 89 45 f8 mov %eax,-0x8(%ebp) for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) 6c7: a1 88 0b 00 00 mov 0xb88,%eax 6cc: 89 45 fc mov %eax,-0x4(%ebp) 6cf: eb 24 jmp 6f5 <free+0x3d> if(p >= p->s.ptr && (bp > p || bp < p->s.ptr)) 6d1: 8b 45 fc mov -0x4(%ebp),%eax 6d4: 8b 00 mov (%eax),%eax 6d6: 3b 45 fc cmp -0x4(%ebp),%eax 6d9: 77 12 ja 6ed <free+0x35> 6db: 8b 45 f8 mov -0x8(%ebp),%eax 6de: 3b 45 fc cmp -0x4(%ebp),%eax 6e1: 77 24 ja 707 <free+0x4f> 6e3: 8b 45 fc mov -0x4(%ebp),%eax 6e6: 8b 00 mov (%eax),%eax 6e8: 3b 45 f8 cmp -0x8(%ebp),%eax 6eb: 77 1a ja 707 <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) 6ed: 8b 45 fc mov -0x4(%ebp),%eax 6f0: 8b 00 mov (%eax),%eax 6f2: 89 45 fc mov %eax,-0x4(%ebp) 6f5: 8b 45 f8 mov -0x8(%ebp),%eax 6f8: 3b 45 fc cmp -0x4(%ebp),%eax 6fb: 76 d4 jbe 6d1 <free+0x19> 6fd: 8b 45 fc mov -0x4(%ebp),%eax 700: 8b 00 mov (%eax),%eax 702: 3b 45 f8 cmp -0x8(%ebp),%eax 705: 76 ca jbe 6d1 <free+0x19> if(p >= p->s.ptr && (bp > p || bp < p->s.ptr)) break; if(bp + bp->s.size == p->s.ptr){ 707: 8b 45 f8 mov -0x8(%ebp),%eax 70a: 8b 40 04 mov 0x4(%eax),%eax 70d: 8d 14 c5 00 00 00 00 lea 0x0(,%eax,8),%edx 714: 8b 45 f8 mov -0x8(%ebp),%eax 717: 01 c2 add %eax,%edx 719: 8b 45 fc mov -0x4(%ebp),%eax 71c: 8b 00 mov (%eax),%eax 71e: 39 c2 cmp %eax,%edx 720: 75 24 jne 746 <free+0x8e> bp->s.size += p->s.ptr->s.size; 722: 8b 45 f8 mov -0x8(%ebp),%eax 725: 8b 50 04 mov 0x4(%eax),%edx 728: 8b 45 fc mov -0x4(%ebp),%eax 72b: 8b 00 mov (%eax),%eax 72d: 8b 40 04 mov 0x4(%eax),%eax 730: 01 c2 add %eax,%edx 732: 8b 45 f8 mov -0x8(%ebp),%eax 735: 89 50 04 mov %edx,0x4(%eax) bp->s.ptr = p->s.ptr->s.ptr; 738: 8b 45 fc mov -0x4(%ebp),%eax 73b: 8b 00 mov (%eax),%eax 73d: 8b 10 mov (%eax),%edx 73f: 8b 45 f8 mov -0x8(%ebp),%eax 742: 89 10 mov %edx,(%eax) 744: eb 0a jmp 750 <free+0x98> } else bp->s.ptr = p->s.ptr; 746: 8b 45 fc mov -0x4(%ebp),%eax 749: 8b 10 mov (%eax),%edx 74b: 8b 45 f8 mov -0x8(%ebp),%eax 74e: 89 10 mov %edx,(%eax) if(p + p->s.size == bp){ 750: 8b 45 fc mov -0x4(%ebp),%eax 753: 8b 40 04 mov 0x4(%eax),%eax 756: 8d 14 c5 00 00 00 00 lea 0x0(,%eax,8),%edx 75d: 8b 45 fc mov -0x4(%ebp),%eax 760: 01 d0 add %edx,%eax 762: 3b 45 f8 cmp -0x8(%ebp),%eax 765: 75 20 jne 787 <free+0xcf> p->s.size += bp->s.size; 767: 8b 45 fc mov -0x4(%ebp),%eax 76a: 8b 50 04 mov 0x4(%eax),%edx 76d: 8b 45 f8 mov -0x8(%ebp),%eax 770: 8b 40 04 mov 0x4(%eax),%eax 773: 01 c2 add %eax,%edx 775: 8b 45 fc mov -0x4(%ebp),%eax 778: 89 50 04 mov %edx,0x4(%eax) p->s.ptr = bp->s.ptr; 77b: 8b 45 f8 mov -0x8(%ebp),%eax 77e: 8b 10 mov (%eax),%edx 780: 8b 45 fc mov -0x4(%ebp),%eax 783: 89 10 mov %edx,(%eax) 785: eb 08 jmp 78f <free+0xd7> } else p->s.ptr = bp; 787: 8b 45 fc mov -0x4(%ebp),%eax 78a: 8b 55 f8 mov -0x8(%ebp),%edx 78d: 89 10 mov %edx,(%eax) freep = p; 78f: 8b 45 fc mov -0x4(%ebp),%eax 792: a3 88 0b 00 00 mov %eax,0xb88 } 797: c9 leave 798: c3 ret 00000799 <morecore>: static Header* morecore(uint nu) { 799: 55 push %ebp 79a: 89 e5 mov %esp,%ebp 79c: 83 ec 28 sub $0x28,%esp char *p; Header *hp; if(nu < 4096) 79f: 81 7d 08 ff 0f 00 00 cmpl $0xfff,0x8(%ebp) 7a6: 77 07 ja 7af <morecore+0x16> nu = 4096; 7a8: c7 45 08 00 10 00 00 movl $0x1000,0x8(%ebp) p = sbrk(nu * sizeof(Header)); 7af: 8b 45 08 mov 0x8(%ebp),%eax 7b2: c1 e0 03 shl $0x3,%eax 7b5: 89 04 24 mov %eax,(%esp) 7b8: e8 50 fc ff ff call 40d <sbrk> 7bd: 89 45 f4 mov %eax,-0xc(%ebp) if(p == (char*)-1) 7c0: 83 7d f4 ff cmpl $0xffffffff,-0xc(%ebp) 7c4: 75 07 jne 7cd <morecore+0x34> return 0; 7c6: b8 00 00 00 00 mov $0x0,%eax 7cb: eb 22 jmp 7ef <morecore+0x56> hp = (Header*)p; 7cd: 8b 45 f4 mov -0xc(%ebp),%eax 7d0: 89 45 f0 mov %eax,-0x10(%ebp) hp->s.size = nu; 7d3: 8b 45 f0 mov -0x10(%ebp),%eax 7d6: 8b 55 08 mov 0x8(%ebp),%edx 7d9: 89 50 04 mov %edx,0x4(%eax) free((void*)(hp + 1)); 7dc: 8b 45 f0 mov -0x10(%ebp),%eax 7df: 83 c0 08 add $0x8,%eax 7e2: 89 04 24 mov %eax,(%esp) 7e5: e8 ce fe ff ff call 6b8 <free> return freep; 7ea: a1 88 0b 00 00 mov 0xb88,%eax } 7ef: c9 leave 7f0: c3 ret 000007f1 <malloc>: void* malloc(uint nbytes) { 7f1: 55 push %ebp 7f2: 89 e5 mov %esp,%ebp 7f4: 83 ec 28 sub $0x28,%esp Header *p, *prevp; uint nunits; nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1; 7f7: 8b 45 08 mov 0x8(%ebp),%eax 7fa: 83 c0 07 add $0x7,%eax 7fd: c1 e8 03 shr $0x3,%eax 800: 83 c0 01 add $0x1,%eax 803: 89 45 ec mov %eax,-0x14(%ebp) if((prevp = freep) == 0){ 806: a1 88 0b 00 00 mov 0xb88,%eax 80b: 89 45 f0 mov %eax,-0x10(%ebp) 80e: 83 7d f0 00 cmpl $0x0,-0x10(%ebp) 812: 75 23 jne 837 <malloc+0x46> base.s.ptr = freep = prevp = &base; 814: c7 45 f0 80 0b 00 00 movl $0xb80,-0x10(%ebp) 81b: 8b 45 f0 mov -0x10(%ebp),%eax 81e: a3 88 0b 00 00 mov %eax,0xb88 823: a1 88 0b 00 00 mov 0xb88,%eax 828: a3 80 0b 00 00 mov %eax,0xb80 base.s.size = 0; 82d: c7 05 84 0b 00 00 00 movl $0x0,0xb84 834: 00 00 00 } for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){ 837: 8b 45 f0 mov -0x10(%ebp),%eax 83a: 8b 00 mov (%eax),%eax 83c: 89 45 f4 mov %eax,-0xc(%ebp) if(p->s.size >= nunits){ 83f: 8b 45 f4 mov -0xc(%ebp),%eax 842: 8b 40 04 mov 0x4(%eax),%eax 845: 3b 45 ec cmp -0x14(%ebp),%eax 848: 72 4d jb 897 <malloc+0xa6> if(p->s.size == nunits) 84a: 8b 45 f4 mov -0xc(%ebp),%eax 84d: 8b 40 04 mov 0x4(%eax),%eax 850: 3b 45 ec cmp -0x14(%ebp),%eax 853: 75 0c jne 861 <malloc+0x70> prevp->s.ptr = p->s.ptr; 855: 8b 45 f4 mov -0xc(%ebp),%eax 858: 8b 10 mov (%eax),%edx 85a: 8b 45 f0 mov -0x10(%ebp),%eax 85d: 89 10 mov %edx,(%eax) 85f: eb 26 jmp 887 <malloc+0x96> else { p->s.size -= nunits; 861: 8b 45 f4 mov -0xc(%ebp),%eax 864: 8b 40 04 mov 0x4(%eax),%eax 867: 2b 45 ec sub -0x14(%ebp),%eax 86a: 89 c2 mov %eax,%edx 86c: 8b 45 f4 mov -0xc(%ebp),%eax 86f: 89 50 04 mov %edx,0x4(%eax) p += p->s.size; 872: 8b 45 f4 mov -0xc(%ebp),%eax 875: 8b 40 04 mov 0x4(%eax),%eax 878: c1 e0 03 shl $0x3,%eax 87b: 01 45 f4 add %eax,-0xc(%ebp) p->s.size = nunits; 87e: 8b 45 f4 mov -0xc(%ebp),%eax 881: 8b 55 ec mov -0x14(%ebp),%edx 884: 89 50 04 mov %edx,0x4(%eax) } freep = prevp; 887: 8b 45 f0 mov -0x10(%ebp),%eax 88a: a3 88 0b 00 00 mov %eax,0xb88 return (void*)(p + 1); 88f: 8b 45 f4 mov -0xc(%ebp),%eax 892: 83 c0 08 add $0x8,%eax 895: eb 38 jmp 8cf <malloc+0xde> } if(p == freep) 897: a1 88 0b 00 00 mov 0xb88,%eax 89c: 39 45 f4 cmp %eax,-0xc(%ebp) 89f: 75 1b jne 8bc <malloc+0xcb> if((p = morecore(nunits)) == 0) 8a1: 8b 45 ec mov -0x14(%ebp),%eax 8a4: 89 04 24 mov %eax,(%esp) 8a7: e8 ed fe ff ff call 799 <morecore> 8ac: 89 45 f4 mov %eax,-0xc(%ebp) 8af: 83 7d f4 00 cmpl $0x0,-0xc(%ebp) 8b3: 75 07 jne 8bc <malloc+0xcb> return 0; 8b5: b8 00 00 00 00 mov $0x0,%eax 8ba: eb 13 jmp 8cf <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){ 8bc: 8b 45 f4 mov -0xc(%ebp),%eax 8bf: 89 45 f0 mov %eax,-0x10(%ebp) 8c2: 8b 45 f4 mov -0xc(%ebp),%eax 8c5: 8b 00 mov (%eax),%eax 8c7: 89 45 f4 mov %eax,-0xc(%ebp) return (void*)(p + 1); } if(p == freep) if((p = morecore(nunits)) == 0) return 0; } 8ca: e9 70 ff ff ff jmp 83f <malloc+0x4e> } 8cf: c9 leave 8d0: c3 ret
; A063229: Dimension of the space of weight 2n cuspidal newforms for Gamma_0( 69 ). ; 3,12,18,26,32,42,46,56,62,70,76,86,90,100,106,114,120,130,134,144,150,158,164,174,178,188,194,202,208,218,222,232,238,246,252,262,266,276,282,290,296,306,310,320,326,334,340,350,354,364 mov $2,$0 mov $4,$0 add $0,1 mul $0,2 div $0,3 add $0,1 mov $3,3 add $3,$0 add $4,1 div $4,2 mul $4,4 mov $5,$4 mov $4,1 lpb $0,1 mov $0,0 add $3,$4 trn $5,1 add $5,$3 add $3,1 add $5,$3 add $5,16 lpe mov $1,$5 sub $1,24 mov $6,$2 mul $6,4 add $1,$6
;; Copyright (C) 2016 Ben Kurtovic <ben.kurtovic@gmail.com> ;; Released under the terms of the MIT License. See LICENSE for details. ; ----- CRATER UNIT TESTING SUITE --------------------------------------------- ; 03-headers2.asm ; Header/directive test using non-default values .rom_size "64 KB" .rom_header $7FF0 .rom_product 101893 .rom_version 3 .rom_region "GG International" .rom_checksum on .rom_declsize "32 KB" .cross_blocks off
#include "DummyObject.h" TDummyObject::TDummyObject(std::string name) : TObjectOfObservation(name) { properties.insert( {"Property1", new TProperties({{"Property1", 2}}, false, "Property1")}); properties.insert( {"Property2", new TProperties({{"Property2", 5}}, true, "Property2")}); } LIB_EXPORT_API TObjectOfObservation* create() { return new TDummyObject("TDummyObject"); }
/* * Copyright (c) 2021, Linus Groh <linusg@serenityos.org> * Copyright (c) 2021, David Tuin <davidot@serenityos.org> * * SPDX-License-Identifier: MIT */ #include "GlobalObject.h" #include <AK/Format.h> #include <AK/JsonObject.h> #include <AK/Result.h> #include <AK/String.h> #include <AK/Vector.h> #include <LibCore/ArgsParser.h> #include <LibCore/File.h> #include <LibJS/Bytecode/BasicBlock.h> #include <LibJS/Bytecode/Generator.h> #include <LibJS/Bytecode/Interpreter.h> #include <LibJS/Bytecode/PassManager.h> #include <LibJS/Interpreter.h> #include <LibJS/Lexer.h> #include <LibJS/Parser.h> #include <LibJS/Runtime/VM.h> #include <fcntl.h> #include <signal.h> #include <stdio.h> #include <time.h> #include <unistd.h> static String s_current_test = ""; static bool s_use_bytecode = false; static bool s_parse_only = false; static String s_harness_file_directory; enum class NegativePhase { ParseOrEarly, Resolution, Runtime, Harness }; struct TestError { NegativePhase phase { NegativePhase::ParseOrEarly }; String type; String details; String harness_file; }; static Result<NonnullRefPtr<JS::Program>, TestError> parse_program(StringView source, JS::Program::Type program_type) { auto parser = JS::Parser(JS::Lexer(source), program_type); auto program = parser.parse_program(); if (parser.has_errors()) { return TestError { NegativePhase::ParseOrEarly, "SyntaxError", parser.errors()[0].to_string(), "" }; } return program; } template<typename InterpreterT> static Result<void, TestError> run_program(InterpreterT& interpreter, JS::Program const& program) { auto& vm = interpreter.vm(); if constexpr (IsSame<InterpreterT, JS::Interpreter>) { interpreter.run(interpreter.global_object(), program); } else { auto unit = JS::Bytecode::Generator::generate(program); auto& passes = JS::Bytecode::Interpreter::optimization_pipeline(); passes.perform(unit); TRY_OR_DISCARD(interpreter.run(unit)); } if (auto* exception = vm.exception()) { vm.clear_exception(); TestError error; error.phase = NegativePhase::Runtime; if (exception->value().is_object()) { auto& object = exception->value().as_object(); auto name = object.get_without_side_effects("name"); if (!name.is_empty() && !name.is_accessor()) { error.type = name.to_string_without_side_effects(); } else { auto constructor = object.get_without_side_effects("constructor"); if (constructor.is_object()) { name = constructor.as_object().get_without_side_effects("name"); if (!name.is_undefined()) error.type = name.to_string_without_side_effects(); } } auto message = object.get_without_side_effects("message"); if (!message.is_empty() && !message.is_accessor()) error.details = message.to_string_without_side_effects(); } if (error.type.is_empty()) error.type = exception->value().to_string_without_side_effects(); return error; } return {}; } static HashMap<String, String> s_cached_harness_files; static Result<StringView, TestError> read_harness_file(StringView harness_file) { auto cache = s_cached_harness_files.find(harness_file); if (cache == s_cached_harness_files.end()) { auto file = Core::File::construct(String::formatted("{}{}", s_harness_file_directory, harness_file)); if (!file->open(Core::OpenMode::ReadOnly)) { return TestError { NegativePhase::Harness, "filesystem", String::formatted("Could not open file: {}", harness_file), harness_file }; } auto contents = file->read_all(); StringView contents_view = contents; s_cached_harness_files.set(harness_file, contents_view.to_string()); cache = s_cached_harness_files.find(harness_file); VERIFY(cache != s_cached_harness_files.end()); } return cache->value.view(); } static Result<NonnullRefPtr<JS::Program>, TestError> parse_harness_files(StringView harness_file) { auto source_or_error = read_harness_file(harness_file); if (source_or_error.is_error()) return source_or_error.release_error(); auto program_or_error = parse_program(source_or_error.value(), JS::Program::Type::Script); if (program_or_error.is_error()) { return TestError { NegativePhase::Harness, program_or_error.error().type, program_or_error.error().details, harness_file }; } return program_or_error.release_value(); } static Result<void, TestError> run_test(StringView source, JS::Program::Type program_type, Vector<StringView> const& harness_files) { auto program_or_error = parse_program(source, program_type); if (program_or_error.is_error()) return program_or_error.release_error(); if (s_parse_only) return {}; auto vm = JS::VM::create(); auto ast_interpreter = JS::Interpreter::create<GlobalObject>(*vm); OwnPtr<JS::Bytecode::Interpreter> bytecode_interpreter = nullptr; if (s_use_bytecode) bytecode_interpreter = make<JS::Bytecode::Interpreter>(ast_interpreter->global_object(), ast_interpreter->realm()); auto run_with_interpreter = [&](JS::Program const& program) { if (s_use_bytecode) return run_program(*bytecode_interpreter, program); return run_program(*ast_interpreter, program); }; for (auto& harness_file : harness_files) { auto harness_program_or_error = parse_harness_files(harness_file); if (harness_program_or_error.is_error()) return harness_program_or_error.release_error(); auto harness_program = harness_program_or_error.release_value(); auto result = run_with_interpreter(*harness_program); if (result.is_error()) { return TestError { NegativePhase::Harness, result.error().type, result.error().details, harness_file }; } } return run_with_interpreter(*program_or_error.value()); } enum class StrictMode { Both, NoStrict, OnlyStrict }; static constexpr auto sta_harness_file = "sta.js"sv; static constexpr auto assert_harness_file = "assert.js"sv; static constexpr auto async_include = "doneprintHandle.js"sv; struct TestMetadata { Vector<StringView> harness_files { sta_harness_file, assert_harness_file }; StrictMode strict_mode { StrictMode::Both }; JS::Program::Type program_type { JS::Program::Type::Script }; bool is_async { false }; bool is_negative { false }; NegativePhase phase { NegativePhase::ParseOrEarly }; StringView type; }; static Result<TestMetadata, String> extract_metadata(StringView source) { auto lines = source.lines(); TestMetadata metadata; bool parsing_negative = false; String failed_message; auto parse_list = [&](StringView line) { auto start = line.find('['); if (!start.has_value()) return Vector<StringView> {}; Vector<StringView> items; auto end = line.find_last(']'); if (!end.has_value() || end.value() <= start.value()) { failed_message = String::formatted("Can't parse list in '{}'", line); return items; } auto list = line.substring_view(start.value() + 1, end.value() - start.value() - 1); for (auto const& item : list.split_view(","sv)) items.append(item.trim_whitespace(TrimMode::Both)); return items; }; auto second_word = [&](StringView line) { auto separator = line.find(' '); if (!separator.has_value() || separator.value() >= (line.length() - 1u)) { failed_message = String::formatted("Can't parse value after space in '{}'", line); return ""sv; } return line.substring_view(separator.value() + 1); }; Vector<StringView> include_list; bool parsing_includes_list = false; bool has_phase = false; for (auto raw_line : lines) { if (!failed_message.is_empty()) break; if (raw_line.starts_with("---*/"sv)) { if (parsing_includes_list) { for (auto& file : include_list) metadata.harness_files.append(file); } return metadata; } auto line = raw_line.trim_whitespace(); if (parsing_includes_list) { if (line.starts_with('-')) { include_list.append(second_word(line)); continue; } else { if (include_list.is_empty()) { failed_message = "Supposed to parse a list but found no entries"; break; } for (auto& file : include_list) metadata.harness_files.append(file); include_list.clear(); parsing_includes_list = false; } } if (parsing_negative) { if (line.starts_with("phase:"sv)) { auto phase = second_word(line); has_phase = true; if (phase == "early"sv || phase == "parse"sv) { metadata.phase = NegativePhase::ParseOrEarly; } else if (phase == "resolution"sv) { metadata.phase = NegativePhase::Resolution; } else if (phase == "runtime"sv) { metadata.phase = NegativePhase::Runtime; } else { has_phase = false; failed_message = String::formatted("Unknown negative phase: {}", phase); break; } } else if (line.starts_with("type:"sv)) { metadata.type = second_word(line); } else { if (!has_phase) { failed_message = "Failed to find phase in negative attributes"; break; } if (metadata.type.is_null()) { failed_message = "Failed to find type in negative attributes"; break; } parsing_negative = false; } } if (line.starts_with("flags:"sv)) { auto flags = parse_list(line); if (flags.is_empty()) { failed_message = String::formatted("Failed to find flags in '{}'", line); break; } for (auto flag : flags) { if (flag == "noStrict"sv || flag == "raw"sv) { metadata.strict_mode = StrictMode::NoStrict; } else if (flag == "onlyStrict"sv) { metadata.strict_mode = StrictMode::OnlyStrict; } else if (flag == "module"sv) { VERIFY(metadata.strict_mode == StrictMode::Both); metadata.program_type = JS::Program::Type::Module; metadata.strict_mode = StrictMode::NoStrict; } else if (flag == "async"sv) { metadata.harness_files.append(async_include); metadata.is_async = true; } } } else if (line.starts_with("includes:")) { auto files = parse_list(line); if (files.is_empty()) { parsing_includes_list = true; } else { for (auto& file : files) metadata.harness_files.append(file); } } else if (line.starts_with("negative:"sv)) { metadata.is_negative = true; parsing_negative = true; } } if (failed_message.is_empty()) failed_message = String::formatted("Never reached end of comment '---*/'"); return failed_message; } static bool verify_test(Result<void, TestError>& result, TestMetadata const& metadata, JsonObject& output) { if (result.is_error()) { if (result.error().phase == NegativePhase::Harness) { output.set("harness_error", true); output.set("harness_file", result.error().harness_file); output.set("result", "harness_error"); } else if (result.error().phase == NegativePhase::Runtime) { auto& error_type = result.error().type; auto& error_details = result.error().details; if ((error_type == "InternalError"sv && error_details.starts_with("TODO(")) || (error_type == "Test262Error"sv && error_details.ends_with(" but got a InternalError"sv))) { output.set("todo_error", true); output.set("result", "todo_error"); } } } auto phase_to_string = [](NegativePhase phase) { switch (phase) { case NegativePhase::ParseOrEarly: return "parse"; case NegativePhase::Resolution: return "resolution"; case NegativePhase::Runtime: return "runtime"; case NegativePhase::Harness: return "harness"; } VERIFY_NOT_REACHED(); }; auto error_to_json = [&phase_to_string](TestError const& error) { JsonObject error_object; error_object.set("phase", phase_to_string(error.phase)); error_object.set("type", error.type); error_object.set("details", error.details); return error_object; }; JsonValue expected_error; JsonValue got_error; ScopeGuard set_error = [&] { JsonObject error_object; error_object.set("expected", expected_error); error_object.set("got", got_error); output.set("error", error_object); }; if (!metadata.is_negative) { if (!result.is_error()) return true; got_error = JsonValue { error_to_json(result.error()) }; return false; } JsonObject expected_error_object; expected_error_object.set("phase", phase_to_string(metadata.phase)); expected_error_object.set("type", metadata.type.to_string()); expected_error = expected_error_object; if (!result.is_error()) { if (s_parse_only && metadata.phase != NegativePhase::ParseOrEarly) { // Expected non-parse error but did not get it but we never got to that phase. return true; } return false; } auto const& error = result.error(); got_error = JsonValue { error_to_json(error) }; return error.phase == metadata.phase && error.type == metadata.type; } static FILE* saved_stdout_fd; static void timer_handler(int signum) { JsonObject timeout_result; timeout_result.set("test", s_current_test); timeout_result.set("timeout", true); timeout_result.set("result", "timeout"); outln(saved_stdout_fd, "RESULT {}{}", timeout_result.to_string(), '\0'); // Make sure this message gets out and just die like the default action would be. fflush(saved_stdout_fd); signal(signum, SIG_DFL); raise(signum); } void __assert_fail(const char* assertion, const char* file, unsigned int line, const char* function) { JsonObject assert_fail_result; assert_fail_result.set("test", s_current_test); assert_fail_result.set("assert_fail", true); assert_fail_result.set("result", "assert_fail"); assert_fail_result.set("output", String::formatted("{}:{}: {}: Assertion `{}' failed.", file, line, function, assertion)); outln(saved_stdout_fd, "RESULT {}{}", assert_fail_result.to_string(), '\0'); // (Attempt to) Ensure that messages are written before quitting. fflush(saved_stdout_fd); fflush(stderr); abort(); } int main(int argc, char** argv) { int timeout = 10; Core::ArgsParser args_parser; args_parser.set_general_help("LibJS test262 runner for streaming tests"); args_parser.add_option(s_harness_file_directory, "Directory containing the harness files", "harness-location", 'l', "harness-files"); args_parser.add_option(s_use_bytecode, "Use the bytecode interpreter", "use-bytecode", 'b'); args_parser.add_option(s_parse_only, "Only parse the files", "parse-only", 'p'); args_parser.add_option(timeout, "Seconds before test should timeout", "timeout", 't', "seconds"); args_parser.parse(argc, argv); if (s_harness_file_directory.is_empty()) { dbgln("You must specify the harness file directory via --harness-location"); return 2; } if (!s_harness_file_directory.ends_with('/')) { s_harness_file_directory = String::formatted("{}/", s_harness_file_directory); } if (timeout <= 0) { dbgln("timeout must be atleast 1"); return 2; } AK::set_debug_enabled(false); // The piping stuff is based on https://stackoverflow.com/a/956269. constexpr auto BUFFER_SIZE = 1 * KiB; char buffer[BUFFER_SIZE] = {}; auto saved_stdout = dup(STDOUT_FILENO); if (saved_stdout < 0) { perror("dup"); return 1; } saved_stdout_fd = fdopen(saved_stdout, "w"); if (!saved_stdout_fd) { perror("fdopen"); return 1; } int stdout_pipe[2]; if (pipe(stdout_pipe) < 0) { perror("pipe"); return 1; } auto flags = fcntl(stdout_pipe[0], F_GETFL); flags |= O_NONBLOCK; fcntl(stdout_pipe[0], F_SETFL, flags); auto flags2 = fcntl(stdout_pipe[1], F_GETFL); flags2 |= O_NONBLOCK; fcntl(stdout_pipe[1], F_SETFL, flags2); if (dup2(stdout_pipe[1], STDOUT_FILENO) < 0) { perror("dup2"); return 1; } if (close(stdout_pipe[1]) < 0) { perror("close"); return 1; } auto collect_output = [&] { fflush(stdout); auto nread = read(stdout_pipe[0], buffer, BUFFER_SIZE); String value; if (nread > 0) { value = String { buffer, static_cast<size_t>(nread) }; while (nread > 0) { nread = read(stdout_pipe[0], buffer, BUFFER_SIZE); } } return value; }; if (signal(SIGVTALRM, timer_handler) == SIG_ERR) { perror("signal"); return 1; } timer_t timer_id; struct sigevent timer_settings; timer_settings.sigev_notify = SIGEV_SIGNAL; timer_settings.sigev_signo = SIGVTALRM; timer_settings.sigev_value.sival_ptr = &timer_id; if (timer_create(CLOCK_PROCESS_CPUTIME_ID, &timer_settings, &timer_id) < 0) { perror("timer_create"); return 1; } struct itimerspec timeout_timer; timeout_timer.it_value.tv_sec = timeout; timeout_timer.it_value.tv_nsec = 0; timeout_timer.it_interval.tv_sec = 0; timeout_timer.it_interval.tv_nsec = 0; struct itimerspec disarm; disarm.it_value.tv_sec = 0; disarm.it_value.tv_nsec = 0; disarm.it_interval.tv_sec = 0; disarm.it_interval.tv_nsec = 0; #define ARM_TIMER() \ if (timer_settime(timer_id, 0, &timeout_timer, nullptr) < 0) { \ perror("timer_settime"); \ return 1; \ } #define DISARM_TIMER() \ if (timer_settime(timer_id, 0, &disarm, nullptr) < 0) { \ perror("timer_settime"); \ return 1; \ } auto stdin = Core::File::standard_input(); size_t count = 0; while (!stdin->eof()) { auto path = stdin->read_line(); if (path.is_empty()) { continue; } s_current_test = path; auto file = Core::File::construct(path); if (!file->open(Core::OpenMode::ReadOnly)) { dbgln("Could not open file: {}", path); return 3; } count++; String source_with_strict; static String use_strict = "'use strict';\n"; static size_t strict_length = use_strict.length(); { auto contents = file->read_all(); StringBuilder builder { contents.size() + strict_length }; builder.append(use_strict); builder.append(contents); source_with_strict = builder.to_string(); } StringView with_strict = source_with_strict.view(); StringView original_contents = source_with_strict.substring_view(strict_length); JsonObject result_object; result_object.set("test", path); ScopeGuard output_guard = [&] { outln(saved_stdout_fd, "RESULT {}{}", result_object.to_string(), '\0'); fflush(saved_stdout_fd); }; auto metadata_or_error = extract_metadata(original_contents); if (metadata_or_error.is_error()) { result_object.set("result", "metadata_error"); result_object.set("metadata_error", true); result_object.set("metadata_output", metadata_or_error.error()); continue; } auto& metadata = metadata_or_error.value(); bool passed = true; if (metadata.strict_mode != StrictMode::OnlyStrict) { result_object.set("strict_mode", false); ARM_TIMER(); auto result = run_test(original_contents, metadata.program_type, metadata.harness_files); DISARM_TIMER(); String first_output = collect_output(); if (!first_output.is_null()) result_object.set("output", first_output); passed = verify_test(result, metadata, result_object); if (metadata.is_async && !s_parse_only) { if (!first_output.contains("Test262:AsyncTestComplete") || first_output.contains("Test262:AsyncTestFailure")) { passed = false; } } } if (passed && metadata.strict_mode != StrictMode::NoStrict) { result_object.set("strict_mode", true); ARM_TIMER(); auto result = run_test(with_strict, metadata.program_type, metadata.harness_files); DISARM_TIMER(); String first_output = collect_output(); if (!first_output.is_null()) result_object.set("strict_output", first_output); passed = verify_test(result, metadata, result_object); if (metadata.is_async && !s_parse_only) { if (!first_output.contains("Test262:AsyncTestComplete") || first_output.contains("Test262:AsyncTestFailure")) { passed = false; } } } if (passed) result_object.remove("strict_mode"); if (!result_object.has("result")) result_object.set("result", passed ? "passed" : "failed"); } s_current_test = ""; outln(saved_stdout_fd, "DONE {}", count); // After this point we have already written our output so pretend everything is fine if we get an error. if (dup2(saved_stdout, STDOUT_FILENO) < 0) { perror("dup2"); return 0; } if (fclose(saved_stdout_fd) < 0) { perror("fclose"); return 0; } if (close(stdout_pipe[0]) < 0) { perror("close"); return 0; } return 0; }
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Copyright (c) GeoWorks 1992 -- All Rights Reserved PROJECT: PC GEOS MODULE: FILE: splineAttrs.asm AUTHOR: Chris Boyke ROUTINES: Name Description ---- ----------- REVISION HISTORY: Name Date Description ---- ---- ----------- CDB 5/22/92 Initial version. DESCRIPTION: $Id: splineAttrs.asm,v 1.1 97/04/07 11:09:27 newdeal Exp $ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ SplineAttrCode segment resource COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SplineApplyAttributesToGState %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DESCRIPTION: PASS: *ds:si = VisSplineClass object ds:di = VisSplineClass instance data es = Segment of VisSplineClass. RETURN: DESTROYED: nothing REGISTER/STACK USAGE: PSEUDO CODE/STRATEGY: KNOWN BUGS/SIDE EFFECTS/CAVEATS/IDEAS: REVISION HISTORY: Name Date Description ---- ---- ----------- CDB 5/27/92 Initial version. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ SplineApplyAttributesToGState method dynamic VisSplineClass, MSG_SPLINE_APPLY_ATTRIBUTES_TO_GSTATE uses ax,cx,dx,bp .enter push bp call SplineMethodCommonReadOnly pop di ; set normal draw mode mov al, MM_COPY call GrSetMixMode mov si, es:[bp].VSI_lineAttr mov si, ds:[si] call GrSetLineAttr mov si, es:[bp].VSI_areaAttr mov si, ds:[si] call GrSetAreaAttr call SplineEndmCommon .leave ret SplineApplyAttributesToGState endm COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SplineSetDefaultLineAttrs %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DESCRIPTION: Initialize the line attributes data structure with the default attributes. PASS: *ds:si = VisSplineClass object ds:di = VisSplineClass instance data es = Segment of VisSplineClass. RETURN: DESTROYED: nothing REGISTER/STACK USAGE: PSEUDO CODE/STRATEGY: KNOWN BUGS/SIDE EFFECTS/CAVEATS/IDEAS: REVISION HISTORY: Name Date Description ---- ---- ----------- CDB 5/22/92 Initial version. SH 5/05/94 XIP'ed %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ DefaultSplineLineAttrs LineAttr <CF_INDEX, <C_BLACK,0,0>, SDM_100, CMT_DITHER shl offset CMM_MAP_TYPE, LE_BUTTCAP, LJ_BEVELED, LS_SOLID, <0,1>> SplineSetDefaultLineAttrs method dynamic VisSplineClass, MSG_SPLINE_SET_DEFAULT_LINE_ATTRS uses ax,cx,dx .enter FXIP< push bx, si > FXIP< mov bx, cs > FXIP< mov si, offset DefaultSplineLineAttrs > FXIP< mov cx, size LineAttr > FXIP< call SysCopyToStackBXSI > FXIP< mov cx, bx > FXIP< mov dx, si > FXIP< pop bx, si NOFXIP< mov cx, cs > NOFXIP< mov dx, offset DefaultSplineLineAttrs > mov ax, MSG_SPLINE_SET_LINE_ATTRS call ObjCallInstanceNoLock FXIP< call SysRemoveFromStack > .leave ret SplineSetDefaultLineAttrs endm COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SplineSetDefaultAreaAttrs %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DESCRIPTION: PASS: *ds:si = VisSplineClass object ds:di = VisSplineClass instance data es = Segment of VisSplineClass. RETURN: DESTROYED: nothing REGISTER/STACK USAGE: PSEUDO CODE/STRATEGY: KNOWN BUGS/SIDE EFFECTS/CAVEATS/IDEAS: REVISION HISTORY: Name Date Description ---- ---- ----------- CDB 5/22/92 Initial version. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ DefaultSplineAreaAttrs AreaAttr <CF_INDEX, <C_BLACK,0,0>, SDM_100, CMT_DITHER shl offset CMM_MAP_TYPE> SplineSetDefaultAreaAttrs method dynamic VisSplineClass, MSG_SPLINE_SET_DEFAULT_AREA_ATTRS uses ax,cx,dx .enter FXIP< push bx, si > FXIP< mov bx, cs > FXIP< mov si, offset DefaultSplineAreaAttrs > FXIP< mov cx, size AreaAttr > FXIP< call SysCopyToStackBXSI > FXIP< mov cx, bx > FXIP< mov dx, si > FXIP< pop bx, si NOFXIP< mov cx, cs > NOFXIP< mov dx, offset DefaultSplineAreaAttrs > mov ax, MSG_SPLINE_SET_AREA_ATTRS call ObjCallInstanceNoLock FXIP< call SysRemoveFromStack > .leave ret SplineSetDefaultAreaAttrs endm COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SplineSetLineAttrs %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DESCRIPTION: PASS: *ds:si = VisSplineClass object ds:di = VisSplineClass instance data es = Segment of VisSplineClass. cx:dx = fptr to a LineAttr structure (must be fptr for XIP'ed geodes) RETURN: DESTROYED: nothing REGISTER/STACK USAGE: PSEUDO CODE/STRATEGY: KNOWN BUGS/SIDE EFFECTS/CAVEATS/IDEAS: REVISION HISTORY: Name Date Description ---- ---- ----------- CDB 5/22/92 Initial version. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ SplineSetLineAttrs method dynamic VisSplineClass, MSG_SPLINE_SET_LINE_ATTRS uses ax,cx,dx,bp .enter if FULL_EXECUTE_IN_PLACE ; ; Validate that cx:dx is not pointing to a movable code segment ; EC< push bx, si > EC< movdw bxsi, cxdx > EC< call ECAssertValidFarPointerXIP > EC< pop bx, si > endif test ds:[di].VSI_state, mask SS_HAS_ATTR_CHUNKS jz done call SplineMethodCommon mov di, es:[bp].VSI_lineAttr mov di, ds:[di] push ds, es segmov es, ds mov ds, cx mov si, dx mov cx, size LineAttr rep movsb pop ds, es call SplineEndmCommon done: .leave ret SplineSetLineAttrs endm COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SplineSetAreaAttrs %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DESCRIPTION: PASS: *ds:si = VisSplineClass object ds:di = VisSplineClass instance data es = Segment of VisSplineClass. cx:dx = fptr to a AreaAttr structure (must be fptr for XIP'ed geodes) RETURN: DESTROYED: nothing REGISTER/STACK USAGE: PSEUDO CODE/STRATEGY: KNOWN BUGS/SIDE EFFECTS/CAVEATS/IDEAS: REVISION HISTORY: Name Date Description ---- ---- ----------- CDB 5/22/92 Initial version. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ SplineSetAreaAttrs method dynamic VisSplineClass, MSG_SPLINE_SET_AREA_ATTRS uses ax,cx,dx,bp .enter if FULL_EXECUTE_IN_PLACE ; ; Validate that cx:dx is not pointing to a movable code segment ; EC< push bx, si > EC< movdw bxsi, cxdx > EC< call ECAssertValidFarPointerXIP > EC< pop bx, si > endif test ds:[di].VSI_state, mask SS_HAS_ATTR_CHUNKS jz done call SplineMethodCommon mov di, es:[bp].VSI_areaAttr mov di, ds:[di] push ds, es segmov es, ds mov ds, cx mov si, dx mov cx, size AreaAttr rep movsb pop ds, es call SplineEndmCommon done: .leave ret SplineSetAreaAttrs endm COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% METHOD: SplineSetLineWidth, MSG_SPLINE_SET_LINE_WIDTH DESCRIPTION: Set the line width for all subsequent draws PASS: *ds:si - VisSpline object ds:di - VisSPline instance data dx.cx - line width (WWFixed) RETURN: nothing DESTROYED: nothing REGISTER/STACK USAGE: PSEUDO CODE/STRATEGY: KNOWN BUGS/SIDE EFFECTS/CAVEATS/IDEAS: REVISION HISTORY: Name Date Description ---- ---- ----------- CDB 4/91 Initial version %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ SplineSetLineWidth method dynamic VisSplineClass, MSG_SPLINE_SET_LINE_WIDTH uses ax, cx, dx, bp .enter call SplineMethodCommon mov ax, UT_LINE_ATTR call SplineInitUndo mov di, es:[bp].VSI_lineAttr mov di, ds:[di] movdw bxax, dxcx ; bxax is NEW width xchg cx, ds:[di].LA_width.WWF_frac xchg dx, ds:[di].LA_width.WWF_int cmpdw bxax, dxcx ; compare NEW, OLD ; If NEW > OLD, recalc vis bounds BEFORE invalidating, ; otherwise vice versa. jg recalcThenInval call SplineInvalidate call SplineRecalcVisBounds jmp done recalcThenInval: call SplineRecalcVisBounds call SplineInvalidate done: call SplineEndmCommon .leave ret SplineSetLineWidth endm COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SplineGetLineWidth %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DESCRIPTION: Get the line width from my instance data PASS: *ds:si = VisSplineClass object ds:di = VisSplineClass instance data es = Segment of VisSplineClass. ax = Method. RETURN: dx.cx - line width (WWFixed) DESTROYED: nothing REGISTER/STACK USAGE: PSEUDO CODE/STRATEGY: KNOWN BUGS/SIDE EFFECTS/CAVEATS/IDEAS: REVISION HISTORY: Name Date Description ---- ---- ----------- CDB 10/15/91 Initial version. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ SplineGetLineWidth method dynamic VisSplineClass, MSG_SPLINE_GET_LINE_WIDTH mov bx, offset VSI_lineAttr mov cx, offset LA_width mov dx, size LA_width GOTO SplineGetAttrCommon SplineGetLineWidth endm COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SplineGetLineAttrs %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DESCRIPTION: PASS: *ds:si = VisSplineClass object ds:di = VisSplineClass instance data es = Segment of VisSplineClass. RETURN: DESTROYED: nothing REGISTER/STACK USAGE: PSEUDO CODE/STRATEGY: KNOWN BUGS/SIDE EFFECTS/CAVEATS/IDEAS: REVISION HISTORY: Name Date Description ---- ---- ----------- CDB 5/22/92 Initial version. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ SplineGetLineAttrs method dynamic VisSplineClass, MSG_SPLINE_GET_LINE_ATTRS uses ax,cx,dx,bp .enter call SplineMethodCommonReadOnly mov si, es:[bp].VSI_lineAttr mov si, ds:[si] push es mov es, cx mov di, dx mov cx, size LineAttr rep movsb pop es call SplineEndmCommon .leave ret SplineGetLineAttrs endm COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SplineGetAreaAttrs %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DESCRIPTION: PASS: *ds:si = VisSplineClass object ds:di = VisSplineClass instance data es = Segment of VisSplineClass. RETURN: DESTROYED: nothing REGISTER/STACK USAGE: PSEUDO CODE/STRATEGY: KNOWN BUGS/SIDE EFFECTS/CAVEATS/IDEAS: REVISION HISTORY: Name Date Description ---- ---- ----------- CDB 5/22/92 Initial version. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ SplineGetAreaAttrs method dynamic VisSplineClass, MSG_SPLINE_GET_AREA_ATTRS uses ax,cx,dx,bp .enter call SplineMethodCommonReadOnly mov si, es:[bp].VSI_areaAttr mov si, ds:[si] push es mov es, cx mov di, dx mov cx, size AreaAttr rep movsb pop es call SplineEndmCommon .leave ret SplineGetAreaAttrs endm COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SplineSetLineStyle %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DESCRIPTION: Set the line style PASS: *ds:si = VisSplineClass instance data. ds:di = *ds:si ds:bx = instance data of superclass es = Segment of VisSplineClass class record ax = Method number. cl = Line Style RETURN: nothing DESTROYED: Nada. REGISTER/STACK USAGE: PSEUDO CODE/STRATEGY: KNOWN BUGS/SIDE EFFECTS/CAVEATS/IDEAS: REVISION HISTORY: Name Date Description ---- ---- ----------- CDB 6/17/91 Initial version. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ SplineSetLineStyle method dynamic VisSplineClass, \ MSG_SPLINE_SET_LINE_STYLE uses ax, cx, dx, bp .enter push cx, dx mov ax, UT_LINE_ATTR mov bx, offset VSI_lineAttr mov cx, size LA_style mov dx, offset LA_style call SplineSetAttrCommon .leave ret SplineSetLineStyle endm COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SplineSetLineMask %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DESCRIPTION: Set the line mask PASS: *ds:si = VisSplineClass object ds:di = VisSplineClass instance data es = Segment of VisSplineClass. RETURN: DESTROYED: nothing REGISTER/STACK USAGE: PSEUDO CODE/STRATEGY: KNOWN BUGS/SIDE EFFECTS/CAVEATS/IDEAS: REVISION HISTORY: Name Date Description ---- ---- ----------- CDB 5/22/92 Initial version. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ SplineSetLineMask method dynamic VisSplineClass, MSG_SPLINE_SET_LINE_MASK uses ax,cx,dx,bp .enter push cx, dx mov ax, UT_LINE_ATTR mov bx, offset VSI_lineAttr mov cx, size LA_mask mov dx, offset LA_mask call SplineSetAttrCommon .leave ret SplineSetLineMask endm COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SplineGetLineMask %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DESCRIPTION: PASS: *ds:si = VisSplineClass object ds:di = VisSplineClass instance data es = Segment of VisSplineClass. RETURN: DESTROYED: nothing REGISTER/STACK USAGE: PSEUDO CODE/STRATEGY: KNOWN BUGS/SIDE EFFECTS/CAVEATS/IDEAS: REVISION HISTORY: Name Date Description ---- ---- ----------- CDB 5/22/92 Initial version. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ SplineGetLineMask method dynamic VisSplineClass, MSG_SPLINE_GET_LINE_MASK mov bx, offset VSI_lineAttr mov cx, offset LA_mask mov dx, size LA_mask GOTO SplineGetAttrCommon SplineGetLineMask endm COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SplineGetLineStyle %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DESCRIPTION: Return the spline's current line style PASS: *ds:si = VisSplineClass object ds:di = VisSplineClass instance data es = Segment of VisSplineClass. ax = Method. RETURN: cl = line style DESTROYED: dx REGISTER/STACK USAGE: PSEUDO CODE/STRATEGY: KNOWN BUGS/SIDE EFFECTS/CAVEATS/IDEAS: REVISION HISTORY: Name Date Description ---- ---- ----------- CDB 10/15/91 Initial version. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ SplineGetLineStyle method dynamic VisSplineClass, MSG_SPLINE_GET_LINE_STYLE mov bx, offset VSI_lineAttr mov cx, offset LA_style mov dx, size LA_style GOTO SplineGetAttrCommon SplineGetLineStyle endm COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SplineSetLineColor %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DESCRIPTION: Set the line color of the spline object PASS: *ds:si = VisSplineClass instance data. ds:di = *ds:si ds:bx = instance data of superclass es = Segment of VisSplineClass class record ax = Method number. cx, dx = color values (see GrSetLineColor for description). RETURN: nothing DESTROYED: Nada. REGISTER/STACK USAGE: Standard dynamic register file. PSEUDO CODE/STRATEGY: KNOWN BUGS/SIDE EFFECTS/CAVEATS/IDEAS: REVISION HISTORY: Name Date Description ---- ---- ----------- CDB 6/17/91 Initial version. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ SplineSetLineColor method dynamic VisSplineClass, MSG_SPLINE_SET_LINE_COLOR uses ax, cx, dx, bp .enter push cx, dx mov ax, UT_LINE_ATTR mov bx, offset VSI_lineAttr mov cx, size LA_color mov dx, offset LA_color call SplineSetAttrCommon .leave ret SplineSetLineColor endm COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SplineGetLineColor %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DESCRIPTION: returns the line color PASS: *ds:si = VisSpline`Class object ds:di = VisSpline`Class instance data es = Segment of VisSpline`Class. ax = Method. RETURN: DESTROYED: REGISTER/STACK USAGE: PSEUDO CODE/STRATEGY: KNOWN BUGS/SIDE EFFECTS/CAVEATS/IDEAS: REVISION HISTORY: Name Date Description ---- ---- ----------- CDB 10/15/91 Initial version. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ SplineGetLineColor method dynamic VisSplineClass, MSG_SPLINE_GET_LINE_COLOR mov bx, offset VSI_lineAttr mov cx, offset LA_color mov dx, size LA_color GOTO SplineGetAttrCommon SplineGetLineColor endm COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SplineSetAreaColor %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DESCRIPTION: Set the area color PASS: *ds:si = VisSplineClass instance data. ds:di = *ds:si ds:bx = instance data of superclass es = Segment of VisSplineClass class record ax = Method number. ch = ColorFlag cl, dh, dl - color values (see GrSetAreaColor for more info). RETURN: nothing DESTROYED: Nada. REGISTER/STACK USAGE: Standard dynamic register file. PSEUDO CODE/STRATEGY: KNOWN BUGS/SIDE EFFECTS/CAVEATS/IDEAS: ??? REVISION HISTORY: Name Date Description ---- ---- ----------- CDB 6/17/91 Initial version. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ SplineSetAreaColor method dynamic VisSplineClass, \ MSG_SPLINE_SET_AREA_COLOR uses bp .enter push cx, dx mov ax, UT_AREA_ATTR mov bx, offset VSI_areaAttr mov cx, size AA_color mov dx, offset AA_color call SplineSetAttrCommon .leave ret SplineSetAreaColor endm COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SplineGetAreaColor %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DESCRIPTION: Return the spline's area color PASS: *ds:si = VisSplineClass object ds:di = VisSplineClass instance data es = Segment of VisSplineClass. ax = Method. RETURN: cx = area color DESTROYED: dx REGISTER/STACK USAGE: PSEUDO CODE/STRATEGY: KNOWN BUGS/SIDE EFFECTS/CAVEATS/IDEAS: REVISION HISTORY: Name Date Description ---- ---- ----------- CDB 10/15/91 Initial version. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ SplineGetAreaColor method dynamic VisSplineClass, MSG_SPLINE_GET_AREA_COLOR mov bx, offset VSI_areaAttr mov cx, offset AA_color mov dx, size AA_color GOTO SplineGetAttrCommon SplineGetAreaColor endm COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SplineSetAreaMask %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DESCRIPTION: Set the mask for the area-fill routine. PASS: *ds:si = VisSplineClass instance data. ds:di = *ds:si ds:bx = instance data of superclass es = Segment of VisSplineClass class record ax = Method number. cl - area fill mask RETURN: nothing DESTROYED: Nada. REGISTER/STACK USAGE: Standard dynamic register file. PSEUDO CODE/STRATEGY: KNOWN BUGS/SIDE EFFECTS/CAVEATS/IDEAS: REVISION HISTORY: Name Date Description ---- ---- ----------- CDB 6/17/91 Initial version. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ SplineSetAreaMask method dynamic VisSplineClass, MSG_SPLINE_SET_AREA_MASK uses ax, bp .enter push cx, dx mov ax, UT_AREA_ATTR mov bx, offset VSI_areaAttr mov cx, size AA_mask mov dx, offset AA_mask call SplineSetAttrCommon .leave ret SplineSetAreaMask endm COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SplineSetAttrCommon %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: CALLED BY: SplineSetLineWidth, etc, etc, etc,. PASS: ax - UndoType (UT_LINE_ATTR or UT_AREA_ATTR) bx - offset in instance data to chunk handle of attribute chunk cx - size of attribute data (1, 2 or 4 bytes) dx - offset into attribute chunk to attribute field ON STACK: dataCX ; words of data to store dataDX RETURN: nothing DESTROYED: ax,bx,cx,dx,si,di,bp PSEUDO CODE/STRATEGY: KNOWN BUGS/SIDE EFFECTS/IDEAS: REVISION HISTORY: Name Date Description ---- ---- ----------- CDB 11/ 7/91 Initial version. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ SplineSetAttrCommon proc near \ dataDX:word, dataCX:word ; (pushed first) class VisSplineClass .enter test ds:[di].VSI_state, mask SS_HAS_ATTR_CHUNKS jz realExit ; save stack frame and offset into instance data push bp, bx call SplineMethodCommon pop di, bx ; stack frame, offset call SplineInitUndo ; undo type in AL EC < call ECSplineAttrChunks > xchg di, bp ; di <= instance data, ; bp <= stack frame mov bx, es:[bx][di] ; attr chunk handle EC < tst bx > EC < ERROR_Z SPLINE_HAS_NO_ATTR_CHUNKS > mov bx, ds:[bx] ; deref attr chunk EC < xchg bx, si > EC < call ECCheckLMemChunk > EC < xchg bx, si > push es, di ; instance ptr segmov es, ds, di mov di, bx add di, dx ; es:di - offset into attr chunk mov ax, dataCX stosb dec cx jz done mov al, ah stosb dec cx jz done mov ax, dataDX stosb dec cx jz done mov al, ah stosb done: pop es, bp ; es:bp - instance ptr call SplineInvalidate call SplineEndmCommon realExit: .leave ret @ArgSize SplineSetAttrCommon endp COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SplineGetAreaMask %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DESCRIPTION: Return the spline's area mask PASS: *ds:si = VisSplineClass object ds:di = VisSplineClass instance data es = Segment of VisSplineClass. ax = Method. RETURN: cx = area mask DESTROYED: dx REGISTER/STACK USAGE: PSEUDO CODE/STRATEGY: KNOWN BUGS/SIDE EFFECTS/CAVEATS/IDEAS: REVISION HISTORY: Name Date Description ---- ---- ----------- CDB 10/15/91 Initial version. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ SplineGetAreaMask method dynamic VisSplineClass, MSG_SPLINE_GET_AREA_MASK mov bx, offset VSI_areaAttr mov cx, offset AA_mask mov dx, size AA_mask GOTO SplineGetAttrCommon SplineGetAreaMask endm COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SplineGetAttrCommon %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SYNOPSIS: Retrieve the attribute CALLED BY: SplineGet... PASS: bx - offset into VSI data wherein the pointer to the attribute resides cx - offset into the attribute chunk for the desired attribute. dx - size of the attribute: 1-4 bytes RETURN: (depending on DX passed) cl, cx, or DX:CX as the RETURN value (if dword, DX is the HIGH word) DESTROYED: bx, di dx (if not returned) PSEUDO CODE/STRATEGY: KNOWN BUGS/SIDE EFFECTS/IDEAS: REVISION HISTORY: Name Date Description ---- ---- ----------- CDB 10/15/91 Initial version. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@ SplineGetAttrCommon proc far uses bp class VisSplineClass .enter test ds:[di].VSI_state, mask SS_HAS_ATTR_CHUNKS jz noChunks call SplineMethodCommonReadOnly mov di, bx ; offset to lptr in ; instance data. mov di, es:[bp][di] mov di, ds:[di] add di, cx ; now, ds:di points to the desired ; attribute. cmp dx, 1 je movByte ; Move a dword even if only one word is needed (it's faster than ; checking!) movdw dxcx, ds:[di] done: call SplineEndmCommon realExit: .leave ret movByte: mov cl, {byte} ds:[di] jmp done noChunks: clrdw cxdx jmp realExit SplineGetAttrCommon endp SplineAttrCode ends
/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "networkrequest.h" #include "captiveportal/captiveportal.h" #include "constants.h" #include "hawkauth.h" #include "leakdetector.h" #include "logger.h" #include "mozillavpn.h" #include "networkmanager.h" #include "settingsholder.h" #include "task.h" #include <QDirIterator> #include <QHostAddress> #include <QJsonDocument> #include <QJsonArray> #include <QJsonObject> #include <QNetworkAccessManager> #include <QNetworkReply> #include <QNetworkRequest> #include <QRegularExpression> #include <QUrl> // Timeout for the network requests. constexpr uint32_t REQUEST_TIMEOUT_MSEC = 15000; constexpr int REQUEST_MAX_REDIRECTS = 4; constexpr const char* IPINFO_URL_IPV4 = "https://%1/api/v1/vpn/ipinfo"; constexpr const char* IPINFO_URL_IPV6 = "https://[%1]/api/v1/vpn/ipinfo"; namespace { Logger logger(LOG_NETWORKING, "NetworkRequest"); QList<QSslCertificate> s_intervention_certs; } // namespace NetworkRequest::NetworkRequest(Task* parent, int status, bool setAuthorizationHeader) : QObject(parent), m_status(status) { MVPN_COUNT_CTOR(NetworkRequest); logger.debug() << "Network request created by" << parent->name(); #ifndef MVPN_WASM m_request.setRawHeader("User-Agent", NetworkManager::userAgent()); #endif m_request.setMaximumRedirectsAllowed(REQUEST_MAX_REDIRECTS); m_request.setAttribute(QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::SameOriginRedirectPolicy); // Let's use "glean-enabled" as an indicator for DNT/GPC too. if (!SettingsHolder::instance()->gleanEnabled()) { // Do-Not-Track: // https://datatracker.ietf.org/doc/html/draft-mayer-do-not-track-00 m_request.setRawHeader("DNT", "1"); // Global Privacy Control: https://globalprivacycontrol.github.io/gpc-spec/ m_request.setRawHeader("Sec-GPC", "1"); } m_request.setOriginatingObject(parent); if (setAuthorizationHeader) { QByteArray authorizationHeader = "Bearer "; authorizationHeader.append( SettingsHolder::instance()->token().toLocal8Bit()); m_request.setRawHeader("Authorization", authorizationHeader); } m_timer.setSingleShot(true); connect(&m_timer, &QTimer::timeout, this, &NetworkRequest::timeout); connect(&m_timer, &QTimer::timeout, this, &NetworkRequest::maybeDeleteLater); NetworkManager::instance()->increaseNetworkRequestCount(); enableSSLIntervention(); } NetworkRequest::~NetworkRequest() { MVPN_COUNT_DTOR(NetworkRequest); // During the shutdown, the QML NetworkManager can be released before the // deletion of the pending network requests. if (NetworkManager::exists()) { NetworkManager::instance()->decreaseNetworkRequestCount(); } } // static QString NetworkRequest::apiBaseUrl() { if (Constants::inProduction()) { return Constants::API_PRODUCTION_URL; } return Constants::getStagingServerAddress(); } // static NetworkRequest* NetworkRequest::createForGetUrl(Task* parent, const QString& url, int status) { Q_ASSERT(parent); NetworkRequest* r = new NetworkRequest(parent, status, false); r->m_request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); r->m_request.setAttribute(QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::NoLessSafeRedirectPolicy); r->m_request.setUrl(url); r->getRequest(); return r; } NetworkRequest* NetworkRequest::createForGetHostAddress( Task* parent, const QString& url, const QHostAddress& address) { Q_ASSERT(parent); QUrl requestUrl(url); QString hostname = requestUrl.host(); NetworkRequest* r = new NetworkRequest(parent, 200, false); r->m_request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); r->m_request.setAttribute(QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::NoLessSafeRedirectPolicy); // Rewrite the request URL to use an explicit host address. if (address.protocol() == QAbstractSocket::IPv6Protocol) { requestUrl.setHost("[" + address.toString() + "]"); } else { requestUrl.setHost(address.toString()); } r->m_request.setUrl(requestUrl); r->m_request.setRawHeader("Host", hostname.toLocal8Bit()); r->m_request.setPeerVerifyName(hostname); r->getRequest(); return r; } // static NetworkRequest* NetworkRequest::createForAuthenticationVerification( Task* parent, const QString& pkceCodeSuccess, const QString& pkceCodeVerifier) { Q_ASSERT(parent); NetworkRequest* r = new NetworkRequest(parent, 200, false); r->m_request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); QUrl url(apiBaseUrl()); url.setPath("/api/v2/vpn/login/verify"); r->m_request.setUrl(url); QJsonObject obj; obj.insert("code", pkceCodeSuccess); obj.insert("code_verifier", pkceCodeVerifier); QJsonDocument json; json.setObject(obj); r->postRequest(json.toJson(QJsonDocument::Compact)); return r; } // static NetworkRequest* NetworkRequest::createForAdjustProxy( Task* parent, const QString& method, const QString& path, const QList<QPair<QString, QString>>& headers, const QString& queryParameters, const QString& bodyParameters, const QList<QString>& unknownParameters) { Q_ASSERT(parent); NetworkRequest* r = new NetworkRequest(parent, 200, false); r->m_request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); QUrl url(apiBaseUrl()); url.setPath("/api/v1/vpn/adjust"); r->m_request.setUrl(url); QJsonObject headersObj; for (QPair<QString, QString> header : headers) { headersObj.insert(header.first, header.second); } QJsonObject obj; obj.insert("method", method); obj.insert("path", path); obj.insert("headers", headersObj); obj.insert("queryParameters", queryParameters); obj.insert("bodyParameters", bodyParameters); QJsonArray unknownParametersArray; for (QString unknownParameter : unknownParameters) { unknownParametersArray.append(unknownParameter); } obj.insert("unknownParameters", unknownParametersArray); QJsonDocument json(obj); r->postRequest(json.toJson(QJsonDocument::Compact)); return r; } // static NetworkRequest* NetworkRequest::createForDeviceCreation( Task* parent, const QString& deviceName, const QString& pubKey, const QString& deviceId) { Q_ASSERT(parent); NetworkRequest* r = new NetworkRequest(parent, 201, true); r->m_request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); QUrl url(apiBaseUrl()); url.setPath("/api/v1/vpn/device"); r->m_request.setUrl(url); QJsonObject obj; obj.insert("name", deviceName); obj.insert("unique_id", deviceId); obj.insert("pubkey", pubKey); QJsonDocument json; json.setObject(obj); r->postRequest(json.toJson(QJsonDocument::Compact)); return r; } // static NetworkRequest* NetworkRequest::createForDeviceRemoval(Task* parent, const QString& pubKey) { Q_ASSERT(parent); NetworkRequest* r = new NetworkRequest(parent, 204, true); QString url(apiBaseUrl()); url.append("/api/v1/vpn/device/"); url.append(QUrl::toPercentEncoding(pubKey)); QUrl u(url); r->m_request.setUrl(QUrl(url)); #ifdef MVPN_DEBUG logger.debug() << "Network starting" << r->m_request.url().toString(); #endif r->deleteRequest(); return r; } NetworkRequest* NetworkRequest::createForServers(Task* parent) { Q_ASSERT(parent); NetworkRequest* r = new NetworkRequest(parent, 200, true); QUrl url(apiBaseUrl()); url.setPath("/api/v1/vpn/servers"); r->m_request.setUrl(url); r->getRequest(); return r; } NetworkRequest* NetworkRequest::createForSurveyData(Task* parent) { Q_ASSERT(parent); NetworkRequest* r = new NetworkRequest(parent, 200, true); QUrl url(apiBaseUrl()); url.setPath("/api/v1/vpn/surveys"); r->m_request.setUrl(url); r->getRequest(); return r; } NetworkRequest* NetworkRequest::createForVersions(Task* parent) { Q_ASSERT(parent); NetworkRequest* r = new NetworkRequest(parent, 200, false); QUrl url(apiBaseUrl()); url.setPath("/api/v1/vpn/versions"); r->m_request.setUrl(url); r->getRequest(); return r; } NetworkRequest* NetworkRequest::createForAccount(Task* parent) { Q_ASSERT(parent); NetworkRequest* r = new NetworkRequest(parent, 200, true); QUrl url(apiBaseUrl()); url.setPath("/api/v1/vpn/account"); r->m_request.setUrl(url); r->getRequest(); return r; } NetworkRequest* NetworkRequest::createForIpInfo(Task* parent, const QHostAddress& address) { Q_ASSERT(parent); NetworkRequest* r = new NetworkRequest(parent, 200, true); if (address.protocol() == QAbstractSocket::IPv6Protocol) { r->m_request.setUrl(QUrl(QString(IPINFO_URL_IPV6).arg(address.toString()))); } else { Q_ASSERT(address.protocol() == QAbstractSocket::IPv4Protocol); r->m_request.setUrl(QUrl(QString(IPINFO_URL_IPV4).arg(address.toString()))); } QUrl url(apiBaseUrl()); r->m_request.setRawHeader("Host", url.host().toLocal8Bit()); r->m_request.setPeerVerifyName(url.host()); r->getRequest(); return r; } NetworkRequest* NetworkRequest::createForCaptivePortalDetection( Task* parent, const QUrl& url, const QByteArray& host) { Q_ASSERT(parent); NetworkRequest* r = new NetworkRequest(parent, 0, false); r->m_request.setUrl(url); r->m_request.setRawHeader("Host", host); r->m_request.setPeerVerifyName(host); // This enables the QNetworkReply::redirected for every type of redirect. r->m_request.setAttribute(QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::UserVerifiedRedirectPolicy); r->getRequest(); return r; } NetworkRequest* NetworkRequest::createForCaptivePortalLookup(Task* parent) { NetworkRequest* r = new NetworkRequest(parent, 200, true); QUrl url(apiBaseUrl()); url.setPath("/api/v1/vpn/dns/detectportal"); r->m_request.setUrl(url); r->getRequest(); return r; } NetworkRequest* NetworkRequest::createForHeartbeat(Task* parent) { NetworkRequest* r = new NetworkRequest(parent, 200, false); QUrl url(apiBaseUrl()); url.setPath("/__heartbeat__"); r->m_request.setUrl(url); r->getRequest(); return r; } NetworkRequest* NetworkRequest::createForFeedback(Task* parent, const QString& feedbackText, const QString& logs, const qint8 rating, const QString& category) { NetworkRequest* r = new NetworkRequest(parent, 201, true); QUrl url(apiBaseUrl()); url.setPath("/api/v1/vpn/feedback"); r->m_request.setUrl(url); r->m_request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); QJsonObject obj; obj.insert("feedbackText", feedbackText); obj.insert("logs", logs); obj.insert("versionString", MozillaVPN::instance()->versionString()); obj.insert("platformVersion", QString(NetworkManager::osVersion())); obj.insert("rating", rating); obj.insert("category", category); QJsonDocument json; json.setObject(obj); r->postRequest(json.toJson(QJsonDocument::Compact)); return r; } NetworkRequest* NetworkRequest::createForSupportTicket( Task* parent, const QString& email, const QString& subject, const QString& issueText, const QString& logs, const QString& category) { bool isAuthenticated = MozillaVPN::instance()->userState() == MozillaVPN::UserAuthenticated; NetworkRequest* r = new NetworkRequest(parent, 201, isAuthenticated); QUrl url(apiBaseUrl()); if (isAuthenticated) { url.setPath("/api/v1/vpn/createSupportTicket"); } else { url.setPath("/api/v1/vpn/createGuestSupportTicket"); } r->m_request.setUrl(url); r->m_request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); QJsonObject obj; obj.insert("email", email); obj.insert("logs", logs); obj.insert("versionString", MozillaVPN::instance()->versionString()); obj.insert("platformVersion", QString(NetworkManager::osVersion())); obj.insert("subject", subject); obj.insert("issueText", issueText); obj.insert("category", category); QJsonDocument json; json.setObject(obj); r->postRequest(json.toJson(QJsonDocument::Compact)); return r; } // static NetworkRequest* NetworkRequest::createForGetFeatureList(Task* parent) { NetworkRequest* r = new NetworkRequest(parent, 200, false); QUrl url(apiBaseUrl()); url.setPath("/api/v1/vpn/featurelist"); r->m_request.setUrl(url); r->getRequest(); return r; } // static NetworkRequest* NetworkRequest::createForFxaAccountStatus( Task* parent, const QString& emailAddress) { Q_ASSERT(parent); NetworkRequest* r = new NetworkRequest(parent, 200, false); r->m_request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); QUrl url(Constants::fxaApiBaseUrl()); url.setPath("/v1/account/status"); r->m_request.setUrl(url); QJsonObject obj; obj.insert("email", emailAddress); QJsonDocument json; json.setObject(obj); r->postRequest(json.toJson(QJsonDocument::Compact)); return r; } // static NetworkRequest* NetworkRequest::createForFxaAccountCreation( Task* parent, const QString& email, const QByteArray& authpw, const QString& fxaClientId, const QString& fxaDeviceId, const QString& fxaFlowId, double fxaFlowBeginTime) { NetworkRequest* r = new NetworkRequest(parent, 200, false); QUrl url(Constants::fxaApiBaseUrl()); url.setPath("/v1/account/create"); r->m_request.setUrl(url); r->m_request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); QJsonObject obj; obj.insert("email", email); obj.insert("authPW", QString(authpw.toHex())); obj.insert("service", fxaClientId); obj.insert("verificationMethod", "email-otp"); QJsonObject metrics; metrics.insert("deviceId", fxaDeviceId); metrics.insert("flowId", fxaFlowId); metrics.insert("flowBeginTime", fxaFlowBeginTime); obj.insert("metricsContext", metrics); QJsonDocument json; json.setObject(obj); r->postRequest(json.toJson(QJsonDocument::Compact)); return r; } // static NetworkRequest* NetworkRequest::createForFxaLogin( Task* parent, const QString& email, const QByteArray& authpw, const QString& unblockCode, const QString& fxaClientId, const QString& fxaDeviceId, const QString& fxaFlowId, double fxaFlowBeginTime) { NetworkRequest* r = new NetworkRequest(parent, 200, false); QUrl url(Constants::fxaApiBaseUrl()); url.setPath("/v1/account/login"); r->m_request.setUrl(url); r->m_request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); QJsonObject obj; obj.insert("email", email); obj.insert("authPW", QString(authpw.toHex())); obj.insert("reason", "signin"); obj.insert("service", fxaClientId); obj.insert("skipErrorCase", true); obj.insert("verificationMethod", "email-otp"); if (!unblockCode.isEmpty()) { obj.insert("unblockCode", unblockCode); } QJsonObject metrics; metrics.insert("deviceId", fxaDeviceId); metrics.insert("flowId", fxaFlowId); metrics.insert("flowBeginTime", fxaFlowBeginTime); obj.insert("metricsContext", metrics); QJsonDocument json; json.setObject(obj); r->postRequest(json.toJson(QJsonDocument::Compact)); return r; } // static NetworkRequest* NetworkRequest::createForFxaSendUnblockCode( Task* parent, const QString& emailAddress) { Q_ASSERT(parent); NetworkRequest* r = new NetworkRequest(parent, 200, false); r->m_request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); QUrl url(Constants::fxaApiBaseUrl()); url.setPath("/v1/account/login/send_unblock_code"); r->m_request.setUrl(url); QJsonObject obj; obj.insert("email", emailAddress); QJsonDocument json; json.setObject(obj); r->postRequest(json.toJson(QJsonDocument::Compact)); return r; } // static NetworkRequest* NetworkRequest::createForFxaSessionVerifyByEmailCode( Task* parent, const QByteArray& sessionToken, const QString& code, const QString& fxaClientId, const QString& fxaScope) { NetworkRequest* r = new NetworkRequest(parent, 200, false); QUrl url(Constants::fxaApiBaseUrl()); url.setPath("/v1/session/verify_code"); r->m_request.setUrl(url); r->m_request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); QJsonObject obj; obj.insert("code", code); obj.insert("service", fxaClientId); QJsonArray scopes; QStringList queryScopes = fxaScope.split(" "); foreach (const QString& s, queryScopes) { QString parsedScope; if (s.startsWith("http")) { parsedScope = QUrl::fromPercentEncoding(s.toUtf8()); } else { parsedScope = s; } scopes.append(parsedScope); } obj.insert("scopes", scopes); QByteArray payload = QJsonDocument(obj).toJson(QJsonDocument::Compact); HawkAuth hawk = HawkAuth(sessionToken); QByteArray hawkHeader = hawk.generate(r->m_request, "POST", payload).toUtf8(); r->m_request.setRawHeader("Authorization", hawkHeader); r->postRequest(payload); return r; } // static NetworkRequest* NetworkRequest::createForFxaSessionResendCode( Task* parent, const QByteArray& sessionToken) { NetworkRequest* r = new NetworkRequest(parent, 200, false); QUrl url(Constants::fxaApiBaseUrl()); url.setPath("/v1/session/resend_code"); r->m_request.setUrl(url); r->m_request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); QByteArray payload = QJsonDocument(QJsonObject()).toJson(QJsonDocument::Compact); HawkAuth hawk = HawkAuth(sessionToken); QByteArray hawkHeader = hawk.generate(r->m_request, "POST", payload).toUtf8(); r->m_request.setRawHeader("Authorization", hawkHeader); r->postRequest(payload); return r; } // static NetworkRequest* NetworkRequest::createForFxaSessionVerifyByTotpCode( Task* parent, const QByteArray& sessionToken, const QString& code, const QString& fxaClientId, const QString& fxaScope) { NetworkRequest* r = new NetworkRequest(parent, 200, false); QUrl url(Constants::fxaApiBaseUrl()); url.setPath("/v1/session/verify/totp"); r->m_request.setUrl(url); r->m_request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); QJsonObject obj; obj.insert("code", code); obj.insert("service", fxaClientId); QJsonArray scopes; scopes.append(fxaScope); obj.insert("scopes", scopes); QByteArray payload = QJsonDocument(obj).toJson(QJsonDocument::Compact); HawkAuth hawk = HawkAuth(sessionToken); QByteArray hawkHeader = hawk.generate(r->m_request, "POST", payload).toUtf8(); r->m_request.setRawHeader("Authorization", hawkHeader); r->postRequest(payload); return r; } // static NetworkRequest* NetworkRequest::createForFxaAuthz( Task* parent, const QByteArray& sessionToken, const QString& fxaClientId, const QString& fxaState, const QString& fxaScope, const QString& fxaAccessType) { NetworkRequest* r = new NetworkRequest(parent, 200, false); QUrl url(Constants::fxaApiBaseUrl()); url.setPath("/v1/oauth/authorization"); r->m_request.setUrl(url); r->m_request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); QJsonObject obj; obj.insert("client_id", fxaClientId); obj.insert("state", fxaState); obj.insert("scope", fxaScope); obj.insert("access_type", fxaAccessType); QByteArray payload = QJsonDocument(obj).toJson(QJsonDocument::Compact); HawkAuth hawk = HawkAuth(sessionToken); QByteArray hawkHeader = hawk.generate(r->m_request, "POST", payload).toUtf8(); r->m_request.setRawHeader("Authorization", hawkHeader); r->postRequest(payload); return r; } #ifdef UNIT_TEST // static NetworkRequest* NetworkRequest::createForFxaTotpCreation( Task* parent, const QByteArray& sessionToken) { NetworkRequest* r = new NetworkRequest(parent, 200, false); QUrl url(Constants::fxaApiBaseUrl()); url.setPath("/v1/totp/create"); r->m_request.setUrl(url); r->m_request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); QByteArray payload = "{}"; HawkAuth hawk = HawkAuth(sessionToken); QByteArray hawkHeader = hawk.generate(r->m_request, "POST", payload).toUtf8(); r->m_request.setRawHeader("Authorization", hawkHeader); r->postRequest(payload); return r; } #endif // static NetworkRequest* NetworkRequest::createForFxaAttachedClients( Task* parent, const QByteArray& sessionToken) { NetworkRequest* r = new NetworkRequest(parent, 200, false); QUrl url(Constants::fxaApiBaseUrl()); url.setPath("/v1/account/attached_clients"); r->m_request.setUrl(url); r->m_request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); HawkAuth hawk = HawkAuth(sessionToken); QByteArray hawkHeader = hawk.generate(r->m_request, "GET", "").toUtf8(); r->m_request.setRawHeader("Authorization", hawkHeader); r->getRequest(); return r; } // static NetworkRequest* NetworkRequest::createForFxaAccountDeletion( Task* parent, const QByteArray& sessionToken, const QString& emailAddress, const QByteArray& authpw) { NetworkRequest* r = new NetworkRequest(parent, 200, false); QUrl url(Constants::fxaApiBaseUrl()); url.setPath("/v1/account/destroy"); r->m_request.setUrl(url); r->m_request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); QJsonObject obj; obj.insert("email", emailAddress); obj.insert("authPW", QString(authpw.toHex())); QByteArray payload = QJsonDocument(obj).toJson(QJsonDocument::Compact); HawkAuth hawk = HawkAuth(sessionToken); QByteArray hawkHeader = hawk.generate(r->m_request, "POST", payload).toUtf8(); r->m_request.setRawHeader("Authorization", hawkHeader); r->postRequest(payload); return r; } // static NetworkRequest* NetworkRequest::createForFxaSessionDestroy( Task* parent, const QByteArray& sessionToken) { NetworkRequest* r = new NetworkRequest(parent, 200, false); QUrl url(Constants::fxaApiBaseUrl()); url.setPath("/v1/session/destroy"); r->m_request.setUrl(url); r->m_request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); QByteArray payload = QJsonDocument(QJsonObject()).toJson(QJsonDocument::Compact); HawkAuth hawk = HawkAuth(sessionToken); QByteArray hawkHeader = hawk.generate(r->m_request, "POST", payload).toUtf8(); r->m_request.setRawHeader("Authorization", hawkHeader); r->postRequest(payload); return r; } NetworkRequest* NetworkRequest::createForProducts(Task* parent) { Q_ASSERT(parent); NetworkRequest* r = new NetworkRequest(parent, 200, true); QUrl url(apiBaseUrl()); url.setPath("/api/v3/vpn/products"); r->m_request.setUrl(url); r->getRequest(); return r; } #ifdef MVPN_IOS NetworkRequest* NetworkRequest::createForIOSPurchase(Task* parent, const QString& receipt) { Q_ASSERT(parent); NetworkRequest* r = new NetworkRequest(parent, 201, true); r->m_request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); QUrl url(apiBaseUrl()); url.setPath("/api/v1/vpn/purchases/ios"); r->m_request.setUrl(url); QJsonObject obj; obj.insert("receipt", QJsonValue(receipt)); obj.insert("appId", "org.mozilla.ios.FirefoxVPN"); QJsonDocument json; json.setObject(obj); r->postRequest(json.toJson(QJsonDocument::Compact)); return r; } #endif #ifdef MVPN_ANDROID NetworkRequest* NetworkRequest::createForAndroidPurchase( Task* parent, const QString& sku, const QString& purchaseToken) { Q_ASSERT(parent); NetworkRequest* r = new NetworkRequest(parent, 200, true); r->m_request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); QUrl url(apiBaseUrl()); url.setPath("/api/v1/vpn/purchases/android"); r->m_request.setUrl(url); QJsonObject obj; obj.insert("sku", sku); obj.insert("token", purchaseToken); QJsonDocument json; json.setObject(obj); logger.debug() << "Network request createForAndroidPurchase created" << logger.sensitive(json.toJson(QJsonDocument::Compact)); r->postRequest(json.toJson(QJsonDocument::Compact)); return r; } #endif void NetworkRequest::replyFinished() { Q_ASSERT(m_reply); Q_ASSERT(m_reply->isFinished()); if (m_completed) { Q_ASSERT(!m_timer.isActive()); return; } #if QT_VERSION >= 0x060000 && QT_VERSION < 0x060400 if (m_reply->error() == QNetworkReply::HostNotFoundError && isRedirect()) { QUrl brokenUrl = m_reply->url(); if (brokenUrl.host().isEmpty() && !m_redirectedUrl.isEmpty()) { QUrl url = m_redirectedUrl.resolved(brokenUrl); # ifdef MVPN_DEBUG // See https://bugreports.qt.io/browse/QTBUG-100651 logger.debug() << "QT6 redirect bug! The current URL is broken because it's not " "resolved using the latest HTTP redirection as base-URL"; logger.debug() << "Broken URL:" << brokenUrl.toString(); logger.debug() << "Latest redirected URL:" << m_redirectedUrl.toString(); logger.debug() << "Final URL:" << url.toString(); # endif m_request = QNetworkRequest(url); m_request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); m_request.setAttribute(QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::NoLessSafeRedirectPolicy); m_reply = nullptr; m_timer.stop(); getRequest(); return; } } #endif m_completed = true; m_timer.stop(); int status = statusCode(); QString expect = m_status ? QString::number(m_status) : "any"; logger.debug() << "Network reply received - status:" << status << "- expected:" << expect; QByteArray data = m_reply->readAll(); if (m_reply->error() != QNetworkReply::NoError) { QUrl::FormattingOptions options = QUrl::RemoveQuery | QUrl::RemoveUserInfo; logger.error() << "Network error:" << m_reply->errorString() << "status code:" << status << "- body:" << data; logger.error() << "Failed to access:" << m_request.url().toString(options); emit requestFailed(m_reply->error(), data); return; } // This is an extra check for succeeded requests (status code 200 vs 201, for // instance). The real network status check is done in the previous if-stmt. if (m_status && status != m_status) { logger.error() << "Status code unexpected - status code:" << status << "- expected:" << m_status; emit requestFailed(QNetworkReply::ConnectionRefusedError, data); return; } emit requestCompleted(data); } bool NetworkRequest::isRedirect() const { int status = statusCode(); return status >= 300 && status < 400; } void NetworkRequest::handleHeaderReceived() { // Suppress this signal if a redirect is about to happen. int policy = m_request.attribute(QNetworkRequest::RedirectPolicyAttribute).toInt(); if (isRedirect() && (policy != QNetworkRequest::ManualRedirectPolicy)) { return; } logger.debug() << "Network header received"; emit requestHeaderReceived(this); } void NetworkRequest::handleRedirect(const QUrl& redirectUrl) { #if QT_VERSION >= 0x060000 && QT_VERSION < 0x060400 if (redirectUrl.host().isEmpty()) { # ifdef MVPN_DEBUG // See https://bugreports.qt.io/browse/QTBUG-100651 logger.debug() << "QT6 redirect bug! The redirected URL is broken because it's not " "resolved using the previous HTTP redirection as base-URL"; logger.debug() << "Broken URL:" << redirectUrl.toString(); logger.debug() << "Latest redirected URL:" << m_redirectedUrl.toString(); # endif if (m_redirectedUrl.isEmpty()) { m_redirectedUrl = url().resolved(redirectUrl); } else { m_redirectedUrl = m_redirectedUrl.resolved(redirectUrl); } } else { m_redirectedUrl = redirectUrl; } emit requestRedirected(this, m_redirectedUrl); #else emit requestRedirected(this, redirectUrl); #endif } void NetworkRequest::timeout() { Q_ASSERT(m_reply); Q_ASSERT(!m_reply->isFinished()); Q_ASSERT(!m_completed); m_completed = true; m_reply->abort(); logger.error() << "Network request timeout"; emit requestFailed(QNetworkReply::TimeoutError, QByteArray()); } void NetworkRequest::getRequest() { QNetworkAccessManager* manager = NetworkManager::instance()->networkAccessManager(); handleReply(manager->get(m_request)); m_timer.start(REQUEST_TIMEOUT_MSEC); } void NetworkRequest::deleteRequest() { QNetworkAccessManager* manager = NetworkManager::instance()->networkAccessManager(); handleReply(manager->sendCustomRequest(m_request, "DELETE")); m_timer.start(REQUEST_TIMEOUT_MSEC); } void NetworkRequest::postRequest(const QByteArray& body) { QNetworkAccessManager* manager = NetworkManager::instance()->networkAccessManager(); handleReply(manager->post(m_request, body)); m_timer.start(REQUEST_TIMEOUT_MSEC); } void NetworkRequest::handleReply(QNetworkReply* reply) { Q_ASSERT(reply); Q_ASSERT(!m_reply); m_reply = reply; m_reply->setParent(this); connect(m_reply, &QNetworkReply::finished, this, &NetworkRequest::replyFinished); connect(m_reply, &QNetworkReply::sslErrors, this, &NetworkRequest::sslErrors); connect(m_reply, &QNetworkReply::metaDataChanged, this, &NetworkRequest::handleHeaderReceived); connect(m_reply, &QNetworkReply::redirected, this, &NetworkRequest::handleRedirect); connect(m_reply, &QNetworkReply::finished, this, &NetworkRequest::maybeDeleteLater); connect(m_reply, &QNetworkReply::downloadProgress, this, [&](qint64 bytesReceived, qint64 bytesTotal) { requestUpdated(bytesReceived, bytesTotal, m_reply); }); } void NetworkRequest::maybeDeleteLater() { if (m_reply && m_reply->isFinished()) { deleteLater(); } } int NetworkRequest::statusCode() const { Q_ASSERT(m_reply); QVariant statusCode = m_reply->attribute(QNetworkRequest::HttpStatusCodeAttribute); if (!statusCode.isValid()) { return 0; } return statusCode.toInt(); } void NetworkRequest::disableTimeout() { m_timer.stop(); } QByteArray NetworkRequest::rawHeader(const QByteArray& headerName) const { if (!m_reply) { logger.error() << "INTERNAL ERROR! NetworkRequest::rawHeader called before " "starting the request"; return QByteArray(); } return m_reply->rawHeader(headerName); } void NetworkRequest::abort() { m_aborted = true; if (!m_reply) { logger.error() << "INTERNAL ERROR! NetworkRequest::abort called before " "starting the request"; return; } m_reply->abort(); } bool NetworkRequest::checkSubjectName(const QSslCertificate& cert) { QString hostname = QString(m_request.rawHeader("Host")); if (hostname.isEmpty()) { Q_ASSERT(m_reply); hostname = m_reply->url().host(); } // Check if there is a match in the subject common name. QStringList commonNames = cert.subjectInfo(QSslCertificate::CommonName); if (commonNames.contains(hostname)) { logger.debug() << "Found commonName match for" << hostname; return true; } // Check there is a match amongst the subject alternative names. QStringList altNames = cert.subjectAlternativeNames().values(QSsl::DnsEntry); for (const QString& pattern : altNames) { QRegularExpression re( QRegularExpression::wildcardToRegularExpression(pattern)); if (re.match(hostname).hasMatch()) { logger.debug() << "Found subjectAltName match for" << hostname; return true; } } // If we get this far, then the certificate has no matching subject name. return false; } void NetworkRequest::sslErrors(const QList<QSslError>& errors) { if (!m_reply) { return; } // Manually check for a hostname match in case we set a raw Host header. if ((errors.count() == 1) && m_request.hasRawHeader("Host") && (errors[0].error() == QSslError::HostNameMismatch) && checkSubjectName(errors[0].certificate())) { m_reply->ignoreSslErrors(errors); return; } logger.error() << "SSL Error on" << m_reply->url().host(); for (const auto& error : errors) { logger.error() << error.errorString(); auto cert = error.certificate(); if (!cert.isNull()) { logger.info() << "Related Cert:"; logger.info() << cert.toText(); } } } void NetworkRequest::enableSSLIntervention() { if (s_intervention_certs.isEmpty()) { s_intervention_certs = QSslConfiguration::systemCaCertificates(); QDirIterator certFolder(":/certs"); while (certFolder.hasNext()) { QFile f(certFolder.next()); if (!f.open(QIODevice::ReadOnly)) { continue; } QSslCertificate cert(&f, QSsl::Pem); if (!cert.isNull()) { logger.info() << "Imported cert from:" << cert.issuerDisplayName(); s_intervention_certs.append(cert); } else { logger.error() << "Failed to import cert -" << f.fileName(); } } } if (s_intervention_certs.isEmpty()) { return; } auto conf = QSslConfiguration::defaultConfiguration(); conf.addCaCertificates(s_intervention_certs); m_request.setSslConfiguration(conf); }
/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ // vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4: #ident "$Id$" /*====== This file is part of PerconaFT. Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. PerconaFT is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. PerconaFT is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with PerconaFT. If not, see <http://www.gnu.org/licenses/>. ---------------------------------------- PerconaFT is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License, version 3, as published by the Free Software Foundation. PerconaFT is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with PerconaFT. If not, see <http://www.gnu.org/licenses/>. ======= */ #ident "Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved." #include <db.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <memory.h> #include <sys/stat.h> #include "src/tests/test.h" #include <ft/txn/xids.h> #define MAX_NEST MAX_TRANSACTION_RECORDS #define MAX_SIZE MAX_TRANSACTION_RECORDS uint8_t valbufs[MAX_NEST][MAX_SIZE]; DBT vals [MAX_NEST]; uint8_t keybuf [MAX_SIZE]; DBT key; DB_TXN *txns [MAX_NEST]; DB_TXN *txn_query; int which_expected; static void fillrandom(uint8_t buf[MAX_SIZE], uint32_t length) { assert(length < MAX_SIZE); uint32_t i; for (i = 0; i < length; i++) { buf[i] = random() & 0xFF; } } static void initialize_values (void) { int nest_level; for (nest_level = 0; nest_level < MAX_NEST; nest_level++) { fillrandom(valbufs[nest_level], nest_level); dbt_init(&vals[nest_level], &valbufs[nest_level][0], nest_level); } uint32_t len = random() % MAX_SIZE; fillrandom(keybuf, len); dbt_init(&key, &keybuf[0], len); } /********************* * * Purpose of this test is to verify nested transactions (support right number of possible values) for test = 1 to MAX create empty db for nesting_level = 1 to MAX - begin txn - insert a value/len unique to this txn - query abort txn (MAX-test) (test-th innermost) // for test=1 don't abort anything commit txn 1 (outermost) // for test = MAX don't commit anything query // only query that really matters */ static DB *db; static DB_ENV *env; static void setup_db (void) { int r; toku_os_recursive_delete(TOKU_TEST_FILENAME); toku_os_mkdir(TOKU_TEST_FILENAME, S_IRWXU+S_IRWXG+S_IRWXO); r = db_env_create(&env, 0); CKERR(r); r = env->open(env, TOKU_TEST_FILENAME, DB_INIT_MPOOL | DB_INIT_LOG | DB_INIT_LOCK | DB_INIT_TXN | DB_PRIVATE | DB_CREATE, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r); { DB_TXN *txn = 0; r = env->txn_begin(env, 0, &txn, 0); CKERR(r); r = db_create(&db, env, 0); CKERR(r); r = db->open(db, txn, "test.db", 0, DB_BTREE, DB_CREATE, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r); r = txn->commit(txn, 0); CKERR(r); } } static void close_db (void) { int r; r = txn_query->commit(txn_query, 0); CKERR(r); r=db->close(db, 0); CKERR(r); r=env->close(env, 0); CKERR(r); } static void verify_val(void) { int r; DBT observed_val; dbt_init(&observed_val, NULL, 0); r = db->get(db, txn_query, &key, &observed_val, 0); if (which_expected==-1) CKERR2(r, DB_NOTFOUND); else { CKERR(r); assert(observed_val.size == vals[which_expected].size); assert(memcmp(observed_val.data, vals[which_expected].data, vals[which_expected].size) == 0); } } static void initialize_db(void) { int r; r = env->txn_begin(env, NULL, &txn_query, DB_READ_UNCOMMITTED); CKERR(r); which_expected = -1; verify_val(); //Put in a 'committed value' r = db->put(db, NULL, &key, &vals[0], 0); CKERR(r); txns[0] = NULL; int i; which_expected = 0; for (i = 1; i < MAX_NEST; i++) { r = env->txn_begin(env, txns[i-1], &txns[i], 0); CKERR(r); verify_val(); r = db->put(db, txns[i], &key, &vals[i], 0); CKERR(r); which_expected = i; verify_val(); } } static void test_txn_nested_shortcut (int abort_at_depth) { int r; if (verbose) { fprintf(stderr, "%s (%s):%d [abortdepth = %d]\n", __FILE__, __FUNCTION__, __LINE__, abort_at_depth); fflush(stderr); } setup_db(); initialize_db(); which_expected = MAX_NEST-1; verify_val(); assert(abort_at_depth > 0); //Cannot abort 'committed' txn. assert(abort_at_depth <= MAX_NEST); //must be in range if (abort_at_depth < MAX_NEST) { //MAX_NEST means no abort DB_TXN *abort_txn = txns[abort_at_depth]; r = abort_txn->abort(abort_txn); CKERR(r); which_expected = abort_at_depth - 1; verify_val(); } if (abort_at_depth > 1) { //abort_at_depth 1 means abort the whole thing (nothing left to commit) DB_TXN *commit_txn = txns[1]; r = commit_txn->commit(commit_txn, DB_TXN_NOSYNC); CKERR(r); verify_val(); } close_db(); } static void test_txn_nested_slow (int abort_at_depth) { int r; if (verbose) { fprintf(stderr, "%s (%s):%d [abortdepth = %d]\n", __FILE__, __FUNCTION__, __LINE__, abort_at_depth); fflush(stderr); } setup_db(); initialize_db(); which_expected = MAX_NEST-1; verify_val(); assert(abort_at_depth > 0); //Cannot abort 'committed' txn. assert(abort_at_depth <= MAX_NEST); //must be in range //MAX_NEST means no abort int nest; for (nest = MAX_NEST - 1; nest >= abort_at_depth; nest--) { DB_TXN *abort_txn = txns[nest]; r = abort_txn->abort(abort_txn); CKERR(r); which_expected = nest - 1; verify_val(); } //which_expected does not change anymore for (nest = abort_at_depth-1; nest > 0; nest--) { DB_TXN *commit_txn = txns[nest]; r = commit_txn->commit(commit_txn, DB_TXN_NOSYNC); CKERR(r); verify_val(); } close_db(); } int test_main(int argc, char *const argv[]) { parse_args(argc, argv); initialize_values(); int i; for (i = 1; i <= MAX_NEST; i++) { test_txn_nested_shortcut(i); test_txn_nested_slow(i); } return 0; }
dnl PowerPC-64 mpn_and_n, mpn_andn_n, mpn_nand_n, mpn_ior_n, mpn_iorn_n, dnl mpn_nior_n, mpn_xor_n, mpn_xnor_n -- mpn bitwise logical operations. dnl Copyright 2003, 2004, 2005 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 cycles/limb C POWER3/PPC630: 1.75 C POWER4/PPC970: 2.10 C n POWER3/PPC630 POWER4/PPC970 C 1 15.00 15.33 C 2 7.50 7.99 C 3 5.33 6.00 C 4 4.50 4.74 C 5 4.20 4.39 C 6 3.50 3.99 C 7 3.14 3.64 C 8 3.00 3.36 C 9 3.00 3.36 C 10 2.70 3.25 C 11 2.63 3.11 C 12 2.58 3.00 C 13 2.61 3.02 C 14 2.42 2.82 C 15 2.40 2.79 C 50 2.08 2.67 C 100 1.85 2.31 C 200 1.80 2.18 C 400 1.77 2.14 C 1000 1.76 2.10# C 2000 1.75# 2.13 C 4000 2.30 2.57 C 8000 2.62 2.58 C 16000 2.52 4.25 C 32000 2.49 16.25 C 64000 2.66 18.76 ifdef(`OPERATION_and_n', ` define(`func',`mpn_and_n') define(`logop', `and')') ifdef(`OPERATION_andn_n', ` define(`func',`mpn_andn_n') define(`logop', `andc')') ifdef(`OPERATION_nand_n', ` define(`func',`mpn_nand_n') define(`logop', `nand')') ifdef(`OPERATION_ior_n', ` define(`func',`mpn_ior_n') define(`logop', `or')') ifdef(`OPERATION_iorn_n', ` define(`func',`mpn_iorn_n') define(`logop', `orc')') ifdef(`OPERATION_nior_n', ` define(`func',`mpn_nior_n') define(`logop', `nor')') ifdef(`OPERATION_xor_n', ` define(`func',`mpn_xor_n') define(`logop', `xor')') ifdef(`OPERATION_xnor_n', ` define(`func',`mpn_xnor_n') define(`logop', `eqv')') C INPUT PARAMETERS C rp r3 C up r4 C vp r5 C n r6 MULFUNC_PROLOGUE(mpn_and_n mpn_andn_n mpn_nand_n mpn_ior_n mpn_iorn_n mpn_nior_n mpn_xor_n mpn_xnor_n) ASM_START() PROLOGUE(func) ld r8, 0(r4) C read lowest u limb ld r9, 0(r5) C read lowest v limb addi r6, r6, 3 C compute branch count (1) rldic. r0, r6, 3, 59 C r0 = (n-1 & 3) << 3; cr0 = (n == 4(t+1))? cmpldi cr6, r0, 16 C cr6 = (n cmp 4t + 3) ifdef(`HAVE_ABI_mode32', ` rldicl r6, r6, 62,34', C ...branch count ` rldicl r6, r6, 62, 2') C ...branch count mtctr r6 ld r6, 0(r4) C read lowest u limb (again) ld r7, 0(r5) C read lowest v limb (again) add r5, r5, r0 C offset vp add r4, r4, r0 C offset up add r3, r3, r0 C offset rp beq cr0, L(L01) blt cr6, L(L10) beq cr6, L(L11) b L(L00) L(oop): ld r8, -24(r4) ld r9, -24(r5) logop r10, r6, r7 std r10, -32(r3) L(L00): ld r6, -16(r4) ld r7, -16(r5) logop r10, r8, r9 std r10, -24(r3) L(L11): ld r8, -8(r4) ld r9, -8(r5) logop r10, r6, r7 std r10, -16(r3) L(L10): ld r6, 0(r4) ld r7, 0(r5) logop r10, r8, r9 std r10, -8(r3) L(L01): addi r5, r5, 32 addi r4, r4, 32 addi r3, r3, 32 bdnz L(oop) logop r10, r6, r7 std r10, -32(r3) blr EPILOGUE()
<% from pwnlib.shellcraft.powerpc.linux import syscall %> <%page args="old, new"/> <%docstring> Invokes the syscall rename. See 'man 2 rename' for more information. Arguments: old(char): old new(char): new </%docstring> ${syscall('SYS_rename', old, new)}
// Copyright (c) 2011-2015 The Bitcoin Core developers // Copyright (c) 2014-2019 The Dash Core developers // Copyright (c) 2019 The Umbru Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #if defined(HAVE_CONFIG_H) #include "config/umbru-config.h" #endif #include "utilitydialog.h" #include "ui_helpmessagedialog.h" #include "bitcoingui.h" #include "clientmodel.h" #include "guiconstants.h" #include "intro.h" #include "paymentrequestplus.h" #include "guiutil.h" #include "clientversion.h" #include "init.h" #include "util.h" #include <stdio.h> #include <QCloseEvent> #include <QLabel> #include <QRegExp> #include <QTextTable> #include <QTextCursor> #include <QVBoxLayout> /** "Help message" or "About" dialog box */ HelpMessageDialog::HelpMessageDialog(QWidget *parent, HelpMode helpMode) : QDialog(parent), ui(new Ui::HelpMessageDialog) { ui->setupUi(this); QString version = tr(PACKAGE_NAME) + " " + tr("version") + " " + QString::fromStdString(FormatFullVersion()); /* On x86 add a bit specifier to the version so that users can distinguish between * 32 and 64 bit builds. On other architectures, 32/64 bit may be more ambiguous. */ #if defined(__x86_64__) version += " " + tr("(%1-bit)").arg(64); #elif defined(__i386__ ) version += " " + tr("(%1-bit)").arg(32); #endif if (helpMode == about) { setWindowTitle(tr("About %1").arg(tr(PACKAGE_NAME))); /// HTML-format the license message from the core QString licenseInfo = QString::fromStdString(LicenseInfo()); QString licenseInfoHTML = licenseInfo; // Make URLs clickable QRegExp uri("<(.*)>", Qt::CaseSensitive, QRegExp::RegExp2); uri.setMinimal(true); // use non-greedy matching licenseInfoHTML.replace(uri, "<a href=\"\\1\">\\1</a>"); // Replace newlines with HTML breaks licenseInfoHTML.replace("\n", "<br>"); ui->aboutMessage->setTextFormat(Qt::RichText); ui->scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); text = version + "\n" + licenseInfo; ui->aboutMessage->setText(version + "<br><br>" + licenseInfoHTML); ui->aboutMessage->setWordWrap(true); ui->helpMessage->setVisible(false); } else if (helpMode == cmdline) { setWindowTitle(tr("Command-line options")); QString header = tr("Usage:") + "\n" + " umbru-qt [" + tr("command-line options") + "] " + "\n"; QTextCursor cursor(ui->helpMessage->document()); cursor.insertText(version); cursor.insertBlock(); cursor.insertText(header); cursor.insertBlock(); std::string strUsage = HelpMessage(HMM_BITCOIN_QT); const bool showDebug = GetBoolArg("-help-debug", false); strUsage += HelpMessageGroup(tr("UI Options:").toStdString()); if (showDebug) { strUsage += HelpMessageOpt("-allowselfsignedrootcertificates", strprintf("Allow self signed root certificates (default: %u)", DEFAULT_SELFSIGNED_ROOTCERTS)); } strUsage += HelpMessageOpt("-choosedatadir", strprintf(tr("Choose data directory on startup (default: %u)").toStdString(), DEFAULT_CHOOSE_DATADIR)); strUsage += HelpMessageOpt("-lang=<lang>", tr("Set language, for example \"de_DE\" (default: system locale)").toStdString()); strUsage += HelpMessageOpt("-min", tr("Start minimized").toStdString()); strUsage += HelpMessageOpt("-rootcertificates=<file>", tr("Set SSL root certificates for payment request (default: -system-)").toStdString()); strUsage += HelpMessageOpt("-splash", strprintf(tr("Show splash screen on startup (default: %u)").toStdString(), DEFAULT_SPLASHSCREEN)); strUsage += HelpMessageOpt("-resetguisettings", tr("Reset all settings changed in the GUI").toStdString()); if (showDebug) { strUsage += HelpMessageOpt("-uiplatform", strprintf("Select platform to customize UI for (one of windows, macosx, other; default: %s)", BitcoinGUI::DEFAULT_UIPLATFORM)); } QString coreOptions = QString::fromStdString(strUsage); text = version + "\n" + header + "\n" + coreOptions; QTextTableFormat tf; tf.setBorderStyle(QTextFrameFormat::BorderStyle_None); tf.setCellPadding(2); QVector<QTextLength> widths; widths << QTextLength(QTextLength::PercentageLength, 35); widths << QTextLength(QTextLength::PercentageLength, 65); tf.setColumnWidthConstraints(widths); QTextCharFormat bold; bold.setFontWeight(QFont::Bold); Q_FOREACH (const QString &line, coreOptions.split("\n")) { if (line.startsWith(" -")) { cursor.currentTable()->appendRows(1); cursor.movePosition(QTextCursor::PreviousCell); cursor.movePosition(QTextCursor::NextRow); cursor.insertText(line.trimmed()); cursor.movePosition(QTextCursor::NextCell); } else if (line.startsWith(" ")) { cursor.insertText(line.trimmed()+' '); } else if (line.size() > 0) { //Title of a group if (cursor.currentTable()) cursor.currentTable()->appendRows(1); cursor.movePosition(QTextCursor::Down); cursor.insertText(line.trimmed(), bold); cursor.insertTable(1, 2, tf); } } ui->helpMessage->moveCursor(QTextCursor::Start); ui->scrollArea->setVisible(false); ui->aboutLogo->setVisible(false); } else if (helpMode == pshelp) { setWindowTitle(tr("PrivateSend information")); ui->aboutMessage->setTextFormat(Qt::RichText); ui->scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); ui->aboutMessage->setText(tr("\ <h3>PrivateSend Basics</h3> \ PrivateSend gives you true financial privacy by obscuring the origins of your funds. \ All the Umbru in your wallet is comprised of different \"inputs\" which you can think of as separate, discrete coins.<br> \ PrivateSend uses an innovative process to mix your inputs with the inputs of two other people, without having your coins ever leave your wallet. \ You retain control of your money at all times.<hr> \ <b>The PrivateSend process works like this:</b>\ <ol type=\"1\"> \ <li>PrivateSend begins by breaking your transaction inputs down into standard denominations. \ These denominations are 0.001 UMBRU, 0.01 UMBRU, 0.1 UMBRU, 1 UMBRU and 10 UMBRU -- sort of like the paper money you use every day.</li> \ <li>Your wallet then sends requests to specially configured software nodes on the network, called \"masternodes.\" \ These masternodes are informed then that you are interested in mixing a certain denomination. \ No identifiable information is sent to the masternodes, so they never know \"who\" you are.</li> \ <li>When two other people send similar messages, indicating that they wish to mix the same denomination, a mixing session begins. \ The masternode mixes up the inputs and instructs all three users' wallets to pay the now-transformed input back to themselves. \ Your wallet pays that denomination directly to itself, but in a different address (called a change address).</li> \ <li>In order to fully obscure your funds, your wallet must repeat this process a number of times with each denomination. \ Each time the process is completed, it's called a \"round.\" Each round of PrivateSend makes it exponentially more difficult to determine where your funds originated.</li> \ <li>This mixing process happens in the background without any intervention on your part. When you wish to make a transaction, \ your funds will already be anonymized. No additional waiting is required.</li> \ </ol> <hr>\ <b>IMPORTANT:</b> Your wallet only contains 1000 of these \"change addresses.\" Every time a mixing event happens, up to 9 of your addresses are used up. \ This means those 1000 addresses last for about 100 mixing events. When 900 of them are used, your wallet must create more addresses. \ It can only do this, however, if you have automatic backups enabled.<br> \ Consequently, users who have backups disabled will also have PrivateSend disabled. <hr>\ For more information, see the <a href=\"https://docs.umbru.org/en/latest/wallets/umbrucore/privatesend-instantsend.html\">PrivateSend documentation</a>." )); ui->aboutMessage->setWordWrap(true); ui->helpMessage->setVisible(false); ui->aboutLogo->setVisible(false); } // Theme dependent Gfx in About popup QString helpMessageGfx = ":/images/" + GUIUtil::getThemeName() + "/about"; QPixmap pixmap = QPixmap(helpMessageGfx); ui->aboutLogo->setPixmap(pixmap); } HelpMessageDialog::~HelpMessageDialog() { delete ui; } void HelpMessageDialog::printToConsole() { // On other operating systems, the expected action is to print the message to the console. fprintf(stdout, "%s\n", qPrintable(text)); } void HelpMessageDialog::showOrPrint() { #if defined(WIN32) // On Windows, show a message box, as there is no stderr/stdout in windowed applications exec(); #else // On other operating systems, print help text to console printToConsole(); #endif } void HelpMessageDialog::on_okButton_accepted() { close(); } /** "Shutdown" window */ ShutdownWindow::ShutdownWindow(QWidget *parent, Qt::WindowFlags f): QWidget(parent, f) { QVBoxLayout *layout = new QVBoxLayout(); layout->addWidget(new QLabel( tr("%1 is shutting down...").arg(tr(PACKAGE_NAME)) + "<br /><br />" + tr("Do not shut down the computer until this window disappears."))); setLayout(layout); } QWidget *ShutdownWindow::showShutdownWindow(BitcoinGUI *window) { if (!window) return nullptr; // Show a simple window indicating shutdown status QWidget *shutdownWindow = new ShutdownWindow(); shutdownWindow->setWindowTitle(window->windowTitle()); // Center shutdown window at where main window was const QPoint global = window->mapToGlobal(window->rect().center()); shutdownWindow->move(global.x() - shutdownWindow->width() / 2, global.y() - shutdownWindow->height() / 2); shutdownWindow->show(); return shutdownWindow; } void ShutdownWindow::closeEvent(QCloseEvent *event) { event->ignore(); }
; A158249: 256n^2 - 2n. ; 254,1020,2298,4088,6390,9204,12530,16368,20718,25580,30954,36840,43238,50148,57570,65504,73950,82908,92378,102360,112854,123860,135378,147408,159950,173004,186570,200648,215238,230340,245954,262080,278718,295868,313530,331704,350390,369588,389298,409520,430254,451500,473258,495528,518310,541604,565410,589728,614558,639900,665754,692120,718998,746388,774290,802704,831630,861068,891018,921480,952454,983940,1015938,1048448,1081470,1115004,1149050,1183608,1218678,1254260,1290354,1326960,1364078 mov $1,8 mov $2,$0 add $2,1 mul $2,2 mul $1,$2 pow $1,2 sub $1,$2 mov $0,$1
; ; Old School Computer Architecture - interfacing FLOS ; Stefano Bodrato, 2011 ; ; $Id: get_pen.asm,v 1.2 2012/03/08 07:16:46 stefano Exp $ ; INCLUDE "flos.def" XLIB get_pen get_pen: call kjt_get_pen ld h,0 ld l,a ret
; A290061: a(n) = (1/24)*(n + 3)*(3*n^3 + 5*n^2 - 6*n + 16). ; 3,10,31,77,162,303,520,836,1277,1872,2653,3655,4916,6477,8382,10678,13415,16646,20427,24817,29878,35675,42276,49752,58177,67628,78185,89931,102952,117337,133178,150570,169611,190402,213047,237653,264330,293191,324352,357932,394053,432840,474421,518927,566492,617253,671350,728926,790127,855102,924003,996985,1074206,1155827,1242012,1332928,1428745,1529636,1635777,1747347,1864528,1987505,2116466,2251602,2393107,2541178,2696015,2857821,3026802,3203167,3387128,3578900,3778701,3986752,4203277,4428503,4662660,4905981,5158702,5421062,5693303,5975670,6268411,6571777,6886022,7211403,7548180,7896616,8256977,8629532,9014553,9412315,9823096,10247177,10684842,11136378,11602075,12082226,12577127,13087077 add $0,1 mov $1,2 mov $3,$0 lpb $0 add $2,$3 add $1,$2 add $3,$0 sub $0,1 lpe mov $0,$1
; A281362: a(0) = 1, a(1) = 2; for n>1, a(n) = a(n-1) + a(n-2) + floor(n/2). ; 1,2,4,7,13,22,38,63,105,172,282,459,747,1212,1966,3185,5159,8352,13520,21881,35411,57302,92724,150037,242773,392822,635608,1028443,1664065,2692522,4356602,7049139,11405757,18454912,29860686,48315615,78176319,126491952,204668290,331160261,535828571,866988852,1402817444,2269806317,3672623783,5942430122,9615053928,15557484073,25172538025,40730022122,65902560172,106632582319,172535142517,279167724862,451702867406,730870592295,1182573459729,1913444052052,3096017511810,5009461563891,8105479075731,13114940639652,21220419715414,34335360355097,55555780070543,89891140425672,145446920496248,235338060921953,380784981418235,616123042340222,996908023758492,1613031066098749,2609939089857277,4222970155956062,6832909245813376,11055879401769475,17888788647582889,28944668049352402,46833456696935330,75778124746287771,122611581443223141,198389706189510952,321001287632734134,519390993822245127,840392281454979303,1359783275277224472,2200175556732203818,3559958832009428333,5760134388741632195,9320093220751060572,15080227609492692812,24400320830243753429,39480548439736446287,63880869269980199762,103361417709716646096,167242286979696845905,270603704689413492049,437845991669110338002,708449696358523830100,1146295688027634168151 lpb $0 mov $2,$0 seq $2,1595 ; a(n) = a(n-1) + a(n-2) + 1, with a(0) = a(1) = 1. add $1,$2 mov $3,$2 min $3,1 add $0,$3 trn $0,3 lpe add $1,1 mov $0,$1
; A106505: Ordered and uniqued length of side common to the two angles, one being the double of the other, of a primitive integer-sided triangle. ; 5,7,9,11,13,15,16,17,19,21,23,24,25,27,29,31,32,33,35,37,39,40,41,43,45,47,48,49,51,53,55,56,57,59,61,63,64,65,67,69,71,72,73,75,77,79,80,81,83,85,87,88,89,91,93,95,96,97,99,101,103,104,105,107,109,111,112 mov $2,$0 lpb $2 trn $0,5 add $1,2 trn $1,$0 sub $2,1 lpe add $1,5
; A188295: [nr]-[nr-r], where r=1/sqrt(2), [ ]=floor. ; 0,1,1,0,1,1,0,1,1,1,0,1,1,0,1,1,1,0,1,1,0,1,1,0,1,1,1,0,1,1,0,1,1,1,0,1,1,0,1,1,0,1,1,1,0,1,1,0,1,1,1,0,1,1,0,1,1,1,0,1,1,0,1,1,0,1,1,1,0,1,1,0,1,1,1,0,1,1,0,1,1,0,1,1,1,0,1,1,0,1,1,1,0,1,1,0,1,1,1,0,1,1,0,1,1,0,1,1,1,0,1,1,0,1,1,1,0,1,1,0,1,1,0 mov $22,$0 mov $24,2 lpb $24,1 clr $0,22 mov $0,$22 sub $24,1 add $0,$24 sub $0,1 mov $19,$0 mov $21,$0 add $21,1 lpb $21,1 mov $0,$19 sub $21,1 sub $0,$21 mov $15,$0 mov $17,2 lpb $17,1 mov $0,$15 sub $17,1 add $0,$17 sub $0,1 mov $9,$0 mov $12,$0 add $0,1 pow $0,2 mov $2,$0 mov $3,1 lpb $2,1 add $3,1 mov $4,$2 trn $4,2 mov $5,1 lpb $4,1 add $3,4 trn $4,$3 add $5,2 lpe sub $2,$2 lpe mov $1,$5 mov $11,$9 mul $11,2 add $1,$11 div $1,2 add $1,3 add $1,$12 mov $18,$17 lpb $18,1 mov $16,$1 trn $18,2 lpe lpe lpb $15,1 mov $15,0 sub $16,$1 lpe mov $1,$16 sub $1,2 mul $1,3 add $1,3 add $20,$1 lpe mov $1,$20 sub $1,5 mov $25,$24 lpb $25,1 mov $23,$1 sub $25,1 lpe lpe lpb $22,1 mov $22,0 sub $23,$1 lpe mov $1,$23 sub $1,3 div $1,3
global _start, _kmain, __morestack extern kmain, start_ctors, end_ctors, start_dtors, end_dtors %define MULTIBOOT_HEADER_MAGIC 0x1BADB002 %define MULTIBOOT_HEADER_FLAGS 0x00000003 %define CHECKSUM -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS) ;-- Entry point _start: jmp start __morestack: ;-- Multiboot header -- align 4 multiboot_header: dd MULTIBOOT_HEADER_MAGIC dd MULTIBOOT_HEADER_FLAGS dd CHECKSUM ;--/Multiboot header -- start: push ebx static_ctors_loop: mov ebx, start_ctors jmp .test .body: call [ebx] add ebx,4 .test: cmp ebx, end_ctors jb .body call kmain ; call kernel proper static_dtors_loop: mov ebx, start_dtors jmp .test .body: call [ebx] add ebx,4 .test: cmp ebx, end_dtors jb .body cli ; stop interrupts hlt ; halt the CPU
/* Copyright (c) 2003, 2014 Oracle and/or its affiliates. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #include <signaldata/PackedSignal.hpp> #include <signaldata/LqhKey.hpp> #include <signaldata/FireTrigOrd.hpp> #include <debugger/DebuggerNames.hpp> bool printPACKED_SIGNAL(FILE * output, const Uint32 * theData, Uint32 len, Uint16 receiverBlockNo){ fprintf(output, "Signal data: "); Uint32 i = 0; while (i < len) fprintf(output, "H\'%.8x ", theData[i++]); fprintf(output,"\n"); fprintf(output, "--------- Begin Packed Signals --------\n"); // Print each signal separately for (i = 0; i < len;) { switch (PackedSignal::getSignalType(theData[i])) { case ZCOMMIT: { Uint32 signalLength = 5; fprintf(output, "--------------- Signal ----------------\n"); fprintf(output, "r.bn: %u \"%s\", length: %u \"COMMIT\"\n", receiverBlockNo, getBlockName(receiverBlockNo,""), signalLength); fprintf(output, "Signal data: "); for(Uint32 j = 0; j < signalLength; j++) fprintf(output, "H\'%.8x ", theData[i++]); fprintf(output,"\n"); break; } case ZCOMPLETE: { Uint32 signalLength = 3; fprintf(output, "--------------- Signal ----------------\n"); fprintf(output, "r.bn: %u \"%s\", length: %u \"COMPLETE\"\n", receiverBlockNo, getBlockName(receiverBlockNo,""), signalLength); fprintf(output, "Signal data: "); for(Uint32 j = 0; j < signalLength; j++) fprintf(output, "H\'%.8x ", theData[i++]); fprintf(output,"\n"); break; } case ZCOMMITTED: { Uint32 signalLength = 3; fprintf(output, "--------------- Signal ----------------\n"); fprintf(output, "r.bn: %u \"%s\", length: %u \"COMMITTED\"\n", receiverBlockNo, getBlockName(receiverBlockNo,""), signalLength); fprintf(output, "Signal data: "); for(Uint32 j = 0; j < signalLength; j++) fprintf(output, "H\'%.8x ", theData[i++]); fprintf(output,"\n"); break; } case ZCOMPLETED: { Uint32 signalLength = 3; fprintf(output, "--------------- Signal ----------------\n"); fprintf(output, "r.bn: %u \"%s\", length: %u \"COMPLETED\"\n", receiverBlockNo, getBlockName(receiverBlockNo,""), signalLength); fprintf(output, "Signal data: "); for(Uint32 j = 0; j < signalLength; j++) fprintf(output, "H\'%.8x ", theData[i++]); fprintf(output,"\n"); break; } case ZLQHKEYCONF: { Uint32 signalLength = LqhKeyConf::SignalLength; fprintf(output, "--------------- Signal ----------------\n"); fprintf(output, "r.bn: %u \"%s\", length: %u \"LQHKEYCONF\"\n", receiverBlockNo, getBlockName(receiverBlockNo,""), signalLength); printLQHKEYCONF(output, theData + i, signalLength, receiverBlockNo); i += signalLength; break; } case ZREMOVE_MARKER: { bool removed_by_api = !(theData[i] & 1); Uint32 signalLength = 2; fprintf(output, "--------------- Signal ----------------\n"); if (removed_by_api) { fprintf(output, "r.bn: %u \"%s\", length: %u \"REMOVE_MARKER\"\n", receiverBlockNo, getBlockName(receiverBlockNo,""), signalLength); } else { fprintf(output, "r.bn: %u \"%s\", length: %u \"REMOVE_MARKER_FAIL_API\"\n", receiverBlockNo, getBlockName(receiverBlockNo,""), signalLength); } fprintf(output, "Signal data: "); i++; // Skip first word! for(Uint32 j = 0; j < signalLength; j++) fprintf(output, "H\'%.8x ", theData[i++]); fprintf(output,"\n"); break; } case ZFIRE_TRIG_REQ: { Uint32 signalLength = FireTrigReq::SignalLength; fprintf(output, "--------------- Signal ----------------\n"); fprintf(output, "r.bn: %u \"%s\", length: %u \"FIRE_TRIG_REQ\"\n", receiverBlockNo, getBlockName(receiverBlockNo,""), signalLength); i += signalLength; break; } case ZFIRE_TRIG_CONF: { Uint32 signalLength = FireTrigConf::SignalLength; fprintf(output, "--------------- Signal ----------------\n"); fprintf(output, "r.bn: %u \"%s\", length: %u \"FIRE_TRIG_CONF\"\n", receiverBlockNo, getBlockName(receiverBlockNo,""), signalLength); i += signalLength; break; } default: fprintf(output, "Unknown signal type\n"); i = len; // terminate printing break; } }//for fprintf(output, "--------- End Packed Signals ----------\n"); return true; } bool PackedSignal::verify(const Uint32* data, Uint32 len, Uint32 receiverBlockNo, Uint32 typesExpected, Uint32 commitLen) { Uint32 pos = 0; bool bad = false; if (unlikely(len > 25)) { fprintf(stderr, "Bad PackedSignal length : %u\n", len); bad = true; } else { while ((pos < len) && ! bad) { Uint32 sigType = data[pos] >> 28; if (unlikely(((1 << sigType) & typesExpected) == 0)) { fprintf(stderr, "Unexpected sigtype in packed signal : %u at pos %u. Expected : %u\n", sigType, pos, typesExpected); bad = true; break; } switch (sigType) { case ZCOMMIT: assert(commitLen > 0); pos += commitLen; break; case ZCOMPLETE: pos+= 3; break; case ZCOMMITTED: pos+= 3; break; case ZCOMPLETED: pos+= 3; break; case ZLQHKEYCONF: pos+= LqhKeyConf::SignalLength; break; case ZREMOVE_MARKER: pos+= 3; break; case ZFIRE_TRIG_REQ: pos+= FireTrigReq::SignalLength; break; case ZFIRE_TRIG_CONF: pos+= FireTrigConf::SignalLength; break; default : fprintf(stderr, "Unrecognised signal type %u at pos %u\n", sigType, pos); bad = true; break; } } if (likely(pos == len)) { /* Looks ok */ return true; } if (!bad) { fprintf(stderr, "Packed signal component length (%u) != total length (%u)\n", pos, len); } } printPACKED_SIGNAL(stderr, data, len, receiverBlockNo); return false; }
; DV3 PC Compatible Floppy Disk Write Sector  1993 Tony Tebby section dv3 xdef fd_wphys ; write sector (physical layer) xref fd_cmd_rw xref fd_stat xref fd_fint xref.l fdc_stat xref.l fdc_data xref.s fdc.intl include 'dev8_keys_err' include 'dev8_dv3_keys' include 'dev8_dv3_fd_keys' include 'dev8_dv3_fd_pcf_keys' include 'dev8_mac_assert' ;+++ ; Write sector (physical layer) - no error recovery ; ; d7 c p drive ID / number ; a1 c p address to write from ; a3 c p linkage block ; a4 c p drive definition ; ; status return 0, ERR.MCHK or conventional error ; ;--- fd_wphys fdw.reg reg d1/d2/a0/a1/a2 movem.l fdw.reg,-(sp) lea fdc_stat,a0 ; status register address lea fdc_data-fdc_stat(a0),a2 ; data register address move.w ddf_slen(a4),d1 ; sector length subq.w #1,d1 ; allow for dbra blt.l fdw_mchk ; !!! move.w sr,-(sp) move.w #fdc.intl,sr ; ... can we get rid of this??? moveq #fdc.wrsc,d0 ; write sector jsr fd_cmd_rw bne.s fdw_mchs moveq #fdcs.wrd,d2 ; write status move.l fdl_1sec(a3),d0 ; 1 second timer ish fdw_wait cmp.b (a0),d2 ; write? beq.s fdw_put ; ... yes bgt.s fdw_stat ; ... failed, status is ready cmp.b (a0),d2 ; write? beq.s fdw_put ; ... yes subq.l #2,d0 ; count down bgt.s fdw_wait bra.s fdw_time fdw_put move.b (a1)+,(a2) ; put byte dbra d1,fdw_wait ; loop fdw_stat move.w (sp)+,sr jsr fd_stat ; wait for status at end of command fdw_exit movem.l (sp)+,fdw.reg rts fdw_time move.w (sp)+,sr jsr fd_fint ; interrupt command bra.s fdw_exit fdw_mchs move.w (sp)+,sr fdw_mchk moveq #err.mchk,d0 bra.s fdw_exit end
; ; Spectrum C Library ; ; ANSI Video handling for ZX Spectrum ; ; BEL - chr(7) Beep it out ; ; ; Stefano Bodrato - Apr. 2000 ; ; ; $Id: f_ansi_bel.asm,v 1.3 2016-06-12 16:06:43 dom Exp $ ; SECTION code_clib PUBLIC ansi_BEL ; A fine double frequency beep for BEL .ansi_BEL ld a,(23624) rra rra rra .BEL_LENGHT ld b,70 ld c,254 .BEL_loop dec h jr nz,BEL_jump xor 16 out (c),a .BEL_FREQ_1 ld h,165 .BEL_jump dec l jr nz,BEL_loop xor 16 out (c),a .BEL_FR_2 ld l,180 djnz BEL_loop ret
; A021560: Decimal expansion of 1/556. ; Submitted by Christian Krause ; 0,0,1,7,9,8,5,6,1,1,5,1,0,7,9,1,3,6,6,9,0,6,4,7,4,8,2,0,1,4,3,8,8,4,8,9,2,0,8,6,3,3,0,9,3,5,2,5,1,7,9,8,5,6,1,1,5,1,0,7,9,1,3,6,6,9,0,6,4,7,4,8,2,0,1,4,3,8,8,4,8,9,2,0,8,6,3,3,0,9,3,5,2,5,1,7,9,8,5 seq $0,83811 ; Numbers n such that 2n+1 is the digit reversal of n+1. div $0,2224 mod $0,10
//===- lli.cpp - LLVM Interpreter / Dynamic compiler ----------------------===// // // The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// // // This utility provides a simple wrapper around the LLVM Execution Engines, // which allow the direct execution of LLVM programs through a Just-In-Time // compiler, or through an interpreter if no JIT is available for this platform. // //===----------------------------------------------------------------------===// #include "OrcLazyJIT.h" #include "RemoteJITUtils.h" #include "llvm/IR/LLVMContext.h" #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/Triple.h" #include "llvm/Bitcode/BitcodeReader.h" #include "llvm/CodeGen/LinkAllCodegenComponents.h" #include "llvm/ExecutionEngine/GenericValue.h" #include "llvm/ExecutionEngine/Interpreter.h" #include "llvm/ExecutionEngine/JITEventListener.h" #include "llvm/ExecutionEngine/MCJIT.h" #include "llvm/ExecutionEngine/ObjectCache.h" #include "llvm/ExecutionEngine/OrcMCJITReplacement.h" #include "llvm/ExecutionEngine/SectionMemoryManager.h" #include "llvm/ExecutionEngine/Orc/OrcRemoteTargetClient.h" #include "llvm/IR/IRBuilder.h" #include "llvm/IR/Module.h" #include "llvm/IR/Type.h" #include "llvm/IR/TypeBuilder.h" #include "llvm/IRReader/IRReader.h" #include "llvm/Object/Archive.h" #include "llvm/Object/ObjectFile.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/Debug.h" #include "llvm/Support/DynamicLibrary.h" #include "llvm/Support/Format.h" #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/MathExtras.h" #include "llvm/Support/Memory.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/Path.h" #include "llvm/Support/PluginLoader.h" #include "llvm/Support/PrettyStackTrace.h" #include "llvm/Support/Process.h" #include "llvm/Support/Program.h" #include "llvm/Support/Signals.h" #include "llvm/Support/SourceMgr.h" #include "llvm/Support/TargetSelect.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Transforms/Instrumentation.h" #include <cerrno> #ifdef __CYGWIN__ #include <cygwin/version.h> #if defined(CYGWIN_VERSION_DLL_MAJOR) && CYGWIN_VERSION_DLL_MAJOR<1007 #define DO_NOTHING_ATEXIT 1 #endif #endif using namespace llvm; #define DEBUG_TYPE "lli" namespace { enum class JITKind { MCJIT, OrcMCJITReplacement, OrcLazy }; cl::opt<std::string> InputFile(cl::desc("<input bitcode>"), cl::Positional, cl::init("-")); cl::list<std::string> InputArgv(cl::ConsumeAfter, cl::desc("<program arguments>...")); cl::opt<bool> ForceInterpreter("force-interpreter", cl::desc("Force interpretation: disable JIT"), cl::init(false)); cl::opt<JITKind> UseJITKind("jit-kind", cl::desc("Choose underlying JIT kind."), cl::init(JITKind::MCJIT), cl::values( clEnumValN(JITKind::MCJIT, "mcjit", "MCJIT"), clEnumValN(JITKind::OrcMCJITReplacement, "orc-mcjit", "Orc-based MCJIT replacement"), clEnumValN(JITKind::OrcLazy, "orc-lazy", "Orc-based lazy JIT."))); // The MCJIT supports building for a target address space separate from // the JIT compilation process. Use a forked process and a copying // memory manager with IPC to execute using this functionality. cl::opt<bool> RemoteMCJIT("remote-mcjit", cl::desc("Execute MCJIT'ed code in a separate process."), cl::init(false)); // Manually specify the child process for remote execution. This overrides // the simulated remote execution that allocates address space for child // execution. The child process will be executed and will communicate with // lli via stdin/stdout pipes. cl::opt<std::string> ChildExecPath("mcjit-remote-process", cl::desc("Specify the filename of the process to launch " "for remote MCJIT execution. If none is specified," "\n\tremote execution will be simulated in-process."), cl::value_desc("filename"), cl::init("")); // Determine optimization level. cl::opt<char> OptLevel("O", cl::desc("Optimization level. [-O0, -O1, -O2, or -O3] " "(default = '-O2')"), cl::Prefix, cl::ZeroOrMore, cl::init(' ')); cl::opt<std::string> TargetTriple("mtriple", cl::desc("Override target triple for module")); cl::opt<std::string> MArch("march", cl::desc("Architecture to generate assembly for (see --version)")); cl::opt<std::string> MCPU("mcpu", cl::desc("Target a specific cpu type (-mcpu=help for details)"), cl::value_desc("cpu-name"), cl::init("")); cl::list<std::string> MAttrs("mattr", cl::CommaSeparated, cl::desc("Target specific attributes (-mattr=help for details)"), cl::value_desc("a1,+a2,-a3,...")); cl::opt<std::string> EntryFunc("entry-function", cl::desc("Specify the entry function (default = 'main') " "of the executable"), cl::value_desc("function"), cl::init("main")); cl::list<std::string> ExtraModules("extra-module", cl::desc("Extra modules to be loaded"), cl::value_desc("input bitcode")); cl::list<std::string> ExtraObjects("extra-object", cl::desc("Extra object files to be loaded"), cl::value_desc("input object")); cl::list<std::string> ExtraArchives("extra-archive", cl::desc("Extra archive files to be loaded"), cl::value_desc("input archive")); cl::opt<bool> EnableCacheManager("enable-cache-manager", cl::desc("Use cache manager to save/load mdoules"), cl::init(false)); cl::opt<std::string> ObjectCacheDir("object-cache-dir", cl::desc("Directory to store cached object files " "(must be user writable)"), cl::init("")); cl::opt<std::string> FakeArgv0("fake-argv0", cl::desc("Override the 'argv[0]' value passed into the executing" " program"), cl::value_desc("executable")); cl::opt<bool> DisableCoreFiles("disable-core-files", cl::Hidden, cl::desc("Disable emission of core files if possible")); cl::opt<bool> NoLazyCompilation("disable-lazy-compilation", cl::desc("Disable JIT lazy compilation"), cl::init(false)); cl::opt<Reloc::Model> RelocModel( "relocation-model", cl::desc("Choose relocation model"), cl::values( clEnumValN(Reloc::Static, "static", "Non-relocatable code"), clEnumValN(Reloc::PIC_, "pic", "Fully relocatable, position independent code"), clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic", "Relocatable external references, non-relocatable code"))); cl::opt<llvm::CodeModel::Model> CMModel("code-model", cl::desc("Choose code model"), cl::init(CodeModel::JITDefault), cl::values(clEnumValN(CodeModel::JITDefault, "default", "Target default JIT code model"), clEnumValN(CodeModel::Small, "small", "Small code model"), clEnumValN(CodeModel::Kernel, "kernel", "Kernel code model"), clEnumValN(CodeModel::Medium, "medium", "Medium code model"), clEnumValN(CodeModel::Large, "large", "Large code model"))); cl::opt<bool> GenerateSoftFloatCalls("soft-float", cl::desc("Generate software floating point library calls"), cl::init(false)); cl::opt<llvm::FloatABI::ABIType> FloatABIForCalls("float-abi", cl::desc("Choose float ABI type"), cl::init(FloatABI::Default), cl::values( clEnumValN(FloatABI::Default, "default", "Target default float ABI type"), clEnumValN(FloatABI::Soft, "soft", "Soft float ABI (implied by -soft-float)"), clEnumValN(FloatABI::Hard, "hard", "Hard float ABI (uses FP registers)"))); ExitOnError ExitOnErr; } //===----------------------------------------------------------------------===// // Object cache // // This object cache implementation writes cached objects to disk to the // directory specified by CacheDir, using a filename provided in the module // descriptor. The cache tries to load a saved object using that path if the // file exists. CacheDir defaults to "", in which case objects are cached // alongside their originating bitcodes. // class LLIObjectCache : public ObjectCache { public: LLIObjectCache(const std::string& CacheDir) : CacheDir(CacheDir) { // Add trailing '/' to cache dir if necessary. if (!this->CacheDir.empty() && this->CacheDir[this->CacheDir.size() - 1] != '/') this->CacheDir += '/'; } ~LLIObjectCache() override {} void notifyObjectCompiled(const Module *M, MemoryBufferRef Obj) override { const std::string &ModuleID = M->getModuleIdentifier(); std::string CacheName; if (!getCacheFilename(ModuleID, CacheName)) return; if (!CacheDir.empty()) { // Create user-defined cache dir. SmallString<128> dir(sys::path::parent_path(CacheName)); sys::fs::create_directories(Twine(dir)); } std::error_code EC; raw_fd_ostream outfile(CacheName, EC, sys::fs::F_None); outfile.write(Obj.getBufferStart(), Obj.getBufferSize()); outfile.close(); } std::unique_ptr<MemoryBuffer> getObject(const Module* M) override { const std::string &ModuleID = M->getModuleIdentifier(); std::string CacheName; if (!getCacheFilename(ModuleID, CacheName)) return nullptr; // Load the object from the cache filename ErrorOr<std::unique_ptr<MemoryBuffer>> IRObjectBuffer = MemoryBuffer::getFile(CacheName, -1, false); // If the file isn't there, that's OK. if (!IRObjectBuffer) return nullptr; // MCJIT will want to write into this buffer, and we don't want that // because the file has probably just been mmapped. Instead we make // a copy. The filed-based buffer will be released when it goes // out of scope. return MemoryBuffer::getMemBufferCopy(IRObjectBuffer.get()->getBuffer()); } private: std::string CacheDir; bool getCacheFilename(const std::string &ModID, std::string &CacheName) { std::string Prefix("file:"); size_t PrefixLength = Prefix.length(); if (ModID.substr(0, PrefixLength) != Prefix) return false; std::string CacheSubdir = ModID.substr(PrefixLength); #if defined(_WIN32) // Transform "X:\foo" => "/X\foo" for convenience. if (isalpha(CacheSubdir[0]) && CacheSubdir[1] == ':') { CacheSubdir[1] = CacheSubdir[0]; CacheSubdir[0] = '/'; } #endif CacheName = CacheDir + CacheSubdir; size_t pos = CacheName.rfind('.'); CacheName.replace(pos, CacheName.length() - pos, ".o"); return true; } }; // On Mingw and Cygwin, an external symbol named '__main' is called from the // generated 'main' function to allow static initialization. To avoid linking // problems with remote targets (because lli's remote target support does not // currently handle external linking) we add a secondary module which defines // an empty '__main' function. static void addCygMingExtraModule(ExecutionEngine &EE, LLVMContext &Context, StringRef TargetTripleStr) { IRBuilder<> Builder(Context); Triple TargetTriple(TargetTripleStr); // Create a new module. std::unique_ptr<Module> M = make_unique<Module>("CygMingHelper", Context); M->setTargetTriple(TargetTripleStr); // Create an empty function named "__main". Function *Result; if (TargetTriple.isArch64Bit()) { Result = Function::Create( TypeBuilder<int64_t(void), false>::get(Context), GlobalValue::ExternalLinkage, "__main", M.get()); } else { Result = Function::Create( TypeBuilder<int32_t(void), false>::get(Context), GlobalValue::ExternalLinkage, "__main", M.get()); } BasicBlock *BB = BasicBlock::Create(Context, "__main", Result); Builder.SetInsertPoint(BB); Value *ReturnVal; if (TargetTriple.isArch64Bit()) ReturnVal = ConstantInt::get(Context, APInt(64, 0)); else ReturnVal = ConstantInt::get(Context, APInt(32, 0)); Builder.CreateRet(ReturnVal); // Add this new module to the ExecutionEngine. EE.addModule(std::move(M)); } CodeGenOpt::Level getOptLevel() { switch (OptLevel) { default: errs() << "lli: Invalid optimization level.\n"; exit(1); case '0': return CodeGenOpt::None; case '1': return CodeGenOpt::Less; case ' ': case '2': return CodeGenOpt::Default; case '3': return CodeGenOpt::Aggressive; } llvm_unreachable("Unrecognized opt level."); } LLVM_ATTRIBUTE_NORETURN static void reportError(SMDiagnostic Err, const char *ProgName) { Err.print(ProgName, errs()); exit(1); } //===----------------------------------------------------------------------===// // main Driver function // int main(int argc, char **argv, char * const *envp) { sys::PrintStackTraceOnErrorSignal(argv[0]); PrettyStackTraceProgram X(argc, argv); atexit(llvm_shutdown); // Call llvm_shutdown() on exit. if (argc > 1) ExitOnErr.setBanner(std::string(argv[0]) + ": "); // If we have a native target, initialize it to ensure it is linked in and // usable by the JIT. InitializeNativeTarget(); InitializeNativeTargetAsmPrinter(); InitializeNativeTargetAsmParser(); cl::ParseCommandLineOptions(argc, argv, "llvm interpreter & dynamic compiler\n"); // If the user doesn't want core files, disable them. if (DisableCoreFiles) sys::Process::PreventCoreFiles(); LLVMContext Context; // Load the bitcode... SMDiagnostic Err; std::unique_ptr<Module> Owner = parseIRFile(InputFile, Err, Context); Module *Mod = Owner.get(); if (!Mod) reportError(Err, argv[0]); if (UseJITKind == JITKind::OrcLazy) { std::vector<std::unique_ptr<Module>> Ms; Ms.push_back(std::move(Owner)); for (auto &ExtraMod : ExtraModules) { Ms.push_back(parseIRFile(ExtraMod, Err, Context)); if (!Ms.back()) reportError(Err, argv[0]); } std::vector<std::string> Args; Args.push_back(InputFile); for (auto &Arg : InputArgv) Args.push_back(Arg); return runOrcLazyJIT(std::move(Ms), Args); } if (EnableCacheManager) { std::string CacheName("file:"); CacheName.append(InputFile); Mod->setModuleIdentifier(CacheName); } // If not jitting lazily, load the whole bitcode file eagerly too. if (NoLazyCompilation) { // Use *argv instead of argv[0] to work around a wrong GCC warning. ExitOnError ExitOnErr(std::string(*argv) + ": bitcode didn't read correctly: "); ExitOnErr(Mod->materializeAll()); } std::string ErrorMsg; EngineBuilder builder(std::move(Owner)); builder.setMArch(MArch); builder.setMCPU(MCPU); builder.setMAttrs(MAttrs); if (RelocModel.getNumOccurrences()) builder.setRelocationModel(RelocModel); builder.setCodeModel(CMModel); builder.setErrorStr(&ErrorMsg); builder.setEngineKind(ForceInterpreter ? EngineKind::Interpreter : EngineKind::JIT); builder.setUseOrcMCJITReplacement(UseJITKind == JITKind::OrcMCJITReplacement); // If we are supposed to override the target triple, do so now. if (!TargetTriple.empty()) Mod->setTargetTriple(Triple::normalize(TargetTriple)); // Enable MCJIT if desired. RTDyldMemoryManager *RTDyldMM = nullptr; if (!ForceInterpreter) { if (RemoteMCJIT) RTDyldMM = new ForwardingMemoryManager(); else RTDyldMM = new SectionMemoryManager(); // Deliberately construct a temp std::unique_ptr to pass in. Do not null out // RTDyldMM: We still use it below, even though we don't own it. builder.setMCJITMemoryManager( std::unique_ptr<RTDyldMemoryManager>(RTDyldMM)); } else if (RemoteMCJIT) { errs() << "error: Remote process execution does not work with the " "interpreter.\n"; exit(1); } builder.setOptLevel(getOptLevel()); TargetOptions Options; if (FloatABIForCalls != FloatABI::Default) Options.FloatABIType = FloatABIForCalls; builder.setTargetOptions(Options); std::unique_ptr<ExecutionEngine> EE(builder.create()); if (!EE) { if (!ErrorMsg.empty()) errs() << argv[0] << ": error creating EE: " << ErrorMsg << "\n"; else errs() << argv[0] << ": unknown error creating EE!\n"; exit(1); } std::unique_ptr<LLIObjectCache> CacheManager; if (EnableCacheManager) { CacheManager.reset(new LLIObjectCache(ObjectCacheDir)); EE->setObjectCache(CacheManager.get()); } // Load any additional modules specified on the command line. for (unsigned i = 0, e = ExtraModules.size(); i != e; ++i) { std::unique_ptr<Module> XMod = parseIRFile(ExtraModules[i], Err, Context); if (!XMod) reportError(Err, argv[0]); if (EnableCacheManager) { std::string CacheName("file:"); CacheName.append(ExtraModules[i]); XMod->setModuleIdentifier(CacheName); } EE->addModule(std::move(XMod)); } for (unsigned i = 0, e = ExtraObjects.size(); i != e; ++i) { Expected<object::OwningBinary<object::ObjectFile>> Obj = object::ObjectFile::createObjectFile(ExtraObjects[i]); if (!Obj) { // TODO: Actually report errors helpfully. consumeError(Obj.takeError()); reportError(Err, argv[0]); } object::OwningBinary<object::ObjectFile> &O = Obj.get(); EE->addObjectFile(std::move(O)); } for (unsigned i = 0, e = ExtraArchives.size(); i != e; ++i) { ErrorOr<std::unique_ptr<MemoryBuffer>> ArBufOrErr = MemoryBuffer::getFileOrSTDIN(ExtraArchives[i]); if (!ArBufOrErr) reportError(Err, argv[0]); std::unique_ptr<MemoryBuffer> &ArBuf = ArBufOrErr.get(); Expected<std::unique_ptr<object::Archive>> ArOrErr = object::Archive::create(ArBuf->getMemBufferRef()); if (!ArOrErr) { std::string Buf; raw_string_ostream OS(Buf); logAllUnhandledErrors(ArOrErr.takeError(), OS, ""); OS.flush(); errs() << Buf; exit(1); } std::unique_ptr<object::Archive> &Ar = ArOrErr.get(); object::OwningBinary<object::Archive> OB(std::move(Ar), std::move(ArBuf)); EE->addArchive(std::move(OB)); } // If the target is Cygwin/MingW and we are generating remote code, we // need an extra module to help out with linking. if (RemoteMCJIT && Triple(Mod->getTargetTriple()).isOSCygMing()) { addCygMingExtraModule(*EE, Context, Mod->getTargetTriple()); } // The following functions have no effect if their respective profiling // support wasn't enabled in the build configuration. EE->RegisterJITEventListener( JITEventListener::createOProfileJITEventListener()); EE->RegisterJITEventListener( JITEventListener::createIntelJITEventListener()); if (!NoLazyCompilation && RemoteMCJIT) { errs() << "warning: remote mcjit does not support lazy compilation\n"; NoLazyCompilation = true; } EE->DisableLazyCompilation(NoLazyCompilation); // If the user specifically requested an argv[0] to pass into the program, // do it now. if (!FakeArgv0.empty()) { InputFile = static_cast<std::string>(FakeArgv0); } else { // Otherwise, if there is a .bc suffix on the executable strip it off, it // might confuse the program. if (StringRef(InputFile).endswith(".bc")) InputFile.erase(InputFile.length() - 3); } // Add the module's name to the start of the vector of arguments to main(). InputArgv.insert(InputArgv.begin(), InputFile); // Call the main function from M as if its signature were: // int main (int argc, char **argv, const char **envp) // using the contents of Args to determine argc & argv, and the contents of // EnvVars to determine envp. // Function *EntryFn = Mod->getFunction(EntryFunc); if (!EntryFn) { errs() << '\'' << EntryFunc << "\' function not found in module.\n"; return -1; } // Reset errno to zero on entry to main. errno = 0; int Result = -1; // Sanity check use of remote-jit: LLI currently only supports use of the // remote JIT on Unix platforms. if (RemoteMCJIT) { #ifndef LLVM_ON_UNIX errs() << "Warning: host does not support external remote targets.\n" << " Defaulting to local execution\n"; return -1; #else if (ChildExecPath.empty()) { errs() << "-remote-mcjit requires -mcjit-remote-process.\n"; exit(1); } else if (!sys::fs::can_execute(ChildExecPath)) { errs() << "Unable to find usable child executable: '" << ChildExecPath << "'\n"; return -1; } #endif } if (!RemoteMCJIT) { // If the program doesn't explicitly call exit, we will need the Exit // function later on to make an explicit call, so get the function now. Constant *Exit = Mod->getOrInsertFunction("exit", Type::getVoidTy(Context), Type::getInt32Ty(Context), nullptr); // Run static constructors. if (!ForceInterpreter) { // Give MCJIT a chance to apply relocations and set page permissions. EE->finalizeObject(); } EE->runStaticConstructorsDestructors(false); // Trigger compilation separately so code regions that need to be // invalidated will be known. (void)EE->getPointerToFunction(EntryFn); // Clear instruction cache before code will be executed. if (RTDyldMM) static_cast<SectionMemoryManager*>(RTDyldMM)->invalidateInstructionCache(); // Run main. Result = EE->runFunctionAsMain(EntryFn, InputArgv, envp); // Run static destructors. EE->runStaticConstructorsDestructors(true); // If the program didn't call exit explicitly, we should call it now. // This ensures that any atexit handlers get called correctly. if (Function *ExitF = dyn_cast<Function>(Exit)) { std::vector<GenericValue> Args; GenericValue ResultGV; ResultGV.IntVal = APInt(32, Result); Args.push_back(ResultGV); EE->runFunction(ExitF, Args); errs() << "ERROR: exit(" << Result << ") returned!\n"; abort(); } else { errs() << "ERROR: exit defined with wrong prototype!\n"; abort(); } } else { // else == "if (RemoteMCJIT)" // Remote target MCJIT doesn't (yet) support static constructors. No reason // it couldn't. This is a limitation of the LLI implemantation, not the // MCJIT itself. FIXME. // Lanch the remote process and get a channel to it. std::unique_ptr<FDRawChannel> C = launchRemote(); if (!C) { errs() << "Failed to launch remote JIT.\n"; exit(1); } // Create a remote target client running over the channel. typedef orc::remote::OrcRemoteTargetClient<orc::rpc::RawByteChannel> MyRemote; auto R = ExitOnErr(MyRemote::Create(*C)); // Create a remote memory manager. std::unique_ptr<MyRemote::RCMemoryManager> RemoteMM; ExitOnErr(R->createRemoteMemoryManager(RemoteMM)); // Forward MCJIT's memory manager calls to the remote memory manager. static_cast<ForwardingMemoryManager*>(RTDyldMM)->setMemMgr( std::move(RemoteMM)); // Forward MCJIT's symbol resolution calls to the remote. static_cast<ForwardingMemoryManager*>(RTDyldMM)->setResolver( orc::createLambdaResolver( [](const std::string &Name) { return nullptr; }, [&](const std::string &Name) { if (auto Addr = ExitOnErr(R->getSymbolAddress(Name))) return JITSymbol(Addr, JITSymbolFlags::Exported); return JITSymbol(nullptr); } )); // Grab the target address of the JIT'd main function on the remote and call // it. // FIXME: argv and envp handling. JITTargetAddress Entry = EE->getFunctionAddress(EntryFn->getName().str()); EE->finalizeObject(); DEBUG(dbgs() << "Executing '" << EntryFn->getName() << "' at 0x" << format("%llx", Entry) << "\n"); Result = ExitOnErr(R->callIntVoid(Entry)); // Like static constructors, the remote target MCJIT support doesn't handle // this yet. It could. FIXME. // Delete the EE - we need to tear it down *before* we terminate the session // with the remote, otherwise it'll crash when it tries to release resources // on a remote that has already been disconnected. EE.reset(); // Signal the remote target that we're done JITing. ExitOnErr(R->terminateSession()); } return Result; } std::unique_ptr<FDRawChannel> launchRemote() { #ifndef LLVM_ON_UNIX llvm_unreachable("launchRemote not supported on non-Unix platforms"); #else int PipeFD[2][2]; pid_t ChildPID; // Create two pipes. if (pipe(PipeFD[0]) != 0 || pipe(PipeFD[1]) != 0) perror("Error creating pipe: "); ChildPID = fork(); if (ChildPID == 0) { // In the child... // Close the parent ends of the pipes close(PipeFD[0][1]); close(PipeFD[1][0]); // Execute the child process. std::unique_ptr<char[]> ChildPath, ChildIn, ChildOut; { ChildPath.reset(new char[ChildExecPath.size() + 1]); std::copy(ChildExecPath.begin(), ChildExecPath.end(), &ChildPath[0]); ChildPath[ChildExecPath.size()] = '\0'; std::string ChildInStr = utostr(PipeFD[0][0]); ChildIn.reset(new char[ChildInStr.size() + 1]); std::copy(ChildInStr.begin(), ChildInStr.end(), &ChildIn[0]); ChildIn[ChildInStr.size()] = '\0'; std::string ChildOutStr = utostr(PipeFD[1][1]); ChildOut.reset(new char[ChildOutStr.size() + 1]); std::copy(ChildOutStr.begin(), ChildOutStr.end(), &ChildOut[0]); ChildOut[ChildOutStr.size()] = '\0'; } char * const args[] = { &ChildPath[0], &ChildIn[0], &ChildOut[0], nullptr }; int rc = execv(ChildExecPath.c_str(), args); if (rc != 0) perror("Error executing child process: "); llvm_unreachable("Error executing child process"); } // else we're the parent... // Close the child ends of the pipes close(PipeFD[0][0]); close(PipeFD[1][1]); // Return an RPC channel connected to our end of the pipes. return llvm::make_unique<FDRawChannel>(PipeFD[1][0], PipeFD[0][1]); #endif }
; A133386: Number of forests of labeled rooted trees with n nodes, containing exactly 2 trees of height one, all others having height zero. ; Submitted by Jon Maiga ; 0,0,0,0,12,120,750,3780,16856,69552,272250,1026300,3762132,13498056,47615750,165683700,570024240,1942538592,6566094450,22038141420,73510278380,243854707320,804962754750,2645408201700,8658857196552,28237920483600,91778694166250,297374746703580,960774548807556,3095883594109992,9951171179061750,31912626184722900,102120936367056992,326129285495192256,1039539506992577250,3307630815078372300,10506602824154767260,33320963268762299352,105516431994206091950,333660170580700001220,1053663910975398997560 mov $1,$0 trn $0,1 seq $0,178759 ; Expansion of e.g.f. 3*x*exp(x)*(exp(x)-1)^2. mul $0,$1 div $0,6
/* Copyright (C) 2011 Joseph A. Adams (joeyadams3.14159@gmail.com) All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include "json.h" #include "file.h" #include <assert.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <lua/lua.hpp> #define out_of_memory() do { \ fprintf(stderr, "Out of memory.\n"); \ exit(EXIT_FAILURE); \ } while (0) /* Sadly, strdup is not portable. */ #define json_strdup(str) strdup(str) /* String buffer */ typedef struct { char *cur; char *end; char *start; } SB; static void sb_init(SB *sb) { sb->start = (char*) malloc(17); if (sb->start == nullptr) throw suil::Exception::allocationFailure("json::Object sb_init"); sb->cur = sb->start; sb->end = sb->start + 16; } /* sb and need may be evaluated multiple times. */ #define sb_need(sb, need) do { \ if ((sb)->end - (sb)->cur < (need)) \ sb_grow(sb, need); \ } while (0) static void sb_grow(SB *sb, int need) { size_t length = sb->cur - sb->start; size_t alloc = sb->end - sb->start; do { alloc *= 2; } while (alloc < length + need); sb->start = (char*) realloc(sb->start, alloc + 1); if (sb->start == nullptr) out_of_memory(); sb->cur = sb->start + length; sb->end = sb->start + alloc; } static char *sb_finish(SB *sb) { *sb->cur = 0; assert(sb->start <= sb->cur && strlen(sb->start) == (size_t)(sb->cur - sb->start)); return sb->start; } static void sb_free(SB *sb) { free(sb->start); } /* * Unicode helper functions * * These are taken from the ccan/charset module and customized a bit. * Putting them here means the compiler can (choose to) inline them, * and it keeps ccan/json from having a dependency. */ /* * Type for Unicode codepoints. * We need our own because wchar_t might be 16 bits. */ typedef uint32_t uchar_t; /* * Validate a single UTF-8 character starting at @s. * The string must be null-terminated. * * If it's valid, return its length (1 thru 4). * If it's invalid or clipped, return 0. * * This function implements the syntax given in RFC3629, which is * the same as that given in The Unicode Standard, Version 6.0. * * It has the following properties: * * * All codepoints U+0000..U+10FFFF may be encoded, * except for U+D800..U+DFFF, which are reserved * for UTF-16 surrogate pair encoding. * * UTF-8 byte sequences longer than 4 bytes are not permitted, * as they exceed the range of Unicode. * * The sixty-six Unicode "non-characters" are permitted * (namely, U+FDD0..U+FDEF, U+xxFFFE, and U+xxFFFF). */ static int utf8_validate_cz(const char *s) { unsigned char c = *s++; if (c <= 0x7F) { /* 00..7F */ return 1; } else if (c <= 0xC1) { /* 80..C1 */ /* Disallow overlong 2-byte sequence. */ return 0; } else if (c <= 0xDF) { /* C2..DF */ /* Make sure subsequent byte is in the range 0x80..0xBF. */ if (((unsigned char)*s++ & 0xC0) != 0x80) return 0; return 2; } else if (c <= 0xEF) { /* E0..EF */ /* Disallow overlong 3-byte sequence. */ if (c == 0xE0 && (unsigned char)*s < 0xA0) return 0; /* Disallow U+D800..U+DFFF. */ if (c == 0xED && (unsigned char)*s > 0x9F) return 0; /* Make sure subsequent bytes are in the range 0x80..0xBF. */ if (((unsigned char)*s++ & 0xC0) != 0x80) return 0; if (((unsigned char)*s++ & 0xC0) != 0x80) return 0; return 3; } else if (c <= 0xF4) { /* F0..F4 */ /* Disallow overlong 4-byte sequence. */ if (c == 0xF0 && (unsigned char)*s < 0x90) return 0; /* Disallow codepoints beyond U+10FFFF. */ if (c == 0xF4 && (unsigned char)*s > 0x8F) return 0; /* Make sure subsequent bytes are in the range 0x80..0xBF. */ if (((unsigned char)*s++ & 0xC0) != 0x80) return 0; if (((unsigned char)*s++ & 0xC0) != 0x80) return 0; if (((unsigned char)*s++ & 0xC0) != 0x80) return 0; return 4; } else { /* F5..FF */ return 0; } } /* Validate a null-terminated UTF-8 string. */ static bool utf8_validate(const char *s) { int len; for (; *s != 0; s += len) { len = utf8_validate_cz(s); if (len == 0) return false; } return true; } /* * Read a single UTF-8 character starting at @s, * returning the length, in bytes, of the character read. * * This function assumes input is valid UTF-8, * and that there are enough characters in front of @s. */ static int utf8_read_char(const char *s, uchar_t *out) { const auto *c = (const unsigned char*) s; if (!utf8_validate_cz(s)) throw suil::Exception::create("string '", s, "' is not a valid utf8 string"); if (c[0] <= 0x7F) { /* 00..7F */ *out = c[0]; return 1; } else if (c[0] <= 0xDF) { /* C2..DF (unless input is invalid) */ *out = ((uchar_t)c[0] & 0x1F) << 6 | ((uchar_t)c[1] & 0x3F); return 2; } else if (c[0] <= 0xEF) { /* E0..EF */ *out = ((uchar_t)c[0] & 0xF) << 12 | ((uchar_t)c[1] & 0x3F) << 6 | ((uchar_t)c[2] & 0x3F); return 3; } else { /* F0..F4 (unless input is invalid) */ *out = ((uchar_t)c[0] & 0x7) << 18 | ((uchar_t)c[1] & 0x3F) << 12 | ((uchar_t)c[2] & 0x3F) << 6 | ((uchar_t)c[3] & 0x3F); return 4; } } /* * Write a single UTF-8 character to @s, * returning the length, in bytes, of the character written. * * @unicode must be U+0000..U+10FFFF, but not U+D800..U+DFFF. * * This function will write up to 4 bytes to @out. */ static int utf8_write_char(uchar_t unicode, char *out) { unsigned char *o = (unsigned char*) out; if (!(unicode <= 0x10FFFF && !(unicode >= 0xD800 && unicode <= 0xDFFF))) throw suil::Exception::create("'", unicode, "' is not a valid unicode character"); if (unicode <= 0x7F) { /* U+0000..U+007F */ *o++ = unicode; return 1; } else if (unicode <= 0x7FF) { /* U+0080..U+07FF */ *o++ = 0xC0 | unicode >> 6; *o++ = 0x80 | (unicode & 0x3F); return 2; } else if (unicode <= 0xFFFF) { /* U+0800..U+FFFF */ *o++ = 0xE0 | unicode >> 12; *o++ = 0x80 | (unicode >> 6 & 0x3F); *o++ = 0x80 | (unicode & 0x3F); return 3; } else { /* U+10000..U+10FFFF */ *o++ = 0xF0 | unicode >> 18; *o++ = 0x80 | (unicode >> 12 & 0x3F); *o++ = 0x80 | (unicode >> 6 & 0x3F); *o++ = 0x80 | (unicode & 0x3F); return 4; } } /* * Compute the Unicode codepoint of a UTF-16 surrogate pair. * * @uc should be 0xD800..0xDBFF, and @lc should be 0xDC00..0xDFFF. * If they aren't, this function returns false. */ static bool from_surrogate_pair(uint16_t uc, uint16_t lc, uchar_t *unicode) { if (uc >= 0xD800 && uc <= 0xDBFF && lc >= 0xDC00 && lc <= 0xDFFF) { *unicode = 0x10000 + ((((uchar_t)uc & 0x3FF) << 10) | (lc & 0x3FF)); return true; } else { return false; } } /* * Construct a UTF-16 surrogate pair given a Unicode codepoint. * * @unicode must be U+10000..U+10FFFF. */ static void to_surrogate_pair(uchar_t unicode, uint16_t *uc, uint16_t *lc) { uchar_t n; if (!(unicode >= 0x10000 && unicode <= 0x10FFFF)) throw suil::Exception::create("'", unicode, "' is not a valid unicode character"); n = unicode - 0x10000; *uc = ((n >> 10) & 0x3FF) | 0xD800; *lc = (n & 0x3FF) | 0xDC00; } #define is_space(c) ((c) == '\t' || (c) == '\n' || (c) == '\r' || (c) == ' ') #define is_digit(c) ((c) >= '0' && (c) <= '9') static bool parse_value (const char **sp, JsonNode **out); static bool parse_string (const char **sp, char **out); static bool parse_number (const char **sp, double *out); static bool parse_array (const char **sp, JsonNode **out); static bool parse_object (const char **sp, JsonNode **out); static bool parse_hex16 (const char **sp, uint16_t *out); static bool expect_literal (const char **sp, const char *str); static void skip_space (const char **sp); static void emit_value (iod::encode_stream& out, const JsonNode *node); static void emit_value_indented (iod::encode_stream& out, const JsonNode *node, const char *space, int indent_level); static void emit_string (iod::encode_stream& out, const char *str); static void emit_number (iod::encode_stream& out, double num); static void emit_array (iod::encode_stream& out, const JsonNode *array); static void emit_array_indented (iod::encode_stream& out, const JsonNode *array, const char *space, int indent_level); static void emit_object (iod::encode_stream& out, const JsonNode *object); static void emit_object_indented (iod::encode_stream& out, const JsonNode *object, const char *space, int indent_level); static int write_hex16(iod::encode_stream& out, uint16_t val); static JsonNode *mknode(JsonTag tag); static void append_node(JsonNode *parent, JsonNode *child); static void prepend_node(JsonNode *parent, JsonNode *child); static void append_member(JsonNode *object, char *key, JsonNode *value); /* Assertion-friendly validity checks */ static bool tag_is_valid(unsigned int tag); static bool number_is_valid(const char *num); static void json_delete(JsonNode *node); static JsonNode *json_decode(const char *json) { const char *s = json; JsonNode *ret; skip_space(&s); if (!parse_value(&s, &ret)) return nullptr; skip_space(&s); if (*s != 0) { json_delete(ret); return nullptr; } return ret; } static void json_delete(JsonNode *node) { if (node != nullptr) { json_remove_from_parent(node); switch (node->tag) { case JSON_STRING: free(node->string_); break; case JSON_ARRAY: case JSON_OBJECT: { JsonNode *child, *next; for (child = node->children.head; child != nullptr; child = next) { next = child->next; json_delete(child); } break; } default:; } free(node); } } bool json_validate(const char *json) { const char *s = json; skip_space(&s); if (!parse_value(&s, nullptr)) return false; skip_space(&s); if (*s != 0) return false; return true; } JsonNode *json_find_element(JsonNode *array, int index) { JsonNode *element; int i = 0; if (array == nullptr || array->tag != JSON_ARRAY) return nullptr; json_foreach(element, array) { if (i == index) return element; i++; } return nullptr; } JsonNode *json_find_member(JsonNode *object, const char *name) { JsonNode *member; if (object == nullptr || object->tag != JSON_OBJECT) return nullptr; json_foreach(member, object) if (strcmp(member->key, name) == 0) return member; return nullptr; } JsonNode *json_find_member(JsonNode *object, const char *key, size_t keyLen) { JsonNode *member; if (object == nullptr || object->tag != JSON_OBJECT) return nullptr; json_foreach(member, object) if (strncmp(member->key, key, keyLen) == 0) return member; return nullptr; } JsonNode *json_first_child(const JsonNode *node) { if (node != nullptr && (node->tag == JSON_ARRAY || node->tag == JSON_OBJECT)) return node->children.head; return nullptr; } static JsonNode *mknode(JsonTag tag) { JsonNode *ret = (JsonNode*) calloc(1, sizeof(JsonNode)); if (ret == nullptr) out_of_memory(); ret->tag = tag; return ret; } JsonNode *json_mknull(void) { return mknode(JSON_NULL); } JsonNode *json_mkbool(bool b) { JsonNode *ret = mknode(JSON_BOOL); ret->bool_ = b; return ret; } static JsonNode *mkstring(char *s) { JsonNode *ret = mknode(JSON_STRING); ret->string_ = s; return ret; } JsonNode *json_mkstring(const char *s) { return mkstring(json_strdup(s)); } JsonNode *json_mknstring(const char *s, size_t size) { return mkstring(strndup(s, size)); } JsonNode *json_mknumber(double n) { JsonNode *node = mknode(JSON_NUMBER); node->number_ = n; return node; } JsonNode *json_mkarray(void) { return mknode(JSON_ARRAY); } JsonNode *json_mkobject(void) { return mknode(JSON_OBJECT); } static void append_node(JsonNode *parent, JsonNode *child) { child->parent = parent; child->prev = parent->children.tail; child->next = nullptr; if (parent->children.tail != nullptr) parent->children.tail->next = child; else parent->children.head = child; parent->children.tail = child; } static void prepend_node(JsonNode *parent, JsonNode *child) { child->parent = parent; child->prev = nullptr; child->next = parent->children.head; if (parent->children.head != nullptr) parent->children.head->prev = child; else parent->children.tail = child; parent->children.head = child; } static void append_member(JsonNode *object, char *key, JsonNode *value) { value->key = key; append_node(object, value); } void json_append_element(JsonNode *array, JsonNode *element) { assert(array->tag == JSON_ARRAY); assert(element->parent == nullptr); append_node(array, element); } void json_prepend_element(JsonNode *array, JsonNode *element) { assert(array->tag == JSON_ARRAY); assert(element->parent == nullptr); prepend_node(array, element); } void json_append_member(JsonNode *object, const char *key, JsonNode *value) { assert(object->tag == JSON_OBJECT); assert(value->parent == nullptr); append_member(object, json_strdup(key), value); } void json_prepend_member(JsonNode *object, const char *key, JsonNode *value) { assert(object->tag == JSON_OBJECT); assert(value->parent == nullptr); value->key = json_strdup(key); prepend_node(object, value); } void json_remove_from_parent(JsonNode *node) { JsonNode *parent = node->parent; if (parent != nullptr) { if (node->prev != nullptr) node->prev->next = node->next; else parent->children.head = node->next; if (node->next != nullptr) node->next->prev = node->prev; else parent->children.tail = node->prev; free(node->key); node->parent = nullptr; node->prev = node->next = nullptr; node->key = nullptr; } } static bool parse_value(const char **sp, JsonNode **out) { const char *s = *sp; switch (*s) { case 'n': if (expect_literal(&s, "null")) { if (out) *out = json_mknull(); *sp = s; return true; } return false; case 'f': if (expect_literal(&s, "false")) { if (out) *out = json_mkbool(false); *sp = s; return true; } return false; case 't': if (expect_literal(&s, "true")) { if (out) *out = json_mkbool(true); *sp = s; return true; } return false; case '"': { char *str; if (parse_string(&s, out ? &str : nullptr)) { if (out) *out = mkstring(str); *sp = s; return true; } return false; } case '[': if (parse_array(&s, out)) { *sp = s; return true; } return false; case '{': if (parse_object(&s, out)) { *sp = s; return true; } return false; default: { double num; if (parse_number(&s, out ? &num : nullptr)) { if (out) *out = json_mknumber(num); *sp = s; return true; } return false; } } } static bool parse_array(const char **sp, JsonNode **out) { const char *s = *sp; JsonNode *ret = out ? json_mkarray() : nullptr; JsonNode *element; if (*s++ != '[') goto failure; skip_space(&s); if (*s == ']') { s++; goto success; } for (;;) { if (!parse_value(&s, out ? &element : nullptr)) goto failure; skip_space(&s); if (out) json_append_element(ret, element); if (*s == ']') { s++; goto success; } if (*s++ != ',') goto failure; skip_space(&s); } success: *sp = s; if (out) *out = ret; return true; failure: json_delete(ret); return false; } static bool parse_object(const char **sp, JsonNode **out) { const char *s = *sp; JsonNode *ret = out ? json_mkobject() : nullptr; char *key; JsonNode *value; if (*s++ != '{') goto failure; skip_space(&s); if (*s == '}') { s++; goto success; } for (;;) { if (!parse_string(&s, out ? &key : nullptr)) goto failure; skip_space(&s); if (*s++ != ':') goto failure_free_key; skip_space(&s); if (!parse_value(&s, out ? &value : nullptr)) goto failure_free_key; skip_space(&s); if (out) append_member(ret, key, value); if (*s == '}') { s++; goto success; } if (*s++ != ',') goto failure; skip_space(&s); } success: *sp = s; if (out) *out = ret; return true; failure_free_key: if (out) free(key); failure: json_delete(ret); return false; } bool parse_string(const char **sp, char **out) { const char *s = *sp; SB sb; char throwaway_buffer[4]; /* enough space for a UTF-8 character */ char *b; if (*s++ != '"') return false; if (out) { sb_init(&sb); sb_need(&sb, 4); b = sb.cur; } else { b = throwaway_buffer; } while (*s != '"') { unsigned char c = *s++; /* Parse next character, and write it to b. */ if (c == '\\') { c = *s++; switch (c) { case '"': case '\\': case '/': *b++ = c; break; case 'b': *b++ = '\b'; break; case 'f': *b++ = '\f'; break; case 'n': *b++ = '\n'; break; case 'r': *b++ = '\r'; break; case 't': *b++ = '\t'; break; case 'u': { uint16_t uc, lc; uchar_t unicode; if (!parse_hex16(&s, &uc)) goto failed; if (uc >= 0xD800 && uc <= 0xDFFF) { /* Handle UTF-16 surrogate pair. */ if (*s++ != '\\' || *s++ != 'u' || !parse_hex16(&s, &lc)) goto failed; /* Incomplete surrogate pair. */ if (!from_surrogate_pair(uc, lc, &unicode)) goto failed; /* Invalid surrogate pair. */ } else if (uc == 0) { /* Disallow "\u0000". */ goto failed; } else { unicode = uc; } b += utf8_write_char(unicode, b); break; } default: /* Invalid escape */ goto failed; } } else if (c <= 0x1F) { /* Control characters are not allowed in string literals. */ goto failed; } else { /* Validate and echo a UTF-8 character. */ int len; s--; len = utf8_validate_cz(s); if (len == 0) goto failed; /* Invalid UTF-8 character. */ while (len--) *b++ = *s++; } /* * Update sb to know about the new bytes, * and set up b to write another character. */ if (out) { sb.cur = b; sb_need(&sb, 4); b = sb.cur; } else { b = throwaway_buffer; } } s++; if (out) *out = sb_finish(&sb); *sp = s; return true; failed: if (out) sb_free(&sb); return false; } /* * The JSON spec says that a number shall follow this precise pattern * (spaces and quotes added for readability): * '-'? (0 | [1-9][0-9]*) ('.' [0-9]+)? ([Ee] [+-]? [0-9]+)? * * However, some JSON parsers are more liberal. For instance, PHP accepts * '.5' and '1.'. JSON.parse accepts '+3'. * * This function takes the strict approach. */ bool parse_number(const char **sp, double *out) { const char *s = *sp; /* '-'? */ if (*s == '-') s++; /* (0 | [1-9][0-9]*) */ if (*s == '0') { s++; } else { if (!is_digit(*s)) return false; do { s++; } while (is_digit(*s)); } /* ('.' [0-9]+)? */ if (*s == '.') { s++; if (!is_digit(*s)) return false; do { s++; } while (is_digit(*s)); } /* ([Ee] [+-]? [0-9]+)? */ if (*s == 'E' || *s == 'e') { s++; if (*s == '+' || *s == '-') s++; if (!is_digit(*s)) return false; do { s++; } while (is_digit(*s)); } if (out) *out = strtod(*sp, nullptr); *sp = s; return true; } static void skip_space(const char **sp) { const char *s = *sp; while (is_space(*s)) s++; *sp = s; } static void emit_value(iod::encode_stream& out, const JsonNode *node) { assert(tag_is_valid(node->tag)); switch (node->tag) { case JSON_NULL: out << "null"; break; case JSON_BOOL: out << (node->bool_ ? "true" : "false"); break; case JSON_STRING: emit_string(out, node->string_); break; case JSON_NUMBER: emit_number(out, node->number_); break; case JSON_ARRAY: emit_array(out, node); break; case JSON_OBJECT: emit_object(out, node); break; default: assert(false); } } void emit_value_indented(iod::encode_stream& out, const JsonNode *node, const char *space, int indent_level) { if (!tag_is_valid(node->tag)) { throw suil::Exception::create("Attempt to encode an invalid json node"); } switch (node->tag) { case JSON_NULL: out << "null"; break; case JSON_BOOL: out << (node->bool_ ? "true" : "false"); break; case JSON_STRING: emit_string(out, node->string_); break; case JSON_NUMBER: emit_number(out, node->number_); break; case JSON_ARRAY: emit_array_indented(out, node, space, indent_level); break; case JSON_OBJECT: emit_object_indented(out, node, space, indent_level); break; default: assert(false); } } static void emit_array(iod::encode_stream& out, const JsonNode *array) { const JsonNode *element; out << '['; json_foreach(element, array) { emit_value(out, element); if (element->next != nullptr) out << ','; } out << ']'; } static void emit_array_indented(iod::encode_stream& out, const JsonNode *array, const char *space, int indent_level) { const JsonNode *element = array->children.head; int i; if (element == nullptr) { out << "[]"; return; } out << "[\n"; while (element != nullptr) { for (i = 0; i < indent_level + 1; i++) out << space; emit_value_indented(out, element, space, indent_level + 1); element = element->next; out << (element != nullptr ? ",\n" : "\n"); } for (i = 0; i < indent_level; i++) out << space; out << ']'; } static void emit_object(iod::encode_stream& out, const JsonNode *object) { const JsonNode *member; out << '{'; json_foreach(member, object) { emit_string(out, member->key); out << ':'; emit_value(out, member); if (member->next != nullptr) out << ','; } out << '}'; } static void emit_object_indented(iod::encode_stream& out, const JsonNode *object, const char *space, int indent_level) { const JsonNode *member = object->children.head; int i; if (member == nullptr) { out << "{}"; return; } out << "{\n"; while (member != nullptr) { for (i = 0; i < indent_level + 1; i++) out << space; emit_string(out, member->key); out << ": "; emit_value_indented(out, member, space, indent_level + 1); member = member->next; out << (member != nullptr ? ",\n" : "\n"); } for (i = 0; i < indent_level; i++) out << space; out << '}'; } void emit_string(iod::encode_stream& out, const char *str) { bool escape_unicode = false; const char *s = str; if (!utf8_validate(str)) throw suil::Exception::create("'", str, "' is not a valid utf8 string"); out << '"'; while (*s != 0) { unsigned char c = *s++; /* Encode the next character, and write it to b. */ switch (c) { case '"': out << '\\'; out << '"'; break; case '\\': out << '\\'; out << '\\'; break; case '\b': out << '\\'; out << 'b'; break; case '\f': out << '\\'; out << 'f'; break; case '\n': out << '\\'; out << 'n'; break; case '\r': out << '\\'; out << 'r'; break; case '\t': out << '\\'; out << 't'; break; default: { int len; s--; len = utf8_validate_cz(s); if (len == 0) { /* * Handle invalid UTF-8 character gracefully in production * by writing a replacement character (U+FFFD) * and skipping a single byte. * * This should never happen when assertions are enabled * due to the assertion at the beginning of this function. */ assert(false); if (escape_unicode) { out << "\\uFFFD"; } else { out << 0xEF; out << 0xBF; out << 0xBD; } s++; } else if (c < 0x1F || (c >= 0x80 && escape_unicode)) { /* Encode using \u.... */ uint32_t unicode; s += utf8_read_char(s, &unicode); if (unicode <= 0xFFFF) { out << '\\'; out << 'u'; write_hex16(out, unicode); } else { /* Produce a surrogate pair. */ uint16_t uc, lc; if (unicode > 0x10FFFF) throw suil::Exception::create("'...", s, "' is not a valid unicode string"); to_surrogate_pair(unicode, &uc, &lc); out << '\\'; out << 'u'; write_hex16(out, uc); out << '\\'; out << 'u'; write_hex16(out, lc); } } else { /* Write the character directly. */ while (len--) out << *s++; } break; } } } out << '"'; } static void emit_number(iod::encode_stream& out, double num) { /* * This isn't exactly how JavaScript renders numbers, * but it should produce valid JSON for reasonable numbers * preserve precision well enough, and avoid some oddities * like 0.3 -> 0.299999999999999988898 . */ char buf[64]; sprintf(buf, "%.16g", num); if (number_is_valid(buf)) out << num; else out << "null"; } static bool tag_is_valid(unsigned int tag) { return (/* tag >= JSON_NULL && */ tag <= JSON_OBJECT); } static bool number_is_valid(const char *num) { return (parse_number(&num, nullptr) && *num == '\0'); } static bool expect_literal(const char **sp, const char *str) { const char *s = *sp; while (*str != '\0') if (*s++ != *str++) return false; *sp = s; return true; } /* * Parses exactly 4 hex characters (capital or lowercase). * Fails if any input chars are not [0-9A-Fa-f]. */ static bool parse_hex16(const char **sp, uint16_t *out) { const char *s = *sp; uint16_t ret = 0; uint16_t i; uint16_t tmp; char c; for (i = 0; i < 4; i++) { c = *s++; if (c >= '0' && c <= '9') tmp = c - '0'; else if (c >= 'A' && c <= 'F') tmp = c - 'A' + 10; else if (c >= 'a' && c <= 'f') tmp = c - 'a' + 10; else return false; ret <<= 4; ret += tmp; } if (out) *out = ret; *sp = s; return true; } /* * Encodes a 16-bit number into hexadecimal, * writing exactly 4 hex chars. */ static int write_hex16(iod::encode_stream& out, uint16_t val) { const char *hex = "0123456789ABCDEF"; out.append(hex[(val >> 12) & 0xF]); out.append(hex[(val >> 8) & 0xF]); out.append(hex[(val >> 4) & 0xF]); out.append(hex[ val & 0xF]); return 4; } bool json_check(const JsonNode *node, char errmsg[256]) { #define problem(...) do { \ if (errmsg != nullptr) \ snprintf(errmsg, 256, __VA_ARGS__); \ return false; \ } while (0) if (node->key != nullptr && !utf8_validate(node->key)) problem("key contains invalid UTF-8"); if (!tag_is_valid(node->tag)) problem("tag is invalid (%u)", node->tag); if (node->tag == JSON_BOOL) { if (node->bool_ != false && node->bool_ != true) problem("bool_ is neither false (%d) nor true (%d)", (int)false, (int)true); } else if (node->tag == JSON_STRING) { if (node->string_ == nullptr) problem("string_ is nullptr"); if (!utf8_validate(node->string_)) problem("string_ contains invalid UTF-8"); } else if (node->tag == JSON_ARRAY || node->tag == JSON_OBJECT) { JsonNode *head = node->children.head; JsonNode *tail = node->children.tail; if (head == nullptr || tail == nullptr) { if (head != nullptr) problem("tail is nullptr, but head is not"); if (tail != nullptr) problem("head is nullptr, but tail is not"); } else { JsonNode *child; JsonNode *last = nullptr; if (head->prev != nullptr) problem("First child's prev pointer is not nullptr"); for (child = head; child != nullptr; last = child, child = child->next) { if (child == node) problem("node is its own child"); if (child->next == child) problem("child->next == child (cycle)"); if (child->next == head) problem("child->next == head (cycle)"); if (child->parent != node) problem("child does not point back to parent"); if (child->next != nullptr && child->next->prev != child) problem("child->next does not point back to child"); if (node->tag == JSON_ARRAY && child->key != nullptr) problem("Array element's key is not nullptr"); if (node->tag == JSON_OBJECT && child->key == nullptr) problem("Object member's key is nullptr"); if (!json_check(child, errmsg)) return false; } if (last != tail) problem("tail does not match pointer found by starting at head and following next links"); } } return true; #undef problem } namespace { int luaEnv(lua_State *L) { if (!lua_isstring(L, 1)) { return luaL_error( L, "'env' function expects an environment name"); } if (lua_gettop(L) == 2 and !lua_isboolean(L, 2)) { return luaL_error( L, "env(name, required:false) parameter must be boolean"); } auto name = luaL_checkstring(L, 1); auto val = std::getenv(name); if (val == nullptr) { return luaL_error( L, "env(%s, true): environment variable required but does not exist", name); } lua_pushstring(L, val); return 1; } } namespace suil::json { Object::Object() : mNode(mknode(JsonTag::JSON_NULL)) {} Object::Object(bool b) : mNode(json_mkbool(b)) {} Object::Object(double d) : mNode(json_mknumber(d)) {} Object::Object(const char *str) : mNode(json_mkstring(str)) {} Object::Object(const suil::String &str) : mNode(json_mknstring(str.data(), str.size())) {} Object::Object(const std::string &str) : mNode(json_mknstring(str.data(), str.size())) {} Object::Object(suil::json::Array_t) : mNode(json_mkarray()) {} Object::Object(suil::json::Object_t) : mNode(json_mkobject()) {} void Object::push(suil::json::Object &&o) { if (mNode == nullptr || mNode->tag != JsonTag::JSON_ARRAY) throw Exception::create("json::Object::push - object is not a JSON array"); json_append_element(mNode, o.mNode); o.ref = true; } void Object::set(const char *key, suil::json::Object &&o) { if (mNode == nullptr || mNode->tag != JsonTag::JSON_OBJECT) throw Exception::create("json::Object::set - object is not a JSON object"); json_append_member(mNode, key, o.mNode); o.ref = true; } Object Object::operator[](int index) const { if (mNode == nullptr || mNode->tag != JsonTag::JSON_ARRAY) throw Exception::create("json::Object::[index] - object is not a JSON array"); Object obj(json_find_element(mNode, index)); return obj; } Object Object::operator()(const char *key, bool throwNotFound) const { const char *s = key, *p = key; Object obj{mNode}; while ((p = strchr(s, '.')) != nullptr) { String part{s, (size_t)(p-s), false}; obj = obj.get(part, throwNotFound); if (obj.empty() || !obj.isObject()) { if (throwNotFound) throw Exception::create("Key '", key, "'is not an object"); else return Object{nullptr}; } s = p+1; } String tmp{s}; if (tmp == "*") { return std::move(obj); } return obj.get(s, throwNotFound); } Object Object::operator[](const suil::String &key) const { return Ego.get(key, true); } Object Object::get(const suil::String &key, bool shouldThrow) const { if (mNode == nullptr || mNode->tag != JsonTag::JSON_OBJECT) { if (shouldThrow) throw Exception::create("json::Object::[index] - object is not a JSON object"); else return Object{nullptr}; } Object obj(json_find_member(mNode, key.data(), key.size())); return obj; } Object::operator bool() const { return !Ego.empty(); } Object::operator double() const { if (mNode == nullptr || mNode->tag != JsonTag::JSON_NUMBER) throw Exception::create("json::Object - object is not a number"); return mNode->number_; } Object::operator const char*() const { if (mNode == nullptr || mNode->tag != JsonTag::JSON_STRING) throw Exception::create("json::Object - object is not a string"); return mNode->string_; } bool Object::empty() const { if (mNode == nullptr || mNode->tag == JsonTag::JSON_NULL) return true; if (mNode->tag == JsonTag::JSON_STRING) return mNode->string_? strlen(mNode->string_) == 0 : true; if (mNode->tag == JsonTag::JSON_BOOL) return !mNode->bool_; if (mNode->tag == JsonTag::JSON_OBJECT || mNode->tag == JsonTag::JSON_ARRAY) return mNode->children.head == nullptr; return false; } bool Object::isNull() const { return mNode == nullptr || mNode->tag == JsonTag::JSON_NULL; } bool Object::isBool() const { return mNode != nullptr && mNode->tag == JsonTag::JSON_BOOL; } bool Object::isNumber() const { return mNode != nullptr && mNode->tag == JsonTag::JSON_NUMBER; } bool Object::isString() const { return mNode != nullptr && mNode->tag == JsonTag::JSON_STRING; } bool Object::isArray() const { return mNode != nullptr && mNode->tag == JsonTag::JSON_ARRAY; } bool Object::isObject() const { return mNode != nullptr && mNode->tag == JsonTag::JSON_OBJECT; } JsonTag Object::type() const { return mNode? mNode->tag : JsonTag::JSON_BOOL; } Object Object::push(const suil::json::Array_t &) { if (mNode == nullptr || mNode->tag != JsonTag::JSON_ARRAY) /* valid node */ throw Exception::create("json::Object::push - object is not a JSON array"); /* create array node and append it */ Object o(json::Arr); json_append_element(mNode, o.mNode); o.ref = true; return o; } Object Object::push(const suil::json::Object_t&) { if (mNode == nullptr || mNode->tag != JsonTag::JSON_ARRAY) /* valid node */ throw Exception::create("json::Object::push - object is not a JSON array"); /* create array node and append it */ Object o(json::Obj); json_append_element(mNode, o.mNode); o.ref = true; return o; } Object Object::set(const char *key, const suil::json::Object_t &) { if (mNode == nullptr || mNode->tag != JsonTag::JSON_OBJECT) /* valid node */ throw Exception::create("json::Object::set - object is not a JSON object"); /* create array node and append it */ Object o(json::Obj); json_append_member(mNode, key, o.mNode); o.ref = true; return o; } Object Object::set(const char *key, const suil::json::Array_t &) { if (mNode == nullptr || mNode->tag != JsonTag::JSON_OBJECT) /* valid node */ throw Exception::create("json::Object::set - object is not a JSON object"); /* create array node and append it */ Object o(json::Arr); json_append_member(mNode, key, o.mNode); o.ref = true; return o; } void Object::encode(iod::encode_stream &ss) const { /* encode json object */ emit_value(ss, mNode); } Object Object::decode(const char *str, size_t& sz) { JsonNode *ret; const char *s = str; skip_space(&s); if (!parse_value(&s, &ret)) { /* parsing json string failed */ throw Exception::create("json::Object::decode invalid json string at ", (s-str)); } skip_space(&s); sz = s-str; return Object(ret, false); } void Object::operator|(suil::json::Object::ArrayEnumerator f) const { if (mNode == nullptr || mNode->tag != JsonTag::JSON_ARRAY) /* valid node */ throw Exception::create("json::Object::enumerate - object is not a JSON array"); JsonNode *node{nullptr}; json_foreach(node, mNode) { if (f(Object(node, true))) break; } } void Object::operator|(suil::json::Object::ObjectEnumerator f) const { if (mNode == nullptr || mNode->tag != JsonTag::JSON_OBJECT) /* valid node */ throw Exception::create("json::Object::enumerate - object is not a JSON object"); JsonNode *node{nullptr}; json_foreach(node, mNode) { if (f(node->key, Object(node, true))) break; } } bool Object::operator==(const Object &other) const { if (other.type() != Ego.type()) return false; if (other.empty() && Ego.empty()) return true; switch (other.type()) { case JSON_NUMBER: return other.mNode->number_ == Ego.mNode->number_; case JSON_BOOL: return other.mNode->bool_ == Ego.mNode->bool_; case JSON_STRING: return String{other.mNode->string_} == String{Ego.mNode->string_}; case JSON_ARRAY: { auto ai = Ego.begin(); auto bi = other.end(); while (ai != Ego.end()) { if (bi == other.end()) return false; if (!((*ai).second == (*bi).second)) return false; ++ai; ++bi; } return bi == other.end(); break; } case JSON_OBJECT: { for (auto[key, obj]: Ego) { auto tmp = other[key]; if (tmp.isNull()) return false; if (!(obj == tmp)) return false; } return true; break; } default: return false; } } Object::iterator Object::iterator::operator++() { if (mNode) mNode = mNode->next; return Ego; } const std::pair<const char*,Object> Object::iterator::operator*() const { return std::make_pair(mNode? mNode->key:nullptr, Object(mNode)); } Object::iterator Object::begin() { if (Ego.isArray() || Ego.isObject()) return iterator(mNode->children.head); return end(); } Object::const_iterator Object::begin() const { if (Ego.isArray() || Ego.isObject()) return const_iterator(mNode->children.head); return end(); } Object& Object::operator=(suil::json::Object &&o) noexcept { if (this != &o) { if (mNode && !ref) json_delete(mNode); mNode = o.mNode; ref = o.ref; o.mNode = nullptr; } return Ego; } Object Object::fromLuaFile(const suil::String &file) { if (utils::fs::exists(file())) { try { auto str = utils::fs::readall(file(), true); return Object::fromLuaString(str); } catch (...) { serror("failed to load lua '%s' to json: %s", file(), Exception::fromCurrent().what()); } } return Object{nullptr}; } static Object parseLuaTable(lua_State* L); static Object parseLuaValue(lua_State* L) { Object obj{nullptr}; auto type = lua_type(L, -1); switch (type) { case LUA_TBOOLEAN: obj = Object(lua_toboolean(L, -1) != 0); break; case LUA_TNUMBER: obj = Object(lua_tonumber(L, -1)); break; case LUA_TSTRING: obj = Object(lua_tostring(L, -1)); break; case LUA_TTABLE: obj = parseLuaTable(L); break; default: throw Exception::create("type '", luaL_typename(L, -1), "' is not supported"); } return std::move(obj); } Object parseLuaTable(lua_State* L) { Object obj(Obj); lua_pushnil(L); bool first{true}, isArray{false}; while (lua_next(L, -2) != 0) { if (first) { if (lua_type(L, -2) == LUA_TNUMBER) { isArray = true; obj = Object(Arr); } first = false; } if (isArray) { if (lua_type(L, -2) != LUA_TNUMBER) { throw Exception::create("Invalid config file, array indexes can only be numbers"); } obj.push(parseLuaValue(L)); } else { if (lua_type(L, -2) != LUA_TSTRING) { throw Exception::create("Invalid config file, array indexes can only be numbers"); } auto key = lua_tostring(L, -2); obj.set(key, parseLuaValue(L)); } lua_pop(L, 1); } return std::move(obj); } Object Object::fromLuaTable(lua_State *L, int index) { int top = lua_gettop(L); if (index && top != index) // bring value to top of stack lua_pushvalue(L, index); Object obj{nullptr}; auto _pop = [L,&top]() { auto diff = lua_gettop(L) - top; if (diff > 0) { lua_pop(L, diff); } }; try { obj = parseLuaValue(L); _pop(); } catch (...) { _pop(); throw; } return std::move(obj); } Object Object::fromLuaString(const suil::String &script) { lua_State *L{luaL_newstate()}; luaL_openlibs(L); lua_register(L, "env", luaEnv); defer(L, { if (L != nullptr) lua_close(L); }); if (luaL_loadstring(L, script()) || lua_pcall(L, 0, LUA_MULTRET, 0)) { // loading configuration file failed throw Exception::create(lua_tostring(L, -1)); } lua_getglobal(L, "app"); if (lua_type(L, -1) != LUA_TTABLE) { // config invalid throw Exception::create("Configuration must be within an 'app' tag"); } auto obj = parseLuaTable(L); return std::move(obj); } Object::~Object() { if (mNode && !ref) json_delete(mNode); mNode = nullptr; } } #ifdef unit_test #include <catch/catch.hpp> #include "tests/test_symbols.h" using namespace suil; struct Mt : iod::MetaType { typedef decltype(iod::D( tprop(a, int), tprop(b, String) )) Schema; static Schema Meta; int a; String b; void toJson(iod::json::jstream& ss) const { ss << '{'; int i = 0; bool first = true; foreach(Mt::Meta) | [&](auto m) { if (!m.attributes().has(iod::_json_skip)) { /* ignore empty entry */ auto val = m.value(); if (m.attributes().has(iod::_ignore) && iod::json::json_ignore<decltype(val)>(val)) return; if (!first) { ss << ','; } first = false; iod::json::json_encode_symbol(m.attributes().get(iod::_json_key, m.symbol()), ss); ss << ':'; iod::json::json_encode_(m.symbol().member_access(Ego), ss); } i++; }; ss << '}'; } static Mt fromJson(iod::json::parser& p) { Mt tmp; iod::json::iod_attr_from_json(&Mt::Meta, tmp, p); return std::move(tmp); } }; Mt::Schema Mt::Meta{}; TEST_CASE("suil::json::Object", "[json][Object]") { SECTION("Constructing a JSON Object") { // test constucting a json::Object json::Object nl{}; REQUIRE(nl.mNode->tag == JsonTag::JSON_NULL); REQUIRE_FALSE(nl.ref); json::Object num((uint8_t) 6); REQUIRE(num.mNode->tag == JsonTag::JSON_NUMBER); REQUIRE_FALSE(num.ref); REQUIRE(6 == num.mNode->number_); json::Object num2((int) 12); REQUIRE(num2.mNode->tag == JsonTag::JSON_NUMBER); REQUIRE_FALSE(num2.ref); REQUIRE(12 == num2.mNode->number_); json::Object num3(33.89); REQUIRE(num3.mNode->tag == JsonTag::JSON_NUMBER); REQUIRE_FALSE(num3.ref); REQUIRE(33.89 == num3.mNode->number_); json::Object b(true); REQUIRE(b.mNode->tag == JsonTag::JSON_BOOL); REQUIRE_FALSE(b.ref); REQUIRE(b.mNode->bool_); json::Object s("Hello World"); REQUIRE(s.mNode->tag == JsonTag::JSON_STRING); REQUIRE_FALSE(s.ref); REQUIRE(strcmp("Hello World", s.mNode->string_) == 0); json::Object s2(""); REQUIRE(s2.mNode->tag == JsonTag::JSON_STRING); REQUIRE_FALSE(s2.ref); REQUIRE(strlen(s2.mNode->string_) == 0); json::Object arr(json::Arr); REQUIRE(arr.mNode->tag == JsonTag::JSON_ARRAY); REQUIRE_FALSE(arr.ref); REQUIRE(arr.mNode->children.head == nullptr); json::Object arr2(json::Arr, 1, 2, "Carter", true, json::Object(json::Arr, "Hello", 4, "Worlds")); REQUIRE(arr2.mNode->tag == JsonTag::JSON_ARRAY); REQUIRE_FALSE(arr2.ref); REQUIRE_FALSE(arr2.mNode->children.head == nullptr); json::Object arr3(json::Arr, std::vector<int>{1, 2, 4}); REQUIRE(arr3.mNode->tag == JsonTag::JSON_ARRAY); REQUIRE_FALSE(arr3.ref); REQUIRE_FALSE(arr3.mNode->children.head == nullptr); json::Object obj(json::Obj); REQUIRE(obj.mNode->tag == JsonTag::JSON_OBJECT); REQUIRE_FALSE(obj.ref); REQUIRE(obj.mNode->children.head == nullptr); json::Object obj2(json::Obj, "name", "Carter", "age", 29); REQUIRE(obj2.mNode->tag == JsonTag::JSON_OBJECT); REQUIRE_FALSE(obj2.ref); REQUIRE_FALSE(obj2.mNode->children.head == nullptr); } SECTION("assigning/moving json objects") { /* test assignment operators and moving object */ json::Object j1; REQUIRE((j1.mNode != nullptr && j1.mNode->tag == JsonTag::JSON_NULL)); JsonNode *node = j1.mNode; WHEN("implicit assigning to Object") { /* assigning to object with implicit cast */ j1 = 68.63; REQUIRE_FALSE(j1.mNode == nullptr); REQUIRE_FALSE(j1.mNode == node); REQUIRE(j1.mNode->tag == JsonTag::JSON_NUMBER); REQUIRE(j1.mNode->number_ == 68.63); node = j1.mNode; j1 = 69; REQUIRE_FALSE(j1.mNode == nullptr); REQUIRE_FALSE(j1.mNode == node); REQUIRE(j1.mNode->tag == JsonTag::JSON_NUMBER); REQUIRE(j1.mNode->number_ == 69); node = j1.mNode; j1 = "Worlds of Great"; REQUIRE_FALSE(j1.mNode == nullptr); REQUIRE_FALSE(j1.mNode == node); REQUIRE(j1.mNode->tag == JsonTag::JSON_STRING); REQUIRE(strcmp(j1.mNode->string_, "Worlds of Great") == 0); node = j1.mNode; j1 = String{"Hello World"}; REQUIRE_FALSE(j1.mNode == nullptr); REQUIRE_FALSE(j1.mNode == node); REQUIRE(j1.mNode->tag == JsonTag::JSON_STRING); REQUIRE(strcmp(j1.mNode->string_, "Hello World") == 0); node = j1.mNode; j1 = json::Object(json::Arr, 1, 4); REQUIRE_FALSE(j1.mNode == nullptr); REQUIRE_FALSE(j1.mNode == node); REQUIRE(j1.mNode->tag == JsonTag::JSON_ARRAY); REQUIRE_FALSE(j1.mNode->children.head == nullptr); node = j1.mNode; j1 = json::Object(json::Arr); REQUIRE_FALSE(j1.mNode == nullptr); REQUIRE_FALSE(j1.mNode == node); REQUIRE(j1.mNode->tag == JsonTag::JSON_ARRAY); REQUIRE(j1.mNode->children.head == nullptr); node = j1.mNode; j1 = json::Object(json::Obj, "One", 1); REQUIRE_FALSE(j1.mNode == nullptr); REQUIRE_FALSE(j1.mNode == node); REQUIRE(j1.mNode->tag == JsonTag::JSON_OBJECT); REQUIRE_FALSE(j1.mNode->children.head == nullptr); } WHEN("copying or moving JSON object") { /* test copying or moving json Object * !!!NOTE!!! always move, do not copy */ j1 = json::Object(9); // move assignment REQUIRE(j1.mNode->tag == JsonTag::JSON_NUMBER); REQUIRE(j1.mNode->number_ == 9); REQUIRE_FALSE(j1.ref); json::Object j2(std::move(j1)); // move constructor REQUIRE(j2.mNode->tag == JsonTag::JSON_NUMBER); REQUIRE(j2.mNode->number_ == 9); REQUIRE_FALSE(j2.ref); REQUIRE(j1.mNode == nullptr); json::Object j3(j2); // copy constructor REQUIRE(j3.mNode->tag == JsonTag::JSON_NUMBER); REQUIRE(j3.mNode->number_ == 9); REQUIRE(j3.ref); REQUIRE_FALSE(j2.mNode == nullptr); REQUIRE_FALSE(j2.ref); // after copy, j2 still owns the object, j3 should be a weak copy json::Object j4 = std::move(j2); // move assignment REQUIRE(j4.mNode->tag == JsonTag::JSON_NUMBER); REQUIRE(j4.mNode->number_ == 9); REQUIRE_FALSE(j4.ref); REQUIRE(j2.mNode == nullptr); // nove j2 has been moved REQUIRE(j3.mNode == j4.mNode); // although j3 is still a valid reference REQUIRE(j3.ref); } } SECTION("casting to native values") { /* test reading native values */ json::Object j1(true); REQUIRE((bool) j1); j1 = false; REQUIRE_FALSE((bool) j1); REQUIRE_THROWS((String) j1); REQUIRE_THROWS((int) j1); j1 = 4; REQUIRE(4 == (int) j1); j1 = 67.09; REQUIRE(67.09f == (float) j1); REQUIRE_THROWS((const char*) j1); float f = j1; REQUIRE(f == 67.09f); j1 = "Cali"; REQUIRE(strcmp("Cali", (const char *)j1) == 0); REQUIRE(String{"Cali"} == (String) j1); REQUIRE("Cali" == (std::string) j1); REQUIRE_THROWS((int) j1); } SECTION("adding values to arrays/objects") { /* test adding values to arrays or objects */ WHEN("adding values to an array") { /* initializing and adding values to arrays */ JsonNode *node{nullptr}; json::Object arr(json::Arr); arr.push(1); node = json_first_child(arr.mNode); REQUIRE_FALSE(node == nullptr); REQUIRE(node->tag == JsonTag::JSON_NUMBER); REQUIRE(node->number_ == 1); arr.push(true, 67.9, "Cali", json::Object(json::Arr), json::Object(json::Obj)); node = node->next; REQUIRE_FALSE(node == nullptr); REQUIRE(node->tag == JsonTag::JSON_BOOL); REQUIRE(node->bool_); node = node->next; REQUIRE_FALSE(node == nullptr); REQUIRE(node->tag == JsonTag::JSON_NUMBER); REQUIRE(node->number_ == 67.9); node = node->next; REQUIRE_FALSE(node == nullptr); REQUIRE(node->tag == JsonTag::JSON_STRING); REQUIRE(strcmp(node->string_, "Cali") == 0); node = node->next; REQUIRE_FALSE(node == nullptr); REQUIRE(node->tag == JsonTag::JSON_ARRAY); node = node->next; REQUIRE_FALSE(node == nullptr); REQUIRE(node->tag == JsonTag::JSON_OBJECT); REQUIRE(node->next == nullptr); arr = json::Object(json::Arr, 1, json::Object(json::Arr, 10, true)); node = json_first_child(arr.mNode); REQUIRE_FALSE(node == nullptr); REQUIRE(node->tag == JsonTag::JSON_NUMBER); REQUIRE(node->number_ == 1); node = node->next; REQUIRE_FALSE(node == nullptr); REQUIRE(node->tag == JsonTag::JSON_ARRAY); node = json_first_child(node); REQUIRE_FALSE(node == nullptr); REQUIRE(node->tag == JsonTag::JSON_NUMBER); REQUIRE(node->number_ == 10); node = node->next; REQUIRE_FALSE(node == nullptr); REQUIRE(node->tag == JsonTag::JSON_BOOL); REQUIRE(node->bool_); /* can only push into arrays*/ arr = json::Object(); REQUIRE_THROWS(arr.push(6)); arr = json::Object(json::Obj); REQUIRE_THROWS(arr.push(6)); arr = json::Object(8); REQUIRE_THROWS(arr.push(6)); arr = json::Object("Cali"); REQUIRE_THROWS(arr.push(6)); } WHEN("adding values to an object") { /* test adding values to an object */ JsonNode *node{nullptr}; json::Object obj(json::Obj); obj.set("one", 1); node = json_first_child(obj.mNode); REQUIRE_FALSE(node == nullptr); REQUIRE(node->tag == JsonTag::JSON_NUMBER); REQUIRE(strcmp(node->key, "one") == 0); REQUIRE(node->number_ == 1); obj.set("two", 2, "bool", true, "str", "Cali", "arr", json::Object(json::Arr), "obj", json::Object(json::Obj)); node = node->next; REQUIRE_FALSE(node == nullptr); REQUIRE(node->tag == JsonTag::JSON_NUMBER); REQUIRE(strcmp(node->key, "two") == 0); REQUIRE(node->number_ == 2); node = node->next; REQUIRE_FALSE(node == nullptr); REQUIRE(node->tag == JsonTag::JSON_BOOL); REQUIRE(strcmp(node->key, "bool") == 0); REQUIRE(node->bool_); node = node->next; REQUIRE_FALSE(node == nullptr); REQUIRE(node->tag == JsonTag::JSON_STRING); REQUIRE(strcmp(node->key, "str") == 0); REQUIRE(strcmp(node->string_, "Cali") == 0); node = node->next; REQUIRE_FALSE(node == nullptr); REQUIRE(node->tag == JsonTag::JSON_ARRAY); REQUIRE(strcmp(node->key, "arr") == 0); node = node->next; REQUIRE_FALSE(node == nullptr); REQUIRE(node->tag == JsonTag::JSON_OBJECT); REQUIRE(strcmp(node->key, "obj") == 0); REQUIRE(node->next == nullptr); obj = json::Object(json::Obj, "one", 1, "bool", true, "obj", json::Object(json::Obj, "two", 2, "str", "Cali")); node = json_first_child(obj.mNode); REQUIRE_FALSE(node == nullptr); REQUIRE(node->tag == JsonTag::JSON_NUMBER); REQUIRE(strcmp(node->key, "one") == 0); REQUIRE(node->number_ == 1); node = node->next; REQUIRE_FALSE(node == nullptr); REQUIRE(node->tag == JsonTag::JSON_BOOL); REQUIRE(strcmp(node->key, "bool") == 0); REQUIRE(node->bool_); node = node->next; REQUIRE_FALSE(node == nullptr); REQUIRE(node->tag == JsonTag::JSON_OBJECT); REQUIRE(strcmp(node->key, "obj") == 0); node = json_first_child(node); REQUIRE_FALSE(node == nullptr); REQUIRE(node->tag == JsonTag::JSON_NUMBER); REQUIRE(strcmp(node->key, "two") == 0); REQUIRE(node->number_ == 2); node = node->next; REQUIRE_FALSE(node == nullptr); REQUIRE(node->tag == JsonTag::JSON_STRING); REQUIRE(strcmp(node->key, "str") == 0); REQUIRE(strcmp(node->string_, "Cali") == 0); REQUIRE(node->next == nullptr); obj = json::Object(); REQUIRE_THROWS(obj.push(5)); // cannot insert into a json object obj = json::Object(json::Arr); REQUIRE_THROWS(obj.set("five", 5)); obj = json::Object(6); REQUIRE_THROWS(obj.set("five", 5)); obj = json::Object("Cali"); REQUIRE_THROWS(obj.set("five", 5)); } } SECTION("index access operators on arrays/objects") { /* tests the index operators on objects and array*/ WHEN("accessing array elements by index") { /* array JSON objects support the [int] operator*/ json::Object arr(json::Arr, 1, true, "Cali", json::Object(json::Arr, 2, false, "Cali")); REQUIRE(arr[-1].mNode == nullptr); REQUIRE(arr[4].mNode == nullptr); auto tmp = arr[0]; REQUIRE_FALSE(tmp.mNode == nullptr); REQUIRE(tmp.ref); REQUIRE(1 == (int) tmp); tmp = arr[1]; REQUIRE_FALSE(tmp.mNode == nullptr); REQUIRE(tmp.ref); REQUIRE((bool) tmp); tmp = arr[2]; REQUIRE_FALSE(tmp.mNode == nullptr); REQUIRE(tmp.ref); REQUIRE(strcmp(tmp.mNode->string_, "Cali") == 0); auto arr1 = arr[3]; REQUIRE_FALSE(arr1.mNode == nullptr); REQUIRE(arr1.ref); REQUIRE(arr1.mNode->tag == JsonTag::JSON_ARRAY); tmp = arr1[0]; REQUIRE_FALSE(tmp.mNode == nullptr); REQUIRE(tmp.ref); REQUIRE(2 == (int) tmp); tmp = arr1[1]; REQUIRE_FALSE(tmp.mNode == nullptr); REQUIRE(tmp.ref); REQUIRE_FALSE((bool) tmp); tmp = arr1[2]; REQUIRE_FALSE(tmp.mNode == nullptr); REQUIRE(tmp.ref); REQUIRE(strcmp(tmp.mNode->string_, "Cali") == 0); /* array of arrays works like magic */ REQUIRE(arr[3][1].mNode == arr1[1].mNode); /* index operator is only supported on arrays*/ arr = json::Object(); REQUIRE_THROWS(arr[0]); arr = json::Object(true); REQUIRE_THROWS(arr[0]); arr = json::Object("Cali"); REQUIRE_THROWS(arr[0]); arr = json::Object(json::Obj); REQUIRE_THROWS(arr[0]); } WHEN("accessing object elements by index") { /* objects elements can be accessed via string index */ json::Object obj(json::Obj, "one", 1, "bool", true, "str", "Cali", "obj", json::Object(json::Obj, "two", 2, "bool", false, "str", "Cali")); REQUIRE(obj["no_key"].mNode == nullptr); auto tmp = obj["one"]; REQUIRE_FALSE(tmp.mNode == nullptr); REQUIRE(tmp.ref); REQUIRE(1 == (int) tmp); tmp = obj["bool"]; REQUIRE_FALSE(tmp.mNode == nullptr); REQUIRE(tmp.ref); REQUIRE((bool) tmp); tmp = obj["str"]; REQUIRE_FALSE(tmp.mNode == nullptr); REQUIRE(tmp.ref); REQUIRE(strcmp(tmp.mNode->string_, "Cali") == 0); auto obj1 = obj["obj"]; REQUIRE_FALSE(obj1.mNode == nullptr); REQUIRE(obj1.ref); REQUIRE(obj1.mNode->tag == JsonTag::JSON_OBJECT); tmp = obj1["two"]; REQUIRE_FALSE(tmp.mNode == nullptr); REQUIRE(tmp.ref); REQUIRE(2 == (int) tmp); tmp = obj1["bool"]; REQUIRE_FALSE(tmp.mNode == nullptr); REQUIRE(tmp.ref); REQUIRE_FALSE((bool) tmp); tmp = obj1["str"]; REQUIRE_FALSE(tmp.mNode == nullptr); REQUIRE(tmp.ref); REQUIRE(strcmp(tmp.mNode->string_, "Cali") == 0); /* object of objects works like magic */ REQUIRE(obj["obj"]["two"].mNode == obj1["two"].mNode); /* index operator is only supported on object */ obj = json::Object(); REQUIRE_THROWS(obj["null"]); obj = json::Object(true); REQUIRE_THROWS(obj["bool"]); obj = json::Object("Cali"); REQUIRE_THROWS(obj["str"]); obj = json::Object(json::Arr); REQUIRE_THROWS(obj["arr"]); } WHEN("Using fullpath lookup") { json::Object obj(json::Obj, "one", 1, "bool", true, "str", "cali", "obj1", json::Object(json::Obj, "two", 2, "bool", false, "str", "carter", "obj2", json::Object(json::Obj, "three", 3))); auto tmp = obj("obj1", true); REQUIRE_FALSE(tmp.empty()); REQUIRE(tmp.isObject()); REQUIRE_NOTHROW(tmp = obj("*", true)); REQUIRE(tmp.isObject()); REQUIRE(tmp.mNode == obj.mNode); REQUIRE_NOTHROW(tmp = obj("obj1.two", true)); REQUIRE(tmp.isNumber()); REQUIRE((int)tmp == 2); REQUIRE_THROWS(tmp = obj("obj1.str.*", true)); // Wilcard expects an object REQUIRE_NOTHROW(tmp = obj("obj1.obj2", true)); REQUIRE(tmp.isObject()); REQUIRE_NOTHROW(tmp = obj("obj1.obj2.*", true)); // result is an object so * operation won't throw REQUIRE(tmp.isObject()); REQUIRE_NOTHROW(tmp = obj("obj1.obj2.three", true)); REQUIRE(tmp.isNumber()); REQUIRE((int)tmp == 3); } } SECTION("enumerating arrays and objects") { /* test enumerating arrays and objects */ WHEN("using callback enumerators") { /* testing enumerating using | operator */ json::Object arr(json::Arr, 1, true, "Cali", json::Object(json::Arr, 2, false, "Cali")); int count{0}; arr | [&count](json::Object tmp) -> bool { switch (count) { case 0: REQUIRE(1 == (int) tmp); break; case 1: REQUIRE((bool) tmp); break; case 2: REQUIRE((tmp.isString() && (strcmp(tmp.mNode->string_, "Cali") == 0))); break; case 3: REQUIRE(tmp.isArray()); break; default: REQUIRE(false); break; } count++; return false; }; REQUIRE(count == 4); /* test breaking the loop */ count = 0; arr | [&count](json::Object tmp) -> bool { return ++count % 2 == 0; /* break out of loop early */ }; REQUIRE(count == 2); /*iterating obects works as iterating arrays*/ json::Object obj(json::Obj, "one", 1, "bool", true, "str", "Cali", "obj", json::Object(json::Obj, "two", 2, "bool", false, "str", "Cali")); count = 0; obj | [&count](const char *key, json::Object tmp) { REQUIRE(utils::strmatchany(key, "one", "bool", "str", "obj")); REQUIRE(utils::strmatchany(tmp.mNode->key, "one", "bool", "str", "obj")); count++; return false; }; REQUIRE(count == 4); } WHEN("enumerating using iterators/range loop") { /* tests enumeration using for loop */ json::Object arr(json::Arr, 1, true, "Cali", json::Object(json::Arr, 2, false, "Cali")); int count{0}; for(const auto [_,tmp] : arr) { /* basically for an array the first return is always null */ REQUIRE(_ == nullptr); switch (count) { case 0: REQUIRE(1 == (int) tmp); break; case 1: REQUIRE((bool) tmp); break; case 2: REQUIRE((tmp.isString() && (strcmp(tmp.mNode->string_, "Cali") == 0))); break; case 3: REQUIRE(tmp.isArray()); break; default: REQUIRE(false); break; } count++; } REQUIRE(count == 4); /*iterating obects works as iterating arrays*/ json::Object obj(json::Obj, "one", 1, "bool", true, "str", "Cali", "obj", json::Object(json::Obj, "two", 2, "bool", false, "str", "Cali")); count = 0; for (const auto [key, val] : obj) { /* for objects key is the value's key */ REQUIRE(utils::strmatchany(key, "one", "bool", "str", "obj")); REQUIRE(utils::strmatchany(val.mNode->key, "one", "bool", "str", "obj")); count++; } REQUIRE(count == 4); // Other types are not enumerable count = 0; json::Object a("C"); for(const auto [_,__] : a) count++; REQUIRE(count == 0); a = json::Object(1); for(const auto [_,__] : a) count++; REQUIRE(count == 0); } } SECTION("encoding/decoding json object") { /* tests encoding decoding json object * !!! NOTE !!! since this is clone from ccan/json, I'm only * validating my editions */ String str = R"({"one":1,"bool":true,"str":"Cali","obj":{"two":2,"bool":false,"str":"Cali"},"arr":[1,true,"Cali"]})"; String str2 = R"({"data":{"one":1,"bool":true,"str":"Cali","obj":{"two":2,"bool":false,"str":"Cali"},"arr":[1,true,"Cali"]},"msg":"Hello Carter"})"; WHEN("decoding json strings") { auto size{str.size()}; auto obj = json::Object::decode(str.data(), size); // decode json object REQUIRE(size == str.size()); auto tmp = obj["one"]; REQUIRE_FALSE(tmp.mNode == nullptr); REQUIRE(tmp.ref); REQUIRE(1 == (int) tmp); tmp = obj["bool"]; REQUIRE_FALSE(tmp.mNode == nullptr); REQUIRE(tmp.ref); REQUIRE((bool) tmp); tmp = obj["str"]; REQUIRE_FALSE(tmp.mNode == nullptr); REQUIRE(tmp.ref); REQUIRE(strcmp(tmp.mNode->string_, "Cali") == 0); auto obj1 = obj["obj"]; REQUIRE_FALSE(obj1.mNode == nullptr); REQUIRE(obj1.ref); REQUIRE(obj1.mNode->tag == JsonTag::JSON_OBJECT); tmp = obj1["two"]; REQUIRE_FALSE(tmp.mNode == nullptr); REQUIRE(tmp.ref); REQUIRE(2 == (int) tmp); tmp = obj1["bool"]; REQUIRE_FALSE(tmp.mNode == nullptr); REQUIRE(tmp.ref); REQUIRE_FALSE((bool) tmp); tmp = obj1["str"]; REQUIRE_FALSE(tmp.mNode == nullptr); REQUIRE(tmp.ref); REQUIRE(strcmp(tmp.mNode->string_, "Cali") == 0); auto arr = obj["arr"]; REQUIRE_FALSE(arr.mNode == nullptr); tmp = arr[0]; REQUIRE_FALSE(tmp.mNode == nullptr); REQUIRE(tmp.ref); REQUIRE(1 == (int) tmp); tmp = arr[1]; REQUIRE_FALSE(tmp.mNode == nullptr); REQUIRE(tmp.ref); REQUIRE((bool) tmp); tmp = arr[2]; REQUIRE_FALSE(tmp.mNode == nullptr); REQUIRE(tmp.ref); REQUIRE(strcmp(tmp.mNode->string_, "Cali") == 0); /* !!!NOTE!!! this is really important */ size = str2.size()-9; REQUIRE_NOTHROW((obj = json::Object::decode(&str2.data()[8], size))); REQUIRE(size == str.size()); } WHEN("encoding JSON object") { /*encoding with wrapper functions */ json::Object obj(json::Obj, "one", 1, "bool", true, "str", "Cali", "obj", json::Object(json::Obj, "two", 2, "bool", false, "str", "Cali"), "arr", json::Object(json::Arr, 1, true, "Cali")); auto s1 = json::encode(obj); REQUIRE(String(s1) == str); } } SECTION("converting IOD serializable and JSON object") { // we should be able to easily convert between IOD and JSON object typedef decltype(iod::D( tprop(a(var(json_skip)), bool), tprop(b(var(optional)), String), tprop(c, iod::Nullable<std::vector<int>>) )) IodInner; typedef decltype(iod::D( tprop(a, std::string), tprop(b, std::vector<int>), tprop(c, iod::Nullable<IodInner>) )) IodType; WHEN("Converting from IOD to json::Object") { // should be able to cast/assign from IOD to json::Object IodType iodValue{}; iodValue.a = "Hello"; for(int i = 0; i < 10; i++) iodValue.b.push_back(i); json::Object j1(iodValue); REQUIRE(j1.isObject()); REQUIRE(iodValue.a == (std::string) j1["a"]); REQUIRE(j1["c"].isNull()); auto v1 = j1["b"]; for (int i = 0; i < 10; i++) { // verify vector REQUIRE(i == (int)v1[i]); } // assign value to inner type iodValue.c = IodInner{}; auto& innerType = *iodValue.c; innerType.a = true; innerType.b = "World"; json::Object j2(iodValue); REQUIRE(j2["c"].isObject()); REQUIRE(j2["c"]["a"].isNull()); REQUIRE(innerType.b == (String)j2["c"]["b"]); REQUIRE(j2["c"]["c"].isNull()); innerType.c = std::vector<int>{1, 2}; json::Object j3(iodValue); REQUIRE(j3["c"]["c"].isArray()); REQUIRE(1 == (int) j3["c"]["c"][0]); REQUIRE(2 == (int) j3["c"]["c"][1]); } WHEN("Converting from json::Object to IOD") { // should be able to convert IOD's from JSON object json::Object j1(json::Obj, "a", "Hello", "b", std::vector<int>{1, 2, 3}); auto it1 = (IodType) j1; REQUIRE(it1.a == "Hello"); REQUIRE(it1.b.size() == 3); REQUIRE(it1.b[0] == 1); REQUIRE(it1.b[1] == 2); REQUIRE(it1.b[2] == 3); REQUIRE(it1.c.isNull); j1.set("c", json::Object(json::Obj, "a", true, "c", std::vector<int>{1, 2})); auto it2 = (IodType) j1; REQUIRE_FALSE(it2.c.isNull); REQUIRE_FALSE(it2.c->a); REQUIRE(it2.c->c->size() == 2); REQUIRE((*(it2.c->c))[0] == 1); REQUIRE((*(it2.c->c))[1] == 2); } } SECTION("other JSON Object properties") { /* some miscellaneous tests */ WHEN("checking type") { /* check type checking API's */ json::Object j{}; REQUIRE(j.isNull()); j = json::Object(nullptr); REQUIRE(j.isNull()); j = '5'; REQUIRE(j.isNumber()); j = true; REQUIRE(j.isBool()); j = json::Arr; REQUIRE(j.isArray()); j = json::Obj; REQUIRE(j.isObject()); } WHEN("checking if object is empty") { /* test empty method */ /* null object is always empty */ json::Object j{}; REQUIRE(j.empty()); /* numbers boolean's can never be empty */ j = 5; REQUIRE_FALSE(j.empty()); j = true; REQUIRE_FALSE(j.empty()); /* for string, we check the actual string */ j = ""; REQUIRE(j.empty()); j = "Hello"; REQUIRE_FALSE(j.empty()); /* arrays and objects are empty when ther is no elements or members */ j = json::Arr; REQUIRE(j.empty()); j.push(1, true, "Cali"); REQUIRE_FALSE(j.empty()); j = json::Obj; REQUIRE(j.empty()); j.set("name", "Cali"); REQUIRE_FALSE(j.empty()); } WHEN("using JSON Object with IOD") { /* the main reason for adding json::Object was to have * a dynamic JSON object within iod object */ typedef decltype(iod::D( tprop(a, int), tprop(b, String), tprop(c, json::Object) )) Type; String s1 = R"({"a":5,"b":"Cali","c":{"one":1,"bool":true,"str":"Cali"}})"; Type obj; json::decode(s1, obj); REQUIRE(obj.a == 5); REQUIRE(obj.b == "Cali"); REQUIRE(1 == (int)obj.c["one"]); REQUIRE((bool) obj.c["bool"]); REQUIRE(String{"Cali"} == (String) obj.c["str"]); auto s2 = json::encode(obj); REQUIRE(String(s2) == s1); } WHEN("Using a meta object") { Mt mt; mt.a = 29; mt.b = "Carter"; auto str = json::encode(mt); REQUIRE(str == R"({"a":29,"b":"Carter"})"); Mt mt1; json::decode(str, mt1); REQUIRE(mt1.a == 29); REQUIRE(mt1.b == "Carter"); } WHEN("Loading a LUA config script to JSON object") { String lConfig{"app = { " " num = 1," " str = 'A string'," " bool = true," " arr = {1, true, 'string', {1, true}}," " obj = {" " num = 1," " bool = true" " }" "}"}; json::Object obj = json::Object::fromLuaString(lConfig); REQUIRE_FALSE(obj.empty()); json::Object val, v2; REQUIRE_NOTHROW(val = obj["num"]); REQUIRE(val.isNumber()); REQUIRE((int)val == 1); REQUIRE_NOTHROW(val = obj["str"]); REQUIRE(val.isString()); REQUIRE((String)val == "A string"); REQUIRE_NOTHROW(val = obj["bool"]); REQUIRE(val.isBool()); REQUIRE((bool)val); REQUIRE_NOTHROW(val = obj["arr"]); REQUIRE(val.isArray()); REQUIRE((int)val[0] == 1); REQUIRE((bool)val[1]); REQUIRE((String)val[2] == "string"); REQUIRE_NOTHROW(v2 = val[3]); REQUIRE(v2.isArray()); REQUIRE((int)v2[0] == 1); REQUIRE((bool)v2[1]); REQUIRE_NOTHROW(val = obj["obj"]); REQUIRE(val.isObject()); REQUIRE((int)val["num"] == 1); REQUIRE((bool)val["bool"]); // When passing empty config REQUIRE_NOTHROW(obj = json::Object::fromLuaString("app = {}")); // passing empty config will fail REQUIRE_THROWS(obj = json::Object::fromLuaString("")); // Config must be within app declaration REQUIRE_THROWS(obj = json::Object::fromLuaString("configuration = {}")); // Cannot mix array and object indexing REQUIRE_THROWS(obj = json::Object::fromLuaString("app = {'one', name='Carter'}")); } } } #endif
; A021412: Decimal expansion of 1/408. ; 0,0,2,4,5,0,9,8,0,3,9,2,1,5,6,8,6,2,7,4,5,0,9,8,0,3,9,2,1,5,6,8,6,2,7,4,5,0,9,8,0,3,9,2,1,5,6,8,6,2,7,4,5,0,9,8,0,3,9,2,1,5,6,8,6,2,7,4,5,0,9,8,0,3,9,2,1,5,6,8,6,2,7,4,5,0,9,8,0,3,9,2,1,5,6,8,6,2,7 add $0,1 mov $1,10 pow $1,$0 mul $1,7 div $1,2856 mod $1,10 mov $0,$1
bin/app.elf: file format elf32-littlearm Disassembly of section .text: c0d00000 <main>: // command has been processed, DO NOT reset the current APDU transport return 1; } /** boot up the app and intialize it */ __attribute__((section(".boot"))) int main(void) { c0d00000: b5b0 push {r4, r5, r7, lr} c0d00002: b08c sub sp, #48 ; 0x30 // exit critical section __asm volatile("cpsie i"); c0d00004: b662 cpsie i curr_scr_ix = 0; c0d00006: 4825 ldr r0, [pc, #148] ; (c0d0009c <main+0x9c>) c0d00008: 2400 movs r4, #0 c0d0000a: 6004 str r4, [r0, #0] max_scr_ix = 0; c0d0000c: 4824 ldr r0, [pc, #144] ; (c0d000a0 <main+0xa0>) c0d0000e: 6004 str r4, [r0, #0] raw_tx_ix = 0; c0d00010: 4824 ldr r0, [pc, #144] ; (c0d000a4 <main+0xa4>) c0d00012: 6004 str r4, [r0, #0] hashTainted = 1; c0d00014: 4824 ldr r0, [pc, #144] ; (c0d000a8 <main+0xa8>) c0d00016: 2101 movs r1, #1 c0d00018: 7001 strb r1, [r0, #0] uiState = UI_IDLE; c0d0001a: 4824 ldr r0, [pc, #144] ; (c0d000ac <main+0xac>) c0d0001c: 7001 strb r1, [r0, #0] // ensure exception will work as planned os_boot(); c0d0001e: f000 fd93 bl c0d00b48 <os_boot> UX_INIT(); c0d00022: 4823 ldr r0, [pc, #140] ; (c0d000b0 <main+0xb0>) c0d00024: 22b0 movs r2, #176 ; 0xb0 c0d00026: 4621 mov r1, r4 c0d00028: f000 fe3c bl c0d00ca4 <os_memset> c0d0002c: ad01 add r5, sp, #4 BEGIN_TRY { TRY c0d0002e: 4628 mov r0, r5 c0d00030: f004 f94c bl c0d042cc <setjmp> c0d00034: 8528 strh r0, [r5, #40] ; 0x28 c0d00036: 491f ldr r1, [pc, #124] ; (c0d000b4 <main+0xb4>) c0d00038: 4208 tst r0, r1 c0d0003a: d002 beq.n c0d00042 <main+0x42> c0d0003c: a801 add r0, sp, #4 Timer_Set(); // run main event loop. bottos_main(); } CATCH_OTHER(e) c0d0003e: 8504 strh r4, [r0, #40] ; 0x28 c0d00040: e019 b.n c0d00076 <main+0x76> c0d00042: a801 add r0, sp, #4 UX_INIT(); BEGIN_TRY { TRY c0d00044: f000 fd83 bl c0d00b4e <try_context_set> { io_seproxyhal_init(); c0d00048: f001 f826 bl c0d01098 <io_seproxyhal_init> c0d0004c: 2000 movs r0, #0 // restart IOs BLE_power(1, NULL); } #endif USB_power(0); c0d0004e: f003 ff5b bl c0d03f08 <USB_power> USB_power(1); c0d00052: 2001 movs r0, #1 c0d00054: f003 ff58 bl c0d03f08 <USB_power> // init the public key display to "no public key". //display_no_public_key(); // set menu bar colour for blue ui_set_menu_bar_colour(); c0d00058: f003 f808 bl c0d0306c <ui_set_menu_bar_colour> // show idle screen. ui_idle(); c0d0005c: f002 fe04 bl c0d02c68 <ui_idle> Timer_UpdateDescription(); } } static void Timer_Set() { exit_timer = MAX_EXIT_TIMER; c0d00060: 4815 ldr r0, [pc, #84] ; (c0d000b8 <main+0xb8>) c0d00062: 4916 ldr r1, [pc, #88] ; (c0d000bc <main+0xbc>) c0d00064: 6001 str r1, [r0, #0] #define MAX_EXIT_TIMER 4098 #define EXIT_TIMER_REFRESH_INTERVAL 512 static void Timer_UpdateDescription() { snprintf(timer_desc, MAX_TIMER_TEXT_WIDTH, "%d", exit_timer / EXIT_TIMER_REFRESH_INTERVAL); c0d00066: 4816 ldr r0, [pc, #88] ; (c0d000c0 <main+0xc0>) c0d00068: 2104 movs r1, #4 c0d0006a: a216 add r2, pc, #88 ; (adr r2, c0d000c4 <main+0xc4>) c0d0006c: 2308 movs r3, #8 c0d0006e: f001 fd0d bl c0d01a8c <snprintf> // set timer Timer_Set(); // run main event loop. bottos_main(); c0d00072: f000 fb03 bl c0d0067c <bottos_main> } CATCH_OTHER(e) { } FINALLY c0d00076: f000 fed7 bl c0d00e28 <try_context_get> c0d0007a: a901 add r1, sp, #4 c0d0007c: 4288 cmp r0, r1 c0d0007e: d103 bne.n c0d00088 <main+0x88> c0d00080: f000 fed4 bl c0d00e2c <try_context_get_previous> c0d00084: f000 fd63 bl c0d00b4e <try_context_set> c0d00088: a801 add r0, sp, #4 { } } END_TRY; c0d0008a: 8d00 ldrh r0, [r0, #40] ; 0x28 c0d0008c: 2800 cmp r0, #0 c0d0008e: d102 bne.n c0d00096 <main+0x96> } c0d00090: 2000 movs r0, #0 c0d00092: b00c add sp, #48 ; 0x30 c0d00094: bdb0 pop {r4, r5, r7, pc} } FINALLY { } } END_TRY; c0d00096: f000 fec2 bl c0d00e1e <os_longjmp> c0d0009a: 46c0 nop ; (mov r8, r8) c0d0009c: 20001c44 .word 0x20001c44 c0d000a0: 20001c48 .word 0x20001c48 c0d000a4: 20001b80 .word 0x20001b80 c0d000a8: 20001b7c .word 0x20001b7c c0d000ac: 20001b84 .word 0x20001b84 c0d000b0: 20001b88 .word 0x20001b88 c0d000b4: 0000ffff .word 0x0000ffff c0d000b8: 20001c38 .word 0x20001c38 c0d000bc: 00001002 .word 0x00001002 c0d000c0: 20001c3c .word 0x20001c3c c0d000c4: 00006425 .word 0x00006425 c0d000c8 <io_exchange_al>: #define P1_CONFIRM 0x01 #define P1_NO_CONFIRM 0x00 /** some kind of event loop */ unsigned short io_exchange_al(unsigned char channel, unsigned short tx_len) { c0d000c8: b5b0 push {r4, r5, r7, lr} c0d000ca: 4605 mov r5, r0 c0d000cc: 2007 movs r0, #7 switch (channel & ~(IO_FLAGS)) { c0d000ce: 4028 ands r0, r5 c0d000d0: 2400 movs r4, #0 c0d000d2: 2801 cmp r0, #1 c0d000d4: d013 beq.n c0d000fe <io_exchange_al+0x36> c0d000d6: 2802 cmp r0, #2 c0d000d8: d113 bne.n c0d00102 <io_exchange_al+0x3a> case CHANNEL_KEYBOARD: break; // multiplexed io exchange over a SPI channel and TLV encapsulated protocol case CHANNEL_SPI: if (tx_len) { c0d000da: 2900 cmp r1, #0 c0d000dc: d008 beq.n c0d000f0 <io_exchange_al+0x28> io_seproxyhal_spi_send(G_io_apdu_buffer, tx_len); c0d000de: 480c ldr r0, [pc, #48] ; (c0d00110 <io_exchange_al+0x48>) c0d000e0: f002 f878 bl c0d021d4 <io_seproxyhal_spi_send> if (channel & IO_RESET_AFTER_REPLIED) { c0d000e4: b268 sxtb r0, r5 c0d000e6: 2800 cmp r0, #0 c0d000e8: da09 bge.n c0d000fe <io_exchange_al+0x36> reset(); c0d000ea: f001 ff0d bl c0d01f08 <reset> c0d000ee: e006 b.n c0d000fe <io_exchange_al+0x36> } // nothing received from the master so far //(it's a tx transaction) return 0; } else { return io_seproxyhal_spi_recv(G_io_apdu_buffer, sizeof(G_io_apdu_buffer), 0); c0d000f0: 21ff movs r1, #255 ; 0xff c0d000f2: 3152 adds r1, #82 ; 0x52 c0d000f4: 4806 ldr r0, [pc, #24] ; (c0d00110 <io_exchange_al+0x48>) c0d000f6: 2200 movs r2, #0 c0d000f8: f002 f898 bl c0d0222c <io_seproxyhal_spi_recv> c0d000fc: 4604 mov r4, r0 default: hashTainted = 1; THROW(INVALID_PARAMETER); } return 0; } c0d000fe: 4620 mov r0, r4 c0d00100: bdb0 pop {r4, r5, r7, pc} } else { return io_seproxyhal_spi_recv(G_io_apdu_buffer, sizeof(G_io_apdu_buffer), 0); } default: hashTainted = 1; c0d00102: 4804 ldr r0, [pc, #16] ; (c0d00114 <io_exchange_al+0x4c>) c0d00104: 2101 movs r1, #1 c0d00106: 7001 strb r1, [r0, #0] THROW(INVALID_PARAMETER); c0d00108: 2002 movs r0, #2 c0d0010a: f000 fe88 bl c0d00e1e <os_longjmp> c0d0010e: 46c0 nop ; (mov r8, r8) c0d00110: 200018f8 .word 0x200018f8 c0d00114: 20001b7c .word 0x20001b7c c0d00118 <io_seproxyhal_display>: return_to_dashboard: return; } /** display function */ void io_seproxyhal_display(const bagl_element_t *element) { c0d00118: b580 push {r7, lr} io_seproxyhal_display_default((bagl_element_t *) element); c0d0011a: f001 f931 bl c0d01380 <io_seproxyhal_display_default> } c0d0011e: bd80 pop {r7, pc} c0d00120 <io_event>: unsigned char io_event(unsigned char channel) { c0d00120: b5f0 push {r4, r5, r6, r7, lr} c0d00122: b085 sub sp, #20 // nothing done with the event, throw an error on the transport layer if // needed // can't have more than one tag in the reply, not supported yet. switch (G_io_seproxyhal_spi_buffer[0]) { c0d00124: 4df6 ldr r5, [pc, #984] ; (c0d00500 <io_event+0x3e0>) c0d00126: 7829 ldrb r1, [r5, #0] c0d00128: 48f6 ldr r0, [pc, #984] ; (c0d00504 <io_event+0x3e4>) c0d0012a: 290c cmp r1, #12 c0d0012c: dc36 bgt.n c0d0019c <io_event+0x7c> c0d0012e: 2905 cmp r1, #5 c0d00130: d07f beq.n c0d00232 <io_event+0x112> c0d00132: 290c cmp r1, #12 c0d00134: d000 beq.n c0d00138 <io_event+0x18> c0d00136: e0f3 b.n c0d00320 <io_event+0x200> exit_timer = MAX_EXIT_TIMER; Timer_UpdateDescription(); } static void Timer_Restart() { if (exit_timer != MAX_EXIT_TIMER) { c0d00138: 49f3 ldr r1, [pc, #972] ; (c0d00508 <io_event+0x3e8>) c0d0013a: 680a ldr r2, [r1, #0] c0d0013c: 4282 cmp r2, r0 c0d0013e: d006 beq.n c0d0014e <io_event+0x2e> Timer_UpdateDescription(); } } static void Timer_Set() { exit_timer = MAX_EXIT_TIMER; c0d00140: 6008 str r0, [r1, #0] #define MAX_EXIT_TIMER 4098 #define EXIT_TIMER_REFRESH_INTERVAL 512 static void Timer_UpdateDescription() { snprintf(timer_desc, MAX_TIMER_TEXT_WIDTH, "%d", exit_timer / EXIT_TIMER_REFRESH_INTERVAL); c0d00142: 48f2 ldr r0, [pc, #968] ; (c0d0050c <io_event+0x3ec>) c0d00144: 2104 movs r1, #4 c0d00146: a2f2 add r2, pc, #968 ; (adr r2, c0d00510 <io_event+0x3f0>) c0d00148: 2308 movs r3, #8 c0d0014a: f001 fc9f bl c0d01a8c <snprintf> // can't have more than one tag in the reply, not supported yet. switch (G_io_seproxyhal_spi_buffer[0]) { case SEPROXYHAL_TAG_FINGER_EVENT: Timer_Restart(); UX_FINGER_EVENT(G_io_seproxyhal_spi_buffer); c0d0014e: 4cf1 ldr r4, [pc, #964] ; (c0d00514 <io_event+0x3f4>) c0d00150: 2001 movs r0, #1 c0d00152: 7620 strb r0, [r4, #24] c0d00154: 2600 movs r6, #0 c0d00156: 61e6 str r6, [r4, #28] c0d00158: 4620 mov r0, r4 c0d0015a: 3018 adds r0, #24 c0d0015c: f001 fff6 bl c0d0214c <os_ux> c0d00160: 61e0 str r0, [r4, #28] c0d00162: f001 faec bl c0d0173e <ux_check_status_default> c0d00166: 69e0 ldr r0, [r4, #28] c0d00168: 49eb ldr r1, [pc, #940] ; (c0d00518 <io_event+0x3f8>) c0d0016a: 4288 cmp r0, r1 c0d0016c: d100 bne.n c0d00170 <io_event+0x50> c0d0016e: e276 b.n c0d0065e <io_event+0x53e> c0d00170: 2800 cmp r0, #0 c0d00172: d100 bne.n c0d00176 <io_event+0x56> c0d00174: e273 b.n c0d0065e <io_event+0x53e> c0d00176: 49e9 ldr r1, [pc, #932] ; (c0d0051c <io_event+0x3fc>) c0d00178: 4288 cmp r0, r1 c0d0017a: d000 beq.n c0d0017e <io_event+0x5e> c0d0017c: e1d2 b.n c0d00524 <io_event+0x404> c0d0017e: f000 ffab bl c0d010d8 <io_seproxyhal_init_ux> c0d00182: f000 ffaf bl c0d010e4 <io_seproxyhal_init_button> c0d00186: 60a6 str r6, [r4, #8] c0d00188: 6820 ldr r0, [r4, #0] c0d0018a: 2800 cmp r0, #0 c0d0018c: d100 bne.n c0d00190 <io_event+0x70> c0d0018e: e266 b.n c0d0065e <io_event+0x53e> c0d00190: 69e0 ldr r0, [r4, #28] c0d00192: 49e1 ldr r1, [pc, #900] ; (c0d00518 <io_event+0x3f8>) c0d00194: 4288 cmp r0, r1 c0d00196: d000 beq.n c0d0019a <io_event+0x7a> c0d00198: e124 b.n c0d003e4 <io_event+0x2c4> c0d0019a: e260 b.n c0d0065e <io_event+0x53e> c0d0019c: 290d cmp r1, #13 c0d0019e: d07a beq.n c0d00296 <io_event+0x176> c0d001a0: 290e cmp r1, #14 c0d001a2: d000 beq.n c0d001a6 <io_event+0x86> c0d001a4: e0bc b.n c0d00320 <io_event+0x200> UX_REDISPLAY(); } } static void Timer_Tick() { if (exit_timer > 0) { c0d001a6: 4dd8 ldr r5, [pc, #864] ; (c0d00508 <io_event+0x3e8>) c0d001a8: 6828 ldr r0, [r5, #0] c0d001aa: 2801 cmp r0, #1 c0d001ac: db0a blt.n c0d001c4 <io_event+0xa4> exit_timer--; c0d001ae: 1e40 subs r0, r0, #1 c0d001b0: 6028 str r0, [r5, #0] #define MAX_EXIT_TIMER 4098 #define EXIT_TIMER_REFRESH_INTERVAL 512 static void Timer_UpdateDescription() { snprintf(timer_desc, MAX_TIMER_TEXT_WIDTH, "%d", exit_timer / EXIT_TIMER_REFRESH_INTERVAL); c0d001b2: 17c1 asrs r1, r0, #31 c0d001b4: 0dc9 lsrs r1, r1, #23 c0d001b6: 1840 adds r0, r0, r1 c0d001b8: 1243 asrs r3, r0, #9 c0d001ba: 48d4 ldr r0, [pc, #848] ; (c0d0050c <io_event+0x3ec>) c0d001bc: 2104 movs r1, #4 c0d001be: a2d4 add r2, pc, #848 ; (adr r2, c0d00510 <io_event+0x3f0>) c0d001c0: f001 fc64 bl c0d01a8c <snprintf> } }); #else // UX_REDISPLAY(); Timer_Tick(); if (publicKeyNeedsRefresh == 1) { c0d001c4: 4cd6 ldr r4, [pc, #856] ; (c0d00520 <io_event+0x400>) c0d001c6: 7820 ldrb r0, [r4, #0] c0d001c8: 2801 cmp r0, #1 c0d001ca: d000 beq.n c0d001ce <io_event+0xae> c0d001cc: e130 b.n c0d00430 <io_event+0x310> UX_REDISPLAY(); c0d001ce: f000 ff83 bl c0d010d8 <io_seproxyhal_init_ux> c0d001d2: f000 ff87 bl c0d010e4 <io_seproxyhal_init_button> c0d001d6: 4dcf ldr r5, [pc, #828] ; (c0d00514 <io_event+0x3f4>) c0d001d8: 2000 movs r0, #0 c0d001da: 60a8 str r0, [r5, #8] c0d001dc: 6829 ldr r1, [r5, #0] c0d001de: 2900 cmp r1, #0 c0d001e0: d024 beq.n c0d0022c <io_event+0x10c> c0d001e2: 69e9 ldr r1, [r5, #28] c0d001e4: 4acc ldr r2, [pc, #816] ; (c0d00518 <io_event+0x3f8>) c0d001e6: 4291 cmp r1, r2 c0d001e8: d11e bne.n c0d00228 <io_event+0x108> c0d001ea: e01f b.n c0d0022c <io_event+0x10c> c0d001ec: 6869 ldr r1, [r5, #4] c0d001ee: 4288 cmp r0, r1 c0d001f0: d21c bcs.n c0d0022c <io_event+0x10c> c0d001f2: f002 f805 bl c0d02200 <io_seproxyhal_spi_is_status_sent> c0d001f6: 2800 cmp r0, #0 c0d001f8: d118 bne.n c0d0022c <io_event+0x10c> c0d001fa: 68a8 ldr r0, [r5, #8] c0d001fc: 68e9 ldr r1, [r5, #12] c0d001fe: 2638 movs r6, #56 ; 0x38 c0d00200: 4370 muls r0, r6 c0d00202: 682a ldr r2, [r5, #0] c0d00204: 1810 adds r0, r2, r0 c0d00206: 2900 cmp r1, #0 c0d00208: d002 beq.n c0d00210 <io_event+0xf0> c0d0020a: 4788 blx r1 c0d0020c: 2800 cmp r0, #0 c0d0020e: d007 beq.n c0d00220 <io_event+0x100> c0d00210: 2801 cmp r0, #1 c0d00212: d103 bne.n c0d0021c <io_event+0xfc> c0d00214: 68a8 ldr r0, [r5, #8] c0d00216: 4346 muls r6, r0 c0d00218: 6828 ldr r0, [r5, #0] c0d0021a: 1980 adds r0, r0, r6 return_to_dashboard: return; } /** display function */ void io_seproxyhal_display(const bagl_element_t *element) { io_seproxyhal_display_default((bagl_element_t *) element); c0d0021c: f001 f8b0 bl c0d01380 <io_seproxyhal_display_default> }); #else // UX_REDISPLAY(); Timer_Tick(); if (publicKeyNeedsRefresh == 1) { UX_REDISPLAY(); c0d00220: 68a8 ldr r0, [r5, #8] c0d00222: 1c40 adds r0, r0, #1 c0d00224: 60a8 str r0, [r5, #8] c0d00226: 6829 ldr r1, [r5, #0] c0d00228: 2900 cmp r1, #0 c0d0022a: d1df bne.n c0d001ec <io_event+0xcc> publicKeyNeedsRefresh = 0; c0d0022c: 2000 movs r0, #0 c0d0022e: 7020 strb r0, [r4, #0] c0d00230: e215 b.n c0d0065e <io_event+0x53e> exit_timer = MAX_EXIT_TIMER; Timer_UpdateDescription(); } static void Timer_Restart() { if (exit_timer != MAX_EXIT_TIMER) { c0d00232: 49b5 ldr r1, [pc, #724] ; (c0d00508 <io_event+0x3e8>) c0d00234: 680a ldr r2, [r1, #0] c0d00236: 4282 cmp r2, r0 c0d00238: d006 beq.n c0d00248 <io_event+0x128> Timer_UpdateDescription(); } } static void Timer_Set() { exit_timer = MAX_EXIT_TIMER; c0d0023a: 6008 str r0, [r1, #0] #define MAX_EXIT_TIMER 4098 #define EXIT_TIMER_REFRESH_INTERVAL 512 static void Timer_UpdateDescription() { snprintf(timer_desc, MAX_TIMER_TEXT_WIDTH, "%d", exit_timer / EXIT_TIMER_REFRESH_INTERVAL); c0d0023c: 48b3 ldr r0, [pc, #716] ; (c0d0050c <io_event+0x3ec>) c0d0023e: 2104 movs r1, #4 c0d00240: a2b3 add r2, pc, #716 ; (adr r2, c0d00510 <io_event+0x3f0>) c0d00242: 2308 movs r3, #8 c0d00244: f001 fc22 bl c0d01a8c <snprintf> UX_FINGER_EVENT(G_io_seproxyhal_spi_buffer); break; case SEPROXYHAL_TAG_BUTTON_PUSH_EVENT: // for Nano S Timer_Restart(); UX_BUTTON_PUSH_EVENT(G_io_seproxyhal_spi_buffer); c0d00248: 4cb2 ldr r4, [pc, #712] ; (c0d00514 <io_event+0x3f4>) c0d0024a: 2001 movs r0, #1 c0d0024c: 7620 strb r0, [r4, #24] c0d0024e: 2600 movs r6, #0 c0d00250: 61e6 str r6, [r4, #28] c0d00252: 4620 mov r0, r4 c0d00254: 3018 adds r0, #24 c0d00256: f001 ff79 bl c0d0214c <os_ux> c0d0025a: 61e0 str r0, [r4, #28] c0d0025c: f001 fa6f bl c0d0173e <ux_check_status_default> c0d00260: 69e0 ldr r0, [r4, #28] c0d00262: 49ad ldr r1, [pc, #692] ; (c0d00518 <io_event+0x3f8>) c0d00264: 4288 cmp r0, r1 c0d00266: d100 bne.n c0d0026a <io_event+0x14a> c0d00268: e1f9 b.n c0d0065e <io_event+0x53e> c0d0026a: 2800 cmp r0, #0 c0d0026c: d100 bne.n c0d00270 <io_event+0x150> c0d0026e: e1f6 b.n c0d0065e <io_event+0x53e> c0d00270: 49aa ldr r1, [pc, #680] ; (c0d0051c <io_event+0x3fc>) c0d00272: 4288 cmp r0, r1 c0d00274: d000 beq.n c0d00278 <io_event+0x158> c0d00276: e18f b.n c0d00598 <io_event+0x478> c0d00278: f000 ff2e bl c0d010d8 <io_seproxyhal_init_ux> c0d0027c: f000 ff32 bl c0d010e4 <io_seproxyhal_init_button> c0d00280: 60a6 str r6, [r4, #8] c0d00282: 6820 ldr r0, [r4, #0] c0d00284: 2800 cmp r0, #0 c0d00286: d100 bne.n c0d0028a <io_event+0x16a> c0d00288: e1e9 b.n c0d0065e <io_event+0x53e> c0d0028a: 69e0 ldr r0, [r4, #28] c0d0028c: 49f9 ldr r1, [pc, #996] ; (c0d00674 <io_event+0x554>) c0d0028e: 4288 cmp r0, r1 c0d00290: d000 beq.n c0d00294 <io_event+0x174> c0d00292: e0ca b.n c0d0042a <io_event+0x30a> c0d00294: e1e3 b.n c0d0065e <io_event+0x53e> break; case SEPROXYHAL_TAG_DISPLAY_PROCESSED_EVENT: //Timer_Restart(); if (UX_DISPLAYED()) { c0d00296: 4cf6 ldr r4, [pc, #984] ; (c0d00670 <io_event+0x550>) c0d00298: 6860 ldr r0, [r4, #4] c0d0029a: 68a1 ldr r1, [r4, #8] c0d0029c: 4281 cmp r1, r0 c0d0029e: d300 bcc.n c0d002a2 <io_event+0x182> c0d002a0: e1dd b.n c0d0065e <io_event+0x53e> // perform actions after all screen elements have been displayed } else { UX_DISPLAYED_EVENT(); c0d002a2: 2001 movs r0, #1 c0d002a4: 7620 strb r0, [r4, #24] c0d002a6: 2500 movs r5, #0 c0d002a8: 61e5 str r5, [r4, #28] c0d002aa: 4620 mov r0, r4 c0d002ac: 3018 adds r0, #24 c0d002ae: f001 ff4d bl c0d0214c <os_ux> c0d002b2: 61e0 str r0, [r4, #28] c0d002b4: f001 fa43 bl c0d0173e <ux_check_status_default> c0d002b8: 69e0 ldr r0, [r4, #28] c0d002ba: 49ee ldr r1, [pc, #952] ; (c0d00674 <io_event+0x554>) c0d002bc: 4288 cmp r0, r1 c0d002be: d100 bne.n c0d002c2 <io_event+0x1a2> c0d002c0: e1cd b.n c0d0065e <io_event+0x53e> c0d002c2: 49ed ldr r1, [pc, #948] ; (c0d00678 <io_event+0x558>) c0d002c4: 4288 cmp r0, r1 c0d002c6: d100 bne.n c0d002ca <io_event+0x1aa> c0d002c8: e19c b.n c0d00604 <io_event+0x4e4> c0d002ca: 2800 cmp r0, #0 c0d002cc: d100 bne.n c0d002d0 <io_event+0x1b0> c0d002ce: e1c6 b.n c0d0065e <io_event+0x53e> c0d002d0: 6820 ldr r0, [r4, #0] c0d002d2: 2800 cmp r0, #0 c0d002d4: d100 bne.n c0d002d8 <io_event+0x1b8> c0d002d6: e18a b.n c0d005ee <io_event+0x4ce> c0d002d8: 68a0 ldr r0, [r4, #8] c0d002da: 6861 ldr r1, [r4, #4] c0d002dc: 4288 cmp r0, r1 c0d002de: d300 bcc.n c0d002e2 <io_event+0x1c2> c0d002e0: e185 b.n c0d005ee <io_event+0x4ce> c0d002e2: f001 ff8d bl c0d02200 <io_seproxyhal_spi_is_status_sent> c0d002e6: 2800 cmp r0, #0 c0d002e8: d000 beq.n c0d002ec <io_event+0x1cc> c0d002ea: e180 b.n c0d005ee <io_event+0x4ce> c0d002ec: 68a0 ldr r0, [r4, #8] c0d002ee: 68e1 ldr r1, [r4, #12] c0d002f0: 2538 movs r5, #56 ; 0x38 c0d002f2: 4368 muls r0, r5 c0d002f4: 6822 ldr r2, [r4, #0] c0d002f6: 1810 adds r0, r2, r0 c0d002f8: 2900 cmp r1, #0 c0d002fa: d002 beq.n c0d00302 <io_event+0x1e2> c0d002fc: 4788 blx r1 c0d002fe: 2800 cmp r0, #0 c0d00300: d007 beq.n c0d00312 <io_event+0x1f2> c0d00302: 2801 cmp r0, #1 c0d00304: d103 bne.n c0d0030e <io_event+0x1ee> c0d00306: 68a0 ldr r0, [r4, #8] c0d00308: 4345 muls r5, r0 c0d0030a: 6820 ldr r0, [r4, #0] c0d0030c: 1940 adds r0, r0, r5 return_to_dashboard: return; } /** display function */ void io_seproxyhal_display(const bagl_element_t *element) { io_seproxyhal_display_default((bagl_element_t *) element); c0d0030e: f001 f837 bl c0d01380 <io_seproxyhal_display_default> case SEPROXYHAL_TAG_DISPLAY_PROCESSED_EVENT: //Timer_Restart(); if (UX_DISPLAYED()) { // perform actions after all screen elements have been displayed } else { UX_DISPLAYED_EVENT(); c0d00312: 68a0 ldr r0, [r4, #8] c0d00314: 1c40 adds r0, r0, #1 c0d00316: 60a0 str r0, [r4, #8] c0d00318: 6821 ldr r1, [r4, #0] c0d0031a: 2900 cmp r1, #0 c0d0031c: d1dd bne.n c0d002da <io_event+0x1ba> c0d0031e: e166 b.n c0d005ee <io_event+0x4ce> #endif break; // unknown events are acknowledged default: UX_DEFAULT_EVENT(); c0d00320: 4cd3 ldr r4, [pc, #844] ; (c0d00670 <io_event+0x550>) c0d00322: 2001 movs r0, #1 c0d00324: 7620 strb r0, [r4, #24] c0d00326: 2500 movs r5, #0 c0d00328: 61e5 str r5, [r4, #28] c0d0032a: 4620 mov r0, r4 c0d0032c: 3018 adds r0, #24 c0d0032e: f001 ff0d bl c0d0214c <os_ux> c0d00332: 61e0 str r0, [r4, #28] c0d00334: f001 fa03 bl c0d0173e <ux_check_status_default> c0d00338: 69e0 ldr r0, [r4, #28] c0d0033a: 49cf ldr r1, [pc, #828] ; (c0d00678 <io_event+0x558>) c0d0033c: 4288 cmp r0, r1 c0d0033e: d000 beq.n c0d00342 <io_event+0x222> c0d00340: e092 b.n c0d00468 <io_event+0x348> c0d00342: f000 fec9 bl c0d010d8 <io_seproxyhal_init_ux> c0d00346: f000 fecd bl c0d010e4 <io_seproxyhal_init_button> c0d0034a: 60a5 str r5, [r4, #8] c0d0034c: 6820 ldr r0, [r4, #0] c0d0034e: 2800 cmp r0, #0 c0d00350: d100 bne.n c0d00354 <io_event+0x234> c0d00352: e184 b.n c0d0065e <io_event+0x53e> c0d00354: 69e0 ldr r0, [r4, #28] c0d00356: 49c7 ldr r1, [pc, #796] ; (c0d00674 <io_event+0x554>) c0d00358: 4288 cmp r0, r1 c0d0035a: d120 bne.n c0d0039e <io_event+0x27e> c0d0035c: e17f b.n c0d0065e <io_event+0x53e> c0d0035e: 6860 ldr r0, [r4, #4] c0d00360: 4285 cmp r5, r0 c0d00362: d300 bcc.n c0d00366 <io_event+0x246> c0d00364: e17b b.n c0d0065e <io_event+0x53e> c0d00366: f001 ff4b bl c0d02200 <io_seproxyhal_spi_is_status_sent> c0d0036a: 2800 cmp r0, #0 c0d0036c: d000 beq.n c0d00370 <io_event+0x250> c0d0036e: e176 b.n c0d0065e <io_event+0x53e> c0d00370: 68a0 ldr r0, [r4, #8] c0d00372: 68e1 ldr r1, [r4, #12] c0d00374: 2538 movs r5, #56 ; 0x38 c0d00376: 4368 muls r0, r5 c0d00378: 6822 ldr r2, [r4, #0] c0d0037a: 1810 adds r0, r2, r0 c0d0037c: 2900 cmp r1, #0 c0d0037e: d002 beq.n c0d00386 <io_event+0x266> c0d00380: 4788 blx r1 c0d00382: 2800 cmp r0, #0 c0d00384: d007 beq.n c0d00396 <io_event+0x276> c0d00386: 2801 cmp r0, #1 c0d00388: d103 bne.n c0d00392 <io_event+0x272> c0d0038a: 68a0 ldr r0, [r4, #8] c0d0038c: 4345 muls r5, r0 c0d0038e: 6820 ldr r0, [r4, #0] c0d00390: 1940 adds r0, r0, r5 return_to_dashboard: return; } /** display function */ void io_seproxyhal_display(const bagl_element_t *element) { io_seproxyhal_display_default((bagl_element_t *) element); c0d00392: f000 fff5 bl c0d01380 <io_seproxyhal_display_default> #endif break; // unknown events are acknowledged default: UX_DEFAULT_EVENT(); c0d00396: 68a0 ldr r0, [r4, #8] c0d00398: 1c45 adds r5, r0, #1 c0d0039a: 60a5 str r5, [r4, #8] c0d0039c: 6820 ldr r0, [r4, #0] c0d0039e: 2800 cmp r0, #0 c0d003a0: d1dd bne.n c0d0035e <io_event+0x23e> c0d003a2: e15c b.n c0d0065e <io_event+0x53e> // can't have more than one tag in the reply, not supported yet. switch (G_io_seproxyhal_spi_buffer[0]) { case SEPROXYHAL_TAG_FINGER_EVENT: Timer_Restart(); UX_FINGER_EVENT(G_io_seproxyhal_spi_buffer); c0d003a4: 6860 ldr r0, [r4, #4] c0d003a6: 4286 cmp r6, r0 c0d003a8: d300 bcc.n c0d003ac <io_event+0x28c> c0d003aa: e158 b.n c0d0065e <io_event+0x53e> c0d003ac: f001 ff28 bl c0d02200 <io_seproxyhal_spi_is_status_sent> c0d003b0: 2800 cmp r0, #0 c0d003b2: d000 beq.n c0d003b6 <io_event+0x296> c0d003b4: e153 b.n c0d0065e <io_event+0x53e> c0d003b6: 68a0 ldr r0, [r4, #8] c0d003b8: 68e1 ldr r1, [r4, #12] c0d003ba: 2538 movs r5, #56 ; 0x38 c0d003bc: 4368 muls r0, r5 c0d003be: 6822 ldr r2, [r4, #0] c0d003c0: 1810 adds r0, r2, r0 c0d003c2: 2900 cmp r1, #0 c0d003c4: d002 beq.n c0d003cc <io_event+0x2ac> c0d003c6: 4788 blx r1 c0d003c8: 2800 cmp r0, #0 c0d003ca: d007 beq.n c0d003dc <io_event+0x2bc> c0d003cc: 2801 cmp r0, #1 c0d003ce: d103 bne.n c0d003d8 <io_event+0x2b8> c0d003d0: 68a0 ldr r0, [r4, #8] c0d003d2: 4345 muls r5, r0 c0d003d4: 6820 ldr r0, [r4, #0] c0d003d6: 1940 adds r0, r0, r5 return_to_dashboard: return; } /** display function */ void io_seproxyhal_display(const bagl_element_t *element) { io_seproxyhal_display_default((bagl_element_t *) element); c0d003d8: f000 ffd2 bl c0d01380 <io_seproxyhal_display_default> // can't have more than one tag in the reply, not supported yet. switch (G_io_seproxyhal_spi_buffer[0]) { case SEPROXYHAL_TAG_FINGER_EVENT: Timer_Restart(); UX_FINGER_EVENT(G_io_seproxyhal_spi_buffer); c0d003dc: 68a0 ldr r0, [r4, #8] c0d003de: 1c46 adds r6, r0, #1 c0d003e0: 60a6 str r6, [r4, #8] c0d003e2: 6820 ldr r0, [r4, #0] c0d003e4: 2800 cmp r0, #0 c0d003e6: d1dd bne.n c0d003a4 <io_event+0x284> c0d003e8: e139 b.n c0d0065e <io_event+0x53e> break; case SEPROXYHAL_TAG_BUTTON_PUSH_EVENT: // for Nano S Timer_Restart(); UX_BUTTON_PUSH_EVENT(G_io_seproxyhal_spi_buffer); c0d003ea: 6860 ldr r0, [r4, #4] c0d003ec: 4286 cmp r6, r0 c0d003ee: d300 bcc.n c0d003f2 <io_event+0x2d2> c0d003f0: e135 b.n c0d0065e <io_event+0x53e> c0d003f2: f001 ff05 bl c0d02200 <io_seproxyhal_spi_is_status_sent> c0d003f6: 2800 cmp r0, #0 c0d003f8: d000 beq.n c0d003fc <io_event+0x2dc> c0d003fa: e130 b.n c0d0065e <io_event+0x53e> c0d003fc: 68a0 ldr r0, [r4, #8] c0d003fe: 68e1 ldr r1, [r4, #12] c0d00400: 2538 movs r5, #56 ; 0x38 c0d00402: 4368 muls r0, r5 c0d00404: 6822 ldr r2, [r4, #0] c0d00406: 1810 adds r0, r2, r0 c0d00408: 2900 cmp r1, #0 c0d0040a: d002 beq.n c0d00412 <io_event+0x2f2> c0d0040c: 4788 blx r1 c0d0040e: 2800 cmp r0, #0 c0d00410: d007 beq.n c0d00422 <io_event+0x302> c0d00412: 2801 cmp r0, #1 c0d00414: d103 bne.n c0d0041e <io_event+0x2fe> c0d00416: 68a0 ldr r0, [r4, #8] c0d00418: 4345 muls r5, r0 c0d0041a: 6820 ldr r0, [r4, #0] c0d0041c: 1940 adds r0, r0, r5 return_to_dashboard: return; } /** display function */ void io_seproxyhal_display(const bagl_element_t *element) { io_seproxyhal_display_default((bagl_element_t *) element); c0d0041e: f000 ffaf bl c0d01380 <io_seproxyhal_display_default> UX_FINGER_EVENT(G_io_seproxyhal_spi_buffer); break; case SEPROXYHAL_TAG_BUTTON_PUSH_EVENT: // for Nano S Timer_Restart(); UX_BUTTON_PUSH_EVENT(G_io_seproxyhal_spi_buffer); c0d00422: 68a0 ldr r0, [r4, #8] c0d00424: 1c46 adds r6, r0, #1 c0d00426: 60a6 str r6, [r4, #8] c0d00428: 6820 ldr r0, [r4, #0] c0d0042a: 2800 cmp r0, #0 c0d0042c: d1dd bne.n c0d003ea <io_event+0x2ca> c0d0042e: e116 b.n c0d0065e <io_event+0x53e> Timer_Set(); } } static bool Timer_Expired() { return exit_timer <= 0; c0d00430: 6828 ldr r0, [r5, #0] Timer_Tick(); if (publicKeyNeedsRefresh == 1) { UX_REDISPLAY(); publicKeyNeedsRefresh = 0; } else { if (Timer_Expired()) { c0d00432: 2800 cmp r0, #0 c0d00434: dc00 bgt.n c0d00438 <io_event+0x318> c0d00436: e0e1 b.n c0d005fc <io_event+0x4dc> c0d00438: 2101 movs r1, #1 c0d0043a: 0209 lsls r1, r1, #8 c0d0043c: 460a mov r2, r1 c0d0043e: 32ff adds r2, #255 ; 0xff c0d00440: 4010 ands r0, r2 static void Timer_UpdateDescription() { snprintf(timer_desc, MAX_TIMER_TEXT_WIDTH, "%d", exit_timer / EXIT_TIMER_REFRESH_INTERVAL); } static void Timer_UpdateDisplay() { if ((exit_timer % EXIT_TIMER_REFRESH_INTERVAL) == (EXIT_TIMER_REFRESH_INTERVAL / 2)) { c0d00442: 4288 cmp r0, r1 c0d00444: d000 beq.n c0d00448 <io_event+0x328> c0d00446: e10a b.n c0d0065e <io_event+0x53e> UX_REDISPLAY(); c0d00448: f000 fe46 bl c0d010d8 <io_seproxyhal_init_ux> c0d0044c: f000 fe4a bl c0d010e4 <io_seproxyhal_init_button> c0d00450: 4c87 ldr r4, [pc, #540] ; (c0d00670 <io_event+0x550>) c0d00452: 2000 movs r0, #0 c0d00454: 60a0 str r0, [r4, #8] c0d00456: 6821 ldr r1, [r4, #0] c0d00458: 2900 cmp r1, #0 c0d0045a: d100 bne.n c0d0045e <io_event+0x33e> c0d0045c: e0ff b.n c0d0065e <io_event+0x53e> c0d0045e: 69e1 ldr r1, [r4, #28] c0d00460: 4a84 ldr r2, [pc, #528] ; (c0d00674 <io_event+0x554>) c0d00462: 4291 cmp r1, r2 c0d00464: d148 bne.n c0d004f8 <io_event+0x3d8> c0d00466: e0fa b.n c0d0065e <io_event+0x53e> #endif break; // unknown events are acknowledged default: UX_DEFAULT_EVENT(); c0d00468: 6820 ldr r0, [r4, #0] c0d0046a: 2800 cmp r0, #0 c0d0046c: d100 bne.n c0d00470 <io_event+0x350> c0d0046e: e0be b.n c0d005ee <io_event+0x4ce> c0d00470: 68a0 ldr r0, [r4, #8] c0d00472: 6861 ldr r1, [r4, #4] c0d00474: 4288 cmp r0, r1 c0d00476: d300 bcc.n c0d0047a <io_event+0x35a> c0d00478: e0b9 b.n c0d005ee <io_event+0x4ce> c0d0047a: f001 fec1 bl c0d02200 <io_seproxyhal_spi_is_status_sent> c0d0047e: 2800 cmp r0, #0 c0d00480: d000 beq.n c0d00484 <io_event+0x364> c0d00482: e0b4 b.n c0d005ee <io_event+0x4ce> c0d00484: 68a0 ldr r0, [r4, #8] c0d00486: 68e1 ldr r1, [r4, #12] c0d00488: 2538 movs r5, #56 ; 0x38 c0d0048a: 4368 muls r0, r5 c0d0048c: 6822 ldr r2, [r4, #0] c0d0048e: 1810 adds r0, r2, r0 c0d00490: 2900 cmp r1, #0 c0d00492: d002 beq.n c0d0049a <io_event+0x37a> c0d00494: 4788 blx r1 c0d00496: 2800 cmp r0, #0 c0d00498: d007 beq.n c0d004aa <io_event+0x38a> c0d0049a: 2801 cmp r0, #1 c0d0049c: d103 bne.n c0d004a6 <io_event+0x386> c0d0049e: 68a0 ldr r0, [r4, #8] c0d004a0: 4345 muls r5, r0 c0d004a2: 6820 ldr r0, [r4, #0] c0d004a4: 1940 adds r0, r0, r5 return_to_dashboard: return; } /** display function */ void io_seproxyhal_display(const bagl_element_t *element) { io_seproxyhal_display_default((bagl_element_t *) element); c0d004a6: f000 ff6b bl c0d01380 <io_seproxyhal_display_default> #endif break; // unknown events are acknowledged default: UX_DEFAULT_EVENT(); c0d004aa: 68a0 ldr r0, [r4, #8] c0d004ac: 1c40 adds r0, r0, #1 c0d004ae: 60a0 str r0, [r4, #8] c0d004b0: 6821 ldr r1, [r4, #0] c0d004b2: 2900 cmp r1, #0 c0d004b4: d1dd bne.n c0d00472 <io_event+0x352> c0d004b6: e09a b.n c0d005ee <io_event+0x4ce> snprintf(timer_desc, MAX_TIMER_TEXT_WIDTH, "%d", exit_timer / EXIT_TIMER_REFRESH_INTERVAL); } static void Timer_UpdateDisplay() { if ((exit_timer % EXIT_TIMER_REFRESH_INTERVAL) == (EXIT_TIMER_REFRESH_INTERVAL / 2)) { UX_REDISPLAY(); c0d004b8: 6861 ldr r1, [r4, #4] c0d004ba: 4288 cmp r0, r1 c0d004bc: d300 bcc.n c0d004c0 <io_event+0x3a0> c0d004be: e0ce b.n c0d0065e <io_event+0x53e> c0d004c0: f001 fe9e bl c0d02200 <io_seproxyhal_spi_is_status_sent> c0d004c4: 2800 cmp r0, #0 c0d004c6: d000 beq.n c0d004ca <io_event+0x3aa> c0d004c8: e0c9 b.n c0d0065e <io_event+0x53e> c0d004ca: 68a0 ldr r0, [r4, #8] c0d004cc: 68e1 ldr r1, [r4, #12] c0d004ce: 2538 movs r5, #56 ; 0x38 c0d004d0: 4368 muls r0, r5 c0d004d2: 6822 ldr r2, [r4, #0] c0d004d4: 1810 adds r0, r2, r0 c0d004d6: 2900 cmp r1, #0 c0d004d8: d002 beq.n c0d004e0 <io_event+0x3c0> c0d004da: 4788 blx r1 c0d004dc: 2800 cmp r0, #0 c0d004de: d007 beq.n c0d004f0 <io_event+0x3d0> c0d004e0: 2801 cmp r0, #1 c0d004e2: d103 bne.n c0d004ec <io_event+0x3cc> c0d004e4: 68a0 ldr r0, [r4, #8] c0d004e6: 4345 muls r5, r0 c0d004e8: 6820 ldr r0, [r4, #0] c0d004ea: 1940 adds r0, r0, r5 return_to_dashboard: return; } /** display function */ void io_seproxyhal_display(const bagl_element_t *element) { io_seproxyhal_display_default((bagl_element_t *) element); c0d004ec: f000 ff48 bl c0d01380 <io_seproxyhal_display_default> snprintf(timer_desc, MAX_TIMER_TEXT_WIDTH, "%d", exit_timer / EXIT_TIMER_REFRESH_INTERVAL); } static void Timer_UpdateDisplay() { if ((exit_timer % EXIT_TIMER_REFRESH_INTERVAL) == (EXIT_TIMER_REFRESH_INTERVAL / 2)) { UX_REDISPLAY(); c0d004f0: 68a0 ldr r0, [r4, #8] c0d004f2: 1c40 adds r0, r0, #1 c0d004f4: 60a0 str r0, [r4, #8] c0d004f6: 6821 ldr r1, [r4, #0] c0d004f8: 2900 cmp r1, #0 c0d004fa: d1dd bne.n c0d004b8 <io_event+0x398> c0d004fc: e0af b.n c0d0065e <io_event+0x53e> c0d004fe: 46c0 nop ; (mov r8, r8) c0d00500: 20001800 .word 0x20001800 c0d00504: 00001002 .word 0x00001002 c0d00508: 20001c38 .word 0x20001c38 c0d0050c: 20001c3c .word 0x20001c3c c0d00510: 00006425 .word 0x00006425 c0d00514: 20001b88 .word 0x20001b88 c0d00518: b0105044 .word 0xb0105044 c0d0051c: b0105055 .word 0xb0105055 c0d00520: 20001c40 .word 0x20001c40 // can't have more than one tag in the reply, not supported yet. switch (G_io_seproxyhal_spi_buffer[0]) { case SEPROXYHAL_TAG_FINGER_EVENT: Timer_Restart(); UX_FINGER_EVENT(G_io_seproxyhal_spi_buffer); c0d00524: 88a0 ldrh r0, [r4, #4] c0d00526: 9004 str r0, [sp, #16] c0d00528: 6820 ldr r0, [r4, #0] c0d0052a: 9003 str r0, [sp, #12] c0d0052c: 79ee ldrb r6, [r5, #7] c0d0052e: 79ab ldrb r3, [r5, #6] c0d00530: 796f ldrb r7, [r5, #5] c0d00532: 792a ldrb r2, [r5, #4] c0d00534: 78ed ldrb r5, [r5, #3] c0d00536: 68e1 ldr r1, [r4, #12] c0d00538: 4668 mov r0, sp c0d0053a: 6005 str r5, [r0, #0] c0d0053c: 6041 str r1, [r0, #4] c0d0053e: 0212 lsls r2, r2, #8 c0d00540: 433a orrs r2, r7 c0d00542: 021b lsls r3, r3, #8 c0d00544: 4333 orrs r3, r6 c0d00546: 9803 ldr r0, [sp, #12] c0d00548: 9904 ldr r1, [sp, #16] c0d0054a: f000 fe4b bl c0d011e4 <io_seproxyhal_touch_element_callback> c0d0054e: 6820 ldr r0, [r4, #0] c0d00550: 2800 cmp r0, #0 c0d00552: d04c beq.n c0d005ee <io_event+0x4ce> c0d00554: 68a0 ldr r0, [r4, #8] c0d00556: 6861 ldr r1, [r4, #4] c0d00558: 4288 cmp r0, r1 c0d0055a: d248 bcs.n c0d005ee <io_event+0x4ce> c0d0055c: f001 fe50 bl c0d02200 <io_seproxyhal_spi_is_status_sent> c0d00560: 2800 cmp r0, #0 c0d00562: d144 bne.n c0d005ee <io_event+0x4ce> c0d00564: 68a0 ldr r0, [r4, #8] c0d00566: 68e1 ldr r1, [r4, #12] c0d00568: 2538 movs r5, #56 ; 0x38 c0d0056a: 4368 muls r0, r5 c0d0056c: 6822 ldr r2, [r4, #0] c0d0056e: 1810 adds r0, r2, r0 c0d00570: 2900 cmp r1, #0 c0d00572: d002 beq.n c0d0057a <io_event+0x45a> c0d00574: 4788 blx r1 c0d00576: 2800 cmp r0, #0 c0d00578: d007 beq.n c0d0058a <io_event+0x46a> c0d0057a: 2801 cmp r0, #1 c0d0057c: d103 bne.n c0d00586 <io_event+0x466> c0d0057e: 68a0 ldr r0, [r4, #8] c0d00580: 4345 muls r5, r0 c0d00582: 6820 ldr r0, [r4, #0] c0d00584: 1940 adds r0, r0, r5 return_to_dashboard: return; } /** display function */ void io_seproxyhal_display(const bagl_element_t *element) { io_seproxyhal_display_default((bagl_element_t *) element); c0d00586: f000 fefb bl c0d01380 <io_seproxyhal_display_default> // can't have more than one tag in the reply, not supported yet. switch (G_io_seproxyhal_spi_buffer[0]) { case SEPROXYHAL_TAG_FINGER_EVENT: Timer_Restart(); UX_FINGER_EVENT(G_io_seproxyhal_spi_buffer); c0d0058a: 68a0 ldr r0, [r4, #8] c0d0058c: 1c40 adds r0, r0, #1 c0d0058e: 60a0 str r0, [r4, #8] c0d00590: 6821 ldr r1, [r4, #0] c0d00592: 2900 cmp r1, #0 c0d00594: d1df bne.n c0d00556 <io_event+0x436> c0d00596: e02a b.n c0d005ee <io_event+0x4ce> break; case SEPROXYHAL_TAG_BUTTON_PUSH_EVENT: // for Nano S Timer_Restart(); UX_BUTTON_PUSH_EVENT(G_io_seproxyhal_spi_buffer); c0d00598: 6920 ldr r0, [r4, #16] c0d0059a: 2800 cmp r0, #0 c0d0059c: d003 beq.n c0d005a6 <io_event+0x486> c0d0059e: 78e9 ldrb r1, [r5, #3] c0d005a0: 0849 lsrs r1, r1, #1 c0d005a2: f000 ff2f bl c0d01404 <io_seproxyhal_button_push> c0d005a6: 6820 ldr r0, [r4, #0] c0d005a8: 2800 cmp r0, #0 c0d005aa: d020 beq.n c0d005ee <io_event+0x4ce> c0d005ac: 68a0 ldr r0, [r4, #8] c0d005ae: 6861 ldr r1, [r4, #4] c0d005b0: 4288 cmp r0, r1 c0d005b2: d21c bcs.n c0d005ee <io_event+0x4ce> c0d005b4: f001 fe24 bl c0d02200 <io_seproxyhal_spi_is_status_sent> c0d005b8: 2800 cmp r0, #0 c0d005ba: d118 bne.n c0d005ee <io_event+0x4ce> c0d005bc: 68a0 ldr r0, [r4, #8] c0d005be: 68e1 ldr r1, [r4, #12] c0d005c0: 2538 movs r5, #56 ; 0x38 c0d005c2: 4368 muls r0, r5 c0d005c4: 6822 ldr r2, [r4, #0] c0d005c6: 1810 adds r0, r2, r0 c0d005c8: 2900 cmp r1, #0 c0d005ca: d002 beq.n c0d005d2 <io_event+0x4b2> c0d005cc: 4788 blx r1 c0d005ce: 2800 cmp r0, #0 c0d005d0: d007 beq.n c0d005e2 <io_event+0x4c2> c0d005d2: 2801 cmp r0, #1 c0d005d4: d103 bne.n c0d005de <io_event+0x4be> c0d005d6: 68a0 ldr r0, [r4, #8] c0d005d8: 4345 muls r5, r0 c0d005da: 6820 ldr r0, [r4, #0] c0d005dc: 1940 adds r0, r0, r5 return_to_dashboard: return; } /** display function */ void io_seproxyhal_display(const bagl_element_t *element) { io_seproxyhal_display_default((bagl_element_t *) element); c0d005de: f000 fecf bl c0d01380 <io_seproxyhal_display_default> UX_FINGER_EVENT(G_io_seproxyhal_spi_buffer); break; case SEPROXYHAL_TAG_BUTTON_PUSH_EVENT: // for Nano S Timer_Restart(); UX_BUTTON_PUSH_EVENT(G_io_seproxyhal_spi_buffer); c0d005e2: 68a0 ldr r0, [r4, #8] c0d005e4: 1c40 adds r0, r0, #1 c0d005e6: 60a0 str r0, [r4, #8] c0d005e8: 6821 ldr r1, [r4, #0] c0d005ea: 2900 cmp r1, #0 c0d005ec: d1df bne.n c0d005ae <io_event+0x48e> c0d005ee: 6860 ldr r0, [r4, #4] c0d005f0: 68a1 ldr r1, [r4, #8] c0d005f2: 4281 cmp r1, r0 c0d005f4: d333 bcc.n c0d0065e <io_event+0x53e> c0d005f6: f001 fe03 bl c0d02200 <io_seproxyhal_spi_is_status_sent> c0d005fa: e030 b.n c0d0065e <io_event+0x53e> if (publicKeyNeedsRefresh == 1) { UX_REDISPLAY(); publicKeyNeedsRefresh = 0; } else { if (Timer_Expired()) { os_sched_exit(0); c0d005fc: 2000 movs r0, #0 c0d005fe: f001 fd8f bl c0d02120 <os_sched_exit> c0d00602: e02c b.n c0d0065e <io_event+0x53e> case SEPROXYHAL_TAG_DISPLAY_PROCESSED_EVENT: //Timer_Restart(); if (UX_DISPLAYED()) { // perform actions after all screen elements have been displayed } else { UX_DISPLAYED_EVENT(); c0d00604: f000 fd68 bl c0d010d8 <io_seproxyhal_init_ux> c0d00608: f000 fd6c bl c0d010e4 <io_seproxyhal_init_button> c0d0060c: 60a5 str r5, [r4, #8] c0d0060e: 6820 ldr r0, [r4, #0] c0d00610: 2800 cmp r0, #0 c0d00612: d024 beq.n c0d0065e <io_event+0x53e> c0d00614: 69e0 ldr r0, [r4, #28] c0d00616: 4917 ldr r1, [pc, #92] ; (c0d00674 <io_event+0x554>) c0d00618: 4288 cmp r0, r1 c0d0061a: d11e bne.n c0d0065a <io_event+0x53a> c0d0061c: e01f b.n c0d0065e <io_event+0x53e> c0d0061e: 6860 ldr r0, [r4, #4] c0d00620: 4285 cmp r5, r0 c0d00622: d21c bcs.n c0d0065e <io_event+0x53e> c0d00624: f001 fdec bl c0d02200 <io_seproxyhal_spi_is_status_sent> c0d00628: 2800 cmp r0, #0 c0d0062a: d118 bne.n c0d0065e <io_event+0x53e> c0d0062c: 68a0 ldr r0, [r4, #8] c0d0062e: 68e1 ldr r1, [r4, #12] c0d00630: 2538 movs r5, #56 ; 0x38 c0d00632: 4368 muls r0, r5 c0d00634: 6822 ldr r2, [r4, #0] c0d00636: 1810 adds r0, r2, r0 c0d00638: 2900 cmp r1, #0 c0d0063a: d002 beq.n c0d00642 <io_event+0x522> c0d0063c: 4788 blx r1 c0d0063e: 2800 cmp r0, #0 c0d00640: d007 beq.n c0d00652 <io_event+0x532> c0d00642: 2801 cmp r0, #1 c0d00644: d103 bne.n c0d0064e <io_event+0x52e> c0d00646: 68a0 ldr r0, [r4, #8] c0d00648: 4345 muls r5, r0 c0d0064a: 6820 ldr r0, [r4, #0] c0d0064c: 1940 adds r0, r0, r5 return_to_dashboard: return; } /** display function */ void io_seproxyhal_display(const bagl_element_t *element) { io_seproxyhal_display_default((bagl_element_t *) element); c0d0064e: f000 fe97 bl c0d01380 <io_seproxyhal_display_default> case SEPROXYHAL_TAG_DISPLAY_PROCESSED_EVENT: //Timer_Restart(); if (UX_DISPLAYED()) { // perform actions after all screen elements have been displayed } else { UX_DISPLAYED_EVENT(); c0d00652: 68a0 ldr r0, [r4, #8] c0d00654: 1c45 adds r5, r0, #1 c0d00656: 60a5 str r5, [r4, #8] c0d00658: 6820 ldr r0, [r4, #0] c0d0065a: 2800 cmp r0, #0 c0d0065c: d1df bne.n c0d0061e <io_event+0x4fe> UX_DEFAULT_EVENT(); break; } // close the event if not done previously (by a display or whatever) if (!io_seproxyhal_spi_is_status_sent()) { c0d0065e: f001 fdcf bl c0d02200 <io_seproxyhal_spi_is_status_sent> c0d00662: 2800 cmp r0, #0 c0d00664: d101 bne.n c0d0066a <io_event+0x54a> io_seproxyhal_general_status(); c0d00666: f000 fbe7 bl c0d00e38 <io_seproxyhal_general_status> } // command has been processed, DO NOT reset the current APDU transport return 1; c0d0066a: 2001 movs r0, #1 c0d0066c: b005 add sp, #20 c0d0066e: bdf0 pop {r4, r5, r6, r7, pc} c0d00670: 20001b88 .word 0x20001b88 c0d00674: b0105044 .word 0xb0105044 c0d00678: b0105055 .word 0xb0105055 c0d0067c <bottos_main>: publicKeyNeedsRefresh = 1; } } /** main loop. */ static void bottos_main(void) { c0d0067c: b5f0 push {r4, r5, r6, r7, lr} c0d0067e: b0bb sub sp, #236 ; 0xec c0d00680: 2600 movs r6, #0 volatile unsigned int rx = 0; c0d00682: 963a str r6, [sp, #232] ; 0xe8 volatile unsigned int tx = 0; c0d00684: 9639 str r6, [sp, #228] ; 0xe4 volatile unsigned int flags = 0; c0d00686: 9638 str r6, [sp, #224] ; 0xe0 c0d00688: 4c8b ldr r4, [pc, #556] ; (c0d008b8 <bottos_main+0x23c>) c0d0068a: 4d92 ldr r5, [pc, #584] ; (c0d008d4 <bottos_main+0x258>) c0d0068c: a837 add r0, sp, #220 ; 0xdc // When APDU are to be fetched from multiple IOs, like NFC+USB+BLE, make // sure the io_event is called with a // switch event, before the apdu is replied to the bootloader. This avoid // APDU injection faults. for (;;) { volatile unsigned short sw = 0; c0d0068e: 8006 strh r6, [r0, #0] c0d00690: af2c add r7, sp, #176 ; 0xb0 BEGIN_TRY { TRY c0d00692: 4638 mov r0, r7 c0d00694: f003 fe1a bl c0d042cc <setjmp> c0d00698: 8538 strh r0, [r7, #40] ; 0x28 c0d0069a: 4985 ldr r1, [pc, #532] ; (c0d008b0 <bottos_main+0x234>) c0d0069c: 4208 tst r0, r1 c0d0069e: d00f beq.n c0d006c0 <bottos_main+0x44> c0d006a0: a92c add r1, sp, #176 ; 0xb0 hashTainted = 1; THROW(0x6D00); break; } } CATCH_OTHER(e) c0d006a2: 850e strh r6, [r1, #40] ; 0x28 c0d006a4: 210f movs r1, #15 c0d006a6: 0309 lsls r1, r1, #12 { switch (e & 0xF000) { c0d006a8: 4001 ands r1, r0 c0d006aa: 2209 movs r2, #9 c0d006ac: 0312 lsls r2, r2, #12 c0d006ae: 4291 cmp r1, r2 c0d006b0: d003 beq.n c0d006ba <bottos_main+0x3e> c0d006b2: 2203 movs r2, #3 c0d006b4: 0352 lsls r2, r2, #13 c0d006b6: 4291 cmp r1, r2 c0d006b8: d151 bne.n c0d0075e <bottos_main+0xe2> c0d006ba: a937 add r1, sp, #220 ; 0xdc case 0x6000: case 0x9000: sw = e; c0d006bc: 8008 strh r0, [r1, #0] c0d006be: e055 b.n c0d0076c <bottos_main+0xf0> c0d006c0: 462f mov r7, r5 c0d006c2: a82c add r0, sp, #176 ; 0xb0 for (;;) { volatile unsigned short sw = 0; BEGIN_TRY { TRY c0d006c4: f000 fa43 bl c0d00b4e <try_context_set> { rx = tx; c0d006c8: 9839 ldr r0, [sp, #228] ; 0xe4 c0d006ca: 903a str r0, [sp, #232] ; 0xe8 c0d006cc: 2500 movs r5, #0 // ensure no race in catch_other if io_exchange throws an error tx = 0; c0d006ce: 9539 str r5, [sp, #228] ; 0xe4 rx = io_exchange(CHANNEL_APDU | flags, rx); c0d006d0: 9838 ldr r0, [sp, #224] ; 0xe0 c0d006d2: 993a ldr r1, [sp, #232] ; 0xe8 c0d006d4: b2c0 uxtb r0, r0 c0d006d6: b289 uxth r1, r1 c0d006d8: f000 fef2 bl c0d014c0 <io_exchange> c0d006dc: 903a str r0, [sp, #232] ; 0xe8 flags = 0; c0d006de: 9538 str r5, [sp, #224] ; 0xe0 PRINTF("APDU received:\n%.*H\n",100, G_io_apdu_buffer); c0d006e0: 2164 movs r1, #100 ; 0x64 c0d006e2: a076 add r0, pc, #472 ; (adr r0, c0d008bc <bottos_main+0x240>) c0d006e4: 4622 mov r2, r4 c0d006e6: f001 f82b bl c0d01740 <screen_printf> // no apdu received, well, reset the session, and reset the // bootloader configuration if (rx == 0) { c0d006ea: 983a ldr r0, [sp, #232] ; 0xe8 c0d006ec: 2800 cmp r0, #0 c0d006ee: d100 bne.n c0d006f2 <bottos_main+0x76> c0d006f0: e0bd b.n c0d0086e <bottos_main+0x1f2> // 安全条件不满足 THROW(0x6982); } // if the buffer doesn't start with the magic byte, return an error. if (G_io_apdu_buffer[0] != CLA) { c0d006f2: 7820 ldrb r0, [r4, #0] c0d006f4: 28ea cmp r0, #234 ; 0xea c0d006f6: d000 beq.n c0d006fa <bottos_main+0x7e> c0d006f8: e0be b.n c0d00878 <bottos_main+0x1fc> c0d006fa: 7861 ldrb r1, [r4, #1] c0d006fc: 206d movs r0, #109 ; 0x6d c0d006fe: 0203 lsls r3, r0, #8 c0d00700: 4875 ldr r0, [pc, #468] ; (c0d008d8 <bottos_main+0x25c>) // CLA 不支持 THROW(0x6E00); } // check the second byte (0x01) for the instruction. switch (G_io_apdu_buffer[1]) { c0d00702: 2905 cmp r1, #5 c0d00704: dc3e bgt.n c0d00784 <bottos_main+0x108> c0d00706: 2901 cmp r1, #1 c0d00708: d059 beq.n c0d007be <bottos_main+0x142> c0d0070a: 2902 cmp r1, #2 c0d0070c: d000 beq.n c0d00710 <bottos_main+0x94> c0d0070e: e0b9 b.n c0d00884 <bottos_main+0x208> exit_timer = MAX_EXIT_TIMER; Timer_UpdateDescription(); } static void Timer_Restart() { if (exit_timer != MAX_EXIT_TIMER) { c0d00710: 4972 ldr r1, [pc, #456] ; (c0d008dc <bottos_main+0x260>) c0d00712: 6809 ldr r1, [r1, #0] c0d00714: 4281 cmp r1, r0 c0d00716: d007 beq.n c0d00728 <bottos_main+0xac> Timer_UpdateDescription(); } } static void Timer_Set() { exit_timer = MAX_EXIT_TIMER; c0d00718: 4970 ldr r1, [pc, #448] ; (c0d008dc <bottos_main+0x260>) c0d0071a: 6008 str r0, [r1, #0] #define MAX_EXIT_TIMER 4098 #define EXIT_TIMER_REFRESH_INTERVAL 512 static void Timer_UpdateDescription() { snprintf(timer_desc, MAX_TIMER_TEXT_WIDTH, "%d", exit_timer / EXIT_TIMER_REFRESH_INTERVAL); c0d0071c: 2104 movs r1, #4 c0d0071e: 2308 movs r3, #8 c0d00720: 486f ldr r0, [pc, #444] ; (c0d008e0 <bottos_main+0x264>) c0d00722: a270 add r2, pc, #448 ; (adr r2, c0d008e4 <bottos_main+0x268>) c0d00724: f001 f9b2 bl c0d01a8c <snprintf> // we're getting a transaction to sign, in parts. case INS_SIGN_HASH: { Timer_Restart(); // 检查P1是否为0x01 if ((G_io_apdu_buffer[2] != P1_CONFIRM)) { c0d00728: 78a0 ldrb r0, [r4, #2] c0d0072a: 2801 cmp r0, #1 c0d0072c: d000 beq.n c0d00730 <bottos_main+0xb4> c0d0072e: e0ae b.n c0d0088e <bottos_main+0x212> c0d00730: 4638 mov r0, r7 // 不正确的参数 THROW(0x6A86); } // if this is the first transaction part, reset the hash and all the other temporary variables. if (hashTainted) { c0d00732: 7800 ldrb r0, [r0, #0] c0d00734: 2800 cmp r0, #0 c0d00736: d008 beq.n c0d0074a <bottos_main+0xce> cx_sha256_init(&hash); c0d00738: 486e ldr r0, [pc, #440] ; (c0d008f4 <bottos_main+0x278>) c0d0073a: f001 fc43 bl c0d01fc4 <cx_sha256_init> hashTainted = 0; c0d0073e: 4865 ldr r0, [pc, #404] ; (c0d008d4 <bottos_main+0x258>) c0d00740: 7005 strb r5, [r0, #0] raw_tx_ix = 0; c0d00742: 486d ldr r0, [pc, #436] ; (c0d008f8 <bottos_main+0x27c>) c0d00744: 6005 str r5, [r0, #0] raw_tx_len = 0; c0d00746: 486d ldr r0, [pc, #436] ; (c0d008fc <bottos_main+0x280>) c0d00748: 6005 str r5, [r0, #0] } // move the contents of the buffer into raw_tx, and update raw_tx_ix to the end of the buffer, to be ready for the next part of the tx. unsigned int len = get_apdu_buffer_length(); c0d0074a: f002 fc89 bl c0d03060 <get_apdu_buffer_length> // todo:: 长度应为52 if(len != 52) { c0d0074e: 2834 cmp r0, #52 ; 0x34 c0d00750: d000 beq.n c0d00754 <bottos_main+0xd8> c0d00752: e0a1 b.n c0d00898 <bottos_main+0x21c> hashTainted = 1; // 长度错误 THROW(0x6C00); } update_sign_hash(); c0d00754: f002 fb74 bl c0d02e40 <update_sign_hash> ui_confirm_sign(); c0d00758: f002 fc18 bl c0d02f8c <ui_confirm_sign> c0d0075c: e016 b.n c0d0078c <bottos_main+0x110> case 0x6000: case 0x9000: sw = e; break; default: sw = 0x6800 | (e & 0x7FF); c0d0075e: 4955 ldr r1, [pc, #340] ; (c0d008b4 <bottos_main+0x238>) c0d00760: 4008 ands r0, r1 c0d00762: 210d movs r1, #13 c0d00764: 02c9 lsls r1, r1, #11 c0d00766: 4301 orrs r1, r0 c0d00768: a837 add r0, sp, #220 ; 0xdc c0d0076a: 8001 strh r1, [r0, #0] break; } // Unexpected exception => report G_io_apdu_buffer[tx] = sw >> 8; c0d0076c: 9837 ldr r0, [sp, #220] ; 0xdc c0d0076e: 0a00 lsrs r0, r0, #8 c0d00770: 9939 ldr r1, [sp, #228] ; 0xe4 c0d00772: 5460 strb r0, [r4, r1] G_io_apdu_buffer[tx + 1] = sw; c0d00774: 9837 ldr r0, [sp, #220] ; 0xdc c0d00776: 9939 ldr r1, [sp, #228] ; 0xe4 default: sw = 0x6800 | (e & 0x7FF); break; } // Unexpected exception => report G_io_apdu_buffer[tx] = sw >> 8; c0d00778: 1861 adds r1, r4, r1 G_io_apdu_buffer[tx + 1] = sw; c0d0077a: 7048 strb r0, [r1, #1] tx += 2; c0d0077c: 9839 ldr r0, [sp, #228] ; 0xe4 c0d0077e: 1c80 adds r0, r0, #2 c0d00780: 9039 str r0, [sp, #228] ; 0xe4 c0d00782: e008 b.n c0d00796 <bottos_main+0x11a> c0d00784: 2906 cmp r1, #6 c0d00786: d116 bne.n c0d007b6 <bottos_main+0x13a> } break; case INS_TEST: { // 显示UI ui_test(); c0d00788: f002 fb8c bl c0d02ea4 <ui_test> c0d0078c: 2010 movs r0, #16 c0d0078e: 9938 ldr r1, [sp, #224] ; 0xe0 c0d00790: 4301 orrs r1, r0 c0d00792: 9138 str r1, [sp, #224] ; 0xe0 c0d00794: 463d mov r5, r7 // Unexpected exception => report G_io_apdu_buffer[tx] = sw >> 8; G_io_apdu_buffer[tx + 1] = sw; tx += 2; } FINALLY c0d00796: f000 fb47 bl c0d00e28 <try_context_get> c0d0079a: a92c add r1, sp, #176 ; 0xb0 c0d0079c: 4288 cmp r0, r1 c0d0079e: d103 bne.n c0d007a8 <bottos_main+0x12c> c0d007a0: f000 fb44 bl c0d00e2c <try_context_get_previous> c0d007a4: f000 f9d3 bl c0d00b4e <try_context_set> c0d007a8: a82c add r0, sp, #176 ; 0xb0 { } } END_TRY; c0d007aa: 8d00 ldrh r0, [r0, #40] ; 0x28 c0d007ac: 2800 cmp r0, #0 c0d007ae: d100 bne.n c0d007b2 <bottos_main+0x136> c0d007b0: e76c b.n c0d0068c <bottos_main+0x10> c0d007b2: f000 fb34 bl c0d00e1e <os_longjmp> c0d007b6: 29ff cmp r1, #255 ; 0xff c0d007b8: d164 bne.n c0d00884 <bottos_main+0x208> } return_to_dashboard: return; } c0d007ba: b03b add sp, #236 ; 0xec c0d007bc: bdf0 pop {r4, r5, r6, r7, pc} c0d007be: 4a47 ldr r2, [pc, #284] ; (c0d008dc <bottos_main+0x260>) exit_timer = MAX_EXIT_TIMER; Timer_UpdateDescription(); } static void Timer_Restart() { if (exit_timer != MAX_EXIT_TIMER) { c0d007c0: 6811 ldr r1, [r2, #0] c0d007c2: 4281 cmp r1, r0 c0d007c4: d008 beq.n c0d007d8 <bottos_main+0x15c> Timer_UpdateDescription(); } } static void Timer_Set() { exit_timer = MAX_EXIT_TIMER; c0d007c6: 6010 str r0, [r2, #0] #define MAX_EXIT_TIMER 4098 #define EXIT_TIMER_REFRESH_INTERVAL 512 static void Timer_UpdateDescription() { snprintf(timer_desc, MAX_TIMER_TEXT_WIDTH, "%d", exit_timer / EXIT_TIMER_REFRESH_INTERVAL); c0d007c8: 4845 ldr r0, [pc, #276] ; (c0d008e0 <bottos_main+0x264>) c0d007ca: 2104 movs r1, #4 c0d007cc: a245 add r2, pc, #276 ; (adr r2, c0d008e4 <bottos_main+0x268>) c0d007ce: 461e mov r6, r3 c0d007d0: 2308 movs r3, #8 c0d007d2: f001 f95b bl c0d01a8c <snprintf> c0d007d6: 4633 mov r3, r6 Timer_Restart(); cx_ecfp_public_key_t publicKey; cx_ecfp_private_key_t privateKey; if (rx < APDU_HEADER_LENGTH + BIP44_BYTE_LENGTH) { c0d007d8: 983a ldr r0, [sp, #232] ; 0xe8 c0d007da: 2818 cmp r0, #24 c0d007dc: d962 bls.n c0d008a4 <bottos_main+0x228> unsigned char *bip44_in = G_io_apdu_buffer + APDU_HEADER_LENGTH; unsigned int bip44_path[BIP44_PATH_LEN]; uint32_t i; for (i = 0; i < BIP44_PATH_LEN; i++) { bip44_path[i] = (bip44_in[0] << 24) | (bip44_in[1] << 16) | (bip44_in[2] << 8) | (bip44_in[3]); c0d007de: 00a8 lsls r0, r5, #2 c0d007e0: 1821 adds r1, r4, r0 c0d007e2: 794a ldrb r2, [r1, #5] c0d007e4: 0612 lsls r2, r2, #24 c0d007e6: 798b ldrb r3, [r1, #6] c0d007e8: 041b lsls r3, r3, #16 c0d007ea: 4313 orrs r3, r2 c0d007ec: 79ca ldrb r2, [r1, #7] c0d007ee: 0212 lsls r2, r2, #8 c0d007f0: 431a orrs r2, r3 c0d007f2: 7a09 ldrb r1, [r1, #8] c0d007f4: 4311 orrs r1, r2 c0d007f6: aa0a add r2, sp, #40 ; 0x28 c0d007f8: 5011 str r1, [r2, r0] /** BIP44 path, used to derive the private key from the mnemonic by calling os_perso_derive_node_bip32. */ unsigned char *bip44_in = G_io_apdu_buffer + APDU_HEADER_LENGTH; unsigned int bip44_path[BIP44_PATH_LEN]; uint32_t i; for (i = 0; i < BIP44_PATH_LEN; i++) { c0d007fa: 1c6d adds r5, r5, #1 c0d007fc: 2d05 cmp r5, #5 c0d007fe: d1ee bne.n c0d007de <bottos_main+0x162> c0d00800: 2400 movs r4, #0 bip44_path[i] = (bip44_in[0] << 24) | (bip44_in[1] << 16) | (bip44_in[2] << 8) | (bip44_in[3]); bip44_in += 4; } unsigned char privateKeyData[32]; os_perso_derive_node_bip32(CX_CURVE_256K1, bip44_path, BIP44_PATH_LEN, privateKeyData, NULL); c0d00802: 4668 mov r0, sp c0d00804: 6004 str r4, [r0, #0] c0d00806: 2521 movs r5, #33 ; 0x21 c0d00808: a90a add r1, sp, #40 ; 0x28 c0d0080a: 2205 movs r2, #5 c0d0080c: ae02 add r6, sp, #8 c0d0080e: 4628 mov r0, r5 c0d00810: 4633 mov r3, r6 c0d00812: f001 fc6d bl c0d020f0 <os_perso_derive_node_bip32> cx_ecdsa_init_private_key(CX_CURVE_256K1, privateKeyData, 32, &privateKey); c0d00816: 2220 movs r2, #32 c0d00818: af0f add r7, sp, #60 ; 0x3c c0d0081a: 4628 mov r0, r5 c0d0081c: 4631 mov r1, r6 c0d0081e: 463b mov r3, r7 c0d00820: f001 fbfe bl c0d02020 <cx_ecfp_init_private_key> c0d00824: ae19 add r6, sp, #100 ; 0x64 // generate the public key. cx_ecdsa_init_public_key(CX_CURVE_256K1, NULL, 0, &publicKey); c0d00826: 4628 mov r0, r5 c0d00828: 4621 mov r1, r4 c0d0082a: 4622 mov r2, r4 c0d0082c: 4633 mov r3, r6 c0d0082e: f001 fbdf bl c0d01ff0 <cx_ecfp_init_public_key> c0d00832: 2401 movs r4, #1 cx_ecfp_generate_pair(CX_CURVE_256K1, &publicKey, &privateKey, 1); c0d00834: 4628 mov r0, r5 c0d00836: 4631 mov r1, r6 c0d00838: 463a mov r2, r7 c0d0083a: 4623 mov r3, r4 c0d0083c: f001 fc08 bl c0d02050 <cx_ecfp_generate_pair> // push the public key onto the response buffer. os_memmove(G_io_apdu_buffer, publicKey.W, 65); c0d00840: 3608 adds r6, #8 c0d00842: 481d ldr r0, [pc, #116] ; (c0d008b8 <bottos_main+0x23c>) c0d00844: 2541 movs r5, #65 ; 0x41 c0d00846: 4631 mov r1, r6 c0d00848: 462a mov r2, r5 c0d0084a: f000 fa34 bl c0d00cb6 <os_memmove> tx = 65; c0d0084e: 9539 str r5, [sp, #228] ; 0xe4 display_public_key(publicKey.W); c0d00850: 4630 mov r0, r6 c0d00852: f000 f921 bl c0d00a98 <display_public_key> return 0; } /** refreshes the display if the public key was changed ans we are on the page displaying the public key */ static void refresh_public_key_display(void) { if ((uiState == UI_PUBLIC_KEY_1) || (uiState == UI_PUBLIC_KEY_2)) { c0d00856: 4824 ldr r0, [pc, #144] ; (c0d008e8 <bottos_main+0x26c>) c0d00858: 7800 ldrb r0, [r0, #0] c0d0085a: 21fe movs r1, #254 ; 0xfe c0d0085c: 4001 ands r1, r0 c0d0085e: 2908 cmp r1, #8 c0d00860: d101 bne.n c0d00866 <bottos_main+0x1ea> publicKeyNeedsRefresh = 1; c0d00862: 4822 ldr r0, [pc, #136] ; (c0d008ec <bottos_main+0x270>) c0d00864: 7004 strb r4, [r0, #0] display_public_key(publicKey.W); refresh_public_key_display(); // return 0x9000 OK. THROW(0x9000); c0d00866: 2009 movs r0, #9 c0d00868: 0300 lsls r0, r0, #12 c0d0086a: f000 fad8 bl c0d00e1e <os_longjmp> PRINTF("APDU received:\n%.*H\n",100, G_io_apdu_buffer); // no apdu received, well, reset the session, and reset the // bootloader configuration if (rx == 0) { hashTainted = 1; c0d0086e: 2001 movs r0, #1 c0d00870: 7038 strb r0, [r7, #0] // 安全条件不满足 THROW(0x6982); c0d00872: 4823 ldr r0, [pc, #140] ; (c0d00900 <bottos_main+0x284>) c0d00874: f000 fad3 bl c0d00e1e <os_longjmp> } // if the buffer doesn't start with the magic byte, return an error. if (G_io_apdu_buffer[0] != CLA) { hashTainted = 1; c0d00878: 2001 movs r0, #1 c0d0087a: 7038 strb r0, [r7, #0] // CLA 不支持 THROW(0x6E00); c0d0087c: 2037 movs r0, #55 ; 0x37 c0d0087e: 0240 lsls r0, r0, #9 c0d00880: f000 facd bl c0d00e1e <os_longjmp> goto return_to_dashboard; // we're asked to do an unknown command default: // return an error. hashTainted = 1; c0d00884: 2001 movs r0, #1 c0d00886: 7038 strb r0, [r7, #0] THROW(0x6D00); c0d00888: 4618 mov r0, r3 c0d0088a: f000 fac8 bl c0d00e1e <os_longjmp> // we're getting a transaction to sign, in parts. case INS_SIGN_HASH: { Timer_Restart(); // 检查P1是否为0x01 if ((G_io_apdu_buffer[2] != P1_CONFIRM)) { hashTainted = 1; c0d0088e: 2001 movs r0, #1 c0d00890: 7038 strb r0, [r7, #0] // 不正确的参数 THROW(0x6A86); c0d00892: 4817 ldr r0, [pc, #92] ; (c0d008f0 <bottos_main+0x274>) c0d00894: f000 fac3 bl c0d00e1e <os_longjmp> // move the contents of the buffer into raw_tx, and update raw_tx_ix to the end of the buffer, to be ready for the next part of the tx. unsigned int len = get_apdu_buffer_length(); // todo:: 长度应为52 if(len != 52) { hashTainted = 1; c0d00898: 2001 movs r0, #1 c0d0089a: 7038 strb r0, [r7, #0] // 长度错误 THROW(0x6C00); c0d0089c: 201b movs r0, #27 c0d0089e: 0280 lsls r0, r0, #10 c0d008a0: f000 fabd bl c0d00e1e <os_longjmp> cx_ecfp_public_key_t publicKey; cx_ecfp_private_key_t privateKey; if (rx < APDU_HEADER_LENGTH + BIP44_BYTE_LENGTH) { hashTainted = 1; c0d008a4: 2001 movs r0, #1 c0d008a6: 7038 strb r0, [r7, #0] THROW(0x6D09); c0d008a8: 3309 adds r3, #9 c0d008aa: 4618 mov r0, r3 c0d008ac: f000 fab7 bl c0d00e1e <os_longjmp> c0d008b0: 0000ffff .word 0x0000ffff c0d008b4: 000007ff .word 0x000007ff c0d008b8: 200018f8 .word 0x200018f8 c0d008bc: 55445041 .word 0x55445041 c0d008c0: 63657220 .word 0x63657220 c0d008c4: 65766965 .word 0x65766965 c0d008c8: 250a3a64 .word 0x250a3a64 c0d008cc: 0a482a2e .word 0x0a482a2e c0d008d0: 00000000 .word 0x00000000 c0d008d4: 20001b7c .word 0x20001b7c c0d008d8: 00001002 .word 0x00001002 c0d008dc: 20001c38 .word 0x20001c38 c0d008e0: 20001c3c .word 0x20001c3c c0d008e4: 00006425 .word 0x00006425 c0d008e8: 20001b84 .word 0x20001b84 c0d008ec: 20001c40 .word 0x20001c40 c0d008f0: 00006a86 .word 0x00006a86 c0d008f4: 20001b10 .word 0x20001b10 c0d008f8: 20001b80 .word 0x20001b80 c0d008fc: 20001b0c .word 0x20001b0c c0d00900: 00006982 .word 0x00006982 c0d00904 <to_address>: os_memmove(dest + dec_place_ix + 1, base10_buffer + dec_place_ix, buffer_len - dec_place_ix); } } /** converts a ONT scripthas to a ONT address by adding a checksum and encoding in base58 */ static void to_address(char *dest, unsigned int dest_len, const unsigned char *script_hash) { c0d00904: b5f0 push {r4, r5, r6, r7, lr} c0d00906: b0d1 sub sp, #324 ; 0x144 c0d00908: 9004 str r0, [sp, #16] c0d0090a: ad0a add r5, sp, #40 ; 0x28 unsigned char address_hash_result_0[SHA256_HASH_LEN]; unsigned char address_hash_result_1[SHA256_HASH_LEN]; // concatenate the ADDRESS_VERSION and the address. unsigned char address[ADDRESS_LEN]; address[0] = ADDRESS_VERSION; c0d0090c: 2017 movs r0, #23 c0d0090e: 7028 strb r0, [r5, #0] os_memmove(address + 1, script_hash, SCRIPT_HASH_LEN); c0d00910: 1c68 adds r0, r5, #1 c0d00912: 2214 movs r2, #20 c0d00914: f000 f9cf bl c0d00cb6 <os_memmove> // do a sha256 hash of the address twice. cx_sha256_init(&address_hash); c0d00918: 4c4a ldr r4, [pc, #296] ; (c0d00a44 <to_address+0x140>) c0d0091a: 4620 mov r0, r4 c0d0091c: f001 fb52 bl c0d01fc4 <cx_sha256_init> cx_hash(&address_hash.header, CX_LAST, address, SCRIPT_HASH_LEN + 1, address_hash_result_0, 32); c0d00920: 2720 movs r7, #32 c0d00922: 4668 mov r0, sp c0d00924: 6047 str r7, [r0, #4] c0d00926: a919 add r1, sp, #100 ; 0x64 c0d00928: 9109 str r1, [sp, #36] ; 0x24 c0d0092a: 6001 str r1, [r0, #0] c0d0092c: 2601 movs r6, #1 c0d0092e: 2315 movs r3, #21 c0d00930: 4620 mov r0, r4 c0d00932: 4631 mov r1, r6 c0d00934: 462a mov r2, r5 c0d00936: f001 fb13 bl c0d01f60 <cx_hash> cx_sha256_init(&address_hash); c0d0093a: 4620 mov r0, r4 c0d0093c: f001 fb42 bl c0d01fc4 <cx_sha256_init> cx_hash(&address_hash.header, CX_LAST, address_hash_result_0, SHA256_HASH_LEN, address_hash_result_1, 32); c0d00940: 4668 mov r0, sp c0d00942: 6047 str r7, [r0, #4] c0d00944: ac11 add r4, sp, #68 ; 0x44 c0d00946: 6004 str r4, [r0, #0] c0d00948: 483e ldr r0, [pc, #248] ; (c0d00a44 <to_address+0x140>) c0d0094a: 4631 mov r1, r6 c0d0094c: 9a09 ldr r2, [sp, #36] ; 0x24 c0d0094e: 463b mov r3, r7 c0d00950: f001 fb06 bl c0d01f60 <cx_hash> // add the first bytes of the hash as a checksum at the end of the address. os_memmove(address + 1 + SCRIPT_HASH_LEN, address_hash_result_1, SCRIPT_HASH_CHECKSUM_LEN); c0d00954: 4628 mov r0, r5 c0d00956: 3015 adds r0, #21 c0d00958: 2204 movs r2, #4 c0d0095a: 4621 mov r1, r4 c0d0095c: f000 f9ab bl c0d00cb6 <os_memmove> c0d00960: a841 add r0, sp, #260 ; 0x104 unsigned char zeroCount = 0; if (in_length > sizeof(tmp)) { hashTainted = 1; THROW(0x6D11); } os_memmove(tmp, in, in_length); c0d00962: 2219 movs r2, #25 c0d00964: 4629 mov r1, r5 c0d00966: f000 f9a6 bl c0d00cb6 <os_memmove> c0d0096a: 2600 movs r6, #0 c0d0096c: a841 add r0, sp, #260 ; 0x104 while ((zeroCount < in_length) && (tmp[zeroCount] == 0)) { c0d0096e: 5d80 ldrb r0, [r0, r6] c0d00970: 2800 cmp r0, #0 c0d00972: d104 bne.n c0d0097e <to_address+0x7a> ++zeroCount; c0d00974: 1c76 adds r6, r6, #1 if (in_length > sizeof(tmp)) { hashTainted = 1; THROW(0x6D11); } os_memmove(tmp, in, in_length); while ((zeroCount < in_length) && (tmp[zeroCount] == 0)) { c0d00976: 2e19 cmp r6, #25 c0d00978: d3f8 bcc.n c0d0096c <to_address+0x68> c0d0097a: 2732 movs r7, #50 ; 0x32 c0d0097c: e046 b.n c0d00a0c <to_address+0x108> c0d0097e: 2000 movs r0, #0 c0d00980: 9005 str r0, [sp, #20] c0d00982: 43c5 mvns r5, r0 c0d00984: 2732 movs r7, #50 ; 0x32 c0d00986: 2231 movs r2, #49 ; 0x31 c0d00988: 9609 str r6, [sp, #36] ; 0x24 c0d0098a: 9603 str r6, [sp, #12] c0d0098c: 4633 mov r3, r6 c0d0098e: 9708 str r7, [sp, #32] c0d00990: 9207 str r2, [sp, #28] c0d00992: 9306 str r3, [sp, #24] startAt = zeroCount; while (startAt < in_length) { unsigned short remainder = 0; unsigned char divLoop; for (divLoop = startAt; divLoop < in_length; divLoop++) { c0d00994: b2de uxtb r6, r3 c0d00996: 436e muls r6, r5 c0d00998: 9905 ldr r1, [sp, #20] unsigned short digit256 = (unsigned short) (tmp[divLoop] & 0xff); c0d0099a: 462f mov r7, r5 c0d0099c: 4377 muls r7, r6 c0d0099e: ac41 add r4, sp, #260 ; 0x104 unsigned short tmpDiv = remainder * 256 + digit256; c0d009a0: 5de2 ldrb r2, [r4, r7] c0d009a2: 0208 lsls r0, r1, #8 tmp[divLoop] = (unsigned char) (tmpDiv / alphabet_len); c0d009a4: 4310 orrs r0, r2 c0d009a6: 213a movs r1, #58 ; 0x3a remainder = (tmpDiv % alphabet_len); c0d009a8: f003 fbf4 bl c0d04194 <__aeabi_uidivmod> unsigned short remainder = 0; unsigned char divLoop; for (divLoop = startAt; divLoop < in_length; divLoop++) { unsigned short digit256 = (unsigned short) (tmp[divLoop] & 0xff); unsigned short tmpDiv = remainder * 256 + digit256; tmp[divLoop] = (unsigned char) (tmpDiv / alphabet_len); c0d009ac: 55e0 strb r0, [r4, r7] startAt = zeroCount; while (startAt < in_length) { unsigned short remainder = 0; unsigned char divLoop; for (divLoop = startAt; divLoop < in_length; divLoop++) { c0d009ae: 1e76 subs r6, r6, #1 c0d009b0: 4630 mov r0, r6 c0d009b2: 3019 adds r0, #25 c0d009b4: d1f1 bne.n c0d0099a <to_address+0x96> c0d009b6: a841 add r0, sp, #260 ; 0x104 unsigned short digit256 = (unsigned short) (tmp[divLoop] & 0xff); unsigned short tmpDiv = remainder * 256 + digit256; tmp[divLoop] = (unsigned char) (tmpDiv / alphabet_len); remainder = (tmpDiv % alphabet_len); } if (tmp[startAt] == 0) { c0d009b8: 9a09 ldr r2, [sp, #36] ; 0x24 c0d009ba: 5c82 ldrb r2, [r0, r2] ++startAt; } buffer[--buffer_ix] = *(alphabet + remainder); c0d009bc: 4823 ldr r0, [pc, #140] ; (c0d00a4c <to_address+0x148>) c0d009be: 4478 add r0, pc c0d009c0: 5c43 ldrb r3, [r0, r1] c0d009c2: 9f08 ldr r7, [sp, #32] c0d009c4: 1e7f subs r7, r7, #1 c0d009c6: b2f8 uxtb r0, r7 c0d009c8: ac21 add r4, sp, #132 ; 0x84 c0d009ca: 5423 strb r3, [r4, r0] c0d009cc: 9c06 ldr r4, [sp, #24] unsigned short digit256 = (unsigned short) (tmp[divLoop] & 0xff); unsigned short tmpDiv = remainder * 256 + digit256; tmp[divLoop] = (unsigned char) (tmpDiv / alphabet_len); remainder = (tmpDiv % alphabet_len); } if (tmp[startAt] == 0) { c0d009ce: 1c63 adds r3, r4, #1 c0d009d0: 2a00 cmp r2, #0 c0d009d2: d000 beq.n c0d009d6 <to_address+0xd2> c0d009d4: 4623 mov r3, r4 c0d009d6: b2de uxtb r6, r3 c0d009d8: 9c07 ldr r4, [sp, #28] hashTainted = 1; THROW(0x6D12); } startAt = zeroCount; while (startAt < in_length) { c0d009da: 1e62 subs r2, r4, #1 c0d009dc: 9609 str r6, [sp, #36] ; 0x24 c0d009de: 2e19 cmp r6, #25 c0d009e0: d3d5 bcc.n c0d0098e <to_address+0x8a> if (tmp[startAt] == 0) { ++startAt; } buffer[--buffer_ix] = *(alphabet + remainder); } while ((buffer_ix < (2 * in_length)) && (buffer[buffer_ix] == *(alphabet + 0))) { c0d009e2: 2831 cmp r0, #49 ; 0x31 c0d009e4: d80e bhi.n c0d00a04 <to_address+0x100> c0d009e6: 2900 cmp r1, #0 c0d009e8: 9e03 ldr r6, [sp, #12] c0d009ea: d10c bne.n c0d00a06 <to_address+0x102> ++buffer_ix; c0d009ec: b2e0 uxtb r0, r4 c0d009ee: 1c40 adds r0, r0, #1 c0d009f0: 1c7f adds r7, r7, #1 if (tmp[startAt] == 0) { ++startAt; } buffer[--buffer_ix] = *(alphabet + remainder); } while ((buffer_ix < (2 * in_length)) && (buffer[buffer_ix] == *(alphabet + 0))) { c0d009f2: 2831 cmp r0, #49 ; 0x31 c0d009f4: d807 bhi.n c0d00a06 <to_address+0x102> c0d009f6: a921 add r1, sp, #132 ; 0x84 c0d009f8: 5c09 ldrb r1, [r1, r0] c0d009fa: 1c40 adds r0, r0, #1 c0d009fc: 2931 cmp r1, #49 ; 0x31 c0d009fe: d0f7 beq.n c0d009f0 <to_address+0xec> c0d00a00: 1e47 subs r7, r0, #1 c0d00a02: e000 b.n c0d00a06 <to_address+0x102> c0d00a04: 9e03 ldr r6, [sp, #12] c0d00a06: 20ff movs r0, #255 ; 0xff ++buffer_ix; } while (zeroCount-- > 0) { c0d00a08: 4206 tst r6, r0 c0d00a0a: d00b beq.n c0d00a24 <to_address+0x120> c0d00a0c: 4638 mov r0, r7 c0d00a0e: 4631 mov r1, r6 buffer[--buffer_ix] = *(alphabet + 0); c0d00a10: 1e40 subs r0, r0, #1 c0d00a12: b2c2 uxtb r2, r0 c0d00a14: ab21 add r3, sp, #132 ; 0x84 c0d00a16: 2431 movs r4, #49 ; 0x31 c0d00a18: 549c strb r4, [r3, r2] buffer[--buffer_ix] = *(alphabet + remainder); } while ((buffer_ix < (2 * in_length)) && (buffer[buffer_ix] == *(alphabet + 0))) { ++buffer_ix; } while (zeroCount-- > 0) { c0d00a1a: 1e49 subs r1, r1, #1 c0d00a1c: 22ff movs r2, #255 ; 0xff c0d00a1e: 4211 tst r1, r2 c0d00a20: d1f6 bne.n c0d00a10 <to_address+0x10c> c0d00a22: 1bbf subs r7, r7, r6 buffer[--buffer_ix] = *(alphabet + 0); } const unsigned int true_out_length = (2 * in_length) - buffer_ix; c0d00a24: b2f8 uxtb r0, r7 c0d00a26: 2132 movs r1, #50 ; 0x32 c0d00a28: 1a0a subs r2, r1, r0 if (true_out_length > out_length) { c0d00a2a: 2a23 cmp r2, #35 ; 0x23 c0d00a2c: d206 bcs.n c0d00a3c <to_address+0x138> c0d00a2e: a921 add r1, sp, #132 ; 0x84 THROW(0x6D14); } os_memmove(out, (buffer + buffer_ix), true_out_length); c0d00a30: 1809 adds r1, r1, r0 c0d00a32: 9804 ldr r0, [sp, #16] c0d00a34: f000 f93f bl c0d00cb6 <os_memmove> // add the first bytes of the hash as a checksum at the end of the address. os_memmove(address + 1 + SCRIPT_HASH_LEN, address_hash_result_1, SCRIPT_HASH_CHECKSUM_LEN); // encode the version + address + checksum in base58 encode_base_58(address, ADDRESS_LEN, dest, dest_len); } c0d00a38: b051 add sp, #324 ; 0x144 c0d00a3a: bdf0 pop {r4, r5, r6, r7, pc} while (zeroCount-- > 0) { buffer[--buffer_ix] = *(alphabet + 0); } const unsigned int true_out_length = (2 * in_length) - buffer_ix; if (true_out_length > out_length) { THROW(0x6D14); c0d00a3c: 4802 ldr r0, [pc, #8] ; (c0d00a48 <to_address+0x144>) c0d00a3e: f000 f9ee bl c0d00e1e <os_longjmp> c0d00a42: 46c0 nop ; (mov r8, r8) c0d00a44: 20001880 .word 0x20001880 c0d00a48: 00006d14 .word 0x00006d14 c0d00a4c: 000039b8 .word 0x000039b8 c0d00a50 <public_key_hash160>: os_memmove(current_public_key[0], NO_PUBLIC_KEY_0, sizeof(NO_PUBLIC_KEY_0)); os_memmove(current_public_key[1], NO_PUBLIC_KEY_1, sizeof(NO_PUBLIC_KEY_1)); publicKeyNeedsRefresh = 0; } void public_key_hash160(unsigned char *in, unsigned short inlen, unsigned char *out) { c0d00a50: b5f0 push {r4, r5, r6, r7, lr} c0d00a52: b0a9 sub sp, #164 ; 0xa4 c0d00a54: ab03 add r3, sp, #12 c0d00a56: c307 stmia r3!, {r0, r1, r2} c0d00a58: ad0e add r5, sp, #56 ; 0x38 cx_sha256_t shasha; cx_ripemd160_t riprip; } u; unsigned char buffer[32]; cx_sha256_init(&u.shasha); c0d00a5a: 4628 mov r0, r5 c0d00a5c: f001 fab2 bl c0d01fc4 <cx_sha256_init> cx_hash(&u.shasha.header, CX_LAST, in, inlen, buffer, 32); c0d00a60: 2620 movs r6, #32 c0d00a62: 4668 mov r0, sp c0d00a64: 6046 str r6, [r0, #4] c0d00a66: af06 add r7, sp, #24 c0d00a68: 6007 str r7, [r0, #0] c0d00a6a: 2401 movs r4, #1 c0d00a6c: 4628 mov r0, r5 c0d00a6e: 4621 mov r1, r4 c0d00a70: 9a03 ldr r2, [sp, #12] c0d00a72: 9b04 ldr r3, [sp, #16] c0d00a74: f001 fa74 bl c0d01f60 <cx_hash> cx_ripemd160_init(&u.riprip); c0d00a78: 4628 mov r0, r5 c0d00a7a: f001 fa8d bl c0d01f98 <cx_ripemd160_init> cx_hash(&u.riprip.header, CX_LAST, buffer, 32, out, 20); c0d00a7e: 2014 movs r0, #20 c0d00a80: 4669 mov r1, sp c0d00a82: 9a05 ldr r2, [sp, #20] c0d00a84: 600a str r2, [r1, #0] c0d00a86: 6048 str r0, [r1, #4] c0d00a88: 4628 mov r0, r5 c0d00a8a: 4621 mov r1, r4 c0d00a8c: 463a mov r2, r7 c0d00a8e: 4633 mov r3, r6 c0d00a90: f001 fa66 bl c0d01f60 <cx_hash> } c0d00a94: b029 add sp, #164 ; 0xa4 c0d00a96: bdf0 pop {r4, r5, r6, r7, pc} c0d00a98 <display_public_key>: void display_public_key(const unsigned char *public_key) { c0d00a98: b5f0 push {r4, r5, r6, r7, lr} c0d00a9a: b0a1 sub sp, #132 ; 0x84 c0d00a9c: 9000 str r0, [sp, #0] os_memmove(current_public_key[0], TXT_BLANK, sizeof(TXT_BLANK)); c0d00a9e: 4e28 ldr r6, [pc, #160] ; (c0d00b40 <display_public_key+0xa8>) c0d00aa0: 4c28 ldr r4, [pc, #160] ; (c0d00b44 <display_public_key+0xac>) c0d00aa2: 447c add r4, pc c0d00aa4: 2712 movs r7, #18 c0d00aa6: 4630 mov r0, r6 c0d00aa8: 4621 mov r1, r4 c0d00aaa: 463a mov r2, r7 c0d00aac: f000 f903 bl c0d00cb6 <os_memmove> os_memmove(current_public_key[1], TXT_BLANK, sizeof(TXT_BLANK)); c0d00ab0: 3612 adds r6, #18 c0d00ab2: 4630 mov r0, r6 c0d00ab4: 4621 mov r1, r4 c0d00ab6: 463a mov r2, r7 c0d00ab8: f000 f8fd bl c0d00cb6 <os_memmove> os_memmove(current_public_key[2], TXT_BLANK, sizeof(TXT_BLANK)); c0d00abc: 4d20 ldr r5, [pc, #128] ; (c0d00b40 <display_public_key+0xa8>) c0d00abe: 3524 adds r5, #36 ; 0x24 c0d00ac0: 4628 mov r0, r5 c0d00ac2: 4621 mov r1, r4 c0d00ac4: 463a mov r2, r7 c0d00ac6: f000 f8f6 bl c0d00cb6 <os_memmove> unsigned char public_key_encoded[33]; public_key_encoded[0] = ((public_key[64] & 1) ? 0x03 : 0x02); c0d00aca: 2040 movs r0, #64 ; 0x40 c0d00acc: 9a00 ldr r2, [sp, #0] c0d00ace: 5c10 ldrb r0, [r2, r0] c0d00ad0: 2101 movs r1, #1 c0d00ad2: 4001 ands r1, r0 c0d00ad4: 2002 movs r0, #2 c0d00ad6: 4308 orrs r0, r1 c0d00ad8: ac18 add r4, sp, #96 ; 0x60 c0d00ada: 7020 strb r0, [r4, #0] os_memmove(public_key_encoded + 1, public_key + 1, 32); c0d00adc: 1c60 adds r0, r4, #1 c0d00ade: 1c51 adds r1, r2, #1 c0d00ae0: 2220 movs r2, #32 c0d00ae2: f000 f8e8 bl c0d00cb6 <os_memmove> c0d00ae6: af0f add r7, sp, #60 ; 0x3c c0d00ae8: 2221 movs r2, #33 ; 0x21 unsigned char verification_script[35]; verification_script[0] = 0x21; c0d00aea: 703a strb r2, [r7, #0] os_memmove(verification_script + 1, public_key_encoded, sizeof(public_key_encoded)); c0d00aec: 1c78 adds r0, r7, #1 c0d00aee: 4621 mov r1, r4 c0d00af0: f000 f8e1 bl c0d00cb6 <os_memmove> verification_script[sizeof(verification_script) - 1] = 0xAC; c0d00af4: 2022 movs r0, #34 ; 0x22 c0d00af6: 21ac movs r1, #172 ; 0xac c0d00af8: 5439 strb r1, [r7, r0] c0d00afa: ac0a add r4, sp, #40 ; 0x28 unsigned char script_hash[SCRIPT_HASH_LEN]; for (int i = 0; i < SCRIPT_HASH_LEN; i++) { script_hash[i] = 0x00; c0d00afc: 2114 movs r1, #20 c0d00afe: 4620 mov r0, r4 c0d00b00: f003 fb4e bl c0d041a0 <__aeabi_memclr> } public_key_hash160(verification_script, sizeof(verification_script), script_hash); c0d00b04: 2123 movs r1, #35 ; 0x23 c0d00b06: 4638 mov r0, r7 c0d00b08: 4622 mov r2, r4 c0d00b0a: f7ff ffa1 bl c0d00a50 <public_key_hash160> c0d00b0e: af01 add r7, sp, #4 unsigned int address_base58_len_1 = 11; unsigned int address_base58_len_2 = 12; char *address_base58_0 = address_base58; char *address_base58_1 = address_base58 + address_base58_len_0; char *address_base58_2 = address_base58 + address_base58_len_0 + address_base58_len_1; to_address(address_base58, ADDRESS_BASE58_LEN, script_hash); c0d00b10: 4638 mov r0, r7 c0d00b12: 4621 mov r1, r4 c0d00b14: f7ff fef6 bl c0d00904 <to_address> c0d00b18: 240b movs r4, #11 os_memmove(current_public_key[0], address_base58_0, address_base58_len_0); c0d00b1a: 4809 ldr r0, [pc, #36] ; (c0d00b40 <display_public_key+0xa8>) c0d00b1c: 4639 mov r1, r7 c0d00b1e: 4622 mov r2, r4 c0d00b20: f000 f8c9 bl c0d00cb6 <os_memmove> char address_base58[ADDRESS_BASE58_LEN]; unsigned int address_base58_len_0 = 11; unsigned int address_base58_len_1 = 11; unsigned int address_base58_len_2 = 12; char *address_base58_0 = address_base58; char *address_base58_1 = address_base58 + address_base58_len_0; c0d00b24: 4639 mov r1, r7 c0d00b26: 310b adds r1, #11 char *address_base58_2 = address_base58 + address_base58_len_0 + address_base58_len_1; to_address(address_base58, ADDRESS_BASE58_LEN, script_hash); os_memmove(current_public_key[0], address_base58_0, address_base58_len_0); os_memmove(current_public_key[1], address_base58_1, address_base58_len_1); c0d00b28: 4630 mov r0, r6 c0d00b2a: 4622 mov r2, r4 c0d00b2c: f000 f8c3 bl c0d00cb6 <os_memmove> unsigned int address_base58_len_0 = 11; unsigned int address_base58_len_1 = 11; unsigned int address_base58_len_2 = 12; char *address_base58_0 = address_base58; char *address_base58_1 = address_base58 + address_base58_len_0; char *address_base58_2 = address_base58 + address_base58_len_0 + address_base58_len_1; c0d00b30: 3716 adds r7, #22 to_address(address_base58, ADDRESS_BASE58_LEN, script_hash); os_memmove(current_public_key[0], address_base58_0, address_base58_len_0); os_memmove(current_public_key[1], address_base58_1, address_base58_len_1); os_memmove(current_public_key[2], address_base58_2, address_base58_len_2); c0d00b32: 220c movs r2, #12 c0d00b34: 4628 mov r0, r5 c0d00b36: 4639 mov r1, r7 c0d00b38: f000 f8bd bl c0d00cb6 <os_memmove> } c0d00b3c: b021 add sp, #132 ; 0x84 c0d00b3e: bdf0 pop {r4, r5, r6, r7, pc} c0d00b40: 20001c4c .word 0x20001c4c c0d00b44: 000038c2 .word 0x000038c2 c0d00b48 <os_boot>: // ^ platform register return (try_context_t*) current_ctx->jmp_buf[5]; } void try_context_set(try_context_t* ctx) { __asm volatile ("mov r9, %0"::"r"(ctx)); c0d00b48: 2000 movs r0, #0 c0d00b4a: 4681 mov r9, r0 void os_boot(void) { // TODO patch entry point when romming (f) // set the default try context to nothing try_context_set(NULL); } c0d00b4c: 4770 bx lr c0d00b4e <try_context_set>: // ^ platform register return (try_context_t*) current_ctx->jmp_buf[5]; } void try_context_set(try_context_t* ctx) { __asm volatile ("mov r9, %0"::"r"(ctx)); c0d00b4e: 4681 mov r9, r0 } c0d00b50: 4770 bx lr ... c0d00b54 <io_usb_hid_receive>: volatile unsigned int G_io_usb_hid_channel; volatile unsigned int G_io_usb_hid_remaining_length; volatile unsigned int G_io_usb_hid_sequence_number; volatile unsigned char* G_io_usb_hid_current_buffer; io_usb_hid_receive_status_t io_usb_hid_receive (io_send_t sndfct, unsigned char* buffer, unsigned short l) { c0d00b54: b5f0 push {r4, r5, r6, r7, lr} c0d00b56: b081 sub sp, #4 c0d00b58: 9200 str r2, [sp, #0] c0d00b5a: 460f mov r7, r1 c0d00b5c: 4605 mov r5, r0 // avoid over/under flows if (buffer != G_io_usb_ep_buffer) { c0d00b5e: 4b48 ldr r3, [pc, #288] ; (c0d00c80 <io_usb_hid_receive+0x12c>) c0d00b60: 429f cmp r7, r3 c0d00b62: d00f beq.n c0d00b84 <io_usb_hid_receive+0x30> } void os_memset(void * dst, unsigned char c, unsigned int length) { #define DSTCHAR ((unsigned char *)dst) while(length--) { DSTCHAR[length] = c; c0d00b64: 4c46 ldr r4, [pc, #280] ; (c0d00c80 <io_usb_hid_receive+0x12c>) c0d00b66: 2640 movs r6, #64 ; 0x40 c0d00b68: 4620 mov r0, r4 c0d00b6a: 4631 mov r1, r6 c0d00b6c: f003 fb18 bl c0d041a0 <__aeabi_memclr> c0d00b70: 9800 ldr r0, [sp, #0] io_usb_hid_receive_status_t io_usb_hid_receive (io_send_t sndfct, unsigned char* buffer, unsigned short l) { // avoid over/under flows if (buffer != G_io_usb_ep_buffer) { os_memset(G_io_usb_ep_buffer, 0, sizeof(G_io_usb_ep_buffer)); os_memmove(G_io_usb_ep_buffer, buffer, MIN(l, sizeof(G_io_usb_ep_buffer))); c0d00b72: 2840 cmp r0, #64 ; 0x40 c0d00b74: 4602 mov r2, r0 c0d00b76: d300 bcc.n c0d00b7a <io_usb_hid_receive+0x26> c0d00b78: 4632 mov r2, r6 c0d00b7a: 4620 mov r0, r4 c0d00b7c: 4639 mov r1, r7 c0d00b7e: f000 f89a bl c0d00cb6 <os_memmove> c0d00b82: 4b3f ldr r3, [pc, #252] ; (c0d00c80 <io_usb_hid_receive+0x12c>) c0d00b84: 7898 ldrb r0, [r3, #2] } // process the chunk content switch(G_io_usb_ep_buffer[2]) { c0d00b86: 2801 cmp r0, #1 c0d00b88: dc0b bgt.n c0d00ba2 <io_usb_hid_receive+0x4e> c0d00b8a: 2800 cmp r0, #0 c0d00b8c: d02b beq.n c0d00be6 <io_usb_hid_receive+0x92> c0d00b8e: 2801 cmp r0, #1 c0d00b90: d169 bne.n c0d00c66 <io_usb_hid_receive+0x112> // await for the next chunk goto apdu_reset; case 0x01: // ALLOCATE CHANNEL // do not reset the current apdu reception if any cx_rng(G_io_usb_ep_buffer+3, 4); c0d00b92: 1cd8 adds r0, r3, #3 c0d00b94: 2104 movs r1, #4 c0d00b96: 461c mov r4, r3 c0d00b98: f001 f9ca bl c0d01f30 <cx_rng> // send the response sndfct(G_io_usb_ep_buffer, IO_HID_EP_LENGTH); c0d00b9c: 2140 movs r1, #64 ; 0x40 c0d00b9e: 4620 mov r0, r4 c0d00ba0: e02c b.n c0d00bfc <io_usb_hid_receive+0xa8> c0d00ba2: 2802 cmp r0, #2 c0d00ba4: d028 beq.n c0d00bf8 <io_usb_hid_receive+0xa4> c0d00ba6: 2805 cmp r0, #5 c0d00ba8: d15d bne.n c0d00c66 <io_usb_hid_receive+0x112> // process the chunk content switch(G_io_usb_ep_buffer[2]) { case 0x05: // ensure sequence idx is 0 for the first chunk ! if ((unsigned int)U2BE(G_io_usb_ep_buffer, 3) != (unsigned int)G_io_usb_hid_sequence_number) { c0d00baa: 7918 ldrb r0, [r3, #4] c0d00bac: 78d9 ldrb r1, [r3, #3] c0d00bae: 0209 lsls r1, r1, #8 c0d00bb0: 4301 orrs r1, r0 c0d00bb2: 4a34 ldr r2, [pc, #208] ; (c0d00c84 <io_usb_hid_receive+0x130>) c0d00bb4: 6810 ldr r0, [r2, #0] c0d00bb6: 2400 movs r4, #0 c0d00bb8: 4281 cmp r1, r0 c0d00bba: d15a bne.n c0d00c72 <io_usb_hid_receive+0x11e> c0d00bbc: 4e32 ldr r6, [pc, #200] ; (c0d00c88 <io_usb_hid_receive+0x134>) // ignore packet goto apdu_reset; } // cid, tag, seq l -= 2+1+2; c0d00bbe: 9800 ldr r0, [sp, #0] c0d00bc0: 1980 adds r0, r0, r6 c0d00bc2: 1f07 subs r7, r0, #4 // append the received chunk to the current command apdu if (G_io_usb_hid_sequence_number == 0) { c0d00bc4: 6810 ldr r0, [r2, #0] c0d00bc6: 2800 cmp r0, #0 c0d00bc8: d01b beq.n c0d00c02 <io_usb_hid_receive+0xae> c0d00bca: 4614 mov r4, r2 // copy data os_memmove((void*)G_io_usb_hid_current_buffer, G_io_usb_ep_buffer+7, l); } else { // check for invalid length encoding (more data in chunk that announced in the total apdu) if (l > G_io_usb_hid_remaining_length) { c0d00bcc: 4639 mov r1, r7 c0d00bce: 4031 ands r1, r6 c0d00bd0: 482e ldr r0, [pc, #184] ; (c0d00c8c <io_usb_hid_receive+0x138>) c0d00bd2: 6802 ldr r2, [r0, #0] c0d00bd4: 4291 cmp r1, r2 c0d00bd6: d900 bls.n c0d00bda <io_usb_hid_receive+0x86> l = G_io_usb_hid_remaining_length; c0d00bd8: 6807 ldr r7, [r0, #0] } /// This is a following chunk // append content os_memmove((void*)G_io_usb_hid_current_buffer, G_io_usb_ep_buffer+5, l); c0d00bda: 463a mov r2, r7 c0d00bdc: 4032 ands r2, r6 c0d00bde: 482c ldr r0, [pc, #176] ; (c0d00c90 <io_usb_hid_receive+0x13c>) c0d00be0: 6800 ldr r0, [r0, #0] c0d00be2: 1d59 adds r1, r3, #5 c0d00be4: e031 b.n c0d00c4a <io_usb_hid_receive+0xf6> c0d00be6: 2400 movs r4, #0 } void os_memset(void * dst, unsigned char c, unsigned int length) { #define DSTCHAR ((unsigned char *)dst) while(length--) { DSTCHAR[length] = c; c0d00be8: 719c strb r4, [r3, #6] c0d00bea: 715c strb r4, [r3, #5] c0d00bec: 711c strb r4, [r3, #4] c0d00bee: 70dc strb r4, [r3, #3] case 0x00: // get version ID // do not reset the current apdu reception if any os_memset(G_io_usb_ep_buffer+3, 0, 4); // PROTOCOL VERSION is 0 // send the response sndfct(G_io_usb_ep_buffer, IO_HID_EP_LENGTH); c0d00bf0: 2140 movs r1, #64 ; 0x40 c0d00bf2: 4618 mov r0, r3 c0d00bf4: 47a8 blx r5 c0d00bf6: e03c b.n c0d00c72 <io_usb_hid_receive+0x11e> goto apdu_reset; case 0x02: // ECHO|PING // do not reset the current apdu reception if any // send the response sndfct(G_io_usb_ep_buffer, IO_HID_EP_LENGTH); c0d00bf8: 4821 ldr r0, [pc, #132] ; (c0d00c80 <io_usb_hid_receive+0x12c>) c0d00bfa: 2140 movs r1, #64 ; 0x40 c0d00bfc: 47a8 blx r5 c0d00bfe: 2400 movs r4, #0 c0d00c00: e037 b.n c0d00c72 <io_usb_hid_receive+0x11e> // append the received chunk to the current command apdu if (G_io_usb_hid_sequence_number == 0) { /// This is the apdu first chunk // total apdu size to receive G_io_usb_hid_total_length = U2BE(G_io_usb_ep_buffer, 5); //(G_io_usb_ep_buffer[5]<<8)+(G_io_usb_ep_buffer[6]&0xFF); c0d00c02: 7998 ldrb r0, [r3, #6] c0d00c04: 7959 ldrb r1, [r3, #5] c0d00c06: 0209 lsls r1, r1, #8 c0d00c08: 4301 orrs r1, r0 c0d00c0a: 4822 ldr r0, [pc, #136] ; (c0d00c94 <io_usb_hid_receive+0x140>) c0d00c0c: 6001 str r1, [r0, #0] // check for invalid length encoding (more data in chunk that announced in the total apdu) if (G_io_usb_hid_total_length > sizeof(G_io_apdu_buffer)) { c0d00c0e: 6801 ldr r1, [r0, #0] c0d00c10: 0849 lsrs r1, r1, #1 c0d00c12: 29a8 cmp r1, #168 ; 0xa8 c0d00c14: d82d bhi.n c0d00c72 <io_usb_hid_receive+0x11e> c0d00c16: 4614 mov r4, r2 goto apdu_reset; } // seq and total length l -= 2; // compute remaining size to receive G_io_usb_hid_remaining_length = G_io_usb_hid_total_length; c0d00c18: 6801 ldr r1, [r0, #0] c0d00c1a: 481c ldr r0, [pc, #112] ; (c0d00c8c <io_usb_hid_receive+0x138>) c0d00c1c: 6001 str r1, [r0, #0] G_io_usb_hid_current_buffer = G_io_apdu_buffer; c0d00c1e: 491c ldr r1, [pc, #112] ; (c0d00c90 <io_usb_hid_receive+0x13c>) c0d00c20: 4a1d ldr r2, [pc, #116] ; (c0d00c98 <io_usb_hid_receive+0x144>) c0d00c22: 600a str r2, [r1, #0] // retain the channel id to use for the reply G_io_usb_hid_channel = U2BE(G_io_usb_ep_buffer, 0); c0d00c24: 7859 ldrb r1, [r3, #1] c0d00c26: 781a ldrb r2, [r3, #0] c0d00c28: 0212 lsls r2, r2, #8 c0d00c2a: 430a orrs r2, r1 c0d00c2c: 491b ldr r1, [pc, #108] ; (c0d00c9c <io_usb_hid_receive+0x148>) c0d00c2e: 600a str r2, [r1, #0] // check for invalid length encoding (more data in chunk that announced in the total apdu) if (G_io_usb_hid_total_length > sizeof(G_io_apdu_buffer)) { goto apdu_reset; } // seq and total length l -= 2; c0d00c30: 491b ldr r1, [pc, #108] ; (c0d00ca0 <io_usb_hid_receive+0x14c>) c0d00c32: 9a00 ldr r2, [sp, #0] c0d00c34: 1857 adds r7, r2, r1 G_io_usb_hid_current_buffer = G_io_apdu_buffer; // retain the channel id to use for the reply G_io_usb_hid_channel = U2BE(G_io_usb_ep_buffer, 0); if (l > G_io_usb_hid_remaining_length) { c0d00c36: 4639 mov r1, r7 c0d00c38: 4031 ands r1, r6 c0d00c3a: 6802 ldr r2, [r0, #0] c0d00c3c: 4291 cmp r1, r2 c0d00c3e: d900 bls.n c0d00c42 <io_usb_hid_receive+0xee> l = G_io_usb_hid_remaining_length; c0d00c40: 6807 ldr r7, [r0, #0] } // copy data os_memmove((void*)G_io_usb_hid_current_buffer, G_io_usb_ep_buffer+7, l); c0d00c42: 463a mov r2, r7 c0d00c44: 4032 ands r2, r6 c0d00c46: 1dd9 adds r1, r3, #7 c0d00c48: 4813 ldr r0, [pc, #76] ; (c0d00c98 <io_usb_hid_receive+0x144>) c0d00c4a: f000 f834 bl c0d00cb6 <os_memmove> /// This is a following chunk // append content os_memmove((void*)G_io_usb_hid_current_buffer, G_io_usb_ep_buffer+5, l); } // factorize (f) G_io_usb_hid_current_buffer += l; c0d00c4e: 4037 ands r7, r6 c0d00c50: 480f ldr r0, [pc, #60] ; (c0d00c90 <io_usb_hid_receive+0x13c>) c0d00c52: 6801 ldr r1, [r0, #0] c0d00c54: 19c9 adds r1, r1, r7 c0d00c56: 6001 str r1, [r0, #0] G_io_usb_hid_remaining_length -= l; c0d00c58: 480c ldr r0, [pc, #48] ; (c0d00c8c <io_usb_hid_receive+0x138>) c0d00c5a: 6801 ldr r1, [r0, #0] c0d00c5c: 1bc9 subs r1, r1, r7 c0d00c5e: 6001 str r1, [r0, #0] G_io_usb_hid_sequence_number++; c0d00c60: 6820 ldr r0, [r4, #0] c0d00c62: 1c40 adds r0, r0, #1 c0d00c64: 6020 str r0, [r4, #0] // await for the next chunk goto apdu_reset; } // if more data to be received, notify it if (G_io_usb_hid_remaining_length) { c0d00c66: 4809 ldr r0, [pc, #36] ; (c0d00c8c <io_usb_hid_receive+0x138>) c0d00c68: 6801 ldr r1, [r0, #0] c0d00c6a: 2001 movs r0, #1 c0d00c6c: 2402 movs r4, #2 c0d00c6e: 2900 cmp r1, #0 c0d00c70: d103 bne.n c0d00c7a <io_usb_hid_receive+0x126> io_usb_hid_init(); return IO_USB_APDU_RESET; } void io_usb_hid_init(void) { G_io_usb_hid_sequence_number = 0; c0d00c72: 4804 ldr r0, [pc, #16] ; (c0d00c84 <io_usb_hid_receive+0x130>) c0d00c74: 2100 movs r1, #0 c0d00c76: 6001 str r1, [r0, #0] c0d00c78: 4620 mov r0, r4 return IO_USB_APDU_RECEIVED; apdu_reset: io_usb_hid_init(); return IO_USB_APDU_RESET; } c0d00c7a: b2c0 uxtb r0, r0 c0d00c7c: b001 add sp, #4 c0d00c7e: bdf0 pop {r4, r5, r6, r7, pc} c0d00c80: 20001ac0 .word 0x20001ac0 c0d00c84: 200018ec .word 0x200018ec c0d00c88: 0000ffff .word 0x0000ffff c0d00c8c: 200018f4 .word 0x200018f4 c0d00c90: 20001a4c .word 0x20001a4c c0d00c94: 200018f0 .word 0x200018f0 c0d00c98: 200018f8 .word 0x200018f8 c0d00c9c: 20001a50 .word 0x20001a50 c0d00ca0: 0001fff9 .word 0x0001fff9 c0d00ca4 <os_memset>: } } #undef DSTCHAR } void os_memset(void * dst, unsigned char c, unsigned int length) { c0d00ca4: b580 push {r7, lr} c0d00ca6: 460b mov r3, r1 #define DSTCHAR ((unsigned char *)dst) while(length--) { c0d00ca8: 2a00 cmp r2, #0 c0d00caa: d003 beq.n c0d00cb4 <os_memset+0x10> DSTCHAR[length] = c; c0d00cac: 4611 mov r1, r2 c0d00cae: 461a mov r2, r3 c0d00cb0: f003 fa80 bl c0d041b4 <__aeabi_memset> } #undef DSTCHAR } c0d00cb4: bd80 pop {r7, pc} c0d00cb6 <os_memmove>: } } #endif // HAVE_USB_APDU REENTRANT(void os_memmove(void * dst, const void WIDE * src, unsigned int length)) { c0d00cb6: b5b0 push {r4, r5, r7, lr} #define DSTCHAR ((unsigned char *)dst) #define SRCCHAR ((unsigned char WIDE *)src) if (dst > src) { c0d00cb8: 4288 cmp r0, r1 c0d00cba: d90d bls.n c0d00cd8 <os_memmove+0x22> while(length--) { c0d00cbc: 2a00 cmp r2, #0 c0d00cbe: d014 beq.n c0d00cea <os_memmove+0x34> c0d00cc0: 1e49 subs r1, r1, #1 c0d00cc2: 4252 negs r2, r2 c0d00cc4: 1e40 subs r0, r0, #1 c0d00cc6: 2300 movs r3, #0 c0d00cc8: 43db mvns r3, r3 DSTCHAR[length] = SRCCHAR[length]; c0d00cca: 461c mov r4, r3 c0d00ccc: 4354 muls r4, r2 c0d00cce: 5d0d ldrb r5, [r1, r4] c0d00cd0: 5505 strb r5, [r0, r4] REENTRANT(void os_memmove(void * dst, const void WIDE * src, unsigned int length)) { #define DSTCHAR ((unsigned char *)dst) #define SRCCHAR ((unsigned char WIDE *)src) if (dst > src) { while(length--) { c0d00cd2: 1c52 adds r2, r2, #1 c0d00cd4: d1f9 bne.n c0d00cca <os_memmove+0x14> c0d00cd6: e008 b.n c0d00cea <os_memmove+0x34> DSTCHAR[length] = SRCCHAR[length]; } } else { unsigned short l = 0; while (length--) { c0d00cd8: 2a00 cmp r2, #0 c0d00cda: d006 beq.n c0d00cea <os_memmove+0x34> c0d00cdc: 2300 movs r3, #0 DSTCHAR[l] = SRCCHAR[l]; c0d00cde: b29c uxth r4, r3 c0d00ce0: 5d0d ldrb r5, [r1, r4] c0d00ce2: 5505 strb r5, [r0, r4] l++; c0d00ce4: 1c5b adds r3, r3, #1 DSTCHAR[length] = SRCCHAR[length]; } } else { unsigned short l = 0; while (length--) { c0d00ce6: 1e52 subs r2, r2, #1 c0d00ce8: d1f9 bne.n c0d00cde <os_memmove+0x28> DSTCHAR[l] = SRCCHAR[l]; l++; } } #undef DSTCHAR } c0d00cea: bdb0 pop {r4, r5, r7, pc} c0d00cec <io_usb_hid_init>: io_usb_hid_init(); return IO_USB_APDU_RESET; } void io_usb_hid_init(void) { G_io_usb_hid_sequence_number = 0; c0d00cec: 4801 ldr r0, [pc, #4] ; (c0d00cf4 <io_usb_hid_init+0x8>) c0d00cee: 2100 movs r1, #0 c0d00cf0: 6001 str r1, [r0, #0] //G_io_usb_hid_remaining_length = 0; // not really needed //G_io_usb_hid_total_length = 0; // not really needed //G_io_usb_hid_current_buffer = G_io_apdu_buffer; // not really needed } c0d00cf2: 4770 bx lr c0d00cf4: 200018ec .word 0x200018ec c0d00cf8 <io_usb_hid_sent>: /** * sent the next io_usb_hid transport chunk (rx on the host, tx on the device) */ void io_usb_hid_sent(io_send_t sndfct) { c0d00cf8: b5f0 push {r4, r5, r6, r7, lr} c0d00cfa: b081 sub sp, #4 unsigned int l; // only prepare next chunk if some data to be sent remain if (G_io_usb_hid_remaining_length) { c0d00cfc: 4f29 ldr r7, [pc, #164] ; (c0d00da4 <io_usb_hid_sent+0xac>) c0d00cfe: 6839 ldr r1, [r7, #0] c0d00d00: 2900 cmp r1, #0 c0d00d02: d026 beq.n c0d00d52 <io_usb_hid_sent+0x5a> c0d00d04: 9000 str r0, [sp, #0] } void os_memset(void * dst, unsigned char c, unsigned int length) { #define DSTCHAR ((unsigned char *)dst) while(length--) { DSTCHAR[length] = c; c0d00d06: 4c28 ldr r4, [pc, #160] ; (c0d00da8 <io_usb_hid_sent+0xb0>) c0d00d08: 1d66 adds r6, r4, #5 c0d00d0a: 2539 movs r5, #57 ; 0x39 c0d00d0c: 4630 mov r0, r6 c0d00d0e: 4629 mov r1, r5 c0d00d10: f003 fa46 bl c0d041a0 <__aeabi_memclr> if (G_io_usb_hid_remaining_length) { // fill the chunk os_memset(G_io_usb_ep_buffer, 0, IO_HID_EP_LENGTH-2); // keep the channel identifier G_io_usb_ep_buffer[0] = (G_io_usb_hid_channel>>8)&0xFF; c0d00d14: 4825 ldr r0, [pc, #148] ; (c0d00dac <io_usb_hid_sent+0xb4>) c0d00d16: 6801 ldr r1, [r0, #0] c0d00d18: 0a09 lsrs r1, r1, #8 c0d00d1a: 7021 strb r1, [r4, #0] G_io_usb_ep_buffer[1] = G_io_usb_hid_channel&0xFF; c0d00d1c: 6800 ldr r0, [r0, #0] c0d00d1e: 7060 strb r0, [r4, #1] c0d00d20: 2005 movs r0, #5 G_io_usb_ep_buffer[2] = 0x05; c0d00d22: 70a0 strb r0, [r4, #2] G_io_usb_ep_buffer[3] = G_io_usb_hid_sequence_number>>8; c0d00d24: 4a22 ldr r2, [pc, #136] ; (c0d00db0 <io_usb_hid_sent+0xb8>) c0d00d26: 6810 ldr r0, [r2, #0] c0d00d28: 0a00 lsrs r0, r0, #8 c0d00d2a: 70e0 strb r0, [r4, #3] G_io_usb_ep_buffer[4] = G_io_usb_hid_sequence_number; c0d00d2c: 6810 ldr r0, [r2, #0] c0d00d2e: 7120 strb r0, [r4, #4] if (G_io_usb_hid_sequence_number == 0) { c0d00d30: 6811 ldr r1, [r2, #0] c0d00d32: 6838 ldr r0, [r7, #0] c0d00d34: 2900 cmp r1, #0 c0d00d36: d014 beq.n c0d00d62 <io_usb_hid_sent+0x6a> c0d00d38: 4614 mov r4, r2 c0d00d3a: 253b movs r5, #59 ; 0x3b G_io_usb_hid_current_buffer += l; G_io_usb_hid_remaining_length -= l; l += 7; } else { l = ((G_io_usb_hid_remaining_length>IO_HID_EP_LENGTH-5) ? IO_HID_EP_LENGTH-5 : G_io_usb_hid_remaining_length); c0d00d3c: 283b cmp r0, #59 ; 0x3b c0d00d3e: d800 bhi.n c0d00d42 <io_usb_hid_sent+0x4a> c0d00d40: 683d ldr r5, [r7, #0] os_memmove(G_io_usb_ep_buffer+5, (const void*)G_io_usb_hid_current_buffer, l); c0d00d42: 481c ldr r0, [pc, #112] ; (c0d00db4 <io_usb_hid_sent+0xbc>) c0d00d44: 6801 ldr r1, [r0, #0] c0d00d46: 4630 mov r0, r6 c0d00d48: 462a mov r2, r5 c0d00d4a: f7ff ffb4 bl c0d00cb6 <os_memmove> c0d00d4e: 9a00 ldr r2, [sp, #0] c0d00d50: e018 b.n c0d00d84 <io_usb_hid_sent+0x8c> // always pad :) sndfct(G_io_usb_ep_buffer, sizeof(G_io_usb_ep_buffer)); } // cleanup when everything has been sent (ack for the last sent usb in packet) else { G_io_usb_hid_sequence_number = 0; c0d00d52: 4817 ldr r0, [pc, #92] ; (c0d00db0 <io_usb_hid_sent+0xb8>) c0d00d54: 2100 movs r1, #0 c0d00d56: 6001 str r1, [r0, #0] G_io_usb_hid_current_buffer = NULL; c0d00d58: 4816 ldr r0, [pc, #88] ; (c0d00db4 <io_usb_hid_sent+0xbc>) c0d00d5a: 6001 str r1, [r0, #0] // we sent the whole response G_io_apdu_state = APDU_IDLE; c0d00d5c: 4816 ldr r0, [pc, #88] ; (c0d00db8 <io_usb_hid_sent+0xc0>) c0d00d5e: 7001 strb r1, [r0, #0] c0d00d60: e01d b.n c0d00d9e <io_usb_hid_sent+0xa6> c0d00d62: 4616 mov r6, r2 G_io_usb_ep_buffer[2] = 0x05; G_io_usb_ep_buffer[3] = G_io_usb_hid_sequence_number>>8; G_io_usb_ep_buffer[4] = G_io_usb_hid_sequence_number; if (G_io_usb_hid_sequence_number == 0) { l = ((G_io_usb_hid_remaining_length>IO_HID_EP_LENGTH-7) ? IO_HID_EP_LENGTH-7 : G_io_usb_hid_remaining_length); c0d00d64: 2839 cmp r0, #57 ; 0x39 c0d00d66: d800 bhi.n c0d00d6a <io_usb_hid_sent+0x72> c0d00d68: 683d ldr r5, [r7, #0] G_io_usb_ep_buffer[5] = G_io_usb_hid_remaining_length>>8; c0d00d6a: 6838 ldr r0, [r7, #0] c0d00d6c: 0a00 lsrs r0, r0, #8 c0d00d6e: 7160 strb r0, [r4, #5] G_io_usb_ep_buffer[6] = G_io_usb_hid_remaining_length; c0d00d70: 6838 ldr r0, [r7, #0] c0d00d72: 71a0 strb r0, [r4, #6] os_memmove(G_io_usb_ep_buffer+7, (const void*)G_io_usb_hid_current_buffer, l); c0d00d74: 480f ldr r0, [pc, #60] ; (c0d00db4 <io_usb_hid_sent+0xbc>) c0d00d76: 6801 ldr r1, [r0, #0] c0d00d78: 1de0 adds r0, r4, #7 c0d00d7a: 462a mov r2, r5 c0d00d7c: f7ff ff9b bl c0d00cb6 <os_memmove> c0d00d80: 9a00 ldr r2, [sp, #0] c0d00d82: 4634 mov r4, r6 c0d00d84: 480b ldr r0, [pc, #44] ; (c0d00db4 <io_usb_hid_sent+0xbc>) c0d00d86: 6801 ldr r1, [r0, #0] c0d00d88: 1949 adds r1, r1, r5 c0d00d8a: 6001 str r1, [r0, #0] c0d00d8c: 6838 ldr r0, [r7, #0] c0d00d8e: 1b40 subs r0, r0, r5 c0d00d90: 6038 str r0, [r7, #0] G_io_usb_hid_current_buffer += l; G_io_usb_hid_remaining_length -= l; l += 5; } // prepare next chunk numbering G_io_usb_hid_sequence_number++; c0d00d92: 6820 ldr r0, [r4, #0] c0d00d94: 1c40 adds r0, r0, #1 c0d00d96: 6020 str r0, [r4, #0] // send the chunk // always pad :) sndfct(G_io_usb_ep_buffer, sizeof(G_io_usb_ep_buffer)); c0d00d98: 4803 ldr r0, [pc, #12] ; (c0d00da8 <io_usb_hid_sent+0xb0>) c0d00d9a: 2140 movs r1, #64 ; 0x40 c0d00d9c: 4790 blx r2 G_io_usb_hid_current_buffer = NULL; // we sent the whole response G_io_apdu_state = APDU_IDLE; } } c0d00d9e: b001 add sp, #4 c0d00da0: bdf0 pop {r4, r5, r6, r7, pc} c0d00da2: 46c0 nop ; (mov r8, r8) c0d00da4: 200018f4 .word 0x200018f4 c0d00da8: 20001ac0 .word 0x20001ac0 c0d00dac: 20001a50 .word 0x20001a50 c0d00db0: 200018ec .word 0x200018ec c0d00db4: 20001a4c .word 0x20001a4c c0d00db8: 20001a6a .word 0x20001a6a c0d00dbc <io_usb_hid_send>: void io_usb_hid_send(io_send_t sndfct, unsigned short sndlength) { c0d00dbc: b580 push {r7, lr} // perform send if (sndlength) { c0d00dbe: 2900 cmp r1, #0 c0d00dc0: d00b beq.n c0d00dda <io_usb_hid_send+0x1e> G_io_usb_hid_sequence_number = 0; c0d00dc2: 4a06 ldr r2, [pc, #24] ; (c0d00ddc <io_usb_hid_send+0x20>) c0d00dc4: 2300 movs r3, #0 c0d00dc6: 6013 str r3, [r2, #0] G_io_usb_hid_current_buffer = G_io_apdu_buffer; c0d00dc8: 4a05 ldr r2, [pc, #20] ; (c0d00de0 <io_usb_hid_send+0x24>) c0d00dca: 4b06 ldr r3, [pc, #24] ; (c0d00de4 <io_usb_hid_send+0x28>) c0d00dcc: 6013 str r3, [r2, #0] G_io_usb_hid_remaining_length = sndlength; c0d00dce: 4a06 ldr r2, [pc, #24] ; (c0d00de8 <io_usb_hid_send+0x2c>) c0d00dd0: 6011 str r1, [r2, #0] G_io_usb_hid_total_length = sndlength; c0d00dd2: 4a06 ldr r2, [pc, #24] ; (c0d00dec <io_usb_hid_send+0x30>) c0d00dd4: 6011 str r1, [r2, #0] io_usb_hid_sent(sndfct); c0d00dd6: f7ff ff8f bl c0d00cf8 <io_usb_hid_sent> } } c0d00dda: bd80 pop {r7, pc} c0d00ddc: 200018ec .word 0x200018ec c0d00de0: 20001a4c .word 0x20001a4c c0d00de4: 200018f8 .word 0x200018f8 c0d00de8: 200018f4 .word 0x200018f4 c0d00dec: 200018f0 .word 0x200018f0 c0d00df0 <os_memcmp>: DSTCHAR[length] = c; } #undef DSTCHAR } char os_memcmp(const void WIDE * buf1, const void WIDE * buf2, unsigned int length) { c0d00df0: b570 push {r4, r5, r6, lr} #define BUF1 ((unsigned char const WIDE *)buf1) #define BUF2 ((unsigned char const WIDE *)buf2) while(length--) { c0d00df2: 1e43 subs r3, r0, #1 c0d00df4: 1e49 subs r1, r1, #1 c0d00df6: 4252 negs r2, r2 c0d00df8: 2000 movs r0, #0 c0d00dfa: 43c4 mvns r4, r0 c0d00dfc: 2a00 cmp r2, #0 c0d00dfe: d00c beq.n c0d00e1a <os_memcmp+0x2a> if (BUF1[length] != BUF2[length]) { c0d00e00: 4626 mov r6, r4 c0d00e02: 4356 muls r6, r2 c0d00e04: 5d8d ldrb r5, [r1, r6] c0d00e06: 5d9e ldrb r6, [r3, r6] c0d00e08: 1c52 adds r2, r2, #1 c0d00e0a: 42ae cmp r6, r5 c0d00e0c: d0f6 beq.n c0d00dfc <os_memcmp+0xc> return (BUF1[length] > BUF2[length])? 1:-1; c0d00e0e: 2000 movs r0, #0 c0d00e10: 43c1 mvns r1, r0 c0d00e12: 2001 movs r0, #1 c0d00e14: 42ae cmp r6, r5 c0d00e16: d800 bhi.n c0d00e1a <os_memcmp+0x2a> c0d00e18: 4608 mov r0, r1 } return 0; #undef BUF1 #undef BUF2 } c0d00e1a: b2c0 uxtb r0, r0 c0d00e1c: bd70 pop {r4, r5, r6, pc} c0d00e1e <os_longjmp>: void try_context_set(try_context_t* ctx) { __asm volatile ("mov r9, %0"::"r"(ctx)); } #ifndef HAVE_BOLOS void os_longjmp(unsigned int exception) { c0d00e1e: b580 push {r7, lr} c0d00e20: 4601 mov r1, r0 return xoracc; } try_context_t* try_context_get(void) { try_context_t* current_ctx; __asm volatile ("mov %0, r9":"=r"(current_ctx)); c0d00e22: 4648 mov r0, r9 __asm volatile ("mov r9, %0"::"r"(ctx)); } #ifndef HAVE_BOLOS void os_longjmp(unsigned int exception) { longjmp(try_context_get()->jmp_buf, exception); c0d00e24: f003 fa5e bl c0d042e4 <longjmp> c0d00e28 <try_context_get>: return xoracc; } try_context_t* try_context_get(void) { try_context_t* current_ctx; __asm volatile ("mov %0, r9":"=r"(current_ctx)); c0d00e28: 4648 mov r0, r9 return current_ctx; c0d00e2a: 4770 bx lr c0d00e2c <try_context_get_previous>: } try_context_t* try_context_get_previous(void) { c0d00e2c: 2000 movs r0, #0 try_context_t* current_ctx; __asm volatile ("mov %0, r9":"=r"(current_ctx)); c0d00e2e: 4649 mov r1, r9 // first context reached ? if (current_ctx == NULL) { c0d00e30: 2900 cmp r1, #0 c0d00e32: d000 beq.n c0d00e36 <try_context_get_previous+0xa> } // return r9 content saved on the current context. It links to the previous context. // r4 r5 r6 r7 r8 r9 r10 r11 sp lr // ^ platform register return (try_context_t*) current_ctx->jmp_buf[5]; c0d00e34: 6948 ldr r0, [r1, #20] } c0d00e36: 4770 bx lr c0d00e38 <io_seproxyhal_general_status>: #ifndef IO_RAPDU_TRANSMIT_TIMEOUT_MS #define IO_RAPDU_TRANSMIT_TIMEOUT_MS 2000UL #endif // IO_RAPDU_TRANSMIT_TIMEOUT_MS void io_seproxyhal_general_status(void) { c0d00e38: b580 push {r7, lr} // avoid troubles if (io_seproxyhal_spi_is_status_sent()) { c0d00e3a: f001 f9e1 bl c0d02200 <io_seproxyhal_spi_is_status_sent> c0d00e3e: 2800 cmp r0, #0 c0d00e40: d10b bne.n c0d00e5a <io_seproxyhal_general_status+0x22> return; } // send the general status G_io_seproxyhal_spi_buffer[0] = SEPROXYHAL_TAG_GENERAL_STATUS; c0d00e42: 4806 ldr r0, [pc, #24] ; (c0d00e5c <io_seproxyhal_general_status+0x24>) c0d00e44: 2160 movs r1, #96 ; 0x60 c0d00e46: 7001 strb r1, [r0, #0] G_io_seproxyhal_spi_buffer[1] = 0; c0d00e48: 2100 movs r1, #0 c0d00e4a: 7041 strb r1, [r0, #1] G_io_seproxyhal_spi_buffer[2] = 2; c0d00e4c: 2202 movs r2, #2 c0d00e4e: 7082 strb r2, [r0, #2] G_io_seproxyhal_spi_buffer[3] = SEPROXYHAL_TAG_GENERAL_STATUS_LAST_COMMAND>>8; c0d00e50: 70c1 strb r1, [r0, #3] G_io_seproxyhal_spi_buffer[4] = SEPROXYHAL_TAG_GENERAL_STATUS_LAST_COMMAND; c0d00e52: 7101 strb r1, [r0, #4] io_seproxyhal_spi_send(G_io_seproxyhal_spi_buffer, 5); c0d00e54: 2105 movs r1, #5 c0d00e56: f001 f9bd bl c0d021d4 <io_seproxyhal_spi_send> } c0d00e5a: bd80 pop {r7, pc} c0d00e5c: 20001800 .word 0x20001800 c0d00e60 <io_seproxyhal_handle_usb_event>: } G_io_usb_ep_timeouts[IO_USB_MAX_ENDPOINTS]; #include "usbd_def.h" #include "usbd_core.h" extern USBD_HandleTypeDef USBD_Device; void io_seproxyhal_handle_usb_event(void) { c0d00e60: b510 push {r4, lr} switch(G_io_seproxyhal_spi_buffer[3]) { c0d00e62: 4819 ldr r0, [pc, #100] ; (c0d00ec8 <io_seproxyhal_handle_usb_event+0x68>) c0d00e64: 78c0 ldrb r0, [r0, #3] c0d00e66: 2803 cmp r0, #3 c0d00e68: dc07 bgt.n c0d00e7a <io_seproxyhal_handle_usb_event+0x1a> c0d00e6a: 2801 cmp r0, #1 c0d00e6c: d00d beq.n c0d00e8a <io_seproxyhal_handle_usb_event+0x2a> c0d00e6e: 2802 cmp r0, #2 c0d00e70: d126 bne.n c0d00ec0 <io_seproxyhal_handle_usb_event+0x60> } os_memset(G_io_usb_ep_xfer_len, 0, sizeof(G_io_usb_ep_xfer_len)); os_memset(G_io_usb_ep_timeouts, 0, sizeof(G_io_usb_ep_timeouts)); break; case SEPROXYHAL_TAG_USB_EVENT_SOF: USBD_LL_SOF(&USBD_Device); c0d00e72: 4816 ldr r0, [pc, #88] ; (c0d00ecc <io_seproxyhal_handle_usb_event+0x6c>) c0d00e74: f002 fbd1 bl c0d0361a <USBD_LL_SOF> break; case SEPROXYHAL_TAG_USB_EVENT_RESUMED: USBD_LL_Resume(&USBD_Device); break; } } c0d00e78: bd10 pop {r4, pc} c0d00e7a: 2804 cmp r0, #4 c0d00e7c: d01d beq.n c0d00eba <io_seproxyhal_handle_usb_event+0x5a> c0d00e7e: 2808 cmp r0, #8 c0d00e80: d11e bne.n c0d00ec0 <io_seproxyhal_handle_usb_event+0x60> break; case SEPROXYHAL_TAG_USB_EVENT_SUSPENDED: USBD_LL_Suspend(&USBD_Device); break; case SEPROXYHAL_TAG_USB_EVENT_RESUMED: USBD_LL_Resume(&USBD_Device); c0d00e82: 4812 ldr r0, [pc, #72] ; (c0d00ecc <io_seproxyhal_handle_usb_event+0x6c>) c0d00e84: f002 fbc7 bl c0d03616 <USBD_LL_Resume> break; } } c0d00e88: bd10 pop {r4, pc} extern USBD_HandleTypeDef USBD_Device; void io_seproxyhal_handle_usb_event(void) { switch(G_io_seproxyhal_spi_buffer[3]) { case SEPROXYHAL_TAG_USB_EVENT_RESET: USBD_LL_SetSpeed(&USBD_Device, USBD_SPEED_FULL); c0d00e8a: 4c10 ldr r4, [pc, #64] ; (c0d00ecc <io_seproxyhal_handle_usb_event+0x6c>) c0d00e8c: 2101 movs r1, #1 c0d00e8e: 4620 mov r0, r4 c0d00e90: f002 fbbc bl c0d0360c <USBD_LL_SetSpeed> USBD_LL_Reset(&USBD_Device); c0d00e94: 4620 mov r0, r4 c0d00e96: f002 fb98 bl c0d035ca <USBD_LL_Reset> // ongoing APDU detected, throw a reset, even if not the media. to avoid potential troubles. if (G_io_apdu_media != IO_APDU_MEDIA_NONE) { c0d00e9a: 480d ldr r0, [pc, #52] ; (c0d00ed0 <io_seproxyhal_handle_usb_event+0x70>) c0d00e9c: 7800 ldrb r0, [r0, #0] c0d00e9e: 2800 cmp r0, #0 c0d00ea0: d10f bne.n c0d00ec2 <io_seproxyhal_handle_usb_event+0x62> THROW(EXCEPTION_IO_RESET); } os_memset(G_io_usb_ep_xfer_len, 0, sizeof(G_io_usb_ep_xfer_len)); c0d00ea2: 480c ldr r0, [pc, #48] ; (c0d00ed4 <io_seproxyhal_handle_usb_event+0x74>) c0d00ea4: 2400 movs r4, #0 c0d00ea6: 2207 movs r2, #7 c0d00ea8: 4621 mov r1, r4 c0d00eaa: f7ff fefb bl c0d00ca4 <os_memset> os_memset(G_io_usb_ep_timeouts, 0, sizeof(G_io_usb_ep_timeouts)); c0d00eae: 480a ldr r0, [pc, #40] ; (c0d00ed8 <io_seproxyhal_handle_usb_event+0x78>) c0d00eb0: 220e movs r2, #14 c0d00eb2: 4621 mov r1, r4 c0d00eb4: f7ff fef6 bl c0d00ca4 <os_memset> break; case SEPROXYHAL_TAG_USB_EVENT_RESUMED: USBD_LL_Resume(&USBD_Device); break; } } c0d00eb8: bd10 pop {r4, pc} break; case SEPROXYHAL_TAG_USB_EVENT_SOF: USBD_LL_SOF(&USBD_Device); break; case SEPROXYHAL_TAG_USB_EVENT_SUSPENDED: USBD_LL_Suspend(&USBD_Device); c0d00eba: 4804 ldr r0, [pc, #16] ; (c0d00ecc <io_seproxyhal_handle_usb_event+0x6c>) c0d00ebc: f002 fba9 bl c0d03612 <USBD_LL_Suspend> break; case SEPROXYHAL_TAG_USB_EVENT_RESUMED: USBD_LL_Resume(&USBD_Device); break; } } c0d00ec0: bd10 pop {r4, pc} case SEPROXYHAL_TAG_USB_EVENT_RESET: USBD_LL_SetSpeed(&USBD_Device, USBD_SPEED_FULL); USBD_LL_Reset(&USBD_Device); // ongoing APDU detected, throw a reset, even if not the media. to avoid potential troubles. if (G_io_apdu_media != IO_APDU_MEDIA_NONE) { THROW(EXCEPTION_IO_RESET); c0d00ec2: 2010 movs r0, #16 c0d00ec4: f7ff ffab bl c0d00e1e <os_longjmp> c0d00ec8: 20001800 .word 0x20001800 c0d00ecc: 20001c8c .word 0x20001c8c c0d00ed0: 20001a54 .word 0x20001a54 c0d00ed4: 20001a55 .word 0x20001a55 c0d00ed8: 20001a5c .word 0x20001a5c c0d00edc <io_seproxyhal_get_ep_rx_size>: break; } } uint16_t io_seproxyhal_get_ep_rx_size(uint8_t epnum) { return G_io_usb_ep_xfer_len[epnum&0x7F]; c0d00edc: 217f movs r1, #127 ; 0x7f c0d00ede: 4001 ands r1, r0 c0d00ee0: 4801 ldr r0, [pc, #4] ; (c0d00ee8 <io_seproxyhal_get_ep_rx_size+0xc>) c0d00ee2: 5c40 ldrb r0, [r0, r1] c0d00ee4: 4770 bx lr c0d00ee6: 46c0 nop ; (mov r8, r8) c0d00ee8: 20001a55 .word 0x20001a55 c0d00eec <io_seproxyhal_handle_usb_ep_xfer_event>: } void io_seproxyhal_handle_usb_ep_xfer_event(void) { c0d00eec: b510 push {r4, lr} switch(G_io_seproxyhal_spi_buffer[4]) { c0d00eee: 4815 ldr r0, [pc, #84] ; (c0d00f44 <io_seproxyhal_handle_usb_ep_xfer_event+0x58>) c0d00ef0: 7901 ldrb r1, [r0, #4] c0d00ef2: 2904 cmp r1, #4 c0d00ef4: d017 beq.n c0d00f26 <io_seproxyhal_handle_usb_ep_xfer_event+0x3a> c0d00ef6: 2902 cmp r1, #2 c0d00ef8: d006 beq.n c0d00f08 <io_seproxyhal_handle_usb_ep_xfer_event+0x1c> c0d00efa: 2901 cmp r1, #1 c0d00efc: d120 bne.n c0d00f40 <io_seproxyhal_handle_usb_ep_xfer_event+0x54> /* This event is received when a new SETUP token had been received on a control endpoint */ case SEPROXYHAL_TAG_USB_EP_XFER_SETUP: // assume length of setup packet, and that it is on endpoint 0 USBD_LL_SetupStage(&USBD_Device, &G_io_seproxyhal_spi_buffer[6]); c0d00efe: 1d81 adds r1, r0, #6 c0d00f00: 4812 ldr r0, [pc, #72] ; (c0d00f4c <io_seproxyhal_handle_usb_ep_xfer_event+0x60>) c0d00f02: f002 fa5b bl c0d033bc <USBD_LL_SetupStage> // prepare reception USBD_LL_DataOutStage(&USBD_Device, G_io_seproxyhal_spi_buffer[3]&0x7F, &G_io_seproxyhal_spi_buffer[6]); } break; } } c0d00f06: bd10 pop {r4, pc} USBD_LL_SetupStage(&USBD_Device, &G_io_seproxyhal_spi_buffer[6]); break; /* This event is received after the prepare data packet has been flushed to the usb host */ case SEPROXYHAL_TAG_USB_EP_XFER_IN: if ((G_io_seproxyhal_spi_buffer[3]&0x7F) < IO_USB_MAX_ENDPOINTS) { c0d00f08: 78c2 ldrb r2, [r0, #3] c0d00f0a: 217f movs r1, #127 ; 0x7f c0d00f0c: 4011 ands r1, r2 c0d00f0e: 2906 cmp r1, #6 c0d00f10: d816 bhi.n c0d00f40 <io_seproxyhal_handle_usb_ep_xfer_event+0x54> c0d00f12: b2c9 uxtb r1, r1 // discard ep timeout as we received the sent packet confirmation G_io_usb_ep_timeouts[G_io_seproxyhal_spi_buffer[3]&0x7F].timeout = 0; c0d00f14: 004a lsls r2, r1, #1 c0d00f16: 4b0e ldr r3, [pc, #56] ; (c0d00f50 <io_seproxyhal_handle_usb_ep_xfer_event+0x64>) c0d00f18: 2400 movs r4, #0 c0d00f1a: 529c strh r4, [r3, r2] // propagate sending ack of the data USBD_LL_DataInStage(&USBD_Device, G_io_seproxyhal_spi_buffer[3]&0x7F, &G_io_seproxyhal_spi_buffer[6]); c0d00f1c: 1d82 adds r2, r0, #6 c0d00f1e: 480b ldr r0, [pc, #44] ; (c0d00f4c <io_seproxyhal_handle_usb_ep_xfer_event+0x60>) c0d00f20: f002 fada bl c0d034d8 <USBD_LL_DataInStage> // prepare reception USBD_LL_DataOutStage(&USBD_Device, G_io_seproxyhal_spi_buffer[3]&0x7F, &G_io_seproxyhal_spi_buffer[6]); } break; } } c0d00f24: bd10 pop {r4, pc} } break; /* This event is received when a new DATA token is received on an endpoint */ case SEPROXYHAL_TAG_USB_EP_XFER_OUT: if ((G_io_seproxyhal_spi_buffer[3]&0x7F) < IO_USB_MAX_ENDPOINTS) { c0d00f26: 78c2 ldrb r2, [r0, #3] c0d00f28: 217f movs r1, #127 ; 0x7f c0d00f2a: 4011 ands r1, r2 c0d00f2c: 2906 cmp r1, #6 c0d00f2e: d807 bhi.n c0d00f40 <io_seproxyhal_handle_usb_ep_xfer_event+0x54> // saved just in case it is needed ... G_io_usb_ep_xfer_len[G_io_seproxyhal_spi_buffer[3]&0x7F] = G_io_seproxyhal_spi_buffer[5]; c0d00f30: 7942 ldrb r2, [r0, #5] } break; /* This event is received when a new DATA token is received on an endpoint */ case SEPROXYHAL_TAG_USB_EP_XFER_OUT: if ((G_io_seproxyhal_spi_buffer[3]&0x7F) < IO_USB_MAX_ENDPOINTS) { c0d00f32: b2c9 uxtb r1, r1 // saved just in case it is needed ... G_io_usb_ep_xfer_len[G_io_seproxyhal_spi_buffer[3]&0x7F] = G_io_seproxyhal_spi_buffer[5]; c0d00f34: 4b04 ldr r3, [pc, #16] ; (c0d00f48 <io_seproxyhal_handle_usb_ep_xfer_event+0x5c>) c0d00f36: 545a strb r2, [r3, r1] // prepare reception USBD_LL_DataOutStage(&USBD_Device, G_io_seproxyhal_spi_buffer[3]&0x7F, &G_io_seproxyhal_spi_buffer[6]); c0d00f38: 1d82 adds r2, r0, #6 c0d00f3a: 4804 ldr r0, [pc, #16] ; (c0d00f4c <io_seproxyhal_handle_usb_ep_xfer_event+0x60>) c0d00f3c: f002 fa6d bl c0d0341a <USBD_LL_DataOutStage> } break; } } c0d00f40: bd10 pop {r4, pc} c0d00f42: 46c0 nop ; (mov r8, r8) c0d00f44: 20001800 .word 0x20001800 c0d00f48: 20001a55 .word 0x20001a55 c0d00f4c: 20001c8c .word 0x20001c8c c0d00f50: 20001a5c .word 0x20001a5c c0d00f54 <io_usb_send_ep>: #endif // HAVE_L4_USBLIB // TODO, refactor this using the USB DataIn event like for the U2F tunnel // TODO add a blocking parameter, for HID KBD sending, or use a USB busy flag per channel to know if // the transfer has been processed or not. and move on to the next transfer on the same endpoint void io_usb_send_ep(unsigned int ep, unsigned char* buffer, unsigned short length, unsigned int timeout) { c0d00f54: b570 push {r4, r5, r6, lr} c0d00f56: 4615 mov r5, r2 c0d00f58: 460e mov r6, r1 c0d00f5a: 4604 mov r4, r0 if (timeout) { timeout++; } // won't send if overflowing seproxyhal buffer format if (length > 255) { c0d00f5c: 2dff cmp r5, #255 ; 0xff c0d00f5e: d81a bhi.n c0d00f96 <io_usb_send_ep+0x42> return; } G_io_seproxyhal_spi_buffer[0] = SEPROXYHAL_TAG_USB_EP_PREPARE; c0d00f60: 480d ldr r0, [pc, #52] ; (c0d00f98 <io_usb_send_ep+0x44>) c0d00f62: 2150 movs r1, #80 ; 0x50 c0d00f64: 7001 strb r1, [r0, #0] G_io_seproxyhal_spi_buffer[1] = (3+length)>>8; c0d00f66: 1ce9 adds r1, r5, #3 c0d00f68: 0a0a lsrs r2, r1, #8 c0d00f6a: 7042 strb r2, [r0, #1] G_io_seproxyhal_spi_buffer[2] = (3+length); c0d00f6c: 7081 strb r1, [r0, #2] G_io_seproxyhal_spi_buffer[3] = ep|0x80; c0d00f6e: 2180 movs r1, #128 ; 0x80 c0d00f70: 4321 orrs r1, r4 c0d00f72: 70c1 strb r1, [r0, #3] G_io_seproxyhal_spi_buffer[4] = SEPROXYHAL_TAG_USB_EP_PREPARE_DIR_IN; c0d00f74: 2120 movs r1, #32 c0d00f76: 7101 strb r1, [r0, #4] G_io_seproxyhal_spi_buffer[5] = length; c0d00f78: 7145 strb r5, [r0, #5] io_seproxyhal_spi_send(G_io_seproxyhal_spi_buffer, 6); c0d00f7a: 2106 movs r1, #6 c0d00f7c: f001 f92a bl c0d021d4 <io_seproxyhal_spi_send> io_seproxyhal_spi_send(buffer, length); c0d00f80: 4630 mov r0, r6 c0d00f82: 4629 mov r1, r5 c0d00f84: f001 f926 bl c0d021d4 <io_seproxyhal_spi_send> // setup timeout of the endpoint G_io_usb_ep_timeouts[ep&0x7F].timeout = IO_RAPDU_TRANSMIT_TIMEOUT_MS; c0d00f88: 207f movs r0, #127 ; 0x7f c0d00f8a: 4020 ands r0, r4 c0d00f8c: 0040 lsls r0, r0, #1 c0d00f8e: 217d movs r1, #125 ; 0x7d c0d00f90: 0109 lsls r1, r1, #4 c0d00f92: 4a02 ldr r2, [pc, #8] ; (c0d00f9c <io_usb_send_ep+0x48>) c0d00f94: 5211 strh r1, [r2, r0] } c0d00f96: bd70 pop {r4, r5, r6, pc} c0d00f98: 20001800 .word 0x20001800 c0d00f9c: 20001a5c .word 0x20001a5c c0d00fa0 <io_usb_send_apdu_data>: void io_usb_send_apdu_data(unsigned char* buffer, unsigned short length) { c0d00fa0: b580 push {r7, lr} c0d00fa2: 460a mov r2, r1 c0d00fa4: 4601 mov r1, r0 // wait for 20 events before hanging up and timeout (~2 seconds of timeout) io_usb_send_ep(0x82, buffer, length, 20); c0d00fa6: 2082 movs r0, #130 ; 0x82 c0d00fa8: 2314 movs r3, #20 c0d00faa: f7ff ffd3 bl c0d00f54 <io_usb_send_ep> } c0d00fae: bd80 pop {r7, pc} c0d00fb0 <io_usb_send_apdu_data_ep0x83>: #ifdef HAVE_WEBUSB void io_usb_send_apdu_data_ep0x83(unsigned char* buffer, unsigned short length) { c0d00fb0: b580 push {r7, lr} c0d00fb2: 460a mov r2, r1 c0d00fb4: 4601 mov r1, r0 // wait for 20 events before hanging up and timeout (~2 seconds of timeout) io_usb_send_ep(0x83, buffer, length, 20); c0d00fb6: 2083 movs r0, #131 ; 0x83 c0d00fb8: 2314 movs r3, #20 c0d00fba: f7ff ffcb bl c0d00f54 <io_usb_send_ep> } c0d00fbe: bd80 pop {r7, pc} c0d00fc0 <io_seproxyhal_handle_capdu_event>: } #endif void io_seproxyhal_handle_capdu_event(void) { c0d00fc0: b580 push {r7, lr} if(G_io_apdu_state == APDU_IDLE) c0d00fc2: 480d ldr r0, [pc, #52] ; (c0d00ff8 <io_seproxyhal_handle_capdu_event+0x38>) c0d00fc4: 7801 ldrb r1, [r0, #0] c0d00fc6: 2900 cmp r1, #0 c0d00fc8: d115 bne.n c0d00ff6 <io_seproxyhal_handle_capdu_event+0x36> { G_io_apdu_media = IO_APDU_MEDIA_RAW; // for application code c0d00fca: 490c ldr r1, [pc, #48] ; (c0d00ffc <io_seproxyhal_handle_capdu_event+0x3c>) c0d00fcc: 2206 movs r2, #6 c0d00fce: 700a strb r2, [r1, #0] G_io_apdu_state = APDU_RAW; // for next call to io_exchange c0d00fd0: 210a movs r1, #10 c0d00fd2: 7001 strb r1, [r0, #0] G_io_apdu_length = MIN(U2BE(G_io_seproxyhal_spi_buffer, 1), sizeof(G_io_apdu_buffer)); c0d00fd4: 480a ldr r0, [pc, #40] ; (c0d01000 <io_seproxyhal_handle_capdu_event+0x40>) c0d00fd6: 7882 ldrb r2, [r0, #2] c0d00fd8: 7841 ldrb r1, [r0, #1] c0d00fda: 0209 lsls r1, r1, #8 c0d00fdc: 4311 orrs r1, r2 c0d00fde: 22ff movs r2, #255 ; 0xff c0d00fe0: 3252 adds r2, #82 ; 0x52 c0d00fe2: 4291 cmp r1, r2 c0d00fe4: d300 bcc.n c0d00fe8 <io_seproxyhal_handle_capdu_event+0x28> c0d00fe6: 4611 mov r1, r2 c0d00fe8: 4a06 ldr r2, [pc, #24] ; (c0d01004 <io_seproxyhal_handle_capdu_event+0x44>) c0d00fea: 8011 strh r1, [r2, #0] // copy apdu to apdu buffer os_memmove(G_io_apdu_buffer, G_io_seproxyhal_spi_buffer+3, G_io_apdu_length); c0d00fec: 8812 ldrh r2, [r2, #0] c0d00fee: 1cc1 adds r1, r0, #3 c0d00ff0: 4805 ldr r0, [pc, #20] ; (c0d01008 <io_seproxyhal_handle_capdu_event+0x48>) c0d00ff2: f7ff fe60 bl c0d00cb6 <os_memmove> } } c0d00ff6: bd80 pop {r7, pc} c0d00ff8: 20001a6a .word 0x20001a6a c0d00ffc: 20001a54 .word 0x20001a54 c0d01000: 20001800 .word 0x20001800 c0d01004: 20001a6c .word 0x20001a6c c0d01008: 200018f8 .word 0x200018f8 c0d0100c <io_seproxyhal_handle_event>: unsigned int io_seproxyhal_handle_event(void) { c0d0100c: b5b0 push {r4, r5, r7, lr} unsigned int rx_len = U2BE(G_io_seproxyhal_spi_buffer, 1); c0d0100e: 481e ldr r0, [pc, #120] ; (c0d01088 <io_seproxyhal_handle_event+0x7c>) c0d01010: 7882 ldrb r2, [r0, #2] c0d01012: 7841 ldrb r1, [r0, #1] c0d01014: 0209 lsls r1, r1, #8 c0d01016: 4311 orrs r1, r2 c0d01018: 7800 ldrb r0, [r0, #0] switch(G_io_seproxyhal_spi_buffer[0]) { c0d0101a: 280f cmp r0, #15 c0d0101c: dc09 bgt.n c0d01032 <io_seproxyhal_handle_event+0x26> c0d0101e: 280e cmp r0, #14 c0d01020: d00e beq.n c0d01040 <io_seproxyhal_handle_event+0x34> c0d01022: 280f cmp r0, #15 c0d01024: d11f bne.n c0d01066 <io_seproxyhal_handle_event+0x5a> c0d01026: 2000 movs r0, #0 #ifdef HAVE_IO_USB case SEPROXYHAL_TAG_USB_EVENT: if (rx_len != 1) { c0d01028: 2901 cmp r1, #1 c0d0102a: d126 bne.n c0d0107a <io_seproxyhal_handle_event+0x6e> return 0; } io_seproxyhal_handle_usb_event(); c0d0102c: f7ff ff18 bl c0d00e60 <io_seproxyhal_handle_usb_event> c0d01030: e022 b.n c0d01078 <io_seproxyhal_handle_event+0x6c> c0d01032: 2810 cmp r0, #16 c0d01034: d01b beq.n c0d0106e <io_seproxyhal_handle_event+0x62> c0d01036: 2816 cmp r0, #22 c0d01038: d115 bne.n c0d01066 <io_seproxyhal_handle_event+0x5a> } return 1; #endif // HAVE_BLE case SEPROXYHAL_TAG_CAPDU_EVENT: io_seproxyhal_handle_capdu_event(); c0d0103a: f7ff ffc1 bl c0d00fc0 <io_seproxyhal_handle_capdu_event> c0d0103e: e01b b.n c0d01078 <io_seproxyhal_handle_event+0x6c> c0d01040: 2000 movs r0, #0 c0d01042: 4912 ldr r1, [pc, #72] ; (c0d0108c <io_seproxyhal_handle_event+0x80>) // process ticker events to timeout the IO transfers, and forward to the user io_event function too #ifdef HAVE_IO_USB { unsigned int i = IO_USB_MAX_ENDPOINTS; while(i--) { if (G_io_usb_ep_timeouts[i].timeout) { c0d01044: 1a0a subs r2, r1, r0 c0d01046: 8993 ldrh r3, [r2, #12] c0d01048: 2b00 cmp r3, #0 c0d0104a: d009 beq.n c0d01060 <io_seproxyhal_handle_event+0x54> G_io_usb_ep_timeouts[i].timeout-=MIN(G_io_usb_ep_timeouts[i].timeout, 100); c0d0104c: 2464 movs r4, #100 ; 0x64 c0d0104e: 2b64 cmp r3, #100 ; 0x64 c0d01050: 461d mov r5, r3 c0d01052: d300 bcc.n c0d01056 <io_seproxyhal_handle_event+0x4a> c0d01054: 4625 mov r5, r4 c0d01056: 1b5b subs r3, r3, r5 c0d01058: 8193 strh r3, [r2, #12] c0d0105a: 4a0d ldr r2, [pc, #52] ; (c0d01090 <io_seproxyhal_handle_event+0x84>) if (!G_io_usb_ep_timeouts[i].timeout) { c0d0105c: 4213 tst r3, r2 c0d0105e: d00d beq.n c0d0107c <io_seproxyhal_handle_event+0x70> case SEPROXYHAL_TAG_TICKER_EVENT: // process ticker events to timeout the IO transfers, and forward to the user io_event function too #ifdef HAVE_IO_USB { unsigned int i = IO_USB_MAX_ENDPOINTS; while(i--) { c0d01060: 1c80 adds r0, r0, #2 c0d01062: 280e cmp r0, #14 c0d01064: d1ee bne.n c0d01044 <io_seproxyhal_handle_event+0x38> } } #endif // HAVE_IO_USB // no break is intentional default: return io_event(CHANNEL_SPI); c0d01066: 2002 movs r0, #2 c0d01068: f7ff f85a bl c0d00120 <io_event> } // defaultly return as not processed return 0; } c0d0106c: bdb0 pop {r4, r5, r7, pc} c0d0106e: 2000 movs r0, #0 } io_seproxyhal_handle_usb_event(); return 1; case SEPROXYHAL_TAG_USB_EP_XFER_EVENT: if (rx_len < 3) { c0d01070: 2903 cmp r1, #3 c0d01072: d302 bcc.n c0d0107a <io_seproxyhal_handle_event+0x6e> // error ! return 0; } io_seproxyhal_handle_usb_ep_xfer_event(); c0d01074: f7ff ff3a bl c0d00eec <io_seproxyhal_handle_usb_ep_xfer_event> c0d01078: 2001 movs r0, #1 default: return io_event(CHANNEL_SPI); } // defaultly return as not processed return 0; } c0d0107a: bdb0 pop {r4, r5, r7, pc} while(i--) { if (G_io_usb_ep_timeouts[i].timeout) { G_io_usb_ep_timeouts[i].timeout-=MIN(G_io_usb_ep_timeouts[i].timeout, 100); if (!G_io_usb_ep_timeouts[i].timeout) { // timeout ! G_io_apdu_state = APDU_IDLE; c0d0107c: 4805 ldr r0, [pc, #20] ; (c0d01094 <io_seproxyhal_handle_event+0x88>) c0d0107e: 2100 movs r1, #0 c0d01080: 7001 strb r1, [r0, #0] THROW(EXCEPTION_IO_RESET); c0d01082: 2010 movs r0, #16 c0d01084: f7ff fecb bl c0d00e1e <os_longjmp> c0d01088: 20001800 .word 0x20001800 c0d0108c: 20001a5c .word 0x20001a5c c0d01090: 0000ffff .word 0x0000ffff c0d01094: 20001a6a .word 0x20001a6a c0d01098 <io_seproxyhal_init>: #ifdef HAVE_BOLOS_APP_STACK_CANARY #define APP_STACK_CANARY_MAGIC 0xDEAD0031 extern unsigned int app_stack_canary; #endif // HAVE_BOLOS_APP_STACK_CANARY void io_seproxyhal_init(void) { c0d01098: b510 push {r4, lr} // Enforce OS compatibility check_api_level(CX_COMPAT_APILEVEL); c0d0109a: 2009 movs r0, #9 c0d0109c: f000 ff1e bl c0d01edc <check_api_level> #ifdef HAVE_BOLOS_APP_STACK_CANARY app_stack_canary = APP_STACK_CANARY_MAGIC; #endif // HAVE_BOLOS_APP_STACK_CANARY G_io_apdu_state = APDU_IDLE; c0d010a0: 4807 ldr r0, [pc, #28] ; (c0d010c0 <io_seproxyhal_init+0x28>) c0d010a2: 2400 movs r4, #0 c0d010a4: 7004 strb r4, [r0, #0] G_io_apdu_length = 0; c0d010a6: 4807 ldr r0, [pc, #28] ; (c0d010c4 <io_seproxyhal_init+0x2c>) c0d010a8: 8004 strh r4, [r0, #0] G_io_apdu_media = IO_APDU_MEDIA_NONE; c0d010aa: 4807 ldr r0, [pc, #28] ; (c0d010c8 <io_seproxyhal_init+0x30>) c0d010ac: 7004 strb r4, [r0, #0] debug_apdus_offset = 0; #endif // DEBUG_APDU #ifdef HAVE_USB_APDU io_usb_hid_init(); c0d010ae: f7ff fe1d bl c0d00cec <io_usb_hid_init> io_seproxyhal_init_button(); } void io_seproxyhal_init_ux(void) { // initialize the touch part G_bagl_last_touched_not_released_component = NULL; c0d010b2: 4806 ldr r0, [pc, #24] ; (c0d010cc <io_seproxyhal_init+0x34>) c0d010b4: 6004 str r4, [r0, #0] } void io_seproxyhal_init_button(void) { // no button push so far G_button_mask = 0; c0d010b6: 4806 ldr r0, [pc, #24] ; (c0d010d0 <io_seproxyhal_init+0x38>) c0d010b8: 6004 str r4, [r0, #0] G_button_same_mask_counter = 0; c0d010ba: 4806 ldr r0, [pc, #24] ; (c0d010d4 <io_seproxyhal_init+0x3c>) c0d010bc: 6004 str r4, [r0, #0] io_usb_hid_init(); #endif // HAVE_USB_APDU io_seproxyhal_init_ux(); io_seproxyhal_init_button(); } c0d010be: bd10 pop {r4, pc} c0d010c0: 20001a6a .word 0x20001a6a c0d010c4: 20001a6c .word 0x20001a6c c0d010c8: 20001a54 .word 0x20001a54 c0d010cc: 20001a70 .word 0x20001a70 c0d010d0: 20001a74 .word 0x20001a74 c0d010d4: 20001a78 .word 0x20001a78 c0d010d8 <io_seproxyhal_init_ux>: void io_seproxyhal_init_ux(void) { // initialize the touch part G_bagl_last_touched_not_released_component = NULL; c0d010d8: 4801 ldr r0, [pc, #4] ; (c0d010e0 <io_seproxyhal_init_ux+0x8>) c0d010da: 2100 movs r1, #0 c0d010dc: 6001 str r1, [r0, #0] } c0d010de: 4770 bx lr c0d010e0: 20001a70 .word 0x20001a70 c0d010e4 <io_seproxyhal_init_button>: void io_seproxyhal_init_button(void) { // no button push so far G_button_mask = 0; c0d010e4: 4802 ldr r0, [pc, #8] ; (c0d010f0 <io_seproxyhal_init_button+0xc>) c0d010e6: 2100 movs r1, #0 c0d010e8: 6001 str r1, [r0, #0] G_button_same_mask_counter = 0; c0d010ea: 4802 ldr r0, [pc, #8] ; (c0d010f4 <io_seproxyhal_init_button+0x10>) c0d010ec: 6001 str r1, [r0, #0] } c0d010ee: 4770 bx lr c0d010f0: 20001a74 .word 0x20001a74 c0d010f4: 20001a78 .word 0x20001a78 c0d010f8 <io_seproxyhal_touch_out>: #ifdef HAVE_BAGL unsigned int io_seproxyhal_touch_out(const bagl_element_t* element, bagl_element_callback_t before_display) { c0d010f8: b5b0 push {r4, r5, r7, lr} c0d010fa: 460d mov r5, r1 c0d010fc: 4604 mov r4, r0 const bagl_element_t* el; if (element->out != NULL) { c0d010fe: 6b20 ldr r0, [r4, #48] ; 0x30 c0d01100: 2800 cmp r0, #0 c0d01102: d00c beq.n c0d0111e <io_seproxyhal_touch_out+0x26> el = (const bagl_element_t*)PIC(((bagl_element_callback_t)PIC(element->out))(element)); c0d01104: f000 fed2 bl c0d01eac <pic> c0d01108: 4601 mov r1, r0 c0d0110a: 4620 mov r0, r4 c0d0110c: 4788 blx r1 c0d0110e: f000 fecd bl c0d01eac <pic> c0d01112: 2100 movs r1, #0 // backward compatible with samples and such if (! el) { c0d01114: 2800 cmp r0, #0 c0d01116: d010 beq.n c0d0113a <io_seproxyhal_touch_out+0x42> c0d01118: 2801 cmp r0, #1 c0d0111a: d000 beq.n c0d0111e <io_seproxyhal_touch_out+0x26> c0d0111c: 4604 mov r4, r0 element = el; } } // out function might have triggered a draw of its own during a display callback if (before_display) { c0d0111e: 2d00 cmp r5, #0 c0d01120: d007 beq.n c0d01132 <io_seproxyhal_touch_out+0x3a> el = before_display(element); c0d01122: 4620 mov r0, r4 c0d01124: 47a8 blx r5 c0d01126: 2100 movs r1, #0 if (!el) { c0d01128: 2800 cmp r0, #0 c0d0112a: d006 beq.n c0d0113a <io_seproxyhal_touch_out+0x42> c0d0112c: 2801 cmp r0, #1 c0d0112e: d000 beq.n c0d01132 <io_seproxyhal_touch_out+0x3a> c0d01130: 4604 mov r4, r0 if ((unsigned int)el != 1) { element = el; } } io_seproxyhal_display(element); c0d01132: 4620 mov r0, r4 c0d01134: f7fe fff0 bl c0d00118 <io_seproxyhal_display> c0d01138: 2101 movs r1, #1 return 1; } c0d0113a: 4608 mov r0, r1 c0d0113c: bdb0 pop {r4, r5, r7, pc} c0d0113e <io_seproxyhal_touch_over>: unsigned int io_seproxyhal_touch_over(const bagl_element_t* element, bagl_element_callback_t before_display) { c0d0113e: b5b0 push {r4, r5, r7, lr} c0d01140: b08e sub sp, #56 ; 0x38 c0d01142: 460d mov r5, r1 c0d01144: 4604 mov r4, r0 bagl_element_t e; const bagl_element_t* el; if (element->over != NULL) { c0d01146: 6b60 ldr r0, [r4, #52] ; 0x34 c0d01148: 2800 cmp r0, #0 c0d0114a: d00c beq.n c0d01166 <io_seproxyhal_touch_over+0x28> el = (const bagl_element_t*)PIC(((bagl_element_callback_t)PIC(element->over))(element)); c0d0114c: f000 feae bl c0d01eac <pic> c0d01150: 4601 mov r1, r0 c0d01152: 4620 mov r0, r4 c0d01154: 4788 blx r1 c0d01156: f000 fea9 bl c0d01eac <pic> c0d0115a: 2100 movs r1, #0 // backward compatible with samples and such if (!el) { c0d0115c: 2800 cmp r0, #0 c0d0115e: d01b beq.n c0d01198 <io_seproxyhal_touch_over+0x5a> c0d01160: 2801 cmp r0, #1 c0d01162: d000 beq.n c0d01166 <io_seproxyhal_touch_over+0x28> c0d01164: 4604 mov r4, r0 element = el; } } // over function might have triggered a draw of its own during a display callback if (before_display) { c0d01166: 2d00 cmp r5, #0 c0d01168: d008 beq.n c0d0117c <io_seproxyhal_touch_over+0x3e> el = before_display(element); c0d0116a: 4620 mov r0, r4 c0d0116c: 47a8 blx r5 c0d0116e: 466c mov r4, sp c0d01170: 2100 movs r1, #0 element = &e; if (!el) { c0d01172: 2800 cmp r0, #0 c0d01174: d010 beq.n c0d01198 <io_seproxyhal_touch_over+0x5a> c0d01176: 2801 cmp r0, #1 c0d01178: d000 beq.n c0d0117c <io_seproxyhal_touch_over+0x3e> c0d0117a: 4604 mov r4, r0 c0d0117c: 466d mov r5, sp element = el; } } // swap colors os_memmove(&e, (void*)element, sizeof(bagl_element_t)); c0d0117e: 2238 movs r2, #56 ; 0x38 c0d01180: 4628 mov r0, r5 c0d01182: 4621 mov r1, r4 c0d01184: f7ff fd97 bl c0d00cb6 <os_memmove> e.component.fgcolor = element->overfgcolor; c0d01188: 6a60 ldr r0, [r4, #36] ; 0x24 c0d0118a: 9004 str r0, [sp, #16] e.component.bgcolor = element->overbgcolor; c0d0118c: 6aa0 ldr r0, [r4, #40] ; 0x28 c0d0118e: 9005 str r0, [sp, #20] io_seproxyhal_display(&e); c0d01190: 4628 mov r0, r5 c0d01192: f7fe ffc1 bl c0d00118 <io_seproxyhal_display> c0d01196: 2101 movs r1, #1 return 1; } c0d01198: 4608 mov r0, r1 c0d0119a: b00e add sp, #56 ; 0x38 c0d0119c: bdb0 pop {r4, r5, r7, pc} c0d0119e <io_seproxyhal_touch_tap>: unsigned int io_seproxyhal_touch_tap(const bagl_element_t* element, bagl_element_callback_t before_display) { c0d0119e: b5b0 push {r4, r5, r7, lr} c0d011a0: 460d mov r5, r1 c0d011a2: 4604 mov r4, r0 const bagl_element_t* el; if (element->tap != NULL) { c0d011a4: 6ae0 ldr r0, [r4, #44] ; 0x2c c0d011a6: 2800 cmp r0, #0 c0d011a8: d00c beq.n c0d011c4 <io_seproxyhal_touch_tap+0x26> el = (const bagl_element_t*)PIC(((bagl_element_callback_t)PIC(element->tap))(element)); c0d011aa: f000 fe7f bl c0d01eac <pic> c0d011ae: 4601 mov r1, r0 c0d011b0: 4620 mov r0, r4 c0d011b2: 4788 blx r1 c0d011b4: f000 fe7a bl c0d01eac <pic> c0d011b8: 2100 movs r1, #0 // backward compatible with samples and such if (!el) { c0d011ba: 2800 cmp r0, #0 c0d011bc: d010 beq.n c0d011e0 <io_seproxyhal_touch_tap+0x42> c0d011be: 2801 cmp r0, #1 c0d011c0: d000 beq.n c0d011c4 <io_seproxyhal_touch_tap+0x26> c0d011c2: 4604 mov r4, r0 element = el; } } // tap function might have triggered a draw of its own during a display callback if (before_display) { c0d011c4: 2d00 cmp r5, #0 c0d011c6: d007 beq.n c0d011d8 <io_seproxyhal_touch_tap+0x3a> el = before_display(element); c0d011c8: 4620 mov r0, r4 c0d011ca: 47a8 blx r5 c0d011cc: 2100 movs r1, #0 if (!el) { c0d011ce: 2800 cmp r0, #0 c0d011d0: d006 beq.n c0d011e0 <io_seproxyhal_touch_tap+0x42> c0d011d2: 2801 cmp r0, #1 c0d011d4: d000 beq.n c0d011d8 <io_seproxyhal_touch_tap+0x3a> c0d011d6: 4604 mov r4, r0 } if ((unsigned int)el != 1) { element = el; } } io_seproxyhal_display(element); c0d011d8: 4620 mov r0, r4 c0d011da: f7fe ff9d bl c0d00118 <io_seproxyhal_display> c0d011de: 2101 movs r1, #1 return 1; } c0d011e0: 4608 mov r0, r1 c0d011e2: bdb0 pop {r4, r5, r7, pc} c0d011e4 <io_seproxyhal_touch_element_callback>: io_seproxyhal_touch_element_callback(elements, element_count, x, y, event_kind, NULL); } // browse all elements and until an element has changed state, continue browsing // return if processed or not void io_seproxyhal_touch_element_callback(const bagl_element_t* elements, unsigned short element_count, unsigned short x, unsigned short y, unsigned char event_kind, bagl_element_callback_t before_display) { c0d011e4: b5f0 push {r4, r5, r6, r7, lr} c0d011e6: b087 sub sp, #28 c0d011e8: 9302 str r3, [sp, #8] c0d011ea: 9203 str r2, [sp, #12] c0d011ec: 9105 str r1, [sp, #20] unsigned char comp_idx; unsigned char last_touched_not_released_component_was_in_current_array = 0; // find the first empty entry for (comp_idx=0; comp_idx < element_count; comp_idx++) { c0d011ee: 2900 cmp r1, #0 c0d011f0: d077 beq.n c0d012e2 <io_seproxyhal_touch_element_callback+0xfe> c0d011f2: 9004 str r0, [sp, #16] c0d011f4: 980d ldr r0, [sp, #52] ; 0x34 c0d011f6: 9001 str r0, [sp, #4] c0d011f8: 980c ldr r0, [sp, #48] ; 0x30 c0d011fa: 9000 str r0, [sp, #0] c0d011fc: 2500 movs r5, #0 c0d011fe: 4b3c ldr r3, [pc, #240] ; (c0d012f0 <io_seproxyhal_touch_element_callback+0x10c>) c0d01200: 9506 str r5, [sp, #24] c0d01202: 462f mov r7, r5 c0d01204: 461e mov r6, r3 // process all components matching the x/y/w/h (no break) => fishy for the released out of zone // continue processing only if a status has not been sent if (io_seproxyhal_spi_is_status_sent()) { c0d01206: f000 fffb bl c0d02200 <io_seproxyhal_spi_is_status_sent> c0d0120a: 2800 cmp r0, #0 c0d0120c: d155 bne.n c0d012ba <io_seproxyhal_touch_element_callback+0xd6> // continue instead of return to process all elemnts and therefore discard last touched element break; } // only perform out callback when element was in the current array, else, leave it be if (&elements[comp_idx] == G_bagl_last_touched_not_released_component) { c0d0120e: 2038 movs r0, #56 ; 0x38 c0d01210: 4368 muls r0, r5 c0d01212: 9c04 ldr r4, [sp, #16] c0d01214: 1825 adds r5, r4, r0 c0d01216: 4633 mov r3, r6 c0d01218: 681a ldr r2, [r3, #0] c0d0121a: 2101 movs r1, #1 c0d0121c: 4295 cmp r5, r2 c0d0121e: d000 beq.n c0d01222 <io_seproxyhal_touch_element_callback+0x3e> c0d01220: 9906 ldr r1, [sp, #24] c0d01222: 9106 str r1, [sp, #24] last_touched_not_released_component_was_in_current_array = 1; } // the first component drawn with a if ((elements[comp_idx].component.type & BAGL_FLAG_TOUCHABLE) c0d01224: 5620 ldrsb r0, [r4, r0] && elements[comp_idx].component.x-elements[comp_idx].touch_area_brim <= x && x<elements[comp_idx].component.x+elements[comp_idx].component.width+elements[comp_idx].touch_area_brim c0d01226: 2800 cmp r0, #0 c0d01228: da41 bge.n c0d012ae <io_seproxyhal_touch_element_callback+0xca> c0d0122a: 2020 movs r0, #32 c0d0122c: 5c28 ldrb r0, [r5, r0] c0d0122e: 2102 movs r1, #2 c0d01230: 5e69 ldrsh r1, [r5, r1] c0d01232: 1a0a subs r2, r1, r0 c0d01234: 9c03 ldr r4, [sp, #12] c0d01236: 42a2 cmp r2, r4 c0d01238: dc39 bgt.n c0d012ae <io_seproxyhal_touch_element_callback+0xca> c0d0123a: 1841 adds r1, r0, r1 c0d0123c: 88ea ldrh r2, [r5, #6] c0d0123e: 1889 adds r1, r1, r2 && elements[comp_idx].component.y-elements[comp_idx].touch_area_brim <= y && y<elements[comp_idx].component.y+elements[comp_idx].component.height+elements[comp_idx].touch_area_brim) { c0d01240: 9a03 ldr r2, [sp, #12] c0d01242: 428a cmp r2, r1 c0d01244: da33 bge.n c0d012ae <io_seproxyhal_touch_element_callback+0xca> c0d01246: 2104 movs r1, #4 c0d01248: 5e6c ldrsh r4, [r5, r1] c0d0124a: 1a22 subs r2, r4, r0 c0d0124c: 9902 ldr r1, [sp, #8] c0d0124e: 428a cmp r2, r1 c0d01250: dc2d bgt.n c0d012ae <io_seproxyhal_touch_element_callback+0xca> c0d01252: 1820 adds r0, r4, r0 c0d01254: 8929 ldrh r1, [r5, #8] c0d01256: 1840 adds r0, r0, r1 if (&elements[comp_idx] == G_bagl_last_touched_not_released_component) { last_touched_not_released_component_was_in_current_array = 1; } // the first component drawn with a if ((elements[comp_idx].component.type & BAGL_FLAG_TOUCHABLE) c0d01258: 9902 ldr r1, [sp, #8] c0d0125a: 4281 cmp r1, r0 c0d0125c: da27 bge.n c0d012ae <io_seproxyhal_touch_element_callback+0xca> && elements[comp_idx].component.x-elements[comp_idx].touch_area_brim <= x && x<elements[comp_idx].component.x+elements[comp_idx].component.width+elements[comp_idx].touch_area_brim && elements[comp_idx].component.y-elements[comp_idx].touch_area_brim <= y && y<elements[comp_idx].component.y+elements[comp_idx].component.height+elements[comp_idx].touch_area_brim) { // outing the previous over'ed component if (&elements[comp_idx] != G_bagl_last_touched_not_released_component c0d0125e: 6818 ldr r0, [r3, #0] && G_bagl_last_touched_not_released_component != NULL) { c0d01260: 4285 cmp r5, r0 c0d01262: d010 beq.n c0d01286 <io_seproxyhal_touch_element_callback+0xa2> c0d01264: 6818 ldr r0, [r3, #0] if ((elements[comp_idx].component.type & BAGL_FLAG_TOUCHABLE) && elements[comp_idx].component.x-elements[comp_idx].touch_area_brim <= x && x<elements[comp_idx].component.x+elements[comp_idx].component.width+elements[comp_idx].touch_area_brim && elements[comp_idx].component.y-elements[comp_idx].touch_area_brim <= y && y<elements[comp_idx].component.y+elements[comp_idx].component.height+elements[comp_idx].touch_area_brim) { // outing the previous over'ed component if (&elements[comp_idx] != G_bagl_last_touched_not_released_component c0d01266: 2800 cmp r0, #0 c0d01268: d00d beq.n c0d01286 <io_seproxyhal_touch_element_callback+0xa2> && G_bagl_last_touched_not_released_component != NULL) { // only out the previous element if the newly matching will be displayed if (!before_display || before_display(&elements[comp_idx])) { c0d0126a: 9801 ldr r0, [sp, #4] c0d0126c: 2800 cmp r0, #0 c0d0126e: d005 beq.n c0d0127c <io_seproxyhal_touch_element_callback+0x98> c0d01270: 4628 mov r0, r5 c0d01272: 9901 ldr r1, [sp, #4] c0d01274: 4788 blx r1 c0d01276: 4633 mov r3, r6 c0d01278: 2800 cmp r0, #0 c0d0127a: d018 beq.n c0d012ae <io_seproxyhal_touch_element_callback+0xca> if (io_seproxyhal_touch_out(G_bagl_last_touched_not_released_component, before_display)) { c0d0127c: 6818 ldr r0, [r3, #0] c0d0127e: 9901 ldr r1, [sp, #4] c0d01280: f7ff ff3a bl c0d010f8 <io_seproxyhal_touch_out> c0d01284: e008 b.n c0d01298 <io_seproxyhal_touch_element_callback+0xb4> c0d01286: 9800 ldr r0, [sp, #0] continue; } */ // callback the hal to notify the component impacted by the user input else if (event_kind == SEPROXYHAL_TAG_FINGER_EVENT_RELEASE) { c0d01288: 2801 cmp r0, #1 c0d0128a: d009 beq.n c0d012a0 <io_seproxyhal_touch_element_callback+0xbc> c0d0128c: 2802 cmp r0, #2 c0d0128e: d10e bne.n c0d012ae <io_seproxyhal_touch_element_callback+0xca> if (io_seproxyhal_touch_tap(&elements[comp_idx], before_display)) { c0d01290: 4628 mov r0, r5 c0d01292: 9901 ldr r1, [sp, #4] c0d01294: f7ff ff83 bl c0d0119e <io_seproxyhal_touch_tap> c0d01298: 4633 mov r3, r6 c0d0129a: 2800 cmp r0, #0 c0d0129c: d007 beq.n c0d012ae <io_seproxyhal_touch_element_callback+0xca> c0d0129e: e022 b.n c0d012e6 <io_seproxyhal_touch_element_callback+0x102> return; } } else if (event_kind == SEPROXYHAL_TAG_FINGER_EVENT_TOUCH) { // ask for overing if (io_seproxyhal_touch_over(&elements[comp_idx], before_display)) { c0d012a0: 4628 mov r0, r5 c0d012a2: 9901 ldr r1, [sp, #4] c0d012a4: f7ff ff4b bl c0d0113e <io_seproxyhal_touch_over> c0d012a8: 4633 mov r3, r6 c0d012aa: 2800 cmp r0, #0 c0d012ac: d11e bne.n c0d012ec <io_seproxyhal_touch_element_callback+0x108> void io_seproxyhal_touch_element_callback(const bagl_element_t* elements, unsigned short element_count, unsigned short x, unsigned short y, unsigned char event_kind, bagl_element_callback_t before_display) { unsigned char comp_idx; unsigned char last_touched_not_released_component_was_in_current_array = 0; // find the first empty entry for (comp_idx=0; comp_idx < element_count; comp_idx++) { c0d012ae: 1c7f adds r7, r7, #1 c0d012b0: b2fd uxtb r5, r7 c0d012b2: 9805 ldr r0, [sp, #20] c0d012b4: 4285 cmp r5, r0 c0d012b6: d3a5 bcc.n c0d01204 <io_seproxyhal_touch_element_callback+0x20> c0d012b8: e000 b.n c0d012bc <io_seproxyhal_touch_element_callback+0xd8> c0d012ba: 4633 mov r3, r6 } } // if overing out of component or over another component, the out event is sent after the over event of the previous component if(last_touched_not_released_component_was_in_current_array && G_bagl_last_touched_not_released_component != NULL) { c0d012bc: 9806 ldr r0, [sp, #24] c0d012be: 0600 lsls r0, r0, #24 c0d012c0: d00f beq.n c0d012e2 <io_seproxyhal_touch_element_callback+0xfe> c0d012c2: 6818 ldr r0, [r3, #0] } } } // if overing out of component or over another component, the out event is sent after the over event of the previous component if(last_touched_not_released_component_was_in_current_array c0d012c4: 2800 cmp r0, #0 c0d012c6: d00c beq.n c0d012e2 <io_seproxyhal_touch_element_callback+0xfe> && G_bagl_last_touched_not_released_component != NULL) { // we won't be able to notify the out, don't do it, in case a diplay refused the dra of the relased element and the position matched another element of the array (in autocomplete for example) if (io_seproxyhal_spi_is_status_sent()) { c0d012c8: f000 ff9a bl c0d02200 <io_seproxyhal_spi_is_status_sent> c0d012cc: 4631 mov r1, r6 c0d012ce: 2800 cmp r0, #0 c0d012d0: d107 bne.n c0d012e2 <io_seproxyhal_touch_element_callback+0xfe> return; } if (io_seproxyhal_touch_out(G_bagl_last_touched_not_released_component, before_display)) { c0d012d2: 6808 ldr r0, [r1, #0] c0d012d4: 9901 ldr r1, [sp, #4] c0d012d6: f7ff ff0f bl c0d010f8 <io_seproxyhal_touch_out> c0d012da: 2800 cmp r0, #0 c0d012dc: d001 beq.n c0d012e2 <io_seproxyhal_touch_element_callback+0xfe> // ok component out has been emitted G_bagl_last_touched_not_released_component = NULL; c0d012de: 2000 movs r0, #0 c0d012e0: 6030 str r0, [r6, #0] } } // not processed } c0d012e2: b007 add sp, #28 c0d012e4: bdf0 pop {r4, r5, r6, r7, pc} c0d012e6: 2000 movs r0, #0 c0d012e8: 6018 str r0, [r3, #0] c0d012ea: e7fa b.n c0d012e2 <io_seproxyhal_touch_element_callback+0xfe> } else if (event_kind == SEPROXYHAL_TAG_FINGER_EVENT_TOUCH) { // ask for overing if (io_seproxyhal_touch_over(&elements[comp_idx], before_display)) { // remember the last touched component G_bagl_last_touched_not_released_component = (bagl_element_t*)&elements[comp_idx]; c0d012ec: 601d str r5, [r3, #0] c0d012ee: e7f8 b.n c0d012e2 <io_seproxyhal_touch_element_callback+0xfe> c0d012f0: 20001a70 .word 0x20001a70 c0d012f4 <io_seproxyhal_display_icon>: // remaining length of bitmap bits to be displayed return len; } #endif // SEPROXYHAL_TAG_SCREEN_DISPLAY_RAW_STATUS void io_seproxyhal_display_icon(bagl_component_t* icon_component, bagl_icon_details_t* icon_details) { c0d012f4: b5f0 push {r4, r5, r6, r7, lr} c0d012f6: b089 sub sp, #36 ; 0x24 c0d012f8: 460c mov r4, r1 c0d012fa: 4601 mov r1, r0 c0d012fc: ad02 add r5, sp, #8 c0d012fe: 221c movs r2, #28 bagl_component_t icon_component_mod; // ensure not being out of bounds in the icon component agianst the declared icon real size os_memmove(&icon_component_mod, icon_component, sizeof(bagl_component_t)); c0d01300: 4628 mov r0, r5 c0d01302: 9201 str r2, [sp, #4] c0d01304: f7ff fcd7 bl c0d00cb6 <os_memmove> icon_component_mod.width = icon_details->width; c0d01308: 6821 ldr r1, [r4, #0] c0d0130a: 80e9 strh r1, [r5, #6] icon_component_mod.height = icon_details->height; c0d0130c: 6862 ldr r2, [r4, #4] c0d0130e: 812a strh r2, [r5, #8] // component type = ICON, provided bitmap // => bitmap transmitted // color index size unsigned int h = (1<<(icon_details->bpp))*sizeof(unsigned int); c0d01310: 68a0 ldr r0, [r4, #8] unsigned int w = ((icon_component->width*icon_component->height*icon_details->bpp)/8)+((icon_component->width*icon_component->height*icon_details->bpp)%8?1:0); unsigned short length = sizeof(bagl_component_t) +1 /* bpp */ +h /* color index */ +w; /* image bitmap size */ G_io_seproxyhal_spi_buffer[0] = SEPROXYHAL_TAG_SCREEN_DISPLAY_STATUS; c0d01312: 4f1a ldr r7, [pc, #104] ; (c0d0137c <io_seproxyhal_display_icon+0x88>) c0d01314: 2365 movs r3, #101 ; 0x65 c0d01316: 703b strb r3, [r7, #0] // color index size unsigned int h = (1<<(icon_details->bpp))*sizeof(unsigned int); // bitmap size unsigned int w = ((icon_component->width*icon_component->height*icon_details->bpp)/8)+((icon_component->width*icon_component->height*icon_details->bpp)%8?1:0); c0d01318: b292 uxth r2, r2 c0d0131a: 4342 muls r2, r0 c0d0131c: b28b uxth r3, r1 c0d0131e: 4353 muls r3, r2 c0d01320: 08d9 lsrs r1, r3, #3 c0d01322: 1c4e adds r6, r1, #1 c0d01324: 2207 movs r2, #7 c0d01326: 4213 tst r3, r2 c0d01328: d100 bne.n c0d0132c <io_seproxyhal_display_icon+0x38> c0d0132a: 460e mov r6, r1 c0d0132c: 4631 mov r1, r6 c0d0132e: 9100 str r1, [sp, #0] c0d01330: 2604 movs r6, #4 // component type = ICON, provided bitmap // => bitmap transmitted // color index size unsigned int h = (1<<(icon_details->bpp))*sizeof(unsigned int); c0d01332: 4086 lsls r6, r0 // bitmap size unsigned int w = ((icon_component->width*icon_component->height*icon_details->bpp)/8)+((icon_component->width*icon_component->height*icon_details->bpp)%8?1:0); unsigned short length = sizeof(bagl_component_t) +1 /* bpp */ +h /* color index */ c0d01334: 1870 adds r0, r6, r1 +w; /* image bitmap size */ c0d01336: 301d adds r0, #29 G_io_seproxyhal_spi_buffer[0] = SEPROXYHAL_TAG_SCREEN_DISPLAY_STATUS; G_io_seproxyhal_spi_buffer[1] = length>>8; c0d01338: 0a01 lsrs r1, r0, #8 c0d0133a: 7079 strb r1, [r7, #1] G_io_seproxyhal_spi_buffer[2] = length; c0d0133c: 70b8 strb r0, [r7, #2] c0d0133e: 2103 movs r1, #3 io_seproxyhal_spi_send(G_io_seproxyhal_spi_buffer, 3); c0d01340: 4638 mov r0, r7 c0d01342: f000 ff47 bl c0d021d4 <io_seproxyhal_spi_send> io_seproxyhal_spi_send((unsigned char*)icon_component, sizeof(bagl_component_t)); c0d01346: 4628 mov r0, r5 c0d01348: 9901 ldr r1, [sp, #4] c0d0134a: f000 ff43 bl c0d021d4 <io_seproxyhal_spi_send> G_io_seproxyhal_spi_buffer[0] = icon_details->bpp; c0d0134e: 68a0 ldr r0, [r4, #8] c0d01350: 7038 strb r0, [r7, #0] c0d01352: 2101 movs r1, #1 io_seproxyhal_spi_send(G_io_seproxyhal_spi_buffer, 1); c0d01354: 4638 mov r0, r7 c0d01356: f000 ff3d bl c0d021d4 <io_seproxyhal_spi_send> io_seproxyhal_spi_send((unsigned char*)PIC(icon_details->colors), h); c0d0135a: 68e0 ldr r0, [r4, #12] c0d0135c: f000 fda6 bl c0d01eac <pic> c0d01360: b2b1 uxth r1, r6 c0d01362: f000 ff37 bl c0d021d4 <io_seproxyhal_spi_send> io_seproxyhal_spi_send((unsigned char*)PIC(icon_details->bitmap), w); c0d01366: 9800 ldr r0, [sp, #0] c0d01368: b285 uxth r5, r0 c0d0136a: 6920 ldr r0, [r4, #16] c0d0136c: f000 fd9e bl c0d01eac <pic> c0d01370: 4629 mov r1, r5 c0d01372: f000 ff2f bl c0d021d4 <io_seproxyhal_spi_send> #endif // !SEPROXYHAL_TAG_SCREEN_DISPLAY_RAW_STATUS } c0d01376: b009 add sp, #36 ; 0x24 c0d01378: bdf0 pop {r4, r5, r6, r7, pc} c0d0137a: 46c0 nop ; (mov r8, r8) c0d0137c: 20001800 .word 0x20001800 c0d01380 <io_seproxyhal_display_default>: void io_seproxyhal_display_default(const bagl_element_t * element) { c0d01380: b570 push {r4, r5, r6, lr} c0d01382: 4604 mov r4, r0 // process automagically address from rom and from ram unsigned int type = (element->component.type & ~(BAGL_FLAG_TOUCHABLE)); c0d01384: 7820 ldrb r0, [r4, #0] c0d01386: 267f movs r6, #127 ; 0x7f c0d01388: 4006 ands r6, r0 // avoid sending another status :), fixes a lot of bugs in the end if (io_seproxyhal_spi_is_status_sent()) { c0d0138a: f000 ff39 bl c0d02200 <io_seproxyhal_spi_is_status_sent> c0d0138e: 2800 cmp r0, #0 c0d01390: d130 bne.n c0d013f4 <io_seproxyhal_display_default+0x74> c0d01392: 2e00 cmp r6, #0 c0d01394: d02e beq.n c0d013f4 <io_seproxyhal_display_default+0x74> return; } if (type != BAGL_NONE) { if (element->text != NULL) { c0d01396: 69e0 ldr r0, [r4, #28] c0d01398: 2800 cmp r0, #0 c0d0139a: d01d beq.n c0d013d8 <io_seproxyhal_display_default+0x58> unsigned int text_adr = PIC((unsigned int)element->text); c0d0139c: f000 fd86 bl c0d01eac <pic> c0d013a0: 4605 mov r5, r0 // consider an icon details descriptor is pointed by the context if (type == BAGL_ICON && element->component.icon_id == 0) { c0d013a2: 2e05 cmp r6, #5 c0d013a4: d102 bne.n c0d013ac <io_seproxyhal_display_default+0x2c> c0d013a6: 7ea0 ldrb r0, [r4, #26] c0d013a8: 2800 cmp r0, #0 c0d013aa: d024 beq.n c0d013f6 <io_seproxyhal_display_default+0x76> io_seproxyhal_display_icon((bagl_component_t*)&element->component, (bagl_icon_details_t*)text_adr); } else { unsigned short length = sizeof(bagl_component_t)+strlen((const char*)text_adr); c0d013ac: 4628 mov r0, r5 c0d013ae: f002 ffa7 bl c0d04300 <strlen> c0d013b2: 4606 mov r6, r0 G_io_seproxyhal_spi_buffer[0] = SEPROXYHAL_TAG_SCREEN_DISPLAY_STATUS; c0d013b4: 4812 ldr r0, [pc, #72] ; (c0d01400 <io_seproxyhal_display_default+0x80>) c0d013b6: 2165 movs r1, #101 ; 0x65 c0d013b8: 7001 strb r1, [r0, #0] // consider an icon details descriptor is pointed by the context if (type == BAGL_ICON && element->component.icon_id == 0) { io_seproxyhal_display_icon((bagl_component_t*)&element->component, (bagl_icon_details_t*)text_adr); } else { unsigned short length = sizeof(bagl_component_t)+strlen((const char*)text_adr); c0d013ba: 4631 mov r1, r6 c0d013bc: 311c adds r1, #28 G_io_seproxyhal_spi_buffer[0] = SEPROXYHAL_TAG_SCREEN_DISPLAY_STATUS; G_io_seproxyhal_spi_buffer[1] = length>>8; c0d013be: 0a0a lsrs r2, r1, #8 c0d013c0: 7042 strb r2, [r0, #1] G_io_seproxyhal_spi_buffer[2] = length; c0d013c2: 7081 strb r1, [r0, #2] io_seproxyhal_spi_send(G_io_seproxyhal_spi_buffer, 3); c0d013c4: 2103 movs r1, #3 c0d013c6: f000 ff05 bl c0d021d4 <io_seproxyhal_spi_send> c0d013ca: 211c movs r1, #28 io_seproxyhal_spi_send((unsigned char*)&element->component, sizeof(bagl_component_t)); c0d013cc: 4620 mov r0, r4 c0d013ce: f000 ff01 bl c0d021d4 <io_seproxyhal_spi_send> io_seproxyhal_spi_send((unsigned char*)text_adr, length-sizeof(bagl_component_t)); c0d013d2: b2b1 uxth r1, r6 c0d013d4: 4628 mov r0, r5 c0d013d6: e00b b.n c0d013f0 <io_seproxyhal_display_default+0x70> } } else { unsigned short length = sizeof(bagl_component_t); G_io_seproxyhal_spi_buffer[0] = SEPROXYHAL_TAG_SCREEN_DISPLAY_STATUS; c0d013d8: 4809 ldr r0, [pc, #36] ; (c0d01400 <io_seproxyhal_display_default+0x80>) c0d013da: 2165 movs r1, #101 ; 0x65 c0d013dc: 7001 strb r1, [r0, #0] G_io_seproxyhal_spi_buffer[1] = length>>8; c0d013de: 2100 movs r1, #0 c0d013e0: 7041 strb r1, [r0, #1] c0d013e2: 251c movs r5, #28 G_io_seproxyhal_spi_buffer[2] = length; c0d013e4: 7085 strb r5, [r0, #2] io_seproxyhal_spi_send(G_io_seproxyhal_spi_buffer, 3); c0d013e6: 2103 movs r1, #3 c0d013e8: f000 fef4 bl c0d021d4 <io_seproxyhal_spi_send> io_seproxyhal_spi_send((unsigned char*)&element->component, sizeof(bagl_component_t)); c0d013ec: 4620 mov r0, r4 c0d013ee: 4629 mov r1, r5 c0d013f0: f000 fef0 bl c0d021d4 <io_seproxyhal_spi_send> } } } c0d013f4: bd70 pop {r4, r5, r6, pc} if (type != BAGL_NONE) { if (element->text != NULL) { unsigned int text_adr = PIC((unsigned int)element->text); // consider an icon details descriptor is pointed by the context if (type == BAGL_ICON && element->component.icon_id == 0) { io_seproxyhal_display_icon((bagl_component_t*)&element->component, (bagl_icon_details_t*)text_adr); c0d013f6: 4620 mov r0, r4 c0d013f8: 4629 mov r1, r5 c0d013fa: f7ff ff7b bl c0d012f4 <io_seproxyhal_display_icon> G_io_seproxyhal_spi_buffer[2] = length; io_seproxyhal_spi_send(G_io_seproxyhal_spi_buffer, 3); io_seproxyhal_spi_send((unsigned char*)&element->component, sizeof(bagl_component_t)); } } } c0d013fe: bd70 pop {r4, r5, r6, pc} c0d01400: 20001800 .word 0x20001800 c0d01404 <io_seproxyhal_button_push>: G_io_seproxyhal_spi_buffer[3] = (backlight_percentage?0x80:0)|(flags & 0x7F); // power on G_io_seproxyhal_spi_buffer[4] = backlight_percentage; io_seproxyhal_spi_send(G_io_seproxyhal_spi_buffer, 5); } void io_seproxyhal_button_push(button_push_callback_t button_callback, unsigned int new_button_mask) { c0d01404: b5f0 push {r4, r5, r6, r7, lr} c0d01406: b081 sub sp, #4 c0d01408: 4604 mov r4, r0 if (button_callback) { c0d0140a: 2c00 cmp r4, #0 c0d0140c: d02b beq.n c0d01466 <io_seproxyhal_button_push+0x62> unsigned int button_mask; unsigned int button_same_mask_counter; // enable speeded up long push if (new_button_mask == G_button_mask) { c0d0140e: 4817 ldr r0, [pc, #92] ; (c0d0146c <io_seproxyhal_button_push+0x68>) c0d01410: 6802 ldr r2, [r0, #0] c0d01412: 428a cmp r2, r1 c0d01414: d103 bne.n c0d0141e <io_seproxyhal_button_push+0x1a> // each 100ms ~ G_button_same_mask_counter++; c0d01416: 4a16 ldr r2, [pc, #88] ; (c0d01470 <io_seproxyhal_button_push+0x6c>) c0d01418: 6813 ldr r3, [r2, #0] c0d0141a: 1c5b adds r3, r3, #1 c0d0141c: 6013 str r3, [r2, #0] } // append the button mask button_mask = G_button_mask | new_button_mask; c0d0141e: 6806 ldr r6, [r0, #0] c0d01420: 430e orrs r6, r1 // pre reset variable due to os_sched_exit button_same_mask_counter = G_button_same_mask_counter; c0d01422: 4a13 ldr r2, [pc, #76] ; (c0d01470 <io_seproxyhal_button_push+0x6c>) c0d01424: 6815 ldr r5, [r2, #0] c0d01426: 4f13 ldr r7, [pc, #76] ; (c0d01474 <io_seproxyhal_button_push+0x70>) // reset button mask if (new_button_mask == 0) { c0d01428: 2900 cmp r1, #0 c0d0142a: d001 beq.n c0d01430 <io_seproxyhal_button_push+0x2c> // notify button released event button_mask |= BUTTON_EVT_RELEASED; } else { G_button_mask = button_mask; c0d0142c: 6006 str r6, [r0, #0] c0d0142e: e004 b.n c0d0143a <io_seproxyhal_button_push+0x36> c0d01430: 2300 movs r3, #0 button_same_mask_counter = G_button_same_mask_counter; // reset button mask if (new_button_mask == 0) { // reset next state when button are released G_button_mask = 0; c0d01432: 6003 str r3, [r0, #0] G_button_same_mask_counter=0; c0d01434: 6013 str r3, [r2, #0] // notify button released event button_mask |= BUTTON_EVT_RELEASED; c0d01436: 1c7b adds r3, r7, #1 c0d01438: 431e orrs r6, r3 else { G_button_mask = button_mask; } // reset counter when button mask changes if (new_button_mask != G_button_mask) { c0d0143a: 6800 ldr r0, [r0, #0] c0d0143c: 4288 cmp r0, r1 c0d0143e: d001 beq.n c0d01444 <io_seproxyhal_button_push+0x40> G_button_same_mask_counter=0; c0d01440: 2000 movs r0, #0 c0d01442: 6010 str r0, [r2, #0] } if (button_same_mask_counter >= BUTTON_FAST_THRESHOLD_CS) { c0d01444: 2d08 cmp r5, #8 c0d01446: d30b bcc.n c0d01460 <io_seproxyhal_button_push+0x5c> // fast bit when pressing and timing is right if ((button_same_mask_counter%BUTTON_FAST_ACTION_CS) == 0) { c0d01448: 2103 movs r1, #3 c0d0144a: 4628 mov r0, r5 c0d0144c: f002 fea2 bl c0d04194 <__aeabi_uidivmod> button_mask |= BUTTON_EVT_FAST; c0d01450: 2001 movs r0, #1 c0d01452: 0780 lsls r0, r0, #30 c0d01454: 4330 orrs r0, r6 G_button_same_mask_counter=0; } if (button_same_mask_counter >= BUTTON_FAST_THRESHOLD_CS) { // fast bit when pressing and timing is right if ((button_same_mask_counter%BUTTON_FAST_ACTION_CS) == 0) { c0d01456: 2900 cmp r1, #0 c0d01458: d000 beq.n c0d0145c <io_seproxyhal_button_push+0x58> c0d0145a: 4630 mov r0, r6 } */ // discard the release event after a fastskip has been detected, to avoid strange at release behavior // and also to enable user to cancel an operation by starting triggering the fast skip button_mask &= ~BUTTON_EVT_RELEASED; c0d0145c: 4038 ands r0, r7 c0d0145e: e000 b.n c0d01462 <io_seproxyhal_button_push+0x5e> c0d01460: 4630 mov r0, r6 } // indicate if button have been released button_callback(button_mask, button_same_mask_counter); c0d01462: 4629 mov r1, r5 c0d01464: 47a0 blx r4 } } c0d01466: b001 add sp, #4 c0d01468: bdf0 pop {r4, r5, r6, r7, pc} c0d0146a: 46c0 nop ; (mov r8, r8) c0d0146c: 20001a74 .word 0x20001a74 c0d01470: 20001a78 .word 0x20001a78 c0d01474: 7fffffff .word 0x7fffffff c0d01478 <os_io_seproxyhal_get_app_name_and_version>: #ifdef HAVE_IO_U2F u2f_service_t G_io_u2f; #endif // HAVE_IO_U2F unsigned int os_io_seproxyhal_get_app_name_and_version(void) __attribute__((weak)); unsigned int os_io_seproxyhal_get_app_name_and_version(void) { c0d01478: b5f0 push {r4, r5, r6, r7, lr} c0d0147a: b081 sub sp, #4 unsigned int tx_len, len; // build the get app name and version reply tx_len = 0; G_io_apdu_buffer[tx_len++] = 1; // format ID c0d0147c: 4e0f ldr r6, [pc, #60] ; (c0d014bc <os_io_seproxyhal_get_app_name_and_version+0x44>) c0d0147e: 2401 movs r4, #1 c0d01480: 7034 strb r4, [r6, #0] // append app name len = os_registry_get_current_app_tag(BOLOS_TAG_APPNAME, G_io_apdu_buffer+tx_len+1, sizeof(G_io_apdu_buffer)-tx_len); c0d01482: 1cb1 adds r1, r6, #2 c0d01484: 27ff movs r7, #255 ; 0xff c0d01486: 3750 adds r7, #80 ; 0x50 c0d01488: 1c7a adds r2, r7, #1 c0d0148a: 4620 mov r0, r4 c0d0148c: f000 fe8a bl c0d021a4 <os_registry_get_current_app_tag> c0d01490: 4605 mov r5, r0 G_io_apdu_buffer[tx_len++] = len; c0d01492: 7075 strb r5, [r6, #1] tx_len += len; // append app version len = os_registry_get_current_app_tag(BOLOS_TAG_APPVERSION, G_io_apdu_buffer+tx_len+1, sizeof(G_io_apdu_buffer)-tx_len); c0d01494: 1b7a subs r2, r7, r5 unsigned int os_io_seproxyhal_get_app_name_and_version(void) __attribute__((weak)); unsigned int os_io_seproxyhal_get_app_name_and_version(void) { unsigned int tx_len, len; // build the get app name and version reply tx_len = 0; G_io_apdu_buffer[tx_len++] = 1; // format ID c0d01496: 1977 adds r7, r6, r5 // append app name len = os_registry_get_current_app_tag(BOLOS_TAG_APPNAME, G_io_apdu_buffer+tx_len+1, sizeof(G_io_apdu_buffer)-tx_len); G_io_apdu_buffer[tx_len++] = len; tx_len += len; // append app version len = os_registry_get_current_app_tag(BOLOS_TAG_APPVERSION, G_io_apdu_buffer+tx_len+1, sizeof(G_io_apdu_buffer)-tx_len); c0d01498: 1cf9 adds r1, r7, #3 c0d0149a: 2002 movs r0, #2 c0d0149c: f000 fe82 bl c0d021a4 <os_registry_get_current_app_tag> G_io_apdu_buffer[tx_len++] = len; c0d014a0: 70b8 strb r0, [r7, #2] c0d014a2: 182d adds r5, r5, r0 unsigned int os_io_seproxyhal_get_app_name_and_version(void) __attribute__((weak)); unsigned int os_io_seproxyhal_get_app_name_and_version(void) { unsigned int tx_len, len; // build the get app name and version reply tx_len = 0; G_io_apdu_buffer[tx_len++] = 1; // format ID c0d014a4: 1976 adds r6, r6, r5 // append app version len = os_registry_get_current_app_tag(BOLOS_TAG_APPVERSION, G_io_apdu_buffer+tx_len+1, sizeof(G_io_apdu_buffer)-tx_len); G_io_apdu_buffer[tx_len++] = len; tx_len += len; // return OS flags to notify of platform's global state (pin lock etc) G_io_apdu_buffer[tx_len++] = 1; // flags length c0d014a6: 70f4 strb r4, [r6, #3] G_io_apdu_buffer[tx_len++] = os_flags(); c0d014a8: f000 fe66 bl c0d02178 <os_flags> c0d014ac: 7130 strb r0, [r6, #4] // status words G_io_apdu_buffer[tx_len++] = 0x90; c0d014ae: 2090 movs r0, #144 ; 0x90 c0d014b0: 7170 strb r0, [r6, #5] G_io_apdu_buffer[tx_len++] = 0x00; c0d014b2: 2000 movs r0, #0 c0d014b4: 71b0 strb r0, [r6, #6] c0d014b6: 1de8 adds r0, r5, #7 return tx_len; c0d014b8: b001 add sp, #4 c0d014ba: bdf0 pop {r4, r5, r6, r7, pc} c0d014bc: 200018f8 .word 0x200018f8 c0d014c0 <io_exchange>: } unsigned short io_exchange(unsigned char channel, unsigned short tx_len) { c0d014c0: b5f0 push {r4, r5, r6, r7, lr} c0d014c2: b087 sub sp, #28 c0d014c4: 4602 mov r2, r0 } after_debug: #endif // DEBUG_APDU reply_apdu: switch(channel&~(IO_FLAGS)) { c0d014c6: 2007 movs r0, #7 c0d014c8: 4202 tst r2, r0 c0d014ca: d006 beq.n c0d014da <io_exchange+0x1a> c0d014cc: 4616 mov r6, r2 } } break; default: return io_exchange_al(channel, tx_len); c0d014ce: b2f0 uxtb r0, r6 c0d014d0: f7fe fdfa bl c0d000c8 <io_exchange_al> } } c0d014d4: b280 uxth r0, r0 c0d014d6: b007 add sp, #28 c0d014d8: bdf0 pop {r4, r5, r6, r7, pc} c0d014da: 9003 str r0, [sp, #12] c0d014dc: 487f ldr r0, [pc, #508] ; (c0d016dc <io_exchange+0x21c>) goto reply_apdu; } // exit app after replied else if (os_memcmp(G_io_apdu_buffer, "\xB0\xA7\x00\x00", 4) == 0) { tx_len = 0; G_io_apdu_buffer[tx_len++] = 0x90; c0d014de: 9001 str r0, [sp, #4] c0d014e0: 2083 movs r0, #131 ; 0x83 c0d014e2: 9004 str r0, [sp, #16] c0d014e4: 4c7e ldr r4, [pc, #504] ; (c0d016e0 <io_exchange+0x220>) c0d014e6: 4d80 ldr r5, [pc, #512] ; (c0d016e8 <io_exchange+0x228>) c0d014e8: 4616 mov r6, r2 c0d014ea: e011 b.n c0d01510 <io_exchange+0x50> c0d014ec: 9804 ldr r0, [sp, #16] c0d014ee: 300d adds r0, #13 c0d014f0: 497e ldr r1, [pc, #504] ; (c0d016ec <io_exchange+0x22c>) c0d014f2: 7008 strb r0, [r1, #0] G_io_apdu_buffer[tx_len++] = 0x00; c0d014f4: 704f strb r7, [r1, #1] c0d014f6: 9a06 ldr r2, [sp, #24] // exit app after replied channel |= IO_RESET_AFTER_REPLIED; c0d014f8: 4316 orrs r6, r2 c0d014fa: 2102 movs r1, #2 } after_debug: #endif // DEBUG_APDU reply_apdu: switch(channel&~(IO_FLAGS)) { c0d014fc: 9803 ldr r0, [sp, #12] c0d014fe: 4202 tst r2, r0 c0d01500: 4632 mov r2, r6 c0d01502: d005 beq.n c0d01510 <io_exchange+0x50> c0d01504: e7e3 b.n c0d014ce <io_exchange+0xe> // an apdu has been received asynchroneously, return it if (G_io_apdu_state != APDU_IDLE && G_io_apdu_length > 0) { // handle reserved apdus // get name and version if (os_memcmp(G_io_apdu_buffer, "\xB0\x01\x00\x00", 4) == 0) { tx_len = os_io_seproxyhal_get_app_name_and_version(); c0d01506: f7ff ffb7 bl c0d01478 <os_io_seproxyhal_get_app_name_and_version> c0d0150a: 4601 mov r1, r0 c0d0150c: 463a mov r2, r7 c0d0150e: 463e mov r6, r7 reply_apdu: switch(channel&~(IO_FLAGS)) { case CHANNEL_APDU: // TODO work up the spi state machine over the HAL proxy until an APDU is available if (tx_len && !(channel&IO_ASYNCH_REPLY)) { c0d01510: 2310 movs r3, #16 c0d01512: 4013 ands r3, r2 c0d01514: b28f uxth r7, r1 c0d01516: 2f00 cmp r7, #0 c0d01518: 9206 str r2, [sp, #24] c0d0151a: d100 bne.n c0d0151e <io_exchange+0x5e> c0d0151c: e091 b.n c0d01642 <io_exchange+0x182> c0d0151e: 2b00 cmp r3, #0 c0d01520: d000 beq.n c0d01524 <io_exchange+0x64> c0d01522: e08e b.n c0d01642 <io_exchange+0x182> c0d01524: 7820 ldrb r0, [r4, #0] // until the whole RAPDU is transmitted, send chunks using the current mode for communication for (;;) { switch(G_io_apdu_state) { c0d01526: 2809 cmp r0, #9 c0d01528: 9305 str r3, [sp, #20] c0d0152a: dc3c bgt.n c0d015a6 <io_exchange+0xe6> c0d0152c: 2807 cmp r0, #7 c0d0152e: d041 beq.n c0d015b4 <io_exchange+0xf4> c0d01530: 2809 cmp r0, #9 c0d01532: d15b bne.n c0d015ec <io_exchange+0x12c> c0d01534: 2100 movs r1, #0 c0d01536: 4e6b ldr r6, [pc, #428] ; (c0d016e4 <io_exchange+0x224>) // case to handle U2F channels. u2f apdu to be dispatched in the upper layers case APDU_U2F: // prepare reply, the remaining segments will be pumped during USB/BLE events handling while waiting for the next APDU // the reply has been prepared by the application, stop sending anti timeouts u2f_message_set_autoreply_wait_user_presence(&G_io_u2f, false); c0d01538: 4630 mov r0, r6 c0d0153a: 9102 str r1, [sp, #8] c0d0153c: f001 fb4a bl c0d02bd4 <u2f_message_set_autoreply_wait_user_presence> // continue processing currently received command until completely received. while(!u2f_message_repliable(&G_io_u2f)) { c0d01540: 4630 mov r0, r6 c0d01542: f001 fb5a bl c0d02bfa <u2f_message_repliable> c0d01546: 2800 cmp r0, #0 c0d01548: d10d bne.n c0d01566 <io_exchange+0xa6> io_seproxyhal_general_status(); c0d0154a: f7ff fc75 bl c0d00e38 <io_seproxyhal_general_status> io_seproxyhal_spi_recv(G_io_seproxyhal_spi_buffer, sizeof(G_io_seproxyhal_spi_buffer), 0); c0d0154e: 2180 movs r1, #128 ; 0x80 c0d01550: 2200 movs r2, #0 c0d01552: 4628 mov r0, r5 c0d01554: f000 fe6a bl c0d0222c <io_seproxyhal_spi_recv> // if packet is not well formed, then too bad ... io_seproxyhal_handle_event(); c0d01558: f7ff fd58 bl c0d0100c <io_seproxyhal_handle_event> // the reply has been prepared by the application, stop sending anti timeouts u2f_message_set_autoreply_wait_user_presence(&G_io_u2f, false); // continue processing currently received command until completely received. while(!u2f_message_repliable(&G_io_u2f)) { c0d0155c: 4630 mov r0, r6 c0d0155e: f001 fb4c bl c0d02bfa <u2f_message_repliable> c0d01562: 2801 cmp r0, #1 c0d01564: d1f1 bne.n c0d0154a <io_exchange+0x8a> } #ifdef U2F_PROXY_MAGIC // user presence + counter + rapdu + sw must fit the apdu buffer if (1U+ 4U+ tx_len +2U > sizeof(G_io_apdu_buffer)) { c0d01566: 1dfe adds r6, r7, #7 c0d01568: 0870 lsrs r0, r6, #1 c0d0156a: 28a9 cmp r0, #169 ; 0xa9 c0d0156c: d300 bcc.n c0d01570 <io_exchange+0xb0> c0d0156e: e0b1 b.n c0d016d4 <io_exchange+0x214> THROW(INVALID_PARAMETER); } // u2F tunnel needs the status words to be included in the signature response BLOB, do it now. // always return 9000 in the signature to avoid error @ transport level in u2f layers. G_io_apdu_buffer[tx_len] = 0x90; //G_io_apdu_buffer[tx_len-2]; c0d01570: 9804 ldr r0, [sp, #16] c0d01572: 300d adds r0, #13 c0d01574: 495d ldr r1, [pc, #372] ; (c0d016ec <io_exchange+0x22c>) c0d01576: 55c8 strb r0, [r1, r7] c0d01578: 19c8 adds r0, r1, r7 G_io_apdu_buffer[tx_len+1] = 0x00; //G_io_apdu_buffer[tx_len-1]; c0d0157a: 9a02 ldr r2, [sp, #8] c0d0157c: 7042 strb r2, [r0, #1] tx_len += 2; os_memmove(G_io_apdu_buffer+5, G_io_apdu_buffer, tx_len); c0d0157e: 9801 ldr r0, [sp, #4] c0d01580: 1d00 adds r0, r0, #4 // u2F tunnel needs the status words to be included in the signature response BLOB, do it now. // always return 9000 in the signature to avoid error @ transport level in u2f layers. G_io_apdu_buffer[tx_len] = 0x90; //G_io_apdu_buffer[tx_len-2]; G_io_apdu_buffer[tx_len+1] = 0x00; //G_io_apdu_buffer[tx_len-1]; tx_len += 2; c0d01582: 1cba adds r2, r7, #2 os_memmove(G_io_apdu_buffer+5, G_io_apdu_buffer, tx_len); c0d01584: 4002 ands r2, r0 c0d01586: 1d48 adds r0, r1, #5 c0d01588: 460f mov r7, r1 c0d0158a: f7ff fb94 bl c0d00cb6 <os_memmove> c0d0158e: 2205 movs r2, #5 // zeroize user presence and counter os_memset(G_io_apdu_buffer, 0, 5); c0d01590: 4638 mov r0, r7 c0d01592: 9902 ldr r1, [sp, #8] c0d01594: f7ff fb86 bl c0d00ca4 <os_memset> u2f_message_reply(&G_io_u2f, U2F_CMD_MSG, G_io_apdu_buffer, tx_len+5); c0d01598: b2b3 uxth r3, r6 c0d0159a: 4852 ldr r0, [pc, #328] ; (c0d016e4 <io_exchange+0x224>) c0d0159c: 9904 ldr r1, [sp, #16] c0d0159e: 463a mov r2, r7 c0d015a0: f001 fb43 bl c0d02c2a <u2f_message_reply> c0d015a4: e034 b.n c0d01610 <io_exchange+0x150> c0d015a6: 280a cmp r0, #10 c0d015a8: d00a beq.n c0d015c0 <io_exchange+0x100> c0d015aa: 280b cmp r0, #11 c0d015ac: d120 bne.n c0d015f0 <io_exchange+0x130> io_usb_ccid_reply(G_io_apdu_buffer, tx_len); goto break_send; #endif // HAVE_USB_CLASS_CCID #ifdef HAVE_WEBUSB case APDU_USB_WEBUSB: io_usb_hid_send(io_usb_send_apdu_data_ep0x83, tx_len); c0d015ae: 4858 ldr r0, [pc, #352] ; (c0d01710 <io_exchange+0x250>) c0d015b0: 4478 add r0, pc c0d015b2: e001 b.n c0d015b8 <io_exchange+0xf8> goto break_send; #ifdef HAVE_USB_APDU case APDU_USB_HID: // only send, don't perform synchronous reception of the next command (will be done later by the seproxyhal packet processing) io_usb_hid_send(io_usb_send_apdu_data, tx_len); c0d015b4: 4855 ldr r0, [pc, #340] ; (c0d0170c <io_exchange+0x24c>) c0d015b6: 4478 add r0, pc c0d015b8: 4639 mov r1, r7 c0d015ba: f7ff fbff bl c0d00dbc <io_usb_hid_send> c0d015be: e027 b.n c0d01610 <io_exchange+0x150> LOG("invalid state for APDU reply\n"); THROW(INVALID_STATE); break; case APDU_RAW: if (tx_len > sizeof(G_io_apdu_buffer)) { c0d015c0: 484b ldr r0, [pc, #300] ; (c0d016f0 <io_exchange+0x230>) c0d015c2: 4008 ands r0, r1 c0d015c4: 0840 lsrs r0, r0, #1 c0d015c6: 28a9 cmp r0, #169 ; 0xa9 c0d015c8: d300 bcc.n c0d015cc <io_exchange+0x10c> c0d015ca: e083 b.n c0d016d4 <io_exchange+0x214> THROW(INVALID_PARAMETER); } // reply the RAW APDU over SEPROXYHAL protocol G_io_seproxyhal_spi_buffer[0] = SEPROXYHAL_TAG_RAPDU; c0d015cc: 2053 movs r0, #83 ; 0x53 c0d015ce: 7028 strb r0, [r5, #0] G_io_seproxyhal_spi_buffer[1] = (tx_len)>>8; c0d015d0: 0a38 lsrs r0, r7, #8 c0d015d2: 7068 strb r0, [r5, #1] G_io_seproxyhal_spi_buffer[2] = (tx_len); c0d015d4: 70a9 strb r1, [r5, #2] io_seproxyhal_spi_send(G_io_seproxyhal_spi_buffer, 3); c0d015d6: 2103 movs r1, #3 c0d015d8: 4628 mov r0, r5 c0d015da: f000 fdfb bl c0d021d4 <io_seproxyhal_spi_send> io_seproxyhal_spi_send(G_io_apdu_buffer, tx_len); c0d015de: 4843 ldr r0, [pc, #268] ; (c0d016ec <io_exchange+0x22c>) c0d015e0: 4639 mov r1, r7 c0d015e2: f000 fdf7 bl c0d021d4 <io_seproxyhal_spi_send> // isngle packet reply, mark immediate idle G_io_apdu_state = APDU_IDLE; c0d015e6: 2000 movs r0, #0 c0d015e8: 7020 strb r0, [r4, #0] c0d015ea: e011 b.n c0d01610 <io_exchange+0x150> c0d015ec: 2800 cmp r0, #0 c0d015ee: d06e beq.n c0d016ce <io_exchange+0x20e> // until the whole RAPDU is transmitted, send chunks using the current mode for communication for (;;) { switch(G_io_apdu_state) { default: // delegate to the hal in case of not generic transport mode (or asynch) if (io_exchange_al(channel, tx_len) == 0) { c0d015f0: b2f0 uxtb r0, r6 c0d015f2: 4639 mov r1, r7 c0d015f4: f7fe fd68 bl c0d000c8 <io_exchange_al> c0d015f8: 2800 cmp r0, #0 c0d015fa: d009 beq.n c0d01610 <io_exchange+0x150> c0d015fc: e067 b.n c0d016ce <io_exchange+0x20e> // wait end of reply transmission while (G_io_apdu_state != APDU_IDLE) { #ifdef HAVE_TINY_COROUTINE tcr_yield(); #else // HAVE_TINY_COROUTINE io_seproxyhal_general_status(); c0d015fe: f7ff fc1b bl c0d00e38 <io_seproxyhal_general_status> io_seproxyhal_spi_recv(G_io_seproxyhal_spi_buffer, sizeof(G_io_seproxyhal_spi_buffer), 0); c0d01602: 2180 movs r1, #128 ; 0x80 c0d01604: 2200 movs r2, #0 c0d01606: 4628 mov r0, r5 c0d01608: f000 fe10 bl c0d0222c <io_seproxyhal_spi_recv> // if packet is not well formed, then too bad ... io_seproxyhal_handle_event(); c0d0160c: f7ff fcfe bl c0d0100c <io_seproxyhal_handle_event> c0d01610: 7820 ldrb r0, [r4, #0] c0d01612: 2800 cmp r0, #0 c0d01614: d1f3 bne.n c0d015fe <io_exchange+0x13e> c0d01616: 2000 movs r0, #0 #endif // HAVE_TINY_COROUTINE } // reset apdu state G_io_apdu_state = APDU_IDLE; c0d01618: 7020 strb r0, [r4, #0] G_io_apdu_media = IO_APDU_MEDIA_NONE; c0d0161a: 4936 ldr r1, [pc, #216] ; (c0d016f4 <io_exchange+0x234>) c0d0161c: 7008 strb r0, [r1, #0] G_io_apdu_length = 0; c0d0161e: 4936 ldr r1, [pc, #216] ; (c0d016f8 <io_exchange+0x238>) c0d01620: 8008 strh r0, [r1, #0] // continue sending commands, don't issue status yet if (channel & IO_RETURN_AFTER_TX) { c0d01622: 9906 ldr r1, [sp, #24] c0d01624: 0689 lsls r1, r1, #26 c0d01626: d500 bpl.n c0d0162a <io_exchange+0x16a> c0d01628: e754 b.n c0d014d4 <io_exchange+0x14> return 0; } // acknowledge the write request (general status OK) and no more command to follow (wait until another APDU container is received to continue unwrapping) io_seproxyhal_general_status(); c0d0162a: f7ff fc05 bl c0d00e38 <io_seproxyhal_general_status> c0d0162e: 9a06 ldr r2, [sp, #24] break; } // perform reset after io exchange if (channel & IO_RESET_AFTER_REPLIED) { c0d01630: 0610 lsls r0, r2, #24 c0d01632: 9b05 ldr r3, [sp, #20] c0d01634: d505 bpl.n c0d01642 <io_exchange+0x182> os_sched_exit(1); c0d01636: 2001 movs r0, #1 c0d01638: 461e mov r6, r3 c0d0163a: f000 fd71 bl c0d02120 <os_sched_exit> c0d0163e: 4633 mov r3, r6 c0d01640: 9a06 ldr r2, [sp, #24] //reset(); } } #ifndef HAVE_TINY_COROUTINE if (!(channel&IO_ASYNCH_REPLY)) { c0d01642: 2b00 cmp r3, #0 c0d01644: d105 bne.n c0d01652 <io_exchange+0x192> // already received the data of the apdu when received the whole apdu if ((channel & (CHANNEL_APDU|IO_RECEIVE_DATA)) == (CHANNEL_APDU|IO_RECEIVE_DATA)) { c0d01646: 0650 lsls r0, r2, #25 c0d01648: d43c bmi.n c0d016c4 <io_exchange+0x204> // return apdu data - header return G_io_apdu_length-5; } // reply has ended, proceed to next apdu reception (reset status only after asynch reply) G_io_apdu_state = APDU_IDLE; c0d0164a: 2000 movs r0, #0 c0d0164c: 7020 strb r0, [r4, #0] G_io_apdu_media = IO_APDU_MEDIA_NONE; c0d0164e: 4929 ldr r1, [pc, #164] ; (c0d016f4 <io_exchange+0x234>) c0d01650: 7008 strb r0, [r1, #0] } #endif // HAVE_TINY_COROUTINE // reset the received apdu length G_io_apdu_length = 0; c0d01652: 2000 movs r0, #0 c0d01654: 4928 ldr r1, [pc, #160] ; (c0d016f8 <io_exchange+0x238>) c0d01656: 8008 strh r0, [r1, #0] #ifdef HAVE_TINY_COROUTINE // give back hand to the seph task which interprets all incoming events first tcr_yield(); #else // HAVE_TINY_COROUTINE if (!io_seproxyhal_spi_is_status_sent()) { c0d01658: f000 fdd2 bl c0d02200 <io_seproxyhal_spi_is_status_sent> c0d0165c: 2800 cmp r0, #0 c0d0165e: d101 bne.n c0d01664 <io_exchange+0x1a4> io_seproxyhal_general_status(); c0d01660: f7ff fbea bl c0d00e38 <io_seproxyhal_general_status> } // wait until a SPI packet is available // NOTE: on ST31, dual wait ISO & RF (ISO instead of SPI) rx_len = io_seproxyhal_spi_recv(G_io_seproxyhal_spi_buffer, sizeof(G_io_seproxyhal_spi_buffer), 0); c0d01664: 2680 movs r6, #128 ; 0x80 c0d01666: 2700 movs r7, #0 c0d01668: 4628 mov r0, r5 c0d0166a: 4631 mov r1, r6 c0d0166c: 463a mov r2, r7 c0d0166e: f000 fddd bl c0d0222c <io_seproxyhal_spi_recv> // can't process split TLV, continue if (rx_len < 3 && rx_len-3 != U2(G_io_seproxyhal_spi_buffer[1],G_io_seproxyhal_spi_buffer[2])) { c0d01672: 2802 cmp r0, #2 c0d01674: d806 bhi.n c0d01684 <io_exchange+0x1c4> c0d01676: 78a9 ldrb r1, [r5, #2] c0d01678: 786a ldrb r2, [r5, #1] c0d0167a: 0212 lsls r2, r2, #8 c0d0167c: 430a orrs r2, r1 c0d0167e: 1ec0 subs r0, r0, #3 c0d01680: 4290 cmp r0, r2 c0d01682: d109 bne.n c0d01698 <io_exchange+0x1d8> G_io_apdu_state = APDU_IDLE; G_io_apdu_length = 0; continue; } io_seproxyhal_handle_event(); c0d01684: f7ff fcc2 bl c0d0100c <io_seproxyhal_handle_event> #endif // HAVE_TINY_COROUTINE // an apdu has been received asynchroneously, return it if (G_io_apdu_state != APDU_IDLE && G_io_apdu_length > 0) { c0d01688: 7820 ldrb r0, [r4, #0] c0d0168a: 2800 cmp r0, #0 c0d0168c: d0e4 beq.n c0d01658 <io_exchange+0x198> c0d0168e: 481a ldr r0, [pc, #104] ; (c0d016f8 <io_exchange+0x238>) c0d01690: 8800 ldrh r0, [r0, #0] c0d01692: 2800 cmp r0, #0 c0d01694: d0e0 beq.n c0d01658 <io_exchange+0x198> c0d01696: e002 b.n c0d0169e <io_exchange+0x1de> c0d01698: 2000 movs r0, #0 rx_len = io_seproxyhal_spi_recv(G_io_seproxyhal_spi_buffer, sizeof(G_io_seproxyhal_spi_buffer), 0); // can't process split TLV, continue if (rx_len < 3 && rx_len-3 != U2(G_io_seproxyhal_spi_buffer[1],G_io_seproxyhal_spi_buffer[2])) { LOG("invalid TLV format\n"); G_io_apdu_state = APDU_IDLE; c0d0169a: 7020 strb r0, [r4, #0] c0d0169c: e7da b.n c0d01654 <io_exchange+0x194> // an apdu has been received asynchroneously, return it if (G_io_apdu_state != APDU_IDLE && G_io_apdu_length > 0) { // handle reserved apdus // get name and version if (os_memcmp(G_io_apdu_buffer, "\xB0\x01\x00\x00", 4) == 0) { c0d0169e: 2204 movs r2, #4 c0d016a0: 4812 ldr r0, [pc, #72] ; (c0d016ec <io_exchange+0x22c>) c0d016a2: a116 add r1, pc, #88 ; (adr r1, c0d016fc <io_exchange+0x23c>) c0d016a4: f7ff fba4 bl c0d00df0 <os_memcmp> c0d016a8: 2800 cmp r0, #0 c0d016aa: d100 bne.n c0d016ae <io_exchange+0x1ee> c0d016ac: e72b b.n c0d01506 <io_exchange+0x46> // disable 'return after tx' and 'asynch reply' flags channel &= ~IO_FLAGS; goto reply_apdu; } // exit app after replied else if (os_memcmp(G_io_apdu_buffer, "\xB0\xA7\x00\x00", 4) == 0) { c0d016ae: 2204 movs r2, #4 c0d016b0: 480e ldr r0, [pc, #56] ; (c0d016ec <io_exchange+0x22c>) c0d016b2: a114 add r1, pc, #80 ; (adr r1, c0d01704 <io_exchange+0x244>) c0d016b4: f7ff fb9c bl c0d00df0 <os_memcmp> c0d016b8: 2800 cmp r0, #0 c0d016ba: d100 bne.n c0d016be <io_exchange+0x1fe> c0d016bc: e716 b.n c0d014ec <io_exchange+0x2c> // disable 'return after tx' and 'asynch reply' flags channel &= ~IO_FLAGS; goto reply_apdu; } #endif // HAVE_BOLOS_WITH_VIRGIN_ATTESTATION return G_io_apdu_length; c0d016be: 480e ldr r0, [pc, #56] ; (c0d016f8 <io_exchange+0x238>) c0d016c0: 8800 ldrh r0, [r0, #0] c0d016c2: e707 b.n c0d014d4 <io_exchange+0x14> if (!(channel&IO_ASYNCH_REPLY)) { // already received the data of the apdu when received the whole apdu if ((channel & (CHANNEL_APDU|IO_RECEIVE_DATA)) == (CHANNEL_APDU|IO_RECEIVE_DATA)) { // return apdu data - header return G_io_apdu_length-5; c0d016c4: 480c ldr r0, [pc, #48] ; (c0d016f8 <io_exchange+0x238>) c0d016c6: 8800 ldrh r0, [r0, #0] c0d016c8: 9901 ldr r1, [sp, #4] c0d016ca: 1840 adds r0, r0, r1 c0d016cc: e702 b.n c0d014d4 <io_exchange+0x14> if (io_exchange_al(channel, tx_len) == 0) { goto break_send; } case APDU_IDLE: LOG("invalid state for APDU reply\n"); THROW(INVALID_STATE); c0d016ce: 2009 movs r0, #9 c0d016d0: f7ff fba5 bl c0d00e1e <os_longjmp> c0d016d4: 2002 movs r0, #2 c0d016d6: f7ff fba2 bl c0d00e1e <os_longjmp> c0d016da: 46c0 nop ; (mov r8, r8) c0d016dc: 0000fffb .word 0x0000fffb c0d016e0: 20001a6a .word 0x20001a6a c0d016e4: 20001a7c .word 0x20001a7c c0d016e8: 20001800 .word 0x20001800 c0d016ec: 200018f8 .word 0x200018f8 c0d016f0: 0000fffe .word 0x0000fffe c0d016f4: 20001a54 .word 0x20001a54 c0d016f8: 20001a6c .word 0x20001a6c c0d016fc: 000001b0 .word 0x000001b0 c0d01700: 00000000 .word 0x00000000 c0d01704: 0000a7b0 .word 0x0000a7b0 c0d01708: 00000000 .word 0x00000000 c0d0170c: fffff9e7 .word 0xfffff9e7 c0d01710: fffff9fd .word 0xfffff9fd c0d01714 <screen_printc>: return ret; } // so unoptimized void screen_printc(unsigned char c) { c0d01714: b5b0 push {r4, r5, r7, lr} c0d01716: b082 sub sp, #8 c0d01718: ac01 add r4, sp, #4 unsigned char buf[4]; buf[0] = SEPROXYHAL_TAG_PRINTF_STATUS; c0d0171a: 2166 movs r1, #102 ; 0x66 c0d0171c: 7021 strb r1, [r4, #0] c0d0171e: 2500 movs r5, #0 buf[1] = 0; c0d01720: 7065 strb r5, [r4, #1] c0d01722: 2101 movs r1, #1 buf[2] = 1; c0d01724: 70a1 strb r1, [r4, #2] buf[3] = c; c0d01726: 70e0 strb r0, [r4, #3] io_seproxyhal_spi_send(buf, 4); c0d01728: 2104 movs r1, #4 c0d0172a: 4620 mov r0, r4 c0d0172c: f000 fd52 bl c0d021d4 <io_seproxyhal_spi_send> c0d01730: 2103 movs r1, #3 #ifndef IO_SEPROXYHAL_DEBUG // wait printf ack (no race kthx) io_seproxyhal_spi_recv(buf, 3, 0); c0d01732: 4620 mov r0, r4 c0d01734: 462a mov r2, r5 c0d01736: f000 fd79 bl c0d0222c <io_seproxyhal_spi_recv> buf[0] = 0; // consume tag to avoid misinterpretation (due to IO_CACHE) #endif // IO_SEPROXYHAL_DEBUG } c0d0173a: b002 add sp, #8 c0d0173c: bdb0 pop {r4, r5, r7, pc} c0d0173e <ux_check_status_default>: } void ux_check_status_default(unsigned int status) { // nothing to be done here by default. UNUSED(status); } c0d0173e: 4770 bx lr c0d01740 <screen_printf>: * - screen_prints * - screen_printc */ void screen_printf(const char* format, ...) { c0d01740: b083 sub sp, #12 c0d01742: b5f0 push {r4, r5, r6, r7, lr} c0d01744: b08c sub sp, #48 ; 0x30 c0d01746: 4604 mov r4, r0 c0d01748: a811 add r0, sp, #68 ; 0x44 c0d0174a: c00e stmia r0!, {r1, r2, r3} char cStrlenSet; // // Check the arguments. // if(format == 0) { c0d0174c: 2c00 cmp r4, #0 c0d0174e: d100 bne.n c0d01752 <screen_printf+0x12> c0d01750: e18d b.n c0d01a6e <screen_printf+0x32e> c0d01752: a811 add r0, sp, #68 ; 0x44 } // // Start the varargs processing. // va_start(vaArgP, format); c0d01754: 9007 str r0, [sp, #28] c0d01756: e186 b.n c0d01a66 <screen_printf+0x326> c0d01758: 4625 mov r5, r4 c0d0175a: 2600 movs r6, #0 while(*format) { // // Find the first non-% character, or the end of the string. // for(ulIdx = 0; (format[ulIdx] != '%') && (format[ulIdx] != '\0'); c0d0175c: 4601 mov r1, r0 c0d0175e: e002 b.n c0d01766 <screen_printf+0x26> c0d01760: 19a9 adds r1, r5, r6 c0d01762: 7849 ldrb r1, [r1, #1] ulIdx++) c0d01764: 1c76 adds r6, r6, #1 c0d01766: b2ca uxtb r2, r1 while(*format) { // // Find the first non-% character, or the end of the string. // for(ulIdx = 0; (format[ulIdx] != '%') && (format[ulIdx] != '\0'); c0d01768: 2a00 cmp r2, #0 c0d0176a: d001 beq.n c0d01770 <screen_printf+0x30> c0d0176c: 2a25 cmp r2, #37 ; 0x25 c0d0176e: d1f7 bne.n c0d01760 <screen_printf+0x20> #ifdef HAVE_PRINTF #ifndef BOLOS_RELEASE void screen_prints(const char* str, unsigned int charcount) { while(charcount--) { c0d01770: 19ac adds r4, r5, r6 c0d01772: 2e00 cmp r6, #0 c0d01774: d00c beq.n c0d01790 <screen_printf+0x50> screen_printc(*str++); c0d01776: b2c0 uxtb r0, r0 c0d01778: f7ff ffcc bl c0d01714 <screen_printc> #ifdef HAVE_PRINTF #ifndef BOLOS_RELEASE void screen_prints(const char* str, unsigned int charcount) { while(charcount--) { c0d0177c: 2e01 cmp r6, #1 c0d0177e: d006 beq.n c0d0178e <screen_printf+0x4e> c0d01780: 2701 movs r7, #1 screen_printc(*str++); c0d01782: 5de8 ldrb r0, [r5, r7] c0d01784: f7ff ffc6 bl c0d01714 <screen_printc> #ifdef HAVE_PRINTF #ifndef BOLOS_RELEASE void screen_prints(const char* str, unsigned int charcount) { while(charcount--) { c0d01788: 1c7f adds r7, r7, #1 c0d0178a: 42b7 cmp r7, r6 c0d0178c: d1f9 bne.n c0d01782 <screen_printf+0x42> c0d0178e: 7821 ldrb r1, [r4, #0] format += ulIdx; // // See if the next character is a %. // if(*format == '%') c0d01790: b2c8 uxtb r0, r1 c0d01792: 2825 cmp r0, #37 ; 0x25 c0d01794: d000 beq.n c0d01798 <screen_printf+0x58> c0d01796: e166 b.n c0d01a66 <screen_printf+0x326> ulCount = 0; cFill = ' '; ulStrlen = 0; cStrlenSet = 0; ulCap = 0; ulBase = 10; c0d01798: 19a8 adds r0, r5, r6 c0d0179a: 1c43 adds r3, r0, #1 c0d0179c: 2100 movs r1, #0 c0d0179e: 2020 movs r0, #32 c0d017a0: 9004 str r0, [sp, #16] c0d017a2: 200a movs r0, #10 c0d017a4: 9106 str r1, [sp, #24] c0d017a6: 9103 str r1, [sp, #12] c0d017a8: 9105 str r1, [sp, #20] c0d017aa: 2204 movs r2, #4 c0d017ac: 43d5 mvns r5, r2 c0d017ae: 2202 movs r2, #2 c0d017b0: 461c mov r4, r3 again: // // Determine how to handle the next character. // switch(*format++) c0d017b2: 7823 ldrb r3, [r4, #0] c0d017b4: 1c64 adds r4, r4, #1 c0d017b6: 2700 movs r7, #0 c0d017b8: 2b2d cmp r3, #45 ; 0x2d c0d017ba: dc0d bgt.n c0d017d8 <screen_printf+0x98> c0d017bc: 4639 mov r1, r7 c0d017be: d0f8 beq.n c0d017b2 <screen_printf+0x72> c0d017c0: 2b25 cmp r3, #37 ; 0x25 c0d017c2: d07f beq.n c0d018c4 <screen_printf+0x184> c0d017c4: 2b2a cmp r3, #42 ; 0x2a c0d017c6: d000 beq.n c0d017ca <screen_printf+0x8a> c0d017c8: e0fa b.n c0d019c0 <screen_printf+0x280> goto error; } case '*': { if (*format == 's' ) { c0d017ca: 7821 ldrb r1, [r4, #0] c0d017cc: 2973 cmp r1, #115 ; 0x73 c0d017ce: d000 beq.n c0d017d2 <screen_printf+0x92> c0d017d0: e0f6 b.n c0d019c0 <screen_printf+0x280> c0d017d2: 4611 mov r1, r2 c0d017d4: 4623 mov r3, r4 c0d017d6: e04b b.n c0d01870 <screen_printf+0x130> c0d017d8: 2b47 cmp r3, #71 ; 0x47 c0d017da: dc14 bgt.n c0d01806 <screen_printf+0xc6> c0d017dc: 461a mov r2, r3 c0d017de: 3a30 subs r2, #48 ; 0x30 c0d017e0: 2a0a cmp r2, #10 c0d017e2: d234 bcs.n c0d0184e <screen_printf+0x10e> { // // If this is a zero, and it is the first digit, then the // fill character is a zero instead of a space. // if((format[-1] == '0') && (ulCount == 0)) c0d017e4: 2b30 cmp r3, #48 ; 0x30 c0d017e6: 9d04 ldr r5, [sp, #16] c0d017e8: 462a mov r2, r5 c0d017ea: d100 bne.n c0d017ee <screen_printf+0xae> c0d017ec: 461a mov r2, r3 c0d017ee: 9f05 ldr r7, [sp, #20] c0d017f0: 2f00 cmp r7, #0 c0d017f2: d000 beq.n c0d017f6 <screen_printf+0xb6> c0d017f4: 462a mov r2, r5 } // // Update the digit count. // ulCount *= 10; c0d017f6: 250a movs r5, #10 c0d017f8: 437d muls r5, r7 ulCount += format[-1] - '0'; c0d017fa: 18eb adds r3, r5, r3 c0d017fc: 3b30 subs r3, #48 ; 0x30 c0d017fe: 9305 str r3, [sp, #20] c0d01800: 9204 str r2, [sp, #16] c0d01802: 4623 mov r3, r4 c0d01804: e7d1 b.n c0d017aa <screen_printf+0x6a> c0d01806: 2b67 cmp r3, #103 ; 0x67 c0d01808: dd04 ble.n c0d01814 <screen_printf+0xd4> c0d0180a: 2b72 cmp r3, #114 ; 0x72 c0d0180c: dd08 ble.n c0d01820 <screen_printf+0xe0> c0d0180e: 2b73 cmp r3, #115 ; 0x73 c0d01810: d134 bne.n c0d0187c <screen_printf+0x13c> c0d01812: e00a b.n c0d0182a <screen_printf+0xea> c0d01814: 2b62 cmp r3, #98 ; 0x62 c0d01816: dc36 bgt.n c0d01886 <screen_printf+0x146> c0d01818: 2b48 cmp r3, #72 ; 0x48 c0d0181a: d143 bne.n c0d018a4 <screen_printf+0x164> c0d0181c: 2001 movs r0, #1 c0d0181e: e002 b.n c0d01826 <screen_printf+0xe6> c0d01820: 2b68 cmp r3, #104 ; 0x68 c0d01822: d145 bne.n c0d018b0 <screen_printf+0x170> c0d01824: 2000 movs r0, #0 c0d01826: 9003 str r0, [sp, #12] c0d01828: 2010 movs r0, #16 case_s: { // // Get the string pointer from the varargs. // pcStr = va_arg(vaArgP, char *); c0d0182a: 9b07 ldr r3, [sp, #28] c0d0182c: 1d1f adds r7, r3, #4 c0d0182e: 9707 str r7, [sp, #28] c0d01830: 2703 movs r7, #3 c0d01832: 4039 ands r1, r7 c0d01834: 1c52 adds r2, r2, #1 c0d01836: 681f ldr r7, [r3, #0] // // Determine the length of the string. (if not specified using .*) // switch(cStrlenSet) { c0d01838: 2901 cmp r1, #1 c0d0183a: d100 bne.n c0d0183e <screen_printf+0xfe> c0d0183c: e0bb b.n c0d019b6 <screen_printf+0x276> c0d0183e: 2902 cmp r1, #2 c0d01840: d100 bne.n c0d01844 <screen_printf+0x104> c0d01842: e0ba b.n c0d019ba <screen_printf+0x27a> c0d01844: 2903 cmp r1, #3 c0d01846: 4611 mov r1, r2 c0d01848: 4623 mov r3, r4 c0d0184a: d0ae beq.n c0d017aa <screen_printf+0x6a> c0d0184c: e0c1 b.n c0d019d2 <screen_printf+0x292> c0d0184e: 2b2e cmp r3, #46 ; 0x2e c0d01850: d000 beq.n c0d01854 <screen_printf+0x114> c0d01852: e0b5 b.n c0d019c0 <screen_printf+0x280> // special %.*H or %.*h format to print a given length of hex digits (case: H UPPER, h lower) // case '.': { // ensure next char is '*' and next one is 's' if (format[0] == '*' && (format[1] == 's' || format[1] == 'H' || format[1] == 'h')) { c0d01854: 7821 ldrb r1, [r4, #0] c0d01856: 292a cmp r1, #42 ; 0x2a c0d01858: d000 beq.n c0d0185c <screen_printf+0x11c> c0d0185a: e0b1 b.n c0d019c0 <screen_printf+0x280> c0d0185c: 7862 ldrb r2, [r4, #1] c0d0185e: 1c63 adds r3, r4, #1 c0d01860: 2101 movs r1, #1 c0d01862: 2a48 cmp r2, #72 ; 0x48 c0d01864: d004 beq.n c0d01870 <screen_printf+0x130> c0d01866: 2a68 cmp r2, #104 ; 0x68 c0d01868: d002 beq.n c0d01870 <screen_printf+0x130> c0d0186a: 2a73 cmp r2, #115 ; 0x73 c0d0186c: d000 beq.n c0d01870 <screen_printf+0x130> c0d0186e: e0a7 b.n c0d019c0 <screen_printf+0x280> c0d01870: 9a07 ldr r2, [sp, #28] c0d01872: 1d14 adds r4, r2, #4 c0d01874: 9407 str r4, [sp, #28] c0d01876: 6812 ldr r2, [r2, #0] * - screen_prints * - screen_printc */ void screen_printf(const char* format, ...) { c0d01878: 9206 str r2, [sp, #24] c0d0187a: e796 b.n c0d017aa <screen_printf+0x6a> c0d0187c: 2b75 cmp r3, #117 ; 0x75 c0d0187e: d023 beq.n c0d018c8 <screen_printf+0x188> c0d01880: 2b78 cmp r3, #120 ; 0x78 c0d01882: d018 beq.n c0d018b6 <screen_printf+0x176> c0d01884: e09c b.n c0d019c0 <screen_printf+0x280> c0d01886: 2b63 cmp r3, #99 ; 0x63 c0d01888: d100 bne.n c0d0188c <screen_printf+0x14c> c0d0188a: e08d b.n c0d019a8 <screen_printf+0x268> c0d0188c: 2b64 cmp r3, #100 ; 0x64 c0d0188e: d000 beq.n c0d01892 <screen_printf+0x152> c0d01890: e096 b.n c0d019c0 <screen_printf+0x280> case 'd': { // // Get the value from the varargs. // ulValue = va_arg(vaArgP, unsigned long); c0d01892: 9807 ldr r0, [sp, #28] c0d01894: 1d01 adds r1, r0, #4 c0d01896: 9107 str r1, [sp, #28] c0d01898: 6800 ldr r0, [r0, #0] c0d0189a: 17c1 asrs r1, r0, #31 c0d0189c: 1842 adds r2, r0, r1 c0d0189e: 404a eors r2, r1 // // If the value is negative, make it positive and indicate // that a minus sign is needed. // if((long)ulValue < 0) c0d018a0: 0fc0 lsrs r0, r0, #31 c0d018a2: e016 b.n c0d018d2 <screen_printf+0x192> c0d018a4: 2b58 cmp r3, #88 ; 0x58 c0d018a6: d000 beq.n c0d018aa <screen_printf+0x16a> c0d018a8: e08a b.n c0d019c0 <screen_printf+0x280> c0d018aa: 2001 movs r0, #1 screen_printc(str[i]); } */ unsigned long ulIdx, ulValue, ulPos, ulCount, ulBase, ulNeg, ulStrlen, ulCap; c0d018ac: 9003 str r0, [sp, #12] c0d018ae: e002 b.n c0d018b6 <screen_printf+0x176> c0d018b0: 2b70 cmp r3, #112 ; 0x70 c0d018b2: d000 beq.n c0d018b6 <screen_printf+0x176> c0d018b4: e084 b.n c0d019c0 <screen_printf+0x280> case 'p': { // // Get the value from the varargs. // ulValue = va_arg(vaArgP, unsigned long); c0d018b6: 9807 ldr r0, [sp, #28] c0d018b8: 1d01 adds r1, r0, #4 c0d018ba: 9107 str r1, [sp, #28] c0d018bc: 6802 ldr r2, [r0, #0] c0d018be: 2000 movs r0, #0 c0d018c0: 2610 movs r6, #16 c0d018c2: e007 b.n c0d018d4 <screen_printf+0x194> #ifdef HAVE_PRINTF #ifndef BOLOS_RELEASE void screen_prints(const char* str, unsigned int charcount) { while(charcount--) { screen_printc(*str++); c0d018c4: 2025 movs r0, #37 ; 0x25 c0d018c6: e073 b.n c0d019b0 <screen_printf+0x270> case 'u': { // // Get the value from the varargs. // ulValue = va_arg(vaArgP, unsigned long); c0d018c8: 9807 ldr r0, [sp, #28] c0d018ca: 1d01 adds r1, r0, #4 c0d018cc: 9107 str r1, [sp, #28] c0d018ce: 6802 ldr r2, [r0, #0] c0d018d0: 2000 movs r0, #0 c0d018d2: 260a movs r6, #10 c0d018d4: 9002 str r0, [sp, #8] c0d018d6: 2701 movs r7, #1 c0d018d8: 9206 str r2, [sp, #24] // Determine the number of digits in the string version of // the value. // convert: for(ulIdx = 1; (((ulIdx * ulBase) <= ulValue) && c0d018da: 4296 cmp r6, r2 c0d018dc: d812 bhi.n c0d01904 <screen_printf+0x1c4> c0d018de: 2501 movs r5, #1 c0d018e0: 4630 mov r0, r6 c0d018e2: 4607 mov r7, r0 (((ulIdx * ulBase) / ulBase) == ulIdx)); c0d018e4: 4631 mov r1, r6 c0d018e6: f002 fbcf bl c0d04088 <__aeabi_uidiv> // // Determine the number of digits in the string version of // the value. // convert: for(ulIdx = 1; c0d018ea: 42a8 cmp r0, r5 c0d018ec: d109 bne.n c0d01902 <screen_printf+0x1c2> (((ulIdx * ulBase) <= ulValue) && c0d018ee: 4630 mov r0, r6 c0d018f0: 4378 muls r0, r7 (((ulIdx * ulBase) / ulBase) == ulIdx)); ulIdx *= ulBase, ulCount--) c0d018f2: 9905 ldr r1, [sp, #20] c0d018f4: 1e49 subs r1, r1, #1 // Determine the number of digits in the string version of // the value. // convert: for(ulIdx = 1; (((ulIdx * ulBase) <= ulValue) && c0d018f6: 9105 str r1, [sp, #20] c0d018f8: 9906 ldr r1, [sp, #24] c0d018fa: 4288 cmp r0, r1 c0d018fc: 463d mov r5, r7 c0d018fe: d9f0 bls.n c0d018e2 <screen_printf+0x1a2> c0d01900: e000 b.n c0d01904 <screen_printf+0x1c4> c0d01902: 462f mov r7, r5 // // If the value is negative, reduce the count of padding // characters needed. // if(ulNeg) c0d01904: 2500 movs r5, #0 c0d01906: 43e9 mvns r1, r5 c0d01908: 9b02 ldr r3, [sp, #8] c0d0190a: 2b00 cmp r3, #0 c0d0190c: d100 bne.n c0d01910 <screen_printf+0x1d0> c0d0190e: 4619 mov r1, r3 c0d01910: 9805 ldr r0, [sp, #20] c0d01912: 9101 str r1, [sp, #4] c0d01914: 1840 adds r0, r0, r1 // // If the value is negative and the value is padded with // zeros, then place the minus sign before the padding. // if(ulNeg && (cFill == '0')) c0d01916: 9904 ldr r1, [sp, #16] c0d01918: b2ca uxtb r2, r1 c0d0191a: 2a30 cmp r2, #48 ; 0x30 c0d0191c: d106 bne.n c0d0192c <screen_printf+0x1ec> c0d0191e: 2b00 cmp r3, #0 c0d01920: d004 beq.n c0d0192c <screen_printf+0x1ec> c0d01922: a908 add r1, sp, #32 { // // Place the minus sign in the output buffer. // pcBuf[ulPos++] = '-'; c0d01924: 232d movs r3, #45 ; 0x2d c0d01926: 700b strb r3, [r1, #0] c0d01928: 2501 movs r5, #1 c0d0192a: 2300 movs r3, #0 // // Provide additional padding at the beginning of the // string conversion if needed. // if((ulCount > 1) && (ulCount < 16)) c0d0192c: 1e81 subs r1, r0, #2 c0d0192e: 290d cmp r1, #13 c0d01930: d80c bhi.n c0d0194c <screen_printf+0x20c> c0d01932: 1e41 subs r1, r0, #1 c0d01934: d00a beq.n c0d0194c <screen_printf+0x20c> c0d01936: a808 add r0, sp, #32 { for(ulCount--; ulCount; ulCount--) { pcBuf[ulPos++] = cFill; c0d01938: 4328 orrs r0, r5 c0d0193a: 9302 str r3, [sp, #8] c0d0193c: f002 fc3a bl c0d041b4 <__aeabi_memset> c0d01940: 9b02 ldr r3, [sp, #8] c0d01942: 9805 ldr r0, [sp, #20] c0d01944: 1940 adds r0, r0, r5 c0d01946: 9901 ldr r1, [sp, #4] c0d01948: 1840 adds r0, r0, r1 c0d0194a: 1e45 subs r5, r0, #1 // // If the value is negative, then place the minus sign // before the number. // if(ulNeg) c0d0194c: 2b00 cmp r3, #0 c0d0194e: d003 beq.n c0d01958 <screen_printf+0x218> c0d01950: a808 add r0, sp, #32 { // // Place the minus sign in the output buffer. // pcBuf[ulPos++] = '-'; c0d01952: 212d movs r1, #45 ; 0x2d c0d01954: 5541 strb r1, [r0, r5] c0d01956: 1c6d adds r5, r5, #1 } // // Convert the value into a string. // for(; ulIdx; ulIdx /= ulBase) c0d01958: 2f00 cmp r7, #0 c0d0195a: d01b beq.n c0d01994 <screen_printf+0x254> c0d0195c: 9803 ldr r0, [sp, #12] c0d0195e: 2800 cmp r0, #0 c0d01960: d002 beq.n c0d01968 <screen_printf+0x228> c0d01962: 4849 ldr r0, [pc, #292] ; (c0d01a88 <screen_printf+0x348>) c0d01964: 4478 add r0, pc c0d01966: e001 b.n c0d0196c <screen_printf+0x22c> c0d01968: 4846 ldr r0, [pc, #280] ; (c0d01a84 <screen_printf+0x344>) c0d0196a: 4478 add r0, pc c0d0196c: 9005 str r0, [sp, #20] c0d0196e: 9806 ldr r0, [sp, #24] c0d01970: 4639 mov r1, r7 c0d01972: f002 fb89 bl c0d04088 <__aeabi_uidiv> c0d01976: 4631 mov r1, r6 c0d01978: f002 fc0c bl c0d04194 <__aeabi_uidivmod> c0d0197c: 9805 ldr r0, [sp, #20] c0d0197e: 5c40 ldrb r0, [r0, r1] c0d01980: a908 add r1, sp, #32 c0d01982: 5548 strb r0, [r1, r5] c0d01984: 4638 mov r0, r7 c0d01986: 4631 mov r1, r6 c0d01988: f002 fb7e bl c0d04088 <__aeabi_uidiv> c0d0198c: 1c6d adds r5, r5, #1 c0d0198e: 42be cmp r6, r7 c0d01990: 4607 mov r7, r0 c0d01992: d9ec bls.n c0d0196e <screen_printf+0x22e> #ifdef HAVE_PRINTF #ifndef BOLOS_RELEASE void screen_prints(const char* str, unsigned int charcount) { while(charcount--) { c0d01994: 2d00 cmp r5, #0 c0d01996: d066 beq.n c0d01a66 <screen_printf+0x326> c0d01998: ae08 add r6, sp, #32 screen_printc(*str++); c0d0199a: 7830 ldrb r0, [r6, #0] c0d0199c: f7ff feba bl c0d01714 <screen_printc> c0d019a0: 1c76 adds r6, r6, #1 #ifdef HAVE_PRINTF #ifndef BOLOS_RELEASE void screen_prints(const char* str, unsigned int charcount) { while(charcount--) { c0d019a2: 1e6d subs r5, r5, #1 c0d019a4: d1f9 bne.n c0d0199a <screen_printf+0x25a> c0d019a6: e05e b.n c0d01a66 <screen_printf+0x326> case 'c': { // // Get the value from the varargs. // ulValue = va_arg(vaArgP, unsigned long); c0d019a8: 9807 ldr r0, [sp, #28] c0d019aa: 1d01 adds r1, r0, #4 c0d019ac: 9107 str r1, [sp, #28] #ifdef HAVE_PRINTF #ifndef BOLOS_RELEASE void screen_prints(const char* str, unsigned int charcount) { while(charcount--) { screen_printc(*str++); c0d019ae: 7800 ldrb r0, [r0, #0] c0d019b0: f7ff feb0 bl c0d01714 <screen_printc> c0d019b4: e057 b.n c0d01a66 <screen_printf+0x326> c0d019b6: 9a06 ldr r2, [sp, #24] c0d019b8: e011 b.n c0d019de <screen_printf+0x29e> break; // printout prepad case 2: // if string is empty, then, ' ' padding if (pcStr[0] == '\0') { c0d019ba: 7838 ldrb r0, [r7, #0] c0d019bc: 2800 cmp r0, #0 c0d019be: d03f beq.n c0d01a40 <screen_printf+0x300> #ifdef HAVE_PRINTF #ifndef BOLOS_RELEASE void screen_prints(const char* str, unsigned int charcount) { while(charcount--) { c0d019c0: 482d ldr r0, [pc, #180] ; (c0d01a78 <screen_printf+0x338>) c0d019c2: 4478 add r0, pc c0d019c4: 1940 adds r0, r0, r5 screen_printc(*str++); c0d019c6: 7940 ldrb r0, [r0, #5] c0d019c8: f7ff fea4 bl c0d01714 <screen_printc> #ifdef HAVE_PRINTF #ifndef BOLOS_RELEASE void screen_prints(const char* str, unsigned int charcount) { while(charcount--) { c0d019cc: 1c6d adds r5, r5, #1 c0d019ce: d1f7 bne.n c0d019c0 <screen_printf+0x280> c0d019d0: e049 b.n c0d01a66 <screen_printf+0x326> c0d019d2: 1d2a adds r2, r5, #4 // Determine the length of the string. (if not specified using .*) // switch(cStrlenSet) { // compute length with strlen case 0: for(ulIdx = 0; pcStr[ulIdx] != '\0'; ulIdx++) c0d019d4: 18b9 adds r1, r7, r2 c0d019d6: 7849 ldrb r1, [r1, #1] c0d019d8: 1c52 adds r2, r2, #1 c0d019da: 2900 cmp r1, #0 c0d019dc: d1fa bne.n c0d019d4 <screen_printf+0x294> c0d019de: 9206 str r2, [sp, #24] } // // Write the string. // switch(ulBase) { c0d019e0: 2810 cmp r0, #16 c0d019e2: 9e03 ldr r6, [sp, #12] c0d019e4: d11f bne.n c0d01a26 <screen_printf+0x2e6> default: screen_prints(pcStr, ulIdx); break; case 16: { unsigned char nibble1, nibble2; for (ulCount = 0; ulCount < ulIdx; ulCount++) { c0d019e6: 9806 ldr r0, [sp, #24] c0d019e8: e01a b.n c0d01a20 <screen_printf+0x2e0> nibble1 = (pcStr[ulCount]>>4)&0xF; c0d019ea: 7838 ldrb r0, [r7, #0] nibble2 = pcStr[ulCount]&0xF; c0d019ec: 250f movs r5, #15 c0d019ee: 4005 ands r5, r0 screen_prints(pcStr, ulIdx); break; case 16: { unsigned char nibble1, nibble2; for (ulCount = 0; ulCount < ulIdx; ulCount++) { nibble1 = (pcStr[ulCount]>>4)&0xF; c0d019f0: 0900 lsrs r0, r0, #4 nibble2 = pcStr[ulCount]&0xF; switch(ulCap) { c0d019f2: 2e01 cmp r6, #1 c0d019f4: d005 beq.n c0d01a02 <screen_printf+0x2c2> c0d019f6: 2e00 cmp r6, #0 c0d019f8: d10e bne.n c0d01a18 <screen_printf+0x2d8> case 0: screen_printc(g_pcHex[nibble1]); c0d019fa: b2c0 uxtb r0, r0 c0d019fc: 4e1f ldr r6, [pc, #124] ; (c0d01a7c <screen_printf+0x33c>) c0d019fe: 447e add r6, pc c0d01a00: e002 b.n c0d01a08 <screen_printf+0x2c8> screen_printc(g_pcHex[nibble2]); break; case 1: screen_printc(g_pcHex_cap[nibble1]); c0d01a02: b2c0 uxtb r0, r0 c0d01a04: 4e1e ldr r6, [pc, #120] ; (c0d01a80 <screen_printf+0x340>) c0d01a06: 447e add r6, pc c0d01a08: 5c30 ldrb r0, [r6, r0] c0d01a0a: f7ff fe83 bl c0d01714 <screen_printc> c0d01a0e: b2e8 uxtb r0, r5 c0d01a10: 5c30 ldrb r0, [r6, r0] c0d01a12: 9e03 ldr r6, [sp, #12] c0d01a14: f7ff fe7e bl c0d01714 <screen_printc> c0d01a18: 9806 ldr r0, [sp, #24] default: screen_prints(pcStr, ulIdx); break; case 16: { unsigned char nibble1, nibble2; for (ulCount = 0; ulCount < ulIdx; ulCount++) { c0d01a1a: 1e40 subs r0, r0, #1 c0d01a1c: 1c7f adds r7, r7, #1 c0d01a1e: 9006 str r0, [sp, #24] c0d01a20: 2800 cmp r0, #0 c0d01a22: d1e2 bne.n c0d019ea <screen_printf+0x2aa> c0d01a24: e01f b.n c0d01a66 <screen_printf+0x326> c0d01a26: 2600 movs r6, #0 #ifdef HAVE_PRINTF #ifndef BOLOS_RELEASE void screen_prints(const char* str, unsigned int charcount) { while(charcount--) { c0d01a28: 9806 ldr r0, [sp, #24] c0d01a2a: 2800 cmp r0, #0 c0d01a2c: d010 beq.n c0d01a50 <screen_printf+0x310> c0d01a2e: 2500 movs r5, #0 c0d01a30: 9e06 ldr r6, [sp, #24] screen_printc(*str++); c0d01a32: 5d78 ldrb r0, [r7, r5] c0d01a34: f7ff fe6e bl c0d01714 <screen_printc> #ifdef HAVE_PRINTF #ifndef BOLOS_RELEASE void screen_prints(const char* str, unsigned int charcount) { while(charcount--) { c0d01a38: 1c6d adds r5, r5, #1 c0d01a3a: 42ae cmp r6, r5 c0d01a3c: d1f9 bne.n c0d01a32 <screen_printf+0x2f2> c0d01a3e: e007 b.n c0d01a50 <screen_printf+0x310> screen_printc(str[i]); } */ unsigned long ulIdx, ulValue, ulPos, ulCount, ulBase, ulNeg, ulStrlen, ulCap; c0d01a40: 1d28 adds r0, r5, #4 c0d01a42: 9906 ldr r1, [sp, #24] c0d01a44: 1a45 subs r5, r0, r1 #ifdef HAVE_PRINTF #ifndef BOLOS_RELEASE void screen_prints(const char* str, unsigned int charcount) { while(charcount--) { screen_printc(*str++); c0d01a46: 2020 movs r0, #32 c0d01a48: f7ff fe64 bl c0d01714 <screen_printc> if (pcStr[0] == '\0') { // padd ulStrlen white space do { screen_prints(" ", 1); } while(ulStrlen-- > 0); c0d01a4c: 1c6d adds r5, r5, #1 c0d01a4e: d1fa bne.n c0d01a46 <screen_printf+0x306> c0d01a50: 9905 ldr r1, [sp, #20] s_pad: // // Write any required padding spaces // if(ulCount > ulIdx) c0d01a52: 42b1 cmp r1, r6 c0d01a54: d907 bls.n c0d01a66 <screen_printf+0x326> { ulCount -= ulIdx; c0d01a56: 1b88 subs r0, r1, r6 c0d01a58: d005 beq.n c0d01a66 <screen_printf+0x326> }; #ifdef HAVE_PRINTF #ifndef BOLOS_RELEASE void screen_prints(const char* str, unsigned int charcount) { c0d01a5a: 1a75 subs r5, r6, r1 while(charcount--) { screen_printc(*str++); c0d01a5c: 2020 movs r0, #32 c0d01a5e: f7ff fe59 bl c0d01714 <screen_printc> // Write any required padding spaces // if(ulCount > ulIdx) { ulCount -= ulIdx; while(ulCount--) c0d01a62: 1c6d adds r5, r5, #1 c0d01a64: d1fa bne.n c0d01a5c <screen_printf+0x31c> c0d01a66: 7820 ldrb r0, [r4, #0] c0d01a68: 2800 cmp r0, #0 c0d01a6a: d000 beq.n c0d01a6e <screen_printf+0x32e> c0d01a6c: e674 b.n c0d01758 <screen_printf+0x18> // // End the varargs processing. // va_end(vaArgP); } c0d01a6e: b00c add sp, #48 ; 0x30 c0d01a70: bcf0 pop {r4, r5, r6, r7} c0d01a72: bc01 pop {r0} c0d01a74: b003 add sp, #12 c0d01a76: 4700 bx r0 c0d01a78: 00002a0e .word 0x00002a0e c0d01a7c: 000029b2 .word 0x000029b2 c0d01a80: 000029ba .word 0x000029ba c0d01a84: 00002a46 .word 0x00002a46 c0d01a88: 00002a5c .word 0x00002a5c c0d01a8c <snprintf>: #endif // HAVE_PRINTF #ifdef HAVE_SPRINTF //unsigned int snprintf(unsigned char * str, unsigned int str_size, const char* format, ...) int snprintf(char * str, size_t str_size, const char * format, ...) { c0d01a8c: b081 sub sp, #4 c0d01a8e: b5f0 push {r4, r5, r6, r7, lr} c0d01a90: b090 sub sp, #64 ; 0x40 c0d01a92: 4615 mov r5, r2 c0d01a94: 460c mov r4, r1 c0d01a96: 900a str r0, [sp, #40] ; 0x28 c0d01a98: 9315 str r3, [sp, #84] ; 0x54 char cStrlenSet; // // Check the arguments. // if(format == 0 || str == 0 ||str_size < 2) { c0d01a9a: 2c02 cmp r4, #2 c0d01a9c: d200 bcs.n c0d01aa0 <snprintf+0x14> c0d01a9e: e1f5 b.n c0d01e8c <snprintf+0x400> c0d01aa0: 980a ldr r0, [sp, #40] ; 0x28 c0d01aa2: 2800 cmp r0, #0 c0d01aa4: d100 bne.n c0d01aa8 <snprintf+0x1c> c0d01aa6: e1f1 b.n c0d01e8c <snprintf+0x400> c0d01aa8: 2d00 cmp r5, #0 c0d01aaa: d100 bne.n c0d01aae <snprintf+0x22> c0d01aac: e1ee b.n c0d01e8c <snprintf+0x400> c0d01aae: 2100 movs r1, #0 return 0; } // ensure terminating string with a \0 os_memset(str, 0, str_size); c0d01ab0: 980a ldr r0, [sp, #40] ; 0x28 c0d01ab2: 9107 str r1, [sp, #28] c0d01ab4: 4622 mov r2, r4 c0d01ab6: f7ff f8f5 bl c0d00ca4 <os_memset> c0d01aba: a815 add r0, sp, #84 ; 0x54 // // Start the varargs processing. // va_start(vaArgP, format); c0d01abc: 900b str r0, [sp, #44] ; 0x2c // // Loop while there are more characters in the string. // while(*format) c0d01abe: 7828 ldrb r0, [r5, #0] c0d01ac0: 2800 cmp r0, #0 c0d01ac2: d100 bne.n c0d01ac6 <snprintf+0x3a> c0d01ac4: e1e2 b.n c0d01e8c <snprintf+0x400> c0d01ac6: 9907 ldr r1, [sp, #28] c0d01ac8: 43c9 mvns r1, r1 return 0; } // ensure terminating string with a \0 os_memset(str, 0, str_size); str_size--; c0d01aca: 1e67 subs r7, r4, #1 c0d01acc: 9105 str r1, [sp, #20] c0d01ace: e1c2 b.n c0d01e56 <snprintf+0x3ca> } // // Skip the portion of the string that was written. // format += ulIdx; c0d01ad0: 1928 adds r0, r5, r4 // // See if the next character is a %. // if(*format == '%') c0d01ad2: 5d29 ldrb r1, [r5, r4] c0d01ad4: 2925 cmp r1, #37 ; 0x25 c0d01ad6: d10b bne.n c0d01af0 <snprintf+0x64> c0d01ad8: 9703 str r7, [sp, #12] c0d01ada: 9202 str r2, [sp, #8] { // // Skip the %. // format++; c0d01adc: 1c43 adds r3, r0, #1 c0d01ade: 2000 movs r0, #0 c0d01ae0: 2120 movs r1, #32 c0d01ae2: 9108 str r1, [sp, #32] c0d01ae4: 210a movs r1, #10 c0d01ae6: 9101 str r1, [sp, #4] c0d01ae8: 9000 str r0, [sp, #0] c0d01aea: 9004 str r0, [sp, #16] c0d01aec: 9009 str r0, [sp, #36] ; 0x24 c0d01aee: e056 b.n c0d01b9e <snprintf+0x112> c0d01af0: 4605 mov r5, r0 c0d01af2: 920a str r2, [sp, #40] ; 0x28 c0d01af4: e121 b.n c0d01d3a <snprintf+0x2ae> c0d01af6: 462b mov r3, r5 c0d01af8: 4608 mov r0, r1 c0d01afa: e04b b.n c0d01b94 <snprintf+0x108> c0d01afc: 2b47 cmp r3, #71 ; 0x47 c0d01afe: dc13 bgt.n c0d01b28 <snprintf+0x9c> c0d01b00: 4619 mov r1, r3 c0d01b02: 3930 subs r1, #48 ; 0x30 c0d01b04: 290a cmp r1, #10 c0d01b06: d234 bcs.n c0d01b72 <snprintf+0xe6> { // // If this is a zero, and it is the first digit, then the // fill character is a zero instead of a space. // if((format[-1] == '0') && (ulCount == 0)) c0d01b08: 2b30 cmp r3, #48 ; 0x30 c0d01b0a: 9908 ldr r1, [sp, #32] c0d01b0c: d100 bne.n c0d01b10 <snprintf+0x84> c0d01b0e: 4619 mov r1, r3 c0d01b10: 9f09 ldr r7, [sp, #36] ; 0x24 c0d01b12: 2f00 cmp r7, #0 c0d01b14: d000 beq.n c0d01b18 <snprintf+0x8c> c0d01b16: 9908 ldr r1, [sp, #32] } // // Update the digit count. // ulCount *= 10; c0d01b18: 220a movs r2, #10 c0d01b1a: 437a muls r2, r7 ulCount += format[-1] - '0'; c0d01b1c: 18d2 adds r2, r2, r3 c0d01b1e: 3a30 subs r2, #48 ; 0x30 c0d01b20: 9209 str r2, [sp, #36] ; 0x24 c0d01b22: 462b mov r3, r5 c0d01b24: 9108 str r1, [sp, #32] c0d01b26: e03a b.n c0d01b9e <snprintf+0x112> c0d01b28: 2b67 cmp r3, #103 ; 0x67 c0d01b2a: dd04 ble.n c0d01b36 <snprintf+0xaa> c0d01b2c: 2b72 cmp r3, #114 ; 0x72 c0d01b2e: dd09 ble.n c0d01b44 <snprintf+0xb8> c0d01b30: 2b73 cmp r3, #115 ; 0x73 c0d01b32: d146 bne.n c0d01bc2 <snprintf+0x136> c0d01b34: e00a b.n c0d01b4c <snprintf+0xc0> c0d01b36: 2b62 cmp r3, #98 ; 0x62 c0d01b38: dc48 bgt.n c0d01bcc <snprintf+0x140> c0d01b3a: 2b48 cmp r3, #72 ; 0x48 c0d01b3c: d155 bne.n c0d01bea <snprintf+0x15e> c0d01b3e: 2201 movs r2, #1 c0d01b40: 9204 str r2, [sp, #16] c0d01b42: e001 b.n c0d01b48 <snprintf+0xbc> c0d01b44: 2b68 cmp r3, #104 ; 0x68 c0d01b46: d156 bne.n c0d01bf6 <snprintf+0x16a> c0d01b48: 2210 movs r2, #16 c0d01b4a: 9201 str r2, [sp, #4] case_s: { // // Get the string pointer from the varargs. // pcStr = va_arg(vaArgP, char *); c0d01b4c: 9a0b ldr r2, [sp, #44] ; 0x2c c0d01b4e: 1d13 adds r3, r2, #4 c0d01b50: 930b str r3, [sp, #44] ; 0x2c c0d01b52: 2303 movs r3, #3 c0d01b54: 4018 ands r0, r3 c0d01b56: 1c4f adds r7, r1, #1 c0d01b58: 6811 ldr r1, [r2, #0] // // Determine the length of the string. (if not specified using .*) // switch(cStrlenSet) { c0d01b5a: 2801 cmp r0, #1 c0d01b5c: d100 bne.n c0d01b60 <snprintf+0xd4> c0d01b5e: e0d0 b.n c0d01d02 <snprintf+0x276> c0d01b60: 2802 cmp r0, #2 c0d01b62: d100 bne.n c0d01b66 <snprintf+0xda> c0d01b64: e0d2 b.n c0d01d0c <snprintf+0x280> c0d01b66: 2803 cmp r0, #3 c0d01b68: 462b mov r3, r5 c0d01b6a: 4638 mov r0, r7 c0d01b6c: 9f06 ldr r7, [sp, #24] c0d01b6e: d016 beq.n c0d01b9e <snprintf+0x112> c0d01b70: e0e9 b.n c0d01d46 <snprintf+0x2ba> c0d01b72: 2b2e cmp r3, #46 ; 0x2e c0d01b74: d000 beq.n c0d01b78 <snprintf+0xec> c0d01b76: e0cc b.n c0d01d12 <snprintf+0x286> // special %.*H or %.*h format to print a given length of hex digits (case: H UPPER, h lower) // case '.': { // ensure next char is '*' and next one is 's'/'h'/'H' if (format[0] == '*' && (format[1] == 's' || format[1] == 'H' || format[1] == 'h')) { c0d01b78: 7828 ldrb r0, [r5, #0] c0d01b7a: 282a cmp r0, #42 ; 0x2a c0d01b7c: d000 beq.n c0d01b80 <snprintf+0xf4> c0d01b7e: e0c8 b.n c0d01d12 <snprintf+0x286> c0d01b80: 7869 ldrb r1, [r5, #1] c0d01b82: 1c6b adds r3, r5, #1 c0d01b84: 2001 movs r0, #1 c0d01b86: 2948 cmp r1, #72 ; 0x48 c0d01b88: d004 beq.n c0d01b94 <snprintf+0x108> c0d01b8a: 2968 cmp r1, #104 ; 0x68 c0d01b8c: d002 beq.n c0d01b94 <snprintf+0x108> c0d01b8e: 2973 cmp r1, #115 ; 0x73 c0d01b90: d000 beq.n c0d01b94 <snprintf+0x108> c0d01b92: e0be b.n c0d01d12 <snprintf+0x286> c0d01b94: 990b ldr r1, [sp, #44] ; 0x2c c0d01b96: 1d0a adds r2, r1, #4 c0d01b98: 920b str r2, [sp, #44] ; 0x2c c0d01b9a: 6809 ldr r1, [r1, #0] int snprintf(char * str, size_t str_size, const char * format, ...) { unsigned int ulIdx, ulValue, ulPos, ulCount, ulBase, ulNeg, ulStrlen, ulCap; char *pcStr, pcBuf[16], cFill; va_list vaArgP; char cStrlenSet; c0d01b9c: 9100 str r1, [sp, #0] c0d01b9e: 2102 movs r1, #2 c0d01ba0: 461d mov r5, r3 again: // // Determine how to handle the next character. // switch(*format++) c0d01ba2: 782b ldrb r3, [r5, #0] c0d01ba4: 1c6d adds r5, r5, #1 c0d01ba6: 2200 movs r2, #0 c0d01ba8: 2b2d cmp r3, #45 ; 0x2d c0d01baa: dca7 bgt.n c0d01afc <snprintf+0x70> c0d01bac: 4610 mov r0, r2 c0d01bae: d0f8 beq.n c0d01ba2 <snprintf+0x116> c0d01bb0: 2b25 cmp r3, #37 ; 0x25 c0d01bb2: d02a beq.n c0d01c0a <snprintf+0x17e> c0d01bb4: 2b2a cmp r3, #42 ; 0x2a c0d01bb6: d000 beq.n c0d01bba <snprintf+0x12e> c0d01bb8: e0ab b.n c0d01d12 <snprintf+0x286> goto error; } case '*': { if (*format == 's' ) { c0d01bba: 7828 ldrb r0, [r5, #0] c0d01bbc: 2873 cmp r0, #115 ; 0x73 c0d01bbe: d09a beq.n c0d01af6 <snprintf+0x6a> c0d01bc0: e0a7 b.n c0d01d12 <snprintf+0x286> c0d01bc2: 2b75 cmp r3, #117 ; 0x75 c0d01bc4: d023 beq.n c0d01c0e <snprintf+0x182> c0d01bc6: 2b78 cmp r3, #120 ; 0x78 c0d01bc8: d018 beq.n c0d01bfc <snprintf+0x170> c0d01bca: e0a2 b.n c0d01d12 <snprintf+0x286> c0d01bcc: 2b63 cmp r3, #99 ; 0x63 c0d01bce: d100 bne.n c0d01bd2 <snprintf+0x146> c0d01bd0: e08d b.n c0d01cee <snprintf+0x262> c0d01bd2: 2b64 cmp r3, #100 ; 0x64 c0d01bd4: d000 beq.n c0d01bd8 <snprintf+0x14c> c0d01bd6: e09c b.n c0d01d12 <snprintf+0x286> case 'd': { // // Get the value from the varargs. // ulValue = va_arg(vaArgP, unsigned long); c0d01bd8: 980b ldr r0, [sp, #44] ; 0x2c c0d01bda: 1d01 adds r1, r0, #4 c0d01bdc: 910b str r1, [sp, #44] ; 0x2c c0d01bde: 6800 ldr r0, [r0, #0] c0d01be0: 17c1 asrs r1, r0, #31 c0d01be2: 1842 adds r2, r0, r1 c0d01be4: 404a eors r2, r1 // // If the value is negative, make it positive and indicate // that a minus sign is needed. // if((long)ulValue < 0) c0d01be6: 0fc0 lsrs r0, r0, #31 c0d01be8: e016 b.n c0d01c18 <snprintf+0x18c> c0d01bea: 2b58 cmp r3, #88 ; 0x58 c0d01bec: d000 beq.n c0d01bf0 <snprintf+0x164> c0d01bee: e090 b.n c0d01d12 <snprintf+0x286> c0d01bf0: 2001 movs r0, #1 #ifdef HAVE_SPRINTF //unsigned int snprintf(unsigned char * str, unsigned int str_size, const char* format, ...) int snprintf(char * str, size_t str_size, const char * format, ...) { unsigned int ulIdx, ulValue, ulPos, ulCount, ulBase, ulNeg, ulStrlen, ulCap; c0d01bf2: 9004 str r0, [sp, #16] c0d01bf4: e002 b.n c0d01bfc <snprintf+0x170> c0d01bf6: 2b70 cmp r3, #112 ; 0x70 c0d01bf8: d000 beq.n c0d01bfc <snprintf+0x170> c0d01bfa: e08a b.n c0d01d12 <snprintf+0x286> case 'p': { // // Get the value from the varargs. // ulValue = va_arg(vaArgP, unsigned long); c0d01bfc: 980b ldr r0, [sp, #44] ; 0x2c c0d01bfe: 1d01 adds r1, r0, #4 c0d01c00: 910b str r1, [sp, #44] ; 0x2c c0d01c02: 6802 ldr r2, [r0, #0] c0d01c04: 2000 movs r0, #0 c0d01c06: 2710 movs r7, #16 c0d01c08: e007 b.n c0d01c1a <snprintf+0x18e> case '%': { // // Simply write a single %. // str[0] = '%'; c0d01c0a: 2025 movs r0, #37 ; 0x25 c0d01c0c: e073 b.n c0d01cf6 <snprintf+0x26a> case 'u': { // // Get the value from the varargs. // ulValue = va_arg(vaArgP, unsigned long); c0d01c0e: 980b ldr r0, [sp, #44] ; 0x2c c0d01c10: 1d01 adds r1, r0, #4 c0d01c12: 910b str r1, [sp, #44] ; 0x2c c0d01c14: 6802 ldr r2, [r0, #0] c0d01c16: 2000 movs r0, #0 c0d01c18: 270a movs r7, #10 c0d01c1a: 9006 str r0, [sp, #24] c0d01c1c: 2601 movs r6, #1 c0d01c1e: 920a str r2, [sp, #40] ; 0x28 // Determine the number of digits in the string version of // the value. // convert: for(ulIdx = 1; (((ulIdx * ulBase) <= ulValue) && c0d01c20: 4297 cmp r7, r2 c0d01c22: d812 bhi.n c0d01c4a <snprintf+0x1be> c0d01c24: 2401 movs r4, #1 c0d01c26: 4638 mov r0, r7 c0d01c28: 4606 mov r6, r0 (((ulIdx * ulBase) / ulBase) == ulIdx)); c0d01c2a: 4639 mov r1, r7 c0d01c2c: f002 fa2c bl c0d04088 <__aeabi_uidiv> // // Determine the number of digits in the string version of // the value. // convert: for(ulIdx = 1; c0d01c30: 42a0 cmp r0, r4 c0d01c32: d109 bne.n c0d01c48 <snprintf+0x1bc> (((ulIdx * ulBase) <= ulValue) && c0d01c34: 4638 mov r0, r7 c0d01c36: 4370 muls r0, r6 (((ulIdx * ulBase) / ulBase) == ulIdx)); ulIdx *= ulBase, ulCount--) c0d01c38: 9909 ldr r1, [sp, #36] ; 0x24 c0d01c3a: 1e49 subs r1, r1, #1 // Determine the number of digits in the string version of // the value. // convert: for(ulIdx = 1; (((ulIdx * ulBase) <= ulValue) && c0d01c3c: 9109 str r1, [sp, #36] ; 0x24 c0d01c3e: 990a ldr r1, [sp, #40] ; 0x28 c0d01c40: 4288 cmp r0, r1 c0d01c42: 4634 mov r4, r6 c0d01c44: d9f0 bls.n c0d01c28 <snprintf+0x19c> c0d01c46: e000 b.n c0d01c4a <snprintf+0x1be> c0d01c48: 4626 mov r6, r4 // // If the value is negative, reduce the count of padding // characters needed. // if(ulNeg) c0d01c4a: 2400 movs r4, #0 c0d01c4c: 43e1 mvns r1, r4 c0d01c4e: 9b06 ldr r3, [sp, #24] c0d01c50: 2b00 cmp r3, #0 c0d01c52: d100 bne.n c0d01c56 <snprintf+0x1ca> c0d01c54: 4619 mov r1, r3 c0d01c56: 9809 ldr r0, [sp, #36] ; 0x24 c0d01c58: 9101 str r1, [sp, #4] c0d01c5a: 1840 adds r0, r0, r1 // // If the value is negative and the value is padded with // zeros, then place the minus sign before the padding. // if(ulNeg && (cFill == '0')) c0d01c5c: 9908 ldr r1, [sp, #32] c0d01c5e: b2ca uxtb r2, r1 c0d01c60: 2a30 cmp r2, #48 ; 0x30 c0d01c62: d106 bne.n c0d01c72 <snprintf+0x1e6> c0d01c64: 2b00 cmp r3, #0 c0d01c66: d004 beq.n c0d01c72 <snprintf+0x1e6> c0d01c68: a90c add r1, sp, #48 ; 0x30 { // // Place the minus sign in the output buffer. // pcBuf[ulPos++] = '-'; c0d01c6a: 232d movs r3, #45 ; 0x2d c0d01c6c: 700b strb r3, [r1, #0] c0d01c6e: 2300 movs r3, #0 c0d01c70: 2401 movs r4, #1 // // Provide additional padding at the beginning of the // string conversion if needed. // if((ulCount > 1) && (ulCount < 16)) c0d01c72: 1e81 subs r1, r0, #2 c0d01c74: 290d cmp r1, #13 c0d01c76: d80c bhi.n c0d01c92 <snprintf+0x206> c0d01c78: 1e41 subs r1, r0, #1 c0d01c7a: d00a beq.n c0d01c92 <snprintf+0x206> c0d01c7c: a80c add r0, sp, #48 ; 0x30 { for(ulCount--; ulCount; ulCount--) { pcBuf[ulPos++] = cFill; c0d01c7e: 4320 orrs r0, r4 c0d01c80: 9306 str r3, [sp, #24] c0d01c82: f002 fa97 bl c0d041b4 <__aeabi_memset> c0d01c86: 9b06 ldr r3, [sp, #24] c0d01c88: 9809 ldr r0, [sp, #36] ; 0x24 c0d01c8a: 1900 adds r0, r0, r4 c0d01c8c: 9901 ldr r1, [sp, #4] c0d01c8e: 1840 adds r0, r0, r1 c0d01c90: 1e44 subs r4, r0, #1 // // If the value is negative, then place the minus sign // before the number. // if(ulNeg) c0d01c92: 2b00 cmp r3, #0 c0d01c94: d003 beq.n c0d01c9e <snprintf+0x212> c0d01c96: a80c add r0, sp, #48 ; 0x30 { // // Place the minus sign in the output buffer. // pcBuf[ulPos++] = '-'; c0d01c98: 212d movs r1, #45 ; 0x2d c0d01c9a: 5501 strb r1, [r0, r4] c0d01c9c: 1c64 adds r4, r4, #1 c0d01c9e: 9804 ldr r0, [sp, #16] } // // Convert the value into a string. // for(; ulIdx; ulIdx /= ulBase) c0d01ca0: 2e00 cmp r6, #0 c0d01ca2: d01a beq.n c0d01cda <snprintf+0x24e> c0d01ca4: 2800 cmp r0, #0 c0d01ca6: d002 beq.n c0d01cae <snprintf+0x222> c0d01ca8: 487f ldr r0, [pc, #508] ; (c0d01ea8 <snprintf+0x41c>) c0d01caa: 4478 add r0, pc c0d01cac: e001 b.n c0d01cb2 <snprintf+0x226> c0d01cae: 487d ldr r0, [pc, #500] ; (c0d01ea4 <snprintf+0x418>) c0d01cb0: 4478 add r0, pc c0d01cb2: 9009 str r0, [sp, #36] ; 0x24 c0d01cb4: 980a ldr r0, [sp, #40] ; 0x28 c0d01cb6: 4631 mov r1, r6 c0d01cb8: f002 f9e6 bl c0d04088 <__aeabi_uidiv> c0d01cbc: 4639 mov r1, r7 c0d01cbe: f002 fa69 bl c0d04194 <__aeabi_uidivmod> c0d01cc2: 9809 ldr r0, [sp, #36] ; 0x24 c0d01cc4: 5c40 ldrb r0, [r0, r1] c0d01cc6: a90c add r1, sp, #48 ; 0x30 c0d01cc8: 5508 strb r0, [r1, r4] c0d01cca: 4630 mov r0, r6 c0d01ccc: 4639 mov r1, r7 c0d01cce: f002 f9db bl c0d04088 <__aeabi_uidiv> c0d01cd2: 1c64 adds r4, r4, #1 c0d01cd4: 42b7 cmp r7, r6 c0d01cd6: 4606 mov r6, r0 c0d01cd8: d9ec bls.n c0d01cb4 <snprintf+0x228> c0d01cda: 9b03 ldr r3, [sp, #12] } // // Write the string. // ulPos = MIN(ulPos, str_size); c0d01cdc: 429c cmp r4, r3 c0d01cde: d300 bcc.n c0d01ce2 <snprintf+0x256> c0d01ce0: 461c mov r4, r3 c0d01ce2: a90c add r1, sp, #48 ; 0x30 c0d01ce4: 9e02 ldr r6, [sp, #8] os_memmove(str, pcBuf, ulPos); c0d01ce6: 4630 mov r0, r6 c0d01ce8: 4622 mov r2, r4 c0d01cea: 461f mov r7, r3 c0d01cec: e01c b.n c0d01d28 <snprintf+0x29c> case 'c': { // // Get the value from the varargs. // ulValue = va_arg(vaArgP, unsigned long); c0d01cee: 980b ldr r0, [sp, #44] ; 0x2c c0d01cf0: 1d01 adds r1, r0, #4 c0d01cf2: 910b str r1, [sp, #44] ; 0x2c c0d01cf4: 6800 ldr r0, [r0, #0] c0d01cf6: 9902 ldr r1, [sp, #8] c0d01cf8: 7008 strb r0, [r1, #0] c0d01cfa: 9803 ldr r0, [sp, #12] c0d01cfc: 1e40 subs r0, r0, #1 c0d01cfe: 1c49 adds r1, r1, #1 c0d01d00: e016 b.n c0d01d30 <snprintf+0x2a4> c0d01d02: 9c00 ldr r4, [sp, #0] c0d01d04: 9a05 ldr r2, [sp, #20] c0d01d06: 9b03 ldr r3, [sp, #12] c0d01d08: 9f06 ldr r7, [sp, #24] c0d01d0a: e024 b.n c0d01d56 <snprintf+0x2ca> break; // printout prepad case 2: // if string is empty, then, ' ' padding if (pcStr[0] == '\0') { c0d01d0c: 7808 ldrb r0, [r1, #0] c0d01d0e: 2800 cmp r0, #0 c0d01d10: d077 beq.n c0d01e02 <snprintf+0x376> default: { // // Indicate an error. // ulPos = MIN(strlen("ERROR"), str_size); c0d01d12: 2005 movs r0, #5 c0d01d14: 9f03 ldr r7, [sp, #12] c0d01d16: 2f05 cmp r7, #5 c0d01d18: 463c mov r4, r7 c0d01d1a: d300 bcc.n c0d01d1e <snprintf+0x292> c0d01d1c: 4604 mov r4, r0 os_memmove(str, "ERROR", ulPos); c0d01d1e: 495e ldr r1, [pc, #376] ; (c0d01e98 <snprintf+0x40c>) c0d01d20: 4479 add r1, pc c0d01d22: 9e02 ldr r6, [sp, #8] c0d01d24: 4630 mov r0, r6 c0d01d26: 4622 mov r2, r4 c0d01d28: f7fe ffc5 bl c0d00cb6 <os_memmove> c0d01d2c: 1b38 subs r0, r7, r4 c0d01d2e: 1931 adds r1, r6, r4 c0d01d30: 910a str r1, [sp, #40] ; 0x28 c0d01d32: 4607 mov r7, r0 c0d01d34: 2800 cmp r0, #0 c0d01d36: d100 bne.n c0d01d3a <snprintf+0x2ae> c0d01d38: e0a8 b.n c0d01e8c <snprintf+0x400> va_start(vaArgP, format); // // Loop while there are more characters in the string. // while(*format) c0d01d3a: 7828 ldrb r0, [r5, #0] c0d01d3c: 2800 cmp r0, #0 c0d01d3e: 9905 ldr r1, [sp, #20] c0d01d40: d000 beq.n c0d01d44 <snprintf+0x2b8> c0d01d42: e088 b.n c0d01e56 <snprintf+0x3ca> c0d01d44: e0a2 b.n c0d01e8c <snprintf+0x400> c0d01d46: 9a05 ldr r2, [sp, #20] c0d01d48: 4614 mov r4, r2 c0d01d4a: 9b03 ldr r3, [sp, #12] // Determine the length of the string. (if not specified using .*) // switch(cStrlenSet) { // compute length with strlen case 0: for(ulIdx = 0; pcStr[ulIdx] != '\0'; ulIdx++) c0d01d4c: 1908 adds r0, r1, r4 c0d01d4e: 7840 ldrb r0, [r0, #1] c0d01d50: 1c64 adds r4, r4, #1 c0d01d52: 2800 cmp r0, #0 c0d01d54: d1fa bne.n c0d01d4c <snprintf+0x2c0> } // // Write the string. // switch(ulBase) { c0d01d56: 9801 ldr r0, [sp, #4] c0d01d58: 2810 cmp r0, #16 c0d01d5a: 9802 ldr r0, [sp, #8] c0d01d5c: d146 bne.n c0d01dec <snprintf+0x360> return 0; } break; case 16: { unsigned char nibble1, nibble2; for (ulCount = 0; ulCount < ulIdx; ulCount++) { c0d01d5e: 2c00 cmp r4, #0 c0d01d60: d076 beq.n c0d01e50 <snprintf+0x3c4> c0d01d62: 9108 str r1, [sp, #32] nibble1 = (pcStr[ulCount]>>4)&0xF; c0d01d64: 980a ldr r0, [sp, #40] ; 0x28 c0d01d66: 1883 adds r3, r0, r2 c0d01d68: 1bd0 subs r0, r2, r7 c0d01d6a: 4286 cmp r6, r0 c0d01d6c: 4631 mov r1, r6 c0d01d6e: d800 bhi.n c0d01d72 <snprintf+0x2e6> c0d01d70: 4601 mov r1, r0 c0d01d72: 9103 str r1, [sp, #12] c0d01d74: 434a muls r2, r1 c0d01d76: 9202 str r2, [sp, #8] c0d01d78: 1c50 adds r0, r2, #1 c0d01d7a: 9001 str r0, [sp, #4] c0d01d7c: 2000 movs r0, #0 c0d01d7e: 463a mov r2, r7 c0d01d80: 930a str r3, [sp, #40] ; 0x28 c0d01d82: 9902 ldr r1, [sp, #8] c0d01d84: 185b adds r3, r3, r1 c0d01d86: 9009 str r0, [sp, #36] ; 0x24 c0d01d88: 9908 ldr r1, [sp, #32] c0d01d8a: 5c08 ldrb r0, [r1, r0] nibble2 = pcStr[ulCount]&0xF; c0d01d8c: 270f movs r7, #15 c0d01d8e: 4007 ands r7, r0 } break; case 16: { unsigned char nibble1, nibble2; for (ulCount = 0; ulCount < ulIdx; ulCount++) { nibble1 = (pcStr[ulCount]>>4)&0xF; c0d01d90: 0900 lsrs r0, r0, #4 c0d01d92: 9903 ldr r1, [sp, #12] c0d01d94: 1889 adds r1, r1, r2 c0d01d96: 1c49 adds r1, r1, #1 nibble2 = pcStr[ulCount]&0xF; if (str_size < 2) { c0d01d98: 2902 cmp r1, #2 c0d01d9a: d377 bcc.n c0d01e8c <snprintf+0x400> c0d01d9c: 9904 ldr r1, [sp, #16] return 0; } switch(ulCap) { c0d01d9e: 2901 cmp r1, #1 c0d01da0: d004 beq.n c0d01dac <snprintf+0x320> c0d01da2: 2900 cmp r1, #0 c0d01da4: d10a bne.n c0d01dbc <snprintf+0x330> c0d01da6: 493e ldr r1, [pc, #248] ; (c0d01ea0 <snprintf+0x414>) c0d01da8: 4479 add r1, pc c0d01daa: e001 b.n c0d01db0 <snprintf+0x324> c0d01dac: 493b ldr r1, [pc, #236] ; (c0d01e9c <snprintf+0x410>) c0d01dae: 4479 add r1, pc c0d01db0: b2c0 uxtb r0, r0 c0d01db2: 5c08 ldrb r0, [r1, r0] c0d01db4: 7018 strb r0, [r3, #0] c0d01db6: b2f8 uxtb r0, r7 c0d01db8: 5c08 ldrb r0, [r1, r0] c0d01dba: 7058 strb r0, [r3, #1] str[1] = g_pcHex_cap[nibble2]; break; } str+= 2; str_size -= 2; if (str_size == 0) { c0d01dbc: 9801 ldr r0, [sp, #4] c0d01dbe: 4290 cmp r0, r2 c0d01dc0: d064 beq.n c0d01e8c <snprintf+0x400> return 0; } break; case 16: { unsigned char nibble1, nibble2; for (ulCount = 0; ulCount < ulIdx; ulCount++) { c0d01dc2: 1e92 subs r2, r2, #2 c0d01dc4: 9b0a ldr r3, [sp, #40] ; 0x28 c0d01dc6: 1c9b adds r3, r3, #2 c0d01dc8: 9809 ldr r0, [sp, #36] ; 0x24 c0d01dca: 1c40 adds r0, r0, #1 c0d01dcc: 42a0 cmp r0, r4 c0d01dce: d3d7 bcc.n c0d01d80 <snprintf+0x2f4> c0d01dd0: 9009 str r0, [sp, #36] ; 0x24 c0d01dd2: 9905 ldr r1, [sp, #20] #endif // HAVE_PRINTF #ifdef HAVE_SPRINTF //unsigned int snprintf(unsigned char * str, unsigned int str_size, const char* format, ...) int snprintf(char * str, size_t str_size, const char * format, ...) c0d01dd4: 9806 ldr r0, [sp, #24] c0d01dd6: 1a08 subs r0, r1, r0 c0d01dd8: 4286 cmp r6, r0 c0d01dda: d800 bhi.n c0d01dde <snprintf+0x352> c0d01ddc: 4606 mov r6, r0 c0d01dde: 4608 mov r0, r1 c0d01de0: 4370 muls r0, r6 c0d01de2: 1818 adds r0, r3, r0 c0d01de4: 900a str r0, [sp, #40] ; 0x28 c0d01de6: 18b0 adds r0, r6, r2 c0d01de8: 1c47 adds r7, r0, #1 c0d01dea: e01c b.n c0d01e26 <snprintf+0x39a> // // Write the string. // switch(ulBase) { default: ulIdx = MIN(ulIdx, str_size); c0d01dec: 429c cmp r4, r3 c0d01dee: d300 bcc.n c0d01df2 <snprintf+0x366> c0d01df0: 461c mov r4, r3 os_memmove(str, pcStr, ulIdx); c0d01df2: 4622 mov r2, r4 c0d01df4: 4606 mov r6, r0 c0d01df6: 461f mov r7, r3 c0d01df8: f7fe ff5d bl c0d00cb6 <os_memmove> str+= ulIdx; str_size -= ulIdx; c0d01dfc: 1b38 subs r0, r7, r4 // switch(ulBase) { default: ulIdx = MIN(ulIdx, str_size); os_memmove(str, pcStr, ulIdx); str+= ulIdx; c0d01dfe: 1931 adds r1, r6, r4 c0d01e00: e00d b.n c0d01e1e <snprintf+0x392> c0d01e02: 9b03 ldr r3, [sp, #12] c0d01e04: 9f00 ldr r7, [sp, #0] case 2: // if string is empty, then, ' ' padding if (pcStr[0] == '\0') { // padd ulStrlen white space ulStrlen = MIN(ulStrlen, str_size); c0d01e06: 429f cmp r7, r3 c0d01e08: d300 bcc.n c0d01e0c <snprintf+0x380> c0d01e0a: 461f mov r7, r3 os_memset(str, ' ', ulStrlen); c0d01e0c: 2120 movs r1, #32 c0d01e0e: 9e02 ldr r6, [sp, #8] c0d01e10: 4630 mov r0, r6 c0d01e12: 463a mov r2, r7 c0d01e14: f7fe ff46 bl c0d00ca4 <os_memset> str+= ulStrlen; str_size -= ulStrlen; c0d01e18: 9803 ldr r0, [sp, #12] c0d01e1a: 1bc0 subs r0, r0, r7 if (pcStr[0] == '\0') { // padd ulStrlen white space ulStrlen = MIN(ulStrlen, str_size); os_memset(str, ' ', ulStrlen); str+= ulStrlen; c0d01e1c: 19f1 adds r1, r6, r7 c0d01e1e: 910a str r1, [sp, #40] ; 0x28 c0d01e20: 4607 mov r7, r0 c0d01e22: 2800 cmp r0, #0 c0d01e24: d032 beq.n c0d01e8c <snprintf+0x400> c0d01e26: 9809 ldr r0, [sp, #36] ; 0x24 s_pad: // // Write any required padding spaces // if(ulCount > ulIdx) c0d01e28: 42a0 cmp r0, r4 c0d01e2a: d986 bls.n c0d01d3a <snprintf+0x2ae> { ulCount -= ulIdx; c0d01e2c: 1b04 subs r4, r0, r4 c0d01e2e: 463e mov r6, r7 ulCount = MIN(ulCount, str_size); c0d01e30: 42b4 cmp r4, r6 c0d01e32: d300 bcc.n c0d01e36 <snprintf+0x3aa> c0d01e34: 4634 mov r4, r6 os_memset(str, ' ', ulCount); c0d01e36: 2120 movs r1, #32 c0d01e38: 9f0a ldr r7, [sp, #40] ; 0x28 c0d01e3a: 4638 mov r0, r7 c0d01e3c: 4622 mov r2, r4 c0d01e3e: f7fe ff31 bl c0d00ca4 <os_memset> str+= ulCount; str_size -= ulCount; c0d01e42: 1b36 subs r6, r6, r4 if(ulCount > ulIdx) { ulCount -= ulIdx; ulCount = MIN(ulCount, str_size); os_memset(str, ' ', ulCount); str+= ulCount; c0d01e44: 193f adds r7, r7, r4 c0d01e46: 970a str r7, [sp, #40] ; 0x28 c0d01e48: 4637 mov r7, r6 str_size -= ulCount; if (str_size == 0) { c0d01e4a: 2e00 cmp r6, #0 c0d01e4c: d01e beq.n c0d01e8c <snprintf+0x400> c0d01e4e: e774 b.n c0d01d3a <snprintf+0x2ae> c0d01e50: 461f mov r7, r3 c0d01e52: 900a str r0, [sp, #40] ; 0x28 c0d01e54: e771 b.n c0d01d3a <snprintf+0x2ae> while(*format) { // // Find the first non-% character, or the end of the string. // for(ulIdx = 0; (format[ulIdx] != '%') && (format[ulIdx] != '\0'); c0d01e56: 460e mov r6, r1 c0d01e58: 9c07 ldr r4, [sp, #28] c0d01e5a: e003 b.n c0d01e64 <snprintf+0x3d8> c0d01e5c: 1928 adds r0, r5, r4 c0d01e5e: 7840 ldrb r0, [r0, #1] c0d01e60: 1e76 subs r6, r6, #1 ulIdx++) c0d01e62: 1c64 adds r4, r4, #1 c0d01e64: b2c0 uxtb r0, r0 while(*format) { // // Find the first non-% character, or the end of the string. // for(ulIdx = 0; (format[ulIdx] != '%') && (format[ulIdx] != '\0'); c0d01e66: 2800 cmp r0, #0 c0d01e68: d001 beq.n c0d01e6e <snprintf+0x3e2> c0d01e6a: 2825 cmp r0, #37 ; 0x25 c0d01e6c: d1f6 bne.n c0d01e5c <snprintf+0x3d0> } // // Write this portion of the string. // ulIdx = MIN(ulIdx, str_size); c0d01e6e: 42bc cmp r4, r7 c0d01e70: d300 bcc.n c0d01e74 <snprintf+0x3e8> c0d01e72: 463c mov r4, r7 os_memmove(str, format, ulIdx); c0d01e74: 980a ldr r0, [sp, #40] ; 0x28 c0d01e76: 4629 mov r1, r5 c0d01e78: 4622 mov r2, r4 c0d01e7a: f7fe ff1c bl c0d00cb6 <os_memmove> c0d01e7e: 9706 str r7, [sp, #24] str+= ulIdx; str_size -= ulIdx; c0d01e80: 1b3f subs r7, r7, r4 // // Write this portion of the string. // ulIdx = MIN(ulIdx, str_size); os_memmove(str, format, ulIdx); str+= ulIdx; c0d01e82: 980a ldr r0, [sp, #40] ; 0x28 c0d01e84: 1902 adds r2, r0, r4 str_size -= ulIdx; if (str_size == 0) { c0d01e86: 2f00 cmp r7, #0 c0d01e88: d000 beq.n c0d01e8c <snprintf+0x400> c0d01e8a: e621 b.n c0d01ad0 <snprintf+0x44> // End the varargs processing. // va_end(vaArgP); return 0; } c0d01e8c: 2000 movs r0, #0 c0d01e8e: b010 add sp, #64 ; 0x40 c0d01e90: bcf0 pop {r4, r5, r6, r7} c0d01e92: bc02 pop {r1} c0d01e94: b001 add sp, #4 c0d01e96: 4708 bx r1 c0d01e98: 000026b0 .word 0x000026b0 c0d01e9c: 00002612 .word 0x00002612 c0d01ea0: 00002608 .word 0x00002608 c0d01ea4: 00002700 .word 0x00002700 c0d01ea8: 00002716 .word 0x00002716 c0d01eac <pic>: // only apply PIC conversion if link_address is in linked code (over 0xC0D00000 in our example) // this way, PIC call are armless if the address is not meant to be converted extern unsigned int _nvram; extern unsigned int _envram; unsigned int pic(unsigned int link_address) { c0d01eac: b580 push {r7, lr} // screen_printf(" %08X", link_address); if (link_address >= ((unsigned int)&_nvram) && link_address < ((unsigned int)&_envram)) { c0d01eae: 4904 ldr r1, [pc, #16] ; (c0d01ec0 <pic+0x14>) c0d01eb0: 4288 cmp r0, r1 c0d01eb2: d304 bcc.n c0d01ebe <pic+0x12> c0d01eb4: 4903 ldr r1, [pc, #12] ; (c0d01ec4 <pic+0x18>) c0d01eb6: 4288 cmp r0, r1 c0d01eb8: d201 bcs.n c0d01ebe <pic+0x12> link_address = pic_internal(link_address); c0d01eba: f000 f805 bl c0d01ec8 <pic_internal> // screen_printf(" -> %08X\n", link_address); } return link_address; c0d01ebe: bd80 pop {r7, pc} c0d01ec0: c0d00000 .word 0xc0d00000 c0d01ec4: c0d04940 .word 0xc0d04940 c0d01ec8 <pic_internal>: unsigned int pic_internal(unsigned int link_address) __attribute__((naked)); unsigned int pic_internal(unsigned int link_address) { // compute the delta offset between LinkMemAddr & ExecMemAddr __asm volatile ("mov r2, pc\n"); // r2 = 0x109004 c0d01ec8: 467a mov r2, pc __asm volatile ("ldr r1, =pic_internal\n"); // r1 = 0xC0D00001 c0d01eca: 4902 ldr r1, [pc, #8] ; (c0d01ed4 <pic_internal+0xc>) __asm volatile ("adds r1, r1, #3\n"); // r1 = 0xC0D00004 c0d01ecc: 1cc9 adds r1, r1, #3 __asm volatile ("subs r1, r1, r2\n"); // r1 = 0xC0BF7000 (delta between load and exec address) c0d01ece: 1a89 subs r1, r1, r2 // adjust value of the given parameter __asm volatile ("subs r0, r0, r1\n"); // r0 = 0xC0D0C244 => r0 = 0x115244 c0d01ed0: 1a40 subs r0, r0, r1 __asm volatile ("bx lr\n"); c0d01ed2: 4770 bx lr c0d01ed4: c0d01ec9 .word 0xc0d01ec9 c0d01ed8 <SVC_Call>: // avoid a separate asm file, but avoid any intrusion from the compiler unsigned int SVC_Call(unsigned int syscall_id, unsigned int * parameters) __attribute__ ((naked)); // r0 r1 unsigned int SVC_Call(unsigned int syscall_id, unsigned int * parameters) { // delegate svc asm volatile("svc #1":::"r0","r1"); c0d01ed8: df01 svc 1 // directly return R0 value asm volatile("bx lr"); c0d01eda: 4770 bx lr c0d01edc <check_api_level>: } void check_api_level ( unsigned int apiLevel ) { c0d01edc: b580 push {r7, lr} c0d01ede: b082 sub sp, #8 unsigned int ret; unsigned int retid; unsigned int parameters [0+1]; parameters[0] = (unsigned int)apiLevel; c0d01ee0: 9000 str r0, [sp, #0] retid = SVC_Call(SYSCALL_check_api_level_ID_IN, parameters); c0d01ee2: 4807 ldr r0, [pc, #28] ; (c0d01f00 <check_api_level+0x24>) c0d01ee4: 4669 mov r1, sp c0d01ee6: f7ff fff7 bl c0d01ed8 <SVC_Call> c0d01eea: aa01 add r2, sp, #4 asm volatile("str r1, %0":"=m"(ret)::"r1"); c0d01eec: 6011 str r1, [r2, #0] if (retid != SYSCALL_check_api_level_ID_OUT) { c0d01eee: 4905 ldr r1, [pc, #20] ; (c0d01f04 <check_api_level+0x28>) c0d01ef0: 4288 cmp r0, r1 c0d01ef2: d101 bne.n c0d01ef8 <check_api_level+0x1c> THROW(EXCEPTION_SECURITY); } } c0d01ef4: b002 add sp, #8 c0d01ef6: bd80 pop {r7, pc} unsigned int parameters [0+1]; parameters[0] = (unsigned int)apiLevel; retid = SVC_Call(SYSCALL_check_api_level_ID_IN, parameters); asm volatile("str r1, %0":"=m"(ret)::"r1"); if (retid != SYSCALL_check_api_level_ID_OUT) { THROW(EXCEPTION_SECURITY); c0d01ef8: 2004 movs r0, #4 c0d01efa: f7fe ff90 bl c0d00e1e <os_longjmp> c0d01efe: 46c0 nop ; (mov r8, r8) c0d01f00: 60000137 .word 0x60000137 c0d01f04: 900001c6 .word 0x900001c6 c0d01f08 <reset>: } } void reset ( void ) { c0d01f08: b580 push {r7, lr} c0d01f0a: b082 sub sp, #8 unsigned int ret; unsigned int retid; unsigned int parameters [0]; retid = SVC_Call(SYSCALL_reset_ID_IN, parameters); c0d01f0c: 4806 ldr r0, [pc, #24] ; (c0d01f28 <reset+0x20>) c0d01f0e: a901 add r1, sp, #4 c0d01f10: f7ff ffe2 bl c0d01ed8 <SVC_Call> c0d01f14: 466a mov r2, sp asm volatile("str r1, %0":"=m"(ret)::"r1"); c0d01f16: 6011 str r1, [r2, #0] if (retid != SYSCALL_reset_ID_OUT) { c0d01f18: 4904 ldr r1, [pc, #16] ; (c0d01f2c <reset+0x24>) c0d01f1a: 4288 cmp r0, r1 c0d01f1c: d101 bne.n c0d01f22 <reset+0x1a> THROW(EXCEPTION_SECURITY); } } c0d01f1e: b002 add sp, #8 c0d01f20: bd80 pop {r7, pc} unsigned int retid; unsigned int parameters [0]; retid = SVC_Call(SYSCALL_reset_ID_IN, parameters); asm volatile("str r1, %0":"=m"(ret)::"r1"); if (retid != SYSCALL_reset_ID_OUT) { THROW(EXCEPTION_SECURITY); c0d01f22: 2004 movs r0, #4 c0d01f24: f7fe ff7b bl c0d00e1e <os_longjmp> c0d01f28: 60000200 .word 0x60000200 c0d01f2c: 900002f1 .word 0x900002f1 c0d01f30 <cx_rng>: } return (unsigned char)ret; } unsigned char * cx_rng ( unsigned char * buffer, unsigned int len ) { c0d01f30: b580 push {r7, lr} c0d01f32: b084 sub sp, #16 unsigned int ret; unsigned int retid; unsigned int parameters [0+2]; parameters[0] = (unsigned int)buffer; c0d01f34: 9001 str r0, [sp, #4] parameters[1] = (unsigned int)len; c0d01f36: 9102 str r1, [sp, #8] retid = SVC_Call(SYSCALL_cx_rng_ID_IN, parameters); c0d01f38: 4807 ldr r0, [pc, #28] ; (c0d01f58 <cx_rng+0x28>) c0d01f3a: a901 add r1, sp, #4 c0d01f3c: f7ff ffcc bl c0d01ed8 <SVC_Call> c0d01f40: aa03 add r2, sp, #12 asm volatile("str r1, %0":"=m"(ret)::"r1"); c0d01f42: 6011 str r1, [r2, #0] if (retid != SYSCALL_cx_rng_ID_OUT) { c0d01f44: 4905 ldr r1, [pc, #20] ; (c0d01f5c <cx_rng+0x2c>) c0d01f46: 4288 cmp r0, r1 c0d01f48: d102 bne.n c0d01f50 <cx_rng+0x20> THROW(EXCEPTION_SECURITY); } return (unsigned char *)ret; c0d01f4a: 9803 ldr r0, [sp, #12] c0d01f4c: b004 add sp, #16 c0d01f4e: bd80 pop {r7, pc} parameters[0] = (unsigned int)buffer; parameters[1] = (unsigned int)len; retid = SVC_Call(SYSCALL_cx_rng_ID_IN, parameters); asm volatile("str r1, %0":"=m"(ret)::"r1"); if (retid != SYSCALL_cx_rng_ID_OUT) { THROW(EXCEPTION_SECURITY); c0d01f50: 2004 movs r0, #4 c0d01f52: f7fe ff64 bl c0d00e1e <os_longjmp> c0d01f56: 46c0 nop ; (mov r8, r8) c0d01f58: 6000052c .word 0x6000052c c0d01f5c: 90000567 .word 0x90000567 c0d01f60 <cx_hash>: } return (int)ret; } int cx_hash ( cx_hash_t * hash, int mode, const unsigned char * in, unsigned int len, unsigned char * out, unsigned int out_len ) { c0d01f60: b580 push {r7, lr} c0d01f62: b088 sub sp, #32 unsigned int ret; unsigned int retid; unsigned int parameters [0+6]; parameters[0] = (unsigned int)hash; c0d01f64: af01 add r7, sp, #4 c0d01f66: c70f stmia r7!, {r0, r1, r2, r3} c0d01f68: 980a ldr r0, [sp, #40] ; 0x28 parameters[1] = (unsigned int)mode; parameters[2] = (unsigned int)in; parameters[3] = (unsigned int)len; parameters[4] = (unsigned int)out; c0d01f6a: 9005 str r0, [sp, #20] c0d01f6c: 980b ldr r0, [sp, #44] ; 0x2c parameters[5] = (unsigned int)out_len; c0d01f6e: 9006 str r0, [sp, #24] retid = SVC_Call(SYSCALL_cx_hash_ID_IN, parameters); c0d01f70: 4807 ldr r0, [pc, #28] ; (c0d01f90 <cx_hash+0x30>) c0d01f72: a901 add r1, sp, #4 c0d01f74: f7ff ffb0 bl c0d01ed8 <SVC_Call> c0d01f78: aa07 add r2, sp, #28 asm volatile("str r1, %0":"=m"(ret)::"r1"); c0d01f7a: 6011 str r1, [r2, #0] if (retid != SYSCALL_cx_hash_ID_OUT) { c0d01f7c: 4905 ldr r1, [pc, #20] ; (c0d01f94 <cx_hash+0x34>) c0d01f7e: 4288 cmp r0, r1 c0d01f80: d102 bne.n c0d01f88 <cx_hash+0x28> THROW(EXCEPTION_SECURITY); } return (int)ret; c0d01f82: 9807 ldr r0, [sp, #28] c0d01f84: b008 add sp, #32 c0d01f86: bd80 pop {r7, pc} parameters[4] = (unsigned int)out; parameters[5] = (unsigned int)out_len; retid = SVC_Call(SYSCALL_cx_hash_ID_IN, parameters); asm volatile("str r1, %0":"=m"(ret)::"r1"); if (retid != SYSCALL_cx_hash_ID_OUT) { THROW(EXCEPTION_SECURITY); c0d01f88: 2004 movs r0, #4 c0d01f8a: f7fe ff48 bl c0d00e1e <os_longjmp> c0d01f8e: 46c0 nop ; (mov r8, r8) c0d01f90: 6000073b .word 0x6000073b c0d01f94: 900007ad .word 0x900007ad c0d01f98 <cx_ripemd160_init>: } return (int)ret; } int cx_ripemd160_init ( cx_ripemd160_t * hash ) { c0d01f98: b580 push {r7, lr} c0d01f9a: b082 sub sp, #8 unsigned int ret; unsigned int retid; unsigned int parameters [0+1]; parameters[0] = (unsigned int)hash; c0d01f9c: 9000 str r0, [sp, #0] retid = SVC_Call(SYSCALL_cx_ripemd160_init_ID_IN, parameters); c0d01f9e: 4807 ldr r0, [pc, #28] ; (c0d01fbc <cx_ripemd160_init+0x24>) c0d01fa0: 4669 mov r1, sp c0d01fa2: f7ff ff99 bl c0d01ed8 <SVC_Call> c0d01fa6: aa01 add r2, sp, #4 asm volatile("str r1, %0":"=m"(ret)::"r1"); c0d01fa8: 6011 str r1, [r2, #0] if (retid != SYSCALL_cx_ripemd160_init_ID_OUT) { c0d01faa: 4905 ldr r1, [pc, #20] ; (c0d01fc0 <cx_ripemd160_init+0x28>) c0d01fac: 4288 cmp r0, r1 c0d01fae: d102 bne.n c0d01fb6 <cx_ripemd160_init+0x1e> THROW(EXCEPTION_SECURITY); } return (int)ret; c0d01fb0: 9801 ldr r0, [sp, #4] c0d01fb2: b002 add sp, #8 c0d01fb4: bd80 pop {r7, pc} unsigned int parameters [0+1]; parameters[0] = (unsigned int)hash; retid = SVC_Call(SYSCALL_cx_ripemd160_init_ID_IN, parameters); asm volatile("str r1, %0":"=m"(ret)::"r1"); if (retid != SYSCALL_cx_ripemd160_init_ID_OUT) { THROW(EXCEPTION_SECURITY); c0d01fb6: 2004 movs r0, #4 c0d01fb8: f7fe ff31 bl c0d00e1e <os_longjmp> c0d01fbc: 6000087f .word 0x6000087f c0d01fc0: 900008f8 .word 0x900008f8 c0d01fc4 <cx_sha256_init>: } return (int)ret; } int cx_sha256_init ( cx_sha256_t * hash ) { c0d01fc4: b580 push {r7, lr} c0d01fc6: b082 sub sp, #8 unsigned int ret; unsigned int retid; unsigned int parameters [0+1]; parameters[0] = (unsigned int)hash; c0d01fc8: 9000 str r0, [sp, #0] retid = SVC_Call(SYSCALL_cx_sha256_init_ID_IN, parameters); c0d01fca: 4807 ldr r0, [pc, #28] ; (c0d01fe8 <cx_sha256_init+0x24>) c0d01fcc: 4669 mov r1, sp c0d01fce: f7ff ff83 bl c0d01ed8 <SVC_Call> c0d01fd2: aa01 add r2, sp, #4 asm volatile("str r1, %0":"=m"(ret)::"r1"); c0d01fd4: 6011 str r1, [r2, #0] if (retid != SYSCALL_cx_sha256_init_ID_OUT) { c0d01fd6: 4905 ldr r1, [pc, #20] ; (c0d01fec <cx_sha256_init+0x28>) c0d01fd8: 4288 cmp r0, r1 c0d01fda: d102 bne.n c0d01fe2 <cx_sha256_init+0x1e> THROW(EXCEPTION_SECURITY); } return (int)ret; c0d01fdc: 9801 ldr r0, [sp, #4] c0d01fde: b002 add sp, #8 c0d01fe0: bd80 pop {r7, pc} unsigned int parameters [0+1]; parameters[0] = (unsigned int)hash; retid = SVC_Call(SYSCALL_cx_sha256_init_ID_IN, parameters); asm volatile("str r1, %0":"=m"(ret)::"r1"); if (retid != SYSCALL_cx_sha256_init_ID_OUT) { THROW(EXCEPTION_SECURITY); c0d01fe2: 2004 movs r0, #4 c0d01fe4: f7fe ff1b bl c0d00e1e <os_longjmp> c0d01fe8: 60000adb .word 0x60000adb c0d01fec: 90000a64 .word 0x90000a64 c0d01ff0 <cx_ecfp_init_public_key>: } return (int)ret; } int cx_ecfp_init_public_key ( cx_curve_t curve, const unsigned char * rawkey, unsigned int key_len, cx_ecfp_public_key_t * key ) { c0d01ff0: b580 push {r7, lr} c0d01ff2: b086 sub sp, #24 unsigned int ret; unsigned int retid; unsigned int parameters [0+4]; parameters[0] = (unsigned int)curve; c0d01ff4: af01 add r7, sp, #4 c0d01ff6: c70f stmia r7!, {r0, r1, r2, r3} parameters[1] = (unsigned int)rawkey; parameters[2] = (unsigned int)key_len; parameters[3] = (unsigned int)key; retid = SVC_Call(SYSCALL_cx_ecfp_init_public_key_ID_IN, parameters); c0d01ff8: 4807 ldr r0, [pc, #28] ; (c0d02018 <cx_ecfp_init_public_key+0x28>) c0d01ffa: a901 add r1, sp, #4 c0d01ffc: f7ff ff6c bl c0d01ed8 <SVC_Call> c0d02000: aa05 add r2, sp, #20 asm volatile("str r1, %0":"=m"(ret)::"r1"); c0d02002: 6011 str r1, [r2, #0] if (retid != SYSCALL_cx_ecfp_init_public_key_ID_OUT) { c0d02004: 4905 ldr r1, [pc, #20] ; (c0d0201c <cx_ecfp_init_public_key+0x2c>) c0d02006: 4288 cmp r0, r1 c0d02008: d102 bne.n c0d02010 <cx_ecfp_init_public_key+0x20> THROW(EXCEPTION_SECURITY); } return (int)ret; c0d0200a: 9805 ldr r0, [sp, #20] c0d0200c: b006 add sp, #24 c0d0200e: bd80 pop {r7, pc} parameters[2] = (unsigned int)key_len; parameters[3] = (unsigned int)key; retid = SVC_Call(SYSCALL_cx_ecfp_init_public_key_ID_IN, parameters); asm volatile("str r1, %0":"=m"(ret)::"r1"); if (retid != SYSCALL_cx_ecfp_init_public_key_ID_OUT) { THROW(EXCEPTION_SECURITY); c0d02010: 2004 movs r0, #4 c0d02012: f7fe ff04 bl c0d00e1e <os_longjmp> c0d02016: 46c0 nop ; (mov r8, r8) c0d02018: 60002ded .word 0x60002ded c0d0201c: 90002d49 .word 0x90002d49 c0d02020 <cx_ecfp_init_private_key>: } return (int)ret; } int cx_ecfp_init_private_key ( cx_curve_t curve, const unsigned char * rawkey, unsigned int key_len, cx_ecfp_private_key_t * pvkey ) { c0d02020: b580 push {r7, lr} c0d02022: b086 sub sp, #24 unsigned int ret; unsigned int retid; unsigned int parameters [0+4]; parameters[0] = (unsigned int)curve; c0d02024: af01 add r7, sp, #4 c0d02026: c70f stmia r7!, {r0, r1, r2, r3} parameters[1] = (unsigned int)rawkey; parameters[2] = (unsigned int)key_len; parameters[3] = (unsigned int)pvkey; retid = SVC_Call(SYSCALL_cx_ecfp_init_private_key_ID_IN, parameters); c0d02028: 4807 ldr r0, [pc, #28] ; (c0d02048 <cx_ecfp_init_private_key+0x28>) c0d0202a: a901 add r1, sp, #4 c0d0202c: f7ff ff54 bl c0d01ed8 <SVC_Call> c0d02030: aa05 add r2, sp, #20 asm volatile("str r1, %0":"=m"(ret)::"r1"); c0d02032: 6011 str r1, [r2, #0] if (retid != SYSCALL_cx_ecfp_init_private_key_ID_OUT) { c0d02034: 4905 ldr r1, [pc, #20] ; (c0d0204c <cx_ecfp_init_private_key+0x2c>) c0d02036: 4288 cmp r0, r1 c0d02038: d102 bne.n c0d02040 <cx_ecfp_init_private_key+0x20> THROW(EXCEPTION_SECURITY); } return (int)ret; c0d0203a: 9805 ldr r0, [sp, #20] c0d0203c: b006 add sp, #24 c0d0203e: bd80 pop {r7, pc} parameters[2] = (unsigned int)key_len; parameters[3] = (unsigned int)pvkey; retid = SVC_Call(SYSCALL_cx_ecfp_init_private_key_ID_IN, parameters); asm volatile("str r1, %0":"=m"(ret)::"r1"); if (retid != SYSCALL_cx_ecfp_init_private_key_ID_OUT) { THROW(EXCEPTION_SECURITY); c0d02040: 2004 movs r0, #4 c0d02042: f7fe feec bl c0d00e1e <os_longjmp> c0d02046: 46c0 nop ; (mov r8, r8) c0d02048: 60002eea .word 0x60002eea c0d0204c: 90002e63 .word 0x90002e63 c0d02050 <cx_ecfp_generate_pair>: } return (int)ret; } int cx_ecfp_generate_pair ( cx_curve_t curve, cx_ecfp_public_key_t * pubkey, cx_ecfp_private_key_t * privkey, int keepprivate ) { c0d02050: b580 push {r7, lr} c0d02052: b086 sub sp, #24 unsigned int ret; unsigned int retid; unsigned int parameters [0+4]; parameters[0] = (unsigned int)curve; c0d02054: af01 add r7, sp, #4 c0d02056: c70f stmia r7!, {r0, r1, r2, r3} parameters[1] = (unsigned int)pubkey; parameters[2] = (unsigned int)privkey; parameters[3] = (unsigned int)keepprivate; retid = SVC_Call(SYSCALL_cx_ecfp_generate_pair_ID_IN, parameters); c0d02058: 4807 ldr r0, [pc, #28] ; (c0d02078 <cx_ecfp_generate_pair+0x28>) c0d0205a: a901 add r1, sp, #4 c0d0205c: f7ff ff3c bl c0d01ed8 <SVC_Call> c0d02060: aa05 add r2, sp, #20 asm volatile("str r1, %0":"=m"(ret)::"r1"); c0d02062: 6011 str r1, [r2, #0] if (retid != SYSCALL_cx_ecfp_generate_pair_ID_OUT) { c0d02064: 4905 ldr r1, [pc, #20] ; (c0d0207c <cx_ecfp_generate_pair+0x2c>) c0d02066: 4288 cmp r0, r1 c0d02068: d102 bne.n c0d02070 <cx_ecfp_generate_pair+0x20> THROW(EXCEPTION_SECURITY); } return (int)ret; c0d0206a: 9805 ldr r0, [sp, #20] c0d0206c: b006 add sp, #24 c0d0206e: bd80 pop {r7, pc} parameters[2] = (unsigned int)privkey; parameters[3] = (unsigned int)keepprivate; retid = SVC_Call(SYSCALL_cx_ecfp_generate_pair_ID_IN, parameters); asm volatile("str r1, %0":"=m"(ret)::"r1"); if (retid != SYSCALL_cx_ecfp_generate_pair_ID_OUT) { THROW(EXCEPTION_SECURITY); c0d02070: 2004 movs r0, #4 c0d02072: f7fe fed4 bl c0d00e1e <os_longjmp> c0d02076: 46c0 nop ; (mov r8, r8) c0d02078: 60002f2e .word 0x60002f2e c0d0207c: 90002f74 .word 0x90002f74 c0d02080 <cx_ecdsa_sign>: } return (int)ret; } int cx_ecdsa_sign ( const cx_ecfp_private_key_t * pvkey, int mode, cx_md_t hashID, const unsigned char * hash, unsigned int hash_len, unsigned char * sig, unsigned int sig_len, unsigned int * info ) { c0d02080: b580 push {r7, lr} c0d02082: b08a sub sp, #40 ; 0x28 unsigned int ret; unsigned int retid; unsigned int parameters [0+8]; parameters[0] = (unsigned int)pvkey; c0d02084: af01 add r7, sp, #4 c0d02086: c70f stmia r7!, {r0, r1, r2, r3} c0d02088: 980c ldr r0, [sp, #48] ; 0x30 parameters[1] = (unsigned int)mode; parameters[2] = (unsigned int)hashID; parameters[3] = (unsigned int)hash; parameters[4] = (unsigned int)hash_len; c0d0208a: 9005 str r0, [sp, #20] c0d0208c: 980d ldr r0, [sp, #52] ; 0x34 parameters[5] = (unsigned int)sig; c0d0208e: 9006 str r0, [sp, #24] c0d02090: 980e ldr r0, [sp, #56] ; 0x38 parameters[6] = (unsigned int)sig_len; c0d02092: 9007 str r0, [sp, #28] c0d02094: 980f ldr r0, [sp, #60] ; 0x3c parameters[7] = (unsigned int)info; c0d02096: 9008 str r0, [sp, #32] retid = SVC_Call(SYSCALL_cx_ecdsa_sign_ID_IN, parameters); c0d02098: 4807 ldr r0, [pc, #28] ; (c0d020b8 <cx_ecdsa_sign+0x38>) c0d0209a: a901 add r1, sp, #4 c0d0209c: f7ff ff1c bl c0d01ed8 <SVC_Call> c0d020a0: aa09 add r2, sp, #36 ; 0x24 asm volatile("str r1, %0":"=m"(ret)::"r1"); c0d020a2: 6011 str r1, [r2, #0] if (retid != SYSCALL_cx_ecdsa_sign_ID_OUT) { c0d020a4: 4905 ldr r1, [pc, #20] ; (c0d020bc <cx_ecdsa_sign+0x3c>) c0d020a6: 4288 cmp r0, r1 c0d020a8: d102 bne.n c0d020b0 <cx_ecdsa_sign+0x30> THROW(EXCEPTION_SECURITY); } return (int)ret; c0d020aa: 9809 ldr r0, [sp, #36] ; 0x24 c0d020ac: b00a add sp, #40 ; 0x28 c0d020ae: bd80 pop {r7, pc} parameters[6] = (unsigned int)sig_len; parameters[7] = (unsigned int)info; retid = SVC_Call(SYSCALL_cx_ecdsa_sign_ID_IN, parameters); asm volatile("str r1, %0":"=m"(ret)::"r1"); if (retid != SYSCALL_cx_ecdsa_sign_ID_OUT) { THROW(EXCEPTION_SECURITY); c0d020b0: 2004 movs r0, #4 c0d020b2: f7fe feb4 bl c0d00e1e <os_longjmp> c0d020b6: 46c0 nop ; (mov r8, r8) c0d020b8: 600038f3 .word 0x600038f3 c0d020bc: 90003876 .word 0x90003876 c0d020c0 <cx_crc16_update>: } return (unsigned short)ret; } unsigned short cx_crc16_update ( unsigned short crc, const void * buffer, unsigned int len ) { c0d020c0: b580 push {r7, lr} c0d020c2: b084 sub sp, #16 unsigned int ret; unsigned int retid; unsigned int parameters [0+3]; parameters[0] = (unsigned int)crc; c0d020c4: ab00 add r3, sp, #0 c0d020c6: c307 stmia r3!, {r0, r1, r2} parameters[1] = (unsigned int)buffer; parameters[2] = (unsigned int)len; retid = SVC_Call(SYSCALL_cx_crc16_update_ID_IN, parameters); c0d020c8: 4807 ldr r0, [pc, #28] ; (c0d020e8 <cx_crc16_update+0x28>) c0d020ca: 4669 mov r1, sp c0d020cc: f7ff ff04 bl c0d01ed8 <SVC_Call> c0d020d0: aa03 add r2, sp, #12 asm volatile("str r1, %0":"=m"(ret)::"r1"); c0d020d2: 6011 str r1, [r2, #0] if (retid != SYSCALL_cx_crc16_update_ID_OUT) { c0d020d4: 4905 ldr r1, [pc, #20] ; (c0d020ec <cx_crc16_update+0x2c>) c0d020d6: 4288 cmp r0, r1 c0d020d8: d103 bne.n c0d020e2 <cx_crc16_update+0x22> c0d020da: a803 add r0, sp, #12 THROW(EXCEPTION_SECURITY); } return (unsigned short)ret; c0d020dc: 8800 ldrh r0, [r0, #0] c0d020de: b004 add sp, #16 c0d020e0: bd80 pop {r7, pc} parameters[1] = (unsigned int)buffer; parameters[2] = (unsigned int)len; retid = SVC_Call(SYSCALL_cx_crc16_update_ID_IN, parameters); asm volatile("str r1, %0":"=m"(ret)::"r1"); if (retid != SYSCALL_cx_crc16_update_ID_OUT) { THROW(EXCEPTION_SECURITY); c0d020e2: 2004 movs r0, #4 c0d020e4: f7fe fe9b bl c0d00e1e <os_longjmp> c0d020e8: 60003c9e .word 0x60003c9e c0d020ec: 90003cb9 .word 0x90003cb9 c0d020f0 <os_perso_derive_node_bip32>: } return (unsigned int)ret; } void os_perso_derive_node_bip32 ( cx_curve_t curve, const unsigned int * path, unsigned int pathLength, unsigned char * privateKey, unsigned char * chain ) { c0d020f0: b580 push {r7, lr} c0d020f2: b086 sub sp, #24 unsigned int ret; unsigned int retid; unsigned int parameters [0+5]; parameters[0] = (unsigned int)curve; c0d020f4: af00 add r7, sp, #0 c0d020f6: c70f stmia r7!, {r0, r1, r2, r3} c0d020f8: 9808 ldr r0, [sp, #32] parameters[1] = (unsigned int)path; parameters[2] = (unsigned int)pathLength; parameters[3] = (unsigned int)privateKey; parameters[4] = (unsigned int)chain; c0d020fa: 9004 str r0, [sp, #16] retid = SVC_Call(SYSCALL_os_perso_derive_node_bip32_ID_IN, parameters); c0d020fc: 4806 ldr r0, [pc, #24] ; (c0d02118 <os_perso_derive_node_bip32+0x28>) c0d020fe: 4669 mov r1, sp c0d02100: f7ff feea bl c0d01ed8 <SVC_Call> c0d02104: aa05 add r2, sp, #20 asm volatile("str r1, %0":"=m"(ret)::"r1"); c0d02106: 6011 str r1, [r2, #0] if (retid != SYSCALL_os_perso_derive_node_bip32_ID_OUT) { c0d02108: 4904 ldr r1, [pc, #16] ; (c0d0211c <os_perso_derive_node_bip32+0x2c>) c0d0210a: 4288 cmp r0, r1 c0d0210c: d101 bne.n c0d02112 <os_perso_derive_node_bip32+0x22> THROW(EXCEPTION_SECURITY); } } c0d0210e: b006 add sp, #24 c0d02110: bd80 pop {r7, pc} parameters[3] = (unsigned int)privateKey; parameters[4] = (unsigned int)chain; retid = SVC_Call(SYSCALL_os_perso_derive_node_bip32_ID_IN, parameters); asm volatile("str r1, %0":"=m"(ret)::"r1"); if (retid != SYSCALL_os_perso_derive_node_bip32_ID_OUT) { THROW(EXCEPTION_SECURITY); c0d02112: 2004 movs r0, #4 c0d02114: f7fe fe83 bl c0d00e1e <os_longjmp> c0d02118: 600053ba .word 0x600053ba c0d0211c: 9000531e .word 0x9000531e c0d02120 <os_sched_exit>: } return (unsigned int)ret; } void os_sched_exit ( unsigned int exit_code ) { c0d02120: b580 push {r7, lr} c0d02122: b082 sub sp, #8 unsigned int ret; unsigned int retid; unsigned int parameters [0+1]; parameters[0] = (unsigned int)exit_code; c0d02124: 9000 str r0, [sp, #0] retid = SVC_Call(SYSCALL_os_sched_exit_ID_IN, parameters); c0d02126: 4807 ldr r0, [pc, #28] ; (c0d02144 <os_sched_exit+0x24>) c0d02128: 4669 mov r1, sp c0d0212a: f7ff fed5 bl c0d01ed8 <SVC_Call> c0d0212e: aa01 add r2, sp, #4 asm volatile("str r1, %0":"=m"(ret)::"r1"); c0d02130: 6011 str r1, [r2, #0] if (retid != SYSCALL_os_sched_exit_ID_OUT) { c0d02132: 4905 ldr r1, [pc, #20] ; (c0d02148 <os_sched_exit+0x28>) c0d02134: 4288 cmp r0, r1 c0d02136: d101 bne.n c0d0213c <os_sched_exit+0x1c> THROW(EXCEPTION_SECURITY); } } c0d02138: b002 add sp, #8 c0d0213a: bd80 pop {r7, pc} unsigned int parameters [0+1]; parameters[0] = (unsigned int)exit_code; retid = SVC_Call(SYSCALL_os_sched_exit_ID_IN, parameters); asm volatile("str r1, %0":"=m"(ret)::"r1"); if (retid != SYSCALL_os_sched_exit_ID_OUT) { THROW(EXCEPTION_SECURITY); c0d0213c: 2004 movs r0, #4 c0d0213e: f7fe fe6e bl c0d00e1e <os_longjmp> c0d02142: 46c0 nop ; (mov r8, r8) c0d02144: 600062e1 .word 0x600062e1 c0d02148: 9000626f .word 0x9000626f c0d0214c <os_ux>: THROW(EXCEPTION_SECURITY); } } unsigned int os_ux ( bolos_ux_params_t * params ) { c0d0214c: b580 push {r7, lr} c0d0214e: b082 sub sp, #8 unsigned int ret; unsigned int retid; unsigned int parameters [0+1]; parameters[0] = (unsigned int)params; c0d02150: 9000 str r0, [sp, #0] retid = SVC_Call(SYSCALL_os_ux_ID_IN, parameters); c0d02152: 4807 ldr r0, [pc, #28] ; (c0d02170 <os_ux+0x24>) c0d02154: 4669 mov r1, sp c0d02156: f7ff febf bl c0d01ed8 <SVC_Call> c0d0215a: aa01 add r2, sp, #4 asm volatile("str r1, %0":"=m"(ret)::"r1"); c0d0215c: 6011 str r1, [r2, #0] if (retid != SYSCALL_os_ux_ID_OUT) { c0d0215e: 4905 ldr r1, [pc, #20] ; (c0d02174 <os_ux+0x28>) c0d02160: 4288 cmp r0, r1 c0d02162: d102 bne.n c0d0216a <os_ux+0x1e> THROW(EXCEPTION_SECURITY); } return (unsigned int)ret; c0d02164: 9801 ldr r0, [sp, #4] c0d02166: b002 add sp, #8 c0d02168: bd80 pop {r7, pc} unsigned int parameters [0+1]; parameters[0] = (unsigned int)params; retid = SVC_Call(SYSCALL_os_ux_ID_IN, parameters); asm volatile("str r1, %0":"=m"(ret)::"r1"); if (retid != SYSCALL_os_ux_ID_OUT) { THROW(EXCEPTION_SECURITY); c0d0216a: 2004 movs r0, #4 c0d0216c: f7fe fe57 bl c0d00e1e <os_longjmp> c0d02170: 60006458 .word 0x60006458 c0d02174: 9000641f .word 0x9000641f c0d02178 <os_flags>: THROW(EXCEPTION_SECURITY); } } unsigned int os_flags ( void ) { c0d02178: b580 push {r7, lr} c0d0217a: b082 sub sp, #8 unsigned int ret; unsigned int retid; unsigned int parameters [0]; retid = SVC_Call(SYSCALL_os_flags_ID_IN, parameters); c0d0217c: 4807 ldr r0, [pc, #28] ; (c0d0219c <os_flags+0x24>) c0d0217e: a901 add r1, sp, #4 c0d02180: f7ff feaa bl c0d01ed8 <SVC_Call> c0d02184: 466a mov r2, sp asm volatile("str r1, %0":"=m"(ret)::"r1"); c0d02186: 6011 str r1, [r2, #0] if (retid != SYSCALL_os_flags_ID_OUT) { c0d02188: 4905 ldr r1, [pc, #20] ; (c0d021a0 <os_flags+0x28>) c0d0218a: 4288 cmp r0, r1 c0d0218c: d102 bne.n c0d02194 <os_flags+0x1c> THROW(EXCEPTION_SECURITY); } return (unsigned int)ret; c0d0218e: 9800 ldr r0, [sp, #0] c0d02190: b002 add sp, #8 c0d02192: bd80 pop {r7, pc} unsigned int retid; unsigned int parameters [0]; retid = SVC_Call(SYSCALL_os_flags_ID_IN, parameters); asm volatile("str r1, %0":"=m"(ret)::"r1"); if (retid != SYSCALL_os_flags_ID_OUT) { THROW(EXCEPTION_SECURITY); c0d02194: 2004 movs r0, #4 c0d02196: f7fe fe42 bl c0d00e1e <os_longjmp> c0d0219a: 46c0 nop ; (mov r8, r8) c0d0219c: 6000686e .word 0x6000686e c0d021a0: 9000687f .word 0x9000687f c0d021a4 <os_registry_get_current_app_tag>: } return (unsigned int)ret; } unsigned int os_registry_get_current_app_tag ( unsigned int tag, unsigned char * buffer, unsigned int maxlen ) { c0d021a4: b580 push {r7, lr} c0d021a6: b084 sub sp, #16 unsigned int ret; unsigned int retid; unsigned int parameters [0+3]; parameters[0] = (unsigned int)tag; c0d021a8: ab00 add r3, sp, #0 c0d021aa: c307 stmia r3!, {r0, r1, r2} parameters[1] = (unsigned int)buffer; parameters[2] = (unsigned int)maxlen; retid = SVC_Call(SYSCALL_os_registry_get_current_app_tag_ID_IN, parameters); c0d021ac: 4807 ldr r0, [pc, #28] ; (c0d021cc <os_registry_get_current_app_tag+0x28>) c0d021ae: 4669 mov r1, sp c0d021b0: f7ff fe92 bl c0d01ed8 <SVC_Call> c0d021b4: aa03 add r2, sp, #12 asm volatile("str r1, %0":"=m"(ret)::"r1"); c0d021b6: 6011 str r1, [r2, #0] if (retid != SYSCALL_os_registry_get_current_app_tag_ID_OUT) { c0d021b8: 4905 ldr r1, [pc, #20] ; (c0d021d0 <os_registry_get_current_app_tag+0x2c>) c0d021ba: 4288 cmp r0, r1 c0d021bc: d102 bne.n c0d021c4 <os_registry_get_current_app_tag+0x20> THROW(EXCEPTION_SECURITY); } return (unsigned int)ret; c0d021be: 9803 ldr r0, [sp, #12] c0d021c0: b004 add sp, #16 c0d021c2: bd80 pop {r7, pc} parameters[1] = (unsigned int)buffer; parameters[2] = (unsigned int)maxlen; retid = SVC_Call(SYSCALL_os_registry_get_current_app_tag_ID_IN, parameters); asm volatile("str r1, %0":"=m"(ret)::"r1"); if (retid != SYSCALL_os_registry_get_current_app_tag_ID_OUT) { THROW(EXCEPTION_SECURITY); c0d021c4: 2004 movs r0, #4 c0d021c6: f7fe fe2a bl c0d00e1e <os_longjmp> c0d021ca: 46c0 nop ; (mov r8, r8) c0d021cc: 600070d4 .word 0x600070d4 c0d021d0: 90007087 .word 0x90007087 c0d021d4 <io_seproxyhal_spi_send>: } return (unsigned int)ret; } void io_seproxyhal_spi_send ( const unsigned char * buffer, unsigned short length ) { c0d021d4: b580 push {r7, lr} c0d021d6: b084 sub sp, #16 unsigned int ret; unsigned int retid; unsigned int parameters [0+2]; parameters[0] = (unsigned int)buffer; c0d021d8: 9001 str r0, [sp, #4] parameters[1] = (unsigned int)length; c0d021da: 9102 str r1, [sp, #8] retid = SVC_Call(SYSCALL_io_seproxyhal_spi_send_ID_IN, parameters); c0d021dc: 4806 ldr r0, [pc, #24] ; (c0d021f8 <io_seproxyhal_spi_send+0x24>) c0d021de: a901 add r1, sp, #4 c0d021e0: f7ff fe7a bl c0d01ed8 <SVC_Call> c0d021e4: aa03 add r2, sp, #12 asm volatile("str r1, %0":"=m"(ret)::"r1"); c0d021e6: 6011 str r1, [r2, #0] if (retid != SYSCALL_io_seproxyhal_spi_send_ID_OUT) { c0d021e8: 4904 ldr r1, [pc, #16] ; (c0d021fc <io_seproxyhal_spi_send+0x28>) c0d021ea: 4288 cmp r0, r1 c0d021ec: d101 bne.n c0d021f2 <io_seproxyhal_spi_send+0x1e> THROW(EXCEPTION_SECURITY); } } c0d021ee: b004 add sp, #16 c0d021f0: bd80 pop {r7, pc} parameters[0] = (unsigned int)buffer; parameters[1] = (unsigned int)length; retid = SVC_Call(SYSCALL_io_seproxyhal_spi_send_ID_IN, parameters); asm volatile("str r1, %0":"=m"(ret)::"r1"); if (retid != SYSCALL_io_seproxyhal_spi_send_ID_OUT) { THROW(EXCEPTION_SECURITY); c0d021f2: 2004 movs r0, #4 c0d021f4: f7fe fe13 bl c0d00e1e <os_longjmp> c0d021f8: 6000721c .word 0x6000721c c0d021fc: 900072f3 .word 0x900072f3 c0d02200 <io_seproxyhal_spi_is_status_sent>: } } unsigned int io_seproxyhal_spi_is_status_sent ( void ) { c0d02200: b580 push {r7, lr} c0d02202: b082 sub sp, #8 unsigned int ret; unsigned int retid; unsigned int parameters [0]; retid = SVC_Call(SYSCALL_io_seproxyhal_spi_is_status_sent_ID_IN, parameters); c0d02204: 4807 ldr r0, [pc, #28] ; (c0d02224 <io_seproxyhal_spi_is_status_sent+0x24>) c0d02206: a901 add r1, sp, #4 c0d02208: f7ff fe66 bl c0d01ed8 <SVC_Call> c0d0220c: 466a mov r2, sp asm volatile("str r1, %0":"=m"(ret)::"r1"); c0d0220e: 6011 str r1, [r2, #0] if (retid != SYSCALL_io_seproxyhal_spi_is_status_sent_ID_OUT) { c0d02210: 4905 ldr r1, [pc, #20] ; (c0d02228 <io_seproxyhal_spi_is_status_sent+0x28>) c0d02212: 4288 cmp r0, r1 c0d02214: d102 bne.n c0d0221c <io_seproxyhal_spi_is_status_sent+0x1c> THROW(EXCEPTION_SECURITY); } return (unsigned int)ret; c0d02216: 9800 ldr r0, [sp, #0] c0d02218: b002 add sp, #8 c0d0221a: bd80 pop {r7, pc} unsigned int retid; unsigned int parameters [0]; retid = SVC_Call(SYSCALL_io_seproxyhal_spi_is_status_sent_ID_IN, parameters); asm volatile("str r1, %0":"=m"(ret)::"r1"); if (retid != SYSCALL_io_seproxyhal_spi_is_status_sent_ID_OUT) { THROW(EXCEPTION_SECURITY); c0d0221c: 2004 movs r0, #4 c0d0221e: f7fe fdfe bl c0d00e1e <os_longjmp> c0d02222: 46c0 nop ; (mov r8, r8) c0d02224: 600073cf .word 0x600073cf c0d02228: 9000737f .word 0x9000737f c0d0222c <io_seproxyhal_spi_recv>: } return (unsigned int)ret; } unsigned short io_seproxyhal_spi_recv ( unsigned char * buffer, unsigned short maxlength, unsigned int flags ) { c0d0222c: b580 push {r7, lr} c0d0222e: b084 sub sp, #16 unsigned int ret; unsigned int retid; unsigned int parameters [0+3]; parameters[0] = (unsigned int)buffer; c0d02230: ab00 add r3, sp, #0 c0d02232: c307 stmia r3!, {r0, r1, r2} parameters[1] = (unsigned int)maxlength; parameters[2] = (unsigned int)flags; retid = SVC_Call(SYSCALL_io_seproxyhal_spi_recv_ID_IN, parameters); c0d02234: 4807 ldr r0, [pc, #28] ; (c0d02254 <io_seproxyhal_spi_recv+0x28>) c0d02236: 4669 mov r1, sp c0d02238: f7ff fe4e bl c0d01ed8 <SVC_Call> c0d0223c: aa03 add r2, sp, #12 asm volatile("str r1, %0":"=m"(ret)::"r1"); c0d0223e: 6011 str r1, [r2, #0] if (retid != SYSCALL_io_seproxyhal_spi_recv_ID_OUT) { c0d02240: 4905 ldr r1, [pc, #20] ; (c0d02258 <io_seproxyhal_spi_recv+0x2c>) c0d02242: 4288 cmp r0, r1 c0d02244: d103 bne.n c0d0224e <io_seproxyhal_spi_recv+0x22> c0d02246: a803 add r0, sp, #12 THROW(EXCEPTION_SECURITY); } return (unsigned short)ret; c0d02248: 8800 ldrh r0, [r0, #0] c0d0224a: b004 add sp, #16 c0d0224c: bd80 pop {r7, pc} parameters[1] = (unsigned int)maxlength; parameters[2] = (unsigned int)flags; retid = SVC_Call(SYSCALL_io_seproxyhal_spi_recv_ID_IN, parameters); asm volatile("str r1, %0":"=m"(ret)::"r1"); if (retid != SYSCALL_io_seproxyhal_spi_recv_ID_OUT) { THROW(EXCEPTION_SECURITY); c0d0224e: 2004 movs r0, #4 c0d02250: f7fe fde5 bl c0d00e1e <os_longjmp> c0d02254: 600074d1 .word 0x600074d1 c0d02258: 9000742b .word 0x9000742b c0d0225c <u2f_apdu_sign>: u2f_message_reply(service, U2F_CMD_MSG, (uint8_t *)SW_INTERNAL, sizeof(SW_INTERNAL)); } void u2f_apdu_sign(u2f_service_t *service, uint8_t p1, uint8_t p2, uint8_t *buffer, uint16_t length) { c0d0225c: b5f0 push {r4, r5, r6, r7, lr} c0d0225e: b085 sub sp, #20 UNUSED(p2); uint8_t keyHandleLength; uint8_t i; // can't process the apdu if another one is already scheduled in if (G_io_apdu_state != APDU_IDLE) { c0d02260: 4a34 ldr r2, [pc, #208] ; (c0d02334 <u2f_apdu_sign+0xd8>) c0d02262: 7812 ldrb r2, [r2, #0] for (i = 0; i < keyHandleLength; i++) { buffer[U2F_HANDLE_SIGN_HEADER_SIZE + i] ^= U2F_PROXY_MAGIC[i % (sizeof(U2F_PROXY_MAGIC)-1)]; } // Check that it looks like an APDU if (length != U2F_HANDLE_SIGN_HEADER_SIZE + 5 + buffer[U2F_HANDLE_SIGN_HEADER_SIZE + 4]) { u2f_message_reply(service, U2F_CMD_MSG, c0d02264: 2483 movs r4, #131 ; 0x83 UNUSED(p2); uint8_t keyHandleLength; uint8_t i; // can't process the apdu if another one is already scheduled in if (G_io_apdu_state != APDU_IDLE) { c0d02266: 2a00 cmp r2, #0 c0d02268: d002 beq.n c0d02270 <u2f_apdu_sign+0x14> u2f_message_reply(service, U2F_CMD_MSG, c0d0226a: 4a3b ldr r2, [pc, #236] ; (c0d02358 <u2f_apdu_sign+0xfc>) c0d0226c: 447a add r2, pc c0d0226e: e009 b.n c0d02284 <u2f_apdu_sign+0x28> c0d02270: 9a0a ldr r2, [sp, #40] ; 0x28 (uint8_t *)SW_BUSY, sizeof(SW_BUSY)); return; } if (length < U2F_HANDLE_SIGN_HEADER_SIZE + 5 /*at least an apdu header*/) { c0d02272: 2a45 cmp r2, #69 ; 0x45 c0d02274: d802 bhi.n c0d0227c <u2f_apdu_sign+0x20> u2f_message_reply(service, U2F_CMD_MSG, c0d02276: 4a39 ldr r2, [pc, #228] ; (c0d0235c <u2f_apdu_sign+0x100>) c0d02278: 447a add r2, pc c0d0227a: e003 b.n c0d02284 <u2f_apdu_sign+0x28> sizeof(SW_WRONG_LENGTH)); return; } // Confirm immediately if it's just a validation call if (p1 == P1_SIGN_CHECK_ONLY) { c0d0227c: 2907 cmp r1, #7 c0d0227e: d107 bne.n c0d02290 <u2f_apdu_sign+0x34> u2f_message_reply(service, U2F_CMD_MSG, c0d02280: 4a37 ldr r2, [pc, #220] ; (c0d02360 <u2f_apdu_sign+0x104>) c0d02282: 447a add r2, pc c0d02284: 2302 movs r3, #2 c0d02286: 4621 mov r1, r4 c0d02288: f000 fccf bl c0d02c2a <u2f_message_reply> app_dispatch(); if ((btchip_context_D.io_flags & IO_ASYNCH_REPLY) == 0) { u2f_proxy_response(service, btchip_context_D.outLength); } */ } c0d0228c: b005 add sp, #20 c0d0228e: bdf0 pop {r4, r5, r6, r7, pc} c0d02290: 9202 str r2, [sp, #8] c0d02292: 9401 str r4, [sp, #4] c0d02294: 9003 str r0, [sp, #12] sizeof(SW_PROOF_OF_PRESENCE_REQUIRED)); return; } // Unwrap magic keyHandleLength = buffer[U2F_HANDLE_SIGN_HEADER_SIZE-1]; c0d02296: 2040 movs r0, #64 ; 0x40 c0d02298: 9304 str r3, [sp, #16] c0d0229a: 5c1f ldrb r7, [r3, r0] // reply to the "get magic" question of the host if (keyHandleLength == 5) { c0d0229c: 2f00 cmp r7, #0 c0d0229e: d018 beq.n c0d022d2 <u2f_apdu_sign+0x76> c0d022a0: 2f05 cmp r7, #5 c0d022a2: 9e04 ldr r6, [sp, #16] c0d022a4: d107 bne.n c0d022b6 <u2f_apdu_sign+0x5a> // GET U2F PROXY PARAMETERS // this apdu is not subject to proxy magic masking // APDU is F1 D0 00 00 00 to get the magic proxy // RAPDU: <> if (os_memcmp(buffer+U2F_HANDLE_SIGN_HEADER_SIZE, "\xF1\xD0\x00\x00\x00", 5) == 0 ) { c0d022a6: 4630 mov r0, r6 c0d022a8: 3041 adds r0, #65 ; 0x41 c0d022aa: a123 add r1, pc, #140 ; (adr r1, c0d02338 <u2f_apdu_sign+0xdc>) c0d022ac: 2205 movs r2, #5 c0d022ae: f7fe fd9f bl c0d00df0 <os_memcmp> c0d022b2: 2800 cmp r0, #0 c0d022b4: d02c beq.n c0d02310 <u2f_apdu_sign+0xb4> } } for (i = 0; i < keyHandleLength; i++) { buffer[U2F_HANDLE_SIGN_HEADER_SIZE + i] ^= U2F_PROXY_MAGIC[i % (sizeof(U2F_PROXY_MAGIC)-1)]; c0d022b6: 3641 adds r6, #65 ; 0x41 c0d022b8: 2400 movs r4, #0 c0d022ba: a522 add r5, pc, #136 ; (adr r5, c0d02344 <u2f_apdu_sign+0xe8>) c0d022bc: b2e0 uxtb r0, r4 c0d022be: 2103 movs r1, #3 c0d022c0: f001 ff68 bl c0d04194 <__aeabi_uidivmod> c0d022c4: 5d30 ldrb r0, [r6, r4] c0d022c6: 5c69 ldrb r1, [r5, r1] c0d022c8: 4041 eors r1, r0 c0d022ca: 5531 strb r1, [r6, r4] return; } } for (i = 0; i < keyHandleLength; i++) { c0d022cc: 1c64 adds r4, r4, #1 c0d022ce: 42a7 cmp r7, r4 c0d022d0: d1f4 bne.n c0d022bc <u2f_apdu_sign+0x60> buffer[U2F_HANDLE_SIGN_HEADER_SIZE + i] ^= U2F_PROXY_MAGIC[i % (sizeof(U2F_PROXY_MAGIC)-1)]; } // Check that it looks like an APDU if (length != U2F_HANDLE_SIGN_HEADER_SIZE + 5 + buffer[U2F_HANDLE_SIGN_HEADER_SIZE + 4]) { c0d022d2: 2045 movs r0, #69 ; 0x45 c0d022d4: 9904 ldr r1, [sp, #16] c0d022d6: 5c08 ldrb r0, [r1, r0] c0d022d8: 3046 adds r0, #70 ; 0x46 c0d022da: 9a02 ldr r2, [sp, #8] c0d022dc: 4282 cmp r2, r0 c0d022de: d111 bne.n c0d02304 <u2f_apdu_sign+0xa8> sizeof(SW_BAD_KEY_HANDLE)); return; } // make the apdu available to higher layers os_memmove(G_io_apdu_buffer, buffer + U2F_HANDLE_SIGN_HEADER_SIZE, keyHandleLength); c0d022e0: 3141 adds r1, #65 ; 0x41 c0d022e2: 4817 ldr r0, [pc, #92] ; (c0d02340 <u2f_apdu_sign+0xe4>) c0d022e4: 463a mov r2, r7 c0d022e6: f7fe fce6 bl c0d00cb6 <os_memmove> G_io_apdu_length = keyHandleLength; c0d022ea: 4819 ldr r0, [pc, #100] ; (c0d02350 <u2f_apdu_sign+0xf4>) c0d022ec: 8007 strh r7, [r0, #0] G_io_apdu_media = IO_APDU_MEDIA_U2F; // the effective transport is managed by the U2F layer c0d022ee: 4819 ldr r0, [pc, #100] ; (c0d02354 <u2f_apdu_sign+0xf8>) c0d022f0: 2107 movs r1, #7 c0d022f2: 7001 strb r1, [r0, #0] G_io_apdu_state = APDU_U2F; c0d022f4: 2009 movs r0, #9 c0d022f6: 490f ldr r1, [pc, #60] ; (c0d02334 <u2f_apdu_sign+0xd8>) c0d022f8: 7008 strb r0, [r1, #0] // prepare for asynch reply u2f_message_set_autoreply_wait_user_presence(service, true); c0d022fa: 2101 movs r1, #1 c0d022fc: 9803 ldr r0, [sp, #12] c0d022fe: f000 fc69 bl c0d02bd4 <u2f_message_set_autoreply_wait_user_presence> c0d02302: e7c3 b.n c0d0228c <u2f_apdu_sign+0x30> for (i = 0; i < keyHandleLength; i++) { buffer[U2F_HANDLE_SIGN_HEADER_SIZE + i] ^= U2F_PROXY_MAGIC[i % (sizeof(U2F_PROXY_MAGIC)-1)]; } // Check that it looks like an APDU if (length != U2F_HANDLE_SIGN_HEADER_SIZE + 5 + buffer[U2F_HANDLE_SIGN_HEADER_SIZE + 4]) { u2f_message_reply(service, U2F_CMD_MSG, c0d02304: 4a17 ldr r2, [pc, #92] ; (c0d02364 <u2f_apdu_sign+0x108>) c0d02306: 447a add r2, pc c0d02308: 2302 movs r3, #2 c0d0230a: 9803 ldr r0, [sp, #12] c0d0230c: 9901 ldr r1, [sp, #4] c0d0230e: e7bb b.n c0d02288 <u2f_apdu_sign+0x2c> // this apdu is not subject to proxy magic masking // APDU is F1 D0 00 00 00 to get the magic proxy // RAPDU: <> if (os_memcmp(buffer+U2F_HANDLE_SIGN_HEADER_SIZE, "\xF1\xD0\x00\x00\x00", 5) == 0 ) { // U2F_PROXY_MAGIC is given as a 0 terminated string G_io_apdu_buffer[0] = sizeof(U2F_PROXY_MAGIC)-1; c0d02310: 4e0b ldr r6, [pc, #44] ; (c0d02340 <u2f_apdu_sign+0xe4>) c0d02312: 2203 movs r2, #3 c0d02314: 7032 strb r2, [r6, #0] os_memmove(G_io_apdu_buffer+1, U2F_PROXY_MAGIC, sizeof(U2F_PROXY_MAGIC)-1); c0d02316: 1c70 adds r0, r6, #1 c0d02318: a10a add r1, pc, #40 ; (adr r1, c0d02344 <u2f_apdu_sign+0xe8>) c0d0231a: f7fe fccc bl c0d00cb6 <os_memmove> os_memmove(G_io_apdu_buffer+1+sizeof(U2F_PROXY_MAGIC)-1, "\x90\x00\x90\x00", 4); c0d0231e: 1d30 adds r0, r6, #4 c0d02320: a109 add r1, pc, #36 ; (adr r1, c0d02348 <u2f_apdu_sign+0xec>) c0d02322: 2204 movs r2, #4 c0d02324: f7fe fcc7 bl c0d00cb6 <os_memmove> u2f_message_reply(service, U2F_CMD_MSG, (uint8_t *)G_io_apdu_buffer, G_io_apdu_buffer[0]+1+2+2); c0d02328: 7830 ldrb r0, [r6, #0] c0d0232a: 1d43 adds r3, r0, #5 if (os_memcmp(buffer+U2F_HANDLE_SIGN_HEADER_SIZE, "\xF1\xD0\x00\x00\x00", 5) == 0 ) { // U2F_PROXY_MAGIC is given as a 0 terminated string G_io_apdu_buffer[0] = sizeof(U2F_PROXY_MAGIC)-1; os_memmove(G_io_apdu_buffer+1, U2F_PROXY_MAGIC, sizeof(U2F_PROXY_MAGIC)-1); os_memmove(G_io_apdu_buffer+1+sizeof(U2F_PROXY_MAGIC)-1, "\x90\x00\x90\x00", 4); u2f_message_reply(service, U2F_CMD_MSG, c0d0232c: 9803 ldr r0, [sp, #12] c0d0232e: 9901 ldr r1, [sp, #4] c0d02330: 4632 mov r2, r6 c0d02332: e7a9 b.n c0d02288 <u2f_apdu_sign+0x2c> c0d02334: 20001a6a .word 0x20001a6a c0d02338: 0000d0f1 .word 0x0000d0f1 c0d0233c: 00000000 .word 0x00000000 c0d02340: 200018f8 .word 0x200018f8 c0d02344: 00544e4f .word 0x00544e4f c0d02348: 00900090 .word 0x00900090 c0d0234c: 00000000 .word 0x00000000 c0d02350: 20001a6c .word 0x20001a6c c0d02354: 20001a54 .word 0x20001a54 c0d02358: 0000216c .word 0x0000216c c0d0235c: 00002162 .word 0x00002162 c0d02360: 0000215a .word 0x0000215a c0d02364: 000020d8 .word 0x000020d8 c0d02368 <u2f_handle_cmd_init>: } #endif void u2f_handle_cmd_init(u2f_service_t *service, uint8_t *buffer, uint16_t length, uint8_t *channelInit) { c0d02368: b5f0 push {r4, r5, r6, r7, lr} c0d0236a: b081 sub sp, #4 c0d0236c: 461d mov r5, r3 c0d0236e: 460e mov r6, r1 c0d02370: 4604 mov r4, r0 // screen_printf("U2F init\n"); uint8_t channel[4]; (void)length; if (u2f_is_channel_broadcast(channelInit)) { c0d02372: 4628 mov r0, r5 c0d02374: f000 fc1e bl c0d02bb4 <u2f_is_channel_broadcast> c0d02378: 2801 cmp r0, #1 c0d0237a: d104 bne.n c0d02386 <u2f_handle_cmd_init+0x1e> c0d0237c: 4668 mov r0, sp cx_rng(channel, 4); c0d0237e: 2104 movs r1, #4 c0d02380: f7ff fdd6 bl c0d01f30 <cx_rng> c0d02384: e004 b.n c0d02390 <u2f_handle_cmd_init+0x28> c0d02386: 4668 mov r0, sp } else { os_memmove(channel, channelInit, 4); c0d02388: 2204 movs r2, #4 c0d0238a: 4629 mov r1, r5 c0d0238c: f7fe fc93 bl c0d00cb6 <os_memmove> } os_memmove(G_io_apdu_buffer, buffer, 8); c0d02390: 4f17 ldr r7, [pc, #92] ; (c0d023f0 <u2f_handle_cmd_init+0x88>) c0d02392: 2208 movs r2, #8 c0d02394: 4638 mov r0, r7 c0d02396: 4631 mov r1, r6 c0d02398: f7fe fc8d bl c0d00cb6 <os_memmove> os_memmove(G_io_apdu_buffer + 8, channel, 4); c0d0239c: 4638 mov r0, r7 c0d0239e: 3008 adds r0, #8 c0d023a0: 4669 mov r1, sp c0d023a2: 2204 movs r2, #4 c0d023a4: f7fe fc87 bl c0d00cb6 <os_memmove> G_io_apdu_buffer[12] = INIT_U2F_VERSION; c0d023a8: 2002 movs r0, #2 c0d023aa: 7338 strb r0, [r7, #12] G_io_apdu_buffer[13] = INIT_DEVICE_VERSION_MAJOR; c0d023ac: 2000 movs r0, #0 c0d023ae: 7378 strb r0, [r7, #13] c0d023b0: 2101 movs r1, #1 G_io_apdu_buffer[14] = INIT_DEVICE_VERSION_MINOR; c0d023b2: 73b9 strb r1, [r7, #14] G_io_apdu_buffer[15] = INIT_BUILD_VERSION; c0d023b4: 73f8 strb r0, [r7, #15] G_io_apdu_buffer[16] = INIT_CAPABILITIES; c0d023b6: 7438 strb r0, [r7, #16] if (u2f_is_channel_broadcast(channelInit)) { c0d023b8: 4628 mov r0, r5 c0d023ba: f000 fbfb bl c0d02bb4 <u2f_is_channel_broadcast> c0d023be: 4601 mov r1, r0 c0d023c0: 1d20 adds r0, r4, #4 os_memset(service->channel, 0xff, 4); c0d023c2: 2586 movs r5, #134 ; 0x86 G_io_apdu_buffer[13] = INIT_DEVICE_VERSION_MAJOR; G_io_apdu_buffer[14] = INIT_DEVICE_VERSION_MINOR; G_io_apdu_buffer[15] = INIT_BUILD_VERSION; G_io_apdu_buffer[16] = INIT_CAPABILITIES; if (u2f_is_channel_broadcast(channelInit)) { c0d023c4: 2901 cmp r1, #1 c0d023c6: d106 bne.n c0d023d6 <u2f_handle_cmd_init+0x6e> os_memset(service->channel, 0xff, 4); c0d023c8: 4629 mov r1, r5 c0d023ca: 3179 adds r1, #121 ; 0x79 c0d023cc: b2c9 uxtb r1, r1 c0d023ce: 2204 movs r2, #4 c0d023d0: f7fe fc68 bl c0d00ca4 <os_memset> c0d023d4: e003 b.n c0d023de <u2f_handle_cmd_init+0x76> c0d023d6: 4669 mov r1, sp } else { os_memmove(service->channel, channel, 4); c0d023d8: 2204 movs r2, #4 c0d023da: f7fe fc6c bl c0d00cb6 <os_memmove> } u2f_message_reply(service, U2F_CMD_INIT, G_io_apdu_buffer, 17); c0d023de: 4a04 ldr r2, [pc, #16] ; (c0d023f0 <u2f_handle_cmd_init+0x88>) c0d023e0: 2311 movs r3, #17 c0d023e2: 4620 mov r0, r4 c0d023e4: 4629 mov r1, r5 c0d023e6: f000 fc20 bl c0d02c2a <u2f_message_reply> } c0d023ea: b001 add sp, #4 c0d023ec: bdf0 pop {r4, r5, r6, r7, pc} c0d023ee: 46c0 nop ; (mov r8, r8) c0d023f0: 200018f8 .word 0x200018f8 c0d023f4 <u2f_handle_cmd_msg>: // screen_printf("U2F ping\n"); u2f_message_reply(service, U2F_CMD_PING, buffer, length); } void u2f_handle_cmd_msg(u2f_service_t *service, uint8_t *buffer, uint16_t length) { c0d023f4: b5f0 push {r4, r5, r6, r7, lr} c0d023f6: b085 sub sp, #20 c0d023f8: 4615 mov r5, r2 c0d023fa: 460c mov r4, r1 c0d023fc: 9004 str r0, [sp, #16] uint8_t cla = buffer[0]; uint8_t ins = buffer[1]; uint8_t p1 = buffer[2]; uint8_t p2 = buffer[3]; // in extended length buffer[4] must be 0 uint32_t dataLength = /*(buffer[4] << 16) |*/ (buffer[5] << 8) | (buffer[6]); c0d023fe: 79a0 ldrb r0, [r4, #6] c0d02400: 7961 ldrb r1, [r4, #5] c0d02402: 020e lsls r6, r1, #8 c0d02404: 4306 orrs r6, r0 void u2f_handle_cmd_msg(u2f_service_t *service, uint8_t *buffer, uint16_t length) { // screen_printf("U2F msg\n"); uint8_t cla = buffer[0]; uint8_t ins = buffer[1]; uint8_t p1 = buffer[2]; c0d02406: 78a0 ldrb r0, [r4, #2] void u2f_handle_cmd_msg(u2f_service_t *service, uint8_t *buffer, uint16_t length) { // screen_printf("U2F msg\n"); uint8_t cla = buffer[0]; uint8_t ins = buffer[1]; c0d02408: 9002 str r0, [sp, #8] c0d0240a: 7861 ldrb r1, [r4, #1] } void u2f_handle_cmd_msg(u2f_service_t *service, uint8_t *buffer, uint16_t length) { // screen_printf("U2F msg\n"); uint8_t cla = buffer[0]; c0d0240c: 7827 ldrb r7, [r4, #0] uint8_t ins = buffer[1]; uint8_t p1 = buffer[2]; uint8_t p2 = buffer[3]; // in extended length buffer[4] must be 0 uint32_t dataLength = /*(buffer[4] << 16) |*/ (buffer[5] << 8) | (buffer[6]); if (dataLength == (uint16_t)(length - 9) || dataLength == (uint16_t)(length - 7)) { c0d0240e: 3a09 subs r2, #9 c0d02410: b290 uxth r0, r2 u2f_apdu_get_info(service, p1, p2, buffer + 7, dataLength); break; default: // screen_printf("unsupported\n"); u2f_message_reply(service, U2F_CMD_MSG, c0d02412: 2383 movs r3, #131 ; 0x83 c0d02414: 9303 str r3, [sp, #12] c0d02416: 4b1f ldr r3, [pc, #124] ; (c0d02494 <u2f_handle_cmd_msg+0xa0>) uint8_t ins = buffer[1]; uint8_t p1 = buffer[2]; uint8_t p2 = buffer[3]; // in extended length buffer[4] must be 0 uint32_t dataLength = /*(buffer[4] << 16) |*/ (buffer[5] << 8) | (buffer[6]); if (dataLength == (uint16_t)(length - 9) || dataLength == (uint16_t)(length - 7)) { c0d02418: 4286 cmp r6, r0 c0d0241a: d003 beq.n c0d02424 <u2f_handle_cmd_msg+0x30> c0d0241c: 1fed subs r5, r5, #7 c0d0241e: 402b ands r3, r5 c0d02420: 429e cmp r6, r3 c0d02422: d11b bne.n c0d0245c <u2f_handle_cmd_msg+0x68> c0d02424: 4632 mov r2, r6 G_io_apdu_media = IO_APDU_MEDIA_U2F; // the effective transport is managed by the U2F layer G_io_apdu_state = APDU_U2F; #else if (cla != FIDO_CLA) { c0d02426: 2f00 cmp r7, #0 c0d02428: d008 beq.n c0d0243c <u2f_handle_cmd_msg+0x48> u2f_message_reply(service, U2F_CMD_MSG, c0d0242a: 4a1b ldr r2, [pc, #108] ; (c0d02498 <u2f_handle_cmd_msg+0xa4>) c0d0242c: 447a add r2, pc c0d0242e: 2302 movs r3, #2 c0d02430: 9804 ldr r0, [sp, #16] c0d02432: 9903 ldr r1, [sp, #12] c0d02434: f000 fbf9 bl c0d02c2a <u2f_message_reply> sizeof(SW_UNKNOWN_INSTRUCTION)); return; } #endif } c0d02438: b005 add sp, #20 c0d0243a: bdf0 pop {r4, r5, r6, r7, pc} u2f_message_reply(service, U2F_CMD_MSG, (uint8_t *)SW_UNKNOWN_CLASS, sizeof(SW_UNKNOWN_CLASS)); return; } switch (ins) { c0d0243c: 2902 cmp r1, #2 c0d0243e: dc17 bgt.n c0d02470 <u2f_handle_cmd_msg+0x7c> c0d02440: 2901 cmp r1, #1 c0d02442: d020 beq.n c0d02486 <u2f_handle_cmd_msg+0x92> c0d02444: 2902 cmp r1, #2 c0d02446: d11b bne.n c0d02480 <u2f_handle_cmd_msg+0x8c> // screen_printf("enroll\n"); u2f_apdu_enroll(service, p1, p2, buffer + 7, dataLength); break; case FIDO_INS_SIGN: // screen_printf("sign\n"); u2f_apdu_sign(service, p1, p2, buffer + 7, dataLength); c0d02448: b290 uxth r0, r2 c0d0244a: 4669 mov r1, sp c0d0244c: 6008 str r0, [r1, #0] c0d0244e: 1de3 adds r3, r4, #7 c0d02450: 2200 movs r2, #0 c0d02452: 9804 ldr r0, [sp, #16] c0d02454: 9902 ldr r1, [sp, #8] c0d02456: f7ff ff01 bl c0d0225c <u2f_apdu_sign> c0d0245a: e7ed b.n c0d02438 <u2f_handle_cmd_msg+0x44> if (dataLength == (uint16_t)(length - 9) || dataLength == (uint16_t)(length - 7)) { // Le is optional // nominal case from the specification } // circumvent google chrome extended length encoding done on the last byte only (module 256) but all data being transferred else if (dataLength == (uint16_t)(length - 9)%256) { c0d0245c: b2d0 uxtb r0, r2 c0d0245e: 4286 cmp r6, r0 c0d02460: d0e1 beq.n c0d02426 <u2f_handle_cmd_msg+0x32> dataLength = length - 9; } else if (dataLength == (uint16_t)(length - 7)%256) { c0d02462: b2e8 uxtb r0, r5 c0d02464: 4286 cmp r6, r0 c0d02466: 462a mov r2, r5 c0d02468: d0dd beq.n c0d02426 <u2f_handle_cmd_msg+0x32> dataLength = length - 7; } else { // invalid size u2f_message_reply(service, U2F_CMD_MSG, c0d0246a: 4a0c ldr r2, [pc, #48] ; (c0d0249c <u2f_handle_cmd_msg+0xa8>) c0d0246c: 447a add r2, pc c0d0246e: e7de b.n c0d0242e <u2f_handle_cmd_msg+0x3a> c0d02470: 2903 cmp r1, #3 c0d02472: d00b beq.n c0d0248c <u2f_handle_cmd_msg+0x98> c0d02474: 29c1 cmp r1, #193 ; 0xc1 c0d02476: d103 bne.n c0d02480 <u2f_handle_cmd_msg+0x8c> uint8_t *buffer, uint16_t length) { UNUSED(p1); UNUSED(p2); UNUSED(buffer); UNUSED(length); u2f_message_reply(service, U2F_CMD_MSG, (uint8_t *)INFO, sizeof(INFO)); c0d02478: 4a09 ldr r2, [pc, #36] ; (c0d024a0 <u2f_handle_cmd_msg+0xac>) c0d0247a: 447a add r2, pc c0d0247c: 2304 movs r3, #4 c0d0247e: e7d7 b.n c0d02430 <u2f_handle_cmd_msg+0x3c> u2f_apdu_get_info(service, p1, p2, buffer + 7, dataLength); break; default: // screen_printf("unsupported\n"); u2f_message_reply(service, U2F_CMD_MSG, c0d02480: 4a0a ldr r2, [pc, #40] ; (c0d024ac <u2f_handle_cmd_msg+0xb8>) c0d02482: 447a add r2, pc c0d02484: e7d3 b.n c0d0242e <u2f_handle_cmd_msg+0x3a> UNUSED(p1); UNUSED(p2); UNUSED(buffer); UNUSED(length); u2f_message_reply(service, U2F_CMD_MSG, (uint8_t *)SW_INTERNAL, sizeof(SW_INTERNAL)); c0d02486: 4a07 ldr r2, [pc, #28] ; (c0d024a4 <u2f_handle_cmd_msg+0xb0>) c0d02488: 447a add r2, pc c0d0248a: e7d0 b.n c0d0242e <u2f_handle_cmd_msg+0x3a> // screen_printf("U2F version\n"); UNUSED(p1); UNUSED(p2); UNUSED(buffer); UNUSED(length); u2f_message_reply(service, U2F_CMD_MSG, (uint8_t *)U2F_VERSION, sizeof(U2F_VERSION)); c0d0248c: 4a06 ldr r2, [pc, #24] ; (c0d024a8 <u2f_handle_cmd_msg+0xb4>) c0d0248e: 447a add r2, pc c0d02490: 2308 movs r3, #8 c0d02492: e7cd b.n c0d02430 <u2f_handle_cmd_msg+0x3c> c0d02494: 0000ffff .word 0x0000ffff c0d02498: 00001fc0 .word 0x00001fc0 c0d0249c: 00001f6e .word 0x00001f6e c0d024a0: 00001f6e .word 0x00001f6e c0d024a4: 00001f4e .word 0x00001f4e c0d024a8: 00001f52 .word 0x00001f52 c0d024ac: 00001f6c .word 0x00001f6c c0d024b0 <u2f_message_complete>: } #endif } void u2f_message_complete(u2f_service_t *service) { c0d024b0: b580 push {r7, lr} uint8_t cmd = service->transportBuffer[0]; c0d024b2: 69c1 ldr r1, [r0, #28] uint16_t length = (service->transportBuffer[1] << 8) | (service->transportBuffer[2]); c0d024b4: 788a ldrb r2, [r1, #2] c0d024b6: 784b ldrb r3, [r1, #1] c0d024b8: 021b lsls r3, r3, #8 c0d024ba: 4313 orrs r3, r2 #endif } void u2f_message_complete(u2f_service_t *service) { uint8_t cmd = service->transportBuffer[0]; c0d024bc: 780a ldrb r2, [r1, #0] uint16_t length = (service->transportBuffer[1] << 8) | (service->transportBuffer[2]); switch (cmd) { c0d024be: 2a81 cmp r2, #129 ; 0x81 c0d024c0: d009 beq.n c0d024d6 <u2f_message_complete+0x26> c0d024c2: 2a83 cmp r2, #131 ; 0x83 c0d024c4: d00c beq.n c0d024e0 <u2f_message_complete+0x30> c0d024c6: 2a86 cmp r2, #134 ; 0x86 c0d024c8: d10e bne.n c0d024e8 <u2f_message_complete+0x38> case U2F_CMD_INIT: u2f_handle_cmd_init(service, service->transportBuffer + 3, length, service->channel); c0d024ca: 1cc9 adds r1, r1, #3 c0d024cc: 1d03 adds r3, r0, #4 c0d024ce: 2200 movs r2, #0 c0d024d0: f7ff ff4a bl c0d02368 <u2f_handle_cmd_init> break; case U2F_CMD_MSG: u2f_handle_cmd_msg(service, service->transportBuffer + 3, length); break; } } c0d024d4: bd80 pop {r7, pc} switch (cmd) { case U2F_CMD_INIT: u2f_handle_cmd_init(service, service->transportBuffer + 3, length, service->channel); break; case U2F_CMD_PING: u2f_handle_cmd_ping(service, service->transportBuffer + 3, length); c0d024d6: 1cca adds r2, r1, #3 } void u2f_handle_cmd_ping(u2f_service_t *service, uint8_t *buffer, uint16_t length) { // screen_printf("U2F ping\n"); u2f_message_reply(service, U2F_CMD_PING, buffer, length); c0d024d8: 2181 movs r1, #129 ; 0x81 c0d024da: f000 fba6 bl c0d02c2a <u2f_message_reply> break; case U2F_CMD_MSG: u2f_handle_cmd_msg(service, service->transportBuffer + 3, length); break; } } c0d024de: bd80 pop {r7, pc} break; case U2F_CMD_PING: u2f_handle_cmd_ping(service, service->transportBuffer + 3, length); break; case U2F_CMD_MSG: u2f_handle_cmd_msg(service, service->transportBuffer + 3, length); c0d024e0: 1cc9 adds r1, r1, #3 c0d024e2: 461a mov r2, r3 c0d024e4: f7ff ff86 bl c0d023f4 <u2f_handle_cmd_msg> break; } } c0d024e8: bd80 pop {r7, pc} ... c0d024ec <u2f_io_send>: #include "u2f_processing.h" #include "u2f_impl.h" #include "os_io_seproxyhal.h" void u2f_io_send(uint8_t *buffer, uint16_t length, u2f_transport_media_t media) { c0d024ec: b570 push {r4, r5, r6, lr} c0d024ee: 460d mov r5, r1 c0d024f0: 4601 mov r1, r0 if (media == U2F_MEDIA_USB) { c0d024f2: 2a01 cmp r2, #1 c0d024f4: d112 bne.n c0d0251c <u2f_io_send+0x30> os_memmove(G_io_usb_ep_buffer, buffer, length); c0d024f6: 4c17 ldr r4, [pc, #92] ; (c0d02554 <u2f_io_send+0x68>) c0d024f8: 4620 mov r0, r4 c0d024fa: 462a mov r2, r5 c0d024fc: f7fe fbdb bl c0d00cb6 <os_memmove> // wipe the remaining to avoid : // 1/ data leaks // 2/ invalid junk os_memset(G_io_usb_ep_buffer+length, 0, sizeof(G_io_usb_ep_buffer)-length); c0d02500: 1960 adds r0, r4, r5 c0d02502: 2640 movs r6, #64 ; 0x40 c0d02504: 1b72 subs r2, r6, r5 c0d02506: 2500 movs r5, #0 c0d02508: 4629 mov r1, r5 c0d0250a: f7fe fbcb bl c0d00ca4 <os_memset> } switch (media) { case U2F_MEDIA_USB: io_usb_send_ep(U2F_EPIN_ADDR, G_io_usb_ep_buffer, USB_SEGMENT_SIZE, 0); c0d0250e: 2081 movs r0, #129 ; 0x81 c0d02510: 4621 mov r1, r4 c0d02512: 4632 mov r2, r6 c0d02514: 462b mov r3, r5 c0d02516: f7fe fd1d bl c0d00f54 <io_usb_send_ep> #endif default: PRINTF("Request to send on unsupported media %d\n", media); break; } } c0d0251a: bd70 pop {r4, r5, r6, pc} case U2F_MEDIA_BLE: BLE_protocol_send(buffer, length); break; #endif default: PRINTF("Request to send on unsupported media %d\n", media); c0d0251c: a002 add r0, pc, #8 ; (adr r0, c0d02528 <u2f_io_send+0x3c>) c0d0251e: 4611 mov r1, r2 c0d02520: f7ff f90e bl c0d01740 <screen_printf> break; } } c0d02524: bd70 pop {r4, r5, r6, pc} c0d02526: 46c0 nop ; (mov r8, r8) c0d02528: 75716552 .word 0x75716552 c0d0252c: 20747365 .word 0x20747365 c0d02530: 73206f74 .word 0x73206f74 c0d02534: 20646e65 .word 0x20646e65 c0d02538: 75206e6f .word 0x75206e6f c0d0253c: 7075736e .word 0x7075736e c0d02540: 74726f70 .word 0x74726f70 c0d02544: 6d206465 .word 0x6d206465 c0d02548: 61696465 .word 0x61696465 c0d0254c: 0a642520 .word 0x0a642520 c0d02550: 00000000 .word 0x00000000 c0d02554: 20001ac0 .word 0x20001ac0 c0d02558 <u2f_transport_init>: /** * Initialize the u2f transport and provide the buffer into which to store incoming message */ void u2f_transport_init(u2f_service_t *service, uint8_t* message_buffer, uint16_t message_buffer_length) { service->transportReceiveBuffer = message_buffer; c0d02558: 60c1 str r1, [r0, #12] service->transportReceiveBufferLength = message_buffer_length; c0d0255a: 8202 strh r2, [r0, #16] c0d0255c: 2200 movs r2, #0 #warning TODO take into account the INIT during SEGMENTED message correctly (avoid erasing the first part of the apdu buffer when doing so) // init void u2f_transport_reset(u2f_service_t* service) { service->transportState = U2F_IDLE; service->transportOffset = 0; c0d0255e: 82c2 strh r2, [r0, #22] service->transportMedia = 0; service->transportPacketIndex = 0; c0d02560: 7682 strb r2, [r0, #26] service->fakeChannelTransportState = U2F_IDLE; service->fakeChannelTransportOffset = 0; service->fakeChannelTransportPacketIndex = 0; service->sending = false; c0d02562: 232b movs r3, #43 ; 0x2b c0d02564: 54c2 strb r2, [r0, r3] service->waitAsynchronousResponse = U2F_WAIT_ASYNCH_IDLE; c0d02566: 232a movs r3, #42 ; 0x2a c0d02568: 54c2 strb r2, [r0, r3] // init void u2f_transport_reset(u2f_service_t* service) { service->transportState = U2F_IDLE; service->transportOffset = 0; service->transportMedia = 0; c0d0256a: 8482 strh r2, [r0, #36] ; 0x24 service->fakeChannelTransportOffset = 0; service->fakeChannelTransportPacketIndex = 0; service->sending = false; service->waitAsynchronousResponse = U2F_WAIT_ASYNCH_IDLE; // reset the receive buffer to allow for a new message to be received again (in case transmission of a CODE buffer the previous reply) service->transportBuffer = service->transportReceiveBuffer; c0d0256c: 61c1 str r1, [r0, #28] // init void u2f_transport_reset(u2f_service_t* service) { service->transportState = U2F_IDLE; service->transportOffset = 0; service->transportMedia = 0; c0d0256e: 6202 str r2, [r0, #32] */ void u2f_transport_init(u2f_service_t *service, uint8_t* message_buffer, uint16_t message_buffer_length) { service->transportReceiveBuffer = message_buffer; service->transportReceiveBufferLength = message_buffer_length; u2f_transport_reset(service); } c0d02570: 4770 bx lr ... c0d02574 <u2f_transport_sent>: /** * Function called when the previously scheduled message to be sent on the media is effectively sent. * And a new message can be scheduled. */ void u2f_transport_sent(u2f_service_t* service, u2f_transport_media_t media) { c0d02574: b5f0 push {r4, r5, r6, r7, lr} c0d02576: b083 sub sp, #12 c0d02578: 460d mov r5, r1 c0d0257a: 4604 mov r4, r0 // previous mark packet as sent if (service->sending) { c0d0257c: 202b movs r0, #43 ; 0x2b c0d0257e: 5c21 ldrb r1, [r4, r0] c0d02580: 4620 mov r0, r4 c0d02582: 302b adds r0, #43 ; 0x2b c0d02584: 2900 cmp r1, #0 c0d02586: d002 beq.n c0d0258e <u2f_transport_sent+0x1a> service->sending = false; c0d02588: 2100 movs r1, #0 c0d0258a: 7001 strb r1, [r0, #0] c0d0258c: e061 b.n c0d02652 <u2f_transport_sent+0xde> return; } // if idle (possibly after an error), then only await for a transmission if (service->transportState != U2F_SENDING_RESPONSE c0d0258e: 2120 movs r1, #32 c0d02590: 5c61 ldrb r1, [r4, r1] && service->transportState != U2F_SENDING_ERROR) { c0d02592: 1ec9 subs r1, r1, #3 c0d02594: b2c9 uxtb r1, r1 service->sending = false; return; } // if idle (possibly after an error), then only await for a transmission if (service->transportState != U2F_SENDING_RESPONSE c0d02596: 4623 mov r3, r4 c0d02598: 3320 adds r3, #32 && service->transportState != U2F_SENDING_ERROR) { c0d0259a: 2901 cmp r1, #1 c0d0259c: d859 bhi.n c0d02652 <u2f_transport_sent+0xde> // absorb the error, transport is erroneous but that won't hurt in the end. // also absorb the fake channel user presence check reply ack //THROW(INVALID_STATE); return; } if (service->transportOffset < service->transportLength) { c0d0259e: 8b21 ldrh r1, [r4, #24] c0d025a0: 8ae2 ldrh r2, [r4, #22] c0d025a2: 4291 cmp r1, r2 c0d025a4: d924 bls.n c0d025f0 <u2f_transport_sent+0x7c> uint16_t mtu = (media == U2F_MEDIA_USB) ? USB_SEGMENT_SIZE : BLE_SEGMENT_SIZE; uint16_t channelHeader = (media == U2F_MEDIA_USB ? 4 : 0); c0d025a6: 2304 movs r3, #4 c0d025a8: 2000 movs r0, #0 c0d025aa: 2d01 cmp r5, #1 c0d025ac: d000 beq.n c0d025b0 <u2f_transport_sent+0x3c> c0d025ae: 4603 mov r3, r0 c0d025b0: 9002 str r0, [sp, #8] uint8_t headerSize = (service->transportPacketIndex == 0 ? (channelHeader + 3) c0d025b2: 7ea0 ldrb r0, [r4, #26] c0d025b4: 2703 movs r7, #3 c0d025b6: 2601 movs r6, #1 c0d025b8: 2800 cmp r0, #0 c0d025ba: d000 beq.n c0d025be <u2f_transport_sent+0x4a> c0d025bc: 4637 mov r7, r6 c0d025be: 431f orrs r7, r3 : (channelHeader + 1)); uint16_t blockSize = ((service->transportLength - service->transportOffset) > (mtu - headerSize) c0d025c0: 2340 movs r3, #64 ; 0x40 c0d025c2: 1bde subs r6, r3, r7 uint16_t channelHeader = (media == U2F_MEDIA_USB ? 4 : 0); uint8_t headerSize = (service->transportPacketIndex == 0 ? (channelHeader + 3) : (channelHeader + 1)); uint16_t blockSize = ((service->transportLength - service->transportOffset) > c0d025c4: 1a89 subs r1, r1, r2 c0d025c6: 42b1 cmp r1, r6 c0d025c8: dc00 bgt.n c0d025cc <u2f_transport_sent+0x58> c0d025ca: 460e mov r6, r1 (mtu - headerSize) ? (mtu - headerSize) : service->transportLength - service->transportOffset); uint16_t dataSize = blockSize + headerSize; c0d025cc: 19f1 adds r1, r6, r7 uint16_t offset = 0; // Fragment if (media == U2F_MEDIA_USB) { c0d025ce: 9101 str r1, [sp, #4] c0d025d0: 2d01 cmp r5, #1 c0d025d2: d108 bne.n c0d025e6 <u2f_transport_sent+0x72> os_memmove(G_io_usb_ep_buffer, service->channel, 4); c0d025d4: 1d21 adds r1, r4, #4 c0d025d6: 4821 ldr r0, [pc, #132] ; (c0d0265c <u2f_transport_sent+0xe8>) c0d025d8: 2204 movs r2, #4 c0d025da: 9202 str r2, [sp, #8] c0d025dc: 9300 str r3, [sp, #0] c0d025de: f7fe fb6a bl c0d00cb6 <os_memmove> c0d025e2: 9b00 ldr r3, [sp, #0] c0d025e4: 7ea0 ldrb r0, [r4, #26] offset += 4; } if (service->transportPacketIndex == 0) { c0d025e6: 2800 cmp r0, #0 c0d025e8: d00f beq.n c0d0260a <u2f_transport_sent+0x96> G_io_usb_ep_buffer[offset++] = service->sendCmd; G_io_usb_ep_buffer[offset++] = (service->transportLength >> 8); G_io_usb_ep_buffer[offset++] = (service->transportLength & 0xff); } else { G_io_usb_ep_buffer[offset++] = (service->transportPacketIndex - 1); c0d025ea: 30ff adds r0, #255 ; 0xff c0d025ec: 9902 ldr r1, [sp, #8] c0d025ee: e018 b.n c0d02622 <u2f_transport_sent+0xae> c0d025f0: d12f bne.n c0d02652 <u2f_transport_sent+0xde> c0d025f2: 2100 movs r1, #0 #warning TODO take into account the INIT during SEGMENTED message correctly (avoid erasing the first part of the apdu buffer when doing so) // init void u2f_transport_reset(u2f_service_t* service) { service->transportState = U2F_IDLE; service->transportOffset = 0; c0d025f4: 82e1 strh r1, [r4, #22] service->transportMedia = 0; service->transportPacketIndex = 0; c0d025f6: 76a1 strb r1, [r4, #26] service->fakeChannelTransportState = U2F_IDLE; service->fakeChannelTransportOffset = 0; service->fakeChannelTransportPacketIndex = 0; service->sending = false; c0d025f8: 7001 strb r1, [r0, #0] service->waitAsynchronousResponse = U2F_WAIT_ASYNCH_IDLE; c0d025fa: 202a movs r0, #42 ; 0x2a c0d025fc: 5421 strb r1, [r4, r0] // init void u2f_transport_reset(u2f_service_t* service) { service->transportState = U2F_IDLE; service->transportOffset = 0; service->transportMedia = 0; c0d025fe: 8099 strh r1, [r3, #4] c0d02600: 6019 str r1, [r3, #0] service->fakeChannelTransportOffset = 0; service->fakeChannelTransportPacketIndex = 0; service->sending = false; service->waitAsynchronousResponse = U2F_WAIT_ASYNCH_IDLE; // reset the receive buffer to allow for a new message to be received again (in case transmission of a CODE buffer the previous reply) service->transportBuffer = service->transportReceiveBuffer; c0d02602: 68e0 ldr r0, [r4, #12] c0d02604: 61e0 str r0, [r4, #28] } // last part sent else if (service->transportOffset == service->transportLength) { u2f_transport_reset(service); // we sent the whole response (even if we haven't yet received the ack for the last sent usb in packet) G_io_apdu_state = APDU_IDLE; c0d02606: 4814 ldr r0, [pc, #80] ; (c0d02658 <u2f_transport_sent+0xe4>) c0d02608: e7bf b.n c0d0258a <u2f_transport_sent+0x16> if (media == U2F_MEDIA_USB) { os_memmove(G_io_usb_ep_buffer, service->channel, 4); offset += 4; } if (service->transportPacketIndex == 0) { G_io_usb_ep_buffer[offset++] = service->sendCmd; c0d0260a: 5ce0 ldrb r0, [r4, r3] c0d0260c: 9b02 ldr r3, [sp, #8] c0d0260e: b299 uxth r1, r3 c0d02610: 4a12 ldr r2, [pc, #72] ; (c0d0265c <u2f_transport_sent+0xe8>) c0d02612: 5450 strb r0, [r2, r1] c0d02614: 2001 movs r0, #1 c0d02616: 4318 orrs r0, r3 G_io_usb_ep_buffer[offset++] = (service->transportLength >> 8); c0d02618: b281 uxth r1, r0 c0d0261a: 7e63 ldrb r3, [r4, #25] c0d0261c: 5453 strb r3, [r2, r1] c0d0261e: 1c41 adds r1, r0, #1 G_io_usb_ep_buffer[offset++] = (service->transportLength & 0xff); c0d02620: 7e20 ldrb r0, [r4, #24] c0d02622: b289 uxth r1, r1 c0d02624: 4b0d ldr r3, [pc, #52] ; (c0d0265c <u2f_transport_sent+0xe8>) c0d02626: 5458 strb r0, [r3, r1] } else { G_io_usb_ep_buffer[offset++] = (service->transportPacketIndex - 1); } if (service->transportBuffer != NULL) { c0d02628: 69e1 ldr r1, [r4, #28] c0d0262a: 2900 cmp r1, #0 c0d0262c: d005 beq.n c0d0263a <u2f_transport_sent+0xc6> : (channelHeader + 1)); uint16_t blockSize = ((service->transportLength - service->transportOffset) > (mtu - headerSize) ? (mtu - headerSize) : service->transportLength - service->transportOffset); uint16_t dataSize = blockSize + headerSize; c0d0262e: b2b2 uxth r2, r6 G_io_usb_ep_buffer[offset++] = (service->transportLength & 0xff); } else { G_io_usb_ep_buffer[offset++] = (service->transportPacketIndex - 1); } if (service->transportBuffer != NULL) { os_memmove(G_io_usb_ep_buffer + headerSize, c0d02630: 19d8 adds r0, r3, r7 service->transportBuffer + service->transportOffset, blockSize); c0d02632: 8ae3 ldrh r3, [r4, #22] c0d02634: 18c9 adds r1, r1, r3 G_io_usb_ep_buffer[offset++] = (service->transportLength & 0xff); } else { G_io_usb_ep_buffer[offset++] = (service->transportPacketIndex - 1); } if (service->transportBuffer != NULL) { os_memmove(G_io_usb_ep_buffer + headerSize, c0d02636: f7fe fb3e bl c0d00cb6 <os_memmove> service->transportBuffer + service->transportOffset, blockSize); } service->transportOffset += blockSize; c0d0263a: 8ae0 ldrh r0, [r4, #22] c0d0263c: 1980 adds r0, r0, r6 c0d0263e: 82e0 strh r0, [r4, #22] service->transportPacketIndex++; c0d02640: 7ea0 ldrb r0, [r4, #26] c0d02642: 1c40 adds r0, r0, #1 c0d02644: 76a0 strb r0, [r4, #26] u2f_io_send(G_io_usb_ep_buffer, dataSize, media); c0d02646: 9801 ldr r0, [sp, #4] c0d02648: b281 uxth r1, r0 c0d0264a: 4804 ldr r0, [pc, #16] ; (c0d0265c <u2f_transport_sent+0xe8>) c0d0264c: 462a mov r2, r5 c0d0264e: f7ff ff4d bl c0d024ec <u2f_io_send> else if (service->transportOffset == service->transportLength) { u2f_transport_reset(service); // we sent the whole response (even if we haven't yet received the ack for the last sent usb in packet) G_io_apdu_state = APDU_IDLE; } } c0d02652: b003 add sp, #12 c0d02654: bdf0 pop {r4, r5, r6, r7, pc} c0d02656: 46c0 nop ; (mov r8, r8) c0d02658: 20001a6a .word 0x20001a6a c0d0265c: 20001ac0 .word 0x20001ac0 c0d02660 <u2f_transport_send_usb_user_presence_required>: void u2f_transport_send_usb_user_presence_required(u2f_service_t *service) { c0d02660: b5b0 push {r4, r5, r7, lr} uint16_t offset = 0; service->sending = true; c0d02662: 212b movs r1, #43 ; 0x2b c0d02664: 2401 movs r4, #1 c0d02666: 5444 strb r4, [r0, r1] os_memmove(G_io_usb_ep_buffer, service->channel, 4); c0d02668: 1d01 adds r1, r0, #4 c0d0266a: 4d0b ldr r5, [pc, #44] ; (c0d02698 <u2f_transport_send_usb_user_presence_required+0x38>) c0d0266c: 2204 movs r2, #4 c0d0266e: 4628 mov r0, r5 c0d02670: f7fe fb21 bl c0d00cb6 <os_memmove> offset += 4; G_io_usb_ep_buffer[offset++] = U2F_CMD_MSG; G_io_usb_ep_buffer[offset++] = 0; G_io_usb_ep_buffer[offset++] = 2; G_io_usb_ep_buffer[offset++] = 0x69; G_io_usb_ep_buffer[offset++] = 0x85; c0d02674: 2083 movs r0, #131 ; 0x83 void u2f_transport_send_usb_user_presence_required(u2f_service_t *service) { uint16_t offset = 0; service->sending = true; os_memmove(G_io_usb_ep_buffer, service->channel, 4); offset += 4; G_io_usb_ep_buffer[offset++] = U2F_CMD_MSG; c0d02676: 7128 strb r0, [r5, #4] G_io_usb_ep_buffer[offset++] = 0; c0d02678: 2000 movs r0, #0 c0d0267a: 7168 strb r0, [r5, #5] G_io_usb_ep_buffer[offset++] = 2; c0d0267c: 2002 movs r0, #2 c0d0267e: 71a8 strb r0, [r5, #6] G_io_usb_ep_buffer[offset++] = 0x69; c0d02680: 2069 movs r0, #105 ; 0x69 c0d02682: 71e8 strb r0, [r5, #7] G_io_usb_ep_buffer[offset++] = 0x85; c0d02684: 207c movs r0, #124 ; 0x7c c0d02686: 43c0 mvns r0, r0 c0d02688: 1c80 adds r0, r0, #2 c0d0268a: 7228 strb r0, [r5, #8] u2f_io_send(G_io_usb_ep_buffer, offset, U2F_MEDIA_USB); c0d0268c: 2109 movs r1, #9 c0d0268e: 4628 mov r0, r5 c0d02690: 4622 mov r2, r4 c0d02692: f7ff ff2b bl c0d024ec <u2f_io_send> } c0d02696: bdb0 pop {r4, r5, r7, pc} c0d02698: 20001ac0 .word 0x20001ac0 c0d0269c <u2f_transport_send_wink>: void u2f_transport_send_wink(u2f_service_t *service) { c0d0269c: b5b0 push {r4, r5, r7, lr} uint16_t offset = 0; service->sending = true; c0d0269e: 212b movs r1, #43 ; 0x2b c0d026a0: 2401 movs r4, #1 c0d026a2: 5444 strb r4, [r0, r1] os_memmove(G_io_usb_ep_buffer, service->channel, 4); c0d026a4: 1d01 adds r1, r0, #4 c0d026a6: 4d08 ldr r5, [pc, #32] ; (c0d026c8 <u2f_transport_send_wink+0x2c>) c0d026a8: 2204 movs r2, #4 c0d026aa: 4628 mov r0, r5 c0d026ac: f7fe fb03 bl c0d00cb6 <os_memmove> offset += 4; G_io_usb_ep_buffer[offset++] = U2F_CMD_WINK; c0d026b0: 2088 movs r0, #136 ; 0x88 c0d026b2: 7128 strb r0, [r5, #4] G_io_usb_ep_buffer[offset++] = 0; c0d026b4: 2000 movs r0, #0 c0d026b6: 7168 strb r0, [r5, #5] G_io_usb_ep_buffer[offset++] = 0; c0d026b8: 71a8 strb r0, [r5, #6] u2f_io_send(G_io_usb_ep_buffer, offset, U2F_MEDIA_USB); c0d026ba: 2107 movs r1, #7 c0d026bc: 4628 mov r0, r5 c0d026be: 4622 mov r2, r4 c0d026c0: f7ff ff14 bl c0d024ec <u2f_io_send> } c0d026c4: bdb0 pop {r4, r5, r7, pc} c0d026c6: 46c0 nop ; (mov r8, r8) c0d026c8: 20001ac0 .word 0x20001ac0 c0d026cc <u2f_transport_receive_fakeChannel>: bool u2f_transport_receive_fakeChannel(u2f_service_t *service, uint8_t *buffer, uint16_t size) { c0d026cc: b5f0 push {r4, r5, r6, r7, lr} c0d026ce: b085 sub sp, #20 c0d026d0: 4604 mov r4, r0 if (service->fakeChannelTransportState == U2F_INTERNAL_ERROR) { c0d026d2: 2025 movs r0, #37 ; 0x25 c0d026d4: 5c23 ldrb r3, [r4, r0] c0d026d6: 4627 mov r7, r4 c0d026d8: 3725 adds r7, #37 ; 0x25 c0d026da: 2000 movs r0, #0 c0d026dc: 2b05 cmp r3, #5 c0d026de: d019 beq.n c0d02714 <u2f_transport_receive_fakeChannel+0x48> c0d026e0: 9004 str r0, [sp, #16] return false; } if (memcmp(service->channel, buffer, 4) != 0) { c0d026e2: 7808 ldrb r0, [r1, #0] c0d026e4: 784b ldrb r3, [r1, #1] c0d026e6: 021b lsls r3, r3, #8 c0d026e8: 4303 orrs r3, r0 c0d026ea: 7888 ldrb r0, [r1, #2] c0d026ec: 78ce ldrb r6, [r1, #3] c0d026ee: 0236 lsls r6, r6, #8 c0d026f0: 4306 orrs r6, r0 c0d026f2: 0430 lsls r0, r6, #16 c0d026f4: 4318 orrs r0, r3 c0d026f6: 7923 ldrb r3, [r4, #4] c0d026f8: 7966 ldrb r6, [r4, #5] c0d026fa: 0236 lsls r6, r6, #8 c0d026fc: 431e orrs r6, r3 c0d026fe: 79a3 ldrb r3, [r4, #6] c0d02700: 79e5 ldrb r5, [r4, #7] c0d02702: 022d lsls r5, r5, #8 c0d02704: 431d orrs r5, r3 c0d02706: 042b lsls r3, r5, #16 c0d02708: 4333 orrs r3, r6 c0d0270a: 4283 cmp r3, r0 c0d0270c: d004 beq.n c0d02718 <u2f_transport_receive_fakeChannel+0x4c> service->fakeChannelTransportState = U2F_IDLE; } } return true; error: service->fakeChannelTransportState = U2F_INTERNAL_ERROR; c0d0270e: 2005 movs r0, #5 c0d02710: 7038 strb r0, [r7, #0] c0d02712: 9804 ldr r0, [sp, #16] return false; } c0d02714: b005 add sp, #20 c0d02716: bdf0 pop {r4, r5, r6, r7, pc} c0d02718: 790e ldrb r6, [r1, #4] c0d0271a: 1d0d adds r5, r1, #4 return false; } if (memcmp(service->channel, buffer, 4) != 0) { goto error; } if (service->fakeChannelTransportOffset == 0) { c0d0271c: 8c60 ldrh r0, [r4, #34] ; 0x22 c0d0271e: 2301 movs r3, #1 c0d02720: 9303 str r3, [sp, #12] c0d02722: 4b30 ldr r3, [pc, #192] ; (c0d027e4 <u2f_transport_receive_fakeChannel+0x118>) c0d02724: 2800 cmp r0, #0 c0d02726: d01e beq.n c0d02766 <u2f_transport_receive_fakeChannel+0x9a> c0d02728: 9302 str r3, [sp, #8] service->fakeChannelTransportOffset = MIN(size - 4, service->transportLength); service->fakeChannelTransportPacketIndex = 0; service->fakeChannelCrc = cx_crc16_update(0, buffer + 4, service->fakeChannelTransportOffset); } else { if (buffer[4] != service->fakeChannelTransportPacketIndex) { c0d0272a: 2324 movs r3, #36 ; 0x24 c0d0272c: 5ce5 ldrb r5, [r4, r3] c0d0272e: 4623 mov r3, r4 c0d02730: 3324 adds r3, #36 ; 0x24 c0d02732: 42ae cmp r6, r5 c0d02734: d1eb bne.n c0d0270e <u2f_transport_receive_fakeChannel+0x42> goto error; } uint16_t xfer_len = MIN(size - 5, service->transportLength - service->fakeChannelTransportOffset); c0d02736: 8b25 ldrh r5, [r4, #24] service->fakeChannelTransportPacketIndex++; c0d02738: 9500 str r5, [sp, #0] c0d0273a: 1c75 adds r5, r6, #1 c0d0273c: 701d strb r5, [r3, #0] } else { if (buffer[4] != service->fakeChannelTransportPacketIndex) { goto error; } uint16_t xfer_len = MIN(size - 5, service->transportLength - service->fakeChannelTransportOffset); c0d0273e: 9b00 ldr r3, [sp, #0] c0d02740: 1a1e subs r6, r3, r0 c0d02742: 1f53 subs r3, r2, #5 c0d02744: 2505 movs r5, #5 c0d02746: 9501 str r5, [sp, #4] c0d02748: 42b3 cmp r3, r6 c0d0274a: db00 blt.n c0d0274e <u2f_transport_receive_fakeChannel+0x82> c0d0274c: 9001 str r0, [sp, #4] c0d0274e: 42b3 cmp r3, r6 c0d02750: db00 blt.n c0d02754 <u2f_transport_receive_fakeChannel+0x88> c0d02752: 9a00 ldr r2, [sp, #0] c0d02754: 9b01 ldr r3, [sp, #4] c0d02756: 1ad3 subs r3, r2, r3 service->fakeChannelTransportPacketIndex++; service->fakeChannelTransportOffset += xfer_len; c0d02758: 1818 adds r0, r3, r0 c0d0275a: 8460 strh r0, [r4, #34] ; 0x22 c0d0275c: 9a02 ldr r2, [sp, #8] c0d0275e: 401a ands r2, r3 service->fakeChannelCrc = cx_crc16_update(service->fakeChannelCrc, buffer + 5, xfer_len); c0d02760: 8d20 ldrh r0, [r4, #40] ; 0x28 c0d02762: 1d49 adds r1, r1, #5 c0d02764: e025 b.n c0d027b2 <u2f_transport_receive_fakeChannel+0xe6> c0d02766: 207c movs r0, #124 ; 0x7c c0d02768: 43c0 mvns r0, r0 } if (service->fakeChannelTransportOffset == 0) { uint16_t commandLength = (buffer[4 + 1] << 8) | (buffer[4 + 2]) + U2F_COMMAND_HEADER_SIZE; // Some buggy implementations can send a WINK here, reply it gently if (buffer[4] == U2F_CMD_WINK) { c0d0276a: 1d40 adds r0, r0, #5 c0d0276c: b2c0 uxtb r0, r0 c0d0276e: 9002 str r0, [sp, #8] c0d02770: 2083 movs r0, #131 ; 0x83 c0d02772: 9001 str r0, [sp, #4] c0d02774: 9802 ldr r0, [sp, #8] c0d02776: 4286 cmp r6, r0 c0d02778: d103 bne.n c0d02782 <u2f_transport_receive_fakeChannel+0xb6> u2f_transport_send_wink(service); c0d0277a: 4620 mov r0, r4 c0d0277c: f7ff ff8e bl c0d0269c <u2f_transport_send_wink> c0d02780: e02d b.n c0d027de <u2f_transport_receive_fakeChannel+0x112> c0d02782: 9502 str r5, [sp, #8] c0d02784: 461d mov r5, r3 if (memcmp(service->channel, buffer, 4) != 0) { goto error; } if (service->fakeChannelTransportOffset == 0) { uint16_t commandLength = (buffer[4 + 1] << 8) | (buffer[4 + 2]) + U2F_COMMAND_HEADER_SIZE; c0d02786: 7948 ldrb r0, [r1, #5] c0d02788: 0203 lsls r3, r0, #8 c0d0278a: 7988 ldrb r0, [r1, #6] c0d0278c: 1cc0 adds r0, r0, #3 c0d0278e: 4318 orrs r0, r3 if (buffer[4] == U2F_CMD_WINK) { u2f_transport_send_wink(service); return true; } if (commandLength != service->transportLength) { c0d02790: 9901 ldr r1, [sp, #4] c0d02792: 428e cmp r6, r1 c0d02794: d1bb bne.n c0d0270e <u2f_transport_receive_fakeChannel+0x42> c0d02796: 8b21 ldrh r1, [r4, #24] c0d02798: 4288 cmp r0, r1 c0d0279a: d1b8 bne.n c0d0270e <u2f_transport_receive_fakeChannel+0x42> goto error; } if (buffer[4] != U2F_CMD_MSG) { goto error; } service->fakeChannelTransportOffset = MIN(size - 4, service->transportLength); c0d0279c: 1f11 subs r1, r2, #4 c0d0279e: 4281 cmp r1, r0 c0d027a0: db00 blt.n c0d027a4 <u2f_transport_receive_fakeChannel+0xd8> c0d027a2: 4601 mov r1, r0 c0d027a4: 8461 strh r1, [r4, #34] ; 0x22 service->fakeChannelTransportPacketIndex = 0; c0d027a6: 2224 movs r2, #36 ; 0x24 c0d027a8: 2000 movs r0, #0 c0d027aa: 54a0 strb r0, [r4, r2] c0d027ac: 462a mov r2, r5 service->fakeChannelCrc = cx_crc16_update(0, buffer + 4, service->fakeChannelTransportOffset); c0d027ae: 400a ands r2, r1 c0d027b0: 9902 ldr r1, [sp, #8] c0d027b2: f7ff fc85 bl c0d020c0 <cx_crc16_update> c0d027b6: 8520 strh r0, [r4, #40] ; 0x28 uint16_t xfer_len = MIN(size - 5, service->transportLength - service->fakeChannelTransportOffset); service->fakeChannelTransportPacketIndex++; service->fakeChannelTransportOffset += xfer_len; service->fakeChannelCrc = cx_crc16_update(service->fakeChannelCrc, buffer + 5, xfer_len); } if (service->fakeChannelTransportOffset >= service->transportLength) { c0d027b8: 8b21 ldrh r1, [r4, #24] c0d027ba: 8c62 ldrh r2, [r4, #34] ; 0x22 c0d027bc: 428a cmp r2, r1 c0d027be: d30e bcc.n c0d027de <u2f_transport_receive_fakeChannel+0x112> if (service->fakeChannelCrc != service->commandCrc) { c0d027c0: 8ce1 ldrh r1, [r4, #38] ; 0x26 c0d027c2: 4288 cmp r0, r1 c0d027c4: d1a3 bne.n c0d0270e <u2f_transport_receive_fakeChannel+0x42> goto error; } service->fakeChannelTransportState = U2F_FAKE_RECEIVED; c0d027c6: 2006 movs r0, #6 c0d027c8: 7038 strb r0, [r7, #0] service->fakeChannelTransportOffset = 0; c0d027ca: 2500 movs r5, #0 c0d027cc: 8465 strh r5, [r4, #34] ; 0x22 // reply immediately when the asynch response is not yet ready if (service->waitAsynchronousResponse == U2F_WAIT_ASYNCH_ON) { c0d027ce: 202a movs r0, #42 ; 0x2a c0d027d0: 5c20 ldrb r0, [r4, r0] c0d027d2: 2801 cmp r0, #1 c0d027d4: d103 bne.n c0d027de <u2f_transport_receive_fakeChannel+0x112> u2f_transport_send_usb_user_presence_required(service); c0d027d6: 4620 mov r0, r4 c0d027d8: f7ff ff42 bl c0d02660 <u2f_transport_send_usb_user_presence_required> // response sent service->fakeChannelTransportState = U2F_IDLE; c0d027dc: 703d strb r5, [r7, #0] c0d027de: 9803 ldr r0, [sp, #12] c0d027e0: e798 b.n c0d02714 <u2f_transport_receive_fakeChannel+0x48> c0d027e2: 46c0 nop ; (mov r8, r8) c0d027e4: 0000ffff .word 0x0000ffff c0d027e8 <u2f_transport_received>: /** * Function that process every message received on a media. * Performs message concatenation when message is splitted. */ void u2f_transport_received(u2f_service_t *service, uint8_t *buffer, uint16_t size, u2f_transport_media_t media) { c0d027e8: b5f0 push {r4, r5, r6, r7, lr} c0d027ea: b08b sub sp, #44 ; 0x2c c0d027ec: 4604 mov r4, r0 uint16_t channelHeader = (media == U2F_MEDIA_USB ? 4 : 0); uint16_t xfer_len; service->media = media; c0d027ee: 7223 strb r3, [r4, #8] // Handle a busy channel and avoid reentry if (service->transportState == U2F_SENDING_RESPONSE) { c0d027f0: 2020 movs r0, #32 c0d027f2: 5c20 ldrb r0, [r4, r0] c0d027f4: 4627 mov r7, r4 c0d027f6: 3720 adds r7, #32 // Message to short, abort u2f_transport_error(service, ERROR_PROP_MESSAGE_TOO_SHORT); goto error; } // check this is a command, cannot accept continuation without previous command if ((buffer[channelHeader+0]&U2F_MASK_COMMAND) == 0) { c0d027f8: 2585 movs r5, #133 ; 0x85 uint16_t channelHeader = (media == U2F_MEDIA_USB ? 4 : 0); uint16_t xfer_len; service->media = media; // Handle a busy channel and avoid reentry if (service->transportState == U2F_SENDING_RESPONSE) { c0d027fa: 2803 cmp r0, #3 c0d027fc: d00e beq.n c0d0281c <u2f_transport_received+0x34> c0d027fe: 9109 str r1, [sp, #36] ; 0x24 c0d02800: 920a str r2, [sp, #40] ; 0x28 u2f_transport_error(service, ERROR_CHANNEL_BUSY); goto error; } if (service->waitAsynchronousResponse != U2F_WAIT_ASYNCH_IDLE) { c0d02802: 212a movs r1, #42 ; 0x2a c0d02804: 5c61 ldrb r1, [r4, r1] c0d02806: 4626 mov r6, r4 c0d02808: 362a adds r6, #42 ; 0x2a c0d0280a: 2900 cmp r1, #0 c0d0280c: d013 beq.n c0d02836 <u2f_transport_received+0x4e> if (!u2f_transport_receive_fakeChannel(service, buffer, size)) { c0d0280e: 4620 mov r0, r4 c0d02810: 9909 ldr r1, [sp, #36] ; 0x24 c0d02812: 9a0a ldr r2, [sp, #40] ; 0x28 c0d02814: f7ff ff5a bl c0d026cc <u2f_transport_receive_fakeChannel> c0d02818: 2800 cmp r0, #0 c0d0281a: d173 bne.n c0d02904 <u2f_transport_received+0x11c> c0d0281c: 48e0 ldr r0, [pc, #896] ; (c0d02ba0 <u2f_transport_received+0x3b8>) c0d0281e: 2106 movs r1, #6 c0d02820: 7201 strb r1, [r0, #8] c0d02822: 2104 movs r1, #4 c0d02824: 7039 strb r1, [r7, #0] c0d02826: 2100 movs r1, #0 c0d02828: 76a1 strb r1, [r4, #26] c0d0282a: 3008 adds r0, #8 c0d0282c: 61e0 str r0, [r4, #28] c0d0282e: 82e1 strh r1, [r4, #22] c0d02830: 2001 movs r0, #1 c0d02832: 8320 strh r0, [r4, #24] c0d02834: e05f b.n c0d028f6 <u2f_transport_received+0x10e> } return; } // SENDING_ERROR is accepted, and triggers a reset => means the host hasn't consumed the error. if (service->transportState == U2F_SENDING_ERROR) { c0d02836: 2804 cmp r0, #4 c0d02838: d109 bne.n c0d0284e <u2f_transport_received+0x66> c0d0283a: 2000 movs r0, #0 #warning TODO take into account the INIT during SEGMENTED message correctly (avoid erasing the first part of the apdu buffer when doing so) // init void u2f_transport_reset(u2f_service_t* service) { service->transportState = U2F_IDLE; service->transportOffset = 0; c0d0283c: 82e0 strh r0, [r4, #22] service->transportMedia = 0; service->transportPacketIndex = 0; c0d0283e: 76a0 strb r0, [r4, #26] service->fakeChannelTransportState = U2F_IDLE; service->fakeChannelTransportOffset = 0; service->fakeChannelTransportPacketIndex = 0; service->sending = false; c0d02840: 212b movs r1, #43 ; 0x2b c0d02842: 5460 strb r0, [r4, r1] service->waitAsynchronousResponse = U2F_WAIT_ASYNCH_IDLE; c0d02844: 7030 strb r0, [r6, #0] // init void u2f_transport_reset(u2f_service_t* service) { service->transportState = U2F_IDLE; service->transportOffset = 0; service->transportMedia = 0; c0d02846: 80b8 strh r0, [r7, #4] c0d02848: 6038 str r0, [r7, #0] service->fakeChannelTransportOffset = 0; service->fakeChannelTransportPacketIndex = 0; service->sending = false; service->waitAsynchronousResponse = U2F_WAIT_ASYNCH_IDLE; // reset the receive buffer to allow for a new message to be received again (in case transmission of a CODE buffer the previous reply) service->transportBuffer = service->transportReceiveBuffer; c0d0284a: 68e0 ldr r0, [r4, #12] c0d0284c: 61e0 str r0, [r4, #28] // SENDING_ERROR is accepted, and triggers a reset => means the host hasn't consumed the error. if (service->transportState == U2F_SENDING_ERROR) { u2f_transport_reset(service); } if (size < (1 + channelHeader)) { c0d0284e: 2104 movs r1, #4 c0d02850: 2000 movs r0, #0 c0d02852: 9308 str r3, [sp, #32] c0d02854: 2b01 cmp r3, #1 c0d02856: d000 beq.n c0d0285a <u2f_transport_received+0x72> c0d02858: 4601 mov r1, r0 c0d0285a: 2301 movs r3, #1 c0d0285c: 460a mov r2, r1 c0d0285e: 431a orrs r2, r3 c0d02860: 980a ldr r0, [sp, #40] ; 0x28 c0d02862: 4290 cmp r0, r2 c0d02864: d33d bcc.n c0d028e2 <u2f_transport_received+0xfa> c0d02866: 9204 str r2, [sp, #16] // Message to short, abort u2f_transport_error(service, ERROR_PROP_MESSAGE_TOO_SHORT); goto error; } if (media == U2F_MEDIA_USB) { c0d02868: 9808 ldr r0, [sp, #32] c0d0286a: 2801 cmp r0, #1 c0d0286c: 9106 str r1, [sp, #24] c0d0286e: 9505 str r5, [sp, #20] c0d02870: 9307 str r3, [sp, #28] c0d02872: d107 bne.n c0d02884 <u2f_transport_received+0x9c> // hold the current channel value to reply to, for example, INIT commands within flow of segments. os_memmove(service->channel, buffer, 4); c0d02874: 1d20 adds r0, r4, #4 c0d02876: 2204 movs r2, #4 c0d02878: 9909 ldr r1, [sp, #36] ; 0x24 c0d0287a: f7fe fa1c bl c0d00cb6 <os_memmove> c0d0287e: 9906 ldr r1, [sp, #24] c0d02880: 9b07 ldr r3, [sp, #28] c0d02882: 9d05 ldr r5, [sp, #20] } // no previous chunk processed for the current message if (service->transportOffset == 0 c0d02884: 8ae0 ldrh r0, [r4, #22] c0d02886: 4ac7 ldr r2, [pc, #796] ; (c0d02ba4 <u2f_transport_received+0x3bc>) // on USB we could get an INIT within a flow of segments. || (media == U2F_MEDIA_USB && os_memcmp(service->transportChannel, service->channel, 4) != 0) ) { c0d02888: 2800 cmp r0, #0 c0d0288a: d00f beq.n c0d028ac <u2f_transport_received+0xc4> c0d0288c: 9808 ldr r0, [sp, #32] c0d0288e: 2801 cmp r0, #1 c0d02890: d122 bne.n c0d028d8 <u2f_transport_received+0xf0> c0d02892: 4620 mov r0, r4 c0d02894: 3012 adds r0, #18 c0d02896: 1d21 adds r1, r4, #4 c0d02898: 4615 mov r5, r2 c0d0289a: 2204 movs r2, #4 c0d0289c: f7fe faa8 bl c0d00df0 <os_memcmp> c0d028a0: 9906 ldr r1, [sp, #24] c0d028a2: 462a mov r2, r5 c0d028a4: 9b07 ldr r3, [sp, #28] c0d028a6: 9d05 ldr r5, [sp, #20] // hold the current channel value to reply to, for example, INIT commands within flow of segments. os_memmove(service->channel, buffer, 4); } // no previous chunk processed for the current message if (service->transportOffset == 0 c0d028a8: 2800 cmp r0, #0 c0d028aa: d015 beq.n c0d028d8 <u2f_transport_received+0xf0> // on USB we could get an INIT within a flow of segments. || (media == U2F_MEDIA_USB && os_memcmp(service->transportChannel, service->channel, 4) != 0) ) { if (size < (channelHeader + 3)) { c0d028ac: 2603 movs r6, #3 c0d028ae: 4608 mov r0, r1 c0d028b0: 9603 str r6, [sp, #12] c0d028b2: 4330 orrs r0, r6 c0d028b4: 460e mov r6, r1 c0d028b6: 990a ldr r1, [sp, #40] ; 0x28 c0d028b8: 4281 cmp r1, r0 c0d028ba: d312 bcc.n c0d028e2 <u2f_transport_received+0xfa> c0d028bc: 9909 ldr r1, [sp, #36] ; 0x24 // Message to short, abort u2f_transport_error(service, ERROR_PROP_MESSAGE_TOO_SHORT); goto error; } // check this is a command, cannot accept continuation without previous command if ((buffer[channelHeader+0]&U2F_MASK_COMMAND) == 0) { c0d028be: 1988 adds r0, r1, r6 c0d028c0: 9002 str r0, [sp, #8] c0d028c2: 5788 ldrsb r0, [r1, r6] c0d028c4: 460e mov r6, r1 c0d028c6: 4629 mov r1, r5 c0d028c8: 317a adds r1, #122 ; 0x7a c0d028ca: b249 sxtb r1, r1 c0d028cc: 4288 cmp r0, r1 c0d028ce: dd37 ble.n c0d02940 <u2f_transport_received+0x158> c0d028d0: 48b3 ldr r0, [pc, #716] ; (c0d02ba0 <u2f_transport_received+0x3b8>) c0d028d2: 2104 movs r1, #4 c0d028d4: 7201 strb r1, [r0, #8] c0d028d6: e007 b.n c0d028e8 <u2f_transport_received+0x100> c0d028d8: 2002 movs r0, #2 service->transportPacketIndex = 0; os_memmove(service->transportChannel, service->channel, 4); } } else { // Continuation if (size < (channelHeader + 2)) { c0d028da: 4308 orrs r0, r1 c0d028dc: 990a ldr r1, [sp, #40] ; 0x28 c0d028de: 4281 cmp r1, r0 c0d028e0: d212 bcs.n c0d02908 <u2f_transport_received+0x120> c0d028e2: 48af ldr r0, [pc, #700] ; (c0d02ba0 <u2f_transport_received+0x3b8>) c0d028e4: 7205 strb r5, [r0, #8] c0d028e6: 2104 movs r1, #4 c0d028e8: 7039 strb r1, [r7, #0] c0d028ea: 2100 movs r1, #0 c0d028ec: 76a1 strb r1, [r4, #26] c0d028ee: 3008 adds r0, #8 c0d028f0: 61e0 str r0, [r4, #28] c0d028f2: 82e1 strh r1, [r4, #22] c0d028f4: 8323 strh r3, [r4, #24] c0d028f6: 353a adds r5, #58 ; 0x3a c0d028f8: 2040 movs r0, #64 ; 0x40 c0d028fa: 5425 strb r5, [r4, r0] c0d028fc: 7a21 ldrb r1, [r4, #8] c0d028fe: 4620 mov r0, r4 c0d02900: f7ff fe38 bl c0d02574 <u2f_transport_sent> service->seqTimeout = 0; service->transportState = U2F_HANDLE_SEGMENTED; } error: return; } c0d02904: b00b add sp, #44 ; 0x2c c0d02906: bdf0 pop {r4, r5, r6, r7, pc} if (size < (channelHeader + 2)) { // Message to short, abort u2f_transport_error(service, ERROR_PROP_MESSAGE_TOO_SHORT); goto error; } if (media != service->transportMedia) { c0d02908: 2021 movs r0, #33 ; 0x21 c0d0290a: 5c20 ldrb r0, [r4, r0] c0d0290c: 9908 ldr r1, [sp, #32] c0d0290e: 4288 cmp r0, r1 c0d02910: d14d bne.n c0d029ae <u2f_transport_received+0x1c6> // Mixed medias u2f_transport_error(service, ERROR_PROP_MEDIA_MIXED); goto error; } if (service->transportState != U2F_HANDLE_SEGMENTED) { c0d02912: 7838 ldrb r0, [r7, #0] c0d02914: 2801 cmp r0, #1 c0d02916: d156 bne.n c0d029c6 <u2f_transport_received+0x1de> c0d02918: 9203 str r2, [sp, #12] } else { u2f_transport_error(service, ERROR_INVALID_SEQ); goto error; } } if (media == U2F_MEDIA_USB) { c0d0291a: 9808 ldr r0, [sp, #32] c0d0291c: 2801 cmp r0, #1 c0d0291e: d000 beq.n c0d02922 <u2f_transport_received+0x13a> c0d02920: e085 b.n c0d02a2e <u2f_transport_received+0x246> // Check the channel if (os_memcmp(buffer, service->channel, 4) != 0) { c0d02922: 1d21 adds r1, r4, #4 c0d02924: 2504 movs r5, #4 c0d02926: 9809 ldr r0, [sp, #36] ; 0x24 c0d02928: 462a mov r2, r5 c0d0292a: 461e mov r6, r3 c0d0292c: f7fe fa60 bl c0d00df0 <os_memcmp> c0d02930: 4633 mov r3, r6 c0d02932: 2800 cmp r0, #0 c0d02934: d07b beq.n c0d02a2e <u2f_transport_received+0x246> /** * Reply an error at the U2F transport level (take into account the FIDO U2F framing) */ static void u2f_transport_error(u2f_service_t *service, char errorCode) { //u2f_transport_reset(service); // warning reset first to allow for U2F_io sent call to u2f_transport_sent internally on eventless platforms G_io_usb_ep_buffer[8] = errorCode; c0d02936: 489a ldr r0, [pc, #616] ; (c0d02ba0 <u2f_transport_received+0x3b8>) c0d02938: 2106 movs r1, #6 c0d0293a: 7201 strb r1, [r0, #8] // ensure the state is set to error sending to allow for special treatment in case reply is not read by the receiver service->transportState = U2F_SENDING_ERROR; c0d0293c: 703d strb r5, [r7, #0] c0d0293e: e0f6 b.n c0d02b2e <u2f_transport_received+0x346> c0d02940: 9b08 ldr r3, [sp, #32] goto error; } // If waiting for a continuation on a different channel, reply BUSY // immediately if (media == U2F_MEDIA_USB) { c0d02942: 2b01 cmp r3, #1 c0d02944: d116 bne.n c0d02974 <u2f_transport_received+0x18c> if ((service->transportState == U2F_HANDLE_SEGMENTED) && c0d02946: 7838 ldrb r0, [r7, #0] c0d02948: 2801 cmp r0, #1 c0d0294a: d11f bne.n c0d0298c <u2f_transport_received+0x1a4> (os_memcmp(service->channel, service->transportChannel, 4) != c0d0294c: 1d20 adds r0, r4, #4 c0d0294e: 4621 mov r1, r4 c0d02950: 3112 adds r1, #18 c0d02952: 4615 mov r5, r2 c0d02954: 2204 movs r2, #4 c0d02956: 9001 str r0, [sp, #4] c0d02958: f7fe fa4a bl c0d00df0 <os_memcmp> c0d0295c: 462a mov r2, r5 c0d0295e: 9b08 ldr r3, [sp, #32] c0d02960: 9d05 ldr r5, [sp, #20] 0) && c0d02962: 2800 cmp r0, #0 c0d02964: d006 beq.n c0d02974 <u2f_transport_received+0x18c> (buffer[channelHeader] != U2F_CMD_INIT)) { c0d02966: 9802 ldr r0, [sp, #8] c0d02968: 7800 ldrb r0, [r0, #0] c0d0296a: 1c69 adds r1, r5, #1 c0d0296c: b2c9 uxtb r1, r1 } // If waiting for a continuation on a different channel, reply BUSY // immediately if (media == U2F_MEDIA_USB) { if ((service->transportState == U2F_HANDLE_SEGMENTED) && c0d0296e: 4288 cmp r0, r1 c0d02970: d000 beq.n c0d02974 <u2f_transport_received+0x18c> c0d02972: e0f6 b.n c0d02b62 <u2f_transport_received+0x37a> goto error; } } // If a command was already sent, and we are not processing a INIT // command, abort if ((service->transportState == U2F_HANDLE_SEGMENTED) && c0d02974: 7838 ldrb r0, [r7, #0] c0d02976: 2801 cmp r0, #1 c0d02978: d108 bne.n c0d0298c <u2f_transport_received+0x1a4> !((media == U2F_MEDIA_USB) && c0d0297a: 2b01 cmp r3, #1 c0d0297c: d000 beq.n c0d02980 <u2f_transport_received+0x198> c0d0297e: e082 b.n c0d02a86 <u2f_transport_received+0x29e> (buffer[channelHeader] == U2F_CMD_INIT))) { c0d02980: 9802 ldr r0, [sp, #8] c0d02982: 7800 ldrb r0, [r0, #0] c0d02984: 1c69 adds r1, r5, #1 c0d02986: b2c9 uxtb r1, r1 goto error; } } // If a command was already sent, and we are not processing a INIT // command, abort if ((service->transportState == U2F_HANDLE_SEGMENTED) && c0d02988: 4288 cmp r0, r1 c0d0298a: d17c bne.n c0d02a86 <u2f_transport_received+0x29e> u2f_transport_error(service, ERROR_INVALID_SEQ); goto error; } // Check the length uint16_t commandLength = (buffer[channelHeader + 1] << 8) | (buffer[channelHeader + 2]); c0d0298c: 2002 movs r0, #2 c0d0298e: 9906 ldr r1, [sp, #24] c0d02990: 4308 orrs r0, r1 c0d02992: 5c30 ldrb r0, [r6, r0] c0d02994: 9904 ldr r1, [sp, #16] c0d02996: 5c71 ldrb r1, [r6, r1] c0d02998: 0209 lsls r1, r1, #8 c0d0299a: 4301 orrs r1, r0 if (commandLength > (service->transportReceiveBufferLength - 3)) { c0d0299c: 8a20 ldrh r0, [r4, #16] c0d0299e: 1ec0 subs r0, r0, #3 c0d029a0: 4281 cmp r1, r0 c0d029a2: dd1e ble.n c0d029e2 <u2f_transport_received+0x1fa> /** * Reply an error at the U2F transport level (take into account the FIDO U2F framing) */ static void u2f_transport_error(u2f_service_t *service, char errorCode) { //u2f_transport_reset(service); // warning reset first to allow for U2F_io sent call to u2f_transport_sent internally on eventless platforms G_io_usb_ep_buffer[8] = errorCode; c0d029a4: 487e ldr r0, [pc, #504] ; (c0d02ba0 <u2f_transport_received+0x3b8>) c0d029a6: 9903 ldr r1, [sp, #12] c0d029a8: 7201 strb r1, [r0, #8] // ensure the state is set to error sending to allow for special treatment in case reply is not read by the receiver service->transportState = U2F_SENDING_ERROR; c0d029aa: 2104 movs r1, #4 c0d029ac: e06e b.n c0d02a8c <u2f_transport_received+0x2a4> /** * Reply an error at the U2F transport level (take into account the FIDO U2F framing) */ static void u2f_transport_error(u2f_service_t *service, char errorCode) { //u2f_transport_reset(service); // warning reset first to allow for U2F_io sent call to u2f_transport_sent internally on eventless platforms G_io_usb_ep_buffer[8] = errorCode; c0d029ae: 4628 mov r0, r5 c0d029b0: 3008 adds r0, #8 c0d029b2: 497b ldr r1, [pc, #492] ; (c0d02ba0 <u2f_transport_received+0x3b8>) c0d029b4: 7208 strb r0, [r1, #8] // ensure the state is set to error sending to allow for special treatment in case reply is not read by the receiver service->transportState = U2F_SENDING_ERROR; c0d029b6: 2004 movs r0, #4 c0d029b8: 7038 strb r0, [r7, #0] c0d029ba: 2000 movs r0, #0 service->transportPacketIndex = 0; c0d029bc: 76a0 strb r0, [r4, #26] /** * Reply an error at the U2F transport level (take into account the FIDO U2F framing) */ static void u2f_transport_error(u2f_service_t *service, char errorCode) { //u2f_transport_reset(service); // warning reset first to allow for U2F_io sent call to u2f_transport_sent internally on eventless platforms G_io_usb_ep_buffer[8] = errorCode; c0d029be: 3108 adds r1, #8 // ensure the state is set to error sending to allow for special treatment in case reply is not read by the receiver service->transportState = U2F_SENDING_ERROR; service->transportPacketIndex = 0; service->transportBuffer = G_io_usb_ep_buffer + 8; c0d029c0: 61e1 str r1, [r4, #28] service->transportOffset = 0; c0d029c2: 82e0 strh r0, [r4, #22] c0d029c4: e796 b.n c0d028f4 <u2f_transport_received+0x10c> goto error; } if (service->transportState != U2F_HANDLE_SEGMENTED) { // Unexpected continuation at this stage, abort // TODO : review the behavior is HID only if (media == U2F_MEDIA_USB) { c0d029c6: 9808 ldr r0, [sp, #32] c0d029c8: 2801 cmp r0, #1 c0d029ca: d181 bne.n c0d028d0 <u2f_transport_received+0xe8> c0d029cc: 2000 movs r0, #0 #warning TODO take into account the INIT during SEGMENTED message correctly (avoid erasing the first part of the apdu buffer when doing so) // init void u2f_transport_reset(u2f_service_t* service) { service->transportState = U2F_IDLE; service->transportOffset = 0; c0d029ce: 82e0 strh r0, [r4, #22] service->transportMedia = 0; service->transportPacketIndex = 0; c0d029d0: 76a0 strb r0, [r4, #26] service->fakeChannelTransportState = U2F_IDLE; service->fakeChannelTransportOffset = 0; service->fakeChannelTransportPacketIndex = 0; service->sending = false; c0d029d2: 212b movs r1, #43 ; 0x2b c0d029d4: 5460 strb r0, [r4, r1] service->waitAsynchronousResponse = U2F_WAIT_ASYNCH_IDLE; c0d029d6: 7030 strb r0, [r6, #0] // init void u2f_transport_reset(u2f_service_t* service) { service->transportState = U2F_IDLE; service->transportOffset = 0; service->transportMedia = 0; c0d029d8: 80b8 strh r0, [r7, #4] c0d029da: 6038 str r0, [r7, #0] service->fakeChannelTransportOffset = 0; service->fakeChannelTransportPacketIndex = 0; service->sending = false; service->waitAsynchronousResponse = U2F_WAIT_ASYNCH_IDLE; // reset the receive buffer to allow for a new message to be received again (in case transmission of a CODE buffer the previous reply) service->transportBuffer = service->transportReceiveBuffer; c0d029dc: 68e0 ldr r0, [r4, #12] c0d029de: 61e0 str r0, [r4, #28] c0d029e0: e790 b.n c0d02904 <u2f_transport_received+0x11c> // Overflow in message size, abort u2f_transport_error(service, ERROR_INVALID_LEN); goto error; } // Check if the command is supported switch (buffer[channelHeader]) { c0d029e2: 9802 ldr r0, [sp, #8] c0d029e4: 7800 ldrb r0, [r0, #0] c0d029e6: 2881 cmp r0, #129 ; 0x81 c0d029e8: 9b07 ldr r3, [sp, #28] c0d029ea: d004 beq.n c0d029f6 <u2f_transport_received+0x20e> c0d029ec: 2886 cmp r0, #134 ; 0x86 c0d029ee: d059 beq.n c0d02aa4 <u2f_transport_received+0x2bc> c0d029f0: 2883 cmp r0, #131 ; 0x83 c0d029f2: d000 beq.n c0d029f6 <u2f_transport_received+0x20e> c0d029f4: e0ac b.n c0d02b50 <u2f_transport_received+0x368> c0d029f6: 9109 str r1, [sp, #36] ; 0x24 c0d029f8: 9203 str r2, [sp, #12] case U2F_CMD_PING: case U2F_CMD_MSG: if (media == U2F_MEDIA_USB) { c0d029fa: 9808 ldr r0, [sp, #32] c0d029fc: 2801 cmp r0, #1 c0d029fe: d15f bne.n c0d02ac0 <u2f_transport_received+0x2d8> if (u2f_is_channel_broadcast(service->channel) || c0d02a00: 1d26 adds r6, r4, #4 error: return; } bool u2f_is_channel_broadcast(uint8_t *channel) { return (os_memcmp(channel, BROADCAST_CHANNEL, 4) == 0); c0d02a02: 4969 ldr r1, [pc, #420] ; (c0d02ba8 <u2f_transport_received+0x3c0>) c0d02a04: 4479 add r1, pc c0d02a06: 2504 movs r5, #4 c0d02a08: 4630 mov r0, r6 c0d02a0a: 462a mov r2, r5 c0d02a0c: f7fe f9f0 bl c0d00df0 <os_memcmp> // Check if the command is supported switch (buffer[channelHeader]) { case U2F_CMD_PING: case U2F_CMD_MSG: if (media == U2F_MEDIA_USB) { if (u2f_is_channel_broadcast(service->channel) || c0d02a10: 2800 cmp r0, #0 c0d02a12: d007 beq.n c0d02a24 <u2f_transport_received+0x23c> bool u2f_is_channel_broadcast(uint8_t *channel) { return (os_memcmp(channel, BROADCAST_CHANNEL, 4) == 0); } bool u2f_is_channel_forbidden(uint8_t *channel) { return (os_memcmp(channel, FORBIDDEN_CHANNEL, 4) == 0); c0d02a14: 4965 ldr r1, [pc, #404] ; (c0d02bac <u2f_transport_received+0x3c4>) c0d02a16: 4479 add r1, pc c0d02a18: 2204 movs r2, #4 c0d02a1a: 4630 mov r0, r6 c0d02a1c: f7fe f9e8 bl c0d00df0 <os_memcmp> // Check if the command is supported switch (buffer[channelHeader]) { case U2F_CMD_PING: case U2F_CMD_MSG: if (media == U2F_MEDIA_USB) { if (u2f_is_channel_broadcast(service->channel) || c0d02a20: 2800 cmp r0, #0 c0d02a22: d14d bne.n c0d02ac0 <u2f_transport_received+0x2d8> /** * Reply an error at the U2F transport level (take into account the FIDO U2F framing) */ static void u2f_transport_error(u2f_service_t *service, char errorCode) { //u2f_transport_reset(service); // warning reset first to allow for U2F_io sent call to u2f_transport_sent internally on eventless platforms G_io_usb_ep_buffer[8] = errorCode; c0d02a24: 485e ldr r0, [pc, #376] ; (c0d02ba0 <u2f_transport_received+0x3b8>) c0d02a26: 210b movs r1, #11 c0d02a28: 7201 strb r1, [r0, #8] // ensure the state is set to error sending to allow for special treatment in case reply is not read by the receiver service->transportState = U2F_SENDING_ERROR; c0d02a2a: 703d strb r5, [r7, #0] c0d02a2c: e0b0 b.n c0d02b90 <u2f_transport_received+0x3a8> c0d02a2e: 9806 ldr r0, [sp, #24] c0d02a30: 9a09 ldr r2, [sp, #36] ; 0x24 u2f_transport_error(service, ERROR_CHANNEL_BUSY); goto error; } } // also discriminate invalid command sent instead of a continuation if (buffer[channelHeader] != service->transportPacketIndex) { c0d02a32: 1811 adds r1, r2, r0 c0d02a34: 5c10 ldrb r0, [r2, r0] c0d02a36: 7ea2 ldrb r2, [r4, #26] c0d02a38: 4290 cmp r0, r2 c0d02a3a: d12f bne.n c0d02a9c <u2f_transport_received+0x2b4> // Bad continuation packet, abort u2f_transport_error(service, ERROR_INVALID_SEQ); goto error; } xfer_len = MIN(size - (channelHeader + 1), service->transportLength - service->transportOffset); c0d02a3c: 980a ldr r0, [sp, #40] ; 0x28 c0d02a3e: 9a04 ldr r2, [sp, #16] c0d02a40: 1a85 subs r5, r0, r2 c0d02a42: 8ae0 ldrh r0, [r4, #22] c0d02a44: 8b22 ldrh r2, [r4, #24] c0d02a46: 1a12 subs r2, r2, r0 c0d02a48: 4295 cmp r5, r2 c0d02a4a: db00 blt.n c0d02a4e <u2f_transport_received+0x266> c0d02a4c: 4615 mov r5, r2 c0d02a4e: 9e03 ldr r6, [sp, #12] os_memmove(service->transportBuffer + service->transportOffset, buffer + channelHeader + 1, xfer_len); c0d02a50: 402e ands r6, r5 c0d02a52: 69e2 ldr r2, [r4, #28] c0d02a54: 1810 adds r0, r2, r0 c0d02a56: 1c49 adds r1, r1, #1 c0d02a58: 4632 mov r2, r6 c0d02a5a: f7fe f92c bl c0d00cb6 <os_memmove> if (media == U2F_MEDIA_USB) { c0d02a5e: 9808 ldr r0, [sp, #32] c0d02a60: 2801 cmp r0, #1 c0d02a62: d107 bne.n c0d02a74 <u2f_transport_received+0x28c> service->commandCrc = cx_crc16_update(service->commandCrc, service->transportBuffer + service->transportOffset, xfer_len); c0d02a64: 8ae0 ldrh r0, [r4, #22] c0d02a66: 69e1 ldr r1, [r4, #28] c0d02a68: 1809 adds r1, r1, r0 c0d02a6a: 8ce0 ldrh r0, [r4, #38] ; 0x26 c0d02a6c: 4632 mov r2, r6 c0d02a6e: f7ff fb27 bl c0d020c0 <cx_crc16_update> c0d02a72: 84e0 strh r0, [r4, #38] ; 0x26 } service->transportOffset += xfer_len; c0d02a74: 8ae0 ldrh r0, [r4, #22] c0d02a76: 1940 adds r0, r0, r5 c0d02a78: 82e0 strh r0, [r4, #22] service->transportPacketIndex++; c0d02a7a: 7ea0 ldrb r0, [r4, #26] c0d02a7c: 1c40 adds r0, r0, #1 c0d02a7e: 76a0 strb r0, [r4, #26] c0d02a80: 9b07 ldr r3, [sp, #28] c0d02a82: 9d08 ldr r5, [sp, #32] c0d02a84: e045 b.n c0d02b12 <u2f_transport_received+0x32a> /** * Reply an error at the U2F transport level (take into account the FIDO U2F framing) */ static void u2f_transport_error(u2f_service_t *service, char errorCode) { //u2f_transport_reset(service); // warning reset first to allow for U2F_io sent call to u2f_transport_sent internally on eventless platforms G_io_usb_ep_buffer[8] = errorCode; c0d02a86: 4846 ldr r0, [pc, #280] ; (c0d02ba0 <u2f_transport_received+0x3b8>) c0d02a88: 2104 movs r1, #4 c0d02a8a: 7201 strb r1, [r0, #8] c0d02a8c: 7039 strb r1, [r7, #0] c0d02a8e: 2100 movs r1, #0 c0d02a90: 76a1 strb r1, [r4, #26] c0d02a92: 3008 adds r0, #8 c0d02a94: 61e0 str r0, [r4, #28] c0d02a96: 82e1 strh r1, [r4, #22] c0d02a98: 9807 ldr r0, [sp, #28] c0d02a9a: e6ca b.n c0d02832 <u2f_transport_received+0x4a> c0d02a9c: 4840 ldr r0, [pc, #256] ; (c0d02ba0 <u2f_transport_received+0x3b8>) c0d02a9e: 2104 movs r1, #4 c0d02aa0: 7201 strb r1, [r0, #8] c0d02aa2: e043 b.n c0d02b2c <u2f_transport_received+0x344> } } // no channel for BLE break; case U2F_CMD_INIT: if (media != U2F_MEDIA_USB) { c0d02aa4: 9808 ldr r0, [sp, #32] c0d02aa6: 2801 cmp r0, #1 c0d02aa8: d152 bne.n c0d02b50 <u2f_transport_received+0x368> c0d02aaa: 9109 str r1, [sp, #36] ; 0x24 c0d02aac: 9203 str r2, [sp, #12] // Unknown command, abort u2f_transport_error(service, ERROR_INVALID_CMD); goto error; } if (u2f_is_channel_forbidden(service->channel)) { c0d02aae: 1d20 adds r0, r4, #4 bool u2f_is_channel_broadcast(uint8_t *channel) { return (os_memcmp(channel, BROADCAST_CHANNEL, 4) == 0); } bool u2f_is_channel_forbidden(uint8_t *channel) { return (os_memcmp(channel, FORBIDDEN_CHANNEL, 4) == 0); c0d02ab0: 493f ldr r1, [pc, #252] ; (c0d02bb0 <u2f_transport_received+0x3c8>) c0d02ab2: 4479 add r1, pc c0d02ab4: 2604 movs r6, #4 c0d02ab6: 4632 mov r2, r6 c0d02ab8: f7fe f99a bl c0d00df0 <os_memcmp> // Unknown command, abort u2f_transport_error(service, ERROR_INVALID_CMD); goto error; } if (u2f_is_channel_forbidden(service->channel)) { c0d02abc: 2800 cmp r0, #0 c0d02abe: d063 beq.n c0d02b88 <u2f_transport_received+0x3a0> } // Ok, initialize the buffer //if (buffer[channelHeader] != U2F_CMD_INIT) { xfer_len = MIN(size - (channelHeader), U2F_COMMAND_HEADER_SIZE+commandLength); c0d02ac0: 980a ldr r0, [sp, #40] ; 0x28 c0d02ac2: 9906 ldr r1, [sp, #24] c0d02ac4: 1a46 subs r6, r0, r1 c0d02ac6: 9809 ldr r0, [sp, #36] ; 0x24 c0d02ac8: 1cc0 adds r0, r0, #3 c0d02aca: 4286 cmp r6, r0 c0d02acc: 9d03 ldr r5, [sp, #12] c0d02ace: db00 blt.n c0d02ad2 <u2f_transport_received+0x2ea> c0d02ad0: 4606 mov r6, r0 c0d02ad2: 900a str r0, [sp, #40] ; 0x28 os_memmove(service->transportBuffer, buffer + channelHeader, xfer_len); c0d02ad4: 4035 ands r5, r6 c0d02ad6: 69e0 ldr r0, [r4, #28] c0d02ad8: 9902 ldr r1, [sp, #8] c0d02ada: 462a mov r2, r5 c0d02adc: f7fe f8eb bl c0d00cb6 <os_memmove> c0d02ae0: 9b08 ldr r3, [sp, #32] if (media == U2F_MEDIA_USB) { c0d02ae2: 2b01 cmp r3, #1 c0d02ae4: d106 bne.n c0d02af4 <u2f_transport_received+0x30c> service->commandCrc = cx_crc16_update(0, service->transportBuffer, xfer_len); c0d02ae6: 69e1 ldr r1, [r4, #28] c0d02ae8: 2000 movs r0, #0 c0d02aea: 462a mov r2, r5 c0d02aec: f7ff fae8 bl c0d020c0 <cx_crc16_update> c0d02af0: 9b08 ldr r3, [sp, #32] c0d02af2: 84e0 strh r0, [r4, #38] ; 0x26 } service->transportOffset = xfer_len; c0d02af4: 82e6 strh r6, [r4, #22] service->transportLength = U2F_COMMAND_HEADER_SIZE+commandLength; c0d02af6: 980a ldr r0, [sp, #40] ; 0x28 c0d02af8: 8320 strh r0, [r4, #24] service->transportMedia = media; c0d02afa: 2021 movs r0, #33 ; 0x21 c0d02afc: 5423 strb r3, [r4, r0] // initialize the response service->transportPacketIndex = 0; c0d02afe: 2000 movs r0, #0 c0d02b00: 76a0 strb r0, [r4, #26] os_memmove(service->transportChannel, service->channel, 4); c0d02b02: 4620 mov r0, r4 c0d02b04: 3012 adds r0, #18 c0d02b06: 1d21 adds r1, r4, #4 c0d02b08: 2204 movs r2, #4 c0d02b0a: 461d mov r5, r3 c0d02b0c: f7fe f8d3 bl c0d00cb6 <os_memmove> c0d02b10: 9b07 ldr r3, [sp, #28] c0d02b12: 8ae0 ldrh r0, [r4, #22] } service->transportOffset += xfer_len; service->transportPacketIndex++; } // See if we can process the command if ((media != U2F_MEDIA_USB) && c0d02b14: 2d01 cmp r5, #1 c0d02b16: d101 bne.n c0d02b1c <u2f_transport_received+0x334> c0d02b18: 8b21 ldrh r1, [r4, #24] c0d02b1a: e013 b.n c0d02b44 <u2f_transport_received+0x35c> (service->transportOffset > (service->transportLength + U2F_COMMAND_HEADER_SIZE))) { c0d02b1c: 8b21 ldrh r1, [r4, #24] c0d02b1e: 1cca adds r2, r1, #3 } service->transportOffset += xfer_len; service->transportPacketIndex++; } // See if we can process the command if ((media != U2F_MEDIA_USB) && c0d02b20: 4290 cmp r0, r2 c0d02b22: d90f bls.n c0d02b44 <u2f_transport_received+0x35c> /** * Reply an error at the U2F transport level (take into account the FIDO U2F framing) */ static void u2f_transport_error(u2f_service_t *service, char errorCode) { //u2f_transport_reset(service); // warning reset first to allow for U2F_io sent call to u2f_transport_sent internally on eventless platforms G_io_usb_ep_buffer[8] = errorCode; c0d02b24: 481e ldr r0, [pc, #120] ; (c0d02ba0 <u2f_transport_received+0x3b8>) c0d02b26: 2103 movs r1, #3 c0d02b28: 7201 strb r1, [r0, #8] // ensure the state is set to error sending to allow for special treatment in case reply is not read by the receiver service->transportState = U2F_SENDING_ERROR; c0d02b2a: 2104 movs r1, #4 c0d02b2c: 7039 strb r1, [r7, #0] c0d02b2e: 2100 movs r1, #0 c0d02b30: 76a1 strb r1, [r4, #26] c0d02b32: 3008 adds r0, #8 c0d02b34: 61e0 str r0, [r4, #28] c0d02b36: 82e1 strh r1, [r4, #22] c0d02b38: 8323 strh r3, [r4, #24] c0d02b3a: 9905 ldr r1, [sp, #20] c0d02b3c: 313a adds r1, #58 ; 0x3a c0d02b3e: 2040 movs r0, #64 ; 0x40 c0d02b40: 5421 strb r1, [r4, r0] c0d02b42: e6db b.n c0d028fc <u2f_transport_received+0x114> (service->transportOffset > (service->transportLength + U2F_COMMAND_HEADER_SIZE))) { // Overflow, abort u2f_transport_error(service, ERROR_INVALID_LEN); goto error; } else if (service->transportOffset >= service->transportLength) { c0d02b44: 4288 cmp r0, r1 c0d02b46: d206 bcs.n c0d02b56 <u2f_transport_received+0x36e> c0d02b48: 2000 movs r0, #0 service->transportState = U2F_PROCESSING_COMMAND; // internal notification of a complete message received u2f_message_complete(service); } else { // new segment received, reset the timeout for the current piece service->seqTimeout = 0; c0d02b4a: 6360 str r0, [r4, #52] ; 0x34 service->transportState = U2F_HANDLE_SEGMENTED; c0d02b4c: 703b strb r3, [r7, #0] c0d02b4e: e6d9 b.n c0d02904 <u2f_transport_received+0x11c> c0d02b50: 4813 ldr r0, [pc, #76] ; (c0d02ba0 <u2f_transport_received+0x3b8>) c0d02b52: 7203 strb r3, [r0, #8] c0d02b54: e6c7 b.n c0d028e6 <u2f_transport_received+0xfe> // Overflow, abort u2f_transport_error(service, ERROR_INVALID_LEN); goto error; } else if (service->transportOffset >= service->transportLength) { // switch before the handler gets the opportunity to change it again service->transportState = U2F_PROCESSING_COMMAND; c0d02b56: 2002 movs r0, #2 c0d02b58: 7038 strb r0, [r7, #0] // internal notification of a complete message received u2f_message_complete(service); c0d02b5a: 4620 mov r0, r4 c0d02b5c: f7ff fca8 bl c0d024b0 <u2f_message_complete> c0d02b60: e6d0 b.n c0d02904 <u2f_transport_received+0x11c> // special error case, we reply but don't change the current state of the transport (ongoing message for example) //u2f_transport_error_no_reset(service, ERROR_CHANNEL_BUSY); uint16_t offset = 0; // Fragment if (media == U2F_MEDIA_USB) { os_memmove(G_io_usb_ep_buffer, service->channel, 4); c0d02b62: 4c0f ldr r4, [pc, #60] ; (c0d02ba0 <u2f_transport_received+0x3b8>) c0d02b64: 2204 movs r2, #4 c0d02b66: 4620 mov r0, r4 c0d02b68: 9901 ldr r1, [sp, #4] c0d02b6a: f7fe f8a4 bl c0d00cb6 <os_memmove> offset += 4; } G_io_usb_ep_buffer[offset++] = U2F_STATUS_ERROR; c0d02b6e: 353a adds r5, #58 ; 0x3a c0d02b70: 7125 strb r5, [r4, #4] G_io_usb_ep_buffer[offset++] = 0; c0d02b72: 2000 movs r0, #0 c0d02b74: 7160 strb r0, [r4, #5] c0d02b76: 9a07 ldr r2, [sp, #28] G_io_usb_ep_buffer[offset++] = 1; c0d02b78: 71a2 strb r2, [r4, #6] c0d02b7a: 2006 movs r0, #6 G_io_usb_ep_buffer[offset++] = ERROR_CHANNEL_BUSY; c0d02b7c: 71e0 strb r0, [r4, #7] u2f_io_send(G_io_usb_ep_buffer, offset, media); c0d02b7e: 2108 movs r1, #8 c0d02b80: 4620 mov r0, r4 c0d02b82: f7ff fcb3 bl c0d024ec <u2f_io_send> c0d02b86: e6bd b.n c0d02904 <u2f_transport_received+0x11c> /** * Reply an error at the U2F transport level (take into account the FIDO U2F framing) */ static void u2f_transport_error(u2f_service_t *service, char errorCode) { //u2f_transport_reset(service); // warning reset first to allow for U2F_io sent call to u2f_transport_sent internally on eventless platforms G_io_usb_ep_buffer[8] = errorCode; c0d02b88: 4805 ldr r0, [pc, #20] ; (c0d02ba0 <u2f_transport_received+0x3b8>) c0d02b8a: 210b movs r1, #11 c0d02b8c: 7201 strb r1, [r0, #8] // ensure the state is set to error sending to allow for special treatment in case reply is not read by the receiver service->transportState = U2F_SENDING_ERROR; c0d02b8e: 703e strb r6, [r7, #0] c0d02b90: 2100 movs r1, #0 c0d02b92: 76a1 strb r1, [r4, #26] c0d02b94: 3008 adds r0, #8 c0d02b96: 61e0 str r0, [r4, #28] c0d02b98: 82e1 strh r1, [r4, #22] c0d02b9a: 9807 ldr r0, [sp, #28] c0d02b9c: 8320 strh r0, [r4, #24] c0d02b9e: e7cc b.n c0d02b3a <u2f_transport_received+0x352> c0d02ba0: 20001ac0 .word 0x20001ac0 c0d02ba4: 0000ffff .word 0x0000ffff c0d02ba8: 000019ec .word 0x000019ec c0d02bac: 000019de .word 0x000019de c0d02bb0: 00001942 .word 0x00001942 c0d02bb4 <u2f_is_channel_broadcast>: } error: return; } bool u2f_is_channel_broadcast(uint8_t *channel) { c0d02bb4: b580 push {r7, lr} return (os_memcmp(channel, BROADCAST_CHANNEL, 4) == 0); c0d02bb6: 4906 ldr r1, [pc, #24] ; (c0d02bd0 <u2f_is_channel_broadcast+0x1c>) c0d02bb8: 4479 add r1, pc c0d02bba: 2204 movs r2, #4 c0d02bbc: f7fe f918 bl c0d00df0 <os_memcmp> c0d02bc0: 4601 mov r1, r0 c0d02bc2: 2001 movs r0, #1 c0d02bc4: 2200 movs r2, #0 c0d02bc6: 2900 cmp r1, #0 c0d02bc8: d000 beq.n c0d02bcc <u2f_is_channel_broadcast+0x18> c0d02bca: 4610 mov r0, r2 c0d02bcc: bd80 pop {r7, pc} c0d02bce: 46c0 nop ; (mov r8, r8) c0d02bd0: 00001838 .word 0x00001838 c0d02bd4 <u2f_message_set_autoreply_wait_user_presence>: } /** * Auto reply hodl until the real reply is prepared and sent */ void u2f_message_set_autoreply_wait_user_presence(u2f_service_t* service, bool enabled) { c0d02bd4: b580 push {r7, lr} c0d02bd6: 222a movs r2, #42 ; 0x2a c0d02bd8: 5c83 ldrb r3, [r0, r2] c0d02bda: 4602 mov r2, r0 c0d02bdc: 322a adds r2, #42 ; 0x2a if (enabled) { c0d02bde: 2901 cmp r1, #1 c0d02be0: d106 bne.n c0d02bf0 <u2f_message_set_autoreply_wait_user_presence+0x1c> // start replying placeholder until user presence validated if (service->waitAsynchronousResponse == U2F_WAIT_ASYNCH_IDLE) { c0d02be2: 2b00 cmp r3, #0 c0d02be4: d108 bne.n c0d02bf8 <u2f_message_set_autoreply_wait_user_presence+0x24> service->waitAsynchronousResponse = U2F_WAIT_ASYNCH_ON; c0d02be6: 2101 movs r1, #1 c0d02be8: 7011 strb r1, [r2, #0] u2f_transport_send_usb_user_presence_required(service); c0d02bea: f7ff fd39 bl c0d02660 <u2f_transport_send_usb_user_presence_required> } // don't set to REPLY_READY when it has not been enabled beforehand else if (service->waitAsynchronousResponse == U2F_WAIT_ASYNCH_ON) { service->waitAsynchronousResponse = U2F_WAIT_ASYNCH_REPLY_READY; } } c0d02bee: bd80 pop {r7, pc} service->waitAsynchronousResponse = U2F_WAIT_ASYNCH_ON; u2f_transport_send_usb_user_presence_required(service); } } // don't set to REPLY_READY when it has not been enabled beforehand else if (service->waitAsynchronousResponse == U2F_WAIT_ASYNCH_ON) { c0d02bf0: 2b01 cmp r3, #1 c0d02bf2: d101 bne.n c0d02bf8 <u2f_message_set_autoreply_wait_user_presence+0x24> service->waitAsynchronousResponse = U2F_WAIT_ASYNCH_REPLY_READY; c0d02bf4: 2002 movs r0, #2 c0d02bf6: 7010 strb r0, [r2, #0] } } c0d02bf8: bd80 pop {r7, pc} c0d02bfa <u2f_message_repliable>: bool u2f_message_repliable(u2f_service_t* service) { c0d02bfa: 4601 mov r1, r0 // no more asynch replies // finished receiving the command // and not sending a user presence required status return service->waitAsynchronousResponse == U2F_WAIT_ASYNCH_IDLE c0d02bfc: 202a movs r0, #42 ; 0x2a c0d02bfe: 5c0a ldrb r2, [r1, r0] c0d02c00: 2001 movs r0, #1 || (service->waitAsynchronousResponse != U2F_WAIT_ASYNCH_ON c0d02c02: 2a00 cmp r2, #0 c0d02c04: d010 beq.n c0d02c28 <u2f_message_repliable+0x2e> c0d02c06: 2a01 cmp r2, #1 c0d02c08: d101 bne.n c0d02c0e <u2f_message_repliable+0x14> c0d02c0a: 2000 movs r0, #0 bool u2f_message_repliable(u2f_service_t* service) { // no more asynch replies // finished receiving the command // and not sending a user presence required status return service->waitAsynchronousResponse == U2F_WAIT_ASYNCH_IDLE c0d02c0c: 4770 bx lr || (service->waitAsynchronousResponse != U2F_WAIT_ASYNCH_ON && service->fakeChannelTransportState == U2F_FAKE_RECEIVED c0d02c0e: 2025 movs r0, #37 ; 0x25 c0d02c10: 5c0a ldrb r2, [r1, r0] c0d02c12: 2000 movs r0, #0 && service->sending == false) c0d02c14: 2a06 cmp r2, #6 c0d02c16: d107 bne.n c0d02c28 <u2f_message_repliable+0x2e> c0d02c18: 202b movs r0, #43 ; 0x2b c0d02c1a: 5c0a ldrb r2, [r1, r0] c0d02c1c: 2001 movs r0, #1 c0d02c1e: 2100 movs r1, #0 c0d02c20: 2a00 cmp r2, #0 c0d02c22: d001 beq.n c0d02c28 <u2f_message_repliable+0x2e> c0d02c24: 4608 mov r0, r1 bool u2f_message_repliable(u2f_service_t* service) { // no more asynch replies // finished receiving the command // and not sending a user presence required status return service->waitAsynchronousResponse == U2F_WAIT_ASYNCH_IDLE c0d02c26: 4770 bx lr c0d02c28: 4770 bx lr c0d02c2a <u2f_message_reply>: && service->fakeChannelTransportState == U2F_FAKE_RECEIVED && service->sending == false) ; } void u2f_message_reply(u2f_service_t *service, uint8_t cmd, uint8_t *buffer, uint16_t len) { c0d02c2a: b5b0 push {r4, r5, r7, lr} bool u2f_message_repliable(u2f_service_t* service) { // no more asynch replies // finished receiving the command // and not sending a user presence required status return service->waitAsynchronousResponse == U2F_WAIT_ASYNCH_IDLE c0d02c2c: 242a movs r4, #42 ; 0x2a c0d02c2e: 5d04 ldrb r4, [r0, r4] || (service->waitAsynchronousResponse != U2F_WAIT_ASYNCH_ON c0d02c30: 2c00 cmp r4, #0 c0d02c32: d009 beq.n c0d02c48 <u2f_message_reply+0x1e> c0d02c34: 2c01 cmp r4, #1 c0d02c36: d015 beq.n c0d02c64 <u2f_message_reply+0x3a> && service->fakeChannelTransportState == U2F_FAKE_RECEIVED c0d02c38: 2425 movs r4, #37 ; 0x25 c0d02c3a: 5d04 ldrb r4, [r0, r4] && service->sending == false) c0d02c3c: 2c06 cmp r4, #6 c0d02c3e: d111 bne.n c0d02c64 <u2f_message_reply+0x3a> c0d02c40: 242b movs r4, #43 ; 0x2b c0d02c42: 5d04 ldrb r4, [r0, r4] } void u2f_message_reply(u2f_service_t *service, uint8_t cmd, uint8_t *buffer, uint16_t len) { // if U2F is not ready to reply, then gently avoid replying if (u2f_message_repliable(service)) c0d02c44: 2c00 cmp r4, #0 c0d02c46: d10d bne.n c0d02c64 <u2f_message_reply+0x3a> { service->transportState = U2F_SENDING_RESPONSE; c0d02c48: 2420 movs r4, #32 c0d02c4a: 2503 movs r5, #3 c0d02c4c: 5505 strb r5, [r0, r4] c0d02c4e: 2400 movs r4, #0 service->transportPacketIndex = 0; c0d02c50: 7684 strb r4, [r0, #26] service->transportBuffer = buffer; c0d02c52: 61c2 str r2, [r0, #28] service->transportOffset = 0; c0d02c54: 82c4 strh r4, [r0, #22] service->transportLength = len; c0d02c56: 8303 strh r3, [r0, #24] service->sendCmd = cmd; c0d02c58: 2240 movs r2, #64 ; 0x40 c0d02c5a: 5481 strb r1, [r0, r2] // pump the first message u2f_transport_sent(service, service->transportMedia); c0d02c5c: 2121 movs r1, #33 ; 0x21 c0d02c5e: 5c41 ldrb r1, [r0, r1] c0d02c60: f7ff fc88 bl c0d02574 <u2f_transport_sent> } } c0d02c64: bdb0 pop {r4, r5, r7, pc} ... c0d02c68 <ui_idle>: return 0; } /** show the idle screen. */ void ui_idle(void) { c0d02c68: b5b0 push {r4, r5, r7, lr} uiState = UI_IDLE; c0d02c6a: 4823 ldr r0, [pc, #140] ; (c0d02cf8 <ui_idle+0x90>) c0d02c6c: 2101 movs r1, #1 c0d02c6e: 7001 strb r1, [r0, #0] #if defined(TARGET_BLUE) UX_DISPLAY(bagl_ui_idle_blue, NULL); #elif defined(TARGET_NANOS) UX_DISPLAY(bagl_ui_idle_nanos, NULL); c0d02c70: 4c22 ldr r4, [pc, #136] ; (c0d02cfc <ui_idle+0x94>) c0d02c72: 4824 ldr r0, [pc, #144] ; (c0d02d04 <ui_idle+0x9c>) c0d02c74: 4478 add r0, pc c0d02c76: 6020 str r0, [r4, #0] c0d02c78: 2004 movs r0, #4 c0d02c7a: 6060 str r0, [r4, #4] c0d02c7c: 4822 ldr r0, [pc, #136] ; (c0d02d08 <ui_idle+0xa0>) c0d02c7e: 4478 add r0, pc c0d02c80: 6120 str r0, [r4, #16] c0d02c82: 2500 movs r5, #0 c0d02c84: 60e5 str r5, [r4, #12] c0d02c86: 2003 movs r0, #3 c0d02c88: 7620 strb r0, [r4, #24] c0d02c8a: 61e5 str r5, [r4, #28] c0d02c8c: 4620 mov r0, r4 c0d02c8e: 3018 adds r0, #24 c0d02c90: f7ff fa5c bl c0d0214c <os_ux> c0d02c94: 61e0 str r0, [r4, #28] c0d02c96: f7fe fd52 bl c0d0173e <ux_check_status_default> c0d02c9a: f7fe fa1d bl c0d010d8 <io_seproxyhal_init_ux> c0d02c9e: f7fe fa21 bl c0d010e4 <io_seproxyhal_init_button> c0d02ca2: 60a5 str r5, [r4, #8] c0d02ca4: 6820 ldr r0, [r4, #0] c0d02ca6: 2800 cmp r0, #0 c0d02ca8: d024 beq.n c0d02cf4 <ui_idle+0x8c> c0d02caa: 69e0 ldr r0, [r4, #28] c0d02cac: 4914 ldr r1, [pc, #80] ; (c0d02d00 <ui_idle+0x98>) c0d02cae: 4288 cmp r0, r1 c0d02cb0: d11e bne.n c0d02cf0 <ui_idle+0x88> c0d02cb2: e01f b.n c0d02cf4 <ui_idle+0x8c> c0d02cb4: 6860 ldr r0, [r4, #4] c0d02cb6: 4285 cmp r5, r0 c0d02cb8: d21c bcs.n c0d02cf4 <ui_idle+0x8c> c0d02cba: f7ff faa1 bl c0d02200 <io_seproxyhal_spi_is_status_sent> c0d02cbe: 2800 cmp r0, #0 c0d02cc0: d118 bne.n c0d02cf4 <ui_idle+0x8c> c0d02cc2: 68a0 ldr r0, [r4, #8] c0d02cc4: 68e1 ldr r1, [r4, #12] c0d02cc6: 2538 movs r5, #56 ; 0x38 c0d02cc8: 4368 muls r0, r5 c0d02cca: 6822 ldr r2, [r4, #0] c0d02ccc: 1810 adds r0, r2, r0 c0d02cce: 2900 cmp r1, #0 c0d02cd0: d002 beq.n c0d02cd8 <ui_idle+0x70> c0d02cd2: 4788 blx r1 c0d02cd4: 2800 cmp r0, #0 c0d02cd6: d007 beq.n c0d02ce8 <ui_idle+0x80> c0d02cd8: 2801 cmp r0, #1 c0d02cda: d103 bne.n c0d02ce4 <ui_idle+0x7c> c0d02cdc: 68a0 ldr r0, [r4, #8] c0d02cde: 4345 muls r5, r0 c0d02ce0: 6820 ldr r0, [r4, #0] c0d02ce2: 1940 adds r0, r0, r5 c0d02ce4: f7fd fa18 bl c0d00118 <io_seproxyhal_display> c0d02ce8: 68a0 ldr r0, [r4, #8] c0d02cea: 1c45 adds r5, r0, #1 c0d02cec: 60a5 str r5, [r4, #8] c0d02cee: 6820 ldr r0, [r4, #0] c0d02cf0: 2800 cmp r0, #0 c0d02cf2: d1df bne.n c0d02cb4 <ui_idle+0x4c> if(G_ux.stack_count == 0) { ux_stack_push(); } ux_flow_init(0, ux_idle_flow, NULL); #endif // #if TARGET_ID } c0d02cf4: bdb0 pop {r4, r5, r7, pc} c0d02cf6: 46c0 nop ; (mov r8, r8) c0d02cf8: 20001b84 .word 0x20001b84 c0d02cfc: 20001b88 .word 0x20001b88 c0d02d00: b0105044 .word 0xb0105044 c0d02d04: 000018a4 .word 0x000018a4 c0d02d08: 0000020b .word 0x0000020b c0d02d0c <sign_touch_ok>: // Display back the original UX ui_idle(); return 0; // do not redraw the widget } unsigned int sign_touch_ok(const bagl_element_t *e) { c0d02d0c: b5f0 push {r4, r5, r6, r7, lr} c0d02d0e: b0d5 sub sp, #340 ; 0x154 c0d02d10: 2000 movs r0, #0 volatile unsigned int tx = 0; c0d02d12: 9054 str r0, [sp, #336] ; 0x150 c0d02d14: 4d48 ldr r5, [pc, #288] ; (c0d02e38 <sign_touch_ok+0x12c>) // 首先获取BIP44路径 unsigned char *bip44_in = G_io_apdu_buffer + APDU_HEADER_LENGTH; unsigned int bip44_path[BIP44_PATH_LEN]; uint8_t i; for (i = 0; i < BIP44_PATH_LEN; i++) { bip44_path[i] = (bip44_in[0] << 24) | (bip44_in[1] << 16) | (bip44_in[2] << 8) | (bip44_in[3]); c0d02d16: 0081 lsls r1, r0, #2 c0d02d18: 186a adds r2, r5, r1 c0d02d1a: 7953 ldrb r3, [r2, #5] c0d02d1c: 061b lsls r3, r3, #24 c0d02d1e: 7994 ldrb r4, [r2, #6] c0d02d20: 0424 lsls r4, r4, #16 c0d02d22: 431c orrs r4, r3 c0d02d24: 79d3 ldrb r3, [r2, #7] c0d02d26: 021b lsls r3, r3, #8 c0d02d28: 4323 orrs r3, r4 c0d02d2a: 7a12 ldrb r2, [r2, #8] c0d02d2c: 431a orrs r2, r3 c0d02d2e: ab4f add r3, sp, #316 ; 0x13c c0d02d30: 505a str r2, [r3, r1] // 首先获取BIP44路径 unsigned char *bip44_in = G_io_apdu_buffer + APDU_HEADER_LENGTH; unsigned int bip44_path[BIP44_PATH_LEN]; uint8_t i; for (i = 0; i < BIP44_PATH_LEN; i++) { c0d02d32: 1c40 adds r0, r0, #1 c0d02d34: 2805 cmp r0, #5 c0d02d36: d1ee bne.n c0d02d16 <sign_touch_ok+0xa> } // 获取待签名的hash值 unsigned char hash[32]; unsigned char* hash_ptr = G_io_apdu_buffer + APDU_HEADER_LENGTH + BIP44_PATH_LEN*4; for (i = 0; i < sizeof(hash); i++){ hash[i] = *(hash_ptr + i); c0d02d38: 4629 mov r1, r5 c0d02d3a: 3119 adds r1, #25 c0d02d3c: a847 add r0, sp, #284 ; 0x11c c0d02d3e: 9005 str r0, [sp, #20] c0d02d40: 2220 movs r2, #32 c0d02d42: 9207 str r2, [sp, #28] c0d02d44: f001 fa32 bl c0d041ac <__aeabi_memcpy> c0d02d48: 2700 movs r7, #0 } cx_ecfp_private_key_t privateKey; unsigned char privateKeyData[32]; os_perso_derive_node_bip32(CX_CURVE_256K1, bip44_path, BIP44_PATH_LEN, privateKeyData, NULL); c0d02d4a: 4668 mov r0, sp c0d02d4c: 6007 str r7, [r0, #0] c0d02d4e: 2621 movs r6, #33 ; 0x21 c0d02d50: 9604 str r6, [sp, #16] c0d02d52: a94f add r1, sp, #316 ; 0x13c c0d02d54: 2205 movs r2, #5 c0d02d56: ac35 add r4, sp, #212 ; 0xd4 c0d02d58: 4630 mov r0, r6 c0d02d5a: 4623 mov r3, r4 c0d02d5c: f7ff f9c8 bl c0d020f0 <os_perso_derive_node_bip32> c0d02d60: ab3d add r3, sp, #244 ; 0xf4 cx_ecdsa_init_private_key(CX_CURVE_256K1, privateKeyData, 32, &privateKey); c0d02d62: 9306 str r3, [sp, #24] c0d02d64: 4630 mov r0, r6 c0d02d66: 4621 mov r1, r4 c0d02d68: 9e07 ldr r6, [sp, #28] c0d02d6a: 4632 mov r2, r6 c0d02d6c: f7ff f958 bl c0d02020 <cx_ecfp_init_private_key> os_memset(privateKeyData, 0, sizeof(privateKeyData)); c0d02d70: 4620 mov r0, r4 c0d02d72: 4639 mov r1, r7 c0d02d74: 4632 mov r2, r6 c0d02d76: f7fd ff95 bl c0d00ca4 <os_memset> c0d02d7a: ac22 add r4, sp, #136 ; 0x88 c0d02d7c: 9e04 ldr r6, [sp, #16] // generate the public key. cx_ecfp_public_key_t publicKey; cx_ecdsa_init_public_key(CX_CURVE_256K1, NULL, 0, &publicKey); c0d02d7e: 4630 mov r0, r6 c0d02d80: 4639 mov r1, r7 c0d02d82: 463a mov r2, r7 c0d02d84: 4623 mov r3, r4 c0d02d86: f7ff f933 bl c0d01ff0 <cx_ecfp_init_public_key> c0d02d8a: 2301 movs r3, #1 cx_ecfp_generate_pair(CX_CURVE_256K1, &publicKey, &privateKey, 1); c0d02d8c: 4630 mov r0, r6 c0d02d8e: 4621 mov r1, r4 c0d02d90: 9a06 ldr r2, [sp, #24] c0d02d92: f7ff f95d bl c0d02050 <cx_ecfp_generate_pair> // 进行签名 uint8_t signature[100]; unsigned int info = 0; c0d02d96: 9708 str r7, [sp, #32] c0d02d98: ae09 add r6, sp, #36 ; 0x24 os_memset(signature, 0, sizeof(signature)); c0d02d9a: 2464 movs r4, #100 ; 0x64 c0d02d9c: 4630 mov r0, r6 c0d02d9e: 4639 mov r1, r7 c0d02da0: 4622 mov r2, r4 c0d02da2: f7fd ff7f bl c0d00ca4 <os_memset> c0d02da6: a808 add r0, sp, #32 uint8_t signatureLength; signatureLength = cx_ecdsa_sign(&privateKey, CX_RND_RFC6979 | CX_LAST, CX_SHA256, c0d02da8: 4669 mov r1, sp c0d02daa: 9a07 ldr r2, [sp, #28] c0d02dac: c144 stmia r1!, {r2, r6} c0d02dae: 600c str r4, [r1, #0] c0d02db0: 6048 str r0, [r1, #4] c0d02db2: 4922 ldr r1, [pc, #136] ; (c0d02e3c <sign_touch_ok+0x130>) c0d02db4: 2203 movs r2, #3 c0d02db6: 9204 str r2, [sp, #16] c0d02db8: 9c06 ldr r4, [sp, #24] c0d02dba: 4620 mov r0, r4 c0d02dbc: 9b05 ldr r3, [sp, #20] c0d02dbe: f7ff f95f bl c0d02080 <cx_ecdsa_sign> c0d02dc2: 9005 str r0, [sp, #20] hash, sizeof(hash), signature, sizeof(signature), &info); os_memset(&privateKey, 0, sizeof(privateKey)); c0d02dc4: 2228 movs r2, #40 ; 0x28 c0d02dc6: 4620 mov r0, r4 c0d02dc8: 9706 str r7, [sp, #24] c0d02dca: 4639 mov r1, r7 c0d02dcc: f7fd ff6a bl c0d00ca4 <os_memset> G_io_apdu_buffer[0] = 27; if (info & CX_ECCINFO_PARITY_ODD) { c0d02dd0: 9808 ldr r0, [sp, #32] c0d02dd2: 9904 ldr r1, [sp, #16] c0d02dd4: 4008 ands r0, r1 G_io_apdu_buffer[0]++; } if (info & CX_ECCINFO_xGTn) { c0d02dd6: 301b adds r0, #27 hash, sizeof(hash), signature, sizeof(signature), &info); os_memset(&privateKey, 0, sizeof(privateKey)); G_io_apdu_buffer[0] = 27; if (info & CX_ECCINFO_PARITY_ODD) { G_io_apdu_buffer[0]++; c0d02dd8: 7028 strb r0, [r5, #0] } uint8_t rLength = signature[3]; uint8_t sLength = signature[4 + rLength + 1]; uint8_t rOffset = (rLength == 33 ? 1 : 0); uint8_t sOffset = (sLength == 33 ? 1 : 0); os_memmove(G_io_apdu_buffer + 1, signature + 4 + rOffset, 32); c0d02dda: 1d71 adds r1, r6, #5 c0d02ddc: 1d34 adds r4, r6, #4 G_io_apdu_buffer[0]++; } if (info & CX_ECCINFO_xGTn) { G_io_apdu_buffer[0] += 2; } uint8_t rLength = signature[3]; c0d02dde: 78f7 ldrb r7, [r6, #3] uint8_t sLength = signature[4 + rLength + 1]; uint8_t rOffset = (rLength == 33 ? 1 : 0); uint8_t sOffset = (sLength == 33 ? 1 : 0); os_memmove(G_io_apdu_buffer + 1, signature + 4 + rOffset, 32); c0d02de0: 2f21 cmp r7, #33 ; 0x21 c0d02de2: d000 beq.n c0d02de6 <sign_touch_ok+0xda> c0d02de4: 4621 mov r1, r4 c0d02de6: 19f0 adds r0, r6, r7 } if (info & CX_ECCINFO_xGTn) { G_io_apdu_buffer[0] += 2; } uint8_t rLength = signature[3]; uint8_t sLength = signature[4 + rLength + 1]; c0d02de8: 7946 ldrb r6, [r0, #5] uint8_t rOffset = (rLength == 33 ? 1 : 0); uint8_t sOffset = (sLength == 33 ? 1 : 0); os_memmove(G_io_apdu_buffer + 1, signature + 4 + rOffset, 32); c0d02dea: 1c68 adds r0, r5, #1 c0d02dec: 9a07 ldr r2, [sp, #28] c0d02dee: f7fd ff62 bl c0d00cb6 <os_memmove> os_memmove(G_io_apdu_buffer + 1 + 32, signature + 4 + rLength + 2 + sOffset, 32); c0d02df2: 19e1 adds r1, r4, r7 c0d02df4: 1c48 adds r0, r1, #1 c0d02df6: 2e21 cmp r6, #33 ; 0x21 c0d02df8: d000 beq.n c0d02dfc <sign_touch_ok+0xf0> c0d02dfa: 4608 mov r0, r1 c0d02dfc: 1c81 adds r1, r0, #2 c0d02dfe: 4628 mov r0, r5 c0d02e00: 3021 adds r0, #33 ; 0x21 c0d02e02: 9c07 ldr r4, [sp, #28] c0d02e04: 4622 mov r2, r4 c0d02e06: f7fd ff56 bl c0d00cb6 <os_memmove> // os_memmove(G_io_apdu_buffer+1+32+32, publicKey.W, 65); // os_memmove(G_io_apdu_buffer+1+32+32+65, hash, 32); tx = signatureLength; c0d02e0a: 9805 ldr r0, [sp, #20] c0d02e0c: b2c0 uxtb r0, r0 c0d02e0e: 9054 str r0, [sp, #336] ; 0x150 G_io_apdu_buffer[tx++] = 0x90; c0d02e10: 9854 ldr r0, [sp, #336] ; 0x150 c0d02e12: 1c41 adds r1, r0, #1 c0d02e14: 9154 str r1, [sp, #336] ; 0x150 c0d02e16: 2190 movs r1, #144 ; 0x90 c0d02e18: 5429 strb r1, [r5, r0] G_io_apdu_buffer[tx++] = 0x00; c0d02e1a: 9854 ldr r0, [sp, #336] ; 0x150 c0d02e1c: 1c41 adds r1, r0, #1 c0d02e1e: 9154 str r1, [sp, #336] ; 0x150 c0d02e20: 9e06 ldr r6, [sp, #24] c0d02e22: 542e strb r6, [r5, r0] // Send back the response, do not restart the event loop io_exchange(CHANNEL_APDU | IO_RETURN_AFTER_TX, tx); c0d02e24: 9854 ldr r0, [sp, #336] ; 0x150 c0d02e26: b281 uxth r1, r0 c0d02e28: 4620 mov r0, r4 c0d02e2a: f7fe fb49 bl c0d014c0 <io_exchange> // Display back the original UX ui_idle(); c0d02e2e: f7ff ff1b bl c0d02c68 <ui_idle> return 0; // do not redraw the widget c0d02e32: 4630 mov r0, r6 c0d02e34: b055 add sp, #340 ; 0x154 c0d02e36: bdf0 pop {r4, r5, r6, r7, pc} c0d02e38: 200018f8 .word 0x200018f8 c0d02e3c: 00000601 .word 0x00000601 c0d02e40 <update_sign_hash>: } void update_sign_hash() { c0d02e40: b570 push {r4, r5, r6, lr} c0d02e42: b088 sub sp, #32 // 获取待签名的hash值 unsigned char hash[32]; unsigned char* hash_ptr = G_io_apdu_buffer + APDU_HEADER_LENGTH + BIP44_PATH_LEN*4; for (uint8_t i = 0; i < sizeof(hash); i++){ hash[i] = *(hash_ptr + i); c0d02e44: 490f ldr r1, [pc, #60] ; (c0d02e84 <update_sign_hash+0x44>) c0d02e46: 3119 adds r1, #25 c0d02e48: 466c mov r4, sp c0d02e4a: 2220 movs r2, #32 c0d02e4c: 4620 mov r0, r4 c0d02e4e: f001 f9ad bl c0d041ac <__aeabi_memcpy> } os_memset(sign_hash, 0, sizeof(sign_hash)); c0d02e52: 4d0d ldr r5, [pc, #52] ; (c0d02e88 <update_sign_hash+0x48>) c0d02e54: 2100 movs r1, #0 c0d02e56: 220c movs r2, #12 c0d02e58: 4628 mov r0, r5 c0d02e5a: f7fd ff23 bl c0d00ca4 <os_memset> hex_to_str(hash, sign_hash, 2); c0d02e5e: 2602 movs r6, #2 c0d02e60: 4620 mov r0, r4 c0d02e62: 4629 mov r1, r5 c0d02e64: 4632 mov r2, r6 c0d02e66: f001 f8ed bl c0d04044 <hex_to_str> sign_hash[4] = '*'; c0d02e6a: 202a movs r0, #42 ; 0x2a c0d02e6c: 7128 strb r0, [r5, #4] sign_hash[5] = '*'; c0d02e6e: 7168 strb r0, [r5, #5] sign_hash[6] = '*'; c0d02e70: 71a8 strb r0, [r5, #6] hex_to_str(hash+30, sign_hash+7, 2); c0d02e72: 341e adds r4, #30 c0d02e74: 1de9 adds r1, r5, #7 c0d02e76: 4620 mov r0, r4 c0d02e78: 4632 mov r2, r6 c0d02e7a: f001 f8e3 bl c0d04044 <hex_to_str> } c0d02e7e: b008 add sp, #32 c0d02e80: bd70 pop {r4, r5, r6, pc} c0d02e82: 46c0 nop ; (mov r8, r8) c0d02e84: 200018f8 .word 0x200018f8 c0d02e88: 20001b00 .word 0x20001b00 c0d02e8c <bagl_ui_idle_nanos_button>: /** * buttons for the idle screen * * exit on Left button, or on Both buttons. Do nothing on Right button only. */ static unsigned int bagl_ui_idle_nanos_button(unsigned int button_mask, unsigned int button_mask_counter) { c0d02e8c: b580 push {r7, lr} switch (button_mask) { c0d02e8e: 4904 ldr r1, [pc, #16] ; (c0d02ea0 <bagl_ui_idle_nanos_button+0x14>) c0d02e90: 4288 cmp r0, r1 c0d02e92: d102 bne.n c0d02e9a <bagl_ui_idle_nanos_button+0xe> /** if the user wants to exit go back to the app dashboard. */ static const bagl_element_t *io_seproxyhal_touch_exit(const bagl_element_t *e) { // Go back to the dashboard os_sched_exit(0); c0d02e94: 2000 movs r0, #0 c0d02e96: f7ff f943 bl c0d02120 <os_sched_exit> case BUTTON_EVT_RELEASED | BUTTON_LEFT: io_seproxyhal_touch_exit(NULL); break; } return 0; c0d02e9a: 2000 movs r0, #0 c0d02e9c: bd80 pop {r7, pc} c0d02e9e: 46c0 nop ; (mov r8, r8) c0d02ea0: 80000001 .word 0x80000001 c0d02ea4 <ui_test>: ux_flow_init(0, ux_idle_flow, NULL); #endif // #if TARGET_ID } /**ui 显示. */ void ui_test(void) { c0d02ea4: b5b0 push {r4, r5, r7, lr} #if defined(TARGET_BLUE) UX_DISPLAY(bagl_ui_top_sign_blue, NULL); #elif defined(TARGET_NANOS) UX_DISPLAY(bagl_ui_test_nanos, NULL); c0d02ea6: 4c21 ldr r4, [pc, #132] ; (c0d02f2c <ui_test+0x88>) c0d02ea8: 4822 ldr r0, [pc, #136] ; (c0d02f34 <ui_test+0x90>) c0d02eaa: 4478 add r0, pc c0d02eac: 6020 str r0, [r4, #0] c0d02eae: 2004 movs r0, #4 c0d02eb0: 6060 str r0, [r4, #4] c0d02eb2: 4821 ldr r0, [pc, #132] ; (c0d02f38 <ui_test+0x94>) c0d02eb4: 4478 add r0, pc c0d02eb6: 6120 str r0, [r4, #16] c0d02eb8: 2500 movs r5, #0 c0d02eba: 60e5 str r5, [r4, #12] c0d02ebc: 2003 movs r0, #3 c0d02ebe: 7620 strb r0, [r4, #24] c0d02ec0: 61e5 str r5, [r4, #28] c0d02ec2: 4620 mov r0, r4 c0d02ec4: 3018 adds r0, #24 c0d02ec6: f7ff f941 bl c0d0214c <os_ux> c0d02eca: 61e0 str r0, [r4, #28] c0d02ecc: f7fe fc37 bl c0d0173e <ux_check_status_default> c0d02ed0: f7fe f902 bl c0d010d8 <io_seproxyhal_init_ux> c0d02ed4: f7fe f906 bl c0d010e4 <io_seproxyhal_init_button> c0d02ed8: 60a5 str r5, [r4, #8] c0d02eda: 6820 ldr r0, [r4, #0] c0d02edc: 2800 cmp r0, #0 c0d02ede: d024 beq.n c0d02f2a <ui_test+0x86> c0d02ee0: 69e0 ldr r0, [r4, #28] c0d02ee2: 4913 ldr r1, [pc, #76] ; (c0d02f30 <ui_test+0x8c>) c0d02ee4: 4288 cmp r0, r1 c0d02ee6: d11e bne.n c0d02f26 <ui_test+0x82> c0d02ee8: e01f b.n c0d02f2a <ui_test+0x86> c0d02eea: 6860 ldr r0, [r4, #4] c0d02eec: 4285 cmp r5, r0 c0d02eee: d21c bcs.n c0d02f2a <ui_test+0x86> c0d02ef0: f7ff f986 bl c0d02200 <io_seproxyhal_spi_is_status_sent> c0d02ef4: 2800 cmp r0, #0 c0d02ef6: d118 bne.n c0d02f2a <ui_test+0x86> c0d02ef8: 68a0 ldr r0, [r4, #8] c0d02efa: 68e1 ldr r1, [r4, #12] c0d02efc: 2538 movs r5, #56 ; 0x38 c0d02efe: 4368 muls r0, r5 c0d02f00: 6822 ldr r2, [r4, #0] c0d02f02: 1810 adds r0, r2, r0 c0d02f04: 2900 cmp r1, #0 c0d02f06: d002 beq.n c0d02f0e <ui_test+0x6a> c0d02f08: 4788 blx r1 c0d02f0a: 2800 cmp r0, #0 c0d02f0c: d007 beq.n c0d02f1e <ui_test+0x7a> c0d02f0e: 2801 cmp r0, #1 c0d02f10: d103 bne.n c0d02f1a <ui_test+0x76> c0d02f12: 68a0 ldr r0, [r4, #8] c0d02f14: 4345 muls r5, r0 c0d02f16: 6820 ldr r0, [r4, #0] c0d02f18: 1940 adds r0, r0, r5 c0d02f1a: f7fd f8fd bl c0d00118 <io_seproxyhal_display> c0d02f1e: 68a0 ldr r0, [r4, #8] c0d02f20: 1c45 adds r5, r0, #1 c0d02f22: 60a5 str r5, [r4, #8] c0d02f24: 6820 ldr r0, [r4, #0] c0d02f26: 2800 cmp r0, #0 c0d02f28: d1df bne.n c0d02eea <ui_test+0x46> if(G_ux.stack_count == 0) { ux_stack_push(); } ux_flow_init(0, ux_confirm_single_flow, NULL); #endif // #if TARGET_ID } c0d02f2a: bdb0 pop {r4, r5, r7, pc} c0d02f2c: 20001b88 .word 0x20001b88 c0d02f30: b0105044 .word 0xb0105044 c0d02f34: 0000158e .word 0x0000158e c0d02f38: 00000085 .word 0x00000085 c0d02f3c <bagl_ui_test_nanos_button>: ui_idle(); return 0; // do not redraw the widget } static unsigned int bagl_ui_test_nanos_button(unsigned int button_mask, unsigned int button_mask_counter) { c0d02f3c: b580 push {r7, lr} switch (button_mask) { c0d02f3e: 4910 ldr r1, [pc, #64] ; (c0d02f80 <bagl_ui_test_nanos_button+0x44>) c0d02f40: 4288 cmp r0, r1 c0d02f42: d010 beq.n c0d02f66 <bagl_ui_test_nanos_button+0x2a> c0d02f44: 490f ldr r1, [pc, #60] ; (c0d02f84 <bagl_ui_test_nanos_button+0x48>) c0d02f46: 4288 cmp r0, r1 c0d02f48: d118 bne.n c0d02f7c <bagl_ui_test_nanos_button+0x40> ui_idle(); return 0; // do not redraw the widget } unsigned int test_touch_ok(const bagl_element_t *e) { G_io_apdu_buffer[0] = 0x69; c0d02f4a: 480f ldr r0, [pc, #60] ; (c0d02f88 <bagl_ui_test_nanos_button+0x4c>) c0d02f4c: 2169 movs r1, #105 ; 0x69 c0d02f4e: 7001 strb r1, [r0, #0] G_io_apdu_buffer[1] = 0x98; c0d02f50: 216f movs r1, #111 ; 0x6f c0d02f52: 43c9 mvns r1, r1 c0d02f54: 3108 adds r1, #8 c0d02f56: 7041 strb r1, [r0, #1] c0d02f58: 2190 movs r1, #144 ; 0x90 G_io_apdu_buffer[2] = 0x90; c0d02f5a: 7081 strb r1, [r0, #2] G_io_apdu_buffer[3] = 0x00; c0d02f5c: 2100 movs r1, #0 c0d02f5e: 70c1 strb r1, [r0, #3] // Send back the response, do not restart the event loop io_exchange(CHANNEL_APDU | IO_RETURN_AFTER_TX, 4); c0d02f60: 2020 movs r0, #32 c0d02f62: 2104 movs r1, #4 c0d02f64: e006 b.n c0d02f74 <bagl_ui_test_nanos_button+0x38> //{{BAGL_ICON , 0x01, 31, 9, 14, 14, 0, 0, 0 , 0xFFFFFF, 0x000000, 0, BAGL_GLYPH_ICON_EYE_BADGE }, NULL, 0, 0, 0, NULL, NULL, NULL }, {{BAGL_LABELINE , 0x01, 0, 12, 128, 12, 0, 0, 0 , 0xFFFFFF, 0x000000, BAGL_FONT_OPEN_SANS_EXTRABOLD_11px|BAGL_FONT_ALIGNMENT_CENTER, 0 }, "Are you sure?", 0, 0, 0, NULL, NULL, NULL }, }; unsigned int test_touch_cancle(const bagl_element_t *e) { G_io_apdu_buffer[0] = 0x69; c0d02f66: 4808 ldr r0, [pc, #32] ; (c0d02f88 <bagl_ui_test_nanos_button+0x4c>) c0d02f68: 2169 movs r1, #105 ; 0x69 c0d02f6a: 7001 strb r1, [r0, #0] G_io_apdu_buffer[1] = 0x01; c0d02f6c: 2101 movs r1, #1 c0d02f6e: 7041 strb r1, [r0, #1] // Send back the response, do not restart the event loop io_exchange(CHANNEL_APDU | IO_RETURN_AFTER_TX, 2); c0d02f70: 2020 movs r0, #32 c0d02f72: 2102 movs r1, #2 c0d02f74: f7fe faa4 bl c0d014c0 <io_exchange> c0d02f78: f7ff fe76 bl c0d02c68 <ui_idle> case BUTTON_EVT_RELEASED | BUTTON_LEFT: test_touch_cancle(NULL); break; } return 0; c0d02f7c: 2000 movs r0, #0 c0d02f7e: bd80 pop {r7, pc} c0d02f80: 80000001 .word 0x80000001 c0d02f84: 80000002 .word 0x80000002 c0d02f88: 200018f8 .word 0x200018f8 c0d02f8c <ui_confirm_sign>: ux_flow_init(0, ux_confirm_single_flow, NULL); #endif // #if TARGET_ID } /**ui 显示. */ void ui_confirm_sign(void) { c0d02f8c: b5b0 push {r4, r5, r7, lr} #if defined(TARGET_BLUE) UX_DISPLAY(bagl_ui_top_sign_blue, NULL); #elif defined(TARGET_NANOS) UX_DISPLAY(bagl_ui_sign_hash_nanos, NULL); c0d02f8e: 4c21 ldr r4, [pc, #132] ; (c0d03014 <ui_confirm_sign+0x88>) c0d02f90: 4822 ldr r0, [pc, #136] ; (c0d0301c <ui_confirm_sign+0x90>) c0d02f92: 4478 add r0, pc c0d02f94: 6020 str r0, [r4, #0] c0d02f96: 2005 movs r0, #5 c0d02f98: 6060 str r0, [r4, #4] c0d02f9a: 4821 ldr r0, [pc, #132] ; (c0d03020 <ui_confirm_sign+0x94>) c0d02f9c: 4478 add r0, pc c0d02f9e: 6120 str r0, [r4, #16] c0d02fa0: 2500 movs r5, #0 c0d02fa2: 60e5 str r5, [r4, #12] c0d02fa4: 2003 movs r0, #3 c0d02fa6: 7620 strb r0, [r4, #24] c0d02fa8: 61e5 str r5, [r4, #28] c0d02faa: 4620 mov r0, r4 c0d02fac: 3018 adds r0, #24 c0d02fae: f7ff f8cd bl c0d0214c <os_ux> c0d02fb2: 61e0 str r0, [r4, #28] c0d02fb4: f7fe fbc3 bl c0d0173e <ux_check_status_default> c0d02fb8: f7fe f88e bl c0d010d8 <io_seproxyhal_init_ux> c0d02fbc: f7fe f892 bl c0d010e4 <io_seproxyhal_init_button> c0d02fc0: 60a5 str r5, [r4, #8] c0d02fc2: 6820 ldr r0, [r4, #0] c0d02fc4: 2800 cmp r0, #0 c0d02fc6: d024 beq.n c0d03012 <ui_confirm_sign+0x86> c0d02fc8: 69e0 ldr r0, [r4, #28] c0d02fca: 4913 ldr r1, [pc, #76] ; (c0d03018 <ui_confirm_sign+0x8c>) c0d02fcc: 4288 cmp r0, r1 c0d02fce: d11e bne.n c0d0300e <ui_confirm_sign+0x82> c0d02fd0: e01f b.n c0d03012 <ui_confirm_sign+0x86> c0d02fd2: 6860 ldr r0, [r4, #4] c0d02fd4: 4285 cmp r5, r0 c0d02fd6: d21c bcs.n c0d03012 <ui_confirm_sign+0x86> c0d02fd8: f7ff f912 bl c0d02200 <io_seproxyhal_spi_is_status_sent> c0d02fdc: 2800 cmp r0, #0 c0d02fde: d118 bne.n c0d03012 <ui_confirm_sign+0x86> c0d02fe0: 68a0 ldr r0, [r4, #8] c0d02fe2: 68e1 ldr r1, [r4, #12] c0d02fe4: 2538 movs r5, #56 ; 0x38 c0d02fe6: 4368 muls r0, r5 c0d02fe8: 6822 ldr r2, [r4, #0] c0d02fea: 1810 adds r0, r2, r0 c0d02fec: 2900 cmp r1, #0 c0d02fee: d002 beq.n c0d02ff6 <ui_confirm_sign+0x6a> c0d02ff0: 4788 blx r1 c0d02ff2: 2800 cmp r0, #0 c0d02ff4: d007 beq.n c0d03006 <ui_confirm_sign+0x7a> c0d02ff6: 2801 cmp r0, #1 c0d02ff8: d103 bne.n c0d03002 <ui_confirm_sign+0x76> c0d02ffa: 68a0 ldr r0, [r4, #8] c0d02ffc: 4345 muls r5, r0 c0d02ffe: 6820 ldr r0, [r4, #0] c0d03000: 1940 adds r0, r0, r5 c0d03002: f7fd f889 bl c0d00118 <io_seproxyhal_display> c0d03006: 68a0 ldr r0, [r4, #8] c0d03008: 1c45 adds r5, r0, #1 c0d0300a: 60a5 str r5, [r4, #8] c0d0300c: 6820 ldr r0, [r4, #0] c0d0300e: 2800 cmp r0, #0 c0d03010: d1df bne.n c0d02fd2 <ui_confirm_sign+0x46> if(G_ux.stack_count == 0) { ux_stack_push(); } ux_flow_init(0, ux_confirm_single_flow, NULL); #endif // #if TARGET_ID } c0d03012: bdb0 pop {r4, r5, r7, pc} c0d03014: 20001b88 .word 0x20001b88 c0d03018: b0105044 .word 0xb0105044 c0d0301c: 00001666 .word 0x00001666 c0d03020: 00000085 .word 0x00000085 c0d03024 <bagl_ui_sign_hash_nanos_button>: sign_hash[5] = '*'; sign_hash[6] = '*'; hex_to_str(hash+30, sign_hash+7, 2); } static unsigned int bagl_ui_sign_hash_nanos_button(unsigned int button_mask, unsigned int button_mask_counter) { c0d03024: b580 push {r7, lr} switch (button_mask) { c0d03026: 490b ldr r1, [pc, #44] ; (c0d03054 <bagl_ui_sign_hash_nanos_button+0x30>) c0d03028: 4288 cmp r0, r1 c0d0302a: d005 beq.n c0d03038 <bagl_ui_sign_hash_nanos_button+0x14> c0d0302c: 490a ldr r1, [pc, #40] ; (c0d03058 <bagl_ui_sign_hash_nanos_button+0x34>) c0d0302e: 4288 cmp r0, r1 c0d03030: d10d bne.n c0d0304e <bagl_ui_sign_hash_nanos_button+0x2a> case BUTTON_EVT_RELEASED | BUTTON_RIGHT: sign_touch_ok(NULL); c0d03032: f7ff fe6b bl c0d02d0c <sign_touch_ok> c0d03036: e00a b.n c0d0304e <bagl_ui_sign_hash_nanos_button+0x2a> /* */ }; unsigned int sign_touch_cancle(const bagl_element_t *e) { G_io_apdu_buffer[0] = 0x69; c0d03038: 4808 ldr r0, [pc, #32] ; (c0d0305c <bagl_ui_sign_hash_nanos_button+0x38>) c0d0303a: 2169 movs r1, #105 ; 0x69 c0d0303c: 7001 strb r1, [r0, #0] G_io_apdu_buffer[1] = 0x01; c0d0303e: 2101 movs r1, #1 c0d03040: 7041 strb r1, [r0, #1] // Send back the response, do not restart the event loop io_exchange(CHANNEL_APDU | IO_RETURN_AFTER_TX, 2); c0d03042: 2020 movs r0, #32 c0d03044: 2102 movs r1, #2 c0d03046: f7fe fa3b bl c0d014c0 <io_exchange> // Display back the original UX ui_idle(); c0d0304a: f7ff fe0d bl c0d02c68 <ui_idle> case BUTTON_EVT_RELEASED | BUTTON_LEFT: sign_touch_cancle(NULL); break; } return 0; c0d0304e: 2000 movs r0, #0 c0d03050: bd80 pop {r7, pc} c0d03052: 46c0 nop ; (mov r8, r8) c0d03054: 80000001 .word 0x80000001 c0d03058: 80000002 .word 0x80000002 c0d0305c: 200018f8 .word 0x200018f8 c0d03060 <get_apdu_buffer_length>: #endif // #if TARGET_ID } /** returns the length of the transaction in the buffer. */ unsigned int get_apdu_buffer_length() { unsigned int len0 = G_io_apdu_buffer[APDU_BODY_LENGTH_OFFSET]; c0d03060: 4801 ldr r0, [pc, #4] ; (c0d03068 <get_apdu_buffer_length+0x8>) c0d03062: 7900 ldrb r0, [r0, #4] return len0; c0d03064: 4770 bx lr c0d03066: 46c0 nop ; (mov r8, r8) c0d03068: 200018f8 .word 0x200018f8 c0d0306c <ui_set_menu_bar_colour>: void ui_set_menu_bar_colour(void) { #if defined(TARGET_BLUE) UX_SET_STATUS_BAR_COLOR(COLOUR_WHITE, COLOUR_ONT_GREEN); clear_tx_desc(); #endif // #if TARGET_ID } c0d0306c: 4770 bx lr ... c0d03070 <USBD_LL_Init>: * @retval USBD Status */ USBD_StatusTypeDef USBD_LL_Init (USBD_HandleTypeDef *pdev) { UNUSED(pdev); ep_in_stall = 0; c0d03070: 4902 ldr r1, [pc, #8] ; (c0d0307c <USBD_LL_Init+0xc>) c0d03072: 2000 movs r0, #0 c0d03074: 6008 str r0, [r1, #0] ep_out_stall = 0; c0d03076: 4902 ldr r1, [pc, #8] ; (c0d03080 <USBD_LL_Init+0x10>) c0d03078: 6008 str r0, [r1, #0] return USBD_OK; c0d0307a: 4770 bx lr c0d0307c: 20001c84 .word 0x20001c84 c0d03080: 20001c88 .word 0x20001c88 c0d03084 <USBD_LL_DeInit>: * @brief De-Initializes the Low Level portion of the Device driver. * @param pdev: Device handle * @retval USBD Status */ USBD_StatusTypeDef USBD_LL_DeInit (USBD_HandleTypeDef *pdev) { c0d03084: b510 push {r4, lr} UNUSED(pdev); // usb off G_io_seproxyhal_spi_buffer[0] = SEPROXYHAL_TAG_USB_CONFIG; c0d03086: 4807 ldr r0, [pc, #28] ; (c0d030a4 <USBD_LL_DeInit+0x20>) c0d03088: 214f movs r1, #79 ; 0x4f c0d0308a: 7001 strb r1, [r0, #0] c0d0308c: 2400 movs r4, #0 G_io_seproxyhal_spi_buffer[1] = 0; c0d0308e: 7044 strb r4, [r0, #1] c0d03090: 2101 movs r1, #1 G_io_seproxyhal_spi_buffer[2] = 1; c0d03092: 7081 strb r1, [r0, #2] c0d03094: 2102 movs r1, #2 G_io_seproxyhal_spi_buffer[3] = SEPROXYHAL_TAG_USB_CONFIG_DISCONNECT; c0d03096: 70c1 strb r1, [r0, #3] io_seproxyhal_spi_send(G_io_seproxyhal_spi_buffer, 4); c0d03098: 2104 movs r1, #4 c0d0309a: f7ff f89b bl c0d021d4 <io_seproxyhal_spi_send> return USBD_OK; c0d0309e: 4620 mov r0, r4 c0d030a0: bd10 pop {r4, pc} c0d030a2: 46c0 nop ; (mov r8, r8) c0d030a4: 20001800 .word 0x20001800 c0d030a8 <USBD_LL_Start>: * @brief Starts the Low Level portion of the Device driver. * @param pdev: Device handle * @retval USBD Status */ USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev) { c0d030a8: b570 push {r4, r5, r6, lr} c0d030aa: b082 sub sp, #8 c0d030ac: 466d mov r5, sp uint8_t buffer[5]; UNUSED(pdev); // reset address buffer[0] = SEPROXYHAL_TAG_USB_CONFIG; c0d030ae: 264f movs r6, #79 ; 0x4f c0d030b0: 702e strb r6, [r5, #0] c0d030b2: 2400 movs r4, #0 buffer[1] = 0; c0d030b4: 706c strb r4, [r5, #1] c0d030b6: 2002 movs r0, #2 buffer[2] = 2; c0d030b8: 70a8 strb r0, [r5, #2] c0d030ba: 2003 movs r0, #3 buffer[3] = SEPROXYHAL_TAG_USB_CONFIG_ADDR; c0d030bc: 70e8 strb r0, [r5, #3] buffer[4] = 0; c0d030be: 712c strb r4, [r5, #4] io_seproxyhal_spi_send(buffer, 5); c0d030c0: 2105 movs r1, #5 c0d030c2: 4628 mov r0, r5 c0d030c4: f7ff f886 bl c0d021d4 <io_seproxyhal_spi_send> // start usb operation buffer[0] = SEPROXYHAL_TAG_USB_CONFIG; c0d030c8: 702e strb r6, [r5, #0] buffer[1] = 0; c0d030ca: 706c strb r4, [r5, #1] c0d030cc: 2001 movs r0, #1 buffer[2] = 1; c0d030ce: 70a8 strb r0, [r5, #2] buffer[3] = SEPROXYHAL_TAG_USB_CONFIG_CONNECT; c0d030d0: 70e8 strb r0, [r5, #3] c0d030d2: 2104 movs r1, #4 io_seproxyhal_spi_send(buffer, 4); c0d030d4: 4628 mov r0, r5 c0d030d6: f7ff f87d bl c0d021d4 <io_seproxyhal_spi_send> return USBD_OK; c0d030da: 4620 mov r0, r4 c0d030dc: b002 add sp, #8 c0d030de: bd70 pop {r4, r5, r6, pc} c0d030e0 <USBD_LL_Stop>: * @brief Stops the Low Level portion of the Device driver. * @param pdev: Device handle * @retval USBD Status */ USBD_StatusTypeDef USBD_LL_Stop (USBD_HandleTypeDef *pdev) { c0d030e0: b510 push {r4, lr} c0d030e2: b082 sub sp, #8 c0d030e4: a801 add r0, sp, #4 UNUSED(pdev); uint8_t buffer[4]; buffer[0] = SEPROXYHAL_TAG_USB_CONFIG; c0d030e6: 214f movs r1, #79 ; 0x4f c0d030e8: 7001 strb r1, [r0, #0] c0d030ea: 2400 movs r4, #0 buffer[1] = 0; c0d030ec: 7044 strb r4, [r0, #1] c0d030ee: 2101 movs r1, #1 buffer[2] = 1; c0d030f0: 7081 strb r1, [r0, #2] c0d030f2: 2102 movs r1, #2 buffer[3] = SEPROXYHAL_TAG_USB_CONFIG_DISCONNECT; c0d030f4: 70c1 strb r1, [r0, #3] io_seproxyhal_spi_send(buffer, 4); c0d030f6: 2104 movs r1, #4 c0d030f8: f7ff f86c bl c0d021d4 <io_seproxyhal_spi_send> return USBD_OK; c0d030fc: 4620 mov r0, r4 c0d030fe: b002 add sp, #8 c0d03100: bd10 pop {r4, pc} ... c0d03104 <USBD_LL_OpenEP>: */ USBD_StatusTypeDef USBD_LL_OpenEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t ep_type, uint16_t ep_mps) { c0d03104: b5b0 push {r4, r5, r7, lr} c0d03106: b082 sub sp, #8 uint8_t buffer[8]; UNUSED(pdev); ep_in_stall = 0; c0d03108: 480e ldr r0, [pc, #56] ; (c0d03144 <USBD_LL_OpenEP+0x40>) c0d0310a: 2400 movs r4, #0 c0d0310c: 6004 str r4, [r0, #0] ep_out_stall = 0; c0d0310e: 480e ldr r0, [pc, #56] ; (c0d03148 <USBD_LL_OpenEP+0x44>) c0d03110: 6004 str r4, [r0, #0] c0d03112: 4668 mov r0, sp buffer[0] = SEPROXYHAL_TAG_USB_CONFIG; c0d03114: 254f movs r5, #79 ; 0x4f c0d03116: 7005 strb r5, [r0, #0] buffer[1] = 0; c0d03118: 7044 strb r4, [r0, #1] c0d0311a: 2505 movs r5, #5 buffer[2] = 5; c0d0311c: 7085 strb r5, [r0, #2] c0d0311e: 2504 movs r5, #4 buffer[3] = SEPROXYHAL_TAG_USB_CONFIG_ENDPOINTS; c0d03120: 70c5 strb r5, [r0, #3] c0d03122: 2501 movs r5, #1 buffer[4] = 1; c0d03124: 7105 strb r5, [r0, #4] buffer[5] = ep_addr; c0d03126: 7141 strb r1, [r0, #5] buffer[6] = 0; switch(ep_type) { c0d03128: 2a03 cmp r2, #3 c0d0312a: d802 bhi.n c0d03132 <USBD_LL_OpenEP+0x2e> c0d0312c: 00d0 lsls r0, r2, #3 c0d0312e: 4c07 ldr r4, [pc, #28] ; (c0d0314c <USBD_LL_OpenEP+0x48>) c0d03130: 40c4 lsrs r4, r0 c0d03132: 4668 mov r0, sp buffer[1] = 0; buffer[2] = 5; buffer[3] = SEPROXYHAL_TAG_USB_CONFIG_ENDPOINTS; buffer[4] = 1; buffer[5] = ep_addr; buffer[6] = 0; c0d03134: 7184 strb r4, [r0, #6] break; case USBD_EP_TYPE_INTR: buffer[6] = SEPROXYHAL_TAG_USB_CONFIG_TYPE_INTERRUPT; break; } buffer[7] = ep_mps; c0d03136: 71c3 strb r3, [r0, #7] io_seproxyhal_spi_send(buffer, 8); c0d03138: 2108 movs r1, #8 c0d0313a: f7ff f84b bl c0d021d4 <io_seproxyhal_spi_send> c0d0313e: 2000 movs r0, #0 return USBD_OK; c0d03140: b002 add sp, #8 c0d03142: bdb0 pop {r4, r5, r7, pc} c0d03144: 20001c84 .word 0x20001c84 c0d03148: 20001c88 .word 0x20001c88 c0d0314c: 02030401 .word 0x02030401 c0d03150 <USBD_LL_CloseEP>: * @param pdev: Device handle * @param ep_addr: Endpoint Number * @retval USBD Status */ USBD_StatusTypeDef USBD_LL_CloseEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr) { c0d03150: b510 push {r4, lr} c0d03152: b082 sub sp, #8 c0d03154: 4668 mov r0, sp UNUSED(pdev); uint8_t buffer[8]; buffer[0] = SEPROXYHAL_TAG_USB_CONFIG; c0d03156: 224f movs r2, #79 ; 0x4f c0d03158: 7002 strb r2, [r0, #0] c0d0315a: 2400 movs r4, #0 buffer[1] = 0; c0d0315c: 7044 strb r4, [r0, #1] c0d0315e: 2205 movs r2, #5 buffer[2] = 5; c0d03160: 7082 strb r2, [r0, #2] c0d03162: 2204 movs r2, #4 buffer[3] = SEPROXYHAL_TAG_USB_CONFIG_ENDPOINTS; c0d03164: 70c2 strb r2, [r0, #3] c0d03166: 2201 movs r2, #1 buffer[4] = 1; c0d03168: 7102 strb r2, [r0, #4] buffer[5] = ep_addr; c0d0316a: 7141 strb r1, [r0, #5] buffer[6] = SEPROXYHAL_TAG_USB_CONFIG_TYPE_DISABLED; c0d0316c: 7184 strb r4, [r0, #6] buffer[7] = 0; c0d0316e: 71c4 strb r4, [r0, #7] io_seproxyhal_spi_send(buffer, 8); c0d03170: 2108 movs r1, #8 c0d03172: f7ff f82f bl c0d021d4 <io_seproxyhal_spi_send> return USBD_OK; c0d03176: 4620 mov r0, r4 c0d03178: b002 add sp, #8 c0d0317a: bd10 pop {r4, pc} c0d0317c <USBD_LL_StallEP>: * @param pdev: Device handle * @param ep_addr: Endpoint Number * @retval USBD Status */ USBD_StatusTypeDef USBD_LL_StallEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr) { c0d0317c: b5b0 push {r4, r5, r7, lr} c0d0317e: b082 sub sp, #8 c0d03180: 460d mov r5, r1 c0d03182: 4668 mov r0, sp UNUSED(pdev); uint8_t buffer[6]; buffer[0] = SEPROXYHAL_TAG_USB_EP_PREPARE; c0d03184: 2150 movs r1, #80 ; 0x50 c0d03186: 7001 strb r1, [r0, #0] c0d03188: 2400 movs r4, #0 buffer[1] = 0; c0d0318a: 7044 strb r4, [r0, #1] c0d0318c: 2103 movs r1, #3 buffer[2] = 3; c0d0318e: 7081 strb r1, [r0, #2] buffer[3] = ep_addr; c0d03190: 70c5 strb r5, [r0, #3] buffer[4] = SEPROXYHAL_TAG_USB_EP_PREPARE_DIR_STALL; c0d03192: 2140 movs r1, #64 ; 0x40 c0d03194: 7101 strb r1, [r0, #4] buffer[5] = 0; c0d03196: 7144 strb r4, [r0, #5] io_seproxyhal_spi_send(buffer, 6); c0d03198: 2106 movs r1, #6 c0d0319a: f7ff f81b bl c0d021d4 <io_seproxyhal_spi_send> if (ep_addr & 0x80) { c0d0319e: 2080 movs r0, #128 ; 0x80 c0d031a0: 4205 tst r5, r0 c0d031a2: d101 bne.n c0d031a8 <USBD_LL_StallEP+0x2c> c0d031a4: 4807 ldr r0, [pc, #28] ; (c0d031c4 <USBD_LL_StallEP+0x48>) c0d031a6: e000 b.n c0d031aa <USBD_LL_StallEP+0x2e> c0d031a8: 4805 ldr r0, [pc, #20] ; (c0d031c0 <USBD_LL_StallEP+0x44>) c0d031aa: 6801 ldr r1, [r0, #0] c0d031ac: 227f movs r2, #127 ; 0x7f c0d031ae: 4015 ands r5, r2 c0d031b0: 2201 movs r2, #1 c0d031b2: 40aa lsls r2, r5 c0d031b4: 430a orrs r2, r1 c0d031b6: 6002 str r2, [r0, #0] ep_in_stall |= (1<<(ep_addr&0x7F)); } else { ep_out_stall |= (1<<(ep_addr&0x7F)); } return USBD_OK; c0d031b8: 4620 mov r0, r4 c0d031ba: b002 add sp, #8 c0d031bc: bdb0 pop {r4, r5, r7, pc} c0d031be: 46c0 nop ; (mov r8, r8) c0d031c0: 20001c84 .word 0x20001c84 c0d031c4: 20001c88 .word 0x20001c88 c0d031c8 <USBD_LL_ClearStallEP>: * @param pdev: Device handle * @param ep_addr: Endpoint Number * @retval USBD Status */ USBD_StatusTypeDef USBD_LL_ClearStallEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr) { c0d031c8: b570 push {r4, r5, r6, lr} c0d031ca: b082 sub sp, #8 c0d031cc: 460d mov r5, r1 c0d031ce: 4668 mov r0, sp UNUSED(pdev); uint8_t buffer[6]; buffer[0] = SEPROXYHAL_TAG_USB_EP_PREPARE; c0d031d0: 2150 movs r1, #80 ; 0x50 c0d031d2: 7001 strb r1, [r0, #0] c0d031d4: 2400 movs r4, #0 buffer[1] = 0; c0d031d6: 7044 strb r4, [r0, #1] c0d031d8: 2103 movs r1, #3 buffer[2] = 3; c0d031da: 7081 strb r1, [r0, #2] buffer[3] = ep_addr; c0d031dc: 70c5 strb r5, [r0, #3] c0d031de: 2680 movs r6, #128 ; 0x80 buffer[4] = SEPROXYHAL_TAG_USB_EP_PREPARE_DIR_UNSTALL; c0d031e0: 7106 strb r6, [r0, #4] buffer[5] = 0; c0d031e2: 7144 strb r4, [r0, #5] io_seproxyhal_spi_send(buffer, 6); c0d031e4: 2106 movs r1, #6 c0d031e6: f7fe fff5 bl c0d021d4 <io_seproxyhal_spi_send> if (ep_addr & 0x80) { c0d031ea: 4235 tst r5, r6 c0d031ec: d101 bne.n c0d031f2 <USBD_LL_ClearStallEP+0x2a> c0d031ee: 4807 ldr r0, [pc, #28] ; (c0d0320c <USBD_LL_ClearStallEP+0x44>) c0d031f0: e000 b.n c0d031f4 <USBD_LL_ClearStallEP+0x2c> c0d031f2: 4805 ldr r0, [pc, #20] ; (c0d03208 <USBD_LL_ClearStallEP+0x40>) c0d031f4: 6801 ldr r1, [r0, #0] c0d031f6: 227f movs r2, #127 ; 0x7f c0d031f8: 4015 ands r5, r2 c0d031fa: 2201 movs r2, #1 c0d031fc: 40aa lsls r2, r5 c0d031fe: 4391 bics r1, r2 c0d03200: 6001 str r1, [r0, #0] ep_in_stall &= ~(1<<(ep_addr&0x7F)); } else { ep_out_stall &= ~(1<<(ep_addr&0x7F)); } return USBD_OK; c0d03202: 4620 mov r0, r4 c0d03204: b002 add sp, #8 c0d03206: bd70 pop {r4, r5, r6, pc} c0d03208: 20001c84 .word 0x20001c84 c0d0320c: 20001c88 .word 0x20001c88 c0d03210 <USBD_LL_IsStallEP>: * @retval Stall (1: Yes, 0: No) */ uint8_t USBD_LL_IsStallEP (USBD_HandleTypeDef *pdev, uint8_t ep_addr) { UNUSED(pdev); if((ep_addr & 0x80) == 0x80) c0d03210: 2080 movs r0, #128 ; 0x80 c0d03212: 4201 tst r1, r0 c0d03214: d001 beq.n c0d0321a <USBD_LL_IsStallEP+0xa> c0d03216: 4806 ldr r0, [pc, #24] ; (c0d03230 <USBD_LL_IsStallEP+0x20>) c0d03218: e000 b.n c0d0321c <USBD_LL_IsStallEP+0xc> c0d0321a: 4804 ldr r0, [pc, #16] ; (c0d0322c <USBD_LL_IsStallEP+0x1c>) c0d0321c: 6800 ldr r0, [r0, #0] c0d0321e: 227f movs r2, #127 ; 0x7f c0d03220: 4011 ands r1, r2 c0d03222: 2201 movs r2, #1 c0d03224: 408a lsls r2, r1 c0d03226: 4002 ands r2, r0 } else { return ep_out_stall & (1<<(ep_addr&0x7F)); } } c0d03228: b2d0 uxtb r0, r2 c0d0322a: 4770 bx lr c0d0322c: 20001c88 .word 0x20001c88 c0d03230: 20001c84 .word 0x20001c84 c0d03234 <USBD_LL_SetUSBAddress>: * @param pdev: Device handle * @param ep_addr: Endpoint Number * @retval USBD Status */ USBD_StatusTypeDef USBD_LL_SetUSBAddress (USBD_HandleTypeDef *pdev, uint8_t dev_addr) { c0d03234: b510 push {r4, lr} c0d03236: b082 sub sp, #8 c0d03238: 4668 mov r0, sp UNUSED(pdev); uint8_t buffer[5]; buffer[0] = SEPROXYHAL_TAG_USB_CONFIG; c0d0323a: 224f movs r2, #79 ; 0x4f c0d0323c: 7002 strb r2, [r0, #0] c0d0323e: 2400 movs r4, #0 buffer[1] = 0; c0d03240: 7044 strb r4, [r0, #1] c0d03242: 2202 movs r2, #2 buffer[2] = 2; c0d03244: 7082 strb r2, [r0, #2] c0d03246: 2203 movs r2, #3 buffer[3] = SEPROXYHAL_TAG_USB_CONFIG_ADDR; c0d03248: 70c2 strb r2, [r0, #3] buffer[4] = dev_addr; c0d0324a: 7101 strb r1, [r0, #4] io_seproxyhal_spi_send(buffer, 5); c0d0324c: 2105 movs r1, #5 c0d0324e: f7fe ffc1 bl c0d021d4 <io_seproxyhal_spi_send> return USBD_OK; c0d03252: 4620 mov r0, r4 c0d03254: b002 add sp, #8 c0d03256: bd10 pop {r4, pc} c0d03258 <USBD_LL_Transmit>: */ USBD_StatusTypeDef USBD_LL_Transmit (USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint8_t *pbuf, uint16_t size) { c0d03258: b5b0 push {r4, r5, r7, lr} c0d0325a: b082 sub sp, #8 c0d0325c: 461c mov r4, r3 c0d0325e: 4615 mov r5, r2 c0d03260: 4668 mov r0, sp UNUSED(pdev); uint8_t buffer[6]; buffer[0] = SEPROXYHAL_TAG_USB_EP_PREPARE; c0d03262: 2250 movs r2, #80 ; 0x50 c0d03264: 7002 strb r2, [r0, #0] buffer[1] = (3+size)>>8; c0d03266: 1ce2 adds r2, r4, #3 c0d03268: 0a13 lsrs r3, r2, #8 c0d0326a: 7043 strb r3, [r0, #1] buffer[2] = (3+size); c0d0326c: 7082 strb r2, [r0, #2] buffer[3] = ep_addr; c0d0326e: 70c1 strb r1, [r0, #3] buffer[4] = SEPROXYHAL_TAG_USB_EP_PREPARE_DIR_IN; c0d03270: 2120 movs r1, #32 c0d03272: 7101 strb r1, [r0, #4] buffer[5] = size; c0d03274: 7144 strb r4, [r0, #5] io_seproxyhal_spi_send(buffer, 6); c0d03276: 2106 movs r1, #6 c0d03278: f7fe ffac bl c0d021d4 <io_seproxyhal_spi_send> io_seproxyhal_spi_send(pbuf, size); c0d0327c: 4628 mov r0, r5 c0d0327e: 4621 mov r1, r4 c0d03280: f7fe ffa8 bl c0d021d4 <io_seproxyhal_spi_send> c0d03284: 2000 movs r0, #0 return USBD_OK; c0d03286: b002 add sp, #8 c0d03288: bdb0 pop {r4, r5, r7, pc} c0d0328a <USBD_LL_PrepareReceive>: * @retval USBD Status */ USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev, uint8_t ep_addr, uint16_t size) { c0d0328a: b510 push {r4, lr} c0d0328c: b082 sub sp, #8 c0d0328e: 4668 mov r0, sp UNUSED(pdev); uint8_t buffer[6]; buffer[0] = SEPROXYHAL_TAG_USB_EP_PREPARE; c0d03290: 2350 movs r3, #80 ; 0x50 c0d03292: 7003 strb r3, [r0, #0] c0d03294: 2400 movs r4, #0 buffer[1] = (3/*+size*/)>>8; c0d03296: 7044 strb r4, [r0, #1] c0d03298: 2303 movs r3, #3 buffer[2] = (3/*+size*/); c0d0329a: 7083 strb r3, [r0, #2] buffer[3] = ep_addr; c0d0329c: 70c1 strb r1, [r0, #3] buffer[4] = SEPROXYHAL_TAG_USB_EP_PREPARE_DIR_OUT; c0d0329e: 2130 movs r1, #48 ; 0x30 c0d032a0: 7101 strb r1, [r0, #4] buffer[5] = size; // expected size, not transmitted here ! c0d032a2: 7142 strb r2, [r0, #5] io_seproxyhal_spi_send(buffer, 6); c0d032a4: 2106 movs r1, #6 c0d032a6: f7fe ff95 bl c0d021d4 <io_seproxyhal_spi_send> return USBD_OK; c0d032aa: 4620 mov r0, r4 c0d032ac: b002 add sp, #8 c0d032ae: bd10 pop {r4, pc} c0d032b0 <USBD_Init>: * @param pdesc: Descriptor structure address * @param id: Low level core index * @retval None */ USBD_StatusTypeDef USBD_Init(USBD_HandleTypeDef *pdev, USBD_DescriptorsTypeDef *pdesc, uint8_t id) { c0d032b0: b570 push {r4, r5, r6, lr} c0d032b2: 4615 mov r5, r2 c0d032b4: 460e mov r6, r1 c0d032b6: 4604 mov r4, r0 c0d032b8: 2002 movs r0, #2 /* Check whether the USB Host handle is valid */ if(pdev == NULL) c0d032ba: 2c00 cmp r4, #0 c0d032bc: d011 beq.n c0d032e2 <USBD_Init+0x32> { USBD_ErrLog("Invalid Device handle"); return USBD_FAIL; } memset(pdev, 0, sizeof(USBD_HandleTypeDef)); c0d032be: 204d movs r0, #77 ; 0x4d c0d032c0: 0081 lsls r1, r0, #2 c0d032c2: 4620 mov r0, r4 c0d032c4: f000 ff6c bl c0d041a0 <__aeabi_memclr> /* Assign USBD Descriptors */ if(pdesc != NULL) c0d032c8: 2e00 cmp r6, #0 c0d032ca: d002 beq.n c0d032d2 <USBD_Init+0x22> { pdev->pDesc = pdesc; c0d032cc: 2011 movs r0, #17 c0d032ce: 0100 lsls r0, r0, #4 c0d032d0: 5026 str r6, [r4, r0] } /* Set Device initial State */ pdev->dev_state = USBD_STATE_DEFAULT; c0d032d2: 20fc movs r0, #252 ; 0xfc c0d032d4: 2101 movs r1, #1 c0d032d6: 5421 strb r1, [r4, r0] pdev->id = id; c0d032d8: 7025 strb r5, [r4, #0] /* Initialize low level driver */ USBD_LL_Init(pdev); c0d032da: 4620 mov r0, r4 c0d032dc: f7ff fec8 bl c0d03070 <USBD_LL_Init> c0d032e0: 2000 movs r0, #0 return USBD_OK; } c0d032e2: b2c0 uxtb r0, r0 c0d032e4: bd70 pop {r4, r5, r6, pc} c0d032e6 <USBD_DeInit>: * Re-Initialize th device library * @param pdev: device instance * @retval status: status */ USBD_StatusTypeDef USBD_DeInit(USBD_HandleTypeDef *pdev) { c0d032e6: b570 push {r4, r5, r6, lr} c0d032e8: 4604 mov r4, r0 /* Set Default State */ pdev->dev_state = USBD_STATE_DEFAULT; c0d032ea: 20fc movs r0, #252 ; 0xfc c0d032ec: 2101 movs r1, #1 c0d032ee: 5421 strb r1, [r4, r0] /* Free Class Resources */ uint8_t intf; for (intf =0; intf < USBD_MAX_NUM_INTERFACES; intf++) { c0d032f0: 2045 movs r0, #69 ; 0x45 c0d032f2: 0080 lsls r0, r0, #2 c0d032f4: 1825 adds r5, r4, r0 c0d032f6: 2600 movs r6, #0 if(pdev->interfacesClass[intf].pClass != NULL) { c0d032f8: 00f0 lsls r0, r6, #3 c0d032fa: 5828 ldr r0, [r5, r0] c0d032fc: 2800 cmp r0, #0 c0d032fe: d006 beq.n c0d0330e <USBD_DeInit+0x28> ((DeInit_t)PIC(pdev->interfacesClass[intf].pClass->DeInit))(pdev, pdev->dev_config); c0d03300: 6840 ldr r0, [r0, #4] c0d03302: f7fe fdd3 bl c0d01eac <pic> c0d03306: 4602 mov r2, r0 c0d03308: 7921 ldrb r1, [r4, #4] c0d0330a: 4620 mov r0, r4 c0d0330c: 4790 blx r2 /* Set Default State */ pdev->dev_state = USBD_STATE_DEFAULT; /* Free Class Resources */ uint8_t intf; for (intf =0; intf < USBD_MAX_NUM_INTERFACES; intf++) { c0d0330e: 1c76 adds r6, r6, #1 c0d03310: 2e03 cmp r6, #3 c0d03312: d1f1 bne.n c0d032f8 <USBD_DeInit+0x12> ((DeInit_t)PIC(pdev->interfacesClass[intf].pClass->DeInit))(pdev, pdev->dev_config); } } /* Stop the low level driver */ USBD_LL_Stop(pdev); c0d03314: 4620 mov r0, r4 c0d03316: f7ff fee3 bl c0d030e0 <USBD_LL_Stop> /* Initialize low level driver */ USBD_LL_DeInit(pdev); c0d0331a: 4620 mov r0, r4 c0d0331c: f7ff feb2 bl c0d03084 <USBD_LL_DeInit> return USBD_OK; c0d03320: 2000 movs r0, #0 c0d03322: bd70 pop {r4, r5, r6, pc} c0d03324 <USBD_RegisterClassForInterface>: * @param pDevice : Device Handle * @param pclass: Class handle * @retval USBD Status */ USBD_StatusTypeDef USBD_RegisterClassForInterface(uint8_t interfaceidx, USBD_HandleTypeDef *pdev, USBD_ClassTypeDef *pclass) { c0d03324: 2302 movs r3, #2 USBD_StatusTypeDef status = USBD_OK; if(pclass != 0) c0d03326: 2a00 cmp r2, #0 c0d03328: d007 beq.n c0d0333a <USBD_RegisterClassForInterface+0x16> c0d0332a: 2300 movs r3, #0 { if (interfaceidx < USBD_MAX_NUM_INTERFACES) { c0d0332c: 2802 cmp r0, #2 c0d0332e: d804 bhi.n c0d0333a <USBD_RegisterClassForInterface+0x16> /* link the class to the USB Device handle */ pdev->interfacesClass[interfaceidx].pClass = pclass; c0d03330: 00c0 lsls r0, r0, #3 c0d03332: 1808 adds r0, r1, r0 c0d03334: 2145 movs r1, #69 ; 0x45 c0d03336: 0089 lsls r1, r1, #2 c0d03338: 5042 str r2, [r0, r1] { USBD_ErrLog("Invalid Class handle"); status = USBD_FAIL; } return status; c0d0333a: b2d8 uxtb r0, r3 c0d0333c: 4770 bx lr c0d0333e <USBD_Start>: * Start the USB Device Core. * @param pdev: Device Handle * @retval USBD Status */ USBD_StatusTypeDef USBD_Start (USBD_HandleTypeDef *pdev) { c0d0333e: b580 push {r7, lr} /* Start the low level driver */ USBD_LL_Start(pdev); c0d03340: f7ff feb2 bl c0d030a8 <USBD_LL_Start> return USBD_OK; c0d03344: 2000 movs r0, #0 c0d03346: bd80 pop {r7, pc} c0d03348 <USBD_SetClassConfig>: * @param cfgidx: configuration index * @retval status */ USBD_StatusTypeDef USBD_SetClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx) { c0d03348: b5f0 push {r4, r5, r6, r7, lr} c0d0334a: b081 sub sp, #4 c0d0334c: 460c mov r4, r1 c0d0334e: 4605 mov r5, r0 /* Set configuration and Start the Class*/ uint8_t intf; for (intf =0; intf < USBD_MAX_NUM_INTERFACES; intf++) { c0d03350: 2045 movs r0, #69 ; 0x45 c0d03352: 0080 lsls r0, r0, #2 c0d03354: 182f adds r7, r5, r0 c0d03356: 2600 movs r6, #0 if(usbd_is_valid_intf(pdev, intf)) { c0d03358: 4628 mov r0, r5 c0d0335a: 4631 mov r1, r6 c0d0335c: f000 f97c bl c0d03658 <usbd_is_valid_intf> c0d03360: 2800 cmp r0, #0 c0d03362: d008 beq.n c0d03376 <USBD_SetClassConfig+0x2e> ((Init_t)PIC(pdev->interfacesClass[intf].pClass->Init))(pdev, cfgidx); c0d03364: 00f0 lsls r0, r6, #3 c0d03366: 5838 ldr r0, [r7, r0] c0d03368: 6800 ldr r0, [r0, #0] c0d0336a: f7fe fd9f bl c0d01eac <pic> c0d0336e: 4602 mov r2, r0 c0d03370: 4628 mov r0, r5 c0d03372: 4621 mov r1, r4 c0d03374: 4790 blx r2 USBD_StatusTypeDef USBD_SetClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx) { /* Set configuration and Start the Class*/ uint8_t intf; for (intf =0; intf < USBD_MAX_NUM_INTERFACES; intf++) { c0d03376: 1c76 adds r6, r6, #1 c0d03378: 2e03 cmp r6, #3 c0d0337a: d1ed bne.n c0d03358 <USBD_SetClassConfig+0x10> if(usbd_is_valid_intf(pdev, intf)) { ((Init_t)PIC(pdev->interfacesClass[intf].pClass->Init))(pdev, cfgidx); } } return USBD_OK; c0d0337c: 2000 movs r0, #0 c0d0337e: b001 add sp, #4 c0d03380: bdf0 pop {r4, r5, r6, r7, pc} c0d03382 <USBD_ClrClassConfig>: * @param pdev: device instance * @param cfgidx: configuration index * @retval status: USBD_StatusTypeDef */ USBD_StatusTypeDef USBD_ClrClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx) { c0d03382: b5f0 push {r4, r5, r6, r7, lr} c0d03384: b081 sub sp, #4 c0d03386: 460c mov r4, r1 c0d03388: 4605 mov r5, r0 /* Clear configuration and De-initialize the Class process*/ uint8_t intf; for (intf =0; intf < USBD_MAX_NUM_INTERFACES; intf++) { c0d0338a: 2045 movs r0, #69 ; 0x45 c0d0338c: 0080 lsls r0, r0, #2 c0d0338e: 182f adds r7, r5, r0 c0d03390: 2600 movs r6, #0 if(usbd_is_valid_intf(pdev, intf)) { c0d03392: 4628 mov r0, r5 c0d03394: 4631 mov r1, r6 c0d03396: f000 f95f bl c0d03658 <usbd_is_valid_intf> c0d0339a: 2800 cmp r0, #0 c0d0339c: d008 beq.n c0d033b0 <USBD_ClrClassConfig+0x2e> ((DeInit_t)PIC(pdev->interfacesClass[intf].pClass->DeInit))(pdev, cfgidx); c0d0339e: 00f0 lsls r0, r6, #3 c0d033a0: 5838 ldr r0, [r7, r0] c0d033a2: 6840 ldr r0, [r0, #4] c0d033a4: f7fe fd82 bl c0d01eac <pic> c0d033a8: 4602 mov r2, r0 c0d033aa: 4628 mov r0, r5 c0d033ac: 4621 mov r1, r4 c0d033ae: 4790 blx r2 */ USBD_StatusTypeDef USBD_ClrClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx) { /* Clear configuration and De-initialize the Class process*/ uint8_t intf; for (intf =0; intf < USBD_MAX_NUM_INTERFACES; intf++) { c0d033b0: 1c76 adds r6, r6, #1 c0d033b2: 2e03 cmp r6, #3 c0d033b4: d1ed bne.n c0d03392 <USBD_ClrClassConfig+0x10> if(usbd_is_valid_intf(pdev, intf)) { ((DeInit_t)PIC(pdev->interfacesClass[intf].pClass->DeInit))(pdev, cfgidx); } } return USBD_OK; c0d033b6: 2000 movs r0, #0 c0d033b8: b001 add sp, #4 c0d033ba: bdf0 pop {r4, r5, r6, r7, pc} c0d033bc <USBD_LL_SetupStage>: * Handle the setup stage * @param pdev: device instance * @retval status */ USBD_StatusTypeDef USBD_LL_SetupStage(USBD_HandleTypeDef *pdev, uint8_t *psetup) { c0d033bc: b570 push {r4, r5, r6, lr} c0d033be: 4604 mov r4, r0 c0d033c0: 2021 movs r0, #33 ; 0x21 c0d033c2: 00c6 lsls r6, r0, #3 USBD_ParseSetupRequest(&pdev->request, psetup); c0d033c4: 19a5 adds r5, r4, r6 c0d033c6: 4628 mov r0, r5 c0d033c8: f000 fb9d bl c0d03b06 <USBD_ParseSetupRequest> pdev->ep0_state = USBD_EP0_SETUP; c0d033cc: 20f4 movs r0, #244 ; 0xf4 c0d033ce: 2101 movs r1, #1 c0d033d0: 5021 str r1, [r4, r0] pdev->ep0_data_len = pdev->request.wLength; c0d033d2: 2087 movs r0, #135 ; 0x87 c0d033d4: 0040 lsls r0, r0, #1 c0d033d6: 5a20 ldrh r0, [r4, r0] c0d033d8: 21f8 movs r1, #248 ; 0xf8 c0d033da: 5060 str r0, [r4, r1] switch (pdev->request.bmRequest & 0x1F) c0d033dc: 5da1 ldrb r1, [r4, r6] c0d033de: 201f movs r0, #31 c0d033e0: 4008 ands r0, r1 c0d033e2: 2802 cmp r0, #2 c0d033e4: d008 beq.n c0d033f8 <USBD_LL_SetupStage+0x3c> c0d033e6: 2801 cmp r0, #1 c0d033e8: d00b beq.n c0d03402 <USBD_LL_SetupStage+0x46> c0d033ea: 2800 cmp r0, #0 c0d033ec: d10e bne.n c0d0340c <USBD_LL_SetupStage+0x50> { case USB_REQ_RECIPIENT_DEVICE: USBD_StdDevReq (pdev, &pdev->request); c0d033ee: 4620 mov r0, r4 c0d033f0: 4629 mov r1, r5 c0d033f2: f000 f93f bl c0d03674 <USBD_StdDevReq> c0d033f6: e00e b.n c0d03416 <USBD_LL_SetupStage+0x5a> case USB_REQ_RECIPIENT_INTERFACE: USBD_StdItfReq(pdev, &pdev->request); break; case USB_REQ_RECIPIENT_ENDPOINT: USBD_StdEPReq(pdev, &pdev->request); c0d033f8: 4620 mov r0, r4 c0d033fa: 4629 mov r1, r5 c0d033fc: f000 faf8 bl c0d039f0 <USBD_StdEPReq> c0d03400: e009 b.n c0d03416 <USBD_LL_SetupStage+0x5a> case USB_REQ_RECIPIENT_DEVICE: USBD_StdDevReq (pdev, &pdev->request); break; case USB_REQ_RECIPIENT_INTERFACE: USBD_StdItfReq(pdev, &pdev->request); c0d03402: 4620 mov r0, r4 c0d03404: 4629 mov r1, r5 c0d03406: f000 face bl c0d039a6 <USBD_StdItfReq> c0d0340a: e004 b.n c0d03416 <USBD_LL_SetupStage+0x5a> case USB_REQ_RECIPIENT_ENDPOINT: USBD_StdEPReq(pdev, &pdev->request); break; default: USBD_LL_StallEP(pdev , pdev->request.bmRequest & 0x80); c0d0340c: 2080 movs r0, #128 ; 0x80 c0d0340e: 4001 ands r1, r0 c0d03410: 4620 mov r0, r4 c0d03412: f7ff feb3 bl c0d0317c <USBD_LL_StallEP> break; } return USBD_OK; c0d03416: 2000 movs r0, #0 c0d03418: bd70 pop {r4, r5, r6, pc} c0d0341a <USBD_LL_DataOutStage>: * @param pdev: device instance * @param epnum: endpoint index * @retval status */ USBD_StatusTypeDef USBD_LL_DataOutStage(USBD_HandleTypeDef *pdev , uint8_t epnum, uint8_t *pdata) { c0d0341a: b5f0 push {r4, r5, r6, r7, lr} c0d0341c: b083 sub sp, #12 c0d0341e: 9202 str r2, [sp, #8] c0d03420: 4604 mov r4, r0 c0d03422: 9101 str r1, [sp, #4] USBD_EndpointTypeDef *pep; if(epnum == 0) c0d03424: 2900 cmp r1, #0 c0d03426: d01e beq.n c0d03466 <USBD_LL_DataOutStage+0x4c> } } else { uint8_t intf; for (intf =0; intf < USBD_MAX_NUM_INTERFACES; intf++) { c0d03428: 2045 movs r0, #69 ; 0x45 c0d0342a: 0080 lsls r0, r0, #2 c0d0342c: 1825 adds r5, r4, r0 c0d0342e: 4626 mov r6, r4 c0d03430: 36fc adds r6, #252 ; 0xfc c0d03432: 2700 movs r7, #0 if( usbd_is_valid_intf(pdev, intf) && (pdev->interfacesClass[intf].pClass->DataOut != NULL)&& c0d03434: 4620 mov r0, r4 c0d03436: 4639 mov r1, r7 c0d03438: f000 f90e bl c0d03658 <usbd_is_valid_intf> c0d0343c: 2800 cmp r0, #0 c0d0343e: d00e beq.n c0d0345e <USBD_LL_DataOutStage+0x44> c0d03440: 00f8 lsls r0, r7, #3 c0d03442: 5828 ldr r0, [r5, r0] c0d03444: 6980 ldr r0, [r0, #24] c0d03446: 2800 cmp r0, #0 c0d03448: d009 beq.n c0d0345e <USBD_LL_DataOutStage+0x44> (pdev->dev_state == USBD_STATE_CONFIGURED)) c0d0344a: 7831 ldrb r1, [r6, #0] } else { uint8_t intf; for (intf =0; intf < USBD_MAX_NUM_INTERFACES; intf++) { if( usbd_is_valid_intf(pdev, intf) && (pdev->interfacesClass[intf].pClass->DataOut != NULL)&& c0d0344c: 2903 cmp r1, #3 c0d0344e: d106 bne.n c0d0345e <USBD_LL_DataOutStage+0x44> (pdev->dev_state == USBD_STATE_CONFIGURED)) { ((DataOut_t)PIC(pdev->interfacesClass[intf].pClass->DataOut))(pdev, epnum, pdata); c0d03450: f7fe fd2c bl c0d01eac <pic> c0d03454: 4603 mov r3, r0 c0d03456: 4620 mov r0, r4 c0d03458: 9901 ldr r1, [sp, #4] c0d0345a: 9a02 ldr r2, [sp, #8] c0d0345c: 4798 blx r3 } } else { uint8_t intf; for (intf =0; intf < USBD_MAX_NUM_INTERFACES; intf++) { c0d0345e: 1c7f adds r7, r7, #1 c0d03460: 2f03 cmp r7, #3 c0d03462: d1e7 bne.n c0d03434 <USBD_LL_DataOutStage+0x1a> c0d03464: e035 b.n c0d034d2 <USBD_LL_DataOutStage+0xb8> if(epnum == 0) { pep = &pdev->ep_out[0]; if ( pdev->ep0_state == USBD_EP0_DATA_OUT) c0d03466: 20f4 movs r0, #244 ; 0xf4 c0d03468: 5820 ldr r0, [r4, r0] c0d0346a: 2803 cmp r0, #3 c0d0346c: d131 bne.n c0d034d2 <USBD_LL_DataOutStage+0xb8> { if(pep->rem_length > pep->maxpacket) c0d0346e: 2090 movs r0, #144 ; 0x90 c0d03470: 5820 ldr r0, [r4, r0] c0d03472: 218c movs r1, #140 ; 0x8c c0d03474: 5861 ldr r1, [r4, r1] c0d03476: 4622 mov r2, r4 c0d03478: 328c adds r2, #140 ; 0x8c c0d0347a: 4281 cmp r1, r0 c0d0347c: d90a bls.n c0d03494 <USBD_LL_DataOutStage+0x7a> { pep->rem_length -= pep->maxpacket; c0d0347e: 1a09 subs r1, r1, r0 c0d03480: 6011 str r1, [r2, #0] c0d03482: 4281 cmp r1, r0 c0d03484: d300 bcc.n c0d03488 <USBD_LL_DataOutStage+0x6e> c0d03486: 4601 mov r1, r0 USBD_CtlContinueRx (pdev, c0d03488: b28a uxth r2, r1 c0d0348a: 4620 mov r0, r4 c0d0348c: 9902 ldr r1, [sp, #8] c0d0348e: f000 fdbb bl c0d04008 <USBD_CtlContinueRx> c0d03492: e01e b.n c0d034d2 <USBD_LL_DataOutStage+0xb8> MIN(pep->rem_length ,pep->maxpacket)); } else { uint8_t intf; for (intf =0; intf < USBD_MAX_NUM_INTERFACES; intf++) { c0d03494: 2045 movs r0, #69 ; 0x45 c0d03496: 0080 lsls r0, r0, #2 c0d03498: 1826 adds r6, r4, r0 c0d0349a: 4627 mov r7, r4 c0d0349c: 37fc adds r7, #252 ; 0xfc c0d0349e: 2500 movs r5, #0 if(usbd_is_valid_intf(pdev, intf) && (pdev->interfacesClass[intf].pClass->EP0_RxReady != NULL)&& c0d034a0: 4620 mov r0, r4 c0d034a2: 4629 mov r1, r5 c0d034a4: f000 f8d8 bl c0d03658 <usbd_is_valid_intf> c0d034a8: 2800 cmp r0, #0 c0d034aa: d00c beq.n c0d034c6 <USBD_LL_DataOutStage+0xac> c0d034ac: 00e8 lsls r0, r5, #3 c0d034ae: 5830 ldr r0, [r6, r0] c0d034b0: 6900 ldr r0, [r0, #16] c0d034b2: 2800 cmp r0, #0 c0d034b4: d007 beq.n c0d034c6 <USBD_LL_DataOutStage+0xac> (pdev->dev_state == USBD_STATE_CONFIGURED)) c0d034b6: 7839 ldrb r1, [r7, #0] } else { uint8_t intf; for (intf =0; intf < USBD_MAX_NUM_INTERFACES; intf++) { if(usbd_is_valid_intf(pdev, intf) && (pdev->interfacesClass[intf].pClass->EP0_RxReady != NULL)&& c0d034b8: 2903 cmp r1, #3 c0d034ba: d104 bne.n c0d034c6 <USBD_LL_DataOutStage+0xac> (pdev->dev_state == USBD_STATE_CONFIGURED)) { ((EP0_RxReady_t)PIC(pdev->interfacesClass[intf].pClass->EP0_RxReady))(pdev); c0d034bc: f7fe fcf6 bl c0d01eac <pic> c0d034c0: 4601 mov r1, r0 c0d034c2: 4620 mov r0, r4 c0d034c4: 4788 blx r1 MIN(pep->rem_length ,pep->maxpacket)); } else { uint8_t intf; for (intf =0; intf < USBD_MAX_NUM_INTERFACES; intf++) { c0d034c6: 1c6d adds r5, r5, #1 c0d034c8: 2d03 cmp r5, #3 c0d034ca: d1e9 bne.n c0d034a0 <USBD_LL_DataOutStage+0x86> (pdev->dev_state == USBD_STATE_CONFIGURED)) { ((EP0_RxReady_t)PIC(pdev->interfacesClass[intf].pClass->EP0_RxReady))(pdev); } } USBD_CtlSendStatus(pdev); c0d034cc: 4620 mov r0, r4 c0d034ce: f000 fda2 bl c0d04016 <USBD_CtlSendStatus> { ((DataOut_t)PIC(pdev->interfacesClass[intf].pClass->DataOut))(pdev, epnum, pdata); } } } return USBD_OK; c0d034d2: 2000 movs r0, #0 c0d034d4: b003 add sp, #12 c0d034d6: bdf0 pop {r4, r5, r6, r7, pc} c0d034d8 <USBD_LL_DataInStage>: * @param pdev: device instance * @param epnum: endpoint index * @retval status */ USBD_StatusTypeDef USBD_LL_DataInStage(USBD_HandleTypeDef *pdev ,uint8_t epnum, uint8_t *pdata) { c0d034d8: b5f0 push {r4, r5, r6, r7, lr} c0d034da: b081 sub sp, #4 c0d034dc: 4604 mov r4, r0 c0d034de: 9100 str r1, [sp, #0] USBD_EndpointTypeDef *pep; UNUSED(pdata); if(epnum == 0) c0d034e0: 2900 cmp r1, #0 c0d034e2: d01d beq.n c0d03520 <USBD_LL_DataInStage+0x48> pdev->dev_test_mode = 0; } } else { uint8_t intf; for (intf = 0; intf < USBD_MAX_NUM_INTERFACES; intf++) { c0d034e4: 2045 movs r0, #69 ; 0x45 c0d034e6: 0080 lsls r0, r0, #2 c0d034e8: 1827 adds r7, r4, r0 c0d034ea: 4625 mov r5, r4 c0d034ec: 35fc adds r5, #252 ; 0xfc c0d034ee: 2600 movs r6, #0 if( usbd_is_valid_intf(pdev, intf) && (pdev->interfacesClass[intf].pClass->DataIn != NULL)&& c0d034f0: 4620 mov r0, r4 c0d034f2: 4631 mov r1, r6 c0d034f4: f000 f8b0 bl c0d03658 <usbd_is_valid_intf> c0d034f8: 2800 cmp r0, #0 c0d034fa: d00d beq.n c0d03518 <USBD_LL_DataInStage+0x40> c0d034fc: 00f0 lsls r0, r6, #3 c0d034fe: 5838 ldr r0, [r7, r0] c0d03500: 6940 ldr r0, [r0, #20] c0d03502: 2800 cmp r0, #0 c0d03504: d008 beq.n c0d03518 <USBD_LL_DataInStage+0x40> (pdev->dev_state == USBD_STATE_CONFIGURED)) c0d03506: 7829 ldrb r1, [r5, #0] } } else { uint8_t intf; for (intf = 0; intf < USBD_MAX_NUM_INTERFACES; intf++) { if( usbd_is_valid_intf(pdev, intf) && (pdev->interfacesClass[intf].pClass->DataIn != NULL)&& c0d03508: 2903 cmp r1, #3 c0d0350a: d105 bne.n c0d03518 <USBD_LL_DataInStage+0x40> (pdev->dev_state == USBD_STATE_CONFIGURED)) { ((DataIn_t)PIC(pdev->interfacesClass[intf].pClass->DataIn))(pdev, epnum); c0d0350c: f7fe fcce bl c0d01eac <pic> c0d03510: 4602 mov r2, r0 c0d03512: 4620 mov r0, r4 c0d03514: 9900 ldr r1, [sp, #0] c0d03516: 4790 blx r2 pdev->dev_test_mode = 0; } } else { uint8_t intf; for (intf = 0; intf < USBD_MAX_NUM_INTERFACES; intf++) { c0d03518: 1c76 adds r6, r6, #1 c0d0351a: 2e03 cmp r6, #3 c0d0351c: d1e8 bne.n c0d034f0 <USBD_LL_DataInStage+0x18> c0d0351e: e051 b.n c0d035c4 <USBD_LL_DataInStage+0xec> if(epnum == 0) { pep = &pdev->ep_in[0]; if ( pdev->ep0_state == USBD_EP0_DATA_IN) c0d03520: 20f4 movs r0, #244 ; 0xf4 c0d03522: 5820 ldr r0, [r4, r0] c0d03524: 2802 cmp r0, #2 c0d03526: d145 bne.n c0d035b4 <USBD_LL_DataInStage+0xdc> { if(pep->rem_length > pep->maxpacket) c0d03528: 69e0 ldr r0, [r4, #28] c0d0352a: 6a25 ldr r5, [r4, #32] c0d0352c: 42a8 cmp r0, r5 c0d0352e: d90b bls.n c0d03548 <USBD_LL_DataInStage+0x70> { pep->rem_length -= pep->maxpacket; c0d03530: 1b40 subs r0, r0, r5 c0d03532: 61e0 str r0, [r4, #28] pdev->pData += pep->maxpacket; c0d03534: 2113 movs r1, #19 c0d03536: 010a lsls r2, r1, #4 c0d03538: 58a1 ldr r1, [r4, r2] c0d0353a: 1949 adds r1, r1, r5 c0d0353c: 50a1 str r1, [r4, r2] USBD_LL_PrepareReceive (pdev, 0, 0); */ USBD_CtlContinueSendData (pdev, c0d0353e: b282 uxth r2, r0 c0d03540: 4620 mov r0, r4 c0d03542: f000 fd53 bl c0d03fec <USBD_CtlContinueSendData> c0d03546: e035 b.n c0d035b4 <USBD_LL_DataInStage+0xdc> pep->rem_length); } else { /* last packet is MPS multiple, so send ZLP packet */ if((pep->total_length % pep->maxpacket == 0) && c0d03548: 69a6 ldr r6, [r4, #24] c0d0354a: 4630 mov r0, r6 c0d0354c: 4629 mov r1, r5 c0d0354e: f000 fe21 bl c0d04194 <__aeabi_uidivmod> c0d03552: 42ae cmp r6, r5 c0d03554: d30f bcc.n c0d03576 <USBD_LL_DataInStage+0x9e> c0d03556: 2900 cmp r1, #0 c0d03558: d10d bne.n c0d03576 <USBD_LL_DataInStage+0x9e> (pep->total_length >= pep->maxpacket) && (pep->total_length < pdev->ep0_data_len )) c0d0355a: 20f8 movs r0, #248 ; 0xf8 c0d0355c: 5820 ldr r0, [r4, r0] c0d0355e: 4627 mov r7, r4 c0d03560: 37f8 adds r7, #248 ; 0xf8 pep->rem_length); } else { /* last packet is MPS multiple, so send ZLP packet */ if((pep->total_length % pep->maxpacket == 0) && c0d03562: 4286 cmp r6, r0 c0d03564: d207 bcs.n c0d03576 <USBD_LL_DataInStage+0x9e> c0d03566: 2500 movs r5, #0 USBD_LL_PrepareReceive (pdev, 0, 0); */ USBD_CtlContinueSendData(pdev , NULL, 0); c0d03568: 4620 mov r0, r4 c0d0356a: 4629 mov r1, r5 c0d0356c: 462a mov r2, r5 c0d0356e: f000 fd3d bl c0d03fec <USBD_CtlContinueSendData> pdev->ep0_data_len = 0; c0d03572: 603d str r5, [r7, #0] c0d03574: e01e b.n c0d035b4 <USBD_LL_DataInStage+0xdc> } else { uint8_t intf; for (intf =0; intf < USBD_MAX_NUM_INTERFACES; intf++) { c0d03576: 2045 movs r0, #69 ; 0x45 c0d03578: 0080 lsls r0, r0, #2 c0d0357a: 1826 adds r6, r4, r0 c0d0357c: 4627 mov r7, r4 c0d0357e: 37fc adds r7, #252 ; 0xfc c0d03580: 2500 movs r5, #0 if(usbd_is_valid_intf(pdev, intf) && (pdev->interfacesClass[intf].pClass->EP0_TxSent != NULL)&& c0d03582: 4620 mov r0, r4 c0d03584: 4629 mov r1, r5 c0d03586: f000 f867 bl c0d03658 <usbd_is_valid_intf> c0d0358a: 2800 cmp r0, #0 c0d0358c: d00c beq.n c0d035a8 <USBD_LL_DataInStage+0xd0> c0d0358e: 00e8 lsls r0, r5, #3 c0d03590: 5830 ldr r0, [r6, r0] c0d03592: 68c0 ldr r0, [r0, #12] c0d03594: 2800 cmp r0, #0 c0d03596: d007 beq.n c0d035a8 <USBD_LL_DataInStage+0xd0> (pdev->dev_state == USBD_STATE_CONFIGURED)) c0d03598: 7839 ldrb r1, [r7, #0] } else { uint8_t intf; for (intf =0; intf < USBD_MAX_NUM_INTERFACES; intf++) { if(usbd_is_valid_intf(pdev, intf) && (pdev->interfacesClass[intf].pClass->EP0_TxSent != NULL)&& c0d0359a: 2903 cmp r1, #3 c0d0359c: d104 bne.n c0d035a8 <USBD_LL_DataInStage+0xd0> (pdev->dev_state == USBD_STATE_CONFIGURED)) { ((EP0_RxReady_t)PIC(pdev->interfacesClass[intf].pClass->EP0_TxSent))(pdev); c0d0359e: f7fe fc85 bl c0d01eac <pic> c0d035a2: 4601 mov r1, r0 c0d035a4: 4620 mov r0, r4 c0d035a6: 4788 blx r1 } else { uint8_t intf; for (intf =0; intf < USBD_MAX_NUM_INTERFACES; intf++) { c0d035a8: 1c6d adds r5, r5, #1 c0d035aa: 2d03 cmp r5, #3 c0d035ac: d1e9 bne.n c0d03582 <USBD_LL_DataInStage+0xaa> (pdev->dev_state == USBD_STATE_CONFIGURED)) { ((EP0_RxReady_t)PIC(pdev->interfacesClass[intf].pClass->EP0_TxSent))(pdev); } } USBD_CtlReceiveStatus(pdev); c0d035ae: 4620 mov r0, r4 c0d035b0: f000 fd3d bl c0d0402e <USBD_CtlReceiveStatus> } } } if (pdev->dev_test_mode == 1) c0d035b4: 2001 movs r0, #1 c0d035b6: 0201 lsls r1, r0, #8 c0d035b8: 1860 adds r0, r4, r1 c0d035ba: 5c61 ldrb r1, [r4, r1] c0d035bc: 2901 cmp r1, #1 c0d035be: d101 bne.n c0d035c4 <USBD_LL_DataInStage+0xec> { USBD_RunTestMode(pdev); pdev->dev_test_mode = 0; c0d035c0: 2100 movs r1, #0 c0d035c2: 7001 strb r1, [r0, #0] { ((DataIn_t)PIC(pdev->interfacesClass[intf].pClass->DataIn))(pdev, epnum); } } } return USBD_OK; c0d035c4: 2000 movs r0, #0 c0d035c6: b001 add sp, #4 c0d035c8: bdf0 pop {r4, r5, r6, r7, pc} c0d035ca <USBD_LL_Reset>: * @param pdev: device instance * @retval status */ USBD_StatusTypeDef USBD_LL_Reset(USBD_HandleTypeDef *pdev) { c0d035ca: b570 push {r4, r5, r6, lr} c0d035cc: 4604 mov r4, r0 pdev->ep_out[0].maxpacket = USB_MAX_EP0_SIZE; c0d035ce: 2090 movs r0, #144 ; 0x90 c0d035d0: 2140 movs r1, #64 ; 0x40 c0d035d2: 5021 str r1, [r4, r0] pdev->ep_in[0].maxpacket = USB_MAX_EP0_SIZE; c0d035d4: 6221 str r1, [r4, #32] /* Upon Reset call user call back */ pdev->dev_state = USBD_STATE_DEFAULT; c0d035d6: 20fc movs r0, #252 ; 0xfc c0d035d8: 2101 movs r1, #1 c0d035da: 5421 strb r1, [r4, r0] uint8_t intf; for (intf =0; intf < USBD_MAX_NUM_INTERFACES; intf++) { c0d035dc: 2045 movs r0, #69 ; 0x45 c0d035de: 0080 lsls r0, r0, #2 c0d035e0: 1826 adds r6, r4, r0 c0d035e2: 2500 movs r5, #0 if( usbd_is_valid_intf(pdev, intf)) c0d035e4: 4620 mov r0, r4 c0d035e6: 4629 mov r1, r5 c0d035e8: f000 f836 bl c0d03658 <usbd_is_valid_intf> c0d035ec: 2800 cmp r0, #0 c0d035ee: d008 beq.n c0d03602 <USBD_LL_Reset+0x38> { ((DeInit_t)PIC(pdev->interfacesClass[intf].pClass->DeInit))(pdev, pdev->dev_config); c0d035f0: 00e8 lsls r0, r5, #3 c0d035f2: 5830 ldr r0, [r6, r0] c0d035f4: 6840 ldr r0, [r0, #4] c0d035f6: f7fe fc59 bl c0d01eac <pic> c0d035fa: 4602 mov r2, r0 c0d035fc: 7921 ldrb r1, [r4, #4] c0d035fe: 4620 mov r0, r4 c0d03600: 4790 blx r2 pdev->ep_in[0].maxpacket = USB_MAX_EP0_SIZE; /* Upon Reset call user call back */ pdev->dev_state = USBD_STATE_DEFAULT; uint8_t intf; for (intf =0; intf < USBD_MAX_NUM_INTERFACES; intf++) { c0d03602: 1c6d adds r5, r5, #1 c0d03604: 2d03 cmp r5, #3 c0d03606: d1ed bne.n c0d035e4 <USBD_LL_Reset+0x1a> { ((DeInit_t)PIC(pdev->interfacesClass[intf].pClass->DeInit))(pdev, pdev->dev_config); } } return USBD_OK; c0d03608: 2000 movs r0, #0 c0d0360a: bd70 pop {r4, r5, r6, pc} c0d0360c <USBD_LL_SetSpeed>: * @param pdev: device instance * @retval status */ USBD_StatusTypeDef USBD_LL_SetSpeed(USBD_HandleTypeDef *pdev, USBD_SpeedTypeDef speed) { pdev->dev_speed = speed; c0d0360c: 7401 strb r1, [r0, #16] c0d0360e: 2000 movs r0, #0 return USBD_OK; c0d03610: 4770 bx lr c0d03612 <USBD_LL_Suspend>: { UNUSED(pdev); // Ignored, gently //pdev->dev_old_state = pdev->dev_state; //pdev->dev_state = USBD_STATE_SUSPENDED; return USBD_OK; c0d03612: 2000 movs r0, #0 c0d03614: 4770 bx lr c0d03616 <USBD_LL_Resume>: USBD_StatusTypeDef USBD_LL_Resume(USBD_HandleTypeDef *pdev) { UNUSED(pdev); // Ignored, gently //pdev->dev_state = pdev->dev_old_state; return USBD_OK; c0d03616: 2000 movs r0, #0 c0d03618: 4770 bx lr c0d0361a <USBD_LL_SOF>: * @param pdev: device instance * @retval status */ USBD_StatusTypeDef USBD_LL_SOF(USBD_HandleTypeDef *pdev) { c0d0361a: b570 push {r4, r5, r6, lr} c0d0361c: 4604 mov r4, r0 if(pdev->dev_state == USBD_STATE_CONFIGURED) c0d0361e: 20fc movs r0, #252 ; 0xfc c0d03620: 5c20 ldrb r0, [r4, r0] c0d03622: 2803 cmp r0, #3 c0d03624: d116 bne.n c0d03654 <USBD_LL_SOF+0x3a> { uint8_t intf; for (intf =0; intf < USBD_MAX_NUM_INTERFACES; intf++) { if( usbd_is_valid_intf(pdev, intf) && pdev->interfacesClass[intf].pClass->SOF != NULL) c0d03626: 2045 movs r0, #69 ; 0x45 c0d03628: 0080 lsls r0, r0, #2 c0d0362a: 1826 adds r6, r4, r0 c0d0362c: 2500 movs r5, #0 c0d0362e: 4620 mov r0, r4 c0d03630: 4629 mov r1, r5 c0d03632: f000 f811 bl c0d03658 <usbd_is_valid_intf> c0d03636: 2800 cmp r0, #0 c0d03638: d009 beq.n c0d0364e <USBD_LL_SOF+0x34> c0d0363a: 00e8 lsls r0, r5, #3 c0d0363c: 5830 ldr r0, [r6, r0] c0d0363e: 69c0 ldr r0, [r0, #28] c0d03640: 2800 cmp r0, #0 c0d03642: d004 beq.n c0d0364e <USBD_LL_SOF+0x34> { ((SOF_t)PIC(pdev->interfacesClass[intf].pClass->SOF))(pdev); c0d03644: f7fe fc32 bl c0d01eac <pic> c0d03648: 4601 mov r1, r0 c0d0364a: 4620 mov r0, r4 c0d0364c: 4788 blx r1 USBD_StatusTypeDef USBD_LL_SOF(USBD_HandleTypeDef *pdev) { if(pdev->dev_state == USBD_STATE_CONFIGURED) { uint8_t intf; for (intf =0; intf < USBD_MAX_NUM_INTERFACES; intf++) { c0d0364e: 1c6d adds r5, r5, #1 c0d03650: 2d03 cmp r5, #3 c0d03652: d1ec bne.n c0d0362e <USBD_LL_SOF+0x14> { ((SOF_t)PIC(pdev->interfacesClass[intf].pClass->SOF))(pdev); } } } return USBD_OK; c0d03654: 2000 movs r0, #0 c0d03656: bd70 pop {r4, r5, r6, pc} c0d03658 <usbd_is_valid_intf>: /** @defgroup USBD_REQ_Private_Functions * @{ */ unsigned int usbd_is_valid_intf(USBD_HandleTypeDef *pdev , unsigned int intf) { c0d03658: 4602 mov r2, r0 c0d0365a: 2000 movs r0, #0 return intf < USBD_MAX_NUM_INTERFACES && pdev->interfacesClass[intf].pClass != NULL; c0d0365c: 2902 cmp r1, #2 c0d0365e: d808 bhi.n c0d03672 <usbd_is_valid_intf+0x1a> c0d03660: 00c8 lsls r0, r1, #3 c0d03662: 1810 adds r0, r2, r0 c0d03664: 2145 movs r1, #69 ; 0x45 c0d03666: 0089 lsls r1, r1, #2 c0d03668: 5841 ldr r1, [r0, r1] c0d0366a: 2001 movs r0, #1 c0d0366c: 2900 cmp r1, #0 c0d0366e: d100 bne.n c0d03672 <usbd_is_valid_intf+0x1a> c0d03670: 4608 mov r0, r1 c0d03672: 4770 bx lr c0d03674 <USBD_StdDevReq>: * @param pdev: device instance * @param req: usb request * @retval status */ USBD_StatusTypeDef USBD_StdDevReq (USBD_HandleTypeDef *pdev , USBD_SetupReqTypedef *req) { c0d03674: b580 push {r7, lr} c0d03676: 784a ldrb r2, [r1, #1] USBD_StatusTypeDef ret = USBD_OK; switch (req->bRequest) c0d03678: 2a04 cmp r2, #4 c0d0367a: dd08 ble.n c0d0368e <USBD_StdDevReq+0x1a> c0d0367c: 2a07 cmp r2, #7 c0d0367e: dc0f bgt.n c0d036a0 <USBD_StdDevReq+0x2c> c0d03680: 2a05 cmp r2, #5 c0d03682: d014 beq.n c0d036ae <USBD_StdDevReq+0x3a> c0d03684: 2a06 cmp r2, #6 c0d03686: d11b bne.n c0d036c0 <USBD_StdDevReq+0x4c> { case USB_REQ_GET_DESCRIPTOR: USBD_GetDescriptor (pdev, req) ; c0d03688: f000 f821 bl c0d036ce <USBD_GetDescriptor> c0d0368c: e01d b.n c0d036ca <USBD_StdDevReq+0x56> c0d0368e: 2a00 cmp r2, #0 c0d03690: d010 beq.n c0d036b4 <USBD_StdDevReq+0x40> c0d03692: 2a01 cmp r2, #1 c0d03694: d017 beq.n c0d036c6 <USBD_StdDevReq+0x52> c0d03696: 2a03 cmp r2, #3 c0d03698: d112 bne.n c0d036c0 <USBD_StdDevReq+0x4c> USBD_GetStatus (pdev , req); break; case USB_REQ_SET_FEATURE: USBD_SetFeature (pdev , req); c0d0369a: f000 f93b bl c0d03914 <USBD_SetFeature> c0d0369e: e014 b.n c0d036ca <USBD_StdDevReq+0x56> c0d036a0: 2a08 cmp r2, #8 c0d036a2: d00a beq.n c0d036ba <USBD_StdDevReq+0x46> c0d036a4: 2a09 cmp r2, #9 c0d036a6: d10b bne.n c0d036c0 <USBD_StdDevReq+0x4c> case USB_REQ_SET_ADDRESS: USBD_SetAddress(pdev, req); break; case USB_REQ_SET_CONFIGURATION: USBD_SetConfig (pdev , req); c0d036a8: f000 f8c3 bl c0d03832 <USBD_SetConfig> c0d036ac: e00d b.n c0d036ca <USBD_StdDevReq+0x56> USBD_GetDescriptor (pdev, req) ; break; case USB_REQ_SET_ADDRESS: USBD_SetAddress(pdev, req); c0d036ae: f000 f89b bl c0d037e8 <USBD_SetAddress> c0d036b2: e00a b.n c0d036ca <USBD_StdDevReq+0x56> case USB_REQ_GET_CONFIGURATION: USBD_GetConfig (pdev , req); break; case USB_REQ_GET_STATUS: USBD_GetStatus (pdev , req); c0d036b4: f000 f90b bl c0d038ce <USBD_GetStatus> c0d036b8: e007 b.n c0d036ca <USBD_StdDevReq+0x56> case USB_REQ_SET_CONFIGURATION: USBD_SetConfig (pdev , req); break; case USB_REQ_GET_CONFIGURATION: USBD_GetConfig (pdev , req); c0d036ba: f000 f8f1 bl c0d038a0 <USBD_GetConfig> c0d036be: e004 b.n c0d036ca <USBD_StdDevReq+0x56> case USB_REQ_CLEAR_FEATURE: USBD_ClrFeature (pdev , req); break; default: USBD_CtlError(pdev , req); c0d036c0: f000 fbfc bl c0d03ebc <USBD_CtlError> c0d036c4: e001 b.n c0d036ca <USBD_StdDevReq+0x56> case USB_REQ_SET_FEATURE: USBD_SetFeature (pdev , req); break; case USB_REQ_CLEAR_FEATURE: USBD_ClrFeature (pdev , req); c0d036c6: f000 f944 bl c0d03952 <USBD_ClrFeature> default: USBD_CtlError(pdev , req); break; } return ret; c0d036ca: 2000 movs r0, #0 c0d036cc: bd80 pop {r7, pc} c0d036ce <USBD_GetDescriptor>: * @param req: usb request * @retval status */ void USBD_GetDescriptor(USBD_HandleTypeDef *pdev , USBD_SetupReqTypedef *req) { c0d036ce: b5b0 push {r4, r5, r7, lr} c0d036d0: b082 sub sp, #8 c0d036d2: 460d mov r5, r1 c0d036d4: 4604 mov r4, r0 uint16_t len; uint8_t *pbuf = NULL; switch (req->wValue >> 8) c0d036d6: 8869 ldrh r1, [r5, #2] c0d036d8: 0a08 lsrs r0, r1, #8 c0d036da: 2805 cmp r0, #5 c0d036dc: dc13 bgt.n c0d03706 <USBD_GetDescriptor+0x38> c0d036de: 2801 cmp r0, #1 c0d036e0: d01c beq.n c0d0371c <USBD_GetDescriptor+0x4e> c0d036e2: 2802 cmp r0, #2 c0d036e4: d025 beq.n c0d03732 <USBD_GetDescriptor+0x64> c0d036e6: 2803 cmp r0, #3 c0d036e8: d13b bne.n c0d03762 <USBD_GetDescriptor+0x94> c0d036ea: b2c8 uxtb r0, r1 } } break; case USB_DESC_TYPE_STRING: switch ((uint8_t)(req->wValue)) c0d036ec: 2802 cmp r0, #2 c0d036ee: dc3d bgt.n c0d0376c <USBD_GetDescriptor+0x9e> c0d036f0: 2800 cmp r0, #0 c0d036f2: d065 beq.n c0d037c0 <USBD_GetDescriptor+0xf2> c0d036f4: 2801 cmp r0, #1 c0d036f6: d06d beq.n c0d037d4 <USBD_GetDescriptor+0x106> c0d036f8: 2802 cmp r0, #2 c0d036fa: d132 bne.n c0d03762 <USBD_GetDescriptor+0x94> case USBD_IDX_MFC_STR: pbuf = ((GetManufacturerStrDescriptor_t)PIC(pdev->pDesc->GetManufacturerStrDescriptor))(pdev->dev_speed, &len); break; case USBD_IDX_PRODUCT_STR: pbuf = ((GetProductStrDescriptor_t)PIC(pdev->pDesc->GetProductStrDescriptor))(pdev->dev_speed, &len); c0d036fc: 2011 movs r0, #17 c0d036fe: 0100 lsls r0, r0, #4 c0d03700: 5820 ldr r0, [r4, r0] c0d03702: 68c0 ldr r0, [r0, #12] c0d03704: e00e b.n c0d03724 <USBD_GetDescriptor+0x56> c0d03706: 2806 cmp r0, #6 c0d03708: d01e beq.n c0d03748 <USBD_GetDescriptor+0x7a> c0d0370a: 2807 cmp r0, #7 c0d0370c: d026 beq.n c0d0375c <USBD_GetDescriptor+0x8e> c0d0370e: 280f cmp r0, #15 c0d03710: d127 bne.n c0d03762 <USBD_GetDescriptor+0x94> switch (req->wValue >> 8) { #if (USBD_LPM_ENABLED == 1) case USB_DESC_TYPE_BOS: pbuf = ((GetBOSDescriptor_t)PIC(pdev->pDesc->GetBOSDescriptor))(pdev->dev_speed, &len); c0d03712: 2011 movs r0, #17 c0d03714: 0100 lsls r0, r0, #4 c0d03716: 5820 ldr r0, [r4, r0] c0d03718: 69c0 ldr r0, [r0, #28] c0d0371a: e003 b.n c0d03724 <USBD_GetDescriptor+0x56> break; #endif case USB_DESC_TYPE_DEVICE: pbuf = ((GetDeviceDescriptor_t)PIC(pdev->pDesc->GetDeviceDescriptor))(pdev->dev_speed, &len); c0d0371c: 2011 movs r0, #17 c0d0371e: 0100 lsls r0, r0, #4 c0d03720: 5820 ldr r0, [r4, r0] c0d03722: 6800 ldr r0, [r0, #0] c0d03724: f7fe fbc2 bl c0d01eac <pic> c0d03728: 4602 mov r2, r0 c0d0372a: 7c20 ldrb r0, [r4, #16] c0d0372c: a901 add r1, sp, #4 c0d0372e: 4790 blx r2 c0d03730: e034 b.n c0d0379c <USBD_GetDescriptor+0xce> break; case USB_DESC_TYPE_CONFIGURATION: if(pdev->interfacesClass[0].pClass != NULL) { c0d03732: 2045 movs r0, #69 ; 0x45 c0d03734: 0080 lsls r0, r0, #2 c0d03736: 5820 ldr r0, [r4, r0] c0d03738: 2100 movs r1, #0 c0d0373a: 2800 cmp r0, #0 c0d0373c: d02f beq.n c0d0379e <USBD_GetDescriptor+0xd0> if(pdev->dev_speed == USBD_SPEED_HIGH ) c0d0373e: 7c21 ldrb r1, [r4, #16] c0d03740: 2900 cmp r1, #0 c0d03742: d025 beq.n c0d03790 <USBD_GetDescriptor+0xc2> pbuf = (uint8_t *)((GetHSConfigDescriptor_t)PIC(pdev->interfacesClass[0].pClass->GetHSConfigDescriptor))(&len); //pbuf[1] = USB_DESC_TYPE_CONFIGURATION; CONST BUFFER KTHX } else { pbuf = (uint8_t *)((GetFSConfigDescriptor_t)PIC(pdev->interfacesClass[0].pClass->GetFSConfigDescriptor))(&len); c0d03744: 6ac0 ldr r0, [r0, #44] ; 0x2c c0d03746: e024 b.n c0d03792 <USBD_GetDescriptor+0xc4> #endif } break; case USB_DESC_TYPE_DEVICE_QUALIFIER: if(pdev->dev_speed == USBD_SPEED_HIGH && pdev->interfacesClass[0].pClass != NULL ) c0d03748: 7c20 ldrb r0, [r4, #16] c0d0374a: 2800 cmp r0, #0 c0d0374c: d109 bne.n c0d03762 <USBD_GetDescriptor+0x94> c0d0374e: 2045 movs r0, #69 ; 0x45 c0d03750: 0080 lsls r0, r0, #2 c0d03752: 5820 ldr r0, [r4, r0] c0d03754: 2800 cmp r0, #0 c0d03756: d004 beq.n c0d03762 <USBD_GetDescriptor+0x94> { pbuf = (uint8_t *)((GetDeviceQualifierDescriptor_t)PIC(pdev->interfacesClass[0].pClass->GetDeviceQualifierDescriptor))(&len); c0d03758: 6b40 ldr r0, [r0, #52] ; 0x34 c0d0375a: e01a b.n c0d03792 <USBD_GetDescriptor+0xc4> USBD_CtlError(pdev , req); return; } case USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION: if(pdev->dev_speed == USBD_SPEED_HIGH && pdev->interfacesClass[0].pClass != NULL) c0d0375c: 7c20 ldrb r0, [r4, #16] c0d0375e: 2800 cmp r0, #0 c0d03760: d00f beq.n c0d03782 <USBD_GetDescriptor+0xb4> c0d03762: 4620 mov r0, r4 c0d03764: 4629 mov r1, r5 c0d03766: f000 fba9 bl c0d03ebc <USBD_CtlError> c0d0376a: e027 b.n c0d037bc <USBD_GetDescriptor+0xee> c0d0376c: 2803 cmp r0, #3 c0d0376e: d02c beq.n c0d037ca <USBD_GetDescriptor+0xfc> c0d03770: 2804 cmp r0, #4 c0d03772: d034 beq.n c0d037de <USBD_GetDescriptor+0x110> c0d03774: 2805 cmp r0, #5 c0d03776: d1f4 bne.n c0d03762 <USBD_GetDescriptor+0x94> case USBD_IDX_CONFIG_STR: pbuf = ((GetConfigurationStrDescriptor_t)PIC(pdev->pDesc->GetConfigurationStrDescriptor))(pdev->dev_speed, &len); break; case USBD_IDX_INTERFACE_STR: pbuf = ((GetInterfaceStrDescriptor_t)PIC(pdev->pDesc->GetInterfaceStrDescriptor))(pdev->dev_speed, &len); c0d03778: 2011 movs r0, #17 c0d0377a: 0100 lsls r0, r0, #4 c0d0377c: 5820 ldr r0, [r4, r0] c0d0377e: 6980 ldr r0, [r0, #24] c0d03780: e7d0 b.n c0d03724 <USBD_GetDescriptor+0x56> USBD_CtlError(pdev , req); return; } case USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION: if(pdev->dev_speed == USBD_SPEED_HIGH && pdev->interfacesClass[0].pClass != NULL) c0d03782: 2045 movs r0, #69 ; 0x45 c0d03784: 0080 lsls r0, r0, #2 c0d03786: 5820 ldr r0, [r4, r0] c0d03788: 2800 cmp r0, #0 c0d0378a: d0ea beq.n c0d03762 <USBD_GetDescriptor+0x94> { pbuf = (uint8_t *)((GetOtherSpeedConfigDescriptor_t)PIC(pdev->interfacesClass[0].pClass->GetOtherSpeedConfigDescriptor))(&len); c0d0378c: 6b00 ldr r0, [r0, #48] ; 0x30 c0d0378e: e000 b.n c0d03792 <USBD_GetDescriptor+0xc4> case USB_DESC_TYPE_CONFIGURATION: if(pdev->interfacesClass[0].pClass != NULL) { if(pdev->dev_speed == USBD_SPEED_HIGH ) { pbuf = (uint8_t *)((GetHSConfigDescriptor_t)PIC(pdev->interfacesClass[0].pClass->GetHSConfigDescriptor))(&len); c0d03790: 6a80 ldr r0, [r0, #40] ; 0x28 c0d03792: f7fe fb8b bl c0d01eac <pic> c0d03796: 4601 mov r1, r0 c0d03798: a801 add r0, sp, #4 c0d0379a: 4788 blx r1 c0d0379c: 4601 mov r1, r0 c0d0379e: a801 add r0, sp, #4 default: USBD_CtlError(pdev , req); return; } if((len != 0)&& (req->wLength != 0)) c0d037a0: 8802 ldrh r2, [r0, #0] c0d037a2: 2a00 cmp r2, #0 c0d037a4: d00a beq.n c0d037bc <USBD_GetDescriptor+0xee> c0d037a6: 88e8 ldrh r0, [r5, #6] c0d037a8: 2800 cmp r0, #0 c0d037aa: d007 beq.n c0d037bc <USBD_GetDescriptor+0xee> { len = MIN(len , req->wLength); c0d037ac: 4282 cmp r2, r0 c0d037ae: d300 bcc.n c0d037b2 <USBD_GetDescriptor+0xe4> c0d037b0: 4602 mov r2, r0 c0d037b2: a801 add r0, sp, #4 c0d037b4: 8002 strh r2, [r0, #0] // prepare abort if host does not read the whole data //USBD_CtlReceiveStatus(pdev); // start transfer USBD_CtlSendData (pdev, c0d037b6: 4620 mov r0, r4 c0d037b8: f000 fc02 bl c0d03fc0 <USBD_CtlSendData> pbuf, len); } } c0d037bc: b002 add sp, #8 c0d037be: bdb0 pop {r4, r5, r7, pc} case USB_DESC_TYPE_STRING: switch ((uint8_t)(req->wValue)) { case USBD_IDX_LANGID_STR: pbuf = ((GetLangIDStrDescriptor_t)PIC(pdev->pDesc->GetLangIDStrDescriptor))(pdev->dev_speed, &len); c0d037c0: 2011 movs r0, #17 c0d037c2: 0100 lsls r0, r0, #4 c0d037c4: 5820 ldr r0, [r4, r0] c0d037c6: 6840 ldr r0, [r0, #4] c0d037c8: e7ac b.n c0d03724 <USBD_GetDescriptor+0x56> case USBD_IDX_PRODUCT_STR: pbuf = ((GetProductStrDescriptor_t)PIC(pdev->pDesc->GetProductStrDescriptor))(pdev->dev_speed, &len); break; case USBD_IDX_SERIAL_STR: pbuf = ((GetSerialStrDescriptor_t)PIC(pdev->pDesc->GetSerialStrDescriptor))(pdev->dev_speed, &len); c0d037ca: 2011 movs r0, #17 c0d037cc: 0100 lsls r0, r0, #4 c0d037ce: 5820 ldr r0, [r4, r0] c0d037d0: 6900 ldr r0, [r0, #16] c0d037d2: e7a7 b.n c0d03724 <USBD_GetDescriptor+0x56> case USBD_IDX_LANGID_STR: pbuf = ((GetLangIDStrDescriptor_t)PIC(pdev->pDesc->GetLangIDStrDescriptor))(pdev->dev_speed, &len); break; case USBD_IDX_MFC_STR: pbuf = ((GetManufacturerStrDescriptor_t)PIC(pdev->pDesc->GetManufacturerStrDescriptor))(pdev->dev_speed, &len); c0d037d4: 2011 movs r0, #17 c0d037d6: 0100 lsls r0, r0, #4 c0d037d8: 5820 ldr r0, [r4, r0] c0d037da: 6880 ldr r0, [r0, #8] c0d037dc: e7a2 b.n c0d03724 <USBD_GetDescriptor+0x56> case USBD_IDX_SERIAL_STR: pbuf = ((GetSerialStrDescriptor_t)PIC(pdev->pDesc->GetSerialStrDescriptor))(pdev->dev_speed, &len); break; case USBD_IDX_CONFIG_STR: pbuf = ((GetConfigurationStrDescriptor_t)PIC(pdev->pDesc->GetConfigurationStrDescriptor))(pdev->dev_speed, &len); c0d037de: 2011 movs r0, #17 c0d037e0: 0100 lsls r0, r0, #4 c0d037e2: 5820 ldr r0, [r4, r0] c0d037e4: 6940 ldr r0, [r0, #20] c0d037e6: e79d b.n c0d03724 <USBD_GetDescriptor+0x56> c0d037e8 <USBD_SetAddress>: * @param req: usb request * @retval status */ void USBD_SetAddress(USBD_HandleTypeDef *pdev , USBD_SetupReqTypedef *req) { c0d037e8: b570 push {r4, r5, r6, lr} c0d037ea: 4604 mov r4, r0 uint8_t dev_addr; if ((req->wIndex == 0) && (req->wLength == 0)) c0d037ec: 8888 ldrh r0, [r1, #4] c0d037ee: 2800 cmp r0, #0 c0d037f0: d10b bne.n c0d0380a <USBD_SetAddress+0x22> c0d037f2: 88c8 ldrh r0, [r1, #6] c0d037f4: 2800 cmp r0, #0 c0d037f6: d108 bne.n c0d0380a <USBD_SetAddress+0x22> { dev_addr = (uint8_t)(req->wValue) & 0x7F; c0d037f8: 8848 ldrh r0, [r1, #2] c0d037fa: 267f movs r6, #127 ; 0x7f c0d037fc: 4006 ands r6, r0 if (pdev->dev_state == USBD_STATE_CONFIGURED) c0d037fe: 20fc movs r0, #252 ; 0xfc c0d03800: 5c20 ldrb r0, [r4, r0] c0d03802: 4625 mov r5, r4 c0d03804: 35fc adds r5, #252 ; 0xfc c0d03806: 2803 cmp r0, #3 c0d03808: d103 bne.n c0d03812 <USBD_SetAddress+0x2a> c0d0380a: 4620 mov r0, r4 c0d0380c: f000 fb56 bl c0d03ebc <USBD_CtlError> } else { USBD_CtlError(pdev , req); } } c0d03810: bd70 pop {r4, r5, r6, pc} { USBD_CtlError(pdev , req); } else { pdev->dev_address = dev_addr; c0d03812: 20fe movs r0, #254 ; 0xfe c0d03814: 5426 strb r6, [r4, r0] USBD_LL_SetUSBAddress(pdev, dev_addr); c0d03816: b2f1 uxtb r1, r6 c0d03818: 4620 mov r0, r4 c0d0381a: f7ff fd0b bl c0d03234 <USBD_LL_SetUSBAddress> USBD_CtlSendStatus(pdev); c0d0381e: 4620 mov r0, r4 c0d03820: f000 fbf9 bl c0d04016 <USBD_CtlSendStatus> if (dev_addr != 0) c0d03824: 2002 movs r0, #2 c0d03826: 2101 movs r1, #1 c0d03828: 2e00 cmp r6, #0 c0d0382a: d100 bne.n c0d0382e <USBD_SetAddress+0x46> c0d0382c: 4608 mov r0, r1 c0d0382e: 7028 strb r0, [r5, #0] } else { USBD_CtlError(pdev , req); } } c0d03830: bd70 pop {r4, r5, r6, pc} c0d03832 <USBD_SetConfig>: * @param req: usb request * @retval status */ void USBD_SetConfig(USBD_HandleTypeDef *pdev , USBD_SetupReqTypedef *req) { c0d03832: b570 push {r4, r5, r6, lr} c0d03834: 460d mov r5, r1 c0d03836: 4604 mov r4, r0 uint8_t cfgidx; cfgidx = (uint8_t)(req->wValue); c0d03838: 78ae ldrb r6, [r5, #2] if (cfgidx > USBD_MAX_NUM_CONFIGURATION ) c0d0383a: 2e02 cmp r6, #2 c0d0383c: d21d bcs.n c0d0387a <USBD_SetConfig+0x48> { USBD_CtlError(pdev , req); } else { switch (pdev->dev_state) c0d0383e: 20fc movs r0, #252 ; 0xfc c0d03840: 5c21 ldrb r1, [r4, r0] c0d03842: 4620 mov r0, r4 c0d03844: 30fc adds r0, #252 ; 0xfc c0d03846: 2903 cmp r1, #3 c0d03848: d007 beq.n c0d0385a <USBD_SetConfig+0x28> c0d0384a: 2902 cmp r1, #2 c0d0384c: d115 bne.n c0d0387a <USBD_SetConfig+0x48> { case USBD_STATE_ADDRESSED: if (cfgidx) c0d0384e: 2e00 cmp r6, #0 c0d03850: d022 beq.n c0d03898 <USBD_SetConfig+0x66> { pdev->dev_config = cfgidx; c0d03852: 6066 str r6, [r4, #4] pdev->dev_state = USBD_STATE_CONFIGURED; c0d03854: 2103 movs r1, #3 c0d03856: 7001 strb r1, [r0, #0] c0d03858: e009 b.n c0d0386e <USBD_SetConfig+0x3c> } USBD_CtlSendStatus(pdev); break; case USBD_STATE_CONFIGURED: if (cfgidx == 0) c0d0385a: 2e00 cmp r6, #0 c0d0385c: d012 beq.n c0d03884 <USBD_SetConfig+0x52> pdev->dev_state = USBD_STATE_ADDRESSED; pdev->dev_config = cfgidx; USBD_ClrClassConfig(pdev , cfgidx); USBD_CtlSendStatus(pdev); } else if (cfgidx != pdev->dev_config) c0d0385e: 6860 ldr r0, [r4, #4] c0d03860: 4286 cmp r6, r0 c0d03862: d019 beq.n c0d03898 <USBD_SetConfig+0x66> { /* Clear old configuration */ USBD_ClrClassConfig(pdev , pdev->dev_config); c0d03864: b2c1 uxtb r1, r0 c0d03866: 4620 mov r0, r4 c0d03868: f7ff fd8b bl c0d03382 <USBD_ClrClassConfig> /* set new configuration */ pdev->dev_config = cfgidx; c0d0386c: 6066 str r6, [r4, #4] c0d0386e: 4620 mov r0, r4 c0d03870: 4631 mov r1, r6 c0d03872: f7ff fd69 bl c0d03348 <USBD_SetClassConfig> c0d03876: 2802 cmp r0, #2 c0d03878: d10e bne.n c0d03898 <USBD_SetConfig+0x66> c0d0387a: 4620 mov r0, r4 c0d0387c: 4629 mov r1, r5 c0d0387e: f000 fb1d bl c0d03ebc <USBD_CtlError> default: USBD_CtlError(pdev , req); break; } } } c0d03882: bd70 pop {r4, r5, r6, pc} break; case USBD_STATE_CONFIGURED: if (cfgidx == 0) { pdev->dev_state = USBD_STATE_ADDRESSED; c0d03884: 2102 movs r1, #2 c0d03886: 7001 strb r1, [r0, #0] pdev->dev_config = cfgidx; c0d03888: 6066 str r6, [r4, #4] USBD_ClrClassConfig(pdev , cfgidx); c0d0388a: 4620 mov r0, r4 c0d0388c: 4631 mov r1, r6 c0d0388e: f7ff fd78 bl c0d03382 <USBD_ClrClassConfig> USBD_CtlSendStatus(pdev); c0d03892: 4620 mov r0, r4 c0d03894: f000 fbbf bl c0d04016 <USBD_CtlSendStatus> c0d03898: 4620 mov r0, r4 c0d0389a: f000 fbbc bl c0d04016 <USBD_CtlSendStatus> default: USBD_CtlError(pdev , req); break; } } } c0d0389e: bd70 pop {r4, r5, r6, pc} c0d038a0 <USBD_GetConfig>: * @param req: usb request * @retval status */ void USBD_GetConfig(USBD_HandleTypeDef *pdev , USBD_SetupReqTypedef *req) { c0d038a0: b580 push {r7, lr} if (req->wLength != 1) c0d038a2: 88ca ldrh r2, [r1, #6] c0d038a4: 2a01 cmp r2, #1 c0d038a6: d10a bne.n c0d038be <USBD_GetConfig+0x1e> { USBD_CtlError(pdev , req); } else { switch (pdev->dev_state ) c0d038a8: 22fc movs r2, #252 ; 0xfc c0d038aa: 5c82 ldrb r2, [r0, r2] c0d038ac: 2a03 cmp r2, #3 c0d038ae: d009 beq.n c0d038c4 <USBD_GetConfig+0x24> c0d038b0: 2a02 cmp r2, #2 c0d038b2: d104 bne.n c0d038be <USBD_GetConfig+0x1e> { case USBD_STATE_ADDRESSED: pdev->dev_default_config = 0; c0d038b4: 2100 movs r1, #0 c0d038b6: 6081 str r1, [r0, #8] c0d038b8: 4601 mov r1, r0 c0d038ba: 3108 adds r1, #8 c0d038bc: e003 b.n c0d038c6 <USBD_GetConfig+0x26> c0d038be: f000 fafd bl c0d03ebc <USBD_CtlError> default: USBD_CtlError(pdev , req); break; } } } c0d038c2: bd80 pop {r7, pc} 1); break; case USBD_STATE_CONFIGURED: USBD_CtlSendData (pdev, (uint8_t *)&pdev->dev_config, c0d038c4: 1d01 adds r1, r0, #4 c0d038c6: 2201 movs r2, #1 c0d038c8: f000 fb7a bl c0d03fc0 <USBD_CtlSendData> default: USBD_CtlError(pdev , req); break; } } } c0d038cc: bd80 pop {r7, pc} c0d038ce <USBD_GetStatus>: * @param req: usb request * @retval status */ void USBD_GetStatus(USBD_HandleTypeDef *pdev , USBD_SetupReqTypedef *req) { c0d038ce: b5b0 push {r4, r5, r7, lr} c0d038d0: 4604 mov r4, r0 switch (pdev->dev_state) c0d038d2: 20fc movs r0, #252 ; 0xfc c0d038d4: 5c20 ldrb r0, [r4, r0] c0d038d6: 22fe movs r2, #254 ; 0xfe c0d038d8: 4002 ands r2, r0 c0d038da: 2a02 cmp r2, #2 c0d038dc: d116 bne.n c0d0390c <USBD_GetStatus+0x3e> { case USBD_STATE_ADDRESSED: case USBD_STATE_CONFIGURED: #if ( USBD_SELF_POWERED == 1) pdev->dev_config_status = USB_CONFIG_SELF_POWERED; c0d038de: 2001 movs r0, #1 c0d038e0: 60e0 str r0, [r4, #12] #else pdev->dev_config_status = 0; #endif if (pdev->dev_remote_wakeup) USBD_CtlReceiveStatus(pdev); c0d038e2: 2041 movs r0, #65 ; 0x41 c0d038e4: 0080 lsls r0, r0, #2 c0d038e6: 5821 ldr r1, [r4, r0] { case USBD_STATE_ADDRESSED: case USBD_STATE_CONFIGURED: #if ( USBD_SELF_POWERED == 1) pdev->dev_config_status = USB_CONFIG_SELF_POWERED; c0d038e8: 4625 mov r5, r4 c0d038ea: 350c adds r5, #12 c0d038ec: 2003 movs r0, #3 #else pdev->dev_config_status = 0; #endif if (pdev->dev_remote_wakeup) USBD_CtlReceiveStatus(pdev); c0d038ee: 2900 cmp r1, #0 c0d038f0: d005 beq.n c0d038fe <USBD_GetStatus+0x30> c0d038f2: 4620 mov r0, r4 c0d038f4: f000 fb9b bl c0d0402e <USBD_CtlReceiveStatus> c0d038f8: 68e1 ldr r1, [r4, #12] c0d038fa: 2002 movs r0, #2 c0d038fc: 4308 orrs r0, r1 { pdev->dev_config_status |= USB_CONFIG_REMOTE_WAKEUP; c0d038fe: 60e0 str r0, [r4, #12] } USBD_CtlSendData (pdev, c0d03900: 2202 movs r2, #2 c0d03902: 4620 mov r0, r4 c0d03904: 4629 mov r1, r5 c0d03906: f000 fb5b bl c0d03fc0 <USBD_CtlSendData> default : USBD_CtlError(pdev , req); break; } } c0d0390a: bdb0 pop {r4, r5, r7, pc} (uint8_t *)& pdev->dev_config_status, 2); break; default : USBD_CtlError(pdev , req); c0d0390c: 4620 mov r0, r4 c0d0390e: f000 fad5 bl c0d03ebc <USBD_CtlError> break; } } c0d03912: bdb0 pop {r4, r5, r7, pc} c0d03914 <USBD_SetFeature>: * @param req: usb request * @retval status */ void USBD_SetFeature(USBD_HandleTypeDef *pdev , USBD_SetupReqTypedef *req) { c0d03914: b5b0 push {r4, r5, r7, lr} c0d03916: 460d mov r5, r1 c0d03918: 4604 mov r4, r0 if (req->wValue == USB_FEATURE_REMOTE_WAKEUP) c0d0391a: 8868 ldrh r0, [r5, #2] c0d0391c: 2801 cmp r0, #1 c0d0391e: d117 bne.n c0d03950 <USBD_SetFeature+0x3c> { pdev->dev_remote_wakeup = 1; c0d03920: 2041 movs r0, #65 ; 0x41 c0d03922: 0080 lsls r0, r0, #2 c0d03924: 2101 movs r1, #1 c0d03926: 5021 str r1, [r4, r0] if(usbd_is_valid_intf(pdev, LOBYTE(req->wIndex))) { c0d03928: 7928 ldrb r0, [r5, #4] /** @defgroup USBD_REQ_Private_Functions * @{ */ unsigned int usbd_is_valid_intf(USBD_HandleTypeDef *pdev , unsigned int intf) { return intf < USBD_MAX_NUM_INTERFACES && pdev->interfacesClass[intf].pClass != NULL; c0d0392a: 2802 cmp r0, #2 c0d0392c: d80d bhi.n c0d0394a <USBD_SetFeature+0x36> c0d0392e: 00c0 lsls r0, r0, #3 c0d03930: 1820 adds r0, r4, r0 c0d03932: 2145 movs r1, #69 ; 0x45 c0d03934: 0089 lsls r1, r1, #2 c0d03936: 5840 ldr r0, [r0, r1] { if (req->wValue == USB_FEATURE_REMOTE_WAKEUP) { pdev->dev_remote_wakeup = 1; if(usbd_is_valid_intf(pdev, LOBYTE(req->wIndex))) { c0d03938: 2800 cmp r0, #0 c0d0393a: d006 beq.n c0d0394a <USBD_SetFeature+0x36> ((Setup_t)PIC(pdev->interfacesClass[LOBYTE(req->wIndex)].pClass->Setup)) (pdev, req); c0d0393c: 6880 ldr r0, [r0, #8] c0d0393e: f7fe fab5 bl c0d01eac <pic> c0d03942: 4602 mov r2, r0 c0d03944: 4620 mov r0, r4 c0d03946: 4629 mov r1, r5 c0d03948: 4790 blx r2 } USBD_CtlSendStatus(pdev); c0d0394a: 4620 mov r0, r4 c0d0394c: f000 fb63 bl c0d04016 <USBD_CtlSendStatus> } } c0d03950: bdb0 pop {r4, r5, r7, pc} c0d03952 <USBD_ClrFeature>: * @param req: usb request * @retval status */ void USBD_ClrFeature(USBD_HandleTypeDef *pdev , USBD_SetupReqTypedef *req) { c0d03952: b5b0 push {r4, r5, r7, lr} c0d03954: 460d mov r5, r1 c0d03956: 4604 mov r4, r0 switch (pdev->dev_state) c0d03958: 20fc movs r0, #252 ; 0xfc c0d0395a: 5c20 ldrb r0, [r4, r0] c0d0395c: 21fe movs r1, #254 ; 0xfe c0d0395e: 4001 ands r1, r0 c0d03960: 2902 cmp r1, #2 c0d03962: d11b bne.n c0d0399c <USBD_ClrFeature+0x4a> { case USBD_STATE_ADDRESSED: case USBD_STATE_CONFIGURED: if (req->wValue == USB_FEATURE_REMOTE_WAKEUP) c0d03964: 8868 ldrh r0, [r5, #2] c0d03966: 2801 cmp r0, #1 c0d03968: d11c bne.n c0d039a4 <USBD_ClrFeature+0x52> { pdev->dev_remote_wakeup = 0; c0d0396a: 2041 movs r0, #65 ; 0x41 c0d0396c: 0080 lsls r0, r0, #2 c0d0396e: 2100 movs r1, #0 c0d03970: 5021 str r1, [r4, r0] if(usbd_is_valid_intf(pdev, LOBYTE(req->wIndex))) { c0d03972: 7928 ldrb r0, [r5, #4] /** @defgroup USBD_REQ_Private_Functions * @{ */ unsigned int usbd_is_valid_intf(USBD_HandleTypeDef *pdev , unsigned int intf) { return intf < USBD_MAX_NUM_INTERFACES && pdev->interfacesClass[intf].pClass != NULL; c0d03974: 2802 cmp r0, #2 c0d03976: d80d bhi.n c0d03994 <USBD_ClrFeature+0x42> c0d03978: 00c0 lsls r0, r0, #3 c0d0397a: 1820 adds r0, r4, r0 c0d0397c: 2145 movs r1, #69 ; 0x45 c0d0397e: 0089 lsls r1, r1, #2 c0d03980: 5840 ldr r0, [r0, r1] case USBD_STATE_ADDRESSED: case USBD_STATE_CONFIGURED: if (req->wValue == USB_FEATURE_REMOTE_WAKEUP) { pdev->dev_remote_wakeup = 0; if(usbd_is_valid_intf(pdev, LOBYTE(req->wIndex))) { c0d03982: 2800 cmp r0, #0 c0d03984: d006 beq.n c0d03994 <USBD_ClrFeature+0x42> ((Setup_t)PIC(pdev->interfacesClass[LOBYTE(req->wIndex)].pClass->Setup)) (pdev, req); c0d03986: 6880 ldr r0, [r0, #8] c0d03988: f7fe fa90 bl c0d01eac <pic> c0d0398c: 4602 mov r2, r0 c0d0398e: 4620 mov r0, r4 c0d03990: 4629 mov r1, r5 c0d03992: 4790 blx r2 } USBD_CtlSendStatus(pdev); c0d03994: 4620 mov r0, r4 c0d03996: f000 fb3e bl c0d04016 <USBD_CtlSendStatus> default : USBD_CtlError(pdev , req); break; } } c0d0399a: bdb0 pop {r4, r5, r7, pc} USBD_CtlSendStatus(pdev); } break; default : USBD_CtlError(pdev , req); c0d0399c: 4620 mov r0, r4 c0d0399e: 4629 mov r1, r5 c0d039a0: f000 fa8c bl c0d03ebc <USBD_CtlError> break; } } c0d039a4: bdb0 pop {r4, r5, r7, pc} c0d039a6 <USBD_StdItfReq>: * @param pdev: device instance * @param req: usb request * @retval status */ USBD_StatusTypeDef USBD_StdItfReq (USBD_HandleTypeDef *pdev , USBD_SetupReqTypedef *req) { c0d039a6: b5b0 push {r4, r5, r7, lr} c0d039a8: 460d mov r5, r1 c0d039aa: 4604 mov r4, r0 USBD_StatusTypeDef ret = USBD_OK; switch (pdev->dev_state) c0d039ac: 20fc movs r0, #252 ; 0xfc c0d039ae: 5c20 ldrb r0, [r4, r0] c0d039b0: 2803 cmp r0, #3 c0d039b2: d117 bne.n c0d039e4 <USBD_StdItfReq+0x3e> { case USBD_STATE_CONFIGURED: if (usbd_is_valid_intf(pdev, LOBYTE(req->wIndex))) c0d039b4: 7928 ldrb r0, [r5, #4] /** @defgroup USBD_REQ_Private_Functions * @{ */ unsigned int usbd_is_valid_intf(USBD_HandleTypeDef *pdev , unsigned int intf) { return intf < USBD_MAX_NUM_INTERFACES && pdev->interfacesClass[intf].pClass != NULL; c0d039b6: 2802 cmp r0, #2 c0d039b8: d814 bhi.n c0d039e4 <USBD_StdItfReq+0x3e> c0d039ba: 00c0 lsls r0, r0, #3 c0d039bc: 1820 adds r0, r4, r0 c0d039be: 2145 movs r1, #69 ; 0x45 c0d039c0: 0089 lsls r1, r1, #2 c0d039c2: 5840 ldr r0, [r0, r1] switch (pdev->dev_state) { case USBD_STATE_CONFIGURED: if (usbd_is_valid_intf(pdev, LOBYTE(req->wIndex))) c0d039c4: 2800 cmp r0, #0 c0d039c6: d00d beq.n c0d039e4 <USBD_StdItfReq+0x3e> { ((Setup_t)PIC(pdev->interfacesClass[LOBYTE(req->wIndex)].pClass->Setup)) (pdev, req); c0d039c8: 6880 ldr r0, [r0, #8] c0d039ca: f7fe fa6f bl c0d01eac <pic> c0d039ce: 4602 mov r2, r0 c0d039d0: 4620 mov r0, r4 c0d039d2: 4629 mov r1, r5 c0d039d4: 4790 blx r2 if((req->wLength == 0)&& (ret == USBD_OK)) c0d039d6: 88e8 ldrh r0, [r5, #6] c0d039d8: 2800 cmp r0, #0 c0d039da: d107 bne.n c0d039ec <USBD_StdItfReq+0x46> { USBD_CtlSendStatus(pdev); c0d039dc: 4620 mov r0, r4 c0d039de: f000 fb1a bl c0d04016 <USBD_CtlSendStatus> c0d039e2: e003 b.n c0d039ec <USBD_StdItfReq+0x46> c0d039e4: 4620 mov r0, r4 c0d039e6: 4629 mov r1, r5 c0d039e8: f000 fa68 bl c0d03ebc <USBD_CtlError> default: USBD_CtlError(pdev , req); break; } return USBD_OK; c0d039ec: 2000 movs r0, #0 c0d039ee: bdb0 pop {r4, r5, r7, pc} c0d039f0 <USBD_StdEPReq>: * @param pdev: device instance * @param req: usb request * @retval status */ USBD_StatusTypeDef USBD_StdEPReq (USBD_HandleTypeDef *pdev , USBD_SetupReqTypedef *req) { c0d039f0: b570 push {r4, r5, r6, lr} c0d039f2: 460d mov r5, r1 c0d039f4: 4604 mov r4, r0 USBD_StatusTypeDef ret = USBD_OK; USBD_EndpointTypeDef *pep; ep_addr = LOBYTE(req->wIndex); /* Check if it is a class request */ if ((req->bmRequest & 0x60) == 0x20 && usbd_is_valid_intf(pdev, LOBYTE(req->wIndex))) c0d039f6: 7828 ldrb r0, [r5, #0] c0d039f8: 2160 movs r1, #96 ; 0x60 c0d039fa: 4001 ands r1, r0 { uint8_t ep_addr; USBD_StatusTypeDef ret = USBD_OK; USBD_EndpointTypeDef *pep; ep_addr = LOBYTE(req->wIndex); c0d039fc: 792e ldrb r6, [r5, #4] /* Check if it is a class request */ if ((req->bmRequest & 0x60) == 0x20 && usbd_is_valid_intf(pdev, LOBYTE(req->wIndex))) c0d039fe: 2920 cmp r1, #32 c0d03a00: d110 bne.n c0d03a24 <USBD_StdEPReq+0x34> /** @defgroup USBD_REQ_Private_Functions * @{ */ unsigned int usbd_is_valid_intf(USBD_HandleTypeDef *pdev , unsigned int intf) { return intf < USBD_MAX_NUM_INTERFACES && pdev->interfacesClass[intf].pClass != NULL; c0d03a02: 2e02 cmp r6, #2 c0d03a04: d80e bhi.n c0d03a24 <USBD_StdEPReq+0x34> c0d03a06: 00f0 lsls r0, r6, #3 c0d03a08: 1820 adds r0, r4, r0 c0d03a0a: 2145 movs r1, #69 ; 0x45 c0d03a0c: 0089 lsls r1, r1, #2 c0d03a0e: 5840 ldr r0, [r0, r1] USBD_StatusTypeDef ret = USBD_OK; USBD_EndpointTypeDef *pep; ep_addr = LOBYTE(req->wIndex); /* Check if it is a class request */ if ((req->bmRequest & 0x60) == 0x20 && usbd_is_valid_intf(pdev, LOBYTE(req->wIndex))) c0d03a10: 2800 cmp r0, #0 c0d03a12: d007 beq.n c0d03a24 <USBD_StdEPReq+0x34> { ((Setup_t)PIC(pdev->interfacesClass[LOBYTE(req->wIndex)].pClass->Setup)) (pdev, req); c0d03a14: 6880 ldr r0, [r0, #8] c0d03a16: f7fe fa49 bl c0d01eac <pic> c0d03a1a: 4602 mov r2, r0 c0d03a1c: 4620 mov r0, r4 c0d03a1e: 4629 mov r1, r5 c0d03a20: 4790 blx r2 c0d03a22: e06e b.n c0d03b02 <USBD_StdEPReq+0x112> return USBD_OK; } switch (req->bRequest) c0d03a24: 7868 ldrb r0, [r5, #1] c0d03a26: 2800 cmp r0, #0 c0d03a28: d017 beq.n c0d03a5a <USBD_StdEPReq+0x6a> c0d03a2a: 2801 cmp r0, #1 c0d03a2c: d01e beq.n c0d03a6c <USBD_StdEPReq+0x7c> c0d03a2e: 2803 cmp r0, #3 c0d03a30: d167 bne.n c0d03b02 <USBD_StdEPReq+0x112> { case USB_REQ_SET_FEATURE : switch (pdev->dev_state) c0d03a32: 20fc movs r0, #252 ; 0xfc c0d03a34: 5c20 ldrb r0, [r4, r0] c0d03a36: 2803 cmp r0, #3 c0d03a38: d11c bne.n c0d03a74 <USBD_StdEPReq+0x84> USBD_LL_StallEP(pdev , ep_addr); } break; case USBD_STATE_CONFIGURED: if (req->wValue == USB_FEATURE_EP_HALT) c0d03a3a: 8868 ldrh r0, [r5, #2] c0d03a3c: 2800 cmp r0, #0 c0d03a3e: d108 bne.n c0d03a52 <USBD_StdEPReq+0x62> { if ((ep_addr != 0x00) && (ep_addr != 0x80)) c0d03a40: 2080 movs r0, #128 ; 0x80 c0d03a42: 4330 orrs r0, r6 c0d03a44: 2880 cmp r0, #128 ; 0x80 c0d03a46: d004 beq.n c0d03a52 <USBD_StdEPReq+0x62> { USBD_LL_StallEP(pdev , ep_addr); c0d03a48: 4620 mov r0, r4 c0d03a4a: 4631 mov r1, r6 c0d03a4c: f7ff fb96 bl c0d0317c <USBD_LL_StallEP> } c0d03a50: 792e ldrb r6, [r5, #4] /** @defgroup USBD_REQ_Private_Functions * @{ */ unsigned int usbd_is_valid_intf(USBD_HandleTypeDef *pdev , unsigned int intf) { return intf < USBD_MAX_NUM_INTERFACES && pdev->interfacesClass[intf].pClass != NULL; c0d03a52: 2e02 cmp r6, #2 c0d03a54: d852 bhi.n c0d03afc <USBD_StdEPReq+0x10c> c0d03a56: 00f0 lsls r0, r6, #3 c0d03a58: e043 b.n c0d03ae2 <USBD_StdEPReq+0xf2> break; } break; case USB_REQ_GET_STATUS: switch (pdev->dev_state) c0d03a5a: 20fc movs r0, #252 ; 0xfc c0d03a5c: 5c20 ldrb r0, [r4, r0] c0d03a5e: 2803 cmp r0, #3 c0d03a60: d018 beq.n c0d03a94 <USBD_StdEPReq+0xa4> c0d03a62: 2802 cmp r0, #2 c0d03a64: d111 bne.n c0d03a8a <USBD_StdEPReq+0x9a> { case USBD_STATE_ADDRESSED: if ((ep_addr & 0x7F) != 0x00) c0d03a66: 0670 lsls r0, r6, #25 c0d03a68: d10a bne.n c0d03a80 <USBD_StdEPReq+0x90> c0d03a6a: e04a b.n c0d03b02 <USBD_StdEPReq+0x112> } break; case USB_REQ_CLEAR_FEATURE : switch (pdev->dev_state) c0d03a6c: 20fc movs r0, #252 ; 0xfc c0d03a6e: 5c20 ldrb r0, [r4, r0] c0d03a70: 2803 cmp r0, #3 c0d03a72: d029 beq.n c0d03ac8 <USBD_StdEPReq+0xd8> c0d03a74: 2802 cmp r0, #2 c0d03a76: d108 bne.n c0d03a8a <USBD_StdEPReq+0x9a> c0d03a78: 2080 movs r0, #128 ; 0x80 c0d03a7a: 4330 orrs r0, r6 c0d03a7c: 2880 cmp r0, #128 ; 0x80 c0d03a7e: d040 beq.n c0d03b02 <USBD_StdEPReq+0x112> c0d03a80: 4620 mov r0, r4 c0d03a82: 4631 mov r1, r6 c0d03a84: f7ff fb7a bl c0d0317c <USBD_LL_StallEP> c0d03a88: e03b b.n c0d03b02 <USBD_StdEPReq+0x112> c0d03a8a: 4620 mov r0, r4 c0d03a8c: 4629 mov r1, r5 c0d03a8e: f000 fa15 bl c0d03ebc <USBD_CtlError> c0d03a92: e036 b.n c0d03b02 <USBD_StdEPReq+0x112> USBD_LL_StallEP(pdev , ep_addr); } break; case USBD_STATE_CONFIGURED: pep = ((ep_addr & 0x80) == 0x80) ? &pdev->ep_in[ep_addr & 0x7F]:\ c0d03a94: 4625 mov r5, r4 c0d03a96: 3514 adds r5, #20 &pdev->ep_out[ep_addr & 0x7F]; c0d03a98: 4620 mov r0, r4 c0d03a9a: 3084 adds r0, #132 ; 0x84 USBD_LL_StallEP(pdev , ep_addr); } break; case USBD_STATE_CONFIGURED: pep = ((ep_addr & 0x80) == 0x80) ? &pdev->ep_in[ep_addr & 0x7F]:\ c0d03a9c: 2180 movs r1, #128 ; 0x80 c0d03a9e: 420e tst r6, r1 c0d03aa0: d100 bne.n c0d03aa4 <USBD_StdEPReq+0xb4> c0d03aa2: 4605 mov r5, r0 &pdev->ep_out[ep_addr & 0x7F]; if(USBD_LL_IsStallEP(pdev, ep_addr)) c0d03aa4: 4620 mov r0, r4 c0d03aa6: 4631 mov r1, r6 c0d03aa8: f7ff fbb2 bl c0d03210 <USBD_LL_IsStallEP> c0d03aac: 2101 movs r1, #1 c0d03aae: 2800 cmp r0, #0 c0d03ab0: d100 bne.n c0d03ab4 <USBD_StdEPReq+0xc4> c0d03ab2: 4601 mov r1, r0 c0d03ab4: 207f movs r0, #127 ; 0x7f c0d03ab6: 4006 ands r6, r0 c0d03ab8: 0130 lsls r0, r6, #4 c0d03aba: 5029 str r1, [r5, r0] c0d03abc: 1829 adds r1, r5, r0 else { pep->status = 0x0000; } USBD_CtlSendData (pdev, c0d03abe: 2202 movs r2, #2 c0d03ac0: 4620 mov r0, r4 c0d03ac2: f000 fa7d bl c0d03fc0 <USBD_CtlSendData> c0d03ac6: e01c b.n c0d03b02 <USBD_StdEPReq+0x112> USBD_LL_StallEP(pdev , ep_addr); } break; case USBD_STATE_CONFIGURED: if (req->wValue == USB_FEATURE_EP_HALT) c0d03ac8: 8868 ldrh r0, [r5, #2] c0d03aca: 2800 cmp r0, #0 c0d03acc: d119 bne.n c0d03b02 <USBD_StdEPReq+0x112> { if ((ep_addr & 0x7F) != 0x00) c0d03ace: 0670 lsls r0, r6, #25 c0d03ad0: d014 beq.n c0d03afc <USBD_StdEPReq+0x10c> { USBD_LL_ClearStallEP(pdev , ep_addr); c0d03ad2: 4620 mov r0, r4 c0d03ad4: 4631 mov r1, r6 c0d03ad6: f7ff fb77 bl c0d031c8 <USBD_LL_ClearStallEP> if(usbd_is_valid_intf(pdev, LOBYTE(req->wIndex))) { c0d03ada: 7928 ldrb r0, [r5, #4] /** @defgroup USBD_REQ_Private_Functions * @{ */ unsigned int usbd_is_valid_intf(USBD_HandleTypeDef *pdev , unsigned int intf) { return intf < USBD_MAX_NUM_INTERFACES && pdev->interfacesClass[intf].pClass != NULL; c0d03adc: 2802 cmp r0, #2 c0d03ade: d80d bhi.n c0d03afc <USBD_StdEPReq+0x10c> c0d03ae0: 00c0 lsls r0, r0, #3 c0d03ae2: 1820 adds r0, r4, r0 c0d03ae4: 2145 movs r1, #69 ; 0x45 c0d03ae6: 0089 lsls r1, r1, #2 c0d03ae8: 5840 ldr r0, [r0, r1] c0d03aea: 2800 cmp r0, #0 c0d03aec: d006 beq.n c0d03afc <USBD_StdEPReq+0x10c> c0d03aee: 6880 ldr r0, [r0, #8] c0d03af0: f7fe f9dc bl c0d01eac <pic> c0d03af4: 4602 mov r2, r0 c0d03af6: 4620 mov r0, r4 c0d03af8: 4629 mov r1, r5 c0d03afa: 4790 blx r2 c0d03afc: 4620 mov r0, r4 c0d03afe: f000 fa8a bl c0d04016 <USBD_CtlSendStatus> default: break; } return ret; } c0d03b02: 2000 movs r0, #0 c0d03b04: bd70 pop {r4, r5, r6, pc} c0d03b06 <USBD_ParseSetupRequest>: * @retval None */ void USBD_ParseSetupRequest(USBD_SetupReqTypedef *req, uint8_t *pdata) { req->bmRequest = *(uint8_t *) (pdata); c0d03b06: 780a ldrb r2, [r1, #0] c0d03b08: 7002 strb r2, [r0, #0] req->bRequest = *(uint8_t *) (pdata + 1); c0d03b0a: 784a ldrb r2, [r1, #1] c0d03b0c: 7042 strb r2, [r0, #1] req->wValue = SWAPBYTE (pdata + 2); c0d03b0e: 788a ldrb r2, [r1, #2] c0d03b10: 78cb ldrb r3, [r1, #3] c0d03b12: 021b lsls r3, r3, #8 c0d03b14: 4313 orrs r3, r2 c0d03b16: 8043 strh r3, [r0, #2] req->wIndex = SWAPBYTE (pdata + 4); c0d03b18: 790a ldrb r2, [r1, #4] c0d03b1a: 794b ldrb r3, [r1, #5] c0d03b1c: 021b lsls r3, r3, #8 c0d03b1e: 4313 orrs r3, r2 c0d03b20: 8083 strh r3, [r0, #4] req->wLength = SWAPBYTE (pdata + 6); c0d03b22: 798a ldrb r2, [r1, #6] c0d03b24: 79c9 ldrb r1, [r1, #7] c0d03b26: 0209 lsls r1, r1, #8 c0d03b28: 4311 orrs r1, r2 c0d03b2a: 80c1 strh r1, [r0, #6] } c0d03b2c: 4770 bx lr c0d03b2e <USBD_CtlStall>: * @param pdev: device instance * @param req: usb request * @retval None */ void USBD_CtlStall( USBD_HandleTypeDef *pdev) { c0d03b2e: b510 push {r4, lr} c0d03b30: 4604 mov r4, r0 USBD_LL_StallEP(pdev , 0x80); c0d03b32: 2180 movs r1, #128 ; 0x80 c0d03b34: f7ff fb22 bl c0d0317c <USBD_LL_StallEP> USBD_LL_StallEP(pdev , 0); c0d03b38: 2100 movs r1, #0 c0d03b3a: 4620 mov r0, r4 c0d03b3c: f7ff fb1e bl c0d0317c <USBD_LL_StallEP> } c0d03b40: bd10 pop {r4, pc} c0d03b42 <USBD_HID_Setup>: * @param req: usb requests * @retval status */ uint8_t USBD_HID_Setup (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) { c0d03b42: b5f0 push {r4, r5, r6, r7, lr} c0d03b44: b083 sub sp, #12 c0d03b46: 460d mov r5, r1 c0d03b48: 4604 mov r4, r0 c0d03b4a: a802 add r0, sp, #8 c0d03b4c: 2700 movs r7, #0 uint16_t len = 0; c0d03b4e: 8007 strh r7, [r0, #0] c0d03b50: a801 add r0, sp, #4 uint8_t *pbuf = NULL; uint8_t val = 0; c0d03b52: 7007 strb r7, [r0, #0] switch (req->bmRequest & USB_REQ_TYPE_MASK) c0d03b54: 7829 ldrb r1, [r5, #0] c0d03b56: 2060 movs r0, #96 ; 0x60 c0d03b58: 4008 ands r0, r1 c0d03b5a: 2800 cmp r0, #0 c0d03b5c: d010 beq.n c0d03b80 <USBD_HID_Setup+0x3e> c0d03b5e: 2820 cmp r0, #32 c0d03b60: d138 bne.n c0d03bd4 <USBD_HID_Setup+0x92> c0d03b62: 7868 ldrb r0, [r5, #1] { case USB_REQ_TYPE_CLASS : switch (req->bRequest) c0d03b64: 4601 mov r1, r0 c0d03b66: 390a subs r1, #10 c0d03b68: 2902 cmp r1, #2 c0d03b6a: d333 bcc.n c0d03bd4 <USBD_HID_Setup+0x92> c0d03b6c: 2802 cmp r0, #2 c0d03b6e: d01c beq.n c0d03baa <USBD_HID_Setup+0x68> c0d03b70: 2803 cmp r0, #3 c0d03b72: d01a beq.n c0d03baa <USBD_HID_Setup+0x68> (uint8_t *)&val, 1); break; default: USBD_CtlError (pdev, req); c0d03b74: 4620 mov r0, r4 c0d03b76: 4629 mov r1, r5 c0d03b78: f000 f9a0 bl c0d03ebc <USBD_CtlError> c0d03b7c: 2702 movs r7, #2 c0d03b7e: e029 b.n c0d03bd4 <USBD_HID_Setup+0x92> return USBD_FAIL; } break; case USB_REQ_TYPE_STANDARD: switch (req->bRequest) c0d03b80: 7868 ldrb r0, [r5, #1] c0d03b82: 280b cmp r0, #11 c0d03b84: d014 beq.n c0d03bb0 <USBD_HID_Setup+0x6e> c0d03b86: 280a cmp r0, #10 c0d03b88: d00f beq.n c0d03baa <USBD_HID_Setup+0x68> c0d03b8a: 2806 cmp r0, #6 c0d03b8c: d122 bne.n c0d03bd4 <USBD_HID_Setup+0x92> { case USB_REQ_GET_DESCRIPTOR: // 0x22 if( req->wValue >> 8 == HID_REPORT_DESC) c0d03b8e: 8868 ldrh r0, [r5, #2] c0d03b90: 0a00 lsrs r0, r0, #8 c0d03b92: 2700 movs r7, #0 c0d03b94: 2821 cmp r0, #33 ; 0x21 c0d03b96: d00f beq.n c0d03bb8 <USBD_HID_Setup+0x76> c0d03b98: 2822 cmp r0, #34 ; 0x22 //USBD_CtlReceiveStatus(pdev); USBD_CtlSendData (pdev, pbuf, len); c0d03b9a: 463a mov r2, r7 c0d03b9c: 4639 mov r1, r7 c0d03b9e: d116 bne.n c0d03bce <USBD_HID_Setup+0x8c> c0d03ba0: ae02 add r6, sp, #8 { case USB_REQ_GET_DESCRIPTOR: // 0x22 if( req->wValue >> 8 == HID_REPORT_DESC) { pbuf = USBD_HID_GetReportDescriptor_impl(&len); c0d03ba2: 4630 mov r0, r6 c0d03ba4: f000 f858 bl c0d03c58 <USBD_HID_GetReportDescriptor_impl> c0d03ba8: e00a b.n c0d03bc0 <USBD_HID_Setup+0x7e> c0d03baa: a901 add r1, sp, #4 c0d03bac: 2201 movs r2, #1 c0d03bae: e00e b.n c0d03bce <USBD_HID_Setup+0x8c> len); break; case USB_REQ_SET_INTERFACE : //hhid->AltSetting = (uint8_t)(req->wValue); USBD_CtlSendStatus(pdev); c0d03bb0: 4620 mov r0, r4 c0d03bb2: f000 fa30 bl c0d04016 <USBD_CtlSendStatus> c0d03bb6: e00d b.n c0d03bd4 <USBD_HID_Setup+0x92> c0d03bb8: ae02 add r6, sp, #8 len = MIN(len , req->wLength); } // 0x21 else if( req->wValue >> 8 == HID_DESCRIPTOR_TYPE) { pbuf = USBD_HID_GetHidDescriptor_impl(&len); c0d03bba: 4630 mov r0, r6 c0d03bbc: f000 f832 bl c0d03c24 <USBD_HID_GetHidDescriptor_impl> c0d03bc0: 4601 mov r1, r0 c0d03bc2: 8832 ldrh r2, [r6, #0] c0d03bc4: 88e8 ldrh r0, [r5, #6] c0d03bc6: 4282 cmp r2, r0 c0d03bc8: d300 bcc.n c0d03bcc <USBD_HID_Setup+0x8a> c0d03bca: 4602 mov r2, r0 c0d03bcc: 8032 strh r2, [r6, #0] c0d03bce: 4620 mov r0, r4 c0d03bd0: f000 f9f6 bl c0d03fc0 <USBD_CtlSendData> } } return USBD_OK; } c0d03bd4: b2f8 uxtb r0, r7 c0d03bd6: b003 add sp, #12 c0d03bd8: bdf0 pop {r4, r5, r6, r7, pc} c0d03bda <USBD_HID_Init>: * @param cfgidx: Configuration index * @retval status */ uint8_t USBD_HID_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx) { c0d03bda: b5f0 push {r4, r5, r6, r7, lr} c0d03bdc: b081 sub sp, #4 c0d03bde: 4604 mov r4, r0 UNUSED(cfgidx); /* Open EP IN */ USBD_LL_OpenEP(pdev, c0d03be0: 2182 movs r1, #130 ; 0x82 c0d03be2: 2603 movs r6, #3 c0d03be4: 2540 movs r5, #64 ; 0x40 c0d03be6: 4632 mov r2, r6 c0d03be8: 462b mov r3, r5 c0d03bea: f7ff fa8b bl c0d03104 <USBD_LL_OpenEP> c0d03bee: 2702 movs r7, #2 HID_EPIN_ADDR, USBD_EP_TYPE_INTR, HID_EPIN_SIZE); /* Open EP OUT */ USBD_LL_OpenEP(pdev, c0d03bf0: 4620 mov r0, r4 c0d03bf2: 4639 mov r1, r7 c0d03bf4: 4632 mov r2, r6 c0d03bf6: 462b mov r3, r5 c0d03bf8: f7ff fa84 bl c0d03104 <USBD_LL_OpenEP> HID_EPOUT_ADDR, USBD_EP_TYPE_INTR, HID_EPOUT_SIZE); /* Prepare Out endpoint to receive 1st packet */ USBD_LL_PrepareReceive(pdev, HID_EPOUT_ADDR, HID_EPOUT_SIZE); c0d03bfc: 4620 mov r0, r4 c0d03bfe: 4639 mov r1, r7 c0d03c00: 462a mov r2, r5 c0d03c02: f7ff fb42 bl c0d0328a <USBD_LL_PrepareReceive> USBD_LL_Transmit (pdev, HID_EPIN_ADDR, NULL, 0); */ return USBD_OK; c0d03c06: 2000 movs r0, #0 c0d03c08: b001 add sp, #4 c0d03c0a: bdf0 pop {r4, r5, r6, r7, pc} c0d03c0c <USBD_HID_DeInit>: * @param cfgidx: Configuration index * @retval status */ uint8_t USBD_HID_DeInit (USBD_HandleTypeDef *pdev, uint8_t cfgidx) { c0d03c0c: b510 push {r4, lr} c0d03c0e: 4604 mov r4, r0 UNUSED(cfgidx); /* Close HID EP IN */ USBD_LL_CloseEP(pdev, c0d03c10: 2182 movs r1, #130 ; 0x82 c0d03c12: f7ff fa9d bl c0d03150 <USBD_LL_CloseEP> HID_EPIN_ADDR); /* Close HID EP OUT */ USBD_LL_CloseEP(pdev, c0d03c16: 2102 movs r1, #2 c0d03c18: 4620 mov r0, r4 c0d03c1a: f7ff fa99 bl c0d03150 <USBD_LL_CloseEP> HID_EPOUT_ADDR); return USBD_OK; c0d03c1e: 2000 movs r0, #0 c0d03c20: bd10 pop {r4, pc} ... c0d03c24 <USBD_HID_GetHidDescriptor_impl>: *length = sizeof (USBD_CfgDesc); return (uint8_t*)USBD_CfgDesc; } uint8_t* USBD_HID_GetHidDescriptor_impl(uint16_t* len) { switch (USBD_Device.request.wIndex&0xFF) { c0d03c24: 2143 movs r1, #67 ; 0x43 c0d03c26: 0089 lsls r1, r1, #2 c0d03c28: 4a08 ldr r2, [pc, #32] ; (c0d03c4c <USBD_HID_GetHidDescriptor_impl+0x28>) c0d03c2a: 5c51 ldrb r1, [r2, r1] c0d03c2c: 2209 movs r2, #9 c0d03c2e: 2900 cmp r1, #0 c0d03c30: d004 beq.n c0d03c3c <USBD_HID_GetHidDescriptor_impl+0x18> c0d03c32: 2901 cmp r1, #1 c0d03c34: d105 bne.n c0d03c42 <USBD_HID_GetHidDescriptor_impl+0x1e> c0d03c36: 4907 ldr r1, [pc, #28] ; (c0d03c54 <USBD_HID_GetHidDescriptor_impl+0x30>) c0d03c38: 4479 add r1, pc c0d03c3a: e004 b.n c0d03c46 <USBD_HID_GetHidDescriptor_impl+0x22> c0d03c3c: 4904 ldr r1, [pc, #16] ; (c0d03c50 <USBD_HID_GetHidDescriptor_impl+0x2c>) c0d03c3e: 4479 add r1, pc c0d03c40: e001 b.n c0d03c46 <USBD_HID_GetHidDescriptor_impl+0x22> c0d03c42: 2200 movs r2, #0 c0d03c44: 4611 mov r1, r2 c0d03c46: 8002 strh r2, [r0, #0] *len = sizeof(USBD_HID_Desc); return (uint8_t*)USBD_HID_Desc; } *len = 0; return 0; } c0d03c48: 4608 mov r0, r1 c0d03c4a: 4770 bx lr c0d03c4c: 20001c8c .word 0x20001c8c c0d03c50: 00000ade .word 0x00000ade c0d03c54: 00000ad8 .word 0x00000ad8 c0d03c58 <USBD_HID_GetReportDescriptor_impl>: uint8_t* USBD_HID_GetReportDescriptor_impl(uint16_t* len) { c0d03c58: b5f0 push {r4, r5, r6, r7, lr} c0d03c5a: b081 sub sp, #4 c0d03c5c: 4602 mov r2, r0 switch (USBD_Device.request.wIndex&0xFF) { c0d03c5e: 2043 movs r0, #67 ; 0x43 c0d03c60: 0080 lsls r0, r0, #2 c0d03c62: 4914 ldr r1, [pc, #80] ; (c0d03cb4 <USBD_HID_GetReportDescriptor_impl+0x5c>) c0d03c64: 5c08 ldrb r0, [r1, r0] c0d03c66: 2422 movs r4, #34 ; 0x22 c0d03c68: 2800 cmp r0, #0 c0d03c6a: d01a beq.n c0d03ca2 <USBD_HID_GetReportDescriptor_impl+0x4a> c0d03c6c: 2801 cmp r0, #1 c0d03c6e: d11b bne.n c0d03ca8 <USBD_HID_GetReportDescriptor_impl+0x50> #ifdef HAVE_IO_U2F case U2F_INTF: // very dirty work due to lack of callback when USB_HID_Init is called USBD_LL_OpenEP(&USBD_Device, c0d03c70: 4810 ldr r0, [pc, #64] ; (c0d03cb4 <USBD_HID_GetReportDescriptor_impl+0x5c>) c0d03c72: 2181 movs r1, #129 ; 0x81 c0d03c74: 2703 movs r7, #3 c0d03c76: 2640 movs r6, #64 ; 0x40 c0d03c78: 9200 str r2, [sp, #0] c0d03c7a: 463a mov r2, r7 c0d03c7c: 4633 mov r3, r6 c0d03c7e: f7ff fa41 bl c0d03104 <USBD_LL_OpenEP> c0d03c82: 2501 movs r5, #1 U2F_EPIN_ADDR, USBD_EP_TYPE_INTR, U2F_EPIN_SIZE); USBD_LL_OpenEP(&USBD_Device, c0d03c84: 480b ldr r0, [pc, #44] ; (c0d03cb4 <USBD_HID_GetReportDescriptor_impl+0x5c>) c0d03c86: 4629 mov r1, r5 c0d03c88: 463a mov r2, r7 c0d03c8a: 4633 mov r3, r6 c0d03c8c: f7ff fa3a bl c0d03104 <USBD_LL_OpenEP> U2F_EPOUT_ADDR, USBD_EP_TYPE_INTR, U2F_EPOUT_SIZE); /* Prepare Out endpoint to receive 1st packet */ USBD_LL_PrepareReceive(&USBD_Device, U2F_EPOUT_ADDR, U2F_EPOUT_SIZE); c0d03c90: 4808 ldr r0, [pc, #32] ; (c0d03cb4 <USBD_HID_GetReportDescriptor_impl+0x5c>) c0d03c92: 4629 mov r1, r5 c0d03c94: 4632 mov r2, r6 c0d03c96: f7ff faf8 bl c0d0328a <USBD_LL_PrepareReceive> c0d03c9a: 9a00 ldr r2, [sp, #0] c0d03c9c: 4807 ldr r0, [pc, #28] ; (c0d03cbc <USBD_HID_GetReportDescriptor_impl+0x64>) c0d03c9e: 4478 add r0, pc c0d03ca0: e004 b.n c0d03cac <USBD_HID_GetReportDescriptor_impl+0x54> c0d03ca2: 4805 ldr r0, [pc, #20] ; (c0d03cb8 <USBD_HID_GetReportDescriptor_impl+0x60>) c0d03ca4: 4478 add r0, pc c0d03ca6: e001 b.n c0d03cac <USBD_HID_GetReportDescriptor_impl+0x54> c0d03ca8: 2400 movs r4, #0 c0d03caa: 4620 mov r0, r4 c0d03cac: 8014 strh r4, [r2, #0] *len = sizeof(HID_ReportDesc); return (uint8_t*)HID_ReportDesc; } *len = 0; return 0; } c0d03cae: b001 add sp, #4 c0d03cb0: bdf0 pop {r4, r5, r6, r7, pc} c0d03cb2: 46c0 nop ; (mov r8, r8) c0d03cb4: 20001c8c .word 0x20001c8c c0d03cb8: 00000aa3 .word 0x00000aa3 c0d03cbc: 00000a87 .word 0x00000a87 c0d03cc0 <USBD_U2F_Init>: * @param cfgidx: Configuration index * @retval status */ uint8_t USBD_U2F_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx) { c0d03cc0: b5f0 push {r4, r5, r6, r7, lr} c0d03cc2: b081 sub sp, #4 c0d03cc4: 4604 mov r4, r0 UNUSED(cfgidx); /* Open EP IN */ USBD_LL_OpenEP(pdev, c0d03cc6: 2181 movs r1, #129 ; 0x81 c0d03cc8: 2603 movs r6, #3 c0d03cca: 2540 movs r5, #64 ; 0x40 c0d03ccc: 4632 mov r2, r6 c0d03cce: 462b mov r3, r5 c0d03cd0: f7ff fa18 bl c0d03104 <USBD_LL_OpenEP> c0d03cd4: 2701 movs r7, #1 U2F_EPIN_ADDR, USBD_EP_TYPE_INTR, U2F_EPIN_SIZE); /* Open EP OUT */ USBD_LL_OpenEP(pdev, c0d03cd6: 4620 mov r0, r4 c0d03cd8: 4639 mov r1, r7 c0d03cda: 4632 mov r2, r6 c0d03cdc: 462b mov r3, r5 c0d03cde: f7ff fa11 bl c0d03104 <USBD_LL_OpenEP> U2F_EPOUT_ADDR, USBD_EP_TYPE_INTR, U2F_EPOUT_SIZE); /* Prepare Out endpoint to receive 1st packet */ USBD_LL_PrepareReceive(pdev, U2F_EPOUT_ADDR, U2F_EPOUT_SIZE); c0d03ce2: 4620 mov r0, r4 c0d03ce4: 4639 mov r1, r7 c0d03ce6: 462a mov r2, r5 c0d03ce8: f7ff facf bl c0d0328a <USBD_LL_PrepareReceive> return USBD_OK; c0d03cec: 2000 movs r0, #0 c0d03cee: b001 add sp, #4 c0d03cf0: bdf0 pop {r4, r5, r6, r7, pc} ... c0d03cf4 <USBD_U2F_DataIn_impl>: } uint8_t USBD_U2F_DataIn_impl (USBD_HandleTypeDef *pdev, uint8_t epnum) { c0d03cf4: b580 push {r7, lr} UNUSED(pdev); // only the data hid endpoint will receive data switch (epnum) { c0d03cf6: 2901 cmp r1, #1 c0d03cf8: d103 bne.n c0d03d02 <USBD_U2F_DataIn_impl+0xe> // FIDO endpoint case (U2F_EPIN_ADDR&0x7F): // advance the u2f sending machine state u2f_transport_sent(&G_io_u2f, U2F_MEDIA_USB); c0d03cfa: 4803 ldr r0, [pc, #12] ; (c0d03d08 <USBD_U2F_DataIn_impl+0x14>) c0d03cfc: 2101 movs r1, #1 c0d03cfe: f7fe fc39 bl c0d02574 <u2f_transport_sent> break; } return USBD_OK; c0d03d02: 2000 movs r0, #0 c0d03d04: bd80 pop {r7, pc} c0d03d06: 46c0 nop ; (mov r8, r8) c0d03d08: 20001a7c .word 0x20001a7c c0d03d0c <USBD_U2F_DataOut_impl>: } uint8_t USBD_U2F_DataOut_impl (USBD_HandleTypeDef *pdev, uint8_t epnum, uint8_t* buffer) { c0d03d0c: b5b0 push {r4, r5, r7, lr} c0d03d0e: 4614 mov r4, r2 switch (epnum) { c0d03d10: 2901 cmp r1, #1 c0d03d12: d10d bne.n c0d03d30 <USBD_U2F_DataOut_impl+0x24> c0d03d14: 2501 movs r5, #1 // FIDO endpoint case (U2F_EPOUT_ADDR&0x7F): USBD_LL_PrepareReceive(pdev, U2F_EPOUT_ADDR , U2F_EPOUT_SIZE); c0d03d16: 2240 movs r2, #64 ; 0x40 c0d03d18: 4629 mov r1, r5 c0d03d1a: f7ff fab6 bl c0d0328a <USBD_LL_PrepareReceive> u2f_transport_received(&G_io_u2f, buffer, io_seproxyhal_get_ep_rx_size(U2F_EPOUT_ADDR), U2F_MEDIA_USB); c0d03d1e: 4628 mov r0, r5 c0d03d20: f7fd f8dc bl c0d00edc <io_seproxyhal_get_ep_rx_size> c0d03d24: 4602 mov r2, r0 c0d03d26: 4803 ldr r0, [pc, #12] ; (c0d03d34 <USBD_U2F_DataOut_impl+0x28>) c0d03d28: 4621 mov r1, r4 c0d03d2a: 462b mov r3, r5 c0d03d2c: f7fe fd5c bl c0d027e8 <u2f_transport_received> break; } return USBD_OK; c0d03d30: 2000 movs r0, #0 c0d03d32: bdb0 pop {r4, r5, r7, pc} c0d03d34: 20001a7c .word 0x20001a7c c0d03d38 <USBD_HID_DataIn_impl>: } #endif // HAVE_IO_U2F uint8_t USBD_HID_DataIn_impl (USBD_HandleTypeDef *pdev, uint8_t epnum) { c0d03d38: b580 push {r7, lr} UNUSED(pdev); switch (epnum) { c0d03d3a: 2902 cmp r1, #2 c0d03d3c: d103 bne.n c0d03d46 <USBD_HID_DataIn_impl+0xe> // HID gen endpoint case (HID_EPIN_ADDR&0x7F): io_usb_hid_sent(io_usb_send_apdu_data); c0d03d3e: 4803 ldr r0, [pc, #12] ; (c0d03d4c <USBD_HID_DataIn_impl+0x14>) c0d03d40: 4478 add r0, pc c0d03d42: f7fc ffd9 bl c0d00cf8 <io_usb_hid_sent> break; } return USBD_OK; c0d03d46: 2000 movs r0, #0 c0d03d48: bd80 pop {r7, pc} c0d03d4a: 46c0 nop ; (mov r8, r8) c0d03d4c: ffffd25d .word 0xffffd25d c0d03d50 <USBD_HID_DataOut_impl>: } uint8_t USBD_HID_DataOut_impl (USBD_HandleTypeDef *pdev, uint8_t epnum, uint8_t* buffer) { c0d03d50: b5b0 push {r4, r5, r7, lr} c0d03d52: 4614 mov r4, r2 // only the data hid endpoint will receive data switch (epnum) { c0d03d54: 2902 cmp r1, #2 c0d03d56: d11b bne.n c0d03d90 <USBD_HID_DataOut_impl+0x40> // HID gen endpoint case (HID_EPOUT_ADDR&0x7F): // prepare receiving the next chunk (masked time) USBD_LL_PrepareReceive(pdev, HID_EPOUT_ADDR , HID_EPOUT_SIZE); c0d03d58: 2102 movs r1, #2 c0d03d5a: 2240 movs r2, #64 ; 0x40 c0d03d5c: f7ff fa95 bl c0d0328a <USBD_LL_PrepareReceive> // avoid troubles when an apdu has not been replied yet if (G_io_apdu_media == IO_APDU_MEDIA_NONE) { c0d03d60: 4d0c ldr r5, [pc, #48] ; (c0d03d94 <USBD_HID_DataOut_impl+0x44>) c0d03d62: 7828 ldrb r0, [r5, #0] c0d03d64: 2800 cmp r0, #0 c0d03d66: d113 bne.n c0d03d90 <USBD_HID_DataOut_impl+0x40> // add to the hid transport switch(io_usb_hid_receive(io_usb_send_apdu_data, buffer, io_seproxyhal_get_ep_rx_size(HID_EPOUT_ADDR))) { c0d03d68: 2002 movs r0, #2 c0d03d6a: f7fd f8b7 bl c0d00edc <io_seproxyhal_get_ep_rx_size> c0d03d6e: 4602 mov r2, r0 c0d03d70: 480c ldr r0, [pc, #48] ; (c0d03da4 <USBD_HID_DataOut_impl+0x54>) c0d03d72: 4478 add r0, pc c0d03d74: 4621 mov r1, r4 c0d03d76: f7fc feed bl c0d00b54 <io_usb_hid_receive> c0d03d7a: 2802 cmp r0, #2 c0d03d7c: d108 bne.n c0d03d90 <USBD_HID_DataOut_impl+0x40> default: break; case IO_USB_APDU_RECEIVED: G_io_apdu_media = IO_APDU_MEDIA_USB_HID; // for application code c0d03d7e: 2001 movs r0, #1 c0d03d80: 7028 strb r0, [r5, #0] G_io_apdu_state = APDU_USB_HID; // for next call to io_exchange c0d03d82: 4805 ldr r0, [pc, #20] ; (c0d03d98 <USBD_HID_DataOut_impl+0x48>) c0d03d84: 2107 movs r1, #7 c0d03d86: 7001 strb r1, [r0, #0] G_io_apdu_length = G_io_usb_hid_total_length; c0d03d88: 4804 ldr r0, [pc, #16] ; (c0d03d9c <USBD_HID_DataOut_impl+0x4c>) c0d03d8a: 6800 ldr r0, [r0, #0] c0d03d8c: 4904 ldr r1, [pc, #16] ; (c0d03da0 <USBD_HID_DataOut_impl+0x50>) c0d03d8e: 8008 strh r0, [r1, #0] } } break; } return USBD_OK; c0d03d90: 2000 movs r0, #0 c0d03d92: bdb0 pop {r4, r5, r7, pc} c0d03d94: 20001a54 .word 0x20001a54 c0d03d98: 20001a6a .word 0x20001a6a c0d03d9c: 200018f0 .word 0x200018f0 c0d03da0: 20001a6c .word 0x20001a6c c0d03da4: ffffd22b .word 0xffffd22b c0d03da8 <USBD_WEBUSB_Init>: #ifdef HAVE_WEBUSB uint8_t USBD_WEBUSB_Init (USBD_HandleTypeDef *pdev, uint8_t cfgidx) { c0d03da8: b570 push {r4, r5, r6, lr} c0d03daa: 4604 mov r4, r0 UNUSED(cfgidx); /* Open EP IN */ USBD_LL_OpenEP(pdev, c0d03dac: 2183 movs r1, #131 ; 0x83 c0d03dae: 2503 movs r5, #3 c0d03db0: 2640 movs r6, #64 ; 0x40 c0d03db2: 462a mov r2, r5 c0d03db4: 4633 mov r3, r6 c0d03db6: f7ff f9a5 bl c0d03104 <USBD_LL_OpenEP> WEBUSB_EPIN_ADDR, USBD_EP_TYPE_INTR, WEBUSB_EPIN_SIZE); /* Open EP OUT */ USBD_LL_OpenEP(pdev, c0d03dba: 4620 mov r0, r4 c0d03dbc: 4629 mov r1, r5 c0d03dbe: 462a mov r2, r5 c0d03dc0: 4633 mov r3, r6 c0d03dc2: f7ff f99f bl c0d03104 <USBD_LL_OpenEP> WEBUSB_EPOUT_ADDR, USBD_EP_TYPE_INTR, WEBUSB_EPOUT_SIZE); /* Prepare Out endpoint to receive 1st packet */ USBD_LL_PrepareReceive(pdev, WEBUSB_EPOUT_ADDR, WEBUSB_EPOUT_SIZE); c0d03dc6: 4620 mov r0, r4 c0d03dc8: 4629 mov r1, r5 c0d03dca: 4632 mov r2, r6 c0d03dcc: f7ff fa5d bl c0d0328a <USBD_LL_PrepareReceive> return USBD_OK; c0d03dd0: 2000 movs r0, #0 c0d03dd2: bd70 pop {r4, r5, r6, pc} c0d03dd4 <USBD_WEBUSB_DeInit>: uint8_t USBD_WEBUSB_DeInit (USBD_HandleTypeDef *pdev, uint8_t cfgidx) { UNUSED(pdev); UNUSED(cfgidx); return USBD_OK; c0d03dd4: 2000 movs r0, #0 c0d03dd6: 4770 bx lr c0d03dd8 <USBD_WEBUSB_Setup>: uint8_t USBD_WEBUSB_Setup (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) { UNUSED(pdev); UNUSED(req); return USBD_OK; c0d03dd8: 2000 movs r0, #0 c0d03dda: 4770 bx lr c0d03ddc <USBD_WEBUSB_DataIn>: } uint8_t USBD_WEBUSB_DataIn (USBD_HandleTypeDef *pdev, uint8_t epnum) { c0d03ddc: b580 push {r7, lr} UNUSED(pdev); switch (epnum) { c0d03dde: 2903 cmp r1, #3 c0d03de0: d103 bne.n c0d03dea <USBD_WEBUSB_DataIn+0xe> // HID gen endpoint case (WEBUSB_EPIN_ADDR&0x7F): io_usb_hid_sent(io_usb_send_apdu_data_ep0x83); c0d03de2: 4803 ldr r0, [pc, #12] ; (c0d03df0 <USBD_WEBUSB_DataIn+0x14>) c0d03de4: 4478 add r0, pc c0d03de6: f7fc ff87 bl c0d00cf8 <io_usb_hid_sent> break; } return USBD_OK; c0d03dea: 2000 movs r0, #0 c0d03dec: bd80 pop {r7, pc} c0d03dee: 46c0 nop ; (mov r8, r8) c0d03df0: ffffd1c9 .word 0xffffd1c9 c0d03df4 <USBD_WEBUSB_DataOut>: } uint8_t USBD_WEBUSB_DataOut (USBD_HandleTypeDef *pdev, uint8_t epnum, uint8_t* buffer) { c0d03df4: b5b0 push {r4, r5, r7, lr} c0d03df6: 4614 mov r4, r2 // only the data hid endpoint will receive data switch (epnum) { c0d03df8: 2903 cmp r1, #3 c0d03dfa: d11b bne.n c0d03e34 <USBD_WEBUSB_DataOut+0x40> // HID gen endpoint case (WEBUSB_EPOUT_ADDR&0x7F): // prepare receiving the next chunk (masked time) USBD_LL_PrepareReceive(pdev, WEBUSB_EPOUT_ADDR, WEBUSB_EPOUT_SIZE); c0d03dfc: 2103 movs r1, #3 c0d03dfe: 2240 movs r2, #64 ; 0x40 c0d03e00: f7ff fa43 bl c0d0328a <USBD_LL_PrepareReceive> // avoid troubles when an apdu has not been replied yet if (G_io_apdu_media == IO_APDU_MEDIA_NONE) { c0d03e04: 4d0c ldr r5, [pc, #48] ; (c0d03e38 <USBD_WEBUSB_DataOut+0x44>) c0d03e06: 7828 ldrb r0, [r5, #0] c0d03e08: 2800 cmp r0, #0 c0d03e0a: d113 bne.n c0d03e34 <USBD_WEBUSB_DataOut+0x40> // add to the hid transport switch(io_usb_hid_receive(io_usb_send_apdu_data_ep0x83, buffer, io_seproxyhal_get_ep_rx_size(WEBUSB_EPOUT_ADDR))) { c0d03e0c: 2003 movs r0, #3 c0d03e0e: f7fd f865 bl c0d00edc <io_seproxyhal_get_ep_rx_size> c0d03e12: 4602 mov r2, r0 c0d03e14: 480c ldr r0, [pc, #48] ; (c0d03e48 <USBD_WEBUSB_DataOut+0x54>) c0d03e16: 4478 add r0, pc c0d03e18: 4621 mov r1, r4 c0d03e1a: f7fc fe9b bl c0d00b54 <io_usb_hid_receive> c0d03e1e: 2802 cmp r0, #2 c0d03e20: d108 bne.n c0d03e34 <USBD_WEBUSB_DataOut+0x40> default: break; case IO_USB_APDU_RECEIVED: G_io_apdu_media = IO_APDU_MEDIA_USB_WEBUSB; // for application code c0d03e22: 2005 movs r0, #5 c0d03e24: 7028 strb r0, [r5, #0] G_io_apdu_state = APDU_USB_WEBUSB; // for next call to io_exchange c0d03e26: 4805 ldr r0, [pc, #20] ; (c0d03e3c <USBD_WEBUSB_DataOut+0x48>) c0d03e28: 210b movs r1, #11 c0d03e2a: 7001 strb r1, [r0, #0] G_io_apdu_length = G_io_usb_hid_total_length; c0d03e2c: 4804 ldr r0, [pc, #16] ; (c0d03e40 <USBD_WEBUSB_DataOut+0x4c>) c0d03e2e: 6800 ldr r0, [r0, #0] c0d03e30: 4904 ldr r1, [pc, #16] ; (c0d03e44 <USBD_WEBUSB_DataOut+0x50>) c0d03e32: 8008 strh r0, [r1, #0] } } break; } return USBD_OK; c0d03e34: 2000 movs r0, #0 c0d03e36: bdb0 pop {r4, r5, r7, pc} c0d03e38: 20001a54 .word 0x20001a54 c0d03e3c: 20001a6a .word 0x20001a6a c0d03e40: 200018f0 .word 0x200018f0 c0d03e44: 20001a6c .word 0x20001a6c c0d03e48: ffffd197 .word 0xffffd197 c0d03e4c <USBD_DeviceDescriptor>: * @retval Pointer to descriptor buffer */ static uint8_t *USBD_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) { UNUSED(speed); *length = sizeof(USBD_DeviceDesc); c0d03e4c: 2012 movs r0, #18 c0d03e4e: 8008 strh r0, [r1, #0] return (uint8_t*)USBD_DeviceDesc; c0d03e50: 4801 ldr r0, [pc, #4] ; (c0d03e58 <USBD_DeviceDescriptor+0xc>) c0d03e52: 4478 add r0, pc c0d03e54: 4770 bx lr c0d03e56: 46c0 nop ; (mov r8, r8) c0d03e58: 00000a16 .word 0x00000a16 c0d03e5c <USBD_LangIDStrDescriptor>: * @retval Pointer to descriptor buffer */ static uint8_t *USBD_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) { UNUSED(speed); *length = sizeof(USBD_LangIDDesc); c0d03e5c: 2004 movs r0, #4 c0d03e5e: 8008 strh r0, [r1, #0] return (uint8_t*)USBD_LangIDDesc; c0d03e60: 4801 ldr r0, [pc, #4] ; (c0d03e68 <USBD_LangIDStrDescriptor+0xc>) c0d03e62: 4478 add r0, pc c0d03e64: 4770 bx lr c0d03e66: 46c0 nop ; (mov r8, r8) c0d03e68: 00000a18 .word 0x00000a18 c0d03e6c <USBD_ManufacturerStrDescriptor>: * @retval Pointer to descriptor buffer */ static uint8_t *USBD_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) { UNUSED(speed); *length = sizeof(USBD_MANUFACTURER_STRING); c0d03e6c: 200e movs r0, #14 c0d03e6e: 8008 strh r0, [r1, #0] return (uint8_t*)USBD_MANUFACTURER_STRING; c0d03e70: 4801 ldr r0, [pc, #4] ; (c0d03e78 <USBD_ManufacturerStrDescriptor+0xc>) c0d03e72: 4478 add r0, pc c0d03e74: 4770 bx lr c0d03e76: 46c0 nop ; (mov r8, r8) c0d03e78: 00000a0c .word 0x00000a0c c0d03e7c <USBD_ProductStrDescriptor>: * @retval Pointer to descriptor buffer */ static uint8_t *USBD_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) { UNUSED(speed); *length = sizeof(USBD_PRODUCT_FS_STRING); c0d03e7c: 200e movs r0, #14 c0d03e7e: 8008 strh r0, [r1, #0] return (uint8_t*)USBD_PRODUCT_FS_STRING; c0d03e80: 4801 ldr r0, [pc, #4] ; (c0d03e88 <USBD_ProductStrDescriptor+0xc>) c0d03e82: 4478 add r0, pc c0d03e84: 4770 bx lr c0d03e86: 46c0 nop ; (mov r8, r8) c0d03e88: 00000a0a .word 0x00000a0a c0d03e8c <USBD_SerialStrDescriptor>: * @retval Pointer to descriptor buffer */ static uint8_t *USBD_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) { UNUSED(speed); *length = sizeof(USB_SERIAL_STRING); c0d03e8c: 200a movs r0, #10 c0d03e8e: 8008 strh r0, [r1, #0] return (uint8_t*)USB_SERIAL_STRING; c0d03e90: 4801 ldr r0, [pc, #4] ; (c0d03e98 <USBD_SerialStrDescriptor+0xc>) c0d03e92: 4478 add r0, pc c0d03e94: 4770 bx lr c0d03e96: 46c0 nop ; (mov r8, r8) c0d03e98: 00000a08 .word 0x00000a08 c0d03e9c <USBD_ConfigStrDescriptor>: * @retval Pointer to descriptor buffer */ static uint8_t *USBD_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) { UNUSED(speed); *length = sizeof(USBD_CONFIGURATION_FS_STRING); c0d03e9c: 200e movs r0, #14 c0d03e9e: 8008 strh r0, [r1, #0] return (uint8_t*)USBD_CONFIGURATION_FS_STRING; c0d03ea0: 4801 ldr r0, [pc, #4] ; (c0d03ea8 <USBD_ConfigStrDescriptor+0xc>) c0d03ea2: 4478 add r0, pc c0d03ea4: 4770 bx lr c0d03ea6: 46c0 nop ; (mov r8, r8) c0d03ea8: 000009ea .word 0x000009ea c0d03eac <USBD_InterfaceStrDescriptor>: * @retval Pointer to descriptor buffer */ static uint8_t *USBD_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length) { UNUSED(speed); *length = sizeof(USBD_INTERFACE_FS_STRING); c0d03eac: 200e movs r0, #14 c0d03eae: 8008 strh r0, [r1, #0] return (uint8_t*)USBD_INTERFACE_FS_STRING; c0d03eb0: 4801 ldr r0, [pc, #4] ; (c0d03eb8 <USBD_InterfaceStrDescriptor+0xc>) c0d03eb2: 4478 add r0, pc c0d03eb4: 4770 bx lr c0d03eb6: 46c0 nop ; (mov r8, r8) c0d03eb8: 000009da .word 0x000009da c0d03ebc <USBD_CtlError>: WEBUSB_VENDOR_CODE, // bVencordCode 1 // iLanding }; // upon unsupported request, check for webusb request void USBD_CtlError( USBD_HandleTypeDef *pdev , USBD_SetupReqTypedef *req) { c0d03ebc: b580 push {r7, lr} if ((req->bmRequest & 0x80) && req->bRequest == WEBUSB_VENDOR_CODE && req->wIndex == WEBUSB_REQ_GET_URL c0d03ebe: 780a ldrb r2, [r1, #0] c0d03ec0: b252 sxtb r2, r2 c0d03ec2: 2a00 cmp r2, #0 c0d03ec4: db02 blt.n c0d03ecc <USBD_CtlError+0x10> } else if ((req->bmRequest & 0x80) && req->bRequest == USB_REQ_GET_DESCRIPTOR && (req->wValue>>8) == USB_DT_BOS) { USBD_CtlSendData(pdev, (unsigned char*)C_usb_bos, sizeof(C_usb_bos)); } else { USBD_CtlStall(pdev); c0d03ec6: f7ff fe32 bl c0d03b2e <USBD_CtlStall> } } c0d03eca: bd80 pop {r7, pc} 1 // iLanding }; // upon unsupported request, check for webusb request void USBD_CtlError( USBD_HandleTypeDef *pdev , USBD_SetupReqTypedef *req) { if ((req->bmRequest & 0x80) && req->bRequest == WEBUSB_VENDOR_CODE && req->wIndex == WEBUSB_REQ_GET_URL c0d03ecc: 784a ldrb r2, [r1, #1] c0d03ece: 2a06 cmp r2, #6 c0d03ed0: d00d beq.n c0d03eee <USBD_CtlError+0x32> c0d03ed2: 2a1e cmp r2, #30 c0d03ed4: d1f7 bne.n c0d03ec6 <USBD_CtlError+0xa> c0d03ed6: 888a ldrh r2, [r1, #4] // HTTPS url && req->wValue == 1) { c0d03ed8: 2a02 cmp r2, #2 c0d03eda: d1f4 bne.n c0d03ec6 <USBD_CtlError+0xa> c0d03edc: 8849 ldrh r1, [r1, #2] 1 // iLanding }; // upon unsupported request, check for webusb request void USBD_CtlError( USBD_HandleTypeDef *pdev , USBD_SetupReqTypedef *req) { if ((req->bmRequest & 0x80) && req->bRequest == WEBUSB_VENDOR_CODE && req->wIndex == WEBUSB_REQ_GET_URL c0d03ede: 2901 cmp r1, #1 c0d03ee0: d1f1 bne.n c0d03ec6 <USBD_CtlError+0xa> // HTTPS url && req->wValue == 1) { // return the URL descriptor USBD_CtlSendData (pdev, (unsigned char*)C_webusb_url_descriptor, sizeof(C_webusb_url_descriptor)); c0d03ee2: 4907 ldr r1, [pc, #28] ; (c0d03f00 <USBD_CtlError+0x44>) c0d03ee4: 4479 add r1, pc c0d03ee6: 2217 movs r2, #23 c0d03ee8: f000 f86a bl c0d03fc0 <USBD_CtlSendData> USBD_CtlSendData(pdev, (unsigned char*)C_usb_bos, sizeof(C_usb_bos)); } else { USBD_CtlStall(pdev); } } c0d03eec: bd80 pop {r7, pc} // HTTPS url && req->wValue == 1) { // return the URL descriptor USBD_CtlSendData (pdev, (unsigned char*)C_webusb_url_descriptor, sizeof(C_webusb_url_descriptor)); } else if ((req->bmRequest & 0x80) && req->bRequest == USB_REQ_GET_DESCRIPTOR && (req->wValue>>8) == USB_DT_BOS) { c0d03eee: 78c9 ldrb r1, [r1, #3] c0d03ef0: 290f cmp r1, #15 c0d03ef2: d1e8 bne.n c0d03ec6 <USBD_CtlError+0xa> USBD_CtlSendData(pdev, (unsigned char*)C_usb_bos, sizeof(C_usb_bos)); c0d03ef4: 4903 ldr r1, [pc, #12] ; (c0d03f04 <USBD_CtlError+0x48>) c0d03ef6: 4479 add r1, pc c0d03ef8: 221d movs r2, #29 c0d03efa: f000 f861 bl c0d03fc0 <USBD_CtlSendData> } else { USBD_CtlStall(pdev); } } c0d03efe: bd80 pop {r7, pc} c0d03f00: 000008a8 .word 0x000008a8 c0d03f04: 000008ad .word 0x000008ad c0d03f08 <USB_power>: // nothing to do ? return 0; } #endif // HAVE_USB_CLASS_CCID void USB_power(unsigned char enabled) { c0d03f08: b570 push {r4, r5, r6, lr} c0d03f0a: 4604 mov r4, r0 c0d03f0c: 204d movs r0, #77 ; 0x4d c0d03f0e: 0085 lsls r5, r0, #2 os_memset(&USBD_Device, 0, sizeof(USBD_Device)); c0d03f10: 481c ldr r0, [pc, #112] ; (c0d03f84 <USB_power+0x7c>) c0d03f12: 2100 movs r1, #0 c0d03f14: 462a mov r2, r5 c0d03f16: f7fc fec5 bl c0d00ca4 <os_memset> if (enabled) { c0d03f1a: 2c00 cmp r4, #0 c0d03f1c: d02d beq.n c0d03f7a <USB_power+0x72> os_memset(&USBD_Device, 0, sizeof(USBD_Device)); c0d03f1e: 4c19 ldr r4, [pc, #100] ; (c0d03f84 <USB_power+0x7c>) c0d03f20: 2600 movs r6, #0 c0d03f22: 4620 mov r0, r4 c0d03f24: 4631 mov r1, r6 c0d03f26: 462a mov r2, r5 c0d03f28: f7fc febc bl c0d00ca4 <os_memset> /* Init Device Library */ USBD_Init(&USBD_Device, (USBD_DescriptorsTypeDef*)&HID_Desc, 0); c0d03f2c: 4918 ldr r1, [pc, #96] ; (c0d03f90 <USB_power+0x88>) c0d03f2e: 4479 add r1, pc c0d03f30: 4620 mov r0, r4 c0d03f32: 4632 mov r2, r6 c0d03f34: f7ff f9bc bl c0d032b0 <USBD_Init> /* Register the HID class */ USBD_RegisterClassForInterface(HID_INTF, &USBD_Device, (USBD_ClassTypeDef*)&USBD_HID); c0d03f38: 4a16 ldr r2, [pc, #88] ; (c0d03f94 <USB_power+0x8c>) c0d03f3a: 447a add r2, pc c0d03f3c: 4630 mov r0, r6 c0d03f3e: 4621 mov r1, r4 c0d03f40: f7ff f9f0 bl c0d03324 <USBD_RegisterClassForInterface> #ifdef HAVE_IO_U2F USBD_RegisterClassForInterface(U2F_INTF, &USBD_Device, (USBD_ClassTypeDef*)&USBD_U2F); c0d03f44: 2001 movs r0, #1 c0d03f46: 4a14 ldr r2, [pc, #80] ; (c0d03f98 <USB_power+0x90>) c0d03f48: 447a add r2, pc c0d03f4a: 4621 mov r1, r4 c0d03f4c: f7ff f9ea bl c0d03324 <USBD_RegisterClassForInterface> // initialize the U2F tunnel transport u2f_transport_init(&G_io_u2f, G_io_apdu_buffer, IO_APDU_BUFFER_SIZE); c0d03f50: 22ff movs r2, #255 ; 0xff c0d03f52: 3252 adds r2, #82 ; 0x52 c0d03f54: 480c ldr r0, [pc, #48] ; (c0d03f88 <USB_power+0x80>) c0d03f56: 490d ldr r1, [pc, #52] ; (c0d03f8c <USB_power+0x84>) c0d03f58: f7fe fafe bl c0d02558 <u2f_transport_init> #ifdef HAVE_USB_CLASS_CCID USBD_RegisterClassForInterface(CCID_INTF, &USBD_Device, (USBD_ClassTypeDef*)&USBD_CCID); #endif // HAVE_USB_CLASS_CCID #ifdef HAVE_WEBUSB USBD_RegisterClassForInterface(WEBUSB_INTF, &USBD_Device, (USBD_ClassTypeDef*)&USBD_WEBUSB); c0d03f5c: 2002 movs r0, #2 c0d03f5e: 4a0f ldr r2, [pc, #60] ; (c0d03f9c <USB_power+0x94>) c0d03f60: 447a add r2, pc c0d03f62: 4621 mov r1, r4 c0d03f64: f7ff f9de bl c0d03324 <USBD_RegisterClassForInterface> USBD_LL_PrepareReceive(&USBD_Device, WEBUSB_EPOUT_ADDR , WEBUSB_EPOUT_SIZE); c0d03f68: 2103 movs r1, #3 c0d03f6a: 2240 movs r2, #64 ; 0x40 c0d03f6c: 4620 mov r0, r4 c0d03f6e: f7ff f98c bl c0d0328a <USBD_LL_PrepareReceive> #endif // HAVE_WEBUSB /* Start Device Process */ USBD_Start(&USBD_Device); c0d03f72: 4620 mov r0, r4 c0d03f74: f7ff f9e3 bl c0d0333e <USBD_Start> } else { USBD_DeInit(&USBD_Device); } } c0d03f78: bd70 pop {r4, r5, r6, pc} /* Start Device Process */ USBD_Start(&USBD_Device); } else { USBD_DeInit(&USBD_Device); c0d03f7a: 4802 ldr r0, [pc, #8] ; (c0d03f84 <USB_power+0x7c>) c0d03f7c: f7ff f9b3 bl c0d032e6 <USBD_DeInit> } } c0d03f80: bd70 pop {r4, r5, r6, pc} c0d03f82: 46c0 nop ; (mov r8, r8) c0d03f84: 20001c8c .word 0x20001c8c c0d03f88: 20001a7c .word 0x20001a7c c0d03f8c: 200018f8 .word 0x200018f8 c0d03f90: 0000083e .word 0x0000083e c0d03f94: 00000886 .word 0x00000886 c0d03f98: 000008b0 .word 0x000008b0 c0d03f9c: 000008d0 .word 0x000008d0 c0d03fa0 <USBD_GetCfgDesc_impl>: * @param length : pointer data length * @retval pointer to descriptor buffer */ static uint8_t *USBD_GetCfgDesc_impl (uint16_t *length) { *length = sizeof (USBD_CfgDesc); c0d03fa0: 2160 movs r1, #96 ; 0x60 c0d03fa2: 8001 strh r1, [r0, #0] return (uint8_t*)USBD_CfgDesc; c0d03fa4: 4801 ldr r0, [pc, #4] ; (c0d03fac <USBD_GetCfgDesc_impl+0xc>) c0d03fa6: 4478 add r0, pc c0d03fa8: 4770 bx lr c0d03faa: 46c0 nop ; (mov r8, r8) c0d03fac: 000008fe .word 0x000008fe c0d03fb0 <USBD_GetDeviceQualifierDesc_impl>: * @param length : pointer data length * @retval pointer to descriptor buffer */ static uint8_t *USBD_GetDeviceQualifierDesc_impl (uint16_t *length) { *length = sizeof (USBD_DeviceQualifierDesc); c0d03fb0: 210a movs r1, #10 c0d03fb2: 8001 strh r1, [r0, #0] return (uint8_t*)USBD_DeviceQualifierDesc; c0d03fb4: 4801 ldr r0, [pc, #4] ; (c0d03fbc <USBD_GetDeviceQualifierDesc_impl+0xc>) c0d03fb6: 4478 add r0, pc c0d03fb8: 4770 bx lr c0d03fba: 46c0 nop ; (mov r8, r8) c0d03fbc: 0000094e .word 0x0000094e c0d03fc0 <USBD_CtlSendData>: * @retval status */ USBD_StatusTypeDef USBD_CtlSendData (USBD_HandleTypeDef *pdev, uint8_t *pbuf, uint16_t len) { c0d03fc0: b5b0 push {r4, r5, r7, lr} c0d03fc2: 460c mov r4, r1 /* Set EP0 State */ pdev->ep0_state = USBD_EP0_DATA_IN; c0d03fc4: 21f4 movs r1, #244 ; 0xf4 c0d03fc6: 2302 movs r3, #2 c0d03fc8: 5043 str r3, [r0, r1] pdev->ep_in[0].total_length = len; c0d03fca: 6182 str r2, [r0, #24] pdev->ep_in[0].rem_length = len; c0d03fcc: 61c2 str r2, [r0, #28] // store the continuation data if needed pdev->pData = pbuf; c0d03fce: 2113 movs r1, #19 c0d03fd0: 0109 lsls r1, r1, #4 c0d03fd2: 5044 str r4, [r0, r1] /* Start the transfer */ USBD_LL_Transmit (pdev, 0x00, pbuf, MIN(len, pdev->ep_in[0].maxpacket)); c0d03fd4: 6a01 ldr r1, [r0, #32] c0d03fd6: 428a cmp r2, r1 c0d03fd8: d300 bcc.n c0d03fdc <USBD_CtlSendData+0x1c> c0d03fda: 460a mov r2, r1 c0d03fdc: b293 uxth r3, r2 c0d03fde: 2500 movs r5, #0 c0d03fe0: 4629 mov r1, r5 c0d03fe2: 4622 mov r2, r4 c0d03fe4: f7ff f938 bl c0d03258 <USBD_LL_Transmit> return USBD_OK; c0d03fe8: 4628 mov r0, r5 c0d03fea: bdb0 pop {r4, r5, r7, pc} c0d03fec <USBD_CtlContinueSendData>: * @retval status */ USBD_StatusTypeDef USBD_CtlContinueSendData (USBD_HandleTypeDef *pdev, uint8_t *pbuf, uint16_t len) { c0d03fec: b5b0 push {r4, r5, r7, lr} c0d03fee: 460c mov r4, r1 /* Start the next transfer */ USBD_LL_Transmit (pdev, 0x00, pbuf, MIN(len, pdev->ep_in[0].maxpacket)); c0d03ff0: 6a01 ldr r1, [r0, #32] c0d03ff2: 428a cmp r2, r1 c0d03ff4: d300 bcc.n c0d03ff8 <USBD_CtlContinueSendData+0xc> c0d03ff6: 460a mov r2, r1 c0d03ff8: b293 uxth r3, r2 c0d03ffa: 2500 movs r5, #0 c0d03ffc: 4629 mov r1, r5 c0d03ffe: 4622 mov r2, r4 c0d04000: f7ff f92a bl c0d03258 <USBD_LL_Transmit> return USBD_OK; c0d04004: 4628 mov r0, r5 c0d04006: bdb0 pop {r4, r5, r7, pc} c0d04008 <USBD_CtlContinueRx>: * @retval status */ USBD_StatusTypeDef USBD_CtlContinueRx (USBD_HandleTypeDef *pdev, uint8_t *pbuf, uint16_t len) { c0d04008: b510 push {r4, lr} c0d0400a: 2400 movs r4, #0 UNUSED(pbuf); USBD_LL_PrepareReceive (pdev, c0d0400c: 4621 mov r1, r4 c0d0400e: f7ff f93c bl c0d0328a <USBD_LL_PrepareReceive> 0, len); return USBD_OK; c0d04012: 4620 mov r0, r4 c0d04014: bd10 pop {r4, pc} c0d04016 <USBD_CtlSendStatus>: * send zero lzngth packet on the ctl pipe * @param pdev: device instance * @retval status */ USBD_StatusTypeDef USBD_CtlSendStatus (USBD_HandleTypeDef *pdev) { c0d04016: b510 push {r4, lr} /* Set EP0 State */ pdev->ep0_state = USBD_EP0_STATUS_IN; c0d04018: 21f4 movs r1, #244 ; 0xf4 c0d0401a: 2204 movs r2, #4 c0d0401c: 5042 str r2, [r0, r1] c0d0401e: 2400 movs r4, #0 /* Start the transfer */ USBD_LL_Transmit (pdev, 0x00, NULL, 0); c0d04020: 4621 mov r1, r4 c0d04022: 4622 mov r2, r4 c0d04024: 4623 mov r3, r4 c0d04026: f7ff f917 bl c0d03258 <USBD_LL_Transmit> return USBD_OK; c0d0402a: 4620 mov r0, r4 c0d0402c: bd10 pop {r4, pc} c0d0402e <USBD_CtlReceiveStatus>: * receive zero lzngth packet on the ctl pipe * @param pdev: device instance * @retval status */ USBD_StatusTypeDef USBD_CtlReceiveStatus (USBD_HandleTypeDef *pdev) { c0d0402e: b510 push {r4, lr} /* Set EP0 State */ pdev->ep0_state = USBD_EP0_STATUS_OUT; c0d04030: 21f4 movs r1, #244 ; 0xf4 c0d04032: 2205 movs r2, #5 c0d04034: 5042 str r2, [r0, r1] c0d04036: 2400 movs r4, #0 /* Start the transfer */ USBD_LL_PrepareReceive ( pdev, c0d04038: 4621 mov r1, r4 c0d0403a: 4622 mov r2, r4 c0d0403c: f7ff f925 bl c0d0328a <USBD_LL_PrepareReceive> 0, 0); return USBD_OK; c0d04040: 4620 mov r0, r4 c0d04042: bd10 pop {r4, pc} c0d04044 <hex_to_str>: # include "utils.h" //字节流转换为十六进制字符串的另一种实现方式 void hex_to_str( const unsigned char* source, char* dest, int sourceLen ) { c0d04044: b5f0 push {r4, r5, r6, r7, lr} c0d04046: b081 sub sp, #4 c0d04048: 9000 str r0, [sp, #0] short i; unsigned char highByte, lowByte; for (i = 0; i < sourceLen; i++) c0d0404a: 2a01 cmp r2, #1 c0d0404c: db1a blt.n c0d04084 <hex_to_str+0x40> c0d0404e: 2400 movs r4, #0 c0d04050: 4623 mov r3, r4 { highByte = source[i] >> 4; c0d04052: 9800 ldr r0, [sp, #0] c0d04054: 5d05 ldrb r5, [r0, r4] c0d04056: 092f lsrs r7, r5, #4 lowByte = source[i] & 0x0f ; highByte += 0x30; c0d04058: 2030 movs r0, #48 ; 0x30 c0d0405a: 4307 orrs r7, r0 if (highByte > 0x39) dest[i * 2] = highByte + 0x07; c0d0405c: 1dfe adds r6, r7, #7 highByte += 0x30; if (highByte > 0x39) c0d0405e: 2f39 cmp r7, #57 ; 0x39 c0d04060: d800 bhi.n c0d04064 <hex_to_str+0x20> c0d04062: 463e mov r6, r7 c0d04064: 0064 lsls r4, r4, #1 c0d04066: 550e strb r6, [r1, r4] for (i = 0; i < sourceLen; i++) { highByte = source[i] >> 4; lowByte = source[i] & 0x0f ; c0d04068: 260f movs r6, #15 c0d0406a: 4035 ands r5, r6 dest[i * 2] = highByte + 0x07; else dest[i * 2] = highByte; lowByte += 0x30; c0d0406c: 4305 orrs r5, r0 if (lowByte > 0x39) dest[i * 2 + 1] = lowByte + 0x07; c0d0406e: 1dee adds r6, r5, #7 else dest[i * 2] = highByte; lowByte += 0x30; if (lowByte > 0x39) c0d04070: 2d39 cmp r5, #57 ; 0x39 c0d04072: d800 bhi.n c0d04076 <hex_to_str+0x32> c0d04074: 462e mov r6, r5 c0d04076: 2001 movs r0, #1 c0d04078: 4304 orrs r4, r0 c0d0407a: 550e strb r6, [r1, r4] { short i; unsigned char highByte, lowByte; for (i = 0; i < sourceLen; i++) c0d0407c: 1c5b adds r3, r3, #1 c0d0407e: b21c sxth r4, r3 c0d04080: 4294 cmp r4, r2 c0d04082: dbe6 blt.n c0d04052 <hex_to_str+0xe> dest[i * 2 + 1] = lowByte + 0x07; else dest[i * 2 + 1] = lowByte; } return ; c0d04084: b001 add sp, #4 c0d04086: bdf0 pop {r4, r5, r6, r7, pc} c0d04088 <__aeabi_uidiv>: c0d04088: 2200 movs r2, #0 c0d0408a: 0843 lsrs r3, r0, #1 c0d0408c: 428b cmp r3, r1 c0d0408e: d374 bcc.n c0d0417a <__aeabi_uidiv+0xf2> c0d04090: 0903 lsrs r3, r0, #4 c0d04092: 428b cmp r3, r1 c0d04094: d35f bcc.n c0d04156 <__aeabi_uidiv+0xce> c0d04096: 0a03 lsrs r3, r0, #8 c0d04098: 428b cmp r3, r1 c0d0409a: d344 bcc.n c0d04126 <__aeabi_uidiv+0x9e> c0d0409c: 0b03 lsrs r3, r0, #12 c0d0409e: 428b cmp r3, r1 c0d040a0: d328 bcc.n c0d040f4 <__aeabi_uidiv+0x6c> c0d040a2: 0c03 lsrs r3, r0, #16 c0d040a4: 428b cmp r3, r1 c0d040a6: d30d bcc.n c0d040c4 <__aeabi_uidiv+0x3c> c0d040a8: 22ff movs r2, #255 ; 0xff c0d040aa: 0209 lsls r1, r1, #8 c0d040ac: ba12 rev r2, r2 c0d040ae: 0c03 lsrs r3, r0, #16 c0d040b0: 428b cmp r3, r1 c0d040b2: d302 bcc.n c0d040ba <__aeabi_uidiv+0x32> c0d040b4: 1212 asrs r2, r2, #8 c0d040b6: 0209 lsls r1, r1, #8 c0d040b8: d065 beq.n c0d04186 <__aeabi_uidiv+0xfe> c0d040ba: 0b03 lsrs r3, r0, #12 c0d040bc: 428b cmp r3, r1 c0d040be: d319 bcc.n c0d040f4 <__aeabi_uidiv+0x6c> c0d040c0: e000 b.n c0d040c4 <__aeabi_uidiv+0x3c> c0d040c2: 0a09 lsrs r1, r1, #8 c0d040c4: 0bc3 lsrs r3, r0, #15 c0d040c6: 428b cmp r3, r1 c0d040c8: d301 bcc.n c0d040ce <__aeabi_uidiv+0x46> c0d040ca: 03cb lsls r3, r1, #15 c0d040cc: 1ac0 subs r0, r0, r3 c0d040ce: 4152 adcs r2, r2 c0d040d0: 0b83 lsrs r3, r0, #14 c0d040d2: 428b cmp r3, r1 c0d040d4: d301 bcc.n c0d040da <__aeabi_uidiv+0x52> c0d040d6: 038b lsls r3, r1, #14 c0d040d8: 1ac0 subs r0, r0, r3 c0d040da: 4152 adcs r2, r2 c0d040dc: 0b43 lsrs r3, r0, #13 c0d040de: 428b cmp r3, r1 c0d040e0: d301 bcc.n c0d040e6 <__aeabi_uidiv+0x5e> c0d040e2: 034b lsls r3, r1, #13 c0d040e4: 1ac0 subs r0, r0, r3 c0d040e6: 4152 adcs r2, r2 c0d040e8: 0b03 lsrs r3, r0, #12 c0d040ea: 428b cmp r3, r1 c0d040ec: d301 bcc.n c0d040f2 <__aeabi_uidiv+0x6a> c0d040ee: 030b lsls r3, r1, #12 c0d040f0: 1ac0 subs r0, r0, r3 c0d040f2: 4152 adcs r2, r2 c0d040f4: 0ac3 lsrs r3, r0, #11 c0d040f6: 428b cmp r3, r1 c0d040f8: d301 bcc.n c0d040fe <__aeabi_uidiv+0x76> c0d040fa: 02cb lsls r3, r1, #11 c0d040fc: 1ac0 subs r0, r0, r3 c0d040fe: 4152 adcs r2, r2 c0d04100: 0a83 lsrs r3, r0, #10 c0d04102: 428b cmp r3, r1 c0d04104: d301 bcc.n c0d0410a <__aeabi_uidiv+0x82> c0d04106: 028b lsls r3, r1, #10 c0d04108: 1ac0 subs r0, r0, r3 c0d0410a: 4152 adcs r2, r2 c0d0410c: 0a43 lsrs r3, r0, #9 c0d0410e: 428b cmp r3, r1 c0d04110: d301 bcc.n c0d04116 <__aeabi_uidiv+0x8e> c0d04112: 024b lsls r3, r1, #9 c0d04114: 1ac0 subs r0, r0, r3 c0d04116: 4152 adcs r2, r2 c0d04118: 0a03 lsrs r3, r0, #8 c0d0411a: 428b cmp r3, r1 c0d0411c: d301 bcc.n c0d04122 <__aeabi_uidiv+0x9a> c0d0411e: 020b lsls r3, r1, #8 c0d04120: 1ac0 subs r0, r0, r3 c0d04122: 4152 adcs r2, r2 c0d04124: d2cd bcs.n c0d040c2 <__aeabi_uidiv+0x3a> c0d04126: 09c3 lsrs r3, r0, #7 c0d04128: 428b cmp r3, r1 c0d0412a: d301 bcc.n c0d04130 <__aeabi_uidiv+0xa8> c0d0412c: 01cb lsls r3, r1, #7 c0d0412e: 1ac0 subs r0, r0, r3 c0d04130: 4152 adcs r2, r2 c0d04132: 0983 lsrs r3, r0, #6 c0d04134: 428b cmp r3, r1 c0d04136: d301 bcc.n c0d0413c <__aeabi_uidiv+0xb4> c0d04138: 018b lsls r3, r1, #6 c0d0413a: 1ac0 subs r0, r0, r3 c0d0413c: 4152 adcs r2, r2 c0d0413e: 0943 lsrs r3, r0, #5 c0d04140: 428b cmp r3, r1 c0d04142: d301 bcc.n c0d04148 <__aeabi_uidiv+0xc0> c0d04144: 014b lsls r3, r1, #5 c0d04146: 1ac0 subs r0, r0, r3 c0d04148: 4152 adcs r2, r2 c0d0414a: 0903 lsrs r3, r0, #4 c0d0414c: 428b cmp r3, r1 c0d0414e: d301 bcc.n c0d04154 <__aeabi_uidiv+0xcc> c0d04150: 010b lsls r3, r1, #4 c0d04152: 1ac0 subs r0, r0, r3 c0d04154: 4152 adcs r2, r2 c0d04156: 08c3 lsrs r3, r0, #3 c0d04158: 428b cmp r3, r1 c0d0415a: d301 bcc.n c0d04160 <__aeabi_uidiv+0xd8> c0d0415c: 00cb lsls r3, r1, #3 c0d0415e: 1ac0 subs r0, r0, r3 c0d04160: 4152 adcs r2, r2 c0d04162: 0883 lsrs r3, r0, #2 c0d04164: 428b cmp r3, r1 c0d04166: d301 bcc.n c0d0416c <__aeabi_uidiv+0xe4> c0d04168: 008b lsls r3, r1, #2 c0d0416a: 1ac0 subs r0, r0, r3 c0d0416c: 4152 adcs r2, r2 c0d0416e: 0843 lsrs r3, r0, #1 c0d04170: 428b cmp r3, r1 c0d04172: d301 bcc.n c0d04178 <__aeabi_uidiv+0xf0> c0d04174: 004b lsls r3, r1, #1 c0d04176: 1ac0 subs r0, r0, r3 c0d04178: 4152 adcs r2, r2 c0d0417a: 1a41 subs r1, r0, r1 c0d0417c: d200 bcs.n c0d04180 <__aeabi_uidiv+0xf8> c0d0417e: 4601 mov r1, r0 c0d04180: 4152 adcs r2, r2 c0d04182: 4610 mov r0, r2 c0d04184: 4770 bx lr c0d04186: e7ff b.n c0d04188 <__aeabi_uidiv+0x100> c0d04188: b501 push {r0, lr} c0d0418a: 2000 movs r0, #0 c0d0418c: f000 f806 bl c0d0419c <__aeabi_idiv0> c0d04190: bd02 pop {r1, pc} c0d04192: 46c0 nop ; (mov r8, r8) c0d04194 <__aeabi_uidivmod>: c0d04194: 2900 cmp r1, #0 c0d04196: d0f7 beq.n c0d04188 <__aeabi_uidiv+0x100> c0d04198: e776 b.n c0d04088 <__aeabi_uidiv> c0d0419a: 4770 bx lr c0d0419c <__aeabi_idiv0>: c0d0419c: 4770 bx lr c0d0419e: 46c0 nop ; (mov r8, r8) c0d041a0 <__aeabi_memclr>: c0d041a0: b510 push {r4, lr} c0d041a2: 2200 movs r2, #0 c0d041a4: f000 f806 bl c0d041b4 <__aeabi_memset> c0d041a8: bd10 pop {r4, pc} c0d041aa: 46c0 nop ; (mov r8, r8) c0d041ac <__aeabi_memcpy>: c0d041ac: b510 push {r4, lr} c0d041ae: f000 f809 bl c0d041c4 <memcpy> c0d041b2: bd10 pop {r4, pc} c0d041b4 <__aeabi_memset>: c0d041b4: 0013 movs r3, r2 c0d041b6: b510 push {r4, lr} c0d041b8: 000a movs r2, r1 c0d041ba: 0019 movs r1, r3 c0d041bc: f000 f840 bl c0d04240 <memset> c0d041c0: bd10 pop {r4, pc} c0d041c2: 46c0 nop ; (mov r8, r8) c0d041c4 <memcpy>: c0d041c4: b570 push {r4, r5, r6, lr} c0d041c6: 2a0f cmp r2, #15 c0d041c8: d932 bls.n c0d04230 <memcpy+0x6c> c0d041ca: 000c movs r4, r1 c0d041cc: 4304 orrs r4, r0 c0d041ce: 000b movs r3, r1 c0d041d0: 07a4 lsls r4, r4, #30 c0d041d2: d131 bne.n c0d04238 <memcpy+0x74> c0d041d4: 0015 movs r5, r2 c0d041d6: 0004 movs r4, r0 c0d041d8: 3d10 subs r5, #16 c0d041da: 092d lsrs r5, r5, #4 c0d041dc: 3501 adds r5, #1 c0d041de: 012d lsls r5, r5, #4 c0d041e0: 1949 adds r1, r1, r5 c0d041e2: 681e ldr r6, [r3, #0] c0d041e4: 6026 str r6, [r4, #0] c0d041e6: 685e ldr r6, [r3, #4] c0d041e8: 6066 str r6, [r4, #4] c0d041ea: 689e ldr r6, [r3, #8] c0d041ec: 60a6 str r6, [r4, #8] c0d041ee: 68de ldr r6, [r3, #12] c0d041f0: 3310 adds r3, #16 c0d041f2: 60e6 str r6, [r4, #12] c0d041f4: 3410 adds r4, #16 c0d041f6: 4299 cmp r1, r3 c0d041f8: d1f3 bne.n c0d041e2 <memcpy+0x1e> c0d041fa: 230f movs r3, #15 c0d041fc: 1945 adds r5, r0, r5 c0d041fe: 4013 ands r3, r2 c0d04200: 2b03 cmp r3, #3 c0d04202: d91b bls.n c0d0423c <memcpy+0x78> c0d04204: 1f1c subs r4, r3, #4 c0d04206: 2300 movs r3, #0 c0d04208: 08a4 lsrs r4, r4, #2 c0d0420a: 3401 adds r4, #1 c0d0420c: 00a4 lsls r4, r4, #2 c0d0420e: 58ce ldr r6, [r1, r3] c0d04210: 50ee str r6, [r5, r3] c0d04212: 3304 adds r3, #4 c0d04214: 429c cmp r4, r3 c0d04216: d1fa bne.n c0d0420e <memcpy+0x4a> c0d04218: 2303 movs r3, #3 c0d0421a: 192d adds r5, r5, r4 c0d0421c: 1909 adds r1, r1, r4 c0d0421e: 401a ands r2, r3 c0d04220: d005 beq.n c0d0422e <memcpy+0x6a> c0d04222: 2300 movs r3, #0 c0d04224: 5ccc ldrb r4, [r1, r3] c0d04226: 54ec strb r4, [r5, r3] c0d04228: 3301 adds r3, #1 c0d0422a: 429a cmp r2, r3 c0d0422c: d1fa bne.n c0d04224 <memcpy+0x60> c0d0422e: bd70 pop {r4, r5, r6, pc} c0d04230: 0005 movs r5, r0 c0d04232: 2a00 cmp r2, #0 c0d04234: d1f5 bne.n c0d04222 <memcpy+0x5e> c0d04236: e7fa b.n c0d0422e <memcpy+0x6a> c0d04238: 0005 movs r5, r0 c0d0423a: e7f2 b.n c0d04222 <memcpy+0x5e> c0d0423c: 001a movs r2, r3 c0d0423e: e7f8 b.n c0d04232 <memcpy+0x6e> c0d04240 <memset>: c0d04240: b570 push {r4, r5, r6, lr} c0d04242: 0783 lsls r3, r0, #30 c0d04244: d03f beq.n c0d042c6 <memset+0x86> c0d04246: 1e54 subs r4, r2, #1 c0d04248: 2a00 cmp r2, #0 c0d0424a: d03b beq.n c0d042c4 <memset+0x84> c0d0424c: b2ce uxtb r6, r1 c0d0424e: 0003 movs r3, r0 c0d04250: 2503 movs r5, #3 c0d04252: e003 b.n c0d0425c <memset+0x1c> c0d04254: 1e62 subs r2, r4, #1 c0d04256: 2c00 cmp r4, #0 c0d04258: d034 beq.n c0d042c4 <memset+0x84> c0d0425a: 0014 movs r4, r2 c0d0425c: 3301 adds r3, #1 c0d0425e: 1e5a subs r2, r3, #1 c0d04260: 7016 strb r6, [r2, #0] c0d04262: 422b tst r3, r5 c0d04264: d1f6 bne.n c0d04254 <memset+0x14> c0d04266: 2c03 cmp r4, #3 c0d04268: d924 bls.n c0d042b4 <memset+0x74> c0d0426a: 25ff movs r5, #255 ; 0xff c0d0426c: 400d ands r5, r1 c0d0426e: 022a lsls r2, r5, #8 c0d04270: 4315 orrs r5, r2 c0d04272: 042a lsls r2, r5, #16 c0d04274: 4315 orrs r5, r2 c0d04276: 2c0f cmp r4, #15 c0d04278: d911 bls.n c0d0429e <memset+0x5e> c0d0427a: 0026 movs r6, r4 c0d0427c: 3e10 subs r6, #16 c0d0427e: 0936 lsrs r6, r6, #4 c0d04280: 3601 adds r6, #1 c0d04282: 0136 lsls r6, r6, #4 c0d04284: 001a movs r2, r3 c0d04286: 199b adds r3, r3, r6 c0d04288: 6015 str r5, [r2, #0] c0d0428a: 6055 str r5, [r2, #4] c0d0428c: 6095 str r5, [r2, #8] c0d0428e: 60d5 str r5, [r2, #12] c0d04290: 3210 adds r2, #16 c0d04292: 4293 cmp r3, r2 c0d04294: d1f8 bne.n c0d04288 <memset+0x48> c0d04296: 220f movs r2, #15 c0d04298: 4014 ands r4, r2 c0d0429a: 2c03 cmp r4, #3 c0d0429c: d90a bls.n c0d042b4 <memset+0x74> c0d0429e: 1f26 subs r6, r4, #4 c0d042a0: 08b6 lsrs r6, r6, #2 c0d042a2: 3601 adds r6, #1 c0d042a4: 00b6 lsls r6, r6, #2 c0d042a6: 001a movs r2, r3 c0d042a8: 199b adds r3, r3, r6 c0d042aa: c220 stmia r2!, {r5} c0d042ac: 4293 cmp r3, r2 c0d042ae: d1fc bne.n c0d042aa <memset+0x6a> c0d042b0: 2203 movs r2, #3 c0d042b2: 4014 ands r4, r2 c0d042b4: 2c00 cmp r4, #0 c0d042b6: d005 beq.n c0d042c4 <memset+0x84> c0d042b8: b2c9 uxtb r1, r1 c0d042ba: 191c adds r4, r3, r4 c0d042bc: 7019 strb r1, [r3, #0] c0d042be: 3301 adds r3, #1 c0d042c0: 429c cmp r4, r3 c0d042c2: d1fb bne.n c0d042bc <memset+0x7c> c0d042c4: bd70 pop {r4, r5, r6, pc} c0d042c6: 0014 movs r4, r2 c0d042c8: 0003 movs r3, r0 c0d042ca: e7cc b.n c0d04266 <memset+0x26> c0d042cc <setjmp>: c0d042cc: c0f0 stmia r0!, {r4, r5, r6, r7} c0d042ce: 4641 mov r1, r8 c0d042d0: 464a mov r2, r9 c0d042d2: 4653 mov r3, sl c0d042d4: 465c mov r4, fp c0d042d6: 466d mov r5, sp c0d042d8: 4676 mov r6, lr c0d042da: c07e stmia r0!, {r1, r2, r3, r4, r5, r6} c0d042dc: 3828 subs r0, #40 ; 0x28 c0d042de: c8f0 ldmia r0!, {r4, r5, r6, r7} c0d042e0: 2000 movs r0, #0 c0d042e2: 4770 bx lr c0d042e4 <longjmp>: c0d042e4: 3010 adds r0, #16 c0d042e6: c87c ldmia r0!, {r2, r3, r4, r5, r6} c0d042e8: 4690 mov r8, r2 c0d042ea: 4699 mov r9, r3 c0d042ec: 46a2 mov sl, r4 c0d042ee: 46ab mov fp, r5 c0d042f0: 46b5 mov sp, r6 c0d042f2: c808 ldmia r0!, {r3} c0d042f4: 3828 subs r0, #40 ; 0x28 c0d042f6: c8f0 ldmia r0!, {r4, r5, r6, r7} c0d042f8: 1c08 adds r0, r1, #0 c0d042fa: d100 bne.n c0d042fe <longjmp+0x1a> c0d042fc: 2001 movs r0, #1 c0d042fe: 4718 bx r3 c0d04300 <strlen>: c0d04300: b510 push {r4, lr} c0d04302: 0783 lsls r3, r0, #30 c0d04304: d027 beq.n c0d04356 <strlen+0x56> c0d04306: 7803 ldrb r3, [r0, #0] c0d04308: 2b00 cmp r3, #0 c0d0430a: d026 beq.n c0d0435a <strlen+0x5a> c0d0430c: 0003 movs r3, r0 c0d0430e: 2103 movs r1, #3 c0d04310: e002 b.n c0d04318 <strlen+0x18> c0d04312: 781a ldrb r2, [r3, #0] c0d04314: 2a00 cmp r2, #0 c0d04316: d01c beq.n c0d04352 <strlen+0x52> c0d04318: 3301 adds r3, #1 c0d0431a: 420b tst r3, r1 c0d0431c: d1f9 bne.n c0d04312 <strlen+0x12> c0d0431e: 6819 ldr r1, [r3, #0] c0d04320: 4a0f ldr r2, [pc, #60] ; (c0d04360 <strlen+0x60>) c0d04322: 4c10 ldr r4, [pc, #64] ; (c0d04364 <strlen+0x64>) c0d04324: 188a adds r2, r1, r2 c0d04326: 438a bics r2, r1 c0d04328: 4222 tst r2, r4 c0d0432a: d10f bne.n c0d0434c <strlen+0x4c> c0d0432c: 3304 adds r3, #4 c0d0432e: 6819 ldr r1, [r3, #0] c0d04330: 4a0b ldr r2, [pc, #44] ; (c0d04360 <strlen+0x60>) c0d04332: 188a adds r2, r1, r2 c0d04334: 438a bics r2, r1 c0d04336: 4222 tst r2, r4 c0d04338: d108 bne.n c0d0434c <strlen+0x4c> c0d0433a: 3304 adds r3, #4 c0d0433c: 6819 ldr r1, [r3, #0] c0d0433e: 4a08 ldr r2, [pc, #32] ; (c0d04360 <strlen+0x60>) c0d04340: 188a adds r2, r1, r2 c0d04342: 438a bics r2, r1 c0d04344: 4222 tst r2, r4 c0d04346: d0f1 beq.n c0d0432c <strlen+0x2c> c0d04348: e000 b.n c0d0434c <strlen+0x4c> c0d0434a: 3301 adds r3, #1 c0d0434c: 781a ldrb r2, [r3, #0] c0d0434e: 2a00 cmp r2, #0 c0d04350: d1fb bne.n c0d0434a <strlen+0x4a> c0d04352: 1a18 subs r0, r3, r0 c0d04354: bd10 pop {r4, pc} c0d04356: 0003 movs r3, r0 c0d04358: e7e1 b.n c0d0431e <strlen+0x1e> c0d0435a: 2000 movs r0, #0 c0d0435c: e7fa b.n c0d04354 <strlen+0x54> c0d0435e: 46c0 nop ; (mov r8, r8) c0d04360: fefefeff .word 0xfefefeff c0d04364: 80808080 .word 0x80808080 c0d04368 <TXT_BLANK>: c0d04368: 20202020 20202020 20202020 20202020 c0d04378: 32310020 . c0d0437a <BASE_58_ALPHABET>: c0d0437a: 34333231 38373635 43424139 47464544 123456789ABCDEFG c0d0438a: 4c4b4a48 51504e4d 55545352 59585756 HJKLMNPQRSTUVWXY c0d0439a: 6362615a 67666564 6b6a6968 706f6e6d Zabcdefghijkmnop c0d043aa: 74737271 78777675 31307a79 qrstuvwxyz c0d043b4 <g_pcHex>: c0d043b4: 33323130 37363534 62613938 66656463 0123456789abcdef c0d043c4 <g_pcHex_cap>: c0d043c4: 33323130 37363534 42413938 46454443 0123456789ABCDEF c0d043d4: 4f525245 006f0052 ERROR. c0d043da <SW_INTERNAL>: c0d043da: 0190006f o. c0d043dc <SW_BUSY>: c0d043dc: 00670190 .. c0d043de <SW_WRONG_LENGTH>: c0d043de: 85690067 g. c0d043e0 <SW_PROOF_OF_PRESENCE_REQUIRED>: c0d043e0: 806a8569 i. c0d043e2 <SW_BAD_KEY_HANDLE>: c0d043e2: 3255806a j. c0d043e4 <U2F_VERSION>: c0d043e4: 5f463255 00903256 U2F_V2.. c0d043ec <INFO>: c0d043ec: 00900901 .... c0d043f0 <SW_UNKNOWN_CLASS>: c0d043f0: 006d006e n. c0d043f2 <SW_UNKNOWN_INSTRUCTION>: c0d043f2: ffff006d m. c0d043f4 <BROADCAST_CHANNEL>: c0d043f4: ffffffff .... c0d043f8 <FORBIDDEN_CHANNEL>: c0d043f8: 00000000 20657241 20756f79 65727573 ....Are you sure c0d04408: 6557003f 6d6f636c 6f422065 736f7474 ?.Welcome Bottos c0d04418: 72655600 6e6f6973 302e3120 4300302e .Version 1.0.0.C c0d04428: 69666e6f 53206d72 206e6769 3f207854 onfirm Sign Tx ? c0d04438: 00000000 .... c0d0443c <bagl_ui_test_nanos>: c0d0443c: 00000003 00800000 00000020 00000001 ........ ....... c0d0444c: 00000000 00ffffff 00000000 00000000 ................ ... c0d04474: 00030005 0007000c 00000007 00000000 ................ c0d04484: 00ffffff 00000000 00070000 00000000 ................ ... c0d044ac: 00750005 0008000d 00000006 00000000 ..u............. c0d044bc: 00ffffff 00000000 00060000 00000000 ................ ... c0d044e4: 00000107 0080000c 0000000c 00000000 ................ c0d044f4: 00ffffff 00000000 00008008 c0d043fc .............C.. ... c0d0451c <bagl_ui_idle_nanos>: c0d0451c: 00000003 00800000 00000020 00000001 ........ ....... c0d0452c: 00000000 00ffffff 00000000 00000000 ................ ... c0d04554: 00000207 0080000c 0000000b 00000000 ................ c0d04564: 00ffffff 00000000 00008008 c0d0440a .............D.. ... c0d0458c: 000a0207 006c001c 008a000b 00000000 ......l......... c0d0459c: 00ffffff 00000000 0000800a c0d04419 .............D.. ... c0d045c4: 00030005 0007000c 00000007 00000000 ................ c0d045d4: 00ffffff 00000000 00070000 00000000 ................ ... c0d045fc <bagl_ui_sign_hash_nanos>: c0d045fc: 00000003 00800000 00000020 00000001 ........ ....... c0d0460c: 00000000 00ffffff 00000000 00000000 ................ ... c0d04634: 00000207 0080000c 0000000b 00000000 ................ c0d04644: 00ffffff 00000000 00008008 c0d04427 ............'D.. ... c0d0466c: 000a0207 006c001c 008a000b 00000000 ......l......... c0d0467c: 00ffffff 00000000 0000800a 20001b00 ............... ... c0d046a4: 00030005 0007000c 00000007 00000000 ................ c0d046b4: 00ffffff 00000000 00070000 00000000 ................ ... c0d046dc: 00750005 0007000c 00000007 00000000 ..u............. c0d046ec: 00ffffff 00000000 00060000 00000000 ................ ... c0d04714 <USBD_HID_Desc_fido>: c0d04714: 01112109 22220121 00000000 .!..!."".... c0d04720 <USBD_HID_Desc>: c0d04720: 01112109 22220100 f1d00600 .!...."". c0d04729 <HID_ReportDesc_fido>: c0d04729: 09f1d006 0901a101 26001503 087500ff ...........&..u. c0d04739: 08814095 00150409 7500ff26 91409508 .@......&..u..@. c0d04749: a006c008 .. c0d0474b <HID_ReportDesc>: c0d0474b: 09ffa006 0901a101 26001503 087500ff ...........&..u. c0d0475b: 08814095 00150409 7500ff26 91409508 .@......&..u..@. c0d0476b: 0000c008 d03e4d00 ..... c0d04770 <HID_Desc>: c0d04770: c0d03e4d c0d03e5d c0d03e6d c0d03e7d M>..]>..m>..}>.. c0d04780: c0d03e8d c0d03e9d c0d03ead 00000000 .>...>...>...... c0d04790 <C_webusb_url_descriptor>: c0d04790: 77010317 6c2e7777 65676465 6c617772 ...www.ledgerwal c0d047a0: 2e74656c 056d6f63 let.com c0d047a7 <C_usb_bos>: c0d047a7: 001d0f05 05101801 08b63800 a009a934 .........8..4... c0d047b7: a0fd8b47 b6158876 1e010065 d03bdb01 G...v...e.... c0d047c4 <USBD_HID>: c0d047c4: c0d03bdb c0d03c0d c0d03b43 00000000 .;...<..C;...... c0d047d4: 00000000 c0d03d39 c0d03d51 00000000 ....9=..Q=...... ... c0d047ec: c0d03fa1 c0d03fa1 c0d03fa1 c0d03fb1 .?...?...?...?.. c0d047fc <USBD_U2F>: c0d047fc: c0d03cc1 c0d03c0d c0d03b43 00000000 .<...<..C;...... c0d0480c: 00000000 c0d03cf5 c0d03d0d 00000000 .....<...=...... ... c0d04824: c0d03fa1 c0d03fa1 c0d03fa1 c0d03fb1 .?...?...?...?.. c0d04834 <USBD_WEBUSB>: c0d04834: c0d03da9 c0d03dd5 c0d03dd9 00000000 .=...=...=...... c0d04844: 00000000 c0d03ddd c0d03df5 00000000 .....=...=...... ... c0d0485c: c0d03fa1 c0d03fa1 c0d03fa1 c0d03fb1 .?...?...?...?.. c0d0486c <USBD_DeviceDesc>: c0d0486c: 02000112 40000000 00012c97 02010200 .......@.,...... c0d0487c: 03040103 .. c0d0487e <USBD_LangIDDesc>: c0d0487e: 04090304 .... c0d04882 <USBD_MANUFACTURER_STRING>: c0d04882: 004c030e 00640065 00650067 030e0072 ..L.e.d.g.e.r. c0d04890 <USBD_PRODUCT_FS_STRING>: c0d04890: 004e030e 006e0061 0020006f 030a0053 ..N.a.n.o. .S. c0d0489e <USB_SERIAL_STRING>: c0d0489e: 0030030a 00300030 02090031 ..0.0.0.1. c0d048a8 <USBD_CfgDesc>: c0d048a8: 00600209 c0020103 00040932 00030200 ..`.....2....... c0d048b8: 21090200 01000111 07002222 40038205 ...!...."".....@ c0d048c8: 05070100 00400302 01040901 01030200 ......@......... c0d048d8: 21090201 01210111 07002222 40038105 ...!..!."".....@ c0d048e8: 05070100 00400301 02040901 ffff0200 ......@......... c0d048f8: 050702ff 00400383 03050701 01004003 ......@......@.. c0d04908 <USBD_DeviceQualifierDesc>: c0d04908: 0200060a 40000000 00000001 .......@.... c0d04914 <_etext>: ...
; A083337: a(n) = 2*a(n-1) + 2*a(n-2); a(0)=0, a(1)=3. ; 0,3,6,18,48,132,360,984,2688,7344,20064,54816,149760,409152,1117824,3053952,8343552,22795008,62277120,170144256,464842752,1269974016,3469633536,9479215104,25897697280,70753824768,193303044096,528113737728,1442833563648,3941894602752,10769456332800,29422701871104,80384316407808,219614036557824,599996705931264,1639221484978176,4478436381818880 mov $2,3 lpb $0,1 sub $0,1 add $1,$2 mov $3,$2 mov $2,$1 add $2,$1 mov $1,$3 lpe
;=============================================================================== ; Copyright 2015-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. ;=============================================================================== ; ; ; Purpose: Cryptography Primitive. ; Rijndael Inverse Cipher function ; ; Content: ; AuthEncrypt_RIJ128_AES_NI() ; DecryptAuth_RIJ128_AES_NI() ; ; include asmdefs.inc include ia_32e.inc include pcpvariant.inc IF (_AES_NI_ENABLING_ EQ _FEATURE_ON_) OR (_AES_NI_ENABLING_ EQ _FEATURE_TICKTOCK_) IF (_IPP32E GE _IPP32E_Y8) IPPCODE SEGMENT 'CODE' ALIGN (IPP_ALIGN_FACTOR) ALIGN IPP_ALIGN_FACTOR u128_str DB 15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0 increment DQ 1,0 ;*************************************************************** ;* Purpose: Authenticate and Encrypt ;* ;* void AuthEncrypt_RIJ128_AES_NI(Ipp8u* outBlk, ;* const Ipp8u* inpBlk, ;* int nr, ;* const Ipp8u* pRKey, ;* Ipp32u len, ;* Ipp8u* pLocalState) ;* inp localCtx: ;* MAC ;* CTRi ;* CTRi mask ;* ;* out localCtx: ;* new MAC ;* S = enc(CTRi) ;*************************************************************** ;; ;; Lib = Y8 ;; ;; Caller = ippsAES_CCMEncrypt ;; ALIGN IPP_ALIGN_FACTOR IPPASM AuthEncrypt_RIJ128_AES_NI PROC PUBLIC FRAME USES_GPR rsi, rdi, rbx LOCAL_FRAME = 0 USES_XMM xmm6, xmm7 COMP_ABI 6 ;; rdi: pInpBlk: PTR BYTE, ; input blocks address ;; rsi: pOutBlk: PTR BYTE, ; output blocks address ;; rdx: nr: DWORD, ; number of rounds ;; rcx pKey: PTR BYTE, ; key material address ;; r8d length: DWORD, ; length (bytes) ;; r9 pLocCtx: PTR BYTE ; pointer to the localState BYTES_PER_BLK = (16) movdqa xmm0, oword ptr [r9] ; MAC movdqa xmm2, oword ptr [r9+sizeof(oword)] ; CTRi block movdqa xmm1, oword ptr [r9+sizeof(oword)*2] ; CTR mask movdqa xmm7, oword ptr u128_str pshufb xmm2, xmm7 ; CTRi block (LE) pshufb xmm1, xmm7 ; CTR mask movdqa xmm3, xmm1 pandn xmm3, xmm2 ; CTR block template pand xmm2, xmm1 ; CTR value mov r8d, r8d ; expand length movsxd rdx, edx ; expand number of rounds lea rdx, [rdx*4] ; nrCounter = -nr*16 lea rdx, [rdx*4] ; pKey += nr*16 lea rcx, [rcx+rdx] neg rdx mov rbx, rdx ALIGN IPP_ALIGN_FACTOR ;; ;; block-by-block processing ;; blk_loop: movdqu xmm4, oword ptr [rdi] ; input block src[i] pxor xmm0, xmm4 ; MAC ^= src[i] movdqa xmm5, xmm3 paddq xmm2, oword ptr increment ; advance counter bits pand xmm2, xmm1 ; and mask them por xmm5, xmm2 pshufb xmm5, xmm7 ; CTRi (BE) movdqa xmm6, oword ptr [rcx+rdx] ; keys for whitening add rdx, 16 pxor xmm5, xmm6 ; whitening (CTRi) pxor xmm0, xmm6 ; whitening (MAC) movdqa xmm6, oword ptr [rcx+rdx] ; pre load operation's keys ALIGN IPP_ALIGN_FACTOR cipher_loop: aesenc xmm5, xmm6 ; regular round (CTRi) aesenc xmm0, xmm6 ; regular round (MAC) movdqa xmm6, oword ptr [rcx+rdx+16] add rdx, 16 jnz cipher_loop aesenclast xmm5, xmm6 ; irregular round (CTRi) aesenclast xmm0, xmm6 ; irregular round (MAC) pxor xmm4, xmm5 ; dst[i] = src[i] ^ ENC(CTRi) movdqu oword ptr[rsi], xmm4 mov rdx, rbx add rsi, BYTES_PER_BLK add rdi, BYTES_PER_BLK sub r8, BYTES_PER_BLK jnz blk_loop movdqu oword ptr[r9], xmm0 ; update MAC value movdqu oword ptr[r9+sizeof(oword)], xmm5 ; update ENC(Ctri) pxor xmm6, xmm6 REST_XMM REST_GPR ret IPPASM AuthEncrypt_RIJ128_AES_NI ENDP ;*************************************************************** ;* Purpose: Decrypt and Authenticate ;* ;* void DecryptAuth_RIJ128_AES_NI(Ipp8u* outBlk, ;* const Ipp8u* inpBlk, ;* int nr, ;* const Ipp8u* pRKey, ;* Ipp32u len, ;* Ipp8u* pLocalState) ;* inp localCtx: ;* MAC ;* CTRi ;* CTRi mask ;* ;* out localCtx: ;* new MAC ;* S = enc(CTRi) ;*************************************************************** ;; ;; Lib = Y8 ;; ;; Caller = ippsAES_CCMDecrypt ;; ALIGN IPP_ALIGN_FACTOR IPPASM DecryptAuth_RIJ128_AES_NI PROC PUBLIC FRAME USES_GPR rsi, rdi, rbx LOCAL_FRAME = sizeof(qword) USES_XMM xmm6, xmm7 COMP_ABI 6 ;; rdi: pInpBlk: PTR BYTE, ; input blocks address ;; rsi: pOutBlk: PTR BYTE, ; output blocks address ;; rdx: nr: DWORD, ; number of rounds ;; rcx pKey: PTR BYTE, ; key material address ;; r8d length: DWORD, ; length (bytes) ;; r9 pLocCtx: PTR BYTE ; pointer to the localState BYTES_PER_BLK = (16) movdqa xmm0, oword ptr [r9] ; MAC movdqa xmm2, oword ptr [r9+sizeof(oword)] ; CTRi block movdqa xmm1, oword ptr [r9+sizeof(oword)*2] ; CTR mask movdqa xmm7, oword ptr u128_str pshufb xmm2, xmm7 ; CTRi block (LE) pshufb xmm1, xmm7 ; CTR mask movdqa xmm3, xmm1 pandn xmm3, xmm2 ; CTR block template pand xmm2, xmm1 ; CTR value mov r8d, r8d ; expand length movsxd rdx, edx ; expand number of rounds lea rdx, [rdx*4] ; nrCounter = -nr*16 lea rdx, [rdx*4] ; pKey += nr*16 lea rcx, [rcx+rdx] neg rdx mov rbx, rdx ALIGN IPP_ALIGN_FACTOR ;; ;; block-by-block processing ;; blk_loop: ;;;;;;;;;;;;;;;;; ;; decryption ;;;;;;;;;;;;;;;;; movdqu xmm4, oword ptr [rdi] ; input block src[i] movdqa xmm5, xmm3 paddq xmm2, oword ptr increment ; advance counter bits pand xmm2, xmm1 ; and mask them por xmm5, xmm2 pshufb xmm5, xmm7 ; CTRi (BE) movdqa xmm6, oword ptr [rcx+rdx] ; keys for whitening add rdx, 16 pxor xmm5, xmm6 ; whitening (CTRi) movdqa xmm6, oword ptr [rcx+rdx] ; pre load operation's keys ALIGN IPP_ALIGN_FACTOR cipher_loop: aesenc xmm5, xmm6 ; regular round (CTRi) movdqa xmm6, oword ptr [rcx+rdx+16] add rdx, 16 jnz cipher_loop aesenclast xmm5, xmm6 ; irregular round (CTRi) pxor xmm4, xmm5 ; dst[i] = src[i] ^ ENC(CTRi) movdqu oword ptr[rsi], xmm4 ;;;;;;;;;;;;;;;;; ;; update MAC ;;;;;;;;;;;;;;;;; mov rdx, rbx movdqa xmm6, oword ptr [rcx+rdx] ; keys for whitening add rdx, 16 pxor xmm0, xmm4 ; MAC ^= dst[i] pxor xmm0, xmm6 ; whitening (MAC) movdqa xmm6, oword ptr [rcx+rdx] ; pre load operation's keys ALIGN IPP_ALIGN_FACTOR auth_loop: aesenc xmm0, xmm6 ; regular round (MAC) movdqa xmm6, oword ptr [rcx+rdx+16] add rdx, 16 jnz auth_loop aesenclast xmm0, xmm6 ; irregular round (MAC) mov rdx, rbx add rsi, BYTES_PER_BLK add rdi, BYTES_PER_BLK sub r8, BYTES_PER_BLK jnz blk_loop movdqu oword ptr[r9], xmm0 ; update MAC value movdqu oword ptr[r9+sizeof(oword)], xmm6 ; update ENC(Ctri) pxor xmm6, xmm6 REST_XMM REST_GPR ret IPPASM DecryptAuth_RIJ128_AES_NI ENDP ENDIF ENDIF ;; _AES_NI_ENABLING_ END
extern kmain [bits 32] _start: call kmain
; @file irq_stubs.asm ; @author Konstantin Tcholokachvili ; @date 2014, 2016 ; ; Interrupt Requests (IRQs) section .text ; The address of the table of handlers (defined in irq.c) [extern x86_irq_handler_array] ; The address of the table of wrappers (defined below, and shared with irq.c) [global x86_irq_wrapper_array] %macro SAVE_REGISTERS 0 push edi push esi push edx push ecx push ebx push eax sub esp, 2 push word ss push word ds push word es push word fs push word gs %endmacro %macro RESTORE_REGISTERS 0 pop word gs pop word fs pop word es pop word ds pop word ss add esp, 2 pop eax pop ebx pop ecx pop edx pop esi pop edi pop ebp %endmacro ; These pre-handlers are for IRQ (Master PIC) %macro X86_IRQ_WRAPPER_MASTER 1 align 4 x86_irq_wrapper_%1: ; Fake error code push 0 ; Backup the actual context push ebp mov ebp, esp SAVE_REGISTERS ; Send EOI to PIC. See Intel 8259 datasheet mov al, 0x20 out byte 0x20, al ; Call the handler with IRQ number as argument push %1 lea edi, [x86_irq_handler_array] call [edi+4*%1] add esp, 4 RESTORE_REGISTERS ; Remove fake error code add esp, 4 iret %endmacro ; These pre-handlers are for IRQ (Slave PIC) %macro X86_IRQ_WRAPPER_SLAVE 1 align 4 x86_irq_wrapper_%1: ; Fake error code push 0 ; Backup the actual context push ebp mov ebp, esp SAVE_REGISTERS ; Send EOI to PIC. See Intel 8259 datasheet mov byte al, 0x20 out byte 0xa0, al out byte 0x20, al ; Call the handler with IRQ number as argument push %1 lea edi, [x86_irq_handler_array] call [edi+4*%1] add esp, 4 RESTORE_REGISTERS ; Remove fake error code add esp, 4 iret %endmacro X86_IRQ_WRAPPER_MASTER 0 X86_IRQ_WRAPPER_MASTER 1 X86_IRQ_WRAPPER_MASTER 2 X86_IRQ_WRAPPER_MASTER 3 X86_IRQ_WRAPPER_MASTER 4 X86_IRQ_WRAPPER_MASTER 5 X86_IRQ_WRAPPER_MASTER 6 X86_IRQ_WRAPPER_MASTER 7 X86_IRQ_WRAPPER_SLAVE 8 X86_IRQ_WRAPPER_SLAVE 9 X86_IRQ_WRAPPER_SLAVE 10 X86_IRQ_WRAPPER_SLAVE 11 X86_IRQ_WRAPPER_SLAVE 12 X86_IRQ_WRAPPER_SLAVE 13 X86_IRQ_WRAPPER_SLAVE 14 X86_IRQ_WRAPPER_SLAVE 15 section .rodata ; Build the x86_irq_wrapper_array, shared with irq.c align 32, db 0 x86_irq_wrapper_array: dd x86_irq_wrapper_0 dd x86_irq_wrapper_1 dd x86_irq_wrapper_2 dd x86_irq_wrapper_3 dd x86_irq_wrapper_4 dd x86_irq_wrapper_5 dd x86_irq_wrapper_6 dd x86_irq_wrapper_7 dd x86_irq_wrapper_8 dd x86_irq_wrapper_9 dd x86_irq_wrapper_10 dd x86_irq_wrapper_11 dd x86_irq_wrapper_12 dd x86_irq_wrapper_13 dd x86_irq_wrapper_14 dd x86_irq_wrapper_15
%define BPM 100 %include "../src/sointu.inc" BEGIN_PATTERNS PATTERN 64, HLD, HLD, HLD, HLD, HLD, HLD, HLD, 0, 0, 0, 0, 0, 0, 0, 0 END_PATTERNS BEGIN_TRACKS TRACK VOICES(1),0 END_TRACKS BEGIN_PATCH BEGIN_INSTRUMENT VOICES(1) ; Instrument0 SU_LOADVAL MONO,VALUE(0) SU_OUTAUX MONO,OUTGAIN(32),AUXGAIN(64) SU_IN MONO,CHANNEL(0) SU_IN MONO,CHANNEL(2) SU_LOADVAL MONO,VALUE(48) SU_LOADVAL MONO,VALUE(128) SU_ADDP STEREO SU_OUT STEREO,GAIN(128) END_INSTRUMENT END_PATCH %include "../src/sointu.asm"
; A250661: Number of (7+1) X (n+1) 0..1 arrays with nondecreasing x(i,j)-x(i,j-1) in the i direction and nondecreasing min(x(i,j),x(i-1,j)) in the j direction. ; 639,1150,1789,2556,3451,4474,5625,6904,8311,9846,11509,13300,15219,17266,19441,21744,24175,26734,29421,32236,35179,38250,41449,44776,48231,51814,55525,59364,63331,67426,71649,76000,80479,85086,89821,94684,99675 mov $2,$0 mul $0,8 lpb $0 sub $0,1 add $1,$0 add $1,$0 lpe lpb $2 add $1,455 sub $2,1 lpe add $1,639
; A017193: a(n) = (9*n + 2)^9. ; 512,2357947691,512000000000,14507145975869,165216101262848,1119130473102767,5416169448144896,20711912837890625,66540410775079424,186940255267540403,472161363286556672,1093685272684360901,2357947691000000000,4785448563124474679,9223372036854775808,17001416405572203977,30142252394633171456,51639887032560546875,85821209809770512384,138808137876363860813,219100057666451666432,338298681559573317311,512000000000000000000,760880711892098878289,1112009359074462407168,1600415374247183470787 mul $0,9 add $0,2 pow $0,9
; ; ; ZX Maths Routines ; ; 8/12/02 - Stefano Bodrato ; ; $Id: pow.asm,v 1.1 2003/03/24 09:17:40 stefano Exp $ ; ;double pow(double x,double y) ;y is in the FA ;x is on the stack +8 (+2=y) ; IF FORzx INCLUDE "#zxfp.def" ELSE INCLUDE "#81fp.def" ENDIF XLIB pow LIB fsetupf LIB stkequ .pow call fsetupf defb ZXFP_TO_POWER defb ZXFP_END_CALC jp stkequ
; A038154: a(n) = n! * Sum_{k=0..n-2} 1/k!. ; 0,0,2,12,60,320,1950,13692,109592,986400,9864090,108505100,1302061332,16926797472,236975164790,3554627472060,56874039553200,966858672404672,17403456103284402,330665665962403980,6613313319248079980,138879579704209680000 lpb $0 sub $0,1 add $1,$0 add $2,$0 mul $2,$0 add $1,$2 lpe mov $0,$1
/* Copyright 2013-present Barefoot Networks, Inc. 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. */ #include <ctype.h> #include "bitvec.h" #include "hex.h" std::ostream &operator<<(std::ostream &os, const bitvec &bv) { if (bv.size == 1) { os << hex(bv.data); } else { bool first = true; for (int i = bv.size-1; i >= 0; i--) { if (first) { if (!bv.ptr[i]) continue; os << hex(bv.ptr[i]); first = false; } else { os << hex(bv.ptr[i], sizeof(bv.data)*2, '0'); } } if (first) os << '0'; } return os; } std::istream &operator>>(std::istream &is, bitvec &bv) { char ch; while (is && isspace((ch = is.get()))) {} if (!is) return is; if (!isxdigit(ch)) { is.unget(); is.setstate(std::ios_base::failbit); } else { bv.clear(); do { bv <<= 4; if (isdigit(ch)) bv |= ch - '0'; if (islower(ch)) bv |= ch - 'a' + 10; if (isupper(ch)) bv |= ch - 'A' + 10; ch = is.get(); } while (is && isxdigit(ch)); if (is) is.unget(); } return is; } bool operator>>(const char *s, bitvec &bv) { bv.clear(); while (*s) { if (!isxdigit(*s)) return false; bv <<= 4; if (isdigit(*s)) bv |= *s - '0'; if (islower(*s)) bv |= *s - 'a' + 10; if (isupper(*s)) bv |= *s - 'A' + 10; s++; } return true; } bitvec &bitvec::operator>>=(size_t count) { if (size == 1) { if (count >= bits_per_unit) data = 0; else data >>= count; return *this; } int off = count / bits_per_unit; count %= bits_per_unit; for (size_t i = 0; i < size; i++) if (i + off < size) { ptr[i] = ptr[i+off] >> count; if (count && i + off + 1 < size) ptr[i] |= ptr[i+off+1] << (bits_per_unit - count); } else { ptr[i] = 0; } while (size > 1 && !ptr[size-1]) size--; if (size == 1) { auto tmp = ptr[0]; delete [] ptr; data = tmp; } return *this; } bitvec &bitvec::operator<<=(size_t count) { size_t needsize = (max().index() + count + bits_per_unit)/bits_per_unit; if (needsize > size) expand(needsize); if (size == 1) { data <<= count; return *this; } int off = count / bits_per_unit; count %= bits_per_unit; for (int i = size-1; i >= 0; i--) if (i >= off) { ptr[i] = ptr[i-off] << count; if (count && i > off) ptr[i] |= ptr[i-off-1] >> (bits_per_unit - count); } else { ptr[i] = 0; } return *this; } bitvec bitvec::getslice(size_t idx, size_t sz) const { if (sz == 0) return bitvec(); if (idx >= size * bits_per_unit) return bitvec(); if (idx + sz > size * bits_per_unit) sz = size * bits_per_unit - idx; if (size > 1) { bitvec rv; unsigned shift = idx % bits_per_unit; idx /= bits_per_unit; if (sz > bits_per_unit) { rv.expand((sz-1)/bits_per_unit + 1); for (size_t i = 0; i < rv.size; i++) { if (shift != 0 && i != 0) rv.ptr[i-1] |= ptr[idx + i] << (bits_per_unit - shift); rv.ptr[i] = ptr[idx + i] >> shift; } if ((sz %= bits_per_unit)) rv.ptr[rv.size-1] &= ~(~static_cast<uintptr_t>(1) << (sz-1)); } else { rv.data = ptr[idx] >> shift; if (shift != 0 && idx + 1 < size) rv.data |= ptr[idx + 1] << (bits_per_unit - shift); rv.data &= ~(~static_cast<uintptr_t>(1) << (sz-1)); } return rv; } else { return bitvec((data >> idx) & ~(~static_cast<uintptr_t>(1) << (sz-1))); } } int bitvec::ffs(unsigned start) const { uintptr_t val = ~static_cast<uintptr_t>(0); unsigned idx = start / bits_per_unit; val <<= (start % bits_per_unit); while (idx < size && !(val &= word(idx))) { ++idx; val = ~static_cast<uintptr_t>(0); } if (idx >= size) return -1; unsigned rv = idx * bits_per_unit; #if defined(__GNUC__) || defined(__clang__) rv += builtin_ctz(val); #else while ((val & 0xff) == 0) { rv += 8; val >>= 8; } while ((val & 1) == 0) { rv++; val >>= 1; } #endif return rv; } unsigned bitvec::ffz(unsigned start) const { uintptr_t val = static_cast<uintptr_t>(0); unsigned idx = start / bits_per_unit; val = ~(~val << (start % bits_per_unit)); while (!~(val |= word(idx))) { ++idx; val = 0; } unsigned rv = idx * bits_per_unit; #if defined(__GNUC__) || defined(__clang__) rv += builtin_ctz(~val); #else while ((val & 0xff) == 0xff) { rv += 8; val >>= 8; } while (val & 1) { rv++; val >>= 1; } #endif return rv; } bool bitvec::is_contiguous() const { // Empty bitvec is not contiguous if (empty()) return false; return max().index() - min().index() + 1 == popcount(); } bitvec bitvec::rotate_right_helper(size_t start_bit, size_t rotation_idx, size_t end_bit) const { assert(start_bit <= rotation_idx && rotation_idx < end_bit); bitvec rot_mask(start_bit, end_bit - start_bit); bitvec rotation_section = *this & rot_mask; int down_shift = rotation_idx - start_bit; int up_shift = (end_bit - start_bit) - down_shift; bitvec rv; rv = (rotation_section >> down_shift) | (rotation_section << up_shift); return rv & rot_mask; } /** * Designed to imitate the std::rotate/std::rotate_copy function for vectors. Return a bitvec * which has the bit at rotation_idx appear at start_bit, and the corresponding data * between start_bit and end_bit rotated. Similar to std::rotate/std::rotate_copy, end_bit is * exclusive */ void bitvec::rotate_right(size_t start_bit, size_t rotation_idx, size_t end_bit) { bitvec rot_section = rotate_right_helper(start_bit, rotation_idx, end_bit); clrrange(start_bit, end_bit - start_bit); *this |= rot_section; } bitvec bitvec::rotate_right_copy(size_t start_bit, size_t rotation_idx, size_t end_bit) const { bitvec rot_section = rotate_right_helper(start_bit, rotation_idx, end_bit); bitvec rot_mask(start_bit, end_bit - start_bit); bitvec rv = rot_section | (*this - rot_mask); return rv; }
; A017034: a(n) = (7*n + 4)^6. ; 4096,1771561,34012224,244140625,1073741824,3518743761,9474296896,22164361129,46656000000,90458382169,164206490176,282429536481,464404086784,735091890625,1126162419264,1677100110841,2436396322816,3462825991689,4826809000000,6611856250609,8916100448256,11853911588401,15557597153344,20179187015625,25892303048704,32894113444921,41407371740736,51682540549249,64000000000000,78672340886049,96046742518336,116507435287321,140478247931904,168425239515625,200859416110144,238339532186001,281474976710656,330928743953809,387420489000000,451729667968489,524698762940416,607236591593241,700321701542464,805005849390625,922417564483584,1053765797374081,1200343652992576,1363532208525369,1544804416000000,1745729089577929,1967974977554496,2213314919066161,2483630085505024,2780914306640625,3107278481449024,3464955073649161,3856302691946496,4283810754983929,4750104241000000,5257948522194369,5810254283800576,6410082527866081,7060649661739584,7765332671265625,8527674378686464,9351388785251241,10240366498532416,11198680244449489,12230590464000000,13340550994697809,14533214836718656,15813440003753001,17186295458566144,18657067133265625,20231264034275904,21914624432020321,23713122135310336,25632972850442049,27680640625000000,29862844376368249,32186564504948736,34659049592086921,37287823182704704,40080690652640625,43045746160697344,46191379685396401,49526284146440256,53059462610881609,56800235584000000,60758248384885689,64943478606730816,69366243661827841,74037208411275264,78967392879390625,84168180052830784,89651323764419481,95428956661682176,101513598260088169,107918163081000000,114655968874330129 mul $0,7 add $0,4 pow $0,6
; Spectravideo SVI CRT0 stub ; ; Stefano Bodrato - Apr. 2001 ; ; $Id: svi_crt0.asm,v 1.6 2007/06/27 20:49:28 dom Exp $ ; MODULE svi_crt0 ; ; Initially include the zcc_opt.def file to find out lots of lovely ; information about what we should do.. ; INCLUDE "zcc_opt.def" ; No matter what set up we have, main is always, always external to ; this file XREF _main ; ; Some variables which are needed for both app and basic startup ; XDEF cleanup XDEF l_dcal ; Integer rnd seed XDEF _std_seed ; vprintf is internal to this file so we only ever include one of the set ; of routines XDEF _vfprintf ;Exit variables XDEF exitsp XDEF exitcount XDEF heaplast ;Near malloc heap variables XDEF heapblocks ;For stdin, stdout, stder XDEF __sgoioblk ; Now, getting to the real stuff now! org 34816 .start ld hl,0 add hl,sp ld (start1+1),hl ld hl,-64 add hl,sp ld sp,hl ld (exitsp),sp 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 $53 ; Hide function key menu call _main .cleanup ; ; Deallocate memory which has been allocated here! ; IF !DEFINED_nostreams IF DEFINED_ANSIstdio LIB closeall call closeall ENDIF ENDIF .start1 ld sp,0 ret .l_dcal jp (hl) ; Now, define some values for stdin, stdout, stderr .__sgoioblk IF DEFINED_ANSIstdio INCLUDE "#stdio_fp.asm" ELSE defw -11,-12,-10 ENDIF ; Now, which of the vfprintf routines do we need? ._vfprintf IF DEFINED_floatstdio LIB vfprintf_fp jp vfprintf_fp ELSE IF DEFINED_complexstdio LIB vfprintf_comp jp vfprintf_comp ELSE IF DEFINED_ministdio LIB vfprintf_mini jp vfprintf_mini ENDIF ENDIF ENDIF ;Seed for integer rand() routines .defltdsk defb 0 ;Seed for integer rand() routines ._std_seed defw 0 ;Atexit routine .exitsp defw 0 .exitcount defb 0 ; Heap stuff .heaplast defw 0 .heapblocks defw 0 ; mem stuff defm "Small C+ MSX" defb 0 ;All the float stuff is kept in a different file...for ease of altering! ;It will eventually be integrated into the library ; ;Here we have a minor (minor!) problem, we've no idea if we need the ;float package if this is separated from main (we had this problem before ;but it wasn't critical..so, now we will have to read in a file from ;the directory (this will be produced by zcc) which tells us if we need ;the floatpackage, and if so what it is..kludgey, but it might just work! ; ;Brainwave time! The zcc_opt file could actually be written by the ;compiler as it goes through the modules, appending as necessary - this ;way we only include the package if we *really* need it! IF NEED_floatpack INCLUDE "#float.asm" ;seed for random number generator - not used yet.. .fp_seed defb $80,$80,0,0,0,0 ;Floating point registers... .extra defs 6 .fa defs 6 .fasign defb 0 ENDIF
; A206608: Fibonacci sequence beginning 13, 10. ; 13,10,23,33,56,89,145,234,379,613,992,1605,2597,4202,6799,11001,17800,28801,46601,75402,122003,197405,319408,516813,836221,1353034,2189255,3542289,5731544,9273833,15005377,24279210,39284587,63563797,102848384,166412181,269260565,435672746,704933311,1140606057,1845539368,2986145425,4831684793,7817830218,12649515011,20467345229,33116860240,53584205469,86701065709,140285271178,226986336887,367271608065,594257944952,961529553017,1555787497969,2517317050986,4073104548955,6590421599941,10663526148896,17253947748837,27917473897733,45171421646570,73088895544303,118260317190873,191349212735176,309609529926049,500958742661225,810568272587274,1311527015248499,2122095287835773,3433622303084272,5555717590920045,8989339894004317 add $0,4 mul $0,2 sub $0,6 mov $3,3 lpb $0,1 sub $0,2 mov $1,4 add $1,$3 add $1,6 mov $3,$2 add $2,$1 lpe
; DV3 Standard Hard Disk Control Procedures V1.03  1999 Tony Tebby ; win_chk xref'd V1.05 (wl) march 2020 ; Q40 WIN_DRIVE may use name for QXL.WIN file V1.04  W. Lenerz 2017 Nov 21 section exten xdef hd_thing xdef hd_tname xdef hdt_doact xdef hd_byte xref thp_ostr xref thp_nrstr xref thp_wd xref dv3_usep xref dv3_acdef xref norm_nm xref cv_locas xref gu_fclos xref gu_fopen xref win_chk include 'dev8_keys_thg' include 'dev8_keys_err' include 'dev8_mac_thg' include 'dev8_mac_assert' include 'dev8_dv3_keys' include 'dev8_keys_qdos_ioa' include 'dev8_dv3_hd_keys' hdt.reg reg d1-d7/a0-a5 ; DON'T CHANGE THIS UNLESS IT IS ALSO CHANGED ;!!!! ; IN dev8_dv3_q40_hd_chkwin_asm hd_4byte dc.w thp.ubyt ; two compulsory unsigned byte dc.w thp.ubyt dc.w thp.ubyt+thp.opt dc.w thp.ubyt+thp.opt+thp.nnul dc.w thp.call+thp.str+thp.opt dc.w 0 hd_2byte dc.w thp.ubyt ; compulsory unsigned byte dc.w thp.ubyt+thp.opt+thp.nnul dc.w 0 hd_byte dc.w thp.ubyt dc.w 0 hd_bochr dc.w thp.ubyt ; drive dc.w thp.char+thp.opt ; with optional character dc.w 0 hd_noptm dc.w thp.ubyt ; drive dc.w thp.ubyt+thp.opt+thp.nnul ; default is set dc.w 0 mdir dc.w thp.ubyt ; drive dc.w thp.call+thp.str ; string dc.w 0 ;+++ ; ASCI Thing NAME ;--- hd_tname dc.b 0,11,'WIN Control',$a ;+++ ; This is the Thing with the WIN extensions ;--- hd_thing ;+++ ; WIN_USE xxx ;--- win_use thg_extn {USE },win_drive$,thp_ostr jmp dv3_usep ;+++ ; WIN_DRIVE$ n,d$ ;--- win_drive$ thg_extn {DRV$},win_drive,thp_nrstr wd$.reg reg d1/d2/d3/a1/a2/a3 movem.l wd$.reg,-(sp) move.l (a1)+,d3 beq.s wd$_err move.l d3,d7 subq.l #8,d3 bhi.s wd$_err move.l 4(a1),a1 clr.w (a1)+ ; null string lea hdl_targ+7-ddl_thing(a2),a3 add.l d3,a3 ; ptr to target number moveq #0,d0 move.b hdl_part-hdl_targ(a3),d1 ; partition bmi.s wd$_done ; ... none wd$_do move.l a1,d2 add.b (a3),d0 ; target bsr.s wd$_0_19 move.b hdl_unit-hdl_targ(a3),d0 ; unit bsr.s wd$_0_19c move.b d1,d0 ; partition bsr.s wd$_0_19c wd$_set lea hdl_end-12-ddl_thing(a2),a2 mulu #12,d7 add.w d7,a2 ; normalized name we're looking for move.l (a2)+,d0 ; first part of file name beq.s wd$_end ; none, drive is not on FAT xard move.b #' ',(a1)+ ; for qx0, there were 5 chars (t,u,p) move.l d0,(a1)+ move.l (a2)+,(a1)+ move.l (a2),d0 move.b #'.',d0 ror.l #8,d0 move.l d0,(a1)+ wd$_end exg d2,a1 sub.l a1,d2 ; length move.w d2,-(a1) wd$_done moveq #0,d0 wd$_exit movem.l (sp)+,wd$.reg rts wd$_err moveq #err.ipar,d0 bra.s wd$_exit wd$_0_19c move.b #',',(a1)+ ; preceded by comma wd$_0_19 cmp.b #9,d0 ; 0-9 ble.s wd$_sdig ; ... yes sub.w #10,d0 move.b #'1',(a1)+ ; 10-19 wd$_sdig add.b #'0',d0 move.b d0,(a1)+ ; units rts ;+++ ; WIN_DRIVE n,t,u,p,name$ ;--- win_drive thg_extn {DRIV},win_start,hd_4byte movem.l hdt.reg,-(sp) bsr.l hdt_doact ; call following code as device driver bne.s hdt_setd ; no definition tst.b ddf_nropen(a4) ; files open? bne.s hdt_inus sf ddf_mstat(a4) ; drive changed hdt_setd lea -ddl_thing(a2),a3 ; get linkage add.w d7,a3 ; table entry moveq #$3,d1 ; qx0 only has 4 targets and.l (a1)+,d1 ; target move.b d1,hdl_targ-1(a3) ; set it move.l (a1)+,d0 ; unit move.l (a1)+,d1 ; partition bpl.s hdt_setu ; four params given move.l d0,d1 ; less than four - this is partition moveq #0,d0 ; unit hdt_setu and.b #1,d0 ; unit must be 0/1 move.b d0,hdl_unit-1(a3) ; set unit move.b d1,hdl_part-1(a3) ; set partition move.l (a1)+,d0 ; name param set? bne.s set_name ; ... yes hdt_rtok moveq #0,d0 rts set_name andi.b #3,d1 ; here partitions are limited to 3 move.b d1,hdl_part-1(a3) ; set partition move.l (a1),d0 ; pointer name beq.s hdt_rtok ; ... none move.l d0,a0 ; pointer to name to normalise sub.w d7,a3 lea hdl_end-12(a3),a1 ; names go here move.l d7,d6 mulu #12,d6 add.w d6,a1 ; point to entry in table jsr norm_nm ; normalise name rts hdt_inus moveq #err.fdiu,d0 wdrvout rts ;+++ ; WIN_START n ;--- win_start thg_extn {STRT},win_stop,hd_byte moveq #-1,d0 ; start bra.s hdt_stst ;+++ ; WIN_STOP n,t ;--- win_stop thg_extn {STOP},win_remv,hd_2byte moveq #0,d0 move.w 6(a1),d0 ; stop time / 0 / 0000ffff hdt_stst movem.l hdt.reg,-(sp) move.l d0,d5 ; start or stop bsr.s hdt_doact ; call following code as device driver move.l d3,d0 ; defined? beq.s hdt_rts ; ... no move.l d5,d0 ; start / stop parameters jsr hdl_ststp(a3) ; start or stop hdt_rts rts ; general do action hdt_doact move.l (sp)+,a0 ; action routine lea -ddl_thing(a2),a3 ; master linkage move.l (a1)+,d7 ; drive number ble.s hdt_fdnf ; ... oops cmp.w #8,d7 bhi.s hdt_fdnf move.w #hdl_part-1,d3 add.l d7,d3 ; offset in linkage hdt_actest tst.b (a3,d3.w) ; any partition? bge.s hdt_acdef move.l ddl_slave(a3),a3 ; another slave move.l a3,d0 bne.s hdt_actest lea -ddl_thing(a2),a3 ; master linkage moveq #0,d3 ; no partition hdt_acdef jsr dv3_acdef ; action on definition hdt_exit movem.l (sp)+,hdt.reg rts hdt_fdnf moveq #err.fdnf,d0 ; no such drive number bra.s hdt_exit ;+++ ; WIN_REMV n, (char) ;--- win_remv thg_extn {REMV},win_wp,hd_bochr moveq #0,d0 rts hdt_ipar4 addq.l #4,sp hdt_ipar moveq #err.ipar,d0 bra.s hdt_exit ; prepare for simple operation hdt_prep moveq #8,d0 move.l (a1)+,d7 ; drive number beq.s hdt_ipar4 cmp.l d0,d7 bhi.s hdt_ipar4 lea -ddl_thing(a2),a3 rts ;+++ ; WIN_FORMAT n, (0|1) ;--- win_format thg_extn {FRMT},win_slug,hd_noptm movem.l hdt.reg,-(sp) bsr.s hdt_prep tst.l (a1) ; true or false? sne d5 neg.b d5 bra.s wwp_do ;+++ ; WIN_WP n, (0|1) ;--- win_wp thg_extn {WPRT},win_format,hd_noptm movem.l hdt.reg,-(sp) bsr.s hdt_prep tst.l (a1) ; true or false? sne d5 wwp_do move.l a3,-(sp) lea hdt_sets,a0 ; set drive undefined jsr dv3_acdef ; action on definition move.l (sp)+,a3 hdt_setwp add.w #hdl_wprt-1,d7 ; set write protect ; set a byte in all blocks hdt_seta move.b d5,(a3,d7.w) ; set flag move.l ddl_slave(a3),a3 move.l a3,d0 bne hdt_seta bra hdt_exit hdt_sets bne.s hdt_rok ; ... no drive sf ddf_mstat(a4) ; drive changed hdt_rok moveq #0,d0 rts ;+++ ; WIN_SLUG n ;--- win_slug thg_extn {SLUG},win_chk,hd_byte moveq #0,d0 out rts end
; $Id: fabsf.asm 69111 2017-10-17 14:26:02Z vboxsync $ ;; @file ; IPRT - No-CRT fabsf - AMD64 & X86. ; ; ; Copyright (C) 2006-2017 Oracle Corporation ; ; This file is part of VirtualBox Open Source Edition (OSE), as ; available from http://www.virtualbox.org. This file is free software; ; you can redistribute it and/or modify it under the terms of the GNU ; General Public License (GPL) as published by the Free Software ; Foundation, in version 2 as it comes in the "COPYING" file of the ; VirtualBox OSE distribution. VirtualBox OSE is distributed in the ; hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. ; ; The contents of this file may alternatively be used under the terms ; of the Common Development and Distribution License Version 1.0 ; (CDDL) only, as it comes in the "COPYING.CDDL" file of the ; VirtualBox OSE distribution, in which case the provisions of the ; CDDL are applicable instead of those of the GPL. ; ; You may elect to license modified versions of this file under the ; terms and conditions of either the GPL or the CDDL or both. ; %include "iprt/asmdefs.mac" BEGINCODE ;; ; Compute the absolute value of rf (|rf|). ; @returns 32-bit: st(0) 64-bit: xmm0 ; @param rf 32-bit: [ebp + 8] 64-bit: xmm0 BEGINPROC RT_NOCRT(fabsf) push xBP mov xBP, xSP %ifdef RT_ARCH_AMD64 sub xSP, 10h movsd [xSP], xmm0 fld dword [xSP] fabs fstp dword [xSP] movsd xmm0, [xSP] %else fld dword [xBP + xCB*2] fabs %endif leave ret ENDPROC RT_NOCRT(fabsf)
#pragma once #include <algorithm> #include <cstdint> #include <cstring> // Based on https://github.com/vog/sha1 /* Original authors: Steve Reid (Original C Code) Bruce Guenter (Small changes to fit into bglibs) Volker Grabsch (Translation to simpler C++ Code) Eugene Hopkinson (Safety improvements) Vincent Falco (beast adaptation) */ namespace cinatra { namespace sha1 { static std::size_t constexpr BLOCK_INTS = 16; static std::size_t constexpr BLOCK_BYTES = 64; static std::size_t constexpr DIGEST_BYTES = 20; inline std::uint32_t rol(std::uint32_t value, std::size_t bits) { return (value << bits) | (value >> (32 - bits)); } inline std::uint32_t blk(std::uint32_t block[BLOCK_INTS], std::size_t i) { return rol(block[(i + 13) & 15] ^ block[(i + 8) & 15] ^ block[(i + 2) & 15] ^ block[i], 1); } inline void R0(std::uint32_t block[BLOCK_INTS], std::uint32_t v, std::uint32_t &w, std::uint32_t x, std::uint32_t y, std::uint32_t &z, std::size_t i) { z += ((w & (x ^ y)) ^ y) + block[i] + 0x5a827999 + rol(v, 5); w = rol(w, 30); } inline void R1(std::uint32_t block[BLOCK_INTS], std::uint32_t v, std::uint32_t &w, std::uint32_t x, std::uint32_t y, std::uint32_t &z, std::size_t i) { block[i] = blk(block, i); z += ((w & (x ^ y)) ^ y) + block[i] + 0x5a827999 + rol(v, 5); w = rol(w, 30); } inline void R2(std::uint32_t block[BLOCK_INTS], std::uint32_t v, std::uint32_t &w, std::uint32_t x, std::uint32_t y, std::uint32_t &z, std::size_t i) { block[i] = blk(block, i); z += (w ^ x ^ y) + block[i] + 0x6ed9eba1 + rol(v, 5); w = rol(w, 30); } inline void R3(std::uint32_t block[BLOCK_INTS], std::uint32_t v, std::uint32_t &w, std::uint32_t x, std::uint32_t y, std::uint32_t &z, std::size_t i) { block[i] = blk(block, i); z += (((w | x) & y) | (w & x)) + block[i] + 0x8f1bbcdc + rol(v, 5); w = rol(w, 30); } inline void R4(std::uint32_t block[BLOCK_INTS], std::uint32_t v, std::uint32_t &w, std::uint32_t x, std::uint32_t y, std::uint32_t &z, std::size_t i) { block[i] = blk(block, i); z += (w ^ x ^ y) + block[i] + 0xca62c1d6 + rol(v, 5); w = rol(w, 30); } inline void make_block(std::uint8_t const *p, std::uint32_t block[BLOCK_INTS]) { for (std::size_t i = 0; i < BLOCK_INTS; i++) block[i] = (static_cast<std::uint32_t>(p[4 * i + 3])) | (static_cast<std::uint32_t>(p[4 * i + 2])) << 8 | (static_cast<std::uint32_t>(p[4 * i + 1])) << 16 | (static_cast<std::uint32_t>(p[4 * i + 0])) << 24; } template <class = void> void transform(std::uint32_t digest[], std::uint32_t block[BLOCK_INTS]) { std::uint32_t a = digest[0]; std::uint32_t b = digest[1]; std::uint32_t c = digest[2]; std::uint32_t d = digest[3]; std::uint32_t e = digest[4]; R0(block, a, b, c, d, e, 0); R0(block, e, a, b, c, d, 1); R0(block, d, e, a, b, c, 2); R0(block, c, d, e, a, b, 3); R0(block, b, c, d, e, a, 4); R0(block, a, b, c, d, e, 5); R0(block, e, a, b, c, d, 6); R0(block, d, e, a, b, c, 7); R0(block, c, d, e, a, b, 8); R0(block, b, c, d, e, a, 9); R0(block, a, b, c, d, e, 10); R0(block, e, a, b, c, d, 11); R0(block, d, e, a, b, c, 12); R0(block, c, d, e, a, b, 13); R0(block, b, c, d, e, a, 14); R0(block, a, b, c, d, e, 15); R1(block, e, a, b, c, d, 0); R1(block, d, e, a, b, c, 1); R1(block, c, d, e, a, b, 2); R1(block, b, c, d, e, a, 3); R2(block, a, b, c, d, e, 4); R2(block, e, a, b, c, d, 5); R2(block, d, e, a, b, c, 6); R2(block, c, d, e, a, b, 7); R2(block, b, c, d, e, a, 8); R2(block, a, b, c, d, e, 9); R2(block, e, a, b, c, d, 10); R2(block, d, e, a, b, c, 11); R2(block, c, d, e, a, b, 12); R2(block, b, c, d, e, a, 13); R2(block, a, b, c, d, e, 14); R2(block, e, a, b, c, d, 15); R2(block, d, e, a, b, c, 0); R2(block, c, d, e, a, b, 1); R2(block, b, c, d, e, a, 2); R2(block, a, b, c, d, e, 3); R2(block, e, a, b, c, d, 4); R2(block, d, e, a, b, c, 5); R2(block, c, d, e, a, b, 6); R2(block, b, c, d, e, a, 7); R3(block, a, b, c, d, e, 8); R3(block, e, a, b, c, d, 9); R3(block, d, e, a, b, c, 10); R3(block, c, d, e, a, b, 11); R3(block, b, c, d, e, a, 12); R3(block, a, b, c, d, e, 13); R3(block, e, a, b, c, d, 14); R3(block, d, e, a, b, c, 15); R3(block, c, d, e, a, b, 0); R3(block, b, c, d, e, a, 1); R3(block, a, b, c, d, e, 2); R3(block, e, a, b, c, d, 3); R3(block, d, e, a, b, c, 4); R3(block, c, d, e, a, b, 5); R3(block, b, c, d, e, a, 6); R3(block, a, b, c, d, e, 7); R3(block, e, a, b, c, d, 8); R3(block, d, e, a, b, c, 9); R3(block, c, d, e, a, b, 10); R3(block, b, c, d, e, a, 11); R4(block, a, b, c, d, e, 12); R4(block, e, a, b, c, d, 13); R4(block, d, e, a, b, c, 14); R4(block, c, d, e, a, b, 15); R4(block, b, c, d, e, a, 0); R4(block, a, b, c, d, e, 1); R4(block, e, a, b, c, d, 2); R4(block, d, e, a, b, c, 3); R4(block, c, d, e, a, b, 4); R4(block, b, c, d, e, a, 5); R4(block, a, b, c, d, e, 6); R4(block, e, a, b, c, d, 7); R4(block, d, e, a, b, c, 8); R4(block, c, d, e, a, b, 9); R4(block, b, c, d, e, a, 10); R4(block, a, b, c, d, e, 11); R4(block, e, a, b, c, d, 12); R4(block, d, e, a, b, c, 13); R4(block, c, d, e, a, b, 14); R4(block, b, c, d, e, a, 15); digest[0] += a; digest[1] += b; digest[2] += c; digest[3] += d; digest[4] += e; } } // namespace sha1 struct sha1_context { static unsigned int constexpr block_size = sha1::BLOCK_BYTES; static unsigned int constexpr digest_size = 20; std::size_t buflen; std::size_t blocks; std::uint32_t digest[5]; std::uint8_t buf[block_size]; }; template <class = void> inline void init(sha1_context &ctx) noexcept { ctx.buflen = 0; ctx.blocks = 0; ctx.digest[0] = 0x67452301; ctx.digest[1] = 0xefcdab89; ctx.digest[2] = 0x98badcfe; ctx.digest[3] = 0x10325476; ctx.digest[4] = 0xc3d2e1f0; } template <class = void> inline void update(sha1_context &ctx, void const *message, std::size_t size) noexcept { auto p = reinterpret_cast<std::uint8_t const *>(message); for (;;) { auto const n = (std::min)(size, sizeof(ctx.buf) - ctx.buflen); std::memcpy(ctx.buf + ctx.buflen, p, n); ctx.buflen += n; if (ctx.buflen != 64) return; p += n; size -= n; ctx.buflen = 0; std::uint32_t block[sha1::BLOCK_INTS]; sha1::make_block(ctx.buf, block); sha1::transform(ctx.digest, block); ++ctx.blocks; } } template <class = void> inline void finish(sha1_context &ctx, void *digest) noexcept { using sha1::BLOCK_BYTES; using sha1::BLOCK_INTS; std::uint64_t total_bits = (ctx.blocks * 64 + ctx.buflen) * 8; // pad ctx.buf[ctx.buflen++] = 0x80; auto const buflen = ctx.buflen; while (ctx.buflen < 64) ctx.buf[ctx.buflen++] = 0x00; std::uint32_t block[BLOCK_INTS]; sha1::make_block(ctx.buf, block); if (buflen > BLOCK_BYTES - 8) { sha1::transform(ctx.digest, block); for (size_t i = 0; i < BLOCK_INTS - 2; i++) block[i] = 0; } /* Append total_bits, split this uint64_t into two uint32_t */ block[BLOCK_INTS - 1] = total_bits & 0xffffffff; block[BLOCK_INTS - 2] = (total_bits >> 32); sha1::transform(ctx.digest, block); for (std::size_t i = 0; i < sha1::DIGEST_BYTES / 4; i++) { std::uint8_t *d = reinterpret_cast<std::uint8_t *>(digest) + 4 * i; d[3] = ctx.digest[i] & 0xff; d[2] = (ctx.digest[i] >> 8) & 0xff; d[1] = (ctx.digest[i] >> 16) & 0xff; d[0] = (ctx.digest[i] >> 24) & 0xff; } } } // namespace cinatra
/* * Copyright (C) 2021 Intel Corporation * * SPDX-License-Identifier: MIT * */ #include "shared/source/compiler_interface/compiler_options/compiler_options.h" #include "opencl/test/unit_test/offline_compiler/mock/mock_offline_compiler.h" #include "opencl/test/unit_test/offline_compiler/offline_compiler_tests.h" #include "test.h" using namespace NEO; using MockOfflineCompilerRklTests = ::testing::Test; RKLTEST_F(MockOfflineCompilerRklTests, givenRklWhenAppendExtraInternalOptionsThenForceEmuInt32DivRemSPIsApplied) { MockOfflineCompiler mockOfflineCompiler; mockOfflineCompiler.deviceName = " rkl"; mockOfflineCompiler.initHardwareInfo(mockOfflineCompiler.deviceName); std::string internalOptions = mockOfflineCompiler.internalOptions; mockOfflineCompiler.appendExtraInternalOptions(mockOfflineCompiler.hwInfo, internalOptions); size_t found = internalOptions.find(NEO::CompilerOptions::forceEmuInt32DivRemSP.data()); EXPECT_NE(std::string::npos, found); }
[BITS 32] [global _start] [ORG 0x100000] ;If using '-f bin' we need to specify the ;origin point for our code with ORG directive ;multiboot loaders load us at physical ;address 0x100000 MULTIBOOT_AOUT_KLUDGE equ 1 << 16 ;FLAGS[16] indicates to GRUB we are not ;an ELF executable and the fields ;header address, load address, load end address; ;bss end address and entry address will be available ;in Multiboot header MULTIBOOT_ALIGN equ 1<<0 ; align loaded modules on page boundaries MULTIBOOT_MEMINFO equ 1<<1 ; provide memory map MULTIBOOT_VBE_MODE equ 1<<2 MULTIBOOT_HEADER_MAGIC equ 0x1BADB002 ;magic number GRUB searches for in the first 8k ;of the kernel file GRUB is told to load MULTIBOOT_HEADER_FLAGS equ MULTIBOOT_AOUT_KLUDGE|MULTIBOOT_ALIGN|MULTIBOOT_MEMINFO|MULTIBOOT_VBE_MODE CHECKSUM equ -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS) _start: xor eax, eax ;Clear eax and ebx in the event xor ebx, ebx ;we are not loaded by GRUB. jmp multiboot_entry ;Jump over the multiboot header align 4 ;Multiboot header must be 32 ;bits aligned to avoid error 13 multiboot_header: dd MULTIBOOT_HEADER_MAGIC ;magic number dd MULTIBOOT_HEADER_FLAGS ;flags dd CHECKSUM ;checksum dd multiboot_header ;header address dd _start ;load address of code entry point ;in our case _start dd 00 ;load end address : not necessary dd 00 ;bss end address : not necessary dd multiboot_entry ;entry address GRUB will start at ; Uncomment this and "|MULTIBOOT_VBE_MODE" in MULTIBOOT_HEADER_FLAGS to enable VBE dd 00 ; Safe resolution dd 1024 dd 768 dd 32 multiboot_entry: mov esp, STACKTOP ;Setup the stack push 0 ;Reset EFLAGS popf push eax ;2nd argument is magic number push ebx ;1st argument multiboot info pointer mov [multiboot_pointer],ebx jmp Enter_Long_Mode cli hlt jmp $ multiboot_pointer: dq 0 ALIGN 4 IDT: .Length dw 0 .Base dd 0 ; Function to switch directly to long mode from real mode. ; Identity maps the first 1GiB. ; Uses Intel syntax. ; es:edi Should point to a valid page-aligned 16KiB buffer, for the PML4, PDPT, PD and a PT. ; ss:esp Should point to memory that can be used as a small (1 uint32_t) stack Enter_Long_Mode: mov edi, P4_TABLE ; Zero out the 16KiB buffer. ; Since we are doing a rep stosd, count should be bytes/4. push di ; REP STOSD alters DI. ; map first P4 entry to P3 table mov eax, P3_TABLE or eax, 0b11 ; present + writable mov [P4_TABLE], eax ; map first P3 entry to P2 table mov eax, P2_TABLE or eax, 0b11 ; present + writable mov [P3_TABLE], eax ; map each P2 entry to a huge 2MiB page mov ecx, 0 ; counter variable .Map_P2_Table: ; map ecx-th P2 entry to a huge page that starts at address 2MiB*ecx mov eax, 0x200000 ; 2MiB mul ecx ; start address of ecx-th page or eax, 0b10000011 ; present + writable + huge mov [P2_TABLE + ecx * 8], eax ; map ecx-th entry inc ecx ; increase counter cmp ecx, 512 ; if counter == 512, the whole P2 table is mapped jne .Map_P2_Table ; else map the next entry ;1024MB of memory should be mapped now pop di ; Restore DI. ; Disable IRQs mov al, 0xFF ; Out 0xFF to 0xA1 and 0x21 to disable all IRQs. out 0xA1, al out 0x21, al cli nop nop lidt [IDT] ; Load a zero length IDT so that any NMI causes a triple fault. ; Enter long mode. mov eax, 10100000b ; Set the PAE and PGE bit. mov cr4, eax mov edx, edi ; Point CR3 at the PML4. mov cr3, edx mov ecx, 0xC0000080 ; Read from the EFER MSR. rdmsr or eax, 0x00000100 ; Set the LME bit. wrmsr mov ebx, cr0 ; Activate long mode - or ebx,0x80000001 ; - by enabling paging and protection simultaneously. mov cr0, ebx lgdt [GDT.Pointer] ; Load GDT.Pointer defined below. sti jmp 0x0008:Main ; Load CS with 64 bit segment and flush the instruction cache ; Global Descriptor Table GDT: .Null: dq 0x0000000000000000 ; Null Descriptor - should be present. .Code: dq 0x00209A0000000000 ; 64-bit code descriptor (exec/read). dq 0x0000920000000000 ; 64-bit data descriptor (read/write). ALIGN 4 dw 0 ; Padding to make the "address of the GDT" field aligned on a 4-byte boundary .Pointer: dw $ - GDT - 1 ; 16-bit Size (Limit) of GDT. dd GDT ; 32-bit Base Address of GDT. (CPU will zero extend to 64-bit) struc DOSHeader .e_magic: resb 2 .e_cblp: resb 2 .e_cp: resb 2 .e_crlc: resb 2 .e_cparhdr: resb 2 .e_minalloc: resb 2 .e_maxalloc: resb 2 .e_ss: resb 2 .e_sp: resb 2 .e_csum: resb 2 .e_ip: resb 2 .e_cs: resb 2 .e_lfarlc: resb 2 .e_ovno: resb 2 .e_res1: resb 8 .e_oemid: resb 2 .e_oeminfo: resb 2 .e_res2: resb 20 .e_lfanew: resb 4 endstruc struc NTHeader .Signature: resb 4 .Machine: resb 2 .NumberOfSections: resb 2 .TimeDateStamp: resb 4 .PointerToSymbolTable: resb 4 .NumberOfSymbols: resb 4 .SizeOfOptionalHeader: resb 2 .Characteristics: resb 2 .Magic: resb 2 .MajorLinkerVersion: resb 1 .MinorLinkerVersion: resb 1 .SizeOfCode: resb 4 .SizeOfInitializedData: resb 4 .SizeOfUninitializedData: resb 4 .AddressOfEntryPoint: resb 4 .BaseOfCode: resb 4 .ImageBase: resb 8 .SectionAlignment: resb 4 .FileAlignment: resb 4 .MajorOperatingSystemVersion: resb 2 .MinorOperatingSystemVersion: resb 2 .MajorImageVersion: resb 2 .MinorImageVersion: resb 2 .MajorSubsystemVersion: resb 2 .MinorSubsystemVersion: resb 2 .Win32VersionValue: resb 4 .SizeOfImage: resb 4 .SizeOfHeaders: resb 4 .CheckSum: resb 4 .Subsystem: resb 2 .DllCharacteristics: resb 2 .SizeOfStackReserve: resb 8 .SizeOfStackCommit: resb 8 .SizeOfHeapReserve: resb 8 .SizeOfHeapCommit: resb 8 .LoaderFlags: resb 4 .NumberOfRvaAndSizes: resb 4 .Tables: resb 128 endstruc struc SectionHeader .Name: resb 8 .PhysicalAddress_VirtualSize: resb 4 .VirtualAddress: resb 4 .SizeOfRawData: resb 4 .PointerToRawData: resb 4 .PointerToRelocations: resb 4 .PointerToLineNumbers: resb 4 .NumberOfRelocations: resb 2 .NumberOfLineNumbers: resb 2 .Characteristics: resb 4 endstruc LOAD_IMAGE_PARAMS_STACK_SIZE equ 64 [BITS 64] Main: mov ax, 0x0010 mov ds, ax mov es, ax mov fs, ax mov gs, ax mov ss, ax mov rsp,STACKTOP mov rbp,rsp mov rcx,0x200 mov rbx,cr4 or rbx,rcx mov cr4,rbx fninit sub rsp,LOAD_IMAGE_PARAMS_STACK_SIZE xor rbx,rbx mov ebx,[EXE+DOSHeader.e_lfanew] lea ebx,[ebx+EXE+NTHeader.NumberOfSections] xor rcx,rcx mov cx,[rbx] mov [rsp+16],rcx xor rbx,rbx mov ebx,[EXE+DOSHeader.e_lfanew] lea ebx,[ebx+EXE+NTHeader.ImageBase] mov rbx,[rbx] mov [rsp+24],rbx xor rbx,rbx mov ebx,[EXE+DOSHeader.e_lfanew] lea ebx,[ebx+EXE+NTHeader.AddressOfEntryPoint] mov ebx,[ebx] mov rax,[rsp+24] add rbx,rax mov [rsp+8],rbx xor rbx,rbx mov ebx,[EXE+DOSHeader.e_lfanew] lea ebx,[ebx+EXE+NTHeader.SizeOfImage] mov ebx,[ebx] mov [rsp+48],rbx mov rdi,[rsp+24] mov rcx,[rsp+48] mov rax,0 rep stosb xor rbx,rbx mov ebx,[EXE+DOSHeader.e_lfanew] lea ebx,[ebx+EXE+NTHeader_size] mov r15,0 LoadSection: xor rsi,rsi xor rdi,rdi xor rcx,rcx xor r13,r13 lea esi,[ebx+SectionHeader.PointerToRawData] mov esi,[esi] add rsi,EXE lea ecx,[ebx+SectionHeader.SizeOfRawData] mov ecx,[ecx] lea edi,[ebx+SectionHeader.VirtualAddress] mov edi,[edi] mov rax,[rsp+24] add rdi,rax lea r13d,[ebx+SectionHeader.Name] mov r13,[r13] mov qword r14,0x73656C75646F6D2E cmp qword r13,r14 jne Skip mov qword [rsp+32],rdi Skip: rep movsb inc r15 add ebx,SectionHeader_size mov r14,[rsp+16] cmp r15,r14 jne LoadSection mov rcx,[multiboot_pointer] mov rdx,[rsp+32] mov rax,[rsp+8] add rsp,LOAD_IMAGE_PARAMS_STACK_SIZE call rax cli hlt jmp $ align 4096 STACKBOTTOM: resb 32768 STACKTOP: P4_TABLE: resb 4096 P3_TABLE: resb 4096 P2_TABLE: resb 4096 align 4096 EXE:
; Don't even think of reading this code ; It was automatically generated by md5-586.pl ; Which is a perl program used to generate the x86 assember for ; any of elf, a.out, BSDI, Win32, gaswin (for GNU as on Win32) or Solaris ; eric <eay@cryptsoft.com> ; TITLE md5-586.asm .386 .model FLAT _TEXT SEGMENT PUBLIC _md5_block_asm_host_order _md5_block_asm_host_order PROC NEAR push esi push edi mov edi, DWORD PTR 12[esp] mov esi, DWORD PTR 16[esp] mov ecx, DWORD PTR 20[esp] push ebp shl ecx, 6 push ebx add ecx, esi sub ecx, 64 mov eax, DWORD PTR [edi] push ecx mov ebx, DWORD PTR 4[edi] mov ecx, DWORD PTR 8[edi] mov edx, DWORD PTR 12[edi] L000start: ; ; R0 section mov edi, ecx mov ebp, DWORD PTR [esi] ; R0 0 xor edi, edx and edi, ebx lea eax, DWORD PTR 3614090360[ebp*1+eax] xor edi, edx add eax, edi mov edi, ebx rol eax, 7 mov ebp, DWORD PTR 4[esi] add eax, ebx ; R0 1 xor edi, ecx and edi, eax lea edx, DWORD PTR 3905402710[ebp*1+edx] xor edi, ecx add edx, edi mov edi, eax rol edx, 12 mov ebp, DWORD PTR 8[esi] add edx, eax ; R0 2 xor edi, ebx and edi, edx lea ecx, DWORD PTR 606105819[ebp*1+ecx] xor edi, ebx add ecx, edi mov edi, edx rol ecx, 17 mov ebp, DWORD PTR 12[esi] add ecx, edx ; R0 3 xor edi, eax and edi, ecx lea ebx, DWORD PTR 3250441966[ebp*1+ebx] xor edi, eax add ebx, edi mov edi, ecx rol ebx, 22 mov ebp, DWORD PTR 16[esi] add ebx, ecx ; R0 4 xor edi, edx and edi, ebx lea eax, DWORD PTR 4118548399[ebp*1+eax] xor edi, edx add eax, edi mov edi, ebx rol eax, 7 mov ebp, DWORD PTR 20[esi] add eax, ebx ; R0 5 xor edi, ecx and edi, eax lea edx, DWORD PTR 1200080426[ebp*1+edx] xor edi, ecx add edx, edi mov edi, eax rol edx, 12 mov ebp, DWORD PTR 24[esi] add edx, eax ; R0 6 xor edi, ebx and edi, edx lea ecx, DWORD PTR 2821735955[ebp*1+ecx] xor edi, ebx add ecx, edi mov edi, edx rol ecx, 17 mov ebp, DWORD PTR 28[esi] add ecx, edx ; R0 7 xor edi, eax and edi, ecx lea ebx, DWORD PTR 4249261313[ebp*1+ebx] xor edi, eax add ebx, edi mov edi, ecx rol ebx, 22 mov ebp, DWORD PTR 32[esi] add ebx, ecx ; R0 8 xor edi, edx and edi, ebx lea eax, DWORD PTR 1770035416[ebp*1+eax] xor edi, edx add eax, edi mov edi, ebx rol eax, 7 mov ebp, DWORD PTR 36[esi] add eax, ebx ; R0 9 xor edi, ecx and edi, eax lea edx, DWORD PTR 2336552879[ebp*1+edx] xor edi, ecx add edx, edi mov edi, eax rol edx, 12 mov ebp, DWORD PTR 40[esi] add edx, eax ; R0 10 xor edi, ebx and edi, edx lea ecx, DWORD PTR 4294925233[ebp*1+ecx] xor edi, ebx add ecx, edi mov edi, edx rol ecx, 17 mov ebp, DWORD PTR 44[esi] add ecx, edx ; R0 11 xor edi, eax and edi, ecx lea ebx, DWORD PTR 2304563134[ebp*1+ebx] xor edi, eax add ebx, edi mov edi, ecx rol ebx, 22 mov ebp, DWORD PTR 48[esi] add ebx, ecx ; R0 12 xor edi, edx and edi, ebx lea eax, DWORD PTR 1804603682[ebp*1+eax] xor edi, edx add eax, edi mov edi, ebx rol eax, 7 mov ebp, DWORD PTR 52[esi] add eax, ebx ; R0 13 xor edi, ecx and edi, eax lea edx, DWORD PTR 4254626195[ebp*1+edx] xor edi, ecx add edx, edi mov edi, eax rol edx, 12 mov ebp, DWORD PTR 56[esi] add edx, eax ; R0 14 xor edi, ebx and edi, edx lea ecx, DWORD PTR 2792965006[ebp*1+ecx] xor edi, ebx add ecx, edi mov edi, edx rol ecx, 17 mov ebp, DWORD PTR 60[esi] add ecx, edx ; R0 15 xor edi, eax and edi, ecx lea ebx, DWORD PTR 1236535329[ebp*1+ebx] xor edi, eax add ebx, edi mov edi, ecx rol ebx, 22 mov ebp, DWORD PTR 4[esi] add ebx, ecx ; ; R1 section ; R1 16 lea eax, DWORD PTR 4129170786[ebp*1+eax] xor edi, ebx and edi, edx mov ebp, DWORD PTR 24[esi] xor edi, ecx add eax, edi mov edi, ebx rol eax, 5 add eax, ebx ; R1 17 lea edx, DWORD PTR 3225465664[ebp*1+edx] xor edi, eax and edi, ecx mov ebp, DWORD PTR 44[esi] xor edi, ebx add edx, edi mov edi, eax rol edx, 9 add edx, eax ; R1 18 lea ecx, DWORD PTR 643717713[ebp*1+ecx] xor edi, edx and edi, ebx mov ebp, DWORD PTR [esi] xor edi, eax add ecx, edi mov edi, edx rol ecx, 14 add ecx, edx ; R1 19 lea ebx, DWORD PTR 3921069994[ebp*1+ebx] xor edi, ecx and edi, eax mov ebp, DWORD PTR 20[esi] xor edi, edx add ebx, edi mov edi, ecx rol ebx, 20 add ebx, ecx ; R1 20 lea eax, DWORD PTR 3593408605[ebp*1+eax] xor edi, ebx and edi, edx mov ebp, DWORD PTR 40[esi] xor edi, ecx add eax, edi mov edi, ebx rol eax, 5 add eax, ebx ; R1 21 lea edx, DWORD PTR 38016083[ebp*1+edx] xor edi, eax and edi, ecx mov ebp, DWORD PTR 60[esi] xor edi, ebx add edx, edi mov edi, eax rol edx, 9 add edx, eax ; R1 22 lea ecx, DWORD PTR 3634488961[ebp*1+ecx] xor edi, edx and edi, ebx mov ebp, DWORD PTR 16[esi] xor edi, eax add ecx, edi mov edi, edx rol ecx, 14 add ecx, edx ; R1 23 lea ebx, DWORD PTR 3889429448[ebp*1+ebx] xor edi, ecx and edi, eax mov ebp, DWORD PTR 36[esi] xor edi, edx add ebx, edi mov edi, ecx rol ebx, 20 add ebx, ecx ; R1 24 lea eax, DWORD PTR 568446438[ebp*1+eax] xor edi, ebx and edi, edx mov ebp, DWORD PTR 56[esi] xor edi, ecx add eax, edi mov edi, ebx rol eax, 5 add eax, ebx ; R1 25 lea edx, DWORD PTR 3275163606[ebp*1+edx] xor edi, eax and edi, ecx mov ebp, DWORD PTR 12[esi] xor edi, ebx add edx, edi mov edi, eax rol edx, 9 add edx, eax ; R1 26 lea ecx, DWORD PTR 4107603335[ebp*1+ecx] xor edi, edx and edi, ebx mov ebp, DWORD PTR 32[esi] xor edi, eax add ecx, edi mov edi, edx rol ecx, 14 add ecx, edx ; R1 27 lea ebx, DWORD PTR 1163531501[ebp*1+ebx] xor edi, ecx and edi, eax mov ebp, DWORD PTR 52[esi] xor edi, edx add ebx, edi mov edi, ecx rol ebx, 20 add ebx, ecx ; R1 28 lea eax, DWORD PTR 2850285829[ebp*1+eax] xor edi, ebx and edi, edx mov ebp, DWORD PTR 8[esi] xor edi, ecx add eax, edi mov edi, ebx rol eax, 5 add eax, ebx ; R1 29 lea edx, DWORD PTR 4243563512[ebp*1+edx] xor edi, eax and edi, ecx mov ebp, DWORD PTR 28[esi] xor edi, ebx add edx, edi mov edi, eax rol edx, 9 add edx, eax ; R1 30 lea ecx, DWORD PTR 1735328473[ebp*1+ecx] xor edi, edx and edi, ebx mov ebp, DWORD PTR 48[esi] xor edi, eax add ecx, edi mov edi, edx rol ecx, 14 add ecx, edx ; R1 31 lea ebx, DWORD PTR 2368359562[ebp*1+ebx] xor edi, ecx and edi, eax mov ebp, DWORD PTR 20[esi] xor edi, edx add ebx, edi mov edi, ecx rol ebx, 20 add ebx, ecx ; ; R2 section ; R2 32 xor edi, edx xor edi, ebx lea eax, DWORD PTR 4294588738[ebp*1+eax] add eax, edi rol eax, 4 mov ebp, DWORD PTR 32[esi] mov edi, ebx ; R2 33 lea edx, DWORD PTR 2272392833[ebp*1+edx] add eax, ebx xor edi, ecx xor edi, eax mov ebp, DWORD PTR 44[esi] add edx, edi mov edi, eax rol edx, 11 add edx, eax ; R2 34 xor edi, ebx xor edi, edx lea ecx, DWORD PTR 1839030562[ebp*1+ecx] add ecx, edi rol ecx, 16 mov ebp, DWORD PTR 56[esi] mov edi, edx ; R2 35 lea ebx, DWORD PTR 4259657740[ebp*1+ebx] add ecx, edx xor edi, eax xor edi, ecx mov ebp, DWORD PTR 4[esi] add ebx, edi mov edi, ecx rol ebx, 23 add ebx, ecx ; R2 36 xor edi, edx xor edi, ebx lea eax, DWORD PTR 2763975236[ebp*1+eax] add eax, edi rol eax, 4 mov ebp, DWORD PTR 16[esi] mov edi, ebx ; R2 37 lea edx, DWORD PTR 1272893353[ebp*1+edx] add eax, ebx xor edi, ecx xor edi, eax mov ebp, DWORD PTR 28[esi] add edx, edi mov edi, eax rol edx, 11 add edx, eax ; R2 38 xor edi, ebx xor edi, edx lea ecx, DWORD PTR 4139469664[ebp*1+ecx] add ecx, edi rol ecx, 16 mov ebp, DWORD PTR 40[esi] mov edi, edx ; R2 39 lea ebx, DWORD PTR 3200236656[ebp*1+ebx] add ecx, edx xor edi, eax xor edi, ecx mov ebp, DWORD PTR 52[esi] add ebx, edi mov edi, ecx rol ebx, 23 add ebx, ecx ; R2 40 xor edi, edx xor edi, ebx lea eax, DWORD PTR 681279174[ebp*1+eax] add eax, edi rol eax, 4 mov ebp, DWORD PTR [esi] mov edi, ebx ; R2 41 lea edx, DWORD PTR 3936430074[ebp*1+edx] add eax, ebx xor edi, ecx xor edi, eax mov ebp, DWORD PTR 12[esi] add edx, edi mov edi, eax rol edx, 11 add edx, eax ; R2 42 xor edi, ebx xor edi, edx lea ecx, DWORD PTR 3572445317[ebp*1+ecx] add ecx, edi rol ecx, 16 mov ebp, DWORD PTR 24[esi] mov edi, edx ; R2 43 lea ebx, DWORD PTR 76029189[ebp*1+ebx] add ecx, edx xor edi, eax xor edi, ecx mov ebp, DWORD PTR 36[esi] add ebx, edi mov edi, ecx rol ebx, 23 add ebx, ecx ; R2 44 xor edi, edx xor edi, ebx lea eax, DWORD PTR 3654602809[ebp*1+eax] add eax, edi rol eax, 4 mov ebp, DWORD PTR 48[esi] mov edi, ebx ; R2 45 lea edx, DWORD PTR 3873151461[ebp*1+edx] add eax, ebx xor edi, ecx xor edi, eax mov ebp, DWORD PTR 60[esi] add edx, edi mov edi, eax rol edx, 11 add edx, eax ; R2 46 xor edi, ebx xor edi, edx lea ecx, DWORD PTR 530742520[ebp*1+ecx] add ecx, edi rol ecx, 16 mov ebp, DWORD PTR 8[esi] mov edi, edx ; R2 47 lea ebx, DWORD PTR 3299628645[ebp*1+ebx] add ecx, edx xor edi, eax xor edi, ecx mov ebp, DWORD PTR [esi] add ebx, edi mov edi, -1 rol ebx, 23 add ebx, ecx ; ; R3 section ; R3 48 xor edi, edx or edi, ebx lea eax, DWORD PTR 4096336452[ebp*1+eax] xor edi, ecx mov ebp, DWORD PTR 28[esi] add eax, edi mov edi, -1 rol eax, 6 xor edi, ecx add eax, ebx ; R3 49 or edi, eax lea edx, DWORD PTR 1126891415[ebp*1+edx] xor edi, ebx mov ebp, DWORD PTR 56[esi] add edx, edi mov edi, -1 rol edx, 10 xor edi, ebx add edx, eax ; R3 50 or edi, edx lea ecx, DWORD PTR 2878612391[ebp*1+ecx] xor edi, eax mov ebp, DWORD PTR 20[esi] add ecx, edi mov edi, -1 rol ecx, 15 xor edi, eax add ecx, edx ; R3 51 or edi, ecx lea ebx, DWORD PTR 4237533241[ebp*1+ebx] xor edi, edx mov ebp, DWORD PTR 48[esi] add ebx, edi mov edi, -1 rol ebx, 21 xor edi, edx add ebx, ecx ; R3 52 or edi, ebx lea eax, DWORD PTR 1700485571[ebp*1+eax] xor edi, ecx mov ebp, DWORD PTR 12[esi] add eax, edi mov edi, -1 rol eax, 6 xor edi, ecx add eax, ebx ; R3 53 or edi, eax lea edx, DWORD PTR 2399980690[ebp*1+edx] xor edi, ebx mov ebp, DWORD PTR 40[esi] add edx, edi mov edi, -1 rol edx, 10 xor edi, ebx add edx, eax ; R3 54 or edi, edx lea ecx, DWORD PTR 4293915773[ebp*1+ecx] xor edi, eax mov ebp, DWORD PTR 4[esi] add ecx, edi mov edi, -1 rol ecx, 15 xor edi, eax add ecx, edx ; R3 55 or edi, ecx lea ebx, DWORD PTR 2240044497[ebp*1+ebx] xor edi, edx mov ebp, DWORD PTR 32[esi] add ebx, edi mov edi, -1 rol ebx, 21 xor edi, edx add ebx, ecx ; R3 56 or edi, ebx lea eax, DWORD PTR 1873313359[ebp*1+eax] xor edi, ecx mov ebp, DWORD PTR 60[esi] add eax, edi mov edi, -1 rol eax, 6 xor edi, ecx add eax, ebx ; R3 57 or edi, eax lea edx, DWORD PTR 4264355552[ebp*1+edx] xor edi, ebx mov ebp, DWORD PTR 24[esi] add edx, edi mov edi, -1 rol edx, 10 xor edi, ebx add edx, eax ; R3 58 or edi, edx lea ecx, DWORD PTR 2734768916[ebp*1+ecx] xor edi, eax mov ebp, DWORD PTR 52[esi] add ecx, edi mov edi, -1 rol ecx, 15 xor edi, eax add ecx, edx ; R3 59 or edi, ecx lea ebx, DWORD PTR 1309151649[ebp*1+ebx] xor edi, edx mov ebp, DWORD PTR 16[esi] add ebx, edi mov edi, -1 rol ebx, 21 xor edi, edx add ebx, ecx ; R3 60 or edi, ebx lea eax, DWORD PTR 4149444226[ebp*1+eax] xor edi, ecx mov ebp, DWORD PTR 44[esi] add eax, edi mov edi, -1 rol eax, 6 xor edi, ecx add eax, ebx ; R3 61 or edi, eax lea edx, DWORD PTR 3174756917[ebp*1+edx] xor edi, ebx mov ebp, DWORD PTR 8[esi] add edx, edi mov edi, -1 rol edx, 10 xor edi, ebx add edx, eax ; R3 62 or edi, edx lea ecx, DWORD PTR 718787259[ebp*1+ecx] xor edi, eax mov ebp, DWORD PTR 36[esi] add ecx, edi mov edi, -1 rol ecx, 15 xor edi, eax add ecx, edx ; R3 63 or edi, ecx lea ebx, DWORD PTR 3951481745[ebp*1+ebx] xor edi, edx mov ebp, DWORD PTR 24[esp] add ebx, edi add esi, 64 rol ebx, 21 mov edi, DWORD PTR [ebp] add ebx, ecx add eax, edi mov edi, DWORD PTR 4[ebp] add ebx, edi mov edi, DWORD PTR 8[ebp] add ecx, edi mov edi, DWORD PTR 12[ebp] add edx, edi mov DWORD PTR [ebp],eax mov DWORD PTR 4[ebp],ebx mov edi, DWORD PTR [esp] mov DWORD PTR 8[ebp],ecx mov DWORD PTR 12[ebp],edx cmp edi, esi jge L000start pop eax pop ebx pop ebp pop edi pop esi ret _md5_block_asm_host_order ENDP _TEXT ENDS END
/* Copyright (c) 2010-2018, Delft University of Technology * All rigths reserved * * This file is part of the Tudat. Redistribution and use in source and * binary forms, with or without modification, are permitted exclusively * under the terms of the Modified BSD license. You should have received * a copy of the license with this file. If not, please or visit: * http://tudat.tudelft.nl/LICENSE. */ #include "Tudat/Astrodynamics/Propagators/singleStateTypeDerivative.h" namespace tudat { namespace propagators { //! Get size of state for single propagated state of given type. int getSingleIntegrationSize( const IntegratedStateType stateType ) { int singleStateSize = 0; switch( stateType ) { case translational_state: singleStateSize = 6; break; case rotational_state: singleStateSize = 7; break; case body_mass_state: singleStateSize = 1; break; default: std::string errorMessage = "Did not recognize state type " + std::to_string( stateType ) + "when getting size"; throw std::runtime_error( errorMessage ); } return singleStateSize; } //! Get order of differential equation for governing equations of dynamics of given type. int getSingleIntegrationDifferentialEquationOrder( const IntegratedStateType stateType ) { int singleStateSize = 0; switch( stateType ) { case translational_state: singleStateSize = 2; break; case body_mass_state: singleStateSize = 1; break; case rotational_state: singleStateSize = 1; break; default: std::string errorMessage = "Did not recognize state type " + std::to_string( stateType ) + "when getting order"; throw std::runtime_error( errorMessage ); } return singleStateSize; } //! Function to get the size of the generalized acceleration for a given state type int getGeneralizedAccelerationSize( const IntegratedStateType stateType ) { int accelerationSize = 0; switch( stateType ) { case translational_state: accelerationSize = 3; break; case body_mass_state: accelerationSize = 1; break; case rotational_state: accelerationSize = 3; break; default: std::string errorMessage = "Did not recognize state type " + std::to_string( stateType ) + "when getting acceleration sizw"; throw std::runtime_error( errorMessage ); } return accelerationSize; } template class SingleStateTypeDerivative< double, double >; #if( BUILD_EXTENDED_PRECISION_PROPAGATION_TOOLS ) template class SingleStateTypeDerivative< long double, double >; template class SingleStateTypeDerivative< double, Time >; template class SingleStateTypeDerivative< long double, Time >; #endif } }
; A053133: One half of binomial coefficients binomial(2*n-8,9). ; 5,110,1001,5720,24310,83980,248710,653752,1562275,3453450,7153575,14024400,26225628,47071640,81505820,136719440,222945905,354465254,550858165,838553320,1252716850,1839537700,2658968130,3787984200,5324436975,7391571330,10143295635,13770292256,18507065720,24640032560,32516764280,42556502560,55262073757,71233337950,91182316225,115950148600,146526043950,184068392508,229928220990,285675180120,353126264315,434377473530,531838637759,648271635440,786832248020,951115904200,1145207578900,1373736123760,1641933318025,1955697940950,2321665179405,2747281697160,3240886705386,3811799387220,4470413042810,5228296335080,6098302030535,7094683643762,8233220408875,9531351016000,11008316566000,12685313212000,14585654971888,16734947211840,19161271317045,21895381082190,24970911370905,28424599610264,32296520703590,36630335962220,41473556674550,46877822948600,52899198482515,59598481935850,67041535593175,75299632030480,84449819514060,94575306881016,105765868670220,118118271292560,131736721049505,146733334829510,163228634332517,181352064693800,201242538399650,223049005408900,246931050416050,273059518213768,301617168134815,332799358575970,366814762629315,403886115869280,444250997367144,488162645028240,535890806370920,587722625890400,643963570174925,704938391966270,770992134381425,842491176537400,919824321846430,1003403930274460,1093667095881646,1191076870989720,1296123538347435,1409325932691930,1531232813130735,1662424287796272,1803513292252100,1955147123157800,2118009028727300,2292819857543600,2480339767321273,2681369995236790,2896754691475645,3127382817674440,3374190111965530,3638161122361524,3920331310246890,4221789225774120,4543678756992375,4887201454567250,5253618933981275,5644255357136000,6060499995308000,6503809875442880,6975712511803360,7477808725019776,8011775550623845,8579369239179310,9182428350156105 mov $1,$0 add $1,$0 add $1,10 bin $1,9 div $1,2
.global s_prepare_buffers s_prepare_buffers: push %r10 push %r11 push %r8 push %rax push %rbp push %rcx push %rdi push %rsi lea addresses_WC_ht+0x15c87, %r10 inc %r8 movb (%r10), %r11b nop sub %rsi, %rsi lea addresses_normal_ht+0x179d7, %rbp sub %r8, %r8 mov (%rbp), %edi nop nop add $61209, %rbp lea addresses_WT_ht+0x124df, %r10 nop xor $5059, %rcx movb (%r10), %r8b nop nop and $5240, %rbp lea addresses_normal_ht+0x59c7, %r10 nop xor $39490, %rcx mov (%r10), %r11w sub $65112, %r10 lea addresses_A_ht+0x13407, %r8 sub $42445, %r11 mov $0x6162636465666768, %r10 movq %r10, (%r8) nop nop inc %rbp lea addresses_WC_ht+0x57b7, %r11 sub %rbp, %rbp movb (%r11), %cl nop nop nop dec %rsi lea addresses_D_ht+0xafca, %rsi lea addresses_WC_ht+0x29fb, %rdi nop nop nop nop nop sub $55194, %rax mov $86, %rcx rep movsl nop cmp %r10, %r10 lea addresses_D_ht+0xd207, %r11 nop inc %rcx mov (%r11), %esi nop nop nop nop cmp $30246, %rax lea addresses_UC_ht+0x17187, %rcx nop inc %rax mov $0x6162636465666768, %rsi movq %rsi, %xmm1 and $0xffffffffffffffc0, %rcx vmovaps %ymm1, (%rcx) nop and %r11, %r11 lea addresses_A_ht+0xee87, %rdi nop nop nop sub %rax, %rax mov (%rdi), %esi nop nop nop nop and %rbp, %rbp lea addresses_A_ht+0x19a87, %rdi nop nop sub %rsi, %rsi mov $0x6162636465666768, %rbp movq %rbp, %xmm0 vmovups %ymm0, (%rdi) nop nop nop nop nop dec %rbp lea addresses_D_ht+0x68a7, %r10 nop nop nop nop nop sub %rbp, %rbp mov (%r10), %r8 nop nop nop nop nop lfence lea addresses_D_ht+0xf567, %rsi lea addresses_WC_ht+0xa21f, %rdi nop dec %r11 mov $27, %rcx rep movsw nop nop and $16699, %r8 lea addresses_D_ht+0xf087, %rdi nop nop nop inc %r10 mov $0x6162636465666768, %rbp movq %rbp, %xmm2 movups %xmm2, (%rdi) nop inc %r10 lea addresses_UC_ht+0x154f7, %r8 nop and %rcx, %rcx mov (%r8), %edi nop nop nop nop add %rbp, %rbp pop %rsi pop %rdi pop %rcx pop %rbp pop %rax pop %r8 pop %r11 pop %r10 ret .global s_faulty_load s_faulty_load: push %r11 push %r12 push %r15 push %r9 push %rax push %rbx push %rsi // Load lea addresses_US+0x3a7, %rbx nop nop nop nop inc %rax mov (%rbx), %r11d cmp %r9, %r9 // Load lea addresses_UC+0xf687, %r12 nop nop nop nop sub $51116, %r15 mov (%r12), %rax nop nop and $21077, %rax // Store mov $0xa43570000000a87, %rsi nop nop nop cmp $65129, %r9 movb $0x51, (%rsi) nop nop nop nop sub %rbx, %rbx // Faulty Load mov $0xa43570000000a87, %r15 nop nop xor %r9, %r9 mov (%r15), %eax lea oracles, %r11 and $0xff, %rax shlq $12, %rax mov (%r11,%rax,1), %rax pop %rsi pop %rbx pop %rax pop %r9 pop %r15 pop %r12 pop %r11 ret /* <gen_faulty_load> [REF] {'src': {'NT': False, 'AVXalign': False, 'size': 16, 'congruent': 0, 'same': False, 'type': 'addresses_NC'}, 'OP': 'LOAD'} {'src': {'NT': False, 'AVXalign': False, 'size': 4, 'congruent': 4, 'same': False, 'type': 'addresses_US'}, 'OP': 'LOAD'} {'src': {'NT': True, 'AVXalign': False, 'size': 8, 'congruent': 10, 'same': False, 'type': 'addresses_UC'}, 'OP': 'LOAD'} {'dst': {'NT': True, 'AVXalign': False, 'size': 1, 'congruent': 0, 'same': True, 'type': 'addresses_NC'}, 'OP': 'STOR'} [Faulty Load] {'src': {'NT': False, 'AVXalign': False, 'size': 4, 'congruent': 0, 'same': True, 'type': 'addresses_NC'}, 'OP': 'LOAD'} <gen_prepare_buffer> {'src': {'NT': False, 'AVXalign': False, 'size': 1, 'congruent': 8, 'same': False, 'type': 'addresses_WC_ht'}, 'OP': 'LOAD'} {'src': {'NT': False, 'AVXalign': True, 'size': 4, 'congruent': 3, 'same': False, 'type': 'addresses_normal_ht'}, 'OP': 'LOAD'} {'src': {'NT': False, 'AVXalign': False, 'size': 1, 'congruent': 2, 'same': False, 'type': 'addresses_WT_ht'}, 'OP': 'LOAD'} {'src': {'NT': True, 'AVXalign': False, 'size': 2, 'congruent': 4, 'same': True, 'type': 'addresses_normal_ht'}, 'OP': 'LOAD'} {'dst': {'NT': False, 'AVXalign': False, 'size': 8, 'congruent': 7, 'same': False, 'type': 'addresses_A_ht'}, 'OP': 'STOR'} {'src': {'NT': False, 'AVXalign': False, 'size': 1, 'congruent': 3, 'same': False, 'type': 'addresses_WC_ht'}, 'OP': 'LOAD'} {'src': {'congruent': 0, 'same': False, 'type': 'addresses_D_ht'}, 'dst': {'congruent': 2, 'same': False, 'type': 'addresses_WC_ht'}, 'OP': 'REPM'} {'src': {'NT': False, 'AVXalign': False, 'size': 4, 'congruent': 7, 'same': False, 'type': 'addresses_D_ht'}, 'OP': 'LOAD'} {'dst': {'NT': False, 'AVXalign': True, 'size': 32, 'congruent': 6, 'same': False, 'type': 'addresses_UC_ht'}, 'OP': 'STOR'} {'src': {'NT': False, 'AVXalign': False, 'size': 4, 'congruent': 10, 'same': True, 'type': 'addresses_A_ht'}, 'OP': 'LOAD'} {'dst': {'NT': False, 'AVXalign': False, 'size': 32, 'congruent': 11, 'same': False, 'type': 'addresses_A_ht'}, 'OP': 'STOR'} {'src': {'NT': True, 'AVXalign': True, 'size': 8, 'congruent': 5, 'same': False, 'type': 'addresses_D_ht'}, 'OP': 'LOAD'} {'src': {'congruent': 5, 'same': True, 'type': 'addresses_D_ht'}, 'dst': {'congruent': 2, 'same': False, 'type': 'addresses_WC_ht'}, 'OP': 'REPM'} {'dst': {'NT': False, 'AVXalign': False, 'size': 16, 'congruent': 6, 'same': False, 'type': 'addresses_D_ht'}, 'OP': 'STOR'} {'src': {'NT': False, 'AVXalign': False, 'size': 4, 'congruent': 0, 'same': False, 'type': 'addresses_UC_ht'}, 'OP': 'LOAD'} {'4e': 3, '42': 1, '66': 1, '72': 3, '7a': 1, 'fa': 2, 'c2': 3, '24': 4, '0c': 1, '5e': 1, 'f8': 7, '9c': 4, '6a': 3, '28': 1, '36': 3, '12': 2, '86': 1, '56': 1, '96': 3, '20': 2, 'ba': 3, '26': 1, '50': 2, '0e': 5, 'e2': 1, '46': 1, 'de': 2, '04': 2, '92': 1, 'e6': 2, '16': 1, '54': 2, '88': 2, 'a0': 1, 'b6': 3, '76': 1, '2c': 3, 'cc': 2, 'f0': 2, '7c': 2, '70': 4, 'b8': 4, '51': 19804, 'a2': 4, '5c': 1, 'ee': 3, 'b2': 3, 'dc': 1, 'a8': 2, '3a': 2, 'e4': 2, '90': 2, '3e': 4, '2a': 2, 'bc': 1, '0a': 2, 'fc': 5, '60': 2, 'd8': 1, '6e': 1, '38': 1, '5a': 2, '40': 2, '08': 2, '00': 1795, '84': 1, '4c': 1, '78': 2, '14': 4, 'ce': 2, '80': 1, 'd6': 2, '9e': 2, 'f2': 1, '06': 3, '8a': 1, '64': 1, '98': 1, '1e': 3, 'd2': 2, 'da': 3, 'c8': 3, 'fe': 3, '62': 2, '58': 3, '3c': 2, '74': 3, 'b4': 3, 'c0': 4, 'f6': 2, '02': 1, 'ca': 1, '44': 3, '1a': 2, 'a4': 2, 'a6': 2, '7e': 2, 'be': 2, '32': 1, '4a': 2, 'c6': 4, '68': 3, 'd0': 6, 'd4': 5} 51 00 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 c2 51 51 51 51 51 51 51 51 51 51 51 00 51 00 51 51 00 51 51 51 00 51 51 51 51 51 51 00 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 00 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 00 51 51 51 51 51 51 00 00 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 00 51 51 51 51 51 51 51 51 51 51 51 00 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 00 51 00 51 51 51 51 51 51 00 51 51 51 51 51 51 51 51 51 51 51 51 00 2c 51 51 51 51 51 51 51 51 51 00 51 51 00 51 51 51 51 51 51 00 51 51 51 00 51 51 51 51 51 51 51 51 51 51 51 51 00 51 51 51 51 51 51 51 51 51 51 51 51 51 00 51 51 51 51 51 51 51 51 51 51 00 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 5e 51 51 51 51 51 51 51 51 00 51 51 51 51 51 51 51 51 51 51 51 51 00 51 51 51 51 00 51 51 51 00 51 51 51 51 51 51 51 51 51 51 51 51 51 00 00 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 00 51 a2 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 00 51 51 51 51 51 51 6e 51 51 51 51 51 51 51 51 51 51 00 51 51 51 51 51 51 51 51 51 00 51 51 51 51 51 51 51 51 51 51 51 00 51 51 51 51 51 51 51 51 51 51 51 51 00 51 51 51 51 51 51 51 51 86 51 51 51 00 51 51 51 51 51 00 51 51 51 51 51 51 00 51 51 51 51 51 00 51 51 51 51 51 51 51 51 51 00 51 51 51 51 51 51 51 51 00 51 51 51 51 51 51 51 51 51 51 51 51 00 51 51 00 51 51 00 51 51 9e 51 51 51 51 51 00 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 00 51 51 51 51 51 51 51 00 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 00 51 51 51 51 00 51 51 51 00 51 51 51 51 51 51 51 51 51 51 51 51 51 51 00 51 51 00 00 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 00 51 51 51 51 00 51 51 51 51 51 51 51 51 51 00 51 51 51 00 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 00 51 51 51 51 51 51 00 51 51 51 00 51 51 51 51 51 51 51 51 00 00 51 51 51 51 51 51 51 51 51 51 51 51 00 51 00 51 51 51 51 00 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 00 51 51 51 51 51 51 51 51 51 00 51 00 51 00 51 51 00 51 51 51 00 51 51 51 51 51 51 51 00 51 51 51 51 51 51 51 51 51 51 51 00 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 00 00 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 00 51 51 51 51 51 51 51 51 51 51 51 51 51 00 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 00 00 51 51 51 00 51 51 51 51 51 51 51 51 51 51 51 51 00 51 51 51 51 51 51 51 51 51 51 51 51 51 de 51 51 51 51 51 51 51 51 51 51 51 51 00 76 51 51 51 51 51 00 51 51 51 51 51 51 51 51 51 00 51 51 00 51 51 51 51 00 51 51 51 51 51 51 51 51 00 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 00 51 51 51 51 51 00 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 */
; A168420: a(n) = 4 + 10*floor(n/2). ; 4,14,14,24,24,34,34,44,44,54,54,64,64,74,74,84,84,94,94,104,104,114,114,124,124,134,134,144,144,154,154,164,164,174,174,184,184,194,194,204,204,214,214,224,224,234,234,244,244,254,254,264,264,274,274,284,284,294,294,304,304,314,314,324,324,334,334,344,344,354,354,364,364,374,374,384,384,394,394,404,404,414,414,424,424,434,434,444,444,454,454,464,464,474,474,484,484,494,494,504,504,514,514,524,524,534,534,544,544,554,554,564,564,574,574,584,584,594,594,604,604,614,614,624,624,634,634,644,644,654,654,664,664,674,674,684,684,694,694,704,704,714,714,724,724,734,734,744,744,754,754,764,764,774,774,784,784,794,794,804,804,814,814,824,824,834,834,844,844,854,854,864,864,874,874,884,884,894,894,904,904,914,914,924,924,934,934,944,944,954,954,964,964,974,974,984,984,994,994,1004,1004,1014,1014,1024,1024,1034,1034,1044,1044,1054,1054,1064,1064,1074,1074,1084,1084,1094,1094,1104,1104,1114,1114,1124,1124,1134,1134,1144,1144,1154,1154,1164,1164,1174,1174,1184,1184,1194,1194,1204,1204,1214,1214,1224,1224,1234,1234,1244,1244,1254 mov $1,1 add $1,$0 div $1,2 mul $1,10 add $1,4
// 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. #include "olap/tablet_meta.h" #include <sstream> #include "olap/file_helper.h" #include "olap/olap_common.h" #include "olap/olap_define.h" #include "olap/rowset/alpha_rowset_meta.h" #include "olap/tablet_meta_manager.h" #include "util/string_util.h" #include "util/uid_util.h" #include "util/url_coding.h" using std::string; using std::unordered_map; using std::vector; namespace doris { Status TabletMeta::create(const TCreateTabletReq& request, const TabletUid& tablet_uid, uint64_t shard_id, uint32_t next_unique_id, const unordered_map<uint32_t, uint32_t>& col_ordinal_to_unique_id, TabletMetaSharedPtr* tablet_meta) { tablet_meta->reset(new TabletMeta( request.table_id, request.partition_id, request.tablet_id, request.replica_id, request.tablet_schema.schema_hash, shard_id, request.tablet_schema, next_unique_id, col_ordinal_to_unique_id, tablet_uid, request.__isset.tablet_type ? request.tablet_type : TTabletType::TABLET_TYPE_DISK, request.storage_medium, request.storage_param.storage_name, request.compression_type)); return Status::OK(); } TabletMeta::TabletMeta() : _tablet_uid(0, 0), _schema(new TabletSchema) {} TabletMeta::TabletMeta(int64_t table_id, int64_t partition_id, int64_t tablet_id, int64_t replica_id, int32_t schema_hash, uint64_t shard_id, const TTabletSchema& tablet_schema, uint32_t next_unique_id, const std::unordered_map<uint32_t, uint32_t>& col_ordinal_to_unique_id, TabletUid tablet_uid, TTabletType::type tabletType, TStorageMedium::type t_storage_medium, const std::string& storage_name, TCompressionType::type compression_type) : _tablet_uid(0, 0), _schema(new TabletSchema) { TabletMetaPB tablet_meta_pb; tablet_meta_pb.set_table_id(table_id); tablet_meta_pb.set_partition_id(partition_id); tablet_meta_pb.set_tablet_id(tablet_id); tablet_meta_pb.set_replica_id(replica_id); tablet_meta_pb.set_schema_hash(schema_hash); tablet_meta_pb.set_shard_id(shard_id); // Persist the creation time, but it is not used tablet_meta_pb.set_creation_time(time(nullptr)); tablet_meta_pb.set_cumulative_layer_point(-1); tablet_meta_pb.set_tablet_state(PB_RUNNING); *(tablet_meta_pb.mutable_tablet_uid()) = tablet_uid.to_proto(); tablet_meta_pb.set_tablet_type(tabletType == TTabletType::TABLET_TYPE_DISK ? TabletTypePB::TABLET_TYPE_DISK : TabletTypePB::TABLET_TYPE_MEMORY); tablet_meta_pb.set_storage_medium(fs::fs_util::get_storage_medium_pb(t_storage_medium)); tablet_meta_pb.set_remote_storage_name(storage_name); TabletSchemaPB* schema = tablet_meta_pb.mutable_schema(); schema->set_num_short_key_columns(tablet_schema.short_key_column_count); schema->set_num_rows_per_row_block(config::default_num_rows_per_column_file_block); schema->set_sequence_col_idx(tablet_schema.sequence_col_idx); switch (tablet_schema.keys_type) { case TKeysType::DUP_KEYS: schema->set_keys_type(KeysType::DUP_KEYS); break; case TKeysType::UNIQUE_KEYS: schema->set_keys_type(KeysType::UNIQUE_KEYS); break; case TKeysType::AGG_KEYS: schema->set_keys_type(KeysType::AGG_KEYS); break; default: LOG(WARNING) << "unknown tablet keys type"; break; } // compress_kind used to compress segment files schema->set_compress_kind(COMPRESS_LZ4); // compression_type used to compress segment page switch (compression_type) { case TCompressionType::NO_COMPRESSION: schema->set_compression_type(NO_COMPRESSION); break; case TCompressionType::SNAPPY: schema->set_compression_type(SNAPPY); break; case TCompressionType::LZ4: schema->set_compression_type(LZ4); break; case TCompressionType::LZ4F: schema->set_compression_type(LZ4F); break; case TCompressionType::ZLIB: schema->set_compression_type(ZLIB); break; case TCompressionType::ZSTD: schema->set_compression_type(ZSTD); break; default: schema->set_compression_type(LZ4F); break; } switch (tablet_schema.sort_type) { case TSortType::type::ZORDER: schema->set_sort_type(SortType::ZORDER); break; default: schema->set_sort_type(SortType::LEXICAL); } schema->set_sort_col_num(tablet_schema.sort_col_num); tablet_meta_pb.set_in_restore_mode(false); // set column information uint32_t col_ordinal = 0; uint32_t key_count = 0; bool has_bf_columns = false; for (TColumn tcolumn : tablet_schema.columns) { ColumnPB* column = schema->add_column(); uint32_t unique_id = col_ordinal_to_unique_id.at(col_ordinal++); _init_column_from_tcolumn(unique_id, tcolumn, column); if (column->is_key()) { ++key_count; } if (column->is_bf_column()) { has_bf_columns = true; } if (tablet_schema.__isset.indexes) { for (auto& index : tablet_schema.indexes) { if (index.index_type == TIndexType::type::BITMAP) { DCHECK_EQ(index.columns.size(), 1); if (iequal(tcolumn.column_name, index.columns[0])) { column->set_has_bitmap_index(true); break; } } } } } schema->set_next_column_unique_id(next_unique_id); if (has_bf_columns && tablet_schema.__isset.bloom_filter_fpp) { schema->set_bf_fpp(tablet_schema.bloom_filter_fpp); } if (tablet_schema.__isset.is_in_memory) { schema->set_is_in_memory(tablet_schema.is_in_memory); } if (tablet_schema.__isset.delete_sign_idx) { schema->set_delete_sign_idx(tablet_schema.delete_sign_idx); } init_from_pb(tablet_meta_pb); } TabletMeta::TabletMeta(const TabletMeta& b) : _table_id(b._table_id), _partition_id(b._partition_id), _tablet_id(b._tablet_id), _schema_hash(b._schema_hash), _shard_id(b._shard_id), _creation_time(b._creation_time), _cumulative_layer_point(b._cumulative_layer_point), _tablet_uid(b._tablet_uid), _tablet_type(b._tablet_type), _tablet_state(b._tablet_state), _schema(b._schema), _rs_metas(b._rs_metas), _stale_rs_metas(b._stale_rs_metas), _del_pred_array(b._del_pred_array), _in_restore_mode(b._in_restore_mode), _preferred_rowset_type(b._preferred_rowset_type), _remote_storage_name(b._remote_storage_name), _storage_medium(b._storage_medium) {}; void TabletMeta::_init_column_from_tcolumn(uint32_t unique_id, const TColumn& tcolumn, ColumnPB* column) { column->set_unique_id(unique_id); column->set_name(tcolumn.column_name); column->set_has_bitmap_index(false); string data_type; EnumToString(TPrimitiveType, tcolumn.column_type.type, data_type); column->set_type(data_type); if (tcolumn.column_type.type == TPrimitiveType::DECIMALV2) { column->set_precision(tcolumn.column_type.precision); column->set_frac(tcolumn.column_type.scale); } uint32_t length = TabletColumn::get_field_length_by_type(tcolumn.column_type.type, tcolumn.column_type.len); column->set_length(length); column->set_index_length(length); if (tcolumn.column_type.type == TPrimitiveType::VARCHAR || tcolumn.column_type.type == TPrimitiveType::STRING) { if (!tcolumn.column_type.__isset.index_len) { column->set_index_length(10); } else { column->set_index_length(tcolumn.column_type.index_len); } } if (!tcolumn.is_key) { column->set_is_key(false); string aggregation_type; EnumToString(TAggregationType, tcolumn.aggregation_type, aggregation_type); column->set_aggregation(aggregation_type); } else { column->set_is_key(true); column->set_aggregation("NONE"); } column->set_is_nullable(tcolumn.is_allow_null); if (tcolumn.__isset.default_value) { column->set_default_value(tcolumn.default_value); } if (tcolumn.__isset.is_bloom_filter_column) { column->set_is_bf_column(tcolumn.is_bloom_filter_column); } if (tcolumn.column_type.type == TPrimitiveType::ARRAY) { ColumnPB* children_column = column->add_children_columns(); _init_column_from_tcolumn(0, tcolumn.children_column[0], children_column); } } Status TabletMeta::create_from_file(const string& file_path) { FileHeader<TabletMetaPB> file_header; FileHandler file_handler; if (file_handler.open(file_path, O_RDONLY) != Status::OK()) { LOG(WARNING) << "fail to open ordinal file. file=" << file_path; return Status::OLAPInternalError(OLAP_ERR_IO_ERROR); } // In file_header.unserialize(), it validates file length, signature, checksum of protobuf. if (file_header.unserialize(&file_handler) != Status::OK()) { LOG(WARNING) << "fail to unserialize tablet_meta. file='" << file_path; return Status::OLAPInternalError(OLAP_ERR_PARSE_PROTOBUF_ERROR); } TabletMetaPB tablet_meta_pb; try { tablet_meta_pb.CopyFrom(file_header.message()); } catch (...) { LOG(WARNING) << "fail to copy protocol buffer object. file='" << file_path; return Status::OLAPInternalError(OLAP_ERR_PARSE_PROTOBUF_ERROR); } init_from_pb(tablet_meta_pb); return Status::OK(); } Status TabletMeta::reset_tablet_uid(const string& header_file) { Status res = Status::OK(); TabletMeta tmp_tablet_meta; if ((res = tmp_tablet_meta.create_from_file(header_file)) != Status::OK()) { LOG(WARNING) << "fail to load tablet meta from file" << ", meta_file=" << header_file; return res; } TabletMetaPB tmp_tablet_meta_pb; tmp_tablet_meta.to_meta_pb(&tmp_tablet_meta_pb); *(tmp_tablet_meta_pb.mutable_tablet_uid()) = TabletUid::gen_uid().to_proto(); res = save(header_file, tmp_tablet_meta_pb); if (!res.ok()) { LOG(FATAL) << "fail to save tablet meta pb to " << " meta_file=" << header_file; return res; } return res; } std::string TabletMeta::construct_header_file_path(const string& schema_hash_path, int64_t tablet_id) { std::stringstream header_name_stream; header_name_stream << schema_hash_path << "/" << tablet_id << ".hdr"; return header_name_stream.str(); } Status TabletMeta::save(const string& file_path) { TabletMetaPB tablet_meta_pb; to_meta_pb(&tablet_meta_pb); return TabletMeta::save(file_path, tablet_meta_pb); } Status TabletMeta::save(const string& file_path, const TabletMetaPB& tablet_meta_pb) { DCHECK(!file_path.empty()); FileHeader<TabletMetaPB> file_header; FileHandler file_handler; if (!file_handler.open_with_mode(file_path, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR)) { LOG(WARNING) << "fail to open header file. file='" << file_path; return Status::OLAPInternalError(OLAP_ERR_IO_ERROR); } try { file_header.mutable_message()->CopyFrom(tablet_meta_pb); } catch (...) { LOG(WARNING) << "fail to copy protocol buffer object. file='" << file_path; return Status::OLAPInternalError(OLAP_ERR_OTHER_ERROR); } if (file_header.prepare(&file_handler) != Status::OK() || file_header.serialize(&file_handler) != Status::OK()) { LOG(WARNING) << "fail to serialize to file header. file='" << file_path; return Status::OLAPInternalError(OLAP_ERR_SERIALIZE_PROTOBUF_ERROR); } return Status::OK(); } Status TabletMeta::save_meta(DataDir* data_dir) { std::lock_guard<std::shared_mutex> wrlock(_meta_lock); return _save_meta(data_dir); } Status TabletMeta::_save_meta(DataDir* data_dir) { // check if tablet uid is valid if (_tablet_uid.hi == 0 && _tablet_uid.lo == 0) { LOG(FATAL) << "tablet_uid is invalid" << " tablet=" << full_name() << " _tablet_uid=" << _tablet_uid.to_string(); } string meta_binary; RETURN_NOT_OK(serialize(&meta_binary)); Status status = TabletMetaManager::save(data_dir, tablet_id(), schema_hash(), meta_binary); if (!status.ok()) { LOG(FATAL) << "fail to save tablet_meta. status=" << status << ", tablet_id=" << tablet_id() << ", schema_hash=" << schema_hash(); } return status; } Status TabletMeta::serialize(string* meta_binary) { TabletMetaPB tablet_meta_pb; to_meta_pb(&tablet_meta_pb); bool serialize_success = tablet_meta_pb.SerializeToString(meta_binary); if (!serialize_success) { LOG(FATAL) << "failed to serialize meta " << full_name(); } return Status::OK(); } Status TabletMeta::deserialize(const string& meta_binary) { TabletMetaPB tablet_meta_pb; bool parsed = tablet_meta_pb.ParseFromString(meta_binary); if (!parsed) { LOG(WARNING) << "parse tablet meta failed"; return Status::OLAPInternalError(OLAP_ERR_INIT_FAILED); } init_from_pb(tablet_meta_pb); return Status::OK(); } void TabletMeta::init_from_pb(const TabletMetaPB& tablet_meta_pb) { _table_id = tablet_meta_pb.table_id(); _partition_id = tablet_meta_pb.partition_id(); _tablet_id = tablet_meta_pb.tablet_id(); _replica_id = tablet_meta_pb.replica_id(); _schema_hash = tablet_meta_pb.schema_hash(); _shard_id = tablet_meta_pb.shard_id(); _creation_time = tablet_meta_pb.creation_time(); _cumulative_layer_point = tablet_meta_pb.cumulative_layer_point(); _tablet_uid = TabletUid(tablet_meta_pb.tablet_uid()); if (tablet_meta_pb.has_tablet_type()) { _tablet_type = tablet_meta_pb.tablet_type(); } else { _tablet_type = TabletTypePB::TABLET_TYPE_DISK; } // init _tablet_state switch (tablet_meta_pb.tablet_state()) { case PB_NOTREADY: _tablet_state = TabletState::TABLET_NOTREADY; break; case PB_RUNNING: _tablet_state = TabletState::TABLET_RUNNING; break; case PB_TOMBSTONED: _tablet_state = TabletState::TABLET_TOMBSTONED; break; case PB_STOPPED: _tablet_state = TabletState::TABLET_STOPPED; break; case PB_SHUTDOWN: _tablet_state = TabletState::TABLET_SHUTDOWN; break; default: LOG(WARNING) << "tablet has no state. tablet=" << tablet_id() << ", schema_hash=" << schema_hash(); } // init _schema _schema->init_from_pb(tablet_meta_pb.schema()); // init _rs_metas for (auto& it : tablet_meta_pb.rs_metas()) { RowsetMetaSharedPtr rs_meta(new AlphaRowsetMeta()); rs_meta->init_from_pb(it); if (rs_meta->has_delete_predicate()) { add_delete_predicate(rs_meta->delete_predicate(), rs_meta->version().first); } _rs_metas.push_back(std::move(rs_meta)); } for (auto& it : tablet_meta_pb.stale_rs_metas()) { RowsetMetaSharedPtr rs_meta(new AlphaRowsetMeta()); rs_meta->init_from_pb(it); _stale_rs_metas.push_back(std::move(rs_meta)); } if (tablet_meta_pb.has_in_restore_mode()) { _in_restore_mode = tablet_meta_pb.in_restore_mode(); } if (tablet_meta_pb.has_preferred_rowset_type()) { _preferred_rowset_type = tablet_meta_pb.preferred_rowset_type(); } _remote_storage_name = tablet_meta_pb.remote_storage_name(); _storage_medium = tablet_meta_pb.storage_medium(); } void TabletMeta::to_meta_pb(TabletMetaPB* tablet_meta_pb) { tablet_meta_pb->set_table_id(table_id()); tablet_meta_pb->set_partition_id(partition_id()); tablet_meta_pb->set_tablet_id(tablet_id()); tablet_meta_pb->set_replica_id(replica_id()); tablet_meta_pb->set_schema_hash(schema_hash()); tablet_meta_pb->set_shard_id(shard_id()); tablet_meta_pb->set_creation_time(creation_time()); tablet_meta_pb->set_cumulative_layer_point(cumulative_layer_point()); *(tablet_meta_pb->mutable_tablet_uid()) = tablet_uid().to_proto(); tablet_meta_pb->set_tablet_type(_tablet_type); switch (tablet_state()) { case TABLET_NOTREADY: tablet_meta_pb->set_tablet_state(PB_NOTREADY); break; case TABLET_RUNNING: tablet_meta_pb->set_tablet_state(PB_RUNNING); break; case TABLET_TOMBSTONED: tablet_meta_pb->set_tablet_state(PB_TOMBSTONED); break; case TABLET_STOPPED: tablet_meta_pb->set_tablet_state(PB_STOPPED); break; case TABLET_SHUTDOWN: tablet_meta_pb->set_tablet_state(PB_SHUTDOWN); break; } for (auto& rs : _rs_metas) { rs->to_rowset_pb(tablet_meta_pb->add_rs_metas()); } for (auto rs : _stale_rs_metas) { rs->to_rowset_pb(tablet_meta_pb->add_stale_rs_metas()); } _schema->to_schema_pb(tablet_meta_pb->mutable_schema()); tablet_meta_pb->set_in_restore_mode(in_restore_mode()); // to avoid modify tablet meta to the greatest extend if (_preferred_rowset_type == BETA_ROWSET) { tablet_meta_pb->set_preferred_rowset_type(_preferred_rowset_type); } tablet_meta_pb->set_remote_storage_name(_remote_storage_name); tablet_meta_pb->set_storage_medium(_storage_medium); } uint32_t TabletMeta::mem_size() const { auto size = sizeof(TabletMeta); size += _schema->mem_size(); return size; } void TabletMeta::to_json(string* json_string, json2pb::Pb2JsonOptions& options) { TabletMetaPB tablet_meta_pb; to_meta_pb(&tablet_meta_pb); json2pb::ProtoMessageToJson(tablet_meta_pb, json_string, options); } Version TabletMeta::max_version() const { Version max_version = {-1, 0}; for (auto& rs_meta : _rs_metas) { if (rs_meta->end_version() > max_version.second) { max_version = rs_meta->version(); } } return max_version; } Status TabletMeta::add_rs_meta(const RowsetMetaSharedPtr& rs_meta) { // check RowsetMeta is valid for (auto& rs : _rs_metas) { if (rs->version() == rs_meta->version()) { if (rs->rowset_id() != rs_meta->rowset_id()) { LOG(WARNING) << "version already exist. rowset_id=" << rs->rowset_id() << " version=" << rs->version() << ", tablet=" << full_name(); return Status::OLAPInternalError(OLAP_ERR_PUSH_VERSION_ALREADY_EXIST); } else { // rowsetid,version is equal, it is a duplicate req, skip it return Status::OK(); } } } _rs_metas.push_back(rs_meta); if (rs_meta->has_delete_predicate()) { add_delete_predicate(rs_meta->delete_predicate(), rs_meta->version().first); } return Status::OK(); } void TabletMeta::delete_rs_meta_by_version(const Version& version, std::vector<RowsetMetaSharedPtr>* deleted_rs_metas) { auto it = _rs_metas.begin(); while (it != _rs_metas.end()) { if ((*it)->version() == version) { if (deleted_rs_metas != nullptr) { deleted_rs_metas->push_back(*it); } _rs_metas.erase(it); return; } else { ++it; } } } void TabletMeta::modify_rs_metas(const std::vector<RowsetMetaSharedPtr>& to_add, const std::vector<RowsetMetaSharedPtr>& to_delete, bool same_version) { // Remove to_delete rowsets from _rs_metas for (auto rs_to_del : to_delete) { auto it = _rs_metas.begin(); while (it != _rs_metas.end()) { if (rs_to_del->version() == (*it)->version()) { if ((*it)->has_delete_predicate()) { remove_delete_predicate_by_version((*it)->version()); } _rs_metas.erase(it); // there should be only one rowset match the version break; } else { ++it; } } } if (!same_version) { // put to_delete rowsets in _stale_rs_metas. _stale_rs_metas.insert(_stale_rs_metas.end(), to_delete.begin(), to_delete.end()); } // put to_add rowsets in _rs_metas. _rs_metas.insert(_rs_metas.end(), to_add.begin(), to_add.end()); } // Use the passing "rs_metas" to replace the rs meta in this tablet meta // Also clear the _stale_rs_metas because this tablet meta maybe copyied from // an existing tablet before. Add after revise, only the passing "rs_metas" // is needed. void TabletMeta::revise_rs_metas(std::vector<RowsetMetaSharedPtr>&& rs_metas) { std::lock_guard<std::shared_mutex> wrlock(_meta_lock); _rs_metas = std::move(rs_metas); _stale_rs_metas.clear(); } void TabletMeta::delete_stale_rs_meta_by_version(const Version& version) { auto it = _stale_rs_metas.begin(); while (it != _stale_rs_metas.end()) { if ((*it)->version() == version) { it = _stale_rs_metas.erase(it); } else { it++; } } } RowsetMetaSharedPtr TabletMeta::acquire_rs_meta_by_version(const Version& version) const { for (auto it : _rs_metas) { if (it->version() == version) { return it; } } return nullptr; } RowsetMetaSharedPtr TabletMeta::acquire_stale_rs_meta_by_version(const Version& version) const { for (auto it : _stale_rs_metas) { if (it->version() == version) { return it; } } return nullptr; } void TabletMeta::add_delete_predicate(const DeletePredicatePB& delete_predicate, int64_t version) { for (auto& del_pred : _del_pred_array) { if (del_pred.version() == version) { *del_pred.mutable_sub_predicates() = delete_predicate.sub_predicates(); return; } } DeletePredicatePB* del_pred = _del_pred_array.Add(); del_pred->set_version(version); *del_pred->mutable_sub_predicates() = delete_predicate.sub_predicates(); *del_pred->mutable_in_predicates() = delete_predicate.in_predicates(); } void TabletMeta::remove_delete_predicate_by_version(const Version& version) { DCHECK(version.first == version.second) << "version=" << version; for (int ordinal = 0; ordinal < _del_pred_array.size(); ++ordinal) { const DeletePredicatePB& temp = _del_pred_array.Get(ordinal); if (temp.version() == version.first) { // log delete condition string del_cond_str; for (const auto& it : temp.sub_predicates()) { del_cond_str += it + ";"; } VLOG_NOTICE << "remove one del_pred. version=" << temp.version() << ", condition=" << del_cond_str; // remove delete condition from PB _del_pred_array.SwapElements(ordinal, _del_pred_array.size() - 1); _del_pred_array.RemoveLast(); } } } DelPredicateArray TabletMeta::delete_predicates() const { return _del_pred_array; } bool TabletMeta::version_for_delete_predicate(const Version& version) { if (version.first != version.second) { return false; } for (auto& del_pred : _del_pred_array) { if (del_pred.version() == version.first) { return true; } } return false; } std::string TabletMeta::full_name() const { std::stringstream ss; ss << _tablet_id << "." << _schema_hash << "." << _tablet_uid.to_string(); return ss.str(); } Status TabletMeta::set_partition_id(int64_t partition_id) { if ((_partition_id > 0 && _partition_id != partition_id) || partition_id < 1) { LOG(FATAL) << "cur partition id=" << _partition_id << " new partition id=" << partition_id << " not equal"; } _partition_id = partition_id; return Status::OK(); } bool operator==(const TabletMeta& a, const TabletMeta& b) { if (a._table_id != b._table_id) return false; if (a._partition_id != b._partition_id) return false; if (a._tablet_id != b._tablet_id) return false; if (a._replica_id != b._replica_id) return false; if (a._schema_hash != b._schema_hash) return false; if (a._shard_id != b._shard_id) return false; if (a._creation_time != b._creation_time) return false; if (a._cumulative_layer_point != b._cumulative_layer_point) return false; if (a._tablet_uid != b._tablet_uid) return false; if (a._tablet_type != b._tablet_type) return false; if (a._tablet_state != b._tablet_state) return false; if (*a._schema != *b._schema) return false; if (a._rs_metas.size() != b._rs_metas.size()) return false; for (int i = 0; i < a._rs_metas.size(); ++i) { if (a._rs_metas[i] != b._rs_metas[i]) return false; } if (a._in_restore_mode != b._in_restore_mode) return false; if (a._preferred_rowset_type != b._preferred_rowset_type) return false; if (a._storage_medium != b._storage_medium) return false; if (a._remote_storage_name != b._remote_storage_name) return false; return true; } bool operator!=(const TabletMeta& a, const TabletMeta& b) { return !(a == b); } } // namespace doris
SPDPointsViewerColourTable* createColourTabBGRY() { float rgbVals[256][3] = { {0,0,0}, {0,0,2}, {0,0,4}, {0,0,6}, {0,0,8}, {0,0,10}, {0,0,12}, {0,0,14}, {0,0,16}, {0,0,18}, {0,0,20}, {0,0,22}, {0,0,25}, {0,0,27}, {0,0,29}, {0,0,31}, {0,0,33}, {0,0,35}, {0,0,37}, {0,0,39}, {0,0,41}, {0,0,43}, {0,0,45}, {0,0,47}, {0,0,50}, {0,0,52}, {0,0,54}, {0,0,56}, {0,0,58}, {0,0,60}, {0,0,62}, {0,0,64}, {0,0,66}, {0,3,68}, {0,6,70}, {0,9,72}, {0,12,75}, {0,15,77}, {0,18,79}, {0,21,81}, {0,25,83}, {0,28,85}, {0,31,87}, {0,34,89}, {0,37,91}, {0,40,93}, {0,43,95}, {0,46,97}, {0,50,100}, {0,53,100}, {0,56,100}, {0,59,100}, {0,62,100}, {0,65,100}, {0,68,100}, {0,71,100}, {0,75,100}, {0,78,100}, {0,81,100}, {0,84,100}, {0,87,100}, {0,90,100}, {0,93,100}, {0,96,100}, {0,100,100}, {0,103,100}, {0,106,100}, {0,109,100}, {0,112,100}, {0,115,100}, {0,118,100}, {0,121,100}, {0,125,100}, {0,128,100}, {0,131,100}, {0,134,100}, {0,137,100}, {0,140,100}, {0,143,100}, {0,146,100}, {0,150,100}, {0,150,96}, {0,150,93}, {0,150,90}, {0,150,87}, {0,150,84}, {0,150,81}, {0,150,78}, {0,150,75}, {0,150,71}, {0,150,68}, {0,150,65}, {0,150,62}, {0,150,59}, {0,150,56}, {0,150,53}, {0,150,50}, {0,149,46}, {0,148,43}, {0,148,40}, {0,147,37}, {0,146,34}, {0,146,31}, {0,145,28}, {0,145,25}, {0,144,21}, {0,143,18}, {0,143,15}, {0,142,12}, {0,141,9}, {0,141,6}, {0,140,3}, {0,140,0}, {7,137,0}, {15,135,0}, {22,132,0}, {30,130,0}, {37,127,0}, {45,125,0}, {52,122,0}, {60,120,0}, {67,117,0}, {75,115,0}, {82,112,0}, {90,110,0}, {97,107,0}, {105,105,0}, {112,102,0}, {120,100,0}, {125,93,0}, {130,87,0}, {135,81,0}, {140,75,0}, {145,68,0}, {150,62,0}, {155,56,0}, {160,50,0}, {165,43,0}, {170,37,0}, {175,31,0}, {180,25,0}, {185,18,0}, {190,12,0}, {195,6,0}, {200,0,0}, {200,2,0}, {201,4,0}, {201,6,0}, {202,9,0}, {202,11,0}, {203,13,0}, {203,16,0}, {204,18,0}, {204,20,0}, {205,23,0}, {205,25,0}, {206,27,0}, {206,29,0}, {207,32,0}, {207,34,0}, {208,36,0}, {208,39,0}, {209,41,0}, {209,43,0}, {210,46,0}, {210,48,0}, {211,50,0}, {211,53,0}, {212,55,0}, {212,57,0}, {213,59,0}, {213,62,0}, {214,64,0}, {214,66,0}, {215,69,0}, {215,71,0}, {216,73,0}, {216,76,0}, {217,78,0}, {217,80,0}, {218,83,0}, {218,85,0}, {219,87,0}, {219,89,0}, {220,92,0}, {220,94,0}, {221,96,0}, {221,99,0}, {222,101,0}, {222,103,0}, {223,106,0}, {223,108,0}, {224,110,0}, {224,113,0}, {225,115,0}, {225,117,0}, {226,119,0}, {226,122,0}, {227,124,0}, {227,126,0}, {228,129,0}, {228,131,0}, {229,133,0}, {229,136,0}, {230,138,0}, {230,140,0}, {231,142,0}, {231,145,0}, {232,147,0}, {232,149,0}, {233,152,0}, {233,154,0}, {234,156,0}, {234,159,0}, {235,161,0}, {235,163,0}, {236,166,0}, {236,168,0}, {237,170,0}, {237,172,0}, {238,175,0}, {238,177,0}, {239,179,0}, {239,182,0}, {240,184,0}, {240,186,0}, {241,189,0}, {241,191,0}, {242,193,0}, {242,196,0}, {243,198,0}, {243,200,0}, {244,202,0}, {244,205,0}, {245,207,0}, {245,209,0}, {246,212,0}, {246,214,0}, {247,216,0}, {247,219,0}, {248,221,0}, {248,223,0}, {249,226,0}, {249,228,0}, {250,230,0}, {250,232,0}, {251,235,0}, {251,237,0}, {252,239,0}, {252,242,0}, {253,244,0}, {253,246,0}, {254,249,0}, {254,251,0}, {255,253,0}, {255,255,0}}; SPDPointsViewerColourTable *colourTab = new SPDPointsViewerColourTable(); colourTab->setName("Blue Green Red Yellow"); for(unsigned int i = 0; i < 256; ++i) { ClrVals clrVal; clrVal.val = i; clrVal.red = rgbVals[i][0]/255; clrVal.green = rgbVals[i][1]/255; clrVal.blue = rgbVals[i][2]/255; colourTab->addColorValPair(clrVal); } return colourTab; };
// Hash_Map_With_Allocator_T.cpp // Hash_Map_With_Allocator_T.cpp,v 4.1 1999/06/26 19:54:04 marina Exp #ifndef ACE_HASH_MAP_WITH_ALLOCATOR_T_CPP #define ACE_HASH_MAP_WITH_ALLOCATOR_T_CPP #include "ace/Hash_Map_With_Allocator_T.h" #if !defined (ACE_LACKS_PRAGMA_ONCE) # pragma once #endif /* ACE_LACKS_PRAGMA_ONCE */ #if !defined (__ACE_INLINE__) #include "ace/Hash_Map_With_Allocator_T.i" #endif /* __ACE_INLINE__ */ template <class EXT_ID, class INT_ID> ACE_Hash_Map_With_Allocator<EXT_ID, INT_ID>::ACE_Hash_Map_With_Allocator (ACE_Allocator *alloc) : ACE_Hash_Map_Manager<EXT_ID, INT_ID, ACE_Null_Mutex> (alloc) { ACE_TRACE ("ACE_Hash_Map_With_Allocator<EXT_ID, INT_ID>::ACE_Hash_Map_With_Allocator"); } template <class EXT_ID, class INT_ID> ACE_Hash_Map_With_Allocator<EXT_ID, INT_ID>::ACE_Hash_Map_With_Allocator (size_t size, ACE_Allocator *alloc) : ACE_Hash_Map_Manager<EXT_ID, INT_ID, ACE_Null_Mutex> (size, alloc) { ACE_TRACE ("ACE_Hash_Map_With_Allocator<EXT_ID, INT_ID>::ACE_Hash_Map_With_Allocator"); } #endif /* ACE_HASH_MAP_WITH_ALLOCATOR_T_CPP */
;/*! ; @file ; ; @ingroup fapi ; ; @brief DosQPathInfo DOS wrapper ; ; (c) osFree Project 2022, <http://www.osFree.org> ; for licence see licence.txt in root directory, or project website ; ; This is Family API implementation for DOS, used with BIND tools ; to link required API ; ; @author Yuri Prokushev (yuri.prokushev@gmail.com) ; ;*/ .8086 ; Helpers INCLUDE helpers.inc INCLUDE dos.inc INCLUDE bseerr.inc _TEXT SEGMENT BYTE PUBLIC 'CODE' USE16 @PROLOG DOSQPATHINFO @START DOSQPATHINFO XOR AX,AX EXIT: @EPILOG DOSQPATHINFO _TEXT ENDS END
copyright zengfr site:http://github.com/zengfr/romhack 0029B2 move.w D1, ($6,A4) 0029B6 move.w D1, ($8,A4) 002ACE cmp.w ($8,A4), D0 [base+28E, base+2AE, base+2CE] 002B84 cmp.w ($8,A4), D0 [base+28E, base+2AE, base+2CE] 002B9E move.w (A0)+, D1 [base+28E, base+2AE, base+2CE] 002DD4 move.w ($6,A4), D0 002DD8 bra $2b90 [base+28E, base+2AE, base+2CE] 002DE0 cmp.w ($8,A4), D0 [base+28E, base+2AE, base+2CE] 01A74C dbra D7, $1a74a copyright zengfr site:http://github.com/zengfr/romhack
.386 .model flat,C PUBLIC dosexterr include dpmi32.inc EXTRN __WDOSXRmRegs:RmCallStruc .code dosexterr proc near push ebx push edi mov __WDOSXRmRegs._ah,59h mov __WDOSXRmRegs._bx,0 sub ecx,ecx lea edi,__WDOSXRmRegs mov bl,21h mov eax,300h int 31h pop edi pop ebx mov edx,[esp+4] mov eax,__WDOSXRmRegs._ebx mov [edx+4],ah mov [edx+5],al mov eax,__WDOSXRmRegs._ebx mov [edx+6],ah movzx eax,__WDOSXRmRegs._ax mov [edx],ax ret dosexterr endp end
%include 'src/include/functions.asm' SECTION .data listening db 'listening on port 9001', 0h response db 'HTTP/1.1 200 OK', 0Dh, 0Ah, 'Content-Type: text/html', 0Dh, 0Ah, 'Content-Length: 16', 0Dh, 0Ah, 0Dh, 0Ah, 'Hello World :)', 0Dh, 0Ah, 0h SECTION .bss buffer resb 255 ; place to store headers SECTION .text global _start _start: xor eax, eax ; init 0 xor ebx, ebx xor edi, edi xor esi, esi _socket: push byte 6 ; push 6 to stack - IPPROTO_TCP push byte 1 ; push 1 to stack - SOCK_STREAM push byte 2 ; push 2 to stack - PF_INET mov ecx, esp mov ebx, 1 ; subroutine SOCKET - 1 mov eax, 102 ; sys_socketcall opcode int 80h _bind: mov edi, eax ; move ret of sys_socketcall into edi (file descriptor or -1 on error) push dword 0x00000000 ; 0.0.0.0 push word 0x2923 ; port 9001 dec (reversed bytes) push word 2 ; AF_INET mov ecx, esp push byte 16 ; push 16 dec onto stack (args len) push ecx push edi mov ecx, esp mov ebx, 2 ; BIND mov eax, 102 ; sys_socketcall int 80h mov eax, listening call sprintLF _listen: push byte 1 ; max queue len arg push edi ; file descriptor onto stack mov ecx, esp mov ebx, 4 ; LISTEN mov eax, 102 ; sys_socketcall int 80h _accept: push byte 0 ; address len arg push byte 0 ; address arg push edi ; file descriptor onto stack mov ecx, esp mov ebx, 5 ; ACCEPT mov eax, 102 ; sys_socketcall int 80h _fork: mov esi, eax mov eax, 2 ; sys_fork opcode int 80h cmp eax, 0 ; if 0 we are child jz _read ; child jumps to _read jmp _accept ; parent jumps to _accept _read: mov edx, 255 ; bytes to read (only first 255 for simplicity) mov ecx, buffer ; move addr of buffer to ecx mov ebx, esi ; move accepted file descriptor mov eax, 3 ; sys_read opcode int 80h mov eax, buffer call sprintLF _write: mov edx, 80 ; bytes to write mov ecx, response mov ebx, esi mov eax, 4 ; sys_write opcode int 80h _close: mov ebx, esi mov eax, 6 ; sys_close opcode int 80h _exit: call quit