text stringlengths 1 1.05M |
|---|
; A178115: a(n)=(-1)^C(n+1,2)*(F(n+1)*(1+(-1)^n)/2+F(n+2)*(1-(-1)^n)/2).
; Submitted by Jamie Morken(s1)
; 1,-2,-2,5,5,-13,-13,34,34,-89,-89,233,233,-610,-610,1597,1597,-4181,-4181,10946,10946,-28657,-28657,75025,75025,-196418,-196418,514229,514229,-1346269,-1346269,3524578,3524578,-9227465,-9227465,24157817
mov $2,$0
div $2,2
sub $0,$2
seq $0,99496 ; a(n) = (-1)^n * Fibonacci(2*n+1).
|
; A047925: 3rd column of array in A038150.
; 8,16,29,37,50,63,71,84,92,105,118,126,139,152,160,173,181,194,207,215,228,236,249,262,270,283,296,304,317,325,338,351,359,372,385,393,406,414,427,440,448,461,469,482,495,503,516,529,537,550,558,571,584,592
seq $0,26352 ; a(n) = floor(n*tau)+n+1.
seq $0,276885 ; Sums-complement of the Beatty sequence for 1 + phi.
add $0,4
|
; DCL_PI_A1.asm - Series PI controller on C28x (fixed point) [r1.02]
;
; Copyright (C) 2018 Texas Instruments Incorporated - http://www.ti.com/
; ALL RIGHTS RESERVED
.if __TI_EABI__
.asg DCL_runPI_A1, _DCL_runPI_A1
.endif
.global _DCL_runPI_A1
.sect "dcl32funcs"
; C prototype: int32_t DCL_runPI_A1(DCL_PI32 *p, int32_t rk, int32_t yk)
; argument 1 = *p : DCL_PI32 structure address [XAR4]
; argument 2 = rk : set point reference [ACC]
; argument 3 = yk : feedback [stack-2]
; return = uk : control [ACC]
.align 2
_DCL_runPI_A1:
.asmfunc
MOVL XT, *-SP[4] ; XT = yk
SUBL ACC, XT ; ACC = v1
MOVL XT, ACC ; XT = v1
IMPYL P, XT, *XAR4 ; P = v2(L)
QMPYL ACC, XT, *XAR4++ ; ACC = v2(H)
LSL64 ACC:P, #8 ; ACC = v2 [I8Q24]
MOVL XT, ACC ; XT = v2
IMPYL P, XT, *XAR4 ; P = v3(L)
QMPYL ACC, XT, *XAR4++ ; ACC = v3(H)
LSL64 ACC:P, #8 ; ACC = v3 [I8Q24]
MOVL XAR0, XT ; store v2
MOVL XT, ACC ; XT = v3
IMPYL P, XT, *XAR4 ; P = v8(L)
QMPYL ACC, XT, *XAR4++ ; ACC = v8(H)
LSL64 ACC:P, #8 ; ACC = v8 [I8Q24]
ADDL ACC, *XAR4 ; ACC = v4
SAT ACC ; saturate ACC
MOVL *XAR4++, ACC ; store i10
ADDL ACC, XAR0 ; ACC = v5
SAT ACC ; saturate v5
MOVL P, ACC ; P = v5
MINL ACC, *XAR4++ ; clamp v5 pos
MAXL ACC, *XAR4 ; ACC = uk
PUSH ACC ; push uk to stack
SPM 0 ; zero PM
CMPL ACC, P<<PM ; set flags on (uk-v5)
PUSH ST0 ; save flags
ZAPA ; ACC = P = 0
OR ACC, #0x1000<<12 ; ACC = IQ24(1.0)
POP ST0 ; restore flags
MOVL P, ACC, EQ ; P = i6
SUBB XAR4, #6 ; XAR4 = &i6
MOVL *XAR4, P ; store i6
MOVL ACC, *--SP ; ACC = uk
LRETR ; return uk
.endasmfunc
.end
; end of file
|
; A047434: Numbers that are congruent to {0, 2, 4, 5, 6} mod 8.
; 0,2,4,5,6,8,10,12,13,14,16,18,20,21,22,24,26,28,29,30,32,34,36,37,38,40,42,44,45,46,48,50,52,53,54,56,58,60,61,62,64,66,68,69,70,72,74,76,77,78,80,82,84,85,86,88,90,92,93,94,96,98,100,101,102
mov $2,$0
lpb $0,1
sub $0,1
add $1,2
trn $2,$1
trn $1,$2
sub $2,3
lpe
|
<%
from pwnlib.shellcraft.aarch64.linux import syscall
%>
<%page args="name, length"/>
<%docstring>
Invokes the syscall setdomainname. See 'man 2 setdomainname' for more information.
Arguments:
name(char): name
len(size_t): len
</%docstring>
${syscall('SYS_setdomainname', name, length)}
|
;
; char *asm_strcpy(char *dest, char *src);
;
BITS 64
SECTION .text
GLOBAL asm_strcpy
asm_strcpy:
PUSH RCX
MOV RCX, -1
_loop:
INC RCX
MOV AL, BYTE [RSI + RCX]
MOV BYTE [RDI + RCX], AL
CMP BYTE [RSI + RCX], 0
JNE _loop
_end:
MOV RAX, RDI
POP RCX
RET
|
//---------------------------------------------------------------------------//
// Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
//
// Distributed under the Boost Software License, Version 1.0
// See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
//
// See http://boostorg.github.com/compute for more information.
//---------------------------------------------------------------------------//
#define BOOST_TEST_MODULE TestStack
#include <boost/test/unit_test.hpp>
#include <boost/compute/container/stack.hpp>
#include "context_setup.hpp"
namespace bc = boost::compute;
BOOST_AUTO_TEST_CASE(size)
{
bc::stack<int> stack;
BOOST_CHECK_EQUAL(stack.size(), size_t(0));
stack.push(1);
stack.push(2);
stack.push(3);
BOOST_CHECK_EQUAL(stack.size(), size_t(3));
}
BOOST_AUTO_TEST_CASE(push_and_pop)
{
bc::stack<int> stack;
stack.push(1);
stack.push(2);
stack.push(3);
BOOST_CHECK_EQUAL(stack.top(), 3);
BOOST_CHECK_EQUAL(stack.size(), size_t(3));
stack.pop();
BOOST_CHECK_EQUAL(stack.top(), 2);
BOOST_CHECK_EQUAL(stack.size(), size_t(2));
stack.pop();
BOOST_CHECK_EQUAL(stack.top(), 1);
BOOST_CHECK_EQUAL(stack.size(), size_t(1));
stack.pop();
BOOST_CHECK_EQUAL(stack.size(), size_t(0));
}
BOOST_AUTO_TEST_SUITE_END()
|
.global s_prepare_buffers
s_prepare_buffers:
push %r13
push %r14
push %r15
push %r8
push %r9
push %rcx
push %rdi
push %rsi
lea addresses_normal_ht+0x12541, %rsi
lea addresses_A_ht+0x171, %rdi
nop
nop
nop
add %r13, %r13
mov $117, %rcx
rep movsl
nop
nop
dec %r15
lea addresses_UC_ht+0x13ee1, %r8
nop
nop
nop
nop
add %rdi, %rdi
movb (%r8), %r15b
nop
nop
nop
nop
xor %r15, %r15
lea addresses_WT_ht+0x172c9, %r13
clflush (%r13)
and $2764, %r9
mov (%r13), %edi
nop
and $55864, %r13
lea addresses_WC_ht+0x59e1, %r9
sub $59982, %rdi
movb $0x61, (%r9)
nop
and $27113, %r8
lea addresses_D_ht+0xd54a, %rsi
add %r13, %r13
movl $0x61626364, (%rsi)
nop
nop
nop
nop
xor %r15, %r15
lea addresses_UC_ht+0x1bc19, %rcx
nop
nop
and %r8, %r8
mov (%rcx), %r15d
nop
nop
nop
add $30005, %rcx
lea addresses_D_ht+0x14e45, %r8
nop
nop
nop
nop
nop
dec %r13
movl $0x61626364, (%r8)
nop
nop
nop
cmp %r15, %r15
lea addresses_WT_ht+0x4ee1, %rsi
clflush (%rsi)
nop
nop
nop
nop
add %r13, %r13
mov $0x6162636465666768, %rdi
movq %rdi, %xmm5
vmovups %ymm5, (%rsi)
xor %r15, %r15
lea addresses_D_ht+0xe7e1, %rsi
lea addresses_WC_ht+0x13a21, %rdi
nop
nop
nop
nop
sub %r14, %r14
mov $89, %rcx
rep movsb
nop
nop
nop
add $26033, %rcx
lea addresses_D_ht+0x1207c, %r14
nop
nop
nop
nop
add %r8, %r8
mov $0x6162636465666768, %rdi
movq %rdi, (%r14)
nop
nop
nop
nop
add $20177, %r15
lea addresses_UC_ht+0x158f, %rsi
lea addresses_D_ht+0xefe1, %rdi
add $24700, %r9
mov $51, %rcx
rep movsl
nop
nop
nop
dec %rsi
lea addresses_WT_ht+0x7e1, %rsi
lea addresses_UC_ht+0xb7e1, %rdi
xor %r13, %r13
mov $34, %rcx
rep movsl
nop
nop
nop
nop
nop
sub %rcx, %rcx
lea addresses_A_ht+0x10021, %rdi
nop
nop
nop
nop
nop
cmp %r15, %r15
mov $0x6162636465666768, %r14
movq %r14, (%rdi)
nop
cmp $37296, %r8
pop %rsi
pop %rdi
pop %rcx
pop %r9
pop %r8
pop %r15
pop %r14
pop %r13
ret
.global s_faulty_load
s_faulty_load:
push %r13
push %r14
push %r8
push %r9
push %rax
push %rcx
push %rdx
// Store
mov $0x4d14960000000ca1, %rax
nop
nop
nop
nop
nop
sub $6885, %r14
mov $0x5152535455565758, %r8
movq %r8, (%rax)
nop
nop
add $8548, %r14
// Store
lea addresses_RW+0xe4a1, %rcx
nop
sub $27807, %rax
mov $0x5152535455565758, %r14
movq %r14, (%rcx)
nop
nop
nop
nop
sub $15097, %r8
// Store
mov $0x4bed680000000921, %r14
nop
nop
nop
cmp $32506, %r13
mov $0x5152535455565758, %r8
movq %r8, (%r14)
nop
nop
nop
nop
cmp %rcx, %rcx
// Store
lea addresses_A+0x16fe1, %r9
clflush (%r9)
inc %r14
movw $0x5152, (%r9)
xor $33516, %rcx
// Store
lea addresses_WT+0x1ee23, %r9
nop
xor %r14, %r14
mov $0x5152535455565758, %rax
movq %rax, %xmm3
vmovups %ymm3, (%r9)
nop
nop
and %r8, %r8
// Store
lea addresses_WC+0xcbe1, %r14
nop
nop
nop
xor $41525, %r8
mov $0x5152535455565758, %rcx
movq %rcx, (%r14)
nop
nop
nop
dec %r13
// Faulty Load
lea addresses_A+0x16fe1, %rdx
nop
nop
and %rcx, %rcx
mov (%rdx), %eax
lea oracles, %r13
and $0xff, %rax
shlq $12, %rax
mov (%r13,%rax,1), %rax
pop %rdx
pop %rcx
pop %rax
pop %r9
pop %r8
pop %r14
pop %r13
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'type': 'addresses_A', 'AVXalign': False, 'congruent': 0, 'size': 1, 'same': False, 'NT': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_NC', 'AVXalign': False, 'congruent': 6, 'size': 8, 'same': False, 'NT': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_RW', 'AVXalign': False, 'congruent': 4, 'size': 8, 'same': False, 'NT': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_NC', 'AVXalign': False, 'congruent': 5, 'size': 8, 'same': False, 'NT': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_A', 'AVXalign': False, 'congruent': 0, 'size': 2, 'same': True, 'NT': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_WT', 'AVXalign': False, 'congruent': 1, 'size': 32, 'same': False, 'NT': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_WC', 'AVXalign': False, 'congruent': 10, 'size': 8, 'same': False, 'NT': False}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'type': 'addresses_A', 'AVXalign': False, 'congruent': 0, 'size': 4, 'same': True, 'NT': False}}
<gen_prepare_buffer>
{'OP': 'REPM', 'src': {'type': 'addresses_normal_ht', 'congruent': 4, 'same': False}, 'dst': {'type': 'addresses_A_ht', 'congruent': 3, 'same': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_UC_ht', 'AVXalign': False, 'congruent': 3, 'size': 1, 'same': False, 'NT': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_WT_ht', 'AVXalign': False, 'congruent': 3, 'size': 4, 'same': False, 'NT': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_WC_ht', 'AVXalign': False, 'congruent': 7, 'size': 1, 'same': False, 'NT': True}}
{'OP': 'STOR', 'dst': {'type': 'addresses_D_ht', 'AVXalign': False, 'congruent': 0, 'size': 4, 'same': False, 'NT': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_UC_ht', 'AVXalign': False, 'congruent': 2, 'size': 4, 'same': False, 'NT': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_D_ht', 'AVXalign': False, 'congruent': 1, 'size': 4, 'same': False, 'NT': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_WT_ht', 'AVXalign': False, 'congruent': 2, 'size': 32, 'same': False, 'NT': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_D_ht', 'congruent': 10, 'same': False}, 'dst': {'type': 'addresses_WC_ht', 'congruent': 6, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_D_ht', 'AVXalign': False, 'congruent': 0, 'size': 8, 'same': False, 'NT': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_UC_ht', 'congruent': 1, 'same': False}, 'dst': {'type': 'addresses_D_ht', 'congruent': 9, 'same': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_WT_ht', 'congruent': 11, 'same': False}, 'dst': {'type': 'addresses_UC_ht', 'congruent': 11, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_A_ht', 'AVXalign': False, 'congruent': 6, 'size': 8, 'same': False, 'NT': False}}
{'52': 196}
52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52
*/
|
;Jakub Pilch
;Informatyka IEiT
data segment
tabl db 127 dup (?) ;tablica 127 elementów po 1 bajcie (max input)
licz dw 1 ;licznik przeladowanych danych
argz dw 1 ;licznik argrumentow (oddzielonych spacjami/tabulatorem)
lent dw 4 dup (?) ;miara dlugosci argumentow (oraz adresy ich poczatkow)
;tablica postaci: [adres][dlugosc][adres][dlugosc]...
flaga dw 1 ;flaga oczekiwania na argument.
iternum dw 1 ;liczba operacji l-systemu.
len dw 1 ;dlugosc pojedynczego odcinka krzywej.
mulkeeper dw 1 ;pomocniczo przechowuje mnoznik podczas konwersji liczb.
lsystab db 7170 dup (?) ;tablica l-systemu.
lsyscpy db 7170 dup (?) ;tablica pomocnicza.
lsis db '-', 'F', '+', '+', 'F', '-', 'F' ;"dopisek" do kazdego F.
komu1 db "Blad danych: zla liczba argumentow (oczekiwano 2).$"
komu2 db "Blad: zbyt duza liczba iteracji l-systemu.$"
data ends
;-------------------------------
stack segment stack
dw 256 dup (?) ;stos 256 * 2 bajty
top dw ? ;wierzcholek stosu
stack ends
;------------------------
code segment
.386 ;dopuszczenie instrukcji 386.
;==============================LOADER===========================================
LOADER proc ;laduje argumenty do tabl
;seg tablicy wejsciowej w ES
;seg danych w DS
push ax ;ladowanie rejestrow na stos
push bx ;celem przywrocenia ich na koncu
push cx ;procedury
push dx
mov di,offset tabl ;początek docelowej tablicy
mov si,82h ;w 81h jest spacja
mov ch,byte ptr es:[80h] ;licznik argumentow z wiersza polecen
;-----------------------------------------------
cmp ch,0d ;jesli wywolano bez argumentow
JE stoper ;skocz na koniec
cmp ch,1d ;jesli wywolano z jednym argumentem
JE stoper ;czyli spacja, skocz na koniec
;-----------------------------------------------
mov ax,0 ;zerowanie licznika przeniesionych danych
mov ds:[licz],ax ;licznik przeniesionych arg. wyzerowany
mov ax,0 ;poczatkowa ilosc argumentow.
mov ds:[argz],ax ;licznik arg. oddzielonych bialym znakiem =0.
mov dx,1d
mov ds:[flaga],dx ;flaga oczekiwania=TRUE.
mov bx,offset lent ;offset tablicy dlugosci argumentow do BX.
dec bx ;oczekujemy "przed" tablica na pierwszy arg.
;-----------------------------------------------
whspace:
cmp ch,1d ;czy juz nie ma czego przenosic?
JE stoper ;jeśli tak, skocz do stoper
mov ah,es:[si] ;przenosimy porownywany el. do ah
cmp ah,20h ;czy wczytany znak to spacja?
JNE whtab ;jesli nie, skocz do whtab.
inc si ;jestli tak to przesun offset wejscia
dec ch ;zmniejsz licznik arg. do przeniesienia
mov dx,1d
mov ds:[flaga],dx ;flaga oczekiwania=TRUE.
JMP whspace ;sprawdzamy od nowa
;-----------------------------------------------
whtab:
cmp ah,9h ;czy wczytany znak to tabulacja?
JNE finish ;jesli nie, skocz do finish
inc si ;jesli tak, przesun offset wejscia
dec ch ;zmniejsz licznik arg. do przeniesienia
mov dx,1d
mov ds:[flaga],dx ;flaga oczekiwania=TRUE.
JMP whspace ;i skok do sprawdzania spacji
;-----------------------------------------------
finish:
mov ds:[di],ah ;przerzut do tablicy docelowej
inc si ;przesuwamy offset wejscia
dec ch ;zmniejszamy licznik arg. do przeniesienia
inc ds:[licz] ;zwiekszamy licznik przeniesionych argumentow
cmp ds:[flaga],1d ;czy oczekiwano na argument?
JNE conti ;jesli nie, kontynuuj przeladowanie.
mov dx,0d ;jesli tak:
mov ds:[flaga],dx ;flaga oczekiwania=FALSE.
inc ds:[argz] ;zwieksz licznik argumentow
mov dx,2d
cmp ds:[argz],dx ;porownanie z limitem argumentow
JA argerr ;jesli przekroczony, skok do komuniaktu o bledzie.
inc bx ;jesli nie, przesuwamy sie w tablicy [lent].
mov [bx],di ;jako poczatek kolejnego argumentu: aktualne polozenie w [tabl]
inc bx ;przesuwamy sie do licznika dlugosci kolejnego argumentu[lent]
conti:
inc di ;przesuwamy sie w tablicy docelowej
mov ax,1d
add ds:[bx],ax ;zwiekszamy licznik dlugosci argumentu.
JMP whspace ;i sprawdzamy kolejny znak
;-------------Powrot do programu----------------------
stoper:
pop dx ;przywracamy rejestry
pop cx
pop bx
pop ax
ret ;powrot do programu
LOADER endp
;===============================CHECKUP==============================================
CHECKUP proc ;procedura CHECKUP sprawdza poprawnosc
push ax ;danych przeniesionych do tablicy [tabl]
push bx ;przez procedure LOADER oraz oblicza argumenty liczbowe
push cx ;na podstawie argumentow wejsciowych.
push dx
;-------------Sprawdzenie ilosci argumentow---------------
cmp ds:[argz],2d ;sprawdzenie, czy wywolano z wlasciwa iloscia argumentow
JNE argerr ;jesli nie 2 argumenty, blad.
;-------------Sprawdzenie rozmiaru licznikow-----------
call ITERNUMGETVALUE ;okreslenie wartosci iternum oraz len
call LENGETVALUE ;z argumentow wejsciowych.
cmp ds:[iternum],5 ;czy podana liczba iteracji l-systemu nie jest
JA sizeerr ;zbyt duza? Jesli tak - blad.
;-------------Powrot do programu----------------------
getback:
pop dx ;przywracamy rejestry
pop cx
pop bx
pop ax
ret ;powrot do programu
CHECKUP endp
;=========================ITERNUMGETVALUE=======================================
ITERNUMGETVALUE proc
push ax ;procedura konwertuje pierwszy argument wejsciowy
push bx ;do liczby iternum.
push cx
push dx
;--------------------------------
mov di,offset tabl ;offset pierwszego argumentu do DI.
mov cx,ds:[lent+1] ;dlugosc pierwszego argumentu do CX.
xor ch,ch
add di,cx ;ustawiamy sie na koncu (czytamy od najmlodszych bitow).
mov ds:[mulkeeper],1d ;nasz poczatkowy mnoznik.
mov ds:[iternum],0d ;inicjalizacja.
unpacki:
dec di ;przesuniecie w tablicy.
xor bx,bx
mov bl,ds:[di] ;pobranie znaku z tablicy do BX.
cmp bx,65d ;klasyfikacja znaku, czy jest mniejszy od 'A'?
JB decimalsub ;jesli tak, jest z zakresu 0-9.
sub bx,55d ;jesli nie, jest z zakresu 'A' - 'F'.
JMP multiplier
decimalsub:
sub bx,48d
multiplier:
xor ax,ax
mov ax,ds:[mulkeeper] ;aktualny mnoznik do AX.
mul bx ;DX:AX = AX * BX
add ds:[iternum],ax ;dodanie obliczonej liczby do zmiennej iternum.
mov bx,ds:[mulkeeper] ;mnoznik = mnoznik * 10.
mov ax,10d
mul bx
mov ds:[mulkeeper],ax ;zapisanie nowego mnoznika.
loop unpacki ;powtarzane dla wszystkich znakow wejsciowych.
;------------------------------------
pop dx
pop cx
pop bx
pop ax
ret
ITERNUMGETVALUE endp
;===============================LENGETVALUE======================================
LENGETVALUE proc
push ax ;procedura konwertuje drugi argument wejsciowy
push bx ;do liczby len.
push cx
push dx
;--------------------------------
mov bx,ds:[lent+2] ;adres drugiego argumentu do BX.
xor bh,bh
mov di,bx
mov cx,ds:[lent+3] ;dlugosc drugiego argumentu do CX.
xor ch,ch
add di,cx ;ustawiamy sie na koncu (czytamy od najmlodszych bitow).
mov ds:[mulkeeper],1d ;nasz poczatkowy mnoznik.
mov ds:[len],0d ;inicjalizacja.
unpack:
dec di ;przesuniecie w tablicy.
xor bx,bx
mov bl,ds:[di] ;pobranie znaku z tablicy do BX.
cmp bx,65d ;klasyfikacja znaku, czy jest mniejszy od 'A'?
JB decimalsub ;jesli tak, jest z zakresu 0-9.
sub bx,55d ;jesli nie, jest z zakresu 'A' - 'F'.
JMP multiplier
decimalsub:
sub bx,48d
multiplier:
xor ax,ax
mov ax,ds:[mulkeeper] ;aktualny mnoznik do AX.
mul bx ;DX:AX = AX * BX
add ds:[len],ax ;dodanie obliczonej liczby do zmiennej len.
mov bx,ds:[mulkeeper] ;mnoznik = mnoznik * 10.
mov ax,10d
mul bx
mov ds:[mulkeeper],ax ;zapisanie nowego mnoznika.
loop unpack ;powtarzane dla wszystkich znakow wejsciowych.
;------------------------------------
pop dx
pop cx
pop bx
pop ax
ret
LENGETVALUE endp
;===============================================================================
LSYSTEM proc
push ax ;procedura oblicza instrukcje l-systemu
push bx ;po iternum iteracjach i zapisuje wynik
push cx ;do tablicy lsystab.
push dx
;------------------------------
mov di,offset lsystab ;offset tablicy z l-systemem do DI.
mov si,offset lsyscpy ;offset tablicy pomocniczej z l-systemem do SI.
mov al,'F'
mov ds:[si],al ;zapis poczatkowego l-systemu.
mov ds:[si+3],al
mov ds:[si+6],al
mov al,'+'
mov ds:[si+1],al
mov ds:[si+2],al
mov ds:[si+4],al
mov ds:[si+5],al ;l-system: F++F++F
mov al,0d
mov ds:[si+7],al ;oznaczenie konca aktualnej tablicy.
mov cx,ds:[iternum] ;licznik iteracji do CX.
iterate:
mov di,offset lsystab ;offset tablicy z l-systemem do DI.
mov si,offset lsyscpy ;offset tablicy pomocniczej z l-systemem do SI.
fullsis:
mov al,ds:[si] ;przeniesienie pojedynczego znaku do docelowej tablicy.
mov ds:[di],al
mov ah,'F'
cmp ds:[di],ah ;czy przeniesiono znak 'F'?
JE pluslsis ;jesli tak, skocz do pluslsis.
mov ah,0
cmp ds:[si],ah ;czy przeniesiono ostatni znak?
JE endsis ;jesli tak, skocz do endsis.
inc di
inc si ;przesuniecie w obu tablicach.
JMP fullsis ;powtarzaj od fullsis.
pluslsis:
call LSISADD ;dodaj znaki rozwiniecia do docelowego l-systemu.
inc si
inc di
JMP fullsis ;powtarzaj od fullsis.
endsis:
call TABCOPY ;przenies dane z tabicy docelowej do pomocniczej.
loop iterate ;powtarzaj iteracje.
;--------------------------------
pop dx
pop cx
pop bx
pop ax
ret
LSYSTEM endp
;===============================================================================
LSISADD proc
push ax ;procedura rozszerza F do F-F++F-F.
push bx ;AKTUALNY OFFSET W DOCELOWEJ TABLICY W DI.
push cx
push dx
mov bx,offset lsis ;offset dodawanego ciagu do BX.
dec bx ;oczekiwanie przed tablica.
mov cx,7d ;7 znakow do dodania.
addition:
inc di
inc bx ;przesuniecie w obu tablicach.
mov al,ds:[bx]
mov ds:[di],al ;jeden znak z lsis do wyjsciowego l-systemu.
loop addition ;powtorzenie dla wszystkich znakow lsis.
pop dx
pop cx
pop bx
pop ax
ret
LSISADD endp
;===============================================================================
TABCOPY proc
push ax ;procedura przekopiowuje zawartosc docelowej tablicy
push bx ;do pomocniczej tablicy.
push cx
push dx
;------------------------
mov di,offset lsystab ;offset tablicy z l-systemem do DI.
mov si,offset lsyscpy ;offset tablicy pomocniczej z l-systemem do SI.
dec di
dec si ;oczekiwanie przed tablicami.
copier:
inc di
inc si
mov al,ds:[di]
mov ds:[si],al ;przenies pojedynczy znak z tablicy glownej do pomocniczej.
mov ah,0d
cmp ds:[si],ah ;czy przeniesiono ostatni znak?
JNE copier ;jesli nie, przenos dalej.
;-------------------------
pop dx
pop cx
pop bx
pop ax
ret
TABCOPY endp
;===============================================================================
START:
mov bx,ds
;Program Segment Prefix do BX
mov es,bx ;przenosimy segment do ES dla procedury
mov ax,seg data ;segment danych przeladowany
mov ds,ax ;do DS
;----------------------------------------------------
mov ax,seg stack ;inicjalizacja stosu
mov ss,ax
mov sp,offset top
;----------------------------------------------------
call LOADER ;procedura loader-zaladuje arg. do tabl.
call CHECKUP
;========TESTY TESTY TESTY================
call LSYSTEM
mov cx,30d
mov ah,2
mov si,offset lsystab
petla:
mov dx,ds:[si]
int 21h
inc si
loop petla
;==========TESTY TESTY TESTY==============
mov ah,4ch ;zakonczenie programu.
int 21h
;****************BLAD ilosci argumentow*************************
argerr:
mov dx,offset komu1 ;napis komunikatu do rejestru DX
mov ah,9 ;przerwanie nr 9 wypisuje lancuch zakonczony $
int 21h ;komunikat o zlej liczbie argumentow
mov ah,4ch ;i zakonczenie programu.
int 21h
;****************BLAD rozmiaru liczb*************************
sizeerr:
mov dx,offset komu2 ;napis komunikatu do rejestru DX
mov ah,9 ;przerwanie nr 9 wypisuje lancuch zakonczony $
int 21h ;komunikat o zbyt duzym rozmiarze iternum.
mov ah,4ch ;i zakonczenie programu.
int 21h
code ends
end START |
; A055899: Column 3 of triangle A055898.
; 1,7,31,101,272,636,1340,2600,4725,8135,13391,21217,32536,48496,70512,100296,139905,191775,258775,344245,452056,586652,753116,957216,1205477,1505231,1864695,2293025,2800400,3398080,4098496,4915312
mov $16,$0
mov $18,$0
add $18,1
lpb $18,1
clr $0,16
mov $0,$16
sub $18,1
sub $0,$18
mov $13,$0
mov $15,$0
add $15,1
lpb $15,1
clr $0,13
mov $0,$13
sub $15,1
sub $0,$15
mov $10,$0
mov $12,$0
add $12,1
lpb $12,1
clr $0,10
mov $0,$10
sub $12,1
sub $0,$12
mov $7,$0
mov $9,$0
add $9,1
lpb $9,1
mov $0,$7
sub $9,1
sub $0,$9
mov $3,$0
mul $3,$0
mov $6,2
add $6,$0
add $3,$6
sub $3,1
div $6,2
mov $2,$6
sub $6,1
mul $6,$2
add $6,$3
add $8,$6
lpe
add $11,$8
lpe
add $14,$11
lpe
add $17,$14
lpe
mov $1,$17
|
#ifndef RTMATH_H
#define RTMATH_H
/* This contains some extra math/utility definitions for ray tracing. */
/* Delta function - equals 1 if x equals zero, 0 otherwise. Note the very generous delta epsilon. */
#define delta(x) (float)(std::abs(x) <= 1e-3f)
/* Uniform number generation (for C++11 PRNG's only). */
#define RandomVariable(x) (((*x)() - x->min()) / (float)x->max())
#endif
|
;--------------------------------------------------------
; File Created by SDCC : free open source ANSI-C Compiler
; Version 4.1.4 #12274 (Linux)
;--------------------------------------------------------
; Processed by Z88DK
;--------------------------------------------------------
EXTERN __divschar
EXTERN __divschar_callee
EXTERN __divsint
EXTERN __divsint_callee
EXTERN __divslong
EXTERN __divslong_callee
EXTERN __divslonglong
EXTERN __divslonglong_callee
EXTERN __divsuchar
EXTERN __divsuchar_callee
EXTERN __divuchar
EXTERN __divuchar_callee
EXTERN __divuint
EXTERN __divuint_callee
EXTERN __divulong
EXTERN __divulong_callee
EXTERN __divulonglong
EXTERN __divulonglong_callee
EXTERN __divuschar
EXTERN __divuschar_callee
EXTERN __modschar
EXTERN __modschar_callee
EXTERN __modsint
EXTERN __modsint_callee
EXTERN __modslong
EXTERN __modslong_callee
EXTERN __modslonglong
EXTERN __modslonglong_callee
EXTERN __modsuchar
EXTERN __modsuchar_callee
EXTERN __moduchar
EXTERN __moduchar_callee
EXTERN __moduint
EXTERN __moduint_callee
EXTERN __modulong
EXTERN __modulong_callee
EXTERN __modulonglong
EXTERN __modulonglong_callee
EXTERN __moduschar
EXTERN __moduschar_callee
EXTERN __mulint
EXTERN __mulint_callee
EXTERN __mullong
EXTERN __mullong_callee
EXTERN __mullonglong
EXTERN __mullonglong_callee
EXTERN __mulschar
EXTERN __mulschar_callee
EXTERN __mulsuchar
EXTERN __mulsuchar_callee
EXTERN __muluchar
EXTERN __muluchar_callee
EXTERN __muluschar
EXTERN __muluschar_callee
EXTERN __rlslonglong
EXTERN __rlslonglong_callee
EXTERN __rlulonglong
EXTERN __rlulonglong_callee
EXTERN __rrslonglong
EXTERN __rrslonglong_callee
EXTERN __rrulonglong
EXTERN __rrulonglong_callee
EXTERN ___sdcc_call_hl
EXTERN ___sdcc_call_iy
EXTERN ___sdcc_enter_ix
EXTERN banked_call
EXTERN _banked_ret
EXTERN ___fs2schar
EXTERN ___fs2schar_callee
EXTERN ___fs2sint
EXTERN ___fs2sint_callee
EXTERN ___fs2slong
EXTERN ___fs2slong_callee
EXTERN ___fs2slonglong
EXTERN ___fs2slonglong_callee
EXTERN ___fs2uchar
EXTERN ___fs2uchar_callee
EXTERN ___fs2uint
EXTERN ___fs2uint_callee
EXTERN ___fs2ulong
EXTERN ___fs2ulong_callee
EXTERN ___fs2ulonglong
EXTERN ___fs2ulonglong_callee
EXTERN ___fsadd
EXTERN ___fsadd_callee
EXTERN ___fsdiv
EXTERN ___fsdiv_callee
EXTERN ___fseq
EXTERN ___fseq_callee
EXTERN ___fsgt
EXTERN ___fsgt_callee
EXTERN ___fslt
EXTERN ___fslt_callee
EXTERN ___fsmul
EXTERN ___fsmul_callee
EXTERN ___fsneq
EXTERN ___fsneq_callee
EXTERN ___fssub
EXTERN ___fssub_callee
EXTERN ___schar2fs
EXTERN ___schar2fs_callee
EXTERN ___sint2fs
EXTERN ___sint2fs_callee
EXTERN ___slong2fs
EXTERN ___slong2fs_callee
EXTERN ___slonglong2fs
EXTERN ___slonglong2fs_callee
EXTERN ___uchar2fs
EXTERN ___uchar2fs_callee
EXTERN ___uint2fs
EXTERN ___uint2fs_callee
EXTERN ___ulong2fs
EXTERN ___ulong2fs_callee
EXTERN ___ulonglong2fs
EXTERN ___ulonglong2fs_callee
EXTERN ____sdcc_2_copy_src_mhl_dst_deix
EXTERN ____sdcc_2_copy_src_mhl_dst_bcix
EXTERN ____sdcc_4_copy_src_mhl_dst_deix
EXTERN ____sdcc_4_copy_src_mhl_dst_bcix
EXTERN ____sdcc_4_copy_src_mhl_dst_mbc
EXTERN ____sdcc_4_ldi_nosave_bc
EXTERN ____sdcc_4_ldi_save_bc
EXTERN ____sdcc_4_push_hlix
EXTERN ____sdcc_4_push_mhl
EXTERN ____sdcc_lib_setmem_hl
EXTERN ____sdcc_ll_add_de_bc_hl
EXTERN ____sdcc_ll_add_de_bc_hlix
EXTERN ____sdcc_ll_add_de_hlix_bc
EXTERN ____sdcc_ll_add_de_hlix_bcix
EXTERN ____sdcc_ll_add_deix_bc_hl
EXTERN ____sdcc_ll_add_deix_hlix
EXTERN ____sdcc_ll_add_hlix_bc_deix
EXTERN ____sdcc_ll_add_hlix_deix_bc
EXTERN ____sdcc_ll_add_hlix_deix_bcix
EXTERN ____sdcc_ll_asr_hlix_a
EXTERN ____sdcc_ll_asr_mbc_a
EXTERN ____sdcc_ll_copy_src_de_dst_hlix
EXTERN ____sdcc_ll_copy_src_de_dst_hlsp
EXTERN ____sdcc_ll_copy_src_deix_dst_hl
EXTERN ____sdcc_ll_copy_src_deix_dst_hlix
EXTERN ____sdcc_ll_copy_src_deixm_dst_hlsp
EXTERN ____sdcc_ll_copy_src_desp_dst_hlsp
EXTERN ____sdcc_ll_copy_src_hl_dst_de
EXTERN ____sdcc_ll_copy_src_hlsp_dst_de
EXTERN ____sdcc_ll_copy_src_hlsp_dst_deixm
EXTERN ____sdcc_ll_lsl_hlix_a
EXTERN ____sdcc_ll_lsl_mbc_a
EXTERN ____sdcc_ll_lsr_hlix_a
EXTERN ____sdcc_ll_lsr_mbc_a
EXTERN ____sdcc_ll_push_hlix
EXTERN ____sdcc_ll_push_mhl
EXTERN ____sdcc_ll_sub_de_bc_hl
EXTERN ____sdcc_ll_sub_de_bc_hlix
EXTERN ____sdcc_ll_sub_de_hlix_bc
EXTERN ____sdcc_ll_sub_de_hlix_bcix
EXTERN ____sdcc_ll_sub_deix_bc_hl
EXTERN ____sdcc_ll_sub_deix_hlix
EXTERN ____sdcc_ll_sub_hlix_bc_deix
EXTERN ____sdcc_ll_sub_hlix_deix_bc
EXTERN ____sdcc_ll_sub_hlix_deix_bcix
EXTERN ____sdcc_load_debc_deix
EXTERN ____sdcc_load_dehl_deix
EXTERN ____sdcc_load_debc_mhl
EXTERN ____sdcc_load_hlde_mhl
EXTERN ____sdcc_store_dehl_bcix
EXTERN ____sdcc_store_debc_hlix
EXTERN ____sdcc_store_debc_mhl
EXTERN ____sdcc_cpu_pop_ei
EXTERN ____sdcc_cpu_pop_ei_jp
EXTERN ____sdcc_cpu_push_di
EXTERN ____sdcc_outi
EXTERN ____sdcc_outi_128
EXTERN ____sdcc_outi_256
EXTERN ____sdcc_ldi
EXTERN ____sdcc_ldi_128
EXTERN ____sdcc_ldi_256
EXTERN ____sdcc_4_copy_srcd_hlix_dst_deix
EXTERN ____sdcc_4_and_src_mbc_mhl_dst_deix
EXTERN ____sdcc_4_or_src_mbc_mhl_dst_deix
EXTERN ____sdcc_4_xor_src_mbc_mhl_dst_deix
EXTERN ____sdcc_4_or_src_dehl_dst_bcix
EXTERN ____sdcc_4_xor_src_dehl_dst_bcix
EXTERN ____sdcc_4_and_src_dehl_dst_bcix
EXTERN ____sdcc_4_xor_src_mbc_mhl_dst_debc
EXTERN ____sdcc_4_or_src_mbc_mhl_dst_debc
EXTERN ____sdcc_4_and_src_mbc_mhl_dst_debc
EXTERN ____sdcc_4_cpl_src_mhl_dst_debc
EXTERN ____sdcc_4_xor_src_debc_mhl_dst_debc
EXTERN ____sdcc_4_or_src_debc_mhl_dst_debc
EXTERN ____sdcc_4_and_src_debc_mhl_dst_debc
EXTERN ____sdcc_4_and_src_debc_hlix_dst_debc
EXTERN ____sdcc_4_or_src_debc_hlix_dst_debc
EXTERN ____sdcc_4_xor_src_debc_hlix_dst_debc
;--------------------------------------------------------
; Public variables in this module
;--------------------------------------------------------
GLOBAL _m32_coshf
;--------------------------------------------------------
; Externals used
;--------------------------------------------------------
GLOBAL _m32_polyf
GLOBAL _m32_hypotf
GLOBAL _m32_ldexpf
GLOBAL _m32_frexpf
GLOBAL _m32_invsqrtf
GLOBAL _m32_sqrtf
GLOBAL _m32_invf
GLOBAL _m32_sqrf
GLOBAL _m32_div2f
GLOBAL _m32_mul2f
GLOBAL _m32_modff
GLOBAL _m32_fmodf
GLOBAL _m32_roundf
GLOBAL _m32_floorf
GLOBAL _m32_fabsf
GLOBAL _m32_ceilf
GLOBAL _m32_powf
GLOBAL _m32_log10f
GLOBAL _m32_log2f
GLOBAL _m32_logf
GLOBAL _m32_exp10f
GLOBAL _m32_exp2f
GLOBAL _m32_expf
GLOBAL _m32_atanhf
GLOBAL _m32_acoshf
GLOBAL _m32_asinhf
GLOBAL _m32_tanhf
GLOBAL _m32_sinhf
GLOBAL _m32_atan2f
GLOBAL _m32_atanf
GLOBAL _m32_acosf
GLOBAL _m32_asinf
GLOBAL _m32_tanf
GLOBAL _m32_cosf
GLOBAL _m32_sinf
GLOBAL _poly_callee
GLOBAL _poly
GLOBAL _exp10_fastcall
GLOBAL _exp10
GLOBAL _mul10u_fastcall
GLOBAL _mul10u
GLOBAL _mul2_fastcall
GLOBAL _mul2
GLOBAL _div2_fastcall
GLOBAL _div2
GLOBAL _invsqrt_fastcall
GLOBAL _invsqrt
GLOBAL _inv_fastcall
GLOBAL _inv
GLOBAL _sqr_fastcall
GLOBAL _sqr
GLOBAL _isunordered_callee
GLOBAL _isunordered
GLOBAL _islessgreater_callee
GLOBAL _islessgreater
GLOBAL _islessequal_callee
GLOBAL _islessequal
GLOBAL _isless_callee
GLOBAL _isless
GLOBAL _isgreaterequal_callee
GLOBAL _isgreaterequal
GLOBAL _isgreater_callee
GLOBAL _isgreater
GLOBAL _fma_callee
GLOBAL _fma
GLOBAL _fmin_callee
GLOBAL _fmin
GLOBAL _fmax_callee
GLOBAL _fmax
GLOBAL _fdim_callee
GLOBAL _fdim
GLOBAL _nexttoward_callee
GLOBAL _nexttoward
GLOBAL _nextafter_callee
GLOBAL _nextafter
GLOBAL _nan_fastcall
GLOBAL _nan
GLOBAL _copysign_callee
GLOBAL _copysign
GLOBAL _remquo_callee
GLOBAL _remquo
GLOBAL _remainder_callee
GLOBAL _remainder
GLOBAL _fmod_callee
GLOBAL _fmod
GLOBAL _modf_callee
GLOBAL _modf
GLOBAL _trunc_fastcall
GLOBAL _trunc
GLOBAL _lround_fastcall
GLOBAL _lround
GLOBAL _round_fastcall
GLOBAL _round
GLOBAL _lrint_fastcall
GLOBAL _lrint
GLOBAL _rint_fastcall
GLOBAL _rint
GLOBAL _nearbyint_fastcall
GLOBAL _nearbyint
GLOBAL _floor_fastcall
GLOBAL _floor
GLOBAL _ceil_fastcall
GLOBAL _ceil
GLOBAL _tgamma_fastcall
GLOBAL _tgamma
GLOBAL _lgamma_fastcall
GLOBAL _lgamma
GLOBAL _erfc_fastcall
GLOBAL _erfc
GLOBAL _erf_fastcall
GLOBAL _erf
GLOBAL _cbrt_fastcall
GLOBAL _cbrt
GLOBAL _sqrt_fastcall
GLOBAL _sqrt
GLOBAL _pow_callee
GLOBAL _pow
GLOBAL _hypot_callee
GLOBAL _hypot
GLOBAL _fabs_fastcall
GLOBAL _fabs
GLOBAL _logb_fastcall
GLOBAL _logb
GLOBAL _log2_fastcall
GLOBAL _log2
GLOBAL _log1p_fastcall
GLOBAL _log1p
GLOBAL _log10_fastcall
GLOBAL _log10
GLOBAL _log_fastcall
GLOBAL _log
GLOBAL _scalbln_callee
GLOBAL _scalbln
GLOBAL _scalbn_callee
GLOBAL _scalbn
GLOBAL _ldexp_callee
GLOBAL _ldexp
GLOBAL _ilogb_fastcall
GLOBAL _ilogb
GLOBAL _frexp_callee
GLOBAL _frexp
GLOBAL _expm1_fastcall
GLOBAL _expm1
GLOBAL _exp2_fastcall
GLOBAL _exp2
GLOBAL _exp_fastcall
GLOBAL _exp
GLOBAL _tanh_fastcall
GLOBAL _tanh
GLOBAL _sinh_fastcall
GLOBAL _sinh
GLOBAL _cosh_fastcall
GLOBAL _cosh
GLOBAL _atanh_fastcall
GLOBAL _atanh
GLOBAL _asinh_fastcall
GLOBAL _asinh
GLOBAL _acosh_fastcall
GLOBAL _acosh
GLOBAL _tan_fastcall
GLOBAL _tan
GLOBAL _sin_fastcall
GLOBAL _sin
GLOBAL _cos_fastcall
GLOBAL _cos
GLOBAL _atan2_callee
GLOBAL _atan2
GLOBAL _atan_fastcall
GLOBAL _atan
GLOBAL _asin_fastcall
GLOBAL _asin
GLOBAL _acos_fastcall
GLOBAL _acos
;--------------------------------------------------------
; special function registers
;--------------------------------------------------------
;--------------------------------------------------------
; ram data
;--------------------------------------------------------
SECTION bss_compiler
;--------------------------------------------------------
; ram data
;--------------------------------------------------------
IF 0
; .area _INITIALIZED removed by z88dk
ENDIF
;--------------------------------------------------------
; absolute external ram data
;--------------------------------------------------------
SECTION IGNORE
;--------------------------------------------------------
; global & static initialisations
;--------------------------------------------------------
SECTION code_crt_init
;--------------------------------------------------------
; Home
;--------------------------------------------------------
SECTION IGNORE
;--------------------------------------------------------
; code
;--------------------------------------------------------
SECTION code_compiler
; ---------------------------------
; Function m32_coshf
; ---------------------------------
_m32_coshf:
push ix
ld ix,0
add ix,sp
push af
push af
call _m32_expf
ex (sp), hl
ld (ix-2),e
ld (ix-1),d
pop hl
push hl
ld e,(ix-2)
ld d,(ix-1)
call _m32_invf
push de
push hl
ld l,(ix-2)
ld h,(ix-1)
push hl
ld l,(ix-4)
ld h,(ix-3)
push hl
call ___fsadd_callee
call _m32_div2f
ld sp, ix
pop ix
ret
SECTION IGNORE
|
; A066079: Arises in detailed black hole state counting in loop quantum gravity.
; 3,8,15,24,35,63,80,99,120,143,168,195,224,255
mov $1,2
mov $2,$0
mov $3,$0
lpb $2
mod $2,5
add $3,1
lpe
add $1,$3
pow $1,2
sub $1,1
mov $0,$1
|
;This file contain tests for the various function of math.asm and printing.asm
;It should be printed as 'reflet-nasm libtesting.asm math.asm printing.asm -o out.bin'
;It can then be tested as following: (TODO when the simulator will have a nice cli write a tuto here)
@import libs/import_all_libs.asm
@align_word
label testString
@string Reflet is a neat ISA!
@rawbytes 0A 0
label start
callf testingPrinting
callf testingMath
quit
label testingMath
set 13 ;testing intMult
cpy R1
set 15
cpy R2
callf intMult
read R1
debug ;expexting 13x5 = 195 = 0xc3
set 15 ;testing intDiv
cpy R1
set 4
cpy R2
callf intDiv
read R1
debug ;expecting 15/4 = 3 = 0x3
read R2
debug ;expecting 15%4 = 3 = 0x3
set 10 ;testing intPow
cpy R1
set 4
cpy R2
callf intPow
read R1
debug ;expecting 10^4 = 10000 = 0x2710
ret
label testingPrinting
set+ 64
cpy R1
callf printc ;should print '@'
callf CR ;should print a newline
setlab testString
cpy R1
callf strlen
read R1
debug ;expecting the length of the string which is 22 = 0x16
setlab testString
cpy R1
callf print ;should print "Reflet is a neat ISA!\n"
set+ 200
add SP
cpy R2
set+ 0xABCD
cpy R1
callf printNum ;expecting '43981'
callf CR
set+ 34567
cpy R1
callf printNum ;expecting '34567'
callf CR
set 0
cpy R1
callf printNum ;expecting '0'
callf CR
callf getch ;Ask for a char
callf printc ;Print it 3 times
callf printc
callf printc
callf CR
ret
|
#include "../lib/mainwindow.h"
#include "../lib/fileio.h"
#include "../lib/employee.h"
#include <QApplication>
#include <time.h>
#include <cstdlib>
int main(int argc, char *argv[])
{
srand(time(NULL));
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
|
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2012 The Bitcoin Developers
// Copyright (c) 2011-2017 The Peercoin developers
// Copyright (c) 2017-2018 The Stronghands developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "protocol.h"
#include "util.h"
#include "netbase.h"
#include "main.h"
#ifndef WIN32
# include <arpa/inet.h>
#endif
// The message start string is designed to be unlikely to occur in normal data.
// The characters are rarely used upper ascii, not valid as UTF-8, and produce
// a large 4-byte int at any alignment.
// Public testnet message start
// unsigned char pchMessageStartTestBitcoin[4] = { 0xcf, 0xbf, 0xb5, 0xfc };
static unsigned char pchMessageStartTestOld[4] = { 0xcf, 0xe1, 0xf2, 0xfc };
static unsigned char pchMessageStartTestNew[4] = { 0xcf, 0xf2, 0xc0, 0xfc };
static unsigned int nMessageStartTestSwitchTime = 1346200000;
// StrongHands message start (switch from Bitcoin's in v0.2)
static unsigned char pchMessageStartBitcoin[4] = { 0xcf, 0xbe, 0xb4, 0xfc };
static unsigned char pchMessageStartStrongHands[4] = { 0x46, 0x55, 0x43, 0x4b };
static unsigned int nMessageStartSwitchTime = 1347300000;
unsigned char pchMessageStart[4] = { 0x46, 0x55, 0x43, 0x4b };
void GetMessageStart(unsigned char pchMessageStart[], bool fPersistent)
{
if (fTestNet)
memcpy(pchMessageStart, (fPersistent || GetAdjustedTime() > nMessageStartTestSwitchTime)? pchMessageStartTestNew : pchMessageStartTestOld, sizeof(pchMessageStartTestNew));
else
memcpy(pchMessageStart, (fPersistent || GetAdjustedTime() > nMessageStartSwitchTime)? pchMessageStartStrongHands : pchMessageStartBitcoin, sizeof(pchMessageStartStrongHands));
}
static const char* ppszTypeName[] =
{
"ERROR",
"tx",
"block",
"filtered block"
};
CMessageHeader::CMessageHeader()
{
memcpy(pchMessageStart, ::pchMessageStart, sizeof(pchMessageStart));
memset(pchCommand, 0, sizeof(pchCommand));
pchCommand[1] = 1;
nMessageSize = -1;
nChecksum = 0;
}
CMessageHeader::CMessageHeader(const char* pszCommand, unsigned int nMessageSizeIn)
{
memcpy(pchMessageStart, ::pchMessageStart, sizeof(pchMessageStart));
strncpy(pchCommand, pszCommand, COMMAND_SIZE);
nMessageSize = nMessageSizeIn;
nChecksum = 0;
}
std::string CMessageHeader::GetCommand() const
{
if (pchCommand[COMMAND_SIZE-1] == 0)
return std::string(pchCommand, pchCommand + strlen(pchCommand));
else
return std::string(pchCommand, pchCommand + COMMAND_SIZE);
}
bool CMessageHeader::IsValid() const
{
// Check start string
if (memcmp(pchMessageStart, ::pchMessageStart, sizeof(pchMessageStart)) != 0)
return false;
// Check the command string for errors
for (const char* p1 = pchCommand; p1 < pchCommand + COMMAND_SIZE; p1++)
{
if (*p1 == 0)
{
// Must be all zeros after the first zero
for (; p1 < pchCommand + COMMAND_SIZE; p1++)
if (*p1 != 0)
return false;
}
else if (*p1 < ' ' || *p1 > 0x7E)
return false;
}
// Message size
if (nMessageSize > MAX_SIZE)
{
printf("CMessageHeader::IsValid() : (%s, %u bytes) nMessageSize > MAX_SIZE\n", GetCommand().c_str(), nMessageSize);
return false;
}
return true;
}
CAddress::CAddress() : CService()
{
Init();
}
CAddress::CAddress(CService ipIn, uint64 nServicesIn) : CService(ipIn)
{
Init();
nServices = nServicesIn;
}
void CAddress::Init()
{
nServices = NODE_NETWORK;
nTime = 100000000;
nLastTry = 0;
}
CInv::CInv()
{
type = 0;
hash = 0;
}
CInv::CInv(int typeIn, const uint256& hashIn)
{
type = typeIn;
hash = hashIn;
}
CInv::CInv(const std::string& strType, const uint256& hashIn)
{
unsigned int i;
for (i = 1; i < ARRAYLEN(ppszTypeName); i++)
{
if (strType == ppszTypeName[i])
{
type = i;
break;
}
}
if (i == ARRAYLEN(ppszTypeName))
throw std::out_of_range(strprintf("CInv::CInv(string, uint256) : unknown type '%s'", strType.c_str()));
hash = hashIn;
}
bool operator<(const CInv& a, const CInv& b)
{
return (a.type < b.type || (a.type == b.type && a.hash < b.hash));
}
bool CInv::IsKnownType() const
{
return (type >= 1 && type < (int)ARRAYLEN(ppszTypeName));
}
const char* CInv::GetCommand() const
{
if (!IsKnownType())
throw std::out_of_range(strprintf("CInv::GetCommand() : type=%d unknown type", type));
return ppszTypeName[type];
}
std::string CInv::ToString() const
{
return strprintf("%s %s", GetCommand(), hash.ToString().c_str());
}
void CInv::print() const
{
printf("CInv(%s)\n", ToString().c_str());
}
|
; ===============================================================
; October 2014
; ===============================================================
;
; int close(int fd)
;
; Flush and then close the file.
;
; ===============================================================
INCLUDE "clib_cfg.asm"
SECTION code_clib
SECTION code_fcntl
PUBLIC asm_close, asm0_close
EXTERN __fcntl_fdstruct_from_fd_2, __fcntl_fdchain_descend
EXTERN error_mc, error_znc, __stdio_heap, asm_heap_free
EXTERN STDIO_MSG_CLOS, STDIO_MSG_FLSH, l_jpix
asm_close:
; enter : hl = int fd
;
; exit : success
;
; hl = 0
; carry reset
;
; fail
;
; hl = -1
; carry set, errno set
;
; uses : all except iy
; clear fd table entry
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
IF __CLIB_OPT_MULTITHREAD & $08
EXTERN __fcntl_lock_fdtbl
call __fcntl_lock_fdbtl
ENDIF
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
call __fcntl_fdstruct_from_fd_2
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
IF __CLIB_OPT_MULTITHREAD & $08
jr c, exit_ebdfd ; if fd invalid
ld (hl),0
dec hl
ld (hl),0 ; clear fd entry
exit_ebdfd:
EXTERN __fcntl_unlock_fdtbl
call __fcntl_unlock_fdbtl
jp c, error_mc ; if fd invalid
ELSE
jp c, error_mc ; if fd invalid
ld (hl),0
dec hl
ld (hl),0 ; clear fd entry
ENDIF
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; adjust reference count
ld c,1
asm0_close:
; ix = FDSTRUCT *
; c = ref_count_adj
ld a,(ix+7)
sub c
ld (ix+7),a ; store adjusted reference count
jr z, close_fdstruct ; if ref_count reached zero
jr c, close_fdstruct ; if ref_count < 0
; fdstructs further in chain need to be adjusted too
; if their reference counts reach zero, it is a bug so attempt fix
ld b,a ; b = current max ref_count after adjust
ref_count_loop:
; ix = FDSTRUCT *
; b = current max ref_count after adjust
; c = ref_count_adj
call __fcntl_fdchain_descend
jp z, error_znc ; return success if end of chain reached
ld a,(ix+7)
sub c
jr c, bugged ; if adjusted ref_count < 0
cp b
jr c, bugged ; if adjusted ref_count < parent ref_count
ld b,a ; b = possibly larger child ref_count
rejoin_loop:
ld (ix+7),a ; store adjusted ref_count
jr ref_count_loop
bugged:
ld a,b ; inherit parent ref_count to fix
jr rejoin_loop
close_fdstruct:
; fdstruct is being closed
; ix = FDSTRUCT *
; c = ref_count_adj
push bc ; save ref_count_adj
ld a,STDIO_MSG_FLSH
call l_jpix
ld a,STDIO_MSG_CLOS
call l_jpix
push af ; save close flag
push ix
pop hl ; hl = FDSTRUCT *
call __fcntl_fdchain_descend
push af ; save descend flag
ld de,__stdio_heap
call asm_heap_free ; free(FDSTRUCT)
pop af ; descend flag
pop de ; close flag
pop bc ; c = ref_count_adj
jr nz, asm0_close ; if chain continues
bit 0,e ; check carry flag (close flag)
jp z, error_znc ; if close successful
jp error_mc ; if close failed
|
.global s_prepare_buffers
s_prepare_buffers:
push %r12
push %r13
push %r15
push %rbp
push %rcx
push %rdi
push %rdx
push %rsi
lea addresses_normal_ht+0x17163, %rsi
lea addresses_normal_ht+0x18153, %rdi
nop
inc %r15
mov $58, %rcx
rep movsl
nop
cmp %rcx, %rcx
lea addresses_normal_ht+0xe953, %rsi
lea addresses_normal_ht+0x16d53, %rdi
dec %rdx
mov $56, %rcx
rep movsq
nop
nop
nop
nop
cmp $43283, %rsi
lea addresses_WC_ht+0x2553, %rsi
lea addresses_normal_ht+0xb153, %rdi
nop
nop
sub %rbp, %rbp
mov $13, %rcx
rep movsw
nop
nop
nop
nop
inc %rcx
lea addresses_WC_ht+0x8723, %rbp
nop
sub $11097, %r15
mov $0x6162636465666768, %rdi
movq %rdi, %xmm1
and $0xffffffffffffffc0, %rbp
vmovntdq %ymm1, (%rbp)
nop
xor $23595, %rdi
lea addresses_A_ht+0xf657, %rdi
nop
nop
nop
nop
xor $11142, %r13
movb (%rdi), %dl
cmp %rdx, %rdx
lea addresses_WT_ht+0xd153, %rsi
lea addresses_normal_ht+0x16853, %rdi
clflush (%rsi)
nop
nop
nop
nop
and $25467, %r15
mov $81, %rcx
rep movsb
nop
nop
inc %r13
lea addresses_normal_ht+0x16d9b, %rdi
nop
nop
nop
nop
nop
and $42125, %r15
mov (%rdi), %ebp
and $11839, %rbp
lea addresses_WT_ht+0x4f97, %r15
nop
nop
cmp $3999, %rdx
movl $0x61626364, (%r15)
sub $14810, %rdi
lea addresses_A_ht+0x1ac73, %rdx
nop
nop
sub %rsi, %rsi
mov (%rdx), %rdi
nop
nop
nop
nop
add $19443, %rdi
lea addresses_WT_ht+0x7b83, %r13
nop
nop
nop
sub $33260, %rdi
mov $0x6162636465666768, %rdx
movq %rdx, %xmm6
movups %xmm6, (%r13)
nop
and $42041, %rdx
lea addresses_normal_ht+0xcf1b, %rsi
lea addresses_WC_ht+0x1c90b, %rdi
nop
nop
nop
nop
xor $15522, %r12
mov $3, %rcx
rep movsw
nop
cmp %rbp, %rbp
lea addresses_WT_ht+0x10253, %r15
nop
nop
nop
nop
dec %rbp
vmovups (%r15), %ymm6
vextracti128 $0, %ymm6, %xmm6
vpextrq $0, %xmm6, %rcx
nop
nop
nop
nop
inc %rsi
lea addresses_WC_ht+0x105af, %rbp
nop
nop
nop
nop
and $1607, %rdx
mov (%rbp), %r15w
nop
nop
nop
nop
nop
cmp %rdi, %rdi
lea addresses_WT_ht+0x13153, %rsi
lea addresses_normal_ht+0x15d43, %rdi
sub %r13, %r13
mov $101, %rcx
rep movsl
nop
nop
add $17731, %rsi
lea addresses_D_ht+0xd753, %rbp
nop
nop
nop
and %rdx, %rdx
mov (%rbp), %edi
and $56129, %r12
pop %rsi
pop %rdx
pop %rdi
pop %rcx
pop %rbp
pop %r15
pop %r13
pop %r12
ret
.global s_faulty_load
s_faulty_load:
push %r13
push %rax
push %rbp
push %rbx
push %rdi
push %rsi
// Faulty Load
lea addresses_RW+0xb153, %rax
clflush (%rax)
xor %rbx, %rbx
mov (%rax), %esi
lea oracles, %rbx
and $0xff, %rsi
shlq $12, %rsi
mov (%rbx,%rsi,1), %rsi
pop %rsi
pop %rdi
pop %rbx
pop %rbp
pop %rax
pop %r13
ret
/*
<gen_faulty_load>
[REF]
{'src': {'NT': False, 'same': False, 'congruent': 0, 'type': 'addresses_RW', 'AVXalign': False, 'size': 16}, 'OP': 'LOAD'}
[Faulty Load]
{'src': {'NT': False, 'same': True, 'congruent': 0, 'type': 'addresses_RW', 'AVXalign': False, 'size': 4}, 'OP': 'LOAD'}
<gen_prepare_buffer>
{'src': {'same': False, 'congruent': 1, 'type': 'addresses_normal_ht'}, 'OP': 'REPM', 'dst': {'same': False, 'congruent': 7, 'type': 'addresses_normal_ht'}}
{'src': {'same': False, 'congruent': 11, 'type': 'addresses_normal_ht'}, 'OP': 'REPM', 'dst': {'same': False, 'congruent': 6, 'type': 'addresses_normal_ht'}}
{'src': {'same': False, 'congruent': 10, 'type': 'addresses_WC_ht'}, 'OP': 'REPM', 'dst': {'same': False, 'congruent': 9, 'type': 'addresses_normal_ht'}}
{'OP': 'STOR', 'dst': {'NT': True, 'same': False, 'congruent': 4, 'type': 'addresses_WC_ht', 'AVXalign': False, 'size': 32}}
{'src': {'NT': False, 'same': False, 'congruent': 2, 'type': 'addresses_A_ht', 'AVXalign': False, 'size': 1}, 'OP': 'LOAD'}
{'src': {'same': False, 'congruent': 11, 'type': 'addresses_WT_ht'}, 'OP': 'REPM', 'dst': {'same': False, 'congruent': 7, 'type': 'addresses_normal_ht'}}
{'src': {'NT': False, 'same': False, 'congruent': 3, 'type': 'addresses_normal_ht', 'AVXalign': False, 'size': 4}, 'OP': 'LOAD'}
{'OP': 'STOR', 'dst': {'NT': False, 'same': False, 'congruent': 2, 'type': 'addresses_WT_ht', 'AVXalign': False, 'size': 4}}
{'src': {'NT': True, 'same': True, 'congruent': 5, 'type': 'addresses_A_ht', 'AVXalign': False, 'size': 8}, 'OP': 'LOAD'}
{'OP': 'STOR', 'dst': {'NT': False, 'same': False, 'congruent': 4, 'type': 'addresses_WT_ht', 'AVXalign': False, 'size': 16}}
{'src': {'same': False, 'congruent': 2, 'type': 'addresses_normal_ht'}, 'OP': 'REPM', 'dst': {'same': False, 'congruent': 3, 'type': 'addresses_WC_ht'}}
{'src': {'NT': False, 'same': False, 'congruent': 8, 'type': 'addresses_WT_ht', 'AVXalign': False, 'size': 32}, 'OP': 'LOAD'}
{'src': {'NT': False, 'same': False, 'congruent': 1, 'type': 'addresses_WC_ht', 'AVXalign': True, 'size': 2}, 'OP': 'LOAD'}
{'src': {'same': False, 'congruent': 10, 'type': 'addresses_WT_ht'}, 'OP': 'REPM', 'dst': {'same': False, 'congruent': 4, 'type': 'addresses_normal_ht'}}
{'src': {'NT': True, 'same': False, 'congruent': 9, 'type': 'addresses_D_ht', 'AVXalign': False, 'size': 4}, 'OP': 'LOAD'}
{'32': 21829}
32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32 32
*/
|
; A213776: Antidiagonal sums of the convolution array A213774.
; 1,8,30,81,184,376,717,1304,2294,3941,6656,11104,18361,30168,49342,80441,130840,212472,344645,558600,904886,1465293,2372160,3839616,6214129,10056296,16273182,26332449,42608824,68944696,111557181,180505784,292067126,472577333,764649152,1237231456,2001885865,3239122872,5241014590,8480143625,13721164696,22201315128,35922486965,58123809576,94046304374,152170122141,246216435072,398386566144,644603010529,1042989586376,1687592607006,2730582203889,4418174821816,7148757037048,11566931870637
add $0,1
mov $2,1
lpb $0
sub $0,1
add $4,$2
mov $3,$4
add $3,5
mov $4,$2
add $5,$2
add $1,$5
mov $2,$3
add $4,3
lpe
mov $0,$1
|
db DEX_MACHOP ; pokedex id
db 70, 80, 50, 35, 35
; hp atk def spd spc
db FIGHTING, FIGHTING ; type
db 180 ; catch rate
db 88 ; base exp
INCBIN "gfx/pokemon/front/machop.pic", 0, 1 ; sprite dimensions
dw MachopPicFront, MachopPicBack
db KARATE_CHOP, NO_MOVE, NO_MOVE, NO_MOVE ; level 1 learnset
db GROWTH_MEDIUM_SLOW ; growth rate
; tm/hm learnset
tmhm MEGA_PUNCH, MEGA_KICK, TOXIC, BODY_SLAM, TAKE_DOWN, \
DOUBLE_EDGE, SUBMISSION, COUNTER, SEISMIC_TOSS, RAGE, \
EARTHQUAKE, FISSURE, DIG, MIMIC, DOUBLE_TEAM, \
BIDE, METRONOME, FIRE_BLAST, SKULL_BASH, REST, \
ROCK_SLIDE, SUBSTITUTE, STRENGTH
; end
db 0 ; padding
|
; Z88 Small C+ Run time Library
; Moved functions over to proper libdefs
; To make startup code smaller and neater!
;
; 6/9/98 djm
XLIB l_le
;
; DE <= HL [signed]
; set carry if true
.l_le
ld a,d
add a,$80
ld b,a
ld a,h
add a,$80
cp b
ccf
ret nz
ld a,l
cp e
ccf
ret
; call l_cmp
; ret c
; scf
; ret z
; ccf
; ret
|
.global s_prepare_buffers
s_prepare_buffers:
push %r10
push %r11
push %r12
push %r14
push %r8
push %r9
push %rdi
lea addresses_A_ht+0x1759a, %r9
nop
nop
nop
nop
nop
cmp %r12, %r12
mov $0x6162636465666768, %r8
movq %r8, (%r9)
nop
nop
nop
cmp $11047, %r11
lea addresses_WT_ht+0x14c74, %rdi
nop
dec %r10
movb $0x61, (%rdi)
nop
nop
nop
nop
xor $19428, %r8
lea addresses_D_ht+0x4a74, %r12
nop
nop
nop
nop
cmp $27674, %r9
mov $0x6162636465666768, %rdi
movq %rdi, (%r12)
nop
nop
nop
nop
nop
dec %rdi
pop %rdi
pop %r9
pop %r8
pop %r14
pop %r12
pop %r11
pop %r10
ret
.global s_faulty_load
s_faulty_load:
push %r10
push %r11
push %r13
push %r14
push %rax
push %rbx
push %rdx
// Store
lea addresses_UC+0xe1d4, %rbx
nop
nop
sub %rax, %rax
mov $0x5152535455565758, %r11
movq %r11, %xmm2
movups %xmm2, (%rbx)
nop
nop
nop
add $27380, %rax
// Store
lea addresses_UC+0xa674, %r13
nop
nop
inc %r10
mov $0x5152535455565758, %rbx
movq %rbx, (%r13)
nop
dec %rax
// Faulty Load
lea addresses_UC+0xa674, %rbx
nop
nop
nop
nop
nop
sub $50284, %r14
mov (%rbx), %ax
lea oracles, %rdx
and $0xff, %rax
shlq $12, %rax
mov (%rdx,%rax,1), %rax
pop %rdx
pop %rbx
pop %rax
pop %r14
pop %r13
pop %r11
pop %r10
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'type': 'addresses_UC', 'size': 16, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_UC', 'size': 16, 'AVXalign': False, 'NT': False, 'congruent': 5, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_UC', 'size': 8, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': True}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'type': 'addresses_UC', 'size': 2, 'AVXalign': False, 'NT': True, 'congruent': 0, 'same': True}}
<gen_prepare_buffer>
{'OP': 'STOR', 'dst': {'type': 'addresses_A_ht', 'size': 8, 'AVXalign': False, 'NT': False, 'congruent': 1, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_WT_ht', 'size': 1, 'AVXalign': False, 'NT': True, 'congruent': 9, 'same': True}}
{'OP': 'STOR', 'dst': {'type': 'addresses_D_ht', 'size': 8, 'AVXalign': True, 'NT': False, 'congruent': 10, 'same': False}}
{'58': 2542}
58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58
*/
|
#include "test_threads.h"
#include <future>
#include <functional>
#include <chrono>
using namespace std::chrono_literals;
int main(int argc, char** argv)
{
int rc = test_threads();
return rc;
}
|
/*
* Copyright (C) 2021 Alibaba Inc. All rights reserved.
* Author: Kraken Team.
*/
#include "bridge_qjs.h"
#include "gtest/gtest.h"
TEST(Context, isValid) {
auto bridge = new kraken::JSBridge(0, [](int32_t contextId, const char* errmsg) {});
EXPECT_EQ(bridge->getContext()->isValid(), true);
delete bridge;
}
TEST(Context, evalWithError) {
bool errorHandlerExecuted = false;
auto errorHandler = [&errorHandlerExecuted](int32_t contextId, const char* errmsg) {
errorHandlerExecuted = true;
EXPECT_STREQ(errmsg,
"TypeError: cannot read property 'toString' of null\n"
" at <eval> (file://:1)\n");
};
auto bridge = new kraken::JSBridge(0, errorHandler);
const char* code = "let object = null; object.toString();";
bridge->evaluateScript(code, strlen(code), "file://", 0);
EXPECT_EQ(errorHandlerExecuted, true);
delete bridge;
}
TEST(Context, unrejectPromiseError) {
bool errorHandlerExecuted = false;
auto errorHandler = [&errorHandlerExecuted](int32_t contextId, const char* errmsg) {
errorHandlerExecuted = true;
EXPECT_STREQ(errmsg,
"TypeError: cannot read property 'forceNullError' of null\n"
" at <anonymous> (file://:4)\n"
" at Promise (native)\n"
" at <eval> (file://:6)\n");
};
auto bridge = new kraken::JSBridge(0, errorHandler);
const char* code =
" var p = new Promise(function (resolve, reject) {\n"
" var nullObject = null;\n"
" // Raise a TypeError: Cannot read property 'forceNullError' of null\n"
" var x = nullObject.forceNullError();\n"
" resolve();\n"
" });\n"
"\n";
bridge->evaluateScript(code, strlen(code), "file://", 0);
EXPECT_EQ(errorHandlerExecuted, true);
delete bridge;
}
TEST(Context, window) {
bool errorHandlerExecuted = false;
static bool logCalled = false;
kraken::JSBridge::consoleMessageHandler = [](void* ctx, const std::string& message, int logLevel) {
logCalled = true;
EXPECT_STREQ(message.c_str(), "true");
};
auto errorHandler = [&errorHandlerExecuted](int32_t contextId, const char* errmsg) {
errorHandlerExecuted = true;
KRAKEN_LOG(VERBOSE) << errmsg;
};
auto bridge = new kraken::JSBridge(0, errorHandler);
const char* code = "console.log(window == globalThis)";
bridge->evaluateScript(code, strlen(code), "file://", 0);
EXPECT_EQ(errorHandlerExecuted, false);
EXPECT_EQ(logCalled, true);
delete bridge;
}
TEST(Context, windowInheritEventTarget) {
bool errorHandlerExecuted = false;
static bool logCalled = false;
kraken::JSBridge::consoleMessageHandler = [](void* ctx, const std::string& message, int logLevel) {
logCalled = true;
EXPECT_STREQ(message.c_str(), "ƒ () ƒ () ƒ () true");
};
auto errorHandler = [&errorHandlerExecuted](int32_t contextId, const char* errmsg) {
errorHandlerExecuted = true;
KRAKEN_LOG(VERBOSE) << errmsg;
};
auto bridge = new kraken::JSBridge(0, errorHandler);
const char* code = "console.log(window.addEventListener, addEventListener, globalThis.addEventListener, window.addEventListener === addEventListener)";
bridge->evaluateScript(code, strlen(code), "file://", 0);
EXPECT_EQ(errorHandlerExecuted, false);
EXPECT_EQ(logCalled, true);
delete bridge;
}
TEST(Context, evaluateByteCode) {
bool errorHandlerExecuted = false;
static bool logCalled = false;
kraken::JSBridge::consoleMessageHandler = [](void* ctx, const std::string& message, int logLevel) {
logCalled = true;
EXPECT_STREQ(message.c_str(), "Arguments {0: 1, 1: 2, 2: 3, 3: 4, callee: ƒ (), length: 4}");
};
auto errorHandler = [&errorHandlerExecuted](int32_t contextId, const char* errmsg) { errorHandlerExecuted = true; };
auto bridge = new kraken::JSBridge(0, errorHandler);
const char* code = "function f() { console.log(arguments)} f(1,2,3,4);";
size_t byteLen;
uint8_t* bytes = bridge->dumpByteCode(code, strlen(code), "vm://", &byteLen);
bridge->evaluateByteCode(bytes, byteLen);
EXPECT_EQ(errorHandlerExecuted, false);
EXPECT_EQ(logCalled, true);
delete bridge;
}
TEST(jsValueToNativeString, utf8String) {
auto bridge = new kraken::JSBridge(0, [](int32_t contextId, const char* errmsg) {});
JSValue str = JS_NewString(bridge->getContext()->ctx(), "helloworld");
NativeString* nativeString = kraken::binding::qjs::jsValueToNativeString(bridge->getContext()->ctx(), str);
EXPECT_EQ(nativeString->length, 10);
uint8_t expectedString[10] = {104, 101, 108, 108, 111, 119, 111, 114, 108, 100};
for (int i = 0; i < 10; i++) {
EXPECT_EQ(expectedString[i], *(nativeString->string + i));
}
JS_FreeValue(bridge->getContext()->ctx(), str);
delete bridge;
}
TEST(jsValueToNativeString, unicodeChinese) {
auto bridge = new kraken::JSBridge(0, [](int32_t contextId, const char* errmsg) {});
JSValue str = JS_NewString(bridge->getContext()->ctx(), "这是你的优乐美");
NativeString* nativeString = kraken::binding::qjs::jsValueToNativeString(bridge->getContext()->ctx(), str);
std::u16string expectedString = u"这是你的优乐美";
EXPECT_EQ(nativeString->length, expectedString.size());
for (int i = 0; i < nativeString->length; i++) {
EXPECT_EQ(expectedString[i], *(nativeString->string + i));
}
JS_FreeValue(bridge->getContext()->ctx(), str);
delete bridge;
}
TEST(jsValueToNativeString, emoji) {
auto bridge = new kraken::JSBridge(0, [](int32_t contextId, const char* errmsg) {});
JSValue str = JS_NewString(bridge->getContext()->ctx(), "……🤪");
NativeString* nativeString = kraken::binding::qjs::jsValueToNativeString(bridge->getContext()->ctx(), str);
std::u16string expectedString = u"……🤪";
EXPECT_EQ(nativeString->length, expectedString.length());
for (int i = 0; i < nativeString->length; i++) {
EXPECT_EQ(expectedString[i], *(nativeString->string + i));
}
JS_FreeValue(bridge->getContext()->ctx(), str);
delete bridge;
}
|
; A063204: Dimension of the space of weight 2n cuspidal newforms for Gamma_0( 25 ).
; 0,3,7,9,13,16,19,22,26,28,32,35,38,41,45,47,51,54,57,60,64,66,70,73,76,79,83,85,89,92,95,98,102,104,108,111,114,117,121,123,127,130,133,136,140,142,146,149,152,155
add $0,3
mul $0,19
seq $0,10764 ; a(n) = floor(n/2) mod floor(n/3).
sub $0,10
|
; ===============================================================
; Jan 2014
; ===============================================================
;
; int puts(const char *s)
;
; Write string to stdout followed by a '\n'.
; Return number of bytes written.
;
; ===============================================================
INCLUDE "config_private.inc"
SECTION code_clib
SECTION code_stdio
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
IF __CLIB_OPT_MULTITHREAD & $02
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
PUBLIC asm_puts
EXTERN _stdout
EXTERN asm0_puts_unlocked, __stdio_lock_release
asm_puts:
; enter : hl = char *s
;
; exit : ix = FILE *stdout
;
; success
;
; hl = strlen(s) + 1
; carry reset
;
; fail
;
; hl = -1
; carry set, errno set
;
; uses : all
ld ix,(_stdout)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
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_puts_unlocked
jp __stdio_lock_release
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ELSE
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
PUBLIC asm_puts
EXTERN asm_puts_unlocked
defc asm_puts = asm_puts_unlocked
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ENDIF
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
/*
* Copyright 2016 Advanced Micro Devices, Inc.
*
* 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 COPYRIGHT HOLDER(S) OR AUTHOR(S) 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.
*/
/* To compile this assembly code:
*
* gfx9:
* cpp -DASIC_FAMILY=CHIP_VEGAM cwsr_trap_handler_gfx9.asm -P -o gfx9.sp3
* sp3 gfx9.sp3 -hex gfx9.hex
*
* arcturus:
* cpp -DASIC_FAMILY=CHIP_ARCTURUS cwsr_trap_handler_gfx9.asm -P -o arcturus.sp3
* sp3 arcturus.sp3 -hex arcturus.hex
*
* aldebaran:
* cpp -DASIC_FAMILY=CHIP_ALDEBARAN cwsr_trap_handler_gfx9.asm -P -o aldebaran.sp3
* sp3 aldebaran.sp3 -hex aldebaran.hex
*/
#define CHIP_VEGAM 18
#define CHIP_ARCTURUS 23
#define CHIP_ALDEBARAN 25
var ACK_SQC_STORE = 1 //workaround for suspected SQC store bug causing incorrect stores under concurrency
var SAVE_AFTER_XNACK_ERROR = 1 //workaround for TCP store failure after XNACK error when ALLOW_REPLAY=0, for debugger
var SINGLE_STEP_MISSED_WORKAROUND = 1 //workaround for lost MODE.DEBUG_EN exception when SAVECTX raised
/**************************************************************************/
/* variables */
/**************************************************************************/
var SQ_WAVE_STATUS_INST_ATC_SHIFT = 23
var SQ_WAVE_STATUS_INST_ATC_MASK = 0x00800000
var SQ_WAVE_STATUS_SPI_PRIO_SHIFT = 1
var SQ_WAVE_STATUS_SPI_PRIO_MASK = 0x00000006
var SQ_WAVE_STATUS_HALT_MASK = 0x2000
var SQ_WAVE_STATUS_PRE_SPI_PRIO_SHIFT = 0
var SQ_WAVE_STATUS_PRE_SPI_PRIO_SIZE = 1
var SQ_WAVE_STATUS_POST_SPI_PRIO_SHIFT = 3
var SQ_WAVE_STATUS_POST_SPI_PRIO_SIZE = 29
var SQ_WAVE_STATUS_ALLOW_REPLAY_MASK = 0x400000
var SQ_WAVE_LDS_ALLOC_LDS_SIZE_SHIFT = 12
var SQ_WAVE_LDS_ALLOC_LDS_SIZE_SIZE = 9
var SQ_WAVE_GPR_ALLOC_VGPR_SIZE_SIZE = 6
var SQ_WAVE_GPR_ALLOC_SGPR_SIZE_SIZE = 3 //FIXME sq.blk still has 4 bits at this time while SQ programming guide has 3 bits
var SQ_WAVE_GPR_ALLOC_SGPR_SIZE_SHIFT = 24
#if ASIC_FAMILY >= CHIP_ALDEBARAN
var SQ_WAVE_GPR_ALLOC_VGPR_SIZE_SHIFT = 6
var SQ_WAVE_GPR_ALLOC_ACCV_OFFSET_SHIFT = 12
var SQ_WAVE_GPR_ALLOC_ACCV_OFFSET_SIZE = 6
#else
var SQ_WAVE_GPR_ALLOC_VGPR_SIZE_SHIFT = 8
#endif
var SQ_WAVE_TRAPSTS_SAVECTX_MASK = 0x400
var SQ_WAVE_TRAPSTS_EXCE_MASK = 0x1FF // Exception mask
var SQ_WAVE_TRAPSTS_SAVECTX_SHIFT = 10
var SQ_WAVE_TRAPSTS_MEM_VIOL_MASK = 0x100
var SQ_WAVE_TRAPSTS_MEM_VIOL_SHIFT = 8
var SQ_WAVE_TRAPSTS_PRE_SAVECTX_MASK = 0x3FF
var SQ_WAVE_TRAPSTS_PRE_SAVECTX_SHIFT = 0x0
var SQ_WAVE_TRAPSTS_PRE_SAVECTX_SIZE = 10
var SQ_WAVE_TRAPSTS_POST_SAVECTX_MASK = 0xFFFFF800
var SQ_WAVE_TRAPSTS_POST_SAVECTX_SHIFT = 11
var SQ_WAVE_TRAPSTS_POST_SAVECTX_SIZE = 21
var SQ_WAVE_TRAPSTS_ILLEGAL_INST_MASK = 0x800
var SQ_WAVE_TRAPSTS_XNACK_ERROR_MASK = 0x10000000
var SQ_WAVE_IB_STS_RCNT_SHIFT = 16 //FIXME
var SQ_WAVE_IB_STS_FIRST_REPLAY_SHIFT = 15 //FIXME
var SQ_WAVE_IB_STS_RCNT_FIRST_REPLAY_MASK = 0x1F8000
var SQ_WAVE_IB_STS_RCNT_FIRST_REPLAY_MASK_NEG = 0x00007FFF //FIXME
var SQ_WAVE_MODE_DEBUG_EN_MASK = 0x800
var SQ_BUF_RSRC_WORD1_ATC_SHIFT = 24
var SQ_BUF_RSRC_WORD3_MTYPE_SHIFT = 27
var TTMP11_SAVE_RCNT_FIRST_REPLAY_SHIFT = 26 // bits [31:26] unused by SPI debug data
var TTMP11_SAVE_RCNT_FIRST_REPLAY_MASK = 0xFC000000
/* Save */
var S_SAVE_BUF_RSRC_WORD1_STRIDE = 0x00040000 //stride is 4 bytes
var S_SAVE_BUF_RSRC_WORD3_MISC = 0x00807FAC //SQ_SEL_X/Y/Z/W, BUF_NUM_FORMAT_FLOAT, (0 for MUBUF stride[17:14] when ADD_TID_ENABLE and BUF_DATA_FORMAT_32 for MTBUF), ADD_TID_ENABLE
var S_SAVE_SPI_INIT_ATC_MASK = 0x08000000 //bit[27]: ATC bit
var S_SAVE_SPI_INIT_ATC_SHIFT = 27
var S_SAVE_SPI_INIT_MTYPE_MASK = 0x70000000 //bit[30:28]: Mtype
var S_SAVE_SPI_INIT_MTYPE_SHIFT = 28
var S_SAVE_SPI_INIT_FIRST_WAVE_MASK = 0x04000000 //bit[26]: FirstWaveInTG
var S_SAVE_SPI_INIT_FIRST_WAVE_SHIFT = 26
var S_SAVE_PC_HI_RCNT_SHIFT = 27 //FIXME check with Brian to ensure all fields other than PC[47:0] can be used
var S_SAVE_PC_HI_RCNT_MASK = 0xF8000000 //FIXME
var S_SAVE_PC_HI_FIRST_REPLAY_SHIFT = 26 //FIXME
var S_SAVE_PC_HI_FIRST_REPLAY_MASK = 0x04000000 //FIXME
var s_save_spi_init_lo = exec_lo
var s_save_spi_init_hi = exec_hi
var s_save_pc_lo = ttmp0 //{TTMP1, TTMP0} = {3'h0,pc_rewind[3:0], HT[0],trapID[7:0], PC[47:0]}
var s_save_pc_hi = ttmp1
var s_save_exec_lo = ttmp2
var s_save_exec_hi = ttmp3
var s_save_tmp = ttmp14
var s_save_trapsts = ttmp15 //not really used until the end of the SAVE routine
var s_save_xnack_mask_lo = ttmp6
var s_save_xnack_mask_hi = ttmp7
var s_save_buf_rsrc0 = ttmp8
var s_save_buf_rsrc1 = ttmp9
var s_save_buf_rsrc2 = ttmp10
var s_save_buf_rsrc3 = ttmp11
var s_save_status = ttmp12
var s_save_mem_offset = ttmp4
var s_save_alloc_size = s_save_trapsts //conflict
var s_save_m0 = ttmp5
var s_save_ttmps_lo = s_save_tmp //no conflict
var s_save_ttmps_hi = s_save_trapsts //no conflict
/* Restore */
var S_RESTORE_BUF_RSRC_WORD1_STRIDE = S_SAVE_BUF_RSRC_WORD1_STRIDE
var S_RESTORE_BUF_RSRC_WORD3_MISC = S_SAVE_BUF_RSRC_WORD3_MISC
var S_RESTORE_SPI_INIT_ATC_MASK = 0x08000000 //bit[27]: ATC bit
var S_RESTORE_SPI_INIT_ATC_SHIFT = 27
var S_RESTORE_SPI_INIT_MTYPE_MASK = 0x70000000 //bit[30:28]: Mtype
var S_RESTORE_SPI_INIT_MTYPE_SHIFT = 28
var S_RESTORE_SPI_INIT_FIRST_WAVE_MASK = 0x04000000 //bit[26]: FirstWaveInTG
var S_RESTORE_SPI_INIT_FIRST_WAVE_SHIFT = 26
var S_RESTORE_PC_HI_RCNT_SHIFT = S_SAVE_PC_HI_RCNT_SHIFT
var S_RESTORE_PC_HI_RCNT_MASK = S_SAVE_PC_HI_RCNT_MASK
var S_RESTORE_PC_HI_FIRST_REPLAY_SHIFT = S_SAVE_PC_HI_FIRST_REPLAY_SHIFT
var S_RESTORE_PC_HI_FIRST_REPLAY_MASK = S_SAVE_PC_HI_FIRST_REPLAY_MASK
var s_restore_spi_init_lo = exec_lo
var s_restore_spi_init_hi = exec_hi
var s_restore_mem_offset = ttmp12
var s_restore_tmp2 = ttmp13
var s_restore_alloc_size = ttmp3
var s_restore_tmp = ttmp2
var s_restore_mem_offset_save = s_restore_tmp //no conflict
var s_restore_accvgpr_offset_save = ttmp7
var s_restore_m0 = s_restore_alloc_size //no conflict
var s_restore_mode = s_restore_accvgpr_offset_save
var s_restore_pc_lo = ttmp0
var s_restore_pc_hi = ttmp1
var s_restore_exec_lo = ttmp4
var s_restore_exec_hi = ttmp5
var s_restore_status = ttmp14
var s_restore_trapsts = ttmp15
var s_restore_xnack_mask_lo = xnack_mask_lo
var s_restore_xnack_mask_hi = xnack_mask_hi
var s_restore_buf_rsrc0 = ttmp8
var s_restore_buf_rsrc1 = ttmp9
var s_restore_buf_rsrc2 = ttmp10
var s_restore_buf_rsrc3 = ttmp11
var s_restore_ttmps_lo = s_restore_tmp //no conflict
var s_restore_ttmps_hi = s_restore_alloc_size //no conflict
/**************************************************************************/
/* trap handler entry points */
/**************************************************************************/
/* Shader Main*/
shader main
asic(DEFAULT)
type(CS)
s_branch L_SKIP_RESTORE //NOT restore. might be a regular trap or save
L_JUMP_TO_RESTORE:
s_branch L_RESTORE //restore
L_SKIP_RESTORE:
s_getreg_b32 s_save_status, hwreg(HW_REG_STATUS) //save STATUS since we will change SCC
s_andn2_b32 s_save_status, s_save_status, SQ_WAVE_STATUS_SPI_PRIO_MASK //check whether this is for save
if SINGLE_STEP_MISSED_WORKAROUND
// No single step exceptions if MODE.DEBUG_EN=0.
s_getreg_b32 ttmp2, hwreg(HW_REG_MODE)
s_and_b32 ttmp2, ttmp2, SQ_WAVE_MODE_DEBUG_EN_MASK
s_cbranch_scc0 L_NO_SINGLE_STEP_WORKAROUND
// Second-level trap already handled exception if STATUS.HALT=1.
s_and_b32 ttmp2, s_save_status, SQ_WAVE_STATUS_HALT_MASK
// Prioritize single step exception over context save.
// Second-level trap will halt wave and RFE, re-entering for SAVECTX.
s_cbranch_scc0 L_FETCH_2ND_TRAP
L_NO_SINGLE_STEP_WORKAROUND:
end
s_getreg_b32 s_save_trapsts, hwreg(HW_REG_TRAPSTS)
s_and_b32 ttmp2, s_save_trapsts, SQ_WAVE_TRAPSTS_SAVECTX_MASK //check whether this is for save
s_cbranch_scc1 L_SAVE //this is the operation for save
// ********* Handle non-CWSR traps *******************
// Illegal instruction is a non-maskable exception which blocks context save.
// Halt the wavefront and return from the trap.
s_and_b32 ttmp2, s_save_trapsts, SQ_WAVE_TRAPSTS_ILLEGAL_INST_MASK
s_cbranch_scc1 L_HALT_WAVE
// If STATUS.MEM_VIOL is asserted then we cannot fetch from the TMA.
// Instead, halt the wavefront and return from the trap.
s_and_b32 ttmp2, s_save_trapsts, SQ_WAVE_TRAPSTS_MEM_VIOL_MASK
s_cbranch_scc0 L_FETCH_2ND_TRAP
L_HALT_WAVE:
// If STATUS.HALT is set then this fault must come from SQC instruction fetch.
// We cannot prevent further faults. Spin wait until context saved.
s_and_b32 ttmp2, s_save_status, SQ_WAVE_STATUS_HALT_MASK
s_cbranch_scc0 L_NOT_ALREADY_HALTED
L_WAIT_CTX_SAVE:
s_sleep 0x10
s_getreg_b32 ttmp2, hwreg(HW_REG_TRAPSTS)
s_and_b32 ttmp2, ttmp2, SQ_WAVE_TRAPSTS_SAVECTX_MASK
s_cbranch_scc0 L_WAIT_CTX_SAVE
L_NOT_ALREADY_HALTED:
s_or_b32 s_save_status, s_save_status, SQ_WAVE_STATUS_HALT_MASK
// If the PC points to S_ENDPGM then context save will fail if STATUS.HALT is set.
// Rewind the PC to prevent this from occurring. The debugger compensates for this.
s_sub_u32 ttmp0, ttmp0, 0x8
s_subb_u32 ttmp1, ttmp1, 0x0
L_FETCH_2ND_TRAP:
// Preserve and clear scalar XNACK state before issuing scalar reads.
// Save IB_STS.FIRST_REPLAY[15] and IB_STS.RCNT[20:16] into unused space ttmp11[31:26].
s_getreg_b32 ttmp2, hwreg(HW_REG_IB_STS)
s_and_b32 ttmp3, ttmp2, SQ_WAVE_IB_STS_RCNT_FIRST_REPLAY_MASK
s_lshl_b32 ttmp3, ttmp3, (TTMP11_SAVE_RCNT_FIRST_REPLAY_SHIFT - SQ_WAVE_IB_STS_FIRST_REPLAY_SHIFT)
s_andn2_b32 ttmp11, ttmp11, TTMP11_SAVE_RCNT_FIRST_REPLAY_MASK
s_or_b32 ttmp11, ttmp11, ttmp3
s_andn2_b32 ttmp2, ttmp2, SQ_WAVE_IB_STS_RCNT_FIRST_REPLAY_MASK
s_setreg_b32 hwreg(HW_REG_IB_STS), ttmp2
// Read second-level TBA/TMA from first-level TMA and jump if available.
// ttmp[2:5] and ttmp12 can be used (others hold SPI-initialized debug data)
// ttmp12 holds SQ_WAVE_STATUS
s_getreg_b32 ttmp14, hwreg(HW_REG_SQ_SHADER_TMA_LO)
s_getreg_b32 ttmp15, hwreg(HW_REG_SQ_SHADER_TMA_HI)
s_lshl_b64 [ttmp14, ttmp15], [ttmp14, ttmp15], 0x8
s_load_dwordx2 [ttmp2, ttmp3], [ttmp14, ttmp15], 0x0 glc:1 // second-level TBA
s_waitcnt lgkmcnt(0)
s_load_dwordx2 [ttmp14, ttmp15], [ttmp14, ttmp15], 0x8 glc:1 // second-level TMA
s_waitcnt lgkmcnt(0)
s_and_b64 [ttmp2, ttmp3], [ttmp2, ttmp3], [ttmp2, ttmp3]
s_cbranch_scc0 L_NO_NEXT_TRAP // second-level trap handler not been set
s_setpc_b64 [ttmp2, ttmp3] // jump to second-level trap handler
L_NO_NEXT_TRAP:
s_getreg_b32 s_save_trapsts, hwreg(HW_REG_TRAPSTS)
s_and_b32 s_save_trapsts, s_save_trapsts, SQ_WAVE_TRAPSTS_EXCE_MASK // Check whether it is an exception
s_cbranch_scc1 L_EXCP_CASE // Exception, jump back to the shader program directly.
s_add_u32 ttmp0, ttmp0, 4 // S_TRAP case, add 4 to ttmp0
s_addc_u32 ttmp1, ttmp1, 0
L_EXCP_CASE:
s_and_b32 ttmp1, ttmp1, 0xFFFF
// Restore SQ_WAVE_IB_STS.
s_lshr_b32 ttmp2, ttmp11, (TTMP11_SAVE_RCNT_FIRST_REPLAY_SHIFT - SQ_WAVE_IB_STS_FIRST_REPLAY_SHIFT)
s_and_b32 ttmp2, ttmp2, SQ_WAVE_IB_STS_RCNT_FIRST_REPLAY_MASK
s_setreg_b32 hwreg(HW_REG_IB_STS), ttmp2
// Restore SQ_WAVE_STATUS.
s_and_b64 exec, exec, exec // Restore STATUS.EXECZ, not writable by s_setreg_b32
s_and_b64 vcc, vcc, vcc // Restore STATUS.VCCZ, not writable by s_setreg_b32
set_status_without_spi_prio(s_save_status, ttmp2)
s_rfe_b64 [ttmp0, ttmp1]
// ********* End handling of non-CWSR traps *******************
/**************************************************************************/
/* save routine */
/**************************************************************************/
L_SAVE:
s_and_b32 s_save_pc_hi, s_save_pc_hi, 0x0000ffff //pc[47:32]
s_mov_b32 s_save_tmp, 0 //clear saveCtx bit
s_setreg_b32 hwreg(HW_REG_TRAPSTS, SQ_WAVE_TRAPSTS_SAVECTX_SHIFT, 1), s_save_tmp //clear saveCtx bit
s_getreg_b32 s_save_tmp, hwreg(HW_REG_IB_STS, SQ_WAVE_IB_STS_RCNT_SHIFT, SQ_WAVE_IB_STS_RCNT_SIZE) //save RCNT
s_lshl_b32 s_save_tmp, s_save_tmp, S_SAVE_PC_HI_RCNT_SHIFT
s_or_b32 s_save_pc_hi, s_save_pc_hi, s_save_tmp
s_getreg_b32 s_save_tmp, hwreg(HW_REG_IB_STS, SQ_WAVE_IB_STS_FIRST_REPLAY_SHIFT, SQ_WAVE_IB_STS_FIRST_REPLAY_SIZE) //save FIRST_REPLAY
s_lshl_b32 s_save_tmp, s_save_tmp, S_SAVE_PC_HI_FIRST_REPLAY_SHIFT
s_or_b32 s_save_pc_hi, s_save_pc_hi, s_save_tmp
s_getreg_b32 s_save_tmp, hwreg(HW_REG_IB_STS) //clear RCNT and FIRST_REPLAY in IB_STS
s_and_b32 s_save_tmp, s_save_tmp, SQ_WAVE_IB_STS_RCNT_FIRST_REPLAY_MASK_NEG
s_setreg_b32 hwreg(HW_REG_IB_STS), s_save_tmp
/* inform SPI the readiness and wait for SPI's go signal */
s_mov_b32 s_save_exec_lo, exec_lo //save EXEC and use EXEC for the go signal from SPI
s_mov_b32 s_save_exec_hi, exec_hi
s_mov_b64 exec, 0x0 //clear EXEC to get ready to receive
s_sendmsg sendmsg(MSG_SAVEWAVE) //send SPI a message and wait for SPI's write to EXEC
// Set SPI_PRIO=2 to avoid starving instruction fetch in the waves we're waiting for.
s_or_b32 s_save_tmp, s_save_status, (2 << SQ_WAVE_STATUS_SPI_PRIO_SHIFT)
s_setreg_b32 hwreg(HW_REG_STATUS), s_save_tmp
L_SLEEP:
s_sleep 0x2 // sleep 1 (64clk) is not enough for 8 waves per SIMD, which will cause SQ hang, since the 7,8th wave could not get arbit to exec inst, while other waves are stuck into the sleep-loop and waiting for wrexec!=0
s_cbranch_execz L_SLEEP
// Save trap temporaries 4-11, 13 initialized by SPI debug dispatch logic
// ttmp SR memory offset : size(VGPR)+size(SGPR)+0x40
get_vgpr_size_bytes(s_save_ttmps_lo)
get_sgpr_size_bytes(s_save_ttmps_hi)
s_add_u32 s_save_ttmps_lo, s_save_ttmps_lo, s_save_ttmps_hi
s_add_u32 s_save_ttmps_lo, s_save_ttmps_lo, s_save_spi_init_lo
s_addc_u32 s_save_ttmps_hi, s_save_spi_init_hi, 0x0
s_and_b32 s_save_ttmps_hi, s_save_ttmps_hi, 0xFFFF
s_store_dwordx4 [ttmp4, ttmp5, ttmp6, ttmp7], [s_save_ttmps_lo, s_save_ttmps_hi], 0x50 glc:1
ack_sqc_store_workaround()
s_store_dwordx4 [ttmp8, ttmp9, ttmp10, ttmp11], [s_save_ttmps_lo, s_save_ttmps_hi], 0x60 glc:1
ack_sqc_store_workaround()
s_store_dword ttmp13, [s_save_ttmps_lo, s_save_ttmps_hi], 0x74 glc:1
ack_sqc_store_workaround()
/* setup Resource Contants */
s_mov_b32 s_save_buf_rsrc0, s_save_spi_init_lo //base_addr_lo
s_and_b32 s_save_buf_rsrc1, s_save_spi_init_hi, 0x0000FFFF //base_addr_hi
s_or_b32 s_save_buf_rsrc1, s_save_buf_rsrc1, S_SAVE_BUF_RSRC_WORD1_STRIDE
s_mov_b32 s_save_buf_rsrc2, 0 //NUM_RECORDS initial value = 0 (in bytes) although not neccessarily inited
s_mov_b32 s_save_buf_rsrc3, S_SAVE_BUF_RSRC_WORD3_MISC
s_and_b32 s_save_tmp, s_save_spi_init_hi, S_SAVE_SPI_INIT_ATC_MASK
s_lshr_b32 s_save_tmp, s_save_tmp, (S_SAVE_SPI_INIT_ATC_SHIFT-SQ_BUF_RSRC_WORD1_ATC_SHIFT) //get ATC bit into position
s_or_b32 s_save_buf_rsrc3, s_save_buf_rsrc3, s_save_tmp //or ATC
s_and_b32 s_save_tmp, s_save_spi_init_hi, S_SAVE_SPI_INIT_MTYPE_MASK
s_lshr_b32 s_save_tmp, s_save_tmp, (S_SAVE_SPI_INIT_MTYPE_SHIFT-SQ_BUF_RSRC_WORD3_MTYPE_SHIFT) //get MTYPE bits into position
s_or_b32 s_save_buf_rsrc3, s_save_buf_rsrc3, s_save_tmp //or MTYPE
//FIXME right now s_save_m0/s_save_mem_offset use tma_lo/tma_hi (might need to save them before using them?)
s_mov_b32 s_save_m0, m0 //save M0
/* global mem offset */
s_mov_b32 s_save_mem_offset, 0x0 //mem offset initial value = 0
/* save HW registers */
//////////////////////////////
L_SAVE_HWREG:
// HWREG SR memory offset : size(VGPR)+size(SGPR)
get_vgpr_size_bytes(s_save_mem_offset)
get_sgpr_size_bytes(s_save_tmp)
s_add_u32 s_save_mem_offset, s_save_mem_offset, s_save_tmp
s_mov_b32 s_save_buf_rsrc2, 0x4 //NUM_RECORDS in bytes
s_mov_b32 s_save_buf_rsrc2, 0x1000000 //NUM_RECORDS in bytes
write_hwreg_to_mem(s_save_m0, s_save_buf_rsrc0, s_save_mem_offset) //M0
write_hwreg_to_mem(s_save_pc_lo, s_save_buf_rsrc0, s_save_mem_offset) //PC
write_hwreg_to_mem(s_save_pc_hi, s_save_buf_rsrc0, s_save_mem_offset)
write_hwreg_to_mem(s_save_exec_lo, s_save_buf_rsrc0, s_save_mem_offset) //EXEC
write_hwreg_to_mem(s_save_exec_hi, s_save_buf_rsrc0, s_save_mem_offset)
write_hwreg_to_mem(s_save_status, s_save_buf_rsrc0, s_save_mem_offset) //STATUS
//s_save_trapsts conflicts with s_save_alloc_size
s_getreg_b32 s_save_trapsts, hwreg(HW_REG_TRAPSTS)
write_hwreg_to_mem(s_save_trapsts, s_save_buf_rsrc0, s_save_mem_offset) //TRAPSTS
write_hwreg_to_mem(xnack_mask_lo, s_save_buf_rsrc0, s_save_mem_offset) //XNACK_MASK_LO
write_hwreg_to_mem(xnack_mask_hi, s_save_buf_rsrc0, s_save_mem_offset) //XNACK_MASK_HI
//use s_save_tmp would introduce conflict here between s_save_tmp and s_save_buf_rsrc2
s_getreg_b32 s_save_m0, hwreg(HW_REG_MODE) //MODE
write_hwreg_to_mem(s_save_m0, s_save_buf_rsrc0, s_save_mem_offset)
/* the first wave in the threadgroup */
s_and_b32 s_save_tmp, s_save_spi_init_hi, S_SAVE_SPI_INIT_FIRST_WAVE_MASK // extract fisrt wave bit
s_mov_b32 s_save_exec_hi, 0x0
s_or_b32 s_save_exec_hi, s_save_tmp, s_save_exec_hi // save first wave bit to s_save_exec_hi.bits[26]
/* save SGPRs */
// Save SGPR before LDS save, then the s0 to s4 can be used during LDS save...
//////////////////////////////
// SGPR SR memory offset : size(VGPR)
get_vgpr_size_bytes(s_save_mem_offset)
// TODO, change RSRC word to rearrange memory layout for SGPRS
s_getreg_b32 s_save_alloc_size, hwreg(HW_REG_GPR_ALLOC,SQ_WAVE_GPR_ALLOC_SGPR_SIZE_SHIFT,SQ_WAVE_GPR_ALLOC_SGPR_SIZE_SIZE) //spgr_size
s_add_u32 s_save_alloc_size, s_save_alloc_size, 1
s_lshl_b32 s_save_alloc_size, s_save_alloc_size, 4 //Number of SGPRs = (sgpr_size + 1) * 16 (non-zero value)
s_lshl_b32 s_save_buf_rsrc2, s_save_alloc_size, 2 //NUM_RECORDS in bytes
s_mov_b32 s_save_buf_rsrc2, 0x1000000 //NUM_RECORDS in bytes
// backup s_save_buf_rsrc0,1 to s_save_pc_lo/hi, since write_16sgpr_to_mem function will change the rsrc0
//s_mov_b64 s_save_pc_lo, s_save_buf_rsrc0
s_mov_b64 s_save_xnack_mask_lo, s_save_buf_rsrc0
s_add_u32 s_save_buf_rsrc0, s_save_buf_rsrc0, s_save_mem_offset
s_addc_u32 s_save_buf_rsrc1, s_save_buf_rsrc1, 0
s_mov_b32 m0, 0x0 //SGPR initial index value =0
s_nop 0x0 //Manually inserted wait states
L_SAVE_SGPR_LOOP:
// SGPR is allocated in 16 SGPR granularity
s_movrels_b64 s0, s0 //s0 = s[0+m0], s1 = s[1+m0]
s_movrels_b64 s2, s2 //s2 = s[2+m0], s3 = s[3+m0]
s_movrels_b64 s4, s4 //s4 = s[4+m0], s5 = s[5+m0]
s_movrels_b64 s6, s6 //s6 = s[6+m0], s7 = s[7+m0]
s_movrels_b64 s8, s8 //s8 = s[8+m0], s9 = s[9+m0]
s_movrels_b64 s10, s10 //s10 = s[10+m0], s11 = s[11+m0]
s_movrels_b64 s12, s12 //s12 = s[12+m0], s13 = s[13+m0]
s_movrels_b64 s14, s14 //s14 = s[14+m0], s15 = s[15+m0]
write_16sgpr_to_mem(s0, s_save_buf_rsrc0, s_save_mem_offset) //PV: the best performance should be using s_buffer_store_dwordx4
s_add_u32 m0, m0, 16 //next sgpr index
s_cmp_lt_u32 m0, s_save_alloc_size //scc = (m0 < s_save_alloc_size) ? 1 : 0
s_cbranch_scc1 L_SAVE_SGPR_LOOP //SGPR save is complete?
// restore s_save_buf_rsrc0,1
//s_mov_b64 s_save_buf_rsrc0, s_save_pc_lo
s_mov_b64 s_save_buf_rsrc0, s_save_xnack_mask_lo
/* save first 4 VGPR, then LDS save could use */
// each wave will alloc 4 vgprs at least...
/////////////////////////////////////////////////////////////////////////////////////
s_mov_b32 s_save_mem_offset, 0
s_mov_b32 exec_lo, 0xFFFFFFFF //need every thread from now on
s_mov_b32 exec_hi, 0xFFFFFFFF
s_mov_b32 xnack_mask_lo, 0x0
s_mov_b32 xnack_mask_hi, 0x0
s_mov_b32 s_save_buf_rsrc2, 0x1000000 //NUM_RECORDS in bytes
// VGPR Allocated in 4-GPR granularity
if SAVE_AFTER_XNACK_ERROR
check_if_tcp_store_ok()
s_cbranch_scc1 L_SAVE_FIRST_VGPRS_WITH_TCP
write_vgprs_to_mem_with_sqc(v0, 4, s_save_buf_rsrc0, s_save_mem_offset)
s_branch L_SAVE_LDS
L_SAVE_FIRST_VGPRS_WITH_TCP:
end
write_4vgprs_to_mem(s_save_buf_rsrc0, s_save_mem_offset)
/* save LDS */
//////////////////////////////
L_SAVE_LDS:
// Change EXEC to all threads...
s_mov_b32 exec_lo, 0xFFFFFFFF //need every thread from now on
s_mov_b32 exec_hi, 0xFFFFFFFF
s_getreg_b32 s_save_alloc_size, hwreg(HW_REG_LDS_ALLOC,SQ_WAVE_LDS_ALLOC_LDS_SIZE_SHIFT,SQ_WAVE_LDS_ALLOC_LDS_SIZE_SIZE) //lds_size
s_and_b32 s_save_alloc_size, s_save_alloc_size, 0xFFFFFFFF //lds_size is zero?
s_cbranch_scc0 L_SAVE_LDS_DONE //no lds used? jump to L_SAVE_DONE
s_barrier //LDS is used? wait for other waves in the same TG
s_and_b32 s_save_tmp, s_save_exec_hi, S_SAVE_SPI_INIT_FIRST_WAVE_MASK //exec is still used here
s_cbranch_scc0 L_SAVE_LDS_DONE
// first wave do LDS save;
s_lshl_b32 s_save_alloc_size, s_save_alloc_size, 6 //LDS size in dwords = lds_size * 64dw
s_lshl_b32 s_save_alloc_size, s_save_alloc_size, 2 //LDS size in bytes
s_mov_b32 s_save_buf_rsrc2, s_save_alloc_size //NUM_RECORDS in bytes
// LDS at offset: size(VGPR)+SIZE(SGPR)+SIZE(HWREG)
//
get_vgpr_size_bytes(s_save_mem_offset)
get_sgpr_size_bytes(s_save_tmp)
s_add_u32 s_save_mem_offset, s_save_mem_offset, s_save_tmp
s_add_u32 s_save_mem_offset, s_save_mem_offset, get_hwreg_size_bytes()
s_mov_b32 s_save_buf_rsrc2, 0x1000000 //NUM_RECORDS in bytes
s_mov_b32 m0, 0x0 //lds_offset initial value = 0
v_mbcnt_lo_u32_b32 v2, 0xffffffff, 0x0
v_mbcnt_hi_u32_b32 v3, 0xffffffff, v2 // tid
if SAVE_AFTER_XNACK_ERROR
check_if_tcp_store_ok()
s_cbranch_scc1 L_SAVE_LDS_WITH_TCP
v_lshlrev_b32 v2, 2, v3
L_SAVE_LDS_LOOP_SQC:
ds_read2_b32 v[0:1], v2 offset0:0 offset1:0x40
s_waitcnt lgkmcnt(0)
write_vgprs_to_mem_with_sqc(v0, 2, s_save_buf_rsrc0, s_save_mem_offset)
v_add_u32 v2, 0x200, v2
v_cmp_lt_u32 vcc[0:1], v2, s_save_alloc_size
s_cbranch_vccnz L_SAVE_LDS_LOOP_SQC
s_branch L_SAVE_LDS_DONE
L_SAVE_LDS_WITH_TCP:
end
v_mul_i32_i24 v2, v3, 8 // tid*8
v_mov_b32 v3, 256*2
s_mov_b32 m0, 0x10000
s_mov_b32 s0, s_save_buf_rsrc3
s_and_b32 s_save_buf_rsrc3, s_save_buf_rsrc3, 0xFF7FFFFF // disable add_tid
s_or_b32 s_save_buf_rsrc3, s_save_buf_rsrc3, 0x58000 //DFMT
L_SAVE_LDS_LOOP_VECTOR:
ds_read_b64 v[0:1], v2 //x =LDS[a], byte address
s_waitcnt lgkmcnt(0)
buffer_store_dwordx2 v[0:1], v2, s_save_buf_rsrc0, s_save_mem_offset offen:1 glc:1 slc:1
// s_waitcnt vmcnt(0)
// v_add_u32 v2, vcc[0:1], v2, v3
v_add_u32 v2, v2, v3
v_cmp_lt_u32 vcc[0:1], v2, s_save_alloc_size
s_cbranch_vccnz L_SAVE_LDS_LOOP_VECTOR
// restore rsrc3
s_mov_b32 s_save_buf_rsrc3, s0
L_SAVE_LDS_DONE:
/* save VGPRs - set the Rest VGPRs */
//////////////////////////////////////////////////////////////////////////////////////
L_SAVE_VGPR:
// VGPR SR memory offset: 0
// TODO rearrange the RSRC words to use swizzle for VGPR save...
s_mov_b32 s_save_mem_offset, (0+256*4) // for the rest VGPRs
s_mov_b32 exec_lo, 0xFFFFFFFF //need every thread from now on
s_mov_b32 exec_hi, 0xFFFFFFFF
get_num_arch_vgprs(s_save_alloc_size)
s_mov_b32 s_save_buf_rsrc2, 0x1000000 //NUM_RECORDS in bytes
// VGPR store using dw burst
s_mov_b32 m0, 0x4 //VGPR initial index value =0
s_cmp_lt_u32 m0, s_save_alloc_size
s_cbranch_scc0 L_SAVE_VGPR_END
s_set_gpr_idx_on m0, 0x1 //M0[7:0] = M0[7:0] and M0[15:12] = 0x1
s_add_u32 s_save_alloc_size, s_save_alloc_size, 0x1000 //add 0x1000 since we compare m0 against it later
if SAVE_AFTER_XNACK_ERROR
check_if_tcp_store_ok()
s_cbranch_scc1 L_SAVE_VGPR_LOOP
L_SAVE_VGPR_LOOP_SQC:
write_vgprs_to_mem_with_sqc(v0, 4, s_save_buf_rsrc0, s_save_mem_offset)
s_add_u32 m0, m0, 4
s_cmp_lt_u32 m0, s_save_alloc_size
s_cbranch_scc1 L_SAVE_VGPR_LOOP_SQC
s_set_gpr_idx_off
s_branch L_SAVE_VGPR_END
end
L_SAVE_VGPR_LOOP:
v_mov_b32 v0, v0 //v0 = v[0+m0]
v_mov_b32 v1, v1 //v0 = v[0+m0]
v_mov_b32 v2, v2 //v0 = v[0+m0]
v_mov_b32 v3, v3 //v0 = v[0+m0]
write_4vgprs_to_mem(s_save_buf_rsrc0, s_save_mem_offset)
s_add_u32 m0, m0, 4 //next vgpr index
s_add_u32 s_save_mem_offset, s_save_mem_offset, 256*4 //every buffer_store_dword does 256 bytes
s_cmp_lt_u32 m0, s_save_alloc_size //scc = (m0 < s_save_alloc_size) ? 1 : 0
s_cbranch_scc1 L_SAVE_VGPR_LOOP //VGPR save is complete?
s_set_gpr_idx_off
L_SAVE_VGPR_END:
#if ASIC_FAMILY >= CHIP_ARCTURUS
// Save ACC VGPRs
#if ASIC_FAMILY >= CHIP_ALDEBARAN
// ACC VGPR count may differ from ARCH VGPR count.
get_num_acc_vgprs(s_save_alloc_size, s_save_tmp)
s_and_b32 s_save_alloc_size, s_save_alloc_size, s_save_alloc_size
s_cbranch_scc0 L_SAVE_ACCVGPR_END
s_add_u32 s_save_alloc_size, s_save_alloc_size, 0x1000 //add 0x1000 since we compare m0 against it later
#endif
s_mov_b32 m0, 0x0 //VGPR initial index value =0
s_set_gpr_idx_on m0, 0x1 //M0[7:0] = M0[7:0] and M0[15:12] = 0x1
if SAVE_AFTER_XNACK_ERROR
check_if_tcp_store_ok()
s_cbranch_scc1 L_SAVE_ACCVGPR_LOOP
L_SAVE_ACCVGPR_LOOP_SQC:
for var vgpr = 0; vgpr < 4; ++ vgpr
v_accvgpr_read v[vgpr], acc[vgpr] // v[N] = acc[N+m0]
end
write_vgprs_to_mem_with_sqc(v0, 4, s_save_buf_rsrc0, s_save_mem_offset)
s_add_u32 m0, m0, 4
s_cmp_lt_u32 m0, s_save_alloc_size
s_cbranch_scc1 L_SAVE_ACCVGPR_LOOP_SQC
s_set_gpr_idx_off
s_branch L_SAVE_ACCVGPR_END
end
L_SAVE_ACCVGPR_LOOP:
for var vgpr = 0; vgpr < 4; ++ vgpr
v_accvgpr_read v[vgpr], acc[vgpr] // v[N] = acc[N+m0]
end
write_4vgprs_to_mem(s_save_buf_rsrc0, s_save_mem_offset)
s_add_u32 m0, m0, 4
s_add_u32 s_save_mem_offset, s_save_mem_offset, 256*4
s_cmp_lt_u32 m0, s_save_alloc_size
s_cbranch_scc1 L_SAVE_ACCVGPR_LOOP
s_set_gpr_idx_off
L_SAVE_ACCVGPR_END:
#endif
s_branch L_END_PGM
/**************************************************************************/
/* restore routine */
/**************************************************************************/
L_RESTORE:
/* Setup Resource Contants */
s_mov_b32 s_restore_buf_rsrc0, s_restore_spi_init_lo //base_addr_lo
s_and_b32 s_restore_buf_rsrc1, s_restore_spi_init_hi, 0x0000FFFF //base_addr_hi
s_or_b32 s_restore_buf_rsrc1, s_restore_buf_rsrc1, S_RESTORE_BUF_RSRC_WORD1_STRIDE
s_mov_b32 s_restore_buf_rsrc2, 0 //NUM_RECORDS initial value = 0 (in bytes)
s_mov_b32 s_restore_buf_rsrc3, S_RESTORE_BUF_RSRC_WORD3_MISC
s_and_b32 s_restore_tmp, s_restore_spi_init_hi, S_RESTORE_SPI_INIT_ATC_MASK
s_lshr_b32 s_restore_tmp, s_restore_tmp, (S_RESTORE_SPI_INIT_ATC_SHIFT-SQ_BUF_RSRC_WORD1_ATC_SHIFT) //get ATC bit into position
s_or_b32 s_restore_buf_rsrc3, s_restore_buf_rsrc3, s_restore_tmp //or ATC
s_and_b32 s_restore_tmp, s_restore_spi_init_hi, S_RESTORE_SPI_INIT_MTYPE_MASK
s_lshr_b32 s_restore_tmp, s_restore_tmp, (S_RESTORE_SPI_INIT_MTYPE_SHIFT-SQ_BUF_RSRC_WORD3_MTYPE_SHIFT) //get MTYPE bits into position
s_or_b32 s_restore_buf_rsrc3, s_restore_buf_rsrc3, s_restore_tmp //or MTYPE
/* global mem offset */
// s_mov_b32 s_restore_mem_offset, 0x0 //mem offset initial value = 0
/* the first wave in the threadgroup */
s_and_b32 s_restore_tmp, s_restore_spi_init_hi, S_RESTORE_SPI_INIT_FIRST_WAVE_MASK
s_cbranch_scc0 L_RESTORE_VGPR
/* restore LDS */
//////////////////////////////
L_RESTORE_LDS:
s_mov_b32 exec_lo, 0xFFFFFFFF //need every thread from now on //be consistent with SAVE although can be moved ahead
s_mov_b32 exec_hi, 0xFFFFFFFF
s_getreg_b32 s_restore_alloc_size, hwreg(HW_REG_LDS_ALLOC,SQ_WAVE_LDS_ALLOC_LDS_SIZE_SHIFT,SQ_WAVE_LDS_ALLOC_LDS_SIZE_SIZE) //lds_size
s_and_b32 s_restore_alloc_size, s_restore_alloc_size, 0xFFFFFFFF //lds_size is zero?
s_cbranch_scc0 L_RESTORE_VGPR //no lds used? jump to L_RESTORE_VGPR
s_lshl_b32 s_restore_alloc_size, s_restore_alloc_size, 6 //LDS size in dwords = lds_size * 64dw
s_lshl_b32 s_restore_alloc_size, s_restore_alloc_size, 2 //LDS size in bytes
s_mov_b32 s_restore_buf_rsrc2, s_restore_alloc_size //NUM_RECORDS in bytes
// LDS at offset: size(VGPR)+SIZE(SGPR)+SIZE(HWREG)
//
get_vgpr_size_bytes(s_restore_mem_offset)
get_sgpr_size_bytes(s_restore_tmp)
s_add_u32 s_restore_mem_offset, s_restore_mem_offset, s_restore_tmp
s_add_u32 s_restore_mem_offset, s_restore_mem_offset, get_hwreg_size_bytes() //FIXME, Check if offset overflow???
s_mov_b32 s_restore_buf_rsrc2, 0x1000000 //NUM_RECORDS in bytes
s_mov_b32 m0, 0x0 //lds_offset initial value = 0
L_RESTORE_LDS_LOOP:
buffer_load_dword v0, v0, s_restore_buf_rsrc0, s_restore_mem_offset lds:1 // first 64DW
buffer_load_dword v0, v0, s_restore_buf_rsrc0, s_restore_mem_offset lds:1 offset:256 // second 64DW
s_add_u32 m0, m0, 256*2 // 128 DW
s_add_u32 s_restore_mem_offset, s_restore_mem_offset, 256*2 //mem offset increased by 128DW
s_cmp_lt_u32 m0, s_restore_alloc_size //scc=(m0 < s_restore_alloc_size) ? 1 : 0
s_cbranch_scc1 L_RESTORE_LDS_LOOP //LDS restore is complete?
/* restore VGPRs */
//////////////////////////////
L_RESTORE_VGPR:
s_mov_b32 exec_lo, 0xFFFFFFFF //need every thread from now on //be consistent with SAVE although can be moved ahead
s_mov_b32 exec_hi, 0xFFFFFFFF
s_mov_b32 s_restore_buf_rsrc2, 0x1000000 //NUM_RECORDS in bytes
// Save ARCH VGPRs 4-N, then all ACC VGPRs, then ARCH VGPRs 0-3.
get_num_arch_vgprs(s_restore_alloc_size)
s_add_u32 s_restore_alloc_size, s_restore_alloc_size, 0x8000 //add 0x8000 since we compare m0 against it later
// ARCH VGPRs at offset: 0
s_mov_b32 s_restore_mem_offset, 0x0
s_mov_b32 s_restore_mem_offset_save, s_restore_mem_offset // restore start with v1, v0 will be the last
s_add_u32 s_restore_mem_offset, s_restore_mem_offset, 256*4
s_mov_b32 m0, 4 //VGPR initial index value = 1
s_set_gpr_idx_on m0, 0x8 //M0[7:0] = M0[7:0] and M0[15:12] = 0x8
L_RESTORE_VGPR_LOOP:
read_4vgprs_from_mem(s_restore_buf_rsrc0, s_restore_mem_offset)
v_mov_b32 v0, v0 //v[0+m0] = v0
v_mov_b32 v1, v1
v_mov_b32 v2, v2
v_mov_b32 v3, v3
s_add_u32 m0, m0, 4 //next vgpr index
s_add_u32 s_restore_mem_offset, s_restore_mem_offset, 256*4 //every buffer_load_dword does 256 bytes
s_cmp_lt_u32 m0, s_restore_alloc_size //scc = (m0 < s_restore_alloc_size) ? 1 : 0
s_cbranch_scc1 L_RESTORE_VGPR_LOOP //VGPR restore (except v0) is complete?
#if ASIC_FAMILY >= CHIP_ALDEBARAN
// ACC VGPR count may differ from ARCH VGPR count.
get_num_acc_vgprs(s_restore_alloc_size, s_restore_tmp2)
s_and_b32 s_restore_alloc_size, s_restore_alloc_size, s_restore_alloc_size
s_cbranch_scc0 L_RESTORE_ACCVGPR_END
s_add_u32 s_restore_alloc_size, s_restore_alloc_size, 0x8000 //add 0x8000 since we compare m0 against it later
#endif
#if ASIC_FAMILY >= CHIP_ARCTURUS
// ACC VGPRs at offset: size(ARCH VGPRs)
s_mov_b32 m0, 0
s_set_gpr_idx_on m0, 0x8 //M0[7:0] = M0[7:0] and M0[15:12] = 0x8
L_RESTORE_ACCVGPR_LOOP:
read_4vgprs_from_mem(s_restore_buf_rsrc0, s_restore_mem_offset)
for var vgpr = 0; vgpr < 4; ++ vgpr
v_accvgpr_write acc[vgpr], v[vgpr]
end
s_add_u32 m0, m0, 4 //next vgpr index
s_add_u32 s_restore_mem_offset, s_restore_mem_offset, 256*4 //every buffer_load_dword does 256 bytes
s_cmp_lt_u32 m0, s_restore_alloc_size //scc = (m0 < s_restore_alloc_size) ? 1 : 0
s_cbranch_scc1 L_RESTORE_ACCVGPR_LOOP //VGPR restore (except v0) is complete?
L_RESTORE_ACCVGPR_END:
#endif
s_set_gpr_idx_off
// Restore VGPRs 0-3 last, no longer needed.
read_4vgprs_from_mem(s_restore_buf_rsrc0, s_restore_mem_offset_save)
/* restore SGPRs */
//////////////////////////////
// SGPR SR memory offset : size(VGPR)
get_vgpr_size_bytes(s_restore_mem_offset)
get_sgpr_size_bytes(s_restore_tmp)
s_add_u32 s_restore_mem_offset, s_restore_mem_offset, s_restore_tmp
s_sub_u32 s_restore_mem_offset, s_restore_mem_offset, 16*4 // restore SGPR from S[n] to S[0], by 16 sgprs group
// TODO, change RSRC word to rearrange memory layout for SGPRS
s_getreg_b32 s_restore_alloc_size, hwreg(HW_REG_GPR_ALLOC,SQ_WAVE_GPR_ALLOC_SGPR_SIZE_SHIFT,SQ_WAVE_GPR_ALLOC_SGPR_SIZE_SIZE) //spgr_size
s_add_u32 s_restore_alloc_size, s_restore_alloc_size, 1
s_lshl_b32 s_restore_alloc_size, s_restore_alloc_size, 4 //Number of SGPRs = (sgpr_size + 1) * 16 (non-zero value)
s_lshl_b32 s_restore_buf_rsrc2, s_restore_alloc_size, 2 //NUM_RECORDS in bytes
s_mov_b32 s_restore_buf_rsrc2, 0x1000000 //NUM_RECORDS in bytes
s_mov_b32 m0, s_restore_alloc_size
L_RESTORE_SGPR_LOOP:
read_16sgpr_from_mem(s0, s_restore_buf_rsrc0, s_restore_mem_offset) //PV: further performance improvement can be made
s_waitcnt lgkmcnt(0) //ensure data ready
s_sub_u32 m0, m0, 16 // Restore from S[n] to S[0]
s_nop 0 // hazard SALU M0=> S_MOVREL
s_movreld_b64 s0, s0 //s[0+m0] = s0
s_movreld_b64 s2, s2
s_movreld_b64 s4, s4
s_movreld_b64 s6, s6
s_movreld_b64 s8, s8
s_movreld_b64 s10, s10
s_movreld_b64 s12, s12
s_movreld_b64 s14, s14
s_cmp_eq_u32 m0, 0 //scc = (m0 < s_restore_alloc_size) ? 1 : 0
s_cbranch_scc0 L_RESTORE_SGPR_LOOP //SGPR restore (except s0) is complete?
/* restore HW registers */
//////////////////////////////
L_RESTORE_HWREG:
// HWREG SR memory offset : size(VGPR)+size(SGPR)
get_vgpr_size_bytes(s_restore_mem_offset)
get_sgpr_size_bytes(s_restore_tmp)
s_add_u32 s_restore_mem_offset, s_restore_mem_offset, s_restore_tmp
s_mov_b32 s_restore_buf_rsrc2, 0x4 //NUM_RECORDS in bytes
s_mov_b32 s_restore_buf_rsrc2, 0x1000000 //NUM_RECORDS in bytes
read_hwreg_from_mem(s_restore_m0, s_restore_buf_rsrc0, s_restore_mem_offset) //M0
read_hwreg_from_mem(s_restore_pc_lo, s_restore_buf_rsrc0, s_restore_mem_offset) //PC
read_hwreg_from_mem(s_restore_pc_hi, s_restore_buf_rsrc0, s_restore_mem_offset)
read_hwreg_from_mem(s_restore_exec_lo, s_restore_buf_rsrc0, s_restore_mem_offset) //EXEC
read_hwreg_from_mem(s_restore_exec_hi, s_restore_buf_rsrc0, s_restore_mem_offset)
read_hwreg_from_mem(s_restore_status, s_restore_buf_rsrc0, s_restore_mem_offset) //STATUS
read_hwreg_from_mem(s_restore_trapsts, s_restore_buf_rsrc0, s_restore_mem_offset) //TRAPSTS
read_hwreg_from_mem(xnack_mask_lo, s_restore_buf_rsrc0, s_restore_mem_offset) //XNACK_MASK_LO
read_hwreg_from_mem(xnack_mask_hi, s_restore_buf_rsrc0, s_restore_mem_offset) //XNACK_MASK_HI
read_hwreg_from_mem(s_restore_mode, s_restore_buf_rsrc0, s_restore_mem_offset) //MODE
s_waitcnt lgkmcnt(0) //from now on, it is safe to restore STATUS and IB_STS
s_mov_b32 m0, s_restore_m0
s_mov_b32 exec_lo, s_restore_exec_lo
s_mov_b32 exec_hi, s_restore_exec_hi
s_and_b32 s_restore_m0, SQ_WAVE_TRAPSTS_PRE_SAVECTX_MASK, s_restore_trapsts
s_setreg_b32 hwreg(HW_REG_TRAPSTS, SQ_WAVE_TRAPSTS_PRE_SAVECTX_SHIFT, SQ_WAVE_TRAPSTS_PRE_SAVECTX_SIZE), s_restore_m0
s_and_b32 s_restore_m0, SQ_WAVE_TRAPSTS_POST_SAVECTX_MASK, s_restore_trapsts
s_lshr_b32 s_restore_m0, s_restore_m0, SQ_WAVE_TRAPSTS_POST_SAVECTX_SHIFT
s_setreg_b32 hwreg(HW_REG_TRAPSTS, SQ_WAVE_TRAPSTS_POST_SAVECTX_SHIFT, SQ_WAVE_TRAPSTS_POST_SAVECTX_SIZE), s_restore_m0
//s_setreg_b32 hwreg(HW_REG_TRAPSTS), s_restore_trapsts //don't overwrite SAVECTX bit as it may be set through external SAVECTX during restore
s_setreg_b32 hwreg(HW_REG_MODE), s_restore_mode
// Restore trap temporaries 4-11, 13 initialized by SPI debug dispatch logic
// ttmp SR memory offset : size(VGPR)+size(SGPR)+0x40
get_vgpr_size_bytes(s_restore_ttmps_lo)
get_sgpr_size_bytes(s_restore_ttmps_hi)
s_add_u32 s_restore_ttmps_lo, s_restore_ttmps_lo, s_restore_ttmps_hi
s_add_u32 s_restore_ttmps_lo, s_restore_ttmps_lo, s_restore_buf_rsrc0
s_addc_u32 s_restore_ttmps_hi, s_restore_buf_rsrc1, 0x0
s_and_b32 s_restore_ttmps_hi, s_restore_ttmps_hi, 0xFFFF
s_load_dwordx4 [ttmp4, ttmp5, ttmp6, ttmp7], [s_restore_ttmps_lo, s_restore_ttmps_hi], 0x50 glc:1
s_load_dwordx4 [ttmp8, ttmp9, ttmp10, ttmp11], [s_restore_ttmps_lo, s_restore_ttmps_hi], 0x60 glc:1
s_load_dword ttmp13, [s_restore_ttmps_lo, s_restore_ttmps_hi], 0x74 glc:1
s_waitcnt lgkmcnt(0)
//reuse s_restore_m0 as a temp register
s_and_b32 s_restore_m0, s_restore_pc_hi, S_SAVE_PC_HI_RCNT_MASK
s_lshr_b32 s_restore_m0, s_restore_m0, S_SAVE_PC_HI_RCNT_SHIFT
s_lshl_b32 s_restore_m0, s_restore_m0, SQ_WAVE_IB_STS_RCNT_SHIFT
s_mov_b32 s_restore_tmp, 0x0 //IB_STS is zero
s_or_b32 s_restore_tmp, s_restore_tmp, s_restore_m0
s_and_b32 s_restore_m0, s_restore_pc_hi, S_SAVE_PC_HI_FIRST_REPLAY_MASK
s_lshr_b32 s_restore_m0, s_restore_m0, S_SAVE_PC_HI_FIRST_REPLAY_SHIFT
s_lshl_b32 s_restore_m0, s_restore_m0, SQ_WAVE_IB_STS_FIRST_REPLAY_SHIFT
s_or_b32 s_restore_tmp, s_restore_tmp, s_restore_m0
s_and_b32 s_restore_m0, s_restore_status, SQ_WAVE_STATUS_INST_ATC_MASK
s_lshr_b32 s_restore_m0, s_restore_m0, SQ_WAVE_STATUS_INST_ATC_SHIFT
s_setreg_b32 hwreg(HW_REG_IB_STS), s_restore_tmp
s_and_b32 s_restore_pc_hi, s_restore_pc_hi, 0x0000ffff //pc[47:32] //Do it here in order not to affect STATUS
s_and_b64 exec, exec, exec // Restore STATUS.EXECZ, not writable by s_setreg_b32
s_and_b64 vcc, vcc, vcc // Restore STATUS.VCCZ, not writable by s_setreg_b32
set_status_without_spi_prio(s_restore_status, s_restore_tmp) // SCC is included, which is changed by previous salu
s_barrier //barrier to ensure the readiness of LDS before access attempts from any other wave in the same TG //FIXME not performance-optimal at this time
// s_rfe_b64 s_restore_pc_lo //Return to the main shader program and resume execution
s_rfe_restore_b64 s_restore_pc_lo, s_restore_m0 // s_restore_m0[0] is used to set STATUS.inst_atc
/**************************************************************************/
/* the END */
/**************************************************************************/
L_END_PGM:
s_endpgm
end
/**************************************************************************/
/* the helper functions */
/**************************************************************************/
//Only for save hwreg to mem
function write_hwreg_to_mem(s, s_rsrc, s_mem_offset)
s_mov_b32 exec_lo, m0 //assuming exec_lo is not needed anymore from this point on
s_mov_b32 m0, s_mem_offset
s_buffer_store_dword s, s_rsrc, m0 glc:1
ack_sqc_store_workaround()
s_add_u32 s_mem_offset, s_mem_offset, 4
s_mov_b32 m0, exec_lo
end
// HWREG are saved before SGPRs, so all HWREG could be use.
function write_16sgpr_to_mem(s, s_rsrc, s_mem_offset)
s_buffer_store_dwordx4 s[0], s_rsrc, 0 glc:1
ack_sqc_store_workaround()
s_buffer_store_dwordx4 s[4], s_rsrc, 16 glc:1
ack_sqc_store_workaround()
s_buffer_store_dwordx4 s[8], s_rsrc, 32 glc:1
ack_sqc_store_workaround()
s_buffer_store_dwordx4 s[12], s_rsrc, 48 glc:1
ack_sqc_store_workaround()
s_add_u32 s_rsrc[0], s_rsrc[0], 4*16
s_addc_u32 s_rsrc[1], s_rsrc[1], 0x0 // +scc
end
function read_hwreg_from_mem(s, s_rsrc, s_mem_offset)
s_buffer_load_dword s, s_rsrc, s_mem_offset glc:1
s_add_u32 s_mem_offset, s_mem_offset, 4
end
function read_16sgpr_from_mem(s, s_rsrc, s_mem_offset)
s_buffer_load_dwordx16 s, s_rsrc, s_mem_offset glc:1
s_sub_u32 s_mem_offset, s_mem_offset, 4*16
end
function check_if_tcp_store_ok
// If STATUS.ALLOW_REPLAY=0 and TRAPSTS.XNACK_ERROR=1 then TCP stores will fail.
s_and_b32 s_save_tmp, s_save_status, SQ_WAVE_STATUS_ALLOW_REPLAY_MASK
s_cbranch_scc1 L_TCP_STORE_CHECK_DONE
s_getreg_b32 s_save_tmp, hwreg(HW_REG_TRAPSTS)
s_andn2_b32 s_save_tmp, SQ_WAVE_TRAPSTS_XNACK_ERROR_MASK, s_save_tmp
L_TCP_STORE_CHECK_DONE:
end
function write_4vgprs_to_mem(s_rsrc, s_mem_offset)
buffer_store_dword v0, v0, s_rsrc, s_mem_offset slc:1 glc:1
buffer_store_dword v1, v0, s_rsrc, s_mem_offset slc:1 glc:1 offset:256
buffer_store_dword v2, v0, s_rsrc, s_mem_offset slc:1 glc:1 offset:256*2
buffer_store_dword v3, v0, s_rsrc, s_mem_offset slc:1 glc:1 offset:256*3
end
function read_4vgprs_from_mem(s_rsrc, s_mem_offset)
buffer_load_dword v0, v0, s_rsrc, s_mem_offset slc:1 glc:1
buffer_load_dword v1, v0, s_rsrc, s_mem_offset slc:1 glc:1 offset:256
buffer_load_dword v2, v0, s_rsrc, s_mem_offset slc:1 glc:1 offset:256*2
buffer_load_dword v3, v0, s_rsrc, s_mem_offset slc:1 glc:1 offset:256*3
s_waitcnt vmcnt(0)
end
function write_vgpr_to_mem_with_sqc(v, s_rsrc, s_mem_offset)
s_mov_b32 s4, 0
L_WRITE_VGPR_LANE_LOOP:
for var lane = 0; lane < 4; ++ lane
v_readlane_b32 s[lane], v, s4
s_add_u32 s4, s4, 1
end
s_buffer_store_dwordx4 s[0:3], s_rsrc, s_mem_offset glc:1
ack_sqc_store_workaround()
s_add_u32 s_mem_offset, s_mem_offset, 0x10
s_cmp_eq_u32 s4, 0x40
s_cbranch_scc0 L_WRITE_VGPR_LANE_LOOP
end
function write_vgprs_to_mem_with_sqc(v, n_vgprs, s_rsrc, s_mem_offset)
for var vgpr = 0; vgpr < n_vgprs; ++ vgpr
write_vgpr_to_mem_with_sqc(v[vgpr], s_rsrc, s_mem_offset)
end
end
function get_lds_size_bytes(s_lds_size_byte)
// SQ LDS granularity is 64DW, while PGM_RSRC2.lds_size is in granularity 128DW
s_getreg_b32 s_lds_size_byte, hwreg(HW_REG_LDS_ALLOC, SQ_WAVE_LDS_ALLOC_LDS_SIZE_SHIFT, SQ_WAVE_LDS_ALLOC_LDS_SIZE_SIZE) // lds_size
s_lshl_b32 s_lds_size_byte, s_lds_size_byte, 8 //LDS size in dwords = lds_size * 64 *4Bytes // granularity 64DW
end
function get_vgpr_size_bytes(s_vgpr_size_byte)
s_getreg_b32 s_vgpr_size_byte, hwreg(HW_REG_GPR_ALLOC,SQ_WAVE_GPR_ALLOC_VGPR_SIZE_SHIFT,SQ_WAVE_GPR_ALLOC_VGPR_SIZE_SIZE) //vpgr_size
s_add_u32 s_vgpr_size_byte, s_vgpr_size_byte, 1
s_lshl_b32 s_vgpr_size_byte, s_vgpr_size_byte, (2+8) //Number of VGPRs = (vgpr_size + 1) * 4 * 64 * 4 (non-zero value) //FIXME for GFX, zero is possible
#if ASIC_FAMILY >= CHIP_ARCTURUS
s_lshl_b32 s_vgpr_size_byte, s_vgpr_size_byte, 1 // Double size for ACC VGPRs
#endif
end
function get_sgpr_size_bytes(s_sgpr_size_byte)
s_getreg_b32 s_sgpr_size_byte, hwreg(HW_REG_GPR_ALLOC,SQ_WAVE_GPR_ALLOC_SGPR_SIZE_SHIFT,SQ_WAVE_GPR_ALLOC_SGPR_SIZE_SIZE) //spgr_size
s_add_u32 s_sgpr_size_byte, s_sgpr_size_byte, 1
s_lshl_b32 s_sgpr_size_byte, s_sgpr_size_byte, 6 //Number of SGPRs = (sgpr_size + 1) * 16 *4 (non-zero value)
end
function get_hwreg_size_bytes
return 128 //HWREG size 128 bytes
end
function get_num_arch_vgprs(s_num_arch_vgprs)
#if ASIC_FAMILY >= CHIP_ALDEBARAN
// VGPR count includes ACC VGPRs, use ACC VGPR offset for ARCH VGPR count.
s_getreg_b32 s_num_arch_vgprs, hwreg(HW_REG_GPR_ALLOC,SQ_WAVE_GPR_ALLOC_ACCV_OFFSET_SHIFT,SQ_WAVE_GPR_ALLOC_ACCV_OFFSET_SIZE)
#else
s_getreg_b32 s_num_arch_vgprs, hwreg(HW_REG_GPR_ALLOC,SQ_WAVE_GPR_ALLOC_VGPR_SIZE_SHIFT,SQ_WAVE_GPR_ALLOC_VGPR_SIZE_SIZE)
#endif
// Number of VGPRs = (vgpr_size + 1) * 4
s_add_u32 s_num_arch_vgprs, s_num_arch_vgprs, 1
s_lshl_b32 s_num_arch_vgprs, s_num_arch_vgprs, 2
end
#if ASIC_FAMILY >= CHIP_ALDEBARAN
function get_num_acc_vgprs(s_num_acc_vgprs, s_tmp)
// VGPR count = (GPR_ALLOC.VGPR_SIZE + 1) * 8
s_getreg_b32 s_num_acc_vgprs, hwreg(HW_REG_GPR_ALLOC,SQ_WAVE_GPR_ALLOC_VGPR_SIZE_SHIFT,SQ_WAVE_GPR_ALLOC_VGPR_SIZE_SIZE)
s_add_u32 s_num_acc_vgprs, s_num_acc_vgprs, 1
s_lshl_b32 s_num_acc_vgprs, s_num_acc_vgprs, 3
// ACC VGPR count = VGPR count - ARCH VGPR count.
get_num_arch_vgprs(s_tmp)
s_sub_u32 s_num_acc_vgprs, s_num_acc_vgprs, s_tmp
end
#endif
function ack_sqc_store_workaround
if ACK_SQC_STORE
s_waitcnt lgkmcnt(0)
end
end
function set_status_without_spi_prio(status, tmp)
// Do not restore STATUS.SPI_PRIO since scheduler may have raised it.
s_lshr_b32 tmp, status, SQ_WAVE_STATUS_POST_SPI_PRIO_SHIFT
s_setreg_b32 hwreg(HW_REG_STATUS, SQ_WAVE_STATUS_POST_SPI_PRIO_SHIFT, SQ_WAVE_STATUS_POST_SPI_PRIO_SIZE), tmp
s_nop 0x2 // avoid S_SETREG => S_SETREG hazard
s_setreg_b32 hwreg(HW_REG_STATUS, SQ_WAVE_STATUS_PRE_SPI_PRIO_SHIFT, SQ_WAVE_STATUS_PRE_SPI_PRIO_SIZE), status
end
|
; A171965: Partial sums of floor(n^2/6) (A056827).
; 0,0,0,1,3,7,13,21,31,44,60,80,104,132,164,201,243,291,345,405,471,544,624,712,808,912,1024,1145,1275,1415,1565,1725,1895,2076,2268,2472,2688,2916,3156,3409,3675,3955,4249,4557,4879,5216,5568,5936,6320,6720,7136,7569,8019,8487,8973,9477,9999,10540,11100,11680,12280,12900,13540,14201,14883,15587,16313,17061,17831,18624,19440,20280,21144,22032,22944,23881,24843,25831,26845,27885,28951,30044,31164,32312,33488,34692,35924,37185,38475,39795,41145,42525,43935,45376,46848,48352,49888,51456,53056,54689,56355,58055,59789,61557,63359,65196,67068,68976,70920,72900,74916,76969,79059,81187,83353,85557,87799,90080,92400,94760,97160,99600,102080,104601,107163,109767,112413,115101,117831,120604,123420,126280,129184,132132,135124,138161,141243,144371,147545,150765,154031,157344,160704,164112,167568,171072,174624,178225,181875,185575,189325,193125,196975,200876,204828,208832,212888,216996,221156,225369,229635,233955,238329,242757,247239,251776,256368,261016,265720,270480,275296,280169,285099,290087,295133,300237,305399,310620,315900,321240,326640,332100,337620,343201,348843,354547,360313,366141,372031,377984,384000,390080,396224,402432,408704,415041,421443,427911,434445,441045,447711,454444,461244,468112,475048,482052,489124,496265,503475,510755,518105,525525,533015,540576,548208,555912,563688,571536,579456,587449,595515,603655,611869,620157,628519,636956,645468,654056,662720,671460,680276,689169,698139,707187,716313,725517,734799,744160,753600,763120,772720,782400,792160,802001,811923,821927,832013,842181,852431,862764
mov $2,$0
mov $4,$0
lpb $2
mov $0,$4
sub $2,1
sub $0,$2
mov $3,$0
pow $3,2
div $3,6
add $1,$3
lpe
|
; A171781: Numbers for which the second bit of the binary expansion is equal to the last bit.
; Submitted by Jon Maiga
; 2,3,4,7,8,10,13,15,16,18,20,22,25,27,29,31,32,34,36,38,40,42,44,46,49,51,53,55,57,59,61,63,64,66,68,70,72,74,76,78,80,82,84,86,88,90,92,94,97,99,101,103,105,107,109,111,113,115,117,119,121,123,125,127,128,130,132,134,136,138,140,142,144,146,148,150,152,154,156,158,160,162,164,166,168,170,172,174,176,178,180,182,184,186,188,190,193,195,197,199
mul $0,2
mov $1,$0
mov $2,$0
lpb $1
div $2,2
mov $1,$2
trn $1,2
lpe
sub $0,$2
add $0,2
|
; A224882: G.f.: 1/(1 - 32*x)^(1/16).
; Submitted by Christian Krause
; 1,2,34,748,18326,476476,12864852,356540184,10072260198,288738125676,8373405644604,245112419778408,7230816383463036,214699624924363992,6410317372741724904,192309521182251747120,5793324325615333881990,175162864903898918549580
mov $1,1
mov $2,1
mov $3,$0
mul $3,2
lpb $3
mul $1,$3
mul $1,8
mul $2,15
sub $1,$2
mov $2,$1
sub $3,1
cmp $4,0
add $5,$4
div $1,$5
div $2,$5
add $2,$1
mul $1,2
sub $3,1
mov $4,2
add $5,1
lpe
mov $0,$1
|
MOV A,#1
START:
RLC A
SJMP START |
SECTION "Map_3828", ROM0[$B800]
Map_3828_Header:
hdr_tileset 0
hdr_dimensions 14, 9
hdr_pointers_a Map_3828_Blocks, Map_3828_TextPointers
hdr_pointers_b Map_3828_Script, Map_3828_Objects
hdr_pointers_c Map_3828_InitScript, Map_3828_RAMScript
hdr_palette $06
hdr_music MUSIC_ROUTES3, AUDIO_1
hdr_connection NORTH, $0000, 0, 0
hdr_connection SOUTH, $0000, 0, 0
hdr_connection WEST, $3420, 18, 10
hdr_connection EAST, $0000, 0, 0
Map_3828_Objects:
hdr_border $0f
hdr_warp_count 0
hdr_sign_count 0
hdr_object_count 2
hdr_object SPRITE_SAILOR, 16, 9, STAY, NONE, $01
hdr_object SPRITE_LITTLE_GIRL, 7, 7, STAY, NONE, $02
Map_3828_RAMScript:
rs_fill_byte $55
rs_fill_3 $c774
rs_fill_byte $0a
rs_fill_3 $c788
rs_end
Map_3828_Blocks:
db $0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f
db $0f,$0f,$0f,$0f,$0b,$0b,$0f,$0f,$0b,$0b,$0b,$0f,$0f,$0f
db $0f,$0f,$0b,$0b,$9f,$0a,$a5,$0b,$9a,$0a,$0a,$0b,$0f,$0f
db $0f,$0b,$0b,$0a,$0a,$af,$ab,$c4,$0a,$96,$a3,$0b,$0b,$0f
db $55,$55,$55,$55,$55,$55,$55,$55,$55,$55,$bf,$0a,$0b,$0f
db $0a,$0a,$0a,$0a,$0a,$0a,$9a,$8a,$96,$85,$0a,$0a,$0b,$0f
db $0f,$0f,$0f,$0b,$95,$9b,$0a,$c2,$0a,$0b,$0b,$0f,$0f,$0f
db $0f,$0f,$0f,$0f,$0f,$0b,$0b,$0b,$0f,$0f,$0f,$0f,$0f,$0f
db $0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f
Map_3828_TextPointers:
dw Map_3828_TX1
dw Map_3828_TX2
Map_3828_InitScript:
ret
Map_3828_Script:
ret
Map_3828_TX1:
TX_ASM
jp EnhancedTextOnly
text "1 ERROR."
done
Map_3828_TX2:
TX_ASM
ld c, EVENT_CORRUPTED_PLAINS
ld hl, Map_3828_After
call CheckEventAndPrintHLIfCompleted
ld a, [$c769]
cp $ab
jr z, .nope
ld hl, Map_3828_After
call PrintTextEnhanced
ld bc, $FEF0
ld de, $A169
call CompleteEvent
jp TextScriptEnd
.nope
ld hl, Map_3828_Before
call PrintTextEnhanced
jp TextScriptEnd
Map_3828_Before:
text "This once beautiful area"
next "turned into a corrupted"
cont "wasteland..."
para "I don't know what"
next "happened!"
para "Can you please help us"
next "cleanse the corruption?"
done
Map_3828_After:
text "Oh my! This is so much"
next "better!"
para "Thank you for your help!"
wait
|
; decoder.nasm - A decoder for ROL3 shellcode
; Assignment 4 of SLAE32 course
; 2018-07-05 Thomas Karpiniec
; Compile with encoded PAYLOAD
; nasm -f elf32 -o decoder.o -DPAYLOAD="0x90,0x90,..." decoder.nasm
global _start
_start:
jmp short payload_to_stack
decoder:
; Need to rotate each byte once to the right
pop edi ; remember where the start is
mov esi, edi ; copy to esi, which we'll use as our walking ptr
loop:
mov eax, [esi]
cmp eax, 0x59595959 ; if equal, we've finished
je run_shellcode
ror al, 3 ; otherwise rotate the bottom byte
mov [esi], eax ; and put it back
inc esi ; shift up one byte
jmp loop ; keep going
run_shellcode:
jmp edi
payload_to_stack:
; Place ptr to PAYLOAD on the stack and jump
call decoder
db PAYLOAD
db 0x59, 0x59, 0x59, 0x59 ; "ZZZZ"
|
/*
* Copyright (c) 2020-2021 Samsung Electronics Co., Ltd. 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 <string>
#include <thorvg.h>
#include "thorvg_capi.h"
using namespace std;
using namespace tvg;
#define CCP(A) const_cast<Tvg_Paint*>(A) //Const-Cast-Paint
#ifdef __cplusplus
extern "C" {
#endif
/************************************************************************/
/* Engine API */
/************************************************************************/
TVG_EXPORT Tvg_Result tvg_engine_init(unsigned engine_method, unsigned threads)
{
return (Tvg_Result) Initializer::init(CanvasEngine(engine_method), threads);
}
TVG_EXPORT Tvg_Result tvg_engine_term(unsigned engine_method)
{
return (Tvg_Result) Initializer::term(CanvasEngine(engine_method));
}
/************************************************************************/
/* Canvas API */
/************************************************************************/
TVG_EXPORT Tvg_Canvas* tvg_swcanvas_create()
{
return (Tvg_Canvas*) SwCanvas::gen().release();
}
TVG_EXPORT Tvg_Result tvg_canvas_destroy(Tvg_Canvas* canvas)
{
if (!canvas) return TVG_RESULT_INVALID_ARGUMENT;
delete(reinterpret_cast<SwCanvas*>(canvas));
return TVG_RESULT_SUCCESS;
}
TVG_EXPORT Tvg_Result tvg_swcanvas_set_target(Tvg_Canvas* canvas, uint32_t* buffer, uint32_t stride, uint32_t w, uint32_t h, uint32_t cs)
{
if (!canvas) return TVG_RESULT_INVALID_ARGUMENT;
return (Tvg_Result) reinterpret_cast<SwCanvas*>(canvas)->target(buffer, stride, w, h, static_cast<SwCanvas::Colorspace>(cs));
}
TVG_EXPORT Tvg_Result tvg_canvas_push(Tvg_Canvas* canvas, Tvg_Paint* paint)
{
if (!canvas || !paint) return TVG_RESULT_INVALID_ARGUMENT;
return (Tvg_Result) reinterpret_cast<Canvas*>(canvas)->push(unique_ptr<Paint>((Paint*)paint));
}
TVG_EXPORT Tvg_Result tvg_canvas_reserve(Tvg_Canvas* canvas, uint32_t n)
{
if (!canvas) return TVG_RESULT_INVALID_ARGUMENT;
return (Tvg_Result) reinterpret_cast<Canvas*>(canvas)->reserve(n);
}
TVG_EXPORT Tvg_Result tvg_canvas_clear(Tvg_Canvas* canvas, bool free)
{
if (!canvas) return TVG_RESULT_INVALID_ARGUMENT;
return (Tvg_Result) reinterpret_cast<Canvas*>(canvas)->clear(free);
}
TVG_EXPORT Tvg_Result tvg_canvas_update(Tvg_Canvas* canvas)
{
if (!canvas) return TVG_RESULT_INVALID_ARGUMENT;
return (Tvg_Result) reinterpret_cast<Canvas*>(canvas)->update(nullptr);
}
TVG_EXPORT Tvg_Result tvg_canvas_update_paint(Tvg_Canvas* canvas, Tvg_Paint* paint)
{
if (!canvas || !paint) return TVG_RESULT_INVALID_ARGUMENT;
return (Tvg_Result) reinterpret_cast<Canvas*>(canvas)->update((Paint*) paint);
}
TVG_EXPORT Tvg_Result tvg_canvas_draw(Tvg_Canvas* canvas)
{
if (!canvas) return TVG_RESULT_INVALID_ARGUMENT;
return (Tvg_Result) reinterpret_cast<Canvas*>(canvas)->draw();
}
TVG_EXPORT Tvg_Result tvg_canvas_sync(Tvg_Canvas* canvas)
{
if (!canvas) return TVG_RESULT_INVALID_ARGUMENT;
return (Tvg_Result) reinterpret_cast<Canvas*>(canvas)->sync();
}
/************************************************************************/
/* Paint API */
/************************************************************************/
TVG_EXPORT Tvg_Result tvg_paint_del(Tvg_Paint* paint)
{
if (!paint) return TVG_RESULT_INVALID_ARGUMENT;
delete(reinterpret_cast<Paint*>(paint));
return TVG_RESULT_SUCCESS;
}
TVG_EXPORT Tvg_Result tvg_paint_scale(Tvg_Paint* paint, float factor)
{
if (!paint) return TVG_RESULT_INVALID_ARGUMENT;
return (Tvg_Result) reinterpret_cast<Paint*>(paint)->scale(factor);
}
TVG_EXPORT Tvg_Result tvg_paint_rotate(Tvg_Paint* paint, float degree)
{
if (!paint) return TVG_RESULT_INVALID_ARGUMENT;
return (Tvg_Result) reinterpret_cast<Paint*>(paint)->rotate(degree);
}
TVG_EXPORT Tvg_Result tvg_paint_translate(Tvg_Paint* paint, float x, float y)
{
if (!paint) return TVG_RESULT_INVALID_ARGUMENT;
return (Tvg_Result) reinterpret_cast<Paint*>(paint)->translate(x, y);
}
TVG_EXPORT Tvg_Result tvg_paint_transform(Tvg_Paint* paint, const Tvg_Matrix* m)
{
if (!paint) return TVG_RESULT_INVALID_ARGUMENT;
return (Tvg_Result) reinterpret_cast<Paint*>(paint)->transform(*(reinterpret_cast<const Matrix*>(m)));
}
TVG_EXPORT Tvg_Result tvg_paint_get_transform(Tvg_Paint* paint, Tvg_Matrix* m)
{
if (!paint || !m) return TVG_RESULT_INVALID_ARGUMENT;
*reinterpret_cast<Matrix*>(m) = reinterpret_cast<Paint*>(paint)->transform();
return TVG_RESULT_SUCCESS;
}
TVG_EXPORT Tvg_Paint* tvg_paint_duplicate(Tvg_Paint* paint)
{
if (!paint) return nullptr;
return (Tvg_Paint*) reinterpret_cast<Paint*>(paint)->duplicate();
}
TVG_EXPORT Tvg_Result tvg_paint_set_opacity(Tvg_Paint* paint, uint8_t opacity)
{
if (!paint) return TVG_RESULT_INVALID_ARGUMENT;
return (Tvg_Result) reinterpret_cast<Paint*>(paint)->opacity(opacity);
}
TVG_EXPORT Tvg_Result tvg_paint_get_opacity(Tvg_Paint* paint, uint8_t* opacity)
{
if (!paint || !opacity) return TVG_RESULT_INVALID_ARGUMENT;
*opacity = reinterpret_cast<Paint*>(paint)->opacity();
return TVG_RESULT_SUCCESS;
}
TVG_EXPORT Tvg_Result tvg_paint_get_bounds(const Tvg_Paint* paint, float* x, float* y, float* w, float* h)
{
if (!paint) return TVG_RESULT_INVALID_ARGUMENT;
return (Tvg_Result) reinterpret_cast<const Paint*>(paint)->bounds(x, y, w, h);
}
TVG_EXPORT Tvg_Result tvg_paint_set_composite_method(Tvg_Paint* paint, Tvg_Paint* target, Tvg_Composite_Method method)
{
if (!paint) return TVG_RESULT_INVALID_ARGUMENT;
return (Tvg_Result) reinterpret_cast<Paint*>(paint)->composite(unique_ptr<Paint>((Paint*)(target)), (CompositeMethod)method);
}
/************************************************************************/
/* Shape API */
/************************************************************************/
TVG_EXPORT Tvg_Paint* tvg_shape_new()
{
return (Tvg_Paint*) Shape::gen().release();
}
TVG_EXPORT Tvg_Result tvg_shape_reset(Tvg_Paint* paint)
{
if (!paint) return TVG_RESULT_INVALID_ARGUMENT;
return (Tvg_Result) reinterpret_cast<Shape*>(paint)->reset();
}
TVG_EXPORT Tvg_Result tvg_shape_move_to(Tvg_Paint* paint, float x, float y)
{
if (!paint) return TVG_RESULT_INVALID_ARGUMENT;
return (Tvg_Result) reinterpret_cast<Shape*>(paint)->moveTo(x, y);
}
TVG_EXPORT Tvg_Result tvg_shape_line_to(Tvg_Paint* paint, float x, float y)
{
if (!paint) return TVG_RESULT_INVALID_ARGUMENT;
return (Tvg_Result) reinterpret_cast<Shape*>(paint)->lineTo(x, y);
}
TVG_EXPORT Tvg_Result tvg_shape_cubic_to(Tvg_Paint* paint, float cx1, float cy1, float cx2, float cy2, float x, float y)
{
if (!paint) return TVG_RESULT_INVALID_ARGUMENT;
return (Tvg_Result) reinterpret_cast<Shape*>(paint)->cubicTo(cx1, cy1, cx2, cy2, x, y);
}
TVG_EXPORT Tvg_Result tvg_shape_close(Tvg_Paint* paint)
{
if (!paint) return TVG_RESULT_INVALID_ARGUMENT;
return (Tvg_Result) reinterpret_cast<Shape*>(paint)->close();
}
TVG_EXPORT Tvg_Result tvg_shape_append_rect(Tvg_Paint* paint, float x, float y, float w, float h, float rx, float ry)
{
if (!paint) return TVG_RESULT_INVALID_ARGUMENT;
return (Tvg_Result) reinterpret_cast<Shape*>(paint)->appendRect(x, y, w, h, rx, ry);
}
TVG_EXPORT Tvg_Result tvg_shape_append_arc(Tvg_Paint* paint, float cx, float cy, float radius, float startAngle, float sweep, uint8_t pie)
{
if (!paint) return TVG_RESULT_INVALID_ARGUMENT;
return (Tvg_Result) reinterpret_cast<Shape*>(paint)->appendArc(cx, cy, radius, startAngle, sweep, pie);
}
TVG_EXPORT Tvg_Result tvg_shape_append_circle(Tvg_Paint* paint, float cx, float cy, float rx, float ry)
{
if (!paint) return TVG_RESULT_INVALID_ARGUMENT;
return (Tvg_Result) reinterpret_cast<Shape*>(paint)->appendCircle(cx, cy, rx, ry);
}
TVG_EXPORT Tvg_Result tvg_shape_append_path(Tvg_Paint* paint, const Tvg_Path_Command* cmds, uint32_t cmdCnt, const Tvg_Point* pts, uint32_t ptsCnt)
{
if (!paint) return TVG_RESULT_INVALID_ARGUMENT;
return (Tvg_Result) reinterpret_cast<Shape*>(paint)->appendPath((const PathCommand*)cmds, cmdCnt, (const Point*)pts, ptsCnt);
}
TVG_EXPORT Tvg_Result tvg_shape_get_path_coords(const Tvg_Paint* paint, const Tvg_Point** pts, uint32_t* cnt)
{
if (!paint || !pts || !cnt) return TVG_RESULT_INVALID_ARGUMENT;
*cnt = reinterpret_cast<const Shape*>(paint)->pathCoords((const Point**)pts);
return TVG_RESULT_SUCCESS;
}
TVG_EXPORT Tvg_Result tvg_shape_get_path_commands(const Tvg_Paint* paint, const Tvg_Path_Command** cmds, uint32_t* cnt)
{
if (!paint || !cmds || !cnt) return TVG_RESULT_INVALID_ARGUMENT;
*cnt = reinterpret_cast<const Shape*>(paint)->pathCommands((const PathCommand**)cmds);
return TVG_RESULT_SUCCESS;
}
TVG_EXPORT Tvg_Result tvg_shape_set_stroke_width(Tvg_Paint* paint, float width)
{
if (!paint) return TVG_RESULT_INVALID_ARGUMENT;
return (Tvg_Result) reinterpret_cast<Shape*>(paint)->stroke(width);
}
TVG_EXPORT Tvg_Result tvg_shape_get_stroke_width(const Tvg_Paint* paint, float* width)
{
if (!paint || !width) return TVG_RESULT_INVALID_ARGUMENT;
*width = reinterpret_cast<Shape*>(CCP(paint))->strokeWidth();
return TVG_RESULT_SUCCESS;
}
TVG_EXPORT Tvg_Result tvg_shape_set_stroke_color(Tvg_Paint* paint, uint8_t r, uint8_t g, uint8_t b, uint8_t a)
{
if (!paint) return TVG_RESULT_INVALID_ARGUMENT;
return (Tvg_Result) reinterpret_cast<Shape*>(paint)->stroke(r, g, b, a);
}
TVG_EXPORT Tvg_Result tvg_shape_get_stroke_color(const Tvg_Paint* paint, uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a)
{
if (!paint) return TVG_RESULT_INVALID_ARGUMENT;
return (Tvg_Result) reinterpret_cast<Shape*>(CCP(paint))->strokeColor(r, g, b, a);
}
TVG_EXPORT Tvg_Result tvg_shape_set_stroke_linear_gradient(Tvg_Paint* paint, Tvg_Gradient* gradient)
{
if (!paint) return TVG_RESULT_INVALID_ARGUMENT;
return (Tvg_Result) reinterpret_cast<Shape*>(paint)->stroke(unique_ptr<LinearGradient>((LinearGradient*)(gradient)));
}
TVG_EXPORT Tvg_Result tvg_shape_set_stroke_radial_gradient(Tvg_Paint* paint, Tvg_Gradient* gradient)
{
if (!paint) return TVG_RESULT_INVALID_ARGUMENT;
return (Tvg_Result) reinterpret_cast<Shape*>(paint)->stroke(unique_ptr<RadialGradient>((RadialGradient*)(gradient)));
}
TVG_EXPORT Tvg_Result tvg_shape_get_stroke_gradient(const Tvg_Paint* paint, Tvg_Gradient** gradient)
{
if (!paint || !gradient) return TVG_RESULT_INVALID_ARGUMENT;
*gradient = (Tvg_Gradient*)(reinterpret_cast<Shape*>(CCP(paint))->strokeFill());
return TVG_RESULT_SUCCESS;
}
TVG_EXPORT Tvg_Result tvg_shape_set_stroke_dash(Tvg_Paint* paint, const float* dashPattern, uint32_t cnt)
{
if (!paint) return TVG_RESULT_INVALID_ARGUMENT;
return (Tvg_Result) reinterpret_cast<Shape*>(paint)->stroke(dashPattern, cnt);
}
TVG_EXPORT Tvg_Result tvg_shape_get_stroke_dash(const Tvg_Paint* paint, const float** dashPattern, uint32_t* cnt)
{
if (!paint || !cnt || !dashPattern) return TVG_RESULT_INVALID_ARGUMENT;
*cnt = reinterpret_cast<Shape*>(CCP(paint))->strokeDash(dashPattern);
return TVG_RESULT_SUCCESS;
}
TVG_EXPORT Tvg_Result tvg_shape_set_stroke_cap(Tvg_Paint* paint, Tvg_Stroke_Cap cap)
{
if (!paint) return TVG_RESULT_INVALID_ARGUMENT;
return (Tvg_Result) reinterpret_cast<Shape*>(paint)->stroke((StrokeCap)cap);
}
TVG_EXPORT Tvg_Result tvg_shape_get_stroke_cap(const Tvg_Paint* paint, Tvg_Stroke_Cap* cap)
{
if (!paint || !cap) return TVG_RESULT_INVALID_ARGUMENT;
*cap = (Tvg_Stroke_Cap) reinterpret_cast<Shape*>(CCP(paint))->strokeCap();
return TVG_RESULT_SUCCESS;
}
TVG_EXPORT Tvg_Result tvg_shape_set_stroke_join(Tvg_Paint* paint, Tvg_Stroke_Join join)
{
if (!paint) return TVG_RESULT_INVALID_ARGUMENT;
return (Tvg_Result) reinterpret_cast<Shape*>(paint)->stroke((StrokeJoin)join);
}
TVG_EXPORT Tvg_Result tvg_shape_get_stroke_join(const Tvg_Paint* paint, Tvg_Stroke_Join* join)
{
if (!paint || !join) return TVG_RESULT_INVALID_ARGUMENT;
*join = (Tvg_Stroke_Join) reinterpret_cast<Shape*>(CCP(paint))->strokeJoin();
return TVG_RESULT_SUCCESS;
}
TVG_EXPORT Tvg_Result tvg_shape_set_fill_color(Tvg_Paint* paint, uint8_t r, uint8_t g, uint8_t b, uint8_t a)
{
if (!paint) return TVG_RESULT_INVALID_ARGUMENT;
return (Tvg_Result) reinterpret_cast<Shape*>(paint)->fill(r, g, b, a);
}
TVG_EXPORT Tvg_Result tvg_shape_get_fill_color(const Tvg_Paint* paint, uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a)
{
if (!paint) return TVG_RESULT_INVALID_ARGUMENT;
return (Tvg_Result) reinterpret_cast<Shape*>(CCP(paint))->fillColor(r, g, b, a);
}
TVG_EXPORT Tvg_Result tvg_shape_set_fill_rule(Tvg_Paint* paint, Tvg_Fill_Rule rule)
{
if (!paint) return TVG_RESULT_INVALID_ARGUMENT;
return (Tvg_Result) reinterpret_cast<Shape*>(paint)->fill((FillRule)rule);
}
TVG_EXPORT Tvg_Result tvg_shape_get_fill_rule(const Tvg_Paint* paint, Tvg_Fill_Rule* rule)
{
if (!paint || !rule) return TVG_RESULT_INVALID_ARGUMENT;
*rule = (Tvg_Fill_Rule) reinterpret_cast<Shape*>(CCP(paint))->fillRule();
return TVG_RESULT_SUCCESS;
}
TVG_EXPORT Tvg_Result tvg_shape_set_linear_gradient(Tvg_Paint* paint, Tvg_Gradient* gradient)
{
if (!paint) return TVG_RESULT_INVALID_ARGUMENT;
return (Tvg_Result) reinterpret_cast<Shape*>(paint)->fill(unique_ptr<LinearGradient>((LinearGradient*)(gradient)));
}
TVG_EXPORT Tvg_Result tvg_shape_set_radial_gradient(Tvg_Paint* paint, Tvg_Gradient* gradient)
{
if (!paint) return TVG_RESULT_INVALID_ARGUMENT;
return (Tvg_Result) reinterpret_cast<Shape*>(paint)->fill(unique_ptr<RadialGradient>((RadialGradient*)(gradient)));
}
TVG_EXPORT Tvg_Result tvg_shape_get_gradient(const Tvg_Paint* paint, Tvg_Gradient** gradient)
{
if (!paint || !gradient) return TVG_RESULT_INVALID_ARGUMENT;
*gradient = (Tvg_Gradient*)(reinterpret_cast<Shape*>(CCP(paint))->fill());
return TVG_RESULT_SUCCESS;
}
/************************************************************************/
/* Picture API */
/************************************************************************/
TVG_EXPORT Tvg_Paint* tvg_picture_new()
{
return (Tvg_Paint*) Picture::gen().release();
}
TVG_EXPORT Tvg_Result tvg_picture_load(Tvg_Paint* paint, const char* path)
{
if (!paint) return TVG_RESULT_INVALID_ARGUMENT;
return (Tvg_Result) reinterpret_cast<Picture*>(paint)->load(path);
}
TVG_EXPORT Tvg_Result tvg_picture_load_raw(Tvg_Paint* paint, uint32_t *data, uint32_t w, uint32_t h, bool copy)
{
if (!paint) return TVG_RESULT_INVALID_ARGUMENT;
return (Tvg_Result) reinterpret_cast<Picture*>(paint)->load(data, w, h, copy);
}
TVG_EXPORT Tvg_Result tvg_picture_load_data(Tvg_Paint* paint, const char *data, uint32_t size, const char *mimetype, bool copy)
{
if (!paint) return TVG_RESULT_INVALID_ARGUMENT;
return (Tvg_Result) reinterpret_cast<Picture*>(paint)->load(data, size, mimetype ? mimetype : "", copy);
}
TVG_EXPORT Tvg_Result tvg_picture_get_size(const Tvg_Paint* paint, float* w, float* h)
{
if (!paint) return TVG_RESULT_INVALID_ARGUMENT;
return (Tvg_Result) reinterpret_cast<Picture*>(CCP(paint))->size(w, h);
}
TVG_EXPORT Tvg_Result tvg_picture_get_viewbox(const Tvg_Paint* paint, float* x, float* y, float* w, float* h)
{
if (!paint) return TVG_RESULT_INVALID_ARGUMENT;
return (Tvg_Result) reinterpret_cast<Picture*>(CCP(paint))->viewbox(x, y, w, h);
}
/************************************************************************/
/* Gradient API */
/************************************************************************/
TVG_EXPORT Tvg_Gradient* tvg_linear_gradient_new()
{
return (Tvg_Gradient*)LinearGradient::gen().release();
}
TVG_EXPORT Tvg_Gradient* tvg_radial_gradient_new()
{
return (Tvg_Gradient*)RadialGradient::gen().release();
}
TVG_EXPORT Tvg_Result tvg_gradient_del(Tvg_Gradient* grad)
{
if (!grad) return TVG_RESULT_INVALID_ARGUMENT;
delete(reinterpret_cast<Fill*>(grad));
return TVG_RESULT_SUCCESS;
}
TVG_EXPORT Tvg_Result tvg_linear_gradient_set(Tvg_Gradient* grad, float x1, float y1, float x2, float y2)
{
if (!grad) return TVG_RESULT_INVALID_ARGUMENT;
return (Tvg_Result) reinterpret_cast<LinearGradient*>(grad)->linear(x1, y1, x2, y2);
}
TVG_EXPORT Tvg_Result tvg_linear_gradient_get(Tvg_Gradient* grad, float* x1, float* y1, float* x2, float* y2)
{
if (!grad) return TVG_RESULT_INVALID_ARGUMENT;
return (Tvg_Result) reinterpret_cast<LinearGradient*>(grad)->linear(x1, y1, x2, y2);
}
TVG_EXPORT Tvg_Result tvg_radial_gradient_set(Tvg_Gradient* grad, float cx, float cy, float radius)
{
if (!grad) return TVG_RESULT_INVALID_ARGUMENT;
return (Tvg_Result) reinterpret_cast<RadialGradient*>(grad)->radial(cx, cy, radius);
}
TVG_EXPORT Tvg_Result tvg_radial_gradient_get(Tvg_Gradient* grad, float* cx, float* cy, float* radius)
{
if (!grad) return TVG_RESULT_INVALID_ARGUMENT;
return (Tvg_Result) reinterpret_cast<RadialGradient*>(grad)->radial(cx, cy, radius);
}
TVG_EXPORT Tvg_Result tvg_gradient_set_color_stops(Tvg_Gradient* grad, const Tvg_Color_Stop* color_stop, uint32_t cnt)
{
if (!grad) return TVG_RESULT_INVALID_ARGUMENT;
return (Tvg_Result) reinterpret_cast<Fill*>(grad)->colorStops(reinterpret_cast<const Fill::ColorStop*>(color_stop), cnt);
}
TVG_EXPORT Tvg_Result tvg_gradient_get_color_stops(Tvg_Gradient* grad, const Tvg_Color_Stop** color_stop, uint32_t* cnt)
{
if (!grad || !color_stop || !cnt) return TVG_RESULT_INVALID_ARGUMENT;
*cnt = reinterpret_cast<Fill*>(grad)->colorStops(reinterpret_cast<const Fill::ColorStop**>(color_stop));
return TVG_RESULT_SUCCESS;
}
TVG_EXPORT Tvg_Result tvg_gradient_set_spread(Tvg_Gradient* grad, const Tvg_Stroke_Fill spread)
{
if (!grad) return TVG_RESULT_INVALID_ARGUMENT;
return (Tvg_Result) reinterpret_cast<Fill*>(grad)->spread((FillSpread)spread);
}
TVG_EXPORT Tvg_Result tvg_gradient_get_spread(Tvg_Gradient* grad, Tvg_Stroke_Fill* spread)
{
if (!grad || !spread) return TVG_RESULT_INVALID_ARGUMENT;
*spread = (Tvg_Stroke_Fill) reinterpret_cast<Fill*>(grad)->spread();
return TVG_RESULT_SUCCESS;
}
TVG_EXPORT Tvg_Paint* tvg_scene_new()
{
return (Tvg_Paint*) Scene::gen().release();
}
TVG_EXPORT Tvg_Result tvg_scene_reserve(Tvg_Paint* scene, uint32_t size)
{
if (!scene) return TVG_RESULT_INVALID_ARGUMENT;
return (Tvg_Result) reinterpret_cast<Scene*>(scene)->reserve(size);
}
TVG_EXPORT Tvg_Result tvg_scene_push(Tvg_Paint* scene, Tvg_Paint* paint)
{
if (!scene || !paint) return TVG_RESULT_INVALID_ARGUMENT;
return (Tvg_Result) reinterpret_cast<Scene*>(scene)->push(unique_ptr<Paint>((Paint*)paint));
}
TVG_EXPORT Tvg_Result tvg_scene_clear(Tvg_Paint* scene, bool free)
{
if (!scene) return TVG_RESULT_INVALID_ARGUMENT;
return (Tvg_Result) reinterpret_cast<Scene*>(scene)->clear(free);
}
#ifdef __cplusplus
}
#endif
|
//
// Copyright 2019 Autodesk
//
// 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 "UsdAttribute.h"
#include "private/Utils.h"
#include <mayaUsd/ufe/StagesSubject.h>
#include <mayaUsd/ufe/Utils.h>
#include <mayaUsd/undo/UsdUndoBlock.h>
#include <mayaUsd/undo/UsdUndoableItem.h>
#include <pxr/base/tf/token.h>
#include <pxr/base/vt/value.h>
#include <pxr/pxr.h>
#include <pxr/usd/sdf/attributeSpec.h>
#include <pxr/usd/usd/schemaRegistry.h>
#include <sstream>
#include <unordered_map>
#include <unordered_set>
// Note: normally we would use this using directive, but here we cannot because
// our class is called UsdAttribute which is exactly the same as the one
// in USD.
// PXR_NAMESPACE_USING_DIRECTIVE
static constexpr char kErrorMsgFailedConvertToString[]
= "Could not convert the attribute to a string";
static constexpr char kErrorMsgInvalidType[]
= "USD attribute does not match created attribute class type";
//------------------------------------------------------------------------------
// Helper functions
//------------------------------------------------------------------------------
namespace {
template <typename T> bool setUsdAttr(const PXR_NS::UsdAttribute& attr, const T& value)
{
// USD Attribute Notification doubling problem:
// As of 24-Nov-2019, calling Set() on a UsdAttribute causes two "info only"
// change notifications to be sent (see StagesSubject::stageChanged). With
// the current USD implementation (USD 19.11), UsdAttribute::Set() ends up
// in UsdStage::_SetValueImpl(). This function calls in sequence:
// - UsdStage::_CreateAttributeSpecForEditing(), which has an SdfChangeBlock
// whose expiry causes a notification to be sent.
// - SdfLayer::SetField(), which also has an SdfChangeBlock whose
// expiry causes a notification to be sent.
// These two calls appear to be made on all calls to UsdAttribute::Set(),
// not just on the first call.
//
// Trying to wrap the call to UsdAttribute::Set() inside an additional
// SdfChangeBlock fails: no notifications are sent at all. This is most
// likely because of the warning given in the SdfChangeBlock documentation:
//
// https://graphics.pixar.com/usd/docs/api/class_sdf_change_block.html
//
// which stages that "it is not safe to use [...] [a] downstream API [such
// as Usd] while a changeblock is open [...]".
//
// Therefore, we have implemented an attribute change block notification of
// our own in the StagesSubject, which we invoke here, so that only a
// single UFE attribute changed notification is generated.
if (!attr.IsValid())
return false;
MayaUsd::ufe::AttributeChangedNotificationGuard guard;
std::string errMsg;
bool isSetAttrAllowed = MayaUsd::ufe::isAttributeEditAllowed(attr, &errMsg);
if (!isSetAttrAllowed) {
throw std::runtime_error(errMsg);
}
return attr.Set<T>(value);
}
PXR_NS::UsdTimeCode getCurrentTime(const Ufe::SceneItem::Ptr& item)
{
// Attributes with time samples will fail when calling Get with default time code.
// So we'll always use the current time when calling Get. If there are no time
// samples, it will fall-back to the default time code.
return MayaUsd::ufe::getTime(item->path());
}
std::string
getUsdAttributeValueAsString(const PXR_NS::UsdAttribute& attr, const PXR_NS::UsdTimeCode& time)
{
if (!attr.IsValid() || !attr.HasValue())
return std::string();
PXR_NS::VtValue v;
if (attr.Get(&v, time)) {
if (v.CanCast<std::string>()) {
PXR_NS::VtValue v_str = v.Cast<std::string>();
return v_str.Get<std::string>();
}
std::ostringstream os;
os << v;
return os.str();
}
TF_CODING_ERROR(kErrorMsgFailedConvertToString);
return std::string();
}
template <typename T, typename U>
U getUsdAttributeVectorAsUfe(const PXR_NS::UsdAttribute& attr, const PXR_NS::UsdTimeCode& time)
{
if (!attr.IsValid() || !attr.HasValue())
return U();
PXR_NS::VtValue vt;
if (attr.Get(&vt, time) && vt.IsHolding<T>()) {
T gfVec = vt.UncheckedGet<T>();
U ret(gfVec[0], gfVec[1], gfVec[2]);
return ret;
}
return U();
}
template <typename T, typename U>
void setUsdAttributeVectorFromUfe(
PXR_NS::UsdAttribute& attr,
const U& value,
const PXR_NS::UsdTimeCode& time)
{
T vec;
vec.Set(value.x(), value.y(), value.z());
setUsdAttr<T>(attr, vec);
}
template <typename T, typename A = MayaUsd::ufe::TypedUsdAttribute<T>>
class SetUndoableCommand : public Ufe::UndoableCommand
{
public:
SetUndoableCommand(const typename A::Ptr& attr, const T& newValue)
: _attr(attr)
, _newValue(newValue)
{
}
void execute() override
{
MayaUsd::UsdUndoBlock undoBlock(&_undoableItem);
_attr->set(_newValue);
}
void undo() override { _undoableItem.undo(); }
void redo() override { _undoableItem.redo(); }
private:
const typename A::Ptr _attr;
const T _newValue;
MayaUsd::UsdUndoableItem _undoableItem;
};
} // end namespace
namespace MAYAUSD_NS_DEF {
namespace ufe {
//------------------------------------------------------------------------------
// UsdAttribute:
//------------------------------------------------------------------------------
UsdAttribute::UsdAttribute(const UsdSceneItem::Ptr& item, const PXR_NS::UsdAttribute& usdAttr)
: fUsdAttr(usdAttr)
{
fPrim = item->prim();
}
UsdAttribute::~UsdAttribute() { }
bool UsdAttribute::hasValue() const { return fUsdAttr.HasValue(); }
std::string UsdAttribute::name() const
{
// Should be the same as the name we were created with.
return fUsdAttr.GetName().GetString();
}
std::string UsdAttribute::documentation() const { return fUsdAttr.GetDocumentation(); }
std::string UsdAttribute::string(const Ufe::SceneItem::Ptr& item) const
{
return getUsdAttributeValueAsString(fUsdAttr, getCurrentTime(item));
}
//------------------------------------------------------------------------------
// UsdAttributeGeneric:
//------------------------------------------------------------------------------
UsdAttributeGeneric::UsdAttributeGeneric(
const UsdSceneItem::Ptr& item,
const PXR_NS::UsdAttribute& usdAttr)
: Ufe::AttributeGeneric(item)
, UsdAttribute(item, usdAttr)
{
}
/*static*/
UsdAttributeGeneric::Ptr
UsdAttributeGeneric::create(const UsdSceneItem::Ptr& item, const PXR_NS::UsdAttribute& usdAttr)
{
auto attr = std::make_shared<UsdAttributeGeneric>(item, usdAttr);
return attr;
}
//------------------------------------------------------------------------------
// UsdAttributeGeneric - Ufe::AttributeGeneric overrides
//------------------------------------------------------------------------------
std::string UsdAttributeGeneric::nativeType() const
{
return fUsdAttr.GetTypeName().GetType().GetTypeName();
}
//------------------------------------------------------------------------------
// UsdAttributeEnumString:
//------------------------------------------------------------------------------
UsdAttributeEnumString::UsdAttributeEnumString(
const UsdSceneItem::Ptr& item,
const PXR_NS::UsdAttribute& usdAttr)
: Ufe::AttributeEnumString(item)
, UsdAttribute(item, usdAttr)
{
}
/*static*/
UsdAttributeEnumString::Ptr
UsdAttributeEnumString::create(const UsdSceneItem::Ptr& item, const PXR_NS::UsdAttribute& usdAttr)
{
auto attr = std::make_shared<UsdAttributeEnumString>(item, usdAttr);
return attr;
}
//------------------------------------------------------------------------------
// UsdAttributeEnumString - Ufe::AttributeEnumString overrides
//------------------------------------------------------------------------------
std::string UsdAttributeEnumString::get() const
{
PXR_NS::VtValue vt;
if (fUsdAttr.Get(&vt, getCurrentTime(sceneItem())) && vt.IsHolding<TfToken>()) {
TfToken tok = vt.UncheckedGet<TfToken>();
return tok.GetString();
}
return std::string();
}
void UsdAttributeEnumString::set(const std::string& value)
{
PXR_NS::TfToken tok(value);
setUsdAttr<PXR_NS::TfToken>(fUsdAttr, tok);
}
Ufe::UndoableCommand::Ptr UsdAttributeEnumString::setCmd(const std::string& value)
{
auto self = std::dynamic_pointer_cast<UsdAttributeEnumString>(shared_from_this());
if (!TF_VERIFY(self, kErrorMsgInvalidType))
return nullptr;
std::string errMsg;
if (!MayaUsd::ufe::isAttributeEditAllowed(fUsdAttr, &errMsg)) {
MGlobal::displayError(errMsg.c_str());
return nullptr;
}
return std::make_shared<SetUndoableCommand<std::string, UsdAttributeEnumString>>(self, value);
}
Ufe::AttributeEnumString::EnumValues UsdAttributeEnumString::getEnumValues() const
{
PXR_NS::TfToken tk(name());
auto attrDefn = fPrim.GetPrimDefinition().GetSchemaAttributeSpec(tk);
if (attrDefn && attrDefn->HasAllowedTokens()) {
auto tokenArray = attrDefn->GetAllowedTokens();
std::vector<PXR_NS::TfToken> tokenVec(tokenArray.begin(), tokenArray.end());
EnumValues tokens = PXR_NS::TfToStringVector(tokenVec);
return tokens;
}
return EnumValues();
}
//------------------------------------------------------------------------------
// TypedUsdAttribute<T>:
//------------------------------------------------------------------------------
template <typename T>
TypedUsdAttribute<T>::TypedUsdAttribute(
const UsdSceneItem::Ptr& item,
const PXR_NS::UsdAttribute& usdAttr)
: Ufe::TypedAttribute<T>(item)
, UsdAttribute(item, usdAttr)
{
}
template <typename T> Ufe::UndoableCommand::Ptr TypedUsdAttribute<T>::setCmd(const T& value)
{
std::string errMsg;
if (!MayaUsd::ufe::isAttributeEditAllowed(fUsdAttr, &errMsg)) {
MGlobal::displayError(errMsg.c_str());
return nullptr;
}
// See
// https://stackoverflow.com/questions/17853212/using-shared-from-this-in-templated-classes
// for explanation of this->shared_from_this() in templated class.
return std::make_shared<SetUndoableCommand<T>>(this->shared_from_this(), value);
}
//------------------------------------------------------------------------------
// TypedUsdAttribute<T> - Ufe::TypedAttribute overrides
//------------------------------------------------------------------------------
template <> std::string TypedUsdAttribute<std::string>::get() const
{
if (!hasValue())
return std::string();
PXR_NS::VtValue vt;
if (fUsdAttr.Get(&vt, getCurrentTime(sceneItem()))) {
// The USDAttribute can be holding either TfToken or string.
if (vt.IsHolding<TfToken>()) {
TfToken tok = vt.UncheckedGet<TfToken>();
return tok.GetString();
} else if (vt.IsHolding<std::string>()) {
return vt.UncheckedGet<std::string>();
}
}
return std::string();
}
template <> void TypedUsdAttribute<std::string>::set(const std::string& value)
{
// We need to figure out if the USDAttribute is holding a TfToken or string.
const PXR_NS::SdfValueTypeName typeName = fUsdAttr.GetTypeName();
if (typeName.GetHash() == SdfValueTypeNames->String.GetHash()) {
setUsdAttr<std::string>(fUsdAttr, value);
return;
} else if (typeName.GetHash() == SdfValueTypeNames->Token.GetHash()) {
PXR_NS::TfToken tok(value);
setUsdAttr<PXR_NS::TfToken>(fUsdAttr, tok);
return;
}
// If we get here it means the USDAttribute type wasn't TfToken or string.
TF_CODING_ERROR(kErrorMsgInvalidType);
}
template <> Ufe::Color3f TypedUsdAttribute<Ufe::Color3f>::get() const
{
return getUsdAttributeVectorAsUfe<GfVec3f, Ufe::Color3f>(fUsdAttr, getCurrentTime(sceneItem()));
}
// Note: cannot use setUsdAttributeVectorFromUfe since it relies on x/y/z
template <> void TypedUsdAttribute<Ufe::Color3f>::set(const Ufe::Color3f& value)
{
GfVec3f vec;
vec.Set(value.r(), value.g(), value.b());
setUsdAttr<GfVec3f>(fUsdAttr, vec);
}
template <> Ufe::Vector3i TypedUsdAttribute<Ufe::Vector3i>::get() const
{
return getUsdAttributeVectorAsUfe<GfVec3i, Ufe::Vector3i>(
fUsdAttr, getCurrentTime(sceneItem()));
}
template <> void TypedUsdAttribute<Ufe::Vector3i>::set(const Ufe::Vector3i& value)
{
setUsdAttributeVectorFromUfe<GfVec3i, Ufe::Vector3i>(
fUsdAttr, value, getCurrentTime(sceneItem()));
}
template <> Ufe::Vector3f TypedUsdAttribute<Ufe::Vector3f>::get() const
{
return getUsdAttributeVectorAsUfe<GfVec3f, Ufe::Vector3f>(
fUsdAttr, getCurrentTime(sceneItem()));
}
template <> void TypedUsdAttribute<Ufe::Vector3f>::set(const Ufe::Vector3f& value)
{
setUsdAttributeVectorFromUfe<GfVec3f, Ufe::Vector3f>(
fUsdAttr, value, getCurrentTime(sceneItem()));
}
template <> Ufe::Vector3d TypedUsdAttribute<Ufe::Vector3d>::get() const
{
return getUsdAttributeVectorAsUfe<GfVec3d, Ufe::Vector3d>(
fUsdAttr, getCurrentTime(sceneItem()));
}
template <> void TypedUsdAttribute<Ufe::Vector3d>::set(const Ufe::Vector3d& value)
{
setUsdAttributeVectorFromUfe<GfVec3d, Ufe::Vector3d>(
fUsdAttr, value, getCurrentTime(sceneItem()));
}
template <typename T> T TypedUsdAttribute<T>::get() const
{
if (!hasValue())
return T();
PXR_NS::VtValue vt;
if (fUsdAttr.Get(&vt, getCurrentTime(Ufe::Attribute::sceneItem())) && vt.IsHolding<T>()) {
return vt.UncheckedGet<T>();
}
return T();
}
template <typename T> void TypedUsdAttribute<T>::set(const T& value)
{
setUsdAttr<T>(fUsdAttr, value);
}
//------------------------------------------------------------------------------
// UsdAttributeBool:
//------------------------------------------------------------------------------
/*static*/
UsdAttributeBool::Ptr
UsdAttributeBool::create(const UsdSceneItem::Ptr& item, const PXR_NS::UsdAttribute& usdAttr)
{
auto attr = std::make_shared<UsdAttributeBool>(item, usdAttr);
return attr;
}
//------------------------------------------------------------------------------
// UsdAttributeInt:
//------------------------------------------------------------------------------
/*static*/
UsdAttributeInt::Ptr
UsdAttributeInt::create(const UsdSceneItem::Ptr& item, const PXR_NS::UsdAttribute& usdAttr)
{
auto attr = std::make_shared<UsdAttributeInt>(item, usdAttr);
return attr;
}
//------------------------------------------------------------------------------
// UsdAttributeFloat:
//------------------------------------------------------------------------------
/*static*/
UsdAttributeFloat::Ptr
UsdAttributeFloat::create(const UsdSceneItem::Ptr& item, const PXR_NS::UsdAttribute& usdAttr)
{
auto attr = std::make_shared<UsdAttributeFloat>(item, usdAttr);
return attr;
}
//------------------------------------------------------------------------------
// UsdAttributeDouble:
//------------------------------------------------------------------------------
/*static*/
UsdAttributeDouble::Ptr
UsdAttributeDouble::create(const UsdSceneItem::Ptr& item, const PXR_NS::UsdAttribute& usdAttr)
{
auto attr = std::make_shared<UsdAttributeDouble>(item, usdAttr);
return attr;
}
//------------------------------------------------------------------------------
// UsdAttributeString:
//------------------------------------------------------------------------------
/*static*/
UsdAttributeString::Ptr
UsdAttributeString::create(const UsdSceneItem::Ptr& item, const PXR_NS::UsdAttribute& usdAttr)
{
auto attr = std::make_shared<UsdAttributeString>(item, usdAttr);
return attr;
}
//------------------------------------------------------------------------------
// UsdAttributeColorFloat3:
//------------------------------------------------------------------------------
/*static*/
UsdAttributeColorFloat3::Ptr
UsdAttributeColorFloat3::create(const UsdSceneItem::Ptr& item, const PXR_NS::UsdAttribute& usdAttr)
{
auto attr = std::make_shared<UsdAttributeColorFloat3>(item, usdAttr);
return attr;
}
//------------------------------------------------------------------------------
// UsdAttributeInt3:
//------------------------------------------------------------------------------
/*static*/
UsdAttributeInt3::Ptr
UsdAttributeInt3::create(const UsdSceneItem::Ptr& item, const PXR_NS::UsdAttribute& usdAttr)
{
auto attr = std::make_shared<UsdAttributeInt3>(item, usdAttr);
return attr;
}
//------------------------------------------------------------------------------
// UsdAttributeFloat3:
//------------------------------------------------------------------------------
/*static*/
UsdAttributeFloat3::Ptr
UsdAttributeFloat3::create(const UsdSceneItem::Ptr& item, const PXR_NS::UsdAttribute& usdAttr)
{
auto attr = std::make_shared<UsdAttributeFloat3>(item, usdAttr);
return attr;
}
//------------------------------------------------------------------------------
// UsdAttributeDouble3:
//------------------------------------------------------------------------------
/*static*/
UsdAttributeDouble3::Ptr
UsdAttributeDouble3::create(const UsdSceneItem::Ptr& item, const PXR_NS::UsdAttribute& usdAttr)
{
auto attr = std::make_shared<UsdAttributeDouble3>(item, usdAttr);
return attr;
}
#if 0
// Note: if we were to implement generic attribute setting (via string) this
// would be the way it could be done.
bool UsdAttribute::setValue(const std::string& value)
{
// Put the input string into a VtValue so we can cast it to the proper type.
PXR_NS::VtValue val(value.c_str());
// Attempt to cast the value to what we want. Get a default value for this
// attribute's type name.
PXR_NS::VtValue defVal = fUsdAttr.GetTypeName().GetDefaultValue();
// Attempt to cast the given string to the default value's type.
// If casting fails, attempt to continue with the given value.
PXR_NS::VtValue cast = PXR_NS::VtValue::CastToTypeOf(val, defVal);
if (!cast.IsEmpty())
cast.Swap(val);
return setUsdAttr<PXR_NS::VtValue>(fUsdAttr, val);
}
#endif
} // namespace ufe
} // namespace MAYAUSD_NS_DEF
|
; A055236: Sums of two powers of 4.
; 2,5,8,17,20,32,65,68,80,128,257,260,272,320,512,1025,1028,1040,1088,1280,2048,4097,4100,4112,4160,4352,5120,8192,16385,16388,16400,16448,16640,17408,20480,32768,65537,65540,65552,65600,65792,66560,69632,81920,131072,262145,262148,262160,262208,262400,263168,266240,278528,327680,524288,1048577,1048580,1048592,1048640,1048832,1049600,1052672,1064960,1114112,1310720,2097152,4194305,4194308,4194320,4194368,4194560,4195328,4198400,4210688,4259840,4456448,5242880,8388608,16777217,16777220,16777232
seq $0,131437 ; (A000012 * A131436) + (A131436 * A000012) - A000012.
mul $0,2
seq $0,32925 ; Numbers whose set of base-4 digits is {1,2}.
div $0,16
mul $0,3
add $0,2
|
;
; Copyright (C) 1996-2006 by Narech K. All rights reserved.
;
; Redistribution and use in source and binary forms, with or without
; modification, are permitted provided that the following conditions are
; met:
;
; 1. Redistributions of source code must retain the above copyright
; notice, this list of conditions and the following disclaimer.
;
; 2. Redistributions in binary form must reproduce the above copyright
; notice, this list of conditions and the following disclaimer in the
; documentation and/or other materials provided with the distribution.
;
; 3. The end-user documentation included with the redistribution, if any,
; must include the following acknowledgment:
;
; "This product uses DOS/32 Advanced DOS Extender technology."
;
; Alternately, this acknowledgment may appear in the software itself, if
; and wherever such third-party acknowledgments normally appear.
;
; 4. Products derived from this software may not be called "DOS/32A" or
; "DOS/32 Advanced".
;
; THIS SOFTWARE AND DOCUMENTATION IS PROVIDED "AS IS" AND ANY EXPRESSED
; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
; DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
; LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
; BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
; OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
; ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
;
;
PushState
.8086
;=============================================================================
; Get default configuration from _ID32 segment (buried in the program)
; and configure the both KERNEL and CLIENT
;
get_default_config:
push ds es
mov ax,_ID32
mov dx,_KERNEL
mov _seg_id32,ax
mov _seg_kernel,dx
push ax dx ; STUB/32C configuration code
mov ax,0FF87h
int 21h
cmp dx,'ID'
jnz @@1
cmp ax,'32'
jnz @@1
mov es,cs:_seg_id32
xor di,di
mov cx,12
rep movsw
mov ds,cs:_seg_ds
or _sys_misc,0001h ; indicate STUB/32C configuration
@@1: pop dx ax
mov ds,ax
mov es,dx
xor si,si ; DS:SI=_ID32:0000
mov di,offs pm32_data ; ES:DI=_KERNEL:PM32_DATA
lodsw ; check for 'ID32' signature
cmp ax,'DI' ; if not present, skip confuguration
jnz @@err
lodsw
cmp ax,'23'
jnz @@err
mov cx,_ID32_SIZE
rep movsb ; copy default config to KERNEL
mov es,cs:_seg_ds
If EXEC_TYPE eq 0
and wptr ds:[si],7FFFh
Else
or wptr ds:[si],8800h
Endif
lodsw ; get DOS/32A config byte
mov wptr es:_misc_byte,ax
lodsw ; get DOS buffer size
mov wptr es:_lowmembuf,ax
lodsw ; get version
mov wptr es:_version,ax
clc
jmp @@done
@@err: stc
@@done: pop es ds
ret
evendata
@area2_db label byte
@area2_dw label word
@area2_dd label dword
;=============================================================================
; Get environment configuration from the environment segment (at PSP:002C)
; and configure both KERNEL and DOS/32A
;
get_environ_config:
push ds es
jc @@done
test _misc_byte2,00000001b
jz @@done
mov es,_seg_env
xor di,di ; ES:DI=envirment
mov cx,-1 ; environment size, unlimited
xor ax,ax
@@0: push cx
mov cx,7 ; CX =length of 'DOS32A=' string
mov si,offs dos_str ; DS:SI=offset of 'DOS32A=' string
repe cmpsb
pop cx
jz @@1 ; quit loop if found
repne scasb
cmp al,es:[di] ; check for end of environment
jnz @@0 ; loop until found or end of environ.
jmp @@done ; no string found, exit
@@1: call skip_env_spaces ; skip any leading spaces
cmp bptr es:[di],0 ; if at the end of the line, exit
jz @@done ; (actually, just in case)
call get_env_word ; get word and configure
call skip_env_nonspaces ; skip anything else until space or 0
cmp bptr es:[di],0
jnz @@1
@@done: pop es ds
ret
get_env_word:
xor bx,bx ; BX=pointer to next argument in tab
@@0: mov si,dfn_tab[bx] ; DS:SI=string offset
cmp si,-1 ; check if at end of arg. list
jz @@1 ; if yes, terminate search
mov cx,dfn_tab[bx+2] ; CX=get string length
push di
repe cmpsb ; compare strings
pop di
jz @@2 ; if equ, process argument
add bx,6 ; loop until done
jmp @@0
@@1: ret
@@2: add di,dfn_tab[bx+2] ; adjust env pointer by string length
jmp cs:dfn_tab[bx-2+6] ; goto appropriate argument handler
skip_env_spaces:
@@1: mov al,es:[di]
test al,al
jz @@3
cmp al,'/'
jz @@2
cmp al,20h
jnz @@3
inc di
jmp @@1
@@2: inc di
@@3: ret
skip_env_nonspaces:
@@1: mov al,es:[di]
test al,al
jz @@3
cmp al,'/'
jz @@2
cmp al,20h
jz @@3
inc di
jmp @@1
@@2: inc di
@@3: ret
;=============================================================================
; Get switch in AX: 0, 1, ON, OFF (CF=1 if not found)
;
get_env_swc:
cmp bptr es:[di],':' ; skip ':' if present
jne @@1
inc di
@@1: xor ax,ax ; if '0', return(0)
cmp bptr es:[di],'0' ; check for '0'=OFF
jz @@x1
inc ax ; if '1', return(1)
cmp bptr es:[di],'1' ; check for '1'=ON
jz @@x1
cmp wptr es:[di],'NO' ; check for 'ON'
jz @@x2
dec ax
cmp wptr es:[di],'FO' ; check for 'OF'(F)
jnz @@x0
cmp bptr es:[di+2],'F' ; check for (OF)'F'
jz @@x3
@@x0: stc
ret
@@x3: inc di
@@x2: inc di
@@x1: inc di
test al,al
ret
;=============================================================================
; Get number in AX: 0<=N(dec)<=65535 (CF=1 if not found)
;
get_env_num:
cmp bptr es:[di],':' ; skip ':' if present
jne @@1
inc di
@@1: xor ax,ax
xor bx,bx
mov cx,10
mov al,es:[di]
sub al,'0'
jb @@exit
cmp al,9
ja @@exit
xchg bx,ax
mul cx
xchg bx,ax
add bx,ax
@@2: inc di
xor ax,ax
mov al,es:[di]
sub al,'0'
jb @@done
cmp al,9
ja @@done
xchg bx,ax
mul cx
xchg bx,ax
add bx,ax
jmp @@2
@@done: mov ax,bx
clc
ret
@@exit: stc
ret
;=============================================================================
; /QUIET
;
cfg_env_quiet:
If EXEC_TYPE eq 0
and wptr _misc_byte,1111011111111100b
Else
and wptr _misc_byte,1111111111111100b
Endif
ret
;=============================================================================
; /PRINT:ON|OFF
;
cfg_env_print:
call get_env_swc
jc @@0
jz @@1
or wptr _misc_byte,0000100000000001b
ret
@@1: and wptr _misc_byte,1111011111111110b
@@0: ret
;=============================================================================
; SOUND:ON|OFF
;
cfg_env_sound:
call get_env_swc
jc @@0
jz @@1
or _misc_byte,00000010b
ret
@@1: and _misc_byte,11111101b
@@0: ret
;=============================================================================
; /EXTMEM:nnnn (KB)
;
cfg_env_extmem:
call get_env_num
jc @@0
push ds
mov ds,_seg_kernel
assume ds:_KERNEL
push ax
mov bx,1024 ; make AX (Kb)-> DX:AX (bytes)
mul bx ; DX:AX= bytes
mov wptr ds:[pm32_data+12],ax ; set ext mem requirements
mov wptr ds:[pm32_data+14],dx
pop ax
add ax,00FFFh
and ax,0F000h
xor dx,dx
mov bx,1000h ; BX=Page size in KB
div bx ; MEM KB / Page Size KB
test al,al
jnz @@1 ; must alloc at least one
inc al
@@1: mov bptr ds:[pm32_data+1],al ; set max allowed pagetables
assume ds:_TEXT16
pop ds
@@0: ret
;=============================================================================
; /DOSBUF:nnnn (KB)
;
cfg_env_dosbuf:
call get_env_num
cmp ax,1 ; 1KB < ax < 64KB
jb @@0
cmp ax,64
ja @@0
jnz @@2
mov ax,0FFFh
jmp @@1
@@2: mov cl,6
shl ax,cl ; convert KB to para
@@1: mov _lowmembuf,ax
@@0: ret
;=============================================================================
; /DPMITST:ON|OFF
;
cfg_env_test:
call get_env_swc
; jc @@0
; push ds
; mov ds,_seg_kernel
; assume ds:_KERNEL
; jz @@1
; or bptr ds:pm32_data[0],00000001b
; pop ds
; ret
;@@1: and bptr ds:pm32_data[0],11111110b
; assume ds:_TEXT16
; pop ds
@@0: ret
;=============================================================================
; /RESTORE:ON|OFF
;
cfg_env_restore:
call get_env_swc
jc @@0
jz @@1
or _misc_byte,00000100b
ret
@@1: and _misc_byte,11111011b
@@0: ret
;=============================================================================
; /NULLP[:ON|OFF]
;
cfg_env_nullp:
call get_env_swc
jc @@0
jz @@1
@@0: or _misc_byte,10000000b
ret
@@1: and _misc_byte,01111111b
ret
;=============================================================================
; /VERBOSE[:ON:OFF]
;
cfg_env_verbose:
call get_env_swc
jc @@0
jz @@1
@@0: or _misc_byte2,00010000b
ret
@@1: and _misc_byte2,11101111b
ret
;=============================================================================
; /NOWARN:nnnn
;
cfg_env_nowarn:
call get_env_num
sub ax,9000
jb @@0
cmp al,6
ja @@0
add ax,ax
mov bx,ax
mov wptr errtab_90xx[bx],0
cmp bptr es:[di],','
jnz @@0
inc di
jmp cfg_env_nowarn
@@0: ret
;=============================================================================
; /NOC
;
cfg_env_noc:
and bptr _misc_byte2,11110111b
ret
PopState
|
; ---------------------------------------------------------------------------
; Animation script - lava balls
; ---------------------------------------------------------------------------
dc.w byte_E4CC-Ani_obj14
dc.w byte_E4D2-Ani_obj14
dc.w byte_E4D6-Ani_obj14
dc.w byte_E4DC-Ani_obj14
byte_E4CC: dc.b 5, 0, $20, 1, $21, $FF
byte_E4D2: dc.b 5, 2, $FC, 0
byte_E4D6: dc.b 5, 3, $43, 4, $44, $FF
byte_E4DC: dc.b 5, 5, $FC, 0
even |
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
//
// File: clsload.hpp
//
//
//
// ============================================================================
#ifndef _H_CLSLOAD
#define _H_CLSLOAD
#include "crst.h"
#include "eehash.h"
#include "vars.hpp"
#include "stubmgr.h"
#include "typehandle.h"
#include "object.h" // only needed for def. of PTRARRAYREF
#include "classloadlevel.h"
#include "specstrings.h"
#include "simplerwlock.hpp"
#include "classhash.h"
// SystemDomain is a friend of ClassLoader.
class SystemDomain;
class Assembly;
class ClassLoader;
class TypeKey;
class PendingTypeLoadEntry;
class PendingTypeLoadTable;
class EEClass;
class Thread;
class EETypeHashTable;
class DynamicResolver;
class SigPointer;
// Hash table parameter for unresolved class hash
#define UNRESOLVED_CLASS_HASH_BUCKETS 8
// This is information required to look up a type in the loader. Besides the
// basic name there is the meta data information for the type, whether the
// the name is case sensitive, and tokens not to load. This last item allows
// the loader to prevent a type from being recursively loaded.
typedef enum NameHandleTable
{
nhCaseSensitive = 0,
nhCaseInsensitive = 1
} NameHandleTable;
class HashedTypeEntry
{
public:
typedef enum
{
IsNullEntry, // Uninitialized HashedTypeEntry
IsHashedTokenEntry, // Entry is a token value in a R2R hashtable in from the R2R module
IsHashedClassEntry // Entry is a EEClassHashEntry_t from the hashtable constructed at
// module load time (or from the hashtable loaded from the native image)
} EntryType;
typedef struct
{
mdToken m_TypeToken;
Module * m_pModule;
} TokenTypeEntry;
private:
EntryType m_EntryType;
PTR_EEClassHashEntry m_pClassHashEntry;
TokenTypeEntry m_TokenAndModulePair;
public:
HashedTypeEntry()
{
m_EntryType = EntryType::IsNullEntry;
m_pClassHashEntry = PTR_NULL;
}
EntryType GetEntryType() const { return m_EntryType; }
bool IsNull() const { return m_EntryType == EntryType::IsNullEntry; }
const HashedTypeEntry& SetClassHashBasedEntryValue(EEClassHashEntry_t * pClassHashEntry)
{
LIMITED_METHOD_CONTRACT;
m_EntryType = EntryType::IsHashedClassEntry;
m_pClassHashEntry = dac_cast<PTR_EEClassHashEntry>(pClassHashEntry);
return *this;
}
EEClassHashEntry_t * GetClassHashBasedEntryValue() const
{
LIMITED_METHOD_CONTRACT;
_ASSERT(m_EntryType == EntryType::IsHashedClassEntry);
return m_pClassHashEntry;
}
const HashedTypeEntry& SetTokenBasedEntryValue(mdTypeDef typeToken, Module * pModule)
{
LIMITED_METHOD_CONTRACT;
m_EntryType = EntryType::IsHashedTokenEntry;
m_TokenAndModulePair.m_TypeToken = typeToken;
m_TokenAndModulePair.m_pModule = pModule;
return *this;
}
const TokenTypeEntry& GetTokenBasedEntryValue() const
{
LIMITED_METHOD_CONTRACT;
_ASSERT(m_EntryType == EntryType::IsHashedTokenEntry);
return m_TokenAndModulePair;
}
};
class NameHandle
{
friend class ClassLoader;
LPCUTF8 m_nameSpace;
LPCUTF8 m_name;
PTR_Module m_pTypeScope;
mdToken m_mdType;
mdToken m_mdTokenNotToLoad;
NameHandleTable m_WhichTable;
HashedTypeEntry m_Bucket;
public:
NameHandle()
{
LIMITED_METHOD_CONTRACT;
memset((void*) this, NULL, sizeof(*this));
}
NameHandle(LPCUTF8 name) :
m_nameSpace(NULL),
m_name(name),
m_pTypeScope(PTR_NULL),
m_mdType(mdTokenNil),
m_mdTokenNotToLoad(tdNoTypes),
m_WhichTable(nhCaseSensitive),
m_Bucket()
{
LIMITED_METHOD_CONTRACT;
}
NameHandle(LPCUTF8 nameSpace, LPCUTF8 name) :
m_nameSpace(nameSpace),
m_name(name),
m_pTypeScope(PTR_NULL),
m_mdType(mdTokenNil),
m_mdTokenNotToLoad(tdNoTypes),
m_WhichTable(nhCaseSensitive),
m_Bucket()
{
LIMITED_METHOD_CONTRACT;
SUPPORTS_DAC;
}
NameHandle(Module* pModule, mdToken token) :
m_nameSpace(NULL),
m_name(NULL),
m_pTypeScope(pModule),
m_mdType(token),
m_mdTokenNotToLoad(tdNoTypes),
m_WhichTable(nhCaseSensitive),
m_Bucket()
{
LIMITED_METHOD_CONTRACT;
SUPPORTS_DAC;
}
NameHandle(const NameHandle & p)
{
LIMITED_METHOD_CONTRACT;
SUPPORTS_DAC;
m_nameSpace = p.m_nameSpace;
m_name = p.m_name;
m_pTypeScope = p.m_pTypeScope;
m_mdType = p.m_mdType;
m_mdTokenNotToLoad = p.m_mdTokenNotToLoad;
m_WhichTable = p.m_WhichTable;
m_Bucket = p.m_Bucket;
}
void SetName(LPCUTF8 pName)
{
LIMITED_METHOD_CONTRACT;
m_name = pName;
}
void SetName(LPCUTF8 pNameSpace, LPCUTF8 pName)
{
LIMITED_METHOD_CONTRACT;
SUPPORTS_DAC_HOST_ONLY;
m_nameSpace = pNameSpace;
m_name = pName;
}
LPCUTF8 GetName() const
{
LIMITED_METHOD_CONTRACT;
SUPPORTS_DAC;
return m_name;
}
LPCUTF8 GetNameSpace() const
{
LIMITED_METHOD_CONTRACT;
SUPPORTS_DAC;
return m_nameSpace;
}
void SetTypeToken(Module* pModule, mdToken mdToken)
{
LIMITED_METHOD_CONTRACT;
m_pTypeScope = dac_cast<PTR_Module>(pModule);
m_mdType = mdToken;
}
PTR_Module GetTypeModule() const
{
LIMITED_METHOD_CONTRACT;
SUPPORTS_DAC;
return m_pTypeScope;
}
mdToken GetTypeToken() const
{
LIMITED_METHOD_CONTRACT;
SUPPORTS_DAC;
return m_mdType;
}
void SetTokenNotToLoad(mdToken mdtok)
{
LIMITED_METHOD_CONTRACT;
SUPPORTS_DAC; // "this" must be a host address
m_mdTokenNotToLoad = mdtok;
}
mdToken GetTokenNotToLoad() const
{
LIMITED_METHOD_CONTRACT;
SUPPORTS_DAC;
return m_mdTokenNotToLoad;
}
void SetCaseInsensitive()
{
LIMITED_METHOD_CONTRACT;
m_WhichTable = nhCaseInsensitive;
}
NameHandleTable GetTable() const
{
LIMITED_METHOD_CONTRACT;
SUPPORTS_DAC;
return m_WhichTable;
}
void SetBucket(const HashedTypeEntry& bucket)
{
LIMITED_METHOD_CONTRACT;
SUPPORTS_DAC; // "this" must be a host address
m_Bucket = bucket;
}
const HashedTypeEntry& GetBucket() const
{
LIMITED_METHOD_CONTRACT;
SUPPORTS_DAC;
return m_Bucket;
}
static BOOL OKToLoad(mdToken token, mdToken tokenNotToLoad)
{
LIMITED_METHOD_CONTRACT;
SUPPORTS_DAC;
return (token == 0 || token != tokenNotToLoad) && tokenNotToLoad != tdAllTypes;
}
BOOL OKToLoad() const
{
WRAPPER_NO_CONTRACT;
SUPPORTS_DAC;
return OKToLoad(m_mdType, m_mdTokenNotToLoad);
}
};
//-------------------------------------------------------------------------------------------
//
// Introducing AccessCheckContext so that we can defer caller resolution as much as possible.
// Stack walk is expensive and we should avoid it if we can determine accessibility without
// knowing the caller. For example, public transparent APIs without link demand should always
// be accessible.
// We will have two types of AccessCheckContext.
// 1. StaticAccessCheckContext is used by JIT and other places where the caller is statically known.
// 2. RefSecContext is used by reflection and resolves the caller by performing a stack walk.
//
//-------------------------------------------------------------------------------------------
class AccessCheckContext
{
public:
virtual MethodDesc* GetCallerMethod() = 0; // The method that wants access.
virtual MethodTable* GetCallerMT() = 0; // The class that wants access; NULL if interop caller.
virtual Assembly* GetCallerAssembly() = 0; // Assembly containing that class.
virtual bool IsCalledFromInterop() = 0;
};
class StaticAccessCheckContext : public AccessCheckContext
{
public:
StaticAccessCheckContext(MethodDesc* pCallerMethod, MethodTable* pCallerType, Assembly* pCallerAssembly)
: m_pCallerMethod(pCallerMethod),
m_pCallerMT(pCallerType),
m_pCallerAssembly(pCallerAssembly)
{
CONTRACTL
{
LIMITED_METHOD_CONTRACT;
PRECONDITION(CheckPointer(pCallerMethod, NULL_OK));
PRECONDITION(CheckPointer(pCallerType, NULL_OK));
PRECONDITION(CheckPointer(pCallerAssembly));
}
CONTRACTL_END;
}
StaticAccessCheckContext(MethodDesc* pCallerMethod);
StaticAccessCheckContext(MethodDesc* pCallerMethod, MethodTable* pCallerType);
virtual MethodDesc* GetCallerMethod()
{
LIMITED_METHOD_CONTRACT;
return m_pCallerMethod;
}
virtual MethodTable* GetCallerMT()
{
LIMITED_METHOD_CONTRACT;
return m_pCallerMT;
}
virtual Assembly* GetCallerAssembly()
{
WRAPPER_NO_CONTRACT;
return m_pCallerAssembly;
}
virtual bool IsCalledFromInterop()
{
WRAPPER_NO_CONTRACT;
return false;
}
private:
MethodDesc* m_pCallerMethod;
MethodTable* m_pCallerMT;
Assembly* m_pCallerAssembly;
};
//******************************************************************************
// This type specifies the kind of accessibility checks to perform.
// On failure, it can be configured to either return FALSE or to throw an exception.
class AccessCheckOptions
{
public:
enum AccessCheckType
{
// Used by statically compiled code.
// Desktop: Just do normal accessibility checks. No security demands.
// CoreCLR: Just do normal accessibility checks.
kNormalAccessibilityChecks,
// Used only for resource loading and reflection inovcation when the target is remoted.
// Desktop: If normal accessiblity checks fail, return TRUE if a demand for MemberAccess succeeds
// CoreCLR: If normal accessiblity checks fail, return TRUE if a the caller is Security(Safe)Critical
kMemberAccess,
// Used by Reflection invocation and DynamicMethod with RestrictedSkipVisibility.
// Desktop: If normal accessiblity checks fail, return TRUE if a demand for RestrictedMemberAccess
// and grant set of the target assembly succeeds.
// CoreCLR: If normal accessiblity checks fail, return TRUE if the callee is App transparent code (in a user assembly)
kRestrictedMemberAccess,
// Used by normal DynamicMethods in full trust CoreCLR
// CoreCLR: Do normal visibility checks but bypass transparency checks.
kNormalAccessNoTransparency,
// Used by DynamicMethods with restrictedSkipVisibility in full trust CoreCLR
// CoreCLR: Do RestrictedMemberAcess visibility checks but bypass transparency checks.
kRestrictedMemberAccessNoTransparency,
};
AccessCheckOptions(
AccessCheckType accessCheckType,
DynamicResolver * pAccessContext,
BOOL throwIfTargetIsInaccessible,
MethodTable * pTargetMT);
AccessCheckOptions(
AccessCheckType accessCheckType,
DynamicResolver * pAccessContext,
BOOL throwIfTargetIsInaccessible,
MethodDesc * pTargetMD);
AccessCheckOptions(
AccessCheckType accessCheckType,
DynamicResolver * pAccessContext,
BOOL throwIfTargetIsInaccessible,
FieldDesc * pTargetFD);
AccessCheckOptions(
const AccessCheckOptions & templateAccessCheckOptions,
BOOL throwIfTargetIsInaccessible);
// Follow standard rules for doing accessability
BOOL DoNormalAccessibilityChecks() const
{
LIMITED_METHOD_CONTRACT;
return m_accessCheckType == kNormalAccessibilityChecks;
}
// Do visibility checks including security demands for reflection access to members
BOOL DoReflectionAccessibilityChecks() const
{
WRAPPER_NO_CONTRACT;
return !DoNormalAccessibilityChecks();
}
BOOL Throws() const
{
LIMITED_METHOD_CONTRACT;
return m_fThrowIfTargetIsInaccessible;
}
BOOL DemandMemberAccessOrFail(AccessCheckContext *pContext, MethodTable * pTargetMT, BOOL visibilityCheck) const;
BOOL FailOrThrow(AccessCheckContext *pContext) const;
BOOL TransparencyCheckNeeded() const
{
LIMITED_METHOD_CONTRACT;
return (m_accessCheckType != kNormalAccessNoTransparency && m_accessCheckType != kRestrictedMemberAccessNoTransparency);
}
static AccessCheckOptions* s_pNormalAccessChecks;
static void Startup();
private:
void Initialize(
AccessCheckType accessCheckType,
BOOL throwIfTargetIsInaccessible,
MethodTable * pTargetMT,
MethodDesc * pTargetMD,
FieldDesc * pTargetFD);
BOOL DemandMemberAccess(AccessCheckContext *pContext, MethodTable * pTargetMT, BOOL visibilityCheck) const;
void ThrowAccessException(
AccessCheckContext* pContext,
MethodTable* pFailureMT = NULL,
Exception* pInnerException = NULL) const;
MethodTable * m_pTargetMT;
MethodDesc * m_pTargetMethod;
FieldDesc * m_pTargetField;
AccessCheckType m_accessCheckType;
// The context used to determine if access is allowed. It is the resolver that carries the compressed-stack used to do the Demand.
// If this is NULL, the access is checked against the current call-stack.
// This is non-NULL only for m_accessCheckType==kRestrictedMemberAccess
DynamicResolver * m_pAccessContext;
// If the target is not accessible, should the API return FALSE, or should it throw an exception?
BOOL m_fThrowIfTargetIsInaccessible;
};
void DECLSPEC_NORETURN ThrowFieldAccessException(MethodDesc *pCallerMD,
FieldDesc *pFD,
UINT messageID = 0,
Exception *pInnerException = NULL);
void DECLSPEC_NORETURN ThrowMethodAccessException(MethodDesc *pCallerMD,
MethodDesc *pCalleeMD,
UINT messageID = 0,
Exception *pInnerException = NULL);
void DECLSPEC_NORETURN ThrowTypeAccessException(MethodDesc *pCallerMD,
MethodTable *pMT,
UINT messageID = 0,
Exception *pInnerException = NULL);
void DECLSPEC_NORETURN ThrowFieldAccessException(AccessCheckContext* pContext,
FieldDesc *pFD,
UINT messageID = 0,
Exception *pInnerException = NULL);
void DECLSPEC_NORETURN ThrowMethodAccessException(AccessCheckContext* pContext,
MethodDesc *pCalleeMD,
UINT messageID = 0,
Exception *pInnerException = NULL);
void DECLSPEC_NORETURN ThrowTypeAccessException(AccessCheckContext* pContext,
MethodTable *pMT,
UINT messageID = 0,
Exception *pInnerException = NULL);
//---------------------------------------------------------------------------------------
//
class ClassLoader
{
friend class PendingTypeLoadEntry;
friend class MethodTableBuilder;
friend class AppDomain;
friend class Assembly;
friend class Module;
friend class InstantiatedMethodDesc;
friend class CLRPrivTypeCacheWinRT;
// the following two classes are friends because they will call LoadTypeHandleForTypeKey by token directly
friend class COMDynamicWrite;
friend class COMModule;
private:
// Classes for which load is in progress
PendingTypeLoadTable * m_pUnresolvedClassHash;
CrstExplicitInit m_UnresolvedClassLock;
// Protects addition of elements to module's m_pAvailableClasses.
// (indeed thus protects addition of elements to any m_pAvailableClasses in any
// of the modules managed by this loader)
CrstExplicitInit m_AvailableClassLock;
CrstExplicitInit m_AvailableTypesLock;
// Do we have any modules which need to have their classes added to
// the available list?
Volatile<LONG> m_cUnhashedModules;
// Back reference to the assembly
PTR_Assembly m_pAssembly;
public:
#ifdef _DEBUG
DWORD m_dwDebugMethods;
DWORD m_dwDebugFieldDescs; // Doesn't include anything we don't allocate a FieldDesc for
DWORD m_dwDebugClasses;
DWORD m_dwDebugDuplicateInterfaceSlots;
DWORD m_dwGCSize;
DWORD m_dwInterfaceMapSize;
DWORD m_dwMethodTableSize;
DWORD m_dwVtableData;
DWORD m_dwStaticFieldData;
DWORD m_dwFieldDescData;
DWORD m_dwMethodDescData;
size_t m_dwEEClassData;
#endif
public:
ClassLoader(Assembly *pAssembly);
~ClassLoader();
private:
VOID PopulateAvailableClassHashTable(Module *pModule,
AllocMemTracker *pamTracker);
void LazyPopulateCaseSensitiveHashTablesDontHaveLock();
void LazyPopulateCaseSensitiveHashTables();
void LazyPopulateCaseInsensitiveHashTables();
// Lookup the hash table entry from the hash table
void GetClassValue(NameHandleTable nhTable,
const NameHandle *pName,
HashDatum *pData,
EEClassHashTable **ppTable,
Module* pLookInThisModuleOnly,
HashedTypeEntry* pFoundEntry,
Loader::LoadFlag loadFlag,
BOOL& needsToBuildHashtable);
public:
//#LoaderModule
// LoaderModule determines in which module an item gets placed.
// For everything except paramaterized types and methods the choice is easy.
//
// If NGEN'ing we may choose to place the item into the current module (which is different from runtime behavior).
//
// The rule for determining the loader module must ensure that a type or method never outlives its loader module
// with respect to app-domain unloading
static Module * ComputeLoaderModule(MethodTable * pMT,
mdToken token, // the token of the method
Instantiation methodInst); // the type arguments to the method (if any)
static Module * ComputeLoaderModule(TypeKey * typeKey);
inline static PTR_Module ComputeLoaderModuleForFunctionPointer(TypeHandle * pRetAndArgTypes, DWORD NumArgsPlusRetType);
inline static PTR_Module ComputeLoaderModuleForParamType(TypeHandle paramType);
private:
static PTR_Module ComputeLoaderModuleWorker(Module *pDefinitionModule, // the module that declares the generic type or method
mdToken token,
Instantiation classInst, // the type arguments to the type (if any)
Instantiation methodInst); // the type arguments to the method (if any)
BOOL FindClassModuleThrowing(
const NameHandle * pName,
TypeHandle * pType,
mdToken * pmdClassToken,
Module ** ppModule,
mdToken * pmdFoundExportedType,
HashedTypeEntry * pEntry,
Module * pLookInThisModuleOnly,
Loader::LoadFlag loadFlag);
static PTR_Module ComputeLoaderModuleForCompilation(Module *pDefinitionModule, // the module that declares the generic type or method
mdToken token,
Instantiation classInst, // the type arguments to the type (if any)
Instantiation methodInst); // the type arguments to the method (if any)
public:
void Init(AllocMemTracker *pamTracker);
PTR_Assembly GetAssembly();
DomainAssembly* GetDomainAssembly();
void FreeModules();
#ifdef DACCESS_COMPILE
void EnumMemoryRegions(CLRDataEnumMemoryFlags flags);
#endif
//==================================================================================
// Main entry points to class loader
// Organized as follows:
// by token:
// TypeDef
// TypeDefOrRef
// TypeDefOrRefOrSpec
// by constructed type:
// ArrayType
// PointerOrByrefType
// FnPtrType
// GenericInstantiation
// by name:
// ByName
// Each takes a parameter comes, with the following semantics:
// fLoadTypes=DontLoadTypes: if type isn't already in the loader's table, return NULL
// fLoadTypes=LoadTypes: if type isn't already in the loader's table, then create it
// Each comes in two variants, LoadXThrowing and LoadXNoThrow, the latter being just
// an exception-handling wrapper around the former.
//
// Each also allows types to be loaded only up to a particular level (see classloadlevel.h).
// The class loader itself makes use of these levels to "break" recursion across
// generic instantiations. External clients should leave the parameter at its default
// value (CLASS_LOADED).
//==================================================================================
public:
// We use enums for these flags so that we can easily search the codebase to
// determine where the flags are set to their non-default values.
//
// This enum tells us what to do if the load fails. If ThrowIfNotFound is used
// with a HRESULT-returning NOTHROW function then it actually indicates that
// an error-HRESULT will be returned.
// The ThrowButNullV11McppWorkaround value means ThrowIfNotFound, except when the case
// of a Nil ResolutionScope for a value type (erroneously generated by Everett MCPP
// compiler.)
typedef enum { ThrowIfNotFound, ReturnNullIfNotFound, ThrowButNullV11McppWorkaround } NotFoundAction;
// This flag indicates whether we should accept an uninstantiatednaked TypeDef or TypeRef
// for a generic type definition, where "uninstantiated" means "not used as part of
// a TypeSpec"
typedef enum { FailIfUninstDefOrRef, PermitUninstDefOrRef } PermitUninstantiatedFlag;
// This flag indicates whether we want to "load" the type if it isn't already in the
// loader's tables and has reached the load level desired.
typedef enum { LoadTypes, DontLoadTypes } LoadTypesFlag;
// Load types by token (Def, Ref and Spec)
static TypeHandle LoadTypeDefThrowing(Module *pModule,
mdToken typeDef,
NotFoundAction fNotFound = ThrowIfNotFound,
PermitUninstantiatedFlag fUninstantiated = FailIfUninstDefOrRef,
mdToken tokenNotToLoad = tdNoTypes,
ClassLoadLevel level = CLASS_LOADED,
Instantiation * pTargetInstantiation = NULL /* used to verify arity of the loaded type */);
static TypeHandle LoadTypeDefOrRefThrowing(Module *pModule,
mdToken typeRefOrDef,
NotFoundAction fNotFound = ThrowIfNotFound,
PermitUninstantiatedFlag fUninstantiated = FailIfUninstDefOrRef,
mdToken tokenNotToLoad = tdNoTypes,
ClassLoadLevel level = CLASS_LOADED);
static TypeHandle LoadTypeDefOrRefOrSpecThrowing(Module *pModule,
mdToken typeRefOrDefOrSpec,
const SigTypeContext *pTypeContext,
NotFoundAction fNotFound = ThrowIfNotFound,
PermitUninstantiatedFlag fUninstantiated = FailIfUninstDefOrRef,
LoadTypesFlag fLoadTypes = LoadTypes,
ClassLoadLevel level = CLASS_LOADED,
BOOL dropGenericArgumentLevel = FALSE,
const Substitution *pSubst = NULL /* substitution to apply if the token is a type spec with generic variables */ );
// Load constructed types by providing their constituents
static TypeHandle LoadPointerOrByrefTypeThrowing(CorElementType typ,
TypeHandle baseType,
LoadTypesFlag fLoadTypes = LoadTypes,
ClassLoadLevel level = CLASS_LOADED);
// The resulting type behaves like the unmanaged view of a given value type.
static TypeHandle LoadNativeValueTypeThrowing(TypeHandle baseType,
LoadTypesFlag fLoadTypes = LoadTypes,
ClassLoadLevel level = CLASS_LOADED);
static TypeHandle LoadArrayTypeThrowing(TypeHandle baseType,
CorElementType typ = ELEMENT_TYPE_SZARRAY,
unsigned rank = 0,
LoadTypesFlag fLoadTypes = LoadTypes,
ClassLoadLevel level = CLASS_LOADED);
static TypeHandle LoadFnptrTypeThrowing(BYTE callConv,
DWORD numArgs,
TypeHandle* retAndArgTypes,
LoadTypesFlag fLoadTypes = LoadTypes,
ClassLoadLevel level = CLASS_LOADED);
// Load types by name
static TypeHandle LoadTypeByNameThrowing(Assembly *pAssembly,
LPCUTF8 nameSpace,
LPCUTF8 name,
NotFoundAction fNotFound = ThrowIfNotFound,
LoadTypesFlag fLoadTypes = LoadTypes,
ClassLoadLevel level = CLASS_LOADED);
// Resolve a TypeRef to a TypeDef
// (Just a no-op on TypeDefs)
// Return FALSE if operation failed (e.g. type does not exist)
// *pfUsesTypeForwarder is set to TRUE if a type forwarder is found. It is never set to FALSE.
static BOOL ResolveTokenToTypeDefThrowing(Module * pTypeRefModule,
mdTypeRef typeRefToken,
Module ** ppTypeDefModule,
mdTypeDef * pTypeDefToken,
Loader::LoadFlag loadFlag = Loader::Load,
BOOL * pfUsesTypeForwarder = NULL);
// Resolve a name to a TypeDef
// Return FALSE if operation failed (e.g. type does not exist)
// *pfUsesTypeForwarder is set to TRUE if a type forwarder is found. It is never set to FALSE.
static BOOL ResolveNameToTypeDefThrowing(Module * pTypeRefModule,
const NameHandle * pName,
Module ** ppTypeDefModule,
mdTypeDef * pTypeDefToken,
Loader::LoadFlag loadFlag = Loader::Load,
BOOL * pfUsesTypeForwarder = NULL);
static void EnsureLoaded(TypeHandle typeHnd, ClassLoadLevel level = CLASS_LOADED);
static void TryEnsureLoaded(TypeHandle typeHnd, ClassLoadLevel level = CLASS_LOADED);
public:
// Look up a class by name
//
// Guaranteed to only return NULL if pName->OKToLoad() returns FALSE.
// Thus when type loads are enabled this will return non-null.
TypeHandle LoadTypeHandleThrowIfFailed(NameHandle* pName, ClassLoadLevel level = CLASS_LOADED,
Module* pLookInThisModuleOnly=NULL);
public:
// Looks up class in the local module table, if it is there it succeeds,
// Otherwise it fails, This is meant only for optimizations etc
static TypeHandle LookupTypeDefOrRefInModule(Module *pModule, mdToken cl, ClassLoadLevel *pLoadLevel = NULL);
private:
VOID AddAvailableClassDontHaveLock(Module *pModule,
mdTypeDef classdef,
AllocMemTracker *pamTracker);
VOID AddAvailableClassHaveLock(Module * pModule,
mdTypeDef classdef,
AllocMemTracker * pamTracker,
LPCSTR szWinRtNamespacePrefix,
DWORD cchWinRtNamespacePrefix);
VOID AddExportedTypeDontHaveLock(Module *pManifestModule,
mdExportedType cl,
AllocMemTracker *pamTracker);
VOID AddExportedTypeHaveLock(Module *pManifestModule,
mdExportedType cl,
AllocMemTracker *pamTracker);
public:
// For an generic type instance return the representative within the class of
// all type handles that share code. For example,
// <int> --> <int>,
// <object> --> <__Canon>,
// <string> --> <__Canon>,
// <List<string>> --> <__Canon>,
// <Struct<string>> --> <Struct<__Canon>>
//
// If the code for the type handle is not shared then return
// the type handle itself.
static TypeHandle CanonicalizeGenericArg(TypeHandle genericArg);
// Determine if the specified type representation induces a sharable
// set of compatible instantiations when used as a type parameter to
// a generic type or method.
//
// For example, when sharing at reference types "object" and "Struct<object>"
// both induce sets of compatible instantiations, e.g. when used to build types
// "List<object>" and "List<Struct<object>>" respectively.
static BOOL IsSharableInstantiation(Instantiation inst);
// Determine if it is normalized canonical generic instantiation.
// Dictionary<__Canon, __Canon> -> TRUE
// Dictionary<__Canon, int> -> TRUE
// Dictionary<__Canon, String> -> FALSE
static BOOL IsCanonicalGenericInstantiation(Instantiation inst);
// Determine if it is the entirely-canonical generic instantiation
// Dictionary<__Canon, __Canon> -> TRUE
// Dictionary<anything else> -> FALSE
static BOOL IsTypicalSharedInstantiation(Instantiation inst);
// Return TRUE if inst is the typical instantiation for the type or method specified by pModule/token
static BOOL IsTypicalInstantiation(Module *pModule, mdToken token, Instantiation inst);
// Load canonical shared instantiation for type key (each instantiation argument is
// substituted by CanonicalizeGenericArg)
static TypeHandle LoadCanonicalGenericInstantiation(TypeKey *pTypeKey,
LoadTypesFlag fLoadTypes/*=LoadTypes*/,
ClassLoadLevel level/*=CLASS_LOADED*/);
// Create a generic instantiation.
// If typeDef is not a generic type then throw an exception
// If its arity does not match nGenericClassArgCount then throw an exception
// The pointer to the instantiation is not persisted e.g. the type parameters can be stack-allocated.
// If inst=NULL then <__Canon,...,__Canon> is assumed
// If fLoadTypes=DontLoadTypes then the type handle is not created if it is not
// already present in the tables.
static TypeHandle LoadGenericInstantiationThrowing(Module *pModule,
mdTypeDef typeDef,
Instantiation inst,
LoadTypesFlag fLoadTypes = LoadTypes,
ClassLoadLevel level = CLASS_LOADED,
const InstantiationContext *pInstContext = NULL,
BOOL fFromNativeImage = FALSE);
// Public access Check APIs
public:
static BOOL CanAccessClass(
AccessCheckContext* pContext,
MethodTable* pTargetClass,
Assembly* pTargetAssembly,
const AccessCheckOptions & accessCheckOptions = *AccessCheckOptions::s_pNormalAccessChecks);
static BOOL CanAccess(
AccessCheckContext* pContext,
MethodTable* pTargetClass,
Assembly* pTargetAssembly,
DWORD dwMemberAttrs,
MethodDesc* pOptionalTargetMethod,
FieldDesc* pOptionalTargetField,
const AccessCheckOptions & accessCheckOptions = *AccessCheckOptions::s_pNormalAccessChecks);
static BOOL CanAccessFamilyVerification(
TypeHandle thCurrentClass,
TypeHandle thInstanceClass);
private:
// Access check helpers
static BOOL CanAccessMethodInstantiation(
AccessCheckContext* pContext,
MethodDesc* pOptionalTargetMethod,
const AccessCheckOptions & accessCheckOptions);
static BOOL CanAccessFamily(
MethodTable* pCurrentClass,
MethodTable* pTargetClass);
static BOOL CheckAccessMember(
AccessCheckContext* pContext,
MethodTable* pTargetClass,
Assembly* pTargetAssembly,
DWORD dwMemberAttrs,
MethodDesc* pOptionalTargetMethod,
FieldDesc* pOptionalTargetField,
const AccessCheckOptions & accessCheckOptions = *AccessCheckOptions::s_pNormalAccessChecks);
public:
//Creates a key with both the namespace and name converted to lowercase and
//made into a proper namespace-path.
VOID CreateCanonicallyCasedKey(LPCUTF8 pszNameSpace, LPCUTF8 pszName,
__out LPUTF8 *ppszOutNameSpace, __out LPUTF8 *ppszOutName);
static HRESULT FindTypeDefByExportedType(IMDInternalImport *pCTImport,
mdExportedType mdCurrent,
IMDInternalImport *pTDImport,
mdTypeDef *mtd);
class AvailableClasses_LockHolder : public CrstHolder
{
public:
AvailableClasses_LockHolder(ClassLoader *classLoader)
: CrstHolder(&classLoader->m_AvailableClassLock)
{
WRAPPER_NO_CONTRACT;
}
};
friend class AvailableClasses_LockHolder;
private:
static TypeHandle LoadConstructedTypeThrowing(TypeKey *pKey,
LoadTypesFlag fLoadTypes = LoadTypes,
ClassLoadLevel level = CLASS_LOADED,
const InstantiationContext *pInstContext = NULL);
static TypeHandle LookupTypeKeyUnderLock(TypeKey *pKey,
EETypeHashTable *pTable,
CrstBase *pLock);
static TypeHandle LookupTypeKey(TypeKey *pKey,
EETypeHashTable *pTable,
CrstBase *pLock,
BOOL fCheckUnderLock);
static TypeHandle LookupInLoaderModule(TypeKey* pKey, BOOL fCheckUnderLock);
#ifdef FEATURE_PREJIT
static TypeHandle LookupInPreferredZapModule(TypeKey* pKey, BOOL fCheckUnderLock);
#endif // FEATURE_PREJIT
// Lookup a handle in the appropriate table
// (declaring module for TypeDef or loader-module for constructed types)
static TypeHandle LookupTypeHandleForTypeKey(TypeKey *pTypeKey);
static TypeHandle LookupTypeHandleForTypeKeyInner(TypeKey *pTypeKey, BOOL fCheckUnderLock);
static void DECLSPEC_NORETURN ThrowTypeLoadException(TypeKey *pKey, UINT resIDWhy);
BOOL IsNested(const NameHandle* pName, mdToken *mdEncloser);
static BOOL IsNested(Module *pModude, mdToken typeDefOrRef, mdToken *mdEncloser);
public:
// Helpers for FindClassModule()
BOOL CompareNestedEntryWithTypeDef(IMDInternalImport *pImport,
mdTypeDef mdCurrent,
EEClassHashTable *pClassHash,
PTR_EEClassHashEntry pEntry);
BOOL CompareNestedEntryWithTypeRef(IMDInternalImport *pImport,
mdTypeRef mdCurrent,
EEClassHashTable *pClassHash,
PTR_EEClassHashEntry pEntry);
BOOL CompareNestedEntryWithExportedType(IMDInternalImport *pImport,
mdExportedType mdCurrent,
EEClassHashTable *pClassHash,
PTR_EEClassHashEntry pEntry);
//Attempts to find/load/create a type handle but does not throw
// if used in "find" mode.
TypeHandle LoadTypeHandleThrowing(NameHandle* pName, ClassLoadLevel level = CLASS_LOADED,
Module* pLookInThisModuleOnly=NULL);
private:
#ifndef DACCESS_COMPILE
// Perform a single phase of class loading
// If no type handle has yet been created, typeHnd is null.
static TypeHandle DoIncrementalLoad(TypeKey *pTypeKey,
TypeHandle typeHnd,
ClassLoadLevel workLevel);
// Phase CLASS_LOAD_CREATE of class loading
static TypeHandle CreateTypeHandleForTypeKey(TypeKey *pTypeKey,
AllocMemTracker *pamTracker);
// Publish the type in the loader's tables
static TypeHandle PublishType(TypeKey *pTypeKey, TypeHandle typeHnd);
// Notify profiler and debugger that a type load has completed
// Also update perf counters
static void Notify(TypeHandle typeHnd);
// Phase CLASS_LOAD_EXACTPARENTS of class loading
// Load exact parents and interfaces and dependent structures (generics dictionary, vtable fixes)
static void LoadExactParents(MethodTable *pMT);
static void LoadExactParentAndInterfacesTransitively(MethodTable *pMT);
// Create a non-canonical instantiation of a generic type based off the canonical instantiation
// (For example, MethodTable for List<string> is based on the MethodTable for List<__Canon>)
static TypeHandle CreateTypeHandleForNonCanonicalGenericInstantiation(TypeKey *pTypeKey,
AllocMemTracker *pamTracker);
// Loads a class. This is the inner call from the multi-threaded load. This load must
// be protected in some manner.
// If we're attempting to load a fresh instantiated type then genericArgs should be filled in
static TypeHandle CreateTypeHandleForTypeDefThrowing(Module *pModule,
mdTypeDef cl,
Instantiation inst,
AllocMemTracker *pamTracker);
// The token must be a type def. GC must be enabled.
// If we're attempting to load a fresh instantiated type then genericArgs should be filled in
TypeHandle LoadTypeHandleForTypeKey(TypeKey *pTypeKey,
TypeHandle typeHnd,
ClassLoadLevel level = CLASS_LOADED,
const InstantiationContext *pInstContext = NULL);
TypeHandle LoadTypeHandleForTypeKeyNoLock(TypeKey *pTypeKey,
ClassLoadLevel level = CLASS_LOADED,
const InstantiationContext *pInstContext = NULL);
// Used for initial loading of parent class and implemented interfaces
// When tok represents an instantiated type return an *approximate* instantiated
// type (where reference type arguments are replaced by Object)
static
TypeHandle
LoadApproxTypeThrowing(
Module * pModule,
mdToken tok,
SigPointer * pSigInst,
const SigTypeContext * pClassTypeContext);
// Returns the parent of a token. The token must be a typedef.
// If the parent is a shared constructed type (e.g. class C : List<string>) then
// only the canonical instantiation is loaded at this point.
// This is to avoid cycles in the loader e.g. on class C : D<C> or class C<T> : D<C<T>>
// We fix up the exact parent later in LoadInstantiatedInfo.
static
MethodTable *
LoadApproxParentThrowing(
Module * pModule,
mdToken cl,
SigPointer * pParentInst,
const SigTypeContext * pClassTypeContext);
// Locates the enclosing class of a token if any. The token must be a typedef.
static VOID GetEnclosingClassThrowing(IMDInternalImport *pInternalImport,
Module *pModule,
mdTypeDef cl,
mdTypeDef *tdEnclosing);
// Insert the class in the classes hash table and if needed in the case insensitive one
EEClassHashEntry_t *InsertValue(EEClassHashTable *pClassHash,
EEClassHashTable *pClassCaseInsHash,
LPCUTF8 pszNamespace,
LPCUTF8 pszClassName,
HashDatum Data,
EEClassHashEntry_t *pEncloser,
AllocMemTracker *pamTracker);
// don't call this directly.
TypeHandle LoadTypeHandleForTypeKey_Body(TypeKey *pTypeKey,
TypeHandle typeHnd,
ClassLoadLevel targetLevel);
#endif //!DACCESS_COMPILE
}; // class ClassLoader
#endif /* _H_CLSLOAD */
|
.global s_prepare_buffers
s_prepare_buffers:
push %r10
push %r11
push %r15
push %rbp
push %rbx
push %rcx
push %rdi
push %rsi
lea addresses_UC_ht+0x19fd5, %rsi
nop
cmp %r10, %r10
movw $0x6162, (%rsi)
nop
nop
nop
add $43850, %rbx
lea addresses_WT_ht+0x1493d, %r11
nop
nop
nop
nop
nop
xor $33216, %r10
movb (%r11), %cl
nop
nop
nop
xor $37793, %rcx
lea addresses_D_ht+0x197d5, %r15
xor %rbp, %rbp
movups (%r15), %xmm5
vpextrq $0, %xmm5, %r11
nop
nop
and %rsi, %rsi
lea addresses_normal_ht+0x8501, %rsi
lea addresses_UC_ht+0xf7f8, %rdi
nop
nop
nop
nop
sub $4708, %rbx
mov $42, %rcx
rep movsb
nop
nop
nop
and %rsi, %rsi
pop %rsi
pop %rdi
pop %rcx
pop %rbx
pop %rbp
pop %r15
pop %r11
pop %r10
ret
.global s_faulty_load
s_faulty_load:
push %r12
push %r13
push %r15
push %rax
push %rbp
push %rcx
push %rdi
// Store
lea addresses_WC+0x8065, %r12
xor $30199, %rbp
movw $0x5152, (%r12)
nop
nop
nop
nop
nop
xor $43263, %r13
// Store
lea addresses_WC+0x1106, %r12
nop
and %r15, %r15
mov $0x5152535455565758, %rax
movq %rax, (%r12)
nop
nop
nop
nop
nop
dec %r12
// Load
lea addresses_D+0x1a6f5, %r13
nop
nop
nop
add $43573, %rcx
movb (%r13), %r12b
nop
nop
nop
nop
dec %rax
// Faulty Load
lea addresses_WC+0xad5, %r15
nop
nop
sub $40586, %rdi
movups (%r15), %xmm4
vpextrq $1, %xmm4, %r13
lea oracles, %rcx
and $0xff, %r13
shlq $12, %r13
mov (%rcx,%r13,1), %r13
pop %rdi
pop %rcx
pop %rbp
pop %rax
pop %r15
pop %r13
pop %r12
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'type': 'addresses_WC', 'AVXalign': False, 'congruent': 0, 'size': 4, 'same': False, 'NT': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_WC', 'AVXalign': False, 'congruent': 3, 'size': 2, 'same': False, 'NT': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_WC', 'AVXalign': False, 'congruent': 0, 'size': 8, 'same': False, 'NT': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_D', 'AVXalign': True, 'congruent': 5, 'size': 1, 'same': False, 'NT': False}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'type': 'addresses_WC', 'AVXalign': False, 'congruent': 0, 'size': 16, 'same': True, 'NT': False}}
<gen_prepare_buffer>
{'OP': 'STOR', 'dst': {'type': 'addresses_UC_ht', 'AVXalign': False, 'congruent': 8, 'size': 2, 'same': False, 'NT': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_WT_ht', 'AVXalign': False, 'congruent': 3, 'size': 1, 'same': False, 'NT': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_D_ht', 'AVXalign': False, 'congruent': 6, 'size': 16, 'same': False, 'NT': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_normal_ht', 'congruent': 2, 'same': False}, 'dst': {'type': 'addresses_UC_ht', 'congruent': 0, 'same': False}}
{'00': 21829}
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
*/
|
; A297109: If n is prime(k)^e, e >= 1, then a(n) = k, otherwise 0.
; 0,1,2,1,3,0,4,1,2,0,5,0,6,0,0,1,7,0,8,0,0,0,9,0,3,0,2,0,10,0,11,1,0,0,0,0,12,0,0,0,13,0,14,0,0,0,15,0,4,0,0,0,16,0,0,0,0,0,17,0,18,0,0,1,0,0,19,0,0,0,20,0,21,0,0,0,0,0,22,0,2,0,23,0,0,0,0,0,24,0,0,0,0,0,0,0,25,0,0,0
seq $0,20500 ; Cyclotomic polynomials at x=1.
seq $0,230980 ; Number of primes <= n, starting at n=0.
|
db 0 ; species ID placeholder
db 73, 100, 60, 65, 100, 60
; hp atk def spd sat sdf
db POISON, POISON ; type
db 90 ; catch rate
db 165 ; base exp
db NO_ITEM, NO_ITEM ; items
db GENDER_F50 ; gender ratio
db 100 ; unknown 1
db 20 ; step cycles to hatch
db 5 ; unknown 2
INCBIN "gfx/pokemon/seviper/front.dimensions"
db 0, 0, 0, 0 ; padding
db GROWTH_FLUCTUATING ; growth rate
dn EGG_GROUND, EGG_DRAGON ; egg groups
; tm/hm learnset
tmhm HEADBUTT, CURSE, TOXIC, HIDDEN_POWER, SUNNY_DAY, SNORE, PROTECT, RAIN_DANCE, GIGA_DRAIN, ENDURE, FRUSTRATION, IRON_TAIL, EARTHQUAKE, RETURN, DIG, MUD_SLAP, DOUBLE_TEAM, SWAGGER, SLEEP_TALK, SLUDGE_BOMB, SWIFT, REST, ATTRACT, THIEF, FURY_CUTTER, STRENGTH, FLAMETHROWER
; end
|
;-- Hash function configuration --------------------------------------------
hash_ror_value equ 0x01
;-- Function hashes --------------------------------------------------------
hash_kernel32_LoadLibraryA equ 0x1AAA
hash_ole32_CoInitialize equ 0xF0DA
hash_ole32_CoInitializeEx equ 0x1C20
hash_ole32_CoCreateInstance equ 0x2769
hash_ole32_CoCreateInstanceEx equ 0xE9CC
;-- Warnings ---------------------------------------------------------------
|
; A083421: a(n)=2*5^n-2^n.
; 1,8,46,242,1234,6218,31186,156122,780994,3905738,19530226,97654202,488277154,2441398058,12207014866,61035123482,305175715714,1525878775178,7629394269106,38146972131962,190734862232674
mov $2,5
pow $2,$0
mov $3,$0
mov $0,2
pow $0,$3
mov $1,2
mul $1,$2
sub $1,$0
mov $0,$1
|
; A075666: Sum of next n 5th powers.
; Submitted by Jon Maiga
; 1,275,11925,208624,2078375,14118201,72758875,304553600,1084203549,3390961375,9540835601,24582546000,58801331875,131987718149,280410672375,567799960576,1102105900025,2060382328875,3724847929549,6534040766000,11154010982751,18575718271825,30246236395475,48243040458624,75502588703125,116116635541751,175712253806025,261934430438800,385053361057499,558722236132125,800915417395951,1135081481216000,1591550690922225,2209242088703299,3037721607045125,4139669428484976,5593822310596375,7498464781771625
add $0,1
mov $2,5
mov $5,$0
bin $5,2
lpb $0
mov $4,$0
sub $0,1
add $4,$5
pow $4,$2
add $3,$4
lpe
mov $0,$3
|
#include "ARemote.h"
#include <ui/DisplayInfo.h>
#include <ui/PixelFormat.h>
#include "Event.Display.Debug.h"
#include "Event.Display.API.h"
namespace Event
{
[[ maybe_unused ]] static inline const char *ImgTypeString[] =
{
"raw",
"bmp",
"bmz",
"sdl",
"jpg",
"png",
"rnp", // RAW no pad (as JPG, PNG bytes buffer format)
"-"
};
[[ maybe_unused ]] static inline const char *DisplayOrientString[] =
{
"ROTATE 0",
"ROTATE 90",
"ROTATE 180",
"ROTATE 270",
"MIRROR",
"PORTRAIT",
"LANDSCAPE",
"-"
};
[[ maybe_unused ]] static inline const char *DisplayBitFormatString[] =
{
"16 bit",
"24 bit",
"32 bit",
"ERROR"
};
//
ADisplay::ADisplay()
{
acap_init();
if ((m_dsp = android::SurfaceComposerClient::getBuiltInDisplay(
android::ISurfaceComposer::eDisplayIdMain
)) == nullptr)
throw std::system_error(App::make_error_code(App::ErrorId::error_display_android_builtin));
getDisplay(false);
m_run = true;
std::thread thcap(
[&]
{
do
{
errno = 0;
acap_release();
//
while(!m_clientcount.load())
{
if (!m_run)
return;
std::this_thread::yield();
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
if (__builtin_expect(!!(acap_capture() != android::NO_ERROR), 0))
continue;
# if (__ANDROID_VER__ >= 9)
if (__builtin_expect(!!(m_sc == nullptr), 0))
{
m_run = false;
break;
}
uint8_t *vbdata = nullptr;
if (acap_lock(reinterpret_cast<void**>(&vbdata)) != android::NO_ERROR)
continue;
# else
const uint8_t *vbdata = static_cast<const uint8_t*>(acap_getPixels());
# endif
if (!vbdata)
continue;
std::size_t vbsz = acap_size();
{
std::lock_guard<std::shared_mutex> l_lock(m_lock);
//
if (__builtin_expect(!!(vbsz != Conf.display.sz), 0))
{
Conf.display.sz = vbsz;
m_dspdata.resize(vbsz);
}
m_dspdata.assign(vbdata, vbdata + vbsz);
m_tcond = HClockNow();
}
# if (_BUILD_CAPTURE_STAT)
LOGDC("\t-> clients: ", m_clientcount.load());
LOGDC("\t-> point : ", acap_getWidth(), "x", acap_getHeight());
LOGDC("\t-> stride : ", acap_getStride());
LOGDC("\t-> format : ", acap_getFormat(), "/", android::bytesPerPixel(acap_getFormat()));
LOGDC("\t-> size : ", acap_size());
# endif
# if (_BUILD_CAPTURE_FILE_WRITE)
{
FILE *fp = ::fopen("/data/local/tmp/capture-buffer.raw", "wb");
if (!fp)
throw std::system_error(App::make_error_code(App::ErrorId::error_display_open_file), "/data/local/tmp/capture-buffer.raw");
::fwrite(vbdata, 1, vbsz, fp);
::fclose(fp);
}
# endif
}
while (m_run);
});
if (thcap.joinable())
m_thcap = move(thcap);
Conf.class_display = this;
}
ADisplay::~ADisplay()
{
m_run = ((m_run.load()) ? false : m_run.load());
if (m_thcap.joinable())
m_thcap.join();
acap_release();
Conf.class_display = nullptr;
}
void ADisplay::clientcountUp()
{
m_clientcount += 1;
}
void ADisplay::clientcountDown()
{
if (m_clientcount.load())
m_clientcount -= 1;
}
bool ADisplay::clientcountActive()
{
return static_cast<bool>(m_clientcount.load());
}
void ADisplay::getDisplay(bool b)
{
ADisplay::Orient o = getOrientation();
if ((b) && (Conf.display.o == o))
return;
if (acap_capture() != android::NO_ERROR)
throw std::system_error(App::make_error_code(App::ErrorId::error_display_android_capture));
Conf.display.w = acap_getWidth();
Conf.display.h = acap_getHeight();
Conf.display.s = acap_getStride();
Conf.display.f = acap_getFormat();
Conf.display.b = android::bytesPerPixel(Conf.display.f);
Conf.display.fmt = getAndroidFormat(Conf.display.f);
Conf.display.o = o;
Conf.display.changexy = false;
uint32_t dsz = acap_size();
//
acap_release();
//
# if defined(_BUILD_STRICT)
assert(dsz > 0);
assert(Conf.display.fmt != ImgTypeFmt::F_FMT_TYPE_NONE);
# else
if (__builtin_expect(!!(!dsz), 0))
throw std::system_error(App::make_error_code(App::ErrorId::error_display_not_size));
if (__builtin_expect(!!(Conf.display.fmt == ImgTypeFmt::F_FMT_TYPE_NONE), 0))
throw std::system_error(App::make_error_code(App::ErrorId::error_display_not_type));
# endif
if ((Conf.display.x.max) && (Conf.display.y.max))
{
int32_t r = (Conf.display.h - Conf.display.x.max);
if ((r >= 0) && (r <= 2))
{
r = (Conf.display.w - Conf.display.y.max);
if ((r >= 0) && (r <= 2))
Conf.display.changexy = true;
}
}
//
if (Conf.display.sz != dsz)
{
std::lock_guard<std::shared_mutex> l_lock(m_lock);
Conf.display.sz = dsz;
m_dspdata.resize(dsz);
}
}
ADisplay::Orient ADisplay::getOrientation() const
{
android::Vector<android::DisplayInfo> configs;
android::SurfaceComposerClient::getDisplayConfigs(m_dsp, &configs);
int32_t idx, idc = android::SurfaceComposerClient::getActiveConfig(m_dsp);
if ((idc < 0) || (!configs.size()) || (static_cast<size_t>(idc) >= configs.size()))
throw std::system_error(App::make_error_code(App::ErrorId::error_display_android_getconfig));
switch ((idx = static_cast<int32_t>(configs[idc].orientation)))
{
case 0:
case 1:
case 2:
case 3: return static_cast<ADisplay::Orient>(idx);
default: return ADisplay::Orient::O_0;
}
}
ADisplay::ImgTypeFmt ADisplay::getAndroidFormat(uint16_t f) const
{
// TODO: format normalize
switch(f)
{
/// * 32 BPP
case android::PIXEL_FORMAT_RGBA_8888:
case android::PIXEL_FORMAT_RGBX_8888:
case android::PIXEL_FORMAT_BGRA_8888:
/// > 5.1.1 duplicate PIXEL_FORMAT_RGBA_8888
//case android::PIXEL_FORMAT_sRGB_A_8888:
/// 5.1.1 AOSP
//case android::PIXEL_FORMAT_sRGB_X_8888:
return ImgTypeFmt::F_32;
/// * 24 BPP
case android::PIXEL_FORMAT_RGB_888:
return ImgTypeFmt::F_24;
/// * 16 BPP
case android::PIXEL_FORMAT_RGB_565:
case android::PIXEL_FORMAT_RGBA_5551:
case android::PIXEL_FORMAT_RGBA_4444:
return ImgTypeFmt::F_16;
default: return ImgTypeFmt::F_FMT_TYPE_NONE;
}
}
std::string ADisplay::getImgTypeString(ADisplay::ImgTypeOut t)
{
return ImgTypeString[t];
}
ADisplay::ImgTypeOut ADisplay::getImgTypeEnum(std::string const & s)
{
for (uint32_t i = 0U; i < __NELE(ImgTypeString); i++)
if (s.compare(0, 3, ImgTypeString[i], 3) == 0)
return static_cast<ADisplay::ImgTypeOut>(i);
return ADisplay::ImgTypeOut::T_IMG_TYPE_NONE;
}
std::string ADisplay::getOrientationString(ADisplay::Orient t)
{
return DisplayOrientString[t];
}
///
void ADisplay::displayInfo(std::ostream & os) const
{
# if defined(_DEBUG) || defined(_BUILD_INFO_STAT)
os << "Orientation -> " << Event::ADisplay::getOrientationString(Conf.display.o).c_str() << "\n";
os << "Display ->";
os << " w: " << Conf.display.w;
os << ", h: " << Conf.display.h;
os << ", s: " << Conf.display.s;
os << ", b: " << Conf.display.b;
os << ", f: " << Conf.display.f;
os << ", format: " << DisplayBitFormatString[Conf.display.fmt];
os << ", size: " << Conf.display.sz;
os << ", change XY: " << ((Conf.display.changexy) ? "yes" : "no" );
os << "\n";
if ((Conf.display.x.max) || (Conf.display.y.max))
{
os << "Click range ->";
os << " X min: " << Conf.display.x.min;
os << ", X max: " << Conf.display.x.max;
os << ", Y min: " << Conf.display.y.min;
os << ", Y max: " << Conf.display.y.max;
os << "\n";
}
if (Conf.display.p.max)
{
os << "Pressure ->";
os << " min: " << Conf.display.p.min;
os << ", max: " << Conf.display.p.max;
os << "\n";
}
if (Conf.display.d.max)
{
os << "Distance ->";
os << " min: " << Conf.display.d.min;
os << ", max: " << Conf.display.d.max;
os << "\n";
}
# else
os << "only build in _DEBUG mode..";
# endif
}
void ADisplay::displayInfo(Helper::Xml & x) const
{
x.xmlsection("Display")
.xmlpair("orientation", Event::ADisplay::getOrientationString(Conf.display.o))
.xmlpair("width", Conf.display.w)
.xmlpair("height", Conf.display.h)
.xmlpair("stride", Conf.display.s)
.xmlpair("format", Conf.display.f, DisplayBitFormatString[Conf.display.fmt])
.xmlpair("bpp", Conf.display.b)
.xmlpair("buffsize", Conf.display.sz)
.xmlpair("changexy", ((Conf.display.changexy) ? "yes" : "no" ));
if (Conf.display.x.max)
x.xmlsection("RangeX")
.xmlpair("min", Conf.display.x.min)
.xmlpair("max", Conf.display.x.max);
if (Conf.display.y.max)
x.xmlsection("RangeY")
.xmlpair("min", Conf.display.y.min)
.xmlpair("max", Conf.display.y.max);
if (Conf.display.p.max)
x.xmlsection("Pressure")
.xmlpair("min", Conf.display.p.min)
.xmlpair("max", Conf.display.p.max);
if (Conf.display.d.max)
x.xmlsection("Distance")
.xmlpair("min", Conf.display.d.min)
.xmlpair("max", Conf.display.d.max);
if (Conf.keymap.size())
{
x.xmlsection("HWKeyMap");
for (auto & [ key, dev ] : Conf.keymap)
{
std::string s;
Conf.helperKeyDesc(key, s);
x.xmlpair(key, dev, s);
}
}
}
};
|
#include <iostream>
void needInt(int i)
{
std::cout << "int: " << i << std::endl;
}
int main()
{
std::cout << std::endl;
double d{1.234};
std::cout << "double: " << d << std::endl;
needInt(d);
std::cout << std::endl;
} |
/*******************************************************************\
Module:
Author: Daniel Kroening, kroening@kroening.com
\*******************************************************************/
#include "c_qualifiers.h"
#include <ostream>
std::string c_qualifierst::as_string() const
{
std::string qualifiers;
if(is_constant)
qualifiers+="const ";
if(is_volatile)
qualifiers+="volatile ";
if(is_restricted)
qualifiers+="restrict ";
if(is_atomic)
qualifiers+="_Atomic ";
if(is_ptr32)
qualifiers+="__ptr32 ";
if(is_ptr64)
qualifiers+="__ptr64 ";
if(is_noreturn)
qualifiers+="_Noreturn ";
return qualifiers;
}
void c_qualifierst::read(const typet &src)
{
if(src.get_bool(ID_C_constant))
is_constant=true;
if(src.get_bool(ID_C_volatile))
is_volatile=true;
if(src.get_bool(ID_C_restricted))
is_restricted=true;
if(src.get_bool(ID_C_atomic))
is_atomic=true;
if(src.get_bool(ID_C_ptr32))
is_ptr32=true;
if(src.get_bool(ID_C_ptr64))
is_ptr64=true;
if(src.get_bool(ID_C_transparent_union))
is_transparent_union=true;
if(src.get_bool(ID_C_noreturn))
is_noreturn=true;
}
void c_qualifierst::write(typet &dest) const
{
if(is_constant)
dest.set(ID_C_constant, true);
else
dest.remove(ID_C_constant);
if(is_volatile)
dest.set(ID_C_volatile, true);
else
dest.remove(ID_C_volatile);
if(is_restricted)
dest.set(ID_C_restricted, true);
else
dest.remove(ID_C_restricted);
if(is_atomic)
dest.set(ID_C_atomic, true);
else
dest.remove(ID_C_atomic);
if(is_ptr32)
dest.set(ID_C_ptr32, true);
else
dest.remove(ID_C_ptr32);
if(is_ptr64)
dest.set(ID_C_ptr64, true);
else
dest.remove(ID_C_ptr64);
if(is_transparent_union)
dest.set(ID_C_transparent_union, true);
else
dest.remove(ID_C_transparent_union);
if(is_noreturn)
dest.set(ID_C_noreturn, true);
else
dest.remove(ID_C_noreturn);
}
void c_qualifierst::clear(typet &dest)
{
dest.remove(ID_C_constant);
dest.remove(ID_C_volatile);
dest.remove(ID_C_restricted);
dest.remove(ID_C_ptr32);
dest.remove(ID_C_ptr64);
dest.remove(ID_C_transparent_union);
dest.remove(ID_C_noreturn);
}
/// pretty-print the qualifiers
std::ostream &operator << (
std::ostream &out,
const c_qualifierst &c_qualifiers)
{
return out << c_qualifiers.as_string();
}
|
;------------------------------------------------------------------------------
; @file
; Build paging tables dynamically for x64 mode
;
; Copyright (c) 2020 Intel Corporation. All rights reserved.<BR>
; SPDX-License-Identifier: BSD-2-Clause-Patent
;
;------------------------------------------------------------------------------
%define FSP_HEADER_TEMPRAMINIT_OFFSET 0x30
%define PAGE_REGION_SIZE 0x6000
%define PAGE_PRESENT 0x01
%define PAGE_READ_WRITE 0x02
%define PAGE_USER_SUPERVISOR 0x04
%define PAGE_WRITE_THROUGH 0x08
%define PAGE_CACHE_DISABLE 0x010
%define PAGE_ACCESSED 0x020
%define PAGE_DIRTY 0x040
%define PAGE_PAT 0x080
%define PAGE_GLOBAL 0x0100
%define PAGE_2M_MBO 0x080
%define PAGE_2M_PAT 0x01000
%define PAGE_2M_PDE_ATTR (PAGE_2M_MBO + \
PAGE_ACCESSED + \
PAGE_DIRTY + \
PAGE_READ_WRITE + \
PAGE_PRESENT)
%define PAGE_PDP_ATTR (PAGE_ACCESSED + \
PAGE_READ_WRITE + \
PAGE_PRESENT)
BITS 32
PreparePagingTable:
; Input:
; ECX: Page table base, need 6 pages
; Modify:
; ECX, EDX, ESI
;
; Set up identical paging table for x64
;
mov esi, ecx
mov ecx, PAGE_REGION_SIZE / 4
xor eax, eax
xor edx, edx
clearPageTablesMemoryLoop:
mov dword[ecx * 4 + esi - 4], eax
loop clearPageTablesMemoryLoop
;
; Top level Page Directory Pointers (1 * 512GB entry)
;
lea eax, [esi + (0x1000) + PAGE_PDP_ATTR]
mov dword[esi + (0)], eax
mov dword[esi + (4)], edx
;
; Next level Page Directory Pointers (4 * 1GB entries => 4GB)
;
lea eax, [esi + (0x2000) + PAGE_PDP_ATTR]
mov dword[esi + (0x1000)], eax
mov dword[esi + (0x1004)], edx
lea eax, [esi + (0x3000) + PAGE_PDP_ATTR]
mov dword[esi + (0x1008)], eax
mov dword[esi + (0x100C)], edx
lea eax, [esi + (0x4000) + PAGE_PDP_ATTR]
mov dword[esi + (0x1010)], eax
mov dword[esi + (0x1014)], edx
lea eax, [esi + (0x5000) + PAGE_PDP_ATTR]
mov dword[esi + (0x1018)], eax
mov dword[esi + (0x101C)], edx
;
; Page Table Entries (2048 * 2MB entries => 4GB)
;
mov ecx, 0x800
pageTableEntriesLoop:
mov eax, ecx
dec eax
shl eax, 21
add eax, PAGE_2M_PDE_ATTR
mov [ecx * 8 + esi + (0x2000 - 8)], eax
mov [(ecx * 8 + esi + (0x2000 - 8)) + 4], edx
loop pageTableEntriesLoop
mov eax, esi
OneTimeCallRet PreparePagingTable
|
; Variables on stack
; $3Exx
; 00 end of stack
; 01..1A string array: 2 bytes of length + 1 byte dimensions + content
; 21..3A numeric array: 2 bytes of length + 1 byte dimensions + content
; 41..5A simple string: 2 bytes of max length + 2 bytes of actual length + content
; 61..7A simple numeric: 5 bytes
; 7B REPEAT, 3 bytes: (PPC), (SUBPPC)
; 7C WHILE, 5 bytes: (PPC), (SUBPPC), error
; 7D PROC, 7 bytes: (DATADD)-(PROG), (PPC), (SUBPPC), error
; 7E ON ERROR (reserved)
; 7F ERROR (reserved)
; 81..9A string function (reserved)
; A1..BA numeric function (reserved)
; E1..FA for loop variable: 18 bytes: value, target, step, (PPC), (SUBPPC)
REPEAT_M: EQU $7B
WHILE_M: EQU $7C
PROC_M: EQU $7D
; Skip all local variables, incl. loops
SKIP_LL:CALL SKIP_LC
SKIPLL: CP $E0
RET C
LD DE,$0013
ADD HL,DE
CALL LOC_L
JR SKIPLL
; Skip local variables excl. loops
SKIP_LC:LD C,0 ; this will never be found
; Look up local variables
; Input: C variable discriminator (a:$61, a():$01, a$:$41)
; Output: CF set, if variable found, HL pointing to variable found or next candidate, A context type $3E for GO SUB
LOOK_LC:LD HL,(ERR_SP)
INC HL
INC HL ; skip error address
LOC_L: LD A,MM
LD E,(HL)
INC HL
LD D,(HL)
CP D
JR NZ,LOC_GS ; regular GO SUB stack entry, local variable not found
LD A,E
OR A
RET Z ; end-of-stack, local variable not found
CP REPEAT_M
JR C,LOC_VAR
CP PROC_M + 1
JR NC,LOC_VAR
EX DE,HL
LD HL,LOC_TAB - REPEAT_M
PUSH BC
LD C,A
LD B,0
ADD HL,BC
LD L,(HL)
LD H,B
POP BC
ADD HL,DE
RET
LOC_VAR:LD A,E
AND $7F ; treat loop variables as simple numerics
LOC_SA: BIT 5,A
JR NZ,LOC_NM ; numeric
OR $40 ; find string arrays as well
LOC_NM: BIT 6,C
JR NZ,LOC_NA ; not an array
SUB $20
LOC_NA: CP C
JR NZ,LOC_NX
SCF
RET ; local variable found
; structure lengths + 1
LOC_TAB:DEFB $04, $06, $08
LOC_NX: LD A,E
CP $E0
RET NC ; stop at loop variable, not ours
CP $60
JR C,LOC_SKL ; skip arrays and strings
ADD A,A
LD DE,$0006
JR NC,LOC_SK ; skip numeric variables
LOC_SKL:INC HL ; skip functions
LD E,(HL)
INC HL
LD D,(HL)
INC HL
LOC_SK: ADD HL,DE
JR LOC_L
LOC_GS: INC HL ; skip line number
INC HL ; skip statement number
AND A ; not found!
RET
; Look up local variables
LOCAL_CONT:
DEC A
JR NZ,FN_ARG
LD HL,7
ADD HL,SP
LD A,(HL)
CP $06 ; called from LOAD/SAVE?
JR Z,LC_NOTF
CP $2C ; called from DIM?
JR Z,LC_NOTF
LC_DO: CALL LOOK_LC
LC_LL: JR C,LC_FND
OR A
JR Z,LC_NOTF
ADD A,A
JR Z,LC_LOOP
JR NC,LC_LOOP ; not a loop variable
LD DE,$0013 ; skip loop variable
ADD HL,DE
LC_LOOP:CALL LOC_L
JR LC_LL
LC_NOTF:LD HL,L28EF ; V-RUN-SYN
LC_JP: EX (SP),HL ; replace the return address
LC_SW: RST $10
FN_ARG: LD HL,L2951 ; STK-FN-ARK
JR LC_JP
LC_FND: POP DE ; discard return address
POP DE ; discard variable pointer
;; LD DE,L28EF ; V-RUN-SYN TODO: ???
DEC HL
LD A,(HL)
INC HL
RLCA
RLCA
RLCA
INC A
AND $07
PUSH BC
LD C,A
LD B,0
EX DE,HL
LD HL,LC_TAB
ADD HL,BC
LD C,(HL)
ADD HL,BC
POP BC
OR H ; reset Z flag
JP (HL)
LC_TAB: DEFB LC_NUM - $ ; FOR loop variable
DEFB LC_SARR - $ ; string array
DEFB LC_NARR - $ ; numeric array
DEFB LC_STR - $ ; simple string
DEFB LC_NUM - $ ; simple numeric
LC_SARR:LD C,$7F
LC_NARR:LD HL,2
ADD HL,SP
LD A,(HL)
OR A
JR Z,LC_ARR ; called from DELETE
EX DE,HL
XOR A ; signal array
RST $30
DEFW L29AE ; SV-ARRAYS
OR H ; clear both ZF and CF
JR LC_STRR
LC_STR: EX DE,HL
INC HL ; skip marker
INC HL ; skip first byte of max. length
POP DE ; discard pointer
CP A ; set Z flag
RST $10
LC_ARR: CP A ; set Z flag
LD C,$7F
LC_NUM: EX DE,HL
LC_STRR:POP DE ; discard pointer
RST $10
; new string variable assignment
NSTRNG: JR NC,FRSTR ; first assignment
AND $E0
JR Z,RSTRNG ; re-assignment of long-named string
RST $10 ; back to ROM1 for short names
FRSTR: LD HL,-7
ADD HL,BC
JR C,LSTRNG ; first assignment of long-named string
RST $10 ; back to ROM1 for short names
; long-named string variable reassignment
RSTRNG: POP AF ; discard return address
POP AF ; discard return address
POP AF ; discard zero AF
POP BC ; discard return address
POP BC ; length of old version
POP HL ; pointer to old version
LD DE,-2 ; net variable name length - 2
DEC HL ; skip zero byte
INC BC ; account for it
RSTR_L: INC BC ; increment length
INC DE ; increment net variable name length
DEC HL ; step back with pointer
BIT 6,(HL)
JR NZ,RSTR_L ; find beginning
LD A,(HL) ; first character in long name format
LD (DEST),HL ; point DEST to variable name
PUSH HL ; put back pointer to old version
PUSH BC ; put back length of old version
LD HL,L_ADDR
PUSH HL ; put back return address
XOR $E0 ; change to short name format
PUSH AF ; put back first character
LD HL,L_STRR
PUSH HL ; put back return address
PUSH HL ; placeholder
EX DE,HL ; net length - 2 to HL
; long-named string variable assignment
LSTRNG: INC HL
INC HL
PUSH HL ; save net variable name length
RST $30
DEFW L2BF1 ; STK_FETCH
LD (K_CUR),DE ; point cursor to string
POP HL ; restore net variable name length
POP AF ; discard return address
POP DE ; fetch return address
POP AF ; fetch first letter
INC DE ; skip POP AF
PUSH DE ; store return address
PUSH BC ; save string length
PUSH HL ; save net variable name length
INC HL
LD C,L
LD B,H
RST $30
DEFW MAKE_STRING
EX DE,HL
INC DE
XOR $E0 ; indicate long variable name
LD (DE),A ; with the first character
INC DE
XOR A
POP HL ; restore net variable name length
RST $30
DEFW L_STORE
POP BC
LD DE,(K_CUR)
XOR A
RST $10
STRNG_CONT:
JR NZ,NSTRNG
; string variable assignment L-DELETE
AND A
SBC HL,SP
ADD HL,SP
JR C,SW_STR ; jump if global variable
BIT 0,(IY+$37) ; FLAGX, complete string
JR Z,SW_STR
PUSH HL
RST $30
DEFW L2BF1 ; STK-FETCH
POP HL
PUSH HL
DEC HL
LD (HL),B
DEC HL
LD (HL),C
DEC HL
LD A,(HL)
DEC HL
LD L,(HL)
LD H,A
DEC HL
SCF
SBC HL,BC
JR C,STRNG_LONG
POP HL
EX DE,HL
LD A,B
OR C
JR Z,STRNG_Z
LDIR
STRNG_Z:POP BC ; discard return value
LD A,(T_ADDR)
CP $7D ; LET?
RET NZ ; return, if not
SW_STR: RST $10
STRNG_LONG:
PUSH BC ; string length
PUSH HL ; room to make (negative)
LD A,L
CPL
LD C,A
LD A,H
CPL
LD B,A
INC BC ; room to make (positive)
PUSH DE ; source address
RST $30
DEFW L1F05 ; TEST-ROOM
POP HL ; source address
EXX
POP BC ; room to make (negative)
LD HL,(ERR_SP)
ADD HL,BC
LD (ERR_SP),HL
LD HL,0
ADD HL,SP
LD E,L
LD D,H
ADD HL,BC ; DE=SP, HL=destination
EXX
POP BC ; string length
EXX
POP BC ; target address
LD SP,HL
EX DE,HL
PUSH HL
LD L,C
LD H,B
POP BC
AND A
SBC HL,BC
PUSH HL
LD L,C
LD H,B
POP BC
LDIR
PUSH DE
EXX
POP DE
PUSH DE
LDIR
POP HL
DEC HL
LD B,(HL)
DEC HL
LD C,(HL)
DEC HL
INC BC
INC BC
LD (HL),B
DEC HL
LD (HL),C
POP BC ; discard length
POP BC ; discard target address
POP BC ; discard return address
JR STRNG_Z
; LET substitute for FOR
FOR_CONT:
LD BC,18 ; enough space for a FOR loop
RST $30
DEFW L1F05 ; TEST-ROOM
POP DE ; discard return address
POP DE ; discard return address
POP DE ; save return address
POP BC ; save error address
LD HL,-18 ; 18 bytes for a FOR loop
ADD HL,SP
LD (MEM),HL ; set calculator memory area
LD SP,HL
PUSH HL ; placeholder for marker
PUSH BC ; error address
LD (ERR_SP),SP
PUSH DE ; return address
INC HL
INC HL
INC HL
INC HL
EX DE,HL
LD HL,(STKEND)
DEC HL
LD BC,5
LDDR
INC HL
LD (STKEND),HL
LD HL,(DEST)
EX DE,HL
LD (HL),$3E ; marker
BIT 1,(IY+$37)
JR NZ,LF_GETN ; jump, if not found
EX DE,HL
AND A
SBC HL,SP
ADD HL,SP
JR NC,LF_GLOB
DEC HL
LF_GLOB:DEC HL
EX DE,HL
LF_GETN:LD A,(DE)
AND $1F
OR $E0
DEC HL
LD (HL),A ; marker-discriminator
LD DE,$0007
ADD HL,DE ; HL points to limit
LD DE,L1D34 ; F-L-S
PUSH DE
RST $10
; Check local variables for NEXT
NEXT_CONT:
AND A
SBC HL,SP
ADD HL,SP
JR C,LF_SWAP ; not local
DEC HL
BIT 7,(HL)
JR Z,LF_SWAP ; not a loop variable
INC HL
EX (SP),HL
LD HL,X1DB9 ; continue with NEXT
EX (SP),HL
LF_SWAP:RST $10
|
.global s_prepare_buffers
s_prepare_buffers:
push %r11
push %r13
push %r8
push %r9
push %rbx
push %rcx
push %rdi
push %rdx
push %rsi
lea addresses_UC_ht+0x19c4c, %rdx
nop
nop
and $26880, %rbx
mov (%rdx), %r8d
nop
xor %r11, %r11
lea addresses_A_ht+0x1a744, %rdi
clflush (%rdi)
nop
nop
nop
nop
add $7180, %r13
mov (%rdi), %r9
xor $42531, %r13
lea addresses_WC_ht+0x42cc, %rdi
nop
nop
nop
dec %r8
mov (%rdi), %ebx
nop
nop
nop
nop
nop
cmp $27718, %rbx
lea addresses_WT_ht+0x8fa4, %rbx
nop
and %r13, %r13
movups (%rbx), %xmm1
vpextrq $0, %xmm1, %r11
nop
nop
nop
cmp %r8, %r8
lea addresses_UC_ht+0x34d8, %r8
cmp $35860, %rdx
mov $0x6162636465666768, %r9
movq %r9, (%r8)
nop
dec %r13
lea addresses_D_ht+0x43ec, %rsi
lea addresses_D_ht+0x92c4, %rdi
nop
sub %rdx, %rdx
mov $20, %rcx
rep movsl
nop
nop
nop
nop
nop
add $37410, %r13
lea addresses_WT_ht+0xaf08, %rsi
nop
nop
nop
sub $8778, %rbx
mov $0x6162636465666768, %rdx
movq %rdx, %xmm4
vmovups %ymm4, (%rsi)
dec %r9
pop %rsi
pop %rdx
pop %rdi
pop %rcx
pop %rbx
pop %r9
pop %r8
pop %r13
pop %r11
ret
.global s_faulty_load
s_faulty_load:
push %r12
push %r14
push %r15
push %r9
push %rax
push %rbx
push %rsi
// Store
lea addresses_PSE+0xef44, %rbx
nop
nop
nop
cmp %r12, %r12
movb $0x51, (%rbx)
add %r12, %r12
// Store
lea addresses_WT+0x143c4, %r9
nop
nop
nop
nop
and $14409, %rsi
mov $0x5152535455565758, %rax
movq %rax, %xmm3
and $0xffffffffffffffc0, %r9
movaps %xmm3, (%r9)
nop
dec %r12
// Faulty Load
lea addresses_PSE+0xb744, %rbx
nop
nop
nop
cmp $59295, %rsi
vmovups (%rbx), %ymm6
vextracti128 $1, %ymm6, %xmm6
vpextrq $0, %xmm6, %r15
lea oracles, %r14
and $0xff, %r15
shlq $12, %r15
mov (%r14,%r15,1), %r15
pop %rsi
pop %rbx
pop %rax
pop %r9
pop %r15
pop %r14
pop %r12
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'type': 'addresses_PSE', 'size': 16, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_PSE', 'size': 1, 'AVXalign': False, 'NT': False, 'congruent': 10, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_WT', 'size': 16, 'AVXalign': True, 'NT': False, 'congruent': 2, 'same': False}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'type': 'addresses_PSE', 'size': 32, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': True}}
<gen_prepare_buffer>
{'OP': 'LOAD', 'src': {'type': 'addresses_UC_ht', 'size': 4, 'AVXalign': False, 'NT': False, 'congruent': 3, 'same': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_A_ht', 'size': 8, 'AVXalign': False, 'NT': False, 'congruent': 11, 'same': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_WC_ht', 'size': 4, 'AVXalign': True, 'NT': False, 'congruent': 3, 'same': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_WT_ht', 'size': 16, 'AVXalign': False, 'NT': False, 'congruent': 5, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_UC_ht', 'size': 8, 'AVXalign': False, 'NT': False, 'congruent': 1, 'same': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_D_ht', 'congruent': 3, 'same': False}, 'dst': {'type': 'addresses_D_ht', 'congruent': 7, 'same': True}}
{'OP': 'STOR', 'dst': {'type': 'addresses_WT_ht', 'size': 32, 'AVXalign': False, 'NT': False, 'congruent': 1, 'same': True}}
{'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
*/
|
;; ----------------------------------------------------------------------------
;;
;; Copyright (c) Microsoft Corporation. All rights reserved.
;;
;; ----------------------------------------------------------------------------
include hal.inc
SYMFIX(?KdNotifyTrap@@YIXPAUKdDebugTrapData@@@Z) proc
nop
mov PAX, PCX
int 29
ret
SYMFIX(?KdNotifyTrap@@YIXPAUKdDebugTrapData@@@Z) endp
SYMFIX(?KdNotifyException@@YIXPAUClass_System_Exception@@I@Z) proc
GET_PROCESSOR_CONTEXT PAX
mov [PAX].Struct_Microsoft_Singularity_ProcessorContext._exception, PCX
mov PAX, PDX
int 29 ;Notify debugging stub of first chance exception.
ret
SYMFIX(?KdNotifyException@@YIXPAUClass_System_Exception@@I@Z) endp
end
|
; A129527: a(2n) = a(n) + 2n, a(2n+1) = 2n + 1.
; 0,1,3,3,7,5,9,7,15,9,15,11,21,13,21,15,31,17,27,19,35,21,33,23,45,25,39,27,49,29,45,31,63,33,51,35,63,37,57,39,75,41,63,43,77,45,69,47,93,49,75,51,91,53,81,55,105,57,87,59,105,61,93,63,127,65,99,67,119,69,105,71,135,73,111,75,133,77,117,79,155,81,123,83,147,85,129,87,165,89,135,91,161,93,141,95,189,97,147,99
lpb $0
add $1,$0
dif $0,2
lpe
add $1,$0
mov $0,$1
|
.global s_prepare_buffers
s_prepare_buffers:
push %r9
push %rax
push %rbp
push %rbx
push %rcx
push %rdi
push %rsi
lea addresses_UC_ht+0xdff7, %rsi
lea addresses_D_ht+0x10227, %rdi
nop
nop
nop
nop
inc %rax
mov $122, %rcx
rep movsb
add %rbx, %rbx
lea addresses_UC_ht+0x3cb7, %rdi
add $40946, %r9
movl $0x61626364, (%rdi)
add %rcx, %rcx
lea addresses_WT_ht+0x18b17, %rsi
nop
nop
nop
nop
nop
sub $60853, %rcx
movl $0x61626364, (%rsi)
nop
nop
sub %rax, %rax
lea addresses_WT_ht+0x57b7, %rsi
lea addresses_D_ht+0xf5d3, %rdi
nop
nop
xor %rbp, %rbp
mov $54, %rcx
rep movsl
dec %rax
pop %rsi
pop %rdi
pop %rcx
pop %rbx
pop %rbp
pop %rax
pop %r9
ret
.global s_faulty_load
s_faulty_load:
push %r11
push %r15
push %r8
push %rax
push %rbp
// Faulty Load
lea addresses_US+0x68b7, %r15
nop
nop
nop
nop
cmp $41471, %r8
mov (%r15), %r11d
lea oracles, %rax
and $0xff, %r11
shlq $12, %r11
mov (%rax,%r11,1), %r11
pop %rbp
pop %rax
pop %r8
pop %r15
pop %r11
ret
/*
<gen_faulty_load>
[REF]
{'src': {'NT': False, 'AVXalign': False, 'size': 32, 'congruent': 0, 'same': False, 'type': 'addresses_US'}, 'OP': 'LOAD'}
[Faulty Load]
{'src': {'NT': False, 'AVXalign': False, 'size': 4, 'congruent': 0, 'same': True, 'type': 'addresses_US'}, 'OP': 'LOAD'}
<gen_prepare_buffer>
{'src': {'congruent': 4, 'same': False, 'type': 'addresses_UC_ht'}, 'dst': {'congruent': 2, 'same': False, 'type': 'addresses_D_ht'}, 'OP': 'REPM'}
{'dst': {'NT': False, 'AVXalign': False, 'size': 4, 'congruent': 9, 'same': False, 'type': 'addresses_UC_ht'}, 'OP': 'STOR'}
{'dst': {'NT': False, 'AVXalign': False, 'size': 4, 'congruent': 5, 'same': False, 'type': 'addresses_WT_ht'}, 'OP': 'STOR'}
{'src': {'congruent': 2, 'same': False, 'type': 'addresses_WT_ht'}, 'dst': {'congruent': 2, 'same': False, 'type': 'addresses_D_ht'}, 'OP': 'REPM'}
{'00': 9}
00 00 00 00 00 00 00 00 00
*/
|
#include "spark_precompiled.h"
#include <AzTest/AzTest.h>
class sparkTest
: public ::testing::Test
{
protected:
void SetUp() override
{
}
void TearDown() override
{
}
};
TEST_F(sparkTest, ExampleTest)
{
ASSERT_TRUE(true);
}
AZ_UNIT_TEST_HOOK();
|
; this file is part of Release, written by Malban in 2017
;
HAS_VOICE0 = 1
HAS_TONE0 = 1
FIRST7 = $3E
dw $0066
pattern14Data:
db $F3, $1E, $87, $A9, $E3, $DC, $79, $EA, $EE, $F7
db $1E, $78, $9E, $3B, $47, $9D, $67, $8E, $71, $E7
db $AB, $BB, $4F, $1E, $EE, $EF, $53, $C6, $BB, $B8
db $18, $7F, $EF, $47, $6F, $27, $F7, $F5, $1F, $7B
db $C9, $F9, $8C, $4B, $B5, $69, $D7, $48, $E9, $24
db $9F, $3C, $33, $E7, $7A, $3B, $79, $3F, $5F, $A8
db $F8, $DE, $4F, $B4, $62, $5C, $EB, $4E, $5A, $47
db $19, $24, $FF, $C6, $25, $F7, $98, $FF, $86, $9F
db $B9, $8D, $3B, $7F, $1C, $0C, $1E, $E7, $90, $F3
db $77, $78, $9E, $38, $18, $1F, $FB, $D1, $DB, $C9
db $FD, $FD, $47, $DE, $F2, $7E, $63, $12, $ED, $5A
db $75, $D2, $3A, $49, $27, $CF, $0C, $F7, $3C, $87
db $8B, $BB, $D4, $F1, $C0, $C0, $F7, $77, $79, $9E
db $3A, $5D, $DE, $A3, $CF, $37, $77, $19, $E3, $AD
db $DD, $DA, $3C, $E0, $7F, $8C, $4B, $EF, $31, $FF
db $0D, $3F, $73, $1A, $76, $FE, $38, $18, $7F, $EF
db $47, $6F, $27, $F7, $F5, $1F, $7B, $C9, $F9, $8C
db $4B, $B5, $69, $D7, $48, $E9, $24, $9F, $3C, $33
db $DC, $F2, $1E, $2E, $EF, $53, $C7, $03, $00 |
.psx
.open "../build/SLUS_005_VANILLA.61", "../build/SLUS_005.61", 0x80010000-0x800
; Constants
PLAYER_ID_X equ 0x00
PLAYER_ID_ZERO equ 0x01
STAGE_ID_SPIDER equ 0x01
STAGE_ID_PEACOCK equ 0x06
STAGE_ID_OWL equ 0x07
STAGE_ID_DRAGOON equ 0x04
STAGE_ID_STINGRAY equ 0x05
STAGE_ID_MUSHROOM equ 0x03
STAGE_ID_BEAST equ 0x08
STAGE_ID_WALRUS equ 0x02
STAGE_ID_SPACE_PORT equ 0x0A
STAGE_ID_FINAL_WEAPON_1 equ 0x0B
STAGE_ID_FINAL_WEAPON_2 equ 0x0C
; ROM(? it all seems to be ram in PS1) Addresses
STAGE_SELECT_TO_STAGE_ID_TABLE_HI equ 0x800F
STAGE_SELECT_TO_STAGE_ID_TABLE_LO equ 0x474C
STAGE_SELECT_TO_STAGE_ID_TABLE equ 0x800F474C
STAGE_ID_TO_STAGE_SELECT_TABLE_HI equ 0x800F
STAGE_ID_TO_STAGE_SELECT_TABLE_LO equ 0x4758
STAGE_ID_TO_STAGE_SELECT_TABLE equ 0x800F4758
PLAY_SOUND_SUB equ 0x8001540C ; plays sound id currently on a1
MENU_SELECT_SOUND_ID equ 0x22
; RAM Addresses
GAME_STATE_1 equ 0x801721C0
CURRENT_PLAYER equ 0x80172203
CURRENT_STAGE equ 0x801721CC
STAGE_PART equ 0x801721CD
CURRENT_CHECKPOINT equ 0x801721DD
MAX_HP equ 0x80172206
IFRAME_COUNTER equ 0x80141929
CURRENT_HP equ 0x80141924
CURRENT_WEAPON equ 0x8014195B
WEAPON_ENERGIES equ 0x80141970 ; 16 bytes, max at 0x30 each
SUB_HP_1 equ 0x8017221C
SUB_HP_2 equ 0x8017221D
WEP_HP equ 0x8017221E
HEARTS_OBTAINED equ 0x8017221A
TANKS_OBTAINED equ 0x8017221B ; upper 4 bits
ARMOR_OBTAINED equ 0x80172207 ; lower 4 bits
BUSTER_TYPE equ 0x80172208
CAM_X_CURR equ 0x801419B8
CAM_X_PREV equ 0x801419C4
CAM_Y_CURR equ 0x801419BC
CAM_Y_PREV equ 0x801419C8
INPUT_1_PREV equ 0x80166C08
INPUT_1_CURR equ 0x80166C0A
INPUT_1_NEW equ 0x80166C0C ; DPad, start, select
INPUT_2_PREV equ 0x80166C09
INPUT_2_CURR equ 0x80166C0B
INPUT_2_NEW equ 0x80166C0D ; Face buttons, shoulder buttons
MAVERICKS_DEFEATED equ 0x80172219
SELECTION_STAGE_ID_MINUS_ONE equ 0x80173DA7 ; only in stage select
REFIGHT_CAPSULE_STATES equ 0x801721EE ; 8 bytes. 00 is open, 01 is closing and 02 is closed.
TELEPORT_VALUE_1 equ 0x801418CC ; Set to 0x0003 when teleporting
TELEPORT_VALUE_2 equ 0x801721CF ; Set to 0x00C0 when teleporting
ONE_BEFORE_SIGMA_HPS equ 0x8013BF61 ; to use v0 as an offset in @sigma_infinite
GUNNER_SIGMA_HP equ 0x8013BF62
GROUND_SIGMA_HP equ 0x8013BF63
SIGMA_FIGHT_LIFECYCLE equ 0x8013BF66 ; will be 2 before ground spawns, 6 before gunner spawns
SIGMA_FIGHT_STATE equ 0x8013B8B8 ; 0 is both alive, 1 is gunner dead, 2 is ground dead
TEMP_RAM equ 0x8011E3F0
TEMP_RAM_LENGTH equ 16
CONTROLLER_INPUTS_1 equ (TEMP_RAM + 0)
CONTROLLER_INPUTS_2 equ (TEMP_RAM + 1)
CONTROLLER_INPUTS_1_PREV equ (TEMP_RAM + 2)
CONTROLLER_INPUTS_2_PREV equ (TEMP_RAM + 3)
HEARTS_STORAGE equ (TEMP_RAM + 4)
TANKS_STORAGE equ (TEMP_RAM + 5)
ARMOR_STORAGE equ (TEMP_RAM + 6)
WEAPON_STORAGE equ (TEMP_RAM + 7)
CHECKPOINT_STORAGE equ (TEMP_RAM + 8)
SPAWN_NEXT_SIGMA equ (TEMP_RAM + 9) ; 0 to spawn ground, 1 to spawn gunner
CHECKPOINT_LOAD_READY equ (TEMP_RAM + 10) ; Using this to get loading checkpoint a frame to soak so weapon swaps don't crash etc
INPUT_1_DONT_COUNT equ (TEMP_RAM + 11)
CHECKPOINT_LOADING equ (TEMP_RAM + 12)
CAVE_1 equ 0x8011C200
CAVE_1_LENGTH equ 0x03F0
CAVE_2 equ 0x8011E400
CAVE_2_LENGTH equ 0x07D0
; Macros for replacing existing code and then jumping back to cave org
.macro replace,dest
.org dest
.endmacro
.macro endreplace,nextlabel
.org org(nextlabel)
.endmacro
; Stack macros
.macro push,reg
addiu sp,sp,-4
sw reg,(sp)
.endmacro
.macro pop,reg
lw reg,(sp)
addiu sp,sp,4
.endmacro
; This block is the main area for now.
; There are 16 bytes here for storing temporary things in RAM
.org TEMP_RAM
.area TEMP_RAM_LENGTH
.dw 0x00000000
.dw 0x00000000
.dw 0x00000000
.dw 0x00000000
.endarea
; Split the code into 2 caves because only cave 2 was causing things to break after a while
.org CAVE_1 ; This is nearly full, so put stuff that won't change much
.area CAVE_1_LENGTH
; Assembly hacks
.include "asm/tables.asm"
.include "asm/utils.asm"
.include "asm/stageselect.asm"
.endarea
.org CAVE_2
.area CAVE_2_LENGTH
.include "asm/general.asm"
.include "asm/gameplay.asm"
.include "asm/menu.asm"
.endarea
.close
; Non-assembly/data hacks. Files should be opened and closed where necessary since they can vary.
; These changes require you to delete the bin and build folders before building.
.include "data/menu.asm"
|
global @ASM_strncmp@12
segment .text align=16
%define count 4
%define regCount esi
%define count4 edi
%define str1 ecx
%define str2 edx
%define tmpChar eax
%define tmpChar2 ebx
%define loTmpChar al
%define loTmpChar2 bl
%define result eax
@ASM_strncmp@12:
push count4
push regCount
push tmpChar2
mov regCount, dword [esp + 12 + count]
cmp regCount, 3
jbe .skipBigComp
mov ebx, regCount
and ebx, -4
lea count4, [str1 + ebx]
.dwordLoop:
movzx tmpChar, byte [str1]
movzx tmpChar2, byte [str2]
test loTmpChar, loTmpChar
je .foundChar
cmp loTmpChar, loTmpChar2
jne .foundChar
movzx tmpChar, byte [str1 + 1]
movzx tmpChar2, byte [str2 + 1]
test loTmpChar, loTmpChar
je .foundChar
cmp loTmpChar, loTmpChar2
jne .foundChar
movzx tmpChar, byte [str1 + 2]
movzx tmpChar2, byte [str2 + 2]
test loTmpChar, loTmpChar
je .foundChar
cmp loTmpChar, loTmpChar2
jne .foundChar
movzx tmpChar, byte [str1 + 3]
movzx tmpChar2, byte [str2 + 3]
add str1, 4
add str2, 4
test loTmpChar, loTmpChar
je .foundChar
cmp loTmpChar, loTmpChar2
jne .foundChar
cmp count4, str1
jne .dwordLoop
and regCount, 3
jmp .doEndBytes
align 16
.skipBigComp:
xor tmpChar, tmpChar
xor tmpChar2, tmpChar2
.doEndBytes:
; regCount is smaller than 4 at this point so yeah
test regCount, regCount
je .foundChar
movzx tmpChar, byte [str1]
movzx tmpChar2, byte [str2]
test loTmpChar, loTmpChar
je .foundChar
cmp loTmpChar2, loTmpChar
jne .foundChar
dec regCount
je .foundChar
movzx tmpChar, byte [str1 + 1]
movzx tmpChar2, byte [str2 + 1]
test loTmpChar, loTmpChar
je .foundChar
cmp loTmpChar2, loTmpChar
jne .foundChar
cmp regCount, 1
je .foundChar
movzx tmpChar, byte [str1 + 2]
movzx tmpChar2, byte [str2 + 2]
.foundChar:
movzx count4, loTmpChar2
; mov result, tmpChar
sub result, count4
pop tmpChar2
pop regCount
pop count4
ret 4
|
; A095097: Fib000 numbers: those n for which the Zeckendorf expansion A014417(n) ends with three zeros.
; 8,13,18,21,26,29,34,39,42,47,52,55,60,63,68,73,76,81,84,89,94,97,102,107,110,115,118,123,128,131,136,141,144,149,152,157,162,165,170,173,178,183,186,191,196,199,204,207,212,217,220,225,228,233,238,241,246
mov $6,$0
add $0,5
mul $0,2
mov $1,3
mov $2,$0
mov $3,$0
mov $4,$0
sub $0,1
add $2,3
sub $3,$0
add $4,1
lpb $2,1
sub $1,$3
add $5,$4
lpb $4,1
add $5,$4
sub $4,$3
lpe
add $3,4
add $3,$2
lpb $5,1
add $1,2
mov $2,3
add $3,4
trn $5,$3
lpe
mov $0,2
lpb $0,1
trn $0,4
sub $1,1
lpe
lpe
lpb $6,1
add $1,3
sub $6,1
lpe
add $1,1
|
; ================================================================
; XM2GB replay routine
; ================================================================
; NOTE: For best results, place player code in ROM0.
; ===========
; Player code
; ===========
section "GBMod",rom0
GBMod:
GBM_LoadModule: jp GBMod_LoadModule
GBM_Update: jp GBMod_Update
GBM_Stop: jp GBMod_Stop
; db "XM2GB by DevEd | email: deved8@gmail.com"
; ================================
GBMod_LoadModule:
push af
push bc
push hl
di
ld [GBM_SongID],a
xor a
ld hl,GBM_RAM_Start+1
ld b,(GBM_RAM_End-GBM_RAM_Start+1)-2
.clearloop
ld [hl+],a
dec b
jr nz,.clearloop
inc a
ld [GBM_ModuleTimer],a
ld [GBM_TickTimer],a
ldh [rNR52],a ; disable sound (clears all sound registers)
or $80
ldh [rNR52],a ; enable sound
or $7f
ldh [rNR51],a ; all channels to SO1+SO2
xor %10001000
ldh [rNR50],a ; master volume 7
ld a,[GBM_SongID]
inc a
ld [rROMB0],a
ld hl,$4000
ld a,[hl+]
ld [GBM_PatternCount],a
ld a,[hl+]
ld [GBM_PatTableSize],a
ld a,[hl+]
ld [GBM_ModuleSpeed],a
ld a,[hl+]
ld [GBM_TickSpeed],a
ld a,[hl+]
ld [GBM_SongDataOffset],a
ld a,[hl]
ld [GBM_SongDataOffset+1],a
ld a,$ff
ld [GBM_LastWave],a
ld a,1
ld [GBM_DoPlay],a
ld [GBM_CmdTick1],a
ld [GBM_CmdTick2],a
ld [GBM_CmdTick3],a
ld [GBM_CmdTick4],a
sub 2
ld [GBM_PanFlags],a
pop hl
pop bc
pop af
reti
; ================================
GBMod_Stop:
xor a
ld hl,GBM_RAM_Start
ld b,GBM_RAM_End-GBM_RAM_Start
.clearloop
ld [hl+],a
dec b
jr nz,.clearloop
ldh [rNR52],a ; disable sound (clears all sound registers)
or $80
ldh [rNR52],a ; enable sound
or $7f
ldh [rNR51],a ; all channels to SO1+SO2
xor %10001000
ldh [rNR50],a ; master volume 7
ret
; ================================
GBMod_Update:
ld a,[GBM_DoPlay]
and a
ret z
; anything that needs to be updated on a per-frame basis should be put here
ld e,0
call GBMod_DoVib ; pulse 1 vibrato
inc e
call GBMod_DoVib ; pulse 2 vibrato
inc e
call GBMod_DoVib ; pulse 3 vibrato
; sample playback
ld a,[GBM_SamplePlaying]
and a
call nz,GBMod_UpdateSample
ld a,[GBM_TickTimer]
dec a
ld [GBM_TickTimer],a
ret nz
ld a,[GBM_TickSpeed]
ld [GBM_TickTimer],a
ld a,[GBM_ModuleTimer]
dec a
ld [GBM_ModuleTimer],a
jp nz,GBMod_UpdateCommands
xor a
ld [GBM_SpeedChanged],a
ld a,[GBM_ModuleSpeed]
ld [GBM_ModuleTimer],a
ld a,[GBM_SongID]
inc a
ld [rROMB0],a
ld hl,GBM_SongDataOffset
ld a,[hl+]
ld b,a
ld a,[hl]
add $40
ld h,a
ld l,b
; get pattern offset
ld a,[GBM_CurrentPattern]
and a
jr z,.getRow
add a
add a
add h
ld h,a
.getRow
ld a,[GBM_CurrentRow]
and a
jr z,.readPatternData
ld b,a
swap a
and $f0
ld e,a
ld a,b
swap a
and $0f
ld d,a
add hl,de
.readPatternData
; ch1 note
ld a,[hl+]
push af
cp $ff
jr z,.skip1
cp $fe
jr nz,.nocut1
xor a
ld [GBM_Vol1],a
.nocut1
inc hl
ld a,[hl]
dec hl
cp 1
jr z,.noreset1
cp 2
jr z,.noreset1
call GBM_ResetFreqOffset1
.noreset1
pop af
.freq1
ld [GBM_Note1],a
ld e,0
call GBMod_GetFreq2
; ch1 volume
ld a,[GBM_SkipCH1]
and a
jr nz,.skipvol1
ld a,[GBM_Command1]
cp $a
jr z,.skipvol1
ld a,[hl]
swap a
and $f
jr z,.skipvol1
ld b,a
rla
rla
rla
ld [GBM_Vol1],a
ld a,b
swap a
ldh [rNR12],a
set 7,e
.skipvol1
; ch1 pulse
ld a,[hl+]
ld b,a
ld a,[GBM_SkipCH1]
and a
jr nz,.skippulse1
ld a,b
and $f
jr z,.skippulse1
dec a
ld [GBM_Pulse1],a
swap a
rla
rla
ldh [rNR11],a
.skippulse1
; ch1 command
ld a,[hl+]
ld [GBM_Command1],a
; ch1 param
ld a,[hl+]
ld [GBM_Param1],a
; update freq
ld a,[GBM_SkipCH1]
and a
jr nz,.ch2
ld a,d
ldh [rNR13],a
ld a,e
ldh [rNR14],a
jr .ch2
.skip1
pop af
ld a,[GBM_Note1]
jr .freq1
.ch2
; ch2 note
ld a,[hl+]
push af
cp $ff
jr z,.skip2
cp $fe
jr nz,.nocut2
xor a
ld [GBM_Vol2],a
.nocut2
inc hl
ld a,[hl]
dec hl
cp 1
jr z,.noreset2
cp 2
jr z,.noreset2
call GBM_ResetFreqOffset2
.noreset2
pop af
.freq2
ld [GBM_Note2],a
ld e,1
call GBMod_GetFreq2
; ch2 volume
ld a,[GBM_SkipCH2]
and a
jr nz,.skipvol2
ld a,[GBM_Command2]
cp $a
jr z,.skipvol2
ld a,[hl]
swap a
and $f
jr z,.skipvol2
ld b,a
rla
rla
rla
ld [GBM_Vol2],a
ld a,b
swap a
ldh [rNR22],a
set 7,e
.skipvol2
; ch2 pulse
ld a,[hl+]
ld b,a
ld a,[GBM_SkipCH2]
and a
jr nz,.skippulse2
ld a,b
and $f
jr z,.skippulse2
dec a
ld [GBM_Pulse2],a
swap a
rla
rla
ldh [rNR21],a
.skippulse2
; ch2 command
ld a,[hl+]
ld [GBM_Command2],a
; ch2 param
ld a,[hl+]
ld [GBM_Param2],a
; update freq
ld a,[GBM_SkipCH2]
and a
jr nz,.ch3
ld a,d
ldh [rNR23],a
ld a,e
ldh [rNR24],a
jr .ch3
.skip2
pop af
ld a,[GBM_Note2]
jr .freq2
.ch3
; ch3 note
ld a,[GBM_SamplePlaying]
and a
jp nz,.sample3
.note3
ld a,[hl+]
push af
cp $ff
jr z,.skip3
cp $fe
jr nz,.nocut3
xor a
ld [GBM_Vol3],a
.nocut3
inc hl
ld a,[hl]
dec hl
cp 1
jr z,.noreset3
cp 2
jr z,.noreset3
call GBM_ResetFreqOffset3
.noreset3
pop af
cp $80
jr z,.playsample3
.freq3
ld [GBM_Note3],a
ld e,2
call GBMod_GetFreq2
; ch3 volume
ld a,[hl]
swap a
and $f
jr z,.skipvol3
ld [GBM_Vol3],a
call GBMod_GetVol3
ld b,a
ld a,[GBM_OldVol3]
cp b
jr z,.skipvol3
ld a,[GBM_SkipCH3]
and a
jr nz,.skipvol3
ld a,b
ldh [rNR32],a
set 7,e
.skipvol3
ld [GBM_OldVol3],a
; ch3 wave
ld a,[hl+]
dec a
and $f
cp 15
jr z,.continue3
ld b,a
ld a,[GBM_LastWave]
cp b
jr z,.continue3
ld a,b
ld [GBM_Wave3],a
ld [GBM_LastWave],a
push hl
call GBM_LoadWave
set 7,e
pop hl
.continue3
; ch3 command
ld a,[hl+]
ld [GBM_Command3],a
; ch3 param
ld a,[hl+]
ld [GBM_Param3],a
; update freq
ld a,[GBM_SkipCH3]
and a
jr nz,.ch4
ld a,d
ldh [rNR33],a
ld a,e
ldh [rNR34],a
jr .ch4
.skip3
pop af
ld a,[GBM_Note3]
jr .freq3
.playsample3
ld a,[hl+]
call GBMod_PlaySample
jr .continue3
.sample3
ld a,[hl]
cp $ff
jr z,.nostopsample3
xor a
ld [GBM_SamplePlaying],a
jp .note3
.nostopsample3
ld a,l
add 4
ld l,a
jr nc,.ch4
inc h
.ch4
; ch4 note
ld a,[hl+]
cp $ff
jr z,.skip4
cp $fe
jr nz,.freq4
xor a
ld [GBM_Vol4],a
.freq4
ld [GBM_Note4],a
push hl
ld hl,NoiseTable
add l
ld l,a
jr nc,.nocarry
inc h
.nocarry
ld a,[hl+]
ld d,a
pop hl
; ch4 volume
ld a,[GBM_SkipCH4]
and a
jr nz,.skipvol4
inc hl
ld a,[hl]
dec hl
cp $a
jr nz,.disablecmd4
.dovol4
ld a,[hl]
swap a
and $f
ld b,a
rla
rla
rla
ld [GBM_Vol4],a
ld a,b
swap a
ldh [rNR42],a
jr .skipvol4
.disablecmd4
xor a
ld [GBM_Command4],a
jr .dovol4
.skipvol4
; ch4 mode
ld a,[hl+]
and a
jr z,.nomode
dec a
and 1
ld [GBM_Mode4],a
and a
jr z,.nomode
set 3,d
.nomode
; ch4 command
ld a,[hl+]
ld [GBM_Command4],a
; ch4 param
ld a,[hl+]
ld [GBM_Param4],a
; set freq
ld a,[GBM_SkipCH4]
and a
jr nz,.updateRow
ld a,d
ldh [rNR43],a
ld a,$80
ldh [rNR44],a
jr .updateRow
.skip4
ld a,[GBM_Note4]
jr .freq4
.updateRow
call GBM_ResetCommandTick
ld a,[GBM_CurrentRow]
inc a
cp 64
jr z,.nextPattern
ld [GBM_CurrentRow],a
jr .done
.nextPattern
xor a
ld [GBM_CurrentRow],a
ld a,[GBM_PatTablePos]
inc a
ld b,a
ld a,[GBM_PatTableSize]
cp b
jr z,.loopSong
ld a,b
ld [GBM_PatTablePos],a
jr .setPattern
.loopSong
xor a
ld [GBM_PatTablePos],a
.setPattern
ld hl,$40f0
add l
ld l,a
ld a,[hl+]
ld [GBM_CurrentPattern],a
.done
GBMod_UpdateCommands:
ld a,$ff
ld [GBM_PanFlags],a
; ch1
ld a,[GBM_Command1]
ld hl,.commandTable1
add a
add l
ld l,a
jr nc,.nocarry1
inc h
.nocarry1
ld a,[hl+]
ld h,[hl]
ld l,a
jp hl
.commandTable1
dw .arp1 ; 0xy - arp
dw .slideup1 ; 1xy - note slide up
dw .slidedown1 ; 2xy - note slide down
dw .ch2 ; 3xy - portamento (NYI)
dw .ch2 ; 4xy - vibrato (handled elsewhere)
dw .ch2 ; 5xy - portamento + volume slide (NYI)
dw .ch2 ; 6xy - vibrato + volume slide (NYI)
dw .ch2 ; 7xy - tremolo (NYI)
dw .pan1 ; 8xy - panning
dw .ch2 ; 9xy - sample offset (won't be implemented)
dw .volslide1 ; Axy - volume slide
dw .patjump1 ; Bxy - pattern jump
dw .ch2 ; Cxy - set volume (won't be implemented)
dw .patbreak1 ; Dxy - pattern break
dw .ch2 ; Exy - extended commands (NYI)
dw .speed1 ; Fxy - set module speed
.arp1
ld a,[GBM_Param1]
and a
jp z,.ch2
ld a,[GBM_ArpTick1]
inc a
cp 4
jr nz,.noresetarp1
ld a,1
.noresetarp1
ld [GBM_ArpTick1],a
ld a,[GBM_Param1]
ld b,a
ld a,[GBM_Note1]
ld c,a
ld a,[GBM_ArpTick1]
dec a
call GBMod_DoArp
ld a,[GBM_SkipCH1]
and a
jp nz,.ch2
ld a,d
ldh [rNR13],a
ld a,e
ldh [rNR14],a
jp .ch2
.slideup1
ld a,[GBM_Param1]
ld b,a
ld e,0
call GBMod_DoPitchSlide
ld a,[GBM_Note1]
call GBMod_GetFreq2
jp .dosetfreq1
.slidedown1
; read tick speed
ld a,[GBM_Param1]
ld b,a
ld e,0
call GBMod_DoPitchSlide
ld a,[GBM_Note1]
call GBMod_GetFreq2
jp .dosetfreq1
.pan1
ld a,[GBM_Param1]
cpl
and $11
ld b,a
ld a,[GBM_PanFlags]
xor b
ld [GBM_PanFlags],a
jp .ch2
.patbreak1
ld a,[GBM_Param1]
ld [GBM_CurrentRow],a
ld a,[GBM_PatTablePos]
inc a
ld [GBM_PatTablePos],a
ld hl,$40f0
add l
ld l,a
ld a,[hl]
ld [GBM_CurrentPattern],a
xor a
ld [GBM_Command1],a
ld [GBM_Param1],a
jp .done
.patjump1
xor a
ld [GBM_CurrentRow],a
ld a,[GBM_Param1]
ld [GBM_PatTablePos],a
ld hl,$40f0
add l
ld l,a
ld a,[hl]
ld [GBM_CurrentPattern],a
xor a
ld [GBM_Command1],a
ld [GBM_Param1],a
jp .done
.volslide1
ld a,[GBM_ModuleSpeed]
ld b,a
ld a,[GBM_ModuleTimer]
cp b
jr z,.ch2 ; skip first tick
ld a,[GBM_Param1]
cp $10
jr c,.volslide1_dec
.volslide1_inc
swap a
and $f
ld b,a
ld a,[GBM_Vol1]
add b
jr .volslide1_nocarry
.volslide1_dec
ld b,a
ld a,[GBM_Vol1]
sub b
jr nc,.volslide1_nocarry
xor a
.volslide1_nocarry
ld [GBM_Vol1],a
rra
rra
rra
and $f
ld b,a
ld a,[GBM_SkipCH1]
and a
jr nz,.ch2
ld a,b
swap a
ld [rNR12],a
ld a,[GBM_Note1]
call GBMod_GetFreq
ld a,[GBM_SkipCH1]
and a
jr nz,.ch2
ld a,d
ldh [rNR13],a
ld a,e
or $80
ldh [rNR14],a
jr .ch2
.dosetfreq1
ld a,[GBM_SkipCH1]
and a
jr nz,.ch2
ld a,d
ldh [rNR13],a
ld a,e
ldh [rNR14],a
jr .ch2
.speed1
ld a,[GBM_SpeedChanged]
and a
jr nz,.ch2
ld a,[GBM_Param1]
ld [GBM_ModuleSpeed],a
ld [GBM_ModuleTimer],a
ld a,1
ld [GBM_SpeedChanged],a
.ch2
ld a,[GBM_Command1]
cp 4
jr nz,.novib1
ld a,[GBM_Note1]
call GBMod_GetFreq
ld h,d
ld l,e
ld a,[GBM_FreqOffset1]
add h
ld h,a
jr nc,.continue1
inc l
.continue1
ld a,[GBM_SkipCH1]
and a
jr nz,.novib1
ld a,h
ldh [rNR13],a
ld a,l
ldh [rNR14],a
.novib1
ld a,[GBM_Command2]
ld hl,.commandTable2
add a
add l
ld l,a
jr nc,.nocarry2
inc h
.nocarry2
ld a,[hl+]
ld h,[hl]
ld l,a
jp hl
.commandTable2
dw .arp2 ; 0xy - arp
dw .slideup2 ; 1xy - note slide up
dw .slidedown2 ; 2xy - note slide down
dw .ch3 ; 3xy - portamento (NYI)
dw .ch3 ; 4xy - vibrato (handled elsewhere)
dw .ch3 ; 5xy - portamento + volume slide (NYI)
dw .ch3 ; 6xy - vibrato + volume slide (NYI)
dw .ch3 ; 7xy - tremolo (NYI)
dw .pan2 ; 8xy - panning
dw .ch3 ; 9xy - sample offset (won't be implemented)
dw .volslide2 ; Axy - volume slide
dw .patjump2 ; Bxy - pattern jump
dw .ch3 ; Cxy - set volume (won't be implemented)
dw .patbreak2 ; Dxy - pattern break
dw .ch3 ; Exy - extended commands (NYI)
dw .speed2 ; Fxy - set module speed
.arp2
ld a,[GBM_Param2]
and a
jp z,.ch3
ld a,[GBM_ArpTick2]
inc a
cp 4
jr nz,.noresetarp2
ld a,1
.noresetarp2
ld [GBM_ArpTick2],a
ld a,[GBM_Param2]
ld b,a
ld a,[GBM_Note2]
ld c,a
ld a,[GBM_ArpTick2]
dec a
call GBMod_DoArp
ld a,[GBM_SkipCH2]
and a
jp nz,.ch3
ld a,d
ldh [rNR23],a
ld a,e
ldh [rNR24],a
jp .ch3
.slideup2
ld a,[GBM_Param2]
ld b,a
ld e,1
call GBMod_DoPitchSlide
ld a,[GBM_Note2]
call GBMod_GetFreq2
jp .dosetfreq2
.slidedown2
; read tick speed
ld a,[GBM_Param2]
ld b,a
ld e,1
call GBMod_DoPitchSlide
ld a,[GBM_Note2]
call GBMod_GetFreq2
jp .dosetfreq2
.pan2
ld a,[GBM_Param2]
cpl
and $11
rla
ld b,a
ld a,[GBM_PanFlags]
xor b
ld [GBM_PanFlags],a
jp .ch3
.patbreak2
ld a,[GBM_Param2]
ld [GBM_CurrentRow],a
ld a,[GBM_PatTablePos]
inc a
ld [GBM_PatTablePos],a
ld hl,$40f0
add l
ld l,a
ld a,[hl]
ld [GBM_CurrentPattern],a
xor a
ld [GBM_Command2],a
ld [GBM_Param2],a
jp .done
.patjump2
xor a
ld [GBM_CurrentRow],a
ld a,[GBM_Param2]
ld [GBM_PatTablePos],a
ld hl,$40f0
add l
ld l,a
ld a,[hl]
ld [GBM_CurrentPattern],a
xor a
ld [GBM_Command2],a
ld [GBM_Param2],a
jp .done
.volslide2
ld a,[GBM_ModuleSpeed]
ld b,a
ld a,[GBM_ModuleTimer]
cp b
jr z,.ch3 ; skip first tick
ld a,[GBM_Param2]
cp $10
jr c,.volslide2_dec
.volslide2_inc
swap a
and $f
ld b,a
ld a,[GBM_Vol2]
add b
jr .volslide2_nocarry
.volslide2_dec
ld b,a
ld a,[GBM_Vol2]
sub b
jr nc,.volslide2_nocarry
xor a
.volslide2_nocarry
ld [GBM_Vol2],a
rra
rra
rra
and $f
ld b,a
ld a,[GBM_SkipCH2]
and a
jr nz,.ch3
ld a,b
swap a
ld [rNR22],a
ld a,[GBM_Note2]
call GBMod_GetFreq
ld a,[GBM_SkipCH2]
and a
jr nz,.ch3
ld a,d
ldh [rNR23],a
ld a,e
or $80
ldh [rNR24],a
jr .ch3
.dosetfreq2
ld a,[GBM_SkipCH2]
and a
jr nz,.ch3
ld a,d
ldh [rNR23],a
ld a,e
ldh [rNR24],a
jr .ch3
.speed2
ld a,[GBM_SpeedChanged]
and a
jr nz,.ch3
ld a,[GBM_Param2]
ld [GBM_ModuleSpeed],a
ld [GBM_ModuleTimer],a
ld a,1
ld [GBM_SpeedChanged],a
.ch3
ld a,[GBM_Command2]
cp 4
jr nz,.novib2
ld a,[GBM_Note2]
call GBMod_GetFreq
ld h,d
ld l,e
ld a,[GBM_FreqOffset2]
add h
ld h,a
jr nc,.continue2
inc l
.continue2
ld a,[GBM_SkipCH2]
and a
jr nz,.novib2
ld a,h
ldh [rNR23],a
ld a,l
ldh [rNR24],a
.novib2
ld a,[GBM_Command3]
ld hl,.commandTable3
add a
add l
ld l,a
jr nc,.nocarry3
inc h
.nocarry3
ld a,[hl+]
ld h,[hl]
ld l,a
jp hl
.commandTable3
dw .arp3 ; 0xy - arp
dw .slideup3 ; 1xy - note slide up
dw .slidedown3 ; 2xy - note slide down
dw .ch4 ; 3xy - portamento (NYI)
dw .ch4 ; 4xy - vibrato (handled elsewhere)
dw .ch4 ; 5xy - portamento + volume slide (NYI)
dw .ch4 ; 6xy - vibrato + volume slide (NYI)
dw .ch4 ; 7xy - tremolo (doesn't apply for CH3)
dw .pan3 ; 8xy - panning
dw .ch4 ; 9xy - sample offset (won't be implemented)
dw .ch4 ; Axy - volume slide (doesn't apply for CH3)
dw .patjump3 ; Bxy - pattern jump
dw .ch4 ; Cxy - set volume (won't be implemented)
dw .patbreak3 ; Dxy - pattern break
dw .ch4 ; Exy - extended commands (NYI)
dw .speed3 ; Fxy - set module speed
.arp3
ld a,[GBM_Param3]
and a
jp z,.ch4
ld a,[GBM_ArpTick3]
inc a
cp 4
jr nz,.noresetarp3
ld a,1
.noresetarp3
ld [GBM_ArpTick3],a
ld a,[GBM_Param3]
ld b,a
ld a,[GBM_Note3]
ld c,a
ld a,[GBM_ArpTick3]
dec a
call GBMod_DoArp
ld a,[GBM_SkipCH3]
and a
jp nz,.ch4
ld a,d
ldh [rNR33],a
ld a,e
ldh [rNR34],a
jp .ch4
.slideup3
ld a,[GBM_Param3]
ld b,a
ld e,2
call GBMod_DoPitchSlide
ld a,[GBM_Note3]
call GBMod_GetFreq2
jp .dosetfreq3
.slidedown3
; read tick speed
ld a,[GBM_Param3]
ld b,a
ld e,2
call GBMod_DoPitchSlide
ld a,[GBM_Note3]
call GBMod_GetFreq2
jp .dosetfreq3
.pan3
ld a,[GBM_Param3]
cpl
and $11
rla
ld b,a
ld a,[GBM_PanFlags]
xor b
ld [GBM_PanFlags],a
jp .ch4
.patbreak3
ld a,[GBM_Param3]
ld [GBM_CurrentRow],a
ld a,[GBM_PatTablePos]
inc a
ld [GBM_PatTablePos],a
ld hl,$40f0
add l
ld l,a
ld a,[hl]
ld [GBM_CurrentPattern],a
xor a
ld [GBM_Command3],a
ld [GBM_Param3],a
jp .done
.patjump3
xor a
ld [GBM_CurrentRow],a
ld a,[GBM_Param3]
ld [GBM_PatTablePos],a
ld hl,$40f0
add l
ld l,a
ld a,[hl]
ld [GBM_CurrentPattern],a
xor a
ld [GBM_Command3],a
ld [GBM_Param3],a
jp .done
.dosetfreq3
ld a,[GBM_SkipCH3]
and a
jr nz,.ch4
ld a,d
ldh [rNR33],a
ld a,e
ldh [rNR34],a
jr .ch4
.speed3
ld a,[GBM_SpeedChanged]
and a
jr nz,.ch4
ld a,[GBM_Param3]
ld [GBM_ModuleSpeed],a
ld [GBM_ModuleTimer],a
ld a,1
ld [GBM_SpeedChanged],a
.ch4
ld a,[GBM_Command3]
cp 4
jr nz,.novib3
ld a,[GBM_SkipCH3]
and a
jp nz,.novib3
ld a,[GBM_Note3]
call GBMod_GetFreq
ld h,d
ld l,e
ld a,[GBM_FreqOffset3]
add h
ld h,a
jr nc,.continue3
inc l
.continue3
ld a,h
ldh [rNR33],a
ld a,l
ldh [rNR34],a
.novib3
ld a,[GBM_Command4]
ld hl,.commandTable4
add a
add l
ld l,a
jr nc,.nocarry4
inc h
.nocarry4
ld a,[hl+]
ld h,[hl]
ld l,a
jp hl
.commandTable4
dw .arp4 ; 0xy - arp
dw .done ; 1xy - note slide up (doesn't apply for CH4)
dw .done ; 2xy - note slide down (doesn't apply for CH4)
dw .done ; 3xy - portamento (doesn't apply for CH4)
dw .done ; 4xy - vibrato (doesn't apply for CH4)
dw .done ; 5xy - portamento + volume slide (doesn't apply for CH4)
dw .done ; 6xy - vibrato + volume slide (doesn't apply for CH4)
dw .done ; 7xy - tremolo (NYI)
dw .pan4 ; 8xy - panning
dw .done ; 9xy - sample offset (won't be implemented)
dw .volslide4 ; Axy - volume slide
dw .patjump4 ; Bxy - pattern jump
dw .done ; Cxy - set volume (won't be implemented)
dw .patbreak4 ; Dxy - pattern break
dw .done ; Exy - extended commands (NYI)
dw .speed4 ; Fxy - set module speed
.arp4
ld a,[GBM_Param4]
and a
jp z,.done
ld a,[GBM_ArpTick4]
inc a
cp 4
jr nz,.noresetarp4
ld a,1
.noresetarp4
ld [GBM_ArpTick4],a
ld a,[GBM_Param4]
ld b,a
ld a,[GBM_Note4]
ld c,a
ld a,[GBM_ArpTick4]
dec a
call GBMod_DoArp4
ld hl,NoiseTable
add l
ld l,a
jr nc,.nocarry5
inc h
.nocarry5
ld a,[hl]
ldh [rNR43],a
jp .done
.pan4
ld a,[GBM_Param4]
cpl
and $11
ld b,a
ld a,[GBM_PanFlags]
xor b
ld [GBM_PanFlags],a
jp .done
.patbreak4
ld a,[GBM_Param4]
ld [GBM_CurrentRow],a
ld a,[GBM_PatTablePos]
inc a
ld [GBM_PatTablePos],a
ld hl,$40f0
add l
ld l,a
ld a,[hl+]
ld [GBM_CurrentPattern],a
xor a
ld [GBM_Command4],a
ld [GBM_Param4],a
jr .done
.patjump4
xor a
ld [GBM_CurrentRow],a
ld a,[GBM_Param4]
ld [GBM_PatTablePos],a
ld hl,$40f0
add l
ld l,a
ld a,[hl]
ld [GBM_CurrentPattern],a
xor a
ld [GBM_Command4],a
ld [GBM_Param4],a
jr .done
.volslide4
ld a,[GBM_ModuleSpeed]
ld b,a
ld a,[GBM_ModuleTimer]
cp b
jr z,.done ; skip first tick
ld a,[GBM_Param4]
cp $10
jr c,.volslide4_dec
.volslide4_inc
swap a
and $f
ld b,a
ld a,[GBM_Vol4]
add b
jr .volslide4_nocarry
.volslide4_dec
ld b,a
ld a,[GBM_Vol4]
sub b
jr nc,.volslide4_nocarry
xor a
.volslide4_nocarry
ld [GBM_Vol4],a
rra
rra
rra
and $f
ld b,a
ld a,[GBM_SkipCH4]
and a
jr nz,.done
ld a,b
swap a
ld [rNR42],a
ld a,[GBM_Note4]
call GBMod_GetFreq
ld a,[GBM_SkipCH4]
and a
jr nz,.done
or $80
ldh [rNR44],a
jr .done
.speed4
ld a,[GBM_SpeedChanged]
and a
jr nz,.done
ld a,[GBM_Param4]
ld [GBM_ModuleSpeed],a
ld [GBM_ModuleTimer],a
ld a,1
ld [GBM_SpeedChanged],a
.done
ld a,[GBM_PanFlags]
ldh [rNR51],a
ld a,1
ld [rROMB0],a
ret
GBMod_DoArp:
call GBMod_DoArp4
jp GBMod_GetFreq
ret
GBMod_DoArp4:
and a
jr z,.arp0
dec a
jr z,.arp1
dec a
jr z,.arp2
ret ; default case
.arp0
xor a
ld b,a
jr .getNote
.arp1
ld a,b
swap a
and $f
ld b,a
jr .getNote
.arp2
ld a,b
and $f
ld b,a
.getNote
ld a,c
add b
ret
; Input: e = current channel
GBMod_DoVib:
ld hl,GBM_Command1
call GBM_AddChannelID
ld a,[hl]
cp 4
ret nz ; return if vibrato is disabled
; get vibrato tick
ld hl,GBM_Param1
call GBM_AddChannelID
ld a,[hl]
push af
swap a
cpl
and $f
ld b,a
ld hl,GBM_CmdTick1
call GBM_AddChannelID
ld a,[hl]
and a
jr z,.noexit
pop af
dec [hl]
ret
.noexit
ld [hl],b
; get vibrato depth
pop af
and $f
ld d,a
ld hl,GBM_ArpTick1
call GBM_AddChannelID
ld a,[hl]
xor 1
ld [hl],a
and a
jr nz,.noreset2
ld hl,GBM_FreqOffset1
call GBM_AddChannelID16
ld [hl],0
ret
.noreset2
ld hl,GBM_FreqOffset1
call GBM_AddChannelID16
ld a,d
rr d
add d
ld [hl],a
ret
; INPUT: e=channel ID
GBMod_DoPitchSlide:
push bc
push de
ld hl,GBM_Command1
call GBM_AddChannelID
ld a,[hl]
cp 1
jr z,.slideup
cp 2
jr nz,.done
.slidedown
call .getparam
xor a
sub c
ld c,a
ld a,0
sbc b
ld b,a
jr .setoffset
.slideup
call .getparam
.setoffset
add hl,bc
add hl,bc
add hl,bc
ld b,h
ld c,l
ld hl,GBM_FreqOffset1
call GBM_AddChannelID16
ld a,c
ld [hl+],a
ld a,b
ld [hl],a
call .getparam
jr .done
.getparam
ld hl,GBM_Param1
call GBM_AddChannelID
ld a,[hl]
ld c,a
ld b,0
ld hl,GBM_FreqOffset1
call GBM_AddChannelID16
ld a,[hl+]
ld h,[hl]
ld l,a
ret
.done
pop de
pop bc
ret
GBM_AddChannelID:
ld a,e
GBM_AddChannelID_skip:
add l
ld l,a
ret nc
inc h
ret
GBM_AddChannelID16:
ld a,e
add a
jr GBM_AddChannelID_skip
GBM_ResetCommandTick:
.ch1
ld a,[GBM_Command1]
cp 4
jr z,.ch2
xor a
ld [GBM_CmdTick1],a
.ch2
ld a,[GBM_Command2]
cp 4
jr z,.ch3
xor a
ld [GBM_CmdTick2],a
.ch3
ld a,[GBM_Command3]
cp 4
jr z,.ch4
xor a
ld [GBM_CmdTick3],a
.ch4
xor a
ld [GBM_CmdTick4],a
ret
; input: a = note id
; b = channel ID
; output: de = frequency
GBMod_GetFreq:
push af
push bc
push hl
ld de,0
ld l,a
ld h,0
jr GBMod_DoGetFreq
GBMod_GetFreq2:
push af
push bc
push hl
ld c,a
ld hl,GBM_FreqOffset1
call GBM_AddChannelID16
ld a,[hl+]
ld d,[hl]
ld e,a
ld l,c
ld h,0
GBMod_DoGetFreq:
add hl,hl ; x1
add hl,hl ; x2
add hl,hl ; x4
add hl,hl ; x8
add hl,hl ; x16
add hl,hl ; x32
ld b,h
ld c,l
ld hl,FreqTable
add hl,bc
add hl,de
ld a,[hl+]
ld d,a
ld a,[hl]
ld e,a
pop hl
pop bc
pop af
ret
GBM_ResetFreqOffset1:
push af
push hl
xor a
ld [GBM_Command1],a
ld [GBM_Param1],a
ld hl,GBM_FreqOffset1
jr GBM_DoResetFreqOffset
GBM_ResetFreqOffset2:
push af
push hl
xor a
ld [GBM_Command2],a
ld [GBM_Param2],a
ld hl,GBM_FreqOffset2
jr GBM_DoResetFreqOffset
GBM_ResetFreqOffset3:
push af
push hl
xor a
ld [GBM_Command3],a
ld [GBM_Param3],a
ld hl,GBM_FreqOffset3
GBM_DoResetFreqOffset:
ld [hl+],a
ld [hl],a
pop hl
pop af
ret
GBMod_GetVol3:
push hl
ld hl,WaveVolTable
add l
ld l,a
jr nc,.nocarry
inc h
.nocarry
ld a,[hl]
pop hl
ret
; INPUT: a = wave ID
GBM_LoadWave:
and $f
add a
ld hl,GBM_PulseWaves
add l
ld l,a
jr nc,.nocarry2
inc h
.nocarry2
ld a,[hl+]
ld h,[hl]
ld l,a
GBM_CopyWave:
ldh a,[rNR51]
push af
and %10111011
ldh [rNR51],a ; prevent spike on GBA
xor a
ldh [rNR30],a
ld bc,$1030
.loop
ld a,[hl+]
ld [c],a
inc c
dec b
jr nz,.loop
ld a,%10000000
ldh [rNR30],a
pop af
ldh [rNR51],a
ret
; INPUT: a = sample ID
GBMod_PlaySample:
ld [GBM_SampleID],a
push hl
ld c,a
ld b,0
ld hl,GBM_SampleTable
add hl,bc
add hl,bc
ld a,[hl+]
ld h,[hl]
ld l,a
; bank
ld a,[hl+]
ld [GBM_SampleBank],a
; pointer
ld a,[hl+]
ld [GBM_SamplePointer],a
ld a,[hl+]
ld [GBM_SamplePointer+1],a
; counter
ld a,[hl+]
ld [GBM_SampleCounter],a
ld a,[hl]
ld [GBM_SampleCounter+1],a
ld a,1
ld [GBM_SamplePlaying],a
jr GBMod_UpdateSample2
GBMod_UpdateSample:
push hl
GBMod_UpdateSample2:
ld a,[GBM_SamplePlaying]
and a
ret z ; return if sample not playing
ld a,[GBM_SampleBank]
ld [rROMB0],a
ld hl,GBM_SamplePointer
ld a,[hl+]
ld h,[hl]
ld l,a
call GBM_CopyWave
ld a,%00100000
ldh [rNR32],a
ld a,$d4
ldh [rNR33],a
ld a,$83
ldh [rNR34],a
ld a,[GBM_SampleCounter]
sub 16
ld [GBM_SampleCounter],a
jr nc,.skiphigh
ld a,[GBM_SampleCounter+1]
dec a
ld [GBM_SampleCounter+1],a
.skiphigh
ld b,a
ld a,l
ld [GBM_SamplePointer],a
ld a,h
ld [GBM_SamplePointer+1],a
ld a,[GBM_SampleCounter+1]
ld b,a
ld a,[GBM_SampleCounter]
or b
jr nz,.done
xor a
ld [GBM_SamplePlaying],a
ld a,[GBM_SongID]
inc a
ld [rROMB0],a
ld a,[GBM_Wave3]
call GBM_LoadWave
pop hl
ret
.done
ld a,[GBM_SongID]
inc a
ld [rROMB0],a
pop hl
ret
GBM_PulseWaves:
dw wave_Pulse125,wave_Pulse25,wave_Pulse50,wave_Pulse75
dw $4030,$4040,$4050,$4060
dw $4070,$4080,$4090,$40a0
dw $40b0,$40c0,$40d0,$40e0
; evil optimization hax for pulse wave data
; should result in the following:
; wave_Pulse75: $ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$00,$00,$00,$00
; wave_Pulse50: $ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$00,$00,$00,$00,$00,$00,$00,$00
; wave_Pulse25: $ff,$ff,$ff,$ff,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
; wave_Pulse125: $ff,$ff,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
wave_Pulse75: db $ff,$ff,$ff,$ff
wave_Pulse50: db $ff,$ff,$ff,$ff
wave_Pulse25: db $ff,$ff
wave_Pulse125: db $ff,$ff,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00 ; last four bytes read from WaveVolumeTable
WaveVolTable:
db $00,$00,$00,$00,$60,$60,$60,$60,$40,$40,$40,$40,$20,$20,$20,$20
; ================================
FreqTable:
dw $0022,$0026,$002a,$002d,$0031,$0034,$0038,$003c
dw $003f,$0043,$0046,$004a,$004e,$0051,$0055,$0058
dw $005c,$005f,$0063,$0066,$006a,$006d,$0071,$0074
dw $0078,$007b,$007f,$0082,$0086,$0089,$008d,$0090
dw $0093,$0097,$009a,$009e,$00a1,$00a4,$00a8,$00ab
dw $00af,$00b2,$00b5,$00b9,$00bc,$00bf,$00c3,$00c6
dw $00ca,$00cd,$00d0,$00d3,$00d7,$00da,$00dd,$00e1
dw $00e4,$00e7,$00eb,$00ee,$00f1,$00f4,$00f8,$00fb
dw $00fe,$0101,$0105,$0108,$010b,$010e,$0111,$0115
dw $0118,$011b,$011e,$0121,$0125,$0128,$012b,$012e
dw $0131,$0134,$0137,$013b,$013e,$0141,$0144,$0147
dw $014a,$014d,$0150,$0153,$0157,$015a,$015d,$0160
dw $0163,$0166,$0169,$016c,$016f,$0172,$0175,$0178
dw $017b,$017e,$0181,$0184,$0187,$018a,$018d,$0190
dw $0193,$0196,$0199,$019c,$019f,$01a2,$01a5,$01a8
dw $01ab,$01ad,$01b0,$01b3,$01b6,$01b9,$01bc,$01bf
dw $01c2,$01c5,$01c8,$01ca,$01cd,$01d0,$01d3,$01d6
dw $01d9,$01dc,$01de,$01e1,$01e4,$01e7,$01ea,$01ed
dw $01ef,$01f2,$01f5,$01f8,$01fa,$01fd,$0200,$0203
dw $0206,$0208,$020b,$020e,$0211,$0213,$0216,$0219
dw $021c,$021e,$0221,$0224,$0226,$0229,$022c,$022e
dw $0231,$0234,$0236,$0239,$023c,$023e,$0241,$0244
dw $0246,$0249,$024c,$024e,$0251,$0254,$0256,$0259
dw $025b,$025e,$0261,$0263,$0266,$0268,$026b,$026e
dw $0270,$0273,$0275,$0278,$027a,$027d,$0280,$0282
dw $0285,$0287,$028a,$028c,$028f,$0291,$0294,$0296
dw $0299,$029b,$029e,$02a0,$02a3,$02a5,$02a8,$02aa
dw $02ad,$02af,$02b1,$02b4,$02b6,$02b9,$02bb,$02be
dw $02c0,$02c3,$02c5,$02c7,$02ca,$02cc,$02cf,$02d1
dw $02d3,$02d6,$02d8,$02db,$02dd,$02df,$02e2,$02e4
dw $02e6,$02e9,$02eb,$02ed,$02f0,$02f2,$02f4,$02f7
dw $02f9,$02fb,$02fe,$0300,$0302,$0305,$0307,$0309
dw $030c,$030e,$0310,$0312,$0315,$0317,$0319,$031b
dw $031e,$0320,$0322,$0324,$0327,$0329,$032b,$032d
dw $0330,$0332,$0334,$0336,$0338,$033b,$033d,$033f
dw $0341,$0343,$0346,$0348,$034a,$034c,$034e,$0351
dw $0353,$0355,$0357,$0359,$035b,$035d,$0360,$0362
dw $0364,$0366,$0368,$036a,$036c,$036e,$0371,$0373
dw $0375,$0377,$0379,$037b,$037d,$037f,$0381,$0383
dw $0385,$0388,$038a,$038c,$038e,$0390,$0392,$0394
dw $0396,$0398,$039a,$039c,$039e,$03a0,$03a2,$03a4
dw $03a6,$03a8,$03aa,$03ac,$03ae,$03b0,$03b2,$03b4
dw $03b6,$03b8,$03ba,$03bc,$03be,$03c0,$03c2,$03c4
dw $03c6,$03c8,$03ca,$03cc,$03ce,$03d0,$03d1,$03d3
dw $03d5,$03d7,$03d9,$03db,$03dd,$03df,$03e1,$03e3
dw $03e5,$03e7,$03e8,$03ea,$03ec,$03ee,$03f0,$03f2
dw $03f4,$03f6,$03f7,$03f9,$03fb,$03fd,$03ff,$0401
dw $0403,$0404,$0406,$0408,$040a,$040c,$040e,$040f
dw $0411,$0413,$0415,$0417,$0418,$041a,$041c,$041e
dw $0420,$0421,$0423,$0425,$0427,$0429,$042a,$042c
dw $042e,$0430,$0431,$0433,$0435,$0437,$0438,$043a
dw $043c,$043e,$043f,$0441,$0443,$0445,$0446,$0448
dw $044a,$044b,$044d,$044f,$0451,$0452,$0454,$0456
dw $0457,$0459,$045b,$045c,$045e,$0460,$0461,$0463
dw $0465,$0466,$0468,$046a,$046b,$046d,$046f,$0470
dw $0472,$0474,$0475,$0477,$0479,$047a,$047c,$047d
dw $047f,$0481,$0482,$0484,$0485,$0487,$0489,$048a
dw $048c,$048d,$048f,$0491,$0492,$0494,$0495,$0497
dw $0499,$049a,$049c,$049d,$049f,$04a0,$04a2,$04a4
dw $04a5,$04a7,$04a8,$04aa,$04ab,$04ad,$04ae,$04b0
dw $04b1,$04b3,$04b4,$04b6,$04b7,$04b9,$04bb,$04bc
dw $04be,$04bf,$04c1,$04c2,$04c4,$04c5,$04c7,$04c8
dw $04c9,$04cb,$04cc,$04ce,$04cf,$04d1,$04d2,$04d4
dw $04d5,$04d7,$04d8,$04da,$04db,$04dd,$04de,$04df
dw $04e1,$04e2,$04e4,$04e5,$04e7,$04e8,$04ea,$04eb
dw $04ec,$04ee,$04ef,$04f1,$04f2,$04f3,$04f5,$04f6
dw $04f8,$04f9,$04fa,$04fc,$04fd,$04ff,$0500,$0501
dw $0503,$0504,$0506,$0507,$0508,$050a,$050b,$050c
dw $050e,$050f,$0510,$0512,$0513,$0515,$0516,$0517
dw $0519,$051a,$051b,$051d,$051e,$051f,$0521,$0522
dw $0523,$0525,$0526,$0527,$0528,$052a,$052b,$052c
dw $052e,$052f,$0530,$0532,$0533,$0534,$0536,$0537
dw $0538,$0539,$053b,$053c,$053d,$053e,$0540,$0541
dw $0542,$0544,$0545,$0546,$0547,$0549,$054a,$054b
dw $054c,$054e,$054f,$0550,$0551,$0553,$0554,$0555
dw $0556,$0557,$0559,$055a,$055b,$055c,$055e,$055f
dw $0560,$0561,$0562,$0564,$0565,$0566,$0567,$0568
dw $056a,$056b,$056c,$056d,$056e,$0570,$0571,$0572
dw $0573,$0574,$0576,$0577,$0578,$0579,$057a,$057b
dw $057d,$057e,$057f,$0580,$0581,$0582,$0583,$0585
dw $0586,$0587,$0588,$0589,$058a,$058b,$058d,$058e
dw $058f,$0590,$0591,$0592,$0593,$0594,$0596,$0597
dw $0598,$0599,$059a,$059b,$059c,$059d,$059e,$05a0
dw $05a1,$05a2,$05a3,$05a4,$05a5,$05a6,$05a7,$05a8
dw $05a9,$05aa,$05ac,$05ad,$05ae,$05af,$05b0,$05b1
dw $05b2,$05b3,$05b4,$05b5,$05b6,$05b7,$05b8,$05b9
dw $05ba,$05bb,$05bc,$05be,$05bf,$05c0,$05c1,$05c2
dw $05c3,$05c4,$05c5,$05c6,$05c7,$05c8,$05c9,$05ca
dw $05cb,$05cc,$05cd,$05ce,$05cf,$05d0,$05d1,$05d2
dw $05d3,$05d4,$05d5,$05d6,$05d7,$05d8,$05d9,$05da
dw $05db,$05dc,$05dd,$05de,$05df,$05e0,$05e1,$05e2
dw $05e3,$05e4,$05e5,$05e6,$05e7,$05e8,$05e9,$05ea
dw $05eb,$05ec,$05ed,$05ee,$05ef,$05ef,$05f0,$05f1
dw $05f2,$05f3,$05f4,$05f5,$05f6,$05f7,$05f8,$05f9
dw $05fa,$05fb,$05fc,$05fd,$05fe,$05ff,$05ff,$0600
dw $0601,$0602,$0603,$0604,$0605,$0606,$0607,$0608
dw $0609,$060a,$060a,$060b,$060c,$060d,$060e,$060f
dw $0610,$0611,$0612,$0612,$0613,$0614,$0615,$0616
dw $0617,$0618,$0619,$061a,$061a,$061b,$061c,$061d
dw $061e,$061f,$0620,$0621,$0621,$0622,$0623,$0624
dw $0625,$0626,$0627,$0627,$0628,$0629,$062a,$062b
dw $062c,$062d,$062d,$062e,$062f,$0630,$0631,$0632
dw $0632,$0633,$0634,$0635,$0636,$0637,$0637,$0638
dw $0639,$063a,$063b,$063b,$063c,$063d,$063e,$063f
dw $0640,$0640,$0641,$0642,$0643,$0644,$0644,$0645
dw $0646,$0647,$0648,$0648,$0649,$064a,$064b,$064c
dw $064c,$064d,$064e,$064f,$064f,$0650,$0651,$0652
dw $0653,$0653,$0654,$0655,$0656,$0656,$0657,$0658
dw $0659,$0659,$065a,$065b,$065c,$065c,$065d,$065e
dw $065f,$0660,$0660,$0661,$0662,$0663,$0663,$0664
dw $0665,$0665,$0666,$0667,$0668,$0668,$0669,$066a
dw $066b,$066b,$066c,$066d,$066e,$066e,$066f,$0670
dw $0670,$0671,$0672,$0673,$0673,$0674,$0675,$0675
dw $0676,$0677,$0678,$0678,$0679,$067a,$067a,$067b
dw $067c,$067d,$067d,$067e,$067f,$067f,$0680,$0681
dw $0681,$0682,$0683,$0683,$0684,$0685,$0686,$0686
dw $0687,$0688,$0688,$0689,$068a,$068a,$068b,$068c
dw $068c,$068d,$068e,$068e,$068f,$0690,$0690,$0691
dw $0692,$0692,$0693,$0694,$0694,$0695,$0696,$0696
dw $0697,$0698,$0698,$0699,$0699,$069a,$069b,$069b
dw $069c,$069d,$069d,$069e,$069f,$069f,$06a0,$06a1
dw $06a1,$06a2,$06a2,$06a3,$06a4,$06a4,$06a5,$06a6
dw $06a6,$06a7,$06a7,$06a8,$06a9,$06a9,$06aa,$06ab
dw $06ab,$06ac,$06ac,$06ad,$06ae,$06ae,$06af,$06af
dw $06b0,$06b1,$06b1,$06b2,$06b2,$06b3,$06b4,$06b4
dw $06b5,$06b5,$06b6,$06b7,$06b7,$06b8,$06b8,$06b9
dw $06ba,$06ba,$06bb,$06bb,$06bc,$06bd,$06bd,$06be
dw $06be,$06bf,$06bf,$06c0,$06c1,$06c1,$06c2,$06c2
dw $06c3,$06c3,$06c4,$06c5,$06c5,$06c6,$06c6,$06c7
dw $06c7,$06c8,$06c9,$06c9,$06ca,$06ca,$06cb,$06cb
dw $06cc,$06cc,$06cd,$06ce,$06ce,$06cf,$06cf,$06d0
dw $06d0,$06d1,$06d1,$06d2,$06d3,$06d3,$06d4,$06d4
dw $06d5,$06d5,$06d6,$06d6,$06d7,$06d7,$06d8,$06d8
dw $06d9,$06da,$06da,$06db,$06db,$06dc,$06dc,$06dd
dw $06dd,$06de,$06de,$06df,$06df,$06e0,$06e0,$06e1
dw $06e1,$06e2,$06e2,$06e3,$06e3,$06e4,$06e4,$06e5
dw $06e5,$06e6,$06e6,$06e7,$06e8,$06e8,$06e9,$06e9
dw $06ea,$06ea,$06eb,$06eb,$06ec,$06ec,$06ed,$06ed
dw $06ee,$06ee,$06ef,$06ef,$06ef,$06f0,$06f0,$06f1
dw $06f1,$06f2,$06f2,$06f3,$06f3,$06f4,$06f4,$06f5
dw $06f5,$06f6,$06f6,$06f7,$06f7,$06f8,$06f8,$06f9
dw $06f9,$06fa,$06fa,$06fb,$06fb,$06fc,$06fc,$06fc
dw $06fd,$06fd,$06fe,$06fe,$06ff,$06ff,$0700,$0700
dw $0701,$0701,$0702,$0702,$0702,$0703,$0703,$0704
dw $0704,$0705,$0705,$0706,$0706,$0707,$0707,$0707
dw $0708,$0708,$0709,$0709,$070a,$070a,$070b,$070b
dw $070b,$070c,$070c,$070d,$070d,$070e,$070e,$070f
dw $070f,$070f,$0710,$0710,$0711,$0711,$0712,$0712
dw $0712,$0713,$0713,$0714,$0714,$0715,$0715,$0715
dw $0716,$0716,$0717,$0717,$0718,$0718,$0718,$0719
dw $0719,$071a,$071a,$071a,$071b,$071b,$071c,$071c
dw $071c,$071d,$071d,$071e,$071e,$071f,$071f,$071f
dw $0720,$0720,$0721,$0721,$0721,$0722,$0722,$0723
dw $0723,$0723,$0724,$0724,$0725,$0725,$0725,$0726
dw $0726,$0727,$0727,$0727,$0728,$0728,$0728,$0729
dw $0729,$072a,$072a,$072a,$072b,$072b,$072c,$072c
dw $072c,$072d,$072d,$072d,$072e,$072e,$072f,$072f
dw $072f,$0730,$0730,$0731,$0731,$0731,$0732,$0732
dw $0732,$0733,$0733,$0733,$0734,$0734,$0735,$0735
dw $0735,$0736,$0736,$0736,$0737,$0737,$0738,$0738
dw $0738,$0739,$0739,$0739,$073a,$073a,$073a,$073b
dw $073b,$073b,$073c,$073c,$073d,$073d,$073d,$073e
dw $073e,$073e,$073f,$073f,$073f,$0740,$0740,$0740
dw $0741,$0741,$0741,$0742,$0742,$0742,$0743,$0743
dw $0743,$0744,$0744,$0744,$0745,$0745,$0745,$0746
dw $0746,$0746,$0747,$0747,$0747,$0748,$0748,$0748
dw $0749,$0749,$0749,$074a,$074a,$074a,$074b,$074b
dw $074b,$074c,$074c,$074c,$074d,$074d,$074d,$074e
dw $074e,$074e,$074f,$074f,$074f,$0750,$0750,$0750
dw $0751,$0751,$0751,$0752,$0752,$0752,$0752,$0753
dw $0753,$0753,$0754,$0754,$0754,$0755,$0755,$0755
dw $0756,$0756,$0756,$0756,$0757,$0757,$0757,$0758
dw $0758,$0758,$0759,$0759,$0759,$075a,$075a,$075a
dw $075a,$075b,$075b,$075b,$075c,$075c,$075c,$075c
dw $075d,$075d,$075d,$075e,$075e,$075e,$075f,$075f
dw $075f,$075f,$0760,$0760,$0760,$0761,$0761,$0761
dw $0761,$0762,$0762,$0762,$0763,$0763,$0763,$0763
dw $0764,$0764,$0764,$0765,$0765,$0765,$0765,$0766
dw $0766,$0766,$0767,$0767,$0767,$0767,$0768,$0768
dw $0768,$0768,$0769,$0769,$0769,$076a,$076a,$076a
dw $076a,$076b,$076b,$076b,$076b,$076c,$076c,$076c
dw $076c,$076d,$076d,$076d,$076e,$076e,$076e,$076e
dw $076f,$076f,$076f,$076f,$0770,$0770,$0770,$0770
dw $0771,$0771,$0771,$0771,$0772,$0772,$0772,$0772
dw $0773,$0773,$0773,$0774,$0774,$0774,$0774,$0775
dw $0775,$0775,$0775,$0776,$0776,$0776,$0776,$0777
dw $0777,$0777,$0777,$0778,$0778,$0778,$0778,$0778
dw $0779,$0779,$0779,$0779,$077a,$077a,$077a,$077a
dw $077b,$077b,$077b,$077b,$077c,$077c,$077c,$077c
dw $077d,$077d,$077d,$077d,$077e,$077e,$077e,$077e
dw $077e,$077f,$077f,$077f,$077f,$0780,$0780,$0780
dw $0780,$0781,$0781,$0781,$0781,$0781,$0782,$0782
dw $0782,$0782,$0783,$0783,$0783,$0783,$0784,$0784
dw $0784,$0784,$0784,$0785,$0785,$0785,$0785,$0786
dw $0786,$0786,$0786,$0786,$0787,$0787,$0787,$0787
dw $0787,$0788,$0788,$0788,$0788,$0789,$0789,$0789
dw $0789,$0789,$078a,$078a,$078a,$078a,$078a,$078b
dw $078b,$078b,$078b,$078c,$078c,$078c,$078c,$078c
dw $078d,$078d,$078d,$078d,$078d,$078e,$078e,$078e
dw $078e,$078e,$078f,$078f,$078f,$078f,$078f,$0790
dw $0790,$0790,$0790,$0790,$0791,$0791,$0791,$0791
dw $0791,$0792,$0792,$0792,$0792,$0792,$0793,$0793
dw $0793,$0793,$0793,$0794,$0794,$0794,$0794,$0794
dw $0795,$0795,$0795,$0795,$0795,$0796,$0796,$0796
dw $0796,$0796,$0797,$0797,$0797,$0797,$0797,$0798
dw $0798,$0798,$0798,$0798,$0798,$0799,$0799,$0799
dw $0799,$0799,$079a,$079a,$079a,$079a,$079a,$079a
dw $079b,$079b,$079b,$079b,$079b,$079c,$079c,$079c
dw $079c,$079c,$079c,$079d,$079d,$079d,$079d,$079d
dw $079e,$079e,$079e,$079e,$079e,$079e,$079f,$079f
dw $079f,$079f,$079f,$079f,$07a0,$07a0,$07a0,$07a0
dw $07a0,$07a1,$07a1,$07a1,$07a1,$07a1,$07a1,$07a2
dw $07a2,$07a2,$07a2,$07a2,$07a2,$07a3,$07a3,$07a3
dw $07a3,$07a3,$07a3,$07a4,$07a4,$07a4,$07a4,$07a4
dw $07a4,$07a5,$07a5,$07a5,$07a5,$07a5,$07a5,$07a6
dw $07a6,$07a6,$07a6,$07a6,$07a6,$07a7,$07a7,$07a7
dw $07a7,$07a7,$07a7,$07a7,$07a8,$07a8,$07a8,$07a8
dw $07a8,$07a8,$07a9,$07a9,$07a9,$07a9,$07a9,$07a9
dw $07aa,$07aa,$07aa,$07aa,$07aa,$07aa,$07aa,$07ab
dw $07ab,$07ab,$07ab,$07ab,$07ab,$07ac,$07ac,$07ac
dw $07ac,$07ac,$07ac,$07ac,$07ad,$07ad,$07ad,$07ad
dw $07ad,$07ad,$07ae,$07ae,$07ae,$07ae,$07ae,$07ae
dw $07ae,$07af,$07af,$07af,$07af,$07af,$07af,$07af
dw $07b0,$07b0,$07b0,$07b0,$07b0,$07b0,$07b0,$07b1
dw $07b1,$07b1,$07b1,$07b1,$07b1,$07b1,$07b2,$07b2
dw $07b2,$07b2,$07b2,$07b2,$07b2,$07b3,$07b3,$07b3
dw $07b3,$07b3,$07b3,$07b3,$07b4,$07b4,$07b4,$07b4
dw $07b4,$07b4,$07b4,$07b4,$07b5,$07b5,$07b5,$07b5
dw $07b5,$07b5,$07b5,$07b6,$07b6,$07b6,$07b6,$07b6
dw $07b6,$07b6,$07b7,$07b7,$07b7,$07b7,$07b7,$07b7
dw $07b7,$07b7,$07b8,$07b8,$07b8,$07b8,$07b8,$07b8
dw $07b8,$07b8,$07b9,$07b9,$07b9,$07b9,$07b9,$07b9
dw $07b9,$07b9,$07ba,$07ba,$07ba,$07ba,$07ba,$07ba
dw $07ba,$07bb,$07bb,$07bb,$07bb,$07bb,$07bb,$07bb
dw $07bb,$07bc,$07bc,$07bc,$07bc,$07bc,$07bc,$07bc
dw $07bc,$07bc,$07bd,$07bd,$07bd,$07bd,$07bd,$07bd
dw $07bd,$07bd,$07be,$07be,$07be,$07be,$07be,$07be
dw $07be,$07be,$07bf,$07bf,$07bf,$07bf,$07bf,$07bf
dw $07bf,$07bf,$07bf,$07c0,$07c0,$07c0,$07c0,$07c0
dw $07c0,$07c0,$07c0,$07c1,$07c1,$07c1,$07c1,$07c1
dw $07c1,$07c1,$07c1,$07c1,$07c2,$07c2,$07c2,$07c2
dw $07c2,$07c2,$07c2,$07c2,$07c2,$07c3,$07c3,$07c3
dw $07c3,$07c3,$07c3,$07c3,$07c3,$07c3,$07c4,$07c4
dw $07c4,$07c4,$07c4,$07c4,$07c4,$07c4,$07c4,$07c4
dw $07c5,$07c5,$07c5,$07c5,$07c5,$07c5,$07c5,$07c5
dw $07c5,$07c6,$07c6,$07c6,$07c6,$07c6,$07c6,$07c6
dw $07c6,$07c6,$07c7,$07c7,$07c7,$07c7,$07c7,$07c7
dw $07c7,$07c7,$07c7,$07c7,$07c8,$07c8,$07c8,$07c8
dw $07c8,$07c8,$07c8,$07c8,$07c8,$07c8,$07c9,$07c9
dw $07c9,$07c9,$07c9,$07c9,$07c9,$07c9,$07c9,$07c9
dw $07ca,$07ca,$07ca,$07ca,$07ca,$07ca,$07ca,$07ca
dw $07ca,$07ca,$07cb,$07cb,$07cb,$07cb,$07cb,$07cb
dw $07cb,$07cb,$07cb,$07cb,$07cb,$07cc,$07cc,$07cc
dw $07cc,$07cc,$07cc,$07cc,$07cc,$07cc,$07cc,$07cd
dw $07cd,$07cd,$07cd,$07cd,$07cd,$07cd,$07cd,$07cd
dw $07cd,$07cd,$07ce,$07ce,$07ce,$07ce,$07ce,$07ce
dw $07ce,$07ce,$07ce,$07ce,$07ce,$07cf,$07cf,$07cf
dw $07cf,$07cf,$07cf,$07cf,$07cf,$07cf,$07cf,$07cf
dw $07cf,$07d0,$07d0,$07d0,$07d0,$07d0,$07d0,$07d0
dw $07d0,$07d0,$07d0,$07d0,$07d1,$07d1,$07d1,$07d1
dw $07d1,$07d1,$07d1,$07d1,$07d1,$07d1,$07d1,$07d1
dw $07d2,$07d2,$07d2,$07d2,$07d2,$07d2,$07d2,$07d2
dw $07d2,$07d2,$07d2,$07d2,$07d3,$07d3,$07d3,$07d3
dw $07d3,$07d3,$07d3,$07d3,$07d3,$07d3,$07d3,$07d3
dw $07d4,$07d4,$07d4,$07d4,$07d4,$07d4,$07d4,$07d4
dw $07d4,$07d4,$07d4,$07d4,$07d4,$07d5,$07d5,$07d5
dw $07d5,$07d5,$07d5,$07d5,$07d5,$07d5,$07d5,$07d5
dw $07d5,$07d5,$07d6,$07d6,$07d6,$07d6,$07d6,$07d6
dw $07d6,$07d6,$07d6,$07d6,$07d6,$07d6,$07d6,$07d7
dw $07d7,$07d7,$07d7,$07d7,$07d7,$07d7,$07d7,$07d7
dw $07d7,$07d7,$07d7,$07d7,$07d7,$07d8,$07d8,$07d8
dw $07d8,$07d8,$07d8,$07d8,$07d8,$07d8,$07d8,$07d8
dw $07d8,$07d8,$07d9,$07d9,$07d9,$07d9,$07d9,$07d9
dw $07d9,$07d9,$07d9,$07d9,$07d9,$07d9,$07d9,$07d9
dw $07d9,$07da,$07da,$07da,$07da,$07da,$07da,$07da
dw $07da,$07da,$07da,$07da,$07da,$07da,$07da,$07db
dw $07db,$07db,$07db,$07db,$07db,$07db,$07db,$07db
dw $07db,$07db,$07db,$07db,$07db,$07db,$07dc,$07dc
dw $07dc,$07dc,$07dc,$07dc,$07dc,$07dc,$07dc,$07dc
dw $07dc,$07dc,$07dc,$07dc,$07dc,$07dc,$07dd,$07dd
dw $07dd,$07dd,$07dd,$07dd,$07dd,$07dd,$07dd,$07dd
dw $07dd,$07dd,$07dd,$07dd,$07dd,$07de,$07de,$07de
dw $07de,$07de,$07de,$07de,$07de,$07de,$07de,$07de
dw $07de,$07de,$07de,$07de,$07de,$07de,$07df,$07df
dw $07df,$07df,$07df,$07df,$07df,$07df,$07df,$07df
dw $07df,$07df,$07df,$07df,$07df,$07df,$07df,$07e0
dw $07e0,$07e0,$07e0,$07e0,$07e0,$07e0,$07e0,$07e0
dw $07e0,$07e0,$07e0,$07e0,$07e0,$07e0,$07e0,$07e0
NoiseTable: ; taken from deflemask
db $a4 ; 15 steps
db $97,$96,$95,$94,$87,$86,$85,$84,$77,$76,$75,$74,$67,$66,$65,$64
db $57,$56,$55,$54,$47,$46,$45,$44,$37,$36,$35,$34,$27,$26,$25,$24
db $17,$16,$15,$14,$07,$06,$05,$04,$03,$02,$01,$00
include "GBMod_SampleData.asm"
; ================
; Player variables
; ================
section "GBMod vars",wram0
GBM_RAM_Start:
GBM_SongID: ds 1
GBM_DoPlay: ds 1
GBM_CurrentRow: ds 1
GBM_CurrentPattern: ds 1
GBM_ModuleSpeed: ds 1
GBM_SpeedChanged: ds 1
GBM_ModuleTimer: ds 1
GBM_TickSpeed: ds 1
GBM_TickTimer: ds 1
GBM_PatternCount: ds 1
GBM_PatTableSize: ds 1
GBM_PatTablePos: ds 1
GBM_SongDataOffset: ds 2
GBM_PanFlags: ds 1
GBM_ArpTick1: ds 1
GBM_ArpTick2: ds 1
GBM_ArpTick3: ds 1
GBM_ArpTick4: ds 1
GBM_CmdTick1: ds 1
GBM_CmdTick2: ds 1
GBM_CmdTick3: ds 1
GBM_CmdTick4: ds 1
GBM_Command1: ds 1
GBM_Command2: ds 1
GBM_Command3: ds 1
GBM_Command4: ds 1
GBM_Param1: ds 1
GBM_Param2: ds 1
GBM_Param3: ds 1
GBM_Param4: ds 1
GBM_Note1: ds 1
GBM_Note2: ds 1
GBM_Note3: ds 1
GBM_Note4: ds 1
GBM_FreqOffset1: ds 2
GBM_FreqOffset2: ds 2
GBM_FreqOffset3: ds 2
GBM_Vol1: ds 1
GBM_Vol2: ds 1
GBM_Vol3: ds 1
GBM_Vol4: ds 1
GBM_OldVol1: ds 1
GBM_OldVol2: ds 1
GBM_OldVol3: ds 1
GBM_OldVol4: ds 1
GBM_Pulse1: ds 1
GBM_Pulse2: ds 1
GBM_Wave3: ds 1
GBM_Mode4: ds 1
GBM_SkipCH1: ds 1
GBM_SkipCH2: ds 1
GBM_SkipCH3: ds 1
GBM_SkipCH4: ds 1
GBM_LastWave: ds 1
GBM_WaveBuffer: ds 16
GBM_SamplePlaying: ds 1
GBM_SampleID: ds 1
GBM_SampleBank: ds 1
GBM_SamplePointer: ds 2
GBM_SampleCounter: ds 2
GBM_RAM_End:
; Note values
C_2 equ $00
C#2 equ $01
D_2 equ $02
D#2 equ $03
E_2 equ $04
F_2 equ $05
F#2 equ $06
G_2 equ $07
G#2 equ $08
A_2 equ $09
A#2 equ $0a
B_2 equ $0b
C_3 equ $0c
C#3 equ $0d
D_3 equ $0e
D#3 equ $0f
E_3 equ $10
F_3 equ $11
F#3 equ $12
G_3 equ $13
G#3 equ $14
A_3 equ $15
A#3 equ $16
B_3 equ $17
C_4 equ $18
C#4 equ $19
D_4 equ $1a
D#4 equ $1b
E_4 equ $1c
F_4 equ $1d
F#4 equ $1e
G_4 equ $1f
G#4 equ $20
A_4 equ $21
A#4 equ $22
B_4 equ $23
C_5 equ $24
C#5 equ $25
D_5 equ $26
D#5 equ $27
E_5 equ $28
F_5 equ $29
F#5 equ $2a
G_5 equ $2b
G#5 equ $2c
A_5 equ $2d
A#5 equ $2e
B_5 equ $2f
C_6 equ $30
C#6 equ $31
D_6 equ $32
D#6 equ $33
E_6 equ $34
F_6 equ $35
F#6 equ $36
G_6 equ $37
G#6 equ $38
A_6 equ $39
A#6 equ $3a
B_6 equ $3b
C_7 equ $3c
C#7 equ $3d
D_7 equ $3e
D#7 equ $3f
E_7 equ $40
F_7 equ $41
F#7 equ $42
G_7 equ $43
G#7 equ $44
A_7 equ $45
A#7 equ $46
B_7 equ $47 |
SECTION code_clib
SECTION code_fp_math48
PUBLIC ___sint2fs
EXTERN cm48_sdccixp_sint2ds
defc ___sint2fs = cm48_sdccixp_sint2ds
|
db DEX_BUTTERFREE ; pokedex id
db 60, 45, 50, 70, 80
; hp atk def spd spc
db BUG, FLYING ; type
db 45 ; catch rate
db 160 ; base exp
INCBIN "gfx/pokemon/front/butterfree.pic", 0, 1 ; sprite dimensions
dw ButterfreePicFront, ButterfreePicBack
db CONFUSION, NO_MOVE, NO_MOVE, NO_MOVE ; level 1 learnset
db GROWTH_MEDIUM_FAST ; growth rate
; tm/hm learnset
tmhm RAZOR_WIND, WHIRLWIND, TOXIC, TAKE_DOWN, DOUBLE_EDGE, \
HYPER_BEAM, RAGE, MEGA_DRAIN, SOLARBEAM, PSYCHIC_M, \
TELEPORT, MIMIC, DOUBLE_TEAM, REFLECT, BIDE, \
SWIFT, REST, PSYWAVE, SUBSTITUTE
; end
db 0 ; padding
|
#include <algorithm>
#include <assert.h>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <sstream>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
struct Node {
Node(){}
Node(Node * p,string t):parent(p),tag(t){}
Node *parent = nullptr;
string tag;
};
void ParseData(unordered_map<string, vector<pair<string, string>>> &dict,
vector<Node *> &hierarchy, Node *¤t,
int &n) {
string line;
getline(cin, line);
string tag, attribute, value;
// Decide if we are dealing with opening tags or closing tags.
if (line[1] != '/') {
tag = line.substr(1, line.find(' ') - 1);
line.erase(0, line.find(' '));
line.erase(line.find('>'), line.find('>'));
// Add tag to hierarchy
// new_tag.tag = tag;
//if (n != 0)
//new_tag.parent = current;
//current = &new_tag;
hierarchy.emplace_back(new Node(current,tag));
current = hierarchy.back();
// cout<<"alive\n";
// Extract the attributes.
while (line.size()) {
// Find Attribute
attribute = line.substr(line.find(' ') + 1, line.find('=') - 2);
line.erase(0, line.find('=') + 3);
// Get Value Attribute
value = line.substr(0, line.find('"'));
line.erase(0, line.find('"') + 1);
// Add value to the map
dict[tag].push_back({attribute, value});
}
} else { // check that the tag exists when closing and check hierarchy
tag = line.substr(2, line.find('>') - 2);
line.clear();
// Find node that matches the closing tag
for (const auto &node : hierarchy)
if (node->tag == tag)
current = node->parent;
assert((dict.find(tag) != dict.end()));
}
// for(auto node:hierarchy)
// cout<<" Tag: "<<node->tag<<endl;
}
void ParseQuery(unordered_map<string, vector<pair<string, string>>> &dict,
vector<Node *> &hierarchy) {
string line;
getline(cin, line);
string tag, attribute, value;
int idx;
bool found = false;
while (line.size()) {
found = false;
idx = line.find('.');
if (idx > 0) { // We have multiple tags
tag = line.substr(0, idx);
line.erase(0, idx + 1);
} else {
idx = line.find('~');
tag = line.substr(0, idx);
for(const auto &node: hierarchy)
if(node->tag == tag && node->parent !)
line.erase(0, idx + 1);
attribute = line;
line.clear();
if (dict.find(tag) != dict.end()) {
for (const auto &attribute_value : dict[tag])
if (attribute_value.first == attribute) {
cout << attribute_value.second << endl;
found = true;
}
if (!found)
cout << "Not Found!" << endl;
} else
cout << "Not Found!" << endl;
}
}
}
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
int N{0}, Q{0};
Node *current = nullptr;
vector<Node *> tag_hierarchy;
unordered_map<string, vector<pair<string, string>>> tag_dict;
// read N and Q;
cin >> N >> Q;
cin.ignore(256, '\n');
// parse the HRML lines
for (int n = 0; n < N; n++) {
ParseData(tag_dict, tag_hierarchy, current, n);
/* cout << " Tag in node: " << node.tag << endl;
cout << "----------------------------" << endl;
cout << "Size of tree " << tag_hierarchy.size() << endl;
for (const auto &nd : tag_hierarchy) {
cout << "Tag in hierarchy: " << nd->tag << " Parent: " << nd->parent
<< endl;
}
cout << "----------------------------" << endl; */
}
// for(auto nodes:tag_hierarchy)
// cout<<" Tag: "<<nodes->tag<<endl;
// parse the queries
for(int q=0;q<Q;q++)
ParseQuery(tag_dict,tag_hierarchy);
return 0;
}
|
dword ],1,F_IMMED,RBRAC
.wp ONE
.wp STATE
.wp POKE
.wp EXIT
dword [,1,F_IMMED,LBRAC
.wp ZERO
.wp STATE
.wp POKE
.wp EXIT
dword \;,1,F_IMMED+F_COMPILEONLY,SEMICOLON
.comp EXIT
.wp REVEAL
.wp LBRAC
.wp EXIT
dword \:,1,,COLON
.wp HEADER
.lit $22
.wp CCOMMA
.comp DOCOL
.wp RBRAC
.wp EXIT
.ifncflag min
dword },1,F_IMMED+F_COMPILEONLY,END_QCOMP
.comp EXIT
.wp LBRAC
.wp LATEST
.wp PEEK
.wp TCFA
.wp EXECUTE
.wp LATEST
.wp PEEK
.wp IFORGET
.wp EXIT
dword {,1,,BEGIN_QCOMP
.wp ZERO
.wp DUP
.wp IHEADER
.lit $22
.wp CCOMMA
.comp DOCOL
.wp RBRAC
.wp EXIT
.endif
dword LITERAL,7,F_IMMED+F_COMPILEONLY,
.comp LIT
.wp COMMA
.wp EXIT
dword [COMPILE],9,F_IMMED+F_COMPILEONLY,COMPILEB
.wp _TICK
.wp COMMA
.wp EXIT
dword (DOES>),7,,NDOES
; replace ent DOVAR with jsr
.wp LATEST
.wp PEEK
.wp TCFA
.wp DUP
.lit $20 ; jsr abs
.wp SWAP
.wp POKEBYTE
.wp INCR
.wp RFETCH
.wp INCRTWO ; skip 'EXIT'
.wp SWAP
.wp POKE
.wp EXIT
.macro .does
.wp NDOES
.wp EXIT
ent DOCOL
.endm
dword DOES>,5,F_IMMED+F_COMPILEONLY,DOES
.comp NDOES
.comp EXIT
.compb $22 ; ent WORD
.comp DOCOL
.wp EXIT
dword POSTPONE,8,F_IMMED+F_COMPILEONLY,
.wp _HTICK
.wp DUP
.wp ISIMMEDIATE
.zbranch POSTPONE_notimmed
.wp TCFA
.wp COMMA
.wp EXIT
POSTPONE_notimmed:
.wp TCFA
.comp LIT
.wp COMMA
.comp COMMA
.wp EXIT |
.global s_prepare_buffers
s_prepare_buffers:
push %r13
push %r14
push %r8
push %r9
push %rax
push %rcx
push %rdi
push %rsi
lea addresses_D_ht+0x17f0b, %rsi
lea addresses_UC_ht+0x1247, %rdi
nop
nop
and $21481, %r9
mov $24, %rcx
rep movsw
nop
nop
nop
nop
nop
cmp %r13, %r13
lea addresses_UC_ht+0xaa47, %rsi
nop
nop
nop
nop
nop
cmp $25038, %r8
mov (%rsi), %r13
nop
nop
nop
nop
add %rcx, %rcx
lea addresses_normal_ht+0x12247, %r13
nop
sub %r8, %r8
mov $0x6162636465666768, %rsi
movq %rsi, %xmm7
movups %xmm7, (%r13)
nop
nop
and %r9, %r9
lea addresses_A_ht+0x4933, %r9
nop
nop
nop
cmp %r14, %r14
movw $0x6162, (%r9)
nop
nop
nop
sub %r13, %r13
lea addresses_WT_ht+0xd7e7, %rsi
lea addresses_D_ht+0x19847, %rdi
dec %r8
mov $87, %rcx
rep movsb
nop
nop
dec %r13
lea addresses_A_ht+0xd647, %rsi
lea addresses_A_ht+0x6b47, %rdi
nop
nop
nop
add $19158, %rax
mov $48, %rcx
rep movsw
nop
nop
nop
nop
dec %r8
lea addresses_D_ht+0x1447, %r8
nop
nop
nop
cmp $55338, %rcx
mov (%r8), %edi
xor $33095, %r9
lea addresses_WC_ht+0x4ba7, %rsi
lea addresses_A_ht+0xac6f, %rdi
nop
nop
nop
nop
nop
cmp %r9, %r9
mov $110, %rcx
rep movsq
nop
nop
nop
add %rcx, %rcx
lea addresses_WC_ht+0x82a7, %rdi
and $61670, %r9
vmovups (%rdi), %ymm7
vextracti128 $0, %ymm7, %xmm7
vpextrq $0, %xmm7, %r13
inc %r13
lea addresses_UC_ht+0x8247, %r13
nop
nop
add $18769, %rsi
mov (%r13), %rax
xor %rsi, %rsi
lea addresses_normal_ht+0x1e247, %rsi
lea addresses_D_ht+0xc987, %rdi
nop
nop
nop
nop
sub %r13, %r13
mov $20, %rcx
rep movsq
nop
add %rax, %rax
lea addresses_WT_ht+0x1893, %rsi
lea addresses_UC_ht+0x4747, %rdi
nop
and %r8, %r8
mov $99, %rcx
rep movsl
add %rax, %rax
lea addresses_A_ht+0x10987, %rax
xor %r13, %r13
mov $0x6162636465666768, %rcx
movq %rcx, (%rax)
cmp %rcx, %rcx
pop %rsi
pop %rdi
pop %rcx
pop %rax
pop %r9
pop %r8
pop %r14
pop %r13
ret
.global s_faulty_load
s_faulty_load:
push %r11
push %r13
push %r14
push %rbp
push %rbx
push %rcx
push %rdi
// Load
mov $0xa47, %rbx
nop
nop
nop
add $6514, %rbp
movb (%rbx), %r14b
nop
xor $31458, %rbx
// Store
mov $0x347, %rbx
sub %r11, %r11
movl $0x51525354, (%rbx)
xor $52451, %r13
// Store
lea addresses_UC+0x75ab, %rbx
nop
nop
cmp $24785, %rdi
movl $0x51525354, (%rbx)
nop
nop
cmp %rbp, %rbp
// Store
lea addresses_WT+0xc95f, %rcx
nop
nop
xor %rbp, %rbp
movw $0x5152, (%rcx)
nop
nop
nop
nop
add $43379, %r11
// Faulty Load
lea addresses_A+0x4c47, %rbx
dec %rcx
movups (%rbx), %xmm7
vpextrq $0, %xmm7, %r13
lea oracles, %r14
and $0xff, %r13
shlq $12, %r13
mov (%r14,%r13,1), %r13
pop %rdi
pop %rcx
pop %rbx
pop %rbp
pop %r14
pop %r13
pop %r11
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'same': False, 'NT': False, 'AVXalign': True, 'size': 32, 'type': 'addresses_A', 'congruent': 0}}
{'OP': 'LOAD', 'src': {'same': False, 'NT': False, 'AVXalign': False, 'size': 1, 'type': 'addresses_P', 'congruent': 9}}
{'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 4, 'type': 'addresses_P', 'congruent': 6}, 'OP': 'STOR'}
{'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 4, 'type': 'addresses_UC', 'congruent': 2}, 'OP': 'STOR'}
{'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 2, 'type': 'addresses_WT', 'congruent': 1}, 'OP': 'STOR'}
[Faulty Load]
{'OP': 'LOAD', 'src': {'same': True, 'NT': False, 'AVXalign': False, 'size': 16, 'type': 'addresses_A', 'congruent': 0}}
<gen_prepare_buffer>
{'dst': {'same': False, 'congruent': 9, 'type': 'addresses_UC_ht'}, 'OP': 'REPM', 'src': {'same': False, 'congruent': 2, 'type': 'addresses_D_ht'}}
{'OP': 'LOAD', 'src': {'same': False, 'NT': False, 'AVXalign': False, 'size': 8, 'type': 'addresses_UC_ht', 'congruent': 9}}
{'dst': {'same': True, 'NT': False, 'AVXalign': False, 'size': 16, 'type': 'addresses_normal_ht', 'congruent': 8}, 'OP': 'STOR'}
{'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 2, 'type': 'addresses_A_ht', 'congruent': 2}, 'OP': 'STOR'}
{'dst': {'same': False, 'congruent': 9, 'type': 'addresses_D_ht'}, 'OP': 'REPM', 'src': {'same': False, 'congruent': 3, 'type': 'addresses_WT_ht'}}
{'dst': {'same': False, 'congruent': 8, 'type': 'addresses_A_ht'}, 'OP': 'REPM', 'src': {'same': False, 'congruent': 5, 'type': 'addresses_A_ht'}}
{'OP': 'LOAD', 'src': {'same': False, 'NT': False, 'AVXalign': False, 'size': 4, 'type': 'addresses_D_ht', 'congruent': 11}}
{'dst': {'same': False, 'congruent': 3, 'type': 'addresses_A_ht'}, 'OP': 'REPM', 'src': {'same': False, 'congruent': 2, 'type': 'addresses_WC_ht'}}
{'OP': 'LOAD', 'src': {'same': False, 'NT': False, 'AVXalign': False, 'size': 32, 'type': 'addresses_WC_ht', 'congruent': 3}}
{'OP': 'LOAD', 'src': {'same': True, 'NT': False, 'AVXalign': False, 'size': 8, 'type': 'addresses_UC_ht', 'congruent': 7}}
{'dst': {'same': False, 'congruent': 5, 'type': 'addresses_D_ht'}, 'OP': 'REPM', 'src': {'same': False, 'congruent': 8, 'type': 'addresses_normal_ht'}}
{'dst': {'same': False, 'congruent': 5, 'type': 'addresses_UC_ht'}, 'OP': 'REPM', 'src': {'same': False, 'congruent': 2, 'type': 'addresses_WT_ht'}}
{'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 8, 'type': 'addresses_A_ht', 'congruent': 5}, 'OP': 'STOR'}
{'00': 21829}
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
*/
|
*= $0801
.byte $4c,$16,$08,$00,$97,$32
.byte $2c,$30,$3a,$9e,$32,$30
.byte $37,$30,$00,$00,$00,$a9
.byte $01,$85,$02
jsr print
.byte 13
.text "(up)decz"
.byte 0
lda #%00011011
sta db
lda #%11000110
sta ab
lda #%10110001
sta xb
lda #%01101100
sta yb
lda #0
sta pb
tsx
stx sb
lda #0
sta db
next ldx db
stx 172
dex
stx dr
lda ab
sta ar
lda xb
sta xr
lda yb
sta yr
lda pb
ora #%00110000
and #%01111101
tax
lda dr
cmp #0
bne nozero
txa
ora #%00000010
tax
lda dr
nozero asl a
bcc noneg
txa
ora #%10000000
tax
noneg stx pr
lda sb
sta sr
ldx sb
txs
lda pb
pha
lda ab
ldx xb
ldy yb
plp
cmd dec 172
php
cld
sta aa
stx xa
sty ya
pla
sta pa
tsx
stx sa
lda 172
sta da
jsr check
dec db
bne next
inc pb
bne next
jsr print
.text " - ok"
.byte 13,0
lda 2
beq load
wait jsr $ffe4
beq wait
jmp $8000
load jsr print
name .text "deczx"
namelen = *-name
.byte 0
lda #0
sta $0a
sta $b9
lda #namelen
sta $b7
lda #<name
sta $bb
lda #>name
sta $bc
pla
pla
jmp $e16f
db .byte 0
ab .byte 0
xb .byte 0
yb .byte 0
pb .byte 0
sb .byte 0
da .byte 0
aa .byte 0
xa .byte 0
ya .byte 0
pa .byte 0
sa .byte 0
dr .byte 0
ar .byte 0
xr .byte 0
yr .byte 0
pr .byte 0
sr .byte 0
check
.block
lda da
cmp dr
bne error
lda aa
cmp ar
bne error
lda xa
cmp xr
bne error
lda ya
cmp yr
bne error
lda pa
cmp pr
bne error
lda sa
cmp sr
bne error
rts
error jsr print
.byte 13
.null "before "
ldx #<db
ldy #>db
jsr showregs
jsr print
.byte 13
.null "after "
ldx #<da
ldy #>da
jsr showregs
jsr print
.byte 13
.null "right "
ldx #<dr
ldy #>dr
jsr showregs
lda #13
jsr $ffd2
wait jsr $ffe4
beq wait
cmp #3
beq stop
rts
stop lda 2
beq basic
jmp $8000
basic jmp ($a002)
showregs stx 172
sty 173
ldy #0
lda (172),y
jsr hexb
lda #32
jsr $ffd2
lda #32
jsr $ffd2
iny
lda (172),y
jsr hexb
lda #32
jsr $ffd2
iny
lda (172),y
jsr hexb
lda #32
jsr $ffd2
iny
lda (172),y
jsr hexb
lda #32
jsr $ffd2
iny
lda (172),y
ldx #"n"
asl a
bcc ok7
ldx #"N"
ok7 pha
txa
jsr $ffd2
pla
ldx #"v"
asl a
bcc ok6
ldx #"V"
ok6 pha
txa
jsr $ffd2
pla
ldx #"0"
asl a
bcc ok5
ldx #"1"
ok5 pha
txa
jsr $ffd2
pla
ldx #"b"
asl a
bcc ok4
ldx #"B"
ok4 pha
txa
jsr $ffd2
pla
ldx #"d"
asl a
bcc ok3
ldx #"D"
ok3 pha
txa
jsr $ffd2
pla
ldx #"i"
asl a
bcc ok2
ldx #"I"
ok2 pha
txa
jsr $ffd2
pla
ldx #"z"
asl a
bcc ok1
ldx #"Z"
ok1 pha
txa
jsr $ffd2
pla
ldx #"c"
asl a
bcc ok0
ldx #"C"
ok0 pha
txa
jsr $ffd2
pla
lda #32
jsr $ffd2
iny
lda (172),y
.bend
hexb pha
lsr a
lsr a
lsr a
lsr a
jsr hexn
pla
and #$0f
hexn ora #$30
cmp #$3a
bcc hexn0
adc #6
hexn0 jmp $ffd2
print pla
.block
sta print0+1
pla
sta print0+2
ldx #1
print0 lda !*,x
beq print1
jsr $ffd2
inx
bne print0
print1 sec
txa
adc print0+1
sta print2+1
lda #0
adc print0+2
sta print2+2
print2 jmp !*
.bend
|
; A128104: a(n) = largest multiple of n which is < exp(n).
; 2,6,18,52,145,402,1092,2976,8100,22020,59873,162744,442403,1202600,3269010,8886096,24154943,65659968,178482295,485165180,1318815729,3584912826,9744803438,26489122128,72004899325,195729609426
mov $2,$0
seq $0,107316 ; Floor(exp(n)/n).
add $2,1
add $3,$0
add $3,1
mul $3,$2
sub $3,$2
mov $0,$3
|
.text
# To test the MEM_to_EX hazard
# To test the WB_to_EX hazard
# If the hazard is handled correctly, $a2 should be 8. Otherwise, it may be -1 or something else
addi $v0, $zero, 1
addiu $v1, $zero, 2
addiu $a0, $zero, 20
addiu $a1, $zero, 16
addi $t1, $zero, 1 # meaningless instruction, just to avoid other hazards
addi $t1, $zero, 1 # meaningless instruction, just to avoid other hazards
addi $t1, $zero, 1 # meaningless instruction, just to avoid other hazards
sub $v0, $a0, $a1 # 4 in $v0
sub $v1, $a1, $a0 # -4 in $v1
sub $a2, $v1, $v0 # -8 in $a2 (if the forward succeeds, $a2 should be 8)
sw $a2, 0($zero) # store $a2, which should be -8, in DATA_MEM[0]
# We only need to care about the value in $a2, so we just store $a2 |
PROGRAM 8
BR L1
L0:
PROC 4
LDLADDR 8
LDCINT 2
STOREW
LDLADDR -8
LOADW
LDLADDR -4
LOADW
LDLADDR 8
LOADW
ADD
STOREW
LDCSTR "m = "
PUTSTR
LDLADDR -8
LOADW
LOADW
PUTINT
LDCSTR ", n = "
PUTSTR
LDLADDR -4
LOADW
PUTINT
LDCSTR ", k = "
PUTSTR
LDLADDR 8
LOADW
PUTINT
PUTEOL
RET 8
L1:
LDGADDR 0
LDCINT 5
STOREW
LDGADDR 4
LDCINT 6
STOREW
LDGADDR 0
LDGADDR 4
LOADW
CALL L0
LDCSTR "x = "
PUTSTR
LDGADDR 0
LOADW
PUTINT
LDCSTR ", y = "
PUTSTR
LDGADDR 4
LOADW
PUTINT
PUTEOL
HALT
|
// Copyright (c) 2006-2008 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 "chrome/renderer/dom_ui_bindings.h"
#include "base/json_writer.h"
#include "base/stl_util-inl.h"
#include "base/values.h"
#include "chrome/common/render_messages.h"
DOMBoundBrowserObject::~DOMBoundBrowserObject() {
STLDeleteContainerPointers(properties_.begin(), properties_.end());
}
DOMUIBindings::DOMUIBindings() {
BindMethod("send", &DOMUIBindings::send);
}
void DOMUIBindings::send(const CppArgumentList& args, CppVariant* result) {
// We expect at least a string message identifier, and optionally take
// an object parameter. If we get anything else we bail.
if (args.size() < 1 || args.size() > 2)
return;
// Require the first parameter to be the message name.
if (!args[0].isString())
return;
const std::string message = args[0].ToString();
// If they've provided an optional message parameter, convert that into JSON.
std::string content;
if (args.size() == 2) {
if (!args[1].isObject())
return;
// TODO(evanm): we ought to support more than just sending arrays of
// strings, but it's not yet necessary for the current code.
std::vector<std::wstring> strings = args[1].ToStringVector();
ListValue value;
for (size_t i = 0; i < strings.size(); ++i) {
value.Append(Value::CreateStringValue(strings[i]));
}
JSONWriter::Write(&value, /* pretty_print= */ false, &content);
}
// Send the message up to the browser.
sender()->Send(
new ViewHostMsg_DOMUISend(routing_id(), message, content));
}
void DOMBoundBrowserObject::SetProperty(const std::string& name,
const std::string& value) {
CppVariant* cpp_value = new CppVariant;
cpp_value->Set(value);
BindProperty(name, cpp_value);
properties_.push_back(cpp_value);
}
|
; A042415: Denominators of continued fraction convergents to sqrt(735).
; Submitted by Jon Maiga
; 1,9,487,4392,237655,2143287,115975153,1045919664,56595637009,510406652745,27618554885239,249077400619896,13477798188359623,121549261095856503,6577137897364610785,59315790337377353568,3209629816115741703457,28945984135379052684681,1566292773126584586676231,14125580942274640332770760,764347663655957162556297271,6893254553845889103339446199,373000093571333968742886392017,3363894096695851607789316974352,182023281315147320789366003007025,1641573425933021738712083344037577
add $0,1
mov $3,1
lpb $0
sub $0,1
add $2,$3
mov $3,$1
mov $1,$2
dif $2,6
mul $2,27
add $3,$2
lpe
mov $0,$2
div $0,27
|
;
; ANSI Video handling for Sharp OZ family
;
; CLS - Clear the text screen
;
;
; Stefano Bodrato - Aug. 2002
;
;
; $Id: f_ansi_cls.asm,v 1.4 2015/01/19 01:33:18 pauloscustodio Exp $
;
PUBLIC ansi_cls
EXTERN base_graphics
EXTERN swapgfxbk
EXTERN swapgfxbk1
.ansi_cls
call swapgfxbk
ld hl,(base_graphics)
ld d,h
ld e,l
inc de
ld bc,2400-1
xor a
ld (hl),a
ldir
jp swapgfxbk1
|
; A082181: a(0)=1; for n>=1, a(n) = sum(k=0..n, 9^k*N(n,k)), where N(n,k) =1/n*C(n,k)*C(n,k+1) are the Narayana numbers (A001263).
; Submitted by Christian Krause
; 1,1,10,109,1270,15562,198100,2596645,34825150,475697854,6595646860,92590323058,1313427716380,18798095833012,271118225915560,3936516861402901,57494017447915150,844109420603623030,12450759123400155100,184419491302065776518,2741920337983270198420,40906056234083127141196,612171571653789513771160,9187477819399898263302274,138247080089176661934491020,2085273149751535157858448172,31523770050233613991719643000,477541467393619970108496204100,7248008748375939650946600907000
mov $1,1
mov $3,$0
mov $4,1
lpb $3
mul $4,$3
sub $3,1
mul $4,$3
add $5,$1
add $1,1
div $4,2
div $4,$5
mul $4,9
add $2,$4
lpe
mov $0,$2
add $0,1
|
.global s_prepare_buffers
s_prepare_buffers:
push %r10
push %r12
push %r8
push %r9
push %rbp
push %rcx
push %rdi
push %rsi
lea addresses_D_ht+0x15313, %r12
clflush (%r12)
nop
nop
nop
add %rbp, %rbp
mov (%r12), %r10d
nop
nop
sub $56400, %r10
lea addresses_WT_ht+0xf9ab, %r8
add $49020, %r9
mov (%r8), %r10d
nop
nop
nop
nop
xor %r9, %r9
lea addresses_WC_ht+0x1242b, %rsi
lea addresses_UC_ht+0x90ab, %rdi
nop
nop
nop
nop
nop
cmp %r12, %r12
mov $71, %rcx
rep movsl
nop
sub $37067, %r12
lea addresses_normal_ht+0xc83, %rbp
nop
nop
nop
nop
nop
cmp $8479, %rsi
movw $0x6162, (%rbp)
and $1663, %r10
lea addresses_UC_ht+0x19ab, %rsi
clflush (%rsi)
nop
nop
nop
nop
nop
and %r9, %r9
mov (%rsi), %r12d
nop
nop
nop
nop
nop
cmp $62393, %rdi
lea addresses_WT_ht+0xfab, %rsi
lea addresses_WT_ht+0x174af, %rdi
sub $45950, %r10
mov $52, %rcx
rep movsq
nop
nop
nop
cmp $12584, %r8
lea addresses_normal_ht+0x14dab, %rsi
lea addresses_normal_ht+0x121cb, %rdi
clflush (%rdi)
nop
nop
nop
cmp $8442, %r12
mov $23, %rcx
rep movsb
nop
nop
nop
nop
and %r9, %r9
pop %rsi
pop %rdi
pop %rcx
pop %rbp
pop %r9
pop %r8
pop %r12
pop %r10
ret
.global s_faulty_load
s_faulty_load:
push %r14
push %r15
push %rax
push %rbx
push %rcx
push %rdx
push %rsi
// Store
mov $0xa0b, %rsi
nop
nop
nop
nop
add $42233, %r15
movb $0x51, (%rsi)
nop
nop
nop
nop
nop
dec %rsi
// Load
lea addresses_RW+0x1f7f, %r14
clflush (%r14)
sub %rax, %rax
mov (%r14), %ebx
nop
nop
sub $55020, %rsi
// Store
lea addresses_normal+0xe5ab, %rcx
clflush (%rcx)
inc %rax
mov $0x5152535455565758, %rbx
movq %rbx, %xmm3
movups %xmm3, (%rcx)
nop
nop
sub $30265, %rcx
// Store
lea addresses_WT+0xbf2b, %rax
nop
sub $48829, %r15
movl $0x51525354, (%rax)
nop
nop
inc %rcx
// Store
lea addresses_A+0xa1ab, %rsi
nop
and %r15, %r15
movl $0x51525354, (%rsi)
nop
nop
nop
nop
nop
xor $21937, %rsi
// Load
lea addresses_US+0x121ab, %rsi
nop
nop
nop
and $39901, %rax
movups (%rsi), %xmm4
vpextrq $1, %xmm4, %rbx
inc %rsi
// Load
lea addresses_PSE+0x4fab, %rcx
sub %rax, %rax
mov (%rcx), %si
nop
nop
nop
nop
nop
cmp $19805, %rcx
// Store
mov $0xf33, %rax
nop
nop
xor %r15, %r15
mov $0x5152535455565758, %rsi
movq %rsi, %xmm1
vmovaps %ymm1, (%rax)
nop
nop
xor %r15, %r15
// Faulty Load
lea addresses_US+0x121ab, %r14
clflush (%r14)
nop
nop
nop
nop
nop
and $48225, %rsi
mov (%r14), %cx
lea oracles, %rbx
and $0xff, %rcx
shlq $12, %rcx
mov (%rbx,%rcx,1), %rcx
pop %rsi
pop %rdx
pop %rcx
pop %rbx
pop %rax
pop %r15
pop %r14
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'same': False, 'type': 'addresses_US', 'NT': False, 'AVXalign': False, 'size': 32, 'congruent': 0}}
{'OP': 'STOR', 'dst': {'same': False, 'type': 'addresses_P', 'NT': False, 'AVXalign': False, 'size': 1, 'congruent': 1}}
{'OP': 'LOAD', 'src': {'same': False, 'type': 'addresses_RW', 'NT': False, 'AVXalign': False, 'size': 4, 'congruent': 1}}
{'OP': 'STOR', 'dst': {'same': False, 'type': 'addresses_normal', 'NT': False, 'AVXalign': False, 'size': 16, 'congruent': 10}}
{'OP': 'STOR', 'dst': {'same': False, 'type': 'addresses_WT', 'NT': False, 'AVXalign': True, 'size': 4, 'congruent': 5}}
{'OP': 'STOR', 'dst': {'same': False, 'type': 'addresses_A', 'NT': False, 'AVXalign': False, 'size': 4, 'congruent': 10}}
{'OP': 'LOAD', 'src': {'same': True, 'type': 'addresses_US', 'NT': False, 'AVXalign': False, 'size': 16, 'congruent': 0}}
{'OP': 'LOAD', 'src': {'same': False, 'type': 'addresses_PSE', 'NT': False, 'AVXalign': False, 'size': 2, 'congruent': 9}}
{'OP': 'STOR', 'dst': {'same': False, 'type': 'addresses_P', 'NT': False, 'AVXalign': True, 'size': 32, 'congruent': 3}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'same': True, 'type': 'addresses_US', 'NT': False, 'AVXalign': False, 'size': 2, 'congruent': 0}}
<gen_prepare_buffer>
{'OP': 'LOAD', 'src': {'same': False, 'type': 'addresses_D_ht', 'NT': True, 'AVXalign': False, 'size': 4, 'congruent': 3}}
{'OP': 'LOAD', 'src': {'same': True, 'type': 'addresses_WT_ht', 'NT': False, 'AVXalign': False, 'size': 4, 'congruent': 8}}
{'OP': 'REPM', 'src': {'same': False, 'congruent': 6, 'type': 'addresses_WC_ht'}, 'dst': {'same': False, 'congruent': 8, 'type': 'addresses_UC_ht'}}
{'OP': 'STOR', 'dst': {'same': False, 'type': 'addresses_normal_ht', 'NT': False, 'AVXalign': True, 'size': 2, 'congruent': 3}}
{'OP': 'LOAD', 'src': {'same': False, 'type': 'addresses_UC_ht', 'NT': False, 'AVXalign': True, 'size': 4, 'congruent': 10}}
{'OP': 'REPM', 'src': {'same': False, 'congruent': 9, 'type': 'addresses_WT_ht'}, 'dst': {'same': False, 'congruent': 2, 'type': 'addresses_WT_ht'}}
{'OP': 'REPM', 'src': {'same': True, 'congruent': 10, 'type': 'addresses_normal_ht'}, 'dst': {'same': False, 'congruent': 2, 'type': 'addresses_normal_ht'}}
{'54': 21829}
54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54
*/
|
; A065330: a(n) = max { k | gcd(n, k) = k and gcd(k, 6) = 1 }.
; 1,1,1,1,5,1,7,1,1,5,11,1,13,7,5,1,17,1,19,5,7,11,23,1,25,13,1,7,29,5,31,1,11,17,35,1,37,19,13,5,41,7,43,11,5,23,47,1,49,25,17,13,53,1,55,7,19,29,59,5,61,31,7,1,65,11,67,17,23,35,71,1,73,37,25,19,77,13,79,5,1,41,83,7,85,43,29,11,89,5,91,23,31,47,95,1,97,49,11,25
add $0,1
mov $2,2985984
gcd $2,$0
div $0,$2
|
/**
* Copyright (C) 2016 D Levin (http://www.kfrlib.com)
* This file is part of KFR
*
* KFR 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, either version 3 of the License, or
* (at your option) any later version.
*
* KFR 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 KFR.
*
* If GPL is not suitable for your project, you must purchase a commercial license to use KFR.
* Buying a commercial license is mandatory as soon as you develop commercial activities without
* disclosing the source code of your own applications.
* See http://www.kfrlib.com for details.
*/
#pragma once
#include "../base/function.hpp"
#include "../base/log_exp.hpp"
#include "../base/select.hpp"
#include "../base/sin_cos.hpp"
#include "../base/vec.hpp"
namespace kfr
{
namespace internal
{
template <typename T, size_t width_, typename Class>
struct generator : input_expression
{
constexpr static size_t width = width_;
using type = T;
template <typename U, size_t N>
CMT_INLINE vec<U, N> operator()(cinput_t, size_t, vec_t<U, N> t) const
{
return generate(t);
}
void resync(T start) const { ptr_cast<Class>(this)->sync(start); }
protected:
void call_next() const { ptr_cast<Class>(this)->next(); }
template <size_t N>
void call_shift(csize_t<N>) const
{
ptr_cast<Class>(this)->shift(csize<N>);
}
template <size_t N>
void shift(csize_t<N>) const
{
const vec<T, width> oldvalue = value;
call_next();
value = slice<N, width>(oldvalue, value);
}
template <size_t N, KFR_ENABLE_IF(N == width)>
CMT_INLINE vec<T, N> generate(vec_t<T, N>) const
{
const vec<T, N> result = value;
call_next();
return result;
}
template <size_t N, KFR_ENABLE_IF(N < width)>
CMT_INLINE vec<T, N> generate(vec_t<T, N>) const
{
const vec<T, N> result = narrow<N>(value);
shift(csize<N>);
return result;
}
template <size_t N, KFR_ENABLE_IF(N > width)>
CMT_INLINE vec<T, N> generate(vec_t<T, N> x) const
{
const auto lo = generate(low(x));
const auto hi = generate(high(x));
return concat(lo, hi);
}
mutable vec<T, width> value;
};
template <typename T, size_t width = get_vector_width<T, cpu_t::native>(1, 2)>
struct generator_linear : generator<T, width, generator_linear<T, width>>
{
constexpr generator_linear(T start, T step) noexcept : step(step), vstep(step* width)
{
this->resync(start);
}
CMT_INLINE void sync(T start) const noexcept { this->value = start + enumerate<T, width>() * step; }
CMT_INLINE void next() const noexcept { this->value += vstep; }
protected:
T step;
T vstep;
};
template <typename T, size_t width = get_vector_width<T, cpu_t::native>(1, 2), KFR_ARCH_DEP>
struct generator_exp : generator<T, width, generator_exp<T, width>>
{
generator_exp(T start, T step) noexcept : step(step), vstep(exp(make_vector(step* width))[0] - 1)
{
this->resync(start);
}
CMT_INLINE void sync(T start) const noexcept { this->value = exp(start + enumerate<T, width>() * step); }
CMT_INLINE void next() const noexcept { this->value += this->value * vstep; }
protected:
T step;
T vstep;
};
template <typename T, size_t width = get_vector_width<T, cpu_t::native>(1, 2), KFR_ARCH_DEP>
struct generator_exp2 : generator<T, width, generator_exp2<T, width>>
{
generator_exp2(T start, T step) noexcept : step(step), vstep(exp2(make_vector(step* width))[0] - 1)
{
this->resync(start);
}
CMT_INLINE void sync(T start) const noexcept { this->value = exp2(start + enumerate<T, width>() * step); }
CMT_INLINE void next() const noexcept { this->value += this->value * vstep; }
protected:
T step;
T vstep;
};
template <typename T, size_t width = get_vector_width<T, cpu_t::native>(1, 2), KFR_ARCH_DEP>
struct generator_cossin : generator<T, width, generator_cossin<T, width>>
{
generator_cossin(T start, T step)
: step(step), alpha(2 * sqr(sin(width / 2 * step / 2))), beta(-sin(width / 2 * step))
{
this->resync(start);
}
CMT_INLINE void sync(T start) const noexcept { this->value = init_cossin(step, start); }
CMT_INLINE void next() const noexcept
{
this->value = this->value - subadd(alpha * this->value, beta * swap<2>(this->value));
}
protected:
T step;
T alpha;
T beta;
CMT_NOINLINE static vec<T, width> init_cossin(T w, T phase)
{
return cossin(dup(phase + enumerate<T, width / 2>() * w));
}
};
template <typename T, size_t width = get_vector_width<T, cpu_t::native>(2, 4), KFR_ARCH_DEP>
struct generator_sin : generator<T, width, generator_sin<T, width>>
{
generator_sin(T start, T step)
: step(step), alpha(2 * sqr(sin(width * step / 2))), beta(sin(width * step))
{
this->resync(start);
}
CMT_INLINE void sync(T start) const noexcept
{
const vec<T, width* 2> cs = splitpairs(cossin(dup(start + enumerate<T, width>() * step)));
this->cos_value = low(cs);
this->value = high(cs);
}
CMT_INLINE void next() const noexcept
{
const vec<T, width> c = this->cos_value;
const vec<T, width> s = this->value;
const vec<T, width> cc = alpha * c + beta * s;
const vec<T, width> ss = alpha * s - beta * c;
this->cos_value = c - cc;
this->value = s - ss;
}
template <size_t N>
void shift(csize_t<N>) const noexcept
{
const vec<T, width> oldvalue = this->value;
const vec<T, width> oldcosvalue = this->cos_value;
next();
this->value = slice<N, width>(oldvalue, this->value);
this->cos_value = slice<N, width>(oldcosvalue, this->cos_value);
}
protected:
T step;
T alpha;
T beta;
mutable vec<T, width> cos_value;
};
}
template <typename T1, typename T2, typename TF = ftype<common_type<T1, T2>>>
KFR_SINTRIN internal::generator_linear<TF> gen_linear(T1 start, T2 step)
{
return internal::generator_linear<TF>(start, step);
}
template <typename T1, typename T2, typename TF = ftype<common_type<T1, T2>>>
KFR_SINTRIN internal::generator_exp<TF> gen_exp(T1 start, T2 step)
{
return internal::generator_exp<TF>(start, step);
}
template <typename T1, typename T2, typename TF = ftype<common_type<T1, T2>>>
KFR_SINTRIN internal::generator_exp2<TF> gen_exp2(T1 start, T2 step)
{
return internal::generator_exp2<TF>(start, step);
}
template <typename T1, typename T2, typename TF = ftype<common_type<T1, T2>>>
KFR_SINTRIN internal::generator_cossin<TF> gen_cossin(T1 start, T2 step)
{
return internal::generator_cossin<TF>(start, step);
}
template <typename T1, typename T2, typename TF = ftype<common_type<T1, T2>>>
KFR_SINTRIN internal::generator_sin<TF> gen_sin(T1 start, T2 step)
{
return internal::generator_sin<TF>(start, step);
}
}
|
.global s_prepare_buffers
s_prepare_buffers:
push %r14
push %r9
push %rbp
push %rbx
push %rcx
push %rdi
push %rsi
lea addresses_WT_ht+0xd893, %rsi
lea addresses_WC_ht+0xdb27, %rdi
sub $17849, %r9
mov $40, %rcx
rep movsl
nop
nop
add %r14, %r14
lea addresses_WC_ht+0x24b3, %rsi
lea addresses_A_ht+0x2b63, %rdi
clflush (%rdi)
nop
nop
nop
nop
add $37363, %rbp
mov $49, %rcx
rep movsw
nop
nop
nop
nop
sub %rbp, %rbp
lea addresses_WC_ht+0x1dead, %rbp
xor %rbx, %rbx
movl $0x61626364, (%rbp)
xor %rbp, %rbp
lea addresses_A_ht+0xc5b3, %rsi
lea addresses_WT_ht+0x1b2bb, %rdi
nop
inc %r14
mov $55, %rcx
rep movsl
nop
nop
nop
inc %r9
lea addresses_A_ht+0x1a19b, %r9
clflush (%r9)
nop
nop
nop
nop
add %r14, %r14
mov $0x6162636465666768, %rcx
movq %rcx, %xmm3
vmovups %ymm3, (%r9)
nop
nop
nop
nop
xor %rdi, %rdi
pop %rsi
pop %rdi
pop %rcx
pop %rbx
pop %rbp
pop %r9
pop %r14
ret
.global s_faulty_load
s_faulty_load:
push %r10
push %r13
push %r15
push %r8
push %r9
push %rax
push %rsi
// Store
lea addresses_A+0x18c93, %r15
nop
nop
nop
inc %r8
mov $0x5152535455565758, %r9
movq %r9, (%r15)
nop
nop
nop
nop
dec %rsi
// Faulty Load
lea addresses_WC+0x15c93, %r13
and %rax, %rax
mov (%r13), %r8w
lea oracles, %rsi
and $0xff, %r8
shlq $12, %r8
mov (%rsi,%r8,1), %r8
pop %rsi
pop %rax
pop %r9
pop %r8
pop %r15
pop %r13
pop %r10
ret
/*
<gen_faulty_load>
[REF]
{'src': {'NT': False, 'same': False, 'congruent': 0, 'type': 'addresses_WC', 'AVXalign': False, 'size': 2}, 'OP': 'LOAD'}
{'OP': 'STOR', 'dst': {'NT': False, 'same': False, 'congruent': 11, 'type': 'addresses_A', 'AVXalign': False, 'size': 8}}
[Faulty Load]
{'src': {'NT': False, 'same': True, 'congruent': 0, 'type': 'addresses_WC', 'AVXalign': False, 'size': 2}, 'OP': 'LOAD'}
<gen_prepare_buffer>
{'src': {'same': False, 'congruent': 10, 'type': 'addresses_WT_ht'}, 'OP': 'REPM', 'dst': {'same': False, 'congruent': 2, 'type': 'addresses_WC_ht'}}
{'src': {'same': False, 'congruent': 5, 'type': 'addresses_WC_ht'}, 'OP': 'REPM', 'dst': {'same': False, 'congruent': 3, 'type': 'addresses_A_ht'}}
{'OP': 'STOR', 'dst': {'NT': False, 'same': False, 'congruent': 1, 'type': 'addresses_WC_ht', 'AVXalign': False, 'size': 4}}
{'src': {'same': False, 'congruent': 5, 'type': 'addresses_A_ht'}, 'OP': 'REPM', 'dst': {'same': False, 'congruent': 1, 'type': 'addresses_WT_ht'}}
{'OP': 'STOR', 'dst': {'NT': False, 'same': False, 'congruent': 1, 'type': 'addresses_A_ht', 'AVXalign': False, 'size': 32}}
{'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
*/
|
; A003149: a(n) = Sum_{k=0..n} k!(n-k)!.
; Submitted by Christian Krause
; 1,2,5,16,64,312,1812,12288,95616,840960,8254080,89441280,1060369920,13649610240,189550368000,2824077312000,44927447040000,760034451456000,13622700994560000,257872110354432000,5140559166898176000,107637093007589376000,2361827297364885504000,54193944307263602688000,1297872705574034472960000,32383555215793434132480000,840469456539816996372480000,22655441841975790109982720000,633392251320362817096253440000,18342645763545144210987417600000,549563869147140793906613452800000
mov $1,1
mov $2,1
mov $3,1
lpb $0
mul $3,$0
sub $0,1
add $2,1
add $3,$1
mul $1,$2
lpe
mov $0,$3
|
// Copyright 2015 Google Inc. All rights reserved.
//
// 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 "colorprint.h"
#include <cstdarg>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <memory>
#include <string>
#include "check.h"
#include "internal_macros.h"
#ifdef BENCHMARK_OS_WINDOWS
#include <windows.h>
#include <io.h>
#else
#include <unistd.h>
#endif // BENCHMARK_OS_WINDOWS
namespace benchmark {
namespace {
#ifdef BENCHMARK_OS_WINDOWS
typedef WORD PlatformColorCode;
#else
typedef const char* PlatformColorCode;
#endif
PlatformColorCode GetPlatformColorCode(LogColor color) {
#ifdef BENCHMARK_OS_WINDOWS
switch (color) {
case COLOR_RED:
return FOREGROUND_RED;
case COLOR_GREEN:
return FOREGROUND_GREEN;
case COLOR_YELLOW:
return FOREGROUND_RED | FOREGROUND_GREEN;
case COLOR_BLUE:
return FOREGROUND_BLUE;
case COLOR_MAGENTA:
return FOREGROUND_BLUE | FOREGROUND_RED;
case COLOR_CYAN:
return FOREGROUND_BLUE | FOREGROUND_GREEN;
case COLOR_WHITE: // fall through to default
default:
return 0;
}
#else
switch (color) {
case COLOR_RED:
return "1";
case COLOR_GREEN:
return "2";
case COLOR_YELLOW:
return "3";
case COLOR_BLUE:
return "4";
case COLOR_MAGENTA:
return "5";
case COLOR_CYAN:
return "6";
case COLOR_WHITE:
return "7";
default:
return nullptr;
};
#endif
}
} // end namespace
std::string FormatString(const char* msg, va_list args) {
// we might need a second shot at this, so pre-emptivly make a copy
va_list args_cp;
va_copy(args_cp, args);
std::size_t size = 256;
char local_buff[256];
auto ret = vsnprintf(local_buff, size, msg, args_cp);
va_end(args_cp);
// currently there is no error handling for failure, so this is hack.
CHECK(ret >= 0);
if (ret == 0) // handle empty expansion
return {};
else if (static_cast<size_t>(ret) < size)
return local_buff;
else {
// we did not provide a long enough buffer on our first attempt.
size = (size_t)ret + 1; // + 1 for the null byte
std::unique_ptr<char[]> buff(new char[size]);
ret = vsnprintf(buff.get(), size, msg, args);
CHECK(ret > 0 && ((size_t)ret) < size);
return buff.get();
}
}
std::string FormatString(const char* msg, ...) {
va_list args;
va_start(args, msg);
auto tmp = FormatString(msg, args);
va_end(args);
return tmp;
}
void ColorPrintf(std::ostream& out, LogColor color, const char* fmt, ...) {
va_list args;
va_start(args, fmt);
ColorPrintf(out, color, fmt, args);
va_end(args);
}
void ColorPrintf(std::ostream& out, LogColor color, const char* fmt,
va_list args) {
#ifdef BENCHMARK_OS_WINDOWS
((void)out); // suppress unused warning
const HANDLE stdout_handle = GetStdHandle(STD_OUTPUT_HANDLE);
// Gets the current text color.
CONSOLE_SCREEN_BUFFER_INFO buffer_info;
GetConsoleScreenBufferInfo(stdout_handle, &buffer_info);
const WORD old_color_attrs = buffer_info.wAttributes;
// We need to flush the stream buffers into the console before each
// SetConsoleTextAttribute call lest it affect the text that is already
// printed but has not yet reached the console.
fflush(stdout);
SetConsoleTextAttribute(stdout_handle,
GetPlatformColorCode(color) | FOREGROUND_INTENSITY);
vprintf(fmt, args);
fflush(stdout);
// Restores the text color.
SetConsoleTextAttribute(stdout_handle, old_color_attrs);
#else
const char* color_code = GetPlatformColorCode(color);
if (color_code) out << FormatString("\033[0;3%sm", color_code);
out << FormatString(fmt, args) << "\033[m";
#endif
}
bool IsColorTerminal() {
#if BENCHMARK_OS_WINDOWS
// On Windows the TERM variable is usually not set, but the
// console there does support colors.
return 0 != _isatty(_fileno(stdout));
#else
// On non-Windows platforms, we rely on the TERM variable. This list of
// supported TERM values is copied from Google Test:
// <https://github.com/google/googletest/blob/master/googletest/src/gtest.cc#L2925>.
const char* const SUPPORTED_TERM_VALUES[] = {
"xterm", "xterm-color", "xterm-256color",
"screen", "screen-256color", "tmux",
"tmux-256color", "rxvt-unicode", "rxvt-unicode-256color",
"linux", "cygwin",
};
const char* const term = getenv("TERM");
bool term_supports_color = false;
for (const char* candidate : SUPPORTED_TERM_VALUES) {
if (term && 0 == strcmp(term, candidate)) {
term_supports_color = true;
break;
}
}
return 0 != isatty(fileno(stdout)) && term_supports_color;
#endif // BENCHMARK_OS_WINDOWS
}
} // end namespace benchmark
|
/******************************************************************************
* Copyright (c) 2017 Philipp Schubert.
* All rights reserved. This program and the accompanying materials are made
* available under the terms of LICENSE.txt.
*
* Contributors:
* Philipp Schubert and others
*****************************************************************************/
#include <llvm/IR/CallSite.h>
#include <llvm/IR/Function.h>
#include <llvm/IR/Instruction.h>
#include <llvm/IR/IntrinsicInst.h>
#include <llvm/IR/Value.h>
#include <phasar/PhasarLLVM/ControlFlow/LLVMBasedICFG.h>
#include <phasar/PhasarLLVM/IfdsIde/FlowFunction.h>
#include <phasar/PhasarLLVM/IfdsIde/FlowFunctions/GenAll.h>
#include <phasar/PhasarLLVM/IfdsIde/FlowFunctions/Identity.h>
#include <phasar/PhasarLLVM/IfdsIde/FlowFunctions/KillAll.h>
#include <phasar/PhasarLLVM/IfdsIde/LLVMFlowFunctions/MapFactsToCallee.h>
#include <phasar/PhasarLLVM/IfdsIde/LLVMFlowFunctions/MapFactsToCaller.h>
#include <phasar/PhasarLLVM/IfdsIde/LLVMZeroValue.h>
#include <phasar/PhasarLLVM/IfdsIde/Problems/IFDSConstAnalysis.h>
#include <phasar/Utils/LLVMIRToSrc.h>
#include <phasar/Utils/LLVMShorthands.h>
#include <phasar/Utils/Logger.h>
#include <phasar/Utils/Macros.h>
#include <phasar/Utils/PAMMMacros.h>
using namespace std;
using namespace psr;
namespace psr {
IFDSConstAnalysis::IFDSConstAnalysis(IFDSConstAnalysis::i_t icfg,
const LLVMTypeHierarchy &th,
const ProjectIRDB &irdb,
set<IFDSConstAnalysis::d_t> AllMemLocs,
vector<string> EntryPoints)
: LLVMDefaultIFDSTabulationProblem(icfg, th, irdb),
ptg(icfg.getWholeModulePTG()), AllMemLocs(AllMemLocs),
EntryPoints(EntryPoints) {
PAMM_GET_INSTANCE;
REG_HISTOGRAM("Context-relevant Pointer", PAMM_SEVERITY_LEVEL::Full);
REG_COUNTER("[Calls] getContextRelevantPointsToSet", 0,
PAMM_SEVERITY_LEVEL::Full);
IFDSConstAnalysis::zerovalue = createZeroValue();
}
shared_ptr<FlowFunction<IFDSConstAnalysis::d_t>>
IFDSConstAnalysis::getNormalFlowFunction(IFDSConstAnalysis::n_t curr,
IFDSConstAnalysis::n_t succ) {
auto &lg = lg::get();
LOG_IF_ENABLE(BOOST_LOG_SEV(lg, DEBUG)
<< "IFDSConstAnalysis::getNormalFlowFunction()");
// Check all store instructions.
if (const llvm::StoreInst *Store = llvm::dyn_cast<llvm::StoreInst>(curr)) {
// If the store instruction sets up or updates the vtable, i.e. value
// operand is vtable pointer, ignore it!
// Setting up the vtable is counted towards the initialization of an
// object - the object stays immutable.
// To identifiy such a store instruction, we need to check the stored
// value, which is of i32 (...)** type, e.g.
// i32 (...)** bitcast (i8** getelementptr inbounds ([3 x i8*], [3 x i8*]*
// @_ZTV5Child, i32 0, i32 2) to i32 (...)**)
//
// WARNING: The VTT could also be stored, which would make this analysis
// fail
if (const llvm::ConstantExpr *CE =
llvm::dyn_cast<llvm::ConstantExpr>(Store->getValueOperand())) {
// llvm::ConstantExpr *CE = const_cast<llvm::ConstantExpr *>(ConstCE);
auto CE_inst = const_cast<llvm::ConstantExpr *>(CE)->getAsInstruction();
if (llvm::ConstantExpr *CF =
llvm::dyn_cast<llvm::ConstantExpr>(CE_inst->getOperand(0))) {
auto CF_inst = CF->getAsInstruction();
if (auto VTable =
llvm::dyn_cast<llvm::GlobalVariable>(CF_inst->getOperand(0))) {
if (VTable->hasName() &&
cxx_demangle(VTable->getName().str()).find("vtable") !=
string::npos) {
LOG_IF_ENABLE(
BOOST_LOG_SEV(lg, DEBUG)
<< "Store Instruction sets up or updates vtable - ignored!");
return Identity<IFDSConstAnalysis::d_t>::getInstance();
}
}
CF_inst->deleteValue();
}
CE_inst->deleteValue();
} /* end vtable set-up instruction */
IFDSConstAnalysis::d_t pointerOp = Store->getPointerOperand();
LOG_IF_ENABLE(BOOST_LOG_SEV(lg, DEBUG)
<< "Pointer operand of store Instruction: "
<< llvmIRToString(pointerOp));
set<IFDSConstAnalysis::d_t> pointsToSet = ptg.getPointsToSet(pointerOp);
// Check if this store instruction is the second write access to the memory
// location the pointer operand or it's alias are pointing to.
// This is done by checking the Initialized set.
// If so, generate the pointer operand as a new data-flow fact. Also
// generate data-flow facts of all alias that meet the 'context-relevant'
// requirements! (see getContextRelevantPointsToSet function)
// NOTE: The points-to set of value x also contains the value x itself!
for (auto alias : pointsToSet) {
if (isInitialized(alias)) {
LOG_IF_ENABLE(BOOST_LOG_SEV(lg, DEBUG)
<< "Compute context-relevant points-to "
"information for the pointer operand.");
return make_shared<
GenAll<IFDSConstAnalysis::d_t>>(/*pointsToSet*/
getContextRelevantPointsToSet(
pointsToSet,
curr->getFunction()),
zeroValue());
}
}
// If neither the pointer operand nor one of its alias is initialized,
// we mark only the pointer operand (to keep the Initialized set as
// small as possible) as initialized by adding it to the Initialized set.
// We do not generate any new data-flow facts at this point.
markAsInitialized(pointerOp);
LOG_IF_ENABLE(BOOST_LOG_SEV(lg, DEBUG)
<< "Pointer operand marked as initialized!");
} /* end store instruction */
// Pass everything else as identity
return Identity<IFDSConstAnalysis::d_t>::getInstance();
}
shared_ptr<FlowFunction<IFDSConstAnalysis::d_t>>
IFDSConstAnalysis::getCallFlowFunction(IFDSConstAnalysis::n_t callStmt,
IFDSConstAnalysis::m_t destMthd) {
auto &lg = lg::get();
LOG_IF_ENABLE(BOOST_LOG_SEV(lg, DEBUG)
<< "IFDSConstAnalysis::getCallFlowFunction()");
// Handle one of the three llvm memory intrinsics (memcpy, memmove or memset)
if (llvm::isa<llvm::MemIntrinsic>(callStmt)) {
LOG_IF_ENABLE(BOOST_LOG_SEV(lg, DEBUG)
<< "Call statement is a LLVM MemIntrinsic!");
return KillAll<IFDSConstAnalysis::d_t>::getInstance();
}
// Check if its a Call Instruction or an Invoke Instruction. If so, we
// need to map all actual parameters into formal parameters.
if (llvm::isa<llvm::CallInst>(callStmt) ||
llvm::isa<llvm::InvokeInst>(callStmt)) {
// return KillAll<IFDSConstAnalysis::d_t>::getInstance();
LOG_IF_ENABLE(BOOST_LOG_SEV(lg, DEBUG)
<< "Call statement: " << llvmIRToString(callStmt));
LOG_IF_ENABLE(BOOST_LOG_SEV(lg, DEBUG)
<< "Destination method: " << destMthd->getName().str());
return make_shared<MapFactsToCallee>(
llvm::ImmutableCallSite(callStmt), destMthd,
[](IFDSConstAnalysis::d_t actual) {
return actual->getType()->isPointerTy();
});
} /* end call/invoke instruction */
// Pass everything else as identity
return Identity<IFDSConstAnalysis::d_t>::getInstance();
}
shared_ptr<FlowFunction<IFDSConstAnalysis::d_t>>
IFDSConstAnalysis::getRetFlowFunction(IFDSConstAnalysis::n_t callSite,
IFDSConstAnalysis::m_t calleeMthd,
IFDSConstAnalysis::n_t exitStmt,
IFDSConstAnalysis::n_t retSite) {
// return KillAll<IFDSConstAnalysis::d_t>::getInstance();
auto &lg = lg::get();
LOG_IF_ENABLE(BOOST_LOG_SEV(lg, DEBUG)
<< "IFDSConstAnalysis::getRetFlowFunction()");
LOG_IF_ENABLE(BOOST_LOG_SEV(lg, DEBUG)
<< "Call site: " << llvmIRToString(callSite));
LOG_IF_ENABLE(BOOST_LOG_SEV(lg, DEBUG)
<< "Caller context: "
<< callSite->getFunction()->getName().str());
LOG_IF_ENABLE(BOOST_LOG_SEV(lg, DEBUG)
<< "Retrun site: " << llvmIRToString(retSite));
LOG_IF_ENABLE(BOOST_LOG_SEV(lg, DEBUG)
<< "Callee method: " << calleeMthd->getName().str());
LOG_IF_ENABLE(BOOST_LOG_SEV(lg, DEBUG)
<< "Callee exit statement: " << llvmIRToString(exitStmt));
// Map formal parameter back to the actual parameter in the caller.
return make_shared<MapFactsToCaller>(
llvm::ImmutableCallSite(callSite), calleeMthd, exitStmt,
[](IFDSConstAnalysis::d_t formal) {
return formal->getType()->isPointerTy();
},
[](IFDSConstAnalysis::m_t cmthd) {
return cmthd->getReturnType()->isPointerTy();
});
// All other data-flow facts of the callee function are killed at this point
}
shared_ptr<FlowFunction<IFDSConstAnalysis::d_t>>
IFDSConstAnalysis::getCallToRetFlowFunction(
IFDSConstAnalysis::n_t callSite, IFDSConstAnalysis::n_t retSite,
set<IFDSConstAnalysis::m_t> callees) {
auto &lg = lg::get();
LOG_IF_ENABLE(BOOST_LOG_SEV(lg, DEBUG)
<< "IFDSConstAnalysis::getCallToRetFlowFunction()");
LOG_IF_ENABLE(BOOST_LOG_SEV(lg, DEBUG)
<< "Call site: " << llvmIRToString(callSite));
LOG_IF_ENABLE(BOOST_LOG_SEV(lg, DEBUG)
<< "Return site: " << llvmIRToString(retSite));
// Process the effects of a llvm memory intrinsic function.
if (llvm::isa<llvm::MemIntrinsic>(callSite)) {
IFDSConstAnalysis::d_t pointerOp = callSite->getOperand(0);
LOG_IF_ENABLE(BOOST_LOG_SEV(lg, DEBUG)
<< "Pointer Operand: " << llvmIRToString(pointerOp));
set<IFDSConstAnalysis::d_t> pointsToSet = ptg.getPointsToSet(pointerOp);
for (auto alias : pointsToSet) {
if (isInitialized(alias)) {
LOG_IF_ENABLE(BOOST_LOG_SEV(lg, DEBUG)
<< "Compute context-relevant points-to "
"information of the pointer operand.");
return make_shared<
GenAll<IFDSConstAnalysis::d_t>>(/*pointsToSet*/
getContextRelevantPointsToSet(
pointsToSet,
callSite->getFunction()),
zeroValue());
}
}
markAsInitialized(pointerOp);
LOG_IF_ENABLE(BOOST_LOG_SEV(lg, DEBUG)
<< "Pointer operand marked as initialized!");
}
// Pass everything else as identity
return Identity<IFDSConstAnalysis::d_t>::getInstance();
}
shared_ptr<FlowFunction<IFDSConstAnalysis::d_t>>
IFDSConstAnalysis::getSummaryFlowFunction(IFDSConstAnalysis::n_t callStmt,
IFDSConstAnalysis::m_t destMthd) {
auto &lg = lg::get();
LOG_IF_ENABLE(BOOST_LOG_SEV(lg, DEBUG)
<< "IFDSConstAnalysis::getSummaryFlowFunction()");
return nullptr;
}
map<IFDSConstAnalysis::n_t, set<IFDSConstAnalysis::d_t>>
IFDSConstAnalysis::initialSeeds() {
auto &lg = lg::get();
LOG_IF_ENABLE(BOOST_LOG_SEV(lg, DEBUG)
<< "IFDSConstAnalysis::initialSeeds()");
// just start in main()
map<IFDSConstAnalysis::n_t, set<IFDSConstAnalysis::d_t>> SeedMap;
for (auto &EntryPoint : EntryPoints) {
SeedMap.insert(make_pair(&icfg.getMethod(EntryPoint)->front().front(),
set<IFDSConstAnalysis::d_t>({zeroValue()})));
}
return SeedMap;
}
IFDSConstAnalysis::d_t IFDSConstAnalysis::createZeroValue() {
auto &lg = lg::get();
LOG_IF_ENABLE(BOOST_LOG_SEV(lg, DEBUG)
<< "IFDSConstAnalysis::createZeroValue()");
// create a special value to represent the zero value!
return LLVMZeroValue::getInstance();
}
bool IFDSConstAnalysis::isZeroValue(IFDSConstAnalysis::d_t d) const {
return LLVMZeroValue::getInstance()->isLLVMZeroValue(d);
}
void IFDSConstAnalysis::printNode(ostream &os, IFDSConstAnalysis::n_t n) const {
os << llvmIRToString(n);
}
void IFDSConstAnalysis::printDataFlowFact(ostream &os,
IFDSConstAnalysis::d_t d) const {
os << llvmIRToString(d);
}
void IFDSConstAnalysis::printMethod(ostream &os,
IFDSConstAnalysis::m_t m) const {
os << m->getName().str();
}
void IFDSConstAnalysis::printInitMemoryLocations() {
auto &lg = lg::get();
LOG_IF_ENABLE(
BOOST_LOG_SEV(lg, DEBUG)
<< "Printing all initialized memory location (or one of its alias)");
for (auto stmt : IFDSConstAnalysis::Initialized) {
LOG_IF_ENABLE(BOOST_LOG_SEV(lg, DEBUG) << llvmIRToString(stmt));
}
}
set<IFDSConstAnalysis::d_t> IFDSConstAnalysis::getContextRelevantPointsToSet(
set<IFDSConstAnalysis::d_t> &PointsToSet,
IFDSConstAnalysis::m_t CurrentContext) {
PAMM_GET_INSTANCE;
INC_COUNTER("[Calls] getContextRelevantPointsToSet", 1,
PAMM_SEVERITY_LEVEL::Full);
START_TIMER("Context-Relevant-PointsTo-Set Computation",
PAMM_SEVERITY_LEVEL::Full);
auto &lg = lg::get();
set<IFDSConstAnalysis::d_t> ToGenerate;
for (auto alias : PointsToSet) {
LOG_IF_ENABLE(BOOST_LOG_SEV(lg, DEBUG)
<< "Alias: " << llvmIRToString(alias));
// Case (i + ii)
if (const llvm::Instruction *I = llvm::dyn_cast<llvm::Instruction>(alias)) {
if (isAllocaInstOrHeapAllocaFunction(alias)) {
ToGenerate.insert(alias);
LOG_IF_ENABLE(BOOST_LOG_SEV(lg, DEBUG)
<< "alloca inst will be generated as a new fact!");
} else if (I->getFunction() == CurrentContext) {
ToGenerate.insert(alias);
LOG_IF_ENABLE(BOOST_LOG_SEV(lg, DEBUG)
<< "instruction within current function will "
"be generated as a new fact!");
}
} // Case (ii)
else if (llvm::isa<llvm::GlobalValue>(alias)) {
ToGenerate.insert(alias);
LOG_IF_ENABLE(BOOST_LOG_SEV(lg, DEBUG)
<< "global variable will be generated as a new fact!");
} // Case (iii)
else if (const llvm::Argument *A = llvm::dyn_cast<llvm::Argument>(alias)) {
if (A->getParent() == CurrentContext) {
ToGenerate.insert(alias);
LOG_IF_ENABLE(BOOST_LOG_SEV(lg, DEBUG)
<< "formal argument will be generated as a new fact!");
}
} // ignore everything else
}
PAUSE_TIMER("Context-Relevant-PointsTo-Set Computation",
PAMM_SEVERITY_LEVEL::Full);
ADD_TO_HISTOGRAM("Context-relevant Pointer", ToGenerate.size(), 1,
PAMM_SEVERITY_LEVEL::Full);
return ToGenerate;
}
bool IFDSConstAnalysis::isInitialized(IFDSConstAnalysis::d_t d) const {
return llvm::isa<llvm::GlobalValue>(d) || Initialized.count(d);
}
void IFDSConstAnalysis::markAsInitialized(IFDSConstAnalysis::d_t d) {
Initialized.insert(d);
}
size_t IFDSConstAnalysis::initMemoryLocationCount() {
return Initialized.size();
}
void IFDSConstAnalysis::printIFDSReport(
ostream &os,
SolverResults<IFDSConstAnalysis::n_t, IFDSConstAnalysis::d_t, BinaryDomain>
&SR) {
// 1) Remove all mutable memory locations
for (auto f : icfg.getAllMethods()) {
for (auto exit : icfg.getExitPointsOf(f)) {
std::set<const llvm::Value *> facts = SR.ifdsResultsAt(exit);
// Empty facts means the exit statement is part of a not
// analyzed function, thus remove all memory locations of that function
if (facts.empty()) {
for (auto mem_itr = AllMemLocs.begin(); mem_itr != AllMemLocs.end();) {
if (auto Inst = llvm::dyn_cast<llvm::Instruction>(*mem_itr)) {
if (Inst->getParent()->getParent() == f) {
mem_itr = AllMemLocs.erase(mem_itr);
} else {
++mem_itr;
}
} else {
++mem_itr;
}
}
} else {
for (auto fact : facts) {
if (isAllocaInstOrHeapAllocaFunction(fact) ||
llvm::isa<llvm::GlobalValue>(fact)) {
// remove memory locations that are mutable, i.e. are valid facts
AllMemLocs.erase(fact);
}
}
}
}
}
// 2) Print all immutbale/const memory locations
os << "=========== IFDS Const Analysis Results ===========\n";
if (AllMemLocs.empty()) {
os << "No immutable memory locations found!\n";
} else {
os << "Immutable/const stack and/or heap memory locations:\n";
for (auto memloc : AllMemLocs) {
os << "\nIR : " << llvmIRToString(memloc) << '\n'
<< llvmValueToSrc(memloc) << "\n";
}
}
os << "\n===================================================\n";
}
} // namespace psr
|
;; Code has been used from Philipp Oppermann's blog
;; @ https://os.phil-opp.com/
;; Copyright (c) 2019 Philipp Oppermann
global long_mode_start
STRING_OKAY: equ 0x2f592f412f4b2f4f
VGA_BUFFER_START: equ 0xb8000
section .text
; We should have enabled 64-bit long mode by now
bits 64
long_mode_start:
call reset_segment_registers
; 64 bits allow putting 8 bytes in one go!
mov rax, STRING_OKAY
mov [VGA_BUFFER_START], rax
extern rust_main
call rust_main ; Call Rust function now that we are in 64-bit long mode
; 64 bits allow putting 8 bytes in one go!
mov rax, STRING_OKAY
mov [VGA_BUFFER_START+8], rax
hlt
; reset segment registers other than CS to prevent issue in future
reset_segment_registers:
mov ax, 0
mov ss, ax
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
ret
|
dnl Alpha mpn_sub_n -- Subtract two limb vectors of the same length > 0
dnl and store difference in a third limb vector.
dnl Copyright 1995, 1999, 2000, 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 EV4: ?
C EV5: 4.75
C EV6: 3
dnl INPUT PARAMETERS
dnl res_ptr r16
dnl s1_ptr r17
dnl s2_ptr r18
dnl size r19
ASM_START()
PROLOGUE(mpn_sub_n)
bis r31,r31,r25 C clear cy
subq r19,4,r19 C decr loop cnt
blt r19,$Lend2 C if less than 4 limbs, goto 2nd loop
C Start software pipeline for 1st loop
ldq r0,0(r18)
ldq r4,0(r17)
ldq r1,8(r18)
ldq r5,8(r17)
addq r17,32,r17 C update s1_ptr
ldq r2,16(r18)
subq r4,r0,r20 C 1st main subtract
ldq r3,24(r18)
subq r19,4,r19 C decr loop cnt
ldq r6,-16(r17)
cmpult r4,r0,r25 C compute cy from last subtract
ldq r7,-8(r17)
subq r5,r1,r28 C 2nd main subtract
addq r18,32,r18 C update s2_ptr
subq r28,r25,r21 C 2nd carry subtract
cmpult r5,r1,r8 C compute cy from last subtract
blt r19,$Lend1 C if less than 4 limbs remain, jump
C 1st loop handles groups of 4 limbs in a software pipeline
ALIGN(16)
$Loop: cmpult r28,r25,r25 C compute cy from last subtract
ldq r0,0(r18)
bis r8,r25,r25 C combine cy from the two subtracts
ldq r1,8(r18)
subq r6,r2,r28 C 3rd main subtract
ldq r4,0(r17)
subq r28,r25,r22 C 3rd carry subtract
ldq r5,8(r17)
cmpult r6,r2,r8 C compute cy from last subtract
cmpult r28,r25,r25 C compute cy from last subtract
stq r20,0(r16)
bis r8,r25,r25 C combine cy from the two subtracts
stq r21,8(r16)
subq r7,r3,r28 C 4th main subtract
subq r28,r25,r23 C 4th carry subtract
cmpult r7,r3,r8 C compute cy from last subtract
cmpult r28,r25,r25 C compute cy from last subtract
addq r17,32,r17 C update s1_ptr
bis r8,r25,r25 C combine cy from the two subtracts
addq r16,32,r16 C update res_ptr
subq r4,r0,r28 C 1st main subtract
ldq r2,16(r18)
subq r28,r25,r20 C 1st carry subtract
ldq r3,24(r18)
cmpult r4,r0,r8 C compute cy from last subtract
ldq r6,-16(r17)
cmpult r28,r25,r25 C compute cy from last subtract
ldq r7,-8(r17)
bis r8,r25,r25 C combine cy from the two subtracts
subq r19,4,r19 C decr loop cnt
stq r22,-16(r16)
subq r5,r1,r28 C 2nd main subtract
stq r23,-8(r16)
subq r28,r25,r21 C 2nd carry subtract
addq r18,32,r18 C update s2_ptr
cmpult r5,r1,r8 C compute cy from last subtract
bge r19,$Loop
C Finish software pipeline for 1st loop
$Lend1: cmpult r28,r25,r25 C compute cy from last subtract
bis r8,r25,r25 C combine cy from the two subtracts
subq r6,r2,r28 C cy add
subq r28,r25,r22 C 3rd main subtract
cmpult r6,r2,r8 C compute cy from last subtract
cmpult r28,r25,r25 C compute cy from last subtract
stq r20,0(r16)
bis r8,r25,r25 C combine cy from the two subtracts
stq r21,8(r16)
subq r7,r3,r28 C cy add
subq r28,r25,r23 C 4th main subtract
cmpult r7,r3,r8 C compute cy from last subtract
cmpult r28,r25,r25 C compute cy from last subtract
bis r8,r25,r25 C combine cy from the two subtracts
addq r16,32,r16 C update res_ptr
stq r22,-16(r16)
stq r23,-8(r16)
$Lend2: addq r19,4,r19 C restore loop cnt
beq r19,$Lret
C Start software pipeline for 2nd loop
ldq r0,0(r18)
ldq r4,0(r17)
subq r19,1,r19
beq r19,$Lend0
C 2nd loop handles remaining 1-3 limbs
ALIGN(16)
$Loop0: subq r4,r0,r28 C main subtract
cmpult r4,r0,r8 C compute cy from last subtract
ldq r0,8(r18)
ldq r4,8(r17)
subq r28,r25,r20 C carry subtract
addq r18,8,r18
addq r17,8,r17
stq r20,0(r16)
cmpult r28,r25,r25 C compute cy from last subtract
subq r19,1,r19 C decr loop cnt
bis r8,r25,r25 C combine cy from the two subtracts
addq r16,8,r16
bne r19,$Loop0
$Lend0: subq r4,r0,r28 C main subtract
subq r28,r25,r20 C carry subtract
cmpult r4,r0,r8 C compute cy from last subtract
cmpult r28,r25,r25 C compute cy from last subtract
stq r20,0(r16)
bis r8,r25,r25 C combine cy from the two subtracts
$Lret: bis r25,r31,r0 C return cy
ret r31,(r26),1
EPILOGUE(mpn_sub_n)
ASM_END()
|
VictoryRoad3Object:
db $7d ; border block
db $4 ; warps
db $7, $17, $3, VICTORY_ROAD_2
db $8, $1a, $5, VICTORY_ROAD_2
db $f, $1b, $4, VICTORY_ROAD_2
db $0, $2, $6, VICTORY_ROAD_2
db $0 ; signs
db $a ; objects
object SPRITE_BLACK_HAIR_BOY_1, $1c, $5, STAY, LEFT, $1, OPP_COOLTRAINER_M, $2
object SPRITE_LASS, $7, $d, STAY, RIGHT, $2, OPP_COOLTRAINER_F, $2
object SPRITE_BLACK_HAIR_BOY_1, $6, $e, STAY, LEFT, $3, OPP_COOLTRAINER_M, $3
object SPRITE_LASS, $d, $3, STAY, RIGHT, $4, OPP_COOLTRAINER_F, $3
object SPRITE_BALL, $1a, $5, STAY, NONE, $5, MAX_REVIVE
object SPRITE_BALL, $7, $7, STAY, NONE, $6, TM_47
object SPRITE_BOULDER, $16, $3, STAY, BOULDER_MOVEMENT_BYTE_2, $7 ; person
object SPRITE_BOULDER, $d, $c, STAY, BOULDER_MOVEMENT_BYTE_2, $8 ; person
object SPRITE_BOULDER, $18, $a, STAY, BOULDER_MOVEMENT_BYTE_2, $9 ; person
object SPRITE_BOULDER, $16, $f, STAY, BOULDER_MOVEMENT_BYTE_2, $a ; person
; warp-to
EVENT_DISP VICTORY_ROAD_3_WIDTH, $7, $17 ; VICTORY_ROAD_2
EVENT_DISP VICTORY_ROAD_3_WIDTH, $8, $1a ; VICTORY_ROAD_2
EVENT_DISP VICTORY_ROAD_3_WIDTH, $f, $1b ; VICTORY_ROAD_2
EVENT_DISP VICTORY_ROAD_3_WIDTH, $0, $2 ; VICTORY_ROAD_2
|
; returns in HL the video-lines count for current mode (ie. 0x137 for VGA ZX128)
; modifies: AF, BC, HL
; This algorithm works correctly only for modes with 258..511 video lines
; current core 3.1.5 conforms to this for all VGA/HDMI modes in any variant (min 261?)
findVLinesCount:
ld bc,TBBLUE_REGISTER_SELECT_P_243B
ld hl,$0100 + VIDEO_LINE_LSB_NR_1F ; H = 1, L = VIDEO_LINE_LSB_NR_1F
out (c),l
inc b
.waitForNon255MaxLsb:
ld a,255 ; non-255 max not found yet
.waitForZeroLsb:
ld l,a
in a,(c) ; L = last non-zero LSB, A = fresh LSB (may be zero upon wrap)
jr nz,.waitForZeroLsb
inc l ; check if L is non-255 when line LSB wraps to 0 => max LSB found
jr z,.waitForNon255MaxLsb
ret ; here HL is then equal to lines count (H=1 already, L=line.LSB+1)
|
/**
* Copyright (c) 2019 Melown Technologies SE
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <cmath>
#include "../ogr.hpp"
#include "tree.hpp"
namespace semantic {
OgrGeometry ogr(const Tree &tree, const math::Point3 &origin)
{
auto cs(std::make_unique< ::OGRCircularString>());
const math::Point3 center(origin + tree.origin + tree.center);
/** Closed circle between two arcs.
* TODO: take harmonics into account
*/
cs->addPoint(center(0) - tree.a, center(1), center(2));
cs->addPoint(center(0) + tree.a, center(1), center(2));
cs->addPoint(center(0) - tree.a, center(1), center(2));
math::Extent verticalExtent;
update(verticalExtent, origin(2) + tree.origin(2));
update(verticalExtent, center(2) + tree.b);
update(verticalExtent, center(2) - tree.b);
return { std::move(cs), verticalExtent };
}
} // namespace semantic
|
; void __CALLEE__ *calloc_callee(unsigned int nobj, unsigned int size)
; 12.2006 aralbrec
PUBLIC calloc_callee
EXTERN ASMDISP_CALLOC_CALLEE
EXTERN HeapCalloc_callee
EXTERN _heap, ASMDISP_HEAPCALLOC_CALLEE
.calloc_callee
pop hl
pop de
ex (sp),hl
.asmentry
; enter : hl = number of objects
; de = size of each object
; exit : hl = address of memory block and carry set if successful
; else 0 and no carry if failed
; uses : af, bc, de, hl
ld bc,_heap
jp HeapCalloc_callee + ASMDISP_HEAPCALLOC_CALLEE
DEFC ASMDISP_CALLOC_CALLEE = # asmentry - calloc_callee
|
BITS 32
%include "inc/util.inc.asm"
call get_msg
db "OWNED BY I4K",0x0a
msg:
pop ecx
mov edx, 13
mov ebx, 1
mov eax, 4
int 0x80
xor eax, eax
xor ebx, ebx
xor ecx, ecx
xor edx, edx
jmp exit
get_msg: jmp msg
exit:
|
#pragma once
#include "Creature.hpp"
// Weaving allows the creation of new items of clothing from fibres.
// Unlike skinning, which just provides a straight evade or soak bonus,
// weaving provides a randomized number of free enchants based on the
// creature's Weaving skill.
class WeavingCalculator
{
public:
int calculate_min_enchant_points(CreaturePtr creature);
int calculate_max_enchant_points(CreaturePtr creature);
};
|
; 1 2 3 4 5 6 7
;234567890123456789012345678901234567890123456789012345678901234567890
;=====================================================================
;
; FUNCTION NAME: mat_zeros
; DOCUMENTATIONS: <See doc/description file>
;
; AUTHOR: Nik Mohamad Aizuddin bin Nik Azmi
; EMAIL: nickaizuddin93@gmail.com
; DATE CREATED: 15-APR-2015
;
; CONTRIBUTORS: ---
;
; LANGUAGE: x86 Assembly Language
; SYNTAX: Intel
; ASSEMBLER: NASM
; ARCHITECTURE: i386
; KERNEL: Linux 32-bit
; FORMAT: elf32
;
; REQ EXTERNAL FILES: ---
;
; VERSION: 0.1.0
; STATUS: Alpha
; BUGS: --- <See doc/bugs/index file>
;
; REVISION HISTORY: <See doc/revision_history/index file>
;
; MIT Licensed. See /LICENSE file.
;
;=====================================================================
global mat_zeros
section .text
mat_zeros:
;parameter 1) EAX = @srcMatrix : Matrix (Input Only)
;parameter 2) EBX = @dstMatrix : Matrix (Input and Output)
;EDI = dstMatrix.pData
mov edi, ebx
add edi, (4*4)
mov edi, [edi]
;EBX = srcMatrix.columnSize
mov ebx, eax
add ebx, (4*2)
mov ebx, [ebx]
;NOTE: dstMatrix is no longer can be referenced.
;ECX = srcMatrix.numOfRows * srcMatrix.numOfColumns
mov ecx, eax ;ECX = srcMatrix.numOfRows
mov ecx, [ecx]
add eax, (4*1) ;EAX = srcMatrix.numOfColumns
mov eax, [eax]
mul ecx
mov ecx, eax
;NOTE: srcMatrix is no longer can be referenced.
pxor xmm0, xmm0
.loop:
movss [edi], xmm0
add esi, ebx
add edi, ebx
sub ecx, 1
jnz .loop
.endloop:
ret
|
_grep: file format elf32-i386
Disassembly of section .text:
00000000 <main>:
}
}
int
main(int argc, char *argv[])
{
0: 55 push %ebp
1: 89 e5 mov %esp,%ebp
3: 57 push %edi
4: 56 push %esi
5: 53 push %ebx
6: 83 e4 f0 and $0xfffffff0,%esp
9: 83 ec 10 sub $0x10,%esp
c: 8b 5d 0c mov 0xc(%ebp),%ebx
int fd, i;
char *pattern;
if(argc <= 1){
f: 83 7d 08 01 cmpl $0x1,0x8(%ebp)
13: 0f 8e 8b 00 00 00 jle a4 <main+0xa4>
printf(2, "usage: grep pattern [file ...]\n");
exit();
}
pattern = argv[1];
19: 8b 43 04 mov 0x4(%ebx),%eax
1c: 83 c3 08 add $0x8,%ebx
if(argc <= 2){
1f: be 02 00 00 00 mov $0x2,%esi
24: 83 7d 08 02 cmpl $0x2,0x8(%ebp)
if(argc <= 1){
printf(2, "usage: grep pattern [file ...]\n");
exit();
}
pattern = argv[1];
28: 89 44 24 0c mov %eax,0xc(%esp)
if(argc <= 2){
2c: 74 61 je 8f <main+0x8f>
2e: 66 90 xchg %ax,%ax
grep(pattern, 0);
exit();
}
for(i = 2; i < argc; i++){
if((fd = open(argv[i], 0)) < 0){
30: c7 44 24 04 00 00 00 movl $0x0,0x4(%esp)
37: 00
38: 8b 03 mov (%ebx),%eax
3a: 89 04 24 mov %eax,(%esp)
3d: e8 30 05 00 00 call 572 <open>
42: 85 c0 test %eax,%eax
44: 89 c7 mov %eax,%edi
46: 78 28 js 70 <main+0x70>
printf(1, "grep: cannot open %s\n", argv[i]);
exit();
}
grep(pattern, fd);
48: 89 44 24 04 mov %eax,0x4(%esp)
4c: 8b 44 24 0c mov 0xc(%esp),%eax
if(argc <= 2){
grep(pattern, 0);
exit();
}
for(i = 2; i < argc; i++){
50: 83 c6 01 add $0x1,%esi
53: 83 c3 04 add $0x4,%ebx
if((fd = open(argv[i], 0)) < 0){
printf(1, "grep: cannot open %s\n", argv[i]);
exit();
}
grep(pattern, fd);
56: 89 04 24 mov %eax,(%esp)
59: e8 a2 01 00 00 call 200 <grep>
close(fd);
5e: 89 3c 24 mov %edi,(%esp)
61: e8 f4 04 00 00 call 55a <close>
if(argc <= 2){
grep(pattern, 0);
exit();
}
for(i = 2; i < argc; i++){
66: 39 75 08 cmp %esi,0x8(%ebp)
69: 7f c5 jg 30 <main+0x30>
exit();
}
grep(pattern, fd);
close(fd);
}
exit();
6b: e8 c2 04 00 00 call 532 <exit>
exit();
}
for(i = 2; i < argc; i++){
if((fd = open(argv[i], 0)) < 0){
printf(1, "grep: cannot open %s\n", argv[i]);
70: 8b 03 mov (%ebx),%eax
72: c7 44 24 04 08 0a 00 movl $0xa08,0x4(%esp)
79: 00
7a: c7 04 24 01 00 00 00 movl $0x1,(%esp)
81: 89 44 24 08 mov %eax,0x8(%esp)
85: e8 f6 05 00 00 call 680 <printf>
exit();
8a: e8 a3 04 00 00 call 532 <exit>
exit();
}
pattern = argv[1];
if(argc <= 2){
grep(pattern, 0);
8f: 89 04 24 mov %eax,(%esp)
92: c7 44 24 04 00 00 00 movl $0x0,0x4(%esp)
99: 00
9a: e8 61 01 00 00 call 200 <grep>
exit();
9f: e8 8e 04 00 00 call 532 <exit>
{
int fd, i;
char *pattern;
if(argc <= 1){
printf(2, "usage: grep pattern [file ...]\n");
a4: c7 44 24 04 e8 09 00 movl $0x9e8,0x4(%esp)
ab: 00
ac: c7 04 24 02 00 00 00 movl $0x2,(%esp)
b3: e8 c8 05 00 00 call 680 <printf>
exit();
b8: e8 75 04 00 00 call 532 <exit>
bd: 66 90 xchg %ax,%ax
bf: 90 nop
000000c0 <matchstar>:
return 0;
}
// matchstar: search for c*re at beginning of text
int matchstar(int c, char *re, char *text)
{
c0: 55 push %ebp
c1: 89 e5 mov %esp,%ebp
c3: 57 push %edi
c4: 56 push %esi
c5: 53 push %ebx
c6: 83 ec 1c sub $0x1c,%esp
c9: 8b 75 08 mov 0x8(%ebp),%esi
cc: 8b 7d 0c mov 0xc(%ebp),%edi
cf: 8b 5d 10 mov 0x10(%ebp),%ebx
d2: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
do{ // a * matches zero or more instances
if(matchhere(re, text))
d8: 89 5c 24 04 mov %ebx,0x4(%esp)
dc: 89 3c 24 mov %edi,(%esp)
df: e8 3c 00 00 00 call 120 <matchhere>
e4: 85 c0 test %eax,%eax
e6: 75 20 jne 108 <matchstar+0x48>
return 1;
}while(*text!='\0' && (*text++==c || c=='.'));
e8: 0f be 13 movsbl (%ebx),%edx
eb: 84 d2 test %dl,%dl
ed: 74 0c je fb <matchstar+0x3b>
ef: 83 c3 01 add $0x1,%ebx
f2: 39 f2 cmp %esi,%edx
f4: 74 e2 je d8 <matchstar+0x18>
f6: 83 fe 2e cmp $0x2e,%esi
f9: 74 dd je d8 <matchstar+0x18>
return 0;
}
fb: 83 c4 1c add $0x1c,%esp
fe: 5b pop %ebx
ff: 5e pop %esi
100: 5f pop %edi
101: 5d pop %ebp
102: c3 ret
103: 90 nop
104: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
108: 83 c4 1c add $0x1c,%esp
// matchstar: search for c*re at beginning of text
int matchstar(int c, char *re, char *text)
{
do{ // a * matches zero or more instances
if(matchhere(re, text))
return 1;
10b: b8 01 00 00 00 mov $0x1,%eax
}while(*text!='\0' && (*text++==c || c=='.'));
return 0;
}
110: 5b pop %ebx
111: 5e pop %esi
112: 5f pop %edi
113: 5d pop %ebp
114: c3 ret
115: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
119: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000120 <matchhere>:
return 0;
}
// matchhere: search for re at beginning of text
int matchhere(char *re, char *text)
{
120: 55 push %ebp
121: 89 e5 mov %esp,%ebp
123: 53 push %ebx
124: 83 ec 14 sub $0x14,%esp
127: 8b 55 08 mov 0x8(%ebp),%edx
12a: 8b 4d 0c mov 0xc(%ebp),%ecx
if(re[0] == '\0')
12d: 0f be 02 movsbl (%edx),%eax
130: 84 c0 test %al,%al
132: 75 20 jne 154 <matchhere+0x34>
134: eb 42 jmp 178 <matchhere+0x58>
136: 66 90 xchg %ax,%ax
return 1;
if(re[1] == '*')
return matchstar(re[0], re+2, text);
if(re[0] == '$' && re[1] == '\0')
return *text == '\0';
if(*text!='\0' && (re[0]=='.' || re[0]==*text))
138: 0f b6 19 movzbl (%ecx),%ebx
13b: 84 db test %bl,%bl
13d: 74 31 je 170 <matchhere+0x50>
13f: 3c 2e cmp $0x2e,%al
141: 74 04 je 147 <matchhere+0x27>
143: 38 d8 cmp %bl,%al
145: 75 29 jne 170 <matchhere+0x50>
return matchhere(re+1, text+1);
147: 83 c2 01 add $0x1,%edx
}
// matchhere: search for re at beginning of text
int matchhere(char *re, char *text)
{
if(re[0] == '\0')
14a: 0f be 02 movsbl (%edx),%eax
if(re[1] == '*')
return matchstar(re[0], re+2, text);
if(re[0] == '$' && re[1] == '\0')
return *text == '\0';
if(*text!='\0' && (re[0]=='.' || re[0]==*text))
return matchhere(re+1, text+1);
14d: 83 c1 01 add $0x1,%ecx
}
// matchhere: search for re at beginning of text
int matchhere(char *re, char *text)
{
if(re[0] == '\0')
150: 84 c0 test %al,%al
152: 74 24 je 178 <matchhere+0x58>
return 1;
if(re[1] == '*')
154: 0f b6 5a 01 movzbl 0x1(%edx),%ebx
158: 80 fb 2a cmp $0x2a,%bl
15b: 74 2b je 188 <matchhere+0x68>
return matchstar(re[0], re+2, text);
if(re[0] == '$' && re[1] == '\0')
15d: 3c 24 cmp $0x24,%al
15f: 75 d7 jne 138 <matchhere+0x18>
161: 84 db test %bl,%bl
163: 74 3c je 1a1 <matchhere+0x81>
return *text == '\0';
if(*text!='\0' && (re[0]=='.' || re[0]==*text))
165: 0f b6 19 movzbl (%ecx),%ebx
168: 84 db test %bl,%bl
16a: 75 d7 jne 143 <matchhere+0x23>
16c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
return matchhere(re+1, text+1);
return 0;
170: 31 c0 xor %eax,%eax
}
172: 83 c4 14 add $0x14,%esp
175: 5b pop %ebx
176: 5d pop %ebp
177: c3 ret
178: 83 c4 14 add $0x14,%esp
// matchhere: search for re at beginning of text
int matchhere(char *re, char *text)
{
if(re[0] == '\0')
return 1;
17b: b8 01 00 00 00 mov $0x1,%eax
if(re[0] == '$' && re[1] == '\0')
return *text == '\0';
if(*text!='\0' && (re[0]=='.' || re[0]==*text))
return matchhere(re+1, text+1);
return 0;
}
180: 5b pop %ebx
181: 5d pop %ebp
182: c3 ret
183: 90 nop
184: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
int matchhere(char *re, char *text)
{
if(re[0] == '\0')
return 1;
if(re[1] == '*')
return matchstar(re[0], re+2, text);
188: 83 c2 02 add $0x2,%edx
18b: 89 4c 24 08 mov %ecx,0x8(%esp)
18f: 89 54 24 04 mov %edx,0x4(%esp)
193: 89 04 24 mov %eax,(%esp)
196: e8 25 ff ff ff call c0 <matchstar>
if(re[0] == '$' && re[1] == '\0')
return *text == '\0';
if(*text!='\0' && (re[0]=='.' || re[0]==*text))
return matchhere(re+1, text+1);
return 0;
}
19b: 83 c4 14 add $0x14,%esp
19e: 5b pop %ebx
19f: 5d pop %ebp
1a0: c3 ret
if(re[0] == '\0')
return 1;
if(re[1] == '*')
return matchstar(re[0], re+2, text);
if(re[0] == '$' && re[1] == '\0')
return *text == '\0';
1a1: 31 c0 xor %eax,%eax
1a3: 80 39 00 cmpb $0x0,(%ecx)
1a6: 0f 94 c0 sete %al
1a9: eb c7 jmp 172 <matchhere+0x52>
1ab: 90 nop
1ac: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
000001b0 <match>:
int matchhere(char*, char*);
int matchstar(int, char*, char*);
int
match(char *re, char *text)
{
1b0: 55 push %ebp
1b1: 89 e5 mov %esp,%ebp
1b3: 56 push %esi
1b4: 53 push %ebx
1b5: 83 ec 10 sub $0x10,%esp
1b8: 8b 75 08 mov 0x8(%ebp),%esi
1bb: 8b 5d 0c mov 0xc(%ebp),%ebx
if(re[0] == '^')
1be: 80 3e 5e cmpb $0x5e,(%esi)
1c1: 75 0e jne 1d1 <match+0x21>
1c3: eb 28 jmp 1ed <match+0x3d>
1c5: 8d 76 00 lea 0x0(%esi),%esi
return matchhere(re+1, text);
do{ // must look at empty string
if(matchhere(re, text))
return 1;
}while(*text++ != '\0');
1c8: 83 c3 01 add $0x1,%ebx
1cb: 80 7b ff 00 cmpb $0x0,-0x1(%ebx)
1cf: 74 15 je 1e6 <match+0x36>
match(char *re, char *text)
{
if(re[0] == '^')
return matchhere(re+1, text);
do{ // must look at empty string
if(matchhere(re, text))
1d1: 89 5c 24 04 mov %ebx,0x4(%esp)
1d5: 89 34 24 mov %esi,(%esp)
1d8: e8 43 ff ff ff call 120 <matchhere>
1dd: 85 c0 test %eax,%eax
1df: 74 e7 je 1c8 <match+0x18>
return 1;
1e1: b8 01 00 00 00 mov $0x1,%eax
}while(*text++ != '\0');
return 0;
}
1e6: 83 c4 10 add $0x10,%esp
1e9: 5b pop %ebx
1ea: 5e pop %esi
1eb: 5d pop %ebp
1ec: c3 ret
int
match(char *re, char *text)
{
if(re[0] == '^')
return matchhere(re+1, text);
1ed: 83 c6 01 add $0x1,%esi
1f0: 89 75 08 mov %esi,0x8(%ebp)
do{ // must look at empty string
if(matchhere(re, text))
return 1;
}while(*text++ != '\0');
return 0;
}
1f3: 83 c4 10 add $0x10,%esp
1f6: 5b pop %ebx
1f7: 5e pop %esi
1f8: 5d pop %ebp
int
match(char *re, char *text)
{
if(re[0] == '^')
return matchhere(re+1, text);
1f9: e9 22 ff ff ff jmp 120 <matchhere>
1fe: 66 90 xchg %ax,%ax
00000200 <grep>:
char buf[1024];
int match(char*, char*);
void
grep(char *pattern, int fd)
{
200: 55 push %ebp
201: 89 e5 mov %esp,%ebp
203: 57 push %edi
204: 56 push %esi
205: 53 push %ebx
206: 83 ec 1c sub $0x1c,%esp
209: 8b 75 08 mov 0x8(%ebp),%esi
int n, m;
char *p, *q;
m = 0;
20c: c7 45 e4 00 00 00 00 movl $0x0,-0x1c(%ebp)
213: 90 nop
214: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
while((n = read(fd, buf+m, sizeof(buf)-m-1)) > 0){
218: 8b 55 e4 mov -0x1c(%ebp),%edx
21b: b8 ff 03 00 00 mov $0x3ff,%eax
220: 29 d0 sub %edx,%eax
222: 89 44 24 08 mov %eax,0x8(%esp)
226: 89 d0 mov %edx,%eax
228: 05 a0 0d 00 00 add $0xda0,%eax
22d: 89 44 24 04 mov %eax,0x4(%esp)
231: 8b 45 0c mov 0xc(%ebp),%eax
234: 89 04 24 mov %eax,(%esp)
237: e8 0e 03 00 00 call 54a <read>
23c: 85 c0 test %eax,%eax
23e: 0f 8e b8 00 00 00 jle 2fc <grep+0xfc>
m += n;
244: 01 45 e4 add %eax,-0x1c(%ebp)
buf[m] = '\0';
p = buf;
247: bb a0 0d 00 00 mov $0xda0,%ebx
char *p, *q;
m = 0;
while((n = read(fd, buf+m, sizeof(buf)-m-1)) > 0){
m += n;
buf[m] = '\0';
24c: 8b 45 e4 mov -0x1c(%ebp),%eax
24f: c6 80 a0 0d 00 00 00 movb $0x0,0xda0(%eax)
256: 66 90 xchg %ax,%ax
p = buf;
while((q = strchr(p, '\n')) != 0){
258: c7 44 24 04 0a 00 00 movl $0xa,0x4(%esp)
25f: 00
260: 89 1c 24 mov %ebx,(%esp)
263: e8 78 01 00 00 call 3e0 <strchr>
268: 85 c0 test %eax,%eax
26a: 89 c7 mov %eax,%edi
26c: 74 42 je 2b0 <grep+0xb0>
*q = 0;
26e: c6 07 00 movb $0x0,(%edi)
if(match(pattern, p)){
271: 89 5c 24 04 mov %ebx,0x4(%esp)
275: 89 34 24 mov %esi,(%esp)
278: e8 33 ff ff ff call 1b0 <match>
27d: 85 c0 test %eax,%eax
27f: 75 07 jne 288 <grep+0x88>
281: 8d 5f 01 lea 0x1(%edi),%ebx
284: eb d2 jmp 258 <grep+0x58>
286: 66 90 xchg %ax,%ax
*q = '\n';
288: c6 07 0a movb $0xa,(%edi)
write(1, p, q+1 - p);
28b: 83 c7 01 add $0x1,%edi
28e: 89 f8 mov %edi,%eax
290: 29 d8 sub %ebx,%eax
292: 89 5c 24 04 mov %ebx,0x4(%esp)
296: 89 fb mov %edi,%ebx
298: 89 44 24 08 mov %eax,0x8(%esp)
29c: c7 04 24 01 00 00 00 movl $0x1,(%esp)
2a3: e8 aa 02 00 00 call 552 <write>
2a8: eb ae jmp 258 <grep+0x58>
2aa: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
}
p = q+1;
}
if(p == buf)
2b0: 81 fb a0 0d 00 00 cmp $0xda0,%ebx
2b6: 74 38 je 2f0 <grep+0xf0>
m = 0;
if(m > 0){
2b8: 8b 45 e4 mov -0x1c(%ebp),%eax
2bb: 85 c0 test %eax,%eax
2bd: 0f 8e 55 ff ff ff jle 218 <grep+0x18>
m -= p - buf;
2c3: b8 a0 0d 00 00 mov $0xda0,%eax
2c8: 29 d8 sub %ebx,%eax
2ca: 01 45 e4 add %eax,-0x1c(%ebp)
memmove(buf, p, m);
2cd: 8b 45 e4 mov -0x1c(%ebp),%eax
2d0: 89 5c 24 04 mov %ebx,0x4(%esp)
2d4: c7 04 24 a0 0d 00 00 movl $0xda0,(%esp)
2db: 89 44 24 08 mov %eax,0x8(%esp)
2df: e8 1c 02 00 00 call 500 <memmove>
2e4: e9 2f ff ff ff jmp 218 <grep+0x18>
2e9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
write(1, p, q+1 - p);
}
p = q+1;
}
if(p == buf)
m = 0;
2f0: c7 45 e4 00 00 00 00 movl $0x0,-0x1c(%ebp)
2f7: e9 1c ff ff ff jmp 218 <grep+0x18>
if(m > 0){
m -= p - buf;
memmove(buf, p, m);
}
}
}
2fc: 83 c4 1c add $0x1c,%esp
2ff: 5b pop %ebx
300: 5e pop %esi
301: 5f pop %edi
302: 5d pop %ebp
303: c3 ret
304: 66 90 xchg %ax,%ax
306: 66 90 xchg %ax,%ax
308: 66 90 xchg %ax,%ax
30a: 66 90 xchg %ax,%ax
30c: 66 90 xchg %ax,%ax
30e: 66 90 xchg %ax,%ax
00000310 <strcpy>:
#include "user.h"
#include "x86.h"
char*
strcpy(char *s, const char *t)
{
310: 55 push %ebp
311: 89 e5 mov %esp,%ebp
313: 8b 45 08 mov 0x8(%ebp),%eax
316: 8b 4d 0c mov 0xc(%ebp),%ecx
319: 53 push %ebx
char *os;
os = s;
while((*s++ = *t++) != 0)
31a: 89 c2 mov %eax,%edx
31c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
320: 83 c1 01 add $0x1,%ecx
323: 0f b6 59 ff movzbl -0x1(%ecx),%ebx
327: 83 c2 01 add $0x1,%edx
32a: 84 db test %bl,%bl
32c: 88 5a ff mov %bl,-0x1(%edx)
32f: 75 ef jne 320 <strcpy+0x10>
;
return os;
}
331: 5b pop %ebx
332: 5d pop %ebp
333: c3 ret
334: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
33a: 8d bf 00 00 00 00 lea 0x0(%edi),%edi
00000340 <strcmp>:
int
strcmp(const char *p, const char *q)
{
340: 55 push %ebp
341: 89 e5 mov %esp,%ebp
343: 8b 55 08 mov 0x8(%ebp),%edx
346: 53 push %ebx
347: 8b 4d 0c mov 0xc(%ebp),%ecx
while(*p && *p == *q)
34a: 0f b6 02 movzbl (%edx),%eax
34d: 84 c0 test %al,%al
34f: 74 2d je 37e <strcmp+0x3e>
351: 0f b6 19 movzbl (%ecx),%ebx
354: 38 d8 cmp %bl,%al
356: 74 0e je 366 <strcmp+0x26>
358: eb 2b jmp 385 <strcmp+0x45>
35a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
360: 38 c8 cmp %cl,%al
362: 75 15 jne 379 <strcmp+0x39>
p++, q++;
364: 89 d9 mov %ebx,%ecx
366: 83 c2 01 add $0x1,%edx
}
int
strcmp(const char *p, const char *q)
{
while(*p && *p == *q)
369: 0f b6 02 movzbl (%edx),%eax
p++, q++;
36c: 8d 59 01 lea 0x1(%ecx),%ebx
}
int
strcmp(const char *p, const char *q)
{
while(*p && *p == *q)
36f: 0f b6 49 01 movzbl 0x1(%ecx),%ecx
373: 84 c0 test %al,%al
375: 75 e9 jne 360 <strcmp+0x20>
377: 31 c0 xor %eax,%eax
p++, q++;
return (uchar)*p - (uchar)*q;
379: 29 c8 sub %ecx,%eax
}
37b: 5b pop %ebx
37c: 5d pop %ebp
37d: c3 ret
37e: 0f b6 09 movzbl (%ecx),%ecx
}
int
strcmp(const char *p, const char *q)
{
while(*p && *p == *q)
381: 31 c0 xor %eax,%eax
383: eb f4 jmp 379 <strcmp+0x39>
385: 0f b6 cb movzbl %bl,%ecx
388: eb ef jmp 379 <strcmp+0x39>
38a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
00000390 <strlen>:
return (uchar)*p - (uchar)*q;
}
uint
strlen(const char *s)
{
390: 55 push %ebp
391: 89 e5 mov %esp,%ebp
393: 8b 4d 08 mov 0x8(%ebp),%ecx
int n;
for(n = 0; s[n]; n++)
396: 80 39 00 cmpb $0x0,(%ecx)
399: 74 12 je 3ad <strlen+0x1d>
39b: 31 d2 xor %edx,%edx
39d: 8d 76 00 lea 0x0(%esi),%esi
3a0: 83 c2 01 add $0x1,%edx
3a3: 80 3c 11 00 cmpb $0x0,(%ecx,%edx,1)
3a7: 89 d0 mov %edx,%eax
3a9: 75 f5 jne 3a0 <strlen+0x10>
;
return n;
}
3ab: 5d pop %ebp
3ac: c3 ret
uint
strlen(const char *s)
{
int n;
for(n = 0; s[n]; n++)
3ad: 31 c0 xor %eax,%eax
;
return n;
}
3af: 5d pop %ebp
3b0: c3 ret
3b1: eb 0d jmp 3c0 <memset>
3b3: 90 nop
3b4: 90 nop
3b5: 90 nop
3b6: 90 nop
3b7: 90 nop
3b8: 90 nop
3b9: 90 nop
3ba: 90 nop
3bb: 90 nop
3bc: 90 nop
3bd: 90 nop
3be: 90 nop
3bf: 90 nop
000003c0 <memset>:
void*
memset(void *dst, int c, uint n)
{
3c0: 55 push %ebp
3c1: 89 e5 mov %esp,%ebp
3c3: 8b 55 08 mov 0x8(%ebp),%edx
3c6: 57 push %edi
}
static inline void
stosb(void *addr, int data, int cnt)
{
asm volatile("cld; rep stosb" :
3c7: 8b 4d 10 mov 0x10(%ebp),%ecx
3ca: 8b 45 0c mov 0xc(%ebp),%eax
3cd: 89 d7 mov %edx,%edi
3cf: fc cld
3d0: f3 aa rep stos %al,%es:(%edi)
stosb(dst, c, n);
return dst;
}
3d2: 89 d0 mov %edx,%eax
3d4: 5f pop %edi
3d5: 5d pop %ebp
3d6: c3 ret
3d7: 89 f6 mov %esi,%esi
3d9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
000003e0 <strchr>:
char*
strchr(const char *s, char c)
{
3e0: 55 push %ebp
3e1: 89 e5 mov %esp,%ebp
3e3: 8b 45 08 mov 0x8(%ebp),%eax
3e6: 53 push %ebx
3e7: 8b 55 0c mov 0xc(%ebp),%edx
for(; *s; s++)
3ea: 0f b6 18 movzbl (%eax),%ebx
3ed: 84 db test %bl,%bl
3ef: 74 1d je 40e <strchr+0x2e>
if(*s == c)
3f1: 38 d3 cmp %dl,%bl
3f3: 89 d1 mov %edx,%ecx
3f5: 75 0d jne 404 <strchr+0x24>
3f7: eb 17 jmp 410 <strchr+0x30>
3f9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
400: 38 ca cmp %cl,%dl
402: 74 0c je 410 <strchr+0x30>
}
char*
strchr(const char *s, char c)
{
for(; *s; s++)
404: 83 c0 01 add $0x1,%eax
407: 0f b6 10 movzbl (%eax),%edx
40a: 84 d2 test %dl,%dl
40c: 75 f2 jne 400 <strchr+0x20>
if(*s == c)
return (char*)s;
return 0;
40e: 31 c0 xor %eax,%eax
}
410: 5b pop %ebx
411: 5d pop %ebp
412: c3 ret
413: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
419: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000420 <gets>:
char*
gets(char *buf, int max)
{
420: 55 push %ebp
421: 89 e5 mov %esp,%ebp
423: 57 push %edi
424: 56 push %esi
int i, cc;
char c;
for(i=0; i+1 < max; ){
425: 31 f6 xor %esi,%esi
return 0;
}
char*
gets(char *buf, int max)
{
427: 53 push %ebx
428: 83 ec 2c sub $0x2c,%esp
int i, cc;
char c;
for(i=0; i+1 < max; ){
cc = read(0, &c, 1);
42b: 8d 7d e7 lea -0x19(%ebp),%edi
gets(char *buf, int max)
{
int i, cc;
char c;
for(i=0; i+1 < max; ){
42e: eb 31 jmp 461 <gets+0x41>
cc = read(0, &c, 1);
430: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp)
437: 00
438: 89 7c 24 04 mov %edi,0x4(%esp)
43c: c7 04 24 00 00 00 00 movl $0x0,(%esp)
443: e8 02 01 00 00 call 54a <read>
if(cc < 1)
448: 85 c0 test %eax,%eax
44a: 7e 1d jle 469 <gets+0x49>
break;
buf[i++] = c;
44c: 0f b6 45 e7 movzbl -0x19(%ebp),%eax
gets(char *buf, int max)
{
int i, cc;
char c;
for(i=0; i+1 < max; ){
450: 89 de mov %ebx,%esi
cc = read(0, &c, 1);
if(cc < 1)
break;
buf[i++] = c;
452: 8b 55 08 mov 0x8(%ebp),%edx
if(c == '\n' || c == '\r')
455: 3c 0d cmp $0xd,%al
for(i=0; i+1 < max; ){
cc = read(0, &c, 1);
if(cc < 1)
break;
buf[i++] = c;
457: 88 44 1a ff mov %al,-0x1(%edx,%ebx,1)
if(c == '\n' || c == '\r')
45b: 74 0c je 469 <gets+0x49>
45d: 3c 0a cmp $0xa,%al
45f: 74 08 je 469 <gets+0x49>
gets(char *buf, int max)
{
int i, cc;
char c;
for(i=0; i+1 < max; ){
461: 8d 5e 01 lea 0x1(%esi),%ebx
464: 3b 5d 0c cmp 0xc(%ebp),%ebx
467: 7c c7 jl 430 <gets+0x10>
break;
buf[i++] = c;
if(c == '\n' || c == '\r')
break;
}
buf[i] = '\0';
469: 8b 45 08 mov 0x8(%ebp),%eax
46c: c6 04 30 00 movb $0x0,(%eax,%esi,1)
return buf;
}
470: 83 c4 2c add $0x2c,%esp
473: 5b pop %ebx
474: 5e pop %esi
475: 5f pop %edi
476: 5d pop %ebp
477: c3 ret
478: 90 nop
479: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
00000480 <stat>:
int
stat(const char *n, struct stat *st)
{
480: 55 push %ebp
481: 89 e5 mov %esp,%ebp
483: 56 push %esi
484: 53 push %ebx
485: 83 ec 10 sub $0x10,%esp
int fd;
int r;
fd = open(n, O_RDONLY);
488: 8b 45 08 mov 0x8(%ebp),%eax
48b: c7 44 24 04 00 00 00 movl $0x0,0x4(%esp)
492: 00
493: 89 04 24 mov %eax,(%esp)
496: e8 d7 00 00 00 call 572 <open>
if(fd < 0)
49b: 85 c0 test %eax,%eax
stat(const char *n, struct stat *st)
{
int fd;
int r;
fd = open(n, O_RDONLY);
49d: 89 c3 mov %eax,%ebx
if(fd < 0)
49f: 78 27 js 4c8 <stat+0x48>
return -1;
r = fstat(fd, st);
4a1: 8b 45 0c mov 0xc(%ebp),%eax
4a4: 89 1c 24 mov %ebx,(%esp)
4a7: 89 44 24 04 mov %eax,0x4(%esp)
4ab: e8 da 00 00 00 call 58a <fstat>
close(fd);
4b0: 89 1c 24 mov %ebx,(%esp)
int r;
fd = open(n, O_RDONLY);
if(fd < 0)
return -1;
r = fstat(fd, st);
4b3: 89 c6 mov %eax,%esi
close(fd);
4b5: e8 a0 00 00 00 call 55a <close>
return r;
4ba: 89 f0 mov %esi,%eax
}
4bc: 83 c4 10 add $0x10,%esp
4bf: 5b pop %ebx
4c0: 5e pop %esi
4c1: 5d pop %ebp
4c2: c3 ret
4c3: 90 nop
4c4: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
int fd;
int r;
fd = open(n, O_RDONLY);
if(fd < 0)
return -1;
4c8: b8 ff ff ff ff mov $0xffffffff,%eax
4cd: eb ed jmp 4bc <stat+0x3c>
4cf: 90 nop
000004d0 <atoi>:
return r;
}
int
atoi(const char *s)
{
4d0: 55 push %ebp
4d1: 89 e5 mov %esp,%ebp
4d3: 8b 4d 08 mov 0x8(%ebp),%ecx
4d6: 53 push %ebx
int n;
n = 0;
while('0' <= *s && *s <= '9')
4d7: 0f be 11 movsbl (%ecx),%edx
4da: 8d 42 d0 lea -0x30(%edx),%eax
4dd: 3c 09 cmp $0x9,%al
int
atoi(const char *s)
{
int n;
n = 0;
4df: b8 00 00 00 00 mov $0x0,%eax
while('0' <= *s && *s <= '9')
4e4: 77 17 ja 4fd <atoi+0x2d>
4e6: 66 90 xchg %ax,%ax
n = n*10 + *s++ - '0';
4e8: 83 c1 01 add $0x1,%ecx
4eb: 8d 04 80 lea (%eax,%eax,4),%eax
4ee: 8d 44 42 d0 lea -0x30(%edx,%eax,2),%eax
atoi(const char *s)
{
int n;
n = 0;
while('0' <= *s && *s <= '9')
4f2: 0f be 11 movsbl (%ecx),%edx
4f5: 8d 5a d0 lea -0x30(%edx),%ebx
4f8: 80 fb 09 cmp $0x9,%bl
4fb: 76 eb jbe 4e8 <atoi+0x18>
n = n*10 + *s++ - '0';
return n;
}
4fd: 5b pop %ebx
4fe: 5d pop %ebp
4ff: c3 ret
00000500 <memmove>:
void*
memmove(void *vdst, const void *vsrc, int n)
{
500: 55 push %ebp
char *dst;
const char *src;
dst = vdst;
src = vsrc;
while(n-- > 0)
501: 31 d2 xor %edx,%edx
return n;
}
void*
memmove(void *vdst, const void *vsrc, int n)
{
503: 89 e5 mov %esp,%ebp
505: 56 push %esi
506: 8b 45 08 mov 0x8(%ebp),%eax
509: 53 push %ebx
50a: 8b 5d 10 mov 0x10(%ebp),%ebx
50d: 8b 75 0c mov 0xc(%ebp),%esi
char *dst;
const char *src;
dst = vdst;
src = vsrc;
while(n-- > 0)
510: 85 db test %ebx,%ebx
512: 7e 12 jle 526 <memmove+0x26>
514: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
*dst++ = *src++;
518: 0f b6 0c 16 movzbl (%esi,%edx,1),%ecx
51c: 88 0c 10 mov %cl,(%eax,%edx,1)
51f: 83 c2 01 add $0x1,%edx
char *dst;
const char *src;
dst = vdst;
src = vsrc;
while(n-- > 0)
522: 39 da cmp %ebx,%edx
524: 75 f2 jne 518 <memmove+0x18>
*dst++ = *src++;
return vdst;
}
526: 5b pop %ebx
527: 5e pop %esi
528: 5d pop %ebp
529: c3 ret
0000052a <fork>:
name: \
movl $SYS_ ## name, %eax; \
int $T_SYSCALL; \
ret
SYSCALL(fork)
52a: b8 01 00 00 00 mov $0x1,%eax
52f: cd 40 int $0x40
531: c3 ret
00000532 <exit>:
SYSCALL(exit)
532: b8 02 00 00 00 mov $0x2,%eax
537: cd 40 int $0x40
539: c3 ret
0000053a <wait>:
SYSCALL(wait)
53a: b8 03 00 00 00 mov $0x3,%eax
53f: cd 40 int $0x40
541: c3 ret
00000542 <pipe>:
SYSCALL(pipe)
542: b8 04 00 00 00 mov $0x4,%eax
547: cd 40 int $0x40
549: c3 ret
0000054a <read>:
SYSCALL(read)
54a: b8 05 00 00 00 mov $0x5,%eax
54f: cd 40 int $0x40
551: c3 ret
00000552 <write>:
SYSCALL(write)
552: b8 10 00 00 00 mov $0x10,%eax
557: cd 40 int $0x40
559: c3 ret
0000055a <close>:
SYSCALL(close)
55a: b8 15 00 00 00 mov $0x15,%eax
55f: cd 40 int $0x40
561: c3 ret
00000562 <kill>:
SYSCALL(kill)
562: b8 06 00 00 00 mov $0x6,%eax
567: cd 40 int $0x40
569: c3 ret
0000056a <exec>:
SYSCALL(exec)
56a: b8 07 00 00 00 mov $0x7,%eax
56f: cd 40 int $0x40
571: c3 ret
00000572 <open>:
SYSCALL(open)
572: b8 0f 00 00 00 mov $0xf,%eax
577: cd 40 int $0x40
579: c3 ret
0000057a <mknod>:
SYSCALL(mknod)
57a: b8 11 00 00 00 mov $0x11,%eax
57f: cd 40 int $0x40
581: c3 ret
00000582 <unlink>:
SYSCALL(unlink)
582: b8 12 00 00 00 mov $0x12,%eax
587: cd 40 int $0x40
589: c3 ret
0000058a <fstat>:
SYSCALL(fstat)
58a: b8 08 00 00 00 mov $0x8,%eax
58f: cd 40 int $0x40
591: c3 ret
00000592 <link>:
SYSCALL(link)
592: b8 13 00 00 00 mov $0x13,%eax
597: cd 40 int $0x40
599: c3 ret
0000059a <mkdir>:
SYSCALL(mkdir)
59a: b8 14 00 00 00 mov $0x14,%eax
59f: cd 40 int $0x40
5a1: c3 ret
000005a2 <chdir>:
SYSCALL(chdir)
5a2: b8 09 00 00 00 mov $0x9,%eax
5a7: cd 40 int $0x40
5a9: c3 ret
000005aa <dup>:
SYSCALL(dup)
5aa: b8 0a 00 00 00 mov $0xa,%eax
5af: cd 40 int $0x40
5b1: c3 ret
000005b2 <getpid>:
SYSCALL(getpid)
5b2: b8 0b 00 00 00 mov $0xb,%eax
5b7: cd 40 int $0x40
5b9: c3 ret
000005ba <sbrk>:
SYSCALL(sbrk)
5ba: b8 0c 00 00 00 mov $0xc,%eax
5bf: cd 40 int $0x40
5c1: c3 ret
000005c2 <sleep>:
SYSCALL(sleep)
5c2: b8 0d 00 00 00 mov $0xd,%eax
5c7: cd 40 int $0x40
5c9: c3 ret
000005ca <uptime>:
SYSCALL(uptime)
5ca: b8 0e 00 00 00 mov $0xe,%eax
5cf: cd 40 int $0x40
5d1: c3 ret
5d2: 66 90 xchg %ax,%ax
5d4: 66 90 xchg %ax,%ax
5d6: 66 90 xchg %ax,%ax
5d8: 66 90 xchg %ax,%ax
5da: 66 90 xchg %ax,%ax
5dc: 66 90 xchg %ax,%ax
5de: 66 90 xchg %ax,%ax
000005e0 <printint>:
write(fd, &c, 1);
}
static void
printint(int fd, int xx, int base, int sgn)
{
5e0: 55 push %ebp
5e1: 89 e5 mov %esp,%ebp
5e3: 57 push %edi
5e4: 56 push %esi
5e5: 89 c6 mov %eax,%esi
5e7: 53 push %ebx
5e8: 83 ec 4c sub $0x4c,%esp
char buf[16];
int i, neg;
uint x;
neg = 0;
if(sgn && xx < 0){
5eb: 8b 5d 08 mov 0x8(%ebp),%ebx
5ee: 85 db test %ebx,%ebx
5f0: 74 09 je 5fb <printint+0x1b>
5f2: 89 d0 mov %edx,%eax
5f4: c1 e8 1f shr $0x1f,%eax
5f7: 84 c0 test %al,%al
5f9: 75 75 jne 670 <printint+0x90>
neg = 1;
x = -xx;
} else {
x = xx;
5fb: 89 d0 mov %edx,%eax
static char digits[] = "0123456789ABCDEF";
char buf[16];
int i, neg;
uint x;
neg = 0;
5fd: c7 45 c4 00 00 00 00 movl $0x0,-0x3c(%ebp)
604: 89 75 c0 mov %esi,-0x40(%ebp)
x = -xx;
} else {
x = xx;
}
i = 0;
607: 31 ff xor %edi,%edi
609: 89 ce mov %ecx,%esi
60b: 8d 5d d7 lea -0x29(%ebp),%ebx
60e: eb 02 jmp 612 <printint+0x32>
do{
buf[i++] = digits[x % base];
610: 89 cf mov %ecx,%edi
612: 31 d2 xor %edx,%edx
614: f7 f6 div %esi
616: 8d 4f 01 lea 0x1(%edi),%ecx
619: 0f b6 92 25 0a 00 00 movzbl 0xa25(%edx),%edx
}while((x /= base) != 0);
620: 85 c0 test %eax,%eax
x = xx;
}
i = 0;
do{
buf[i++] = digits[x % base];
622: 88 14 0b mov %dl,(%ebx,%ecx,1)
}while((x /= base) != 0);
625: 75 e9 jne 610 <printint+0x30>
if(neg)
627: 8b 55 c4 mov -0x3c(%ebp),%edx
x = xx;
}
i = 0;
do{
buf[i++] = digits[x % base];
62a: 89 c8 mov %ecx,%eax
62c: 8b 75 c0 mov -0x40(%ebp),%esi
}while((x /= base) != 0);
if(neg)
62f: 85 d2 test %edx,%edx
631: 74 08 je 63b <printint+0x5b>
buf[i++] = '-';
633: 8d 4f 02 lea 0x2(%edi),%ecx
636: c6 44 05 d8 2d movb $0x2d,-0x28(%ebp,%eax,1)
while(--i >= 0)
63b: 8d 79 ff lea -0x1(%ecx),%edi
63e: 66 90 xchg %ax,%ax
640: 0f b6 44 3d d8 movzbl -0x28(%ebp,%edi,1),%eax
645: 83 ef 01 sub $0x1,%edi
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
648: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp)
64f: 00
650: 89 5c 24 04 mov %ebx,0x4(%esp)
654: 89 34 24 mov %esi,(%esp)
657: 88 45 d7 mov %al,-0x29(%ebp)
65a: e8 f3 fe ff ff call 552 <write>
buf[i++] = digits[x % base];
}while((x /= base) != 0);
if(neg)
buf[i++] = '-';
while(--i >= 0)
65f: 83 ff ff cmp $0xffffffff,%edi
662: 75 dc jne 640 <printint+0x60>
putc(fd, buf[i]);
}
664: 83 c4 4c add $0x4c,%esp
667: 5b pop %ebx
668: 5e pop %esi
669: 5f pop %edi
66a: 5d pop %ebp
66b: c3 ret
66c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
uint x;
neg = 0;
if(sgn && xx < 0){
neg = 1;
x = -xx;
670: 89 d0 mov %edx,%eax
672: f7 d8 neg %eax
int i, neg;
uint x;
neg = 0;
if(sgn && xx < 0){
neg = 1;
674: c7 45 c4 01 00 00 00 movl $0x1,-0x3c(%ebp)
67b: eb 87 jmp 604 <printint+0x24>
67d: 8d 76 00 lea 0x0(%esi),%esi
00000680 <printf>:
}
// Print to the given fd. Only understands %d, %x, %p, %s.
void
printf(int fd, const char *fmt, ...)
{
680: 55 push %ebp
681: 89 e5 mov %esp,%ebp
683: 57 push %edi
char *s;
int c, i, state;
uint *ap;
state = 0;
684: 31 ff xor %edi,%edi
}
// Print to the given fd. Only understands %d, %x, %p, %s.
void
printf(int fd, const char *fmt, ...)
{
686: 56 push %esi
687: 53 push %ebx
688: 83 ec 3c sub $0x3c,%esp
int c, i, state;
uint *ap;
state = 0;
ap = (uint*)(void*)&fmt + 1;
for(i = 0; fmt[i]; i++){
68b: 8b 5d 0c mov 0xc(%ebp),%ebx
char *s;
int c, i, state;
uint *ap;
state = 0;
ap = (uint*)(void*)&fmt + 1;
68e: 8d 45 10 lea 0x10(%ebp),%eax
}
// Print to the given fd. Only understands %d, %x, %p, %s.
void
printf(int fd, const char *fmt, ...)
{
691: 8b 75 08 mov 0x8(%ebp),%esi
char *s;
int c, i, state;
uint *ap;
state = 0;
ap = (uint*)(void*)&fmt + 1;
694: 89 45 d4 mov %eax,-0x2c(%ebp)
for(i = 0; fmt[i]; i++){
697: 0f b6 13 movzbl (%ebx),%edx
69a: 83 c3 01 add $0x1,%ebx
69d: 84 d2 test %dl,%dl
69f: 75 39 jne 6da <printf+0x5a>
6a1: e9 c2 00 00 00 jmp 768 <printf+0xe8>
6a6: 66 90 xchg %ax,%ax
c = fmt[i] & 0xff;
if(state == 0){
if(c == '%'){
6a8: 83 fa 25 cmp $0x25,%edx
6ab: 0f 84 bf 00 00 00 je 770 <printf+0xf0>
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
6b1: 8d 45 e2 lea -0x1e(%ebp),%eax
6b4: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp)
6bb: 00
6bc: 89 44 24 04 mov %eax,0x4(%esp)
6c0: 89 34 24 mov %esi,(%esp)
c = fmt[i] & 0xff;
if(state == 0){
if(c == '%'){
state = '%';
} else {
putc(fd, c);
6c3: 88 55 e2 mov %dl,-0x1e(%ebp)
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
6c6: e8 87 fe ff ff call 552 <write>
6cb: 83 c3 01 add $0x1,%ebx
int c, i, state;
uint *ap;
state = 0;
ap = (uint*)(void*)&fmt + 1;
for(i = 0; fmt[i]; i++){
6ce: 0f b6 53 ff movzbl -0x1(%ebx),%edx
6d2: 84 d2 test %dl,%dl
6d4: 0f 84 8e 00 00 00 je 768 <printf+0xe8>
c = fmt[i] & 0xff;
if(state == 0){
6da: 85 ff test %edi,%edi
uint *ap;
state = 0;
ap = (uint*)(void*)&fmt + 1;
for(i = 0; fmt[i]; i++){
c = fmt[i] & 0xff;
6dc: 0f be c2 movsbl %dl,%eax
if(state == 0){
6df: 74 c7 je 6a8 <printf+0x28>
if(c == '%'){
state = '%';
} else {
putc(fd, c);
}
} else if(state == '%'){
6e1: 83 ff 25 cmp $0x25,%edi
6e4: 75 e5 jne 6cb <printf+0x4b>
if(c == 'd'){
6e6: 83 fa 64 cmp $0x64,%edx
6e9: 0f 84 31 01 00 00 je 820 <printf+0x1a0>
printint(fd, *ap, 10, 1);
ap++;
} else if(c == 'x' || c == 'p'){
6ef: 25 f7 00 00 00 and $0xf7,%eax
6f4: 83 f8 70 cmp $0x70,%eax
6f7: 0f 84 83 00 00 00 je 780 <printf+0x100>
printint(fd, *ap, 16, 0);
ap++;
} else if(c == 's'){
6fd: 83 fa 73 cmp $0x73,%edx
700: 0f 84 a2 00 00 00 je 7a8 <printf+0x128>
s = "(null)";
while(*s != 0){
putc(fd, *s);
s++;
}
} else if(c == 'c'){
706: 83 fa 63 cmp $0x63,%edx
709: 0f 84 35 01 00 00 je 844 <printf+0x1c4>
putc(fd, *ap);
ap++;
} else if(c == '%'){
70f: 83 fa 25 cmp $0x25,%edx
712: 0f 84 e0 00 00 00 je 7f8 <printf+0x178>
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
718: 8d 45 e6 lea -0x1a(%ebp),%eax
71b: 83 c3 01 add $0x1,%ebx
71e: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp)
725: 00
} else {
// Unknown % sequence. Print it to draw attention.
putc(fd, '%');
putc(fd, c);
}
state = 0;
726: 31 ff xor %edi,%edi
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
728: 89 44 24 04 mov %eax,0x4(%esp)
72c: 89 34 24 mov %esi,(%esp)
72f: 89 55 d0 mov %edx,-0x30(%ebp)
732: c6 45 e6 25 movb $0x25,-0x1a(%ebp)
736: e8 17 fe ff ff call 552 <write>
} else if(c == '%'){
putc(fd, c);
} else {
// Unknown % sequence. Print it to draw attention.
putc(fd, '%');
putc(fd, c);
73b: 8b 55 d0 mov -0x30(%ebp),%edx
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
73e: 8d 45 e7 lea -0x19(%ebp),%eax
741: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp)
748: 00
749: 89 44 24 04 mov %eax,0x4(%esp)
74d: 89 34 24 mov %esi,(%esp)
} else if(c == '%'){
putc(fd, c);
} else {
// Unknown % sequence. Print it to draw attention.
putc(fd, '%');
putc(fd, c);
750: 88 55 e7 mov %dl,-0x19(%ebp)
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
753: e8 fa fd ff ff call 552 <write>
int c, i, state;
uint *ap;
state = 0;
ap = (uint*)(void*)&fmt + 1;
for(i = 0; fmt[i]; i++){
758: 0f b6 53 ff movzbl -0x1(%ebx),%edx
75c: 84 d2 test %dl,%dl
75e: 0f 85 76 ff ff ff jne 6da <printf+0x5a>
764: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
putc(fd, c);
}
state = 0;
}
}
}
768: 83 c4 3c add $0x3c,%esp
76b: 5b pop %ebx
76c: 5e pop %esi
76d: 5f pop %edi
76e: 5d pop %ebp
76f: c3 ret
ap = (uint*)(void*)&fmt + 1;
for(i = 0; fmt[i]; i++){
c = fmt[i] & 0xff;
if(state == 0){
if(c == '%'){
state = '%';
770: bf 25 00 00 00 mov $0x25,%edi
775: e9 51 ff ff ff jmp 6cb <printf+0x4b>
77a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
} else if(state == '%'){
if(c == 'd'){
printint(fd, *ap, 10, 1);
ap++;
} else if(c == 'x' || c == 'p'){
printint(fd, *ap, 16, 0);
780: 8b 45 d4 mov -0x2c(%ebp),%eax
783: b9 10 00 00 00 mov $0x10,%ecx
} else {
// Unknown % sequence. Print it to draw attention.
putc(fd, '%');
putc(fd, c);
}
state = 0;
788: 31 ff xor %edi,%edi
} else if(state == '%'){
if(c == 'd'){
printint(fd, *ap, 10, 1);
ap++;
} else if(c == 'x' || c == 'p'){
printint(fd, *ap, 16, 0);
78a: c7 04 24 00 00 00 00 movl $0x0,(%esp)
791: 8b 10 mov (%eax),%edx
793: 89 f0 mov %esi,%eax
795: e8 46 fe ff ff call 5e0 <printint>
ap++;
79a: 83 45 d4 04 addl $0x4,-0x2c(%ebp)
79e: e9 28 ff ff ff jmp 6cb <printf+0x4b>
7a3: 90 nop
7a4: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
} else if(c == 's'){
s = (char*)*ap;
7a8: 8b 45 d4 mov -0x2c(%ebp),%eax
ap++;
7ab: 83 45 d4 04 addl $0x4,-0x2c(%ebp)
ap++;
} else if(c == 'x' || c == 'p'){
printint(fd, *ap, 16, 0);
ap++;
} else if(c == 's'){
s = (char*)*ap;
7af: 8b 38 mov (%eax),%edi
ap++;
if(s == 0)
s = "(null)";
7b1: b8 1e 0a 00 00 mov $0xa1e,%eax
7b6: 85 ff test %edi,%edi
7b8: 0f 44 f8 cmove %eax,%edi
while(*s != 0){
7bb: 0f b6 07 movzbl (%edi),%eax
7be: 84 c0 test %al,%al
7c0: 74 2a je 7ec <printf+0x16c>
7c2: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
7c8: 88 45 e3 mov %al,-0x1d(%ebp)
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
7cb: 8d 45 e3 lea -0x1d(%ebp),%eax
ap++;
if(s == 0)
s = "(null)";
while(*s != 0){
putc(fd, *s);
s++;
7ce: 83 c7 01 add $0x1,%edi
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
7d1: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp)
7d8: 00
7d9: 89 44 24 04 mov %eax,0x4(%esp)
7dd: 89 34 24 mov %esi,(%esp)
7e0: e8 6d fd ff ff call 552 <write>
} else if(c == 's'){
s = (char*)*ap;
ap++;
if(s == 0)
s = "(null)";
while(*s != 0){
7e5: 0f b6 07 movzbl (%edi),%eax
7e8: 84 c0 test %al,%al
7ea: 75 dc jne 7c8 <printf+0x148>
} else {
// Unknown % sequence. Print it to draw attention.
putc(fd, '%');
putc(fd, c);
}
state = 0;
7ec: 31 ff xor %edi,%edi
7ee: e9 d8 fe ff ff jmp 6cb <printf+0x4b>
7f3: 90 nop
7f4: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
7f8: 8d 45 e5 lea -0x1b(%ebp),%eax
} else {
// Unknown % sequence. Print it to draw attention.
putc(fd, '%');
putc(fd, c);
}
state = 0;
7fb: 31 ff xor %edi,%edi
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
7fd: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp)
804: 00
805: 89 44 24 04 mov %eax,0x4(%esp)
809: 89 34 24 mov %esi,(%esp)
80c: c6 45 e5 25 movb $0x25,-0x1b(%ebp)
810: e8 3d fd ff ff call 552 <write>
815: e9 b1 fe ff ff jmp 6cb <printf+0x4b>
81a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
} else {
putc(fd, c);
}
} else if(state == '%'){
if(c == 'd'){
printint(fd, *ap, 10, 1);
820: 8b 45 d4 mov -0x2c(%ebp),%eax
823: b9 0a 00 00 00 mov $0xa,%ecx
} else {
// Unknown % sequence. Print it to draw attention.
putc(fd, '%');
putc(fd, c);
}
state = 0;
828: 66 31 ff xor %di,%di
} else {
putc(fd, c);
}
} else if(state == '%'){
if(c == 'd'){
printint(fd, *ap, 10, 1);
82b: c7 04 24 01 00 00 00 movl $0x1,(%esp)
832: 8b 10 mov (%eax),%edx
834: 89 f0 mov %esi,%eax
836: e8 a5 fd ff ff call 5e0 <printint>
ap++;
83b: 83 45 d4 04 addl $0x4,-0x2c(%ebp)
83f: e9 87 fe ff ff jmp 6cb <printf+0x4b>
while(*s != 0){
putc(fd, *s);
s++;
}
} else if(c == 'c'){
putc(fd, *ap);
844: 8b 45 d4 mov -0x2c(%ebp),%eax
} else {
// Unknown % sequence. Print it to draw attention.
putc(fd, '%');
putc(fd, c);
}
state = 0;
847: 31 ff xor %edi,%edi
while(*s != 0){
putc(fd, *s);
s++;
}
} else if(c == 'c'){
putc(fd, *ap);
849: 8b 00 mov (%eax),%eax
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
84b: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp)
852: 00
853: 89 34 24 mov %esi,(%esp)
while(*s != 0){
putc(fd, *s);
s++;
}
} else if(c == 'c'){
putc(fd, *ap);
856: 88 45 e4 mov %al,-0x1c(%ebp)
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
859: 8d 45 e4 lea -0x1c(%ebp),%eax
85c: 89 44 24 04 mov %eax,0x4(%esp)
860: e8 ed fc ff ff call 552 <write>
putc(fd, *s);
s++;
}
} else if(c == 'c'){
putc(fd, *ap);
ap++;
865: 83 45 d4 04 addl $0x4,-0x2c(%ebp)
869: e9 5d fe ff ff jmp 6cb <printf+0x4b>
86e: 66 90 xchg %ax,%ax
00000870 <free>:
static Header base;
static Header *freep;
void
free(void *ap)
{
870: 55 push %ebp
Header *bp, *p;
bp = (Header*)ap - 1;
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
871: a1 80 0d 00 00 mov 0xd80,%eax
static Header base;
static Header *freep;
void
free(void *ap)
{
876: 89 e5 mov %esp,%ebp
878: 57 push %edi
879: 56 push %esi
87a: 53 push %ebx
87b: 8b 5d 08 mov 0x8(%ebp),%ebx
Header *bp, *p;
bp = (Header*)ap - 1;
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
87e: 8b 08 mov (%eax),%ecx
void
free(void *ap)
{
Header *bp, *p;
bp = (Header*)ap - 1;
880: 8d 53 f8 lea -0x8(%ebx),%edx
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
883: 39 d0 cmp %edx,%eax
885: 72 11 jb 898 <free+0x28>
887: 90 nop
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
888: 39 c8 cmp %ecx,%eax
88a: 72 04 jb 890 <free+0x20>
88c: 39 ca cmp %ecx,%edx
88e: 72 10 jb 8a0 <free+0x30>
890: 89 c8 mov %ecx,%eax
free(void *ap)
{
Header *bp, *p;
bp = (Header*)ap - 1;
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
892: 39 d0 cmp %edx,%eax
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
894: 8b 08 mov (%eax),%ecx
free(void *ap)
{
Header *bp, *p;
bp = (Header*)ap - 1;
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
896: 73 f0 jae 888 <free+0x18>
898: 39 ca cmp %ecx,%edx
89a: 72 04 jb 8a0 <free+0x30>
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
89c: 39 c8 cmp %ecx,%eax
89e: 72 f0 jb 890 <free+0x20>
break;
if(bp + bp->s.size == p->s.ptr){
8a0: 8b 73 fc mov -0x4(%ebx),%esi
8a3: 8d 3c f2 lea (%edx,%esi,8),%edi
8a6: 39 cf cmp %ecx,%edi
8a8: 74 1e je 8c8 <free+0x58>
bp->s.size += p->s.ptr->s.size;
bp->s.ptr = p->s.ptr->s.ptr;
} else
bp->s.ptr = p->s.ptr;
8aa: 89 4b f8 mov %ecx,-0x8(%ebx)
if(p + p->s.size == bp){
8ad: 8b 48 04 mov 0x4(%eax),%ecx
8b0: 8d 34 c8 lea (%eax,%ecx,8),%esi
8b3: 39 f2 cmp %esi,%edx
8b5: 74 28 je 8df <free+0x6f>
p->s.size += bp->s.size;
p->s.ptr = bp->s.ptr;
} else
p->s.ptr = bp;
8b7: 89 10 mov %edx,(%eax)
freep = p;
8b9: a3 80 0d 00 00 mov %eax,0xd80
}
8be: 5b pop %ebx
8bf: 5e pop %esi
8c0: 5f pop %edi
8c1: 5d pop %ebp
8c2: c3 ret
8c3: 90 nop
8c4: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
bp = (Header*)ap - 1;
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
break;
if(bp + bp->s.size == p->s.ptr){
bp->s.size += p->s.ptr->s.size;
8c8: 03 71 04 add 0x4(%ecx),%esi
8cb: 89 73 fc mov %esi,-0x4(%ebx)
bp->s.ptr = p->s.ptr->s.ptr;
8ce: 8b 08 mov (%eax),%ecx
8d0: 8b 09 mov (%ecx),%ecx
8d2: 89 4b f8 mov %ecx,-0x8(%ebx)
} else
bp->s.ptr = p->s.ptr;
if(p + p->s.size == bp){
8d5: 8b 48 04 mov 0x4(%eax),%ecx
8d8: 8d 34 c8 lea (%eax,%ecx,8),%esi
8db: 39 f2 cmp %esi,%edx
8dd: 75 d8 jne 8b7 <free+0x47>
p->s.size += bp->s.size;
8df: 03 4b fc add -0x4(%ebx),%ecx
p->s.ptr = bp->s.ptr;
} else
p->s.ptr = bp;
freep = p;
8e2: a3 80 0d 00 00 mov %eax,0xd80
bp->s.size += p->s.ptr->s.size;
bp->s.ptr = p->s.ptr->s.ptr;
} else
bp->s.ptr = p->s.ptr;
if(p + p->s.size == bp){
p->s.size += bp->s.size;
8e7: 89 48 04 mov %ecx,0x4(%eax)
p->s.ptr = bp->s.ptr;
8ea: 8b 53 f8 mov -0x8(%ebx),%edx
8ed: 89 10 mov %edx,(%eax)
} else
p->s.ptr = bp;
freep = p;
}
8ef: 5b pop %ebx
8f0: 5e pop %esi
8f1: 5f pop %edi
8f2: 5d pop %ebp
8f3: c3 ret
8f4: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
8fa: 8d bf 00 00 00 00 lea 0x0(%edi),%edi
00000900 <malloc>:
return freep;
}
void*
malloc(uint nbytes)
{
900: 55 push %ebp
901: 89 e5 mov %esp,%ebp
903: 57 push %edi
904: 56 push %esi
905: 53 push %ebx
906: 83 ec 1c sub $0x1c,%esp
Header *p, *prevp;
uint nunits;
nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
909: 8b 45 08 mov 0x8(%ebp),%eax
if((prevp = freep) == 0){
90c: 8b 1d 80 0d 00 00 mov 0xd80,%ebx
malloc(uint nbytes)
{
Header *p, *prevp;
uint nunits;
nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
912: 8d 48 07 lea 0x7(%eax),%ecx
915: c1 e9 03 shr $0x3,%ecx
if((prevp = freep) == 0){
918: 85 db test %ebx,%ebx
malloc(uint nbytes)
{
Header *p, *prevp;
uint nunits;
nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
91a: 8d 71 01 lea 0x1(%ecx),%esi
if((prevp = freep) == 0){
91d: 0f 84 9b 00 00 00 je 9be <malloc+0xbe>
923: 8b 13 mov (%ebx),%edx
925: 8b 7a 04 mov 0x4(%edx),%edi
base.s.ptr = freep = prevp = &base;
base.s.size = 0;
}
for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
if(p->s.size >= nunits){
928: 39 fe cmp %edi,%esi
92a: 76 64 jbe 990 <malloc+0x90>
92c: 8d 04 f5 00 00 00 00 lea 0x0(,%esi,8),%eax
morecore(uint nu)
{
char *p;
Header *hp;
if(nu < 4096)
933: bb 00 80 00 00 mov $0x8000,%ebx
938: 89 45 e4 mov %eax,-0x1c(%ebp)
93b: eb 0e jmp 94b <malloc+0x4b>
93d: 8d 76 00 lea 0x0(%esi),%esi
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){
940: 8b 02 mov (%edx),%eax
if(p->s.size >= nunits){
942: 8b 78 04 mov 0x4(%eax),%edi
945: 39 fe cmp %edi,%esi
947: 76 4f jbe 998 <malloc+0x98>
949: 89 c2 mov %eax,%edx
p->s.size = nunits;
}
freep = prevp;
return (void*)(p + 1);
}
if(p == freep)
94b: 3b 15 80 0d 00 00 cmp 0xd80,%edx
951: 75 ed jne 940 <malloc+0x40>
morecore(uint nu)
{
char *p;
Header *hp;
if(nu < 4096)
953: 8b 45 e4 mov -0x1c(%ebp),%eax
956: 81 fe 00 10 00 00 cmp $0x1000,%esi
95c: bf 00 10 00 00 mov $0x1000,%edi
961: 0f 43 fe cmovae %esi,%edi
964: 0f 42 c3 cmovb %ebx,%eax
nu = 4096;
p = sbrk(nu * sizeof(Header));
967: 89 04 24 mov %eax,(%esp)
96a: e8 4b fc ff ff call 5ba <sbrk>
if(p == (char*)-1)
96f: 83 f8 ff cmp $0xffffffff,%eax
972: 74 18 je 98c <malloc+0x8c>
return 0;
hp = (Header*)p;
hp->s.size = nu;
974: 89 78 04 mov %edi,0x4(%eax)
free((void*)(hp + 1));
977: 83 c0 08 add $0x8,%eax
97a: 89 04 24 mov %eax,(%esp)
97d: e8 ee fe ff ff call 870 <free>
return freep;
982: 8b 15 80 0d 00 00 mov 0xd80,%edx
}
freep = prevp;
return (void*)(p + 1);
}
if(p == freep)
if((p = morecore(nunits)) == 0)
988: 85 d2 test %edx,%edx
98a: 75 b4 jne 940 <malloc+0x40>
return 0;
98c: 31 c0 xor %eax,%eax
98e: eb 20 jmp 9b0 <malloc+0xb0>
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){
if(p->s.size >= nunits){
990: 89 d0 mov %edx,%eax
992: 89 da mov %ebx,%edx
994: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
if(p->s.size == nunits)
998: 39 fe cmp %edi,%esi
99a: 74 1c je 9b8 <malloc+0xb8>
prevp->s.ptr = p->s.ptr;
else {
p->s.size -= nunits;
99c: 29 f7 sub %esi,%edi
99e: 89 78 04 mov %edi,0x4(%eax)
p += p->s.size;
9a1: 8d 04 f8 lea (%eax,%edi,8),%eax
p->s.size = nunits;
9a4: 89 70 04 mov %esi,0x4(%eax)
}
freep = prevp;
9a7: 89 15 80 0d 00 00 mov %edx,0xd80
return (void*)(p + 1);
9ad: 83 c0 08 add $0x8,%eax
}
if(p == freep)
if((p = morecore(nunits)) == 0)
return 0;
}
}
9b0: 83 c4 1c add $0x1c,%esp
9b3: 5b pop %ebx
9b4: 5e pop %esi
9b5: 5f pop %edi
9b6: 5d pop %ebp
9b7: c3 ret
base.s.size = 0;
}
for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
if(p->s.size >= nunits){
if(p->s.size == nunits)
prevp->s.ptr = p->s.ptr;
9b8: 8b 08 mov (%eax),%ecx
9ba: 89 0a mov %ecx,(%edx)
9bc: eb e9 jmp 9a7 <malloc+0xa7>
Header *p, *prevp;
uint nunits;
nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
if((prevp = freep) == 0){
base.s.ptr = freep = prevp = &base;
9be: c7 05 80 0d 00 00 84 movl $0xd84,0xd80
9c5: 0d 00 00
base.s.size = 0;
9c8: ba 84 0d 00 00 mov $0xd84,%edx
Header *p, *prevp;
uint nunits;
nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
if((prevp = freep) == 0){
base.s.ptr = freep = prevp = &base;
9cd: c7 05 84 0d 00 00 84 movl $0xd84,0xd84
9d4: 0d 00 00
base.s.size = 0;
9d7: c7 05 88 0d 00 00 00 movl $0x0,0xd88
9de: 00 00 00
9e1: e9 46 ff ff ff jmp 92c <malloc+0x2c>
|
; unsigned char esx_m_tapein_info(uint8_t *drive,unsigned char *filename)
SECTION code_esxdos
PUBLIC _esx_m_tapein_info
EXTERN l0_esx_m_tapein_info_callee
_esx_m_tapein_info:
pop af
pop de
pop hl
push hl
push de
push af
jp l0_esx_m_tapein_info_callee
|
section .data
option_msg: db "Press: 1 - add | 2 - substract | 3 - multiply | 4 - divide", 0xA
option_msg_length equ $- option_msg
num_msg: db "Enter first number", 0xA
num_msg_length equ $- num_msg
add_msg: db "Add", 0xA
add_msg_length equ $- add_msg
sub_msg: db "Substract", 0xA
sub_msg_length equ $- sub_msg
mul_msg: db "Multiply", 0xA
mul_msg_length equ $- mul_msg
div_msg: db "Divide", 0xA
div_msg_length equ $- div_msg
newLine: db 0xA
section .text
_optionMessage:
mov eax, 0x4
mov ebx, 1
mov ecx, option_msg
mov edx, option_msg_length
int 0x80
ret
_numMessage:
mov eax, 0x4
mov ebx, 1
mov ecx, num_msg
mov edx, num_msg_length
int 0x80
ret
_addMessage:
mov eax, 0x4
mov ebx, 1
mov ecx, add_msg
mov edx, add_msg_length
int 0x80
ret
_subMessage:
mov eax, 0x4
mov ebx, 1
mov ecx, sub_msg
mov edx, sub_msg_length
int 0x80
ret
_mulMessage:
mov eax, 0x4
mov ebx, 1
mov ecx, mul_msg
mov edx, mul_msg_length
int 0x80
ret
_divMessage:
mov eax, 0x4
mov ebx, 1
mov ecx, div_msg
mov edx, div_msg_length
int 0x80
ret
_resultMsg:
mov eax, 0x4
mov ebx, 1
mov ecx, result
mov edx, 1
int 0x80
ret
|
MAP_SAMPLE
byte $00,$00,$00,$00,$08,$08,$10,$10,$40,$40,$40,$40,$00, $ff
byte $01,$01,$01,$01,$09,$09,$11,$11,$80,$80,$80,$80,$00, $ff
byte $02,$02,$02,$02,$0A,$0A,$12,$12,$C0,$C0,$C0,$C0,$00, $ff
byte $03,$03,$03,$03,$0B,$0B,$13,$13,$00,$00,$00,$00,$00, $ff
byte $04,$04,$04,$04,$0C,$0C,$20,$20,$00,$00,$00,$00,$00, $ff
byte $05,$05,$05,$05,$0D,$0D,$21,$21,$00,$00,$00,$00,$00, $ff
byte $06,$06,$06,$06,$0E,$0E,$22,$22,$00,$00,$00,$00,$00, $ff
byte $07,$07,$07,$07,$0F,$0F,$23,$23,$00,$00,$00,$00,$00, $ff
incasm "Maps\KITCHEN_01.asm"
incasm "Maps\KITCHEN_02.asm"
incasm "Maps\FOREST_01.asm"
incasm "Maps\FOREST_02.asm"
incasm "Maps\FOREST_03.asm"
incasm "Maps\FOREST_04.asm"
incasm "Maps\FOREST_05.asm"
incasm "Maps\CASTLE_01.asm"
incasm "Maps\SPACE_01.asm"
incasm "Maps\SPACE_02.asm"
incasm "Maps\SPACE_03.asm" |
//
// main.cpp
//
// Created by Mikołaj Semeniuk on 04/04/2020.
// Copyright © 2020 Mikołaj Semeniuk. All rights reserved.
//
#include <iostream>
#include <vector> // needed for using std::vector
#include <set> // needed for using std::set
#include <numeric> // needed for using std::iota, std::accumulate
#include <algorithm> // needed for std::iter_swap, std::min_value, std::max_value
#include <random> // std::rand, std::random_device, std::mt19937, std::shuffle
using namespace std;
void display (std::vector<int> const &v)
{
for (auto &i : v)
cout << i << endl;
}
template <typename T>
void shuffle_vector(std::vector<T>* v)
{
if ((*v).size() < 1)
return;
std::random_device rd;
std::mt19937 g(rd());
std::shuffle((*v).begin(), (*v).end(), g);
}
template <typename T>
T random_choice (const std::vector<T> &v)
{
if (v.size() < 1)
return -1;
int random = std::rand() % v.size();
return v.at(random);
}
template <class T>
void init (vector<T> &v)
{
vector<int> vec(10, 0); // initialize with only 0
v.push_back(1); // add at to the end of the list
v.insert(v.begin(), 7); // add at to the beginning of the list
v.insert(v.begin() + 2, 74); // add to 2 position
v.at(2) = 177; // edit element at position 2
auto my_val = v.at(2); // get the value at position 2
v.pop_back(); // remove the last element
v.erase(v.begin()); // remove the first element
v.erase(v.begin() + 2); // remove element at 2 position
std::sort(v.begin(), v.end()); // sort the vector
std::reverse(v.begin(), v.end()); // reverse the vector
std::rotate(v.rbegin(), v.rbegin() + 2, v.rend()); // rotate array by 4 positions
sort( v.begin(), v.end() ); // in order to remove duplicates we have to sort vector first
v.erase( unique( v.begin(), v.end() ), v.end() );
set<int> s( v.begin(), v.end() ); // remove duplicates to create a ordered set
v.assign( s.begin(), s.end() ); // and assign it to vector
vector<int> n(102); // fill vector with values from 0 to 101
std::iota(n.begin(), n.end(), 0);
std::iter_swap(v.begin() + 1, v.begin() + 2); // swap values from elementes at index 1 and 2
std::swap(v[0],v[1]); // swap values from elementes at index 0 and 1
shuffle_vector(&v); // shuffle a vector
auto min_value = *std::min_element(v.begin(), v.end()); // capture min value
std::cout << "minimal value: " << min_value << std::endl; // cout min value
auto max_value = *std::max_element(v.begin(), v.end()); // capture max value
std::cout << "max value: " << max_value << std::endl; // cout max value
auto sum_of_elems = std::accumulate(v.begin(), v.end(), 0); // sum of elements
cout << "sum_of_elems: " << sum_of_elems << endl;
auto random = random_choice(v); // capture random_choice
std::cout << "random value: " << random << std::endl; // cout random_choice
auto p = remove_if(v.begin(), v.end(), [](const int i) { return i < 0; });
v.erase(p, v.end()); // remove negative values
auto q = remove_if(v.begin(), v.end(), [](const int i) { return i > 0; });
v.erase(q, v.end()); // remove positive values
display(v); // display a vector
v.clear(); // empty a vector
return;
}
int main ()
{
srand( static_cast<unsigned int>(time(nullptr)) ); // needed for init std::rand()
vector<int> v = { 2, 2, 3, 3, 4, 4, 4, 15, 25, 45, 55, 17, 28 };
init(v);
return 0;
}
|
.global s_prepare_buffers
s_prepare_buffers:
push %r10
push %r14
push %r15
push %r8
push %rcx
push %rdi
push %rdx
push %rsi
lea addresses_normal_ht+0x1245c, %r14
nop
nop
nop
and $42901, %rdx
mov (%r14), %r15d
nop
nop
nop
nop
nop
sub %rcx, %rcx
lea addresses_A_ht+0x1c2, %rsi
lea addresses_D_ht+0xdc2, %rdi
nop
nop
nop
nop
add %r10, %r10
mov $23, %rcx
rep movsb
nop
nop
cmp $31601, %rsi
lea addresses_WC_ht+0x11e12, %rsi
lea addresses_UC_ht+0x118c2, %rdi
and %r8, %r8
mov $54, %rcx
rep movsl
nop
add $13638, %r14
lea addresses_WT_ht+0x117e2, %r14
nop
nop
nop
add $50608, %r10
mov $0x6162636465666768, %rsi
movq %rsi, %xmm1
movups %xmm1, (%r14)
inc %rsi
lea addresses_normal_ht+0x1ed64, %r8
nop
nop
nop
nop
sub %r14, %r14
movw $0x6162, (%r8)
add $19566, %r15
lea addresses_normal_ht+0xa5c2, %rsi
lea addresses_WC_ht+0xf4ba, %rdi
nop
nop
nop
nop
nop
xor %r15, %r15
mov $127, %rcx
rep movsq
nop
nop
nop
and $43584, %rcx
lea addresses_normal_ht+0xc8c2, %r10
nop
nop
nop
nop
dec %rcx
movups (%r10), %xmm3
vpextrq $0, %xmm3, %r15
nop
nop
nop
nop
cmp %rsi, %rsi
lea addresses_normal_ht+0x15caa, %rsi
lea addresses_A_ht+0x412e, %rdi
nop
nop
xor $39307, %r14
mov $81, %rcx
rep movsb
nop
nop
nop
add $3107, %r14
lea addresses_normal_ht+0xe0c2, %r15
nop
nop
nop
nop
xor $54050, %rdx
vmovups (%r15), %ymm1
vextracti128 $0, %ymm1, %xmm1
vpextrq $0, %xmm1, %rdi
nop
inc %rdi
pop %rsi
pop %rdx
pop %rdi
pop %rcx
pop %r8
pop %r15
pop %r14
pop %r10
ret
.global s_faulty_load
s_faulty_load:
push %r10
push %r11
push %r14
push %r8
push %rdi
push %rsi
// Faulty Load
lea addresses_PSE+0x1d5c2, %r10
dec %r14
mov (%r10), %di
lea oracles, %r14
and $0xff, %rdi
shlq $12, %rdi
mov (%r14,%rdi,1), %rdi
pop %rsi
pop %rdi
pop %r8
pop %r14
pop %r11
pop %r10
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'same': True, 'NT': False, 'AVXalign': False, 'size': 16, 'type': 'addresses_PSE', 'congruent': 0}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'same': True, 'NT': False, 'AVXalign': True, 'size': 2, 'type': 'addresses_PSE', 'congruent': 0}}
<gen_prepare_buffer>
{'OP': 'LOAD', 'src': {'same': False, 'NT': False, 'AVXalign': False, 'size': 4, 'type': 'addresses_normal_ht', 'congruent': 1}}
{'dst': {'same': False, 'congruent': 11, 'type': 'addresses_D_ht'}, 'OP': 'REPM', 'src': {'same': False, 'congruent': 8, 'type': 'addresses_A_ht'}}
{'dst': {'same': False, 'congruent': 8, 'type': 'addresses_UC_ht'}, 'OP': 'REPM', 'src': {'same': False, 'congruent': 4, 'type': 'addresses_WC_ht'}}
{'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 16, 'type': 'addresses_WT_ht', 'congruent': 5}, 'OP': 'STOR'}
{'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 2, 'type': 'addresses_normal_ht', 'congruent': 1}, 'OP': 'STOR'}
{'dst': {'same': False, 'congruent': 3, 'type': 'addresses_WC_ht'}, 'OP': 'REPM', 'src': {'same': False, 'congruent': 10, 'type': 'addresses_normal_ht'}}
{'OP': 'LOAD', 'src': {'same': False, 'NT': False, 'AVXalign': False, 'size': 16, 'type': 'addresses_normal_ht', 'congruent': 3}}
{'dst': {'same': False, 'congruent': 0, 'type': 'addresses_A_ht'}, 'OP': 'REPM', 'src': {'same': False, 'congruent': 3, 'type': 'addresses_normal_ht'}}
{'OP': 'LOAD', 'src': {'same': True, 'NT': False, 'AVXalign': False, 'size': 32, 'type': 'addresses_normal_ht', 'congruent': 6}}
{'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
*/
|
.global s_prepare_buffers
s_prepare_buffers:
push %r12
push %r14
push %r15
push %r9
push %rbx
push %rcx
push %rdi
push %rsi
lea addresses_WC_ht+0xf0e, %r9
nop
nop
nop
sub $708, %r15
movb $0x61, (%r9)
nop
cmp $16941, %rsi
lea addresses_WC_ht+0xa20e, %rsi
lea addresses_A_ht+0x1ab0e, %rdi
sub %rbx, %rbx
mov $55, %rcx
rep movsq
nop
nop
nop
nop
nop
xor $51341, %rdi
lea addresses_UC_ht+0x888e, %r15
nop
nop
nop
nop
inc %rdi
mov $0x6162636465666768, %rcx
movq %rcx, (%r15)
nop
nop
nop
inc %rcx
lea addresses_normal_ht+0x1a9c7, %rsi
lea addresses_UC_ht+0xb30e, %rdi
nop
nop
nop
nop
and $62267, %r14
mov $76, %rcx
rep movsq
nop
nop
nop
nop
sub %rbx, %rbx
pop %rsi
pop %rdi
pop %rcx
pop %rbx
pop %r9
pop %r15
pop %r14
pop %r12
ret
.global s_faulty_load
s_faulty_load:
push %r12
push %r14
push %r15
push %r8
push %rbp
push %rbx
push %rdx
// Load
lea addresses_RW+0x190e, %r12
clflush (%r12)
nop
nop
nop
add %r8, %r8
mov (%r12), %r15d
nop
nop
nop
nop
nop
sub %rbp, %rbp
// Store
lea addresses_WC+0x530e, %r12
nop
nop
nop
xor %r14, %r14
movw $0x5152, (%r12)
nop
add $56710, %rbp
// Faulty Load
lea addresses_WC+0x530e, %rbx
nop
sub %r12, %r12
movb (%rbx), %r15b
lea oracles, %r8
and $0xff, %r15
shlq $12, %r15
mov (%r8,%r15,1), %r15
pop %rdx
pop %rbx
pop %rbp
pop %r8
pop %r15
pop %r14
pop %r12
ret
/*
<gen_faulty_load>
[REF]
{'src': {'NT': False, 'same': False, 'congruent': 0, 'type': 'addresses_WC', 'AVXalign': False, 'size': 16}, 'OP': 'LOAD'}
{'src': {'NT': False, 'same': False, 'congruent': 9, 'type': 'addresses_RW', 'AVXalign': False, 'size': 4}, 'OP': 'LOAD'}
{'OP': 'STOR', 'dst': {'NT': False, 'same': True, 'congruent': 0, 'type': 'addresses_WC', 'AVXalign': False, 'size': 2}}
[Faulty Load]
{'src': {'NT': False, 'same': True, 'congruent': 0, 'type': 'addresses_WC', 'AVXalign': False, 'size': 1}, 'OP': 'LOAD'}
<gen_prepare_buffer>
{'OP': 'STOR', 'dst': {'NT': False, 'same': False, 'congruent': 10, 'type': 'addresses_WC_ht', 'AVXalign': False, 'size': 1}}
{'src': {'same': False, 'congruent': 8, 'type': 'addresses_WC_ht'}, 'OP': 'REPM', 'dst': {'same': False, 'congruent': 9, 'type': 'addresses_A_ht'}}
{'OP': 'STOR', 'dst': {'NT': True, 'same': False, 'congruent': 6, 'type': 'addresses_UC_ht', 'AVXalign': False, 'size': 8}}
{'src': {'same': False, 'congruent': 0, 'type': 'addresses_normal_ht'}, 'OP': 'REPM', 'dst': {'same': False, 'congruent': 7, 'type': 'addresses_UC_ht'}}
{'52': 21829}
52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52
*/
|
#pragma once
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <Eigen/Dense>
#define GLM_FORCE_RADIANS
#define GLM_FORCE_DEPTH_ZERO_TO_ONE
#include <glm/vec4.hpp>
#include <glm/mat4x4.hpp>
#include "imgui.h"
#include "imgui_impl_glfw.h"
#include "imgui_impl_opengl3.h"
#include <iostream>
#include <string>
#include <vector>
#include <optional>
#include <set>
#include <cstdint>
#include <algorithm>
#include <cstring>
#include <cstdint>
#include "openwarp.hpp"
#include "util/obj.hpp"
#include "testrun.hpp"
class Openwarp::OpenwarpApplication{
const uint32_t WIDTH = 1024;
const uint32_t HEIGHT = 1024;
public:
OpenwarpApplication(size_t meshSize = 1024);
~OpenwarpApplication();
void Run(bool showGUI);
void DoFullTestRun(const TestRun& testRun);
void RunTest(const TestRun& testRun, std::string runDir, bool isGroundTruth, bool testUsesRay);
static OpenwarpApplication* instance;
private:
// Application metadata
ImGuiIO imgui_io;
double xpos_onfocus = 0,
ypos_onfocus = 0,
xpos_unfocus = 0,
ypos_unfocus = 0;
bool showMeshConfig = true;
bool showRayConfig = true;
bool useVsync = false;
// Application resources
ObjScene demoscene;
Eigen::Matrix4f projection;
Eigen::Vector3f position = Eigen::Vector3f(0,0,0);
Eigen::Quaternionf orientation = Eigen::Quaternionf::Identity();
Eigen::Matrix4f renderedView;
Eigen::Matrix4f renderedCameraMatrix;
double nextRenderTime = 0.0f;
double renderFPS = 15.0f;
double renderInterval = (1/renderFPS);
size_t meshWidth = 1024;
size_t meshHeight = 1024;
// Hand-tuned parameters
float bleedRadius = 0.005f;
float bleedTolerance = 0.0001f;
// Hand-tuned parameters
float rayPower = 0.5f;
float rayStepSize = 0.242f;
float rayDepthOffset = 0.379f;
float occlusionThreshold = 0.02f;
float occlusionOffset = 0.388f;
bool showDebugGrid = false;
bool shouldRenderScene = true;
bool shouldReproject = true;
bool useRay = false;
double lastSwapTime;
double presentationFramerate;
// GLFW resources
GLFWwindow* window;
// Need to init so that we don't
// get uninitialized errors
double lastInputTime = glfwGetTime();
// OpenGL resources
// Demo render resources
GLuint renderTexture;
GLuint depthTexture;
GLuint renderFBO;
GLuint renderDepthTarget;
GLint demoShaderProgram;
GLuint demoVAO;
// Demo shader attributes
GLuint demoVertexPosAttr;
GLuint demoModelViewAttr;
GLuint demoProjectionAttr;
typedef struct owMeshProgram {
// Reprojection resources
// Reprojection mesh CPU buffers and GPU VBO handles
std::vector<vertex_t> mesh_vertices;
GLuint mesh_vertices_vbo;
std::vector<GLuint> mesh_indices;
GLuint mesh_indices_vbo;
// Color- and depth-samplers for openwarp
GLint eye_sampler;
GLint depth_sampler;
// Mesh edge bleed parameters
GLint u_bleedRadius;
GLint u_bleedTolerance;
// Controls opacity of debug grid overlay
GLint u_debugOpacity;
GLuint u_renderInverseP;
GLuint u_renderInverseV;
// VP matrix of the fresh pose
GLuint u_warp_vp;
GLint program;
GLuint vao;
} owMeshProgram;
owMeshProgram meshProgram;
typedef struct owRayProgram {
// Reprojection resources
// Reprojection mesh CPU buffers and GPU VBO handles
std::vector<vertex_t> mesh_vertices;
GLuint mesh_vertices_vbo;
std::vector<GLuint> mesh_indices;
GLuint mesh_indices_vbo;
// Color- and depth-samplers for openwarp
GLint eye_sampler;
GLint depth_sampler;
GLuint u_renderPV;
GLuint u_warpInverseVP;
GLuint u_warpPos;
GLuint u_power;
GLuint u_stepSize;
GLuint u_depthOffset;
GLuint u_occlusionThreshold;
GLuint u_occlusionOffset;
GLint program;
GLuint vao;
} owRayProgram;
owRayProgram rayProgram;
int initGL();
int cleanupGL();
void drawGUI();
void processInput();
void renderScene();
void doReprojection(bool useRay);
static void scrollCallback(GLFWwindow* window, double xoffset, double yoffset) {
OpenwarpApplication::instance->renderFPS += yoffset;
OpenwarpApplication::instance->renderFPS = abs(OpenwarpApplication::instance->renderFPS);
OpenwarpApplication::instance->renderInterval = 1.0f/OpenwarpApplication::instance->renderFPS;
}
static void mouseClickCallback(GLFWwindow* window, int button, int action, int mods) {
if(OpenwarpApplication::instance != NULL &&
OpenwarpApplication::instance->imgui_io.WantCaptureMouse) {
return;
}
if (button == GLFW_MOUSE_BUTTON_LEFT && action == GLFW_PRESS) {
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
if(OpenwarpApplication::instance != NULL) {
glfwGetCursorPos(window, &OpenwarpApplication::instance->xpos_onfocus, &OpenwarpApplication::instance->ypos_onfocus);
}
}
}
static void keyCallback(GLFWwindow* window, int key, int scancode, int action, int mods) {
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) {
if(OpenwarpApplication::instance != NULL) {
// Do some math so that the view doesn't jump
// when you re-focus the window.
double xpos,ypos;
auto instance = OpenwarpApplication::instance;
glfwGetCursorPos(window, &xpos, &ypos);
instance->xpos_unfocus = (xpos - instance->xpos_onfocus) + instance->xpos_unfocus;
instance->ypos_unfocus = (ypos - instance->ypos_onfocus) + instance->ypos_unfocus;
}
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
}
if (key == GLFW_KEY_F && action == GLFW_PRESS) {
if(OpenwarpApplication::instance != NULL &&
!OpenwarpApplication::instance->imgui_io.WantCaptureMouse) {
OpenwarpApplication::instance->shouldRenderScene = !OpenwarpApplication::instance->shouldRenderScene;
}
}
if (key == GLFW_KEY_R && action == GLFW_PRESS) {
if(OpenwarpApplication::instance != NULL &&
!OpenwarpApplication::instance->imgui_io.WantCaptureMouse) {
OpenwarpApplication::instance->shouldReproject = !OpenwarpApplication::instance->shouldReproject;
}
}
if (key == GLFW_KEY_T && action == GLFW_PRESS) {
if(OpenwarpApplication::instance != NULL &&
!OpenwarpApplication::instance->imgui_io.WantCaptureMouse) {
OpenwarpApplication::instance->useRay = !OpenwarpApplication::instance->useRay;
}
}
}
Eigen::Matrix4f createCameraMatrix(Eigen::Vector3f position, Eigen::Quaternionf orientation){
Eigen::Matrix4f cameraMatrix = Eigen::Matrix4f::Identity();
cameraMatrix.block<3,1>(0,3) = position;
cameraMatrix.block<3,3>(0,0) = orientation.toRotationMatrix();
return cameraMatrix;
}
int createRenderTexture(GLuint* texture_handle, GLuint width, GLuint height, bool isDepth){
// Create the texture handle.
glGenTextures(1, texture_handle);
glBindTexture(GL_TEXTURE_2D, *texture_handle);
// We use GL_NEAREST for depth textures for performance reasons.
// Linear filtering on depth textures is (apparently) costly.
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, isDepth ? GL_NEAREST : GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
if(isDepth) {
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32, width, height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, 0);
}
else {
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, 0);
}
glBindTexture(GL_TEXTURE_2D, 0); // unbind texture
if(glGetError()){
return 0;
} else {
return 1;
}
}
void createFBO(GLuint* texture_handle, GLuint* fbo, GLuint* depth_texture_handle, GLuint* depth_target, GLuint width, GLuint height){
// Create a framebuffer to draw some things to the eye texture
glGenFramebuffers(1, fbo);
// Bind the FBO as the active framebuffer.
glBindFramebuffer(GL_FRAMEBUFFER, *fbo);
glGenRenderbuffers(1, depth_target);
glBindRenderbuffer(GL_RENDERBUFFER, *depth_target);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, width, height);
glBindRenderbuffer(GL_RENDERBUFFER, 0);
// Attach color texture to color attachment.
glBindTexture(GL_TEXTURE_2D, *texture_handle);
glFramebufferTexture(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, *texture_handle, 0);
glBindTexture(GL_TEXTURE_2D, 0);
// Attach depth texture to depth attachment.
glBindTexture(GL_TEXTURE_2D, *depth_texture_handle);
glFramebufferTexture(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, *depth_texture_handle, 0);
glBindTexture(GL_TEXTURE_2D, 0);
if(glGetError()){
abort();
}
// Unbind FBO.
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
// Build a rectangular plane.
void BuildMesh(size_t width, size_t height, std::vector<GLuint>& indices, std::vector<vertex_t>& vertices){
std::cout << "Generating reprojection mesh, size (" << width << ", " << height << ")" << std::endl;
// Compute the size of the vectors we'll need to store the
// data, ahead of time.
// width and height are not in # of verts, but in # of faces.
size_t num_indices = 2 * 3 * width * height;
size_t num_vertices = (width + 1)*(height + 1);
// Size the vectors accordingly
indices.resize(num_indices);
vertices.resize(num_vertices);
// Build indices.
for ( size_t y = 0; y < height; y++ ) {
for ( size_t x = 0; x < width; x++ ) {
const int offset = ( y * width + x ) * 6;
indices[offset + 0] = (GLuint)( ( y + 0 ) * ( width + 1 ) + ( x + 0 ) );
indices[offset + 1] = (GLuint)( ( y + 1 ) * ( width + 1 ) + ( x + 0 ) );
indices[offset + 2] = (GLuint)( ( y + 0 ) * ( width + 1 ) + ( x + 1 ) );
indices[offset + 3] = (GLuint)( ( y + 0 ) * ( width + 1 ) + ( x + 1 ) );
indices[offset + 4] = (GLuint)( ( y + 1 ) * ( width + 1 ) + ( x + 0 ) );
indices[offset + 5] = (GLuint)( ( y + 1 ) * ( width + 1 ) + ( x + 1 ) );
}
}
// Build vertices
for (size_t y = 0; y < height + 1; y++){
for (size_t x = 0; x < width + 1; x++){
size_t index = y * ( width + 1 ) + x;
vertices[index].uv[0] = ((float)x / width);
vertices[index].uv[1] = ((( height - (float)y) / height));
if(x == 0) {
vertices[index].uv[0] = -0.5f;
}
if(x == width) {
vertices[index].uv[0] = 1.5f;
}
if(y == 0) {
vertices[index].uv[1] = 1.5f;
}
if(y == height) {
vertices[index].uv[1] = -0.5f;
}
}
}
}
// Perspective matrix construction borrowed from
// http://spointeau.blogspot.com/2013/12/hello-i-am-looking-at-opengl-3.html
// I would use GLM, but I'd like to use Eigen for the rest of my computations.
Eigen::Matrix4f perspective
(
float fovy,
float aspect,
float zNear,
float zFar
)
{
assert(aspect > 0);
assert(zFar > zNear);
float radf = fovy * (M_PI / 180.0);
float tanHalfFovy = tan(radf / 2.0);
Eigen::Matrix4f res = Eigen::Matrix4f::Zero();
res(0,0) = 1.0 / (aspect * tanHalfFovy);
res(1,1) = 1.0 / (tanHalfFovy);
res(2,2) = - (zFar + zNear) / (zFar - zNear);
res(3,2) = - 1.0;
res(2,3) = - (2.0 * zFar * zNear) / (zFar - zNear);
return res;
}
}; |
TITLE_CURSOR_X_OFFSET = 42
TITLE_CURSOR_Y_OFFSET = 102
load_menu:
; Reset scrolling to 0
lda #0
sta scrollX
sta scrollY
; Make sure we're not writing every 32nd byte rather than every single one, and force back to nametable 0
lda ppuCtrlBuffer
and #%11111000
sta ppuCtrlBuffer
jsr vblank_wait
lda ppuMaskBuffer
and #%11110111
sta ppuMaskBuffer ; Stop rendering sprites
; Hide all sprites
ldx #0
lda #SPRITE_OFFSCREEN
@sprite_loop:
sta SPRITE_DATA, x
.repeat 4
inx
.endrepeat
cpx #0
bne @sprite_loop
jsr disable_all
jsr vblank_wait
ldy #0
set_ppu_addr $3f00
@palette_loop:
lda menu_palettes, y
sta PPU_DATA
iny
cpy #$20
bne @palette_loop
bank #BANK_CHR
set_ppu_addr $0000
store #<(menu_chr_data), tempAddr
store #>(menu_chr_data), tempAddr+1
jsr PKB_unpackblk
store #<(default_sprite_chr), tempAddr
store #>(default_sprite_chr), tempAddr+1
jsr PKB_unpackblk
bank #BANK_SPRITES_AND_LEVEL
; wipe out the nametable so we don't have any leftovers.
set_ppu_addr $2000
ldx #0
ldy #0
lda #0
@nametable_loop:
sta PPU_DATA
iny
cpy #$c0
bne @nametable_loop
inx
inc tempAddr+1
cpx #4
bne @nametable_loop
ldy #0
;set_ppu_addr $23c0
lda #0
@clear_attributes:
sta PPU_DATA
iny
cpy #$40
bne @clear_attributes
reset_ppu_scrolling_and_ctrl
rts
load_title:
jsr load_menu
lda #SONG_TITLE
jsr music_play
store #0, titleNoWarpVal
set_ppu_addr $2000
store #<(title_screen_base), tempAddr
store #>(title_screen_base), tempAddr+1
jsr PKB_unpackblk
.if SHOW_VERSION_STRING = 1
write_string .sprintf("Version %04s Build %05d", VERSION, BUILD), $2321
write_string .sprintf("Built on: %24s", BUILD_DATE), $2341
write_string SPLASH_MESSAGE, $2381, $1e
.else
write_string COPYRIGHT, $2361, $1e
.endif
.if DEBUGGING = 1
write_string .sprintf("Debug enabled"), $2301
.endif
lda GAME_BEATEN_BYTE
cmp #0
bne @gems
jmp load_title_no_gems
@gems:
; Show gem count and level select if you've beaten the game once.
write_string .sprintf("Gems: "), $20e8
jsr get_game_gem_count
draw_current_digit
lda temp1
draw_current_num
lda #CHAR_SPACE
sta PPU_DATA
lda #NUM_SYM_TABLE_START+$b
sta PPU_DATA
lda #CHAR_SPACE
sta PPU_DATA
jsr get_game_gem_total
draw_current_digit
lda tempc
draw_current_num
; Quick and dirty in-place macro to draw gem count based on the level.
.macro draw_gem_count I, baseCount
.local BINARY_COUNT, BINARY_TOTAL
BINARY_TOTAL = ((I .mod 10) + (I / 10) * 16)
lda baseCount
draw_current_num
lda #CHAR_SPACE
sta PPU_DATA
lda #NUM_SYM_TABLE_START+$b
sta PPU_DATA
lda #CHAR_SPACE
sta PPU_DATA
lda #BINARY_TOTAL
draw_current_num
.endmacro
; NOTE: We're depending on the return value of get_level_gem_count being in temp1 here.
.repeat NUMBER_OF_REGULAR_LEVELS, I
.if I = 0 && DEBUGGING = 1
; Debugging level gets a special case, since we want level numbers to match with/without debugging.
write_string .sprintf("Level DD "), $21a7+I*$20
lda #I
jsr get_level_gem_count
draw_gem_count LVL_DEBUG_COLLECTIBLE_COUNT, temp1
.elseif DEBUGGING = 1
; Unfortunately since we added a special debugging level, we need separate logic for showing level numbers based on that.
write_string .sprintf("Level %02d ", I), $21a7+I*$20
lda #I
jsr get_level_gem_count
draw_gem_count (.ident(.concat("LVL",.string(I),"_COLLECTIBLE_COUNT"))), temp1
.else
write_string .sprintf("Level %02d ", I+1), $21a7+I*$20
lda #I
jsr get_level_gem_count
draw_gem_count (.ident(.concat("LVL",.string(I+1),"_COLLECTIBLE_COUNT"))), temp1
.endif
.if ACTION53
jsr MAIN_draw_menu_extras
.endif
.endrepeat
jmp after_no_gems
load_title_no_gems:
.if ACTION53
jsr MAIN_draw_a53_no_levelsel
.else
jsr MAIN_draw_no_levelsel
.endif
after_no_gems:
reset_ppu_scrolling_and_ctrl
jsr vblank_wait
jsr enable_all
rts
show_title:
jsr load_menu
bank #BANK_INTRO
jsr show_intro
bank #BANK_SPRITES_AND_LEVEL
jsr load_title
lda #0
sta temp5 ; Cursor offset if you have level select enabled.
@loopa:
jsr sound_update
jsr read_controller
jsr vblank_wait
; Check for start button...
; Make sure we don't count keypresses from last cycle.
lda lastCtrlButtons
eor #$ff ; flip the bits.
and ctrlButtons
and #CONTROLLER_START+CONTROLLER_A
beq @dododo
jmp @game_time
@dododo:
lda GAME_BEATEN_BYTE
cmp #0
beq @no_level_select
lda ctrlButtons
and #CONTROLLER_UP
beq @no_up
lda lastCtrlButtons
and #CONTROLLER_UP
bne @no_up
lda temp5
.if ACTION53
cmp #(NUMBER_OF_REGULAR_LEVELS+1)
bne @no_special
dec temp5 ; Second dec for action53
@no_special:
.endif
cmp #0
beq @no_up
dec temp5
lda #SFX_MENU
ldx #FT_SFX_CH0
jsr sfx_play
@no_up:
lda ctrlButtons
and #CONTROLLER_DOWN
beq @no_down
lda lastCtrlButtons
and #CONTROLLER_DOWN
bne @no_down
lda temp5
.if ACTION53
cmp #NUMBER_OF_REGULAR_LEVELS-1
beq @exitopt
bcs @no_down
jmp @after_exitopt
@exitopt:
inc temp5 ; Extra add for action53 jump
@after_exitopt:
.else
cmp #NUMBER_OF_REGULAR_LEVELS-1
bcs @no_down
.endif
inc temp5
lda #SFX_MENU
ldx #FT_SFX_CH0
jsr sfx_play
@no_down:
lda #SPRITE_POINTER
sta VAR_SPRITE_DATA+1
lda temp5
asl
asl
asl ; multiply offset by 8
adc #TITLE_CURSOR_Y_OFFSET
sta VAR_SPRITE_DATA
lda #TITLE_CURSOR_X_OFFSET
sta VAR_SPRITE_DATA+3
lda #0
sta VAR_SPRITE_DATA+2
jmp @after_level_select
@no_level_select:
.if ACTION53
lda ctrlButtons
and #CONTROLLER_UP
beq @no_upb
lda lastCtrlButtons
and #CONTROLLER_UP
bne @no_upb
lda titleNoWarpVal
cmp #0
beq @no_upb
store #0, titleNoWarpVal
lda #SFX_MENU
ldx #FT_SFX_CH0
jsr sfx_play
@no_upb:
lda ctrlButtons
and #CONTROLLER_DOWN
beq @no_downb
lda lastCtrlButtons
and #CONTROLLER_DOWN
bne @no_downb
lda titleNoWarpVal
cmp #1
beq @no_downb
store #1, titleNoWarpVal
lda #SFX_MENU
ldx #FT_SFX_CH0
jsr sfx_play
@no_downb:
lda #SPRITE_POINTER
sta VAR_SPRITE_DATA+1
lda titleNoWarpVal
asl
asl
asl ; multiply offset by 8
asl
adc #TITLE_CURSOR_Y_OFFSET+8
sta VAR_SPRITE_DATA
lda #TITLE_CURSOR_X_OFFSET+24
sta VAR_SPRITE_DATA+3
lda #0
sta VAR_SPRITE_DATA+2
.endif
@after_level_select:
jmp @loopa
@game_time:
.if ACTION53
lda titleNoWarpVal
cmp #1
bne @no_exit
jmp reset_to_action53
@no_exit:
.endif
lda temp5
.if ACTION53
cmp #NUMBER_OF_REGULAR_LEVELS+1
bne @doit
; If you selected to go back to a53, we'll send ya...
jmp reset_to_action53
@doit:
.endif
sta currentLevel
lda #SFX_MENU
ldx #FT_SFX_CH0
jsr sfx_play
jmp show_ready
.if ACTION53 = 1
reset_to_action53:
; NOTE: Code borrowed/ripped-off from exitpatch.py in the A53 menu tools.
sei
ldx #11
@loop:
lda @cpsrc,x
sta $F0,x
dex
bpl @loop
; X = $FF at end
ldy #$80
sty $5000
lda #$00
iny
jmp $00F0
@cpsrc:
sta $8000
sty $5000
stx $8000
jmp ($FFFC)
.endif
load_ready:
jsr load_menu
write_string "Ready!", $218b
reset_ppu_scrolling_and_ctrl
jsr vblank_wait
jsr enable_all
rts
show_ready:
lda #1
jsr music_pause
jsr load_ready
lda #0
sta scrollX
sta scrollY
ldx #0
@loopa:
txa
pha
; Not really doing anything... just makes it look less like we're locked for frames. Could easily be ditched.
jsr read_controller
jsr sound_update
reset_ppu_scrolling_and_ctrl
jsr vblank_wait
reset_ppu_scrolling_and_ctrl
pla
tax
inx
cpx #READY_TIME
bne @loopa
game_time:
jmp show_level
game_end:
; Clear out buttons in case you already hit start for some screwy reason.
lda #0
sta ctrlButtons
sta lastCtrlButtons
sta scrollX
sta scrollY
jsr load_menu
bank #BANK_INTRO
lda currentLevel
cmp #LEVEL_9_ID+1
bne @bad_ending
jmp show_good_ending
@bad_ending:
jmp show_bad_ending
title_screen_base:
.incbin "graphics/processed/title_screen.nam.pkb" |
_KogaBeforeBattleText::
text "KOGA: Fwahahaha!"
para "A mere child like"
line "you dares to"
cont "challenge me?"
para "Very well, I"
line "shall show you"
cont "true terror as a"
cont "ninja master!"
para "You shall feel"
line "the despair of"
cont "poison and sleep"
cont "techniques!"
done
_KogaAfterBattleText::
text "Humph!"
line "You have proven"
cont "your worth!"
para "Here! Take the"
line "MARSHBADGE!"
prompt
|
.global s_prepare_buffers
s_prepare_buffers:
push %r11
push %r13
push %r9
push %rax
push %rbx
push %rcx
push %rdi
push %rsi
lea addresses_D_ht+0xf8c1, %r11
nop
nop
nop
nop
add $57465, %rdi
mov (%r11), %r9
nop
nop
nop
cmp $61776, %r9
lea addresses_UC_ht+0x11ac1, %rax
nop
nop
nop
nop
and %rsi, %rsi
movl $0x61626364, (%rax)
nop
nop
nop
nop
dec %r13
lea addresses_A_ht+0x69c1, %rdi
nop
nop
nop
nop
dec %rbx
mov $0x6162636465666768, %rsi
movq %rsi, %xmm0
vmovups %ymm0, (%rdi)
nop
nop
nop
nop
cmp $47604, %r13
lea addresses_A_ht+0xb781, %rax
inc %r11
movb $0x61, (%rax)
nop
nop
nop
nop
nop
cmp %rax, %rax
lea addresses_WT_ht+0xfcf1, %rsi
lea addresses_normal_ht+0x1bcc1, %rdi
nop
nop
nop
inc %rbx
mov $36, %rcx
rep movsq
xor %r13, %r13
lea addresses_A_ht+0xccc1, %rcx
clflush (%rcx)
nop
nop
nop
nop
nop
inc %rsi
mov $0x6162636465666768, %rdi
movq %rdi, %xmm5
movups %xmm5, (%rcx)
nop
nop
sub %rsi, %rsi
lea addresses_A_ht+0x1aac1, %rsi
lea addresses_WT_ht+0x92c1, %rdi
and $39273, %r13
mov $49, %rcx
rep movsl
nop
add $20883, %rdi
lea addresses_WC_ht+0x96c1, %rsi
lea addresses_A_ht+0x10741, %rdi
nop
nop
nop
nop
nop
cmp %r9, %r9
mov $111, %rcx
rep movsb
nop
nop
nop
nop
sub %rax, %rax
lea addresses_A_ht+0xa1c1, %rdi
nop
and $57429, %rcx
movups (%rdi), %xmm4
vpextrq $1, %xmm4, %r13
nop
nop
nop
nop
nop
xor $23687, %rbx
lea addresses_A_ht+0x15cc1, %rsi
lea addresses_D_ht+0x4341, %rdi
nop
nop
and %r11, %r11
mov $73, %rcx
rep movsl
nop
nop
nop
xor %rbx, %rbx
lea addresses_UC_ht+0x118c1, %r9
nop
dec %rdi
movw $0x6162, (%r9)
nop
inc %rax
pop %rsi
pop %rdi
pop %rcx
pop %rbx
pop %rax
pop %r9
pop %r13
pop %r11
ret
.global s_faulty_load
s_faulty_load:
push %r12
push %r13
push %r15
push %rax
push %rbx
push %rdx
// Faulty Load
lea addresses_WC+0x18cc1, %rdx
nop
add $47109, %r15
mov (%rdx), %r13w
lea oracles, %r15
and $0xff, %r13
shlq $12, %r13
mov (%r15,%r13,1), %r13
pop %rdx
pop %rbx
pop %rax
pop %r15
pop %r13
pop %r12
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'size': 8, 'NT': False, 'type': 'addresses_WC', 'same': True, 'AVXalign': True, 'congruent': 0}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'size': 2, 'NT': False, 'type': 'addresses_WC', 'same': True, 'AVXalign': False, 'congruent': 0}}
<gen_prepare_buffer>
{'OP': 'LOAD', 'src': {'size': 8, 'NT': False, 'type': 'addresses_D_ht', 'same': False, 'AVXalign': False, 'congruent': 10}}
{'OP': 'STOR', 'dst': {'size': 4, 'NT': False, 'type': 'addresses_UC_ht', 'same': False, 'AVXalign': False, 'congruent': 8}}
{'OP': 'STOR', 'dst': {'size': 32, 'NT': False, 'type': 'addresses_A_ht', 'same': False, 'AVXalign': False, 'congruent': 3}}
{'OP': 'STOR', 'dst': {'size': 1, 'NT': False, 'type': 'addresses_A_ht', 'same': False, 'AVXalign': False, 'congruent': 6}}
{'OP': 'REPM', 'src': {'same': False, 'type': 'addresses_WT_ht', 'congruent': 3}, 'dst': {'same': False, 'type': 'addresses_normal_ht', 'congruent': 10}}
{'OP': 'STOR', 'dst': {'size': 16, 'NT': False, 'type': 'addresses_A_ht', 'same': False, 'AVXalign': False, 'congruent': 9}}
{'OP': 'REPM', 'src': {'same': False, 'type': 'addresses_A_ht', 'congruent': 9}, 'dst': {'same': False, 'type': 'addresses_WT_ht', 'congruent': 8}}
{'OP': 'REPM', 'src': {'same': False, 'type': 'addresses_WC_ht', 'congruent': 7}, 'dst': {'same': False, 'type': 'addresses_A_ht', 'congruent': 7}}
{'OP': 'LOAD', 'src': {'size': 16, 'NT': False, 'type': 'addresses_A_ht', 'same': False, 'AVXalign': False, 'congruent': 8}}
{'OP': 'REPM', 'src': {'same': False, 'type': 'addresses_A_ht', 'congruent': 10}, 'dst': {'same': False, 'type': 'addresses_D_ht', 'congruent': 7}}
{'OP': 'STOR', 'dst': {'size': 2, 'NT': False, 'type': 'addresses_UC_ht', 'same': False, 'AVXalign': False, 'congruent': 8}}
{'00': 21829}
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
*/
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.