text stringlengths 1 1.05M |
|---|
; A262019: The first of eleven consecutive positive integers the sum of the squares of which is equal to the sum of the squares of five consecutive positive integers.
; Submitted by Christian Krause
; 15,3575,637215,113421575,20188404015,3593422493975,639609015524415,113846811340852775,20264092809656270415,3606894673307475281975,642006987755920943922015,114273636925880620542837575,20340065365818994535681167215,3620417361478855146730704927575,644413950277870397123529795942015,114702062732099451832841572972751975,20416322752363424555848676459353910415,3633990747857957471489231568192023302775,646829936795964066500527370461720793984415,115132094758933745879622382710618109305923975
mov $3,1
lpb $0
sub $0,$3
add $2,2
add $4,1
mov $1,$4
mul $1,176
add $2,$1
add $4,$2
lpe
mov $0,$2
mul $0,20
add $0,15
|
; void z80_set_int_state(uint8_t state)
SECTION code_clib
SECTION code_z80
PUBLIC _z80_set_int_state
EXTERN asm_z80_set_int_state
_z80_set_int_state:
pop af
pop hl
push hl
push af
jp asm_z80_set_int_state
|
; A131479: a(n) = floor(n^4/4).
; 0,0,4,20,64,156,324,600,1024,1640,2500,3660,5184,7140,9604,12656,16384,20880,26244,32580,40000,48620,58564,69960,82944,97656,114244,132860,153664,176820,202500,230880,262144,296480,334084,375156,419904,468540,521284,578360,640000,706440,777924,854700,937024,1025156,1119364,1219920,1327104,1441200,1562500,1691300,1827904,1972620,2125764,2287656,2458624,2639000,2829124,3029340,3240000,3461460,3694084,3938240,4194304,4462656,4743684,5037780,5345344,5666780,6002500,6352920,6718464,7099560,7496644,7910156,8340544,8788260,9253764,9737520,10240000,10761680,11303044,11864580,12446784,13050156,13675204,14322440,14992384,15685560,16402500,17143740,17909824,18701300,19518724,20362656,21233664,22132320,23059204,24014900,25000000,26015100,27060804,28137720,29246464,30387656,31561924,32769900,34012224,35289540,36602500,37951760,39337984,40761840,42224004,43725156,45265984,46847180,48469444,50133480,51840000,53589720,55383364,57221660,59105344,61035156,63011844,65036160,67108864,69230720,71402500,73624980,75898944,78225180,80604484,83037656,85525504,88068840,90668484,93325260,96040000,98813540,101646724,104540400,107495424,110512656,113592964,116737220,119946304,123221100,126562500,129971400,133448704,136995320,140612164,144300156,148060224,151893300,155800324,159782240,163840000,167974560,172186884,176477940,180848704,185300156,189833284,194449080,199148544,203932680,208802500,213759020,218803264,223936260,229159044,234472656,239878144,245376560,250968964,256656420,262440000,268320780,274299844,280378280,286557184,292837656,299220804,305707740,312299584,318997460,325802500,332715840,339738624,346872000,354117124,361475156,368947264,376534620,384238404,392059800,400000000,408060200,416241604,424545420,432972864,441525156,450203524,459009200,467943424,477007440,486202500,495529860,504990784,514586540,524318404,534187656,544195584,554343480,564632644,575064380,585640000,596360820,607228164,618243360,629407744,640722656,652189444,663809460,675584064,687514620,699602500,711849080,724255744,736823880,749554884,762450156,775511104,788739140,802135684,815702160,829440000,843350640,857435524,871696100,886133824,900750156,915546564,930524520,945685504,961031000
pow $0,4
div $0,4
mov $1,$0
|
/* ----------------------------------------------------------------------
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
http://lammps.sandia.gov, Sandia National Laboratories
Steve Plimpton, sjplimp@sandia.gov
This software is distributed under the GNU General Public License.
See the README file in the top-level LAMMPS directory.
------------------------------------------------------------------------- */
/* ----------------------------------------------------------------------
Contributing author: Axel Kohlmeyer (Temple U)
------------------------------------------------------------------------- */
#include <math.h>
#include "pair_lj_class2_omp.h"
#include "atom.h"
#include "comm.h"
#include "force.h"
#include "neighbor.h"
#include "neigh_list.h"
#include "suffix.h"
using namespace LAMMPS_NS;
/* ---------------------------------------------------------------------- */
PairLJClass2OMP::PairLJClass2OMP(LAMMPS *lmp) :
PairLJClass2(lmp), ThrOMP(lmp, THR_PAIR)
{
suffix_flag |= Suffix::OMP;
respa_enable = 0;
}
/* ---------------------------------------------------------------------- */
void PairLJClass2OMP::compute(int eflag, int vflag)
{
if (eflag || vflag) {
ev_setup(eflag,vflag);
} else evflag = vflag_fdotr = 0;
const int nall = atom->nlocal + atom->nghost;
const int nthreads = comm->nthreads;
const int inum = list->inum;
#if defined(_OPENMP)
#pragma omp parallel default(none) shared(eflag,vflag)
#endif
{
int ifrom, ito, tid;
loop_setup_thr(ifrom, ito, tid, inum, nthreads);
ThrData *thr = fix->get_thr(tid);
thr->timer(Timer::START);
ev_setup_thr(eflag, vflag, nall, eatom, vatom, thr);
if (evflag) {
if (eflag) {
if (force->newton_pair) eval<1,1,1>(ifrom, ito, thr);
else eval<1,1,0>(ifrom, ito, thr);
} else {
if (force->newton_pair) eval<1,0,1>(ifrom, ito, thr);
else eval<1,0,0>(ifrom, ito, thr);
}
} else {
if (force->newton_pair) eval<0,0,1>(ifrom, ito, thr);
else eval<0,0,0>(ifrom, ito, thr);
}
thr->timer(Timer::PAIR);
reduce_thr(this, eflag, vflag, thr);
} // end of omp parallel region
}
template <int EVFLAG, int EFLAG, int NEWTON_PAIR>
void PairLJClass2OMP::eval(int iifrom, int iito, ThrData * const thr)
{
int i,j,ii,jj,jnum,itype,jtype;
double xtmp,ytmp,ztmp,delx,dely,delz,evdwl,fpair;
double rsq,r2inv,r3inv,r6inv,forcelj,factor_lj;
int *ilist,*jlist,*numneigh,**firstneigh;
evdwl = 0.0;
const dbl3_t * _noalias const x = (dbl3_t *) atom->x[0];
dbl3_t * _noalias const f = (dbl3_t *) thr->get_f()[0];
const int * _noalias const type = atom->type;
const int nlocal = atom->nlocal;
const double * _noalias const special_lj = force->special_lj;
double fxtmp,fytmp,fztmp;
ilist = list->ilist;
numneigh = list->numneigh;
firstneigh = list->firstneigh;
// loop over neighbors of my atoms
for (ii = iifrom; ii < iito; ++ii) {
i = ilist[ii];
xtmp = x[i].x;
ytmp = x[i].y;
ztmp = x[i].z;
itype = type[i];
jlist = firstneigh[i];
jnum = numneigh[i];
fxtmp=fytmp=fztmp=0.0;
for (jj = 0; jj < jnum; jj++) {
j = jlist[jj];
factor_lj = special_lj[sbmask(j)];
j &= NEIGHMASK;
delx = xtmp - x[j].x;
dely = ytmp - x[j].y;
delz = ztmp - x[j].z;
rsq = delx*delx + dely*dely + delz*delz;
jtype = type[j];
if (rsq < cutsq[itype][jtype]) {
r2inv = 1.0/rsq;
r6inv = r2inv*r2inv*r2inv;
r3inv = sqrt(r6inv);
forcelj = r6inv * (lj1[itype][jtype]*r3inv - lj2[itype][jtype]);
fpair = factor_lj*forcelj*r2inv;
fxtmp += delx*fpair;
fytmp += dely*fpair;
fztmp += delz*fpair;
if (NEWTON_PAIR || j < nlocal) {
f[j].x -= delx*fpair;
f[j].y -= dely*fpair;
f[j].z -= delz*fpair;
}
if (EFLAG) {
evdwl = r6inv*(lj3[itype][jtype]*r3inv-lj4[itype][jtype])
- offset[itype][jtype];
evdwl *= factor_lj;
}
if (EVFLAG) ev_tally_thr(this,i,j,nlocal,NEWTON_PAIR,
evdwl,0.0,fpair,delx,dely,delz,thr);
}
}
f[i].x += fxtmp;
f[i].y += fytmp;
f[i].z += fztmp;
}
}
/* ---------------------------------------------------------------------- */
double PairLJClass2OMP::memory_usage()
{
double bytes = memory_usage_thr();
bytes += PairLJClass2::memory_usage();
return bytes;
}
|
; > ptr++
; < ptr--
; + dat[ptr]++
; - dat[ptr]--
; . cprint(dat[ptr])
; , dat[ptr] = cinp()
; [ if dat[ptr]==0 jmp matching ]
; ] if dat[ptr]!=0 jmp backmatching [
BFCK.ptr :
dd 0x0
BFCK.memRegion :
dd 0x0
BFCK.init :
pusha
push dword BFCK.COMMAND_PARSE
call iConsole2.RegisterCommand
popa
ret
BFCK.COMMAND_PARSE :
dd .parseStr
dd BFCK.parse
dd null
.parseStr :
db "parse", 0
BFCK.parse :
enter 0, 0
pusha
cmp dword [iConsole2.argNum], 2
jne .keepGoingPre
mov eax, [ebp+12]
mov ebx, .fileFlag
call os.seq
cmp al, 0
je .keepGoingPre
push dword .warning
call iConsole2.Echo
; need to read in the file with its name at [ebp+8]
mov eax, [ebp+8]
mov ebx, [iConsole2.currentFolder+0x0]
mov [.file+0x0], ebx
mov ebx, [iConsole2.currentFolder+0x4]
mov [.file+0x4], ebx
mov ebx, .file
call Minnow5.byName
cmp dword [ebx+0x4], -1
jne .allGood
push dword .fileNotFound
call iConsole2.Echo
jmp .ret
.allGood :
mov ebx, 1000 ; only run up to 1000 chars for now
call Guppy2.malloc
mov eax, .file
mov ecx, 1000
mov edx, 0
call Minnow5.readBuffer
; then set [ebp+8] to point to the file data in memory
mov [ebp+8], ebx
.keepGoingPre :
mov ebx, 1000
call Guppy2.malloc
mov [BFCK.memRegion], ebx
mov dword [.c], 0
mov dword [BFCK.ptr], 0
mov eax, [BFCK.memRegion]
mov ebx, 1000
call Buffer.clear
.loop :
mov ebx, [.c]
add ebx, [ebp+8]
cmp byte [ebx], 0
je .aret
cmp byte [ebx], '>'
jne .ngthan
inc dword [BFCK.ptr]
jmp .cdone
.ngthan :
cmp byte [ebx], '<'
jne .nlthan
dec dword [BFCK.ptr]
jmp .cdone
.nlthan :
cmp byte [ebx], '+'
jne .nplus
mov edx, [BFCK.memRegion]
add edx, [BFCK.ptr]
inc byte [edx]
jmp .cdone
.nplus :
cmp byte [ebx], '-'
jne .nminus
mov edx, [BFCK.memRegion]
add edx, [BFCK.ptr]
dec byte [edx]
jmp .cdone
.nminus :
cmp byte [ebx], '.'
jne .ndot
mov edx, [BFCK.memRegion]
add edx, [BFCK.ptr]
push edx
call iConsole2.EchoChar
jmp .cdone
.ndot :
cmp byte [ebx], ','
jne .ncomma
mov dword [iConsole2.keyRedirect], BFCK.keyGetter
mov [.ebxstor], ebx
mov ebx, [ebp+8]
mov [.instr], ebx
popa
leave
jmp iConsole2.returnBlindSilent
.entryPoint :
enter 0, 0
pusha
mov ebx, [.ebxstor]
mov edx, [BFCK.memRegion]
add edx, [BFCK.ptr]
mov cl, [BFCK.keyGetter.char]
mov [edx], cl
jmp .cdone
.ncomma :
cmp byte [ebx], '['
jne .nlbracket
mov edx, [BFCK.memRegion]
add edx, [BFCK.ptr]
cmp byte [edx], 0
jne .skiplbrak
.lbracketloop :
inc dword [.c]
inc ebx
cmp byte [ebx], 0
je .cdone
cmp byte [ebx], ']'
jne .lbracketloop
.skiplbrak :
jmp .cdone
.nlbracket :
cmp byte [ebx], ']'
jne .nrbracket
mov edx, [BFCK.memRegion]
add edx, [BFCK.ptr]
cmp byte [edx], 0
je .skiprbrak
.rbracketloop :
dec dword [.c]
dec ebx
cmp byte [ebx], '['
je .cdone
cmp dword [.c], 0
jne .rbracketloop
.skiprbrak :
jmp .cdone
.nrbracket :
.cdone :
inc dword [.c]
jmp .loop
.aret :
mov edx, [BFCK.memRegion]
call Guppy2.free
mov dword [iConsole2.keyRedirect], null
.ret :
popa
leave
call iConsole2.returnBlind
.c :
dd 0x0
.ebxstor :
dd 0x0
.instr :
dd 0x0
.fileFlag :
db "-F", 0
.warning :
db "[WARN] Executing files is currently in development.", newline, 0
.fileNotFound :
db "[ERROR] File not found.", newline, 0
.file :
dq 0x0
BFCK.keyGetter :
pusha
mov [0x1000], esp
call iConsole2.HandleKeyEventNoMod
mov bl, [Component.keyChar]
cmp bl, 0xFE
jne .notEnter
mov bl, 0x0
.notEnter :
mov [.char], bl
; mov dword [iConsole2.keyRedirect], null
push dword [BFCK.parse.instr]
call BFCK.parse.entryPoint
ret
.char :
db 0x0
|
; A016298: Expansion of 1/((1-2x)(1-5x)(1-9x)).
; Submitted by Jon Maiga
; 1,16,183,1850,17681,164316,1504843,13673710,123714261,1116683216,10066424303,90679197570,816519676441,7350711587716,66166576804563,595550053849430,5360204797752221,48243114745437816
mov $1,1
mov $3,2
lpb $0
sub $0,1
mul $1,5
div $3,2
mul $3,9
add $3,2
sub $3,$2
add $1,$3
mul $2,2
sub $2,2
mul $3,2
lpe
mov $0,$1
|
#pragma once
using material_handle_t = unsigned short;
enum material_flags {
material_var_debug = ( 1 << 0 ),
material_var_no_debug_override = ( 1 << 1 ),
material_var_no_draw = ( 1 << 2 ),
material_var_use_in_fillrate_mode = ( 1 << 3 ),
material_var_vertexcolor = ( 1 << 4 ),
material_var_vertexalpha = ( 1 << 5 ),
material_var_selfillum = ( 1 << 6 ),
material_var_additive = ( 1 << 7 ),
material_var_alphatest = ( 1 << 8 ),
material_var_multipass = ( 1 << 9 ),
material_var_znearer = ( 1 << 10 ),
material_var_model = ( 1 << 11 ),
material_var_flat = ( 1 << 12 ),
material_var_nocull = ( 1 << 13 ),
material_var_nofog = ( 1 << 14 ),
material_var_ignorez = ( 1 << 15 ),
material_var_decal = ( 1 << 16 ),
material_var_envmapsphere = ( 1 << 17 ),
material_var_noalphamod = ( 1 << 18 ),
material_var_envmapcameraspace = ( 1 << 19 ),
material_var_basealphaenvmapmask = ( 1 << 20 ),
material_var_translucent = ( 1 << 21 ),
material_var_normalmapalphaenvmapmask = ( 1 << 22 ),
material_var_needs_software_skinning = ( 1 << 23 ),
material_var_opaquetexture = ( 1 << 24 ),
material_var_envmapmode = ( 1 << 25 ),
material_var_suppress_decals = ( 1 << 26 ),
material_var_halflambert = ( 1 << 27 ),
material_var_wireframe = ( 1 << 28 ),
material_var_allowalphatocoverage = ( 1 << 29 ),
material_var_ignore_alpha_modulation = ( 1 << 30 ),
material_var_vertexfog = ( 1 << 31 )
};
class i_material {
public:
const char* get_name( ) {
using original_fn = const char*( __thiscall* )( i_material* );
return utilities::get( ).get_vfunc<original_fn>( this, 0 )( this );
}
const char* get_group_name( ) {
using original_fn = const char*( __thiscall* )( i_material* );
return utilities::get( ).get_vfunc<original_fn>( this, 1 )( this );
}
void set_alpha( int alpha ) {
using original_fn = void( __thiscall* )( i_material*, float );
return utilities::get( ).get_vfunc<original_fn>( this, 27 )( this, static_cast< float >( alpha ) / 255.f );
}
void set_color( int r, int g, int b ) {
using original_fn = void( __thiscall* )( i_material*, float, float, float );
return utilities::get( ).get_vfunc<original_fn>( this, 28 )( this, r / 255.f, g / 255.f, b / 255.f );
}
void set_flag( int flag, bool on ) {
using original_fn = void( __thiscall* )( i_material*, int, bool );
return utilities::get( ).get_vfunc<original_fn>( this, 29 )( this, flag, on );
}
}; |
[bits 16]
disk_load:
pusha
push dx
mov ah, 0x02
mov al, dh
mov cl, 0x02
mov ch, 0x00
mov dh, 0x00
int 0x13
jc disk_error
pop dx
cmp al, dh
jne sectors_error
popa
ret
disk_error:
mov bx, DISK_ERROR
call print
mov dh, ah
call print_hex
jmp disk_loop
sectors_error:
mov bx, SECTORS_ERROR
call print
disk_loop:
jmp $
DISK_ERROR: db "Disk read error ", 0
SECTOR_PER_TRACK: db 0
TOTAL_SECTOR: db 0
SECTORS_ERROR: db "Incorrect number of sectors read", 0 |
; A308742: Decimal expansion of BesselI(3/4,1/2)/BesselI(-1/4,1/2).
; Submitted by Jon Maiga
; 3,1,8,3,6,6,2,4,6,7,2,8,3,1,6,4,7,1,6,8,1,9,0,8,7,0,7,6,4,4,3,8,6,9,3,4,7,3,9,9,7,9,5,3,0,1,2,4,2,1,0,4,6,3,7,6,0,3,0,6,4,2,0,4,0,5,7,5,3,3,3,8,7,5,9,3,0,1,4,2,9,0,9,4,9,7,3,7,3,3,1,1,7,8,2,0,1,1,1,6
add $0,1
mov $2,5
mov $3,$0
add $3,1
mul $3,4
lpb $3
add $6,$2
add $1,$6
add $2,$1
mov $1,$5
sub $3,2
add $5,$2
mul $6,$3
lpe
mov $4,10
pow $4,$0
div $2,$4
div $1,$2
mov $0,$1
mod $0,10
|
/***************************************************************************
copyright : (C) 2002 - 2008 by Scott Wheeler
email : wheeler@kde.org
***************************************************************************/
/***************************************************************************
* This library is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License version *
* 2.1 as published by the Free Software Foundation. *
* *
* This library is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library; if not, write to the Free Software *
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA *
* 02110-1301 USA *
* *
* Alternatively, this file is available under the Mozilla Public *
* License Version 1.1. You may obtain a copy of the License at *
* http://www.mozilla.org/MPL/ *
***************************************************************************/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <tstring.h>
#include <tdebug.h>
#include "trefcounter.h"
#include "tutils.h"
#include "tbytevector.h"
// This is a bit ugly to keep writing over and over again.
// A rather obscure feature of the C++ spec that I hadn't thought of that makes
// working with C libs much more efficient. There's more here:
//
// http://www.informit.com/isapi/product_id~{9C84DAB4-FE6E-49C5-BB0A-FB50331233EA}/content/index.asp
#define DATA(x) (&(x->data->data[0]))
namespace TagLib {
static const char hexTable[17] = "0123456789abcdef";
static const uint crcTable[256] = {
0x00000000, 0x04c11db7, 0x09823b6e, 0x0d4326d9, 0x130476dc, 0x17c56b6b,
0x1a864db2, 0x1e475005, 0x2608edb8, 0x22c9f00f, 0x2f8ad6d6, 0x2b4bcb61,
0x350c9b64, 0x31cd86d3, 0x3c8ea00a, 0x384fbdbd, 0x4c11db70, 0x48d0c6c7,
0x4593e01e, 0x4152fda9, 0x5f15adac, 0x5bd4b01b, 0x569796c2, 0x52568b75,
0x6a1936c8, 0x6ed82b7f, 0x639b0da6, 0x675a1011, 0x791d4014, 0x7ddc5da3,
0x709f7b7a, 0x745e66cd, 0x9823b6e0, 0x9ce2ab57, 0x91a18d8e, 0x95609039,
0x8b27c03c, 0x8fe6dd8b, 0x82a5fb52, 0x8664e6e5, 0xbe2b5b58, 0xbaea46ef,
0xb7a96036, 0xb3687d81, 0xad2f2d84, 0xa9ee3033, 0xa4ad16ea, 0xa06c0b5d,
0xd4326d90, 0xd0f37027, 0xddb056fe, 0xd9714b49, 0xc7361b4c, 0xc3f706fb,
0xceb42022, 0xca753d95, 0xf23a8028, 0xf6fb9d9f, 0xfbb8bb46, 0xff79a6f1,
0xe13ef6f4, 0xe5ffeb43, 0xe8bccd9a, 0xec7dd02d, 0x34867077, 0x30476dc0,
0x3d044b19, 0x39c556ae, 0x278206ab, 0x23431b1c, 0x2e003dc5, 0x2ac12072,
0x128e9dcf, 0x164f8078, 0x1b0ca6a1, 0x1fcdbb16, 0x018aeb13, 0x054bf6a4,
0x0808d07d, 0x0cc9cdca, 0x7897ab07, 0x7c56b6b0, 0x71159069, 0x75d48dde,
0x6b93dddb, 0x6f52c06c, 0x6211e6b5, 0x66d0fb02, 0x5e9f46bf, 0x5a5e5b08,
0x571d7dd1, 0x53dc6066, 0x4d9b3063, 0x495a2dd4, 0x44190b0d, 0x40d816ba,
0xaca5c697, 0xa864db20, 0xa527fdf9, 0xa1e6e04e, 0xbfa1b04b, 0xbb60adfc,
0xb6238b25, 0xb2e29692, 0x8aad2b2f, 0x8e6c3698, 0x832f1041, 0x87ee0df6,
0x99a95df3, 0x9d684044, 0x902b669d, 0x94ea7b2a, 0xe0b41de7, 0xe4750050,
0xe9362689, 0xedf73b3e, 0xf3b06b3b, 0xf771768c, 0xfa325055, 0xfef34de2,
0xc6bcf05f, 0xc27dede8, 0xcf3ecb31, 0xcbffd686, 0xd5b88683, 0xd1799b34,
0xdc3abded, 0xd8fba05a, 0x690ce0ee, 0x6dcdfd59, 0x608edb80, 0x644fc637,
0x7a089632, 0x7ec98b85, 0x738aad5c, 0x774bb0eb, 0x4f040d56, 0x4bc510e1,
0x46863638, 0x42472b8f, 0x5c007b8a, 0x58c1663d, 0x558240e4, 0x51435d53,
0x251d3b9e, 0x21dc2629, 0x2c9f00f0, 0x285e1d47, 0x36194d42, 0x32d850f5,
0x3f9b762c, 0x3b5a6b9b, 0x0315d626, 0x07d4cb91, 0x0a97ed48, 0x0e56f0ff,
0x1011a0fa, 0x14d0bd4d, 0x19939b94, 0x1d528623, 0xf12f560e, 0xf5ee4bb9,
0xf8ad6d60, 0xfc6c70d7, 0xe22b20d2, 0xe6ea3d65, 0xeba91bbc, 0xef68060b,
0xd727bbb6, 0xd3e6a601, 0xdea580d8, 0xda649d6f, 0xc423cd6a, 0xc0e2d0dd,
0xcda1f604, 0xc960ebb3, 0xbd3e8d7e, 0xb9ff90c9, 0xb4bcb610, 0xb07daba7,
0xae3afba2, 0xaafbe615, 0xa7b8c0cc, 0xa379dd7b, 0x9b3660c6, 0x9ff77d71,
0x92b45ba8, 0x9675461f, 0x8832161a, 0x8cf30bad, 0x81b02d74, 0x857130c3,
0x5d8a9099, 0x594b8d2e, 0x5408abf7, 0x50c9b640, 0x4e8ee645, 0x4a4ffbf2,
0x470cdd2b, 0x43cdc09c, 0x7b827d21, 0x7f436096, 0x7200464f, 0x76c15bf8,
0x68860bfd, 0x6c47164a, 0x61043093, 0x65c52d24, 0x119b4be9, 0x155a565e,
0x18197087, 0x1cd86d30, 0x029f3d35, 0x065e2082, 0x0b1d065b, 0x0fdc1bec,
0x3793a651, 0x3352bbe6, 0x3e119d3f, 0x3ad08088, 0x2497d08d, 0x2056cd3a,
0x2d15ebe3, 0x29d4f654, 0xc5a92679, 0xc1683bce, 0xcc2b1d17, 0xc8ea00a0,
0xd6ad50a5, 0xd26c4d12, 0xdf2f6bcb, 0xdbee767c, 0xe3a1cbc1, 0xe760d676,
0xea23f0af, 0xeee2ed18, 0xf0a5bd1d, 0xf464a0aa, 0xf9278673, 0xfde69bc4,
0x89b8fd09, 0x8d79e0be, 0x803ac667, 0x84fbdbd0, 0x9abc8bd5, 0x9e7d9662,
0x933eb0bb, 0x97ffad0c, 0xafb010b1, 0xab710d06, 0xa6322bdf, 0xa2f33668,
0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4
};
/*!
* A templatized straightforward find that works with the types
* std::vector<char>::iterator and std::vector<char>::reverse_iterator.
*/
template <class TIterator>
int findChar(
const TIterator dataBegin, const TIterator dataEnd,
char c, uint offset, int byteAlign)
{
const size_t dataSize = dataEnd - dataBegin;
if(dataSize == 0 || offset > dataSize - 1)
return -1;
// n % 0 is invalid
if(byteAlign == 0)
return -1;
for(TIterator it = dataBegin + offset; it < dataEnd; it += byteAlign) {
if(*it == c)
return (it - dataBegin);
}
return -1;
}
/*!
* A templatized KMP find that works with the types
* std::vector<char>::iterator and std::vector<char>::reverse_iterator.
*/
template <class TIterator>
int findVector(
const TIterator dataBegin, const TIterator dataEnd,
const TIterator patternBegin, const TIterator patternEnd,
uint offset, int byteAlign)
{
const size_t dataSize = dataEnd - dataBegin;
const size_t patternSize = patternEnd - patternBegin;
if(patternSize > dataSize || offset > dataSize - 1)
return -1;
// n % 0 is invalid
if(byteAlign == 0)
return -1;
// Special case that pattern contains just single char.
if(patternSize == 1)
return findChar(dataBegin, dataEnd, *patternBegin, offset, byteAlign);
size_t lastOccurrence[256];
for(size_t i = 0; i < 256; ++i)
lastOccurrence[i] = patternSize;
for(size_t i = 0; i < patternSize - 1; ++i)
lastOccurrence[static_cast<uchar>(*(patternBegin + i))] = patternSize - i - 1;
TIterator it = dataBegin + patternSize - 1 + offset;
while(true)
{
TIterator itBuffer = it;
TIterator itPattern = patternBegin + patternSize - 1;
while(*itBuffer == *itPattern)
{
if(itPattern == patternBegin)
{
if((itBuffer - dataBegin - offset) % byteAlign == 0)
return (itBuffer - dataBegin);
else
break;
}
--itBuffer;
--itPattern;
}
const size_t step = lastOccurrence[static_cast<uchar>(*it)];
if(dataEnd - step <= it)
break;
it += step;
}
return -1;
}
template <class T>
T toNumber(const ByteVector &v, size_t offset, size_t length, bool mostSignificantByteFirst)
{
if(offset >= v.size()) {
debug("toNumber<T>() -- No data to convert. Returning 0.");
return 0;
}
length = std::min(length, v.size() - offset);
T sum = 0;
for(size_t i = 0; i < length; i++) {
const size_t shift = (mostSignificantByteFirst ? length - 1 - i : i) * 8;
sum |= static_cast<T>(static_cast<uchar>(v[offset + i])) << shift;
}
return sum;
}
template <class T>
T toNumber(const ByteVector &v, size_t offset, bool mostSignificantByteFirst)
{
static const bool isBigEndian = (Utils::SystemByteOrder == Utils::BigEndian);
const bool swap = (mostSignificantByteFirst != isBigEndian);
if(offset + sizeof(T) > v.size())
return toNumber<T>(v, offset, v.size() - offset, mostSignificantByteFirst);
// Uses memcpy instead of reinterpret_cast to avoid an alignment exception.
T tmp;
::memcpy(&tmp, v.data() + offset, sizeof(T));
if(swap)
return Utils::byteSwap(tmp);
else
return tmp;
}
template <class T>
ByteVector fromNumber(T value, bool mostSignificantByteFirst)
{
static const bool isBigEndian = (Utils::SystemByteOrder == Utils::BigEndian);
const bool swap = (mostSignificantByteFirst != isBigEndian);
if(swap)
value = Utils::byteSwap(value);
return ByteVector(reinterpret_cast<const char *>(&value), sizeof(T));
}
class DataPrivate : public RefCounter
{
public:
DataPrivate()
{
}
DataPrivate(const std::vector<char> &v, uint offset, uint length)
: data(v.begin() + offset, v.begin() + offset + length)
{
}
// A char* can be an iterator.
DataPrivate(const char *begin, const char *end)
: data(begin, end)
{
}
DataPrivate(uint len, char c)
: data(len, c)
{
}
std::vector<char> data;
};
class ByteVector::ByteVectorPrivate : public RefCounter
{
public:
ByteVectorPrivate()
: RefCounter()
, data(new DataPrivate())
, offset(0)
, length(0)
{
}
ByteVectorPrivate(ByteVectorPrivate *d, uint o, uint l)
: RefCounter()
, data(d->data)
, offset(d->offset + o)
, length(l)
{
data->ref();
}
ByteVectorPrivate(const std::vector<char> &v, uint o, uint l)
: RefCounter()
, data(new DataPrivate(v, o, l))
, offset(0)
, length(l)
{
}
ByteVectorPrivate(uint l, char c)
: RefCounter()
, data(new DataPrivate(l, c))
, offset(0)
, length(l)
{
}
ByteVectorPrivate(const char *s, uint l)
: RefCounter()
, data(new DataPrivate(s, s + l))
, offset(0)
, length(l)
{
}
void detach()
{
if(data->count() > 1) {
data->deref();
data = new DataPrivate(data->data, offset, length);
offset = 0;
}
}
~ByteVectorPrivate()
{
if(data->deref())
delete data;
}
ByteVectorPrivate &operator=(const ByteVectorPrivate &x)
{
if(&x != this)
{
if(data->deref())
delete data;
data = x.data;
data->ref();
}
return *this;
}
DataPrivate *data;
uint offset;
uint length;
};
////////////////////////////////////////////////////////////////////////////////
// static members
////////////////////////////////////////////////////////////////////////////////
ByteVector ByteVector::null;
ByteVector ByteVector::fromCString(const char *s, uint length)
{
if(length == 0xffffffff)
return ByteVector(s, ::strlen(s));
else
return ByteVector(s, length);
}
ByteVector ByteVector::fromUInt(uint value, bool mostSignificantByteFirst)
{
return fromNumber<uint>(value, mostSignificantByteFirst);
}
ByteVector ByteVector::fromShort(short value, bool mostSignificantByteFirst)
{
return fromNumber<ushort>(value, mostSignificantByteFirst);
}
ByteVector ByteVector::fromLongLong(long long value, bool mostSignificantByteFirst)
{
return fromNumber<unsigned long long>(value, mostSignificantByteFirst);
}
////////////////////////////////////////////////////////////////////////////////
// public members
////////////////////////////////////////////////////////////////////////////////
ByteVector::ByteVector()
: d(new ByteVectorPrivate())
{
}
ByteVector::ByteVector(uint size, char value)
: d(new ByteVectorPrivate(size, value))
{
}
ByteVector::ByteVector(const ByteVector &v)
: d(v.d)
{
d->ref();
}
ByteVector::ByteVector(const ByteVector &v, uint offset, uint length)
: d(new ByteVectorPrivate(v.d, offset, length))
{
}
ByteVector::ByteVector(char c)
: d(new ByteVectorPrivate(1, c))
{
}
ByteVector::ByteVector(const char *data, uint length)
: d(new ByteVectorPrivate(data, length))
{
}
ByteVector::ByteVector(const char *data)
: d(new ByteVectorPrivate(data, ::strlen(data)))
{
}
ByteVector::~ByteVector()
{
if(d->deref())
delete d;
}
ByteVector &ByteVector::setData(const char *s, uint length)
{
*this = ByteVector(s, length);
return *this;
}
ByteVector &ByteVector::setData(const char *data)
{
*this = ByteVector(data);
return *this;
}
char *ByteVector::data()
{
detach();
return size() > 0 ? (DATA(d) + d->offset) : 0;
}
const char *ByteVector::data() const
{
return size() > 0 ? (DATA(d) + d->offset) : 0;
}
ByteVector ByteVector::mid(uint index, uint length) const
{
index = std::min(index, size());
length = std::min(length, size() - index);
return ByteVector(*this, index, length);
}
char ByteVector::at(uint index) const
{
return index < size() ? DATA(d)[d->offset + index] : 0;
}
int ByteVector::find(const ByteVector &pattern, uint offset, int byteAlign) const
{
return findVector<ConstIterator>(
begin(), end(), pattern.begin(), pattern.end(), offset, byteAlign);
}
int ByteVector::find(char c, uint offset, int byteAlign) const
{
return findChar<ConstIterator>(begin(), end(), c, offset, byteAlign);
}
int ByteVector::rfind(const ByteVector &pattern, uint offset, int byteAlign) const
{
if(offset > 0) {
offset = size() - offset - pattern.size();
if(offset >= size())
offset = 0;
}
const int pos = findVector<ConstReverseIterator>(
rbegin(), rend(), pattern.rbegin(), pattern.rend(), offset, byteAlign);
if(pos == -1)
return -1;
else
return size() - pos - pattern.size();
}
bool ByteVector::containsAt(const ByteVector &pattern, uint offset, uint patternOffset, uint patternLength) const
{
if(pattern.size() < patternLength)
patternLength = pattern.size();
// do some sanity checking -- all of these things are needed for the search to be valid
const uint compareLength = patternLength - patternOffset;
if(offset + compareLength > size() || patternOffset >= pattern.size() || patternLength == 0)
return false;
return (::memcmp(data() + offset, pattern.data() + patternOffset, compareLength) == 0);
}
bool ByteVector::startsWith(const ByteVector &pattern) const
{
return containsAt(pattern, 0);
}
bool ByteVector::endsWith(const ByteVector &pattern) const
{
return containsAt(pattern, size() - pattern.size());
}
ByteVector &ByteVector::replace(const ByteVector &pattern, const ByteVector &with)
{
if(pattern.size() == 0 || pattern.size() > size())
return *this;
const uint withSize = with.size();
const uint patternSize = pattern.size();
int offset = 0;
if(withSize == patternSize) {
// I think this case might be common enough to optimize it
detach();
offset = find(pattern);
while(offset >= 0) {
::memcpy(data() + offset, with.data(), withSize);
offset = find(pattern, offset + withSize);
}
return *this;
}
// calculate new size:
uint newSize = 0;
for(;;) {
int next = find(pattern, offset);
if(next < 0) {
if(offset == 0)
// pattern not found, do nothing:
return *this;
newSize += size() - offset;
break;
}
newSize += (next - offset) + withSize;
offset = next + patternSize;
}
// new private data of appropriate size:
ByteVectorPrivate *newData = new ByteVectorPrivate(newSize, 0);
char *target = DATA(newData);
const char *source = data();
// copy modified data into new private data:
offset = 0;
for(;;) {
int next = find(pattern, offset);
if(next < 0) {
::memcpy(target, source + offset, size() - offset);
break;
}
int chunkSize = next - offset;
::memcpy(target, source + offset, chunkSize);
target += chunkSize;
::memcpy(target, with.data(), withSize);
target += withSize;
offset += chunkSize + patternSize;
}
// replace private data:
if(d->deref())
delete d;
d = newData;
return *this;
}
int ByteVector::endsWithPartialMatch(const ByteVector &pattern) const
{
if(pattern.size() > size())
return -1;
const int startIndex = size() - pattern.size();
// try to match the last n-1 bytes from the vector (where n is the pattern
// size) -- continue trying to match n-2, n-3...1 bytes
for(uint i = 1; i < pattern.size(); i++) {
if(containsAt(pattern, startIndex + i, 0, pattern.size() - i))
return startIndex + i;
}
return -1;
}
ByteVector &ByteVector::append(const ByteVector &v)
{
if(v.d->length != 0)
{
detach();
uint originalSize = size();
resize(originalSize + v.size());
::memcpy(data() + originalSize, v.data(), v.size());
}
return *this;
}
ByteVector &ByteVector::clear()
{
*this = ByteVector();
return *this;
}
TagLib::uint ByteVector::size() const
{
return d->length;
}
ByteVector &ByteVector::resize(uint size, char padding)
{
if(size != d->length) {
detach();
d->data->data.resize(d->offset + size, padding);
d->length = size;
}
return *this;
}
ByteVector::Iterator ByteVector::begin()
{
return d->data->data.begin() + d->offset;
}
ByteVector::ConstIterator ByteVector::begin() const
{
return d->data->data.begin() + d->offset;
}
ByteVector::Iterator ByteVector::end()
{
return d->data->data.begin() + d->offset + d->length;
}
ByteVector::ConstIterator ByteVector::end() const
{
return d->data->data.begin() + d->offset + d->length;
}
ByteVector::ReverseIterator ByteVector::rbegin()
{
std::vector<char> &v = d->data->data;
return v.rbegin() + (v.size() - (d->offset + d->length));
}
ByteVector::ConstReverseIterator ByteVector::rbegin() const
{
std::vector<char> &v = d->data->data;
return v.rbegin() + (v.size() - (d->offset + d->length));
}
ByteVector::ReverseIterator ByteVector::rend()
{
std::vector<char> &v = d->data->data;
return v.rbegin() + (v.size() - d->offset);
}
ByteVector::ConstReverseIterator ByteVector::rend() const
{
std::vector<char> &v = d->data->data;
return v.rbegin() + (v.size() - d->offset);
}
bool ByteVector::isNull() const
{
return (d == null.d);
}
bool ByteVector::isEmpty() const
{
return (d->length == 0);
}
TagLib::uint ByteVector::checksum() const
{
uint sum = 0;
for(ByteVector::ConstIterator it = begin(); it != end(); ++it)
sum = (sum << 8) ^ crcTable[((sum >> 24) & 0xff) ^ uchar(*it)];
return sum;
}
TagLib::uint ByteVector::toUInt(bool mostSignificantByteFirst) const
{
return toNumber<uint>(*this, 0, mostSignificantByteFirst);
}
TagLib::uint ByteVector::toUInt(uint offset, bool mostSignificantByteFirst) const
{
return toNumber<uint>(*this, offset, mostSignificantByteFirst);
}
TagLib::uint ByteVector::toUInt(uint offset, uint length, bool mostSignificantByteFirst) const
{
return toNumber<uint>(*this, offset, length, mostSignificantByteFirst);
}
short ByteVector::toShort(bool mostSignificantByteFirst) const
{
return toNumber<unsigned short>(*this, 0, mostSignificantByteFirst);
}
short ByteVector::toShort(uint offset, bool mostSignificantByteFirst) const
{
return toNumber<unsigned short>(*this, offset, mostSignificantByteFirst);
}
unsigned short ByteVector::toUShort(bool mostSignificantByteFirst) const
{
return toNumber<unsigned short>(*this, 0, mostSignificantByteFirst);
}
unsigned short ByteVector::toUShort(uint offset, bool mostSignificantByteFirst) const
{
return toNumber<unsigned short>(*this, offset, mostSignificantByteFirst);
}
long long ByteVector::toLongLong(bool mostSignificantByteFirst) const
{
return toNumber<unsigned long long>(*this, 0, mostSignificantByteFirst);
}
long long ByteVector::toLongLong(uint offset, bool mostSignificantByteFirst) const
{
return toNumber<unsigned long long>(*this, offset, mostSignificantByteFirst);
}
const char &ByteVector::operator[](int index) const
{
return d->data->data[d->offset + index];
}
char &ByteVector::operator[](int index)
{
detach();
return d->data->data[d->offset + index];
}
bool ByteVector::operator==(const ByteVector &v) const
{
if(size() != v.size())
return false;
return (::memcmp(data(), v.data(), size()) == 0);
}
bool ByteVector::operator!=(const ByteVector &v) const
{
return !operator==(v);
}
bool ByteVector::operator==(const char *s) const
{
if(size() != ::strlen(s))
return false;
return (::memcmp(data(), s, size()) == 0);
}
bool ByteVector::operator!=(const char *s) const
{
return !operator==(s);
}
bool ByteVector::operator<(const ByteVector &v) const
{
const int result = ::memcmp(data(), v.data(), std::min(size(), v.size()));
if(result != 0)
return result < 0;
else
return size() < v.size();
}
bool ByteVector::operator>(const ByteVector &v) const
{
return v < *this;
}
ByteVector ByteVector::operator+(const ByteVector &v) const
{
ByteVector sum(*this);
sum.append(v);
return sum;
}
ByteVector &ByteVector::operator=(const ByteVector &v)
{
if(&v == this)
return *this;
if(d->deref())
delete d;
d = v.d;
d->ref();
return *this;
}
ByteVector &ByteVector::operator=(char c)
{
*this = ByteVector(c);
return *this;
}
ByteVector &ByteVector::operator=(const char *data)
{
*this = ByteVector(data);
return *this;
}
ByteVector ByteVector::toHex() const
{
ByteVector encoded(size() * 2);
char *p = encoded.data();
for(uint i = 0; i < size(); i++) {
unsigned char c = data()[i];
*p++ = hexTable[(c >> 4) & 0x0F];
*p++ = hexTable[(c ) & 0x0F];
}
return encoded;
}
////////////////////////////////////////////////////////////////////////////////
// protected members
////////////////////////////////////////////////////////////////////////////////
void ByteVector::detach()
{
if(d->data->count() > 1) {
d->data->deref();
d->data = new DataPrivate(d->data->data, d->offset, d->length);
d->offset = 0;
}
if(d->count() > 1) {
d->deref();
d = new ByteVectorPrivate(d->data->data, d->offset, d->length);
}
}
}
////////////////////////////////////////////////////////////////////////////////
// related functions
////////////////////////////////////////////////////////////////////////////////
std::ostream &operator<<(std::ostream &s, const TagLib::ByteVector &v)
{
for(TagLib::uint i = 0; i < v.size(); i++)
s << v[i];
return s;
}
|
; The old code patched in NAME1 for a status message inside 08077F14.
; We now render properly using the VWF, so remove the patching.
.org 0x08077F94
.region 0x08077FAA-.,0x00
b 0x08077FAA
.endregion
.ifdef NameMaxLength
; This is a small part of 0807C96C, which draws the Friends status content.
; Just adjusting the name length.
.org 0x0807C98E
.region 0x0807C9AC-.,0x00
; At this point: r0=FREE, r1=FREE, r2=FREE
; r4=0x03004FF8 (menu params), r5=FREE, r6=FREE, r7=FREE, r8=dest
; This is the char number.
ldrb r0,[r4,0x1F]
; Get our utility params struct.
ldr r3,[0x0807CAB8] ; 0x030018BC
mov r1,r8
; Our X/Y offset is 0x140 + 0x400.
mov r2,0x54
lsl r2,r2,4
add r1,r1,r2
str r1,[r3,8]
mov r1,6
bl CopyCharName8x8ToVRAMClearR1
b 0x0807C9AC
.pool
.endregion
; This replaces a value in the literal pool (since we no longer need the old one.)
.org 0x0807CAB8
dw 0x030018BC
; This function draws the names on the left of the Friends menu. We fix the lengths.
.org 0x08072FBC
.region 0x08073034-.,0x00
.func FriendsMenuDrawSidebarNames
mov r3,r8
push r3-r7,r14
; This is where our dest address lives.
ldr r7,=0x03004FF8
ldr r7,[r7,0]
; Add our Y, 0x30 pixels or 6 tiles.
mov r0,6
lsl r0,r0,10
add r7,r7,r0
; And our base X, 1 tile.
add r7,0x20
; Grab the party size and start a counter in r6.
ldr r0,=0x030035F0
ldrb r0,[r0,0]
mov r8,r0
mov r6,0
; Set up the y stride for each character (except the first.)
mov r5,3
lsl r5,r5,10
; And finally the utility/drawing params struct.
ldr r4,=0x030018BC
@@nextChar:
mov r0,r6
mov r1,6
str r7,[r4,8]
bl CopyCharName8x8ToVRAMClearR1
add r7,r7,r5
add r6,r6,1
cmp r6,1
bne @@skipExtraSpacing
; Conveniently, we want 1 tile of space after the first one.
lsl r0,r6,10
add r7,r7,r0
@@skipExtraSpacing:
cmp r6,r8
blt @@nextChar
pop r3
mov r8,r3
pop r4-r7,r15
.pool
.endfunc
.endregion
.endif
|
; A064038: Numerator of average number of swaps needed to bubble sort a string of n distinct letters.
; 0,1,3,3,5,15,21,14,18,45,55,33,39,91,105,60,68,153,171,95,105,231,253,138,150,325,351,189,203,435,465,248,264,561,595,315,333,703,741,390,410,861,903,473,495,1035,1081,564,588,1225,1275,663,689,1431,1485,770,798,1653,1711,885,915,1891,1953,1008,1040,2145,2211,1139,1173,2415,2485,1278,1314,2701,2775,1425,1463,3003,3081,1580,1620,3321,3403,1743,1785,3655,3741,1914,1958,4005,4095,2093,2139,4371,4465,2280,2328,4753,4851,2475,2525,5151,5253,2678,2730,5565,5671,2889,2943,5995,6105,3108,3164,6441,6555,3335,3393,6903,7021,3570,3630,7381,7503,3813,3875,7875,8001,4064,4128,8385,8515,4323,4389,8911,9045,4590,4658,9453,9591,4865,4935,10011,10153,5148,5220,10585,10731,5439,5513,11175,11325,5738,5814,11781,11935,6045,6123,12403,12561,6360,6440,13041,13203,6683,6765,13695,13861,7014,7098,14365,14535,7353,7439,15051,15225,7700,7788,15753,15931,8055,8145,16471,16653,8418,8510,17205,17391,8789,8883,17955,18145,9168,9264,18721,18915,9555,9653,19503,19701,9950,10050,20301,20503,10353,10455,21115,21321,10764,10868,21945,22155,11183,11289,22791,23005,11610,11718,23653,23871,12045,12155,24531,24753,12488,12600,25425,25651,12939,13053,26335,26565,13398,13514,27261,27495,13865,13983,28203,28441,14340,14460,29161,29403,14823,14945,30135,30381,15314,15438,31125
add $0,1
bin $0,2
mov $1,1031
mul $1,$0
sub $1,$0
mov $2,$0
gcd $2,2
div $1,$2
div $1,1030
|
#include "DataFormats/HcalIsolatedTrack/interface/IsolatedPixelTrackCandidate.h"
using namespace reco;
IsolatedPixelTrackCandidate::IsolatedPixelTrackCandidate(const IsolatedPixelTrackCandidate& right) : RecoCandidate(right), track_(right.track_), l1tauJet_(right.l1tauJet_) {
maxPtPxl_ = right.maxPtPxl_;
sumPtPxl_ = right.sumPtPxl_;
enIn_ = right.enIn_;
enOut_ = right.enOut_;
nhitIn_ = right.nhitIn_;
nhitOut_ = right.nhitOut_;
etaPhiEcal_= right.etaPhiEcal_;
etaEcal_ = right.etaEcal_;
phiEcal_ = right.phiEcal_;
}
IsolatedPixelTrackCandidate::~IsolatedPixelTrackCandidate() { }
IsolatedPixelTrackCandidate * IsolatedPixelTrackCandidate::clone() const {
return new IsolatedPixelTrackCandidate( * this );
}
TrackRef IsolatedPixelTrackCandidate::track() const {
return track_;
}
l1extra::L1JetParticleRef IsolatedPixelTrackCandidate::l1tau() const {
return l1tauJet_;
}
l1t::TauRef IsolatedPixelTrackCandidate::l1ttau() const {
return l1ttauJet_;
}
bool IsolatedPixelTrackCandidate::overlap( const Candidate & c ) const {
const RecoCandidate * o = dynamic_cast<const RecoCandidate *>( & c );
return ( o != 0 && checkOverlap( track(), o->track() ) );
}
std::pair<int,int> IsolatedPixelTrackCandidate::towerIndex() const {
int ieta(0), iphi(0), nphi(72), kphi(1);
double etas[24]={0.000,0.087,0.174,0.261,0.348,0.435,0.522,0.609,0.696,
0.783,0.870,0.957,1.044,1.131,1.218,1.305,1.392,1.479,
1.566,1.653,1.740,1.830,1.930,2.043};
for (int i=1; i<24; i++) {
if (fabs(track_->eta())<=etas[i]) {
ieta = (track_->eta() > 0) ? i : -i;
if (i > 20) {
kphi = 2; nphi = 36;
}
break;
}
}
const double dphi=M_PI/36.; //0.087266462;
double phi = track_->phi();
if (phi < 0) phi += (2*M_PI);
double delta = phi+(kphi*dphi);
for (int i=0; i<nphi; i++) {
if (delta<=(kphi*(i+1)*dphi)) {
iphi = kphi*i + 1;
break;
}
}
return std::pair<int,int>(ieta,iphi);
}
|
.global s_prepare_buffers
s_prepare_buffers:
push %r11
push %r14
push %r8
push %rax
push %rcx
push %rdi
push %rdx
push %rsi
lea addresses_D_ht+0xa3c7, %rsi
lea addresses_WT_ht+0x133c7, %rdi
nop
cmp $52334, %rax
mov $110, %rcx
rep movsq
nop
nop
nop
nop
nop
add %rdi, %rdi
lea addresses_UC_ht+0x3fc7, %rsi
lea addresses_WC_ht+0x1e907, %rdi
nop
and %r8, %r8
mov $122, %rcx
rep movsl
and %rcx, %rcx
lea addresses_A_ht+0xc7c7, %rsi
lea addresses_normal_ht+0x7cc7, %rdi
nop
nop
xor %r14, %r14
mov $111, %rcx
rep movsw
nop
nop
nop
nop
nop
add %rcx, %rcx
lea addresses_WT_ht+0x127c7, %rsi
lea addresses_normal_ht+0xa5db, %rdi
clflush (%rsi)
clflush (%rdi)
nop
nop
nop
add $62230, %r11
mov $109, %rcx
rep movsl
nop
nop
nop
xor %rax, %rax
lea addresses_WT_ht+0x1efc7, %rax
add %r14, %r14
movb $0x61, (%rax)
nop
nop
nop
dec %r8
lea addresses_A_ht+0xdd07, %r11
nop
nop
nop
nop
nop
add $28626, %r8
mov $0x6162636465666768, %rcx
movq %rcx, (%r11)
nop
nop
nop
nop
and %rcx, %rcx
lea addresses_D_ht+0x135c7, %rsi
xor %r8, %r8
mov $0x6162636465666768, %r11
movq %r11, (%rsi)
nop
and $24668, %r14
lea addresses_D_ht+0x13267, %rsi
lea addresses_WT_ht+0x49c7, %rdi
clflush (%rsi)
nop
nop
nop
nop
nop
inc %rdx
mov $23, %rcx
rep movsb
nop
nop
nop
nop
inc %rax
pop %rsi
pop %rdx
pop %rdi
pop %rcx
pop %rax
pop %r8
pop %r14
pop %r11
ret
.global s_faulty_load
s_faulty_load:
push %r11
push %r12
push %r15
push %r9
push %rax
// Faulty Load
lea addresses_D+0xdfc7, %r9
nop
nop
add %r11, %r11
movups (%r9), %xmm4
vpextrq $1, %xmm4, %r15
lea oracles, %rax
and $0xff, %r15
shlq $12, %r15
mov (%rax,%r15,1), %r15
pop %rax
pop %r9
pop %r15
pop %r12
pop %r11
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'type': 'addresses_D', 'size': 32, 'AVXalign': False, 'NT': True, 'congruent': 0, 'same': False}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'type': 'addresses_D', 'size': 16, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': True}}
<gen_prepare_buffer>
{'OP': 'REPM', 'src': {'type': 'addresses_D_ht', 'congruent': 10, 'same': False}, 'dst': {'type': 'addresses_WT_ht', 'congruent': 10, 'same': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_UC_ht', 'congruent': 11, 'same': False}, 'dst': {'type': 'addresses_WC_ht', 'congruent': 1, 'same': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_A_ht', 'congruent': 11, 'same': False}, 'dst': {'type': 'addresses_normal_ht', 'congruent': 8, 'same': True}}
{'OP': 'REPM', 'src': {'type': 'addresses_WT_ht', 'congruent': 11, 'same': False}, 'dst': {'type': 'addresses_normal_ht', 'congruent': 2, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_WT_ht', 'size': 1, 'AVXalign': True, 'NT': False, 'congruent': 6, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_A_ht', 'size': 8, 'AVXalign': False, 'NT': False, 'congruent': 6, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_D_ht', 'size': 8, 'AVXalign': False, 'NT': False, 'congruent': 8, 'same': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_D_ht', 'congruent': 3, 'same': False}, 'dst': {'type': 'addresses_WT_ht', 'congruent': 7, 'same': True}}
{'36': 21829}
36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36
*/
|
INCLUDE "graphics/grafix.inc"
PUBLIC w_line_r
EXTERN line
;EXTERN l_cmp
EXTERN coords
;
; $Id: w_liner.asm,v 1.7 2015/09/29 15:36:04 stefano Exp $
;
; ******************************************************************************
;
; Draw a pixel line from (x0,y0) defined in (COORDS) - the current plot
; coordinate, to the relative distance points (x0+x,y0+y).
;
; Wide resolution (WORD based parameters) version by Stefano Bodrato
;
; Design & programming by Gunther Strube, Copyright (C) InterLogic 1995
;
;
; The (COORDS+0) pointer contains the current x coordinate, (COORDS+2) the
; current y coordinate. The main program should set the (COORDS) variables
; before using line drawing.
;
; The routine checks the range of specified coordinates which is the
; boundaries of the graphics area (256x64 pixels).
; If a boundary error occurs the routine exits automatically. This may be
; useful if you are trying to draw a line longer than allowed. Only the
; visible part will be drawn.
;
; The hardware graphics memory is organized as (0,0) in the top left corner.
;
;
;
; "draw line" algorithm
; ------------------------------------------
;
; direc_x = SGN x: direc_y = SGN y (D',E')
; x = ABS x: y = ABS y
;
; if x >= y
; if x+y=0 then return
; HL = x
; DE = y
; ddx = direc_x (B')
; ddy = 0 (C')
; else
; HL = y
; DE = x
; ddx = 0 (B')
; ddy = direc_y (C')
; endif
;
; BC = HL
; i = INT(BC/2)
; FOR N=BC TO 1 STEP -1
; i = i + DE
; if i < HL
; inx = ddx (B')
; iny = ddy (C')
; else
; i = i - HL
; inx = direc_x
; iny = direc_y
; endif
; x0 = x0 + inx
; y0 = y0 + iny
; plot (x0,y0)
; NEXT N
; ------------------------------------------
.w_line_r ;push bc
;push de ; preserve relative vertical distance
;push hl ; preserve relative horizontal distance
push de
push hl
exx
pop hl ; get relative horizontal direction
call sgn
ld d,a ; direc_x [D'] = SGN(x) installed
call abs ; x = ABS(x)
ex (sp),hl ; get vert. direction/save horiz. direction
call sgn ; direc_y = SGN(y) installed [DE']
ld e,a ; direc_y [E'] = SGN(y) installed
call abs
push hl
exx
pop de ; DE = absolute y distance
pop hl ; HL = absolute x distance
;call l_cmp ; CMP HL,DE [carry set if DE < HL]
ld a,d ; CMP DE,HL [carry set if HL < DE]
add $80
ld b,a
ld a,h
add $80
cp b
jr nz,noteq
ld a,l
cp e
; jr z, exit_draw ; if x+y = 0 then return
.noteq
jr c, x_smaller_y ; if x > y
ld a,d
or e
or h
or l
jr z, exit_draw ; if x+y = 0 then return
; else
exx
ld b,d ; ddx = direc_x
ld c,2 ; ddy = zero
exx
jr init_drawloop ; else
.x_smaller_y
ex de,hl ; invert x,y
exx
ld b,2 ; ddx = zero
ld c,e ; ddy = direc_y
exx
.init_drawloop ld b,h
ld c,l ; BC = HL
srl h ; i = INT(BC/2)
rr l
push hl
pop iy
ld h,b
ld l,c
;-------------- -------------- -------------- --------------
.drawloop push bc ; FOR N=BC TO 1 STEP -1
add iy,de ; i = i + DE
; cmp hl,iy
ld a,iyh
add $80
ld b,a
ld a,h
add $80
cp b
ret nz
ld a,l
cp iyl
.noteq2
jp c, i_greater ; if i < HL
exx
push bc ; inx = ddx: iny = ddy
exx
jp check_plot ; else
.i_greater
ld a,iyl ; (IY) i = i - HL
sub l
ld iyl,a
ld a,iyh
sbc a,h
ld iyh,a
exx
push de ; inx = direc_x: iny = direc_y
exx ; endif
.check_plot
ex (sp),hl ; preserve distances on stack
push de
; ex de,hl ; D,E = inx, iny
ld de,(coords+2) ; y0 = y0 + iny (range is checked by plot func.)
dec l ; iny
jp z,incy
dec l
jp z,zy
dec de
dec de
.incy inc de
.zy
ld a,h
ld hl,(coords) ; x0 = x0 + inx (range is checked by plot func.)
dec a ; inx
jp z,incx
dec a
jp z,zx
dec hl
dec hl
.incx inc hl
.zx
.plot_point ld bc, plot_RET
push bc ; hl,de = (x0,y0)...
jp (ix) ; execute PLOT at (x0,y0)
.plot_RET
pop de ; restore distances...
pop hl
pop bc
dec bc
ld a,b
or c
jp nz,drawloop ; NEXT N
;-------------- -------------- -------------- --------------
.exit_draw
ret
;.exit_draw pop hl ; restore relative horizontal distance
; pop de ; restore relative vertical distance
; pop bc
; ret
; ******************************************************************************
;
; SGN (Sign value) of 16 bit signed integer.
;
; IN: HL = integer
; OUT: A = result: 2,1,-1 (if zero, positive, negative)
;
; Registers changed after return:
; ..BCDEHL/IXIY same
; AF....../.... different
;
.sgn ld a,h
or l
ld a,2
ret z ; integer is zero, return 0...
bit 7,h
jr nz,negative_int
dec a ; 1
ret
.negative_int ld a,-1
ret
; ******************************************************************************
;
; ABS (Absolute value) of 16 bit signed integer.
;
; IN: HL = integer
; OUT: HL = converted integer
;
; Registers changed after return:
; A.BCDE../IXIY same
; .F....HL/.... different
;
.abs bit 7,h
ret z ; integer is positive...
push de
ex de,hl
xor a ; Fc=0
ld h,a
ld l,a
sbc hl,de ; convert negative integer
pop de
ret
|
.global s_prepare_buffers
s_prepare_buffers:
push %r13
push %r15
push %r8
push %rax
push %rbx
push %rcx
push %rdi
push %rsi
lea addresses_WC_ht+0x1c953, %rdi
inc %rsi
movl $0x61626364, (%rdi)
nop
nop
nop
nop
nop
xor %rbx, %rbx
lea addresses_D_ht+0x8a53, %r15
nop
nop
cmp %rdi, %rdi
vmovups (%r15), %ymm3
vextracti128 $0, %ymm3, %xmm3
vpextrq $1, %xmm3, %r13
nop
nop
nop
nop
add $57229, %rdi
lea addresses_normal_ht+0xd993, %rsi
lea addresses_normal_ht+0x3d93, %rdi
nop
nop
xor %r8, %r8
mov $67, %rcx
rep movsl
nop
nop
nop
nop
nop
cmp $48114, %rbx
lea addresses_WC_ht+0x11a53, %rcx
nop
nop
nop
xor $36892, %rsi
mov $0x6162636465666768, %rdi
movq %rdi, %xmm2
movups %xmm2, (%rcx)
nop
nop
dec %r15
lea addresses_WT_ht+0x12353, %rsi
lea addresses_WC_ht+0x14052, %rdi
clflush (%rsi)
nop
nop
nop
inc %rax
mov $45, %rcx
rep movsb
nop
nop
nop
nop
and %r15, %r15
lea addresses_WT_ht+0x105e3, %rbx
nop
add %r15, %r15
mov $0x6162636465666768, %rdi
movq %rdi, (%rbx)
nop
nop
nop
sub %rbx, %rbx
pop %rsi
pop %rdi
pop %rcx
pop %rbx
pop %rax
pop %r8
pop %r15
pop %r13
ret
.global s_faulty_load
s_faulty_load:
push %r12
push %r15
push %r9
push %rax
push %rbx
// Faulty Load
mov $0x6fb2a50000000653, %rax
nop
nop
inc %r12
mov (%rax), %r9d
lea oracles, %r12
and $0xff, %r9
shlq $12, %r9
mov (%r12,%r9,1), %r9
pop %rbx
pop %rax
pop %r9
pop %r15
pop %r12
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'same': False, 'NT': False, 'AVXalign': False, 'size': 2, 'type': 'addresses_NC', 'congruent': 0}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'same': True, 'NT': True, 'AVXalign': False, 'size': 4, 'type': 'addresses_NC', 'congruent': 0}}
<gen_prepare_buffer>
{'dst': {'same': False, 'NT': False, 'AVXalign': True, 'size': 4, 'type': 'addresses_WC_ht', 'congruent': 8}, 'OP': 'STOR'}
{'OP': 'LOAD', 'src': {'same': True, 'NT': False, 'AVXalign': False, 'size': 32, 'type': 'addresses_D_ht', 'congruent': 9}}
{'dst': {'same': False, 'congruent': 6, 'type': 'addresses_normal_ht'}, 'OP': 'REPM', 'src': {'same': False, 'congruent': 4, 'type': 'addresses_normal_ht'}}
{'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 16, 'type': 'addresses_WC_ht', 'congruent': 9}, 'OP': 'STOR'}
{'dst': {'same': True, 'congruent': 0, 'type': 'addresses_WC_ht'}, 'OP': 'REPM', 'src': {'same': False, 'congruent': 8, 'type': 'addresses_WT_ht'}}
{'dst': {'same': False, 'NT': False, 'AVXalign': False, 'size': 8, 'type': 'addresses_WT_ht', 'congruent': 3}, '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
*/
|
/*
==============================================================================
This file is part of the iPlug 2 library. Copyright (C) the iPlug 2 developers.
See LICENSE.txt for more info.
==============================================================================
*/
#include <cstring>
#include <cstdio>
#include <emscripten/key_codes.h>
#include "IGraphicsWeb.h"
BEGIN_IPLUG_NAMESPACE
BEGIN_IGRAPHICS_NAMESPACE
void GetScreenDimensions(int& width, int& height)
{
width = val::global("window")["innerWidth"].as<int>();
height = val::global("window")["innerHeight"].as<int>();
}
float GetScaleForScreen(int height)
{
return 1.f;
}
END_IPLUG_NAMESPACE
END_IGRAPHICS_NAMESPACE
using namespace iplug;
using namespace igraphics;
using namespace emscripten;
extern IGraphicsWeb* gGraphics;
double gPrevMouseDownTime = 0.;
bool gFirstClick = false;
#pragma mark - Private Classes and Structs
// Fonts
class IGraphicsWeb::Font : public PlatformFont
{
public:
Font(const char* fontName, const char* fontStyle)
: PlatformFont(true), mDescriptor{fontName, fontStyle}
{}
FontDescriptor GetDescriptor() override { return &mDescriptor; }
private:
std::pair<WDL_String, WDL_String> mDescriptor;
};
class IGraphicsWeb::FileFont : public Font
{
public:
FileFont(const char* fontName, const char* fontStyle, const char* fontPath)
: Font(fontName, fontStyle), mPath(fontPath)
{
mSystem = false;
}
IFontDataPtr GetFontData() override;
private:
WDL_String mPath;
};
IFontDataPtr IGraphicsWeb::FileFont::GetFontData()
{
IFontDataPtr fontData(new IFontData());
FILE* fp = fopen(mPath.Get(), "rb");
// Read in the font data.
if (!fp)
return fontData;
fseek(fp,0,SEEK_END);
fontData = std::make_unique<IFontData>((int) ftell(fp));
if (!fontData->GetSize())
return fontData;
fseek(fp,0,SEEK_SET);
size_t readSize = fread(fontData->Get(), 1, fontData->GetSize(), fp);
fclose(fp);
if (readSize && readSize == fontData->GetSize())
fontData->SetFaceIdx(0);
return fontData;
}
#pragma mark - Utilities and Callbacks
// Key combos
static int domVKToWinVK(int dom_vk_code)
{
switch(dom_vk_code)
{
// case DOM_VK_CANCEL: return 0; // TODO
case DOM_VK_HELP: return kVK_HELP;
case DOM_VK_BACK_SPACE: return kVK_BACK;
case DOM_VK_TAB: return kVK_TAB;
case DOM_VK_CLEAR: return kVK_CLEAR;
case DOM_VK_RETURN: return kVK_RETURN;
case DOM_VK_ENTER: return kVK_RETURN;
case DOM_VK_SHIFT: return kVK_SHIFT;
case DOM_VK_CONTROL: return kVK_CONTROL;
case DOM_VK_ALT: return kVK_MENU;
case DOM_VK_PAUSE: return kVK_PAUSE;
case DOM_VK_CAPS_LOCK: return kVK_CAPITAL;
case DOM_VK_ESCAPE: return kVK_ESCAPE;
// case DOM_VK_CONVERT: return 0; // TODO
// case DOM_VK_NONCONVERT: return 0; // TODO
// case DOM_VK_ACCEPT: return 0; // TODO
// case DOM_VK_MODECHANGE: return 0; // TODO
case DOM_VK_SPACE: return kVK_SPACE;
case DOM_VK_PAGE_UP: return kVK_PRIOR;
case DOM_VK_PAGE_DOWN: return kVK_NEXT;
case DOM_VK_END: return kVK_END;
case DOM_VK_HOME: return kVK_HOME;
case DOM_VK_LEFT: return kVK_LEFT;
case DOM_VK_UP: return kVK_UP;
case DOM_VK_RIGHT: return kVK_RIGHT;
case DOM_VK_DOWN: return kVK_DOWN;
// case DOM_VK_SELECT: return 0; // TODO
// case DOM_VK_PRINT: return 0; // TODO
// case DOM_VK_EXECUTE: return 0; // TODO
// case DOM_VK_PRINTSCREEN: return 0; // TODO
case DOM_VK_INSERT: return kVK_INSERT;
case DOM_VK_DELETE: return kVK_DELETE;
case DOM_VK_0: return kVK_0;
case DOM_VK_1: return kVK_1;
case DOM_VK_2: return kVK_2;
case DOM_VK_3: return kVK_3;
case DOM_VK_4: return kVK_4;
case DOM_VK_5: return kVK_5;
case DOM_VK_6: return kVK_6;
case DOM_VK_7: return kVK_7;
case DOM_VK_8: return kVK_8;
case DOM_VK_9: return kVK_9;
// case DOM_VK_COLON: return 0; // TODO
// case DOM_VK_SEMICOLON: return 0; // TODO
// case DOM_VK_LESS_THAN: return 0; // TODO
// case DOM_VK_EQUALS: return 0; // TODO
// case DOM_VK_GREATER_THAN: return 0; // TODO
// case DOM_VK_QUESTION_MARK: return 0; // TODO
// case DOM_VK_AT: return 0; // TODO
case DOM_VK_A: return kVK_A;
case DOM_VK_B: return kVK_B;
case DOM_VK_C: return kVK_C;
case DOM_VK_D: return kVK_D;
case DOM_VK_E: return kVK_E;
case DOM_VK_F: return kVK_F;
case DOM_VK_G: return kVK_G;
case DOM_VK_H: return kVK_H;
case DOM_VK_I: return kVK_I;
case DOM_VK_J: return kVK_J;
case DOM_VK_K: return kVK_K;
case DOM_VK_L: return kVK_L;
case DOM_VK_M: return kVK_M;
case DOM_VK_N: return kVK_N;
case DOM_VK_O: return kVK_O;
case DOM_VK_P: return kVK_P;
case DOM_VK_Q: return kVK_Q;
case DOM_VK_R: return kVK_R;
case DOM_VK_S: return kVK_S;
case DOM_VK_T: return kVK_T;
case DOM_VK_U: return kVK_U;
case DOM_VK_V: return kVK_V;
case DOM_VK_W: return kVK_W;
case DOM_VK_X: return kVK_X;
case DOM_VK_Y: return kVK_Y;
case DOM_VK_Z: return kVK_Z;
// case DOM_VK_WIN: return 0; // TODO
// case DOM_VK_CONTEXT_MENU: return 0; // TODO
// case DOM_VK_SLEEP: return 0; // TODO
case DOM_VK_NUMPAD0: return kVK_NUMPAD0;
case DOM_VK_NUMPAD1: return kVK_NUMPAD1;
case DOM_VK_NUMPAD2: return kVK_NUMPAD2;
case DOM_VK_NUMPAD3: return kVK_NUMPAD3;
case DOM_VK_NUMPAD4: return kVK_NUMPAD4;
case DOM_VK_NUMPAD5: return kVK_NUMPAD5;
case DOM_VK_NUMPAD6: return kVK_NUMPAD6;
case DOM_VK_NUMPAD7: return kVK_NUMPAD7;
case DOM_VK_NUMPAD8: return kVK_NUMPAD8;
case DOM_VK_NUMPAD9: return kVK_NUMPAD9;
case DOM_VK_MULTIPLY: return kVK_MULTIPLY;
case DOM_VK_ADD: return kVK_ADD;
case DOM_VK_SEPARATOR: return kVK_SEPARATOR;
case DOM_VK_SUBTRACT: return kVK_SUBTRACT;
case DOM_VK_DECIMAL: return kVK_DECIMAL;
case DOM_VK_DIVIDE: return kVK_DIVIDE;
case DOM_VK_F1: return kVK_F1;
case DOM_VK_F2: return kVK_F2;
case DOM_VK_F3: return kVK_F3;
case DOM_VK_F4: return kVK_F4;
case DOM_VK_F5: return kVK_F5;
case DOM_VK_F6: return kVK_F6;
case DOM_VK_F7: return kVK_F7;
case DOM_VK_F8: return kVK_F8;
case DOM_VK_F9: return kVK_F9;
case DOM_VK_F10: return kVK_F10;
case DOM_VK_F11: return kVK_F11;
case DOM_VK_F12: return kVK_F12;
case DOM_VK_F13: return kVK_F13;
case DOM_VK_F14: return kVK_F14;
case DOM_VK_F15: return kVK_F15;
case DOM_VK_F16: return kVK_F16;
case DOM_VK_F17: return kVK_F17;
case DOM_VK_F18: return kVK_F18;
case DOM_VK_F19: return kVK_F19;
case DOM_VK_F20: return kVK_F20;
case DOM_VK_F21: return kVK_F21;
case DOM_VK_F22: return kVK_F22;
case DOM_VK_F23: return kVK_F23;
case DOM_VK_F24: return kVK_F24;
case DOM_VK_NUM_LOCK: return kVK_NUMLOCK;
case DOM_VK_SCROLL_LOCK: return kVK_SCROLL;
// case DOM_VK_WIN_OEM_FJ_JISHO: return 0; // TODO
// case DOM_VK_WIN_OEM_FJ_MASSHOU: return 0; // TODO
// case DOM_VK_WIN_OEM_FJ_TOUROKU: return 0; // TODO
// case DOM_VK_WIN_OEM_FJ_LOYA: return 0; // TODO
// case DOM_VK_WIN_OEM_FJ_ROYA: return 0; // TODO
// case DOM_VK_CIRCUMFLEX: return 0; // TODO
// case DOM_VK_EXCLAMATION: return 0; // TODO
// case DOM_VK_HASH: return 0; // TODO
// case DOM_VK_DOLLAR: return 0; // TODO
// case DOM_VK_PERCENT: return 0; // TODO
// case DOM_VK_AMPERSAND: return 0; // TODO
// case DOM_VK_UNDERSCORE: return 0; // TODO
// case DOM_VK_OPEN_PAREN: return 0; // TODO
// case DOM_VK_CLOSE_PAREN: return 0; // TODO
// case DOM_VK_ASTERISK: return 0; // TODO
// case DOM_VK_PLUS: return 0; // TODO
// case DOM_VK_PIPE: return 0; // TODO
// case DOM_VK_HYPHEN_MINUS: return 0; // TODO
// case DOM_VK_OPEN_CURLY_BRACKET: return 0; // TODO
// case DOM_VK_CLOSE_CURLY_BRACKET: return 0; // TODO
// case DOM_VK_TILDE: return 0; // TODO
// case DOM_VK_VOLUME_MUTE: return 0; // TODO
// case DOM_VK_VOLUME_DOWN: return 0; // TODO
// case DOM_VK_VOLUME_UP: return 0; // TODO
// case DOM_VK_COMMA: return 0; // TODO
// case DOM_VK_PERIOD: return 0; // TODO
// case DOM_VK_SLASH: return 0; // TODO
// case DOM_VK_BACK_QUOTE: return 0; // TODO
// case DOM_VK_OPEN_BRACKET: return 0; // TODO
// case DOM_VK_BACK_SLASH: return 0; // TODO
// case DOM_VK_CLOSE_BRACKET: return 0; // TODO
// case DOM_VK_QUOTE: return 0; // TODO
// case DOM_VK_META: return 0; // TODO
// case DOM_VK_ALTGR: return 0; // TODO
// case DOM_VK_WIN_ICO_HELP: return 0; // TODO
// case DOM_VK_WIN_ICO_00: return 0; // TODO
// case DOM_VK_WIN_ICO_CLEAR: return 0; // TODO
// case DOM_VK_WIN_OEM_RESET: return 0; // TODO
// case DOM_VK_WIN_OEM_JUMP: return 0; // TODO
// case DOM_VK_WIN_OEM_PA1: return 0; // TODO
// case DOM_VK_WIN_OEM_PA2: return 0; // TODO
// case DOM_VK_WIN_OEM_PA3: return 0; // TODO
// case DOM_VK_WIN_OEM_WSCTRL: return 0; // TODO
// case DOM_VK_WIN_OEM_CUSEL: return 0; // TODO
// case DOM_VK_WIN_OEM_ATTN: return 0; // TODO
// case DOM_VK_WIN_OEM_FINISH: return 0; // TODO
// case DOM_VK_WIN_OEM_COPY: return 0; // TODO
// case DOM_VK_WIN_OEM_AUTO: return 0; // TODO
// case DOM_VK_WIN_OEM_ENLW: return 0; // TODO
// case DOM_VK_WIN_OEM_BACKTAB: return 0; // TODO
// case DOM_VK_ATTN: return 0; // TODO
// case DOM_VK_CRSEL: return 0; // TODO
// case DOM_VK_EXSEL: return 0; // TODO
// case DOM_VK_EREOF: return 0; // TODO
// case DOM_VK_PLAY: return 0; // TODO
// case DOM_VK_ZOOM: return 0; // TODO
// case DOM_VK_PA1: return 0; // TODO
// case DOM_VK_WIN_OEM_CLEAR: return 0; // TODO
default: return kVK_NONE;
}
}
static EM_BOOL key_callback(int eventType, const EmscriptenKeyboardEvent* pEvent, void* pUserData)
{
IGraphicsWeb* pGraphicsWeb = (IGraphicsWeb*) pUserData;
int VK = domVKToWinVK(pEvent->keyCode);
WDL_String keyUTF8;
// filter utf8 for non ascii keys
if((VK >= kVK_0 && VK <= kVK_Z) || VK == kVK_NONE)
keyUTF8.Set(pEvent->key);
else
keyUTF8.Set("");
IKeyPress keyPress {keyUTF8.Get(),
domVKToWinVK(pEvent->keyCode),
static_cast<bool>(pEvent->shiftKey),
static_cast<bool>(pEvent->ctrlKey || pEvent->metaKey),
static_cast<bool>(pEvent->altKey)};
switch (eventType)
{
case EMSCRIPTEN_EVENT_KEYDOWN:
{
return pGraphicsWeb->OnKeyDown(pGraphicsWeb->mPrevX, pGraphicsWeb->mPrevY, keyPress);
}
case EMSCRIPTEN_EVENT_KEYUP:
{
return pGraphicsWeb->OnKeyUp(pGraphicsWeb->mPrevX, pGraphicsWeb->mPrevY, keyPress);
}
default:
break;
}
return 0;
}
static EM_BOOL outside_mouse_callback(int eventType, const EmscriptenMouseEvent* pEvent, void* pUserData)
{
IGraphicsWeb* pGraphics = (IGraphicsWeb*) pUserData;
IMouseInfo info;
val rect = GetCanvas().call<val>("getBoundingClientRect");
info.x = (pEvent->targetX - rect["left"].as<double>()) / pGraphics->GetDrawScale();
info.y = (pEvent->targetY - rect["top"].as<double>()) / pGraphics->GetDrawScale();
info.dX = pEvent->movementX;
info.dY = pEvent->movementY;
info.ms = {pEvent->buttons == 1, pEvent->buttons == 2, static_cast<bool>(pEvent->shiftKey), static_cast<bool>(pEvent->ctrlKey), static_cast<bool>(pEvent->altKey)};
std::vector<IMouseInfo> list {info};
switch (eventType)
{
case EMSCRIPTEN_EVENT_MOUSEUP:
pGraphics->OnMouseUp(list);
emscripten_set_mousemove_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, pGraphics, 1, nullptr);
emscripten_set_mouseup_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, pGraphics, 1, nullptr);
break;
case EMSCRIPTEN_EVENT_MOUSEMOVE:
if(pEvent->buttons != 0 && !pGraphics->IsInPlatformTextEntry())
pGraphics->OnMouseDrag(list);
break;
default:
break;
}
pGraphics->mPrevX = info.x;
pGraphics->mPrevY = info.y;
return true;
}
static EM_BOOL mouse_callback(int eventType, const EmscriptenMouseEvent* pEvent, void* pUserData)
{
IGraphicsWeb* pGraphics = (IGraphicsWeb*) pUserData;
IMouseInfo info;
info.x = pEvent->targetX / pGraphics->GetDrawScale();
info.y = pEvent->targetY / pGraphics->GetDrawScale();
info.dX = pEvent->movementX;
info.dY = pEvent->movementY;
info.ms = {pEvent->buttons == 1,
pEvent->buttons == 2,
static_cast<bool>(pEvent->shiftKey),
static_cast<bool>(pEvent->ctrlKey),
static_cast<bool>(pEvent->altKey)};
std::vector<IMouseInfo> list {info};
switch (eventType)
{
case EMSCRIPTEN_EVENT_MOUSEDOWN:
{
const double timestamp = GetTimestamp();
const double timeDiff = timestamp - gPrevMouseDownTime;
if (gFirstClick && timeDiff < 0.3)
{
gFirstClick = false;
pGraphics->OnMouseDblClick(info.x, info.y, info.ms);
}
else
{
gFirstClick = true;
pGraphics->OnMouseDown(list);
}
gPrevMouseDownTime = timestamp;
break;
}
case EMSCRIPTEN_EVENT_MOUSEUP: pGraphics->OnMouseUp(list); break;
case EMSCRIPTEN_EVENT_MOUSEMOVE:
{
gFirstClick = false;
if(pEvent->buttons == 0)
pGraphics->OnMouseOver(info.x, info.y, info.ms);
else
{
if(!pGraphics->IsInPlatformTextEntry())
pGraphics->OnMouseDrag(list);
}
break;
}
case EMSCRIPTEN_EVENT_MOUSEENTER:
pGraphics->OnSetCursor();
pGraphics->OnMouseOver(info.x, info.y, info.ms);
emscripten_set_mousemove_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, pGraphics, 1, nullptr);
break;
case EMSCRIPTEN_EVENT_MOUSELEAVE:
if(pEvent->buttons != 0)
{
emscripten_set_mousemove_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, pGraphics, 1, outside_mouse_callback);
emscripten_set_mouseup_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, pGraphics, 1, outside_mouse_callback);
}
pGraphics->OnMouseOut(); break;
default:
break;
}
pGraphics->mPrevX = info.x;
pGraphics->mPrevY = info.y;
return true;
}
static EM_BOOL wheel_callback(int eventType, const EmscriptenWheelEvent* pEvent, void* pUserData)
{
IGraphics* pGraphics = (IGraphics*) pUserData;
IMouseMod modifiers(0, 0, pEvent->mouse.shiftKey, pEvent->mouse.ctrlKey, pEvent->mouse.altKey);
double x = pEvent->mouse.targetX;
double y = pEvent->mouse.targetY;
x /= pGraphics->GetDrawScale();
y /= pGraphics->GetDrawScale();
switch (eventType) {
case EMSCRIPTEN_EVENT_WHEEL: pGraphics->OnMouseWheel(x, y, modifiers, pEvent->deltaY);
default:
break;
}
return true;
}
EM_BOOL touch_callback(int eventType, const EmscriptenTouchEvent* pEvent, void* pUserData)
{
IGraphics* pGraphics = (IGraphics*) pUserData;
const float drawScale = pGraphics->GetDrawScale();
std::vector<IMouseInfo> points;
static EmscriptenTouchPoint previousTouches[32];
for (auto i = 0; i < pEvent->numTouches; i++)
{
IMouseInfo info;
info.x = pEvent->touches[i].targetX / drawScale;
info.y = pEvent->touches[i].targetY / drawScale;
info.dX = info.x - (previousTouches[i].targetX / drawScale);
info.dY = info.y - (previousTouches[i].targetY / drawScale);
info.ms = {true,
false,
static_cast<bool>(pEvent->shiftKey),
static_cast<bool>(pEvent->ctrlKey),
static_cast<bool>(pEvent->altKey),
static_cast<ITouchID>(pEvent->touches[i].identifier)
};
if(pEvent->touches[i].isChanged)
points.push_back(info);
}
memcpy(previousTouches, pEvent->touches, sizeof(previousTouches));
switch (eventType)
{
case EMSCRIPTEN_EVENT_TOUCHSTART:
pGraphics->OnMouseDown(points);
return true;
case EMSCRIPTEN_EVENT_TOUCHEND:
pGraphics->OnMouseUp(points);
return true;
case EMSCRIPTEN_EVENT_TOUCHMOVE:
pGraphics->OnMouseDrag(points);
return true;
case EMSCRIPTEN_EVENT_TOUCHCANCEL:
pGraphics->OnTouchCancelled(points);
return true;
default:
return false;
}
}
static EM_BOOL complete_text_entry(int eventType, const EmscriptenFocusEvent* focusEvent, void* pUserData)
{
IGraphicsWeb* pGraphics = (IGraphicsWeb*) pUserData;
val input = val::global("document").call<val>("getElementById", std::string("textEntry"));
std::string str = input["value"].as<std::string>();
val::global("document")["body"].call<void>("removeChild", input);
pGraphics->SetControlValueAfterTextEdit(str.c_str());
return true;
}
static EM_BOOL text_entry_keydown(int eventType, const EmscriptenKeyboardEvent* pEvent, void* pUserData)
{
IGraphicsWeb* pGraphicsWeb = (IGraphicsWeb*) pUserData;
IKeyPress keyPress {pEvent->key, domVKToWinVK(pEvent->keyCode),
static_cast<bool>(pEvent->shiftKey),
static_cast<bool>(pEvent->ctrlKey),
static_cast<bool>(pEvent->altKey)};
if (keyPress.VK == kVK_RETURN || keyPress.VK == kVK_TAB)
return complete_text_entry(0, nullptr, pUserData);
return false;
}
static EM_BOOL uievent_callback(int eventType, const EmscriptenUiEvent* pEvent, void* pUserData)
{
IGraphicsWeb* pGraphics = (IGraphicsWeb*) pUserData;
if (eventType == EMSCRIPTEN_EVENT_RESIZE)
{
pGraphics->GetDelegate()->OnParentWindowResize(pEvent->windowInnerWidth, pEvent->windowInnerHeight);
return true;
}
return false;
}
IColorPickerHandlerFunc gColorPickerHandlerFunc = nullptr;
static void color_picker_callback(val e)
{
if(gColorPickerHandlerFunc)
{
std::string colorStrHex = e["target"]["value"].as<std::string>();
if (colorStrHex[0] == '#')
colorStrHex = colorStrHex.erase(0, 1);
IColor result;
result.A = 255;
sscanf(colorStrHex.c_str(), "%02x%02x%02x", &result.R, &result.G, &result.B);
gColorPickerHandlerFunc(result);
}
}
static void file_dialog_callback(val e)
{
// DBGMSG(e["files"].as<std::string>().c_str());
}
EMSCRIPTEN_BINDINGS(events) {
function("color_picker_callback", color_picker_callback);
function("file_dialog_callback", file_dialog_callback);
}
#pragma mark -
IGraphicsWeb::IGraphicsWeb(IGEditorDelegate& dlg, int w, int h, int fps, float scale)
: IGRAPHICS_DRAW_CLASS(dlg, w, h, fps, scale)
{
val keys = val::global("Object").call<val>("keys", GetPreloadedImages());
DBGMSG("Preloaded %i images\n", keys["length"].as<int>());
emscripten_set_mousedown_callback("#canvas", this, 1, mouse_callback);
emscripten_set_mouseup_callback("#canvas", this, 1, mouse_callback);
emscripten_set_mousemove_callback("#canvas", this, 1, mouse_callback);
emscripten_set_mouseenter_callback("#canvas", this, 1, mouse_callback);
emscripten_set_mouseleave_callback("#canvas", this, 1, mouse_callback);
emscripten_set_wheel_callback("#canvas", this, 1, wheel_callback);
emscripten_set_keydown_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, this, 1, key_callback);
emscripten_set_keyup_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, this, 1, key_callback);
emscripten_set_touchstart_callback("#canvas", this, 1, touch_callback);
emscripten_set_touchend_callback("#canvas", this, 1, touch_callback);
emscripten_set_touchmove_callback("#canvas", this, 1, touch_callback);
emscripten_set_touchcancel_callback("#canvas", this, 1, touch_callback);
emscripten_set_resize_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, this, 1, uievent_callback);
}
IGraphicsWeb::~IGraphicsWeb()
{
}
void* IGraphicsWeb::OpenWindow(void* pHandle)
{
#ifdef IGRAPHICS_GL
EmscriptenWebGLContextAttributes attr;
emscripten_webgl_init_context_attributes(&attr);
attr.stencil = true;
attr.depth = true;
// attr.explicitSwapControl = 1;
EMSCRIPTEN_WEBGL_CONTEXT_HANDLE ctx = emscripten_webgl_create_context("#canvas", &attr);
emscripten_webgl_make_context_current(ctx);
#endif
OnViewInitialized(nullptr /* not used */);
SetScreenScale(std::ceil(std::max(emscripten_get_device_pixel_ratio(), 1.)));
GetDelegate()->LayoutUI(this);
GetDelegate()->OnUIOpen();
return nullptr;
}
void IGraphicsWeb::HideMouseCursor(bool hide, bool lock)
{
if (hide)
{
#ifdef IGRAPHICS_WEB_POINTERLOCK
if (lock)
emscripten_request_pointerlock("#canvas", EM_FALSE);
else
#endif
val::global("document")["body"]["style"].set("cursor", "none");
mCursorLock = lock;
}
else
{
#ifdef IGRAPHICS_WEB_POINTERLOCK
if (mCursorLock)
emscripten_exit_pointerlock();
else
#endif
OnSetCursor();
mCursorLock = false;
}
}
ECursor IGraphicsWeb::SetMouseCursor(ECursor cursorType)
{
std::string cursor("pointer");
switch (cursorType)
{
case ECursor::ARROW: cursor = "default"; break;
case ECursor::IBEAM: cursor = "text"; break;
case ECursor::WAIT: cursor = "wait"; break;
case ECursor::CROSS: cursor = "crosshair"; break;
case ECursor::UPARROW: cursor = "n-resize"; break;
case ECursor::SIZENWSE: cursor = "nwse-resize"; break;
case ECursor::SIZENESW: cursor = "nesw-resize"; break;
case ECursor::SIZEWE: cursor = "ew-resize"; break;
case ECursor::SIZENS: cursor = "ns-resize"; break;
case ECursor::SIZEALL: cursor = "move"; break;
case ECursor::INO: cursor = "not-allowed"; break;
case ECursor::HAND: cursor = "pointer"; break;
case ECursor::APPSTARTING: cursor = "progress"; break;
case ECursor::HELP: cursor = "help"; break;
}
val::global("document")["body"]["style"].set("cursor", cursor);
return IGraphics::SetMouseCursor(cursorType);
}
void IGraphicsWeb::GetMouseLocation(float& x, float&y) const
{
x = mPrevX;
y = mPrevY;
}
//static
void IGraphicsWeb::OnMainLoopTimer()
{
IRECTList rects;
int screenScale = (int) std::ceil(std::max(emscripten_get_device_pixel_ratio(), 1.));
// Don't draw if there are no graphics or if assets are still loading
if (!gGraphics || !gGraphics->AssetsLoaded())
return;
if (screenScale != gGraphics->GetScreenScale())
{
gGraphics->SetScreenScale(screenScale);
}
if (gGraphics->IsDirty(rects))
{
gGraphics->SetAllControlsClean();
gGraphics->Draw(rects);
}
}
bool IGraphicsWeb::GetTextFromClipboard(WDL_String& str)
{
val clipboardText = val::global("window")["clipboardData"].call<val>("getData", std::string("Text"));
str.Set(clipboardText.as<std::string>().c_str());
return true; // TODO: return?
}
EMsgBoxResult IGraphicsWeb::ShowMessageBox(const char* str, const char* caption, EMsgBoxType type, IMsgBoxCompletionHanderFunc completionHandler)
{
ReleaseMouseCapture();
EMsgBoxResult result = kNoResult;
switch (type)
{
case kMB_OK:
{
val::global("window").call<val>("alert", std::string(str));
result = EMsgBoxResult::kOK;
break;
}
case kMB_YESNO:
case kMB_OKCANCEL:
{
result = static_cast<EMsgBoxResult>(val::global("window").call<val>("confirm", std::string(str)).as<int>());
}
// case MB_CANCEL:
// break;
default:
return result = kNoResult;
}
if(completionHandler)
completionHandler(result);
return result;
}
void IGraphicsWeb::PromptForFile(WDL_String& filename, WDL_String& path, EFileAction action, const char* ext)
{
//TODO
// val inputEl = val::global("document").call<val>("createElement", std::string("input"));
// inputEl.call<void>("setAttribute", std::string("type"), std::string("file"));
// inputEl.call<void>("setAttribute", std::string("accept"), std::string(ext));
// inputEl.call<void>("click");
// inputEl.call<void>("addEventListener", std::string("input"), val::module_property("file_dialog_callback"), false);
// inputEl.call<void>("addEventListener", std::string("onChange"), val::module_property("file_dialog_callback"), false);
}
void IGraphicsWeb::PromptForDirectory(WDL_String& path)
{
//TODO
// val inputEl = val::global("document").call<val>("createElement", std::string("input"));
// inputEl.call<void>("setAttribute", std::string("type"), std::string("file"));
// inputEl.call<void>("setAttribute", std::string("directory"), true);
// inputEl.call<void>("setAttribute", std::string("webkitdirectory"), true);
// inputEl.call<void>("click");
// inputEl.call<void>("addEventListener", std::string("input"), val::module_property("file_dialog_callback"), false);
// inputEl.call<void>("addEventListener", std::string("onChange"), val::module_property("file_dialog_callback"), false);
}
bool IGraphicsWeb::PromptForColor(IColor& color, const char* str, IColorPickerHandlerFunc func)
{
ReleaseMouseCapture();
gColorPickerHandlerFunc = func;
val inputEl = val::global("document").call<val>("createElement", std::string("input"));
inputEl.call<void>("setAttribute", std::string("type"), std::string("color"));
WDL_String colorStr;
colorStr.SetFormatted(64, "#%02x%02x%02x", color.R, color.G, color.B);
inputEl.call<void>("setAttribute", std::string("value"), std::string(colorStr.Get()));
inputEl.call<void>("click");
inputEl.call<void>("addEventListener", std::string("input"), val::module_property("color_picker_callback"), false);
inputEl.call<void>("addEventListener", std::string("onChange"), val::module_property("color_picker_callback"), false);
return false;
}
void IGraphicsWeb::CreatePlatformTextEntry(int paramIdx, const IText& text, const IRECT& bounds, int length, const char* str)
{
val input = val::global("document").call<val>("createElement", std::string("input"));
val rect = GetCanvas().call<val>("getBoundingClientRect");
auto setDim = [&input](const char *dimName, double pixels)
{
WDL_String dimstr;
dimstr.SetFormatted(32, "%fpx", pixels);
input["style"].set(dimName, std::string(dimstr.Get()));
};
auto setColor = [&input](const char *colorName, IColor color)
{
WDL_String str;
str.SetFormatted(64, "rgba(%d, %d, %d, %d)", color.R, color.G, color.B, color.A);
input["style"].set(colorName, std::string(str.Get()));
};
input.set("id", std::string("textEntry"));
input["style"].set("position", val("fixed"));
setDim("left", rect["left"].as<double>() + bounds.L);
setDim("top", rect["top"].as<double>() + bounds.T);
setDim("width", bounds.W());
setDim("height", bounds.H());
setColor("color", text.mTextEntryFGColor);
setColor("background-color", text.mTextEntryBGColor);
if (paramIdx > kNoParameter)
{
const IParam* pParam = GetDelegate()->GetParam(paramIdx);
switch (pParam->Type())
{
case IParam::kTypeEnum:
case IParam::kTypeInt:
case IParam::kTypeBool:
input.set("type", val("number")); // TODO
break;
case IParam::kTypeDouble:
input.set("type", val("number"));
break;
default:
break;
}
}
else
{
input.set("type", val("text"));
}
val::global("document")["body"].call<void>("appendChild", input);
input.call<void>("focus");
emscripten_set_focusout_callback("textEntry", this, 1, complete_text_entry);
emscripten_set_keydown_callback("textEntry", this, 1, text_entry_keydown);
}
IPopupMenu* IGraphicsWeb::CreatePlatformPopupMenu(IPopupMenu& menu, const IRECT& bounds, bool& isAsync)
{
return nullptr;
}
bool IGraphicsWeb::OpenURL(const char* url, const char* msgWindowTitle, const char* confirmMsg, const char* errMsgOnFailure)
{
val::global("window").call<val>("open", std::string(url), std::string("_blank"));
return true;
}
void IGraphicsWeb::DrawResize()
{
val canvas = GetCanvas();
canvas["style"].set("width", val(Width() * GetDrawScale()));
canvas["style"].set("height", val(Height() * GetDrawScale()));
canvas.set("width", Width() * GetBackingPixelScale());
canvas.set("height", Height() * GetBackingPixelScale());
IGRAPHICS_DRAW_CLASS::DrawResize();
}
PlatformFontPtr IGraphicsWeb::LoadPlatformFont(const char* fontID, const char* fileNameOrResID)
{
WDL_String fullPath;
const EResourceLocation fontLocation = LocateResource(fileNameOrResID, "ttf", fullPath, GetBundleID(), nullptr, nullptr);
if (fontLocation == kNotFound)
return nullptr;
return PlatformFontPtr(new FileFont(fontID, "", fullPath.Get()));
}
PlatformFontPtr IGraphicsWeb::LoadPlatformFont(const char* fontID, const char* fontName, ETextStyle style)
{
const char* styles[] = { "normal", "bold", "italic" };
return PlatformFontPtr(new Font(fontName, styles[static_cast<int>(style)]));
}
#if defined IGRAPHICS_CANVAS
#include "IGraphicsCanvas.cpp"
#elif defined IGRAPHICS_NANOVG
#include "IGraphicsNanoVG.cpp"
#ifdef IGRAPHICS_FREETYPE
#define FONS_USE_FREETYPE
#endif
#include "nanovg.c"
#endif
|
/*
*
* Copyright (c) 2020 Project CHIP Authors
* Copyright (c) 2019 Nest Labs, 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.
*/
/**
* @file
* Contains non-inline method definitions for the
* GenericThreadStackManagerImpl_OpenThread<> template.
*/
#ifndef GENERIC_THREAD_STACK_MANAGER_IMPL_OPENTHREAD_IPP
#define GENERIC_THREAD_STACK_MANAGER_IMPL_OPENTHREAD_IPP
#include <cassert>
#include <openthread/cli.h>
#include <openthread/dataset.h>
#include <openthread/joiner.h>
#include <openthread/link.h>
#include <openthread/netdata.h>
#include <openthread/tasklet.h>
#include <openthread/thread.h>
#if CHIP_DEVICE_CONFIG_THREAD_FTD
#include <openthread/dataset_ftd.h>
#include <openthread/thread_ftd.h>
#endif
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT
#include <openthread/srp_client.h>
#endif
#include <app/AttributeAccessInterface.h>
#include <app/clusters/network-commissioning/network-commissioning.h>
#include <lib/core/CHIPEncoding.h>
#include <lib/support/CHIPMemString.h>
#include <lib/support/CodeUtils.h>
#include <lib/support/FixedBufferAllocator.h>
#include <lib/support/ThreadOperationalDataset.h>
#include <lib/support/logging/CHIPLogging.h>
#include <platform/OpenThread/GenericNetworkCommissioningThreadDriver.h>
#include <platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.h>
#include <platform/OpenThread/OpenThreadUtils.h>
#include <platform/ThreadStackManager.h>
#include <platform/internal/CHIPDeviceLayerInternal.h>
#include <app-common/zap-generated/ids/Attributes.h>
#include <app-common/zap-generated/ids/Clusters.h>
#include <app/MessageDef/AttributeDataIB.h>
#include <app/data-model/Encode.h>
#include <limits>
extern "C" void otSysProcessDrivers(otInstance * aInstance);
#if CHIP_DEVICE_CONFIG_THREAD_ENABLE_CLI
extern "C" void otAppCliInit(otInstance * aInstance);
#endif
using namespace chip::app;
using namespace chip::app::Clusters;
using namespace chip::app::DataModel;
using namespace chip::DeviceLayer::NetworkCommissioning;
using chip::Inet::IPPrefix;
namespace chip {
namespace DeviceLayer {
namespace Internal {
// Network commissioning
namespace {
#ifndef _NO_NETWORK_COMMISSIONING_DRIVER_
NetworkCommissioning::GenericThreadDriver sGenericThreadDriver;
Clusters::NetworkCommissioning::Instance sThreadNetworkCommissioningInstance(0 /* Endpoint Id */, &sGenericThreadDriver);
#endif
void initNetworkCommissioningThreadDriver(void)
{
#ifndef _NO_NETWORK_COMMISSIONING_DRIVER_
sThreadNetworkCommissioningInstance.Init();
#endif
}
NetworkCommissioning::ThreadScanResponse * sScanResult;
otScanResponseIterator<NetworkCommissioning::ThreadScanResponse> mScanResponseIter(sScanResult);
} // namespace
// Fully instantiate the generic implementation class in whatever compilation unit includes this file.
template class GenericThreadStackManagerImpl_OpenThread<ThreadStackManagerImpl>;
/**
* Called by OpenThread to alert the ThreadStackManager of a change in the state of the Thread stack.
*
* By default, applications never need to call this method directly. However, applications that
* wish to receive OpenThread state change call-backs directly from OpenThread (e.g. by calling
* otSetStateChangedCallback() with their own callback function) can call this method to pass
* state change events to the ThreadStackManager.
*/
template <class ImplClass>
void GenericThreadStackManagerImpl_OpenThread<ImplClass>::OnOpenThreadStateChange(uint32_t flags, void * context)
{
ChipDeviceEvent event;
event.Type = DeviceEventType::kThreadStateChange;
event.ThreadStateChange.RoleChanged = (flags & OT_CHANGED_THREAD_ROLE) != 0;
event.ThreadStateChange.AddressChanged = (flags & (OT_CHANGED_IP6_ADDRESS_ADDED | OT_CHANGED_IP6_ADDRESS_REMOVED)) != 0;
event.ThreadStateChange.NetDataChanged = (flags & OT_CHANGED_THREAD_NETDATA) != 0;
event.ThreadStateChange.ChildNodesChanged = (flags & (OT_CHANGED_THREAD_CHILD_ADDED | OT_CHANGED_THREAD_CHILD_REMOVED)) != 0;
event.ThreadStateChange.OpenThread.Flags = flags;
CHIP_ERROR status = PlatformMgr().PostEvent(&event);
if (status != CHIP_NO_ERROR)
{
ChipLogError(DeviceLayer, "Failed to post Thread state change: %" CHIP_ERROR_FORMAT, status.Format());
}
DeviceLayer::SystemLayer().ScheduleLambda([]() { ThreadStackMgrImpl()._UpdateNetworkStatus(); });
}
template <class ImplClass>
void GenericThreadStackManagerImpl_OpenThread<ImplClass>::_ProcessThreadActivity(void)
{
otTaskletsProcess(mOTInst);
otSysProcessDrivers(mOTInst);
}
template <class ImplClass>
bool GenericThreadStackManagerImpl_OpenThread<ImplClass>::_HaveRouteToAddress(const Inet::IPAddress & destAddr)
{
bool res = false;
// Lock OpenThread
Impl()->LockThreadStack();
// No routing of IPv4 over Thread.
VerifyOrExit(!destAddr.IsIPv4(), res = false);
// If the device is attached to a Thread network...
if (IsThreadAttachedNoLock())
{
// Link-local addresses are always presumed to be routable, provided the device is attached.
if (destAddr.IsIPv6LinkLocal())
{
ExitNow(res = true);
}
// Iterate over the routes known to the OpenThread stack looking for a route that covers the
// destination address. If found, consider the address routable.
// Ignore any routes advertised by this device.
// If the destination address is a ULA, ignore default routes. Border routers advertising
// default routes are not expected to be capable of routing CHIP fabric ULAs unless they
// advertise those routes specifically.
{
otError otErr;
otNetworkDataIterator routeIter = OT_NETWORK_DATA_ITERATOR_INIT;
otExternalRouteConfig routeConfig;
const bool destIsULA = destAddr.IsIPv6ULA();
while ((otErr = otNetDataGetNextRoute(Impl()->OTInstance(), &routeIter, &routeConfig)) == OT_ERROR_NONE)
{
const IPPrefix prefix = ToIPPrefix(routeConfig.mPrefix);
char addrStr[64];
prefix.IPAddr.ToString(addrStr);
if (!routeConfig.mNextHopIsThisDevice && (!destIsULA || routeConfig.mPrefix.mLength > 0) &&
ToIPPrefix(routeConfig.mPrefix).MatchAddress(destAddr))
{
ExitNow(res = true);
}
}
}
}
exit:
// Unlock OpenThread
Impl()->UnlockThreadStack();
return res;
}
template <class ImplClass>
void GenericThreadStackManagerImpl_OpenThread<ImplClass>::_OnPlatformEvent(const ChipDeviceEvent * event)
{
if (event->Type == DeviceEventType::kThreadStateChange)
{
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT
if (event->ThreadStateChange.AddressChanged)
{
const otSrpClientHostInfo * hostInfo = otSrpClientGetHostInfo(Impl()->OTInstance());
if (hostInfo && hostInfo->mName)
{
Impl()->_SetupSrpHost(hostInfo->mName);
}
}
#endif
Impl()->LockThreadStack();
#if CHIP_DETAIL_LOGGING
LogOpenThreadStateChange(mOTInst, event->ThreadStateChange.OpenThread.Flags);
#endif // CHIP_DETAIL_LOGGING
Impl()->UnlockThreadStack();
}
}
template <class ImplClass>
bool GenericThreadStackManagerImpl_OpenThread<ImplClass>::_IsThreadEnabled(void)
{
otDeviceRole curRole;
Impl()->LockThreadStack();
curRole = otThreadGetDeviceRole(mOTInst);
Impl()->UnlockThreadStack();
return (curRole != OT_DEVICE_ROLE_DISABLED);
}
template <class ImplClass>
CHIP_ERROR GenericThreadStackManagerImpl_OpenThread<ImplClass>::_SetThreadEnabled(bool val)
{
otError otErr = OT_ERROR_NONE;
Impl()->LockThreadStack();
bool isEnabled = (otThreadGetDeviceRole(mOTInst) != OT_DEVICE_ROLE_DISABLED);
bool isIp6Enabled = otIp6IsEnabled(mOTInst);
if (val && !isIp6Enabled)
{
otErr = otIp6SetEnabled(mOTInst, val);
VerifyOrExit(otErr == OT_ERROR_NONE, );
}
if (val != isEnabled)
{
otErr = otThreadSetEnabled(mOTInst, val);
VerifyOrExit(otErr == OT_ERROR_NONE, );
}
if (!val && isIp6Enabled)
{
otErr = otIp6SetEnabled(mOTInst, val);
VerifyOrExit(otErr == OT_ERROR_NONE, );
}
exit:
Impl()->UnlockThreadStack();
return MapOpenThreadError(otErr);
}
template <class ImplClass>
CHIP_ERROR GenericThreadStackManagerImpl_OpenThread<ImplClass>::_SetThreadProvision(ByteSpan netInfo)
{
otError otErr = OT_ERROR_FAILED;
otOperationalDatasetTlvs tlvs;
assert(netInfo.size() <= Thread::kSizeOperationalDataset);
tlvs.mLength = static_cast<uint8_t>(netInfo.size());
memcpy(tlvs.mTlvs, netInfo.data(), netInfo.size());
// Set the dataset as the active dataset for the node.
Impl()->LockThreadStack();
otErr = otDatasetSetActiveTlvs(mOTInst, &tlvs);
Impl()->UnlockThreadStack();
if (otErr != OT_ERROR_NONE)
{
return MapOpenThreadError(otErr);
}
// post an event alerting other subsystems about change in provisioning state
ChipDeviceEvent event;
event.Type = DeviceEventType::kServiceProvisioningChange;
event.ServiceProvisioningChange.IsServiceProvisioned = true;
return PlatformMgr().PostEvent(&event);
}
template <class ImplClass>
bool GenericThreadStackManagerImpl_OpenThread<ImplClass>::_IsThreadProvisioned(void)
{
bool provisioned;
Impl()->LockThreadStack();
provisioned = otDatasetIsCommissioned(mOTInst);
Impl()->UnlockThreadStack();
return provisioned;
}
template <class ImplClass>
CHIP_ERROR GenericThreadStackManagerImpl_OpenThread<ImplClass>::_GetThreadProvision(ByteSpan & netInfo)
{
VerifyOrReturnError(Impl()->IsThreadProvisioned(), CHIP_ERROR_INCORRECT_STATE);
otOperationalDatasetTlvs datasetTlv;
Impl()->LockThreadStack();
otError otErr = otDatasetGetActiveTlvs(mOTInst, &datasetTlv);
Impl()->UnlockThreadStack();
if (otErr != OT_ERROR_NONE)
{
return MapOpenThreadError(otErr);
}
ReturnErrorOnFailure(mActiveDataset.Init(ByteSpan(datasetTlv.mTlvs, datasetTlv.mLength)));
netInfo = mActiveDataset.AsByteSpan();
return CHIP_NO_ERROR;
}
template <class ImplClass>
bool GenericThreadStackManagerImpl_OpenThread<ImplClass>::_IsThreadAttached(void)
{
otDeviceRole curRole;
Impl()->LockThreadStack();
curRole = otThreadGetDeviceRole(mOTInst);
Impl()->UnlockThreadStack();
return (curRole != OT_DEVICE_ROLE_DISABLED && curRole != OT_DEVICE_ROLE_DETACHED);
}
template <class ImplClass>
CHIP_ERROR GenericThreadStackManagerImpl_OpenThread<ImplClass>::_AttachToThreadNetwork(
ByteSpan netInfo, NetworkCommissioning::Internal::WirelessDriver::ConnectCallback * callback)
{
// There is another ongoing connect request, reject the new one.
VerifyOrReturnError(mpConnectCallback == nullptr, CHIP_ERROR_INCORRECT_STATE);
ReturnErrorOnFailure(Impl()->SetThreadEnabled(false));
ReturnErrorOnFailure(Impl()->SetThreadProvision(netInfo));
ReturnErrorOnFailure(Impl()->SetThreadEnabled(true));
mpConnectCallback = callback;
return CHIP_NO_ERROR;
}
template <class ImplClass>
void GenericThreadStackManagerImpl_OpenThread<ImplClass>::_OnThreadAttachFinished()
{
if (mpConnectCallback != nullptr)
{
DeviceLayer::SystemLayer().ScheduleLambda([this]() {
mpConnectCallback->OnResult(NetworkCommissioning::Status::kSuccess, CharSpan(), 0);
mpConnectCallback = nullptr;
});
}
}
template <class ImplClass>
CHIP_ERROR GenericThreadStackManagerImpl_OpenThread<ImplClass>::_StartThreadScan(ThreadDriver::ScanCallback * callback)
{
// If there is another ongoing scan request, reject the new one.
VerifyOrReturnError(mpScanCallback == nullptr, CHIP_ERROR_INCORRECT_STATE);
mpScanCallback = callback;
CHIP_ERROR err = MapOpenThreadError(otLinkActiveScan(mOTInst, 0, /* all channels */
0, /* default value `kScanDurationDefault` = 300 ms. */
_OnNetworkScanFinished, this));
if (err != CHIP_NO_ERROR)
{
mpScanCallback = nullptr;
}
return err;
}
template <class ImplClass>
void GenericThreadStackManagerImpl_OpenThread<ImplClass>::_OnNetworkScanFinished(otActiveScanResult * aResult, void * aContext)
{
reinterpret_cast<GenericThreadStackManagerImpl_OpenThread *>(aContext)->_OnNetworkScanFinished(aResult);
}
template <class ImplClass>
void GenericThreadStackManagerImpl_OpenThread<ImplClass>::_OnNetworkScanFinished(otActiveScanResult * aResult)
{
if (aResult == nullptr) // scan completed
{
if (mpScanCallback != nullptr)
{
DeviceLayer::SystemLayer().ScheduleLambda([this]() {
mpScanCallback->OnFinished(NetworkCommissioning::Status::kSuccess, CharSpan(), &mScanResponseIter);
mpScanCallback = nullptr;
});
}
}
else
{
ChipLogProgress(
DeviceLayer,
"Thread Network: %s Panid 0x%" PRIx16 " Channel %" PRIu16 " RSSI %" PRId16 " LQI %" PRIu16 " Version %" PRIu16,
aResult->mNetworkName.m8, aResult->mPanId, aResult->mChannel, aResult->mRssi, aResult->mLqi, aResult->mVersion);
NetworkCommissioning::ThreadScanResponse scanResponse = { 0 };
scanResponse.panId = aResult->mPanId; // why is scanResponse.panID 64b
scanResponse.channel = aResult->mChannel; // why is scanResponse.channel 16b
scanResponse.version = aResult->mVersion;
scanResponse.rssi = aResult->mRssi;
scanResponse.lqi = aResult->mLqi;
scanResponse.extendedAddress = Encoding::BigEndian::Get64(aResult->mExtAddress.m8);
scanResponse.extendedPanId = Encoding::BigEndian::Get64(aResult->mExtendedPanId.m8);
scanResponse.networkNameLen = strnlen(aResult->mNetworkName.m8, OT_NETWORK_NAME_MAX_SIZE);
memcpy(scanResponse.networkName, aResult->mNetworkName.m8, scanResponse.networkNameLen);
mScanResponseIter.Add(&scanResponse);
}
}
template <class ImplClass>
ConnectivityManager::ThreadDeviceType GenericThreadStackManagerImpl_OpenThread<ImplClass>::_GetThreadDeviceType(void)
{
ConnectivityManager::ThreadDeviceType deviceType;
Impl()->LockThreadStack();
const otLinkModeConfig linkMode = otThreadGetLinkMode(mOTInst);
#if CHIP_DEVICE_CONFIG_THREAD_FTD
if (linkMode.mDeviceType && otThreadIsRouterEligible(mOTInst))
ExitNow(deviceType = ConnectivityManager::kThreadDeviceType_Router);
if (linkMode.mDeviceType)
ExitNow(deviceType = ConnectivityManager::kThreadDeviceType_FullEndDevice);
#endif
if (linkMode.mRxOnWhenIdle)
ExitNow(deviceType = ConnectivityManager::kThreadDeviceType_MinimalEndDevice);
ExitNow(deviceType = ConnectivityManager::kThreadDeviceType_SleepyEndDevice);
exit:
Impl()->UnlockThreadStack();
return deviceType;
}
template <class ImplClass>
CHIP_ERROR
GenericThreadStackManagerImpl_OpenThread<ImplClass>::_SetThreadDeviceType(ConnectivityManager::ThreadDeviceType deviceType)
{
CHIP_ERROR err = CHIP_NO_ERROR;
otLinkModeConfig linkMode;
switch (deviceType)
{
#if CHIP_DEVICE_CONFIG_THREAD_FTD
case ConnectivityManager::kThreadDeviceType_Router:
case ConnectivityManager::kThreadDeviceType_FullEndDevice:
#endif
case ConnectivityManager::kThreadDeviceType_MinimalEndDevice:
case ConnectivityManager::kThreadDeviceType_SleepyEndDevice:
break;
default:
ExitNow(err = CHIP_ERROR_INVALID_ARGUMENT);
}
#if CHIP_PROGRESS_LOGGING
{
const char * deviceTypeStr;
switch (deviceType)
{
case ConnectivityManager::kThreadDeviceType_Router:
deviceTypeStr = "ROUTER";
break;
case ConnectivityManager::kThreadDeviceType_FullEndDevice:
deviceTypeStr = "FULL END DEVICE";
break;
case ConnectivityManager::kThreadDeviceType_MinimalEndDevice:
deviceTypeStr = "MINIMAL END DEVICE";
break;
case ConnectivityManager::kThreadDeviceType_SleepyEndDevice:
deviceTypeStr = "SLEEPY END DEVICE";
break;
default:
deviceTypeStr = "(unknown)";
break;
}
ChipLogProgress(DeviceLayer, "Setting OpenThread device type to %s", deviceTypeStr);
}
#endif // CHIP_PROGRESS_LOGGING
Impl()->LockThreadStack();
linkMode = otThreadGetLinkMode(mOTInst);
switch (deviceType)
{
#if CHIP_DEVICE_CONFIG_THREAD_FTD
case ConnectivityManager::kThreadDeviceType_Router:
case ConnectivityManager::kThreadDeviceType_FullEndDevice:
linkMode.mDeviceType = true;
linkMode.mRxOnWhenIdle = true;
otThreadSetRouterEligible(mOTInst, deviceType == ConnectivityManager::kThreadDeviceType_Router);
break;
#endif
case ConnectivityManager::kThreadDeviceType_MinimalEndDevice:
linkMode.mDeviceType = false;
linkMode.mRxOnWhenIdle = true;
break;
case ConnectivityManager::kThreadDeviceType_SleepyEndDevice:
linkMode.mDeviceType = false;
linkMode.mRxOnWhenIdle = false;
break;
default:
break;
}
otThreadSetLinkMode(mOTInst, linkMode);
Impl()->UnlockThreadStack();
exit:
return err;
}
template <class ImplClass>
bool GenericThreadStackManagerImpl_OpenThread<ImplClass>::_HaveMeshConnectivity(void)
{
bool res;
otDeviceRole curRole;
Impl()->LockThreadStack();
// Get the current Thread role.
curRole = otThreadGetDeviceRole(mOTInst);
// If Thread is disabled, or the node is detached, then the node has no mesh connectivity.
if (curRole == OT_DEVICE_ROLE_DISABLED || curRole == OT_DEVICE_ROLE_DETACHED)
{
res = false;
}
// If the node is a child, that implies the existence of a parent node which provides connectivity
// to the mesh.
else if (curRole == OT_DEVICE_ROLE_CHILD)
{
res = true;
}
// Otherwise, if the node is acting as a router, scan the Thread neighbor table looking for at least
// one other node that is also acting as router.
else
{
otNeighborInfoIterator neighborIter = OT_NEIGHBOR_INFO_ITERATOR_INIT;
otNeighborInfo neighborInfo;
res = false;
while (otThreadGetNextNeighborInfo(mOTInst, &neighborIter, &neighborInfo) == OT_ERROR_NONE)
{
if (!neighborInfo.mIsChild)
{
res = true;
break;
}
}
}
Impl()->UnlockThreadStack();
return res;
}
template <class ImplClass>
CHIP_ERROR GenericThreadStackManagerImpl_OpenThread<ImplClass>::_GetAndLogThreadStatsCounters(void)
{
CHIP_ERROR err = CHIP_NO_ERROR;
otError otErr;
otOperationalDataset activeDataset;
Impl()->LockThreadStack();
#if CHIP_PROGRESS_LOGGING
{
otDeviceRole role;
role = otThreadGetDeviceRole(mOTInst);
ChipLogProgress(DeviceLayer, "Thread Role: %d\n", role);
}
#endif // CHIP_PROGRESS_LOGGING
if (otDatasetIsCommissioned(mOTInst))
{
otErr = otDatasetGetActive(mOTInst, &activeDataset);
VerifyOrExit(otErr == OT_ERROR_NONE, err = MapOpenThreadError(otErr));
if (activeDataset.mComponents.mIsChannelPresent)
{
ChipLogProgress(DeviceLayer, "Thread Channel: %d\n", activeDataset.mChannel);
}
}
#if CHIP_PROGRESS_LOGGING
{
const otIpCounters * ipCounters;
const otMacCounters * macCounters;
macCounters = otLinkGetCounters(mOTInst);
ChipLogProgress(DeviceLayer,
"Rx Counters:\n"
"PHY Rx Total: %" PRIu32 "\n"
"MAC Rx Unicast: %" PRIu32 "\n"
"MAC Rx Broadcast: %" PRIu32 "\n"
"MAC Rx Data: %" PRIu32 "\n"
"MAC Rx Data Polls: %" PRIu32 "\n"
"MAC Rx Beacons: %" PRIu32 "\n"
"MAC Rx Beacon Reqs: %" PRIu32 "\n"
"MAC Rx Other: %" PRIu32 "\n"
"MAC Rx Filtered Whitelist: %" PRIu32 "\n"
"MAC Rx Filtered DestAddr: %" PRIu32 "\n",
macCounters->mRxTotal, macCounters->mRxUnicast, macCounters->mRxBroadcast, macCounters->mRxData,
macCounters->mRxDataPoll, macCounters->mRxBeacon, macCounters->mRxBeaconRequest, macCounters->mRxOther,
macCounters->mRxAddressFiltered, macCounters->mRxDestAddrFiltered);
ChipLogProgress(DeviceLayer,
"Tx Counters:\n"
"PHY Tx Total: %" PRIu32 "\n"
"MAC Tx Unicast: %" PRIu32 "\n"
"MAC Tx Broadcast: %" PRIu32 "\n"
"MAC Tx Data: %" PRIu32 "\n"
"MAC Tx Data Polls: %" PRIu32 "\n"
"MAC Tx Beacons: %" PRIu32 "\n"
"MAC Tx Beacon Reqs: %" PRIu32 "\n"
"MAC Tx Other: %" PRIu32 "\n"
"MAC Tx Retry: %" PRIu32 "\n"
"MAC Tx CCA Fail: %" PRIu32 "\n",
macCounters->mTxTotal, macCounters->mTxUnicast, macCounters->mTxBroadcast, macCounters->mTxData,
macCounters->mTxDataPoll, macCounters->mTxBeacon, macCounters->mTxBeaconRequest, macCounters->mTxOther,
macCounters->mTxRetry, macCounters->mTxErrCca);
ChipLogProgress(DeviceLayer,
"Failure Counters:\n"
"MAC Rx Decrypt Fail: %" PRIu32 "\n"
"MAC Rx No Frame Fail: %" PRIu32 "\n"
"MAC Rx Unknown Neighbor Fail: %" PRIu32 "\n"
"MAC Rx Invalid Src Addr Fail: %" PRIu32 "\n"
"MAC Rx FCS Fail: %" PRIu32 "\n"
"MAC Rx Other Fail: %" PRIu32 "\n",
macCounters->mRxErrSec, macCounters->mRxErrNoFrame, macCounters->mRxErrUnknownNeighbor,
macCounters->mRxErrInvalidSrcAddr, macCounters->mRxErrFcs, macCounters->mRxErrOther);
ipCounters = otThreadGetIp6Counters(mOTInst);
ChipLogProgress(DeviceLayer,
"IP Counters:\n"
"IP Tx Success: %" PRIu32 "\n"
"IP Rx Success: %" PRIu32 "\n"
"IP Tx Fail: %" PRIu32 "\n"
"IP Rx Fail: %" PRIu32 "\n",
ipCounters->mTxSuccess, ipCounters->mRxSuccess, ipCounters->mTxFailure, ipCounters->mRxFailure);
}
#endif // CHIP_PROGRESS_LOGGING
exit:
Impl()->UnlockThreadStack();
return err;
}
template <class ImplClass>
CHIP_ERROR GenericThreadStackManagerImpl_OpenThread<ImplClass>::_GetAndLogThreadTopologyMinimal(void)
{
CHIP_ERROR err = CHIP_NO_ERROR;
#if CHIP_PROGRESS_LOGGING
otError otErr;
const otExtAddress * extAddress;
uint16_t rloc16;
uint16_t routerId;
uint16_t leaderRouterId;
uint32_t partitionId;
int8_t parentAverageRssi;
int8_t parentLastRssi;
int8_t instantRssi;
Impl()->LockThreadStack();
rloc16 = otThreadGetRloc16(mOTInst);
// Router ID is the top 6 bits of the RLOC
routerId = (rloc16 >> 10) & 0x3f;
leaderRouterId = otThreadGetLeaderRouterId(mOTInst);
otErr = otThreadGetParentAverageRssi(mOTInst, &parentAverageRssi);
VerifyOrExit(otErr == OT_ERROR_NONE, err = MapOpenThreadError(otErr));
otErr = otThreadGetParentLastRssi(mOTInst, &parentLastRssi);
VerifyOrExit(otErr == OT_ERROR_NONE, err = MapOpenThreadError(otErr));
partitionId = otThreadGetPartitionId(mOTInst);
extAddress = otLinkGetExtendedAddress(mOTInst);
instantRssi = otPlatRadioGetRssi(mOTInst);
ChipLogProgress(DeviceLayer,
"Thread Topology:\n"
"RLOC16: %04X\n"
"Router ID: %u\n"
"Leader Router ID: %u\n"
"Parent Avg RSSI: %d\n"
"Parent Last RSSI: %d\n"
"Partition ID: %" PRIu32 "\n",
rloc16, routerId, leaderRouterId, parentAverageRssi, parentLastRssi, partitionId);
ChipLogProgress(DeviceLayer,
"Extended Address: %02X%02X:%02X%02X:%02X%02X:%02X%02X\n"
"Instant RSSI: %d\n",
extAddress->m8[0], extAddress->m8[1], extAddress->m8[2], extAddress->m8[3], extAddress->m8[4],
extAddress->m8[5], extAddress->m8[6], extAddress->m8[7], instantRssi);
exit:
Impl()->UnlockThreadStack();
if (err != CHIP_NO_ERROR)
{
ChipLogError(DeviceLayer, "GetAndLogThreadTopologyMinimul failed: %" CHIP_ERROR_FORMAT, err.Format());
}
#endif // CHIP_PROGRESS_LOGGING
return err;
}
#define TELEM_NEIGHBOR_TABLE_SIZE (64)
#define TELEM_PRINT_BUFFER_SIZE (64)
#if CHIP_DEVICE_CONFIG_THREAD_FTD
template <class ImplClass>
CHIP_ERROR GenericThreadStackManagerImpl_OpenThread<ImplClass>::_GetAndLogThreadTopologyFull()
{
CHIP_ERROR err = CHIP_NO_ERROR;
#if CHIP_PROGRESS_LOGGING
otError otErr;
otIp6Address * leaderAddr = NULL;
uint8_t * networkData = NULL;
uint8_t * stableNetworkData = NULL;
uint8_t networkDataLen = 0;
uint8_t stableNetworkDataLen = 0;
const otExtAddress * extAddress;
otNeighborInfo neighborInfo[TELEM_NEIGHBOR_TABLE_SIZE];
otNeighborInfoIterator iter;
otNeighborInfoIterator iterCopy;
char printBuf[TELEM_PRINT_BUFFER_SIZE] = {0};
uint16_t rloc16;
uint16_t routerId;
uint16_t leaderRouterId;
uint8_t leaderWeight;
uint8_t leaderLocalWeight;
uint32_t partitionId;
int8_t instantRssi;
uint8_t networkDataVersion;
uint8_t stableNetworkDataVersion;
uint16_t neighborTableSize = 0;
uint16_t childTableSize = 0;
Impl()->LockThreadStack();
rloc16 = otThreadGetRloc16(mOTInst);
// Router ID is the top 6 bits of the RLOC
routerId = (rloc16 >> 10) & 0x3f;
leaderRouterId = otThreadGetLeaderRouterId(mOTInst);
otErr = otThreadGetLeaderRloc(mOTInst, leaderAddr);
VerifyOrExit(otErr == OT_ERROR_NONE, err = MapOpenThreadError(otErr));
leaderWeight = otThreadGetLeaderWeight(mOTInst);
leaderLocalWeight = otThreadGetLocalLeaderWeight(mOTInst);
otErr = otNetDataGet(mOTInst, false, networkData, &networkDataLen);
VerifyOrExit(otErr == OT_ERROR_NONE, err = MapOpenThreadError(otErr));
networkDataVersion = otNetDataGetVersion(mOTInst);
otErr = otNetDataGet(mOTInst, true, stableNetworkData, &stableNetworkDataLen);
VerifyOrExit(otErr == OT_ERROR_NONE, err = MapOpenThreadError(otErr));
stableNetworkDataVersion = otNetDataGetStableVersion(mOTInst);
extAddress = otLinkGetExtendedAddress(mOTInst);
partitionId = otThreadGetPartitionId(mOTInst);
instantRssi = otPlatRadioGetRssi(mOTInst);
iter = OT_NEIGHBOR_INFO_ITERATOR_INIT;
iterCopy = OT_NEIGHBOR_INFO_ITERATOR_INIT;
neighborTableSize = 0;
childTableSize = 0;
while (otThreadGetNextNeighborInfo(mOTInst, &iter, &neighborInfo[iter]) == OT_ERROR_NONE)
{
neighborTableSize++;
if (neighborInfo[iterCopy].mIsChild)
{
childTableSize++;
}
iterCopy = iter;
}
snprintf(printBuf, TELEM_PRINT_BUFFER_SIZE, "%02X%02X:%02X%02X:%02X%02X:%02X%02X:%02X%02X:%02X%02X:%02X%02X:%02X%02X",
leaderAddr->mFields.m8[0], leaderAddr->mFields.m8[1], leaderAddr->mFields.m8[2], leaderAddr->mFields.m8[3],
leaderAddr->mFields.m8[4], leaderAddr->mFields.m8[5], leaderAddr->mFields.m8[6], leaderAddr->mFields.m8[7],
leaderAddr->mFields.m8[8], leaderAddr->mFields.m8[9], leaderAddr->mFields.m8[10], leaderAddr->mFields.m8[11],
leaderAddr->mFields.m8[12], leaderAddr->mFields.m8[13], leaderAddr->mFields.m8[14], leaderAddr->mFields.m8[15]);
ChipLogProgress(DeviceLayer,
"Thread Topology:\n"
"RLOC16: %04X\n"
"Router ID: %u\n"
"Leader Router ID: %u\n"
"Leader Address: %s\n"
"Leader Weight: %d\n"
"Local Leader Weight: %d\n"
"Network Data Len: %d\n"
"Network Data Version: %d\n"
"Stable Network Data Version: %d\n",
rloc16, routerId, leaderRouterId, printBuf, leaderWeight, leaderLocalWeight, networkDataLen, networkDataVersion,
stableNetworkDataVersion);
memset(printBuf, 0x00, TELEM_PRINT_BUFFER_SIZE);
ChipLogProgress(DeviceLayer,
"Extended Address: %02X%02X:%02X%02X:%02X%02X:%02X%02X\n"
"Partition ID: %" PRIx32 "\n"
"Instant RSSI: %d\n"
"Neighbor Table Length: %d\n"
"Child Table Length: %d\n",
extAddress->m8[0], extAddress->m8[1], extAddress->m8[2], extAddress->m8[3], extAddress->m8[4],
extAddress->m8[5], extAddress->m8[6], extAddress->m8[7], partitionId, instantRssi, neighborTableSize,
childTableSize);
// Handle each neighbor event seperatly.
for (uint32_t i = 0; i < neighborTableSize; i++)
{
otNeighborInfo * neighbor = &neighborInfo[i];
if (neighbor->mIsChild)
{
otChildInfo * child = NULL;
otErr = otThreadGetChildInfoById(mOTInst, neighbor->mRloc16, child);
VerifyOrExit(otErr == OT_ERROR_NONE, err = MapOpenThreadError(otErr));
snprintf(printBuf, TELEM_PRINT_BUFFER_SIZE, ", Timeout: %10" PRIu32 " NetworkDataVersion: %3u", child->mTimeout,
child->mNetworkDataVersion);
}
else
{
printBuf[0] = 0;
}
ChipLogProgress(DeviceLayer,
"TopoEntry[%" PRIu32 "]: %02X%02X:%02X%02X:%02X%02X:%02X%02X\n"
"RLOC: %04X\n"
"Age: %3" PRIu32 "\n"
"LQI: %1d\n"
"AvgRSSI: %3d\n"
"LastRSSI: %3d\n",
i, neighbor->mExtAddress.m8[0], neighbor->mExtAddress.m8[1], neighbor->mExtAddress.m8[2],
neighbor->mExtAddress.m8[3], neighbor->mExtAddress.m8[4], neighbor->mExtAddress.m8[5],
neighbor->mExtAddress.m8[6], neighbor->mExtAddress.m8[7], neighbor->mRloc16, neighbor->mAge,
neighbor->mLinkQualityIn, neighbor->mAverageRssi, neighbor->mLastRssi);
ChipLogProgress(DeviceLayer,
"LinkFrameCounter: %10" PRIu32 "\n"
"MleFrameCounter: %10" PRIu32 "\n"
"RxOnWhenIdle: %c\n"
"FullFunction: %c\n"
"FullNetworkData: %c\n"
"IsChild: %c%s\n",
neighbor->mLinkFrameCounter, neighbor->mMleFrameCounter, neighbor->mRxOnWhenIdle ? 'Y' : 'n',
neighbor->mFullThreadDevice ? 'Y' : 'n', neighbor->mFullNetworkData ? 'Y' : 'n',
neighbor->mIsChild ? 'Y' : 'n', printBuf);
}
exit:
Impl()->UnlockThreadStack();
if (err != CHIP_NO_ERROR)
{
ChipLogError(DeviceLayer, "GetAndLogThreadTopologyFull failed: %s", ErrorStr(err));
}
#endif // CHIP_PROGRESS_LOGGING
return err;
}
#else // CHIP_DEVICE_CONFIG_THREAD_FTD
template <class ImplClass>
CHIP_ERROR GenericThreadStackManagerImpl_OpenThread<ImplClass>::_GetAndLogThreadTopologyFull()
{
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
}
#endif
template <class ImplClass>
CHIP_ERROR GenericThreadStackManagerImpl_OpenThread<ImplClass>::_GetPrimary802154MACAddress(uint8_t * buf)
{
const otExtAddress * extendedAddr = otLinkGetExtendedAddress(mOTInst);
memcpy(buf, extendedAddr, sizeof(otExtAddress));
return CHIP_NO_ERROR;
}
template <class ImplClass>
CHIP_ERROR GenericThreadStackManagerImpl_OpenThread<ImplClass>::_GetExternalIPv6Address(chip::Inet::IPAddress & addr)
{
const otNetifAddress * otAddresses = otIp6GetUnicastAddresses(mOTInst);
// Look only for the global unicast addresses, not internally assigned by Thread.
for (const otNetifAddress * otAddress = otAddresses; otAddress != nullptr; otAddress = otAddress->mNext)
{
if (otAddress->mValid)
{
switch (otAddress->mAddressOrigin)
{
case OT_ADDRESS_ORIGIN_THREAD:
break;
case OT_ADDRESS_ORIGIN_SLAAC:
case OT_ADDRESS_ORIGIN_DHCPV6:
case OT_ADDRESS_ORIGIN_MANUAL:
addr = ToIPAddress(otAddress->mAddress);
return CHIP_NO_ERROR;
default:
break;
}
}
}
return CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND;
}
template <class ImplClass>
void GenericThreadStackManagerImpl_OpenThread<ImplClass>::_ResetThreadNetworkDiagnosticsCounts(void)
{
// Based on the spec, only OverrunCount should be resetted.
mOverrunCount = 0;
}
/*
* @brief Get runtime value from the thread network based on the given attribute ID.
* The info is encoded via the AttributeValueEncoder.
*
* @param attributeId Id of the attribute for the requested info.
* @param aEncoder Encoder to encode the attribute value.
*
* @return CHIP_NO_ERROR = Succes.
* CHIP_ERROR_NOT_IMPLEMENTED = Runtime value for this attribute to yet available to send as reply
* Use standard read.
* CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE = Is not a Runtime readable attribute. Use standard read
* All other errors should be treated as a read error and reported as such.
*/
template <class ImplClass>
CHIP_ERROR GenericThreadStackManagerImpl_OpenThread<ImplClass>::_WriteThreadNetworkDiagnosticAttributeToTlv(
AttributeId attributeId, app::AttributeValueEncoder & encoder)
{
CHIP_ERROR err;
switch (attributeId)
{
case ThreadNetworkDiagnostics::Attributes::Channel::Id: {
uint16_t channel = otLinkGetChannel(mOTInst);
err = encoder.Encode(channel);
}
break;
case ThreadNetworkDiagnostics::Attributes::RoutingRole::Id: {
ThreadNetworkDiagnostics::RoutingRole routingRole;
otDeviceRole otRole = otThreadGetDeviceRole(mOTInst);
if (otRole == OT_DEVICE_ROLE_DISABLED)
{
routingRole = EMBER_ZCL_ROUTING_ROLE_UNSPECIFIED;
}
else if (otRole == OT_DEVICE_ROLE_DETACHED)
{
routingRole = EMBER_ZCL_ROUTING_ROLE_UNASSIGNED;
}
else if (otRole == OT_DEVICE_ROLE_ROUTER)
{
routingRole = EMBER_ZCL_ROUTING_ROLE_ROUTER;
}
else if (otRole == OT_DEVICE_ROLE_LEADER)
{
routingRole = EMBER_ZCL_ROUTING_ROLE_LEADER;
}
else if (otRole == OT_DEVICE_ROLE_CHILD)
{
otLinkModeConfig linkMode = otThreadGetLinkMode(mOTInst);
if (linkMode.mRxOnWhenIdle)
{
routingRole = EMBER_ZCL_ROUTING_ROLE_END_DEVICE;
#if CHIP_DEVICE_CONFIG_THREAD_FTD
if (otThreadIsRouterEligible(mOTInst))
{
routingRole = EMBER_ZCL_ROUTING_ROLE_REED;
}
#endif
}
else
{
routingRole = EMBER_ZCL_ROUTING_ROLE_SLEEPY_END_DEVICE;
}
}
err = encoder.Encode(routingRole);
}
break;
case ThreadNetworkDiagnostics::Attributes::NetworkName::Id: {
const char * networkName = otThreadGetNetworkName(mOTInst);
err = encoder.Encode(CharSpan::fromCharString(networkName));
}
break;
case ThreadNetworkDiagnostics::Attributes::PanId::Id: {
uint16_t panId = otLinkGetPanId(mOTInst);
err = encoder.Encode(panId);
}
break;
case ThreadNetworkDiagnostics::Attributes::ExtendedPanId::Id: {
const otExtendedPanId * pExtendedPanid = otThreadGetExtendedPanId(mOTInst);
err = encoder.Encode(Encoding::BigEndian::Get64(pExtendedPanid->m8));
}
break;
case ThreadNetworkDiagnostics::Attributes::MeshLocalPrefix::Id: {
uint8_t meshLocaPrefix[OT_MESH_LOCAL_PREFIX_SIZE + 1] = { 0 }; // + 1 to encode prefix Len in the octstr
const otMeshLocalPrefix * pMeshLocalPrefix = otThreadGetMeshLocalPrefix(mOTInst);
meshLocaPrefix[0] = OT_IP6_PREFIX_BITSIZE;
memcpy(&meshLocaPrefix[1], pMeshLocalPrefix->m8, OT_MESH_LOCAL_PREFIX_SIZE);
err = encoder.Encode(ByteSpan(meshLocaPrefix));
}
break;
case ThreadNetworkDiagnostics::Attributes::OverrunCount::Id: {
uint64_t overrunCount = mOverrunCount;
err = encoder.Encode(overrunCount);
}
break;
case ThreadNetworkDiagnostics::Attributes::NeighborTableList::Id: {
err = encoder.EncodeList([this](const auto & aEncoder) -> CHIP_ERROR {
otNeighborInfo neighInfo;
otNeighborInfoIterator iterator = OT_NEIGHBOR_INFO_ITERATOR_INIT;
while (otThreadGetNextNeighborInfo(mOTInst, &iterator, &neighInfo) == OT_ERROR_NONE)
{
ThreadNetworkDiagnostics::Structs::NeighborTable::Type neighborTable;
neighborTable.extAddress = Encoding::BigEndian::Get64(neighInfo.mExtAddress.m8);
neighborTable.age = neighInfo.mAge;
neighborTable.rloc16 = neighInfo.mRloc16;
neighborTable.linkFrameCounter = neighInfo.mLinkFrameCounter;
neighborTable.mleFrameCounter = neighInfo.mMleFrameCounter;
neighborTable.lqi = neighInfo.mLinkQualityIn;
neighborTable.averageRssi = neighInfo.mAverageRssi;
neighborTable.lastRssi = neighInfo.mLastRssi;
neighborTable.frameErrorRate = neighInfo.mFrameErrorRate;
neighborTable.messageErrorRate = neighInfo.mMessageErrorRate;
neighborTable.rxOnWhenIdle = neighInfo.mRxOnWhenIdle;
neighborTable.fullThreadDevice = neighInfo.mFullThreadDevice;
neighborTable.fullNetworkData = neighInfo.mFullNetworkData;
neighborTable.isChild = neighInfo.mIsChild;
ReturnErrorOnFailure(aEncoder.Encode(neighborTable));
}
return CHIP_NO_ERROR;
});
}
break;
case ThreadNetworkDiagnostics::Attributes::RouteTableList::Id: {
err = encoder.EncodeList([this](const auto & aEncoder) -> CHIP_ERROR {
otRouterInfo routerInfo;
#if CHIP_DEVICE_CONFIG_THREAD_FTD
uint8_t maxRouterId = otThreadGetMaxRouterId(mOTInst);
CHIP_ERROR chipErr = CHIP_ERROR_INCORRECT_STATE;
for (uint8_t i = 0; i <= maxRouterId; i++)
{
if (otThreadGetRouterInfo(mOTInst, i, &routerInfo) == OT_ERROR_NONE)
{
ThreadNetworkDiagnostics::Structs::RouteTable::Type routeTable;
routeTable.extAddress = Encoding::BigEndian::Get64(routerInfo.mExtAddress.m8);
routeTable.rloc16 = routerInfo.mRloc16;
routeTable.routerId = routerInfo.mRouterId;
routeTable.nextHop = routerInfo.mNextHop;
routeTable.pathCost = routerInfo.mPathCost;
routeTable.LQIIn = routerInfo.mLinkQualityIn;
routeTable.LQIOut = routerInfo.mLinkQualityOut;
routeTable.age = routerInfo.mAge;
routeTable.allocated = routerInfo.mAllocated;
routeTable.linkEstablished = routerInfo.mLinkEstablished;
ReturnErrorOnFailure(aEncoder.Encode(routeTable));
chipErr = CHIP_NO_ERROR;
}
}
return chipErr;
#else // OPENTHREAD_MTD
otError otErr = otThreadGetParentInfo(mOTInst, &routerInfo);
ReturnErrorOnFailure(MapOpenThreadError(otErr));
ThreadNetworkDiagnostics::Structs::RouteTable::Type routeTable;
routeTable.extAddress = Encoding::BigEndian::Get64(routerInfo.mExtAddress.m8);
routeTable.rloc16 = routerInfo.mRloc16;
routeTable.routerId = routerInfo.mRouterId;
routeTable.nextHop = routerInfo.mNextHop;
routeTable.pathCost = routerInfo.mPathCost;
routeTable.LQIIn = routerInfo.mLinkQualityIn;
routeTable.LQIOut = routerInfo.mLinkQualityOut;
routeTable.age = routerInfo.mAge;
routeTable.allocated = routerInfo.mAllocated;
routeTable.linkEstablished = routerInfo.mLinkEstablished;
ReturnErrorOnFailure(aEncoder.Encode(routeTable));
return CHIP_NO_ERROR;
#endif
});
}
break;
case ThreadNetworkDiagnostics::Attributes::PartitionId::Id: {
uint32_t partitionId = otThreadGetPartitionId(mOTInst);
err = encoder.Encode(partitionId);
}
break;
case ThreadNetworkDiagnostics::Attributes::Weighting::Id: {
uint8_t weight = otThreadGetLeaderWeight(mOTInst);
err = encoder.Encode(weight);
}
break;
case ThreadNetworkDiagnostics::Attributes::DataVersion::Id: {
uint8_t dataVersion = otNetDataGetVersion(mOTInst);
err = encoder.Encode(dataVersion);
}
break;
case ThreadNetworkDiagnostics::Attributes::StableDataVersion::Id: {
uint8_t stableVersion = otNetDataGetStableVersion(mOTInst);
err = encoder.Encode(stableVersion);
}
break;
case ThreadNetworkDiagnostics::Attributes::LeaderRouterId::Id: {
uint8_t leaderRouterId = otThreadGetLeaderRouterId(mOTInst);
err = encoder.Encode(leaderRouterId);
}
break;
case ThreadNetworkDiagnostics::Attributes::DetachedRoleCount::Id: {
uint16_t detachedRole = otThreadGetMleCounters(mOTInst)->mDetachedRole;
err = encoder.Encode(detachedRole);
}
break;
case ThreadNetworkDiagnostics::Attributes::ChildRoleCount::Id: {
uint16_t childRole = otThreadGetMleCounters(mOTInst)->mChildRole;
err = encoder.Encode(childRole);
}
break;
case ThreadNetworkDiagnostics::Attributes::RouterRoleCount::Id: {
uint16_t routerRole = otThreadGetMleCounters(mOTInst)->mRouterRole;
err = encoder.Encode(routerRole);
}
break;
case ThreadNetworkDiagnostics::Attributes::LeaderRoleCount::Id: {
uint16_t leaderRole = otThreadGetMleCounters(mOTInst)->mLeaderRole;
err = encoder.Encode(leaderRole);
}
break;
case ThreadNetworkDiagnostics::Attributes::AttachAttemptCount::Id: {
uint16_t attachAttempts = otThreadGetMleCounters(mOTInst)->mAttachAttempts;
err = encoder.Encode(attachAttempts);
}
break;
case ThreadNetworkDiagnostics::Attributes::PartitionIdChangeCount::Id: {
uint16_t partitionIdChanges = otThreadGetMleCounters(mOTInst)->mPartitionIdChanges;
err = encoder.Encode(partitionIdChanges);
}
break;
case ThreadNetworkDiagnostics::Attributes::BetterPartitionAttachAttemptCount::Id: {
uint16_t betterPartitionAttachAttempts = otThreadGetMleCounters(mOTInst)->mBetterPartitionAttachAttempts;
err = encoder.Encode(betterPartitionAttachAttempts);
}
break;
case ThreadNetworkDiagnostics::Attributes::ParentChangeCount::Id: {
uint16_t parentChanges = otThreadGetMleCounters(mOTInst)->mParentChanges;
err = encoder.Encode(parentChanges);
}
break;
case ThreadNetworkDiagnostics::Attributes::TxTotalCount::Id: {
uint32_t txTotal = otLinkGetCounters(mOTInst)->mTxTotal;
err = encoder.Encode(txTotal);
}
break;
case ThreadNetworkDiagnostics::Attributes::TxUnicastCount::Id: {
uint32_t txUnicast = otLinkGetCounters(mOTInst)->mTxUnicast;
err = encoder.Encode(txUnicast);
}
break;
case ThreadNetworkDiagnostics::Attributes::TxBroadcastCount::Id: {
uint32_t txBroadcast = otLinkGetCounters(mOTInst)->mTxBroadcast;
err = encoder.Encode(txBroadcast);
}
break;
case ThreadNetworkDiagnostics::Attributes::TxAckRequestedCount::Id: {
uint32_t txAckRequested = otLinkGetCounters(mOTInst)->mTxAckRequested;
err = encoder.Encode(txAckRequested);
}
break;
case ThreadNetworkDiagnostics::Attributes::TxAckedCount::Id: {
uint32_t txAcked = otLinkGetCounters(mOTInst)->mTxAcked;
err = encoder.Encode(txAcked);
}
break;
case ThreadNetworkDiagnostics::Attributes::TxNoAckRequestedCount::Id: {
uint32_t txNoAckRequested = otLinkGetCounters(mOTInst)->mTxNoAckRequested;
err = encoder.Encode(txNoAckRequested);
}
break;
case ThreadNetworkDiagnostics::Attributes::TxDataCount::Id: {
uint32_t txData = otLinkGetCounters(mOTInst)->mTxData;
err = encoder.Encode(txData);
}
break;
case ThreadNetworkDiagnostics::Attributes::TxDataPollCount::Id: {
uint32_t txDataPoll = otLinkGetCounters(mOTInst)->mTxDataPoll;
err = encoder.Encode(txDataPoll);
}
break;
case ThreadNetworkDiagnostics::Attributes::TxBeaconCount::Id: {
uint32_t txBeacon = otLinkGetCounters(mOTInst)->mTxBeacon;
err = encoder.Encode(txBeacon);
}
break;
case ThreadNetworkDiagnostics::Attributes::TxBeaconRequestCount::Id: {
uint32_t txBeaconRequest = otLinkGetCounters(mOTInst)->mTxBeaconRequest;
err = encoder.Encode(txBeaconRequest);
}
break;
case ThreadNetworkDiagnostics::Attributes::TxOtherCount::Id: {
uint32_t txOther = otLinkGetCounters(mOTInst)->mTxOther;
err = encoder.Encode(txOther);
}
break;
case ThreadNetworkDiagnostics::Attributes::TxRetryCount::Id: {
uint32_t txRetry = otLinkGetCounters(mOTInst)->mTxRetry;
err = encoder.Encode(txRetry);
}
break;
case ThreadNetworkDiagnostics::Attributes::TxDirectMaxRetryExpiryCount::Id: {
uint32_t txDirectMaxRetryExpiry = otLinkGetCounters(mOTInst)->mTxDirectMaxRetryExpiry;
err = encoder.Encode(txDirectMaxRetryExpiry);
}
break;
case ThreadNetworkDiagnostics::Attributes::TxIndirectMaxRetryExpiryCount::Id: {
uint32_t txIndirectMaxRetryExpiry = otLinkGetCounters(mOTInst)->mTxIndirectMaxRetryExpiry;
err = encoder.Encode(txIndirectMaxRetryExpiry);
}
break;
case ThreadNetworkDiagnostics::Attributes::TxErrCcaCount::Id: {
uint32_t txErrCca = otLinkGetCounters(mOTInst)->mTxErrCca;
err = encoder.Encode(txErrCca);
}
break;
case ThreadNetworkDiagnostics::Attributes::TxErrAbortCount::Id: {
uint32_t TxErrAbort = otLinkGetCounters(mOTInst)->mTxErrAbort;
err = encoder.Encode(TxErrAbort);
}
break;
case ThreadNetworkDiagnostics::Attributes::TxErrBusyChannelCount::Id: {
uint32_t TxErrBusyChannel = otLinkGetCounters(mOTInst)->mTxErrBusyChannel;
err = encoder.Encode(TxErrBusyChannel);
}
break;
case ThreadNetworkDiagnostics::Attributes::RxTotalCount::Id: {
uint32_t rxTotal = otLinkGetCounters(mOTInst)->mRxTotal;
err = encoder.Encode(rxTotal);
}
break;
case ThreadNetworkDiagnostics::Attributes::RxUnicastCount::Id: {
uint32_t rxUnicast = otLinkGetCounters(mOTInst)->mRxUnicast;
err = encoder.Encode(rxUnicast);
}
break;
case ThreadNetworkDiagnostics::Attributes::RxBroadcastCount::Id: {
uint32_t rxBroadcast = otLinkGetCounters(mOTInst)->mRxBroadcast;
err = encoder.Encode(rxBroadcast);
}
break;
case ThreadNetworkDiagnostics::Attributes::RxDataCount::Id: {
uint32_t rxData = otLinkGetCounters(mOTInst)->mRxData;
err = encoder.Encode(rxData);
}
break;
case ThreadNetworkDiagnostics::Attributes::RxDataPollCount::Id: {
uint32_t rxDataPoll = otLinkGetCounters(mOTInst)->mRxDataPoll;
err = encoder.Encode(rxDataPoll);
}
break;
case ThreadNetworkDiagnostics::Attributes::RxBeaconCount::Id: {
uint32_t rxBeacon = otLinkGetCounters(mOTInst)->mRxBeacon;
err = encoder.Encode(rxBeacon);
}
break;
case ThreadNetworkDiagnostics::Attributes::RxBeaconRequestCount::Id: {
uint32_t rxBeaconRequest = otLinkGetCounters(mOTInst)->mRxBeaconRequest;
err = encoder.Encode(rxBeaconRequest);
}
break;
case ThreadNetworkDiagnostics::Attributes::RxOtherCount::Id: {
uint32_t rxOther = otLinkGetCounters(mOTInst)->mRxOther;
err = encoder.Encode(rxOther);
}
break;
case ThreadNetworkDiagnostics::Attributes::RxAddressFilteredCount::Id: {
uint32_t rxAddressFiltered = otLinkGetCounters(mOTInst)->mRxAddressFiltered;
err = encoder.Encode(rxAddressFiltered);
}
break;
case ThreadNetworkDiagnostics::Attributes::RxDestAddrFilteredCount::Id: {
uint32_t rxDestAddrFiltered = otLinkGetCounters(mOTInst)->mRxDestAddrFiltered;
err = encoder.Encode(rxDestAddrFiltered);
}
break;
case ThreadNetworkDiagnostics::Attributes::RxDuplicatedCount::Id: {
uint32_t rxDuplicated = otLinkGetCounters(mOTInst)->mRxDuplicated;
err = encoder.Encode(rxDuplicated);
}
break;
case ThreadNetworkDiagnostics::Attributes::RxErrNoFrameCount::Id: {
uint32_t rxErrNoFrame = otLinkGetCounters(mOTInst)->mRxErrNoFrame;
err = encoder.Encode(rxErrNoFrame);
}
break;
case ThreadNetworkDiagnostics::Attributes::RxErrUnknownNeighborCount::Id: {
uint32_t rxErrUnknownNeighbor = otLinkGetCounters(mOTInst)->mRxErrUnknownNeighbor;
err = encoder.Encode(rxErrUnknownNeighbor);
}
break;
case ThreadNetworkDiagnostics::Attributes::RxErrInvalidSrcAddrCount::Id: {
uint32_t rxErrInvalidSrcAddr = otLinkGetCounters(mOTInst)->mRxErrInvalidSrcAddr;
err = encoder.Encode(rxErrInvalidSrcAddr);
}
break;
case ThreadNetworkDiagnostics::Attributes::RxErrSecCount::Id: {
uint32_t rxErrSec = otLinkGetCounters(mOTInst)->mRxErrSec;
err = encoder.Encode(rxErrSec);
}
break;
case ThreadNetworkDiagnostics::Attributes::RxErrFcsCount::Id: {
uint32_t rxErrFcs = otLinkGetCounters(mOTInst)->mRxErrFcs;
err = encoder.Encode(rxErrFcs);
}
break;
case ThreadNetworkDiagnostics::Attributes::RxErrOtherCount::Id: {
uint32_t rxErrOther = otLinkGetCounters(mOTInst)->mRxErrOther;
err = encoder.Encode(rxErrOther);
}
break;
case ThreadNetworkDiagnostics::Attributes::ActiveTimestamp::Id: {
err = CHIP_ERROR_INCORRECT_STATE;
if (otDatasetIsCommissioned(mOTInst))
{
otOperationalDataset activeDataset;
otError otErr = otDatasetGetActive(mOTInst, &activeDataset);
VerifyOrExit(otErr == OT_ERROR_NONE, err = MapOpenThreadError(otErr));
uint64_t activeTimestamp = activeDataset.mPendingTimestamp;
err = encoder.Encode(activeTimestamp);
}
}
break;
case ThreadNetworkDiagnostics::Attributes::PendingTimestamp::Id: {
err = CHIP_ERROR_INCORRECT_STATE;
if (otDatasetIsCommissioned(mOTInst))
{
otOperationalDataset activeDataset;
otError otErr = otDatasetGetActive(mOTInst, &activeDataset);
VerifyOrExit(otErr == OT_ERROR_NONE, err = MapOpenThreadError(otErr));
uint64_t pendingTimestamp = activeDataset.mPendingTimestamp;
err = encoder.Encode(pendingTimestamp);
}
}
break;
case ThreadNetworkDiagnostics::Attributes::Delay::Id: {
err = CHIP_ERROR_INCORRECT_STATE;
if (otDatasetIsCommissioned(mOTInst))
{
otOperationalDataset activeDataset;
otError otErr = otDatasetGetActive(mOTInst, &activeDataset);
VerifyOrExit(otErr == OT_ERROR_NONE, err = MapOpenThreadError(otErr));
uint32_t delay = activeDataset.mDelay;
err = encoder.Encode(delay);
}
}
break;
case ThreadNetworkDiagnostics::Attributes::SecurityPolicy::Id: {
err = CHIP_ERROR_INCORRECT_STATE;
if (otDatasetIsCommissioned(mOTInst))
{
otOperationalDataset activeDataset;
otError otErr = otDatasetGetActive(mOTInst, &activeDataset);
VerifyOrExit(otErr == OT_ERROR_NONE, err = MapOpenThreadError(otErr));
ThreadNetworkDiagnostics::Structs::SecurityPolicy::Type securityPolicy;
static_assert(sizeof(securityPolicy) == sizeof(activeDataset.mSecurityPolicy),
"securityPolicy Struct do not match otSecurityPolicy");
uint16_t policyAsInts[2];
static_assert(sizeof(policyAsInts) == sizeof(activeDataset.mSecurityPolicy),
"We're missing some members of otSecurityPolicy?");
memcpy(&policyAsInts, &activeDataset.mSecurityPolicy, sizeof(policyAsInts));
securityPolicy.rotationTime = policyAsInts[0];
securityPolicy.flags = policyAsInts[1];
err = encoder.EncodeList([securityPolicy](const auto & aEncoder) -> CHIP_ERROR {
ReturnErrorOnFailure(aEncoder.Encode(securityPolicy));
return CHIP_NO_ERROR;
});
}
}
break;
case ThreadNetworkDiagnostics::Attributes::ChannelMask::Id: {
err = CHIP_ERROR_INCORRECT_STATE;
if (otDatasetIsCommissioned(mOTInst))
{
otOperationalDataset activeDataset;
otError otErr = otDatasetGetActive(mOTInst, &activeDataset);
VerifyOrExit(otErr == OT_ERROR_NONE, err = MapOpenThreadError(otErr));
// In the resultant Octet string, the most significant bit of the left-most byte indicates channel 0
// We have to bitswap the entire uint32_t before converting to octet string
uint32_t bitSwappedChannelMask = 0;
for (int i = 0, j = 31; i < 32; i++, j--)
{
bitSwappedChannelMask |= ((activeDataset.mChannelMask >> j) & 1) << i;
}
uint8_t buffer[sizeof(uint32_t)] = { 0 };
Encoding::BigEndian::Put32(buffer, bitSwappedChannelMask);
err = encoder.Encode(ByteSpan(buffer));
}
}
break;
case ThreadNetworkDiagnostics::Attributes::OperationalDatasetComponents::Id: {
err = CHIP_ERROR_INCORRECT_STATE;
if (otDatasetIsCommissioned(mOTInst))
{
otOperationalDataset activeDataset;
otError otErr = otDatasetGetActive(mOTInst, &activeDataset);
VerifyOrExit(otErr == OT_ERROR_NONE, err = MapOpenThreadError(otErr));
ThreadNetworkDiagnostics::Structs::OperationalDatasetComponents::Type OpDatasetComponents;
OpDatasetComponents.activeTimestampPresent = activeDataset.mComponents.mIsActiveTimestampPresent;
OpDatasetComponents.pendingTimestampPresent = activeDataset.mComponents.mIsPendingTimestampPresent;
OpDatasetComponents.masterKeyPresent = activeDataset.mComponents.mIsNetworkKeyPresent;
OpDatasetComponents.networkNamePresent = activeDataset.mComponents.mIsNetworkNamePresent;
OpDatasetComponents.extendedPanIdPresent = activeDataset.mComponents.mIsExtendedPanIdPresent;
OpDatasetComponents.meshLocalPrefixPresent = activeDataset.mComponents.mIsMeshLocalPrefixPresent;
OpDatasetComponents.delayPresent = activeDataset.mComponents.mIsDelayPresent;
OpDatasetComponents.panIdPresent = activeDataset.mComponents.mIsPanIdPresent;
OpDatasetComponents.channelPresent = activeDataset.mComponents.mIsChannelPresent;
OpDatasetComponents.pskcPresent = activeDataset.mComponents.mIsPskcPresent;
OpDatasetComponents.securityPolicyPresent = activeDataset.mComponents.mIsSecurityPolicyPresent;
OpDatasetComponents.channelMaskPresent = activeDataset.mComponents.mIsChannelMaskPresent;
err = encoder.EncodeList([OpDatasetComponents](const auto & aEncoder) -> CHIP_ERROR {
ReturnErrorOnFailure(aEncoder.Encode(OpDatasetComponents));
return CHIP_NO_ERROR;
});
}
}
break;
case ThreadNetworkDiagnostics::Attributes::ActiveNetworkFaultsList::Id: {
err = encoder.EncodeList([](const auto & aEncoder) -> CHIP_ERROR {
// TODO activeNetworkFaultsList isn't tracked. Encode the list of 4 entries at 0 none the less
ThreadNetworkDiagnostics::NetworkFault activeNetworkFaultsList[4] = { ThreadNetworkDiagnostics::NetworkFault(0) };
for (auto fault : activeNetworkFaultsList)
{
ReturnErrorOnFailure(aEncoder.Encode(fault));
}
return CHIP_NO_ERROR;
});
}
break;
default: {
err = CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
}
break;
}
exit:
if (err != CHIP_NO_ERROR)
{
ChipLogError(DeviceLayer, "_WriteThreadNetworkDiagnosticAttributeToTlv failed: %s", ErrorStr(err));
}
return err;
}
template <class ImplClass>
CHIP_ERROR GenericThreadStackManagerImpl_OpenThread<ImplClass>::_GetPollPeriod(uint32_t & buf)
{
Impl()->LockThreadStack();
buf = otLinkGetPollPeriod(mOTInst);
Impl()->UnlockThreadStack();
return CHIP_NO_ERROR;
}
template <class ImplClass>
CHIP_ERROR GenericThreadStackManagerImpl_OpenThread<ImplClass>::DoInit(otInstance * otInst)
{
CHIP_ERROR err = CHIP_NO_ERROR;
otError otErr = OT_ERROR_NONE;
// Arrange for OpenThread errors to be translated to text.
RegisterOpenThreadErrorFormatter();
mOTInst = NULL;
// If an OpenThread instance hasn't been supplied, call otInstanceInitSingle() to
// create or acquire a singleton instance of OpenThread.
if (otInst == NULL)
{
otInst = otInstanceInitSingle();
VerifyOrExit(otInst != NULL, err = MapOpenThreadError(OT_ERROR_FAILED));
}
#if !defined(PW_RPC_ENABLED) && CHIP_DEVICE_CONFIG_THREAD_ENABLE_CLI
otAppCliInit(otInst);
#endif
mOTInst = otInst;
#if CHIP_DEVICE_CONFIG_ENABLE_SED
ConnectivityManager::SEDPollingConfig sedPollingConfig;
using namespace System::Clock::Literals;
sedPollingConfig.FastPollingIntervalMS = CHIP_DEVICE_CONFIG_SED_FAST_POLLING_INTERVAL;
sedPollingConfig.SlowPollingIntervalMS = CHIP_DEVICE_CONFIG_SED_SLOW_POLLING_INTERVAL;
err = _SetSEDPollingConfig(sedPollingConfig);
if (err != CHIP_NO_ERROR)
{
ChipLogError(DeviceLayer, "Sleepy end device polling config set failed: %s", ErrorStr(err));
}
SuccessOrExit(err);
#endif
// Arrange for OpenThread to call the OnOpenThreadStateChange method whenever a
// state change occurs. Note that we reference the OnOpenThreadStateChange method
// on the concrete implementation class so that that class can override the default
// method implementation if it chooses to.
otErr = otSetStateChangedCallback(otInst, ImplClass::OnOpenThreadStateChange, mOTInst);
VerifyOrExit(otErr == OT_ERROR_NONE, err = MapOpenThreadError(otErr));
// Enable automatic assignment of Thread advertised addresses.
#if OPENTHREAD_CONFIG_IP6_SLAAC_ENABLE
otIp6SetSlaacEnabled(otInst, true);
#endif
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT
otSrpClientSetCallback(mOTInst, &OnSrpClientNotification, nullptr);
otSrpClientEnableAutoStartMode(mOTInst, &OnSrpClientStateChange, nullptr);
memset(&mSrpClient, 0, sizeof(mSrpClient));
#endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT
// If the Thread stack has been provisioned, but is not currently enabled, enable it now.
if (otThreadGetDeviceRole(mOTInst) == OT_DEVICE_ROLE_DISABLED && otDatasetIsCommissioned(otInst))
{
// Enable the Thread IPv6 interface.
otErr = otIp6SetEnabled(otInst, true);
VerifyOrExit(otErr == OT_ERROR_NONE, err = MapOpenThreadError(otErr));
otErr = otThreadSetEnabled(otInst, true);
VerifyOrExit(otErr == OT_ERROR_NONE, err = MapOpenThreadError(otErr));
ChipLogProgress(DeviceLayer, "OpenThread ifconfig up and thread start");
}
initNetworkCommissioningThreadDriver();
exit:
ChipLogProgress(DeviceLayer, "OpenThread started: %s", otThreadErrorToString(otErr));
return err;
}
template <class ImplClass>
bool GenericThreadStackManagerImpl_OpenThread<ImplClass>::IsThreadAttachedNoLock(void)
{
otDeviceRole curRole = otThreadGetDeviceRole(mOTInst);
return (curRole != OT_DEVICE_ROLE_DISABLED && curRole != OT_DEVICE_ROLE_DETACHED);
}
template <class ImplClass>
bool GenericThreadStackManagerImpl_OpenThread<ImplClass>::IsThreadInterfaceUpNoLock(void)
{
return otIp6IsEnabled(mOTInst);
}
#if CHIP_DEVICE_CONFIG_ENABLE_SED
template <class ImplClass>
CHIP_ERROR
GenericThreadStackManagerImpl_OpenThread<ImplClass>::_GetSEDPollingConfig(ConnectivityManager::SEDPollingConfig & pollingConfig)
{
pollingConfig = mPollingConfig;
return CHIP_NO_ERROR;
}
template <class ImplClass>
CHIP_ERROR GenericThreadStackManagerImpl_OpenThread<ImplClass>::_SetSEDPollingConfig(
const ConnectivityManager::SEDPollingConfig & pollingConfig)
{
using namespace System::Clock::Literals;
if ((pollingConfig.SlowPollingIntervalMS < pollingConfig.FastPollingIntervalMS) ||
(pollingConfig.SlowPollingIntervalMS == 0_ms32) || (pollingConfig.FastPollingIntervalMS == 0_ms32))
{
return CHIP_ERROR_INVALID_ARGUMENT;
}
mPollingConfig = pollingConfig;
CHIP_ERROR err = SetSEDPollingMode(mPollingMode);
if (err == CHIP_NO_ERROR)
{
ChipDeviceEvent event;
event.Type = DeviceEventType::kSEDPollingIntervalChange;
err = chip::DeviceLayer::PlatformMgr().PostEvent(&event);
}
return err;
}
template <class ImplClass>
CHIP_ERROR GenericThreadStackManagerImpl_OpenThread<ImplClass>::SetSEDPollingMode(ConnectivityManager::SEDPollingMode pollingType)
{
CHIP_ERROR err = CHIP_NO_ERROR;
System::Clock::Milliseconds32 interval;
if (pollingType == ConnectivityManager::SEDPollingMode::Idle)
{
interval = mPollingConfig.SlowPollingIntervalMS;
}
else if (pollingType == ConnectivityManager::SEDPollingMode::Active)
{
interval = mPollingConfig.FastPollingIntervalMS;
}
else
{
return CHIP_ERROR_INVALID_ARGUMENT;
}
mPollingMode = pollingType;
Impl()->LockThreadStack();
uint32_t curPollingIntervalMS = otLinkGetPollPeriod(mOTInst);
if (interval.count() != curPollingIntervalMS)
{
otError otErr = otLinkSetPollPeriod(mOTInst, interval.count());
err = MapOpenThreadError(otErr);
}
Impl()->UnlockThreadStack();
if (interval.count() != curPollingIntervalMS)
{
ChipLogProgress(DeviceLayer, "OpenThread polling interval set to %" PRId32 "ms", interval.count());
}
return err;
}
template <class ImplClass>
CHIP_ERROR GenericThreadStackManagerImpl_OpenThread<ImplClass>::_RequestSEDFastPollingMode(bool onOff)
{
CHIP_ERROR err = CHIP_NO_ERROR;
ConnectivityManager::SEDPollingMode mode;
if (onOff)
{
mFastPollingConsumers++;
}
else
{
if (mFastPollingConsumers > 0)
mFastPollingConsumers--;
}
mode = mFastPollingConsumers > 0 ? ConnectivityManager::SEDPollingMode::Active : ConnectivityManager::SEDPollingMode::Idle;
if (mPollingMode != mode)
err = SetSEDPollingMode(mode);
return err;
}
#endif
template <class ImplClass>
void GenericThreadStackManagerImpl_OpenThread<ImplClass>::_ErasePersistentInfo(void)
{
ChipLogProgress(DeviceLayer, "Erasing Thread persistent info...");
Impl()->LockThreadStack();
otThreadSetEnabled(mOTInst, false);
otInstanceErasePersistentInfo(mOTInst);
Impl()->UnlockThreadStack();
}
template <class ImplClass>
void GenericThreadStackManagerImpl_OpenThread<ImplClass>::OnJoinerComplete(otError aError, void * aContext)
{
static_cast<GenericThreadStackManagerImpl_OpenThread *>(aContext)->OnJoinerComplete(aError);
}
template <class ImplClass>
void GenericThreadStackManagerImpl_OpenThread<ImplClass>::OnJoinerComplete(otError aError)
{
#if CHIP_PROGRESS_LOGGING
ChipLogProgress(DeviceLayer, "Join Thread network: %s", otThreadErrorToString(aError));
if (aError == OT_ERROR_NONE)
{
otError error = otThreadSetEnabled(mOTInst, true);
ChipLogProgress(DeviceLayer, "Start Thread network: %s", otThreadErrorToString(error));
}
#endif // CHIP_PROGRESS_LOGGING
}
template <class ImplClass>
CHIP_ERROR GenericThreadStackManagerImpl_OpenThread<ImplClass>::_JoinerStart(void)
{
CHIP_ERROR error = CHIP_NO_ERROR;
Impl()->LockThreadStack();
VerifyOrExit(!otDatasetIsCommissioned(mOTInst) && otThreadGetDeviceRole(mOTInst) == OT_DEVICE_ROLE_DISABLED,
error = MapOpenThreadError(OT_ERROR_INVALID_STATE));
VerifyOrExit(otJoinerGetState(mOTInst) == OT_JOINER_STATE_IDLE, error = MapOpenThreadError(OT_ERROR_BUSY));
if (!otIp6IsEnabled(mOTInst))
{
SuccessOrExit(error = MapOpenThreadError(otIp6SetEnabled(mOTInst, true)));
}
{
otJoinerDiscerner discerner;
// This is dead code to remove, so the placeholder value is OK.
// See ThreadStackManagerImpl.
uint16_t discriminator = 3840;
discerner.mLength = 12;
discerner.mValue = discriminator;
ChipLogProgress(DeviceLayer, "Joiner Discerner: %u", discriminator);
otJoinerSetDiscerner(mOTInst, &discerner);
}
{
otJoinerPskd pskd;
// This is dead code to remove, so the placeholder value is OK.d
// See ThreadStackManagerImpl.
uint32_t pincode = 20202021;
snprintf(pskd.m8, sizeof(pskd.m8) - 1, "%09" PRIu32, pincode);
ChipLogProgress(DeviceLayer, "Joiner PSKd: %s", pskd.m8);
error = MapOpenThreadError(otJoinerStart(mOTInst, pskd.m8, NULL, NULL, NULL, NULL, NULL,
&GenericThreadStackManagerImpl_OpenThread::OnJoinerComplete, this));
}
exit:
Impl()->UnlockThreadStack();
ChipLogProgress(DeviceLayer, "Joiner start: %s", chip::ErrorStr(error));
return error;
}
template <class ImplClass>
void GenericThreadStackManagerImpl_OpenThread<ImplClass>::_UpdateNetworkStatus()
{
// Thread is not enabled, then we are not trying to connect to the network.
VerifyOrReturn(ThreadStackMgrImpl().IsThreadEnabled() && mpStatusChangeCallback != nullptr);
ByteSpan datasetTLV;
Thread::OperationalDataset dataset;
uint8_t extpanid[chip::Thread::kSizeExtendedPanId];
// If we have not provisioned any Thread network, return the status from last network scan,
// If we have provisioned a network, we assume the ot-br-posix is activitely connecting to that network.
ReturnOnFailure(ThreadStackMgrImpl().GetThreadProvision(datasetTLV));
ReturnOnFailure(dataset.Init(datasetTLV));
// The Thread network is not enabled, but has a different extended pan id.
ReturnOnFailure(dataset.GetExtendedPanId(extpanid));
// If we don't have a valid dataset, we are not attempting to connect the network.
// We have already connected to the network, thus return success.
if (ThreadStackMgrImpl().IsThreadAttached())
{
mpStatusChangeCallback->OnNetworkingStatusChange(Status::kSuccess, MakeOptional(ByteSpan(extpanid)), NullOptional);
}
else
{
mpStatusChangeCallback->OnNetworkingStatusChange(Status::kNetworkNotFound, MakeOptional(ByteSpan(extpanid)),
MakeOptional(static_cast<int32_t>(OT_ERROR_DETACHED)));
}
}
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT
static_assert(OPENTHREAD_API_VERSION >= 156, "SRP Client requires a more recent OpenThread version");
template <class ImplClass>
void GenericThreadStackManagerImpl_OpenThread<ImplClass>::OnSrpClientNotification(otError aError,
const otSrpClientHostInfo * aHostInfo,
const otSrpClientService * aServices,
const otSrpClientService * aRemovedServices,
void * aContext)
{
switch (aError)
{
case OT_ERROR_NONE: {
ChipLogProgress(DeviceLayer, "OnSrpClientNotification: Last requested operation completed successfully");
if (aHostInfo)
{
if (aHostInfo->mState == OT_SRP_CLIENT_ITEM_STATE_REMOVED)
{
// Clear memory for removed host
memset(ThreadStackMgrImpl().mSrpClient.mHostName, 0, sizeof(ThreadStackMgrImpl().mSrpClient.mHostName));
ThreadStackMgrImpl().mSrpClient.mIsInitialized = true;
ThreadStackMgrImpl().mSrpClient.mInitializedCallback(ThreadStackMgrImpl().mSrpClient.mCallbackContext,
CHIP_NO_ERROR);
}
}
if (aRemovedServices)
{
otSrpClientService * otService = const_cast<otSrpClientService *>(aRemovedServices);
otSrpClientService * next = nullptr;
using Service = typename SrpClient::Service;
// Clear memory for all removed services.
do
{
next = otService->mNext;
auto service = reinterpret_cast<Service *>(reinterpret_cast<size_t>(otService) - offsetof(Service, mService));
memset(service, 0, sizeof(Service));
otService = next;
} while (otService);
}
break;
}
case OT_ERROR_PARSE:
ChipLogError(DeviceLayer, "OnSrpClientNotification: Parsing operaton failed");
break;
case OT_ERROR_NOT_FOUND:
ChipLogError(DeviceLayer, "OnSrpClientNotification: Domain name or RRset does not exist");
break;
case OT_ERROR_NOT_IMPLEMENTED:
ChipLogError(DeviceLayer, "OnSrpClientNotification: Server does not support query type");
break;
case OT_ERROR_SECURITY:
ChipLogError(DeviceLayer, "OnSrpClientNotification: Operation refused for security reasons");
break;
case OT_ERROR_DUPLICATED:
ChipLogError(DeviceLayer, "OnSrpClientNotification: Domain name or RRset is duplicated");
break;
case OT_ERROR_RESPONSE_TIMEOUT:
ChipLogError(DeviceLayer, "OnSrpClientNotification: Timed out waiting on server response");
break;
case OT_ERROR_INVALID_ARGS:
ChipLogError(DeviceLayer, "OnSrpClientNotification: Invalid service structure detected");
break;
case OT_ERROR_NO_BUFS:
ChipLogError(DeviceLayer, "OnSrpClientNotification: Insufficient buffer to handle message");
break;
case OT_ERROR_FAILED:
ChipLogError(DeviceLayer, "OnSrpClientNotification: Internal server error occurred");
break;
default:
ChipLogError(DeviceLayer, "OnSrpClientNotification: Unknown error occurred");
break;
}
}
template <class ImplClass>
void GenericThreadStackManagerImpl_OpenThread<ImplClass>::OnSrpClientStateChange(const otSockAddr * aServerSockAddr,
void * aContext)
{
if (aServerSockAddr)
{
ChipLogProgress(DeviceLayer, "SRP Client was started, detected server: %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x",
Encoding::BigEndian::HostSwap16(aServerSockAddr->mAddress.mFields.m16[0]),
Encoding::BigEndian::HostSwap16(aServerSockAddr->mAddress.mFields.m16[1]),
Encoding::BigEndian::HostSwap16(aServerSockAddr->mAddress.mFields.m16[2]),
Encoding::BigEndian::HostSwap16(aServerSockAddr->mAddress.mFields.m16[3]),
Encoding::BigEndian::HostSwap16(aServerSockAddr->mAddress.mFields.m16[4]),
Encoding::BigEndian::HostSwap16(aServerSockAddr->mAddress.mFields.m16[5]),
Encoding::BigEndian::HostSwap16(aServerSockAddr->mAddress.mFields.m16[6]),
Encoding::BigEndian::HostSwap16(aServerSockAddr->mAddress.mFields.m16[7]));
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD_DNS_CLIENT
// Set DNS server config to be set at the SRP server address
otDnsQueryConfig dnsConfig = *otDnsClientGetDefaultConfig(ThreadStackMgrImpl().OTInstance());
dnsConfig.mServerSockAddr.mAddress = aServerSockAddr->mAddress;
otDnsClientSetDefaultConfig(ThreadStackMgrImpl().OTInstance(), &dnsConfig);
#endif
}
else
{
ChipLogProgress(DeviceLayer, "SRP Client was stopped, because current server is no longer detected.");
}
}
template <class ImplClass>
bool GenericThreadStackManagerImpl_OpenThread<ImplClass>::SrpClient::Service::Matches(const char * aInstanceName,
const char * aName) const
{
return IsUsed() && (strcmp(mService.mInstanceName, aInstanceName) == 0) && (strcmp(mService.mName, aName) == 0);
}
template <class ImplClass>
CHIP_ERROR GenericThreadStackManagerImpl_OpenThread<ImplClass>::_AddSrpService(const char * aInstanceName, const char * aName,
uint16_t aPort,
const Span<const char * const> & aSubTypes,
const Span<const Dnssd::TextEntry> & aTxtEntries,
uint32_t aLeaseInterval, uint32_t aKeyLeaseInterval)
{
CHIP_ERROR error = CHIP_NO_ERROR;
typename SrpClient::Service * srpService = nullptr;
size_t entryId = 0;
FixedBufferAllocator alloc;
Impl()->LockThreadStack();
VerifyOrExit(mSrpClient.mIsInitialized, error = CHIP_ERROR_WELL_UNINITIALIZED);
VerifyOrExit(aInstanceName, error = CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrExit(aName, error = CHIP_ERROR_INVALID_ARGUMENT);
// Try to find an empty slot in array for the new service and
// remove the possible existing entry from anywhere in the list
for (typename SrpClient::Service & service : mSrpClient.mServices)
{
// Remove possible existing entry
if (service.Matches(aInstanceName, aName))
{
SuccessOrExit(error = MapOpenThreadError(otSrpClientClearService(mOTInst, &service.mService)));
// Clear memory immediately, as OnSrpClientNotification will not be called.
memset(&service, 0, sizeof(service));
}
if ((srpService == nullptr) && !service.IsUsed())
{
// Assign first empty slot found in array for a new service.
srpService = &service;
// Keep looping to remove possible existing entry further in the list
}
}
// Verify there is a slot found for the new service.
VerifyOrExit(srpService != nullptr, error = CHIP_ERROR_BUFFER_TOO_SMALL);
alloc.Init(srpService->mServiceBuffer);
otSrpClientSetLeaseInterval(mOTInst, aLeaseInterval);
otSrpClientSetKeyLeaseInterval(mOTInst, aKeyLeaseInterval);
srpService->mService.mInstanceName = alloc.Clone(aInstanceName);
srpService->mService.mName = alloc.Clone(aName);
srpService->mService.mPort = aPort;
VerifyOrExit(aSubTypes.size() < ArraySize(srpService->mSubTypes), error = CHIP_ERROR_BUFFER_TOO_SMALL);
entryId = 0;
for (const char * subType : aSubTypes)
{
srpService->mSubTypes[entryId++] = alloc.Clone(subType);
}
srpService->mSubTypes[entryId] = nullptr;
srpService->mService.mSubTypeLabels = srpService->mSubTypes;
// Initialize TXT entries
VerifyOrExit(aTxtEntries.size() <= ArraySize(srpService->mTxtEntries), error = CHIP_ERROR_BUFFER_TOO_SMALL);
entryId = 0;
for (const chip::Dnssd::TextEntry & entry : aTxtEntries)
{
using OtTxtValueLength = decltype(srpService->mTxtEntries[entryId].mValueLength);
static_assert(SrpClient::kServiceBufferSize <= std::numeric_limits<OtTxtValueLength>::max(),
"DNS TXT value length may not fit in otDnsTxtEntry structure");
// TXT entry keys are constants, so they don't need to be cloned
srpService->mTxtEntries[entryId].mKey = entry.mKey;
srpService->mTxtEntries[entryId].mValue = alloc.Clone(entry.mData, entry.mDataSize);
srpService->mTxtEntries[entryId].mValueLength = static_cast<OtTxtValueLength>(entry.mDataSize);
++entryId;
}
using OtNumTxtEntries = decltype(srpService->mService.mNumTxtEntries);
static_assert(ArraySize(srpService->mTxtEntries) <= std::numeric_limits<OtNumTxtEntries>::max(),
"Number of DNS TXT entries may not fit in otSrpClientService structure");
srpService->mService.mNumTxtEntries = static_cast<OtNumTxtEntries>(aTxtEntries.size());
srpService->mService.mTxtEntries = srpService->mTxtEntries;
VerifyOrExit(!alloc.AnyAllocFailed(), error = CHIP_ERROR_BUFFER_TOO_SMALL);
ChipLogProgress(DeviceLayer, "advertising srp service: %s.%s", srpService->mService.mInstanceName, srpService->mService.mName);
error = MapOpenThreadError(otSrpClientAddService(mOTInst, &(srpService->mService)));
exit:
if (srpService != nullptr && error != CHIP_NO_ERROR)
{
memset(srpService, 0, sizeof(*srpService));
}
Impl()->UnlockThreadStack();
return error;
}
template <class ImplClass>
CHIP_ERROR GenericThreadStackManagerImpl_OpenThread<ImplClass>::_RemoveSrpService(const char * aInstanceName, const char * aName)
{
CHIP_ERROR error = CHIP_NO_ERROR;
typename SrpClient::Service * srpService = nullptr;
VerifyOrExit(mSrpClient.mIsInitialized, error = CHIP_ERROR_WELL_UNINITIALIZED);
Impl()->LockThreadStack();
VerifyOrExit(aInstanceName, error = CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrExit(aName, error = CHIP_ERROR_INVALID_ARGUMENT);
// Check if service to remove exists.
for (typename SrpClient::Service & service : mSrpClient.mServices)
{
if (service.Matches(aInstanceName, aName))
{
srpService = &service;
break;
}
}
VerifyOrExit(srpService, error = MapOpenThreadError(OT_ERROR_NOT_FOUND));
ChipLogProgress(DeviceLayer, "removing srp service: %s.%s", aInstanceName, aName);
error = MapOpenThreadError(otSrpClientRemoveService(mOTInst, &(srpService->mService)));
exit:
Impl()->UnlockThreadStack();
return error;
}
template <class ImplClass>
CHIP_ERROR GenericThreadStackManagerImpl_OpenThread<ImplClass>::_InvalidateAllSrpServices()
{
Impl()->LockThreadStack();
for (typename SrpClient::Service & service : mSrpClient.mServices)
{
if (service.IsUsed())
{
service.mIsInvalid = true;
}
}
Impl()->UnlockThreadStack();
return CHIP_NO_ERROR;
}
template <class ImplClass>
CHIP_ERROR GenericThreadStackManagerImpl_OpenThread<ImplClass>::_RemoveInvalidSrpServices()
{
CHIP_ERROR error = CHIP_NO_ERROR;
VerifyOrExit(mSrpClient.mIsInitialized, error = CHIP_ERROR_WELL_UNINITIALIZED);
Impl()->LockThreadStack();
for (typename SrpClient::Service & service : mSrpClient.mServices)
{
if (service.IsUsed() && service.mIsInvalid)
{
ChipLogProgress(DeviceLayer, "removing srp service: %s.%s", service.mService.mInstanceName, service.mService.mName);
error = MapOpenThreadError(otSrpClientRemoveService(mOTInst, &service.mService));
SuccessOrExit(error);
}
}
exit:
Impl()->UnlockThreadStack();
return error;
}
template <class ImplClass>
CHIP_ERROR GenericThreadStackManagerImpl_OpenThread<ImplClass>::_SetupSrpHost(const char * aHostName)
{
CHIP_ERROR error = CHIP_NO_ERROR;
Inet::IPAddress hostAddress;
VerifyOrExit(mSrpClient.mIsInitialized, error = CHIP_ERROR_WELL_UNINITIALIZED);
Impl()->LockThreadStack();
VerifyOrExit(aHostName, error = CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrExit(strlen(aHostName) <= Dnssd::kHostNameMaxLength, error = CHIP_ERROR_INVALID_STRING_LENGTH);
// Avoid adding the same host name multiple times
if (strcmp(mSrpClient.mHostName, aHostName) != 0)
{
strcpy(mSrpClient.mHostName, aHostName);
error = MapOpenThreadError(otSrpClientSetHostName(mOTInst, mSrpClient.mHostName));
SuccessOrExit(error);
}
// Check if device has any external IPv6 assigned. If not, host will be set without IPv6 addresses
// and updated later on.
if (ThreadStackMgr().GetExternalIPv6Address(hostAddress) == CHIP_NO_ERROR)
{
memcpy(&mSrpClient.mHostAddress.mFields.m32, hostAddress.Addr, sizeof(hostAddress.Addr));
error = MapOpenThreadError(otSrpClientSetHostAddresses(mOTInst, &mSrpClient.mHostAddress, 1));
}
exit:
Impl()->UnlockThreadStack();
return error;
}
template <class ImplClass>
CHIP_ERROR GenericThreadStackManagerImpl_OpenThread<ImplClass>::_ClearSrpHost(const char * aHostName)
{
CHIP_ERROR error = CHIP_NO_ERROR;
Impl()->LockThreadStack();
VerifyOrExit(aHostName, error = CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrExit(strlen(aHostName) <= Dnssd::kHostNameMaxLength, error = CHIP_ERROR_INVALID_STRING_LENGTH);
VerifyOrExit(mSrpClient.mInitializedCallback, error = CHIP_ERROR_INCORRECT_STATE);
// Add host and remove it with notifying SRP server to clean old information related to the host.
// Avoid adding the same host name multiple times
if (strcmp(mSrpClient.mHostName, aHostName) != 0)
{
strcpy(mSrpClient.mHostName, aHostName);
error = MapOpenThreadError(otSrpClientSetHostName(mOTInst, mSrpClient.mHostName));
SuccessOrExit(error);
}
error = MapOpenThreadError(otSrpClientRemoveHostAndServices(mOTInst, false, true));
exit:
Impl()->UnlockThreadStack();
return error;
}
template <class ImplClass>
CHIP_ERROR GenericThreadStackManagerImpl_OpenThread<ImplClass>::_SetSrpDnsCallbacks(DnsAsyncReturnCallback aInitCallback,
DnsAsyncReturnCallback aErrorCallback,
void * aContext)
{
mSrpClient.mInitializedCallback = aInitCallback;
mSrpClient.mCallbackContext = aContext;
return CHIP_NO_ERROR;
}
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD_DNS_CLIENT
template <class ImplClass>
CHIP_ERROR GenericThreadStackManagerImpl_OpenThread<ImplClass>::FromOtDnsResponseToMdnsData(
otDnsServiceInfo & serviceInfo, const char * serviceType, chip::Dnssd::DnssdService & mdnsService,
DnsServiceTxtEntries & serviceTxtEntries)
{
char protocol[chip::Dnssd::kDnssdProtocolTextMaxSize + 1];
if (strchr(serviceInfo.mHostNameBuffer, '.') == nullptr)
return CHIP_ERROR_INVALID_ARGUMENT;
// Extract from the <hostname>.<domain-name>. the <hostname> part.
size_t substringSize = strchr(serviceInfo.mHostNameBuffer, '.') - serviceInfo.mHostNameBuffer;
if (substringSize >= ArraySize(mdnsService.mHostName))
{
return CHIP_ERROR_INVALID_ARGUMENT;
}
strncpy(mdnsService.mHostName, serviceInfo.mHostNameBuffer, substringSize);
// Append string terminating character.
mdnsService.mHostName[substringSize] = '\0';
if (strchr(serviceType, '.') == nullptr)
return CHIP_ERROR_INVALID_ARGUMENT;
// Extract from the <type>.<protocol>.<domain-name>. the <type> part.
substringSize = strchr(serviceType, '.') - serviceType;
if (substringSize >= ArraySize(mdnsService.mType))
{
return CHIP_ERROR_INVALID_ARGUMENT;
}
strncpy(mdnsService.mType, serviceType, substringSize);
// Append string terminating character.
mdnsService.mType[substringSize] = '\0';
// Extract from the <type>.<protocol>.<domain-name>. the <protocol> part.
const char * protocolSubstringStart = serviceType + substringSize + 1;
if (strchr(protocolSubstringStart, '.') == nullptr)
return CHIP_ERROR_INVALID_ARGUMENT;
substringSize = strchr(protocolSubstringStart, '.') - protocolSubstringStart;
if (substringSize >= ArraySize(protocol))
{
return CHIP_ERROR_INVALID_ARGUMENT;
}
strncpy(protocol, protocolSubstringStart, substringSize);
// Append string terminating character.
protocol[substringSize] = '\0';
if (strncmp(protocol, "_udp", chip::Dnssd::kDnssdProtocolTextMaxSize) == 0)
{
mdnsService.mProtocol = chip::Dnssd::DnssdServiceProtocol::kDnssdProtocolUdp;
}
else if (strncmp(protocol, "_tcp", chip::Dnssd::kDnssdProtocolTextMaxSize) == 0)
{
mdnsService.mProtocol = chip::Dnssd::DnssdServiceProtocol::kDnssdProtocolTcp;
}
else
{
mdnsService.mProtocol = chip::Dnssd::DnssdServiceProtocol::kDnssdProtocolUnknown;
}
mdnsService.mPort = serviceInfo.mPort;
mdnsService.mInterface = Inet::InterfaceId::Null();
mdnsService.mAddressType = Inet::IPAddressType::kIPv6;
mdnsService.mAddress = chip::Optional<chip::Inet::IPAddress>(ToIPAddress(serviceInfo.mHostAddress));
otDnsTxtEntryIterator iterator;
otDnsInitTxtEntryIterator(&iterator, serviceInfo.mTxtData, serviceInfo.mTxtDataSize);
otDnsTxtEntry txtEntry;
FixedBufferAllocator alloc(serviceTxtEntries.mBuffer);
uint8_t entryIndex = 0;
while ((otDnsGetNextTxtEntry(&iterator, &txtEntry) == OT_ERROR_NONE) && entryIndex < kMaxDnsServiceTxtEntriesNumber)
{
if (txtEntry.mKey == nullptr || txtEntry.mValue == nullptr)
continue;
serviceTxtEntries.mTxtEntries[entryIndex].mKey = alloc.Clone(txtEntry.mKey);
serviceTxtEntries.mTxtEntries[entryIndex].mData = alloc.Clone(txtEntry.mValue, txtEntry.mValueLength);
serviceTxtEntries.mTxtEntries[entryIndex].mDataSize = txtEntry.mValueLength;
entryIndex++;
}
ReturnErrorCodeIf(alloc.AnyAllocFailed(), CHIP_ERROR_BUFFER_TOO_SMALL);
mdnsService.mTextEntries = serviceTxtEntries.mTxtEntries;
mdnsService.mTextEntrySize = entryIndex;
return CHIP_NO_ERROR;
}
template <class ImplClass>
void GenericThreadStackManagerImpl_OpenThread<ImplClass>::DispatchResolve(intptr_t context)
{
auto * dnsResult = reinterpret_cast<DnsResult *>(context);
ThreadStackMgrImpl().mDnsResolveCallback(dnsResult->context, &(dnsResult->mMdnsService), Span<Inet::IPAddress>(),
dnsResult->error);
Platform::Delete<DnsResult>(dnsResult);
}
template <class ImplClass>
void GenericThreadStackManagerImpl_OpenThread<ImplClass>::DispatchBrowseEmpty(intptr_t context)
{
auto * dnsResult = reinterpret_cast<DnsResult *>(context);
ThreadStackMgrImpl().mDnsBrowseCallback(dnsResult->context, nullptr, 0, dnsResult->error);
Platform::Delete<DnsResult>(dnsResult);
}
template <class ImplClass>
void GenericThreadStackManagerImpl_OpenThread<ImplClass>::DispatchBrowse(intptr_t context)
{
auto * dnsResult = reinterpret_cast<DnsResult *>(context);
ThreadStackMgrImpl().mDnsBrowseCallback(dnsResult->context, &dnsResult->mMdnsService, 1, dnsResult->error);
Platform::Delete<DnsResult>(dnsResult);
}
template <class ImplClass>
void GenericThreadStackManagerImpl_OpenThread<ImplClass>::OnDnsBrowseResult(otError aError, const otDnsBrowseResponse * aResponse,
void * aContext)
{
CHIP_ERROR error;
// type buffer size is kDnssdTypeAndProtocolMaxSize + . + kMaxDomainNameSize + . + termination character
char type[Dnssd::kDnssdTypeAndProtocolMaxSize + SrpClient::kMaxDomainNameSize + 3];
// hostname buffer size is kHostNameMaxLength + . + kMaxDomainNameSize + . + termination character
char hostname[Dnssd::kHostNameMaxLength + SrpClient::kMaxDomainNameSize + 3];
// secure space for the raw TXT data in the worst-case scenario relevant for Matter:
// each entry consists of txt_entry_size (1B) + txt_entry_key + "=" + txt_entry_data
uint8_t txtBuffer[kMaxDnsServiceTxtEntriesNumber + kTotalDnsServiceTxtBufferSize];
otDnsServiceInfo serviceInfo;
uint16_t index = 0;
bool wasAnythingBrowsed = false;
if (ThreadStackMgrImpl().mDnsBrowseCallback == nullptr)
{
ChipLogError(DeviceLayer, "Invalid dns browse callback");
return;
}
VerifyOrExit(aError == OT_ERROR_NONE, error = MapOpenThreadError(aError));
error = MapOpenThreadError(otDnsBrowseResponseGetServiceName(aResponse, type, sizeof(type)));
VerifyOrExit(error == CHIP_NO_ERROR, );
char serviceName[Dnssd::Common::kInstanceNameMaxLength + 1];
while (otDnsBrowseResponseGetServiceInstance(aResponse, index, serviceName, sizeof(serviceName)) == OT_ERROR_NONE)
{
serviceInfo.mHostNameBuffer = hostname;
serviceInfo.mHostNameBufferSize = sizeof(hostname);
serviceInfo.mTxtData = txtBuffer;
serviceInfo.mTxtDataSize = sizeof(txtBuffer);
error = MapOpenThreadError(otDnsBrowseResponseGetServiceInfo(aResponse, serviceName, &serviceInfo));
VerifyOrExit(error == CHIP_NO_ERROR, );
DnsResult * dnsResult = Platform::New<DnsResult>(aContext, MapOpenThreadError(aError));
error = FromOtDnsResponseToMdnsData(serviceInfo, type, dnsResult->mMdnsService, dnsResult->mServiceTxtEntry);
if (CHIP_NO_ERROR == error)
{
// Invoke callback for every service one by one instead of for the whole list due to large memory size needed to
// allocate on
// stack.
static_assert(ArraySize(dnsResult->mMdnsService.mName) >= ArraySize(serviceName),
"The target buffer must be big enough");
Platform::CopyString(dnsResult->mMdnsService.mName, serviceName);
DeviceLayer::PlatformMgr().ScheduleWork(DispatchBrowse, reinterpret_cast<intptr_t>(dnsResult));
wasAnythingBrowsed = true;
}
else
{
Platform::Delete<DnsResult>(dnsResult);
}
index++;
}
exit:
// In case no service was found invoke callback to notify about failure. In other case it was already called before.
if (!wasAnythingBrowsed)
{
DnsResult * dnsResult = Platform::New<DnsResult>(aContext, MapOpenThreadError(aError));
DeviceLayer::PlatformMgr().ScheduleWork(DispatchBrowseEmpty, reinterpret_cast<intptr_t>(dnsResult));
}
}
template <class ImplClass>
CHIP_ERROR GenericThreadStackManagerImpl_OpenThread<ImplClass>::_DnsBrowse(const char * aServiceName, DnsBrowseCallback aCallback,
void * aContext)
{
CHIP_ERROR error = CHIP_NO_ERROR;
Impl()->LockThreadStack();
VerifyOrExit(aServiceName, error = CHIP_ERROR_INVALID_ARGUMENT);
mDnsBrowseCallback = aCallback;
// Append default SRP domain name to the service name.
// fullServiceName buffer size is kDnssdFullTypeAndProtocolMaxSize + . + kDefaultDomainNameSize + null-terminator.
char fullServiceName[Dnssd::kDnssdFullTypeAndProtocolMaxSize + 1 + SrpClient::kDefaultDomainNameSize + 1];
snprintf(fullServiceName, sizeof(fullServiceName), "%s.%s", aServiceName, SrpClient::kDefaultDomainName);
error = MapOpenThreadError(otDnsClientBrowse(mOTInst, fullServiceName, OnDnsBrowseResult, aContext, /* config */ nullptr));
exit:
Impl()->UnlockThreadStack();
return error;
}
template <class ImplClass>
void GenericThreadStackManagerImpl_OpenThread<ImplClass>::OnDnsResolveResult(otError aError, const otDnsServiceResponse * aResponse,
void * aContext)
{
CHIP_ERROR error;
DnsResult * dnsResult = Platform::New<DnsResult>(aContext, MapOpenThreadError(aError));
// type buffer size is kDnssdTypeAndProtocolMaxSize + . + kMaxDomainNameSize + . + termination character
char type[Dnssd::kDnssdTypeAndProtocolMaxSize + SrpClient::kMaxDomainNameSize + 3];
// hostname buffer size is kHostNameMaxLength + . + kMaxDomainNameSize + . + termination character
char hostname[Dnssd::kHostNameMaxLength + SrpClient::kMaxDomainNameSize + 3];
// secure space for the raw TXT data in the worst-case scenario relevant for Matter:
// each entry consists of txt_entry_size (1B) + txt_entry_key + "=" + txt_entry_data
uint8_t txtBuffer[kMaxDnsServiceTxtEntriesNumber + kTotalDnsServiceTxtBufferSize];
otDnsServiceInfo serviceInfo;
if (ThreadStackMgrImpl().mDnsResolveCallback == nullptr)
{
ChipLogError(DeviceLayer, "Invalid dns browse callback");
return;
}
VerifyOrExit(aError == OT_ERROR_NONE, error = MapOpenThreadError(aError));
error = MapOpenThreadError(otDnsServiceResponseGetServiceName(aResponse, dnsResult->mMdnsService.mName,
sizeof(dnsResult->mMdnsService.mName), type, sizeof(type)));
VerifyOrExit(error == CHIP_NO_ERROR, );
serviceInfo.mHostNameBuffer = hostname;
serviceInfo.mHostNameBufferSize = sizeof(hostname);
serviceInfo.mTxtData = txtBuffer;
serviceInfo.mTxtDataSize = sizeof(txtBuffer);
error = MapOpenThreadError(otDnsServiceResponseGetServiceInfo(aResponse, &serviceInfo));
VerifyOrExit(error == CHIP_NO_ERROR, );
error = FromOtDnsResponseToMdnsData(serviceInfo, type, dnsResult->mMdnsService, dnsResult->mServiceTxtEntry);
exit:
dnsResult->error = error;
DeviceLayer::PlatformMgr().ScheduleWork(DispatchResolve, reinterpret_cast<intptr_t>(dnsResult));
}
template <class ImplClass>
CHIP_ERROR GenericThreadStackManagerImpl_OpenThread<ImplClass>::_DnsResolve(const char * aServiceName, const char * aInstanceName,
DnsResolveCallback aCallback, void * aContext)
{
CHIP_ERROR error = CHIP_NO_ERROR;
Impl()->LockThreadStack();
const otDnsQueryConfig * defaultConfig = otDnsClientGetDefaultConfig(mOTInst);
VerifyOrExit(aServiceName && aInstanceName, error = CHIP_ERROR_INVALID_ARGUMENT);
mDnsResolveCallback = aCallback;
// Append default SRP domain name to the service name.
// fullServiceName buffer size is kDnssdTypeAndProtocolMaxSize + . separator + kDefaultDomainNameSize + termination character.
char fullServiceName[Dnssd::kDnssdTypeAndProtocolMaxSize + 1 + SrpClient::kDefaultDomainNameSize + 1];
snprintf(fullServiceName, sizeof(fullServiceName), "%s.%s", aServiceName, SrpClient::kDefaultDomainName);
error = MapOpenThreadError(
otDnsClientResolveService(mOTInst, aInstanceName, fullServiceName, OnDnsResolveResult, aContext, defaultConfig));
exit:
Impl()->UnlockThreadStack();
return error;
}
#endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD_DNS_CLIENT
#endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT
} // namespace Internal
} // namespace DeviceLayer
} // namespace chip
#endif // GENERIC_THREAD_STACK_MANAGER_IMPL_OPENTHREAD_IPP
|
/*
** The MIT License (MIT)
**
** Copyright (c) 2020, National Cybersecurity Agency of France (ANSSI)
**
** 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.
**
** Author:
** - Guillaume Bouffard <guillaume.bouffard@ssi.gouv.fr>
*/
#include "../jc_config.h"
#include "../types.hpp"
#include "../context.hpp"
#include "../debug.hpp"
#include "../exceptions.hpp"
#include "../heap.hpp"
#include "../jc_handlers/flashmemory.hpp"
#include "../jc_handlers/jc_class.hpp"
#include "../jc_handlers/jc_cp.hpp"
#include "../jc_handlers/jc_export.hpp"
#include "../jc_handlers/jc_import.hpp"
#include "../jc_handlers/jc_method.hpp"
#include "../jc_handlers/package.hpp"
#include "../stack.hpp"
#include "bytecodes.hpp"
namespace jcvm {
/**
* Invoke instance method; dispatch based on class
*
* Format:
* invokevirtual
* indexbyte1
* indexbyte2
*
* Forms:
* invokevirtual = 139 (0x8b)
*
* Stack:
* ..., objectref, [arg1, [arg2 ...]] -> ...
*
* Description:
*
* The unsigned indexbyte1 and indexbyte2 are used to construct an index
* into the constant pool of the current package (§3.5 Frames), where the
* value of the index is (indexbyte1 << 8) | indexbyte2. The constant pool
* item at that index must be of type CONSTANT_VirtualMethodref (§6.8.2
* CONSTANT_InstanceFieldref, CONSTANT_VirtualMethodref, and
* CONSTANT_SuperMethodref), a reference to a class and a virtual method
* token. The specified method is resolved. The method must not be <init>,
* an instance initialization method, or <clinit>, a class or interface
* initialization method. Finally, if the resolved method is protected,
* and it is a member of a superclass of the current class, and the method
* is not declared in the same package as the current class, then the
* class of objectref must be either the current class or a subclass of
* the current class.
*
* The resolved method reference includes an unsigned index into the
* method table of the resolved class and an unsigned byte nargs that must
* not be zero.
*
* The objectref must be of type reference. The index is an unsigned byte
* that is used as an index into the method table of the class of the type
* of objectref. If the objectref is an array type, then the method table
* of class Object (§2.2.1.4 Unsupported Classes) is used. The table entry
* at that index includes a direct reference to the method's code and
* modifier information.
*
* The objectref must be followed on the operand stack by nargs - 1 words of
* arguments, where the number of words of arguments and the type and order of
* the values they represent must be consistent with those of the selected
* instance method.
*
* The nargs - 1 words of arguments and objectref are popped from the
* operand stack. A new stack frame is created for the method being
* invoked, and objectref and the arguments are made the values of its
* first nargs words of local variables, with objectref in local variable
* 0, arg1 in local variable 1, and so on. The new stack frame is then
* made current, and the Java Card virtual machine pc is set to the opcode
* of the first instruction of the method to be invoked. Execution
* continues with the first instruction of the method.
*
* Runtime Exception:
*
* If objectref is null, the invokevirtual instruction throws a
* NullPointerException.
*
* In some circumstances, the invokevirtual instruction may throw a
* SecurityException if the current context (§3.4 Contexts) is not the
* context (§3.4 Contexts) of the object referenced by objectref. The
* exact circumstances when the exception will be thrown are specified in
* Chapter 6 of the Runtime Environment Specification, Java Card 3
* Platform, v3.0.5, Classic Edition. If the current context is not the
* object's context and the Java Card RE permits invocation of the method,
* the invokevirtual instruction will cause a context switch (§3.4
* Contexts) to the object's context before invoking the method, and will
* cause a return context switch to the previous context when the invoked
* method returns.
*
*/
void Bytecodes::bc_invokevirtual() {
Stack &stack = this->context.getStack();
ConstantPool_Handler cp_handler(this->context.getCurrentPackage());
Method_Handler method_handler(this->context);
Class_Handler class_handler(this->context.getCurrentPackage());
pc_t &pc = stack.getPC();
uint16_t index = pc.getNextShort();
TRACE_JCVM_DEBUG("INVOKEVIRTUAL 0x%04X", index);
auto virtual_method_ref_info = cp_handler.getVirtualMethodRef(index);
auto method_offset = class_handler.getMethodOffset(virtual_method_ref_info);
// Calling the method and updating PC value
method_handler.setPackage(method_offset.first);
method_handler.callVirtualMethod(method_offset.second);
// checking if the this reference is non NULL
jref_t objectref = stack.readLocal_Reference((uint8_t)0);
if (objectref.isNullPointer()) {
throw Exceptions::NullPointerException;
}
auto instance = context.getHeap().getInstance(objectref);
return;
}
/**
* Invoke instance method; special handling for superclass, private, and
* instance initialization method invocations
*
* Format:
* invokespecial
* indexbyte1
* indexbyte2
*
* Forms:
* invokespecial = 140 (0x8c)
*
* Stack:
* ..., objectref, [arg1, [arg2 ...]] -> ...
*
* Description:
*
* The unsigned indexbyte1 and indexbyte2 are used to construct an index
* into the constant pool of the current package (§3.5 Frames), where the
* value of the index is (indexbyte1 << 8) | indexbyte2. If the invoked
* method is a private instance method or an instance initialization
* method, the constant pool item at index must be of type
* CONSTANT_StaticMethodref (§6.8.3 CONSTANT_StaticFieldref and
* CONSTANT_StaticMethodref), a reference to a statically linked instance
* method. If the invoked method is a superclass method, the constant pool
* item at index must be of type CONSTANT_SuperMethodref (6.8.2
* CONSTANT_InstanceFieldref, CONSTANT_VirtualMethodref, and
* CONSTANT_SuperMethodref), a reference to an instance method of a
* specified class. The reference is resolved. The resolved method must
* not be <clinit>, a class or interface initialization method. If the
* method is <init>, an instance initialization method, then the method
* must only be invoked once on an uninitialized object, and before the
* first backward branch following the execution of the new instruction
* that allocated the object. Finally, if the resolved method is
* protected, and it is a member of a superclass of the current class, and
* the method is not declared in the same package as the current class,
* then the class of objectref must be either the current class or a
* subclass of the current class.
*
* The resolved method includes the code for the method, an unsigned byte
* nargs that must not be zero, and the method's modifier information.
*
* The objectref must be of type reference, and must be followed on the
* operand stack by nargs - 1 words of arguments, where the number of
* words of arguments and the type and order of the values they represent
* must be consistent with those of the selected instance method.
*
* The nargs - 1 words of arguments and objectref are popped from the
* operand stack. A new stack frame is created for the method being
* invoked, and objectref and the arguments are made the values of its
* first nargs words of local variables, with objectref in local variable
* 0, arg1 in local variable 1, and so on. The new stack frame is then
* made current, and the Java Card virtual machine pc is set to the opcode
* of the first instruction of the method to be invoked. Execution
* continues with the first instruction of the method.
*
* Runtime Exception:
*
* If objectref is null, the invokespecial instruction throws a
* NullPointerException.
*/
void Bytecodes::bc_invokespecial() {
Context &context = this->context;
Stack &stack = context.getStack();
ConstantPool_Handler cp_handler(context.getCurrentPackage());
Method_Handler method_handler(context);
Class_Handler class_handler(context.getCurrentPackage());
uint16_t method_offset;
pc_t &pc = stack.getPC();
uint16_t index = pc.getNextShort();
TRACE_JCVM_DEBUG("INVOKESPECIAL 0x%04X", index);
auto cp_entry = cp_handler.getCPEntry(index);
switch (cp_entry.tag) {
case JC_CP_TAG_CONSTANT_STATICMETHODREF:
/*
* The invoked method is a private instance method or an instance
* initialization method.
*/
{
jc_cap_static_method_ref_info method_ref =
cp_entry.info.static_method_ref_info;
if (IS_CP_INTERNAL_REF(method_ref.static_method_ref)) {
method_offset = HTONS(method_ref.static_method_ref.internal_ref.offset);
} else { // Is external static method ref
Import_Handler imported(context.getCurrentPackage());
const jc_cap_package_info *package_aid = imported.getPackageAID(
method_ref.static_method_ref.external_ref.package_token & 0x7F);
Package exported_package(imported.getPackageIndex(package_aid));
Export_Handler export_handler(exported_package);
method_offset = export_handler.getExportedStaticMethodOffset(
method_ref.static_method_ref.external_ref.class_token,
method_ref.static_method_ref.external_ref.token);
method_handler.setPackage(exported_package);
}
}
break;
case JC_CP_TAG_CONSTANT_SUPERMETHODREF: {
/*
* The invoked method is a superclass method.
*/
auto virtual_method_ref_info = cp_handler.getVirtualMethodRef(index);
#ifdef JCVM_DYNAMIC_CHECKS_CAP
/*
* The class referenced in the CONSTANT_SuperMethodref_info structure must
* always be internal to the class that defines the method that contains
* the Java language-level super invocation. The class must be defined in
* this package.
*/
if (virtual_method_ref_info.class_ref.isExternalClassRef()) {
// TODO
throw Exceptions::SecurityException;
}
#endif /* JCVM_DYNAMIC_CHECKS_CAP */
auto method = class_handler.getMethodOffset(virtual_method_ref_info);
method_handler.setPackage(method.first);
method_offset = method.second;
} break;
default:
// NOTE: Wrong invokestatic method type
throw Exceptions::SecurityException;
break;
}
// Calling the method
method_handler.callVirtualMethod(method_offset);
// checking if the this reference is non NULL
jref_t objectref = stack.readLocal_Reference((uint8_t)0);
if (objectref.isNullPointer()) {
// NOTE: Manipulated objectref is null
throw Exceptions::NullPointerException;
}
// auto instance = context.getHeap().getInstance(objectref);
// instance->setInitialized(true);
return;
}
/**
* Invoke a class (static) method
*
* Format:
* invokestatic
* indexbyte1
* indexbyte2
*
* Forms:
* invokestatic = 141 (0x8d)
*
* Stack:
* ..., [arg1, [arg2 ...]] -> ...
*
* Description:
*
* The unsigned indexbyte1 and indexbyte2 are used to construct an index
* into the constant pool of the current package (§3.5 Frames), where the
* value of the index is (indexbyte1 << 8) | indexbyte2. The constant pool
* item at that index must be of type CONSTANT_StaticMethodref (§6.8.3
* CONSTANT_StaticFieldref and CONSTANT_StaticMethodref), a reference to a
* static method. The method must not be <init>, an instance
* initialization method, or <clinit>, a class or interface initialization
* method. It must be static, and therefore cannot be abstract.
*
* The resolved method includes the code for the method, an unsigned byte
* nargs that may be zero, and the method's modifier information.
*
* The operand stack must contain nargs words of arguments, where the
* number of words of arguments and the type and order of the values they
* represent must be consistent with those of the resolved method.
*
* The nargs words of arguments are popped from the operand stack. A new
* stack frame is created for the method being invoked, and the words of
* arguments are made the values of its first nargs words of local
* variables, with arg1 in local variable 0, arg2 in local variable 1, and
* so on. The new stack frame is then made current, and the Java Card
* virtual machine pc is set to the opcode of the first instruction of the
* method to be invoked. Execution continues with the first instruction of
* the method.
*
*/
void Bytecodes::bc_invokestatic() {
Context &context = this->context;
Stack &stack = context.getStack();
ConstantPool_Handler cp_handler(context.getCurrentPackage());
Method_Handler method_handler(context);
Class_Handler class_handler(context.getCurrentPackage());
uint16_t method_offset;
pc_t &pc = stack.getPC();
uint16_t index = pc.getNextShort();
TRACE_JCVM_DEBUG("INVOKESTATIC 0x%04X", index);
auto cp_entry = cp_handler.getCPEntry(index);
if (cp_entry.tag != JC_CP_TAG_CONSTANT_STATICMETHODREF) {
throw Exceptions::SecurityException;
}
jc_cap_static_method_ref_info method_ref =
cp_entry.info.static_method_ref_info;
if (IS_CP_INTERNAL_REF(method_ref.static_method_ref)) {
method_offset = method_ref.static_method_ref.internal_ref.offset
// remove handler_count element's size
- sizeof(jc_cap_method_component::handler_count);
} else { // Is external static method ref
Import_Handler imported(context.getCurrentPackage());
const jc_cap_package_info *package_aid = imported.getPackageAID(
method_ref.static_method_ref.external_ref.package_token & 0x7F);
Package exported_package(imported.getPackageIndex(package_aid));
Export_Handler export_handler(exported_package);
method_offset = export_handler.getExportedStaticMethodOffset(
method_ref.static_method_ref.external_ref.class_token,
method_ref.static_method_ref.external_ref.token);
method_handler.setPackage(exported_package);
}
// Calling the method
method_handler.callStaticMethod(method_offset);
return;
}
/**
* Invoke interface method
*
* Format:
* invokeinterface
* nargs
* indexbyte1
* indexbyte2
* method
*
* Forms:
* invokeinterface = 142 (0x8e)
*
* Stack:
* ..., objectref, [arg1, [arg2 ...]] -> ...
*
* Description:
*
* The unsigned indexbyte1 and indexbyte2 are used to construct an index
* into the constant pool of the current package (§3.5 Frames), where the
* value of the index is (indexbyte1 << 8) | indexbyte2. The constant pool
* item at that index must be of type CONSTANT_Classref (§6.8.1
* CONSTANT_Classref), a reference to an interface class. The specified
* interface is resolved.
*
* The nargs operand is an unsigned byte that must not be zero.
*
* The method operand is an unsigned byte that is the interface method
* token for the method to be invoked. The interface method must not be
* <init> or an instance initialization method.
*
* The object-ref must be of type reference and must be followed on the
* operand stack by nargs - 1 words of arguments. The number of words of
* arguments and the type and order of the values they represent must be
* consistent with those of the selected interface method.
*
* The interface table of the class of the type of objectref is
* determined. If objectref is an array type, then the interface table of
* class Object (§2.2.1.4 Unsupported Classes) is used. The interface
* table is searched for the resolved interface. The result of the search
* is a table that is used to map the method token to a index.
*
* The index is an unsigned byte that is used as an index into the method
* table of the class of the type of objectref. If the objectref is an
* array type, then the method table of class Object is used. The table
* entry at that index includes a direct reference to the method's code
* and modifier information.
*
* The nargs - 1 words of arguments and objectref are popped from the
* operand stack. A new stack frame is created for the method being
* invoked, and objectref and the arguments are made the values of its
* first nargs words of local variables, with objectref in local variable
* 0, arg1 in local variable 1, and so on. The new stack frame is then
* made current, and the Java Card virtual machine pc is set to the opcode
* of the first instruction of the method to be invoked. Execution
* continues with the first instruction of the method.
*
* Runtime Exception:
*
* If objectref is null, the invokeinterface instruction throws a
* NullPointerException.
*
* Notes:
*
* In some circumstances, the invokeinterface instruction may throw a
* SecurityException if the current context (§3.4 Contexts) is not the
* context (§3.4 Contexts) of the object referenced by objectref. The
* exact circumstances when the exception will be thrown are specified in
* Chapter 6 of the Runtime Environment Specification, Java Card 3
* Platform, v3.0.5, Classic Edition. If the current context is not the
* object's context and the Java Card RE permits invocation of the method,
* the invokeinterface instruction will cause a context switch (§3.4
* Contexts) to the object's context before invoking the method, and will
* cause a return context switch to the previous context when the invoked
* method returns.
*
*/
void Bytecodes::bc_invokeinterface() {
Context &context = this->context;
Stack &stack = context.getStack();
ConstantPool_Handler cp_handler(context.getCurrentPackage());
Method_Handler method_handler(context);
Class_Handler class_handler(context.getCurrentPackage());
pc_t &pc = stack.getPC();
TRACE_JCVM_DEBUG("INVOKEINTERFACE");
uint8_t nargs = pc.getNextByte();
uint16_t index = pc.getNextShort();
uint8_t method = pc.getNextByte();
if (nargs == 0) {
throw Exceptions::SecurityException;
}
auto interface_ref = cp_handler.getClassRef(index);
// nargs-th arguments should be popped to access the objectref.
jref_t objectref = stack.get_Pushed_Element(nargs);
if (objectref.isNullPointer()) {
throw Exceptions::NullPointerException;
}
if (objectref.isArray()) { // Is an array
// class variable must point to Object class.
jref_t thisref = stack.readLocal_Reference((uint8_t)0);
auto instance = context.getHeap().getInstance(thisref);
auto classref = ConstantPool_Handler(instance->getPackageID())
.getClassRefFromClassIndex(instance->getClassIndex());
auto method_offset = class_handler.getImplementedInterfaceMethodOffset(
classref, interface_ref, method, true);
// Calling the method
method_handler.setPackage(method_offset.first);
method_handler.callVirtualMethod(method_offset.second);
} else { // is an interface
auto instance = context.getHeap().getInstance(objectref);
auto classref = ConstantPool_Handler(instance->getPackageID())
.getClassRefFromClassIndex(instance->getClassIndex());
auto method_offset = class_handler.getImplementedInterfaceMethodOffset(
classref, interface_ref, method);
// Calling the method
method_handler.setPackage(method_offset.first);
method_handler.callVirtualMethod(method_offset.second);
}
return;
}
} // namespace jcvm
|
/*
* Special support for eabi and SVR4
*
* Copyright (C) 1995, 1996, 1998, 2000, 2001 Free Software Foundation, Inc.
* Written By Michael Meissner
*
* This file 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 2, or (at your option) any
* later version.
*
* In addition to the permissions in the GNU General Public License, the
* Free Software Foundation gives you unlimited permission to link the
* compiled version of this file with other programs, and to distribute
* those programs without any restriction coming from the use of this
* file. (The General Public License restrictions do apply in other
* respects; for example, they cover modification of the file, and
* distribution when not linked into another program.)
*
* This file is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
* As a special exception, if you link this library with files
* compiled with GCC to produce an executable, this does not cause
* the resulting executable to be covered by the GNU General Public License.
* This exception does not however invalidate any other reasons why
* the executable file might be covered by the GNU General Public License.
*/
/* Do any initializations needed for the eabi environment */
.file "eabi.asm"
.section ".text"
#include "ppc-asm.h"
#ifndef __powerpc64__
.section ".got2","aw"
.align 2
.LCTOC1 = . /* +32768 */
/* Table of addresses */
.Ltable = .-.LCTOC1
.long .LCTOC1 /* address we are really at */
.Lsda = .-.LCTOC1
.long _SDA_BASE_ /* address of the first small data area */
.Lsdas = .-.LCTOC1
.long __SDATA_START__ /* start of .sdata/.sbss section */
.Lsdae = .-.LCTOC1
.long __SBSS_END__ /* end of .sdata/.sbss section */
.Lsda2 = .-.LCTOC1
.long _SDA2_BASE_ /* address of the second small data area */
.Lsda2s = .-.LCTOC1
.long __SDATA2_START__ /* start of .sdata2/.sbss2 section */
.Lsda2e = .-.LCTOC1
.long __SBSS2_END__ /* end of .sdata2/.sbss2 section */
#ifdef _RELOCATABLE
.Lgots = .-.LCTOC1
.long __GOT_START__ /* Global offset table start */
.Lgotm1 = .-.LCTOC1
.long _GLOBAL_OFFSET_TABLE_-4 /* end of GOT ptrs before BLCL + 3 reserved words */
.Lgotm2 = .-.LCTOC1
.long _GLOBAL_OFFSET_TABLE_+12 /* start of GOT ptrs after BLCL + 3 reserved words */
.Lgote = .-.LCTOC1
.long __GOT_END__ /* Global offset table end */
.Lgot2s = .-.LCTOC1
.long __GOT2_START__ /* -mrelocatable GOT pointers start */
.Lgot2e = .-.LCTOC1
.long __GOT2_END__ /* -mrelocatable GOT pointers end */
.Lfixups = .-.LCTOC1
.long __FIXUP_START__ /* start of .fixup section */
.Lfixupe = .-.LCTOC1
.long __FIXUP_END__ /* end of .fixup section */
.Lctors = .-.LCTOC1
.long __CTOR_LIST__ /* start of .ctor section */
.Lctore = .-.LCTOC1
.long __CTOR_END__ /* end of .ctor section */
.Ldtors = .-.LCTOC1
.long __DTOR_LIST__ /* start of .dtor section */
.Ldtore = .-.LCTOC1
.long __DTOR_END__ /* end of .dtor section */
.Lexcepts = .-.LCTOC1
.long __EXCEPT_START__ /* start of .gcc_except_table section */
.Lexcepte = .-.LCTOC1
.long __EXCEPT_END__ /* end of .gcc_except_table section */
.Linit = .-.LCTOC1
.long .Linit_p /* address of variable to say we've been called */
.text
.align 2
.Lptr:
.long .LCTOC1-.Laddr /* PC relative pointer to .got2 */
#endif
.data
.align 2
.Linit_p:
.long 0
.text
FUNC_START(__eabi)
/* Eliminate -mrelocatable code if not -mrelocatable, so that this file can
be assembled with other assemblers than GAS. */
#ifndef _RELOCATABLE
addis 10,0,.Linit_p@ha /* init flag */
addis 11,0,.LCTOC1@ha /* load address of .LCTOC1 */
lwz 9,.Linit_p@l(10) /* init flag */
addi 11,11,.LCTOC1@l
cmplwi 2,9,0 /* init flag != 0? */
bnelr 2 /* return now, if we've been called already */
stw 1,.Linit_p@l(10) /* store a non-zero value in the done flag */
#else /* -mrelocatable */
mflr 0
bl .Laddr /* get current address */
.Laddr:
mflr 12 /* real address of .Laddr */
lwz 11,(.Lptr-.Laddr)(12) /* linker generated address of .LCTOC1 */
add 11,11,12 /* correct to real pointer */
lwz 12,.Ltable(11) /* get linker's idea of where .Laddr is */
lwz 10,.Linit(11) /* address of init flag */
subf. 12,12,11 /* calculate difference */
lwzx 9,10,12 /* done flag */
cmplwi 2,9,0 /* init flag != 0? */
mtlr 0 /* restore in case branch was taken */
bnelr 2 /* return now, if we've been called already */
stwx 1,10,12 /* store a non-zero value in the done flag */
beq+ 0,.Lsdata /* skip if we don't need to relocate */
/* We need to relocate the .got2 pointers. */
lwz 3,.Lgot2s(11) /* GOT2 pointers start */
lwz 4,.Lgot2e(11) /* GOT2 pointers end */
add 3,12,3 /* adjust pointers */
add 4,12,4
bl FUNC_NAME(__eabi_convert) /* convert pointers in .got2 section */
/* Fixup the .ctor section for static constructors */
lwz 3,.Lctors(11) /* constructors pointers start */
lwz 4,.Lctore(11) /* constructors pointers end */
bl FUNC_NAME(__eabi_convert) /* convert constructors */
/* Fixup the .dtor section for static destructors */
lwz 3,.Ldtors(11) /* destructors pointers start */
lwz 4,.Ldtore(11) /* destructors pointers end */
bl FUNC_NAME(__eabi_convert) /* convert destructors */
/* Fixup the .gcc_except_table section for G++ exceptions */
lwz 3,.Lexcepts(11) /* exception table pointers start */
lwz 4,.Lexcepte(11) /* exception table pointers end */
bl FUNC_NAME(__eabi_convert) /* convert exceptions */
/* Fixup the addresses in the GOT below _GLOBAL_OFFSET_TABLE_-4 */
lwz 3,.Lgots(11) /* GOT table pointers start */
lwz 4,.Lgotm1(11) /* GOT table pointers below _GLOBAL_OFFSET_TABLE-4 */
bl FUNC_NAME(__eabi_convert) /* convert lower GOT */
/* Fixup the addresses in the GOT above _GLOBAL_OFFSET_TABLE_+12 */
lwz 3,.Lgotm2(11) /* GOT table pointers above _GLOBAL_OFFSET_TABLE+12 */
lwz 4,.Lgote(11) /* GOT table pointers end */
bl FUNC_NAME(__eabi_convert) /* convert lower GOT */
/* Fixup any user initialized pointers now (the compiler drops pointers to */
/* each of the relocs that it does in the .fixup section). */
.Lfix:
lwz 3,.Lfixups(11) /* fixup pointers start */
lwz 4,.Lfixupe(11) /* fixup pointers end */
bl FUNC_NAME(__eabi_uconvert) /* convert user initialized pointers */
.Lsdata:
mtlr 0 /* restore link register */
#endif /* _RELOCATABLE */
/* Only load up register 13 if there is a .sdata and/or .sbss section */
lwz 3,.Lsdas(11) /* start of .sdata/.sbss section */
lwz 4,.Lsdae(11) /* end of .sdata/.sbss section */
cmpw 1,3,4 /* .sdata/.sbss section non-empty? */
beq- 1,.Lsda2l /* skip loading r13 */
lwz 13,.Lsda(11) /* load r13 with _SDA_BASE_ address */
/* Only load up register 2 if there is a .sdata2 and/or .sbss2 section */
.Lsda2l:
lwz 3,.Lsda2s(11) /* start of .sdata/.sbss section */
lwz 4,.Lsda2e(11) /* end of .sdata/.sbss section */
cmpw 1,3,4 /* .sdata/.sbss section non-empty? */
beq+ 1,.Ldone /* skip loading r2 */
lwz 2,.Lsda2(11) /* load r2 with _SDA2_BASE_ address */
/* Done adjusting pointers, return by way of doing the C++ global constructors. */
.Ldone:
b FUNC_NAME(__init) /* do any C++ global constructors (which returns to caller) */
FUNC_END(__eabi)
/* Special subroutine to convert a bunch of pointers directly.
r0 has original link register
r3 has low pointer to convert
r4 has high pointer to convert
r5 .. r10 are scratch registers
r11 has the address of .LCTOC1 in it.
r12 has the value to add to each pointer
r13 .. r31 are unchanged */
FUNC_START(__eabi_convert)
cmplw 1,3,4 /* any pointers to convert? */
subf 5,3,4 /* calculate number of words to convert */
bclr 4,4 /* return if no pointers */
srawi 5,5,2
addi 3,3,-4 /* start-4 for use with lwzu */
mtctr 5
.Lcvt:
lwzu 6,4(3) /* pointer to convert */
cmpi 0,6,0
beq- .Lcvt2 /* if pointer is null, don't convert */
add 6,6,12 /* convert pointer */
stw 6,0(3)
.Lcvt2:
bdnz+ .Lcvt
blr
FUNC_END(__eabi_convert)
/* Special subroutine to convert the pointers the user has initialized. The
compiler has placed the address of the initialized pointer into the .fixup
section.
r0 has original link register
r3 has low pointer to convert
r4 has high pointer to convert
r5 .. r10 are scratch registers
r11 has the address of .LCTOC1 in it.
r12 has the value to add to each pointer
r13 .. r31 are unchanged */
FUNC_START(__eabi_uconvert)
cmplw 1,3,4 /* any pointers to convert? */
subf 5,3,4 /* calculate number of words to convert */
bclr 4,4 /* return if no pointers */
srawi 5,5,2
addi 3,3,-4 /* start-4 for use with lwzu */
mtctr 5
.Lucvt:
lwzu 6,4(3) /* next pointer to pointer to convert */
add 6,6,12 /* adjust pointer */
lwz 7,0(6) /* get the pointer it points to */
stw 6,0(3) /* store adjusted pointer */
add 7,7,12 /* adjust */
stw 7,0(6)
bdnz+ .Lucvt
blr
FUNC_END(__eabi_uconvert)
#endif
|
; A165563: a(n) = 1 + 2*n + n^2 + 2*n^3 + n^4.
; 1,7,41,151,409,911,1777,3151,5201,8119,12121,17447,24361,33151,44129,57631,74017,93671,117001,144439,176441,213487,256081,304751,360049,422551,492857,571591,659401,756959,864961,984127,1115201,1258951,1416169,1587671,1774297,1976911,2196401,2433679,2689681,2965367,3261721,3579751,3920489,4284991,4674337,5089631,5532001,6002599,6502601,7033207,7595641,8191151,8821009,9486511,10188977,10929751,11710201,12531719,13395721,14303647,15256961,16257151,17305729,18404231,19554217,20757271,22015001,23329039,24701041,26132687,27625681,29181751,30802649,32490151,34246057,36072191,37970401,39942559,41990561,44116327,46321801,48608951,50979769,53436271,55980497,58614511,61340401,64160279,67076281,70090567,73205321,76422751,79745089,83174591,86713537,90364231,94129001,98010199
mov $2,1
add $2,$0
pow $2,2
mul $2,$0
add $2,2
mul $0,$2
div $0,2
mul $0,2
add $0,1
|
;
; ZX 81 pseudo-Gray Library Functions
;
; Written by Stefano Bodrato - Oct 2007
;
; $Id: g_clg.asm,v 1.3 2017-01-02 22:57:58 aralbrec Exp $
;
;
;Usage: g_clg(GrayLevel)
PUBLIC g_clg
PUBLIC _g_clg
EXTERN base_graphics
EXTERN graybit1
EXTERN graybit2
.g_clg
._g_clg
pop hl
pop bc
ld a,c ;GrayLevel
push bc
push hl
ld hl,(graybit1)
rra
jr nc,lbl1
push af
ld a,0
call cls
pop af
jr lbl2
.lbl1
push af
ld a,255
call cls
pop af
.lbl2
ld hl,(graybit2)
rra
ld a,0
jr c,lbl3
ld a,255
.lbl3
.cls
ld (hl),a
ld d,h
ld e,l
inc de
ld bc,2047
ldir
ret
|
;
; Copyright (c) 2010 The WebM project authors. All Rights Reserved.
;
; Use of this source code is governed by a BSD-style license
; that can be found in the LICENSE file in the root of the source
; tree. An additional intellectual property rights grant can be found
; in the file PATENTS. All contributing project authors may
; be found in the AUTHORS file in the root of the source tree.
;
%include "aom_ports/x86_abi_support.asm"
;void aom_plane_add_noise_sse2(unsigned char *start, unsigned char *noise,
; unsigned char blackclamp[16],
; unsigned char whiteclamp[16],
; unsigned char bothclamp[16],
; unsigned int width, unsigned int height,
; int pitch)
global sym(aom_plane_add_noise_sse2) PRIVATE
sym(aom_plane_add_noise_sse2):
push rbp
mov rbp, rsp
SHADOW_ARGS_TO_STACK 8
GET_GOT rbx
push rsi
push rdi
; end prolog
; get the clamps in registers
mov rdx, arg(2) ; blackclamp
movdqu xmm3, [rdx]
mov rdx, arg(3) ; whiteclamp
movdqu xmm4, [rdx]
mov rdx, arg(4) ; bothclamp
movdqu xmm5, [rdx]
.addnoise_loop:
call sym(LIBAOM_RAND) WRT_PLT
mov rcx, arg(1) ;noise
and rax, 0xff
add rcx, rax
mov rdi, rcx
movsxd rcx, dword arg(5) ;[Width]
mov rsi, arg(0) ;Pos
xor rax,rax
.addnoise_nextset:
movdqu xmm1,[rsi+rax] ; get the source
psubusb xmm1, xmm3 ; subtract black clamp
paddusb xmm1, xmm5 ; add both clamp
psubusb xmm1, xmm4 ; subtract whiteclamp
movdqu xmm2,[rdi+rax] ; get the noise for this line
paddb xmm1,xmm2 ; add it in
movdqu [rsi+rax],xmm1 ; store the result
add rax,16 ; move to the next line
cmp rax, rcx
jl .addnoise_nextset
movsxd rax, dword arg(7) ; Pitch
add arg(0), rax ; Start += Pitch
sub dword arg(6), 1 ; Height -= 1
jg .addnoise_loop
; begin epilog
pop rdi
pop rsi
RESTORE_GOT
UNSHADOW_ARGS
pop rbp
ret
SECTION_RODATA
align 16
rd42:
times 8 dw 0x04
four8s:
times 4 dd 8
|
db 0 ; species ID placeholder
db 255, 10, 10, 55, 75, 135
; hp atk def spd sat sdf
db NORMAL, NORMAL ; type
db 30 ; catch rate
db 255 ; base exp
db NO_ITEM, LUCKY_EGG ; items
db GENDER_F100 ; gender ratio
db 40 ; step cycles to hatch
INCBIN "gfx/pokemon/blissey/front.dimensions"
db GROWTH_FAST ; growth rate
dn EGG_FAIRY, EGG_FAIRY ; egg groups
db 140 ; happiness
; tm/hm learnset
tmhm FOCUS_PUNCH, WATER_PULSE, CALM_MIND, TOXIC, HAIL, HIDDEN_POWER, SUNNY_DAY, ICE_BEAM, BLIZZARD, HYPER_BEAM, LIGHT_SCREEN, PROTECT, RAIN_DANCE, SAFEGUARD, FRUSTRATION, SOLARBEAM, IRON_TAIL, THUNDERBOLT, THUNDER, EARTHQUAKE, RETURN, PSYCHIC_M, SHADOW_BALL, BRICK_BREAK, DOUBLE_TEAM, SHOCK_WAVE, FLAMETHROWER, SANDSTORM, FIRE_BLAST, ROCK_TOMB, FACADE, SECRET_POWER, REST, ATTRACT, SKILL_SWAP, SNATCH, FOCUS_BLAST, FLING, CHARGE_BEAM, ENDURE, DRAIN_PUNCH, RECYCLE, GIGA_IMPACT, FLASH, AVALANCHE, THUNDER_WAVE, STEALTH_ROCK, PSYCH_UP, CAPTIVATE, ROCK_SLIDE, SLEEP_TALK, NATURAL_GIFT, DREAM_EATER, GRASS_KNOT, SWAGGER, SUBSTITUTE, STRENGTH, ROCK_SMASH, ROCK_CLIMB, ENDEAVOR, FIRE_PUNCH, HELPING_HAND, ICE_PUNCH, ICY_WIND, LAST_RESORT, MUD_SLAP, ROLLOUT, SNORE, THUNDERPUNCH, ZEN_HEADBUTT
; end
|
#include <bits/stdc++.h>
using namespace std;
int main()
{
int a,b;
scanf("%d%d",&a,&b);
if(a<b) printf("O JOGO DUROU %d HORA(S)\n",b-a);
else printf("O JOGO DUROU %d HORA(S)\n",b+24-a);
return 0;
}
|
// Commodore 64 PRG executable file
.file [name="dword.prg", type="prg", segments="Program"]
.segmentdef Program [segments="Basic, Code, Data"]
.segmentdef Basic [start=$0801]
.segmentdef Code [start=$80d]
.segmentdef Data [startAfter="Code"]
.segment Basic
:BasicUpstart(main)
.segment Code
main: {
.const a = $ee6b2800
.label SCREEN = $400
.label b = 2
ldx #0
__b1:
// dword b = a + i
txa
clc
adc #<a
sta.z b
lda #>a
adc #0
sta.z b+1
lda #<a>>$10
adc #0
sta.z b+2
lda #>a>>$10
adc #0
sta.z b+3
// byte c = (byte) b
lda.z b
// SCREEN[i] = c
sta SCREEN,x
// for( byte i: 0..100)
inx
cpx #$65
bne __b1
// }
rts
}
|
; You may customize this and other start-up templates;
; The location of this template is c:\emu8086\inc\0_com_template.txt
org 100h
arr0 DB 3,6,3,6,3;
ret
|
; A258073: a(n) = 1 + 78557*2^n.
; 157115,314229,628457,1256913,2513825,5027649,10055297,20110593,40221185,80442369,160884737,321769473,643538945,1287077889,2574155777,5148311553,10296623105,20593246209,41186492417,82372984833,164745969665,329491939329,658983878657,1317967757313,2635935514625,5271871029249,10543742058497,21087484116993,42174968233985,84349936467969,168699872935937,337399745871873,674799491743745,1349598983487489,2699197966974977,5398395933949953,10796791867899905,21593583735799809,43187167471599617,86374334943199233,172748669886398465,345497339772796929,690994679545593857,1381989359091187713,2763978718182375425,5527957436364750849,11055914872729501697,22111829745459003393,44223659490918006785,88447318981836013569,176894637963672027137,353789275927344054273,707578551854688108545,1415157103709376217089,2830314207418752434177,5660628414837504868353,11321256829675009736705,22642513659350019473409,45285027318700038946817,90570054637400077893633,181140109274800155787265,362280218549600311574529,724560437099200623149057,1449120874198401246298113,2898241748396802492596225,5796483496793604985192449,11592966993587209970384897,23185933987174419940769793,46371867974348839881539585,92743735948697679763079169,185487471897395359526158337,370974943794790719052316673,741949887589581438104633345,1483899775179162876209266689,2967799550358325752418533377,5935599100716651504837066753,11871198201433303009674133505,23742396402866606019348267009,47484792805733212038696534017,94969585611466424077393068033,189939171222932848154786136065,379878342445865696309572272129,759756684891731392619144544257,1519513369783462785238289088513,3039026739566925570476578177025,6078053479133851140953156354049,12156106958267702281906312708097,24312213916535404563812625416193,48624427833070809127625250832385,97248855666141618255250501664769,194497711332283236510501003329537,388995422664566473021002006659073,777990845329132946042004013318145,1555981690658265892084008026636289,3111963381316531784168016053272577,6223926762633063568336032106545153,12447853525266127136672064213090305,24895707050532254273344128426180609,49791414101064508546688256852361217,99582828202129017093376513704722433
mov $1,2
pow $1,$0
sub $1,1
mul $1,157114
add $1,157115
mov $0,$1
|
;
; int cpc_model();
;
; Results:
; 0 - 464
; 1 - 664
; 2 - 6128
; $Id: cpc_model.asm,v 1.7 2016-06-10 21:12:36 dom Exp $
INCLUDE "cpcfirm.def"
SECTION code_clib
PUBLIC cpc_model
PUBLIC _cpc_model
.cpc_model
._cpc_model
call firmware
defw kl_probe_rom ; 0B915H
ld a,h ; version
ld hl,1
rra
ret c ; 664
ld l,2
rra
ret c ; 6128
ld l,h
ret ; 464
|
; A170059: Number of reduced words of length n in Coxeter group on 50 generators S_i with relations (S_i)^2 = (S_i S_j)^36 = I.
; 1,50,2450,120050,5882450,288240050,14123762450,692064360050,33911153642450,1661646528480050,81420679895522450,3989613314880600050,195491052429149402450,9579061569028320720050,469374016882387715282450
add $0,1
mov $3,1
lpb $0
sub $0,1
add $2,$3
div $3,$2
mul $2,49
lpe
mov $0,$2
div $0,49
|
; A074795: Number of numbers k <= n such that tau(k) == 0 (mod 3) where tau(k) = A000005(k) is the number of divisors of k.
; 0,0,0,1,1,1,1,1,2,2,2,3,3,3,3,3,3,4,4,5,5,5,5,5,6,6,6,7,7,7,7,8,8,8,8,9,9,9,9,9,9,9,9,10,11,11,11,11,12,13,13,14,14,14,14,14,14,14,14,15,15,15,16,16,16,16,16,17,17,17,17,18,18,18,19,20,20,20,20,20,20,20,20,21,21,21,21,21,21,22,22,23,23,23,23,24,24,25,26,27,27,27,27,27,27,27,27,28,28,28,28,28,28,28,28,29,30,30,30,30,31,31,31,32,32,33,33,33,33,33,33,34,34,34,34,34,34,34,34,35,35,35,35,36,36,36,37,38,38,39,39,39,40,40,40,41,41,41,41,42,42,42,42,43,43,43,43,43,44,44,45,46,46,46,47,47,47,47,47,48,48,48,48,48,48,48,48,49,49,49,49,49,49,49,49,50,50,51,51,52,52,52,52,53,53,53,54,54,54,54,54,55,55,55,55,55,55,55,55,56,56,56,56,57,58,58,58,59,59,59,59,59,59,60,60,61,61,61,61,61,61,62,63,64,65,65,65,65,65,65
mov $4,$0
mov $6,$0
lpb $6,1
clr $0,4
mov $0,$4
sub $6,1
sub $0,$6
cal $0,5 ; d(n) (also called tau(n) or sigma_0(n)), the number of divisors of n.
add $1,3
mov $3,$0
gcd $3,$1
add $2,$3
mov $1,$2
div $1,2
add $5,$1
lpe
mov $1,$5
|
; A202201: Number of (n+2) X 9 binary arrays avoiding patterns 001 and 101 in rows and columns.
; 2430,11880,44550,138996,378378,926640,2084940,4375800,8664084,16325712,29476980,51279480,86337900,141210432,225054126,350430300,534298050,799227000,1174863690,1699689420,2423110950,3407929200,4733235000,6497785008,8823915144,11862053280,15795897480,20848330800,27288148536,35437678848,45681382890,58475525940,74359016550,93965516424,118036929582,147438385380,183174836130,226409396400,278483557572,340939417896,415544075100,504316335600,609555901500,733875203880,880234058340,1051977326400,1252875774150,1487170327500,1759619931498,2075553229464,2440924286130,2862372587580,3347287559550,3903877854576,4541245667568,5269466348640,6099673591440,7044150484800,8116426725264,9331382297952,10705357943280,12256272737280,14003749123650,15969245746212,18176198441166,20650169759400,23419007400150,26513011948500,29965114320570,33811063331760,38089623815100,42842785728600,48115984702500,53958334489488,60422871793284,67566813963480,75451830057180,84144325780800,93715742838366,104242873225788,115808189023890,128500188256440,142413757393050,157650551090604,174319389780822,192536675725680,212426828176680,234122738288400,257766244451352,283508628723936,311511135058200,341945510029200,374994566793000,410852773013760,449726863515930,491836478433300,537414827642550,586709382285000,639982594196478,697512644081604,759594219285330,826539322031280,898678109013300,976359763243656,1059953399078508,1149849001358640,1246458399620940,1350216278353800,1461581224287444,1581036811728192,1709092726963830,1846285932785580,1993181874190650,2150375726347992,2318493685928706,2498194306921500,2690169882072750,2895147871110000,3113892376927200,3347205670929600,3595929768756000,3860948057616000,4143186976500000,4443617750539968,4763258180819424,5103174490951680,5464483231766130,5848353245463300,6256007690620446,6688726129450728,7147846678740390,7634768225909940,8150952711667050,8697927480740784
mov $3,$0
mov $0,1
add $0,$3
add $0,9
mov $2,$0
bin $0,8
mov $3,$0
mov $0,0
mov $1,$3
sub $2,8
add $0,$2
mul $0,$3
add $1,$0
sub $1,135
mul $1,18
add $1,2430
|
; A135989: a(n) = 6*n + 3 + 90*floor((6*n+3)/10).
; 3,9,105,201,207,303,309,405,501,507,603,609,705,801,807,903,909,1005,1101,1107,1203,1209,1305,1401,1407,1503,1509,1605,1701,1707,1803,1809,1905,2001,2007,2103,2109,2205,2301,2307,2403,2409,2505,2601,2607,2703
mov $3,$0
add $0,6
mul $0,5
mov $4,5
mov $5,3
add $5,$3
add $0,$5
lpb $0,1
sub $0,6
trn $0,4
add $5,3
add $5,$4
mov $2,$5
mov $4,4
add $5,8
lpe
add $0,$2
mov $1,$0
sub $1,56
mul $1,6
add $1,3
|
; A075520: 4*prime(n) + (prime(n) mod 4).
; 10,15,21,31,47,53,69,79,95,117,127,149,165,175,191,213,239,245,271,287,293,319,335,357,389,405,415,431,437,453,511,527,549,559,597,607,629,655,671,693,719,725,767,773,789,799,847,895,911,917,933,959,965,1007,1029,1055,1077,1087,1109,1125,1135,1173,1231,1247,1253,1269,1327,1349,1391,1397,1413,1439,1471,1493,1519,1535,1557,1589,1605,1637,1679,1685,1727,1733,1759,1775,1797,1829,1845,1855,1871,1919,1951,1967,1999,2015,2037,2085,2095,2165
seq $0,6005 ; The odd prime numbers together with 1.
sub $0,2
max $3,$0
mul $0,2
mov $1,$0
add $1,4
add $3,1
mov $2,$3
sub $2,$0
mod $2,4
add $0,$2
add $0,$1
add $0,7
|
; A077842: Expansion of (1-x)/(1-2*x-2*x^2-3*x^3).
; 1,1,4,13,37,112,337,1009,3028,9085,27253,81760,245281,735841,2207524,6622573,19867717,59603152,178809457,536428369,1609285108,4827855325,14483565973,43450697920,130352093761,391056281281,1173168843844,3519506531533,10558519594597
mov $1,3
pow $1,$0
mul $1,8
div $1,52
mul $1,3
add $1,1
|
CeladonMart5F_Object:
db $f ; border block
def_warps
warp 12, 1, 0, CELADON_MART_ROOF
warp 16, 1, 1, CELADON_MART_4F
warp 1, 1, 0, CELADON_MART_ELEVATOR
def_signs
sign 14, 1, 5 ; CeladonMart5Text5
def_objects
object SPRITE_GENTLEMAN, 14, 5, WALK, UP_DOWN, 1 ; person
object SPRITE_SAILOR, 2, 6, STAY, NONE, 2 ; person
object SPRITE_CLERK, 5, 3, STAY, DOWN, 3 ; person
object SPRITE_CLERK, 6, 3, STAY, DOWN, 4 ; person
def_warps_to CELADON_MART_5F
|
; A132636: a(n) = Fibonacci(n) mod n^3.
; Submitted by Simon Strandgaard
; 0,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,1597,2584,4181,6765,1685,7063,4323,4896,12525,15937,19271,10483,2060,22040,5674,15621,2752,3807,9340,432,46989,19305,11932,62155,31899,12088,22273,3677,32420,68263,8459,92736,25467,19025,31601,76515,13302,131552,62320,125685,60631,8991,101245,43920,213562,20585,247192,139451,42440,65656,141168,102541,168266,288135,180909,139104,8540,355865,134300,174803,141297,255104,279661,307685,75823,114063,450357,479664,535835,11609,498193,142251,352708,574120
add $0,1
mov $1,$0
seq $0,45 ; Fibonacci numbers: F(n) = F(n-1) + F(n-2) with F(0) = 0 and F(1) = 1.
pow $1,3
mod $0,$1
|
.global s_prepare_buffers
s_prepare_buffers:
push %r10
push %r13
push %rbp
push %rbx
push %rcx
push %rdi
push %rsi
lea addresses_WC_ht+0x14cc4, %rsi
lea addresses_A_ht+0x1e7d4, %rdi
nop
nop
sub $63000, %rbx
mov $118, %rcx
rep movsb
nop
nop
cmp $16162, %rbp
lea addresses_UC_ht+0x1c254, %r10
nop
xor $50461, %rbx
mov (%r10), %cx
nop
nop
nop
nop
and $40965, %rcx
lea addresses_UC_ht+0x1df14, %rcx
nop
nop
nop
nop
nop
and %r13, %r13
vmovups (%rcx), %ymm7
vextracti128 $1, %ymm7, %xmm7
vpextrq $0, %xmm7, %rsi
nop
nop
nop
nop
and %r10, %r10
lea addresses_A_ht+0xaac4, %r10
nop
nop
nop
nop
cmp $54043, %rcx
mov (%r10), %si
nop
add %rdi, %rdi
lea addresses_D_ht+0x11764, %rsi
lea addresses_normal_ht+0x1c8d4, %rdi
nop
nop
nop
nop
nop
add %r10, %r10
mov $30, %rcx
rep movsl
nop
nop
sub $16679, %r13
lea addresses_WC_ht+0x17d54, %rcx
nop
nop
xor %rsi, %rsi
mov $0x6162636465666768, %r13
movq %r13, %xmm7
movups %xmm7, (%rcx)
nop
add $9256, %r13
lea addresses_UC_ht+0x47ee, %rbx
nop
nop
nop
nop
nop
and $1899, %rdi
mov $0x6162636465666768, %rsi
movq %rsi, %xmm4
vmovups %ymm4, (%rbx)
nop
nop
nop
nop
add %r13, %r13
pop %rsi
pop %rdi
pop %rcx
pop %rbx
pop %rbp
pop %r13
pop %r10
ret
.global s_faulty_load
s_faulty_load:
push %r11
push %r12
push %r13
push %r14
push %rbp
push %rbx
push %rcx
// Store
lea addresses_WC+0x5264, %rbp
nop
nop
nop
nop
nop
sub $32669, %r12
movw $0x5152, (%rbp)
nop
nop
nop
nop
nop
cmp %rcx, %rcx
// Load
lea addresses_RW+0x197c, %r11
nop
add %rbx, %rbx
movb (%r11), %cl
nop
nop
xor $9425, %r13
// Faulty Load
lea addresses_A+0x3254, %rbx
nop
nop
nop
nop
inc %r13
vmovups (%rbx), %ymm3
vextracti128 $1, %ymm3, %xmm3
vpextrq $1, %xmm3, %rbp
lea oracles, %r12
and $0xff, %rbp
shlq $12, %rbp
mov (%r12,%rbp,1), %rbp
pop %rcx
pop %rbx
pop %rbp
pop %r14
pop %r13
pop %r12
pop %r11
ret
/*
<gen_faulty_load>
[REF]
{'src': {'congruent': 0, 'AVXalign': False, 'same': True, 'size': 32, 'NT': False, 'type': 'addresses_A'}, 'OP': 'LOAD'}
{'OP': 'STOR', 'dst': {'congruent': 4, 'AVXalign': False, 'same': False, 'size': 2, 'NT': False, 'type': 'addresses_WC'}}
{'src': {'congruent': 1, 'AVXalign': False, 'same': False, 'size': 1, 'NT': False, 'type': 'addresses_RW'}, 'OP': 'LOAD'}
[Faulty Load]
{'src': {'congruent': 0, 'AVXalign': False, 'same': True, 'size': 32, 'NT': False, 'type': 'addresses_A'}, 'OP': 'LOAD'}
<gen_prepare_buffer>
{'src': {'congruent': 3, 'same': False, 'type': 'addresses_WC_ht'}, 'OP': 'REPM', 'dst': {'congruent': 3, 'same': True, 'type': 'addresses_A_ht'}}
{'src': {'congruent': 10, 'AVXalign': False, 'same': False, 'size': 2, 'NT': False, 'type': 'addresses_UC_ht'}, 'OP': 'LOAD'}
{'src': {'congruent': 6, 'AVXalign': False, 'same': True, 'size': 32, 'NT': False, 'type': 'addresses_UC_ht'}, 'OP': 'LOAD'}
{'src': {'congruent': 4, 'AVXalign': False, 'same': False, 'size': 2, 'NT': True, 'type': 'addresses_A_ht'}, 'OP': 'LOAD'}
{'src': {'congruent': 4, 'same': True, 'type': 'addresses_D_ht'}, 'OP': 'REPM', 'dst': {'congruent': 6, 'same': False, 'type': 'addresses_normal_ht'}}
{'OP': 'STOR', 'dst': {'congruent': 8, 'AVXalign': False, 'same': False, 'size': 16, 'NT': False, 'type': 'addresses_WC_ht'}}
{'OP': 'STOR', 'dst': {'congruent': 0, 'AVXalign': False, 'same': False, 'size': 32, 'NT': False, 'type': 'addresses_UC_ht'}}
{'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
*/
|
; A082286: a(n) = 18*n + 10.
; 10,28,46,64,82,100,118,136,154,172,190,208,226,244,262,280,298,316,334,352,370,388,406,424,442,460,478,496,514,532,550,568,586,604,622,640,658,676,694,712,730,748,766,784,802,820,838,856,874,892,910,928,946,964,982,1000,1018,1036,1054,1072,1090,1108,1126,1144,1162,1180,1198,1216,1234,1252,1270,1288,1306,1324,1342,1360,1378,1396,1414,1432,1450,1468,1486,1504,1522,1540,1558,1576,1594,1612,1630,1648,1666,1684,1702,1720,1738,1756,1774,1792
mul $0,18
add $0,10
|
; int strncasecmp(const char *s1, const char *s2, size_t n)
SECTION code_clib
SECTION code_string
PUBLIC strncasecmp
EXTERN asm_strncasecmp
strncasecmp:
IF __CPU_GBZ80__ | __CPU_INTEL__
ld hl,sp+2
ld c,(hl)
inc hl
ld b,(hl)
inc hl
ld e,(hl)
inc hl
ld d,(hl)
inc hl
ld a,(hl+)
ld h,(hl)
ld l,e
ld e,a
ld a,d
ld d,h
ld h,a
call asm_strncasecmp
ld d,h
ld e,l
ret
ELSE
pop af
pop bc
pop hl
pop de
push de
push hl
push bc
push af
IF __CLASSIC
IF !__CPU_INTEL__
push ix
ENDIF
call asm_strncasecmp
IF !__CPU_INTEL__
pop ix
ENDIF
ret
ELSE
jp asm_strncasecmp
ENDIF
ENDIF
; SDCC bridge for Classic
IF __CLASSIC
PUBLIC _strncasecmp
defc _strncasecmp = strncasecmp
ENDIF
|
; A105968: a(n) = 4*a(n-1) - a(n-2) - 2*(-1)^n, a(0) = 1, a(1) = 4.
; 1,4,13,50,185,692,2581,9634,35953,134180,500765,1868882,6974761,26030164,97145893,362553410,1353067745,5049717572,18845802541,70333492594,262488167833,979619178740,3655988547125,13644335009762,50921351491921,190041070957924,709242932339773,2646930658401170,9878479701264905,36866988146658452,137589472885368901,513490903394817154,1916374140693899713,7152005659380781700,26691648496829227085,99614588327936126642,371766704814915279481,1387452230931724991284,5178042218911984685653
mov $1,4
mov $2,1
lpb $0
sub $0,1
add $1,$2
add $2,$1
add $1,$2
lpe
add $1,1
div $1,3
mov $0,$1
|
//----------------------------------------------------------------------------
//
// TSDuck - The MPEG Transport Stream Toolkit
// Copyright (c) 2005-2018, Thierry Lelegard
// 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.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
// THE POSSIBILITY OF SUCH DAMAGE.
//
//----------------------------------------------------------------------------
//
// CppUnit test suite for class ts::PluginSharedLibrary
//
//----------------------------------------------------------------------------
#include "tsPluginSharedLibrary.h"
#include "utestCppUnitTest.h"
TSDUCK_SOURCE;
//----------------------------------------------------------------------------
// The test fixture
//----------------------------------------------------------------------------
class PluginTest: public CppUnit::TestFixture
{
public:
virtual void setUp() override;
virtual void tearDown() override;
void testInput();
void testOutput();
void testProcessor();
CPPUNIT_TEST_SUITE(PluginTest);
CPPUNIT_TEST(testInput);
CPPUNIT_TEST(testOutput);
CPPUNIT_TEST(testProcessor);
CPPUNIT_TEST_SUITE_END();
private:
static void display(const ts::PluginSharedLibrary& lib);
};
CPPUNIT_TEST_SUITE_REGISTRATION(PluginTest);
//----------------------------------------------------------------------------
// Initialization.
//----------------------------------------------------------------------------
// Test suite initialization method.
void PluginTest::setUp()
{
}
// Test suite cleanup method.
void PluginTest::tearDown()
{
}
//----------------------------------------------------------------------------
// Unitary tests.
//----------------------------------------------------------------------------
void PluginTest::display(const ts::PluginSharedLibrary& lib)
{
utest::Out() << "* File: " << lib.fileName() << std::endl
<< " isLoaded: " << lib.isLoaded() << std::endl
<< " input: " << ts::UString::YesNo(lib.new_input != nullptr) << std::endl
<< " output: " << ts::UString::YesNo(lib.new_output != nullptr) << std::endl
<< " processor: " << ts::UString::YesNo(lib.new_processor != nullptr) << std::endl;
}
void PluginTest::testInput()
{
ts::PluginSharedLibrary plugin(u"null");
display(plugin);
CPPUNIT_ASSERT(plugin.isLoaded());
CPPUNIT_ASSERT(plugin.new_input != nullptr);
CPPUNIT_ASSERT(plugin.new_output == nullptr);
CPPUNIT_ASSERT(plugin.new_processor == nullptr);
}
void PluginTest::testOutput()
{
ts::PluginSharedLibrary plugin(u"drop");
display(plugin);
CPPUNIT_ASSERT(plugin.isLoaded());
CPPUNIT_ASSERT(plugin.new_input == nullptr);
CPPUNIT_ASSERT(plugin.new_output != nullptr);
CPPUNIT_ASSERT(plugin.new_processor == nullptr);
}
void PluginTest::testProcessor()
{
ts::PluginSharedLibrary plugin(u"skip");
display(plugin);
CPPUNIT_ASSERT(plugin.isLoaded());
CPPUNIT_ASSERT(plugin.new_input == nullptr);
CPPUNIT_ASSERT(plugin.new_output == nullptr);
CPPUNIT_ASSERT(plugin.new_processor != nullptr);
}
|
; A296135: {0->01}-transform of the Fibonacci word A003849.
; 0,1,1,0,1,0,1,1,0,1,1,0,1,0,1,1,0,1,0,1,1,0,1,1,0,1,0,1,1,0,1,1,0,1,0,1,1,0,1,0,1,1,0,1,1,0,1,0,1,1,0,1,0,1,1,0,1,1,0,1,0,1,1,0,1,1,0,1,0,1,1,0,1,0,1,1,0,1,1,0,1,0,1,1,0,1,1,0,1,0,1,1,0,1,0,1,1,0,1,1
add $0,3
seq $0,189661 ; Fixed point of the morphism 0->010, 1->10 starting with 0.
pow $1,$0
mov $0,$1
|
; A081954: Triangle read by rows: T(n, k) = 2^(n-k)*3^k, n >= 1, 0 <= k < n.
; Submitted by Christian Krause
; 2,4,6,8,12,18,16,24,36,54,32,48,72,108,162,64,96,144,216,324,486,128,192,288,432,648,972,1458,256,384,576,864,1296,1944,2916,4374,512,768,1152,1728,2592,3888,5832,8748,13122,1024,1536,2304,3456,5184,7776
seq $0,48645 ; Integers with one or two 1-bits in their binary expansion.
seq $0,284005 ; a(0) = 1, and for n > 1, a(n) = (1 + A000120(n))*a(floor(n/2)); also a(n) = A000005(A283477(n)).
|
.global s_prepare_buffers
s_prepare_buffers:
push %r11
push %r12
push %r8
push %r9
push %rax
push %rcx
push %rdi
push %rsi
lea addresses_A_ht+0x130dc, %rdi
add %r9, %r9
mov $0x6162636465666768, %rax
movq %rax, %xmm1
vmovups %ymm1, (%rdi)
nop
nop
dec %r12
lea addresses_UC_ht+0x10ebc, %rdi
clflush (%rdi)
dec %r11
mov (%rdi), %r8
nop
sub %r11, %r11
lea addresses_A_ht+0x95c, %rdi
nop
nop
nop
nop
nop
xor $27607, %rsi
movl $0x61626364, (%rdi)
nop
xor $45119, %rax
lea addresses_UC_ht+0x19edc, %rsi
lea addresses_WT_ht+0xbddc, %rdi
clflush (%rsi)
nop
nop
add $15495, %rax
mov $121, %rcx
rep movsq
nop
nop
nop
dec %r12
lea addresses_A_ht+0xc686, %rax
xor %r11, %r11
mov (%rax), %si
nop
nop
nop
nop
nop
sub $41986, %rdi
lea addresses_A_ht+0x111dc, %rsi
cmp $44889, %r9
movl $0x61626364, (%rsi)
nop
nop
nop
nop
mfence
lea addresses_UC_ht+0xc6b4, %r11
nop
nop
nop
nop
sub %r9, %r9
movl $0x61626364, (%r11)
nop
nop
nop
nop
nop
sub $7029, %rdi
lea addresses_D_ht+0x18da2, %r9
nop
cmp $18297, %rax
movl $0x61626364, (%r9)
and %rcx, %rcx
lea addresses_D_ht+0x14dc, %rsi
lea addresses_normal_ht+0xd5dc, %rdi
nop
nop
nop
nop
nop
cmp $54841, %r8
mov $30, %rcx
rep movsw
nop
nop
and $39067, %rcx
lea addresses_normal_ht+0x1392c, %rcx
nop
nop
nop
dec %r9
mov (%rcx), %rdi
nop
nop
and %r9, %r9
lea addresses_D_ht+0x144dc, %r9
nop
nop
nop
nop
nop
sub $34903, %r8
movb $0x61, (%r9)
nop
nop
nop
nop
cmp %r12, %r12
pop %rsi
pop %rdi
pop %rcx
pop %rax
pop %r9
pop %r8
pop %r12
pop %r11
ret
.global s_faulty_load
s_faulty_load:
push %r10
push %r14
push %r9
push %rcx
push %rdi
push %rdx
push %rsi
// Load
lea addresses_normal+0x1dddc, %r10
nop
add $39601, %rcx
mov (%r10), %edx
nop
nop
nop
nop
inc %r14
// REPMOV
lea addresses_PSE+0xd9dc, %rsi
lea addresses_PSE+0xd9dc, %rdi
nop
cmp %r9, %r9
mov $96, %rcx
rep movsw
nop
nop
nop
nop
xor $46573, %rcx
// Store
lea addresses_WC+0x1e5d4, %r10
cmp %rcx, %rcx
movw $0x5152, (%r10)
nop
inc %r9
// Store
lea addresses_PSE+0x1e3b2, %r9
sub $61889, %rdi
mov $0x5152535455565758, %rsi
movq %rsi, %xmm0
vmovaps %ymm0, (%r9)
nop
nop
cmp %rdi, %rdi
// Faulty Load
lea addresses_PSE+0xd9dc, %r9
clflush (%r9)
nop
sub %r14, %r14
mov (%r9), %r10w
lea oracles, %rsi
and $0xff, %r10
shlq $12, %r10
mov (%rsi,%r10,1), %r10
pop %rsi
pop %rdx
pop %rdi
pop %rcx
pop %r9
pop %r14
pop %r10
ret
/*
<gen_faulty_load>
[REF]
{'OP': 'LOAD', 'src': {'type': 'addresses_PSE', 'size': 1, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_normal', 'size': 4, 'AVXalign': True, 'NT': False, 'congruent': 8, 'same': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_PSE', 'congruent': 0, 'same': True}, 'dst': {'type': 'addresses_PSE', 'congruent': 0, 'same': True}}
{'OP': 'STOR', 'dst': {'type': 'addresses_WC', 'size': 2, 'AVXalign': False, 'NT': False, 'congruent': 3, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_PSE', 'size': 32, 'AVXalign': True, 'NT': False, 'congruent': 1, 'same': False}}
[Faulty Load]
{'OP': 'LOAD', 'src': {'type': 'addresses_PSE', 'size': 2, 'AVXalign': False, 'NT': False, 'congruent': 0, 'same': True}}
<gen_prepare_buffer>
{'OP': 'STOR', 'dst': {'type': 'addresses_A_ht', 'size': 32, 'AVXalign': False, 'NT': False, 'congruent': 8, 'same': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_UC_ht', 'size': 8, 'AVXalign': False, 'NT': False, 'congruent': 5, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_A_ht', 'size': 4, 'AVXalign': False, 'NT': False, 'congruent': 4, 'same': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_UC_ht', 'congruent': 8, 'same': False}, 'dst': {'type': 'addresses_WT_ht', 'congruent': 9, 'same': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_A_ht', 'size': 2, 'AVXalign': True, 'NT': False, 'congruent': 1, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_A_ht', 'size': 4, 'AVXalign': False, 'NT': True, 'congruent': 8, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_UC_ht', 'size': 4, 'AVXalign': False, 'NT': False, 'congruent': 3, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_D_ht', 'size': 4, 'AVXalign': True, 'NT': True, 'congruent': 1, 'same': False}}
{'OP': 'REPM', 'src': {'type': 'addresses_D_ht', 'congruent': 8, 'same': False}, 'dst': {'type': 'addresses_normal_ht', 'congruent': 7, 'same': False}}
{'OP': 'LOAD', 'src': {'type': 'addresses_normal_ht', 'size': 8, 'AVXalign': False, 'NT': False, 'congruent': 2, 'same': False}}
{'OP': 'STOR', 'dst': {'type': 'addresses_D_ht', 'size': 1, 'AVXalign': False, 'NT': True, 'congruent': 2, 'same': False}}
{'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
*/
|
cpu 8008new
org 2000h
jmp 2003h
in 1
mvi h,20h
mvi l,0
loop: mov m,l
inr l
jnz loop
inr h
mov a,h
cpi 24h
jnz loop
wait: jmp wait
|
;
; trace.nasm
; Copyright © 2012-2018 Jeff Parsons <Jeff@pcjs.org>
;
; This file is part of PCjs, a computer emulation software project at <https://www.pcjs.org>.
;
; PCjs 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.
;
; PCjs 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 PCjs. If not,
; see <http://www.gnu.org/licenses/gpl.html>.
;
; You are required to include the above copyright notice in every source code file of every
; copy or modified version of this work, and to display that copyright notice on every screen
; that loads or runs any version of this software (see Computer.sCopyright).
;
; Some PCjs files also attempt to load external resource files, such as character-image files,
; ROM files, and disk image files. Those external resource files are not considered part of the
; PCjs program for purposes of the GNU General Public License, and the author does not claim
; any copyright as to their contents.
;
; Overview
; --------
; Takes an instruction log, as recorded by the Debugger's traceLog() function, and
; "plays" the instructions back on another machine DOS-compatible 8086 machine, verifying that:
;
; 1) results match the recorded results
; 2) any "modified" flags match the recorded flags
; 3) any "unmodified" flags remain unmodified
;
; The format of an instruction log entry is a series of lines (ASCII characters terminated by an LF),
; where each line looks like:
;
; F000:EEFF SHL(0480,0002,F006) 1200,F006
;
; ie, address, space, instruction, parenthesis, dst operand, comma, src operand, comma,
; input flags, parenthesis, space, result, comma, and output flags.
;
; WARNING: For the shift and rotate tests to pass on a real x86 CPU, we either have to distinguish
; between single-bit shifts and multi-bit shifts (because the latter leaves PS_OF in an "undefined"
; state), or we have to ignore PS_OF altogether. For now, I'm specifying PS_ALL_BUT_OF for those
; instructions, even though we'll be missing OVERFLOW validation for all single-bit shifts and rotates.
;
CPU 8086
;
; Bit masks for all the arithmetic flags we care about
;
PS_NONE equ 0x0000
PS_CF equ 0x0001 ; bit 0: Carry flag
PS_PF equ 0x0004 ; bit 2: Parity flag
PS_AF equ 0x0010 ; bit 4: Auxiliary Carry flag (aka Arithmetic flag)
PS_ZF equ 0x0040 ; bit 6: Zero flag
PS_SF equ 0x0080 ; bit 7: Sign flag
PS_OF equ 0x0800 ; bit 11: Overflow flag
PS_ALL equ PS_CF | PS_PF | PS_AF | PS_ZF | PS_SF | PS_OF
PS_ALL_BUT_AF equ PS_CF | PS_PF | PS_ZF | PS_SF | PS_OF
PS_ALL_BUT_OF equ PS_CF | PS_PF | PS_AF | PS_ZF | PS_SF
%macro openF 1
section .data
%%name: db %1,0
section .text
mov dx,%%name
mov ax,0x3D00
int 0x21
%endmacro
%macro readF 3
%ifnidni %1,bx
mov bx,%1
%endif
%ifnidni %2,dx
mov dx,%2
%endif
%ifnidni %3,cx
mov cx,%3
%endif
mov ah,0x3F
int 0x21
%endmacro
%macro print 1
%ifidni %1,line
push ax
push cx
push dx
push si
mov dx,si
dec cx
add si,cx
mov byte [si],'$'
mov ah,0x09
int 0x21
mov dx,strCRLF
mov ah,0x09
int 0x21
pop si
pop dx
pop cx
pop ax
%else
%ifstr %1
section .data
%%str: db %1,'$'
section .text
push dx
mov dx,%%str
%elifnidni %1,dx
push dx
mov dx,%1
%endif
push ax
mov ah,0x09
int 0x21
pop ax
%ifnidni %1,dx
pop dx
%endif
%endif
%endmacro
%macro exit 0-2
%ifstr %1
section .data
%%msg: db %1,'$'
section .text
%ifidni %2,oncarry
jnc %%ok
%endif
mov dx,%%msg
mov ah,0x09
int 0x21
%endif
int 0x20
%%ok:
%endmacro
%macro break 0
;
; "int3" generates the 1-byte breakpoint instruction; "int 3" generates a 2-byte software interrupt
;
int3
%endmacro
org 0x100
section .text
openF "TRACE.TXT"
exit "unable to open file",oncarry
mov di,file_buffer
readF ax,di,file_buffer_len
m1: exit "unable to read file",oncarry
test ax,ax ; AX contains how many bytes were actually read
jnz m2
exit "processing complete"
m2: cld
mov si,file_buffer
add di,ax
;
; At this point, DS:SI is the current line pointer, and DI is the end-of-buffer
; position. getLine() will update CX to the length of the current line (including
; the terminating LF).
;
m3: call getLine
jnc m4
;
; Oops, carry is set, so we're missing part or all of the next line. Move the
; partial line to the top of the file buffer and then fill the rest of the buffer.
;
mov di,file_buffer
rep movsb
mov cx,file_buffer_end
sub cx,di
readF bx,di,cx
jmp m1
;
; OK, we now have a complete line at DS:SI, guaranteed to end with an LF, with a
; length of CX (although CX will soon be overwritten by calls to getHex).
;
m4:
; print line
mov ah,' '
call skipTo
m4err: exit "missing space",oncarry
inc si
push di
mov di,ins_name
m5: lodsb
cmp al,'('
je m6
stosb
jmp m5
m6: mov al,'$'
stosb
pop di
print ins_name
print strColon
call getHex
mov [dst_operand],ax
mov [dst_operand+2],dx
mov [dst_size],cx
call printHex
print strComma
inc si
call getHex
mov [src_operand],ax
mov [src_operand+2],dx
mov [src_size],cx
call printHex
inc si
call getHex
and ax,PS_ALL
mov [operand_flags],ax
jcxz m6b
print strComma
call printHex
m6b: mov ah,' '
call skipTo
jc m4err
inc si
call getHex
mov [result_operand],ax
mov [result_operand+2],dx
mov [result_size],cx
print strEquals
call printHex
print strComma
inc si
call getHex
and ax,PS_ALL
mov [result_flags],ax
call printHex
print strCRLF
;
; Now that we know operand sizes, it's time to look up the instruction function
;
push si
mov si,ins_table
push di
m7a: mov di,ins_name
m7b: lodsb
test al,al
jz m8
mov ah,[es:di]
inc di
cmp al,ah
je m7b
m7c: lodsb
test al,al
jnz m7c
add si,8 ; after then name, each ins_table entry is 4 words long
cmp byte [si],0
jne m7a
print "missing function: "
print ins_name
exit
m8: mov ax,[si]
mov cx,[result_size]
mov dx,compare8
cmp cl,4
jb m8a
mov ax,[si+2]
mov dx,compare16
cmp cl,8
jb m8a
mov ax,[si+4]
mov dx,compare32
m8a: test ax,ax
jnz m8b
print "missing "
print ins_name
xchg ax,cx
call printHex
exit
m8b: mov [ins_function],ax
mov [ins_compare],dx
mov ax,[si+6]
mov [relevant_flags],ax
;
; Let's call the instruction function now, loading the PS_ALL flags with the same values
; that the emulator recorded (operand_flags).
;
pushf
pop cx ; CX == current flags
mov ax,PS_ALL
not ax
and cx,ax ; CX == current flags, with PS_ALL flags cleared
or cx,[operand_flags]
push cx ; CX == current flags, with PS_ALL flags from operand_flags included
popf
call [ins_function]
pushf
pop cx
call [ins_compare]
;
; If we're still here, the instruction passed, so restore the line pointer and move to the next line
;
pop di
pop si
;
; When we finished reading the current line, DS:SI should have been left pointing at the terminating LF;
; however, if we used "print" to display it, that LF would have replaced with a '$'. In any case, we don't
; really need to call skipTo, if we know we're at the end of the current line.
;
; mov ah,0x0A
; call skipTo
inc si ; step over the LF (or '$', in case we printed the line before processing it)
jmp m3
compare8:
mov ah,[result_operand]
cmp al,ah
jne c8err
jmp compareFlags
c8err: print "byte mismatch:"
print strActual
mov cx,2
call printHex
print strRecorded
mov al,ah
call printHex
print strCRLF
exit
compare16:
mov dx,[result_operand]
cmp ax,dx
jne c16err
jmp compareFlags
c16err: print "word mismatch:"
print strActual
mov cx,4
call printHex
print strRecorded
xchg ax,dx
call printHex
print strCRLF
exit
compare32:
cmp ax,[result_operand]
jne c32err
cmp dx,[result_operand+2]
je compareFlags
c32err: print "dword mismatch:"
print strActual
mov cx,8
call printHex
print strRecorded
mov ax,[result_operand]
mov dx,[result_operand+2]
call printHex
print strCRLF
exit
compareFlags:
mov dx,[result_flags]
and cx,[relevant_flags]
and dx,[relevant_flags]
cmp cx,dx
je cfret
print "flag mismatch:"
print strActual
xchg ax,cx
mov cx,4
call printHex
print strRecorded
xchg ax,dx
call printHex
print strCRLF
exit
cfret: ret
testROL8:
mov al,[dst_operand]
mov cl,[src_operand]
rol al,cl
ret
testROL16:
mov ax,[dst_operand]
mov cl,[src_operand]
rol ax,cl
ret
testROR8:
mov al,[dst_operand]
mov cl,[src_operand]
ror al,cl
ret
testROR16:
mov ax,[dst_operand]
mov cl,[src_operand]
ror ax,cl
ret
testRCL8:
mov al,[dst_operand]
mov cl,[src_operand]
rcl al,cl
ret
testRCL16:
mov ax,[dst_operand]
mov cl,[src_operand]
rcl ax,cl
ret
testRCR8:
mov al,[dst_operand]
mov cl,[src_operand]
rcr al,cl
ret
testRCR16:
mov ax,[dst_operand]
mov cl,[src_operand]
rcr ax,cl
ret
testSHL8:
mov al,[dst_operand]
mov cl,[src_operand]
shl al,cl
ret
testSHL16:
mov ax,[dst_operand]
mov cl,[src_operand]
shl ax,cl
ret
testMUL16:
mov al,[dst_operand]
mov cl,[src_operand]
mul cl
ret
testMUL32:
mov ax,[dst_operand]
mov cx,[src_operand]
mul cx
ret
testIMUL16:
mov al,[dst_operand]
mov cl,[src_operand]
imul cl
ret
testIMUL32:
mov ax,[dst_operand]
mov cx,[src_operand]
imul cx
ret
testDIV16:
mov ax,[dst_operand]
mov cl,[src_operand]
div cl
ret
testDIV32:
mov ax,[dst_operand]
mov dx,[dst_operand+2]
mov cx,[src_operand]
div cx
ret
testIDIV16:
mov ax,[dst_operand]
mov cl,[src_operand]
idiv cl
ret
testIDIV32:
mov ax,[dst_operand]
mov dx,[dst_operand+2]
mov cx,[src_operand]
idiv cx
ret
;
; getHex: get value of hex string
;
; Inputs
; DS:SI -> hex string
;
; Outputs
; CX == number of characters
; DX:AX == corresponding value
; DS:SI -> next non-hex character
;
; Uses
; AX, CX, DX, SI, Flags
;
; Notes
; Supports upper-case alpha chars only, with no prefixes (eg, "0x") or suffixes (eg, "h");
; if there are more than 8 hex characters, the value will represent only the last 8 characters.
;
getHex:
push bx
sub bx,bx ; BX holds the low 16 bits
sub dx,dx ; DX holds the high 16 bits
sub cx,cx ; CX holds the character count
gh1: lodsb
cmp al,'0'
jb gh9
cmp al,'9'
ja gh3
sub al,'0'
gh2: shl bx,1
rcl dx,1
shl bx,1
rcl dx,1
shl bx,1
rcl dx,1
shl bx,1
rcl dx,1
or bl,al
inc cx
jmp gh1
gh3: cmp al,'A'
jb gh9
cmp al,'F'
ja gh9
sub al,'A'-10
jmp gh2
gh9: dec si
xchg ax,bx ; DX:AX now holds the final 32-bit result
pop bx
ret
;
; printHex: print value in hex
;
; Inputs
; DX:AX == value
; CX == # of characters
;
; Outputs
; None
;
; Uses
; Flags
;
printHex:
push ax
push bx
push cx
push dx
push di
mov bx,ax ; DX:BX now holds the value to print
mov di,hex_buffer_end - 1
mov al,'$'
std
stosb
ph1: jcxz ph3
mov al,bl
and al,0x0F
add al,'0'
cmp al,'9'
jbe ph2
add al,'A'-'0'-10
ph2: stosb
dec cx
shr dx,1
rcr bx,1
shr dx,1
rcr bx,1
shr dx,1
rcr bx,1
shr dx,1
rcr bx,1
jmp ph1
ph3: cld
inc di
print di
pop di
pop dx
pop cx
pop bx
pop ax
ret
;
; getLine: find the length of the current line
;
; Inputs
; DS:SI -> start of line
; DS:DI -> first byte past end of line buffer
;
; Outputs
; CX == length of line, including the terminating LF (or partial length)
; Carry clear if line complete, carry set if line incomplete (SI reached DI)
;
; Uses
; AL, CX, Flags
;
getLine:
push si
sub cx,cx
gl1: cmp si,di
jb gl2
stc
jmp gl9
gl2: lodsb
inc cx
cmp al,0x0A
jne gl1
gl9: pop si
ret
;
; skipTo: skip to the character in AH
;
; Inputs
; AH == specified character
; DS:SI -> LF-terminated line
;
; Outputs
; DS:SI -> specified character if carry clear, or LF if carry set
;
; Uses
; AL, SI, Flags
;
skipTo:
lodsb
cmp al,ah
je st9
cmp al,0x0A
jne skipTo
stc
st9: dec si
ret
;
; The following is "const" (read-only) data...
;
section .data
ins_table db "ROL",0
dw testROL8, testROL16, 0, PS_ALL_BUT_OF
db "ROR",0
dw testROR8, testROR16, 0, PS_ALL_BUT_OF
db "RCL",0
dw testRCL8, testRCL16, 0, PS_ALL_BUT_OF
db "RCR",0
dw testRCR8, testRCR16, 0, PS_ALL_BUT_OF
db "SHL",0
dw testSHL8, testSHL16, 0, PS_ALL_BUT_AF
db "MUL",0
dw 0, testMUL16, testMUL32, PS_CF | PS_OF
db "IMUL",0
dw 0, testIMUL16, testIMUL32, PS_CF | PS_OF
db "DIV",0
dw 0, testDIV16, testDIV32, PS_NONE
db "IMUL",0
dw 0, testIDIV16, testIDIV32, PS_NONE
db 0 ; end of instruction table
strCRLF db 0x0D,0x0A,'$'
strColon db ":$"
strEquals db "=$"
strComma db ",$"
strActual db " actual=$"
strRecorded db " recorded=$"
;
; We end with all the unitialized data (ie, data that doesn't need to be stored in the binary)
;
section .bss
ins_name resb 6
ins_function resw 1
ins_compare resw 1
dst_operand resw 2
dst_size resw 1
src_operand resw 2
src_size resw 1
operand_flags resw 1
relevant_flags resw 1
result_operand resw 2
result_size resw 1
result_flags resw 1
hex_buffer resb 9
hex_buffer_end equ $
hex_buffer_len equ hex_buffer_end - hex_buffer
file_buffer resb 0x1000
file_buffer_end equ $
file_buffer_len equ file_buffer_end - file_buffer
|
// Copyright (c) 2017-2018 The PIVX developers
// Copyright (c) 2019 The CryptoVerification developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "mintpool.h"
#include "util.h"
using namespace std;
CMintPool::CMintPool()
{
this->nCountLastGenerated = 0;
this->nCountLastRemoved = 0;
}
CMintPool::CMintPool(uint32_t nCount)
{
this->nCountLastRemoved = nCount;
this->nCountLastGenerated = nCount;
}
void CMintPool::Add(const CBigNum& bnValue, const uint32_t& nCount)
{
uint256 hash = GetPubCoinHash(bnValue);
Add(make_pair(hash, nCount));
LogPrintf("%s : add %s to mint pool, nCountLastGenerated=%d\n", __func__, bnValue.GetHex().substr(0, 6), nCountLastGenerated);
}
void CMintPool::Add(const pair<uint256, uint32_t>& pMint, bool fVerbose)
{
insert(pMint);
if (pMint.second > nCountLastGenerated)
nCountLastGenerated = pMint.second;
if (fVerbose)
LogPrintf("%s : add %s count %d to mint pool\n", __func__, pMint.first.GetHex().substr(0, 6), pMint.second);
}
bool CMintPool::Has(const CBigNum& bnValue)
{
return static_cast<bool>(count(GetPubCoinHash(bnValue)));
}
std::pair<uint256, uint32_t> CMintPool::Get(const CBigNum& bnValue)
{
auto it = find(GetPubCoinHash(bnValue));
return *it;
}
bool SortSmallest(const pair<uint256, uint32_t>& a, const pair<uint256, uint32_t>& b)
{
return a.second < b.second;
}
std::list<pair<uint256, uint32_t> > CMintPool::List()
{
list<pair<uint256, uint32_t> > listMints;
for (auto pMint : *(this)) {
listMints.emplace_back(pMint);
}
listMints.sort(SortSmallest);
return listMints;
}
void CMintPool::Reset()
{
clear();
nCountLastGenerated = 0;
nCountLastRemoved = 0;
}
bool CMintPool::Front(std::pair<uint256, uint32_t>& pMint)
{
if (empty())
return false;
pMint = *begin();
return true;
}
bool CMintPool::Next(pair<uint256, uint32_t>& pMint)
{
auto it = find(pMint.first);
if (it == end() || ++it == end())
return false;
pMint = *it;
return true;
}
void CMintPool::Remove(const CBigNum& bnValue)
{
Remove(GetPubCoinHash(bnValue));
LogPrintf("%s : remove %s from mint pool\n", __func__, bnValue.GetHex().substr(0, 6));
}
void CMintPool::Remove(const uint256& hashPubcoin)
{
auto it = find(hashPubcoin);
if (it == end())
return;
nCountLastRemoved = it->second;
erase(it);
}
|
#Mergesort for benchmarking
#Optimized for 512 bit I$ 1024 bit D$
#Author Adam Hendrickson ahendri@purdue.edu
#CORE 0
org 0x0000
ori $fp, $zero, 0xFFFC
ori $sp, $zero, 0xFFFC
ori $a0, $zero, data
lw $s0, size($zero)
srl $a1, $s0, 1
or $s1, $zero, $a0
or $s2, $zero, $a1
jal insertion_sort
srl $t0, $s0, 1
subu $a1, $s0, $t0
sll $t0, $t0, 2
ori $a0, $zero, data
addu $a0, $a0, $t0
or $s3, $zero, $a0
or $s4, $zero, $a1
or $a0, $zero, $s1
or $a1, $zero, $s2
or $a2, $zero, $s3
or $a3, $zero, $s4
ori $t0, $zero, sorted
push $t0
ori $t1, $zero, flag
wait1:
lw $t2, 0($t1)
beq $t2, $zero, wait1
jal merge
addiu $sp, $sp, 4
halt
#CORE 1
org 0x0200
ori $fp, $zero, 0x3FFC
ori $sp, $zero, 0x3FFC
ori $a0, $zero, data
lw $s0, size($zero)
srl $a1, $s0, 1
sll $t0, $a1, 2
addu $a0, $a0, $t0
subu $a1, $s0, $a1
jal insertion_sort
ori $t0, $zero, flag
ori $t1, $zero, 1
sw $t1, 0($t0)
halt
#void insertion_sort(int* $a0, int $a1)
# $a0 : pointer to data start
# $a1 : size of array
#--------------------------------------
insertion_sort:
ori $t0, $zero, 4
sll $t1, $a1, 2
is_outer:
sltu $at, $t0, $t1
beq $at, $zero, is_end
addu $t9, $a0, $t0
lw $t8, 0($t9)
is_inner:
beq $t9, $a0, is_inner_end
lw $t7, -4($t9)
slt $at, $t8, $t7
beq $at, $zero, is_inner_end
sw $t7, 0($t9)
addiu $t9, $t9, -4
j is_inner
is_inner_end:
sw $t8, 0($t9)
addiu $t0, $t0, 4
j is_outer
is_end:
jr $ra
#--------------------------------------
#void merge(int* $a0, int $a1, int* $a2, int $a3, int* dst)
# $a0 : pointer to list 1
# $a1 : size of list 1
# $a2 : pointer to list 2
# $a3 : size of list 2
# dst [$sp+4] : pointer to merged list location
#--------------------------------------
merge:
lw $t0, 0($sp)
m_1:
bne $a1, $zero, m_3
m_2:
bne $a3, $zero, m_3
j m_end
m_3:
beq $a3, $zero, m_4
beq $a1, $zero, m_5
lw $t1, 0($a0)
lw $t2, 0($a2)
slt $at, $t1, $t2
beq $at, $zero, m_3a
sw $t1, 0($t0)
addiu $t0, $t0, 4
addiu $a0, $a0, 4
addiu $a1, $a1, -1
j m_1
m_3a:
sw $t2, 0($t0)
addiu $t0, $t0, 4
addiu $a2, $a2, 4
addiu $a3, $a3, -1
j m_1
m_4: #left copy
lw $t1, 0($a0)
sw $t1, 0($t0)
addiu $t0, $t0, 4
addiu $a1, $a1, -1
addiu $a0, $a0, 4
beq $a1, $zero, m_end
j m_4
m_5: # right copy
lw $t2, 0($a2)
sw $t2, 0($t0)
addiu $t0, $t0, 4
addiu $a3, $a3, -1
addiu $a2, $a2, 4
beq $a3, $zero, m_end
j m_5
m_end:
jr $ra
#--------------------------------------
org 0x400
flag:
cfw 0
size:
cfw 4
data:
cfw 90
cfw 81
cfw 51
cfw 25
org 0x600
sorted:
|
copyright zengfr site:http://github.com/zengfr/romhack
012A74 clr.b ($200,A5)
012A78 move.b #$2, ($1c8,A5)
012F04 move.b #$63, ($1de,A5)
01A610 dbra D1, $1a60e
01AD3E addi.b #$1e, ($1de,A5)
copyright zengfr site:http://github.com/zengfr/romhack
|
/*include*/
#ifndef takeoff1203
// 기본 header (ROS & C/C++)
#include <mavlink/v2.0/common/mavlink.h>
#include <ros/ros.h>
#include <iostream>
#include <std_msgs/String.h>
#include <vector>
#include <stdlib.h>
#include <geometry_msgs/Point.h>
#include <geographic_msgs/GeoPoint.h>
#include <string>
#include <unistd.h>
// 토픽 선언 header
#include <eDrone_msgs/Target.h>
#include <eDrone_msgs/Phase.h>
// 파라미터 초기값 선언 header
#include <takeoff1203/params.h>
// 서비스 선언 header
#include <eDrone_msgs/CheckState.h>
#include <eDrone_msgs/CheckPosition.h>
#include <eDrone_msgs/Arming.h>
#include <eDrone_msgs/Takeoff.h>
#include <eDrone_msgs/Landing.h>
/*namespace*/
#endif
using namespace std;
using namespace geographic_msgs;
using namespace geometry_msgs;
using namespace eDrone_msgs;
ros::NodeHandle nh;
eDrone_msgs::Target cur_target; // 무인기가 현재 향하고 있는 목적지 (경유지)
eDrone_msgs::Phase cur_phase; // 무인기의 현재 동작 단계 (ex. UNARMED, ARMED, TAKEOFF, GOTO, ...)
/*콜백 함수 정의*/
// 토픽 콜백 함수
void cur_target_cb(const eDrone_msgs::Target::ConstPtr& msg)
{
cur_target = *msg;
// 현재 목적지 도달 여부 확인
ROS_INFO("cur_target_cb(): \n");
ROS_INFO("current target: %d \n", cur_target.target_seq_no);
if (cur_target.reached == true)
{
ROS_INFO("we reached at the current target\n");
}
}
void cur_phase_cb(const eDrone_msgs::Phase::ConstPtr& msg)
{
cur_phase = *msg;
// 현재 목적지 도달 여부 확인
ROS_INFO("cur_phase_cb(): \n");
ROS_INFO("current phase: %s \n", cur_phase.phase.c_str());
}
/*begin of main*/
int main (int argc, char** argv)
{
/*ROS node 초기화*/
ROS_INFO("==takeoff1203==\n");
ros::init(argc, argv, "takeoff1203");
ros::NodeHandle nh;
for (int arg_index = 0; arg_index < argc; arg_index++)
{
ROS_INFO("main arg[%d]: %s", arg_index, argv[arg_index] );
}
/*Service 메시지 변수*/
eDrone_msgs::CheckState checkState_cmd;
eDrone_msgs::CheckPosition checkPosition_cmd;
eDrone_msgs::Arming arming_cmd;
eDrone_msgs::Takeoff takeoff_cmd;
eDrone_msgs::Landing landing_cmd;
/*Topic Subscriber 객체 */
// rate 설정
ros::Rate rate(20.0);
// 토픽 subscriber 선언 & 초기화
ros::Subscriber cur_target_sub = nh.subscribe("eDrone_msgs/current_target", 10, cur_target_cb); //
ros::Subscriber cur_phase_sub = nh.subscribe("eDrone_msgs/current_phase", 10, cur_phase_cb);
/* ROS Service Client 객체 */
ros::ServiceClient checkState_client =nh.serviceClient<eDrone_msgs::CheckState>("srv_checkState");
ros::ServiceClient checkPosition_client =nh.serviceClient<eDrone_msgs::CheckPosition>("srv_checkPosition");
ros::ServiceClient arming_client =nh.serviceClient<eDrone_msgs::Arming>("srv_arming");
ros::ServiceClient takeoff_client =nh.serviceClient<eDrone_msgs::Takeoff>("srv_takeoff");
ros::ServiceClient landing_client =nh.serviceClient<eDrone_msgs::Landing>("srv_landing");
/*ROS Service 호출*/
// 연결 상태 확인
sleep(10); // (수정)
ROS_INFO("Send checkState command ... \n");
ROS_INFO("Checking the connection ... \n");
if (checkState_client.call(checkState_cmd))
{
ROS_INFO ("CheckState service was requested");
while (checkState_cmd.response.connected == false)
{
if (checkState_client.call(checkState_cmd))
{
ROS_INFO ("Checking state...");
}
ros::spinOnce();
rate.sleep();
}
ROS_INFO("UAV connection established!");
if (checkState_cmd.response.connected == true)
{
cout << "UAV connected: " << endl;
}
if (checkState_cmd.response.armed == true )
{
cout << "UAV armed: " << endl;
}
cout << "flight mode: " << checkState_cmd.response.mode << endl;
cout << "remaining battery(%): " << checkState_cmd.response.battery_remain << endl;
}
// 무인기 위치 확인
ROS_INFO("Send checkPosition command ... \n");
ROS_INFO("Checking the position ... \n");
if (checkPosition_client.call(checkPosition_cmd))
{
ROS_INFO ("CheckPosition service was requested");
while (checkPosition_cmd.response.value == false)
{
if (checkPosition_client.call(checkPosition_cmd))
{
ROS_INFO ("Checking position...");
}
ros::spinOnce();
sleep(10);
}
cout <<"global frame (WGS84): (" << checkPosition_cmd.response.latitude << ", ";
cout << checkPosition_cmd.response.longitude << ", ";
cout << checkPosition_cmd.response.altitude << ") " << endl << endl;
cout <<"local frame (ENU): (" << checkPosition_cmd.response.x << ", ";
cout << checkPosition_cmd.response.y << ", " << checkPosition_cmd.response.z << ") " << endl;
}
ROS_INFO("UAV position was checked!");
// Arming
ROS_INFO("Send arming command ... \n");
arming_client.call(arming_cmd);
if (arming_cmd.response.value == true)
{
ROS_INFO("Arming command was sent to FC");
}
// Takeoff
double takeoff_altitude = 0;
takeoff_altitude = TAKEOFF_ALTITUDE;
// 1) 상수에 의한 초기화: takeoff_altitude = TAKEOFF_ALTITUDE;
// 2) 명령줄 인자에 의한 초기화: takeoff_altitude = atof (argv[1]);
ROS_INFO("takeoff_altitude: %lf", takeoff_altitude);
ROS_INFO("Send takeoff command ... \n");
takeoff_cmd.request.takeoff_altitude = takeoff_altitude; // 서비스 파라미터 설정
takeoff_client.call(takeoff_cmd); // 서비스 호출
if (takeoff_cmd.response.value == true) // 서비스 호출 결과 확인
{
ROS_INFO("Takeoff command was sent to FC\n");
}
sleep(10);
// Landing
while (cur_phase.phase.compare ("READY")!=0)
{
ros::spinOnce();
rate.sleep();
cout << "cur_phase: " << cur_phase.phase << endl;
}
ROS_INFO("Send landing command ... \n");
landing_client.call(landing_cmd); // 착륙 명령
if (landing_cmd.response.value == true) // 서비스 호출 결과 확인
{
ROS_INFO("Landing command was sent to FC\n");
}
/*end of main*/
return 0;
}
|
/*
* yosys -- Yosys Open SYnthesis Suite
*
* Copyright (C) 2012 Clifford Wolf <clifford@clifford.at>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
*/
#include "kernel/yosys.h"
#include "kernel/macc.h"
USING_YOSYS_NAMESPACE
PRIVATE_NAMESPACE_BEGIN
struct MaccmapWorker
{
std::vector<std::set<RTLIL::SigBit>> bits;
RTLIL::Module *module;
int width;
MaccmapWorker(RTLIL::Module *module, int width) : module(module), width(width)
{
bits.resize(width);
}
void add(RTLIL::SigBit bit, int position)
{
if (position >= width || bit == RTLIL::S0)
return;
if (bits.at(position).count(bit)) {
bits.at(position).erase(bit);
add(bit, position+1);
} else {
bits.at(position).insert(bit);
}
}
void add(RTLIL::SigSpec a, bool is_signed, bool do_subtract)
{
a.extend_u0(width, is_signed);
if (do_subtract) {
a = module->Not(NEW_ID, a);
add(RTLIL::S1, 0);
}
for (int i = 0; i < width; i++)
add(a[i], i);
}
void add(RTLIL::SigSpec a, RTLIL::SigSpec b, bool is_signed, bool do_subtract)
{
if (GetSize(a) < GetSize(b))
std::swap(a, b);
a.extend_u0(width, is_signed);
if (GetSize(b) > width)
b.extend_u0(width, is_signed);
for (int i = 0; i < GetSize(b); i++)
if (is_signed && i+1 == GetSize(b))
{
a = {module->Not(NEW_ID, a.extract(i, width-i)), RTLIL::SigSpec(0, i)};
add(module->And(NEW_ID, a, RTLIL::SigSpec(b[i], width)), false, do_subtract);
add({b[i], RTLIL::SigSpec(0, i)}, false, do_subtract);
}
else
{
add(module->And(NEW_ID, a, RTLIL::SigSpec(b[i], width)), false, do_subtract);
a = {a.extract(0, width-1), RTLIL::S0};
}
}
void fulladd(RTLIL::SigSpec &in1, RTLIL::SigSpec &in2, RTLIL::SigSpec &in3, RTLIL::SigSpec &out1, RTLIL::SigSpec &out2)
{
int start_index = 0, stop_index = GetSize(in1);
while (start_index < stop_index && in1[start_index] == RTLIL::S0 && in2[start_index] == RTLIL::S0 && in3[start_index] == RTLIL::S0)
start_index++;
while (start_index < stop_index && in1[stop_index-1] == RTLIL::S0 && in2[stop_index-1] == RTLIL::S0 && in3[stop_index-1] == RTLIL::S0)
stop_index--;
if (start_index == stop_index)
{
out1 = RTLIL::SigSpec(0, GetSize(in1));
out2 = RTLIL::SigSpec(0, GetSize(in1));
}
else
{
RTLIL::SigSpec out_zeros_lsb(0, start_index), out_zeros_msb(0, GetSize(in1)-stop_index);
in1 = in1.extract(start_index, stop_index-start_index);
in2 = in2.extract(start_index, stop_index-start_index);
in3 = in3.extract(start_index, stop_index-start_index);
int width = GetSize(in1);
RTLIL::Wire *w1 = module->addWire(NEW_ID, width);
RTLIL::Wire *w2 = module->addWire(NEW_ID, width);
RTLIL::Cell *cell = module->addCell(NEW_ID, "$fa");
cell->setParam("\\WIDTH", width);
cell->setPort("\\A", in1);
cell->setPort("\\B", in2);
cell->setPort("\\C", in3);
cell->setPort("\\Y", w1);
cell->setPort("\\X", w2);
out1 = {out_zeros_msb, w1, out_zeros_lsb};
out2 = {out_zeros_msb, w2, out_zeros_lsb};
}
}
int tree_bit_slots(int n)
{
#if 0
int retval = 1;
while (n > 2) {
retval += n / 3;
n = 2*(n / 3) + (n % 3);
}
return retval;
#else
return std::max(n - 1, 0);
#endif
}
RTLIL::SigSpec synth()
{
std::vector<RTLIL::SigSpec> summands;
std::vector<RTLIL::SigBit> tree_sum_bits;
int unique_tree_bits = 0;
int count_tree_words = 0;
while (1)
{
RTLIL::SigSpec summand(0, width);
bool got_data_bits = false;
for (int i = 0; i < width; i++)
if (!bits.at(i).empty()) {
auto it = bits.at(i).begin();
summand[i] = *it;
bits.at(i).erase(it);
got_data_bits = true;
}
if (!got_data_bits)
break;
summands.push_back(summand);
while (1)
{
int free_bit_slots = tree_bit_slots(GetSize(summands)) - GetSize(tree_sum_bits);
int max_depth = 0, max_position = 0;
for (int i = 0; i < width; i++)
if (max_depth <= GetSize(bits.at(i))) {
max_depth = GetSize(bits.at(i));
max_position = i;
}
if (max_depth == 0 || max_position > 4)
break;
int required_bits = 0;
for (int i = 0; i <= max_position; i++)
if (GetSize(bits.at(i)) == max_depth)
required_bits += 1 << i;
if (required_bits > free_bit_slots)
break;
for (int i = 0; i <= max_position; i++)
if (GetSize(bits.at(i)) == max_depth) {
auto it = bits.at(i).begin();
RTLIL::SigBit bit = *it;
for (int k = 0; k < (1 << i); k++, free_bit_slots--)
tree_sum_bits.push_back(bit);
bits.at(i).erase(it);
unique_tree_bits++;
}
count_tree_words++;
}
}
if (!tree_sum_bits.empty())
log(" packed %d (%d) bits / %d words into adder tree\n", GetSize(tree_sum_bits), unique_tree_bits, count_tree_words);
if (GetSize(summands) == 0) {
log_assert(tree_sum_bits.empty());
return RTLIL::SigSpec(0, width);
}
if (GetSize(summands) == 1) {
log_assert(tree_sum_bits.empty());
return summands.front();
}
while (GetSize(summands) > 2)
{
std::vector<RTLIL::SigSpec> new_summands;
for (int i = 0; i < GetSize(summands); i += 3)
if (i+2 < GetSize(summands)) {
RTLIL::SigSpec in1 = summands[i];
RTLIL::SigSpec in2 = summands[i+1];
RTLIL::SigSpec in3 = summands[i+2];
RTLIL::SigSpec out1, out2;
fulladd(in1, in2, in3, out1, out2);
RTLIL::SigBit extra_bit = RTLIL::S0;
if (!tree_sum_bits.empty()) {
extra_bit = tree_sum_bits.back();
tree_sum_bits.pop_back();
}
new_summands.push_back(out1);
new_summands.push_back({out2.extract(0, width-1), extra_bit});
} else {
new_summands.push_back(summands[i]);
i -= 2;
}
summands.swap(new_summands);
}
RTLIL::Cell *c = module->addCell(NEW_ID, "$alu");
c->setPort("\\A", summands.front());
c->setPort("\\B", summands.back());
c->setPort("\\CI", RTLIL::S0);
c->setPort("\\BI", RTLIL::S0);
c->setPort("\\Y", module->addWire(NEW_ID, width));
c->setPort("\\X", module->addWire(NEW_ID, width));
c->setPort("\\CO", module->addWire(NEW_ID, width));
c->fixup_parameters();
if (!tree_sum_bits.empty()) {
c->setPort("\\CI", tree_sum_bits.back());
tree_sum_bits.pop_back();
}
log_assert(tree_sum_bits.empty());
return c->getPort("\\Y");
}
};
PRIVATE_NAMESPACE_END
YOSYS_NAMESPACE_BEGIN
extern void maccmap(RTLIL::Module *module, RTLIL::Cell *cell, bool unmap = false);
void maccmap(RTLIL::Module *module, RTLIL::Cell *cell, bool unmap)
{
int width = GetSize(cell->getPort("\\Y"));
Macc macc;
macc.from_cell(cell);
RTLIL::SigSpec all_input_bits;
all_input_bits.append(cell->getPort("\\A"));
all_input_bits.append(cell->getPort("\\B"));
if (all_input_bits.to_sigbit_set().count(RTLIL::Sx)) {
module->connect(cell->getPort("\\Y"), RTLIL::SigSpec(RTLIL::Sx, width));
return;
}
for (auto &port : macc.ports)
if (GetSize(port.in_b) == 0)
log(" %s %s (%d bits, %s)\n", port.do_subtract ? "sub" : "add", log_signal(port.in_a),
GetSize(port.in_a), port.is_signed ? "signed" : "unsigned");
else
log(" %s %s * %s (%dx%d bits, %s)\n", port.do_subtract ? "sub" : "add", log_signal(port.in_a), log_signal(port.in_b),
GetSize(port.in_a), GetSize(port.in_b), port.is_signed ? "signed" : "unsigned");
if (GetSize(macc.bit_ports) != 0)
log(" add bits %s (%d bits)\n", log_signal(macc.bit_ports), GetSize(macc.bit_ports));
if (unmap)
{
typedef std::pair<RTLIL::SigSpec, bool> summand_t;
std::vector<summand_t> summands;
for (auto &port : macc.ports) {
summand_t this_summand;
if (GetSize(port.in_b)) {
this_summand.first = module->addWire(NEW_ID, width);
module->addMul(NEW_ID, port.in_a, port.in_b, this_summand.first, port.is_signed);
} else if (GetSize(port.in_a) != width) {
this_summand.first = module->addWire(NEW_ID, width);
module->addPos(NEW_ID, port.in_a, this_summand.first, port.is_signed);
} else {
this_summand.first = port.in_a;
}
this_summand.second = port.do_subtract;
summands.push_back(this_summand);
}
for (auto &bit : macc.bit_ports)
summands.push_back(summand_t(bit, false));
if (GetSize(summands) == 0)
summands.push_back(summand_t(RTLIL::SigSpec(0, width), false));
while (GetSize(summands) > 1)
{
std::vector<summand_t> new_summands;
for (int i = 0; i < GetSize(summands); i += 2) {
if (i+1 < GetSize(summands)) {
summand_t this_summand;
this_summand.first = module->addWire(NEW_ID, width);
this_summand.second = summands[i].second && summands[i+1].second;
if (summands[i].second == summands[i+1].second)
module->addAdd(NEW_ID, summands[i].first, summands[i+1].first, this_summand.first);
else if (summands[i].second)
module->addSub(NEW_ID, summands[i+1].first, summands[i].first, this_summand.first);
else if (summands[i+1].second)
module->addSub(NEW_ID, summands[i].first, summands[i+1].first, this_summand.first);
else
log_abort();
new_summands.push_back(this_summand);
} else
new_summands.push_back(summands[i]);
}
summands.swap(new_summands);
}
if (summands.front().second)
module->addNeg(NEW_ID, summands.front().first, cell->getPort("\\Y"));
else
module->connect(cell->getPort("\\Y"), summands.front().first);
}
else
{
MaccmapWorker worker(module, width);
for (auto &port : macc.ports)
if (GetSize(port.in_b) == 0)
worker.add(port.in_a, port.is_signed, port.do_subtract);
else
worker.add(port.in_a, port.in_b, port.is_signed, port.do_subtract);
for (auto &bit : macc.bit_ports)
worker.add(bit, 0);
module->connect(cell->getPort("\\Y"), worker.synth());
}
}
YOSYS_NAMESPACE_END
PRIVATE_NAMESPACE_BEGIN
struct MaccmapPass : public Pass {
MaccmapPass() : Pass("maccmap", "mapping macc cells") { }
virtual void help()
{
// |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
log("\n");
log(" maccmap [-unmap] [selection]\n");
log("\n");
log("This pass maps $macc cells to yosys gate primitives. When the -unmap option is\n");
log("used then the $macc cell is mapped to $and, $sub, etc. cells instead.\n");
log("\n");
}
virtual void execute(std::vector<std::string> args, RTLIL::Design *design)
{
bool unmap_mode = false;
log_header("Executing MACCMAP pass (map $macc cells).\n");
size_t argidx;
for (argidx = 1; argidx < args.size(); argidx++) {
if (args[argidx] == "-unmap") {
unmap_mode = true;
continue;
}
break;
}
extra_args(args, argidx, design);
for (auto mod : design->selected_modules())
for (auto cell : mod->selected_cells())
if (cell->type == "$macc") {
log("Mapping %s.%s (%s).\n", log_id(mod), log_id(cell), log_id(cell->type));
maccmap(mod, cell, unmap_mode);
mod->remove(cell);
}
}
} MaccmapPass;
PRIVATE_NAMESPACE_END
|
###############################################################################
# Copyright 2019 Intel Corporation
# All Rights Reserved.
#
# If this software was obtained under the Intel Simplified Software License,
# the following terms apply:
#
# The source code, information and material ("Material") contained herein is
# owned by Intel Corporation or its suppliers or licensors, and title to such
# Material remains with Intel Corporation or its suppliers or licensors. The
# Material contains proprietary information of Intel or its suppliers and
# licensors. The Material is protected by worldwide copyright laws and treaty
# provisions. No part of the Material may be used, copied, reproduced,
# modified, published, uploaded, posted, transmitted, distributed or disclosed
# in any way without Intel's prior express written permission. No license under
# any patent, copyright or other intellectual property rights in the Material
# is granted to or conferred upon you, either expressly, by implication,
# inducement, estoppel or otherwise. Any license under such intellectual
# property rights must be express and approved by Intel in writing.
#
# Unless otherwise agreed by Intel in writing, you may not remove or alter this
# notice or any other notice embedded in Materials by Intel or Intel's
# suppliers or licensors in any way.
#
#
# If this software was obtained under the Apache License, Version 2.0 (the
# "License"), the following terms apply:
#
# You may not use this file except in compliance with the License. You may
# obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
#
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#
# See the License for the specific language governing permissions and
# limitations under the License.
###############################################################################
.text
.p2align 5, 0x90
.globl _DecryptCFB_RIJ128pipe_AES_NI
_DecryptCFB_RIJ128pipe_AES_NI:
push %r13
push %r14
push %r15
sub $(144), %rsp
mov (176)(%rsp), %rax
movdqu (%rax), %xmm4
movdqa %xmm4, (%rsp)
mov %rdi, %r13
mov %rsi, %r14
mov %rcx, %r15
movslq %r8d, %r8
movslq %r9d, %r9
sub $(4), %r8
jl .Lshort_inputgas_1
lea (,%r9,4), %r10
.Lblks_loopgas_1:
xor %rcx, %rcx
.L__000Agas_1:
movl (%r13,%rcx), %r11d
movl %r11d, (16)(%rsp,%rcx)
add $(4), %rcx
cmp %r10, %rcx
jl .L__000Agas_1
movdqa (%r15), %xmm4
lea (%r9,%r9,2), %r10
movdqa (%rsp), %xmm0
movdqu (%rsp,%r9), %xmm1
movdqu (%rsp,%r9,2), %xmm2
movdqu (%rsp,%r10), %xmm3
mov %r15, %r10
pxor %xmm4, %xmm0
pxor %xmm4, %xmm1
pxor %xmm4, %xmm2
pxor %xmm4, %xmm3
movdqa (16)(%r10), %xmm4
add $(16), %r10
mov %rdx, %r11
sub $(1), %r11
.Lcipher_loopgas_1:
aesenc %xmm4, %xmm0
aesenc %xmm4, %xmm1
aesenc %xmm4, %xmm2
aesenc %xmm4, %xmm3
movdqa (16)(%r10), %xmm4
add $(16), %r10
dec %r11
jnz .Lcipher_loopgas_1
aesenclast %xmm4, %xmm0
aesenclast %xmm4, %xmm1
aesenclast %xmm4, %xmm2
aesenclast %xmm4, %xmm3
lea (%r9,%r9,2), %r10
movdqa (16)(%rsp), %xmm4
movdqu (16)(%rsp,%r9), %xmm5
movdqu (16)(%rsp,%r9,2), %xmm6
movdqu (16)(%rsp,%r10), %xmm7
pxor %xmm4, %xmm0
movdqa %xmm0, (80)(%rsp)
pxor %xmm5, %xmm1
movdqu %xmm1, (80)(%rsp,%r9)
pxor %xmm6, %xmm2
movdqu %xmm2, (80)(%rsp,%r9,2)
pxor %xmm7, %xmm3
movdqu %xmm3, (80)(%rsp,%r10)
lea (,%r9,4), %r10
xor %rcx, %rcx
.L__000Bgas_1:
movl (80)(%rsp,%rcx), %r11d
movl %r11d, (%r14,%rcx)
add $(4), %rcx
cmp %r10, %rcx
jl .L__000Bgas_1
movdqu (%rsp,%r10), %xmm0
movdqu %xmm0, (%rsp)
add %r10, %r13
add %r10, %r14
sub $(4), %r8
jge .Lblks_loopgas_1
.Lshort_inputgas_1:
add $(4), %r8
jz .Lquitgas_1
lea (,%r9,2), %r10
lea (%r9,%r9,2), %r11
cmp $(2), %r8
cmovl %r9, %r10
cmovg %r11, %r10
xor %rcx, %rcx
.L__000Cgas_1:
movb (%r13,%rcx), %al
movb %al, (16)(%rsp,%rcx)
add $(1), %rcx
cmp %r10, %rcx
jl .L__000Cgas_1
lea (,%rdx,4), %rax
lea (-144)(%r15,%rax,4), %rax
xor %r11, %r11
.Lsingle_blk_loopgas_1:
movdqu (%rsp,%r11), %xmm0
pxor (%r15), %xmm0
cmp $(12), %rdx
jl .Lkey_128_sgas_1
jz .Lkey_192_sgas_1
.Lkey_256_sgas_1:
aesenc (-64)(%rax), %xmm0
aesenc (-48)(%rax), %xmm0
.Lkey_192_sgas_1:
aesenc (-32)(%rax), %xmm0
aesenc (-16)(%rax), %xmm0
.Lkey_128_sgas_1:
aesenc (%rax), %xmm0
aesenc (16)(%rax), %xmm0
aesenc (32)(%rax), %xmm0
aesenc (48)(%rax), %xmm0
aesenc (64)(%rax), %xmm0
aesenc (80)(%rax), %xmm0
aesenc (96)(%rax), %xmm0
aesenc (112)(%rax), %xmm0
aesenc (128)(%rax), %xmm0
aesenclast (144)(%rax), %xmm0
movdqu (16)(%rsp,%r11), %xmm1
pxor %xmm1, %xmm0
movdqu %xmm0, (80)(%rsp,%r11)
add %r9, %r11
dec %r8
jnz .Lsingle_blk_loopgas_1
xor %rcx, %rcx
.L__000Dgas_1:
movb (80)(%rsp,%rcx), %al
movb %al, (%r14,%rcx)
add $(1), %rcx
cmp %r10, %rcx
jl .L__000Dgas_1
.Lquitgas_1:
add $(144), %rsp
vzeroupper
pop %r15
pop %r14
pop %r13
ret
.p2align 5, 0x90
.globl _DecryptCFB32_RIJ128pipe_AES_NI
_DecryptCFB32_RIJ128pipe_AES_NI:
push %r13
push %r14
push %r15
sub $(144), %rsp
mov (176)(%rsp), %rax
movdqu (%rax), %xmm4
movdqa %xmm4, (%rsp)
mov %rdi, %r13
mov %rsi, %r14
mov %rcx, %r15
movslq %r8d, %r8
movslq %r9d, %r9
sub $(4), %r8
jl .Lshort_inputgas_2
lea (,%r9,4), %r10
.Lblks_loopgas_2:
xor %rcx, %rcx
.L__0020gas_2:
movdqu (%r13,%rcx), %xmm0
movdqu %xmm0, (16)(%rsp,%rcx)
add $(16), %rcx
cmp %r10, %rcx
jl .L__0020gas_2
movdqa (%r15), %xmm4
lea (%r9,%r9,2), %r10
movdqa (%rsp), %xmm0
movdqu (%rsp,%r9), %xmm1
movdqu (%rsp,%r9,2), %xmm2
movdqu (%rsp,%r10), %xmm3
mov %r15, %r10
pxor %xmm4, %xmm0
pxor %xmm4, %xmm1
pxor %xmm4, %xmm2
pxor %xmm4, %xmm3
movdqa (16)(%r10), %xmm4
add $(16), %r10
mov %rdx, %r11
sub $(1), %r11
.Lcipher_loopgas_2:
aesenc %xmm4, %xmm0
aesenc %xmm4, %xmm1
aesenc %xmm4, %xmm2
aesenc %xmm4, %xmm3
movdqa (16)(%r10), %xmm4
add $(16), %r10
dec %r11
jnz .Lcipher_loopgas_2
aesenclast %xmm4, %xmm0
aesenclast %xmm4, %xmm1
aesenclast %xmm4, %xmm2
aesenclast %xmm4, %xmm3
lea (%r9,%r9,2), %r10
movdqa (16)(%rsp), %xmm4
movdqu (16)(%rsp,%r9), %xmm5
movdqu (16)(%rsp,%r9,2), %xmm6
movdqu (16)(%rsp,%r10), %xmm7
pxor %xmm4, %xmm0
movdqa %xmm0, (80)(%rsp)
pxor %xmm5, %xmm1
movdqu %xmm1, (80)(%rsp,%r9)
pxor %xmm6, %xmm2
movdqu %xmm2, (80)(%rsp,%r9,2)
pxor %xmm7, %xmm3
movdqu %xmm3, (80)(%rsp,%r10)
lea (,%r9,4), %r10
xor %rcx, %rcx
.L__0021gas_2:
movdqu (80)(%rsp,%rcx), %xmm0
movdqu %xmm0, (%r14,%rcx)
add $(16), %rcx
cmp %r10, %rcx
jl .L__0021gas_2
movdqu (%rsp,%r10), %xmm0
movdqu %xmm0, (%rsp)
add %r10, %r13
add %r10, %r14
sub $(4), %r8
jge .Lblks_loopgas_2
.Lshort_inputgas_2:
add $(4), %r8
jz .Lquitgas_2
lea (,%r9,2), %r10
lea (%r9,%r9,2), %r11
cmp $(2), %r8
cmovl %r9, %r10
cmovg %r11, %r10
xor %rcx, %rcx
.L__0022gas_2:
movl (%r13,%rcx), %eax
movl %eax, (16)(%rsp,%rcx)
add $(4), %rcx
cmp %r10, %rcx
jl .L__0022gas_2
lea (,%rdx,4), %rax
lea (-144)(%r15,%rax,4), %rax
xor %r11, %r11
.Lsingle_blk_loopgas_2:
movdqu (%rsp,%r11), %xmm0
pxor (%r15), %xmm0
cmp $(12), %rdx
jl .Lkey_128_sgas_2
jz .Lkey_192_sgas_2
.Lkey_256_sgas_2:
aesenc (-64)(%rax), %xmm0
aesenc (-48)(%rax), %xmm0
.Lkey_192_sgas_2:
aesenc (-32)(%rax), %xmm0
aesenc (-16)(%rax), %xmm0
.Lkey_128_sgas_2:
aesenc (%rax), %xmm0
aesenc (16)(%rax), %xmm0
aesenc (32)(%rax), %xmm0
aesenc (48)(%rax), %xmm0
aesenc (64)(%rax), %xmm0
aesenc (80)(%rax), %xmm0
aesenc (96)(%rax), %xmm0
aesenc (112)(%rax), %xmm0
aesenc (128)(%rax), %xmm0
aesenclast (144)(%rax), %xmm0
movdqu (16)(%rsp,%r11), %xmm1
pxor %xmm1, %xmm0
movdqu %xmm0, (80)(%rsp,%r11)
add %r9, %r11
dec %r8
jnz .Lsingle_blk_loopgas_2
xor %rcx, %rcx
.L__0023gas_2:
movl (80)(%rsp,%rcx), %eax
movl %eax, (%r14,%rcx)
add $(4), %rcx
cmp %r10, %rcx
jl .L__0023gas_2
.Lquitgas_2:
add $(144), %rsp
vzeroupper
pop %r15
pop %r14
pop %r13
ret
.p2align 5, 0x90
.globl _DecryptCFB128_RIJ128pipe_AES_NI
_DecryptCFB128_RIJ128pipe_AES_NI:
movdqu (%r9), %xmm0
movslq %r8d, %r8
sub $(64), %r8
jl .Lshort_inputgas_3
.Lblks_loopgas_3:
movdqa (%rcx), %xmm7
mov %rcx, %r10
movdqu (%rdi), %xmm1
movdqu (16)(%rdi), %xmm2
movdqu (32)(%rdi), %xmm3
pxor %xmm7, %xmm0
pxor %xmm7, %xmm1
pxor %xmm7, %xmm2
pxor %xmm7, %xmm3
movdqa (16)(%r10), %xmm7
add $(16), %r10
mov %rdx, %r11
sub $(1), %r11
.Lcipher_loopgas_3:
aesenc %xmm7, %xmm0
aesenc %xmm7, %xmm1
aesenc %xmm7, %xmm2
aesenc %xmm7, %xmm3
movdqa (16)(%r10), %xmm7
add $(16), %r10
dec %r11
jnz .Lcipher_loopgas_3
aesenclast %xmm7, %xmm0
movdqu (%rdi), %xmm4
aesenclast %xmm7, %xmm1
movdqu (16)(%rdi), %xmm5
aesenclast %xmm7, %xmm2
movdqu (32)(%rdi), %xmm6
aesenclast %xmm7, %xmm3
movdqu (48)(%rdi), %xmm7
add $(64), %rdi
pxor %xmm4, %xmm0
movdqu %xmm0, (%rsi)
pxor %xmm5, %xmm1
movdqu %xmm1, (16)(%rsi)
pxor %xmm6, %xmm2
movdqu %xmm2, (32)(%rsi)
pxor %xmm7, %xmm3
movdqu %xmm3, (48)(%rsi)
add $(64), %rsi
movdqa %xmm7, %xmm0
sub $(64), %r8
jge .Lblks_loopgas_3
.Lshort_inputgas_3:
add $(64), %r8
jz .Lquitgas_3
lea (,%rdx,4), %rax
lea (-144)(%rcx,%rax,4), %rax
.Lsingle_blk_loopgas_3:
pxor (%rcx), %xmm0
cmp $(12), %rdx
jl .Lkey_128_sgas_3
jz .Lkey_192_sgas_3
.Lkey_256_sgas_3:
aesenc (-64)(%rax), %xmm0
aesenc (-48)(%rax), %xmm0
.Lkey_192_sgas_3:
aesenc (-32)(%rax), %xmm0
aesenc (-16)(%rax), %xmm0
.Lkey_128_sgas_3:
aesenc (%rax), %xmm0
aesenc (16)(%rax), %xmm0
aesenc (32)(%rax), %xmm0
aesenc (48)(%rax), %xmm0
aesenc (64)(%rax), %xmm0
aesenc (80)(%rax), %xmm0
aesenc (96)(%rax), %xmm0
aesenc (112)(%rax), %xmm0
aesenc (128)(%rax), %xmm0
aesenclast (144)(%rax), %xmm0
movdqu (%rdi), %xmm1
add $(16), %rdi
pxor %xmm1, %xmm0
movdqu %xmm0, (%rsi)
add $(16), %rsi
movdqa %xmm1, %xmm0
sub $(16), %r8
jnz .Lsingle_blk_loopgas_3
.Lquitgas_3:
vzeroupper
ret
|
0000: START
0000: STRT EQU *
0000: LH 13,X'000A'
0004: BCR R15,R13
0006: DC XL10'028017484FD800000000'
0010: DC XL16'003400340000158C158C000000000000'
0020: DC XL16'00000000000049300000000000004930'
0030: DC XL16'00000000000019280000000000001928'
0040: DC XL16'00000001900004560000000000001838'
0050: DC XL16'00000000000016600000000000001660'
0060: DC XL16'0000000000001BE80000000000001BE8'
0070: DC XL16'00000000000000000000000000000000'
0080: DC XL16'00000000000000000000000000000000'
0090: DC XL16'00000000000000000000000000000000'
00A0: DC XL16'000000004550D2DE0000000000000000'
00B0: DC XL16'00000000000000000000000000000000'
00C0: DC XL16'00000000000000000000000000000000'
00D0: DC XL16'00000000000000000000000000000000'
00E0: DC XL16'00000000000000000000000000000000'
00F0: DC XL16'00000000000000000000000000000000'
0100: DC XL16'00000000000000000000000000000000'
0110: DC XL16'00000000000000000000000000000000'
0120: DC XL16'00000000000000000000000000000000'
0130: DC XL16'00000000000000000000000000000000'
0140: DC XL16'00000000000000000000000000000000'
0150: DC XL16'00000000000000000000000000000000'
0160: DC XL16'00000000000000000000000000000000'
0170: DC XL16'00000000000000000000000000000000'
0180: DC XL16'00000000000000000000000000000000'
0190: DC XL16'00000000000000000000000000000000'
01A0: DC XL16'00000000000000000000000000000000'
01B0: DC XL16'00000000000000000000000000000000'
01C0: DC XL16'00000000000000000000000000000000'
01D0: DC XL16'00000000000000000000000000000000'
01E0: DC XL16'00000000000000000000000000000000'
01F0: DC XL16'00000000000000000000000000000000'
0200: DC XL16'00000000000000000000000000000000'
0210: DC XL16'00000000000000000000000000000000'
0220: DC XL16'00000000000000000000000000000000'
0230: DC XL16'00000000000000000000000000000000'
0240: DC XL16'00000000000000000000000000000000'
0250: DC XL16'00000000000000000000000000000000'
0260: DC XL16'00000000000000000000000000000000'
0270: DC XL16'00000000000000000000000000000000'
0280: DC XL16'F440F240009B0000009D0000FF6B0002'
0290: DC XL16'0000000A000000280000000700000000'
02A0: DC XL16'00000000009A0A000AC809A809280000'
02B0: DC XL16'0908000033C000001404A3030000F040'
02C0: DC XL16'00005CF0000000020000002700000908'
02D0: DC XL16'00005C50000000000000028000000000'
02E0: DC XL16'00000000E2E85BE2E3C44390C0010007'
02F0: DC XL16'0014046E000000000000000000000005'
0300: DC XL16'08000000006C006C04080558049A0000'
0310: DC XL16'186603C800000100FF0F1FFF1F0000C8'
0320: DC XL16'00000000000000000000000000001D32'
0330: DC XL16'00002710000000000000000000000000'
0340: DC XL16'00000000000000000408053800000000'
0350: DC XL16'3D000000000055400000000000000000'
0360: DC XL16'00000000000000000000606000000000'
0370: DC XL16'052C006000001F200000000000000334'
0380: DC XL16'0000070000010000000000004632493C'
0390: DC XL16'42004158000000000000000000000000'
03A0: DC XL16'00000000000000000000000000000000'
03B0: DC XL16'00000000000000000000000000000000'
03C0: DC XL16'00000000000000000000000000000000'
03D0: DC XL16'00000000000000000000000000000000'
03E0: DC XL16'00000000000000000000000000000000'
03F0: DC XL16'00000000000000000000000000000000'
0400: DC XL14'000000000000000000005C500000'
040E: DC XL16'000000000000000060F8000067400000'
041E: DC XL16'0000000000000000000000000000FFFF'
* SAVE USER REGISTERS
USING JT$TCB,R14
042E: SSTM R0,R15,JT$SA
0432: TM SB$CFG,BB$FPT FLOATING POINT INSTALLED?
0436: BCR R14,R5
0438: NC X'015'(3,R14),X'015'(R14)
043E: BCR R8,R5
0440: STD 0,JT$FPT
0444: STD 2,JT$FPT+8
0448: STD 4,JT$FPT+16
044C: STD 6,JT$FPT+24
0450: BCR R15,R5
* RESTORE USER REGISTERS
USING JT$TCB,R3
0452: SLM R0,R15,JT$SA
0456: TM SB$CFG,BB$FPT FLOATING POINT INSTALLED?
045A: BCR R14,R5
045C: LD 0,JT$FPT
0460: LD 2,JT$FPT+8
0464: LD 4,JT$FPT+16
0468: LD 6,JT$FPT+24
046C: BCR R15,R5
* RESIDENT SVC JUMP TABLE
046E: DC XL16'4630199619E64E50199005801CA41CEA'
047E: DC XL16'19F8051A05EA1D705A0805EA05EA05E0'
048E: DC XL16'05E005E005E005E02525000000000000'
049E: DC XL16'00000000000000000000000000000000'
04AE: DC XL16'00000000000000000000000000000000'
04BE: DC XL16'00000000000000000000000000000000'
04CE: DC XL16'00000000000000000000000000000000'
04DE: DC XL16'00000000000000000000000000000000'
04EE: DC XL16'00000000000000000000000000000000'
04FE: DC XL16'00000000000000000000000000000000'
050E: DC XL16'0000000000000000000000005830B0DC'
051E: DC XL16'123307734830200E07F305EA25250000'
052E: DC XL16'00000000000000000000000000000000'
053E: DC XL16'00000000000000000000000000000000'
054E: DC XL16'00000000000000000000000000000000'
055E: DC XL16'00000000000000000000000000000000'
056E: DC XL16'00000000000000000000000000000000'
057E: DC XL2'0000'
* SVC 5 - OPR
0580: BALR R3,R0
0582: AI X'0406',1
0586: OI JT$WAIT+2(R14),BT$WTOPR SET WAIT FOR CONSOLE LINE
058A: OI SB$SOI1(R11),BB$SOOPR OPR COMMUN. SVC
058E: L 14,SB$SOS(,R11) GET ADDR SOS TCV
0592: NI JT$WAIT+1(R14),247 CLEAR YIELD BIT
0596: BCR R15,R15 GO TO SWITCHER
*
0598: BALR R3,R0
059A: NI SB$ERFLG,247 CLEAR ALL BUT TRANSIENT IN CONTROL
059E: SR R2,R2
05A0: L 5,SB$SOI GET SUPERVISOR INDICATOR WORD
05A4: LTR R5,R5 IS IT ZERO?
05A6: BNZ X'05AE' NO
05AA: SVC 4 YES, NOTHING TO DO SO YIELD
05AC: BCR R15,R3
*
05AE: BM X'05BC' CONSOLE INTERRUPT?
05B2: LA 2,X'0001'(R2) BUMP R2
05B6: AR R5,R5 R5 = R5 * 2
05B8: BC 15,X'05AE'
05BC: XR R1,R1 CLEAR R1
05BE: LA 2,X'100'(R2,R2) R2 = R2 * 2 + 265
05C2: LA 5,X'0002'
05C6: LM R8,R11,SB$PBA LOAD STANDARD SUPER REGISTERS
05CA: BALR R3,R0
05CC: NI SB$ERFLG,247 CLEAR ALL BUT TRANSIENT IN CONTROL
05D0: L 7,SB$SOS GET ADDR OF SOS TCB
05D4: LA 7,JT$TRLNG(R7)
05D8: BC 15,X'077C'
05DC: DC XL4'00000000'
*
05E0: BALR R3,R0
USING *,R3
* R5 POINTS TO 1ST TRANSIENT AREA
*
* IT LOOKS LIKE THE TCB FOLLOWING THE TRANSIENT AREA IN MEMORY IS THE
* ONE THAT CONTROLS THAT TRANSIENT AREA. TRANSIENT AREAS ARE 1032 BYTES
* IN LENGTH.
05E2: CLI X'0053',105 SVC CODE <= 105
05E6: BNH X'05F6' YES
05EA: LA 0,X'0021'
05EE: SR R1,R1
05F0: LH 3,X'0310'
05F4: BCR R15,R3
05F6: AI SB$AVC,255 DEC. # OF AVAIL. TRANS. AREAS
05FA: BM X'06C0' NEGATIVE!
05FE: SR R2,R2 GET SVC CODE
0600: IC 2,X'018'(,R14)
0604: SR R7,R7 CLEAR REGS.
0606: SR R8,R8
0608: SR R9,R9
060A: SR R4,R4
060C: TM X'40E'(R5),BT$WTTRN TEST JT$WAIT+2 OF TCB FOLLOWING TRANS. AREA.
0610: BO X'0620' SET
0614: LA 5,X'04A8'(R5) POINT TO NEXT TRANSIENT AREA
0618: BCT 6,X'060C' DEC TRANS AREA COUNT & LOOP
061C: BC 15,X'0676'
0620: TM X'000'(R5),128 TEST TRANSIENT AREA BIT
0624: BZ X'0646' NOT SET
0628: MVI X'420'(R5),0
062C: C 14,X'420'(,R5)
0630: BC 7,X'07A'(,R3)
0634: LH 9,X'0000'(R5)
0638: N 9,X'31E'(,R3)
063C: CR R2,R9
063E: BC 7,X'07A'(,R3)
0642: BC 15,X'0A6'(,R3)
0646: TM X'000'(R5),79 ANY OTHER BITS SET?
064A: BZ X'0654' NO
064E: LR R4,R5 POINT TO TRANSIENT AREA
0650: BC 15,X'0614'
*
0654: CH 2,X'0000'(R5)
0658: BC 8,X'0A6'(,R3)
065C: LH 9,X'414'(,R5)
0660: LA 9,X'0001'(R9)
0664: STH 9,X'414'(,R5)
0668: CR R9,R8
066A: BC 13,X'032'(,R3)
066E: LR R8,R9
0670: LR R7,R5
0672: BC 15,X'0614'
0676: LTR R5,R4 POINT TO TRANSIENT AREA TO USER
0678: BC 7,X'067E'
067C: LR R5,R7
067E: MVC X'42C'(4,R5),X'06BC' MOVE NEW ADDRESS TO T/A TCB PSW
0684: BC 15,X'0690'
*
0688: ST 5,X'42C'(,R5)
068C: AI X'42E'(R5),2
0690: LM R8,R9,SB$PBA RESTORE REGS FROM SIB
0694: XC X'414'(2,R5),X'414'(R5) CLEAR OUTSTANDING I/O COUNT IN TCB
069A: OI JT$WAIT+2,BT$WTTRN SET 'WAIT FOR TRANSIENT' BIT
069E: MVC X'408'(1,R5),X'000'(R14)
06A4: ST 14,X'420'(,R5)
06A8: STM R0,R14,X'430'(,R5)
06AC: ST 5,X'46C'(,R5)
06B0: NI X'40E'(R5),253
06B4: NI X'40D'(R5),247
06B8: BCR R15,R15 RETURN TO SWITCHER
06BA: DC XL6'000000000778'
06C0: OI X'006'(R14),4
06C4: BCR R15,R15
*
06C6: BALR R3,R0
USING *,R3
06C8: NC X'474'(8,R15),X'474'(R15)
06CE: BC 8,X'02E'(,R3)
06D2: TM X'02FE',32
06D6: BC 1,X'21E'(,R3)
06DA: LA 1,X'0408'(R15)
06DE: O 1,X'0A8'(,R3)
06E2: L 0,X'478'(,R15)
06E6: SVC 8 LOCK SYSTEM TABLE
06E8: LA 1,X'0408'(R15)
06EC: O 1,X'0AC'(,R3)
06F0: L 0,X'474'(,R15)
06F4: SVC 8 LOCK SYSTEM TABLE
06F6: SVC 2 WAIT ALL
06F8: NI X'417'(R15),254
06FC: L 14,X'420'(,R15)
0700: LA 14,X'0000'(R14)
0704: LTR R14,R14
0706: BC 8,X'046'(,R3)
070A: NI X'006'(R14),253
070E: SSM SB$INHIB,0 DISABLE INTERRUPTS
0712: AI X'028E',1
0716: BC 13,X'058'(,R3)
071A: OI X'40E'(R15),2
071E: SVC 4 YIELD
0720: L 4,X'076C'
0724: SR R5,R5
0726: DIAG X'104'(R4),15
072A: BC 2,X'046'(,R3)
072E: BC 4,X'05E'(,R3)
0732: LR R14,R5
0734: LA 14,X'0000'(R14)
0738: ST 14,X'420'(,R15)
073C: SR R2,R2
073E: IC 2,X'018'(,R14)
0742: LH 4,X'234'(,R3)
0746: BALR R3,R4
0748: SSM SB$ALLOW,0
074C: MVC X'408'(1,R15),X'000'(R14)
0752: OI X'006'(R14),2
0756: NI X'006'(R14),251
075A: NI X'000'(R15),127
075E: CH 2,X'000'(,R15)
0762: BC 8,X'002'(,R15)
0766: BC 15,X'030'(,R3)
076A: DC XL14'0000000604088800000008000000'
* THIS SEEMS TO HAVE TO DO WITH CALCULATING THE DISK ADDRESS OF
* THE TRANSIENT REQUIRED TO EXECUTE A SUPERVISOR CALL. IT ALSO
* LOADS THE TRANSIENT
*
* R7 POINTS TO A BCW
* R7 + 16 POINTS TO CCB
0778: LA 7,X'47C'(,R15)
077C: BALR R3,R0
USING *,R3
USING SB$TRF,R6
USING IB$BCW,R7
077E: CH 2,X'08F4' SVC ID < 11?
0782: BL X'08DA' YES
0786: CH 2,X'0BF6' SVC ID > 2200?
078A: BH X'08DA' YES
078E: CH 2,X'0BF8' SVC ID < 256?
0792: BL X'O8BC' YES
0796: STH 5,X'006'(,R7) SAVE RECORD COUNT TO BCW
079A: SLL R5,X'0008' * 256
079E: STH 5,X'004'(,R7)
07A2: LA 6,X'0288'
07A6: LR R5,R2
07A8: SH 5,X'08F8' R5 = R5 - 256
07AC: SR R4,R4 R5 = R5 / RECS PER TRACK
07AE: D 4,X'0294'
07B2: LA 4,X'0001'(R4) BUMP DISK REC # BY 1
07B6: STC 4,IB$RECRD SAVE REC # TO BCW
07BA: AH 5,X'0002'(R6) CALC TRACK #
07BE: SR R4,R4 CLEAR R4
07C0: D 4,SB$TCYL DIVIDE BY TRKS/CYL
07C4: AH 5,X'0000'(R6) CALC CYL #
07C8: STH 5,IB$CYL SAVE CYL # TO BCW
07CC: STC 4,IB$TRACK SAVE TRK # TO BCW
07D0: LR R6,R1 POINT TO TRANS NAME
07D2: LA 1,SB$RES GET PTR TO SYSRES PUB
07D6: ST 1,X'020'(,R7) SAVE TO CCB
07DA: LA 1,X'010'(,R7) POINT TO CCB
07DE: ST 15,X'000'(,R7)
07E2: MVI X'000'(R7),2 SET READ COMMAND IN BCW
07E6: MVI X'00B'(R7),0 CLEAR TRACK CONDITION IN BCW
07EA: MVI X'0833',11
07EE: NI X'000'(R1),252
07F2: AI X'0832',255
07F6: BZ X'082A' OOPS!
07FA: BAL X'089E'
07FE: BC 15,X'0F2'(,R3)
0802: BAL 5,X'104'(,R3)
0806: BC 15,X'0F2'(,R3)
*
080A: TM X'013'(R7),BC$OWN OWN ERROR CODE SET IN CCB?
080E: BNO X'081C' NO
0812: MVC X'00C'(2,R7),X'224'(R15) SET CYL # IN BCW TO X'9D'
0818: BC 15,X'07F2'
*
081C: LR R0,R2
081E: SLL R0,X'0010'
0822: IC 0,X'180'(,R3)
0826: BC 15,X'0C8'(,R3)
082A: HPR X'0900',9
082E: BC 15,X'06C'(,R3)
0832: DC XL2'0000'
0834: L 15,X'0314'
0838: SH 15,X'0348'
083C: LH 2,X'0000'(R15)
0840: SLL R2,X'0010'
0844: OR R0,R2
*
0846: BALR R3,R0
0848: O 0,X'0A8'(,R3)
084C: L 14,X'420'(,R15)
0850: LA 14,X'0000'(R14)
0854: LH 4,X'0B4'(,R3)
0858: BAL 3,X'0004'(R4)
085C: LA 2,X'001C'
0860: TM X'417'(R15),1
0864: BC 14,X'0778'
0868: ST 0,X'028'(,R14)
086C: BC 15,X'06C6'
* JUMP TO 1ST INSTRUCTION OF TRANSIENT JUST LOADED
0870: LR R1,R6
0872: CH 2,X'000C'
0876: BC 7,X'100'(,R3)
087A: HPR X'0CCC',0
087E: BC 15,X'002'(R15)
0882: LH 4,X'00C'(,R7)
0886: TM X'013'(R7),128
088A: BC 14,X'114'(,R3)
088E: STH 4,X'224'(,R15)
0892: AH 4,X'028C'
0896: STH 4,X'00C'(,R7)
089A: OI X'00C'(R7),128
* READ STUFF FROM DISK
089E: SVC 0 SVC 0 - PHYISCAL I/O REQUEST
08A0: TM X'002'(R1),128
08A4: BC 1,X'12C'(,R3)
08A8: SVC 1 SVC 1 - WAIT FOR I/O
08AA: TM X'002'(R1),119
08AE: BC 7,X'13A'(,R3)
08B2: CH 2,X'000'(,R15)
08B6: BCR 8,R5
08B8: BC 15,X'004'(,R5)
*
08BC: LA 6,X'0284'
08C0: MVI X'007'(R7),4 SET REC COUNT IN BCW
08C4: MVC X'004'(2,R7),X'17C'(R3)
08CA: LR R5,R2 GET SVC ID
08CC: SR R4,R4 CLEAR R4
08CE: D 4,SB$R1024 DIVIDE SVC ID BY 1024 BLKS/TRACK
08D2: SLL R4,X'0002' CALC PHYS REC # ON TRACK
08D6: BC 15,X'07B2'
*
08DA: LA 0,X'0022'
08DE: CLI X'008'(R14),0
08E2: BC 7,X'0BE'(,R3)
08E6: HPR X'0822',8
08EA: BC 15,X'168'(,R3)
08EE: DC XL2'0000'
08F0: SSM X'0100',0
08F4: DC XL2'000B'
08F6: SSK R9,R8
08F8: DC XL2'0100'
08FA: SPM R0,R0
08FC: XR R2,R12
08FE: HDR R0,R0
0900: DC XL2'0000'
0902: SUR R15,R15
* Device control table (PUB table) starts @ 908
0904: DC XL16'00000000000000000000000000000000'
0914: DC XL16'01200080134C0DE81D881DF800000000'
0924: DC XL16'00000001000001600000000000000000'
0934: DC XL16'0480040A14B40E00202824D000000000'
0944: DC XL16'00000002000001700000000000000000'
0954: DC XL16'04200C1614D80E18202824D000000000'
0964: DC XL16'00000003000000020000000000000000'
0974: DC XL16'0440000913940EF41D881DF800000000'
0984: DC XL16'000000040DA801430000000000000000'
0994: DC XL16'0408000515440F0C202824D000000000'
09A4: DC XL16'00000005000000010000000000000000'
09B4: DC XL16'0820000213700F241D881DF800000000'
09C4: DC XL16'00000006000001100000000000000000'
09D4: DC XL16'0880040014000F3C202824D000000000'
09E4: DC XL16'00000007000001300000000000000000'
09F4: DC XL16'0802000014480F54202824D000000000'
0A04: DC XL16'00000008000001200000000000000000'
0A14: DC XL16'0801000014240F6C202824D000000000'
0A24: DC XL16'000000090DA801410000000000000000'
0A34: DC XL16'0808000014FC0F84202824D000000000'
0A44: DC XL16'0000000A000001500000000000000000'
0A54: DC XL16'0240000414900F9C202824D000000000'
0A64: DC XL16'0000000B000000030000000000000000'
0A74: DC XL16'0220000613B80FB41D881DF800000000'
0A84: DC XL16'0000000C000001310000000000000000'
0A94: DC XL16'0202000014480FCC202824D000000000'
0AA4: DC XL16'0000000D0DA801420000000000000000'
0AB4: DC XL16'0208000015200FE4202824D000000000'
0AC4: DC XL16'0000000E000003000100800000000000'
0AD4: DC XL16'2010000013280FFC2CF02DF000000000'
0AE4: DC XL16'8000000F000003010000800000000000'
0AF4: DC XL16'20100000132810142CF02DF000000000'
0B04: DC XL16'80000010000003020000800000000000'
0B14: DC XL16'201000001328102C2CF02DF000000000'
0B24: DC XL16'80000011000003030000800000000000'
0B34: DC XL16'20100000132810442CF02DF000000000'
0B44: DC XL16'80000012000004400000800000000000'
0B54: DC XL16'204000001568105C3AF03D8800000000'
0B64: DC XL16'80000013000004410000800000000000'
0B74: DC XL5'2040000015'
0B79: DC XL1'68'
0B7A: LPR R7,R4
0B7C: AER R15,R0
0B7E: DER R8,R8
0B80: DC XL4'00000000'
0B84: SSM X'0014',0
0B88: DC XL2'0000'
0B8A: SPM R4,R2
0B8C: DC XL2'0000'
0B8E: SSM X'0000',0
0B92: DC XL2'0000'
0B94: LDPR R4,R0
0B96: DC XL2'0000'
0B98: CLR R6,R8
0B9A: LPR R8,R12
0B9C: AER R15,R0
0B9E: DER R8,R8
0BA0: DC XL4'00000000'
0BA4: SSM X'0015',0
0BA8: DC XL2'0000'
0BAA: SPM R0,R0
0BAC: DC XL2'0000'
0BAE: SSM X'0000',0
0BB2: DC XL2'0000'
0BB4: LDPR R2,R0
0BB6: DC XL2'0000'
0BB8: CLR R6,R8
0BBA: LPR R10,R4
0BBC: AER R15,R0
0BBE: DER R8,R8
0BC0: DC XL4'00000000'
0BC4: SSM X'0016',0
0BC8: DC XL2'0000'
0BCA: SPM R0,R1
0BCC: DC XL2'0000'
0BCE: SSM X'0000',0
0BD2: DC XL2'0000'
0BD4: LDPR R2,R0
0BD6: DC XL2'0000'
0BD8: CLR R6,R8
0BDA: LPR R11,R12
0BDC: AER R15,R0
0BDE: DER R8,R8
0BE0: DC XL4'00000000'
0BE4: SSM X'0017',0
0BE8: DC XL2'0000'
0BEA: SPM R0,R2
0BEC: DC XL2'0000'
0BEE: SSM X'0000',0
0BF2: DC XL2'0000'
0BF4: LDPR R2,R0
0BF6: DC XL2'0000'
0BF8: CLR R6,R8
0BFA: LPR R13,R4
0BFC: AER R15,R0
0BFE: DER R8,R8
0C00: DC XL4'00000000'
0C04: SSM X'0018',0
0C08: DC XL2'0000'
0C0A: SPM R0,R3
0C0C: DC XL2'0000'
0C0E: SSM X'0000',0
0C12: DC XL2'0000'
0C14: LDPR R2,R0
0C16: DC XL2'0000'
0C18: CLR R6,R8
0C1A: LPR R14,R12
0C1C: AER R15,R0
0C1E: DER R8,R8
0C20: DC XL4'00000000'
0C24: SSM X'0019',0
0C28: DC XL2'0000'
0C2A: SPM R1,R0
0C2C: DC XL2'0000'
0C2E: SSM X'0000',0
0C32: DC XL2'0000'
0C34: LDPR R8,R0
0C36: DC XL2'0000'
0C38: CLR R6,R8
0C3A: LNR R0,R4
0C3C: AER R15,R0
0C3E: DER R8,R8
0C40: DC XL4'00000000'
0C44: SSM X'001A',0
0C48: DC XL2'0000'
0C4A: SPM R1,R1
0C4C: DC XL2'0000'
0C4E: SSM X'0000',0
0C52: DC XL2'0000'
0C54: LDPR R8,R0
0C56: DC XL2'0000'
0C58: CLR R6,R8
0C5A: LNR R1,R12
0C5C: AER R15,R0
0C5E: DER R8,R8
0C60: DC XL4'00000000'
0C64: SSM X'001B',0
0C68: DC XL2'0000'
0C6A: SPM R1,R2
0C6C: DC XL2'0000'
0C6E: SSM X'0000',0
0C72: DC XL2'0000'
0C74: LDPR R8,R0
0C76: DC XL2'0000'
0C78: CLR R6,R8
0C7A: LNR R3,R4
0C7C: AER R15,R0
0C7E: DER R8,R8
0C80: DC XL4'00000000'
0C84: SSM X'001C',0
0C88: DC XL2'0000'
0C8A: SPM R2,R0
0C8C: DC XL2'0000'
0C8E: SSM X'0000',0
0C92: DC XL2'0000'
0C94: LPR R1,R0
0C96: DC XL2'000A'
0C98: CLR R6,R8
0C9A: LNR R4,R12
0C9C: AER R15,R0
0C9E: DER R8,R8
0CA0: DC XL10'000000000000001D0000'
0CAA: SPM R2,R1
0CAC: DC XL2'0000'
0CAE: SSM X'0000',0
0CB2: DC XL2'0000'
0CB4: LPR R1,R0
0CB6: DC XL2'000A'
0CB8: CLR R6,R8
0CBA: LNR R6,R8
0CBC: AER R15,R0
0CBE: DER R8,R8
0CC0: DC XL10'000000000000001E0000'
0CCA: SPM R2,R2
0CCC: DC XL2'0000'
0CCE: SSM X'0000',0
0CD2: DC XL2'0000'
0CD4: LPR R1,R0
0CD6: DC XL2'000A'
0CD8: CLR R6,R8
0CDA: LNR R8,R4
0CDC: AER R15,R0
0CDE: DER R8,R8
0CE0: DC XL10'000000000000001F0000'
0CEA: SPM R3,R0
0CEC: DC XL2'0000'
0CEE: SSM X'0000',0
0CF2: DC XL2'0000'
0CF4: LPR R4,R0
0CF6: DC XL2'000E'
0CF8: CLR R6,R8
0CFA: LNR R10,R0
0CFC: AER R15,R0
0CFE: DER R8,R8
0D00: DC XL10'00000000000000200000'
0D0A: SPM R3,R1
0D0C: DC XL2'0000'
0D0E: SSM X'0000',0
0D12: DC XL2'0000'
0D14: LPR R4,R0
0D16: DC XL2'000E'
0D18: CLR R6,R8
0D1A: LNR R11,R12
0D1C: AER R15,R0
0D1E: DER R8,R8
0D20: DC XL10'00000000000000210000'
0D2A: SPM R3,R2
0D2C: DC XL2'0000'
0D2E: SSM X'0000',0
0D32: DC XL2'0000'
0D34: LPR R4,R0
0D36: DC XL2'000E'
0D38: CLR R6,R8
0D3A: LNR R13,R8
0D3C: AER R15,R0
0D3E: DER R8,R8
0D40: DC XL14'0000000000000022000001000000'
0D4E: SSM X'0000',0
0D52: DC XL2'0000'
0D54: LPR R8,R0
0D56: DC XL2'0006'
0D58: LCR R13,R12
0D5A: LNR R15,R4
0D5C: LDPR R2,R8
0D5E: HDR R13,R0
0D60: DC XL14'0000000000000023000001010000'
0D6E: SSM X'0000',0
0D72: DC XL2'0000'
0D74: LPR R8,R0
0D76: DC XL2'0006'
0D78: LCR R13,R12
0D7A: LTR R1,R0
0D7C: LDPR R2,R8
0D7E: HDR R13,R0
0D80: DC XL14'0000000000000024000001020000'
0D8E: SSM X'0000',0
0D92: DC XL2'0000'
0D94: LPR R8,R0
0D96: DC XL2'0006'
0D98: LCR R13,R12
0D9A: LTR R2,R12
0D9C: LDPR R2,R8
0D9E: HDR R13,R0
0DA0: DC XL16'00000000000000250000014000000000'
0DB0: DC XL8'0000000000000000'
0DB8: NR R6,R12
0DBA: LTR R4,R8
0DBC: LDPR R2,R8
0DBE: HDR R13,R0
0DC0: DC XL16'00000000000000260000000000000000'
0DD0: DC XL16'00000000000000000000000000000000'
0DE0: DC XL16'00000000000000000000000000000000'
0DF0: DC XL16'00000000000000000000000000000000'
0E00: OC X'5D3'(231,R13),X'3F1'(R12)
0E06: STH 4,X'6E6'(,R13)
0E0A: CLC X'6F1'(230,R12),X'040'(R4)
0E10: DC XL8'0000000000000000'
0E18: OC X'5D3'(231,R13),X'3F2'(R12)
0E1E: STH 4,X'6E6'(,R13)
0E22: CLC X'6F1'(230,R12),X'040'(R4)
0E28: DC XL16'00000000000000000000000000000000'
0E38: DC XL16'00000000000000000000000000000000'
0E48: DC XL16'00000000000000000000000000000000'
0E58: DC XL16'00000000000000000000000000000000'
0E68: DC XL16'00000000000000000000000000000000'
0E78: DC XL16'00000000000000000000000000000000'
0E88: DC XL16'00000000000000000000000000000000'
0E98: DC XL16'00000000000000000000000000000000'
0EA8: DC XL16'00000000000000000000000000000000'
0EB8: DC XL16'00000000000000000000000000000000'
0EC8: DC XL16'00000000000000000000000000000000'
0ED8: DC XL16'00000000000000000000000000000000'
0EE8: DC XL12'000000000000000000000000'
0EF4: OC X'5D3'(231,R13),X'3F1'(R12)
0EFA: STH 4,X'6E6'(,R13)
0EFE: CLC X'6F1'(230,R12),X'040'(R4)
0F04: DC XL8'0000000000000000'
0F0C: OC X'5D3'(231,R13),X'3F2'(R12)
0F12: STH 4,X'6E6'(,R13)
0F16: CLC X'6F1'(230,R12),X'040'(R4)
0F1C: DC XL16'00000000000000000000000000000000'
0F2C: DC XL16'00000000000000000000000000000000'
0F3C: DC XL16'00000000000000000000000000000000'
0F4C: DC XL16'00000000000000000000000000000000'
0F5C: DC XL16'00000000000000000000000000000000'
0F6C: DC XL16'00000000000000000000000000000000'
0F7C: DC XL16'00000000000000000000000000000000'
0F8C: DC XL16'00000000000000000000000000000000'
0F9C: DC XL16'00000000000000000000000000000000'
0FAC: DC XL16'00000000000000000000000000000000'
0FBC: DC XL16'00000000000000000000000000000000'
0FCC: DC XL16'00000000000000000000000000000000'
0FDC: DC XL16'00000000000000000000000000000000'
0FEC: DC XL16'00000000000000000000000000000000'
0FFC: DC XL16'000000000000000000000000009A0000'
100C: DC XL16'0000009B000000000000000000000000'
101C: DC XL16'00000000000000000000000000000000'
102C: DC XL16'00000000000000000000000000000000'
103C: DC XL16'00000000000000000000000000000000'
104C: DC XL16'00000000000000000000000000000000'
105C: DC XL16'00000000000000000000000000000000'
106C: DC XL16'00000000000000000000000000000000'
107C: DC XL16'00000000000000000000000000000000'
108C: DC XL16'00000000000000000000000000000000'
109C: DC XL16'00000000000000000000000000000000'
10AC: DC XL16'00000000000000000000000000000000'
10BC: DC XL16'00000000000000000000000000000000'
10CC: DC XL16'00000000000000000000000000000000'
10DC: DC XL16'00000000000000000000000000000000'
10EC: DC XL16'00000000000000000000000000000000'
10FC: DC XL16'00000000000000000000000000000000'
110C: DC XL16'00000000000000000000000000000000'
111C: DC XL16'00000000000000000000000000000000'
112C: DC XL16'00000000000000000000000000000000'
113C: DC XL16'00000000000000000000000000000000'
114C: DC XL16'00000000000000000000000000000000'
115C: DC XL16'0000C3C3000000000000000000000000'
116C: DC XL16'0000000000000000000000000000C3C3'
117C: DC XL16'00000000000000000000000000000000'
118C: DC XL16'00000000000000000000C3C300000000'
119C: DC XL16'00000000000000000000000000000000'
11AC: DC XL16'000000000000C3C30000000000000000'
11BC: DC XL16'00000000000000000000000000000000'
11CC: DC XL16'0000C3C3000000000000000000000000'
11DC: DC XL16'0000000000000000000000000000C3C3'
11EC: DC XL16'00000000000000000000000000000000'
11FC: DC XL10'00000000000000000000'
1206: DIAG X'0000',131
120A: DC XL16'00000000000000000000000000000000'
121A: DC XL8'0000000000000000'
1222: DIAG X'0000',131
1226: DC XL16'00000000000000000000000000000000'
1236: DC XL8'0000000000000000'
123E: DIAG X'0000',131
1242: DC XL16'00000000000000000000000000000000'
1252: DC XL16'00000000000000000000000000000000'
1262: DC XL16'00000000000000000000000000000000'
1272: DC XL16'00000000000000000000000000000000'
1282: DC XL16'00000000000000000000000000000000'
1292: DC XL16'00000000000000000000000000000000'
12A2: DC XL16'00000000000000000000000000000000'
12B2: DC XL16'00000000000000000000000000000000'
12C2: DC XL16'00000000000000000000000000000000'
12D2: DC XL16'00000000000000000000000000000000'
12E2: DC XL16'00000000000000000000000000000000'
12F2: DC XL16'00000000000000000000000000000000'
1302: DC XL16'00000000000000000000000000000000'
1312: DC XL16'00000000000000000000000000000000'
1322: DC XL16'00000000000000000000000000000000'
1332: DC XL16'00000000000000000000000000000000'
1342: DC XL8'0000000000000000'
134A: LCR R2,R8
134C: DC XL16'00000000000000000000000000000000'
135C: DC XL16'00000000000000000000000000000000'
136C: DC XL2'0000'
136E: LCR R4,R12
1370: DC XL16'00000000000000000000000000000000'
1380: DC XL16'00000000000000000000000000000000'
1390: DC XL2'0000'
1392: LCR R7,R0
1394: DC XL16'00000000000000000000000000000000'
13A4: DC XL16'00000000000000000000000000000000'
13B4: DC XL2'0000'
13B6: LCR R9,R4
13B8: DC XL16'00000000000000000000000000000000'
13C8: DC XL16'00000000000000000000000000000000'
13D8: DC XL2'0000'
13DA: LCR R11,R8
13DC: DC XL16'00000000000000000000000000000000'
13EC: DC XL16'00000000000000000000000000000000'
13FC: DC XL2'0000'
13FE: LCR R13,R12
1400: DC XL16'00000000000000000000000000000000'
1410: DC XL16'00000000000000000000000000000000'
1420: DC XL2'0000'
1422: NR R0,R0
1424: DC XL16'00000000000000000000000000000000'
1434: DC XL16'00000000000000000000000000000000'
1444: DC XL2'0000'
1446: NR R2,R4
1448: DC XL16'00000000000000000000000000000000'
1458: DC XL16'00000000000000000000000000000000'
1468: DC XL2'0000'
146A: NR R4,R8
146C: DC XL16'00000000000000000000000000000000'
147C: DC XL16'00000000000000000000000000000000'
148C: DC XL2'0000'
148E: NR R6,R12
1490: DC XL16'00000000000000000000000000000000'
14A0: DC XL16'00000000000000000000000000000000'
14B0: DC XL2'0000'
14B2: NR R9,R0
14B4: DC XL16'00000000000000000000000000000000'
14C4: DC XL16'00000000000000000000000000000000'
14D4: DC XL2'0000'
14D6: NR R11,R4
14D8: DC XL16'00000000000000000000000000000000'
14E8: DC XL16'00000000000000000000000000000000'
14F8: DC XL2'0000'
14FA: NR R13,R8
14FC: DC XL16'00000000000000000000000000000000'
150C: DC XL16'00000000000000000000000000000000'
151C: DC XL2'0000'
151E: NR R15,R12
1520: DC XL16'00000000000000000000000000000000'
1530: DC XL16'00000000000000000000000000000000'
1540: DC XL2'0000'
1542: CLR R2,R0
1544: DC XL16'00000000000000000000000000000000'
1554: DC XL16'00000000000000000000000000000000'
1564: DC XL2'0000'
1566: CLR R4,R4
1568: DC XL16'00000000000000000000000000000000'
1578: DC XL16'00000000000000000000000000000000'
1588: DC XL2'0000'
158A: CLR R6,R8
158C: SSM X'0000',0
1590: SSM X'0000',0
1594: SSM X'0000',0
1598: SSM X'0000',0
159C: SSM X'0000',0
15A0: SSM X'0000',0
15A4: SSM X'0000',0
15A8: SSM X'0000',0
15AC: SSM X'0000',0
15B0: SSM X'0000',0
15B4: SSM X'0000',0
15B8: SSM X'0000',0
15BC: SSM X'0000',0
15C0: SSM X'0000',0
15C4: SSM X'0000',0
15C8: SSM X'0000',0
15CC: SSM X'0000',0
15D0: SSM X'0000',0
15D4: SSM X'0000',0
15D8: SSM X'0000',0
15DC: SSM X'0000',0
15E0: SSM X'0000',0
15E4: SSM X'0000',0
15E8: SSM X'0000',0
15EC: SSM X'0000',0
15F0: SSM X'0000',0
15F4: SSM X'0000',0
15F8: SSM X'0000',0
15FC: SSM X'0000',0
1600: SSM X'0000',0
1604: SSM X'0000',0
1608: SSM X'0000',0
160C: SSM X'0000',0
1610: SSM X'0000',0
1614: SSM X'0000',0
1618: SSM X'0000',0
161C: SSM X'0000',0
1620: SSM X'0000',0
1624: SSM X'0000',0
1628: SSM X'0000',0
162C: SSM X'0000',0
1630: SSM X'0000',0
1634: SSM X'0000',0
1638: SSM X'0000',0
163C: SSM X'0000',0
1640: SSM X'0000',0
1644: SSM X'0000',0
1648: SSM X'0000',0
164C: SSM X'0000',0
1650: SSM X'0000',0
1654: SSM X'0000',0
1658: SSM X'0000',0
165C: DC XL4'00000000'
* Supervisor call interrupt handler.
1660: BALR R3,R0
USING *,R3
1662: MVC JT$PSW+3(5),X'0053' SAVE PSW TO TCB
1668: OI SB$ERFLG,BB$RES SET 'IN SVC' FLAG
166C: LH 6,X'1746' SAVE USER REGISTERS
1670: BALR R5,R6
1672: OI SB$FLG,BB$SVC
1676: LA 4,X'172C'
167A: BALR R3,R4
*
167C: SR R2,R2 CLEAR R2
167E: IC 2,X'0053' GET THE SVC CODE
1682: STC 2,JT$ECB SAVE TO TCB
1686: LTR R2,R2 R2 = 0?
1688: BNZ X'1710' NO - X'094'(,R3)
* SVC 0 - EXCP - EXECUTE CHANNEL PROGRAM - PHYSICAL I/O REQUEST
*
* R1 POINTS TO CCB (SEE SUP. USER GUIDE FOR DETAILS)
* R5 HAS ABSOLUTE CCB ADDRESS
USING SB$SIB,R11
USING IC$CCB,R5
USING IP$PUB,R8
168C: OI SB$ERFLG,BB$IO+BB$CCB? SET PIOCS IN CNTRL & CCB QUESTIONALBE
1690: LA 5,X'000'(R1,R12) ADD REL REG TO CCB ADDRESS
1694: MVI IC$EC,0 CLEAR I/O ERROR COUNT.
1698: LA 0,X'0011'
169C: NI IC$T,128 CLEAR TRANSMISSION BYTE
16A0: BZ X'1706' ZERO?
16A4: L 8,X'010'(,R5) GET PTR TO PIOCB OR PUB
16A8: LH 8,X'000'(R12,R8) ADD REL REG TO PIOCB ADDR
16AC: TM SB$CHR,BB$DIAG "ONLINE DIAGNOSTICS" SET?
16B0: BNO X'16BC' NO
16B4: TM IC$T+1,16BC$DIAG DIAGNOSTIC CCB?
16B8: BO X'170C' YES
16BC: LM R6,R7,X'048'(,R11) GET # PUBS & ADDR 1ST PUB
* FIND REQUESTED PUB IN PUB LIST
16C0: CR R8,R7 REQUESTED PUB = CRNT PUB?
16C2: BE X'16D6' YES
16C6: LA 7,X'0020'(R7) BUMP TO NEXT PUB
16CA: BCT 6,X'16C0' LOOP
16CE: LA 0,X'0012'
16D2: BC 15,X'08A'(,R3)
* COME HERE IF PUB FOUND
16D6: LR R6,R8 PUB PTR TO R6
16D8: NI CB$ERFLG,191 CLEAR THE ERROR FLAG
16DC: TM IP$CONT2,BP$NOAVL+BP$UPDWN DVC NOT AVAIL / DOWN?
16E0: LA 0,X'0013'
16E4: BNZ X'1706' YES
* IT LOOKS AS THOUGH THE FIRST BYTE OF THE TCB CONTAINS THE JOB # IN THE UPPER
* 4 BITS. THIS BIT OF CRUFT IS USING THAT TO CHECK THE JOB # BIT IN THE PUB.
16E8: LA 7,X'0001'
16EC: PACK X'16F5'(1),JT$LNK(1) SET JOB # IN FOLLOWING INST.
16F2: SLL R7,X'0000' SHIFT R7 LEFT JOB # BITS
16F6: STC 7,X'07F'(,R3) PUT APPROPRIATE JOB # FLAG INTO FOLLOWING INST.
16FA: TM IP$ALC,0 PUB ALLOCATED TO THIS JOB?
*
16FE: LA 0,X'0014'
1702: BO X'170C' YES
1706: LH 2,X'090'(,R11)
170A: BCR R15,R2
170C: ST 14,IC$BCW SAVE TCB ADDR IN CCB
*
1710: CLI X'0053',20 SVC CODE >= 20
1714: BNL X'1724' YES
1718: AR R2,R2 SVC CODE * 2
171A: AH 2,SB$SVCTB ADD TO SVC JUMP TABLE ADDR?
171E: LH 2,X'0000'(R2) GET ADDR OF SVC HANDLER
1722: BCR R15,R2 GO TO IT
1724: LH 3,X'172A'
1728: BCR R15,R3
*
172A: DC X'05E0'
*
172C: LM R0,R1,X'028'(,R14) GET USER'S R0/R1
1730: LH 12,SB$RELOC LOAD R7 WITH RELOCATION REG.
1734: BALR R13,R12
1736: LR R12,R7
1738: L 13,JT$PRE GET TCB PREAMBLE ADDR.
173C: LA 13,X'000'(,R13)
1740: LM R5,R11,SB$REGAD RESTORE SUPER REGS.
1744: BCR R15,R3 RETURN
*
1746: DC X'042E' ADDRESS OF SAVE USER REGS. RTN.
* SUPERVISOR ENTRY POINT AFTER IPL. (IDLE LOOP???)
USING *,R15
USING JT$TCB,R14
USING SB$SIB,0
1748: LA 14,X'068'(,R15) -> 17B0
174C: NI SB$ERFLG,BB$TIO
1750: SSM SB$ALLOW,0 ENABLE ALL INTERRUPTS
1754: SSM SB$INHIB',0 DISABLE ALL INTERRUPTS
1758: LA 2,X'0408'
175C: SR R3,R3
175E: DIAG X'000'(R2),15
1762: BC 4,X'016'(,R15) COND CODE 1, LOOP TO DIAG
1766: BC 2,X'082'(,R15) COND COD 2, GO WAIT FOR INTERRUPT
176A: TM SB$FLG,BB$SVC
176E: BO X'1786' X'03E'(,R15)
1772: L 14,SB$TCB GET PTR TO LAST ACTIVE TCB?
1776: CR R3,R14 SAME AS SELECTED TCB?
1778: BE X'1796' X'04E'(,R15) YES
177C: LTR R14,R14 NO LAST ACTIVE TCB?
177E: BZ X'1786' X'03E'(,R15) YES, -> 1786
1782: BAL 5,X'042E' SAVE PROGRAM REGISTERS TO TCB
1786: NI SB$FLG,X'7F'
178A: ST 3,SB$TCB SAVE PTR TO LAST ACTIVE TCB
178E: L 13,JT$PRE POINT TO TASKS PREAMBLE
1792: BAL 5,X'0452' LOAD PROGRAM REGISTERS FROM TCB
1796: ST 3,X'0000'(R2) MAKE CRNT TBC 1ST FOR ITS PRIORITY
179A: LA 14,X'0000'(R3) SET R14 TO CURRENT TCB
179E: TM JT$FLGS,BT$ACTIC+BT$SETSV
17A2: BZ X'17AA'
17A6: BAL R5,X'17D8'
17AA: TM JT$FLGS+1,BT$HPR+BT$LPSW1
17AE: BNZ X'17B6' 7,X'06E'(,R15)
17B2: LPSW X'020'(R14),0 GOTO PSW @ R14 + 20
17B6: TM JT$FLGS+1,BT$HPR
17BA: BNO X'17C2' X'07A'(,R15)
17BE: HPR X'007C',124
17C2: NI JT$FLGS+1,X'5F'
17C6: LPSW X'020'(R14),1 GOTO PSW @ R14 + 20, IMMED 1 = ?
*
17CA: SSM SB$ALLOW',0 ENABLE INTERRUPTS
17CE: BC 15,X'086'(,R15) WAIT FOR INTERRUPT
*
17D2: DC XL6'000000000000'
*
17D8: TM JT$FLGS(R14),BT$OPACT OPR WORKING ON THIS TCB?
17DC: BNO X'1804' NO
17E0: TM JT$FLGS+1(R14),BT$MCBSY MEMCON DID SETSVC ON TCB?
17E4: BNO X'17FC' NO
17E8: TM JT$PSW+5(R14),128
17EC: BNO X'17FC'
17F0: TM JT$WAIT+2(R14),BT$ICOR ISLAND CODE OVERRIDE?
17F4: BNOR R5 NO, RETURN
17F6: NI JT$WAIT+2(R14),127 CLEAR BT$ICOR
17FA: BCR R15,R15 RETURN
17FC: LA 2,X'0A54'
1800: BC 15,X'0C4'(,R15) -> 180C
1804: NI X'00E'(R14),127
1808: LA 2,X'0A0F'
180C: STH 2,X'084'(,R14)
1810: LM R2,R3,X'020'(,R14)
1814: TM X'00E'(R14),1
1818: BC 1,X'0DC'(,R15) -> 1824
181C: STM R2,R3,X'08C'(,R14)
1820: OI X'00E'(R14),1
1824: N 2,X'0318'
1828: LA 3,X'084'(,R14)
182C: STM R2,R3,X'020'(,R14)
1830: BCR R15,R5
1832: DC XL6'000000000000'
* PROGRAM EXCEPTION INTERRUPT HANDLER
1838: BALR R2,R0
USING *,R2
183A: LA 0,X'002E'
183E: LH 12,X'1908'
1842: TM SB$ERFLG,BB$IO+BB$TIO I/O OR TRANSIENT IN CONTROL?
1846: BNZR R12 YES
1848: TM X'0041',4 PROGRAM REGISTERS IN USE?
184C: BNZ X'185C' YES
1850: TM X'02B6',16
1854: BC 1,X'02C'(,R2)
1858: BC 15,X'066'(,R2)
185C: MVC JT$PSW+3(5,R14),X'0043' COPY SALIENT BITS OF PSW TO TCB
1862: IC 0,X'0043' GET THE INTERRUPT CODE
*
1866: BALR R2,R0
1868: STM R6,R12,X'190C' SAVE REGISTERS
186C: LH 4,X'1904'
1870: BAL 3,X'004'(,R4)
1874: LTR R13,R13 R13 = 0?
1876: BC 7,X'18A4' NO
187A: TM X'02FE',32
187E: BC 1,X'038'(,R2)
1882: CLI X'008'(R14),12
1886: BC 7,X'038'(,R2)
188A: MVC X'026'(2,R14),X'09E'(R2)
1890: BAL 5,X'042E'
1894: OI X'02B8',128
1898: STM R0,R1,X'028'(,R14)
189C: BC 15,X'096'(,R2)
18A0: HPR X'0800',8
18A4: CH 0,X'1988' INTERRUPT CODE > 15?
18A8: BC 2,X'18EA' YES
18AC: L 1,JT$ECB(,R14) GET TRANSIENT ID / ECB ADDR
18B0: LA 4,JT$PCIC(,R14) GET ISLAND CODE PARAMS
18B4: LTR R0,R0 INTERRUPT CODE = 0?
18B6: BC 7,X'18BE' NO
18BA: LA 4,X'07C'(,R14)
18BE: LA 6,X'0020'
18C2: L 3,X'0000'(R4) GET ISLAND CODE ADDR
18C6: AR R3,R12 ADD RELOC. REG.
18C8: BNM X'18E8' RESULT POSITIVE
18CC: LA 6,X'0028'
18D0: TM X'000'(R4),96
18D4: BC 7,X'080'(,R2)
18D8: OI X'000'(R4),32
18DC: STM R0,R1,X'008'(,R3)
18E0: OI X'00E'(R14),128
18E4: BC 15,X'092'(,R2)
18E8: LR R0,R6 R6 = R0
18EA: STH 0,JT$ERCOD(,R14) SAVE R6 (ERROR CODE) TO TCB
18EE: ST 1,JT$ERADD(,R14) SAVE TRANS ID / ECB ADDR
18F2: OI JT$FLGS(R14),BT$SETSV SET TERMINATION SVC BIT.
18F6: OI JT$SVFLG(R14),BT$SVCAN SET SVC CANCEL BIT.
18FA: OI JT$WAIT+2(R14),BT$ICOR SET ISLAND CODE OVERRIDE BIT.
18FE: LM R6,R12,X'190C' RESTORE REGISTERS
1902: BCR R15,R15 RETURN TO SWITCHER
*
1904: XR R2,R12
1906: SSK R3,R4
1908: BAS 8,X'0000'(R4)
190C: DC XL16'00000000000000000000000000000000'
191C: DC XL12'000000000000000000000000'
1928: BALR R15,R0
192A: ST 3,X'05A'(,R15)
192E: CLI X'0033',224
1932: BC 8,X'022'(,R15)
1936: CLI X'0033',239
193A: BC 8,X'032'(,R15)
193E: MVC X'01D'(1,R15),X'0033'
1944: HPR X'0600',6
1948: BC 15,X'01A'(,R15)
194C: L 3,X'02D0'
1950: OI X'02F5',128
1954: NI X'005'(R14),247
1958: BC 15,X'04E'(,R15)
195C: TM X'0034',64
1960: BC 1,X'014'(,R15)
1964: L 3,X'0034'
1968: SH 3,X'060'(,R15)
196C: CLI X'000'(R3),156
1970: BC 7,X'014'(,R15)
1974: OI X'0034',48
1978: L 3,X'05A'(,R15)
197C: LH 15,X'0008'
1980: LPSW X'0030',0
1984: DC XL12'00000000000F000400000000'
* SVC #4 = Yield
USING JT$TCB,R14
1990: OI JT$WAIT+1,BT$YIELD
1994: BCR R15,R15
* SVC #1 - WAIT
1996: LA 0,X'0027'
199A: AR R1,R12
199C: OI SB$ERFLG,BB$IO+BB$CCB? PIOCS IN CONTROL, CCB QUESTIONABLE
19A0: TM IC$T(R1),BC$TRAFF CCB PROCESSED?
19A4: BOR R15 YES
19A6: TM IC$CTL(R1),BC$LKSCT LINK IS TO SCT?
19AA: BO X'19CA' YES
19AE: L 3,IC$BCW(,R1) GET PTR TO TCB
19B2: LA 3,X'0000'(R3)
19B6: CR R14,R3 = TO CURRENT TCB?
19B8: BNE X'19DE' NO
19BC: OI IC$CTL(R1),BC$WAIT SET WAIT FLAG IN CCB
19C0: XI X'004'(R1),4
19C4: OI JT$WAIT+1(R14),BT$WAIT SET WAIT FLAG IN TCB
19C8: BCR R15,R15 RETURN SWITCHER
*
19CA: TM X'000'(R1),4
19CE: BC 1,X'04A'(,R2)
19D2: LR R3,R14
19D4: SR R3,R13
19D6: ST 3,X'004'(,R1)
19DA: BC 15,X'026'(,R2)
19DE: BCTR R0,R0
19E0: LH 2,X'0310'
19E4: BCR R15,R2
19E6: CLC X'00C'(2,R14),X'0290'
19EC: BCR R8,R15
19EE: OI X'005'(R14),2
19F2: BCR R15,R15
19F4: DC XL4'00000000'
* SVC 8 - LOCK SYSTEM TABLE
*
* R1 BITS:
* X'08000000' - USE JT$LOCK IF SET, OTHERWISE JT$USER
* X'80000000' - USE SB$USER IF SET, OTHERWISE SB$LOCK
19F8: L 3,JT$PRE(,R14) GET TCB PREAMBLE ADDR
19FC: LTR R3,R3 IS IT ZERO?
19FE: BZ X'1A20' YES
1A02: TM JP$IDLTR(R3),4 CHECK SVC OF IDLE TRANSIENT??
1A06: BO X'1A20'
1A0A: TM JP$IDLTR(R3),16
1A0E: BNO X'1A20'
1A12: L 3,X'024'(,R14)
1A16: SH 3,X'17C'(,R2)
1A1A: ST 3,X'024'(,R14)
1A1E: BCR R15,R15
*
1A20: TM JT$SA+4(R14),1 CHECK USER R1
1A24: BNO X'1A34'
1A28: LH 12,X'10A'(,R11)
1A2C: LTR R12,R12
1A2E: BCR R8,R15
1A30: BALR R13,R12
1A32: BCR R15,R15
1A34: TM CB$CHR+1(R11),BB$ULCK USER FILES LOCKED?
1A38: BO X'1A40' YES
1A3C: N 0,X'1E4'(,R2)
1A40: LR R3,R1 R3 = USER'S R1
1A42: SLL R3,X'0004' LEFT 4
1A46: SRL R3,X'001D' RIGHT 29
1A4A: LR R4,R1 R4 = USER'S R1
1A4C: SRL R4,X'001D' RIGHT 29
1A50: LA 1,X'000'(,R1) CLEAR R1 UPPER
1A54: LTR R1,R1 R1 = 0?
1A56: BNZ X'1A60' NO
1A5A: LR R1,R14 R1 = PTR TO CURRENT TCB
1A5C: BC 15,X'1A62'
1A60: AR R1,R12
1A62: LR R8,R0 R8 = USER'S R0
1A64: L 7,X'06C'(R4,R1) GET USER OR LOCK FLAGS??
1A68: NR R7,R8 GET MATCHING BITS BETWEEN FLAGS & USER R0
1A6A: EX 0,X'144'(R3,R2) EITHER GOTO X'1A76' OR RETURN
1A6E: EX 0,X'164'(R3,R2)
1A72: EX 0,X'14A'(R3,R2)
1A76: EX 0,X'152'(R4,R2) LOAD EITHER SB$LOCK OR SB$USER TO R7
1A7A: NR R7,R8 GET BITS IN COMMON BETWEEN R7 & R8
1A7C: BNZ X'1B78'
1A80: L 10,JT$USER(,R1) GET USER FLAGS
1A84: LTR R9,R4 GET USER / LOCK INDICATOR
1A86: BC 7,X'1A8E' INDICATOR <> 0
1A8A: EX 0,X'15A'(R3,R2)
1A8E: L 7,X'0A0'(R9,R11)
1A92: EX 0,X'162'(R3,R2)
1A96: ST 7,SB$USER(R9,R11) SET THE APPROPRIATE FLAG IN SIB
1A9A: L 7,X'06C'(R9,R1) SET APPROPRIATE FLAG IN TCB
1A9E: EX 0,X'162'(R3,R2)
1AA2: ST 7,X'06C'(R9,R1)
1AA6: LTR R9,R9 CHECK USER / LOCK INDICATOR
1AA8: BZ X'1AB2' ZERO
1AAC: SR R9,R9 CLEAR R9
1AAE: EX 0,X'15A'(R3,R2)
1AB2: NR R10,R0 CLEAR FLAG IN R10
1AB4: LTR R9,R0
1AB6: EX 0,X'17A'(R3,R2)
1ABA: BCR R8,R15 RETURN TO SWITCHER IF RESULT ZERO
1ABC: LA 8,X'1B6'(,R2)
1AC0: BALR R8,R8
1AC2: LR R10,R5
1AC4: AH 10,SB$LKTAB(,R11) ADDR. OF LOCK COUNTER TABLE
1AC8: EX 0,X'16A'(R3,R2) ADD 1 OR -1 TO LOCK ENTRY
1ACC: EX 0,X'172'(R3,R2) B OR BNE
1AD0: L 13,X'0A0'(,R11)
1AD4: XR R13,R12
1AD6: ST 13,X'0A0'(,R11)
1ADA: AI X'000'(R10),0
1ADE: BC 8,X'0C8'(,R2)
1AE2: ST 1,X'1EC'(,R2)
1AE6: LR R13,R12
1AE8: LR R0,R5
1AEA: SRL R0,X'0005'
1AEE: LR R1,R0
1AF0: SLL R0,X'0003'
1AF4: LA 6,X'0018'
1AF8: SR R6,R0
1AFA: SRL R13,X'000'(,R6)
1AFE: STC 13,X'11B'(,R2)
1B02: LA 0,X'0068'(R1)
1B06: SLL R0,X'0010'
1B0A: AH 0,X'088'(,R11)
1B0E: SR R1,R1
1B10: DIAG X'010F',15
1B14: BC 4,X'118'(,R2)
1B18: BC 2,X'136'(,R2)
1B1C: NI X'004'(R1),254
1B20: XC X'068'(4,R1),X'068'(R1)
1B26: AI X'000'(R10),255
1B2A: BC 7,X'118'(,R2)
1B2E: XC X'000'(2,R10),X'000'(R10)
1B34: L 1,X'1EC'(,R2)
1B38: BC 15,X'0C8'(,R2)
* EXECUTED @ 1A6A
1B3C: BZ X'1A76'
1B40: BZR R15
* EXECUTED @ 1A72
1B42: BCR R8,R15
1B44: BCR R0,R9
1B46: BC 15,X'088'(,R2)
* EXECUTED @ 1A76
1B4A: L 7,SB$LOCK(,R11)
1B4E: L 7,SB$USER(,R11)
* EXECUTED @ 1A8A & 1AAE
1B52: BC 15,X'096'(,R2)
1B56: BC 15,X'0A2'(,R2)
* EXECUTED AT 1A92 & 1A9E
1B5A: OR R7,R0
* EXECUTED @ 1A6E
1B5C: XR R0,R7
1B5E: XR R7,R0
1B60: LR R0,R7
*
1B62: AI X'002'(R10),1
1B66: AI X'002'(R10),255
1B6A: BC 15,X'0C8'(,R2)
1B6E: BC 7,X'0C8'(,R2)
* EXECUTED @ 1AB6
1B72: XR R9,R10
1B74: DC XL2'0002'
1B76: BCR R0,R9
1B78: CR R1,R14 R1 = R14?
1B7A: BE X'1B82' YES
1B7E: ST 7,X'028'(,R14)
1B82: OI JT$WAIT(R1),BT$LOCK SET WAIT FOR LOCKED FILE OR TABLE
1B86: L 3,JT$PSW+4(,R1) GET NEXT INST ADDR FROM TCB
1B8A: SH 3,X'1B74' SUBTRACT 2
1B8E: ST 3,JT$PSW+4(,R1) PUT BACK INTO PSW
1B92: LR R0,R7 R0 = R7
1B94: LR R9,R7 R9 = R7
1B96: L 12,X'1BE0'
1B9A: LH 5,SB$LKTAB(,R11) GET ADDR OF LOCK TABLE
1B9E: BAL 7,X'1BC4'
1BA2: AI X'000'(R5),1 BUMP LOCK TABLE ENTRY
1BA6: NR R0,R12 GET BITS IN COMMON BETWEEN R0 & R12
1BA8: ST 0,JT$WTLCK(,R1) SET REASON FOR WAIT LOCK
1BAC: BCR R15,R15 RETURN TO SWITCHER
1BAE: SR R5,R5 CLEAR R5
1BB0: L 12,X'1BE0'
1BB4: LA 7,X'1BC4'
1BB8: BALR R7,R7
1BBA: BALR R8,R8 RETURN
1BBC: LTR R9,R9 R9 = 0?
1BBE: BNZ X'1C0'(,R2) NO
1BC2: BCR R15,R15 YES, RERTURN TO SWITCHER
1BC4: LTR R9,R9
1BC6: SLL R9,X'0001' LEFT 1
1BCA: BC 11,X'1BD0' R9 >= 0
1BCE: BALR R7,R7 RETURN
1BD0: SRL R12,X'0001' RIGHT 1
1BD4: LA 5,X'004'(,R5) BUMP LOCK TABLE PTR
1BD8: BC 15,X'1BC4'
1BDC: DC XL4'FFFF0000'
1BE0: SSM X'0000',0
1BE4: DC XL4'00000000'\
* TIMER INTERRUPT HANDLER
1BE8: BALR R12,R0
USING *,R12
1BEA: MVC X'024'(4,R14),X'0064' SAVE OLD PSW ADDRESS
1BF0: BAL 3,X'1D32'
1BF4: C 6,X'1D54' NEW TIME < MIDNIGHT
1BF8: BL X'1C08' YES
1BFC: OI SB$SOI2,BB$SOMID SET MIDNIGHT PROCESSING FLAG
1C00: L 7,SB$SOS ADDR OF SOS PUB
1C04: NI JT$WAIT+1(R7),247
1C08: LH 7,SB$MXINT GET MAX MS BETWEEN INTERRUPTS.
1C0C: LR R10,R15 SAVE R15
1C0E: LH 2,SB$SPE GET ADDR OF SOFTWARE PGM EXCP.
1C12: LA 15,X'1C1C'
1C16: L 8,X'1D48'
* SOMEHOW THIS DIAG KNOWS TO RETURN ONLY THOSE TCBS WITH BT$SETTIM SET IN JT$TIM
1C1A: SR R9,R9
1C1C: DIAG X'180'(R8),15
1C20: BC 4,X'1C1C'
1C24: BC 2,X'1C76'
1C28: L R1,JT$TIM(,R9) GET TIMER EXPIRATION
1C2C: N R1,X'1D50' CLEAR BT$SETTIM
1C30: LR R5,R1 -> R5
1C32: SR R5,R6 SUBTRACT CURRENT TIME
1C34: BNP X'1C5C' RESULT <= 0
1C38: C 5,X'1D54' RESULT <= MIDNIGHT?
1C3C: BNH X'1C48' YES
1C40: S 5,X'1D54' MIDNIGHT ADJUST
1C44: BC 15,X'1C38' TRY AGAIN
1C48: C 5,X'1D4C'
1C4C: BH X'1C5C'
1C50: CR R5,R7 RESULT >= MS BETWEEN INTERRUPTS?
1C52: BNL X'1C1C' YES
1C56: LR R7,R5 SET NEW LOWER MS BETWEEN INTERRUPTS
1C58: BC 15,X'1C1C' LOOP
*
1C5C: NI JT$TIM(R9),127 CLEAR BT$SETTIM
1C60: LR R14,R9 MAKE CURRENT TCB
1C62: SR R0,R0 CLEAR R0
1C64: L 1,JT$TID(,R9) GET SETTIME EXPIRATION
1C68: TM JT$WAIT+1(R9),BT$WTTIM SETTIME WAIT SET?
1C6C: BNOR R2 NO
1C6E: NI JT$WAIT+1(R9),239 CLEAR BT$WTTIM
1C72: BC 15,X'1C1C' LOOP
*
1C76: LH 4,SB$OTV GET TIMER VALUE
1C7A: LR R15,R10 RESTORE R15
1C7C: ST 6,SB$CLK UPDATE TIME OF DAY
1C80: STH 7,SB$OTV SET NEW TIMER VALUE
1C84: STR R5,R1 NO CLUE
1C86: STR R7,R4 SET NEW TIMER INTERVAL
1C88: AH 4,X'0B8'(,R12)
1C8C: CH 4,X'0332'
1C90: STH 4,X'0B8'(,R12)
1C94: BCR R4,R15
1C96: SR R4,R4
1C98: STH 4,X'0B8'(,R12)
1C9C: L 11,X'0374'
1CA0: BCR R15,R11
1CA2: DC XL2'0000'
1CA4: STC 0,X'0A0'(,R2)
1CA8: TM X'0A0'(R2),2
1CAC: BC 14,X'010'(,R2)
1CB0: M 0,X'0B4'(,R2)
1CB4: BAL 3,X'08E'(,R2)
1CB8: LR R5,R6
1CBA: AR R5,R1
1CBC: ST 5,X'01C'(,R14)
1CC0: LTR R1,R1
1CC2: BCR R8,R15
1CC4: OI X'01C'(R14),128
1CC8: TM X'0A0'(R2),1
1CCC: BC 14,X'030'(,R2)
1CD0: OI X'005'(R14),16
1CD4: STR R5,R0
1CD6: BCR R4,R15
1CD8: CR R1,R5
1CDA: BCR R11,R15
1CDC: STR R5,R1
1CDE: ST 6,X'0A8'(,R11)
1CE2: STH 1,X'0AC'(,R11)
1CE6: STR R1,R4
1CE8: BCR R15,R15
1CEA: BAL 3,X'048'(,R2)
1CEE: ST 6,X'02C'(,R14)
1CF2: LTR R1,R1
1CF4: BC 7,X'040'(,R2)
1CF8: SR R8,R8
1CFA: LR R9,R6
1CFC: D 8,X'07E'(,R2)
1D00: LR R5,R9
1D02: SR R4,R4
1D04: M 4,X'076'(,R2)
1D08: LR R1,R5
1D0A: LR R9,R8
1D0C: SR R8,R8
1D0E: D 8,X'07A'(,R2)
1D12: LR R5,R9
1D14: SR R4,R4
1D16: M 4,X'072'(,R2)
1D1A: AR R1,R5
1D1C: LR R9,R8
1D1E: SR R8,R8
1D20: D 8,X'06E'(,R2)
1D24: AR R1,R9
1D26: CVD 1,X'028'(,R14)
1D2A: MVC X'028'(4,R14),X'064'(R13)
1D30: BCR R15,R15
*
1D32: STR R5,R0 GET CURRENT VALUE OF TIMER REG.
1D34: LH 6,SB$OTV GET TIMER INTERVAL
1D38: SR R6,R5 ADJUST BY CURRENT TIMER VALUE
1D3A: LA 6,X'0000'(R6) CLEAR MSB
1D3E: A 6,SB$CLK ADD TO DAY CLOCK
1D42: BCR R15,R3 RETURN
*
1D44: DC XL16'00000000001C040C04F057E07FFFFFFF'
1D54: DC XL16'05265C00000003E80000006400002710'
1D64: DC XL16'0000EA600036EE80000000009608E004'
1D74: DC XL16'968010069602B07494F7900507FF0000'
1D84: DC XL16'000000001A471A4A1BAA43A0800389A0'
1D94: DC XL2'0004'
*
1D96: STM R2,R5,X'100'(,R10)
1D9A: AI X'002'(R8),0
1D9E: BCR R8,R13
1DA0: TM X'103'(R10),1
1DA4: LA 0,X'0016'
1DA8: BC 1,X'2CA'(,R11)
1DAC: TM X'107'(R10),1
1DB0: LA 0,X'0017'
1DB4: BC 1,X'2CA'(,R11)
1DB8: CLI X'003'(R8),3
1DBC: BCR R4,R13
1DBE: TM X'003'(R1),8
1DC2: BC 8,X'052'(,R12)
1DC6: TM X'100'(R10),2
1DCA: BC 8,X'052'(,R12)
1DCE: MVC X'109'(3,R10),X'101'(R10)
1DD4: MVC X'104'(2,R10),X'106'(R10)
1DDA: TM X'10B'(R10),1
1DDE: LA 0,X'0016'
1DE2: BC 1,X'2CA'(,R11)
1DE6: TM X'107'(R10),1
1DEA: LA 0,X'0017'
1DEE: BC 1,X'2CA'(,R11)
1DF2: BCR R15,R13
1DF4: DC XL4'00000000'
* CHANNEL 0 INTERRUPT HANDLER
1DF8: SR R9,R9 CLEAR R9
1DFA: IC R9,IP$DA(,R8) GET PUB DVC ADDR.
1DFE: SLL R9,X'0004' CALC. BCW ADDRESS OF THIS DVC
1E02: LA R9,X'100'(,R9)
1E06: LR R13,R0
1E08: MVC X'00A'(2,R13),X'006'(R9) SAVE BCW FLAGS AND COUNT
1E0E: NI X'00A'(R13),31
1E12: TM IP$CONT5(R8),255 COMPOSITE CHAIN ERROR?
1E16: BNZ X'1E52' YES
1E1A: TM IP$CONT1(R8),DP$DVERR UNIT CHECK?
1E1E: BO X'1E7E' YES
1E22: TM X'003'(R1),16
1E26: BZ X'1E46'(,R12)
1E2A: TM X'003'(R1),128
1E2E: BC 8,X'04E'(,R12)
1E32: TM X'01C'(R8),2
1E36: BC 1,X'04E'(,R12)
1E3A: TM X'01C'(R1),3
1E3E: BC 8,X'04E'(,R12)
1E42: BC 15,X'086'(,R12)
1E46: TM X1P$CONT2(R8),BP$IO2 IO 2 CONTROL?
1E4A: BZ X'4CA8' NO
1E4E: NI X'01C'(R8),253
1E52: SR R9,R9
1E54: TM X'003'(R1),16
1E58: BC 8,X'074'(,R12)
1E5C: TM X'01C'(R8),2
1E60: BC 8,X'074'(,R12)
1E64: OI X'01C'(R8),2
1E68: BC 15,X'086'(,R12)
1E6C: IC 9,X'003'(,R8)
1E70: SLL R9,X'0001'
1E74: LH 9,X'0DC'(R9,R12)
1E78: LH 13,X'100'(,R12)
1E7C: BCR R15,R13
1E7E: OI X'01C'(R8),2
1E82: LM R2,R3,X'0E4'(,R12)
1E86: AR R2,R1
1E88: SR R2,R7
1E8A: TM X'003'(R1),16
1E8E: BC 8,X'0AE'(,R12)
1E92: TM X'01C'(R1),3
1E96: BC 14,X'0AE'(,R12)
1E9A: L 2,X'014'(,R1)
1E9E: L 2,X'000'(,R2)
1EA2: LA 3,X'0006'
1EA6: TM X'003'(R1),16
1EAA: BC 14,X'0C6'(,R12)
1EAE: LA 0,X'0014'
1EB2: MVI X'004'(R1),0
* DIAG14
1EB6: DIAG X'0000',14
1EBA: STC 0,X'004'(,R1)
1EBE: LH 11,X'0F0'(,R12)
1EC2: BC 15,X'1AC'(,R11)
1EC6: L 5,X'00C'(,R1)
1ECA: AR R5,R7
1ECC: LM R2,R5,X'000'(,R5)
1ED0: BC 15,X'0AE'(,R12)
1ED4: ALR R14,R4
1ED6: ALR R14,R4
1ED8: ALR R14,R4
1EDA: ALR R14,R12
1EDC: SPM R0,R0
1EDE: DC XL10'001400000006FFFFFF4D'
1EE8: BCT 3,X'0040'(R2)
1EEC: SSK R0,R8
1EEE: DC XL2'004D'
1EF0: ALR R12,R6
1EF2: BALR R4,R0
1EF4: DC XL4'FFFFFF4D'
1EF8: STC 0,X'0040'
1EFC: DC XL4'00000000'
* LOAD RELOCATION REGISTER FOR ACTIVE TCB
1F00: SR R10,R10 GET THE KEY
1F02: IC 10,X'021'(,R14)
1F06: TM X'00E'(R14),1 IS IT ODD?
1F0A: BC 8,X'012'(,R12) NO
1F0E: IC 10,X'08D'(,R14)
1F12: SRL R10,X'0004' ISOLATE THE KEY
1F16: SLL R10,X'0002' MAKE INTO OFFSET
1F1A: L 7,X'00B0'(R10) GET RELOATION REGISTER
1F1E: BCR R15,R13
*
1F20: LH 12,X'0392'
1F24: BALR R13,R12
1F26: TM X'006'(R11),128
1F2A: BCR R2,R15
1F2C: CLI X'01B'(R8),0
1F30: BC 8,X'01E'(,R12)
1F34: AI X'002'(R8),0
1F38: BC 8,X'01E'(,R12)
1F3C: AI X'01A'(R8),255
1F40: CLI X'01B'(R8),0
1F44: BC 7,X'01E'(,R12)
1F48: LH 6,X'010'(,R8)
1F4C: NI X'000'(R6),127
1F50: L 1,X'008'(,R8)
1F54: LTR R1,R1
1F56: BC 7,X'060'(,R11)
1F5A: CLI X'002'(R8),1
1F5E: BC 7,X'058'(,R11)
1F62: LH 6,X'016'(,R8)
1F66: LH 6,X'002'(,R6)
1F6A: MVZ X'053'(1,R11),X'003'(R8)
1F70: LA 6,X'000'(,R6)
1F74: MVI X'000'(R6),255
1F78: LH 11,X'038C'
1F7C: BC 15,X'1A2'(,R11)
1F80: TM X'00C'(R8),14
1F84: BC 8,X'098'(,R11)
1F88: TM X'00D'(R8),8
1F8C: BC 8,X'098'(,R11)
1F90: LH 5,X'000'(,R8)
1F94: L 9,X'008'(,R5)
1F98: LA 1,X'000'(,R1)
1F9C: LA 9,X'000'(,R9)
1FA0: CR R9,R1
1FA2: BC 8,X'092'(,R11)
1FA6: LTR R9,R9
1FA8: BC 8,X'092'(,R11)
1FAC: MVI X'01B'(R8),1
1FB0: BCR R15,R15
1FB2: LR R8,R5
1FB4: ST 1,X'008'(,R8)
1FB8: LH 6,X'010'(,R8)
1FBC: NI X'000'(R6),127
1FC0: OI X'007'(R8),255
1FC4: MVI X'01B'(R1),255
1FC8: TM X'003'(R1),16
1FCC: BC 8,X'0B4'(,R11)
1FD0: MVI X'027'(R1),141
1FD4: TM X'00C'(R8),16
1FD8: BC 8,X'0D2'(,R11)
1FDC: TM X'01D'(R8),64
1FE0: BC 8,X'0D2'(,R11)
1FE4: NI X'01D'(R8),191
1FE8: XC X'008'(4,R8),X'008'(R8)
1FEE: BC 15,X'058'(,R11)
1FF2: L 14,X'004'(,R1)
1FF6: LA 14,X'000'(,R14)
1FFA: LH 12,SB$RELOC
1FFE: BALR R13,R12 LOAD R7 WITH RELOCATION REG.
2000: LH 12,X'104'(,R11)
2004: LR R0,R12
2006: SR R4,R4
2008: LR R3,R7
200A: STM R3,R4,X'004'(,R12)
200E: NI X'01C'(R8),248
2012: LA 1,X'000'(,R1)
2016: LA 6,X'0040'
201A: LH 11,X'038E'
201E: LH 12,X'016'(,R8)
2022: BCR R15,R12
2024: LA 14,X'0000'(R8)
* CHANNEL 1 CHANNEL SCHEDULER?
*
* THIS SEEMS TO BE BUILDING A SENSE COMMAND FOR THE PUB IN GIVEN IN R8
USING *,R12
USING IP$PUB,R8
USING IC$CCB,R1
2028: TM IC$T+1(R1),BC$SYS SYSTEM CCB?
202C: BO X'205A' YES
2030: TM IP$TYP(R8),14 CHECK DEVICE TYPE
2034: BO X'204E'
2038: TM IP$SUB(R8),8 CHECK DEVICE SUB TYPE
203C: BO X'204E'
2040: ST 1,X'008'(,R8)
2044: LR R6,R8
2046: LH 8,X'000'(,R8)
204A: STH 6,X'00E'(,R8)
204E: MVZ X'02F'(1,R12),X'003'(R8) MDFY FOLLOWING WITH SUB CHANNEL
2054: STM R2,R5,X'0200'
2058: BCR R15,R13
*
205A: TM X'01C'(R8),7
205E: BC 8,X'042'(,R12)
2062: TM X'01C'(R8),5
2066: BC 8,X'026'(,R12)
206A: LA 6,X'428'(,R12)
206E: MVZ X'04F'(1,R12),X'003'(R8)
2074: LA 6,X'000'(,R6)
2078: TM X'00C'(R8),14
207C: BC 8,X'082'(,R12)
2080: TM X'00D'(R8),8
2084: BC 8,X'082'(,R12)
2088: LH 4,X'000'(,R8)
208C: LA 10,X'004'(,R6)
2090: MVC X'075'(1,R12),X'00C'(R8)
2096: NI X'075'(R12),252
209A: LA 10,X'000'(,R10)
209E: LH 5,X'012'(,R4)
20A2: LA 5,X'018'(,R5)
20A6: STH 8,X'002'(,R10)
20AA: TM X'000'(R6),255
20AE: BCR R4,R15
20B0: BC 8,X'408'(,R12)
20B4: TM X'00C'(R8),14
20B8: BC 8,X'1E0'(,R12)
20BC: TM X'00D'(R8),8
20C0: BC 8,X'1E0'(,R12)
20C4: OC X'008'(4,R4),X'008'(R4)
20CA: BCR R7,R15
20CC: CLI X'001'(R6),255
20D0: BC 7,X'0D0'(,R12)
20D4: MVI X'000'(R10),0
20D8: MVI X'001'(R10),4
20DC: L 2,X'1DC'(,R12)
20E0: LA 3,X'0001'
20E4: AR R2,R1
20E6: ST 1,X'008'(,R8)
20EA: MVI X'01B'(R8),2
20EE: STH 8,X'00E'(,R4)
20F2: LR R8,R4
20F4: BC 15,X'40C'(,R12)
20F8: CLI X'001'(R10),2
20FC: BC 7,X'0F6'(,R12)
2100: MVI X'1D8'(R12),2
2104: LR R2,R5
2106: A 2,X'1D8'(,R12)
210A: CLI X'00E'(R6),0
210E: BC 8,X'0EE'(,R12)
2112: LA 3,X'00A0'
2116: LA 3,X'008'(,R3)
211A: BC 15,X'0BE'(,R12)
211E: TM X'019'(R1),128
2122: BC 1,X'108'(,R12)
2126: TM X'000'(R10),255
212A: BCR R1,R15
212C: BC 4,X'1AA'(,R12)
2130: MVI X'1D8'(R12),1
2134: LR R9,R2
2136: N 9,X'420'(,R12)
213A: SRL R2,X'0018'
213E: STC 2,X'001'(,R5)
2142: LR R2,R5
2144: A 2,X'1D8'(,R12)
2148: STH 3,X'002'(,R2)
214C: AI X'002'(R2),4
2150: MVC X'000'(1,R2),X'00C'(R8)
2156: OC X'000'(1,R2),X'019'(R1)
215C: TM X'000'(R2),8
2160: BC 1,X'14A'(,R12)
2164: BCTR R3,R0
2166: EX 3,X'1D0'(,R12)
216A: LA 3,X'005'(,R3)
216E: BC 15,X'0BE'(,R12)
2172: CLI X'002'(R6),255
2176: BC 7,X'196'(,R12)
217A: MVI X'002'(R6),0
217E: TM X'000'(R10),255
2182: BC 4,X'1AA'(,R12)
2186: XC X'00E'(2,R6),X'00E'(R6)
218C: LR R2,R9
218E: SH 2,X'198'(,R12)
2192: LH 6,X'1D6'(,R12)
2196: LA 9,X'008'(,R3)
219A: SH 9,X'002'(,R5)
219E: STH 9,X'00A'(,R6)
21A2: LR R0,R6
21A4: LR R9,R5
21A6: LA 9,X'008'(,R9)
21AA: BCTR R3,R0
21AC: EX 3,X'1D0'(,R12)
21B0: ST 1,X'008'(,R8)
21B4: SR R6,R6
21B6: LH 11,X'038E'
21BA: BC 15,X'36C'(,R11)
21BE: LA 3,X'0004'
21C2: TM X'001'(R2),4
21C6: BC 8,X'0BE'(,R12)
21CA: OI X'000'(R2),16
21CE: BC 15,X'0BE'(,R12)
21D2: ST 1,X'008'(,R8)
21D6: MVC X'014'(1,R1),X'000'(R10)
21DC: XC X'000'(4,R10),X'000'(R10)
21E2: LH 0,X'1D6'(,R12)
21E6: MVI X'01A'(R1),2
21EA: OI X'01C'(R8),2
21EE: LH 11,X'038E'
21F2: LH 12,X'016'(,R8)
21F6: BCR R15,R12
21F8: MVC X'004'(1,R2),X'000'(R9)
21FE: LA 14,X'0000'(R8)
2202: DC XL2'0000'
2204: SPM R0,R0
2206: DC XL2'0014'
2208: STM R2,R3,X'008'(,R6)
220C: TM X'00C'(R8),4
2210: BC 8,X'34A'(,R12)
2214: TM X'00D'(R8),40
2218: BC 8,X'32E'(,R12)
221C: LH 9,X'012'(,R8)
2220: CLI X'008'(R6),99
2224: BC 7,X'21A'(,R12)
2228: N 2,X'420'(,R12)
222C: MVC X'01C'(192,R9),X'000'(R2)
2232: XC X'018'(4,R9),X'018'(R9)
2238: SR R6,R6
223A: LH 11,X'32C'(,R12)
223E: BC 15,X'36C'(,R11)
2242: MVI X'27F'(R12),0
2246: MVI X'283'(R12),0
224A: MVI X'27B'(R12),9
224E: SR R5,R5
2250: XC X'001'(7,R6),X'001'(R6)
2256: IC 5,X'008'(,R6)
225A: STC 5,X'001'(,R6)
225E: TM X'001'(R6),6
2262: BC 4,X'408'(,R12)
2266: NI X'008'(R6),123
226A: TM X'008'(R6),120
226E: BC 8,X'408'(,R12)
2272: SRL R5,X'0003'
2276: TM X'001'(R6),128
227A: BC 1,X'2D2'(,R12)
227E: STC 5,X'005'(,R6)
2282: L 4,X'018'(,R9)
2286: LA 5,X'01C'(,R9)
228A: LA 4,X'001'(,R4)
228E: LR R3,R5
2290: AR R3,R4
2292: AI X'006'(R6),1
2296: CLI X'000'(R3),7
229A: BC 7,X'27A'(,R12)
229E: SR R3,R4
22A0: SR R4,R4
22A2: CLI X'000'(R3),9
22A6: BC 0,X'2CA'(,R12)
22AA: BC 0,X'29A'(,R12)
22AE: BC 7,X'28E'(,R12)
22B2: MVI X'002'(R6),8
22B6: AI X'004'(R6),255
22BA: BC 2,X'262'(,R12)
22BE: BC 4,X'30E'(,R12)
22C2: NI X'008'(R6),131
22C6: OI X'008'(R6),8
22CA: AI X'006'(R6),255
22CE: BC 8,X'2BE'(,R12)
22D2: TM X'007'(R6),1
22D6: BC 8,X'2BE'(,R12)
22DA: NI X'008'(R6),247
22DE: OI X'008'(R6),16
22E2: AI X'006'(R6),255
22E6: AI X'006'(R6),0
22EA: BC 8,X'2CA'(,R12)
22EE: MVI X'004'(R6),19
22F2: ST 4,X'018'(,R9)
22F6: BC 15,X'408'(,R12)
22FA: MVI X'005'(R6),192
22FE: STC 5,X'27B'(,R12)
2302: NI X'27B'(R12),15
2306: TM X'27B'(R12),14
230A: BC 7,X'2EE'(,R12)
230E: MVI X'27B'(R12),9
2312: OI X'008'(R6),64
2316: TM X'001'(R6),96
231A: BC 8,X'324'(,R12)
231E: MVI X'27F'(R12),128
2322: TM X'27B'(R12),7
2326: BC 14,X'25A'(,R12)
232A: NI X'27B'(R12),7
232E: OI X'008'(R6),64
2332: BC 15,X'25A'(,R12)
2336: OI X'01C'(R8),2
233A: LH 11,X'32C'(,R12)
233E: LH 12,X'016'(,R8)
2342: ST 1,X'008'(,R8)
2346: OI X'015'(R1),2
234A: BCR R15,R12
234C: MVI X'283'(R12),128
2350: BC 15,X'25A'(,R12)
2354: CH 3,X'820'(R12,R8)
2358: DC XL2'001B'
235A: STC 2,X'001'(,R6)
235E: CLI X'001'(R6),17
2362: BC 7,X'408'(,R12)
2366: OI X'008'(R6),224
236A: NI X'008'(R6),231
236E: BC 15,X'408'(,R12)
2372: TM X'00C'(R8),2
2376: BC 8,X'3B4'(,R12)
237A: MVC X'001'(1,R6),X'008'(R6)
2380: CLI X'008'(R6),3
2384: BC 8,X'408'(,R12)
2388: TM X'008'(R6),1
238C: BC 8,X'3A8'(,R12)
2390: OI X'008'(R6),16
2394: TM X'008'(R6),4
2398: BC 1,X'408'(,R12)
239C: TM X'017'(R1),128
23A0: BC 1,X'408'(,R12)
23A4: LH 5,X'3A6'(,R12)
23A8: BCTR R3,R0
23AA: LR R4,R2
23AC: SLL R4,X'000D'
23B0: SRL R4,X'000D'
23B4: TM X'001'(R6),16
23B8: BC 1,X'398'(,R12)
23BC: EX 3,X'3A0'(,R12)
23C0: OI X'017'(R1),128
23C4: BC 15,X'408'(,R12)
23C8: TR X'000'(1,R4),X'000'(R5)
23CE: ADR R14,R8
23D0: MVI X'008'(R6),11
23D4: OI X'01C'(R8),1
23D8: BC 15,X'408'(,R12)
23DC: TM X'00C'(R8),8
23E0: BC 8,X'3C0'(,R12)
23E4: BC 15,X'408'(,R12)
23E8: SR R2,R2
23EA: LR R4,R3
23EC: STC 3,X'007'(,R6)
23F0: SRL R3,X'0010'
23F4: TM X'008'(R6),3
23F8: BC 14,X'3D8'(,R12)
23FC: MVI X'007'(R6),1
2400: D 2,X'004'(,R6)
2404: N 4,X'41C'(,R12)
2408: N 3,X'424'(,R12)
240C: OR R4,R3
240E: ST 4,X'00C'(,R6)
2412: LH 9,X'012'(,R8)
2416: CLC X'013'(1,R9),X'001'(R6)
241C: BC 8,X'408'(,R12)
2420: MVC X'002'(1,R6),X'008'(R6)
2426: MVC X'008'(1,R6),X'013'(R9)
242C: OI X'01C'(R8),1
2430: LM R2,R3,X'008'(,R6)
2434: MVI X'000'(R6),1
2438: SR R4,R4
243A: SR R5,R5
243C: BC 15,X'026'(,R12)
2440: HDR R5,R0
2442: DC XL12'00000000E000000FFFFF0000'
244E: SLR R15,R15
2450: DC XL16'FF000000000000000000000000000000'
2460: DC XL16'FF000000000000000000000000000000'
2470: DC XL16'FF000000000000000000000000000000'
2480: DC XL16'FF000000000000000000000000000000'
2490: DC XL16'FF000000000000000000000000000000'
24A0: DC XL16'FF000000000000000000000000000000'
24B0: DC XL16'FF000000000000000000000000000000'
24C0: DC XL16'FF000000000000000000000000000000'
* INTERRUPT RTN FOR CHANNEL 1?
USING *,R12
USING IC$CCB,R1
USING IP$PUB,R8
24D0: BC 0,X'450'(,R2)
24D4: LA 1,X'000'(,R1) CLEAR R1 UPPER
24D8: MVC X'2CE8(1),IP$CONT2(R8) SAVE IP$CONT2
24DE: NI X'2CE8',7
24E2: NI IP$CONT2(R8),248 CLEAR BP$IOC
24E6: L 4,IC$BCW(,R1) GET PTR TO BCW
24EA: AR R4,R7 ADD RELOCATION REG.
24EC: CH 0,X'2A6A'
24F0: BL X'2A02'
24F4: MVZ X'24FD'(1),IP$DA(R8) MDFY FOLLOWING WITH SUB CHANNEL
24FA: LA 9,X'0200' GET SUB CHANNEL + 200 INTO R9 (BCW ADDR)
24FE: LR R13,R0
2500: CLI X'2CE8',2 SAVED IP$CONT2 = 2?
2504: BE X'2530' YES
2508: MVC X'00A'(2,R13),X'006'(R9)
250E: NI X'00A'(R13),31
2512: LA 9,X'5CC'(,R12)
2516: SR R5,R5
2518: IC 5,X'003'(,R8)
251C: SRL R5,X'0004'
2520: SLL R5,X'0001'
2524: AR R9,R5
2526: BC 0,X'522'(,R12)
252A: MVC X'000'(2,R9),X'00A'(R13)
2530: LH 9,X'2A98'
2534: MVZ X'253D'(1),IP$DA(R8) MODIFY FOLLOWING WITH SUB CHANNEL
253A: LA 9,X'000'(,R9) POINT TO SUB CHANNEL BUFFER
253E: MVI X'000'(R9),255
2542: TM IC$T+1(R1),BC$DIAG DIAGNOSTIC CCB?
2546: BO X'255A' YES
254A: TM IP$CONT5(R8),255 CHECK CHANNEL STATUS
254E: BM X'299E' THERE IS SOME
2552: TM IP$CONT1(R8),BP$DVERR UNIT CHECK?
2556: BO X'2A18' YES
255A: TM X'003'(R1),16
255E: BC 14,X'162'(,R12)
2562: TM X'006'(R8),7
2566: BC 8,X'162'(,R12)
256A: TM X'01D'(R8),128
256E: BC 1,X'0B0'(,R12)
2572: TM X'818'(R12),2
2576: BC 1,X'0B0'(,R12)
257A: MVC X'12C'(4,R12),X'00C'(R1)
2580: L 2,X'00C'(,R1)
2584: AR R2,R7
2586: TM X'004'(R2),64
258A: BC 14,X'10A'(,R12)
258E: TM X'006'(R8),3
2592: BC 7,X'10A'(,R12)
2596: OI X'01D'(R8),128
259A: LA 2,X'008'(,R2)
259E: CLI X'000'(R2),8
25A2: BC 7,X'0E2'(,R12)
25A6: L 2,X'0000'(R2)
25AA: LA 2,X'000'(,R2)
25AE: BC 15,X'0F0'(,R12)
25B2: SR R2,R7
25B4: TM X'818'(R12),2
25B8: BC 8,X'0F0'(,R12)
25BC: OI X'01C'(R8),2
25C0: ST 2,X'00C'(,R1)
25C4: AR R2,R7
25C6: LM R2,R3,X'000'(,R2)
25CA: BC 15,X'58E'(,R12)
25CE: TM X'818'(R12),2
25D2: BC 8,X'10A'(,R12)
25D6: OI X'027'(R1),142
25DA: NI X'01D'(R8),127
25DE: TM X'818'(R12),2
25E2: BC 8,X'120'(,R12)
25E6: MVC X'00C'(4,R1),X'12C'(R12)
25EC: BC 15,X'55C'(,R12)
25F0: MVC X'01F'(4,R1),X'12C'(R12)
25F6: BC 15,X'130'(,R12)
25FA: DC XL6'000000000000'
2600: TM X'003'(R1),16
2604: BC 8,X'162'(,R12)
2608: TM X'006'(R8),7
260C: BC 8,X'162'(,R12)
2610: TM X'818'(R12),2
2614: BC 1,X'55C'(,R12)
2618: TM X'01C'(R1),1
261C: BC 8,X'162'(,R12)
2620: MVC X'12C'(4,R12),X'00C'(R1)
2626: TM X'01C'(R1),3
262A: BC 1,X'56C'(,R12)
262E: BC 15,X'548'(,R12)
2632: CLI X'818'(R12),2
2636: BC 8,X'4CE'(,R12)
263A: TM X'818'(R12),5
263E: BC 7,X'17A'(,R12)
2642: TM X'003'(R1),8
2646: BC 8,X'4B4'(,R12)
264A: TM X'00C'(R8),16
264E: BC 8,X'1B8'(,R12)
2652: CLI X'818'(R12),1
2656: BC 7,X'19A'(,R12)
265A: MVC X'001'(1,R9),X'008'(R9)
2660: MVC X'008'(1,R9),X'002'(R9)
2666: BC 15,X'1B0'(,R12)
266A: AI X'006'(R9),255
266E: BC 8,X'36C'(,R11)
2672: LM R4,R5,X'008'(,R9)
2676: N 5,X'0318'
267A: AR R4,R5
267C: ST 4,X'008'(,R9)
2680: MVI X'000'(R9),0
2684: BC 15,X'58E'(,R12)
2688: CLI X'00C'(R8),0
268C: BC 7,X'3CA'(,R12)
2690: LR R4,R8
2692: LH 8,X'00E'(,R4)
2696: LA 10,X'004'(,R9)
269A: MVI X'01B'(R8),0
269E: MVC X'1DB'(1,R12),X'00C'(R8)
26A4: NI X'1DB'(R12),252
26A8: LA 10,X'000'(,R10)
26AC: LH 5,X'012'(,R4)
26B0: LA 5,X'018'(,R5)
26B4: OC X'008'(4,R4),X'008'(R4)
26BA: BC 8,X'204'(,R12)
26BE: CLI X'006'(R4),144
26C2: BC 7,X'226'(,R12)
26C6: CLI X'001'(R10),4
26CA: BC 7,X'204'(,R12)
26CE: MVI X'000'(R9),1
26D2: BCR R15,R15
26D4: MVI X'001'(R9),255
26D8: OC X'008'(4,R8),X'008'(R8)
26DE: BC 8,X'388'(,R12)
26E2: L 1,X'008'(,R8)
26E6: TM X'008'(R8),112
26EA: BC 7,X'388'(,R12)
26EE: EX 0,X'22C'(,R12)
26F2: BC 15,X'252'(,R12)
26F6: XC X'008'(4,R4),X'008'(R4)
26FC: XC X'008'(4,R8),X'008'(R8)
2702: CLI X'001'(R10),4
2706: BC 7,X'26E'(,R12)
270A: MVI X'001'(R10),2
270E: MVI X'001'(R9),0
2712: CLI X'014'(R1),1
2716: BC 8,X'252'(,R12)
271A: MVI X'001'(R10),1
271E: BC 15,X'388'(,R12)
2722: LR R0,R12
2724: LH 12,SB$RELOC
2728: BALR R13,R12 LOAD R7 WITH RELOCATION REG.
272A: LR R12,R0
272C: L 4,X'00C'(,R1)
2730: AR R4,R7
2732: LM R2,R3,X'000'(,R4)
2736: LH 11,X'038C'
273A: BC 15,X'1AC'(,R11)
273E: CLI X'001'(R10),2
2742: BC 7,X'2BC'(,R12)
2746: MVI X'001'(R10),1
274A: MVC X'003'(1,R9),X'001'(R5)
2750: L 2,X'004'(,R5)
2754: SRL R2,X'0008'
2758: STC 2,X'008'(,R9)
275C: SRL R2,X'0008'
2760: STC 2,X'004'(,R9)
2764: SRL R2,X'0008'
2768: STC 2,X'00C'(,R9)
276C: LA 15,X'340'(,R12)
2770: TM X'000'(R5),8
2774: BC 8,X'252'(,R12)
2778: MVI X'002'(R9),255
277C: LH 8,X'00E'(,R9)
2780: LTR R8,R8
2782: BCR R8,R15
2784: LH 11,X'038C'
2788: BC 15,X'1A2'(,R11)
278C: TM X'00C'(R8),4
2790: BC 8,X'2F8'(,R12)
2794: L 2,X'00C'(,R1)
2798: AR R2,R7
279A: TM X'000'(R2),128
279E: BC 1,X'2F8'(,R12)
27A2: TM X'000'(R2),6
27A6: BC 4,X'2F8'(,R12)
27AA: SR R3,R3
27AC: IC 3,X'000'(,R2)
27B0: SRL R3,X'0003'
27B4: STC 3,X'2E9'(,R12)
27B8: CLI X'003'(R9),0
27BC: BC 11,X'2F8'(,R12)
27C0: LA 6,X'0008'
27C4: OI X'01A'(R1),1
27C8: CLI X'006'(R4),16
27CC: BC 8,X'388'(,R12)
27D0: BC 2,X'204'(,R12)
27D4: CLI X'006'(R4),12
27D8: BC 7,X'204'(,R12)
27DC: MVI X'000'(R10),255
27E0: STM R0,R15,X'348'(,R12)
27E4: LA 15,X'340'(,R12)
27E8: STH 8,X'002'(,R10)
27EC: TM X'00C'(R8),8
27F0: BC 1,X'33A'(,R12)
27F4: TM X'019'(R1),128
27F8: BC 7,X'33A'(,R12)
27FC: XC X'002'(2,R10),X'002'(R10)
2802: ST 1,X'008'(,R8)
2806: BC 15,X'36C'(,R11)
280A: MVI X'019'(R1),0
280E: BCR R0,R0
2810: LM R0,R15,X'008'(,R15)
2814: BC 15,X'388'(,R12)
2818: DC XL16'00000000000000000000000000000000'
2828: DC XL16'00000000000000000000000000000000'
2838: DC XL16'00000000000000000000000000000000'
2848: DC XL16'00000000000000000000000000000000'
2858: OC X'008'(4,R4),X'008'(R4)
285E: BC 7,X'3C6'(,R12)
2862: LA 6,X'0003'
2866: LA 10,X'010'(,R9)
286A: SH 10,X'3C8'(,R12)
286E: LH 8,X'002'(,R10)
2872: LTR R8,R8
2874: BC 8,X'3C2'(,R12)
2878: OC X'008'(4,R8),X'008'(R8)
287E: BC 7,X'3C2'(,R12)
2882: CLI X'001'(R9),255
2886: BC 8,X'2B4'(,R12)
288A: CLI X'000'(R10),255
288E: BC 7,X'2B4'(,R12)
2892: BCT 6,X'39A'(,R12)
2896: BCR R15,R15
2898: DC XL2'0004'
289A: TM X'00C'(R8),2
289E: BC 8,X'418'(,R12)
28A2: TM X'00D'(R8),64
28A6: BC 8,X'418'(,R12)
28AA: TM X'818'(R12),1
28AE: BC 8,X'3F0'(,R12)
28B2: MVC X'008'(1,R9),X'000'(R4)
28B8: MVI X'000'(R9),0
28BC: BC 15,X'58E'(,R12)
28C0: TM X'008'(R9),4
28C4: BC 1,X'36C'(,R11)
28C8: NI X'009'(R9),7
28CC: LM R2,R3,X'008'(,R9)
28D0: BCTR R3,R0
28D2: CLI X'008'(R9),2
28D6: BC 7,X'36C'(,R11)
28DA: STC 3,X'40F'(,R12)
28DE: TR X'000'(1,R2),X'718'(R12)
28E4: BC 15,X'36C'(,R11)
28E8: TM X'00C'(R8),4
28EC: BC 8,X'456'(,R12)
28F0: TM X'00D'(R8),144
28F4: BC 7,X'47A'(,R12)
28F8: TM X'006'(R8),1
28FC: BC 1,X'1B0'(,R12)
2900: MVC X'008'(1,R9),X'004'(R9)
2906: IC 6,X'002'(,R9)
290A: CLI X'004'(R9),0
290E: BC 8,X'36C'(,R11)
2912: MVI X'000'(R9),0
2916: AI X'006'(R9),254
291A: BC 7,X'58E'(,R12)
291E: MVI X'004'(R9),0
2922: BC 15,X'58E'(,R12)
2926: TM X'00D'(R8),8
292A: BC 1,X'36C'(,R11)
292E: TM X'008'(R9),4
2932: BC 1,X'36C'(,R11)
2936: TM X'008'(R9),32
293A: BC 1,X'36C'(,R11)
293E: TM X'00E'(R8),2
2942: BC 1,X'3F8'(,R12)
2946: BC 15,X'36C'(,R11)
294A: TM X'818'(R12),3
294E: BC 7,X'48A'(,R12)
2952: TM X'006'(R8),1
2956: BC 1,X'49E'(,R12)
295A: CLI X'818'(R12),0
295E: BC 8,X'36C'(,R11)
2962: LA 6,X'0008'
2966: TM X'818'(R12),4
296A: BC 1,X'36C'(,R11)
296E: OI X'01C'(R8),7
2972: MVC X'008'(1,R9),X'000'(R4)
2978: OI X'008'(R9),6
297C: MVI X'000'(R9),0
2980: BC 15,X'58E'(,R12)
2984: CLI X'00C'(R8),0
2988: BC 7,X'36C'(,R11)
298C: XC X'008'(4,R8),X'008'(R8)
2992: LH 8,X'00E'(,R8)
2996: MVI X'01B'(R8),0
299A: BC 15,X'36C'(,R11)
299E: TM X'003'(R1),16
29A2: BC 1,X'548'(,R12)
29A6: CLI X'00C'(R8),0
29AA: BC 7,X'51A'(,R12)
29AE: LH 5,X'00E'(,R8)
29B2: MVC X'006'(2,R5),X'006'(R8)
29B8: XC X'008'(4,R8),X'008'(R8)
29BE: LR R8,R5
29C0: MVI X'01B'(R8),0
29C4: LH 5,X'5C8'(,R12)
29C8: MVZ X'501'(1,R12),X'003'(R8)
29CE: LA 5,X'000'(,R5)
29D2: LA 5,X'004'(,R5)
29D6: MVC X'513'(1,R12),X'00C'(R8)
29DC: NI X'513'(R12),252
29E0: LA 5,X'000'(,R5)
29E4: XC X'000'(4,R5),X'000'(R5)
29EA: MVI X'057'(R12),240
29EE: BC 15,X'042'(,R12)
29F2: MVI X'057'(R12),0
29F6: LR R13,R0
29F8: MVC X'00A'(2,R13),X'000'(R9)
29FE: ST 7,X'004'(,R13)
2A02: LA 9,X'608'(,R12)
2A06: TM X'00C'(R8),16
2A0A: BC 1,X'542'(,R12)
2A0E: LA 9,X'5E4'(,R12)
2A12: LH 13,X'5F4'(,R12)
2A16: BCR R15,R13
2A18: TM IC$T+1(R1),BC$DIAG DIAGNOSTIC CCB?
2A1C: BZ X'2A52' NO
2A20: TM X'818'(R12),2
2A24: BC 8,X'564'(,R12)
2A28: OI X'027'(R1),142
2A2C: NI X'01C'(R8),253
2A30: BC 15,X'36C'(,R11)
2A34: TM X'01C'(R1),2
2A38: BC 8,X'582'(,R12)
2A3C: L 2,X'014'(,R1)
2A40: ST 2,X'00C'(,R1)
2A44: AR R2,R7
2A46: LM R2,R3,X'000'(,R2)
2A4A: OI X'01C'(R8),2
2A4E: BC 15,X'58E'(,R12)
2A52: OI IP$CONT2(R8),BP$IO2 SET I/O 2 CONTROL BIT
2A56: LM R2,R3,X'2AAC'
2A5A: AR R2,R1 POINT TO CCB SENSE BYTES
2A5C: SR R2,R7 SUBTRACT RELOCATION REGISTER
2A5E: TM IC$T+1(R1),BC$DIAG DIAGNOSTIC CCB?
2A62: BNO X'2A76' NO
2A66: LA 0,X'0014'
2A6A: MVI X'004'(R1),0
* DIAG14
2A6E: DIAG X'0000',14
2A72: STC 0,X'004'(,R1)
2A76: LH 11,X'5E8'(,R12)
2A7A: BC 15,X'1AC'(,R11)
*
2A7E: TM X'00C'(R8),4
2A82: BC 8,X'4CE'(,R12)
2A86: TM X'018'(R8),32
2A8A: BC 8,X'4CE'(,R12)
2A8E: SR R6,R6
2A90: NI X'018'(R8),251
2A94: BC 15,X'000'(,R12)
2A98: HDR R5,R0
2A9A: DC XL16'00000000000000000000000000000000'
2AAA: DC XL2'0000'
2AAC: SPM R0,R0
2AAE: DC XL6'001400000006'
2AB4: SP X'F4D'(16,R15),X'632'(16,R4)
2ABA: DC XL2'0040'
2ABC: SPM R0,R0
2ABE: DC XL2'004D'
2AC0: ADR R7,R14
2AC2: DC XL2'0140'
2AC4: STC 0,X'4FB'(,R9)
2AC8: SSM X'50F'(R9),24
2ACC: STH 0,X'770'(,R4)
2AD0: DC XL2'B36C'
2AD2: SR R6,R6
2AD4: BC 15,X'36C'(,R11)
2AD8: DC XL12'FF00004D000000400060004D'
2AE4: ADR R12,R6
2AE6: DC XL4'0120BDB1'
2AEA: MVN X'1C1'(146,R10),X'1E1'(R15)
2AF0: SLL R11,X'999'(,R13)
2AF4: HPR X'9E9'(R15),201
2AF8: DC XL2'BBB2'
2AFA: MVC X'2C2'(147,R10),X'2E2'(R15)
2B00: SRA R11,X'A9A'(,R13)
2B04: AH R12,X'AEA'(,R15)
2B08: DC XL2'BEB4'
2B0A: NC X'4C4'(149,R10),X'4E4'(R15)
2B10: SRDL R11,X'C9C'(,R13)
2B14: DC XL2'ACCC'
2B16: MP X'FB0'(15,R11),X'090'(13,R13)
2B1C: DC XL4'A0C0F0E0'
2B20: SRL R11,X'898'(,R13)
2B24: DC XL2'A8C8'
2B26: ZAP X'00B5'(15),X'595'(9,R13)
2B2C: DC XL4'A5C5F5E5'
2B30: SLDL R3,X'919'(,R5)
2B34: CDR R4,R9
2B36: CE 6,X'01B3'(R9)
2B3A: MVZ X'3C3'(148,R10),X'3E3'(R15)
2B40: SLA R3,X'A1A'(,R5)
2B44: ADR R4,R10
2B46: AE 6,X'0234'(R10)
2B4A: OC X'6C6'(151,R10),X'6E6'(R15)
2B50: SRDA R3,X'031C'
2B54: MDR R4,R12
2B56: ME 6,X'07B7'(R12)
2B5A: XC X'7C7'(152,R10),X'7E7'(R15)
2B60: SLDA R3,X'818'(,R5)
2B64: LDR R4,R8
2B66: LE 6,X'D35'(R8,R3)
2B6A: CL 1,X'545'(R5,R2)
2B6E: DC XL2'7565'
2B70: BASR R8,R5
2B72: D 1,X'D4D'(R13,R2)
2B76: DE 6,X'B33'(R13,R3)
2B7A: DC XL2'5313'
2B7C: LDCR R4,R3
2B7E: DC XL4'73630B83'
2B82: S 1,X'B4B'(R11,R2)
2B86: SE 6,X'E36'(R11,R3)
2B8A: O 1,X'646'(R6,R2)
2B8E: DC XL4'76660E86'
2B92: AL 1,X'E4E'(R14,R2)
2B96: AU 6,X'F37'(R14,R3)
2B9A: X 1,X'747'(R7,R2)
2B9E: DC XL6'77670F875F1F'
2BA4: SWR R4,R15
2BA6: SU 6,X'0531'(R15)
2BAA: DC XL2'5111'
2BAC: LNDR R4,R1
2BAE: DC XL2'7161'
2BB0: ISK R8,R1
2BB2: TRT X'DCD'(158,R10),X'DED'(R15)
2BB8: BCTR R3,R2
2BBA: DC XL2'5212'
2BBC: LTDR R4,R2
2BBE: DC XL2'7262'
2BC0: SVC R8,R2
2BC2: DC XL2'DB9B'
2BC4: SH R12,X'BEB'(,R15)
2BC8: M 11,X'414'(R6,R5)
2BCC: HDR R4,R4
2BCE: DC XL4'74640C84'
2BD2: ED X'ECE'(159,R10),X'EEE'(R15)
2BD8: SPM R3,R0
2BDA: ST 1,X'040'(,R2)
2BDE: STE 6,X'0880'
2BE2: EDMK X'FCF'(160,R10),X'FEF'(R15)
2BE8: STH 5,X'06A'(,R6)
2BEC: DC XL4'F0C0D070'
2BF0: ZAP X'898'(13,R13),X'888'(9,R14)
2BF6: DC XL2'A8B8'
2BF8: UNPK X'393'(13,R13),X'383'(4,R14)
2BFE: SSRS R11,X'B4B'(,R7)
2C02: S 9,X'B8B'(R11,R6)
2C06: SH R11,X'4C4'(,R15)
2C0A: NC X'484'(149,R14),X'4B4'(R10)
2C10: ME 4,X'C9C'(R12,R5)
2C14: MD 8,X'CBC'(R12,R10)
2C18: MVO X'191'(13,R13),X'181'(2,R6)
2C1E: DC XL2'A1B1'
2C20: CE 4,X'990'(R9,R5)
2C24: CD 8,X'0B0'(,R10)
2C28: DC XL2'F5C5'
2C2A: CLC X'585'(150,R14),X'5B5'(R10)
2C30: DE 4,X'D9D'(R13,R5)
2C34: DD 8,X'DBD'(R13,R10)
2C38: PACK X'292'(13,R13),X'282'(3,R14)
2C3E: SSFS R11,X'A4A'(,R7)
2C42: A 9,X'08A'(R10,R14)
2C46: AH R11,X'7C7'(,R15)
2C4A: XC X'787'(152,R14),X'7B7'(R10)
2C50: SU 4,X'F9F'(R15,R5)
2C54: SW 8,X'FBF'(R15,R10)
2C58: DC XL2'F6C6'
2C5A: OC X'686'(151,R14),X'6B6'(R10)
2C60: AU 4,X'E9E'(R14,R5)
2C64: AW 8,X'EBE'(R14,R10)
2C68: CP X'999'(13,R13),X'989'(10,R14)
2C6E: HPR X'808'(R3),185
2C72: LR R5,R8
2C74: LDR R4,R8
2C76: LD 7,X'303'(R8,R3)
2C7A: LCR R5,R3
2C7C: LDCR R4,R3
2C7E: DC XL2'6373'
2C80: SER R0,R11
2C82: SR R13,R11
2C84: SDR R12,R11
2C86: DC XL2'EBFB'
2C88: HER R0,R4
2C8A: NR R5,R4
2C8C: HDR R4,R4
2C8E: DC XL2'6474'
2C90: MER R0,R12
2C92: MR R13,R12
2C94: MDR R12,R12
2C96: DC XL2'ECFC'
2C98: LNER R0,R1
2C9A: LNR R5,R1
2C9C: LNDR R4,R1
2C9E: DC XL2'E171'
2CA0: CER R0,R9
2CA2: CR R1,R0
2CA4: CDR R0,R0
2CA6: LDPR R3,R0
2CA8: DC XL2'3505'
2CAA: CLR R5,R5
2CAC: DC XL4'25456575'
2CB0: DER R0,R13
2CB2: DR R13,R13
2CB4: DDR R12,R13
2CB6: DC XL2'EDFD'
2CB8: LTER R0,R2
2CBA: LTR R5,R2
2CBC: LTDR R4,R2
2CBE: DC XL2'6272'
2CC0: AER R0,R10
2CC2: AR R13,R10
2CC4: ADR R12,R10
2CC6: DC XL4'EAFA3707'
2CCA: XR R5,R7
2CCC: DC XL4'27476777'
2CD0: SUR R0,R15
2CD2: SLR R13,R15
2CD4: SWR R12,R15
2CD6: DC XL4'EFFF3606'
2CDA: OR R5,R6
2CDC: DC XL4'26466676'
2CE0: AUR R0,R14
2CE2: ALR R13,R14
2CE4: AWR R12,R14
2CE6: DC XL10'EEFE0000000000000000'
* THE SEEMS TO BE MOSTLY CONCERNED WITH COMPUTING THE SEEK DIFFERENT
* MAGNITUDE BUT ALSO A FEW OTHER THINGS.
*
2CF0: STM R2,R5,X'00F0' SET SET BCW
2CF4: LH 9,IP$TRL(,R8) GET PUB TRAILER ADDR.
2CF8: SLL R5,X'0001' ISOLATE CYLINDER #
2CFC: SRL R5,X'0011'
2D00: LR R6,R5 R6 = R5
2D02: LH 4,X'012'(,R9) GET PRIOR CYLINDER #?
2D06: CLI X'00F0',1 IDA CMD = FORMAT WRITE?
2D0A: BNE X'2D1A' NO
2D0E: LA 0,X'001A'
2D12: TM X'003'(R1),2
2D16: BC 8,X'2CA'(,R11)
2D1A: TM IP$CONT2(R8),7 CHECK IOC BITS
2D1E: BZ X'03E'(,R12) THEY'RE ALL ZERO
2D22: BM X'2D36' SOME ARE SET
2D26: LH 5,X'010'(,R9)
2D2A: BC 15,X'048'(,R12)
2D2E: TM X'00FB',192
2D32: BC 8,X'048'(,R12)
2D36: LR R5,R4 R5 = R4
2D38: NI X'00F6',223 CLEAR DIRECTION BIT IN BCW
2D3C: CLR R5,R4 OLD CYL <= NEW CYL?
2D3E: BNH X'2D4C' YES
2D42: XR R5,R4
2D44: XR R4,R5
2D46: XR R5,R4
2D48: OI X'00F6',32
2D4C: SR R5,R4 GET DIFF BETWEEN OLD AND NEW
2D4E: TM IC$T+1(R1),BC$DIAG DIAGNOSTIC CCB?
2D52: BO X'08C'(,R12) YES
2D56: LA 3,X'019A' R3 = 410
2D5A: TM IP$FEA+1(R8),BP$DUB18 DOUBLE DENSITY 8418?
2D5E: BZ X'076'(,R12) NO
2D62: LA 3,X'032E' R3 = 814
2D66: CR R6,R3 COMPARE CYL # TO 814
2D68: LA 0,X'0018'
2D6C: BH X'2CA'(,R11) CYL # > MAX FOR DEVICE?
2D70: CLI X'00FA',6 COMPARE HEAD # TO 6
2D74: LA 0,X'0019'
2D78: BH X'2CA'(,R11) HEAD # > 6
2D7C: TM IP$CONT2(R8),7 CHECK IOC BITS
2D80: BNZ X'2D9A' SOME ARE SET
2D84: TM X'00FC',128
2D88: BC 8,X'0AA'(,R12)
2D8C: TM X'003'(R1),16
2D90: BC 1,X'0A8'(,R12)
2D94: MVI X'00F0',8
2D98: SR R6,R6
2D9A: STH 5,X'00F8' SET SEEK DIFF MAGNITUDE
2D9E: TM IP$CONT2(R8),7 CHECK IOC BITS
2DA2: BNZ X'2DDA' SOME ARE SET
2DA6: TM X'003'(R1),16
2DAA: BC 1,X'0EA'(,R12)
2DAE: TM X'003'(R1),2
2DB2: BC 1,X'0EA'(,R12)
2DB6: TM X'018'(R8),3
2DBA: BC 7,X'0EA'(,R12)
2DBE: LTR R5,R5
2DC0: BC 8,X'0EA'(,R12)
2DC4: CLI X'00F0',8
2DC8: BC 8,X'0EA'(,R12)
2DCC: TM X'00FB',192
2DD0: BC 7,X'0EA'(,R12)
2DD4: MVI X'00F0',8
2DD8: BCR R15,R13
2DDA: OI IP$CONT3(R8),BP$SKSEP SET SEEK SEPARATED
2DDE: MVN X'00FF'(1),IC$EC(R1) SET PROG OFFSET IN BCW
2DE4: TM X'00F0',10 BCW CMD IS READ OR SEEK OR A SEARCH?
2DE8: BNZR R13 YES, RETURN
2DEA: MVI X'00FF',0 CLEAR PROG OFFSET
2DEE: BCR R15,R13 RETURN
* INTERRUPT HANDLER FOR CHANNEL 3
2DF0: BC 0,X'004'(,R12)
2DF4: LH 9,IP$TRL(,R8) GET PUB TRAILER ADDRESS
2DF8: TM IP$CONT1(R8),BP$ATTN ATTENTION?
2DFC: BZ X'2E06' NO
2E00: XC X'012'(2,R9),X'012'(R9)
2E06: LTR R1,R1 CCB ADDR = 0?
2E08: BZ X'5C6'(,R11) YES
2E0C: L 4,IC$CCW(,R1) GET BCW ADDRESS
2E10: AR R4,R7 ADD RELOC.
2E12: MVC X'3153'(1),IP$CONT2(R8) SAVE IP$CONT2
2E18: NI X'3153',7 CLEAR NON-IOC BITS
2E1C: NI IP$CONT2(R8),248 CLEAR IOC BITS
2E20: TM IP$CONT1(R8),BP$DVEND DEVICE END?
2E24: BZ X'06E'(,R12) NO
2E28: TM X'3153',7 SAVE IOC BITS SET?
2E2C: BM X'06E'(,R12) YES
2E30: TM IP$TRACK(R4),192 CHECK TRACK CONDITION
2E34: BNZ X'06E'(,R12) NOT ZERO
2E38: CLI X'3153',7 SAVED IOC BITS = 7?
2E3C: BNE X'2E4A' NO
2E40: MVC X'012'(2,R9),X'010'(R9)
2E46: BC 15,X'06E'(,R12)
2E4A: MVC X'012'(2,R9),IB$CYL(R4) COPY CYLINDER ADDR TO PUB TRAILER
2E50: TM X'012'(R9),128 CYL HAS X'80' SET?
2E54: BZ X'2E5E'
2E58: XC X'012'(2,R9),X'012'(R9)
2E5E: TM IP$CONT5(R8),255 ANY CHANNEL STATUS?
2E62: BNZ X'2F42' YES
2E66: TM IP$CONT1(R8),BP$DVERR UNIT CHECK?
2E6A: BO X'0FC'(,R12) YES
2E6E: TM IC$T+1(R1),BC$DIAG DIAGNOSTIC CCB?
2E72: BNO X'2EAC' NO
2E76: TM X'006'(R8),7
2E7A: BC 8,X'0BC'(,R12)
2E7E: TM X'363'(R12),2
2E82: BC 1,X'26C'(,R12)
2E86: TM X'01C'(R1),1
2E8A: BC 14,X'0BC'(,R12)
2E8E: TM X'01C'(R1),3
2E92: BC 14,X'13C'(,R12)
2E96: L 2,X'014'(,R1)
2E9A: AR R2,R7
2E9C: L 2,X'000'(,R2)
2EA0: LA 3,X'0006'
2EA4: OI X'01C'(R8),2
2EA8: BC 15,X'14A'(,R12)
2EAC: TM IP$CONT1(R8),BP$BUSY BUSY?
2EB0: BZ X'2F5A' NO
2EB4: CLI X'363'(R12),7
2EB8: BC 8,X'334'(,R12)
2EBC: TM X'003'(R1),2
2EC0: BC 1,X'0D8'(,R12)
2EC4: OI X'00C'(R4),128
2EC8: LM R2,R5,X'000'(,R4)
2ECC: TM IC$T+1(R1),BC$DIAG DIAGNOSTIC CCB?
2ED0: BNO X'2EE4' NO
2ED4: LA 0,X'0014'
2ED8: MVI X'004'(R1),0
* DIAG14
2EDC: DIAG X'0000',14
2EE0: STC 0,X'004'(,R1)
2EE4: LH 11,SB$ECOV GET PTR TO EXCP RTN.
2EE8: BC 15,X'1AC'(,R11)
*
2EEC: TM X'003'(R1),16
2EF0: BC 8,X'136'(,R12)
2EF4: TM X'363'(R12),2
2EF8: BC 8,X'118'(,R12)
2EFC: NI X'363'(R12),253
2F00: OI X'027'(R1),142
2F04: BC 15,X'26C'(,R12)
2F08: TM X'01C'(R1),2
2F0C: BC 8,X'136'(,R12)
2F10: L 2,X'014'(,R1)
2F14: AR R2,R7
2F16: L 2,X'000'(,R2)
2F1A: LA 3,X'0006'
2F1E: OI X'01C'(R8),2
2F22: BC 15,X'0DC'(,R12)
2F26: MVC X'370'(16,R12),X'00F0'
2F2C: OI X'01C'(R8),2
2F30: L 2,X'390'(,R12) R2 = 04000014 (SENSE CMD + OFFSET TO SENSE BYTES)
2F34: AR R2,R1 ADDR TO CCB ADDR (PTR TO SENSE BYTES)
2F36: SR R3,R3
2F38: SR R2,R7 SUBTRACT RELOC.
2F3A: LM R4,R5,X'008'(,R4) GET LAST 2 WORDS OF BCW
2F3E: BC 15,X'2ECC'
*
2F42: TM X'003'(R1),16
2F46: BC 1,X'0FC'(,R12)
2F4A: MVC X'37A'(1,R12),X'017'(R1)
2F50: LA 9,X'39C'(,R12)
2F54: LH 13,X'3A0'(,R12)
2F58: BCR R15,R13
2F5A: TM X'3153',6 CHECK SAVED IOC BITS
2F5E: BO X'313C' THEY'RE SET
2F62: L 2,X'3158'
2F66: LR R5,R2
2F68: TM X'3153',3 CHECK SAVED IOC BITS
2F6C: BNZ X'2F9E' SOME ARE SET
2F70: TM IB$CYL(R4),128 CHECK BIT
2F74: MVZ IB$CYL(1,R4),X'3174' CLEAR UPPER 4 BITS
2F7A: BO X'307C' BIT WAS SET
2F7E: TM IP$CONT3(R8),BP$ECC ECC RECOVERY ACTIVE?
2F82: BO X'3002' YES
2F86: TM IB$COM(R4),X'09' BCW CMD = SEARCH?
2F8A: BNO X'305C' NO
2F8E: TM IP$CONT3(R8),BK$SKSEP SEEK SEPARATED?
2F92: BZ X'3064' NO
2F96: OI IP$CONT2(R8),BP$IO1 SET BIT
2F9A: BC 15,X'2F30'
*
2F9E: CLI X'363'(R12),1
2FA2: BC 7,X'1C2'(,R12)
2FA6: TM X'015'(R1),128
2FAA: BC 1,X'152'(,R12)
2FAE: BC 15,X'26C'(,R12)
2FB2: CLI X'363'(R12),2
2FB6: BC 8,X'152'(,R12)
2FBA: TM X'38B'(R12),255
2FBE: BC 1,X'2E6'(,R12)
2FC2: CLC X'38A'(2,R12),X'364'(R12)
2FC8: BC 8,X'2E6'(,R12)
2FCC: SLL R2,X'000E'
2FD0: SRL R2,X'000E'
2FD4: LR R3,R2
2FD6: SR R9,R9
2FD8: IC 9,X'38A'(,R12)
2FDC: AR R2,R9
2FDE: TM X'000'(R4),9
2FE2: BC 14,X'20C'(,R12)
2FE6: AH 3,X'376'(,R12)
2FEA: SH 3,X'386'(,R12)
2FEE: CLR R2,R3
2FF0: BC 13,X'2E6'(,R12)
2FF4: EX 0,X'20C'(,R12)
2FF8: BC 15,X'180'(,R12)
2FFC: XC X'000'(2,R2),X'38B'(R12)
3002: AI X'36E'(R12),255
3006: BC 8,X'26C'(,R12)
300A: AH 5,X'35C'(,R12)
300E: SR R2,R2
3010: IC 2,X'37E'(,R12)
3014: LA 2,X'001'(,R2)
3018: STC 2,X'37E'(,R12)
301C: CLI X'37E'(R12),40
3020: BC 13,X'244'(,R12)
3024: MVI X'37E'(R12),1
3028: IC 2,X'37A'(,R12)
302C: LA 2,X'001'(,R2)
3030: STC 2,X'37A'(,R12)
3034: LR R2,R5
3036: ST 2,X'368'(,R12)
303A: LA 3,X'0001'
303E: SR R2,R7
3040: LM R4,R5,X'378'(,R12)
3044: BC 15,X'0DC'(,R12)
3048: CLI X'001'(R1),2
304C: BC 13,X'0D8'(,R12)
3050: TM X'003'(R1),32
3054: BC 8,X'0D8'(,R12)
3058: NI X'018'(R8),251
305C: TM X'018'(R8),2
3060: BC 1,X'29E'(,R12)
3064: OI IP$CONT3(R8),BP$SKSEP SET SEEK SEPARATED
3068: CLI X'00F0',8
306C: BC 8,X'0D8'(,R12)
3070: LH 9,X'010'(,R8)
3074: TM X'000'(R9),128
3078: BC 8,X'0D8'(,R12)
307C: XC X'008'(4,R8),X'008'(R8)
3082: LTR R8,R8
3084: LH 12,X'02EA'
3088: BALR R13,R12
308A: BC 15,X'2B2'(,R11)
308E: MVI X'00B'(R4),0
3092: BC 15,X'36C'(,R11)
3096: TM X'006'(R4),64
309A: BC 1,X'30A'(,R12)
309E: BC 15,X'0D4'(,R12)
30A2: TM X'018'(R8),1
30A6: BC 1,X'2F6'(,R12)
30AA: LM R2,R3,X'000'(,R4)
30AE: AR R2,R7
30B0: STM R2,R3,X'368'(,R12)
30B4: NI X'36E'(R12),31
30B8: TM X'000'(R4),9
30BC: BC 4,X'0D8'(,R12)
30C0: BC 1,X'2F6'(,R12)
30C4: CLI X'007'(R4),1
30C8: BC 8,X'2F6'(,R12)
30CC: OI X'018'(R8),1
30D0: MVC X'378'(8,R12),X'008'(R4)
30D6: TM X'000'(R4),9
30DA: BC 1,X'0D8'(,R12)
30DE: L 2,X'368'(,R12)
30E2: BC 15,X'24A'(,R12)
30E6: OI X'01C'(R8),3
30EA: L 2,X'380'(,R12)
30EE: BC 15,X'32A'(,R12)
30F2: TM X'00B'(R4),64
30F6: BC 8,X'322'(,R12)
30FA: MVC X'370'(16,R12),X'000'(R4)
3100: MVC X'37A'(1,R12),X'017'(R1)
3106: NI X'018'(R8),251
310A: LM R2,R5,X'370'(,R12)
310E: BC 15,X'0DC'(,R12)
3112: L 2,X'398'(,R12)
3116: OI X'01C'(R8),6
311A: SR R3,R3
311C: SR R7,R7
311E: SR R10,R10
3120: BC 15,X'148'(,R12)
3124: MVC X'370'(16,R12),X'000'(R4)
312A: MVI X'37B'(R12),64
312E: MVC X'010'(2,R9),X'35F'(R12)
3134: OI X'01C'(R8),7
3138: BC 15,X'316'(,R12)
313C: CLI X'363'(R12),7
3140: BC 7,X'334'(,R12)
3144: MVI X'363'(R12),0
3148: BC 15,X'172'(,R12)
314C: DC XL8'0100000000000000'
3154: SVC R0,R0
3156: DC XL12'000000000000000000000000'
3162: LNER R6,R1
3164: DC XL12'000000000000000000000000'
3170: STR R0,R0
3172: LNER R7,R10
3174: DC XL12'000000010000000000000000'
3180: SPM R0,R0
3182: DC XL4'00140E00'
3186: LNER R7,R4
3188: DC XL2'0E00'
318A: LNER R4,R14
318C: DC XL2'E240'
318E: SPM R4,R13
3190: STC 0,X'0040'
3194: SPM R8,R0
3196: DC XL2'514D'
3198: AWR R12,R8
319A: BCR R4,R0
319C: DC XL2'0000'
319E: SSK R4,R13
31A0: LPER R15,R2
31A2: SVC R4,R0
31A4: LPR R0,R0
31A6: DC XL2'A04D'
31A8: LPER R9,R6
31AA: SVC R4,R0
31AC: DC XL4'0020004F'
31B0: LPER R4,R8
31B2: SSK R1,R1
31B4: DC XL4'0008004F'
31B8: LPER R4,R8
31BA: SSK R1,R2
31BC: DC XL4'0002004D'
31C0: AWR R12,R8
31C2: BCR R4,R0
31C4: DC XL4'0000024D'
31C8: LPER R10,R2
31CA: LDCR R4,R0
31CC: DC XL4'00000000'
31D0: MVI X'123'(R12),16
31D4: MVI X'0B9'(R12),0
31D8: LA 2,X'100'(,R12)
31DC: MVC X'122'(1,R12),X'01C'(R8)
31E2: NI X'122'(R12),7
31E6: NI X'01C'(R8),248
31EA: TM X'006'(R8),2
31EE: BC 1,X'06C'(,R12)
31F2: TM X'007'(R8),255
31F6: BC 7,X'064'(,R12)
31FA: TM X'006'(R8),36
31FE: BC 1,X'0A4'(,R12)
3202: TM X'006'(R8),48
3206: BC 7,X'0C0'(,R12)
320A: CLI X'122'(R12),2
320E: BC 7,X'0A4'(,R12)
3212: CLI X'014'(R1),0
3216: BC 7,X'052'(,R12)
321A: CLI X'000'(R4),15
321E: BC 8,X'0A4'(,R12)
3222: MVI X'123'(R12),80
3226: LA 9,X'0DC'(,R12)
322A: LH 13,X'0E0'(,R12)
322E: LA 0,X'008'(,R2)
3232: BCR R15,R13
3234: CLI X'122'(R12),2
3238: BC 8,X'042'(,R12)
323C: LR R9,R0
323E: MVC X'008'(12,R2),X'000'(R9)
3244: LA 9,X'0002'
3248: LR R4,R1
324A: LA 4,X'000'(,R4)
324E: A 4,X'118'(,R12)
3252: ST 4,X'000'(,R2)
3256: LA 4,X'000'(,R2)
325A: SR R10,R10
325C: SR R7,R7
325E: EX 9,X'114'(,R12)
3262: MVI X'123'(R12),32
3266: SR R7,R7
3268: LH 11,X'11C'(,R12)
326C: BC 15,X'1AC'(,R11)
3270: NI X'018'(R8),251
3274: TM X'003'(R1),8
3278: BC 8,X'0B4'(,R12)
327C: LH 9,X'0350'
3280: MVI X'070'(R9),255
3284: MVI X'123'(R12),64
3288: BC 0,X'2B2'(,R11)
328C: BC 15,X'36C'(,R11)
3290: TM X'003'(R1),8
3294: BC 8,X'596'(,R11)
3298: LH 9,X'0350'
329C: MVI X'070'(R9),255
32A0: MVI X'123'(R12),48
32A4: BC 15,X'596'(,R11)
32A8: DC XL8'0000000C00000045'
32B0: STC 0,X'0040'
32B4: LNER R0,R1
32B6: DC XL16'004500000040CE00004D000000400060'
32C6: DC XL2'004D'
32C8: LTER R7,R0
32CA: DC XL2'0120'
32CC: BCR R0,R0
32CE: BCR R0,R0
32D0: DC XL2'0000'
32D2: LTER R13,R0
32D4: LDPR R0,R0
32D6: DC XL14'0006000000000000000000000000'
32E4: OI X'01C'(R8),0
32E8: SPM R0,R0
32EA: DC XL2'0014'
32EC: BCT 3,X'F80'(R2,R3)
32F0: DC XL16'00000000000000000000000000000000'
3300: DC XL16'00000000000000000000000000000000'
3310: DC XL16'00000000000000000000000000000000'
3320: DC XL16'00000000000000000000000000000000'
3330: DC XL16'00000000000000000000000000000000'
3340: DC XL16'00000000000000000000000000000000'
3350: DC XL8'0000000000000000'
3358: BC 0,X'004'(,R12)
335C: LA 2,X'2A0'(,R12)
3360: LR R3,R8
3362: TM X'01C'(R8),8
3366: BC 1,X'016'(,R12)
336A: LA 3,X'002'(,R3)
336E: TM X'000'(R3),2
3372: BC 8,X'022'(,R12)
3376: LA 2,X'390'(,R12)
337A: MVC X'26A'(1,R12),X'01C'(R8)
3380: NI X'26A'(R12),7
3384: NI X'01C'(R8),248
3388: TM X'00D'(R8),32
338C: BC 1,X'47E'(,R12)
3390: TM X'006'(R8),2
3394: BC 1,X'184'(,R12)
3398: TM X'007'(R8),255
339C: BC 7,X'05C'(,R12)
33A0: TM X'006'(R8),48
33A4: BC 7,X'238'(,R12)
33A8: CLI X'26A'(R12),2
33AC: BC 7,X'066'(,R12)
33B0: LA 0,X'0A0'(,R2)
33B4: LA 9,X'26C'(,R12)
33B8: LH 13,X'266'(,R12)
33BC: BCR R15,R13
33BE: CLI X'26A'(R12),5
33C2: BC 11,X'1BA'(,R12)
33C6: CLI X'26A'(R12),1
33CA: BC 8,X'0E8'(,R12)
33CE: CLI X'26A'(R12),3
33D2: BC 7,X'1DE'(,R12)
33D6: TM X'0AD'(R2),2
33DA: BC 14,X'0FE'(,R12)
33DE: LA 9,X'0004'
33E2: LA 4,X'018'(,R2)
33E6: SR R10,R10
33E8: NI X'01C'(R8),248
33EC: EX 9,X'0E4'(,R12)
33F0: TM X'003'(R1),8
33F4: BC 8,X'0D2'(,R12)
33F8: LH 9,X'0350'
33FC: LR R3,R8
33FE: TM X'01C'(R8),8
3402: BC 1,X'0B2'(,R12)
3406: LA 3,X'002'(,R3)
340A: TM X'000'(R3),2
340E: BC 8,X'0BE'(,R12)
3412: LH 9,X'0352'
3416: TM X'00D'(R8),32
341A: BC 8,X'0CE'(,R12)
341E: TM X'01C'(R8),7
3422: BC 7,X'0D2'(,R12)
3426: MVI X'070'(R9),0
342A: MVI X'038'(R2),8
342E: MVC X'050'(4,R2),X'038'(R2)
3434: LH 11,X'268'(,R12)
3438: BC 15,X'1AC'(,R11)
343C: OI X'01C'(R8),0
3440: NI X'01C'(R8),248
3444: L 4,X'00C'(,R1)
3448: AR R4,R7
344A: ST 4,X'038'(,R2)
344E: LA 1,X'000'(,R1)
3452: BC 15,X'098'(,R12)
3456: L 9,X'038'(,R2)
345A: L 9,X'000'(,R9)
345E: TM X'003'(R1),8
3462: BC 8,X'130'(,R12)
3466: LH 9,X'0350'
346A: LR R3,R8
346C: TM X'01C'(R8),8
3470: BC 1,X'120'(,R12)
3474: LA 3,X'002'(,R3)
3478: TM X'000'(R3),2
347C: BC 8,X'12C'(,R12)
3480: LH 9,X'0352'
3484: LA 9,X'073'(,R9)
3488: CLC X'0AE'(4,R2),X'000'(R9)
348E: BC 8,X'0E8'(,R12)
3492: L 4,X'00C'(,R1)
3496: AR R4,R7
3498: ST 4,X'038'(,R2)
349C: LA 9,X'0001'
34A0: LA 4,X'000'(,R2)
34A4: BC 15,X'08E'(,R12)
34A8: TM X'003'(R1),32
34AC: BC 8,X'164'(,R12)
34B0: NI X'018'(R8),251
34B4: CLI X'001'(R1),2
34B8: BC 2,X'1DE'(,R12)
34BC: LA 9,X'0003'
34C0: LA 4,X'010'(,R2)
34C4: BC 15,X'08E'(,R12)
34C8: LA 9,X'0005'
34CC: CLI X'26A'(R12),4
34D0: BC 8,X'1A4'(,R12)
34D4: LA 9,X'0006'
34D8: BC 15,X'1A4'(,R12)
34DC: LR R9,R0
34DE: MVC X'0A0'(12,R2),X'000'(R9)
34E4: L 9,X'0A4'(,R2)
34E8: S 9,X'054'(,R2)
34EC: ST 9,X'038'(,R2)
34F0: CLI X'26A'(R12),4
34F4: BC 11,X'170'(,R12)
34F8: LA 9,X'0002'
34FC: LR R4,R1
34FE: LA 4,X'000'(,R4)
3502: A 4,X'29C'(,R12)
3506: ST 4,X'008'(,R2)
350A: LA 4,X'008'(,R2)
350E: BC 15,X'08E'(,R12)
3512: TM X'015'(R1),8
3516: BC 8,X'058'(,R12)
351A: CLI X'26A'(R12),6
351E: BC 7,X'214'(,R12)
3522: LA 6,X'0011'
3526: TM X'015'(R1),32
352A: BC 1,X'1DE'(,R12)
352E: CLI X'0BD'(R2),19
3532: BC 7,X'150'(,R12)
3536: NI X'01C'(R8),248
353A: TM X'003'(R1),8
353E: BC 8,X'20C'(,R12)
3542: LH 9,X'0350'
3546: LR R3,R8
3548: TM X'01C'(R8),8
354C: BC 1,X'1FC'(,R12)
3550: LA 3,X'002'(,R3)
3554: TM X'000'(R3),2
3558: BC 8,X'208'(,R12)
355C: LH 9,X'0352'
3560: MVI X'070'(R9),255
3564: LA 0,X'0A0'(,R2)
3568: BC 15,X'36C'(,R11)
356C: LA 6,X'0011'
3570: L 9,X'038'(,R2)
3574: TM X'000'(R9),128
3578: BC 8,X'1DE'(,R12)
357C: CLI X'0BD'(R2),18
3580: BC 8,X'1DE'(,R12)
3584: LA 9,X'0005'
3588: LA 4,X'0040'(R2)
358C: BC 15,X'08E'(,R12)
3590: TM X'003'(R1),8
3594: BC 8,X'596'(,R11)
3598: LH 9,X'0350'
359C: LR R3,R8
359E: TM X'01C'(R8),8
35A2: BC 1,X'252'(,R12)
35A6: LA 3,X'002'(,R3)
35AA: TM X'000'(R3),2
35AE: BC 8,X'25E'(,R12)
35B2: LH 9,X'0352'
35B6: MVI X'070'(R9),255
35BA: BC 15,X'596'(,R11)
35BE: STC 0,X'632'(,R4)
35C2: DC XL14'0000F044004D000000400C00004D'
35D0: HER R4,R0
35D2: SVC R4,R0
35D4: DC XL4'0100004D'
35D8: HER R9,R12
35DA: SVC R4,R0
35DC: DC XL12'0020004F35360C110008004F'
35E8: HER R10,R8
35EA: DC XL2'0C12'
35EC: SVC R0,R0
35EE: DC XL2'004D'
35F0: LCER R13,R14
35F2: DC XL2'0C40'
35F4: SPM R0,R0
35F6: DC XL2'0014'
35F8: LCR R0,R0
35FA: DC XL2'35F8'
35FC: LDPR R0,R0
35FE: DC XL6'000100003600'
3604: LDPR R0,R0
3606: DC XL2'0006'
3608: AR R0,R0
360A: DC XL6'36A500000005'
3610: OR R0,R0
3612: DC XL2'36AC'
3614: STD 0,X'0004'
3618: BCR R0,R0
361A: DC XL2'36AA'
361C: STH 0,X'0006'
3620: OR R0,R0
3622: DC XL2'36B2'
3624: STD 0,X'0004'
3628: AR R0,R0
362A: DC XL2'3628'
362C: STD 0,X'0000'
3630: DC XL8'0000363000000000'
3638: BCR R0,R0
363A: DC XL2'36B0'
363C: STH 0,X'0006'
3640: AI X'6A5'(R3),0
3644: STH 0,X'0005'
3648: DC XL8'0000364800000008'
3650: SPM R0,R0
3652: DC XL2'36B6'
3654: LDPR R0,R0
3656: DC XL2'0018'
3658: BCR R0,R0
365A: DC XL2'3688'
365C: STD 0,X'0006'
3660: LNER R0,R0
3662: DC XL2'3690'
3664: STD 0,X'0005'
3668: SSK R0,R0
366A: DC XL2'3660'
366C: STH 0,X'0000'
3670: DC XL12'000000000000000000000000'
367C: STH 0,X'0000'
3680: LTR R0,R0
3682: DC XL2'3690'
3684: STD 0,X'0008'
3688: DC XL16'00000000000000000000000000000000'
3698: DC XL16'00000000000000000000000000000000'
36A8: DC XL16'00000000000000000000000000000000'
36B8: DC XL16'00000000000000000000000000000000'
36C8: DC XL16'00000000000000000000000000000000'
36D8: DC XL14'0000000000000000000000000000'
36E6: BCR R0,R0
36E8: LCR R0,R0
36EA: DC XL2'36E8'
36EC: LDPR R0,R0
36EE: DC XL6'0001000036F0'
36F4: LDPR R0,R0
36F6: DC XL2'0006'
36F8: AR R0,R0
36FA: DC XL6'379500000005'
3700: OR R0,R0
3702: DC XL2'379C'
3704: STD 0,X'0004'
3708: BCR R0,R0
370A: DC XL2'379A'
370C: STH 0,X'0006'
3710: OR R0,R0
3712: DC XL2'37A2'
3714: STD 0,X'0004'
3718: AR R0,R0
371A: DC XL2'3718'
371C: STD 0,X'0000'
3720: DC XL8'0000372000000000'
3728: BCR R0,R0
372A: DC XL2'37A0'
372C: STH 0,X'0006'
3730: AI X'795'(R3),0
3734: STH 0,X'0005'
3738: DC XL8'0000373800000008'
3740: SPM R0,R0
3742: DC XL2'37A6'
3744: LDPR R0,R0
3746: DC XL2'0018'
3748: BCR R0,R0
374A: DC XL2'3778'
374C: STD 0,X'0006'
3750: LNER R0,R0
3752: DC XL2'3780'
3754: STD 0,X'0005'
3758: SSK R0,R0
375A: DC XL2'3750'
375C: STH 0,X'0000'
3760: DC XL12'000000000000000000000000'
376C: STH 0,X'0000'
3770: LTR R0,R0
3772: DC XL2'3780'
3774: STD 0,X'0008'
3778: DC XL16'00000000000000000000000000000000'
3788: DC XL16'00000000000000000000000000000000'
3798: DC XL16'00000000000000000000000000000000'
37A8: DC XL16'00000000000000000000000000000000'
37B8: DC XL16'00000000000000000000000000000000'
37C8: DC XL14'0000000000000000000000000000'
37D6: MVI X'6D0'(R12),1
37DA: CLI X'006'(R8),74
37DE: BC 8,X'4D4'(,R12)
37E2: TM X'006'(R8),2
37E6: BC 1,X'528'(,R12)
37EA: TM X'007'(R8),255
37EE: BC 7,X'544'(,R12)
37F2: TM X'006'(R8),48
37F6: BC 7,X'238'(,R12)
37FA: TM X'26A'(R12),4
37FE: BC 1,X'4F2'(,R12)
3802: TM X'26A'(R12),2
3806: BC 1,X'4BE'(,R12)
380A: LH 12,X'016'(,R8)
380E: BCR R15,R12
3810: BCR R0,R12
3812: HPR X'600'(R6),102
3816: MVI X'6D0'(R12),32
381A: CLC X'4D0'(3,R12),X'0BE'(R2)
3820: BC 8,X'5A4'(,R12)
3824: BC 15,X'544'(,R12)
3828: SSK R0,R0
382A: STH 0,X'202'(,R9)
382E: DC XL2'C6D0'
3830: OI X'008'(R8),128
3834: OI X'01C'(R8),4
3838: LR R9,R0
383A: MVC X'0A0'(12,R2),X'000'(R9)
3840: LH 6,X'010'(,R8)
3844: OI X'000'(R6),128
3848: BCR R15,R15
384A: MVI X'6D0'(R12),3
384E: TM X'006'(R8),4
3852: BC 1,X'502'(,R12)
3856: HPR X'700'(R7),119
385A: OI X'01C'(R8),1
385E: LR R9,R0
3860: MVC X'0A0'(12,R2),X'000'(R9)
3866: BAL 13,X'6F2'(,R12)
386A: LR R4,R9
386C: BC 0,X'514'(,R12)
3870: BC 0,X'518'(,R12)
3874: LH 11,X'268'(,R12)
3878: MVI X'6D0'(R12),5
387C: BC 15,X'1AC'(,R11)
3880: LR R9,R0
3882: MVC X'0A0'(12,R2),X'000'(R9)
3888: BAL 13,X'6F2'(,R12)
388C: LA 9,X'0002'
3890: LA 4,X'058'(,R2)
3894: MVI X'6D0'(R12),21
3898: BC 15,X'08E'(,R12)
389C: MVI X'6D0'(R12),48
38A0: LA 0,X'0A0'(,R2)
38A4: MVC X'014'(6,R1),X'0BE'(R2)
38AA: LA 9,X'574'(,R12)
38AE: LH 13,X'266'(,R12)
38B2: BCR R15,R13
38B4: TM X'003'(R1),32
38B8: BC 8,X'0E8'(,R12)
38BC: NI X'018'(R8),251
38C0: CLI X'001'(R1),2
38C4: BC 2,X'676'(,R12)
38C8: BC 15,X'0E8'(,R12)
38CC: SSM X'004D',198
38D0: DC XL4'00000040'
38D4: ME 0,X'004D'
38D8: HER R4,R0
38DA: SVC R4,R0
38DC: DC XL4'0008004F'
38E0: LER R11,R4
38E2: SVC R1,R2
38E4: DC XL4'0020004F'
38E8: LER R11,R4
38EA: SVC R1,R1
38EC: DC XL4'0001004D'
38F0: CER R13,R12
38F2: DC XL4'FF000000'
38F6: LPR R4,R13
38F8: AER R1,R2
38FA: SVC R0,R0
38FC: MVI X'6D1'(R12),64
3900: L 3,X'038'(,R2)
3904: LA 5,X'088'(,R2)
3908: CR R3,R5
390A: BC 2,X'5C4'(,R12)
390E: LA 5,X'060'(,R2)
3912: CR R3,R5
3914: BC 4,X'5C4'(,R12)
3918: BC 15,X'544'(,R12)
391C: L 5,X'0000'(R3)
3920: LA 5,X'0000'(R5)
3924: MVC X'67E'(2,R12),X'006'(R3)
392A: A 5,X'67C'(,R12)
392E: ST 5,X'680'(,R12)
3932: MVI X'6D1'(R12),65
3936: L 3,X'0000'(R3)
393A: LA 3,X'0000'(R3)
393E: MVC X'67E'(2,R12),X'0D0'(R2)
3944: S 3,X'67C'(,R12)
3948: MVC X'67D'(3,R12),X'0CD'(R2)
394E: A 3,X'67C'(,R12)
3952: LA 5,X'0D2'(,R2)
3956: LA 13,X'0003'
395A: C 3,X'680'(,R12)
395E: MVI X'6D1'(R12),66
3962: BC 11,X'620'(,R12)
3966: XC X'000'(1,R3),X'000'(R5)
396C: LA 3,X'0001'(R3)
3970: LA 5,X'0001'(R5)
3974: BCT 13,X'602'(,R12)
3978: SR R6,R6
397A: L 3,X'038'(,R2)
397E: TM X'004'(R3),64
3982: BC 8,X'676'(,R12)
3986: BAL 13,X'704'(,R12)
398A: MVC X'098'(5,R2),X'0C6'(R2)
3990: LA 5,X'0078'(R2)
3994: L 3,X'0A4'(,R2)
3998: LA 3,X'0000'(R3)
399C: TM X'000'(R3),16
39A0: BC 1,X'662'(,R12)
39A4: MVC X'000'(8,R5),X'088'(R2)
39AA: TM X'000'(R3),128
39AE: BC 8,X'65E'(,R12)
39B2: OI X'000'(R5),128
39B6: LA 5,X'0008'(R5)
39BA: BAL 13,X'728'(,R12)
39BE: LA 9,X'0001'
39C2: LA 4,X'0060'(R2)
39C6: MVI X'6D1'(R12),80
39CA: BC 15,X'08E'(,R12)
39CE: BC 15,X'1DE'(,R12)
39D2: DC XL10'00000000000000000000'
39DC: BAL 13,X'704'(,R12)
39E0: MVC X'098'(4,R2),X'092'(R2)
39E6: MVI X'09C'(R2),1
39EA: BAL 13,X'756'(,R12)
39EE: TM X'004'(R3),64
39F2: BC 8,X'6A6'(,R12)
39F6: LA 5,X'0080'(R2)
39FA: BAL 13,X'728'(,R12)
39FE: LA 9,X'0001'
3A02: LA 4,X'0060'(R2)
3A06: MVI X'6D1'(R12),96
3A0A: NI X'018'(R8),251
3A0E: BC 15,X'08E'(,R12)
3A12: LA 3,X'0D6'(,R2)
3A16: LH 5,X'012'(,R8)
3A1A: STH 3,X'016'(,R5)
3A1E: MVC X'0D6'(24,R2),X'0BE'(R2)
3A24: BC 15,X'0E8'(,R12)
3A28: DC XL2'0000'
3A2A: BCR R0,R0
3A2C: LH 9,X'0350'
3A30: TM X'002'(R8),2
3A34: BC 8,X'6E4'(,R12)
3A38: LH 9,X'0352'
3A3C: TM X'003'(R1),8
3A40: BC 1,X'6F0'(,R12)
3A44: LA 13,X'004'(,R13)
3A48: BCR R15,R13
3A4A: L 9,X'0A4'(,R2)
3A4E: LA 9,X'0000'(R9)
3A52: S 9,X'054'(,R2)
3A56: ST 9,X'038'(,R2)
3A5A: BCR R15,R13
3A5C: XC X'090'(16,R2),X'090'(R2)
3A62: MVC X'093'(1,R2),X'0C3'(R2)
3A68: TM X'0C4'(R2),64
3A6C: BC 8,X'71C'(,R12)
3A70: MVI X'092'(R2),1
3A74: MVC X'095'(1,R2),X'0C4'(R2)
3A7A: NI X'095'(R2),31
3A7E: BCR R15,R13
3A80: L 3,X'0A4'(,R2)
3A84: LA 3,X'0000'(R3)
3A88: CLI X'000'(R3),8
3A8C: BC 7,X'740'(,R12)
3A90: MVC X'000'(8,R5),X'000'(R3)
3A96: BCR R15,R13
3A98: XC X'000'(8,R5),X'000'(R5)
3A9E: MVC X'000'(4,R5),X'0A4'(R2)
3AA4: MVI X'000'(R5),8
3AA8: MVI X'004'(R5),64
3AAC: BCR R15,R13
3AAE: L 3,X'038'(,R2)
3AB2: L 5,X'000'(,R3)
3AB6: LA 5,X'0000'(R5)
3ABA: AH 5,X'006'(,R3)
3ABE: SH 5,X'00AA'(R2)
3AC2: ST 5,X'0078'(R2)
3AC6: MVC X'078'(1,R2),X'0C1'(R2)
3ACC: MVC X'07E'(2,R2),X'0AA'(R2)
3AD2: MVC X'07C'(2,R2),X'004'(R3)
3AD8: BCR R15,R13
3ADA: DC XL16'00000000000000000000000000000000'
3AEA: DC XL6'000000000000'
3AF0: MVI X'1DF'(R12),0
3AF4: TM X'003'(R1),16
3AF8: BC 1,X'01C'(,R12)
3AFC: TM X'01C'(R8),16
3B00: BC 1,X'01C'(,R12)
3B04: TM X'01C'(R8),7
3B08: BC 7,X'182'(,R12)
3B0C: SLL R10,X'0009'
3B10: TM X'003'(R1),8
3B14: BC 8,X'158'(,R12)
3B18: LH 6,X'0350'
3B1C: TM X'070'(R6),255
3B20: BC 8,X'0A8'(,R12)
3B24: BCR R4,R15
3B26: STM R1,R3,X'078'(,R6)
3B2A: STH 8,X'084'(,R6)
3B2E: TM X'07C'(R6),9
3B32: BC 1,X'06C'(,R12)
3B36: TM X'07C'(R6),3
3B3A: BC 4,X'054'(,R12)
3B3E: SR R10,R10
3B40: MVI X'083'(R6),1
3B44: MVC X'066'(2,R6),X'082'(R6)
3B4A: NI X'066'(R6),31
3B4E: SRL R3,X'0010'
3B52: SR R2,R2
3B54: D 2,X'064'(,R6)
3B58: STH 3,X'080'(,R6)
3B5C: NI X'07D'(R6),15
3B60: STH 4,X'076'(,R6)
3B64: SRL R5,X'0008'
3B68: STC 5,X'077'(,R6)
3B6C: SRL R5,X'0008'
3B70: STC 5,X'074'(,R6)
3B74: SRL R5,X'0008'
3B78: STC 5,X'073'(,R6)
3B7C: NI X'073'(R6),127
3B80: TM X'00C'(R8),16
3B84: BC 1,X'0A8'(,R12)
3B88: LH 9,X'012'(,R8)
3B8C: MVC X'012'(2,R9),X'073'(R6)
3B92: TR X'07C'(1,R6),X'1FA'(R12)
3B98: LM R1,R3,X'078'(,R6)
3B9C: LH 8,X'084'(,R6)
3BA0: L 14,X'004'(,R1)
3BA4: TM X'00C'(R8),16
3BA8: BC 8,X'0E4'(,R12)
3BAC: SRL R3,X'0010'
3BB0: STM R2,R3,X'030'(,R6)
3BB4: OI X'034'(R6),32
3BB8: MVI X'070'(R6),1
3BBC: LH 4,X'012'(,R8)
3BC0: MVC X'028'(1,R6),X'013'(R4)
3BC6: MVC X'02C'(4,R6),X'00C'(R6)
3BCC: LA 6,X'028'(,R6)
3BD0: BC 15,X'150'(,R12)
3BD4: LA 0,X'001E'
3BD8: CLI X'083'(R6),0
3BDC: BC 8,X'2CA'(,R11)
3BE0: CLI X'07C'(R6),29
3BE4: BC 8,X'0FC'(,R12)
3BE8: MVI X'070'(R6),1
3BEC: MVI X'004'(R6),0
3BF0: CLI X'07C'(R6),8
3BF4: BC 8,X'150'(,R12)
3BF8: MVI X'004'(R6),64
3BFC: TM X'07C'(R6),96
3C00: BC 8,X'188'(,R12)
3C04: L 4,X'20C'(,R12)
3C08: AR R4,R1
3C0A: ST 4,X'050'(,R6)
3C0E: MVI X'077'(R6),0
3C12: TM X'082'(R6),64
3C16: BC 8,X'12E'(,R12)
3C1A: OI X'050'(R6),128
3C1E: STM R2,R3,X'058'(,R6)
3C22: NC X'05C'(4,R6),X'04C'(R6)
3C28: MVI X'05C'(R6),64
3C2C: SRL R3,X'0010'
3C30: AH 2,X'05E'(,R6)
3C34: STM R2,R3,X'068'(,R6)
3C38: MVI X'068'(R6),6
3C3C: LA 6,X'038'(,R6)
3C40: AR R6,R10
3C42: ST 6,X'00A0'
3C46: BCR R15,R13
3C48: LR R0,R13
3C4A: AR R4,R10
3C4C: LH 12,X'1F8'(,R12)
3C50: BALR R13,R12
3C52: LH 12,X'01E'(,R13)
3C56: LR R13,R0
3C58: TM X'00C'(R8),16
3C5C: BC 8,X'182'(,R12)
3C60: LH 6,X'0350'
3C64: ST 4,X'030'(,R6)
3C68: MVI X'030'(R6),8
3C6C: BC 15,X'0CC'(,R12)
3C70: AER R15,R0
3C72: ST 4,X'00A0'
3C76: BCR R15,R13
3C78: LA 4,X'0004'
3C7C: CLI X'083'(R6),4
3C80: BC 2,X'198'(,R12)
3C84: IC 4,X'083'(,R6)
3C88: TM X'082'(R6),128
3C8C: BC 8,X'1A6'(,R12)
3C90: MVI X'1DF'(R12),32
3C94: SR R3,R3
3C96: CLI X'07C'(R6),14
3C9A: BC 8,X'1B2'(,R12)
3C9E: LA 4,X'0001'
3CA2: LA 5,X'018'(,R6)
3CA6: SRL R3,X'0010'
3CAA: CLI X'07C'(R6),29
3CAE: BC 7,X'1D6'(,R12)
3CB2: S 2,X'014'(,R6)
3CB6: A 3,X'014'(,R6)
3CBA: CLI X'070'(R6),0
3CBE: BC 8,X'1D6'(,R12)
3CC2: AI X'076'(R6),255
3CC6: STC 4,X'070'(,R6)
3CCA: STM R2,R3,X'000'(,R5)
3CCE: OI X'004'(R5),0
3CD2: BCTR R4,R0
3CD4: LTR R4,R4
3CD6: BC 8,X'150'(,R12)
3CDA: OI X'004'(R5),64
3CDE: AR R2,R3
3CE0: LA 5,X'008'(,R5)
3CE4: BC 15,X'1DA'(,R12)
3CE8: SUR R8,R0
3CEA: DC XL8'001D0E00000D0000'
3CF2: SSK R2,R9
3CF4: DC XL8'0000006900000000'
3CFC: LTR R0,R0
3CFE: DC XL2'0014'
3D00: BCR R0,R0
3D02: DER R7,R1
3D04: STH 0,X'0006'
3D08: LNER R0,R0
3D0A: DER R7,R3
3D0C: STD 0,X'0005'
3D10: SSK R0,R0
3D12: DER R0,R8
3D14: DC XL6'000000080000'
3D1A: DER R1,R8
3D1C: DC XL6'000000000000'
3D22: DER R2,R0
3D24: DC XL6'000000000000'
3D2A: DER R2,R8
3D2C: DC XL6'000000000000'
3D32: DER R3,R0
3D34: DC XL4'00000000'
3D38: BCR R0,R0
3D3A: DER R7,R1
3D3C: STH 0,X'0006'
3D40: LNER R0,R0
3D42: DER R7,R3
3D44: STD 0,X'0005'
3D48: SSK R0,R0
3D4A: DER R4,R0
3D4C: DC XL6'000001FF0000'
3D52: DER R5,R0
3D54: STD 0,X'0005'
3D58: DC XL2'0000'
3D5A: DER R5,R8
3D5C: DC XL4'00000000'
3D60: SSK R0,R0
3D62: DER R5,R0
3D64: DC XL6'000000000000'
3D6A: DER R6,R8
3D6C: DC XL16'00000000FF0000000000000000000000'
3D7C: DC XL12'000000000000000000000000'
3D88: STC 10,X'1EB'(,R12)
3D8C: STC 6,X'1ED'(,R12)
3D90: L 4,X'00C'(,R1)
3D94: AR R4,R7
3D96: TM X'003'(R1),16
3D9A: BC 1,X'15E'(,R12)
3D9E: TM X'01C'(R8),7
3DA2: BC 7,X'0B2'(,R12)
3DA6: TM X'003'(R1),8
3DAA: BC 8,X'032'(,R12)
3DAE: LH 9,X'0350'
3DB2: C 1,X'078'(,R9)
3DB6: BC 7,X'0A6'(,R12)
3DBA: TM X'006'(R8),114
3DBE: BC 7,X'0B2'(,R12)
3DC2: TM X'007'(R8),255
3DC6: BC 7,X'0B2'(,R12)
3DCA: TM X'003'(R1),8
3DCE: BC 1,X'0C6'(,R12)
3DD2: STH 0,X'1E8'(,R12)
3DD6: LR R0,R12
3DD8: LH 12,X'1E0'(,R12)
3DDC: BALR R13,R12
3DDE: LR R12,R0
3DE0: LH 0,X'1E8'(,R12)
3DE4: TM X'003'(R1),16
3DE8: BC 8,X'0A2'(,R12)
3DEC: BC 0,X'0A2'(,R12)
3DF0: MVI X'065'(R12),240
3DF4: TM X'01C'(R1),3
3DF8: BC 1,X'094'(,R12)
3DFC: TM X'01C'(R1),1
3E00: BC 1,X'08C'(,R12)
3E04: TM X'006'(R8),66
3E08: BC 8,X'0A2'(,R12)
3E0C: TM X'01C'(R1),2
3E10: BC 1,X'094'(,R12)
3E14: LA 4,X'1D0'(,R12)
3E18: BC 15,X'09A'(,R12)
3E1C: L 4,X'014'(,R1)
3E20: AR R4,R7
3E22: TM X'01C'(R8),2
3E26: BC 15,X'04A'(,R12)
3E2A: MVI X'065'(R12),0
3E2E: LH 10,X'1EA'(,R12)
3E32: LH 6,X'1EC'(,R12)
3E36: BC 15,X'36C'(,R11)
3E3A: LH 9,X'1E2'(,R12)
3E3E: TM X'00C'(R8),16
3E42: BC 8,X'0C2'(,R12)
3E46: LH 9,X'1E4'(,R12)
3E4A: LR R12,R9
3E4C: BCR R15,R12
3E4E: LH 6,X'0350'
3E52: LM R2,R3,X'07C'(,R6)
3E56: TM X'00C'(R8),16
3E5A: BC 8,X'0F4'(,R12)
3E5E: SR R9,R9
3E60: IC 9,X'083'(,R6)
3E64: BCTR R9,R0
3E66: LTR R9,R9
3E68: BC 8,X'104'(,R12)
3E6C: AH 2,X'080'(,R6)
3E70: ST 2,X'07C'(,R6)
3E74: STC 9,X'083'(,R6)
3E78: BC 15,X'13A'(,R12)
3E7C: CLI X'07C'(R6),8
3E80: BC 8,X'104'(,R12)
3E84: TM X'07C'(R6),96
3E88: BC 8,X'10E'(,R12)
3E8C: MVI X'070'(R6),255
3E90: SR R6,R6
3E92: BC 15,X'0A6'(,R12)
3E96: SR R9,R9
3E98: IC 9,X'070'(,R6)
3E9C: SR R10,R10
3E9E: IC 10,X'083'(,R6)
3EA2: EX 9,X'1DC'(,R12)
3EA6: AH 2,X'080'(,R6)
3EAA: BCTR R10,R0
3EAC: BCT 9,X'11E'(,R12)
3EB0: STC 9,X'070'(,R6)
3EB4: ST 2,X'07C'(,R6)
3EB8: STC 10,X'083'(,R6)
3EBC: LTR R10,R10
3EBE: BC 8,X'104'(,R12)
3EC2: TM X'003'(R1),16
3EC6: BC 14,X'152'(,R12)
3ECA: LA 0,X'0014'
3ECE: MVI X'004'(R1),0
* DIAG14
3ED2: DIAG X'0000',14
3ED6: STC 0,X'004'(,R1)
3EDA: IC 10,X'1EA'(,R12)
3EDE: LH 11,X'1E6'(,R12)
3EE2: BC 15,X'1AC'(,R11)
3EE6: TM X'01C'(R8),2
3EEA: BC 8,X'172'(,R12)
3EEE: NI X'01C'(R8),253
3EF2: TM X'01C'(R8),2
3EF6: BC 15,X'04A'(,R12)
3EFA: TM X'006'(R8),66
3EFE: BC 8,X'17E'(,R12)
3F02: OI X'01C'(R8),2
3F06: TM X'01C'(R1),3
3F0A: BC 14,X'194'(,R12)
3F0E: L 4,X'014'(,R1)
3F12: AR R4,R7
3F14: OI X'01C'(R8),2
3F18: BC 15,X'13A'(,R12)
3F1C: TM X'01C'(R1),1
3F20: BC 1,X'1AC'(,R12)
3F24: TM X'006'(R8),66
3F28: BC 8,X'04A'(,R12)
3F2C: TM X'01C'(R1),2
3F30: BC 1,X'186'(,R12)
3F34: ST 7,X'1D8'(,R12)
3F38: OI X'01C'(R8),2
3F3C: L 7,X'1CC'(,R12)
3F40: AR R7,R1
3F42: ST 7,X'1D0'(,R12)
3F46: LA 4,X'1D0'(,R12)
3F4A: L 7,X'1D8'(,R12)
3F4E: BC 15,X'13A'(,R12)
3F52: BCR R0,R0
3F54: SPM R0,R0
3F56: DC XL4'00140000'
3F5A: SUR R5,R8
3F5C: LDPR R0,R0
3F5E: DC XL6'000600000000'
3F64: AI X'076'(R6),0
3F68: SUR R8,R0
3F6A: LCER R5,R8
3F6C: LNER R13,R0
3F6E: BCT 3,X'0000'(R2)
3F72: DC XL14'0000000000010008000000000000'
3F80: STH 8,X'174'(,R12)
3F84: STH 10,X'176'(,R12)
3F88: STH 13,X'178'(,R12)
3F8C: LA 2,X'1A8'(,R12)
3F90: BC 7,X'018'(,R12)
3F94: LA 2,X'17A'(,R12)
3F98: MVI X'091'(R12),128
3F9C: MVI X'10F'(R12),128
3FA0: XC X'170'(4,R12),X'170'(R12)
3FA6: TM X'00C'(R8),16
3FAA: BC 8,X'032'(,R12)
3FAE: MVI X'091'(R12),240
3FB2: SR R6,R6
3FB4: SR R9,R9
3FB6: LR R3,R4
3FB8: L 5,X'0000'(R3)
3FBC: LA 13,X'068'(,R12)
3FC0: EX 0,X'002A'(R2)
3FC4: LA 5,X'0000'(R5)
3FC8: TM X'005'(R3),128
3FCC: EX 0,X'0000'(R2)
3FD0: EX 0,X'0004'(R2)
3FD4: MVC X'05F'(1,R12),X'000'(R3)
3FDA: ST 5,X'0000'(R3)
3FDE: MVI X'000'(R3),0
3FE2: EX 0,X'0022'(R2)
3FE6: BCR R15,R13
3FE8: CLI X'000'(R3),8
3FEC: BC 8,X'09E'(,R12)
3FF0: TM X'004'(R3),64
3FF4: BC 1,X'0E8'(,R12)
3FF8: LTR R6,R6
3FFA: BC 8,X'0EE'(,R12)
3FFE: TM X'005'(R6),64
4002: EX 0,X'0006'(R2)
4006: EX 0,X'000A'(R2)
400A: SR R6,R6
400C: TM X'000'(R10),96
4010: BC 8,X'10A'(,R12)
4014: LR R9,R3
4016: LA 3,X'0008'(R3)
401A: BC 15,X'038'(,R12)
401E: TM X'005'(R3),64
4022: EX 0,X'000E'(R2)
4026: CLR R3,R6
4028: BC 8,X'086'(,R12)
402C: CLR R3,R8
402E: BC 8,X'146'(,R12)
4032: LR R8,R6
4034: LR R6,R3
4036: LR R3,R5
4038: BC 15,X'038'(,R12)
403C: LTR R6,R6
403E: BC 7,X'100'(,R12)
4042: TM X'005'(R3),32
4046: EX 0,X'0012'(R2)
404A: LTR R9,R9
404C: BC 8,X'14E'(,R12)
4050: L 5,X'0000'(R9)
4054: LR R3,R9
4056: LA 13,X'0DE'(,R12)
405A: EX 0,X'0026'(R2)
405E: EX 0,X'0016'(R2)
4062: SR R9,R9
4064: BC 15,X'036'(,R12)
4068: LR R10,R3
406A: BC 15,X'096'(,R12)
406E: LTR R9,R9
4070: BC 8,X'14E'(,R12)
4074: TM X'005'(R9),32
4078: EX 0,X'001A'(R2)
407C: BC 15,X'0D0'(,R12)
4080: LR R10,R6
4082: S 10,X'16C'(,R12)
4086: BC 15,X'086'(,R12)
408A: TM X'00C'(R8),16
408E: BC 8,X'132'(,R12)
4092: TM X'003'(R1),16
4096: BC 1,X'132'(,R12)
409A: TM X'000'(R10),7
409E: BC 1,X'12A'(,R12)
40A2: TM X'000'(R10),12
40A6: BC 4,X'132'(,R12)
40AA: ST 10,X'170'(,R12)
40AE: MVI X'10F'(R12),240
40B2: L 5,X'0000'(R3)
40B6: LA 13,X'13E'(,R12)
40BA: EX 0,X'0026'(R2)
40BE: EX 0,X'001E'(R2)
40C2: BC 15,X'036'(,R12)
40C6: LR R6,R8
40C8: LR R3,R8
40CA: BC 15,X'100'(,R12)
40CE: LH 8,X'174'(,R12)
40D2: LH 10,X'176'(,R12)
40D6: LH 13,X'178'(,R12)
40DA: L 12,X'170'(,R12)
40DE: BCR R15,R13
40E0: CLI X'000'(R3),8
40E4: BCR R8,R13
40E6: BC 15,X'044'(,R12)
40EA: DC XL16'00000000000800000000000000000000'
40FA: BC 8,X'068'(,R12)
40FE: SR R5,R7
4100: BC 8,X'0EE'(,R12)
4104: NI X'005'(R6),191
4108: BC 8,X'0BC'(,R12)
410C: BC 1,X'08C'(,R12)
4110: NI X'005'(R9),223
4114: BC 8,X'036'(,R12)
4118: NI X'005'(R3),223
411C: NI X'005'(R3),127
4120: BC 15,X'044'(,R12)
4124: BC 15,X'160'(,R12)
4128: BC 1,X'068'(,R12)
412C: AR R5,R7
412E: BC 1,X'0EE'(,R12)
4132: OI X'005'(R6),64
4136: BC 1,X'0BC'(,R12)
413A: BC 8,X'08C'(,R12)
413E: OI X'005'(R9),32
4142: BC 1,X'036'(,R12)
4146: OI X'005'(R3),32
414A: OI X'005'(R3),128
414E: BC 15,X'0000'
4152: BC 15,X'044'(,R12)
4156: DC XL2'0000'
* FIND DEVICE CONTROL TABLE FOR CHANNEL & DEVICE # IN R2
USING *,R12
4158: LM R7,R8,SB$PBC GET # PUBS AND ADDR OF FIRST
415C: LA 9,X'004'(,R13)
4160: LH 6,IP$CA(,R8) GET CHANNEL & DEVICE ADDRESS
4164: TM IP$CONT2(R8),BP$COCHN
4168: BZ X'4170'
416C: LH 6,IP$CCA(,R8) GET CO CHANNEL ADDRESS
4170: EX 0,X'000'(,R13)
4174: BCR 9,R9
4176: LA 8,X'020'(,R8) BUMP TO NEXT PUB
417A: BCT 7,X'008'(,R12) & LOOP
417E: LTR R9,R9
4180: BCR R15,R9
4182: DC XL6'000000000000'
* COPY CURRENT IOSTIW TO X'41E8' AND UPDATE IOSTIW TABLE POINTERS
USING *,R12
4188: XC X'060'(12,R12),X'060'(R12) CLEAR IOSTIW BUFFER
418E: CLI X'001B',0 ANY IOST ERRORS?
4192: BC 8,X'419C' NO
4196: LH 12,X'04C'(,R12)
419A: BALR R13,R12
419C: LM R1,R4,X'050'(,R12)
41A0: LR R0,R1
* R2 POINTS TO NEXT IOSTIW
* R3 POINTS TO START OF IOSTIW TABLE
* R4 POINTS TO END OF IOSTIW TABLE
41A2: TM X'000'(R2),128 IOSTIW EMPTY?
41A6: BCR R7,R13 YES
41A8: MVC X'000'(4,R1),X'000'(R2) COPY 1ST WORD OF STATUS TO 41E8
41AE: OI X'000'(R2),128 RESET IOSTIW IN USE FLAG
41B2: LA 2,X'0004'(R2) BUMP TO NEXT IOSTIW
41B6: CLR R2,R4 END OF TABLE
41B8: BC 7,X'036'(,R12) NO
41BC: LR R2,R3 YES, WRAP TO START OF TABLE
41BE: ST 2,X'054'(,R12)
41C2: TM X'000'(R1),64 IOSTIW CONTINUED?
41C6: BCR R8,R13 NO
41C8: NI X'000'(R1),191 RESET CONTINUED BIT
41CC: LA 1,X'004'(,R1) BUMP TO NEXT BUFFER ENTRY
41D0: BC 15,X'01A'(,R12) LOOP -> 41A2
41D4: LA 15,X'0700'(R8)
41D8: DC XL2'0000'
41DA: LA 14,X'0000'(R8)
41DE: CLR R8,R12
41E0: DC XL2'0000'
41E2: CLR R8,R12
41E4: DC XL2'0000'
41E6: OR R5,R12
* IOSTIW BUFFER
41E8: DC XL16'00000000000000000000000000000000'
41F8: HPR X'0007',7
41FC: BC 15,X'000'(,R12)
4200: AI X'000'(R1),1
4204: MVI X'131'(R13),0
4208: TM X'003'(R1),2
420C: BC 1,X'014'(,R13)
4210: OI X'018'(R8),4
4214: MVI X'004'(R1),0
4218: LA 4,X'0014'
421C: LR R5,R1
* DIAG14
421E: DIAG X'000'(R4),14
4222: STC 4,X'004'(,R1)
4226: L 4,X'00C'(,R1)
422A: AR R4,R7
422C: SR R6,R6
422E: TM X'003'(R1),8
4232: BC 8,X'042'(,R13)
4236: TM X'002'(R8),4
423A: BC 8,X'042'(,R13)
423E: LH 6,X'0350'
4242: STH 6,X'188'(,R13)
4246: SR R6,R6
4248: IC 6,X'007'(,R9)
424C: TM X'003'(R1),128
4250: BC 8,X'05C'(,R13)
4254: TM X'003'(R1),4
4258: BC 8,X'0B0'(,R13)
425C: LH 5,X'004'(,R9)
4260: MVC X'18A'(3,R13),X'000'(R9)
4266: TM X'007'(R8),255
426A: BC 7,X'092'(,R13)
426E: NC X'014'(3,R1),X'014'(R1)
4274: BC 8,X'092'(,R13)
4278: NC X'18A'(3,R13),X'014'(R1)
427E: BC 7,X'08A'(,R13)
4282: LA 9,X'008'(,R9)
4286: BC 15,X'048'(,R13)
428A: CLC X'001'(1,R1),X'006'(R9)
4290: BCR R13,R5
4292: LH 5,X'188'(,R13)
4296: MVC X'008'(1,R8),X'003'(R9)
429C: TM X'003'(R1),4
42A0: BC 8,X'0C6'(,R13)
42A4: TM X'003'(R1),128
42A8: BC 8,X'0C2'(,R13)
42AC: NI X'018'(R8),251
42B0: LH 5,X'188'(,R13)
42B4: LTR R5,R5
42B6: BC 8,X'36C'(,R11)
42BA: MVI X'070'(R5),255
42BE: BC 15,X'36C'(,R11)
42C2: NI X'008'(R8),252
42C6: CH 8,X'02A8' SB$RES?
42CA: BC 7,X'0EA'(,R13)
42CE: TM X'034C',64
42D2: BC 8,X'0DE'(,R13)
42D6: MVI X'131'(R13),128
42DA: BC 15,X'0E4'(,R13)
42DE: MVC X'034C'(4),X'008'(R8)
42E4: XC X'008'(4,R8),X'008'(R8)
42EA: LTR R5,R5
42EC: BC 8,X'0F4'(,R13)
42F0: MVI X'070'(R5),255
42F4: LH 12,SB$RELOC
42F8: BALR R13,R12 LOAD R7 WITH RELOCATION REG.
42FA: BALR R12,R0
42FC: OI X'02F4',64
4300: L 9,X'02D0'
4304: NI X'005'(R9),247
4308: BALR R12,R0
430A: STH 10,X'07C'(,R12)
430E: TM X'002'(R8),4
4312: BC 8,X'020'(,R12)
4316: TM X'003'(R1),8
431A: BC 1,X'020'(,R12)
431E: L 4,X'00C'(,R1)
4322: AR R4,R7
4324: LH 12,X'07A'(,R12)
4328: BALR R13,R12
432A: BALR R12,R0
432C: LH 10,X'05A'(,R12)
4330: TM X'005'(R12),0
4334: BC 1,X'00E'(,R12)
4338: OR R12,R12
433A: LH 12,X'02EA'
433E: BALR R13,R12
*
4340: BALR R12,R0
4342: STH 8,X'438A' SAVE PUB ADDR.
4346: MVC X'4351'(1),X'002'(R8) MODIFY INST @ 435 WITH CHAN #
434C: LH 8,X'02A8' GET PTR TO SYSRES PUB
4350: CLI IP$CA(R8),0 SYSRES ON CURRENT CHANNEL?
4354: BNE X'4378' NO
4358: NC X'008'(4,R8),X'008'(R8)
435E: BCR R7,R15
4360: LH 13,X'010'(,R8)
4364: L 13,X'000'(,R13)
4368: CLC X'02D1'(3),X'005'(R13)
436E: BC 8,X'2B2'(,R11)
4372: CH 8,X'048'(,R12)
4376: BCR R8,R15
4378: LH 8,X'438A' RESTORE PUB ADDR
437C: LH 11,X'038C' GET EXCP ADDR.
4380: BC 15,X'1A2'(,R11)
4384: SUR R8,R0
4386: DC XL10'00000000000000000000'
* I/O QUEUE PROCESSING
USING *,R12
USING IP$PUB,R8
USING IC$CCB,R1
4390: LH 6,IP$QUE(,R8) GET QUEUE ADDR?
4394: LH 10,X'4618' R10 = 0?
4398: IC 10,JT$KEY GET JOB #
439C: SRL R10,X'0002'
43A0: LA 1,X'000'(,R1)
43A4: BC 4,X'4476' COND CODE = 1
43A8: BC 8,X'453A' COND CODE = 0
43AC: MVC X'4451'(1),X'000'(R6) SAVE 1ST BYTE OF QUEUE TO BE RESTORED LATER
43B2: AR R6,R10 R6 = R6 + (JOB # * 4)
43B4: LR R9,R6 TO R9
43B6: SH 9,X'4622' SUBTRACT 8???
43BA: MVI X'4419',128 MAKE BRANCH A BRANCH EQUAL
43BE: MVI X'4539',240 MAKE BRANCH UNCONDITIONAL
43C2: LR R2,R9 QUEUE ADDR - 8 TO R2
43C4: MVI X'008'(R9),0 CLEAR 1ST BYTE OF QUEUE
43C8: L 9,X'008'(,R9) GET PTR TO HEAD OF QUEUE
43CC: CR R1,R9 QUEUE HEAD = CRNT CCB?
43CE: BC 8,X'444C' YES
43D2: XC IC$RBC(4),IC$RBC CLEAR LINK TO NEXT CCB
43D8: LTR R9,R9 HEAD OF QUEUE <= 0?
43DA: BNP X'4422' YES
43DE: L 4,IC$BCW(,R9) GET PTR TO TCB
43E2: CLC JT$QID(1),JT$QID(R4) CRNT QID <= QID
43E8: BNH X'4466' YES
43EC: L 5,IC$PIO(,R9) GET PTR TO PUB
43F0: SR R3,R3 CLEAR R3
43F2: IC 3,JT$PSW+1(,R4) KEY KEY FROM OLD PSW
43F6: TM JT$FLGS(R4),BT$PSWSV ORIG. PSW SAVED?
43FA: BZ X'4402' YES
43FE: IC 3,JT$PSWS+1(,R4) GET KEY FROM SAVED PSW
4402: SRL R3,X'0004' ISOLATE KEY
4406: SLL R3,X'0002' KEY = KEY * 4
440A: L 3,X'00B0'(R3) GET REL. REG. FOR KEY
440E: LH 5,X'000'(R5,R3) ADD NEW CCB TO CHAIN
4412: CLC X'009'(3,R5),X'009'(R2)
4418: BC 8,X'0C6'(,R12)
441C: MVC X'009'(3,R1),X'009'(R2)
4422: ST 1,X'008'(,R2) SAVE CRNT CCB TO QUEUE
4426: MVI IC$BCW,0 CLEAR FLAG
* DIAG14
442A: LA 0,X'0014'
442E: DIAG X'0000',14
4432: STC 0,IC$BCW
4436: LR R1,R2
4438: BC 15,X'444C'
443C: MVI X'004'(R1),0
4440: LA 0,X'0014'
* DIAG14
4444: DIAG X'0000',14
4448: STC 0,X'004'(,R1)
444C: LH 6,IP$QUE GET THE QUE ADDR FROM PUB
4450: OI X'000'(R6),0 RESTORE BITS SAVED @ 43AC
4454: BCR R15,R13 RETURN
*
4456: MVI X'089'(R12),0
445A: TM X'008'(R5),112
445E: BC 1,X'08C'(,R12)
4462: BC 15,X'0DE'(,R12)
4466: TM X'008'(R8),112
446A: BC 1,X'05C'(,R12)
446E: MVI X'0A9'(R12),0
4472: BC 15,X'032'(,R12)
*
4476: AR R6,R10
4478: L 9,X'0000'(R6)
447C: LA 9,X'000'(,R9)
4480: CLR R9,R1
4482: BC 7,X'0FC'(,R12)
4486: MVC X'001'(3,R6),X'009'(R9)
448C: C 0,X'288'(,R12)
4490: BCR R4,R13
4492: LR R9,R0
4494: LM R9,R10,X'004'(,R9)
4498: TM X'002'(R8),4
449C: BC 8,X'11A'(,R12)
44A0: TM X'003'(R1),8
44A4: BC 1,X'11A'(,R12)
44A8: SR R9,R7
44AA: CH 8,X'02A8' SB$RES?
44AE: BC 7,X'12A'(,R12)
44B2: TM X'034C',64
44B6: BC 1,X'132'(,R12)
44BA: TM X'008'(R8),64
44BE: BC 8,X'168'(,R12)
44C2: SLL R10,X'0012'
44C6: OR R10,R9
44C8: LR R9,R14
44CA: STM R9,R10,X'004'(,R1)
44CE: MVI X'004'(R1),0
44D2: LA 2,X'0014'
44D6: LR R3,R1
* DIAG14
44D8: DIAG X'000'(R2),14
44DC: STC 2,X'004'(,R1)
44E0: TM X'018'(R8),12
44E4: BCR R14,R13
44E6: L 2,X'02D0'
44EA: NI X'005'(R2),247
44EE: OI X'02F5',64
44F2: NI X'008'(R8),127
44F6: BCR R15,R13
44F8: TM X'002'(R8),4
44FC: BC 8,X'19C'(,R12)
4500: TM X'003'(R1),8
4504: BC 1,X'19C'(,R12)
4508: L 4,X'00C'(,R1)
450C: AR R4,R7
450E: STH 13,X'28C'(,R12)
4512: SR R13,R13
4514: LH 12,X'28E'(,R12)
4518: BALR R13,R12
451A: BALR R12,R0
451C: LH 13,X'100'(,R12)
4520: LR R9,R0
4522: LM R9,R10,X'004'(,R9)
4526: SR R9,R7
4528: LH 12,X'104'(,R12)
452C: TM X'018'(R8),12
4530: BC 1,X'132'(,R12)
4534: STM R9,R10,X'004'(,R1)
4538: BCR R15,R13
*
453A: TM X'000'(R6),128 1ST BYTE OF QUEUE PTR = X'80'?
453E: BOR R15 YES, RETURN
4540: LA 3,X'020'(,R6)
4544: L 5,X'000'(,R3)
4548: LA 6,X'004'(,R5)
454C: LA 5,X'0009' INIT. LOOP COUNT.
4550: MVI X'45B3',0 MAKE BRANCH A NO-OP
4554: SR R9,R9
4556: CLR R6,R3 END OF TABLE?
4558: BL X'4560' NO
455C: LH 6,X'010'(,R8)
4560: BCT 5,X'45E4' DEC. LOOP COUNT & JUMP
4564: LTR R1,R9 PTR TO CCB TO R1
4566: BCR R8,R15 IF ZERO, RETURN
4568: MVI X'223'(R12),240
456C: OI SB$ERFLG,BB$TCB? SET TCB QUESTIONABLE
4570: NI SB$ERFLG,191 CLEAR CCB QUESTIONABLE
* DIAG14
*
* THIS DIAG MUST RETURN COND CODE = 0 OR WE REMOVE CCB FROM QUEUE.
4574: LA 0,X'0014'
4578: DIAG X'0000',14
457C: BC 8,X'4598'
4580: XC X'000'(4,R6),X'000'(R6) CLEAR QUEUE HEAD
4586: SH 6,X'010'(,R8)
458A: BC 8,X'4592'
458E: L 1,X'0B0'(,R6)
4592: LH 11,X'296'(,R12)
4596: BCR R15,R11
4598: NI SB$ERFLG,223 CLEAR TCB QUESTIONABLE BIT.
459C: L 14,IC$BCW GET PTR TO TCB
45A0: L 8,IC$PIO GET PTR TO PTR TO PUB
45A4: LR R0,R12 SAVE R12
45A6: LH 12,SB$RELOC LOAD R7 WITH RELOCATION REG.
45AA: BALR R13,R12
45AC: LR R12,R0 RESTORE R12
45AE: LH 8,X'000'(R8,R7) GET PTR TO PUB
45B2: BC 0,X'266'(,R12)
45B6: OC IP$CCB(4),IP$CCB PUB CCB ADDR = 0?
45BC: BNZ X'45EE' NO
45C0: LTR R9,R9 R9 = 0
45C2: BNZ X'45CC' NO
45C6: ST 6,X'000'(,R3)
45CA: LR R9,R1 GET PTR TO CCB
45CC: L 4,X'004'(,R9) GET PTR TO TCB
45D0: CLC JT$QID(1,R4),JT$QID NEW TCB <= CRNT TCB QID?
45D6: BNH X'45EE' YES
45DA: LR R9,R1
45DC: ST 6,X'000'(,R3)
45E0: BC 15,X'25E'(,R12)
*
45E4: L 1,X'000'(,R6) GET PTR TO QUEUE HEAD
45E8: LTR R1,R1 IS IT > 0?
45EA: BP X'456C' YES
45EE: LA 6,X'004'(,R6) BUMP TO NEXT QUEUE
45F2: BC 15,X'4556' & LOOP
*
45F6: NI X'018'(R8),252 CLEAR SEEK SEPARATED & ECC RECOVERY ACTOVE
45FA: L 4,X'00C'(,R1)
45FE: AR R4,R7
4600: TM X'002'(R8),4
4604: BC 8,X'280'(,R12)
4608: TM X'003'(R1),8
460C: BC 8,X'1AC'(,R11)
4610: LM R2,R5,X'000'(,R4)
4614: BC 15,X'1AC'(,R11)
4618: DC XL6'000000200000'
461E: SUR R8,R0
4620: IC 9,X'0008'
4624: BASR R12,R8
4626: BAS 8,X'58C'(R4,R1)
462A: DC XL6'000000000000'
* SVC 0 - EXCP - EXECUTE CHANNEL PROGRAM
4630: BALR R11,R0
USING *,R11
USING IC$CCB,R1
USING JT$TCB,R14
USING IP$PUB,R8
4632: OI SB$ERFLG,BB$IO+BB$CCB? SET PIOCS IN CTRL & CCB QUESTIONABLE
4636: LH 4,SB$SLA GET SWITCH LIST ADDR
463A: SR R2,R2 CLEAR R2
463C: L 3,JT$LNK GET PTR TO NEXT TCB
4640: IC 2,JT$QID GET QUEUE ID (I/O?)
4644: LA 3,X'000'(,R3)
4648: CLI JT$QID,16 QUEUE ID < 16?
464C: BL X'4654' YES
4650: ST 3,X'000'(R4,R2)
4654: AR R1,R12 CALC ABS ADDR OF CCB
4656: TM IC$T+1,BC$DIAG DIAGNOSTIC CCB?
465A: BZ X'4670' NO
465E: XC X'01A'(2,R1),X'01A'(R1)
4664: MVI X'027'(R1),0
4668: OI X'002'(R1),128
466C: BC 15,X'044'(,R11)
4670: XC IC$SB(8),IC$SB CLEAR SENSE AND STATUS BYTES
4676: TM IC$T+1,BC$DIAG DIAGNOSTIC CCB?
467A: BZ X'478E' NO
467E: STM R1,R6,X'142'(,R11)
4682: L 2,X'010'(,R1)
4686: AR R2,R12
4688: SH 2,X'15A'(,R11)
468C: LR R3,R2
468E: TM X'008'(R3),128 JT$QID OF NEXT TCB
4692: BO X'15C'(,R11)
4696: TM X'008'(R3),32
469A: BC 8,X'074'(,R11)
469E: LH 5,X'0002'(R2)
46A2: BC 15,X'0D8'(,R11)
46A6: MVC X'014'(2,R1),X'002'(R3)
46AC: TM X'014'(R1),240
46B0: BC 1,X'088'(,R11)
46B4: TR X'014'(1,R1),X'235'(R11)
46BA: TM X'015'(R1),240
46BE: BC 1,X'096'(,R11)
46C2: TR X'015'(1,R1),X'235'(R11)
46C8: PACK X'017'(2,R1),X'014'(3,R1)
46CE: LM R4,R5,X'02C8'
46D2: CLC X'017'(1,R1),X'003'(R5)
46D8: BC 7,X'0C6'(,R11)
46DC: NI X'001'(R3),15
46E0: CLC X'001'(1,R3),X'002'(R5)
46E6: BC 8,X'0D8'(,R11)
46EA: CLC X'001'(1,R3),X'000'(R5)
46F0: BC 8,X'0D8'(,R11)
46F4: OI X'001'(R3),240
46F8: LA 5,X'0020'(R5)
46FC: BCT 4,X'0A0'(,R11)
4700: MVI X'002'(R1),196
4704: LM R1,R6,X'142'(,R11)
4708: BCR R15,R15
470A: LA 0,X'0001'
470E: PACK X'0E9'(1,R11),X'000'(1,R14)
4714: NI X'0E9'(R11),15
4718: SLL R0,X'0000'
471C: STC 0,X'0EF'(,R11)
4720: TM X'004'(R5),0
4724: BC 1,X'102'(,R11)
4728: TM X'01C'(R5),32
472C: BC 14,X'0CE'(,R11)
4730: OI X'01C'(R5),16
4734: MVC X'010'(32,R3),X'000'(R5)
473A: MVC X'017'(1,R3),X'01C'(R5)
4740: OI X'001'(R3),240
4744: MVC X'008'(4,R2),X'00C'(R5)
474A: STH 5,X'000E'(R3)
474E: LH 5,X'012'(,R5)
4752: MVC X'02C'(20,R3),X'000'(R5)
4758: NI X'008'(R3),95
475C: TM X'008'(R2),4
4760: BC 14,X'138'(,R11)
4764: XC X'000'(8,R5),X'000'(R5)
476A: XC X'014'(4,R1),X'014'(R1)
4770: BC 15,X'0D2'(,R11)
4774: DC XL16'00000000000000000000000000000000'
4784: DC XL10'0000000000000000000E'
*
478E: NI IC$CTL,251 CLEAR WAIT FLAG
4792: XC IC$EC(2),IC$EC CLEAR ERROR COUNT AND TRANSMISSION BYTE
4798: ST 14,IC$BCW SAVE PTR TO TCB IN CCB
479C: NI SB$ERFLG,191 CLEAR CCB QUESTIONABLE FLAG
47A0: TM IP$CONT2,BP$TEST TESTING?
47A4: BNO X'47B8' NO
47A8: TM X'003'(R1),16
47AC: BC 1,X'186'(,R11)
47B0: LA 0,X'0010'
47B4: BC 15,X'2C6'(,R11)
47B8: LH 12,SB$RELOC
47BC: BALR R13,R12 LOAD R7 WITH RELOCATION REG.
47BE: LH R12,SB$TLOCK LOCK FLAG SET?
47C2: LTR R12,R12
47C4: BZ X'47CA' NO
47C8: BALR R13,R12
47CA: AI JT$IOC,1 BUMP OUTSTANDING I/O COUNT
47CE: LH 12,SB$IOQ GET ADDR OR ADD TO QUEUE RTN
47D2: BALR R13,R12
*
47D4: SR R10,R10 SET COND CODE = 0
47D6: LH 12,SB$IOQ GET ADDR OF I/O QUEUE RTN
47DA: BALR R13,R12
47DC: BCR R8,R15
47DE: AR R2,R7 ADD RELOCATION REGISTER TO SENSE BYTE ADDR
47E0: SLL R10,X'0012'
47E4: AR R2,R10
47E6: TM X'00C'(R8),16 CHECK DEVICE TYPE
47EA: BC 8,X'47FC'
47EE: LH 12,X'037C'
47F2: TM X'02B5',1
47F6: BC 8,X'1CA'(,R11)
47FA: BALR R13,R12
47FC: LH 12,IP$EPS(,R8) GET ADDR OF CHANNEL SCHEDULER
4800: BALR R13,R12
4802: BCR R0,R0
4804: XC IP$CONT1(2,R8),IP$CONT1(R8) CLEAR STATUS
480A: XC IP$CCB(4,R8),IP$CCB(R8) CLEAR CCB ADDR
4810: LH 9,IP$CA(,R8) GET CHANNEL AND DEVICE ADDR
4814: SIO X'000'(R9),0
4818: BALR R13,R0 GET ADDR NEXT INST.
481A: SRL R13,X'0004' R13 = R3 / 16
481E: ST 13,X'4784' SAVE IT
4822: TM IC$T+1(R1),BC$DIAG DIAGNOSTIC CCB?
4826: BC 8,X'4840' NO
482A: TM X'01C'(R8),2
482E: BC 8,X'204'(,R11)
4832: BC 15,X'20E'(,R11)
4836: MVC X'01E'(1,R1),X'152'(R11)
483C: NI X'01E'(R1),3
4840: L 13,X'4784' RESTORE R13
4844: SLL R13,X'0004' R13 = R13 * 16
4848: SPM R13,R0
484A: BALR R0,R0
484C: BC 8,X'222'(,R11)
4850: NI X'01C'(R8),250
4854: SPM R0,R0
4856: TM X'002'(R8),4
485A: BC 8,X'248'(,R11)
485E: TM X'003'(R1),8
4862: BC 8,X'248'(,R11)
4866: SPM R0,R0
4868: BC 8,X'248'(,R11)
486C: LH 9,X'0350'
4870: MVI X'070'(R9),255
4874: SPM R0,R0
4876: BC 1,X'262'(,R11)
487A: SPM R0,R0
487C: BC 13,X'262'(,R11)
4880: TM X'002'(R8),4
4884: BC 8,X'27A'(,R11)
4888: TM X'00C'(R8),32
488C: BC 8,X'27A'(,R11)
4890: BC 15,X'272'(,R11)
4894: ST 1,X'008'(,R8)
4898: BC 4,X'2DA'(,R11)
489C: BC 1,X'2D2'(,R11)
48A0: OI X'008'(R8),128
48A4: LH 9,X'010'(,R8)
48A8: OI X'000'(R9),128
48AC: CLI X'00C'(R8),0
48B0: BCR R8,R15
48B2: MVI X'01B'(R8),2
48B6: LH 12,SB$RELOC LOAD R7 WITH RELOCATION REG.
48BA: BALR R13,R12
48BC: TM IP$TYP(R8),16 CHECK DEVICE TYPE
48C0: BZ X'48D6'
48C4: L 9,X'00C'(,R1)
48C8: AR R9,R7
48CA: TM X'000'(R9),47
48CE: BC 14,X'2A4'(,R11)
48D2: MVI X'01B'(R8),120
48D6: TM X'00C'(R8),10 CHECK DEVICE TYPE
48DA: BZ X'48EA'
48DE: TM X'00D'(R8),2
48E2: BC 8,X'2B8'(,R11)
48E6: MVI X'01B'(R8),12
48EA: SPM R0,R0
48EC: BCR R8,R15
48EE: LTR R8,R8
48F0: LH 12,X'02EA'
48F4: BALR R13,R12
48F6: BCR R15,R15
48F8: AI X'00C'(R14),1
48FC: LH 11,X'038E'
4900: BC 15,X'36C'(,R11)
4904: LH 11,X'038E'
4908: BC 15,X'2BA'(,R11)
490C: LH 12,X'038E'
4910: STH 8,X'684'(,R12)
4914: TM X'003'(R1),16
4918: BCR R1,R15
491A: NI X'018'(R8),251
491E: XC X'014'(3,R1),X'014'(R1)
4924: BC 15,X'272'(,R11)
4928: AP X'CFD'(16,R15),X'EFF'(12,R15)
492E: DC XL2'0000'
* IOST INTERRUPT HANDLER
4930: MVC X'024'(4,R14),X'0024' SAVE WORD 1 OF OLD PSW TO TCB
4936: OI SB$ERFLG,BB$IO+BB$TCB?
493A: BALR R11,R0
USING *,R11
493C: LH R12,X'690'(,R11)
4940: BALR R13,R12 GET CURRENT IOSTIW
4942: LH R15,X'0008' GET POINTER TO SWITCHER
4946: BCR 7,R15 NO CURRENT IOSTIW? GOTO SWITCHER
4948: LH R15,X'4FD0'
494C: L R12,SB$CHINT MCP CPIOCS ENTRY ADDR
4950: LTR R12,R12 IS IT ZERO?
4952: BZ X'4958' YES
4956: BALR R13,R12 NO, LET ICAM TRY TO PROCESS IT.
4958: LTR R0,R0 GET ADDR OF IOSTIW BUFFER
495A: BZR R15 ZERO, GO TO SWITCHER
495C: LR R1,R0
495E: LH 2,X'000'(,R1) GET CHANNEL & DEVICE #S
4962: LH 12,SB$PCOV GET ADDR PUB CONTROL COVER
4966: BALR R13,R12
4968: CLR R2,R6
496A: BCR R0,R0
*
496C: BCR R7,R15
496E: CLI X'002'(R8),3 CHANNEL # = 3?
4972: BC 7,X'4986' NO
4976: TM X'002'(R1),12 DEVICE END/CHANNEL END?
497A: BC 11,X'4986' ALL ZERO OR ALL ONE
497E: CLI X'00F0',8
4982: BC 7,X'06E'(,R11)
4986: TM IP$TYP(R8),16 CHECK DEVICE TYPE
498A: BZ X'49A2'
498E: TM X'01D'(R8),64
4992: BC 8,X'066'(,R11)
4996: EX 0,X'3E2'(,R11)
499A: NI X'01D'(R8),191
499E: BC 15,X'294'(,R11)
49A2: LH 2,IP$QUE(,R8) GET THE QUEUE ADDRESS
49A6: NI X'000'(R2),127
49AA: MVC IP$CONT1(2,R8),X'002'(R1) COPY STATUS TO PUB
49B0: L 1,IP$CCB(,R8) GET THE CCB ADDRESS
49B4: LTR R1,R1 = 0?
49B6: BZ X'4EE6' YES
49BA: TM IP$CCB(R8),112
49BE: BMR R15
49C0: L 14,IC$BCW(,R1) GET THE TCB ADDRESS
* I DON'T KNOW WHAT THIS IS SUPPOSED TO BE DOING
49C4: LA 2,X'0014'
49C8: LA 3,X'000'(,R1)
* DIAG14
49CC: DIAG X'000'(R2),14
49D0: BC 7,X'4DDC'
*
49D4: TM IC$T+1(R1),BC$DIAG DIAGNOSTIC CCB?
49D8: BZ X'4AAE' NO
49DC: TM X'006'(R8),66
49E0: BC 7,X'0B0'(,R11)
49E4: TM X'006'(R8),7
49E8: BC 8,X'172'(,R11)
49EC: TM X'01C'(R8),2
49F0: BC 8,X'0BC'(,R11)
49F4: BC 15,X'11A'(,R11)
49F8: CLI X'002'(R8),1
49FC: BC 2,X'0F8'(,R11)
4A00: SR R13,R13
4A02: IC 13,X'003'(,R8)
4A06: CLI X'002'(R8),1
4A0A: BC 4,X'0EC'(,R11)
4A0E: LA 13,X'200'(,R13)
4A12: N 13,X'0E8'(,R11)
4A16: MVC X'688'(8,R11),X'000'(R13)
4A1C: NI X'68E'(R11),31
4A20: BC 15,X'100'(,R11)
4A24: DC XL4'00000FF0'
4A28: SLL R13,X'0004'
4A2C: LA 13,X'100'(,R13)
4A30: BC 15,X'0DA'(,R11)
4A34: LR R13,R0
4A36: MVC X'688'(8,R11),X'004'(R13)
4A3C: L 14,X'004'(,R1)
4A40: LH 12,SB$RELOC
4A44: BALR R13,R12 LOAD R7 WITH RELOCATION REG.
4A46: L 13,X'688'(,R11)
4A4A: SR R13,R7
4A4C: ST 13,X'688'(,R11)
4A50: MVC X'01F'(8,R1),X'688'(R11)
4A56: TM X'006'(R8),66
4A5A: BC 8,X'172'(,R11)
4A5E: TM X'01C'(R8),2
4A62: BC 8,X'172'(,R11)
4A66: MVI X'027'(R1),142
4A6A: LR R13,R0
4A6C: MVC X'001'(2,R1),X'002'(R13)
4A72: MVI X'004'(R1),0
4A76: LA 2,X'0014'
4A7A: LR R3,R1
4A7C: DIAG X'000'(R2),14
4A80: STC 2,X'004'(,R1)
4A84: CLI X'002'(R8),4
4A88: BC 8,X'172'(,R11)
4A8C: CLI X'002'(R8),6
4A90: BC 8,X'172'(,R11)
4A94: BC 15,X'36C'(,R11)
4A98: L 2,X'004'(,R1)
4A9C: MVC X'004'(4,R1),X'00C'(R1)
4AA2: ST 2,X'00C'(,R1)
4AA6: L 2,X'004'(,R1)
4AAA: BC 15,X'280'(,R11)
4AAE: LH 12,SB$RELOC LOAD R7 WITH RELOCATION REG.
4AB2: BALR R13,R12
4AB4: TM IC$T+1(R1),BC$DIAG DIAGNOSTIC CCB?
4AB8: BZ X'4AC2' NO
4ABC: TM X'006'(R8),215
4AC0: BCR R8,R15
4AC2: TM IP$CONT1(R8),247 TEST ALL BUT CHANNEL END
4AC6: BM X'4C22' SOME ARE SET
4ACA: TM X'007'(R8),255
4ACE: BC 7,X'2E6'(,R11)
4AD2: TM X'003'(R1),16
4AD6: BC 14,X'1A8'(,R11)
4ADA: TM X'01C'(R8),5
4ADE: BCR R7,R15
4AE0: BC 15,X'1A8'(,R11)
4AE4: STH 0,X'21E'(,R11)
4AE8: SR R0,R0
4AEA: CLI X'006'(R8),0
4AEE: BC 7,X'1CA'(,R11)
4AF2: MVI X'006'(R8),32
4AF6: OI X'01C'(R8),2
4AFA: LH 12,X'02EA'
4AFE: LTR R12,R12
4B00: BALR R13,R12
4B02: BC 15,X'596'(,R11)
4B06: TM X'01C'(R8),7
4B0A: BCR R7,R15
4B0C: NI X'018'(R8),251
4B10: TM X'00C'(R8),16
4B14: BC 8,X'220'(,R11)
4B18: TM X'00D'(R8),127
4B1C: BC 8,X'220'(,R11)
4B20: CLI X'002'(R8),1
4B24: BC 7,X'1FA'(,R11)
4B28: MVZ X'1F5'(1,R11),X'003'(R8)
4B2E: LA 3,X'0200'
4B32: BC 15,X'206'(,R11)
4B36: LH 3,X'21E'(,R11)
4B3A: L 3,X'004'(,R3)
4B3E: S 3,X'698'(,R11)
4B42: CLI X'000'(R3),7
4B46: BC 7,X'220'(,R11)
4B4A: LH 0,X'21E'(,R11)
4B4E: OI X'006'(R8),4
4B52: OI X'01D'(R8),64
4B56: BC 15,X'2E6'(,R11)
4B5A: DC XL2'0000'
*
4B5C: LH R12,SB$RELOC
4B60: BALR R13,R12 LOAD R7 WITH RELOCATION REG.
4B62: LH R12,SB$IOQ
4B66: OR R12,R12
4B68: BALR R13,R12
4B6A: LTR R0,R0
4B6C: BC 8,X'246'(,R11)
4B70: CH 0,X'568'(,R11)
4B74: BC 11,X'246'(,R11)
4B78: NI X'02B6',31
4B7C: LH 2,X'696'(,R11)
4B80: BCR R15,R2
4B82: TM X'003'(R1),16
4B86: BC 8,X'294'(,R11)
4B8A: TM X'006'(R8),7
4B8E: BC 8,X'294'(,R11)
4B92: NI X'01C'(R8),248
4B96: MVI X'006'(R8),0
4B9A: MVC X'004'(8,R1),X'01F'(R1)
4BA0: CLI X'002'(R8),4
4BA4: BC 8,X'294'(,R11)
4BA8: CLI X'002'(R8),6
4BAC: BC 8,X'294'(,R11)
4BB0: CLI X'002'(R8),1
4BB4: BC 8,X'15C'(,R11)
4BB8: L 2,X'00C'(,R1)
4BBC: LA 2,X'008'(,R2)
4BC0: CLI X'002'(R8),3
4BC4: BC 7,X'290'(,R11)
4BC8: LA 2,X'008'(,R2)
4BCC: ST 2,X'004'(,R1)
4BD0: TM X'003'(R1),16
4BD4: BC 8,X'2AC'(,R11)
4BD8: CLI X'027'(R1),142
4BDC: BC 7,X'2AC'(,R11)
4BE0: LR R13,R0
4BE2: MVC X'001'(2,R1),X'002'(R13)
4BE8: TM X'018'(R8),64
4BEC: BCR R1,R15
4BEE: LH 11,X'038C'
4BF2: BC 15,X'1A2'(,R11)
4BF6: LH 0,X'692'(,R11)
4BFA: MVI X'014'(R1),255
4BFE: OI IP$CONT2(R8),BP$IO2
4C02: TM IC$T+1(R1),BC$DIAG DIAGNOSTIC CCB?
4C06: BZ X'4C22' NO
4C0A: TM X'01C'(R8),2
4C0E: BC 8,X'2DA'(,R11)
4C12: MVI X'027'(R1),142
4C16: TM X'01E'(R1),3
4C1A: BC 14,X'2E6'(,R11)
4C1E: MVI X'027'(R1),143
4C22: MVI IP$CLK(R8),0 CLEAR IP$CLK
4C26: TM IC$T+1(R1),BC$DIAG DIAGNOSTIC CCB?
4C2A: BO X'4C3E' YES
4C2E: TM X'4FC0',255
4C32: BZ X'4C3E'
4C36: LA 12,X'302'(,R11)
4C3A: BC 15,X'63E'(,R11)
4C3E: NI IP$CCB(R8),127 CLEAR BIT
4C42: LA 1,X'000'(,R1) CLEAR R1 UPPER
4C46: SR R6,R6 CLEAR R6
4C48: TM IP$CONT1(R8),BP$UNTEX UNIT EXCEPTION?
4C4C: BZ X'4C54' NO
4C50: LA 6,X'0008'
4C54: LH 12,IP$TRL(,R8) GET PUB TRAILER ADDRESS
4C58: LTR R12,R12 = 0?
4C5A: BZ X'4C72' YES
4C5E: TM IP$CONT5(R8),255 ANY CHANNEL STATUS?
4C62: BM X'4C72' YES
4C66: TM IP$CONT1(R8),BP$DVERR UNIT CHECK?
4C6A: BM X'4C72' YES
4C6E: AI X'014'(R12),1
4C72: TM IP$CONT2(R8),BP$IOC
4C76: LH R12,IP$EPI(,R8) GET ADDR OF CHANNEL INTERRUPT
4C7A: BMR R12
4C7C: LR R2,R0
4C7E: MVC IP$SF(1,R1),X'002'(R2) COPY DVC STATUS TO CCB
4C84: OC IP$SF+1(1,R1),X'003'(R2) ADD CHAN STATUS TO CCB
4C8A: TM X'00C'(R8),16 CHECK DEVICE TYPE
4C8E: BZ X'4CA2'
4C92: LH 12,X'037C'
4C96: TM X'02B5',1
4C9A: BC 8,X'366'(,R11)
4C9E: SR R13,R13
4CA0: BALR R13,R12
4CA2: LH 12,IP$EPI(,R8) GET ENTRY FOR CHANNEL INTERRUPT
4CA6: BCR R15,R12
*
4CA8: STC R6,X'002'(,R1)
4CAC: CH 0,X'4E9C'
4CB0: BC 13,X'428'(,R11)
4CB4: NI IP$CONT2(R8),248 CLEAR IO1/2/4 FLAGS
4CB8: TM X'003'(R1),16
4CBC: BC 1,X'3E2'(,R11)
4CC0: XC IP$CONT1(2,R8),IP$CONT1(R8) CLEAR IP$CONT1, IP$CONT4
4CC6: LH 12,SB$UNLCK TRAP UNLOCK?
4CCA: LTR R12,R12 IS IT ZERO
4CCC: BZ X'4CD2' YES
4CD0: BALR R13,R12
4CD2: CH R8,SB$RES PUB = SYSRES?
4CD6: BE X'4D02' YES
4CDA: LH R12,IP$TRL(,R8) GET PUB TLR ADDR.
4CDE: TM IP$TYP(R8),16 CHECK DEVICE TYPE
4CE2: BC 14,X'4CEE'
4CE6: TM X'018'(R12),1
4CEA: BC 1,X'220'(,R11)
4CEE: LA R14,X'000'(,R14) CLEAR MSB OF TCB ADDR.
4CF2: C R14,X'02D0' TCB = SOS TCB?
4CF6: BE X'4D02' YES
4CFA: TM X'018'(R8),12
4CFE: BC 1,X'220'(,R11)
4D02: NI IP$CONT3(R8),251 CLEAR ERROR LOG PENDING FLAG
4D06: TM IP$TYP(R8),16 CHECK DEVICE TYPE
4D0A: BE X'4D1E'
4D0E: MVI X'01B'(R8),60
4D12: MVI X'008'(R8),128
4D16: TM X'01D'(R8),64
4D1A: BC 1,X'3E8'(,R11)
4D1E: XC IP$CCB(4,R8),IP$CCB(R8) CLEAR CCB ADDR.
4D24: TM X'003'(R1),16
4D28: BZ X'4D5C'
4D2C: CLI X'01B'(R1),0
4D30: BC 7,X'408'(,R11)
4D34: TM X'01A'(R1),2
4D38: BC 1,X'408'(,R11)
4D3C: TM X'027'(R1),128
4D40: BC 8,X'418'(,R11)
4D44: OI X'002'(R1),64
4D48: BC 15,X'428'(,R11)
4D4C: DC XL8'00000040000000BF'
4D54: NI X'002'(R1),191
4D58: BC 15,X'428'(,R11)
4D5C: NI IP$CONT2(R8),248 CLEAR IO1/2/4 CONTROL
4D60: MVI IP$CONT1(R8),0 CLEAR IP$CONT1
4D64: OI X'002'(R1),128
4D68: TM X'000'(R1),4
4D6C: BC 8,X'438'(,R11)
4D70: NI JT$WAIT+1(R14),251 CLEAR WAIT BIT
4D74: AI JT$IOC(R14),255 DEC OUTSTANDING I/O COUNT
4D78: BNZ X'4B5C' NOT ZERO, SKIP NEXT
4D7C: NI JT$WAIT+1(R14),253 CLEAR WAIT ALL BIT
4D80: BC 15,X'4B5C'
*
4D84: BALR R11,R0
4D86: LH 11,SB$HCOV GET INTERRUPT PROCESSOR ADDR.
4D8A: LA 0,X'0015'
4D8E: TM SB$ERFLG,BB$IO PIOCS IN CONTROL?
4D92: BO X'4DC0' YES
4D96: OI X'02B6',32
4D9A: L 14,X'02D0'
4D9E: LR R2,R14
4DA0: SH 2,X'560'(,R11)
4DA4: ST 2,X'024'(,R14)
4DA8: MVC X'000'(8,R2),X'508'(R11)
4DAE: XC X'004'(4,R14),X'004'(R14)
4DB4: SSTM R8,R8,X'510'(,R11)
4DB8: LH 8,X'512'(,R11)
4DBC: L 1,X'008'(,R8)
4DC0: TM DB$DEBUG,BB$IOD PIOCS DEBUG?
4DC4: BZ X'4DCC' NO
4DC8: HPR X'000F',15
*
4DCC: TM SB$ERFLG,BC$CCB? CCB QUESITIONABLE?
4DD0: BO X'4B78' YES
4DD4: TM SB$ERFLG,BB$TCB? TCB QUESTIONABLE?
4DD8: BZ X'4B78' NO
4DDC: LH 2,X'4FC2'
4DE0: TM SB$DEBUG,BB$IOD PCIOS DEBUG OPTION?
4DE4: BZ X'4DEC' NO
4DE8: HPR X'000F',15 OOPS!!!
4DEC: MVC X'000'(32,R2),X'000'(R8) COPY THE PUB
4DF2: XC IP$CCB(4,R8),IP$CCB(R8) CLEAR THE CCB ADDRESS
4DF8: LR R8,R2 GET PTR TO PUB COPY
4DFA: ST 1,IP$CCB(,R8) SAVE CCB ADDRESS
4DFE: MVI IC$SF+1(R1),128 SET CHANNEL STATUS TO X'80'
4E02: OI IP$CONT5(R8),255 SET IP$CONT5 TO X'FF'
4E06: XC X'000'(12,R1),X'000'(R1) CLEAR THE CCB
4E0C: SR R10,R10 CLEAR R10
4E0E: LH 6,X'010'(,R8) GET THE QUEUE ADDRESS
4E12: LA 2,X'020'(,R6)
4E16: CLC X'009'(3,R8),X'001'(R6)
4E1C: BC 8,X'4F6'(,R11)
4E20: CR R6,R2
4E22: BC 8,X'4F6'(,R11)
4E26: LA 6,X'004'(,R6)
4E2A: LA 10,X'004'(,R10)
4E2E: BC 15,X'4DA'(,R11)
4E32: SLL R10,X'0002'
4E36: STC 10,X'506'(,R11)
4E3A: LA 14,X'506'(,R11)
4E3E: BC 15,X'2C2'(,R11)
4E42: DC XL2'0000'
4E44: SSM X'06C'(R11),0
4E48: BC 15,X'0204'
4E4C: DC XL4'00000000'
4E50: OI X'02B6',160
4E54: BALR R12,R0
4E56: LH 11,X'038E'
4E5A: LH 12,X'0392'
4E5E: BALR R13,R12
4E60: TM X'008'(R8),112
4E64: BC 8,X'01E'(,R12)
4E68: BCR R14,R15
4E6A: TM X'006'(R8),128
4E6E: BC 1,X'636'(,R11)
4E72: L 1,X'008'(,R8)
4E76: L 14,X'004'(,R1)
4E7A: LH 12,SB$RELOC
4E7E: BALR R13,R12 LOAD R7 WITH RELOCATION REG.
4E80: LA 12,X'36C'(,R11)
4E84: TM X'008'(R8),8
4E88: BC 1,X'596'(,R11)
4E8C: L 6,X'008'(,R1)
4E90: ST 6,X'004'(,R1)
4E94: NC X'004'(2,R1),X'5A8'(R11)
4E9A: SRL R6,X'0012'
4E9E: ST 6,X'008'(,R1)
4EA2: LA 6,X'0020'
4EA6: LR R0,R1
4EA8: TM X'008'(R8),2
4EAC: BCR R1,R12
4EAE: LA 6,X'0040'
4EB2: TM X'008'(R8),4
4EB6: BCR R1,R12
4EB8: TM X'008'(R8),1
4EBC: BC 1,X'590'(,R11)
4EC0: SR R6,R6
4EC2: IC 6,X'002'(,R1)
4EC6: EX 0,X'3E2'(,R11)
4ECA: BCR R15,R12
4ECC: LA 0,X'001F'
4ED0: BCR R15,R12
4ED2: LH 12,X'016'(,R8)
4ED6: TM X'01C'(R8),2
4EDA: BCR R1,R12
4EDC: EX 0,X'3E2'(,R11)
4EE0: BC 15,X'294'(,R11)
4EE4: DC XL2'0003'
* STATUS PRESENTED FOR PUB WITH NO ACTIVE CCB
4EE6: TM IP$CA(R8),3 CHANNEL 3?
4EEA: BO X'4C76' YES
4EEE: NI IP$CONT4(R8),191 CLEAR FLAGS
4EF2: TM X'4FC0',255
4EF6: BZ X'4F02'
4EFA: LA 12,X'5C6'(,R11)
4EFE: BC 15,X'63E'(,R11)
4F02: TM IP$CONT1(R8),BP$DVERR UNIT CHECK?
4F06: BZ X'4F38' NO
4F0A: TM X'002'(R8),4
4F0E: BC 8,X'5FC'(,R11)
4F12: MVC X'00A0'(4),X'5EC'(R11)
4F18: MVC X'5E4'(2,R11),X'002'(R8)
4F1E: SIO X'5E2'(R11),0
4F22: BCR R15,R15
4F24: DC XL6'000000000000'
4F2A: CVB 3,X'0000'
4F2E: DC XL2'0000'
4F30: SPM R0,R0
4F32: CVB 2,X'000'(R4,R2)
4F36: DC XL2'0002'
4F38: TM IP$CONT1(R8),BP$CUEND CONTROL UNIT END?
4F3C: BO X'4BD0' YES
4F40: TM IP$CONT1(R8),BP$ATTN ATTENTION?
4F44: BNO X'4BD0' NO
* PROCESS ATTENTION INTERRUPTS
4F48: CLI IP$TYP(R8),0 DEVICE TYPE = 0?
4F4C: BE X'4C50' YES
4F50: TM SB$FLG,BB$NOATN ATTENTION NOT ALLOWED?
4F54: BOR R15 YES
4F56: AI X'002'(R8),0 CONSOLE?
4F5A: BC 7,X'636'(,R11) NO
4F5E: OI SB$SOI1,BB$SOCAI SET CONSOLE ATTN RECVD FLAG
4F62: L 12,SB$SOS GET ADDR OF SOS TCB
4F66: NI JT$WAIT+1(R12),247 CLEAR THE YIELD BIT
4F6A: LH 12,SB$MCOV COMMON ERROR PROCESSOR ADDR
4F6E: BC 15,X'140'(,R12)
*
4F72: OI X'02F4',2
4F76: BC 15,X'626'(,R11)
4F7A: LA 2,X'0FF0'
4F7E: LH 6,X'684'(,R11)
4F82: LH 3,X'002'(,R6)
4F86: LH 4,X'002'(,R8)
4F8A: NR R3,R2
4F8C: NR R4,R2
4F8E: CLR R3,R4
4F90: BCR R7,R12
4F92: XC X'684'(2,R11),X'684'(R11)
4F98: CR R8,R6
4F9A: BC 7,X'674'(,R11)
4F9E: TM X'007'(R8),255
4FA2: BCR R7,R12
4FA4: TM X'006'(R8),178
4FA8: BCR R7,R12
4FAA: MVI X'006'(R8),16
4FAE: BCR R15,R12
4FB0: OC X'008'(4,R8),X'008'(R8)
4FB6: BCR R7,R12
4FB8: LR R1,R0
4FBA: LR R8,R6
4FBC: BC 15,X'06E'(,R11)
4FC0: DC XL2'0000'
4FC2: BASR R12,R8
4FC4: DC XL8'0000000000000000'
4FCC: LA 8,X'1E8'(R8,R4)
4FD0: CH 3,X'866'(R10,R1)
4FD4: DC XL4'00000008'
* COME HERE AFTER SYSTEM RESET
4FD8: DIAG X'0000',0
4FDC: BALR R13,R0
4FDE: BC 0,X'08A'(,R13)
4FE2: BC 0,X'04A'(,R13)
4FE6: LPSW X'02A'(R13),0
4FEA: BALR R13,R0
4FEC: L 13,X'014'(,R13)
4FF0: MVC X'2D6'(256,R13),X'0000'
4FF6: MVI X'005'(R13),240
4FFA: BC 15,X'04A'(,R13)
4FFE: DC XL16'000000004FDE00000000000000000000'
500E: DC XL16'4FEA0000000000000000000000000000'
501E: DC XL16'000000000000000000004700D056900F'
502E: DC XL16'D00A92F0D04BD2070048D07441100800'
503E: DC XL16'950010004110180047F0D0605010D03E'
504E: DC XL16'47F0D082000000000000504A00000000'
505E: DC XL16'000092F0D001B00FD04AD7F3000C000C'
506E: DC XL16'40D0003E40D0004E5810D03E48400006'
507E: DC XL16'92800073D22300740073D20B0010D3D6'
508E: DC XL16'D2070028D3E248204028950320024770'
509E: DC XL16'D0C692F0D2674830200248202012D201'
50AE: DC XL16'00BE200CD204D2CE00BE8000D5064120'
50BE: DC XL16'D482502000A0D20F00D0D4F645E0D1E4'
50CE: DC XL16'920800D7920900D095F0D2674770D106'
50DE: DC XL16'D207D3F6D3EA45E0D1B44120D2D65020'
50EE: DC XL16'00D0920500D0920100D7D20300BED461'
50FE: DC XL16'D203D2CE00BE482000BE122247D0D12C'
510E: DC XL16'4120D3FA502000A01755416000011777'
511E: DC XL16'47F0D18A41550100195147B0D1A4D2FF'
512E: DC XL16'D2D650001876416060015960401447D0'
513E: DC XL16'D18A1777416000019A01D2D0D501D2D0'
514E: DC XL16'401A4740D18AD701D2D0D2D09A01D2CE'
515E: DC XL16'D501D2CED4654720D186D20300BED2CE'
516E: DC XL16'4260D2D2427000C245E0D1B4940FD141'
517E: DC XL16'47F0D1449999999947F0D1A499010000'
518E: DC XL16'47F0D08A426000DED20000DAD2D1D201'
519E: DC XL16'00DCD2CE482000BE4B2000BA47B0D1DA'
51AE: DC XL16'962000D6180217221B20402000D8D201'
51BE: DC XL16'00BA00BED20F00F000D094DF00D69400'
51CE: DC XL16'00DB9C00300047F0D1F6D20300A800E0'
51DE: DC XL16'D22300740073940F00A8493000A84770'
51EE: DC XL16'D2289500001B4770D1ACD50100AAD508'
51FE: DC XL16'4770D22C50E0002482000020910200AA'
520E: DC XL16'4780D1AC9180009F4710D1AC9680009F'
521E: DC XL16'50E000C4D20300C800A0D20300AC00D0'
522E: DC XL16'D20300D0D3F24120D3F2502000A08000'
523E: DC XL16'D50645E0D1B44700D29E910200B44780'
524E: DC XL16'D1AC582000C8412020085020D4DA9208'
525E: DC XL16'D4DA4120D4B2502000A045E0D1B4947F'
526E: DC XL16'009FD20300A000C858E000C407FE9108'
527E: DC XL16'00B64780D1AC4120009A502000D0920E'
528E: DC XL16'00D0928000DB45E0D1B4D20100BE009B'
529E: DC XL16'D20300D000AC924000DB47F0D28A0000'
52AE: DC XL16'00000100010000000000000000000000'
52BE: DC XL16'00000000000000000000000000000000'
52CE: DC XL16'00000000000000000000000000000000'
52DE: DC XL16'00000000000000000000000000000000'
52EE: DC XL16'00000000000000000000000000000000'
52FE: DC XL16'00000000000000000000000000000000'
530E: DC XL16'00000000000000000000000000000000'
531E: DC XL16'00000000000000000000000000000000'
532E: DC XL16'00000000000000000000000000000000'
533E: DC XL16'00000000000000000000000000000000'
534E: DC XL16'00000000000000000000000000000000'
535E: DC XL16'00000000000000000000000000000000'
536E: DC XL16'00000000000000000000000000000000'
537E: DC XL16'00000000000000000000000000000000'
538E: DC XL16'00000000000000000000000000000000'
539E: DC XL16'00000000000000000000000000000000'
53AE: DC XL16'00000000000000090009000000740074'
53BE: DC XL16'000000000000000051D85BE85BC4E4D4'
53CE: DC XL16'D740040000B420000005070000BC6000'
53DE: DC XL16'0006310000BE60000005080053E00000'
53EE: DC XL16'00001D0052AC60000108030053F82000'
53FE: DC XL16'00000000000000000000000000000000'
540E: DC XL16'00000000000000000000000000000000'
541E: DC XL16'00000000000000000000000000000000'
542E: DC XL16'00000000000000000000000000000000'
543E: DC XL16'00000000000000000000000000000000'
544E: DC XL16'00000000000000000000000000000000'
545E: DC XL16'0000070000BC60000006390000BE6000'
546E: DC XL16'00050800546800000000290053C86000'
547E: DC XL16'00070800547800000000060054002000'
548E: DC XL16'0060070000BC60000006390000BE6000'
549E: DC XL16'000508005498000000001600009A6000'
54AE: DC XL16'00050700009860000006080053E00000'
54BE: DC XL16'00000000000000000000000000000000'
54CE: DC XL16'000000000000020053D4000000010000'
54DE: DC XL16'00008000010040000C00000000000000'
54EE: DC XL16'00000000000000000000000000000000'
54FE: DC XL16'00000000000000000000000000000000'
550E: DC XL16'00000000000000000000000000000000'
551E: DC XL16'00000000000000000000000000000000'
552E: DC XL16'00000000000000000000000000000000'
553E: DC XL2'0000'
5540: CLI X'02E'(R1),2
5544: BC 7,X'00E'(,R15)
5548: STM R14,R12,X'00C'(,R13)
554C: LR R12,R0
554E: LA R10,X'0000'(R1)
5552: TM X'024'(R1),128
5556: BC 1,X'022'(,R15)
555A: MVI X'038'(R1),19
555E: BC 15,X'11E'(,R15)
5562: MVI X'02D'(R10),1
5566: CLI X'031'(R10),134
556A: BC 7,X'03E'(,R15)
556E: TM X'024'(R10),64
5572: BC 8,X'4B0'(,R15)
5576: L R12,X'028'(,R10)
557A: BC 15,X'3DC'(,R15)
557E: ST R12,X'028'(,R10)
5582: L R1,X'01C'(,R12)
5586: LA R1,X'0000'(R1)
558A: CR R10,R1
558C: BC 7,X'1FE'(,R15)
5590: MVI X'01A'(R12),0
5594: TM X'024'(R10),64
5598: BC 8,X'060'(,R15)
559C: BAL R7,X'3E0'(,R15)
55A0: NI X'025'(R10),127
55A4: MVI X'032'(R10),0
55A8: MVC X'03D'(7,R10),X'011'(R12)
55AE: MVI X'03C'(R10),13
55B2: CLI X'031'(R10),20
55B6: BC 8,X'0D2'(,R15)
55BA: CLI X'031'(R10),18
55BE: BC 8,X'0CE'(,R15)
55C2: MVI X'042'(R10),0
55C6: TM X'031'(R10),64
55CA: BC 8,X'094'(,R15)
55CE: SVC 49
55D0: BC 15,X'486'(,R15)
55D4: MVI X'03C'(R10),8
55D8: CLI X'031'(R10),133
55DC: BC 8,X'1B4'(,R15)
55E0: OI X'024'(R10),1
55E4: TM X'020'(R12),1
55E8: BC 8,X'0B2'(,R15)
55EC: MVC X'02D'(1,R10),X'010'(R12)
55F2: TM X'031'(R10),32
55F6: BC 1,X'14A'(,R15)
55FA: TM X'031'(R10),16
55FE: BC 1,X'0DA'(,R15)
5602: MVI X'038'(R10),20
5606: OI X'032'(R10),2
560A: BC 15,X'11E'(,R15)
560E: MVI X'03C'(R10),9
5612: OI X'025'(R10),128
5616: BC 15,X'1B4'(,R15)
561A: MVI X'03C'(R10),2
561E: CLC X'001'(3,R12),X'00D'(R12)
5624: BC 8,X'130'(,R15)
5628: XR R6,R6
562A: LH R8,X'02C'(,R10)
562E: L R9,X'000'(,R12)
5632: BCTR R9,R0
5634: AR R9,R8
5636: STH R8,X'02C'(,R10)
563A: STC R6,X'01A'(,R12)
563E: L R7,X'00C'(,R12)
5642: LA R7,X'0000'(R7)
5646: CR R9,R7
5648: BC 4,X'1BE'(,R15)
564C: SR R9,R8
564E: LA R6,X'0001'(R6)
5652: BCT R8,X'0F4'(,R15)
5656: MVI X'038'(R10),36
565A: OI X'032'(R10),64
565E: OC X'039'(3,R10),X'039'(R10)
5664: BC 8,X'4BC'(,R15)
5668: L R14,X'038'(,R10)
566C: BC 15,X'49E'(,R15)
5670: TM X'020'(R12),32
5674: BC 8,X'116'(,R15)
5678: OC X'021'(3,R12),X'021'(R12)
567E: BC 8,X'116'(,R15)
5682: L R14,X'020'(,R12)
5686: BC 15,X'49E'(,R15)
568A: TM X'025'(R10),16
568E: BC 1,X'0C2'(,R15)
5692: NI X'051'(R10),127
5696: TM X'020'(R12),16
569A: BC 8,X'162'(,R15)
569E: OI X'020'(R12),8
56A2: CLC X'000'(4,R12),X'004'(R12)
56A8: BC 13,X'184'(,R15)
56AC: TM X'032'(R10),64
56B0: BC 1,X'116'(,R15)
56B4: OI X'032'(R10),64
56B8: SVC 46
56BA: SVC 48
56BC: BC 15,X'11A'(,R15)
56C0: BC 15,X'162'(,R15)
56C4: NI X'032'(R10),191
56C8: MVI X'03C'(R10),5
56CC: CLC X'001'(3,R12),X'00D'(R12)
56D2: BC 4,X'1BE'(,R15)
56D6: TM X'020'(R12),128
56DA: BC 8,X'1BE'(,R15)
56DE: CLC X'001'(3,R12),X'00D'(R12)
56E4: BC 7,X'116'(,R15)
56E8: TM X'024'(R10),16
56EC: BC 1,X'1BE'(,R15)
56F0: MVI X'03C'(R10),1
56F4: CLC X'000'(4,R12),X'004'(R12)
56FA: BC 2,X'116'(,R15)
56FE: L R7,X'000'(,R12)
5702: XR R6,R6
5704: CR R7,R6
5706: BC 13,X'116'(,R15)
570A: D R6,X'008'(,R12)
570E: LTR R6,R6
5710: BC 2,X'1DA'(,R15)
5714: IC R6,X'00B'(,R12)
5718: BCTR R7,R0
571A: STC R6,X'04A'(,R10)
571E: XR R6,R6
5720: L R8,X'04C'(,R10)
5724: LA R8,X'0030'(R8)
5728: CLC X'00C'(1,R12),X'000'(R8)
572E: BC 8,X'206'(,R15)
5732: LA R8,X'0008'(R8)
5736: CLI X'000'(R8),238
573A: BC 7,X'1E8'(,R15)
573E: MVI X'038'(R10),22
5742: BC 15,X'11E'(,R15)
5746: LR R9,R6
5748: LH R6,X'006'(,R8)
574C: SLL R6,X'0010'
5750: SRL R6,X'0010'
5754: CR R7,R6
5756: BC 11,X'1F2'(,R15)
575A: LR R6,R9
575C: XR R9,R9
575E: IC R9,X'001'(,R8)
5762: A R9,X'04C'(,R10)
5766: ST R9,X'010'(,R10)
576A: SR R7,R6
576C: LR R6,R7
576E: BC 8,X'238'(,R15)
5772: XR R6,R6
5774: D R6,X'054'(,R10)
5778: AH R7,X'002'(,R8)
577C: AH R6,X'004'(,R8)
5780: CH R6,X'05A'(,R10)
5784: BC 13,X'250'(,R15)
5788: LA R7,X'0001'(R7)
578C: S R6,X'054'(,R10)
5790: STC R6,X'046'(,R10)
5794: TM X'020'(R12),64
5798: BC 8,X'2B8'(,R15)
579C: IC R6,X'04A'(,R10)
57A0: ST R6,X'048'(,R10)
57A4: LR R8,R6
57A6: C R6,X'008'(,R12)
57AA: BC 7,X'272'(,R15)
57AE: OI X'032'(R10),128
57B2: XR R9,R9
57B4: IC R9,X'018'(,R12)
57B8: LTR R9,R9
57BA: BC 8,X'2B4'(,R15)
57BE: M R8,X'048'(,R10)
57C2: IC R8,X'018'(,R12)
57C6: SR R9,R8
57C8: LA R9,X'0001'(R9)
57CC: XR R8,R8
57CE: D R8,X'008'(,R12)
57D2: LR R6,R8
57D4: XR R8,R8
57D6: L R9,X'048'(,R10)
57DA: BCTR R9,R0
57DC: MVC X'04B'(1,R10),X'016'(R12)
57E2: D R8,X'048'(,R10)
57E6: LA R8,X'000'(R6,R9)
57EA: LTR R8,R8
57EC: BC 2,X'2B4'(,R15)
57F0: L R8,X'008'(,R12)
57F4: STC R8,X'04A'(,R10)
57F8: STH R7,X'048'(,R10)
57FC: TM X'024'(R10),1
5800: BC 8,X'33E'(,R15)
5804: LA R8,X'0001'
5808: TM X'020'(R12),64
580C: BC 1,X'2F4'(,R15)
5810: LH R8,X'02C'(,R10)
5814: XR R9,R9
5816: IC R9,X'04A'(,R10)
581A: AR R9,R8
581C: BCTR R9,R0
581E: NI X'032'(R10),127
5822: C R9,X'008'(,R12)
5826: BC 4,X'2F4'(,R15)
582A: S R9,X'008'(,R12)
582E: SR R8,R9
5830: OI X'032'(R10),128
5834: LR R9,R8
5836: A R9,X'000'(,R12)
583A: ST R9,X'000'(,R12)
583E: CLC X'001'(3,R12),X'00D'(R12)
5844: BC 4,X'30E'(,R15)
5848: MVC X'00D'(3,R12),X'001'(R12)
584E: BCTR R9,R0
5850: ST R9,X'000'(,R12)
5854: LH R9,X'02C'(,R10)
5858: SR R9,R8
585A: LA R9,X'0001'(R9)
585E: STH R9,X'02C'(,R10)
5862: XR R9,R9
5864: XR R7,R7
5866: XR R2,R2
5868: IC R2,X'017'(,R12)
586C: AH R9,X'014'(,R12)
5870: AR R7,R2
5872: BCT R8,X'32C'(,R15)
5876: STC R7,X'043'(,R10)
587A: STH R9,X'040'(,R10)
587E: XR R9,R9
5880: IC R9,X'017'(,R12)
5884: ST R9,X'014'(,R10)
5888: IC R9,X'04A'(,R10)
588C: M R8,X'014'(,R10)
5890: S R9,X'014'(,R10)
5894: LA R9,X'0001'(R9)
5898: STC R9,X'04A'(,R10)
589C: TM X'025'(R10),128
58A0: BC 8,X'376'(,R15)
58A4: LH R8,X'040'(,R10)
58A8: SH R8,X'018'(,R12)
58AC: STH R8,X'040'(,R10)
58B0: MVC X'043'(1,R10),X'019'(R12)
58B6: CLI X'03C'(R10),1
58BA: BC 7,X'3B6'(,R15)
58BE: L R8,X'010'(,R12)
58C2: LA R9,X'0008'
58C6: SR R8,R9
58C8: MVC X'000'(2,R8),X'048'(R10)
58CE: STH R6,X'0002'(R8)
58D2: MVC X'004'(1,R8),X'04A'(R10)
58D8: MVI X'005'(R8),0
58DC: LH R2,X'014'(,R12)
58E0: TM X'020'(R12),2
58E4: BC 8,X'3B2'(,R15)
58E8: MVC X'005'(1,R8),X'019'(R12)
58EE: SH R2,X'018'(,R12)
58F2: STH R2,X'0006'(R8)
58F6: OI X'024'(R10),64
58FA: SVC 0
58FC: CLI X'03C'(R10),8
5900: BC 8,X'486'(,R15)
5904: TM X'020'(R12),8
5908: BC 1,X'3DC'(,R15)
590C: CLI X'02D'(R10),1
5910: BC 2,X'3DC'(,R15)
5914: TM X'024'(R10),32
5918: BC 8,X'486'(,R15)
591C: LA R7,X'406'(,R15)
5920: TM X'002'(R1),128
5924: BC 1,X'3EA'(,R15)
5928: SVC 1
592A: NI X'024'(R10),191
592E: MVC X'033'(1,R10),X'002'(R10)
5934: TM X'002'(R10),115
5938: BCR R8,R7
593A: OI X'032'(R10),16
593E: MVI X'038'(R10),34
5942: BC 15,X'11E'(,R15)
5946: TM X'025'(R10),128
594A: BC 8,X'44E'(,R15)
594E: NI X'025'(R10),127
5952: NI X'016'(R12),0
5956: LH R7,X'016'(,R12)
595A: M R6,X'000'(,R12)
595E: IC R6,X'04A'(,R10)
5962: SR R7,R6
5964: IC R6,X'018'(,R10)
5968: AR R7,R6
596A: LH R6,X'016'(,R12)
596E: ST R6,X'000'(,R12)
5972: XR R6,R6
5974: D R6,X'000'(,R12)
5978: XR R9,R9
597A: IC R9,X'017'(,R10)
597E: IC R6,X'046'(,R10)
5982: SR R9,R6
5984: M R8,X'008'(,R12)
5988: AR R7,R9
598A: ST R7,X'000'(,R12)
598E: MVI X'014'(R10),0
5992: TM X'020'(R12),8
5996: BC 8,X'46A'(,R15)
599A: NI X'020'(R12),247
599E: OI X'042'(R10),128
59A2: MVI X'03C'(R10),2
59A6: BC 15,X'3B6'(,R15)
59AA: NI X'016'(R12),127
59AE: NI X'042'(R10),0
59B2: TM X'020'(R12),32
59B6: BC 8,X'486'(,R15)
59BA: L R6,X'000'(,R12)
59BE: LA R6,X'0001'(R6)
59C2: ST R6,X'000'(,R12)
59C6: AI X'02C'(R10),255
59CA: BC 8,X'49E'(,R15)
59CE: L R8,X'03C'(,R10)
59D2: AH R8,X'040'(,R10)
59D6: ST R8,X'03C'(,R10)
59DA: BC 15,X'0B2'(,R15)
59DE: NI X'024'(R10),254
59E2: XR R7,R7
59E4: IC R7,X'01A'(,R12)
59E8: AH R7,X'02C'(,R10)
59EC: STC R7,X'02D'(,R10)
59F0: CLI X'02E'(R10),2
59F4: BCR R7,R14
59F6: LM R15,R12,X'010'(,R13)
59FA: BCR R15,R14
59FC: LM R14,R12,X'00C'(,R13)
5A00: SVC 61
5A02: DC XL6'000000000000'
* SVC 12 - AWAKE
5A08: LR R3,R1 R1 = R3
5A0A: SLL R3,X'0001' R3 = R3 * 2
5A0E: LTR R3,R3 R3 < 0?
5A10: BNM X'5E0' NO, GO LOAD AWAKE TRANSIENT
* R1 BIT 1 = 1 MAKES THIS A TYIELD CALL, NOT AWAKE.
* DO TYIELD PROCESSING HERE
5A14: OI JT$WAIT+1(R14),BT$TYLD YES, DO TYIELD - SET YIELD BIT
5A18: L R4,JT$ECB(,R14) GET THE ECB ADDRESS
5A1C: LA R4,X'0000'(R4) CLEAR MSB
5A20: LTR R4,R4 ECB ADDR = 0?
5A22: BZR R15 YES
5A24: AR R4,R12 NO, ADD RELOC REGISTER
5A26: OI EC$ACTIV(R4),BE$ACT MARK ECB ACITVE
5A2A: TM EC$CTL(R4),BE$WAIT IS WAIT BIT SET?
5A2E: BZR R15 NO
5A30: NI EC$CTL(R4),251 CLEAR WAIT BIT
5A34: L R5,EC$WTCB(,R4) GET ADDR OF WAITING TCB
5A38: AR R5,R13
5A3A: NI JT$WAIT+1(R5),251 CLEAR TCB WAIT BIT
5A3E: XC X'004'(4,R4),X'004'(R4) CLEAR WAITING TCB ADDR.
5A44: BCR R15,R15
*
5A46: DC XL8'0000000000000000'
5A4E: DC XL16'00000000000000000000000000000000'
5A5E: DC XL16'00000000000000000000000000000000'
5A6E: DC XL16'00000000000000000000000000000000'
5A7E: DC XL16'00000000000000000000000000000000'
5A8E: DC XL16'00000000000000000000000000000000'
5A9E: DC XL16'00000000000000000000000000000000'
5AAE: DC XL16'00000000000000000000000000000000'
5ABE: DC XL16'00000000000000000000000000000000'
5ACE: DC XL16'00000000000000000000000000000000'
5ADE: DC XL16'00000000000000000000000000000000'
5AEE: DC XL16'00000000000000000000000000000000'
5AFE: DC XL16'00000000000000000000000000000000'
5B0E: DC XL16'00000000000000000000000000000000'
5B1E: DC XL16'00000000000000000000000000000000'
5B2E: DC XL16'00000000000000000000000000000000'
5B3E: DC XL16'00000000000000000000000000000000'
5B4E: DC XL16'00000000000000000000000000000000'
5B5E: DC XL16'00000000000000000000000000000000'
5B6E: DC XL16'00000000000000000000000000000000'
5B7E: DC XL16'00000000000000000000000000000000'
5B8E: DC XL16'00000000000000000000000000000000'
5B9E: DC XL16'00000000000000000000000000000000'
5BAE: DC XL16'00000000000000000000000000000000'
5BBE: DC XL16'00000000000000000000000000000000'
5BCE: DC XL16'00000000000000000000000000000000'
5BDE: DC XL16'00000000000000000000000000000000'
5BEE: DC XL16'00000000000000000000000000000000'
5BFE: DC XL16'00000000000000000000000000000000'
5C0E: DC XL16'00000000000000000000000000000000'
5C1E: DC XL16'00000000000000000000000000000000'
5C2E: DC XL16'00000000000000000000000000000000'
5C3E: DC XL16'0000000000000000000047F005CA47F0'
5C4E: DC XL2'0598'
* SUPERVISOR TCB
5C50: DC XL14'00005C500008000000005C500000'
5C5E: DC XL16'00000000000000000000000000000000'
5C6E: DC XL16'0000C004000000000598000000000000'
5C7E: DC XL16'00000000000000000000000000000000'
5C8E: DC XL16'00000000000000000000000000000000'
5C9E: DC XL16'00000000000000000000000000000000'
5CAE: DC XL16'00000000000000005A48000000000000'
5CBE: DC XL16'00000000000002005A48020000020000'
5CCE: DC XL16'0000000000000000808C000000000000'
5CDE: DC XL16'000000005CC4000002A8000000000000'
5CEE: DC XL02'0000'
* FIRST TRANSIENT AREA
5CF0: DC XL14'4000000000000000000000000000'
5CFE: DC XL16'00000000000000000000000000000000'
5D0E: DC XL16'00000000000000000000000000000000'
5D1E: DC XL16'00000000000000000000000000000000'
5D2E: DC XL16'00000000000000000000000000000000'
5D3E: DC XL16'00000000000000000000000000000000'
5D4E: DC XL16'00000000000000000000000000000000'
5D5E: DC XL16'00000000000000000000000000000000'
5D6E: DC XL16'00000000000000000000000000000000'
5D7E: DC XL16'00000000000000000000000000000000'
5D8E: DC XL16'00000000000000000000000000000000'
5D9E: DC XL16'00000000000000000000000000000000'
5DAE: DC XL16'00000000000000000000000000000000'
5DBE: DC XL16'00000000000000000000000000000000'
5DCE: DC XL16'00000000000000000000000000000000'
5DDE: DC XL16'00000000000000000000000000000000'
5DEE: DC XL16'00000000000000000000000000000000'
5DFE: DC XL16'00000000000000000000000000000000'
5E0E: DC XL16'00000000000000000000000000000000'
5E1E: DC XL16'00000000000000000000000000000000'
5E2E: DC XL16'00000000000000000000000000000000'
5E3E: DC XL16'00000000000000000000000000000000'
5E4E: DC XL16'00000000000000000000000000000000'
5E5E: DC XL16'00000000000000000000000000000000'
5E6E: DC XL16'00000000000000000000000000000000'
5E7E: DC XL16'00000000000000000000000000000000'
5E8E: DC XL16'00000000000000000000000000000000'
5E9E: DC XL16'00000000000000000000000000000000'
5EAE: DC XL16'00000000000000000000000000000000'
5EBE: DC XL16'00000000000000000000000000000000'
5ECE: DC XL16'00000000000000000000000000000000'
5EDE: DC XL16'00000000000000000000000000000000'
5EEE: DC XL16'00000000000000000000000000000000'
5EFE: DC XL16'00000000000000000000000000000000'
5F0E: DC XL16'00000000000000000000000000000000'
5F1E: DC XL16'00000000000000000000000000000000'
5F2E: DC XL16'00000000000000000000000000000000'
5F3E: DC XL16'00000000000000000000000000000000'
5F4E: DC XL16'00000000000000000000000000000000'
5F5E: DC XL16'00000000000000000000000000000000'
5F6E: DC XL16'00000000000000000000000000000000'
5F7E: DC XL16'00000000000000000000000000000000'
5F8E: DC XL16'00000000000000000000000000000000'
5F9E: DC XL16'00000000000000000000000000000000'
5FAE: DC XL16'00000000000000000000000000000000'
5FBE: DC XL16'00000000000000000000000000000000'
5FCE: DC XL16'00000000000000000000000000000000'
5FDE: DC XL16'00000000000000000000000000000000'
5FEE: DC XL16'00000000000000000000000000000000'
5FFE: DC XL16'00000000000000000000000000000000'
600E: DC XL16'00000000000000000000000000000000'
601E: DC XL16'00000000000000000000000000000000'
602E: DC XL16'00000000000000000000000000000000'
603E: DC XL16'00000000000000000000000000000000'
604E: DC XL16'00000000000000000000000000000000'
605E: DC XL16'00000000000000000000000000000000'
606E: DC XL16'00000000000000000000000000000000'
607E: DC XL16'00000000000000000000000000000000'
608E: DC XL16'00000000000000000000000000000000'
609E: DC XL16'00000000000000000000000000000000'
60AE: DC XL16'00000000000000000000000000000000'
60BE: DC XL16'00000000000000000000000000000000'
60CE: DC XL16'00000000000000000000000000000000'
60DE: DC XL16'00000000000000000000000000000000'
60EE: DC XL10'000047F0077847F006C6'
* FIRST TRANSIENT AREA TCB
60F8: DC XL06'000065A00000'
60FE: DC XL16'02000C0065A000000000000000000000'
610E: DC XL16'00000000000000000000C00400000000'
611E: DC XL16'00000000000000000000000000000000'
612E: DC XL16'00000000000000000000000000000000'
613E: DC XL16'00000000000000000000000000000000'
614E: DC XL16'00000000000000000000000000000000'
615E: DC XL16'00000000000000000000000000000200'
616E: DC XL16'5CF00400000400000000000000000000'
617E: DC XL16'804800000000000000000000616C0000'
618E: DC XL10'02A80000000000000000'
* SECOND TRANSIENT AREA
6198: DC XL06'400000000000'
619E: DC XL16'00000000000000000000000000000000'
61AE: DC XL16'00000000000000000000000000000000'
61BE: DC XL16'00000000000000000000000000000000'
61CE: DC XL16'00000000000000000000000000000000'
61DE: DC XL16'00000000000000000000000000000000'
61EE: DC XL16'00000000000000000000000000000000'
61FE: DC XL16'00000000000000000000000000000000'
620E: DC XL16'00000000000000000000000000000000'
621E: DC XL16'00000000000000000000000000000000'
622E: DC XL16'00000000000000000000000000000000'
623E: DC XL16'00000000000000000000000000000000'
624E: DC XL16'00000000000000000000000000000000'
625E: DC XL16'00000000000000000000000000000000'
626E: DC XL16'00000000000000000000000000000000'
627E: DC XL16'00000000000000000000000000000000'
628E: DC XL16'00000000000000000000000000000000'
629E: DC XL16'00000000000000000000000000000000'
62AE: DC XL16'00000000000000000000000000000000'
62BE: DC XL16'00000000000000000000000000000000'
62CE: DC XL16'00000000000000000000000000000000'
62DE: DC XL16'00000000000000000000000000000000'
62EE: DC XL16'00000000000000000000000000000000'
62FE: DC XL16'00000000000000000000000000000000'
630E: DC XL16'00000000000000000000000000000000'
631E: DC XL16'00000000000000000000000000000000'
632E: DC XL16'00000000000000000000000000000000'
633E: DC XL16'00000000000000000000000000000000'
634E: DC XL16'00000000000000000000000000000000'
635E: DC XL16'00000000000000000000000000000000'
636E: DC XL16'00000000000000000000000000000000'
637E: DC XL16'00000000000000000000000000000000'
638E: DC XL16'00000000000000000000000000000000'
639E: DC XL16'00000000000000000000000000000000'
63AE: DC XL16'00000000000000000000000000000000'
63BE: DC XL16'00000000000000000000000000000000'
63CE: DC XL16'00000000000000000000000000000000'
63DE: DC XL16'00000000000000000000000000000000'
63EE: DC XL16'00000000000000000000000000000000'
63FE: DC XL16'00000000000000000000000000000000'
640E: DC XL16'00000000000000000000000000000000'
641E: DC XL16'00000000000000000000000000000000'
642E: DC XL16'00000000000000000000000000000000'
643E: DC XL16'00000000000000000000000000000000'
644E: DC XL16'00000000000000000000000000000000'
645E: DC XL16'00000000000000000000000000000000'
646E: DC XL16'00000000000000000000000000000000'
647E: DC XL16'00000000000000000000000000000000'
648E: DC XL16'00000000000000000000000000000000'
649E: DC XL16'00000000000000000000000000000000'
64AE: DC XL16'00000000000000000000000000000000'
64BE: DC XL16'00000000000000000000000000000000'
64CE: DC XL16'00000000000000000000000000000000'
64DE: DC XL16'00000000000000000000000000000000'
64EE: DC XL16'00000000000000000000000000000000'
64FE: DC XL16'00000000000000000000000000000000'
650E: DC XL16'00000000000000000000000000000000'
651E: DC XL16'00000000000000000000000000000000'
652E: DC XL16'00000000000000000000000000000000'
653E: DC XL16'00000000000000000000000000000000'
654E: DC XL16'00000000000000000000000000000000'
655E: DC XL16'00000000000000000000000000000000'
656E: DC XL16'00000000000000000000000000000000'
657E: DC XL16'00000000000000000000000000000000'
658E: DC XL16'0000000000000000000047F0077847F0'
659E: DC XL02'06C6'
* SECOND TRANSIENT AREA TCB
65A0: DC XL14'000060F8000002000C0060F80000'
65AE: DC XL16'00000000000000000000000000000000'
65BE: DC XL16'0000C004000000000000000000000000'
65CE: DC XL16'00000000000000000000000000000000'
65DE: DC XL16'00000000000000000000000000000000'
65EE: DC XL16'00000000000000000000000000000000'
65FE: DC XL16'00000000000000000000000000000000'
660E: DC XL16'00000000000002006198040000040000'
661E: DC XL16'00000000000000008048000000000000'
662E: DC XL16'000000006614000002A8000000000000'
663E: DC XL16'00000000000000000000000000004000'
664E: DC XL16'0000000030000000000000006B480000'
665E: DC XL16'00000000000000000000000000000000'
666E: DC XL16'00000000000000000000000000000000'
667E: DC XL16'00000000000000000000000000000000'
668E: DC XL16'00000000000000000000000000000000'
669E: DC XL16'00000000000000000000000000000000'
66AE: DC XL16'00000000000000000000000000000000'
66BE: DC XL16'00000000000000000000000000000000'
66CE: DC XL16'000C0000000000000001000000000000'
66DE: DC XL16'00000000000000000000000000000000'
66EE: DC XL16'00000000000000000000000000000000'
66FE: DC XL16'00000000000000000000000000000000'
670E: DC XL16'00000000000000000000000000000000'
671E: DC XL16'00000000000000000000000000000000'
672E: DC XL16'00000000000000000000000000000000'
673E: DC XL02'0000'
* SUPERVISOR TCB. THIS IS THE FIRST TCB TO RECEIVE CONTROL
* AFTER IPL.
6740: DC XL14'0000674000000000100067400000'
674E: DC XL16'00000000000000006640000000000000'
675E: DC XL16'0000C004000000006AEC000000000000'
676E: DC XL16'00000000000000000000000000000000'
677E: DC XL16'00000000000000000000000000000000'
678E: DC XL16'00000000000000000000000000000000'
679E: DC XL16'66400000674000006AEC000000000000'
67AE: DC XL16'00000000000000000000000000000000'
67BE: DC XL16'00000000000000000000000000000000'
67CE: DC XL16'00000000000000000000000000000000'
67DE: DC XL16'00000000000000000000000000000000'
67EE: DC XL16'00000000000000000000000000000000'
67FE: DC XL16'00000000000000000000000000000000'
680E: DC XL16'00000000000000000000000000000000'
681E: DC XL16'00000000000000000000000000000000'
682E: DC XL16'00000000000000000000000000000000'
683E: DC XL16'00000000000000000000000000000000'
684E: DC XL16'00000000000000000000000000000000'
685E: DC XL16'00000000000000000000000000000000'
686E: DC XL16'00000000000000000000000000000000'
687E: DC XL16'00000000000000000000000000000000'
688E: DC XL16'00000000000000000000000000000000'
689E: DC XL16'00000000000000000000000000000000'
68AE: DC XL16'00000000000000000000000000000000'
68BE: DC XL16'00000000000000000000000000000000'
68CE: DC XL16'00000000000000000000000000000000'
68DE: DC XL16'00000000000000000000000000000000'
68EE: DC XL16'00000000000000000000000000000000'
68FE: DC XL16'00000000000000000000000000000000'
690E: DC XL16'00000000000000000000000000000000'
691E: DC XL16'00000000000000000000000000000000'
692E: DC XL16'00000000000000000000000000000000'
693E: DC XL16'00000000000000000000000000000000'
694E: DC XL16'00000000000000000000000000000000'
695E: DC XL16'00000000000000000000000000000000'
696E: DC XL16'00000000000000000000000000000000'
697E: DC XL16'00000000000000000000000000000000'
698E: DC XL16'00000000000000000000000000000000'
699E: DC XL16'00000000000000000000000000000000'
69AE: DC XL16'00000000000000000000000000000000'
69BE: DC XL16'00000000000000000000000000000000'
69CE: DC XL16'00000000000000000000000000000000'
69DE: DC XL16'00000000000000000000000000000000'
69EE: DC XL16'00000000000000000000000000000000'
69FE: DC XL16'00000000000000000000000000000000'
6A0E: DC XL16'00000000000000000000000000000000'
6A1E: DC XL16'00000000000000000000000000000000'
6A2E: DC XL16'00000000000000000000000000000000'
6A3E: DC XL16'00000000000000000000000000000000'
6A4E: DC XL16'00000000000000000000000000000000'
6A5E: DC XL16'00000000000000000000000000000000'
6A6E: DC XL16'00000000000000000000000000000000'
6A7E: DC XL16'00000000000000000000F3D3F4F860C2'
6A8E: DC XL16'E4E24040F3E5E2E3C1D5C4F14040F0D3'
6A9E: DC XL16'F4F860C2E4E24040F0E5E2E3C1D5C4F1'
6AAE: DC XL16'4040F8D3F6F360E2E3C44040F8E5E2E3'
6ABE: DC XL16'C1D5C4F14040F6D3F4F860C2E4E24040'
6ACE: DC XL16'F6E5E2E3C1D5C4F14040F9D340404040'
6ADE: DC XL14'40404040F9E5E2E3C1D5C4F14040'
* SUPERVISOR INITIALIZATION CODE? LOADS SL$INT00.
USING *,R15
USING SB$SIB,R11
USING IP$PUB,R1
USING JP$PRE,R13
6AEC: BC 0,X'000'(,R15)
6AF0: LH 11,X'0006' POINT TO SIB
6AF4: LA 1,X'00A8' SET LENGTH OF TCB
6AF8: TM SB$CFG,BB$FPT HAS FLOATING POINT?
6AFC: BNO X'6B04' NO
6B00: LA 1,X'00C8' TCB LONGER IF FPT INSTALLED
6B04: STH 1,SB$SB$JTLNG SAVE TO SIB
6B08: MVC JP$LOD+4(2),SB$RES COPY SYSRES PUB TO LOADER SEARCH TABLE
6B0E: MVC JP$LOAD+12(4),SB$LL2 COPY $Y$LOD FMT2 DISK ADR. TO LDR SRCH TBL
6B14: LH 1,SB$RES GET PTR TO SYSRES PUB
6B18: OI IP$ALC,BP$JOB0 MAKE PUB IN USE BY SUPER
6B1C: LA 0,X'0026'
6B20: BAL 1,X'6B2C' ISSUE SVC
6B24: DC CL8'SL$INT00'
6B2C: SVC 24
6B2E: LTR R0,R0
6B30: BC 4,X'6B38' OOPS!
6B34: BC 15,X'05C'(,R15)
6B38: STC 0,X'053'(,R15) PUT ERROR CODE INTO HPR?
6B3C: HPR X'0200',2
6B40: BC 15,X'6B3C'
*
6B44: DC XL10'07000700000000000000'
6B4E: DC XL16'00000000000000000000000000000000'
6B5E: DC XL16'0000000000000000000000000000A048'
6B6E: DC XL16'4186900012884720F2B45880C0084280'
6B7E: DC XL16'A04A4070A0489101A0244780F33E4180'
6B8E: DC XL16'00019140C0204710F2F44880A02C1799'
6B9E: DC XL16'4390A04A1A980690947FA0325990C008'
6BAE: DC XL16'4740F2F45B90C0081B899680A0321898'
6BBE: DC XL16'5A90C0005090C000D502C001C00D4740'
6BCE: DC XL16'F30ED202C00DC00106905090C0004890'
6BDE: DC XL16'A02C1B98419900014090A02C17991777'
6BEE: DC XL16'17224320C0174A90C0141A724680F32C'
6BFE: DC XL16'4270A0434090A04017994390C0175090'
6C0E: DC XL16'A0144390A04A5C80A0145B90A0144199'
6C1E: DC XL16'00014290A04A9180A0254780F3764880'
6C2E: DC XL16'A0404B80C0184080A040D200A043C019'
6C3E: DC XL16'9501A03C4770F3B65880C01041900008'
6C4E: DC XL16'1B89D2018000A04840680002D2008004'
6C5E: DC XL16'A04A920080054820C0149102C0204780'
6C6E: DC XL16'F3B2D2008005C0194B20C01840280006'
6C7E: DC XL16'9640A0240A009508A03C4780F4869108'
6C8E: DC XL16'C0204710F3DC9501A02D4720F3DC9120'
6C9E: DC XL16'A0244780F4864170F406918010024710'
6CAE: DC XL16'F3EA0A0194BFA024D200A033A0029173'
6CBE: DC XL16'A00207879610A0329222A03847F0F11E'
6CCE: DC XL16'9180A0254780F44E947FA0259400C016'
6CDE: DC XL16'4870C0165C60C0004360A04A1B764360'
6CEE: DC XL16'A0181A764860C0165060C00017665D60'
6CFE: DC XL16'C00017994390A0174360A0461B965C80'
6D0E: DC XL16'C0081A795070C0009200A0149108C020'
6D1E: DC XL16'4780F46A94F7C0209680A0429202A03C'
6D2E: DC XL16'47F0F3B6947FC0169400A0429120C020'
6D3E: DC XL16'4780F4865860C000416600015060C000'
6D4E: DC XL16'9AFFA02C4780F49E5880A03C4A80A040'
6D5E: DC XL16'5080A03C47F0F0B294FEA02417774370'
6D6E: DC XL16'C01A4A70A02C4270A02D9502A02E077E'
6D7E: DC XL16'98FCD01007FE98ECD00C0A3D00000000'
6D8E: DC XL16'0000183189300001123347B005E09620'
6D9E: DC XL16'E0055840E018414400001244078F1A4C'
6DAE: DC XL16'9680400291044000078F94FB40005850'
6DBE: DC XL16'40041A5D94FB5005D7034004400407FF'
6DCE: DC XL16'00000000000000000000000000000000'
6DDE: DC XL16'00000000000000000000000000000000'
6DEE: DC XL16'00000000000000000000000000000000'
6DFE: DC XL16'00000000000000000000000000000000'
6E0E: DC XL16'00000000000000000000000000000000'
6E1E: DC XL16'00000000000000000000000000000000'
6E2E: DC XL16'00000000000000000000000000000000'
6E3E: DC XL16'00000000000000000000000000000000'
6E4E: DC XL16'00000000000000000000000000000000'
6E5E: DC XL16'00000000000000000000000000000000'
6E6E: DC XL16'00000000000000000000000000000000'
6E7E: DC XL16'00000000000000000000000000000000'
6E8E: DC XL16'00000000000000000000000000000000'
6E9E: DC XL16'00000000000000000000000000000000'
6EAE: DC XL16'00000000000000000000000000000000'
6EBE: DC XL16'00000000000000000000000000000000'
6ECE: DC XL16'00000000000000000000000000000000'
6EDE: DC XL16'00000000000000000000000000000000'
6EEE: DC XL16'00000000000000000000000000000000'
6EFE: DC XL16'00000000000000000000000000000000'
6F0E: DC XL16'00000000000000000000000000000000'
6F1E: DC XL16'00000000000000000000000000000000'
6F2E: DC XL16'00000000000000000000000000000000'
6F3E: DC XL16'00000000000000000000000000000000'
6F4E: DC XL16'00000000000000000000000000000000'
6F5E: DC XL16'00000000000000000000000000000000'
6F6E: DC XL16'00000000000000000000000000000000'
6F7E: DC XL16'00000000000000000000000000000000'
6F8E: DC XL16'00000000000000000000000000000000'
6F9E: DC XL16'00000000000000000000000000000000'
6FAE: DC XL16'00000000000000000000000000000000'
6FBE: DC XL16'00000000000000000000000000000000'
6FCE: DC XL16'000047F005CA47F0059800005C500008'
6FDE: DC XL16'000000005C5000000000000000000000'
6FEE: DC XL16'00000000000000000000C00400000000'
6FFE: DC XL2'0598'
|
label:
db label
dw label
dd label
|
;
;==================================================================================================
; ROMWBW 2.X CONFIGURATION DEFAULTS FOR ZETA V1
;==================================================================================================
;
; BUILD CONFIGURATION OPTIONS
;
CPUOSC .EQU 20000000 ; CPU OSC FREQ
RAMSIZE .EQU 512 ; SIZE OF RAM IN KB, MUST MATCH YOUR HARDWARE!!!
DEFSERCFG .EQU SER_38400_8N1 ; DEFAULT SERIAL LINE CONFIG (SHOULD MATCH ABOVE)
INTMODE .EQU 0 ; 0=NONE, 1=INT MODE 1, 2=INT MODE 2
;
CRTACT .EQU FALSE ; CRT ACTIVATION AT STARTUP
VDAEMU .EQU EMUTYP_ANSI ; DEFAULT VDA EMULATION (EMUTYP_TTY, EMUTYP_ANSI, ...)
;
DSKYENABLE .EQU FALSE ; TRUE FOR DSKY SUPPORT (DO NOT COMBINE WITH PPIDE)
;
HTIMENABLE .EQU FALSE ; TRUE FOR SIMH TIMER SUPPORT
SIMRTCENABLE .EQU FALSE ; SIMH CLOCK DRIVER
DSRTCENABLE .EQU TRUE ; DS-1302 CLOCK DRIVER
DSRTCMODE .EQU DSRTCMODE_STD ; DSRTCMODE_STD, DSRTCMODE_MFPIC
;
ASCIENABLE .EQU FALSE ; TRUE FOR Z180 ASCI SUPPORT
UARTENABLE .EQU TRUE ; TRUE FOR UART SUPPORT (ALMOST ALWAYS WANT THIS TO BE TRUE)
UARTOSC .EQU 1843200 ; UART OSC FREQUENCY
SIOENABLE .EQU FALSE ; TRUE FOR ZILOG SIO/2 SUPPORT
SIOMODE .EQU SIOMODE_RC ; SIOMODE_RC, SIOMODE_SMB
ACIAENABLE .EQU FALSE ; TRUE FOR MOTOROLA 6850 ACIA SUPPORT
;
VDUENABLE .EQU FALSE ; TRUE FOR VDU BOARD SUPPORT
CVDUENABLE .EQU FALSE ; TRUE FOR CVDU BOARD SUPPORT
NECENABLE .EQU FALSE ; TRUE FOR uPD7220 BOARD SUPPORT
TMSENABLE .EQU FALSE ; TRUE FOR N8 (TMS9918) VIDEO/KBD SUPPORT
VGAENABLE .EQU FALSE ; TRUE FOR VGA VIDEO/KBD SUPPORT
;
SPKENABLE .EQU FALSE ; TRUE FOR RTC LATCH IOBIT SOUND
AYENABLE .EQU FALSE ; TRUE FOR AY PSG SOUND
;
MDENABLE .EQU TRUE ; TRUE FOR ROM/RAM DISK SUPPORT (ALMOST ALWAYS WANT THIS ENABLED)
MDTRACE .EQU 1 ; 0=SILENT, 1=ERRORS, 2=EVERYTHING (ONLY RELEVANT IF MDENABLE = TRUE)
;
FDENABLE .EQU TRUE ; TRUE FOR FLOPPY SUPPORT
FDMODE .EQU FDMODE_ZETA ; FDMODE_DIO, FDMODE_ZETA, FDMODE_DIDE, FDMODE_N8, FDMODE_DIO3
FDTRACE .EQU 1 ; 0=SILENT, 1=FATAL ERRORS, 2=ALL ERRORS, 3=EVERYTHING (ONLY RELEVANT IF FDENABLE = TRUE)
FDMEDIA .EQU FDM144 ; FDM720, FDM144, FDM360, FDM120 (ONLY RELEVANT IF FDENABLE = TRUE)
FDMEDIAALT .EQU FDM720 ; ALTERNATE MEDIA TO TRY, SAME CHOICES AS ABOVE (ONLY RELEVANT IF FDMAUTO = TRUE)
FDMAUTO .EQU TRUE ; SELECT BETWEEN MEDIA OPTS ABOVE AUTOMATICALLY
;
RFENABLE .EQU FALSE ; TRUE FOR RAM FLOPPY SUPPORT
;
IDEENABLE .EQU FALSE ; TRUE FOR IDE SUPPORT
;
PPIDEENABLE .EQU FALSE ; TRUE FOR PPIDE SUPPORT (DO NOT COMBINE WITH DSKYENABLE)
PPIDEMODE .EQU PPIDEMODE_SBC ; PPIDEMODE_SBC, PPPIDEMODE_DIO3, PPIDEMODE_MFP, PPIDEMODE_N8, PPIDEMODE_RC
PPIDETRACE .EQU 1 ; 0=SILENT, 1=ERRORS, 2=EVERYTHING (ONLY RELEVANT IF PPIDEENABLE = TRUE)
PPIDE8BIT .EQU FALSE ; USE IDE 8BIT TRANSFERS (PROBABLY ONLY WORKS FOR CF CARDS!)
;
SDENABLE .EQU FALSE ; TRUE FOR SD SUPPORT
SDMODE .EQU SDMODE_PPI ; SDMODE_JUHA, SDMODE_CSIO, SDMODE_UART, SDMODE_PPI, SDMODE_DSD
SDTRACE .EQU 1 ; 0=SILENT, 1=ERRORS, 2=EVERYTHING (ONLY RELEVANT IF IDEENABLE = TRUE)
SDCSIOFAST .EQU FALSE ; TABLE-DRIVEN BIT INVERTER
;
PRPENABLE .EQU FALSE ; TRUE FOR PROPIO SUPPORT
;
PPPENABLE .EQU FALSE ; TRUE FOR PARPORTPROP SUPPORT
PPPSDENABLE .EQU TRUE ; TRUE FOR PARPORTPROP SD SUPPORT
PPPSDTRACE .EQU 1 ; 0=SILENT, 1=ERRORS, 2=EVERYTHING (ONLY RELEVANT IF PPPENABLE = TRUE)
PPPCONENABLE .EQU TRUE ; TRUE FOR PROPIO CONSOLE SUPPORT (PS/2 KBD & VGA VIDEO)
;
HDSKENABLE .EQU FALSE ; TRUE FOR SIMH HDSK SUPPORT
;
TERMENABLE .EQU FALSE ; TERM PSEUDO DEVICE, WILL BE ENABLED IF A VDA IS ENABLED
;
BOOTTYPE .EQU BT_MENU ; BT_MENU (WAIT FOR KEYPRESS), BT_AUTO (BOOT_DEFAULT AFTER BOOT_TIMEOUT SECS)
BOOT_TIMEOUT .EQU 20 ; APPROX TIMEOUT IN SECONDS FOR AUTOBOOT, 0 FOR IMMEDIATE
BOOT_DEFAULT .EQU 'Z' ; SELECTION TO INVOKE AT TIMEOUT
|
// Copyright (c) 2014, Facebook, Inc. All rights reserved.
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree. An additional grant
// of patent rights can be found in the PATENTS file in the same directory.
//
// This file implements the "bridge" between Java and C++ for rocksdb::Options.
#include <jni.h>
#include "include/org_rocksdb_PlainTableConfig.h"
#include "include/org_rocksdb_BlockBasedTableConfig.h"
#include "rocksdb/table.h"
#include "rocksdb/cache.h"
#include "rocksdb/filter_policy.h"
/*
* Class: org_rocksdb_PlainTableConfig
* Method: newTableFactoryHandle
* Signature: (IIDI)J
*/
jlong Java_org_rocksdb_PlainTableConfig_newTableFactoryHandle(
JNIEnv* env, jobject jobj, jint jkey_size, jint jbloom_bits_per_key,
jdouble jhash_table_ratio, jint jindex_sparseness) {
rocksdb::PlainTableOptions options = rocksdb::PlainTableOptions();
options.user_key_len = jkey_size;
options.bloom_bits_per_key = jbloom_bits_per_key;
options.hash_table_ratio = jhash_table_ratio;
options.index_sparseness = jindex_sparseness;
return reinterpret_cast<jlong>(rocksdb::NewPlainTableFactory(options));
}
/*
* Class: org_rocksdb_BlockBasedTableConfig
* Method: newTableFactoryHandle
* Signature: (ZJIJIIZI)J
*/
jlong Java_org_rocksdb_BlockBasedTableConfig_newTableFactoryHandle(
JNIEnv* env, jobject jobj, jboolean no_block_cache, jlong block_cache_size,
jint num_shardbits, jlong block_size, jint block_size_deviation,
jint block_restart_interval, jboolean whole_key_filtering,
jint bits_per_key) {
rocksdb::BlockBasedTableOptions options;
options.no_block_cache = no_block_cache;
if (!no_block_cache && block_cache_size > 0) {
if (num_shardbits > 0) {
options.block_cache =
rocksdb::NewLRUCache(block_cache_size, num_shardbits);
} else {
options.block_cache = rocksdb::NewLRUCache(block_cache_size);
}
}
options.block_size = block_size;
options.block_size_deviation = block_size_deviation;
options.block_restart_interval = block_restart_interval;
options.whole_key_filtering = whole_key_filtering;
if (bits_per_key > 0) {
options.filter_policy.reset(rocksdb::NewBloomFilterPolicy(bits_per_key));
}
return reinterpret_cast<jlong>(rocksdb::NewBlockBasedTableFactory(options));
}
|
;
;
;
; This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file.
;
; Copyright 2007-2019 Broadcom Inc. All rights reserved.
;
; This example is used for showing the serial LEDs on
; bcm956170r on option 3a.
;
; To start it, use the following commands from BCM:
;
; led 1 load bcm956170r_1.hex
; led 1 auto on
; led 1 start
;
; For CL port needs to output 2 bits stream,
; bit 0: LED_0 (Link)
; bit 1: LED_1 (Activity)
; For TSCE 10G port need to output 2 bits stream,
; bit 0: LED_0 (10G Link/Activity)
; bit 1: LED_1 (1G Link/Activity)
;
; Totally 6 ports need be outputed, i.e. 24 (= 12 + 6 * 2) bits.
; The output sequence for EGPHY will follow the user port sequence.
;
; The LED sequence is (User Port, Front Panel Order)
; xe0-xe17 (Lport 38-53, 58 59)
; Mapping onto physical port view, the sequence is:
; 58-61 66-77 82 86
; 2-5 10-21 26 30 (LED1 remap, -56)
;
; The CMIC_LEDUP1_PORT_ORDER_REMAP_XXX can only store 6 bits value for 64 ports, also for
; CMIC_LEDUP1_DATA_RAM it can only store data of 64 ports (128 bytes, each port requires
; 2 bytes). So for LED1 which is for physical ports 58-89, the physical port id has to be
; shifted in order to fit in the capability of the HW tables. GH2 LED driver shifts physical
; ports 58-89 to indices 2-33 (by minus 56) for LED1 tables, so that the shifted value can
; be stored in PORT_ORDER_REMAP and reflects on the DATA_RAM.
;
; The output order should be the inverted sequence of the physical
; mapping view
; 30 26 21-10 5-2
; Link up/down info cannot be derived from LINKEN, as the LED
; processor does not always have access to link status. This program
; assumes link status is kept current in bit 0 of RAM byte (0xA0 + portnum).
; Generally, a program running on the main CPU must update these
; locations on link change; see linkscan callback in
; $SDK/src/appl/diag/ledproc.c.
;
;
; Constants
;
; the smaller the TXRX_ALT_TICKS the faster it blinks
TICKS EQU 1
SECOND_TICKS EQU (30*TICKS)
TXRX_ALT_TICKS EQU (SECOND_TICKS/6)
TXRX_ALT_COUNT EQU 0xff
NUM_PORTS equ 18
START_PORT_0 equ 26
END_PORT_0 equ 26
START_PORT_1 equ 30
END_PORT_1 equ 30
START_PORT_2 equ 21
END_PORT_2 equ 18
START_PORT_3 equ 17
END_PORT_3 equ 10
START_PORT_4 equ 5
END_PORT_4 equ 2
;
; LED process
;
ld a, START_PORT_0
port a
ld (PORT_NUM), a
call get_activity_hw
call get_link_hw
ld a, START_PORT_1
port a
ld (PORT_NUM), a
call get_link_hw
call get_activity_hw
start_sec2:
ld a, START_PORT_2
iter_sec2:
port a
ld (PORT_NUM), a
call get_link1Gspeed_status
call get_link10Gspeed_status
ld a, (PORT_NUM)
dec a
cmp a, END_PORT_2 - 1
jnz iter_sec2
start_sec3:
ld a, START_PORT_3
iter_sec3:
port a
ld (PORT_NUM), a
call get_link10G_1Gspeed_status
ld a, (PORT_NUM)
dec a
cmp a, END_PORT_3 - 1
jnz iter_sec3
start_sec4:
ld a, START_PORT_4
iter_sec4:
port a
ld (PORT_NUM), a
call get_link10G_1Gspeed_status
ld a, (PORT_NUM)
dec a
cmp a, END_PORT_4 - 1
jnz iter_sec4
update:
inc (TXRX_ALT_COUNT)
end:
send 2*NUM_PORTS
;
; get_link_hw
;
; This routine finds the link status LED for a port from HW.
; Inputs: (PORT_NUM)
; Outputs: Carry flag set if link is up, clear if link is down.
; Destroys: a, b
get_link_hw:
pushst LINKEN
pop
jc led_on
jmp led_off
;
; get_link_sw
;
; This routine finds the link status LED for a port.
; Link info is in bit 0 of the byte read from PORTDATA[port]
; Inputs: (PORT_NUM)
; Outputs: Carry flag set if link is up, clear if link is down.
; Destroys: a, b
get_link_sw:
ld b, PORTDATA
add b, (PORT_NUM)
ld a, (b)
tst a, 0
jc led_on
jmp led_off
;
; get_activity_hw
;
; This routine finds the link status LED for a port from HW.
; Inputs: (PORT_NUM)
; Outputs: Carry flag set if RX or TX is up, clear if link is down.
; Destroys: a, b
get_activity_hw:
pushst RX
pushst TX
tor
pop
jc led_blink
jmp led_off
;
; get_link10Gspeed_status
;
; This routine finds the link and 10G speed status for a port from HW.
; The LED will blink if there is activity.
; Inputs: a
; Outputs: LED stream for on or off.
; Destroys: b
get_link10Gspeed_status:
port a
pushst LINKEN
pop
jnc led_off ; Always black, No LINK
pushst SPEED_C
pushst SPEED_M
tand
pop
jnc led_off ; Always black, No 10G
pushst RX
pushst TX
tor
pop
jc led_blink ; Show activity
jmp led_on ; Show Link
;
; get_link1Gspeed_status
;
; This routine finds the link and 1G speed status for a port from HW.
; The LED will blink if there is activity.
; Inputs: a
; Outputs: LED stream for on or off.
; Destroys: b
get_link1Gspeed_status:
port a
pushst LINKEN
pop
jnc led_off ; Always black, No LINK
pushst SPEED_M
pop
jnc led_off ; Always black, No 1G
pushst SPEED_C
pop
jc led_off ; If 100M also up, indicate its 10G not 1G
pushst RX
pushst TX
tor
pop
jc led_blink ; Show activity
jmp led_on ; Show Link
;
; get_link10Gspeed_status
;
; This routine finds the link and 10G/iC speed status for a port from HW.
; The LED will blink if there is activity.
; Inputs: a
; Outputs: LED stream for on or off.
; Destroys: b
get_link10G_1Gspeed_status:
port a
; determine whether is 1G or 10G
pushst SPEED_C
pop
jnc link1Gspeed_status
pushst LINKEN
pop
jnc led_off_2 ; Always black, No LINK
pushst SPEED_M
pop
jnc led_off_2 ; Always black, No 10G
pushst RX
pushst TX
tor
pop
jc led_blink_g ; Show activity
jmp led_on_g ; Show Link
link1Gspeed_status:
port a
pushst LINKEN
pop
jnc led_off_2 ; Always black, No LINK
pushst SPEED_M
pop
jnc led_off_2 ; Always black, No 1G
pushst RX
pushst TX
tor
pop
jc led_blink_a ; Show activity
jmp led_on_a ; Show Link
;
; led_blink
;
; Making the LED blinking
;
led_blink:
ld b, (TXRX_ALT_COUNT)
and b, TXRX_ALT_TICKS
jz led_on
jmp led_off
led_blink_g:
ld b, (TXRX_ALT_COUNT)
and b, TXRX_ALT_TICKS
jz led_on_g
jmp led_off_2
led_blink_a:
ld b, (TXRX_ALT_COUNT)
and b, TXRX_ALT_TICKS
jz led_on_a
jmp led_off_2
;
; led_on
;
; Outputs: Bits to the LED stream indicating ON
;
led_on:
push 0
pack
ret
led_on_g:
push 1
pack
push 0
pack
ret
led_on_a:
push 0
pack
push 1
pack
ret
; led_off
;
; Outputs: Bits to the LED stream indicating OFF
;
led_off:
push 1
pack
ret
led_off_2:
push 1
pack
push 1
pack
ret
; Variables (SDK software initializes LED memory from 0xA0-0xff to 0)
PORTDATA equ 0xA0
PORT_NUM equ 0xE0
; Symbolic names for the bits of the port status fields
RX equ 0x0 ; received packet
TX equ 0x1 ; transmitted packet
COLL equ 0x2 ; collision indicator
SPEED_C equ 0x3 ; 100 Mbps
SPEED_M equ 0x4 ; 1000 Mbps
DUPLEX equ 0x5 ; half/full duplex
FLOW equ 0x6 ; flow control capable
LINKUP equ 0x7 ; link down/up status
LINKEN equ 0x8 ; link disabled/enabled status
ZERO equ 0xE ; always 0
ONE equ 0xF ; always 1
|
;
; logic.asm
;
; MC6809E emulator test code for logic commands.
; Test for command correctness and flag settings.
; All tests will use direct or immediate addressing for simplicity,
; other addressing modes will be tested separately.
;
jmp start
;
setcf: equ $01
clrcf: equ $fe
;
varstart equ *
;
var0: fcb $ff
var1: fcb $55
var2: fcb $aa
var3: fcb $01
var4: fcb $80
var5: fcb $00
;
varend: equ *
varlen: equ varend-varstart
;
temp: fcb 0
;
start: andcc #0 ; zero CC bits
;
; COM
;
lda var1
coma
tfr a,b
comb
stb temp
com temp
ldb temp
;
; ROL
;
lda #8
ldb var1
loop_rol: rolb
deca
bne loop_rol
;
; ROR
;
andcc #0
ldb #8
lda var2
loop_ror: rora
decb
lbne loop_ror
;
; LSR
;
lda #8
ldb var1
stb temp
loop_lsr: lsr temp
ldb temp
deca
bne loop_lsr
;
; ASL / LSL
;
lda #8
ldb var1
loop_asl: aslb
deca
bne loop_asl
;
; ASR
;
ldb #8
lda var2
loop_asr: asra
decb
lbne loop_asr
;
; AND
;
lda var1
anda var3
;
ldb var4
andb var2
;
; OR
;
lda var2
ora var1
;
ldb var4
orb var3
;
; EOR
;
lda var1
eora var2
;
ldb var0
eorb var3
;
nop
;
; End of test
|
;
; ANSI Video handling for the Amstrad CPC
;
; Text Attributes
; m - Set Graphic Rendition
;
; The most difficult thing to port:
; Be careful here...
;
; Stefano Bodrato - Jul. 2004
;
;
; $Id: f_ansi_attr.asm,v 1.5 2015/01/19 01:33:18 pauloscustodio Exp $
;
PUBLIC ansi_attr
INCLUDE "cpcfirm.def"
PUBLIC INVRS
PUBLIC UNDRL
.UNDRL defb 0
.ansi_attr
and a
jr nz,noreset
xor a
ld (UNDRL),a ; underline 0
ld a,2 ; ink bright cyan
call firmware
defw txt_set_pen
xor a ; paper blue
call firmware
defw txt_set_paper
ret
.noreset
cp 1
jr nz,nobold
ld a,1 ; ink bright yellow
call firmware
defw txt_set_pen
ret
.nobold
cp 2
jr z,dim
cp 8
jr nz,nodim
.dim ld a,2 ; ink bright cyan
call firmware
defw txt_set_pen
ret
.nodim cp 4
jr nz,nounderline
ld a,1
ld (UNDRL),a ; underline 1
ret
.nounderline
cp 24
jr nz,noCunderline
xor a
ld (UNDRL),a ; underline 0
ret
.noCunderline
cp 5
jr nz,noblink
call firmware
defw txt_get_pen
xor 3
call firmware
defw txt_set_pen
ret
.noblink
cp 25
jr nz,nocblink
call firmware
defw txt_get_pen
xor 3
call firmware
defw txt_set_pen
ret
.nocblink
cp 7
jr nz,noreverse
.callinverse
call firmware
defw txt_inverse
ret
.noreverse
cp 27
jr z,callinverse
.noCreverse
cp 8
jr nz,noinvis
call firmware
defw txt_get_pen
ld (oldattr),a
call firmware
defw txt_get_paper
call firmware
defw txt_set_pen
ret
.oldattr
defb 0
.noinvis
cp 28
jr nz,nocinvis
ld a,(oldattr)
call firmware
defw txt_set_pen
ret
.nocinvis
cp 30
jp m,nofore
cp 37+1
jp p,nofore
sub 30
;'' Palette Handling ''
call dopal
call firmware
defw txt_set_pen
ret
.nofore
cp 40
jp m,noback
cp 47+1
jp p,noback
sub 40
;'' Palette Handling ''
call dopal
call firmware
defw txt_set_paper
.noback ret
.dopal
ld e,a
ld d,0
ld hl,ctable
add hl,de
ld a,(hl)
ret
.ctable defb 5,3,12,1,0,7,2,4
;0 Blue 1
;1 Bright Yellow 24
;2 Bright Cyan 20
;3 Bright Red 6
;4 Bright White 26
;5 Black 0
;6 Bright Blue 2
;7 Bright Magenta 8
;8 Cyan 10
;9 Yellow 12
;10 Pastel blue 14
;11 Pink 16
;12 Bright Green 18
;13 Pastel Green 22
;
;0 black 5
;1 red 3
;2 green 12-13
;3 yellow 1
;4 blue 0
;5 magenta 7
;6 cyan 2
;7 white 4
|
; A224456: The Wiener index of the cyclic phenylene with n hexagons (n>=3).
; 459,1008,1845,3024,4599,6624,9153,12240,15939,20304,25389,31248,37935,45504,54009,63504,74043,85680,98469,112464,127719,144288,162225,181584,202419,224784,248733,274320,301599,330624,361449,394128,428715,465264,503829,544464,587223,632160
add $0,1
mov $1,$0
mov $2,5
add $2,$0
mul $1,$2
mul $1,$2
sub $2,3
sub $1,$2
sub $1,33
mul $1,9
add $1,459
|
#include <affx/affine.hpp>
|
//////////////////////////////////////////////////////////////////////
//
// http://www.garagegames.com/
//
//////////////////////////////////////////////////////////////////////
//
// 3D Studio Model Class
// by: Matthew Fairfax
//
// Model_3DS.cpp: implementation of the Model_3DS class.
// This is a simple class for loading and viewing
// 3D Studio model files (.3ds). It supports models
// with multiple objects. It also supports multiple
// textures per object. It does not support the animation
// for 3D Studio models b/c there are simply too many
// ways for an artist to animate a 3D Studio model and
// I didn't want to impose huge limitations on the artists.
// However, I have imposed a limitation on how the models are
// textured:
// 1) Every faces must be assigned a material
// 2) If you want the face to be textured assign the
// texture to the Diffuse Color map
// 3) The texture must be supported by the GLTexture class
// which only supports bitmap and targa right now
// 4) The texture must be located in the same directory as
// the model
//
// Support for non-textured faces is done by reading the color
// from the material's diffuse color.
//
// Some models have problems loading even if you follow all of
// the restrictions I have stated and I don't know why. If you
// can import the 3D Studio file into Milkshape 3D
// (http://www.swissquake.ch/chumbalum-soft) and then export it
// to a new 3D Studio file. This seems to fix many of the problems
// but there is a limit on the number of faces and vertices Milkshape 3D
// can read.
//
// Usage:
// Model_3DS m;
//
// m.Load("model.3ds"); // Load the model
// m.Draw(); // Renders the model to the screen
//
// // If you want to show the model's normals
// m.shownormals = true;
//
// // If the model is not going to be lit then set the lit
// // variable to false. It defaults to true.
// m.lit = false;
//
// // You can disable the rendering of the model
// m.visible = false;
//
// // You can move and rotate the model like this:
// m.rot.x = 90.0f;
// m.rot.y = 30.0f;
// m.rot.z = 0.0f;
//
// m.pos.x = 10.0f;
// m.pos.y = 0.0f;
// m.pos.z = 0.0f;
//
// // If you want to move or rotate individual objects
// m.Objects[0].rot.x = 90.0f;
// m.Objects[0].rot.y = 30.0f;
// m.Objects[0].rot.z = 0.0f;
//
// m.Objects[0].pos.x = 10.0f;
// m.Objects[0].pos.y = 0.0f;
// m.Objects[0].pos.z = 0.0f;
//
//////////////////////////////////////////////////////////////////////
#ifdef WIN32
#include <windows.h>
#endif
// This is used to generate a warning from the compiler
#define _QUOTE(x) # x
#define QUOTE(x) _QUOTE(x)
#define __FILE__LINE__ __FILE__ "(" QUOTE(__LINE__) ") : "
#define warn( x ) message( __FILE__LINE__ #x "\n" )
#include "Model_3DS.h"
#include <math.h> // Header file for the math library
#include <GL/gl.h> // Header file for the OpenGL32 library
#include <string.h>
// The chunk's id numbers
#define MAIN3DS 0x4D4D
#define MAIN_VERS 0x0002
#define EDIT3DS 0x3D3D
#define MESH_VERS 0x3D3E
#define OBJECT 0x4000
#define TRIG_MESH 0x4100
#define VERT_LIST 0x4110
#define FACE_DESC 0x4120
#define FACE_MAT 0x4130
#define TEX_VERTS 0x4140
#define SMOOTH_GROUP 0x4150
#define LOCAL_COORDS 0x4160
#define MATERIAL 0xAFFF
#define MAT_NAME 0xA000
#define MAT_AMBIENT 0xA010
#define MAT_DIFFUSE 0xA020
#define MAT_SPECULAR 0xA030
#define SHINY_PERC 0xA040
#define SHINY_STR_PERC 0xA041
#define TRANS_PERC 0xA050
#define TRANS_FOFF_PERC 0xA052
#define REF_BLUR_PERC 0xA053
#define RENDER_TYPE 0xA100
#define SELF_ILLUM 0xA084
#define MAT_SELF_ILPCT 0xA08A
#define WIRE_THICKNESS 0xA087
#define MAT_TEXMAP 0xA200
#define MAT_MAPNAME 0xA300
#define ONE_UNIT 0x0100
#define KEYF3DS 0xB000
#define FRAMES 0xB008
#define MESH_INFO 0xB002
#define HIER_POS 0xB030
#define HIER_FATHER 0xB010
#define PIVOT_PT 0xB013
#define TRACK00 0xB020
#define TRACK01 0xB021
#define TRACK02 0xB022
#define COLOR_RGB 0x0010
#define COLOR_TRU 0x0011
#define COLOR_TRUG 0x0012
#define COLOR_RGBG 0x0013
#define PERC_INT 0x0030
#define PERC_FLOAT 0x0031
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
Model_3DS::Model_3DS()
{
// Initialization
// Don't show the normals by default
shownormals = false;
// The model is lit by default
lit = true;
// The model is visible by default
visible = true;
// Set up the default position
pos.x = 0.0f;
pos.y = 0.0f;
pos.z = 0.0f;
// Set up the default rotation
rot.x = 0.0f;
rot.y = 0.0f;
rot.z = 0.0f;
// Set up the path
path = new char[80];
strcpy(path, "");
// Zero out our counters for MFC
numObjects = 0;
numMaterials = 0;
// Set the scale to one
scale = 1.0f;
}
Model_3DS::~Model_3DS()
{
}
bool Model_3DS::Load(const char *name)
{
// holds the main chunk header
ChunkHeader main;
// strip "'s
if (strstr(name, "\""))
name = strtok( ((char*)name), "\"");
// Find the path
if (strstr(name, "/") || strstr(name, "\\"))
{
// Holds the name of the model minus the path
char *temp;
// Find the name without the path
if (strstr(name, "/"))
temp = strrchr((char *)name, '/');
else
temp = strrchr((char *)name, '\\');
// Allocate space for the path
path = new char[strlen(name)-strlen(temp)+1];
// Get a pointer to the end of the path and name
const char *src = name + strlen(name) - 1;
// Back up until a \ or the start
while (src != path && !((*(src-1)) == '\\' || (*(src-1)) == '/'))
src--;
// Copy the path into path
memcpy (path, name, src-name);
path[src-name] = 0;
}
// Load the file
bin3ds = fopen(name,"rb");
if ( bin3ds == NULL ) return false;
// Make sure we are at the beginning
fseek(bin3ds, 0, SEEK_SET);
// Load the Main Chunk's header
fread(&main.id,sizeof(main.id),1,bin3ds);
fread(&main.len,sizeof(main.len),1,bin3ds);
// Start Processing
MainChunkProcessor(main.len, ftell(bin3ds));
// Don't need the file anymore so close it
fclose(bin3ds);
// Calculate the vertex normals
CalculateNormals();
// For future reference
modelname = name;
// Find the total number of faces and vertices
totalFaces = 0;
totalVerts = 0;
for (int i = 0; i < numObjects; i ++)
{
totalFaces += Objects[i].numFaces/3;
totalVerts += Objects[i].numVerts;
}
// If the object doesn't have any texcoords generate some
for (int k = 0; k < numObjects; k++)
{
if (Objects[k].numTexCoords == 0)
{
// Set the number of texture coords
Objects[k].numTexCoords = Objects[k].numVerts;
// Allocate an array to hold the texture coordinates
Objects[k].TexCoords = new GLfloat[Objects[k].numTexCoords * 2];
// Make some texture coords
for (int m = 0; m < Objects[k].numTexCoords; m++)
{
Objects[k].TexCoords[2*m] = Objects[k].Vertexes[3*m];
Objects[k].TexCoords[2*m+1] = Objects[k].Vertexes[3*m+1];
}
}
}
// Let's build simple colored textures for the materials w/o a texture
for (int j = 0; j < numMaterials; j++)
{
if (Materials[j].textured == false)
{
Uint8 r = Materials[j].color.r;
Uint8 g = Materials[j].color.g;
Uint8 b = Materials[j].color.b;
Materials[j].tex.BuildColorTexture(r, g, b);
Materials[j].textured = true;
}
}
return true;
}
void Model_3DS::Draw()
{
if (visible)
{
glPushMatrix();
// Move the model
glTranslatef(pos.x, pos.y, pos.z);
// Rotate the model
glRotatef(rot.x, 1.0f, 0.0f, 0.0f);
glRotatef(rot.y, 0.0f, 1.0f, 0.0f);
glRotatef(rot.z, 0.0f, 0.0f, 1.0f);
glScalef(scale, scale, scale);
// Loop through the objects
for (int i = 0; i < numObjects; i++)
{
// Enable texture coordiantes, normals, and vertices arrays
if (Objects[i].textured)
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
if (lit)
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
// Point them to the objects arrays
if (Objects[i].textured)
glTexCoordPointer(2, GL_FLOAT, 0, Objects[i].TexCoords);
if (lit)
glNormalPointer(GL_FLOAT, 0, Objects[i].Normals);
glVertexPointer(3, GL_FLOAT, 0, Objects[i].Vertexes);
// Loop through the faces as sorted by material and draw them
for (int j = 0; j < Objects[i].numMatFaces; j ++)
{
// Use the material's texture
Materials[Objects[i].MatFaces[j].MatIndex].tex.Use();
glPushMatrix();
// Move the model
glTranslatef(Objects[i].pos.x, Objects[i].pos.y, Objects[i].pos.z);
// Rotate the model
//glRotatef(Objects[i].rot.x, 1.0f, 0.0f, 0.0f);
//glRotatef(Objects[i].rot.y, 0.0f, 1.0f, 0.0f);
//glRotatef(Objects[i].rot.z, 0.0f, 0.0f, 1.0f);
glRotatef(Objects[i].rot.z, 0.0f, 0.0f, 1.0f);
glRotatef(Objects[i].rot.y, 0.0f, 1.0f, 0.0f);
glRotatef(Objects[i].rot.x, 1.0f, 0.0f, 0.0f);
// Draw the faces using an index to the vertex array
glDrawElements(GL_TRIANGLES, Objects[i].MatFaces[j].numSubFaces, GL_UNSIGNED_SHORT, Objects[i].MatFaces[j].subFaces);
glPopMatrix();
Materials[Objects[i].MatFaces[j].MatIndex].tex.Finish();
}
// Show the normals?
if (shownormals)
{
// Loop through the vertices and normals and draw the normal
for (int k = 0; k < Objects[i].numVerts * 3; k += 3)
{
// Disable texturing
glDisable(GL_TEXTURE_2D);
// Disbale lighting if the model is lit
if (lit)
glDisable(GL_LIGHTING);
// Draw the normals blue
glColor3f(0.0f, 0.0f, 1.0f);
// Draw a line between the vertex and the end of the normal
glBegin(GL_LINES);
glVertex3f(Objects[i].Vertexes[k], Objects[i].Vertexes[k+1], Objects[i].Vertexes[k+2]);
glVertex3f(Objects[i].Vertexes[k]+Objects[i].Normals[k], Objects[i].Vertexes[k+1]+Objects[i].Normals[k+1], Objects[i].Vertexes[k+2]+Objects[i].Normals[k+2]);
glEnd();
// Reset the color to white
glColor3f(1.0f, 1.0f, 1.0f);
// If the model is lit then renable lighting
if (lit)
glEnable(GL_LIGHTING);
}
}
}
glPopMatrix();
}
}
void Model_3DS::CalculateNormals()
{
// Let's build some normals
for (int i = 0; i < numObjects; i++)
{
for (int g = 0; g < Objects[i].numVerts; g++)
{
// Reduce each vert's normal to unit
float length;
Vector unit;
unit.x = Objects[i].Normals[g*3];
unit.y = Objects[i].Normals[g*3+1];
unit.z = Objects[i].Normals[g*3+2];
length = (float)sqrt((unit.x*unit.x) + (unit.y*unit.y) + (unit.z*unit.z));
if (length == 0.0f)
length = 1.0f;
unit.x /= length;
unit.y /= length;
unit.z /= length;
Objects[i].Normals[g*3] = unit.x;
Objects[i].Normals[g*3+1] = unit.y;
Objects[i].Normals[g*3+2] = unit.z;
}
}
}
void Model_3DS::MainChunkProcessor(Sint32 length, Sint32 findex)
{
ChunkHeader h;
// move the file pointer to the beginning of the main
// chunk's data findex + the size of the header
fseek(bin3ds, findex, SEEK_SET);
while (ftell(bin3ds) < (findex + length - 6))
{
fread(&h.id,sizeof(h.id),1,bin3ds);
fread(&h.len,sizeof(h.len),1,bin3ds);
switch (h.id)
{
// This is the mesh information like vertices, faces, and materials
case EDIT3DS :
EditChunkProcessor(h.len, ftell(bin3ds));
break;
// I left this in case anyone gets very ambitious
case KEYF3DS :
//KeyFrameChunkProcessor(h.len, ftell(bin3ds));
break;
default :
break;
}
fseek(bin3ds, (h.len - 6), SEEK_CUR);
}
// move the file pointer back to where we got it so
// that the ProcessChunk() which we interrupted will read
// from the right place
fseek(bin3ds, findex, SEEK_SET);
}
void Model_3DS::EditChunkProcessor(Sint32 length, Sint32 findex)
{
ChunkHeader h;
// move the file pointer to the beginning of the main
// chunk's data findex + the size of the header
fseek(bin3ds, findex, SEEK_SET);
// First count the number of Objects and Materials
while (ftell(bin3ds) < (findex + length - 6))
{
fread(&h.id,sizeof(h.id),1,bin3ds);
fread(&h.len,sizeof(h.len),1,bin3ds);
switch (h.id)
{
case OBJECT :
numObjects++;
break;
case MATERIAL :
numMaterials++;
break;
default :
break;
}
fseek(bin3ds, (h.len - 6), SEEK_CUR);
}
// Now load the materials
if (numMaterials > 0)
{
Materials = new Material[numMaterials];
// Material is set to untextured until we find otherwise
for (int d = 0; d < numMaterials; d++)
Materials[d].textured = false;
fseek(bin3ds, findex, SEEK_SET);
int i = 0;
while (ftell(bin3ds) < (findex + length - 6))
{
fread(&h.id,sizeof(h.id),1,bin3ds);
fread(&h.len,sizeof(h.len),1,bin3ds);
switch (h.id)
{
case MATERIAL :
MaterialChunkProcessor(h.len, ftell(bin3ds), i);
i++;
break;
default :
break;
}
fseek(bin3ds, (h.len - 6), SEEK_CUR);
}
}
// Load the Objects (individual meshes in the whole model)
if (numObjects > 0)
{
Objects = new Object[numObjects];
// Set the textured variable to false until we find a texture
for (int k = 0; k < numObjects; k++)
Objects[k].textured = false;
// Zero the objects position and rotation
for (int m = 0; m < numObjects; m++)
{
Objects[m].pos.x = 0.0f;
Objects[m].pos.y = 0.0f;
Objects[m].pos.z = 0.0f;
Objects[m].rot.x = 0.0f;
Objects[m].rot.y = 0.0f;
Objects[m].rot.z = 0.0f;
}
// Zero out the number of texture coords
for (int n = 0; n < numObjects; n++)
Objects[n].numTexCoords = 0;
fseek(bin3ds, findex, SEEK_SET);
int j = 0;
while (ftell(bin3ds) < (findex + length - 6))
{
fread(&h.id,sizeof(h.id),1,bin3ds);
fread(&h.len,sizeof(h.len),1,bin3ds);
switch (h.id)
{
case OBJECT :
ObjectChunkProcessor(h.len, ftell(bin3ds), j);
j++;
break;
default :
break;
}
fseek(bin3ds, (h.len - 6), SEEK_CUR);
}
}
// move the file pointer back to where we got it so
// that the ProcessChunk() which we interrupted will read
// from the right place
fseek(bin3ds, findex, SEEK_SET);
}
void Model_3DS::MaterialChunkProcessor(Sint32 length, Sint32 findex, int matindex)
{
ChunkHeader h;
// move the file pointer to the beginning of the main
// chunk's data findex + the size of the header
fseek(bin3ds, findex, SEEK_SET);
while (ftell(bin3ds) < (findex + length - 6))
{
fread(&h.id,sizeof(h.id),1,bin3ds);
fread(&h.len,sizeof(h.len),1,bin3ds);
switch (h.id)
{
case MAT_NAME :
// Loads the material's names
MaterialNameChunkProcessor(h.len, ftell(bin3ds), matindex);
break;
case MAT_AMBIENT :
//ColorChunkProcessor(h.len, ftell(bin3ds));
break;
case MAT_DIFFUSE :
DiffuseColorChunkProcessor(h.len, ftell(bin3ds), matindex);
break;
case MAT_SPECULAR :
//ColorChunkProcessor(h.len, ftell(bin3ds));
case MAT_TEXMAP :
// Finds the names of the textures of the material and loads them
TextureMapChunkProcessor(h.len, ftell(bin3ds), matindex);
break;
default :
break;
}
fseek(bin3ds, (h.len - 6), SEEK_CUR);
}
// move the file pointer back to where we got it so
// that the ProcessChunk() which we interrupted will read
// from the right place
fseek(bin3ds, findex, SEEK_SET);
}
void Model_3DS::MaterialNameChunkProcessor(Sint32 length, Sint32 findex, int matindex)
{
// move the file pointer to the beginning of the main
// chunk's data findex + the size of the header
fseek(bin3ds, findex, SEEK_SET);
// Read the material's name
for (int i = 0; i < 80; i++)
{
Materials[matindex].name[i] = fgetc(bin3ds);
if (Materials[matindex].name[i] == 0)
{
Materials[matindex].name[i] = 0;
break;
}
}
// move the file pointer back to where we got it so
// that the ProcessChunk() which we interrupted will read
// from the right place
fseek(bin3ds, findex, SEEK_SET);
}
void Model_3DS::DiffuseColorChunkProcessor(Sint32 length, Sint32 findex, int matindex)
{
ChunkHeader h;
// move the file pointer to the beginning of the main
// chunk's data findex + the size of the header
fseek(bin3ds, findex, SEEK_SET);
while (ftell(bin3ds) < (findex + length - 6))
{
fread(&h.id,sizeof(h.id),1,bin3ds);
fread(&h.len,sizeof(h.len),1,bin3ds);
// Determine the format of the color and load it
switch (h.id)
{
case COLOR_RGB :
// A rgb float color chunk
FloatColorChunkProcessor(h.len, ftell(bin3ds), matindex);
break;
case COLOR_TRU :
// A rgb int color chunk
IntColorChunkProcessor(h.len, ftell(bin3ds), matindex);
break;
case COLOR_RGBG :
// A rgb gamma corrected float color chunk
FloatColorChunkProcessor(h.len, ftell(bin3ds), matindex);
break;
case COLOR_TRUG :
// A rgb gamma corrected int color chunk
IntColorChunkProcessor(h.len, ftell(bin3ds), matindex);
break;
default :
break;
}
fseek(bin3ds, (h.len - 6), SEEK_CUR);
}
// move the file pointer back to where we got it so
// that the ProcessChunk() which we interrupted will read
// from the right place
fseek(bin3ds, findex, SEEK_SET);
}
void Model_3DS::FloatColorChunkProcessor(Sint32 length, Sint32 findex, int matindex)
{
float r;
float g;
float b;
// move the file pointer to the beginning of the main
// chunk's data findex + the size of the header
fseek(bin3ds, findex, SEEK_SET);
fread(&r,sizeof(r),1,bin3ds);
fread(&g,sizeof(g),1,bin3ds);
fread(&b,sizeof(b),1,bin3ds);
Materials[matindex].color.r = (Uint8)(r*255.0f);
Materials[matindex].color.g = (Uint8)(r*255.0f);
Materials[matindex].color.b = (Uint8)(r*255.0f);
Materials[matindex].color.a = 255;
// move the file pointer back to where we got it so
// that the ProcessChunk() which we interrupted will read
// from the right place
fseek(bin3ds, findex, SEEK_SET);
}
void Model_3DS::IntColorChunkProcessor(Sint32 length, Sint32 findex, int matindex)
{
Uint8 r;
Uint8 g;
Uint8 b;
// move the file pointer to the beginning of the main
// chunk's data findex + the size of the header
fseek(bin3ds, findex, SEEK_SET);
fread(&r,sizeof(r),1,bin3ds);
fread(&g,sizeof(g),1,bin3ds);
fread(&b,sizeof(b),1,bin3ds);
Materials[matindex].color.r = r;
Materials[matindex].color.g = g;
Materials[matindex].color.b = b;
Materials[matindex].color.a = 255;
// move the file pointer back to where we got it so
// that the ProcessChunk() which we interrupted will read
// from the right place
fseek(bin3ds, findex, SEEK_SET);
}
void Model_3DS::TextureMapChunkProcessor(Sint32 length, Sint32 findex, int matindex)
{
ChunkHeader h;
// move the file pointer to the beginning of the main
// chunk's data findex + the size of the header
fseek(bin3ds, findex, SEEK_SET);
while (ftell(bin3ds) < (findex + length - 6))
{
fread(&h.id,sizeof(h.id),1,bin3ds);
fread(&h.len,sizeof(h.len),1,bin3ds);
switch (h.id)
{
case MAT_MAPNAME:
// Read the name of texture in the Diffuse Color map
MapNameChunkProcessor(h.len, ftell(bin3ds), matindex);
break;
default :
break;
}
fseek(bin3ds, (h.len - 6), SEEK_CUR);
}
// move the file pointer back to where we got it so
// that the ProcessChunk() which we interrupted will read
// from the right place
fseek(bin3ds, findex, SEEK_SET);
}
void Model_3DS::MapNameChunkProcessor(Sint32 length, Sint32 findex, int matindex)
{
char name[80];
// move the file pointer to the beginning of the main
// chunk's data findex + the size of the header
fseek(bin3ds, findex, SEEK_SET);
// Read the name of the texture
for (int i = 0; i < 80; i++)
{
name[i] = fgetc(bin3ds);
if (name[i] == 0)
{
name[i] = 0;
break;
}
}
// Load the name and indicate that the material has a texture
char fullname[80];
sprintf(fullname, "%s%s", path, name);
Materials[matindex].tex.Load(fullname);
Materials[matindex].textured = true;
// move the file pointer back to where we got it so
// that the ProcessChunk() which we interrupted will read
// from the right place
fseek(bin3ds, findex, SEEK_SET);
}
void Model_3DS::ObjectChunkProcessor(Sint32 length, Sint32 findex, int objindex)
{
ChunkHeader h;
// move the file pointer to the beginning of the main
// chunk's data findex + the size of the header
fseek(bin3ds, findex, SEEK_SET);
// Load the object's name
for (int i = 0; i < 80; i++)
{
Objects[objindex].name[i] = fgetc(bin3ds);
if (Objects[objindex].name[i] == 0)
{
Objects[objindex].name[i] = 0;
break;
}
}
while (ftell(bin3ds) < (findex + length - 6))
{
fread(&h.id,sizeof(h.id),1,bin3ds);
fread(&h.len,sizeof(h.len),1,bin3ds);
switch (h.id)
{
case TRIG_MESH :
// Process the triangles of the object
TriangularMeshChunkProcessor(h.len, ftell(bin3ds), objindex);
break;
default :
break;
}
fseek(bin3ds, (h.len - 6), SEEK_CUR);
}
// move the file pointer back to where we got it so
// that the ProcessChunk() which we interrupted will read
// from the right place
fseek(bin3ds, findex, SEEK_SET);
}
void Model_3DS::TriangularMeshChunkProcessor(Sint32 length, Sint32 findex, int objindex)
{
ChunkHeader h;
// move the file pointer to the beginning of the main
// chunk's data findex + the size of the header
fseek(bin3ds, findex, SEEK_SET);
while (ftell(bin3ds) < (findex + length - 6))
{
fread(&h.id,sizeof(h.id),1,bin3ds);
fread(&h.len,sizeof(h.len),1,bin3ds);
switch (h.id)
{
case VERT_LIST :
// Load the vertices of the onject
VertexListChunkProcessor(h.len, ftell(bin3ds), objindex);
break;
case LOCAL_COORDS :
//LocalCoordinatesChunkProcessor(h.len, ftell(bin3ds));
break;
case TEX_VERTS :
// Load the texture coordinates for the vertices
TexCoordsChunkProcessor(h.len, ftell(bin3ds), objindex);
Objects[objindex].textured = true;
break;
default :
break;
}
fseek(bin3ds, (h.len - 6), SEEK_CUR);
}
// After we have loaded the vertices we can load the faces
fseek(bin3ds, findex, SEEK_SET);
while (ftell(bin3ds) < (findex + length - 6))
{
fread(&h.id,sizeof(h.id),1,bin3ds);
fread(&h.len,sizeof(h.len),1,bin3ds);
switch (h.id)
{
case FACE_DESC :
// Load the faces of the object
FacesDescriptionChunkProcessor(h.len, ftell(bin3ds), objindex);
break;
default :
break;
}
fseek(bin3ds, (h.len - 6), SEEK_CUR);
}
// move the file pointer back to where we got it so
// that the ProcessChunk() which we interrupted will read
// from the right place
fseek(bin3ds, findex, SEEK_SET);
}
void Model_3DS::VertexListChunkProcessor(Sint32 length, Sint32 findex, int objindex)
{
Uint16 numVerts;
// move the file pointer to the beginning of the main
// chunk's data findex + the size of the header
fseek(bin3ds, findex, SEEK_SET);
// Read the number of vertices of the object
fread(&numVerts,sizeof(numVerts),1,bin3ds);
// Allocate arrays for the vertices and normals
Objects[objindex].Vertexes = new GLfloat[numVerts * 3];
Objects[objindex].Normals = new GLfloat[numVerts * 3];
// Assign the number of vertices for future use
Objects[objindex].numVerts = numVerts;
// Zero out the normals array
for (int j = 0; j < numVerts * 3; j++)
Objects[objindex].Normals[j] = 0.0f;
// Read the vertices, switching the y and z coordinates and changing the sign of the z coordinate
for (int i = 0; i < numVerts * 3; i+=3)
{
fread(&Objects[objindex].Vertexes[i],sizeof(GLfloat),1,bin3ds);
fread(&Objects[objindex].Vertexes[i+2],sizeof(GLfloat),1,bin3ds);
fread(&Objects[objindex].Vertexes[i+1],sizeof(GLfloat),1,bin3ds);
// Change the sign of the z coordinate
Objects[objindex].Vertexes[i+2] = -Objects[objindex].Vertexes[i+2];
}
// move the file pointer back to where we got it so
// that the ProcessChunk() which we interrupted will read
// from the right place
fseek(bin3ds, findex, SEEK_SET);
}
void Model_3DS::TexCoordsChunkProcessor(Sint32 length, Sint32 findex, int objindex)
{
// The number of texture coordinates
Uint16 numCoords;
// move the file pointer to the beginning of the main
// chunk's data findex + the size of the header
fseek(bin3ds, findex, SEEK_SET);
// Read the number of coordinates
fread(&numCoords,sizeof(numCoords),1,bin3ds);
// Allocate an array to hold the texture coordinates
Objects[objindex].TexCoords = new GLfloat[numCoords * 2];
// Set the number of texture coords
Objects[objindex].numTexCoords = numCoords;
// Read teh texture coordiantes into the array
for (int i = 0; i < numCoords * 2; i+=2)
{
fread(&Objects[objindex].TexCoords[i],sizeof(GLfloat),1,bin3ds);
fread(&Objects[objindex].TexCoords[i+1],sizeof(GLfloat),1,bin3ds);
}
// move the file pointer back to where we got it so
// that the ProcessChunk() which we interrupted will read
// from the right place
fseek(bin3ds, findex, SEEK_SET);
}
void Model_3DS::FacesDescriptionChunkProcessor(Sint32 length, Sint32 findex, int objindex)
{
ChunkHeader h;
Uint16 numFaces; // The number of faces in the object
Uint16 vertA; // The first vertex of the face
Uint16 vertB; // The second vertex of the face
Uint16 vertC; // The third vertex of the face
Uint16 flags; // The winding order flags
Sint32 subs; // Holds our place in the file
int numMatFaces = 0; // The number of different materials
// move the file pointer to the beginning of the main
// chunk's data findex + the size of the header
fseek(bin3ds, findex, SEEK_SET);
// Read the number of faces
fread(&numFaces,sizeof(numFaces),1,bin3ds);
// Allocate an array to hold the faces
Objects[objindex].Faces = new GLushort[numFaces * 3];
// Store the number of faces
Objects[objindex].numFaces = numFaces * 3;
// Read the faces into the array
for (int i = 0; i < numFaces * 3; i+=3)
{
// Read the vertices of the face
fread(&vertA,sizeof(vertA),1,bin3ds);
fread(&vertB,sizeof(vertB),1,bin3ds);
fread(&vertC,sizeof(vertC),1,bin3ds);
fread(&flags,sizeof(flags),1,bin3ds);
// Place them in the array
Objects[objindex].Faces[i] = vertA;
Objects[objindex].Faces[i+1] = vertB;
Objects[objindex].Faces[i+2] = vertC;
// Calculate the face's normal
Vector n;
Vertex v1;
Vertex v2;
Vertex v3;
v1.x = Objects[objindex].Vertexes[vertA*3];
v1.y = Objects[objindex].Vertexes[vertA*3+1];
v1.z = Objects[objindex].Vertexes[vertA*3+2];
v2.x = Objects[objindex].Vertexes[vertB*3];
v2.y = Objects[objindex].Vertexes[vertB*3+1];
v2.z = Objects[objindex].Vertexes[vertB*3+2];
v3.x = Objects[objindex].Vertexes[vertC*3];
v3.y = Objects[objindex].Vertexes[vertC*3+1];
v3.z = Objects[objindex].Vertexes[vertC*3+2];
// calculate the normal
float u[3], v[3];
// V2 - V3;
u[0] = v2.x - v3.x;
u[1] = v2.y - v3.y;
u[2] = v2.z - v3.z;
// V2 - V1;
v[0] = v2.x - v1.x;
v[1] = v2.y - v1.y;
v[2] = v2.z - v1.z;
n.x = (u[1]*v[2] - u[2]*v[1]);
n.y = (u[2]*v[0] - u[0]*v[2]);
n.z = (u[0]*v[1] - u[1]*v[0]);
// Add this normal to its verts' normals
Objects[objindex].Normals[vertA*3] += n.x;
Objects[objindex].Normals[vertA*3+1] += n.y;
Objects[objindex].Normals[vertA*3+2] += n.z;
Objects[objindex].Normals[vertB*3] += n.x;
Objects[objindex].Normals[vertB*3+1] += n.y;
Objects[objindex].Normals[vertB*3+2] += n.z;
Objects[objindex].Normals[vertC*3] += n.x;
Objects[objindex].Normals[vertC*3+1] += n.y;
Objects[objindex].Normals[vertC*3+2] += n.z;
}
// Store our current file position
subs = ftell(bin3ds);
// Check to see how many materials the faces are split into
while (ftell(bin3ds) < (findex + length - 6))
{
fread(&h.id,sizeof(h.id),1,bin3ds);
fread(&h.len,sizeof(h.len),1,bin3ds);
switch (h.id)
{
case FACE_MAT :
//FacesMaterialsListChunkProcessor(h.len, ftell(bin3ds), objindex);
numMatFaces++;
break;
default :
break;
}
fseek(bin3ds, (h.len - 6), SEEK_CUR);
}
// Split the faces up according to their materials
if (numMatFaces > 0)
{
// Allocate an array to hold the lists of faces divided by material
Objects[objindex].MatFaces = new MaterialFaces[numMatFaces];
// Store the number of material faces
Objects[objindex].numMatFaces = numMatFaces;
fseek(bin3ds, subs, SEEK_SET);
int j = 0;
// Split the faces up
while (ftell(bin3ds) < (findex + length - 6))
{
fread(&h.id,sizeof(h.id),1,bin3ds);
fread(&h.len,sizeof(h.len),1,bin3ds);
switch (h.id)
{
case FACE_MAT :
// Process the faces and split them up
FacesMaterialsListChunkProcessor(h.len, ftell(bin3ds), objindex, j);
j++;
break;
default :
break;
}
fseek(bin3ds, (h.len - 6), SEEK_CUR);
}
}
// move the file pointer back to where we got it so
// that the ProcessChunk() which we interrupted will read
// from the right place
fseek(bin3ds, findex, SEEK_SET);
}
void Model_3DS::FacesMaterialsListChunkProcessor(Sint32 length, Sint32 findex, int objindex, int subfacesindex)
{
char name[80]; // The material's name
Uint16 numEntries; // The number of faces associated with this material
Uint16 Face; // Holds the faces as they are read
int material; // An index to the Materials array for this material
int i;
// move the file pointer to the beginning of the main
// chunk's data findex + the size of the header
fseek(bin3ds, findex, SEEK_SET);
// Read the material's name
for (int i = 0; i < 80; i++)
{
name[i] = fgetc(bin3ds);
if (name[i] == 0)
{
name[i] = 0;
break;
}
}
// Faind the material's index in the Materials array
for (material = 0; material < numMaterials; material++)
{
if (strcmp(name, Materials[material].name) == 0)
break;
}
// Store this value for later so that we can find the material
Objects[objindex].MatFaces[subfacesindex].MatIndex = material;
// Read the number of faces associated with this material
fread(&numEntries,sizeof(numEntries),1,bin3ds);
// Allocate an array to hold the list of faces associated with this material
Objects[objindex].MatFaces[subfacesindex].subFaces = new GLushort[numEntries * 3];
// Store this number for later use
Objects[objindex].MatFaces[subfacesindex].numSubFaces = numEntries * 3;
// Read the faces into the array
for (i = 0; i < numEntries * 3; i+=3)
{
// read the face
fread(&Face,sizeof(Face),1,bin3ds);
// Add the face's vertices to the list
Objects[objindex].MatFaces[subfacesindex].subFaces[i] = Objects[objindex].Faces[Face * 3];
Objects[objindex].MatFaces[subfacesindex].subFaces[i+1] = Objects[objindex].Faces[Face * 3 + 1];
Objects[objindex].MatFaces[subfacesindex].subFaces[i+2] = Objects[objindex].Faces[Face * 3 + 2];
}
// move the file pointer back to where we got it so
// that the ProcessChunk() which we interrupted will read
// from the right place
fseek(bin3ds, findex, SEEK_SET);
}
|
; A188039: Positions of 0 in A188038; complement of A188040.
; 2,7,12,19,24,31,36,41,48,53,60,65,70,77,82,89,94,101,106,111,118,123,130,135,140,147,152,159,164,171,176,181,188,193,200,205,210,217,222,229,234,239,246,251,258,263,270,275,280,287,292,299,304,309,316,321,328,333,340,345,350,357,362,369,374,379,386,391,398,403,408,415,420,427,432,439,444,449,456,461,468,473,478,485,490,497,502,509,514,519,526,531,538,543,548,555,560,567,572,579,584,589,596,601,608,613,618,625,630,637,642,647,654,659,666,671,678,683,688,695,700,707,712,717,724,729,736,741,748,753,758,765,770,777,782,787,794,799,806,811,816,823,828,835,840,847,852,857,864,869,876,881,886,893,898,905,910,917,922,927,934,939,946,951,956,963,968,975,980,987,992,997,1004,1009,1016,1021,1026,1033,1038,1045,1050,1055,1062,1067,1074,1079,1086,1091,1096,1103,1108,1115,1120,1125,1132,1137,1144,1149,1156,1161,1166,1173,1178,1185,1190,1195,1202,1207,1214,1219,1224,1231,1236,1243,1248,1255,1260,1265,1272,1277,1284,1289,1294,1301,1306,1313,1318,1325,1330,1335,1342,1347,1354,1359,1364,1371,1376,1383,1388,1393,1400,1405,1412,1417,1424,1429,1434,1441,1446,1453
mov $2,$0
add $2,$0
mov $4,$0
mov $6,1
lpb $6,1
lpb $2,1
sub $2,1
add $5,$0
lpe
mov $3,3
sub $6,1
lpb $5,1
trn $5,$3
add $3,2
lpe
add $1,$3
add $1,6
lpe
lpb $4,1
add $1,3
sub $4,1
lpe
sub $1,7
|
;******************************************************************************
;
; (c) 2006 by BECK IPC GmbH
; http://www.beck-ipc.com
;
;******************************************************************************
;
; Module: usb27.asm
; Function: Dynamic linking of USB-API-Function usbHostGetConfigInfo()
;
;
;******************************************************************************
;
; $Header$
;
;******************************************************************************
INCLUDE usb_api.def
_TEXT SEGMENT BYTE PUBLIC 'CODE'
ASSUME CS:_TEXT, DS:NOTHING, ES:NOTHING, SS:NOTHING
;******************************************************************************
; Prototypes
;******************************************************************************
PUBLIC _usbHostGetConfigInfo
;******************************************************************************
; usbHostGetConfigInfo()
;******************************************************************************
_usbHostGetConfigInfo PROC FAR
LINKER_PATCH ; Will be replaced by dynamic linking code
MOV AX, USB_SERVICE_HOST_GET_CONFIG_INFO ; AH = 0, AL = Function number
INT USB_SWI
; IP-Register will be adjusted on return from software interrupt so that the
; new code is executed immediately.
_usbHostGetConfigInfo ENDP
_TEXT ENDS
END
; End of file
|
/***************************************************************************
* Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht *
* *
* Distributed under the terms of the BSD 3-Clause License. *
* *
* The full license is in the file LICENSE, distributed with this software. *
****************************************************************************/
#ifndef XTENSOR_BUFFER_ADAPTOR_HPP
#define XTENSOR_BUFFER_ADAPTOR_HPP
#include <algorithm>
#include <functional>
#include <iterator>
#include <memory>
#include <stdexcept>
#include <xtl/xclosure.hpp>
#include "xstorage.hpp"
namespace xt
{
/******************************
* xbuffer_adator declaration *
******************************/
struct no_ownership
{
};
struct acquire_ownership
{
};
template <class CP, class O = no_ownership, class A = std::allocator<std::remove_pointer_t<std::remove_reference_t<CP>>>>
class xbuffer_adaptor;
/*********************************
* xbuffer_adator implementation *
*********************************/
namespace detail
{
template <class CP, class A>
class xbuffer_storage
{
public:
using self_type = xbuffer_storage<CP, A>;
using allocator_type = A;
using value_type = typename allocator_type::value_type;
using reference = std::conditional_t<std::is_const<std::remove_pointer_t<std::remove_reference_t<CP>>>::value,
typename allocator_type::const_reference,
typename allocator_type::reference>;
using const_reference = typename allocator_type::const_reference;
using pointer = std::conditional_t<std::is_const<std::remove_pointer_t<std::remove_reference_t<CP>>>::value,
typename allocator_type::const_pointer,
typename allocator_type::pointer>;
using const_pointer = typename allocator_type::const_pointer;
using size_type = typename allocator_type::size_type;
using difference_type = typename allocator_type::difference_type;
xbuffer_storage();
template <class P>
xbuffer_storage(P&& data, size_type size, const allocator_type& alloc = allocator_type());
size_type size() const noexcept;
void resize(size_type size);
pointer data() noexcept;
const_pointer data() const noexcept;
void swap(self_type& rhs) noexcept;
private:
pointer p_data;
size_type m_size;
};
template <class CP, class A>
class xbuffer_owner_storage
{
public:
using self_type = xbuffer_owner_storage<CP, A>;
using allocator_type = A;
using value_type = typename allocator_type::value_type;
using reference = std::conditional_t<std::is_const<std::remove_pointer_t<std::remove_reference_t<CP>>>::value,
typename allocator_type::const_reference,
typename allocator_type::reference>;
using const_reference = typename allocator_type::const_reference;
using pointer = std::conditional_t<std::is_const<std::remove_pointer_t<std::remove_reference_t<CP>>>::value,
typename allocator_type::const_pointer,
typename allocator_type::pointer>;
using const_pointer = typename allocator_type::const_pointer;
using size_type = typename allocator_type::size_type;
using difference_type = typename allocator_type::difference_type;
xbuffer_owner_storage() = default;
template <class P>
xbuffer_owner_storage(P&& data, size_type size, const allocator_type& alloc = allocator_type());
~xbuffer_owner_storage();
xbuffer_owner_storage(const self_type&) = delete;
self_type& operator=(const self_type&);
xbuffer_owner_storage(self_type&&);
self_type& operator=(self_type&&);
size_type size() const noexcept;
void resize(size_type size);
pointer data() noexcept;
const_pointer data() const noexcept;
allocator_type get_allocator() const noexcept;
void swap(self_type& rhs) noexcept;
private:
xtl::xclosure_wrapper<CP> m_data;
size_type m_size;
bool m_moved_from;
allocator_type m_allocator;
};
template <class CP, class A, class O>
struct get_buffer_storage
{
using type = xbuffer_storage<CP, A>;
};
template <class CP, class A>
struct get_buffer_storage<CP, A, acquire_ownership>
{
using type = xbuffer_owner_storage<CP, A>;
};
template <class CP, class A, class O>
using buffer_storage_t = typename get_buffer_storage<CP, A, O>::type;
}
template <class CP, class O, class A>
class xbuffer_adaptor : private detail::buffer_storage_t<CP, A, O>
{
public:
using base_type = detail::buffer_storage_t<CP, A, O>;
using self_type = xbuffer_adaptor<CP, O, A>;
using allocator_type = typename base_type::allocator_type;
using value_type = typename base_type::value_type;
using reference = typename base_type::reference;
using const_reference = typename base_type::const_reference;
using pointer = typename base_type::pointer;
using const_pointer = typename base_type::const_pointer;
using temporary_type = uvector<value_type, allocator_type>;
using size_type = typename base_type::size_type;
using difference_type = typename base_type::difference_type;
using iterator = pointer;
using const_iterator = const_pointer;
using reverse_iterator = std::reverse_iterator<iterator>;
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
xbuffer_adaptor() = default;
template <class P>
xbuffer_adaptor(P&& data, size_type size, const allocator_type& alloc = allocator_type());
~xbuffer_adaptor() = default;
xbuffer_adaptor(const self_type&) = default;
self_type& operator=(const self_type&) = default;
xbuffer_adaptor(self_type&&) = default;
xbuffer_adaptor& operator=(self_type&&) = default;
self_type& operator=(temporary_type&&);
bool empty() const noexcept;
using base_type::size;
using base_type::resize;
reference operator[](size_type i);
const_reference operator[](size_type i) const;
reference front();
const_reference front() const;
reference back();
const_reference back() const;
iterator begin();
iterator end();
const_iterator begin() const;
const_iterator end() const;
const_iterator cbegin() const;
const_iterator cend() const;
reverse_iterator rbegin();
reverse_iterator rend();
const_reverse_iterator rbegin() const;
const_reverse_iterator rend() const;
const_reverse_iterator crbegin() const;
const_reverse_iterator crend() const;
using base_type::data;
using base_type::swap;
};
template <class CP, class O, class A>
bool operator==(const xbuffer_adaptor<CP, O, A>& lhs,
const xbuffer_adaptor<CP, O, A>& rhs);
template <class CP, class O, class A>
bool operator!=(const xbuffer_adaptor<CP, O, A>& lhs,
const xbuffer_adaptor<CP, O, A>& rhs);
template <class CP, class O, class A>
bool operator<(const xbuffer_adaptor<CP, O, A>& lhs,
const xbuffer_adaptor<CP, O, A>& rhs);
template <class CP, class O, class A>
bool operator<=(const xbuffer_adaptor<CP, O, A>& lhs,
const xbuffer_adaptor<CP, O, A>& rhs);
template <class CP, class O, class A>
bool operator>(const xbuffer_adaptor<CP, O, A>& lhs,
const xbuffer_adaptor<CP, O, A>& rhs);
template <class CP, class O, class A>
bool operator>=(const xbuffer_adaptor<CP, O, A>& lhs,
const xbuffer_adaptor<CP, O, A>& rhs);
template <class CP, class O, class A>
void swap(xbuffer_adaptor<CP, O, A>& lhs,
xbuffer_adaptor<CP, O, A>& rhs) noexcept;
/************************************
* temporary_container metafunction *
************************************/
template <class C>
struct temporary_container
{
using type = C;
};
template <class CP, class O, class A>
struct temporary_container<xbuffer_adaptor<CP, O, A>>
{
using type = typename xbuffer_adaptor<CP, O, A>::temporary_type;
};
template <class C>
using temporary_container_t = typename temporary_container<C>::type;
/**********************************
* xbuffer_storage implementation *
**********************************/
namespace detail
{
template <class CP, class A>
inline xbuffer_storage<CP, A>::xbuffer_storage()
: p_data(nullptr), m_size(0)
{
}
template <class CP, class A>
template <class P>
inline xbuffer_storage<CP, A>::xbuffer_storage(P&& data, size_type size, const allocator_type&)
: p_data(std::forward<P>(data)), m_size(size)
{
}
template <class CP, class A>
inline auto xbuffer_storage<CP, A>::size() const noexcept -> size_type
{
return m_size;
}
template <class CP, class A>
inline void xbuffer_storage<CP, A>::resize(size_type size)
{
if (size != m_size)
{
throw std::runtime_error("xbuffer_storage not resizable");
}
}
template <class CP, class A>
inline auto xbuffer_storage<CP, A>::data() noexcept -> pointer
{
return p_data;
}
template <class CP, class A>
inline auto xbuffer_storage<CP, A>::data() const noexcept -> const_pointer
{
return p_data;
}
template <class CP, class A>
inline void xbuffer_storage<CP, A>::swap(self_type& rhs) noexcept
{
using std::swap;
swap(p_data, rhs.p_data);
swap(m_size, rhs.m_size);
}
}
/****************************************
* xbuffer_owner_storage implementation *
****************************************/
namespace detail
{
template <class CP, class A>
template <class P>
inline xbuffer_owner_storage<CP, A>::xbuffer_owner_storage(P&& data, size_type size, const allocator_type& alloc)
: m_data(std::forward<P>(data)), m_size(size), m_moved_from(false), m_allocator(alloc)
{
}
template <class CP, class A>
inline xbuffer_owner_storage<CP, A>::~xbuffer_owner_storage()
{
if (!m_moved_from)
{
safe_destroy_deallocate(m_allocator, m_data.get(), m_size);
m_size = 0;
}
}
template <class CP, class A>
inline auto xbuffer_owner_storage<CP, A>::operator=(const self_type& rhs) -> self_type&
{
using std::swap;
if (this != &rhs)
{
allocator_type al = std::allocator_traits<allocator_type>::select_on_container_copy_construction(rhs.get_allocator());
pointer tmp = safe_init_allocate(al, rhs.m_size);
if (xtrivially_default_constructible<value_type>::value)
{
std::uninitialized_copy(rhs.m_data.get(), rhs.m_data.get() + rhs.m_size, tmp);
}
else
{
std::copy(rhs.m_data.get(), rhs.m_data.get() + rhs.m_size, tmp);
}
swap(m_data.get(), tmp);
m_size = rhs.m_size;
swap(m_allocator, al);
safe_destroy_deallocate(al, tmp, m_size);
}
return *this;
}
template <class CP, class A>
inline xbuffer_owner_storage<CP, A>::xbuffer_owner_storage(self_type&& rhs)
: m_data(std::move(rhs.m_data)), m_size(std::move(rhs.m_size)), m_moved_from(std::move(rhs.m_moved_from)), m_allocator(std::move(rhs.m_allocator))
{
rhs.m_moved_from = true;
rhs.m_size = 0;
}
template <class CP, class A>
inline auto xbuffer_owner_storage<CP, A>::operator=(self_type&& rhs) -> self_type&
{
swap(rhs);
return *this;
}
template <class CP, class A>
inline auto xbuffer_owner_storage<CP, A>::size() const noexcept -> size_type
{
return m_size;
}
template <class CP, class A>
void xbuffer_owner_storage<CP, A>::resize(size_type size)
{
using std::swap;
if (size != m_size)
{
pointer tmp = safe_init_allocate(m_allocator, size);
swap(m_data.get(), tmp);
swap(m_size, size);
safe_destroy_deallocate(m_allocator, tmp, size);
}
}
template <class CP, class A>
inline auto xbuffer_owner_storage<CP, A>::data() noexcept -> pointer
{
return m_data.get();
}
template <class CP, class A>
inline auto xbuffer_owner_storage<CP, A>::data() const noexcept -> const_pointer
{
return m_data.get();
}
template <class CP, class A>
inline auto xbuffer_owner_storage<CP, A>::get_allocator() const noexcept -> allocator_type
{
return allocator_type(m_allocator);
}
template <class CP, class A>
inline void xbuffer_owner_storage<CP, A>::swap(self_type& rhs) noexcept
{
using std::swap;
swap(m_data, rhs.m_data);
swap(m_size, rhs.m_size);
swap(m_allocator, rhs.m_allocator);
}
}
/**********************************
* xbuffer_adaptor implementation *
**********************************/
template <class CP, class O, class A>
template <class P>
inline xbuffer_adaptor<CP, O, A>::xbuffer_adaptor(P&& data, size_type size, const allocator_type& alloc)
: base_type(std::forward<P>(data), size, alloc)
{
}
template <class CP, class O, class A>
inline auto xbuffer_adaptor<CP, O, A>::operator=(temporary_type&& tmp) -> self_type&
{
base_type::resize(tmp.size());
std::copy(tmp.cbegin(), tmp.cend(), begin());
return *this;
}
template <class CP, class O, class A>
bool xbuffer_adaptor<CP, O, A>::empty() const noexcept
{
return size() == 0;
}
template <class CP, class O, class A>
inline auto xbuffer_adaptor<CP, O, A>::operator[](size_type i) -> reference
{
return data()[i];
}
template <class CP, class O, class A>
inline auto xbuffer_adaptor<CP, O, A>::operator[](size_type i) const -> const_reference
{
return data()[i];
}
template <class CP, class O, class A>
inline auto xbuffer_adaptor<CP, O, A>::front() -> reference
{
return data()[0];
}
template <class CP, class O, class A>
inline auto xbuffer_adaptor<CP, O, A>::front() const -> const_reference
{
return data()[0];
}
template <class CP, class O, class A>
inline auto xbuffer_adaptor<CP, O, A>::back() -> reference
{
return data()[size() - 1];
}
template <class CP, class O, class A>
inline auto xbuffer_adaptor<CP, O, A>::back() const -> const_reference
{
return data()[size() - 1];
}
template <class CP, class O, class A>
inline auto xbuffer_adaptor<CP, O, A>::begin() -> iterator
{
return data();
}
template <class CP, class O, class A>
inline auto xbuffer_adaptor<CP, O, A>::end() -> iterator
{
return data() + size();
}
template <class CP, class O, class A>
inline auto xbuffer_adaptor<CP, O, A>::begin() const -> const_iterator
{
return data();
}
template <class CP, class O, class A>
inline auto xbuffer_adaptor<CP, O, A>::end() const -> const_iterator
{
return data() + size();
}
template <class CP, class O, class A>
inline auto xbuffer_adaptor<CP, O, A>::cbegin() const -> const_iterator
{
return begin();
}
template <class CP, class O, class A>
inline auto xbuffer_adaptor<CP, O, A>::cend() const -> const_iterator
{
return end();
}
template <class CP, class O, class A>
inline auto xbuffer_adaptor<CP, O, A>::rbegin() -> reverse_iterator
{
return reverse_iterator(end());
}
template <class CP, class O, class A>
inline auto xbuffer_adaptor<CP, O, A>::rend() -> reverse_iterator
{
return reverse_iterator(begin());
}
template <class CP, class O, class A>
inline auto xbuffer_adaptor<CP, O, A>::rbegin() const -> const_reverse_iterator
{
return const_reverse_iterator(end());
}
template <class CP, class O, class A>
inline auto xbuffer_adaptor<CP, O, A>::rend() const -> const_reverse_iterator
{
return const_reverse_iterator(begin());
}
template <class CP, class O, class A>
inline auto xbuffer_adaptor<CP, O, A>::crbegin() const -> const_reverse_iterator
{
return rbegin();
}
template <class CP, class O, class A>
inline auto xbuffer_adaptor<CP, O, A>::crend() const -> const_reverse_iterator
{
return rend();
}
template <class CP, class O, class A>
inline bool operator==(const xbuffer_adaptor<CP, O, A>& lhs,
const xbuffer_adaptor<CP, O, A>& rhs)
{
return lhs.size() == rhs.size() && std::equal(lhs.begin(), lhs.end(), rhs.begin());
}
template <class CP, class O, class A>
inline bool operator!=(const xbuffer_adaptor<CP, O, A>& lhs,
const xbuffer_adaptor<CP, O, A>& rhs)
{
return !(lhs == rhs);
}
template <class CP, class O, class A>
inline bool operator<(const xbuffer_adaptor<CP, O, A>& lhs,
const xbuffer_adaptor<CP, O, A>& rhs)
{
return std::lexicographical_compare(lhs.begin(), lhs.end(),
rhs.begin(), rhs.end(),
std::less<typename A::value_type>());
}
template <class CP, class O, class A>
inline bool operator<=(const xbuffer_adaptor<CP, O, A>& lhs,
const xbuffer_adaptor<CP, O, A>& rhs)
{
return std::lexicographical_compare(lhs.begin(), lhs.end(),
rhs.begin(), rhs.end(),
std::less_equal<typename A::value_type>());
}
template <class CP, class O, class A>
inline bool operator>(const xbuffer_adaptor<CP, O, A>& lhs,
const xbuffer_adaptor<CP, O, A>& rhs)
{
return std::lexicographical_compare(lhs.begin(), lhs.end(),
rhs.begin(), rhs.end(),
std::greater<typename A::value_type>());
}
template <class CP, class O, class A>
inline bool operator>=(const xbuffer_adaptor<CP, O, A>& lhs,
const xbuffer_adaptor<CP, O, A>& rhs)
{
return std::lexicographical_compare(lhs.begin(), lhs.end(),
rhs.begin(), rhs.end(),
std::greater_equal<typename A::value_type>());
}
template <class CP, class O, class A>
inline void swap(xbuffer_adaptor<CP, O, A>& lhs,
xbuffer_adaptor<CP, O, A>& rhs) noexcept
{
lhs.swap(rhs);
}
}
#endif
|
int isprime(int b)
{
if(b==2)
{
return 1;
}
for(int i=2;i*i<=b;i++)
{
if(b%i==0)
{
return 0;
}
}
return 1;
}
vector<int> Solution::primesum(int A) {
vector<int> a;
for(int i=2;i<A;i++)
{
if(isprime(i)&&isprime(A-i))
{
a.push_back(i);
a.push_back(A-i);
return a;
}
}
}
|
dnl mc68020 mpn_umul_ppmm -- limb by limb multiplication
dnl Copyright 1999, 2000, 2001 Free Software Foundation, Inc.
dnl
dnl This file is part of the GNU MP Library.
dnl
dnl The GNU MP Library is free software; you can redistribute it and/or
dnl modify it under the terms of the GNU Lesser General Public License as
dnl published by the Free Software Foundation; either version 3 of the
dnl License, or (at your option) any later version.
dnl
dnl The GNU MP Library is distributed in the hope that it will be useful,
dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
dnl Lesser General Public License for more details.
dnl
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 mp_limb_t mpn_umul_ppmm (mp_limb_t *lp, mp_limb_t x, mp_limb_t y);
C
PROLOGUE(mpn_umul_ppmm)
movel M(sp,4), a0 C lp
movel M(sp,8), d1 C x
movel M(sp,12), d0 C y
mulul d0, d0:d1
movel d1, M(a0) C low
rts
EPILOGUE(mpn_umul_ppmm)
|
; A088162: n-th prime rotated one binary place to the right less the n-th prime rotated one binary place to the left.
; 0,0,3,0,6,3,21,18,12,3,0,39,33,30,24,15,6,3,90,84,81,72,66,57,45,39,36,30,27,21,0,186,177,174,159,156,147,138,132,123,114,111,96,93,87,84,66,48,42,39,33,24,21,6,381,372,363,360,351,345,342,327,306,300,297,291
seq $0,6005 ; The odd prime numbers together with 1.
sub $0,1
seq $0,80079 ; Least number causing the longest carry sequence when adding numbers <= n to n in binary representation.
div $0,2
mul $0,3
|
// Partitioning of sections and lines for MPI purposes
#include "pentago/end/simple_partition.h"
#include "pentago/base/all_boards.h"
#include "pentago/end/blocks.h"
#include "pentago/end/config.h"
#include "pentago/utility/ceil_div.h"
#include "pentago/utility/debug.h"
#include "pentago/utility/index.h"
#include "pentago/utility/large.h"
#include "pentago/utility/log.h"
#include "pentago/utility/memory_usage.h"
#include "pentago/utility/sort.h"
#include "pentago/utility/random.h"
#include "pentago/utility/const_cast.h"
#include "pentago/utility/box.h"
#include "pentago/utility/sqr.h"
#include "pentago/utility/str.h"
namespace pentago {
namespace end {
using std::min;
using std::max;
using std::make_tuple;
static const uint64_t worst_line = 8*8*8*420;
// A regular grid of 1D block lines with the same section, dimension, and shape
struct chunk_t {
// Section information
section_t section;
Vector<int,4> shape;
// Line information
unsigned dimension : 2; // Line dimension
uint8_t length; // Line length in blocks
Box<Vector<uint8_t,3>> blocks; // Ranges of blocks along the other three dimensions
int count; // Number of lines in this range = blocks.volume()
int node_step; // Number of nodes in all blocks except possibly those at the end of lines
int line_size; // All lines in this line range have the same size
// Running total information, meaningful for owners only
uint64_t block_id; // Unique id of first block (others are indexed consecutively)
uint64_t node_offset; // Total number of nodes in all blocks in lines before this
};
static_assert(sizeof(chunk_t)==64,"");
simple_partition_t::simple_partition_t(const int ranks, const shared_ptr<const sections_t>& sections,
bool save_work)
: partition_t(ranks, sections)
, owner_excess(numeric_limits<double>::infinity())
, total_excess(numeric_limits<double>::infinity())
, max_rank_blocks(0), max_rank_nodes(0) {
GEODE_ASSERT(ranks>0);
Scope scope("simple partition");
thread_time_t time(partition_kind,unevent);
// Each section is a 4D array of blocks, and computing a section requires iterating
// over all its 1D block lines along the four different dimensions. One of the
// dimensions (the most expensive one based on branching factor) is chosen as the
// owner: the rank which computes an owning line owns all contained blocks.
// For now, our partitioning strategy is completely unaware of both graph topology
// and network topology. We simply lay out all lines end to end and give each
// process a contiguous chunk of lines. This is done independently for owning
// and non-owning lines. Since the number of total lines is quite large, we take
// advantage of the fact that for each section dimension, there are at most 8
// different line sizes (depending on whether the line is partial along the 3
// other dimensions). This optimization makes the partitioning computation cheap
// enough to do redundantly across all processes.
// Construct the sets of lines
vector<chunk_t> owner_lines, other_lines;
uint64_t owner_line_count = 0, other_line_count = 0;
for (auto section : sections->sections) {
const auto shape = section.shape();
const Vector<uint8_t,4> blocks_lo(shape/block_size),
blocks_hi(ceil_div(shape,block_size));
const auto sums = section.sums();
GEODE_ASSERT(sums.sum()<36);
const int owner_k = sums.argmin();
const int old_owners = owner_lines.size();
for (int k=0;k<4;k++) {
if (section.counts[k].sum()<9) {
const auto shape_k = shape.remove_index(k);
const auto blocks_lo_k = blocks_lo.remove_index(k),
blocks_hi_k = blocks_hi.remove_index(k);
vector<chunk_t>& lines = owner_k==k ? owner_lines : other_lines;
uint64_t& line_count = owner_k==k ? owner_line_count : other_line_count;
for (int i0=0;i0<2;i0++) {
for (int i1=0;i1<2;i1++) {
for (int i2=0;i2<2;i2++) {
const auto I = vec(i0,i1,i2);
chunk_t chunk;
for (int a=0;a<3;a++) {
if (I[a]) {
chunk.blocks.min[a] = blocks_lo_k[a];
chunk.blocks.max[a] = blocks_hi_k[a];
} else {
chunk.blocks.min[a] = 0;
chunk.blocks.max[a] = blocks_lo_k[a];
}
}
chunk.count = Box<Vector<int,3>>(chunk.blocks).volume();
if (chunk.count) {
chunk.section = section;
chunk.shape = shape;
chunk.dimension = k;
chunk.length = blocks_hi[k];
const int cross_section = block_shape(shape_k,chunk.blocks.min).product();
chunk.line_size = shape[k]*cross_section;
chunk.node_step = block_size*cross_section;
chunk.block_id = chunk.node_offset = (uint64_t)1<<60; // Garbage value
lines.push_back(chunk);
line_count += chunk.count;
}
}
}
}
}
}
// Record the first owner line corresponding to this section
GEODE_ASSERT(owner_lines.size() > size_t(old_owners));
const_cast_(first_owner_line)[section] = old_owners;
}
// Fill in offset information for owner lines
uint64_t block_id = 0, node_offset = 0;
for (auto& chunk : owner_lines) {
chunk.block_id = block_id;
chunk.node_offset = node_offset;
block_id += chunk.length*chunk.count;
node_offset += (uint64_t)chunk.line_size*chunk.count;
}
if (verbose() && sections->sections.size())
slog("total lines = %d %d, total blocks = %s, total nodes = %s",
owner_line_count, other_line_count, large(block_id), large(node_offset));
// Remember
const_cast_(this->owner_lines) = asarray(owner_lines).copy();
const_cast_(this->other_lines) = asarray(other_lines).copy();
GEODE_ASSERT(sections->total_blocks==block_id);
GEODE_ASSERT(sections->total_nodes==node_offset);
// Partition lines between processes, attempting to equalize (1) owned work and (2) total work.
Array<uint64_t> work_nodes(ranks), work_penalties(ranks);
const_cast_(owner_starts) = partition_lines(work_nodes,work_penalties,owner_lines,CHECK_CAST_INT(owner_line_count));
if (verbose() && sections->sections.size()) {
const auto sum = work_nodes.sum(), max = work_nodes.max();
const_cast_(owner_excess) = (double)max/sum*ranks;
const auto penalty_excess = (double)work_penalties.max()/work_penalties.sum()*ranks;
slog("slice %s owned work: all = %s, range = %s %s, excess = %g (%g)",
sections->slice, large(sum), large(work_nodes.min()), large(max), owner_excess, penalty_excess);
GEODE_ASSERT(max<=(owner_line_count+ranks-1)/ranks*worst_line);
}
if (save_work)
const_cast_(owner_work) = work_nodes.copy();
const_cast_(other_starts) = partition_lines(work_nodes,work_penalties,other_lines,CHECK_CAST_INT(other_line_count));
if (verbose() && sections->sections.size()) {
auto sum = work_nodes.sum(), max = work_nodes.max();
const_cast_(total_excess) = (double)max/sum*ranks;
const auto penalty_excess = (double)work_penalties.max()/work_penalties.sum()*ranks;
slog("slice %s total work: all = %s, range = %s %s, excess = %g (%g)",
sections->slice, large(sum), large(work_nodes.min()), large(max), total_excess,
penalty_excess);
GEODE_ASSERT(max<=(owner_line_count+other_line_count+ranks-1)/ranks*worst_line);
}
if (save_work)
const_cast_(other_work) = work_nodes;
// Compute the maximum number of blocks owned by a rank
uint64_t max_blocks = 0,
max_nodes = 0;
Vector<uint64_t,2> start;
for (int rank=0;rank<ranks;rank++) {
const auto end = rank_offsets(rank+1);
max_blocks = max(max_blocks,end[0]-start[0]);
max_nodes = max(max_nodes,end[1]-start[1]);
start = end;
}
const_cast_(this->max_rank_blocks) = CHECK_CAST_INT(max_blocks);
const_cast_(this->max_rank_nodes) = max_nodes;
}
simple_partition_t::~simple_partition_t() {}
// Compute a penalty amount for a line. This is based on (1) the number of blocks and (2) the total memory required by the blocks.
// Penalizing lines based purely on memory is suboptimal, since it results in a wildly varying number of blocks/lines assigned to
// different ranks. Thus, we artificially inflate small blocks and very short lines in order to even things out.
static inline uint64_t line_penalty(const chunk_t& chunk) {
const int block_penalty = sqr(sqr(block_size))*2/3;
return max(chunk.line_size,block_penalty*max((int)chunk.length,4));
}
// Can the remaining work fit within the given bound?
template<bool record> bool simple_partition_t::fit(RawArray<uint64_t> work_nodes, RawArray<uint64_t> work_penalties, RawArray<const chunk_t> lines, const uint64_t bound, RawArray<Vector<int,2>> starts) {
Vector<int,2> start;
int p = 0;
if (start[0]==lines.size()) {
if (record)
starts[p] = start;
goto success;
}
for (;p<work_penalties.size();p++) {
if (record)
starts[p] = start;
uint64_t free = bound-work_penalties[p];
for (;;) {
const auto& chunk = lines[start[0]];
const uint64_t penalty = line_penalty(chunk);
if (free < penalty)
break;
const int count = min(chunk.count-start[1], CHECK_CAST_INT(free/penalty));
free -= count*penalty;
if (record) {
work_nodes[p] += count*(uint64_t)chunk.line_size;
work_penalties[p] += count*penalty;
GEODE_ASSERT(work_penalties[p]<=bound);
}
start[1] += count;
if (start[1] == chunk.count) {
start = vec(start[0]+1,0);
if (start[0]==lines.size())
goto success;
}
}
}
return false; // Didn't manage to distribute all lines
success:
if (record)
starts.slice(p+1, starts.size()).fill(start);
return true;
}
// Divide a set of lines between processes
Array<const Vector<int,2>> simple_partition_t::partition_lines(RawArray<uint64_t> work_nodes, RawArray<uint64_t> work_penalties, RawArray<const chunk_t> lines, const int line_count) {
// Compute a lower bound for how much work each rank needs to do
const int ranks = work_penalties.size();
const uint64_t sum_done = work_penalties.sum(),
max_done = work_penalties.max();
uint64_t left = 0;
for (auto& chunk : lines)
left += chunk.count*line_penalty(chunk);
uint64_t lo = max(max_done,(sum_done+left+ranks-1)/ranks);
// Compute an upper bound based on assuming each line is huge, and dividing them equally between ranks
uint64_t hi = max_done+(line_count+ranks-1)/ranks*worst_line;
GEODE_ASSERT(fit<false>(work_nodes,work_penalties,lines,hi));
// Binary search to find the minimum maximum amount of work
while (lo+1 < hi) {
uint64_t mid = (lo+hi)/2;
(fit<false>(work_nodes,work_penalties,lines,mid) ? hi : lo) = mid;
}
// Compute starts and update work
Array<Vector<int,2>> starts(ranks+1,uninit);
bool success = fit<true>(work_nodes,work_penalties,lines,hi,starts);
GEODE_ASSERT(success);
GEODE_ASSERT(starts.back()==vec(lines.size(),0));
return starts;
}
uint64_t simple_partition_t::memory_usage() const {
return sizeof(simple_partition_t)
+ pentago::memory_usage(sections)
+ pentago::memory_usage(owner_lines)
+ pentago::memory_usage(other_lines)
+ pentago::memory_usage(first_owner_line)
+ pentago::memory_usage(owner_starts)
+ pentago::memory_usage(other_starts)
+ pentago::memory_usage(owner_work)
+ pentago::memory_usage(other_work);
}
Vector<uint64_t,2> simple_partition_t::rank_offsets(int rank) const {
// This is essentially rank_lines copied and pruned to touch only the first line
GEODE_ASSERT(0<=rank && rank<=ranks);
if (rank==ranks)
return vec(sections->total_blocks,sections->total_nodes);
const auto start = owner_starts[rank];
if (start[0]==owner_lines.size())
return vec(sections->total_blocks,sections->total_nodes);
const auto& chunk = owner_lines[start[0]];
return vec(chunk.block_id+(uint64_t)chunk.length*start[1],
chunk.node_offset+(uint64_t)chunk.line_size*start[1]);
}
Array<const line_t> simple_partition_t::rank_lines(int rank) const {
return concat<line_t>(rank_lines(rank, true), rank_lines(rank,false));
}
Array<line_t> simple_partition_t::rank_lines(int rank, bool owned) const {
GEODE_ASSERT(0<=rank && rank<ranks);
RawArray<const chunk_t> all_lines = owned?owner_lines:other_lines;
RawArray<const Vector<int,2>> starts = owned?owner_starts:other_starts;
const auto start = starts[rank], end = starts[rank+1];
vector<line_t> result;
for (int r : range(start[0], min(end[0]+1, all_lines.size()))) {
const auto& chunk = all_lines[r];
const Vector<int,3> sizes(chunk.blocks.shape());
for (int k : range(r==start[0]?start[1]:0,r==end[0]?end[1]:chunk.count)) {
line_t line;
line.section = chunk.section;
line.dimension = chunk.dimension;
line.length = chunk.length;
line.block_base = chunk.blocks.min+Vector<uint8_t,3>(decompose(sizes,k));
result.push_back(line);
}
}
return asarray(result).copy();
}
Array<const local_block_t> simple_partition_t::rank_blocks(int rank) const {
vector<local_block_t> blocks;
for (const auto& line : rank_lines(rank,true))
for (const int b : range(int(line.length))) {
local_block_t block;
block.local_id = local_id_t(blocks.size());
block.section = line.section;
block.block = line.block(b);
blocks.push_back(block);
}
return asarray(blocks).copy();
}
tuple<int,local_id_t> simple_partition_t::find_block(const section_t section, const Vector<uint8_t,4> block) const {
const int rank = block_to_rank(section,block);
const local_id_t id(CHECK_CAST_INT(block_to_id(section,block)-rank_offsets(rank)[0]));
return make_tuple(rank,id);
}
tuple<section_t,Vector<uint8_t,4>> simple_partition_t::rank_block(const int rank, const local_id_t local_id) const {
const uint64_t block_id = rank_offsets(rank)[0]+local_id.id;
// Binary search to find containing line
GEODE_ASSERT(owner_lines.size());
int lo = 0, hi = owner_lines.size()-1;
while (lo<hi) {
const int mid = (lo+hi+1)/2;
if (owner_lines[mid].block_id <= block_id)
lo = mid;
else
hi = mid-1;
}
const chunk_t& chunk = owner_lines[lo];
// Compute block
const int i = CHECK_CAST_INT(block_id-chunk.block_id);
const auto shape = concat(Vector<int,3>(chunk.blocks.shape()), Vector<int,1>(chunk.length));
GEODE_ASSERT((unsigned)i<=(unsigned)shape.product());
const auto I = decompose(shape, i);
const auto block = (chunk.blocks.min + Vector<uint8_t,3>(I.remove_index(3)))
.insert(I[3], chunk.dimension);
return make_tuple(chunk.section,block);
}
uint64_t simple_partition_t::rank_count_lines(int rank) const {
return rank_count_lines(rank,false)
+ rank_count_lines(rank,true);
}
uint64_t simple_partition_t::rank_count_lines(int rank, bool owned) const {
GEODE_ASSERT(0<=rank && rank<ranks);
RawArray<const chunk_t> all_lines = owned?owner_lines:other_lines;
RawArray<const Vector<int,2>> starts = owned?owner_starts:other_starts;
const auto start = starts[rank], end = starts[rank+1];
uint64_t result = 0;
for (int r : range(start[0],end[0]+1))
result += (r==end[0]?end[1]:all_lines[r].count) - (r==start[0]?start[1]:0);
return result;
}
Vector<uint64_t,2> simple_partition_t::rank_counts(int rank) const {
return rank_offsets(rank+1)-rank_offsets(rank);
}
// Find the rank which owns a given block
int simple_partition_t::block_to_rank(section_t section, Vector<uint8_t,4> block) const {
// Find the line range and specific line that contains this block
const auto line = block_to_line(section,block);
// Perform a binary search to find the right rank.
// Invariants: owner_starts[lo] <= line < owner_starts[hi]
int lo = 0, hi = ranks;
while (lo+1 < hi) {
const int mid = (lo+hi)/2;
const auto start = owner_starts[mid];
(line[0]<start[0] || (line[0]==start[0] && line[1]<start[1]) ? hi : lo) = mid;
}
return lo;
}
// Find the line that owns a given block
Vector<int,2> simple_partition_t::block_to_line(section_t section, Vector<uint8_t,4> block) const {
int index = check_get(first_owner_line, section);
const int owner_k = owner_lines[index].dimension;
const auto block_k = block.remove_index(owner_k);
do {
const auto& blocks = owner_lines[index].blocks;
for (int a=0;a<3;a++)
if (!(blocks.min[a]<=block_k[a] && block_k[a]<blocks.max[a]))
goto skip;
// We've locate the range of lines that contains (and owns) the block. Now isolate the exact line.
{
const Vector<int,3> I(block_k - blocks.min),
sizes(blocks.shape());
return vec(index,pentago::index(sizes,I));
}
// The block isn't contained in this line range
skip:;
index++;
} while (owner_lines.valid(index) && owner_lines[index].section==section);
die("block_to_line failed: section %s, blocks %s, block %s",str(section),str(section_blocks(section)),str(Vector<int,4>(block)));
}
uint64_t simple_partition_t::block_to_id(section_t section, Vector<uint8_t,4> block) const {
const auto I = block_to_line(section,block);
const auto& chunk = owner_lines[I[0]];
const int j = block[chunk.dimension];
return chunk.block_id+(uint64_t)chunk.length*I[1]+j;
}
}
}
|
; A108852: Number of Fibonacci numbers <= n.
; 1,3,4,5,5,6,6,6,7,7,7,7,7,8,8,8,8,8,8,8,8,9,9,9,9,9,9,9,9,9,9,9,9,9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11
lpb $0,8
mul $0,5
add $0,1
mov $1,$0
div $0,8
add $3,1
lpe
mov $1,$3
add $1,1
|
#include "XGenerateReportThread.h"
#include <QDir>
namespace XReport{
XGenerateReportThread::XGenerateReportThread(XGenerateReportBase * generator /*= 0*/)
:m_generator(generator)
{
}
XGenerateReportThread::~XGenerateReportThread()
{
}
void XGenerateReportThread::generatePictures(const QStringList & pictures)
{
m_pictures = pictures;
if (!m_timer)
{
m_timer = new QTimer();
connect(m_timer, SIGNAL(timeout()), this, SLOT(slot_generate_picture()));
}
}
void XGenerateReportThread::run()
{
if (m_generator)
{
QString info;
bool bResult = m_generator->generate(info);
emit sig_generate_finished(bResult, info);
}
}
void XGenerateReportThread::slot_generate_picture()
{
if (m_pictures.isEmpty())
{
m_timer->stop();
return;
}
QString file = m_pictures.at(0);
bool bResult = m_generator->generatePicture(file);
m_pictures.removeOne(file);
}
}
|
; *******************************************************************************************
; *******************************************************************************************
;
; Name : vargetset.asm
; Purpose : Copy variable data to and from the mantissa,x
; Date : 25th August 2019
; Author : Paul Robson (paul@robsons.org.uk)
;
; *******************************************************************************************
; *******************************************************************************************
; *******************************************************************************************
;
; Copy data in zVarDataPtr/zVarType => Mantissa in correct format.
;
; *******************************************************************************************
VariableGet:
phy
ldy #0 ; copy first two bytes
lda (zVarDataPtr),y
sta XS_Mantissa,x
iny
lda (zVarDataPtr),y
sta XS_Mantissa+1,x
iny
;
lda zVarType ; if it is a string, set up for that.
cmp #token_Dollar
beq _VGString
;
lda (zVarDataPtr),y ; copy the next two bytes.
sta XS_Mantissa+2,x
iny
lda (zVarDataPtr),y
sta XS_Mantissa+3,x
iny
lda #1 ; set type to 1.
sta XS_Type,x
lda zVarType
cmp #token_Percent ; if it is a %, then exit with default integer.
beq _VGExit
;
; Set up an exponent.
;
lda #$40 ; set type byte to zero
sta XS_Type,x ; which is the code for zero/float.
lda (zVarDataPtr),y ; the last value to copy is the exponent.
sta XS_Exponent,x
beq _VGExit ; if exponent is zero ... it's zero.
;
lda XS_Mantissa+3,x ; the sign bit is the top mantissa bit.
pha
and #$80
sta XS_Type,x ; this is the type byte.
pla
ora #$80 ; set the MSB as you would expect.
sta XS_Mantissa+3,x ; so it's a normalised float.
bra _VGExit
;
; Handle string.
;
_VGString:
lda #2 ; set type to 2, a string
sta XS_Type,x
lda XS_Mantissa,x ; is the value there $0000
ora XS_Mantissa+1,x
bne _VGExit ; if not, exit.
;
sta zNullString ; make zNullString a 00 string.
lda #zNullString
sta XS_Mantissa,x ; make it point to it.
_VGExit: ; exit
ply
rts
; *******************************************************************************************
;
; Copy data in Mantissa => zVarDataPtr/zVarType, typecasting/checking
;
; *******************************************************************************************
VariableSet:
lda XS_Type,x ; is the result a string
and #2 ; if so, it has to be
bne _VSString
;
lda zVarType ; if type is $ there's an error.
cmp #token_Dollar
beq _VSBadType
;
.if hasFloat==1
cmp #token_Percent ; type convert to float/int
beq _VSMakeInt
jsr FPUToFloat
bra _VSCopy
;
_VSMakeInt:
jsr FPUToInteger
;
.endif
_VSCopy:
phy
ldy #0 ; copy mantissa to target.
lda XS_Mantissa+0,x
sta (zVarDataPtr),y
iny
lda XS_Mantissa+1,x
sta (zVarDataPtr),y
iny
lda XS_Mantissa+2,x
sta (zVarDataPtr),y
iny
lda XS_Mantissa+3,x
sta (zVarDataPtr),y
;
lda zVarType ; if target is integer, alrady done.
cmp #token_Percent
beq _VSExit
;
lda XS_Type,x ; get the sign bit into carry flag.
asl a
;
lda XS_Mantissa+3,x ; shift the sign into the mantissa high.
php
asl a
plp
ror a
sta (zVarDataPtr),y
;
iny
lda XS_Exponent,x ; copy the exponent in
sta (zVarDataPtr),y
;
bit XS_Type,x ; if the result is non zero
bvc _VSExit
;
lda #0 ; zero exponent indicating 0.
sta (zVarDataPtr),y
;
_VSExit:
ply
rts
_VSBadType:
jmp TypeError
;
; Assign a string.
;
_VSString:
lda zVarType ; type must be $
cmp #token_Dollar
bne _VSBadType
;
;
phx
phy
jsr StringConcrete ; concrete the string in the mantissa -> AX
ldy #1 ; save high byte
sta (zVarDataPtr),y
dey ; save low byte
txa
sta (zVarDataPtr),y
ply ; and exit.
plx
rts
|
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Copyright (c) GeoWorks 1992 -- All Rights Reserved
PROJECT: PC GEOS
MODULE:
FILE: bigcalcProcess.asm
AUTHOR: Christian Puscasiu, Feb 27, 1992
ROUTINES:
Name Description
---- -----------
INT BigCalcProcessCheckForWorksheets Will enable or disable the option
to have worksheets in the Customize menu.
In case the worksheets are on they will be
switched of if the .ini file wants to not
display them
INT BigCalcProcessLocalize Handle localizing stuff based on system
settings
INT BigCalcProcessSetEngineOffset sets the math engine
INT BigCalcProcessBringUpAllDescriptions brings up the descriptions of
the worksheets
INT BigCalcProcessDisplayLineOnPaperTape displays a line on the
papertape
INT BigCalcProcessSetUsable sets the object that's passed in bx:si
usable
INT BigCalcProcessSetNotUsable sets the object in bx:si not usable
INT BigCalcProcessMoveButtonsUp moves C/CE and <- button up when small
configuration of the calculator is
requested
INT BigCalcProcessMoveButtonsDown moves C/CE and <- button down when
small configuration is left
INT BigCalcProcessPreFloatDup utility function for proper fp
calculation
INT BigCalcProcessConvertToUpper makes the e into E in scientific
notation
REVISION HISTORY:
Name Date Description
---- ---- -----------
CP 2/27/92 Initial revision
DESCRIPTION:
Implements the BigCalcProcessClass
$Id: bigcalcProcess.asm,v 1.1 97/04/04 14:38:23 newdeal Exp $
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
udata segment
restoringFromState byte (FALSE)
udata ends
idata segment
extensionState ExtensionType mask EXT_MATH
calculatorMode CalculatorMode CM_INFIX
inverse BooleanByte BB_FALSE
idata ends
ProcessCode segment
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
BigCalcProcessOpenApplication
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: initializes the stack
CALLED BY: opening thread
PASS: *ds:si = BigCalcProcessClass object
ds:di = BigCalcProcessClass instance data
ds:bx = BigCalcProcessClass object (same as *ds:si)
ax = message #
RETURN: nothing
DESTROYED: nothing
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
CP 3/ 3/92 Initial version
andres 10/ 7/96 Made separate handler for PENELOPE
version
andres 10/26/96 Don't need to check for worksheets in
DOVE
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
BigCalcProcessOpenApplication method dynamic BigCalcProcessClass,
MSG_GEN_PROCESS_OPEN_APPLICATION
uses ax, cx, dx, bp
.enter
;
; Only check .INI flag for worksheets if not restoring from state
;
test cx, mask AAF_RESTORING_FROM_STATE
jnz doLocalization
call BigCalcProcessCheckForAvailableFeatures
doLocalization:
call BigCalcProcessLocalize
;
; let the right things happen automatically
;
mov di, offset BigCalcProcessClass
call ObjCallSuperNoLock
;
; set the default engine
;
call BigCalcProcessSetEngineOffset
;
; get me a nice chunck of Memory for my floating point stack
;
mov ax, FP_STACK_LENGTH
mov bl, FLOAT_STACK_WRAP
call FloatInit
call Float0
;
; get a handle for the operator stack
; Use clear all to initialize instance data and set the various
; operation state bits
;
mov bx, handle BigCalcInfixEngine
mov si, offset BigCalcInfixEngine
clr di
mov ax, MSG_CE_CLEAR_ALL
call ObjMessage
;;; call SetConvertCurrencyMenuItems ; set exchange rate menu items.
cmp ss:[restoringFromState], TRUE
je done
mov bx, handle OptionsMenu
mov si, offset OptionsMenu
clr di
mov ax, MSG_META_LOAD_OPTIONS
call ObjMessage
call BigCalcProcessBringUpAllDescriptions
done:
.leave
ret
BigCalcProcessOpenApplication endm
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
BigCalcProcessCheckForAvailableFeatures
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Make available various features based upon .INI settings
CALLED BY: BigCalcProcessOpenApplication
PASS: nothing
RETURN: nothing
DESTROYED: nothing
SIDE EFFECTS:
PSEUDO CODE/STRATEGY:
- check for paper roll option
- check for worksheets option
REVISION HISTORY:
Name Date Description
---- ---- -----------
CP 12/10/92 Initial version
andres 10/29/96 Don't need this for DOVE
Don 2/7/99 Tweaked for GPC
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
configureString char "bigcalc", 0
worksheetString char "worksheets", 0
paperrollString char "papertape", 0
BigCalcProcessCheckForAvailableFeatures proc near
uses ax,bx,cx,dx,si,di,bp,ds,es
.enter
;
; Read the worksheets value from the .INI file.
; Default behavior is that worksheets are available
;
segmov ds, cs, cx
mov si, offset configureString ;ds:si <- category
mov dx, offset paperrollString ;cx:dx <- key
mov ax, FALSE
call InitFileReadBoolean
push ax
mov dx, offset worksheetString ;cx:dx <- key
mov ax, TRUE
call InitFileReadBoolean
tst ax
jnz checkPaperRoll
;
; Turn off both the options UI and the actual worksheets
;
mov bx, handle WorksheetsGroup
mov si, offset WorksheetsGroup
call BigCalcProcessSetNotUsable
mov ax, MSG_BC_PROCESS_CHANGE_WORKSHEETS_STATE
call GeodeGetProcessHandle
mov cx, FALSE
mov di, mask MF_CALL
call ObjMessage
;
; OK, now do the same for the paper roll (aka paper tape)
; Default behavior is that the paper roll is *not* available
;
checkPaperRoll:
pop ax ; restore .INI setting
tst ax
jz done
;
; Turn on both the options UI and the actual paper roll
;
mov bx, handle PaperRollGroup
mov si, offset PaperRollGroup
call BigCalcProcessSetUsable
mov ax, MSG_BC_PROCESS_CHANGE_PAPER_ROLL_STATE
call GeodeGetProcessHandle
mov cx, TRUE
mov di, mask MF_CALL
call ObjMessage
done:
.leave
ret
BigCalcProcessCheckForAvailableFeatures endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
BigCalcProcessLocalize
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Handle localizing stuff based on system settings
CALLED BY: BigCalcProcessOpenApplication()
PASS: none
RETURN: none
DESTROYED: none
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
gene 6/16/93 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
BigCalcProcessLocalize proc near
uses ax,bx,cx,dx,si,di,bp,ds,es
.enter
;
; Get the numeric format and see if it is what we expect
;
call LocalGetNumericFormat ;cx <- decimal point
;dx <- list separator
;segmov ds, dgroup, ax
GetResourceSegmentNS dgroup, ds
SBCS< mov ds:[listSeparator], dl
DBCS< mov ds:[listSeparator], dx
cmp cx, '.' ;U.S. default?
je done
;
; The decimal separator is different. The ATTR_GEN_TRIGGER_ACTION_DATA
; for the "." key is the data for MSG_META_KBD_CHAR, in the order:
; cx = character value
; dl = CharFlags
; dh = ShiftState
; bp low = ToggleState
; bp high = scan code
; We unnecessarily use the same registers here because they are handy.
;
clr bp
push bp, cx ;<- NULL, char
mov dx, mask CF_FIRST_PRESS
push bp ;<- bp.low, bp.high
push dx ;<- CharFlags, ShiftState
push cx ;<- char value
mov dx, sp
sub sp, (size AddVarDataParams)
mov bp, sp ;ss:bp <- AddVarDataParams
movdw ss:[bp].AVDP_data, ssdx ;ptr to data
mov ss:[bp].AVDP_dataSize, 3*(size word)
mov ss:[bp].AVDP_dataType, ATTR_GEN_TRIGGER_ACTION_DATA
mov ax, MSG_META_ADD_VAR_DATA
call callPointTrigger
add sp, (size AddVarDataParams)+3*(size word)
;
; Set the moniker to the same character, which is on the stack
;
movdw cxdx, sssp ;cx:dx <- ptr to text
mov ax, MSG_GEN_REPLACE_VIS_MONIKER_TEXT
mov bp, VUM_DELAYED_VIA_APP_QUEUE
call callPointTrigger
pop bp, cx
done:
.leave
ret
callPointTrigger:
mov di, mask MF_CALL
mov bx, handle ButtonPoint
mov si, offset ButtonPoint ;^lbx:si <- OD of trigger
call ObjMessage
retn
BigCalcProcessLocalize endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
BigCalcProcessSetEngineOffset
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: sets the math engine
CALLED BY: BigCalcProcessOpenApplication
PASS: ES = DGroup
RETURN: nothing
DESTROYED: nothing
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
CP 6/10/92 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
BigCalcProcessSetEngineOffset proc near
uses ax,bx,cx,dx,si,di,bp
.enter
mov bx, handle ModeItemGroup
mov si, offset ModeItemGroup
mov di, mask MF_CALL
mov ax, MSG_GEN_ITEM_GROUP_GET_SELECTION
call ObjMessage
cmp ax, CM_RPN
if _RPN_CAPABILITY
mov ax, offset BigCalcRPNEngine
endif
je setEngine
mov ax, offset BigCalcInfixEngine
setEngine:
mov ss:[engineOffset], ax
.leave
ret
BigCalcProcessSetEngineOffset endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
BigCalcProcessBringUpAllDescriptions
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: brings up the descriptions of the worksheets
CALLED BY: BigCalcProcessOpenApplication
PASS: nothing
RETURN: nothing
DESTROYED: nothing
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
CP 6/15/92 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
BigCalcProcessBringUpAllDescriptions proc near
uses ax,cx,dx,bp
.enter
mov bx, handle SalesChooser
mov si, offset SalesChooser
clr di
mov cx, PCFID_SALES_TAX
mov ax, MSG_PCF_CHOOSER_CHANGE_DESCRIPTION
call ObjMessage
mov bx, handle SSheetChooser
mov si, offset SSheetChooser
clr di
mov cx, PCFID_CTERM
call ObjMessage
if _STATISTICAL_FORMS
mov bx, handle StatsChooser
mov si, offset StatsChooser
clr di
mov cx, PCFID_SUM
call ObjMessage
endif ;if _STATISTICAL_FORMS
mov bx, handle ConsumerChooser
mov si, offset ConsumerChooser
clr di
mov cx, PCFID_CAR_MILAGE
call ObjMessage
.leave
ret
BigCalcProcessBringUpAllDescriptions endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
BigCalcProcessRestoreFromState
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: restores from state
CALLED BY:
PASS: *ds:si = BigCalcProcessClass object
ds:di = BigCalcProcessClass instance data
ds:bx = BigCalcProcessClass object (same as *ds:si)
es = segment of BigCalcProcessClass
ax = message #
RETURN:
DESTROYED:
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
CP 6/28/92 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
if (NOT FALSE)
BigCalcProcessRestoreFromState method dynamic BigCalcProcessClass,
MSG_GEN_PROCESS_RESTORE_FROM_STATE
uses ax, cx, dx, bp
.enter
push ds
mov bx, bp
call MemLock
mov ds, ax
mov ax, ds:[0]
mov ss:[extensionState], ax
mov ax, ds:[2]
mov ss:[calculatorMode], ax
mov al, ds:[4]
mov ss:[inverse], al
call MemUnlock
mov ss:[restoringFromState], TRUE
pop ds
mov ax, MSG_GEN_PROCESS_RESTORE_FROM_STATE
mov di, offset BigCalcProcessClass
call ObjCallSuperNoLock
mov bx, handle BigCalcNumberDisplay
mov si, offset BigCalcNumberDisplay
mov bp, offset textBuffer
mov dx, ss
SBCS< mov {char} ss:[bp], '0' >
DBCS< mov {wchar} ss:[bp], '0' >
mov cx, 1
mov di, mask MF_CALL
mov ax, MSG_VIS_TEXT_REPLACE_ALL_PTR
call ObjMessage
.leave
ret
BigCalcProcessRestoreFromState endm
endif
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
BigCalcProcessCloseApplication
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: XX will save the state at some point...
CALLED BY:
PASS: *ds:si = BigCalcProcessClass object
ds:di = BigCalcProcessClass instance data
ds:bx = BigCalcProcessClass object (same as *ds:si)
ax = message #
RETURN: cx = handle of extra state block
DESTROYED: nothing
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
CP 3/ 3/92 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
if (NOT FALSE)
BigCalcProcessCloseApplication method dynamic BigCalcProcessClass,
MSG_GEN_PROCESS_CLOSE_APPLICATION
;
; free the floating point stack
;
call FloatExit
;
; Save out some extra state
;
mov ax, 5
mov cx, ALLOC_DYNAMIC_NO_ERR_LOCK
call MemAlloc ; handle => BX,
; segment => AX
mov ds, ax
mov ax, ss:[extensionState]
mov ds:[0], ax
mov ax, ss:[calculatorMode]
mov ds:[2], ax
mov al, ss:[inverse]
mov ds:[4], al
call MemUnlock
mov cx, bx ; extra state block => CX
ret
BigCalcProcessCloseApplication endm
endif
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
BCPButtonZzzPressed
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Called when the 000 button is pressed in the DOVE
version of the calculator. Fakes three '0' button
presses.
CALLED BY: MSG_BCP_BUTTON_ZZZ_PRESSED
PASS: *ds:si = BigCalcProcessClass object
ds:di = BigCalcProcessClass instance data
ds:bx = BigCalcProcessClass object (same as *ds:si)
es = segment of BigCalcProcessClass
ax = message #
RETURN: nothing
DESTROYED: nothing
SIDE EFFECTS: nothing
PSEUDO CODE/STRATEGY:
REVISION HISTORY:
Name Date Description
---- ---- -----------
andres 10/30/96 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
BigCalcProcessOperation
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: sends the opertaion to the approprite engine (RPN/Infix)
CALLED BY: various trigegrs on the calculator
PASS: *ds:si = BigCalcProcessClass object
ds:di = BigCalcProcessClass instance data
ds:bx = BigCalcProcessClass object (same as *ds:si)
es = dgroup
ax = message #
RETURN: nothing
DESTROYED: nothing
PSEUDO CODE/STRATEGY:
looks at the global variable and determines from there where
the arithmetic message will be sent
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
CP 3/17/92 Initial version
EC 5/24/96 Added display requirements for different
operators [Penelope]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
if (NOT FALSE)
BigCalcProcessOperation method dynamic BigCalcProcessClass,
MSG_BC_PROCESS_CLEAR_ALL,
MSG_BC_PROCESS_PLUS,
MSG_BC_PROCESS_Y_TO_X,
MSG_BC_PROCESS_MINUS,
MSG_BC_PROCESS_ONE_OVER,
MSG_BC_PROCESS_TIMES,
MSG_BC_PROCESS_SQUARE,
MSG_BC_PROCESS_DIVIDE,
MSG_BC_PROCESS_SQUARE_ROOT,
MSG_BC_PROCESS_ENTER,
MSG_BC_PROCESS_PERCENT,
MSG_BC_PROCESS_PLUSMINUS,
MSG_BC_PROCESS_INVERSE,
MSG_BC_PROCESS_SINE,
MSG_BC_PROCESS_COSINE,
MSG_BC_PROCESS_TANGENT,
MSG_BC_PROCESS_LN,
MSG_BC_PROCESS_LOG,
MSG_BC_PROCESS_PI,
MSG_BC_PROCESS_E,
MSG_BC_PROCESS_FACTORIAL,
MSG_BC_PROCESS_ARC_SINE,
MSG_BC_PROCESS_ARC_COSINE,
MSG_BC_PROCESS_ARC_TANGENT,
MSG_BC_PROCESS_E_TO_X,
MSG_BC_PROCESS_TEN_TO_X,
MSG_BC_PROCESS_PI_OVER_TWO,
MSG_BC_PROCESS_LEFT_PAREN,
MSG_BC_PROCESS_RIGHT_PAREN,
MSG_BC_PROCESS_SWAP,
MSG_BC_PROCESS_ROLL_DOWN,
MSG_BC_PROCESS_DISPLAY_CONSTANT_TOP_OF_STACK,
MSG_BC_PROCESS_CONVERT
uses ax
.enter
;
; save message
;
push ax,cx
mov bx, handle BigCalcNumberDisplay
mov si, offset BigCalcNumberDisplay
if 0 ; This logic has been moved to
; CalcInputFieldVisTextFilterViaBeforeAfter. -dhunter 9/11/00
mov di, mask MF_FIXUP_DS
mov ax, MSG_CALC_IF_CHECK_ENTER_BIT
call ObjMessage
jnc doOperation
call BigCalcProcessPreFloatDup
call FloatDup
doOperation:
endif
mov di, mask MF_FIXUP_DS
mov ax, MSG_CALC_IF_CLEAR_ENTER_BIT
call ObjMessage
;
; retrieve message
;
pop ax,cx
;
; HACK!!!!!!!
;
; the ordering of all the MSG_BC_PROCESS_operation is the exact
; the same as the MSG_CE_opertion so the ax we want is achieved
; by the add down below
;
add ax, MSG_CE_PLUS - MSG_BC_PROCESS_PLUS
mov bx, handle CalcResource
mov si, ss:[engineOffset]
clr di
call ObjMessage
; plus-minus should not close out an operation
cmp ax, MSG_CE_PLUSMINUS
LONG jz done
if (NOT FALSE)
call BigCalcProcessDisplayLineOnPaperTape
endif
call CEDisplayTopOfStack
if (NOT FALSE)
call CEDisplayOnPaperTapeWithDXBP
endif
mov bx, handle BigCalcNumberDisplay
mov si, offset BigCalcNumberDisplay
mov di, mask MF_FIXUP_DS
mov ax, MSG_CALC_IF_SET_OP_DONE_BIT
call ObjMessage
done:
.leave
ret
BigCalcProcessOperation endm
endif
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
BigCalcProcessDisplayLineOnPaperTape
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: displays a line on the papertape
CALLED BY:
PASS: nothing
RETURN: nothing
DESTROYED: nothing
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
CP 6/12/92 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
BigCalcProcessDisplayLineOnPaperTape proc near
uses ax,bx,cx,dx,si,di,bp
.enter
mov bx, handle CalcResource
mov si, offset BigCalcPaperRoll
mov di, mask MF_CALL
mov ax, MSG_GEN_GET_USABLE
call ObjMessage
jnc done
mov dx, bx
mov bp, offset PaperRollLine
clr cx, di
mov ax, MSG_VIS_TEXT_APPEND_OPTR
call ObjMessage
clr di
mov ax, MSG_PAPER_ROLL_CHECK_LENGTH
call ObjMessage
done:
.leave
ret
BigCalcProcessDisplayLineOnPaperTape endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
BigCalcProcessClear
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: clears the math engine
CALLED BY:
PASS: *ds:si = BigCalcProcessClass object
ds:di = BigCalcProcessClass instance data
ds:bx = BigCalcProcessClass object (same as *ds:si)
es = dgroup
ax = message #
RETURN:
DESTROYED:
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
CP 4/14/92 Initial version
andres 9/24/96 Fix to always display 0 in digital
display
andres 9/30/96 Set firstDigitOfNewOperand flag
andres 10/17/96 clear PFR_replaceOp
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
BigCalcProcessClear method dynamic BigCalcProcessClass,
MSG_BC_PROCESS_CLEAR
uses ax, cx, dx, bp
.enter
mov bx, handle CalcResource
GetResourceSegmentNS dgroup, es
mov si, ss:[engineOffset]
clr di
mov ax, MSG_CE_CLEAR
call ObjMessage
.leave
ret
BigCalcProcessClear endm
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
BigCalcProcessChangeMode
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: changes the calculator mode
CALLED BY:
PASS: ds,es = dgroup
cx = CalculatorMode to switch to
RETURN:
DESTROYED:
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
CP 4/17/92 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
if _RPN_CAPABILITY
BigCalcProcessChangeMode method dynamic BigCalcProcessClass,
MSG_BC_PROCESS_CHANGE_MODE
uses ax, cx, dx, bp
.enter
mov ss:[calculatorMode], cx
mov ax, MSG_CE_SET_RPN_MODE
cmp cx, CM_RPN
je setMode
mov ax, MSG_CE_SET_INFIX_MODE
setMode:
mov bx, handle CalcResource
mov si, ss:[engineOffset]
; mov si, offset BigCalcInfixEngine
clr di
call ObjMessage
; Tell the application object that a user option has changed
;
call BigCalcNotifyOptionsChange
.leave
ret
BigCalcProcessChangeMode endm
endif ;if _RPN_CAPABILITY
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
BigCalcProcessUpdateNumber
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: updates the number in the display according to the setting
in the Customize box
CALLED BY: MSG_BC_PROCESS_UPDATE_NUMBER
PASS: *ds:si = BigCalcProcessClass object
ds:di = BigCalcProcessClass instance data
ds:bx = BigCalcProcessClass object (same as *ds:si)
es = segment of BigCalcProcessClass
ax = message #
RETURN: nothing
DESTROYED: nothing
SIDE EFFECTS:
PSEUDO CODE/STRATEGY:
REVISION HISTORY:
Name Date Description
---- ---- -----------
CP 3/26/93 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
BigCalcProcessUpdateNumber method dynamic BigCalcProcessClass,
MSG_BC_PROCESS_UPDATE_NUMBER
.enter
;
; Reset the display
;
call CEDisplayTopOfStack
;
; Tell the application object that a user option has changed
;
call BigCalcNotifyOptionsChange
.leave
ret
BigCalcProcessUpdateNumber endm
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
BigCalcProcessChangeExtensionsState
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Sets the state of the various extensions (Math, Scientific)
CALLED BY: UI
PASS: ds,es = dgroup
cx = ExtensionType
RETURN: nothing
DESTROYED: nothing
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
Don 1/7/99 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
BigCalcProcessChangeExtensionsState method dynamic BigCalcProcessClass,
MSG_BC_PROCESS_CHANGE_EXTENSIONS_STATE
uses ax, bx, dx, di, si
.enter
;
; First check to see what to do about the math extensions
;
cmp cx, ds:[extensionState]
pushf ; save results - used later!
mov ds:[extensionState], cx
mov ax, offset BigCalcProcessSetNotUsable
test cx, mask EXT_MATH
jz setMathState
mov ax, offset BigCalcProcessSetUsable
setMathState:
mov bx, handle CalcResource
mov si, offset CalcResource:ButtonOneOver
call ax
mov si, offset CalcResource:ButtonPercent
call ax
mov si, offset CalcResource:ButtonSquare
call ax
mov si, offset CalcResource:ButtonSquareRoot
call ax
;
; Need to be careful here, since the parens share the
; same keypad space as two keys in RPN mode. So..., if
; we are in RPN mode, we don't change anything.
;
cmp ds:[calculatorMode], CM_RPN
je checkScientific
mov si, offset CalcResource:ButtonLeftParen
call ax
mov si, offset CalcResource:ButtonRightParen
call ax
;
; Now check to see what to do about the scientific extensions
;
checkScientific:
if _SCIENTIFIC_REP
mov ax, offset BigCalcProcessSetNotUsable
test cx, mask EXT_SCIENTIFIC
jz setScientificState
mov ax, offset BigCalcProcessSetUsable
setScientificState:
mov bx, handle ExtensionResource
mov si, offset ExtensionResource:DegreeItemGroup
call ax
mov si, offset ExtensionResource:SciKeyPad
call ax
endif
;
; Queue a message to reset the geometry, but *only* if
; we are moving to a reduced set of extensions (i.e. from
; scientific down to math, or from math down to none).
; Luckily, detecting this is easy, based upon a comparison
; with the original extension state. We only bother to do
; this to avoid screen flashing on starting up when something
; other than the default configuration (minimal) has been selected
; by the user.
;
popf ; if moving to a higher level
jae doNotify ; ...of extensions, skip reset
mov ax, MSG_GEN_RESET_TO_INITIAL_SIZE
mov dl, VUM_DELAYED_VIA_APP_QUEUE
mov bx, handle BigCalcPrimary
mov si, offset BigCalcPrimary
mov di, mask MF_FORCE_QUEUE or \
mask MF_CHECK_DUPLICATE
call ObjMessage
;
; Tell the application object that a user option has changed
;
doNotify:
call BigCalcNotifyOptionsChange
.leave
ret
BigCalcProcessChangeExtensionsState endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
BigCalcProcessChangeWorksheetsState
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Sets the state (on/off) of the worksheets
CALLED BY: UI
PASS: ds,es = dgroup
cx = Boolean (TRUE = on, FALSE = off)
RETURN: nothing
DESTROYED: nothing
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
Don 1/7/99 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
BigCalcProcessChangeWorksheetsState method dynamic BigCalcProcessClass,
MSG_BC_PROCESS_CHANGE_WORKSHEETS_STATE
uses ax, bx, dx, di, si
.enter
;
; Set usable or not the set of worksheets
;
mov ax, offset BigCalcProcessSetNotUsable
tst cx
jz setState
mov ax, offset BigCalcProcessSetUsable
setState:
mov bx, handle BigCalcBottomRowInteraction
mov si, offset BigCalcBottomRowInteraction
call ax
mov si, offset BigCalcBottomRowSeparator
call ax
;
; Queue a message to reset the geometry
;
mov ax, MSG_GEN_RESET_TO_INITIAL_SIZE
mov dl, VUM_DELAYED_VIA_APP_QUEUE
mov bx, handle BigCalcPrimary
mov si, offset BigCalcPrimary
mov di, mask MF_FORCE_QUEUE or \
mask MF_CHECK_DUPLICATE
call ObjMessage
;
; Tell the application object that a user option has changed
;
call BigCalcNotifyOptionsChange
.leave
ret
BigCalcProcessChangeWorksheetsState endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
BigCalcProcessChangePaperRollState
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Sets the state (on/off) of the paper roll
CALLED BY: UI
PASS: ds,es = dgroup
cx = Boolean (TRUE = on, FALSE = off)
RETURN: nothing
DESTROYED: nothing
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
Don 1/7/99 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
BigCalcProcessChangePaperRollState method dynamic BigCalcProcessClass,
MSG_BC_PROCESS_CHANGE_PAPER_ROLL_STATE
uses ax, bx, dx, di, si
.enter
;
; Set usable or not the paper roll & the trigger
; that clears the contents of the roll
;
mov ax, offset BigCalcProcessSetNotUsable
tst cx
jz setState
mov ax, offset BigCalcProcessSetUsable
setState:
mov bx, handle BigCalcPaperRoll
mov si, offset BigCalcPaperRoll
call ax
mov bx, handle ClearPaperRollButton
mov si, offset ClearPaperRollButton
call ax
;
; Queue a message to reset the geometry
;
mov ax, MSG_GEN_RESET_TO_INITIAL_SIZE
mov dl, VUM_DELAYED_VIA_APP_QUEUE
mov bx, handle BigCalcPrimary
mov si, offset BigCalcPrimary
mov di, mask MF_FORCE_QUEUE or \
mask MF_CHECK_DUPLICATE
call ObjMessage
;
; Tell the application object that a user option has changed
;
call BigCalcNotifyOptionsChange
.leave
ret
BigCalcProcessChangePaperRollState endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
BigCalcProcessSetUsable
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: sets the object that's passed in bx:si usable
CALLED BY:
PASS: bx -- handle of the object
si -- offset of the object
RETURN: nothing
DESTROYED: nothing
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
CP 4/17/92 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
BigCalcProcessSetUsable proc near
uses ax,cx,dx,di,bp
.enter
mov dl, VUM_DELAYED_VIA_APP_QUEUE
mov ax, MSG_GEN_SET_USABLE
clr di
call ObjMessage
.leave
ret
BigCalcProcessSetUsable endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
BigCalcProcessSetNotUsable
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: sets the object in bx:si not usable
CALLED BY:
PASS: bx:si object
RETURN: nothing
DESTROYED: nothing
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
CP 4/17/92 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
BigCalcProcessSetNotUsable proc near
uses ax,bx,cx,dx,si,di,bp
.enter
mov dl, VUM_DELAYED_VIA_APP_QUEUE
mov ax, MSG_GEN_SET_NOT_USABLE
clr di
call ObjMessage
.leave
ret
BigCalcProcessSetNotUsable endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
BigCalcNotifyOptionsChange
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: Notify the application object of a user-option change
CALLED BY: Various
PASS: Nothing
RETURN: Nothing
DESTROYED: Nothing
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
Don 2/7/99 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
BigCalcNotifyOptionsChange proc near
uses ax, bx, di, si
.enter
mov ax, MSG_GEN_APPLICATION_OPTIONS_CHANGED
GetResourceHandleNS BigCalculatorAppObj, bx
mov si, offset BigCalculatorAppObj
clr di
call ObjMessage
.leave
ret
BigCalcNotifyOptionsChange endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
CustBoxGetSettings
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: gets the settings
CALLED BY:
PASS: *ds:si = CustBoxClass object
ds:di = CustBoxClass instance data
ds:bx = CustBoxClass object (same as *ds:si)
es = dgroup
ax = message #
RETURN: ax, cx (=bx) to be used for FloatFloatToAsciiStd_Format
cl = MAX_DISPLAYABLE_LENGTH
ch = DECIMAL_PRECISION
DESTROYED: nothing
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
CP 6/12/92 Initial version
AS 8/29/96 Added code for PENELOPE version that
interperts 0 fixed decimals as round
to nearest integer, and adds the
"don't use fixed decimals"
functionality
andres 10/29/96 Don't need this for DOVE
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
CustBoxGetSettings method dynamic CustBoxClass,
MSG_CUST_BOX_GET_SETTINGS
uses dx, bp
.enter
;
; get the # of digits after decimal point to put them in bl
;
mov si, offset DecimalPlacesRange
mov ax, MSG_GEN_VALUE_GET_VALUE
call ObjCallInstanceNoLock ; decimal places -> dx
mov bl, dl
mov bh, DECIMAL_PRECISION
push bx
mov si, offset NotationItemGroup
mov ax, MSG_GEN_ITEM_GROUP_GET_SELECTION
call ObjCallInstanceNoLock
cmp ax, DU_SCIENTIFIC
je sciNotation
clr ax
jmp convert
sciNotation:
mov ax, mask FFAF_SCIENTIFIC
convert:
;
; get the fp# from the stack (and pop it)
;
pop cx ; # of digits
tst cl
jnz notZeroDigits
mov cl, MAX_DISPLAYABLE_LENGTH
ornf ax, mask FFAF_NO_TRAIL_ZEROS
notZeroDigits:
.leave
ret
CustBoxGetSettings endm
COMMENT @%%%%%%%%% RESPONDER/NON-RESPONDER COMMON CODE %%%%%%%%%%%%%%%%%%%%@
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
BigCalcProcessPreFloatDup
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: utility function for proper fp calculation
CALLED BY: global
PASS: nothing
RETURN: fp stack unchanged if not empty
zero on top if empty
DESTROYED: nothing
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
CP 6/13/92 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
BigCalcProcessPreFloatDup proc far
uses ax,dx
.enter
call FloatDepth
tst ax
jnz done
call Float0
done:
.leave
ret
BigCalcProcessPreFloatDup endp
COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
BigCalcProcessConvertToUpper
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SYNOPSIS: makes the e into E in scientific notation
CALLED BY:
PASS:
RETURN:
DESTROYED: nothing
PSEUDO CODE/STRATEGY:
KNOWN BUGS/SIDE EFFECTS/IDEAS:
REVISION HISTORY:
Name Date Description
---- ---- -----------
CP 6/22/92 Initial version
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
if (NOT FALSE)
BigCalcProcessConvertToUpper proc far
uses ds,si
.enter
segmov ds, es
mov si, di
call LocalUpcaseString
.leave
ret
BigCalcProcessConvertToUpper endp
endif
ProcessCode ends
|
; A073267: Number of compositions (ordered partitions) of n into exactly two powers of 2.
; 0,0,1,2,1,2,2,0,1,2,2,0,2,0,0,0,1,2,2,0,2,0,0,0,2,0,0,0,0,0,0,0,1,2,2,0,2,0,0,0,2,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,2,0,2,0,0,0,2,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,2,0,2,0,0,0,2,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
mov $3,$0
lpb $0,6
div $3,2
mov $14,$0
sub $0,$3
mov $2,$14
lpe
div $0,89
lpb $14
mov $2,$0
sub $14,4
lpe
mov $1,$2
|
.global s_prepare_buffers
s_prepare_buffers:
push %r14
push %r9
push %rcx
push %rdi
push %rsi
lea addresses_UC_ht+0x10753, %rsi
lea addresses_D_ht+0x4453, %rdi
clflush (%rsi)
nop
nop
and %r9, %r9
mov $104, %rcx
rep movsl
cmp %r14, %r14
pop %rsi
pop %rdi
pop %rcx
pop %r9
pop %r14
ret
.global s_faulty_load
s_faulty_load:
push %r10
push %r11
push %r12
push %r13
push %r8
push %r9
push %rbx
// Store
mov $0x5e7, %rbx
nop
nop
inc %r13
mov $0x5152535455565758, %r9
movq %r9, %xmm6
vmovups %ymm6, (%rbx)
nop
nop
nop
nop
cmp %r11, %r11
// Faulty Load
lea addresses_D+0xc753, %r10
nop
nop
nop
nop
inc %r8
mov (%r10), %ebx
lea oracles, %r8
and $0xff, %rbx
shlq $12, %rbx
mov (%r8,%rbx,1), %rbx
pop %rbx
pop %r9
pop %r8
pop %r13
pop %r12
pop %r11
pop %r10
ret
/*
<gen_faulty_load>
[REF]
{'src': {'NT': False, 'AVXalign': False, 'size': 16, 'congruent': 0, 'same': True, 'type': 'addresses_D'}, 'OP': 'LOAD'}
{'dst': {'NT': False, 'AVXalign': False, 'size': 32, 'congruent': 2, 'same': False, 'type': 'addresses_P'}, 'OP': 'STOR'}
[Faulty Load]
{'src': {'NT': False, 'AVXalign': False, 'size': 4, 'congruent': 0, 'same': True, 'type': 'addresses_D'}, 'OP': 'LOAD'}
<gen_prepare_buffer>
{'src': {'congruent': 10, 'same': False, 'type': 'addresses_UC_ht'}, 'dst': {'congruent': 6, 'same': False, 'type': 'addresses_D_ht'}, 'OP': 'REPM'}
{'36': 21829}
36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36
*/
|
; A254651: Characteristic function of A254614, numbers that are either odd or evil (or both).
; 1,1,0,1,0,1,1,1,0,1,1,1,1,1,0,1,0,1,1,1,1,1,0,1,1,1,0,1,0,1,1,1,0,1,1,1,1,1,0,1,1,1,0,1,0,1,1,1,1,1,0,1,0,1,1,1,0,1,1,1,1,1,0,1,0,1,1,1,1,1,0,1,1,1,0,1,0,1,1,1,1,1,0,1,0,1,1,1,0,1,1,1,1,1,0,1,1,1,0,1,0,1,1,1,0,1,1,1,1,1,0,1,0,1,1,1,1,1,0,1,1,1,0,1,0,1,1,1,0,1,1,1,1,1,0,1,1,1,0,1,0,1,1,1,1,1,0,1,0,1,1,1,0,1,1,1,1,1,0,1,1,1,0,1,0,1,1,1,0,1,1,1,1,1,0,1,0,1,1,1,1,1,0,1,1,1,0,1,0,1,1,1,1,1,0,1,0,1,1,1,0,1,1,1,1,1,0,1,0,1,1,1,1,1,0,1,1,1,0,1,0,1,1,1,0,1,1,1,1,1,0,1,1,1,0,1,0,1,1,1,1,1,0,1,0,1,1,1,0,1
mov $4,$0
lpb $0,1
add $3,$0
div $0,2
mov $5,$3
lpe
mov $1,2
add $3,$4
mov $4,$3
mul $4,$5
mov $2,$4
mod $2,2
add $2,4
sub $1,$2
add $1,2
mov $5,$1
mov $1,1
add $1,$5
|
EXTRN output_X: near
STK SEGMENT PARA STACK 'STACK'
db 100 dup(0)
STK ENDS
DSEG SEGMENT PARA PUBLIC 'DATA'
X db 'R'
DSEG ENDS
CSEG SEGMENT PARA PUBLIC 'CODE'
assume CS:CSEG, DS:DSEG, SS:STK
main:
mov ax, DSEG
mov ds, ax
call output_X
mov ax, 4c00h
int 21h
CSEG ENDS
PUBLIC X
END main
|
; You may customize this and other start-up templates;
; The location of this template is c:\emu8086\inc\0_com_template.txt
org 100h
; add your code here
SK1 EQU 1
SK2 EQU 2
SK3 EQU 3
MOV AX, SK1
ADD AX, SK2
ADD AX, SK3
MOV BX, AX
ret
|
; A282088: Binary representation of the x-axis, from the left edge to the origin, of the n-th stage of growth of the two-dimensional cellular automaton defined by "Rule 553", based on the 5-celled von Neumann neighborhood.
; 1,0,1,0,101,0,10101,0,1010101,0,101010101,0,10101010101,0,1010101010101,0,101010101010101,0,10101010101010101,0,1010101010101010101,0,101010101010101010101,0,10101010101010101010101,0,1010101010101010101010101,0,101010101010101010101010101,0,10101010101010101010101010101,0,1010101010101010101010101010101,0,101010101010101010101010101010101,0,10101010101010101010101010101010101,0
mov $1,$0
gcd $1,2
lpb $1
trn $0,2
mov $1,1
mov $2,2
add $2,$0
lpe
mov $0,10
add $3,$2
pow $0,$3
mul $0,2
div $0,198
|
// This file is a part of Julia. License is MIT: https://julialang.org/license
#include "llvm-version.h"
#include "platform.h"
// target support
#include <llvm/ADT/Triple.h>
#include <llvm/Analysis/TargetLibraryInfo.h>
#include <llvm/Analysis/TargetTransformInfo.h>
#include <llvm/IR/DataLayout.h>
#if JL_LLVM_VERSION >= 140000
#include <llvm/MC/TargetRegistry.h>
#else
#include <llvm/Support/TargetRegistry.h>
#endif
#include <llvm/Target/TargetMachine.h>
// analysis passes
#include <llvm/Analysis/Passes.h>
#include <llvm/Analysis/BasicAliasAnalysis.h>
#include <llvm/Analysis/TypeBasedAliasAnalysis.h>
#include <llvm/Analysis/ScopedNoAliasAA.h>
#include <llvm/IR/PassManager.h>
#include <llvm/IR/Verifier.h>
#include <llvm/Transforms/IPO.h>
#include <llvm/Transforms/Scalar.h>
#include <llvm/Transforms/Vectorize.h>
#include <llvm/Transforms/Instrumentation/AddressSanitizer.h>
#include <llvm/Transforms/Instrumentation/ThreadSanitizer.h>
#include <llvm/Transforms/Scalar/GVN.h>
#include <llvm/Transforms/IPO/AlwaysInliner.h>
#include <llvm/Transforms/InstCombine/InstCombine.h>
#include <llvm/Transforms/Scalar/InstSimplifyPass.h>
#include <llvm/Transforms/Utils/SimplifyCFGOptions.h>
#include <llvm/Passes/PassBuilder.h>
#include <llvm/Passes/PassPlugin.h>
#if defined(USE_POLLY)
#include <polly/RegisterPasses.h>
#include <polly/LinkAllPasses.h>
#include <polly/CodeGen/CodegenCleanup.h>
#if defined(USE_POLLY_ACC)
#include <polly/Support/LinkGPURuntime.h>
#endif
#endif
// for outputting code
#include <llvm/Bitcode/BitcodeWriter.h>
#include <llvm/Bitcode/BitcodeWriterPass.h>
#include "llvm/Object/ArchiveWriter.h"
#include <llvm/IR/IRPrintingPasses.h>
#include <llvm/IR/LegacyPassManagers.h>
#include <llvm/Transforms/Utils/Cloning.h>
using namespace llvm;
#include "julia.h"
#include "julia_internal.h"
#include "jitlayers.h"
#include "julia_assert.h"
template<class T> // for GlobalObject's
static T *addComdat(T *G)
{
#if defined(_OS_WINDOWS_)
if (!G->isDeclaration()) {
// add __declspec(dllexport) to everything marked for export
if (G->getLinkage() == GlobalValue::ExternalLinkage)
G->setDLLStorageClass(GlobalValue::DLLExportStorageClass);
else
G->setDLLStorageClass(GlobalValue::DefaultStorageClass);
}
#endif
return G;
}
typedef struct {
std::unique_ptr<Module> M;
std::vector<GlobalValue*> jl_sysimg_fvars;
std::vector<GlobalValue*> jl_sysimg_gvars;
std::map<jl_code_instance_t*, std::tuple<uint32_t, uint32_t>> jl_fvar_map;
std::map<void*, int32_t> jl_value_to_llvm; // uses 1-based indexing
} jl_native_code_desc_t;
extern "C" JL_DLLEXPORT
void jl_get_function_id_impl(void *native_code, jl_code_instance_t *codeinst,
int32_t *func_idx, int32_t *specfunc_idx)
{
jl_native_code_desc_t *data = (jl_native_code_desc_t*)native_code;
if (data) {
// get the function index in the fvar lookup table
auto it = data->jl_fvar_map.find(codeinst);
if (it != data->jl_fvar_map.end()) {
std::tie(*func_idx, *specfunc_idx) = it->second;
}
}
}
extern "C" JL_DLLEXPORT
int32_t jl_get_llvm_gv_impl(void *native_code, jl_value_t *p)
{
// map a jl_value_t memory location to a GlobalVariable
jl_native_code_desc_t *data = (jl_native_code_desc_t*)native_code;
if (data) {
auto it = data->jl_value_to_llvm.find(p);
if (it != data->jl_value_to_llvm.end()) {
return it->second;
}
}
return 0;
}
extern "C" JL_DLLEXPORT
Module* jl_get_llvm_module_impl(void *native_code)
{
jl_native_code_desc_t *data = (jl_native_code_desc_t*)native_code;
if (data)
return data->M.get();
else
return NULL;
}
extern "C" JL_DLLEXPORT
GlobalValue* jl_get_llvm_function_impl(void *native_code, uint32_t idx)
{
jl_native_code_desc_t *data = (jl_native_code_desc_t*)native_code;
if (data)
return data->jl_sysimg_fvars[idx];
else
return NULL;
}
extern "C" JL_DLLEXPORT
LLVMContext* jl_get_llvm_context_impl(void *native_code)
{
jl_native_code_desc_t *data = (jl_native_code_desc_t*)native_code;
if (data)
return &data->M->getContext();
else
return NULL;
}
static void emit_offset_table(Module &mod, const std::vector<GlobalValue*> &vars, StringRef name, Type *T_psize)
{
// Emit a global variable with all the variable addresses.
// The cloning pass will convert them into offsets.
assert(!vars.empty());
size_t nvars = vars.size();
std::vector<Constant*> addrs(nvars);
for (size_t i = 0; i < nvars; i++) {
Constant *var = vars[i];
addrs[i] = ConstantExpr::getBitCast(var, T_psize);
}
ArrayType *vars_type = ArrayType::get(T_psize, nvars);
new GlobalVariable(mod, vars_type, true,
GlobalVariable::ExternalLinkage,
ConstantArray::get(vars_type, addrs),
name);
}
static bool is_safe_char(unsigned char c)
{
return ('0' <= c && c <= '9') ||
('A' <= c && c <= 'Z') ||
('a' <= c && c <= 'z') ||
(c == '_' || c == '$') ||
(c >= 128 && c < 255);
}
static const char hexchars[16] = {
'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
static const char *const common_names[256] = {
// 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, e, f
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0x00
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0x10
"SP", "NOT", "DQT", "YY", 0, "REM", "AND", "SQT", // 0x20
"LPR", "RPR", "MUL", "SUM", 0, "SUB", "DOT", "DIV", // 0x28
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "COL", 0, "LT", "EQ", "GT", "QQ", // 0x30
"AT", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0x40
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "LBR", "RDV", "RBR", "POW", 0, // 0x50
"TIC", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0x60
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "LCR", "OR", "RCR", "TLD", "DEL", // 0x70
0 }; // remainder is filled with zeros, though are also all safe characters
// reversibly removes special characters from the name of GlobalObjects,
// which might cause them to be treated special by LLVM or the system linker
// the only non-identifier characters we allow to appear are '.' and '$',
// and all of UTF-8 above code-point 128 (except 255)
// most are given "friendly" abbreviations
// the remaining few will print as hex
// e.g. mangles "llvm.a≠a$a!a##" as "llvmDOT.a≠a$aNOT.aYY.YY."
static void makeSafeName(GlobalObject &G)
{
StringRef Name = G.getName();
SmallVector<char, 32> SafeName;
for (unsigned char c : Name.bytes()) {
if (is_safe_char(c)) {
SafeName.push_back(c);
}
else {
if (common_names[c]) {
SafeName.push_back(common_names[c][0]);
SafeName.push_back(common_names[c][1]);
if (common_names[c][2])
SafeName.push_back(common_names[c][2]);
}
else {
SafeName.push_back(hexchars[(c >> 4) & 0xF]);
SafeName.push_back(hexchars[c & 0xF]);
}
SafeName.push_back('.');
}
}
if (SafeName.size() != Name.size())
G.setName(StringRef(SafeName.data(), SafeName.size()));
}
static void jl_ci_cache_lookup(const jl_cgparams_t &cgparams, jl_method_instance_t *mi, size_t world, jl_code_instance_t **ci_out, jl_code_info_t **src_out)
{
jl_value_t *ci = cgparams.lookup(mi, world, world);
JL_GC_PROMISE_ROOTED(ci);
jl_code_instance_t *codeinst = NULL;
if (ci != jl_nothing) {
codeinst = (jl_code_instance_t*)ci;
*src_out = (jl_code_info_t*)codeinst->inferred;
jl_method_t *def = codeinst->def->def.method;
if ((jl_value_t*)*src_out == jl_nothing)
*src_out = NULL;
if (*src_out && jl_is_method(def))
*src_out = jl_uncompress_ir(def, codeinst, (jl_array_t*)*src_out);
}
if (*src_out == NULL || !jl_is_code_info(*src_out)) {
if (cgparams.lookup != jl_rettype_inferred) {
jl_error("Refusing to automatically run type inference with custom cache lookup.");
}
else {
*src_out = jl_type_infer(mi, world, 0);
if (*src_out) {
codeinst = jl_get_method_inferred(mi, (*src_out)->rettype, (*src_out)->min_world, (*src_out)->max_world);
if ((*src_out)->inferred && !codeinst->inferred)
codeinst->inferred = jl_nothing;
}
}
}
*ci_out = codeinst;
}
// takes the running content that has collected in the shadow module and dump it to disk
// this builds the object file portion of the sysimage files for fast startup, and can
// also be used be extern consumers like GPUCompiler.jl to obtain a module containing
// all reachable & inferrrable functions. The `policy` flag switches between the default
// mode `0`, the extern mode `1`, and imaging mode `2`.
extern "C" JL_DLLEXPORT
void *jl_create_native_impl(jl_array_t *methods, const jl_cgparams_t *cgparams, int _policy)
{
if (cgparams == NULL)
cgparams = &jl_default_cgparams;
jl_native_code_desc_t *data = new jl_native_code_desc_t;
jl_codegen_params_t params;
params.params = cgparams;
std::map<jl_code_instance_t*, jl_compile_result_t> emitted;
jl_method_instance_t *mi = NULL;
jl_code_info_t *src = NULL;
JL_GC_PUSH1(&src);
JL_LOCK(&jl_codegen_lock);
uint64_t compiler_start_time = 0;
uint8_t measure_compile_time_enabled = jl_atomic_load_relaxed(&jl_measure_compile_time_enabled);
if (measure_compile_time_enabled)
compiler_start_time = jl_hrtime();
CompilationPolicy policy = (CompilationPolicy) _policy;
if (policy == CompilationPolicy::ImagingMode)
imaging_mode = 1;
std::unique_ptr<Module> clone(jl_create_llvm_module("text"));
// compile all methods for the current world and type-inference world
size_t compile_for[] = { jl_typeinf_world, jl_atomic_load_acquire(&jl_world_counter) };
for (int worlds = 0; worlds < 2; worlds++) {
params.world = compile_for[worlds];
if (!params.world)
continue;
// Don't emit methods for the typeinf_world with extern policy
if (policy != CompilationPolicy::Default && params.world == jl_typeinf_world)
continue;
size_t i, l;
for (i = 0, l = jl_array_len(methods); i < l; i++) {
// each item in this list is either a MethodInstance indicating something
// to compile, or an svec(rettype, sig) describing a C-callable alias to create.
jl_value_t *item = jl_array_ptr_ref(methods, i);
if (jl_is_simplevector(item)) {
if (worlds == 1)
jl_compile_extern_c(clone.get(), ¶ms, NULL, jl_svecref(item, 0), jl_svecref(item, 1));
continue;
}
mi = (jl_method_instance_t*)item;
src = NULL;
// if this method is generally visible to the current compilation world,
// and this is either the primary world, or not applicable in the primary world
// then we want to compile and emit this
if (mi->def.method->primary_world <= params.world && params.world <= mi->def.method->deleted_world) {
// find and prepare the source code to compile
jl_code_instance_t *codeinst = NULL;
jl_ci_cache_lookup(*cgparams, mi, params.world, &codeinst, &src);
if (src && !emitted.count(codeinst)) {
// now add it to our compilation results
JL_GC_PROMISE_ROOTED(codeinst->rettype);
jl_compile_result_t result = jl_emit_code(mi, src, codeinst->rettype, params);
if (std::get<0>(result))
emitted[codeinst] = std::move(result);
}
}
}
// finally, make sure all referenced methods also get compiled or fixed up
jl_compile_workqueue(emitted, params, policy);
}
JL_GC_POP();
// process the globals array, before jl_merge_module destroys them
std::vector<std::string> gvars;
for (auto &global : params.globals) {
gvars.push_back(std::string(global.second->getName()));
data->jl_value_to_llvm[global.first] = gvars.size();
}
// clones the contents of the module `m` to the shadow_output collector
// while examining and recording what kind of function pointer we have
for (auto &def : emitted) {
jl_merge_module(clone.get(), std::move(std::get<0>(def.second)));
jl_code_instance_t *this_code = def.first;
jl_llvm_functions_t decls = std::get<1>(def.second);
StringRef func = decls.functionObject;
StringRef cfunc = decls.specFunctionObject;
uint32_t func_id = 0;
uint32_t cfunc_id = 0;
if (func == "jl_fptr_args") {
func_id = -1;
}
else if (func == "jl_fptr_sparam") {
func_id = -2;
}
else {
data->jl_sysimg_fvars.push_back(cast<Function>(clone->getNamedValue(func)));
func_id = data->jl_sysimg_fvars.size();
}
if (!cfunc.empty()) {
data->jl_sysimg_fvars.push_back(cast<Function>(clone->getNamedValue(cfunc)));
cfunc_id = data->jl_sysimg_fvars.size();
}
data->jl_fvar_map[this_code] = std::make_tuple(func_id, cfunc_id);
}
if (params._shared_module) {
std::unique_ptr<Module> shared(params._shared_module);
params._shared_module = NULL;
jl_merge_module(clone.get(), std::move(shared));
}
// now get references to the globals in the merged module
// and set them to be internalized and initialized at startup
for (auto &global : gvars) {
GlobalVariable *G = cast<GlobalVariable>(clone->getNamedValue(global));
G->setInitializer(ConstantPointerNull::get(cast<PointerType>(G->getValueType())));
G->setLinkage(GlobalVariable::InternalLinkage);
data->jl_sysimg_gvars.push_back(G);
}
#if defined(_OS_WINDOWS_) && defined(_CPU_X86_64_)
// setting the function personality enables stack unwinding and catching exceptions
// so make sure everything has something set
Type *T_int32 = Type::getInt32Ty(clone->getContext());
Function *juliapersonality_func =
Function::Create(FunctionType::get(T_int32, true),
Function::ExternalLinkage, "__julia_personality", clone.get());
juliapersonality_func->setDLLStorageClass(GlobalValue::DLLImportStorageClass);
#endif
// move everything inside, now that we've merged everything
// (before adding the exported headers)
if (policy == CompilationPolicy::Default) {
for (GlobalObject &G : clone->global_objects()) {
if (!G.isDeclaration()) {
G.setLinkage(Function::InternalLinkage);
makeSafeName(G);
addComdat(&G);
#if defined(_OS_WINDOWS_) && defined(_CPU_X86_64_)
// Add unwind exception personalities to functions to handle async exceptions
if (Function *F = dyn_cast<Function>(&G))
F->setPersonalityFn(juliapersonality_func);
#endif
}
}
}
data->M = std::move(clone);
if (measure_compile_time_enabled)
jl_atomic_fetch_add_relaxed(&jl_cumulative_compile_time, (jl_hrtime() - compiler_start_time));
if (policy == CompilationPolicy::ImagingMode)
imaging_mode = 0;
JL_UNLOCK(&jl_codegen_lock); // Might GC
return (void*)data;
}
static void emit_result(std::vector<NewArchiveMember> &Archive, SmallVectorImpl<char> &OS,
StringRef Name, std::vector<std::string> &outputs)
{
outputs.push_back({ OS.data(), OS.size() });
Archive.push_back(NewArchiveMember(MemoryBufferRef(outputs.back(), Name)));
OS.clear();
}
static object::Archive::Kind getDefaultForHost(Triple &triple)
{
if (triple.isOSDarwin())
return object::Archive::K_DARWIN;
return object::Archive::K_GNU;
}
typedef Error ArchiveWriterError;
static void reportWriterError(const ErrorInfoBase &E)
{
std::string err = E.message();
jl_safe_printf("ERROR: failed to emit output file %s\n", err.c_str());
}
// takes the running content that has collected in the shadow module and dump it to disk
// this builds the object file portion of the sysimage files for fast startup
extern "C" JL_DLLEXPORT
void jl_dump_native_impl(void *native_code,
const char *bc_fname, const char *unopt_bc_fname, const char *obj_fname,
const char *asm_fname,
const char *sysimg_data, size_t sysimg_len)
{
JL_TIMING(NATIVE_DUMP);
jl_native_code_desc_t *data = (jl_native_code_desc_t*)native_code;
LLVMContext &Context = data->M->getContext();
// We don't want to use MCJIT's target machine because
// it uses the large code model and we may potentially
// want less optimizations there.
Triple TheTriple = Triple(jl_TargetMachine->getTargetTriple());
// make sure to emit the native object format, even if FORCE_ELF was set in codegen
#if defined(_OS_WINDOWS_)
TheTriple.setObjectFormat(Triple::COFF);
#elif defined(_OS_DARWIN_)
TheTriple.setObjectFormat(Triple::MachO);
TheTriple.setOS(llvm::Triple::MacOSX);
#endif
std::unique_ptr<TargetMachine> TM(
jl_TargetMachine->getTarget().createTargetMachine(
TheTriple.getTriple(),
jl_TargetMachine->getTargetCPU(),
jl_TargetMachine->getTargetFeatureString(),
jl_TargetMachine->Options,
#if defined(_OS_LINUX_) || defined(_OS_FREEBSD_)
Reloc::PIC_,
#else
Optional<Reloc::Model>(),
#endif
#if defined(_CPU_PPC_) || defined(_CPU_PPC64_)
// On PPC the small model is limited to 16bit offsets
CodeModel::Medium,
#else
// Use small model so that we can use signed 32bits offset in the function and GV tables
CodeModel::Small,
#endif
CodeGenOpt::Aggressive // -O3 TODO: respect command -O0 flag?
));
legacy::PassManager PM;
addTargetPasses(&PM, TM.get());
// set up optimization passes
SmallVector<char, 0> bc_Buffer;
SmallVector<char, 0> obj_Buffer;
SmallVector<char, 0> asm_Buffer;
SmallVector<char, 0> unopt_bc_Buffer;
raw_svector_ostream bc_OS(bc_Buffer);
raw_svector_ostream obj_OS(obj_Buffer);
raw_svector_ostream asm_OS(asm_Buffer);
raw_svector_ostream unopt_bc_OS(unopt_bc_Buffer);
std::vector<NewArchiveMember> bc_Archive;
std::vector<NewArchiveMember> obj_Archive;
std::vector<NewArchiveMember> asm_Archive;
std::vector<NewArchiveMember> unopt_bc_Archive;
std::vector<std::string> outputs;
if (unopt_bc_fname)
PM.add(createBitcodeWriterPass(unopt_bc_OS));
if (bc_fname || obj_fname || asm_fname) {
addOptimizationPasses(&PM, jl_options.opt_level, true, true);
addMachinePasses(&PM, TM.get(), jl_options.opt_level);
}
if (bc_fname)
PM.add(createBitcodeWriterPass(bc_OS));
if (obj_fname)
if (TM->addPassesToEmitFile(PM, obj_OS, nullptr, CGFT_ObjectFile, false))
jl_safe_printf("ERROR: target does not support generation of object files\n");
if (asm_fname)
if (TM->addPassesToEmitFile(PM, asm_OS, nullptr, CGFT_AssemblyFile, false))
jl_safe_printf("ERROR: target does not support generation of object files\n");
// Reset the target triple to make sure it matches the new target machine
data->M->setTargetTriple(TM->getTargetTriple().str());
DataLayout DL = TM->createDataLayout();
DL.reset(DL.getStringRepresentation() + "-ni:10:11:12:13");
data->M->setDataLayout(DL);
Type *T_size;
if (sizeof(size_t) == 8)
T_size = Type::getInt64Ty(Context);
else
T_size = Type::getInt32Ty(Context);
Type *T_psize = T_size->getPointerTo();
// add metadata information
if (imaging_mode) {
emit_offset_table(*data->M, data->jl_sysimg_gvars, "jl_sysimg_gvars", T_psize);
emit_offset_table(*data->M, data->jl_sysimg_fvars, "jl_sysimg_fvars", T_psize);
// reflect the address of the jl_RTLD_DEFAULT_handle variable
// back to the caller, so that we can check for consistency issues
GlobalValue *jlRTLD_DEFAULT_var = jl_emit_RTLD_DEFAULT_var(data->M.get());
addComdat(new GlobalVariable(*data->M,
jlRTLD_DEFAULT_var->getType(),
true,
GlobalVariable::ExternalLinkage,
jlRTLD_DEFAULT_var,
"jl_RTLD_DEFAULT_handle_pointer"));
}
// do the actual work
auto add_output = [&] (Module &M, StringRef unopt_bc_Name, StringRef bc_Name, StringRef obj_Name, StringRef asm_Name) {
PM.run(M);
if (unopt_bc_fname)
emit_result(unopt_bc_Archive, unopt_bc_Buffer, unopt_bc_Name, outputs);
if (bc_fname)
emit_result(bc_Archive, bc_Buffer, bc_Name, outputs);
if (obj_fname)
emit_result(obj_Archive, obj_Buffer, obj_Name, outputs);
if (asm_fname)
emit_result(asm_Archive, asm_Buffer, asm_Name, outputs);
};
add_output(*data->M, "unopt.bc", "text.bc", "text.o", "text.s");
std::unique_ptr<Module> sysimage(new Module("sysimage", Context));
sysimage->setTargetTriple(data->M->getTargetTriple());
sysimage->setDataLayout(data->M->getDataLayout());
#if JL_LLVM_VERSION >= 130000
sysimage->setStackProtectorGuard(data->M->getStackProtectorGuard());
sysimage->setOverrideStackAlignment(data->M->getOverrideStackAlignment());
#endif
data->M.reset(); // free memory for data->M
if (sysimg_data) {
Constant *data = ConstantDataArray::get(Context,
ArrayRef<uint8_t>((const unsigned char*)sysimg_data, sysimg_len));
addComdat(new GlobalVariable(*sysimage, data->getType(), false,
GlobalVariable::ExternalLinkage,
data, "jl_system_image_data"))->setAlignment(Align(64));
Constant *len = ConstantInt::get(T_size, sysimg_len);
addComdat(new GlobalVariable(*sysimage, len->getType(), true,
GlobalVariable::ExternalLinkage,
len, "jl_system_image_size"));
}
add_output(*sysimage, "data.bc", "data.bc", "data.o", "data.s");
object::Archive::Kind Kind = getDefaultForHost(TheTriple);
if (unopt_bc_fname)
handleAllErrors(writeArchive(unopt_bc_fname, unopt_bc_Archive, true,
Kind, true, false), reportWriterError);
if (bc_fname)
handleAllErrors(writeArchive(bc_fname, bc_Archive, true,
Kind, true, false), reportWriterError);
if (obj_fname)
handleAllErrors(writeArchive(obj_fname, obj_Archive, true,
Kind, true, false), reportWriterError);
if (asm_fname)
handleAllErrors(writeArchive(asm_fname, asm_Archive, true,
Kind, true, false), reportWriterError);
delete data;
}
void addTargetPasses(legacy::PassManagerBase *PM, TargetMachine *TM)
{
PM->add(new TargetLibraryInfoWrapperPass(Triple(TM->getTargetTriple())));
PM->add(createTargetTransformInfoWrapperPass(TM->getTargetIRAnalysis()));
}
void addMachinePasses(legacy::PassManagerBase *PM, TargetMachine *TM, int optlevel)
{
// TODO: don't do this on CPUs that natively support Float16
PM->add(createDemoteFloat16Pass());
if (optlevel > 1)
PM->add(createGVNPass());
}
// this defines the set of optimization passes defined for Julia at various optimization levels.
// it assumes that the TLI and TTI wrapper passes have already been added.
void addOptimizationPasses(legacy::PassManagerBase *PM, int opt_level,
bool lower_intrinsics, bool dump_native)
{
// Note: LLVM 12 disabled the hoisting of common instruction
// before loop vectorization (https://reviews.llvm.org/D84108).
//
// TODO: CommonInstruction hoisting/sinking enables AllocOpt
// to merge allocations and sometimes eliminate them,
// since AllocOpt does not handle PhiNodes.
// Enable this instruction hoisting because of this and Union benchmarks.
auto simplifyCFGOptions = SimplifyCFGOptions().hoistCommonInsts(true);
#ifdef JL_DEBUG_BUILD
PM->add(createGCInvariantVerifierPass(true));
PM->add(createVerifierPass());
#endif
PM->add(createConstantMergePass());
if (opt_level < 2) {
if (!dump_native) {
// we won't be multiversioning, so lower CPU feature checks early on
// so that we can avoid an additional CFG simplification pass at the end.
PM->add(createCPUFeaturesPass());
if (opt_level == 1)
PM->add(createInstSimplifyLegacyPass());
}
PM->add(createCFGSimplificationPass(simplifyCFGOptions));
if (opt_level == 1) {
PM->add(createSROAPass());
PM->add(createInstructionCombiningPass());
PM->add(createEarlyCSEPass());
// maybe add GVN?
// also try GVNHoist and GVNSink
}
PM->add(createMemCpyOptPass());
PM->add(createAlwaysInlinerLegacyPass()); // Respect always_inline
PM->add(createLowerSimdLoopPass()); // Annotate loop marked with "loopinfo" as LLVM parallel loop
if (lower_intrinsics) {
PM->add(createBarrierNoopPass());
PM->add(createLowerExcHandlersPass());
PM->add(createGCInvariantVerifierPass(false));
PM->add(createRemoveNIPass());
PM->add(createLateLowerGCFramePass());
PM->add(createFinalLowerGCPass());
PM->add(createLowerPTLSPass(dump_native));
}
else {
PM->add(createRemoveNIPass());
}
PM->add(createLowerSimdLoopPass()); // Annotate loop marked with "loopinfo" as LLVM parallel loop
if (dump_native) {
PM->add(createMultiVersioningPass());
PM->add(createCPUFeaturesPass());
// minimal clean-up to get rid of CPU feature checks
if (opt_level == 1) {
PM->add(createInstSimplifyLegacyPass());
PM->add(createCFGSimplificationPass(simplifyCFGOptions));
}
}
#if defined(_COMPILER_ASAN_ENABLED_)
PM->add(createAddressSanitizerFunctionPass());
#endif
#if defined(_COMPILER_MSAN_ENABLED_)
PM->add(createMemorySanitizerPass(true));
#endif
#if defined(_COMPILER_TSAN_ENABLED_)
PM->add(createThreadSanitizerLegacyPassPass());
#endif
return;
}
PM->add(createPropagateJuliaAddrspaces());
PM->add(createScopedNoAliasAAWrapperPass());
PM->add(createTypeBasedAAWrapperPass());
if (opt_level >= 3) {
PM->add(createBasicAAWrapperPass());
}
PM->add(createCFGSimplificationPass(simplifyCFGOptions));
PM->add(createDeadCodeEliminationPass());
PM->add(createSROAPass());
//PM->add(createMemCpyOptPass());
PM->add(createAlwaysInlinerLegacyPass()); // Respect always_inline
// Running `memcpyopt` between this and `sroa` seems to give `sroa` a hard time
// merging the `alloca` for the unboxed data and the `alloca` created by the `alloc_opt`
// pass.
PM->add(createAllocOptPass());
// consider AggressiveInstCombinePass at optlevel > 2
PM->add(createInstructionCombiningPass());
PM->add(createCFGSimplificationPass(simplifyCFGOptions));
if (dump_native)
PM->add(createMultiVersioningPass());
PM->add(createCPUFeaturesPass());
PM->add(createSROAPass());
PM->add(createInstSimplifyLegacyPass());
PM->add(createJumpThreadingPass());
PM->add(createCorrelatedValuePropagationPass());
PM->add(createReassociatePass());
PM->add(createEarlyCSEPass());
// Load forwarding above can expose allocations that aren't actually used
// remove those before optimizing loops.
PM->add(createAllocOptPass());
PM->add(createLoopRotatePass());
// moving IndVarSimplify here prevented removing the loop in perf_sumcartesian(10:-1:1)
#ifdef USE_POLLY
// LCSSA (which has already run at this point due to the dependencies of the
// above passes) introduces redundant phis that hinder Polly. Therefore we
// run InstCombine here to remove them.
PM->add(createInstructionCombiningPass());
PM->add(polly::createCodePreparationPass());
polly::registerPollyPasses(*PM);
PM->add(polly::createCodegenCleanupPass());
#endif
// LoopRotate strips metadata from terminator, so run LowerSIMD afterwards
PM->add(createLowerSimdLoopPass()); // Annotate loop marked with "loopinfo" as LLVM parallel loop
PM->add(createLICMPass());
PM->add(createJuliaLICMPass());
PM->add(createLoopUnswitchPass());
PM->add(createLICMPass());
PM->add(createJuliaLICMPass());
PM->add(createInductiveRangeCheckEliminationPass()); // Must come before indvars
// Subsequent passes not stripping metadata from terminator
PM->add(createInstSimplifyLegacyPass());
PM->add(createLoopIdiomPass());
PM->add(createIndVarSimplifyPass());
PM->add(createLoopDeletionPass());
PM->add(createSimpleLoopUnrollPass());
// Run our own SROA on heap objects before LLVM's
PM->add(createAllocOptPass());
// Re-run SROA after loop-unrolling (useful for small loops that operate,
// over the structure of an aggregate)
PM->add(createSROAPass());
// might not be necessary:
PM->add(createInstSimplifyLegacyPass());
PM->add(createGVNPass());
PM->add(createMemCpyOptPass());
PM->add(createSCCPPass());
//These next two passes must come before IRCE to eliminate the bounds check in #43308
PM->add(createCorrelatedValuePropagationPass());
PM->add(createDeadCodeEliminationPass());
PM->add(createInductiveRangeCheckEliminationPass()); // Must come between the two GVN passes
// Run instcombine after redundancy elimination to exploit opportunities
// opened up by them.
// This needs to be InstCombine instead of InstSimplify to allow
// loops over Union-typed arrays to vectorize.
PM->add(createInstructionCombiningPass());
PM->add(createJumpThreadingPass());
if (opt_level >= 3) {
PM->add(createGVNPass()); // Must come after JumpThreading and before LoopVectorize
}
PM->add(createDeadStoreEliminationPass());
// More dead allocation (store) deletion before loop optimization
// consider removing this:
PM->add(createAllocOptPass());
// see if all of the constant folding has exposed more loops
// to simplification and deletion
// this helps significantly with cleaning up iteration
PM->add(createCFGSimplificationPass()); // See note above, don't hoist instructions before LV
PM->add(createLoopDeletionPass());
PM->add(createInstructionCombiningPass());
PM->add(createLoopVectorizePass());
PM->add(createLoopLoadEliminationPass());
// Cleanup after LV pass
PM->add(createInstructionCombiningPass());
PM->add(createCFGSimplificationPass( // Aggressive CFG simplification
SimplifyCFGOptions()
.forwardSwitchCondToPhi(true)
.convertSwitchToLookupTable(true)
.needCanonicalLoops(false)
.hoistCommonInsts(true)
// .sinkCommonInsts(true) // FIXME: Causes assertion in llvm-late-lowering
));
PM->add(createSLPVectorizerPass());
// might need this after LLVM 11:
//PM->add(createVectorCombinePass());
PM->add(createAggressiveDCEPass());
if (lower_intrinsics) {
// LowerPTLS removes an indirect call. As a result, it is likely to trigger
// LLVM's devirtualization heuristics, which would result in the entire
// pass pipeline being re-exectuted. Prevent this by inserting a barrier.
PM->add(createBarrierNoopPass());
PM->add(createLowerExcHandlersPass());
PM->add(createGCInvariantVerifierPass(false));
// Needed **before** LateLowerGCFrame on LLVM < 12
// due to bug in `CreateAlignmentAssumption`.
PM->add(createRemoveNIPass());
PM->add(createLateLowerGCFramePass());
PM->add(createFinalLowerGCPass());
// We need these two passes and the instcombine below
// after GC lowering to let LLVM do some constant propagation on the tags.
// and remove some unnecessary write barrier checks.
PM->add(createGVNPass());
PM->add(createSCCPPass());
// Remove dead use of ptls
PM->add(createDeadCodeEliminationPass());
PM->add(createLowerPTLSPass(dump_native));
PM->add(createInstructionCombiningPass());
// Clean up write barrier and ptls lowering
PM->add(createCFGSimplificationPass());
}
else {
PM->add(createRemoveNIPass());
}
PM->add(createCombineMulAddPass());
PM->add(createDivRemPairsPass());
#if defined(_COMPILER_ASAN_ENABLED_)
PM->add(createAddressSanitizerFunctionPass());
#endif
#if defined(_COMPILER_MSAN_ENABLED_)
PM->add(createMemorySanitizerPass(true));
#endif
#if defined(_COMPILER_TSAN_ENABLED_)
PM->add(createThreadSanitizerLegacyPassPass());
#endif
}
// An LLVM module pass that just runs all julia passes in order. Useful for
// debugging
template <int OptLevel>
class JuliaPipeline : public Pass {
public:
static char ID;
// A bit of a hack, but works
struct TPMAdapter : public PassManagerBase {
PMTopLevelManager *TPM;
TPMAdapter(PMTopLevelManager *TPM) : TPM(TPM) {}
void add(Pass *P) { TPM->schedulePass(P); }
};
void preparePassManager(PMStack &Stack) override {
(void)jl_init_llvm();
PMTopLevelManager *TPM = Stack.top()->getTopLevelManager();
TPMAdapter Adapter(TPM);
addTargetPasses(&Adapter, jl_TargetMachine);
addOptimizationPasses(&Adapter, OptLevel);
addMachinePasses(&Adapter, jl_TargetMachine, OptLevel);
}
JuliaPipeline() : Pass(PT_PassManager, ID) {}
Pass *createPrinterPass(raw_ostream &O, const std::string &Banner) const override {
return createPrintModulePass(O, Banner);
}
};
template<> char JuliaPipeline<0>::ID = 0;
template<> char JuliaPipeline<2>::ID = 0;
template<> char JuliaPipeline<3>::ID = 0;
static RegisterPass<JuliaPipeline<0>> X("juliaO0", "Runs the entire julia pipeline (at -O0)", false, false);
static RegisterPass<JuliaPipeline<2>> Y("julia", "Runs the entire julia pipeline (at -O2)", false, false);
static RegisterPass<JuliaPipeline<3>> Z("juliaO3", "Runs the entire julia pipeline (at -O3)", false, false);
extern "C" JL_DLLEXPORT
void jl_add_optimization_passes_impl(LLVMPassManagerRef PM, int opt_level, int lower_intrinsics) {
addOptimizationPasses(unwrap(PM), opt_level, lower_intrinsics);
}
// new pass manager plugin
// NOTE: Instead of exporting all the constructors in passes.h we could
// forward the callbacks to the respective passes. LLVM seems to prefer this,
// and when we add the full pass builder having them directly will be helpful.
static void registerCallbacks(PassBuilder &PB) {
PB.registerPipelineParsingCallback(
[](StringRef Name, FunctionPassManager &PM,
ArrayRef<PassBuilder::PipelineElement> InnerPipeline) {
if (Name == "DemoteFloat16") {
PM.addPass(DemoteFloat16());
return true;
}
if (Name == "CombineMulAdd") {
PM.addPass(CombineMulAdd());
return true;
}
if (Name == "LateLowerGCFrame") {
PM.addPass(LateLowerGC());
return true;
}
if (Name == "AllocOpt") {
PM.addPass(AllocOptPass());
return true;
}
if (Name == "PropagateJuliaAddrspaces") {
PM.addPass(PropagateJuliaAddrspacesPass());
return true;
}
if (Name == "LowerExcHandlers") {
PM.addPass(LowerExcHandlers());
return true;
}
if (Name == "GCInvariantVerifier") {
// TODO: Parse option and allow users to set `Strong`
PM.addPass(GCInvariantVerifierPass());
return true;
}
return false;
});
PB.registerPipelineParsingCallback(
[](StringRef Name, ModulePassManager &PM,
ArrayRef<PassBuilder::PipelineElement> InnerPipeline) {
if (Name == "CPUFeatures") {
PM.addPass(CPUFeatures());
return true;
}
if (Name == "RemoveNI") {
PM.addPass(RemoveNI());
return true;
}
if (Name == "LowerSIMDLoop") {
PM.addPass(LowerSIMDLoop());
return true;
}
if (Name == "FinalLowerGC") {
PM.addPass(FinalLowerGCPass());
return true;
}
if (Name == "RemoveJuliaAddrspaces") {
PM.addPass(RemoveJuliaAddrspacesPass());
return true;
}
if (Name == "MultiVersioning") {
PM.addPass(MultiVersioning());
return true;
}
if (Name == "LowerPTLS") {
PM.addPass(LowerPTLSPass());
return true;
}
return false;
});
PB.registerPipelineParsingCallback(
[](StringRef Name, LoopPassManager &PM,
ArrayRef<PassBuilder::PipelineElement> InnerPipeline) {
if (Name == "JuliaLICM") {
PM.addPass(JuliaLICMPass());
return true;
}
return false;
});
}
extern "C" JL_DLLEXPORT ::llvm::PassPluginLibraryInfo
llvmGetPassPluginInfo() {
return {LLVM_PLUGIN_API_VERSION, "Julia", "1", registerCallbacks};
}
// --- native code info, and dump function to IR and ASM ---
// Get pointer to llvm::Function instance, compiling if necessary
// for use in reflection from Julia.
// this is paired with jl_dump_function_ir, jl_dump_function_asm, jl_dump_method_asm in particular ways:
// misuse will leak memory or cause read-after-free
extern "C" JL_DLLEXPORT
void *jl_get_llvmf_defn_impl(jl_method_instance_t *mi, size_t world, char getwrapper, char optimize, const jl_cgparams_t params)
{
if (jl_is_method(mi->def.method) && mi->def.method->source == NULL &&
mi->def.method->generator == NULL) {
// not a generic function
return NULL;
}
static legacy::PassManager *PM;
if (!PM) {
PM = new legacy::PassManager();
addTargetPasses(PM, jl_TargetMachine);
addOptimizationPasses(PM, jl_options.opt_level);
addMachinePasses(PM, jl_TargetMachine, jl_options.opt_level);
}
// get the source code for this function
jl_value_t *jlrettype = (jl_value_t*)jl_any_type;
jl_code_info_t *src = NULL;
JL_GC_PUSH2(&src, &jlrettype);
jl_value_t *ci = jl_rettype_inferred(mi, world, world);
if (ci != jl_nothing) {
jl_code_instance_t *codeinst = (jl_code_instance_t*)ci;
src = (jl_code_info_t*)codeinst->inferred;
if ((jl_value_t*)src != jl_nothing && !jl_is_code_info(src) && jl_is_method(mi->def.method))
src = jl_uncompress_ir(mi->def.method, codeinst, (jl_array_t*)src);
jlrettype = codeinst->rettype;
}
if (!src || (jl_value_t*)src == jl_nothing) {
src = jl_type_infer(mi, world, 0);
if (src)
jlrettype = src->rettype;
else if (jl_is_method(mi->def.method)) {
src = mi->def.method->generator ? jl_code_for_staged(mi) : (jl_code_info_t*)mi->def.method->source;
if (src && !jl_is_code_info(src) && jl_is_method(mi->def.method))
src = jl_uncompress_ir(mi->def.method, NULL, (jl_array_t*)src);
}
// TODO: use mi->uninferred
}
// emit this function into a new llvm module
if (src && jl_is_code_info(src)) {
jl_codegen_params_t output;
output.world = world;
output.params = ¶ms;
std::unique_ptr<Module> m;
jl_llvm_functions_t decls;
JL_LOCK(&jl_codegen_lock);
uint64_t compiler_start_time = 0;
uint8_t measure_compile_time_enabled = jl_atomic_load_relaxed(&jl_measure_compile_time_enabled);
if (measure_compile_time_enabled)
compiler_start_time = jl_hrtime();
std::tie(m, decls) = jl_emit_code(mi, src, jlrettype, output);
Function *F = NULL;
if (m) {
// if compilation succeeded, prepare to return the result
// For imaging mode, global constants are currently private without initializer
// which isn't legal. Convert them to extern linkage so that the code can compile
// and will better match what's actually in sysimg.
for (auto &global : output.globals)
global.second->setLinkage(GlobalValue::ExternalLinkage);
if (optimize)
PM->run(*m.get());
const std::string *fname;
if (decls.functionObject == "jl_fptr_args" || decls.functionObject == "jl_fptr_sparam")
getwrapper = false;
if (!getwrapper)
fname = &decls.specFunctionObject;
else
fname = &decls.functionObject;
F = cast<Function>(m->getNamedValue(*fname));
m.release(); // the return object `llvmf` will be the owning pointer
}
JL_GC_POP();
if (measure_compile_time_enabled)
jl_atomic_fetch_add_relaxed(&jl_cumulative_compile_time, (jl_hrtime() - compiler_start_time));
JL_UNLOCK(&jl_codegen_lock); // Might GC
if (F)
return F;
}
const char *mname = name_from_method_instance(mi);
jl_errorf("unable to compile source for function %s", mname);
}
|
;;
;; Copyright (c) 2012-2020, Intel Corporation
;;
;; Redistribution and use in source and binary forms, with or without
;; modification, are permitted provided that the following conditions are met:
;;
;; * Redistributions of source code must retain the above copyright notice,
;; this list of conditions and the following disclaimer.
;; * Redistributions in binary form must reproduce the above copyright
;; notice, this list of conditions and the following disclaimer in the
;; documentation and/or other materials provided with the distribution.
;; * Neither the name of Intel Corporation nor the names of its contributors
;; may be used to endorse or promote products derived from this software
;; without specific prior written permission.
;;
;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
;; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
;; DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
;; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
;; SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
;; CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
;; OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
;; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
;;
;;; routine to do 128 bit AES XCBC
;; clobbers all registers except for ARG1 and rbp
%include "include/os.asm"
%include "mb_mgr_datastruct.asm"
%include "include/clear_regs.asm"
%define VMOVDQ vmovdqu ;; assume buffers not aligned
%macro VPXOR2 2
vpxor %1, %1, %2
%endm
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; struct AES_XCBC_ARGS_x8 {
;; void* in[8];
;; UINT128* keys[8];
;; UINT128 ICV[8];
;; }
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; void aes_xcbc_mac_128_x8(AES_XCBC_ARGS_x8 *args, UINT64 len);
;; arg 1: ARG : addr of AES_XCBC_ARGS_x8 structure
;; arg 2: LEN : len (in units of bytes)
struc STACK
_gpr_save: resq 1
_len: resq 1
endstruc
%define GPR_SAVE_AREA rsp + _gpr_save
%define LEN_AREA rsp + _len
%ifdef LINUX
%define ARG rdi
%define LEN rsi
%define REG3 rcx
%define REG4 rdx
%else
%define ARG rcx
%define LEN rdx
%define REG3 rsi
%define REG4 rdi
%endif
%define IDX rax
%define TMP rbx
%define KEYS0 REG3
%define KEYS1 REG4
%define KEYS2 rbp
%define KEYS3 r8
%define KEYS4 r9
%define KEYS5 r10
%define KEYS6 r11
%define KEYS7 r12
%define IN0 r13
%define IN2 r14
%define IN4 r15
%define IN6 LEN
%define XDATA0 xmm0
%define XDATA1 xmm1
%define XDATA2 xmm2
%define XDATA3 xmm3
%define XDATA4 xmm4
%define XDATA5 xmm5
%define XDATA6 xmm6
%define XDATA7 xmm7
%define XKEY0_3 xmm8
%define XKEY1_4 xmm9
%define XKEY2_5 xmm10
%define XKEY3_6 xmm11
%define XKEY4_7 xmm12
%define XKEY5_8 xmm13
%define XKEY6_9 xmm14
%define XTMP xmm15
section .text
MKGLOBAL(aes_xcbc_mac_128_x8,function,internal)
aes_xcbc_mac_128_x8:
sub rsp, STACK_size
mov [GPR_SAVE_AREA + 8*0], rbp
mov IDX, 16
mov [LEN_AREA], LEN
mov IN0, [ARG + _aesxcbcarg_in + 8*0]
mov IN2, [ARG + _aesxcbcarg_in + 8*2]
mov IN4, [ARG + _aesxcbcarg_in + 8*4]
mov IN6, [ARG + _aesxcbcarg_in + 8*6]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
mov TMP, [ARG + _aesxcbcarg_in + 8*1]
VMOVDQ XDATA0, [IN0] ; load first block of plain text
VMOVDQ XDATA1, [TMP] ; load first block of plain text
mov TMP, [ARG + _aesxcbcarg_in + 8*3]
VMOVDQ XDATA2, [IN2] ; load first block of plain text
VMOVDQ XDATA3, [TMP] ; load first block of plain text
mov TMP, [ARG + _aesxcbcarg_in + 8*5]
VMOVDQ XDATA4, [IN4] ; load first block of plain text
VMOVDQ XDATA5, [TMP] ; load first block of plain text
mov TMP, [ARG + _aesxcbcarg_in + 8*7]
VMOVDQ XDATA6, [IN6] ; load first block of plain text
VMOVDQ XDATA7, [TMP] ; load first block of plain text
VPXOR2 XDATA0, [ARG + _aesxcbcarg_ICV + 16*0] ; plaintext XOR ICV
VPXOR2 XDATA1, [ARG + _aesxcbcarg_ICV + 16*1] ; plaintext XOR ICV
VPXOR2 XDATA2, [ARG + _aesxcbcarg_ICV + 16*2] ; plaintext XOR ICV
VPXOR2 XDATA3, [ARG + _aesxcbcarg_ICV + 16*3] ; plaintext XOR ICV
VPXOR2 XDATA4, [ARG + _aesxcbcarg_ICV + 16*4] ; plaintext XOR ICV
VPXOR2 XDATA5, [ARG + _aesxcbcarg_ICV + 16*5] ; plaintext XOR ICV
VPXOR2 XDATA6, [ARG + _aesxcbcarg_ICV + 16*6] ; plaintext XOR ICV
VPXOR2 XDATA7, [ARG + _aesxcbcarg_ICV + 16*7] ; plaintext XOR ICV
mov KEYS0, [ARG + _aesxcbcarg_keys + 8*0]
mov KEYS1, [ARG + _aesxcbcarg_keys + 8*1]
mov KEYS2, [ARG + _aesxcbcarg_keys + 8*2]
mov KEYS3, [ARG + _aesxcbcarg_keys + 8*3]
mov KEYS4, [ARG + _aesxcbcarg_keys + 8*4]
mov KEYS5, [ARG + _aesxcbcarg_keys + 8*5]
mov KEYS6, [ARG + _aesxcbcarg_keys + 8*6]
mov KEYS7, [ARG + _aesxcbcarg_keys + 8*7]
VPXOR2 XDATA0, [KEYS0 + 16*0] ; 0. ARK
VPXOR2 XDATA1, [KEYS1 + 16*0] ; 0. ARK
VPXOR2 XDATA2, [KEYS2 + 16*0] ; 0. ARK
VPXOR2 XDATA3, [KEYS3 + 16*0] ; 0. ARK
VPXOR2 XDATA4, [KEYS4 + 16*0] ; 0. ARK
VPXOR2 XDATA5, [KEYS5 + 16*0] ; 0. ARK
VPXOR2 XDATA6, [KEYS6 + 16*0] ; 0. ARK
VPXOR2 XDATA7, [KEYS7 + 16*0] ; 0. ARK
vaesenc XDATA0, [KEYS0 + 16*1] ; 1. ENC
vaesenc XDATA1, [KEYS1 + 16*1] ; 1. ENC
vaesenc XDATA2, [KEYS2 + 16*1] ; 1. ENC
vaesenc XDATA3, [KEYS3 + 16*1] ; 1. ENC
vaesenc XDATA4, [KEYS4 + 16*1] ; 1. ENC
vaesenc XDATA5, [KEYS5 + 16*1] ; 1. ENC
vaesenc XDATA6, [KEYS6 + 16*1] ; 1. ENC
vaesenc XDATA7, [KEYS7 + 16*1] ; 1. ENC
vmovdqa XKEY0_3, [KEYS0 + 16*3] ; load round 3 key
vaesenc XDATA0, [KEYS0 + 16*2] ; 2. ENC
vaesenc XDATA1, [KEYS1 + 16*2] ; 2. ENC
vaesenc XDATA2, [KEYS2 + 16*2] ; 2. ENC
vaesenc XDATA3, [KEYS3 + 16*2] ; 2. ENC
vaesenc XDATA4, [KEYS4 + 16*2] ; 2. ENC
vaesenc XDATA5, [KEYS5 + 16*2] ; 2. ENC
vaesenc XDATA6, [KEYS6 + 16*2] ; 2. ENC
vaesenc XDATA7, [KEYS7 + 16*2] ; 2. ENC
vmovdqa XKEY1_4, [KEYS1 + 16*4] ; load round 4 key
vaesenc XDATA0, XKEY0_3 ; 3. ENC
vaesenc XDATA1, [KEYS1 + 16*3] ; 3. ENC
vaesenc XDATA2, [KEYS2 + 16*3] ; 3. ENC
vaesenc XDATA3, [KEYS3 + 16*3] ; 3. ENC
vaesenc XDATA4, [KEYS4 + 16*3] ; 3. ENC
vaesenc XDATA5, [KEYS5 + 16*3] ; 3. ENC
vaesenc XDATA6, [KEYS6 + 16*3] ; 3. ENC
vaesenc XDATA7, [KEYS7 + 16*3] ; 3. ENC
vaesenc XDATA0, [KEYS0 + 16*4] ; 4. ENC
vmovdqa XKEY2_5, [KEYS2 + 16*5] ; load round 5 key
vaesenc XDATA1, XKEY1_4 ; 4. ENC
vaesenc XDATA2, [KEYS2 + 16*4] ; 4. ENC
vaesenc XDATA3, [KEYS3 + 16*4] ; 4. ENC
vaesenc XDATA4, [KEYS4 + 16*4] ; 4. ENC
vaesenc XDATA5, [KEYS5 + 16*4] ; 4. ENC
vaesenc XDATA6, [KEYS6 + 16*4] ; 4. ENC
vaesenc XDATA7, [KEYS7 + 16*4] ; 4. ENC
vaesenc XDATA0, [KEYS0 + 16*5] ; 5. ENC
vaesenc XDATA1, [KEYS1 + 16*5] ; 5. ENC
vmovdqa XKEY3_6, [KEYS3 + 16*6] ; load round 6 key
vaesenc XDATA2, XKEY2_5 ; 5. ENC
vaesenc XDATA3, [KEYS3 + 16*5] ; 5. ENC
vaesenc XDATA4, [KEYS4 + 16*5] ; 5. ENC
vaesenc XDATA5, [KEYS5 + 16*5] ; 5. ENC
vaesenc XDATA6, [KEYS6 + 16*5] ; 5. ENC
vaesenc XDATA7, [KEYS7 + 16*5] ; 5. ENC
vaesenc XDATA0, [KEYS0 + 16*6] ; 6. ENC
vaesenc XDATA1, [KEYS1 + 16*6] ; 6. ENC
vaesenc XDATA2, [KEYS2 + 16*6] ; 6. ENC
vmovdqa XKEY4_7, [KEYS4 + 16*7] ; load round 7 key
vaesenc XDATA3, XKEY3_6 ; 6. ENC
vaesenc XDATA4, [KEYS4 + 16*6] ; 6. ENC
vaesenc XDATA5, [KEYS5 + 16*6] ; 6. ENC
vaesenc XDATA6, [KEYS6 + 16*6] ; 6. ENC
vaesenc XDATA7, [KEYS7 + 16*6] ; 6. ENC
vaesenc XDATA0, [KEYS0 + 16*7] ; 7. ENC
vaesenc XDATA1, [KEYS1 + 16*7] ; 7. ENC
vaesenc XDATA2, [KEYS2 + 16*7] ; 7. ENC
vaesenc XDATA3, [KEYS3 + 16*7] ; 7. ENC
vmovdqa XKEY5_8, [KEYS5 + 16*8] ; load round 8 key
vaesenc XDATA4, XKEY4_7 ; 7. ENC
vaesenc XDATA5, [KEYS5 + 16*7] ; 7. ENC
vaesenc XDATA6, [KEYS6 + 16*7] ; 7. ENC
vaesenc XDATA7, [KEYS7 + 16*7] ; 7. ENC
vaesenc XDATA0, [KEYS0 + 16*8] ; 8. ENC
vaesenc XDATA1, [KEYS1 + 16*8] ; 8. ENC
vaesenc XDATA2, [KEYS2 + 16*8] ; 8. ENC
vaesenc XDATA3, [KEYS3 + 16*8] ; 8. ENC
vaesenc XDATA4, [KEYS4 + 16*8] ; 8. ENC
vmovdqa XKEY6_9, [KEYS6 + 16*9] ; load round 9 key
vaesenc XDATA5, XKEY5_8 ; 8. ENC
vaesenc XDATA6, [KEYS6 + 16*8] ; 8. ENC
vaesenc XDATA7, [KEYS7 + 16*8] ; 8. ENC
vaesenc XDATA0, [KEYS0 + 16*9] ; 9. ENC
vaesenc XDATA1, [KEYS1 + 16*9] ; 9. ENC
vaesenc XDATA2, [KEYS2 + 16*9] ; 9. ENC
vaesenc XDATA3, [KEYS3 + 16*9] ; 9. ENC
vaesenc XDATA4, [KEYS4 + 16*9] ; 9. ENC
vaesenc XDATA5, [KEYS5 + 16*9] ; 9. ENC
vaesenc XDATA6, XKEY6_9 ; 9. ENC
vaesenc XDATA7, [KEYS7 + 16*9] ; 9. ENC
vaesenclast XDATA0, [KEYS0 + 16*10] ; 10. ENC
vaesenclast XDATA1, [KEYS1 + 16*10] ; 10. ENC
vaesenclast XDATA2, [KEYS2 + 16*10] ; 10. ENC
vaesenclast XDATA3, [KEYS3 + 16*10] ; 10. ENC
vaesenclast XDATA4, [KEYS4 + 16*10] ; 10. ENC
vaesenclast XDATA5, [KEYS5 + 16*10] ; 10. ENC
vaesenclast XDATA6, [KEYS6 + 16*10] ; 10. ENC
vaesenclast XDATA7, [KEYS7 + 16*10] ; 10. ENC
cmp [LEN_AREA], IDX
je done
main_loop:
mov TMP, [ARG + _aesxcbcarg_in + 8*1]
VPXOR2 XDATA0, [IN0 + IDX] ; load next block of plain text
VPXOR2 XDATA1, [TMP + IDX] ; load next block of plain text
mov TMP, [ARG + _aesxcbcarg_in + 8*3]
VPXOR2 XDATA2, [IN2 + IDX] ; load next block of plain text
VPXOR2 XDATA3, [TMP + IDX] ; load next block of plain text
mov TMP, [ARG + _aesxcbcarg_in + 8*5]
VPXOR2 XDATA4, [IN4 + IDX] ; load next block of plain text
VPXOR2 XDATA5, [TMP + IDX] ; load next block of plain text
mov TMP, [ARG + _aesxcbcarg_in + 8*7]
VPXOR2 XDATA6, [IN6 + IDX] ; load next block of plain text
VPXOR2 XDATA7, [TMP + IDX] ; load next block of plain text
VPXOR2 XDATA0, [KEYS0 + 16*0] ; 0. ARK
VPXOR2 XDATA1, [KEYS1 + 16*0] ; 0. ARK
VPXOR2 XDATA2, [KEYS2 + 16*0] ; 0. ARK
VPXOR2 XDATA3, [KEYS3 + 16*0] ; 0. ARK
VPXOR2 XDATA4, [KEYS4 + 16*0] ; 0. ARK
VPXOR2 XDATA5, [KEYS5 + 16*0] ; 0. ARK
VPXOR2 XDATA6, [KEYS6 + 16*0] ; 0. ARK
VPXOR2 XDATA7, [KEYS7 + 16*0] ; 0. ARK
vaesenc XDATA0, [KEYS0 + 16*1] ; 1. ENC
vaesenc XDATA1, [KEYS1 + 16*1] ; 1. ENC
vaesenc XDATA2, [KEYS2 + 16*1] ; 1. ENC
vaesenc XDATA3, [KEYS3 + 16*1] ; 1. ENC
vaesenc XDATA4, [KEYS4 + 16*1] ; 1. ENC
vaesenc XDATA5, [KEYS5 + 16*1] ; 1. ENC
vaesenc XDATA6, [KEYS6 + 16*1] ; 1. ENC
vaesenc XDATA7, [KEYS7 + 16*1] ; 1. ENC
vaesenc XDATA0, [KEYS0 + 16*2] ; 2. ENC
vaesenc XDATA1, [KEYS1 + 16*2] ; 2. ENC
vaesenc XDATA2, [KEYS2 + 16*2] ; 2. ENC
vaesenc XDATA3, [KEYS3 + 16*2] ; 2. ENC
vaesenc XDATA4, [KEYS4 + 16*2] ; 2. ENC
vaesenc XDATA5, [KEYS5 + 16*2] ; 2. ENC
vaesenc XDATA6, [KEYS6 + 16*2] ; 2. ENC
vaesenc XDATA7, [KEYS7 + 16*2] ; 2. ENC
vaesenc XDATA0, XKEY0_3 ; 3. ENC
vaesenc XDATA1, [KEYS1 + 16*3] ; 3. ENC
vaesenc XDATA2, [KEYS2 + 16*3] ; 3. ENC
vaesenc XDATA3, [KEYS3 + 16*3] ; 3. ENC
vaesenc XDATA4, [KEYS4 + 16*3] ; 3. ENC
vaesenc XDATA5, [KEYS5 + 16*3] ; 3. ENC
vaesenc XDATA6, [KEYS6 + 16*3] ; 3. ENC
vaesenc XDATA7, [KEYS7 + 16*3] ; 3. ENC
vaesenc XDATA0, [KEYS0 + 16*4] ; 4. ENC
vaesenc XDATA1, XKEY1_4 ; 4. ENC
vaesenc XDATA2, [KEYS2 + 16*4] ; 4. ENC
vaesenc XDATA3, [KEYS3 + 16*4] ; 4. ENC
vaesenc XDATA4, [KEYS4 + 16*4] ; 4. ENC
vaesenc XDATA5, [KEYS5 + 16*4] ; 4. ENC
vaesenc XDATA6, [KEYS6 + 16*4] ; 4. ENC
vaesenc XDATA7, [KEYS7 + 16*4] ; 4. ENC
vaesenc XDATA0, [KEYS0 + 16*5] ; 5. ENC
vaesenc XDATA1, [KEYS1 + 16*5] ; 5. ENC
vaesenc XDATA2, XKEY2_5 ; 5. ENC
vaesenc XDATA3, [KEYS3 + 16*5] ; 5. ENC
vaesenc XDATA4, [KEYS4 + 16*5] ; 5. ENC
vaesenc XDATA5, [KEYS5 + 16*5] ; 5. ENC
vaesenc XDATA6, [KEYS6 + 16*5] ; 5. ENC
vaesenc XDATA7, [KEYS7 + 16*5] ; 5. ENC
vaesenc XDATA0, [KEYS0 + 16*6] ; 6. ENC
vaesenc XDATA1, [KEYS1 + 16*6] ; 6. ENC
vaesenc XDATA2, [KEYS2 + 16*6] ; 6. ENC
vaesenc XDATA3, XKEY3_6 ; 6. ENC
vaesenc XDATA4, [KEYS4 + 16*6] ; 6. ENC
vaesenc XDATA5, [KEYS5 + 16*6] ; 6. ENC
vaesenc XDATA6, [KEYS6 + 16*6] ; 6. ENC
vaesenc XDATA7, [KEYS7 + 16*6] ; 6. ENC
vaesenc XDATA0, [KEYS0 + 16*7] ; 7. ENC
vaesenc XDATA1, [KEYS1 + 16*7] ; 7. ENC
vaesenc XDATA2, [KEYS2 + 16*7] ; 7. ENC
vaesenc XDATA3, [KEYS3 + 16*7] ; 7. ENC
vaesenc XDATA4, XKEY4_7 ; 7. ENC
vaesenc XDATA5, [KEYS5 + 16*7] ; 7. ENC
vaesenc XDATA6, [KEYS6 + 16*7] ; 7. ENC
vaesenc XDATA7, [KEYS7 + 16*7] ; 7. ENC
vaesenc XDATA0, [KEYS0 + 16*8] ; 8. ENC
vaesenc XDATA1, [KEYS1 + 16*8] ; 8. ENC
vaesenc XDATA2, [KEYS2 + 16*8] ; 8. ENC
vaesenc XDATA3, [KEYS3 + 16*8] ; 8. ENC
vaesenc XDATA4, [KEYS4 + 16*8] ; 8. ENC
vaesenc XDATA5, XKEY5_8 ; 8. ENC
vaesenc XDATA6, [KEYS6 + 16*8] ; 8. ENC
vaesenc XDATA7, [KEYS7 + 16*8] ; 8. ENC
vaesenc XDATA0, [KEYS0 + 16*9] ; 9. ENC
vaesenc XDATA1, [KEYS1 + 16*9] ; 9. ENC
vaesenc XDATA2, [KEYS2 + 16*9] ; 9. ENC
vaesenc XDATA3, [KEYS3 + 16*9] ; 9. ENC
vaesenc XDATA4, [KEYS4 + 16*9] ; 9. ENC
vaesenc XDATA5, [KEYS5 + 16*9] ; 9. ENC
vaesenc XDATA6, XKEY6_9 ; 9. ENC
vaesenc XDATA7, [KEYS7 + 16*9] ; 9. ENC
vaesenclast XDATA0, [KEYS0 + 16*10] ; 10. ENC
vaesenclast XDATA1, [KEYS1 + 16*10] ; 10. ENC
vaesenclast XDATA2, [KEYS2 + 16*10] ; 10. ENC
vaesenclast XDATA3, [KEYS3 + 16*10] ; 10. ENC
vaesenclast XDATA4, [KEYS4 + 16*10] ; 10. ENC
vaesenclast XDATA5, [KEYS5 + 16*10] ; 10. ENC
vaesenclast XDATA6, [KEYS6 + 16*10] ; 10. ENC
vaesenclast XDATA7, [KEYS7 + 16*10] ; 10. ENC
add IDX, 16
cmp [LEN_AREA], IDX
jne main_loop
done:
;; update ICV
vmovdqa [ARG + _aesxcbcarg_ICV + 16*0], XDATA0
vmovdqa [ARG + _aesxcbcarg_ICV + 16*1], XDATA1
vmovdqa [ARG + _aesxcbcarg_ICV + 16*2], XDATA2
vmovdqa [ARG + _aesxcbcarg_ICV + 16*3], XDATA3
vmovdqa [ARG + _aesxcbcarg_ICV + 16*4], XDATA4
vmovdqa [ARG + _aesxcbcarg_ICV + 16*5], XDATA5
vmovdqa [ARG + _aesxcbcarg_ICV + 16*6], XDATA6
vmovdqa [ARG + _aesxcbcarg_ICV + 16*7], XDATA7
;; update IN
vmovd xmm0, [LEN_AREA]
vpshufd xmm0, xmm0, 0x44
vpaddq xmm1, xmm0, [ARG + _aesxcbcarg_in + 16*0]
vpaddq xmm2, xmm0, [ARG + _aesxcbcarg_in + 16*1]
vpaddq xmm3, xmm0, [ARG + _aesxcbcarg_in + 16*2]
vpaddq xmm4, xmm0, [ARG + _aesxcbcarg_in + 16*3]
vmovdqa [ARG + _aesxcbcarg_in + 16*0], xmm1
vmovdqa [ARG + _aesxcbcarg_in + 16*1], xmm2
vmovdqa [ARG + _aesxcbcarg_in + 16*2], xmm3
vmovdqa [ARG + _aesxcbcarg_in + 16*3], xmm4
;; XMMs are saved at a higher level
mov rbp, [GPR_SAVE_AREA + 8*0]
add rsp, STACK_size
%ifdef SAFE_DATA
clear_all_xmms_avx_asm
%endif ;; SAFE_DATA
ret
%ifdef LINUX
section .note.GNU-stack noalloc noexec nowrite progbits
%endif
|
SECTION code_clib
PUBLIC bit_open_di
PUBLIC _bit_open_di
EXTERN bit_open
EXTERN __snd_tick
EXTERN __bit_irqstatus
INCLUDE "games/games.inc"
.bit_open_di
._bit_open_di
ld a,($403B)
ld (__bit_irqstatus),a
and @01111111 ;Disable NMI (i.e. how interrupts are delivered), set
out ($0),a
and @01101111 ;Set piezzo to stand-by
ld (__snd_tick),a
ret
|
; Listing generated by Microsoft (R) Optimizing Compiler Version 19.16.27027.1
TITLE C:\Users\DAG\Documents\_Clients\CodeProject Authors Group\Windows on ARM\libxml2\libxml2-2.9.9\error.c
.686P
.XMM
include listing.inc
.model flat
INCLUDELIB MSVCRT
INCLUDELIB OLDNAMES
_DATA SEGMENT
COMM _xmlMalloc:DWORD
COMM _xmlMallocAtomic:DWORD
COMM _xmlRealloc:DWORD
COMM _xmlFree:DWORD
COMM _xmlMemStrdup:DWORD
COMM _forbiddenExp:DWORD
COMM _emptyExp:DWORD
_DATA ENDS
msvcjmc SEGMENT
__188180DA_corecrt_math@h DB 01H
__2CC6E67D_corecrt_stdio_config@h DB 01H
__05476D76_corecrt_wstdio@h DB 01H
__A452D4A0_stdio@h DB 01H
__4384A2D9_corecrt_memcpy_s@h DB 01H
__4E51A221_corecrt_wstring@h DB 01H
__2140C079_string@h DB 01H
__67926DEE_error@c DB 01H
msvcjmc ENDS
PUBLIC ___local_stdio_printf_options
PUBLIC _fprintf
PUBLIC _xmlSetGenericErrorFunc
PUBLIC _initGenericErrorDefaultFunc
PUBLIC _xmlSetStructuredErrorFunc
PUBLIC _xmlParserError
PUBLIC _xmlParserWarning
PUBLIC _xmlParserValidityError
PUBLIC _xmlParserValidityWarning
PUBLIC _xmlParserPrintFileInfo
PUBLIC _xmlParserPrintFileContext
PUBLIC _xmlGetLastError
PUBLIC _xmlResetLastError
PUBLIC _xmlCtxtGetLastError
PUBLIC _xmlCtxtResetLastError
PUBLIC _xmlResetError
PUBLIC _xmlCopyError
PUBLIC ___xmlRaiseError
PUBLIC ___xmlSimpleError
PUBLIC _xmlGenericErrorDefaultFunc
PUBLIC __JustMyCode_Default
PUBLIC ??_C@_07FCDHCGBN@?$CFs?3?$CFd?3?5@ ; `string'
PUBLIC ??_C@_0BC@FMCMLLAH@Entity?3?5line?5?$CFd?3?5@ ; `string'
PUBLIC ??_C@_03OFAPEBGM@?$CFs?6@ ; `string'
PUBLIC ??_C@_0N@MLFICIIN@element?5?$CFs?3?5@ ; `string'
PUBLIC ??_C@_07CNNNFPCP@parser?5@ ; `string'
PUBLIC ??_C@_0L@BNCDLIEB@namespace?5@ ; `string'
PUBLIC ??_C@_09BIOOFDLF@validity?5@ ; `string'
PUBLIC ??_C@_0N@IENDNEBE@HTML?5parser?5@ ; `string'
PUBLIC ??_C@_07KICHBFMM@memory?5@ ; `string'
PUBLIC ??_C@_07NOLKHGJF@output?5@ ; `string'
PUBLIC ??_C@_04HKCNGDON@I?1O?5@ ; `string'
PUBLIC ??_C@_09JKGAONDL@XInclude?5@ ; `string'
PUBLIC ??_C@_06ONGIFIKK@XPath?5@ ; `string'
PUBLIC ??_C@_07IGPLNGGH@regexp?5@ ; `string'
PUBLIC ??_C@_07KEPCOONB@module?5@ ; `string'
PUBLIC ??_C@_0BC@MEEJMAME@Schemas?5validity?5@ ; `string'
PUBLIC ??_C@_0BA@COGPIGL@Schemas?5parser?5@ ; `string'
PUBLIC ??_C@_0BB@FGPKBGBA@Relax?9NG?5parser?5@ ; `string'
PUBLIC ??_C@_0BD@EPDAPLJK@Relax?9NG?5validity?5@ ; `string'
PUBLIC ??_C@_08NOLMNIGP@Catalog?5@ ; `string'
PUBLIC ??_C@_05MLHJFMDG@C14N?5@ ; `string'
PUBLIC ??_C@_05POKACEJG@XSLT?5@ ; `string'
PUBLIC ??_C@_09JICCLIJI@encoding?5@ ; `string'
PUBLIC ??_C@_0M@LAKDBFM@schematron?5@ ; `string'
PUBLIC ??_C@_0BB@FACNAIAH@internal?5buffer?5@ ; `string'
PUBLIC ??_C@_04ECOFBNJN@URI?5@ ; `string'
PUBLIC ??_C@_02LMMGGCAJ@?3?5@ ; `string'
PUBLIC ??_C@_0L@HNPIBIGM@warning?5?3?5@ ; `string'
PUBLIC ??_C@_08PMHKJNKP@error?5?3?5@ ; `string'
PUBLIC ??_C@_02DKCKIIND@?$CFs@ ; `string'
PUBLIC ??_C@_0BE@LHHHBFLE@out?5of?5memory?5error@ ; `string'
PUBLIC ??_C@_08JJLLLDHF@?$CFs?3?$CFd?3?5?6@ ; `string'
PUBLIC ??_C@_0BD@GENHFBJC@Entity?3?5line?5?$CFd?3?5?6@ ; `string'
PUBLIC ??_C@_0BK@ONMNHCCC@No?5error?5message?5provided@ ; `string'
PUBLIC ??_C@_04CMBCJJJD@href@ ; `string'
PUBLIC ??_C@_0BP@DJFHNAOK@Memory?5allocation?5failed?5?3?5?$CFs?6@ ; `string'
PUBLIC ??_C@_0BK@GDFDKGPJ@Memory?5allocation?5failed?6@ ; `string'
PUBLIC ??_C@_07FJOHCPOO@error?3?5@ ; `string'
PUBLIC ??_C@_01EEMJAFIK@?6@ ; `string'
PUBLIC ??_C@_09GFHECBDK@warning?3?5@ ; `string'
PUBLIC ??_C@_0BB@DJCEBDOI@validity?5error?3?5@ ; `string'
PUBLIC ??_C@_0BD@BMEBJKPI@validity?5warning?3?5@ ; `string'
EXTRN _xmlStrdup:PROC
EXTRN _xmlStrlen:PROC
EXTRN __imp____acrt_iob_func:PROC
EXTRN __imp____stdio_common_vfprintf:PROC
EXTRN __imp____stdio_common_vsprintf:PROC
EXTRN _xmlGetLineNo:PROC
EXTRN _xmlGetProp:PROC
EXTRN ___xmlLastError:PROC
EXTRN ___xmlGenericError:PROC
EXTRN ___xmlStructuredError:PROC
EXTRN ___xmlGenericErrorContext:PROC
EXTRN ___xmlStructuredErrorContext:PROC
EXTRN ___xmlGetWarningsDefaultValue:PROC
EXTRN @__CheckForDebuggerJustMyCode@4:PROC
EXTRN _memset:PROC
_DATA SEGMENT
COMM ?_OptionsStorage@?1??__local_stdio_printf_options@@9@9:QWORD ; `__local_stdio_printf_options'::`2'::_OptionsStorage
_DATA ENDS
_BSS SEGMENT
?had_info@?1??xmlParserValidityError@@9@9 DD 01H DUP (?) ; `xmlParserValidityError'::`2'::had_info
_BSS ENDS
; COMDAT ??_C@_0BD@BMEBJKPI@validity?5warning?3?5@
CONST SEGMENT
??_C@_0BD@BMEBJKPI@validity?5warning?3?5@ DB 'validity warning: ', 00H ; `string'
CONST ENDS
; COMDAT ??_C@_0BB@DJCEBDOI@validity?5error?3?5@
CONST SEGMENT
??_C@_0BB@DJCEBDOI@validity?5error?3?5@ DB 'validity error: ', 00H ; `string'
CONST ENDS
; COMDAT ??_C@_09GFHECBDK@warning?3?5@
CONST SEGMENT
??_C@_09GFHECBDK@warning?3?5@ DB 'warning: ', 00H ; `string'
CONST ENDS
; COMDAT ??_C@_01EEMJAFIK@?6@
CONST SEGMENT
??_C@_01EEMJAFIK@?6@ DB 0aH, 00H ; `string'
CONST ENDS
; COMDAT ??_C@_07FJOHCPOO@error?3?5@
CONST SEGMENT
??_C@_07FJOHCPOO@error?3?5@ DB 'error: ', 00H ; `string'
CONST ENDS
; COMDAT ??_C@_0BK@GDFDKGPJ@Memory?5allocation?5failed?6@
CONST SEGMENT
??_C@_0BK@GDFDKGPJ@Memory?5allocation?5failed?6@ DB 'Memory allocation fa'
DB 'iled', 0aH, 00H ; `string'
CONST ENDS
; COMDAT ??_C@_0BP@DJFHNAOK@Memory?5allocation?5failed?5?3?5?$CFs?6@
CONST SEGMENT
??_C@_0BP@DJFHNAOK@Memory?5allocation?5failed?5?3?5?$CFs?6@ DB 'Memory al'
DB 'location failed : %s', 0aH, 00H ; `string'
CONST ENDS
; COMDAT ??_C@_04CMBCJJJD@href@
CONST SEGMENT
??_C@_04CMBCJJJD@href@ DB 'href', 00H ; `string'
CONST ENDS
; COMDAT ??_C@_0BK@ONMNHCCC@No?5error?5message?5provided@
CONST SEGMENT
??_C@_0BK@ONMNHCCC@No?5error?5message?5provided@ DB 'No error message pro'
DB 'vided', 00H ; `string'
CONST ENDS
; COMDAT ??_C@_0BD@GENHFBJC@Entity?3?5line?5?$CFd?3?5?6@
CONST SEGMENT
??_C@_0BD@GENHFBJC@Entity?3?5line?5?$CFd?3?5?6@ DB 'Entity: line %d: ', 0aH
DB 00H ; `string'
CONST ENDS
; COMDAT ??_C@_08JJLLLDHF@?$CFs?3?$CFd?3?5?6@
CONST SEGMENT
??_C@_08JJLLLDHF@?$CFs?3?$CFd?3?5?6@ DB '%s:%d: ', 0aH, 00H ; `string'
CONST ENDS
; COMDAT ??_C@_0BE@LHHHBFLE@out?5of?5memory?5error@
CONST SEGMENT
??_C@_0BE@LHHHBFLE@out?5of?5memory?5error@ DB 'out of memory error', 00H ; `string'
CONST ENDS
; COMDAT ??_C@_02DKCKIIND@?$CFs@
CONST SEGMENT
??_C@_02DKCKIIND@?$CFs@ DB '%s', 00H ; `string'
CONST ENDS
; COMDAT ??_C@_08PMHKJNKP@error?5?3?5@
CONST SEGMENT
??_C@_08PMHKJNKP@error?5?3?5@ DB 'error : ', 00H ; `string'
CONST ENDS
; COMDAT ??_C@_0L@HNPIBIGM@warning?5?3?5@
CONST SEGMENT
??_C@_0L@HNPIBIGM@warning?5?3?5@ DB 'warning : ', 00H ; `string'
CONST ENDS
; COMDAT ??_C@_02LMMGGCAJ@?3?5@
CONST SEGMENT
??_C@_02LMMGGCAJ@?3?5@ DB ': ', 00H ; `string'
CONST ENDS
; COMDAT ??_C@_04ECOFBNJN@URI?5@
CONST SEGMENT
??_C@_04ECOFBNJN@URI?5@ DB 'URI ', 00H ; `string'
CONST ENDS
; COMDAT ??_C@_0BB@FACNAIAH@internal?5buffer?5@
CONST SEGMENT
??_C@_0BB@FACNAIAH@internal?5buffer?5@ DB 'internal buffer ', 00H ; `string'
CONST ENDS
; COMDAT ??_C@_0M@LAKDBFM@schematron?5@
CONST SEGMENT
??_C@_0M@LAKDBFM@schematron?5@ DB 'schematron ', 00H ; `string'
CONST ENDS
; COMDAT ??_C@_09JICCLIJI@encoding?5@
CONST SEGMENT
??_C@_09JICCLIJI@encoding?5@ DB 'encoding ', 00H ; `string'
CONST ENDS
; COMDAT ??_C@_05POKACEJG@XSLT?5@
CONST SEGMENT
??_C@_05POKACEJG@XSLT?5@ DB 'XSLT ', 00H ; `string'
CONST ENDS
; COMDAT ??_C@_05MLHJFMDG@C14N?5@
CONST SEGMENT
??_C@_05MLHJFMDG@C14N?5@ DB 'C14N ', 00H ; `string'
CONST ENDS
; COMDAT ??_C@_08NOLMNIGP@Catalog?5@
CONST SEGMENT
??_C@_08NOLMNIGP@Catalog?5@ DB 'Catalog ', 00H ; `string'
CONST ENDS
; COMDAT ??_C@_0BD@EPDAPLJK@Relax?9NG?5validity?5@
CONST SEGMENT
??_C@_0BD@EPDAPLJK@Relax?9NG?5validity?5@ DB 'Relax-NG validity ', 00H ; `string'
CONST ENDS
; COMDAT ??_C@_0BB@FGPKBGBA@Relax?9NG?5parser?5@
CONST SEGMENT
??_C@_0BB@FGPKBGBA@Relax?9NG?5parser?5@ DB 'Relax-NG parser ', 00H ; `string'
CONST ENDS
; COMDAT ??_C@_0BA@COGPIGL@Schemas?5parser?5@
CONST SEGMENT
??_C@_0BA@COGPIGL@Schemas?5parser?5@ DB 'Schemas parser ', 00H ; `string'
CONST ENDS
; COMDAT ??_C@_0BC@MEEJMAME@Schemas?5validity?5@
CONST SEGMENT
??_C@_0BC@MEEJMAME@Schemas?5validity?5@ DB 'Schemas validity ', 00H ; `string'
CONST ENDS
; COMDAT ??_C@_07KEPCOONB@module?5@
CONST SEGMENT
??_C@_07KEPCOONB@module?5@ DB 'module ', 00H ; `string'
CONST ENDS
; COMDAT ??_C@_07IGPLNGGH@regexp?5@
CONST SEGMENT
??_C@_07IGPLNGGH@regexp?5@ DB 'regexp ', 00H ; `string'
CONST ENDS
; COMDAT ??_C@_06ONGIFIKK@XPath?5@
CONST SEGMENT
??_C@_06ONGIFIKK@XPath?5@ DB 'XPath ', 00H ; `string'
CONST ENDS
; COMDAT ??_C@_09JKGAONDL@XInclude?5@
CONST SEGMENT
??_C@_09JKGAONDL@XInclude?5@ DB 'XInclude ', 00H ; `string'
CONST ENDS
; COMDAT ??_C@_04HKCNGDON@I?1O?5@
CONST SEGMENT
??_C@_04HKCNGDON@I?1O?5@ DB 'I/O ', 00H ; `string'
CONST ENDS
; COMDAT ??_C@_07NOLKHGJF@output?5@
CONST SEGMENT
??_C@_07NOLKHGJF@output?5@ DB 'output ', 00H ; `string'
CONST ENDS
; COMDAT ??_C@_07KICHBFMM@memory?5@
CONST SEGMENT
??_C@_07KICHBFMM@memory?5@ DB 'memory ', 00H ; `string'
CONST ENDS
; COMDAT ??_C@_0N@IENDNEBE@HTML?5parser?5@
CONST SEGMENT
??_C@_0N@IENDNEBE@HTML?5parser?5@ DB 'HTML parser ', 00H ; `string'
CONST ENDS
; COMDAT ??_C@_09BIOOFDLF@validity?5@
CONST SEGMENT
??_C@_09BIOOFDLF@validity?5@ DB 'validity ', 00H ; `string'
CONST ENDS
; COMDAT ??_C@_0L@BNCDLIEB@namespace?5@
CONST SEGMENT
??_C@_0L@BNCDLIEB@namespace?5@ DB 'namespace ', 00H ; `string'
CONST ENDS
; COMDAT ??_C@_07CNNNFPCP@parser?5@
CONST SEGMENT
??_C@_07CNNNFPCP@parser?5@ DB 'parser ', 00H ; `string'
CONST ENDS
; COMDAT ??_C@_0N@MLFICIIN@element?5?$CFs?3?5@
CONST SEGMENT
??_C@_0N@MLFICIIN@element?5?$CFs?3?5@ DB 'element %s: ', 00H ; `string'
CONST ENDS
; COMDAT ??_C@_03OFAPEBGM@?$CFs?6@
CONST SEGMENT
??_C@_03OFAPEBGM@?$CFs?6@ DB '%s', 0aH, 00H ; `string'
CONST ENDS
; COMDAT ??_C@_0BC@FMCMLLAH@Entity?3?5line?5?$CFd?3?5@
CONST SEGMENT
??_C@_0BC@FMCMLLAH@Entity?3?5line?5?$CFd?3?5@ DB 'Entity: line %d: ', 00H ; `string'
CONST ENDS
; COMDAT ??_C@_07FCDHCGBN@?$CFs?3?$CFd?3?5@
CONST SEGMENT
??_C@_07FCDHCGBN@?$CFs?3?$CFd?3?5@ DB '%s:%d: ', 00H ; `string'
CONST ENDS
; Function compile flags: /Odt
; COMDAT __JustMyCode_Default
_TEXT SEGMENT
__JustMyCode_Default PROC ; COMDAT
push ebp
mov ebp, esp
pop ebp
ret 0
__JustMyCode_Default ENDP
_TEXT ENDS
; Function compile flags: /Ogtp
; File c:\users\dag\documents\_clients\codeproject authors group\windows on arm\libxml2\libxml2-2.9.9\error.c
; COMDAT _xmlReportError
_TEXT SEGMENT
_buf$1 = -172 ; size = 150
_level$1$ = -20 ; size = 4
_cur$1$ = -16 ; size = 4
_input$1$ = -12 ; size = 4
_domain$1$ = -8 ; size = 4
_line$1$ = -4 ; size = 4
_err$ = 8 ; size = 4
_ctxt$ = 12 ; size = 4
_str$ = 16 ; size = 4
_channel$ = 20 ; size = 4
_data$ = 24 ; size = 4
_xmlReportError PROC ; COMDAT
; 247 : {
push ebp
mov ebp, esp
sub esp, 172 ; 000000acH
push edi
mov ecx, OFFSET __67926DEE_error@c
call @__CheckForDebuggerJustMyCode@4
mov edi, DWORD PTR _err$[ebp]
xor edx, edx
mov DWORD PTR _input$1$[ebp], 0
mov DWORD PTR _cur$1$[ebp], edx
test edi, edi
je $LN62@xmlReportE
; 248 : char *file = NULL;
; 249 : int line = 0;
; 250 : int code = -1;
; 251 : int domain;
; 252 : const xmlChar *name = NULL;
; 253 : xmlNodePtr node;
; 254 : xmlErrorLevel level;
; 255 : xmlParserInputPtr input = NULL;
; 256 : xmlParserInputPtr cur = NULL;
; 257 :
; 258 : if (err == NULL)
; 259 : return;
; 260 :
; 261 : if (channel == NULL) {
push ebx
push esi
mov esi, DWORD PTR _channel$[ebp]
test esi, esi
jne SHORT $LN68@xmlReportE
; 262 : channel = xmlGenericError;
call ___xmlGenericError
mov esi, DWORD PTR [eax]
; 263 : data = xmlGenericErrorContext;
call ___xmlGenericErrorContext
mov ebx, DWORD PTR [eax]
jmp SHORT $LN10@xmlReportE
$LN68@xmlReportE:
; 248 : char *file = NULL;
; 249 : int line = 0;
; 250 : int code = -1;
; 251 : int domain;
; 252 : const xmlChar *name = NULL;
; 253 : xmlNodePtr node;
; 254 : xmlErrorLevel level;
; 255 : xmlParserInputPtr input = NULL;
; 256 : xmlParserInputPtr cur = NULL;
; 257 :
; 258 : if (err == NULL)
; 259 : return;
; 260 :
; 261 : if (channel == NULL) {
mov ebx, DWORD PTR _data$[ebp]
$LN10@xmlReportE:
; 264 : }
; 265 : file = err->file;
; 266 : line = err->line;
; 267 : code = err->code;
; 268 : domain = err->domain;
; 269 : level = err->level;
; 270 : node = err->node;
; 271 :
; 272 : if (code == XML_ERR_OK)
cmp DWORD PTR [edi+4], 0
mov eax, DWORD PTR [edi+20]
mov ecx, DWORD PTR [edi+12]
mov edx, DWORD PTR [edi+16]
mov DWORD PTR _line$1$[ebp], eax
mov eax, DWORD PTR [edi]
mov DWORD PTR _domain$1$[ebp], eax
mov DWORD PTR _level$1$[ebp], ecx
je $LN71@xmlReportE
; 273 : return;
; 274 :
; 275 : if ((node != NULL) && (node->type == XML_ELEMENT_NODE))
mov ecx, DWORD PTR [edi+48]
test ecx, ecx
je SHORT $LN70@xmlReportE
cmp DWORD PTR [ecx+4], 1
jne SHORT $LN70@xmlReportE
; 276 : name = node->name;
mov edi, DWORD PTR [ecx+8]
jmp SHORT $LN12@xmlReportE
$LN70@xmlReportE:
; 277 :
; 278 : /*
; 279 : * Maintain the compatibility with the legacy error handling
; 280 : */
; 281 : if (ctxt != NULL) {
xor edi, edi
$LN12@xmlReportE:
mov ecx, DWORD PTR _ctxt$[ebp]
test ecx, ecx
je SHORT $LN13@xmlReportE
; 282 : input = ctxt->input;
mov edx, DWORD PTR [ecx+36]
mov DWORD PTR _input$1$[ebp], edx
; 283 : if ((input != NULL) && (input->filename == NULL) &&
test edx, edx
je $LN22@xmlReportE
cmp DWORD PTR [edx+4], 0
jne SHORT $LN15@xmlReportE
mov ecx, DWORD PTR [ecx+40]
cmp ecx, 1
jle SHORT $LN15@xmlReportE
; 284 : (ctxt->inputNr > 1)) {
; 285 : cur = input;
; 286 : input = ctxt->inputTab[ctxt->inputNr - 2];
mov eax, DWORD PTR _ctxt$[ebp]
mov DWORD PTR _cur$1$[ebp], edx
mov eax, DWORD PTR [eax+48]
mov edx, DWORD PTR [eax+ecx*4-8]
mov eax, DWORD PTR _domain$1$[ebp]
mov DWORD PTR _input$1$[ebp], edx
$LN15@xmlReportE:
; 287 : }
; 288 : if (input != NULL) {
test edx, edx
je SHORT $LN22@xmlReportE
; 289 : if (input->filename)
mov ecx, DWORD PTR [edx+4]
test ecx, ecx
je SHORT $LN17@xmlReportE
; 290 : channel(data, "%s:%d: ", input->filename, input->line);
push DWORD PTR [edx+28]
push ecx
push OFFSET ??_C@_07FCDHCGBN@?$CFs?3?$CFd?3?5@
push ebx
call esi
add esp, 16 ; 00000010H
jmp SHORT $LN22@xmlReportE
$LN17@xmlReportE:
; 291 : else if ((line != 0) && (domain == XML_FROM_PARSER))
cmp DWORD PTR _line$1$[ebp], 0
je SHORT $LN22@xmlReportE
cmp eax, 1
jne SHORT $LN22@xmlReportE
; 292 : channel(data, "Entity: line %d: ", input->line);
push DWORD PTR [edx+28]
; 293 : }
; 294 : } else {
jmp SHORT $LN73@xmlReportE
$LN13@xmlReportE:
; 295 : if (file != NULL)
test edx, edx
je SHORT $LN20@xmlReportE
; 296 : channel(data, "%s:%d: ", file, line);
push DWORD PTR _line$1$[ebp]
push edx
push OFFSET ??_C@_07FCDHCGBN@?$CFs?3?$CFd?3?5@
push ebx
call esi
add esp, 16 ; 00000010H
jmp SHORT $LN22@xmlReportE
$LN20@xmlReportE:
; 297 : else if ((line != 0) &&
mov ecx, DWORD PTR _line$1$[ebp]
test ecx, ecx
je SHORT $LN22@xmlReportE
cmp eax, 1
je SHORT $LN23@xmlReportE
cmp eax, 17 ; 00000011H
je SHORT $LN23@xmlReportE
cmp eax, 16 ; 00000010H
je SHORT $LN23@xmlReportE
cmp eax, 4
je SHORT $LN23@xmlReportE
cmp eax, 18 ; 00000012H
je SHORT $LN23@xmlReportE
cmp eax, 19 ; 00000013H
jne SHORT $LN22@xmlReportE
$LN23@xmlReportE:
; 298 : ((domain == XML_FROM_PARSER) || (domain == XML_FROM_SCHEMASV)||
; 299 : (domain == XML_FROM_SCHEMASP)||(domain == XML_FROM_DTD) ||
; 300 : (domain == XML_FROM_RELAXNGP)||(domain == XML_FROM_RELAXNGV)))
; 301 : channel(data, "Entity: line %d: ", line);
push ecx
$LN73@xmlReportE:
; 302 : }
; 303 : if (name != NULL) {
push OFFSET ??_C@_0BC@FMCMLLAH@Entity?3?5line?5?$CFd?3?5@
push ebx
call esi
add esp, 12 ; 0000000cH
$LN22@xmlReportE:
test edi, edi
je SHORT $LN24@xmlReportE
; 304 : channel(data, "element %s: ", name);
push edi
push OFFSET ??_C@_0N@MLFICIIN@element?5?$CFs?3?5@
push ebx
call esi
add esp, 12 ; 0000000cH
$LN24@xmlReportE:
; 305 : }
; 306 : switch (domain) {
mov eax, DWORD PTR _domain$1$[ebp]
dec eax
cmp eax, 29 ; 0000001dH
ja $LN48@xmlReportE
jmp DWORD PTR $LN79@xmlReportE[eax*4]
$LN26@xmlReportE:
; 307 : case XML_FROM_PARSER:
; 308 : channel(data, "parser ");
; 309 : break;
; 310 : case XML_FROM_NAMESPACE:
; 311 : channel(data, "namespace ");
push OFFSET ??_C@_0L@BNCDLIEB@namespace?5@
; 312 : break;
jmp $LN74@xmlReportE
$LN27@xmlReportE:
; 313 : case XML_FROM_DTD:
; 314 : case XML_FROM_VALID:
; 315 : channel(data, "validity ");
push OFFSET ??_C@_09BIOOFDLF@validity?5@
; 316 : break;
jmp $LN74@xmlReportE
$LN28@xmlReportE:
; 317 : case XML_FROM_HTML:
; 318 : channel(data, "HTML parser ");
push OFFSET ??_C@_0N@IENDNEBE@HTML?5parser?5@
; 319 : break;
jmp $LN74@xmlReportE
$LN29@xmlReportE:
; 320 : case XML_FROM_MEMORY:
; 321 : channel(data, "memory ");
push OFFSET ??_C@_07KICHBFMM@memory?5@
; 322 : break;
jmp SHORT $LN74@xmlReportE
$LN30@xmlReportE:
; 323 : case XML_FROM_OUTPUT:
; 324 : channel(data, "output ");
push OFFSET ??_C@_07NOLKHGJF@output?5@
; 325 : break;
jmp SHORT $LN74@xmlReportE
$LN31@xmlReportE:
; 326 : case XML_FROM_IO:
; 327 : channel(data, "I/O ");
push OFFSET ??_C@_04HKCNGDON@I?1O?5@
; 328 : break;
jmp SHORT $LN74@xmlReportE
$LN32@xmlReportE:
; 329 : case XML_FROM_XINCLUDE:
; 330 : channel(data, "XInclude ");
push OFFSET ??_C@_09JKGAONDL@XInclude?5@
; 331 : break;
jmp SHORT $LN74@xmlReportE
$LN33@xmlReportE:
; 332 : case XML_FROM_XPATH:
; 333 : channel(data, "XPath ");
push OFFSET ??_C@_06ONGIFIKK@XPath?5@
; 334 : break;
jmp SHORT $LN74@xmlReportE
$LN34@xmlReportE:
; 335 : case XML_FROM_XPOINTER:
; 336 : channel(data, "parser ");
push OFFSET ??_C@_07CNNNFPCP@parser?5@
; 337 : break;
jmp SHORT $LN74@xmlReportE
$LN35@xmlReportE:
; 338 : case XML_FROM_REGEXP:
; 339 : channel(data, "regexp ");
push OFFSET ??_C@_07IGPLNGGH@regexp?5@
; 340 : break;
jmp SHORT $LN74@xmlReportE
$LN36@xmlReportE:
; 341 : case XML_FROM_MODULE:
; 342 : channel(data, "module ");
push OFFSET ??_C@_07KEPCOONB@module?5@
; 343 : break;
jmp SHORT $LN74@xmlReportE
$LN37@xmlReportE:
; 344 : case XML_FROM_SCHEMASV:
; 345 : channel(data, "Schemas validity ");
push OFFSET ??_C@_0BC@MEEJMAME@Schemas?5validity?5@
; 346 : break;
jmp SHORT $LN74@xmlReportE
$LN38@xmlReportE:
; 347 : case XML_FROM_SCHEMASP:
; 348 : channel(data, "Schemas parser ");
push OFFSET ??_C@_0BA@COGPIGL@Schemas?5parser?5@
; 349 : break;
jmp SHORT $LN74@xmlReportE
$LN39@xmlReportE:
; 350 : case XML_FROM_RELAXNGP:
; 351 : channel(data, "Relax-NG parser ");
push OFFSET ??_C@_0BB@FGPKBGBA@Relax?9NG?5parser?5@
; 352 : break;
jmp SHORT $LN74@xmlReportE
$LN40@xmlReportE:
; 353 : case XML_FROM_RELAXNGV:
; 354 : channel(data, "Relax-NG validity ");
push OFFSET ??_C@_0BD@EPDAPLJK@Relax?9NG?5validity?5@
; 355 : break;
jmp SHORT $LN74@xmlReportE
$LN41@xmlReportE:
; 356 : case XML_FROM_CATALOG:
; 357 : channel(data, "Catalog ");
push OFFSET ??_C@_08NOLMNIGP@Catalog?5@
; 358 : break;
jmp SHORT $LN74@xmlReportE
$LN42@xmlReportE:
; 359 : case XML_FROM_C14N:
; 360 : channel(data, "C14N ");
push OFFSET ??_C@_05MLHJFMDG@C14N?5@
; 361 : break;
jmp SHORT $LN74@xmlReportE
$LN43@xmlReportE:
; 362 : case XML_FROM_XSLT:
; 363 : channel(data, "XSLT ");
push OFFSET ??_C@_05POKACEJG@XSLT?5@
; 364 : break;
jmp SHORT $LN74@xmlReportE
$LN44@xmlReportE:
; 365 : case XML_FROM_I18N:
; 366 : channel(data, "encoding ");
push OFFSET ??_C@_09JICCLIJI@encoding?5@
; 367 : break;
jmp SHORT $LN74@xmlReportE
$LN45@xmlReportE:
; 368 : case XML_FROM_SCHEMATRONV:
; 369 : channel(data, "schematron ");
push OFFSET ??_C@_0M@LAKDBFM@schematron?5@
; 370 : break;
jmp SHORT $LN74@xmlReportE
$LN46@xmlReportE:
; 371 : case XML_FROM_BUFFER:
; 372 : channel(data, "internal buffer ");
push OFFSET ??_C@_0BB@FACNAIAH@internal?5buffer?5@
; 373 : break;
jmp SHORT $LN74@xmlReportE
$LN47@xmlReportE:
; 374 : case XML_FROM_URI:
; 375 : channel(data, "URI ");
push OFFSET ??_C@_04ECOFBNJN@URI?5@
$LN74@xmlReportE:
; 376 : break;
; 377 : default:
; 378 : break;
; 379 : }
; 380 : switch (level) {
push ebx
call esi
add esp, 8
$LN48@xmlReportE:
mov eax, DWORD PTR _level$1$[ebp]
cmp eax, 3
ja SHORT $LN4@xmlReportE
jmp DWORD PTR $LN80@xmlReportE[eax*4]
$LN49@xmlReportE:
; 381 : case XML_ERR_NONE:
; 382 : channel(data, ": ");
push OFFSET ??_C@_02LMMGGCAJ@?3?5@
; 383 : break;
jmp SHORT $LN75@xmlReportE
$LN50@xmlReportE:
; 384 : case XML_ERR_WARNING:
; 385 : channel(data, "warning : ");
push OFFSET ??_C@_0L@HNPIBIGM@warning?5?3?5@
; 386 : break;
jmp SHORT $LN75@xmlReportE
$LN52@xmlReportE:
; 387 : case XML_ERR_ERROR:
; 388 : channel(data, "error : ");
; 389 : break;
; 390 : case XML_ERR_FATAL:
; 391 : channel(data, "error : ");
push OFFSET ??_C@_08PMHKJNKP@error?5?3?5@
$LN75@xmlReportE:
; 392 : break;
; 393 : }
; 394 : if (str != NULL) {
push ebx
call esi
add esp, 8
$LN4@xmlReportE:
mov edi, DWORD PTR _str$[ebp]
test edi, edi
je SHORT $LN53@xmlReportE
; 395 : int len;
; 396 : len = xmlStrlen((const xmlChar *)str);
push edi
call _xmlStrlen
add esp, 4
; 397 : if ((len > 0) && (str[len - 1] != '\n'))
test eax, eax
jle SHORT $LN55@xmlReportE
cmp BYTE PTR [eax+edi-1], 10 ; 0000000aH
je SHORT $LN55@xmlReportE
; 398 : channel(data, "%s\n", str);
push edi
jmp SHORT $LN76@xmlReportE
$LN55@xmlReportE:
; 399 : else
; 400 : channel(data, "%s", str);
push edi
push OFFSET ??_C@_02DKCKIIND@?$CFs@
; 401 : } else {
jmp SHORT $LN77@xmlReportE
$LN53@xmlReportE:
; 402 : channel(data, "%s\n", "out of memory error");
push OFFSET ??_C@_0BE@LHHHBFLE@out?5of?5memory?5error@
$LN76@xmlReportE:
; 403 : }
; 404 :
; 405 : if (ctxt != NULL) {
push OFFSET ??_C@_03OFAPEBGM@?$CFs?6@
$LN77@xmlReportE:
push ebx
call esi
add esp, 12 ; 0000000cH
cmp DWORD PTR _ctxt$[ebp], 0
je SHORT $LN58@xmlReportE
; 406 : xmlParserPrintFileContextInternal(input, channel, data);
push ebx
push esi
push DWORD PTR _input$1$[ebp]
call _xmlParserPrintFileContextInternal
; 407 : if (cur != NULL) {
mov edi, DWORD PTR _cur$1$[ebp]
add esp, 12 ; 0000000cH
test edi, edi
je SHORT $LN58@xmlReportE
; 408 : if (cur->filename)
mov eax, DWORD PTR [edi+4]
test eax, eax
je SHORT $LN59@xmlReportE
; 409 : channel(data, "%s:%d: \n", cur->filename, cur->line);
push DWORD PTR [edi+28]
push eax
push OFFSET ??_C@_08JJLLLDHF@?$CFs?3?$CFd?3?5?6@
push ebx
call esi
add esp, 16 ; 00000010H
jmp SHORT $LN61@xmlReportE
$LN59@xmlReportE:
; 410 : else if ((line != 0) && (domain == XML_FROM_PARSER))
cmp DWORD PTR _line$1$[ebp], 0
je SHORT $LN61@xmlReportE
cmp DWORD PTR _domain$1$[ebp], 1
jne SHORT $LN61@xmlReportE
; 411 : channel(data, "Entity: line %d: \n", cur->line);
push DWORD PTR [edi+28]
push OFFSET ??_C@_0BD@GENHFBJC@Entity?3?5line?5?$CFd?3?5?6@
push ebx
call esi
add esp, 12 ; 0000000cH
$LN61@xmlReportE:
; 412 : xmlParserPrintFileContextInternal(cur, channel, data);
push ebx
push esi
push edi
call _xmlParserPrintFileContextInternal
add esp, 12 ; 0000000cH
$LN58@xmlReportE:
; 413 : }
; 414 : }
; 415 : if ((domain == XML_FROM_XPATH) && (err->str1 != NULL) &&
; 416 : (err->int1 < 100) &&
cmp DWORD PTR _domain$1$[ebp], 12 ; 0000000cH
jne SHORT $LN71@xmlReportE
mov edi, DWORD PTR _err$[ebp]
mov eax, DWORD PTR [edi+24]
test eax, eax
je SHORT $LN71@xmlReportE
cmp DWORD PTR [edi+36], 100 ; 00000064H
jge SHORT $LN71@xmlReportE
push eax
call _xmlStrlen
add esp, 4
cmp DWORD PTR [edi+36], eax
jge SHORT $LN71@xmlReportE
; 417 : (err->int1 < xmlStrlen((const xmlChar *)err->str1))) {
; 418 : xmlChar buf[150];
; 419 : int i;
; 420 :
; 421 : channel(data, "%s\n", err->str1);
push DWORD PTR [edi+24]
push OFFSET ??_C@_03OFAPEBGM@?$CFs?6@
push ebx
call esi
; 422 : for (i=0;i < err->int1;i++)
mov ecx, DWORD PTR [edi+36]
add esp, 12 ; 0000000cH
xor eax, eax
test ecx, ecx
jle SHORT $LN7@xmlReportE
; 417 : (err->int1 < xmlStrlen((const xmlChar *)err->str1))) {
; 418 : xmlChar buf[150];
; 419 : int i;
; 420 :
; 421 : channel(data, "%s\n", err->str1);
mov edx, ecx
lea edi, DWORD PTR _buf$1[ebp]
shr ecx, 2
mov eax, 538976288 ; 20202020H
rep stosd
mov ecx, edx
and ecx, 3
rep stosb
mov eax, edx
$LN7@xmlReportE:
; 423 : buf[i] = ' ';
; 424 : buf[i++] = '^';
mov WORD PTR _buf$1[ebp+eax], 94 ; 0000005eH
; 425 : buf[i] = 0;
; 426 : channel(data, "%s\n", buf);
lea eax, DWORD PTR _buf$1[ebp]
push eax
push OFFSET ??_C@_03OFAPEBGM@?$CFs?6@
push ebx
call esi
add esp, 12 ; 0000000cH
$LN71@xmlReportE:
pop esi
pop ebx
$LN62@xmlReportE:
pop edi
; 427 : }
; 428 : }
mov esp, ebp
pop ebp
ret 0
npad 2
$LN79@xmlReportE:
DD $LN34@xmlReportE
DD $LN48@xmlReportE
DD $LN26@xmlReportE
DD $LN27@xmlReportE
DD $LN28@xmlReportE
DD $LN29@xmlReportE
DD $LN30@xmlReportE
DD $LN31@xmlReportE
DD $LN48@xmlReportE
DD $LN48@xmlReportE
DD $LN32@xmlReportE
DD $LN33@xmlReportE
DD $LN34@xmlReportE
DD $LN35@xmlReportE
DD $LN48@xmlReportE
DD $LN38@xmlReportE
DD $LN37@xmlReportE
DD $LN39@xmlReportE
DD $LN40@xmlReportE
DD $LN41@xmlReportE
DD $LN42@xmlReportE
DD $LN43@xmlReportE
DD $LN27@xmlReportE
DD $LN48@xmlReportE
DD $LN48@xmlReportE
DD $LN36@xmlReportE
DD $LN44@xmlReportE
DD $LN45@xmlReportE
DD $LN46@xmlReportE
DD $LN47@xmlReportE
$LN80@xmlReportE:
DD $LN49@xmlReportE
DD $LN50@xmlReportE
DD $LN52@xmlReportE
DD $LN52@xmlReportE
_xmlReportError ENDP
_TEXT ENDS
; Function compile flags: /Ogtp
; File c:\users\dag\documents\_clients\codeproject authors group\windows on arm\libxml2\libxml2-2.9.9\error.c
; COMDAT _xmlParserPrintFileContextInternal
_TEXT SEGMENT
_content$ = -84 ; size = 81
_input$ = 8 ; size = 4
_channel$ = 12 ; size = 4
_data$ = 16 ; size = 4
_xmlParserPrintFileContextInternal PROC ; COMDAT
; 174 : xmlGenericErrorFunc channel, void *data ) {
push ebp
mov ebp, esp
sub esp, 84 ; 00000054H
mov ecx, OFFSET __67926DEE_error@c
push esi
call @__CheckForDebuggerJustMyCode@4
mov esi, DWORD PTR _input$[ebp]
test esi, esi
je $LN11@xmlParserP
; 175 : const xmlChar *cur, *base;
; 176 : unsigned int n, col; /* GCC warns if signed, because compared with sizeof() */
; 177 : xmlChar content[81]; /* space for 80 chars + line terminator */
; 178 : xmlChar *ctnt;
; 179 :
; 180 : if ((input == NULL) || (input->cur == NULL))
push edi
mov edi, DWORD PTR [esi+16]
test edi, edi
je $LN39@xmlParserP
; 181 : return;
; 182 :
; 183 : cur = input->cur;
; 184 : base = input->base;
mov esi, DWORD PTR [esi+12]
mov eax, edi
; 185 : /* skip backwards over any end-of-lines */
; 186 : while ((cur > base) && ((*(cur) == '\n') || (*(cur) == '\r'))) {
cmp eax, esi
jbe SHORT $LN36@xmlParserP
$LL2@xmlParserP:
mov cl, BYTE PTR [eax]
cmp cl, 10 ; 0000000aH
je SHORT $LN30@xmlParserP
cmp cl, 13 ; 0000000dH
jne SHORT $LN36@xmlParserP
$LN30@xmlParserP:
; 187 : cur--;
dec eax
cmp eax, esi
ja SHORT $LL2@xmlParserP
$LN36@xmlParserP:
; 188 : }
; 189 : n = 0;
xor ecx, ecx
$LL4@xmlParserP:
; 190 : /* search backwards for beginning-of-line (to max buff size) */
; 191 : while ((n++ < (sizeof(content)-1)) && (cur > base) &&
; 192 : (*(cur) != '\n') && (*(cur) != '\r'))
inc ecx
cmp eax, esi
jbe SHORT $LN22@xmlParserP
mov dl, BYTE PTR [eax]
cmp dl, 10 ; 0000000aH
je SHORT $LN14@xmlParserP
cmp dl, 13 ; 0000000dH
je SHORT $LN22@xmlParserP
; 193 : cur--;
dec eax
cmp ecx, 80 ; 00000050H
jb SHORT $LL4@xmlParserP
$LN22@xmlParserP:
; 194 : if ((*(cur) == '\n') || (*(cur) == '\r')) cur++;
mov cl, BYTE PTR [eax]
cmp cl, 10 ; 0000000aH
je SHORT $LN14@xmlParserP
cmp cl, 13 ; 0000000dH
jne SHORT $LN13@xmlParserP
$LN14@xmlParserP:
mov cl, BYTE PTR [eax+1]
inc eax
$LN13@xmlParserP:
; 195 : /* calculate the error position in terms of the current position */
; 196 : col = input->cur - cur;
sub edi, eax
; 197 : /* search forward for end-of-line (to max buff size) */
; 198 : n = 0;
; 199 : ctnt = content;
lea edx, DWORD PTR _content$[ebp]
xor esi, esi
push ebx
; 200 : /* copy selected text to our buffer */
; 201 : while ((*cur != 0) && (*(cur) != '\n') &&
; 202 : (*(cur) != '\r') && (n < sizeof(content)-1)) {
test cl, cl
je SHORT $LN37@xmlParserP
; 185 : /* skip backwards over any end-of-lines */
; 186 : while ((cur > base) && ((*(cur) == '\n') || (*(cur) == '\r'))) {
mov ebx, edx
sub eax, ebx
npad 5
$LL6@xmlParserP:
; 200 : /* copy selected text to our buffer */
; 201 : while ((*cur != 0) && (*(cur) != '\n') &&
; 202 : (*(cur) != '\r') && (n < sizeof(content)-1)) {
cmp cl, 10 ; 0000000aH
je SHORT $LN37@xmlParserP
cmp cl, 13 ; 0000000dH
je SHORT $LN37@xmlParserP
cmp esi, 80 ; 00000050H
jae SHORT $LN37@xmlParserP
; 203 : *ctnt++ = *cur++;
movzx ecx, BYTE PTR [eax+edx]
; 204 : n++;
inc esi
mov BYTE PTR [edx], cl
inc edx
mov cl, BYTE PTR [eax+edx]
test cl, cl
jne SHORT $LL6@xmlParserP
$LN37@xmlParserP:
; 205 : }
; 206 : *ctnt = 0;
; 207 : /* print out the selected text */
; 208 : channel(data ,"%s\n", content);
mov esi, DWORD PTR _data$[ebp]
lea eax, DWORD PTR _content$[ebp]
mov ebx, DWORD PTR _channel$[ebp]
push eax
push OFFSET ??_C@_03OFAPEBGM@?$CFs?6@
push esi
mov BYTE PTR [edx], 0
call ebx
add esp, 12 ; 0000000cH
; 209 : /* create blank line with problem pointer */
; 210 : n = 0;
; 211 : ctnt = content;
lea ecx, DWORD PTR _content$[ebp]
xor edx, edx
; 212 : /* (leave buffer space for pointer + line terminator) */
; 213 : while ((n<col) && (n++ < sizeof(content)-2) && (*ctnt != 0)) {
test edi, edi
je SHORT $LN38@xmlParserP
npad 1
$LL8@xmlParserP:
mov eax, edx
inc edx
cmp eax, 79 ; 0000004fH
jae SHORT $LN38@xmlParserP
mov al, BYTE PTR [ecx]
test al, al
je SHORT $LN38@xmlParserP
; 214 : if (*(ctnt) != '\t')
cmp al, 9
je SHORT $LN35@xmlParserP
; 215 : *(ctnt) = ' ';
mov BYTE PTR [ecx], 32 ; 00000020H
$LN35@xmlParserP:
; 216 : ctnt++;
inc ecx
cmp edx, edi
jb SHORT $LL8@xmlParserP
$LN38@xmlParserP:
; 217 : }
; 218 : *ctnt++ = '^';
; 219 : *ctnt = 0;
; 220 : channel(data ,"%s\n", content);
lea eax, DWORD PTR _content$[ebp]
mov WORD PTR [ecx], 94 ; 0000005eH
push eax
push OFFSET ??_C@_03OFAPEBGM@?$CFs?6@
push esi
call ebx
add esp, 12 ; 0000000cH
pop ebx
$LN39@xmlParserP:
pop edi
$LN11@xmlParserP:
pop esi
; 221 : }
mov esp, ebp
pop ebp
ret 0
_xmlParserPrintFileContextInternal ENDP
_TEXT ENDS
; Function compile flags: /Ogtp
; File c:\users\dag\documents\_clients\codeproject authors group\windows on arm\libxml2\libxml2-2.9.9\error.c
; File c:\program files (x86)\windows kits\10\include\10.0.17763.0\ucrt\stdio.h
; File c:\users\dag\documents\_clients\codeproject authors group\windows on arm\libxml2\libxml2-2.9.9\error.c
; COMDAT _xmlGenericErrorDefaultFunc
_TEXT SEGMENT
_ctx$ = 8 ; size = 4
_msg$ = 12 ; size = 4
_xmlGenericErrorDefaultFunc PROC ; COMDAT
; 71 : xmlGenericErrorDefaultFunc(void *ctx ATTRIBUTE_UNUSED, const char *msg, ...) {
push ebp
mov ebp, esp
push esi
push edi
mov ecx, OFFSET __67926DEE_error@c
call @__CheckForDebuggerJustMyCode@4
call ___xmlGenericErrorContext
cmp DWORD PTR [eax], 0
jne SHORT $LN2@xmlGeneric
; 72 : va_list args;
; 73 :
; 74 : if (xmlGenericErrorContext == NULL)
; 75 : xmlGenericErrorContext = (void *) stderr;
call ___xmlGenericErrorContext
push 2
mov esi, eax
call DWORD PTR __imp____acrt_iob_func
add esp, 4
mov DWORD PTR [esi], eax
$LN2@xmlGeneric:
; 76 :
; 77 : va_start(args, msg);
; 78 : vfprintf((FILE *)xmlGenericErrorContext, msg, args);
mov edi, DWORD PTR _msg$[ebp]
call ___xmlGenericErrorContext
mov esi, DWORD PTR [eax]
; File c:\program files (x86)\windows kits\10\include\10.0.17763.0\ucrt\stdio.h
; 643 : return __stdio_common_vfprintf(_CRT_INTERNAL_LOCAL_PRINTF_OPTIONS, _Stream, _Format, _Locale, _ArgList);
call ___local_stdio_printf_options
lea ecx, DWORD PTR _msg$[ebp+4]
push ecx
push 0
push edi
push esi
push DWORD PTR [eax+4]
push DWORD PTR [eax]
call DWORD PTR __imp____stdio_common_vfprintf
add esp, 24 ; 00000018H
pop edi
pop esi
; File c:\users\dag\documents\_clients\codeproject authors group\windows on arm\libxml2\libxml2-2.9.9\error.c
; 80 : }
pop ebp
ret 0
_xmlGenericErrorDefaultFunc ENDP
_TEXT ENDS
; Function compile flags: /Ogtp
; File c:\users\dag\documents\_clients\codeproject authors group\windows on arm\libxml2\libxml2-2.9.9\error.c
; COMDAT ___xmlSimpleError
_TEXT SEGMENT
_domain$ = 8 ; size = 4
_code$ = 12 ; size = 4
_node$ = 16 ; size = 4
_msg$ = 20 ; size = 4
_extra$ = 24 ; size = 4
___xmlSimpleError PROC ; COMDAT
; 653 : {
push ebp
mov ebp, esp
mov ecx, OFFSET __67926DEE_error@c
call @__CheckForDebuggerJustMyCode@4
mov ecx, DWORD PTR _code$[ebp]
mov eax, DWORD PTR _extra$[ebp]
cmp ecx, 2
jne SHORT $LN2@xmlSimpleE
; 654 :
; 655 : if (code == XML_ERR_NO_MEMORY) {
; 656 : if (extra)
test eax, eax
je SHORT $LN4@xmlSimpleE
; 657 : __xmlRaiseError(NULL, NULL, NULL, NULL, node, domain,
push eax
push OFFSET ??_C@_0BP@DJFHNAOK@Memory?5allocation?5failed?5?3?5?$CFs?6@
push 0
push 0
push 0
push 0
push eax
push 0
push 0
push 3
push ecx
jmp SHORT $LN7@xmlSimpleE
$LN4@xmlSimpleE:
; 658 : XML_ERR_NO_MEMORY, XML_ERR_FATAL, NULL, 0, extra,
; 659 : NULL, NULL, 0, 0,
; 660 : "Memory allocation failed : %s\n", extra);
; 661 : else
; 662 : __xmlRaiseError(NULL, NULL, NULL, NULL, node, domain,
push OFFSET ??_C@_0BK@GDFDKGPJ@Memory?5allocation?5failed?6@
push 0
push 0
push 0
push 0
push 0
push 0
push 0
push 3
push 2
push DWORD PTR _domain$[ebp]
push DWORD PTR _node$[ebp]
push 0
push 0
push 0
push 0
call ___xmlRaiseError
add esp, 64 ; 00000040H
; 667 : code, XML_ERR_ERROR, NULL, 0, extra,
; 668 : NULL, NULL, 0, 0, msg, extra);
; 669 : }
; 670 : }
pop ebp
ret 0
$LN2@xmlSimpleE:
; 663 : XML_ERR_NO_MEMORY, XML_ERR_FATAL, NULL, 0, NULL,
; 664 : NULL, NULL, 0, 0, "Memory allocation failed\n");
; 665 : } else {
; 666 : __xmlRaiseError(NULL, NULL, NULL, NULL, node, domain,
push eax
push DWORD PTR _msg$[ebp]
push 0
push 0
push 0
push 0
push eax
push 0
push 0
push 2
push ecx
$LN7@xmlSimpleE:
; 667 : code, XML_ERR_ERROR, NULL, 0, extra,
; 668 : NULL, NULL, 0, 0, msg, extra);
; 669 : }
; 670 : }
push DWORD PTR _domain$[ebp]
push DWORD PTR _node$[ebp]
push 0
push 0
push 0
push 0
call ___xmlRaiseError
add esp, 68 ; 00000044H
pop ebp
ret 0
___xmlSimpleError ENDP
_TEXT ENDS
; Function compile flags: /Ogtp
; File c:\users\dag\documents\_clients\codeproject authors group\windows on arm\libxml2\libxml2-2.9.9\error.c
; File c:\program files (x86)\windows kits\10\include\10.0.17763.0\ucrt\stdio.h
; File c:\users\dag\documents\_clients\codeproject authors group\windows on arm\libxml2\libxml2-2.9.9\error.c
; COMDAT ___xmlRaiseError
_TEXT SEGMENT
_to$1$ = -24 ; size = 4
_baseptr$1$ = -20 ; size = 4
_ctxt$1$ = -16 ; size = 4
_schannel$1$ = -12 ; size = 4
_str$1$ = -8 ; size = 4
_data$1$ = -4 ; size = 4
_schannel$ = 8 ; size = 4
_channel$ = 12 ; size = 4
_data$ = 16 ; size = 4
_ctx$ = 20 ; size = 4
_line$1$ = 24 ; size = 4
_nod$ = 24 ; size = 4
_domain$ = 28 ; size = 4
_code$ = 32 ; size = 4
_level$ = 36 ; size = 4
_file$ = 40 ; size = 4
_line$ = 44 ; size = 4
_str1$ = 48 ; size = 4
_str2$ = 52 ; size = 4
_str3$ = 56 ; size = 4
_int1$ = 60 ; size = 4
_col$ = 64 ; size = 4
_msg$ = 68 ; size = 4
___xmlRaiseError PROC ; COMDAT
; 461 : {
push ebp
mov ebp, esp
sub esp, 24 ; 00000018H
push ebx
push edi
mov ecx, OFFSET __67926DEE_error@c
call @__CheckForDebuggerJustMyCode@4
mov ebx, DWORD PTR _nod$[ebp]
xor eax, eax
mov DWORD PTR _ctxt$1$[ebp], eax
call ___xmlLastError
cmp DWORD PTR _code$[ebp], 0
mov edi, eax
mov DWORD PTR _to$1$[ebp], edi
mov DWORD PTR _baseptr$1$[ebp], 0
je $LN67@xmlRaiseEr
; 462 : xmlParserCtxtPtr ctxt = NULL;
; 463 : xmlNodePtr node = (xmlNodePtr) nod;
; 464 : char *str = NULL;
; 465 : xmlParserInputPtr input = NULL;
; 466 : xmlErrorPtr to = &xmlLastError;
; 467 : xmlNodePtr baseptr = NULL;
; 468 :
; 469 : if (code == XML_ERR_OK)
; 470 : return;
; 471 : if ((xmlGetWarningsDefaultValue == 0) && (level == XML_ERR_WARNING))
call ___xmlGetWarningsDefaultValue
cmp DWORD PTR [eax], 0
jne SHORT $LN10@xmlRaiseEr
cmp DWORD PTR _level$[ebp], 1
je $LN67@xmlRaiseEr
$LN10@xmlRaiseEr:
; 472 : return;
; 473 : if ((domain == XML_FROM_PARSER) || (domain == XML_FROM_HTML) ||
; 474 : (domain == XML_FROM_DTD) || (domain == XML_FROM_NAMESPACE) ||
; 475 : (domain == XML_FROM_IO) || (domain == XML_FROM_VALID)) {
mov eax, DWORD PTR _domain$[ebp]
push esi
cmp eax, 1
je SHORT $LN12@xmlRaiseEr
cmp eax, 5
je SHORT $LN12@xmlRaiseEr
cmp eax, 4
je SHORT $LN12@xmlRaiseEr
cmp eax, 3
je SHORT $LN12@xmlRaiseEr
cmp eax, 8
je SHORT $LN12@xmlRaiseEr
cmp eax, 23 ; 00000017H
je SHORT $LN12@xmlRaiseEr
mov ecx, DWORD PTR _schannel$[ebp]
mov esi, DWORD PTR _data$[ebp]
mov DWORD PTR _schannel$1$[ebp], ecx
jmp SHORT $LN102@xmlRaiseEr
$LN12@xmlRaiseEr:
; 476 : ctxt = (xmlParserCtxtPtr) ctx;
; 477 : if ((schannel == NULL) && (ctxt != NULL) && (ctxt->sax != NULL) &&
; 478 : (ctxt->sax->initialized == XML_SAX2_MAGIC) &&
mov ecx, DWORD PTR _schannel$[ebp]
mov edx, DWORD PTR _ctx$[ebp]
mov DWORD PTR _ctxt$1$[ebp], edx
mov DWORD PTR _schannel$1$[ebp], ecx
test ecx, ecx
jne SHORT $LN91@xmlRaiseEr
test edx, edx
je SHORT $LN90@xmlRaiseEr
mov eax, DWORD PTR [edx]
test eax, eax
je SHORT $LN90@xmlRaiseEr
cmp DWORD PTR [eax+108], -554844497 ; deedbeafH
jne SHORT $LN90@xmlRaiseEr
mov ecx, DWORD PTR [eax+124]
mov DWORD PTR _schannel$1$[ebp], ecx
test ecx, ecx
je SHORT $LN90@xmlRaiseEr
; 479 : (ctxt->sax->serror != NULL)) {
; 480 : schannel = ctxt->sax->serror;
; 481 : data = ctxt->userData;
mov esi, DWORD PTR [edx+4]
$LN102@xmlRaiseEr:
; 482 : }
; 483 : }
; 484 : /*
; 485 : * Check if structured error handler set
; 486 : */
; 487 : if (schannel == NULL) {
mov DWORD PTR _data$1$[ebp], esi
test ecx, ecx
jne SHORT $LN15@xmlRaiseEr
; 476 : ctxt = (xmlParserCtxtPtr) ctx;
; 477 : if ((schannel == NULL) && (ctxt != NULL) && (ctxt->sax != NULL) &&
; 478 : (ctxt->sax->initialized == XML_SAX2_MAGIC) &&
jmp SHORT $LN87@xmlRaiseEr
$LN90@xmlRaiseEr:
mov eax, DWORD PTR _data$[ebp]
mov DWORD PTR _data$1$[ebp], eax
$LN87@xmlRaiseEr:
; 488 : schannel = xmlStructuredError;
call ___xmlStructuredError
mov eax, DWORD PTR [eax]
mov DWORD PTR _schannel$1$[ebp], eax
; 489 : /*
; 490 : * if user has defined handler, change data ptr to user's choice
; 491 : */
; 492 : if (schannel != NULL)
test eax, eax
je SHORT $LN15@xmlRaiseEr
; 493 : data = xmlStructuredErrorContext;
call ___xmlStructuredErrorContext
mov eax, DWORD PTR [eax]
jmp SHORT $LN103@xmlRaiseEr
$LN91@xmlRaiseEr:
; 476 : ctxt = (xmlParserCtxtPtr) ctx;
; 477 : if ((schannel == NULL) && (ctxt != NULL) && (ctxt->sax != NULL) &&
; 478 : (ctxt->sax->initialized == XML_SAX2_MAGIC) &&
mov eax, DWORD PTR _data$[ebp]
$LN103@xmlRaiseEr:
; 494 : }
; 495 : /*
; 496 : * Formatting the message
; 497 : */
; 498 : if (msg == NULL) {
mov DWORD PTR _data$1$[ebp], eax
$LN15@xmlRaiseEr:
cmp DWORD PTR _msg$[ebp], 0
jne SHORT $LN16@xmlRaiseEr
; 499 : str = (char *) xmlStrdup(BAD_CAST "No error message provided");
push OFFSET ??_C@_0BK@ONMNHCCC@No?5error?5message?5provided@
call _xmlStrdup
add esp, 4
mov DWORD PTR _str$1$[ebp], eax
; 500 : } else {
jmp $LN75@xmlRaiseEr
$LN16@xmlRaiseEr:
; 501 : XML_GET_VAR_STR(msg, str);
push 150 ; 00000096H
call DWORD PTR _xmlMalloc
mov esi, eax
add esp, 4
mov DWORD PTR _str$1$[ebp], esi
test esi, esi
je SHORT $LN75@xmlRaiseEr
mov edi, 150 ; 00000096H
or ebx, -1
npad 4
$LL2@xmlRaiseEr:
mov esi, DWORD PTR _msg$[ebp]
; File c:\program files (x86)\windows kits\10\include\10.0.17763.0\ucrt\stdio.h
; 1440 : int const _Result = __stdio_common_vsprintf(
call ___local_stdio_printf_options
lea ecx, DWORD PTR _msg$[ebp+4]
push ecx
push 0
mov ecx, DWORD PTR [eax]
push esi
mov esi, DWORD PTR _str$1$[ebp]
or ecx, 2
push edi
push esi
push DWORD PTR [eax+4]
push ecx
call DWORD PTR __imp____stdio_common_vsprintf
add esp, 28 ; 0000001cH
; 1441 : _CRT_INTERNAL_LOCAL_PRINTF_OPTIONS | _CRT_INTERNAL_PRINTF_STANDARD_SNPRINTF_BEHAVIOR,
; 1442 : _Buffer, _BufferCount, _Format, NULL, _ArgList);
; 1443 :
; 1444 : return _Result < 0 ? -1 : _Result;
mov ecx, -1
test eax, eax
cmovs eax, ecx
; File c:\users\dag\documents\_clients\codeproject authors group\windows on arm\libxml2\libxml2-2.9.9\error.c
; 501 : XML_GET_VAR_STR(msg, str);
cmp eax, ecx
jle SHORT $LN22@xmlRaiseEr
cmp eax, edi
jge SHORT $LN21@xmlRaiseEr
cmp ebx, eax
je SHORT $LN97@xmlRaiseEr
mov ebx, eax
$LN21@xmlRaiseEr:
inc edi
add edi, eax
jmp SHORT $LN23@xmlRaiseEr
$LN22@xmlRaiseEr:
add edi, 100 ; 00000064H
$LN23@xmlRaiseEr:
push edi
push esi
call DWORD PTR _xmlRealloc
add esp, 8
test eax, eax
je SHORT $LN97@xmlRaiseEr
mov DWORD PTR _str$1$[ebp], eax
cmp edi, 64000 ; 0000fa00H
jl SHORT $LL2@xmlRaiseEr
$LN97@xmlRaiseEr:
mov ebx, DWORD PTR _nod$[ebp]
mov edi, DWORD PTR _to$1$[ebp]
$LN75@xmlRaiseEr:
; 502 : }
; 503 :
; 504 : /*
; 505 : * specific processing if a parser context is provided
; 506 : */
; 507 : if (ctxt != NULL) {
mov edx, DWORD PTR _ctxt$1$[ebp]
test edx, edx
je SHORT $LN25@xmlRaiseEr
; 508 : if (file == NULL) {
cmp DWORD PTR _file$[ebp], 0
jne SHORT $LN92@xmlRaiseEr
; 509 : input = ctxt->input;
mov eax, DWORD PTR [edx+36]
; 510 : if ((input != NULL) && (input->filename == NULL) &&
test eax, eax
je SHORT $LN92@xmlRaiseEr
cmp DWORD PTR [eax+4], 0
jne SHORT $LN28@xmlRaiseEr
mov ecx, DWORD PTR [edx+40]
cmp ecx, 1
jle SHORT $LN28@xmlRaiseEr
; 511 : (ctxt->inputNr > 1)) {
; 512 : input = ctxt->inputTab[ctxt->inputNr - 2];
mov eax, DWORD PTR [edx+48]
mov eax, DWORD PTR [eax+ecx*4-8]
$LN28@xmlRaiseEr:
; 513 : }
; 514 : if (input != NULL) {
test eax, eax
je SHORT $LN92@xmlRaiseEr
; 515 : file = input->filename;
; 516 : line = input->line;
mov ecx, DWORD PTR [eax+28]
; 517 : col = input->col;
; 518 : }
; 519 : }
; 520 : to = &ctxt->lastError;
lea edi, DWORD PTR [edx+384]
mov esi, DWORD PTR [eax+4]
mov eax, DWORD PTR [eax+32]
mov DWORD PTR _line$1$[ebp], ecx
mov DWORD PTR _col$[ebp], eax
jmp $LN34@xmlRaiseEr
$LN92@xmlRaiseEr:
; 513 : }
; 514 : if (input != NULL) {
mov eax, DWORD PTR _line$[ebp]
; 517 : col = input->col;
; 518 : }
; 519 : }
; 520 : to = &ctxt->lastError;
lea edi, DWORD PTR [edx+384]
mov esi, DWORD PTR _file$[ebp]
mov DWORD PTR _line$1$[ebp], eax
jmp $LN34@xmlRaiseEr
$LN25@xmlRaiseEr:
; 521 : } else if ((node != NULL) && (file == NULL)) {
test ebx, ebx
je SHORT $LN95@xmlRaiseEr
cmp DWORD PTR _file$[ebp], 0
jne SHORT $LN96@xmlRaiseEr
; 522 : int i;
; 523 :
; 524 : if ((node->doc != NULL) && (node->doc->URL != NULL)) {
mov eax, DWORD PTR [ebx+32]
xor ecx, ecx
test eax, eax
je SHORT $LN31@xmlRaiseEr
cmp DWORD PTR [eax+72], ecx
cmovne ecx, ebx
mov DWORD PTR _baseptr$1$[ebp], ecx
$LN31@xmlRaiseEr:
; 525 : baseptr = node;
; 526 : /* file = (const char *) node->doc->URL; */
; 527 : }
; 528 : for (i = 0;
xor eax, eax
npad 1
$LL6@xmlRaiseEr:
; 529 : ((i < 10) && (node != NULL) && (node->type != XML_ELEMENT_NODE));
test ebx, ebx
je SHORT $LN5@xmlRaiseEr
cmp DWORD PTR [ebx+4], 1
je SHORT $LN5@xmlRaiseEr
; 530 : i++)
; 531 : node = node->parent;
mov ebx, DWORD PTR [ebx+20]
inc eax
cmp eax, 10 ; 0000000aH
jl SHORT $LL6@xmlRaiseEr
$LN5@xmlRaiseEr:
; 532 : if ((baseptr == NULL) && (node != NULL) &&
; 533 : (node->doc != NULL) && (node->doc->URL != NULL))
test ecx, ecx
jne SHORT $LN32@xmlRaiseEr
test ebx, ebx
je SHORT $LN93@xmlRaiseEr
mov eax, DWORD PTR [ebx+32]
test eax, eax
je SHORT $LN32@xmlRaiseEr
cmp DWORD PTR [eax+72], ecx
cmovne ecx, ebx
mov DWORD PTR _baseptr$1$[ebp], ecx
$LN32@xmlRaiseEr:
; 534 : baseptr = node;
; 535 :
; 536 : if ((node != NULL) && (node->type == XML_ELEMENT_NODE))
test ebx, ebx
je SHORT $LN93@xmlRaiseEr
cmp DWORD PTR [ebx+4], 1
jne SHORT $LN93@xmlRaiseEr
; 537 : line = node->line;
movzx esi, WORD PTR [ebx+56]
jmp SHORT $LN104@xmlRaiseEr
$LN93@xmlRaiseEr:
; 534 : baseptr = node;
; 535 :
; 536 : if ((node != NULL) && (node->type == XML_ELEMENT_NODE))
mov esi, DWORD PTR _line$[ebp]
$LN104@xmlRaiseEr:
; 538 : if ((line == 0) || (line == 65535))
mov DWORD PTR _line$1$[ebp], esi
test esi, esi
je SHORT $LN35@xmlRaiseEr
cmp esi, 65535 ; 0000ffffH
jne SHORT $LN98@xmlRaiseEr
$LN35@xmlRaiseEr:
; 539 : line = xmlGetLineNo(node);
push ebx
call _xmlGetLineNo
add esp, 4
jmp SHORT $LN109@xmlRaiseEr
$LN96@xmlRaiseEr:
; 521 : } else if ((node != NULL) && (file == NULL)) {
mov esi, DWORD PTR _line$[ebp]
mov DWORD PTR _line$1$[ebp], esi
jmp SHORT $LN98@xmlRaiseEr
$LN95@xmlRaiseEr:
mov eax, DWORD PTR _line$[ebp]
$LN109@xmlRaiseEr:
; 540 : }
; 541 :
; 542 : /*
; 543 : * Save the information about the error
; 544 : */
; 545 : xmlResetError(to);
mov DWORD PTR _line$1$[ebp], eax
$LN98@xmlRaiseEr:
mov esi, DWORD PTR _file$[ebp]
$LN34@xmlRaiseEr:
push edi
call _xmlResetError
; 546 : to->domain = domain;
mov eax, DWORD PTR _domain$[ebp]
add esp, 4
mov DWORD PTR [edi], eax
; 547 : to->code = code;
mov eax, DWORD PTR _code$[ebp]
mov DWORD PTR [edi+4], eax
; 548 : to->message = str;
mov eax, DWORD PTR _str$1$[ebp]
mov DWORD PTR [edi+8], eax
; 549 : to->level = level;
mov eax, DWORD PTR _level$[ebp]
mov DWORD PTR [edi+12], eax
; 550 : if (file != NULL)
test esi, esi
je SHORT $LN36@xmlRaiseEr
; 551 : to->file = (char *) xmlStrdup((const xmlChar *) file);
push esi
jmp $LN105@xmlRaiseEr
$LN36@xmlRaiseEr:
; 552 : else if (baseptr != NULL) {
mov edx, DWORD PTR _baseptr$1$[ebp]
test edx, edx
je $LN49@xmlRaiseEr
; 553 : #ifdef LIBXML_XINCLUDE_ENABLED
; 554 : /*
; 555 : * We check if the error is within an XInclude section and,
; 556 : * if so, attempt to print out the href of the XInclude instead
; 557 : * of the usual "base" (doc->URL) for the node (bug 152623).
; 558 : */
; 559 : xmlNodePtr prev = baseptr;
mov esi, edx
; 560 : int inclcount = 0;
xor eax, eax
$LL7@xmlRaiseEr:
; 562 : if (prev->prev == NULL)
mov ecx, DWORD PTR [esi+28]
test ecx, ecx
jne SHORT $LN39@xmlRaiseEr
; 563 : prev = prev->parent;
mov esi, DWORD PTR [esi+20]
jmp SHORT $LN44@xmlRaiseEr
$LN39@xmlRaiseEr:
; 564 : else {
; 565 : prev = prev->prev;
mov esi, ecx
; 566 : if (prev->type == XML_XINCLUDE_START) {
mov ecx, DWORD PTR [esi+4]
cmp ecx, 19 ; 00000013H
jne SHORT $LN41@xmlRaiseEr
; 567 : if (--inclcount < 0)
sub eax, 1
js SHORT $LN77@xmlRaiseEr
; 568 : break;
; 569 : } else if (prev->type == XML_XINCLUDE_END)
jmp SHORT $LN44@xmlRaiseEr
$LN41@xmlRaiseEr:
cmp ecx, 20 ; 00000014H
jne SHORT $LN44@xmlRaiseEr
; 570 : inclcount++;
inc eax
$LN44@xmlRaiseEr:
; 561 : while (prev != NULL) {
test esi, esi
jne SHORT $LL7@xmlRaiseEr
$LN77@xmlRaiseEr:
; 571 : }
; 572 : }
; 573 : if (prev != NULL) {
test esi, esi
je SHORT $LN45@xmlRaiseEr
; 574 : if (prev->type == XML_XINCLUDE_START) {
cmp DWORD PTR [esi+4], 19 ; 00000013H
push OFFSET ??_C@_04CMBCJJJD@href@
push esi
jne SHORT $LN47@xmlRaiseEr
; 575 : prev->type = XML_ELEMENT_NODE;
mov DWORD PTR [esi+4], 1
; 576 : to->file = (char *) xmlGetProp(prev, BAD_CAST "href");
call _xmlGetProp
mov DWORD PTR [edi+16], eax
add esp, 8
; 577 : prev->type = XML_XINCLUDE_START;
mov DWORD PTR [esi+4], 19 ; 00000013H
; 578 : } else {
jmp SHORT $LN46@xmlRaiseEr
$LN47@xmlRaiseEr:
; 579 : to->file = (char *) xmlGetProp(prev, BAD_CAST "href");
call _xmlGetProp
add esp, 8
; 580 : }
; 581 : } else
jmp SHORT $LN106@xmlRaiseEr
$LN45@xmlRaiseEr:
; 582 : #endif
; 583 : to->file = (char *) xmlStrdup(baseptr->doc->URL);
mov eax, DWORD PTR [edx+32]
push DWORD PTR [eax+72]
call _xmlStrdup
add esp, 4
$LN106@xmlRaiseEr:
; 584 : if ((to->file == NULL) && (node != NULL) && (node->doc != NULL)) {
mov DWORD PTR [edi+16], eax
$LN46@xmlRaiseEr:
cmp DWORD PTR [edi+16], 0
jne SHORT $LN49@xmlRaiseEr
test ebx, ebx
je SHORT $LN49@xmlRaiseEr
mov eax, DWORD PTR [ebx+32]
test eax, eax
je SHORT $LN49@xmlRaiseEr
; 585 : to->file = (char *) xmlStrdup(node->doc->URL);
push DWORD PTR [eax+72]
$LN105@xmlRaiseEr:
; 586 : }
; 587 : }
; 588 : to->line = line;
call _xmlStrdup
mov DWORD PTR [edi+16], eax
add esp, 4
$LN49@xmlRaiseEr:
mov eax, DWORD PTR _line$1$[ebp]
mov DWORD PTR [edi+20], eax
; 589 : if (str1 != NULL)
mov eax, DWORD PTR _str1$[ebp]
test eax, eax
je SHORT $LN50@xmlRaiseEr
; 590 : to->str1 = (char *) xmlStrdup((const xmlChar *) str1);
push eax
call _xmlStrdup
add esp, 4
mov DWORD PTR [edi+24], eax
$LN50@xmlRaiseEr:
; 591 : if (str2 != NULL)
mov eax, DWORD PTR _str2$[ebp]
test eax, eax
je SHORT $LN51@xmlRaiseEr
; 592 : to->str2 = (char *) xmlStrdup((const xmlChar *) str2);
push eax
call _xmlStrdup
add esp, 4
mov DWORD PTR [edi+28], eax
$LN51@xmlRaiseEr:
; 593 : if (str3 != NULL)
mov eax, DWORD PTR _str3$[ebp]
test eax, eax
je SHORT $LN52@xmlRaiseEr
; 594 : to->str3 = (char *) xmlStrdup((const xmlChar *) str3);
push eax
call _xmlStrdup
add esp, 4
mov DWORD PTR [edi+32], eax
$LN52@xmlRaiseEr:
; 595 : to->int1 = int1;
mov eax, DWORD PTR _int1$[ebp]
mov DWORD PTR [edi+36], eax
; 596 : to->int2 = col;
mov eax, DWORD PTR _col$[ebp]
mov DWORD PTR [edi+40], eax
; 597 : to->node = node;
; 598 : to->ctxt = ctx;
mov eax, DWORD PTR _ctx$[ebp]
mov DWORD PTR [edi+48], ebx
mov DWORD PTR [edi+44], eax
; 599 :
; 600 : if (to != &xmlLastError)
call ___xmlLastError
cmp edi, eax
je SHORT $LN53@xmlRaiseEr
; 601 : xmlCopyError(to,&xmlLastError);
call ___xmlLastError
push eax
push edi
call _xmlCopyError
add esp, 8
$LN53@xmlRaiseEr:
; 602 :
; 603 : if (schannel != NULL) {
mov eax, DWORD PTR _schannel$1$[ebp]
test eax, eax
je SHORT $LN54@xmlRaiseEr
; 604 : schannel(data, to);
push edi
push DWORD PTR _data$1$[ebp]
call eax
add esp, 8
pop esi
pop edi
; 639 : }
pop ebx
mov esp, ebp
pop ebp
ret 0
$LN54@xmlRaiseEr:
; 605 : return;
; 606 : }
; 607 :
; 608 : /*
; 609 : * Find the callback channel if channel param is NULL
; 610 : */
; 611 : if ((ctxt != NULL) && (channel == NULL) &&
; 612 : (xmlStructuredError == NULL) && (ctxt->sax != NULL)) {
mov ebx, DWORD PTR _channel$[ebp]
mov esi, DWORD PTR _ctxt$1$[ebp]
test ebx, ebx
jne SHORT $LN86@xmlRaiseEr
test esi, esi
je SHORT $LN55@xmlRaiseEr
call ___xmlStructuredError
cmp DWORD PTR [eax], ebx
jne SHORT $LN55@xmlRaiseEr
mov eax, DWORD PTR [esi]
test eax, eax
je SHORT $LN55@xmlRaiseEr
; 613 : if (level == XML_ERR_WARNING)
cmp DWORD PTR _level$[ebp], 1
jne SHORT $LN57@xmlRaiseEr
; 614 : channel = ctxt->sax->warning;
mov ebx, DWORD PTR [eax+84]
; 617 : data = ctxt->userData;
mov eax, DWORD PTR [esi+4]
jmp SHORT $LN107@xmlRaiseEr
$LN57@xmlRaiseEr:
; 615 : else
; 616 : channel = ctxt->sax->error;
mov ebx, DWORD PTR [eax+88]
; 617 : data = ctxt->userData;
mov eax, DWORD PTR [esi+4]
jmp SHORT $LN107@xmlRaiseEr
$LN55@xmlRaiseEr:
; 618 : } else if (channel == NULL) {
; 619 : channel = xmlGenericError;
call ___xmlGenericError
mov ebx, DWORD PTR [eax]
; 620 : if (ctxt != NULL) {
test esi, esi
je SHORT $LN60@xmlRaiseEr
; 621 : data = ctxt;
mov DWORD PTR _data$1$[ebp], esi
; 622 : } else {
jmp SHORT $LN61@xmlRaiseEr
$LN60@xmlRaiseEr:
; 623 : data = xmlGenericErrorContext;
call ___xmlGenericErrorContext
mov eax, DWORD PTR [eax]
$LN107@xmlRaiseEr:
; 624 : }
; 625 : }
; 626 : if (channel == NULL)
mov DWORD PTR _data$1$[ebp], eax
$LN61@xmlRaiseEr:
test ebx, ebx
je SHORT $LN101@xmlRaiseEr
$LN86@xmlRaiseEr:
; 627 : return;
; 628 :
; 629 : if ((channel == xmlParserError) ||
; 630 : (channel == xmlParserWarning) ||
; 631 : (channel == xmlParserValidityError) ||
cmp ebx, OFFSET _xmlParserError
je SHORT $LN65@xmlRaiseEr
cmp ebx, OFFSET _xmlParserWarning
je SHORT $LN65@xmlRaiseEr
cmp ebx, OFFSET _xmlParserValidityError
je SHORT $LN65@xmlRaiseEr
cmp ebx, OFFSET _xmlParserValidityWarning
je SHORT $LN65@xmlRaiseEr
; 634 : else if ((channel == (xmlGenericErrorFunc) fprintf) ||
cmp ebx, OFFSET _fprintf
je SHORT $LN68@xmlRaiseEr
cmp ebx, OFFSET _xmlGenericErrorDefaultFunc
je SHORT $LN68@xmlRaiseEr
; 637 : else
; 638 : channel(data, "%s", str);
push DWORD PTR _str$1$[ebp]
push OFFSET ??_C@_02DKCKIIND@?$CFs@
push DWORD PTR _data$1$[ebp]
call ebx
add esp, 12 ; 0000000cH
pop esi
pop edi
; 639 : }
pop ebx
mov esp, ebp
pop ebp
ret 0
$LN68@xmlRaiseEr:
; 635 : (channel == xmlGenericErrorDefaultFunc))
; 636 : xmlReportError(to, ctxt, str, channel, data);
push DWORD PTR _data$1$[ebp]
push ebx
push DWORD PTR _str$1$[ebp]
push esi
push edi
call _xmlReportError
add esp, 20 ; 00000014H
pop esi
pop edi
; 639 : }
pop ebx
mov esp, ebp
pop ebp
ret 0
$LN65@xmlRaiseEr:
; 632 : (channel == xmlParserValidityWarning))
; 633 : xmlReportError(to, ctxt, str, NULL, NULL);
push 0
push 0
push DWORD PTR _str$1$[ebp]
push esi
push edi
call _xmlReportError
add esp, 20 ; 00000014H
$LN101@xmlRaiseEr:
pop esi
$LN67@xmlRaiseEr:
pop edi
; 639 : }
pop ebx
mov esp, ebp
pop ebp
ret 0
___xmlRaiseError ENDP
_TEXT ENDS
; Function compile flags: /Ogtp
; File c:\users\dag\documents\_clients\codeproject authors group\windows on arm\libxml2\libxml2-2.9.9\error.c
; COMDAT _xmlCopyError
_TEXT SEGMENT
_str3$1$ = -12 ; size = 4
_str2$1$ = -8 ; size = 4
_str1$1$ = -4 ; size = 4
_file$1$ = 8 ; size = 4
_from$ = 8 ; size = 4
_to$ = 12 ; size = 4
_xmlCopyError PROC ; COMDAT
; 957 : xmlCopyError(xmlErrorPtr from, xmlErrorPtr to) {
push ebp
mov ebp, esp
sub esp, 12 ; 0000000cH
mov ecx, OFFSET __67926DEE_error@c
push esi
push edi
call @__CheckForDebuggerJustMyCode@4
mov edi, DWORD PTR _from$[ebp]
test edi, edi
je $LN3@xmlCopyErr
; 958 : char *message, *file, *str1, *str2, *str3;
; 959 :
; 960 : if ((from == NULL) || (to == NULL))
mov esi, DWORD PTR _to$[ebp]
test esi, esi
je $LN3@xmlCopyErr
; 962 :
; 963 : message = (char *) xmlStrdup((xmlChar *) from->message);
push ebx
push DWORD PTR [edi+8]
call _xmlStrdup
; 964 : file = (char *) xmlStrdup ((xmlChar *) from->file);
push DWORD PTR [edi+16]
mov ebx, eax
call _xmlStrdup
; 965 : str1 = (char *) xmlStrdup ((xmlChar *) from->str1);
push DWORD PTR [edi+24]
mov DWORD PTR _file$1$[ebp], eax
call _xmlStrdup
; 966 : str2 = (char *) xmlStrdup ((xmlChar *) from->str2);
push DWORD PTR [edi+28]
mov DWORD PTR _str1$1$[ebp], eax
call _xmlStrdup
; 967 : str3 = (char *) xmlStrdup ((xmlChar *) from->str3);
push DWORD PTR [edi+32]
mov DWORD PTR _str2$1$[ebp], eax
call _xmlStrdup
; 968 :
; 969 : if (to->message != NULL)
mov ecx, DWORD PTR [esi+8]
add esp, 20 ; 00000014H
mov DWORD PTR _str3$1$[ebp], eax
test ecx, ecx
je SHORT $LN4@xmlCopyErr
; 970 : xmlFree(to->message);
push ecx
call DWORD PTR _xmlFree
add esp, 4
$LN4@xmlCopyErr:
; 971 : if (to->file != NULL)
mov eax, DWORD PTR [esi+16]
test eax, eax
je SHORT $LN5@xmlCopyErr
; 972 : xmlFree(to->file);
push eax
call DWORD PTR _xmlFree
add esp, 4
$LN5@xmlCopyErr:
; 973 : if (to->str1 != NULL)
mov eax, DWORD PTR [esi+24]
test eax, eax
je SHORT $LN6@xmlCopyErr
; 974 : xmlFree(to->str1);
push eax
call DWORD PTR _xmlFree
add esp, 4
$LN6@xmlCopyErr:
; 975 : if (to->str2 != NULL)
mov eax, DWORD PTR [esi+28]
test eax, eax
je SHORT $LN7@xmlCopyErr
; 976 : xmlFree(to->str2);
push eax
call DWORD PTR _xmlFree
add esp, 4
$LN7@xmlCopyErr:
; 977 : if (to->str3 != NULL)
mov eax, DWORD PTR [esi+32]
test eax, eax
je SHORT $LN8@xmlCopyErr
; 978 : xmlFree(to->str3);
push eax
call DWORD PTR _xmlFree
add esp, 4
$LN8@xmlCopyErr:
; 979 : to->domain = from->domain;
mov eax, DWORD PTR [edi]
mov DWORD PTR [esi], eax
; 980 : to->code = from->code;
mov eax, DWORD PTR [edi+4]
mov DWORD PTR [esi+4], eax
; 981 : to->level = from->level;
mov eax, DWORD PTR [edi+12]
mov DWORD PTR [esi+12], eax
; 982 : to->line = from->line;
mov eax, DWORD PTR [edi+20]
mov DWORD PTR [esi+20], eax
; 983 : to->node = from->node;
mov eax, DWORD PTR [edi+48]
mov DWORD PTR [esi+48], eax
; 984 : to->int1 = from->int1;
mov eax, DWORD PTR [edi+36]
mov DWORD PTR [esi+36], eax
; 985 : to->int2 = from->int2;
mov eax, DWORD PTR [edi+40]
mov DWORD PTR [esi+40], eax
; 986 : to->node = from->node;
mov eax, DWORD PTR [edi+48]
mov DWORD PTR [esi+48], eax
; 987 : to->ctxt = from->ctxt;
mov eax, DWORD PTR [edi+44]
mov DWORD PTR [esi+44], eax
; 988 : to->message = message;
; 989 : to->file = file;
mov eax, DWORD PTR _file$1$[ebp]
mov DWORD PTR [esi+16], eax
; 990 : to->str1 = str1;
mov eax, DWORD PTR _str1$1$[ebp]
mov DWORD PTR [esi+24], eax
; 991 : to->str2 = str2;
mov eax, DWORD PTR _str2$1$[ebp]
mov DWORD PTR [esi+8], ebx
mov DWORD PTR [esi+28], eax
; 992 : to->str3 = str3;
mov eax, DWORD PTR _str3$1$[ebp]
; 993 :
; 994 : return 0;
pop ebx
mov DWORD PTR [esi+32], eax
xor eax, eax
pop edi
; 995 : }
pop esi
mov esp, ebp
pop ebp
ret 0
$LN3@xmlCopyErr:
pop edi
; 961 : return(-1);
or eax, -1
; 995 : }
pop esi
mov esp, ebp
pop ebp
ret 0
_xmlCopyError ENDP
_TEXT ENDS
; Function compile flags: /Ogtp
; File c:\users\dag\documents\_clients\codeproject authors group\windows on arm\libxml2\libxml2-2.9.9\error.c
; COMDAT _xmlResetError
_TEXT SEGMENT
_err$ = 8 ; size = 4
_xmlResetError PROC ; COMDAT
; 874 : {
push ebp
mov ebp, esp
push esi
mov ecx, OFFSET __67926DEE_error@c
call @__CheckForDebuggerJustMyCode@4
mov esi, DWORD PTR _err$[ebp]
test esi, esi
je SHORT $LN1@xmlResetEr
; 875 : if (err == NULL)
; 876 : return;
; 877 : if (err->code == XML_ERR_OK)
cmp DWORD PTR [esi+4], 0
je SHORT $LN1@xmlResetEr
; 878 : return;
; 879 : if (err->message != NULL)
mov eax, DWORD PTR [esi+8]
test eax, eax
je SHORT $LN4@xmlResetEr
; 880 : xmlFree(err->message);
push eax
call DWORD PTR _xmlFree
add esp, 4
$LN4@xmlResetEr:
; 881 : if (err->file != NULL)
mov eax, DWORD PTR [esi+16]
test eax, eax
je SHORT $LN5@xmlResetEr
; 882 : xmlFree(err->file);
push eax
call DWORD PTR _xmlFree
add esp, 4
$LN5@xmlResetEr:
; 883 : if (err->str1 != NULL)
mov eax, DWORD PTR [esi+24]
test eax, eax
je SHORT $LN6@xmlResetEr
; 884 : xmlFree(err->str1);
push eax
call DWORD PTR _xmlFree
add esp, 4
$LN6@xmlResetEr:
; 885 : if (err->str2 != NULL)
mov eax, DWORD PTR [esi+28]
test eax, eax
je SHORT $LN7@xmlResetEr
; 886 : xmlFree(err->str2);
push eax
call DWORD PTR _xmlFree
add esp, 4
$LN7@xmlResetEr:
; 887 : if (err->str3 != NULL)
mov eax, DWORD PTR [esi+32]
test eax, eax
je SHORT $LN8@xmlResetEr
; 888 : xmlFree(err->str3);
push eax
call DWORD PTR _xmlFree
add esp, 4
$LN8@xmlResetEr:
; 889 : memset(err, 0, sizeof(xmlError));
push 52 ; 00000034H
push 0
push esi
call _memset
add esp, 12 ; 0000000cH
$LN1@xmlResetEr:
pop esi
; 890 : err->code = XML_ERR_OK;
; 891 : }
pop ebp
ret 0
_xmlResetError ENDP
_TEXT ENDS
; Function compile flags: /Ogtp
; File c:\users\dag\documents\_clients\codeproject authors group\windows on arm\libxml2\libxml2-2.9.9\error.c
; COMDAT _xmlCtxtResetLastError
_TEXT SEGMENT
_ctx$ = 8 ; size = 4
_xmlCtxtResetLastError PROC ; COMDAT
; 936 : {
push ebp
mov ebp, esp
mov ecx, OFFSET __67926DEE_error@c
call @__CheckForDebuggerJustMyCode@4
mov eax, DWORD PTR _ctx$[ebp]
test eax, eax
je SHORT $LN1@xmlCtxtRes
; 937 : xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
; 938 :
; 939 : if (ctxt == NULL)
; 940 : return;
; 941 : ctxt->errNo = XML_ERR_OK;
cmp DWORD PTR [eax+388], 0
mov DWORD PTR [eax+84], 0
; 942 : if (ctxt->lastError.code == XML_ERR_OK)
je SHORT $LN1@xmlCtxtRes
; 943 : return;
; 944 : xmlResetError(&ctxt->lastError);
add eax, 384 ; 00000180H
mov DWORD PTR _ctx$[ebp], eax
; 945 : }
pop ebp
; 943 : return;
; 944 : xmlResetError(&ctxt->lastError);
jmp _xmlResetError
$LN1@xmlCtxtRes:
; 945 : }
pop ebp
ret 0
_xmlCtxtResetLastError ENDP
_TEXT ENDS
; Function compile flags: /Ogtp
; File c:\users\dag\documents\_clients\codeproject authors group\windows on arm\libxml2\libxml2-2.9.9\error.c
; COMDAT _xmlCtxtGetLastError
_TEXT SEGMENT
_ctx$ = 8 ; size = 4
_xmlCtxtGetLastError PROC ; COMDAT
; 917 : {
push ebp
mov ebp, esp
mov ecx, OFFSET __67926DEE_error@c
call @__CheckForDebuggerJustMyCode@4
mov eax, DWORD PTR _ctx$[ebp]
test eax, eax
je SHORT $LN5@xmlCtxtGet
; 918 : xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
; 919 :
; 920 : if (ctxt == NULL)
; 921 : return (NULL);
; 922 : if (ctxt->lastError.code == XML_ERR_OK)
cmp DWORD PTR [eax+388], 0
je SHORT $LN5@xmlCtxtGet
; 924 : return (&ctxt->lastError);
add eax, 384 ; 00000180H
; 925 : }
pop ebp
ret 0
$LN5@xmlCtxtGet:
; 923 : return (NULL);
xor eax, eax
; 925 : }
pop ebp
ret 0
_xmlCtxtGetLastError ENDP
_TEXT ENDS
; Function compile flags: /Ogtp
; File c:\users\dag\documents\_clients\codeproject authors group\windows on arm\libxml2\libxml2-2.9.9\error.c
; COMDAT _xmlResetLastError
_TEXT SEGMENT
_xmlResetLastError PROC ; COMDAT
mov ecx, OFFSET __67926DEE_error@c
call @__CheckForDebuggerJustMyCode@4
call ___xmlLastError
cmp DWORD PTR [eax+4], 0
je SHORT $LN1@xmlResetLa
; 902 : if (xmlLastError.code == XML_ERR_OK)
; 903 : return;
; 904 : xmlResetError(&xmlLastError);
call ___xmlLastError
push eax
call _xmlResetError
pop ecx
$LN1@xmlResetLa:
; 905 : }
ret 0
_xmlResetLastError ENDP
_TEXT ENDS
; Function compile flags: /Ogtp
; File c:\users\dag\documents\_clients\codeproject authors group\windows on arm\libxml2\libxml2-2.9.9\error.c
; COMDAT _xmlGetLastError
_TEXT SEGMENT
_xmlGetLastError PROC ; COMDAT
mov ecx, OFFSET __67926DEE_error@c
call @__CheckForDebuggerJustMyCode@4
call ___xmlLastError
cmp DWORD PTR [eax+4], 0
jne SHORT $LN2@xmlGetLast
; 861 : if (xmlLastError.code == XML_ERR_OK)
; 862 : return (NULL);
xor eax, eax
; 864 : }
ret 0
$LN2@xmlGetLast:
; 863 : return (&xmlLastError);
jmp ___xmlLastError
_xmlGetLastError ENDP
_TEXT ENDS
; Function compile flags: /Ogtp
; File c:\users\dag\documents\_clients\codeproject authors group\windows on arm\libxml2\libxml2-2.9.9\error.c
; COMDAT _xmlParserPrintFileContext
_TEXT SEGMENT
_input$ = 8 ; size = 4
_xmlParserPrintFileContext PROC ; COMDAT
; 230 : xmlParserPrintFileContext(xmlParserInputPtr input) {
push ebp
mov ebp, esp
push esi
mov ecx, OFFSET __67926DEE_error@c
call @__CheckForDebuggerJustMyCode@4
call ___xmlGenericErrorContext
mov esi, DWORD PTR [eax]
call ___xmlGenericError
push esi
push DWORD PTR [eax]
push DWORD PTR _input$[ebp]
call _xmlParserPrintFileContextInternal
add esp, 12 ; 0000000cH
pop esi
; 231 : xmlParserPrintFileContextInternal(input, xmlGenericError,
; 232 : xmlGenericErrorContext);
; 233 : }
pop ebp
ret 0
_xmlParserPrintFileContext ENDP
_TEXT ENDS
; Function compile flags: /Ogtp
; File c:\users\dag\documents\_clients\codeproject authors group\windows on arm\libxml2\libxml2-2.9.9\error.c
; COMDAT _xmlParserPrintFileInfo
_TEXT SEGMENT
tv184 = 8 ; size = 4
_input$ = 8 ; size = 4
_xmlParserPrintFileInfo PROC ; COMDAT
; 153 : xmlParserPrintFileInfo(xmlParserInputPtr input) {
push ebp
mov ebp, esp
push edi
mov ecx, OFFSET __67926DEE_error@c
call @__CheckForDebuggerJustMyCode@4
mov edi, DWORD PTR _input$[ebp]
test edi, edi
je SHORT $LN4@xmlParserP
; 154 : if (input != NULL) {
; 155 : if (input->filename)
push ebx
push esi
mov esi, DWORD PTR [edi+4]
call ___xmlGenericError
mov ebx, eax
mov eax, DWORD PTR [edi+28]
mov DWORD PTR tv184[ebp], eax
test esi, esi
je SHORT $LN3@xmlParserP
; 156 : xmlGenericError(xmlGenericErrorContext,
mov esi, DWORD PTR [edi+4]
call ___xmlGenericErrorContext
push DWORD PTR tv184[ebp]
push esi
push OFFSET ??_C@_07FCDHCGBN@?$CFs?3?$CFd?3?5@
push DWORD PTR [eax]
mov eax, DWORD PTR [ebx]
call eax
add esp, 16 ; 00000010H
pop esi
pop ebx
pop edi
; 161 : "Entity: line %d: ", input->line);
; 162 : }
; 163 : }
pop ebp
ret 0
$LN3@xmlParserP:
; 157 : "%s:%d: ", input->filename,
; 158 : input->line);
; 159 : else
; 160 : xmlGenericError(xmlGenericErrorContext,
call ___xmlGenericErrorContext
push DWORD PTR tv184[ebp]
push OFFSET ??_C@_0BC@FMCMLLAH@Entity?3?5line?5?$CFd?3?5@
push DWORD PTR [eax]
mov eax, DWORD PTR [ebx]
call eax
add esp, 12 ; 0000000cH
pop esi
pop ebx
$LN4@xmlParserP:
pop edi
; 161 : "Entity: line %d: ", input->line);
; 162 : }
; 163 : }
pop ebp
ret 0
_xmlParserPrintFileInfo ENDP
_TEXT ENDS
; Function compile flags: /Ogtp
; File c:\users\dag\documents\_clients\codeproject authors group\windows on arm\libxml2\libxml2-2.9.9\error.c
; File c:\program files (x86)\windows kits\10\include\10.0.17763.0\ucrt\stdio.h
; File c:\users\dag\documents\_clients\codeproject authors group\windows on arm\libxml2\libxml2-2.9.9\error.c
; COMDAT _xmlParserValidityWarning
_TEXT SEGMENT
_prev_size$1$ = -8 ; size = 4
_input$1$ = -4 ; size = 4
_ctx$ = 8 ; size = 4
_msg$ = 12 ; size = 4
_xmlParserValidityWarning PROC ; COMDAT
; 818 : {
push ebp
mov ebp, esp
sub esp, 8
push ebx
push esi
push edi
mov ecx, OFFSET __67926DEE_error@c
call @__CheckForDebuggerJustMyCode@4
push DWORD PTR _msg$[ebp]
mov DWORD PTR _input$1$[ebp], 0
call _xmlStrlen
mov edi, DWORD PTR _ctx$[ebp]
add esp, 4
test edi, edi
je SHORT $LN4@xmlParserV
; 819 : xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
; 820 : xmlParserInputPtr input = NULL;
; 821 : char * str;
; 822 : int len = xmlStrlen((const xmlChar *) msg);
; 823 :
; 824 : if ((ctxt != NULL) && (len != 0) && (msg[len - 1] != ':')) {
test eax, eax
je SHORT $LN4@xmlParserV
mov ecx, DWORD PTR _msg$[ebp]
cmp BYTE PTR [eax+ecx-1], 58 ; 0000003aH
je SHORT $LN4@xmlParserV
; 825 : input = ctxt->input;
mov eax, DWORD PTR [edi+36]
mov DWORD PTR _input$1$[ebp], eax
; 826 : if ((input->filename == NULL) && (ctxt->inputNr > 1))
cmp DWORD PTR [eax+4], 0
jne SHORT $LN5@xmlParserV
mov ecx, DWORD PTR [edi+40]
cmp ecx, 1
jle SHORT $LN5@xmlParserV
; 827 : input = ctxt->inputTab[ctxt->inputNr - 2];
mov eax, DWORD PTR [edi+48]
mov eax, DWORD PTR [eax+ecx*4-8]
mov DWORD PTR _input$1$[ebp], eax
$LN5@xmlParserV:
; 828 :
; 829 : xmlParserPrintFileInfo(input);
push eax
call _xmlParserPrintFileInfo
add esp, 4
$LN4@xmlParserV:
; 830 : }
; 831 :
; 832 : xmlGenericError(xmlGenericErrorContext, "validity warning: ");
call ___xmlGenericError
mov esi, eax
call ___xmlGenericErrorContext
push OFFSET ??_C@_0BD@BMEBJKPI@validity?5warning?3?5@
push DWORD PTR [eax]
mov eax, DWORD PTR [esi]
call eax
; 833 : XML_GET_VAR_STR(msg, str);
push 150 ; 00000096H
mov DWORD PTR _prev_size$1$[ebp], -1
call DWORD PTR _xmlMalloc
mov ebx, eax
add esp, 12 ; 0000000cH
test ebx, ebx
je SHORT $LN21@xmlParserV
mov esi, 150 ; 00000096H
$LL2@xmlParserV:
mov edi, DWORD PTR _msg$[ebp]
; File c:\program files (x86)\windows kits\10\include\10.0.17763.0\ucrt\stdio.h
; 1440 : int const _Result = __stdio_common_vsprintf(
call ___local_stdio_printf_options
lea ecx, DWORD PTR _msg$[ebp+4]
push ecx
push 0
mov ecx, DWORD PTR [eax]
push edi
push esi
push ebx
push DWORD PTR [eax+4]
or ecx, 2
push ecx
call DWORD PTR __imp____stdio_common_vsprintf
add esp, 28 ; 0000001cH
; 1441 : _CRT_INTERNAL_LOCAL_PRINTF_OPTIONS | _CRT_INTERNAL_PRINTF_STANDARD_SNPRINTF_BEHAVIOR,
; 1442 : _Buffer, _BufferCount, _Format, NULL, _ArgList);
; 1443 :
; 1444 : return _Result < 0 ? -1 : _Result;
mov ecx, -1
test eax, eax
cmovs eax, ecx
; File c:\users\dag\documents\_clients\codeproject authors group\windows on arm\libxml2\libxml2-2.9.9\error.c
; 833 : XML_GET_VAR_STR(msg, str);
cmp eax, ecx
jle SHORT $LN10@xmlParserV
cmp eax, esi
jge SHORT $LN9@xmlParserV
cmp DWORD PTR _prev_size$1$[ebp], eax
je SHORT $LN26@xmlParserV
mov DWORD PTR _prev_size$1$[ebp], eax
$LN9@xmlParserV:
inc esi
add esi, eax
jmp SHORT $LN11@xmlParserV
$LN10@xmlParserV:
add esi, 100 ; 00000064H
$LN11@xmlParserV:
push esi
push ebx
call DWORD PTR _xmlRealloc
add esp, 8
test eax, eax
je SHORT $LN26@xmlParserV
mov ebx, eax
cmp esi, 64000 ; 0000fa00H
jl SHORT $LL2@xmlParserV
$LN26@xmlParserV:
mov edi, DWORD PTR _ctx$[ebp]
$LN21@xmlParserV:
; 834 : xmlGenericError(xmlGenericErrorContext, "%s", str);
call ___xmlGenericError
mov esi, eax
call ___xmlGenericErrorContext
push ebx
push OFFSET ??_C@_02DKCKIIND@?$CFs@
push DWORD PTR [eax]
mov eax, DWORD PTR [esi]
call eax
add esp, 12 ; 0000000cH
; 835 : if (str != NULL)
test ebx, ebx
je SHORT $LN13@xmlParserV
; 836 : xmlFree(str);
push ebx
call DWORD PTR _xmlFree
add esp, 4
$LN13@xmlParserV:
; 837 :
; 838 : if (ctxt != NULL) {
test edi, edi
je SHORT $LN18@xmlParserV
; 231 : xmlParserPrintFileContextInternal(input, xmlGenericError,
call ___xmlGenericErrorContext
mov esi, DWORD PTR [eax]
call ___xmlGenericError
push esi
push DWORD PTR [eax]
push DWORD PTR _input$1$[ebp]
call _xmlParserPrintFileContextInternal
add esp, 12 ; 0000000cH
$LN18@xmlParserV:
pop edi
; 839 : xmlParserPrintFileContext(input);
; 840 : }
; 841 : }
pop esi
pop ebx
mov esp, ebp
pop ebp
ret 0
_xmlParserValidityWarning ENDP
_TEXT ENDS
; Function compile flags: /Ogtp
; File c:\users\dag\documents\_clients\codeproject authors group\windows on arm\libxml2\libxml2-2.9.9\error.c
; File c:\program files (x86)\windows kits\10\include\10.0.17763.0\ucrt\stdio.h
; File c:\users\dag\documents\_clients\codeproject authors group\windows on arm\libxml2\libxml2-2.9.9\error.c
; COMDAT _xmlParserValidityError
_TEXT SEGMENT
_prev_size$1$ = -8 ; size = 4
_input$1$ = -4 ; size = 4
_ctx$ = 8 ; size = 4
_msg$ = 12 ; size = 4
_xmlParserValidityError PROC ; COMDAT
; 774 : {
push ebp
mov ebp, esp
sub esp, 8
push ebx
push esi
push edi
mov ecx, OFFSET __67926DEE_error@c
call @__CheckForDebuggerJustMyCode@4
push DWORD PTR _msg$[ebp]
mov DWORD PTR _input$1$[ebp], 0
call _xmlStrlen
add esp, 4
cmp eax, 1
jle SHORT $LN4@xmlParserV
; 775 : xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
; 776 : xmlParserInputPtr input = NULL;
; 777 : char * str;
; 778 : int len = xmlStrlen((const xmlChar *) msg);
; 779 : static int had_info = 0;
; 780 :
; 781 : if ((len > 1) && (msg[len - 2] != ':')) {
mov ecx, DWORD PTR _msg$[ebp]
cmp BYTE PTR [eax+ecx-2], 58 ; 0000003aH
je SHORT $LN4@xmlParserV
; 782 : if (ctxt != NULL) {
mov eax, DWORD PTR _ctx$[ebp]
test eax, eax
je SHORT $LN8@xmlParserV
; 783 : input = ctxt->input;
mov ebx, DWORD PTR [eax+36]
mov DWORD PTR _input$1$[ebp], ebx
; 784 : if ((input->filename == NULL) && (ctxt->inputNr > 1))
cmp DWORD PTR [ebx+4], 0
jne SHORT $LN7@xmlParserV
mov ecx, DWORD PTR [eax+40]
cmp ecx, 1
jle SHORT $LN7@xmlParserV
; 785 : input = ctxt->inputTab[ctxt->inputNr - 2];
mov eax, DWORD PTR [eax+48]
mov ebx, DWORD PTR [eax+ecx*4-8]
mov DWORD PTR _input$1$[ebp], ebx
$LN7@xmlParserV:
; 786 :
; 787 : if (had_info == 0) {
cmp DWORD PTR ?had_info@?1??xmlParserValidityError@@9@9, 0
jne SHORT $LN8@xmlParserV
; 788 : xmlParserPrintFileInfo(input);
push ebx
call _xmlParserPrintFileInfo
add esp, 4
$LN8@xmlParserV:
; 789 : }
; 790 : }
; 791 : xmlGenericError(xmlGenericErrorContext, "validity error: ");
call ___xmlGenericError
mov esi, eax
call ___xmlGenericErrorContext
push OFFSET ??_C@_0BB@DJCEBDOI@validity?5error?3?5@
push DWORD PTR [eax]
mov eax, DWORD PTR [esi]
call eax
add esp, 8
; 792 : had_info = 0;
xor eax, eax
; 793 : } else {
jmp SHORT $LN5@xmlParserV
$LN4@xmlParserV:
; 794 : had_info = 1;
mov eax, 1
$LN5@xmlParserV:
; 797 : XML_GET_VAR_STR(msg, str);
push 150 ; 00000096H
mov DWORD PTR ?had_info@?1??xmlParserValidityError@@9@9, eax
mov DWORD PTR _prev_size$1$[ebp], -1
call DWORD PTR _xmlMalloc
mov ebx, eax
add esp, 4
test ebx, ebx
je SHORT $LN29@xmlParserV
mov esi, 150 ; 00000096H
$LL2@xmlParserV:
mov edi, DWORD PTR _msg$[ebp]
; File c:\program files (x86)\windows kits\10\include\10.0.17763.0\ucrt\stdio.h
; 1440 : int const _Result = __stdio_common_vsprintf(
call ___local_stdio_printf_options
lea ecx, DWORD PTR _msg$[ebp+4]
push ecx
push 0
mov ecx, DWORD PTR [eax]
push edi
push esi
push ebx
push DWORD PTR [eax+4]
or ecx, 2
push ecx
call DWORD PTR __imp____stdio_common_vsprintf
add esp, 28 ; 0000001cH
; 1441 : _CRT_INTERNAL_LOCAL_PRINTF_OPTIONS | _CRT_INTERNAL_PRINTF_STANDARD_SNPRINTF_BEHAVIOR,
; 1442 : _Buffer, _BufferCount, _Format, NULL, _ArgList);
; 1443 :
; 1444 : return _Result < 0 ? -1 : _Result;
mov ecx, -1
test eax, eax
cmovs eax, ecx
; File c:\users\dag\documents\_clients\codeproject authors group\windows on arm\libxml2\libxml2-2.9.9\error.c
; 797 : XML_GET_VAR_STR(msg, str);
cmp eax, ecx
jle SHORT $LN13@xmlParserV
cmp eax, esi
jge SHORT $LN12@xmlParserV
cmp DWORD PTR _prev_size$1$[ebp], eax
je SHORT $LN29@xmlParserV
mov DWORD PTR _prev_size$1$[ebp], eax
$LN12@xmlParserV:
inc esi
add esi, eax
jmp SHORT $LN14@xmlParserV
$LN13@xmlParserV:
add esi, 100 ; 00000064H
$LN14@xmlParserV:
push esi
push ebx
call DWORD PTR _xmlRealloc
add esp, 8
test eax, eax
je SHORT $LN29@xmlParserV
mov ebx, eax
cmp esi, 64000 ; 0000fa00H
jl SHORT $LL2@xmlParserV
$LN29@xmlParserV:
; 798 : xmlGenericError(xmlGenericErrorContext, "%s", str);
call ___xmlGenericError
mov esi, eax
call ___xmlGenericErrorContext
push ebx
push OFFSET ??_C@_02DKCKIIND@?$CFs@
push DWORD PTR [eax]
mov eax, DWORD PTR [esi]
call eax
add esp, 12 ; 0000000cH
; 799 : if (str != NULL)
test ebx, ebx
je SHORT $LN16@xmlParserV
; 800 : xmlFree(str);
push ebx
call DWORD PTR _xmlFree
add esp, 4
$LN16@xmlParserV:
; 801 :
; 802 : if ((ctxt != NULL) && (input != NULL)) {
cmp DWORD PTR _ctx$[ebp], 0
je SHORT $LN21@xmlParserV
mov edi, DWORD PTR _input$1$[ebp]
test edi, edi
je SHORT $LN21@xmlParserV
; 231 : xmlParserPrintFileContextInternal(input, xmlGenericError,
call ___xmlGenericErrorContext
mov esi, DWORD PTR [eax]
call ___xmlGenericError
push esi
push DWORD PTR [eax]
push edi
call _xmlParserPrintFileContextInternal
add esp, 12 ; 0000000cH
$LN21@xmlParserV:
pop edi
; 803 : xmlParserPrintFileContext(input);
; 804 : }
; 805 : }
pop esi
pop ebx
mov esp, ebp
pop ebp
ret 0
_xmlParserValidityError ENDP
_TEXT ENDS
; Function compile flags: /Ogtp
; File c:\users\dag\documents\_clients\codeproject authors group\windows on arm\libxml2\libxml2-2.9.9\error.c
; File c:\program files (x86)\windows kits\10\include\10.0.17763.0\ucrt\stdio.h
; File c:\users\dag\documents\_clients\codeproject authors group\windows on arm\libxml2\libxml2-2.9.9\error.c
; COMDAT _xmlParserWarning
_TEXT SEGMENT
_cur$1$ = -12 ; size = 4
_prev_size$1$ = -8 ; size = 4
_input$1$ = -4 ; size = 4
_ctx$ = 8 ; size = 4
_msg$ = 12 ; size = 4
_xmlParserWarning PROC ; COMDAT
; 725 : {
push ebp
mov ebp, esp
sub esp, 12 ; 0000000cH
push ebx
push esi
push edi
mov ecx, OFFSET __67926DEE_error@c
call @__CheckForDebuggerJustMyCode@4
mov eax, DWORD PTR _ctx$[ebp]
xor edi, edi
mov DWORD PTR _input$1$[ebp], 0
mov DWORD PTR _cur$1$[ebp], edi
test eax, eax
je SHORT $LN4@xmlParserW
; 726 : xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
; 727 : xmlParserInputPtr input = NULL;
; 728 : xmlParserInputPtr cur = NULL;
; 729 : char * str;
; 730 :
; 731 : if (ctxt != NULL) {
; 732 : input = ctxt->input;
mov edi, DWORD PTR [eax+36]
mov DWORD PTR _input$1$[ebp], edi
; 733 : if ((input != NULL) && (input->filename == NULL) &&
test edi, edi
je SHORT $LN5@xmlParserW
cmp DWORD PTR [edi+4], 0
jne SHORT $LN5@xmlParserW
mov ecx, DWORD PTR [eax+40]
cmp ecx, 1
jle SHORT $LN5@xmlParserW
; 734 : (ctxt->inputNr > 1)) {
; 735 : cur = input;
; 736 : input = ctxt->inputTab[ctxt->inputNr - 2];
mov eax, DWORD PTR [eax+48]
mov DWORD PTR _cur$1$[ebp], edi
mov edi, DWORD PTR [eax+ecx*4-8]
mov DWORD PTR _input$1$[ebp], edi
$LN5@xmlParserW:
; 737 : }
; 738 : xmlParserPrintFileInfo(input);
push edi
call _xmlParserPrintFileInfo
add esp, 4
$LN4@xmlParserW:
; 739 : }
; 740 :
; 741 : xmlGenericError(xmlGenericErrorContext, "warning: ");
call ___xmlGenericError
mov esi, eax
call ___xmlGenericErrorContext
push OFFSET ??_C@_09GFHECBDK@warning?3?5@
push DWORD PTR [eax]
mov eax, DWORD PTR [esi]
call eax
; 742 : XML_GET_VAR_STR(msg, str);
push 150 ; 00000096H
mov DWORD PTR _prev_size$1$[ebp], -1
call DWORD PTR _xmlMalloc
mov ebx, eax
add esp, 12 ; 0000000cH
test ebx, ebx
je SHORT $LN29@xmlParserW
mov esi, 150 ; 00000096H
npad 5
$LL2@xmlParserW:
mov edi, DWORD PTR _msg$[ebp]
; File c:\program files (x86)\windows kits\10\include\10.0.17763.0\ucrt\stdio.h
; 1440 : int const _Result = __stdio_common_vsprintf(
call ___local_stdio_printf_options
lea ecx, DWORD PTR _msg$[ebp+4]
push ecx
push 0
mov ecx, DWORD PTR [eax]
push edi
push esi
push ebx
push DWORD PTR [eax+4]
or ecx, 2
push ecx
call DWORD PTR __imp____stdio_common_vsprintf
add esp, 28 ; 0000001cH
; 1441 : _CRT_INTERNAL_LOCAL_PRINTF_OPTIONS | _CRT_INTERNAL_PRINTF_STANDARD_SNPRINTF_BEHAVIOR,
; 1442 : _Buffer, _BufferCount, _Format, NULL, _ArgList);
; 1443 :
; 1444 : return _Result < 0 ? -1 : _Result;
mov ecx, -1
test eax, eax
cmovs eax, ecx
; File c:\users\dag\documents\_clients\codeproject authors group\windows on arm\libxml2\libxml2-2.9.9\error.c
; 742 : XML_GET_VAR_STR(msg, str);
cmp eax, ecx
jle SHORT $LN10@xmlParserW
cmp eax, esi
jge SHORT $LN9@xmlParserW
cmp DWORD PTR _prev_size$1$[ebp], eax
je SHORT $LN29@xmlParserW
mov DWORD PTR _prev_size$1$[ebp], eax
$LN9@xmlParserW:
inc esi
add esi, eax
jmp SHORT $LN11@xmlParserW
$LN10@xmlParserW:
add esi, 100 ; 00000064H
$LN11@xmlParserW:
push esi
push ebx
call DWORD PTR _xmlRealloc
add esp, 8
test eax, eax
je SHORT $LN29@xmlParserW
mov ebx, eax
cmp esi, 64000 ; 0000fa00H
jl SHORT $LL2@xmlParserW
$LN29@xmlParserW:
; 743 : xmlGenericError(xmlGenericErrorContext, "%s", str);
call ___xmlGenericError
mov esi, eax
call ___xmlGenericErrorContext
push ebx
push OFFSET ??_C@_02DKCKIIND@?$CFs@
push DWORD PTR [eax]
mov eax, DWORD PTR [esi]
call eax
add esp, 12 ; 0000000cH
; 744 : if (str != NULL)
test ebx, ebx
je SHORT $LN13@xmlParserW
; 745 : xmlFree(str);
push ebx
call DWORD PTR _xmlFree
add esp, 4
$LN13@xmlParserW:
; 746 :
; 747 : if (ctxt != NULL) {
cmp DWORD PTR _ctx$[ebp], 0
je SHORT $LN21@xmlParserW
; 231 : xmlParserPrintFileContextInternal(input, xmlGenericError,
call ___xmlGenericErrorContext
mov esi, DWORD PTR [eax]
call ___xmlGenericError
push esi
push DWORD PTR [eax]
push DWORD PTR _input$1$[ebp]
call _xmlParserPrintFileContextInternal
; 748 : xmlParserPrintFileContext(input);
; 749 : if (cur != NULL) {
mov ebx, DWORD PTR _cur$1$[ebp]
; 231 : xmlParserPrintFileContextInternal(input, xmlGenericError,
add esp, 12 ; 0000000cH
; 748 : xmlParserPrintFileContext(input);
; 749 : if (cur != NULL) {
test ebx, ebx
je SHORT $LN21@xmlParserW
; 750 : xmlParserPrintFileInfo(cur);
push ebx
call _xmlParserPrintFileInfo
; 751 : xmlGenericError(xmlGenericErrorContext, "\n");
call ___xmlGenericError
mov esi, eax
call ___xmlGenericErrorContext
push OFFSET ??_C@_01EEMJAFIK@?6@
push DWORD PTR [eax]
mov eax, DWORD PTR [esi]
call eax
; 231 : xmlParserPrintFileContextInternal(input, xmlGenericError,
call ___xmlGenericErrorContext
mov esi, DWORD PTR [eax]
call ___xmlGenericError
push esi
push DWORD PTR [eax]
push ebx
call _xmlParserPrintFileContextInternal
add esp, 24 ; 00000018H
$LN21@xmlParserW:
pop edi
; 752 : xmlParserPrintFileContext(cur);
; 753 : }
; 754 : }
; 755 : }
pop esi
pop ebx
mov esp, ebp
pop ebp
ret 0
_xmlParserWarning ENDP
_TEXT ENDS
; Function compile flags: /Ogtp
; File c:\users\dag\documents\_clients\codeproject authors group\windows on arm\libxml2\libxml2-2.9.9\error.c
; File c:\program files (x86)\windows kits\10\include\10.0.17763.0\ucrt\stdio.h
; File c:\users\dag\documents\_clients\codeproject authors group\windows on arm\libxml2\libxml2-2.9.9\error.c
; COMDAT _xmlParserError
_TEXT SEGMENT
_cur$1$ = -12 ; size = 4
_prev_size$1$ = -8 ; size = 4
_input$1$ = -4 ; size = 4
_ctx$ = 8 ; size = 4
_msg$ = 12 ; size = 4
_xmlParserError PROC ; COMDAT
; 682 : {
push ebp
mov ebp, esp
sub esp, 12 ; 0000000cH
push ebx
push esi
push edi
mov ecx, OFFSET __67926DEE_error@c
call @__CheckForDebuggerJustMyCode@4
mov eax, DWORD PTR _ctx$[ebp]
xor edi, edi
mov DWORD PTR _input$1$[ebp], 0
mov DWORD PTR _cur$1$[ebp], edi
test eax, eax
je SHORT $LN4@xmlParserE
; 683 : xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
; 684 : xmlParserInputPtr input = NULL;
; 685 : xmlParserInputPtr cur = NULL;
; 686 : char * str;
; 687 :
; 688 : if (ctxt != NULL) {
; 689 : input = ctxt->input;
mov edi, DWORD PTR [eax+36]
mov DWORD PTR _input$1$[ebp], edi
; 690 : if ((input != NULL) && (input->filename == NULL) &&
test edi, edi
je SHORT $LN5@xmlParserE
cmp DWORD PTR [edi+4], 0
jne SHORT $LN5@xmlParserE
mov ecx, DWORD PTR [eax+40]
cmp ecx, 1
jle SHORT $LN5@xmlParserE
; 691 : (ctxt->inputNr > 1)) {
; 692 : cur = input;
; 693 : input = ctxt->inputTab[ctxt->inputNr - 2];
mov eax, DWORD PTR [eax+48]
mov DWORD PTR _cur$1$[ebp], edi
mov edi, DWORD PTR [eax+ecx*4-8]
mov DWORD PTR _input$1$[ebp], edi
$LN5@xmlParserE:
; 694 : }
; 695 : xmlParserPrintFileInfo(input);
push edi
call _xmlParserPrintFileInfo
add esp, 4
$LN4@xmlParserE:
; 696 : }
; 697 :
; 698 : xmlGenericError(xmlGenericErrorContext, "error: ");
call ___xmlGenericError
mov esi, eax
call ___xmlGenericErrorContext
push OFFSET ??_C@_07FJOHCPOO@error?3?5@
push DWORD PTR [eax]
mov eax, DWORD PTR [esi]
call eax
; 699 : XML_GET_VAR_STR(msg, str);
push 150 ; 00000096H
mov DWORD PTR _prev_size$1$[ebp], -1
call DWORD PTR _xmlMalloc
mov ebx, eax
add esp, 12 ; 0000000cH
test ebx, ebx
je SHORT $LN29@xmlParserE
mov esi, 150 ; 00000096H
npad 5
$LL2@xmlParserE:
mov edi, DWORD PTR _msg$[ebp]
; File c:\program files (x86)\windows kits\10\include\10.0.17763.0\ucrt\stdio.h
; 1440 : int const _Result = __stdio_common_vsprintf(
call ___local_stdio_printf_options
lea ecx, DWORD PTR _msg$[ebp+4]
push ecx
push 0
mov ecx, DWORD PTR [eax]
push edi
push esi
push ebx
push DWORD PTR [eax+4]
or ecx, 2
push ecx
call DWORD PTR __imp____stdio_common_vsprintf
add esp, 28 ; 0000001cH
; 1441 : _CRT_INTERNAL_LOCAL_PRINTF_OPTIONS | _CRT_INTERNAL_PRINTF_STANDARD_SNPRINTF_BEHAVIOR,
; 1442 : _Buffer, _BufferCount, _Format, NULL, _ArgList);
; 1443 :
; 1444 : return _Result < 0 ? -1 : _Result;
mov ecx, -1
test eax, eax
cmovs eax, ecx
; File c:\users\dag\documents\_clients\codeproject authors group\windows on arm\libxml2\libxml2-2.9.9\error.c
; 699 : XML_GET_VAR_STR(msg, str);
cmp eax, ecx
jle SHORT $LN10@xmlParserE
cmp eax, esi
jge SHORT $LN9@xmlParserE
cmp DWORD PTR _prev_size$1$[ebp], eax
je SHORT $LN29@xmlParserE
mov DWORD PTR _prev_size$1$[ebp], eax
$LN9@xmlParserE:
inc esi
add esi, eax
jmp SHORT $LN11@xmlParserE
$LN10@xmlParserE:
add esi, 100 ; 00000064H
$LN11@xmlParserE:
push esi
push ebx
call DWORD PTR _xmlRealloc
add esp, 8
test eax, eax
je SHORT $LN29@xmlParserE
mov ebx, eax
cmp esi, 64000 ; 0000fa00H
jl SHORT $LL2@xmlParserE
$LN29@xmlParserE:
; 700 : xmlGenericError(xmlGenericErrorContext, "%s", str);
call ___xmlGenericError
mov esi, eax
call ___xmlGenericErrorContext
push ebx
push OFFSET ??_C@_02DKCKIIND@?$CFs@
push DWORD PTR [eax]
mov eax, DWORD PTR [esi]
call eax
add esp, 12 ; 0000000cH
; 701 : if (str != NULL)
test ebx, ebx
je SHORT $LN13@xmlParserE
; 702 : xmlFree(str);
push ebx
call DWORD PTR _xmlFree
add esp, 4
$LN13@xmlParserE:
; 703 :
; 704 : if (ctxt != NULL) {
cmp DWORD PTR _ctx$[ebp], 0
je SHORT $LN21@xmlParserE
; 231 : xmlParserPrintFileContextInternal(input, xmlGenericError,
call ___xmlGenericErrorContext
mov esi, DWORD PTR [eax]
call ___xmlGenericError
push esi
push DWORD PTR [eax]
push DWORD PTR _input$1$[ebp]
call _xmlParserPrintFileContextInternal
; 705 : xmlParserPrintFileContext(input);
; 706 : if (cur != NULL) {
mov ebx, DWORD PTR _cur$1$[ebp]
; 231 : xmlParserPrintFileContextInternal(input, xmlGenericError,
add esp, 12 ; 0000000cH
; 705 : xmlParserPrintFileContext(input);
; 706 : if (cur != NULL) {
test ebx, ebx
je SHORT $LN21@xmlParserE
; 707 : xmlParserPrintFileInfo(cur);
push ebx
call _xmlParserPrintFileInfo
; 708 : xmlGenericError(xmlGenericErrorContext, "\n");
call ___xmlGenericError
mov esi, eax
call ___xmlGenericErrorContext
push OFFSET ??_C@_01EEMJAFIK@?6@
push DWORD PTR [eax]
mov eax, DWORD PTR [esi]
call eax
; 231 : xmlParserPrintFileContextInternal(input, xmlGenericError,
call ___xmlGenericErrorContext
mov esi, DWORD PTR [eax]
call ___xmlGenericError
push esi
push DWORD PTR [eax]
push ebx
call _xmlParserPrintFileContextInternal
add esp, 24 ; 00000018H
$LN21@xmlParserE:
pop edi
; 709 : xmlParserPrintFileContext(cur);
; 710 : }
; 711 : }
; 712 : }
pop esi
pop ebx
mov esp, ebp
pop ebp
ret 0
_xmlParserError ENDP
_TEXT ENDS
; Function compile flags: /Ogtp
; File c:\users\dag\documents\_clients\codeproject authors group\windows on arm\libxml2\libxml2-2.9.9\error.c
; COMDAT _xmlSetStructuredErrorFunc
_TEXT SEGMENT
_ctx$ = 8 ; size = 4
_handler$ = 12 ; size = 4
_xmlSetStructuredErrorFunc PROC ; COMDAT
; 134 : xmlSetStructuredErrorFunc(void *ctx, xmlStructuredErrorFunc handler) {
push ebp
mov ebp, esp
mov ecx, OFFSET __67926DEE_error@c
call @__CheckForDebuggerJustMyCode@4
call ___xmlStructuredErrorContext
mov ecx, DWORD PTR _ctx$[ebp]
mov DWORD PTR [eax], ecx
call ___xmlStructuredError
mov ecx, DWORD PTR _handler$[ebp]
mov DWORD PTR [eax], ecx
; 135 : xmlStructuredErrorContext = ctx;
; 136 : xmlStructuredError = handler;
; 137 : }
pop ebp
ret 0
_xmlSetStructuredErrorFunc ENDP
_TEXT ENDS
; Function compile flags: /Ogtp
; File c:\users\dag\documents\_clients\codeproject authors group\windows on arm\libxml2\libxml2-2.9.9\error.c
; COMDAT _initGenericErrorDefaultFunc
_TEXT SEGMENT
_handler$ = 8 ; size = 4
_initGenericErrorDefaultFunc PROC ; COMDAT
; 91 : {
push ebp
mov ebp, esp
mov ecx, OFFSET __67926DEE_error@c
call @__CheckForDebuggerJustMyCode@4
call ___xmlGenericError
mov ecx, eax
mov eax, DWORD PTR _handler$[ebp]
test eax, eax
jne SHORT $LN2@initGeneri
; 96 : }
mov DWORD PTR [ecx], OFFSET _xmlGenericErrorDefaultFunc
pop ebp
ret 0
$LN2@initGeneri:
; 92 : if (handler == NULL)
; 93 : xmlGenericError = xmlGenericErrorDefaultFunc;
; 94 : else
; 95 : xmlGenericError = (*handler);
mov eax, DWORD PTR [eax]
; 96 : }
mov DWORD PTR [ecx], eax
pop ebp
ret 0
_initGenericErrorDefaultFunc ENDP
_TEXT ENDS
; Function compile flags: /Ogtp
; File c:\users\dag\documents\_clients\codeproject authors group\windows on arm\libxml2\libxml2-2.9.9\error.c
; COMDAT _xmlSetGenericErrorFunc
_TEXT SEGMENT
_ctx$ = 8 ; size = 4
_handler$ = 12 ; size = 4
_xmlSetGenericErrorFunc PROC ; COMDAT
; 113 : xmlSetGenericErrorFunc(void *ctx, xmlGenericErrorFunc handler) {
push ebp
mov ebp, esp
push esi
mov esi, DWORD PTR _handler$[ebp]
mov ecx, OFFSET __67926DEE_error@c
call @__CheckForDebuggerJustMyCode@4
call ___xmlGenericErrorContext
mov ecx, DWORD PTR _ctx$[ebp]
mov DWORD PTR [eax], ecx
call ___xmlGenericError
test esi, esi
mov ecx, OFFSET _xmlGenericErrorDefaultFunc
cmove esi, ecx
mov DWORD PTR [eax], esi
pop esi
; 114 : xmlGenericErrorContext = ctx;
; 115 : if (handler != NULL)
; 116 : xmlGenericError = handler;
; 117 : else
; 118 : xmlGenericError = xmlGenericErrorDefaultFunc;
; 119 : }
pop ebp
ret 0
_xmlSetGenericErrorFunc ENDP
_TEXT ENDS
; Function compile flags: /Ogtp
; File c:\program files (x86)\windows kits\10\include\10.0.17763.0\ucrt\stdio.h
; COMDAT _vsnprintf
_TEXT SEGMENT
__Buffer$ = 8 ; size = 4
__BufferCount$ = 12 ; size = 4
__Format$ = 16 ; size = 4
__ArgList$ = 20 ; size = 4
_vsnprintf PROC ; COMDAT
; 1439 : {
push ebp
mov ebp, esp
mov ecx, OFFSET __A452D4A0_stdio@h
call @__CheckForDebuggerJustMyCode@4
call ___local_stdio_printf_options
push DWORD PTR __ArgList$[ebp]
mov ecx, eax
push 0
push DWORD PTR __Format$[ebp]
push DWORD PTR __BufferCount$[ebp]
mov eax, DWORD PTR [ecx]
push DWORD PTR __Buffer$[ebp]
or eax, 2
push DWORD PTR [ecx+4]
push eax
call DWORD PTR __imp____stdio_common_vsprintf
or ecx, -1
add esp, 28 ; 0000001cH
test eax, eax
cmovs eax, ecx
; 1440 : int const _Result = __stdio_common_vsprintf(
; 1441 : _CRT_INTERNAL_LOCAL_PRINTF_OPTIONS | _CRT_INTERNAL_PRINTF_STANDARD_SNPRINTF_BEHAVIOR,
; 1442 : _Buffer, _BufferCount, _Format, NULL, _ArgList);
; 1443 :
; 1444 : return _Result < 0 ? -1 : _Result;
; 1445 : }
pop ebp
ret 0
_vsnprintf ENDP
_TEXT ENDS
; Function compile flags: /Ogtp
; File c:\program files (x86)\windows kits\10\include\10.0.17763.0\ucrt\stdio.h
; COMDAT _fprintf
_TEXT SEGMENT
__Stream$ = 8 ; size = 4
__Format$ = 12 ; size = 4
_fprintf PROC ; COMDAT
; 835 : {
push ebp
mov ebp, esp
push esi
mov ecx, OFFSET __A452D4A0_stdio@h
call @__CheckForDebuggerJustMyCode@4
mov esi, DWORD PTR __Format$[ebp]
; 643 : return __stdio_common_vfprintf(_CRT_INTERNAL_LOCAL_PRINTF_OPTIONS, _Stream, _Format, _Locale, _ArgList);
call ___local_stdio_printf_options
lea ecx, DWORD PTR __Format$[ebp+4]
push ecx
push 0
push esi
push DWORD PTR __Stream$[ebp]
push DWORD PTR [eax+4]
push DWORD PTR [eax]
call DWORD PTR __imp____stdio_common_vfprintf
add esp, 24 ; 00000018H
; 836 : int _Result;
; 837 : va_list _ArgList;
; 838 : __crt_va_start(_ArgList, _Format);
; 839 : _Result = _vfprintf_l(_Stream, _Format, NULL, _ArgList);
; 840 : __crt_va_end(_ArgList);
; 841 : return _Result;
pop esi
; 842 : }
pop ebp
ret 0
_fprintf ENDP
_TEXT ENDS
; Function compile flags: /Ogtp
; File c:\program files (x86)\windows kits\10\include\10.0.17763.0\ucrt\stdio.h
; COMDAT _vfprintf
_TEXT SEGMENT
__Stream$ = 8 ; size = 4
__Format$ = 12 ; size = 4
__ArgList$ = 16 ; size = 4
_vfprintf PROC ; COMDAT
; 656 : {
push ebp
mov ebp, esp
mov ecx, OFFSET __A452D4A0_stdio@h
call @__CheckForDebuggerJustMyCode@4
; 643 : return __stdio_common_vfprintf(_CRT_INTERNAL_LOCAL_PRINTF_OPTIONS, _Stream, _Format, _Locale, _ArgList);
call ___local_stdio_printf_options
push DWORD PTR __ArgList$[ebp]
push 0
push DWORD PTR __Format$[ebp]
push DWORD PTR __Stream$[ebp]
push DWORD PTR [eax+4]
push DWORD PTR [eax]
call DWORD PTR __imp____stdio_common_vfprintf
add esp, 24 ; 00000018H
; 657 : return _vfprintf_l(_Stream, _Format, NULL, _ArgList);
; 658 : }
pop ebp
ret 0
_vfprintf ENDP
_TEXT ENDS
; Function compile flags: /Ogtp
; File c:\program files (x86)\windows kits\10\include\10.0.17763.0\ucrt\stdio.h
; COMDAT __vfprintf_l
_TEXT SEGMENT
__Stream$ = 8 ; size = 4
__Format$ = 12 ; size = 4
__Locale$ = 16 ; size = 4
__ArgList$ = 20 ; size = 4
__vfprintf_l PROC ; COMDAT
; 642 : {
push ebp
mov ebp, esp
mov ecx, OFFSET __A452D4A0_stdio@h
call @__CheckForDebuggerJustMyCode@4
call ___local_stdio_printf_options
push DWORD PTR __ArgList$[ebp]
push DWORD PTR __Locale$[ebp]
push DWORD PTR __Format$[ebp]
push DWORD PTR __Stream$[ebp]
push DWORD PTR [eax+4]
push DWORD PTR [eax]
call DWORD PTR __imp____stdio_common_vfprintf
add esp, 24 ; 00000018H
; 643 : return __stdio_common_vfprintf(_CRT_INTERNAL_LOCAL_PRINTF_OPTIONS, _Stream, _Format, _Locale, _ArgList);
; 644 : }
pop ebp
ret 0
__vfprintf_l ENDP
_TEXT ENDS
; Function compile flags: /Ogtp
; File c:\program files (x86)\windows kits\10\include\10.0.17763.0\ucrt\corecrt_stdio_config.h
; COMDAT ___local_stdio_printf_options
_TEXT SEGMENT
___local_stdio_printf_options PROC ; COMDAT
mov ecx, OFFSET __2CC6E67D_corecrt_stdio_config@h
call @__CheckForDebuggerJustMyCode@4
mov eax, OFFSET ?_OptionsStorage@?1??__local_stdio_printf_options@@9@9 ; `__local_stdio_printf_options'::`2'::_OptionsStorage
ret 0
___local_stdio_printf_options ENDP
_TEXT ENDS
END
|
// ===========================================================================
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
// SineAndGraphics Example for Kick Assembler adapted for k64ass
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
//--------------------------------------------
// Functions for calculating vic values and other stuff
// (normally we would put these in a library)
def screenToD018(addr) { // <- This is how we define a function
eval ((addr&$3fff)/$400)<<4
}
def charsetToD018(addr) {
eval ((addr&$3fff)/$800)<<1
}
def toD018(screen, charset) {
eval screenToD018(screen) | charsetToD018(charset) //<- This is how we call functions
}
def toSpritePtr(addr) {
eval (addr&$3fff)/$40
}
def sinus(i, amplitude, center, noOfSteps) {
eval round(center+amplitude*sin(rad(i*360/noOfSteps)))
}
//--------------------------------------------
BasicUpstart($2000,"Program")
start: sei
// Print chars to screen
ldx #0
lda #5
loop0: sta screen,x // <- '!' in front of a label means a multilabel (You can have several labels with the same name)
sta screen+$100,x
sta screen+$200,x
sta screen+$300,x
sec
sbc #1
bcs over // <- Referencing forward to the nearest a multilabel called 'over'
lda #5
over:
inx
bne loop0 // <- Referencing backward to the nearest multilabel called 'loop'
lda #toD018(screen, charset) // <- The d018 value is calculated by a function. You can move graphics around and not worry about d018 is properly set
sta $d018
// Setup some sprites
lda #$0f
sta $d015
ldx #7
loop: lda spritePtrs,x
sta screen+$3f8,x
txa
lsr
sta $d027,x
dex
bpl loop
// Make an effect loop with nonsense sprite movement
ldx #0
ldy #$0
loop1: lda $d012 // Wait for frame
cmp #$ff
bne loop1
lda sinus,x // Set sprite 1
sta $d000
lda sinus+$40,x
sta $d001
lda sinus,x // Set sprite 2
sta $d002
lda sinus+$30,y
sta $d003
lda #$f0 // Set sprite 3
sta $d004
lda sinus,y
sta $d005
lda sinus+$70,x // Set sprite 4
sta $d006
lda sinus,y
sta $d007
inx
iny
iny
iny
jmp loop1
//--------------------------------------------
spritePtrs: .byte toSpritePtr(sprite1), toSpritePtr(sprite2) // <- The spritePtr function is use to calculate the spritePtr
.byte toSpritePtr(sprite1), toSpritePtr(sprite2)
.byte 0,0,0,0
sinus: .byte [i <- [0 .. $100] || round($a0+$40*sin(rad(i*360/$100))) ]
// The number of bytes to fill and an expression to execute for each
// byte. 'i' is the byte number
.byte [i <- [0 .. $100] || sinus(i, $40, $a0, $100) ]
//--------------------------------------------
.align $0800 // <-- You can use align to align data to memory boundaries
charset: .byte %11111110
.byte %10000010
.byte %10000010
.byte %10000010
.byte %10000010
.byte %10000010
.byte %11111110
.byte %00000000
.byte %00000000
.byte %01111100
.byte %01000100
.byte %01000100
.byte %01000100
.byte %01111100
.byte %00000000
.byte %00000000
.byte %00000000
.byte %00000000
.byte %00111000
.byte %00101000
.byte %00111000
.byte %00000000
.byte %00000000
.byte %00000000
.byte %00000000
.byte %00000000
.byte %00000000
.byte %00010000
.byte %00000000
.byte %00000000
.byte %00000000
.byte %00000000
.byte %00000000
.byte %00000000
.byte %00000000
.byte %00000000
.byte %00000000
.byte %00000000
.byte %00000000
.byte %00000000
.byte %00000000
.byte %00000000
.byte %00000000
.byte %00000000
.byte %00000000
.byte %00000000
.byte %00000000
.byte %00000000
//--------------------------------------------
.align $40
sprite1: .byte %00000000, %11111111, %00000000
.byte %00000001, %11111111, %10000000
.byte %00000011, %11111111, %11000000
.byte %00000111, %11111111, %11100000
.byte %00001111, %11111111, %11110000
.byte %00011111, %11111111, %11111000
.byte %00111111, %11111111, %11111100
.byte %00000011, %11111111, %11000000
.byte %00000000, %00000000, %00000000
.byte %00000000, %00000000, %00000000
.byte %00000000, %00000000, %00000000
.byte %00000000, %00000000, %00000000
.byte %00000000, %00000000, %00000000
.byte %00000000, %00000000, %00000000
.byte %00000000, %00000000, %00000000
.byte %00000000, %00000000, %00000000
.byte %00000000, %00000000, %00000000
.byte %00000000, %00000000, %00000000
.byte %00000000, %00000000, %00000000
.byte %00000000, %00000000, %00000000
.byte %00000000, %00000000, %00000000
.byte $00
sprite2: .byte %01110000, %00000000, %00000000
.byte %11111000, %00000000, %00000000
.byte %11111000, %00000000, %00000000
.byte %01110000, %00000000, %00000000
.byte %00000000, %00000000, %00000000
.byte %00000000, %00000000, %00000000
.byte %00000000, %00000000, %00000000
.byte %00000000, %00000000, %00000000
.byte %00000000, %00000000, %00000000
.byte %00000000, %00000000, %00000000
.byte %00000000, %00000000, %00000000
.byte %00000000, %00000000, %00000000
.byte %00000000, %00000000, %00000000
.byte %00000000, %00000000, %00000000
.byte %00000000, %00000000, %00000000
.byte %00000000, %00000000, %00000000
.byte %00000000, %00000000, %00000000
.byte %00000000, %00000000, %00000000
.byte %00000000, %00000000, %00000000
.byte %00000000, %00000000, %00000000
.byte %00000000, %00000000, %00000000
.byte $00
//--------------------------------------------
* = $3c00 virtual "Virtual data" // <- Data in a virtual block is not entered into memory
screen: .fill $400,0
|
; A036085: Centered cube numbers: (n+1)^7 + n^7.
; 1,129,2315,18571,94509,358061,1103479,2920695,6880121,14782969,29487171,55318979,98580325,168162021,276272879,439294831,678774129,1022558705,1506091771,2173871739,3081088541,4295446429,5899183335,7991296871,10689987049,14135325801,18492163379,23953281715,30742804821,39119876309,49382614111,61872352479,76978181345,95141793121,116862647019,142703460971,173296041229,209347459725,251646589271,301071006679,358594273881,425293607129,502357944355,591096420771,692947262789,809487110341,942440777679
mov $1,$0
pow $0,7
add $1,1
pow $1,7
add $0,$1
mul $0,2
div $0,4
mul $0,2
add $0,1
|
%define ARCH_ARM 0
%define ARCH_MIPS 0
%define ARCH_X86 1
%define ARCH_X86_64 0
%define HAVE_EDSP 0
%define HAVE_MEDIA 0
%define HAVE_NEON 0
%define HAVE_NEON_ASM 0
%define HAVE_MIPS32 0
%define HAVE_DSPR2 0
%define HAVE_MSA 0
%define HAVE_MIPS64 0
%define HAVE_MMX 1
%define HAVE_SSE 1
%define HAVE_SSE2 1
%define HAVE_SSE3 1
%define HAVE_SSSE3 1
%define HAVE_SSE4_1 1
%define HAVE_AVX 1
%define HAVE_AVX2 1
%define HAVE_VPX_PORTS 1
%define HAVE_PTHREAD_H 0
%define HAVE_UNISTD_H 0
%define CONFIG_DEPENDENCY_TRACKING 1
%define CONFIG_EXTERNAL_BUILD 1
%define CONFIG_INSTALL_DOCS 0
%define CONFIG_INSTALL_BINS 1
%define CONFIG_INSTALL_LIBS 1
%define CONFIG_INSTALL_SRCS 0
%define CONFIG_USE_X86INC 1
%define CONFIG_DEBUG 0
%define CONFIG_GPROF 0
%define CONFIG_GCOV 0
%define CONFIG_RVCT 0
%define CONFIG_GCC 0
%define CONFIG_MSVS 1
%define CONFIG_PIC 0
%define CONFIG_BIG_ENDIAN 0
%define CONFIG_CODEC_SRCS 0
%define CONFIG_DEBUG_LIBS 0
%define CONFIG_DEQUANT_TOKENS 0
%define CONFIG_DC_RECON 0
%define CONFIG_RUNTIME_CPU_DETECT 1
%define CONFIG_POSTPROC 1
%define CONFIG_VP9_POSTPROC 1
%define CONFIG_MULTITHREAD 1
%define CONFIG_INTERNAL_STATS 0
%define CONFIG_VP8_ENCODER 1
%define CONFIG_VP8_DECODER 1
%define CONFIG_VP9_ENCODER 1
%define CONFIG_VP9_DECODER 1
%define CONFIG_VP10_ENCODER 0
%define CONFIG_VP10_DECODER 0
%define CONFIG_VP8 1
%define CONFIG_VP9 1
%define CONFIG_VP10 0
%define CONFIG_ENCODERS 1
%define CONFIG_DECODERS 1
%define CONFIG_STATIC_MSVCRT 0
%define CONFIG_SPATIAL_RESAMPLING 1
%define CONFIG_REALTIME_ONLY 1
%define CONFIG_ONTHEFLY_BITPACKING 0
%define CONFIG_ERROR_CONCEALMENT 0
%define CONFIG_SHARED 0
%define CONFIG_STATIC 1
%define CONFIG_SMALL 0
%define CONFIG_POSTPROC_VISUALIZER 0
%define CONFIG_OS_SUPPORT 1
%define CONFIG_UNIT_TESTS 0
%define CONFIG_WEBM_IO 1
%define CONFIG_LIBYUV 1
%define CONFIG_DECODE_PERF_TESTS 0
%define CONFIG_ENCODE_PERF_TESTS 0
%define CONFIG_MULTI_RES_ENCODING 1
%define CONFIG_TEMPORAL_DENOISING 1
%define CONFIG_VP9_TEMPORAL_DENOISING 1
%define CONFIG_COEFFICIENT_RANGE_CHECKING 0
%define CONFIG_VP9_HIGHBITDEPTH 0
%define CONFIG_BETTER_HW_COMPATIBILITY 0
%define CONFIG_EXPERIMENTAL 0
%define CONFIG_SIZE_LIMIT 1
%define CONFIG_SPATIAL_SVC 0
%define CONFIG_FP_MB_STATS 0
%define CONFIG_EMULATE_HARDWARE 0
%define CONFIG_MISC_FIXES 0
%define DECODE_WIDTH_LIMIT 16384
%define DECODE_HEIGHT_LIMIT 16384
|
namespace Heuristics {
struct BSMemory {
BSMemory(vector<uint8_t>& data, string location);
explicit operator bool() const;
auto manifest() const -> string;
private:
vector<uint8_t>& data;
string location;
};
BSMemory::BSMemory(vector<uint8_t>& data, string location) : data(data), location(location) {
}
BSMemory::operator bool() const {
return data.size() >= 0x8000;
}
auto BSMemory::manifest() const -> string {
if(!operator bool()) return {};
string output;
output.append("game\n");
output.append(" sha256: ", Hash::SHA256(data).digest(), "\n");
output.append(" label: ", Location::prefix(location), "\n");
output.append(" name: ", Location::prefix(location), "\n");
output.append(" board\n");
output.append(Memory{}.type("Flash").size(data.size()).content("Program").text());
return output;
}
}
|
.data
c: .float 4.20
d: .float 42.0
.text
main:
la $t0, c
l.s $f0, 0($t0)
la $t0, d
l.s $f1, 0($t0)
c.le.s $f0, $f1
bc1t branch
li $a0, 0
li $v0, 1
syscall
branch:
li $a0, 1
li $v0, 1
syscall |
// Copyright 2008, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Author: mheule@google.com (Markus Heule)
//
// Google C++ Testing Framework (Google Test)
//
// Sometimes it's desirable to build Google Test by compiling a single file.
// This file serves this purpose.
// This line ensures that gtest.h can be compiled on its own, even
// when it's fused.
#include "gtest/gtest.h"
// The following lines pull in the real gtest *.cc files.
// Copyright 2005, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Author: wan@google.com (Zhanyong Wan)
//
// The Google C++ Testing Framework (Google Test)
// Copyright 2007, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Author: wan@google.com (Zhanyong Wan)
//
// Utilities for testing Google Test itself and code that uses Google Test
// (e.g. frameworks built on top of Google Test).
#ifndef GTEST_INCLUDE_GTEST_GTEST_SPI_H_
#define GTEST_INCLUDE_GTEST_GTEST_SPI_H_
namespace testing {
// This helper class can be used to mock out Google Test failure reporting
// so that we can test Google Test or code that builds on Google Test.
//
// An object of this class appends a TestPartResult object to the
// TestPartResultArray object given in the constructor whenever a Google Test
// failure is reported. It can either intercept only failures that are
// generated in the same thread that created this object or it can intercept
// all generated failures. The scope of this mock object can be controlled with
// the second argument to the two arguments constructor.
class GTEST_API_ ScopedFakeTestPartResultReporter
: public TestPartResultReporterInterface {
public:
// The two possible mocking modes of this object.
enum InterceptMode {
INTERCEPT_ONLY_CURRENT_THREAD, // Intercepts only thread local failures.
INTERCEPT_ALL_THREADS // Intercepts all failures.
};
// The c'tor sets this object as the test part result reporter used
// by Google Test. The 'result' parameter specifies where to report the
// results. This reporter will only catch failures generated in the current
// thread. DEPRECATED
explicit ScopedFakeTestPartResultReporter(TestPartResultArray* result);
// Same as above, but you can choose the interception scope of this object.
ScopedFakeTestPartResultReporter(InterceptMode intercept_mode,
TestPartResultArray* result);
// The d'tor restores the previous test part result reporter.
virtual ~ScopedFakeTestPartResultReporter();
// Appends the TestPartResult object to the TestPartResultArray
// received in the constructor.
//
// This method is from the TestPartResultReporterInterface
// interface.
virtual void ReportTestPartResult(const TestPartResult& result);
private:
void Init();
const InterceptMode intercept_mode_;
TestPartResultReporterInterface* old_reporter_;
TestPartResultArray* const result_;
GTEST_DISALLOW_COPY_AND_ASSIGN_(ScopedFakeTestPartResultReporter);
};
namespace internal {
// A helper class for implementing EXPECT_FATAL_FAILURE() and
// EXPECT_NONFATAL_FAILURE(). Its destructor verifies that the given
// TestPartResultArray contains exactly one failure that has the given
// type and contains the given substring. If that's not the case, a
// non-fatal failure will be generated.
class GTEST_API_ SingleFailureChecker {
public:
// The constructor remembers the arguments.
SingleFailureChecker(const TestPartResultArray* results,
TestPartResult::Type type,
const string& substr);
~SingleFailureChecker();
private:
const TestPartResultArray* const results_;
const TestPartResult::Type type_;
const string substr_;
GTEST_DISALLOW_COPY_AND_ASSIGN_(SingleFailureChecker);
};
} // namespace internal
} // namespace testing
// A set of macros for testing Google Test assertions or code that's expected
// to generate Google Test fatal failures. It verifies that the given
// statement will cause exactly one fatal Google Test failure with 'substr'
// being part of the failure message.
//
// There are two different versions of this macro. EXPECT_FATAL_FAILURE only
// affects and considers failures generated in the current thread and
// EXPECT_FATAL_FAILURE_ON_ALL_THREADS does the same but for all threads.
//
// The verification of the assertion is done correctly even when the statement
// throws an exception or aborts the current function.
//
// Known restrictions:
// - 'statement' cannot reference local non-static variables or
// non-static members of the current object.
// - 'statement' cannot return a value.
// - You cannot stream a failure message to this macro.
//
// Note that even though the implementations of the following two
// macros are much alike, we cannot refactor them to use a common
// helper macro, due to some peculiarity in how the preprocessor
// works. The AcceptsMacroThatExpandsToUnprotectedComma test in
// gtest_unittest.cc will fail to compile if we do that.
#define EXPECT_FATAL_FAILURE(statement, substr) \
do { \
class GTestExpectFatalFailureHelper {\
public:\
static void Execute() { statement; }\
};\
::testing::TestPartResultArray gtest_failures;\
::testing::internal::SingleFailureChecker gtest_checker(\
>est_failures, ::testing::TestPartResult::kFatalFailure, (substr));\
{\
::testing::ScopedFakeTestPartResultReporter gtest_reporter(\
::testing::ScopedFakeTestPartResultReporter:: \
INTERCEPT_ONLY_CURRENT_THREAD, >est_failures);\
GTestExpectFatalFailureHelper::Execute();\
}\
} while (::testing::internal::AlwaysFalse())
#define EXPECT_FATAL_FAILURE_ON_ALL_THREADS(statement, substr) \
do { \
class GTestExpectFatalFailureHelper {\
public:\
static void Execute() { statement; }\
};\
::testing::TestPartResultArray gtest_failures;\
::testing::internal::SingleFailureChecker gtest_checker(\
>est_failures, ::testing::TestPartResult::kFatalFailure, (substr));\
{\
::testing::ScopedFakeTestPartResultReporter gtest_reporter(\
::testing::ScopedFakeTestPartResultReporter:: \
INTERCEPT_ALL_THREADS, >est_failures);\
GTestExpectFatalFailureHelper::Execute();\
}\
} while (::testing::internal::AlwaysFalse())
// A macro for testing Google Test assertions or code that's expected to
// generate Google Test non-fatal failures. It asserts that the given
// statement will cause exactly one non-fatal Google Test failure with 'substr'
// being part of the failure message.
//
// There are two different versions of this macro. EXPECT_NONFATAL_FAILURE only
// affects and considers failures generated in the current thread and
// EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS does the same but for all threads.
//
// 'statement' is allowed to reference local variables and members of
// the current object.
//
// The verification of the assertion is done correctly even when the statement
// throws an exception or aborts the current function.
//
// Known restrictions:
// - You cannot stream a failure message to this macro.
//
// Note that even though the implementations of the following two
// macros are much alike, we cannot refactor them to use a common
// helper macro, due to some peculiarity in how the preprocessor
// works. If we do that, the code won't compile when the user gives
// EXPECT_NONFATAL_FAILURE() a statement that contains a macro that
// expands to code containing an unprotected comma. The
// AcceptsMacroThatExpandsToUnprotectedComma test in gtest_unittest.cc
// catches that.
//
// For the same reason, we have to write
// if (::testing::internal::AlwaysTrue()) { statement; }
// instead of
// GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement)
// to avoid an MSVC warning on unreachable code.
#define EXPECT_NONFATAL_FAILURE(statement, substr) \
do {\
::testing::TestPartResultArray gtest_failures;\
::testing::internal::SingleFailureChecker gtest_checker(\
>est_failures, ::testing::TestPartResult::kNonFatalFailure, \
(substr));\
{\
::testing::ScopedFakeTestPartResultReporter gtest_reporter(\
::testing::ScopedFakeTestPartResultReporter:: \
INTERCEPT_ONLY_CURRENT_THREAD, >est_failures);\
if (::testing::internal::AlwaysTrue()) { statement; }\
}\
} while (::testing::internal::AlwaysFalse())
#define EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS(statement, substr) \
do {\
::testing::TestPartResultArray gtest_failures;\
::testing::internal::SingleFailureChecker gtest_checker(\
>est_failures, ::testing::TestPartResult::kNonFatalFailure, \
(substr));\
{\
::testing::ScopedFakeTestPartResultReporter gtest_reporter(\
::testing::ScopedFakeTestPartResultReporter::INTERCEPT_ALL_THREADS,\
>est_failures);\
if (::testing::internal::AlwaysTrue()) { statement; }\
}\
} while (::testing::internal::AlwaysFalse())
#endif // GTEST_INCLUDE_GTEST_GTEST_SPI_H_
#include <ctype.h>
#include <math.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <wchar.h>
#include <wctype.h>
#include <algorithm>
#include <ostream> // NOLINT
#include <sstream>
#include <vector>
#if GTEST_OS_LINUX
// TODO(kenton@google.com): Use autoconf to detect availability of
// gettimeofday().
# define GTEST_HAS_GETTIMEOFDAY_ 1
# include <fcntl.h> // NOLINT
# include <limits.h> // NOLINT
# include <sched.h> // NOLINT
// Declares vsnprintf(). This header is not available on Windows.
# include <strings.h> // NOLINT
# include <sys/mman.h> // NOLINT
# include <sys/time.h> // NOLINT
# include <unistd.h> // NOLINT
# include <string>
#elif GTEST_OS_SYMBIAN
# define GTEST_HAS_GETTIMEOFDAY_ 1
# include <sys/time.h> // NOLINT
#elif GTEST_OS_ZOS
# define GTEST_HAS_GETTIMEOFDAY_ 1
# include <sys/time.h> // NOLINT
// On z/OS we additionally need strings.h for strcasecmp.
# include <strings.h> // NOLINT
#elif GTEST_OS_WINDOWS_MOBILE // We are on Windows CE.
# include <windows.h> // NOLINT
#elif GTEST_OS_WINDOWS // We are on Windows proper.
# include <io.h> // NOLINT
# include <sys/timeb.h> // NOLINT
# include <sys/types.h> // NOLINT
# include <sys/stat.h> // NOLINT
# if GTEST_OS_WINDOWS_MINGW
// MinGW has gettimeofday() but not _ftime64().
// TODO(kenton@google.com): Use autoconf to detect availability of
// gettimeofday().
// TODO(kenton@google.com): There are other ways to get the time on
// Windows, like GetTickCount() or GetSystemTimeAsFileTime(). MinGW
// supports these. consider using them instead.
# define GTEST_HAS_GETTIMEOFDAY_ 1
# include <sys/time.h> // NOLINT
# endif // GTEST_OS_WINDOWS_MINGW
// cpplint thinks that the header is already included, so we want to
// silence it.
# include <windows.h> // NOLINT
#else
// Assume other platforms have gettimeofday().
// TODO(kenton@google.com): Use autoconf to detect availability of
// gettimeofday().
# define GTEST_HAS_GETTIMEOFDAY_ 1
// cpplint thinks that the header is already included, so we want to
// silence it.
# include <sys/time.h> // NOLINT
# include <unistd.h> // NOLINT
#endif // GTEST_OS_LINUX
#if GTEST_HAS_EXCEPTIONS
# include <stdexcept>
#endif
#if GTEST_CAN_STREAM_RESULTS_
# include <arpa/inet.h> // NOLINT
# include <netdb.h> // NOLINT
#endif
// Indicates that this translation unit is part of Google Test's
// implementation. It must come before gtest-internal-inl.h is
// included, or there will be a compiler error. This trick is to
// prevent a user from accidentally including gtest-internal-inl.h in
// his code.
#define GTEST_IMPLEMENTATION_ 1
// Copyright 2005, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Utility functions and classes used by the Google C++ testing framework.
//
// Author: wan@google.com (Zhanyong Wan)
//
// This file contains purely Google Test's internal implementation. Please
// DO NOT #INCLUDE IT IN A USER PROGRAM.
#ifndef GTEST_SRC_GTEST_INTERNAL_INL_H_
#define GTEST_SRC_GTEST_INTERNAL_INL_H_
// GTEST_IMPLEMENTATION_ is defined to 1 iff the current translation unit is
// part of Google Test's implementation; otherwise it's undefined.
#if !GTEST_IMPLEMENTATION_
// A user is trying to include this from his code - just say no.
# error "gtest-internal-inl.h is part of Google Test's internal implementation."
# error "It must not be included except by Google Test itself."
#endif // GTEST_IMPLEMENTATION_
#ifndef _WIN32_WCE
# include <errno.h>
#endif // !_WIN32_WCE
#include <stddef.h>
#include <stdlib.h> // For strtoll/_strtoul64/malloc/free.
#include <string.h> // For memmove.
#include <algorithm>
#include <string>
#include <vector>
#if GTEST_OS_WINDOWS
# include <windows.h> // NOLINT
#endif // GTEST_OS_WINDOWS
namespace testing {
// Declares the flags.
//
// We don't want the users to modify this flag in the code, but want
// Google Test's own unit tests to be able to access it. Therefore we
// declare it here as opposed to in gtest.h.
GTEST_DECLARE_bool_(death_test_use_fork);
namespace internal {
// The value of GetTestTypeId() as seen from within the Google Test
// library. This is solely for testing GetTestTypeId().
GTEST_API_ extern const TypeId kTestTypeIdInGoogleTest;
// Names of the flags (needed for parsing Google Test flags).
const char kAlsoRunDisabledTestsFlag[] = "also_run_disabled_tests";
const char kBreakOnFailureFlag[] = "break_on_failure";
const char kCatchExceptionsFlag[] = "catch_exceptions";
const char kColorFlag[] = "color";
const char kFilterFlag[] = "filter";
const char kListTestsFlag[] = "list_tests";
const char kOutputFlag[] = "output";
const char kPrintTimeFlag[] = "print_time";
const char kRandomSeedFlag[] = "random_seed";
const char kRepeatFlag[] = "repeat";
const char kShuffleFlag[] = "shuffle";
const char kStackTraceDepthFlag[] = "stack_trace_depth";
const char kStreamResultToFlag[] = "stream_result_to";
const char kThrowOnFailureFlag[] = "throw_on_failure";
// A valid random seed must be in [1, kMaxRandomSeed].
const int kMaxRandomSeed = 99999;
// g_help_flag is true iff the --help flag or an equivalent form is
// specified on the command line.
GTEST_API_ extern bool g_help_flag;
// Returns the current time in milliseconds.
GTEST_API_ TimeInMillis GetTimeInMillis();
// Returns true iff Google Test should use colors in the output.
GTEST_API_ bool ShouldUseColor(bool stdout_is_tty);
// Formats the given time in milliseconds as seconds.
GTEST_API_ std::string FormatTimeInMillisAsSeconds(TimeInMillis ms);
// Parses a string for an Int32 flag, in the form of "--flag=value".
//
// On success, stores the value of the flag in *value, and returns
// true. On failure, returns false without changing *value.
GTEST_API_ bool ParseInt32Flag(
const char* str, const char* flag, Int32* value);
// Returns a random seed in range [1, kMaxRandomSeed] based on the
// given --gtest_random_seed flag value.
inline int GetRandomSeedFromFlag(Int32 random_seed_flag) {
const unsigned int raw_seed = (random_seed_flag == 0) ?
static_cast<unsigned int>(GetTimeInMillis()) :
static_cast<unsigned int>(random_seed_flag);
// Normalizes the actual seed to range [1, kMaxRandomSeed] such that
// it's easy to type.
const int normalized_seed =
static_cast<int>((raw_seed - 1U) %
static_cast<unsigned int>(kMaxRandomSeed)) + 1;
return normalized_seed;
}
// Returns the first valid random seed after 'seed'. The behavior is
// undefined if 'seed' is invalid. The seed after kMaxRandomSeed is
// considered to be 1.
inline int GetNextRandomSeed(int seed) {
GTEST_CHECK_(1 <= seed && seed <= kMaxRandomSeed)
<< "Invalid random seed " << seed << " - must be in [1, "
<< kMaxRandomSeed << "].";
const int next_seed = seed + 1;
return (next_seed > kMaxRandomSeed) ? 1 : next_seed;
}
// This class saves the values of all Google Test flags in its c'tor, and
// restores them in its d'tor.
class GTestFlagSaver {
public:
// The c'tor.
GTestFlagSaver() {
also_run_disabled_tests_ = GTEST_FLAG(also_run_disabled_tests);
break_on_failure_ = GTEST_FLAG(break_on_failure);
catch_exceptions_ = GTEST_FLAG(catch_exceptions);
color_ = GTEST_FLAG(color);
death_test_style_ = GTEST_FLAG(death_test_style);
death_test_use_fork_ = GTEST_FLAG(death_test_use_fork);
filter_ = GTEST_FLAG(filter);
internal_run_death_test_ = GTEST_FLAG(internal_run_death_test);
list_tests_ = GTEST_FLAG(list_tests);
output_ = GTEST_FLAG(output);
print_time_ = GTEST_FLAG(print_time);
random_seed_ = GTEST_FLAG(random_seed);
repeat_ = GTEST_FLAG(repeat);
shuffle_ = GTEST_FLAG(shuffle);
stack_trace_depth_ = GTEST_FLAG(stack_trace_depth);
stream_result_to_ = GTEST_FLAG(stream_result_to);
throw_on_failure_ = GTEST_FLAG(throw_on_failure);
}
// The d'tor is not virtual. DO NOT INHERIT FROM THIS CLASS.
~GTestFlagSaver() {
GTEST_FLAG(also_run_disabled_tests) = also_run_disabled_tests_;
GTEST_FLAG(break_on_failure) = break_on_failure_;
GTEST_FLAG(catch_exceptions) = catch_exceptions_;
GTEST_FLAG(color) = color_;
GTEST_FLAG(death_test_style) = death_test_style_;
GTEST_FLAG(death_test_use_fork) = death_test_use_fork_;
GTEST_FLAG(filter) = filter_;
GTEST_FLAG(internal_run_death_test) = internal_run_death_test_;
GTEST_FLAG(list_tests) = list_tests_;
GTEST_FLAG(output) = output_;
GTEST_FLAG(print_time) = print_time_;
GTEST_FLAG(random_seed) = random_seed_;
GTEST_FLAG(repeat) = repeat_;
GTEST_FLAG(shuffle) = shuffle_;
GTEST_FLAG(stack_trace_depth) = stack_trace_depth_;
GTEST_FLAG(stream_result_to) = stream_result_to_;
GTEST_FLAG(throw_on_failure) = throw_on_failure_;
}
private:
// Fields for saving the original values of flags.
bool also_run_disabled_tests_;
bool break_on_failure_;
bool catch_exceptions_;
String color_;
String death_test_style_;
bool death_test_use_fork_;
String filter_;
String internal_run_death_test_;
bool list_tests_;
String output_;
bool print_time_;
internal::Int32 random_seed_;
internal::Int32 repeat_;
bool shuffle_;
internal::Int32 stack_trace_depth_;
String stream_result_to_;
bool throw_on_failure_;
} GTEST_ATTRIBUTE_UNUSED_;
// Converts a Unicode code point to a narrow string in UTF-8 encoding.
// code_point parameter is of type UInt32 because wchar_t may not be
// wide enough to contain a code point.
// The output buffer str must containt at least 32 characters.
// The function returns the address of the output buffer.
// If the code_point is not a valid Unicode code point
// (i.e. outside of Unicode range U+0 to U+10FFFF) it will be output
// as '(Invalid Unicode 0xXXXXXXXX)'.
GTEST_API_ char* CodePointToUtf8(UInt32 code_point, char* str);
// Converts a wide string to a narrow string in UTF-8 encoding.
// The wide string is assumed to have the following encoding:
// UTF-16 if sizeof(wchar_t) == 2 (on Windows, Cygwin, Symbian OS)
// UTF-32 if sizeof(wchar_t) == 4 (on Linux)
// Parameter str points to a null-terminated wide string.
// Parameter num_chars may additionally limit the number
// of wchar_t characters processed. -1 is used when the entire string
// should be processed.
// If the string contains code points that are not valid Unicode code points
// (i.e. outside of Unicode range U+0 to U+10FFFF) they will be output
// as '(Invalid Unicode 0xXXXXXXXX)'. If the string is in UTF16 encoding
// and contains invalid UTF-16 surrogate pairs, values in those pairs
// will be encoded as individual Unicode characters from Basic Normal Plane.
GTEST_API_ String WideStringToUtf8(const wchar_t* str, int num_chars);
// Reads the GTEST_SHARD_STATUS_FILE environment variable, and creates the file
// if the variable is present. If a file already exists at this location, this
// function will write over it. If the variable is present, but the file cannot
// be created, prints an error and exits.
void WriteToShardStatusFileIfNeeded();
// Checks whether sharding is enabled by examining the relevant
// environment variable values. If the variables are present,
// but inconsistent (e.g., shard_index >= total_shards), prints
// an error and exits. If in_subprocess_for_death_test, sharding is
// disabled because it must only be applied to the original test
// process. Otherwise, we could filter out death tests we intended to execute.
GTEST_API_ bool ShouldShard(const char* total_shards_str,
const char* shard_index_str,
bool in_subprocess_for_death_test);
// Parses the environment variable var as an Int32. If it is unset,
// returns default_val. If it is not an Int32, prints an error and
// and aborts.
GTEST_API_ Int32 Int32FromEnvOrDie(const char* env_var, Int32 default_val);
// Given the total number of shards, the shard index, and the test id,
// returns true iff the test should be run on this shard. The test id is
// some arbitrary but unique non-negative integer assigned to each test
// method. Assumes that 0 <= shard_index < total_shards.
GTEST_API_ bool ShouldRunTestOnShard(
int total_shards, int shard_index, int test_id);
// STL container utilities.
// Returns the number of elements in the given container that satisfy
// the given predicate.
template <class Container, typename Predicate>
inline int CountIf(const Container& c, Predicate predicate) {
// Implemented as an explicit loop since std::count_if() in libCstd on
// Solaris has a non-standard signature.
int count = 0;
for (typename Container::const_iterator it = c.begin(); it != c.end(); ++it) {
if (predicate(*it))
++count;
}
return count;
}
// Applies a function/functor to each element in the container.
template <class Container, typename Functor>
void ForEach(const Container& c, Functor functor) {
std::for_each(c.begin(), c.end(), functor);
}
// Returns the i-th element of the vector, or default_value if i is not
// in range [0, v.size()).
template <typename E>
inline E GetElementOr(const std::vector<E>& v, int i, E default_value) {
return (i < 0 || i >= static_cast<int>(v.size())) ? default_value : v[i];
}
// Performs an in-place shuffle of a range of the vector's elements.
// 'begin' and 'end' are element indices as an STL-style range;
// i.e. [begin, end) are shuffled, where 'end' == size() means to
// shuffle to the end of the vector.
template <typename E>
void ShuffleRange(internal::Random* random, int begin, int end,
std::vector<E>* v) {
const int size = static_cast<int>(v->size());
GTEST_CHECK_(0 <= begin && begin <= size)
<< "Invalid shuffle range start " << begin << ": must be in range [0, "
<< size << "].";
GTEST_CHECK_(begin <= end && end <= size)
<< "Invalid shuffle range finish " << end << ": must be in range ["
<< begin << ", " << size << "].";
// Fisher-Yates shuffle, from
// http://en.wikipedia.org/wiki/Fisher-Yates_shuffle
for (int range_width = end - begin; range_width >= 2; range_width--) {
const int last_in_range = begin + range_width - 1;
const int selected = begin + random->Generate(range_width);
std::swap((*v)[selected], (*v)[last_in_range]);
}
}
// Performs an in-place shuffle of the vector's elements.
template <typename E>
inline void Shuffle(internal::Random* random, std::vector<E>* v) {
ShuffleRange(random, 0, static_cast<int>(v->size()), v);
}
// A function for deleting an object. Handy for being used as a
// functor.
template <typename T>
static void Delete(T* x) {
delete x;
}
// A predicate that checks the key of a TestProperty against a known key.
//
// TestPropertyKeyIs is copyable.
class TestPropertyKeyIs {
public:
// Constructor.
//
// TestPropertyKeyIs has NO default constructor.
explicit TestPropertyKeyIs(const char* key)
: key_(key) {}
// Returns true iff the test name of test property matches on key_.
bool operator()(const TestProperty& test_property) const {
return String(test_property.key()).Compare(key_) == 0;
}
private:
String key_;
};
// Class UnitTestOptions.
//
// This class contains functions for processing options the user
// specifies when running the tests. It has only static members.
//
// In most cases, the user can specify an option using either an
// environment variable or a command line flag. E.g. you can set the
// test filter using either GTEST_FILTER or --gtest_filter. If both
// the variable and the flag are present, the latter overrides the
// former.
class GTEST_API_ UnitTestOptions {
public:
// Functions for processing the gtest_output flag.
// Returns the output format, or "" for normal printed output.
static String GetOutputFormat();
// Returns the absolute path of the requested output file, or the
// default (test_detail.xml in the original working directory) if
// none was explicitly specified.
static String GetAbsolutePathToOutputFile();
// Functions for processing the gtest_filter flag.
// Returns true iff the wildcard pattern matches the string. The
// first ':' or '\0' character in pattern marks the end of it.
//
// This recursive algorithm isn't very efficient, but is clear and
// works well enough for matching test names, which are short.
static bool PatternMatchesString(const char *pattern, const char *str);
// Returns true iff the user-specified filter matches the test case
// name and the test name.
static bool FilterMatchesTest(const String &test_case_name,
const String &test_name);
#if GTEST_OS_WINDOWS
// Function for supporting the gtest_catch_exception flag.
// Returns EXCEPTION_EXECUTE_HANDLER if Google Test should handle the
// given SEH exception, or EXCEPTION_CONTINUE_SEARCH otherwise.
// This function is useful as an __except condition.
static int GTestShouldProcessSEH(DWORD exception_code);
#endif // GTEST_OS_WINDOWS
// Returns true if "name" matches the ':' separated list of glob-style
// filters in "filter".
static bool MatchesFilter(const String& name, const char* filter);
};
// Returns the current application's name, removing directory path if that
// is present. Used by UnitTestOptions::GetOutputFile.
GTEST_API_ FilePath GetCurrentExecutableName();
// The role interface for getting the OS stack trace as a string.
class OsStackTraceGetterInterface {
public:
OsStackTraceGetterInterface() {}
virtual ~OsStackTraceGetterInterface() {}
// Returns the current OS stack trace as a String. Parameters:
//
// max_depth - the maximum number of stack frames to be included
// in the trace.
// skip_count - the number of top frames to be skipped; doesn't count
// against max_depth.
virtual String CurrentStackTrace(int max_depth, int skip_count) = 0;
// UponLeavingGTest() should be called immediately before Google Test calls
// user code. It saves some information about the current stack that
// CurrentStackTrace() will use to find and hide Google Test stack frames.
virtual void UponLeavingGTest() = 0;
private:
GTEST_DISALLOW_COPY_AND_ASSIGN_(OsStackTraceGetterInterface);
};
// A working implementation of the OsStackTraceGetterInterface interface.
class OsStackTraceGetter : public OsStackTraceGetterInterface {
public:
OsStackTraceGetter() : caller_frame_(NULL) {}
virtual String CurrentStackTrace(int max_depth, int skip_count);
virtual void UponLeavingGTest();
// This string is inserted in place of stack frames that are part of
// Google Test's implementation.
static const char* const kElidedFramesMarker;
private:
Mutex mutex_; // protects all internal state
// We save the stack frame below the frame that calls user code.
// We do this because the address of the frame immediately below
// the user code changes between the call to UponLeavingGTest()
// and any calls to CurrentStackTrace() from within the user code.
void* caller_frame_;
GTEST_DISALLOW_COPY_AND_ASSIGN_(OsStackTraceGetter);
};
// Information about a Google Test trace point.
struct TraceInfo {
const char* file;
int line;
String message;
};
// This is the default global test part result reporter used in UnitTestImpl.
// This class should only be used by UnitTestImpl.
class DefaultGlobalTestPartResultReporter
: public TestPartResultReporterInterface {
public:
explicit DefaultGlobalTestPartResultReporter(UnitTestImpl* unit_test);
// Implements the TestPartResultReporterInterface. Reports the test part
// result in the current test.
virtual void ReportTestPartResult(const TestPartResult& result);
private:
UnitTestImpl* const unit_test_;
GTEST_DISALLOW_COPY_AND_ASSIGN_(DefaultGlobalTestPartResultReporter);
};
// This is the default per thread test part result reporter used in
// UnitTestImpl. This class should only be used by UnitTestImpl.
class DefaultPerThreadTestPartResultReporter
: public TestPartResultReporterInterface {
public:
explicit DefaultPerThreadTestPartResultReporter(UnitTestImpl* unit_test);
// Implements the TestPartResultReporterInterface. The implementation just
// delegates to the current global test part result reporter of *unit_test_.
virtual void ReportTestPartResult(const TestPartResult& result);
private:
UnitTestImpl* const unit_test_;
GTEST_DISALLOW_COPY_AND_ASSIGN_(DefaultPerThreadTestPartResultReporter);
};
// The private implementation of the UnitTest class. We don't protect
// the methods under a mutex, as this class is not accessible by a
// user and the UnitTest class that delegates work to this class does
// proper locking.
class GTEST_API_ UnitTestImpl {
public:
explicit UnitTestImpl(UnitTest* parent);
virtual ~UnitTestImpl();
// There are two different ways to register your own TestPartResultReporter.
// You can register your own repoter to listen either only for test results
// from the current thread or for results from all threads.
// By default, each per-thread test result repoter just passes a new
// TestPartResult to the global test result reporter, which registers the
// test part result for the currently running test.
// Returns the global test part result reporter.
TestPartResultReporterInterface* GetGlobalTestPartResultReporter();
// Sets the global test part result reporter.
void SetGlobalTestPartResultReporter(
TestPartResultReporterInterface* reporter);
// Returns the test part result reporter for the current thread.
TestPartResultReporterInterface* GetTestPartResultReporterForCurrentThread();
// Sets the test part result reporter for the current thread.
void SetTestPartResultReporterForCurrentThread(
TestPartResultReporterInterface* reporter);
// Gets the number of successful test cases.
int successful_test_case_count() const;
// Gets the number of failed test cases.
int failed_test_case_count() const;
// Gets the number of all test cases.
int total_test_case_count() const;
// Gets the number of all test cases that contain at least one test
// that should run.
int test_case_to_run_count() const;
// Gets the number of successful tests.
int successful_test_count() const;
// Gets the number of failed tests.
int failed_test_count() const;
// Gets the number of disabled tests.
int disabled_test_count() const;
// Gets the number of all tests.
int total_test_count() const;
// Gets the number of tests that should run.
int test_to_run_count() const;
// Gets the elapsed time, in milliseconds.
TimeInMillis elapsed_time() const { return elapsed_time_; }
// Returns true iff the unit test passed (i.e. all test cases passed).
bool Passed() const { return !Failed(); }
// Returns true iff the unit test failed (i.e. some test case failed
// or something outside of all tests failed).
bool Failed() const {
return failed_test_case_count() > 0 || ad_hoc_test_result()->Failed();
}
// Gets the i-th test case among all the test cases. i can range from 0 to
// total_test_case_count() - 1. If i is not in that range, returns NULL.
const TestCase* GetTestCase(int i) const {
const int index = GetElementOr(test_case_indices_, i, -1);
return index < 0 ? NULL : test_cases_[i];
}
// Gets the i-th test case among all the test cases. i can range from 0 to
// total_test_case_count() - 1. If i is not in that range, returns NULL.
TestCase* GetMutableTestCase(int i) {
const int index = GetElementOr(test_case_indices_, i, -1);
return index < 0 ? NULL : test_cases_[index];
}
// Provides access to the event listener list.
TestEventListeners* listeners() { return &listeners_; }
// Returns the TestResult for the test that's currently running, or
// the TestResult for the ad hoc test if no test is running.
TestResult* current_test_result();
// Returns the TestResult for the ad hoc test.
const TestResult* ad_hoc_test_result() const { return &ad_hoc_test_result_; }
// Sets the OS stack trace getter.
//
// Does nothing if the input and the current OS stack trace getter
// are the same; otherwise, deletes the old getter and makes the
// input the current getter.
void set_os_stack_trace_getter(OsStackTraceGetterInterface* getter);
// Returns the current OS stack trace getter if it is not NULL;
// otherwise, creates an OsStackTraceGetter, makes it the current
// getter, and returns it.
OsStackTraceGetterInterface* os_stack_trace_getter();
// Returns the current OS stack trace as a String.
//
// The maximum number of stack frames to be included is specified by
// the gtest_stack_trace_depth flag. The skip_count parameter
// specifies the number of top frames to be skipped, which doesn't
// count against the number of frames to be included.
//
// For example, if Foo() calls Bar(), which in turn calls
// CurrentOsStackTraceExceptTop(1), Foo() will be included in the
// trace but Bar() and CurrentOsStackTraceExceptTop() won't.
String CurrentOsStackTraceExceptTop(int skip_count);
// Finds and returns a TestCase with the given name. If one doesn't
// exist, creates one and returns it.
//
// Arguments:
//
// test_case_name: name of the test case
// type_param: the name of the test's type parameter, or NULL if
// this is not a typed or a type-parameterized test.
// set_up_tc: pointer to the function that sets up the test case
// tear_down_tc: pointer to the function that tears down the test case
TestCase* GetTestCase(const char* test_case_name,
const char* type_param,
Test::SetUpTestCaseFunc set_up_tc,
Test::TearDownTestCaseFunc tear_down_tc);
// Adds a TestInfo to the unit test.
//
// Arguments:
//
// set_up_tc: pointer to the function that sets up the test case
// tear_down_tc: pointer to the function that tears down the test case
// test_info: the TestInfo object
void AddTestInfo(Test::SetUpTestCaseFunc set_up_tc,
Test::TearDownTestCaseFunc tear_down_tc,
TestInfo* test_info) {
// In order to support thread-safe death tests, we need to
// remember the original working directory when the test program
// was first invoked. We cannot do this in RUN_ALL_TESTS(), as
// the user may have changed the current directory before calling
// RUN_ALL_TESTS(). Therefore we capture the current directory in
// AddTestInfo(), which is called to register a TEST or TEST_F
// before main() is reached.
if (original_working_dir_.IsEmpty()) {
original_working_dir_.Set(FilePath::GetCurrentDir());
GTEST_CHECK_(!original_working_dir_.IsEmpty())
<< "Failed to get the current working directory.";
}
GetTestCase(test_info->test_case_name(),
test_info->type_param(),
set_up_tc,
tear_down_tc)->AddTestInfo(test_info);
}
#if GTEST_HAS_PARAM_TEST
// Returns ParameterizedTestCaseRegistry object used to keep track of
// value-parameterized tests and instantiate and register them.
internal::ParameterizedTestCaseRegistry& parameterized_test_registry() {
return parameterized_test_registry_;
}
#endif // GTEST_HAS_PARAM_TEST
// Sets the TestCase object for the test that's currently running.
void set_current_test_case(TestCase* a_current_test_case) {
current_test_case_ = a_current_test_case;
}
// Sets the TestInfo object for the test that's currently running. If
// current_test_info is NULL, the assertion results will be stored in
// ad_hoc_test_result_.
void set_current_test_info(TestInfo* a_current_test_info) {
current_test_info_ = a_current_test_info;
}
// Registers all parameterized tests defined using TEST_P and
// INSTANTIATE_TEST_CASE_P, creating regular tests for each test/parameter
// combination. This method can be called more then once; it has guards
// protecting from registering the tests more then once. If
// value-parameterized tests are disabled, RegisterParameterizedTests is
// present but does nothing.
void RegisterParameterizedTests();
// Runs all tests in this UnitTest object, prints the result, and
// returns true if all tests are successful. If any exception is
// thrown during a test, this test is considered to be failed, but
// the rest of the tests will still be run.
bool RunAllTests();
// Clears the results of all tests, except the ad hoc tests.
void ClearNonAdHocTestResult() {
ForEach(test_cases_, TestCase::ClearTestCaseResult);
}
// Clears the results of ad-hoc test assertions.
void ClearAdHocTestResult() {
ad_hoc_test_result_.Clear();
}
enum ReactionToSharding {
HONOR_SHARDING_PROTOCOL,
IGNORE_SHARDING_PROTOCOL
};
// Matches the full name of each test against the user-specified
// filter to decide whether the test should run, then records the
// result in each TestCase and TestInfo object.
// If shard_tests == HONOR_SHARDING_PROTOCOL, further filters tests
// based on sharding variables in the environment.
// Returns the number of tests that should run.
int FilterTests(ReactionToSharding shard_tests);
// Prints the names of the tests matching the user-specified filter flag.
void ListTestsMatchingFilter();
const TestCase* current_test_case() const { return current_test_case_; }
TestInfo* current_test_info() { return current_test_info_; }
const TestInfo* current_test_info() const { return current_test_info_; }
// Returns the vector of environments that need to be set-up/torn-down
// before/after the tests are run.
std::vector<Environment*>& environments() { return environments_; }
// Getters for the per-thread Google Test trace stack.
std::vector<TraceInfo>& gtest_trace_stack() {
return *(gtest_trace_stack_.pointer());
}
const std::vector<TraceInfo>& gtest_trace_stack() const {
return gtest_trace_stack_.get();
}
#if GTEST_HAS_DEATH_TEST
void InitDeathTestSubprocessControlInfo() {
internal_run_death_test_flag_.reset(ParseInternalRunDeathTestFlag());
}
// Returns a pointer to the parsed --gtest_internal_run_death_test
// flag, or NULL if that flag was not specified.
// This information is useful only in a death test child process.
// Must not be called before a call to InitGoogleTest.
const InternalRunDeathTestFlag* internal_run_death_test_flag() const {
return internal_run_death_test_flag_.get();
}
// Returns a pointer to the current death test factory.
internal::DeathTestFactory* death_test_factory() {
return death_test_factory_.get();
}
void SuppressTestEventsIfInSubprocess();
friend class ReplaceDeathTestFactory;
#endif // GTEST_HAS_DEATH_TEST
// Initializes the event listener performing XML output as specified by
// UnitTestOptions. Must not be called before InitGoogleTest.
void ConfigureXmlOutput();
#if GTEST_CAN_STREAM_RESULTS_
// Initializes the event listener for streaming test results to a socket.
// Must not be called before InitGoogleTest.
void ConfigureStreamingOutput();
#endif
// Performs initialization dependent upon flag values obtained in
// ParseGoogleTestFlagsOnly. Is called from InitGoogleTest after the call to
// ParseGoogleTestFlagsOnly. In case a user neglects to call InitGoogleTest
// this function is also called from RunAllTests. Since this function can be
// called more than once, it has to be idempotent.
void PostFlagParsingInit();
// Gets the random seed used at the start of the current test iteration.
int random_seed() const { return random_seed_; }
// Gets the random number generator.
internal::Random* random() { return &random_; }
// Shuffles all test cases, and the tests within each test case,
// making sure that death tests are still run first.
void ShuffleTests();
// Restores the test cases and tests to their order before the first shuffle.
void UnshuffleTests();
// Returns the value of GTEST_FLAG(catch_exceptions) at the moment
// UnitTest::Run() starts.
bool catch_exceptions() const { return catch_exceptions_; }
private:
friend class ::testing::UnitTest;
// Used by UnitTest::Run() to capture the state of
// GTEST_FLAG(catch_exceptions) at the moment it starts.
void set_catch_exceptions(bool value) { catch_exceptions_ = value; }
// The UnitTest object that owns this implementation object.
UnitTest* const parent_;
// The working directory when the first TEST() or TEST_F() was
// executed.
internal::FilePath original_working_dir_;
// The default test part result reporters.
DefaultGlobalTestPartResultReporter default_global_test_part_result_reporter_;
DefaultPerThreadTestPartResultReporter
default_per_thread_test_part_result_reporter_;
// Points to (but doesn't own) the global test part result reporter.
TestPartResultReporterInterface* global_test_part_result_repoter_;
// Protects read and write access to global_test_part_result_reporter_.
internal::Mutex global_test_part_result_reporter_mutex_;
// Points to (but doesn't own) the per-thread test part result reporter.
internal::ThreadLocal<TestPartResultReporterInterface*>
per_thread_test_part_result_reporter_;
// The vector of environments that need to be set-up/torn-down
// before/after the tests are run.
std::vector<Environment*> environments_;
// The vector of TestCases in their original order. It owns the
// elements in the vector.
std::vector<TestCase*> test_cases_;
// Provides a level of indirection for the test case list to allow
// easy shuffling and restoring the test case order. The i-th
// element of this vector is the index of the i-th test case in the
// shuffled order.
std::vector<int> test_case_indices_;
#if GTEST_HAS_PARAM_TEST
// ParameterizedTestRegistry object used to register value-parameterized
// tests.
internal::ParameterizedTestCaseRegistry parameterized_test_registry_;
// Indicates whether RegisterParameterizedTests() has been called already.
bool parameterized_tests_registered_;
#endif // GTEST_HAS_PARAM_TEST
// Index of the last death test case registered. Initially -1.
int last_death_test_case_;
// This points to the TestCase for the currently running test. It
// changes as Google Test goes through one test case after another.
// When no test is running, this is set to NULL and Google Test
// stores assertion results in ad_hoc_test_result_. Initially NULL.
TestCase* current_test_case_;
// This points to the TestInfo for the currently running test. It
// changes as Google Test goes through one test after another. When
// no test is running, this is set to NULL and Google Test stores
// assertion results in ad_hoc_test_result_. Initially NULL.
TestInfo* current_test_info_;
// Normally, a user only writes assertions inside a TEST or TEST_F,
// or inside a function called by a TEST or TEST_F. Since Google
// Test keeps track of which test is current running, it can
// associate such an assertion with the test it belongs to.
//
// If an assertion is encountered when no TEST or TEST_F is running,
// Google Test attributes the assertion result to an imaginary "ad hoc"
// test, and records the result in ad_hoc_test_result_.
TestResult ad_hoc_test_result_;
// The list of event listeners that can be used to track events inside
// Google Test.
TestEventListeners listeners_;
// The OS stack trace getter. Will be deleted when the UnitTest
// object is destructed. By default, an OsStackTraceGetter is used,
// but the user can set this field to use a custom getter if that is
// desired.
OsStackTraceGetterInterface* os_stack_trace_getter_;
// True iff PostFlagParsingInit() has been called.
bool post_flag_parse_init_performed_;
// The random number seed used at the beginning of the test run.
int random_seed_;
// Our random number generator.
internal::Random random_;
// How long the test took to run, in milliseconds.
TimeInMillis elapsed_time_;
#if GTEST_HAS_DEATH_TEST
// The decomposed components of the gtest_internal_run_death_test flag,
// parsed when RUN_ALL_TESTS is called.
internal::scoped_ptr<InternalRunDeathTestFlag> internal_run_death_test_flag_;
internal::scoped_ptr<internal::DeathTestFactory> death_test_factory_;
#endif // GTEST_HAS_DEATH_TEST
// A per-thread stack of traces created by the SCOPED_TRACE() macro.
internal::ThreadLocal<std::vector<TraceInfo> > gtest_trace_stack_;
// The value of GTEST_FLAG(catch_exceptions) at the moment RunAllTests()
// starts.
bool catch_exceptions_;
GTEST_DISALLOW_COPY_AND_ASSIGN_(UnitTestImpl);
}; // class UnitTestImpl
// Convenience function for accessing the global UnitTest
// implementation object.
inline UnitTestImpl* GetUnitTestImpl() {
return UnitTest::GetInstance()->impl();
}
#if GTEST_USES_SIMPLE_RE
// Internal helper functions for implementing the simple regular
// expression matcher.
GTEST_API_ bool IsInSet(char ch, const char* str);
GTEST_API_ bool IsAsciiDigit(char ch);
GTEST_API_ bool IsAsciiPunct(char ch);
GTEST_API_ bool IsRepeat(char ch);
GTEST_API_ bool IsAsciiWhiteSpace(char ch);
GTEST_API_ bool IsAsciiWordChar(char ch);
GTEST_API_ bool IsValidEscape(char ch);
GTEST_API_ bool AtomMatchesChar(bool escaped, char pattern, char ch);
GTEST_API_ bool ValidateRegex(const char* regex);
GTEST_API_ bool MatchRegexAtHead(const char* regex, const char* str);
GTEST_API_ bool MatchRepetitionAndRegexAtHead(
bool escaped, char ch, char repeat, const char* regex, const char* str);
GTEST_API_ bool MatchRegexAnywhere(const char* regex, const char* str);
#endif // GTEST_USES_SIMPLE_RE
// Parses the command line for Google Test flags, without initializing
// other parts of Google Test.
GTEST_API_ void ParseGoogleTestFlagsOnly(int* argc, char** argv);
GTEST_API_ void ParseGoogleTestFlagsOnly(int* argc, wchar_t** argv);
#if GTEST_HAS_DEATH_TEST
// Returns the message describing the last system error, regardless of the
// platform.
GTEST_API_ String GetLastErrnoDescription();
# if GTEST_OS_WINDOWS
// Provides leak-safe Windows kernel handle ownership.
class AutoHandle {
public:
AutoHandle() : handle_(INVALID_HANDLE_VALUE) {}
explicit AutoHandle(HANDLE handle) : handle_(handle) {}
~AutoHandle() { Reset(); }
HANDLE Get() const { return handle_; }
void Reset() { Reset(INVALID_HANDLE_VALUE); }
void Reset(HANDLE handle) {
if (handle != handle_) {
if (handle_ != INVALID_HANDLE_VALUE)
::CloseHandle(handle_);
handle_ = handle;
}
}
private:
HANDLE handle_;
GTEST_DISALLOW_COPY_AND_ASSIGN_(AutoHandle);
};
# endif // GTEST_OS_WINDOWS
// Attempts to parse a string into a positive integer pointed to by the
// number parameter. Returns true if that is possible.
// GTEST_HAS_DEATH_TEST implies that we have ::std::string, so we can use
// it here.
template <typename Integer>
bool ParseNaturalNumber(const ::std::string& str, Integer* number) {
// Fail fast if the given string does not begin with a digit;
// this bypasses strtoXXX's "optional leading whitespace and plus
// or minus sign" semantics, which are undesirable here.
if (str.empty() || !IsDigit(str[0])) {
return false;
}
errno = 0;
char* end;
// BiggestConvertible is the largest integer type that system-provided
// string-to-number conversion routines can return.
# if GTEST_OS_WINDOWS && !defined(__GNUC__)
// MSVC and C++ Builder define __int64 instead of the standard long long.
typedef unsigned __int64 BiggestConvertible;
const BiggestConvertible parsed = _strtoui64(str.c_str(), &end, 10);
# else
typedef unsigned long long BiggestConvertible; // NOLINT
const BiggestConvertible parsed = strtoull(str.c_str(), &end, 10);
# endif // GTEST_OS_WINDOWS && !defined(__GNUC__)
const bool parse_success = *end == '\0' && errno == 0;
// TODO(vladl@google.com): Convert this to compile time assertion when it is
// available.
GTEST_CHECK_(sizeof(Integer) <= sizeof(parsed));
const Integer result = static_cast<Integer>(parsed);
if (parse_success && static_cast<BiggestConvertible>(result) == parsed) {
*number = result;
return true;
}
return false;
}
#endif // GTEST_HAS_DEATH_TEST
// TestResult contains some private methods that should be hidden from
// Google Test user but are required for testing. This class allow our tests
// to access them.
//
// This class is supplied only for the purpose of testing Google Test's own
// constructs. Do not use it in user tests, either directly or indirectly.
class TestResultAccessor {
public:
static void RecordProperty(TestResult* test_result,
const TestProperty& property) {
test_result->RecordProperty(property);
}
static void ClearTestPartResults(TestResult* test_result) {
test_result->ClearTestPartResults();
}
static const std::vector<testing::TestPartResult>& test_part_results(
const TestResult& test_result) {
return test_result.test_part_results();
}
};
} // namespace internal
} // namespace testing
#endif // GTEST_SRC_GTEST_INTERNAL_INL_H_
#undef GTEST_IMPLEMENTATION_
#if GTEST_OS_WINDOWS
# define vsnprintf _vsnprintf
#endif // GTEST_OS_WINDOWS
namespace testing {
using internal::CountIf;
using internal::ForEach;
using internal::GetElementOr;
using internal::Shuffle;
// Constants.
// A test whose test case name or test name matches this filter is
// disabled and not run.
static const char kDisableTestFilter[] = "DISABLED_*:*/DISABLED_*";
// A test case whose name matches this filter is considered a death
// test case and will be run before test cases whose name doesn't
// match this filter.
static const char kDeathTestCaseFilter[] = "*DeathTest:*DeathTest/*";
// A test filter that matches everything.
static const char kUniversalFilter[] = "*";
// The default output file for XML output.
static const char kDefaultOutputFile[] = "test_detail.xml";
// The environment variable name for the test shard index.
static const char kTestShardIndex[] = "GTEST_SHARD_INDEX";
// The environment variable name for the total number of test shards.
static const char kTestTotalShards[] = "GTEST_TOTAL_SHARDS";
// The environment variable name for the test shard status file.
static const char kTestShardStatusFile[] = "GTEST_SHARD_STATUS_FILE";
namespace internal {
// The text used in failure messages to indicate the start of the
// stack trace.
const char kStackTraceMarker[] = "\nStack trace:\n";
// g_help_flag is true iff the --help flag or an equivalent form is
// specified on the command line.
bool g_help_flag = false;
} // namespace internal
GTEST_DEFINE_bool_(
also_run_disabled_tests,
internal::BoolFromGTestEnv("also_run_disabled_tests", false),
"Run disabled tests too, in addition to the tests normally being run.");
GTEST_DEFINE_bool_(
break_on_failure,
internal::BoolFromGTestEnv("break_on_failure", false),
"True iff a failed assertion should be a debugger break-point.");
GTEST_DEFINE_bool_(
catch_exceptions,
internal::BoolFromGTestEnv("catch_exceptions", true),
"True iff " GTEST_NAME_
" should catch exceptions and treat them as test failures.");
GTEST_DEFINE_string_(
color,
internal::StringFromGTestEnv("color", "auto"),
"Whether to use colors in the output. Valid values: yes, no, "
"and auto. 'auto' means to use colors if the output is "
"being sent to a terminal and the TERM environment variable "
"is set to xterm, xterm-color, xterm-256color, linux or cygwin.");
GTEST_DEFINE_string_(
filter,
internal::StringFromGTestEnv("filter", kUniversalFilter),
"A colon-separated list of glob (not regex) patterns "
"for filtering the tests to run, optionally followed by a "
"'-' and a : separated list of negative patterns (tests to "
"exclude). A test is run if it matches one of the positive "
"patterns and does not match any of the negative patterns.");
GTEST_DEFINE_bool_(list_tests, false,
"List all tests without running them.");
GTEST_DEFINE_string_(
output,
internal::StringFromGTestEnv("output", ""),
"A format (currently must be \"xml\"), optionally followed "
"by a colon and an output file name or directory. A directory "
"is indicated by a trailing pathname separator. "
"Examples: \"xml:filename.xml\", \"xml::directoryname/\". "
"If a directory is specified, output files will be created "
"within that directory, with file-names based on the test "
"executable's name and, if necessary, made unique by adding "
"digits.");
GTEST_DEFINE_bool_(
print_time,
internal::BoolFromGTestEnv("print_time", true),
"True iff " GTEST_NAME_
" should display elapsed time in text output.");
GTEST_DEFINE_int32_(
random_seed,
internal::Int32FromGTestEnv("random_seed", 0),
"Random number seed to use when shuffling test orders. Must be in range "
"[1, 99999], or 0 to use a seed based on the current time.");
GTEST_DEFINE_int32_(
repeat,
internal::Int32FromGTestEnv("repeat", 1),
"How many times to repeat each test. Specify a negative number "
"for repeating forever. Useful for shaking out flaky tests.");
GTEST_DEFINE_bool_(
show_internal_stack_frames, false,
"True iff " GTEST_NAME_ " should include internal stack frames when "
"printing test failure stack traces.");
GTEST_DEFINE_bool_(
shuffle,
internal::BoolFromGTestEnv("shuffle", false),
"True iff " GTEST_NAME_
" should randomize tests' order on every run.");
GTEST_DEFINE_int32_(
stack_trace_depth,
internal::Int32FromGTestEnv("stack_trace_depth", kMaxStackTraceDepth),
"The maximum number of stack frames to print when an "
"assertion fails. The valid range is 0 through 100, inclusive.");
GTEST_DEFINE_string_(
stream_result_to,
internal::StringFromGTestEnv("stream_result_to", ""),
"This flag specifies the host name and the port number on which to stream "
"test results. Example: \"localhost:555\". The flag is effective only on "
"Linux.");
GTEST_DEFINE_bool_(
throw_on_failure,
internal::BoolFromGTestEnv("throw_on_failure", false),
"When this flag is specified, a failed assertion will throw an exception "
"if exceptions are enabled or exit the program with a non-zero code "
"otherwise.");
namespace internal {
// Generates a random number from [0, range), using a Linear
// Congruential Generator (LCG). Crashes if 'range' is 0 or greater
// than kMarange.
UInt32 Random::Generate(UInt32 range) {
// These constants are the same as are used in glibc's rand(3).
state_ = (1103515245U*state_ + 12345U) % kMarange;
GTEST_CHECK_(range > 0)
<< "Cannot generate a number in the range [0, 0).";
GTEST_CHECK_(range <= kMarange)
<< "Generation of a number in [0, " << range << ") was requested, "
<< "but this can only generate numbers in [0, " << kMarange << ").";
// Converting via modulus introduces a bit of downward bias, but
// it's simple, and a linear congruential generator isn't too good
// to begin with.
return state_ % range;
}
// GTestIsInitialized() returns true iff the user has initialized
// Google Test. Useful for catching the user mistake of not initializing
// Google Test before calling RUN_ALL_TESTS().
//
// A user must call testing::InitGoogleTest() to initialize Google
// Test. g_init_gtest_count is set to the number of times
// InitGoogleTest() has been called. We don't protect this variable
// under a mutex as it is only accessed in the main thread.
int g_init_gtest_count = 0;
static bool GTestIsInitialized() { return g_init_gtest_count != 0; }
// Iterates over a vector of TestCases, keeping a running sum of the
// results of calling a given int-returning method on each.
// Returns the sum.
static int SumOverTestCaseList(const std::vector<TestCase*>& case_list,
int (TestCase::*method)() const) {
int sum = 0;
for (size_t i = 0; i < case_list.size(); i++) {
sum += (case_list[i]->*method)();
}
return sum;
}
// Returns true iff the test case passed.
static bool TestCasePassed(const TestCase* test_case) {
return test_case->should_run() && test_case->Passed();
}
// Returns true iff the test case failed.
static bool TestCaseFailed(const TestCase* test_case) {
return test_case->should_run() && test_case->Failed();
}
// Returns true iff test_case contains at least one test that should
// run.
static bool ShouldRunTestCase(const TestCase* test_case) {
return test_case->should_run();
}
// AssertHelper constructor.
AssertHelper::AssertHelper(TestPartResult::Type type,
const char* file,
int line,
const char* message)
: data_(new AssertHelperData(type, file, line, message)) {
}
AssertHelper::~AssertHelper() {
delete data_;
}
// Message assignment, for assertion streaming support.
void AssertHelper::operator=(const Message& message) const {
UnitTest::GetInstance()->
AddTestPartResult(data_->type, data_->file, data_->line,
AppendUserMessage(data_->message, message),
UnitTest::GetInstance()->impl()
->CurrentOsStackTraceExceptTop(1)
// Skips the stack frame for this function itself.
); // NOLINT
}
// Mutex for linked pointers.
GTEST_DEFINE_STATIC_MUTEX_(g_linked_ptr_mutex);
// Application pathname gotten in InitGoogleTest.
String g_executable_path;
// Returns the current application's name, removing directory path if that
// is present.
FilePath GetCurrentExecutableName() {
FilePath result;
#if GTEST_OS_WINDOWS
result.Set(FilePath(g_executable_path).RemoveExtension("exe"));
#else
result.Set(FilePath(g_executable_path));
#endif // GTEST_OS_WINDOWS
return result.RemoveDirectoryName();
}
// Functions for processing the gtest_output flag.
// Returns the output format, or "" for normal printed output.
String UnitTestOptions::GetOutputFormat() {
const char* const gtest_output_flag = GTEST_FLAG(output).c_str();
if (gtest_output_flag == NULL) return String("");
const char* const colon = strchr(gtest_output_flag, ':');
return (colon == NULL) ?
String(gtest_output_flag) :
String(gtest_output_flag, colon - gtest_output_flag);
}
// Returns the name of the requested output file, or the default if none
// was explicitly specified.
String UnitTestOptions::GetAbsolutePathToOutputFile() {
const char* const gtest_output_flag = GTEST_FLAG(output).c_str();
if (gtest_output_flag == NULL)
return String("");
const char* const colon = strchr(gtest_output_flag, ':');
if (colon == NULL)
return String(internal::FilePath::ConcatPaths(
internal::FilePath(
UnitTest::GetInstance()->original_working_dir()),
internal::FilePath(kDefaultOutputFile)).ToString() );
internal::FilePath output_name(colon + 1);
if (!output_name.IsAbsolutePath())
// TODO(wan@google.com): on Windows \some\path is not an absolute
// path (as its meaning depends on the current drive), yet the
// following logic for turning it into an absolute path is wrong.
// Fix it.
output_name = internal::FilePath::ConcatPaths(
internal::FilePath(UnitTest::GetInstance()->original_working_dir()),
internal::FilePath(colon + 1));
if (!output_name.IsDirectory())
return output_name.ToString();
internal::FilePath result(internal::FilePath::GenerateUniqueFileName(
output_name, internal::GetCurrentExecutableName(),
GetOutputFormat().c_str()));
return result.ToString();
}
// Returns true iff the wildcard pattern matches the string. The
// first ':' or '\0' character in pattern marks the end of it.
//
// This recursive algorithm isn't very efficient, but is clear and
// works well enough for matching test names, which are short.
bool UnitTestOptions::PatternMatchesString(const char *pattern,
const char *str) {
switch (*pattern) {
case '\0':
case ':': // Either ':' or '\0' marks the end of the pattern.
return *str == '\0';
case '?': // Matches any single character.
return *str != '\0' && PatternMatchesString(pattern + 1, str + 1);
case '*': // Matches any string (possibly empty) of characters.
return (*str != '\0' && PatternMatchesString(pattern, str + 1)) ||
PatternMatchesString(pattern + 1, str);
default: // Non-special character. Matches itself.
return *pattern == *str &&
PatternMatchesString(pattern + 1, str + 1);
}
}
bool UnitTestOptions::MatchesFilter(const String& name, const char* filter) {
const char *cur_pattern = filter;
for (;;) {
if (PatternMatchesString(cur_pattern, name.c_str())) {
return true;
}
// Finds the next pattern in the filter.
cur_pattern = strchr(cur_pattern, ':');
// Returns if no more pattern can be found.
if (cur_pattern == NULL) {
return false;
}
// Skips the pattern separater (the ':' character).
cur_pattern++;
}
}
// TODO(keithray): move String function implementations to gtest-string.cc.
// Returns true iff the user-specified filter matches the test case
// name and the test name.
bool UnitTestOptions::FilterMatchesTest(const String &test_case_name,
const String &test_name) {
const String& full_name = String::Format("%s.%s",
test_case_name.c_str(),
test_name.c_str());
// Split --gtest_filter at '-', if there is one, to separate into
// positive filter and negative filter portions
const char* const p = GTEST_FLAG(filter).c_str();
const char* const dash = strchr(p, '-');
String positive;
String negative;
if (dash == NULL) {
positive = GTEST_FLAG(filter).c_str(); // Whole string is a positive filter
negative = String("");
} else {
positive = String(p, dash - p); // Everything up to the dash
negative = String(dash+1); // Everything after the dash
if (positive.empty()) {
// Treat '-test1' as the same as '*-test1'
positive = kUniversalFilter;
}
}
// A filter is a colon-separated list of patterns. It matches a
// test if any pattern in it matches the test.
return (MatchesFilter(full_name, positive.c_str()) &&
!MatchesFilter(full_name, negative.c_str()));
}
#if GTEST_HAS_SEH
// Returns EXCEPTION_EXECUTE_HANDLER if Google Test should handle the
// given SEH exception, or EXCEPTION_CONTINUE_SEARCH otherwise.
// This function is useful as an __except condition.
int UnitTestOptions::GTestShouldProcessSEH(DWORD exception_code) {
// Google Test should handle a SEH exception if:
// 1. the user wants it to, AND
// 2. this is not a breakpoint exception, AND
// 3. this is not a C++ exception (VC++ implements them via SEH,
// apparently).
//
// SEH exception code for C++ exceptions.
// (see http://support.microsoft.com/kb/185294 for more information).
const DWORD kCxxExceptionCode = 0xe06d7363;
bool should_handle = true;
if (!GTEST_FLAG(catch_exceptions))
should_handle = false;
else if (exception_code == EXCEPTION_BREAKPOINT)
should_handle = false;
else if (exception_code == kCxxExceptionCode)
should_handle = false;
return should_handle ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH;
}
#endif // GTEST_HAS_SEH
} // namespace internal
// The c'tor sets this object as the test part result reporter used by
// Google Test. The 'result' parameter specifies where to report the
// results. Intercepts only failures from the current thread.
ScopedFakeTestPartResultReporter::ScopedFakeTestPartResultReporter(
TestPartResultArray* result)
: intercept_mode_(INTERCEPT_ONLY_CURRENT_THREAD),
result_(result) {
Init();
}
// The c'tor sets this object as the test part result reporter used by
// Google Test. The 'result' parameter specifies where to report the
// results.
ScopedFakeTestPartResultReporter::ScopedFakeTestPartResultReporter(
InterceptMode intercept_mode, TestPartResultArray* result)
: intercept_mode_(intercept_mode),
result_(result) {
Init();
}
void ScopedFakeTestPartResultReporter::Init() {
internal::UnitTestImpl* const impl = internal::GetUnitTestImpl();
if (intercept_mode_ == INTERCEPT_ALL_THREADS) {
old_reporter_ = impl->GetGlobalTestPartResultReporter();
impl->SetGlobalTestPartResultReporter(this);
} else {
old_reporter_ = impl->GetTestPartResultReporterForCurrentThread();
impl->SetTestPartResultReporterForCurrentThread(this);
}
}
// The d'tor restores the test part result reporter used by Google Test
// before.
ScopedFakeTestPartResultReporter::~ScopedFakeTestPartResultReporter() {
internal::UnitTestImpl* const impl = internal::GetUnitTestImpl();
if (intercept_mode_ == INTERCEPT_ALL_THREADS) {
impl->SetGlobalTestPartResultReporter(old_reporter_);
} else {
impl->SetTestPartResultReporterForCurrentThread(old_reporter_);
}
}
// Increments the test part result count and remembers the result.
// This method is from the TestPartResultReporterInterface interface.
void ScopedFakeTestPartResultReporter::ReportTestPartResult(
const TestPartResult& result) {
result_->Append(result);
}
namespace internal {
// Returns the type ID of ::testing::Test. We should always call this
// instead of GetTypeId< ::testing::Test>() to get the type ID of
// testing::Test. This is to work around a suspected linker bug when
// using Google Test as a framework on Mac OS X. The bug causes
// GetTypeId< ::testing::Test>() to return different values depending
// on whether the call is from the Google Test framework itself or
// from user test code. GetTestTypeId() is guaranteed to always
// return the same value, as it always calls GetTypeId<>() from the
// gtest.cc, which is within the Google Test framework.
TypeId GetTestTypeId() {
return GetTypeId<Test>();
}
// The value of GetTestTypeId() as seen from within the Google Test
// library. This is solely for testing GetTestTypeId().
extern const TypeId kTestTypeIdInGoogleTest = GetTestTypeId();
// This predicate-formatter checks that 'results' contains a test part
// failure of the given type and that the failure message contains the
// given substring.
AssertionResult HasOneFailure(const char* /* results_expr */,
const char* /* type_expr */,
const char* /* substr_expr */,
const TestPartResultArray& results,
TestPartResult::Type type,
const string& substr) {
const String expected(type == TestPartResult::kFatalFailure ?
"1 fatal failure" :
"1 non-fatal failure");
Message msg;
if (results.size() != 1) {
msg << "Expected: " << expected << "\n"
<< " Actual: " << results.size() << " failures";
for (int i = 0; i < results.size(); i++) {
msg << "\n" << results.GetTestPartResult(i);
}
return AssertionFailure() << msg;
}
const TestPartResult& r = results.GetTestPartResult(0);
if (r.type() != type) {
return AssertionFailure() << "Expected: " << expected << "\n"
<< " Actual:\n"
<< r;
}
if (strstr(r.message(), substr.c_str()) == NULL) {
return AssertionFailure() << "Expected: " << expected << " containing \""
<< substr << "\"\n"
<< " Actual:\n"
<< r;
}
return AssertionSuccess();
}
// The constructor of SingleFailureChecker remembers where to look up
// test part results, what type of failure we expect, and what
// substring the failure message should contain.
SingleFailureChecker:: SingleFailureChecker(
const TestPartResultArray* results,
TestPartResult::Type type,
const string& substr)
: results_(results),
type_(type),
substr_(substr) {}
// The destructor of SingleFailureChecker verifies that the given
// TestPartResultArray contains exactly one failure that has the given
// type and contains the given substring. If that's not the case, a
// non-fatal failure will be generated.
SingleFailureChecker::~SingleFailureChecker() {
EXPECT_PRED_FORMAT3(HasOneFailure, *results_, type_, substr_);
}
DefaultGlobalTestPartResultReporter::DefaultGlobalTestPartResultReporter(
UnitTestImpl* unit_test) : unit_test_(unit_test) {}
void DefaultGlobalTestPartResultReporter::ReportTestPartResult(
const TestPartResult& result) {
unit_test_->current_test_result()->AddTestPartResult(result);
unit_test_->listeners()->repeater()->OnTestPartResult(result);
}
DefaultPerThreadTestPartResultReporter::DefaultPerThreadTestPartResultReporter(
UnitTestImpl* unit_test) : unit_test_(unit_test) {}
void DefaultPerThreadTestPartResultReporter::ReportTestPartResult(
const TestPartResult& result) {
unit_test_->GetGlobalTestPartResultReporter()->ReportTestPartResult(result);
}
// Returns the global test part result reporter.
TestPartResultReporterInterface*
UnitTestImpl::GetGlobalTestPartResultReporter() {
internal::MutexLock lock(&global_test_part_result_reporter_mutex_);
return global_test_part_result_repoter_;
}
// Sets the global test part result reporter.
void UnitTestImpl::SetGlobalTestPartResultReporter(
TestPartResultReporterInterface* reporter) {
internal::MutexLock lock(&global_test_part_result_reporter_mutex_);
global_test_part_result_repoter_ = reporter;
}
// Returns the test part result reporter for the current thread.
TestPartResultReporterInterface*
UnitTestImpl::GetTestPartResultReporterForCurrentThread() {
return per_thread_test_part_result_reporter_.get();
}
// Sets the test part result reporter for the current thread.
void UnitTestImpl::SetTestPartResultReporterForCurrentThread(
TestPartResultReporterInterface* reporter) {
per_thread_test_part_result_reporter_.set(reporter);
}
// Gets the number of successful test cases.
int UnitTestImpl::successful_test_case_count() const {
return CountIf(test_cases_, TestCasePassed);
}
// Gets the number of failed test cases.
int UnitTestImpl::failed_test_case_count() const {
return CountIf(test_cases_, TestCaseFailed);
}
// Gets the number of all test cases.
int UnitTestImpl::total_test_case_count() const {
return static_cast<int>(test_cases_.size());
}
// Gets the number of all test cases that contain at least one test
// that should run.
int UnitTestImpl::test_case_to_run_count() const {
return CountIf(test_cases_, ShouldRunTestCase);
}
// Gets the number of successful tests.
int UnitTestImpl::successful_test_count() const {
return SumOverTestCaseList(test_cases_, &TestCase::successful_test_count);
}
// Gets the number of failed tests.
int UnitTestImpl::failed_test_count() const {
return SumOverTestCaseList(test_cases_, &TestCase::failed_test_count);
}
// Gets the number of disabled tests.
int UnitTestImpl::disabled_test_count() const {
return SumOverTestCaseList(test_cases_, &TestCase::disabled_test_count);
}
// Gets the number of all tests.
int UnitTestImpl::total_test_count() const {
return SumOverTestCaseList(test_cases_, &TestCase::total_test_count);
}
// Gets the number of tests that should run.
int UnitTestImpl::test_to_run_count() const {
return SumOverTestCaseList(test_cases_, &TestCase::test_to_run_count);
}
// Returns the current OS stack trace as a String.
//
// The maximum number of stack frames to be included is specified by
// the gtest_stack_trace_depth flag. The skip_count parameter
// specifies the number of top frames to be skipped, which doesn't
// count against the number of frames to be included.
//
// For example, if Foo() calls Bar(), which in turn calls
// CurrentOsStackTraceExceptTop(1), Foo() will be included in the
// trace but Bar() and CurrentOsStackTraceExceptTop() won't.
String UnitTestImpl::CurrentOsStackTraceExceptTop(int skip_count) {
(void)skip_count;
return String("");
}
// Returns the current time in milliseconds.
TimeInMillis GetTimeInMillis() {
#if GTEST_OS_WINDOWS_MOBILE || defined(__BORLANDC__)
// Difference between 1970-01-01 and 1601-01-01 in milliseconds.
// http://analogous.blogspot.com/2005/04/epoch.html
const TimeInMillis kJavaEpochToWinFileTimeDelta =
static_cast<TimeInMillis>(116444736UL) * 100000UL;
const DWORD kTenthMicrosInMilliSecond = 10000;
SYSTEMTIME now_systime;
FILETIME now_filetime;
ULARGE_INTEGER now_int64;
// TODO(kenton@google.com): Shouldn't this just use
// GetSystemTimeAsFileTime()?
GetSystemTime(&now_systime);
if (SystemTimeToFileTime(&now_systime, &now_filetime)) {
now_int64.LowPart = now_filetime.dwLowDateTime;
now_int64.HighPart = now_filetime.dwHighDateTime;
now_int64.QuadPart = (now_int64.QuadPart / kTenthMicrosInMilliSecond) -
kJavaEpochToWinFileTimeDelta;
return now_int64.QuadPart;
}
return 0;
#elif GTEST_OS_WINDOWS && !GTEST_HAS_GETTIMEOFDAY_
__timeb64 now;
# ifdef _MSC_VER
// MSVC 8 deprecates _ftime64(), so we want to suppress warning 4996
// (deprecated function) there.
// TODO(kenton@google.com): Use GetTickCount()? Or use
// SystemTimeToFileTime()
# pragma warning(push) // Saves the current warning state.
# pragma warning(disable:4996) // Temporarily disables warning 4996.
_ftime64(&now);
# pragma warning(pop) // Restores the warning state.
# else
_ftime64(&now);
# endif // _MSC_VER
return static_cast<TimeInMillis>(now.time) * 1000 + now.millitm;
#elif GTEST_HAS_GETTIMEOFDAY_
struct timeval now;
gettimeofday(&now, NULL);
return static_cast<TimeInMillis>(now.tv_sec) * 1000 + now.tv_usec / 1000;
#else
# error "Don't know how to get the current time on your system."
#endif
}
// Utilities
// class String
// Returns the input enclosed in double quotes if it's not NULL;
// otherwise returns "(null)". For example, "\"Hello\"" is returned
// for input "Hello".
//
// This is useful for printing a C string in the syntax of a literal.
//
// Known issue: escape sequences are not handled yet.
String String::ShowCStringQuoted(const char* c_str) {
return c_str ? String::Format("\"%s\"", c_str) : String("(null)");
}
// Copies at most length characters from str into a newly-allocated
// piece of memory of size length+1. The memory is allocated with new[].
// A terminating null byte is written to the memory, and a pointer to it
// is returned. If str is NULL, NULL is returned.
static char* CloneString(const char* str, size_t length) {
if (str == NULL) {
return NULL;
} else {
char* const clone = new char[length + 1];
posix::StrNCpy(clone, str, length);
clone[length] = '\0';
return clone;
}
}
// Clones a 0-terminated C string, allocating memory using new. The
// caller is responsible for deleting[] the return value. Returns the
// cloned string, or NULL if the input is NULL.
const char * String::CloneCString(const char* c_str) {
return (c_str == NULL) ?
NULL : CloneString(c_str, strlen(c_str));
}
#if GTEST_OS_WINDOWS_MOBILE
// Creates a UTF-16 wide string from the given ANSI string, allocating
// memory using new. The caller is responsible for deleting the return
// value using delete[]. Returns the wide string, or NULL if the
// input is NULL.
LPCWSTR String::AnsiToUtf16(const char* ansi) {
if (!ansi) return NULL;
const int length = strlen(ansi);
const int unicode_length =
MultiByteToWideChar(CP_ACP, 0, ansi, length,
NULL, 0);
WCHAR* unicode = new WCHAR[unicode_length + 1];
MultiByteToWideChar(CP_ACP, 0, ansi, length,
unicode, unicode_length);
unicode[unicode_length] = 0;
return unicode;
}
// Creates an ANSI string from the given wide string, allocating
// memory using new. The caller is responsible for deleting the return
// value using delete[]. Returns the ANSI string, or NULL if the
// input is NULL.
const char* String::Utf16ToAnsi(LPCWSTR utf16_str) {
if (!utf16_str) return NULL;
const int ansi_length =
WideCharToMultiByte(CP_ACP, 0, utf16_str, -1,
NULL, 0, NULL, NULL);
char* ansi = new char[ansi_length + 1];
WideCharToMultiByte(CP_ACP, 0, utf16_str, -1,
ansi, ansi_length, NULL, NULL);
ansi[ansi_length] = 0;
return ansi;
}
#endif // GTEST_OS_WINDOWS_MOBILE
// Compares two C strings. Returns true iff they have the same content.
//
// Unlike strcmp(), this function can handle NULL argument(s). A NULL
// C string is considered different to any non-NULL C string,
// including the empty string.
bool String::CStringEquals(const char * lhs, const char * rhs) {
if ( lhs == NULL ) return rhs == NULL;
if ( rhs == NULL ) return false;
return strcmp(lhs, rhs) == 0;
}
#if GTEST_HAS_STD_WSTRING || GTEST_HAS_GLOBAL_WSTRING
// Converts an array of wide chars to a narrow string using the UTF-8
// encoding, and streams the result to the given Message object.
static void StreamWideCharsToMessage(const wchar_t* wstr, size_t length,
Message* msg) {
// TODO(wan): consider allowing a testing::String object to
// contain '\0'. This will make it behave more like std::string,
// and will allow ToUtf8String() to return the correct encoding
// for '\0' s.t. we can get rid of the conditional here (and in
// several other places).
for (size_t i = 0; i != length; ) { // NOLINT
if (wstr[i] != L'\0') {
*msg << WideStringToUtf8(wstr + i, static_cast<int>(length - i));
while (i != length && wstr[i] != L'\0')
i++;
} else {
*msg << '\0';
i++;
}
}
}
#endif // GTEST_HAS_STD_WSTRING || GTEST_HAS_GLOBAL_WSTRING
} // namespace internal
#if GTEST_HAS_STD_WSTRING
// Converts the given wide string to a narrow string using the UTF-8
// encoding, and streams the result to this Message object.
Message& Message::operator <<(const ::std::wstring& wstr) {
internal::StreamWideCharsToMessage(wstr.c_str(), wstr.length(), this);
return *this;
}
#endif // GTEST_HAS_STD_WSTRING
#if GTEST_HAS_GLOBAL_WSTRING
// Converts the given wide string to a narrow string using the UTF-8
// encoding, and streams the result to this Message object.
Message& Message::operator <<(const ::wstring& wstr) {
internal::StreamWideCharsToMessage(wstr.c_str(), wstr.length(), this);
return *this;
}
#endif // GTEST_HAS_GLOBAL_WSTRING
// AssertionResult constructors.
// Used in EXPECT_TRUE/FALSE(assertion_result).
AssertionResult::AssertionResult(const AssertionResult& other)
: success_(other.success_),
message_(other.message_.get() != NULL ?
new ::std::string(*other.message_) :
static_cast< ::std::string*>(NULL)) {
}
// Returns the assertion's negation. Used with EXPECT/ASSERT_FALSE.
AssertionResult AssertionResult::operator!() const {
AssertionResult negation(!success_);
if (message_.get() != NULL)
negation << *message_;
return negation;
}
// Makes a successful assertion result.
AssertionResult AssertionSuccess() {
return AssertionResult(true);
}
// Makes a failed assertion result.
AssertionResult AssertionFailure() {
return AssertionResult(false);
}
// Makes a failed assertion result with the given failure message.
// Deprecated; use AssertionFailure() << message.
AssertionResult AssertionFailure(const Message& message) {
return AssertionFailure() << message;
}
namespace internal {
// Constructs and returns the message for an equality assertion
// (e.g. ASSERT_EQ, EXPECT_STREQ, etc) failure.
//
// The first four parameters are the expressions used in the assertion
// and their values, as strings. For example, for ASSERT_EQ(foo, bar)
// where foo is 5 and bar is 6, we have:
//
// expected_expression: "foo"
// actual_expression: "bar"
// expected_value: "5"
// actual_value: "6"
//
// The ignoring_case parameter is true iff the assertion is a
// *_STRCASEEQ*. When it's true, the string " (ignoring case)" will
// be inserted into the message.
AssertionResult EqFailure(const char* expected_expression,
const char* actual_expression,
const String& expected_value,
const String& actual_value,
bool ignoring_case) {
Message msg;
msg << "Value of: " << actual_expression;
if (actual_value != actual_expression) {
msg << "\n Actual: " << actual_value;
}
msg << "\nExpected: " << expected_expression;
if (ignoring_case) {
msg << " (ignoring case)";
}
if (expected_value != expected_expression) {
msg << "\nWhich is: " << expected_value;
}
return AssertionFailure() << msg;
}
// Constructs a failure message for Boolean assertions such as EXPECT_TRUE.
String GetBoolAssertionFailureMessage(const AssertionResult& assertion_result,
const char* expression_text,
const char* actual_predicate_value,
const char* expected_predicate_value) {
const char* actual_message = assertion_result.message();
Message msg;
msg << "Value of: " << expression_text
<< "\n Actual: " << actual_predicate_value;
if (actual_message[0] != '\0')
msg << " (" << actual_message << ")";
msg << "\nExpected: " << expected_predicate_value;
return msg.GetString();
}
// Helper function for implementing ASSERT_NEAR.
AssertionResult DoubleNearPredFormat(const char* expr1,
const char* expr2,
const char* abs_error_expr,
double val1,
double val2,
double abs_error) {
const double diff = fabs(val1 - val2);
if (diff <= abs_error) return AssertionSuccess();
// TODO(wan): do not print the value of an expression if it's
// already a literal.
return AssertionFailure()
<< "The difference between " << expr1 << " and " << expr2
<< " is " << diff << ", which exceeds " << abs_error_expr << ", where\n"
<< expr1 << " evaluates to " << val1 << ",\n"
<< expr2 << " evaluates to " << val2 << ", and\n"
<< abs_error_expr << " evaluates to " << abs_error << ".";
}
// Helper template for implementing FloatLE() and DoubleLE().
template <typename RawType>
AssertionResult FloatingPointLE(const char* expr1,
const char* expr2,
RawType val1,
RawType val2) {
// Returns success if val1 is less than val2,
if (val1 < val2) {
return AssertionSuccess();
}
// or if val1 is almost equal to val2.
const FloatingPoint<RawType> lhs(val1), rhs(val2);
if (lhs.AlmostEquals(rhs)) {
return AssertionSuccess();
}
// Note that the above two checks will both fail if either val1 or
// val2 is NaN, as the IEEE floating-point standard requires that
// any predicate involving a NaN must return false.
::std::stringstream val1_ss;
val1_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2)
<< val1;
::std::stringstream val2_ss;
val2_ss << std::setprecision(std::numeric_limits<RawType>::digits10 + 2)
<< val2;
return AssertionFailure()
<< "Expected: (" << expr1 << ") <= (" << expr2 << ")\n"
<< " Actual: " << StringStreamToString(&val1_ss) << " vs "
<< StringStreamToString(&val2_ss);
}
} // namespace internal
// Asserts that val1 is less than, or almost equal to, val2. Fails
// otherwise. In particular, it fails if either val1 or val2 is NaN.
AssertionResult FloatLE(const char* expr1, const char* expr2,
float val1, float val2) {
return internal::FloatingPointLE<float>(expr1, expr2, val1, val2);
}
// Asserts that val1 is less than, or almost equal to, val2. Fails
// otherwise. In particular, it fails if either val1 or val2 is NaN.
AssertionResult DoubleLE(const char* expr1, const char* expr2,
double val1, double val2) {
return internal::FloatingPointLE<double>(expr1, expr2, val1, val2);
}
namespace internal {
// The helper function for {ASSERT|EXPECT}_EQ with int or enum
// arguments.
AssertionResult CmpHelperEQ(const char* expected_expression,
const char* actual_expression,
BiggestInt expected,
BiggestInt actual) {
if (expected == actual) {
return AssertionSuccess();
}
return EqFailure(expected_expression,
actual_expression,
FormatForComparisonFailureMessage(expected, actual),
FormatForComparisonFailureMessage(actual, expected),
false);
}
// A macro for implementing the helper functions needed to implement
// ASSERT_?? and EXPECT_?? with integer or enum arguments. It is here
// just to avoid copy-and-paste of similar code.
#define GTEST_IMPL_CMP_HELPER_(op_name, op)\
AssertionResult CmpHelper##op_name(const char* expr1, const char* expr2, \
BiggestInt val1, BiggestInt val2) {\
if (val1 op val2) {\
return AssertionSuccess();\
} else {\
return AssertionFailure() \
<< "Expected: (" << expr1 << ") " #op " (" << expr2\
<< "), actual: " << FormatForComparisonFailureMessage(val1, val2)\
<< " vs " << FormatForComparisonFailureMessage(val2, val1);\
}\
}
// Implements the helper function for {ASSERT|EXPECT}_NE with int or
// enum arguments.
GTEST_IMPL_CMP_HELPER_(NE, !=)
// Implements the helper function for {ASSERT|EXPECT}_LE with int or
// enum arguments.
GTEST_IMPL_CMP_HELPER_(LE, <=)
// Implements the helper function for {ASSERT|EXPECT}_LT with int or
// enum arguments.
GTEST_IMPL_CMP_HELPER_(LT, < )
// Implements the helper function for {ASSERT|EXPECT}_GE with int or
// enum arguments.
GTEST_IMPL_CMP_HELPER_(GE, >=)
// Implements the helper function for {ASSERT|EXPECT}_GT with int or
// enum arguments.
GTEST_IMPL_CMP_HELPER_(GT, > )
#undef GTEST_IMPL_CMP_HELPER_
// The helper function for {ASSERT|EXPECT}_STREQ.
AssertionResult CmpHelperSTREQ(const char* expected_expression,
const char* actual_expression,
const char* expected,
const char* actual) {
if (String::CStringEquals(expected, actual)) {
return AssertionSuccess();
}
return EqFailure(expected_expression,
actual_expression,
String::ShowCStringQuoted(expected),
String::ShowCStringQuoted(actual),
false);
}
// The helper function for {ASSERT|EXPECT}_STRCASEEQ.
AssertionResult CmpHelperSTRCASEEQ(const char* expected_expression,
const char* actual_expression,
const char* expected,
const char* actual) {
if (String::CaseInsensitiveCStringEquals(expected, actual)) {
return AssertionSuccess();
}
return EqFailure(expected_expression,
actual_expression,
String::ShowCStringQuoted(expected),
String::ShowCStringQuoted(actual),
true);
}
// The helper function for {ASSERT|EXPECT}_STRNE.
AssertionResult CmpHelperSTRNE(const char* s1_expression,
const char* s2_expression,
const char* s1,
const char* s2) {
if (!String::CStringEquals(s1, s2)) {
return AssertionSuccess();
} else {
return AssertionFailure() << "Expected: (" << s1_expression << ") != ("
<< s2_expression << "), actual: \""
<< s1 << "\" vs \"" << s2 << "\"";
}
}
// The helper function for {ASSERT|EXPECT}_STRCASENE.
AssertionResult CmpHelperSTRCASENE(const char* s1_expression,
const char* s2_expression,
const char* s1,
const char* s2) {
if (!String::CaseInsensitiveCStringEquals(s1, s2)) {
return AssertionSuccess();
} else {
return AssertionFailure()
<< "Expected: (" << s1_expression << ") != ("
<< s2_expression << ") (ignoring case), actual: \""
<< s1 << "\" vs \"" << s2 << "\"";
}
}
} // namespace internal
namespace {
// Helper functions for implementing IsSubString() and IsNotSubstring().
// This group of overloaded functions return true iff needle is a
// substring of haystack. NULL is considered a substring of itself
// only.
bool IsSubstringPred(const char* needle, const char* haystack) {
if (needle == NULL || haystack == NULL)
return needle == haystack;
return strstr(haystack, needle) != NULL;
}
bool IsSubstringPred(const wchar_t* needle, const wchar_t* haystack) {
if (needle == NULL || haystack == NULL)
return needle == haystack;
return wcsstr(haystack, needle) != NULL;
}
// StringType here can be either ::std::string or ::std::wstring.
template <typename StringType>
bool IsSubstringPred(const StringType& needle,
const StringType& haystack) {
return haystack.find(needle) != StringType::npos;
}
// This function implements either IsSubstring() or IsNotSubstring(),
// depending on the value of the expected_to_be_substring parameter.
// StringType here can be const char*, const wchar_t*, ::std::string,
// or ::std::wstring.
template <typename StringType>
AssertionResult IsSubstringImpl(
bool expected_to_be_substring,
const char* needle_expr, const char* haystack_expr,
const StringType& needle, const StringType& haystack) {
if (IsSubstringPred(needle, haystack) == expected_to_be_substring)
return AssertionSuccess();
const bool is_wide_string = sizeof(needle[0]) > 1;
const char* const begin_string_quote = is_wide_string ? "L\"" : "\"";
return AssertionFailure()
<< "Value of: " << needle_expr << "\n"
<< " Actual: " << begin_string_quote << needle << "\"\n"
<< "Expected: " << (expected_to_be_substring ? "" : "not ")
<< "a substring of " << haystack_expr << "\n"
<< "Which is: " << begin_string_quote << haystack << "\"";
}
} // namespace
// IsSubstring() and IsNotSubstring() check whether needle is a
// substring of haystack (NULL is considered a substring of itself
// only), and return an appropriate error message when they fail.
AssertionResult IsSubstring(
const char* needle_expr, const char* haystack_expr,
const char* needle, const char* haystack) {
return IsSubstringImpl(true, needle_expr, haystack_expr, needle, haystack);
}
AssertionResult IsSubstring(
const char* needle_expr, const char* haystack_expr,
const wchar_t* needle, const wchar_t* haystack) {
return IsSubstringImpl(true, needle_expr, haystack_expr, needle, haystack);
}
AssertionResult IsNotSubstring(
const char* needle_expr, const char* haystack_expr,
const char* needle, const char* haystack) {
return IsSubstringImpl(false, needle_expr, haystack_expr, needle, haystack);
}
AssertionResult IsNotSubstring(
const char* needle_expr, const char* haystack_expr,
const wchar_t* needle, const wchar_t* haystack) {
return IsSubstringImpl(false, needle_expr, haystack_expr, needle, haystack);
}
AssertionResult IsSubstring(
const char* needle_expr, const char* haystack_expr,
const ::std::string& needle, const ::std::string& haystack) {
return IsSubstringImpl(true, needle_expr, haystack_expr, needle, haystack);
}
AssertionResult IsNotSubstring(
const char* needle_expr, const char* haystack_expr,
const ::std::string& needle, const ::std::string& haystack) {
return IsSubstringImpl(false, needle_expr, haystack_expr, needle, haystack);
}
#if GTEST_HAS_STD_WSTRING
AssertionResult IsSubstring(
const char* needle_expr, const char* haystack_expr,
const ::std::wstring& needle, const ::std::wstring& haystack) {
return IsSubstringImpl(true, needle_expr, haystack_expr, needle, haystack);
}
AssertionResult IsNotSubstring(
const char* needle_expr, const char* haystack_expr,
const ::std::wstring& needle, const ::std::wstring& haystack) {
return IsSubstringImpl(false, needle_expr, haystack_expr, needle, haystack);
}
#endif // GTEST_HAS_STD_WSTRING
namespace internal {
#if GTEST_OS_WINDOWS
namespace {
// Helper function for IsHRESULT{SuccessFailure} predicates
AssertionResult HRESULTFailureHelper(const char* expr,
const char* expected,
long hr) { // NOLINT
# if GTEST_OS_WINDOWS_MOBILE
// Windows CE doesn't support FormatMessage.
const char error_text[] = "";
# else
// Looks up the human-readable system message for the HRESULT code
// and since we're not passing any params to FormatMessage, we don't
// want inserts expanded.
const DWORD kFlags = FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS;
const DWORD kBufSize = 4096; // String::Format can't exceed this length.
// Gets the system's human readable message string for this HRESULT.
char error_text[kBufSize] = { '\0' };
DWORD message_length = ::FormatMessageA(kFlags,
0, // no source, we're asking system
hr, // the error
0, // no line width restrictions
error_text, // output buffer
kBufSize, // buf size
NULL); // no arguments for inserts
// Trims tailing white space (FormatMessage leaves a trailing cr-lf)
for (; message_length && IsSpace(error_text[message_length - 1]);
--message_length) {
error_text[message_length - 1] = '\0';
}
# endif // GTEST_OS_WINDOWS_MOBILE
const String error_hex(String::Format("0x%08X ", hr));
return ::testing::AssertionFailure()
<< "Expected: " << expr << " " << expected << ".\n"
<< " Actual: " << error_hex << error_text << "\n";
}
} // namespace
AssertionResult IsHRESULTSuccess(const char* expr, long hr) { // NOLINT
if (SUCCEEDED(hr)) {
return AssertionSuccess();
}
return HRESULTFailureHelper(expr, "succeeds", hr);
}
AssertionResult IsHRESULTFailure(const char* expr, long hr) { // NOLINT
if (FAILED(hr)) {
return AssertionSuccess();
}
return HRESULTFailureHelper(expr, "fails", hr);
}
#endif // GTEST_OS_WINDOWS
// Utility functions for encoding Unicode text (wide strings) in
// UTF-8.
// A Unicode code-point can have upto 21 bits, and is encoded in UTF-8
// like this:
//
// Code-point length Encoding
// 0 - 7 bits 0xxxxxxx
// 8 - 11 bits 110xxxxx 10xxxxxx
// 12 - 16 bits 1110xxxx 10xxxxxx 10xxxxxx
// 17 - 21 bits 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
// The maximum code-point a one-byte UTF-8 sequence can represent.
const UInt32 kMaxCodePoint1 = (static_cast<UInt32>(1) << 7) - 1;
// The maximum code-point a two-byte UTF-8 sequence can represent.
const UInt32 kMaxCodePoint2 = (static_cast<UInt32>(1) << (5 + 6)) - 1;
// The maximum code-point a three-byte UTF-8 sequence can represent.
const UInt32 kMaxCodePoint3 = (static_cast<UInt32>(1) << (4 + 2*6)) - 1;
// The maximum code-point a four-byte UTF-8 sequence can represent.
const UInt32 kMaxCodePoint4 = (static_cast<UInt32>(1) << (3 + 3*6)) - 1;
// Chops off the n lowest bits from a bit pattern. Returns the n
// lowest bits. As a side effect, the original bit pattern will be
// shifted to the right by n bits.
inline UInt32 ChopLowBits(UInt32* bits, int n) {
const UInt32 low_bits = *bits & ((static_cast<UInt32>(1) << n) - 1);
*bits >>= n;
return low_bits;
}
// Converts a Unicode code point to a narrow string in UTF-8 encoding.
// code_point parameter is of type UInt32 because wchar_t may not be
// wide enough to contain a code point.
// The output buffer str must containt at least 32 characters.
// The function returns the address of the output buffer.
// If the code_point is not a valid Unicode code point
// (i.e. outside of Unicode range U+0 to U+10FFFF) it will be output
// as '(Invalid Unicode 0xXXXXXXXX)'.
char* CodePointToUtf8(UInt32 code_point, char* str) {
if (code_point <= kMaxCodePoint1) {
str[1] = '\0';
str[0] = static_cast<char>(code_point); // 0xxxxxxx
} else if (code_point <= kMaxCodePoint2) {
str[2] = '\0';
str[1] = static_cast<char>(0x80 | ChopLowBits(&code_point, 6)); // 10xxxxxx
str[0] = static_cast<char>(0xC0 | code_point); // 110xxxxx
} else if (code_point <= kMaxCodePoint3) {
str[3] = '\0';
str[2] = static_cast<char>(0x80 | ChopLowBits(&code_point, 6)); // 10xxxxxx
str[1] = static_cast<char>(0x80 | ChopLowBits(&code_point, 6)); // 10xxxxxx
str[0] = static_cast<char>(0xE0 | code_point); // 1110xxxx
} else if (code_point <= kMaxCodePoint4) {
str[4] = '\0';
str[3] = static_cast<char>(0x80 | ChopLowBits(&code_point, 6)); // 10xxxxxx
str[2] = static_cast<char>(0x80 | ChopLowBits(&code_point, 6)); // 10xxxxxx
str[1] = static_cast<char>(0x80 | ChopLowBits(&code_point, 6)); // 10xxxxxx
str[0] = static_cast<char>(0xF0 | code_point); // 11110xxx
} else {
// The longest string String::Format can produce when invoked
// with these parameters is 28 character long (not including
// the terminating nul character). We are asking for 32 character
// buffer just in case. This is also enough for strncpy to
// null-terminate the destination string.
posix::StrNCpy(
str, String::Format("(Invalid Unicode 0x%X)", code_point).c_str(), 32);
str[31] = '\0'; // Makes sure no change in the format to strncpy leaves
// the result unterminated.
}
return str;
}
// The following two functions only make sense if the the system
// uses UTF-16 for wide string encoding. All supported systems
// with 16 bit wchar_t (Windows, Cygwin, Symbian OS) do use UTF-16.
// Determines if the arguments constitute UTF-16 surrogate pair
// and thus should be combined into a single Unicode code point
// using CreateCodePointFromUtf16SurrogatePair.
inline bool IsUtf16SurrogatePair(wchar_t first, wchar_t second) {
return sizeof(wchar_t) == 2 &&
(first & 0xFC00) == 0xD800 && (second & 0xFC00) == 0xDC00;
}
// Creates a Unicode code point from UTF16 surrogate pair.
inline UInt32 CreateCodePointFromUtf16SurrogatePair(wchar_t first,
wchar_t second) {
const UInt32 mask = (1 << 10) - 1;
return (sizeof(wchar_t) == 2) ?
(((first & mask) << 10) | (second & mask)) + 0x10000 :
// This function should not be called when the condition is
// false, but we provide a sensible default in case it is.
static_cast<UInt32>(first);
}
// Converts a wide string to a narrow string in UTF-8 encoding.
// The wide string is assumed to have the following encoding:
// UTF-16 if sizeof(wchar_t) == 2 (on Windows, Cygwin, Symbian OS)
// UTF-32 if sizeof(wchar_t) == 4 (on Linux)
// Parameter str points to a null-terminated wide string.
// Parameter num_chars may additionally limit the number
// of wchar_t characters processed. -1 is used when the entire string
// should be processed.
// If the string contains code points that are not valid Unicode code points
// (i.e. outside of Unicode range U+0 to U+10FFFF) they will be output
// as '(Invalid Unicode 0xXXXXXXXX)'. If the string is in UTF16 encoding
// and contains invalid UTF-16 surrogate pairs, values in those pairs
// will be encoded as individual Unicode characters from Basic Normal Plane.
String WideStringToUtf8(const wchar_t* str, int num_chars) {
if (num_chars == -1)
num_chars = static_cast<int>(wcslen(str));
::std::stringstream stream;
for (int i = 0; i < num_chars; ++i) {
UInt32 unicode_code_point;
if (str[i] == L'\0') {
break;
} else if (i + 1 < num_chars && IsUtf16SurrogatePair(str[i], str[i + 1])) {
unicode_code_point = CreateCodePointFromUtf16SurrogatePair(str[i],
str[i + 1]);
i++;
} else {
unicode_code_point = static_cast<UInt32>(str[i]);
}
char buffer[32]; // CodePointToUtf8 requires a buffer this big.
stream << CodePointToUtf8(unicode_code_point, buffer);
}
return StringStreamToString(&stream);
}
// Converts a wide C string to a String using the UTF-8 encoding.
// NULL will be converted to "(null)".
String String::ShowWideCString(const wchar_t * wide_c_str) {
if (wide_c_str == NULL) return String("(null)");
return String(internal::WideStringToUtf8(wide_c_str, -1).c_str());
}
// Similar to ShowWideCString(), except that this function encloses
// the converted string in double quotes.
String String::ShowWideCStringQuoted(const wchar_t* wide_c_str) {
if (wide_c_str == NULL) return String("(null)");
return String::Format("L\"%s\"",
String::ShowWideCString(wide_c_str).c_str());
}
// Compares two wide C strings. Returns true iff they have the same
// content.
//
// Unlike wcscmp(), this function can handle NULL argument(s). A NULL
// C string is considered different to any non-NULL C string,
// including the empty string.
bool String::WideCStringEquals(const wchar_t * lhs, const wchar_t * rhs) {
if (lhs == NULL) return rhs == NULL;
if (rhs == NULL) return false;
return wcscmp(lhs, rhs) == 0;
}
// Helper function for *_STREQ on wide strings.
AssertionResult CmpHelperSTREQ(const char* expected_expression,
const char* actual_expression,
const wchar_t* expected,
const wchar_t* actual) {
if (String::WideCStringEquals(expected, actual)) {
return AssertionSuccess();
}
return EqFailure(expected_expression,
actual_expression,
String::ShowWideCStringQuoted(expected),
String::ShowWideCStringQuoted(actual),
false);
}
// Helper function for *_STRNE on wide strings.
AssertionResult CmpHelperSTRNE(const char* s1_expression,
const char* s2_expression,
const wchar_t* s1,
const wchar_t* s2) {
if (!String::WideCStringEquals(s1, s2)) {
return AssertionSuccess();
}
return AssertionFailure() << "Expected: (" << s1_expression << ") != ("
<< s2_expression << "), actual: "
<< String::ShowWideCStringQuoted(s1)
<< " vs " << String::ShowWideCStringQuoted(s2);
}
// Compares two C strings, ignoring case. Returns true iff they have
// the same content.
//
// Unlike strcasecmp(), this function can handle NULL argument(s). A
// NULL C string is considered different to any non-NULL C string,
// including the empty string.
bool String::CaseInsensitiveCStringEquals(const char * lhs, const char * rhs) {
if (lhs == NULL)
return rhs == NULL;
if (rhs == NULL)
return false;
return posix::StrCaseCmp(lhs, rhs) == 0;
}
// Compares two wide C strings, ignoring case. Returns true iff they
// have the same content.
//
// Unlike wcscasecmp(), this function can handle NULL argument(s).
// A NULL C string is considered different to any non-NULL wide C string,
// including the empty string.
// NB: The implementations on different platforms slightly differ.
// On windows, this method uses _wcsicmp which compares according to LC_CTYPE
// environment variable. On GNU platform this method uses wcscasecmp
// which compares according to LC_CTYPE category of the current locale.
// On MacOS X, it uses towlower, which also uses LC_CTYPE category of the
// current locale.
bool String::CaseInsensitiveWideCStringEquals(const wchar_t* lhs,
const wchar_t* rhs) {
if (lhs == NULL) return rhs == NULL;
if (rhs == NULL) return false;
#if GTEST_OS_WINDOWS
return _wcsicmp(lhs, rhs) == 0;
#elif GTEST_OS_LINUX && !GTEST_OS_LINUX_ANDROID
return wcscasecmp(lhs, rhs) == 0;
#else
// Android, Mac OS X and Cygwin don't define wcscasecmp.
// Other unknown OSes may not define it either.
wint_t left, right;
do {
left = towlower(*lhs++);
right = towlower(*rhs++);
} while (left && left == right);
return left == right;
#endif // OS selector
}
// Compares this with another String.
// Returns < 0 if this is less than rhs, 0 if this is equal to rhs, or > 0
// if this is greater than rhs.
int String::Compare(const String & rhs) const {
const char* const lhs_c_str = c_str();
const char* const rhs_c_str = rhs.c_str();
if (lhs_c_str == NULL) {
return rhs_c_str == NULL ? 0 : -1; // NULL < anything except NULL
} else if (rhs_c_str == NULL) {
return 1;
}
const size_t shorter_str_len =
length() <= rhs.length() ? length() : rhs.length();
for (size_t i = 0; i != shorter_str_len; i++) {
if (lhs_c_str[i] < rhs_c_str[i]) {
return -1;
} else if (lhs_c_str[i] > rhs_c_str[i]) {
return 1;
}
}
return (length() < rhs.length()) ? -1 :
(length() > rhs.length()) ? 1 : 0;
}
// Returns true iff this String ends with the given suffix. *Any*
// String is considered to end with a NULL or empty suffix.
bool String::EndsWith(const char* suffix) const {
if (suffix == NULL || CStringEquals(suffix, "")) return true;
if (c_str() == NULL) return false;
const size_t this_len = strlen(c_str());
const size_t suffix_len = strlen(suffix);
return (this_len >= suffix_len) &&
CStringEquals(c_str() + this_len - suffix_len, suffix);
}
// Returns true iff this String ends with the given suffix, ignoring case.
// Any String is considered to end with a NULL or empty suffix.
bool String::EndsWithCaseInsensitive(const char* suffix) const {
if (suffix == NULL || CStringEquals(suffix, "")) return true;
if (c_str() == NULL) return false;
const size_t this_len = strlen(c_str());
const size_t suffix_len = strlen(suffix);
return (this_len >= suffix_len) &&
CaseInsensitiveCStringEquals(c_str() + this_len - suffix_len, suffix);
}
// Formats a list of arguments to a String, using the same format
// spec string as for printf.
//
// We do not use the StringPrintf class as it is not universally
// available.
//
// The result is limited to 4096 characters (including the tailing 0).
// If 4096 characters are not enough to format the input, or if
// there's an error, "<formatting error or buffer exceeded>" is
// returned.
String String::Format(const char * format, ...) {
va_list args;
va_start(args, format);
char buffer[4096];
const int kBufferSize = sizeof(buffer)/sizeof(buffer[0]);
// MSVC 8 deprecates vsnprintf(), so we want to suppress warning
// 4996 (deprecated function) there.
#ifdef _MSC_VER // We are using MSVC.
# pragma warning(push) // Saves the current warning state.
# pragma warning(disable:4996) // Temporarily disables warning 4996.
const int size = vsnprintf(buffer, kBufferSize, format, args);
# pragma warning(pop) // Restores the warning state.
#else // We are not using MSVC.
const int size = vsnprintf(buffer, kBufferSize, format, args);
#endif // _MSC_VER
va_end(args);
// vsnprintf()'s behavior is not portable. When the buffer is not
// big enough, it returns a negative value in MSVC, and returns the
// needed buffer size on Linux. When there is an output error, it
// always returns a negative value. For simplicity, we lump the two
// error cases together.
if (size < 0 || size >= kBufferSize) {
return String("<formatting error or buffer exceeded>");
} else {
return String(buffer, size);
}
}
// Converts the buffer in a stringstream to a String, converting NUL
// bytes to "\\0" along the way.
String StringStreamToString(::std::stringstream* ss) {
const ::std::string& str = ss->str();
const char* const start = str.c_str();
const char* const end = start + str.length();
// We need to use a helper stringstream to do this transformation
// because String doesn't support push_back().
::std::stringstream helper;
for (const char* ch = start; ch != end; ++ch) {
if (*ch == '\0') {
helper << "\\0"; // Replaces NUL with "\\0";
} else {
helper.put(*ch);
}
}
return String(helper.str().c_str());
}
// Appends the user-supplied message to the Google-Test-generated message.
String AppendUserMessage(const String& gtest_msg,
const Message& user_msg) {
// Appends the user message if it's non-empty.
const String user_msg_string = user_msg.GetString();
if (user_msg_string.empty()) {
return gtest_msg;
}
Message msg;
msg << gtest_msg << "\n" << user_msg_string;
return msg.GetString();
}
} // namespace internal
// class TestResult
// Creates an empty TestResult.
TestResult::TestResult()
: death_test_count_(0),
elapsed_time_(0) {
}
// D'tor.
TestResult::~TestResult() {
}
// Returns the i-th test part result among all the results. i can
// range from 0 to total_part_count() - 1. If i is not in that range,
// aborts the program.
const TestPartResult& TestResult::GetTestPartResult(int i) const {
if (i < 0 || i >= total_part_count())
internal::posix::Abort();
return test_part_results_.at(i);
}
// Returns the i-th test property. i can range from 0 to
// test_property_count() - 1. If i is not in that range, aborts the
// program.
const TestProperty& TestResult::GetTestProperty(int i) const {
if (i < 0 || i >= test_property_count())
internal::posix::Abort();
return test_properties_.at(i);
}
// Clears the test part results.
void TestResult::ClearTestPartResults() {
test_part_results_.clear();
}
// Adds a test part result to the list.
void TestResult::AddTestPartResult(const TestPartResult& test_part_result) {
test_part_results_.push_back(test_part_result);
}
// Adds a test property to the list. If a property with the same key as the
// supplied property is already represented, the value of this test_property
// replaces the old value for that key.
void TestResult::RecordProperty(const TestProperty& test_property) {
if (!ValidateTestProperty(test_property)) {
return;
}
internal::MutexLock lock(&test_properites_mutex_);
const std::vector<TestProperty>::iterator property_with_matching_key =
std::find_if(test_properties_.begin(), test_properties_.end(),
internal::TestPropertyKeyIs(test_property.key()));
if (property_with_matching_key == test_properties_.end()) {
test_properties_.push_back(test_property);
return;
}
property_with_matching_key->SetValue(test_property.value());
}
// Adds a failure if the key is a reserved attribute of Google Test
// testcase tags. Returns true if the property is valid.
bool TestResult::ValidateTestProperty(const TestProperty& test_property) {
internal::String key(test_property.key());
if (key == "name" || key == "status" || key == "time" || key == "classname") {
ADD_FAILURE()
<< "Reserved key used in RecordProperty(): "
<< key
<< " ('name', 'status', 'time', and 'classname' are reserved by "
<< GTEST_NAME_ << ")";
return false;
}
return true;
}
// Clears the object.
void TestResult::Clear() {
test_part_results_.clear();
test_properties_.clear();
death_test_count_ = 0;
elapsed_time_ = 0;
}
// Returns true iff the test failed.
bool TestResult::Failed() const {
for (int i = 0; i < total_part_count(); ++i) {
if (GetTestPartResult(i).failed())
return true;
}
return false;
}
// Returns true iff the test part fatally failed.
static bool TestPartFatallyFailed(const TestPartResult& result) {
return result.fatally_failed();
}
// Returns true iff the test fatally failed.
bool TestResult::HasFatalFailure() const {
return CountIf(test_part_results_, TestPartFatallyFailed) > 0;
}
// Returns true iff the test part non-fatally failed.
static bool TestPartNonfatallyFailed(const TestPartResult& result) {
return result.nonfatally_failed();
}
// Returns true iff the test has a non-fatal failure.
bool TestResult::HasNonfatalFailure() const {
return CountIf(test_part_results_, TestPartNonfatallyFailed) > 0;
}
// Gets the number of all test parts. This is the sum of the number
// of successful test parts and the number of failed test parts.
int TestResult::total_part_count() const {
return static_cast<int>(test_part_results_.size());
}
// Returns the number of the test properties.
int TestResult::test_property_count() const {
return static_cast<int>(test_properties_.size());
}
// class Test
// Creates a Test object.
// The c'tor saves the values of all Google Test flags.
Test::Test()
: gtest_flag_saver_(new internal::GTestFlagSaver) {
}
// The d'tor restores the values of all Google Test flags.
Test::~Test() {
delete gtest_flag_saver_;
}
// Sets up the test fixture.
//
// A sub-class may override this.
void Test::SetUp() {
}
// Tears down the test fixture.
//
// A sub-class may override this.
void Test::TearDown() {
}
// Allows user supplied key value pairs to be recorded for later output.
void Test::RecordProperty(const char* key, const char* value) {
UnitTest::GetInstance()->RecordPropertyForCurrentTest(key, value);
}
// Allows user supplied key value pairs to be recorded for later output.
void Test::RecordProperty(const char* key, int value) {
Message value_message;
value_message << value;
RecordProperty(key, value_message.GetString().c_str());
}
namespace internal {
void ReportFailureInUnknownLocation(TestPartResult::Type result_type,
const String& message) {
// This function is a friend of UnitTest and as such has access to
// AddTestPartResult.
UnitTest::GetInstance()->AddTestPartResult(
result_type,
NULL, // No info about the source file where the exception occurred.
-1, // We have no info on which line caused the exception.
message,
String()); // No stack trace, either.
}
} // namespace internal
// Google Test requires all tests in the same test case to use the same test
// fixture class. This function checks if the current test has the
// same fixture class as the first test in the current test case. If
// yes, it returns true; otherwise it generates a Google Test failure and
// returns false.
bool Test::HasSameFixtureClass() {
internal::UnitTestImpl* const impl = internal::GetUnitTestImpl();
const TestCase* const test_case = impl->current_test_case();
// Info about the first test in the current test case.
const TestInfo* const first_test_info = test_case->test_info_list()[0];
const internal::TypeId first_fixture_id = first_test_info->fixture_class_id_;
const char* const first_test_name = first_test_info->name();
// Info about the current test.
const TestInfo* const this_test_info = impl->current_test_info();
const internal::TypeId this_fixture_id = this_test_info->fixture_class_id_;
const char* const this_test_name = this_test_info->name();
if (this_fixture_id != first_fixture_id) {
// Is the first test defined using TEST?
const bool first_is_TEST = first_fixture_id == internal::GetTestTypeId();
// Is this test defined using TEST?
const bool this_is_TEST = this_fixture_id == internal::GetTestTypeId();
if (first_is_TEST || this_is_TEST) {
// The user mixed TEST and TEST_F in this test case - we'll tell
// him/her how to fix it.
// Gets the name of the TEST and the name of the TEST_F. Note
// that first_is_TEST and this_is_TEST cannot both be true, as
// the fixture IDs are different for the two tests.
const char* const TEST_name =
first_is_TEST ? first_test_name : this_test_name;
const char* const TEST_F_name =
first_is_TEST ? this_test_name : first_test_name;
ADD_FAILURE()
<< "All tests in the same test case must use the same test fixture\n"
<< "class, so mixing TEST_F and TEST in the same test case is\n"
<< "illegal. In test case " << this_test_info->test_case_name()
<< ",\n"
<< "test " << TEST_F_name << " is defined using TEST_F but\n"
<< "test " << TEST_name << " is defined using TEST. You probably\n"
<< "want to change the TEST to TEST_F or move it to another test\n"
<< "case.";
} else {
// The user defined two fixture classes with the same name in
// two namespaces - we'll tell him/her how to fix it.
ADD_FAILURE()
<< "All tests in the same test case must use the same test fixture\n"
<< "class. However, in test case "
<< this_test_info->test_case_name() << ",\n"
<< "you defined test " << first_test_name
<< " and test " << this_test_name << "\n"
<< "using two different test fixture classes. This can happen if\n"
<< "the two classes are from different namespaces or translation\n"
<< "units and have the same name. You should probably rename one\n"
<< "of the classes to put the tests into different test cases.";
}
return false;
}
return true;
}
#if GTEST_HAS_SEH
// Adds an "exception thrown" fatal failure to the current test. This
// function returns its result via an output parameter pointer because VC++
// prohibits creation of objects with destructors on stack in functions
// using __try (see error C2712).
static internal::String* FormatSehExceptionMessage(DWORD exception_code,
const char* location) {
Message message;
message << "SEH exception with code 0x" << std::setbase(16) <<
exception_code << std::setbase(10) << " thrown in " << location << ".";
return new internal::String(message.GetString());
}
#endif // GTEST_HAS_SEH
#if GTEST_HAS_EXCEPTIONS
// Adds an "exception thrown" fatal failure to the current test.
static internal::String FormatCxxExceptionMessage(const char* description,
const char* location) {
Message message;
if (description != NULL) {
message << "C++ exception with description \"" << description << "\"";
} else {
message << "Unknown C++ exception";
}
message << " thrown in " << location << ".";
return message.GetString();
}
static internal::String PrintTestPartResultToString(
const TestPartResult& test_part_result);
// A failed Google Test assertion will throw an exception of this type when
// GTEST_FLAG(throw_on_failure) is true (if exceptions are enabled). We
// derive it from std::runtime_error, which is for errors presumably
// detectable only at run time. Since std::runtime_error inherits from
// std::exception, many testing frameworks know how to extract and print the
// message inside it.
class GoogleTestFailureException : public ::std::runtime_error {
public:
explicit GoogleTestFailureException(const TestPartResult& failure)
: ::std::runtime_error(PrintTestPartResultToString(failure).c_str()) {}
};
#endif // GTEST_HAS_EXCEPTIONS
namespace internal {
// We put these helper functions in the internal namespace as IBM's xlC
// compiler rejects the code if they were declared static.
// Runs the given method and handles SEH exceptions it throws, when
// SEH is supported; returns the 0-value for type Result in case of an
// SEH exception. (Microsoft compilers cannot handle SEH and C++
// exceptions in the same function. Therefore, we provide a separate
// wrapper function for handling SEH exceptions.)
template <class T, typename Result>
Result HandleSehExceptionsInMethodIfSupported(
T* object, Result (T::*method)(), const char* location) {
#if GTEST_HAS_SEH
__try {
return (object->*method)();
} __except (internal::UnitTestOptions::GTestShouldProcessSEH( // NOLINT
GetExceptionCode())) {
// We create the exception message on the heap because VC++ prohibits
// creation of objects with destructors on stack in functions using __try
// (see error C2712).
internal::String* exception_message = FormatSehExceptionMessage(
GetExceptionCode(), location);
internal::ReportFailureInUnknownLocation(TestPartResult::kFatalFailure,
*exception_message);
delete exception_message;
return static_cast<Result>(0);
}
#else
(void)location;
return (object->*method)();
#endif // GTEST_HAS_SEH
}
// Runs the given method and catches and reports C++ and/or SEH-style
// exceptions, if they are supported; returns the 0-value for type
// Result in case of an SEH exception.
template <class T, typename Result>
Result HandleExceptionsInMethodIfSupported(
T* object, Result (T::*method)(), const char* location) {
// NOTE: The user code can affect the way in which Google Test handles
// exceptions by setting GTEST_FLAG(catch_exceptions), but only before
// RUN_ALL_TESTS() starts. It is technically possible to check the flag
// after the exception is caught and either report or re-throw the
// exception based on the flag's value:
//
// try {
// // Perform the test method.
// } catch (...) {
// if (GTEST_FLAG(catch_exceptions))
// // Report the exception as failure.
// else
// throw; // Re-throws the original exception.
// }
//
// However, the purpose of this flag is to allow the program to drop into
// the debugger when the exception is thrown. On most platforms, once the
// control enters the catch block, the exception origin information is
// lost and the debugger will stop the program at the point of the
// re-throw in this function -- instead of at the point of the original
// throw statement in the code under test. For this reason, we perform
// the check early, sacrificing the ability to affect Google Test's
// exception handling in the method where the exception is thrown.
if (internal::GetUnitTestImpl()->catch_exceptions()) {
#if GTEST_HAS_EXCEPTIONS
try {
return HandleSehExceptionsInMethodIfSupported(object, method, location);
} catch (const GoogleTestFailureException&) { // NOLINT
// This exception doesn't originate in code under test. It makes no
// sense to report it as a test failure.
throw;
} catch (const std::exception& e) { // NOLINT
internal::ReportFailureInUnknownLocation(
TestPartResult::kFatalFailure,
FormatCxxExceptionMessage(e.what(), location));
} catch (...) { // NOLINT
internal::ReportFailureInUnknownLocation(
TestPartResult::kFatalFailure,
FormatCxxExceptionMessage(NULL, location));
}
return static_cast<Result>(0);
#else
return HandleSehExceptionsInMethodIfSupported(object, method, location);
#endif // GTEST_HAS_EXCEPTIONS
} else {
return (object->*method)();
}
}
} // namespace internal
// Runs the test and updates the test result.
void Test::Run() {
if (!HasSameFixtureClass()) return;
internal::UnitTestImpl* const impl = internal::GetUnitTestImpl();
impl->os_stack_trace_getter()->UponLeavingGTest();
internal::HandleExceptionsInMethodIfSupported(this, &Test::SetUp, "SetUp()");
// We will run the test only if SetUp() was successful.
if (!HasFatalFailure()) {
impl->os_stack_trace_getter()->UponLeavingGTest();
internal::HandleExceptionsInMethodIfSupported(
this, &Test::TestBody, "the test body");
}
// However, we want to clean up as much as possible. Hence we will
// always call TearDown(), even if SetUp() or the test body has
// failed.
impl->os_stack_trace_getter()->UponLeavingGTest();
internal::HandleExceptionsInMethodIfSupported(
this, &Test::TearDown, "TearDown()");
}
// Returns true iff the current test has a fatal failure.
bool Test::HasFatalFailure() {
return internal::GetUnitTestImpl()->current_test_result()->HasFatalFailure();
}
// Returns true iff the current test has a non-fatal failure.
bool Test::HasNonfatalFailure() {
return internal::GetUnitTestImpl()->current_test_result()->
HasNonfatalFailure();
}
// class TestInfo
// Constructs a TestInfo object. It assumes ownership of the test factory
// object.
// TODO(vladl@google.com): Make a_test_case_name and a_name const string&'s
// to signify they cannot be NULLs.
TestInfo::TestInfo(const char* a_test_case_name,
const char* a_name,
const char* a_type_param,
const char* a_value_param,
internal::TypeId fixture_class_id,
internal::TestFactoryBase* factory)
: test_case_name_(a_test_case_name),
name_(a_name),
type_param_(a_type_param ? new std::string(a_type_param) : NULL),
value_param_(a_value_param ? new std::string(a_value_param) : NULL),
fixture_class_id_(fixture_class_id),
should_run_(false),
is_disabled_(false),
matches_filter_(false),
factory_(factory),
result_() {}
// Destructs a TestInfo object.
TestInfo::~TestInfo() { delete factory_; }
namespace internal {
// Creates a new TestInfo object and registers it with Google Test;
// returns the created object.
//
// Arguments:
//
// test_case_name: name of the test case
// name: name of the test
// type_param: the name of the test's type parameter, or NULL if
// this is not a typed or a type-parameterized test.
// value_param: text representation of the test's value parameter,
// or NULL if this is not a value-parameterized test.
// fixture_class_id: ID of the test fixture class
// set_up_tc: pointer to the function that sets up the test case
// tear_down_tc: pointer to the function that tears down the test case
// factory: pointer to the factory that creates a test object.
// The newly created TestInfo instance will assume
// ownership of the factory object.
TestInfo* MakeAndRegisterTestInfo(
const char* test_case_name, const char* name,
const char* type_param,
const char* value_param,
TypeId fixture_class_id,
SetUpTestCaseFunc set_up_tc,
TearDownTestCaseFunc tear_down_tc,
TestFactoryBase* factory) {
TestInfo* const test_info =
new TestInfo(test_case_name, name, type_param, value_param,
fixture_class_id, factory);
GetUnitTestImpl()->AddTestInfo(set_up_tc, tear_down_tc, test_info);
return test_info;
}
#if GTEST_HAS_PARAM_TEST
void ReportInvalidTestCaseType(const char* test_case_name,
const char* file, int line) {
Message errors;
errors
<< "Attempted redefinition of test case " << test_case_name << ".\n"
<< "All tests in the same test case must use the same test fixture\n"
<< "class. However, in test case " << test_case_name << ", you tried\n"
<< "to define a test using a fixture class different from the one\n"
<< "used earlier. This can happen if the two fixture classes are\n"
<< "from different namespaces and have the same name. You should\n"
<< "probably rename one of the classes to put the tests into different\n"
<< "test cases.";
fprintf(stderr, "%s %s", FormatFileLocation(file, line).c_str(),
errors.GetString().c_str());
}
#endif // GTEST_HAS_PARAM_TEST
} // namespace internal
namespace {
// A predicate that checks the test name of a TestInfo against a known
// value.
//
// This is used for implementation of the TestCase class only. We put
// it in the anonymous namespace to prevent polluting the outer
// namespace.
//
// TestNameIs is copyable.
class TestNameIs {
public:
// Constructor.
//
// TestNameIs has NO default constructor.
explicit TestNameIs(const char* name)
: name_(name) {}
// Returns true iff the test name of test_info matches name_.
bool operator()(const TestInfo * test_info) const {
return test_info && internal::String(test_info->name()).Compare(name_) == 0;
}
private:
internal::String name_;
};
} // namespace
namespace internal {
// This method expands all parameterized tests registered with macros TEST_P
// and INSTANTIATE_TEST_CASE_P into regular tests and registers those.
// This will be done just once during the program runtime.
void UnitTestImpl::RegisterParameterizedTests() {
#if GTEST_HAS_PARAM_TEST
if (!parameterized_tests_registered_) {
parameterized_test_registry_.RegisterTests();
parameterized_tests_registered_ = true;
}
#endif
}
} // namespace internal
// Creates the test object, runs it, records its result, and then
// deletes it.
void TestInfo::Run() {
if (!should_run_) return;
// Tells UnitTest where to store test result.
internal::UnitTestImpl* const impl = internal::GetUnitTestImpl();
impl->set_current_test_info(this);
TestEventListener* repeater = UnitTest::GetInstance()->listeners().repeater();
// Notifies the unit test event listeners that a test is about to start.
repeater->OnTestStart(*this);
const TimeInMillis start = internal::GetTimeInMillis();
impl->os_stack_trace_getter()->UponLeavingGTest();
// Creates the test object.
Test* const test = internal::HandleExceptionsInMethodIfSupported(
factory_, &internal::TestFactoryBase::CreateTest,
"the test fixture's constructor");
// Runs the test only if the test object was created and its
// constructor didn't generate a fatal failure.
if ((test != NULL) && !Test::HasFatalFailure()) {
// This doesn't throw as all user code that can throw are wrapped into
// exception handling code.
test->Run();
}
// Deletes the test object.
impl->os_stack_trace_getter()->UponLeavingGTest();
internal::HandleExceptionsInMethodIfSupported(
test, &Test::DeleteSelf_, "the test fixture's destructor");
result_.set_elapsed_time(internal::GetTimeInMillis() - start);
// Notifies the unit test event listener that a test has just finished.
repeater->OnTestEnd(*this);
// Tells UnitTest to stop associating assertion results to this
// test.
impl->set_current_test_info(NULL);
}
// class TestCase
// Gets the number of successful tests in this test case.
int TestCase::successful_test_count() const {
return CountIf(test_info_list_, TestPassed);
}
// Gets the number of failed tests in this test case.
int TestCase::failed_test_count() const {
return CountIf(test_info_list_, TestFailed);
}
int TestCase::disabled_test_count() const {
return CountIf(test_info_list_, TestDisabled);
}
// Get the number of tests in this test case that should run.
int TestCase::test_to_run_count() const {
return CountIf(test_info_list_, ShouldRunTest);
}
// Gets the number of all tests.
int TestCase::total_test_count() const {
return static_cast<int>(test_info_list_.size());
}
// Creates a TestCase with the given name.
//
// Arguments:
//
// name: name of the test case
// a_type_param: the name of the test case's type parameter, or NULL if
// this is not a typed or a type-parameterized test case.
// set_up_tc: pointer to the function that sets up the test case
// tear_down_tc: pointer to the function that tears down the test case
TestCase::TestCase(const char* a_name, const char* a_type_param,
Test::SetUpTestCaseFunc set_up_tc,
Test::TearDownTestCaseFunc tear_down_tc)
: name_(a_name),
type_param_(a_type_param ? new std::string(a_type_param) : NULL),
set_up_tc_(set_up_tc),
tear_down_tc_(tear_down_tc),
should_run_(false),
elapsed_time_(0) {
}
// Destructor of TestCase.
TestCase::~TestCase() {
// Deletes every Test in the collection.
ForEach(test_info_list_, internal::Delete<TestInfo>);
}
// Returns the i-th test among all the tests. i can range from 0 to
// total_test_count() - 1. If i is not in that range, returns NULL.
const TestInfo* TestCase::GetTestInfo(int i) const {
const int index = GetElementOr(test_indices_, i, -1);
return index < 0 ? NULL : test_info_list_[index];
}
// Returns the i-th test among all the tests. i can range from 0 to
// total_test_count() - 1. If i is not in that range, returns NULL.
TestInfo* TestCase::GetMutableTestInfo(int i) {
const int index = GetElementOr(test_indices_, i, -1);
return index < 0 ? NULL : test_info_list_[index];
}
// Adds a test to this test case. Will delete the test upon
// destruction of the TestCase object.
void TestCase::AddTestInfo(TestInfo * test_info) {
test_info_list_.push_back(test_info);
test_indices_.push_back(static_cast<int>(test_indices_.size()));
}
// Runs every test in this TestCase.
void TestCase::Run() {
if (!should_run_) return;
internal::UnitTestImpl* const impl = internal::GetUnitTestImpl();
impl->set_current_test_case(this);
TestEventListener* repeater = UnitTest::GetInstance()->listeners().repeater();
repeater->OnTestCaseStart(*this);
impl->os_stack_trace_getter()->UponLeavingGTest();
internal::HandleExceptionsInMethodIfSupported(
this, &TestCase::RunSetUpTestCase, "SetUpTestCase()");
const internal::TimeInMillis start = internal::GetTimeInMillis();
for (int i = 0; i < total_test_count(); i++) {
GetMutableTestInfo(i)->Run();
}
elapsed_time_ = internal::GetTimeInMillis() - start;
impl->os_stack_trace_getter()->UponLeavingGTest();
internal::HandleExceptionsInMethodIfSupported(
this, &TestCase::RunTearDownTestCase, "TearDownTestCase()");
repeater->OnTestCaseEnd(*this);
impl->set_current_test_case(NULL);
}
// Clears the results of all tests in this test case.
void TestCase::ClearResult() {
ForEach(test_info_list_, TestInfo::ClearTestResult);
}
// Shuffles the tests in this test case.
void TestCase::ShuffleTests(internal::Random* random) {
Shuffle(random, &test_indices_);
}
// Restores the test order to before the first shuffle.
void TestCase::UnshuffleTests() {
for (size_t i = 0; i < test_indices_.size(); i++) {
test_indices_[i] = static_cast<int>(i);
}
}
// Formats a countable noun. Depending on its quantity, either the
// singular form or the plural form is used. e.g.
//
// FormatCountableNoun(1, "formula", "formuli") returns "1 formula".
// FormatCountableNoun(5, "book", "books") returns "5 books".
static internal::String FormatCountableNoun(int count,
const char * singular_form,
const char * plural_form) {
return internal::String::Format("%d %s", count,
count == 1 ? singular_form : plural_form);
}
// Formats the count of tests.
static internal::String FormatTestCount(int test_count) {
return FormatCountableNoun(test_count, "test", "tests");
}
// Formats the count of test cases.
static internal::String FormatTestCaseCount(int test_case_count) {
return FormatCountableNoun(test_case_count, "test case", "test cases");
}
// Converts a TestPartResult::Type enum to human-friendly string
// representation. Both kNonFatalFailure and kFatalFailure are translated
// to "Failure", as the user usually doesn't care about the difference
// between the two when viewing the test result.
static const char * TestPartResultTypeToString(TestPartResult::Type type) {
switch (type) {
case TestPartResult::kSuccess:
return "Success";
case TestPartResult::kNonFatalFailure:
case TestPartResult::kFatalFailure:
#ifdef _MSC_VER
return "error: ";
#else
return "Failure\n";
#endif
default:
return "Unknown result type";
}
}
// Prints a TestPartResult to a String.
static internal::String PrintTestPartResultToString(
const TestPartResult& test_part_result) {
return (Message()
<< internal::FormatFileLocation(test_part_result.file_name(),
test_part_result.line_number())
<< " " << TestPartResultTypeToString(test_part_result.type())
<< test_part_result.message()).GetString();
}
// Prints a TestPartResult.
static void PrintTestPartResult(const TestPartResult& test_part_result) {
const internal::String& result =
PrintTestPartResultToString(test_part_result);
printf("%s\n", result.c_str());
fflush(stdout);
// If the test program runs in Visual Studio or a debugger, the
// following statements add the test part result message to the Output
// window such that the user can double-click on it to jump to the
// corresponding source code location; otherwise they do nothing.
#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE
// We don't call OutputDebugString*() on Windows Mobile, as printing
// to stdout is done by OutputDebugString() there already - we don't
// want the same message printed twice.
::OutputDebugStringA(result.c_str());
::OutputDebugStringA("\n");
#endif
}
// class PrettyUnitTestResultPrinter
namespace internal {
enum GTestColor {
COLOR_DEFAULT,
COLOR_RED,
COLOR_GREEN,
COLOR_YELLOW
};
#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE
// Returns the character attribute for the given color.
WORD GetColorAttribute(GTestColor color) {
switch (color) {
case COLOR_RED: return FOREGROUND_RED;
case COLOR_GREEN: return FOREGROUND_GREEN;
case COLOR_YELLOW: return FOREGROUND_RED | FOREGROUND_GREEN;
default: return 0;
}
}
#else
// Returns the ANSI color code for the given color. COLOR_DEFAULT is
// an invalid input.
const char* GetAnsiColorCode(GTestColor color) {
switch (color) {
case COLOR_RED: return "1";
case COLOR_GREEN: return "2";
case COLOR_YELLOW: return "3";
default: return NULL;
};
}
#endif // GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE
// Returns true iff Google Test should use colors in the output.
bool ShouldUseColor(bool stdout_is_tty) {
const char* const gtest_color = GTEST_FLAG(color).c_str();
if (String::CaseInsensitiveCStringEquals(gtest_color, "auto")) {
#if GTEST_OS_WINDOWS
// On Windows the TERM variable is usually not set, but the
// console there does support colors.
return stdout_is_tty;
#else
// On non-Windows platforms, we rely on the TERM variable.
const char* const term = posix::GetEnv("TERM");
const bool term_supports_color =
String::CStringEquals(term, "xterm") ||
String::CStringEquals(term, "xterm-color") ||
String::CStringEquals(term, "xterm-256color") ||
String::CStringEquals(term, "screen") ||
String::CStringEquals(term, "linux") ||
String::CStringEquals(term, "cygwin");
return stdout_is_tty && term_supports_color;
#endif // GTEST_OS_WINDOWS
}
return String::CaseInsensitiveCStringEquals(gtest_color, "yes") ||
String::CaseInsensitiveCStringEquals(gtest_color, "true") ||
String::CaseInsensitiveCStringEquals(gtest_color, "t") ||
String::CStringEquals(gtest_color, "1");
// We take "yes", "true", "t", and "1" as meaning "yes". If the
// value is neither one of these nor "auto", we treat it as "no" to
// be conservative.
}
// Helpers for printing colored strings to stdout. Note that on Windows, we
// cannot simply emit special characters and have the terminal change colors.
// This routine must actually emit the characters rather than return a string
// that would be colored when printed, as can be done on Linux.
void ColoredPrintf(GTestColor color, const char* fmt, ...) {
va_list args;
va_start(args, fmt);
#if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_SYMBIAN || GTEST_OS_ZOS
const bool use_color = false;
#else
static const bool in_color_mode =
ShouldUseColor(posix::IsATTY(posix::FileNo(stdout)) != 0);
const bool use_color = in_color_mode && (color != COLOR_DEFAULT);
#endif // GTEST_OS_WINDOWS_MOBILE || GTEST_OS_SYMBIAN || GTEST_OS_ZOS
// The '!= 0' comparison is necessary to satisfy MSVC 7.1.
if (!use_color) {
vprintf(fmt, args);
va_end(args);
return;
}
#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE
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,
GetColorAttribute(color) | FOREGROUND_INTENSITY);
vprintf(fmt, args);
fflush(stdout);
// Restores the text color.
SetConsoleTextAttribute(stdout_handle, old_color_attrs);
#else
printf("\033[0;3%sm", GetAnsiColorCode(color));
vprintf(fmt, args);
printf("\033[m"); // Resets the terminal to default.
#endif // GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MOBILE
va_end(args);
}
void PrintFullTestCommentIfPresent(const TestInfo& test_info) {
const char* const type_param = test_info.type_param();
const char* const value_param = test_info.value_param();
if (type_param != NULL || value_param != NULL) {
printf(", where ");
if (type_param != NULL) {
printf("TypeParam = %s", type_param);
if (value_param != NULL)
printf(" and ");
}
if (value_param != NULL) {
printf("GetParam() = %s", value_param);
}
}
}
// This class implements the TestEventListener interface.
//
// Class PrettyUnitTestResultPrinter is copyable.
class PrettyUnitTestResultPrinter : public TestEventListener {
public:
PrettyUnitTestResultPrinter() {}
static void PrintTestName(const char * test_case, const char * test) {
printf("%s.%s", test_case, test);
}
// The following methods override what's in the TestEventListener class.
virtual void OnTestProgramStart(const UnitTest& /*unit_test*/) {}
virtual void OnTestIterationStart(const UnitTest& unit_test, int iteration);
virtual void OnEnvironmentsSetUpStart(const UnitTest& unit_test);
virtual void OnEnvironmentsSetUpEnd(const UnitTest& /*unit_test*/) {}
virtual void OnTestCaseStart(const TestCase& test_case);
virtual void OnTestStart(const TestInfo& test_info);
virtual void OnTestPartResult(const TestPartResult& result);
virtual void OnTestEnd(const TestInfo& test_info);
virtual void OnTestCaseEnd(const TestCase& test_case);
virtual void OnEnvironmentsTearDownStart(const UnitTest& unit_test);
virtual void OnEnvironmentsTearDownEnd(const UnitTest& /*unit_test*/) {}
virtual void OnTestIterationEnd(const UnitTest& unit_test, int iteration);
virtual void OnTestProgramEnd(const UnitTest& /*unit_test*/) {}
private:
static void PrintFailedTests(const UnitTest& unit_test);
internal::String test_case_name_;
};
// Fired before each iteration of tests starts.
void PrettyUnitTestResultPrinter::OnTestIterationStart(
const UnitTest& unit_test, int iteration) {
if (GTEST_FLAG(repeat) != 1)
printf("\nRepeating all tests (iteration %d) . . .\n\n", iteration + 1);
const char* const filter = GTEST_FLAG(filter).c_str();
// Prints the filter if it's not *. This reminds the user that some
// tests may be skipped.
if (!internal::String::CStringEquals(filter, kUniversalFilter)) {
ColoredPrintf(COLOR_YELLOW,
"Note: %s filter = %s\n", GTEST_NAME_, filter);
}
if (internal::ShouldShard(kTestTotalShards, kTestShardIndex, false)) {
const Int32 shard_index = Int32FromEnvOrDie(kTestShardIndex, -1);
ColoredPrintf(COLOR_YELLOW,
"Note: This is test shard %d of %s.\n",
static_cast<int>(shard_index) + 1,
internal::posix::GetEnv(kTestTotalShards));
}
if (GTEST_FLAG(shuffle)) {
ColoredPrintf(COLOR_YELLOW,
"Note: Randomizing tests' orders with a seed of %d .\n",
unit_test.random_seed());
}
ColoredPrintf(COLOR_GREEN, "[==========] ");
printf("Running %s from %s.\n",
FormatTestCount(unit_test.test_to_run_count()).c_str(),
FormatTestCaseCount(unit_test.test_case_to_run_count()).c_str());
fflush(stdout);
}
void PrettyUnitTestResultPrinter::OnEnvironmentsSetUpStart(
const UnitTest& /*unit_test*/) {
ColoredPrintf(COLOR_GREEN, "[----------] ");
printf("Global test environment set-up.\n");
fflush(stdout);
}
void PrettyUnitTestResultPrinter::OnTestCaseStart(const TestCase& test_case) {
test_case_name_ = test_case.name();
const internal::String counts =
FormatCountableNoun(test_case.test_to_run_count(), "test", "tests");
ColoredPrintf(COLOR_GREEN, "[----------] ");
printf("%s from %s", counts.c_str(), test_case_name_.c_str());
if (test_case.type_param() == NULL) {
printf("\n");
} else {
printf(", where TypeParam = %s\n", test_case.type_param());
}
fflush(stdout);
}
void PrettyUnitTestResultPrinter::OnTestStart(const TestInfo& test_info) {
ColoredPrintf(COLOR_GREEN, "[ RUN ] ");
PrintTestName(test_case_name_.c_str(), test_info.name());
printf("\n");
fflush(stdout);
}
// Called after an assertion failure.
void PrettyUnitTestResultPrinter::OnTestPartResult(
const TestPartResult& result) {
// If the test part succeeded, we don't need to do anything.
if (result.type() == TestPartResult::kSuccess)
return;
// Print failure message from the assertion (e.g. expected this and got that).
PrintTestPartResult(result);
fflush(stdout);
}
void PrettyUnitTestResultPrinter::OnTestEnd(const TestInfo& test_info) {
if (test_info.result()->Passed()) {
ColoredPrintf(COLOR_GREEN, "[ OK ] ");
} else {
ColoredPrintf(COLOR_RED, "[ FAILED ] ");
}
PrintTestName(test_case_name_.c_str(), test_info.name());
if (test_info.result()->Failed())
PrintFullTestCommentIfPresent(test_info);
if (GTEST_FLAG(print_time)) {
printf(" (%s ms)\n", internal::StreamableToString(
test_info.result()->elapsed_time()).c_str());
} else {
printf("\n");
}
fflush(stdout);
}
void PrettyUnitTestResultPrinter::OnTestCaseEnd(const TestCase& test_case) {
if (!GTEST_FLAG(print_time)) return;
test_case_name_ = test_case.name();
const internal::String counts =
FormatCountableNoun(test_case.test_to_run_count(), "test", "tests");
ColoredPrintf(COLOR_GREEN, "[----------] ");
printf("%s from %s (%s ms total)\n\n",
counts.c_str(), test_case_name_.c_str(),
internal::StreamableToString(test_case.elapsed_time()).c_str());
fflush(stdout);
}
void PrettyUnitTestResultPrinter::OnEnvironmentsTearDownStart(
const UnitTest& /*unit_test*/) {
ColoredPrintf(COLOR_GREEN, "[----------] ");
printf("Global test environment tear-down\n");
fflush(stdout);
}
// Internal helper for printing the list of failed tests.
void PrettyUnitTestResultPrinter::PrintFailedTests(const UnitTest& unit_test) {
const int failed_test_count = unit_test.failed_test_count();
if (failed_test_count == 0) {
return;
}
for (int i = 0; i < unit_test.total_test_case_count(); ++i) {
const TestCase& test_case = *unit_test.GetTestCase(i);
if (!test_case.should_run() || (test_case.failed_test_count() == 0)) {
continue;
}
for (int j = 0; j < test_case.total_test_count(); ++j) {
const TestInfo& test_info = *test_case.GetTestInfo(j);
if (!test_info.should_run() || test_info.result()->Passed()) {
continue;
}
ColoredPrintf(COLOR_RED, "[ FAILED ] ");
printf("%s.%s", test_case.name(), test_info.name());
PrintFullTestCommentIfPresent(test_info);
printf("\n");
}
}
}
void PrettyUnitTestResultPrinter::OnTestIterationEnd(const UnitTest& unit_test,
int /*iteration*/) {
ColoredPrintf(COLOR_GREEN, "[==========] ");
printf("%s from %s ran.",
FormatTestCount(unit_test.test_to_run_count()).c_str(),
FormatTestCaseCount(unit_test.test_case_to_run_count()).c_str());
if (GTEST_FLAG(print_time)) {
printf(" (%s ms total)",
internal::StreamableToString(unit_test.elapsed_time()).c_str());
}
printf("\n");
ColoredPrintf(COLOR_GREEN, "[ PASSED ] ");
printf("%s.\n", FormatTestCount(unit_test.successful_test_count()).c_str());
int num_failures = unit_test.failed_test_count();
if (!unit_test.Passed()) {
const int failed_test_count = unit_test.failed_test_count();
ColoredPrintf(COLOR_RED, "[ FAILED ] ");
printf("%s, listed below:\n", FormatTestCount(failed_test_count).c_str());
PrintFailedTests(unit_test);
printf("\n%2d FAILED %s\n", num_failures,
num_failures == 1 ? "TEST" : "TESTS");
}
int num_disabled = unit_test.disabled_test_count();
if (num_disabled && !GTEST_FLAG(also_run_disabled_tests)) {
if (!num_failures) {
printf("\n"); // Add a spacer if no FAILURE banner is displayed.
}
ColoredPrintf(COLOR_YELLOW,
" YOU HAVE %d DISABLED %s\n\n",
num_disabled,
num_disabled == 1 ? "TEST" : "TESTS");
}
// Ensure that Google Test output is printed before, e.g., heapchecker output.
fflush(stdout);
}
// End PrettyUnitTestResultPrinter
// class TestEventRepeater
//
// This class forwards events to other event listeners.
class TestEventRepeater : public TestEventListener {
public:
TestEventRepeater() : forwarding_enabled_(true) {}
virtual ~TestEventRepeater();
void Append(TestEventListener *listener);
TestEventListener* Release(TestEventListener* listener);
// Controls whether events will be forwarded to listeners_. Set to false
// in death test child processes.
bool forwarding_enabled() const { return forwarding_enabled_; }
void set_forwarding_enabled(bool enable) { forwarding_enabled_ = enable; }
virtual void OnTestProgramStart(const UnitTest& unit_test);
virtual void OnTestIterationStart(const UnitTest& unit_test, int iteration);
virtual void OnEnvironmentsSetUpStart(const UnitTest& unit_test);
virtual void OnEnvironmentsSetUpEnd(const UnitTest& unit_test);
virtual void OnTestCaseStart(const TestCase& test_case);
virtual void OnTestStart(const TestInfo& test_info);
virtual void OnTestPartResult(const TestPartResult& result);
virtual void OnTestEnd(const TestInfo& test_info);
virtual void OnTestCaseEnd(const TestCase& test_case);
virtual void OnEnvironmentsTearDownStart(const UnitTest& unit_test);
virtual void OnEnvironmentsTearDownEnd(const UnitTest& unit_test);
virtual void OnTestIterationEnd(const UnitTest& unit_test, int iteration);
virtual void OnTestProgramEnd(const UnitTest& unit_test);
private:
// Controls whether events will be forwarded to listeners_. Set to false
// in death test child processes.
bool forwarding_enabled_;
// The list of listeners that receive events.
std::vector<TestEventListener*> listeners_;
GTEST_DISALLOW_COPY_AND_ASSIGN_(TestEventRepeater);
};
TestEventRepeater::~TestEventRepeater() {
ForEach(listeners_, Delete<TestEventListener>);
}
void TestEventRepeater::Append(TestEventListener *listener) {
listeners_.push_back(listener);
}
// TODO(vladl@google.com): Factor the search functionality into Vector::Find.
TestEventListener* TestEventRepeater::Release(TestEventListener *listener) {
for (size_t i = 0; i < listeners_.size(); ++i) {
if (listeners_[i] == listener) {
listeners_.erase(listeners_.begin() + i);
return listener;
}
}
return NULL;
}
// Since most methods are very similar, use macros to reduce boilerplate.
// This defines a member that forwards the call to all listeners.
#define GTEST_REPEATER_METHOD_(Name, Type) \
void TestEventRepeater::Name(const Type& parameter) { \
if (forwarding_enabled_) { \
for (size_t i = 0; i < listeners_.size(); i++) { \
listeners_[i]->Name(parameter); \
} \
} \
}
// This defines a member that forwards the call to all listeners in reverse
// order.
#define GTEST_REVERSE_REPEATER_METHOD_(Name, Type) \
void TestEventRepeater::Name(const Type& parameter) { \
if (forwarding_enabled_) { \
for (int i = static_cast<int>(listeners_.size()) - 1; i >= 0; i--) { \
listeners_[i]->Name(parameter); \
} \
} \
}
GTEST_REPEATER_METHOD_(OnTestProgramStart, UnitTest)
GTEST_REPEATER_METHOD_(OnEnvironmentsSetUpStart, UnitTest)
GTEST_REPEATER_METHOD_(OnTestCaseStart, TestCase)
GTEST_REPEATER_METHOD_(OnTestStart, TestInfo)
GTEST_REPEATER_METHOD_(OnTestPartResult, TestPartResult)
GTEST_REPEATER_METHOD_(OnEnvironmentsTearDownStart, UnitTest)
GTEST_REVERSE_REPEATER_METHOD_(OnEnvironmentsSetUpEnd, UnitTest)
GTEST_REVERSE_REPEATER_METHOD_(OnEnvironmentsTearDownEnd, UnitTest)
GTEST_REVERSE_REPEATER_METHOD_(OnTestEnd, TestInfo)
GTEST_REVERSE_REPEATER_METHOD_(OnTestCaseEnd, TestCase)
GTEST_REVERSE_REPEATER_METHOD_(OnTestProgramEnd, UnitTest)
#undef GTEST_REPEATER_METHOD_
#undef GTEST_REVERSE_REPEATER_METHOD_
void TestEventRepeater::OnTestIterationStart(const UnitTest& unit_test,
int iteration) {
if (forwarding_enabled_) {
for (size_t i = 0; i < listeners_.size(); i++) {
listeners_[i]->OnTestIterationStart(unit_test, iteration);
}
}
}
void TestEventRepeater::OnTestIterationEnd(const UnitTest& unit_test,
int iteration) {
if (forwarding_enabled_) {
for (int i = static_cast<int>(listeners_.size()) - 1; i >= 0; i--) {
listeners_[i]->OnTestIterationEnd(unit_test, iteration);
}
}
}
// End TestEventRepeater
// This class generates an XML output file.
class XmlUnitTestResultPrinter : public EmptyTestEventListener {
public:
explicit XmlUnitTestResultPrinter(const char* output_file);
virtual void OnTestIterationEnd(const UnitTest& unit_test, int iteration);
private:
// Is c a whitespace character that is normalized to a space character
// when it appears in an XML attribute value?
static bool IsNormalizableWhitespace(char c) {
return c == 0x9 || c == 0xA || c == 0xD;
}
// May c appear in a well-formed XML document?
static bool IsValidXmlCharacter(char c) {
return IsNormalizableWhitespace(c) || c >= 0x20;
}
// Returns an XML-escaped copy of the input string str. If
// is_attribute is true, the text is meant to appear as an attribute
// value, and normalizable whitespace is preserved by replacing it
// with character references.
static String EscapeXml(const char* str, bool is_attribute);
// Returns the given string with all characters invalid in XML removed.
static string RemoveInvalidXmlCharacters(const string& str);
// Convenience wrapper around EscapeXml when str is an attribute value.
static String EscapeXmlAttribute(const char* str) {
return EscapeXml(str, true);
}
// Convenience wrapper around EscapeXml when str is not an attribute value.
static String EscapeXmlText(const char* str) { return EscapeXml(str, false); }
// Streams an XML CDATA section, escaping invalid CDATA sequences as needed.
static void OutputXmlCDataSection(::std::ostream* stream, const char* data);
// Streams an XML representation of a TestInfo object.
static void OutputXmlTestInfo(::std::ostream* stream,
const char* test_case_name,
const TestInfo& test_info);
// Prints an XML representation of a TestCase object
static void PrintXmlTestCase(FILE* out, const TestCase& test_case);
// Prints an XML summary of unit_test to output stream out.
static void PrintXmlUnitTest(FILE* out, const UnitTest& unit_test);
// Produces a string representing the test properties in a result as space
// delimited XML attributes based on the property key="value" pairs.
// When the String is not empty, it includes a space at the beginning,
// to delimit this attribute from prior attributes.
static String TestPropertiesAsXmlAttributes(const TestResult& result);
// The output file.
const String output_file_;
GTEST_DISALLOW_COPY_AND_ASSIGN_(XmlUnitTestResultPrinter);
};
// Creates a new XmlUnitTestResultPrinter.
XmlUnitTestResultPrinter::XmlUnitTestResultPrinter(const char* output_file)
: output_file_(output_file) {
if (output_file_.c_str() == NULL || output_file_.empty()) {
fprintf(stderr, "XML output file may not be null\n");
fflush(stderr);
exit(EXIT_FAILURE);
}
}
// Called after the unit test ends.
void XmlUnitTestResultPrinter::OnTestIterationEnd(const UnitTest& unit_test,
int /*iteration*/) {
FILE* xmlout = NULL;
FilePath output_file(output_file_);
FilePath output_dir(output_file.RemoveFileName());
if (output_dir.CreateDirectoriesRecursively()) {
xmlout = posix::FOpen(output_file_.c_str(), "w");
}
if (xmlout == NULL) {
// TODO(wan): report the reason of the failure.
//
// We don't do it for now as:
//
// 1. There is no urgent need for it.
// 2. It's a bit involved to make the errno variable thread-safe on
// all three operating systems (Linux, Windows, and Mac OS).
// 3. To interpret the meaning of errno in a thread-safe way,
// we need the strerror_r() function, which is not available on
// Windows.
fprintf(stderr,
"Unable to open file \"%s\"\n",
output_file_.c_str());
fflush(stderr);
exit(EXIT_FAILURE);
}
PrintXmlUnitTest(xmlout, unit_test);
fclose(xmlout);
}
// Returns an XML-escaped copy of the input string str. If is_attribute
// is true, the text is meant to appear as an attribute value, and
// normalizable whitespace is preserved by replacing it with character
// references.
//
// Invalid XML characters in str, if any, are stripped from the output.
// It is expected that most, if not all, of the text processed by this
// module will consist of ordinary English text.
// If this module is ever modified to produce version 1.1 XML output,
// most invalid characters can be retained using character references.
// TODO(wan): It might be nice to have a minimally invasive, human-readable
// escaping scheme for invalid characters, rather than dropping them.
String XmlUnitTestResultPrinter::EscapeXml(const char* str, bool is_attribute) {
Message m;
if (str != NULL) {
for (const char* src = str; *src; ++src) {
switch (*src) {
case '<':
m << "<";
break;
case '>':
m << ">";
break;
case '&':
m << "&";
break;
case '\'':
if (is_attribute)
m << "'";
else
m << '\'';
break;
case '"':
if (is_attribute)
m << """;
else
m << '"';
break;
default:
if (IsValidXmlCharacter(*src)) {
if (is_attribute && IsNormalizableWhitespace(*src))
m << String::Format("&#x%02X;", unsigned(*src));
else
m << *src;
}
break;
}
}
}
return m.GetString();
}
// Returns the given string with all characters invalid in XML removed.
// Currently invalid characters are dropped from the string. An
// alternative is to replace them with certain characters such as . or ?.
string XmlUnitTestResultPrinter::RemoveInvalidXmlCharacters(const string& str) {
string output;
output.reserve(str.size());
for (string::const_iterator it = str.begin(); it != str.end(); ++it)
if (IsValidXmlCharacter(*it))
output.push_back(*it);
return output;
}
// The following routines generate an XML representation of a UnitTest
// object.
//
// This is how Google Test concepts map to the DTD:
//
// <testsuites name="AllTests"> <-- corresponds to a UnitTest object
// <testsuite name="testcase-name"> <-- corresponds to a TestCase object
// <testcase name="test-name"> <-- corresponds to a TestInfo object
// <failure message="...">...</failure>
// <failure message="...">...</failure>
// <failure message="...">...</failure>
// <-- individual assertion failures
// </testcase>
// </testsuite>
// </testsuites>
// Formats the given time in milliseconds as seconds.
std::string FormatTimeInMillisAsSeconds(TimeInMillis ms) {
::std::stringstream ss;
ss << ms/1000.0;
return ss.str();
}
// Streams an XML CDATA section, escaping invalid CDATA sequences as needed.
void XmlUnitTestResultPrinter::OutputXmlCDataSection(::std::ostream* stream,
const char* data) {
const char* segment = data;
*stream << "<![CDATA[";
for (;;) {
const char* const next_segment = strstr(segment, "]]>");
if (next_segment != NULL) {
stream->write(
segment, static_cast<std::streamsize>(next_segment - segment));
*stream << "]]>]]><![CDATA[";
segment = next_segment + strlen("]]>");
} else {
*stream << segment;
break;
}
}
*stream << "]]>";
}
// Prints an XML representation of a TestInfo object.
// TODO(wan): There is also value in printing properties with the plain printer.
void XmlUnitTestResultPrinter::OutputXmlTestInfo(::std::ostream* stream,
const char* test_case_name,
const TestInfo& test_info) {
const TestResult& result = *test_info.result();
*stream << " <testcase name=\""
<< EscapeXmlAttribute(test_info.name()).c_str() << "\"";
if (test_info.value_param() != NULL) {
*stream << " value_param=\"" << EscapeXmlAttribute(test_info.value_param())
<< "\"";
}
if (test_info.type_param() != NULL) {
*stream << " type_param=\"" << EscapeXmlAttribute(test_info.type_param())
<< "\"";
}
*stream << " status=\""
<< (test_info.should_run() ? "run" : "notrun")
<< "\" time=\""
<< FormatTimeInMillisAsSeconds(result.elapsed_time())
<< "\" classname=\"" << EscapeXmlAttribute(test_case_name).c_str()
<< "\"" << TestPropertiesAsXmlAttributes(result).c_str();
int failures = 0;
for (int i = 0; i < result.total_part_count(); ++i) {
const TestPartResult& part = result.GetTestPartResult(i);
if (part.failed()) {
if (++failures == 1)
*stream << ">\n";
*stream << " <failure message=\""
<< EscapeXmlAttribute(part.summary()).c_str()
<< "\" type=\"\">";
const string location = internal::FormatCompilerIndependentFileLocation(
part.file_name(), part.line_number());
const string message = location + "\n" + part.message();
OutputXmlCDataSection(stream,
RemoveInvalidXmlCharacters(message).c_str());
*stream << "</failure>\n";
}
}
if (failures == 0)
*stream << " />\n";
else
*stream << " </testcase>\n";
}
// Prints an XML representation of a TestCase object
void XmlUnitTestResultPrinter::PrintXmlTestCase(FILE* out,
const TestCase& test_case) {
fprintf(out,
" <testsuite name=\"%s\" tests=\"%d\" failures=\"%d\" "
"disabled=\"%d\" ",
EscapeXmlAttribute(test_case.name()).c_str(),
test_case.total_test_count(),
test_case.failed_test_count(),
test_case.disabled_test_count());
fprintf(out,
"errors=\"0\" time=\"%s\">\n",
FormatTimeInMillisAsSeconds(test_case.elapsed_time()).c_str());
for (int i = 0; i < test_case.total_test_count(); ++i) {
::std::stringstream stream;
OutputXmlTestInfo(&stream, test_case.name(), *test_case.GetTestInfo(i));
fprintf(out, "%s", StringStreamToString(&stream).c_str());
}
fprintf(out, " </testsuite>\n");
}
// Prints an XML summary of unit_test to output stream out.
void XmlUnitTestResultPrinter::PrintXmlUnitTest(FILE* out,
const UnitTest& unit_test) {
fprintf(out, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
fprintf(out,
"<testsuites tests=\"%d\" failures=\"%d\" disabled=\"%d\" "
"errors=\"0\" time=\"%s\" ",
unit_test.total_test_count(),
unit_test.failed_test_count(),
unit_test.disabled_test_count(),
FormatTimeInMillisAsSeconds(unit_test.elapsed_time()).c_str());
if (GTEST_FLAG(shuffle)) {
fprintf(out, "random_seed=\"%d\" ", unit_test.random_seed());
}
fprintf(out, "name=\"AllTests\">\n");
for (int i = 0; i < unit_test.total_test_case_count(); ++i)
PrintXmlTestCase(out, *unit_test.GetTestCase(i));
fprintf(out, "</testsuites>\n");
}
// Produces a string representing the test properties in a result as space
// delimited XML attributes based on the property key="value" pairs.
String XmlUnitTestResultPrinter::TestPropertiesAsXmlAttributes(
const TestResult& result) {
Message attributes;
for (int i = 0; i < result.test_property_count(); ++i) {
const TestProperty& property = result.GetTestProperty(i);
attributes << " " << property.key() << "="
<< "\"" << EscapeXmlAttribute(property.value()) << "\"";
}
return attributes.GetString();
}
// End XmlUnitTestResultPrinter
#if GTEST_CAN_STREAM_RESULTS_
// Streams test results to the given port on the given host machine.
class StreamingListener : public EmptyTestEventListener {
public:
// Escapes '=', '&', '%', and '\n' characters in str as "%xx".
static string UrlEncode(const char* str);
StreamingListener(const string& host, const string& port)
: sockfd_(-1), host_name_(host), port_num_(port) {
MakeConnection();
Send("gtest_streaming_protocol_version=1.0\n");
}
virtual ~StreamingListener() {
if (sockfd_ != -1)
CloseConnection();
}
void OnTestProgramStart(const UnitTest& /* unit_test */) {
Send("event=TestProgramStart\n");
}
void OnTestProgramEnd(const UnitTest& unit_test) {
// Note that Google Test current only report elapsed time for each
// test iteration, not for the entire test program.
Send(String::Format("event=TestProgramEnd&passed=%d\n",
unit_test.Passed()));
// Notify the streaming server to stop.
CloseConnection();
}
void OnTestIterationStart(const UnitTest& /* unit_test */, int iteration) {
Send(String::Format("event=TestIterationStart&iteration=%d\n",
iteration));
}
void OnTestIterationEnd(const UnitTest& unit_test, int /* iteration */) {
Send(String::Format("event=TestIterationEnd&passed=%d&elapsed_time=%sms\n",
unit_test.Passed(),
StreamableToString(unit_test.elapsed_time()).c_str()));
}
void OnTestCaseStart(const TestCase& test_case) {
Send(String::Format("event=TestCaseStart&name=%s\n", test_case.name()));
}
void OnTestCaseEnd(const TestCase& test_case) {
Send(String::Format("event=TestCaseEnd&passed=%d&elapsed_time=%sms\n",
test_case.Passed(),
StreamableToString(test_case.elapsed_time()).c_str()));
}
void OnTestStart(const TestInfo& test_info) {
Send(String::Format("event=TestStart&name=%s\n", test_info.name()));
}
void OnTestEnd(const TestInfo& test_info) {
Send(String::Format(
"event=TestEnd&passed=%d&elapsed_time=%sms\n",
(test_info.result())->Passed(),
StreamableToString((test_info.result())->elapsed_time()).c_str()));
}
void OnTestPartResult(const TestPartResult& test_part_result) {
const char* file_name = test_part_result.file_name();
if (file_name == NULL)
file_name = "";
Send(String::Format("event=TestPartResult&file=%s&line=%d&message=",
UrlEncode(file_name).c_str(),
test_part_result.line_number()));
Send(UrlEncode(test_part_result.message()) + "\n");
}
private:
// Creates a client socket and connects to the server.
void MakeConnection();
// Closes the socket.
void CloseConnection() {
GTEST_CHECK_(sockfd_ != -1)
<< "CloseConnection() can be called only when there is a connection.";
close(sockfd_);
sockfd_ = -1;
}
// Sends a string to the socket.
void Send(const string& message) {
GTEST_CHECK_(sockfd_ != -1)
<< "Send() can be called only when there is a connection.";
const int len = static_cast<int>(message.length());
if (write(sockfd_, message.c_str(), len) != len) {
GTEST_LOG_(WARNING)
<< "stream_result_to: failed to stream to "
<< host_name_ << ":" << port_num_;
}
}
int sockfd_; // socket file descriptor
const string host_name_;
const string port_num_;
GTEST_DISALLOW_COPY_AND_ASSIGN_(StreamingListener);
}; // class StreamingListener
// Checks if str contains '=', '&', '%' or '\n' characters. If yes,
// replaces them by "%xx" where xx is their hexadecimal value. For
// example, replaces "=" with "%3D". This algorithm is O(strlen(str))
// in both time and space -- important as the input str may contain an
// arbitrarily long test failure message and stack trace.
string StreamingListener::UrlEncode(const char* str) {
string result;
result.reserve(strlen(str) + 1);
for (char ch = *str; ch != '\0'; ch = *++str) {
switch (ch) {
case '%':
case '=':
case '&':
case '\n':
result.append(String::Format("%%%02x", static_cast<unsigned char>(ch)));
break;
default:
result.push_back(ch);
break;
}
}
return result;
}
void StreamingListener::MakeConnection() {
GTEST_CHECK_(sockfd_ == -1)
<< "MakeConnection() can't be called when there is already a connection.";
addrinfo hints;
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_UNSPEC; // To allow both IPv4 and IPv6 addresses.
hints.ai_socktype = SOCK_STREAM;
addrinfo* servinfo = NULL;
// Use the getaddrinfo() to get a linked list of IP addresses for
// the given host name.
const int error_num = getaddrinfo(
host_name_.c_str(), port_num_.c_str(), &hints, &servinfo);
if (error_num != 0) {
GTEST_LOG_(WARNING) << "stream_result_to: getaddrinfo() failed: "
<< gai_strerror(error_num);
}
// Loop through all the results and connect to the first we can.
for (addrinfo* cur_addr = servinfo; sockfd_ == -1 && cur_addr != NULL;
cur_addr = cur_addr->ai_next) {
sockfd_ = socket(
cur_addr->ai_family, cur_addr->ai_socktype, cur_addr->ai_protocol);
if (sockfd_ != -1) {
// Connect the client socket to the server socket.
if (connect(sockfd_, cur_addr->ai_addr, cur_addr->ai_addrlen) == -1) {
close(sockfd_);
sockfd_ = -1;
}
}
}
freeaddrinfo(servinfo); // all done with this structure
if (sockfd_ == -1) {
GTEST_LOG_(WARNING) << "stream_result_to: failed to connect to "
<< host_name_ << ":" << port_num_;
}
}
// End of class Streaming Listener
#endif // GTEST_CAN_STREAM_RESULTS__
// Class ScopedTrace
// Pushes the given source file location and message onto a per-thread
// trace stack maintained by Google Test.
// L < UnitTest::mutex_
ScopedTrace::ScopedTrace(const char* file, int line, const Message& message) {
TraceInfo trace;
trace.file = file;
trace.line = line;
trace.message = message.GetString();
UnitTest::GetInstance()->PushGTestTrace(trace);
}
// Pops the info pushed by the c'tor.
// L < UnitTest::mutex_
ScopedTrace::~ScopedTrace() {
UnitTest::GetInstance()->PopGTestTrace();
}
// class OsStackTraceGetter
// Returns the current OS stack trace as a String. Parameters:
//
// max_depth - the maximum number of stack frames to be included
// in the trace.
// skip_count - the number of top frames to be skipped; doesn't count
// against max_depth.
//
// L < mutex_
// We use "L < mutex_" to denote that the function may acquire mutex_.
String OsStackTraceGetter::CurrentStackTrace(int, int) {
return String("");
}
// L < mutex_
void OsStackTraceGetter::UponLeavingGTest() {
}
const char* const
OsStackTraceGetter::kElidedFramesMarker =
"... " GTEST_NAME_ " internal frames ...";
} // namespace internal
// class TestEventListeners
TestEventListeners::TestEventListeners()
: repeater_(new internal::TestEventRepeater()),
default_result_printer_(NULL),
default_xml_generator_(NULL) {
}
TestEventListeners::~TestEventListeners() { delete repeater_; }
// Returns the standard listener responsible for the default console
// output. Can be removed from the listeners list to shut down default
// console output. Note that removing this object from the listener list
// with Release transfers its ownership to the user.
void TestEventListeners::Append(TestEventListener* listener) {
repeater_->Append(listener);
}
// Removes the given event listener from the list and returns it. It then
// becomes the caller's responsibility to delete the listener. Returns
// NULL if the listener is not found in the list.
TestEventListener* TestEventListeners::Release(TestEventListener* listener) {
if (listener == default_result_printer_)
default_result_printer_ = NULL;
else if (listener == default_xml_generator_)
default_xml_generator_ = NULL;
return repeater_->Release(listener);
}
// Returns repeater that broadcasts the TestEventListener events to all
// subscribers.
TestEventListener* TestEventListeners::repeater() { return repeater_; }
// Sets the default_result_printer attribute to the provided listener.
// The listener is also added to the listener list and previous
// default_result_printer is removed from it and deleted. The listener can
// also be NULL in which case it will not be added to the list. Does
// nothing if the previous and the current listener objects are the same.
void TestEventListeners::SetDefaultResultPrinter(TestEventListener* listener) {
if (default_result_printer_ != listener) {
// It is an error to pass this method a listener that is already in the
// list.
delete Release(default_result_printer_);
default_result_printer_ = listener;
if (listener != NULL)
Append(listener);
}
}
// Sets the default_xml_generator attribute to the provided listener. The
// listener is also added to the listener list and previous
// default_xml_generator is removed from it and deleted. The listener can
// also be NULL in which case it will not be added to the list. Does
// nothing if the previous and the current listener objects are the same.
void TestEventListeners::SetDefaultXmlGenerator(TestEventListener* listener) {
if (default_xml_generator_ != listener) {
// It is an error to pass this method a listener that is already in the
// list.
delete Release(default_xml_generator_);
default_xml_generator_ = listener;
if (listener != NULL)
Append(listener);
}
}
// Controls whether events will be forwarded by the repeater to the
// listeners in the list.
bool TestEventListeners::EventForwardingEnabled() const {
return repeater_->forwarding_enabled();
}
void TestEventListeners::SuppressEventForwarding() {
repeater_->set_forwarding_enabled(false);
}
// class UnitTest
// Gets the singleton UnitTest object. The first time this method is
// called, a UnitTest object is constructed and returned. Consecutive
// calls will return the same object.
//
// We don't protect this under mutex_ as a user is not supposed to
// call this before main() starts, from which point on the return
// value will never change.
UnitTest * UnitTest::GetInstance() {
// When compiled with MSVC 7.1 in optimized mode, destroying the
// UnitTest object upon exiting the program messes up the exit code,
// causing successful tests to appear failed. We have to use a
// different implementation in this case to bypass the compiler bug.
// This implementation makes the compiler happy, at the cost of
// leaking the UnitTest object.
// CodeGear C++Builder insists on a public destructor for the
// default implementation. Use this implementation to keep good OO
// design with private destructor.
#if (_MSC_VER == 1310 && !defined(_DEBUG)) || defined(__BORLANDC__)
static UnitTest* const instance = new UnitTest;
return instance;
#else
static UnitTest instance;
return &instance;
#endif // (_MSC_VER == 1310 && !defined(_DEBUG)) || defined(__BORLANDC__)
}
// Gets the number of successful test cases.
int UnitTest::successful_test_case_count() const {
return impl()->successful_test_case_count();
}
// Gets the number of failed test cases.
int UnitTest::failed_test_case_count() const {
return impl()->failed_test_case_count();
}
// Gets the number of all test cases.
int UnitTest::total_test_case_count() const {
return impl()->total_test_case_count();
}
// Gets the number of all test cases that contain at least one test
// that should run.
int UnitTest::test_case_to_run_count() const {
return impl()->test_case_to_run_count();
}
// Gets the number of successful tests.
int UnitTest::successful_test_count() const {
return impl()->successful_test_count();
}
// Gets the number of failed tests.
int UnitTest::failed_test_count() const { return impl()->failed_test_count(); }
// Gets the number of disabled tests.
int UnitTest::disabled_test_count() const {
return impl()->disabled_test_count();
}
// Gets the number of all tests.
int UnitTest::total_test_count() const { return impl()->total_test_count(); }
// Gets the number of tests that should run.
int UnitTest::test_to_run_count() const { return impl()->test_to_run_count(); }
// Gets the elapsed time, in milliseconds.
internal::TimeInMillis UnitTest::elapsed_time() const {
return impl()->elapsed_time();
}
// Returns true iff the unit test passed (i.e. all test cases passed).
bool UnitTest::Passed() const { return impl()->Passed(); }
// Returns true iff the unit test failed (i.e. some test case failed
// or something outside of all tests failed).
bool UnitTest::Failed() const { return impl()->Failed(); }
// Gets the i-th test case among all the test cases. i can range from 0 to
// total_test_case_count() - 1. If i is not in that range, returns NULL.
const TestCase* UnitTest::GetTestCase(int i) const {
return impl()->GetTestCase(i);
}
// Gets the i-th test case among all the test cases. i can range from 0 to
// total_test_case_count() - 1. If i is not in that range, returns NULL.
TestCase* UnitTest::GetMutableTestCase(int i) {
return impl()->GetMutableTestCase(i);
}
// Returns the list of event listeners that can be used to track events
// inside Google Test.
TestEventListeners& UnitTest::listeners() {
return *impl()->listeners();
}
// Registers and returns a global test environment. When a test
// program is run, all global test environments will be set-up in the
// order they were registered. After all tests in the program have
// finished, all global test environments will be torn-down in the
// *reverse* order they were registered.
//
// The UnitTest object takes ownership of the given environment.
//
// We don't protect this under mutex_, as we only support calling it
// from the main thread.
Environment* UnitTest::AddEnvironment(Environment* env) {
if (env == NULL) {
return NULL;
}
impl_->environments().push_back(env);
return env;
}
// Adds a TestPartResult to the current TestResult object. All Google Test
// assertion macros (e.g. ASSERT_TRUE, EXPECT_EQ, etc) eventually call
// this to report their results. The user code should use the
// assertion macros instead of calling this directly.
// L < mutex_
void UnitTest::AddTestPartResult(TestPartResult::Type result_type,
const char* file_name,
int line_number,
const internal::String& message,
const internal::String& os_stack_trace) {
Message msg;
msg << message;
internal::MutexLock lock(&mutex_);
if (impl_->gtest_trace_stack().size() > 0) {
msg << "\n" << GTEST_NAME_ << " trace:";
for (int i = static_cast<int>(impl_->gtest_trace_stack().size());
i > 0; --i) {
const internal::TraceInfo& trace = impl_->gtest_trace_stack()[i - 1];
msg << "\n" << internal::FormatFileLocation(trace.file, trace.line)
<< " " << trace.message;
}
}
if (os_stack_trace.c_str() != NULL && !os_stack_trace.empty()) {
msg << internal::kStackTraceMarker << os_stack_trace;
}
const TestPartResult result =
TestPartResult(result_type, file_name, line_number,
msg.GetString().c_str());
impl_->GetTestPartResultReporterForCurrentThread()->
ReportTestPartResult(result);
if (result_type != TestPartResult::kSuccess) {
// gtest_break_on_failure takes precedence over
// gtest_throw_on_failure. This allows a user to set the latter
// in the code (perhaps in order to use Google Test assertions
// with another testing framework) and specify the former on the
// command line for debugging.
if (GTEST_FLAG(break_on_failure)) {
#if GTEST_OS_WINDOWS
// Using DebugBreak on Windows allows gtest to still break into a debugger
// when a failure happens and both the --gtest_break_on_failure and
// the --gtest_catch_exceptions flags are specified.
DebugBreak();
#else
// Dereference NULL through a volatile pointer to prevent the compiler
// from removing. We use this rather than abort() or __builtin_trap() for
// portability: Symbian doesn't implement abort() well, and some debuggers
// don't correctly trap abort().
*static_cast<volatile int*>(NULL) = 1;
#endif // GTEST_OS_WINDOWS
} else if (GTEST_FLAG(throw_on_failure)) {
#if GTEST_HAS_EXCEPTIONS
throw GoogleTestFailureException(result);
#else
// We cannot call abort() as it generates a pop-up in debug mode
// that cannot be suppressed in VC 7.1 or below.
exit(1);
#endif
}
}
}
// Creates and adds a property to the current TestResult. If a property matching
// the supplied value already exists, updates its value instead.
void UnitTest::RecordPropertyForCurrentTest(const char* key,
const char* value) {
const TestProperty test_property(key, value);
impl_->current_test_result()->RecordProperty(test_property);
}
// Runs all tests in this UnitTest object and prints the result.
// Returns 0 if successful, or 1 otherwise.
//
// We don't protect this under mutex_, as we only support calling it
// from the main thread.
int UnitTest::Run() {
// Captures the value of GTEST_FLAG(catch_exceptions). This value will be
// used for the duration of the program.
impl()->set_catch_exceptions(GTEST_FLAG(catch_exceptions));
#if GTEST_HAS_SEH
const bool in_death_test_child_process =
internal::GTEST_FLAG(internal_run_death_test).length() > 0;
// Either the user wants Google Test to catch exceptions thrown by the
// tests or this is executing in the context of death test child
// process. In either case the user does not want to see pop-up dialogs
// about crashes - they are expected.
if (impl()->catch_exceptions() || in_death_test_child_process) {
# if !GTEST_OS_WINDOWS_MOBILE
// SetErrorMode doesn't exist on CE.
SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOALIGNMENTFAULTEXCEPT |
SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX);
# endif // !GTEST_OS_WINDOWS_MOBILE
# if (defined(_MSC_VER) || GTEST_OS_WINDOWS_MINGW) && !GTEST_OS_WINDOWS_MOBILE
// Death test children can be terminated with _abort(). On Windows,
// _abort() can show a dialog with a warning message. This forces the
// abort message to go to stderr instead.
_set_error_mode(_OUT_TO_STDERR);
# endif
# if _MSC_VER >= 1400 && !GTEST_OS_WINDOWS_MOBILE
// In the debug version, Visual Studio pops up a separate dialog
// offering a choice to debug the aborted program. We need to suppress
// this dialog or it will pop up for every EXPECT/ASSERT_DEATH statement
// executed. Google Test will notify the user of any unexpected
// failure via stderr.
//
// VC++ doesn't define _set_abort_behavior() prior to the version 8.0.
// Users of prior VC versions shall suffer the agony and pain of
// clicking through the countless debug dialogs.
// TODO(vladl@google.com): find a way to suppress the abort dialog() in the
// debug mode when compiled with VC 7.1 or lower.
if (!GTEST_FLAG(break_on_failure))
_set_abort_behavior(
0x0, // Clear the following flags:
_WRITE_ABORT_MSG | _CALL_REPORTFAULT); // pop-up window, core dump.
# endif
}
#endif // GTEST_HAS_SEH
return internal::HandleExceptionsInMethodIfSupported(
impl(),
&internal::UnitTestImpl::RunAllTests,
"auxiliary test code (environments or event listeners)") ? 0 : 1;
}
// Returns the working directory when the first TEST() or TEST_F() was
// executed.
const char* UnitTest::original_working_dir() const {
return impl_->original_working_dir_.c_str();
}
// Returns the TestCase object for the test that's currently running,
// or NULL if no test is running.
// L < mutex_
const TestCase* UnitTest::current_test_case() const {
internal::MutexLock lock(&mutex_);
return impl_->current_test_case();
}
// Returns the TestInfo object for the test that's currently running,
// or NULL if no test is running.
// L < mutex_
const TestInfo* UnitTest::current_test_info() const {
internal::MutexLock lock(&mutex_);
return impl_->current_test_info();
}
// Returns the random seed used at the start of the current test run.
int UnitTest::random_seed() const { return impl_->random_seed(); }
#if GTEST_HAS_PARAM_TEST
// Returns ParameterizedTestCaseRegistry object used to keep track of
// value-parameterized tests and instantiate and register them.
// L < mutex_
internal::ParameterizedTestCaseRegistry&
UnitTest::parameterized_test_registry() {
return impl_->parameterized_test_registry();
}
#endif // GTEST_HAS_PARAM_TEST
// Creates an empty UnitTest.
UnitTest::UnitTest() {
impl_ = new internal::UnitTestImpl(this);
}
// Destructor of UnitTest.
UnitTest::~UnitTest() {
delete impl_;
}
// Pushes a trace defined by SCOPED_TRACE() on to the per-thread
// Google Test trace stack.
// L < mutex_
void UnitTest::PushGTestTrace(const internal::TraceInfo& trace) {
internal::MutexLock lock(&mutex_);
impl_->gtest_trace_stack().push_back(trace);
}
// Pops a trace from the per-thread Google Test trace stack.
// L < mutex_
void UnitTest::PopGTestTrace() {
internal::MutexLock lock(&mutex_);
impl_->gtest_trace_stack().pop_back();
}
namespace internal {
UnitTestImpl::UnitTestImpl(UnitTest* parent)
: parent_(parent),
#ifdef _MSC_VER
# pragma warning(push) // Saves the current warning state.
# pragma warning(disable:4355) // Temporarily disables warning 4355
// (using this in initializer).
default_global_test_part_result_reporter_(this),
default_per_thread_test_part_result_reporter_(this),
# pragma warning(pop) // Restores the warning state again.
#else
default_global_test_part_result_reporter_(this),
default_per_thread_test_part_result_reporter_(this),
#endif // _MSC_VER
global_test_part_result_repoter_(
&default_global_test_part_result_reporter_),
per_thread_test_part_result_reporter_(
&default_per_thread_test_part_result_reporter_),
#if GTEST_HAS_PARAM_TEST
parameterized_test_registry_(),
parameterized_tests_registered_(false),
#endif // GTEST_HAS_PARAM_TEST
last_death_test_case_(-1),
current_test_case_(NULL),
current_test_info_(NULL),
ad_hoc_test_result_(),
os_stack_trace_getter_(NULL),
post_flag_parse_init_performed_(false),
random_seed_(0), // Will be overridden by the flag before first use.
random_(0), // Will be reseeded before first use.
elapsed_time_(0),
#if GTEST_HAS_DEATH_TEST
internal_run_death_test_flag_(NULL),
death_test_factory_(new DefaultDeathTestFactory),
#endif
// Will be overridden by the flag before first use.
catch_exceptions_(false) {
listeners()->SetDefaultResultPrinter(new PrettyUnitTestResultPrinter);
}
UnitTestImpl::~UnitTestImpl() {
// Deletes every TestCase.
ForEach(test_cases_, internal::Delete<TestCase>);
// Deletes every Environment.
ForEach(environments_, internal::Delete<Environment>);
delete os_stack_trace_getter_;
}
#if GTEST_HAS_DEATH_TEST
// Disables event forwarding if the control is currently in a death test
// subprocess. Must not be called before InitGoogleTest.
void UnitTestImpl::SuppressTestEventsIfInSubprocess() {
if (internal_run_death_test_flag_.get() != NULL)
listeners()->SuppressEventForwarding();
}
#endif // GTEST_HAS_DEATH_TEST
// Initializes event listeners performing XML output as specified by
// UnitTestOptions. Must not be called before InitGoogleTest.
void UnitTestImpl::ConfigureXmlOutput() {
const String& output_format = UnitTestOptions::GetOutputFormat();
if (output_format == "xml") {
listeners()->SetDefaultXmlGenerator(new XmlUnitTestResultPrinter(
UnitTestOptions::GetAbsolutePathToOutputFile().c_str()));
} else if (output_format != "") {
printf("WARNING: unrecognized output format \"%s\" ignored.\n",
output_format.c_str());
fflush(stdout);
}
}
#if GTEST_CAN_STREAM_RESULTS_
// Initializes event listeners for streaming test results in String form.
// Must not be called before InitGoogleTest.
void UnitTestImpl::ConfigureStreamingOutput() {
const string& target = GTEST_FLAG(stream_result_to);
if (!target.empty()) {
const size_t pos = target.find(':');
if (pos != string::npos) {
listeners()->Append(new StreamingListener(target.substr(0, pos),
target.substr(pos+1)));
} else {
printf("WARNING: unrecognized streaming target \"%s\" ignored.\n",
target.c_str());
fflush(stdout);
}
}
}
#endif // GTEST_CAN_STREAM_RESULTS_
// Performs initialization dependent upon flag values obtained in
// ParseGoogleTestFlagsOnly. Is called from InitGoogleTest after the call to
// ParseGoogleTestFlagsOnly. In case a user neglects to call InitGoogleTest
// this function is also called from RunAllTests. Since this function can be
// called more than once, it has to be idempotent.
void UnitTestImpl::PostFlagParsingInit() {
// Ensures that this function does not execute more than once.
if (!post_flag_parse_init_performed_) {
post_flag_parse_init_performed_ = true;
#if GTEST_HAS_DEATH_TEST
InitDeathTestSubprocessControlInfo();
SuppressTestEventsIfInSubprocess();
#endif // GTEST_HAS_DEATH_TEST
// Registers parameterized tests. This makes parameterized tests
// available to the UnitTest reflection API without running
// RUN_ALL_TESTS.
RegisterParameterizedTests();
// Configures listeners for XML output. This makes it possible for users
// to shut down the default XML output before invoking RUN_ALL_TESTS.
ConfigureXmlOutput();
#if GTEST_CAN_STREAM_RESULTS_
// Configures listeners for streaming test results to the specified server.
ConfigureStreamingOutput();
#endif // GTEST_CAN_STREAM_RESULTS_
}
}
// A predicate that checks the name of a TestCase against a known
// value.
//
// This is used for implementation of the UnitTest class only. We put
// it in the anonymous namespace to prevent polluting the outer
// namespace.
//
// TestCaseNameIs is copyable.
class TestCaseNameIs {
public:
// Constructor.
explicit TestCaseNameIs(const String& name)
: name_(name) {}
// Returns true iff the name of test_case matches name_.
bool operator()(const TestCase* test_case) const {
return test_case != NULL && strcmp(test_case->name(), name_.c_str()) == 0;
}
private:
String name_;
};
// Finds and returns a TestCase with the given name. If one doesn't
// exist, creates one and returns it. It's the CALLER'S
// RESPONSIBILITY to ensure that this function is only called WHEN THE
// TESTS ARE NOT SHUFFLED.
//
// Arguments:
//
// test_case_name: name of the test case
// type_param: the name of the test case's type parameter, or NULL if
// this is not a typed or a type-parameterized test case.
// set_up_tc: pointer to the function that sets up the test case
// tear_down_tc: pointer to the function that tears down the test case
TestCase* UnitTestImpl::GetTestCase(const char* test_case_name,
const char* type_param,
Test::SetUpTestCaseFunc set_up_tc,
Test::TearDownTestCaseFunc tear_down_tc) {
// Can we find a TestCase with the given name?
const std::vector<TestCase*>::const_iterator test_case =
std::find_if(test_cases_.begin(), test_cases_.end(),
TestCaseNameIs(test_case_name));
if (test_case != test_cases_.end())
return *test_case;
// No. Let's create one.
TestCase* const new_test_case =
new TestCase(test_case_name, type_param, set_up_tc, tear_down_tc);
// Is this a death test case?
if (internal::UnitTestOptions::MatchesFilter(String(test_case_name),
kDeathTestCaseFilter)) {
// Yes. Inserts the test case after the last death test case
// defined so far. This only works when the test cases haven't
// been shuffled. Otherwise we may end up running a death test
// after a non-death test.
++last_death_test_case_;
test_cases_.insert(test_cases_.begin() + last_death_test_case_,
new_test_case);
} else {
// No. Appends to the end of the list.
test_cases_.push_back(new_test_case);
}
test_case_indices_.push_back(static_cast<int>(test_case_indices_.size()));
return new_test_case;
}
// Helpers for setting up / tearing down the given environment. They
// are for use in the ForEach() function.
static void SetUpEnvironment(Environment* env) { env->SetUp(); }
static void TearDownEnvironment(Environment* env) { env->TearDown(); }
// Runs all tests in this UnitTest object, prints the result, and
// returns true if all tests are successful. If any exception is
// thrown during a test, the test is considered to be failed, but the
// rest of the tests will still be run.
//
// When parameterized tests are enabled, it expands and registers
// parameterized tests first in RegisterParameterizedTests().
// All other functions called from RunAllTests() may safely assume that
// parameterized tests are ready to be counted and run.
bool UnitTestImpl::RunAllTests() {
// Makes sure InitGoogleTest() was called.
if (!GTestIsInitialized()) {
printf("%s",
"\nThis test program did NOT call ::testing::InitGoogleTest "
"before calling RUN_ALL_TESTS(). Please fix it.\n");
return false;
}
// Do not run any test if the --help flag was specified.
if (g_help_flag)
return true;
// Repeats the call to the post-flag parsing initialization in case the
// user didn't call InitGoogleTest.
PostFlagParsingInit();
// Even if sharding is not on, test runners may want to use the
// GTEST_SHARD_STATUS_FILE to query whether the test supports the sharding
// protocol.
internal::WriteToShardStatusFileIfNeeded();
// True iff we are in a subprocess for running a thread-safe-style
// death test.
bool in_subprocess_for_death_test = false;
#if GTEST_HAS_DEATH_TEST
in_subprocess_for_death_test = (internal_run_death_test_flag_.get() != NULL);
#endif // GTEST_HAS_DEATH_TEST
const bool should_shard = ShouldShard(kTestTotalShards, kTestShardIndex,
in_subprocess_for_death_test);
// Compares the full test names with the filter to decide which
// tests to run.
const bool has_tests_to_run = FilterTests(should_shard
? HONOR_SHARDING_PROTOCOL
: IGNORE_SHARDING_PROTOCOL) > 0;
// Lists the tests and exits if the --gtest_list_tests flag was specified.
if (GTEST_FLAG(list_tests)) {
// This must be called *after* FilterTests() has been called.
ListTestsMatchingFilter();
return true;
}
random_seed_ = GTEST_FLAG(shuffle) ?
GetRandomSeedFromFlag(GTEST_FLAG(random_seed)) : 0;
// True iff at least one test has failed.
bool failed = false;
TestEventListener* repeater = listeners()->repeater();
repeater->OnTestProgramStart(*parent_);
// How many times to repeat the tests? We don't want to repeat them
// when we are inside the subprocess of a death test.
const int repeat = in_subprocess_for_death_test ? 1 : GTEST_FLAG(repeat);
// Repeats forever if the repeat count is negative.
const bool forever = repeat < 0;
for (int i = 0; forever || i != repeat; i++) {
// We want to preserve failures generated by ad-hoc test
// assertions executed before RUN_ALL_TESTS().
ClearNonAdHocTestResult();
const TimeInMillis start = GetTimeInMillis();
// Shuffles test cases and tests if requested.
if (has_tests_to_run && GTEST_FLAG(shuffle)) {
random()->Reseed(random_seed_);
// This should be done before calling OnTestIterationStart(),
// such that a test event listener can see the actual test order
// in the event.
ShuffleTests();
}
// Tells the unit test event listeners that the tests are about to start.
repeater->OnTestIterationStart(*parent_, i);
// Runs each test case if there is at least one test to run.
if (has_tests_to_run) {
// Sets up all environments beforehand.
repeater->OnEnvironmentsSetUpStart(*parent_);
ForEach(environments_, SetUpEnvironment);
repeater->OnEnvironmentsSetUpEnd(*parent_);
// Runs the tests only if there was no fatal failure during global
// set-up.
if (!Test::HasFatalFailure()) {
for (int test_index = 0; test_index < total_test_case_count();
test_index++) {
GetMutableTestCase(test_index)->Run();
}
}
// Tears down all environments in reverse order afterwards.
repeater->OnEnvironmentsTearDownStart(*parent_);
std::for_each(environments_.rbegin(), environments_.rend(),
TearDownEnvironment);
repeater->OnEnvironmentsTearDownEnd(*parent_);
}
elapsed_time_ = GetTimeInMillis() - start;
// Tells the unit test event listener that the tests have just finished.
repeater->OnTestIterationEnd(*parent_, i);
// Gets the result and clears it.
if (!Passed()) {
failed = true;
}
// Restores the original test order after the iteration. This
// allows the user to quickly repro a failure that happens in the
// N-th iteration without repeating the first (N - 1) iterations.
// This is not enclosed in "if (GTEST_FLAG(shuffle)) { ... }", in
// case the user somehow changes the value of the flag somewhere
// (it's always safe to unshuffle the tests).
UnshuffleTests();
if (GTEST_FLAG(shuffle)) {
// Picks a new random seed for each iteration.
random_seed_ = GetNextRandomSeed(random_seed_);
}
}
repeater->OnTestProgramEnd(*parent_);
return !failed;
}
// Reads the GTEST_SHARD_STATUS_FILE environment variable, and creates the file
// if the variable is present. If a file already exists at this location, this
// function will write over it. If the variable is present, but the file cannot
// be created, prints an error and exits.
void WriteToShardStatusFileIfNeeded() {
const char* const test_shard_file = posix::GetEnv(kTestShardStatusFile);
if (test_shard_file != NULL) {
FILE* const file = posix::FOpen(test_shard_file, "w");
if (file == NULL) {
ColoredPrintf(COLOR_RED,
"Could not write to the test shard status file \"%s\" "
"specified by the %s environment variable.\n",
test_shard_file, kTestShardStatusFile);
fflush(stdout);
exit(EXIT_FAILURE);
}
fclose(file);
}
}
// Checks whether sharding is enabled by examining the relevant
// environment variable values. If the variables are present,
// but inconsistent (i.e., shard_index >= total_shards), prints
// an error and exits. If in_subprocess_for_death_test, sharding is
// disabled because it must only be applied to the original test
// process. Otherwise, we could filter out death tests we intended to execute.
bool ShouldShard(const char* total_shards_env,
const char* shard_index_env,
bool in_subprocess_for_death_test) {
if (in_subprocess_for_death_test) {
return false;
}
const Int32 total_shards = Int32FromEnvOrDie(total_shards_env, -1);
const Int32 shard_index = Int32FromEnvOrDie(shard_index_env, -1);
if (total_shards == -1 && shard_index == -1) {
return false;
} else if (total_shards == -1 && shard_index != -1) {
const Message msg = Message()
<< "Invalid environment variables: you have "
<< kTestShardIndex << " = " << shard_index
<< ", but have left " << kTestTotalShards << " unset.\n";
ColoredPrintf(COLOR_RED, msg.GetString().c_str());
fflush(stdout);
exit(EXIT_FAILURE);
} else if (total_shards != -1 && shard_index == -1) {
const Message msg = Message()
<< "Invalid environment variables: you have "
<< kTestTotalShards << " = " << total_shards
<< ", but have left " << kTestShardIndex << " unset.\n";
ColoredPrintf(COLOR_RED, msg.GetString().c_str());
fflush(stdout);
exit(EXIT_FAILURE);
} else if (shard_index < 0 || shard_index >= total_shards) {
const Message msg = Message()
<< "Invalid environment variables: we require 0 <= "
<< kTestShardIndex << " < " << kTestTotalShards
<< ", but you have " << kTestShardIndex << "=" << shard_index
<< ", " << kTestTotalShards << "=" << total_shards << ".\n";
ColoredPrintf(COLOR_RED, msg.GetString().c_str());
fflush(stdout);
exit(EXIT_FAILURE);
}
return total_shards > 1;
}
// Parses the environment variable var as an Int32. If it is unset,
// returns default_val. If it is not an Int32, prints an error
// and aborts.
Int32 Int32FromEnvOrDie(const char* var, Int32 default_val) {
const char* str_val = posix::GetEnv(var);
if (str_val == NULL) {
return default_val;
}
Int32 result;
if (!ParseInt32(Message() << "The value of environment variable " << var,
str_val, &result)) {
exit(EXIT_FAILURE);
}
return result;
}
// Given the total number of shards, the shard index, and the test id,
// returns true iff the test should be run on this shard. The test id is
// some arbitrary but unique non-negative integer assigned to each test
// method. Assumes that 0 <= shard_index < total_shards.
bool ShouldRunTestOnShard(int total_shards, int shard_index, int test_id) {
return (test_id % total_shards) == shard_index;
}
// Compares the name of each test with the user-specified filter to
// decide whether the test should be run, then records the result in
// each TestCase and TestInfo object.
// If shard_tests == true, further filters tests based on sharding
// variables in the environment - see
// http://code.google.com/p/googletest/wiki/GoogleTestAdvancedGuide.
// Returns the number of tests that should run.
int UnitTestImpl::FilterTests(ReactionToSharding shard_tests) {
const Int32 total_shards = shard_tests == HONOR_SHARDING_PROTOCOL ?
Int32FromEnvOrDie(kTestTotalShards, -1) : -1;
const Int32 shard_index = shard_tests == HONOR_SHARDING_PROTOCOL ?
Int32FromEnvOrDie(kTestShardIndex, -1) : -1;
// num_runnable_tests are the number of tests that will
// run across all shards (i.e., match filter and are not disabled).
// num_selected_tests are the number of tests to be run on
// this shard.
int num_runnable_tests = 0;
int num_selected_tests = 0;
for (size_t i = 0; i < test_cases_.size(); i++) {
TestCase* const test_case = test_cases_[i];
const String &test_case_name = test_case->name();
test_case->set_should_run(false);
for (size_t j = 0; j < test_case->test_info_list().size(); j++) {
TestInfo* const test_info = test_case->test_info_list()[j];
const String test_name(test_info->name());
// A test is disabled if test case name or test name matches
// kDisableTestFilter.
const bool is_disabled =
internal::UnitTestOptions::MatchesFilter(test_case_name,
kDisableTestFilter) ||
internal::UnitTestOptions::MatchesFilter(test_name,
kDisableTestFilter);
test_info->is_disabled_ = is_disabled;
const bool matches_filter =
internal::UnitTestOptions::FilterMatchesTest(test_case_name,
test_name);
test_info->matches_filter_ = matches_filter;
const bool is_runnable =
(GTEST_FLAG(also_run_disabled_tests) || !is_disabled) &&
matches_filter;
const bool is_selected = is_runnable &&
(shard_tests == IGNORE_SHARDING_PROTOCOL ||
ShouldRunTestOnShard(total_shards, shard_index,
num_runnable_tests));
num_runnable_tests += is_runnable;
num_selected_tests += is_selected;
test_info->should_run_ = is_selected;
test_case->set_should_run(test_case->should_run() || is_selected);
}
}
return num_selected_tests;
}
// Prints the names of the tests matching the user-specified filter flag.
void UnitTestImpl::ListTestsMatchingFilter() {
for (size_t i = 0; i < test_cases_.size(); i++) {
const TestCase* const test_case = test_cases_[i];
bool printed_test_case_name = false;
for (size_t j = 0; j < test_case->test_info_list().size(); j++) {
const TestInfo* const test_info =
test_case->test_info_list()[j];
if (test_info->matches_filter_) {
if (!printed_test_case_name) {
printed_test_case_name = true;
printf("%s.\n", test_case->name());
}
printf(" %s\n", test_info->name());
}
}
}
fflush(stdout);
}
// Sets the OS stack trace getter.
//
// Does nothing if the input and the current OS stack trace getter are
// the same; otherwise, deletes the old getter and makes the input the
// current getter.
void UnitTestImpl::set_os_stack_trace_getter(
OsStackTraceGetterInterface* getter) {
if (os_stack_trace_getter_ != getter) {
delete os_stack_trace_getter_;
os_stack_trace_getter_ = getter;
}
}
// Returns the current OS stack trace getter if it is not NULL;
// otherwise, creates an OsStackTraceGetter, makes it the current
// getter, and returns it.
OsStackTraceGetterInterface* UnitTestImpl::os_stack_trace_getter() {
if (os_stack_trace_getter_ == NULL) {
os_stack_trace_getter_ = new OsStackTraceGetter;
}
return os_stack_trace_getter_;
}
// Returns the TestResult for the test that's currently running, or
// the TestResult for the ad hoc test if no test is running.
TestResult* UnitTestImpl::current_test_result() {
return current_test_info_ ?
&(current_test_info_->result_) : &ad_hoc_test_result_;
}
// Shuffles all test cases, and the tests within each test case,
// making sure that death tests are still run first.
void UnitTestImpl::ShuffleTests() {
// Shuffles the death test cases.
ShuffleRange(random(), 0, last_death_test_case_ + 1, &test_case_indices_);
// Shuffles the non-death test cases.
ShuffleRange(random(), last_death_test_case_ + 1,
static_cast<int>(test_cases_.size()), &test_case_indices_);
// Shuffles the tests inside each test case.
for (size_t i = 0; i < test_cases_.size(); i++) {
test_cases_[i]->ShuffleTests(random());
}
}
// Restores the test cases and tests to their order before the first shuffle.
void UnitTestImpl::UnshuffleTests() {
for (size_t i = 0; i < test_cases_.size(); i++) {
// Unshuffles the tests in each test case.
test_cases_[i]->UnshuffleTests();
// Resets the index of each test case.
test_case_indices_[i] = static_cast<int>(i);
}
}
// Returns the current OS stack trace as a String.
//
// The maximum number of stack frames to be included is specified by
// the gtest_stack_trace_depth flag. The skip_count parameter
// specifies the number of top frames to be skipped, which doesn't
// count against the number of frames to be included.
//
// For example, if Foo() calls Bar(), which in turn calls
// GetCurrentOsStackTraceExceptTop(..., 1), Foo() will be included in
// the trace but Bar() and GetCurrentOsStackTraceExceptTop() won't.
String GetCurrentOsStackTraceExceptTop(UnitTest* /*unit_test*/,
int skip_count) {
// We pass skip_count + 1 to skip this wrapper function in addition
// to what the user really wants to skip.
return GetUnitTestImpl()->CurrentOsStackTraceExceptTop(skip_count + 1);
}
// Used by the GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_ macro to
// suppress unreachable code warnings.
namespace {
class ClassUniqueToAlwaysTrue {};
}
bool IsTrue(bool condition) { return condition; }
bool AlwaysTrue() {
#if GTEST_HAS_EXCEPTIONS
// This condition is always false so AlwaysTrue() never actually throws,
// but it makes the compiler think that it may throw.
if (IsTrue(false))
throw ClassUniqueToAlwaysTrue();
#endif // GTEST_HAS_EXCEPTIONS
return true;
}
// If *pstr starts with the given prefix, modifies *pstr to be right
// past the prefix and returns true; otherwise leaves *pstr unchanged
// and returns false. None of pstr, *pstr, and prefix can be NULL.
bool SkipPrefix(const char* prefix, const char** pstr) {
const size_t prefix_len = strlen(prefix);
if (strncmp(*pstr, prefix, prefix_len) == 0) {
*pstr += prefix_len;
return true;
}
return false;
}
// Parses a string as a command line flag. The string should have
// the format "--flag=value". When def_optional is true, the "=value"
// part can be omitted.
//
// Returns the value of the flag, or NULL if the parsing failed.
const char* ParseFlagValue(const char* str,
const char* flag,
bool def_optional) {
// str and flag must not be NULL.
if (str == NULL || flag == NULL) return NULL;
// The flag must start with "--" followed by GTEST_FLAG_PREFIX_.
const String flag_str = String::Format("--%s%s", GTEST_FLAG_PREFIX_, flag);
const size_t flag_len = flag_str.length();
if (strncmp(str, flag_str.c_str(), flag_len) != 0) return NULL;
// Skips the flag name.
const char* flag_end = str + flag_len;
// When def_optional is true, it's OK to not have a "=value" part.
if (def_optional && (flag_end[0] == '\0')) {
return flag_end;
}
// If def_optional is true and there are more characters after the
// flag name, or if def_optional is false, there must be a '=' after
// the flag name.
if (flag_end[0] != '=') return NULL;
// Returns the string after "=".
return flag_end + 1;
}
// Parses a string for a bool flag, in the form of either
// "--flag=value" or "--flag".
//
// In the former case, the value is taken as true as long as it does
// not start with '0', 'f', or 'F'.
//
// In the latter case, the value is taken as true.
//
// On success, stores the value of the flag in *value, and returns
// true. On failure, returns false without changing *value.
bool ParseBoolFlag(const char* str, const char* flag, bool* value) {
// Gets the value of the flag as a string.
const char* const value_str = ParseFlagValue(str, flag, true);
// Aborts if the parsing failed.
if (value_str == NULL) return false;
// Converts the string value to a bool.
*value = !(*value_str == '0' || *value_str == 'f' || *value_str == 'F');
return true;
}
// Parses a string for an Int32 flag, in the form of
// "--flag=value".
//
// On success, stores the value of the flag in *value, and returns
// true. On failure, returns false without changing *value.
bool ParseInt32Flag(const char* str, const char* flag, Int32* value) {
// Gets the value of the flag as a string.
const char* const value_str = ParseFlagValue(str, flag, false);
// Aborts if the parsing failed.
if (value_str == NULL) return false;
// Sets *value to the value of the flag.
return ParseInt32(Message() << "The value of flag --" << flag,
value_str, value);
}
// Parses a string for a string flag, in the form of
// "--flag=value".
//
// On success, stores the value of the flag in *value, and returns
// true. On failure, returns false without changing *value.
bool ParseStringFlag(const char* str, const char* flag, String* value) {
// Gets the value of the flag as a string.
const char* const value_str = ParseFlagValue(str, flag, false);
// Aborts if the parsing failed.
if (value_str == NULL) return false;
// Sets *value to the value of the flag.
*value = value_str;
return true;
}
// Determines whether a string has a prefix that Google Test uses for its
// flags, i.e., starts with GTEST_FLAG_PREFIX_ or GTEST_FLAG_PREFIX_DASH_.
// If Google Test detects that a command line flag has its prefix but is not
// recognized, it will print its help message. Flags starting with
// GTEST_INTERNAL_PREFIX_ followed by "internal_" are considered Google Test
// internal flags and do not trigger the help message.
static bool HasGoogleTestFlagPrefix(const char* str) {
return (SkipPrefix("--", &str) ||
SkipPrefix("-", &str) ||
SkipPrefix("/", &str)) &&
!SkipPrefix(GTEST_FLAG_PREFIX_ "internal_", &str) &&
(SkipPrefix(GTEST_FLAG_PREFIX_, &str) ||
SkipPrefix(GTEST_FLAG_PREFIX_DASH_, &str));
}
// Prints a string containing code-encoded text. The following escape
// sequences can be used in the string to control the text color:
//
// @@ prints a single '@' character.
// @R changes the color to red.
// @G changes the color to green.
// @Y changes the color to yellow.
// @D changes to the default terminal text color.
//
// TODO(wan@google.com): Write tests for this once we add stdout
// capturing to Google Test.
static void PrintColorEncoded(const char* str) {
GTestColor color = COLOR_DEFAULT; // The current color.
// Conceptually, we split the string into segments divided by escape
// sequences. Then we print one segment at a time. At the end of
// each iteration, the str pointer advances to the beginning of the
// next segment.
for (;;) {
const char* p = strchr(str, '@');
if (p == NULL) {
ColoredPrintf(color, "%s", str);
return;
}
ColoredPrintf(color, "%s", String(str, p - str).c_str());
const char ch = p[1];
str = p + 2;
if (ch == '@') {
ColoredPrintf(color, "@");
} else if (ch == 'D') {
color = COLOR_DEFAULT;
} else if (ch == 'R') {
color = COLOR_RED;
} else if (ch == 'G') {
color = COLOR_GREEN;
} else if (ch == 'Y') {
color = COLOR_YELLOW;
} else {
--str;
}
}
}
static const char kColorEncodedHelpMessage[] =
"This program contains tests written using " GTEST_NAME_ ". You can use the\n"
"following command line flags to control its behavior:\n"
"\n"
"Test Selection:\n"
" @G--" GTEST_FLAG_PREFIX_ "list_tests@D\n"
" List the names of all tests instead of running them. The name of\n"
" TEST(Foo, Bar) is \"Foo.Bar\".\n"
" @G--" GTEST_FLAG_PREFIX_ "filter=@YPOSTIVE_PATTERNS"
"[@G-@YNEGATIVE_PATTERNS]@D\n"
" Run only the tests whose name matches one of the positive patterns but\n"
" none of the negative patterns. '?' matches any single character; '*'\n"
" matches any substring; ':' separates two patterns.\n"
" @G--" GTEST_FLAG_PREFIX_ "also_run_disabled_tests@D\n"
" Run all disabled tests too.\n"
"\n"
"Test Execution:\n"
" @G--" GTEST_FLAG_PREFIX_ "repeat=@Y[COUNT]@D\n"
" Run the tests repeatedly; use a negative count to repeat forever.\n"
" @G--" GTEST_FLAG_PREFIX_ "shuffle@D\n"
" Randomize tests' orders on every iteration.\n"
" @G--" GTEST_FLAG_PREFIX_ "random_seed=@Y[NUMBER]@D\n"
" Random number seed to use for shuffling test orders (between 1 and\n"
" 99999, or 0 to use a seed based on the current time).\n"
"\n"
"Test Output:\n"
" @G--" GTEST_FLAG_PREFIX_ "color=@Y(@Gyes@Y|@Gno@Y|@Gauto@Y)@D\n"
" Enable/disable colored output. The default is @Gauto@D.\n"
" -@G-" GTEST_FLAG_PREFIX_ "print_time=0@D\n"
" Don't print the elapsed time of each test.\n"
" @G--" GTEST_FLAG_PREFIX_ "output=xml@Y[@G:@YDIRECTORY_PATH@G"
GTEST_PATH_SEP_ "@Y|@G:@YFILE_PATH]@D\n"
" Generate an XML report in the given directory or with the given file\n"
" name. @YFILE_PATH@D defaults to @Gtest_details.xml@D.\n"
#if GTEST_CAN_STREAM_RESULTS_
" @G--" GTEST_FLAG_PREFIX_ "stream_result_to=@YHOST@G:@YPORT@D\n"
" Stream test results to the given server.\n"
#endif // GTEST_CAN_STREAM_RESULTS_
"\n"
"Assertion Behavior:\n"
#if GTEST_HAS_DEATH_TEST && !GTEST_OS_WINDOWS
" @G--" GTEST_FLAG_PREFIX_ "death_test_style=@Y(@Gfast@Y|@Gthreadsafe@Y)@D\n"
" Set the default death test style.\n"
#endif // GTEST_HAS_DEATH_TEST && !GTEST_OS_WINDOWS
" @G--" GTEST_FLAG_PREFIX_ "break_on_failure@D\n"
" Turn assertion failures into debugger break-points.\n"
" @G--" GTEST_FLAG_PREFIX_ "throw_on_failure@D\n"
" Turn assertion failures into C++ exceptions.\n"
" @G--" GTEST_FLAG_PREFIX_ "catch_exceptions=0@D\n"
" Do not report exceptions as test failures. Instead, allow them\n"
" to crash the program or throw a pop-up (on Windows).\n"
"\n"
"Except for @G--" GTEST_FLAG_PREFIX_ "list_tests@D, you can alternatively set "
"the corresponding\n"
"environment variable of a flag (all letters in upper-case). For example, to\n"
"disable colored text output, you can either specify @G--" GTEST_FLAG_PREFIX_
"color=no@D or set\n"
"the @G" GTEST_FLAG_PREFIX_UPPER_ "COLOR@D environment variable to @Gno@D.\n"
"\n"
"For more information, please read the " GTEST_NAME_ " documentation at\n"
"@G" GTEST_PROJECT_URL_ "@D. If you find a bug in " GTEST_NAME_ "\n"
"(not one in your own code or tests), please report it to\n"
"@G<" GTEST_DEV_EMAIL_ ">@D.\n";
// Parses the command line for Google Test flags, without initializing
// other parts of Google Test. The type parameter CharType can be
// instantiated to either char or wchar_t.
template <typename CharType>
void ParseGoogleTestFlagsOnlyImpl(int* argc, CharType** argv) {
for (int i = 1; i < *argc; i++) {
const String arg_string = StreamableToString(argv[i]);
const char* const arg = arg_string.c_str();
using internal::ParseBoolFlag;
using internal::ParseInt32Flag;
using internal::ParseStringFlag;
// Do we see a Google Test flag?
if (ParseBoolFlag(arg, kAlsoRunDisabledTestsFlag,
>EST_FLAG(also_run_disabled_tests)) ||
ParseBoolFlag(arg, kBreakOnFailureFlag,
>EST_FLAG(break_on_failure)) ||
ParseBoolFlag(arg, kCatchExceptionsFlag,
>EST_FLAG(catch_exceptions)) ||
ParseStringFlag(arg, kColorFlag, >EST_FLAG(color)) ||
ParseStringFlag(arg, kDeathTestStyleFlag,
>EST_FLAG(death_test_style)) ||
ParseBoolFlag(arg, kDeathTestUseFork,
>EST_FLAG(death_test_use_fork)) ||
ParseStringFlag(arg, kFilterFlag, >EST_FLAG(filter)) ||
ParseStringFlag(arg, kInternalRunDeathTestFlag,
>EST_FLAG(internal_run_death_test)) ||
ParseBoolFlag(arg, kListTestsFlag, >EST_FLAG(list_tests)) ||
ParseStringFlag(arg, kOutputFlag, >EST_FLAG(output)) ||
ParseBoolFlag(arg, kPrintTimeFlag, >EST_FLAG(print_time)) ||
ParseInt32Flag(arg, kRandomSeedFlag, >EST_FLAG(random_seed)) ||
ParseInt32Flag(arg, kRepeatFlag, >EST_FLAG(repeat)) ||
ParseBoolFlag(arg, kShuffleFlag, >EST_FLAG(shuffle)) ||
ParseInt32Flag(arg, kStackTraceDepthFlag,
>EST_FLAG(stack_trace_depth)) ||
ParseStringFlag(arg, kStreamResultToFlag,
>EST_FLAG(stream_result_to)) ||
ParseBoolFlag(arg, kThrowOnFailureFlag,
>EST_FLAG(throw_on_failure))
) {
// Yes. Shift the remainder of the argv list left by one. Note
// that argv has (*argc + 1) elements, the last one always being
// NULL. The following loop moves the trailing NULL element as
// well.
for (int j = i; j != *argc; j++) {
argv[j] = argv[j + 1];
}
// Decrements the argument count.
(*argc)--;
// We also need to decrement the iterator as we just removed
// an element.
i--;
} else if (arg_string == "--help" || arg_string == "-h" ||
arg_string == "-?" || arg_string == "/?" ||
HasGoogleTestFlagPrefix(arg)) {
// Both help flag and unrecognized Google Test flags (excluding
// internal ones) trigger help display.
g_help_flag = true;
}
}
if (g_help_flag) {
// We print the help here instead of in RUN_ALL_TESTS(), as the
// latter may not be called at all if the user is using Google
// Test with another testing framework.
PrintColorEncoded(kColorEncodedHelpMessage);
}
}
// Parses the command line for Google Test flags, without initializing
// other parts of Google Test.
void ParseGoogleTestFlagsOnly(int* argc, char** argv) {
ParseGoogleTestFlagsOnlyImpl(argc, argv);
}
void ParseGoogleTestFlagsOnly(int* argc, wchar_t** argv) {
ParseGoogleTestFlagsOnlyImpl(argc, argv);
}
// The internal implementation of InitGoogleTest().
//
// The type parameter CharType can be instantiated to either char or
// wchar_t.
template <typename CharType>
void InitGoogleTestImpl(int* argc, CharType** argv) {
g_init_gtest_count++;
// We don't want to run the initialization code twice.
if (g_init_gtest_count != 1) return;
if (*argc <= 0) return;
internal::g_executable_path = internal::StreamableToString(argv[0]);
#if GTEST_HAS_DEATH_TEST
g_argvs.clear();
for (int i = 0; i != *argc; i++) {
g_argvs.push_back(StreamableToString(argv[i]));
}
#endif // GTEST_HAS_DEATH_TEST
ParseGoogleTestFlagsOnly(argc, argv);
GetUnitTestImpl()->PostFlagParsingInit();
}
} // namespace internal
// Initializes Google Test. This must be called before calling
// RUN_ALL_TESTS(). In particular, it parses a command line for the
// flags that Google Test recognizes. Whenever a Google Test flag is
// seen, it is removed from argv, and *argc is decremented.
//
// No value is returned. Instead, the Google Test flag variables are
// updated.
//
// Calling the function for the second time has no user-visible effect.
void InitGoogleTest(int* argc, char** argv) {
internal::InitGoogleTestImpl(argc, argv);
}
// This overloaded version can be used in Windows programs compiled in
// UNICODE mode.
void InitGoogleTest(int* argc, wchar_t** argv) {
internal::InitGoogleTestImpl(argc, argv);
}
} // namespace testing
// Copyright 2005, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Author: wan@google.com (Zhanyong Wan), vladl@google.com (Vlad Losev)
//
// This file implements death tests.
#if GTEST_HAS_DEATH_TEST
# if GTEST_OS_MAC
# include <crt_externs.h>
# endif // GTEST_OS_MAC
# include <errno.h>
# include <fcntl.h>
# include <limits.h>
# include <stdarg.h>
# if GTEST_OS_WINDOWS
# include <windows.h>
# else
# include <sys/mman.h>
# include <sys/wait.h>
# endif // GTEST_OS_WINDOWS
#endif // GTEST_HAS_DEATH_TEST
// Indicates that this translation unit is part of Google Test's
// implementation. It must come before gtest-internal-inl.h is
// included, or there will be a compiler error. This trick is to
// prevent a user from accidentally including gtest-internal-inl.h in
// his code.
#define GTEST_IMPLEMENTATION_ 1
#undef GTEST_IMPLEMENTATION_
namespace testing {
// Constants.
// The default death test style.
static const char kDefaultDeathTestStyle[] = "fast";
GTEST_DEFINE_string_(
death_test_style,
internal::StringFromGTestEnv("death_test_style", kDefaultDeathTestStyle),
"Indicates how to run a death test in a forked child process: "
"\"threadsafe\" (child process re-executes the test binary "
"from the beginning, running only the specific death test) or "
"\"fast\" (child process runs the death test immediately "
"after forking).");
GTEST_DEFINE_bool_(
death_test_use_fork,
internal::BoolFromGTestEnv("death_test_use_fork", false),
"Instructs to use fork()/_exit() instead of clone() in death tests. "
"Ignored and always uses fork() on POSIX systems where clone() is not "
"implemented. Useful when running under valgrind or similar tools if "
"those do not support clone(). Valgrind 3.3.1 will just fail if "
"it sees an unsupported combination of clone() flags. "
"It is not recommended to use this flag w/o valgrind though it will "
"work in 99% of the cases. Once valgrind is fixed, this flag will "
"most likely be removed.");
namespace internal {
GTEST_DEFINE_string_(
internal_run_death_test, "",
"Indicates the file, line number, temporal index of "
"the single death test to run, and a file descriptor to "
"which a success code may be sent, all separated by "
"colons. This flag is specified if and only if the current "
"process is a sub-process launched for running a thread-safe "
"death test. FOR INTERNAL USE ONLY.");
} // namespace internal
#if GTEST_HAS_DEATH_TEST
// ExitedWithCode constructor.
ExitedWithCode::ExitedWithCode(int exit_code) : exit_code_(exit_code) {
}
// ExitedWithCode function-call operator.
bool ExitedWithCode::operator()(int exit_status) const {
# if GTEST_OS_WINDOWS
return exit_status == exit_code_;
# else
return WIFEXITED(exit_status) && WEXITSTATUS(exit_status) == exit_code_;
# endif // GTEST_OS_WINDOWS
}
# if !GTEST_OS_WINDOWS
// KilledBySignal constructor.
KilledBySignal::KilledBySignal(int signum) : signum_(signum) {
}
// KilledBySignal function-call operator.
bool KilledBySignal::operator()(int exit_status) const {
return WIFSIGNALED(exit_status) && WTERMSIG(exit_status) == signum_;
}
# endif // !GTEST_OS_WINDOWS
namespace internal {
// Utilities needed for death tests.
// Generates a textual description of a given exit code, in the format
// specified by wait(2).
static String ExitSummary(int exit_code) {
Message m;
# if GTEST_OS_WINDOWS
m << "Exited with exit status " << exit_code;
# else
if (WIFEXITED(exit_code)) {
m << "Exited with exit status " << WEXITSTATUS(exit_code);
} else if (WIFSIGNALED(exit_code)) {
m << "Terminated by signal " << WTERMSIG(exit_code);
}
# ifdef WCOREDUMP
if (WCOREDUMP(exit_code)) {
m << " (core dumped)";
}
# endif
# endif // GTEST_OS_WINDOWS
return m.GetString();
}
// Returns true if exit_status describes a process that was terminated
// by a signal, or exited normally with a nonzero exit code.
bool ExitedUnsuccessfully(int exit_status) {
return !ExitedWithCode(0)(exit_status);
}
# if !GTEST_OS_WINDOWS
// Generates a textual failure message when a death test finds more than
// one thread running, or cannot determine the number of threads, prior
// to executing the given statement. It is the responsibility of the
// caller not to pass a thread_count of 1.
static String DeathTestThreadWarning(size_t thread_count) {
Message msg;
msg << "Death tests use fork(), which is unsafe particularly"
<< " in a threaded context. For this test, " << GTEST_NAME_ << " ";
if (thread_count == 0)
msg << "couldn't detect the number of threads.";
else
msg << "detected " << thread_count << " threads.";
return msg.GetString();
}
# endif // !GTEST_OS_WINDOWS
// Flag characters for reporting a death test that did not die.
static const char kDeathTestLived = 'L';
static const char kDeathTestReturned = 'R';
static const char kDeathTestThrew = 'T';
static const char kDeathTestInternalError = 'I';
// An enumeration describing all of the possible ways that a death test can
// conclude. DIED means that the process died while executing the test
// code; LIVED means that process lived beyond the end of the test code;
// RETURNED means that the test statement attempted to execute a return
// statement, which is not allowed; THREW means that the test statement
// returned control by throwing an exception. IN_PROGRESS means the test
// has not yet concluded.
// TODO(vladl@google.com): Unify names and possibly values for
// AbortReason, DeathTestOutcome, and flag characters above.
enum DeathTestOutcome { IN_PROGRESS, DIED, LIVED, RETURNED, THREW };
// Routine for aborting the program which is safe to call from an
// exec-style death test child process, in which case the error
// message is propagated back to the parent process. Otherwise, the
// message is simply printed to stderr. In either case, the program
// then exits with status 1.
void DeathTestAbort(const String& message) {
// On a POSIX system, this function may be called from a threadsafe-style
// death test child process, which operates on a very small stack. Use
// the heap for any additional non-minuscule memory requirements.
const InternalRunDeathTestFlag* const flag =
GetUnitTestImpl()->internal_run_death_test_flag();
if (flag != NULL) {
FILE* parent = posix::FDOpen(flag->write_fd(), "w");
fputc(kDeathTestInternalError, parent);
fprintf(parent, "%s", message.c_str());
fflush(parent);
_exit(1);
} else {
fprintf(stderr, "%s", message.c_str());
fflush(stderr);
posix::Abort();
}
}
// A replacement for CHECK that calls DeathTestAbort if the assertion
// fails.
# define GTEST_DEATH_TEST_CHECK_(expression) \
do { \
if (!::testing::internal::IsTrue(expression)) { \
DeathTestAbort(::testing::internal::String::Format( \
"CHECK failed: File %s, line %d: %s", \
__FILE__, __LINE__, #expression)); \
} \
} while (::testing::internal::AlwaysFalse())
// This macro is similar to GTEST_DEATH_TEST_CHECK_, but it is meant for
// evaluating any system call that fulfills two conditions: it must return
// -1 on failure, and set errno to EINTR when it is interrupted and
// should be tried again. The macro expands to a loop that repeatedly
// evaluates the expression as long as it evaluates to -1 and sets
// errno to EINTR. If the expression evaluates to -1 but errno is
// something other than EINTR, DeathTestAbort is called.
# define GTEST_DEATH_TEST_CHECK_SYSCALL_(expression) \
do { \
int gtest_retval; \
do { \
gtest_retval = (expression); \
} while (gtest_retval == -1 && errno == EINTR); \
if (gtest_retval == -1) { \
DeathTestAbort(::testing::internal::String::Format( \
"CHECK failed: File %s, line %d: %s != -1", \
__FILE__, __LINE__, #expression)); \
} \
} while (::testing::internal::AlwaysFalse())
// Returns the message describing the last system error in errno.
String GetLastErrnoDescription() {
return String(errno == 0 ? "" : posix::StrError(errno));
}
// This is called from a death test parent process to read a failure
// message from the death test child process and log it with the FATAL
// severity. On Windows, the message is read from a pipe handle. On other
// platforms, it is read from a file descriptor.
static void FailFromInternalError(int fd) {
Message error;
char buffer[256];
int num_read;
do {
while ((num_read = posix::Read(fd, buffer, 255)) > 0) {
buffer[num_read] = '\0';
error << buffer;
}
} while (num_read == -1 && errno == EINTR);
if (num_read == 0) {
GTEST_LOG_(FATAL) << error.GetString();
} else {
const int last_error = errno;
GTEST_LOG_(FATAL) << "Error while reading death test internal: "
<< GetLastErrnoDescription() << " [" << last_error << "]";
}
}
// Death test constructor. Increments the running death test count
// for the current test.
DeathTest::DeathTest() {
TestInfo* const info = GetUnitTestImpl()->current_test_info();
if (info == NULL) {
DeathTestAbort("Cannot run a death test outside of a TEST or "
"TEST_F construct");
}
}
// Creates and returns a death test by dispatching to the current
// death test factory.
bool DeathTest::Create(const char* statement, const RE* regex,
const char* file, int line, DeathTest** test) {
return GetUnitTestImpl()->death_test_factory()->Create(
statement, regex, file, line, test);
}
const char* DeathTest::LastMessage() {
return last_death_test_message_.c_str();
}
void DeathTest::set_last_death_test_message(const String& message) {
last_death_test_message_ = message;
}
String DeathTest::last_death_test_message_;
// Provides cross platform implementation for some death functionality.
class DeathTestImpl : public DeathTest {
protected:
DeathTestImpl(const char* a_statement, const RE* a_regex)
: statement_(a_statement),
regex_(a_regex),
spawned_(false),
status_(-1),
outcome_(IN_PROGRESS),
read_fd_(-1),
write_fd_(-1) {}
// read_fd_ is expected to be closed and cleared by a derived class.
~DeathTestImpl() { GTEST_DEATH_TEST_CHECK_(read_fd_ == -1); }
void Abort(AbortReason reason);
virtual bool Passed(bool status_ok);
const char* statement() const { return statement_; }
const RE* regex() const { return regex_; }
bool spawned() const { return spawned_; }
void set_spawned(bool is_spawned) { spawned_ = is_spawned; }
int status() const { return status_; }
void set_status(int a_status) { status_ = a_status; }
DeathTestOutcome outcome() const { return outcome_; }
void set_outcome(DeathTestOutcome an_outcome) { outcome_ = an_outcome; }
int read_fd() const { return read_fd_; }
void set_read_fd(int fd) { read_fd_ = fd; }
int write_fd() const { return write_fd_; }
void set_write_fd(int fd) { write_fd_ = fd; }
// Called in the parent process only. Reads the result code of the death
// test child process via a pipe, interprets it to set the outcome_
// member, and closes read_fd_. Outputs diagnostics and terminates in
// case of unexpected codes.
void ReadAndInterpretStatusByte();
private:
// The textual content of the code this object is testing. This class
// doesn't own this string and should not attempt to delete it.
const char* const statement_;
// The regular expression which test output must match. DeathTestImpl
// doesn't own this object and should not attempt to delete it.
const RE* const regex_;
// True if the death test child process has been successfully spawned.
bool spawned_;
// The exit status of the child process.
int status_;
// How the death test concluded.
DeathTestOutcome outcome_;
// Descriptor to the read end of the pipe to the child process. It is
// always -1 in the child process. The child keeps its write end of the
// pipe in write_fd_.
int read_fd_;
// Descriptor to the child's write end of the pipe to the parent process.
// It is always -1 in the parent process. The parent keeps its end of the
// pipe in read_fd_.
int write_fd_;
};
// Called in the parent process only. Reads the result code of the death
// test child process via a pipe, interprets it to set the outcome_
// member, and closes read_fd_. Outputs diagnostics and terminates in
// case of unexpected codes.
void DeathTestImpl::ReadAndInterpretStatusByte() {
char flag;
int bytes_read;
// The read() here blocks until data is available (signifying the
// failure of the death test) or until the pipe is closed (signifying
// its success), so it's okay to call this in the parent before
// the child process has exited.
do {
bytes_read = posix::Read(read_fd(), &flag, 1);
} while (bytes_read == -1 && errno == EINTR);
if (bytes_read == 0) {
set_outcome(DIED);
} else if (bytes_read == 1) {
switch (flag) {
case kDeathTestReturned:
set_outcome(RETURNED);
break;
case kDeathTestThrew:
set_outcome(THREW);
break;
case kDeathTestLived:
set_outcome(LIVED);
break;
case kDeathTestInternalError:
FailFromInternalError(read_fd()); // Does not return.
break;
default:
GTEST_LOG_(FATAL) << "Death test child process reported "
<< "unexpected status byte ("
<< static_cast<unsigned int>(flag) << ")";
}
} else {
GTEST_LOG_(FATAL) << "Read from death test child process failed: "
<< GetLastErrnoDescription();
}
GTEST_DEATH_TEST_CHECK_SYSCALL_(posix::Close(read_fd()));
set_read_fd(-1);
}
// Signals that the death test code which should have exited, didn't.
// Should be called only in a death test child process.
// Writes a status byte to the child's status file descriptor, then
// calls _exit(1).
void DeathTestImpl::Abort(AbortReason reason) {
// The parent process considers the death test to be a failure if
// it finds any data in our pipe. So, here we write a single flag byte
// to the pipe, then exit.
const char status_ch =
reason == TEST_DID_NOT_DIE ? kDeathTestLived :
reason == TEST_THREW_EXCEPTION ? kDeathTestThrew : kDeathTestReturned;
GTEST_DEATH_TEST_CHECK_SYSCALL_(posix::Write(write_fd(), &status_ch, 1));
// We are leaking the descriptor here because on some platforms (i.e.,
// when built as Windows DLL), destructors of global objects will still
// run after calling _exit(). On such systems, write_fd_ will be
// indirectly closed from the destructor of UnitTestImpl, causing double
// close if it is also closed here. On debug configurations, double close
// may assert. As there are no in-process buffers to flush here, we are
// relying on the OS to close the descriptor after the process terminates
// when the destructors are not run.
_exit(1); // Exits w/o any normal exit hooks (we were supposed to crash)
}
// Returns an indented copy of stderr output for a death test.
// This makes distinguishing death test output lines from regular log lines
// much easier.
static ::std::string FormatDeathTestOutput(const ::std::string& output) {
::std::string ret;
for (size_t at = 0; ; ) {
const size_t line_end = output.find('\n', at);
ret += "[ DEATH ] ";
if (line_end == ::std::string::npos) {
ret += output.substr(at);
break;
}
ret += output.substr(at, line_end + 1 - at);
at = line_end + 1;
}
return ret;
}
// Assesses the success or failure of a death test, using both private
// members which have previously been set, and one argument:
//
// Private data members:
// outcome: An enumeration describing how the death test
// concluded: DIED, LIVED, THREW, or RETURNED. The death test
// fails in the latter three cases.
// status: The exit status of the child process. On *nix, it is in the
// in the format specified by wait(2). On Windows, this is the
// value supplied to the ExitProcess() API or a numeric code
// of the exception that terminated the program.
// regex: A regular expression object to be applied to
// the test's captured standard error output; the death test
// fails if it does not match.
//
// Argument:
// status_ok: true if exit_status is acceptable in the context of
// this particular death test, which fails if it is false
//
// Returns true iff all of the above conditions are met. Otherwise, the
// first failing condition, in the order given above, is the one that is
// reported. Also sets the last death test message string.
bool DeathTestImpl::Passed(bool status_ok) {
if (!spawned())
return false;
const String error_message = GetCapturedStderr();
bool success = false;
Message buffer;
buffer << "Death test: " << statement() << "\n";
switch (outcome()) {
case LIVED:
buffer << " Result: failed to die.\n"
<< " Error msg:\n" << FormatDeathTestOutput(error_message);
break;
case THREW:
buffer << " Result: threw an exception.\n"
<< " Error msg:\n" << FormatDeathTestOutput(error_message);
break;
case RETURNED:
buffer << " Result: illegal return in test statement.\n"
<< " Error msg:\n" << FormatDeathTestOutput(error_message);
break;
case DIED:
if (status_ok) {
const bool matched = RE::PartialMatch(error_message.c_str(), *regex());
if (matched) {
success = true;
} else {
buffer << " Result: died but not with expected error.\n"
<< " Expected: " << regex()->pattern() << "\n"
<< "Actual msg:\n" << FormatDeathTestOutput(error_message);
}
} else {
buffer << " Result: died but not with expected exit code:\n"
<< " " << ExitSummary(status()) << "\n"
<< "Actual msg:\n" << FormatDeathTestOutput(error_message);
}
break;
case IN_PROGRESS:
default:
GTEST_LOG_(FATAL)
<< "DeathTest::Passed somehow called before conclusion of test";
}
DeathTest::set_last_death_test_message(buffer.GetString());
return success;
}
# if GTEST_OS_WINDOWS
// WindowsDeathTest implements death tests on Windows. Due to the
// specifics of starting new processes on Windows, death tests there are
// always threadsafe, and Google Test considers the
// --gtest_death_test_style=fast setting to be equivalent to
// --gtest_death_test_style=threadsafe there.
//
// A few implementation notes: Like the Linux version, the Windows
// implementation uses pipes for child-to-parent communication. But due to
// the specifics of pipes on Windows, some extra steps are required:
//
// 1. The parent creates a communication pipe and stores handles to both
// ends of it.
// 2. The parent starts the child and provides it with the information
// necessary to acquire the handle to the write end of the pipe.
// 3. The child acquires the write end of the pipe and signals the parent
// using a Windows event.
// 4. Now the parent can release the write end of the pipe on its side. If
// this is done before step 3, the object's reference count goes down to
// 0 and it is destroyed, preventing the child from acquiring it. The
// parent now has to release it, or read operations on the read end of
// the pipe will not return when the child terminates.
// 5. The parent reads child's output through the pipe (outcome code and
// any possible error messages) from the pipe, and its stderr and then
// determines whether to fail the test.
//
// Note: to distinguish Win32 API calls from the local method and function
// calls, the former are explicitly resolved in the global namespace.
//
class WindowsDeathTest : public DeathTestImpl {
public:
WindowsDeathTest(const char* a_statement,
const RE* a_regex,
const char* file,
int line)
: DeathTestImpl(a_statement, a_regex), file_(file), line_(line) {}
// All of these virtual functions are inherited from DeathTest.
virtual int Wait();
virtual TestRole AssumeRole();
private:
// The name of the file in which the death test is located.
const char* const file_;
// The line number on which the death test is located.
const int line_;
// Handle to the write end of the pipe to the child process.
AutoHandle write_handle_;
// Child process handle.
AutoHandle child_handle_;
// Event the child process uses to signal the parent that it has
// acquired the handle to the write end of the pipe. After seeing this
// event the parent can release its own handles to make sure its
// ReadFile() calls return when the child terminates.
AutoHandle event_handle_;
};
// Waits for the child in a death test to exit, returning its exit
// status, or 0 if no child process exists. As a side effect, sets the
// outcome data member.
int WindowsDeathTest::Wait() {
if (!spawned())
return 0;
// Wait until the child either signals that it has acquired the write end
// of the pipe or it dies.
const HANDLE wait_handles[2] = { child_handle_.Get(), event_handle_.Get() };
switch (::WaitForMultipleObjects(2,
wait_handles,
FALSE, // Waits for any of the handles.
INFINITE)) {
case WAIT_OBJECT_0:
case WAIT_OBJECT_0 + 1:
break;
default:
GTEST_DEATH_TEST_CHECK_(false); // Should not get here.
}
// The child has acquired the write end of the pipe or exited.
// We release the handle on our side and continue.
write_handle_.Reset();
event_handle_.Reset();
ReadAndInterpretStatusByte();
// Waits for the child process to exit if it haven't already. This
// returns immediately if the child has already exited, regardless of
// whether previous calls to WaitForMultipleObjects synchronized on this
// handle or not.
GTEST_DEATH_TEST_CHECK_(
WAIT_OBJECT_0 == ::WaitForSingleObject(child_handle_.Get(),
INFINITE));
DWORD status_code;
GTEST_DEATH_TEST_CHECK_(
::GetExitCodeProcess(child_handle_.Get(), &status_code) != FALSE);
child_handle_.Reset();
set_status(static_cast<int>(status_code));
return status();
}
// The AssumeRole process for a Windows death test. It creates a child
// process with the same executable as the current process to run the
// death test. The child process is given the --gtest_filter and
// --gtest_internal_run_death_test flags such that it knows to run the
// current death test only.
DeathTest::TestRole WindowsDeathTest::AssumeRole() {
const UnitTestImpl* const impl = GetUnitTestImpl();
const InternalRunDeathTestFlag* const flag =
impl->internal_run_death_test_flag();
const TestInfo* const info = impl->current_test_info();
const int death_test_index = info->result()->death_test_count();
if (flag != NULL) {
// ParseInternalRunDeathTestFlag() has performed all the necessary
// processing.
set_write_fd(flag->write_fd());
return EXECUTE_TEST;
}
// WindowsDeathTest uses an anonymous pipe to communicate results of
// a death test.
SECURITY_ATTRIBUTES handles_are_inheritable = {
sizeof(SECURITY_ATTRIBUTES), NULL, TRUE };
HANDLE read_handle, write_handle;
GTEST_DEATH_TEST_CHECK_(
::CreatePipe(&read_handle, &write_handle, &handles_are_inheritable,
0) // Default buffer size.
!= FALSE);
set_read_fd(::_open_osfhandle(reinterpret_cast<intptr_t>(read_handle),
O_RDONLY));
write_handle_.Reset(write_handle);
event_handle_.Reset(::CreateEvent(
&handles_are_inheritable,
TRUE, // The event will automatically reset to non-signaled state.
FALSE, // The initial state is non-signalled.
NULL)); // The even is unnamed.
GTEST_DEATH_TEST_CHECK_(event_handle_.Get() != NULL);
const String filter_flag = String::Format("--%s%s=%s.%s",
GTEST_FLAG_PREFIX_, kFilterFlag,
info->test_case_name(),
info->name());
const String internal_flag = String::Format(
"--%s%s=%s|%d|%d|%u|%Iu|%Iu",
GTEST_FLAG_PREFIX_,
kInternalRunDeathTestFlag,
file_, line_,
death_test_index,
static_cast<unsigned int>(::GetCurrentProcessId()),
// size_t has the same with as pointers on both 32-bit and 64-bit
// Windows platforms.
// See http://msdn.microsoft.com/en-us/library/tcxf1dw6.aspx.
reinterpret_cast<size_t>(write_handle),
reinterpret_cast<size_t>(event_handle_.Get()));
char executable_path[_MAX_PATH + 1]; // NOLINT
GTEST_DEATH_TEST_CHECK_(
_MAX_PATH + 1 != ::GetModuleFileNameA(NULL,
executable_path,
_MAX_PATH));
String command_line = String::Format("%s %s \"%s\"",
::GetCommandLineA(),
filter_flag.c_str(),
internal_flag.c_str());
DeathTest::set_last_death_test_message("");
CaptureStderr();
// Flush the log buffers since the log streams are shared with the child.
FlushInfoLog();
// The child process will share the standard handles with the parent.
STARTUPINFOA startup_info;
memset(&startup_info, 0, sizeof(STARTUPINFO));
startup_info.dwFlags = STARTF_USESTDHANDLES;
startup_info.hStdInput = ::GetStdHandle(STD_INPUT_HANDLE);
startup_info.hStdOutput = ::GetStdHandle(STD_OUTPUT_HANDLE);
startup_info.hStdError = ::GetStdHandle(STD_ERROR_HANDLE);
PROCESS_INFORMATION process_info;
GTEST_DEATH_TEST_CHECK_(::CreateProcessA(
executable_path,
const_cast<char*>(command_line.c_str()),
NULL, // Retuned process handle is not inheritable.
NULL, // Retuned thread handle is not inheritable.
TRUE, // Child inherits all inheritable handles (for write_handle_).
0x0, // Default creation flags.
NULL, // Inherit the parent's environment.
UnitTest::GetInstance()->original_working_dir(),
&startup_info,
&process_info) != FALSE);
child_handle_.Reset(process_info.hProcess);
::CloseHandle(process_info.hThread);
set_spawned(true);
return OVERSEE_TEST;
}
# else // We are not on Windows.
// ForkingDeathTest provides implementations for most of the abstract
// methods of the DeathTest interface. Only the AssumeRole method is
// left undefined.
class ForkingDeathTest : public DeathTestImpl {
public:
ForkingDeathTest(const char* statement, const RE* regex);
// All of these virtual functions are inherited from DeathTest.
virtual int Wait();
protected:
void set_child_pid(pid_t child_pid) { child_pid_ = child_pid; }
private:
// PID of child process during death test; 0 in the child process itself.
pid_t child_pid_;
};
// Constructs a ForkingDeathTest.
ForkingDeathTest::ForkingDeathTest(const char* a_statement, const RE* a_regex)
: DeathTestImpl(a_statement, a_regex),
child_pid_(-1) {}
// Waits for the child in a death test to exit, returning its exit
// status, or 0 if no child process exists. As a side effect, sets the
// outcome data member.
int ForkingDeathTest::Wait() {
if (!spawned())
return 0;
ReadAndInterpretStatusByte();
int status_value;
GTEST_DEATH_TEST_CHECK_SYSCALL_(waitpid(child_pid_, &status_value, 0));
set_status(status_value);
return status_value;
}
// A concrete death test class that forks, then immediately runs the test
// in the child process.
class NoExecDeathTest : public ForkingDeathTest {
public:
NoExecDeathTest(const char* a_statement, const RE* a_regex) :
ForkingDeathTest(a_statement, a_regex) { }
virtual TestRole AssumeRole();
};
// The AssumeRole process for a fork-and-run death test. It implements a
// straightforward fork, with a simple pipe to transmit the status byte.
DeathTest::TestRole NoExecDeathTest::AssumeRole() {
const size_t thread_count = GetThreadCount();
if (thread_count != 1) {
GTEST_LOG_(WARNING) << DeathTestThreadWarning(thread_count);
}
int pipe_fd[2];
GTEST_DEATH_TEST_CHECK_(pipe(pipe_fd) != -1);
DeathTest::set_last_death_test_message("");
CaptureStderr();
// When we fork the process below, the log file buffers are copied, but the
// file descriptors are shared. We flush all log files here so that closing
// the file descriptors in the child process doesn't throw off the
// synchronization between descriptors and buffers in the parent process.
// This is as close to the fork as possible to avoid a race condition in case
// there are multiple threads running before the death test, and another
// thread writes to the log file.
FlushInfoLog();
const pid_t child_pid = fork();
GTEST_DEATH_TEST_CHECK_(child_pid != -1);
set_child_pid(child_pid);
if (child_pid == 0) {
GTEST_DEATH_TEST_CHECK_SYSCALL_(close(pipe_fd[0]));
set_write_fd(pipe_fd[1]);
// Redirects all logging to stderr in the child process to prevent
// concurrent writes to the log files. We capture stderr in the parent
// process and append the child process' output to a log.
LogToStderr();
// Event forwarding to the listeners of event listener API mush be shut
// down in death test subprocesses.
GetUnitTestImpl()->listeners()->SuppressEventForwarding();
return EXECUTE_TEST;
} else {
GTEST_DEATH_TEST_CHECK_SYSCALL_(close(pipe_fd[1]));
set_read_fd(pipe_fd[0]);
set_spawned(true);
return OVERSEE_TEST;
}
}
// A concrete death test class that forks and re-executes the main
// program from the beginning, with command-line flags set that cause
// only this specific death test to be run.
class ExecDeathTest : public ForkingDeathTest {
public:
ExecDeathTest(const char* a_statement, const RE* a_regex,
const char* file, int line) :
ForkingDeathTest(a_statement, a_regex), file_(file), line_(line) { }
virtual TestRole AssumeRole();
private:
// The name of the file in which the death test is located.
const char* const file_;
// The line number on which the death test is located.
const int line_;
};
// Utility class for accumulating command-line arguments.
class Arguments {
public:
Arguments() {
args_.push_back(NULL);
}
~Arguments() {
for (std::vector<char*>::iterator i = args_.begin(); i != args_.end();
++i) {
free(*i);
}
}
void AddArgument(const char* argument) {
args_.insert(args_.end() - 1, posix::StrDup(argument));
}
template <typename Str>
void AddArguments(const ::std::vector<Str>& arguments) {
for (typename ::std::vector<Str>::const_iterator i = arguments.begin();
i != arguments.end();
++i) {
args_.insert(args_.end() - 1, posix::StrDup(i->c_str()));
}
}
char* const* Argv() {
return &args_[0];
}
private:
std::vector<char*> args_;
};
// A struct that encompasses the arguments to the child process of a
// threadsafe-style death test process.
struct ExecDeathTestArgs {
char* const* argv; // Command-line arguments for the child's call to exec
int close_fd; // File descriptor to close; the read end of a pipe
};
# if GTEST_OS_MAC
inline char** GetEnviron() {
// When Google Test is built as a framework on MacOS X, the environ variable
// is unavailable. Apple's documentation (man environ) recommends using
// _NSGetEnviron() instead.
return *_NSGetEnviron();
}
# else
// Some POSIX platforms expect you to declare environ. extern "C" makes
// it reside in the global namespace.
extern "C" char** environ;
inline char** GetEnviron() { return environ; }
# endif // GTEST_OS_MAC
// The main function for a threadsafe-style death test child process.
// This function is called in a clone()-ed process and thus must avoid
// any potentially unsafe operations like malloc or libc functions.
static int ExecDeathTestChildMain(void* child_arg) {
ExecDeathTestArgs* const args = static_cast<ExecDeathTestArgs*>(child_arg);
GTEST_DEATH_TEST_CHECK_SYSCALL_(close(args->close_fd));
// We need to execute the test program in the same environment where
// it was originally invoked. Therefore we change to the original
// working directory first.
const char* const original_dir =
UnitTest::GetInstance()->original_working_dir();
// We can safely call chdir() as it's a direct system call.
if (chdir(original_dir) != 0) {
DeathTestAbort(String::Format("chdir(\"%s\") failed: %s",
original_dir,
GetLastErrnoDescription().c_str()));
return EXIT_FAILURE;
}
// We can safely call execve() as it's a direct system call. We
// cannot use execvp() as it's a libc function and thus potentially
// unsafe. Since execve() doesn't search the PATH, the user must
// invoke the test program via a valid path that contains at least
// one path separator.
execve(args->argv[0], args->argv, GetEnviron());
DeathTestAbort(String::Format("execve(%s, ...) in %s failed: %s",
args->argv[0],
original_dir,
GetLastErrnoDescription().c_str()));
return EXIT_FAILURE;
}
// Two utility routines that together determine the direction the stack
// grows.
// This could be accomplished more elegantly by a single recursive
// function, but we want to guard against the unlikely possibility of
// a smart compiler optimizing the recursion away.
//
// GTEST_NO_INLINE_ is required to prevent GCC 4.6 from inlining
// StackLowerThanAddress into StackGrowsDown, which then doesn't give
// correct answer.
bool StackLowerThanAddress(const void* ptr) GTEST_NO_INLINE_;
bool StackLowerThanAddress(const void* ptr) {
int dummy;
return &dummy < ptr;
}
bool StackGrowsDown() {
int dummy;
return StackLowerThanAddress(&dummy);
}
// A threadsafe implementation of fork(2) for threadsafe-style death tests
// that uses clone(2). It dies with an error message if anything goes
// wrong.
static pid_t ExecDeathTestFork(char* const* argv, int close_fd) {
ExecDeathTestArgs args = { argv, close_fd };
pid_t child_pid = -1;
# if GTEST_HAS_CLONE
const bool use_fork = GTEST_FLAG(death_test_use_fork);
if (!use_fork) {
static const bool stack_grows_down = StackGrowsDown();
const size_t stack_size = getpagesize();
// MMAP_ANONYMOUS is not defined on Mac, so we use MAP_ANON instead.
void* const stack = mmap(NULL, stack_size, PROT_READ | PROT_WRITE,
MAP_ANON | MAP_PRIVATE, -1, 0);
GTEST_DEATH_TEST_CHECK_(stack != MAP_FAILED);
void* const stack_top =
static_cast<char*>(stack) + (stack_grows_down ? stack_size : 0);
child_pid = clone(&ExecDeathTestChildMain, stack_top, SIGCHLD, &args);
GTEST_DEATH_TEST_CHECK_(munmap(stack, stack_size) != -1);
}
# else
const bool use_fork = true;
# endif // GTEST_HAS_CLONE
if (use_fork && (child_pid = fork()) == 0) {
ExecDeathTestChildMain(&args);
_exit(0);
}
GTEST_DEATH_TEST_CHECK_(child_pid != -1);
return child_pid;
}
// The AssumeRole process for a fork-and-exec death test. It re-executes the
// main program from the beginning, setting the --gtest_filter
// and --gtest_internal_run_death_test flags to cause only the current
// death test to be re-run.
DeathTest::TestRole ExecDeathTest::AssumeRole() {
const UnitTestImpl* const impl = GetUnitTestImpl();
const InternalRunDeathTestFlag* const flag =
impl->internal_run_death_test_flag();
const TestInfo* const info = impl->current_test_info();
const int death_test_index = info->result()->death_test_count();
if (flag != NULL) {
set_write_fd(flag->write_fd());
return EXECUTE_TEST;
}
int pipe_fd[2];
GTEST_DEATH_TEST_CHECK_(pipe(pipe_fd) != -1);
// Clear the close-on-exec flag on the write end of the pipe, lest
// it be closed when the child process does an exec:
GTEST_DEATH_TEST_CHECK_(fcntl(pipe_fd[1], F_SETFD, 0) != -1);
const String filter_flag =
String::Format("--%s%s=%s.%s",
GTEST_FLAG_PREFIX_, kFilterFlag,
info->test_case_name(), info->name());
const String internal_flag =
String::Format("--%s%s=%s|%d|%d|%d",
GTEST_FLAG_PREFIX_, kInternalRunDeathTestFlag,
file_, line_, death_test_index, pipe_fd[1]);
Arguments args;
args.AddArguments(GetArgvs());
args.AddArgument(filter_flag.c_str());
args.AddArgument(internal_flag.c_str());
DeathTest::set_last_death_test_message("");
CaptureStderr();
// See the comment in NoExecDeathTest::AssumeRole for why the next line
// is necessary.
FlushInfoLog();
const pid_t child_pid = ExecDeathTestFork(args.Argv(), pipe_fd[0]);
GTEST_DEATH_TEST_CHECK_SYSCALL_(close(pipe_fd[1]));
set_child_pid(child_pid);
set_read_fd(pipe_fd[0]);
set_spawned(true);
return OVERSEE_TEST;
}
# endif // !GTEST_OS_WINDOWS
// Creates a concrete DeathTest-derived class that depends on the
// --gtest_death_test_style flag, and sets the pointer pointed to
// by the "test" argument to its address. If the test should be
// skipped, sets that pointer to NULL. Returns true, unless the
// flag is set to an invalid value.
bool DefaultDeathTestFactory::Create(const char* statement, const RE* regex,
const char* file, int line,
DeathTest** test) {
UnitTestImpl* const impl = GetUnitTestImpl();
const InternalRunDeathTestFlag* const flag =
impl->internal_run_death_test_flag();
const int death_test_index = impl->current_test_info()
->increment_death_test_count();
if (flag != NULL) {
if (death_test_index > flag->index()) {
DeathTest::set_last_death_test_message(String::Format(
"Death test count (%d) somehow exceeded expected maximum (%d)",
death_test_index, flag->index()));
return false;
}
if (!(flag->file() == file && flag->line() == line &&
flag->index() == death_test_index)) {
*test = NULL;
return true;
}
}
# if GTEST_OS_WINDOWS
if (GTEST_FLAG(death_test_style) == "threadsafe" ||
GTEST_FLAG(death_test_style) == "fast") {
*test = new WindowsDeathTest(statement, regex, file, line);
}
# else
if (GTEST_FLAG(death_test_style) == "threadsafe") {
*test = new ExecDeathTest(statement, regex, file, line);
} else if (GTEST_FLAG(death_test_style) == "fast") {
*test = new NoExecDeathTest(statement, regex);
}
# endif // GTEST_OS_WINDOWS
else { // NOLINT - this is more readable than unbalanced brackets inside #if.
DeathTest::set_last_death_test_message(String::Format(
"Unknown death test style \"%s\" encountered",
GTEST_FLAG(death_test_style).c_str()));
return false;
}
return true;
}
// Splits a given string on a given delimiter, populating a given
// vector with the fields. GTEST_HAS_DEATH_TEST implies that we have
// ::std::string, so we can use it here.
static void SplitString(const ::std::string& str, char delimiter,
::std::vector< ::std::string>* dest) {
::std::vector< ::std::string> parsed;
::std::string::size_type pos = 0;
while (::testing::internal::AlwaysTrue()) {
const ::std::string::size_type colon = str.find(delimiter, pos);
if (colon == ::std::string::npos) {
parsed.push_back(str.substr(pos));
break;
} else {
parsed.push_back(str.substr(pos, colon - pos));
pos = colon + 1;
}
}
dest->swap(parsed);
}
# if GTEST_OS_WINDOWS
// Recreates the pipe and event handles from the provided parameters,
// signals the event, and returns a file descriptor wrapped around the pipe
// handle. This function is called in the child process only.
int GetStatusFileDescriptor(unsigned int parent_process_id,
size_t write_handle_as_size_t,
size_t event_handle_as_size_t) {
AutoHandle parent_process_handle(::OpenProcess(PROCESS_DUP_HANDLE,
FALSE, // Non-inheritable.
parent_process_id));
if (parent_process_handle.Get() == INVALID_HANDLE_VALUE) {
DeathTestAbort(String::Format("Unable to open parent process %u",
parent_process_id));
}
// TODO(vladl@google.com): Replace the following check with a
// compile-time assertion when available.
GTEST_CHECK_(sizeof(HANDLE) <= sizeof(size_t));
const HANDLE write_handle =
reinterpret_cast<HANDLE>(write_handle_as_size_t);
HANDLE dup_write_handle;
// The newly initialized handle is accessible only in in the parent
// process. To obtain one accessible within the child, we need to use
// DuplicateHandle.
if (!::DuplicateHandle(parent_process_handle.Get(), write_handle,
::GetCurrentProcess(), &dup_write_handle,
0x0, // Requested privileges ignored since
// DUPLICATE_SAME_ACCESS is used.
FALSE, // Request non-inheritable handler.
DUPLICATE_SAME_ACCESS)) {
DeathTestAbort(String::Format(
"Unable to duplicate the pipe handle %Iu from the parent process %u",
write_handle_as_size_t, parent_process_id));
}
const HANDLE event_handle = reinterpret_cast<HANDLE>(event_handle_as_size_t);
HANDLE dup_event_handle;
if (!::DuplicateHandle(parent_process_handle.Get(), event_handle,
::GetCurrentProcess(), &dup_event_handle,
0x0,
FALSE,
DUPLICATE_SAME_ACCESS)) {
DeathTestAbort(String::Format(
"Unable to duplicate the event handle %Iu from the parent process %u",
event_handle_as_size_t, parent_process_id));
}
const int write_fd =
::_open_osfhandle(reinterpret_cast<intptr_t>(dup_write_handle), O_APPEND);
if (write_fd == -1) {
DeathTestAbort(String::Format(
"Unable to convert pipe handle %Iu to a file descriptor",
write_handle_as_size_t));
}
// Signals the parent that the write end of the pipe has been acquired
// so the parent can release its own write end.
::SetEvent(dup_event_handle);
return write_fd;
}
# endif // GTEST_OS_WINDOWS
// Returns a newly created InternalRunDeathTestFlag object with fields
// initialized from the GTEST_FLAG(internal_run_death_test) flag if
// the flag is specified; otherwise returns NULL.
InternalRunDeathTestFlag* ParseInternalRunDeathTestFlag() {
if (GTEST_FLAG(internal_run_death_test) == "") return NULL;
// GTEST_HAS_DEATH_TEST implies that we have ::std::string, so we
// can use it here.
int line = -1;
int index = -1;
::std::vector< ::std::string> fields;
SplitString(GTEST_FLAG(internal_run_death_test).c_str(), '|', &fields);
int write_fd = -1;
# if GTEST_OS_WINDOWS
unsigned int parent_process_id = 0;
size_t write_handle_as_size_t = 0;
size_t event_handle_as_size_t = 0;
if (fields.size() != 6
|| !ParseNaturalNumber(fields[1], &line)
|| !ParseNaturalNumber(fields[2], &index)
|| !ParseNaturalNumber(fields[3], &parent_process_id)
|| !ParseNaturalNumber(fields[4], &write_handle_as_size_t)
|| !ParseNaturalNumber(fields[5], &event_handle_as_size_t)) {
DeathTestAbort(String::Format(
"Bad --gtest_internal_run_death_test flag: %s",
GTEST_FLAG(internal_run_death_test).c_str()));
}
write_fd = GetStatusFileDescriptor(parent_process_id,
write_handle_as_size_t,
event_handle_as_size_t);
# else
if (fields.size() != 4
|| !ParseNaturalNumber(fields[1], &line)
|| !ParseNaturalNumber(fields[2], &index)
|| !ParseNaturalNumber(fields[3], &write_fd)) {
DeathTestAbort(String::Format(
"Bad --gtest_internal_run_death_test flag: %s",
GTEST_FLAG(internal_run_death_test).c_str()));
}
# endif // GTEST_OS_WINDOWS
return new InternalRunDeathTestFlag(fields[0], line, index, write_fd);
}
} // namespace internal
#endif // GTEST_HAS_DEATH_TEST
} // namespace testing
// Copyright 2008, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Authors: keith.ray@gmail.com (Keith Ray)
#include <stdlib.h>
#if GTEST_OS_WINDOWS_MOBILE
# include <windows.h>
#elif GTEST_OS_WINDOWS
# include <direct.h>
# include <io.h>
#elif GTEST_OS_SYMBIAN || GTEST_OS_NACL
// Symbian OpenC and NaCl have PATH_MAX in sys/syslimits.h
# include <sys/syslimits.h>
#else
# include <limits.h>
# include <climits> // Some Linux distributions define PATH_MAX here.
#endif // GTEST_OS_WINDOWS_MOBILE
#if GTEST_OS_WINDOWS
# define GTEST_PATH_MAX_ _MAX_PATH
#elif defined(PATH_MAX)
# define GTEST_PATH_MAX_ PATH_MAX
#elif defined(_XOPEN_PATH_MAX)
# define GTEST_PATH_MAX_ _XOPEN_PATH_MAX
#else
# define GTEST_PATH_MAX_ _POSIX_PATH_MAX
#endif // GTEST_OS_WINDOWS
namespace testing {
namespace internal {
#if GTEST_OS_WINDOWS
// On Windows, '\\' is the standard path separator, but many tools and the
// Windows API also accept '/' as an alternate path separator. Unless otherwise
// noted, a file path can contain either kind of path separators, or a mixture
// of them.
const char kPathSeparator = '\\';
const char kAlternatePathSeparator = '/';
const char kPathSeparatorString[] = "\\";
const char kAlternatePathSeparatorString[] = "/";
# if GTEST_OS_WINDOWS_MOBILE
// Windows CE doesn't have a current directory. You should not use
// the current directory in tests on Windows CE, but this at least
// provides a reasonable fallback.
const char kCurrentDirectoryString[] = "\\";
// Windows CE doesn't define INVALID_FILE_ATTRIBUTES
const DWORD kInvalidFileAttributes = 0xffffffff;
# else
const char kCurrentDirectoryString[] = ".\\";
# endif // GTEST_OS_WINDOWS_MOBILE
#else
const char kPathSeparator = '/';
const char kPathSeparatorString[] = "/";
const char kCurrentDirectoryString[] = "./";
#endif // GTEST_OS_WINDOWS
// Returns whether the given character is a valid path separator.
static bool IsPathSeparator(char c) {
#if GTEST_HAS_ALT_PATH_SEP_
return (c == kPathSeparator) || (c == kAlternatePathSeparator);
#else
return c == kPathSeparator;
#endif
}
// Returns the current working directory, or "" if unsuccessful.
FilePath FilePath::GetCurrentDir() {
#if GTEST_OS_WINDOWS_MOBILE
// Windows CE doesn't have a current directory, so we just return
// something reasonable.
return FilePath(kCurrentDirectoryString);
#elif GTEST_OS_WINDOWS
char cwd[GTEST_PATH_MAX_ + 1] = { '\0' };
return FilePath(_getcwd(cwd, sizeof(cwd)) == NULL ? "" : cwd);
#else
char cwd[GTEST_PATH_MAX_ + 1] = { '\0' };
return FilePath(getcwd(cwd, sizeof(cwd)) == NULL ? "" : cwd);
#endif // GTEST_OS_WINDOWS_MOBILE
}
// Returns a copy of the FilePath with the case-insensitive extension removed.
// Example: FilePath("dir/file.exe").RemoveExtension("EXE") returns
// FilePath("dir/file"). If a case-insensitive extension is not
// found, returns a copy of the original FilePath.
FilePath FilePath::RemoveExtension(const char* extension) const {
String dot_extension(String::Format(".%s", extension));
if (pathname_.EndsWithCaseInsensitive(dot_extension.c_str())) {
return FilePath(String(pathname_.c_str(), pathname_.length() - 4));
}
return *this;
}
// Returns a pointer to the last occurence of a valid path separator in
// the FilePath. On Windows, for example, both '/' and '\' are valid path
// separators. Returns NULL if no path separator was found.
const char* FilePath::FindLastPathSeparator() const {
const char* const last_sep = strrchr(c_str(), kPathSeparator);
#if GTEST_HAS_ALT_PATH_SEP_
const char* const last_alt_sep = strrchr(c_str(), kAlternatePathSeparator);
// Comparing two pointers of which only one is NULL is undefined.
if (last_alt_sep != NULL &&
(last_sep == NULL || last_alt_sep > last_sep)) {
return last_alt_sep;
}
#endif
return last_sep;
}
// Returns a copy of the FilePath with the directory part removed.
// Example: FilePath("path/to/file").RemoveDirectoryName() returns
// FilePath("file"). If there is no directory part ("just_a_file"), it returns
// the FilePath unmodified. If there is no file part ("just_a_dir/") it
// returns an empty FilePath ("").
// On Windows platform, '\' is the path separator, otherwise it is '/'.
FilePath FilePath::RemoveDirectoryName() const {
const char* const last_sep = FindLastPathSeparator();
return last_sep ? FilePath(String(last_sep + 1)) : *this;
}
// RemoveFileName returns the directory path with the filename removed.
// Example: FilePath("path/to/file").RemoveFileName() returns "path/to/".
// If the FilePath is "a_file" or "/a_file", RemoveFileName returns
// FilePath("./") or, on Windows, FilePath(".\\"). If the filepath does
// not have a file, like "just/a/dir/", it returns the FilePath unmodified.
// On Windows platform, '\' is the path separator, otherwise it is '/'.
FilePath FilePath::RemoveFileName() const {
const char* const last_sep = FindLastPathSeparator();
String dir;
if (last_sep) {
dir = String(c_str(), last_sep + 1 - c_str());
} else {
dir = kCurrentDirectoryString;
}
return FilePath(dir);
}
// Helper functions for naming files in a directory for xml output.
// Given directory = "dir", base_name = "test", number = 0,
// extension = "xml", returns "dir/test.xml". If number is greater
// than zero (e.g., 12), returns "dir/test_12.xml".
// On Windows platform, uses \ as the separator rather than /.
FilePath FilePath::MakeFileName(const FilePath& directory,
const FilePath& base_name,
int number,
const char* extension) {
String file;
if (number == 0) {
file = String::Format("%s.%s", base_name.c_str(), extension);
} else {
file = String::Format("%s_%d.%s", base_name.c_str(), number, extension);
}
return ConcatPaths(directory, FilePath(file));
}
// Given directory = "dir", relative_path = "test.xml", returns "dir/test.xml".
// On Windows, uses \ as the separator rather than /.
FilePath FilePath::ConcatPaths(const FilePath& directory,
const FilePath& relative_path) {
if (directory.IsEmpty())
return relative_path;
const FilePath dir(directory.RemoveTrailingPathSeparator());
return FilePath(String::Format("%s%c%s", dir.c_str(), kPathSeparator,
relative_path.c_str()));
}
// Returns true if pathname describes something findable in the file-system,
// either a file, directory, or whatever.
bool FilePath::FileOrDirectoryExists() const {
#if GTEST_OS_WINDOWS_MOBILE
LPCWSTR unicode = String::AnsiToUtf16(pathname_.c_str());
const DWORD attributes = GetFileAttributes(unicode);
delete [] unicode;
return attributes != kInvalidFileAttributes;
#else
posix::StatStruct file_stat;
return posix::Stat(pathname_.c_str(), &file_stat) == 0;
#endif // GTEST_OS_WINDOWS_MOBILE
}
// Returns true if pathname describes a directory in the file-system
// that exists.
bool FilePath::DirectoryExists() const {
bool result = false;
#if GTEST_OS_WINDOWS
// Don't strip off trailing separator if path is a root directory on
// Windows (like "C:\\").
const FilePath& path(IsRootDirectory() ? *this :
RemoveTrailingPathSeparator());
#else
const FilePath& path(*this);
#endif
#if GTEST_OS_WINDOWS_MOBILE
LPCWSTR unicode = String::AnsiToUtf16(path.c_str());
const DWORD attributes = GetFileAttributes(unicode);
delete [] unicode;
if ((attributes != kInvalidFileAttributes) &&
(attributes & FILE_ATTRIBUTE_DIRECTORY)) {
result = true;
}
#else
posix::StatStruct file_stat;
result = posix::Stat(path.c_str(), &file_stat) == 0 &&
posix::IsDir(file_stat);
#endif // GTEST_OS_WINDOWS_MOBILE
return result;
}
// Returns true if pathname describes a root directory. (Windows has one
// root directory per disk drive.)
bool FilePath::IsRootDirectory() const {
#if GTEST_OS_WINDOWS
// TODO(wan@google.com): on Windows a network share like
// \\server\share can be a root directory, although it cannot be the
// current directory. Handle this properly.
return pathname_.length() == 3 && IsAbsolutePath();
#else
return pathname_.length() == 1 && IsPathSeparator(pathname_.c_str()[0]);
#endif
}
// Returns true if pathname describes an absolute path.
bool FilePath::IsAbsolutePath() const {
const char* const name = pathname_.c_str();
#if GTEST_OS_WINDOWS
return pathname_.length() >= 3 &&
((name[0] >= 'a' && name[0] <= 'z') ||
(name[0] >= 'A' && name[0] <= 'Z')) &&
name[1] == ':' &&
IsPathSeparator(name[2]);
#else
return IsPathSeparator(name[0]);
#endif
}
// Returns a pathname for a file that does not currently exist. The pathname
// will be directory/base_name.extension or
// directory/base_name_<number>.extension if directory/base_name.extension
// already exists. The number will be incremented until a pathname is found
// that does not already exist.
// Examples: 'dir/foo_test.xml' or 'dir/foo_test_1.xml'.
// There could be a race condition if two or more processes are calling this
// function at the same time -- they could both pick the same filename.
FilePath FilePath::GenerateUniqueFileName(const FilePath& directory,
const FilePath& base_name,
const char* extension) {
FilePath full_pathname;
int number = 0;
do {
full_pathname.Set(MakeFileName(directory, base_name, number++, extension));
} while (full_pathname.FileOrDirectoryExists());
return full_pathname;
}
// Returns true if FilePath ends with a path separator, which indicates that
// it is intended to represent a directory. Returns false otherwise.
// This does NOT check that a directory (or file) actually exists.
bool FilePath::IsDirectory() const {
return !pathname_.empty() &&
IsPathSeparator(pathname_.c_str()[pathname_.length() - 1]);
}
// Create directories so that path exists. Returns true if successful or if
// the directories already exist; returns false if unable to create directories
// for any reason.
bool FilePath::CreateDirectoriesRecursively() const {
if (!this->IsDirectory()) {
return false;
}
if (pathname_.length() == 0 || this->DirectoryExists()) {
return true;
}
const FilePath parent(this->RemoveTrailingPathSeparator().RemoveFileName());
return parent.CreateDirectoriesRecursively() && this->CreateFolder();
}
// Create the directory so that path exists. Returns true if successful or
// if the directory already exists; returns false if unable to create the
// directory for any reason, including if the parent directory does not
// exist. Not named "CreateDirectory" because that's a macro on Windows.
bool FilePath::CreateFolder() const {
#if GTEST_OS_WINDOWS_MOBILE
FilePath removed_sep(this->RemoveTrailingPathSeparator());
LPCWSTR unicode = String::AnsiToUtf16(removed_sep.c_str());
int result = CreateDirectory(unicode, NULL) ? 0 : -1;
delete [] unicode;
#elif GTEST_OS_WINDOWS
int result = _mkdir(pathname_.c_str());
#else
int result = mkdir(pathname_.c_str(), 0777);
#endif // GTEST_OS_WINDOWS_MOBILE
if (result == -1) {
return this->DirectoryExists(); // An error is OK if the directory exists.
}
return true; // No error.
}
// If input name has a trailing separator character, remove it and return the
// name, otherwise return the name string unmodified.
// On Windows platform, uses \ as the separator, other platforms use /.
FilePath FilePath::RemoveTrailingPathSeparator() const {
return IsDirectory()
? FilePath(String(pathname_.c_str(), pathname_.length() - 1))
: *this;
}
// Removes any redundant separators that might be in the pathname.
// For example, "bar///foo" becomes "bar/foo". Does not eliminate other
// redundancies that might be in a pathname involving "." or "..".
// TODO(wan@google.com): handle Windows network shares (e.g. \\server\share).
void FilePath::Normalize() {
if (pathname_.c_str() == NULL) {
pathname_ = "";
return;
}
const char* src = pathname_.c_str();
char* const dest = new char[pathname_.length() + 1];
char* dest_ptr = dest;
memset(dest_ptr, 0, pathname_.length() + 1);
while (*src != '\0') {
*dest_ptr = *src;
if (!IsPathSeparator(*src)) {
src++;
} else {
#if GTEST_HAS_ALT_PATH_SEP_
if (*dest_ptr == kAlternatePathSeparator) {
*dest_ptr = kPathSeparator;
}
#endif
while (IsPathSeparator(*src))
src++;
}
dest_ptr++;
}
*dest_ptr = '\0';
pathname_ = dest;
delete[] dest;
}
} // namespace internal
} // namespace testing
// Copyright 2008, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Author: wan@google.com (Zhanyong Wan)
#include <limits.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#if GTEST_OS_WINDOWS_MOBILE
# include <windows.h> // For TerminateProcess()
#elif GTEST_OS_WINDOWS
# include <io.h>
# include <sys/stat.h>
#else
# include <unistd.h>
#endif // GTEST_OS_WINDOWS_MOBILE
#if GTEST_OS_MAC
# include <mach/mach_init.h>
# include <mach/task.h>
# include <mach/vm_map.h>
#endif // GTEST_OS_MAC
// Indicates that this translation unit is part of Google Test's
// implementation. It must come before gtest-internal-inl.h is
// included, or there will be a compiler error. This trick is to
// prevent a user from accidentally including gtest-internal-inl.h in
// his code.
#define GTEST_IMPLEMENTATION_ 1
#undef GTEST_IMPLEMENTATION_
namespace testing {
namespace internal {
#if defined(_MSC_VER) || defined(__BORLANDC__)
// MSVC and C++Builder do not provide a definition of STDERR_FILENO.
const int kStdOutFileno = 1;
const int kStdErrFileno = 2;
#else
const int kStdOutFileno = STDOUT_FILENO;
const int kStdErrFileno = STDERR_FILENO;
#endif // _MSC_VER
#if GTEST_OS_MAC
// Returns the number of threads running in the process, or 0 to indicate that
// we cannot detect it.
size_t GetThreadCount() {
const task_t task = mach_task_self();
mach_msg_type_number_t thread_count;
thread_act_array_t thread_list;
const kern_return_t status = task_threads(task, &thread_list, &thread_count);
if (status == KERN_SUCCESS) {
// task_threads allocates resources in thread_list and we need to free them
// to avoid leaks.
vm_deallocate(task,
reinterpret_cast<vm_address_t>(thread_list),
sizeof(thread_t) * thread_count);
return static_cast<size_t>(thread_count);
} else {
return 0;
}
}
#else
size_t GetThreadCount() {
// There's no portable way to detect the number of threads, so we just
// return 0 to indicate that we cannot detect it.
return 0;
}
#endif // GTEST_OS_MAC
#if GTEST_USES_POSIX_RE
// Implements RE. Currently only needed for death tests.
RE::~RE() {
if (is_valid_) {
// regfree'ing an invalid regex might crash because the content
// of the regex is undefined. Since the regex's are essentially
// the same, one cannot be valid (or invalid) without the other
// being so too.
regfree(&partial_regex_);
regfree(&full_regex_);
}
free(const_cast<char*>(pattern_));
}
// Returns true iff regular expression re matches the entire str.
bool RE::FullMatch(const char* str, const RE& re) {
if (!re.is_valid_) return false;
regmatch_t match;
return regexec(&re.full_regex_, str, 1, &match, 0) == 0;
}
// Returns true iff regular expression re matches a substring of str
// (including str itself).
bool RE::PartialMatch(const char* str, const RE& re) {
if (!re.is_valid_) return false;
regmatch_t match;
return regexec(&re.partial_regex_, str, 1, &match, 0) == 0;
}
// Initializes an RE from its string representation.
void RE::Init(const char* regex) {
pattern_ = posix::StrDup(regex);
// Reserves enough bytes to hold the regular expression used for a
// full match.
const size_t full_regex_len = strlen(regex) + 10;
char* const full_pattern = new char[full_regex_len];
snprintf(full_pattern, full_regex_len, "^(%s)$", regex);
is_valid_ = regcomp(&full_regex_, full_pattern, REG_EXTENDED) == 0;
// We want to call regcomp(&partial_regex_, ...) even if the
// previous expression returns false. Otherwise partial_regex_ may
// not be properly initialized can may cause trouble when it's
// freed.
//
// Some implementation of POSIX regex (e.g. on at least some
// versions of Cygwin) doesn't accept the empty string as a valid
// regex. We change it to an equivalent form "()" to be safe.
if (is_valid_) {
const char* const partial_regex = (*regex == '\0') ? "()" : regex;
is_valid_ = regcomp(&partial_regex_, partial_regex, REG_EXTENDED) == 0;
}
EXPECT_TRUE(is_valid_)
<< "Regular expression \"" << regex
<< "\" is not a valid POSIX Extended regular expression.";
delete[] full_pattern;
}
#elif GTEST_USES_SIMPLE_RE
// Returns true iff ch appears anywhere in str (excluding the
// terminating '\0' character).
bool IsInSet(char ch, const char* str) {
return ch != '\0' && strchr(str, ch) != NULL;
}
// Returns true iff ch belongs to the given classification. Unlike
// similar functions in <ctype.h>, these aren't affected by the
// current locale.
bool IsAsciiDigit(char ch) { return '0' <= ch && ch <= '9'; }
bool IsAsciiPunct(char ch) {
return IsInSet(ch, "^-!\"#$%&'()*+,./:;<=>?@[\\]_`{|}~");
}
bool IsRepeat(char ch) { return IsInSet(ch, "?*+"); }
bool IsAsciiWhiteSpace(char ch) { return IsInSet(ch, " \f\n\r\t\v"); }
bool IsAsciiWordChar(char ch) {
return ('a' <= ch && ch <= 'z') || ('A' <= ch && ch <= 'Z') ||
('0' <= ch && ch <= '9') || ch == '_';
}
// Returns true iff "\\c" is a supported escape sequence.
bool IsValidEscape(char c) {
return (IsAsciiPunct(c) || IsInSet(c, "dDfnrsStvwW"));
}
// Returns true iff the given atom (specified by escaped and pattern)
// matches ch. The result is undefined if the atom is invalid.
bool AtomMatchesChar(bool escaped, char pattern_char, char ch) {
if (escaped) { // "\\p" where p is pattern_char.
switch (pattern_char) {
case 'd': return IsAsciiDigit(ch);
case 'D': return !IsAsciiDigit(ch);
case 'f': return ch == '\f';
case 'n': return ch == '\n';
case 'r': return ch == '\r';
case 's': return IsAsciiWhiteSpace(ch);
case 'S': return !IsAsciiWhiteSpace(ch);
case 't': return ch == '\t';
case 'v': return ch == '\v';
case 'w': return IsAsciiWordChar(ch);
case 'W': return !IsAsciiWordChar(ch);
}
return IsAsciiPunct(pattern_char) && pattern_char == ch;
}
return (pattern_char == '.' && ch != '\n') || pattern_char == ch;
}
// Helper function used by ValidateRegex() to format error messages.
String FormatRegexSyntaxError(const char* regex, int index) {
return (Message() << "Syntax error at index " << index
<< " in simple regular expression \"" << regex << "\": ").GetString();
}
// Generates non-fatal failures and returns false if regex is invalid;
// otherwise returns true.
bool ValidateRegex(const char* regex) {
if (regex == NULL) {
// TODO(wan@google.com): fix the source file location in the
// assertion failures to match where the regex is used in user
// code.
ADD_FAILURE() << "NULL is not a valid simple regular expression.";
return false;
}
bool is_valid = true;
// True iff ?, *, or + can follow the previous atom.
bool prev_repeatable = false;
for (int i = 0; regex[i]; i++) {
if (regex[i] == '\\') { // An escape sequence
i++;
if (regex[i] == '\0') {
ADD_FAILURE() << FormatRegexSyntaxError(regex, i - 1)
<< "'\\' cannot appear at the end.";
return false;
}
if (!IsValidEscape(regex[i])) {
ADD_FAILURE() << FormatRegexSyntaxError(regex, i - 1)
<< "invalid escape sequence \"\\" << regex[i] << "\".";
is_valid = false;
}
prev_repeatable = true;
} else { // Not an escape sequence.
const char ch = regex[i];
if (ch == '^' && i > 0) {
ADD_FAILURE() << FormatRegexSyntaxError(regex, i)
<< "'^' can only appear at the beginning.";
is_valid = false;
} else if (ch == '$' && regex[i + 1] != '\0') {
ADD_FAILURE() << FormatRegexSyntaxError(regex, i)
<< "'$' can only appear at the end.";
is_valid = false;
} else if (IsInSet(ch, "()[]{}|")) {
ADD_FAILURE() << FormatRegexSyntaxError(regex, i)
<< "'" << ch << "' is unsupported.";
is_valid = false;
} else if (IsRepeat(ch) && !prev_repeatable) {
ADD_FAILURE() << FormatRegexSyntaxError(regex, i)
<< "'" << ch << "' can only follow a repeatable token.";
is_valid = false;
}
prev_repeatable = !IsInSet(ch, "^$?*+");
}
}
return is_valid;
}
// Matches a repeated regex atom followed by a valid simple regular
// expression. The regex atom is defined as c if escaped is false,
// or \c otherwise. repeat is the repetition meta character (?, *,
// or +). The behavior is undefined if str contains too many
// characters to be indexable by size_t, in which case the test will
// probably time out anyway. We are fine with this limitation as
// std::string has it too.
bool MatchRepetitionAndRegexAtHead(
bool escaped, char c, char repeat, const char* regex,
const char* str) {
const size_t min_count = (repeat == '+') ? 1 : 0;
const size_t max_count = (repeat == '?') ? 1 :
static_cast<size_t>(-1) - 1;
// We cannot call numeric_limits::max() as it conflicts with the
// max() macro on Windows.
for (size_t i = 0; i <= max_count; ++i) {
// We know that the atom matches each of the first i characters in str.
if (i >= min_count && MatchRegexAtHead(regex, str + i)) {
// We have enough matches at the head, and the tail matches too.
// Since we only care about *whether* the pattern matches str
// (as opposed to *how* it matches), there is no need to find a
// greedy match.
return true;
}
if (str[i] == '\0' || !AtomMatchesChar(escaped, c, str[i]))
return false;
}
return false;
}
// Returns true iff regex matches a prefix of str. regex must be a
// valid simple regular expression and not start with "^", or the
// result is undefined.
bool MatchRegexAtHead(const char* regex, const char* str) {
if (*regex == '\0') // An empty regex matches a prefix of anything.
return true;
// "$" only matches the end of a string. Note that regex being
// valid guarantees that there's nothing after "$" in it.
if (*regex == '$')
return *str == '\0';
// Is the first thing in regex an escape sequence?
const bool escaped = *regex == '\\';
if (escaped)
++regex;
if (IsRepeat(regex[1])) {
// MatchRepetitionAndRegexAtHead() calls MatchRegexAtHead(), so
// here's an indirect recursion. It terminates as the regex gets
// shorter in each recursion.
return MatchRepetitionAndRegexAtHead(
escaped, regex[0], regex[1], regex + 2, str);
} else {
// regex isn't empty, isn't "$", and doesn't start with a
// repetition. We match the first atom of regex with the first
// character of str and recurse.
return (*str != '\0') && AtomMatchesChar(escaped, *regex, *str) &&
MatchRegexAtHead(regex + 1, str + 1);
}
}
// Returns true iff regex matches any substring of str. regex must be
// a valid simple regular expression, or the result is undefined.
//
// The algorithm is recursive, but the recursion depth doesn't exceed
// the regex length, so we won't need to worry about running out of
// stack space normally. In rare cases the time complexity can be
// exponential with respect to the regex length + the string length,
// but usually it's must faster (often close to linear).
bool MatchRegexAnywhere(const char* regex, const char* str) {
if (regex == NULL || str == NULL)
return false;
if (*regex == '^')
return MatchRegexAtHead(regex + 1, str);
// A successful match can be anywhere in str.
do {
if (MatchRegexAtHead(regex, str))
return true;
} while (*str++ != '\0');
return false;
}
// Implements the RE class.
RE::~RE() {
free(const_cast<char*>(pattern_));
free(const_cast<char*>(full_pattern_));
}
// Returns true iff regular expression re matches the entire str.
bool RE::FullMatch(const char* str, const RE& re) {
return re.is_valid_ && MatchRegexAnywhere(re.full_pattern_, str);
}
// Returns true iff regular expression re matches a substring of str
// (including str itself).
bool RE::PartialMatch(const char* str, const RE& re) {
return re.is_valid_ && MatchRegexAnywhere(re.pattern_, str);
}
// Initializes an RE from its string representation.
void RE::Init(const char* regex) {
pattern_ = full_pattern_ = NULL;
if (regex != NULL) {
pattern_ = posix::StrDup(regex);
}
is_valid_ = ValidateRegex(regex);
if (!is_valid_) {
// No need to calculate the full pattern when the regex is invalid.
return;
}
const size_t len = strlen(regex);
// Reserves enough bytes to hold the regular expression used for a
// full match: we need space to prepend a '^', append a '$', and
// terminate the string with '\0'.
char* buffer = static_cast<char*>(malloc(len + 3));
full_pattern_ = buffer;
if (*regex != '^')
*buffer++ = '^'; // Makes sure full_pattern_ starts with '^'.
// We don't use snprintf or strncpy, as they trigger a warning when
// compiled with VC++ 8.0.
memcpy(buffer, regex, len);
buffer += len;
if (len == 0 || regex[len - 1] != '$')
*buffer++ = '$'; // Makes sure full_pattern_ ends with '$'.
*buffer = '\0';
}
#endif // GTEST_USES_POSIX_RE
const char kUnknownFile[] = "unknown file";
// Formats a source file path and a line number as they would appear
// in an error message from the compiler used to compile this code.
GTEST_API_ ::std::string FormatFileLocation(const char* file, int line) {
const char* const file_name = file == NULL ? kUnknownFile : file;
if (line < 0) {
return String::Format("%s:", file_name).c_str();
}
#ifdef _MSC_VER
return String::Format("%s(%d):", file_name, line).c_str();
#else
return String::Format("%s:%d:", file_name, line).c_str();
#endif // _MSC_VER
}
// Formats a file location for compiler-independent XML output.
// Although this function is not platform dependent, we put it next to
// FormatFileLocation in order to contrast the two functions.
// Note that FormatCompilerIndependentFileLocation() does NOT append colon
// to the file location it produces, unlike FormatFileLocation().
GTEST_API_ ::std::string FormatCompilerIndependentFileLocation(
const char* file, int line) {
const char* const file_name = file == NULL ? kUnknownFile : file;
if (line < 0)
return file_name;
else
return String::Format("%s:%d", file_name, line).c_str();
}
GTestLog::GTestLog(GTestLogSeverity severity, const char* file, int line)
: severity_(severity) {
const char* const marker =
severity == GTEST_INFO ? "[ INFO ]" :
severity == GTEST_WARNING ? "[WARNING]" :
severity == GTEST_ERROR ? "[ ERROR ]" : "[ FATAL ]";
GetStream() << ::std::endl << marker << " "
<< FormatFileLocation(file, line).c_str() << ": ";
}
// Flushes the buffers and, if severity is GTEST_FATAL, aborts the program.
GTestLog::~GTestLog() {
GetStream() << ::std::endl;
if (severity_ == GTEST_FATAL) {
fflush(stderr);
posix::Abort();
}
}
// Disable Microsoft deprecation warnings for POSIX functions called from
// this class (creat, dup, dup2, and close)
#ifdef _MSC_VER
# pragma warning(push)
# pragma warning(disable: 4996)
#endif // _MSC_VER
#if GTEST_HAS_STREAM_REDIRECTION
// Object that captures an output stream (stdout/stderr).
class CapturedStream {
public:
// The ctor redirects the stream to a temporary file.
CapturedStream(int fd) : fd_(fd), uncaptured_fd_(dup(fd)) {
# if GTEST_OS_WINDOWS
char temp_dir_path[MAX_PATH + 1] = { '\0' }; // NOLINT
char temp_file_path[MAX_PATH + 1] = { '\0' }; // NOLINT
::GetTempPathA(sizeof(temp_dir_path), temp_dir_path);
const UINT success = ::GetTempFileNameA(temp_dir_path,
"gtest_redir",
0, // Generate unique file name.
temp_file_path);
GTEST_CHECK_(success != 0)
<< "Unable to create a temporary file in " << temp_dir_path;
const int captured_fd = creat(temp_file_path, _S_IREAD | _S_IWRITE);
GTEST_CHECK_(captured_fd != -1) << "Unable to open temporary file "
<< temp_file_path;
filename_ = temp_file_path;
# else
// There's no guarantee that a test has write access to the
// current directory, so we create the temporary file in the /tmp
// directory instead.
char name_template[] = "/tmp/captured_stream.XXXXXX";
const int captured_fd = mkstemp(name_template);
filename_ = name_template;
# endif // GTEST_OS_WINDOWS
fflush(NULL);
dup2(captured_fd, fd_);
close(captured_fd);
}
~CapturedStream() {
remove(filename_.c_str());
}
String GetCapturedString() {
if (uncaptured_fd_ != -1) {
// Restores the original stream.
fflush(NULL);
dup2(uncaptured_fd_, fd_);
close(uncaptured_fd_);
uncaptured_fd_ = -1;
}
FILE* const file = posix::FOpen(filename_.c_str(), "r");
const String content = ReadEntireFile(file);
posix::FClose(file);
return content;
}
private:
// Reads the entire content of a file as a String.
static String ReadEntireFile(FILE* file);
// Returns the size (in bytes) of a file.
static size_t GetFileSize(FILE* file);
const int fd_; // A stream to capture.
int uncaptured_fd_;
// Name of the temporary file holding the stderr output.
::std::string filename_;
GTEST_DISALLOW_COPY_AND_ASSIGN_(CapturedStream);
};
// Returns the size (in bytes) of a file.
size_t CapturedStream::GetFileSize(FILE* file) {
fseek(file, 0, SEEK_END);
return static_cast<size_t>(ftell(file));
}
// Reads the entire content of a file as a string.
String CapturedStream::ReadEntireFile(FILE* file) {
const size_t file_size = GetFileSize(file);
char* const buffer = new char[file_size];
size_t bytes_last_read = 0; // # of bytes read in the last fread()
size_t bytes_read = 0; // # of bytes read so far
fseek(file, 0, SEEK_SET);
// Keeps reading the file until we cannot read further or the
// pre-determined file size is reached.
do {
bytes_last_read = fread(buffer+bytes_read, 1, file_size-bytes_read, file);
bytes_read += bytes_last_read;
} while (bytes_last_read > 0 && bytes_read < file_size);
const String content(buffer, bytes_read);
delete[] buffer;
return content;
}
# ifdef _MSC_VER
# pragma warning(pop)
# endif // _MSC_VER
static CapturedStream* g_captured_stderr = NULL;
static CapturedStream* g_captured_stdout = NULL;
// Starts capturing an output stream (stdout/stderr).
void CaptureStream(int fd, const char* stream_name, CapturedStream** stream) {
if (*stream != NULL) {
GTEST_LOG_(FATAL) << "Only one " << stream_name
<< " capturer can exist at a time.";
}
*stream = new CapturedStream(fd);
}
// Stops capturing the output stream and returns the captured string.
String GetCapturedStream(CapturedStream** captured_stream) {
const String content = (*captured_stream)->GetCapturedString();
delete *captured_stream;
*captured_stream = NULL;
return content;
}
// Starts capturing stdout.
void CaptureStdout() {
CaptureStream(kStdOutFileno, "stdout", &g_captured_stdout);
}
// Starts capturing stderr.
void CaptureStderr() {
CaptureStream(kStdErrFileno, "stderr", &g_captured_stderr);
}
// Stops capturing stdout and returns the captured string.
String GetCapturedStdout() { return GetCapturedStream(&g_captured_stdout); }
// Stops capturing stderr and returns the captured string.
String GetCapturedStderr() { return GetCapturedStream(&g_captured_stderr); }
#endif // GTEST_HAS_STREAM_REDIRECTION
#if GTEST_HAS_DEATH_TEST
// A copy of all command line arguments. Set by InitGoogleTest().
::std::vector<String> g_argvs;
// Returns the command line as a vector of strings.
const ::std::vector<String>& GetArgvs() { return g_argvs; }
#endif // GTEST_HAS_DEATH_TEST
#if GTEST_OS_WINDOWS_MOBILE
namespace posix {
void Abort() {
DebugBreak();
TerminateProcess(GetCurrentProcess(), 1);
}
} // namespace posix
#endif // GTEST_OS_WINDOWS_MOBILE
// Returns the name of the environment variable corresponding to the
// given flag. For example, FlagToEnvVar("foo") will return
// "GTEST_FOO" in the open-source version.
static String FlagToEnvVar(const char* flag) {
const String full_flag =
(Message() << GTEST_FLAG_PREFIX_ << flag).GetString();
Message env_var;
for (size_t i = 0; i != full_flag.length(); i++) {
env_var << ToUpper(full_flag.c_str()[i]);
}
return env_var.GetString();
}
// Parses 'str' for a 32-bit signed integer. If successful, writes
// the result to *value and returns true; otherwise leaves *value
// unchanged and returns false.
bool ParseInt32(const Message& src_text, const char* str, Int32* value) {
// Parses the environment variable as a decimal integer.
char* end = NULL;
const long long_value = strtol(str, &end, 10); // NOLINT
// Has strtol() consumed all characters in the string?
if (*end != '\0') {
// No - an invalid character was encountered.
Message msg;
msg << "WARNING: " << src_text
<< " is expected to be a 32-bit integer, but actually"
<< " has value \"" << str << "\".\n";
printf("%s", msg.GetString().c_str());
fflush(stdout);
return false;
}
// Is the parsed value in the range of an Int32?
const Int32 result = static_cast<Int32>(long_value);
if (long_value == LONG_MAX || long_value == LONG_MIN ||
// The parsed value overflows as a long. (strtol() returns
// LONG_MAX or LONG_MIN when the input overflows.)
result != long_value
// The parsed value overflows as an Int32.
) {
Message msg;
msg << "WARNING: " << src_text
<< " is expected to be a 32-bit integer, but actually"
<< " has value " << str << ", which overflows.\n";
printf("%s", msg.GetString().c_str());
fflush(stdout);
return false;
}
*value = result;
return true;
}
// Reads and returns the Boolean environment variable corresponding to
// the given flag; if it's not set, returns default_value.
//
// The value is considered true iff it's not "0".
bool BoolFromGTestEnv(const char* flag, bool default_value) {
const String env_var = FlagToEnvVar(flag);
const char* const string_value = posix::GetEnv(env_var.c_str());
return string_value == NULL ?
default_value : strcmp(string_value, "0") != 0;
}
// Reads and returns a 32-bit integer stored in the environment
// variable corresponding to the given flag; if it isn't set or
// doesn't represent a valid 32-bit integer, returns default_value.
Int32 Int32FromGTestEnv(const char* flag, Int32 default_value) {
const String env_var = FlagToEnvVar(flag);
const char* const string_value = posix::GetEnv(env_var.c_str());
if (string_value == NULL) {
// The environment variable is not set.
return default_value;
}
Int32 result = default_value;
if (!ParseInt32(Message() << "Environment variable " << env_var,
string_value, &result)) {
printf("The default value %s is used.\n",
(Message() << default_value).GetString().c_str());
fflush(stdout);
return default_value;
}
return result;
}
// Reads and returns the string environment variable corresponding to
// the given flag; if it's not set, returns default_value.
const char* StringFromGTestEnv(const char* flag, const char* default_value) {
const String env_var = FlagToEnvVar(flag);
const char* const value = posix::GetEnv(env_var.c_str());
return value == NULL ? default_value : value;
}
} // namespace internal
} // namespace testing
// Copyright 2007, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Author: wan@google.com (Zhanyong Wan)
// Google Test - The Google C++ Testing Framework
//
// This file implements a universal value printer that can print a
// value of any type T:
//
// void ::testing::internal::UniversalPrinter<T>::Print(value, ostream_ptr);
//
// It uses the << operator when possible, and prints the bytes in the
// object otherwise. A user can override its behavior for a class
// type Foo by defining either operator<<(::std::ostream&, const Foo&)
// or void PrintTo(const Foo&, ::std::ostream*) in the namespace that
// defines Foo.
#include <ctype.h>
#include <stdio.h>
#include <ostream> // NOLINT
#include <string>
namespace testing {
namespace {
using ::std::ostream;
#if GTEST_OS_WINDOWS_MOBILE // Windows CE does not define _snprintf_s.
# define snprintf _snprintf
#elif _MSC_VER >= 1400 // VC 8.0 and later deprecate snprintf and _snprintf.
# define snprintf _snprintf_s
#elif _MSC_VER
# define snprintf _snprintf
#endif // GTEST_OS_WINDOWS_MOBILE
// Prints a segment of bytes in the given object.
void PrintByteSegmentInObjectTo(const unsigned char* obj_bytes, size_t start,
size_t count, ostream* os) {
char text[5] = "";
for (size_t i = 0; i != count; i++) {
const size_t j = start + i;
if (i != 0) {
// Organizes the bytes into groups of 2 for easy parsing by
// human.
if ((j % 2) == 0)
*os << ' ';
else
*os << '-';
}
snprintf(text, sizeof(text), "%02X", obj_bytes[j]);
*os << text;
}
}
// Prints the bytes in the given value to the given ostream.
void PrintBytesInObjectToImpl(const unsigned char* obj_bytes, size_t count,
ostream* os) {
// Tells the user how big the object is.
*os << count << "-byte object <";
const size_t kThreshold = 132;
const size_t kChunkSize = 64;
// If the object size is bigger than kThreshold, we'll have to omit
// some details by printing only the first and the last kChunkSize
// bytes.
// TODO(wan): let the user control the threshold using a flag.
if (count < kThreshold) {
PrintByteSegmentInObjectTo(obj_bytes, 0, count, os);
} else {
PrintByteSegmentInObjectTo(obj_bytes, 0, kChunkSize, os);
*os << " ... ";
// Rounds up to 2-byte boundary.
const size_t resume_pos = (count - kChunkSize + 1)/2*2;
PrintByteSegmentInObjectTo(obj_bytes, resume_pos, count - resume_pos, os);
}
*os << ">";
}
} // namespace
namespace internal2 {
// Delegates to PrintBytesInObjectToImpl() to print the bytes in the
// given object. The delegation simplifies the implementation, which
// uses the << operator and thus is easier done outside of the
// ::testing::internal namespace, which contains a << operator that
// sometimes conflicts with the one in STL.
void PrintBytesInObjectTo(const unsigned char* obj_bytes, size_t count,
ostream* os) {
PrintBytesInObjectToImpl(obj_bytes, count, os);
}
} // namespace internal2
namespace internal {
// Depending on the value of a char (or wchar_t), we print it in one
// of three formats:
// - as is if it's a printable ASCII (e.g. 'a', '2', ' '),
// - as a hexidecimal escape sequence (e.g. '\x7F'), or
// - as a special escape sequence (e.g. '\r', '\n').
enum CharFormat {
kAsIs,
kHexEscape,
kSpecialEscape
};
// Returns true if c is a printable ASCII character. We test the
// value of c directly instead of calling isprint(), which is buggy on
// Windows Mobile.
inline bool IsPrintableAscii(wchar_t c) {
return 0x20 <= c && c <= 0x7E;
}
// Prints a wide or narrow char c as a character literal without the
// quotes, escaping it when necessary; returns how c was formatted.
// The template argument UnsignedChar is the unsigned version of Char,
// which is the type of c.
template <typename UnsignedChar, typename Char>
static CharFormat PrintAsCharLiteralTo(Char c, ostream* os) {
switch (static_cast<wchar_t>(c)) {
case L'\0':
*os << "\\0";
break;
case L'\'':
*os << "\\'";
break;
case L'\\':
*os << "\\\\";
break;
case L'\a':
*os << "\\a";
break;
case L'\b':
*os << "\\b";
break;
case L'\f':
*os << "\\f";
break;
case L'\n':
*os << "\\n";
break;
case L'\r':
*os << "\\r";
break;
case L'\t':
*os << "\\t";
break;
case L'\v':
*os << "\\v";
break;
default:
if (IsPrintableAscii(c)) {
*os << static_cast<char>(c);
return kAsIs;
} else {
*os << String::Format("\\x%X", static_cast<UnsignedChar>(c));
return kHexEscape;
}
}
return kSpecialEscape;
}
// Prints a char c as if it's part of a string literal, escaping it when
// necessary; returns how c was formatted.
static CharFormat PrintAsWideStringLiteralTo(wchar_t c, ostream* os) {
switch (c) {
case L'\'':
*os << "'";
return kAsIs;
case L'"':
*os << "\\\"";
return kSpecialEscape;
default:
return PrintAsCharLiteralTo<wchar_t>(c, os);
}
}
// Prints a char c as if it's part of a string literal, escaping it when
// necessary; returns how c was formatted.
static CharFormat PrintAsNarrowStringLiteralTo(char c, ostream* os) {
return PrintAsWideStringLiteralTo(static_cast<unsigned char>(c), os);
}
// Prints a wide or narrow character c and its code. '\0' is printed
// as "'\\0'", other unprintable characters are also properly escaped
// using the standard C++ escape sequence. The template argument
// UnsignedChar is the unsigned version of Char, which is the type of c.
template <typename UnsignedChar, typename Char>
void PrintCharAndCodeTo(Char c, ostream* os) {
// First, print c as a literal in the most readable form we can find.
*os << ((sizeof(c) > 1) ? "L'" : "'");
const CharFormat format = PrintAsCharLiteralTo<UnsignedChar>(c, os);
*os << "'";
// To aid user debugging, we also print c's code in decimal, unless
// it's 0 (in which case c was printed as '\\0', making the code
// obvious).
if (c == 0)
return;
*os << " (" << String::Format("%d", c).c_str();
// For more convenience, we print c's code again in hexidecimal,
// unless c was already printed in the form '\x##' or the code is in
// [1, 9].
if (format == kHexEscape || (1 <= c && c <= 9)) {
// Do nothing.
} else {
*os << String::Format(", 0x%X",
static_cast<UnsignedChar>(c)).c_str();
}
*os << ")";
}
void PrintTo(unsigned char c, ::std::ostream* os) {
PrintCharAndCodeTo<unsigned char>(c, os);
}
void PrintTo(signed char c, ::std::ostream* os) {
PrintCharAndCodeTo<unsigned char>(c, os);
}
// Prints a wchar_t as a symbol if it is printable or as its internal
// code otherwise and also as its code. L'\0' is printed as "L'\\0'".
void PrintTo(wchar_t wc, ostream* os) {
PrintCharAndCodeTo<wchar_t>(wc, os);
}
// Prints the given array of characters to the ostream.
// The array starts at *begin, the length is len, it may include '\0' characters
// and may not be null-terminated.
static void PrintCharsAsStringTo(const char* begin, size_t len, ostream* os) {
*os << "\"";
bool is_previous_hex = false;
for (size_t index = 0; index < len; ++index) {
const char cur = begin[index];
if (is_previous_hex && IsXDigit(cur)) {
// Previous character is of '\x..' form and this character can be
// interpreted as another hexadecimal digit in its number. Break string to
// disambiguate.
*os << "\" \"";
}
is_previous_hex = PrintAsNarrowStringLiteralTo(cur, os) == kHexEscape;
}
*os << "\"";
}
// Prints a (const) char array of 'len' elements, starting at address 'begin'.
void UniversalPrintArray(const char* begin, size_t len, ostream* os) {
PrintCharsAsStringTo(begin, len, os);
}
// Prints the given array of wide characters to the ostream.
// The array starts at *begin, the length is len, it may include L'\0'
// characters and may not be null-terminated.
static void PrintWideCharsAsStringTo(const wchar_t* begin, size_t len,
ostream* os) {
*os << "L\"";
bool is_previous_hex = false;
for (size_t index = 0; index < len; ++index) {
const wchar_t cur = begin[index];
if (is_previous_hex && isascii(cur) && IsXDigit(static_cast<char>(cur))) {
// Previous character is of '\x..' form and this character can be
// interpreted as another hexadecimal digit in its number. Break string to
// disambiguate.
*os << "\" L\"";
}
is_previous_hex = PrintAsWideStringLiteralTo(cur, os) == kHexEscape;
}
*os << "\"";
}
// Prints the given C string to the ostream.
void PrintTo(const char* s, ostream* os) {
if (s == NULL) {
*os << "NULL";
} else {
*os << ImplicitCast_<const void*>(s) << " pointing to ";
PrintCharsAsStringTo(s, strlen(s), os);
}
}
// MSVC compiler can be configured to define whar_t as a typedef
// of unsigned short. Defining an overload for const wchar_t* in that case
// would cause pointers to unsigned shorts be printed as wide strings,
// possibly accessing more memory than intended and causing invalid
// memory accesses. MSVC defines _NATIVE_WCHAR_T_DEFINED symbol when
// wchar_t is implemented as a native type.
#if !defined(_MSC_VER) || defined(_NATIVE_WCHAR_T_DEFINED)
// Prints the given wide C string to the ostream.
void PrintTo(const wchar_t* s, ostream* os) {
if (s == NULL) {
*os << "NULL";
} else {
*os << ImplicitCast_<const void*>(s) << " pointing to ";
PrintWideCharsAsStringTo(s, wcslen(s), os);
}
}
#endif // wchar_t is native
// Prints a ::string object.
#if GTEST_HAS_GLOBAL_STRING
void PrintStringTo(const ::string& s, ostream* os) {
PrintCharsAsStringTo(s.data(), s.size(), os);
}
#endif // GTEST_HAS_GLOBAL_STRING
void PrintStringTo(const ::std::string& s, ostream* os) {
PrintCharsAsStringTo(s.data(), s.size(), os);
}
// Prints a ::wstring object.
#if GTEST_HAS_GLOBAL_WSTRING
void PrintWideStringTo(const ::wstring& s, ostream* os) {
PrintWideCharsAsStringTo(s.data(), s.size(), os);
}
#endif // GTEST_HAS_GLOBAL_WSTRING
#if GTEST_HAS_STD_WSTRING
void PrintWideStringTo(const ::std::wstring& s, ostream* os) {
PrintWideCharsAsStringTo(s.data(), s.size(), os);
}
#endif // GTEST_HAS_STD_WSTRING
} // namespace internal
} // namespace testing
// Copyright 2008, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Author: mheule@google.com (Markus Heule)
//
// The Google C++ Testing Framework (Google Test)
// Indicates that this translation unit is part of Google Test's
// implementation. It must come before gtest-internal-inl.h is
// included, or there will be a compiler error. This trick is to
// prevent a user from accidentally including gtest-internal-inl.h in
// his code.
#define GTEST_IMPLEMENTATION_ 1
#undef GTEST_IMPLEMENTATION_
namespace testing {
using internal::GetUnitTestImpl;
// Gets the summary of the failure message by omitting the stack trace
// in it.
internal::String TestPartResult::ExtractSummary(const char* message) {
const char* const stack_trace = strstr(message, internal::kStackTraceMarker);
return stack_trace == NULL ? internal::String(message) :
internal::String(message, stack_trace - message);
}
// Prints a TestPartResult object.
std::ostream& operator<<(std::ostream& os, const TestPartResult& result) {
return os
<< result.file_name() << ":" << result.line_number() << ": "
<< (result.type() == TestPartResult::kSuccess ? "Success" :
result.type() == TestPartResult::kFatalFailure ? "Fatal failure" :
"Non-fatal failure") << ":\n"
<< result.message() << std::endl;
}
// Appends a TestPartResult to the array.
void TestPartResultArray::Append(const TestPartResult& result) {
array_.push_back(result);
}
// Returns the TestPartResult at the given index (0-based).
const TestPartResult& TestPartResultArray::GetTestPartResult(int index) const {
if (index < 0 || index >= size()) {
printf("\nInvalid index (%d) into TestPartResultArray.\n", index);
internal::posix::Abort();
}
return array_[index];
}
// Returns the number of TestPartResult objects in the array.
int TestPartResultArray::size() const {
return static_cast<int>(array_.size());
}
namespace internal {
HasNewFatalFailureHelper::HasNewFatalFailureHelper()
: has_new_fatal_failure_(false),
original_reporter_(GetUnitTestImpl()->
GetTestPartResultReporterForCurrentThread()) {
GetUnitTestImpl()->SetTestPartResultReporterForCurrentThread(this);
}
HasNewFatalFailureHelper::~HasNewFatalFailureHelper() {
GetUnitTestImpl()->SetTestPartResultReporterForCurrentThread(
original_reporter_);
}
void HasNewFatalFailureHelper::ReportTestPartResult(
const TestPartResult& result) {
if (result.fatally_failed())
has_new_fatal_failure_ = true;
original_reporter_->ReportTestPartResult(result);
}
} // namespace internal
} // namespace testing
// Copyright 2008 Google Inc.
// All Rights Reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Author: wan@google.com (Zhanyong Wan)
namespace testing {
namespace internal {
#if GTEST_HAS_TYPED_TEST_P
// Skips to the first non-space char in str. Returns an empty string if str
// contains only whitespace characters.
static const char* SkipSpaces(const char* str) {
while (IsSpace(*str))
str++;
return str;
}
// Verifies that registered_tests match the test names in
// defined_test_names_; returns registered_tests if successful, or
// aborts the program otherwise.
const char* TypedTestCasePState::VerifyRegisteredTestNames(
const char* file, int line, const char* registered_tests) {
typedef ::std::set<const char*>::const_iterator DefinedTestIter;
registered_ = true;
// Skip initial whitespace in registered_tests since some
// preprocessors prefix stringizied literals with whitespace.
registered_tests = SkipSpaces(registered_tests);
Message errors;
::std::set<String> tests;
for (const char* names = registered_tests; names != NULL;
names = SkipComma(names)) {
const String name = GetPrefixUntilComma(names);
if (tests.count(name) != 0) {
errors << "Test " << name << " is listed more than once.\n";
continue;
}
bool found = false;
for (DefinedTestIter it = defined_test_names_.begin();
it != defined_test_names_.end();
++it) {
if (name == *it) {
found = true;
break;
}
}
if (found) {
tests.insert(name);
} else {
errors << "No test named " << name
<< " can be found in this test case.\n";
}
}
for (DefinedTestIter it = defined_test_names_.begin();
it != defined_test_names_.end();
++it) {
if (tests.count(*it) == 0) {
errors << "You forgot to list test " << *it << ".\n";
}
}
const String& errors_str = errors.GetString();
if (errors_str != "") {
fprintf(stderr, "%s %s", FormatFileLocation(file, line).c_str(),
errors_str.c_str());
fflush(stderr);
posix::Abort();
}
return registered_tests;
}
#endif // GTEST_HAS_TYPED_TEST_P
} // namespace internal
} // namespace testing
|
; A029058: Expansion of 1/((1-x)(1-x^3)(1-x^9)(1-x^10)).
; 1,1,1,2,2,2,3,3,3,5,6,6,8,9,9,11,12,12,15,17,18,21,23,24,27,29,30,34,37,39,44,47,49,54,57,59,65,69,72,79,84,87,94,99,102,110,116,120,129,136,141,150,157,162,172,180
lpb $0
mov $2,$0
sub $0,3
seq $2,25791 ; Expansion of 1/((1-x)(1-x^9)(1-x^10)).
add $1,$2
lpe
add $1,1
mov $0,$1
|
10 ORG 100H
20 JP MAIN
30PUTSTR EQU 0BFF1H
40WAITK EQU 0BFCDH
50WSTSR EQU 0BFB2H
60MAIN: LD HL, S0
70 LD DE, 0
80 CALL PUTSTR
90 LD HL, S0
100 CALL STRLN
110 LD C,0
120 LD HL, S0
130 LD DE, S1
140 LDIR
150 LD HL, S0
160 CALL STRLN
170 LD HL, S1
180 CALL STRLN
190 LD HL, S1
200 LD DE, 0200H
210 CALL PUTSTR
220 CALL WAITK
999 RET
1000S0: DB 'This me sending stuff from ASM'
1010 DB 13,10,0
1020S1: DB 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
3450STRLN: LD B, 0
3460STRLN0: LD A, (HL)
3470 OR A
3480 JP Z, STRLN1
3490 INC HL
3500 INC B
3510 JP STRLN0
3520STRLN1: RET
|
;
; int set_psg(int reg, int val);
;
SECTION code_clib
PUBLIC set_psg
PUBLIC _set_psg
EXTERN set_psg_callee
EXTERN ASMDISP_SET_PSG_CALLEE
set_psg:
_set_psg:
pop bc
pop de
pop hl
push hl
push de
push bc
jp set_psg_callee + ASMDISP_SET_PSG_CALLEE
|
; A036232: a(n+1) = a(n) + sum of digits of a(n) starting with 211.
; Submitted by Christian Krause
; 211,215,223,230,235,245,256,269,286,302,307,317,328,341,349,365,379,398,418,431,439,455,469,488,508,521,529,545,559,578,598,620,628,644,658,677,697,719,736,752,766,785,805,818,835,851,865,884,904,917,934
mov $2,$0
add $2,8
mov $3,$0
lpb $3
add $2,2
mov $0,$2
sub $2,1
sub $3,1
sub $0,$3
seq $0,7953 ; Digital sum (i.e., sum of digits) of n; also called digsum(n).
add $2,$0
lpe
mov $0,$2
add $0,203
|
#ifndef BOOST_MPL_AUX_LARGEST_INT_HPP_INCLUDED
#define BOOST_MPL_AUX_LARGEST_INT_HPP_INCLUDED
// Copyright Aleksey Gurtovoy 2000-2004
//
// 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://www.boost.org/libs/mpl for documentation.
// $Id: largest_int.hpp 49267 2008-10-11 06:19:02Z agurtovoy $
// $Date: 2008-10-11 02:19:02 -0400 (Sat, 11 Oct 2008) $
// $Revision: 49267 $
#include <boost/mpl/if.hpp>
#include <boost/mpl/int.hpp>
#include <boost/mpl/aux_/config/integral.hpp>
#include <boost/config.hpp>
namespace boost { namespace mpl { namespace aux {
template< typename T > struct integral_rank;
template<> struct integral_rank<bool> : int_<1> {};
template<> struct integral_rank<signed char> : int_<2> {};
template<> struct integral_rank<char> : int_<3> {};
template<> struct integral_rank<unsigned char> : int_<4> {};
#if !defined(BOOST_NO_INTRINSIC_WCHAR_T)
template<> struct integral_rank<wchar_t> : int_<5> {};
#endif
template<> struct integral_rank<short> : int_<6> {};
template<> struct integral_rank<unsigned short> : int_<7> {};
template<> struct integral_rank<int> : int_<8> {};
template<> struct integral_rank<unsigned int> : int_<9> {};
template<> struct integral_rank<long> : int_<10> {};
template<> struct integral_rank<unsigned long> : int_<11> {};
#if defined(BOOST_HAS_LONG_LONG)
template<> struct integral_rank<long_long_type> : int_<12> {};
template<> struct integral_rank<ulong_long_type>: int_<13> {};
#endif
template< typename T1, typename T2 > struct largest_int
#if !defined(BOOST_MPL_CFG_NO_NESTED_VALUE_ARITHMETIC)
: if_c<
( integral_rank<T1>::value >= integral_rank<T2>::value )
, T1
, T2
>
{
#else
{
enum { rank1 = integral_rank<T1>::value };
enum { rank2 = integral_rank<T2>::value };
typedef typename if_c< (rank1 >= rank2),T1,T2 >::type type;
#endif
};
}}}
#endif // BOOST_MPL_AUX_LARGEST_INT_HPP_INCLUDED
|
SECTION code_fp_math48
PUBLIC am48_dfix8u
EXTERN am48_dfix16u, error_erange_mc
am48_dfix8u:
; double to 8-bit unsigned integer (truncates)
;
; enter : AC' = double x
;
; exit : AC' = AC (AC saved in EXX set)
;
; success
;
; L = (unsigned int)(x)
; carry reset
;
; fail if overflow
;
; L = char_max or char_min
; carry set, errno set
;
; notes : FIX(1.5)= 1= $0001
; FIX(-1.5)= -1= $FFFF
; FIX(0.5)= 0= $0000
;
; uses : af, bc, de, hl, af', bc', de', hl'
; not doing special version for char
call am48_dfix16u
jr c, uint_overflow
; check for 8-bit overflow
ld a,h
or a
ret z
call error_erange_mc
ret p
ld l,$80
ret
uint_overflow:
ld l,h
ret
|
IFDEF RAX
ELSE
.MODEL FLAT,C
ENDIF
SOME SEGMENT EXECUTE READ
public justnop
justnop:
ret
END
|
__________________________________________________________________________________________________
class Solution {
public:
vector<vector<int>> multiply(vector<vector<int>>& A, vector<vector<int>>& B) {
vector<vector<int>> res(A.size(), vector<int>(B[0].size()));
for (int i = 0; i < A.size(); ++i) {
for (int k = 0; k < A[0].size(); ++k) {
if (A[i][k] != 0) {
for (int j = 0; j < B[0].size(); ++j) {
if (B[k][j] != 0) res[i][j] += A[i][k] * B[k][j];
}
}
}
}
return res;
}
};
__________________________________________________________________________________________________
class Solution {
public:
vector<vector<int>> multiply(vector<vector<int>>& A, vector<vector<int>>& B) {
vector<vector<int>> res(A.size(), vector<int>(B[0].size()));
vector<vector<pair<int, int>>> v(A.size(), vector<pair<int,int>>());
for (int i = 0; i < A.size(); ++i) {
for (int k = 0; k < A[i].size(); ++k) {
if (A[i][k] != 0) v[i].push_back({k, A[i][k]});
}
}
for (int i = 0; i < A.size(); ++i) {
for (int k = 0; k < v[i].size(); ++k) {
int col = v[i][k].first;
int val = v[i][k].second;
for (int j = 0; j < B[0].size(); ++j) {
res[i][j] += val * B[col][j];
}
}
}
return res;
}
};
__________________________________________________________________________________________________
|
; A142521: Primes congruent to 29 mod 52.
; Submitted by Jon Maiga
; 29,601,653,757,809,1069,1277,1381,1433,1693,1901,2161,2213,2473,2837,3253,3461,3617,3877,3929,4241,4397,4657,4813,4969,5021,5281,5333,5437,5749,5801,6113,6217,6269,6373,6529,6581,6737,6841,6997,7309,7517,7621,7673,7829,7933,8089,8297,8609,8713,9181,9337,9649,9857,10169,10273,10429,10949,11261,11677,11833,12041,12197,12301,12457,12613,12821,13757,13913,14173,14537,14797,15161,15473,15629,15733,15889,16097,16253,16981,17033,17137,17189,17293,17449,17657,17761,18229,18541,18593,18749,19009,19373
mov $2,$0
add $2,6
pow $2,2
mov $4,9
lpb $2
mov $3,$4
add $3,19
seq $3,10051 ; Characteristic function of primes: 1 if n is prime, else 0.
sub $0,$3
mov $1,$0
max $1,0
cmp $1,$0
mul $2,$1
sub $2,1
add $4,52
lpe
mov $0,$4
add $0,20
|
/****************************************************************************
*
* Copyright (C) 2013-2016 PX4 Development Team. 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. Neither the name PX4 nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/* Auto-generated by genmsg_cpp from file vehicle_trajectory_waypoint.msg */
#include <inttypes.h>
#include <px4_platform_common/log.h>
#include <px4_platform_common/defines.h>
#include <uORB/topics/vehicle_trajectory_waypoint.h>
#include <uORB/topics/uORBTopics.hpp>
#include <drivers/drv_hrt.h>
#include <lib/drivers/device/Device.hpp>
#include <lib/matrix/matrix/math.hpp>
#include <lib/mathlib/mathlib.h>
constexpr char __orb_vehicle_trajectory_waypoint_fields[] = "uint64_t timestamp;uint8_t type;uint8_t[7] _padding0;trajectory_waypoint[5] waypoints;";
ORB_DEFINE(vehicle_trajectory_waypoint, struct vehicle_trajectory_waypoint_s, 296, __orb_vehicle_trajectory_waypoint_fields, static_cast<uint8_t>(ORB_ID::vehicle_trajectory_waypoint));
ORB_DEFINE(vehicle_trajectory_waypoint_desired, struct vehicle_trajectory_waypoint_s, 296, __orb_vehicle_trajectory_waypoint_fields, static_cast<uint8_t>(ORB_ID::vehicle_trajectory_waypoint_desired));
void print_message(const vehicle_trajectory_waypoint_s &message)
{
PX4_INFO_RAW(" vehicle_trajectory_waypoint_s\n");
const hrt_abstime now = hrt_absolute_time();
if (message.timestamp != 0) {
PX4_INFO_RAW("\ttimestamp: %" PRIu64 " (%.6f seconds ago)\n", message.timestamp, (now - message.timestamp) / 1e6);
} else {
PX4_INFO_RAW("\n");
}
PX4_INFO_RAW("\ttype: %u\n", message.type);
PX4_INFO_RAW("\tpx4/trajectory_waypoint[5] waypoints[0]");
print_message(message.waypoints[0]);
PX4_INFO_RAW("\tpx4/trajectory_waypoint[5] waypoints[1]");
print_message(message.waypoints[1]);
PX4_INFO_RAW("\tpx4/trajectory_waypoint[5] waypoints[2]");
print_message(message.waypoints[2]);
PX4_INFO_RAW("\tpx4/trajectory_waypoint[5] waypoints[3]");
print_message(message.waypoints[3]);
PX4_INFO_RAW("\tpx4/trajectory_waypoint[5] waypoints[4]");
print_message(message.waypoints[4]);
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.